decompiled_code:
__int64 __fastcall add_group(__int64 *a1, const char *a2)
{
__int64 v2; // rbx
_QWORD *v3; // r12
size_t v4; // rbp
char *v5; // rax
char *v6; // rax
__int64 v7; // rax
__int64 result; // rax

v2 = *a1;
if ( find_group(*a1, a2) )
return 0xFFFFFFFFLL;
v3 = malloc(0x20uLL);
if ( !v3 )
{
puts("Error when creating group pointer. Program will now exit. ");
exit(0);
}
v4 = (int)(strlen(a2) + 1);
v5 = (char *)malloc(v4);
*v3 = v5;
if ( !v5 )
{
puts("Error when adding group name. Program will now exit ");
exit(0);
}
v6 = strncpy(v5, a2, v4);
v3[3] = 0LL;
v6[v4] = 0;
if ( v2 )
{
do
{
v7 = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
*(_QWORD *)(v7 + 24) = v3;
result = 0LL;
}
else
{
result = 0LL;
*a1 = (__int64)v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, const char *a2)
{
__int64 v2; // rbx
_QWORD *v3; // r12
size_t v4; // rbp
char *v5; // rax
char *v6; // rax
__int64 v7; // rax
__int64 result; // rax

v2 = *a1;
if ( func1(*a1, a2) )
return 0xFFFFFFFFLL;
v3 = malloc(0x20uLL);
if ( !v3 )
{
puts("Error when creating group pointer. Program will now exit. ");
exit(0);
}
v4 = (int)(strlen(a2) + 1);
v5 = (char *)malloc(v4);
*v3 = v5;
if ( !v5 )
{
puts("Error when adding group name. Program will now exit ");
exit(0);
}
v6 = strncpy(v5, a2, v4);
v3[3] = 0LL;
v6[v4] = 0;
if ( v2 )
{
do
{
v7 = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
*(_QWORD *)(v7 + 24) = v3;
result = 0LL;
}
else
{
result = 0LL;
*a1 = (__int64)v3;
}
return result;
}

original_code:
int add_group(Group **group_list_ptr, const char *group_name) {
    if ( find_group(*group_list_ptr, group_name) ) {
        return -1;
    } else {
        Group *newGrp = malloc(sizeof(Group));
        if ( newGrp == ((void *)0) ) {
            printf("Error when creating group pointer. Program will now exit. \n");
            exit(0);
        } else {
            int LENGTH = strlen(group_name) + 1;
            newGrp->name = malloc(LENGTH);
            if ( newGrp->name == ((void *)0) ) {
                printf("Error when adding group name. Program will now exit \n");
                exit(0);
            } else {
                strncpy(newGrp->name, group_name, LENGTH );
                newGrp->name[LENGTH] = '\0';
                newGrp->next = ((void *)0);
            }
        }
        if ( *group_list_ptr == ((void *)0) ) {
            *group_list_ptr = newGrp;
            return 0;
        } else {
            Group *currentGrp = *group_list_ptr;
            while ( currentGrp->next ) {
                currentGrp = currentGrp->next;
            }
            currentGrp->next = newGrp;
            return 0;
        }
    }
}

canonical_original_code:
int add_group(struct group **group_list_ptr, char *group_name) {
    if ( find_group(*group_list_ptr, group_name) ) {
        return -1;
    } else {
        struct group *newGrp = malloc(sizeof(Group));
        if ( newGrp == ((void *)0) ) {
            printf("Error when creating group pointer. Program will now exit. \n");
            exit(0);
        } else {
            int LENGTH = strlen(group_name) + 1;
            newGrp->name = malloc(LENGTH);
            if ( newGrp->name == ((void *)0) ) {
                printf("Error when adding group name. Program will now exit \n");
                exit(0);
            } else {
                strncpy(newGrp->name, group_name, LENGTH );
                newGrp->name[LENGTH] = '\0';
                newGrp->next = ((void *)0);
            }
        }
        if ( *group_list_ptr == ((void *)0) ) {
            *group_list_ptr = newGrp;
            return 0;
        } else {
            struct group *currentGrp = *group_list_ptr;
            while ( currentGrp->next ) {
                currentGrp = currentGrp->next;
            }
            currentGrp->next = newGrp;
            return 0;
        }
    }
}

variable_types: struct group { char *name; struct user { char *name; double balance; struct user *next; } *users; struct xct { char *name; double amount; struct xct *next; } *xcts; struct group *next; } **

variable_types: LENGTH int


repo: aditibarbhai/buxfer

decompiled_code:
int __fastcall list_users(__int64 a1)
{
__int64 v1; // rbx
const char *v2; // rsi

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return puts(" ");
while ( 1 )
{
v2 = *(const char **)v1;
if ( !*(_QWORD *)(v1 + 16) )
break;
printf("%s \n", v2);
v1 = *(_QWORD *)(v1 + 16);
}
return printf("%s \n", v2);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
const char *v2; // rsi

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return puts(" ");
while ( 1 )
{
v2 = *(const char **)v1;
if ( !*(_QWORD *)(v1 + 16) )
break;
printf("%s \n", v2);
v1 = *(_QWORD *)(v1 + 16);
}
return printf("%s \n", v2);
}

original_code:
void list_users(Group *group) {
    User *userPtr = group->users;
    if ( userPtr ) {
        while ( userPtr->next ) {
            printf("%s \n", userPtr->name);
            userPtr = userPtr->next;
        }
        printf("%s \n", userPtr->name);
    } else printf(" \n");
}

canonical_original_code:
void list_users(struct group *group) {
    struct user *userPtr = group->users;
    if ( userPtr ) {
        while ( userPtr->next ) {
            printf("%s \n", userPtr->name);
            userPtr = userPtr->next;
        }
        printf("%s \n", userPtr->name);
    } else printf(" \n");
}

variable_types: struct group { char *name; struct user { char *name; double balance; struct user *next; } *users; struct xct { char *name; double amount; struct xct *next; } *xcts; struct group *next; } *

return_type: void

user_defined_types: struct group { char *name; struct user *users; struct xct *xcts; struct group *next; }


decompiled_code:
__int64 __fastcall under_paid(__int64 a1)
{
__int64 v1; // rbp
double v2; // xmm1_8
__int64 v3; // rbx
double v4; // xmm0_8
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = *(double *)(v1 + 8);
v3 = *(_QWORD *)(a1 + 8);
v4 = v2;
if ( *(_QWORD *)(v1 + 16) )
{
do
{
while ( v2 < v4 )
{
v3 = *(_QWORD *)(v3 + 16);
v4 = *(double *)(v3 + 8);
if ( !*(_QWORD *)(v3 + 16) )
goto LABEL_7;
}
puts(*(const char **)v3);
v3 = *(_QWORD *)(v3 + 16);
v2 = *(double *)(v1 + 8);
v4 = *(double *)(v3 + 8);
}
while ( *(_QWORD *)(v3 + 16) );
}
LABEL_7:
result = 0LL;
if ( v2 >= v4 )
{
puts(*(const char **)v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbp
double v2; // xmm1_8
__int64 v3; // rbx
double v4; // xmm0_8
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return 0xFFFFFFFFLL;
v2 = *(double *)(v1 + 8);
v3 = *(_QWORD *)(a1 + 8);
v4 = v2;
if ( *(_QWORD *)(v1 + 16) )
{
do
{
while ( v2 < v4 )
{
v3 = *(_QWORD *)(v3 + 16);
v4 = *(double *)(v3 + 8);
if ( !*(_QWORD *)(v3 + 16) )
goto LABEL_7;
}
puts(*(const char **)v3);
v3 = *(_QWORD *)(v3 + 16);
v2 = *(double *)(v1 + 8);
v4 = *(double *)(v3 + 8);
}
while ( *(_QWORD *)(v3 + 16) );
}
LABEL_7:
result = 0LL;
if ( v2 >= v4 )
{
puts(*(const char **)v3);
result = 0LL;
}
return result;
}

original_code:
int under_paid(Group *group) {
    User *currentUser = group->users;
    if ( currentUser ) {
        User *underPaid = currentUser;
        while ( currentUser->next ) {
            if ( currentUser->balance <= underPaid->balance ) {
                printf("%s\n", currentUser->name);
            }
            currentUser = currentUser->next;
        }
        if ( currentUser->balance <= underPaid->balance ) {
            printf("%s\n", currentUser->name );
        }
        return 0;
    } else return -1;
}

canonical_original_code:
int under_paid(struct group *group) {
    struct user *currentUser = group->users;
    if ( currentUser ) {
        struct user *underPaid = currentUser;
        while ( currentUser->next ) {
            if ( currentUser->balance <= underPaid->balance ) {
                printf("%s\n", currentUser->name);
            }
            currentUser = currentUser->next;
        }
        if ( currentUser->balance <= underPaid->balance ) {
            printf("%s\n", currentUser->name );
        }
        return 0;
    } else return -1;
}

variable_types: struct user { char *name; double balance; struct user *next; } *

return_type: int

user_defined_types: struct xct { char *name; double amount; struct xct *next; }


decompiled_code:
const char **__fastcall find_prev_user(__int64 a1, const char *a2)
{
const char **v2; // r12
char *v3; // rbx
int v4; // eax
const char **v6; // rbp

v2 = *(const char ***)(a1 + 8);
if ( !v2 )
return v2;
v3 = (char *)v2[2];
v4 = strcmp(*v2, a2);
if ( v3 )
{
if ( !v4 )
return v2;
while ( 1 )
{
v6 = (const char **)v3;
v3 = (char *)*((_QWORD *)v3 + 2);
v4 = strcmp(*v6, a2);
if ( !v3 )
break;
if ( !v4 )
return v2;
v2 = v6;
}
}
if ( v4 )
v2 = (const char **)v3;
return v2;
}

canonical_decompiled_code:
const char **__fastcall func5(__int64 a1, const char *a2)
{
const char **v2; // r12
char *v3; // rbx
int v4; // eax
const char **v6; // rbp

v2 = *(const char ***)(a1 + 8);
if ( !v2 )
return v2;
v3 = (char *)v2[2];
v4 = strcmp(*v2, a2);
if ( v3 )
{
if ( !v4 )
return v2;
while ( 1 )
{
v6 = (const char **)v3;
v3 = (char *)*((_QWORD *)v3 + 2);
v4 = strcmp(*v6, a2);
if ( !v3 )
break;
if ( !v4 )
return v2;
v2 = v6;
}
}
if ( v4 )
v2 = (const char **)v3;
return v2;
}

original_code:
User *find_prev_user(Group *group, const char *user_name) {
    User *previous, *current;
    if ( group->users ) {
        current = group->users;
        if( current->next == ((void *)0) ){
            if ( strcmp(current->name, user_name) == 0 ) {
                return current;
            } else return ((void *)0);
        } else {
            if ( strcmp(current->name, user_name) == 0 ) {
                return current;
            } else {
                previous = current;
                current = current->next;
                while ( current->next ) {
                    if ( strcmp(current->name, user_name) == 0 ) {
                        return previous;
                    }
                    previous = current;
                    current = current->next;
                }
                if(strcmp(current->name, user_name) == 0) {
                    return previous;
                }
            }
            return ((void *)0);
        }
    } else return ((void *)0);
}

canonical_original_code:
struct user *find_prev_user(struct group *group, char *user_name) {
    struct user *previous; struct user *current;
    if ( group->users ) {
        current = group->users;
        if( current->next == ((void *)0) ){
            if ( strcmp(current->name, user_name) == 0 ) {
                return current;
            } else return ((void *)0);
        } else {
            if ( strcmp(current->name, user_name) == 0 ) {
                return current;
            } else {
                previous = current;
                current = current->next;
                while ( current->next ) {
                    if ( strcmp(current->name, user_name) == 0 ) {
                        return previous;
                    }
                    previous = current;
                    current = current->next;
                }
                if(strcmp(current->name, user_name) == 0) {
                    return previous;
                }
            }
            return ((void *)0);
        }
    } else return ((void *)0);
}

variable_types: struct group { char *name; struct user *users; struct xct { char *name; double amount; struct xct *next; } *xcts; struct group *next; } *

return_type: struct user { char *name; double balance; struct user *next; } *


decompiled_code:
__int64 __fastcall add_user(__int64 a1, const char *a2)
{
_QWORD *v2; // rbx
size_t v3; // rbp
char *v4; // rax
char *v5; // rax
__int64 result; // rax

if ( find_prev_user(a1, a2) )
return 0xFFFFFFFFLL;
v2 = malloc(0x18uLL);
if ( !v2 )
{
puts("Error while creating a new user. Program will now exit. ");
exit(0);
}
v3 = (int)(strlen(a2) + 1);
v4 = (char *)malloc(v3);
*v2 = v4;
if ( !v4 )
{
puts("Error while creating user name. Program will now exit. ");
exit(0);
}
v5 = strncpy(v4, a2, v3);
v2[1] = 0LL;
v5[v3] = 0;
result = *(_QWORD *)(a1 + 8);
v2[2] = 0LL;
*(_QWORD *)(a1 + 8) = v2;
if ( result )
{
v2[2] = result;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2)
{
_QWORD *v2; // rbx
size_t v3; // rbp
char *v4; // rax
char *v5; // rax
__int64 result; // rax

if ( func5(a1, a2) )
return 0xFFFFFFFFLL;
v2 = malloc(0x18uLL);
if ( !v2 )
{
puts("Error while creating a new user. Program will now exit. ");
exit(0);
}
v3 = (int)(strlen(a2) + 1);
v4 = (char *)malloc(v3);
*v2 = v4;
if ( !v4 )
{
puts("Error while creating user name. Program will now exit. ");
exit(0);
}
v5 = strncpy(v4, a2, v3);
v2[1] = 0LL;
v5[v3] = 0;
result = *(_QWORD *)(a1 + 8);
v2[2] = 0LL;
*(_QWORD *)(a1 + 8) = v2;
if ( result )
{
v2[2] = result;
result = 0LL;
}
return result;
}

original_code:
int add_user(Group *group, const char *user_name) {
    if ( find_prev_user(group, user_name) != ((void *)0) ) {
        return -1;
    } else {
        User *newUsr = malloc(sizeof(User));
        if ( newUsr == ((void *)0) ) {
            printf("Error while creating a new user. Program will now exit. \n");
            exit(0);
        } else {
            int LENGTH = strlen(user_name) + 1;
            newUsr->name = malloc(LENGTH);
            if ( newUsr->name == ((void *)0) ) {
                printf("Error while creating user name. Program will now exit. \n");
                exit(0);
            } else {
                strncpy(newUsr->name, user_name, LENGTH );
                newUsr->name[LENGTH] = '\0';
                newUsr->balance = 0;
                newUsr->next = ((void *)0);
            }
        }
        if ( group->users == ((void *)0) ) {
            group->users = newUsr;
        } else {
            newUsr->next = group->users;
            group->users = newUsr;
        }
        return 0;
    }
}

canonical_original_code:
int add_user(struct group *group, char *user_name) {
    if ( find_prev_user(group, user_name) != ((void *)0) ) {
        return -1;
    } else {
        struct user *newUsr = malloc(sizeof(User));
        if ( newUsr == ((void *)0) ) {
            printf("Error while creating a new user. Program will now exit. \n");
            exit(0);
        } else {
            int LENGTH = strlen(user_name) + 1;
            newUsr->name = malloc(LENGTH);
            if ( newUsr->name == ((void *)0) ) {
                printf("Error while creating user name. Program will now exit. \n");
                exit(0);
            } else {
                strncpy(newUsr->name, user_name, LENGTH );
                newUsr->name[LENGTH] = '\0';
                newUsr->balance = 0;
                newUsr->next = ((void *)0);
            }
        }
        if ( group->users == ((void *)0) ) {
            group->users = newUsr;
        } else {
            newUsr->next = group->users;
            group->users = newUsr;
        }
        return 0;
    }
}

user_defined_types: struct user { char *name; double balance; struct user *next; }


decompiled_code:
__int64 __fastcall user_balance(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // rbx
unsigned int v4; // er12

if ( !*(_QWORD *)(a1 + 8) )
return (unsigned int)-1;
v2 = find_prev_user(a1, a2);
v3 = v2;
if ( !v2 )
return (unsigned int)-1;
if ( strcmp(*v2, a2) )
{
v4 = 0;
printf("$%.2f\n", *((double *)v3[2] + 1));
return v4;
}
printf("$%.2f\n", *((double *)v3 + 1));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // rbx
unsigned int v4; // er12

if ( !*(_QWORD *)(a1 + 8) )
return (unsigned int)-1;
v2 = func5(a1, a2);
v3 = v2;
if ( !v2 )
return (unsigned int)-1;
if ( strcmp(*v2, a2) )
{
v4 = 0;
printf("$%.2f\n", *((double *)v3[2] + 1));
return v4;
}
printf("$%.2f\n", *((double *)v3 + 1));
return 0LL;
}

original_code:
int user_balance(Group *group, const char *user_name) {
    User *currentUser = group->users;
    User *prevUser = ((void *)0);
    if( currentUser ) {
        prevUser = find_prev_user(group, user_name);
        if ( prevUser ) {
            if ( strcmp(prevUser->name, user_name) == 0 ) {
                printf("$%.2f\n", prevUser->balance);
                return 0;
            } else {
                printf("$%.2f\n", prevUser->next->balance);
                return 0;
            }
        } else return -1;
    } else return -1;
}

canonical_original_code:
int user_balance(struct group *group, char *user_name) {
    struct user *currentUser = group->users;
    struct user *prevUser = ((void *)0);
    if( currentUser ) {
        prevUser = find_prev_user(group, user_name);
        if ( prevUser ) {
            if ( strcmp(prevUser->name, user_name) == 0 ) {
                printf("$%.2f\n", prevUser->balance);
                return 0;
            } else {
                printf("$%.2f\n", prevUser->next->balance);
                return 0;
            }
        } else return -1;
    } else return -1;
}


decompiled_code:
__int64 __fastcall add_xct(__int64 a1, const char *a2, double a3)
{
const char **v3; // rax
__int64 v4; // rbp

v3 = find_prev_user(a1, a2);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = (__int64)v3;
if ( strcmp(*v3, a2) )
v4 = *(_QWORD *)(v4 + 16);
xct_helper(a1, a2, a3);
*(double *)(v4 + 8) = a3 + *(double *)(v4 + 8);
update_user_position(a1, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2, double a3)
{
const char **v3; // rax
__int64 v4; // rbp

v3 = func5(a1, a2);
if ( !v3 )
return 0xFFFFFFFFLL;
v4 = (__int64)v3;
if ( strcmp(*v3, a2) )
v4 = *(_QWORD *)(v4 + 16);
func8(a1, a2, a3);
*(double *)(v4 + 8) = a3 + *(double *)(v4 + 8);
func9(a1, v4);
return 0LL;
}

original_code:
int add_xct(Group *group, const char *user_name, double amount) {
    User *prevUser = ((void *)0);
    User *user = ((void *)0);
    prevUser = find_prev_user(group, user_name);
    if ( prevUser ) {
        if ( strcmp(prevUser->name, user_name) == 0 ) {
            user = prevUser;
        } else {
            user = prevUser->next;
        }
        _xct_helper(group, user_name, amount);
        user->balance = user->balance + amount;
        _update_user_position(group, user);
        return 0;
    } else return -1;
}

canonical_original_code:
int add_xct(struct group *group, char *user_name, double amount) {
    struct user *prevUser = ((void *)0);
    struct user *user = ((void *)0);
    prevUser = find_prev_user(group, user_name);
    if ( prevUser ) {
        if ( strcmp(prevUser->name, user_name) == 0 ) {
            user = prevUser;
        } else {
            user = prevUser->next;
        }
        _xct_helper(group, user_name, amount);
        user->balance = user->balance + amount;
        _update_user_position(group, user);
        return 0;
    } else return -1;
}

variable_types: amount double


decompiled_code:
int __fastcall recent_xct(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
int result; // eax

v2 = *(_QWORD *)(a1 + 16);
if ( !v2 )
return puts(" ");
v3 = a2;
if ( a2 > 0 )
{
do
{
result = printf("Transaction #%s; Amount: %.2f.\n", *(const char **)v2, *(double *)(v2 + 8));
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
break;
--v3;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rbp
int result; // eax

v2 = *(_QWORD *)(a1 + 16);
if ( !v2 )
return puts(" ");
v3 = a2;
if ( a2 > 0 )
{
do
{
result = printf("Transaction #%s; Amount: %.2f.\n", *(const char **)v2, *(double *)(v2 + 8));
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
break;
--v3;
}
while ( v3 );
}
return result;
}

original_code:
void recent_xct(Group *group, long nu_xct) {
    Xct *xctPtr = group->xcts;
    if( xctPtr == ((void *)0) ) {
        printf(" \n");
    } else {
        long num;
        for ( num = nu_xct ; num > 0; num-- ) {
            printf("Transaction #%s; Amount: %.2f.\n", xctPtr->name, xctPtr->amount);
            if( xctPtr->next == ((void *)0) ) {
                break;
            }
            xctPtr = xctPtr->next;
         }
    }
}

canonical_original_code:
void recent_xct(struct group *group, long nu_xct) {
    struct xct *xctPtr = group->xcts;
    if( xctPtr == ((void *)0) ) {
        printf(" \n");
    } else {
        long num;
        for ( num = nu_xct ; num > 0; num-- ) {
            printf("Transaction #%s; Amount: %.2f.\n", xctPtr->name, xctPtr->amount);
            if( xctPtr->next == ((void *)0) ) {
                break;
            }
            xctPtr = xctPtr->next;
         }
    }
}

variable_types: struct xct { char *name; double amount; struct xct *next; } *

variable_types: num long


decompiled_code:
void __fastcall remove_xct(__int64 a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // r12
const char **v4; // r13
const char **v5; // rbp

v2 = *(const char ***)(a1 + 16);
if ( v2 )
{
v3 = v2[2];
if ( v3 )
{
v4 = 0LL;
while ( 1 )
{
if ( !strcmp(*v2, a2) )
{
if ( v4 )
v4[2] = v3;
else
*(_QWORD *)(a1 + 16) = v3;
free(v2);
}
v5 = (const char **)v2[2];
v4 = v2;
v3 = v5[2];
if ( !v3 )
break;
v2 = (const char **)v2[2];
}
if ( !strcmp(*v5, a2) )
{
free(v5);
v2[2] = 0LL;
}
}
else if ( !strcmp(*v2, a2) )
{
*(_QWORD *)(a1 + 16) = 0LL;
}
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, const char *a2)
{
const char **v2; // rbx
const char *v3; // r12
const char **v4; // r13
const char **v5; // rbp

v2 = *(const char ***)(a1 + 16);
if ( v2 )
{
v3 = v2[2];
if ( v3 )
{
v4 = 0LL;
while ( 1 )
{
if ( !strcmp(*v2, a2) )
{
if ( v4 )
v4[2] = v3;
else
*(_QWORD *)(a1 + 16) = v3;
free(v2);
}
v5 = (const char **)v2[2];
v4 = v2;
v3 = v5[2];
if ( !v3 )
break;
v2 = (const char **)v2[2];
}
if ( !strcmp(*v5, a2) )
{
free(v5);
v2[2] = 0LL;
}
}
else if ( !strcmp(*v2, a2) )
{
*(_QWORD *)(a1 + 16) = 0LL;
}
}
}

original_code:
void remove_xct(Group *group, const char *user_name) {
    Xct *currentXct = group->xcts;
    Xct *prevXct = ((void *)0);
    if ( currentXct ) {
        while ( currentXct->next ) {
            if ( strcmp(currentXct->name, user_name) == 0 ) {
                if ( prevXct == ((void *)0) ) {
                    group->xcts = currentXct->next;
                } else {
                    prevXct->next = currentXct->next;
                }
                free(currentXct);
            }
            prevXct = currentXct;
            currentXct = currentXct->next;
        }
        if ( strcmp(currentXct->name, user_name) == 0 ) {
            if ( prevXct == ((void *)0) ) {
                group->xcts = ((void *)0);
            } else {
                free(currentXct);
                prevXct->next = ((void *)0);
            }
        }
    }
}

canonical_original_code:
void remove_xct(struct group *group, char *user_name) {
    struct xct *currentXct = group->xcts;
    struct xct *prevXct = ((void *)0);
    if ( currentXct ) {
        while ( currentXct->next ) {
            if ( strcmp(currentXct->name, user_name) == 0 ) {
                if ( prevXct == ((void *)0) ) {
                    group->xcts = currentXct->next;
                } else {
                    prevXct->next = currentXct->next;
                }
                free(currentXct);
            }
            prevXct = currentXct;
            currentXct = currentXct->next;
        }
        if ( strcmp(currentXct->name, user_name) == 0 ) {
            if ( prevXct == ((void *)0) ) {
                group->xcts = ((void *)0);
            } else {
                free(currentXct);
                prevXct->next = ((void *)0);
            }
        }
    }
}


decompiled_code:
__int64 __fastcall remove_user(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // rbp
int v4; // er8
const char **v5; // rax

if ( !*(_QWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
v2 = find_prev_user(a1, a2);
v3 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = strcmp(*v2, a2);
v5 = (const char **)v3[2];
if ( v4 )
{
v3[2] = v5[2];
v3 = v5;
}
else
{
*(_QWORD *)(a1 + 8) = v5;
}
free(v3);
remove_xct(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // rbp
int v4; // er8
const char **v5; // rax

if ( !*(_QWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
v2 = func5(a1, a2);
v3 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
v4 = strcmp(*v2, a2);
v5 = (const char **)v3[2];
if ( v4 )
{
v3[2] = v5[2];
v3 = v5;
}
else
{
*(_QWORD *)(a1 + 8) = v5;
}
free(v3);
func12(a1, a2);
return 0LL;
}

original_code:
int remove_user(Group *group, const char *user_name) {
    User *currentUser = group->users;
    User *prevUser = ((void *)0);
    if ( currentUser ) {
        prevUser = find_prev_user(group, user_name);
        if ( prevUser ) {
            if ( strcmp(prevUser->name, user_name) == 0 ) {
                currentUser = prevUser;
                if ( currentUser->next != ((void *)0) ) {
                    group->users = currentUser->next;
                } else {
                    group->users = ((void *)0);
                }
            } else {
                currentUser = prevUser->next;
                prevUser->next = currentUser->next;
            }
            currentUser->next = ((void *)0);
            free(currentUser);
            remove_xct(group, user_name);
            return 0;
        } else return -1;
    } else return -1;
}

canonical_original_code:
int remove_user(struct group *group, char *user_name) {
    struct user *currentUser = group->users;
    struct user *prevUser = ((void *)0);
    if ( currentUser ) {
        prevUser = find_prev_user(group, user_name);
        if ( prevUser ) {
            if ( strcmp(prevUser->name, user_name) == 0 ) {
                currentUser = prevUser;
                if ( currentUser->next != ((void *)0) ) {
                    group->users = currentUser->next;
                } else {
                    group->users = ((void *)0);
                }
            } else {
                currentUser = prevUser->next;
                prevUser->next = currentUser->next;
            }
            currentUser->next = ((void *)0);
            free(currentUser);
            remove_xct(group, user_name);
            return 0;
        } else return -1;
    } else return -1;
}


error

decompiled_code:
int __fastcall error(const char *a1)
{
return fprintf(stderr, "Error: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "Error: %s\n", a1);
}

original_code:
void error(const char *msg) {
    fprintf(stderr, "Error: %s\n", msg);
}

canonical_original_code:
void error(char *msg) {
    fprintf(stderr, "Error: %s\n", msg);
}

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall process_args(int a1, __int64 a2, __int64 *a3)
{
const char *v6; // rdx
bool v7; // cl
bool v8; // cf
bool v9; // zf
__int64 v10; // rcx
const char *v11; // rdi
const char *v12; // rsi
__int64 v13; // r8
bool v14; // zf
__int64 result; // rax
__int64 v16; // rdi
__int64 v17; // rdi
__int64 v18; // rdi
__int64 v19; // rbp
__int64 v20; // rsi
__int64 v21; // rdi
__int64 v22; // rbp
double v23; // xmm0_8
__int64 v24; // rdi
char *endptr[4]; // [rsp+0h] [rbp-20h] BYREF

if ( a1 <= 0 )
return 0LL;
v6 = *(const char **)a2;
if ( !strcmp(*(const char **)a2, "quit") && a1 == 1 )
return 0xFFFFFFFFLL;
v7 = strcmp(v6, "add_group") != 0;
v8 = 0;
v9 = !v7;
if ( !v7 && (v8 = 0, v9 = a1 != 2, a1 == 2) )
{
if ( (unsigned int)add_group(a3, *(_QWORD *)(a2 + 8)) != -1 )
return 0LL;
error("Group already exists");
result = 0LL;
}
else
{
v10 = 12LL;
v11 = "list_groups";
v12 = *(const char **)a2;
v13 = *a3;
do
{
if ( !v10 )
break;
v8 = *v12 < (unsigned int)*v11;
v9 = *v12++ == *v11++;
--v10;
}
while ( v9 );
if ( (!v8 && !v9) == v8 && a1 == 1 )
{
list_groups(v13, v12);
return 0LL;
}
if ( strcmp(v6, "add_user") || a1 != 3 )
{
if ( !strcmp(v6, "remove_user") && a1 == 3 )
{
v17 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( !v17 )
goto LABEL_34;
if ( (unsigned int)remove_user(v17, *(_QWORD *)(a2 + 16)) != -1 )
return 0LL;
}
else
{
if ( !strcmp(v6, "list_users") && a1 == 2 )
{
v24 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( v24 )
{
list_users(v24);
return 0LL;
}
goto LABEL_34;
}
if ( strcmp(v6, "user_balance") || a1 != 3 )
{
if ( strcmp(v6, "under_paid") || a1 != 2 )
{
v14 = strcmp(v6, "add_xct") == 0;
if ( a1 == 4 && v14 )
{
v22 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( v22 )
{
v23 = strtod(*(const char **)(a2 + 24), endptr);
if ( *(char **)(a2 + 24) != endptr[0] )
{
if ( (unsigned int)add_xct(v22, *(_QWORD *)(a2 + 16), v23) == -1 )
error("User does not exist");
return 0LL;
}
goto LABEL_54;
}
}
else
{
if ( strcmp(v6, "recent_xct") || a1 != 3 )
{
error("Incorrect syntax");
return 0LL;
}
v19 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( v19 )
{
v20 = strtol(*(const char **)(a2 + 16), endptr, 10);
if ( *(char **)(a2 + 16) != endptr[0] )
{
recent_xct(v19, v20);
return 0LL;
}
LABEL_54:
error("Incorrect number format");
return 0LL;
}
}
goto LABEL_34;
}
v21 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( v21 )
{
if ( (unsigned int)under_paid(v21) != -1 )
return 0LL;
error("User list empty");
return 0LL;
}
LABEL_34:
error("Group does not exist");
return 0LL;
}
v18 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( !v18 )
goto LABEL_34;
if ( (unsigned int)user_balance(v18, *(_QWORD *)(a2 + 16)) != -1 )
return 0LL;
}
error("User does not exist");
return 0LL;
}
v16 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( !v16 )
goto LABEL_34;
if ( (unsigned int)add_user(v16, *(_QWORD *)(a2 + 16)) != -1 )
return 0LL;
error("User already exists");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, __int64 *a3)
{
const char *v6; // rdx
bool v7; // cl
bool v8; // cf
bool v9; // zf
__int64 v10; // rcx
const char *v11; // rdi
const char *v12; // rsi
__int64 v13; // r8
bool v14; // zf
__int64 result; // rax
__int64 v16; // rdi
__int64 v17; // rdi
__int64 v18; // rdi
__int64 v19; // rbp
__int64 v20; // rsi
__int64 v21; // rdi
__int64 v22; // rbp
double v23; // xmm0_8
__int64 v24; // rdi
char *endptr[4]; // [rsp+0h] [rbp-20h] BYREF

if ( a1 <= 0 )
return 0LL;
v6 = *(const char **)a2;
if ( !strcmp(*(const char **)a2, "quit") && a1 == 1 )
return 0xFFFFFFFFLL;
v7 = strcmp(v6, "add_group") != 0;
v8 = 0;
v9 = !v7;
if ( !v7 && (v8 = 0, v9 = a1 != 2, a1 == 2) )
{
if ( (unsigned int)add_group(a3, *(_QWORD *)(a2 + 8)) != -1 )
return 0LL;
func0("Group already exists");
result = 0LL;
}
else
{
v10 = 12LL;
v11 = "list_groups";
v12 = *(const char **)a2;
v13 = *a3;
do
{
if ( !v10 )
break;
v8 = *v12 < (unsigned int)*v11;
v9 = *v12++ == *v11++;
--v10;
}
while ( v9 );
if ( (!v8 && !v9) == v8 && a1 == 1 )
{
list_groups(v13, v12);
return 0LL;
}
if ( strcmp(v6, "add_user") || a1 != 3 )
{
if ( !strcmp(v6, "remove_user") && a1 == 3 )
{
v17 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( !v17 )
goto LABEL_34;
if ( (unsigned int)remove_user(v17, *(_QWORD *)(a2 + 16)) != -1 )
return 0LL;
}
else
{
if ( !strcmp(v6, "list_users") && a1 == 2 )
{
v24 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( v24 )
{
list_users(v24);
return 0LL;
}
goto LABEL_34;
}
if ( strcmp(v6, "user_balance") || a1 != 3 )
{
if ( strcmp(v6, "under_paid") || a1 != 2 )
{
v14 = strcmp(v6, "add_xct") == 0;
if ( a1 == 4 && v14 )
{
v22 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( v22 )
{
v23 = strtod(*(const char **)(a2 + 24), endptr);
if ( *(char **)(a2 + 24) != endptr[0] )
{
if ( (unsigned int)add_xct(v22, *(_QWORD *)(a2 + 16), v23) == -1 )
func0("User does not exist");
return 0LL;
}
goto LABEL_54;
}
}
else
{
if ( strcmp(v6, "recent_xct") || a1 != 3 )
{
func0("Incorrect syntax");
return 0LL;
}
v19 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( v19 )
{
v20 = strtol(*(const char **)(a2 + 16), endptr, 10);
if ( *(char **)(a2 + 16) != endptr[0] )
{
recent_xct(v19, v20);
return 0LL;
}
LABEL_54:
func0("Incorrect number format");
return 0LL;
}
}
goto LABEL_34;
}
v21 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( v21 )
{
if ( (unsigned int)under_paid(v21) != -1 )
return 0LL;
func0("User list empty");
return 0LL;
}
LABEL_34:
func0("Group does not exist");
return 0LL;
}
v18 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( !v18 )
goto LABEL_34;
if ( (unsigned int)user_balance(v18, *(_QWORD *)(a2 + 16)) != -1 )
return 0LL;
}
func0("User does not exist");
return 0LL;
}
v16 = find_group(v13, *(_QWORD *)(a2 + 8));
if ( !v16 )
goto LABEL_34;
if ( (unsigned int)add_user(v16, *(_QWORD *)(a2 + 16)) != -1 )
return 0LL;
func0("User already exists");
result = 0LL;
}
return result;
}

original_code:
int process_args(int cmd_argc, char **cmd_argv, Group **group_list_addr) {
    Group *group_list = *group_list_addr;
    Group *g;
    if (cmd_argc <= 0) {
        return 0;
    } else if (strcmp(cmd_argv[0], "quit") == 0 && cmd_argc == 1) {
        return -1;
    } else if (strcmp(cmd_argv[0], "add_group") == 0 && cmd_argc == 2) {
        if (add_group(group_list_addr, cmd_argv[1]) == -1) {
            error("Group already exists");
        }
    } else if (strcmp(cmd_argv[0], "list_groups") == 0 && cmd_argc == 1) {
        list_groups(group_list);
    } else if (strcmp(cmd_argv[0], "add_user") == 0 && cmd_argc == 3) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            if (add_user(g, cmd_argv[2]) == -1) {
                error("User already exists");
            }
        }
    } else if (strcmp(cmd_argv[0], "remove_user") == 0 && cmd_argc == 3) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            if (remove_user(g, cmd_argv[2]) == -1) {
                error("User does not exist");
            }
        }
    } else if (strcmp(cmd_argv[0], "list_users") == 0 && cmd_argc == 2) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            list_users(g);
        }
    } else if (strcmp(cmd_argv[0], "user_balance") == 0 && cmd_argc == 3) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            if (user_balance(g, cmd_argv[2]) == -1) {
                error("User does not exist");
            }
        }
    } else if (strcmp(cmd_argv[0], "under_paid") == 0 && cmd_argc == 2) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            if (under_paid(g) == -1) {
                error("User list empty");
            }
        }
    } else if (strcmp(cmd_argv[0], "add_xct") == 0 && cmd_argc == 4) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            char *end;
            double amount = strtod(cmd_argv[3], &end);
            if (end == cmd_argv[3]) {
                error("Incorrect number format");
            } else {
                if (add_xct(g, cmd_argv[2], amount) == -1) {
                    error("User does not exist");
                }
            }
        }
    } else if(strcmp(cmd_argv[0], "recent_xct") == 0 && cmd_argc == 3) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            char *end;
            long num = strtol(cmd_argv[2], &end, 10);
            if (end == cmd_argv[2]) {
                error("Incorrect number format");
            } else {
                recent_xct(g, num);
            }
        }
    } else {
        error("Incorrect syntax");
    }
    return 0;
}

canonical_original_code:
int process_args(int cmd_argc, char **cmd_argv, struct group **group_list_addr) {
    struct group *group_list = *group_list_addr;
    struct group *g;
    if (cmd_argc <= 0) {
        return 0;
    } else if (strcmp(cmd_argv[0], "quit") == 0 && cmd_argc == 1) {
        return -1;
    } else if (strcmp(cmd_argv[0], "add_group") == 0 && cmd_argc == 2) {
        if (add_group(group_list_addr, cmd_argv[1]) == -1) {
            error("Group already exists");
        }
    } else if (strcmp(cmd_argv[0], "list_groups") == 0 && cmd_argc == 1) {
        list_groups(group_list);
    } else if (strcmp(cmd_argv[0], "add_user") == 0 && cmd_argc == 3) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            if (add_user(g, cmd_argv[2]) == -1) {
                error("User already exists");
            }
        }
    } else if (strcmp(cmd_argv[0], "remove_user") == 0 && cmd_argc == 3) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            if (remove_user(g, cmd_argv[2]) == -1) {
                error("User does not exist");
            }
        }
    } else if (strcmp(cmd_argv[0], "list_users") == 0 && cmd_argc == 2) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            list_users(g);
        }
    } else if (strcmp(cmd_argv[0], "user_balance") == 0 && cmd_argc == 3) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            if (user_balance(g, cmd_argv[2]) == -1) {
                error("User does not exist");
            }
        }
    } else if (strcmp(cmd_argv[0], "under_paid") == 0 && cmd_argc == 2) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            if (under_paid(g) == -1) {
                error("User list empty");
            }
        }
    } else if (strcmp(cmd_argv[0], "add_xct") == 0 && cmd_argc == 4) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            char *end;
            double amount = strtod(cmd_argv[3], &end);
            if (end == cmd_argv[3]) {
                error("Incorrect number format");
            } else {
                if (add_xct(g, cmd_argv[2], amount) == -1) {
                    error("User does not exist");
                }
            }
        }
    } else if(strcmp(cmd_argv[0], "recent_xct") == 0 && cmd_argc == 3) {
        if ((g = find_group(group_list, cmd_argv[1])) == ((void *)0)) {
            error("Group does not exist");
        } else {
            char *end;
            long num = strtol(cmd_argv[2], &end, 10);
            if (end == cmd_argv[2]) {
                error("Incorrect number format");
            } else {
                recent_xct(g, num);
            }
        }
    } else {
        error("Incorrect syntax");
    }
    return 0;
}

