decompiled_code:
void __fastcall quicksort_recursive(char *a1, char *a2)
{
char *v2; // rbx
char *v3; // rbx
char *v4; // rbp

if ( a1 >= a2 )
return;
v2 = &a1[(a2 - a1) / 2];
if ( (int)((__int64 (*)(void))compare_fn)() <= 0 )
{
if ( (int)compare_fn(v2, a1) > 0 )
{
if ( (int)compare_fn(v2, a2) > 0 )
goto LABEL_5;
LABEL_19:
memcpy(x, v2, element_size);
memcpy(v2, a1, element_size);
goto LABEL_6;
}
LABEL_18:
memcpy(x, a1, element_size);
goto LABEL_6;
}
if ( (int)compare_fn(a1, v2) <= 0 )
goto LABEL_18;
if ( (int)compare_fn(a2, v2) <= 0 )
goto LABEL_19;
LABEL_5:
memcpy(x, a2, element_size);
memcpy(a2, a1, element_size);
LABEL_6:
v3 = &a2[element_size];
if ( a1 >= v3 )
{
v4 = a1;
}
else
{
v4 = a1;
LABEL_8:
while ( 1 )
{
v3 -= element_size;
if ( v3 == v4 )
break;
if ( (int)compare_fn(v3, x) <= 0 )
{
memcpy(v4, v3, element_size);
while ( 1 )
{
v4 += element_size;
if ( v3 == v4 )
goto LABEL_23;
if ( (int)compare_fn(v4, x) >= 0 )
{
memcpy(v3, v4, element_size);
if ( v3 > v4 )
goto LABEL_8;
goto LABEL_23;
}
}
}
}
}
LABEL_23:
memcpy(v4, x, element_size);
quicksort_recursive(a1, &v4[-element_size]);
quicksort_recursive(&v4[element_size], a2);
}

canonical_decompiled_code:
void __fastcall func0(char *a1, char *a2)
{
char *v2; // rbx
char *v3; // rbx
char *v4; // rbp

if ( a1 >= a2 )
return;
v2 = &a1[(a2 - a1) / 2];
if ( (int)((__int64 (*)(void))compare_fn)() <= 0 )
{
if ( (int)compare_fn(v2, a1) > 0 )
{
if ( (int)compare_fn(v2, a2) > 0 )
goto LABEL_5;
LABEL_19:
memcpy(x, v2, element_size);
memcpy(v2, a1, element_size);
goto LABEL_6;
}
LABEL_18:
memcpy(x, a1, element_size);
goto LABEL_6;
}
if ( (int)compare_fn(a1, v2) <= 0 )
goto LABEL_18;
if ( (int)compare_fn(a2, v2) <= 0 )
goto LABEL_19;
LABEL_5:
memcpy(x, a2, element_size);
memcpy(a2, a1, element_size);
LABEL_6:
v3 = &a2[element_size];
if ( a1 >= v3 )
{
v4 = a1;
}
else
{
v4 = a1;
LABEL_8:
while ( 1 )
{
v3 -= element_size;
if ( v3 == v4 )
break;
if ( (int)compare_fn(v3, x) <= 0 )
{
memcpy(v4, v3, element_size);
while ( 1 )
{
v4 += element_size;
if ( v3 == v4 )
goto LABEL_23;
if ( (int)compare_fn(v4, x) >= 0 )
{
memcpy(v3, v4, element_size);
if ( v3 > v4 )
goto LABEL_8;
goto LABEL_23;
}
}
}
}
}
LABEL_23:
memcpy(v4, x, element_size);
func0(a1, &v4[-element_size]);
func0(&v4[element_size], a2);
}

original_code:
void quicksort_recursive(void *p, void *q)
{
    void *i, *j;
    void *m;
    if(p < q) {
 m = p + (q - p) / 2;
        if(compare_fn(p, q) <= 0) {
            if(compare_fn(m, p) <= 0) {
                memcpy(x, p, element_size);
     }
     else {
  if(compare_fn(m, q) <= 0) {
                    memcpy(x, m, element_size);
                    memcpy(m, p, element_size);
  }
  else {
                    memcpy(x, q, element_size);
                    memcpy(q, p, element_size);
  }
     }
 }
 else {
            if(compare_fn(p, m) <= 0) {
                memcpy(x, p, element_size);
     }
     else {
  if(compare_fn(q, m) <= 0) {
                    memcpy(x, m, element_size);
                    memcpy(m, p, element_size);
  }
  else {
                    memcpy(x, q, element_size);
                    memcpy(q, p, element_size);
  }
     }
 }
 i = p;
 j = q + element_size;
 while(i < j) {
     do {
  j -= element_size;
  if(i == j) goto partition_end;
     } while(compare_fn(j, x) > 0);
     memcpy(i, j, element_size);
     do {
  i += element_size;
  if(i == j) goto partition_end;
     } while(compare_fn(i, x) < 0);
     memcpy(j, i, element_size);
 }
      partition_end:
 memcpy(i, x, element_size);
 quicksort_recursive(p, i - element_size);
 quicksort_recursive(i + element_size, q);
    }
}

canonical_original_code:
void quicksort_recursive(void *p, void *q)
{
    void *i; void *j;
    void *m;
    if(p < q) {
 m = p + (q - p) / 2;
        if(compare_fn(p, q) <= 0) {
            if(compare_fn(m, p) <= 0) {
                memcpy(x, p, element_size);
     }
     else {
  if(compare_fn(m, q) <= 0) {
                    memcpy(x, m, element_size);
                    memcpy(m, p, element_size);
  }
  else {
                    memcpy(x, q, element_size);
                    memcpy(q, p, element_size);
  }
     }
 }
 else {
            if(compare_fn(p, m) <= 0) {
                memcpy(x, p, element_size);
     }
     else {
  if(compare_fn(q, m) <= 0) {
                    memcpy(x, m, element_size);
                    memcpy(m, p, element_size);
  }
  else {
                    memcpy(x, q, element_size);
                    memcpy(q, p, element_size);
  }
     }
 }
 i = p;
 j = q + element_size;
 while(i < j) {
     do {
  j -= element_size;
  if(i == j) goto partition_end;
     } while(compare_fn(j, x) > 0);
     memcpy(i, j, element_size);
     do {
  i += element_size;
  if(i == j) goto partition_end;
     } while(compare_fn(i, x) < 0);
     memcpy(j, i, element_size);
 }
      partition_end:
 memcpy(i, x, element_size);
 quicksort_recursive(p, i - element_size);
 quicksort_recursive(i + element_size, q);
    }
}

variable_types:
p
void *

variable_types:
q
void *

variable_types:
i
void *

variable_types:
j
void *

variable_types:
m
void *


quicksort

repo: nickleefly/experiment

decompiled_code:
void __fastcall quicksort(char *a1, __int64 a2, size_t a3, __int64 (__fastcall *a4)(_QWORD, _QWORD))
{
element_size = a3;
compare_fn = a4;
x = malloc(a3);
quicksort_recursive(a1, &a1[a3 * (a2 - 1)]);
free(x);
}

canonical_decompiled_code:
void __fastcall func1(char *a1, __int64 a2, size_t a3, __int64 (__fastcall *a4)(_QWORD, _QWORD))
{
element_size = a3;
compare_fn = a4;
x = malloc(a3);
func0(a1, &a1[a3 * (a2 - 1)]);
free(x);
}

original_code:
void quicksort(void *base, size_t nmemb, size_t size,
        int (* compar)(const void *, const void *))
{
    element_size = size;
    compare_fn = compar;
    x = malloc(size);
    quicksort_recursive(base, base + size * (nmemb - 1));
    free(x);
}

canonical_original_code:
void quicksort(void *base, unsigned long nmemb, unsigned long size, int (*compar)(void *, void *))
{
    element_size = size;
    compare_fn = compar;
    x = malloc(size);
    quicksort_recursive(base, base + size * (nmemb - 1));
    free(x);
}

variable_types:
base
void *

variable_types:
nmemb
unsigned long

variable_types:
size
unsigned long

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

return_type: void


decompiled_code:
void __fastcall mergesort0_recursive(void *dest, unsigned __int64 a2)
{
char *v2; // r14
char *v3; // r14
char *v4; // r13
char *v5; // rbx
char *v6; // rbp

if ( (unsigned __int64)dest < a2 )
{
v2 = (char *)dest + element_size * ((__int64)(a2 - (_QWORD)dest) / (2 * element_size));
mergesort0_recursive(dest);
v3 = &v2[element_size];
mergesort0_recursive(v3);
v4 = (char *)temp_merge_array;
if ( dest >= v3 || a2 < (unsigned __int64)v3 )
{
v5 = v3;
v6 = (char *)dest;
}
else
{
v5 = v3;
v6 = (char *)dest;
do
{
if ( (int)compare_fn(v6, v5) <= 0 )
{
memcpy(v4, v6, element_size);
v6 += element_size;
}
else
{
memcpy(v4, v5, element_size);
v5 += element_size;
}
v4 += element_size;
}
while ( v6 < v3 && (unsigned __int64)v5 <= a2 );
}
memcpy(v4, v6, v3 - v6);
memcpy(v4, v5, a2 - (_QWORD)v5 + element_size);
memcpy(dest, temp_merge_array, a2 - (_QWORD)dest + element_size);
}
}

canonical_decompiled_code:
void __fastcall func2(void *dest, unsigned __int64 a2)
{
char *v2; // r14
char *v3; // r14
char *v4; // r13
char *v5; // rbx
char *v6; // rbp

if ( (unsigned __int64)dest < a2 )
{
v2 = (char *)dest + element_size * ((__int64)(a2 - (_QWORD)dest) / (2 * element_size));
func2(dest);
v3 = &v2[element_size];
func2(v3);
v4 = (char *)temp_merge_array;
if ( dest >= v3 || a2 < (unsigned __int64)v3 )
{
v5 = v3;
v6 = (char *)dest;
}
else
{
v5 = v3;
v6 = (char *)dest;
do
{
if ( (int)compare_fn(v6, v5) <= 0 )
{
memcpy(v4, v6, element_size);
v6 += element_size;
}
else
{
memcpy(v4, v5, element_size);
v5 += element_size;
}
v4 += element_size;
}
while ( v6 < v3 && (unsigned __int64)v5 <= a2 );
}
memcpy(v4, v6, v3 - v6);
memcpy(v4, v5, a2 - (_QWORD)v5 + element_size);
memcpy(dest, temp_merge_array, a2 - (_QWORD)dest + element_size);
}
}

original_code:
void mergesort0_recursive(void *p, void *q)
{
    void *i, *j, *k, *m;
    if(p < q) {
        m = p + element_size * ((q - p) / (2 * element_size));
 mergesort0_recursive(p, m);
 m += element_size;
 mergesort0_recursive(m, q);
 i = p;
 j = m;
 k = temp_merge_array;
        while(i < m && j <= q) {
     if(compare_fn(i, j) <= 0) {
                memcpy(k, i, element_size);
  i += element_size;
     }
     else {
                memcpy(k, j, element_size);
  j += element_size;
     }
            k += element_size;
 }
 memcpy(k, i, m - i);
        memcpy(k, j, (q - j) + element_size);
 memcpy(p, temp_merge_array, (q - p) + element_size);
    }
}

canonical_original_code:
void mergesort0_recursive(void *p, void *q)
{
    void *i; void *j; void *k; void *m;
    if(p < q) {
        m = p + element_size * ((q - p) / (2 * element_size));
 mergesort0_recursive(p, m);
 m += element_size;
 mergesort0_recursive(m, q);
 i = p;
 j = m;
 k = temp_merge_array;
        while(i < m && j <= q) {
     if(compare_fn(i, j) <= 0) {
                memcpy(k, i, element_size);
  i += element_size;
     }
     else {
                memcpy(k, j, element_size);
  j += element_size;
     }
            k += element_size;
 }
 memcpy(k, i, m - i);
        memcpy(k, j, (q - j) + element_size);
 memcpy(p, temp_merge_array, (q - p) + element_size);
    }
}

variable_types:
k
void *


decompiled_code:
void __fastcall mergesort0(void *dest, __int64 a2, __int64 a3, __int64 (__fastcall *a4)(_QWORD, _QWORD))
{
element_size = a3;
compare_fn = a4;
temp_merge_array = malloc(a2 * a3);
mergesort0_recursive(dest, (unsigned __int64)dest + a3 * (a2 - 1));
free(temp_merge_array);
}

canonical_decompiled_code:
void __fastcall func3(void *dest, __int64 a2, __int64 a3, __int64 (__fastcall *a4)(_QWORD, _QWORD))
{
element_size = a3;
compare_fn = a4;
temp_merge_array = malloc(a2 * a3);
func2(dest, (unsigned __int64)dest + a3 * (a2 - 1));
free(temp_merge_array);
}

original_code:
void mergesort0(void *base, size_t nmemb, size_t size,
        int (* compar)(const void *, const void *))
{
    element_size = size;
    compare_fn = compar;
    temp_merge_array = malloc(nmemb * size);
    mergesort0_recursive(base, base + size * (nmemb - 1));
    free(temp_merge_array);
}

canonical_original_code:
void mergesort0(void *base, unsigned long nmemb, unsigned long size, int (*compar)(void *, void *))
{
    element_size = size;
    compare_fn = compar;
    temp_merge_array = malloc(nmemb * size);
    mergesort0_recursive(base, base + size * (nmemb - 1));
    free(temp_merge_array);
}


