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; // r8
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi
bool v14; // zf
unsigned int v15; // edx
int v17; // eax
__int64 v18; // rdi
int v19; // eax
__int64 v20; // rdi
int v21; // eax
__int64 v22; // rdi
__int64 v23; // rdi
int v24; // eax
__int64 v25; // rdi
int v26; // eax
__int64 v27; // rbp
double v28; // xmm0_8
__int64 v29; // rbp
__int64 v30; // rsi
char *endptr[4]; // [rsp+0h] [rbp-20h] BYREF

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

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; // r8
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi
bool v14; // zf
unsigned int v15; // edx
int v17; // eax
__int64 v18; // rdi
int v19; // eax
__int64 v20; // rdi
int v21; // eax
__int64 v22; // rdi
__int64 v23; // rdi
int v24; // eax
__int64 v25; // rdi
int v26; // eax
__int64 v27; // rbp
double v28; // xmm0_8
__int64 v29; // rbp
__int64 v30; // rsi
char *endptr[4]; // [rsp+0h] [rbp-20h] BYREF

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

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 v3; // eax
struct timeval v4; // [rsp+0h] [rbp-58h] BYREF
struct timeval v5; // [rsp+10h] [rbp-48h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF
struct timeval v7; // [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(&v7, 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(&v5, 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,
*((unsigned int *)a1 + 9),
*((_QWORD *)a1 + 2),
*((_QWORD *)a1 + 3)) )
printf("Compression failed. Success %d\n", 0LL);
gettimeofday(&v4, 0LL);
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
++*(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 9));
v3 = *((_DWORD *)a1 + 9) + 1;
*((_DWORD *)a1 + 9) = v3;
if ( v3 == numblocks )
*((_DWORD *)a1 + 9) = 0;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
pthread_cond_signal(*((pthread_cond_t **)a1 + 11));
gettimeofday(&tv, 0LL);
if ( maxiterations <= ++v1 )
goto LABEL_4;
}
++exit_signal;
}
LABEL_4:
deleteGPUmem(*((_QWORD *)a1 + 2));
deleteGPUmem(*((_QWORD *)a1 + 3));
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
int v1; // ebp
int v3; // eax
struct timeval v4; // [rsp+0h] [rbp-58h] BYREF
struct timeval v5; // [rsp+10h] [rbp-48h] BYREF
struct timeval tv; // [rsp+20h] [rbp-38h] BYREF
struct timeval v7; // [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(&v7, 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(&v5, 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,
*((unsigned int *)a1 + 9),
*((_QWORD *)a1 + 2),
*((_QWORD *)a1 + 3)) )
printf("Compression failed. Success %d\n", 0LL);
gettimeofday(&v4, 0LL);
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
++*(_DWORD *)(*((_QWORD *)a1 + 7) + 4LL * *((int *)a1 + 9));
v3 = *((_DWORD *)a1 + 9) + 1;
*((_DWORD *)a1 + 9) = v3;
if ( v3 == numblocks )
*((_DWORD *)a1 + 9) = 0;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
pthread_cond_signal(*((pthread_cond_t **)a1 + 11));
gettimeofday(&tv, 0LL);
if ( maxiterations <= ++v1 )
goto LABEL_4;
}
++exit_signal;
}
LABEL_4:
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 *v1; // rax
void *v2; // r12
int v3; // ebp
unsigned int v5; // er14
__int64 v6; // r15
const void *v7; // r13
int v8; // eax
unsigned int v9; // [rsp+Ch] [rbp-7Ch] BYREF
struct timeval v10; // [rsp+10h] [rbp-78h] BYREF
struct timeval v11; // [rsp+20h] [rbp-68h] BYREF
struct timeval tv; // [rsp+30h] [rbp-58h] BYREF
struct timeval v13; // [rsp+40h] [rbp-48h] BYREF

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

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

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

return_type: int


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

return_type: void


queueDelete