variable_types:
end
char *


decompiled_code:
void *__fastcall gpu_consumer(void *a1)
{
int v1; // ebp
int v2; // eax
bool v3; // zf
struct timeval v5; // [rsp+0h] [rbp-58h] BYREF
struct timeval v6; // [rsp+10h] [rbp-48h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF
struct timeval v8; // [rsp+30h] [rbp-28h] BYREF

*((_QWORD *)a1 + 2) = initGPUmem((unsigned int)blocksize);
*((_QWORD *)a1 + 3) = initGPUmem((unsigned int)(2 * blocksize));
if ( maxiterations > 0 )
{
v1 = 0;
while ( !exit_signal )
{
gettimeofday(&v5, 0LL);
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
while ( *(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 9)) != 1 )
pthread_cond_wait(*((pthread_cond_t **)a1 + 10), *((pthread_mutex_t **)a1 + 9));
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
gettimeofday(&tv, 0LL);
if ( !(unsigned int)compression_kernel_wrapper(
*(_QWORD *)(*(_QWORD *)a1 + 8LL * *((int *)a1 + 9)),
(unsigned int)blocksize,
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *((int *)a1 + 9)),
0LL,
0LL,
128LL,
0LL,
*((int *)a1 + 9),
*((_QWORD *)a1 + 2),
*((_QWORD *)a1 + 3)) )
printf("Compression failed. Success %d\n", 0LL);
gettimeofday(&v8, 0LL);
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
++*(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 9));
v2 = *((_DWORD *)a1 + 9) + 1;
v3 = v2 == numblocks;
*((_DWORD *)a1 + 9) = v2;
if ( v3 )
*((_DWORD *)a1 + 9) = 0;
++v1;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
pthread_cond_signal(*((pthread_cond_t **)a1 + 11));
gettimeofday(&v6, 0LL);
if ( maxiterations <= v1 )
goto LABEL_11;
}
++exit_signal;
}
LABEL_11:
deleteGPUmem(*((_QWORD *)a1 + 2));
deleteGPUmem(*((_QWORD *)a1 + 3));
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
int v1; // ebp
int v2; // eax
bool v3; // zf
struct timeval v5; // [rsp+0h] [rbp-58h] BYREF
struct timeval v6; // [rsp+10h] [rbp-48h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF
struct timeval v8; // [rsp+30h] [rbp-28h] BYREF