decompiled_code:
void __fastcall mergesort_recursive(void *src, unsigned __int64 a2, char *a3)
{
char *v3; // rbx
char *v4; // rbp
__int64 v5; // r14
char *v6; // r15
char *v7; // r14
char *v8; // r12

if ( (unsigned __int64)src < a2 )
{
v3 = (char *)src;
v4 = a3;
v5 = element_size * ((__int64)(a2 - (_QWORD)src) / (2 * element_size));
v6 = &a3[v5];
mergesort_recursive(a3);
v7 = (char *)src + element_size + v5;
mergesort_recursive(&v6[element_size]);
if ( src >= v7 || a2 < (unsigned __int64)v7 )
{
v8 = v7;
}
else
{
v8 = v7;
do
{
if ( (int)compare_fn(v3, v8) <= 0 )
{
memcpy(v4, v3, element_size);
v3 += element_size;
}
else
{
memcpy(v4, v8, element_size);
v8 += element_size;
}
v4 += element_size;
}
while ( v3 < v7 && (unsigned __int64)v8 <= a2 );
}
memcpy(v4, v3, v7 - v3);
memcpy(v4, v8, a2 - (_QWORD)v8 + element_size);
}
}

canonical_decompiled_code:
void __fastcall func4(void *src, unsigned __int64 a2, char *a3)
{
char *v3; // rbx
char *v4; // rbp
__int64 v5; // r14
char *v6; // r15
char *v7; // r14
char *v8; // r12

if ( (unsigned __int64)src < a2 )
{
v3 = (char *)src;
v4 = a3;
v5 = element_size * ((__int64)(a2 - (_QWORD)src) / (2 * element_size));
v6 = &a3[v5];
func4(a3);
v7 = (char *)src + element_size + v5;
func4(&v6[element_size]);
if ( src >= v7 || a2 < (unsigned __int64)v7 )
{
v8 = v7;
}
else
{
v8 = v7;
do
{
if ( (int)compare_fn(v3, v8) <= 0 )
{
memcpy(v4, v3, element_size);
v3 += element_size;
}
else
{
memcpy(v4, v8, element_size);
v8 += element_size;
}
v4 += element_size;
}
while ( v3 < v7 && (unsigned __int64)v8 <= a2 );
}
memcpy(v4, v3, v7 - v3);
memcpy(v4, v8, a2 - (_QWORD)v8 + element_size);
}
}

original_code:
void mergesort_recursive(void *p, void *q, void *dest)
{
    void *i, *j, *k, *m, *dest_m;
    if(p < q) {
        m = p + element_size * ((q - p) / (2 * element_size));
 dest_m = dest + (m - p);
 mergesort_recursive(dest, dest_m, p);
 m += element_size;
 dest_m += element_size;
 mergesort_recursive(dest_m, dest + (q - p), m);
 i = p;
 j = m;
 k = dest;
        while(i < m && j <= q) {
     if(compare_fn(i, j) <= 0) {
                memcpy(k, i, element_size);
  i += element_size;
     }
     else {
                memcpy(k, j, element_size);
  j += element_size;
     }
            k += element_size;
 }
 memcpy(k, i, m - i);
        memcpy(k, j, (q - j) + element_size);
    }
}

canonical_original_code:
void mergesort_recursive(void *p, void *q, void *dest)
{
    void *i; void *j; void *k; void *m; void *dest_m;
    if(p < q) {
        m = p + element_size * ((q - p) / (2 * element_size));
 dest_m = dest + (m - p);
 mergesort_recursive(dest, dest_m, p);
 m += element_size;
 dest_m += element_size;
 mergesort_recursive(dest_m, dest + (q - p), m);
 i = p;
 j = m;
 k = dest;
        while(i < m && j <= q) {
     if(compare_fn(i, j) <= 0) {
                memcpy(k, i, element_size);
  i += element_size;
     }
     else {
                memcpy(k, j, element_size);
  j += element_size;
     }
            k += element_size;
 }
 memcpy(k, i, m - i);
        memcpy(k, j, (q - j) + element_size);
    }
}

variable_types:
dest
void *


mergesort

decompiled_code:
void __fastcall mergesort(void *src, __int64 a2, __int64 a3, __int64 (__fastcall *a4)(_QWORD, _QWORD))
{
size_t v5; // r14
void *v6; // rbp

element_size = a3;
compare_fn = a4;
v5 = a2 * a3;
v6 = malloc(a2 * a3);
memcpy(v6, src, v5);
mergesort_recursive(v6, (unsigned __int64)v6 + a3 * (a2 - 1), (char *)src);
free(v6);
}

canonical_decompiled_code:
void __fastcall func5(void *src, __int64 a2, __int64 a3, __int64 (__fastcall *a4)(_QWORD, _QWORD))
{
size_t v5; // r14
void *v6; // rbp

element_size = a3;
compare_fn = a4;
v5 = a2 * a3;
v6 = malloc(a2 * a3);
memcpy(v6, src, v5);
func4(v6, (unsigned __int64)v6 + a3 * (a2 - 1), (char *)src);
free(v6);
}

original_code:
void mergesort(void *base, size_t nmemb, size_t size,
        int (* compar)(const void *, const void *))
{
    void *swap_array;
    element_size = size;
    compare_fn = compar;
    swap_array = malloc(nmemb * size);
    memcpy(swap_array, base, nmemb * size);
    mergesort_recursive(swap_array, swap_array + size * (nmemb - 1), base);
    free(swap_array);
}

canonical_original_code:
void mergesort(void *base, unsigned long nmemb, unsigned long size, int (*compar)(void *, void *))
{
    void *swap_array;
    element_size = size;
    compare_fn = compar;
    swap_array = malloc(nmemb * size);
    memcpy(swap_array, base, nmemb * size);
    mergesort_recursive(swap_array, swap_array + size * (nmemb - 1), base);
    free(swap_array);
}


radixsort

original_code:
void radixsort(void *base, size_t nmemb, size_t size,
        int (* getvalue)(const void *), int radix)
{
    radix_item_t **bucket_heads, **bucket_tails;
    radix_item_t *bucket_items, *first_item, *item_ptr, *next_item;
    int i, prev_i, x, max_value;
    void *element_ptr;
    void *result;
    bucket_heads = malloc(radix * sizeof(radix_item_t *));
    bucket_tails = malloc(radix * sizeof(radix_item_t *));
    item_ptr = bucket_items = malloc(nmemb * sizeof(radix_item_t));
    item_ptr->ptr = element_ptr = base;
    item_ptr->value = max_value = getvalue(element_ptr);
    for(i = 1; i < nmemb; i++) {
 next_item = item_ptr + 1;
        item_ptr = item_ptr->next = next_item;
        element_ptr += element_size;
 item_ptr->ptr = element_ptr;
 x = getvalue(element_ptr);
 item_ptr->value = x;
 if(x > max_value) max_value = x;
    }
    item_ptr->next = ((void *)0);
    first_item = bucket_items;
    do {
 for(i = 0; i < radix; i++) bucket_tails[i] = bucket_heads[i] = ((void *)0);
 item_ptr = first_item;
 do {
     i = item_ptr->value % radix;
     item_ptr->value /= radix;
     if(bucket_heads[i]) {
  bucket_tails[i] = bucket_tails[i]->next = item_ptr;
     }
     else {
  bucket_tails[i] = bucket_heads[i] = item_ptr;
     }
     item_ptr = item_ptr->next;
 } while(item_ptr);
 i = 0;
 item_ptr = bucket_heads[0];
 while(!item_ptr) item_ptr = bucket_heads[++i];
 first_item = item_ptr;
 do {
     prev_i = i;
     do {
  i++;
  if(i == radix) goto list_complete;
  item_ptr = bucket_heads[i];
     } while(!item_ptr);
     bucket_tails[prev_i]->next = bucket_heads[i];
 } while(1);
      list_complete:
 bucket_tails[prev_i]->next = ((void *)0);
 max_value /= radix;
    } while(max_value);
    free(bucket_heads);
    free(bucket_tails);
    item_ptr = first_item;
    element_ptr = result = malloc(nmemb * size);
    for(i = 0; i < nmemb; i++) {
 memcpy(element_ptr, item_ptr->ptr, element_size);
 element_ptr += element_size;
 item_ptr = item_ptr->next;
    }
    memcpy(base, result, nmemb * size);
    free(bucket_items);
    free(result);
}

canonical_original_code:
void radixsort(void *base, unsigned long nmemb, unsigned long size, int (*getvalue)(void *), int radix)
{
    struct radix_item **bucket_heads; struct radix_item **bucket_tails;
    struct radix_item *bucket_items; struct radix_item *first_item; struct radix_item *item_ptr; struct radix_item *next_item;
    int i; int prev_i; int x; int max_value;
    void *element_ptr;
    void *result;
    bucket_heads = malloc(radix * sizeof(struct radix_item *));
    bucket_tails = malloc(radix * sizeof(struct radix_item *));
    item_ptr = bucket_items = malloc(nmemb * sizeof(radix_item_t));
    item_ptr->ptr = element_ptr = base;
    item_ptr->value = max_value = getvalue(element_ptr);
    for(i = 1; i < nmemb; i++) {
 next_item = item_ptr + 1;
        item_ptr = item_ptr->next = next_item;
        element_ptr += element_size;
 item_ptr->ptr = element_ptr;
 x = getvalue(element_ptr);
 item_ptr->value = x;
 if(x > max_value) max_value = x;
    }
    item_ptr->next = ((void *)0);
    first_item = bucket_items;
    do {
 for(i = 0; i < radix; i++) bucket_tails[i] = bucket_heads[i] = ((void *)0);
 item_ptr = first_item;
 do {
     i = item_ptr->value % radix;
     item_ptr->value /= radix;
     if(bucket_heads[i]) {
  bucket_tails[i] = bucket_tails[i]->next = item_ptr;
     }
     else {
  bucket_tails[i] = bucket_heads[i] = item_ptr;
     }
     item_ptr = item_ptr->next;
 } while(item_ptr);
 i = 0;
 item_ptr = bucket_heads[0];
 while(!item_ptr) item_ptr = bucket_heads[++i];
 first_item = item_ptr;
 do {
     prev_i = i;
     do {
  i++;
  if(i == radix) goto list_complete;
  item_ptr = bucket_heads[i];
     } while(!item_ptr);
     bucket_tails[prev_i]->next = bucket_heads[i];
 } while(1);
      list_complete:
 bucket_tails[prev_i]->next = ((void *)0);
 max_value /= radix;
    } while(max_value);
    free(bucket_heads);
    free(bucket_tails);
    item_ptr = first_item;
    element_ptr = result = malloc(nmemb * size);
    for(i = 0; i < nmemb; i++) {
 memcpy(element_ptr, item_ptr->ptr, element_size);
 element_ptr += element_size;
 item_ptr = item_ptr->next;
    }
    memcpy(base, result, nmemb * size);
    free(bucket_items);
    free(result);
}

variable_types:
getvalue
int (*)(void *)

variable_types: radix int

variable_types: struct radix_item { int value; void *ptr; struct radix_item *next; } **

variable_types: i int

variable_types: x int

variable_types:
result
void *


heapsort

original_code:
void heapsort(void *base, size_t nmemb, size_t size,
        int (* compar)(const void *, const void *))
{
    int i, j, k, other_k, last_entry;
    void *y, *i_ptr;
    y = malloc(size);
    last_entry = (nmemb - 1) * size;
    for(i = ((nmemb - 2)/ 2) * size; i >= 0; i-= size) {
 i_ptr = base + i;
 memcpy(y, i_ptr, size);
 j = i;
 k = (i << 1) + size;
 while(k <= last_entry) {
     if(k < last_entry) {
  other_k = k + size;
  if(compar(base + k, base + other_k) < 0) k = other_k;
     }
     if(compar(y, base + k) >= 0) break;
            memcpy(base + j, base + k, size);
     j = k;
     k = (j << 1) + size;
 }
 memcpy(base + j, y, size);
    }
    i = last_entry;
    while(i > 0) {
        memcpy(y, base + i, size);
        memcpy(base + i, base, size);
 i -= size;
 j = 0;
 k = size;
 while(k <= i) {
     if(k < i) {
  other_k = k + size;
  if(compar(base + k, base + other_k) < 0) k = other_k;
     }
     memcpy(base + j, base + k, size);
     j = k;
     k = (j << 1) + size;
 }
 while(j > 0) {
     k = (((j / size) - 1) >> 1) * size;
     if(compar(y, base + k) <= 0) break;
     memcpy(base + j, base + k, size);
     j = k;
 }
        memcpy(base + j, y, size);
    }
    free(y);
}

canonical_original_code:
void heapsort(void *base, unsigned long nmemb, unsigned long size, int (*compar)(void *, void *))
{
    int i; int j; int k; int other_k; int last_entry;
    void *y; void *i_ptr;
    y = malloc(size);
    last_entry = (nmemb - 1) * size;
    for(i = ((nmemb - 2)/ 2) * size; i >= 0; i-= size) {
 i_ptr = base + i;
 memcpy(y, i_ptr, size);
 j = i;
 k = (i << 1) + size;
 while(k <= last_entry) {
     if(k < last_entry) {
  other_k = k + size;
  if(compar(base + k, base + other_k) < 0) k = other_k;
     }
     if(compar(y, base + k) >= 0) break;
            memcpy(base + j, base + k, size);
     j = k;
     k = (j << 1) + size;
 }
 memcpy(base + j, y, size);
    }
    i = last_entry;
    while(i > 0) {
        memcpy(y, base + i, size);
        memcpy(base + i, base, size);
 i -= size;
 j = 0;
 k = size;
 while(k <= i) {
     if(k < i) {
  other_k = k + size;
  if(compar(base + k, base + other_k) < 0) k = other_k;
     }
     memcpy(base + j, base + k, size);
     j = k;
     k = (j << 1) + size;
 }
 while(j > 0) {
     k = (((j / size) - 1) >> 1) * size;
     if(compar(y, base + k) <= 0) break;
     memcpy(base + j, base + k, size);
     j = k;
 }
        memcpy(base + j, y, size);
    }
    free(y);
}

