decompiled_code:
__int64 refresh_in()
{
term_move_to_item(*((unsigned int *)&gl_env + 46));
term_underline();
if ( *(_DWORD *)(*((_QWORD *)&gl_env + 24) + 24LL * *((int *)&gl_env + 46) + 20) == 1 )
term_standout();
if ( *(_QWORD *)(*((_QWORD *)&gl_env + 24) + 24LL * *((int *)&gl_env + 46)) )
my_str();
term_underend();
return term_standend();
}

canonical_decompiled_code:
__int64 func0()
{
term_move_to_item(*((unsigned int *)&gl_env + 46));
term_underline();
if ( *(_DWORD *)(*((_QWORD *)&gl_env + 24) + 24LL * *((int *)&gl_env + 46) + 20) == 1 )
term_standout();
if ( *(_QWORD *)(*((_QWORD *)&gl_env + 24) + 24LL * *((int *)&gl_env + 46)) )
my_str();
term_underend();
return term_standend();
}

original_code:
void refresh_in()
{
 term_move_to_item(gl_env.pos);
 term_underline();
 if(gl_env.elements[gl_env.pos].mode == 1)
  term_standout();
 if(gl_env.elements[gl_env.pos].elem != ((void *)0))
  my_str(gl_env.elements[gl_env.pos].elem);
 term_underend();
 term_standend();
}


repo: GeneralZero/ATF

decompiled_code:
__int64 __fastcall refresh_out(__int64 a1)
{
term_move_to_item(a1);
term_underend();
if ( *(_DWORD *)(gl_env[24] + 24LL * (int)a1 + 20) == 1 )
term_standout();
if ( *(_QWORD *)(gl_env[24] + 24LL * (int)a1) )
my_str();
return term_standend();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
term_move_to_item(a1);
term_underend();
if ( *(_DWORD *)(gl_env[24] + 24LL * (int)a1 + 20) == 1 )
term_standout();
if ( *(_QWORD *)(gl_env[24] + 24LL * (int)a1) )
my_str();
return term_standend();
}

original_code:
void refresh_out(int i)
{
 term_move_to_item(i);
 term_underend();
 if(gl_env.elements[i].mode == 1)
  term_standout();
 if(gl_env.elements[i].elem != ((void *)0))
  my_str(gl_env.elements[i].elem);
 term_standend();
}

variable_types: i int

return_type: void


original_code:
char* my_strncpy(char* dest, char* src, int size)
{
 int count=0;
 char* ret = ((void*)0);
 if(dest==((void*)0))
  return ((void*)0);
 if(src ==((void*)0))
 {
  ret = (char*)my_xmalloc(size*sizeof(char));
  for(count = 0; dest[count]!='\0' && count<size; count++)
   ret[count] = dest[count];
  if(count<size)
   ret[count++] = '\0';
  return ret;
 }
 else
 {
  ret = (char*)my_xmalloc(size*sizeof(char));
  for(count = 0; src[count]!='\0' && count<size; count++)
   ret[count] = src[count];
  if(count<size)
   ret[count++] = '\0';
  return ret;
 }
 return dest;
}

canonical_original_code:
char *my_strncpy(char *dest, char *src, int size)
{
 int count = 0;
 char *ret = ((void*)0);
 if(dest==((void *)0))
  return ((void *)0);
 if(src ==((void *)0))
 {
  ret = (char *)my_xmalloc(size*sizeof(char));
  for(count = 0; dest[count]!='\0' && count<size; count++)
   ret[count] = dest[count];
  if(count<size)
   ret[count++] = '\0';
  return ret;
 }
 else
 {
  ret = (char *)my_xmalloc(size*sizeof(char));
  for(count = 0; src[count]!='\0' && count<size; count++)
   ret[count] = src[count];
  if(count<size)
   ret[count++] = '\0';
  return ret;
 }
 return dest;
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types: size int

variable_types: count int

variable_types:
ret
char *

return_type: char *


decompiled_code:
__int64 __fastcall my_strcpy(__int64 a1, char *a2)
{
unsigned int v3; // eax
char v4; // dl
__int64 v5; // rax
int v6; // ecx

if ( !a1 )
return 0LL;
if ( a2 )
{
v3 = my_strlen();
a1 = my_xmalloc(v3);
v4 = *a2;
if ( *a2 )
{
v5 = 1LL;
do
{
*(_BYTE *)(a1 + v5 - 1) = v4;
v6 = v5++;
v4 = a2[v5 - 1];
}
while ( v4 );
}
else
{
v6 = 0;
}
*(_BYTE *)(a1 + v6 + 1) = 0;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char *a2)
{
unsigned int v3; // eax
char v4; // dl
__int64 v5; // rax
int v6; // ecx

if ( !a1 )
return 0LL;
if ( a2 )
{
v3 = my_strlen();
a1 = my_xmalloc(v3);
v4 = *a2;
if ( *a2 )
{
v5 = 1LL;
do
{
*(_BYTE *)(a1 + v5 - 1) = v4;
v6 = v5++;
v4 = a2[v5 - 1];
}
while ( v4 );
}
else
{
v6 = 0;
}
*(_BYTE *)(a1 + v6 + 1) = 0;
}
return a1;
}

original_code:
char* my_strcpy(char* dest, char* src)
{
 char* ret = dest;
 if(dest!=((void*)0) && src !=((void*)0))
 {
  int count;
  ret =my_xmalloc(my_strlen(dest));
  for(count = 0; src[count]!='\0'; count++)
   ret[count] = src[count];
  ret[++count] = '\0';
 }
 return ret;
}

canonical_original_code:
char *my_strcpy(char *dest, char *src)
{
 char *ret = dest;
 if(dest!=((void *)0) && src !=((void *)0))
 {
  int count;
  ret =my_xmalloc(my_strlen(dest));
  for(count = 0; src[count]!='\0'; count++)
   ret[count] = src[count];
  ret[++count] = '\0';
 }
 return ret;
}


decompiled_code:
void __fastcall add_node_at(_QWORD *a1, _QWORD *a2, int a3)
{
int v4; // edx
_QWORD *v5; // rax

if ( a2 && a1 )
{
if ( a3 <= 0 )
{
add_node();
}
else if ( (int)count_nodes(*a2) < a3 )
{
append(a1, a2);
}
else
{
v4 = a3 - 1;
v5 = (_QWORD *)*a2;
if ( a3 - 1 > 0 )
{
do
{
v5 = (_QWORD *)*v5;
--v4;
}
while ( v4 );
}
*a1 = *v5;
*v5 = a1;
}
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, _QWORD *a2, int a3)
{
int v4; // edx
_QWORD *v5; // rax

if ( a2 && a1 )
{
if ( a3 <= 0 )
{
add_node();
}
else if ( (int)count_nodes(*a2) < a3 )
{
append(a1, a2);
}
else
{
v4 = a3 - 1;
v5 = (_QWORD *)*a2;
if ( a3 - 1 > 0 )
{
do
{
v5 = (_QWORD *)*v5;
--v4;
}
while ( v4 );
}
*a1 = *v5;
*v5 = a1;
}
}
}

original_code:
void add_node_at(t_node* element, t_node** thenode, int num)
{
 if(thenode!=((void*)0) && element!=((void*)0))
 {
  t_node* point;
  if(num<1)
   add_node(element, thenode);
  else if(num > count_nodes(*thenode))
   append(element, thenode);
  else
  {
   for(num--,point = *thenode; 0 < num; point = point->next, num--);
   element->next = point->next;
   point->next = element;
  }
 }
}

canonical_original_code:
void add_node_at(struct s_node *element, struct s_node **thenode, int num)
{
 if(thenode!=((void *)0) && element!=((void *)0))
 {
  struct s_node *point;
  if(num<1)
   add_node(element, thenode);
  else if(num > count_nodes(*thenode))
   append(element, thenode);
  else
  {
   for(num--,point = *thenode; 0 < num; point = point->next, num--);
   element->next = point->next;
   point->next = element;
  }
 }
}

variable_types: struct s_node { struct s_node *next; void *elem; } *

variable_types:
thenode
struct s_node **

variable_types: num int


original_code:
char* my_strconcat(char* string1, char* string2)
{
 char* ret = ((void*)0);
 if(string1==((void*)0) && string2== ((void*)0))
  return ret;
 else if(string1==((void*)0))
  return string2;
 else if(string2==((void*)0))
  return string1;
 else
 {
  int count;
  int length = my_strlen(string2)+my_strlen(string1)-1;
  ret=(char*)my_xmalloc(length*sizeof(char));
  for(count=0; *string1!='\0';(string1)++)
   ret[count++] = *string1;
  for(;*string2!='\0'; string2++)
   ret[count++] = *string2;
  ret[++count] = '\0';
 }
 return ret;
}

canonical_original_code:
char *my_strconcat(char *string1, char *string2)
{
 char *ret = ((void*)0);
 if(string1==((void *)0) && string2== ((void *)0))
  return ret;
 else if(string1==((void *)0))
  return string2;
 else if(string2==((void *)0))
  return string1;
 else
 {
  int count;
  int length = my_strlen(string2)+my_strlen(string1)-1;
  ret=(char *)my_xmalloc(length*sizeof(char));
  for(count=0; *string1!='\0';(string1)++)
   ret[count++] = *string1;
  for(;*string2!='\0'; string2++)
   ret[count++] = *string2;
  ret[++count] = '\0';
 }
 return ret;
}

variable_types: length int


hswap

original_code:
void hswap(t_heap* theHeap, int a, int b){
 void* temp;
 temp = (void*)malloc(sizeof(void));
 temp = theHeap->tree[b];
 theHeap->tree[b] = theHeap->tree[a];
 theHeap->tree[a] = temp;
 free(temp);
}

canonical_original_code:
void hswap(struct s_heap *theHeap, int a, int b){
 void *temp;
 temp = (void *)malloc(sizeof(void));
 temp = theHeap->tree[b];
 theHeap->tree[b] = theHeap->tree[a];
 theHeap->tree[a] = temp;
 free(temp);
}

variable_types: struct s_heap { int size_max; int current_size; void **tree; } *

variable_types: a int

variable_types: b int

variable_types:
temp
void *


decompiled_code:
__int64 __fastcall my_strlen(_BYTE *a1)
{
unsigned int v1; // edx
__int64 v2; // rax

v1 = 0;
if ( a1 )
{
if ( *a1 )
{
v2 = 1LL;
do
v1 = v2++;
while ( a1[v2 - 1] );
}
else
{
v1 = 0;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
unsigned int v1; // edx
__int64 v2; // rax

v1 = 0;
if ( a1 )
{
if ( *a1 )
{
v2 = 1LL;
do
v1 = v2++;
while ( a1[v2 - 1] );
}
else
{
v1 = 0;
}
}
return v1;
}

original_code:
int my_strlen(char* string)
{
 int count = 0;
 if(string != ((void*)0))
  for(;string[count] !='\0'; count++);
 return count;
}

canonical_original_code:
int my_strlen(char *string)
{
 int count = 0;
 if(string != ((void *)0))
  for(;string[count] !='\0'; count++);
 return count;
}

variable_types:
string
char *

return_type: int


shiftMaxUp

decompiled_code:
char __fastcall shiftMaxUp(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD, _QWORD))
{
int v4; // eax
unsigned int v5; // er13

LOBYTE(v4) = a3 != 0LL;
if ( a3 != 0LL && a1 != 0 && a2 > 0 )
{
v5 = (a2 - 1) / 2;
v4 = a3(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)v5));
if ( v4 > 0 )
{
swap(a1, v5, (unsigned int)a2);
LOBYTE(v4) = shiftMaxUp(a1, v5, a3);
}
}
return v4;
}

canonical_decompiled_code:
char __fastcall func0(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD, _QWORD))
{
int v4; // eax
unsigned int v5; // er13

LOBYTE(v4) = a3 != 0LL;
if ( a3 != 0LL && a1 != 0 && a2 > 0 )
{
v5 = (a2 - 1) / 2;
v4 = a3(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)v5));
if ( v4 > 0 )
{
swap(a1, v5, (unsigned int)a2);
LOBYTE(v4) = func0(a1, v5, a3);
}
}
return v4;
}

original_code:
void shiftMaxUp(t_heap* theHeap, int index, t_comph comp){
 if(index>0&&theHeap!=((void *)0)&&comp!=((void *)0)){
  int p;
  p = (index-1)/2;
  if((*comp)(theHeap->tree[index],theHeap->tree[p])>0){
          swap(theHeap,p,index);
          shiftMaxUp(theHeap,p,comp);
  }
 }
}

canonical_original_code:
void shiftMaxUp(struct s_heap *theHeap, int index, int (*comp)(void *, void *)){
 if(index>0&&theHeap!=((void *)0)&&comp!=((void *)0)){
  int p;
  p = (index-1)/2;
  if((*comp)(theHeap->tree[index],theHeap->tree[p])>0){
          swap(theHeap,p,index);
          shiftMaxUp(theHeap,p,comp);
  }
 }
}

variable_types: index int

variable_types:
comp
int (*)(void *, void *)

variable_types: p int

user_defined_types: struct s_heap { int size_max; int current_size; void **tree; }


popMaxHeap

decompiled_code:
__int64 __fastcall popMaxHeap(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v2 > 0 )
{
*(_DWORD *)(a1 + 4) = v2 - 1;
swap(a1, 0LL);
shiftMaxDown(a1, 0LL, a2);
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * *(int *)(a1 + 4));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // edx
__int64 result; // rax

if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v2 > 0 )
{
*(_DWORD *)(a1 + 4) = v2 - 1;
swap(a1, 0LL);
shiftMaxDown(a1, 0LL, a2);
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * *(int *)(a1 + 4));
}
return result;
}

original_code:
void* popMaxHeap(t_heap* theHeap, t_comph comp){
 if(theHeap==((void *)0)||comp==((void *)0)||theHeap->current_size<=0)
  return ((void *)0);
 swap(theHeap,0,--(theHeap->current_size));
 shiftMaxDown(theHeap, 0, comp);
 return theHeap->tree[theHeap->current_size];
}

canonical_original_code:
void *popMaxHeap(struct s_heap *theHeap, int (*comp)(void *, void *)){
 if(theHeap==((void *)0)||comp==((void *)0)||theHeap->current_size<=0)
  return ((void *)0);
 swap(theHeap,0,--(theHeap->current_size));
 shiftMaxDown(theHeap, 0, comp);
 return theHeap->tree[theHeap->current_size];
}

return_type: void *