*((_QWORD *)a1 + 2) = initGPUmem((unsigned int)blocksize);
*((_QWORD *)a1 + 3) = initGPUmem((unsigned int)(2 * blocksize));
if ( maxiterations > 0 )
{
v1 = 0;
while ( !exit_signal )
{
gettimeofday(&v5, 0LL);
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
while ( *(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 9)) != 1 )
pthread_cond_wait(*((pthread_cond_t **)a1 + 10), *((pthread_mutex_t **)a1 + 9));
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
gettimeofday(&tv, 0LL);
if ( !(unsigned int)compression_kernel_wrapper(
*(_QWORD *)(*(_QWORD *)a1 + 8LL * *((int *)a1 + 9)),
(unsigned int)blocksize,
*(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * *((int *)a1 + 9)),
0LL,
0LL,
128LL,
0LL,
*((int *)a1 + 9),
*((_QWORD *)a1 + 2),
*((_QWORD *)a1 + 3)) )
printf("Compression failed. Success %d\n", 0LL);
gettimeofday(&v8, 0LL);
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
++*(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 9));
v2 = *((_DWORD *)a1 + 9) + 1;
v3 = v2 == numblocks;
*((_DWORD *)a1 + 9) = v2;
if ( v3 )
*((_DWORD *)a1 + 9) = 0;
++v1;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
pthread_cond_signal(*((pthread_cond_t **)a1 + 11));
gettimeofday(&v6, 0LL);
if ( maxiterations <= v1 )
goto LABEL_11;
}
++exit_signal;
}
LABEL_11:
deleteGPUmem(*((_QWORD *)a1 + 2));
deleteGPUmem(*((_QWORD *)a1 + 3));
return 0LL;
}

