original_code:
particles particles_init(vector2 pt1, vector2 pt2, vector2 v){
 particles pts;
 float length = v2Len(v2Sub(pt1, pt2));
 particlenode *cycle;
 particlenode *prev = ((void *)0);
 float i;
 for(i=0; i<=length; i += 1.0f){
  cycle = (particles)malloc(sizeof(particlenode));
  if(i==0)
   {pts = cycle;}
  if(prev != ((void *)0))
   {prev->next = cycle;}
  cycle->p.p = v2Add(pt2, v2sMul(i,v2Unit(v2Sub(pt1, pt2))));
  vector2 rv = {rand()%50-25, rand()%50-25};
  cycle->p.v = v2Add(v, rv);
  cycle->p.t = 2+(float)(rand()%11)/10.0f;
  cycle->next = ((void *)0);
  prev = cycle;
 }
 return pts;
}

canonical_original_code:
struct particlenode *particles_init(struct vector2 pt1, struct vector2 pt2, struct vector2 v){
 struct particlenode *pts;
 float length = v2Len(v2Sub(pt1, pt2));
 struct particlenode *cycle;
 struct particlenode *prev = ((void *)0);
 float i;
 for(i=0; i<=length; i += 1.0f){
  cycle = (struct particlenode *)malloc(sizeof(particlenode));
  if(i==0)
   {pts = cycle;}
  if(prev != ((void *)0))
   {prev->next = cycle;}
  cycle->p.p = v2Add(pt2, v2sMul(i,v2Unit(v2Sub(pt1, pt2))));
  struct vector2 rv = {rand()%50-25, rand()%50-25};
  cycle->p.v = v2Add(v, rv);
  cycle->p.t = 2+(float)(rand()%11)/10.0f;
  cycle->next = ((void *)0);
  prev = cycle;
 }
 return pts;
}

variable_types: struct particlenode { struct particletype { struct vector2 { double x; } p; struct vector2 v; float t; } p; struct particlenode *next; } *

variable_types: length float

variable_types: i float

variable_types:
rv
struct vector2 { double x; }

user_defined_types: struct particlenode { struct particletype p; struct particlenode *next; }

user_defined_types: struct particletype { struct vector2 p; struct vector2 v; float t; }


repo: CovertIII/Tron-Clone

original_code:
void particles_update(particles pts, float dt){
 if(pts == ((void *)0))
  {return;}
 particlenode *cycle = pts;
 while(cycle != ((void *)0)){
  cycle->p.v.x += (-cycle->p.v.x)*dt;
  cycle->p.v.y += (-cycle->p.v.y)*dt;
  cycle->p.p.x += cycle->p.v.x*dt;
  cycle->p.p.y += cycle->p.v.y*dt;
  cycle->p.t -= dt;
  if(cycle->p.t <= 0){
   cycle->p.t = 0;
  }
  cycle = cycle->next;
 }
}

canonical_original_code:
void particles_update(struct particlenode *pts, float dt){
 if(pts == ((void *)0))
  {return;}
 struct particlenode *cycle = pts;
 while(cycle != ((void *)0)){
  cycle->p.v.x += (-cycle->p.v.x)*dt;
  cycle->p.v.y += (-cycle->p.v.y)*dt;
  cycle->p.p.x += cycle->p.v.x*dt;
  cycle->p.p.y += cycle->p.v.y*dt;
  cycle->p.t -= dt;
  if(cycle->p.t <= 0){
   cycle->p.t = 0;
  }
  cycle = cycle->next;
 }
}

variable_types: dt float

return_type: void


original_code:
void particles_bound(particles pts, int x, int y){
 if(pts == ((void *)0))
  {return;}
 particlenode *cycle = pts;
 while(cycle != ((void *)0)){
  if(cycle->p.p.x < 0){
   cycle->p.p.x = 0;
   cycle->p.v.x = -cycle->p.v.x;
  }
  if(cycle->p.p.x > x){
   cycle->p.p.x = x;
   cycle->p.v.x = -cycle->p.v.x;
  }
  if(cycle->p.p.y < 0){
   cycle->p.p.y = 0;
   cycle->p.v.y = -cycle->p.v.y;
  }
  if(cycle->p.p.y > y){
   cycle->p.p.y = y;
   cycle->p.v.y = -cycle->p.v.y;
  }
  cycle = cycle->next;
 }
}