variable_types: j int

variable_types: k int

variable_types:
y
void *


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

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

original_code:
int compare_fn(const void *item1, const void *item2)
{
    return ((test_item_t *)item1)->key - ((test_item_t *)item2)->key;
}

canonical_original_code:
int compare_fn(void *item1, void *item2)
{
    return ((struct test_item *)item1)->key - ((struct test_item *)item2)->key;
}

return_type: int

user_defined_types: struct test_item { int key; int other_data; }


decompiled_code:
__int64 __fastcall hash_fn(unsigned int *a1, int a2)
{
srand(*a1);
rand();
return (unsigned int)(rand() % a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1, int a2)
{
srand(*a1);
rand();
return (unsigned int)(rand() % a2);
}

original_code:
int hash_fn(const void *item, int n)
{
    srand(((test_item_t *)item)->key);
    rand();
    return rand() % n;
}

canonical_original_code:
int hash_fn(void *item, int n)
{
    srand(((struct test_item *)item)->key);
    rand();
    return rand() % n;
}

variable_types:
item
void *

variable_types: n int


decompiled_code:
void __fastcall hash_tbl_free(void *ptr)
{
void *v2; // r14
_QWORD *v3; // rbp
__int64 v4; // r12
_QWORD *v5; // rbx
void *v6; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( *(int *)ptr > 0 )
{
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
v4 = (__int64)v2 + 8 * (unsigned int)(*(_DWORD *)ptr - 1) + 8;
do
{
v5 = (_QWORD *)*v3;
if ( *v3 )
{
do
{
v6 = v5;
v5 = (_QWORD *)v5[1];
free(v6);
}
while ( v5 );
}
++v3;
}
while ( v3 != (_QWORD *)v4 );
}
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
void *v2; // r14
_QWORD *v3; // rbp
__int64 v4; // r12
_QWORD *v5; // rbx
void *v6; // rdi

v2 = (void *)*((_QWORD *)ptr + 1);
if ( *(int *)ptr > 0 )
{
v3 = (_QWORD *)*((_QWORD *)ptr + 1);
v4 = (__int64)v2 + 8 * (unsigned int)(*(_DWORD *)ptr - 1) + 8;
do
{
v5 = (_QWORD *)*v3;
if ( *v3 )
{
do
{
v6 = v5;
v5 = (_QWORD *)v5[1];
free(v6);
}
while ( v5 );
}
++v3;
}
while ( v3 != (_QWORD *)v4 );
}
free(v2);
free(ptr);
}

original_code:
void hash_tbl_free(hash_tbl_t *tbl)
{
    int i, n;
    hash_tbl_item_t **buckets, *item_ptr, *free_item;
    n = tbl->n_buckets;
    buckets = tbl->buckets;
    for(i = 0; i < n; i++) {
        if((item_ptr = buckets[i])) {
            while(item_ptr) {
  free_item = item_ptr;
  item_ptr = item_ptr->next;
                free(free_item);
     }
 }
    }
    free(buckets);
    free(tbl);
}

canonical_original_code:
void hash_tbl_free(struct hash_tbl *tbl)
{
    int i; int n;
    struct hash_tbl_item **buckets; struct hash_tbl_item *item_ptr; struct hash_tbl_item *free_item;
    n = tbl->n_buckets;
    buckets = tbl->buckets;
    for(i = 0; i < n; i++) {
        if((item_ptr = buckets[i])) {
            while(item_ptr) {
  free_item = item_ptr;
  item_ptr = item_ptr->next;
                free(free_item);
     }
 }
    }
    free(buckets);
    free(tbl);
}

variable_types: struct hash_tbl { int n_buckets; struct hash_tbl_item { void *item; struct hash_tbl_item *next; } **buckets; int (*hash_fn)(void *item, int n); int (*compare_fn)(void *item1, void *item2); } *

user_defined_types: struct hash_tbl { int n_buckets; struct hash_tbl_item **buckets; int (*hash_fn)(void *item, int n); int (*compare_fn)(void *item1, void *item2); }


decompiled_code:
__int64 __fastcall hash_tbl_insert(unsigned int *a1, __int64 a2)
{
__int64 v2; // rbx
_QWORD *v3; // r13
_QWORD *v4; // rbx
_QWORD *v5; // rax
__int64 result; // rax

v2 = *((_QWORD *)a1 + 1);
v3 = (_QWORD *)(v2 + 8LL * (*((int (__fastcall **)(__int64, _QWORD))a1 + 2))(a2, *a1));
v4 = (_QWORD *)*v3;
if ( *v3 )
{
while ( (*((unsigned int (__fastcall **)(_QWORD, __int64))a1 + 3))(*v4, a2) )
{
if ( !v4[1] )
{
v3 = v4 + 1;
goto LABEL_7;
}
v4 = (_QWORD *)v4[1];
}
result = *v4;
}
else
{
LABEL_7:
v5 = malloc(0x10uLL);
*v5 = a2;
v5[1] = 0LL;
*v3 = v5;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1, __int64 a2)
{
__int64 v2; // rbx
_QWORD *v3; // r13
_QWORD *v4; // rbx
_QWORD *v5; // rax
__int64 result; // rax

v2 = *((_QWORD *)a1 + 1);
v3 = (_QWORD *)(v2 + 8LL * (*((int (__fastcall **)(__int64, _QWORD))a1 + 2))(a2, *a1));
v4 = (_QWORD *)*v3;
if ( *v3 )
{
while ( (*((unsigned int (__fastcall **)(_QWORD, __int64))a1 + 3))(*v4, a2) )
{
if ( !v4[1] )
{
v3 = v4 + 1;
goto LABEL_7;
}
v4 = (_QWORD *)v4[1];
}
result = *v4;
}
else
{
LABEL_7:
v5 = malloc(0x10uLL);
*v5 = a2;
v5[1] = 0LL;
*v3 = v5;
result = 0LL;
}
return result;
}

original_code:
void *hash_tbl_insert(hash_tbl_t *tbl, void *item)
{
    int pos;
    hash_tbl_item_t *new_item, *item_ptr, *next_item, **buckets;
    hash_tbl_item_t **update_ptr;
    buckets = tbl->buckets;
    pos = tbl->hash_fn(item, tbl->n_buckets);
    next_item = buckets[pos];
    if(next_item) {
        do {
            item_ptr = next_item;
     if(!tbl->compare_fn(item_ptr->item, item)) {
  return item_ptr->item;
     }
     next_item = item_ptr->next;
        } while(next_item);
 update_ptr = &item_ptr->next;
    }
    else {
        update_ptr = &buckets[pos];
    }
    new_item = malloc(sizeof(hash_tbl_item_t));
    new_item->item = item;
    new_item->next = ((void *)0);
    *update_ptr = new_item;
    return ((void *)0);
}

canonical_original_code:
void *hash_tbl_insert(struct hash_tbl *tbl, void *item)
{
    int pos;
    struct hash_tbl_item *new_item; struct hash_tbl_item *item_ptr; struct hash_tbl_item *next_item; struct hash_tbl_item **buckets;
    struct hash_tbl_item **update_ptr;
    buckets = tbl->buckets;
    pos = tbl->hash_fn(item, tbl->n_buckets);
    next_item = buckets[pos];
    if(next_item) {
        do {
            item_ptr = next_item;
     if(!tbl->compare_fn(item_ptr->item, item)) {
  return item_ptr->item;
     }
     next_item = item_ptr->next;
        } while(next_item);
 update_ptr = &item_ptr->next;
    }
    else {
        update_ptr = &buckets[pos];
    }
    new_item = malloc(sizeof(hash_tbl_item_t));
    new_item->item = item;
    new_item->next = ((void *)0);
    *update_ptr = new_item;
    return ((void *)0);
}

variable_types: pos int

variable_types: struct hash_tbl_item { void *item; struct hash_tbl_item *next; } **

return_type: void *


original_code:
void *hash_tbl_delete(hash_tbl_t *tbl, void *item)
{
    int pos;
    hash_tbl_item_t *item_ptr, *next_item, *prev_item, **buckets;
    hash_tbl_item_t *return_item;
    buckets = tbl->buckets;
    pos = tbl->hash_fn(item, tbl->n_buckets);
    next_item = buckets[pos];
    if(next_item) {
        item_ptr = ((void *)0);
        do {
     prev_item = item_ptr;
            item_ptr = next_item;
     if(!tbl->compare_fn(item_ptr->item, item)) {
  return_item = item_ptr->item;
  free(item_ptr);
  if(prev_item) {
      prev_item->next = next_item;
  }
  else {
                    buckets[pos] = next_item;
  }
  return return_item;
     }
     next_item = item_ptr->next;
        } while(next_item);
    }
    return ((void *)0);
}

canonical_original_code:
void *hash_tbl_delete(struct hash_tbl *tbl, void *item)
{
    int pos;
    struct hash_tbl_item *item_ptr; struct hash_tbl_item *next_item; struct hash_tbl_item *prev_item; struct hash_tbl_item **buckets;
    struct hash_tbl_item *return_item;
    buckets = tbl->buckets;
    pos = tbl->hash_fn(item, tbl->n_buckets);
    next_item = buckets[pos];
    if(next_item) {
        item_ptr = ((void *)0);
        do {
     prev_item = item_ptr;
            item_ptr = next_item;
     if(!tbl->compare_fn(item_ptr->item, item)) {
  return_item = item_ptr->item;
  free(item_ptr);
  if(prev_item) {
      prev_item->next = next_item;
  }
  else {
                    buckets[pos] = next_item;
  }
  return return_item;
     }
     next_item = item_ptr->next;
        } while(next_item);
    }
    return ((void *)0);
}

variable_types: struct hash_tbl_item { void *item; struct hash_tbl_item *next; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rax
__int64 v4; // rbp
char *v5; // rbx
unsigned int j; // ebx
__int64 k; // rbx
int v9; // [rsp+0h] [rbp-4D8h] BYREF
unsigned int v10; // [rsp+8h] [rbp-4D0h] BYREF
_DWORD v11[4]; // [rsp+10h] [rbp-4C8h] BYREF
char v12; // [rsp+20h] [rbp-4B8h] BYREF
char v13; // [rsp+4C0h] [rbp-18h] BYREF

for ( i = 0LL; i != 150; ++i )
v11[2 * i] = i * i;
v4 = hash_tbl_alloc(13LL, hash_fn, compare_fn);
printf("Testing inserting items...");
v5 = (char *)v11;
do
{
if ( hash_tbl_insert(v4, v5) )
{
puts("error.");
exit(1);
}
v5 += 8;
}
while ( v5 != &v13 );
puts("passed.");
printf("Testing key duplication...");
v9 = 4;
if ( &v12 != (char *)hash_tbl_insert(v4, &v9) )
{
puts("error.");
exit(1);
}
puts("passed.");
puts("Testing find...");
for ( j = 0; j != 150; ++j )
{
v10 = j;
if ( hash_tbl_find(v4, &v10) )
printf(" key %d - found\n", j);
else
printf(" key %d - not found\n", j);
}
printf("Testing delete...");
for ( k = 0LL; k != 150; ++k )
{
v10 = k * k;
if ( (_DWORD *)hash_tbl_delete(v4, &v10) != &v11[2 * k] )
{
puts("error.");
exit(1);
}
}
puts("passed.");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 i; // rax
__int64 v4; // rbp
char *v5; // rbx
unsigned int j; // ebx
__int64 k; // rbx
int v9; // [rsp+0h] [rbp-4D8h] BYREF
unsigned int v10; // [rsp+8h] [rbp-4D0h] BYREF
_DWORD v11[4]; // [rsp+10h] [rbp-4C8h] BYREF
char v12; // [rsp+20h] [rbp-4B8h] BYREF
char v13; // [rsp+4C0h] [rbp-18h] BYREF

for ( i = 0LL; i != 150; ++i )
v11[2 * i] = i * i;
v4 = hash_tbl_alloc(13LL, hash_fn, compare_fn);
printf("Testing inserting items...");
v5 = (char *)v11;
do
{
if ( func10(v4, v5) )
{
puts("error.");
exit(1);
}
v5 += 8;
}
while ( v5 != &v13 );
puts("passed.");
printf("Testing key duplication...");
v9 = 4;
if ( &v12 != (char *)func10(v4, &v9) )
{
puts("error.");
exit(1);
}
puts("passed.");
puts("Testing find...");
for ( j = 0; j != 150; ++j )
{
v10 = j;
if ( hash_tbl_find(v4, &v10) )
printf(" key %d - found\n", j);
else
printf(" key %d - not found\n", j);
}
printf("Testing delete...");
for ( k = 0LL; k != 150; ++k )
{
v10 = k * k;
if ( (_DWORD *)func11(v4, &v10) != &v11[2 * k] )
{
puts("error.");
exit(1);
}
}
puts("passed.");
return 0;
}

original_code:
int main(void)
{
    int i;
    test_item_t items[150];
    test_item_t lookup, duplicate;
    hash_tbl_t *hash_table;
    for(i = 0; i < 150; i++) {
 items[i].key = i*i;
    }
    hash_table = hash_tbl_alloc(13, hash_fn, compare_fn);
    printf("Testing inserting items...");
    for(i = 0; i < 150; i++) {
        if(hash_tbl_insert(hash_table, &items[i]) != ((void *)0)) {
            printf("error.\n");
            exit(1);
 }
    }
    printf("passed.\n");
    printf("Testing key duplication...");
    duplicate.key = 2*2;
    if(hash_tbl_insert(hash_table, &duplicate) != &items[2]) {
        printf("error.\n");
        exit(1);
    }
    printf("passed.\n");
    printf("Testing find...\n");
    for(i = 0; i < 150; i++) {
 lookup.key = i;
        if(hash_tbl_find(hash_table, &lookup)) {
            printf("  key %d - found\n", i);
 }
 else {
            printf("  key %d - not found\n", i);
 }
    }
    printf("Testing delete...");
    for(i = 0; i < 150; i++) {
 lookup.key = i*i;
        if(hash_tbl_delete(hash_table, &lookup) != &items[i]) {
     printf("error.\n");
     exit(1);
 }
    }
    printf("passed.\n");
    return 0;
}

canonical_original_code:
int main()
{
    int i;
    struct test_item items[150];
    struct test_item lookup; struct test_item duplicate;
    struct hash_tbl *hash_table;
    for(i = 0; i < 150; i++) {
 items[i].key = i*i;
    }
    hash_table = hash_tbl_alloc(13, hash_fn, compare_fn);
    printf("Testing inserting items...");
    for(i = 0; i < 150; i++) {
        if(hash_tbl_insert(hash_table, &items[i]) != ((void *)0)) {
            printf("error.\n");
            exit(1);
 }
    }
    printf("passed.\n");
    printf("Testing key duplication...");
    duplicate.key = 2*2;
    if(hash_tbl_insert(hash_table, &duplicate) != &items[2]) {
        printf("error.\n");
        exit(1);
    }
    printf("passed.\n");
    printf("Testing find...\n");
    for(i = 0; i < 150; i++) {
 lookup.key = i;
        if(hash_tbl_find(hash_table, &lookup)) {
            printf("  key %d - found\n", i);
 }
 else {
            printf("  key %d - not found\n", i);
 }
    }
    printf("Testing delete...");
    for(i = 0; i < 150; i++) {
 lookup.key = i*i;
        if(hash_tbl_delete(hash_table, &lookup) != &items[i]) {
     printf("error.\n");
     exit(1);
 }
    }
    printf("passed.\n");
    return 0;
}

variable_types: struct test_item { int key; int other_data; } [150]

user_defined_types: struct hash_tbl_item { void *item; struct hash_tbl_item *next; }


decompiled_code:
void __fastcall mst_result_free(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void mst_result_free(mst_result_t *r)
{
    free(r->reached);
    free(r->d);
    free(r);
}

canonical_original_code:
void mst_result_free(struct mst_result *r)
{
    free(r->reached);
    free(r->d);
    free(r);
}

variable_types: struct mst_result { int n; int *reached; long *d; } *


binarysearch

original_code:
void *binarysearch(const void *key, const void *base, size_t nmemb,
     size_t size, int (*compar)(const void *, const void *))
{
    int min, max, mid;
    void *test;
    int c;
    min = 0;
    max = nmemb - 1;
    do {
        mid = (min + max) >> 1;
        test = base + mid * size;
 c = compar(key, test);
 if(c < 0) {
            max = mid - 1;
 }
        else if(c > 0) {
            min = mid + 1;
 }
 else {
            return test;
 }
    } while(min <= max);
    return ((void *)0);
}

canonical_original_code:
void *binarysearch(void *key, void *base, unsigned long nmemb, unsigned long size, int (*compar)(void *, void *))
{
    int min; int max; int mid;
    void *test;
    int c;
    min = 0;
    max = nmemb - 1;
    do {
        mid = (min + max) >> 1;
        test = base + mid * size;
 c = compar(key, test);
 if(c < 0) {
            max = mid - 1;
 }
        else if(c > 0) {
            min = mid + 1;
 }
 else {
            return test;
 }
    } while(min <= max);
    return ((void *)0);
}

variable_types:
key
void *

variable_types:
base
void *

variable_types:
nmemb
unsigned long

variable_types:
size
unsigned long

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

variable_types: min int

variable_types: max int

variable_types: mid int

variable_types:
test
void *

variable_types: c int


spaces

decompiled_code:
int __fastcall spaces(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(32);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
int i; // ebx
int result; // eax

if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
result = putchar(32);
}
return result;
}

original_code:
void spaces(int l)
{
    int i;
    for(i = 0; i < l; i++) {
        putchar(' ');
    }
}

variable_types: l int

variable_types: i int


decompiled_code:
__int64 tree23_dump_r()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 0LL;
}

original_code:
void *tree23_dump_r(tree23_node_t *p, int l)
{
    return ((void *)0);
}

canonical_original_code:
void *tree23_dump_r(struct tree23_node *p, int l)
{
    return ((void *)0);
}

variable_types: struct tree23_node { void *key_item1; union tree23_link { struct tree23_node *node; void *item; } left; enum { LEAF_LINK=0, INTERNAL_LINK=1 } link_kind; } *

user_defined_types: struct tree23_node { void *key_item1; union tree23_link left; enum { LEAF_LINK=0, INTERNAL_LINK=1 } link_kind; }


decompiled_code:
__int64 rbtree_dump()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
int rbtree_dump(rbtree_node_t *p, int l) {
    return 0;
}

canonical_original_code:
int rbtree_dump(struct rbtree_node *p, int l) {
    return 0;
}

variable_types: struct rbtree_node { void *item; struct rbtree_node *left; enum rbtree_colour_t { Red=0, Black=1 } colour; } *

user_defined_types: struct rbtree_node { void *item; struct rbtree_node *left; enum rbtree_colour_t colour; }


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

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

original_code:
int item_cmp(const void *item1, const void *item2)
{
    return ((test_item_t *)item1)->data1 - ((test_item_t *)item2)->data1;
}

canonical_original_code:
int item_cmp(void *item1, void *item2)
{
    return ((struct test_item *)item1)->data1 - ((struct test_item *)item2)->data1;
}

user_defined_types: struct test_item { int data1; int data2; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
int i; // ebx
unsigned int *v5; // rax
_DWORD *v6; // rax
const char *v7; // rdi
unsigned int *v8; // rax
int *v9; // rsi
_DWORD *v10; // rax
const char *v11; // rdi
unsigned int *v12; // rax
__int64 v13; // rdx
__int64 v14; // rbp
int *v15; // r12
char *v16; // rbx
char *v17; // r14
char *v18; // rbx
char *v19; // rbx
int v21; // [rsp+0h] [rbp-1D4F8h] BYREF
int v22[2]; // [rsp+8h] [rbp-1D4F0h] BYREF
int v23[15000]; // [rsp+10h] [rbp-1D4E8h] BYREF
int v24[15000]; // [rsp+EA70h] [rbp-EA88h] BYREF
char v25[40]; // [rsp+1D4D0h] [rbp-28h] BYREF

v3 = rbtree_alloc(item_cmp, argv, envp);
puts("Inserting items:");
for ( i = 0; i <= 14999; ++i )
{
v23[2 * i] = rand() % 30000;
v23[2 * i + 1] = rand() % 30000;
v5 = (unsigned int *)rbtree_insert(v3, &v23[2 * i]);
if ( v5 )
{
printf(" duplicate %d detected - trying again\n", *v5);
--i;
}
else
{
printf("inserting %d", (unsigned int)v23[2 * i]);
putchar(10);
}
}
printf("\nAttempting insert to give duplicate key...");
v22[0] = v24[0];
v22[1] = rand() % 30000;
if ( !rbtree_insert(v3, v22) )
{
puts("failed - duplicated undected.");
exit(1);
}
puts("duplicate detected.");
printf("\nTesting rbtree_find() to find an item...");
v21 = v24[0];
v6 = (_DWORD *)rbtree_find(v3, &v21);
if ( v6 )
{
v7 = "successful.";
if ( *v6 != v21 )
v7 = "failed.";
puts(v7);
}
else
{
puts("failed.");
}
printf("Testing rbtree_find_min()...");
v8 = (unsigned int *)rbtree_find_min(v3);
if ( v8 )
printf("%d.\n", *v8);
else
puts("failed.");
printf("\nTesting rbtree_delete()...");
v9 = &v21;
v10 = (_DWORD *)rbtree_delete(v3, &v21);
if ( v10 )
{
v11 = "successful.";
if ( *v10 != v21 )
v11 = "failed.";
puts(v11);
}
else
{
puts("failed.");
}
printf("Testing rbtree_delete_min()...");
v12 = (unsigned int *)rbtree_delete_min(v3);
if ( v12 )
{
v9 = (int *)*v12;
printf("%d.\n", v9);
}
else
{
puts("failed.");
}
printf("Testing rbtree_free()...");
rbtree_free(v3);
puts("successful.");
v14 = rbtree_alloc(item_cmp, v9, v13);
printf("\nRepeating rbtree_insert()/rbtree_delete()...");
v15 = v23;
v16 = (char *)v23;
do
{
rbtree_insert(v14, v16);
printf("inserted %d\n", *(unsigned int *)v16);
v16 += 8;
}
while ( v16 != v25 );
v17 = (char *)v24;
v18 = (char *)v24;
do
{
if ( !rbtree_delete(v14, v18) )
{
puts("failed.");
exit(1);
}
printf("deleted %d\n", *(unsigned int *)v18);
v18 += 8;
}
while ( v18 != v25 );
v19 = (char *)v24;
do
{
rbtree_insert(v14, v19);
printf("inserted %d\n", *(unsigned int *)v19);
v19 += 8;
}
while ( v19 != v25 );
do
{
if ( !rbtree_delete(v14, v15) )
{
puts("failed.");
exit(1);
}
printf("deleted %d\n", (unsigned int)*v15);
v15 += 2;
}
while ( v15 != v24 );
do
{
if ( !rbtree_delete(v14, v17) )
{
puts("failed.");
exit(1);
}
printf("deleted %d\n", *(unsigned int *)v17);
v17 += 8;
}
while ( v17 != v25 );
puts("successful.");
rbtree_free(v14);
return 0;
}

original_code:
int main(void)
{
    rbtree_t *t;
    test_item_t item_array[15000], *i, *i2, duplicate, lookup_item;
    test_item_t *result;
    int j;
    t = rbtree_alloc(item_cmp);
    printf("Inserting items:\n");
    for(j = 0; j < 15000; j++) {
 i = &item_array[j];
 i->data1 = rand() % 30000;
 i->data2 = rand() % 30000;
        if((i2 = rbtree_insert(t, i))) {
     printf("  duplicate %d detected - trying again\n", i2->data1);
     j--;
 }
 else {
     printf("inserting %d", i->data1);
putchar('\n'); rbtree_dump(t->root, 0);
 }
    }
    printf("\nAttempting insert to give duplicate key...");
    i2 = &item_array[15000/2];
    duplicate.data1 = i2->data1; duplicate.data2 = rand() % 30000;
    if(rbtree_insert(t, &duplicate)) {
 printf("duplicate detected.\n");
    }
    else {
 printf("failed - duplicated undected.\n");
 exit(1);
    }
    printf("\nTesting rbtree_find() to find an item...");
    lookup_item.data1 = item_array[15000/2].data1;
    result = rbtree_find(t, &lookup_item);
    if(result) {
 printf("%s\n", result->data1 == lookup_item.data1
        ? "successful." : "failed.");
    }
    else {
 printf("failed.\n");
    }
    printf("Testing rbtree_find_min()...");
    result = rbtree_find_min(t);
    if(result) printf("%d.\n", result->data1); else printf("failed.\n");
    printf("\nTesting rbtree_delete()...");
    result = rbtree_delete(t, &lookup_item);
    if(result) {
 printf("%s\n", result->data1 == lookup_item.data1
        ? "successful." : "failed.");
    }
    else {
 printf("failed.\n");
    }
    printf("Testing rbtree_delete_min()...");
    result = rbtree_delete_min(t);
    if(result) printf("%d.\n", result->data1); else printf("failed.\n");
    printf("Testing rbtree_free()...");
    rbtree_free(t);
    printf("successful.\n");
    t = rbtree_alloc(item_cmp);
    printf("\nRepeating rbtree_insert()/rbtree_delete()...");
    for(j = 0; j < 15000; j++) {
 i = &item_array[j];
        rbtree_insert(t, i);
printf("inserted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    for(j = 15000/2; j < 15000; j++) {
 i = &item_array[j];
 if(!rbtree_delete(t, i)) { printf("failed.\n"); exit(1); }
printf("deleted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    for(j = 15000/2; j < 15000; j++) {
 i = &item_array[j];
        rbtree_insert(t, i);
printf("inserted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    for(j = 0; j < 15000/2; j++) {
 i = &item_array[j];
 if(!rbtree_delete(t, i)) { printf("failed.\n"); exit(1); }
printf("deleted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    for(j = 15000/2; j < 15000; j++) {
 i = &item_array[j];
        if(!rbtree_delete(t, i)) { printf("failed.\n"); exit(1); }
printf("deleted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    printf("successful.\n");
    rbtree_free(t);
    return 0;
}

canonical_original_code:
int main()
{
    struct rbtree *t;
    struct test_item item_array[15000]; struct test_item *i; struct test_item *i2; struct test_item duplicate; struct test_item lookup_item;
    struct test_item *result;
    int j;
    t = rbtree_alloc(item_cmp);
    printf("Inserting items:\n");
    for(j = 0; j < 15000; j++) {
 i = &item_array[j];
 i->data1 = rand() % 30000;
 i->data2 = rand() % 30000;
        if((i2 = rbtree_insert(t, i))) {
     printf("  duplicate %d detected - trying again\n", i2->data1);
     j--;
 }
 else {
     printf("inserting %d", i->data1);
putchar('\n'); rbtree_dump(t->root, 0);
 }
    }
    printf("\nAttempting insert to give duplicate key...");
    i2 = &item_array[15000/2];
    duplicate.data1 = i2->data1; duplicate.data2 = rand() % 30000;
    if(rbtree_insert(t, &duplicate)) {
 printf("duplicate detected.\n");
    }
    else {
 printf("failed - duplicated undected.\n");
 exit(1);
    }
    printf("\nTesting rbtree_find() to find an item...");
    lookup_item.data1 = item_array[15000/2].data1;
    result = rbtree_find(t, &lookup_item);
    if(result) {
 printf("%s\n", result->data1 == lookup_item.data1
        ? "successful." : "failed.");
    }
    else {
 printf("failed.\n");
    }
    printf("Testing rbtree_find_min()...");
    result = rbtree_find_min(t);
    if(result) printf("%d.\n", result->data1); else printf("failed.\n");
    printf("\nTesting rbtree_delete()...");
    result = rbtree_delete(t, &lookup_item);
    if(result) {
 printf("%s\n", result->data1 == lookup_item.data1
        ? "successful." : "failed.");
    }
    else {
 printf("failed.\n");
    }
    printf("Testing rbtree_delete_min()...");
    result = rbtree_delete_min(t);
    if(result) printf("%d.\n", result->data1); else printf("failed.\n");
    printf("Testing rbtree_free()...");
    rbtree_free(t);
    printf("successful.\n");
    t = rbtree_alloc(item_cmp);
    printf("\nRepeating rbtree_insert()/rbtree_delete()...");
    for(j = 0; j < 15000; j++) {
 i = &item_array[j];
        rbtree_insert(t, i);
printf("inserted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    for(j = 15000/2; j < 15000; j++) {
 i = &item_array[j];
 if(!rbtree_delete(t, i)) { printf("failed.\n"); exit(1); }
printf("deleted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    for(j = 15000/2; j < 15000; j++) {
 i = &item_array[j];
        rbtree_insert(t, i);
printf("inserted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    for(j = 0; j < 15000/2; j++) {
 i = &item_array[j];
 if(!rbtree_delete(t, i)) { printf("failed.\n"); exit(1); }
printf("deleted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    for(j = 15000/2; j < 15000; j++) {
 i = &item_array[j];
        if(!rbtree_delete(t, i)) { printf("failed.\n"); exit(1); }
printf("deleted %d\n", i->data1);
rbtree_dump(t->root, 0);
    }
    printf("successful.\n");
    rbtree_free(t);
    return 0;
}

variable_types: struct rbtree { struct rbtree_node { void *item; struct rbtree_node *left; enum rbtree_colour_t { Red=0, Black=1 } colour; } *root; int n; int (*compar)(void *, void *); struct rbtree_node **stack; } *

variable_types: struct test_item { int data1; int data2; } [15000]

variable_types: struct test_item { int data1; int data2; } *

variable_types: j int

user_defined_types: struct rbtree { struct rbtree_node *root; int n; int (*compar)(void *, void *); struct rbtree_node **stack; }


decompiled_code:
int __fastcall err_doit(int a1, int a2, const char *a3, void *a4)
{
char *v5; // rbx
size_t v6; // rax
char s[2]; // [rsp+0h] [rbp-418h] BYREF

vsnprintf(s, 0x400uLL, a3, a4);
if ( a1 )
{
v5 = strerror(a2);
v6 = strlen(s);
snprintf(&s[v6], 1024 - v6, ": %s", v5);
}
*(_WORD *)&s[strlen(s)] = 10;
fflush(stdout);
fputs(s, stderr);
return fflush(0LL);
}

canonical_decompiled_code:
int __fastcall func0(int a1, int a2, const char *a3, void *a4)
{
char *v5; // rbx
size_t v6; // rax
char s[2]; // [rsp+0h] [rbp-418h] BYREF

vsnprintf(s, 0x400uLL, a3, a4);
if ( a1 )
{
v5 = strerror(a2);
v6 = strlen(s);
snprintf(&s[v6], 1024 - v6, ": %s", v5);
}
*(_WORD *)&s[strlen(s)] = 10;
fflush(stdout);
fputs(s, stderr);
return fflush(0LL);
}

original_code:
static void
err_doit(int errnoflag, int error, const char *fmt, va_list ap)
{
 char buf[1024];
 vsnprintf(buf, 1024, fmt, ap);
 if (errnoflag)
  snprintf(buf+strlen(buf), 1024 -strlen(buf), ": %s",
    strerror(error));
 strcat(buf, "\n");
 fflush(stdout);
 fputs(buf, stderr);
 fflush(((void *)0));
}

canonical_original_code:
static void err_doit(int errnoflag, int error, char *fmt, __builtin_va_list ap)
{
 char buf[1024];
 vsnprintf(buf, 1024, fmt, ap);
 if (errnoflag)
  snprintf(buf+strlen(buf), 1024 -strlen(buf), ": %s",
    strerror(error));
 strcat(buf, "\n");
 fflush(stdout);
 fputs(buf, stderr);
 fflush(((void *)0));
}

variable_types: errnoflag int

variable_types: error int

variable_types:
fmt
char *

variable_types:
buf
char [1024]


decompiled_code:
int err_ret(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
return err_doit(1, *v1, a1, va);
}

canonical_decompiled_code:
int func1(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
return func0(1, *v1, a1, va);
}

original_code:
void
err_ret(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, (*__errno_location ()), fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void err_ret(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, (*__errno_location ()), fmt, ap);
 __builtin_va_end(ap);
}


decompiled_code:
void __noreturn err_sys(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
err_doit(1, *v1, a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
func0(1, *v1, a1, va);
exit(1);
}

original_code:
void
err_sys(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, (*__errno_location ()), fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void err_sys(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, (*__errno_location ()), fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}


decompiled_code:
void __noreturn err_exit(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
err_doit(1, a1, a2, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func0(1, a1, a2, va);
exit(1);
}

original_code:
void
err_exit(int error, const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, error, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void err_exit(int error, char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, error, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}


decompiled_code:
void __noreturn err_dump(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
err_doit(1, *v1, a1, va);
abort();
}

canonical_decompiled_code:
void __noreturn func4(const char *a1, ...)
{
int *v1; // rax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
v1 = _errno_location();
func0(1, *v1, a1, va);
abort();
}

original_code:
void
err_dump(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, (*__errno_location ()), fmt, ap);
 __builtin_va_end(ap);
 abort();
 exit(1);
}

canonical_original_code:
void err_dump(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(1, (*__errno_location ()), fmt, ap);
 __builtin_va_end(ap);
 abort();
 exit(1);
}


decompiled_code:
int err_msg(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return err_doit(0, 0, a1, va);
}

canonical_decompiled_code:
int func5(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func0(0, 0, a1, va);
}

original_code:
void
err_msg(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, 0, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void err_msg(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, 0, fmt, ap);
 __builtin_va_end(ap);
}


decompiled_code:
void __noreturn err_quit(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
err_doit(0, 0, a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func6(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(0, 0, a1, va);
exit(1);
}

original_code:
void
err_quit(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, 0, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}

canonical_original_code:
void err_quit(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 err_doit(0, 0, fmt, ap);
 __builtin_va_end(ap);
 exit(1);
}


original_code:
static int conf_parse_line(char* buf,char** name,char**value)
{
 char *index;
 index=buf;
 while((*index != '=') && (*index !='\0'))
  index++;
 if(*index == '=')
 { *index='\0';
  *name=buf;
  index++;
  *value=index;
  return 1;
 }
 else
  return 0;
}

canonical_original_code:
static int conf_parse_line(char *buf, char **name, char **value)
{
 char *index;
 index=buf;
 while((*index != '=') && (*index !='\0'))
  index++;
 if(*index == '=')
 { *index='\0';
  *name=buf;
  index++;
  *value=index;
  return 1;
 }
 else
  return 0;
}

variable_types:
buf
char *

variable_types:
name
char **

variable_types:
value
char **

variable_types:
index
char *


decompiled_code:
__int64 __fastcall conf_entry_list_add(__int64 a1, const char *a2, const char *a3)
{
unsigned __int64 v3; // rbp
size_t v5; // rax
char *v6; // rax
char *v7; // r14
size_t v8; // rax
char *v9; // rax
char *v10; // r12
char **v11; // rax
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 192);
if ( v3 > 0xB )
{
log_msg("conf_entry_list_add() error: entrys overflow()");
result = 0LL;
}
else
{
v5 = strlen(a2);
v6 = (char *)malloc(v5 + 1);
v7 = v6;
if ( v6 )
{
strcpy(v6, a2);
v8 = strlen(a3);
v9 = (char *)malloc(v8 + 1);
v10 = v9;
if ( v9 )
{
strcpy(v9, a3);
v11 = (char **)(a1 + 16 * v3);
*v11 = v7;
v11[1] = v10;
*(_QWORD *)(a1 + 192) = v3 + 1;
result = 1LL;
}
else
{
free(v7);
log_err("conf_entry_list_add() error: allocated memory failed");
result = 0LL;
}
}
else
{
log_err("conf_entry_list_add() error: allocated memory failed");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, const char *a3)
{
unsigned __int64 v3; // rbp
size_t v5; // rax
char *v6; // rax
char *v7; // r14
size_t v8; // rax
char *v9; // rax
char *v10; // r12
char **v11; // rax
__int64 result; // rax

v3 = *(_QWORD *)(a1 + 192);
if ( v3 > 0xB )
{
log_msg("conf_entry_list_add() error: entrys overflow()");
result = 0LL;
}
else
{
v5 = strlen(a2);
v6 = (char *)malloc(v5 + 1);
v7 = v6;
if ( v6 )
{
strcpy(v6, a2);
v8 = strlen(a3);
v9 = (char *)malloc(v8 + 1);
v10 = v9;
if ( v9 )
{
strcpy(v9, a3);
v11 = (char **)(a1 + 16 * v3);
*v11 = v7;
v11[1] = v10;
*(_QWORD *)(a1 + 192) = v3 + 1;
result = 1LL;
}
else
{
free(v7);
log_err("conf_entry_list_add() error: allocated memory failed");
result = 0LL;
}
}
else
{
log_err("conf_entry_list_add() error: allocated memory failed");
result = 0LL;
}
}
return result;
}

original_code:
static int conf_entry_list_add(struct ConfEntryList *list,const char*name,const char *value)
{
 size_t len;
 char *name_ptr,*value_ptr;
 if(list->count >= 12)
 {
        log_msg("conf_entry_list_add() error: entrys overflow()");
  return 0;
 }
 len=strlen(name)+1;
 name_ptr=malloc(sizeof(char)*len);
 if(!name_ptr)
 {
        log_err("conf_entry_list_add() error: allocated memory failed");
  return 0;
 }
 strcpy(name_ptr,name);
 len=strlen(value)+1;
 value_ptr=malloc(sizeof(char)*len);
 if(!value_ptr)
 {
  free(name_ptr);
        log_err("conf_entry_list_add() error: allocated memory failed");
  return 0;
 }
 strcpy(value_ptr,value);
 list->entrys[list->count].name=name_ptr;
 list->entrys[list->count].value=value_ptr;
 list->count++;
 return 1;
}

canonical_original_code:
static int conf_entry_list_add(struct ConfEntryList *list, char *name, char *value)
{
 unsigned long len;
 char *name_ptr; char *value_ptr;
 if(list->count >= 12)
 {
        log_msg("conf_entry_list_add() error: entrys overflow()");
  return 0;
 }
 len=strlen(name)+1;
 name_ptr=malloc(sizeof(char)*len);
 if(!name_ptr)
 {
        log_err("conf_entry_list_add() error: allocated memory failed");
  return 0;
 }
 strcpy(name_ptr,name);
 len=strlen(value)+1;
 value_ptr=malloc(sizeof(char)*len);
 if(!value_ptr)
 {
  free(name_ptr);
        log_err("conf_entry_list_add() error: allocated memory failed");
  return 0;
 }
 strcpy(value_ptr,value);
 list->entrys[list->count].name=name_ptr;
 list->entrys[list->count].value=value_ptr;
 list->count++;
 return 1;
}

variable_types: struct ConfEntryList { struct ConfEntry { char *name; char *value; } entrys[12]; unsigned long count; } *

variable_types:
name
char *

variable_types:
value
char *

variable_types:
len
unsigned long

user_defined_types: struct ConfEntryList { struct ConfEntry entrys[12]; unsigned long count; }


original_code:
static void conf_entry_list_clean(struct ConfEntryList *list)
{
 size_t i;
 for(i=0;i<list->count;++i)
 {
  free(list->entrys[i].name);
  list->entrys[i].name=((void *)0);
  free(list->entrys[i].value);
  list->entrys[i].value=((void *)0);
 }
 list->count=0;
}

canonical_original_code:
static void conf_entry_list_clean(struct ConfEntryList *list)
{
 unsigned long i;
 for(i=0;i<list->count;++i)
 {
  free(list->entrys[i].name);
  list->entrys[i].name=((void *)0);
  free(list->entrys[i].value);
  list->entrys[i].value=((void *)0);
 }
 list->count=0;
}

variable_types:
i
unsigned long

user_defined_types: struct ConfEntry { char *name; char *value; }


decompiled_code:
__int64 __fastcall find_entry(__int64 a1, const char *a2)
{
__int64 v2; // r14
__int64 v3; // rbx

v2 = *(_QWORD *)(a1 + 192);
if ( !v2 )
return 0LL;
v3 = 0LL;
while ( strcmp(*(const char **)(a1 + 16 * v3), a2) )
{
if ( v2 == ++v3 )
return 0LL;
}
return a1 + 16 * v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2)
{
__int64 v2; // r14
__int64 v3; // rbx

v2 = *(_QWORD *)(a1 + 192);
if ( !v2 )
return 0LL;
v3 = 0LL;
while ( strcmp(*(const char **)(a1 + 16 * v3), a2) )
{
if ( v2 == ++v3 )
return 0LL;
}
return a1 + 16 * v3;
}

original_code:
static const struct ConfEntry* find_entry(const struct ConfEntryList *list,const char *name)
{
 size_t count=list->count;
 size_t i;
 for(i=0;i<count;++i)
 {
  if(strcmp(list->entrys[i].name,name) == 0)
   return &(list->entrys[i]);
 }
 return ((void *)0);
}

canonical_original_code:
static struct ConfEntry *find_entry(struct ConfEntryList *list, char *name)
{
 unsigned long count = list->count;
 unsigned long i;
 for(i=0;i<count;++i)
 {
  if(strcmp(list->entrys[i].name,name) == 0)
   return &(list->entrys[i]);
 }
 return ((void *)0);
}

variable_types: struct ConfEntryList { struct ConfEntry entrys[12]; unsigned long count; } *

variable_types:
count
unsigned long

return_type: struct ConfEntry { char *name; char *value; } *


decompiled_code:
__int64 __fastcall print_conf_option(const char *a1)
{
log_msg("host=%s", a1);
log_msg("port=%s", a1 + 256);
log_msg("workdir=%s", a1 + 272);
return log_msg("passwd=%s", a1 + 528);
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
log_msg("host=%s", a1);
log_msg("port=%s", a1 + 256);
log_msg("workdir=%s", a1 + 272);
return log_msg("passwd=%s", a1 + 528);
}

original_code:
void print_conf_option(struct FileTransferConf *conf)
{
    log_msg("host=%s",conf->host);
    log_msg("port=%s",conf->port);
    log_msg("workdir=%s",conf->workdir);
    log_msg("passwd=%s",conf->passwd);
}

variable_types: struct FileTransferConf { char host[256]; char port[16]; char workdir[256]; char passwd[128]; } *


Socket

decompiled_code:
__int64 __fastcall Socket(int a1, int a2, int a3)
{
int v3; // ebx

v3 = socket(a1, a2, a3);
if ( v3 < 0 )
log_sys("socket error");
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3)
{
int v3; // ebx

v3 = socket(a1, a2, a3);
if ( v3 < 0 )
log_sys("socket error");
return (unsigned int)v3;
}

original_code:
int Socket(int domain,int type,int protocal)
{
 int n;
 if((n=socket(domain,type,protocal))<0)
 {
        log_sys("socket error");
 }
 return n;
}

canonical_original_code:
int Socket(int domain, int type, int protocal)
{
 int n;
 if((n=socket(domain,type,protocal))<0)
 {
        log_sys("socket error");
 }
 return n;
}

variable_types: domain int

variable_types: type int

variable_types: protocal int

variable_types: n int


Connect

decompiled_code:
__int64 __fastcall Connect(int a1, const struct sockaddr *a2, socklen_t a3)
{
int v3; // ebx

v3 = connect(a1, a2, a3);
if ( v3 < 0 )
log_sys("connect error");
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, const struct sockaddr *a2, socklen_t a3)
{
int v3; // ebx

v3 = connect(a1, a2, a3);
if ( v3 < 0 )
log_sys("connect error");
return (unsigned int)v3;
}

original_code:
int Connect(int sockfd,const struct sockaddr *addr,socklen_t addrlen)
{
 int n;
 if((n=connect(sockfd,addr,addrlen))<0)
 {
        log_sys("connect error");
 }
 return n;
}

canonical_original_code:
int Connect(int sockfd, struct sockaddr *addr, unsigned int addrlen)
{
 int n;
 if((n=connect(sockfd,addr,addrlen))<0)
 {
        log_sys("connect error");
 }
 return n;
}

variable_types: sockfd int

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

variable_types:
addrlen
unsigned int


Listen

decompiled_code:
__int64 __fastcall Listen(int a1, int a2)
{
int v2; // ebx

v2 = listen(a1, a2);
if ( v2 < 0 )
log_sys("listen error");
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
int v2; // ebx

v2 = listen(a1, a2);
if ( v2 < 0 )
log_sys("listen error");
return (unsigned int)v2;
}

original_code:
int Listen(int sockfd,int backlog)
{
 int n;
 if((n=listen(sockfd,backlog))<0)
 {
        log_sys("listen error");
 }
 return n;
}

canonical_original_code:
int Listen(int sockfd, int backlog)
{
 int n;
 if((n=listen(sockfd,backlog))<0)
 {
        log_sys("listen error");
 }
 return n;
}

variable_types: backlog int


Readn

decompiled_code:
size_t __fastcall Readn(int fd, void *buf, size_t nbytes)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rbx
ssize_t v7; // rax

v3 = nbytes;
if ( nbytes )
{
v5 = nbytes;
while ( 1 )
{
v7 = read(fd, buf, v5);
v6 = v7;
if ( v7 < 0 )
{
if ( *_errno_location() == 4 )
v6 = 0LL;
else
log_sys("readn error");
}
else if ( !v7 )
{
return v3 - v5;
}
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

canonical_decompiled_code:
size_t __fastcall func4(int fd, void *buf, size_t nbytes)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rbx
ssize_t v7; // rax

v3 = nbytes;
if ( nbytes )
{
v5 = nbytes;
while ( 1 )
{
v7 = read(fd, buf, v5);
v6 = v7;
if ( v7 < 0 )
{
if ( *_errno_location() == 4 )
v6 = 0LL;
else
log_sys("readn error");
}
else if ( !v7 )
{
return v3 - v5;
}
buf = (char *)buf + v6;
v5 -= v6;
if ( !v5 )
return v3 - v5;
}
}
v5 = 0LL;
return v3 - v5;
}

original_code:
ssize_t Readn(int fd,void *buf,size_t count)
{
 size_t nleft;
 ssize_t nread;
 char *ptr=(char*)buf;
 nleft=count;
 while(nleft>0)
 {
  if((nread=read(fd,ptr,nleft))<0)
  {
   if((*__errno_location ())==4)
    nread=0;
   else
            {
                log_sys("readn error");
            }
  }
  else
   if(nread==0)
    break;
  nleft-=nread;
  ptr+=nread;
 }
 return (count-nleft);
}

canonical_original_code:
long Readn(int fd, void *buf, unsigned long count)
{
 unsigned long nleft;
 long nread;
 char *ptr = (char*)buf;
 nleft=count;
 while(nleft>0)
 {
  if((nread=read(fd,ptr,nleft))<0)
  {
   if((*__errno_location ())==4)
    nread=0;
   else
            {
                log_sys("readn error");
            }
  }
  else
   if(nread==0)
    break;
  nleft-=nread;
  ptr+=nread;
 }
 return (count-nleft);
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
nleft
unsigned long

variable_types: nread long

variable_types:
ptr
char *

return_type: long


Read

decompiled_code:
__int64 __fastcall Read(int fd, void *buf, size_t nbytes)
{
int v4; // er13

while ( 1 )
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 )
break;
if ( *_errno_location() != 4 )
{
log_sys("read error");
return v4;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, void *buf, size_t nbytes)
{
int v4; // er13

while ( 1 )
{
v4 = read(fd, buf, nbytes);
if ( v4 >= 0 )
break;
if ( *_errno_location() != 4 )
{
log_sys("read error");
return v4;
}
}
return v4;
}

original_code:
ssize_t Read(int fd,void *buf,size_t count)
{
 int n;
again:
 if((n=read(fd,buf,count))<0)
 {
  if((*__errno_location ())==4)
   goto again;
  else
  {
            log_sys("read error");
  }
 }
 return n;
}

canonical_original_code:
long Read(int fd, void *buf, unsigned long count)
{
 int n;
again:
 if((n=read(fd,buf,count))<0)
 {
  if((*__errno_location ())==4)
   goto again;
  else
  {
            log_sys("read error");
  }
 }
 return n;
}


Writen

decompiled_code:
size_t __fastcall Writen(int fd, void *buf, size_t n)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // rbx

v3 = n;
if ( n )
{
v5 = n;
do
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
{
if ( v6 < 0 && *_errno_location() == 4 )
v7 = 0LL;
else
log_sys("writen error");
}
buf = (char *)buf + v7;
v5 -= v7;
}
while ( v5 );
}
return v3;
}

canonical_decompiled_code:
size_t __fastcall func6(int fd, void *buf, size_t n)
{
size_t v3; // r14
size_t v5; // rbp
ssize_t v6; // rax
ssize_t v7; // rbx

v3 = n;
if ( n )
{
v5 = n;
do
{
v6 = write(fd, buf, v5);
v7 = v6;
if ( v6 <= 0 )
{
if ( v6 < 0 && *_errno_location() == 4 )
v7 = 0LL;
else
log_sys("writen error");
}
buf = (char *)buf + v7;
v5 -= v7;
}
while ( v5 );
}
return v3;
}

original_code:
ssize_t Writen(int fd,const void *buf,size_t count)
{
 size_t nleft;
 ssize_t nwritten;
 const char* ptr=(char*)buf;
 nleft=count;
 while(nleft>0)
 {
  if((nwritten=write(fd,ptr,nleft))<=0)
  {
   if(nwritten<0&&(*__errno_location ())==4)
    nwritten=0;
   else
            {
                log_sys("writen error");
            }
  }
  nleft-=nwritten;
  ptr+=nwritten;
 }
 return(count);
}

canonical_original_code:
long Writen(int fd, void *buf, unsigned long count)
{
 unsigned long nleft;
 long nwritten;
 char *ptr = (char*)buf;
 nleft=count;
 while(nleft>0)
 {
  if((nwritten=write(fd,ptr,nleft))<=0)
  {
   if(nwritten<0&&(*__errno_location ())==4)
    nwritten=0;
   else
            {
                log_sys("writen error");
            }
  }
  nleft-=nwritten;
  ptr+=nwritten;
 }
 return(count);
}

variable_types: nwritten long


decompiled_code:
__int64 __fastcall Open_m(const char *a1, int a2)
{
int v2; // ebx

v2 = open(a1, a2);
if ( v2 < 0 )
log_sys("open file %s error", a1);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, int a2)
{
int v2; // ebx

v2 = open(a1, a2);
if ( v2 < 0 )
log_sys("open file %s error", a1);
return (unsigned int)v2;
}

original_code:
int Open_m(const char *pathname,int flags,mode_t mode)
{
 int fd;
 if((fd=open(pathname,flags,mode))<0)
 {
        log_sys("open file %s error",pathname);
 }
 return fd;
}

canonical_original_code:
int Open_m(char *pathname, int flags, unsigned int mode)
{
 int fd;
 if((fd=open(pathname,flags,mode))<0)
 {
        log_sys("open file %s error",pathname);
 }
 return fd;
}

variable_types:
pathname
char *

variable_types: flags int

variable_types:
mode
unsigned int


Open

decompiled_code:
__int64 __fastcall Open(const char *a1, int a2)
{
int v2; // ebx

v2 = open(a1, a2);
if ( v2 < 0 )
log_sys("open file %s error", a1);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, int a2)
{
int v2; // ebx

v2 = open(a1, a2);
if ( v2 < 0 )
log_sys("open file %s error", a1);
return (unsigned int)v2;
}

original_code:
int Open(const char *pathname,int flags)
{
 int fd;
 if((fd=open(pathname,flags))<0)
 {
        log_sys("open file %s error",pathname);
 }
 return fd;
}

canonical_original_code:
int Open(char *pathname, int flags)
{
 int fd;
 if((fd=open(pathname,flags))<0)
 {
        log_sys("open file %s error",pathname);
 }
 return fd;
}


Close

decompiled_code:
__int64 __fastcall Close(int a1)
{
int v1; // ebx

v1 = close(a1);
if ( v1 < 0 )
log_sys("close error");
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // ebx

v1 = close(a1);
if ( v1 < 0 )
log_sys("close error");
return (unsigned int)v1;
}

original_code:
int Close(int fd)
{
 int n;
 if((n=close(fd))<0)
 {
        log_sys("close error");
 }
 return n;
}


Bind

decompiled_code:
__int64 __fastcall Bind(int a1, const struct sockaddr *a2, socklen_t a3)
{
int v3; // ebx

v3 = bind(a1, a2, a3);
if ( v3 < 0 )
log_sys("bind error");
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, const struct sockaddr *a2, socklen_t a3)
{
int v3; // ebx

v3 = bind(a1, a2, a3);
if ( v3 < 0 )
log_sys("bind error");
return (unsigned int)v3;
}

original_code:
int Bind(int sockfd,const struct sockaddr *addr,socklen_t addrlen)
{
 int n;
 if((n=bind(sockfd,addr,addrlen))<0)
 {
        log_sys("bind error");
 }
 return n;
}

canonical_original_code:
int Bind(int sockfd, struct sockaddr *addr, unsigned int addrlen)
{
 int n;
 if((n=bind(sockfd,addr,addrlen))<0)
 {
        log_sys("bind error");
 }
 return n;
}

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


Accept

decompiled_code:
__int64 __fastcall Accept(int a1, struct sockaddr *a2, socklen_t *a3)
{
int v3; // ebx

v3 = accept(a1, a2, a3);
if ( v3 < 0 )
log_sys("accept error");
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, struct sockaddr *a2, socklen_t *a3)
{
int v3; // ebx

v3 = accept(a1, a2, a3);
if ( v3 < 0 )
log_sys("accept error");
return (unsigned int)v3;
}

original_code:
int Accept(int sockfd,struct sockaddr *addr,socklen_t *addrlen)
{
 int n;
 if((n=accept(sockfd,addr,addrlen))<0)
 {
        log_sys("accept error");
 }
 return n;
}

canonical_original_code:
int Accept(int sockfd, struct sockaddr *addr, unsigned int *addrlen)
{
 int n;
 if((n=accept(sockfd,addr,addrlen))<0)
 {
        log_sys("accept error");
 }
 return n;
}

variable_types:
addrlen
unsigned int *


Malloc

decompiled_code:
void *__fastcall Malloc(size_t a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
log_sys("malloc error");
return v1;
}

canonical_decompiled_code:
void *__fastcall func12(size_t a1)
{
void *v1; // rbx

v1 = malloc(a1);
if ( !v1 )
log_sys("malloc error");
return v1;
}

original_code:
void* Malloc(size_t size)
{
 void* ptr;
 if((ptr=malloc(size))==((void *)0))
 {
        log_sys("malloc error");
 }
 return(ptr);
}

canonical_original_code:
void *Malloc(unsigned long size)
{
 void *ptr;
 if((ptr=malloc(size))==((void *)0))
 {
        log_sys("malloc error");
 }
 return(ptr);
}

variable_types:
size
unsigned long

variable_types:
ptr
void *


Calloc

decompiled_code:
void *__fastcall Calloc(size_t a1, size_t a2)
{
void *v2; // rbx

v2 = calloc(a1, a2);
if ( !v2 )
log_sys("calloc error");
return v2;
}

canonical_decompiled_code:
void *__fastcall func13(size_t a1, size_t a2)
{
void *v2; // rbx

v2 = calloc(a1, a2);
if ( !v2 )
log_sys("calloc error");
return v2;
}

original_code:
void* Calloc(size_t nmemb,size_t size)
{
 void* ptr;
 if((ptr=calloc(nmemb,size))==((void *)0))
 {
        log_sys("calloc error");
 }
 return(ptr);
}

canonical_original_code:
void *Calloc(unsigned long nmemb, unsigned long size)
{
 void *ptr;
 if((ptr=calloc(nmemb,size))==((void *)0))
 {
        log_sys("calloc error");
 }
 return(ptr);
}

variable_types:
nmemb
unsigned long


Readline

decompiled_code:
__int64 __fastcall Readline(int fd, __int64 a2, __int64 a3)
{
int v4; // ebp
__int64 v5; // rbx
int v7; // eax
char v8; // al
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( a3 )
{
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v7 = read(fd, buf, 1uLL);
if ( v7 < 0 )
{
if ( *_errno_location() != 4 )
log_sys("readline error");
}
else
{
if ( !v7 )
return v4;
v8 = buf[0];
*(_BYTE *)(a2 + v5) = buf[0];
++v4;
if ( v8 == 10 )
return v4;
}
v5 = v4;
if ( v4 == a3 )
return v4;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func14(int fd, __int64 a2, __int64 a3)
{
int v4; // ebp
__int64 v5; // rbx
int v7; // eax
char v8; // al
char buf[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( a3 )
{
v4 = 0;
v5 = 0LL;
while ( 1 )
{
v7 = read(fd, buf, 1uLL);
if ( v7 < 0 )
{
if ( *_errno_location() != 4 )
log_sys("readline error");
}
else
{
if ( !v7 )
return v4;
v8 = buf[0];
*(_BYTE *)(a2 + v5) = buf[0];
++v4;
if ( v8 == 10 )
return v4;
}
v5 = v4;
if ( v4 == a3 )
return v4;
}
}
return 0;
}

original_code:
ssize_t Readline(int fd,void* buf,size_t maxlen)
{
 int nread,count=0;
    char ch;
    char *buf_ptr=(char*)buf;
    while(1)
    {
        if(count == maxlen)
            return count;
        nread=read(fd,&ch,1);
        if(nread<0)
        {
            if((*__errno_location ()) == 4)
                continue;
            else
                log_sys("readline error");
        }
        else
            if(nread == 0)
                return count;
            else
            {
                buf_ptr[count]=ch;
                count++;
                if('\n' == ch)
                    return count;
            }
    }
}

canonical_original_code:
long Readline(int fd, void *buf, unsigned long maxlen)
{
 int nread; int count = 0;
    char ch;
    char *buf_ptr = (char*)buf;
    while(1)
    {
        if(count == maxlen)
            return count;
        nread=read(fd,&ch,1);
        if(nread<0)
        {
            if((*__errno_location ()) == 4)
                continue;
            else
                log_sys("readline error");
        }
        else
            if(nread == 0)
                return count;
            else
            {
                buf_ptr[count]=ch;
                count++;
                if('\n' == ch)
                    return count;
            }
    }
}

variable_types:
maxlen
unsigned long

variable_types: nread int

variable_types: count int

variable_types: ch char


decompiled_code:
const char *__fastcall sock_ntop(__int64 a1)
{
const char *result; // rax
unsigned __int16 v2; // cx
char s[16]; // [rsp+8h] [rbp-10h] BYREF

if ( *(_WORD *)a1 == 1 )
{
if ( *(_BYTE *)(a1 + 2) )
snprintf(address_0, 0x80uLL, "%s", (const char *)(a1 + 2));
else
strcpy(address_0, "no pathname bound");
result = address_0;
}
else
{
result = 0LL;
if ( *(_WORD *)a1 == 2 )
{
result = inet_ntop(2, (const void *)(a1 + 4), address_0, 0x80u);
if ( result )
{
v2 = _bswap_16(*(_WORD *)(a1 + 2));
result = address_0;
if ( v2 )
{
snprintf(s, 8uLL, ":%d", v2);
strcat(address_0, s);
result = address_0;
}
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func15(__int64 a1)
{
const char *result; // rax
unsigned __int16 v2; // cx
char s[16]; // [rsp+8h] [rbp-10h] BYREF

if ( *(_WORD *)a1 == 1 )
{
if ( *(_BYTE *)(a1 + 2) )
snprintf(address_0, 0x80uLL, "%s", (const char *)(a1 + 2));
else
strcpy(address_0, "no pathname bound");
result = address_0;
}
else
{
result = 0LL;
if ( *(_WORD *)a1 == 2 )
{
result = inet_ntop(2, (const void *)(a1 + 4), address_0, 0x80u);
if ( result )
{
v2 = func0(*(_WORD *)(a1 + 2));
result = address_0;
if ( v2 )
{
snprintf(s, 8uLL, ":%d", v2);
strcat(address_0, s);
result = address_0;
}
}
}
}
return result;
}

original_code:
char* sock_ntop(const struct sockaddr* addr,socklen_t addrlen)
{
 char port[8];
 static char address[128];
 switch(addr->sa_family)
 {
  case 2:
   {
    struct sockaddr_in *sin=(struct sockaddr_in*)addr;
    if(inet_ntop(2,&sin->sin_addr,address,sizeof(address))==((void *)0))
     return ((void *)0);
    if(ntohs(sin->sin_port)!=0)
    {
     snprintf(port,sizeof(port),":%d",ntohs(sin->sin_port));
     strcat(address,port);
    }
    return address;
   }
  case 1:
   {
    struct sockaddr_un *unp=(struct sockaddr_un*)addr;
    if(unp->sun_path[0]==0)
    {
     strcpy(address,"no pathname bound");
    }
    else
     snprintf(address,sizeof(address),"%s",unp->sun_path);
    return address;
   }
 }
 return ((void *)0);
}

canonical_original_code:
char *sock_ntop(struct sockaddr *addr, unsigned int addrlen)
{
 char port[8];
 static char address[128];
 switch(addr->sa_family)
 {
  case 2:
   {
    struct sockaddr_in *sin = (struct sockaddr_in*)addr;
    if(inet_ntop(2,&sin->sin_addr,address,sizeof(address))==((void *)0))
     return ((void *)0);
    if(ntohs(sin->sin_port)!=0)
    {
     snprintf(port,sizeof(port),":%d",ntohs(sin->sin_port));
     strcat(address,port);
    }
    return address;
   }
  case 1:
   {
    struct sockaddr_un *unp = (struct sockaddr_un*)addr;
    if(unp->sun_path[0]==0)
    {
     strcpy(address,"no pathname bound");
    }
    else
     snprintf(address,sizeof(address),"%s",unp->sun_path);
    return address;
   }
 }
 return ((void *)0);
}

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

variable_types:
addrlen
unsigned int

variable_types:
port
char [8]

variable_types:
address
char [128]

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

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *

return_type: char *

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


decompiled_code:
const char *__fastcall Sock_ntop(__int64 a1)
{
const char *v1; // rbx

v1 = sock_ntop(a1);
if ( !v1 )
log_sys("sock_ntop error");
return v1;
}

canonical_decompiled_code:
const char *__fastcall func16(__int64 a1)
{
const char *v1; // rbx

v1 = func15(a1);
if ( !v1 )
log_sys("sock_ntop error");
return v1;
}

original_code:
char *Sock_ntop(const struct sockaddr* addr,socklen_t addrlen)
{
 char *ptr;
 if((ptr=sock_ntop(addr,addrlen))==((void *)0))
 {
        log_sys("sock_ntop error");
 }
 return ptr;
}

canonical_original_code:
char *Sock_ntop(struct sockaddr *addr, unsigned int addrlen)
{
 char *ptr;
 if((ptr=sock_ntop(addr,addrlen))==((void *)0))
 {
        log_sys("sock_ntop error");
 }
 return ptr;
}

variable_types:
ptr
char *


filename

decompiled_code:
const char *__fastcall filename(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
const char *__fastcall func17(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

original_code:
const char* filename(const char *path)
{
 char *ptr;
 if((ptr=strrchr(path,'/'))==((void *)0))
  return path;
 else
  return ++ptr;
}

canonical_original_code:
char *filename(char *path)
{
 char *ptr;
 if((ptr=strrchr(path,'/'))==((void *)0))
  return path;
 else
  return ++ptr;
}

variable_types:
path
char *


decompiled_code:
void *__fastcall sock_address(void *dest, void *src)
{
void *result; // rax
size_t v3; // rbx

result = strchr((const char *)src, 58);
if ( result )
{
v3 = (int)result - (int)src;
result = memcpy(dest, src, v3);
*((_BYTE *)dest + v3) = 0;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func18(void *dest, void *src)
{
void *result; // rax
size_t v3; // rbx

result = strchr((const char *)src, 58);
if ( result )
{
v3 = (int)result - (int)src;
result = memcpy(dest, src, v3);
*((_BYTE *)dest + v3) = 0;
}
return result;
}

original_code:
const char* sock_address(char* result,const char* serverpath)
{
    const char* ptr=strchr(serverpath,':');
 int length=0;
 if(ptr==((void *)0))
 {
        return ((void *)0);
 }
    length=ptr-serverpath;
    memcpy(result,serverpath,length);
    result[length]='\0';
 return result;
}

canonical_original_code:
char *sock_address(char *result, char *serverpath)
{
    char *ptr = strchr(serverpath,':');
 int length = 0;
 if(ptr==((void *)0))
 {
        return ((void *)0);
 }
    length=ptr-serverpath;
    memcpy(result,serverpath,length);
    result[length]='\0';
 return result;
}

variable_types:
result
char *

variable_types:
serverpath
char *

variable_types: length int


decompiled_code:
char *__fastcall sock_port(char *dest, char *s)
{
char *result; // rax

result = strrchr(s, 58);
if ( result )
result = strcpy(dest, result + 1);
return result;
}

canonical_decompiled_code:
char *__fastcall func19(char *dest, char *s)
{
char *result; // rax

result = strrchr(s, 58);
if ( result )
result = strcpy(dest, result + 1);
return result;
}

original_code:
const char* sock_port(char *result, const char *server)
{
    const char* ptr=strrchr(server,':');
    if(ptr==((void *)0))
    {
        return ((void *)0);
    }
    strcpy(result,ptr+1);
    return result;
}

canonical_original_code:
char *sock_port(char *result, char *server)
{
    char *ptr = strrchr(server,':');
    if(ptr==((void *)0))
    {
        return ((void *)0);
    }
    strcpy(result,ptr+1);
    return result;
}

variable_types:
server
char *


decompiled_code:
__int64 __fastcall set_work_dir(char *path)
{
char v2[264]; // [rsp-108h] [rbp-108h] BYREF

if ( !path )
return 0xFFFFFFFFLL;
if ( access(path, 0) < 0 )
{
log_msg("dir %s not exist,now create it\n", path);
if ( mkdir(path, 0x1EDu) < 0 )
{
snprintf(v2, 0x100uLL, "create dir %s failed", path);
log_err(v2);
return 0xFFFFFFFFLL;
}
log_msg("create dir %s success\n", path);
}
else if ( access(path, 3) < 0 )
{
snprintf(v2, 0x100uLL, "access to dir %s error", path);
log_err(v2);
return 0xFFFFFFFFLL;
}
if ( chdir(path) >= 0 )
return 0LL;
snprintf(v2, 0x100uLL, "change dir to %s failed", path);
log_err(v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func20(char *path)
{
char v2[264]; // [rsp-108h] [rbp-108h] BYREF

if ( !path )
return 0xFFFFFFFFLL;
if ( access(path, 0) < 0 )
{
log_msg("dir %s not exist,now create it\n", path);
if ( mkdir(path, 0x1EDu) < 0 )
{
snprintf(v2, 0x100uLL, "create dir %s failed", path);
log_err(v2);
return 0xFFFFFFFFLL;
}
log_msg("create dir %s success\n", path);
}
else if ( access(path, 3) < 0 )
{
snprintf(v2, 0x100uLL, "access to dir %s error", path);
log_err(v2);
return 0xFFFFFFFFLL;
}
if ( chdir(path) >= 0 )
return 0LL;
snprintf(v2, 0x100uLL, "change dir to %s failed", path);
log_err(v2);
return 0xFFFFFFFFLL;
}

original_code:
int set_work_dir(const char *dir)
{
    char buf[256];
    int result;
    if(dir == ((void *)0))
        return -1;
    if(access(dir,0)<0)
    {
        log_msg("dir %s not exist,now create it\n",dir);
        result=mkdir(dir,(0400|0200|0100)|(0400 >> 3)|(0100 >> 3)|((0400 >> 3) >> 3)|((0100 >> 3) >> 3));
        if(result<0)
        {
            snprintf(buf,256,"create dir %s failed",dir);
            log_err(buf);
            return -1;
        }
        else
        {
            log_msg("create dir %s success\n",dir);
        }
    }
    else
    {
        if(access(dir,2|1)<0)
        {
            snprintf(buf,256,"access to dir %s error",dir);
            log_err(buf);
            return -1;
        }
    }
    if(chdir(dir)<0)
    {
        snprintf(buf,256,"change dir to %s failed",dir);
        log_err(buf);
        return -1;
    }
    else
        return 0;
}

canonical_original_code:
int set_work_dir(char *dir)
{
    char buf[256];
    int result;
    if(dir == ((void *)0))
        return -1;
    if(access(dir,0)<0)
    {
        log_msg("dir %s not exist,now create it\n",dir);
        result=mkdir(dir,(0400|0200|0100)|(0400 >> 3)|(0100 >> 3)|((0400 >> 3) >> 3)|((0100 >> 3) >> 3));
        if(result<0)
        {
            snprintf(buf,256,"create dir %s failed",dir);
            log_err(buf);
            return -1;
        }
        else
        {
            log_msg("create dir %s success\n",dir);
        }
    }
    else
    {
        if(access(dir,2|1)<0)
        {
            snprintf(buf,256,"access to dir %s error",dir);
            log_err(buf);
            return -1;
        }
    }
    if(chdir(dir)<0)
    {
        snprintf(buf,256,"change dir to %s failed",dir);
        log_err(buf);
        return -1;
    }
    else
        return 0;
}

variable_types:
dir
char *

variable_types:
buf
char [256]

variable_types: result int


decompiled_code:
int open_echo()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

if ( tcgetattr(0, &v1) < 0 )
return -1;
v1.c_lflag |= 8u;
return tcsetattr(0, 2, &v1);
}

canonical_decompiled_code:
int func21()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

if ( tcgetattr(0, &v1) < 0 )
return -1;
v1.c_lflag |= 8u;
return tcsetattr(0, 2, &v1);
}

original_code:
int open_echo()
{
    struct termios ter_conf;
    int ret;
    ret=tcgetattr(0,&ter_conf);
    if(ret<0)
    {
        return -1;
    }
    ter_conf.c_lflag |= 0000010;
    return tcsetattr(0,2,&ter_conf);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

variable_types: ret int


decompiled_code:
int close_echo()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

if ( tcgetattr(0, &v1) < 0 )
return -1;
v1.c_lflag &= 0xFFFFFFF7;
return tcsetattr(0, 2, &v1);
}

canonical_decompiled_code:
int func22()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

if ( tcgetattr(0, &v1) < 0 )
return -1;
v1.c_lflag &= 0xFFFFFFF7;
return tcsetattr(0, 2, &v1);
}

original_code:
int close_echo()
{
    struct termios ter_conf;
    int ret;
    ret=tcgetattr(0,&ter_conf);
    if(ret<0)
    {
        return -1;
    }
    ter_conf.c_lflag &= ~0000010;
    return tcsetattr(0,2,&ter_conf);
}

user_defined_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


decompiled_code:
__int64 __fastcall file_size_fd(int a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( fstat(a1, &v2) >= 0 )
return LODWORD(v2.st_size);
log_err("fstat error");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func23(int a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( fstat(a1, &v2) >= 0 )
return LODWORD(v2.st_size);
log_err("fstat error");
return 0xFFFFFFFFLL;
}

original_code:
int file_size_fd(int fd)
{
    struct stat file_stat;
    if(fstat(fd,&file_stat)<0)
    {
        log_err("fstat error");
        return -1;
    }
    return file_stat.st_size;
}

variable_types: fd int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall file_size_path(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) >= 0 )
return LODWORD(v2.st_size);
log_err("fstat error");
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func24(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) >= 0 )
return LODWORD(v2.st_size);
log_err("fstat error");
return 0xFFFFFFFFLL;
}

original_code:
int file_size_path(const char *path)
{
    struct stat file_stat;
    if(stat(path,&file_stat)<0)
    {
        log_err("fstat error");
        return -1;
    }
    return file_stat.st_size;
}

canonical_original_code:
int file_size_path(char *path)
{
    struct stat file_stat;
    if(stat(path,&file_stat)<0)
    {
        log_err("fstat error");
        return -1;
    }
    return file_stat.st_size;
}

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


decompiled_code:
int __fastcall progress_bar(int a1)
{
int i; // ebx
int v2; // ebx
int result; // eax

putchar(13);
putchar(91);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
putchar(43);
}
if ( 100 - a1 > 0 )
{
v2 = 1;
do
{
putchar(45);
++v2;
}
while ( v2 <= 100 - a1 );
}
putchar(93);
fprintf(stdout, " %3d%%", (unsigned int)a1);
result = fflush(stdout);
if ( a1 == 100 )
{
putchar(10);
result = fflush(stdout);
}
return result;
}

canonical_decompiled_code:
int __fastcall func25(int a1)
{
int i; // ebx
int v2; // ebx
int result; // eax

putchar(13);
putchar(91);
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
putchar(43);
}
if ( 100 - a1 > 0 )
{
v2 = 1;
do
{
putchar(45);
++v2;
}
while ( v2 <= 100 - a1 );
}
putchar(93);
fprintf(stdout, " %3d%%", (unsigned int)a1);
result = fflush(stdout);
if ( a1 == 100 )
{
putchar(10);
result = fflush(stdout);
}
return result;
}

original_code:
void progress_bar(int progress)
{
    int j=0;
    putchar('\r');
    putchar('[');
    for(j=0;j<progress;++j)
        putchar('+');
    for(j=1;j<=(100-progress);++j)
        putchar('-');
    putchar(']');
    fprintf(stdout," %3d%%",progress);
    fflush(stdout);
    if(progress == 100)
    {
        putchar('\n');
        fflush(stdout);
    }
}

canonical_original_code:
void progress_bar(int progress)
{
    int j = 0;
    putchar('\r');
    putchar('[');
    for(j=0;j<progress;++j)
        putchar('+');
    for(j=1;j<=(100-progress);++j)
        putchar('-');
    putchar(']');
    fprintf(stdout," %3d%%",progress);
    fflush(stdout);
    if(progress == 100)
    {
        putchar('\n');
        fflush(stdout);
    }
}

variable_types: progress int

variable_types: j int


decompiled_code:
void __fastcall log_open(const char *a1, int a2, int a3)
{
if ( !log_to_stderr )
openlog(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func1(const char *a1, int a2, int a3)
{
if ( !log_to_stderr )
openlog(a1, a2, a3);
}

original_code:
void
log_open(const char *ident, int option, int facility)
{
 if (log_to_stderr == 0)
  openlog(ident, option, facility);
}

canonical_original_code:
void log_open(char *ident, int option, int facility)
{
 if (log_to_stderr == 0)
  openlog(ident, option, facility);
}

variable_types:
ident
char *

variable_types: option int

variable_types: facility int


decompiled_code:
void log_err(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
log_doit(1, 3, a1, va);
}

canonical_decompiled_code:
void func2(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(1, 3, a1, va);
}

original_code:
void
log_err(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 log_doit(1, 3, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void log_err(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 log_doit(1, 3, fmt, ap);
 __builtin_va_end(ap);
}

variable_types:
fmt
char *


decompiled_code:
void __noreturn log_sys(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
log_doit(1, 3, a1, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func3(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(1, 3, a1, va);
exit(1);
}

original_code:
void
log_sys(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 log_doit(1, 3, fmt, ap);
 __builtin_va_end(ap);
    exit(1);
}

canonical_original_code:
void log_sys(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 log_doit(1, 3, fmt, ap);
 __builtin_va_end(ap);
    exit(1);
}


decompiled_code:
void log_msg(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
log_doit(0, 3, a1, va);
}

canonical_decompiled_code:
void func4(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(0, 3, a1, va);
}

original_code:
void
log_msg(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 log_doit(0, 3, fmt, ap);
 __builtin_va_end(ap);
}

canonical_original_code:
void log_msg(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 log_doit(0, 3, fmt, ap);
 __builtin_va_end(ap);
}


decompiled_code:
void __noreturn log_quit(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
log_doit(0, 3, a1, va);
exit(2);
}

canonical_decompiled_code:
void __noreturn func5(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
func0(0, 3, a1, va);
exit(2);
}

original_code:
void
log_quit(const char *fmt, ...)
{
 va_list ap;
 __builtin_va_start(ap,fmt);
 log_doit(0, 3, fmt, ap);
 __builtin_va_end(ap);
    exit(2);
}

canonical_original_code:
void log_quit(char *fmt, ...)
{
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 log_doit(0, 3, fmt, ap);
 __builtin_va_end(ap);
    exit(2);
}


decompiled_code:
__pid_t sig_chld()
{
__pid_t result; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
result = waitpid(-1, stat_loc, 1);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
__pid_t func0()
{
__pid_t result; // eax
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

do
result = waitpid(-1, stat_loc, 1);
while ( result > 0 );
return result;
}

original_code:
void sig_chld(int signo)
{
    pid_t pid;
    int stat;
    while((pid=waitpid(-1,&stat,1))>0);
    return;
}

canonical_original_code:
void sig_chld(int signo)
{
    int pid;
    int stat;
    while((pid=waitpid(-1,&stat,1))>0);
    return;
}

variable_types: signo int

variable_types: pid int

variable_types: stat int


sendfile

decompiled_code:
__int64 __fastcall sendfile(unsigned int a1, unsigned int a2)
{
int v2; // er12
int i; // ebp
__int64 v4; // rdx
int v5; // eax
int v6; // ebx
_BYTE v8[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = file_size_fd(a2);
for ( i = 0; ; progress_bar((unsigned int)(100 * (i / v2)), v8, v4) )
{
v5 = Read(a2, v8, 1024LL);
v6 = v5;
if ( v5 <= 0 )
break;
Writen(a1, v8, v5);
i += v6;
v4 = (unsigned int)(i >> 31);
LODWORD(v4) = i % v2;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
int v2; // er12
int i; // ebp
__int64 v4; // rdx
int v5; // eax
int v6; // ebx
_BYTE v8[1064]; // [rsp+0h] [rbp-428h] BYREF

v2 = file_size_fd(a2);
for ( i = 0; ; progress_bar((unsigned int)(100 * (i / v2)), v8, v4) )
{
v5 = Read(a2, v8, 1024LL);
v6 = v5;
if ( v5 <= 0 )
break;
Writen(a1, v8, v5);
i += v6;
v4 = (unsigned int)(i >> 31);
LODWORD(v4) = i % v2;
}
return 0LL;
}

original_code:
int sendfile(int sockfd,int fd)
{
 char buf[1024];
    int nread,count=0;
    int size=file_size_fd(fd);
 while((nread=Read(fd,buf,sizeof(buf)))>0)
 {
  Writen(sockfd,buf,nread);
        count+=nread;
        progress_bar((count/size)*100);
 }
 return 0;
}

canonical_original_code:
int sendfile(int sockfd, int fd)
{
 char buf[1024];
    int nread; int count = 0;
    int size = file_size_fd(fd);
 while((nread=Read(fd,buf,sizeof(buf)))>0)
 {
  Writen(sockfd,buf,nread);
        count+=nread;
        progress_bar((count/size)*100);
 }
 return 0;
}

variable_types: sockfd int

variable_types:
buf
char [1024]

variable_types: nread int

variable_types: count int

variable_types: size int


recvfile

decompiled_code:
__int64 __fastcall recvfile(unsigned int a1, unsigned int a2)
{
int v2; // eax
_BYTE v4[1048]; // [rsp+0h] [rbp-418h] BYREF

while ( 1 )
{
v2 = Read(a1, v4, 1024LL);
if ( v2 <= 0 )
break;
Writen(a2, v4, v2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2)
{
int v2; // eax
_BYTE v4[1048]; // [rsp+0h] [rbp-418h] BYREF

while ( 1 )
{
v2 = Read(a1, v4, 1024LL);
if ( v2 <= 0 )
break;
Writen(a2, v4, v2);
}
return 0LL;
}

original_code:
int recvfile(int sockfd,int fd)
{
 char buf[1024];
 int nread;
 while((nread=Read(sockfd,buf,sizeof(buf)))>0)
  Writen(fd,buf,nread);
 return 0;
}

canonical_original_code:
int recvfile(int sockfd, int fd)
{
 char buf[1024];
 int nread;
 while((nread=Read(sockfd,buf,sizeof(buf)))>0)
  Writen(fd,buf,nread);
 return 0;
}