original_code:
void *gpu_consumer (void *q)
{
 struct timeval t1_start,t1_end,t2_start,t2_end;
 double time_d, alltime;
 queue *fifo;
 int i, d;
 int success=0;
 fifo = (queue *)q;
 int comp_length=0;
 fifo->in_d = initGPUmem((int)blocksize);
 fifo->out_d = initGPUmem((int)blocksize*2);
 for (i = 0; i < maxiterations; i++) {
  if(exit_signal){
   exit_signal++;
   break;
  }
  gettimeofday(&t1_start,0);
  pthread_mutex_lock (fifo->mut);
  while (fifo->ledger[fifo->headGC]!=1)
  {
   pthread_cond_wait (fifo->produced, fifo->mut);
  }
  pthread_mutex_unlock (fifo->mut);
  gettimeofday(&t2_start,0);
  success=compression_kernel_wrapper(fifo->buf[fifo->headGC], blocksize, fifo->bufout[fifo->headGC],
          0, 0, 128, 0,fifo->headGC, fifo->in_d, fifo->out_d);
  if(!success){
   printf("Compression failed. Success %d\n",success);
  }
  gettimeofday(&t2_end,0);
  time_d = (t2_end.tv_sec-t2_start.tv_sec) + (t2_end.tv_usec - t2_start.tv_usec)/1000000.0;
  pthread_mutex_lock (fifo->mut);
  fifo->ledger[fifo->headGC]++;
  fifo->headGC++;
  if (fifo->headGC == numblocks)
   fifo->headGC = 0;
  pthread_mutex_unlock (fifo->mut);
  pthread_cond_signal (fifo->compressed);
  gettimeofday(&t1_end,0);
  alltime = (t1_end.tv_sec-t1_start.tv_sec) + (t1_end.tv_usec - t1_start.tv_usec)/1000000.0;
 }
 deleteGPUmem(fifo->in_d);
 deleteGPUmem(fifo->out_d);
 return (((void *)0));
}

canonical_original_code:
void *gpu_consumer(void *q)
{
 struct timeval t1_start; struct timeval t1_end; struct timeval t2_start; struct timeval t2_end;
 double time_d; double alltime;
 struct queue *fifo;
 int i; int d;
 int success = 0;
 fifo = (struct queue *)q;
 int comp_length = 0;
 fifo->in_d = initGPUmem((int)blocksize);
 fifo->out_d = initGPUmem((int)blocksize*2);
 for (i = 0; i < maxiterations; i++) {
  if(exit_signal){
   exit_signal++;
   break;
  }
  gettimeofday(&t1_start,0);
  pthread_mutex_lock (fifo->mut);
  while (fifo->ledger[fifo->headGC]!=1)
  {
   pthread_cond_wait (fifo->produced, fifo->mut);
  }
  pthread_mutex_unlock (fifo->mut);
  gettimeofday(&t2_start,0);
  success=compression_kernel_wrapper(fifo->buf[fifo->headGC], blocksize, fifo->bufout[fifo->headGC],
          0, 0, 128, 0,fifo->headGC, fifo->in_d, fifo->out_d);
  if(!success){
   printf("Compression failed. Success %d\n",success);
  }
  gettimeofday(&t2_end,0);
  time_d = (t2_end.tv_sec-t2_start.tv_sec) + (t2_end.tv_usec - t2_start.tv_usec)/1000000.0;
  pthread_mutex_lock (fifo->mut);
  fifo->ledger[fifo->headGC]++;
  fifo->headGC++;
  if (fifo->headGC == numblocks)
   fifo->headGC = 0;
  pthread_mutex_unlock (fifo->mut);
  pthread_cond_signal (fifo->compressed);
  gettimeofday(&t1_end,0);
  alltime = (t1_end.tv_sec-t1_start.tv_sec) + (t1_end.tv_usec - t1_start.tv_usec)/1000000.0;
 }
 deleteGPUmem(fifo->in_d);
 deleteGPUmem(fifo->out_d);
 return (((void *)0));
}

variable_types:
q
void *

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

variable_types: alltime double

variable_types: struct queue { unsigned char **buf; unsigned char **bufout; unsigned char *in_d; unsigned char *out_d; int headPG; int headGC; int headSC; int headCS; int headSP; int *ledger; int *outsize; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *mut; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *produced; } *

variable_types: i int

variable_types: d int

variable_types: success int

return_type: void *

user_defined_types: struct queue { unsigned char **buf; unsigned char **bufout; unsigned char *in_d; unsigned char *out_d; int headPG; int headGC; int headSC; int headCS; int headSP; int *ledger; int *outsize; union pthread_mutex_t *mut; union pthread_cond_t *produced; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
void *__fastcall cpu_consumer(void *a1)
{
void *v2; // rax
void *v3; // r12
int v4; // ebp
pthread_mutex_t *v5; // rdi
__int64 v6; // r15
const void *v7; // r13
unsigned int v8; // er14
int v9; // eax
bool v10; // zf
unsigned int v12; // [rsp+Ch] [rbp-7Ch] BYREF
struct timeval tv; // [rsp+10h] [rbp-78h] BYREF
struct timeval v14; // [rsp+20h] [rbp-68h] BYREF
struct timeval v15; // [rsp+30h] [rbp-58h] BYREF
struct timeval v16; // [rsp+40h] [rbp-48h] BYREF

v12 = 0;
v2 = malloc(blocksize);
if ( maxiterations > 0 )
{
v3 = v2;
v4 = 0;
while ( !exit_signal )
{
gettimeofday(&tv, 0LL);
while ( 1 )
{
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
v5 = (pthread_mutex_t *)*((_QWORD *)a1 + 9);
if ( *(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 11)) == 2 )
break;
pthread_mutex_unlock(v5);
}
pthread_mutex_unlock(v5);
onestream_finish_GPU(*((unsigned int *)a1 + 11));
gettimeofday(&v15, 0LL);
v6 = *((int *)a1 + 11);
v7 = *(const void **)(*(_QWORD *)a1 + 8 * v6);
v8 = blocksize;
memcpy(v3, v7, blocksize);
if ( (unsigned int)aftercompression_wrapper(v7, v8, *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v6), &v12) )
{
*(_DWORD *)(*((_QWORD *)a1 + 8) + 4LL * *((int *)a1 + 11)) = v12;
}
else
{
printf("After Compression failed. Success %d return size %d\n", 0LL, v12);
*(_DWORD *)(*((_QWORD *)a1 + 8) + 4LL * *((int *)a1 + 11)) = 0;
memcpy(*(void **)(*(_QWORD *)a1 + 8LL * *((int *)a1 + 11)), v3, blocksize);
}
gettimeofday(&v16, 0LL);
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
++*(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 11));
v9 = *((_DWORD *)a1 + 11) + 1;
v10 = v9 == numblocks;
*((_DWORD *)a1 + 11) = v9;
if ( v10 )
*((_DWORD *)a1 + 11) = 0;
++v4;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
pthread_cond_signal(*((pthread_cond_t **)a1 + 13));
gettimeofday(&v14, 0LL);
if ( maxiterations <= v4 )
return 0LL;
}
++exit_signal;
}
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
void *v2; // rax
void *v3; // r12
int v4; // ebp
pthread_mutex_t *v5; // rdi
__int64 v6; // r15
const void *v7; // r13
unsigned int v8; // er14
int v9; // eax
bool v10; // zf
unsigned int v12; // [rsp+Ch] [rbp-7Ch] BYREF
struct timeval tv; // [rsp+10h] [rbp-78h] BYREF
struct timeval v14; // [rsp+20h] [rbp-68h] BYREF
struct timeval v15; // [rsp+30h] [rbp-58h] BYREF
struct timeval v16; // [rsp+40h] [rbp-48h] BYREF

v12 = 0;
v2 = malloc(blocksize);
if ( maxiterations > 0 )
{
v3 = v2;
v4 = 0;
while ( !exit_signal )
{
gettimeofday(&tv, 0LL);
while ( 1 )
{
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
v5 = (pthread_mutex_t *)*((_QWORD *)a1 + 9);
if ( *(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 11)) == 2 )
break;
pthread_mutex_unlock(v5);
}
pthread_mutex_unlock(v5);
onestream_finish_GPU(*((unsigned int *)a1 + 11));
gettimeofday(&v15, 0LL);
v6 = *((int *)a1 + 11);
v7 = *(const void **)(*(_QWORD *)a1 + 8 * v6);
v8 = blocksize;
memcpy(v3, v7, blocksize);
if ( (unsigned int)aftercompression_wrapper(v7, v8, *(_QWORD *)(*((_QWORD *)a1 + 1) + 8 * v6), &v12) )
{
*(_DWORD *)(*((_QWORD *)a1 + 8) + 4LL * *((int *)a1 + 11)) = v12;
}
else
{
printf("After Compression failed. Success %d return size %d\n", 0LL, v12);
*(_DWORD *)(*((_QWORD *)a1 + 8) + 4LL * *((int *)a1 + 11)) = 0;
memcpy(*(void **)(*(_QWORD *)a1 + 8LL * *((int *)a1 + 11)), v3, blocksize);
}
gettimeofday(&v16, 0LL);
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
++*(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 11));
v9 = *((_DWORD *)a1 + 11) + 1;
v10 = v9 == numblocks;
*((_DWORD *)a1 + 11) = v9;
if ( v10 )
*((_DWORD *)a1 + 11) = 0;
++v4;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
pthread_cond_signal(*((pthread_cond_t **)a1 + 13));
gettimeofday(&v14, 0LL);
if ( maxiterations <= v4 )
return 0LL;
}
++exit_signal;
}
return 0LL;
}

original_code:
void *cpu_consumer (void *q)
{
 struct timeval t1_start,t1_end,t2_start,t2_end;
 double time_d, alltime;
 int i;
 int success=0;
 queue *fifo;
 fifo = (queue *)q;
 int comp_length=0;
 unsigned char * bckpbuf;
 bckpbuf = (unsigned char *)malloc(sizeof(unsigned char)*blocksize);
 for (i = 0; i < maxiterations; i++) {
  if(exit_signal){
   exit_signal++;
   break;
  }
  gettimeofday(&t1_start,0);
  pthread_mutex_lock (fifo->mut);
  while (fifo->ledger[fifo->headCS]!=2) {
   pthread_mutex_unlock (fifo->mut);
   pthread_mutex_lock (fifo->mut);
  }
  pthread_mutex_unlock (fifo->mut);
  onestream_finish_GPU(fifo->headCS);
  gettimeofday(&t2_start,0);
  memcpy (bckpbuf, fifo->buf[fifo->headCS], blocksize);
  success=aftercompression_wrapper(fifo->buf[fifo->headCS], blocksize, fifo->bufout[fifo->headCS], &comp_length);
  if(!success){
   printf("After Compression failed. Success %d return size %d\n",success,comp_length);
   fifo->outsize[fifo->headCS] = 0;
   memcpy (fifo->buf[fifo->headCS],bckpbuf, blocksize);
  }
  else
   fifo->outsize[fifo->headCS] = comp_length;
  gettimeofday(&t2_end,0);
  time_d = (t2_end.tv_sec-t2_start.tv_sec) + (t2_end.tv_usec - t2_start.tv_usec)/1000000.0;
  pthread_mutex_lock (fifo->mut);
  fifo->ledger[fifo->headCS]++;
  fifo->headCS++;
  if (fifo->headCS == numblocks)
   fifo->headCS = 0;
  pthread_mutex_unlock (fifo->mut);
  pthread_cond_signal (fifo->sendready);
  gettimeofday(&t1_end,0);
  alltime = (t1_end.tv_sec-t1_start.tv_sec) + (t1_end.tv_usec - t1_start.tv_usec)/1000000.0;
 }
 return (((void *)0));
}

canonical_original_code:
void *cpu_consumer(void *q)
{
 struct timeval t1_start; struct timeval t1_end; struct timeval t2_start; struct timeval t2_end;
 double time_d; double alltime;
 int i;
 int success = 0;
 struct queue *fifo;
 fifo = (struct queue *)q;
 int comp_length = 0;
 unsigned char *bckpbuf;
 bckpbuf = (unsigned char *)malloc(sizeof(unsigned char)*blocksize);
 for (i = 0; i < maxiterations; i++) {
  if(exit_signal){
   exit_signal++;
   break;
  }
  gettimeofday(&t1_start,0);
  pthread_mutex_lock (fifo->mut);
  while (fifo->ledger[fifo->headCS]!=2) {
   pthread_mutex_unlock (fifo->mut);
   pthread_mutex_lock (fifo->mut);
  }
  pthread_mutex_unlock (fifo->mut);
  onestream_finish_GPU(fifo->headCS);
  gettimeofday(&t2_start,0);
  memcpy (bckpbuf, fifo->buf[fifo->headCS], blocksize);
  success=aftercompression_wrapper(fifo->buf[fifo->headCS], blocksize, fifo->bufout[fifo->headCS], &comp_length);
  if(!success){
   printf("After Compression failed. Success %d return size %d\n",success,comp_length);
   fifo->outsize[fifo->headCS] = 0;
   memcpy (fifo->buf[fifo->headCS],bckpbuf, blocksize);
  }
  else
   fifo->outsize[fifo->headCS] = comp_length;
  gettimeofday(&t2_end,0);
  time_d = (t2_end.tv_sec-t2_start.tv_sec) + (t2_end.tv_usec - t2_start.tv_usec)/1000000.0;
  pthread_mutex_lock (fifo->mut);
  fifo->ledger[fifo->headCS]++;
  fifo->headCS++;
  if (fifo->headCS == numblocks)
   fifo->headCS = 0;
  pthread_mutex_unlock (fifo->mut);
  pthread_cond_signal (fifo->sendready);
  gettimeofday(&t1_end,0);
  alltime = (t1_end.tv_sec-t1_start.tv_sec) + (t1_end.tv_usec - t1_start.tv_usec)/1000000.0;
 }
 return (((void *)0));
}