canonical_original_code:
void particles_bound(struct particlenode *pts, int x, int y){
 if(pts == ((void *)0))
  {return;}
 struct particlenode *cycle = pts;
 while(cycle != ((void *)0)){
  if(cycle->p.p.x < 0){
   cycle->p.p.x = 0;
   cycle->p.v.x = -cycle->p.v.x;
  }
  if(cycle->p.p.x > x){
   cycle->p.p.x = x;
   cycle->p.v.x = -cycle->p.v.x;
  }
  if(cycle->p.p.y < 0){
   cycle->p.p.y = 0;
   cycle->p.v.y = -cycle->p.v.y;
  }
  if(cycle->p.p.y > y){
   cycle->p.p.y = y;
   cycle->p.v.y = -cycle->p.v.y;
  }
  cycle = cycle->next;
 }
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall particles_render(__int64 a1)
{
__int64 v1; // rbx
float v2; // xmm0_4
float v3; // xmm1_4
__int64 result; // rax
float v5; // [rsp+0h] [rbp-18h] BYREF
float v6; // [rsp+4h] [rbp-14h]
float v7; // [rsp+8h] [rbp-10h]

if ( a1 )
{
v1 = a1;
glGetFloatv(2816LL, &v5);
glPointSize(3.0);
glPushMatrix();
glBegin(0LL);
do
{
if ( *(float *)(v1 + 32) < 1.0 )
glColor4f(v5, v6, v7);
else
glColor3f(v5, v6, v7);
v2 = *(double *)v1;
v3 = *(double *)(v1 + 8);
glVertex2f(v2, v3);
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
glEnd();
glPopMatrix();
result = glColor3f(v5, v6, v7);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
float v2; // xmm0_4
float v3; // xmm1_4
__int64 result; // rax
float v5; // [rsp+0h] [rbp-18h] BYREF
float v6; // [rsp+4h] [rbp-14h]
float v7; // [rsp+8h] [rbp-10h]

if ( a1 )
{
v1 = a1;
glGetFloatv(2816LL, &v5);
glPointSize(3.0);
glPushMatrix();
glBegin(0LL);
do
{
if ( *(float *)(v1 + 32) < 1.0 )
glColor4f(v5, v6, v7);
else
glColor3f(v5, v6, v7);
v2 = *(double *)v1;
v3 = *(double *)(v1 + 8);
glVertex2f(v2, v3);
v1 = *(_QWORD *)(v1 + 40);
}
while ( v1 );
glEnd();
glPopMatrix();
result = glColor3f(v5, v6, v7);
}
return result;
}

original_code:
void particles_render(particles pts){
 if(pts == ((void *)0))
  {return;}
 particlenode *cycle = pts;
 float c[4];
 glGetFloatv(0x0B00, &c);
 glPointSize(3);
 glPushMatrix();
 glBegin(0x0000);
 while(cycle != ((void *)0)){
  if(cycle->p.t < 1.0f)
   {glColor4f(c[0],c[1],c[2],cycle->p.t);}
  else
   {glColor3f(c[0],c[1],c[2]);}
  glVertex2f(cycle->p.p.x, cycle->p.p.y);
  cycle = cycle->next;
 }
 glEnd();
 glPopMatrix();
 glColor3f(c[0],c[1],c[2]);
}

canonical_original_code:
void particles_render(struct particlenode *pts){
 if(pts == ((void *)0))
  {return;}
 struct particlenode *cycle = pts;
 float c[4];
 glGetFloatv(0x0B00, &c);
 glPointSize(3);
 glPushMatrix();
 glBegin(0x0000);
 while(cycle != ((void *)0)){
  if(cycle->p.t < 1.0f)
   {glColor4f(c[0],c[1],c[2],cycle->p.t);}
  else
   {glColor3f(c[0],c[1],c[2]);}
  glVertex2f(cycle->p.p.x, cycle->p.p.y);
  cycle = cycle->next;
 }
 glEnd();
 glPopMatrix();
 glColor3f(c[0],c[1],c[2]);
}

variable_types:
c
float [4]


decompiled_code:
unsigned int *__fastcall s_add_snd(unsigned int **a1, double a2, double a3)
{
unsigned int *result; // rax
unsigned int *v4; // rbx
float v5; // xmm0_4
float v6; // xmm1_4

result = (unsigned int *)malloc(0x10uLL);
if ( result )
{
v4 = result;
alGenSources(1LL, result);
alSourcei(*v4, 4105LL, *((unsigned int *)a1 + 2));
v5 = a2;
v6 = a3;
alSource3f(*v4, 4100LL, v5, v6, 0.0);
alSourcePlay(*v4);
*((_QWORD *)v4 + 1) = 0LL;
result = *a1;
if ( *a1 )
*((_QWORD *)v4 + 1) = result;
*a1 = v4;
}
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func0(unsigned int **a1, double a2, double a3)
{
unsigned int *result; // rax
unsigned int *v4; // rbx
float v5; // xmm0_4
float v6; // xmm1_4

result = (unsigned int *)malloc(0x10uLL);
if ( result )
{
v4 = result;
alGenSources(1LL, result);
alSourcei(*v4, 4105LL, *((unsigned int *)a1 + 2));
v5 = a2;
v6 = a3;
alSource3f(*v4, 4100LL, v5, v6, 0.0);
alSourcePlay(*v4);
*((_QWORD *)v4 + 1) = 0LL;
result = *a1;
if ( *a1 )
*((_QWORD *)v4 + 1) = result;
*a1 = v4;
}
return result;
}

original_code:
void s_add_snd(s_list sl, vector2 p){
 s_node * new;
 new = (s_node*)malloc(sizeof(s_node));
 if(!new){return;}
 alGenSources(1, &new->src);
 alSourcei(new->src, 0x1009, sl->buf);
 alSource3f(new->src, 0x1004, p.x, p.y, 0);
 alSourcePlay(new->src);
 new->next = ((void *)0);
 if(sl->head == ((void *)0)){
  sl->head = new;
  return;
 }
 new->next = sl->head;
 sl->head = new;
 return;
}

canonical_original_code:
void s_add_snd(struct s_type *sl, struct vector2 p){
 struct s_node *new;
 new = (struct s_node *)malloc(sizeof(s_node));
 if(!new){return;}
 alGenSources(1, &new->src);
 alSourcei(new->src, 0x1009, sl->buf);
 alSource3f(new->src, 0x1004, p.x, p.y, 0);
 alSourcePlay(new->src);
 new->next = ((void *)0);
 if(sl->head == ((void *)0)){
  sl->head = new;
  return;
 }
 new->next = sl->head;
 sl->head = new;
 return;
}

variable_types: struct s_type { struct s_node { unsigned int src; struct s_node *next; } *head; unsigned int buf; } *

variable_types:
p
struct vector2 { double x; }

user_defined_types: struct s_type { struct s_node *head; unsigned int buf; }


decompiled_code:
void __fastcall s_update(_QWORD **a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *a1;
while ( v1 )
{
alGetSourcei(*(unsigned int *)v1, 4112LL, v3);
if ( v3[0] == 4116 )
{
v2 = (_QWORD *)v1[1];
*a1 = v2;
alDeleteSources(1LL, v1);
free(v1);
v1 = v2;
}
else
{
v1 = (_QWORD *)v1[1];
}
}
}

canonical_decompiled_code:
void __fastcall func1(_QWORD **a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // r12
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = *a1;
while ( v1 )
{
alGetSourcei(*(unsigned int *)v1, 4112LL, v3);
if ( v3[0] == 4116 )
{
v2 = (_QWORD *)v1[1];
*a1 = v2;
alDeleteSources(1LL, v1);
free(v1);
v1 = v2;
}
else
{
v1 = (_QWORD *)v1[1];
}
}
}

original_code:
void s_update(s_list sl){
 s_node * cycle = sl->head;
 s_node * prev = ((void *)0);
 while(cycle != ((void *)0)){
  int state;
  alGetSourcei(cycle->src, 0x1010, &state);
  if(state == 0x1014){
   if(prev == ((void *)0)){
    s_node * tmp = cycle->next;
    sl->head = tmp;
    alDeleteSources(1, &cycle->src);
    free(cycle);
    cycle = tmp;
   }
   else{
    prev->next = cycle->next;
    alDeleteSources(1, &cycle->src);
    free(cycle);
    cycle = prev->next;
   }
  }
  else{cycle = cycle->next;}
 }
}

canonical_original_code:
void s_update(struct s_type *sl){
 struct s_node *cycle = sl->head;
 struct s_node *prev = ((void *)0);
 while(cycle != ((void *)0)){
  int state;
  alGetSourcei(cycle->src, 0x1010, &state);
  if(state == 0x1014){
   if(prev == ((void *)0)){
    struct s_node *tmp = cycle->next;
    sl->head = tmp;
    alDeleteSources(1, &cycle->src);
    free(cycle);
    cycle = tmp;
   }
   else{
    prev->next = cycle->next;
    alDeleteSources(1, &cycle->src);
    free(cycle);
    cycle = prev->next;
   }
  }
  else{cycle = cycle->next;}
 }
}

variable_types: struct s_node { unsigned int src; struct s_node *next; } *

variable_types: state int


decompiled_code:
_QWORD *chat_init()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
*((_DWORD *)result + 4) = 0;
}
return result;
}

original_code:
chat chat_init(void){
 chat cht;
 cht = (chat)malloc(sizeof(chattype));
 if(cht == ((void *)0)){
  return ((void *)0);
 }
 cht->head = ((void *)0);
 cht->tail = ((void *)0);
 cht->m_num = 0;
 return cht;
}

canonical_original_code:
struct chattype *chat_init(){
 struct chattype *cht;
 cht = (struct chattype *)malloc(sizeof(chattype));
 if(cht == ((void *)0)){
  return ((void *)0);
 }
 cht->head = ((void *)0);
 cht->tail = ((void *)0);
 cht->m_num = 0;
 return cht;
}

variable_types: struct chattype { struct chat_node { struct chat_data { char *name; char *message; } cd; struct chat_node *next; } *head; struct chat_node *tail; int m_num; } *

user_defined_types: struct chattype { struct chat_node *head; struct chat_node *tail; int m_num; }

user_defined_types: struct chat_node { struct chat_data cd; struct chat_node *next; }


decompiled_code:
__int64 __fastcall chat_add_message(__int64 *a1, const char *a2, const char *a3)
{
char **v5; // rax
char **v6; // rbx
size_t v7; // rax
char *v8; // rdi
size_t v9; // rax
char *v10; // rdi
__int64 result; // rax

v5 = (char **)malloc(0x18uLL);
if ( !v5 )
return 1LL;
v6 = v5;
v7 = strlen(a2);
v8 = (char *)malloc(v7 + 1);
*v6 = v8;
if ( !v8 )
return 1LL;
strcpy(v8, a2);
v9 = strlen(a3);
v10 = (char *)malloc(v9 + 1);
v6[1] = v10;
if ( !v10 )
return 1LL;
strcpy(v10, a3);
result = *a1;
if ( *a1 )
{
v6[2] = (char *)result;
*a1 = (__int64)v6;
result = 0LL;
}
else
{
*a1 = (__int64)v6;
v6[2] = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, const char *a2, const char *a3)
{
char **v5; // rax
char **v6; // rbx
size_t v7; // rax
char *v8; // rdi
size_t v9; // rax
char *v10; // rdi
__int64 result; // rax

v5 = (char **)malloc(0x18uLL);
if ( !v5 )
return 1LL;
v6 = v5;
v7 = strlen(a2);
v8 = (char *)malloc(v7 + 1);
*v6 = v8;
if ( !v8 )
return 1LL;
strcpy(v8, a2);
v9 = strlen(a3);
v10 = (char *)malloc(v9 + 1);
v6[1] = v10;
if ( !v10 )
return 1LL;
strcpy(v10, a3);
result = *a1;
if ( *a1 )
{
v6[2] = (char *)result;
*a1 = (__int64)v6;
result = 0LL;
}
else
{
*a1 = (__int64)v6;
v6[2] = 0LL;
}
return result;
}

original_code:
int chat_add_message(chat cht, char *name, char *message){
 chat_node *temp;
 temp = (chat_node*)malloc(sizeof(chat_node));
 if(temp == ((void *)0)) {return 1;}
 temp->cd.name = (char*)malloc(strlen(name)+1);
 if(temp->cd.name == ((void *)0)){return 1;}
 strcpy(temp->cd.name, name);
 temp->cd.message = (char*)malloc(strlen(message)+1);
 if(temp->cd.message == ((void *)0)) {return 1;}
 strcpy(temp->cd.message, message);
 if(cht->head == ((void *)0)){
  cht->head = temp;
    temp->next = ((void *)0);
    return 0;
 }
 temp->next = cht->head;
 cht->head = temp;
 return 0;
}

canonical_original_code:
int chat_add_message(struct chattype *cht, char *name, char *message){
 struct chat_node *temp;
 temp = (struct chat_node *)malloc(sizeof(chat_node));
 if(temp == ((void *)0)) {return 1;}
 temp->cd.name = (char *)malloc(strlen(name)+1);
 if(temp->cd.name == ((void *)0)){return 1;}
 strcpy(temp->cd.name, name);
 temp->cd.message = (char *)malloc(strlen(message)+1);
 if(temp->cd.message == ((void *)0)) {return 1;}
 strcpy(temp->cd.message, message);
 if(cht->head == ((void *)0)){
  cht->head = temp;
    temp->next = ((void *)0);
    return 0;
 }
 temp->next = cht->head;
 cht->head = temp;
 return 0;
}

variable_types:
name
char *

variable_types:
message
char *

variable_types: struct chat_node { struct chat_data { char *name; char *message; } cd; struct chat_node *next; } *

return_type: int


decompiled_code:
void __fastcall chat_render(__int64 *a1, int a2)
{
__int64 v2; // rbp
int v3; // er14
int v4; // er15
const char *v5; // r12
size_t v6; // rbx
const char *v7; // r13
size_t v8; // rax
char *v9; // rbx

v2 = *a1;
if ( *a1 )
{
v3 = 10;
v4 = 0;
do
{
v5 = *(const char **)v2;
v6 = strlen(*(const char **)v2);
v7 = *(const char **)(v2 + 8);
v8 = strlen(v7);
v9 = (char *)malloc(v6 + v8 + 5);
sprintf(v9, "%s: %s", v5, v7);
glPushMatrix();
glLoadIdentity();
renderBitmapString((__int64)&glutBitmapHelvetica10, v9);
glPopMatrix(10.0, (float)v3);
free(v9);
v2 = *(_QWORD *)(v2 + 16);
if ( a2 && v4 > 3 )
break;
++v4;
v3 += 12;
}
while ( v2 );
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 *a1, int a2)
{
__int64 v2; // rbp
int v3; // er14
int v4; // er15
const char *v5; // r12
size_t v6; // rbx
const char *v7; // r13
size_t v8; // rax
char *v9; // rbx

v2 = *a1;
if ( *a1 )
{
v3 = 10;
v4 = 0;
do
{
v5 = *(const char **)v2;
v6 = strlen(*(const char **)v2);
v7 = *(const char **)(v2 + 8);
v8 = strlen(v7);
v9 = (char *)malloc(v6 + v8 + 5);
sprintf(v9, "%s: %s", v5, v7);
glPushMatrix();
glLoadIdentity();
func0((__int64)&glutBitmapHelvetica10, v9);
glPopMatrix(10.0, (float)v3);
free(v9);
v2 = *(_QWORD *)(v2 + 16);
if ( a2 && v4 > 3 )
break;
++v4;
v3 += 12;
}
while ( v2 );
}
}

original_code:
void chat_render(chat cht, int type){
 int i=0;
 chat_node *cycle = cht->head;
 while(cycle != ((void *)0)){
  char *buf;
  buf = (char*)malloc(strlen(cycle->cd.name)+strlen(cycle->cd.message)+5);
  sprintf(buf, "%s: %s", cycle->cd.name, cycle->cd.message);
  glPushMatrix();
  glLoadIdentity();
  renderBitmapString(10, 10 + 12*i, ((void *) &glutBitmapHelvetica10), buf);
  glPopMatrix();
  free(buf);
  cycle = cycle->next;
  if(type && i > 3){
   return;
  }
  ++i;
 }
}

canonical_original_code:
void chat_render(struct chattype *cht, int type){
 int i = 0;
 struct chat_node *cycle = cht->head;
 while(cycle != ((void *)0)){
  char *buf;
  buf = (char *)malloc(strlen(cycle->cd.name)+strlen(cycle->cd.message)+5);
  sprintf(buf, "%s: %s", cycle->cd.name, cycle->cd.message);
  glPushMatrix();
  glLoadIdentity();
  renderBitmapString(10, 10 + 12*i, ((void *) &glutBitmapHelvetica10), buf);
  glPopMatrix();
  free(buf);
  cycle = cycle->next;
  if(type && i > 3){
   return;
  }
  ++i;
 }
}

variable_types: type int

variable_types: i int

variable_types:
buf
char *

user_defined_types: struct chat_data { char *name; char *message; }


decompiled_code:
void __fastcall chat_free(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

v2 = *(_QWORD *)ptr;
while ( v2 )
{
free(*(void **)v2);
free(*(void **)(v2 + 8));
v3 = (void *)v2;
v2 = *(_QWORD *)(v2 + 16);
free(v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
__int64 v2; // rbx
void *v3; // rdi

v2 = *(_QWORD *)ptr;
while ( v2 )
{
free(*(void **)v2);
free(*(void **)(v2 + 8));
v3 = (void *)v2;
v2 = *(_QWORD *)(v2 + 16);
free(v3);
}
free(ptr);
}

original_code:
void chat_free(chat cht){
 chat_node *cycle = cht->head;
 while(cycle != ((void *)0)){
  free(cycle->cd.name);
  free(cycle->cd.message);
  chat_node *tmp = cycle->next;
  free(cycle);
  cycle = tmp;
 }
 free(cht);
}

canonical_original_code:
void chat_free(struct chattype *cht){
 struct chat_node *cycle = cht->head;
 while(cycle != ((void *)0)){
  free(cycle->cd.name);
  free(cycle->cd.message);
  struct chat_node *tmp = cycle->next;
  free(cycle);
  cycle = tmp;
 }
 free(cht);
}


decompiled_code:
__int64 __fastcall plist_add(double **a1, double a2, double a3)
{
double *v3; // rax

v3 = (double *)malloc(0x20uLL);
if ( !v3 )
return 1LL;
*v3 = a2;
v3[1] = a3;
*((_DWORD *)v3 + 4) = 1092721050;
v3[3] = 0.0;
if ( *a1 )
*((_QWORD *)v3 + 3) = *a1;
*a1 = v3;
return 0LL;
}

original_code:
int plist_add(plist *list, vector2 p){
 pnode *new_node;
 new_node = (pnode*)malloc(sizeof(pnode));
 if(new_node==((void *)0))
  {return 1;}
 new_node->pt.p = p;
 new_node->pt.t = 10.1f;
 new_node->next = ((void *)0);
 if(*list == ((void *)0)){
  *list = new_node;
  return 0;
 }
 new_node->next = *list;
 *list = new_node;
 return 0;
}

canonical_original_code:
int plist_add(struct pnode **list, struct vector2 p){
 struct pnode *new_node;
 new_node = (struct pnode *)malloc(sizeof(pnode));
 if(new_node==((void *)0))
  {return 1;}
 new_node->pt.p = p;
 new_node->pt.t = 10.1f;
 new_node->next = ((void *)0);
 if(*list == ((void *)0)){
  *list = new_node;
  return 0;
 }
 new_node->next = *list;
 *list = new_node;
 return 0;
}

variable_types: struct pnode { struct pt_type { struct vector2 { double x; } p; float t; } pt; struct pnode *next; } **

variable_types:
p
struct vector2

user_defined_types: struct pnode { struct pt_type pt; struct pnode *next; }

user_defined_types: struct pt_type { struct vector2 p; float t; }


decompiled_code:
double *__fastcall plist_head(double **a1, double a2, double a3)
{
double *result; // rax
double *v4; // rax

result = *a1;
if ( *a1 )
{
*result = a2;
result[1] = a3;
}
else
{
v4 = (double *)malloc(0x20uLL);
if ( v4 )
{
*v4 = a2;
v4[1] = a3;
*((_DWORD *)v4 + 4) = 1092721050;
v4[3] = 0.0;
*a1 = v4;
result = 0LL;
}
else
{
result = (double *)(plist_add + 1);
}
}
return result;
}

canonical_decompiled_code:
double *__fastcall func1(double **a1, double a2, double a3)
{
double *result; // rax
double *v4; // rax

result = *a1;
if ( *a1 )
{
*result = a2;
result[1] = a3;
}
else
{
v4 = (double *)malloc(0x20uLL);
if ( v4 )
{
*v4 = a2;
v4[1] = a3;
*((_DWORD *)v4 + 4) = 1092721050;
v4[3] = 0.0;
*a1 = v4;
result = 0LL;
}
else
{
result = (double *)(plist_add + 1);
}
}
return result;
}

original_code:
int plist_head(plist *list, vector2 p){
 if(*list == ((void *)0)){
  pnode *new_node;
  new_node = (pnode*)malloc(sizeof(pnode));
  if(new_node==((void *)0))
   {return 1;}
  new_node->pt.p = p;
  new_node->pt.t = 10.1f;
  new_node->next = ((void *)0);
  if(*list == ((void *)0)){
   *list = new_node;
   return 0;
  }
  new_node->next = *list;
  *list = new_node;
  return 0;
 }
 (*list)->pt.p = p;
}

canonical_original_code:
int plist_head(struct pnode **list, struct vector2 p){
 if(*list == ((void *)0)){
  struct pnode *new_node;
  new_node = (struct pnode *)malloc(sizeof(pnode));
  if(new_node==((void *)0))
   {return 1;}
  new_node->pt.p = p;
  new_node->pt.t = 10.1f;
  new_node->next = ((void *)0);
  if(*list == ((void *)0)){
   *list = new_node;
   return 0;
  }
  new_node->next = *list;
  *list = new_node;
  return 0;
 }
 (*list)->pt.p = p;
}

variable_types: struct pnode { struct pt_type { struct vector2 { double x; } p; float t; } pt; struct pnode *next; } *


original_code:
int plist_update(plist list, float dt){
 pnode *cycle = list;
 pnode *prev = ((void *)0);
 while(cycle != ((void *)0)){
  cycle->pt.t -= dt;
  if (cycle->pt.t <= 0){
   if (prev == ((void *)0)){
    return 1;
   }
   pnode *temp = cycle;
   prev->next = cycle->next;
   cycle = cycle->next;
   free(temp);
  }
  else{
   prev = cycle;
   cycle = cycle->next;
  }
 }
 return 0;
}

canonical_original_code:
int plist_update(struct pnode *list, float dt){
 struct pnode *cycle = list;
 struct pnode *prev = ((void *)0);
 while(cycle != ((void *)0)){
  cycle->pt.t -= dt;
  if (cycle->pt.t <= 0){
   if (prev == ((void *)0)){
    return 1;
   }
   struct pnode *temp = cycle;
   prev->next = cycle->next;
   cycle = cycle->next;
   free(temp);
  }
  else{
   prev = cycle;
   cycle = cycle->next;
  }
 }
 return 0;
}

variable_types: dt float


decompiled_code:
__int64 __fastcall plist_intersect(__int64 a1, double a2, double a3, double a4, double a5)
{
__int64 v5; // rbx
__int64 result; // rax

if ( !a1 )
return 0LL;
v5 = *(_QWORD *)(a1 + 24);
if ( !v5 )
return 0LL;
while ( !(unsigned int)line_collison(
a2,
a3,
a4,
a5,
*(double *)a1,
*(double *)(a1 + 8),
*(double *)v5,
*(double *)(v5 + 8))
|| *(float *)(v5 + 16) <= 0.5 )
{
result = *(_QWORD *)(v5 + 24);
a1 = v5;
if ( !result )
return result;
v5 = *(_QWORD *)(v5 + 24);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, double a2, double a3, double a4, double a5)
{
__int64 v5; // rbx
__int64 result; // rax

if ( !a1 )
return 0LL;
v5 = *(_QWORD *)(a1 + 24);
if ( !v5 )
return 0LL;
while ( !(unsigned int)line_collison(
a2,
a3,
a4,
a5,
*(double *)a1,
*(double *)(a1 + 8),
*(double *)v5,
*(double *)(v5 + 8))
|| *(float *)(v5 + 16) <= 0.5 )
{
result = *(_QWORD *)(v5 + 24);
a1 = v5;
if ( !result )
return result;
v5 = *(_QWORD *)(v5 + 24);
}
return 1LL;
}

original_code:
int plist_intersect(plist list, vector2 g1, vector2 g2){
 if(list == ((void *)0))
  {return 0;}
 pnode *cycle = list;
 pnode *nxt = cycle->next;
 while(nxt != ((void *)0)){
  if(line_collison(g1, g2, cycle->pt.p, nxt->pt.p) && nxt->pt.t > 0.5){
   return 1;
  }
  cycle = nxt;
  nxt = nxt->next;
 }
 return 0;
}

canonical_original_code:
int plist_intersect(struct pnode *list, struct vector2 g1, struct vector2 g2){
 if(list == ((void *)0))
  {return 0;}
 struct pnode *cycle = list;
 struct pnode *nxt = cycle->next;
 while(nxt != ((void *)0)){
  if(line_collison(g1, g2, cycle->pt.p, nxt->pt.p) && nxt->pt.t > 0.5){
   return 1;
  }
  cycle = nxt;
  nxt = nxt->next;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall plist_render(__int64 a1)
{
__int64 v1; // rbx
float v3; // xmm0_4
float v4; // xmm1_4
float v5; // [rsp+0h] [rbp-18h] BYREF
float v6; // [rsp+4h] [rbp-14h]
float v7; // [rsp+8h] [rbp-10h]

v1 = a1;
glGetFloatv(2816LL, &v5);
glPushMatrix();
glBegin(3LL);
if ( a1 )
{
do
{
if ( *(float *)(v1 + 16) >= 1.0 )
glColor3f(v5 + 0.25, v6 + 0.25, v7 + 0.25);
else
glColor4f(v5 + 0.25, v6 + 0.25, v7 + 0.25);
v3 = *(double *)v1;
v4 = *(double *)(v1 + 8);
glVertex2f(v3, v4);
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
glEnd();
glPopMatrix();
return glColor3f(v5, v6, v7);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
float v3; // xmm0_4
float v4; // xmm1_4
float v5; // [rsp+0h] [rbp-18h] BYREF
float v6; // [rsp+4h] [rbp-14h]
float v7; // [rsp+8h] [rbp-10h]

v1 = a1;
glGetFloatv(2816LL, &v5);
glPushMatrix();
glBegin(3LL);
if ( a1 )
{
do
{
if ( *(float *)(v1 + 16) >= 1.0 )
glColor3f(v5 + 0.25, v6 + 0.25, v7 + 0.25);
else
glColor4f(v5 + 0.25, v6 + 0.25, v7 + 0.25);
v3 = *(double *)v1;
v4 = *(double *)(v1 + 8);
glVertex2f(v3, v4);
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
glEnd();
glPopMatrix();
return glColor3f(v5, v6, v7);
}

original_code:
void plist_render(plist list){
 pnode *cycle = list;
 float c[4];
 glGetFloatv(0x0B00, &c);
 glPushMatrix();
 glBegin(0x0003);
 while(cycle != ((void *)0)){
  if(cycle->pt.t < 1.0f)
   {glColor4f(c[0]+0.25,c[1]+0.25,c[2]+0.25,cycle->pt.t);}
  else
   {glColor3f(c[0]+0.25,c[1]+0.25,c[2]+0.25);}
  glVertex2f(cycle->pt.p.x, cycle->pt.p.y);
  cycle = cycle->next;
 }
 glEnd();
 glPopMatrix();
 glColor3f(c[0],c[1],c[2]);
}

canonical_original_code:
void plist_render(struct pnode *list){
 struct pnode *cycle = list;
 float c[4];
 glGetFloatv(0x0B00, &c);
 glPushMatrix();
 glBegin(0x0003);
 while(cycle != ((void *)0)){
  if(cycle->pt.t < 1.0f)
   {glColor4f(c[0]+0.25,c[1]+0.25,c[2]+0.25,cycle->pt.t);}
  else
   {glColor3f(c[0]+0.25,c[1]+0.25,c[2]+0.25);}
  glVertex2f(cycle->pt.p.x, cycle->pt.p.y);
  cycle = cycle->next;
 }
 glEnd();
 glPopMatrix();
 glColor3f(c[0],c[1],c[2]);
}


decompiled_code:
_BOOL8 __fastcall line_collison(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v10; // r12
float v11; // xmm0_4
_BOOL8 result; // rax
double v13; // xmm0_8
double v14; // xmm0_8
float v15; // xmm0_4
double v16; // [rsp+8h] [rbp-50h]
float v18; // [rsp+10h] [rbp-48h]
float v19; // [rsp+1Ch] [rbp-3Ch]
float v20; // [rsp+1Ch] [rbp-3Ch]

v16 = v2Sub(a3, a4, a1, a2);
v10 = v2Sub(a7, a8, a5, a6);
if ( v2Cross(v16, a4, v10, a8) <= -0.1 || (v11 = v2Cross(v16, a4, v10, a8), result = 0LL, v11 >= 0.1) )
{
v13 = v2Sub(a5, a6, a1, a2);
v19 = v2Cross(v13, a6, v10, a8);
v20 = v19 / v2Cross(v16, a4, v10, a8);
v14 = v2Sub(a5, a6, a1, a2);
v18 = v2Cross(v14, a6, v16, a4);
v15 = v2Cross(v16, a4, v10, a8);
result = 0LL;
if ( v20 >= 0.0 )
{
result = 0LL;
if ( v20 <= 1.0 )
{
result = 0LL;
if ( (float)(v18 / v15) >= 0.0 )
result = (float)(v18 / v15) <= 1.0;
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8)
{
double v10; // r12
float v11; // xmm0_4
_BOOL8 result; // rax
double v13; // xmm0_8
double v14; // xmm0_8
float v15; // xmm0_4
double v16; // [rsp+8h] [rbp-50h]
float v18; // [rsp+10h] [rbp-48h]
float v19; // [rsp+1Ch] [rbp-3Ch]
float v20; // [rsp+1Ch] [rbp-3Ch]

v16 = v2Sub(a3, a4, a1, a2);
v10 = v2Sub(a7, a8, a5, a6);
if ( v2Cross(v16, a4, v10, a8) <= -0.1 || (v11 = v2Cross(v16, a4, v10, a8), result = 0LL, v11 >= 0.1) )
{
v13 = v2Sub(a5, a6, a1, a2);
v19 = v2Cross(v13, a6, v10, a8);
v20 = v19 / v2Cross(v16, a4, v10, a8);
v14 = v2Sub(a5, a6, a1, a2);
v18 = v2Cross(v14, a6, v16, a4);
v15 = v2Cross(v16, a4, v10, a8);
result = 0LL;
if ( v20 >= 0.0 )
{
result = 0LL;
if ( v20 <= 1.0 )
{
result = 0LL;
if ( (float)(v18 / v15) >= 0.0 )
result = (float)(v18 / v15) <= 1.0;
}
}
}
return result;
}

original_code:
int line_collison(vector2 p, vector2 bp, vector2 q, vector2 bq){
 vector2 r = v2Sub(bp, p);
 vector2 s = v2Sub(bq, q);
 if(v2Cross(r, s) > -0.1 && v2Cross(r, s) < 0.1)
  {return 0;}
 float t = v2Cross(v2Sub(q, p), s) / v2Cross(r, s);
 float u = v2Cross(v2Sub(q, p), r) / v2Cross(r, s);
 if((t >= 0 && t <=1) && (u >= 0 && u <=1) )
  {return 1;}
 return 0;
}

canonical_original_code:
int line_collison(struct vector2 p, struct vector2 bp, struct vector2 q, struct vector2 bq){
 struct vector2 r = v2Sub(bp, p);
 struct vector2 s = v2Sub(bq, q);
 if(v2Cross(r, s) > -0.1 && v2Cross(r, s) < 0.1)
  {return 0;}
 float t = v2Cross(v2Sub(q, p), s) / v2Cross(r, s);
 float u = v2Cross(v2Sub(q, p), r) / v2Cross(r, s);
 if((t >= 0 && t <=1) && (u >= 0 && u <=1) )
  {return 1;}
 return 0;
}

variable_types:
bp
struct vector2

variable_types:
q
struct vector2

variable_types:
bq
struct vector2

variable_types:
r
struct vector2 { double x; }

variable_types:
s
struct vector2 { double x; }

variable_types: t float

variable_types: u float


repo: Crabbit/c

decompiled_code:
__int64 __fastcall decode_switches(int argc, char **argv)
{
unsigned int v2; // eax
int v3; // ebx

opterr = 0;
while ( 1 )
{
v2 = getopt(argc, argv, "al:R:u:");
v3 = v2;
if ( v2 == -1 )
return 0LL;
printf("result = %d - %c.\n", v2, v2);
if ( v3 == 97 )
{
printf("option = a\n.");
}
else if ( v3 <= 97 )
{
if ( v3 == 63 )
{
printf("ls: %c: invalid option\n", (unsigned int)optopt);
printf("ls: usage: ls [-a|-l|-R|-u] [file|dir]");
}
else
{
if ( v3 != 82 )
goto LABEL_14;
printf("option = R, optarg = %s\n.", optarg);
}
}
else if ( v3 == 108 )
{
printf("option = l, optarg = %s\n.", optarg);
}
else if ( v3 == 117 )
{
printf("option = u, optarg = %s\n.", optarg);
}
else
{
LABEL_14:
puts("NO option.");
}
}
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv)
{
unsigned int v2; // eax
int v3; // ebx

opterr = 0;
while ( 1 )
{
v2 = getopt(argc, argv, "al:R:u:");
v3 = v2;
if ( v2 == -1 )
return 0LL;
printf("result = %d - %c.\n", v2, v2);
if ( v3 == 97 )
{
printf("option = a\n.");
}
else if ( v3 <= 97 )
{
if ( v3 == 63 )
{
printf("ls: %c: invalid option\n", (unsigned int)optopt);
printf("ls: usage: ls [-a|-l|-R|-u] [file|dir]");
}
else
{
if ( v3 != 82 )
goto LABEL_14;
printf("option = R, optarg = %s\n.", optarg);
}
}
else if ( v3 == 108 )
{
printf("option = l, optarg = %s\n.", optarg);
}
else if ( v3 == 117 )
{
printf("option = u, optarg = %s\n.", optarg);
}
else
{
LABEL_14:
puts("NO option.");
}
}
}

original_code:
char decode_switches(int argc, char *argv[])
{
 int result;
 opterr = 0;
 while(( result = getopt(argc, argv, "al:R:u:") ) != -1 )
 {
  printf( "result = %d - %c.\n", result, result );
  switch(result)
  {
   case 'a':
    printf( "option = a\n." );
    break;
   case 'l':
    printf( "option = l, optarg = %s\n.", optarg );
    break;
   case 'R':
    printf( "option = R, optarg = %s\n.", optarg );
    break;
   case 'u':
    printf( "option = u, optarg = %s\n.", optarg );
    break;
   case '?':
    printf( "ls: %c: invalid option\n", optopt );
    printf( "ls: usage: ls [-a|-l|-R|-u] [file|dir]" );
    break;
   default:
    printf( "NO option.\n" );
    break;
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: result int

return_type: char


decompiled_code:
int __fastcall COMM_CREATE_FILE(const char *a1)
{
int v1; // ebx

v1 = open(a1, 577, 388LL);
if ( v1 == -1 )
my_err("Create file / Open", 36LL);
return close(v1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int v1; // ebx

v1 = open(a1, 577, 388LL);
if ( v1 == -1 )
my_err("Create file / Open", 36LL);
return close(v1);
}

original_code:
void COMM_CREATE_FILE( char *FILE_NAME )
{
 int FILE_ONLINE_fd;
 if( ( FILE_ONLINE_fd = open( FILE_NAME, 01 | 0100 | 01000, 0400 | 0200 | ((0400 >> 3) >> 3) )) == -1 )
  my_err( "Create file / Open",36 );
 close ( FILE_ONLINE_fd );
}

canonical_original_code:
void COMM_CREATE_FILE(char *FILE_NAME)
{
 int FILE_ONLINE_fd;
 if( ( FILE_ONLINE_fd = open( FILE_NAME, 01 | 0100 | 01000, 0400 | 0200 | ((0400 >> 3) >> 3) )) == -1 )
  my_err( "Create file / Open",36 );
 close ( FILE_ONLINE_fd );
}


decompiled_code:
__int64 __fastcall COMM_SAVE_IPADDRESS(void *buf)
{
unsigned int v1; // ebp
size_t v2; // rax
int v3; // eax
int v4; // ebx
int *v6; // rbx
char *v7; // rax
int *v8; // rbx
char *v9; // rax

v1 = open("COMM_FILE_ONLINE", 1025);
if ( v1 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
pr_err("Open", (unsigned int)*v6, v7);
}
else
{
v2 = strlen((const char *)buf);
if ( write(v1, buf, v2) == -1 )
goto LABEL_9;
v3 = strlen((const char *)buf);
v4 = 15 - v3;
if ( v3 != 15 )
{
do
{
write(v1, " ", 1uLL);
--v4;
}
while ( v4 );
}
if ( write(v1, " CONNECTING\n", 0xCuLL) == -1 )
{
LABEL_9:
v8 = _errno_location();
v9 = strerror(*v8);
pr_err("Write", (unsigned int)*v8, v9);
v1 = -1;
}
else
{
puts("connecting save successful");
close(v1);
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *buf)
{
unsigned int v1; // ebp
size_t v2; // rax
int v3; // eax
int v4; // ebx
int *v6; // rbx
char *v7; // rax
int *v8; // rbx
char *v9; // rax

v1 = open("COMM_FILE_ONLINE", 1025);
if ( v1 == -1 )
{
v6 = _errno_location();
v7 = strerror(*v6);
pr_err("Open", (unsigned int)*v6, v7);
}
else
{
v2 = strlen((const char *)buf);
if ( write(v1, buf, v2) == -1 )
goto LABEL_9;
v3 = strlen((const char *)buf);
v4 = 15 - v3;
if ( v3 != 15 )
{
do
{
write(v1, " ", 1uLL);
--v4;
}
while ( v4 );
}
if ( write(v1, " CONNECTING\n", 0xCuLL) == -1 )
{
LABEL_9:
v8 = _errno_location();
v9 = strerror(*v8);
pr_err("Write", (unsigned int)*v8, v9);
v1 = -1;
}
else
{
puts("connecting save successful");
close(v1);
v1 = 0;
}
}
return v1;
}

original_code:
int COMM_SAVE_IPADDRESS( char * IP_ADDRESS )
{
 int FILEDS_comm_online_fd;
 int FILE_format_control = 0;
 if ( ( FILEDS_comm_online_fd = open( "COMM_FILE_ONLINE", 02000 | 01)) == -1 )
 {
  pr_err( "Open", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                return ( -1) ;
 }
        if( write( FILEDS_comm_online_fd, IP_ADDRESS, strlen( IP_ADDRESS )) == -1 )
 {
  pr_err( "Write", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                return ( -1) ;
 }
        FILE_format_control = 15 - strlen( IP_ADDRESS );
        for( ; FILE_format_control != 0; FILE_format_control-- )
                write( FILEDS_comm_online_fd, " ", 1 );
        if( write( FILEDS_comm_online_fd, " CONNECTING\n", 12 ) == -1 )
 {
  pr_err( "Write", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                return ( -1) ;
 }
 else
  printf( "connecting save successful\n" );
        close( FILEDS_comm_online_fd );
 return 0;
}

canonical_original_code:
int COMM_SAVE_IPADDRESS(char *IP_ADDRESS)
{
 int FILEDS_comm_online_fd;
 int FILE_format_control = 0;
 if ( ( FILEDS_comm_online_fd = open( "COMM_FILE_ONLINE", 02000 | 01)) == -1 )
 {
  pr_err( "Open", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                return ( -1) ;
 }
        if( write( FILEDS_comm_online_fd, IP_ADDRESS, strlen( IP_ADDRESS )) == -1 )
 {
  pr_err( "Write", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                return ( -1) ;
 }
        FILE_format_control = 15 - strlen( IP_ADDRESS );
        for( ; FILE_format_control != 0; FILE_format_control-- )
                write( FILEDS_comm_online_fd, " ", 1 );
        if( write( FILEDS_comm_online_fd, " CONNECTING\n", 12 ) == -1 )
 {
  pr_err( "Write", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                return ( -1) ;
 }
 else
  printf( "connecting save successful\n" );
        close( FILEDS_comm_online_fd );
 return 0;
}


decompiled_code:
__int64 __fastcall COMM_FILE_STATE_EXCHANGE(char *s2)
{
unsigned int v1; // er12
unsigned int v2; // ebp
int *v3; // rbx
char *v4; // rax
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax
int v10; // eax
int v11; // ebx
int *v12; // rbx
char *v13; // rax
char v14[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = open("COMM_FILE_ONLINE", 2);
if ( v1 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
pr_err("Open", (unsigned int)*v5, v6);
v2 = -1;
}
else
{
while ( 1 )
{
printf("read_file_buf address = %p\n", v14);
v2 = read(v1, v14, 0xFuLL);
printf("FILE_ONLINEeFD = %d\n", v1);
printf("read_file_buf address = %p\n", v14);
printf("read_file_buf = %s\n", v14);
printf("read_file_buf address = %p\n", v14);
printf("read_file_buf = %s\n", v14);
printf("test = %d\n", v2);
if ( v2 == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
pr_err("Read", (unsigned int)*v7, v8);
return v2;
}
v2 = strcmp(v14, s2);
if ( !v2 )
break;
if ( lseek(v1, 12LL, 1) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
pr_err("Lseek", (unsigned int)*v3, v4);
return (unsigned int)-1;
}
}
v10 = strlen(s2);
v11 = 15 - v10;
if ( v10 != 15 )
{
do
{
write(v1, " ", 1uLL);
--v11;
}
while ( v11 );
}
if ( write(v1, " DISCONNECT\n", 0xCuLL) == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
pr_err("Write", (unsigned int)*v12, v13);
v2 = -1;
}
else
{
close(v1);
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2)
{
unsigned int v1; // er12
unsigned int v2; // ebp
int *v3; // rbx
char *v4; // rax
int *v5; // rbx
char *v6; // rax
int *v7; // rbx
char *v8; // rax
int v10; // eax
int v11; // ebx
int *v12; // rbx
char *v13; // rax
char v14[56]; // [rsp+0h] [rbp-38h] BYREF

v1 = open("COMM_FILE_ONLINE", 2);
if ( v1 == -1 )
{
v5 = _errno_location();
v6 = strerror(*v5);
pr_err("Open", (unsigned int)*v5, v6);
v2 = -1;
}
else
{
while ( 1 )
{
printf("read_file_buf address = %p\n", v14);
v2 = read(v1, v14, 0xFuLL);
printf("FILE_ONLINEeFD = %d\n", v1);
printf("read_file_buf address = %p\n", v14);
printf("read_file_buf = %s\n", v14);
printf("read_file_buf address = %p\n", v14);
printf("read_file_buf = %s\n", v14);
printf("test = %d\n", v2);
if ( v2 == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
pr_err("Read", (unsigned int)*v7, v8);
return v2;
}
v2 = strcmp(v14, s2);
if ( !v2 )
break;
if ( lseek(v1, 12LL, 1) == -1 )
{
v3 = _errno_location();
v4 = strerror(*v3);
pr_err("Lseek", (unsigned int)*v3, v4);
return (unsigned int)-1;
}
}
v10 = strlen(s2);
v11 = 15 - v10;
if ( v10 != 15 )
{
do
{
write(v1, " ", 1uLL);
--v11;
}
while ( v11 );
}
if ( write(v1, " DISCONNECT\n", 0xCuLL) == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
pr_err("Write", (unsigned int)*v12, v13);
v2 = -1;
}
else
{
close(v1);
}
}
return v2;
}

original_code:
int COMM_FILE_STATE_EXCHANGE( char *EXCHANGE_IP )
{
 int FILE_ONLINE_FD;
 char read_file_buf[ 16 ] ;
 int FILE_format_control = 0;
 int test;
 if( ( FILE_ONLINE_FD = open( "COMM_FILE_ONLINE", 02 )) == -1 )
 {
  pr_err( "Open", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                return ( -1);
 }
 while ( 1 )
 {
  printf( "read_file_buf address = %p\n",&read_file_buf );
  test = read( FILE_ONLINE_FD, read_file_buf, 15 );
  printf( "FILE_ONLINEeFD = %d\n",FILE_ONLINE_FD );
  printf( "read_file_buf address = %p\n",&read_file_buf );
  printf( "read_file_buf = %s\n",read_file_buf );
  printf( "read_file_buf address = %p\n",&read_file_buf );
  printf( "read_file_buf = %s\n",read_file_buf );
  printf( "test = %d\n",test );
  if( test == -1 )
  {
   pr_err( "Read", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                 return ( -1);
  }
  else
  {
   if( strcmp( read_file_buf, EXCHANGE_IP ) == 0 )
   {
           FILE_format_control = 15 - strlen( EXCHANGE_IP );
           for( ; FILE_format_control != 0 ;FILE_format_control-- )
                   write( FILE_ONLINE_FD, " ", 1 );
    if( write( FILE_ONLINE_FD, " DISCONNECT\n", 12 ) == -1 )
    {
     pr_err( "Write", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                   return ( -1);
    }
           close( FILE_ONLINE_FD );
    break;
   }
  }
  if ( lseek( FILE_ONLINE_FD, 12, 1 ) == -1 )
  {
   pr_err( "Lseek", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                 return ( -1);
  }
 }
 return 0;
}

canonical_original_code:
int COMM_FILE_STATE_EXCHANGE(char *EXCHANGE_IP)
{
 int FILE_ONLINE_FD;
 char read_file_buf[16];
 int FILE_format_control = 0;
 int test;
 if( ( FILE_ONLINE_FD = open( "COMM_FILE_ONLINE", 02 )) == -1 )
 {
  pr_err( "Open", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                return ( -1);
 }
 while ( 1 )
 {
  printf( "read_file_buf address = %p\n",&read_file_buf );
  test = read( FILE_ONLINE_FD, read_file_buf, 15 );
  printf( "FILE_ONLINEeFD = %d\n",FILE_ONLINE_FD );
  printf( "read_file_buf address = %p\n",&read_file_buf );
  printf( "read_file_buf = %s\n",read_file_buf );
  printf( "read_file_buf address = %p\n",&read_file_buf );
  printf( "read_file_buf = %s\n",read_file_buf );
  printf( "test = %d\n",test );
  if( test == -1 )
  {
   pr_err( "Read", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                 return ( -1);
  }
  else
  {
   if( strcmp( read_file_buf, EXCHANGE_IP ) == 0 )
   {
           FILE_format_control = 15 - strlen( EXCHANGE_IP );
           for( ; FILE_format_control != 0 ;FILE_format_control-- )
                   write( FILE_ONLINE_FD, " ", 1 );
    if( write( FILE_ONLINE_FD, " DISCONNECT\n", 12 ) == -1 )
    {
     pr_err( "Write", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                   return ( -1);
    }
           close( FILE_ONLINE_FD );
    break;
   }
  }
  if ( lseek( FILE_ONLINE_FD, 12, 1 ) == -1 )
  {
   pr_err( "Lseek", (*__errno_location ()), strerror( (*__errno_location ()) ) );
                 return ( -1);
  }
 }
 return 0;
}

variable_types: test int


decompiled_code:
__int64 COMMUNICATE_SOCKET_MAKE__LISTEN()
{
unsigned int v0; // ebx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
if ( v0 == -1 )
my_err("Socket", 100LL);
optval = 2;
if ( setsockopt(v0, 1, 2, &optval, 4u) < 0 )
my_err("Socket reuse address", 105LL);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(1124);
*(_DWORD *)&addr.sa_data[2] = _bswap_32(0);
if ( bind(v0, &addr, 0x10u) == -1 )
my_err("Bind", 116LL);
if ( listen(v0, 32) == -1 )
my_err("Listen", 120LL);
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

v0 = socket(2, 1, 0);
if ( v0 == -1 )
my_err("Socket", 100LL);
optval = 2;
if ( setsockopt(v0, 1, 2, &optval, 4u) < 0 )
my_err("Socket reuse address", 105LL);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(1124);
*(_DWORD *)&addr.sa_data[2] = func1(0);
if ( bind(v0, &addr, 0x10u) == -1 )
my_err("Bind", 116LL);
if ( listen(v0, 32) == -1 )
my_err("Listen", 120LL);
return v0;
}

original_code:
int COMMUNICATE_SOCKET_MAKE__LISTEN( void )
{
 int socket_fd;
 struct sockaddr_in server;
 if( ( socket_fd = socket( 2, SOCK_STREAM, 0 )) == -1 )
  my_err( "Socket",100 );
 int opt = 2;
 if( setsockopt( socket_fd, 1, 2, &opt, sizeof( opt ) ) < 0 )
  my_err( "Socket reuse address",105 );
 bzero( &server, sizeof( server ) );
 server.sin_family = 2;
 server.sin_port = htons( 1124 );
 server.sin_addr.s_addr = htonl( ((in_addr_t) 0x00000000) );
 if( bind( socket_fd, (struct sockaddr *)&server, sizeof( server ) ) == -1 )
  my_err( "Bind",116 );
 if( listen( socket_fd, 32 ) == -1 )
  my_err( "Listen",120 );
 return socket_fd;
}

canonical_original_code:
int COMMUNICATE_SOCKET_MAKE__LISTEN()
{
 int socket_fd;
 struct sockaddr_in server;
 if( ( socket_fd = socket( 2, SOCK_STREAM, 0 )) == -1 )
  my_err( "Socket",100 );
 int opt = 2;
 if( setsockopt( socket_fd, 1, 2, &opt, sizeof( opt ) ) < 0 )
  my_err( "Socket reuse address",105 );
 bzero( &server, sizeof( server ) );
 server.sin_family = 2;
 server.sin_port = htons( 1124 );
 server.sin_addr.s_addr = htonl( ((unsigned int) 0x00000000) );
 if( bind( socket_fd, (struct sockaddr *)&server, sizeof( server ) ) == -1 )
  my_err( "Bind",116 );
 if( listen( socket_fd, 32 ) == -1 )
  my_err( "Listen",120 );
 return socket_fd;
}

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: opt int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
int v4; // ebp
int v5; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

COMM_CREATE_FILE("COMM_FILE_ONLINE", argv, envp);
v3 = COMMUNICATE_SSL_INIT(0LL);
v4 = COMMUNICATE_SOCKET_MAKE__LISTEN();
addr_len = 16;
do
{
puts("Start Successful");
v5 = accept(v4, &addr, &addr_len);
if ( v5 == -1 )
my_err("Connect", 325LL);
else
puts("A new client is connecting.");
close(v4);
}
while ( (unsigned int)COMM_SSL_PROCESS(v5, *(__int64 *)&addr.sa_family, *(__int64 *)&addr.sa_data[6], v3) != -1 );
close(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
int v4; // ebp
int v5; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

COMM_CREATE_FILE("COMM_FILE_ONLINE", argv, envp);
v3 = func2(0LL);
v4 = func3();
addr_len = 16;
do
{
puts("Start Successful");
v5 = accept(v4, &addr, &addr_len);
if ( v5 == -1 )
my_err("Connect", 325LL);
else
puts("A new client is connecting.");
close(v4);
}
while ( (unsigned int)func6(v5, *(__int64 *)&addr.sa_family, *(__int64 *)&addr.sa_data[6], v3) != -1 );
close(v4);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 recursive = false;
 format = default_format;
 time_type = time_mtime;
 ignore_mode = IGNORE_DEFAULT;
 int result;
 Fileinfo *file_array;
 opterr = 0;
 char dirname[32] = {0};
 strncpy( dirname, ".", 1 );
 while(( result = getopt(argc, argv, "aluR") ) != -1 )
 {
  switch(result)
  {
   case 'a':
    ignore_mode = IGNORE_MINIMAL;
    break;
   case 'l':
    format = long_format;
    break;
   case 'R':
    recursive = true;
    break;
   case 'u':
    time_type = time_atime;
    break;
   case '?':
    printf( "ls: %c: invalid option\n", optopt );
    printf( "ls: usage: ls [-a|-l|-R|-u] [file|dir]" );
    break;
   default:
    printf( "NO option.\n" );
    break;
  }
 }
 if( recursive == false )
 {
  file_array = get_dir( dirname );
  print_result( file_array, ignore_mode, format, time_type, recursive );
 }
 else
 {
  recursive_pend( dirname );
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 recursive = false;
 format = default_format;
 time_type = time_mtime;
 ignore_mode = IGNORE_DEFAULT;
 int result;
 struct fileinfo *file_array;
 opterr = 0;
 char dirname[32] = {0};
 strncpy( dirname, ".", 1 );
 while(( result = getopt(argc, argv, "aluR") ) != -1 )
 {
  switch(result)
  {
   case 'a':
    ignore_mode = IGNORE_MINIMAL;
    break;
   case 'l':
    format = long_format;
    break;
   case 'R':
    recursive = true;
    break;
   case 'u':
    time_type = time_atime;
    break;
   case '?':
    printf( "ls: %c: invalid option\n", optopt );
    printf( "ls: usage: ls [-a|-l|-R|-u] [file|dir]" );
    break;
   default:
    printf( "NO option.\n" );
    break;
  }
 }
 if( recursive == false )
 {
  file_array = get_dir( dirname );
  print_result( file_array, ignore_mode, format, time_type, recursive );
 }
 else
 {
  recursive_pend( dirname );
 }
 return 0;
}

variable_types: struct fileinfo { unsigned long file_nlink; unsigned int file_mode; unsigned int file_uid; unsigned int file_gid; long file_size; long file_mtime; long file_ctime; long file_atime; char *file_name; } *

variable_types:
dirname
char [32]


decompiled_code:
int __fastcall pr_err(const char *a1, unsigned int a2, const char *a3)
{
return printf("%s ERROR. Error code : %d. Error info : %s .\n", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, unsigned int a2, const char *a3)
{
return printf("%s ERROR. Error code : %d. Error info : %s .\n", a1, a2, a3);
}

original_code:
void pr_err( char *err_string,int error_code, char * err_info )
{
 printf( "%s ERROR. Error code : %d. Error info : %s .\n",err_string, error_code, err_info );
}

canonical_original_code:
void pr_err(char *err_string, int error_code, char *err_info)
{
 printf( "%s ERROR. Error code : %d. Error info : %s .\n",err_string, error_code, err_info );
}


decompiled_code:
void __fastcall __noreturn my_err(char *s, unsigned int a2)
{
fprintf(stderr, "line : %d .\n", a2);
perror(s);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *s, unsigned int a2)
{
fprintf(stderr, "line : %d .\n", a2);
perror(s);
exit(1);
}

original_code:
void my_err( const char *err_string,int line )
{
        fprintf( stderr,"line : %d .\n",line );
        perror( err_string );
        exit( 1 );
}

canonical_original_code:
void my_err(char *err_string, int line)
{
        fprintf( stderr,"line : %d .\n",line );
        perror( err_string );
        exit( 1 );
}

variable_types: line int


decompiled_code:
__int64 __fastcall parent_index(int a1)
{
return (unsigned int)((a1 - 1) / 2);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)((a1 - 1) / 2);
}

original_code:
int parent_index(int x)
{
 return (x-1)/2;
}

variable_types: x int


isMaxHeap

decompiled_code:
__int64 __fastcall isMaxHeap(int a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // er12

if ( a1 <= 1 )
return 1LL;
v2 = 1LL;
while ( 1 )
{
v3 = *(_DWORD *)(a2 + 4 * v2);
if ( v3 > *(_DWORD *)(a2 + 4LL * (int)parent_index(v2)) )
break;
if ( ++v2 == a1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // er12

if ( a1 <= 1 )
return 1LL;
v2 = 1LL;
while ( 1 )
{
v3 = *(_DWORD *)(a2 + 4 * v2);
if ( v3 > *(_DWORD *)(a2 + 4LL * (int)func0(v2)) )
break;
if ( ++v2 == a1 )
return 1LL;
}
return 0LL;
}

original_code:
int isMaxHeap(Array A)
{
 int i;
 for(i = 1; i<A.size; i++)
 {
  if(A.p[i] > A.p[parent_index(i)]) return 0;
 }
 return 1;
}

canonical_original_code:
int isMaxHeap(struct Array A)
{
 int i;
 for(i = 1; i<A.size; i++)
 {
  if(A.p[i] > A.p[parent_index(i)]) return 0;
 }
 return 1;
}

variable_types:
A
struct Array { int size; int *p; }

variable_types: i int


decompiled_code:
__int64 __fastcall child_index(int a1, char a2)
{
if ( a2 == 108 )
return 2 * a1 + 1;
if ( a2 == 114 )
return 2 * a1 + 2;
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, char a2)
{
if ( a2 == 108 )
return 2 * a1 + 1;
if ( a2 == 114 )
return 2 * a1 + 2;
return -1LL;
}

original_code:
long int child_index(int x, char which)
{
 switch(which)
 {
  case 'l':
  return (x*2 + 1);
  case 'r':
  return (x*2 + 2);
  default:
  return -1;
 }
}

canonical_original_code:
long child_index(int x, char which)
{
 switch(which)
 {
  case 'l':
  return (x*2 + 1);
  case 'r':
  return (x*2 + 2);
  default:
  return -1;
 }
}

variable_types: which char

return_type: long


merge

canonical_original_code:
void merge(struct Array A, int p, int q, int r)
{
    int i; int j; int k;
    int n = q - p + 1;
    int m = r - q;
    int L[-1]; int R[-1];
    for(i = 0; i < n; i++)
    {
        L[i] = A.p[p+i];
    }
    for(i = 0; i < m; i++)
    {
        R[i] = A.p[q+i+1];
    }
    L[n] = R[m] = 2147483647;
    i = j = 0;
    for(k=p; k <= r; k++)
    {
        if(!compare(L[i], R[j]))
            A.p[k] = L[i++];
        else
            A.p[k] = R[j++];
    }
}

variable_types: p int

variable_types: q int

variable_types: r int

variable_types: j int

variable_types: k int

variable_types: n int

variable_types: m int

variable_types:
L
int [-1]

variable_types:
R
int [-1]


decompiled_code:
signed __int64 __fastcall m_sort(__int64 a1, __int64 a2, __int64 a3, int a4)
{
int v4; // ebx
unsigned int v6; // er14
signed __int64 result; // rax

if ( (int)a3 < a4 )
{
v4 = a3;
v6 = ((int)a3 + a4) / 2;
m_sort(a1, a2, a3, v6);
m_sort((unsigned int)a1, a2, v6 + 1, (unsigned int)a4);
result = merge((unsigned int)a1, a2, v4, v6, a4);
}
return result;
}

canonical_decompiled_code:
signed __int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3, int a4)
{
int v4; // ebx
unsigned int v6; // er14
signed __int64 result; // rax

if ( (int)a3 < a4 )
{
v4 = a3;
v6 = ((int)a3 + a4) / 2;
func5(a1, a2, a3, v6);
func5((unsigned int)a1, a2, v6 + 1, (unsigned int)a4);
result = func4((unsigned int)a1, a2, v4, v6, a4);
}
return result;
}

original_code:
void m_sort(Array A, int p, int r)
{
    if(p<r)
    {
        int q = (p+r)/2;
        m_sort(A, p, q);
        m_sort(A, q+1, r);
        merge(A, p, q, r);
    }
}

canonical_original_code:
void m_sort(struct Array A, int p, int r)
{
    if(p<r)
    {
        int q = (p+r)/2;
        m_sort(A, p, q);
        m_sort(A, q+1, r);
        merge(A, p, q, r);
    }
}


swap

decompiled_code:
int *__fastcall swap(__int64 a1, __int64 a2, int a3, int a4)
{
int *v4; // rdx
int v5; // edi
int *result; // rax

v4 = (int *)(a2 + 4LL * a3);
v5 = *v4;
result = (int *)(a2 + 4LL * a4);
*v4 = *result;
*result = v5;
return result;
}

canonical_decompiled_code:
int *__fastcall func6(__int64 a1, __int64 a2, int a3, int a4)
{
int *v4; // rdx
int v5; // edi
int *result; // rax

v4 = (int *)(a2 + 4LL * a3);
v5 = *v4;
result = (int *)(a2 + 4LL * a4);
*v4 = *result;
*result = v5;
return result;
}

original_code:
void swap(Array A, int a, int b)
{
    int temp = A.p[a];
    A.p[a] = A.p[b];
    A.p[b] = temp;
}

canonical_original_code:
void swap(struct Array A, int a, int b)
{
    int temp = A.p[a];
    A.p[a] = A.p[b];
    A.p[b] = temp;
}

variable_types: a int

variable_types: b int

variable_types: temp int


original_code:
void i_sort(Array A)
{
    int i, j, k, temp;
    for(i = 1; i < A.size; i++)
    {
        k = i;
        for(j = k-1; j > -1; j--)
        {
            if(compare(A.p[j], A.p[k]))
            {
                swap(A, j, k);
                k--;
            }
            else break;
        }
    }
}

canonical_original_code:
void i_sort(struct Array A)
{
    int i; int j; int k; int temp;
    for(i = 1; i < A.size; i++)
    {
        k = i;
        for(j = k-1; j > -1; j--)
        {
            if(compare(A.p[j], A.p[k]))
            {
                swap(A, j, k);
                k--;
            }
            else break;
        }
    }
}


decompiled_code:
__int64 __fastcall max_heapify(unsigned int a1, __int64 a2, int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // r12
__int64 v9; // rax
int *v10; // r15

v6 = child_index(a3, 114);
if ( v6 < (int)a4
&& (v8 = v6, v9 = child_index(a3, 108), v10 = (int *)(a2 + 4 * v8), compare(*v10, *(_DWORD *)(a2 + 4 * v9)))
&& compare(*v10, *(_DWORD *)(a2 + 4LL * a3))
|| (result = child_index(a3, 108), LODWORD(v8) = result, (int)a4 > result)
&& (result = compare(*(_DWORD *)(a2 + 4 * result), *(_DWORD *)(a2 + 4LL * a3)), (_DWORD)result) )
{
swap(a1, a2, a3, v8);
result = max_heapify(a1, a2, (unsigned int)v8, a4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2, int a3, unsigned int a4)
{
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // r12
__int64 v9; // rax
int *v10; // r15

v6 = func2(a3, 114);
if ( v6 < (int)a4
&& (v8 = v6, v9 = func2(a3, 108), v10 = (int *)(a2 + 4 * v8), func3(*v10, *(_DWORD *)(a2 + 4 * v9)))
&& func3(*v10, *(_DWORD *)(a2 + 4LL * a3))
|| (result = func2(a3, 108), LODWORD(v8) = result, (int)a4 > result)
&& (result = func3(*(_DWORD *)(a2 + 4 * result), *(_DWORD *)(a2 + 4LL * a3)), (_DWORD)result) )
{
func6(a1, a2, a3, v8);
result = func8(a1, a2, (unsigned int)v8, a4);
}
return result;
}

original_code:
void max_heapify(Array A, int x, int size)
{
 if(child_index(x, 'r') < size && compare(A.p[child_index(x, 'r')], A.p[child_index(x, 'l')]) && compare(A.p[child_index(x, 'r')], A.p[x]))
 {
  swap(A, x, child_index(x, 'r'));
  max_heapify(A, child_index(x, 'r'), size);
 }
 else if (child_index(x, 'l') < size && compare(A.p[child_index(x, 'l')], A.p[x]))
 {
  swap(A, x, child_index(x, 'l'));
  max_heapify(A, child_index(x, 'l'), size);
 }
}

canonical_original_code:
void max_heapify(struct Array A, int x, int size)
{
 if(child_index(x, 'r') < size && compare(A.p[child_index(x, 'r')], A.p[child_index(x, 'l')]) && compare(A.p[child_index(x, 'r')], A.p[x]))
 {
  swap(A, x, child_index(x, 'r'));
  max_heapify(A, child_index(x, 'r'), size);
 }
 else if (child_index(x, 'l') < size && compare(A.p[child_index(x, 'l')], A.p[x]))
 {
  swap(A, x, child_index(x, 'l'));
  max_heapify(A, child_index(x, 'l'), size);
 }
}

variable_types: size int


decompiled_code:
int __fastcall build_max_heap(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 v2; // r14
int v3; // ebx
int result; // eax

v2 = a1;
v3 = a1 - 1;
if ( (int)a1 - 1 >= 0 )
{
do
{
v2 = v2 & 0xFFFFFFFF00000000LL | (unsigned int)a1;
max_heapify(v2, a2, v3--, a1);
}
while ( v3 != -1 );
}
result = isMaxHeap(a1, a2);
if ( !result )
result = puts("Not a max heap");
return result;
}

canonical_decompiled_code:
int __fastcall func9(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 v2; // r14
int v3; // ebx
int result; // eax

v2 = a1;
v3 = a1 - 1;
if ( (int)a1 - 1 >= 0 )
{
do
{
v2 = v2 & 0xFFFFFFFF00000000LL | (unsigned int)a1;
func8(v2, a2, v3--, a1);
}
while ( v3 != -1 );
}
result = func1(a1, a2);
if ( !result )
result = puts("Not a max heap");
return result;
}

original_code:
void build_max_heap(Array A)
{
 int i;
 for(i = A.size-1; i >= 0; i--)
 {
  max_heapify(A, i, A.size);
 }
 if(!isMaxHeap(A)) printf("Not a max heap\n");
}

canonical_original_code:
void build_max_heap(struct Array A)
{
 int i;
 for(i = A.size-1; i >= 0; i--)
 {
  max_heapify(A, i, A.size);
 }
 if(!isMaxHeap(A)) printf("Not a max heap\n");
}


decompiled_code:
int __fastcall h_sort(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 v2; // r15
int result; // eax
int v4; // ebx

v2 = a1;
result = build_max_heap(a1, a2);
v4 = a1 - 1;
if ( (int)a1 - 1 > 0 )
{
do
{
v2 = v2 & 0xFFFFFFFF00000000LL | (unsigned int)a1;
swap((unsigned int)v2, a2, 0, v4);
result = max_heapify(v2, a2, 0, v4--);
}
while ( v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(unsigned __int64 a1, __int64 a2)
{
unsigned __int64 v2; // r15
int result; // eax
int v4; // ebx

v2 = a1;
result = func9(a1, a2);
v4 = a1 - 1;
if ( (int)a1 - 1 > 0 )
{
do
{
v2 = v2 & 0xFFFFFFFF00000000LL | (unsigned int)a1;
func6((unsigned int)v2, a2, 0, v4);
result = func8(v2, a2, 0, v4--);
}
while ( v4 );
}
return result;
}

original_code:
void h_sort(Array A)
{
 int i;
 int size = A.size;
 build_max_heap(A);
 for(i = (A.size - 1); i > 0; i--)
 {
  swap(A, 0, i);
  max_heapify(A, 0, --size);
 }
}

canonical_original_code:
void h_sort(struct Array A)
{
 int i;
 int size = A.size;
 build_max_heap(A);
 for(i = (A.size - 1); i > 0; i--)
 {
  swap(A, 0, i);
  max_heapify(A, 0, --size);
 }
}


partition

decompiled_code:
__int64 __fastcall partition(unsigned int a1, __int64 a2, int a3, int a4)
{
int v5; // er13
int v6; // er12
__int64 v7; // rbx
unsigned __int64 v8; // r14
unsigned int v9; // er12

v5 = *(_DWORD *)(a2 + 4LL * a4);
v6 = a3 - 1;
if ( a4 > a3 )
{
v7 = a3;
v8 = a3 + (unsigned __int64)(unsigned int)(a4 - a3 - 1) + 1;
do
{
if ( !compare(*(_DWORD *)(a2 + 4 * v7), v5) )
swap(a1, a2, ++v6, v7);
++v7;
}
while ( v7 != v8 );
}
v9 = v6 + 1;
swap(a1, a2, v9, a4);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, __int64 a2, int a3, int a4)
{
int v5; // er13
int v6; // er12
__int64 v7; // rbx
unsigned __int64 v8; // r14
unsigned int v9; // er12

v5 = *(_DWORD *)(a2 + 4LL * a4);
v6 = a3 - 1;
if ( a4 > a3 )
{
v7 = a3;
v8 = a3 + (unsigned __int64)(unsigned int)(a4 - a3 - 1) + 1;
do
{
if ( !func3(*(_DWORD *)(a2 + 4 * v7), v5) )
func6(a1, a2, ++v6, v7);
++v7;
}
while ( v7 != v8 );
}
v9 = v6 + 1;
func6(a1, a2, v9, a4);
return v9;
}

original_code:
int partition(Array A, int p, int r)
{
    int pivot = A.p[r];
    int i = p-1;
    int j;
    for(j = p; j < r; j++)
    {
        if(!compare(A.p[j], pivot))
        {
            i++;
            swap(A, i, j);
        }
    }
    swap(A, ++i, r);
    return i;
}

canonical_original_code:
int partition(struct Array A, int p, int r)
{
    int pivot = A.p[r];
    int i = p-1;
    int j;
    for(j = p; j < r; j++)
    {
        if(!compare(A.p[j], pivot))
        {
            i++;
            swap(A, i, j);
        }
    }
    swap(A, ++i, r);
    return i;
}

variable_types: pivot int


decompiled_code:
void __fastcall q_sort(unsigned int a1, __int64 a2, int a3, int a4)
{
int v6; // er14

if ( a3 < a4 )
{
v6 = partition(a1, a2, a3, a4);
q_sort(a1, a2, (unsigned int)a3, (unsigned int)(v6 - 1));
q_sort(a1, a2, (unsigned int)(v6 + 1), (unsigned int)a4);
}
}

canonical_decompiled_code:
void __fastcall func12(unsigned int a1, __int64 a2, int a3, int a4)
{
int v6; // er14

if ( a3 < a4 )
{
v6 = func11(a1, a2, a3, a4);
func12(a1, a2, (unsigned int)a3, (unsigned int)(v6 - 1));
func12(a1, a2, (unsigned int)(v6 + 1), (unsigned int)a4);
}
}

original_code:
void q_sort(Array A, int p, int r)
{
    if(p < r)
    {
        int q = partition(A, p, r);
        q_sort(A, p, q-1);
        q_sort(A, q+1, r);
    }
}

canonical_original_code:
void q_sort(struct Array A, int p, int r)
{
    if(p < r)
    {
        int q = partition(A, p, r);
        q_sort(A, p, q-1);
        q_sort(A, q+1, r);
    }
}

variable_types:
A
struct Array { int size; int *p; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
unsigned int v4; // eax
__int64 v5; // rdx
__int64 v6; // r13
unsigned int v7; // ebp
const char *v8; // r12

if ( argc == 3 )
{
v4 = getArray(argv[2]);
v6 = v5;
v7 = v4;
v8 = argv[1];
if ( !strcmp(v8, "i") )
{
startTimer();
i_sort(v7, v6);
stopTimer();
saveArray(argv[2], "i", v7, v6);
}
else if ( !strcmp(v8, "m") )
{
startTimer();
m_sort(v7, v6, 0LL, v7 - 1);
stopTimer();
saveArray(argv[2], "m", v7, v6);
}
else if ( !strcmp(v8, "h") )
{
startTimer();
h_sort(v7, v6);
stopTimer();
saveArray(argv[2], "h", v7, v6);
}
else
{
if ( strcmp(v8, "q") )
{
printf("Nonvalid sorting argument: %s\n", v8);
exit(1);
}
startTimer();
q_sort(v7, v6, 0LL, v7 - 1);
stopTimer();
saveArray(argv[2], "q", v7, v6);
}
result = 0;
}
else
{
printf("Usage: %s [i|m|h|q] [filename]\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
    Array A;
 if(argc != 3)
 {
  printf("Usage: %s [i|m|h|q] [filename]\n", argv[0]);
  return 1;
 }
    A = getArray(argv[2]);
    if(!strcmp(argv[1], "i"))
    {
  startTimer();
  i_sort(A);
  stopTimer();
  saveArray(argv[2], "i", A);
 }
 else if(!strcmp(argv[1], "m"))
    {
  startTimer();
  m_sort(A, 0, A.size-1);
  stopTimer();
  saveArray(argv[2], "m", A);
 }
 else if(!strcmp(argv[1], "h"))
    {
  startTimer();
  h_sort(A);
  stopTimer();
  saveArray(argv[2], "h", A);
 }
 else if(!strcmp(argv[1], "q"))
    {
  startTimer();
  q_sort(A, 0, A.size-1);
  stopTimer();
  saveArray(argv[2], "q", A);
 }
 else
 {
  printf("Nonvalid sorting argument: %s\n", argv[1]);
  exit(1);
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
    struct Array A;
 if(argc != 3)
 {
  printf("Usage: %s [i|m|h|q] [filename]\n", argv[0]);
  return 1;
 }
    A = getArray(argv[2]);
    if(!strcmp(argv[1], "i"))
    {
  startTimer();
  i_sort(A);
  stopTimer();
  saveArray(argv[2], "i", A);
 }
 else if(!strcmp(argv[1], "m"))
    {
  startTimer();
  m_sort(A, 0, A.size-1);
  stopTimer();
  saveArray(argv[2], "m", A);
 }
 else if(!strcmp(argv[1], "h"))
    {
  startTimer();
  h_sort(A);
  stopTimer();
  saveArray(argv[2], "h", A);
 }
 else if(!strcmp(argv[1], "q"))
    {
  startTimer();
  q_sort(A, 0, A.size-1);
  stopTimer();
  saveArray(argv[2], "q", A);
 }
 else
 {
  printf("Nonvalid sorting argument: %s\n", argv[1]);
  exit(1);
 }
}

variable_types: argc int

variable_types:
argv
char **


printArray

decompiled_code:
int __fastcall printArray(int a1, __int64 a2)
{
__int64 v2; // rbx

if ( a1 > 0 )
{
v2 = 0LL;
do
{
printf("%d ", *(unsigned int *)(v2 + a2));
v2 += 4LL;
}
while ( v2 != 4LL * (unsigned int)a1 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(int a1, __int64 a2)
{
__int64 v2; // rbx

if ( a1 > 0 )
{
v2 = 0LL;
do
{
printf("%d ", *(unsigned int *)(v2 + a2));
v2 += 4LL;
}
while ( v2 != 4LL * (unsigned int)a1 );
}
return putchar(10);
}

original_code:
void printArray(Array A)
{
    int i;
    for(i = 0; i < A.size; i++)
    {
        printf("%d ", *(A.p+i));
    }
    printf("\n");
}

canonical_original_code:
void printArray(struct Array A)
{
    int i;
    for(i = 0; i < A.size; i++)
    {
        printf("%d ", *(A.p+i));
    }
    printf("\n");
}

variable_types: i int


startTimer

decompiled_code:
int startTimer()
{
compCount = 0LL;
return clock_gettime(1, &t1);
}

canonical_decompiled_code:
int func2()
{
compCount = 0LL;
return clock_gettime(1, &t1);
}

original_code:
void startTimer(void)
{
 compCount = 0;
 clock_gettime(1, &t1);
}

canonical_original_code:
void startTimer()
{
 compCount = 0;
 clock_gettime(1, &t1);
}


stopTimer

decompiled_code:
__int64 stopTimer()
{
__int64 result; // rax

clock_gettime(1, &t2);
result = 0x431BDE82D7B634DBLL * (t2.tv_nsec - t1.tv_nsec);
sortTime = (t2.tv_nsec - t1.tv_nsec) / 1000000 + 1000 * (t2.tv_sec - t1.tv_sec);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax

clock_gettime(1, &t2);
result = 0x431BDE82D7B634DBLL * (t2.tv_nsec - t1.tv_nsec);
sortTime = (t2.tv_nsec - t1.tv_nsec) / 1000000 + 1000 * (t2.tv_sec - t1.tv_sec);
return result;
}

original_code:
void stopTimer(void)
{
 clock_gettime(1, &t2);
 sortTime = (t2.tv_sec - t1.tv_sec)*1000;
 sortTime += (t2.tv_nsec - t1.tv_nsec)/1000000;
}

canonical_original_code:
void stopTimer()
{
 clock_gettime(1, &t2);
 sortTime = (t2.tv_sec - t1.tv_sec)*1000;
 sortTime += (t2.tv_nsec - t1.tv_nsec)/1000000;
}


isSorted

decompiled_code:
__int64 __fastcall isSorted(int a1, _DWORD *a2)
{
__int64 result; // rax
_DWORD *v3; // rax

result = 1LL;
if ( a1 > 1 )
{
v3 = a2;
while ( *v3 <= v3[1] )
{
if ( ++v3 == &a2[a1 - 2 + 1] )
return 1LL;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, _DWORD *a2)
{
__int64 result; // rax
_DWORD *v3; // rax

result = 1LL;
if ( a1 > 1 )
{
v3 = a2;
while ( *v3 <= v3[1] )
{
if ( ++v3 == &a2[a1 - 2 + 1] )
return 1LL;
}
result = 0LL;
}
return result;
}

original_code:
int isSorted(Array A)
{
 int i, j;
 if(A.size < 1) return 1;
 for(i = 0, j = 1; j < A.size; i++, j++)
 {
  if(A.p[i] > A.p[j]) return 0;
 }
 return 1;
}

canonical_original_code:
int isSorted(struct Array A)
{
 int i; int j;
 if(A.size < 1) return 1;
 for(i = 0, j = 1; j < A.size; i++, j++)
 {
  if(A.p[i] > A.p[j]) return 0;
 }
 return 1;
}


compare

repo: CrizMobius/ParallelQuicksort

decompiled_code:
__int64 __fastcall compare(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a1 - *(_DWORD *)a2);
}

original_code:
int compare(const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}

canonical_original_code:
int compare(void *a, void *b)
{
  return ( *(int *)a - *(int *)b );
}

variable_types:
a
void *

variable_types:
b
void *


comparePivot

decompiled_code:
__int64 __fastcall comparePivot(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 1) - *((_DWORD *)a2 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func8(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a1 + 1) - *((_DWORD *)a2 + 1));
}

original_code:
int comparePivot(const void * a, const void * b)
{
  return (((struct Pivot*)a)->value - ((struct Pivot*)b)->value);
}

canonical_original_code:
int comparePivot(void *a, void *b)
{
  return (((struct Pivot *)a)->value - ((struct Pivot *)b)->value);
}


initWorkerData

decompiled_code:
void initWorkerData()
{
int *v0; // rax
int *v1; // rdx

if ( g_maxWorkers > 0 )
{
v0 = &g_workerData;
v1 = (int *)((char *)&unk_404198 + 24 * (unsigned int)(g_maxWorkers - 1));
do
{
*v0 = 0;
*((_QWORD *)v0 + 1) = 0LL;
v0[4] = 0;
v0[5] = 0;
v0 += 6;
}
while ( v0 != v1 );
}
}

original_code:
void initWorkerData()
{
 int i;
 for(i = 0; i < g_maxWorkers; i++)
 {
  g_workerData[i].id = 0;
  g_workerData[i].start = 0;
  g_workerData[i].n = 0;
  g_workerData[i].size = 0;
 }
}


generate

decompiled_code:
void __fastcall generate(int *a1, int *a2)
{
int *i; // rbx

for ( i = a1; a2 != i; ++i )
*i = rand() % 100;
}

canonical_decompiled_code:
void __fastcall func10(int *a1, int *a2)
{
int *i; // rbx

for ( i = a1; a2 != i; ++i )
*i = rand() % 100;
}

original_code:
void generate(int * start, int * end)
{
 if(start == end)
  return;
 while(start != end)
 {
  *start = rand() % 100;
  start++;
 }
}

canonical_original_code:
void generate(int *start, int *end)
{
 if(start == end)
  return;
 while(start != end)
 {
  *start = rand() % 100;
  start++;
 }
}

variable_types:
start
int *

variable_types:
end
int *


isSorted

decompiled_code:
__int64 __fastcall isSorted(__int64 a1, _DWORD *a2)
{
_DWORD *v2; // rdi

v2 = (_DWORD *)(a1 + 4);
if ( v2 == a2 )
return 1LL;
while ( *(v2 - 1) <= *v2 )
{
if ( a2 == ++v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, _DWORD *a2)
{
_DWORD *v2; // rdi

v2 = (_DWORD *)(a1 + 4);
if ( v2 == a2 )
return 1LL;
while ( *(v2 - 1) <= *v2 )
{
if ( a2 == ++v2 )
return 1LL;
}
return 0LL;
}

original_code:
_Bool isSorted(int * start, int * end)
{
 start++;
 if(start == end)
  return 1;
 while(start != end)
 {
  if(*(start - 1) > *(start))
   return 0;
  start++;
 }
 return 1;
}

canonical_original_code:
_Bool isSorted(int *start, int *end)
{
 start++;
 if(start == end)
  return 1;
 while(start != end)
 {
  if(*(start - 1) > *(start))
   return 0;
  start++;
 }
 return 1;
}


getPivot

decompiled_code:
__int64 __fastcall getPivot(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // er14
int *v4; // rbx
int v5; // eax
int v6[30]; // [rsp+0h] [rbp-78h] BYREF

result = 0LL;
if ( a2 > 1 )
{
v3 = 10;
if ( a2 <= 10 )
v3 = a2;
v4 = v6;
do
{
v5 = rand();
*v4 = v5 % a2;
v4[1] = *(_DWORD *)(a1 + 4LL * (v5 % a2));
v4 += 2;
}
while ( v4 != &v6[2 * (v3 - 1) + 2] );
qsort(v6, v3, 8uLL, (__compar_fn_t)comparePivot);
result = (unsigned int)v6[2 * (v3 / 2)];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
__int64 result; // rax
int v3; // er14
int *v4; // rbx
int v5; // eax
int v6[30]; // [rsp+0h] [rbp-78h] BYREF

result = 0LL;
if ( a2 > 1 )
{
v3 = 10;
if ( a2 <= 10 )
v3 = a2;
v4 = v6;
do
{
v5 = rand();
*v4 = v5 % a2;
v4[1] = *(_DWORD *)(a1 + 4LL * (v5 % a2));
v4 += 2;
}
while ( v4 != &v6[2 * (v3 - 1) + 2] );
qsort(v6, v3, 8uLL, (__compar_fn_t)comparePivot);
result = (unsigned int)v6[2 * (v3 / 2)];
}
return result;
}

original_code:
int getPivot(int * start, int n)
{
 if(n < 2)
  return 0;
 struct Pivot pivots[10];
 int maxPivots = (10 > n)? n : 10;
 int i;
 for(i = 0; i < maxPivots; i++)
 {
  int index = rand() % n;
  pivots[i].index = index;
  pivots[i].value = start[index];
 }
 qsort(&pivots[0], maxPivots, sizeof(struct Pivot), comparePivot);
 int pivot = pivots[maxPivots / 2].index;
 return pivot;
}

canonical_original_code:
int getPivot(int *start, int n)
{
 if(n < 2)
  return 0;
 struct Pivot pivots[10];
 int maxPivots = (10 > n)? n : 10;
 int i;
 for(i = 0; i < maxPivots; i++)
 {
  int index = rand() % n;
  pivots[i].index = index;
  pivots[i].value = start[index];
 }
 qsort(&pivots[0], maxPivots, sizeof(struct Pivot), comparePivot);
 int pivot = pivots[maxPivots / 2].index;
 return pivot;
}

variable_types: n int

variable_types: struct Pivot { int index; int value; } [10]

variable_types: maxPivots int

variable_types: index int


swap

decompiled_code:
__int64 __fastcall swap(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap(int * a, int * b)
{
 int tmp = *a;
 *a = *b;
 *b = tmp;
}

canonical_original_code:
void swap(int *a, int *b)
{
 int tmp = *a;
 *a = *b;
 *b = tmp;
}

variable_types:
a
int *

variable_types:
b
int *

variable_types: tmp int


parallelQuicksort

decompiled_code:
void __fastcall parallelQuicksort(char *a1, int a2, unsigned int a3)
{
int v3; // eax
char *v4; // r14
char *v5; // rbx
unsigned int v6; // er13
int *v7; // rcx
unsigned int v8; // eax
int v10; // [rsp+4h] [rbp-54h]
__int64 v11; // [rsp+8h] [rbp-50h]
void *thread_return; // [rsp+18h] [rbp-40h] BYREF

if ( a2 <= 99 )
{
qsort(a1, a2, 4uLL, (__compar_fn_t)compare);
}
else
{
pthread_mutex_lock(&g_lock);
v10 = g_activeWorkers;
if ( g_activeWorkers >= g_maxWorkers )
{
pthread_mutex_unlock(&g_lock);
qsort(a1, a2, 4uLL, (__compar_fn_t)compare);
}
else
{
v11 = g_activeWorkers++;
pthread_mutex_unlock(&g_lock);
v3 = getPivot((__int64)a1, a2);
v4 = &a1[4 * a2 - 4];
swap(&a1[4 * v3], v4);
v5 = a1;
v6 = 0;
do
{
if ( *(_DWORD *)v5 < *(_DWORD *)v4 )
swap(v5, &a1[4 * v6++]);
v5 += 4;
}
while ( v5 != &a1[4 * (a2 - 2) + 4] );
swap(&a1[4 * v6], v4);
v7 = &g_workerData[6 * v11];
*v7 = v10;
*((_QWORD *)v7 + 1) = &a1[4 * v6];
v7[4] = a2 - v6;
v7[5] = a3;
pthread_create(&workers[v11], &g_attr, startThread, v7);
parallelQuicksort(a1, v6, a3);
v8 = pthread_join(workers[v11], &thread_return);
if ( v8 )
{
printf("ERROR; return code from pthread_join() is %d\n", v8);
exit(-1);
}
}
}
}

canonical_decompiled_code:
void __fastcall func14(char *a1, int a2, unsigned int a3)
{
int v3; // eax
char *v4; // r14
char *v5; // rbx
unsigned int v6; // er13
int *v7; // rcx
unsigned int v8; // eax
int v10; // [rsp+4h] [rbp-54h]
__int64 v11; // [rsp+8h] [rbp-50h]
void *thread_return; // [rsp+18h] [rbp-40h] BYREF

if ( a2 <= 99 )
{
qsort(a1, a2, 4uLL, (__compar_fn_t)compare);
}
else
{
pthread_mutex_lock(&g_lock);
v10 = g_activeWorkers;
if ( g_activeWorkers >= g_maxWorkers )
{
pthread_mutex_unlock(&g_lock);
qsort(a1, a2, 4uLL, (__compar_fn_t)compare);
}
else
{
v11 = g_activeWorkers++;
pthread_mutex_unlock(&g_lock);
v3 = func12((__int64)a1, a2);
v4 = &a1[4 * a2 - 4];
func13(&a1[4 * v3], v4);
v5 = a1;
v6 = 0;
do
{
if ( *(_DWORD *)v5 < *(_DWORD *)v4 )
func13(v5, &a1[4 * v6++]);
v5 += 4;
}
while ( v5 != &a1[4 * (a2 - 2) + 4] );
func13(&a1[4 * v6], v4);
v7 = &g_workerData[6 * v11];
*v7 = v10;
*((_QWORD *)v7 + 1) = &a1[4 * v6];
v7[4] = a2 - v6;
v7[5] = a3;
pthread_create(&workers[v11], &g_attr, startThread, v7);
func14(a1, v6, a3);
v8 = pthread_join(workers[v11], &thread_return);
if ( v8 )
{
printf("ERROR; return code from pthread_join() is %d\n", v8);
exit(-1);
}
}
}
}

original_code:
void parallelQuicksort(int * start, int n, int size)
{
 if(n < g_sortCutoff)
 {
  qsort(start, n, sizeof(int), compare);
  return;
 }
 pthread_mutex_lock(&g_lock);
 if(g_activeWorkers < g_maxWorkers)
 {
  pthread_t worker = g_activeWorkers;
  g_activeWorkers++;
  pthread_mutex_unlock(&g_lock);
  int pivotIndex = getPivot(start, n);
  int right = n - 1;
  swap(&start[pivotIndex], &start[right]);
  int storeIndex = 0;
  int i;
  for(i = 0; i < right; i++)
  {
   if(start[i] < start[right])
   {
    swap(&start[i], &start[storeIndex]);
    storeIndex++;
   }
  }
  swap(&start[storeIndex], &start[right]);
  pivotIndex = storeIndex;
  g_workerData[worker].id = worker;
  g_workerData[worker].start = start + pivotIndex;
  g_workerData[worker].n = n - pivotIndex;
  g_workerData[worker].size = size;
  pthread_create(&workers[worker], &g_attr, startThread, (void *) &g_workerData[worker]);
  parallelQuicksort(start, pivotIndex, size);
  void * status;
  int rc = pthread_join(workers[worker], &status);
  if(rc)
  {
   printf("ERROR; return code from pthread_join() is %d\n", rc);
   exit(-1);
  }
 }
 else
 {
  pthread_mutex_unlock(&g_lock);
  qsort(start, n, sizeof(int), compare);
 }
}

canonical_original_code:
void parallelQuicksort(int *start, int n, int size)
{
 if(n < g_sortCutoff)
 {
  qsort(start, n, sizeof(int), compare);
  return;
 }
 pthread_mutex_lock(&g_lock);
 if(g_activeWorkers < g_maxWorkers)
 {
  unsigned long worker = g_activeWorkers;
  g_activeWorkers++;
  pthread_mutex_unlock(&g_lock);
  int pivotIndex = getPivot(start, n);
  int right = n - 1;
  swap(&start[pivotIndex], &start[right]);
  int storeIndex = 0;
  int i;
  for(i = 0; i < right; i++)
  {
   if(start[i] < start[right])
   {
    swap(&start[i], &start[storeIndex]);
    storeIndex++;
   }
  }
  swap(&start[storeIndex], &start[right]);
  pivotIndex = storeIndex;
  g_workerData[worker].id = worker;
  g_workerData[worker].start = start + pivotIndex;
  g_workerData[worker].n = n - pivotIndex;
  g_workerData[worker].size = size;
  pthread_create(&workers[worker], &g_attr, startThread, (void *) &g_workerData[worker]);
  parallelQuicksort(start, pivotIndex, size);
  void *status;
  int rc = pthread_join(workers[worker], &status);
  if(rc)
  {
   printf("ERROR; return code from pthread_join() is %d\n", rc);
   exit(-1);
  }
 }
 else
 {
  pthread_mutex_unlock(&g_lock);
  qsort(start, n, sizeof(int), compare);
 }
}

variable_types: size int

variable_types:
worker
unsigned long

variable_types: pivotIndex int

variable_types: right int

variable_types: storeIndex int

variable_types:
status
void *

variable_types: rc int


startThread

decompiled_code:
void __fastcall __noreturn startThread(void *a1)
{
parallelQuicksort(*((char **)a1 + 1), *((_DWORD *)a1 + 4), *((_DWORD *)a1 + 5));
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func15(void *a1)
{
func14(*((char **)a1 + 1), *((_DWORD *)a1 + 4), *((_DWORD *)a1 + 5));
pthread_exit(0LL);
}

original_code:
void * startThread(void * data)
{
 struct WorkerData * p = (struct WorkerData *) data;
 int id = p->id;
 parallelQuicksort(p->start, p->n, p->size);
 pthread_exit(0);
}

canonical_original_code:
void *startThread(void *data)
{
 struct WorkerData *p = (struct WorkerData *) data;
 int id = p->id;
 parallelQuicksort(p->start, p->n, p->size);
 pthread_exit(0);
}

variable_types:
data
void *

variable_types: struct WorkerData { int id; int *start; int n; int size; } *

variable_types: id int

return_type: void *


printArray

decompiled_code:
int __fastcall printArray(unsigned int *a1, unsigned int *a2)
{
unsigned int *v2; // rbx
int result; // eax

v2 = a1;
if ( a1 != a2 )
{
do
printf("%d ", *v2++);
while ( a2 != v2 );
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(unsigned int *a1, unsigned int *a2)
{
unsigned int *v2; // rbx
int result; // eax

v2 = a1;
if ( a1 != a2 )
{
do
printf("%d ", *v2++);
while ( a2 != v2 );
result = putchar(10);
}
return result;
}

original_code:
void printArray(int * start, int * end)
{
 if(start == end)
  return;
 while(start != end)
 {
  printf("%d ", *start);
  start++;
 }
 printf("\n");
}

canonical_original_code:
void printArray(int *start, int *end)
{
 if(start == end)
  return;
 while(start != end)
 {
  printf("%d ", *start);
  start++;
 }
 printf("\n");
}

variable_types:
start
int *

variable_types:
end
int *


readTimer

decompiled_code:
double readTimer()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( !initialized_1 )
{
gettimeofday(&start_0, 0LL);
initialized_1 = 1;
}
gettimeofday(&v1, 0LL);
return (double)(LODWORD(v1.tv_usec) - LODWORD(start_0.tv_usec)) * 0.000001
+ (double)(LODWORD(v1.tv_sec) - LODWORD(start_0.tv_sec));
}

canonical_decompiled_code:
double func17()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( !initialized_1 )
{
gettimeofday(&start_0, 0LL);
initialized_1 = 1;
}
gettimeofday(&v1, 0LL);
return (double)(LODWORD(v1.tv_usec) - LODWORD(start_0.tv_usec)) * 0.000001
+ (double)(LODWORD(v1.tv_sec) - LODWORD(start_0.tv_sec));
}

original_code:
double readTimer()
{
 static _Bool initialized = 0;
 static struct timeval start;
 struct timeval end;
 if( !initialized )
 {
  gettimeofday( &start, ((void *)0) );
  initialized = 1;
 }
 gettimeofday( &end, ((void *)0) );
 return (end.tv_sec - start.tv_sec) + 1.0e-6 * (end.tv_usec - start.tv_usec);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }

return_type: double


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
int v4; // eax

if ( argc <= 1 )
{
g_maxSize = (int)&unk_5F5E100;
v3 = &unk_5F5E100;
}
else
{
LODWORD(v3) = atoi(argv[1]);
g_maxSize = (int)v3;
if ( argc > 2 )
{
v4 = atoi(argv[2]);
g_maxWorkers = v4;
if ( (int)v3 <= (int)&unk_5F5E100 )
goto LABEL_5;
goto LABEL_4;
}
}
g_maxWorkers = 100;
if ( (int)v3 <= (int)&unk_5F5E100 )
goto LABEL_7;
v4 = 100;
LABEL_4:
g_maxSize = (int)&unk_5F5E100;
LABEL_5:
if ( v4 > 100 )
g_maxWorkers = 100;
LABEL_7:
initWorkerData();
generate(g_arrayData, &g_arrayData[g_maxSize]);
pthread_attr_init(&g_attr);
pthread_attr_setscope(&g_attr, 0);
pthread_attr_setdetachstate(&g_attr, 0);
pthread_mutex_init(&g_lock, 0LL);
g_startTime = readTimer();
parallelQuicksort((char *)g_arrayData, g_maxSize, 4u);
*(double *)&g_finalTime = readTimer() - *(double *)&g_startTime;
if ( (unsigned __int8)isSorted((__int64)g_arrayData, &g_arrayData[g_maxSize]) )
puts("Array is sorted");
else
puts("Array is not sorted");
printf("The execution time is %g sec\n", *(double *)&g_finalTime);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r12
int v4; // eax

if ( argc <= 1 )
{
g_maxSize = (int)&unk_5F5E100;
v3 = &unk_5F5E100;
}
else
{
LODWORD(v3) = atoi(argv[1]);
g_maxSize = (int)v3;
if ( argc > 2 )
{
v4 = atoi(argv[2]);
g_maxWorkers = v4;
if ( (int)v3 <= (int)&unk_5F5E100 )
goto LABEL_5;
goto LABEL_4;
}
}
g_maxWorkers = 100;
if ( (int)v3 <= (int)&unk_5F5E100 )
goto LABEL_7;
v4 = 100;
LABEL_4:
g_maxSize = (int)&unk_5F5E100;
LABEL_5:
if ( v4 > 100 )
g_maxWorkers = 100;
LABEL_7:
func9();
func10(g_arrayData, &g_arrayData[g_maxSize]);
pthread_attr_init(&g_attr);
pthread_attr_setscope(&g_attr, 0);
pthread_attr_setdetachstate(&g_attr, 0);
pthread_mutex_init(&g_lock, 0LL);
g_startTime = func17();
func14((char *)g_arrayData, g_maxSize, 4u);
*(double *)&g_finalTime = func17() - *(double *)&g_startTime;
if ( (unsigned __int8)func11((__int64)g_arrayData, &g_arrayData[g_maxSize]) )
puts("Array is sorted");
else
puts("Array is not sorted");
printf("The execution time is %g sec\n", *(double *)&g_finalTime);
return 0;
}

original_code:
int main(int argc, const char * argv [])
{
 g_maxSize = (argc > 1)? atoi(argv[1]) : 100000000;
 g_maxWorkers = (argc > 2)? atoi(argv[2]) : 100;
 if(g_maxSize > 100000000) g_maxSize = 100000000;
 if(g_maxWorkers > 100) g_maxWorkers = 100;
 initWorkerData();
 generate(&g_arrayData[0], &g_arrayData[g_maxSize]);
 pthread_attr_init(&g_attr);
 pthread_attr_setscope(&g_attr, PTHREAD_SCOPE_SYSTEM);
 pthread_attr_setdetachstate(&g_attr, PTHREAD_CREATE_JOINABLE);
 pthread_mutex_init(&g_lock, ((void *)0));
 g_startTime = readTimer();
 parallelQuicksort(&g_arrayData[0], g_maxSize, sizeof(int));
 g_finalTime = readTimer() - g_startTime;
 if(isSorted(&g_arrayData[0], &g_arrayData[g_maxSize]))
 {
  printf("Array is sorted\n");
 }
 else
 {
  printf("Array is not sorted\n");
 }
 printf("The execution time is %g sec\n", g_finalTime);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 g_maxSize = (argc > 1)? atoi(argv[1]) : 100000000;
 g_maxWorkers = (argc > 2)? atoi(argv[2]) : 100;
 if(g_maxSize > 100000000) g_maxSize = 100000000;
 if(g_maxWorkers > 100) g_maxWorkers = 100;
 initWorkerData();
 generate(&g_arrayData[0], &g_arrayData[g_maxSize]);
 pthread_attr_init(&g_attr);
 pthread_attr_setscope(&g_attr, PTHREAD_SCOPE_SYSTEM);
 pthread_attr_setdetachstate(&g_attr, PTHREAD_CREATE_JOINABLE);
 pthread_mutex_init(&g_lock, ((void *)0));
 g_startTime = readTimer();
 parallelQuicksort(&g_arrayData[0], g_maxSize, sizeof(int));
 g_finalTime = readTimer() - g_startTime;
 if(isSorted(&g_arrayData[0], &g_arrayData[g_maxSize]))
 {
  printf("Array is sorted\n");
 }
 else
 {
  printf("Array is not sorted\n");
 }
 printf("The execution time is %g sec\n", g_finalTime);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: Cwndmiao/GoogleCodeJam

original_code:
void solve1(int cur, unsigned long arg1) {
    struct node *root_node = ((void *)0);
    struct node *leaf_node = ((void *)0);
    struct node *cur_node = (struct node*)malloc(sizeof(struct node));
    leaf_node = cur_node;
    cur_node->index = arg1;
    while (cur_node->index != 1) {
        struct node *par_node = (struct node*)malloc(sizeof(struct node));
        cur_node->parent = par_node;
        par_node->parent = ((void *)0);
        par_node->child = cur_node;
        if (cur_node->index % 2) {
            par_node->left = 0;
        } else {
            par_node->left = 1;
        }
        par_node->index = cur_node->index / 2;
        cur_node = par_node;
    }
    root_node = cur_node;
    root_node->parent = ((void *)0);
    root_node->fenzi = root_node->fenmu = 1;
    root_node->index = 1;
    cur_node = root_node->child;
    while (cur_node != leaf_node) {
        if (cur_node->parent->left) {
            cur_node->fenzi = cur_node->parent->fenzi;
            cur_node->fenmu = cur_node->parent->fenzi + cur_node->parent->fenmu;
        } else {
            cur_node->fenzi = cur_node->parent->fenzi + cur_node->parent->fenmu;
            cur_node->fenmu = cur_node->parent->fenmu;
        }
        cur_node = cur_node->child;
    }
    if (cur_node->parent->left) {
        cur_node->fenzi = cur_node->parent->fenzi;
        cur_node->fenmu = cur_node->parent->fenzi + cur_node->parent->fenmu;
    } else {
        cur_node->fenzi = cur_node->parent->fenzi + cur_node->parent->fenmu;
        cur_node->fenmu = cur_node->parent->fenmu;
    }
    printf("Case #%d: %lu %lu\n", cur + 1, cur_node->fenzi, cur_node->fenmu);
    while (cur_node != root_node) {
        struct node *child_node = cur_node;
        cur_node = cur_node->parent;
        free(child_node);
    }
    free(cur_node);
    return;
}

variable_types: cur int

variable_types: struct node { struct node *parent; struct node *child; unsigned long fenzi; unsigned long fenmu; unsigned long index; _Bool left; } *


original_code:
void solve2(int cur, unsigned long arg1, unsigned long arg2) {
    struct node *root_node = ((void *)0);
    struct node *leaf_node = ((void *)0);
    struct node *cur_node = (struct node*)malloc(sizeof(struct node));
    leaf_node = cur_node;
    cur_node->child = ((void *)0);
    cur_node->fenzi = arg1;
    cur_node->fenmu = arg2;
    while (cur_node->fenzi != 1 || cur_node->fenmu != 1) {
        struct node *new_node = (struct node*)malloc(sizeof(struct node));
        cur_node->parent = new_node;
        new_node->child = cur_node;
        new_node->parent = ((void *)0);
        if (cur_node->fenzi > cur_node->fenmu) {
            new_node->left = 0;
            new_node->fenzi = cur_node->fenzi - cur_node->fenmu;
            new_node->fenmu = cur_node->fenmu;
        } else if (cur_node->fenzi < cur_node->fenmu) {
            new_node->left = 1;
            new_node->fenzi = cur_node->fenzi;
            new_node->fenmu = cur_node->fenmu - cur_node->fenzi;
        }
        cur_node = new_node;
    }
    root_node = cur_node;
    root_node->index = 1;
    cur_node = root_node->child;
    while (cur_node != leaf_node) {
        if (cur_node->parent->left) {
            cur_node->index = cur_node->parent->index * 2;
        } else {
            cur_node->index = cur_node->parent->index * 2 + 1;
        }
        cur_node = cur_node->child;
    }
    if (cur_node->parent->left) {
        cur_node->index = cur_node->parent->index * 2;
    } else {
        cur_node->index = cur_node->parent->index * 2 + 1;
    }
    printf("Case #%d: %lu\n", cur + 1, cur_node->index);
    while (cur_node != root_node) {
        struct node *child_node = cur_node;
        cur_node = cur_node->parent;
        free(child_node);
    }
    free(cur_node);
    return;
}

user_defined_types: struct node { struct node *parent; struct node *child; unsigned long fenzi; unsigned long fenmu; unsigned long index; _Bool left; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // ebp
int i; // ebx
size_t n; // [rsp+10h] [rbp-28h] BYREF
char *lineptr[4]; // [rsp+18h] [rbp-20h] BYREF

lineptr[0] = 0LL;
n = 0LL;
getline(lineptr, &n, stdin);
v3 = lineptr[0];
v4 = atoi(lineptr[0]);
free(v3);
lineptr[0] = 0LL;
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
{
getline(lineptr, &n, stdin);
if ( *lineptr[0] == 49 )
{
__isoc99_sscanf();
solve1(i, 0LL);
}
else if ( *lineptr[0] == 50 )
{
__isoc99_sscanf();
solve2(i, 0LL, 0LL);
}
free(lineptr[0]);
lineptr[0] = 0LL;
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
int v4; // ebp
int i; // ebx
size_t n; // [rsp+10h] [rbp-28h] BYREF
char *lineptr[4]; // [rsp+18h] [rbp-20h] BYREF

lineptr[0] = 0LL;
n = 0LL;
getline(lineptr, &n, stdin);
v3 = lineptr[0];
v4 = atoi(lineptr[0]);
free(v3);
lineptr[0] = 0LL;
if ( v4 > 0 )
{
for ( i = 0; i != v4; ++i )
{
getline(lineptr, &n, stdin);
if ( *lineptr[0] == 49 )
{
__isoc99_sscanf();
func7(i, 0LL);
}
else if ( *lineptr[0] == 50 )
{
__isoc99_sscanf();
func8(i, 0LL, 0LL);
}
free(lineptr[0]);
lineptr[0] = 0LL;
}
}
return 0;
}

original_code:
int main(int argc, char **argv) {
    char *input_buf = ((void *)0);
    size_t input_size = 0;
    int total_cases = 0;
    int cur_case = 0;
    getline(&input_buf, &input_size, stdin);
    total_cases = atoi(input_buf);
    free(input_buf);
    input_buf = ((void *)0);
    while (cur_case < total_cases) {
        unsigned long arg1 = 0;
        unsigned long arg2 = 0;
        getline(&input_buf, &input_size, stdin);
        if (input_buf[0] == '1') {
            sscanf(input_buf, "1 %lu\n", &arg1);
            solve1(cur_case, arg1);
        } else if (input_buf[0] == '2') {
            sscanf(input_buf, "2 %lu %lu\n", &arg1, &arg2);
            solve2(cur_case, arg1, arg2);
        }
        free(input_buf);
        input_buf = ((void *)0);
        cur_case++;
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    char *input_buf = ((void *)0);
    unsigned long input_size = 0;
    int total_cases = 0;
    int cur_case = 0;
    getline(&input_buf, &input_size, stdin);
    total_cases = atoi(input_buf);
    free(input_buf);
    input_buf = ((void *)0);
    while (cur_case < total_cases) {
        unsigned long arg1 = 0;
        unsigned long arg2 = 0;
        getline(&input_buf, &input_size, stdin);
        if (input_buf[0] == '1') {
            sscanf(input_buf, "1 %lu\n", &arg1);
            solve1(cur_case, arg1);
        } else if (input_buf[0] == '2') {
            sscanf(input_buf, "2 %lu %lu\n", &arg1, &arg2);
            solve2(cur_case, arg1, arg2);
        }
        free(input_buf);
        input_buf = ((void *)0);
        cur_case++;
    }
    return 0;
}

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall GEN_rand(unsigned int *a1)
{
unsigned int v1; // eax

v1 = -1640531535 * *a1 - 2048144777;
*a1 = v1;
return v1 >> 11;
}

original_code:
static unsigned int GEN_rand (unsigned int* seed)
{
    *seed = ((*seed) * 2654435761U) + 2246822519U;
    return (*seed) >> 11;
}

canonical_original_code:
static unsigned int GEN_rand(unsigned int *seed)
{
    *seed = ((*seed) * 2654435761U) + 2246822519U;
    return (*seed) >> 11;
}

variable_types:
seed
unsigned int *

return_type: unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
double v4; // xmm0_8
char v5; // al
char v7[34]; // [rsp+6h] [rbp-22h] BYREF

strcpy(v7, "proba.bin");
g_programName = (__int64)*argv;
fwrite("Binary file generator\n", 1uLL, 0x16uLL, _bss_start);
if ( argc <= 1 )
badusage();
v3 = argv[1];
v4 = 0.0;
if ( (unsigned __int8)(*v3 - 48) <= 9u )
{
v4 = (double)(*v3 - 48) + 0.0;
v5 = v3[1];
if ( (unsigned __int8)(v5 - 48) <= 9u )
v4 = v4 * 10.0 + (double)(v5 - 48);
}
createSampleFile(v7, v4 / 100.0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
double v4; // xmm0_8
char v5; // al
char v7[34]; // [rsp+6h] [rbp-22h] BYREF

strcpy(v7, "proba.bin");
g_programName = (__int64)*argv;
fwrite("Binary file generator\n", 1uLL, 0x16uLL, _bss_start);
if ( argc <= 1 )
func10();
v3 = argv[1];
v4 = 0.0;
if ( (unsigned __int8)(*v3 - 48) <= 9u )
{
v4 = (double)(*v3 - 48) + 0.0;
v5 = v3[1];
if ( (unsigned __int8)(v5 - 48) <= 9u )
v4 = v4 * 10.0 + (double)(v5 - 48);
}
func11(v7, v4 / 100.0);
return 0;
}

original_code:
int main(int argc, char** argv)
{
    char* n;
    double proba = 0.;
    char filename[] = "proba.bin";
    g_programName = argv[0];
    fprintf(stderr, "Binary file generator\n");
    if (argc<2) badusage();
    n = argv[1];
    if ((*n>='0') && (*n<='9')) { proba += *n-'0'; n++; }
    if ((*n>='0') && (*n<='9')) { proba*=10; proba += *n-'0'; n++; }
    proba /= 100;
    createSampleFile(filename, proba);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char *n;
    double proba = 0.;
    char filename[] = "proba.bin";
    g_programName = argv[0];
    fprintf(stderr, "Binary file generator\n");
    if (argc<2) badusage();
    n = argv[1];
    if ((*n>='0') && (*n<='9')) { proba += *n-'0'; n++; }
    if ((*n>='0') && (*n<='9')) { proba*=10; proba += *n-'0'; n++; }
    proba /= 100;
    createSampleFile(filename, proba);
    return 0;
}

variable_types:
n
char *

variable_types: proba double

variable_types:
filename
char []


decompiled_code:
__int64 lookup_null_sym()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
static int lookup_null_sym(void *pc, struct loc_result *location)
{
 return 1;
}

variable_types:
pc
void *

variable_types: struct loc_result { char *symbol; unsigned long long offset; } *


decompiled_code:
__int64 lookup_null_init()
{
puts("Initalizing null lookup method");
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
puts("Initalizing null lookup method");
return 0LL;
}

original_code:
static int lookup_null_init(void)
{
 printf("Initalizing null lookup method\n");
 return 0;
}

canonical_original_code:
static int lookup_null_init()
{
 printf("Initalizing null lookup method\n");
 return 0;
}


decompiled_code:
__int64 __fastcall init_lookup(unsigned int a1)
{
__int64 result; // rax

if ( a1 == 2 )
{
methods = (__int64)&bfd_methods;
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
methods = (__int64)&kallsym_methods;
}
else
{
if ( a1 )
{
methods = (__int64)&bfd_methods;
result = bfd_methods();
if ( (_DWORD)result )
{
methods = (__int64)&kallsym_methods;
result = kallsym_methods();
if ( (_DWORD)result )
{
methods = 0LL;
result = 0xFFFFFFFFLL;
}
}
return result;
}
methods = (__int64)&null_methods;
}
result = (*(__int64 (**)(void))methods)();
if ( (int)result < 0 )
methods = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
__int64 result; // rax

if ( a1 == 2 )
{
methods = (__int64)&bfd_methods;
}
else if ( a1 > 2 )
{
if ( a1 == 3 )
methods = (__int64)&kallsym_methods;
}
else
{
if ( a1 )
{
methods = (__int64)&bfd_methods;
result = bfd_methods();
if ( (_DWORD)result )
{
methods = (__int64)&kallsym_methods;
result = kallsym_methods();
if ( (_DWORD)result )
{
methods = 0LL;
result = 0xFFFFFFFFLL;
}
}
return result;
}
methods = (__int64)&null_methods;
}
result = (*(__int64 (**)(void))methods)();
if ( (int)result < 0 )
methods = 0LL;
return result;
}

original_code:
int init_lookup(lookup_init_method_t method)
{
 int rc;
 switch (method) {
 case METHOD_NULL:
  methods = &null_methods;
  break;
 case METHOD_AUTO:
  methods = &bfd_methods;
  if (methods->lookup_init() == 0)
   return 0;
  methods = &kallsym_methods;
  if (methods->lookup_init() == 0)
   return 0;
  methods = ((void *)0);
  return -1;
 case METHOD_DEBUGINFO:
  methods = &bfd_methods;
  break;
 case METHOD_KALLSYMS:
  methods = &kallsym_methods;
  break;
 }
 rc = methods->lookup_init();
 if (rc < 0)
  methods = ((void *)0);
 return rc;
}

canonical_original_code:
int init_lookup(enum lookup_init_method_t method)
{
 int rc;
 switch (method) {
 case METHOD_NULL:
  methods = &null_methods;
  break;
 case METHOD_AUTO:
  methods = &bfd_methods;
  if (methods->lookup_init() == 0)
   return 0;
  methods = &kallsym_methods;
  if (methods->lookup_init() == 0)
   return 0;
  methods = ((void *)0);
  return -1;
 case METHOD_DEBUGINFO:
  methods = &bfd_methods;
  break;
 case METHOD_KALLSYMS:
  methods = &kallsym_methods;
  break;
 }
 rc = methods->lookup_init();
 if (rc < 0)
  methods = ((void *)0);
 return rc;
}

variable_types: enum lookup_init_method_t { METHOD_NULL=0, METHOD_AUTO=1, METHOD_DEBUGINFO=2, METHOD_KALLSYMS=3 }

variable_types: rc int


decompiled_code:
__int64 __fastcall lookup_symbol(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a2 )
result = (*(__int64 (**)(void))(methods + 8))();
else
result = 1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 result; // rax

if ( a2 )
result = (*(__int64 (**)(void))(methods + 8))();
else
result = 1LL;
return result;
}

original_code:
int lookup_symbol(void *pc, struct loc_result *loc)
{
 if (loc == ((void *)0))
  return 1;
 return methods->get_symbol(pc, loc);
}

user_defined_types: struct loc_result { char *symbol; unsigned long long offset; }


decompiled_code:
__int64 __fastcall lookup_kas_cache(unsigned __int64 a1, _QWORD *a2)
{
_QWORD *v2; // rax

v2 = (_QWORD *)sym_list_head;
if ( !sym_list_head )
return 1LL;
do
{
if ( v2[1] <= a1 && v2[2] >= a1 )
{
*a2 = *v2;
a2[1] = a1 - v2[1];
return 0LL;
}
v2 = (_QWORD *)v2[3];
}
while ( v2 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1, _QWORD *a2)
{
_QWORD *v2; // rax

v2 = (_QWORD *)sym_list_head;
if ( !sym_list_head )
return 1LL;
do
{
if ( v2[1] <= a1 && v2[2] >= a1 )
{
*a2 = *v2;
a2[1] = a1 - v2[1];
return 0LL;
}
v2 = (_QWORD *)v2[3];
}
while ( v2 );
return 1LL;
}

original_code:
static int lookup_kas_cache( __u64 pc, struct loc_result *location)
{
 struct symbol_entry *sym;
 for ((sym) = ((&sym_list_head)->lh_first); (sym); (sym) = ((sym)->list.le_next)) {
  if ((pc >= sym->start) &&
      (pc <= sym->end)) {
   location->symbol = sym->sym_name;
   location->offset = (pc - sym->start);
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
static int lookup_kas_cache(unsigned long long pc, struct loc_result *location)
{
 struct symbol_entry *sym;
 for ((sym) = ((&sym_list_head)->lh_first); (sym); (sym) = ((sym)->list.le_next)) {
  if ((pc >= sym->start) &&
      (pc <= sym->end)) {
   location->symbol = sym->sym_name;
   location->offset = (pc - sym->start);
   return 0;
  }
 }
 return 1;
}

variable_types:
pc
unsigned long long

variable_types: struct symbol_entry { char *sym_name; unsigned long long start; unsigned long long end; struct { struct symbol_entry *le_next; struct symbol_entry **le_prev; } list; } *


decompiled_code:
__int64 __fastcall lookup_kas_sym(unsigned __int64 a1, _QWORD *a2)
{
__int64 result; // rax

result = lookup_kas_cache(a1, a2);
if ( (_DWORD)result )
result = lookup_kas_proc(a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, _QWORD *a2)
{
__int64 result; // rax

result = func0(a1, a2);
if ( (_DWORD)result )
result = func1(a1, a2);
return result;
}

original_code:
static int lookup_kas_sym(void *pc, struct loc_result *location)
{
 __u64 pcv;
 memset(&pcv, 0, sizeof(__u64));
 memcpy(&pcv, &pc, sizeof(void *));
 if (!lookup_kas_cache(pcv, location))
  return 0;
 return lookup_kas_proc(pcv, location);
}

canonical_original_code:
static int lookup_kas_sym(void *pc, struct loc_result *location)
{
 unsigned long long pcv;
 memset(&pcv, 0, sizeof(__u64));
 memcpy(&pcv, &pc, sizeof(void *));
 if (!lookup_kas_cache(pcv, location))
  return 0;
 return lookup_kas_proc(pcv, location);
}

variable_types:
pcv
unsigned long long