decompiled_code:
ssize_t __fastcall my_termprint(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(int a1)
{
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

original_code:
int my_termprint(int c)
{
 return write(1, &c, 1);
}

variable_types: c int


decompiled_code:
int term_standend()
{
return tputs(*((const char **)&gl_env + 8), 1, (int (*)(int))my_termprint);
}

canonical_decompiled_code:
int func1()
{
return tputs(*((const char **)&gl_env + 8), 1, (int (*)(int))my_termprint);
}

original_code:
void term_standend()
{
 tputs(gl_env.stand_end, 1, my_termprint);
}


decompiled_code:
int term_standout()
{
return tputs(*((const char **)&gl_env + 7), 1, (int (*)(int))my_termprint);
}

canonical_decompiled_code:
int func2()
{
return tputs(*((const char **)&gl_env + 7), 1, (int (*)(int))my_termprint);
}

original_code:
void term_standout()
{
 tputs(gl_env.standout, 1, my_termprint);
}


decompiled_code:
int term_clear()
{
return tputs("\x1B[2J", 1, (int (*)(int))my_termprint);
}

canonical_decompiled_code:
int func3()
{
return tputs("\x1B[2J", 1, (int (*)(int))my_termprint);
}

original_code:
void term_clear()
{
 tputs("\033[2J", 1, my_termprint);
}


decompiled_code:
int term_underline()
{
return tputs(*((const char **)&gl_env + 5), 1, (int (*)(int))my_termprint);
}

canonical_decompiled_code:
int func4()
{
return tputs(*((const char **)&gl_env + 5), 1, (int (*)(int))my_termprint);
}

original_code:
void term_underline()
{
 tputs(gl_env.underline, 1, my_termprint);
}


decompiled_code:
int term_underend()
{
return tputs(*((const char **)&gl_env + 6), 1, (int (*)(int))my_termprint);
}

canonical_decompiled_code:
int func5()
{
return tputs(*((const char **)&gl_env + 6), 1, (int (*)(int))my_termprint);
}

original_code:
void term_underend()
{
 tputs(gl_env.under_end, 1, my_termprint);
}


decompiled_code:
int term_ve()
{
return tputs(*((const char **)&gl_env + 12), 1, (int (*)(int))my_termprint);
}

canonical_decompiled_code:
int func6()
{
return tputs(*((const char **)&gl_env + 12), 1, (int (*)(int))my_termprint);
}

original_code:
void term_ve()
{
 tputs(gl_env.cursoron, 1, my_termprint);
}


decompiled_code:
int term_vi()
{
return tputs(*((const char **)&gl_env + 11), 1, (int (*)(int))my_termprint);
}

canonical_decompiled_code:
int func7()
{
return tputs(*((const char **)&gl_env + 11), 1, (int (*)(int))my_termprint);
}

original_code:
void term_vi()
{
 tputs(gl_env.cursoroff, 1, my_termprint);
}


recMergeSort

original_code:
void recMergeSort(void** arr, int n,t_comp comp,void** temp){
 int m,i,j,k;
 if((arr!=((void *)0))&&(comp!=((void *)0))&&(n>1)&&(temp!=((void *)0))){
   m=n/2;
   recMergeSort(arr,m,comp,temp);
   recMergeSort(&arr[m],n-m,comp,&temp[m]);
   for(i=0;i<m;i++)
    temp[i] = arr[i];
   for(j=n-1;i<n;i++,j--)
    temp[j] = arr[i];
   for(i=0,j=n-1,k=0;k<n;k++){
    if((*comp)(temp[i],temp[j])<=0)
     arr[k]=temp[i++];
    else
     arr[k]=temp[j--];
   }
 }
}

canonical_original_code:
void recMergeSort(void **arr, int n, int (*comp)(void *, void *), void **temp){
 int m; int i; int j; int k;
 if((arr!=((void *)0))&&(comp!=((void *)0))&&(n>1)&&(temp!=((void *)0))){
   m=n/2;
   recMergeSort(arr,m,comp,temp);
   recMergeSort(&arr[m],n-m,comp,&temp[m]);
   for(i=0;i<m;i++)
    temp[i] = arr[i];
   for(j=n-1;i<n;i++,j--)
    temp[j] = arr[i];
   for(i=0,j=n-1,k=0;k<n;k++){
    if((*comp)(temp[i],temp[j])<=0)
     arr[k]=temp[i++];
    else
     arr[k]=temp[j--];
   }
 }
}

variable_types:
arr
void **

variable_types: n int

variable_types:
temp
void **

variable_types: m int

variable_types: i int

variable_types: j int

variable_types: k int


freeHeap

decompiled_code:
__int64 __fastcall freeHeap(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
return 1LL;
}

original_code:
bool freeHeap(t_heap* h){
 free(h->tree);
 free(h);
 return 1;
}

canonical_original_code:
char freeHeap(struct s_heap *h){
 free(h->tree);
 free(h);
 return 1;
}

return_type: char


original_code:
void recursive_int(int sig)
{
 static short count = 0;
 static pid_t c = 0;
 c = c << 1;
 if(sig == 12)
  c |= 1;
 if(++count == sizeof(pid_t)*8)
 {
  gl_env.cpid = c;
  c=0;
  count=0;
 }
}

canonical_original_code:
void recursive_int(int sig)
{
 static short count = 0;
 static int c = 0;
 c = c << 1;
 if(sig == 12)
  c |= 1;
 if(++count == sizeof(pid_t)*8)
 {
  gl_env.cpid = c;
  c=0;
  count=0;
 }
}

variable_types: sig int

variable_types: count short


decompiled_code:
void __fastcall recursive_char(int a1)
{
char v1; // al

v1 = 2 * c_1;
if ( a1 == 12 )
v1 = (2 * c_1) | 1;
c_1 = v1;
if ( count_0 == 7 )
{
count_0 = 0;
if ( c_1 )
my_char((unsigned int)c_1);
else
*((_WORD *)&gl_env + 2) = 1;
c_1 = 0;
}
else
{
++count_0;
}
kill(gl_env, 12);
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
char v1; // al

v1 = 2 * c_1;
if ( a1 == 12 )
v1 = (2 * c_1) | 1;
c_1 = v1;
if ( count_0 == 7 )
{
count_0 = 0;
if ( c_1 )
my_char((unsigned int)c_1);
else
*((_WORD *)&gl_env + 2) = 1;
c_1 = 0;
}
else
{
++count_0;
}
kill(gl_env, 12);
}

original_code:
void recursive_char(int sig)
{
 static char count = 0;
 static char c = 0;
 c = c << 1;
 if(sig == 12)
  c |= 1;
 if(++count == sizeof(char)*8)
 {
  count = 0;
  if(c != '\0')
   my_char(c);
  else
  {
             gl_env.sigflag = 1;
  }
  c = 0;
 }
 kill(gl_env.cpid, 12);
}

variable_types: count char

variable_types: c char


decompiled_code:
void __fastcall serv_exit(int a1)
{
if ( a1 == 2 )
{
my_str("\nSomebody set up us the bomb.\n");
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
if ( a1 == 2 )
{
my_str("\nSomebody set up us the bomb.\n");
exit(0);
}
}

original_code:
void serv_exit(int sig)
{
 if(sig == 2)
 {
  my_str("\nSomebody set up us the bomb.\n");
  exit(0);
 }
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
int v4; // ebx

v3 = getpid();
signal(2, serv_exit);
my_str("Server PID: ");
my_int(v3);
my_str("\n");
while ( 1 )
{
gl_env = 0;
*((_WORD *)&gl_env + 2) = 0;
signal(10, recursive_int);
signal(12, recursive_int);
v4 = 32;
do
{
pause();
--v4;
}
while ( v4 );
my_str("Client PID: ");
my_int((unsigned int)gl_env);
kill(gl_env, 10);
signal(10, recursive_char);
signal(12, recursive_char);
my_str("Receved: ");
while ( !*((_WORD *)&gl_env + 2) )
pause();
my_char(10LL);
}
}

original_code:
int main(int argc, char** argv)
{
 int pid = getpid();
 int i;
 signal(2, serv_exit);
 my_str("Server PID: ");
 my_int(pid);
 my_str("\n");
 while(1)
 {
  gl_env.cpid = 0;
  gl_env.sigflag = 0;
  signal(10, recursive_int);
  signal(12, recursive_int);
  for(i = 0; i < sizeof(pid_t)*8; i++)
  {
   pause();
  }
  my_str("Client PID: ");
  my_int(gl_env.cpid);
  kill(gl_env.cpid, 10);
  signal(10, recursive_char);
  signal(12, recursive_char);
  my_str("Receved: ");
  while(!gl_env.sigflag)
  {
   pause();
  }
  my_char('\n');
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
 int pid = getpid();
 int i;
 signal(2, serv_exit);
 my_str("Server PID: ");
 my_int(pid);
 my_str("\n");
 while(1)
 {
  gl_env.cpid = 0;
  gl_env.sigflag = 0;
  signal(10, recursive_int);
  signal(12, recursive_int);
  for(i = 0; i < sizeof(pid_t)*8; i++)
  {
   pause();
  }
  my_str("Client PID: ");
  my_int(gl_env.cpid);
  kill(gl_env.cpid, 10);
  signal(10, recursive_char);
  signal(12, recursive_char);
  my_str("Receved: ");
  while(!gl_env.sigflag)
  {
   pause();
  }
  my_char('\n');
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: pid int


decompiled_code:
__int64 __fastcall my_vect2str(_QWORD *a1)
{
_QWORD *v2; // rbx
unsigned int v3; // er12
__int64 v4; // rdi
_QWORD *v5; // rbp
__int64 v6; // rax

if ( *a1 )
{
v2 = a1 + 1;
v3 = 0;
do
v3 += my_strlen(*v2++);
while ( *(v2 - 1) );
}
else
{
v3 = 0;
}
v4 = my_xmalloc(v3);
if ( *a1 )
{
v5 = a1 + 1;
do
{
v6 = my_strcat(v4);
v4 = my_strcat(v6);
++v5;
}
while ( *(v5 - 1) );
}
return my_strcat(v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
_QWORD *v2; // rbx
unsigned int v3; // er12
__int64 v4; // rdi
_QWORD *v5; // rbp
__int64 v6; // rax

if ( *a1 )
{
v2 = a1 + 1;
v3 = 0;
do
v3 += my_strlen(*v2++);
while ( *(v2 - 1) );
}
else
{
v3 = 0;
}
v4 = my_xmalloc(v3);
if ( *a1 )
{
v5 = a1 + 1;
do
{
v6 = my_strcat(v4);
v4 = my_strcat(v6);
++v5;
}
while ( *(v5 - 1) );
}
return my_strcat(v4);
}

original_code:
char* my_vect2str(char** args)
{
 int count;
 int i;
 char* ret;
 for(i = 0, count = 0; args[i] !=((void*)0); i++, count+= my_strlen(args[i]));
 ret = my_xmalloc(sizeof(char)* count);
 for(i =0; args[i]!='\0'; i++)
 {
  ret = my_strcat(ret, args[i]);
  ret = my_strcat(ret, " ");
 }
 ret = my_strcat(ret,"\0");
 return ret;
}

canonical_original_code:
char *my_vect2str(char **args)
{
 int count;
 int i;
 char *ret;
 for(i = 0, count = 0; args[i] !=((void *)0); i++, count+= my_strlen(args[i]));
 ret = my_xmalloc(sizeof(char)* count);
 for(i =0; args[i]!='\0'; i++)
 {
  ret = my_strcat(ret, args[i]);
  ret = my_strcat(ret, " ");
 }
 ret = my_strcat(ret,"\0");
 return ret;
}

variable_types:
args
char **

variable_types: count int

variable_types:
ret
char *


mergeSort

decompiled_code:
void __fastcall mergeSort(__int64 a1, int a2, __int64 a3)
{
void *v4; // r13

if ( a3 != 0 && a2 > 1 )
{
if ( a1 )
{
v4 = malloc(8LL * a2);
recMergeSort(a1, (unsigned int)a2, a3, v4);
free(v4);
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, __int64 a3)
{
void *v4; // r13

if ( a3 != 0 && a2 > 1 )
{
if ( a1 )
{
v4 = malloc(8LL * a2);
recMergeSort(a1, (unsigned int)a2, a3, v4);
free(v4);
}
}
}

original_code:
void mergeSort(void** arr,int n,t_comp comp){
 if((arr!=((void *)0))&&(n>1)&&(comp!=((void *)0))){
  void** temp = (void**)malloc(sizeof(void*)*n);
  recMergeSort(arr,n,comp,temp);
  free(temp);
 }
}

canonical_original_code:
void mergeSort(void **arr, int n, int (*comp)(void *, void *)){
 if((arr!=((void *)0))&&(n>1)&&(comp!=((void *)0))){
  void **temp = (void**)malloc(sizeof(void*)*n);
  recMergeSort(arr,n,comp,temp);
  free(temp);
 }
}

variable_types:
arr
void **

variable_types:
comp
int (*)(void *, void *)


original_code:
char* my_stdstrnconcat(char* string1, char* string2, int num)
{
 char* ret = ((void*)0);
 if(string1==((void*)0) && string2== ((void*)0))
  return ret;
 else
 {
  int count = 0;
  int length = my_strlen(string2)+my_strlen(string1)-1;
  if (length>=num)
   length = num;
  else
   return ((void*)0);
  if(length<1)
   length = 1;
  ret=(char*)my_xmalloc(length*sizeof(char));
  if(string1!=((void*)0))
   for(; *string1!='\0' && count<num;(string1)++)
    ret[count++] = *string1;
  if(string2!=((void*)0))
   for(;*string2!='\0' && count<num; string2++)
    ret[count++] = *string2;
  ret[++count] = '\0';
 }
 return ret;
}

canonical_original_code:
char *my_stdstrnconcat(char *string1, char *string2, int num)
{
 char *ret = ((void*)0);
 if(string1==((void *)0) && string2== ((void *)0))
  return ret;
 else
 {
  int count = 0;
  int length = my_strlen(string2)+my_strlen(string1)-1;
  if (length>=num)
   length = num;
  else
   return ((void *)0);
  if(length<1)
   length = 1;
  ret=(char *)my_xmalloc(length*sizeof(char));
  if(string1!=((void *)0))
   for(; *string1!='\0' && count<num;(string1)++)
    ret[count++] = *string1;
  if(string2!=((void *)0))
   for(;*string2!='\0' && count<num; string2++)
    ret[count++] = *string2;
  ret[++count] = '\0';
 }
 return ret;
}

variable_types: num int

variable_types: length int


moveup

decompiled_code:
__int64 moveup()
{
int v0; // eax

refresh_out(gl_env[46]);
v0 = gl_env[46] - 1;
gl_env[46] = v0;
if ( v0 < 0 )
gl_env[46] = gl_env[45] - 1;
return refresh_in();
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax

refresh_out(gl_env[46]);
v0 = gl_env[46] - 1;
gl_env[46] = v0;
if ( v0 < 0 )
gl_env[46] = gl_env[45] - 1;
return refresh_in();
}

original_code:
void moveup()
{
 refresh_out(gl_env.pos);
 if(--gl_env.pos < 0)
  gl_env.pos = gl_env.nbelems - 1;
 refresh_in();
}


movedown

decompiled_code:
__int64 movedown()
{
signed int v0; // eax

refresh_out(gl_env[46]);
v0 = gl_env[46] + 1;
gl_env[46] = v0;
if ( v0 >= (int)gl_env[45] )
gl_env[46] = 0;
return refresh_in();
}

canonical_decompiled_code:
__int64 func1()
{
signed int v0; // eax

refresh_out(gl_env[46]);
v0 = gl_env[46] + 1;
gl_env[46] = v0;
if ( v0 >= (int)gl_env[45] )
gl_env[46] = 0;
return refresh_in();
}

original_code:
void movedown()
{
 refresh_out(gl_env.pos);
 if(++gl_env.pos >= gl_env.nbelems)
  gl_env.pos = 0;
 refresh_in();
}


moveleft

decompiled_code:
__int64 moveleft()
{
signed int v0; // eax

refresh_out(gl_env[46]);
v0 = gl_env[46] - LOWORD(gl_env[26]);
if ( v0 < 0 )
v0 = 0;
gl_env[46] = v0;
return refresh_in();
}

canonical_decompiled_code:
__int64 func2()
{
signed int v0; // eax

refresh_out(gl_env[46]);
v0 = gl_env[46] - LOWORD(gl_env[26]);
if ( v0 < 0 )
v0 = 0;
gl_env[46] = v0;
return refresh_in();
}

original_code:
void moveleft()
{
 refresh_out(gl_env.pos);
 if((gl_env.pos-= gl_env.win.ws_row) < 0)
  gl_env.pos = 0;
 refresh_in();
}


moveright

decompiled_code:
__int64 moveright()
{
signed int v0; // edx
signed int v1; // eax

refresh_out(gl_env[46]);
v0 = gl_env[45];
v1 = gl_env[46] + LOWORD(gl_env[26]);
if ( v0 <= v1 )
v1 = v0 - 1;
gl_env[46] = v1;
return refresh_in();
}

canonical_decompiled_code:
__int64 func3()
{
signed int v0; // edx
signed int v1; // eax

refresh_out(gl_env[46]);
v0 = gl_env[45];
v1 = gl_env[46] + LOWORD(gl_env[26]);
if ( v0 <= v1 )
v1 = v0 - 1;
gl_env[46] = v1;
return refresh_in();
}

original_code:
void moveright()
{
 refresh_out(gl_env.pos);
 if((gl_env.pos+= gl_env.win.ws_row) > gl_env.nbelems-1)
  gl_env.pos = gl_env.nbelems - 1;
 refresh_in();
}


decompiled_code:
__int64 __fastcall move_cursor(unsigned int a1, int a2)
{
void *v2; // rbx
void *v3; // r12
void *v4; // rbp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // r13

v2 = (void *)my_digits2();
v3 = (void *)my_num_base2(a1, v2);
v4 = (void *)my_num_base2((unsigned int)(a2 + 1), v2);
v5 = my_strconcat(&unk_2A8, v4);
v6 = my_strconcat(v5, &unk_2AB);
v7 = my_strconcat(v6, v3);
v8 = my_strconcat(v7, &unk_2AD);
free(v2);
free(v4);
free(v3);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, int a2)
{
void *v2; // rbx
void *v3; // r12
void *v4; // rbp
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // r13

v2 = (void *)my_digits2();
v3 = (void *)my_num_base2(a1, v2);
v4 = (void *)my_num_base2((unsigned int)(a2 + 1), v2);
v5 = my_strconcat(&unk_2A8, v4);
v6 = my_strconcat(v5, &unk_2AB);
v7 = my_strconcat(v6, v3);
v8 = my_strconcat(v7, &unk_2AD);
free(v2);
free(v4);
free(v3);
return v8;
}

original_code:
char* move_cursor(int x,int y)
{
 char* nums = my_digits2();
 char* x_char = my_num_base2(x, nums);
 char* y_char = my_num_base2(y+1, nums);
 char* ptr ;
 ptr = my_strconcat( my_strconcat( my_strconcat( my_strconcat("\033[", y_char), ";"), x_char), "f");
 free(nums);
 free(y_char);
 free(x_char);
 return ptr;
}

canonical_original_code:
char *move_cursor(int x, int y)
{
 char *nums = my_digits2();
 char *x_char = my_num_base2(x, nums);
 char *y_char = my_num_base2(y+1, nums);
 char *ptr;
 ptr = my_strconcat( my_strconcat( my_strconcat( my_strconcat("\033[", y_char), ";"), x_char), "f");
 free(nums);
 free(y_char);
 free(x_char);
 return ptr;
}

variable_types: x int

variable_types: y int

variable_types:
nums
char *

variable_types:
ptr
char *


decompiled_code:
int __fastcall term_move(unsigned int a1, int a2)
{
const char *v2; // rax

v2 = (const char *)move_cursor(a1, a2);
return tputs(v2, 1, (int (*)(int))&my_termprint);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1, int a2)
{
const char *v2; // rax

v2 = (const char *)func4(a1, a2);
return tputs(v2, 1, (int (*)(int))&my_termprint);
}

original_code:
int term_move(int x, int y)
{
 char* move = move_cursor(x,y);
 tputs(move, 1, my_termprint);
}

canonical_original_code:
int term_move(int x, int y)
{
 char *move = move_cursor(x,y);
 tputs(move, 1, my_termprint);
}

variable_types:
move
char *


decompiled_code:
int __fastcall term_move_to_item(int a1)
{
__int64 v1; // rax

v1 = *(_QWORD *)&gl_env[48] + 24LL * a1;
return term_move(*(_DWORD *)(v1 + 12), *(_DWORD *)(v1 + 16));
}

canonical_decompiled_code:
int __fastcall func6(int a1)
{
__int64 v1; // rax

v1 = *(_QWORD *)&gl_env[48] + 24LL * a1;
return func5(*(_DWORD *)(v1 + 12), *(_DWORD *)(v1 + 16));
}

original_code:
void term_move_to_item(int i)
{
 term_move(gl_env.elements[i].x, gl_env.elements[i].y);
}

variable_types: i int


freeihash

decompiled_code:
void __fastcall freeihash(void **a1)
{
free(*a1);
free(*(void **)*a1);
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
free(*a1);
free(*(void **)*a1);
}

original_code:
void freeihash(t_ihashtable ** ht){
 free((*ht));
 free((*ht)->HT);
}

canonical_original_code:
void freeihash(struct s_ihashtable **ht){
 free((*ht));
 free((*ht)->HT);
}

variable_types: struct s_ihashtable { void **HT; int M; int n; int (*getkey)(void *); int (*h)(int); int (*p)(int, int); } **


decompiled_code:
__int64 __fastcall count_nodes(_QWORD **a1)
{
__int64 result; // rax
_QWORD *v2; // rax
int v3; // edx

result = 0LL;
if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
++v3;
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
else
{
v3 = 0;
}
result = (unsigned int)(v3 + 1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD **a1)
{
__int64 result; // rax
_QWORD *v2; // rax
int v3; // edx

result = 0LL;
if ( a1 )
{
v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
++v3;
v2 = (_QWORD *)*v2;
}
while ( v2 );
}
else
{
v3 = 0;
}
result = (unsigned int)(v3 + 1);
}
return result;
}

original_code:
int count_nodes(t_node* thenode)
{
 int i = 0;
 if(thenode != ((void*)0))
 {
  for(; thenode->next!=((void*)0); thenode = thenode->next, i++);
  i++;
 }
 return i;
}

canonical_original_code:
int count_nodes(struct s_node *thenode)
{
 int i = 0;
 if(thenode != ((void *)0))
 {
  for(; thenode->next!=((void *)0); thenode = thenode->next, i++);
  i++;
 }
 return i;
}

variable_types: struct s_node { struct s_node *next; void *elem; } *


decompiled_code:
__int64 __fastcall my_strdup(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rcx
__int64 v3; // rax

if ( !a1 )
return 0LL;
v1 = (unsigned int)my_strlen();
v2 = my_xmalloc(v1);
if ( (int)v1 >= 0 )
{
v3 = (int)v1;
do
{
*(_BYTE *)(v2 + v3) = *(_BYTE *)(a1 + v3);
--v3;
}
while ( (int)v3 >= 0 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rcx
__int64 v3; // rax

if ( !a1 )
return 0LL;
v1 = (unsigned int)my_strlen();
v2 = my_xmalloc(v1);
if ( (int)v1 >= 0 )
{
v3 = (int)v1;
do
{
*(_BYTE *)(v2 + v3) = *(_BYTE *)(a1 + v3);
--v3;
}
while ( (int)v3 >= 0 );
}
return v2;
}

original_code:
char* my_strdup(char* original)
{
 char* ret = ((void*)0);
 if(original!=((void*)0))
 {
  int length = my_strlen(original);
  ret = (char*)my_xmalloc(sizeof(char)*length);
  for(;length>=0; length--)
   ret[length] = original[length];
 }
 return ret;
}

canonical_original_code:
char *my_strdup(char *original)
{
 char *ret = ((void*)0);
 if(original!=((void *)0))
 {
  int length = my_strlen(original);
  ret = (char *)my_xmalloc(sizeof(char)*length);
  for(;length>=0; length--)
   ret[length] = original[length];
 }
 return ret;
}

variable_types:
original
char *


shiftMaxDown

original_code:
void shiftMaxDown(t_heap* theHeap, int index, t_comph comp){
 int lc;
 if(index>=0&&theHeap!=((void *)0)&&comp!=((void *)0)&& 2*index+1 < theHeap->current_size){
  lc = 2 * index + 1;
  if((lc+1<theHeap->current_size)&&((*comp)(theHeap->tree[lc + 1],theHeap->tree[lc])>0))
   lc++;
  if(((*comp)(theHeap->tree[lc],theHeap->tree[index])>0)){
      swap(theHeap,lc,index);
      shiftMaxDown(theHeap,lc,comp);
  }
 }
}

canonical_original_code:
void shiftMaxDown(struct s_heap *theHeap, int index, int (*comp)(void *, void *)){
 int lc;
 if(index>=0&&theHeap!=((void *)0)&&comp!=((void *)0)&& 2*index+1 < theHeap->current_size){
  lc = 2 * index + 1;
  if((lc+1<theHeap->current_size)&&((*comp)(theHeap->tree[lc + 1],theHeap->tree[lc])>0))
   lc++;
  if(((*comp)(theHeap->tree[lc],theHeap->tree[index])>0)){
      swap(theHeap,lc,index);
      shiftMaxDown(theHeap,lc,comp);
  }
 }
}

variable_types: struct s_heap { int size_max; int current_size; void **tree; } *

variable_types: index int

variable_types: lc int


lookHeap

decompiled_code:
__int64 __fastcall lookHeap(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( *(int *)(a1 + 4) <= 0 )
return 0LL;
return **(_QWORD **)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( !a1 )
return 0LL;
if ( *(int *)(a1 + 4) <= 0 )
return 0LL;
return **(_QWORD **)(a1 + 8);
}

original_code:
void* lookHeap(t_heap* theHeap){
 if(theHeap==((void *)0)||theHeap->current_size<=0)
  return ((void *)0);
 return theHeap->tree[0];
}

canonical_original_code:
void *lookHeap(struct s_heap *theHeap){
 if(theHeap==((void *)0)||theHeap->current_size<=0)
  return ((void *)0);
 return theHeap->tree[0];
}


ihashadd

original_code:
int ihashadd(t_ihashtable *ht, void* elem){
     int home,i,k,pos;
     if((ht== ((void *)0))||(elem==((void *)0))||(ht->n>=ht->M))
          return -1;
     if((k=ht->getkey(elem))<0)
          return -1;
     home = ht->h(k)%ht->M;
     for(pos = home,i=1;(ht->HT[pos]!=(void*)0)&&(ht->HT[pos]!=(void*)1); i++,pos = (home + ht->p(k,i))%(ht->M))
  if( *((int*)elem) == *((int*)(ht->HT[pos])) )
   return -1;
     ht->HT[pos] = elem;
     ht->n++;
     return pos;
}

canonical_original_code:
int ihashadd(struct s_ihashtable *ht, void *elem){
     int home; int i; int k; int pos;
     if((ht== ((void *)0))||(elem==((void *)0))||(ht->n>=ht->M))
          return -1;
     if((k=ht->getkey(elem))<0)
          return -1;
     home = ht->h(k)%ht->M;
     for(pos = home,i=1;(ht->HT[pos]!=(void *)0)&&(ht->HT[pos]!=(void *)1); i++,pos = (home + ht->p(k,i))%(ht->M))
  if( *((int *)elem) == *((int *)(ht->HT[pos])) )
   return -1;
     ht->HT[pos] = elem;
     ht->n++;
     return pos;
}

variable_types: struct s_ihashtable { void **HT; int M; int n; int (*getkey)(void *); int (*h)(int); int (*p)(int, int); } *

variable_types:
elem
void *

variable_types: home int

variable_types: k int

variable_types: pos int


addMinElement

decompiled_code:
__int64 __fastcall addMinElement(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ecx
__int64 result; // rax

if ( a3 == 0 || a2 == 0 || !a1 )
return 0LL;
v3 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v3 < *(_DWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v3) = a2;
++*(_DWORD *)(a1 + 4);
shiftMinUp();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ecx
__int64 result; // rax

if ( a3 == 0 || a2 == 0 || !a1 )
return 0LL;
v3 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v3 < *(_DWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v3) = a2;
++*(_DWORD *)(a1 + 4);
shiftMinUp();
result = 1LL;
}
return result;
}

original_code:
bool addMinElement(t_heap* theHeap, void* element, t_comph comp){
 if(theHeap==((void *)0) || element == ((void *)0) || comp == ((void *)0) || theHeap->current_size>=theHeap->size_max)
  return 0;
 theHeap->tree[theHeap->current_size] = element;
        shiftMinUp(theHeap, theHeap->current_size++, comp);
        return 1;
}

canonical_original_code:
char addMinElement(struct s_heap *theHeap, void *element, int (*comp)(void *, void *)){
 if(theHeap==((void *)0) || element == ((void *)0) || comp == ((void *)0) || theHeap->current_size>=theHeap->size_max)
  return 0;
 theHeap->tree[theHeap->current_size] = element;
        shiftMinUp(theHeap, theHeap->current_size++, comp);
        return 1;
}

variable_types:
element
void *

variable_types:
comp
int (*)(void *, void *)


decompiled_code:
void __fastcall remove_last(void ***a1)
{
void **v1; // rax
void **v2; // rbx

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
v2 = *a1;
while ( *v1 )
{
v2 = v1;
v1 = (void **)*v1;
}
free(*v2);
*v2 = 0LL;
}
}
}

original_code:
void remove_last(t_node** thenode)
{
 if(thenode!=((void*)0) && *thenode!=((void*)0))
 {
  t_node* cnode;
  t_node * head;
  for(head = *thenode, cnode = *thenode; (cnode->next)!=((void*)0);head = cnode, cnode = cnode->next);
  free(head->next);
  head->next = ((void*)0);
 }
}

canonical_original_code:
void remove_last(struct s_node **thenode)
{
 if(thenode!=((void *)0) && *thenode!=((void *)0))
 {
  struct s_node *cnode;
  struct s_node *head;
  for(head = *thenode, cnode = *thenode; (cnode->next)!=((void *)0);head = cnode, cnode = cnode->next);
  free(head->next);
  head->next = ((void *)0);
 }
}

variable_types: struct s_node { struct s_node *next; void *elem; } **


decompiled_code:
void __fastcall remove_node(_QWORD **a1)
{
_QWORD *v1; // rax

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
*a1 = (_QWORD *)*v1;
free(v1);
}
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD **a1)
{
_QWORD *v1; // rax

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
*a1 = (_QWORD *)*v1;
free(v1);
}
}
}

original_code:
void remove_node(t_node** thenode)
{
 if(thenode!=((void*)0) && *thenode!=((void*)0))
 {
  t_node* temp;
  temp = *thenode;
  *thenode = (*thenode)->next;
  temp->next = ((void*)0);
  free(temp);
 }
}

canonical_original_code:
void remove_node(struct s_node **thenode)
{
 if(thenode!=((void *)0) && *thenode!=((void *)0))
 {
  struct s_node *temp;
  temp = *thenode;
  *thenode = (*thenode)->next;
  temp->next = ((void *)0);
  free(temp);
 }
}

user_defined_types: struct s_node { struct s_node *next; void *elem; }


addMaxElement

decompiled_code:
__int64 __fastcall addMaxElement(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ecx
__int64 result; // rax

if ( a3 == 0 || a2 == 0 || !a1 )
return 0LL;
v3 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v3 < *(_DWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v3) = a2;
++*(_DWORD *)(a1 + 4);
shiftMaxUp();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // ecx
__int64 result; // rax

if ( a3 == 0 || a2 == 0 || !a1 )
return 0LL;
v3 = *(_DWORD *)(a1 + 4);
result = 0LL;
if ( v3 < *(_DWORD *)a1 )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v3) = a2;
++*(_DWORD *)(a1 + 4);
shiftMaxUp();
result = 1LL;
}
return result;
}

original_code:
bool addMaxElement(t_heap* theHeap, void* element, t_comph comp){
 if(theHeap==((void *)0) || element == ((void *)0) || comp == ((void *)0) || theHeap->current_size>=theHeap->size_max)
  return 0;
 theHeap->tree[theHeap->current_size] = element;
        shiftMaxUp(theHeap, theHeap->current_size++, comp);
        return 1;
}

canonical_original_code:
char addMaxElement(struct s_heap *theHeap, void *element, int (*comp)(void *, void *)){
 if(theHeap==((void *)0) || element == ((void *)0) || comp == ((void *)0) || theHeap->current_size>=theHeap->size_max)
  return 0;
 theHeap->tree[theHeap->current_size] = element;
        shiftMaxUp(theHeap, theHeap->current_size++, comp);
        return 1;
}


decompiled_code:
__int64 my_alpha()
{
unsigned int i; // ebx

for ( i = 97; i != 123; ++i )
my_char(i);
return my_char(10LL);
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int i; // ebx

for ( i = 97; i != 123; ++i )
my_char(i);
return my_char(10LL);
}

original_code:
void my_alpha()
{
 char start;
 for(start = 'a'; start <= 'z'; start++)
  my_char(start);
 my_char('\n');
}

variable_types: start char


decompiled_code:
__int64 __fastcall my_find(char *a1, char a2)
{
char v2; // dl
__int64 v3; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( a2 != v2 )
{
v2 = a1[++v3];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(v3 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char a2)
{
char v2; // dl
__int64 v3; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v2 = *a1;
if ( !*a1 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( a2 != v2 )
{
v2 = a1[++v3];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)(v3 + 1);
}

original_code:
int my_find(char* string, char idx)
{
 int i;
 if(string != ((void*)0))
  for(i=0; string[i]!= '\0'; i++)
   if(string[i] == idx)
    return ++i;
 return -1;
}

canonical_original_code:
int my_find(char *string, char idx)
{
 int i;
 if(string != ((void *)0))
  for(i=0; string[i]!= '\0'; i++)
   if(string[i] == idx)
    return ++i;
 return -1;
}

variable_types:
string
char *

variable_types: idx char


original_code:
char* my_strnconcat(char* string1, char* string2, int num)
{
 char* ret = ((void*)0);
 if(string1==((void*)0) && string2== ((void*)0))
  return ret;
 else
 {
  int count = 0;
  int length = my_strlen(string2)+my_strlen(string1)-1;
  if (length>=num)
   length = num;
  if(length<1)
   length = 1;
  ret=(char*)my_xmalloc(length*sizeof(char));
  if(string1!=((void*)0))
   for(; *string1!='\0' && count<num;(string1)++)
    ret[count++] = *string1;
  if(string2!=((void*)0))
   for(;*string2!='\0' && count<num; string2++)
    ret[count++] = *string2;
  ret[++count] = '\0';
 }
 return ret;
}

canonical_original_code:
char *my_strnconcat(char *string1, char *string2, int num)
{
 char *ret = ((void*)0);
 if(string1==((void *)0) && string2== ((void *)0))
  return ret;
 else
 {
  int count = 0;
  int length = my_strlen(string2)+my_strlen(string1)-1;
  if (length>=num)
   length = num;
  if(length<1)
   length = 1;
  ret=(char *)my_xmalloc(length*sizeof(char));
  if(string1!=((void *)0))
   for(; *string1!='\0' && count<num;(string1)++)
    ret[count++] = *string1;
  if(string2!=((void *)0))
   for(;*string2!='\0' && count<num; string2++)
    ret[count++] = *string2;
  ret[++count] = '\0';
 }
 return ret;
}

variable_types: num int

variable_types:
ret
char *

variable_types: count int

variable_types: length int


original_code:
char** my_str2vect(char* string)
{
 unsigned int i = 0;
 char flag;
 unsigned int s = 0;
 unsigned int w;
 unsigned int end;
 unsigned int bak;
 for(; *(string) == ' ' || *(string) == '\t'; string++);
 for(s=1, i=0, flag=1; string[i]!='\0'; i++)
 {
  if(string[i] == ' ' || string[i] == '\t')
  {
   if(flag==1)
    flag=0;
  }
  else if(string[i] != ' ' && string[i] != '\t')
  {
   if(flag==0)
   {
    flag=1;
    s++;
   }
  }
 }
 bak=s;
 char** ret = (char**)my_xmalloc((s+1)*sizeof(char*));
 for(end=0, w=0, s=0, i=0, flag=1; string[i]!='\0'; i++)
 {
  if(string[i] == ' ' || string[i] == '\t')
  {
   if(flag==1)
   {
    flag=0;
    ret[s] = (char*)my_xmalloc(sizeof(char)*(w+1));
    ret[s++] = my_strnconcat(&string[end],"\0", w);
   }
  }
  else if(string[i] != ' ' && string[i] != '\t')
  {
   if(flag==0)
   {
    flag=1;
    w=0;
    end = i;
   }
   w++;
  }
 }
 ret[s] = (char*)my_xmalloc(sizeof(char)*(w+1));
 ret[s++] = my_strnconcat(&string[end],"\0", w);
 ret[bak] = ((void*)0);
 return ret;
}

canonical_original_code:
char **my_str2vect(char *string)
{
 unsigned int i = 0;
 char flag;
 unsigned int s = 0;
 unsigned int w;
 unsigned int end;
 unsigned int bak;
 for(; *(string) == ' ' || *(string) == '\t'; string++);
 for(s=1, i=0, flag=1; string[i]!='\0'; i++)
 {
  if(string[i] == ' ' || string[i] == '\t')
  {
   if(flag==1)
    flag=0;
  }
  else if(string[i] != ' ' && string[i] != '\t')
  {
   if(flag==0)
   {
    flag=1;
    s++;
   }
  }
 }
 bak=s;
 char **ret = (char**)my_xmalloc((s+1)*sizeof(char*));
 for(end=0, w=0, s=0, i=0, flag=1; string[i]!='\0'; i++)
 {
  if(string[i] == ' ' || string[i] == '\t')
  {
   if(flag==1)
   {
    flag=0;
    ret[s] = (char *)my_xmalloc(sizeof(char)*(w+1));
    ret[s++] = my_strnconcat(&string[end],"\0", w);
   }
  }
  else if(string[i] != ' ' && string[i] != '\t')
  {
   if(flag==0)
   {
    flag=1;
    w=0;
    end = i;
   }
   w++;
  }
 }
 ret[s] = (char *)my_xmalloc(sizeof(char)*(w+1));
 ret[s++] = my_strnconcat(&string[end],"\0", w);
 ret[bak] = ((void *)0);
 return ret;
}

variable_types:
i
unsigned int

variable_types: flag char

variable_types:
s
unsigned int

variable_types:
w
unsigned int

variable_types:
end
unsigned int

variable_types:
bak
unsigned int

variable_types:
ret
char **

return_type: char **


insertSort

decompiled_code:
char __fastcall insertSort(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD, _QWORD))
{
int v4; // eax
__int64 v5; // r13
__int64 i; // rbx

LOBYTE(v4) = a3 != 0LL;
if ( a3 != 0LL && a2 > 1 )
{
v5 = 1LL;
if ( a1 )
{
do
{
for ( i = v5; (int)i > 0; --i )
{
v4 = a3(*(_QWORD *)(a1 + 8 * i), *(_QWORD *)(a1 + 8 * i - 8));
if ( v4 >= 0 )
break;
LOBYTE(v4) = swap(a1, (unsigned int)i, (unsigned int)(i - 1));
}
++v5;
}
while ( a2 > (int)v5 );
}
}
return v4;
}

canonical_decompiled_code:
char __fastcall func0(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD, _QWORD))
{
int v4; // eax
__int64 v5; // r13
__int64 i; // rbx

LOBYTE(v4) = a3 != 0LL;
if ( a3 != 0LL && a2 > 1 )
{
v5 = 1LL;
if ( a1 )
{
do
{
for ( i = v5; (int)i > 0; --i )
{
v4 = a3(*(_QWORD *)(a1 + 8 * i), *(_QWORD *)(a1 + 8 * i - 8));
if ( v4 >= 0 )
break;
LOBYTE(v4) = swap(a1, (unsigned int)i, (unsigned int)(i - 1));
}
++v5;
}
while ( a2 > (int)v5 );
}
}
return v4;
}

original_code:
void insertSort(void** arr,int n,t_comp comp){
 if((arr!=((void *)0))&&(n>1)&&(comp!=((void *)0))){
 int i,j;
  for(i=1; i<n; i++)
   for(j=i; (j>0)&&(*comp)(arr[j],arr[j-1])<0; j--)
    swap(arr,j,j-1);
 }
}

canonical_original_code:
void insertSort(void **arr, int n, int (*comp)(void *, void *)){
 if((arr!=((void *)0))&&(n>1)&&(comp!=((void *)0))){
 int i; int j;
  for(i=1; i<n; i++)
   for(j=i; (j>0)&&(*comp)(arr[j],arr[j-1])<0; j--)
    swap(arr,j,j-1);
 }
}

variable_types:
arr
void **

variable_types: n int

variable_types: i int

variable_types: j int


iicomp

decompiled_code:
__int64 __fastcall iicomp(__int128 a1)
{
__int64 result; // rax
unsigned int v2; // edi

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
LODWORD(a1) = a1 - DWORD2(a1);
result = 1LL;
if ( *((_QWORD *)&a1 + 1) )
result = v2;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int128 a1)
{
__int64 result; // rax
unsigned int v2; // edi

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
LODWORD(a1) = a1 - DWORD2(a1);
result = 1LL;
if ( *((_QWORD *)&a1 + 1) )
result = v2;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int iicomp(void *x ,void *y){
  int a,b;
        if(x==((void *)0) && y==((void *)0))
                return 0;
        if(x==((void *)0))
                return -1;
        if(y==((void *)0))
                return 1;
  a = *(int *) x;
  b = *(int *) y;
        return x-y;
}

canonical_original_code:
int iicomp(void *x, void *y){
  int a; int b;
        if(x==((void *)0) && y==((void *)0))
                return 0;
        if(x==((void *)0))
                return -1;
        if(y==((void *)0))
                return 1;
  a = *(int *) x;
  b = *(int *) y;
        return x-y;
}

variable_types:
x
void *

variable_types:
y
void *

variable_types: a int

variable_types: b int


original_code:
int my_revstr(char* string)
{
 if(string != ((void*)0))
 {
  int end;
  int start;
  char swap;
  for(start=0, end = my_strlen(string); start<end/2; start++)
  {
   swap = string[start];
   string[start] = string[end-1-start];
   string[end-1-start] = swap;
  }
  return end;
 }
}

canonical_original_code:
int my_revstr(char *string)
{
 if(string != ((void *)0))
 {
  int end;
  int start;
  char swap;
  for(start=0, end = my_strlen(string); start<end/2; start++)
  {
   swap = string[start];
   string[start] = string[end-1-start];
   string[end-1-start] = swap;
  }
  return end;
 }
}

variable_types:
string
char *

variable_types: end int

variable_types: start int

variable_types: swap char


ihashcleanup

original_code:
void ihashcleanup(t_ihashtable *ht){
     void **temp;
     void **arr;
     int i;
     temp = (void**)malloc(sizeof(void*)*ht->M);
     if(ht!=((void *)0)){
          arr = (void**)malloc(sizeof(void*)*ht->M);
          for(i=0; i<ht->M; i++)
               arr[i] = (void*)0;
          temp = ht->HT;
          ht->HT = arr;
          ht->n=0;
          for(i=0;i<ht->M; i++)
               if(temp[i]!=(void*)1&&temp[i]!=(void*)0)
                    ihashadd(ht,temp[i]);
          }
     free(temp);
     free(arr);
}

canonical_original_code:
void ihashcleanup(struct s_ihashtable *ht){
     void **temp;
     void **arr;
     int i;
     temp = (void **)malloc(sizeof(void *)*ht->M);
     if(ht!=((void *)0)){
          arr = (void **)malloc(sizeof(void *)*ht->M);
          for(i=0; i<ht->M; i++)
               arr[i] = (void *)0;
          temp = ht->HT;
          ht->HT = arr;
          ht->n=0;
          for(i=0;i<ht->M; i++)
               if(temp[i]!=(void *)1&&temp[i]!=(void *)0)
                    ihashadd(ht,temp[i]);
          }
     free(temp);
     free(arr);
}

variable_types: struct s_ihashtable { void **HT; int M; int n; int (*getkey)(void *); int (*h)(int); int (*p)(int, int); } *

variable_types:
temp
void **


decompiled_code:
ssize_t __fastcall my_char(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
return write(1, buf, 1uLL);
}

original_code:
void my_char(char c)
{
 write(1,&c,1);
}

canonical_original_code:
void my_char(char c)
{
 write(1,&c,1);
}

variable_types: c char


decompiled_code:
__int64 __fastcall my_strcmp(__int128 a1)
{
__int64 result; // rax
char v2; // dl
char v3; // cl

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
if ( *((_QWORD *)&a1 + 1) )
{
v2 = *(_BYTE *)a1;
result = 0LL;
if ( *(_BYTE *)a1 )
{
while ( 1 )
{
v3 = *(_BYTE *)(*((_QWORD *)&a1 + 1) + result);
if ( !v3 )
break;
if ( v3 != v2 )
return (unsigned int)(v2 - v3);
++result;
v2 = *(_BYTE *)(a1 + result);
if ( !v2 )
return 0LL;
}
result = 0LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int128 a1)
{
__int64 result; // rax
char v2; // dl
char v3; // cl

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
if ( *((_QWORD *)&a1 + 1) )
{
v2 = *(_BYTE *)a1;
result = 0LL;
if ( *(_BYTE *)a1 )
{
while ( 1 )
{
v3 = *(_BYTE *)(*((_QWORD *)&a1 + 1) + result);
if ( !v3 )
break;
if ( v3 != v2 )
return (unsigned int)(v2 - v3);
++result;
v2 = *(_BYTE *)(a1 + result);
if ( !v2 )
return 0LL;
}
result = 0LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int my_strcmp(char* dest, char* src)
{
 int count;
 if(dest==((void*)0) && src== ((void*)0))
  return 0;
 else if(dest==((void*)0))
  return -1;
 else if(src==((void*)0))
  return 1;
 else
 {
  for(count=0; dest[count]!='\0' && src[count]!='\0'; count++)
   if(dest[count]!=src[count])
    return (int)(dest[count] - src[count]);
  return 0;
 }
}

canonical_original_code:
int my_strcmp(char *dest, char *src)
{
 int count;
 if(dest==((void *)0) && src== ((void *)0))
  return 0;
 else if(dest==((void *)0))
  return -1;
 else if(src==((void *)0))
  return 1;
 else
 {
  for(count=0; dest[count]!='\0' && src[count]!='\0'; count++)
   if(dest[count]!=src[count])
    return (int)(dest[count] - src[count]);
  return 0;
 }
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types: count int


ppcomp

decompiled_code:
__int64 __fastcall ppcomp(__int128 a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
result = 1LL;
if ( *((_QWORD *)&a1 + 1) )
{
if ( (unsigned int)sscomp(*(_QWORD *)(a1 + 8), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 8LL)) )
{
result = sscomp(*(_QWORD *)(a1 + 8), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 8LL));
}
else if ( (unsigned int)sscomp(*(_QWORD *)a1, **((_QWORD **)&a1 + 1)) )
{
result = sscomp(*(_QWORD *)a1, **((_QWORD **)&a1 + 1));
}
else
{
result = iicomp(a1 + 16, *((_QWORD *)&a1 + 1) + 16LL);
}
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int128 a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
result = 1LL;
if ( *((_QWORD *)&a1 + 1) )
{
if ( (unsigned int)sscomp(*(_QWORD *)(a1 + 8), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 8LL)) )
{
result = sscomp(*(_QWORD *)(a1 + 8), *(_QWORD *)(*((_QWORD *)&a1 + 1) + 8LL));
}
else if ( (unsigned int)sscomp(*(_QWORD *)a1, **((_QWORD **)&a1 + 1)) )
{
result = sscomp(*(_QWORD *)a1, **((_QWORD **)&a1 + 1));
}
else
{
result = iicomp(a1 + 16, *((_QWORD *)&a1 + 1) + 16LL);
}
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int ppcomp(void* x, void* y){
 t_person* a = (t_person*)x;
 t_person* b = (t_person*)y;
 if(x==((void *)0) && y==((void *)0))
  return 0;
 if(x==((void *)0))
  return -1;
 if(y==((void *)0))
  return 1;
 if(sscomp(a->surname,b->surname) !=0)
  return sscomp(a->surname,b->surname);
 if(sscomp(a->name,b->name) !=0)
  return sscomp(a->name,b->name);
 return iicomp(&a->age,&b->age);
}

canonical_original_code:
int ppcomp(void *x, void *y){
 struct s_person *a = (t_person*)x;
 struct s_person *b = (t_person*)y;
 if(x==((void *)0) && y==((void *)0))
  return 0;
 if(x==((void *)0))
  return -1;
 if(y==((void *)0))
  return 1;
 if(sscomp(a->surname,b->surname) !=0)
  return sscomp(a->surname,b->surname);
 if(sscomp(a->name,b->name) !=0)
  return sscomp(a->name,b->name);
 return iicomp(&a->age,&b->age);
}

variable_types: struct s_person { char *name; char *surname; int age; } *


decompiled_code:
void __fastcall remove_node_at(_QWORD ***a1, int a2)
{
int v2; // ebx
_QWORD **v3; // rax
_QWORD **v4; // rdi

if ( a1 )
{
v2 = a2;
if ( *a1 )
{
if ( a2 <= 0 )
{
remove_node(a1);
}
else if ( (int)count_nodes() < a2 )
{
remove_last(a1);
}
else
{
v3 = *a1;
do
{
v3 = (_QWORD **)*v3;
--v2;
}
while ( v2 );
v4 = (_QWORD **)*v3;
*v3 = (_QWORD *)**v3;
free(v4);
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(_QWORD ***a1, int a2)
{
int v2; // ebx
_QWORD **v3; // rax
_QWORD **v4; // rdi

if ( a1 )
{
v2 = a2;
if ( *a1 )
{
if ( a2 <= 0 )
{
remove_node(a1);
}
else if ( (int)count_nodes() < a2 )
{
remove_last(a1);
}
else
{
v3 = *a1;
do
{
v3 = (_QWORD **)*v3;
--v2;
}
while ( v2 );
v4 = (_QWORD **)*v3;
*v3 = (_QWORD *)**v3;
free(v4);
}
}
}
}

original_code:
void remove_node_at(t_node** thenode, int num)
{
 if(thenode!=((void*)0) && *thenode!=((void*)0))
 {
  if(num<1)
   remove_node(thenode);
  else if(num>count_nodes(*thenode))
   remove_last(thenode);
  else
  {
   t_node* temp;
   t_node* head;
   for(temp = *thenode; 0<num;temp = temp->next, num--);
    head = temp->next;
    temp->next = (temp->next)->next;
    head->next = ((void*)0);
    free(head);
  }
 }
}

canonical_original_code:
void remove_node_at(struct s_node **thenode, int num)
{
 if(thenode!=((void *)0) && *thenode!=((void *)0))
 {
  if(num<1)
   remove_node(thenode);
  else if(num>count_nodes(*thenode))
   remove_last(thenode);
  else
  {
   struct s_node *temp;
   struct s_node *head;
   for(temp = *thenode; 0<num;temp = temp->next, num--);
    head = temp->next;
    temp->next = (temp->next)->next;
    head->next = ((void *)0);
    free(head);
  }
 }
}

variable_types: struct s_node { struct s_node *next; void *elem; } **

variable_types: num int


sscomp

decompiled_code:
int __fastcall sscomp(__int128 a1)
{
int result; // eax

result = 0;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
if ( *((_QWORD *)&a1 + 1) )
result = strcmp((const char *)a1, *((const char **)&a1 + 1));
else
result = 1;
}
else
{
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int128 a1)
{
int result; // eax

result = 0;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
if ( *((_QWORD *)&a1 + 1) )
result = strcmp((const char *)a1, *((const char **)&a1 + 1));
else
result = 1;
}
else
{
result = -1;
}
}
return result;
}

original_code:
int sscomp(void* x ,void* y){
 if(x==((void *)0) && y==((void *)0))
  return 0;
 if(x==((void *)0))
  return -1;
 if(y==((void *)0))
  return 1;
 return strcmp((char*)x,(char*)y);
 }

canonical_original_code:
int sscomp(void *x, void *y){
 if(x==((void *)0) && y==((void *)0))
  return 0;
 if(x==((void *)0))
  return -1;
 if(y==((void *)0))
  return 1;
 return strcmp((char *)x,(char *)y);
 }

variable_types:
x
void *


shiftMinDown

original_code:
void shiftMinDown(t_heap* theHeap, int index, t_comph comp){
 int lc;
 if(index>=0&&theHeap!=((void *)0)&&comp!=((void *)0)&& 2*index+1 < theHeap->current_size){
  lc = 2 * index + 1;
  if((lc+1<theHeap->current_size)&&((*comp)(theHeap->tree[lc + 1],theHeap->tree[lc])<0))
   lc++;
  if(((*comp)(theHeap->tree[lc],theHeap->tree[index])<0)){
      swap(theHeap,lc,index);
      shiftMinDown(theHeap,lc,comp);
  }
 }
}

canonical_original_code:
void shiftMinDown(struct s_heap *theHeap, int index, int (*comp)(void *, void *)){
 int lc;
 if(index>=0&&theHeap!=((void *)0)&&comp!=((void *)0)&& 2*index+1 < theHeap->current_size){
  lc = 2 * index + 1;
  if((lc+1<theHeap->current_size)&&((*comp)(theHeap->tree[lc + 1],theHeap->tree[lc])<0))
   lc++;
  if(((*comp)(theHeap->tree[lc],theHeap->tree[index])<0)){
      swap(theHeap,lc,index);
      shiftMinDown(theHeap,lc,comp);
  }
 }
}

variable_types: struct s_heap { int size_max; int current_size; void **tree; } *

variable_types: index int

variable_types:
comp
int (*)(void *, void *)

variable_types: lc int


term

decompiled_code:
void __fastcall term(int a1)
{
if ( a1 == 2 )
{
my_str("\nEnd of ze Server\n");
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
{
my_str("\nEnd of ze Server\n");
exit(0);
}
}

original_code:
void term(int sig)
{
 if(sig == 2)
 {
  my_str("\nEnd of ze Server\n");
  exit(0);
 }
}

variable_types: sig int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
__pid_t v5; // eax
int v6; // eax
int v7; // ebx
void *v8; // r12
struct sockaddr v9; // [rsp+0h] [rbp-448h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-438h] BYREF
char buf[1036]; // [rsp+20h] [rbp-428h] BYREF
socklen_t addr_len[7]; // [rsp+42Ch] [rbp-1Ch] BYREF

if ( argc > 1 )
{
signal(2, term);
v3 = socket(2, 1, 0);
if ( v3 >= 0 )
{
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v4 = my_atoi(argv[1]);
if ( (unsigned int)(v4 - 1) > 0xFFFE )
{
my_str("Invalid Port Number\n");
exit(0);
}
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(v4);
*(_DWORD *)&addr.sa_data[2] = 0;
if ( bind(v3, &addr, 0x10u) >= 0 )
{
listen(v3, 5);
while ( 1 )
{
addr_len[0] = 16;
v6 = accept(v3, &v9, addr_len);
v7 = v6;
if ( v6 < 0 )
break;
if ( v6 )
{
my_str("Client Accepted\n");
v5 = fork();
if ( v5 < 0 )
{
my_str("Error forking\n");
exit(0);
}
if ( !v5 )
{
close(v3);
buf[(int)read(v7, buf, 0x3FFuLL)] = 0;
v8 = (void *)my_strdup(buf);
my_str("***");
my_str(v8);
my_str(" is connected\n");
while ( 1 )
{
signal(2, term);
memset(buf, 0, 0x400uLL);
buf[(int)read(v7, buf, 0x3FFuLL)] = 0;
if ( !(unsigned int)my_strncmp(buf, "/exit", 5LL) )
break;
if ( (unsigned int)my_strncmp(buf, "/me", 3LL) )
{
if ( (unsigned int)my_strncmp(buf, "/nick", 5LL) )
{
my_str(v8);
my_str(": ");
my_str(buf);
my_char(10LL);
}
else
{
my_str("***");
my_str(v8);
my_str(" was changed to ");
my_str(&buf[6]);
my_char(10LL);
v8 = (void *)my_strdup(&buf[6]);
}
}
else
{
my_str(v8);
my_char(32LL);
my_str(&buf[4]);
my_char(10LL);
}
}
my_str("***");
my_str(v8);
my_str(" has disconnected\n");
close(v7);
free(v8);
exit(0);
}
close(v7);
}
else
{
my_str("Client Closed\n");
}
}
my_str("Could not Accept Connection\n");
exit(0);
}
my_str("Could not bind address\n");
exit(0);
}
my_str("Could not create socket\n");
exit(0);
}
my_str("Use: [port_num]\n");
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
__pid_t v5; // eax
int v6; // eax
int v7; // ebx
void *v8; // r12
struct sockaddr v9; // [rsp+0h] [rbp-448h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-438h] BYREF
char buf[1036]; // [rsp+20h] [rbp-428h] BYREF
socklen_t addr_len[7]; // [rsp+42Ch] [rbp-1Ch] BYREF

if ( argc > 1 )
{
signal(2, term);
v3 = socket(2, 1, 0);
if ( v3 >= 0 )
{
*(_QWORD *)&addr.sa_family = 0LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v4 = my_atoi(argv[1]);
if ( (unsigned int)(v4 - 1) > 0xFFFE )
{
my_str("Invalid Port Number\n");
exit(0);
}
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(v4);
*(_DWORD *)&addr.sa_data[2] = 0;
if ( bind(v3, &addr, 0x10u) >= 0 )
{
listen(v3, 5);
while ( 1 )
{
addr_len[0] = 16;
v6 = accept(v3, &v9, addr_len);
v7 = v6;
if ( v6 < 0 )
break;
if ( v6 )
{
my_str("Client Accepted\n");
v5 = fork();
if ( v5 < 0 )
{
my_str("Error forking\n");
exit(0);
}
if ( !v5 )
{
close(v3);
buf[(int)read(v7, buf, 0x3FFuLL)] = 0;
v8 = (void *)my_strdup(buf);
my_str("***");
my_str(v8);
my_str(" is connected\n");
while ( 1 )
{
signal(2, term);
memset(buf, 0, 0x400uLL);
buf[(int)read(v7, buf, 0x3FFuLL)] = 0;
if ( !(unsigned int)my_strncmp(buf, "/exit", 5LL) )
break;
if ( (unsigned int)my_strncmp(buf, "/me", 3LL) )
{
if ( (unsigned int)my_strncmp(buf, "/nick", 5LL) )
{
my_str(v8);
my_str(": ");
my_str(buf);
my_char(10LL);
}
else
{
my_str("***");
my_str(v8);
my_str(" was changed to ");
my_str(&buf[6]);
my_char(10LL);
v8 = (void *)my_strdup(&buf[6]);
}
}
else
{
my_str(v8);
my_char(32LL);
my_str(&buf[4]);
my_char(10LL);
}
}
my_str("***");
my_str(v8);
my_str(" has disconnected\n");
close(v7);
free(v8);
exit(0);
}
close(v7);
}
else
{
my_str("Client Closed\n");
}
}
my_str("Could not Accept Connection\n");
exit(0);
}
my_str("Could not bind address\n");
exit(0);
}
my_str("Could not create socket\n");
exit(0);
}
my_str("Use: [port_num]\n");
exit(0);
}

original_code:
int main(int argc, char** argv)
{
 int sockfd;
 int sockfd2;
 int port_num;
 int client;
  int n;
 int l;
 int pid;
 char buffer[1024];
 char* nname ;
 struct sockaddr_in server_adderess;
 struct sockaddr_in client_adderess;
 if(argc < 2)
 {
  my_str("Use: [port_num]\n");
  exit(0);
 }
 signal(2, term);
 sockfd = socket(2, SOCK_STREAM, 0);
 if(sockfd < 0)
 {
  my_str("Could not create socket\n");
  exit(0);
 }
 bzero((char*)&server_adderess, sizeof(server_adderess));
 port_num = my_atoi(argv[1]);
 if(port_num < 1 || port_num > 65535)
 {
  my_str("Invalid Port Number\n");
  exit(0);
 }
 server_adderess.sin_family = 2;
 server_adderess.sin_port = htons(port_num);
 server_adderess.sin_addr.s_addr = ((in_addr_t) 0x00000000);
 if(bind(sockfd, (struct sockaddr *)&server_adderess, sizeof(server_adderess)) < 0)
 {
  my_str("Could not bind address\n");
  exit(0);
 }
 listen(sockfd, 5);
 while(1)
 {
  client = sizeof(client_adderess);
  sockfd2 = accept(sockfd, (struct sockaddr *)&client_adderess, &client);
  if(sockfd2 < 0)
  {
   my_str("Could not Accept Connection\n");
   exit(0);
  }
  else if(sockfd2 == 0)
   my_str("Client Closed\n");
  else
  {
   my_str("Client Accepted\n");
   if((pid = fork()) < 0)
   {
    my_str("Error forking\n");
    exit(0);
   }
   if(pid==0)
   {
    nname =((void *)0);
    close(sockfd);
    n=read(sockfd2, buffer, 1024 -1);
    buffer[n]='\0';
    nname = my_strdup(buffer);
    my_str("***");
    my_str(nname);
    my_str(" is connected\n");
    while(1)
    {
     signal(2, term);
     bzero(buffer, 1024);
     n=read(sockfd2, buffer, 1024 -1);
     buffer[n]='\0';
     if(my_strncmp(buffer, "/exit", 5) == 0)
     {
      my_str("***");
      my_str(nname);
      my_str(" has disconnected\n");
      close(sockfd2);
      free(nname);
      exit(0);
     }
     else if(my_strncmp(buffer, "/me", 3) == 0)
     {
      my_str(nname);
      my_char(' ');
      my_str(&buffer[4]);
      my_char('\n');
     }
     else if(my_strncmp(buffer, "/nick", 5) == 0)
     {
      my_str("***");
      my_str(nname);
      my_str(" was changed to ");
      my_str(&buffer[6]);
      my_char('\n');
      nname = my_strdup(&buffer[6]);
     }
     else
     {
      my_str(nname);
      my_str(": ");
      my_str(buffer);
      my_char('\n');
     }
    }
   }
   close(sockfd2);
  }
 }
}

canonical_original_code:
int main(int argc, char **argv)
{
 int sockfd;
 int sockfd2;
 int port_num;
 int client;
  int n;
 int l;
 int pid;
 char buffer[1024];
 char *nname;
 struct sockaddr_in server_adderess;
 struct sockaddr_in client_adderess;
 if(argc < 2)
 {
  my_str("Use: [port_num]\n");
  exit(0);
 }
 signal(2, term);
 sockfd = socket(2, SOCK_STREAM, 0);
 if(sockfd < 0)
 {
  my_str("Could not create socket\n");
  exit(0);
 }
 bzero((char *)&server_adderess, sizeof(server_adderess));
 port_num = my_atoi(argv[1]);
 if(port_num < 1 || port_num > 65535)
 {
  my_str("Invalid Port Number\n");
  exit(0);
 }
 server_adderess.sin_family = 2;
 server_adderess.sin_port = htons(port_num);
 server_adderess.sin_addr.s_addr = ((unsigned int) 0x00000000);
 if(bind(sockfd, (struct sockaddr *)&server_adderess, sizeof(server_adderess)) < 0)
 {
  my_str("Could not bind address\n");
  exit(0);
 }
 listen(sockfd, 5);
 while(1)
 {
  client = sizeof(client_adderess);
  sockfd2 = accept(sockfd, (struct sockaddr *)&client_adderess, &client);
  if(sockfd2 < 0)
  {
   my_str("Could not Accept Connection\n");
   exit(0);
  }
  else if(sockfd2 == 0)
   my_str("Client Closed\n");
  else
  {
   my_str("Client Accepted\n");
   if((pid = fork()) < 0)
   {
    my_str("Error forking\n");
    exit(0);
   }
   if(pid==0)
   {
    nname =((void *)0);
    close(sockfd);
    n=read(sockfd2, buffer, 1024 -1);
    buffer[n]='\0';
    nname = my_strdup(buffer);
    my_str("***");
    my_str(nname);
    my_str(" is connected\n");
    while(1)
    {
     signal(2, term);
     bzero(buffer, 1024);
     n=read(sockfd2, buffer, 1024 -1);
     buffer[n]='\0';
     if(my_strncmp(buffer, "/exit", 5) == 0)
     {
      my_str("***");
      my_str(nname);
      my_str(" has disconnected\n");
      close(sockfd2);
      free(nname);
      exit(0);
     }
     else if(my_strncmp(buffer, "/me", 3) == 0)
     {
      my_str(nname);
      my_char(' ');
      my_str(&buffer[4]);
      my_char('\n');
     }
     else if(my_strncmp(buffer, "/nick", 5) == 0)
     {
      my_str("***");
      my_str(nname);
      my_str(" was changed to ");
      my_str(&buffer[6]);
      my_char('\n');
      nname = my_strdup(&buffer[6]);
     }
     else
     {
      my_str(nname);
      my_str(": ");
      my_str(buffer);
      my_char('\n');
     }
    }
   }
   close(sockfd2);
  }
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: sockfd int

variable_types: client int

variable_types: n int

variable_types: l int

variable_types: pid int

variable_types:
buffer
char [1024]

variable_types:
nname
char *

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]; }

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]; }


decompiled_code:
void __fastcall add_elem(__int64 a1, _QWORD *a2)
{
if ( a2 )
{
if ( a1 )
*a2 = new_node(a1, *a2);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, _QWORD *a2)
{
if ( a2 )
{
if ( a1 )
*a2 = new_node(a1, *a2);
}
}

original_code:
void add_elem(void* element, t_node** thenode)
{
 if(thenode!=((void*)0) && element != ((void*)0))
 {
  t_node* n = new_node(element, *thenode);
  *thenode = n;
 }
}

canonical_original_code:
void add_elem(void *element, struct s_node **thenode)
{
 if(thenode!=((void *)0) && element != ((void *)0))
 {
  struct s_node *n = new_node(element, *thenode);
  *thenode = n;
 }
}

variable_types:
element
void *

variable_types: struct s_node { struct s_node *next; void *elem; } **


decompiled_code:
void *__fastcall my_xmalloc(int a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
my_str("Virtual Memory exausted\n");
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
my_str("Virtual Memory exausted\n");
exit(1);
}
return result;
}

original_code:
void* my_xmalloc(int size)
{
 void* ret;
 ret=malloc(size);
 if(ret==((void*)0))
 {
  my_str("Virtual Memory exausted\n");
  exit(1);
 }
 return ret;
}

canonical_original_code:
void *my_xmalloc(int size)
{
 void *ret;
 ret=malloc(size);
 if(ret==((void *)0))
 {
  my_str("Virtual Memory exausted\n");
  exit(1);
 }
 return ret;
}

variable_types: size int

variable_types:
ret
void *


decompiled_code:
__int64 __fastcall empty_list(_QWORD *a1)
{
__int64 result; // rax

for ( ; *a1; result = remove_node(a1) )
;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 result; // rax

for ( ; *a1; result = remove_node(a1) )
;
return result;
}

original_code:
void empty_list(t_node** thenode)
{
 for(; *thenode!=((void*)0);)
  remove_node(thenode);
}

canonical_original_code:
void empty_list(struct s_node **thenode)
{
 for(; *thenode!=((void *)0);)
  remove_node(thenode);
}


original_code:
char* my_digits2()
{
 char* ret = (char*)my_xmalloc(11*sizeof(char));
 char start;
 int i;
 for(i=0, start = '0'; start <='9'; start++)
 {
  ret[i++] = start;
 }
 ret[10] = '\0';
 return ret;
}

canonical_original_code:
char *my_digits2()
{
 char *ret = (char*)my_xmalloc(11*sizeof(char));
 char start;
 int i;
 for(i=0, start = '0'; start <='9'; start++)
 {
  ret[i++] = start;
 }
 ret[10] = '\0';
 return ret;
}

variable_types:
ret
char *

variable_types: start char

variable_types: i int


shiftMinUp

decompiled_code:
char __fastcall shiftMinUp(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD, _QWORD))
{
int v4; // eax
unsigned int v5; // er13

LOBYTE(v4) = a3 != 0LL;
if ( a3 != 0LL && a1 != 0 && a2 > 0 )
{
v5 = (a2 - 1) / 2;
v4 = a3(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)v5));
if ( v4 < 0 )
{
swap(a1, v5, (unsigned int)a2);
LOBYTE(v4) = shiftMinUp(a1, v5, a3);
}
}
return v4;
}

canonical_decompiled_code:
char __fastcall func0(__int64 a1, int a2, __int64 (__fastcall *a3)(_QWORD, _QWORD))
{
int v4; // eax
unsigned int v5; // er13

LOBYTE(v4) = a3 != 0LL;
if ( a3 != 0LL && a1 != 0 && a2 > 0 )
{
v5 = (a2 - 1) / 2;
v4 = a3(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2), *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)v5));
if ( v4 < 0 )
{
swap(a1, v5, (unsigned int)a2);
LOBYTE(v4) = func0(a1, v5, a3);
}
}
return v4;
}

original_code:
void shiftMinUp(t_heap* theHeap, int index, t_comph comp){
 if(index>0&&theHeap!=((void *)0)&&comp!=((void *)0)){
  int p;
  p = (index-1)/2;
  if((*comp)(theHeap->tree[index],theHeap->tree[p])<0){
          swap(theHeap,p,index);
          shiftMinUp(theHeap,p,comp);
  }
 }
}

canonical_original_code:
void shiftMinUp(struct s_heap *theHeap, int index, int (*comp)(void *, void *)){
 if(index>0&&theHeap!=((void *)0)&&comp!=((void *)0)){
  int p;
  p = (index-1)/2;
  if((*comp)(theHeap->tree[index],theHeap->tree[p])<0){
          swap(theHeap,p,index);
          shiftMinUp(theHeap,p,comp);
  }
 }
}

variable_types: struct s_heap { int size_max; int current_size; void **tree; } *

variable_types: index int

variable_types:
comp
int (*)(void *, void *)

variable_types: p int


decompiled_code:
__int64 my_digits()
{
unsigned int i; // ebx

for ( i = 48; i != 58; ++i )
my_char(i);
return my_char(10LL);
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int i; // ebx

for ( i = 48; i != 58; ++i )
my_char(i);
return my_char(10LL);
}

original_code:
void my_digits()
{
 char start;
 for(start = '0'; start <='9'; start++)
 {
  my_char(start);
 }
 my_char('\n');
}


decompiled_code:
void __noreturn no_files()
{
my_str("No files matched input");
restore_terminal();
exit(1);
}

canonical_decompiled_code:
void __noreturn func2()
{
my_str("No files matched input");
func1();
exit(1);
}

original_code:
int no_files()
{
  my_str("No files matched input");
  restore_terminal();
  exit(1);
}


decompiled_code:
__int64 __fastcall my_strncmp(__int128 a1, int a2)
{
__int64 result; // rax
char v4; // dl
char v5; // cl
__int64 v6; // rax
bool v7; // r9

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
if ( *((_QWORD *)&a1 + 1) )
{
v4 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 )
{
v5 = **((_BYTE **)&a1 + 1);
if ( a2 > 0 && v5 )
{
v6 = 1LL;
while ( 1 )
{
if ( v4 != v5 )
return (unsigned int)(v4 - v5);
v4 = *(_BYTE *)(a1 + v6);
if ( !v4 )
break;
v5 = *(_BYTE *)(*((_QWORD *)&a1 + 1) + v6);
v7 = a2 > (int)v6++;
if ( v5 == 0 || !v7 )
return 0LL;
}
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int128 a1, int a2)
{
__int64 result; // rax
char v4; // dl
char v5; // cl
__int64 v6; // rax
bool v7; // r9

result = 0LL;
if ( a1 != 0 )
{
if ( (_QWORD)a1 )
{
if ( *((_QWORD *)&a1 + 1) )
{
v4 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 )
{
v5 = **((_BYTE **)&a1 + 1);
if ( a2 > 0 && v5 )
{
v6 = 1LL;
while ( 1 )
{
if ( v4 != v5 )
return (unsigned int)(v4 - v5);
v4 = *(_BYTE *)(a1 + v6);
if ( !v4 )
break;
v5 = *(_BYTE *)(*((_QWORD *)&a1 + 1) + v6);
v7 = a2 > (int)v6++;
if ( v5 == 0 || !v7 )
return 0LL;
}
result = 0LL;
}
else
{
result = 0LL;
}
}
else
{
result = 0LL;
}
}
else
{
result = 1LL;
}
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int my_strncmp(char* dest, char* src, int length)
{
 int count;
 if(dest==((void*)0) && src== ((void*)0))
  return 0;
 else if(dest==((void*)0))
  return -1;
 else if(src==((void*)0))
  return 1;
 else
 {
  for(count=0; (dest[count]!='\0' && src[count]!='\0') && count<length; count++)
   if(dest[count]!=src[count])
    return (int)(dest[count] - src[count]);
  return 0;
 }
}

canonical_original_code:
int my_strncmp(char *dest, char *src, int length)
{
 int count;
 if(dest==((void *)0) && src== ((void *)0))
  return 0;
 else if(dest==((void *)0))
  return -1;
 else if(src==((void *)0))
  return 1;
 else
 {
  for(count=0; (dest[count]!='\0' && src[count]!='\0') && count<length; count++)
   if(dest[count]!=src[count])
    return (int)(dest[count] - src[count]);
  return 0;
 }
}

variable_types:
dest
char *

variable_types:
src
char *

variable_types: length int

variable_types: count int


decompiled_code:
__int64 __fastcall my_rfind(char *a1, char a2)
{
char v2; // dl
int v3; // eax
unsigned int v4; // ecx

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
if ( !*a1 )
return (unsigned int)-1;
v3 = 0;
v4 = -1;
do
{
if ( a2 == v2 )
v4 = ++v3;
v2 = a1[++v3];
}
while ( v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char a2)
{
char v2; // dl
int v3; // eax
unsigned int v4; // ecx

if ( !a1 )
return (unsigned int)-1;
v2 = *a1;
if ( !*a1 )
return (unsigned int)-1;
v3 = 0;
v4 = -1;
do
{
if ( a2 == v2 )
v4 = ++v3;
v2 = a1[++v3];
}
while ( v2 );
return v4;
}

original_code:
int my_rfind(char* string, char idx)
{
 int ret =-1;
 if(string != ((void*)0))
 {
  int count;
  for(count=0; string[count]!= '\0'; count++)
   if(string[count] == idx)
    ret = ++count;
  return ret;
 }
 return -1;
}

canonical_original_code:
int my_rfind(char *string, char idx)
{
 int ret = -1;
 if(string != ((void *)0))
 {
  int count;
  for(count=0; string[count]!= '\0'; count++)
   if(string[count] == idx)
    ret = ++count;
  return ret;
 }
 return -1;
}

variable_types:
string
char *

variable_types: idx char

variable_types: ret int


radixSort

original_code:
void radixSort(int* arr, int n, int radix){
 if((arr!=((void *)0))&&(n>1)&&(radix>1)){
  int i;
  int max;
  int exp;
  int* temp = (int*)malloc(sizeof(int)*n);
  int* count = (int*)malloc(sizeof(int)*radix);
  for(max = arr[0],i=0;i<n;i++)
   if(arr[i]>max)
    max=arr[i];
  for(exp=1; exp<=max; exp*=radix){
   for(i=0; i<radix; i++)
    count[i]=0;
   for(i=0; i<n; i++)
    count[(arr[i]/exp)%radix]++;
   for(i=1; i<radix; i++)
    count[i]+=count[i-1];
   for(i=n-1; i>=0; i--)
    temp[--count[(arr[i]/exp)%radix]] = arr[i];
   for(i=0; i<n; i++)
    arr[i]=temp[i];
  }
  free(temp);
  free(count);
 }
}

canonical_original_code:
void radixSort(int *arr, int n, int radix){
 if((arr!=((void *)0))&&(n>1)&&(radix>1)){
  int i;
  int max;
  int exp;
  int *temp = (int*)malloc(sizeof(int)*n);
  int *count = (int*)malloc(sizeof(int)*radix);
  for(max = arr[0],i=0;i<n;i++)
   if(arr[i]>max)
    max=arr[i];
  for(exp=1; exp<=max; exp*=radix){
   for(i=0; i<radix; i++)
    count[i]=0;
   for(i=0; i<n; i++)
    count[(arr[i]/exp)%radix]++;
   for(i=1; i<radix; i++)
    count[i]+=count[i-1];
   for(i=n-1; i>=0; i--)
    temp[--count[(arr[i]/exp)%radix]] = arr[i];
   for(i=0; i<n; i++)
    arr[i]=temp[i];
  }
  free(temp);
  free(count);
 }
}

variable_types:
arr
int *

variable_types: n int

variable_types: radix int

variable_types: max int

variable_types: exp int

variable_types:
temp
int *

variable_types:
count
int *


printHeap

original_code:
void printHeap(t_heap* theHeap){
 int i;
 for(i=0; i<theHeap->current_size;i++)
  printf("%d:%d\n",i,*((int*)theHeap->tree[i]));
 printf("-----------\n");
}

canonical_original_code:
void printHeap(struct s_heap *theHeap){
 int i;
 for(i=0; i<theHeap->current_size;i++)
  printf("%d:%d\n",i,*((int *)theHeap->tree[i]));
 printf("-----------\n");
}

variable_types: struct s_heap { int size_max; int current_size; void **tree; } *

variable_types: i int


repo: GeorgiKhomeriki/CursesOfLife

decompiled_code:
__int64 init_params()
{
int v0; // edx
int v1; // ecx
__int64 result; // rax

if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v0 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy + 1;
v1 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxx + 1;
}
else
{
v0 = -1;
v1 = -1;
}
width = v1;
height = v0 - 2;
result = (unsigned int)(v1 * (v0 - 2));
num_cells = v1 * (v0 - 2);
return result;
}

canonical_decompiled_code:
__int64 func7()
{
int v0; // edx
int v1; // ecx
__int64 result; // rax

if ( stdscr__NCURSES6_TINFO_5_0_19991023 )
{
v0 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxy + 1;
v1 = stdscr__NCURSES6_TINFO_5_0_19991023->_maxx + 1;
}
else
{
v0 = -1;
v1 = -1;
}
width = v1;
height = v0 - 2;
result = (unsigned int)(v1 * (v0 - 2));
num_cells = v1 * (v0 - 2);
return result;
}

original_code:
void init_params(void)
{
 (_height = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), _width = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 _height -= 2;
 _num_cells = _height * _width;
}

canonical_original_code:
void init_params()
{
 (_height = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), _width = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
 _height -= 2;
 _num_cells = _height * _width;
}


decompiled_code:
int __fastcall lock_fps(__int64 a1, int a2)
{
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v3.tv_sec = 0LL;
v3.tv_nsec = 1000000000 / a2 - 1000 * (clock() - a1);
return nanosleep(&v3, 0LL);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, int a2)
{
struct timespec v3; // [rsp+0h] [rbp-28h] BYREF

v3.tv_sec = 0LL;
v3.tv_nsec = 1000000000 / a2 - 1000 * (clock() - a1);
return nanosleep(&v3, 0LL);
}

original_code:
void lock_fps(clock_t start, int fps)
{
 struct timespec delay;
 delay.tv_sec = 0;
 delay.tv_nsec = 1000000000 / fps - (clock() - start) * 1000000000 / ((__clock_t) 1000000);
 nanosleep(&delay, ((void *)0));
}

canonical_original_code:
void lock_fps(long start, int fps)
{
 struct timespec delay;
 delay.tv_sec = 0;
 delay.tv_nsec = 1000000000 / fps - (clock() - start) * 1000000000 / ((long) 1000000);
 nanosleep(&delay, ((void *)0));
}

variable_types: start long

variable_types: fps int

variable_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int __fastcall show_info(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rdi
unsigned int v3; // ebx
unsigned __int8 *v4; // rdx

if ( num_cells <= 0 )
{
v3 = 0;
}
else
{
v1 = a1;
v2 = &a1[num_cells - 1];
v3 = 0;
do
{
v3 += *v1;
v4 = v1++;
}
while ( v4 != v2 );
}
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200200uLL, 0LL);
mvprintw(LINES__NCURSES6_TINFO_5_0_19991023 - 1, 2, " Press q to exit ");
mvprintw(LINES__NCURSES6_TINFO_5_0_19991023 - 1, (width - 17) / 2, " Cells alive: %d ", v3);
mvprintw(LINES__NCURSES6_TINFO_5_0_19991023 - 1, width - 21, " Press r to reset ");
return wattr_off(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200200uLL, 0LL);
}

canonical_decompiled_code:
int __fastcall func9(unsigned __int8 *a1)
{
unsigned __int8 *v1; // rax
unsigned __int8 *v2; // rdi
unsigned int v3; // ebx
unsigned __int8 *v4; // rdx

if ( num_cells <= 0 )
{
v3 = 0;
}
else
{
v1 = a1;
v2 = &a1[num_cells - 1];
v3 = 0;
do
{
v3 += *v1;
v4 = v1++;
}
while ( v4 != v2 );
}
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200200uLL, 0LL);
mvprintw(LINES__NCURSES6_TINFO_5_0_19991023 - 1, 2, " Press q to exit ");
mvprintw(LINES__NCURSES6_TINFO_5_0_19991023 - 1, (width - 17) / 2, " Cells alive: %d ", v3);
mvprintw(LINES__NCURSES6_TINFO_5_0_19991023 - 1, width - 21, " Press r to reset ");
return wattr_off(stdscr__NCURSES6_TINFO_5_0_19991023, 0x200200uLL, 0LL);
}

variable_types:
world
_Bool *


decompiled_code:
unsigned __int64 __fastcall init_world(_BYTE *a1)
{
unsigned __int64 result; // rax
_BYTE *v2; // rbx
_BYTE *v3; // rbp

result = (unsigned int)num_cells;
if ( num_cells > 0 )
{
v2 = a1;
v3 = &a1[num_cells - 1];
do
{
*v2 = rand() & 1;
result = (unsigned __int64)v2++;
}
while ( (_BYTE *)result != v3 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(_BYTE *a1)
{
unsigned __int64 result; // rax
_BYTE *v2; // rbx
_BYTE *v3; // rbp

result = (unsigned int)num_cells;
if ( num_cells > 0 )
{
v2 = a1;
v3 = &a1[num_cells - 1];
do
{
*v2 = rand() & 1;
result = (unsigned __int64)v2++;
}
while ( (_BYTE *)result != v3 );
}
return result;
}

original_code:
void init_world(_Bool *world)
{
 int n;
 for(n = 0; n < _num_cells; n++)
  world[n] = rand() % 2;
}


decompiled_code:
int __fastcall draw_world(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int16 v3[13]; // [rsp+Eh] [rbp-1Ah]

v3[0] = 20256;
result = wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 0, 0);
if ( num_cells > 0 )
{
v2 = 0LL;
do
result = printw("%c", (unsigned int)*((char *)v3 + *(unsigned __int8 *)(a1 + v2++)));
while ( num_cells > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int16 v3[13]; // [rsp+Eh] [rbp-1Ah]

v3[0] = 20256;
result = wmove(stdscr__NCURSES6_TINFO_5_0_19991023, 0, 0);
if ( num_cells > 0 )
{
v2 = 0LL;
do
result = printw("%c", (unsigned int)*((char *)v3 + *(unsigned __int8 *)(a1 + v2++)));
while ( num_cells > (int)v2 );
}
return result;
}

original_code:
void draw_world(const _Bool *world)
{
 char chars[2] = {' ', 'O'};
 int n;
 wmove(stdscr,(0),(0));
 for(n = 0; n < _num_cells; n++)
  printw("%c", chars[world[n]]);
}

canonical_original_code:
void draw_world(_Bool *world)
{
 char chars[2] = {' ', 'O'};
 int n;
 wmove(stdscr,(0),(0));
 for(n = 0; n < _num_cells; n++)
  printw("%c", chars[world[n]]);
}

variable_types:
chars
char [2]


decompiled_code:
__int64 __fastcall get_cell(__int64 a1, int a2, int a3)
{
return *(unsigned __int8 *)(a1 + a2 + width * a3);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, int a3)
{
return *(unsigned __int8 *)(a1 + a2 + width * a3);
}

original_code:
_Bool get_cell(const _Bool *world, const int x, const int y)
{
 return world[y * _width + x];
}

canonical_original_code:
_Bool get_cell(_Bool *world, int x, int y)
{
 return world[y * _width + x];
}

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall count_neighbours(__int64 a1, int a2, int a3)
{
int v3; // ebp
int v4; // er15
unsigned __int8 v5; // r13
int v6; // er15
int v7; // er15
int v8; // er15
int v9; // er15
int v10; // er15
int v12; // [rsp+4h] [rbp-34h]

v3 = a3;
v4 = a3 - 1;
v5 = get_cell(a1, a2 - 1, a3 - 1);
v12 = v5 + (unsigned __int8)get_cell(a1, a2, v4);
v6 = v12 + (unsigned __int8)get_cell(a1, a2 + 1, v4);
v7 = (unsigned __int8)get_cell(a1, a2 - 1, v3) + v6;
v8 = (unsigned __int8)get_cell(a1, a2 + 1, v3++) + v7;
v9 = (unsigned __int8)get_cell(a1, a2 - 1, v3) + v8;
v10 = (unsigned __int8)get_cell(a1, a2, v3) + v9;
return v10 + (unsigned int)(unsigned __int8)get_cell(a1, a2 + 1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2, int a3)
{
int v3; // ebp
int v4; // er15
unsigned __int8 v5; // r13
int v6; // er15
int v7; // er15
int v8; // er15
int v9; // er15
int v10; // er15
int v12; // [rsp+4h] [rbp-34h]

v3 = a3;
v4 = a3 - 1;
v5 = func12(a1, a2 - 1, a3 - 1);
v12 = v5 + (unsigned __int8)func12(a1, a2, v4);
v6 = v12 + (unsigned __int8)func12(a1, a2 + 1, v4);
v7 = (unsigned __int8)func12(a1, a2 - 1, v3) + v6;
v8 = (unsigned __int8)func12(a1, a2 + 1, v3++) + v7;
v9 = (unsigned __int8)func12(a1, a2 - 1, v3) + v8;
v10 = (unsigned __int8)func12(a1, a2, v3) + v9;
return v10 + (unsigned int)(unsigned __int8)func12(a1, a2 + 1, v3);
}

original_code:
int count_neighbours(const _Bool *world, const int x, const int y)
{
 return get_cell(world, x-1, y-1) +
  get_cell(world, x, y-1) +
  get_cell(world, x+1, y-1) +
  get_cell(world, x-1, y) +
  get_cell(world, x+1, y) +
  get_cell(world, x-1, y+1) +
  get_cell(world, x, y+1) +
  get_cell(world, x+1, y+1);
}

canonical_original_code:
int count_neighbours(_Bool *world, int x, int y)
{
 return get_cell(world, x-1, y-1) +
  get_cell(world, x, y-1) +
  get_cell(world, x+1, y-1) +
  get_cell(world, x-1, y) +
  get_cell(world, x+1, y) +
  get_cell(world, x-1, y+1) +
  get_cell(world, x, y+1) +
  get_cell(world, x+1, y+1);
}


decompiled_code:
__int64 __fastcall update_world(__int64 a1)
{
void *v1; // rsp
int v2; // er14
__int64 v3; // r15
bool v4; // dl
__int64 v5; // rbx
int v6; // eax
char *v7; // r12
__int64 result; // rax
__int64 v9; // rcx
__int64 v10; // [rsp+0h] [rbp-50h] BYREF
unsigned int v11; // [rsp+8h] [rbp-48h]
int v12; // [rsp+Ch] [rbp-44h]
__int64 *v13; // [rsp+10h] [rbp-40h]
int v14; // [rsp+18h] [rbp-38h]
int v15; // [rsp+1Ch] [rbp-34h]

v11 = num_cells;
v1 = alloca(num_cells);
v13 = &v10;
v12 = height;
if ( height > 0 )
{
v14 = width;
v15 = 0;
v2 = 0;
v3 = (unsigned int)width;
do
{
v5 = 0LL;
v7 = (char *)v13 + v15;
if ( v14 > 0 )
{
do
{
v6 = count_neighbours(a1, v5, v2);
if ( v6 != 2 || (v4 = 1, !*(_BYTE *)(a1 + v15 + (int)v5)) )
v4 = v6 == 3;
v7[v5] = v4;
v7[v5++] &= 1u;
}
while ( v5 != v3 );
}
++v2;
v15 += v14;
}
while ( v2 != v12 );
}
result = v11;
if ( (int)v11 > 0 )
{
v9 = v11;
for ( result = 0LL; result != v9; ++result )
*(_BYTE *)(a1 + result) = *((_BYTE *)v13 + result);
}
return result;
}

original_code:
void update_world(_Bool *world)
{
 _Bool new_world[_num_cells];
 int y, x;
 for(y = 0; y < _height; y++) {
  for(x = 0; x < _width; x++) {
   int neighbours = count_neighbours(world, x, y);
   new_world[y * _width + x] = neighbours == 2 && world[y * _width + x]
    || neighbours == 3;
  }
 }
 int n;
 for(n = 0; n < _num_cells; n++)
  world[n] = new_world[n];
}

canonical_original_code:
void update_world(_Bool *world)
{
 _Bool new_world[-1];
 int y; int x;
 for(y = 0; y < _height; y++) {
  for(x = 0; x < _width; x++) {
   int neighbours = count_neighbours(world, x, y);
   new_world[y * _width + x] = neighbours == 2 && world[y * _width + x]
    || neighbours == 3;
  }
 }
 int n;
 for(n = 0; n < _num_cells; n++)
  world[n] = new_world[n];
}

variable_types: neighbours int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void *v4; // rsp
int v5; // ebx
__int64 v6; // r12
unsigned __int8 v8[32]; // [rsp+0h] [rbp-20h] BYREF

v3 = time(0LL);
srand(v3);
initscr();
wclear(stdscr__NCURSES6_TINFO_5_0_19991023);
noecho();
cbreak();
curs_set(0);
nodelay(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
start_color();
init_pair(1, 6, 0);
init_pair(2, 2, 4);
init_params();
v4 = alloca(num_cells);
init_world(v8);
while ( 1 )
{
v5 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
if ( v5 == 113 )
break;
v6 = clock();
if ( v5 == 114 )
init_world(v8);
show_info(v8);
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
draw_world((__int64)v8);
wattr_off(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
update_world((__int64)v8);
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
lock_fps(v6, 30);
}
wclrtoeol(stdscr__NCURSES6_TINFO_5_0_19991023);
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
void *v4; // rsp
int v5; // ebx
__int64 v6; // r12
unsigned __int8 v8[32]; // [rsp+0h] [rbp-20h] BYREF

v3 = time(0LL);
srand(v3);
initscr();
wclear(stdscr__NCURSES6_TINFO_5_0_19991023);
noecho();
cbreak();
curs_set(0);
nodelay(stdscr__NCURSES6_TINFO_5_0_19991023, 1);
start_color();
init_pair(1, 6, 0);
init_pair(2, 2, 4);
func7();
v4 = alloca(num_cells);
func10(v8);
while ( 1 )
{
v5 = wgetch(stdscr__NCURSES6_TINFO_5_0_19991023);
if ( v5 == 113 )
break;
v6 = clock();
if ( v5 == 114 )
func10(v8);
func9(v8);
wattr_on(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
func11((__int64)v8);
wattr_off(stdscr__NCURSES6_TINFO_5_0_19991023, 0x100uLL, 0LL);
func14((__int64)v8);
wrefresh(stdscr__NCURSES6_TINFO_5_0_19991023);
func8(v6, 30);
}
wclrtoeol(stdscr__NCURSES6_TINFO_5_0_19991023);
endwin();
return 0;
}

original_code:
int main(void)
{
 srand(time(((void *)0)));
 initscr();
 wclear(stdscr);
 noecho();
 cbreak();
 curs_set(0);
 nodelay(stdscr, 1);
 start_color();
 init_pair(1, 6, 0);
 init_pair(2, 2, 4);
 init_params();
 _Bool world[_num_cells];
 init_world(world);
 int ch;
 while((ch = wgetch(stdscr)) != 'q') {
  clock_t start = clock();
  if(ch == 'r')
   init_world(world);
  show_info(world);
  wattr_on(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  draw_world(world);
  wattr_off(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  update_world(world);
  wrefresh(stdscr);
  lock_fps(start, 30);
 }
 wclrtoeol(stdscr);
 endwin();
 return 0;
}

canonical_original_code:
int main()
{
 srand(time(((void *)0)));
 initscr();
 wclear(stdscr);
 noecho();
 cbreak();
 curs_set(0);
 nodelay(stdscr, 1);
 start_color();
 init_pair(1, 6, 0);
 init_pair(2, 2, 4);
 init_params();
 _Bool world[-1];
 init_world(world);
 int ch;
 while((ch = wgetch(stdscr)) != 'q') {
  long start = clock();
  if(ch == 'r')
   init_world(world);
  show_info(world);
  wattr_on(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  draw_world(world);
  wattr_off(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  update_world(world);
  wrefresh(stdscr);
  lock_fps(start, 30);
 }
 wclrtoeol(stdscr);
 endwin();
 return 0;
}

variable_types:
world
_Bool [-1]

variable_types: ch int


repo: GhaisB/Malloc

decompiled_code:
__int64 __fastcall first_link(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = sbrk(a1 + 25);
list = v1;
if ( v1 == (_QWORD *)-1LL )
{
list = 0LL;
result = 0LL;
}
else
{
v1[1] = 0LL;
*v1 = 0LL;
v2 = list;
*(_BYTE *)(list + 24LL) = 0;
*(_QWORD *)(v2 + 16) = a1;
last = v2;
result = v2 + 25;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_QWORD *v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = sbrk(a1 + 25);
list = v1;
if ( v1 == (_QWORD *)-1LL )
{
list = 0LL;
result = 0LL;
}
else
{
v1[1] = 0LL;
*v1 = 0LL;
v2 = list;
*(_BYTE *)(list + 24LL) = 0;
*(_QWORD *)(v2 + 16) = a1;
last = v2;
result = v2 + 25;
}
return result;
}

original_code:
void *first_link(size_t size)
{
  list = sbrk(sizeof(t_malloc) + size);
  if (list == (void*) -1)
    return (list = ((void *)0));
  list->prev = ((void *)0);
  list->next = ((void *)0);
  list->isFree = 0;
  list->size = size;
  last = list;
  return ((void *)list + sizeof(t_malloc));
}

canonical_original_code:
void *first_link(unsigned long size)
{
  list = sbrk(sizeof(t_malloc) + size);
  if (list == (void *) -1)
    return (list = ((void *)0));
  list->prev = ((void *)0);
  list->next = ((void *)0);
  list->isFree = 0;
  list->size = size;
  last = list;
  return ((void *)list + sizeof(t_malloc));
}

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall create_link(unsigned __int64 a1)
{
__int64 v1; // rbx
_QWORD *v3; // rbp
_QWORD *v4; // rax

pthread_mutex_lock(&lock);
v1 = list;
if ( list )
{
v1 = (__int64)research_free_link(a1);
if ( v1 )
{
if ( pthread_mutex_unlock(&lock) )
v1 = 0LL;
}
else
{
v3 = sbrk(a1 + 25);
v4 = (_QWORD *)last;
if ( v3 == (_QWORD *)-1LL )
{
pthread_mutex_unlock(&lock);
}
else
{
v3[2] = a1;
*((_BYTE *)v3 + 24) = 0;
v3[1] = v4;
*v3 = 0LL;
last = v3;
*v4 = v3;
pthread_mutex_unlock(&lock);
v1 = (__int64)v3 + 25;
}
}
}
else if ( !pthread_mutex_unlock(&lock) )
{
v1 = first_link(a1);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1)
{
__int64 v1; // rbx
_QWORD *v3; // rbp
_QWORD *v4; // rax

pthread_mutex_lock(&lock);
v1 = list;
if ( list )
{
v1 = (__int64)research_free_link(a1);
if ( v1 )
{
if ( pthread_mutex_unlock(&lock) )
v1 = 0LL;
}
else
{
v3 = sbrk(a1 + 25);
v4 = (_QWORD *)last;
if ( v3 == (_QWORD *)-1LL )
{
pthread_mutex_unlock(&lock);
}
else
{
v3[2] = a1;
*((_BYTE *)v3 + 24) = 0;
v3[1] = v4;
*v3 = 0LL;
last = v3;
*v4 = v3;
pthread_mutex_unlock(&lock);
v1 = (__int64)v3 + 25;
}
}
}
else if ( !pthread_mutex_unlock(&lock) )
{
v1 = func0(a1);
}
return v1;
}

original_code:
void *create_link(size_t size)
{
  t_malloc *tmp;
  t_malloc *new;
  void *addr;
  pthread_mutex_lock(&lock[0]);
  addr = ((void *)0);
  tmp = list;
  if (!list)
    return ((pthread_mutex_unlock(&lock[0]) != 0) ? ((void *)0) : first_link(size));
  if ((addr = research_free_link(size)) != ((void *)0))
    return ((pthread_mutex_unlock(&lock[0]) != 0) ? ((void *)0) : addr);
  new = sbrk(sizeof(t_malloc) + size);
  tmp = last;
  if (new == (void *) -1)
    return ((pthread_mutex_unlock(&lock[0]) != 0) ? ((void *)0) : ((void *)0));
  new->size = size;
  new->isFree = 0;
  new->prev = tmp;
  new->next = ((void *)0);
  last = new;
  tmp->next = new;
  pthread_mutex_unlock(&lock[0]);
  return ((void *)new + sizeof(t_malloc));
}

canonical_original_code:
void *create_link(unsigned long size)
{
  struct s_malloc *tmp;
  struct s_malloc *new;
  void *addr;
  pthread_mutex_lock(&lock[0]);
  addr = ((void *)0);
  tmp = list;
  if (!list)
    return ((pthread_mutex_unlock(&lock[0]) != 0) ? ((void *)0) : first_link(size));
  if ((addr = research_free_link(size)) != ((void *)0))
    return ((pthread_mutex_unlock(&lock[0]) != 0) ? ((void *)0) : addr);
  new = sbrk(sizeof(t_malloc) + size);
  tmp = last;
  if (new == (void *) -1)
    return ((pthread_mutex_unlock(&lock[0]) != 0) ? ((void *)0) : ((void *)0));
  new->size = size;
  new->isFree = 0;
  new->prev = tmp;
  new->next = ((void *)0);
  last = new;
  tmp->next = new;
  pthread_mutex_unlock(&lock[0]);
  return ((void *)new + sizeof(t_malloc));
}

variable_types: struct s_malloc { struct s_malloc *next; struct s_malloc *prev; unsigned long size; char isFree; } *

variable_types:
addr
void *


malloc

decompiled_code:
__int64 __fastcall malloc(unsigned __int64 a1)
{
return create_link(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
return func1(a1);
}

original_code:
void *malloc(size_t size)
{
  return (create_link(size));
}

canonical_original_code:
void *malloc(unsigned long size)
{
  return (create_link(size));
}


free

decompiled_code:
int __fastcall free(_QWORD *a1)
{
_QWORD *v2; // rax
_QWORD *v3; // rdi

pthread_mutex_lock(&lock);
v2 = (_QWORD *)list;
if ( !a1 || !list )
return pthread_mutex_unlock(&lock);
while ( 1 )
{
v3 = v2;
v2 = (_QWORD *)*v2;
if ( !v2 )
break;
if ( a1 == (_QWORD *)((char *)v3 + 25) )
goto LABEL_5;
}
if ( a1 == (_QWORD *)((char *)v3 + 25) )
{
LABEL_5:
*((_BYTE *)v3 + 24) = 1;
size_link = v3[2];
fusion_link((__int64 ***)v3);
return pthread_mutex_unlock(&lock);
}
size_link = 0LL;
return pthread_mutex_unlock(&lock);
}

canonical_decompiled_code:
int __fastcall func0(_QWORD *a1)
{
_QWORD *v2; // rax
_QWORD *v3; // rdi

pthread_mutex_lock(&lock);
v2 = (_QWORD *)list;
if ( !a1 || !list )
return pthread_mutex_unlock(&lock);
while ( 1 )
{
v3 = v2;
v2 = (_QWORD *)*v2;
if ( !v2 )
break;
if ( a1 == (_QWORD *)((char *)v3 + 25) )
goto LABEL_5;
}
if ( a1 == (_QWORD *)((char *)v3 + 25) )
{
LABEL_5:
*((_BYTE *)v3 + 24) = 1;
size_link = v3[2];
fusion_link((__int64 ***)v3);
return pthread_mutex_unlock(&lock);
}
size_link = 0LL;
return pthread_mutex_unlock(&lock);
}

original_code:
void free(void *ptr)
{
  t_malloc *tmp;
  int a = 0;
  pthread_mutex_lock(&lock[0]);
  tmp = list;
  if (ptr == ((void *)0) || !tmp)
    {
      pthread_mutex_unlock(&lock[0]);
      return ;
    }
  while (tmp && tmp->next && (void *)tmp + sizeof(t_malloc) != ptr)
    tmp = tmp->next;
  if ((void *)tmp + sizeof(t_malloc) != ptr)
    {
      size_link = 0;
      pthread_mutex_unlock(&lock[0]);
      return ;
    }
  tmp->isFree = 1;
  size_link = tmp->size;
  fusion_link(tmp);
  pthread_mutex_unlock(&lock[0]);
  return ;
}

canonical_original_code:
void free(void *ptr)
{
  struct s_malloc *tmp;
  int a = 0;
  pthread_mutex_lock(&lock[0]);
  tmp = list;
  if (ptr == ((void *)0) || !tmp)
    {
      pthread_mutex_unlock(&lock[0]);
      return ;
    }
  while (tmp && tmp->next && (void *)tmp + sizeof(t_malloc) != ptr)
    tmp = tmp->next;
  if ((void *)tmp + sizeof(t_malloc) != ptr)
    {
      size_link = 0;
      pthread_mutex_unlock(&lock[0]);
      return ;
    }
  tmp->isFree = 1;
  size_link = tmp->size;
  fusion_link(tmp);
  pthread_mutex_unlock(&lock[0]);
  return ;
}

variable_types:
ptr
void *

variable_types: a int

user_defined_types: struct s_malloc { struct s_malloc *next; struct s_malloc *prev; unsigned long size; char isFree; }


decompiled_code:
int show_alloc_mem()
{
_QWORD *v0; // rbx
void *v1; // rax
int result; // eax

v0 = (_QWORD *)list;
v1 = sbrk(0LL);
for ( result = printf("break : %p\n", v1); v0; v0 = (_QWORD *)*v0 )
result = printf("%p - %p : %ld octets \n", (char *)v0 + 25, (char *)v0 + v0[2] + 25, v0[2]);
return result;
}

canonical_decompiled_code:
int func1()
{
_QWORD *v0; // rbx
void *v1; // rax
int result; // eax

v0 = (_QWORD *)list;
v1 = sbrk(0LL);
for ( result = printf("break : %p\n", v1); v0; v0 = (_QWORD *)*v0 )
result = printf("%p - %p : %ld octets \n", (char *)v0 + 25, (char *)v0 + v0[2] + 25, v0[2]);
return result;
}

original_code:
void show_alloc_mem()
{
  t_malloc *tmp;
  tmp = list;
  printf("break : %p\n", sbrk(0));
  while (tmp)
    {
      printf("%p - %p : %ld octets \n", (void *)tmp + sizeof(t_malloc), (void *)tmp + sizeof(t_malloc) + tmp->size, tmp->size);
      tmp = tmp->next;
    }
}

canonical_original_code:
void show_alloc_mem()
{
  struct s_malloc *tmp;
  tmp = list;
  printf("break : %p\n", sbrk(0));
  while (tmp)
    {
      printf("%p - %p : %ld octets \n", (void *)tmp + sizeof(t_malloc), (void *)tmp + sizeof(t_malloc) + tmp->size, tmp->size);
      tmp = tmp->next;
    }
}