variable_types:
bckpbuf
unsigned char *

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

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


getloopcount

decompiled_code:
__int64 getloopcount()
{
return (unsigned int)loopnum;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned int)loopnum;
}

original_code:
int getloopcount(){
 return loopnum;
}

canonical_original_code:
int getloopcount(){
 return loopnum;
}


signalExitThreads

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

result = (unsigned int)++exit_signal;
while ( (int)result <= 3 )
;
return result;
}

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

result = (unsigned int)++exit_signal;
while ( (int)result <= 3 )
;
return result;
}

original_code:
void signalExitThreads()
{
 exit_signal++;
 while(! (exit_signal > 3));
}


queueDelete

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

signalExitThreads();
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 9));
free(*((void **)ptr + 9));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 10));
free(*((void **)ptr + 10));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 11));
free(*((void **)ptr + 11));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 13));
free(*((void **)ptr + 13));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 14));
free(*((void **)ptr + 14));
if ( numblocks > 0 )
{
v2 = 0LL;
do
{
deleteCPUmem(*(_QWORD *)(*((_QWORD *)ptr + 1) + 8 * v2));
v3 = *(_QWORD *)(*(_QWORD *)ptr + 8 * v2++);
deleteCPUmem(v3);
}
while ( numblocks > (int)v2 );
}
deleteGPUStreams();
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 7));
free(*((void **)ptr + 8));
free(ptr);
return resetGPU();
}

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

func4();
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 9));
free(*((void **)ptr + 9));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 10));
free(*((void **)ptr + 10));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 11));
free(*((void **)ptr + 11));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 13));
free(*((void **)ptr + 13));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 14));
free(*((void **)ptr + 14));
if ( numblocks > 0 )
{
v2 = 0LL;
do
{
deleteCPUmem(*(_QWORD *)(*((_QWORD *)ptr + 1) + 8 * v2));
v3 = *(_QWORD *)(*(_QWORD *)ptr + 8 * v2++);
deleteCPUmem(v3);
}
while ( numblocks > (int)v2 );
}
deleteGPUStreams();
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 7));
free(*((void **)ptr + 8));
free(ptr);
return resetGPU();
}

original_code:
void queueDelete (queue *q)
{
 int i =0;
 signalExitThreads();
 pthread_mutex_destroy (q->mut);
 free (q->mut);
 pthread_cond_destroy (q->produced);
 free (q->produced);
 pthread_cond_destroy (q->compressed);
 free (q->compressed);
 pthread_cond_destroy (q->sendready);
 free (q->sendready);
 pthread_cond_destroy (q->sent);
 free (q->sent);
 for (i = 0; i < (numblocks); i++) {
  deleteCPUmem(q->bufout[i]);
  deleteCPUmem(q->buf[i]);
 }
 deleteGPUStreams();
 free(q->buf);
 free(q->bufout);
 free(q->ledger);
 free(q->outsize);
 free (q);
 resetGPU();
}

canonical_original_code:
void queueDelete(struct queue *q)
{
 int i = 0;
 signalExitThreads();
 pthread_mutex_destroy (q->mut);
 free (q->mut);
 pthread_cond_destroy (q->produced);
 free (q->produced);
 pthread_cond_destroy (q->compressed);
 free (q->compressed);
 pthread_cond_destroy (q->sendready);
 free (q->sendready);
 pthread_cond_destroy (q->sent);
 free (q->sent);
 for (i = 0; i < (numblocks); i++) {
  deleteCPUmem(q->bufout[i]);
  deleteCPUmem(q->buf[i]);
 }
 deleteGPUStreams();
 free(q->buf);
 free(q->bufout);
 free(q->ledger);
 free(q->outsize);
 free (q);
 resetGPU();
}


decompiled_code:
int __fastcall init_compression(void *arg, int a2, int a3, int a4, char *a5, void *a6)
{
outputfilename = a5;
bookkeeping = a6;
maxiterations = a2;
numblocks = a3;
blocksize = a4;
puts("Initializing the GPU");
initGPU();
pthread_create(&congpu, 0LL, gpu_consumer, arg);
pthread_create(&concpu, 0LL, cpu_consumer, arg);
return pthread_create(&consend, 0LL, cpu_sender, arg);
}

canonical_decompiled_code:
int __fastcall func6(void *arg, int a2, int a3, int a4, char *a5, void *a6)
{
outputfilename = a5;
bookkeeping = a6;
maxiterations = a2;
numblocks = a3;
blocksize = a4;
puts("Initializing the GPU");
initGPU();
pthread_create(&congpu, 0LL, gpu_consumer, arg);
pthread_create(&concpu, 0LL, cpu_consumer, arg);
return pthread_create(&consend, 0LL, cpu_sender, arg);
}

original_code:
void init_compression(queue * fifo,int maxit,int numb,int bsize, char * filename, unsigned int * book)
{
 maxiterations=maxit;
 numblocks=numb;
 blocksize=bsize;
 outputfilename = filename;
 bookkeeping = book;
 printf("Initializing the GPU\n");
 initGPU();
 pthread_create (&congpu, ((void *)0), gpu_consumer, fifo);
 pthread_create (&concpu, ((void *)0), cpu_consumer, fifo);
 pthread_create (&consend, ((void *)0), cpu_sender, fifo);
 return;
}

canonical_original_code:
void init_compression(struct queue *fifo, int maxit, int numb, int bsize, char *filename, unsigned int *book)
{
 maxiterations=maxit;
 numblocks=numb;
 blocksize=bsize;
 outputfilename = filename;
 bookkeeping = book;
 printf("Initializing the GPU\n");
 initGPU();
 pthread_create (&congpu, ((void *)0), gpu_consumer, fifo);
 pthread_create (&concpu, ((void *)0), cpu_consumer, fifo);
 pthread_create (&consend, ((void *)0), cpu_sender, fifo);
 return;
}

variable_types: maxit int

variable_types: numb int

variable_types: bsize int

variable_types:
filename
char *

variable_types:
book
unsigned int *


decompiled_code:
int join_comp_threads()
{
int result; // eax

pthread_join(congpu, 0LL);
pthread_join(concpu, 0LL);
result = pthread_join(consend, 0LL);
exit_signal = 3;
return result;
}

canonical_decompiled_code:
int func7()
{
int result; // eax

pthread_join(congpu, 0LL);
pthread_join(concpu, 0LL);
result = pthread_join(consend, 0LL);
exit_signal = 3;
return result;
}

original_code:
void join_comp_threads()
{
 pthread_join (congpu, ((void *)0));
 pthread_join (concpu, ((void *)0));
 pthread_join (consend, ((void *)0));
 exit_signal = 3;
}


decompiled_code:
void *__fastcall degpu_consumer(void *a1)
{
int v2; // ebp
__int64 v3; // rax
__int64 v4; // rsi
unsigned int v5; // eax
pthread_mutex_t *v6; // rdi
int v7; // edx
int v8; // eax
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v10[0] = 0;
*((_QWORD *)a1 + 2) = deinitGPUmem((unsigned int)bsize);
*((_QWORD *)a1 + 3) = deinitGPUmem((unsigned int)(2 * bsize));
if ( nchunks > 0 )
{
v2 = 0;
do
{
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
while ( *(_DWORD *)(*((_QWORD *)a1 + 6) + 4LL * *((int *)a1 + 9)) != 1 )
pthread_cond_wait(*((pthread_cond_t **)a1 + 10), *((pthread_mutex_t **)a1 + 9));
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
v3 = *((int *)a1 + 9);
v4 = *((unsigned int *)a1 + v3 + 14);
if ( (_DWORD)v4 != bsize )
{
v5 = decompression_kernel_wrapper(*(_QWORD *)(*(_QWORD *)a1 + 8 * v3), v4, v10, 0LL, 1LL, 1LL);
if ( !v5 || v10[0] != bsize )
printf("Decompression failed. Success %d\n", v5);
}
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
v6 = (pthread_mutex_t *)*((_QWORD *)a1 + 9);
++*(_DWORD *)(*((_QWORD *)a1 + 6) + 4LL * *((int *)a1 + 9));
v7 = *((_DWORD *)a1 + 9);
v8 = v7 + 1;
if ( v7 == 3 )
v8 = 0;
++v2;
*((_DWORD *)a1 + 9) = v8;
pthread_mutex_unlock(v6);
pthread_cond_signal(*((pthread_cond_t **)a1 + 11));
}
while ( nchunks > v2 );
}
dedeleteGPUmem(*((_QWORD *)a1 + 2));
dedeleteGPUmem(*((_QWORD *)a1 + 3));
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
int v2; // ebp
__int64 v3; // rax
__int64 v4; // rsi
unsigned int v5; // eax
pthread_mutex_t *v6; // rdi
int v7; // edx
int v8; // eax
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v10[0] = 0;
*((_QWORD *)a1 + 2) = deinitGPUmem((unsigned int)bsize);
*((_QWORD *)a1 + 3) = deinitGPUmem((unsigned int)(2 * bsize));
if ( nchunks > 0 )
{
v2 = 0;
do
{
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
while ( *(_DWORD *)(*((_QWORD *)a1 + 6) + 4LL * *((int *)a1 + 9)) != 1 )
pthread_cond_wait(*((pthread_cond_t **)a1 + 10), *((pthread_mutex_t **)a1 + 9));
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
v3 = *((int *)a1 + 9);
v4 = *((unsigned int *)a1 + v3 + 14);
if ( (_DWORD)v4 != bsize )
{
v5 = decompression_kernel_wrapper(*(_QWORD *)(*(_QWORD *)a1 + 8 * v3), v4, v10, 0LL, 1LL, 1LL);
if ( !v5 || v10[0] != bsize )
printf("Decompression failed. Success %d\n", v5);
}
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
v6 = (pthread_mutex_t *)*((_QWORD *)a1 + 9);
++*(_DWORD *)(*((_QWORD *)a1 + 6) + 4LL * *((int *)a1 + 9));
v7 = *((_DWORD *)a1 + 9);
v8 = v7 + 1;
if ( v7 == 3 )
v8 = 0;
++v2;
*((_DWORD *)a1 + 9) = v8;
pthread_mutex_unlock(v6);
pthread_cond_signal(*((pthread_cond_t **)a1 + 11));
}
while ( nchunks > v2 );
}
dedeleteGPUmem(*((_QWORD *)a1 + 2));
dedeleteGPUmem(*((_QWORD *)a1 + 3));
return 0LL;
}

original_code:
void *degpu_consumer (void *q)
{
 dequeue *fifo;
 int i, d;
 int success=0;
 fifo = (dequeue *)q;
 int decomp_length=0;
 fifo->in_d = deinitGPUmem((int)bsize);
 fifo->out_d = deinitGPUmem((int)bsize*2);
 for (i = 0; i < nchunks; i++) {
  pthread_mutex_lock (fifo->mut);
  while (fifo->ledger[fifo->headGW]!=1) {
   pthread_cond_wait (fifo->rcvd, fifo->mut);
  }
  pthread_mutex_unlock (fifo->mut);
  if(fifo->compsize[fifo->headGW] == bsize)
   ;
  else
  {
   success=decompression_kernel_wrapper(fifo->buf[fifo->headGW], fifo->compsize[fifo->headGW] , &decomp_length, 0, 1, 1);
   if(!success || decomp_length!=bsize){
    printf("Decompression failed. Success %d\n",success);
   }
  }
  pthread_mutex_lock (fifo->mut);
  fifo->ledger[fifo->headGW]++;
  fifo->headGW++;
  if (fifo->headGW == 4)
   fifo->headGW = 0;
  pthread_mutex_unlock (fifo->mut);
  pthread_cond_signal (fifo->decomp);
 }
 dedeleteGPUmem(fifo->in_d);
 dedeleteGPUmem(fifo->out_d);
 return (((void *)0));
}

canonical_original_code:
void *degpu_consumer(void *q)
{
 struct dequeue *fifo;
 int i; int d;
 int success = 0;
 fifo = (struct dequeue *)q;
 int decomp_length = 0;
 fifo->in_d = deinitGPUmem((int)bsize);
 fifo->out_d = deinitGPUmem((int)bsize*2);
 for (i = 0; i < nchunks; i++) {
  pthread_mutex_lock (fifo->mut);
  while (fifo->ledger[fifo->headGW]!=1) {
   pthread_cond_wait (fifo->rcvd, fifo->mut);
  }
  pthread_mutex_unlock (fifo->mut);
  if(fifo->compsize[fifo->headGW] == bsize)
   ;
  else
  {
   success=decompression_kernel_wrapper(fifo->buf[fifo->headGW], fifo->compsize[fifo->headGW] , &decomp_length, 0, 1, 1);
   if(!success || decomp_length!=bsize){
    printf("Decompression failed. Success %d\n",success);
   }
  }
  pthread_mutex_lock (fifo->mut);
  fifo->ledger[fifo->headGW]++;
  fifo->headGW++;
  if (fifo->headGW == 4)
   fifo->headGW = 0;
  pthread_mutex_unlock (fifo->mut);
  pthread_cond_signal (fifo->decomp);
 }
 dedeleteGPUmem(fifo->in_d);
 dedeleteGPUmem(fifo->out_d);
 return (((void *)0));
}

variable_types: struct dequeue { unsigned char **buf; unsigned char **bufout; unsigned char *in_d; unsigned char *out_d; int headRG; int headGW; int headWR; int *ledger; int compsize[4]; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *mut; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } *rcvd; } *

user_defined_types: struct dequeue { unsigned char **buf; unsigned char **bufout; unsigned char *in_d; unsigned char *out_d; int headRG; int headGW; int headWR; int *ledger; int compsize[4]; union pthread_mutex_t *mut; union pthread_cond_t *rcvd; }


dequeueDelete

