merge

decompiled_code:
__int64 __fastcall merge(char *a1, __int64 a2, char *a3, __int64 a4, size_t a5, int (__fastcall *a6)(char *, char *))
{
__int64 v6; // rbp
__int64 v8; // r13
__int64 v9; // r15
char *v10; // rax
char *v11; // r12
__int64 v12; // rbx
char *src; // [rsp+8h] [rbp-60h]
size_t v17; // [rsp+18h] [rbp-50h]
void *ptr; // [rsp+20h] [rbp-48h]

v6 = a2;
v8 = a4;
v9 = a2 + a4;
v17 = (a2 + a4) * a5;
v10 = (char *)malloc(v17);
ptr = v10;
if ( !v10 )
return 0LL;
v11 = v10;
if ( v9 )
{
src = a1;
v12 = 0LL;
while ( !v6 || !v8 )
{
if ( v6 )
goto LABEL_4;
if ( v8 )
goto LABEL_12;
v6 = 0LL;
LABEL_8:
v11 += a5;
if ( v9 == ++v12 )
goto LABEL_15;
}
if ( a6(src, a3) >= 0 )
{
LABEL_12:
memcpy(v11, a3, a5);
a3 += a5;
--v8;
goto LABEL_8;
}
LABEL_4:
memcpy(v11, src, a5);
src += a5;
--v6;
goto LABEL_8;
}
LABEL_15:
memcpy(a1, ptr, v17);
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2, char *a3, __int64 a4, size_t a5, int (__fastcall *a6)(char *, char *))
{
__int64 v6; // rbp
__int64 v8; // r13
__int64 v9; // r15
char *v10; // rax
char *v11; // r12
__int64 v12; // rbx
char *src; // [rsp+8h] [rbp-60h]
size_t v17; // [rsp+18h] [rbp-50h]
void *ptr; // [rsp+20h] [rbp-48h]

v6 = a2;
v8 = a4;
v9 = a2 + a4;
v17 = (a2 + a4) * a5;
v10 = (char *)malloc(v17);
ptr = v10;
if ( !v10 )
return 0LL;
v11 = v10;
if ( v9 )
{
src = a1;
v12 = 0LL;
while ( !v6 || !v8 )
{
if ( v6 )
goto LABEL_4;
if ( v8 )
goto LABEL_12;
v6 = 0LL;
LABEL_8:
v11 += a5;
if ( v9 == ++v12 )
goto LABEL_15;
}
if ( a6(src, a3) >= 0 )
{
LABEL_12:
memcpy(v11, a3, a5);
a3 += a5;
--v8;
goto LABEL_8;
}
LABEL_4:
memcpy(v11, src, a5);
src += a5;
--v6;
goto LABEL_8;
}
LABEL_15:
memcpy(a1, ptr, v17);
free(ptr);
return 1LL;
}

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

repo: sampost/libsort

