decompiled_code:
__int64 __fastcall row_is_valid(int a1, unsigned int *a2)
{
unsigned int v2; // er12
__int64 v3; // rbp
_BYTE *v4; // rbx
__int64 v5; // r11
char v6; // di
_BYTE *v7; // rax
char v8; // cl
bool v9; // si

v3 = *a2;
v4 = (_BYTE *)((unsigned int)(v3 * a1) + *((_QWORD *)a2 + 1));
if ( !(_DWORD)v3 )
return 1LL;
v5 = 0LL;
while ( 1 )
{
v6 = v4[v5];
if ( v6 != 46 )
break;
LABEL_3:
if ( ++v5 == v3 )
return 1LL;
}
LOBYTE(v2) = v6 == *v4 && (_DWORD)v5 != 0 && *v4 != 46;
if ( !(_BYTE)v2 )
{
v7 = v4;
while ( &v4[(unsigned int)(v3 - 1)] != v7 )
{
v8 = v7[1];
v9 = 1 - (_DWORD)v4 + (_DWORD)v7++ != (_DWORD)v5;
if ( v6 == v8 && v8 != 46 && v9 )
return v2;
}
goto LABEL_3;
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, unsigned int *a2)
{
unsigned int v2; // er12
__int64 v3; // rbp
_BYTE *v4; // rbx
__int64 v5; // r11
char v6; // di
_BYTE *v7; // rax
char v8; // cl
bool v9; // si

v3 = *a2;
v4 = (_BYTE *)((unsigned int)(v3 * a1) + *((_QWORD *)a2 + 1));
if ( !(_DWORD)v3 )
return 1LL;
v5 = 0LL;
while ( 1 )
{
v6 = v4[v5];
if ( v6 != 46 )
break;
LABEL_3:
if ( ++v5 == v3 )
return 1LL;
}
LOBYTE(v2) = v6 == *v4 && (_DWORD)v5 != 0 && *v4 != 46;
if ( !(_BYTE)v2 )
{
v7 = v4;
while ( &v4[(unsigned int)(v3 - 1)] != v7 )
{
v8 = v7[1];
v9 = 1 - (_DWORD)v4 + (_DWORD)v7++ != (_DWORD)v5;
if ( v6 == v8 && v8 != 46 && v9 )
return v2;
}
goto LABEL_3;
}
return 0;
}

original_code:
_Bool row_is_valid(unsigned row, latin_square* square) {
    char* row_ptr = square->grid + row * square->width;
    unsigned c_count1, c_count2;
    char c_char1, c_char2;
    for (c_count1 = 0; c_count1 < square->width; c_count1++) {
        c_char1 = row_ptr[c_count1];
        if (c_char1 != placeholder_char) {
            for (c_count2 = 0; c_count2 < square->width; c_count2++) {
                c_char2 = row_ptr[c_count2];
                if (c_char2 != placeholder_char && c_count1 != c_count2 && c_char1 == c_char2) {
                    return 0;
                }
            }
        }
    }
    return 1;
}

canonical_original_code:
_Bool row_is_valid(unsigned int row, struct _latin_square *square) {
    char *row_ptr = square->grid + row * square->width;
    unsigned int c_count1; unsigned int c_count2;
    char c_char1; char c_char2;
    for (c_count1 = 0; c_count1 < square->width; c_count1++) {
        c_char1 = row_ptr[c_count1];
        if (c_char1 != placeholder_char) {
            for (c_count2 = 0; c_count2 < square->width; c_count2++) {
                c_char2 = row_ptr[c_count2];
                if (c_char2 != placeholder_char && c_count1 != c_count2 && c_char1 == c_char2) {
                    return 0;
                }
            }
        }
    }
    return 1;
}


repo: samphippen/lsquare

decompiled_code:
__int64 __fastcall col_is_valid(int a1, __int64 a2)
{
int v3; // edi
__int64 v4; // rsi
int v5; // er9
int v6; // er9
int v7; // er8
char v8; // al
int v9; // er8
char v10; // r10

v3 = *(_DWORD *)a2;
if ( !*(_DWORD *)a2 )
return 1LL;
v4 = *(_QWORD *)(a2 + 8);
v5 = 0;
while ( (unsigned __int8)get_char_at_isra_0(v3, v4, a1, v5) == 46 )
{
LABEL_3:
v5 = v6 + 1;
if ( v5 == v3 )
return 1LL;
}
v7 = 0;
while ( 1 )
{
v8 = get_char_at_isra_0(v3, v4, a1, v7);
if ( v6 != v9 && v8 != 46 && v10 == v8 )
return 0LL;
v7 = v9 + 1;
if ( v7 == v3 )
goto LABEL_3;
}
}

original_code:
_Bool col_is_valid(unsigned col, latin_square* square) {
    unsigned r_count1, r_count2;
    char r_char1, r_char2;
    for (r_count1 = 0; r_count1 < square->width; r_count1++) {
        r_char1 = get_char_at(square, col, r_count1);
        if (r_char1 != placeholder_char) {
            for (r_count2 = 0; r_count2 < square->width; r_count2++) {
                r_char2 = get_char_at(square, col, r_count2);
                if (r_char2 != placeholder_char && r_count1 != r_count2 && r_char1 == r_char2) return 0;
            }
        }
    }
    return 1;
}

canonical_original_code:
_Bool col_is_valid(unsigned int col, struct _latin_square *square) {
    unsigned int r_count1; unsigned int r_count2;
    char r_char1; char r_char2;
    for (r_count1 = 0; r_count1 < square->width; r_count1++) {
        r_char1 = get_char_at(square, col, r_count1);
        if (r_char1 != placeholder_char) {
            for (r_count2 = 0; r_count2 < square->width; r_count2++) {
                r_char2 = get_char_at(square, col, r_count2);
                if (r_char2 != placeholder_char && r_count1 != r_count2 && r_char1 == r_char2) return 0;
            }
        }
    }
    return 1;
}

variable_types:
col
unsigned int

variable_types: struct _latin_square { unsigned int width; char *grid; char *orig_grid; char *alphabet; } *


decompiled_code:
int __fastcall print_latin_square(int *a1)
{
int v1; // er13
unsigned int v3; // er12
int v4; // ebp
__int64 v5; // rcx
char *v6; // r15
__int64 v7; // rbx
int v8; // edi
int result; // eax

v1 = *a1;
if ( *a1 )
{
v3 = 0;
v4 = 0;
do
{
v5 = *((_QWORD *)a1 + 1);
v6 = (char *)(v5 + v3);
v7 = v3 + v5 + (unsigned int)(v1 - 1) + 1;
do
{
v8 = *v6++;
putchar(v8);
putchar(32);
}
while ( (char *)v7 != v6 );
++v4;
v3 += v1;
result = putchar(10);
}
while ( v1 != v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func17(int *a1)
{
int v1; // er13
unsigned int v3; // er12
int v4; // ebp
__int64 v5; // rcx
char *v6; // r15
__int64 v7; // rbx
int v8; // edi
int result; // eax

v1 = *a1;
if ( *a1 )
{
v3 = 0;
v4 = 0;
do
{
v5 = *((_QWORD *)a1 + 1);
v6 = (char *)(v5 + v3);
v7 = v3 + v5 + (unsigned int)(v1 - 1) + 1;
do
{
v8 = *v6++;
putchar(v8);
putchar(32);
}
while ( (char *)v7 != v6 );
++v4;
v3 += v1;
result = putchar(10);
}
while ( v1 != v4 );
}
return result;
}

original_code:
void print_latin_square(latin_square* square) {
    unsigned i = 0;
    unsigned j = 0;
    unsigned width = square->width;
    for (j = 0; j < width; j++) {
        char* row = square->grid + (j * width);
        for (i = 0; i < width; i++) {
            putchar(row[i]);
            putchar(' ');
        }
        putchar('\n');
    }
}

canonical_original_code:
void print_latin_square(struct _latin_square *square) {
    unsigned int i = 0;
    unsigned int j = 0;
    unsigned int width = square->width;
    for (j = 0; j < width; j++) {
        char *row = square->grid + (j * width);
        for (i = 0; i < width; i++) {
            putchar(row[i]);
            putchar(' ');
        }
        putchar('\n');
    }
}

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
width
unsigned int

variable_types:
row
char *

return_type: void

user_defined_types: struct _latin_square { unsigned int width; char *grid; char *orig_grid; char *alphabet; }


decompiled_code:
__int64 __fastcall square_complete(int *a1)
{
int v1; // ebp
unsigned int v2; // er12
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0;
do
{
result = col_is_filled(v2, a1);
if ( !(_BYTE)result )
break;
result = row_is_filled(v2, (__int64)a1);
if ( !(_BYTE)result )
break;
result = row_is_valid(v2, (unsigned int *)a1);
if ( !(_BYTE)result )
break;
result = col_is_valid(v2, (__int64)a1);
if ( !(_BYTE)result )
break;
++v2;
}
while ( v2 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(int *a1)
{
int v1; // ebp
unsigned int v2; // er12
__int64 result; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = 0;
do
{
result = func14(v2, a1);
if ( !(_BYTE)result )
break;
result = func13(v2, (__int64)a1);
if ( !(_BYTE)result )
break;
result = func15(v2, (unsigned int *)a1);
if ( !(_BYTE)result )
break;
result = func16(v2, (__int64)a1);
if ( !(_BYTE)result )
break;
++v2;
}
while ( v2 != v1 );
return result;
}

original_code:
_Bool square_complete(latin_square* square) {
    int i;
    for (i = 0; i < square->width; i++) {
        if (!(col_is_filled(i, square) &&
              row_is_filled(i, square) &&
              row_is_valid(i, square) &&
              col_is_valid(i, square))) return 0;
    }
    return 1;
}

canonical_original_code:
_Bool square_complete(struct _latin_square *square) {
    int i;
    for (i = 0; i < square->width; i++) {
        if (!(col_is_filled(i, square) &&
              row_is_filled(i, square) &&
              row_is_valid(i, square) &&
              col_is_valid(i, square))) return 0;
    }
    return 1;
}

variable_types: i int


decompiled_code:
__int64 __fastcall solve_latin_square(__int64 a1, char a2)
{
unsigned int v3; // eax
unsigned int v4; // ebp
unsigned int v5; // er13
int v6; // er15
int v7; // er12
unsigned int v8; // er14
__int64 result; // rax
__int64 v10; // r14
int v11; // edi
__int64 v12; // [rsp+0h] [rbp-48h]

v3 = clock();
srand(v3);
LABEL_2:
v4 = 0;
v5 = 0;
v6 = 0;
v7 = 0;
while ( 1 )
{
result = square_complete((int *)a1);
if ( (_BYTE)result )
return result;
if ( a2 )
{
putchar(13);
randomize_char(a1, v6, v7);
if ( *(_DWORD *)a1 )
{
v10 = 0LL;
v12 = *(_QWORD *)(a1 + 8) + (unsigned int)(v7 * *(_DWORD *)a1);
do
{
v11 = *(char *)(v12 + v10++);
putchar(v11);
putchar(32);
}
while ( *(_DWORD *)a1 > (unsigned int)v10 );
}
fflush(_bss_start);
}
else
{
randomize_char(a1, v6, v7);
}
++v4;
if ( (unsigned __int8)row_is_valid(v7, (unsigned int *)a1) && (unsigned __int8)col_is_valid(v6, a1) )
{
++v6;
v8 = 0;
if ( *(_DWORD *)a1 == v6 )
{
++v7;
v4 = 0;
v6 = 0;
if ( a2 )
{
putchar(10);
fflush(_bss_start);
}
goto LABEL_7;
}
LABEL_6:
if ( v4 > 0x1000000 )
goto LABEL_19;
goto LABEL_7;
}
v8 = v5 + 1;
if ( v5 <= 0x7F )
goto LABEL_6;
v6 = 0;
reset_row_isra_0(v7, *(_DWORD *)a1, *(_QWORD *)(a1 + 8));
if ( v4 > 0x1000000 )
{
LABEL_19:
puts("resetting grid!");
puts("------------------------------------------------");
memcpy(*(void **)(a1 + 8), *(const void **)(a1 + 16), (unsigned int)(*(_DWORD *)a1 * *(_DWORD *)a1));
goto LABEL_2;
}
LABEL_7:
v5 = v8;
}
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, char a2)
{
unsigned int v3; // eax
unsigned int v4; // ebp
unsigned int v5; // er13
int v6; // er15
int v7; // er12
unsigned int v8; // er14
__int64 result; // rax
__int64 v10; // r14
int v11; // edi
__int64 v12; // [rsp+0h] [rbp-48h]

v3 = clock();
srand(v3);
LABEL_2:
v4 = 0;
v5 = 0;
v6 = 0;
v7 = 0;
while ( 1 )
{
result = func18((int *)a1);
if ( (_BYTE)result )
return result;
if ( a2 )
{
putchar(13);
func7(a1, v6, v7);
if ( *(_DWORD *)a1 )
{
v10 = 0LL;
v12 = *(_QWORD *)(a1 + 8) + (unsigned int)(v7 * *(_DWORD *)a1);
do
{
v11 = *(char *)(v12 + v10++);
putchar(v11);
putchar(32);
}
while ( *(_DWORD *)a1 > (unsigned int)v10 );
}
fflush(_bss_start);
}
else
{
func7(a1, v6, v7);
}
++v4;
if ( (unsigned __int8)func15(v7, (unsigned int *)a1) && (unsigned __int8)func16(v6, a1) )
{
++v6;
v8 = 0;
if ( *(_DWORD *)a1 == v6 )
{
++v7;
v4 = 0;
v6 = 0;
if ( a2 )
{
putchar(10);
fflush(_bss_start);
}
goto LABEL_7;
}
LABEL_6:
if ( v4 > 0x1000000 )
goto LABEL_19;
goto LABEL_7;
}
v8 = v5 + 1;
if ( v5 <= 0x7F )
goto LABEL_6;
v6 = 0;
func8(v7, *(_DWORD *)a1, *(_QWORD *)(a1 + 8));
if ( v4 > 0x1000000 )
{
LABEL_19:
puts("resetting grid!");
puts("------------------------------------------------");
memcpy(*(void **)(a1 + 8), *(const void **)(a1 + 16), (unsigned int)(*(_DWORD *)a1 * *(_DWORD *)a1));
goto LABEL_2;
}
LABEL_7:
v5 = v8;
}
}

original_code:
void solve_latin_square(latin_square* square, _Bool verbose) {
    unsigned working_row = 0;
    unsigned charpos = 0;
    unsigned tries = 0;
    unsigned row_tries = 0;
    unsigned seekback = 1;
    int i;
    srand(clock());
    while (!square_complete(square)) {
        if (verbose) {
            putchar('\r');
        }
        randomize_char(square, charpos, working_row);
        if (verbose) {
            char* row_ptr = square->grid + working_row * square->width;
            for (i = 0; i < square->width; i++) {
                putchar(row_ptr[i]);
                putchar(' ');
            }
            fflush(stdout);
        }
        row_tries++;
        if (row_is_valid(working_row, square) && col_is_valid(charpos, square)) {
           tries = 0;
           if (++charpos == square->width) {
               charpos = 0;
               working_row += 1;
               seekback = 1;
               row_tries = 0;
               if (verbose) {
                   putchar('\n');
                   fflush(stdout);
               }
           }
        } else if (tries++ >= 128) {
                reset_row(working_row, square);
                charpos = 0;
        }
        if (row_tries > (1 << 24)) {
            printf("resetting grid!\n");
            printf("------------------------------------------------\n");
            working_row = 0;
            charpos = 0;
            tries = 0;
            row_tries = 0;
            memcpy(square->grid, square->orig_grid, square->width * square->width);
        }
    }
}

canonical_original_code:
void solve_latin_square(struct _latin_square *square, _Bool verbose) {
    unsigned int working_row = 0;
    unsigned int charpos = 0;
    unsigned int tries = 0;
    unsigned int row_tries = 0;
    unsigned int seekback = 1;
    int i;
    srand(clock());
    while (!square_complete(square)) {
        if (verbose) {
            putchar('\r');
        }
        randomize_char(square, charpos, working_row);
        if (verbose) {
            char *row_ptr = square->grid + working_row * square->width;
            for (i = 0; i < square->width; i++) {
                putchar(row_ptr[i]);
                putchar(' ');
            }
            fflush(stdout);
        }
        row_tries++;
        if (row_is_valid(working_row, square) && col_is_valid(charpos, square)) {
           tries = 0;
           if (++charpos == square->width) {
               charpos = 0;
               working_row += 1;
               seekback = 1;
               row_tries = 0;
               if (verbose) {
                   putchar('\n');
                   fflush(stdout);
               }
           }
        } else if (tries++ >= 128) {
                reset_row(working_row, square);
                charpos = 0;
        }
        if (row_tries > (1 << 24)) {
            printf("resetting grid!\n");
            printf("------------------------------------------------\n");
            working_row = 0;
            charpos = 0;
            tries = 0;
            row_tries = 0;
            memcpy(square->grid, square->orig_grid, square->width * square->width);
        }
    }
}

variable_types:
charpos
unsigned int

variable_types:
tries
unsigned int

variable_types:
seekback
unsigned int


printtime

repo: sampost/libsort

original_code:
void printtime(struct timeval * start, struct timeval * end)
{
    unsigned long long diff_us;
    diff_us =
        (((unsigned long long)end->tv_sec)*1000000 + end->tv_usec) -
        (((unsigned long long)start->tv_sec)*1000000 + start->tv_usec);
    printf("%llu s, %06llu us\n", diff_us/1000000, diff_us%1000000);
}

canonical_original_code:
void printtime(struct timeval *start, struct timeval *end)
{
    unsigned long long diff_us;
    diff_us =
        (((unsigned long long)end->tv_sec)*1000000 + end->tv_usec) -
        (((unsigned long long)start->tv_sec)*1000000 + start->tv_usec);
    printf("%llu s, %06llu us\n", diff_us/1000000, diff_us%1000000);
}

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

variable_types:
end
struct timeval *


decompiled_code:
__int64 __fastcall verify_sort(__int64 a1, int a2, __int16 a3)
{
int v3; // er12
unsigned int *v5; // rbp
unsigned int v6; // ebx
__int64 v7; // rsi
__int64 v8; // rcx
__int64 v9; // r8

v3 = a2 - 1;
if ( a2 - 1 > 0 )
{
v5 = (unsigned int *)(a1 + 4);
v6 = 0;
while ( 1 )
{
v7 = v6;
v8 = *(v5 - 1);
v9 = *v5;
++v6;
if ( a3 )
break;
if ( (int)v8 >= (int)v9 )
{
LABEL_5:
++v5;
if ( v3 == v6 )
return 0LL;
}
else
{
++v5;
printf("Failure! n[%d] < n[%d] (%d, %d)\n", v7, v6, v8, v9);
if ( v3 == v6 )
return 0LL;
}
}
if ( (int)v8 > (int)v9 )
printf("Failure! n[%d] > n[%d] (%d, %d)\n", v7, v6, v8, v9);
goto LABEL_5;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int16 a3)
{
int v3; // er12
unsigned int *v5; // rbp
unsigned int v6; // ebx
__int64 v7; // rsi
__int64 v8; // rcx
__int64 v9; // r8

v3 = a2 - 1;
if ( a2 - 1 > 0 )
{
v5 = (unsigned int *)(a1 + 4);
v6 = 0;
while ( 1 )
{
v7 = v6;
v8 = *(v5 - 1);
v9 = *v5;
++v6;
if ( a3 )
break;
if ( (int)v8 >= (int)v9 )
{
LABEL_5:
++v5;
if ( v3 == v6 )
return 0LL;
}
else
{
++v5;
printf("Failure! n[%d] < n[%d] (%d, %d)\n", v7, v6, v8, v9);
if ( v3 == v6 )
return 0LL;
}
}
if ( (int)v8 > (int)v9 )
printf("Failure! n[%d] > n[%d] (%d, %d)\n", v7, v6, v8, v9);
goto LABEL_5;
}
return 0LL;
}

original_code:
int verify_sort(int * numbers, int len, short asc)
{
    int i;
    for(i = 0; i < len-1; i++)
    {
        if(asc && (numbers[i] > numbers[i+1]))
           printf("Failure! n[%d] > n[%d] (%d, %d)\n",
                  i, i+1, numbers[i], numbers[i+1]);
        if(!asc && (numbers[i] < numbers[i+1]))
           printf("Failure! n[%d] < n[%d] (%d, %d)\n",
                  i, i+1, numbers[i], numbers[i+1]);
    }
}

canonical_original_code:
int verify_sort(int *numbers, int len, short asc)
{
    int i;
    for(i = 0; i < len-1; i++)
    {
        if(asc && (numbers[i] > numbers[i+1]))
           printf("Failure! n[%d] > n[%d] (%d, %d)\n",
                  i, i+1, numbers[i], numbers[i+1]);
        if(!asc && (numbers[i] < numbers[i+1]))
           printf("Failure! n[%d] < n[%d] (%d, %d)\n",
                  i, i+1, numbers[i], numbers[i+1]);
    }
}

variable_types:
numbers
int *

variable_types: len int

variable_types: asc short

return_type: int


decompiled_code:
int __fastcall do_int_sort(__int64 a1, int a2, __int64 a3, __int64 (__fastcall **a4)(_QWORD, _QWORD, _QWORD, _QWORD), void *a5)
{
const char *v8; // rdx
struct timeval v11; // [rsp+0h] [rbp-58h] BYREF
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF

v8 = "asc";
if ( a5 != &int_compare_asc )
v8 = "desc";
printf("Sorting %s, int %s: ", a3, v8);
fflush(stdout);
if ( a4 == &bubblesort )
{
gettimeofday(&v11, 0LL);
bubblesort(a1, a2, 4LL, a5);
goto LABEL_11;
}
if ( a4 == &mergesort )
{
gettimeofday(&v11, 0LL);
mergesort(a1, a2, 4LL, a5);
goto LABEL_11;
}
if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc )
{
gettimeofday(&v11, 0LL);
mergesort_onemalloc(a1, a2, 4LL, a5, 0LL);
goto LABEL_11;
}
if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort )
{
gettimeofday(&v11, 0LL);
quicksort(a1, 0LL, a2 - 1, 4LL, a5);
LABEL_11:
gettimeofday(&tv, 0LL);
return printtime(&v11, &tv);
}
if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc )
{
gettimeofday(&v11, 0LL);
quicksort_onemalloc(a1, 0LL, a2 - 1, 4LL, a5, 0LL);
gettimeofday(&tv, 0LL);
}
return printtime(&v11, &tv);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2, __int64 a3, __int64 (__fastcall **a4)(_QWORD, _QWORD, _QWORD, _QWORD), void *a5)
{
const char *v8; // rdx
struct timeval v11; // [rsp+0h] [rbp-58h] BYREF
struct timeval tv; // [rsp+10h] [rbp-48h] BYREF

v8 = "asc";
if ( a5 != &int_compare_asc )
v8 = "desc";
printf("Sorting %s, int %s: ", a3, v8);
fflush(stdout);
if ( a4 == &bubblesort )
{
gettimeofday(&v11, 0LL);
bubblesort(a1, a2, 4LL, a5);
goto LABEL_11;
}
if ( a4 == &mergesort )
{
gettimeofday(&v11, 0LL);
mergesort(a1, a2, 4LL, a5);
goto LABEL_11;
}
if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc )
{
gettimeofday(&v11, 0LL);
mergesort_onemalloc(a1, a2, 4LL, a5, 0LL);
goto LABEL_11;
}
if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort )
{
gettimeofday(&v11, 0LL);
quicksort(a1, 0LL, a2 - 1, 4LL, a5);
LABEL_11:
gettimeofday(&tv, 0LL);
return func0(&v11, &tv);
}
if ( a4 == (__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc )
{
gettimeofday(&v11, 0LL);
quicksort_onemalloc(a1, 0LL, a2 - 1, 4LL, a5, 0LL);
gettimeofday(&tv, 0LL);
}
return func0(&v11, &tv);
}

original_code:
int do_int_sort(int * numbers, int len, char * name, void * func,
                compare_func comp)
{
    struct timeval start, end;
    printf("Sorting %s, int %s: ", name,
           (comp == &int_compare_asc? "asc" : "desc"));
    fflush(stdout);
    if(func == &bubblesort)
    {
        gettimeofday(&start, ((void *)0));
        bubblesort(numbers, len, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &mergesort)
    {
        gettimeofday(&start, ((void *)0));
        mergesort(numbers, len, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &mergesort_onemalloc)
    {
        gettimeofday(&start, ((void *)0));
        mergesort_onemalloc(numbers, len, sizeof(int), comp, ((void *)0));
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &quicksort)
    {
        gettimeofday(&start, ((void *)0));
        quicksort(numbers, 0, len-1, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &quicksort_onemalloc)
    {
        gettimeofday(&start, ((void *)0));
        quicksort_onemalloc(numbers, 0, len-1, sizeof(int), comp, ((void *)0));
        gettimeofday(&end, ((void *)0));
    }
    printtime(&start, &end);
}

canonical_original_code:
int do_int_sort(int *numbers, int len, char *name, void *func, int (*comp)(void *first, void *second))
{
    struct timeval start; struct timeval end;
    printf("Sorting %s, int %s: ", name,
           (comp == &int_compare_asc? "asc" : "desc"));
    fflush(stdout);
    if(func == &bubblesort)
    {
        gettimeofday(&start, ((void *)0));
        bubblesort(numbers, len, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &mergesort)
    {
        gettimeofday(&start, ((void *)0));
        mergesort(numbers, len, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &mergesort_onemalloc)
    {
        gettimeofday(&start, ((void *)0));
        mergesort_onemalloc(numbers, len, sizeof(int), comp, ((void *)0));
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &quicksort)
    {
        gettimeofday(&start, ((void *)0));
        quicksort(numbers, 0, len-1, sizeof(int), comp);
        gettimeofday(&end, ((void *)0));
    }
    else if(func == &quicksort_onemalloc)
    {
        gettimeofday(&start, ((void *)0));
        quicksort_onemalloc(numbers, 0, len-1, sizeof(int), comp, ((void *)0));
        gettimeofday(&end, ((void *)0));
    }
    printtime(&start, &end);
}

variable_types:
name
char *

variable_types:
func
void *

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // r14
int v5; // er12
void *v6; // rax
void *v7; // rbp
_DWORD *v8; // rbx
__int64 v9; // r13
unsigned int v11; // eax

if ( argc == 3 )
{
v4 = argv[2];
printf("Limiting algorithm to %s\n", v4);
v11 = time(0LL);
srand(v11);
goto LABEL_4;
}
v3 = time(0LL);
srand(v3);
if ( argc > 1 )
{
v4 = 0LL;
LABEL_4:
v5 = atoi(argv[1]);
goto LABEL_5;
}
v4 = 0LL;
v5 = rand() % 100000;
LABEL_5:
printf("Generating array of %d random int's\n", (unsigned int)v5);
v6 = malloc(4LL * v5);
v7 = v6;
if ( v6 )
{
if ( v5 > 0 )
{
v8 = v6;
v9 = (__int64)v6 + 4 * (unsigned int)(v5 - 1) + 4;
do
*v8++ = rand();
while ( (_DWORD *)v9 != v8 );
}
if ( v4 )
{
if ( !strcmp(v4, "bubble") )
{
do_int_sort((__int64)v7, v5, (__int64)"bubblesort", &bubblesort, &int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort((__int64)v7, v5, (__int64)"bubblesort", &bubblesort, &int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "merge") )
{
do_int_sort((__int64)v7, v5, (__int64)"mergesort", &mergesort, &int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort((__int64)v7, v5, (__int64)"mergesort", &mergesort, &int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "mone") )
{
do_int_sort(
(__int64)v7,
v5,
(__int64)"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
(__int64)"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "quick") )
{
do_int_sort(
(__int64)v7,
v5,
(__int64)"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
(__int64)"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
if ( strcmp(v4, "qone") )
goto LABEL_19;
}
else
{
do_int_sort((__int64)v7, v5, (__int64)"bubblesort", &bubblesort, &int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort((__int64)v7, v5, (__int64)"bubblesort", &bubblesort, &int_compare_desc);
verify_sort((__int64)v7, v5, 0);
do_int_sort((__int64)v7, v5, (__int64)"mergesort", &mergesort, &int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort((__int64)v7, v5, (__int64)"mergesort", &mergesort, &int_compare_desc);
verify_sort((__int64)v7, v5, 0);
do_int_sort(
(__int64)v7,
v5,
(__int64)"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
(__int64)"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
do_int_sort(
(__int64)v7,
v5,
(__int64)"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
(__int64)"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
}
do_int_sort(
(__int64)v7,
v5,
(__int64)"quicksort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc,
&int_compare_asc);
verify_sort((__int64)v7, v5, 1);
do_int_sort(
(__int64)v7,
v5,
(__int64)"quicksort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc,
&int_compare_desc);
verify_sort((__int64)v7, v5, 0);
LABEL_19:
free(v7);
return 0;
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
const char *v4; // r14
int v5; // er12
void *v6; // rax
void *v7; // rbp
_DWORD *v8; // rbx
__int64 v9; // r13
unsigned int v11; // eax

if ( argc == 3 )
{
v4 = argv[2];
printf("Limiting algorithm to %s\n", v4);
v11 = time(0LL);
srand(v11);
goto LABEL_4;
}
v3 = time(0LL);
srand(v3);
if ( argc > 1 )
{
v4 = 0LL;
LABEL_4:
v5 = atoi(argv[1]);
goto LABEL_5;
}
v4 = 0LL;
v5 = rand() % 100000;
LABEL_5:
printf("Generating array of %d random int's\n", (unsigned int)v5);
v6 = malloc(4LL * v5);
v7 = v6;
if ( v6 )
{
if ( v5 > 0 )
{
v8 = v6;
v9 = (__int64)v6 + 4 * (unsigned int)(v5 - 1) + 4;
do
*v8++ = rand();
while ( (_DWORD *)v9 != v8 );
}
if ( v4 )
{
if ( !strcmp(v4, "bubble") )
{
func2((__int64)v7, v5, (__int64)"bubblesort", &bubblesort, &int_compare_asc);
func1((__int64)v7, v5, 1);
func2((__int64)v7, v5, (__int64)"bubblesort", &bubblesort, &int_compare_desc);
func1((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "merge") )
{
func2((__int64)v7, v5, (__int64)"mergesort", &mergesort, &int_compare_asc);
func1((__int64)v7, v5, 1);
func2((__int64)v7, v5, (__int64)"mergesort", &mergesort, &int_compare_desc);
func1((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "mone") )
{
func2(
(__int64)v7,
v5,
(__int64)"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
(__int64)"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_desc);
func1((__int64)v7, v5, 0);
}
if ( !strcmp(v4, "quick") )
{
func2(
(__int64)v7,
v5,
(__int64)"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
(__int64)"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_desc);
func1((__int64)v7, v5, 0);
}
if ( strcmp(v4, "qone") )
goto LABEL_19;
}
else
{
func2((__int64)v7, v5, (__int64)"bubblesort", &bubblesort, &int_compare_asc);
func1((__int64)v7, v5, 1);
func2((__int64)v7, v5, (__int64)"bubblesort", &bubblesort, &int_compare_desc);
func1((__int64)v7, v5, 0);
func2((__int64)v7, v5, (__int64)"mergesort", &mergesort, &int_compare_asc);
func1((__int64)v7, v5, 1);
func2((__int64)v7, v5, (__int64)"mergesort", &mergesort, &int_compare_desc);
func1((__int64)v7, v5, 0);
func2(
(__int64)v7,
v5,
(__int64)"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
(__int64)"mergesort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&mergesort_onemalloc,
&int_compare_desc);
func1((__int64)v7, v5, 0);
func2(
(__int64)v7,
v5,
(__int64)"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
(__int64)"quicksort",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort,
&int_compare_desc);
func1((__int64)v7, v5, 0);
}
func2(
(__int64)v7,
v5,
(__int64)"quicksort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc,
&int_compare_asc);
func1((__int64)v7, v5, 1);
func2(
(__int64)v7,
v5,
(__int64)"quicksort_onemalloc",
(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))&quicksort_onemalloc,
&int_compare_desc);
func1((__int64)v7, v5, 0);
LABEL_19:
free(v7);
return 0;
}
return 1;
}

original_code:
int main(int argc, char ** argv)
{
    int * numbers;
    int len, i;
    char * algo = ((void *)0);
    if(argc == 3)
    {
        algo = argv[2];
        printf("Limiting algorithm to %s\n", algo);
    }
    srand(time(((void *)0)));
    if(argc >= 2)
        len = atoi(argv[1]);
    else
    {
        len = rand() % 100000;
    }
    printf("Generating array of %d random int's\n", len);
    numbers = malloc(sizeof(int) * len);
    if(!numbers)
        return 1;
    for(i = 0; i < len; i++)
        numbers[i] = rand();
    if(algo == ((void *)0) || strcmp(algo, "bubble") == 0)
    {
        do_int_sort(numbers, len, "bubblesort",
                    &bubblesort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "bubblesort",
                    &bubblesort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "merge") == 0)
    {
        do_int_sort(numbers, len, "mergesort",
                    &mergesort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "mergesort",
                    &mergesort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "mone") == 0)
    {
        do_int_sort(numbers, len, "mergesort_onemalloc",
                    &mergesort_onemalloc, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "mergesort_onemalloc",
                    &mergesort_onemalloc, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "quick") == 0)
    {
        do_int_sort(numbers, len, "quicksort",
                    &quicksort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "quicksort",
                    &quicksort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "qone") == 0)
    {
        do_int_sort(numbers, len, "quicksort_onemalloc",
                    &quicksort_onemalloc, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "quicksort_onemalloc",
                    &quicksort_onemalloc, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    free(numbers);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    int *numbers;
    int len; int i;
    char *algo = ((void *)0);
    if(argc == 3)
    {
        algo = argv[2];
        printf("Limiting algorithm to %s\n", algo);
    }
    srand(time(((void *)0)));
    if(argc >= 2)
        len = atoi(argv[1]);
    else
    {
        len = rand() % 100000;
    }
    printf("Generating array of %d random int's\n", len);
    numbers = malloc(sizeof(int) * len);
    if(!numbers)
        return 1;
    for(i = 0; i < len; i++)
        numbers[i] = rand();
    if(algo == ((void *)0) || strcmp(algo, "bubble") == 0)
    {
        do_int_sort(numbers, len, "bubblesort",
                    &bubblesort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "bubblesort",
                    &bubblesort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "merge") == 0)
    {
        do_int_sort(numbers, len, "mergesort",
                    &mergesort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "mergesort",
                    &mergesort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "mone") == 0)
    {
        do_int_sort(numbers, len, "mergesort_onemalloc",
                    &mergesort_onemalloc, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "mergesort_onemalloc",
                    &mergesort_onemalloc, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "quick") == 0)
    {
        do_int_sort(numbers, len, "quicksort",
                    &quicksort, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "quicksort",
                    &quicksort, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    if(algo == ((void *)0) || strcmp(algo, "qone") == 0)
    {
        do_int_sort(numbers, len, "quicksort_onemalloc",
                    &quicksort_onemalloc, int_compare_asc);
        verify_sort(numbers, len, 1);
        do_int_sort(numbers, len, "quicksort_onemalloc",
                    &quicksort_onemalloc, int_compare_desc);
        verify_sort(numbers, len, 0);
    }
    free(numbers);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
algo
char *


merge

original_code:
int merge(void * left, size_t leftsize, void * right, size_t rightsize,
          size_t elem_size, compare_func comp)
{
    char * templist, * temploc, * leftloc, * rightloc;
    size_t tempsize, totalsize;
    templist = malloc((leftsize + rightsize) * elem_size);
    if(!templist)
        return 0;
    leftloc = left;
    rightloc = right;
    temploc = templist;
    tempsize = 0;
    totalsize = leftsize + rightsize;
    while(tempsize < totalsize)
    {
        if(leftsize && rightsize)
        {
            if(comp(leftloc, rightloc) < 0)
            {
                memcpy(temploc, leftloc, elem_size);
                leftloc += elem_size;
                leftsize--;
            }
            else
            {
                memcpy(temploc, rightloc, elem_size);
                rightloc += elem_size;
                rightsize--;
            }
        }
        else if(leftsize)
        {
            memcpy(temploc, leftloc, elem_size);
            leftloc += elem_size;
            leftsize--;
        }
        else if(rightsize)
        {
            memcpy(temploc, rightloc, elem_size);
            rightloc += elem_size;
            rightsize--;
        }
        temploc += elem_size;
        tempsize++;
    }
    memcpy(left, templist, elem_size * totalsize);
    free(templist);
    return 1;
}

canonical_original_code:
int merge(void *left, unsigned long leftsize, void *right, unsigned long rightsize, unsigned long elem_size, int (*comp)(void *first, void *second))
{
    char *templist; char *temploc; char *leftloc; char *rightloc;
    unsigned long tempsize; unsigned long totalsize;
    templist = malloc((leftsize + rightsize) * elem_size);
    if(!templist)
        return 0;
    leftloc = left;
    rightloc = right;
    temploc = templist;
    tempsize = 0;
    totalsize = leftsize + rightsize;
    while(tempsize < totalsize)
    {
        if(leftsize && rightsize)
        {
            if(comp(leftloc, rightloc) < 0)
            {
                memcpy(temploc, leftloc, elem_size);
                leftloc += elem_size;
                leftsize--;
            }
            else
            {
                memcpy(temploc, rightloc, elem_size);
                rightloc += elem_size;
                rightsize--;
            }
        }
        else if(leftsize)
        {
            memcpy(temploc, leftloc, elem_size);
            leftloc += elem_size;
            leftsize--;
        }
        else if(rightsize)
        {
            memcpy(temploc, rightloc, elem_size);
            rightloc += elem_size;
            rightsize--;
        }
        temploc += elem_size;
        tempsize++;
    }
    memcpy(left, templist, elem_size * totalsize);
    free(templist);
    return 1;
}

variable_types:
left
void *

variable_types:
leftsize
unsigned long

variable_types:
right
void *

variable_types:
rightsize
unsigned long

variable_types:
templist
char *

variable_types:
temploc
char *

variable_types:
leftloc
char *

variable_types:
rightloc
char *

variable_types:
tempsize
unsigned long

variable_types:
totalsize
unsigned long


mergesort

decompiled_code:
_BOOL8 __fastcall mergesort(void *src, unsigned __int64 a2, size_t a3, __int64 (__fastcall *a4)(char *, char *))
{
_BOOL8 result; // rax
__int64 v5; // r15

result = 1LL;
if ( a2 > 1 )
{
v5 = a2 >> 1;
if ( (unsigned int)mergesort(src) && (unsigned int)mergesort((char *)src + a3 * v5) )
result = (unsigned int)merge(src, v5, (char *)src + a3 * v5, a2 - v5, a3, a4) != 0;
else
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(void *src, unsigned __int64 a2, size_t a3, __int64 (__fastcall *a4)(char *, char *))
{
_BOOL8 result; // rax
__int64 v5; // r15

result = 1LL;
if ( a2 > 1 )
{
v5 = a2 >> 1;
if ( (unsigned int)func1(src) && (unsigned int)func1((char *)src + a3 * v5) )
result = (unsigned int)func0(src, v5, (char *)src + a3 * v5, a2 - v5, a3, a4) != 0;
else
result = 0LL;
}
return result;
}

original_code:
int mergesort(void * list, size_t nelem, size_t elem_size, compare_func comp)
{
    void * left, * right;
    size_t middle, leftsize, rightsize;
    if(nelem <= 1)
        return 1;
    middle = nelem >> 1;
    left = list;
    leftsize = middle;
    right = list + (middle * elem_size);
    rightsize = nelem - leftsize;
    if(!mergesort(left, leftsize, elem_size, comp))
        return 0;
    if(!mergesort(right, rightsize, elem_size, comp))
        return 0;
    if(!merge(left, leftsize, right, rightsize, elem_size, comp))
        return 0;
    return 1;
}

canonical_original_code:
int mergesort(void *list, unsigned long nelem, unsigned long elem_size, int (*comp)(void *first, void *second))
{
    void *left; void *right;
    unsigned long middle; unsigned long leftsize; unsigned long rightsize;
    if(nelem <= 1)
        return 1;
    middle = nelem >> 1;
    left = list;
    leftsize = middle;
    right = list + (middle * elem_size);
    rightsize = nelem - leftsize;
    if(!mergesort(left, leftsize, elem_size, comp))
        return 0;
    if(!mergesort(right, rightsize, elem_size, comp))
        return 0;
    if(!merge(left, leftsize, right, rightsize, elem_size, comp))
        return 0;
    return 1;
}

variable_types:
list
void *

variable_types:
nelem
unsigned long

variable_types:
middle
unsigned long


original_code:
int merge_nomalloc(void * left, size_t leftsize, void * right, size_t rightsize,
                   size_t elem_size, compare_func comp, char * templist)
{
    char * temploc, * leftloc, * rightloc;
    size_t tempsize, totalsize;
    leftloc = left;
    rightloc = right;
    temploc = templist;
    tempsize = 0;
    totalsize = leftsize + rightsize;
    while(tempsize < totalsize)
    {
        if(leftsize && rightsize)
        {
            if(comp(leftloc, rightloc) < 0)
            {
                memcpy(temploc, leftloc, elem_size);
                leftloc += elem_size;
                leftsize--;
            }
            else
            {
                memcpy(temploc, rightloc, elem_size);
                rightloc += elem_size;
                rightsize--;
            }
        }
        else if(leftsize)
        {
            memcpy(temploc, leftloc, elem_size);
            leftloc += elem_size;
            leftsize--;
        }
        else if(rightsize)
        {
            memcpy(temploc, rightloc, elem_size);
            rightloc += elem_size;
            rightsize--;
        }
        temploc += elem_size;
        tempsize++;
    }
    memcpy(left, templist, elem_size * totalsize);
    return 1;
}

canonical_original_code:
int merge_nomalloc(void *left, unsigned long leftsize, void *right, unsigned long rightsize, unsigned long elem_size, int (*comp)(void *first, void *second), char *templist)
{
    char *temploc; char *leftloc; char *rightloc;
    unsigned long tempsize; unsigned long totalsize;
    leftloc = left;
    rightloc = right;
    temploc = templist;
    tempsize = 0;
    totalsize = leftsize + rightsize;
    while(tempsize < totalsize)
    {
        if(leftsize && rightsize)
        {
            if(comp(leftloc, rightloc) < 0)
            {
                memcpy(temploc, leftloc, elem_size);
                leftloc += elem_size;
                leftsize--;
            }
            else
            {
                memcpy(temploc, rightloc, elem_size);
                rightloc += elem_size;
                rightsize--;
            }
        }
        else if(leftsize)
        {
            memcpy(temploc, leftloc, elem_size);
            leftloc += elem_size;
            leftsize--;
        }
        else if(rightsize)
        {
            memcpy(temploc, rightloc, elem_size);
            rightloc += elem_size;
            rightsize--;
        }
        temploc += elem_size;
        tempsize++;
    }
    memcpy(left, templist, elem_size * totalsize);
    return 1;
}

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


decompiled_code:
__int64 __fastcall mergesort_onemalloc(void *src, unsigned __int64 a2, size_t a3, __int64 (__fastcall *a4)(char *, char *), void *a5)
{
int v5; // er14
void *v7; // rbp
__int64 v10; // r12
unsigned __int64 v11; // [rsp+0h] [rbp-48h]
char *v12; // [rsp+0h] [rbp-48h]

v5 = 0;
v7 = a5;
if ( !a5 )
{
v7 = malloc(a3 * a2);
if ( !v7 )
return 0LL;
v5 = 1;
}
if ( a2 <= 1 )
return 1LL;
v11 = a2 >> 1;
if ( (unsigned int)mergesort_onemalloc(src) )
{
v10 = a2 - v11;
v12 = (char *)src + v11 * a3;
if ( (unsigned int)mergesort_onemalloc(v12) )
{
if ( (unsigned int)merge_nomalloc(src, a2 >> 1, v12, v10, a3, a4, v7) )
{
if ( v5 )
free(v7);
return 1LL;
}
}
}
if ( !v5 )
return 0LL;
free(v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src, unsigned __int64 a2, size_t a3, __int64 (__fastcall *a4)(char *, char *), void *a5)
{
int v5; // er14
void *v7; // rbp
__int64 v10; // r12
unsigned __int64 v11; // [rsp+0h] [rbp-48h]
char *v12; // [rsp+0h] [rbp-48h]

v5 = 0;
v7 = a5;
if ( !a5 )
{
v7 = malloc(a3 * a2);
if ( !v7 )
return 0LL;
v5 = 1;
}
if ( a2 <= 1 )
return 1LL;
v11 = a2 >> 1;
if ( (unsigned int)func3(src) )
{
v10 = a2 - v11;
v12 = (char *)src + v11 * a3;
if ( (unsigned int)func3(v12) )
{
if ( (unsigned int)func2(src, a2 >> 1, v12, v10, a3, a4, v7) )
{
if ( v5 )
free(v7);
return 1LL;
}
}
}
if ( !v5 )
return 0LL;
free(v7);
return 0LL;
}

original_code:
int mergesort_onemalloc(void * list, size_t nelem, size_t elem_size,
                        compare_func comp, char * templist)
{
    void * left, * right;
    size_t middle, leftsize, rightsize;
    unsigned int do_free = 0;
    if(!templist)
    {
        do_free = 1;
        templist = malloc(nelem * elem_size);
        if(!templist)
            return 0;
    }
    if(nelem <= 1)
        return 1;
    middle = nelem >> 1;
    left = list;
    leftsize = middle;
    right = list + (middle * elem_size);
    rightsize = nelem - leftsize;
    if(!mergesort_onemalloc(left, leftsize, elem_size, comp, templist))
        goto free_fail;
    if(!mergesort_onemalloc(right, rightsize, elem_size, comp, templist))
        goto free_fail;
    if(!merge_nomalloc(left, leftsize, right, rightsize, elem_size, comp, templist))
        goto free_fail;
    if(do_free)
        free(templist);
    return 1;
free_fail:
    if(do_free)
        free(templist);
    return 0;
}

canonical_original_code:
int mergesort_onemalloc(void *list, unsigned long nelem, unsigned long elem_size, int (*comp)(void *first, void *second), char *templist)
{
    void *left; void *right;
    unsigned long middle; unsigned long leftsize; unsigned long rightsize;
    unsigned int do_free = 0;
    if(!templist)
    {
        do_free = 1;
        templist = malloc(nelem * elem_size);
        if(!templist)
            return 0;
    }
    if(nelem <= 1)
        return 1;
    middle = nelem >> 1;
    left = list;
    leftsize = middle;
    right = list + (middle * elem_size);
    rightsize = nelem - leftsize;
    if(!mergesort_onemalloc(left, leftsize, elem_size, comp, templist))
        goto free_fail;
    if(!mergesort_onemalloc(right, rightsize, elem_size, comp, templist))
        goto free_fail;
    if(!merge_nomalloc(left, leftsize, right, rightsize, elem_size, comp, templist))
        goto free_fail;
    if(do_free)
        free(templist);
    return 1;
free_fail:
    if(do_free)
        free(templist);
    return 0;
}


quicksort

original_code:
int quicksort(void * list, size_t left, size_t right, size_t esize, compare_func comp)
{
    size_t pivot;
    char * tmp, * leftpos, *rightpos, *pivotpos;
    if(((signed long long)right - (signed long long)left) <= 0)
        return 1;
    tmp = malloc(esize);
    if(!tmp)
        return 0;
    pivot = (left + right) / 2;
    leftpos = (unsigned char*)list + (left*esize);
    rightpos = (unsigned char*)list + (right*esize);
    pivotpos = (unsigned char*)list + (pivot*esize);
    while(leftpos <= pivotpos && rightpos >= pivotpos)
    {
        while(comp(leftpos, pivotpos) < 0 && leftpos <= pivotpos)
            leftpos += esize;
        while(comp(rightpos, pivotpos) > 0 && rightpos >= pivotpos)
            rightpos -= esize;
        if(leftpos != rightpos)
        {
            memcpy(tmp, leftpos, esize);
            memcpy(leftpos, rightpos, esize);
            memcpy(rightpos, tmp, esize);
        }
        leftpos += esize;
        rightpos -= esize;
        if(leftpos - esize == pivotpos)
            pivotpos = rightpos = rightpos + esize;
        else if(rightpos+esize == pivotpos)
            pivotpos = leftpos = leftpos - esize;
    }
    pivot = (pivotpos - (char*)list)/esize;
    quicksort(list, left, pivot - 1, esize, comp);
    quicksort(list, pivot + 1, right, esize, comp);
    free(tmp);
    return 1;
}

canonical_original_code:
int quicksort(void *list, unsigned long left, unsigned long right, unsigned long esize, int (*comp)(void *first, void *second))
{
    unsigned long pivot;
    char *tmp; char *leftpos; char *rightpos; char *pivotpos;
    if(((long long)right - (long long)left) <= 0)
        return 1;
    tmp = malloc(esize);
    if(!tmp)
        return 0;
    pivot = (left + right) / 2;
    leftpos = (unsigned char *)list + (left*esize);
    rightpos = (unsigned char *)list + (right*esize);
    pivotpos = (unsigned char *)list + (pivot*esize);
    while(leftpos <= pivotpos && rightpos >= pivotpos)
    {
        while(comp(leftpos, pivotpos) < 0 && leftpos <= pivotpos)
            leftpos += esize;
        while(comp(rightpos, pivotpos) > 0 && rightpos >= pivotpos)
            rightpos -= esize;
        if(leftpos != rightpos)
        {
            memcpy(tmp, leftpos, esize);
            memcpy(leftpos, rightpos, esize);
            memcpy(rightpos, tmp, esize);
        }
        leftpos += esize;
        rightpos -= esize;
        if(leftpos - esize == pivotpos)
            pivotpos = rightpos = rightpos + esize;
        else if(rightpos+esize == pivotpos)
            pivotpos = leftpos = leftpos - esize;
    }
    pivot = (pivotpos - (char *)list)/esize;
    quicksort(list, left, pivot - 1, esize, comp);
    quicksort(list, pivot + 1, right, esize, comp);
    free(tmp);
    return 1;
}

variable_types:
left
unsigned long

variable_types:
right
unsigned long

variable_types:
esize
unsigned long

variable_types:
pivot
unsigned long

variable_types:
tmp
char *

variable_types:
leftpos
char *

variable_types:
rightpos
char *

variable_types:
pivotpos
char *


original_code:
int quicksort_onemalloc(void * list, size_t left, size_t right,
                        size_t esize, compare_func comp, char * tmp)
{
    size_t pivot;
    char * leftpos, *rightpos, *pivotpos;
    int do_free = 0;
    if(((signed long long)right - (signed long long)left) <= 0)
        return 1;
    if(!tmp)
    {
        tmp = malloc(esize);
        if(!tmp)
            return 0;
        do_free = 1;
    }
    pivot = (left + right) / 2;
    leftpos = (unsigned char*)list + (left*esize);
    rightpos = (unsigned char*)list + (right*esize);
    pivotpos = (unsigned char*)list + (pivot*esize);
    while(leftpos <= pivotpos && rightpos >= pivotpos)
    {
        while(comp(leftpos, pivotpos) < 0 && leftpos <= pivotpos)
            leftpos += esize;
        while(comp(rightpos, pivotpos) > 0 && rightpos >= pivotpos)
            rightpos -= esize;
        if(leftpos != rightpos)
        {
            memcpy(tmp, leftpos, esize);
            memcpy(leftpos, rightpos, esize);
            memcpy(rightpos, tmp, esize);
        }
        leftpos += esize;
        rightpos -= esize;
        if(leftpos - esize == pivotpos)
            pivotpos = rightpos = rightpos + esize;
        else if(rightpos+esize == pivotpos)
            pivotpos = leftpos = leftpos - esize;
    }
    pivot = (pivotpos - (char*)list)/esize;
    quicksort_onemalloc(list, left, pivot - 1, esize, comp, tmp);
    quicksort_onemalloc(list, pivot + 1, right, esize, comp, tmp);
    if(do_free)
        free(tmp);
    return 1;
}

canonical_original_code:
int quicksort_onemalloc(void *list, unsigned long left, unsigned long right, unsigned long esize, int (*comp)(void *first, void *second), char *tmp)
{
    unsigned long pivot;
    char *leftpos; char *rightpos; char *pivotpos;
    int do_free = 0;
    if(((long long)right - (long long)left) <= 0)
        return 1;
    if(!tmp)
    {
        tmp = malloc(esize);
        if(!tmp)
            return 0;
        do_free = 1;
    }
    pivot = (left + right) / 2;
    leftpos = (unsigned char *)list + (left*esize);
    rightpos = (unsigned char *)list + (right*esize);
    pivotpos = (unsigned char *)list + (pivot*esize);
    while(leftpos <= pivotpos && rightpos >= pivotpos)
    {
        while(comp(leftpos, pivotpos) < 0 && leftpos <= pivotpos)
            leftpos += esize;
        while(comp(rightpos, pivotpos) > 0 && rightpos >= pivotpos)
            rightpos -= esize;
        if(leftpos != rightpos)
        {
            memcpy(tmp, leftpos, esize);
            memcpy(leftpos, rightpos, esize);
            memcpy(rightpos, tmp, esize);
        }
        leftpos += esize;
        rightpos -= esize;
        if(leftpos - esize == pivotpos)
            pivotpos = rightpos = rightpos + esize;
        else if(rightpos+esize == pivotpos)
            pivotpos = leftpos = leftpos - esize;
    }
    pivot = (pivotpos - (char *)list)/esize;
    quicksort_onemalloc(list, left, pivot - 1, esize, comp, tmp);
    quicksort_onemalloc(list, pivot + 1, right, esize, comp, tmp);
    if(do_free)
        free(tmp);
    return 1;
}


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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

original_code:
int int_compare_asc(const void * first, const void * second)
{
    int a = *(int*)first;
    int b = *(int*)second;
    if(a == b) return 0;
    return (a < b ? -1 : 1);
}

canonical_original_code:
int int_compare_asc(void *first, void *second)
{
    int a = *(int*)first;
    int b = *(int*)second;
    if(a == b) return 0;
    return (a < b ? -1 : 1);
}

variable_types:
first
void *

variable_types:
second
void *

variable_types: a int

variable_types: b int


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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 <= *a2) - 1;
return result;
}

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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 <= *a2) - 1;
return result;
}

original_code:
int int_compare_desc(const void * first, const void * second)
{
    int a = *(int*)first;
    int b = *(int*)second;
    if(a == b) return 0;
    return (a > b ? -1 : 1);
}

canonical_original_code:
int int_compare_desc(void *first, void *second)
{
    int a = *(int*)first;
    int b = *(int*)second;
    if(a == b) return 0;
    return (a > b ? -1 : 1);
}


decompiled_code:
__int64 __fastcall char_compare_asc(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

original_code:
int char_compare_asc(const void * first, const void * second)
{
    char a = *(char*)first;
    char b = *(char*)second;
    if(a == b) return 0;
    return (a < b ? -1 : 1);
}

canonical_original_code:
int char_compare_asc(void *first, void *second)
{
    char a = *(char*)first;
    char b = *(char*)second;
    if(a == b) return 0;
    return (a < b ? -1 : 1);
}

variable_types: a char

variable_types: b char


decompiled_code:
__int64 __fastcall char_compare_desc(_BYTE *a1, _BYTE *a2)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 <= *a2) - 1;
return result;
}

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

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 <= *a2) - 1;
return result;
}

original_code:
int char_compare_desc(const void * first, const void * second)
{
    char a = *(char*)first;
    char b = *(char*)second;
    if(a == b) return 0;
    return (a > b ? -1 : 1);
}

canonical_original_code:
int char_compare_desc(void *first, void *second)
{
    char a = *(char*)first;
    char b = *(char*)second;
    if(a == b) return 0;
    return (a > b ? -1 : 1);
}


bubblesort

decompiled_code:
__int64 __fastcall bubblesort(char *a1, int a2, size_t a3, int (__fastcall *a4)(void *, char *))
{
void *v5; // rax
void *v6; // r13
int v7; // ebp
int v9; // er15
void *v10; // r12

v5 = malloc(a3);
if ( !v5 )
return 0LL;
v6 = v5;
do
{
v7 = a2 - 1;
if ( a2 - 1 <= 0 )
break;
a2 = 0;
v9 = 0;
do
{
v10 = a1;
a1 += a3;
++v9;
if ( a4(v10, a1) > 0 )
{
memcpy(v6, v10, a3);
memcpy(v10, a1, a3);
memcpy(a1, v6, a3);
a2 = v9;
}
}
while ( v7 != v9 );
}
while ( a2 > 1 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2, size_t a3, int (__fastcall *a4)(void *, char *))
{
void *v5; // rax
void *v6; // r13
int v7; // ebp
int v9; // er15
void *v10; // r12

v5 = malloc(a3);
if ( !v5 )
return 0LL;
v6 = v5;
do
{
v7 = a2 - 1;
if ( a2 - 1 <= 0 )
break;
a2 = 0;
v9 = 0;
do
{
v10 = a1;
a1 += a3;
++v9;
if ( a4(v10, a1) > 0 )
{
memcpy(v6, v10, a3);
memcpy(v10, a1, a3);
memcpy(a1, v6, a3);
a2 = v9;
}
}
while ( v7 != v9 );
}
while ( a2 > 1 );
return 1LL;
}

original_code:
int bubblesort(void * list, size_t nelem, size_t elem_size, compare_func comp)
{
    int remain, new_remain, i;
    char * cur_memloc, * swapmem;
    swapmem = malloc(elem_size);
    if(!swapmem)
        return 0;
    remain = nelem;
    do
    {
        new_remain = 0;
        for(i = 0; i < remain - 1; i++)
        {
            cur_memloc = list + (i*elem_size);
            if(comp(cur_memloc, cur_memloc + elem_size) > 0)
            {
                memcpy(swapmem, cur_memloc, elem_size);
                memcpy(cur_memloc, cur_memloc + elem_size, elem_size);
                memcpy(cur_memloc + elem_size, swapmem, elem_size);
                new_remain = i + 1;
            }
        }
        remain = new_remain;
    } while(remain > 1);
    return 1;
}

canonical_original_code:
int bubblesort(void *list, unsigned long nelem, unsigned long elem_size, int (*comp)(void *first, void *second))
{
    int remain; int new_remain; int i;
    char *cur_memloc; char *swapmem;
    swapmem = malloc(elem_size);
    if(!swapmem)
        return 0;
    remain = nelem;
    do
    {
        new_remain = 0;
        for(i = 0; i < remain - 1; i++)
        {
            cur_memloc = list + (i*elem_size);
            if(comp(cur_memloc, cur_memloc + elem_size) > 0)
            {
                memcpy(swapmem, cur_memloc, elem_size);
                memcpy(cur_memloc, cur_memloc + elem_size, elem_size);
                memcpy(cur_memloc + elem_size, swapmem, elem_size);
                new_remain = i + 1;
            }
        }
        remain = new_remain;
    } while(remain > 1);
    return 1;
}

variable_types:
list
void *

variable_types:
nelem
unsigned long

variable_types: remain int

variable_types: i int

variable_types:
swapmem
char *


isop

decompiled_code:
unsigned __int64 __fastcall isop(char a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( (unsigned __int8)(a1 - 42) <= 0x34u )
result = (0x1000000000002BuLL >> (a1 - 42)) & 1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(char a1)
{
unsigned __int64 result; // rax

result = 0LL;
if ( (unsigned __int8)(a1 - 42) <= 0x34u )
result = (0x1000000000002BuLL >> (a1 - 42)) & 1;
return result;
}

variable_types: c char


assoc

decompiled_code:
__int64 __fastcall assoc(char a1)
{
return 2 * (unsigned int)(a1 == 94) - 1;
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
return 2 * (unsigned int)(a1 == 94) - 1;
}

original_code:
int assoc(char c) {
    if(c == '^')
        return 1;
    else
        return -1;
}


prec

original_code:
int prec(char a, char b) {
    int av, bv;
    if(a == b)
        return 0;
    switch(a) {
        case '+':
            av = 0;
            break;
        case '-':
            av = 0;
            break;
        case '*':
            av = 1;
            break;
        case '/':
            av = 1;
            break;
        case '^':
            av = 2;
            break;
    }
    switch(b) {
        case '+':
            bv = 0;
            break;
        case '-':
            bv = 0;
            break;
        case '*':
            bv = 1;
            break;
        case '/':
            bv = 1;
            break;
        case '^':
            bv = 2;
            break;
    }
    if(av == bv)
        return 0;
    else if(av < bv)
        return -1;
    else
        return 1;
}

canonical_original_code:
int prec(char a, char b) {
    int av; int bv;
    if(a == b)
        return 0;
    switch(a) {
        case '+':
            av = 0;
            break;
        case '-':
            av = 0;
            break;
        case '*':
            av = 1;
            break;
        case '/':
            av = 1;
            break;
        case '^':
            av = 2;
            break;
    }
    switch(b) {
        case '+':
            bv = 0;
            break;
        case '-':
            bv = 0;
            break;
        case '*':
            bv = 1;
            break;
        case '/':
            bv = 1;
            break;
        case '^':
            bv = 2;
            break;
    }
    if(av == bv)
        return 0;
    else if(av < bv)
        return -1;
    else
        return 1;
}

variable_types: av int

variable_types: bv int


push

decompiled_code:
__int64 __fastcall push(char a1)
{
__int64 result; // rax
int v2; // edx

result = i;
v2 = i + 1;
stack[i] = a1;
i = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char a1)
{
__int64 result; // rax
int v2; // edx

result = i;
v2 = i + 1;
stack[i] = a1;
i = v2;
return result;
}

original_code:
void push(char c) {
    stack[i++] = c;
}

canonical_original_code:
void push(char c) {
    stack[i++] = c;
}


pop

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

v0 = i;
if ( !i )
return 0xFFFFFFFFLL;
--i;
return (unsigned __int8)stack[v0 - 1];
}

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

v0 = i;
if ( !i )
return 0xFFFFFFFFLL;
--i;
return (unsigned __int8)stack[v0 - 1];
}

original_code:
char pop(void) {
    if(!i)
        return (-1);
    return stack[--i];
}

canonical_original_code:
char pop() {
    if(!i)
        return (-1);
    return stack[--i];
}

return_type: char


top

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

if ( i )
result = (unsigned __int8)stack[i - 1];
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( i )
result = (unsigned __int8)stack[i - 1];
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
char top(void) {
    if(!i)
        return (-1);
    return stack[i - 1];
}

canonical_original_code:
char top() {
    if(!i)
        return (-1);
    return stack[i - 1];
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3; // bl
char *v4; // rbp
unsigned int v5; // er12
__int64 v6; // rdi
char v7; // al
int v8; // ebx
char v9; // al
__int64 v10; // rsi

while ( 1 )
{
fgets(&buffer, 0x100000, _bss_start);
v3 = buffer;
if ( buffer )
{
v4 = (char *)&unk_504081;
while ( v3 != 10 )
{
if ( v3 == 32 )
goto LABEL_7;
v5 = v3;
v6 = (unsigned int)v3;
if ( ((*__ctype_b_loc())[v3] & 8) != 0 || v3 == 46 )
{
putchar(v6);
v3 = *v4++;
if ( !v3 )
break;
}
else
{
if ( (unsigned int)((__int64 (*)(void))isop)() )
{
putchar(32);
v8 = assoc((unsigned int)v3);
while ( 1 )
{
v10 = (unsigned int)(char)((__int64 (*)(void))top)();
if ( (unsigned int)isop(v10) && v8 == -1 )
{
if ( (unsigned int)prec(v5) + 1 > 1 )
goto LABEL_26;
}
else if ( v8 != 1 || (unsigned int)prec(v5) != -1 )
{
LABEL_26:
push(v5);
goto LABEL_7;
}
v9 = pop();
putchar(v9);
putchar(32);
}
}
if ( v3 == 40 )
{
push(40LL);
}
else if ( v3 == 41 )
{
while ( (unsigned __int8)top(v6) != 40 )
{
putchar(32);
v6 = (unsigned int)(char)pop();
putchar(v6);
}
pop();
}
LABEL_7:
v3 = *v4++;
if ( !v3 )
break;
}
}
}
while ( 1 )
{
putchar(32);
if ( (unsigned __int8)top(32LL) == 0xFF )
break;
v7 = pop();
putchar(v7);
}
putchar(10);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3; // bl
char *v4; // rbp
unsigned int v5; // er12
__int64 v6; // rdi
char v7; // al
int v8; // ebx
char v9; // al
__int64 v10; // rsi

while ( 1 )
{
fgets(&buffer, 0x100000, _bss_start);
v3 = buffer;
if ( buffer )
{
v4 = (char *)&unk_504081;
while ( v3 != 10 )
{
if ( v3 == 32 )
goto LABEL_7;
v5 = v3;
v6 = (unsigned int)v3;
if ( ((*__ctype_b_loc())[v3] & 8) != 0 || v3 == 46 )
{
putchar(v6);
v3 = *v4++;
if ( !v3 )
break;
}
else
{
if ( (unsigned int)((__int64 (*)(void))isop)() )
{
putchar(32);
v8 = func8((unsigned int)v3);
while ( 1 )
{
v10 = (unsigned int)(char)((__int64 (*)(void))top)();
if ( (unsigned int)func7(v10) && v8 == -1 )
{
if ( (unsigned int)func9(v5) + 1 > 1 )
goto LABEL_26;
}
else if ( v8 != 1 || (unsigned int)func9(v5) != -1 )
{
LABEL_26:
func10(v5);
goto LABEL_7;
}
v9 = func11();
putchar(v9);
putchar(32);
}
}
if ( v3 == 40 )
{
func10(40LL);
}
else if ( v3 == 41 )
{
while ( (unsigned __int8)func12(v6) != 40 )
{
putchar(32);
v6 = (unsigned int)(char)func11();
putchar(v6);
}
func11();
}
LABEL_7:
v3 = *v4++;
if ( !v3 )
break;
}
}
}
while ( 1 )
{
putchar(32);
if ( (unsigned __int8)func12(32LL) == 0xFF )
break;
v7 = func11();
putchar(v7);
}
putchar(10);
}
}

original_code:
int main(void) {
    int i;
    char token;
    for(;;) {
        fgets(buffer, 1048576, stdin);
        for(i = 0; (token = buffer[i]) != '\n' && buffer[i] != '\0'; i++) {
            if(token == ' ')
                continue;
            if(((*__ctype_b_loc ())[(int) ((token))] & (unsigned short int) _ISalnum) || token == '.')
                putchar(token);
            else if(isop(token)) {
                putchar(' ');
                while(isop(top()) &&
                    (assoc(token) == -1 && (prec(token, top()) == -1 || prec(token, top()) == 0)) ||
                    (assoc(token) == 1 && prec(token, top()) == -1)) {
                        putchar(pop());
                        putchar(' ');
                }
                push(token);
            }
            else if(token == '(')
                push(token);
            else if(token == ')') {
                while(top() != '(') {
                    putchar(' ');
                    putchar(pop());
                }
                pop();
            }
        }
        putchar(' ');
        while(top() != (-1)) {
            putchar(pop());
            putchar(' ');
        }
        putchar('\n');
    }
    return 0;
}

canonical_original_code:
int main() {
    int i;
    char token;
    for(;;) {
        fgets(buffer, 1048576, stdin);
        for(i = 0; (token = buffer[i]) != '\n' && buffer[i] != '\0'; i++) {
            if(token == ' ')
                continue;
            if(((*__ctype_b_loc ())[(int) ((token))] & (unsigned short) _ISalnum) || token == '.')
                putchar(token);
            else if(isop(token)) {
                putchar(' ');
                while(isop(top()) &&
                    (assoc(token) == -1 && (prec(token, top()) == -1 || prec(token, top()) == 0)) ||
                    (assoc(token) == 1 && prec(token, top()) == -1)) {
                        putchar(pop());
                        putchar(' ');
                }
                push(token);
            }
            else if(token == '(')
                push(token);
            else if(token == ')') {
                while(top() != '(') {
                    putchar(' ');
                    putchar(pop());
                }
                pop();
            }
        }
        putchar(' ');
        while(top() != (-1)) {
            putchar(pop());
            putchar(' ');
        }
        putchar('\n');
    }
    return 0;
}

variable_types: token char


decompiled_code:
__int64 __fastcall compare_semis(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 >= *(_QWORD *)a2 )
result = *(_QWORD *)a1 != *(_QWORD *)a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 >= *(_QWORD *)a2 )
result = *(_QWORD *)a1 != *(_QWORD *)a2;
return result;
}

original_code:
int compare_semis(const void *a, const void *b)
{
 const u_long_64 *aa = a, *bb = b;
 if(*aa < *bb)
  return -1;
 else
  return (*aa == *bb) ? 0 : 1;
}

canonical_original_code:
int compare_semis(void *a, void *b)
{
 unsigned long long *aa = a; unsigned long long *bb = b;
 if(*aa < *bb)
  return -1;
 else
  return (*aa == *bb) ? 0 : 1;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
aa
unsigned long long *

variable_types:
bb
unsigned long long *


semiprimegen

original_code:
u_long_64 *semiprimegen(u_long_64 first_range, u_long_64 second_range, u_long_64 *semiprimes_count)
{
 _Bool prime=1, store_2 = 1;
 u_long_64 number_to_check, prime_range, file_linecount=2;
 u_long_64 i, x, y, z;
 u_long_64 *primes_address = ((void *)0), *semi_prime_address = ((void *)0);
 u_long_64 prime_count = 0;
 u_long_64 buff_mult = 1;
 u_long_64 semi_prime = 0;
 int perc = 0;
 prime_range = second_range / 2;
 printf("Generating Primes...\n");
 fpurge(stdout);
 progress(0, 0);
 for(number_to_check=3; number_to_check <= prime_range; number_to_check+=2)
 {
  prime = 1;
  if(store_2)
  {
   primes_address = (u_long_64 *)malloc(sizeof(u_long_64) * 1000000);
   *primes_address = 2;
   prime_count = 1;
   store_2 = 0;
  }
  for(i=3; i*i <= number_to_check; i+=2)
  {
   if(number_to_check % i == 0)
   {
    prime = 0;
    break;
   }
  }
  if(prime)
  {
   prime_count++;
   if(prime_count >= 1000000 * buff_mult)
   {
    buff_mult++;
    primes_address = (u_long_64 *)realloc(primes_address, (sizeof(u_long_64) * 1000000 * buff_mult));
   }
   *(primes_address + prime_count-1) = number_to_check;
  }
  if( (perc+1) <= (int)(100.0 * number_to_check / prime_range)) {
   perc = (int)(100.0 * number_to_check / prime_range);
   progress(0, perc);
  }
 }
 progress(0,100);
 printf("\n\n");
 printf("Generating Semiprimes...\n");
 fpurge(stdout);
 progress(0, 0);
 *semiprimes_count = buff_mult = perc = 0;
 for(y=0; y<prime_count; y++)
 {
  for(z=y; z<prime_count; z++)
  {
   semi_prime = (*(primes_address + y)) * (*(primes_address + z));
   if(semi_prime < first_range)
    continue;
   else if(semi_prime > second_range)
    break;
   else
   {
    (*semiprimes_count)++;
    if(*semiprimes_count >= 1000000 * buff_mult)
    {
     buff_mult++;
     semi_prime_address = (u_long_64 *)realloc(semi_prime_address, (sizeof(u_long_64) * 1000000 * buff_mult));
    }
    *(semi_prime_address + (*semiprimes_count)-1) = semi_prime;
   }
  }
  if(y == z)
   break;
 }
 free(primes_address);
 progress(0, 100);
 printf("\n\n");
 printf("Sorting Semiprimes...\n");
 fpurge(stdout);
 progress(0, 0);
 qsort(semi_prime_address, *semiprimes_count, sizeof(u_long_64), compare_semis);
 progress(0, 100);
 printf("\n");
 fpurge(stdout);
 return semi_prime_address;
}

canonical_original_code:
unsigned long long *semiprimegen(unsigned long long first_range, unsigned long long second_range, unsigned long long *semiprimes_count)
{
 _Bool prime = 1; _Bool store_2 = 1;
 unsigned long long number_to_check; unsigned long long prime_range; unsigned long long file_linecount = 2;
 unsigned long long i; unsigned long long x; unsigned long long y; unsigned long long z;
 unsigned long long *primes_address = ((void *)0); unsigned long long *semi_prime_address = ((void *)0);
 unsigned long long prime_count = 0;
 unsigned long long buff_mult = 1;
 unsigned long long semi_prime = 0;
 int perc = 0;
 prime_range = second_range / 2;
 printf("Generating Primes...\n");
 fpurge(stdout);
 progress(0, 0);
 for(number_to_check=3; number_to_check <= prime_range; number_to_check+=2)
 {
  prime = 1;
  if(store_2)
  {
   primes_address = (unsigned long long *)malloc(sizeof(u_long_64) * 1000000);
   *primes_address = 2;
   prime_count = 1;
   store_2 = 0;
  }
  for(i=3; i*i <= number_to_check; i+=2)
  {
   if(number_to_check % i == 0)
   {
    prime = 0;
    break;
   }
  }
  if(prime)
  {
   prime_count++;
   if(prime_count >= 1000000 * buff_mult)
   {
    buff_mult++;
    primes_address = (unsigned long long *)realloc(primes_address, (sizeof(u_long_64) * 1000000 * buff_mult));
   }
   *(primes_address + prime_count-1) = number_to_check;
  }
  if( (perc+1) <= (int)(100.0 * number_to_check / prime_range)) {
   perc = (int)(100.0 * number_to_check / prime_range);
   progress(0, perc);
  }
 }
 progress(0,100);
 printf("\n\n");
 printf("Generating Semiprimes...\n");
 fpurge(stdout);
 progress(0, 0);
 *semiprimes_count = buff_mult = perc = 0;
 for(y=0; y<prime_count; y++)
 {
  for(z=y; z<prime_count; z++)
  {
   semi_prime = (*(primes_address + y)) * (*(primes_address + z));
   if(semi_prime < first_range)
    continue;
   else if(semi_prime > second_range)
    break;
   else
   {
    (*semiprimes_count)++;
    if(*semiprimes_count >= 1000000 * buff_mult)
    {
     buff_mult++;
     semi_prime_address = (unsigned long long *)realloc(semi_prime_address, (sizeof(u_long_64) * 1000000 * buff_mult));
    }
    *(semi_prime_address + (*semiprimes_count)-1) = semi_prime;
   }
  }
  if(y == z)
   break;
 }
 free(primes_address);
 progress(0, 100);
 printf("\n\n");
 printf("Sorting Semiprimes...\n");
 fpurge(stdout);
 progress(0, 0);
 qsort(semi_prime_address, *semiprimes_count, sizeof(u_long_64), compare_semis);
 progress(0, 100);
 printf("\n");
 fpurge(stdout);
 return semi_prime_address;
}

variable_types:
i
unsigned long long

variable_types:
x
unsigned long long

variable_types:
y
unsigned long long

variable_types:
z
unsigned long long

variable_types: perc int

return_type: unsigned long long *


progress

decompiled_code:
int __fastcall progress(__int64 a1, unsigned int a2)
{
int i; // ebx

printf("\r%3d%%", a2);
putchar(124);
for ( i = 0; i != 33; ++i )
{
while ( (int)a2 / 3 != i )
{
++i;
fputc(45, stdout);
if ( i == 33 )
goto LABEL_5;
}
fputc(42, stdout);
}
LABEL_5:
putchar(124);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, unsigned int a2)
{
int i; // ebx

printf("\r%3d%%", a2);
putchar(124);
for ( i = 0; i != 33; ++i )
{
while ( (int)a2 / 3 != i )
{
++i;
fputc(45, stdout);
if ( i == 33 )
goto LABEL_5;
}
fputc(42, stdout);
}
LABEL_5:
putchar(124);
return fflush(stdout);
}

original_code:
void progress(_Bool start, int perc)
{
 int i;
 printf("\r%3d%%",perc);
 printf("|");
 for (i = 0; i < 33; i++) {
  if (i == perc / 3)
   fprintf (stdout, "*");
  else
   fprintf (stdout, "-");
 }
 printf("|");
 fflush(stdout);
 return;
}


translate

decompiled_code:
char *__fastcall translate(char *src)
{
unsigned __int16 v1; // bp
char v2; // r13
__int16 v3; // bp
char v4; // al
char *v5; // rax
char *result; // rax
char *v7; // rax
char srca[2]; // [rsp+Eh] [rbp-4Ah] BYREF
char dest[72]; // [rsp+10h] [rbp-48h] BYREF

strcpy(srca, "h");
v1 = (*__ctype_b_loc())[*src];
strlower(src);
v2 = *src;
v3 = v1 & 0x100;
switch ( *src )
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
strcpy(stpcpy(dest, src), "ay");
break;
case 'c':
case 'p':
case 'r':
case 's':
case 't':
case 'w':
v4 = src[1];
if ( v4 != 104 )
goto LABEL_3;
goto LABEL_9;
case 'q':
v4 = src[1];
LABEL_3:
if ( v4 != 117 )
goto LABEL_4;
LABEL_9:
v7 = stpcpy(dest, src + 2);
srca[0] = v2;
*(_DWORD *)stpcpy(v7, srca) = 7954792;
break;
default:
LABEL_4:
v5 = stpcpy(dest, src + 1);
srca[0] = v2;
strcpy(stpcpy(v5, srca), "ay");
break;
}
result = strcpy(src, dest);
if ( v3 )
{
result = (char *)(unsigned int)(*__ctype_toupper_loc())[*src];
*src = (char)result;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
unsigned __int16 v1; // bp
char v2; // r13
__int16 v3; // bp
char v4; // al
char *v5; // rax
char *result; // rax
char *v7; // rax
char srca[2]; // [rsp+Eh] [rbp-4Ah] BYREF
char dest[72]; // [rsp+10h] [rbp-48h] BYREF

strcpy(srca, "h");
v1 = (*__ctype_b_loc())[*src];
func7(src);
v2 = *src;
v3 = v1 & 0x100;
switch ( *src )
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
strcpy(stpcpy(dest, src), "ay");
break;
case 'c':
case 'p':
case 'r':
case 's':
case 't':
case 'w':
v4 = src[1];
if ( v4 != 104 )
goto LABEL_3;
goto LABEL_9;
case 'q':
v4 = src[1];
LABEL_3:
if ( v4 != 117 )
goto LABEL_4;
LABEL_9:
v7 = stpcpy(dest, src + 2);
srca[0] = v2;
*(_DWORD *)stpcpy(v7, srca) = 7954792;
break;
default:
LABEL_4:
v5 = stpcpy(dest, src + 1);
srca[0] = v2;
strcpy(stpcpy(v5, srca), "ay");
break;
}
result = strcpy(src, dest);
if ( v3 )
{
result = (char *)(unsigned int)(*__ctype_toupper_loc())[*src];
*src = (char)result;
}
return result;
}

original_code:
void translate(char *word) {
 char *w;
 char piglatin[32];
 char append[] = "h";
 char ch;
 _Bool sw = 0;
 w = word;
 if(((*__ctype_b_loc ())[(int) ((*word))] & (unsigned short int) _ISupper))
  sw = 1;
 strlower(word);
 ch = *word;
 switch(ch) {
  case 'a':
  case 'e':
  case 'i':
  case 'o':
  case 'u':
   strcpy(piglatin,word);
   strcat(piglatin,"ay");
   break;
  case 'c':
  case 'p':
  case 'r':
  case 's':
  case 't':
  case 'w':
   if(*(word+1) == 'h') {
    word += 2;
    strcpy(piglatin,word);
    append[0] = ch;
    strcat(piglatin,append);
    strcat(piglatin,"hay");
    break;
   }
  case 'q':
   if(*(word+1) == 'u') {
    word +=2;
    strcpy(piglatin,word);
    append[0] = ch;
    strcat(piglatin,append);
    strcat(piglatin,"hay");
    break;
   }
  default:
   word++;
   strcpy(piglatin,word);
   append[0] = ch;
   strcat(piglatin,append);
   strcat(piglatin,"ay");
   break;
 }
 strcpy(w,piglatin);
 if(sw)
  *w = toupper(*w);
}

canonical_original_code:
void translate(char *word) {
 char *w;
 char piglatin[32];
 char append[] = "h";
 char ch;
 _Bool sw = 0;
 w = word;
 if(((*__ctype_b_loc ())[(int) ((*word))] & (unsigned short) _ISupper))
  sw = 1;
 strlower(word);
 ch = *word;
 switch(ch) {
  case 'a':
  case 'e':
  case 'i':
  case 'o':
  case 'u':
   strcpy(piglatin,word);
   strcat(piglatin,"ay");
   break;
  case 'c':
  case 'p':
  case 'r':
  case 's':
  case 't':
  case 'w':
   if(*(word+1) == 'h') {
    word += 2;
    strcpy(piglatin,word);
    append[0] = ch;
    strcat(piglatin,append);
    strcat(piglatin,"hay");
    break;
   }
  case 'q':
   if(*(word+1) == 'u') {
    word +=2;
    strcpy(piglatin,word);
    append[0] = ch;
    strcat(piglatin,append);
    strcat(piglatin,"hay");
    break;
   }
  default:
   word++;
   strcpy(piglatin,word);
   append[0] = ch;
   strcat(piglatin,append);
   strcat(piglatin,"ay");
   break;
 }
 strcpy(w,piglatin);
 if(sw)
  *w = toupper(*w);
}

variable_types:
word
char *

variable_types:
w
char *

variable_types:
piglatin
char [32]

variable_types:
append
char []

variable_types: ch char


help

decompiled_code:
int help()
{
return puts("Welcome to PiggyPig 0.0.1b\n\nUSAGE: pig.exe [INPUT] [OUTPUT]");
}

canonical_decompiled_code:
int func9()
{
return puts("Welcome to PiggyPig 0.0.1b\n\nUSAGE: pig.exe [INPUT] [OUTPUT]");
}

original_code:
void help(void) {
 printf(
  "Welcome to PiggyPig " "0.0.1b""\n\n"
  "USAGE: pig.exe [INPUT] [OUTPUT]\n"
 );
}

canonical_original_code:
void help() {
 printf(
  "Welcome to PiggyPig " "0.0.1b""\n\n"
  "USAGE: pig.exe [INPUT] [OUTPUT]\n"
 );
}


decompiled_code:
int __fastcall initfile_once(__int64 a1)
{
file_init(a1 + 1039, a1);
if ( *(_BYTE *)(a1 + 4) )
printf("\nInitial Directory: \n\"%s\"\n\n", cwd1);
return fprintf(file, "\nInitial Directory: \"%s\"\n\n", cwd1);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
file_init(a1 + 1039, a1);
if ( *(_BYTE *)(a1 + 4) )
printf("\nInitial Directory: \n\"%s\"\n\n", cwd1);
return fprintf(file, "\nInitial Directory: \"%s\"\n\n", cwd1);
}

original_code:
void initfile_once(DIR_OPTIONS *options) {
 file_init(options->filepath_arg, options);
 if(options->verbose)
  printf("\nInitial Directory: \n\"%s\"\n\n", cwd1);
 fprintf(file, "\nInitial Directory: \"%s\"\n\n", cwd1);
}

canonical_original_code:
void initfile_once(struct arguments *options) {
 file_init(options->filepath_arg, options);
 if(options->verbose)
  printf("\nInitial Directory: \n\"%s\"\n\n", cwd1);
 fprintf(file, "\nInitial Directory: \"%s\"\n\n", cwd1);
}

variable_types: struct arguments { _Bool help; _Bool recurse; _Bool complete; _Bool output; _Bool verbose; _Bool filetype; _Bool filename; _Bool asterisk; unsigned int other; struct filetype { _Bool summary; _Bool relative; _Bool complete; } filetype_args; char directory[1024]; char filepath_arg[1024]; char filename_arg[1024]; } *

user_defined_types: struct arguments { _Bool help; _Bool recurse; _Bool complete; _Bool output; _Bool verbose; _Bool filetype; _Bool filename; _Bool asterisk; unsigned int other; struct filetype filetype_args; char directory[1024]; char filepath_arg[1024]; char filename_arg[1024]; }


decompiled_code:
size_t __fastcall cut_cwd(__int64 a1)
{
__int64 v2; // rdi
size_t result; // rax
__int64 v4; // rdx
size_t v5; // rsi
size_t v6; // rcx
char v7[1032]; // [rsp+0h] [rbp-408h] BYREF

v2 = a1 + 8;
*(_QWORD *)(v2 - 8) = 0LL;
*(_QWORD *)(v2 + 1008) = 0LL;
memset(
(void *)(v2 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v2 & 0xFFFFFFF8) + 1024) >> 3));
getcwd(v7, 0x400uLL);
result = strlen(v7);
v4 = (unsigned int)cwd1_len;
v5 = result;
if ( result != cwd1_len )
{
result = 0LL;
do
{
v6 = v4 + result;
if ( v7[v4] == 47 )
*(_BYTE *)(a1 + result) = v7[v6 + 1];
else
*(_BYTE *)(a1 + result) = v7[v6];
v4 = (unsigned int)cwd1_len;
++result;
}
while ( v5 - (unsigned int)cwd1_len > result );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func1(__int64 a1)
{
__int64 v2; // rdi
size_t result; // rax
__int64 v4; // rdx
size_t v5; // rsi
size_t v6; // rcx
char v7[1032]; // [rsp+0h] [rbp-408h] BYREF

v2 = a1 + 8;
*(_QWORD *)(v2 - 8) = 0LL;
*(_QWORD *)(v2 + 1008) = 0LL;
memset(
(void *)(v2 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v2 & 0xFFFFFFF8) + 1024) >> 3));
getcwd(v7, 0x400uLL);
result = strlen(v7);
v4 = (unsigned int)cwd1_len;
v5 = result;
if ( result != cwd1_len )
{
result = 0LL;
do
{
v6 = v4 + result;
if ( v7[v4] == 47 )
*(_BYTE *)(a1 + result) = v7[v6 + 1];
else
*(_BYTE *)(a1 + result) = v7[v6];
v4 = (unsigned int)cwd1_len;
++result;
}
while ( v5 - (unsigned int)cwd1_len > result );
}
return result;
}

original_code:
void cut_cwd(char *output) {
 char cwd2[1024];
 unsigned long x;
 unsigned long cwd2_len;
 memset(output, '\0', 1024);
 getcwd(cwd2, 1024);
 cwd2_len = strlen(cwd2);
 for(x=0; x < cwd2_len-cwd1_len; x++) {
  if(cwd2[cwd1_len] == '/')
   output[x] = cwd2[cwd1_len+x+1];
  else
   output[x] = cwd2[cwd1_len+x];
 }
}

variable_types:
output
char *

variable_types:
x
unsigned long


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

if ( ((*__ctype_b_loc())[(char)a1] & 0x100) != 0 )
{
result = (unsigned __int8)((*__ctype_tolower_loc())[(char)a1] - 97);
switch ( (char)result )
{
case 0:
result = 85LL;
break;
case 1:
result = 82LL;
break;
case 2:
result = 83LL;
break;
case 3:
result = 84LL;
break;
case 4:
result = 79LL;
break;
case 5:
result = 86LL;
break;
case 6:
result = 87LL;
break;
case 7:
result = 88LL;
break;
case 8:
result = 65LL;
break;
case 9:
result = 90LL;
break;
case 10:
result = 66LL;
break;
case 11:
result = 67LL;
break;
case 12:
result = 77LL;
break;
case 13:
result = 68LL;
break;
case 14:
result = 69LL;
break;
case 15:
result = 70LL;
break;
case 16:
result = 71LL;
break;
case 17:
result = 72LL;
break;
case 18:
result = 74LL;
break;
case 19:
result = 75LL;
break;
case 20:
result = 73LL;
break;
case 21:
result = 76LL;
break;
case 22:
result = 78LL;
break;
case 23:
result = 80LL;
break;
case 24:
result = HIBYTE(word_4040A2) == 0 ? 79 : 89;
break;
case 25:
result = 81LL;
break;
default:
return result;
}
}
else
{
result = (unsigned __int8)(a1 - 97);
switch ( (char)a1 )
{
case 'a':
result = 117LL;
break;
case 'b':
result = 114LL;
break;
case 'c':
result = 115LL;
break;
case 'd':
result = 116LL;
break;
case 'e':
result = 111LL;
break;
case 'f':
result = 118LL;
break;
case 'g':
result = 119LL;
break;
case 'h':
result = 120LL;
break;
case 'i':
result = 97LL;
break;
case 'j':
result = 122LL;
break;
case 'k':
result = 98LL;
break;
case 'l':
result = 99LL;
break;
case 'm':
result = a1;
break;
case 'n':
result = 100LL;
break;
case 'o':
result = 101LL;
break;
case 'p':
result = 102LL;
break;
case 'q':
result = 103LL;
break;
case 'r':
result = 104LL;
break;
case 's':
result = 106LL;
break;
case 't':
result = 107LL;
break;
case 'u':
result = 105LL;
break;
case 'v':
result = 108LL;
break;
case 'w':
result = 110LL;
break;
case 'x':
result = 112LL;
break;
case 'y':
result = 111LL;
if ( HIBYTE(word_4040A2) )
result = a1;
break;
case 'z':
result = 113LL;
break;
default:
return result;
}
}
return result;
}

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

if ( ((*__ctype_b_loc())[(char)a1] & 0x100) != 0 )
{
result = (unsigned __int8)((*__ctype_tolower_loc())[(char)a1] - 97);
switch ( (char)result )
{
case 0:
result = 85LL;
break;
case 1:
result = 82LL;
break;
case 2:
result = 83LL;
break;
case 3:
result = 84LL;
break;
case 4:
result = 79LL;
break;
case 5:
result = 86LL;
break;
case 6:
result = 87LL;
break;
case 7:
result = 88LL;
break;
case 8:
result = 65LL;
break;
case 9:
result = 90LL;
break;
case 10:
result = 66LL;
break;
case 11:
result = 67LL;
break;
case 12:
result = 77LL;
break;
case 13:
result = 68LL;
break;
case 14:
result = 69LL;
break;
case 15:
result = 70LL;
break;
case 16:
result = 71LL;
break;
case 17:
result = 72LL;
break;
case 18:
result = 74LL;
break;
case 19:
result = 75LL;
break;
case 20:
result = 73LL;
break;
case 21:
result = 76LL;
break;
case 22:
result = 78LL;
break;
case 23:
result = 80LL;
break;
case 24:
result = HIBYTE(word_4040A2) == 0 ? 79 : 89;
break;
case 25:
result = 81LL;
break;
default:
return result;
}
}
else
{
result = (unsigned __int8)(a1 - 97);
switch ( (char)a1 )
{
case 'a':
result = 117LL;
break;
case 'b':
result = 114LL;
break;
case 'c':
result = 115LL;
break;
case 'd':
result = 116LL;
break;
case 'e':
result = 111LL;
break;
case 'f':
result = 118LL;
break;
case 'g':
result = 119LL;
break;
case 'h':
result = 120LL;
break;
case 'i':
result = 97LL;
break;
case 'j':
result = 122LL;
break;
case 'k':
result = 98LL;
break;
case 'l':
result = 99LL;
break;
case 'm':
result = a1;
break;
case 'n':
result = 100LL;
break;
case 'o':
result = 101LL;
break;
case 'p':
result = 102LL;
break;
case 'q':
result = 103LL;
break;
case 'r':
result = 104LL;
break;
case 's':
result = 106LL;
break;
case 't':
result = 107LL;
break;
case 'u':
result = 105LL;
break;
case 'v':
result = 108LL;
break;
case 'w':
result = 110LL;
break;
case 'x':
result = 112LL;
break;
case 'y':
result = 111LL;
if ( HIBYTE(word_4040A2) )
result = a1;
break;
case 'z':
result = 113LL;
break;
default:
return result;
}
}
return result;
}

original_code:
char eng_din(char ch)
{
 _Bool l_switch = 0;
 if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short int) _ISupper))
 {
  ch = tolower(ch);
  l_switch = 1;
 }
 switch(ch)
 {
  case 'a': return((l_switch) ? 'U' : 'u'); break;
  case 'b': return((l_switch) ? 'R' : 'r'); break;
  case 'c': return((l_switch) ? 'S' : 's'); break;
  case 'd': return((l_switch) ? 'T' : 't'); break;
  case 'e': return((l_switch) ? 'O' : 'o'); break;
  case 'f': return((l_switch) ? 'V' : 'v'); break;
  case 'g': return((l_switch) ? 'W' : 'w'); break;
  case 'h': return((l_switch) ? 'X' : 'x'); break;
  case 'i': return((l_switch) ? 'A' : 'a'); break;
  case 'j': return((l_switch) ? 'Z' : 'z'); break;
  case 'k': return((l_switch) ? 'B' : 'b'); break;
  case 'l': return((l_switch) ? 'C' : 'c'); break;
  case 'm': return((l_switch) ? 'M' : 'm'); break;
  case 'n': return((l_switch) ? 'D' : 'd'); break;
  case 'o': return((l_switch) ? 'E' : 'e'); break;
  case 'p': return((l_switch) ? 'F' : 'f'); break;
  case 'q': return((l_switch) ? 'G' : 'g'); break;
  case 'r': return((l_switch) ? 'H' : 'h'); break;
  case 's': return((l_switch) ? 'J' : 'j'); break;
  case 't': return((l_switch) ? 'K' : 'k'); break;
  case 'u': return((l_switch) ? 'I' : 'i'); break;
  case 'v': return((l_switch) ? 'L' : 'l'); break;
  case 'w': return((l_switch) ? 'N' : 'n'); break;
  case 'x': return((l_switch) ? 'P' : 'p'); break;
  case 'y':
   if(options.y_bypass != 1)
    return((l_switch) ? 'O' : 'o');
   else
    return((l_switch) ? 'Y' : 'y');
   break;
  case 'z': return((l_switch) ? 'Q' : 'q'); break;
  default: break;
 }
 l_switch = 0;
}

canonical_original_code:
char eng_din(char ch)
{
 _Bool l_switch = 0;
 if(((*__ctype_b_loc ())[(int) ((ch))] & (unsigned short) _ISupper))
 {
  ch = tolower(ch);
  l_switch = 1;
 }
 switch(ch)
 {
  case 'a': return((l_switch) ? 'U' : 'u'); break;
  case 'b': return((l_switch) ? 'R' : 'r'); break;
  case 'c': return((l_switch) ? 'S' : 's'); break;
  case 'd': return((l_switch) ? 'T' : 't'); break;
  case 'e': return((l_switch) ? 'O' : 'o'); break;
  case 'f': return((l_switch) ? 'V' : 'v'); break;
  case 'g': return((l_switch) ? 'W' : 'w'); break;
  case 'h': return((l_switch) ? 'X' : 'x'); break;
  case 'i': return((l_switch) ? 'A' : 'a'); break;
  case 'j': return((l_switch) ? 'Z' : 'z'); break;
  case 'k': return((l_switch) ? 'B' : 'b'); break;
  case 'l': return((l_switch) ? 'C' : 'c'); break;
  case 'm': return((l_switch) ? 'M' : 'm'); break;
  case 'n': return((l_switch) ? 'D' : 'd'); break;
  case 'o': return((l_switch) ? 'E' : 'e'); break;
  case 'p': return((l_switch) ? 'F' : 'f'); break;
  case 'q': return((l_switch) ? 'G' : 'g'); break;
  case 'r': return((l_switch) ? 'H' : 'h'); break;
  case 's': return((l_switch) ? 'J' : 'j'); break;
  case 't': return((l_switch) ? 'K' : 'k'); break;
  case 'u': return((l_switch) ? 'I' : 'i'); break;
  case 'v': return((l_switch) ? 'L' : 'l'); break;
  case 'w': return((l_switch) ? 'N' : 'n'); break;
  case 'x': return((l_switch) ? 'P' : 'p'); break;
  case 'y':
   if(options.y_bypass != 1)
    return((l_switch) ? 'O' : 'o');
   else
    return((l_switch) ? 'Y' : 'y');
   break;
  case 'z': return((l_switch) ? 'Q' : 'q'); break;
  default: break;
 }
 l_switch = 0;
}


decompiled_code:
char *__fastcall rand_file_extension(char *s)
{
int v2; // edi
char *v3; // rax
char *v4; // rdi
char v5; // dl
int v6; // eax
unsigned int v7; // ecx
__int64 v8; // rsi
__int64 v9; // rax
char *v10; // rcx
__int64 v11; // rdx
char v13[32776]; // [rsp+0h] [rbp-8008h] BYREF

memset(extension, 0, sizeof(extension));
memset(v13, 0, 0x8000uLL);
v2 = strlen(s) - 1;
v3 = v13;
v4 = &s[v2];
do
{
v5 = *v4;
++v3;
--v4;
*(v3 - 1) = v5;
}
while ( v5 != 46 );
v6 = strlen(v13);
v7 = v6 - 1;
if ( v6 )
{
v8 = v7;
v9 = 0LL;
v10 = &v13[v7];
do
{
extension[v9] = v10[-v9];
v11 = v9++;
}
while ( v11 != v8 );
}
return extension;
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
int v2; // edi
char *v3; // rax
char *v4; // rdi
char v5; // dl
int v6; // eax
unsigned int v7; // ecx
__int64 v8; // rsi
__int64 v9; // rax
char *v10; // rcx
__int64 v11; // rdx
char v13[32776]; // [rsp+0h] [rbp-8008h] BYREF

memset(extension, 0, sizeof(extension));
memset(v13, 0, 0x8000uLL);
v2 = strlen(s) - 1;
v3 = v13;
v4 = &s[v2];
do
{
v5 = *v4;
++v3;
--v4;
*(v3 - 1) = v5;
}
while ( v5 != 46 );
v6 = strlen(v13);
v7 = v6 - 1;
if ( v6 )
{
v8 = v7;
v9 = 0LL;
v10 = &v13[v7];
do
{
extension[v9] = v10[-v9];
v11 = v9++;
}
while ( v11 != v8 );
}
return extension;
}

original_code:
char *rand_file_extension(char *filename)
{
    int y = 0, x;
 char pre_extension[32768];
    memset(extension, '\0', 32768);
 memset(pre_extension, '\0', 32768);
    x = strlen(filename) - 1;
    while((pre_extension[y++] = filename[x--]) != '.')
        ;
    x = strlen(pre_extension) - 1;
    y = 0;
    while(x >= 0)
        extension[y++] = pre_extension[x--];
    return extension;
}

canonical_original_code:
char *rand_file_extension(char *filename)
{
    int y = 0; int x;
 char pre_extension[32768];
    memset(extension, '\0', 32768);
 memset(pre_extension, '\0', 32768);
    x = strlen(filename) - 1;
    while((pre_extension[y++] = filename[x--]) != '.')
        ;
    x = strlen(pre_extension) - 1;
    y = 0;
    while(x >= 0)
        extension[y++] = pre_extension[x--];
    return extension;
}

variable_types:
filename
char *

variable_types: y int

variable_types: x int

return_type: char *