decompiled_code:
void __fastcall dequeueDelete(void *ptr)
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 9));
free(*((void **)ptr + 9));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 10));
free(*((void **)ptr + 10));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 11));
free(*((void **)ptr + 11));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 12));
free(*((void **)ptr + 12));
free(*((void **)ptr + 1));
free(*(void **)ptr);
free(*((void **)ptr + 6));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
pthread_mutex_destroy(*((pthread_mutex_t **)ptr + 9));
free(*((void **)ptr + 9));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 10));
free(*((void **)ptr + 10));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 11));
free(*((void **)ptr + 11));
pthread_cond_destroy(*((pthread_cond_t **)ptr + 12));
free(*((void **)ptr + 12));
free(*((void **)ptr + 1));
free(*(void **)ptr);
free(*((void **)ptr + 6));
free(ptr);
}

original_code:
void dequeueDelete (dequeue *q)
{
 pthread_mutex_destroy (q->mut);
 free (q->mut);
 pthread_cond_destroy (q->rcvd);
 free (q->rcvd);
 pthread_cond_destroy (q->decomp);
 free (q->decomp);
 pthread_cond_destroy (q->wrote);
 free (q->wrote);
 free(q->bufout);
 free(q->buf);
 free(q->ledger);
 free (q);
}

canonical_original_code:
void dequeueDelete(struct dequeue *q)
{
 pthread_mutex_destroy (q->mut);
 free (q->mut);
 pthread_cond_destroy (q->rcvd);
 free (q->rcvd);
 pthread_cond_destroy (q->decomp);
 free (q->decomp);
 pthread_cond_destroy (q->wrote);
 free (q->wrote);
 free(q->bufout);
 free(q->buf);
 free(q->ledger);
 free (q);
}


decompiled_code:
int __fastcall init_decompression(void *arg, char *a2)
{
outfile = a2;
puts("Initializing the GPU");
deinitGPU();
pthread_create(&congpu, 0LL, degpu_consumer, arg);
return pthread_create(&concpu, 0LL, decpu_consumer, arg);
}

canonical_decompiled_code:
int __fastcall func3(void *arg, char *a2)
{
outfile = a2;
puts("Initializing the GPU");
deinitGPU();
pthread_create(&congpu, 0LL, degpu_consumer, arg);
return pthread_create(&concpu, 0LL, decpu_consumer, arg);
}

original_code:
void init_decompression(dequeue * fifo, char * filename)
{
 outfile = filename;
 printf("Initializing the GPU\n");
 deinitGPU();
 pthread_create (&congpu, ((void *)0), degpu_consumer, fifo);
 pthread_create (&concpu, ((void *)0), decpu_consumer, fifo);
 return;
}

canonical_original_code:
void init_decompression(struct dequeue *fifo, char *filename)
{
 outfile = filename;
 printf("Initializing the GPU\n");
 deinitGPU();
 pthread_create (&congpu, ((void *)0), degpu_consumer, fifo);
 pthread_create (&concpu, ((void *)0), decpu_consumer, fifo);
 return;
}


decompiled_code:
int join_decomp_threads()
{
pthread_join(congpu, 0LL);
return pthread_join(concpu, 0LL);
}

canonical_decompiled_code:
int func4()
{
pthread_join(congpu, 0LL);
return pthread_join(concpu, 0LL);
}

original_code:
void join_decomp_threads()
{
 pthread_join (congpu, ((void *)0));
 pthread_join (concpu, ((void *)0));
}


max

repo: adolg/worldots

decompiled_code:
__int64 __fastcall max(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a1;
if ( (unsigned __int16)a2 >= (unsigned __int16)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (unsigned __int16)a2 >= (unsigned __int16)a1 )
result = a2;
return result;
}

original_code:
unsigned short
max (
 const unsigned short num1,
 const unsigned short num2
 )
{
 return num1 > num2 ? num1 : num2;
}

canonical_original_code:
unsigned short max(unsigned short num1, unsigned short num2)
{
 return num1 > num2 ? num1 : num2;
}

return_type: unsigned short


min

decompiled_code:
__int64 __fastcall min(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (unsigned __int16)a1 <= (unsigned __int16)a2 )
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (unsigned __int16)a1 <= (unsigned __int16)a2 )
result = a1;
return result;
}

original_code:
unsigned short
min (
 const unsigned short num1,
 const unsigned short num2
 )
{
 return num1 > num2 ? num2 : num1;
}

canonical_original_code:
unsigned short min(unsigned short num1, unsigned short num2)
{
 return num1 > num2 ? num2 : num1;
}


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

result = a1;
if ( a1 )
result = (a1 & (a1 - 1)) == 0;
return result;
}

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

result = a1;
if ( a1 )
result = (a1 & (a1 - 1)) == 0;
return result;
}

original_code:
HT_BOOL
single_bit (
 const unsigned int bitmask
 )
{
 return 0 != bitmask && 0 == (bitmask & (bitmask - 1));
}

canonical_original_code:
enum HT_BOOL_ single_bit(unsigned int bitmask)
{
 return 0 != bitmask && 0 == (bitmask & (bitmask - 1));
}

variable_types:
bitmask
unsigned int

return_type: enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 }


texttoushort