decompiled_code:
__int64 __fastcall mergesort(char *a1, unsigned __int64 a2, size_t a3, int (__fastcall *a4)(char *, char *))
{
__int64 result; // rax
__int64 v7; // r14

result = 1LL;
if ( a2 > 1 )
{
v7 = a2 >> 1;
result = mergesort(a1, a2 >> 1);
if ( (_DWORD)result )
{
result = mergesort(&a1[a3 * v7], a2 - v7);
if ( (_DWORD)result )
result = (unsigned int)merge(a1, v7, &a1[a3 * v7], a2 - v7, a3, a4) != 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, unsigned __int64 a2, size_t a3, int (__fastcall *a4)(char *, char *))
{
__int64 result; // rax
__int64 v7; // r14

result = 1LL;
if ( a2 > 1 )
{
v7 = a2 >> 1;
result = func1(a1, a2 >> 1);
if ( (_DWORD)result )
{
result = func1(&a1[a3 * v7], a2 - v7);
if ( (_DWORD)result )
result = (unsigned int)func0(a1, v7, &a1[a3 * v7], a2 - v7, a3, a4) != 0;
}
}
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:
comp
int (*)(void *first, void *second)

variable_types:
middle
unsigned long

return_type: int


decompiled_code:
__int64 __fastcall merge_nomalloc(void *src, __int64 a2, char *a3, __int64 a4, size_t a5, int (__fastcall *a6)(char *, char *), void *dest)
{
__int64 v7; // rbp
__int64 v9; // r13
char *v10; // r15
char *v11; // r12
__int64 v12; // rbx
__int64 v15; // [rsp+8h] [rbp-50h]

v15 = a4 + a2;
if ( a4 + a2 )
{
v7 = a2;
v9 = a4;
v10 = (char *)src;
v11 = (char *)dest;
v12 = 0LL;
while ( !v7 || !v9 )
{
if ( v7 )
goto LABEL_3;
if ( v9 )
goto LABEL_11;
v7 = 0LL;
LABEL_7:
v11 += a5;
if ( v15 == ++v12 )
goto LABEL_14;
}
if ( a6(v10, a3) >= 0 )
{
LABEL_11:
memcpy(v11, a3, a5);
a3 += a5;
--v9;
goto LABEL_7;
}
LABEL_3:
memcpy(v11, v10, a5);
v10 += a5;
--v7;
goto LABEL_7;
}
LABEL_14:
memcpy(src, dest, a5 * v15);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *src, __int64 a2, char *a3, __int64 a4, size_t a5, int (__fastcall *a6)(char *, char *), void *dest)
{
__int64 v7; // rbp
__int64 v9; // r13
char *v10; // r15
char *v11; // r12
__int64 v12; // rbx
__int64 v15; // [rsp+8h] [rbp-50h]

v15 = a4 + a2;
if ( a4 + a2 )
{
v7 = a2;
v9 = a4;
v10 = (char *)src;
v11 = (char *)dest;
v12 = 0LL;
while ( !v7 || !v9 )
{
if ( v7 )
goto LABEL_3;
if ( v9 )
goto LABEL_11;
v7 = 0LL;
LABEL_7:
v11 += a5;
if ( v15 == ++v12 )
goto LABEL_14;
}
if ( a6(v10, a3) >= 0 )
{
LABEL_11:
memcpy(v11, a3, a5);
a3 += a5;
--v9;
goto LABEL_7;
}
LABEL_3:
memcpy(v11, v10, a5);
v10 += a5;
--v7;
goto LABEL_7;
}
LABEL_14:
memcpy(src, dest, a5 * v15);
return 1LL;
}

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


decompiled_code:
__int64 __fastcall mergesort_onemalloc(char *a1, unsigned __int64 a2, size_t a3, int (__fastcall *a4)(char *, char *), void *a5)
{
void *v7; // rbx
int v8; // er15
__int64 result; // rax
__int64 v10; // r14

v7 = a5;
v8 = 0;
if ( !a5 )
{
v7 = malloc(a3 * a2);
if ( !v7 )
return 0LL;
v8 = 1;
}
result = 1LL;
if ( a2 > 1 )
{
v10 = a2 >> 1;
if ( (unsigned int)mergesort_onemalloc(a1, a2 >> 1, a3, a4, v7)
&& (unsigned int)mergesort_onemalloc(&a1[v10 * a3], a2 - v10, a3, a4, v7)
&& (unsigned int)merge_nomalloc(a1, v10, &a1[v10 * a3], a2 - v10, a3, a4, v7) )
{
result = 1LL;
if ( v8 )
{
free(v7);
result = 1LL;
}
}
else
{
result = 0LL;
if ( v8 )
{
free(v7);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, unsigned __int64 a2, size_t a3, int (__fastcall *a4)(char *, char *), void *a5)
{
void *v7; // rbx
int v8; // er15
__int64 result; // rax
__int64 v10; // r14

v7 = a5;
v8 = 0;
if ( !a5 )
{
v7 = malloc(a3 * a2);
if ( !v7 )
return 0LL;
v8 = 1;
}
result = 1LL;
if ( a2 > 1 )
{
v10 = a2 >> 1;
if ( (unsigned int)func3(a1, a2 >> 1, a3, a4, v7)
&& (unsigned int)func3(&a1[v10 * a3], a2 - v10, a3, a4, v7)
&& (unsigned int)func2(a1, v10, &a1[v10 * a3], a2 - v10, a3, a4, v7) )
{
result = 1LL;
if ( v8 )
{
free(v7);
result = 1LL;
}
}
else
{
result = 0LL;
if ( v8 )
{
free(v7);
result = 0LL;
}
}
}
return result;
}

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 *))
{
int v6; // ebp
void *v7; // r12
char *v8; // rbx
int v9; // er14
void *dest; // [rsp+8h] [rbp-50h]

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

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2, size_t a3, int (__fastcall *a4)(void *, char *))
{
int v6; // ebp
void *v7; // r12
char *v8; // rbx
int v9; // er14
void *dest; // [rsp+8h] [rbp-50h]

dest = malloc(a3);
if ( !dest )
return 0LL;
while ( 1 )
{
v9 = a2;
if ( a2 <= 1 )
break;
v8 = a1;
v6 = 1;
a2 = 0;
do
{
v7 = v8;
v8 += a3;
if ( a4(v7, v8) > 0 )
{
memcpy(dest, v7, a3);
memcpy(v7, v8, a3);
memcpy(v8, dest, a3);
a2 = v6;
}
++v6;
}
while ( v6 != v9 );
if ( a2 <= 1 )
return 1LL;
}
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 *


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

variable_types: c char


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

LODWORD(result) = i++;
result = (int)result;
stack[(int)result] = a1;
return result;
}

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

LODWORD(result) = i++;
result = (int)result;
stack[(int)result] = a1;
return result;
}

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

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

return_type: void


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

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3; // bl
char *v4; // rbp
char v5; // r12
char v6; // al
char v7; // bl
char v8; // al
char v9; // al

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

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char v3; // bl
char *v4; // rbp
char v5; // r12
char v6; // al
char v7; // bl
char v8; // al
char v9; // al

while ( 1 )
{
fgets(&buffer, 0x100000, _bss_start);
v3 = buffer;
if ( buffer && buffer != 10 )
{
v4 = (char *)&unk_504081;
do
{
if ( v3 != 32 )
{
if ( ((*__ctype_b_loc())[v3] & 8) != 0 || v3 == 46 )
{
putchar(v3);
}
else
{
v5 = v3;
if ( (unsigned int)func7(v3) )
{
putchar(32);
while ( 1 )
{
v7 = func12();
if ( (unsigned int)func7(v7) && (unsigned int)func8(v5) == -1 )
{
if ( (unsigned int)func9(v5, v7) + 1 > 1 )
goto LABEL_19;
}
else if ( (unsigned int)func8(v5) != 1 || (unsigned int)func9(v5, v7) != -1 )
{
LABEL_19:
func10(v5);
goto LABEL_3;
}
v6 = func11();
putchar(v6);
putchar(32);
}
}
if ( v3 == 40 )
{
func10(40);
}
else if ( v3 == 41 )
{
while ( (unsigned __int8)func12() != 40 )
{
putchar(32);
v8 = func11();
putchar(v8);
}
func11();
}
}
}
LABEL_3:
v3 = *v4++;
}
while ( v3 && v3 != 10 );
}
putchar(32);
while ( (unsigned __int8)func12() != 0xFF )
{
v9 = func11();
putchar(v9);
putchar(32);
}
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

decompiled_code:
void *__fastcall semiprimegen(unsigned __int64 a1, unsigned __int64 a2, size_t *a3)
{
unsigned __int64 v4; // r12
int v5; // er15
_QWORD *v6; // r13
unsigned __int64 v7; // rbx
char v8; // al
double v9; // xmm0_8
__int64 v10; // r15
__int64 v11; // rbp
unsigned __int64 v12; // rbx
unsigned __int64 v13; // r12
int v15; // ebp
unsigned __int64 v16; // rcx
unsigned __int64 v17; // [rsp+8h] [rbp-60h]
__int64 v18; // [rsp+10h] [rbp-58h]
__int64 v19; // [rsp+10h] [rbp-58h]
void *ptr; // [rsp+18h] [rbp-50h]

v4 = a2 >> 1;
puts("Generating Primes...");
fpurge(stdout);
progress(0LL, 0LL);
if ( a2 <= 5 )
{
progress(0LL, 100LL);
puts("\n");
puts("Generating Semiprimes...");
fpurge(stdout);
progress(0LL, 0LL);
*a3 = 0LL;
v6 = 0LL;
ptr = 0LL;
goto LABEL_17;
}
v5 = 0;
v18 = 1LL;
v17 = 0LL;
v6 = 0LL;
v7 = 3LL;
v8 = 1;
do
{
if ( v8 )
{
v6 = malloc(0x7A1200uLL);
*v6 = 2LL;
v17 = 1LL;
}
if ( v7 > 8 )
{
if ( v7 == v7 / 3 + (((v7 * (unsigned __int128)0xAAAAAAAAAAAAAAABLL) >> 64) & 0xFFFFFFFFFFFFFFFELL) )
goto LABEL_21;
v16 = 3LL;
while ( 1 )
{
v16 += 2LL;
if ( v16 * v16 > v7 )
break;
if ( !(v7 % v16) )
goto LABEL_21;
}
}
if ( 1000000 * v18 <= ++v17 )
{
++v18;
v6 = realloc(v6, 8000000 * v18);
}
v6[v17 - 1] = v7;
LABEL_21:
if ( (v7 & 0x8000000000000000LL) != 0LL )
v9 = (double)(int)(v7 & 1 | (v7 >> 1)) + (double)(int)(v7 & 1 | (v7 >> 1));
else
v9 = (double)(int)v7;
v15 = (int)(v9 * 100.0 / (double)(int)v4);
if ( v15 > v5 )
{
progress(0LL, (unsigned int)v15);
v5 = (int)(v9 * 100.0 / (double)(int)v4);
}
v7 += 2LL;
v8 = 0;
}
while ( v4 >= v7 );
progress(0LL, 100LL);
puts("\n");
puts("Generating Semiprimes...");
fpurge(stdout);
progress(0LL, 0LL);
*a3 = 0LL;
if ( v17 )
{
v10 = 0LL;
v19 = 0LL;
ptr = 0LL;
v11 = 0LL;
while ( 1 )
{
v12 = v6[v11] * v6[v10];
if ( v12 >= a1 )
{
if ( a2 < v12 )
goto LABEL_13;
v13 = *a3 + 1;
*a3 = v13;
if ( v13 >= 1000000 * v19 )
{
++v19;
ptr = realloc(ptr, 8000000 * v19);
}
*((_QWORD *)ptr + v13 - 1) = v12;
}
if ( v17 <= ++v11 )
{
LABEL_13:
if ( v10 == v11 )
goto LABEL_17;
v11 = v10 + 1;
if ( v17 <= v10 + 1 )
goto LABEL_17;
++v10;
}
}
}
ptr = 0LL;
LABEL_17:
free(v6);
progress(0LL, 100LL);
puts("\n");
puts("Sorting Semiprimes...");
fpurge(stdout);
progress(0LL, 0LL);
qsort(ptr, *a3, 8uLL, (__compar_fn_t)compare_semis);
progress(0LL, 100LL);
putchar(10);
fpurge(stdout);
return ptr;
}

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, __int64 a2)
{
int i; // ebx

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

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

printf("\r%3d%%", a2);
putchar(124);
for ( i = 0; i != 33; ++i )
{
if ( (int)a2 / 3 == i )
fputc(42, stdout);
else
fputc(45, stdout);
}
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 *dest)
{
__int16 v1; // bp
char v2; // r12
char *result; // rax
char src[2]; // [rsp+Eh] [rbp-3Ah] BYREF
char desta[4]; // [rsp+10h] [rbp-38h] BYREF

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

canonical_decompiled_code:
char *__fastcall func7(char *dest)
{
__int16 v1; // bp
char v2; // r12
char *result; // rax
char src[2]; // [rsp+Eh] [rbp-3Ah] BYREF
char desta[4]; // [rsp+10h] [rbp-38h] BYREF

strcpy(src, "h");
v1 = (*__ctype_b_loc())[*dest] & 0x100;
strlower(dest);
v2 = *dest;
switch ( *dest )
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
strcpy(desta, dest);
strcpy(&desta[strlen(desta)], "ay");
break;
case 'c':
case 'p':
case 'r':
case 's':
case 't':
case 'w':
if ( dest[1] == 104 )
goto LABEL_9;
goto LABEL_4;
case 'q':
LABEL_4:
if ( dest[1] != 117 )
goto LABEL_5;
LABEL_9:
strcpy(desta, dest + 2);
src[0] = v2;
strcat(desta, src);
*(_DWORD *)&desta[strlen(desta)] = 7954792;
break;
default:
LABEL_5:
strcpy(desta, dest + 1);
src[0] = v2;
strcat(desta, src);
strcpy(&desta[strlen(desta)], "ay");
break;
}
result = strcpy(dest, desta);
if ( v1 )
{
result = (char *)(unsigned int)(*__ctype_toupper_loc())[*dest];
*dest = (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 func8()
{
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:
__int64 __fastcall cut_cwd(_QWORD *a1)
{
size_t v2; // rdi
__int64 result; // rax
__int64 v4; // rdx
size_t v5; // rcx
char v6[1032]; // [rsp+0h] [rbp-408h] BYREF

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

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

*a1 = 0LL;
a1[127] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 1024) >> 3));
getcwd(v6, 0x400uLL);
v2 = strlen(v6);
result = (unsigned int)cwd1_len;
v4 = (unsigned int)cwd1_len;
if ( v2 != cwd1_len )
{
v5 = 0LL;
do
{
if ( v6[(unsigned int)result] == 47 )
*((_BYTE *)a1 + v5) = v6[v4 + 1 + v5];
else
*((_BYTE *)a1 + v5) = v6[v4 + v5];
++v5;
result = (unsigned int)cwd1_len;
v4 = (unsigned int)cwd1_len;
}
while ( v2 - (unsigned int)cwd1_len > v5 );
}
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(char a1)
{
__int64 result; // rax
char v2; // al
char v3; // al
char v4; // al
char v5; // al
char v6; // al
char v7; // al
char v8; // al
char v9; // al
char v10; // al
char v11; // al
char v12; // al
char v13; // al
char v14; // al
char v15; // al
char v16; // al
char v17; // al
char v18; // al
char v19; // al
char v20; // al
char v21; // al
char v22; // al
char v23; // al
char v24; // al
char v25; // al

result = (__int64)*_ctype_b_loc();
if ( (*(_BYTE *)(result + 2LL * a1 + 1) & 1) != 0 )
{
result = (unsigned __int8)((*_ctype_tolower_loc())[a1] - 97);
switch ( (char)result )
{
case 0:
result = 85LL;
break;
case 1:
v2 = 1;
goto LABEL_5;
case 2:
v3 = 1;
goto LABEL_9;
case 3:
v4 = 1;
goto LABEL_12;
case 4:
v5 = 1;
goto LABEL_15;
case 5:
v6 = 1;
goto LABEL_18;
case 6:
v7 = 1;
goto LABEL_21;
case 7:
v8 = 1;
goto LABEL_24;
case 8:
v9 = 1;
goto LABEL_27;
case 9:
v10 = 1;
goto LABEL_30;
case 10:
v11 = 1;
goto LABEL_33;
case 11:
result = 67LL;
break;
case 12:
v12 = 1;
goto LABEL_36;
case 13:
v13 = 1;
goto LABEL_39;
case 14:
v14 = 1;
goto LABEL_42;
case 15:
v15 = 1;
goto LABEL_45;
case 16:
v16 = 1;
goto LABEL_48;
case 17:
v17 = 1;
goto LABEL_51;
case 18:
v18 = 1;
goto LABEL_54;
case 19:
v19 = 1;
goto LABEL_57;
case 20:
v20 = 1;
goto LABEL_60;
case 21:
v21 = 1;
goto LABEL_63;
case 22:
v22 = 1;
goto LABEL_66;
case 23:
v23 = 1;
goto LABEL_69;
case 24:
v24 = 1;
goto LABEL_72;
case 25:
v25 = 1;
goto LABEL_77;
default:
return result;
}
}
else
{
switch ( a1 )
{
case 'a':
result = 117LL;
break;
case 'b':
v2 = 0;
LABEL_5:
result = v2 == 0 ? 114 : 82;
break;
case 'c':
v3 = 0;
LABEL_9:
result = v3 == 0 ? 115 : 83;
break;
case 'd':
v4 = 0;
LABEL_12:
result = v4 == 0 ? 116 : 84;
break;
case 'e':
v5 = 0;
LABEL_15:
result = v5 == 0 ? 111 : 79;
break;
case 'f':
v6 = 0;
LABEL_18:
result = v6 == 0 ? 118 : 86;
break;
case 'g':
v7 = 0;
LABEL_21:
result = v7 == 0 ? 119 : 87;
break;
case 'h':
v8 = 0;
LABEL_24:
result = v8 == 0 ? 120 : 88;
break;
case 'i':
v9 = 0;
LABEL_27:
result = v9 == 0 ? 97 : 65;
break;
case 'j':
v10 = 0;
LABEL_30:
result = v10 == 0 ? 122 : 90;
break;
case 'k':
v11 = 0;
LABEL_33:
result = v11 == 0 ? 98 : 66;
break;
case 'l':
result = 99LL;
break;
case 'm':
v12 = 0;
LABEL_36:
result = v12 == 0 ? 109 : 77;
break;
case 'n':
v13 = 0;
LABEL_39:
result = v13 == 0 ? 100 : 68;
break;
case 'o':
v14 = 0;
LABEL_42:
result = v14 == 0 ? 101 : 69;
break;
case 'p':
v15 = 0;
LABEL_45:
result = v15 == 0 ? 102 : 70;
break;
case 'q':
v16 = 0;
LABEL_48:
result = v16 == 0 ? 103 : 71;
break;
case 'r':
v17 = 0;
LABEL_51:
result = v17 == 0 ? 104 : 72;
break;
case 's':
v18 = 0;
LABEL_54:
result = v18 == 0 ? 106 : 74;
break;
case 't':
v19 = 0;
LABEL_57:
result = v19 == 0 ? 107 : 75;
break;
case 'u':
v20 = 0;
LABEL_60:
result = v20 == 0 ? 105 : 73;
break;
case 'v':
v21 = 0;
LABEL_63:
result = v21 == 0 ? 108 : 76;
break;
case 'w':
v22 = 0;
LABEL_66:
result = v22 == 0 ? 110 : 78;
break;
case 'x':
v23 = 0;
LABEL_69:
result = v23 == 0 ? 112 : 80;
break;
case 'y':
v24 = 0;
LABEL_72:
if ( options[3] )
result = v24 == 0 ? 121 : 89;
else
result = v24 == 0 ? 111 : 79;
break;
case 'z':
v25 = 0;
LABEL_77:
result = v25 == 0 ? 113 : 81;
break;
default:
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
__int64 result; // rax
char v2; // al
char v3; // al
char v4; // al
char v5; // al
char v6; // al
char v7; // al
char v8; // al
char v9; // al
char v10; // al
char v11; // al
char v12; // al
char v13; // al
char v14; // al
char v15; // al
char v16; // al
char v17; // al
char v18; // al
char v19; // al
char v20; // al
char v21; // al
char v22; // al
char v23; // al
char v24; // al
char v25; // al

result = (__int64)*_ctype_b_loc();
if ( (*(_BYTE *)(result + 2LL * a1 + 1) & 1) != 0 )
{
result = (unsigned __int8)((*_ctype_tolower_loc())[a1] - 97);
switch ( (char)result )
{
case 0:
result = 85LL;
break;
case 1:
v2 = 1;
goto LABEL_5;
case 2:
v3 = 1;
goto LABEL_9;
case 3:
v4 = 1;
goto LABEL_12;
case 4:
v5 = 1;
goto LABEL_15;
case 5:
v6 = 1;
goto LABEL_18;
case 6:
v7 = 1;
goto LABEL_21;
case 7:
v8 = 1;
goto LABEL_24;
case 8:
v9 = 1;
goto LABEL_27;
case 9:
v10 = 1;
goto LABEL_30;
case 10:
v11 = 1;
goto LABEL_33;
case 11:
result = 67LL;
break;
case 12:
v12 = 1;
goto LABEL_36;
case 13:
v13 = 1;
goto LABEL_39;
case 14:
v14 = 1;
goto LABEL_42;
case 15:
v15 = 1;
goto LABEL_45;
case 16:
v16 = 1;
goto LABEL_48;
case 17:
v17 = 1;
goto LABEL_51;
case 18:
v18 = 1;
goto LABEL_54;
case 19:
v19 = 1;
goto LABEL_57;
case 20:
v20 = 1;
goto LABEL_60;
case 21:
v21 = 1;
goto LABEL_63;
case 22:
v22 = 1;
goto LABEL_66;
case 23:
v23 = 1;
goto LABEL_69;
case 24:
v24 = 1;
goto LABEL_72;
case 25:
v25 = 1;
goto LABEL_77;
default:
return result;
}
}
else
{
switch ( a1 )
{
case 'a':
result = 117LL;
break;
case 'b':
v2 = 0;
LABEL_5:
result = v2 == 0 ? 114 : 82;
break;
case 'c':
v3 = 0;
LABEL_9:
result = v3 == 0 ? 115 : 83;
break;
case 'd':
v4 = 0;
LABEL_12:
result = v4 == 0 ? 116 : 84;
break;
case 'e':
v5 = 0;
LABEL_15:
result = v5 == 0 ? 111 : 79;
break;
case 'f':
v6 = 0;
LABEL_18:
result = v6 == 0 ? 118 : 86;
break;
case 'g':
v7 = 0;
LABEL_21:
result = v7 == 0 ? 119 : 87;
break;
case 'h':
v8 = 0;
LABEL_24:
result = v8 == 0 ? 120 : 88;
break;
case 'i':
v9 = 0;
LABEL_27:
result = v9 == 0 ? 97 : 65;
break;
case 'j':
v10 = 0;
LABEL_30:
result = v10 == 0 ? 122 : 90;
break;
case 'k':
v11 = 0;
LABEL_33:
result = v11 == 0 ? 98 : 66;
break;
case 'l':
result = 99LL;
break;
case 'm':
v12 = 0;
LABEL_36:
result = v12 == 0 ? 109 : 77;
break;
case 'n':
v13 = 0;
LABEL_39:
result = v13 == 0 ? 100 : 68;
break;
case 'o':
v14 = 0;
LABEL_42:
result = v14 == 0 ? 101 : 69;
break;
case 'p':
v15 = 0;
LABEL_45:
result = v15 == 0 ? 102 : 70;
break;
case 'q':
v16 = 0;
LABEL_48:
result = v16 == 0 ? 103 : 71;
break;
case 'r':
v17 = 0;
LABEL_51:
result = v17 == 0 ? 104 : 72;
break;
case 's':
v18 = 0;
LABEL_54:
result = v18 == 0 ? 106 : 74;
break;
case 't':
v19 = 0;
LABEL_57:
result = v19 == 0 ? 107 : 75;
break;
case 'u':
v20 = 0;
LABEL_60:
result = v20 == 0 ? 105 : 73;
break;
case 'v':
v21 = 0;
LABEL_63:
result = v21 == 0 ? 108 : 76;
break;
case 'w':
v22 = 0;
LABEL_66:
result = v22 == 0 ? 110 : 78;
break;
case 'x':
v23 = 0;
LABEL_69:
result = v23 == 0 ? 112 : 80;
break;
case 'y':
v24 = 0;
LABEL_72:
if ( options[3] )
result = v24 == 0 ? 121 : 89;
else
result = v24 == 0 ? 111 : 79;
break;
case 'z':
v25 = 0;
LABEL_77:
result = v25 == 0 ? 113 : 81;
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)
{
char *v1; // rdi
char *v2; // rax
char v3; // dl
__int64 v4; // rax
char *v5; // rdx
char v7[32776]; // [rsp+0h] [rbp-8008h] BYREF

memset(extension, 0, sizeof(extension));
memset(v7, 0, 0x8000uLL);
v1 = &s[(int)(strlen(s) - 1)];
v2 = v7;
do
{
v3 = *v1;
*v2++ = *v1--;
}
while ( v3 != 46 );
LODWORD(v4) = strlen(v7) - 1;
if ( (int)v4 >= 0 )
{
v4 = (int)v4;
v5 = extension;
do
*v5++ = v7[v4--];
while ( (int)v4 >= 0 );
}
return extension;
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
char *v1; // rdi
char *v2; // rax
char v3; // dl
__int64 v4; // rax
char *v5; // rdx
char v7[32776]; // [rsp+0h] [rbp-8008h] BYREF

memset(extension, 0, sizeof(extension));
memset(v7, 0, 0x8000uLL);
v1 = &s[(int)(strlen(s) - 1)];
v2 = v7;
do
{
v3 = *v1;
*v2++ = *v1--;
}
while ( v3 != 46 );
LODWORD(v4) = strlen(v7) - 1;
if ( (int)v4 >= 0 )
{
v4 = (int)v4;
v5 = extension;
do
*v5++ = v7[v4--];
while ( (int)v4 >= 0 );
}
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 *


original_code:
char *rand_filename(char *random_filename, unsigned int min_length, unsigned int max_length, _Bool add_extension)
{
    int x, length, num;
    static _Bool selector;
    static long long runtime = 0;
    srand((unsigned)clock() + runtime + (time(((void *)0)) - 800500));
    while((length = rand() % max_length) < min_length)
        ;
    if(selector)
        selector = 0;
    else
        selector = 1;
    srand((unsigned)time(((void *)0)) + runtime);
    for(x = 0; x < length; x++) {
        num = rand() % 63;
        if(selector)
            num = 62 - num;
        switch(num) {
            case 0:
                random_filename[x] = '0'; break;
            case 1:
                random_filename[x] = '1'; break;
            case 2:
                random_filename[x] = '2'; break;
            case 3:
                random_filename[x] = '3'; break;
            case 4:
                random_filename[x] = '4'; break;
            case 5:
                random_filename[x] = '5'; break;
            case 6:
                random_filename[x] = '6'; break;
            case 7:
                random_filename[x] = '7'; break;
            case 8:
                random_filename[x] = '8'; break;
            case 9:
                random_filename[x] = '9'; break;
            case 10:
                random_filename[x] = 'a'; break;
            case 11:
                random_filename[x] = 'b'; break;
            case 12:
                random_filename[x] = 'c'; break;
            case 13:
                random_filename[x] = 'd'; break;
            case 14:
                random_filename[x] = 'e'; break;
            case 15:
                random_filename[x] = 'f'; break;
            case 16:
                random_filename[x] = 'g'; break;
            case 17:
                random_filename[x] = 'h'; break;
            case 18:
                random_filename[x] = 'i'; break;
            case 19:
                random_filename[x] = 'j'; break;
            case 20:
                random_filename[x] = 'k'; break;
            case 21:
                random_filename[x] = 'l'; break;
            case 22:
                random_filename[x] = 'm'; break;
            case 23:
                random_filename[x] = 'n'; break;
            case 24:
                random_filename[x] = 'o'; break;
            case 25:
                random_filename[x] = 'p'; break;
            case 26:
                random_filename[x] = 'q'; break;
            case 27:
                random_filename[x] = 'r'; break;
            case 28:
                random_filename[x] = 's'; break;
            case 29:
                random_filename[x] = 't'; break;
            case 30:
                random_filename[x] = 'u'; break;
            case 31:
                random_filename[x] = 'v'; break;
            case 32:
                random_filename[x] = 'w'; break;
            case 33:
                random_filename[x] = 'x'; break;
            case 34:
                random_filename[x] = 'y'; break;
            case 35:
                random_filename[x] = 'z'; break;
            case 36:
                random_filename[x] = 'A'; break;
            case 37:
                random_filename[x] = 'B'; break;
            case 38:
                random_filename[x] = 'C'; break;
            case 39:
                random_filename[x] = 'D'; break;
            case 40:
                random_filename[x] = 'E'; break;
            case 41:
                random_filename[x] = 'F'; break;
            case 42:
                random_filename[x] = 'G'; break;
            case 43:
                random_filename[x] = 'H'; break;
            case 44:
                random_filename[x] = 'I'; break;
            case 45:
                random_filename[x] = 'J'; break;
            case 46:
                random_filename[x] = 'K'; break;
            case 47:
                random_filename[x] = 'L'; break;
            case 48:
                random_filename[x] = 'M'; break;
            case 49:
                random_filename[x] = 'N'; break;
            case 50:
                random_filename[x] = 'O'; break;
            case 51:
                random_filename[x] = 'P'; break;
            case 52:
                random_filename[x] = 'Q'; break;
            case 53:
                random_filename[x] = 'R'; break;
            case 54:
                random_filename[x] = 'S'; break;
            case 55:
                random_filename[x] = 'T'; break;
            case 56:
                random_filename[x] = 'U'; break;
            case 57:
                random_filename[x] = 'V'; break;
            case 58:
                random_filename[x] = 'W'; break;
            case 59:
                random_filename[x] = 'X'; break;
            case 60:
                random_filename[x] = 'Y'; break;
            case 61:
                random_filename[x] = 'Z'; break;
            case 62:
                random_filename[x] = '_'; break;
            default:
                random_filename[x] = '_';
                break;
        }
    }
    if(add_extension)
        strcat(random_filename, extension);
    runtime++;
    return random_filename;
}

canonical_original_code:
char *rand_filename(char *random_filename, unsigned int min_length, unsigned int max_length, _Bool add_extension)
{
    int x; int length; int num;
    static _Bool selector;
    static long long runtime = 0;
    srand((unsigned int)clock() + runtime + (time(((void *)0)) - 800500));
    while((length = rand() % max_length) < min_length)
        ;
    if(selector)
        selector = 0;
    else
        selector = 1;
    srand((unsigned int)time(((void *)0)) + runtime);
    for(x = 0; x < length; x++) {
        num = rand() % 63;
        if(selector)
            num = 62 - num;
        switch(num) {
            case 0:
                random_filename[x] = '0'; break;
            case 1:
                random_filename[x] = '1'; break;
            case 2:
                random_filename[x] = '2'; break;
            case 3:
                random_filename[x] = '3'; break;
            case 4:
                random_filename[x] = '4'; break;
            case 5:
                random_filename[x] = '5'; break;
            case 6:
                random_filename[x] = '6'; break;
            case 7:
                random_filename[x] = '7'; break;
            case 8:
                random_filename[x] = '8'; break;
            case 9:
                random_filename[x] = '9'; break;
            case 10:
                random_filename[x] = 'a'; break;
            case 11:
                random_filename[x] = 'b'; break;
            case 12:
                random_filename[x] = 'c'; break;
            case 13:
                random_filename[x] = 'd'; break;
            case 14:
                random_filename[x] = 'e'; break;
            case 15:
                random_filename[x] = 'f'; break;
            case 16:
                random_filename[x] = 'g'; break;
            case 17:
                random_filename[x] = 'h'; break;
            case 18:
                random_filename[x] = 'i'; break;
            case 19:
                random_filename[x] = 'j'; break;
            case 20:
                random_filename[x] = 'k'; break;
            case 21:
                random_filename[x] = 'l'; break;
            case 22:
                random_filename[x] = 'm'; break;
            case 23:
                random_filename[x] = 'n'; break;
            case 24:
                random_filename[x] = 'o'; break;
            case 25:
                random_filename[x] = 'p'; break;
            case 26:
                random_filename[x] = 'q'; break;
            case 27:
                random_filename[x] = 'r'; break;
            case 28:
                random_filename[x] = 's'; break;
            case 29:
                random_filename[x] = 't'; break;
            case 30:
                random_filename[x] = 'u'; break;
            case 31:
                random_filename[x] = 'v'; break;
            case 32:
                random_filename[x] = 'w'; break;
            case 33:
                random_filename[x] = 'x'; break;
            case 34:
                random_filename[x] = 'y'; break;
            case 35:
                random_filename[x] = 'z'; break;
            case 36:
                random_filename[x] = 'A'; break;
            case 37:
                random_filename[x] = 'B'; break;
            case 38:
                random_filename[x] = 'C'; break;
            case 39:
                random_filename[x] = 'D'; break;
            case 40:
                random_filename[x] = 'E'; break;
            case 41:
                random_filename[x] = 'F'; break;
            case 42:
                random_filename[x] = 'G'; break;
            case 43:
                random_filename[x] = 'H'; break;
            case 44:
                random_filename[x] = 'I'; break;
            case 45:
                random_filename[x] = 'J'; break;
            case 46:
                random_filename[x] = 'K'; break;
            case 47:
                random_filename[x] = 'L'; break;
            case 48:
                random_filename[x] = 'M'; break;
            case 49:
                random_filename[x] = 'N'; break;
            case 50:
                random_filename[x] = 'O'; break;
            case 51:
                random_filename[x] = 'P'; break;
            case 52:
                random_filename[x] = 'Q'; break;
            case 53:
                random_filename[x] = 'R'; break;
            case 54:
                random_filename[x] = 'S'; break;
            case 55:
                random_filename[x] = 'T'; break;
            case 56:
                random_filename[x] = 'U'; break;
            case 57:
                random_filename[x] = 'V'; break;
            case 58:
                random_filename[x] = 'W'; break;
            case 59:
                random_filename[x] = 'X'; break;
            case 60:
                random_filename[x] = 'Y'; break;
            case 61:
                random_filename[x] = 'Z'; break;
            case 62:
                random_filename[x] = '_'; break;
            default:
                random_filename[x] = '_';
                break;
        }
    }
    if(add_extension)
        strcat(random_filename, extension);
    runtime++;
    return random_filename;
}

variable_types: length int

variable_types: num int

variable_types:
runtime
long long


results

decompiled_code:
int results()
{
printf("\n\nI found %llu prime numbers from %llu to %llu!!!\n", prime_numbers, first_range, second_range);
printf("-------------------------------------------------------------------------------");
fprintf(primefile, "\n\nI found %llu prime numbers from %llu to %llu!!!\n", prime_numbers, first_range, second_range);
return fclose(primefile);
}

canonical_decompiled_code:
int func1()
{
printf("\n\nI found %llu prime numbers from %llu to %llu!!!\n", prime_numbers, first_range, second_range);
printf("-------------------------------------------------------------------------------");
fprintf(primefile, "\n\nI found %llu prime numbers from %llu to %llu!!!\n", prime_numbers, first_range, second_range);
return fclose(primefile);
}

original_code:
void results(void)
{
 printf("\n\nI found " "%llu" " prime numbers from " "%llu" " to " "%llu" "!!!\n",prime_numbers,first_range,second_range);
 printf("-------------------------------------------------------------------------------");
 fprintf(primefile,"\n\nI found " "%llu" " prime numbers from " "%llu" " to " "%llu" "!!!\n",prime_numbers,first_range,second_range);
 fclose(primefile);
}

canonical_original_code:
void results()
{
 printf("\n\nI found " "%llu" " prime numbers from " "%llu" " to " "%llu" "!!!\n",prime_numbers,first_range,second_range);
 printf("-------------------------------------------------------------------------------");
 fprintf(primefile,"\n\nI found " "%llu" " prime numbers from " "%llu" " to " "%llu" "!!!\n",prime_numbers,first_range,second_range);
 fclose(primefile);
}


decompiled_code:
char *get_date()
{
struct tm *v0; // rax
__int64 v1; // rdx
const char *v2; // rsi
time_t timer; // [rsp+8h] [rbp-50h] BYREF
__int64 v5[9]; // [rsp+10h] [rbp-48h]

v5[0] = (__int64)"Sunday";
v5[1] = (__int64)"Monday";
v5[2] = (__int64)"Tuesday";
v5[3] = (__int64)"Wednesday";
v5[4] = (__int64)"Thursday";
v5[5] = (__int64)"Friday";
v5[6] = (__int64)"Saturday";
time(&timer);
v0 = localtime(&timer);
v1 = (unsigned int)v0->tm_hour;
if ( (int)v1 <= 12 )
{
v2 = (const char *)&unk_283;
}
else
{
v1 = (unsigned int)(v1 - 12);
v2 = (const char *)&unk_280;
}
sprintf(
output_0,
"; Generated %s, %d/%d/%d, at %d:%02d:%02d %s\n;\n",
(const char *)v5[v0->tm_wday],
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday,
(unsigned int)(v0->tm_year + 1900),
v1,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec,
v2);
return output_0;
}

canonical_decompiled_code:
char *func0()
{
struct tm *v0; // rax
__int64 v1; // rdx
const char *v2; // rsi
time_t timer; // [rsp+8h] [rbp-50h] BYREF
__int64 v5[9]; // [rsp+10h] [rbp-48h]

v5[0] = (__int64)"Sunday";
v5[1] = (__int64)"Monday";
v5[2] = (__int64)"Tuesday";
v5[3] = (__int64)"Wednesday";
v5[4] = (__int64)"Thursday";
v5[5] = (__int64)"Friday";
v5[6] = (__int64)"Saturday";
time(&timer);
v0 = localtime(&timer);
v1 = (unsigned int)v0->tm_hour;
if ( (int)v1 <= 12 )
{
v2 = (const char *)&unk_283;
}
else
{
v1 = (unsigned int)(v1 - 12);
v2 = (const char *)&unk_280;
}
sprintf(
output_0,
"; Generated %s, %d/%d/%d, at %d:%02d:%02d %s\n;\n",
(const char *)v5[v0->tm_wday],
(unsigned int)(v0->tm_mon + 1),
(unsigned int)v0->tm_mday,
(unsigned int)(v0->tm_year + 1900),
v1,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec,
v2);
return output_0;
}

original_code:
char *get_date(void) {
 int month;
 int day;
 int year;
 char *wdays[] = {
  "Sunday",
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday"
 };
 struct tm *t;
 time_t now;
 static char output[256];
 time(&now);
 t = localtime(&now);
 month = t->tm_mon;
 day = t->tm_mday;
 year = t->tm_year;
 sprintf(output,
  "; Generated %s, %d/%d/%d, at %d:%02d:%02d %s\n;\n",
  wdays[t->tm_wday],
  month +1, day, year + 1900,
  t->tm_hour > 12 ? t->tm_hour - 12 : t->tm_hour,
  t->tm_min,
  t->tm_sec,
  t->tm_hour > 12 ? "PM" : "AM"
 );
 return output;
}

canonical_original_code:
char *get_date() {
 int month;
 int day;
 int year;
 char *wdays[] = {
  "Sunday",
  "Monday",
  "Tuesday",
  "Wednesday",
  "Thursday",
  "Friday",
  "Saturday"
 };
 struct tm *t;
 long now;
 static char output[256];
 time(&now);
 t = localtime(&now);
 month = t->tm_mon;
 day = t->tm_mday;
 year = t->tm_year;
 sprintf(output,
  "; Generated %s, %d/%d/%d, at %d:%02d:%02d %s\n;\n",
  wdays[t->tm_wday],
  month +1, day, year + 1900,
  t->tm_hour > 12 ? t->tm_hour - 12 : t->tm_hour,
  t->tm_min,
  t->tm_sec,
  t->tm_hour > 12 ? "PM" : "AM"
 );
 return output;
}

variable_types: month int

variable_types: day int

variable_types: year int

variable_types:
wdays
char *[]

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types: now long

variable_types:
output
char [256]


struppercpy

decompiled_code:
__int64 __fastcall struppercpy(__int64 a1, __int64 a2)
{
const __int32_t **v3; // rsi
__int64 result; // rax
__int32_t v5; // edx

v3 = __ctype_toupper_loc();
result = 0LL;
do
{
v5 = (*v3)[*(char *)(a2 + result)];
*(_BYTE *)(a1 + result++) = v5;
}
while ( (_BYTE)v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
const __int32_t **v3; // rsi
__int64 result; // rax
__int32_t v5; // edx

v3 = __ctype_toupper_loc();
result = 0LL;
do
{
v5 = (*v3)[*(char *)(a2 + result)];
*(_BYTE *)(a1 + result++) = v5;
}
while ( (_BYTE)v5 );
return result;
}

original_code:
void struppercpy(char *output, char *string)
{
  while(*output++ = toupper(*string++));
}

variable_types:
string
char *


welcome

decompiled_code:
int welcome()
{
return puts("\nHexdump v 0.1.2 - Copyright (C) 2008 samus250\nThis software comes with ABSOLUTELY NO WARRANTY.\n");
}

canonical_decompiled_code:
int func7()
{
return puts("\nHexdump v 0.1.2 - Copyright (C) 2008 samus250\nThis software comes with ABSOLUTELY NO WARRANTY.\n");
}

original_code:
void welcome(void)
{
  printf("\n"
      "Hexdump" " " "v 0.1.2" " - Copyright (C) 2008 samus250\n"
      "This software comes with ABSOLUTELY NO WARRANTY.\n\n");
  return;
}

canonical_original_code:
void welcome()
{
  printf("\n"
      "Hexdump" " " "v 0.1.2" " - Copyright (C) 2008 samus250\n"
      "This software comes with ABSOLUTELY NO WARRANTY.\n\n");
  return;
}


help

decompiled_code:
int help()
{
return puts("Usage: [input file] [output file] [array name]");
}

canonical_decompiled_code:
int func8()
{
return puts("Usage: [input file] [output file] [array name]");
}

original_code:
void help(void)
{
  printf("Usage: [input file] [output file] [array name]\n");
  return;
}

canonical_original_code:
void help()
{
  printf("Usage: [input file] [output file] [array name]\n");
  return;
}


primegen

decompiled_code:
__int64 primegen()
{
unsigned __int64 v0; // rbx
__int64 result; // rax
char v2; // bp
char v3; // r15
__int16 v4; // r13
unsigned __int64 v5; // rcx
__int64 v6; // [rsp+8h] [rbp-40h]

v0 = first_range;
result = 2LL;
if ( first_range == 1LL )
v0 = 2LL;
v2 = v0 & 1;
if ( v0 <= second_range )
{
v3 = 0;
v4 = 1;
v6 = 2LL;
while ( 1 )
{
if ( (v0 & 1) != 0 || v0 == 2 )
{
if ( v0 <= 8 )
goto LABEL_5;
if ( v0 != v0 / 3 + (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)v0) >> 64) & 0xFFFFFFFFFFFFFFFELL) )
break;
}
LABEL_10:
result = v0;
v0 += (v2 & 1) + 1LL;
v2 = 1;
if ( second_range < v0 )
return result;
}
v5 = 3LL;
while ( 1 )
{
v5 += 2LL;
if ( v5 * v5 > v0 )
break;
if ( !(v0 % v5) )
goto LABEL_10;
}
LABEL_5:
printf("%llu\t", v0);
if ( !v3 )
fwrite(&unk_172, 1uLL, 2uLL, primefile);
fprintf(primefile, "\t%llu", v0);
if ( v4 == 10 )
{
fprintf(primefile, "\n%llu.", v6++);
v4 = 0;
}
++prime_numbers;
++v4;
v3 = 1;
goto LABEL_10;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned __int64 v0; // rbx
__int64 result; // rax
char v2; // bp
char v3; // r15
__int16 v4; // r13
unsigned __int64 v5; // rcx
__int64 v6; // [rsp+8h] [rbp-40h]

v0 = first_range;
result = 2LL;
if ( first_range == 1LL )
v0 = 2LL;
v2 = v0 & 1;
if ( v0 <= second_range )
{
v3 = 0;
v4 = 1;
v6 = 2LL;
while ( 1 )
{
if ( (v0 & 1) != 0 || v0 == 2 )
{
if ( v0 <= 8 )
goto LABEL_5;
if ( v0 != v0 / 3 + (((0xAAAAAAAAAAAAAAABLL * (unsigned __int128)v0) >> 64) & 0xFFFFFFFFFFFFFFFELL) )
break;
}
LABEL_10:
result = v0;
v0 += (v2 & 1) + 1LL;
v2 = 1;
if ( second_range < v0 )
return result;
}
v5 = 3LL;
while ( 1 )
{
v5 += 2LL;
if ( v5 * v5 > v0 )
break;
if ( !(v0 % v5) )
goto LABEL_10;
}
LABEL_5:
printf("%llu\t", v0);
if ( !v3 )
fwrite(&unk_172, 1uLL, 2uLL, primefile);
fprintf(primefile, "\t%llu", v0);
if ( v4 == 10 )
{
fprintf(primefile, "\n%llu.", v6++);
v4 = 0;
}
++prime_numbers;
++v4;
v3 = 1;
goto LABEL_10;
}
return result;
}

original_code:
void primegen(void)
{
 u_long_64 number_to_check,file_linecount=2;
 u_short filecount=1;
 _Bool line_number_switch=0,prime=1;
 _Bool pair=0;
 u_long_64 i;
 number_to_check=first_range;
 if(number_to_check==1)
 {
  number_to_check=2;
  pair=1;
 }
 pair = number_to_check % 2;
 while(number_to_check<=second_range)
 {
  if(number_to_check % 2 == 0 && number_to_check != 2)
  {
   prime = 0;
  }
  else
  {
   for(i=3; i*i <= number_to_check; i+=2)
   {
    if(number_to_check % i == 0)
    {
     prime = 0;
     break;
    }
   }
  }
  if(prime)
  {
   printf("%llu" "\t",number_to_check);
   if(line_number_switch==0)
   {
    fprintf(primefile,"1.");
    line_number_switch=1;
   }
   fprintf(primefile,"\t" "%llu" ,number_to_check);
   if(filecount==10)
   {
    fprintf(primefile,"\n" "%llu" ".",file_linecount);
    filecount=0;
    file_linecount++;
   }
   prime_numbers++;
   filecount++;
  }
  if(pair)
  {
   number_to_check+=2;
  }
  else
  {
   number_to_check++;
   pair=1;
  }
  prime=1;
 }
 line_number_switch=0;
 filecount=1;
 file_linecount=2;
}

canonical_original_code:
void primegen()
{
 unsigned long long number_to_check; unsigned long long file_linecount = 2;
 unsigned short filecount = 1;
 _Bool line_number_switch = 0; _Bool prime = 1;
 _Bool pair = 0;
 unsigned long long i;
 number_to_check=first_range;
 if(number_to_check==1)
 {
  number_to_check=2;
  pair=1;
 }
 pair = number_to_check % 2;
 while(number_to_check<=second_range)
 {
  if(number_to_check % 2 == 0 && number_to_check != 2)
  {
   prime = 0;
  }
  else
  {
   for(i=3; i*i <= number_to_check; i+=2)
   {
    if(number_to_check % i == 0)
    {
     prime = 0;
     break;
    }
   }
  }
  if(prime)
  {
   printf("%llu" "\t",number_to_check);
   if(line_number_switch==0)
   {
    fprintf(primefile,"1.");
    line_number_switch=1;
   }
   fprintf(primefile,"\t" "%llu" ,number_to_check);
   if(filecount==10)
   {
    fprintf(primefile,"\n" "%llu" ".",file_linecount);
    filecount=0;
    file_linecount++;
   }
   prime_numbers++;
   filecount++;
  }
  if(pair)
  {
   number_to_check+=2;
  }
  else
  {
   number_to_check++;
   pair=1;
  }
  prime=1;
 }
 line_number_switch=0;
 filecount=1;
 file_linecount=2;
}

variable_types:
filecount
unsigned short

variable_types:
i
unsigned long long


myrealloc

decompiled_code:
void *__fastcall myrealloc(void *a1, size_t a2)
{
void *result; // rax

if ( a1 )
result = realloc(a1, a2);
else
result = malloc(a2);
return result;
}

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

if ( a1 )
result = realloc(a1, a2);
else
result = malloc(a2);
return result;
}

original_code:
static void *myrealloc(void *ptr, size_t size)
{
    if(ptr)
        return realloc(ptr, size);
    else
        return malloc(size);
}

canonical_original_code:
static void *myrealloc(void *ptr, unsigned long size)
{
    if(ptr)
        return realloc(ptr, size);
    else
        return malloc(size);
}

variable_types:
ptr
void *

variable_types:
size
unsigned long

return_type: void *


decompiled_code:
size_t __fastcall write_mem_callback(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbp
char *v6; // rax
size_t v7; // rax

v5 = a3 * a2;
v6 = (char *)myrealloc(*(void **)a4, a3 * a2 + *(_QWORD *)(a4 + 8) + 1);
*(_QWORD *)a4 = v6;
if ( v6 )
{
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_QWORD *)(a4 + 8) + v5;
*(_QWORD *)(a4 + 8) = v7;
*(_BYTE *)(*(_QWORD *)a4 + v7) = 0;
}
return v5;
}

original_code:
static size_t write_mem_callback(void *ptr, size_t size, size_t nmemb, void *data)
{
    size_t realsize = size * nmemb;
    struct MemoryStruct *mem = (struct MemoryStruct *)data;
    mem->memory = myrealloc(mem->memory, mem->size + realsize + 1);
    if (mem->memory) {
        memcpy(&(mem->memory[mem->size]), ptr, realsize);
        mem->size += realsize;
        mem->memory[mem->size] = 0;
    }
    return realsize;
}

canonical_original_code:
static unsigned long write_mem_callback(void *ptr, unsigned long size, unsigned long nmemb, void *data)
{
    unsigned long realsize = size * nmemb;
    struct MemoryStruct *mem = (struct MemoryStruct *)data;
    mem->memory = myrealloc(mem->memory, mem->size + realsize + 1);
    if (mem->memory) {
        memcpy(&(mem->memory[mem->size]), ptr, realsize);
        mem->size += realsize;
        mem->memory[mem->size] = 0;
    }
    return realsize;
}

variable_types:
nmemb
unsigned long

variable_types:
data
void *

variable_types:
realsize
unsigned long

variable_types: struct MemoryStruct { char *memory; unsigned long size; } *

return_type: unsigned long


original_code:
void print_progress(double total, double now)
{
    int perc = 0;
    double i = 0;
    fprintf(stderr, "\r");
    if(total > 0) {
        perc = (int)((now / total) * 100);
        fprintf(stderr, "%3d%%",perc);
        fprintf(stderr, "|");
        for (i = 0; i < 100 / 3; i++) {
            if (i == perc / 3)
                fprintf(stderr, "*");
            else
                fprintf(stderr, "-");
        }
        fprintf(stderr, "|");
    }
    if(now / 1024 < 1024)
        fprintf(stderr, " %.0f KB", now / 1024);
    else if(now / (1024 * 1024) < 1024)
        fprintf(stderr, " %.2f MB", now / (1024*1024));
    else
        fprintf(stderr, " %.2f GB", now / (1024*1024*1024));
    if(total > 0) {
        fprintf(stderr, " /");
        if(total / 1024 < 1024)
            fprintf(stderr, " %.0f KB", total / 1024);
        else if(total / (1024 * 1024) < 1024)
            fprintf(stderr, " %.2f MB", total / (1024*1024));
        else
            fprintf(stderr, " %.2f GB", total / (1024*1024*1024));
    }
    return;
}

variable_types: total double

variable_types: now double

variable_types: perc int

variable_types: i double


decompiled_code:
__int64 __fastcall progress_callback(void *a1, double a2, double a3, double a4, double a5)
{
if ( a2 <= 0.0 && a3 <= 0.0 )
{
if ( a4 <= 0.0 && a5 <= 0.0 )
{
fwrite("\rUnknown Progress...", 1uLL, 0x14uLL, stderr);
return 0LL;
}
a3 = a5;
a2 = a4;
}
print_progress(a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1, double a2, double a3, double a4, double a5)
{
if ( a2 <= 0.0 && a3 <= 0.0 )
{
if ( a4 <= 0.0 && a5 <= 0.0 )
{
fwrite("\rUnknown Progress...", 1uLL, 0x14uLL, stderr);
return 0LL;
}
a3 = a5;
a2 = a4;
}
func0(a2, a3);
return 0LL;
}

original_code:
int progress_callback(void *clientp,
                        double dltotal, double dlnow,
                        double ultotal, double ulnow)
{
    if(dltotal > 0 || dlnow > 0)
        print_progress(dltotal, dlnow);
    else if (ultotal > 0 || ulnow > 0)
        print_progress(ultotal, ulnow);
    else
        fprintf(stderr, "\rUnknown Progress...");
    return 0;
}

variable_types:
clientp
void *

variable_types: dltotal double

variable_types: dlnow double

variable_types: ultotal double

variable_types: ulnow double


canonical_original_code:
void print_progress(double total, double now)
{
    int perc = 0;
    double i = 0;
    fprintf(stderr, "\r");
    if(total > 0) {
        perc = (int)((now / total) * 100);
        fprintf(stderr, "%3d%%",perc);
        fprintf(stderr, "|");
        for (i = 0; i < 100 / 3; i++) {
            if (i == perc / 3)
                fprintf(stderr, "*");
            else
                fprintf(stderr, "-");
        }
        fprintf(stderr, "|");
    }
    if(now / 1024 < 1024)
        fprintf(stderr, " %.0f KB", now / 1024);
    else if(now / (1024 * 1024) < 1024)
        fprintf(stderr, " %.2f MB", now / (1024*1024));
    else
        fprintf(stderr, " %.2f GB", now / (1024*1024*1024));
    if(total > 0) {
        fprintf(stderr, " /");
        if(total / 1024 < 1024)
            fprintf(stderr, " %.0f KB", total / 1024);
        else if(total / (1024 * 1024) < 1024)
            fprintf(stderr, " %.2f MB", total / (1024*1024));
        else
            fprintf(stderr, " %.2f GB", total / (1024*1024*1024));
    }
    return;
}


decompiled_code:
__int64 __fastcall progress_callback(double a1, double a2, double a3, double a4)
{
if ( a1 <= 0.0 && a2 <= 0.0 )
{
if ( a3 <= 0.0 && a4 <= 0.0 )
fwrite("\rUnknown Progress...", 1uLL, 0x14uLL, stderr);
else
print_progress(a3, a4);
}
else
{
print_progress(a1, a2);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(double a1, double a2, double a3, double a4)
{
if ( a1 <= 0.0 && a2 <= 0.0 )
{
if ( a3 <= 0.0 && a4 <= 0.0 )
fwrite("\rUnknown Progress...", 1uLL, 0x14uLL, stderr);
else
func0(a3, a4);
}
else
{
func0(a1, a2);
}
return 0LL;
}

canonical_original_code:
int progress_callback(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow)
{
    if(dltotal > 0 || dlnow > 0)
        print_progress(dltotal, dlnow);
    else if (ultotal > 0 || ulnow > 0)
        print_progress(ultotal, ulnow);
    else
        fprintf(stderr, "\rUnknown Progress...");
    return 0;
}


user_defined_types: struct MemoryStruct { char *memory; unsigned long size; }


repo: sanXVII/sima

decompiled_code:
int __fastcall print_usage(const char *a1)
{
return printf("Usage: %s [key]\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return printf("Usage: %s [key]\n", a1);
}

original_code:
static void print_usage( const char * prog )
{
 printf( "Usage: %s [key]\n", prog );
}

canonical_original_code:
static void print_usage(char *prog)
{
 printf( "Usage: %s [key]\n", prog );
}

variable_types:
prog
char *


decompiled_code:
int print_help()
{
puts("Simulation for Ants action.\n");
puts("Keys:");
puts(" -h, --help Print this help information about mosaic ants simulator.");
puts(" -i, --image <file> Image file.");
return putchar(10);
}

canonical_decompiled_code:
int func2()
{
puts("Simulation for Ants action.\n");
puts("Keys:");
puts(" -h, --help Print this help information about mosaic ants simulator.");
puts(" -i, --image <file> Image file.");
return putchar(10);
}

original_code:
static void print_help()
{
 printf( "Simulation for Ants action.\n\n" );
 printf( "Keys:\n" );
 printf( "     -h, --help                Print this help information about mosaic ants simulator.\n" );
 printf( "     -i, --image <file>        Image file.\n" );
 printf( "\n" );
}