decompiled_code:
__int64 __fastcall queueDelete(void *ptr)
{
__int64 v1; // rbx

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 )
{
v1 = 0LL;
do
{
deleteCPUmem(*(_QWORD *)(*((_QWORD *)ptr + 1) + 8 * v1));
deleteCPUmem(*(_QWORD *)(*(_QWORD *)ptr + 8 * v1++));
}
while ( numblocks > (int)v1 );
}
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 v1; // rbx

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 )
{
v1 = 0LL;
do
{
deleteCPUmem(*(_QWORD *)(*((_QWORD *)ptr + 1) + 8 * v1));
deleteCPUmem(*(_QWORD *)(*(_QWORD *)ptr + 8 * v1++));
}
while ( numblocks > (int)v1 );
}
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)
{
maxiterations = a2;
numblocks = a3;
blocksize = a4;
outputfilename = a5;
bookkeeping = a6;
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)
{
maxiterations = a2;
numblocks = a3;
blocksize = a4;
outputfilename = a5;
bookkeeping = a6;
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 v1; // ebp
int v2; // edx
int v3; // eax
int v4; // eax
__int64 v5; // rsi
unsigned int v6; // eax
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

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

v8[0] = 0;
*((_QWORD *)a1 + 2) = deinitGPUmem((unsigned int)bsize);
*((_QWORD *)a1 + 3) = deinitGPUmem((unsigned int)(2 * bsize));
if ( nchunks > 0 )
{
v1 = 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));
v4 = *((_DWORD *)a1 + 9);
v5 = *((unsigned int *)a1 + v4 + 14);
if ( (_DWORD)v5 != bsize )
{
v6 = decompression_kernel_wrapper(*(_QWORD *)(*(_QWORD *)a1 + 8LL * v4), v5, v8, 0LL, 1LL, 1LL);
if ( !v6 || v8[0] != bsize )
printf("Decompression failed. Success %d\n", v6);
}
pthread_mutex_lock(*((pthread_mutex_t **)a1 + 9));
++*(_DWORD *)(*((_QWORD *)a1 + 6) + 4LL * *((int *)a1 + 9));
v2 = *((_DWORD *)a1 + 9);
v3 = v2 + 1;
if ( v2 == 3 )
v3 = 0;
*((_DWORD *)a1 + 9) = v3;
pthread_mutex_unlock(*((pthread_mutex_t **)a1 + 9));
pthread_cond_signal(*((pthread_cond_t **)a1 + 11));
++v1;
}
while ( nchunks > v1 );
}
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:
_BOOL8 __fastcall single_bit(int a1)
{
_BOOL8 result; // rax

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

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

result = 0LL;
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; // rbx
int v3; // er13
unsigned __int64 v4; // rax
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

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

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

v2 = _errno_location();
v3 = *v2;
*v2 = 0;
v4 = strtoul(nptr, &endptr, 10);
if ( *v2 || *endptr || v4 > 0xFFFF )
{
*v2 = v3;
*a2 = -1;
result = 0LL;
}
else
{
*a2 = v4;
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; // si
__int64 result; // rax

if ( a5 == 0LL || a3 == 0LL || !a2 )
{
result = 1LL;
if ( a3 )
*a3 = 0;
}
else
{
*a3 = 0;
if ( a4 >= a1 )
{
*a5 = 2;
result = 12LL;
}
else
{
v5 = **(_BYTE **)(a2 + 8 * a4);
if ( v5 )
{
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; // si
__int64 result; // rax

if ( a5 == 0LL || a3 == 0LL || !a2 )
{
result = 1LL;
if ( a3 )
*a3 = 0;
}
else
{
*a3 = 0;
if ( a4 >= a1 )
{
*a5 = 2;
result = 12LL;
}
else
{
v5 = **(_BYTE **)(a2 + 8 * a4);
if ( v5 )
{
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; // rcx
__int64 result; // rax

if ( a5 == 0LL || a3 == 0 || !a2 )
{
result = 1LL;
if ( a3 )
*(_QWORD *)(a3 + 8) = &unk_2EA;
}
else
{
*(_QWORD *)(a3 + 8) = &unk_2EA;
if ( a4 >= a1 )
{
*a5 = 4;
result = 12LL;
}
else
{
v5 = *(_BYTE **)(a2 + 8 * a4);
if ( *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; // rcx
__int64 result; // rax

if ( a5 == 0LL || a3 == 0 || !a2 )
{
result = 1LL;
if ( a3 )
*(_QWORD *)(a3 + 8) = &unk_2EA;
}
else
{
*(_QWORD *)(a3 + 8) = &unk_2EA;
if ( a4 >= a1 )
{
*a5 = 4;
result = 12LL;
}
else
{
v5 = *(_BYTE **)(a2 + 8 * a4);
if ( *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 result; // rax
__int64 v9; // r15
__int64 v10; // r14
char v11; // al

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

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, __int64 a2, _DWORD *a3, __int64 *a4, _DWORD *a5)
{
__int64 result; // rax
__int64 v9; // r15
__int64 v10; // r14
char v11; // al

if ( !a2 || !a3 )
return 1LL;
result = 1LL;
if ( a5 )
{
v9 = *a4;
v10 = *(_QWORD *)(a2 + 8 * *a4);
if ( strlen((const char *)v10) > 1 && *(_BYTE *)v10 == 45 )
{
v11 = *(_BYTE *)(v10 + 1);
if ( HT_L_INV_S_HELP == v11 )
{
*a3 = 0;
a3[4] = 0;
result = 0LL;
}
else if ( HT_L_INV_S_NINE == v11 )
{
*a3 = 1;
a3[4] = 0;
result = 0LL;
}
else if ( HT_L_INV_S_VERSION == v11 )
{
*a3 = 2;
a3[4] = 0;
result = 0LL;
}
else if ( HT_L_INV_S_UI == v11 )
{
*a4 = v9 + 1;
result = func0(a1, a2, a3, v9 + 1, a5);
}
else if ( HT_L_INV_S_RUNCOM == v11 )
{
*a4 = v9 + 1;
result = func1(a1, a2, (__int64)a3, v9 + 1, a5);
}
else
{
*a5 = 1;
result = 12LL;
}
}
else
{
*a5 = 1;
result = 12LL;
}
}
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 }


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


decompiled_code:
__int64 print_inv_nine()
{
int v0; // edx

v0 = (int)((double)rand() * 4.656612873077393e-10 * 9.0);
if ( v0 )
{
switch ( v0 )
{
case 1:
if ( puts(aTefldu) >= 0
&& puts(aTeitirV) >= 0
&& puts(aVar) >= 0
&& puts(aVant) >= 0
&& puts(aUns) >= 0
&& puts(&byte_C3D) >= 0
&& puts(&byte_C4B) >= 0 )
{
puts(&byte_C5C);
}
break;
case 2:
if ( puts(aTaflEmk) >= 0
&& puts(&byte_C85) >= 0
&& puts(aT) >= 0
&& puts(aT_0) >= 0
&& puts(aSkr) >= 0
&& puts(aSk) >= 0
&& puts(aHv) >= 0 )
{
puts(aHarpsl);
}
break;
case 3:
if ( puts("Burr var inn ellsti,") >= 0
&& puts("en Barn annat,") >= 0
&& puts(aJ) >= 0
&& puts(aArfiM) >= 0
&& puts(aNi) >= 0
&& puts(aN) >= 0
&& puts("Sonr ok Sveinn,") >= 0
&& puts("- sund ok tafl, -") >= 0
&& puts(aKundrH) >= 0 )
{
puts("Konr var inn yngsti.");
}
break;
case 4:
if ( puts(aMj) >= 0
&& puts(aR_0) >= 0
&& puts(&byte_E0C) >= 0
&& puts(asc_E24) >= 0
&& puts(asc_E32) >= 0
&& puts(aOkF) >= 0
&& puts(aM) >= 0 )
{
puts(aOkManiAustr);
}
break;
case 5:
if ( puts(aGestumblindiM) >= 0
&& puts(aHverjarEru) >= 0
&& puts(aErUmSinnDr) >= 0
&& puts(aV) >= 0
&& puts(aInarJ) >= 0
&& puts("um alla daga,") >= 0
&& puts(aEnInarFegriFr) >= 0
&& puts(aHei) >= 0
&& puts(aHygg) >= 0
&& puts(aG) >= 0
&& puts("Gestumblindi,") >= 0
&& puts(aGetitEr) >= 0
&& fputs(&byte_1070, stdout) >= 0 )
{
puts(aUmHnefannOkFyl);
}
break;
case 6:
if ( puts(aGestumblindiM) >= 0
&& puts(aHvatEr) >= 0
&& puts(aErDreprF) >= 0
&& puts(aOkErJ) >= 0
&& puts(aHornHefir) >= 0
&& puts(aEnH) >= 0
&& puts(aOkRennrSemRenn) >= 0
&& puts(aHei) >= 0
&& puts(aHygg) >= 0
&& puts(aG_0) >= 0
&& puts("Gestumblindi,") >= 0
&& puts(aGetitEr) >= 0
&& fputs(&byte_10D0, stdout) >= 0 )
{
puts(aBj);
}
break;
case 7:
if ( fputs(aJafnanSkemmtu, stdout) >= 0
&& fputs(aGunnlaugrLag, stdout) >= 0
&& fputs(aAnnarsBr, stdout) >= 0
&& fputs(aV_0, stdout) >= 0
&& fputs(aHelgaVarSv, stdout) >= 0
&& fputs(aMannaAtHonHafi, stdout) >= 0
&& fputs(asc_1240, stdout) >= 0
&& fputs(aHanaAllaOkSv, stdout) >= 0
&& fputs(aEngiKostr, stdout) >= 0 )
{
fwrite(&unk_12E0, 1uLL, 0x33uLL, stdout);
}
break;
default:
if ( fputs(s, stdout) >= 0
&& fputs(aLi, stdout) >= 0
&& fputs(aEnHannSatAtTaf, stdout) >= 0
&& fputs(&byte_13C0, stdout) >= 0
&& fputs(aOkVildu, stdout) >= 0
&& fputs(aHannSvaradeEng, stdout) >= 0
&& fputs(aR, stdout) >= 0 )
{
fwrite(&unk_1020, 1uLL, 0x19uLL, stdout);
}
break;
}
}
else if ( puts(&byte_B86) >= 0
&& puts("undrsamligar") >= 0
&& puts(aGullnarT) >= 0
&& puts(&byte_BB3) >= 0
&& puts(&byte_BC5) >= 0 )
{
puts(&byte_BD7);
}
return 0LL;
}

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

v0 = (int)((double)rand() * 4.656612873077393e-10 * 9.0);
if ( v0 )
{
switch ( v0 )
{
case 1:
if ( puts(aTefldu) >= 0
&& puts(aTeitirV) >= 0
&& puts(aVar) >= 0
&& puts(aVant) >= 0
&& puts(aUns) >= 0
&& puts(&byte_C3D) >= 0
&& puts(&byte_C4B) >= 0 )
{
puts(&byte_C5C);
}
break;
case 2:
if ( puts(aTaflEmk) >= 0
&& puts(&byte_C85) >= 0
&& puts(aT) >= 0
&& puts(aT_0) >= 0
&& puts(aSkr) >= 0
&& puts(aSk) >= 0
&& puts(aHv) >= 0 )
{
puts(aHarpsl);
}
break;
case 3:
if ( puts("Burr var inn ellsti,") >= 0
&& puts("en Barn annat,") >= 0
&& puts(aJ) >= 0
&& puts(aArfiM) >= 0
&& puts(aNi) >= 0
&& puts(aN) >= 0
&& puts("Sonr ok Sveinn,") >= 0
&& puts("- sund ok tafl, -") >= 0
&& puts(aKundrH) >= 0 )
{
puts("Konr var inn yngsti.");
}
break;
case 4:
if ( puts(aMj) >= 0
&& puts(aR_0) >= 0
&& puts(&byte_E0C) >= 0
&& puts(asc_E24) >= 0
&& puts(asc_E32) >= 0
&& puts(aOkF) >= 0
&& puts(aM) >= 0 )
{
puts(aOkManiAustr);
}
break;
case 5:
if ( puts(aGestumblindiM) >= 0
&& puts(aHverjarEru) >= 0
&& puts(aErUmSinnDr) >= 0
&& puts(aV) >= 0
&& puts(aInarJ) >= 0
&& puts("um alla daga,") >= 0
&& puts(aEnInarFegriFr) >= 0
&& puts(aHei) >= 0
&& puts(aHygg) >= 0
&& puts(aG) >= 0
&& puts("Gestumblindi,") >= 0
&& puts(aGetitEr) >= 0
&& fputs(&byte_1070, stdout) >= 0 )
{
puts(aUmHnefannOkFyl);
}
break;
case 6:
if ( puts(aGestumblindiM) >= 0
&& puts(aHvatEr) >= 0
&& puts(aErDreprF) >= 0
&& puts(aOkErJ) >= 0
&& puts(aHornHefir) >= 0
&& puts(aEnH) >= 0
&& puts(aOkRennrSemRenn) >= 0
&& puts(aHei) >= 0
&& puts(aHygg) >= 0
&& puts(aG_0) >= 0
&& puts("Gestumblindi,") >= 0
&& puts(aGetitEr) >= 0
&& fputs(&byte_10D0, stdout) >= 0 )
{
puts(aBj);
}
break;
case 7:
if ( fputs(aJafnanSkemmtu, stdout) >= 0
&& fputs(aGunnlaugrLag, stdout) >= 0
&& fputs(aAnnarsBr, stdout) >= 0
&& fputs(aV_0, stdout) >= 0
&& fputs(aHelgaVarSv, stdout) >= 0
&& fputs(aMannaAtHonHafi, stdout) >= 0
&& fputs(asc_1240, stdout) >= 0
&& fputs(aHanaAllaOkSv, stdout) >= 0
&& fputs(aEngiKostr, stdout) >= 0 )
{
fwrite(&unk_12E0, 1uLL, 0x33uLL, stdout);
}
break;
default:
if ( fputs(s, stdout) >= 0
&& fputs(aLi, stdout) >= 0
&& fputs(aEnHannSatAtTaf, stdout) >= 0
&& fputs(&byte_13C0, stdout) >= 0
&& fputs(aOkVildu, stdout) >= 0
&& fputs(aHannSvaradeEng, stdout) >= 0
&& fputs(aR, stdout) >= 0 )
{
fwrite(&unk_1020, 1uLL, 0x19uLL, stdout);
}
break;
}
}
else if ( puts(&byte_B86) >= 0
&& puts("undrsamligar") >= 0
&& puts(aGullnarT) >= 0
&& puts(&byte_BB3) >= 0
&& puts(&byte_BC5) >= 0 )
{
puts(&byte_BD7);
}
return 0LL;
}

original_code:
static
enum HT_FR
print_inv_nine (void)
{
 int r = 0;
 int random = 1 + (int)(9.0 * (rand() / (2147483647 + 1.0)));
 if (1 == random)
 {
  r = r < 0 ? r : puts("Þar munu eftir");
  r = r < 0 ? r : puts("undrsamligar");
  r = r < 0 ? r : puts("gullnar tǫflur");
  r = r < 0 ? r : puts("í grasi finnask,");
  r = r < 0 ? r : puts("þærs í árdaga");
  r = r < 0 ? r : puts("áttar hǫfðu.");
 }
 else if (2 == random)
 {
  r = r < 0 ? r : puts("Tefldu í túni,");
  r = r < 0 ? r : puts("teitir váru,");
  r = r < 0 ? r : puts("var þeim vettergis");
  r = r < 0 ? r : puts("vant ór gulli,");
  r = r < 0 ? r : puts("uns þrjár kvámu");
  r = r < 0 ? r : puts("þursa meyjar");
  r = r < 0 ? r : puts("ámáttkar mjǫk");
  r = r < 0 ? r : puts("ór Jǫtunheimum.");
 }
 else if (3 == random)
 {
  r = r < 0 ? r : puts("Tafl emk ǫrr at efla,");
  r = r < 0 ? r : puts("íþróttir kank níu,");
  r = r < 0 ? r : puts("týnik trauðla rúnum,");
  r = r < 0 ? r : puts("tíð er bók ok smíðir,");
  r = r < 0 ? r : puts("skríða kank á skíðum,");
  r = r < 0 ? r : puts("skýtk ok rœk, svát nýtir;");
  r = r < 0 ? r : puts("hvártveggja kank hyggja:");
  r = r < 0 ? r : puts("harpslótt ok bragþóttu.");
 }
 else if (4 == random)
 {
  r = r < 0 ? r : puts("Burr var inn ellsti,");
  r = r < 0 ? r : puts("en Barn annat,");
  r = r < 0 ? r : puts("Jóð ok Aðal,");
  r = r < 0 ? r : puts("Arfi, Mǫgr,");
  r = r < 0 ? r : puts("Niðr ok Niðjungr,");
  r = r < 0 ? r : puts("- námu leika, -");
  r = r < 0 ? r : puts("Sonr ok Sveinn,");
  r = r < 0 ? r : puts("- sund ok tafl, -");
  r = r < 0 ? r : puts("Kundr hét enn,");
  r = r < 0 ? r : puts("Konr var inn yngsti.");
 }
 else if (5 == random)
 {
  r = r < 0 ? r : puts("Mjǫk eru reifðir");
  r = r < 0 ? r : puts("rógbirtingar,");
  r = r < 0 ? r : puts("þeirs í Haralds túni");
  r = r < 0 ? r : puts("húnum verpa;");
  r = r < 0 ? r : puts("féi eru þeir gœddir");
  r = r < 0 ? r : puts("ok fǫgrum mækum,");
  r = r < 0 ? r : puts("málmi húnlenzkum");
  r = r < 0 ? r : puts("ok mani austrœnu.");
 }
 else if (6 == random)
 {
  r = r < 0 ? r : puts("Gestumblindi mælti:\n");
  r = r < 0 ? r : puts("\"Hverjar eru þær snótir,");
  r = r < 0 ? r : puts("er um sinn dróttin");
  r = r < 0 ? r : puts("vápnlausar vega,");
  r = r < 0 ? r : puts("inar jǫrpu hlífa");
  r = r < 0 ? r : puts("um alla daga,");
  r = r < 0 ? r : puts("en inar fegri frýja?");
  r = r < 0 ? r : puts("Heiðrekr konungr,");
  r = r < 0 ? r : puts("hygg þú at gátu.\"\n");
  r = r < 0 ? r : puts("\"Góð er gáta þín,");
  r = r < 0 ? r : puts("Gestumblindi,");
  r = r < 0 ? r : puts("getit er þeirar:\n");
  r = r < 0 ? r : fputs(
  "Þat er hneftafl. Tǫflur drepast vápnlausar ", stdout);
  r = r < 0 ? r : puts(
   "um hnefann, ok fylgja honum inar rauðu.\"");
 }
 else if (7 == random)
 {
  r = r < 0 ? r : puts("Gestumblindi mælti:\n");
  r = r < 0 ? r : puts("\"Hvat er þat dýra,");
  r = r < 0 ? r : puts("er drepr fé manna");
  r = r < 0 ? r : puts("ok er járni kringt útan,");
  r = r < 0 ? r : puts("horn hefir átta,");
  r = r < 0 ? r : puts("en hǫfuð ekki");
  r = r < 0 ? r : puts("ok rennr, sem renna má?");
  r = r < 0 ? r : puts("Heiðrekr konungr,");
  r = r < 0 ? r : puts("hygg þú at gátu.\"\n");
  r = r < 0 ? r : puts("\"Gód er gáta þín,");
  r = r < 0 ? r : puts("Gestumblindi,");
  r = r < 0 ? r : puts("getit er þeirar:\n");
  r = r < 0 ? r : fputs(
  "Þat er húnn í hneftafli; hann heitir som ", stdout);
  r = r < 0 ? r : puts(
   "bjǫrn; hann rennr, þegar honum er kastat.\"");
 }
 else if (8 == random)
 {
  r = r < 0 ? r :
  fputs("Jafnan skemmtu þau Helga sér at tafli ok ",
   stdout);
  r = r < 0 ? r :
  fputs("Gunnlaugr. Lagði hvárt þeira góðan þokka til ",
   stdout);
  r = r < 0 ? r :
  fputs("annars bráðliga, sem raunir bar á síðan. Þau ",
   stdout);
  r = r < 0 ? r : fputs("váru mjǫk jafnaldrar.\n\n",
   stdout);
  r = r < 0 ? r :
  fputs("Helga var svá fǫgr, at þat er sǫgn fróðra ",
   stdout);
  r = r < 0 ? r :
  fputs("manna, at hon hafi fegrst kona verit á Íslandi.",
   stdout);
  r = r < 0 ? r :
  fputs(" Hár hennar var svá mikit, at þat mátti hylja ",
   stdout);
  r = r < 0 ? r :
  fputs("hana alla, ok svá fagrt sem gull barit, ok ",
   stdout);
  r = r < 0 ? r :
  fputs("engi kostr þótti þá þvílíkr sem Helga in fagra ",
   stdout);
  r = r < 0 ? r :
  fputs("í ǫllum Borgarfirði ok víðara annars staðar.\n",
   stdout);
 }
 else
 {
  r = r < 0 ? r :
  fputs("En konungs synir sǫfnuðu liði ok fengu lítit ",
   stdout);
  r = r < 0 ? r :
  fputs("lið ok sendu orð Friðþjófi ok báðu hann liðs, ",
   stdout);
  r = r < 0 ? r :
  fputs("en hann sat at tafli, er sendimenn kómu til "
   "hans.\n\n", stdout);
  r = r < 0 ? r :
  fputs("Þeir mæltu: \"Konungar várar sendu þér kvedju ",
   stdout);
  r = r < 0 ? r :
  fputs("ok vildu þiggja liðsinni þitt til orrostu með "
   "sér.\"\n\n", stdout);
  r = r < 0 ? r :
  fputs("Hann svarade engu ok mælti við Bjǫrn: \"Leita ",
   stdout);
  r = r < 0 ? r :
  fputs("ráðs fyrir at tefla, því at tvíkostr er þér á ",
   stdout);
  r = r < 0 ? r :
  fputs("tvá vega,\" sagði hann.\n", stdout);
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR print_inv_nine()
{
 int r = 0;
 int random = 1 + (int)(9.0 * (rand() / (2147483647 + 1.0)));
 if (1 == random)
 {
  r = r < 0 ? r : puts("Þar munu eftir");
  r = r < 0 ? r : puts("undrsamligar");
  r = r < 0 ? r : puts("gullnar tǫflur");
  r = r < 0 ? r : puts("í grasi finnask,");
  r = r < 0 ? r : puts("þærs í árdaga");
  r = r < 0 ? r : puts("áttar hǫfðu.");
 }
 else if (2 == random)
 {
  r = r < 0 ? r : puts("Tefldu í túni,");
  r = r < 0 ? r : puts("teitir váru,");
  r = r < 0 ? r : puts("var þeim vettergis");
  r = r < 0 ? r : puts("vant ór gulli,");
  r = r < 0 ? r : puts("uns þrjár kvámu");
  r = r < 0 ? r : puts("þursa meyjar");
  r = r < 0 ? r : puts("ámáttkar mjǫk");
  r = r < 0 ? r : puts("ór Jǫtunheimum.");
 }
 else if (3 == random)
 {
  r = r < 0 ? r : puts("Tafl emk ǫrr at efla,");
  r = r < 0 ? r : puts("íþróttir kank níu,");
  r = r < 0 ? r : puts("týnik trauðla rúnum,");
  r = r < 0 ? r : puts("tíð er bók ok smíðir,");
  r = r < 0 ? r : puts("skríða kank á skíðum,");
  r = r < 0 ? r : puts("skýtk ok rœk, svát nýtir;");
  r = r < 0 ? r : puts("hvártveggja kank hyggja:");
  r = r < 0 ? r : puts("harpslótt ok bragþóttu.");
 }
 else if (4 == random)
 {
  r = r < 0 ? r : puts("Burr var inn ellsti,");
  r = r < 0 ? r : puts("en Barn annat,");
  r = r < 0 ? r : puts("Jóð ok Aðal,");
  r = r < 0 ? r : puts("Arfi, Mǫgr,");
  r = r < 0 ? r : puts("Niðr ok Niðjungr,");
  r = r < 0 ? r : puts("- námu leika, -");
  r = r < 0 ? r : puts("Sonr ok Sveinn,");
  r = r < 0 ? r : puts("- sund ok tafl, -");
  r = r < 0 ? r : puts("Kundr hét enn,");
  r = r < 0 ? r : puts("Konr var inn yngsti.");
 }
 else if (5 == random)
 {
  r = r < 0 ? r : puts("Mjǫk eru reifðir");
  r = r < 0 ? r : puts("rógbirtingar,");
  r = r < 0 ? r : puts("þeirs í Haralds túni");
  r = r < 0 ? r : puts("húnum verpa;");
  r = r < 0 ? r : puts("féi eru þeir gœddir");
  r = r < 0 ? r : puts("ok fǫgrum mækum,");
  r = r < 0 ? r : puts("málmi húnlenzkum");
  r = r < 0 ? r : puts("ok mani austrœnu.");
 }
 else if (6 == random)
 {
  r = r < 0 ? r : puts("Gestumblindi mælti:\n");
  r = r < 0 ? r : puts("\"Hverjar eru þær snótir,");
  r = r < 0 ? r : puts("er um sinn dróttin");
  r = r < 0 ? r : puts("vápnlausar vega,");
  r = r < 0 ? r : puts("inar jǫrpu hlífa");
  r = r < 0 ? r : puts("um alla daga,");
  r = r < 0 ? r : puts("en inar fegri frýja?");
  r = r < 0 ? r : puts("Heiðrekr konungr,");
  r = r < 0 ? r : puts("hygg þú at gátu.\"\n");
  r = r < 0 ? r : puts("\"Góð er gáta þín,");
  r = r < 0 ? r : puts("Gestumblindi,");
  r = r < 0 ? r : puts("getit er þeirar:\n");
  r = r < 0 ? r : fputs(
  "Þat er hneftafl. Tǫflur drepast vápnlausar ", stdout);
  r = r < 0 ? r : puts(
   "um hnefann, ok fylgja honum inar rauðu.\"");
 }
 else if (7 == random)
 {
  r = r < 0 ? r : puts("Gestumblindi mælti:\n");
  r = r < 0 ? r : puts("\"Hvat er þat dýra,");
  r = r < 0 ? r : puts("er drepr fé manna");
  r = r < 0 ? r : puts("ok er járni kringt útan,");
  r = r < 0 ? r : puts("horn hefir átta,");
  r = r < 0 ? r : puts("en hǫfuð ekki");
  r = r < 0 ? r : puts("ok rennr, sem renna má?");
  r = r < 0 ? r : puts("Heiðrekr konungr,");
  r = r < 0 ? r : puts("hygg þú at gátu.\"\n");
  r = r < 0 ? r : puts("\"Gód er gáta þín,");
  r = r < 0 ? r : puts("Gestumblindi,");
  r = r < 0 ? r : puts("getit er þeirar:\n");
  r = r < 0 ? r : fputs(
  "Þat er húnn í hneftafli; hann heitir som ", stdout);
  r = r < 0 ? r : puts(
   "bjǫrn; hann rennr, þegar honum er kastat.\"");
 }
 else if (8 == random)
 {
  r = r < 0 ? r :
  fputs("Jafnan skemmtu þau Helga sér at tafli ok ",
   stdout);
  r = r < 0 ? r :
  fputs("Gunnlaugr. Lagði hvárt þeira góðan þokka til ",
   stdout);
  r = r < 0 ? r :
  fputs("annars bráðliga, sem raunir bar á síðan. Þau ",
   stdout);
  r = r < 0 ? r : fputs("váru mjǫk jafnaldrar.\n\n",
   stdout);
  r = r < 0 ? r :
  fputs("Helga var svá fǫgr, at þat er sǫgn fróðra ",
   stdout);
  r = r < 0 ? r :
  fputs("manna, at hon hafi fegrst kona verit á Íslandi.",
   stdout);
  r = r < 0 ? r :
  fputs(" Hár hennar var svá mikit, at þat mátti hylja ",
   stdout);
  r = r < 0 ? r :
  fputs("hana alla, ok svá fagrt sem gull barit, ok ",
   stdout);
  r = r < 0 ? r :
  fputs("engi kostr þótti þá þvílíkr sem Helga in fagra ",
   stdout);
  r = r < 0 ? r :
  fputs("í ǫllum Borgarfirði ok víðara annars staðar.\n",
   stdout);
 }
 else
 {
  r = r < 0 ? r :
  fputs("En konungs synir sǫfnuðu liði ok fengu lítit ",
   stdout);
  r = r < 0 ? r :
  fputs("lið ok sendu orð Friðþjófi ok báðu hann liðs, ",
   stdout);
  r = r < 0 ? r :
  fputs("en hann sat at tafli, er sendimenn kómu til "
   "hans.\n\n", stdout);
  r = r < 0 ? r :
  fputs("Þeir mæltu: \"Konungar várar sendu þér kvedju ",
   stdout);
  r = r < 0 ? r :
  fputs("ok vildu þiggja liðsinni þitt til orrostu með "
   "sér.\"\n\n", stdout);
  r = r < 0 ? r :
  fputs("Hann svarade engu ok mælti við Bjǫrn: \"Leita ",
   stdout);
  r = r < 0 ? r :
  fputs("ráðs fyrir at tefla, því at tvíkostr er þér á ",
   stdout);
  r = r < 0 ? r :
  fputs("tvá vega,\" sagði hann.\n", stdout);
 }
 return HT_FR_SUCCESS;
}

variable_types: r int

variable_types: random int


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

if ( fputs(HT_PROGNAME, stdout) < 0 || fputc(9, stdout) < 0 )
result = 9LL;
else
result = (printf("%d\t\t%s\n", 131214LL, HT_PREPROC) >> 31) & 9;
return result;
}

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

if ( fputs(HT_PROGNAME, stdout) < 0 || fputc(9, stdout) < 0 )
result = 9LL;
else
result = (printf("%d\t\t%s\n", 131214LL, HT_PREPROC) >> 31) & 9;
return result;
}

original_code:
static
enum HT_FR
print_inv_version (void)
{
 int rv;
 rv = fputs(HT_PROGNAME, stdout);
 rv = rv < 0 ? rv : fputc('\t', stdout);
 rv = rv < 0 ? rv : printf("%d\t\t%s\n", 131214, HT_PREPROC);
 return rv < 0 ? HT_FR_FAIL_IO_PRINT : HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR print_inv_version()
{
 int rv;
 rv = fputs(HT_PROGNAME, stdout);
 rv = rv < 0 ? rv : fputc('\t', stdout);
 rv = rv < 0 ? rv : printf("%d\t\t%s\n", 131214, HT_PREPROC);
 return rv < 0 ? HT_FR_FAIL_IO_PRINT : HT_FR_SUCCESS;
}

variable_types: rv int


decompiled_code:
__int64 __fastcall print_err_fail_invoc(unsigned int a1)
{
const char *v1; // rax
int v2; // edx
__int64 result; // rax

v1 = (const char *)fail_invoc_what();
v2 = fprintf(stderr, "[%d:%d]: %s\n", 12LL, a1, v1);
result = 9LL;
if ( v2 >= 0 )
result = (print_errno(stderr) >> 31) & 9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
const char *v1; // rax
int v2; // edx
__int64 result; // rax

v1 = (const char *)fail_invoc_what();
v2 = fprintf(stderr, "[%d:%d]: %s\n", 12LL, a1, v1);
result = 9LL;
if ( v2 >= 0 )
result = (func2(stderr) >> 31) & 9;
return result;
}

original_code:
static
enum HT_FR
print_err_fail_invoc (
 const enum HT_FAIL_INVOC code
 )
{
 const char * msg = fail_invoc_what(code);
 int rv = fprintf(stderr, "[%d:%d]: %s\n",
   (int)HT_FR_FAIL_INVOC, (int)code, msg);
 rv = rv < 0 ? rv : print_errno(stderr);
 return rv < 0 ? HT_FR_FAIL_IO_PRINT : HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR print_err_fail_invoc(enum HT_FAIL_INVOC code)
{
 char *msg = fail_invoc_what(code);
 int rv = fprintf(stderr, "[%d:%d]: %s\n",
   (int)HT_FR_FAIL_INVOC, (int)code, msg);
 rv = rv < 0 ? rv : print_errno(stderr);
 return rv < 0 ? HT_FR_FAIL_IO_PRINT : HT_FR_SUCCESS;
}

variable_types:
msg
char *


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

if ( a1 == 1 )
return print_inv_nine();
if ( a1 == 2 )
return print_inv_version();
result = 4LL;
if ( !a1 )
result = print_inv_help(0);
return result;
}

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

if ( a1 == 1 )
return func0();
if ( a1 == 2 )
return func1();
result = 4LL;
if ( !a1 )
result = func5(0);
return result;
}

original_code:
enum HT_FR
print_inv (
 const enum HT_INV_PRINT nplay_print
 )
{
 switch (nplay_print)
 {
  case HT_INV_PRINT_HELP:
   return print_inv_help(HT_FALSE);
  case HT_INV_PRINT_NINE:
   return print_inv_nine();
  case HT_INV_PRINT_VERSION:
   return print_inv_version();
  default:
   return HT_FR_FAIL_ENUM_UNK;
 }
}

canonical_original_code:
enum HT_FR print_inv(enum HT_INV_PRINT nplay_print)
{
 switch (nplay_print)
 {
  case HT_INV_PRINT_HELP:
   return print_inv_help(HT_FALSE);
  case HT_INV_PRINT_NINE:
   return print_inv_nine();
  case HT_INV_PRINT_VERSION:
   return print_inv_version();
  default:
   return HT_FR_FAIL_ENUM_UNK;
 }
}

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


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

if ( (unsigned int)fr_fail_invoc() )
result = print_err_fail_invoc(a2);
else
result = print_err_fr(stderr, a1);
return result;
}

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

if ( (unsigned int)fr_fail_invoc() )
result = func3(a2);
else
result = func7(stderr, a1);
return result;
}

original_code:
enum HT_FR
print_err_fr_invoc (
 const enum HT_FR code,
 const enum HT_FAIL_INVOC code_inv
 )
{
 if (fr_fail_invoc(code))
 {
  return print_err_fail_invoc (code_inv);
 }
 else
 {
  return print_err_fr (stderr,code);
 }
}

canonical_original_code:
enum HT_FR print_err_fr_invoc(enum HT_FR code, enum HT_FAIL_INVOC code_inv)
{
 if (fr_fail_invoc(code))
 {
  return print_err_fail_invoc (code_inv);
 }
 else
 {
  return print_err_fr (stderr,code);
 }
}


decompiled_code:
__int64 __fastcall ht_isblank(char a1)
{
return (a1 == 9) | (unsigned __int8)(a1 == 32);
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
return (a1 == 9) | (unsigned __int8)(a1 == 32);
}

original_code:
static
HT_BOOL
ht_isblank (
 const char ch
 )
{
 return ' ' == ch || '\t' == ch;
}

canonical_original_code:
static enum HT_BOOL_ ht_isblank(char ch)
{
 return ' ' == ch || '\t' == ch;
}

variable_types: ch char


decompiled_code:
void __fastcall ht_line_clear(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1)
{
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
static
void
ht_line_clear (
 struct ht_line * const l
 )
{
 l->wordc = (size_t)0;
}

canonical_original_code:
static void ht_line_clear(struct ht_line *l)
{
 l->wordc = (unsigned long)0;
}

variable_types: struct ht_line { struct ht_str { char *chars; unsigned long capc; } *words; unsigned long wordc; unsigned long capc; } *

user_defined_types: struct ht_line { struct ht_str *words; unsigned long wordc; unsigned long capc; }


original_code:
static
enum HT_FR
alloc_ht_str_chars (
 struct ht_line * const l,
 const size_t cap,
 const size_t it
 )
{
 size_t i = it;
 for (; i < l->capc; i++)
 {
  struct ht_str * const s = & l->words[i];
  s->capc = cap;
  s->chars = malloc(sizeof(* s->chars) * s->capc);
  if (((void *)0) == s->chars)
  {
   size_t j;
   for (j = it; j < i; j++)
   {
    free (l->words[j].chars);
    l->words[j].chars = ((void *)0);
   }
   return HT_FR_FAIL_ALLOC;
  }
  ht_str_clear(s);
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR alloc_ht_str_chars(struct ht_line *l, unsigned long cap, unsigned long it)
{
 unsigned long i = it;
 for (; i < l->capc; i++)
 {
  struct ht_str *s = & l->words[i];
  s->capc = cap;
  s->chars = malloc(sizeof(* s->chars) * s->capc);
  if (((void *)0) == s->chars)
  {
   unsigned long j;
   for (j = it; j < i; j++)
   {
    free (l->words[j].chars);
    l->words[j].chars = ((void *)0);
   }
   return HT_FR_FAIL_ALLOC;
  }
  ht_str_clear(s);
 }
 return HT_FR_SUCCESS;
}

variable_types:
cap
unsigned long

variable_types:
it
unsigned long

variable_types:
i
unsigned long

variable_types: struct ht_str { char *chars; unsigned long capc; } *

variable_types:
j
unsigned long


original_code:
static
enum HT_FR
ht_line_grow (
 struct ht_line * const l
 )
{
 struct ht_str * words_new;
 const size_t capc_old = l->capc;
 size_t capc_new = (size_t)((float)capc_old
  * HT_LINE_MEMC_GROWF);
 if (capc_new <= capc_old)
 {
  capc_new = capc_old + 1;
 }
 words_new = realloc(l->words, sizeof(* l->words) * capc_new);
 if (((void *)0) == words_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 l->words = words_new;
 l->capc = capc_new;
 return alloc_ht_str_chars(l, HT_STR_MEMC_DEF, capc_old);
}

canonical_original_code:
static enum HT_FR ht_line_grow(struct ht_line *l)
{
 struct ht_str *words_new;
 unsigned long capc_old = l->capc;
 unsigned long capc_new = (size_t)((float)capc_old
  * HT_LINE_MEMC_GROWF);
 if (capc_new <= capc_old)
 {
  capc_new = capc_old + 1;
 }
 words_new = realloc(l->words, sizeof(* l->words) * capc_new);
 if (((void *)0) == words_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 l->words = words_new;
 l->capc = capc_new;
 return alloc_ht_str_chars(l, HT_STR_MEMC_DEF, capc_old);
}

user_defined_types: struct ht_str { char *chars; unsigned long capc; }


original_code:
static
enum HT_FR
ht_str_grow (
 struct ht_str * s,
 const size_t capc_req
 )
{
 const size_t capc_old = s->capc;
 char * chars_new;
 size_t capc_new = (size_t)((float)capc_old
  * HT_STR_MEMC_GROWF);
 if (capc_new <= capc_req)
 {
  capc_new = capc_req + 1;
 }
 chars_new = realloc(s->chars, sizeof(* s->chars) * capc_new);
 if (((void *)0) == chars_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 s->chars = chars_new;
 s->capc = capc_new;
 {
  size_t i;
  for (i = capc_old; i < capc_new; i++)
  {
   s->chars[i] = '\0';
  }
 }
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR ht_str_grow(struct ht_str *s, unsigned long capc_req)
{
 unsigned long capc_old = s->capc;
 char *chars_new;
 unsigned long capc_new = (size_t)((float)capc_old
  * HT_STR_MEMC_GROWF);
 if (capc_new <= capc_req)
 {
  capc_new = capc_req + 1;
 }
 chars_new = realloc(s->chars, sizeof(* s->chars) * capc_new);
 if (((void *)0) == chars_new)
 {
  return HT_FR_FAIL_ALLOC;
 }
 s->chars = chars_new;
 s->capc = capc_new;
 {
  unsigned long i;
  for (i = capc_old; i < capc_new; i++)
  {
   s->chars[i] = '\0';
  }
 }
 return HT_FR_SUCCESS;
}


decompiled_code:
__int64 __fastcall ht_str_addchar(__int64 *a1, char a2, unsigned __int64 *a3)
{
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
__int64 result; // rax
unsigned __int64 v8; // rsi
__int64 v9; // rdi
unsigned __int64 v10; // r8

v5 = *a3;
v6 = a1[1];
result = 5LL;
if ( v5 < v6 && !*(_BYTE *)(*a1 + v5) )
{
v8 = v5 + 1;
if ( v6 > v8 || (result = ht_str_grow((__int64)a1, v8), !(_DWORD)result) )
{
*(_BYTE *)(*a1 + *a3) = a2;
v9 = *a1;
v10 = (*a3)++;
*(_BYTE *)(v9 + v10 + 1) = 0;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, char a2, unsigned __int64 *a3)
{
unsigned __int64 v5; // rsi
unsigned __int64 v6; // rdx
__int64 result; // rax
unsigned __int64 v8; // rsi
__int64 v9; // rdi
unsigned __int64 v10; // r8

v5 = *a3;
v6 = a1[1];
result = 5LL;
if ( v5 < v6 && !*(_BYTE *)(*a1 + v5) )
{
v8 = v5 + 1;
if ( v6 > v8 || (result = func6((__int64)a1, v8), !(_DWORD)result) )
{
*(_BYTE *)(*a1 + *a3) = a2;
v9 = *a1;
v10 = (*a3)++;
*(_BYTE *)(v9 + v10 + 1) = 0;
result = 0LL;
}
}
return result;
}

original_code:
static
enum HT_FR
ht_str_addchar (
 struct ht_str * s,
 const char ch,
 size_t * const charc
 )
{
 if (* charc >= s->capc || '\0' != s->chars[* charc])
 {
  return HT_FR_FAIL_ILL_ARG;
 }
 if (* charc + 1 >= s->capc)
 {
  const enum HT_FR fr = ht_str_grow(s, * charc + 1);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 s->chars[* charc] = ch;
 s->chars[++(* charc)] = '\0';
 return HT_FR_SUCCESS;
}

canonical_original_code:
static enum HT_FR ht_str_addchar(struct ht_str *s, char ch, unsigned long *charc)
{
 if (* charc >= s->capc || '\0' != s->chars[* charc])
 {
  return HT_FR_FAIL_ILL_ARG;
 }
 if (* charc + 1 >= s->capc)
 {
  enum HT_FR fr = ht_str_grow(s, * charc + 1);
  if (HT_FR_SUCCESS != fr)
  {
   return fr;
  }
 }
 s->chars[* charc] = ch;
 s->chars[++(* charc)] = '\0';
 return HT_FR_SUCCESS;
}

variable_types:
charc
unsigned long *


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

if ( *(_QWORD *)ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 16 * v2);
if ( v3 )
free(v3);
++v2;
}
while ( *((_QWORD *)ptr + 2) > v2 );
}
free(*(void **)ptr);
}
free(ptr);
}

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

if ( *(_QWORD *)ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
v2 = 0LL;
do
{
v3 = *(void **)(*(_QWORD *)ptr + 16 * v2);
if ( v3 )
free(v3);
++v2;
}
while ( *((_QWORD *)ptr + 2) > v2 );
}
free(*(void **)ptr);
}
free(ptr);
}

original_code:
void
free_ht_line (
 struct ht_line * const l
 )
{
 if (((void *)0) != l->words)
 {
  size_t i;
  for (i = 0; i < l->capc; i++)
  {
   if (((void *)0) != l->words[i].chars)
   {
    free (l->words[i].chars);
   }
  }
  free (l->words);
 }
 free (l);
}

canonical_original_code:
void free_ht_line(struct ht_line *l)
{
 if (((void *)0) != l->words)
 {
  unsigned long i;
  for (i = 0; i < l->capc; i++)
  {
   if (((void *)0) != l->words[i].chars)
   {
    free (l->words[i].chars);
   }
  }
  free (l->words);
 }
 free (l);
}


decompiled_code:
_BOOL8 __fastcall ht_line_empty(__int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_QWORD *)(a1 + 8) == 1LL )
result = ***(_BYTE ***)a1 == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_QWORD *)(a1 + 8) == 1LL )
result = ***(_BYTE ***)a1 == 0;
return result;
}

original_code:
HT_BOOL
ht_line_empty (
 const struct ht_line * const l
 )
{
 return (size_t)1 == l->wordc
 && strlen(l->words[0].chars) < (size_t)1 ? HT_TRUE : HT_FALSE;
}

canonical_original_code:
enum HT_BOOL_ ht_line_empty(struct ht_line *l)
{
 return (unsigned long)1 == l->wordc
 && strlen(l->words[0].chars) < (unsigned long)1 ? HT_TRUE : HT_FALSE;
}


decompiled_code:
_BOOL8 __fastcall player_index_valid(unsigned __int16 a1)
{
return HT_PLAYERS_MAX > a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned __int16 a1)
{
return HT_PLAYERS_MAX > a1;
}

original_code:
HT_BOOL
player_index_valid (
 const unsigned short index
 )
{
 return index < HT_PLAYERS_MAX ? HT_TRUE : HT_FALSE;
}

canonical_original_code:
enum HT_BOOL_ player_index_valid(unsigned short index)
{
 return index < HT_PLAYERS_MAX ? HT_TRUE : HT_FALSE;
}

variable_types:
index
unsigned short