decompiled_code:
__int64 __fastcall texttoushort(char *nptr, _WORD *a2)
{
int *v2; // rax
int v3; // er13
int *v4; // rbx
unsigned __int64 v5; // rax
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = _errno_location();
v3 = *v2;
*v2 = 0;
v4 = v2;
v5 = strtoul(nptr, &endptr, 10);
if ( *v4 || *endptr || v5 > 0xFFFF )
{
*v4 = v3;
*a2 = -1;
result = 0LL;
}
else
{
*a2 = v5;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *nptr, _WORD *a2)
{
int *v2; // rax
int v3; // er13
int *v4; // rbx
unsigned __int64 v5; // rax
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = _errno_location();
v3 = *v2;
*v2 = 0;
v4 = v2;
v5 = strtoul(nptr, &endptr, 10);
if ( *v4 || *endptr || v5 > 0xFFFF )
{
*v4 = v3;
*a2 = -1;
result = 0LL;
}
else
{
*a2 = v5;
result = 1LL;
}
return result;
}

original_code:
HT_BOOL
texttoushort (
 const char * const str_num,
 unsigned short * const num
 )
{
 char * str_end;
 unsigned long n;
 int errno_old = (*__errno_location ());
   (*__errno_location ()) = 0;
 n = strtoul(str_num, & str_end, 10);
 if (0 != (*__errno_location ()) || strlen(str_end) > 0
 || (0x7fffffffffffffffL * 2UL + 1UL) == n || n > (unsigned long)(0x7fff * 2 + 1))
 {
  (*__errno_location ()) = errno_old;
  * num = (0x7fff * 2 + 1);
  return HT_FALSE;
 }
 * num = (unsigned short)n;
 return HT_TRUE;
}

canonical_original_code:
enum HT_BOOL_ texttoushort(char *str_num, unsigned short *num)
{
 char *str_end;
 unsigned long n;
 int errno_old = (*__errno_location ());
   (*__errno_location ()) = 0;
 n = strtoul(str_num, & str_end, 10);
 if (0 != (*__errno_location ()) || strlen(str_end) > 0
 || (0x7fffffffffffffffL * 2UL + 1UL) == n || n > (unsigned long)(0x7fff * 2 + 1))
 {
  (*__errno_location ()) = errno_old;
  * num = (0x7fff * 2 + 1);
  return HT_FALSE;
 }
 * num = (unsigned short)n;
 return HT_TRUE;
}

variable_types:
num
unsigned short *

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall invoc_read_ui(unsigned __int64 a1, __int64 a2, _DWORD *a3, unsigned __int64 a4, _DWORD *a5)
{
char v5; // cl
__int64 result; // rax

if ( !a2 || !a3 )
{
result = 1LL;
if ( !a3 )
return result;
LABEL_11:
*a3 = 0;
return 1LL;
}
if ( !a5 )
goto LABEL_11;
*a3 = 0;
if ( a4 < a1 && (v5 = **(_BYTE **)(a2 + 8 * a4)) != 0 )
{
if ( v5 == HT_L_INV_S_UI_MSQU )
{
*a3 = 1;
result = 0LL;
}
else
{
*a5 = 3;
result = 12LL;
}
}
else
{
*a5 = 2;
result = 12LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 a1, __int64 a2, _DWORD *a3, unsigned __int64 a4, _DWORD *a5)
{
char v5; // cl
__int64 result; // rax

if ( !a2 || !a3 )
{
result = 1LL;
if ( !a3 )
return result;
LABEL_11:
*a3 = 0;
return 1LL;
}
if ( !a5 )
goto LABEL_11;
*a3 = 0;
if ( a4 < a1 && (v5 = **(_BYTE **)(a2 + 8 * a4)) != 0 )
{
if ( v5 == HT_L_INV_S_UI_MSQU )
{
*a3 = 1;
result = 0LL;
}
else
{
*a5 = 3;
result = 12LL;
}
}
else
{
*a5 = 2;
result = 12LL;
}
return result;
}

original_code:
static
enum HT_FR
invoc_read_ui (
 const size_t argc,
 const char * * argv,
 struct invoc * const inv,
 const size_t i,
 enum HT_FAIL_INVOC * const invfail
 )
{
 if (((void *)0) == argv || ((void *)0) == inv || ((void *)0) == invfail)
 {
  if (((void *)0) != inv)
  {
   inv->info.play_ui = HT_UIT_NONE;
  }
  return HT_FR_FAIL_NULLPTR;
 }
 inv->info.play_ui = HT_UIT_NONE;
 if (i < argc)
 {
  const char * const argn = argv[i];
  char uisym;
  if (strlen(argn) < (size_t)1)
  {
   * invfail = HT_FAIL_INVOC_UI_NONE;
   return HT_FR_FAIL_INVOC;
  }
  uisym = argn[0];
  if (HT_L_INV_S_UI_MSQU == uisym)
  {
   inv->info.play_ui = HT_UIT_MSQU;
  }
  else
  {
   * invfail = HT_FAIL_INVOC_UI_UNK;
   return HT_FR_FAIL_INVOC;
  }
  return HT_FR_SUCCESS;
 }
 else
 {
  * invfail = HT_FAIL_INVOC_UI_NONE;
  return HT_FR_FAIL_INVOC;
 }
}

canonical_original_code:
static enum HT_FR invoc_read_ui(unsigned long argc, char **argv, struct invoc *inv, unsigned long i, enum HT_FAIL_INVOC *invfail)
{
 if (((void *)0) == argv || ((void *)0) == inv || ((void *)0) == invfail)
 {
  if (((void *)0) != inv)
  {
   inv->info.play_ui = HT_UIT_NONE;
  }
  return HT_FR_FAIL_NULLPTR;
 }
 inv->info.play_ui = HT_UIT_NONE;
 if (i < argc)
 {
  char *argn = argv[i];
  char uisym;
  if (strlen(argn) < (unsigned long)1)
  {
   * invfail = HT_FAIL_INVOC_UI_NONE;
   return HT_FR_FAIL_INVOC;
  }
  uisym = argn[0];
  if (HT_L_INV_S_UI_MSQU == uisym)
  {
   inv->info.play_ui = HT_UIT_MSQU;
  }
  else
  {
   * invfail = HT_FAIL_INVOC_UI_UNK;
   return HT_FR_FAIL_INVOC;
  }
  return HT_FR_SUCCESS;
 }
 else
 {
  * invfail = HT_FAIL_INVOC_UI_NONE;
  return HT_FR_FAIL_INVOC;
 }
}

variable_types:
argc
unsigned long

variable_types:
argv
char **

variable_types: struct invoc { union { enum HT_INV_PRINT { HT_INV_PRINT_HELP=0, HT_INV_PRINT_NINE=1, HT_INV_PRINT_VERSION=2 } nplay_print; enum HT_UIT { HT_UIT_NONE=0, HT_UIT_MSQU=1 } play_ui; } info; char *file_rc; enum HT_BOOL_ { HT_FALSE=0, HT_TRUE=1 } play; } *

variable_types:
i
unsigned long

variable_types: enum HT_FAIL_INVOC { HT_FAIL_INVOC_NONE=0, HT_FAIL_INVOC_UNK=1, HT_FAIL_INVOC_UI_NONE=2, HT_FAIL_INVOC_UI_UNK=3, HT_FAIL_INVOC_RC_NONE=4 } *

variable_types:
argn
char *

variable_types: uisym char

return_type: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }

user_defined_types: struct invoc { union { enum HT_INV_PRINT nplay_print; enum HT_UIT play_ui; } info; char *file_rc; enum HT_BOOL_ play; }


decompiled_code:
__int64 __fastcall invoc_read_rc(unsigned __int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4, _DWORD *a5)
{
_BYTE *v5; // rax
__int64 result; // rax

if ( !a2 || !a3 )
{
result = 1LL;
if ( !a3 )
return result;
LABEL_10:
*(_QWORD *)(a3 + 8) = &unk_362;
return 1LL;
}
if ( !a5 )
goto LABEL_10;
*(_QWORD *)(a3 + 8) = &unk_362;
if ( a4 < a1 && (v5 = *(_BYTE **)(a2 + 8 * a4), *v5) )
{
*(_QWORD *)(a3 + 8) = v5;
result = 0LL;
}
else
{
*a5 = 4;
result = 12LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int64 a1, __int64 a2, __int64 a3, unsigned __int64 a4, _DWORD *a5)
{
_BYTE *v5; // rax
__int64 result; // rax

if ( !a2 || !a3 )
{
result = 1LL;
if ( !a3 )
return result;
LABEL_10:
*(_QWORD *)(a3 + 8) = &unk_362;
return 1LL;
}
if ( !a5 )
goto LABEL_10;
*(_QWORD *)(a3 + 8) = &unk_362;
if ( a4 < a1 && (v5 = *(_BYTE **)(a2 + 8 * a4), *v5) )
{
*(_QWORD *)(a3 + 8) = v5;
result = 0LL;
}
else
{
*a5 = 4;
result = 12LL;
}
return result;
}

original_code:
static
enum HT_FR
invoc_read_rc (
 const size_t argc,
 const char * * argv,
 struct invoc * const inv,
 const size_t i,
 enum HT_FAIL_INVOC * const invfail
 )
{
 if (((void *)0) == argv || ((void *)0) == inv || ((void *)0) == invfail)
 {
  if (((void *)0) != inv)
  {
   inv->file_rc = "";
  }
  return HT_FR_FAIL_NULLPTR;
 }
 inv->file_rc = "";
 if (i < argc)
 {
  const char * const argn = argv[i];
  if (strlen(argn) < (size_t)1)
  {
   * invfail = HT_FAIL_INVOC_RC_NONE;
   return HT_FR_FAIL_INVOC;
  }
  inv->file_rc = argn;
  return HT_FR_SUCCESS;
 }
 else
 {
  * invfail = HT_FAIL_INVOC_RC_NONE;
  return HT_FR_FAIL_INVOC;
 }
}

canonical_original_code:
static enum HT_FR invoc_read_rc(unsigned long argc, char **argv, struct invoc *inv, unsigned long i, enum HT_FAIL_INVOC *invfail)
{
 if (((void *)0) == argv || ((void *)0) == inv || ((void *)0) == invfail)
 {
  if (((void *)0) != inv)
  {
   inv->file_rc = "";
  }
  return HT_FR_FAIL_NULLPTR;
 }
 inv->file_rc = "";
 if (i < argc)
 {
  char *argn = argv[i];
  if (strlen(argn) < (unsigned long)1)
  {
   * invfail = HT_FAIL_INVOC_RC_NONE;
   return HT_FR_FAIL_INVOC;
  }
  inv->file_rc = argn;
  return HT_FR_SUCCESS;
 }
 else
 {
  * invfail = HT_FAIL_INVOC_RC_NONE;
  return HT_FR_FAIL_INVOC;
 }
}

user_defined_types: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }

user_defined_types: enum HT_FAIL_INVOC { HT_FAIL_INVOC_NONE=0, HT_FAIL_INVOC_UNK=1, HT_FAIL_INVOC_UI_NONE=2, HT_FAIL_INVOC_UI_UNK=3, HT_FAIL_INVOC_RC_NONE=4 }

user_defined_types: enum HT_INV_PRINT { HT_INV_PRINT_HELP=0, HT_INV_PRINT_NINE=1, HT_INV_PRINT_VERSION=2 }

user_defined_types: enum HT_UIT { HT_UIT_NONE=0, HT_UIT_MSQU=1 }


decompiled_code:
__int64 __fastcall invoc_read_arg(unsigned __int64 a1, __int64 a2, _DWORD *a3, __int64 *a4, _DWORD *a5)
{
__int64 v8; // rcx
__int64 v10; // r15
char v11; // si
__int64 result; // rax
__int64 v13; // [rsp+8h] [rbp-40h]

if ( a5 == 0LL || a3 == 0LL || !a2 )
return 1LL;
v8 = *a4;
v10 = *(_QWORD *)(a2 + 8 * v8);
v13 = v8;
if ( strlen((const char *)v10) <= 1 || *(_BYTE *)v10 != 45 )
goto LABEL_10;
v11 = *(_BYTE *)(v10 + 1);
if ( HT_L_INV_S_HELP == v11 )
{
*a3 = 0;
result = 0LL;
a3[4] = 0;
}
else if ( HT_L_INV_S_NINE == v11 )
{
*a3 = 1;
result = 0LL;
a3[4] = 0;
}
else if ( HT_L_INV_S_VERSION == v11 )
{
*a3 = 2;
result = 0LL;
a3[4] = 0;
}
else if ( HT_L_INV_S_UI == v11 )
{
*a4 = v13 + 1;
result = invoc_read_ui(a1, a2, a3, v13 + 1, a5);
}
else
{
if ( HT_L_INV_S_RUNCOM != v11 )
{
LABEL_10:
*a5 = 1;
return 12LL;
}
*a4 = v13 + 1;
result = invoc_read_rc(a1, a2, (__int64)a3, v13 + 1, a5);
}
return result;
}

original_code:
static
enum HT_FR
invoc_read_arg (
 const size_t argc,
 const char * * argv,
 struct invoc * const inv,
 size_t * const i,
 enum HT_FAIL_INVOC * const invfail
 )
{
 const char * const arg = argv[* i];
 char argsw;
 if (((void *)0) == argv || ((void *)0) == inv || ((void *)0) == i || ((void *)0) == invfail)
 {
  return HT_FR_FAIL_NULLPTR;
 }
 if (strlen(arg) < (size_t)2 || '-' != arg[0])
 {
  * invfail = HT_FAIL_INVOC_UNK;
  return HT_FR_FAIL_INVOC;
 }
 argsw = arg[1];
 if (HT_L_INV_S_HELP == argsw)
 {
  inv->info.nplay_print = HT_INV_PRINT_HELP;
  inv->play = HT_FALSE;
 }
 else if (HT_L_INV_S_NINE == argsw)
 {
  inv->info.nplay_print = HT_INV_PRINT_NINE;
  inv->play = HT_FALSE;
 }
 else if (HT_L_INV_S_VERSION == argsw)
 {
  inv->info.nplay_print = HT_INV_PRINT_VERSION;
  inv->play = HT_FALSE;
 }
 else if (HT_L_INV_S_UI == argsw)
 {
  const enum HT_FR fr = invoc_read_ui(argc, argv, inv,
   ++(* i), invfail);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 else if (HT_L_INV_S_RUNCOM == argsw)
 {
  const enum HT_FR fr = invoc_read_rc(argc, argv, inv,
   ++(* i), invfail);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 else
 {
  * invfail = HT_FAIL_INVOC_UNK;
  return HT_FR_FAIL_INVOC;
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR invoc_read_arg(unsigned long argc, char **argv, struct invoc *inv, unsigned long *i, enum HT_FAIL_INVOC *invfail)
{
 char *arg = argv[* i];
 char argsw;
 if (((void *)0) == argv || ((void *)0) == inv || ((void *)0) == i || ((void *)0) == invfail)
 {
  return HT_FR_FAIL_NULLPTR;
 }
 if (strlen(arg) < (unsigned long)2 || '-' != arg[0])
 {
  * invfail = HT_FAIL_INVOC_UNK;
  return HT_FR_FAIL_INVOC;
 }
 argsw = arg[1];
 if (HT_L_INV_S_HELP == argsw)
 {
  inv->info.nplay_print = HT_INV_PRINT_HELP;
  inv->play = HT_FALSE;
 }
 else if (HT_L_INV_S_NINE == argsw)
 {
  inv->info.nplay_print = HT_INV_PRINT_NINE;
  inv->play = HT_FALSE;
 }
 else if (HT_L_INV_S_VERSION == argsw)
 {
  inv->info.nplay_print = HT_INV_PRINT_VERSION;
  inv->play = HT_FALSE;
 }
 else if (HT_L_INV_S_UI == argsw)
 {
  enum HT_FR fr = invoc_read_ui(argc, argv, inv,
   ++(* i), invfail);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 else if (HT_L_INV_S_RUNCOM == argsw)
 {
  enum HT_FR fr = invoc_read_rc(argc, argv, inv,
   ++(* i), invfail);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 else
 {
  * invfail = HT_FAIL_INVOC_UNK;
  return HT_FR_FAIL_INVOC;
 }
 return HT_FR_SUCCESS;
}

variable_types:
i
unsigned long *

variable_types:
arg
char *

variable_types: argsw char

variable_types: enum HT_FR { HT_FR_NONE=-1, HT_FR_SUCCESS=0, HT_FR_FAIL_NULLPTR=1, HT_FR_FAIL_ARROB=2, HT_FR_FAIL_ALLOC=3, HT_FR_FAIL_ENUM_UNK=4, HT_FR_FAIL_ILL_ARG=5, HT_FR_FAIL_ILL_STATE=6, HT_FR_FAIL_IO_ENV_UNDEF=7, HT_FR_FAIL_IO_FILE_R=8, HT_FR_FAIL_IO_PRINT=9, HT_FR_FAIL_POSIX=10, HT_FR_FAIL_IO=11, HT_FR_FAIL_INVOC=12, HT_FR_FAIL_RREADER=13, HT_FR_FAIL_UI_NONE=14, HT_FR_FAIL_UIMQ_API=15 }


decompiled_code:
__int64 __fastcall invoc_read(unsigned __int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
__int64 result; // rax
int v7; // edx
int v8; // esi
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !a2 || !a3 )
{
result = 1LL;
if ( !a3 )
return result;
LABEL_11:
*(_DWORD *)a3 = 0;
result = 1LL;
*(_QWORD *)(a3 + 8) = &unk_362;
*(_DWORD *)(a3 + 16) = 0;
return result;
}
if ( !a4 )
goto LABEL_11;
*a4 = 0;
*(_DWORD *)a3 = 0;
*(_QWORD *)(a3 + 8) = &unk_362;
*(_DWORD *)(a3 + 16) = 1;
v9[0] = 1LL;
if ( a1 <= 1 )
{
LABEL_14:
v8 = ui_def();
*(_DWORD *)a3 = v8;
result = 14LL;
if ( v8 )
result = 0LL;
}
else
{
while ( 1 )
{
result = invoc_read_arg(a1, a2, (_DWORD *)a3, v9, a4);
if ( (_DWORD)result )
break;
v7 = *(_DWORD *)(a3 + 16);
if ( ++v9[0] >= a1 )
{
if ( !v7 || *(_DWORD *)a3 )
return 0LL;
goto LABEL_14;
}
if ( !v7 )
return 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 a1, __int64 a2, __int64 a3, _DWORD *a4)
{
__int64 result; // rax
int v7; // edx
int v8; // esi
__int64 v9[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !a2 || !a3 )
{
result = 1LL;
if ( !a3 )
return result;
LABEL_11:
*(_DWORD *)a3 = 0;
result = 1LL;
*(_QWORD *)(a3 + 8) = &unk_362;
*(_DWORD *)(a3 + 16) = 0;
return result;
}
if ( !a4 )
goto LABEL_11;
*a4 = 0;
*(_DWORD *)a3 = 0;
*(_QWORD *)(a3 + 8) = &unk_362;
*(_DWORD *)(a3 + 16) = 1;
v9[0] = 1LL;
if ( a1 <= 1 )
{
LABEL_14:
v8 = ui_def();
*(_DWORD *)a3 = v8;
result = 14LL;
if ( v8 )
result = 0LL;
}
else
{
while ( 1 )
{
result = func2(a1, a2, (_DWORD *)a3, v9, a4);
if ( (_DWORD)result )
break;
v7 = *(_DWORD *)(a3 + 16);
if ( ++v9[0] >= a1 )
{
if ( !v7 || *(_DWORD *)a3 )
return 0LL;
goto LABEL_14;
}
if ( !v7 )
return 0LL;
}
}
return result;
}

original_code:
enum HT_FR
invoc_read (
 const size_t argc,
 const char * * argv,
 struct invoc * const inv,
 enum HT_FAIL_INVOC * const invfail
 )
{
 size_t i;
 enum HT_FR fr = HT_FR_NONE;
 if (((void *)0) == argv || ((void *)0) == inv || ((void *)0) == invfail)
 {
  if (((void *)0) != inv)
  {
   inv->info.nplay_print = HT_INV_PRINT_HELP;
   inv->file_rc = "";
   inv->play = HT_FALSE;
  }
  return HT_FR_FAIL_NULLPTR;
 }
 * invfail = HT_FAIL_INVOC_NONE;
 inv->info.nplay_print = HT_INV_PRINT_HELP;
 inv->file_rc = "";
 inv->play = HT_TRUE;
 for (i = (size_t)1; i < argc && inv->play; i++)
 {
  fr = invoc_read_arg(argc, argv, inv, & i, invfail);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
  fr = HT_FR_NONE;
 }
 if (inv->play && HT_UIT_NONE == inv->info.play_ui)
 {
  inv->info.play_ui = ui_def();
  if (HT_UIT_NONE == inv->info.play_ui)
  {
   return HT_FR_FAIL_UI_NONE;
  }
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
enum HT_FR invoc_read(unsigned long argc, char **argv, struct invoc *inv, enum HT_FAIL_INVOC *invfail)
{
 unsigned long i;
 enum HT_FR fr = HT_FR_NONE;
 if (((void *)0) == argv || ((void *)0) == inv || ((void *)0) == invfail)
 {
  if (((void *)0) != inv)
  {
   inv->info.nplay_print = HT_INV_PRINT_HELP;
   inv->file_rc = "";
   inv->play = HT_FALSE;
  }
  return HT_FR_FAIL_NULLPTR;
 }
 * invfail = HT_FAIL_INVOC_NONE;
 inv->info.nplay_print = HT_INV_PRINT_HELP;
 inv->file_rc = "";
 inv->play = HT_TRUE;
 for (i = (unsigned long)1; i < argc && inv->play; i++)
 {
  fr = invoc_read_arg(argc, argv, inv, & i, invfail);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
  fr = HT_FR_NONE;
 }
 if (inv->play && HT_UIT_NONE == inv->info.play_ui)
 {
  inv->info.play_ui = ui_def();
  if (HT_UIT_NONE == inv->info.play_ui)
  {
   return HT_FR_FAIL_UI_NONE;
  }
 }
 return HT_FR_SUCCESS;
}


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

if ( a1 == 3 )
return HT_L_FAIL_INVOC_UI_UNK;
if ( a1 > 3 )
{
result = HT_L_FAIL_INVOC_RC_NONE;
if ( a1 != 4 )
return HT_L_FR_UNKNOWN;
}
else
{
result = HT_L_FAIL_INVOC_UNK;
if ( a1 != 1 )
{
if ( a1 == 2 )
return HT_L_FAIL_INVOC_UI_NONE;
return HT_L_FR_UNKNOWN;
}
}
return result;
}

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

if ( a1 == 3 )
return HT_L_FAIL_INVOC_UI_UNK;
if ( a1 > 3 )
{
result = HT_L_FAIL_INVOC_RC_NONE;
if ( a1 != 4 )
return HT_L_FR_UNKNOWN;
}
else
{
result = HT_L_FAIL_INVOC_UNK;
if ( a1 != 1 )
{
if ( a1 == 2 )
return HT_L_FAIL_INVOC_UI_NONE;
return HT_L_FR_UNKNOWN;
}
}
return result;
}

original_code:
const char *
fail_invoc_what (
 const enum HT_FAIL_INVOC code
 )
{
 switch (code)
 {
  case HT_FAIL_INVOC_UNK:
   return HT_L_FAIL_INVOC_UNK;
  case HT_FAIL_INVOC_UI_NONE:
   return HT_L_FAIL_INVOC_UI_NONE;
  case HT_FAIL_INVOC_UI_UNK:
   return HT_L_FAIL_INVOC_UI_UNK;
  case HT_FAIL_INVOC_RC_NONE:
   return HT_L_FAIL_INVOC_RC_NONE;
  case HT_FAIL_INVOC_NONE:
  default:
   return HT_L_FR_UNKNOWN;
 }
}

canonical_original_code:
char *fail_invoc_what(enum HT_FAIL_INVOC code)
{
 switch (code)
 {
  case HT_FAIL_INVOC_UNK:
   return HT_L_FAIL_INVOC_UNK;
  case HT_FAIL_INVOC_UI_NONE:
   return HT_L_FAIL_INVOC_UI_NONE;
  case HT_FAIL_INVOC_UI_UNK:
   return HT_L_FAIL_INVOC_UI_UNK;
  case HT_FAIL_INVOC_RC_NONE:
   return HT_L_FAIL_INVOC_RC_NONE;
  case HT_FAIL_INVOC_NONE:
  default:
   return HT_L_FR_UNKNOWN;
 }
}

variable_types: enum HT_FAIL_INVOC { HT_FAIL_INVOC_NONE=0, HT_FAIL_INVOC_UNK=1, HT_FAIL_INVOC_UI_NONE=2, HT_FAIL_INVOC_UI_UNK=3, HT_FAIL_INVOC_RC_NONE=4 }

return_type: char *


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

switch ( a1 )
{
case 1:
result = HT_L_FAIL_RREADER_ARG_DUP;
break;
case 2:
result = HT_L_FAIL_RREADER_ARG_MISS;
break;
case 3:
result = HT_L_FAIL_RREADER_ARG_EXCESS;
break;
case 4:
result = HT_L_FAIL_RREADER_ARG_UNK;
break;
case 5:
result = HT_L_FAIL_RREADER_TYPE_DUP;
break;
case 6:
result = HT_L_FAIL_RREADER_TYPE_ORDER;
break;
case 7:
result = HT_L_FAIL_RREADER_TYPE_OVERFLOW;
break;
case 8:
result = HT_L_FAIL_RREADER_TYPE_UNDEF;
break;
case 9:
result = HT_L_FAIL_RREADER_NOSIZE;
break;
case 10:
result = HT_L_FAIL_RREADER_INCOMP;
break;
case 11:
result = HT_L_FAIL_GEN_STRTOL;
break;
case 12:
result = HT_L_FAIL_GEN_NOOB;
break;
case 13:
result = HT_L_FAIL_GEN_BIT_SINGLE;
break;
default:
result = HT_L_FR_UNKNOWN;
break;
}
return result;
}

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

switch ( a1 )
{
case 1:
result = HT_L_FAIL_RREADER_ARG_DUP;
break;
case 2:
result = HT_L_FAIL_RREADER_ARG_MISS;
break;
case 3:
result = HT_L_FAIL_RREADER_ARG_EXCESS;
break;
case 4:
result = HT_L_FAIL_RREADER_ARG_UNK;
break;
case 5:
result = HT_L_FAIL_RREADER_TYPE_DUP;
break;
case 6:
result = HT_L_FAIL_RREADER_TYPE_ORDER;
break;
case 7:
result = HT_L_FAIL_RREADER_TYPE_OVERFLOW;
break;
case 8:
result = HT_L_FAIL_RREADER_TYPE_UNDEF;
break;
case 9:
result = HT_L_FAIL_RREADER_NOSIZE;
break;
case 10:
result = HT_L_FAIL_RREADER_INCOMP;
break;
case 11:
result = HT_L_FAIL_GEN_STRTOL;
break;
case 12:
result = HT_L_FAIL_GEN_NOOB;
break;
case 13:
result = HT_L_FAIL_GEN_BIT_SINGLE;
break;
default:
result = HT_L_FR_UNKNOWN;
break;
}
return result;
}

original_code:
const char *
fail_rreader_what (
 const enum HT_FAIL_RREADER code
 )
{
 switch (code)
 {
  case HT_FAIL_RREADER_ARG_DUP:
   return HT_L_FAIL_RREADER_ARG_DUP;
  case HT_FAIL_RREADER_ARG_MISS:
   return HT_L_FAIL_RREADER_ARG_MISS;
  case HT_FAIL_RREADER_ARG_EXCESS:
   return HT_L_FAIL_RREADER_ARG_EXCESS;
  case HT_FAIL_RREADER_ARG_UNK:
   return HT_L_FAIL_RREADER_ARG_UNK;
  case HT_FAIL_RREADER_TYPE_DUP:
   return HT_L_FAIL_RREADER_TYPE_DUP;
  case HT_FAIL_RREADER_TYPE_ORDER:
   return HT_L_FAIL_RREADER_TYPE_ORDER;
  case HT_FAIL_RREADER_TYPE_OVERFLOW:
   return HT_L_FAIL_RREADER_TYPE_OVERFLOW;
  case HT_FAIL_RREADER_TYPE_UNDEF:
   return HT_L_FAIL_RREADER_TYPE_UNDEF;
  case HT_FAIL_RREADER_NOSIZE:
   return HT_L_FAIL_RREADER_NOSIZE;
  case HT_FAIL_RREADER_INCOMP:
   return HT_L_FAIL_RREADER_INCOMP;
  case HT_FAIL_RREADER_STRTOL:
   return HT_L_FAIL_GEN_STRTOL;
  case HT_FAIL_RREADER_NOOB:
   return HT_L_FAIL_GEN_NOOB;
  case HT_FAIL_RREADER_BIT_SINGLE:
   return HT_L_FAIL_GEN_BIT_SINGLE;
  case HT_FAIL_RREADER_NONE:
  default:
   return HT_L_FR_UNKNOWN;
 }
}

canonical_original_code:
char *fail_rreader_what(enum HT_FAIL_RREADER code)
{
 switch (code)
 {
  case HT_FAIL_RREADER_ARG_DUP:
   return HT_L_FAIL_RREADER_ARG_DUP;
  case HT_FAIL_RREADER_ARG_MISS:
   return HT_L_FAIL_RREADER_ARG_MISS;
  case HT_FAIL_RREADER_ARG_EXCESS:
   return HT_L_FAIL_RREADER_ARG_EXCESS;
  case HT_FAIL_RREADER_ARG_UNK:
   return HT_L_FAIL_RREADER_ARG_UNK;
  case HT_FAIL_RREADER_TYPE_DUP:
   return HT_L_FAIL_RREADER_TYPE_DUP;
  case HT_FAIL_RREADER_TYPE_ORDER:
   return HT_L_FAIL_RREADER_TYPE_ORDER;
  case HT_FAIL_RREADER_TYPE_OVERFLOW:
   return HT_L_FAIL_RREADER_TYPE_OVERFLOW;
  case HT_FAIL_RREADER_TYPE_UNDEF:
   return HT_L_FAIL_RREADER_TYPE_UNDEF;
  case HT_FAIL_RREADER_NOSIZE:
   return HT_L_FAIL_RREADER_NOSIZE;
  case HT_FAIL_RREADER_INCOMP:
   return HT_L_FAIL_RREADER_INCOMP;
  case HT_FAIL_RREADER_STRTOL:
   return HT_L_FAIL_GEN_STRTOL;
  case HT_FAIL_RREADER_NOOB:
   return HT_L_FAIL_GEN_NOOB;
  case HT_FAIL_RREADER_BIT_SINGLE:
   return HT_L_FAIL_GEN_BIT_SINGLE;
  case HT_FAIL_RREADER_NONE:
  default:
   return HT_L_FR_UNKNOWN;
 }
}

variable_types: enum HT_FAIL_RREADER { HT_FAIL_RREADER_NONE=0, HT_FAIL_RREADER_ARG_DUP=1, HT_FAIL_RREADER_ARG_MISS=2, HT_FAIL_RREADER_ARG_EXCESS=3, HT_FAIL_RREADER_ARG_UNK=4, HT_FAIL_RREADER_TYPE_DUP=5, HT_FAIL_RREADER_TYPE_ORDER=6, HT_FAIL_RREADER_TYPE_OVERFLOW=7, HT_FAIL_RREADER_TYPE_UNDEF=8, HT_FAIL_RREADER_NOSIZE=9, HT_FAIL_RREADER_INCOMP=10, HT_FAIL_RREADER_STRTOL=11, HT_FAIL_RREADER_NOOB=12, HT_FAIL_RREADER_BIT_SINGLE=13 }


decompiled_code:
_BOOL8 __fastcall fr_fail_invoc(int a1)
{
return a1 == 12;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(int a1)
{
return a1 == 12;
}

original_code:
HT_BOOL
fr_fail_invoc (
 const enum HT_FR code
 )
{
 return HT_FR_FAIL_INVOC == code;
}

canonical_original_code:
enum HT_BOOL_ fr_fail_invoc(enum HT_FR code)
{
 return HT_FR_FAIL_INVOC == code;
}


decompiled_code:
_BOOL8 __fastcall fr_fail_rreader(int a1)
{
return a1 == 13;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return a1 == 13;
}

original_code:
HT_BOOL
fr_fail_rreader (
 const enum HT_FR code
 )
{
 return HT_FR_FAIL_RREADER == code;
}

canonical_original_code:
enum HT_BOOL_ fr_fail_rreader(enum HT_FR code)
{
 return HT_FR_FAIL_RREADER == code;
}


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

switch ( a1 )
{
case 1:
result = HT_L_FR_FAIL_NULLPTR;
break;
case 2:
result = HT_L_FR_FAIL_ARROB;
break;
case 3:
result = HT_L_FR_FAIL_ALLOC;
break;
case 4:
result = HT_L_FR_FAIL_ENUM_UNK;
break;
case 5:
result = HT_L_FR_FAIL_ILL_ARG;
break;
case 6:
result = HT_L_FR_FAIL_ILL_STATE;
break;
case 7:
result = HT_L_FR_FAIL_IO_ENV_UNDEF;
break;
case 8:
result = HT_L_FR_FAIL_IO_FILE_R;
break;
case 9:
result = HT_L_FR_FAIL_IO_PRINT;
break;
case 10:
result = HT_L_FR_FAIL_POSIX;
break;
case 14:
result = HT_L_FR_FAIL_UI_NONE;
break;
default:
result = HT_L_FR_UNKNOWN;
break;
}
return result;
}

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

switch ( a1 )
{
case 1:
result = HT_L_FR_FAIL_NULLPTR;
break;
case 2:
result = HT_L_FR_FAIL_ARROB;
break;
case 3:
result = HT_L_FR_FAIL_ALLOC;
break;
case 4:
result = HT_L_FR_FAIL_ENUM_UNK;
break;
case 5:
result = HT_L_FR_FAIL_ILL_ARG;
break;
case 6:
result = HT_L_FR_FAIL_ILL_STATE;
break;
case 7:
result = HT_L_FR_FAIL_IO_ENV_UNDEF;
break;
case 8:
result = HT_L_FR_FAIL_IO_FILE_R;
break;
case 9:
result = HT_L_FR_FAIL_IO_PRINT;
break;
case 10:
result = HT_L_FR_FAIL_POSIX;
break;
case 14:
result = HT_L_FR_FAIL_UI_NONE;
break;
default:
result = HT_L_FR_UNKNOWN;
break;
}
return result;
}

original_code:
const char *
fr_fail_what (
 const enum HT_FR code
 )
{
 switch (code)
 {
  case HT_FR_FAIL_ALLOC:
   return HT_L_FR_FAIL_ALLOC;
  case HT_FR_FAIL_NULLPTR:
   return HT_L_FR_FAIL_NULLPTR;
  case HT_FR_FAIL_ARROB:
   return HT_L_FR_FAIL_ARROB;
  case HT_FR_FAIL_ENUM_UNK:
   return HT_L_FR_FAIL_ENUM_UNK;
  case HT_FR_FAIL_ILL_ARG:
   return HT_L_FR_FAIL_ILL_ARG;
  case HT_FR_FAIL_ILL_STATE:
   return HT_L_FR_FAIL_ILL_STATE;
  case HT_FR_FAIL_IO_ENV_UNDEF:
   return HT_L_FR_FAIL_IO_ENV_UNDEF;
  case HT_FR_FAIL_IO_FILE_R:
   return HT_L_FR_FAIL_IO_FILE_R;
  case HT_FR_FAIL_IO_PRINT:
   return HT_L_FR_FAIL_IO_PRINT;
  case HT_FR_FAIL_UI_NONE:
   return HT_L_FR_FAIL_UI_NONE;
  case HT_FR_FAIL_POSIX:
   return HT_L_FR_FAIL_POSIX;
  case HT_FR_NONE:
  case HT_FR_SUCCESS:
  case HT_FR_FAIL_INVOC:
  case HT_FR_FAIL_RREADER:
  default:
   return HT_L_FR_UNKNOWN;
 }
}

canonical_original_code:
char *fr_fail_what(enum HT_FR code)
{
 switch (code)
 {
  case HT_FR_FAIL_ALLOC:
   return HT_L_FR_FAIL_ALLOC;
  case HT_FR_FAIL_NULLPTR:
   return HT_L_FR_FAIL_NULLPTR;
  case HT_FR_FAIL_ARROB:
   return HT_L_FR_FAIL_ARROB;
  case HT_FR_FAIL_ENUM_UNK:
   return HT_L_FR_FAIL_ENUM_UNK;
  case HT_FR_FAIL_ILL_ARG:
   return HT_L_FR_FAIL_ILL_ARG;
  case HT_FR_FAIL_ILL_STATE:
   return HT_L_FR_FAIL_ILL_STATE;
  case HT_FR_FAIL_IO_ENV_UNDEF:
   return HT_L_FR_FAIL_IO_ENV_UNDEF;
  case HT_FR_FAIL_IO_FILE_R:
   return HT_L_FR_FAIL_IO_FILE_R;
  case HT_FR_FAIL_IO_PRINT:
   return HT_L_FR_FAIL_IO_PRINT;
  case HT_FR_FAIL_UI_NONE:
   return HT_L_FR_FAIL_UI_NONE;
  case HT_FR_FAIL_POSIX:
   return HT_L_FR_FAIL_POSIX;
  case HT_FR_NONE:
  case HT_FR_SUCCESS:
  case HT_FR_FAIL_INVOC:
  case HT_FR_FAIL_RREADER:
  default:
   return HT_L_FR_UNKNOWN;
 }
}