KeyItem

repo: pconrad/giffer

decompiled_code:
__int64 __fastcall KeyItem(unsigned int a1)
{
return ((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 12)) & 0x1FFF;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return ((unsigned __int16)a1 ^ (unsigned __int16)(a1 >> 12)) & 0x1FFF;
}

original_code:
static int KeyItem(uint32_t Item)
{
    return ((Item >> 12) ^ Item) & 0x1FFF;
}

canonical_original_code:
static int KeyItem(unsigned int Item)
{
    return ((Item >> 12) ^ Item) & 0x1FFF;
}

variable_types:
Item
unsigned int


Experimento

decompiled_code:
__int64 __fastcall Experimento(__int64 a1, int a2, double a3)
{
unsigned int v3; // er12
__int64 v4; // rbp
unsigned int i; // ebx
unsigned int v6; // eax
int v7; // ebx
int v8; // ebx
unsigned int j; // er12
int v10; // ebx
unsigned int v11; // er15
double v12; // r13
int v13; // ebx
int v14; // ebx
__int64 result; // rax
double v16; // [rsp+8h] [rbp-D0h]
double v17; // [rsp+10h] [rbp-C8h]
double v18; // [rsp+18h] [rbp-C0h]
struct timespec tp; // [rsp+20h] [rbp-B8h] BYREF
struct timespec v20; // [rsp+30h] [rbp-A8h] BYREF
struct timespec v21; // [rsp+40h] [rbp-98h] BYREF
struct timespec v22; // [rsp+50h] [rbp-88h] BYREF
struct timespec v23; // [rsp+60h] [rbp-78h] BYREF
struct timespec v24; // [rsp+70h] [rbp-68h] BYREF
struct timespec v25; // [rsp+80h] [rbp-58h] BYREF
struct timespec v26; // [rsp+90h] [rbp-48h] BYREF

v3 = 0;
v4 = DIGRAPHinit((unsigned int)a2);
if ( a2 <= 0 )
goto LABEL_10;
while ( 2 )
{
for ( i = 0; i == v3 || a3 * 2147483647.0 <= (double)rand(); i = v6 )
{
v6 = i + 1;
if ( a2 == i + 1 )
goto LABEL_8;
LABEL_4:
;
}
DIGRAPHinsertA(v4, v3, i);
v6 = i + 1;
if ( a2 != i + 1 )
goto LABEL_4;
LABEL_8:
if ( i != v3 )
{
++v3;
continue;
}
break;
}
LABEL_10:
v7 = 8;
clock_gettime(0, &tp);
do
{
DIGRAPHdfsM(v4);
--v7;
}
while ( v7 );
v8 = 8;
clock_gettime(0, &v20);
v16 = (double)(LODWORD(v20.tv_nsec) - LODWORD(tp.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v20.tv_sec) - LODWORD(tp.tv_sec));
clock_gettime(0, &v23);
do
{
DIGRAPHdfsL(v4);
--v8;
}
while ( v8 );
clock_gettime(0, &v24);
v17 = (double)(LODWORD(v24.tv_nsec) - LODWORD(v23.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v24.tv_sec) - LODWORD(v23.tv_sec));
clock_gettime(0, &v21);
if ( a2 <= 0 )
{
clock_gettime(0, &v22);
v12 = (double)(LODWORD(v22.tv_nsec) - LODWORD(v21.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(v21.tv_sec));
clock_gettime(0, &v25);
}
else
{
for ( j = 0; ; ++j )
{
v10 = 8;
do
{
DIGRAPHbfsM(v4, j);
--v10;
}
while ( v10 );
if ( a2 == j + 1 )
break;
}
v11 = 0;
clock_gettime(0, &v22);
v12 = (double)(LODWORD(v22.tv_nsec) - LODWORD(v21.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(v21.tv_sec));
clock_gettime(0, &v25);
while ( 1 )
{
v13 = 8;
do
{
DIGRAPHbfsL(v4, v11);
--v13;
}
while ( v13 );
if ( j == v11 )
break;
++v11;
}
}
clock_gettime(0, &v26);
v14 = *(_DWORD *)(v4 + 4);
v18 = (double)(LODWORD(v26.tv_nsec) - LODWORD(v25.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v26.tv_sec) - LODWORD(v25.tv_sec));
DIGRAPHfree(v4);
*(double *)(a1 + 8) = v12;
result = a1;
*(_DWORD *)(a1 + 32) = v14;
*(double *)a1 = v16;
*(double *)(a1 + 16) = v17;
*(double *)(a1 + 24) = v18;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, double a3)
{
unsigned int v3; // er12
__int64 v4; // rbp
unsigned int i; // ebx
unsigned int v6; // eax
int v7; // ebx
int v8; // ebx
unsigned int j; // er12
int v10; // ebx
unsigned int v11; // er15
double v12; // r13
int v13; // ebx
int v14; // ebx
__int64 result; // rax
double v16; // [rsp+8h] [rbp-D0h]
double v17; // [rsp+10h] [rbp-C8h]
double v18; // [rsp+18h] [rbp-C0h]
struct timespec tp; // [rsp+20h] [rbp-B8h] BYREF
struct timespec v20; // [rsp+30h] [rbp-A8h] BYREF
struct timespec v21; // [rsp+40h] [rbp-98h] BYREF
struct timespec v22; // [rsp+50h] [rbp-88h] BYREF
struct timespec v23; // [rsp+60h] [rbp-78h] BYREF
struct timespec v24; // [rsp+70h] [rbp-68h] BYREF
struct timespec v25; // [rsp+80h] [rbp-58h] BYREF
struct timespec v26; // [rsp+90h] [rbp-48h] BYREF

v3 = 0;
v4 = DIGRAPHinit((unsigned int)a2);
if ( a2 <= 0 )
goto LABEL_10;
while ( 2 )
{
for ( i = 0; i == v3 || a3 * 2147483647.0 <= (double)rand(); i = v6 )
{
v6 = i + 1;
if ( a2 == i + 1 )
goto LABEL_8;
LABEL_4:
;
}
DIGRAPHinsertA(v4, v3, i);
v6 = i + 1;
if ( a2 != i + 1 )
goto LABEL_4;
LABEL_8:
if ( i != v3 )
{
++v3;
continue;
}
break;
}
LABEL_10:
v7 = 8;
clock_gettime(0, &tp);
do
{
DIGRAPHdfsM(v4);
--v7;
}
while ( v7 );
v8 = 8;
clock_gettime(0, &v20);
v16 = (double)(LODWORD(v20.tv_nsec) - LODWORD(tp.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v20.tv_sec) - LODWORD(tp.tv_sec));
clock_gettime(0, &v23);
do
{
DIGRAPHdfsL(v4);
--v8;
}
while ( v8 );
clock_gettime(0, &v24);
v17 = (double)(LODWORD(v24.tv_nsec) - LODWORD(v23.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v24.tv_sec) - LODWORD(v23.tv_sec));
clock_gettime(0, &v21);
if ( a2 <= 0 )
{
clock_gettime(0, &v22);
v12 = (double)(LODWORD(v22.tv_nsec) - LODWORD(v21.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(v21.tv_sec));
clock_gettime(0, &v25);
}
else
{
for ( j = 0; ; ++j )
{
v10 = 8;
do
{
DIGRAPHbfsM(v4, j);
--v10;
}
while ( v10 );
if ( a2 == j + 1 )
break;
}
v11 = 0;
clock_gettime(0, &v22);
v12 = (double)(LODWORD(v22.tv_nsec) - LODWORD(v21.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v22.tv_sec) - LODWORD(v21.tv_sec));
clock_gettime(0, &v25);
while ( 1 )
{
v13 = 8;
do
{
DIGRAPHbfsL(v4, v11);
--v13;
}
while ( v13 );
if ( j == v11 )
break;
++v11;
}
}
clock_gettime(0, &v26);
v14 = *(_DWORD *)(v4 + 4);
v18 = (double)(LODWORD(v26.tv_nsec) - LODWORD(v25.tv_nsec)) / 1000000000.0
+ (double)(LODWORD(v26.tv_sec) - LODWORD(v25.tv_sec));
DIGRAPHfree(v4);
*(double *)(a1 + 8) = v12;
result = a1;
*(_DWORD *)(a1 + 32) = v14;
*(double *)a1 = v16;
*(double *)(a1 + 16) = v17;
*(double *)(a1 + 24) = v18;
return result;
}

original_code:
resultado Experimento(int V, double p) {
 int i, j;
 struct timespec M_dfs_ini, M_dfs_fim, M_bfs_ini, M_bfs_fim;
 struct timespec L_dfs_ini, L_dfs_fim, L_bfs_ini, L_bfs_fim;
 resultado ans;
 Digraph G = DIGRAPHinit(V);
 for(i = 0; i<V; i++)
  for(j = 0; j<V; j++)
   if (i != j && rand() < p*2147483647)
    DIGRAPHinsertA (G, i, j);
 clock_gettime(0, &M_dfs_ini);
 for(i = 0; i<8; i++)
  DIGRAPHdfsM (G);
 clock_gettime(0, &M_dfs_fim);
 ans.m_dfs = (( M_dfs_fim.tv_sec - M_dfs_ini.tv_sec ) + (double)( M_dfs_fim.tv_nsec - M_dfs_ini.tv_nsec )/ (double) 1000000000L);
 clock_gettime(0, &L_dfs_ini);
 for(i = 0; i<8; i++)
  DIGRAPHdfsL (G);
 clock_gettime(0, &L_dfs_fim);
 ans.l_dfs = (( L_dfs_fim.tv_sec - L_dfs_ini.tv_sec ) + (double)( L_dfs_fim.tv_nsec - L_dfs_ini.tv_nsec )/ (double) 1000000000L);
 clock_gettime(0, &M_bfs_ini);
 for(i = 0; i<V; i++)
  for(j = 0; j<8; j++)
   DIGRAPHbfsM(G, i);
 clock_gettime(0, &M_bfs_fim);
 ans.m_bfs = (( M_bfs_fim.tv_sec - M_bfs_ini.tv_sec ) + (double)( M_bfs_fim.tv_nsec - M_bfs_ini.tv_nsec )/ (double) 1000000000L);
 clock_gettime(0, &L_bfs_ini);
 for(i = 0; i<V; i++)
  for(j = 0; j<8; j++)
   DIGRAPHbfsL(G, i);
 clock_gettime(0, &L_bfs_fim);
 ans.l_bfs = (( L_bfs_fim.tv_sec - L_bfs_ini.tv_sec ) + (double)( L_bfs_fim.tv_nsec - L_bfs_ini.tv_nsec )/ (double) 1000000000L);
 ans.arcos = G->A;
 DIGRAPHfree(G);
 return ans;
}

canonical_original_code:
struct resultado Experimento(int V, double p) {
 int i; int j;
 struct timespec M_dfs_ini; struct timespec M_dfs_fim; struct timespec M_bfs_ini; struct timespec M_bfs_fim;
 struct timespec L_dfs_ini; struct timespec L_dfs_fim; struct timespec L_bfs_ini; struct timespec L_bfs_fim;
 struct resultado ans;
 struct digraph *G = DIGRAPHinit(V);
 for(i = 0; i<V; i++)
  for(j = 0; j<V; j++)
   if (i != j && rand() < p*2147483647)
    DIGRAPHinsertA (G, i, j);
 clock_gettime(0, &M_dfs_ini);
 for(i = 0; i<8; i++)
  DIGRAPHdfsM (G);
 clock_gettime(0, &M_dfs_fim);
 ans.m_dfs = (( M_dfs_fim.tv_sec - M_dfs_ini.tv_sec ) + (double)( M_dfs_fim.tv_nsec - M_dfs_ini.tv_nsec )/ (double) 1000000000L);
 clock_gettime(0, &L_dfs_ini);
 for(i = 0; i<8; i++)
  DIGRAPHdfsL (G);
 clock_gettime(0, &L_dfs_fim);
 ans.l_dfs = (( L_dfs_fim.tv_sec - L_dfs_ini.tv_sec ) + (double)( L_dfs_fim.tv_nsec - L_dfs_ini.tv_nsec )/ (double) 1000000000L);
 clock_gettime(0, &M_bfs_ini);
 for(i = 0; i<V; i++)
  for(j = 0; j<8; j++)
   DIGRAPHbfsM(G, i);
 clock_gettime(0, &M_bfs_fim);
 ans.m_bfs = (( M_bfs_fim.tv_sec - M_bfs_ini.tv_sec ) + (double)( M_bfs_fim.tv_nsec - M_bfs_ini.tv_nsec )/ (double) 1000000000L);
 clock_gettime(0, &L_bfs_ini);
 for(i = 0; i<V; i++)
  for(j = 0; j<8; j++)
   DIGRAPHbfsL(G, i);
 clock_gettime(0, &L_bfs_fim);
 ans.l_bfs = (( L_bfs_fim.tv_sec - L_bfs_ini.tv_sec ) + (double)( L_bfs_fim.tv_nsec - L_bfs_ini.tv_nsec )/ (double) 1000000000L);
 ans.arcos = G->A;
 DIGRAPHfree(G);
 return ans;
}

variable_types: V int

variable_types: p double

variable_types: i int

variable_types: j int

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

variable_types: struct resultado { double m_dfs; int arcos; }

variable_types: struct digraph { int V; int A; int **Adj; struct node { int w; struct node *next; } **adj; } *

user_defined_types: struct digraph { int V; int A; int **Adj; struct node **adj; }


decompiled_code:
__int64 __fastcall comparar_representacoes(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
__int64 result; // rax

result = 0LL;
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a12 + a11 - (a10 + a9)) & LC2) >= 0.00001 )
{
result = 0xFFFFFFFFLL;
if ( a10 + a9 <= a12 + a11 )
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
__int64 result; // rax

result = 0LL;
if ( COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a12 + a11 - (a10 + a9)) & LC2) >= 0.00001 )
{
result = 0xFFFFFFFFLL;
if ( a10 + a9 <= a12 + a11 )
result = 1LL;
}
return result;
}

original_code:
int comparar_representacoes (resultado r){
 double l, m;
 l = r.l_bfs + r.l_dfs;
 m = r.m_bfs + r.m_dfs;
 if(fabs(l - m) < 1e-5)
  return 0;
 else if(l < m)
  return -1;
 return 1;
}

canonical_original_code:
int comparar_representacoes(struct resultado r){
 double l; double m;
 l = r.l_bfs + r.l_dfs;
 m = r.m_bfs + r.m_dfs;
 if(fabs(l - m) < 1e-5)
  return 0;
 else if(l < m)
  return -1;
 return 1;
}

variable_types: l double

variable_types: m double

return_type: int

user_defined_types: struct resultado { double m_dfs; int arcos; }


setLogLevel

repo: phillimar/UPNPAudioPlayer

decompiled_code:
void __fastcall setLogLevel(int a1)
{
severity = a1;
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
severity = a1;
}

original_code:
void setLogLevel(enum LogSeverity s)
{
 _severity = s;
}

variable_types: enum LogSeverity { Fatal=0, Warn=1, Default=2, Detail=3 }

return_type: void


setLogLocation

decompiled_code:
void __fastcall setLogLocation(int a1)
{
logLocation = a1;
if ( a1 == 1 && !logInit )
{
openlog("upnpaudioplayer", 0, 24);
logInit = 1;
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
logLocation = a1;
if ( a1 == 1 && !logInit )
{
openlog("upnpaudioplayer", 0, 24);
logInit = 1;
}
}

original_code:
void setLogLocation(enum LogLocation l)
{
 _logLocation = l;
 if (l == LocationSyslog && !_logInit)
 {
  openlog("upnpaudioplayer", 0, (3<<3));
  _logInit=1;
 }
}

variable_types: enum LogLocation { LocationDefault=0, LocationSyslog=1 }


logClose

decompiled_code:
void logClose()
{
if ( logInit )
closelog();
}

canonical_decompiled_code:
void func2()
{
if ( logInit )
closelog();
}

original_code:
void logClose()
{
 if ( _logInit )
 {
  closelog();
 }
}


mapPriority

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

if ( a1 <= 3 )
result = (unsigned int)CSWTCH_8[a1];
return result;
}

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

if ( a1 <= 3 )
result = (unsigned int)CSWTCH_8[a1];
return result;
}

original_code:
int mapPriority(enum LogSeverity s)
{
 switch (s)
 {
  case Fatal:
   return 2;
   break;
  case Warn:
   return 4;
   break;
  case Default:
   return 5;
   break;
  case Detail:
   return 7;
   break;
 }
}

user_defined_types: enum LogSeverity { Fatal=0, Warn=1, Default=2, Detail=3 }


main

canonical_name: main

repo: regulusos/exercise

original_code:
int main()
{
 int i;
 D_LINK_LIST *new;
 D_LINK_LIST *tmp;
 new=dlist_init();
 for(i=1;i<=5;i++)
 {
  dlist_insert(new,i,i);
 }
    printf("new is %p\n",new);
    printf("new->next is %p\n",new->next);
    printf("new->next->next is %p\n",new->next->next);
 dlist_print(new);
 dlist_delete(new,5);
 dlist_delete(new,1);
    printf("new is %p\n",new);
    printf("new->next is %p\n",new->next);
    printf("new->next->next is %p\n",new->next->next);
 printf("######################################\n");
 dlist_print(new);
 dlist_drop(new);
}

canonical_original_code:
int main()
{
 int i;
 struct _D_LINK_LIST *new;
 struct _D_LINK_LIST *tmp;
 new=dlist_init();
 for(i=1;i<=5;i++)
 {
  dlist_insert(new,i,i);
 }
    printf("new is %p\n",new);
    printf("new->next is %p\n",new->next);
    printf("new->next->next is %p\n",new->next->next);
 dlist_print(new);
 dlist_delete(new,5);
 dlist_delete(new,1);
    printf("new is %p\n",new);
    printf("new->next is %p\n",new->next);
    printf("new->next->next is %p\n",new->next->next);
 printf("######################################\n");
 dlist_print(new);
 dlist_drop(new);
}

variable_types: struct _D_LINK_LIST { struct _D_LINK_LIST *prev; struct _D_LINK_LIST *next; int data; } *


decompiled_code:
void __fastcall do_cd(__int64 a1)
{
const char *v1; // rdi
int v2; // eax

v1 = *(const char **)(a1 + 8);
if ( v1 && chdir(v1) < 0 )
{
v2 = *__errno_location();
switch ( v2 )
{
case 13:
puts("YOU DO NOT HAVE RIGHT TO ACCESS");
break;
case 20:
puts("NOT A DIRECTORY NAME");
break;
case 2:
puts("DIRECTORY NOT FOUND");
break;
default:
puts("SOME ERROR HAPPENED IN CHDIR");
break;
}
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
const char *v1; // rdi
int v2; // eax

v1 = *(const char **)(a1 + 8);
if ( v1 && chdir(v1) < 0 )
{
v2 = *__errno_location();
switch ( v2 )
{
case 13:
puts("YOU DO NOT HAVE RIGHT TO ACCESS");
break;
case 20:
puts("NOT A DIRECTORY NAME");
break;
case 2:
puts("DIRECTORY NOT FOUND");
break;
default:
puts("SOME ERROR HAPPENED IN CHDIR");
break;
}
}
}

original_code:
void do_cd(char *argv[])
{
 if(argv[1] != ((void *)0))
 {
  if(chdir(argv[1]) < 0)
   switch((*__errno_location ()))
   {
   case 2:
    printf("DIRECTORY NOT FOUND\n");
    break;
   case 20:
    printf("NOT A DIRECTORY NAME\n");
    break;
   case 13:
    printf("YOU DO NOT HAVE RIGHT TO ACCESS\n");
    break;
   default:
    printf("SOME ERROR HAPPENED IN CHDIR\n");
   }
 }
}

variable_types:
argv
char *[]


decompiled_code:
__pid_t __fastcall execute_new(char **argv)
{
__pid_t v1; // eax
int v3; // eax

v1 = fork();
if ( v1 < 0 )
{
puts("SOME ERROR HAPPENED IN FORK");
exit(2);
}
if ( !v1 )
{
if ( execvp(*argv, argv) < 0 )
{
v3 = *__errno_location();
if ( v3 == 2 )
{
puts("COMMAND OR FILENAME NOT FOUND");
}
else if ( v3 == 13 )
{
puts("YOU DO NOT HAVE RIGHT TO ACCESS");
}
else
{
puts("SOME ERROR HAPPENED IN EXEC");
}
}
exit(3);
}
return wait(0LL);
}

canonical_decompiled_code:
__pid_t __fastcall func8(char **argv)
{
__pid_t v1; // eax
int v3; // eax

v1 = fork();
if ( v1 < 0 )
{
puts("SOME ERROR HAPPENED IN FORK");
exit(2);
}
if ( !v1 )
{
if ( execvp(*argv, argv) < 0 )
{
v3 = *__errno_location();
if ( v3 == 2 )
{
puts("COMMAND OR FILENAME NOT FOUND");
}
else if ( v3 == 13 )
{
puts("YOU DO NOT HAVE RIGHT TO ACCESS");
}
else
{
puts("SOME ERROR HAPPENED IN EXEC");
}
}
exit(3);
}
return wait(0LL);
}

original_code:
void execute_new(char *argv[])
{
 pid_t pid;
 pid = fork();
 if(pid < 0)
 {
  printf("SOME ERROR HAPPENED IN FORK\n");
  exit(2);
 }
 else if(pid == 0)
 {
  if(execvp(argv[0],argv)<0)
  switch((*__errno_location ()))
  {
   case 2:
    printf("COMMAND OR FILENAME NOT FOUND\n");
    break;
   case 13:
    printf("YOU DO NOT HAVE RIGHT TO ACCESS\n");
    break;
   default:
    printf("SOME ERROR HAPPENED IN EXEC\n");
  }
   exit(3);
 }
 else
  wait(((void *)0));
}

canonical_original_code:
void execute_new(char *argv[])
{
 int pid;
 pid = fork();
 if(pid < 0)
 {
  printf("SOME ERROR HAPPENED IN FORK\n");
  exit(2);
 }
 else if(pid == 0)
 {
  if(execvp(argv[0],argv)<0)
  switch((*__errno_location ()))
  {
   case 2:
    printf("COMMAND OR FILENAME NOT FOUND\n");
    break;
   case 13:
    printf("YOU DO NOT HAVE RIGHT TO ACCESS\n");
    break;
   default:
    printf("SOME ERROR HAPPENED IN EXEC\n");
  }
   exit(3);
 }
 else
  wait(((void *)0));
}

variable_types: pid int


repo: robertdavidgraham/robdns

decompiled_code:
void __fastcall free2(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void
free2(char *str)
{
    if (str)
        free(str);
}

variable_types:
str
char *


setCommandArgs

decompiled_code:
char *__fastcall setCommandArgs(int a1, __int64 a2)
{
char *result; // rax

numOfArgs = a1;
commandLineArgs = a2;
result = (char *)malloc(4uLL);
intbuffer = result;
return result;
}

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

numOfArgs = a1;
commandLineArgs = a2;
result = (char *)malloc(4uLL);
intbuffer = result;
return result;
}

original_code:
void setCommandArgs(int argc, char ** argv) {
    commandLineArgs = argv;
    numOfArgs = argc;
    intbuffer = (char*) malloc(sizeof (int));
}

canonical_original_code:
void setCommandArgs(int argc, char **argv) {
    commandLineArgs = argv;
    numOfArgs = argc;
    intbuffer = (char *) malloc(sizeof (int));
}

variable_types: argc int

variable_types:
argv
char **


freeMemory

decompiled_code:
void freeMemory()
{
_QWORD *v0; // r8
__int64 v1; // rbx
void *v2; // rdi
_QWORD *v3; // r8
__int64 v4; // rbx
void *v5; // rdi
_QWORD *v6; // r8
__int64 v7; // rbx
void *v8; // rdi

v0 = questions;
if ( questions )
{
if ( numOfQuestions > 0 )
{
v1 = 0LL;
do
{
v2 = (void *)v0[v1];
if ( v2 )
{
free(v2);
v0 = questions;
}
++v1;
}
while ( numOfQuestions > (int)v1 );
}
free(v0);
}
v3 = answers;
if ( answers )
{
if ( numOfAnswers > 0 )
{
v4 = 0LL;
do
{
v5 = (void *)v3[v4];
if ( v5 )
{
free(v5);
v3 = answers;
}
++v4;
}
while ( numOfAnswers > (int)v4 );
}
free(v3);
}
v6 = quizFiles;
if ( quizFiles )
{
if ( numOfQuizzes > 0 )
{
v7 = 0LL;
do
{
v8 = (void *)v6[v7];
if ( v8 )
{
free(v8);
v6 = quizFiles;
}
++v7;
}
while ( numOfQuizzes > (int)v7 );
}
free(v6);
}
free(correctAnswers);
free(intbuffer);
}

canonical_decompiled_code:
void func1()
{
_QWORD *v0; // r8
__int64 v1; // rbx
void *v2; // rdi
_QWORD *v3; // r8
__int64 v4; // rbx
void *v5; // rdi
_QWORD *v6; // r8
__int64 v7; // rbx
void *v8; // rdi

v0 = questions;
if ( questions )
{
if ( numOfQuestions > 0 )
{
v1 = 0LL;
do
{
v2 = (void *)v0[v1];
if ( v2 )
{
free(v2);
v0 = questions;
}
++v1;
}
while ( numOfQuestions > (int)v1 );
}
free(v0);
}
v3 = answers;
if ( answers )
{
if ( numOfAnswers > 0 )
{
v4 = 0LL;
do
{
v5 = (void *)v3[v4];
if ( v5 )
{
free(v5);
v3 = answers;
}
++v4;
}
while ( numOfAnswers > (int)v4 );
}
free(v3);
}
v6 = quizFiles;
if ( quizFiles )
{
if ( numOfQuizzes > 0 )
{
v7 = 0LL;
do
{
v8 = (void *)v6[v7];
if ( v8 )
{
free(v8);
v6 = quizFiles;
}
++v7;
}
while ( numOfQuizzes > (int)v7 );
}
free(v6);
}
free(correctAnswers);
free(intbuffer);
}

original_code:
void freeMemory() {
    int i = 0;
    if (questions != ((void *)0)) {
        for (i = 0; i < numOfQuestions; i++) {
            if (questions[i] != ((void *)0)) free(questions[i]);
        }
        free(questions);
    }
    if (answers != ((void *)0)) {
        for (i = 0; i < numOfAnswers; i++) {
            if (answers[i] != ((void *)0)) free(answers[i]);
        }
        free(answers);
    }
    if (quizFiles != ((void *)0)) {
        for (i = 0; i < numOfQuizzes; i++) {
            if (quizFiles[i] != ((void *)0)) free(quizFiles[i]);
        }
        free(quizFiles);
    }
    free(correctAnswers);
    free(intbuffer);
}


addUpPoints

decompiled_code:
__int64 addUpPoints()
{
__int64 v0; // rdx
int v1; // eax
int v3; // eax

if ( *((_DWORD *)correctAnswers + selQSNum - 1) == selectedAnswer )
{
puts("Well done you were correct!");
v3 = correct;
correctQuestions[correct] = selQSNum;
correct = v3 + 1;
}
else
{
puts("Incorrect this time, sorry!");
v0 = incorrect;
v1 = incorrect;
incorrectQuestions[incorrect] = selQSNum;
incorrect = v1 + 1;
incorrectAnswers[v0] = selectedAnswer;
}
return answerNew();
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdx
int v1; // eax
int v3; // eax

if ( *((_DWORD *)correctAnswers + selQSNum - 1) == selectedAnswer )
{
puts("Well done you were correct!");
v3 = correct;
correctQuestions[correct] = selQSNum;
correct = v3 + 1;
}
else
{
puts("Incorrect this time, sorry!");
v0 = incorrect;
v1 = incorrect;
incorrectQuestions[incorrect] = selQSNum;
incorrect = v1 + 1;
incorrectAnswers[v0] = selectedAnswer;
}
return func6();
}

original_code:
void addUpPoints() {
    if (selectedAnswer == correctAnswers[selQSNum - 1]) {
        printf("Well done you were correct!\n");
        correctQuestions[correct] = selQSNum;
        correct++;
    } else {
        printf("Incorrect this time, sorry!\n");
        incorrectQuestions[incorrect] = selQSNum;
        incorrectAnswers[incorrect] = selectedAnswer;
        incorrect++;
    }
    answerNew();
}


enterAnswer

decompiled_code:
int enterAnswer()
{
const unsigned __int16 *v0; // rax

while ( 1 )
{
*intbuffer = 0;
if ( numOfArgs <= 3 )
{
if ( numOfArgs == 1 )
goto LABEL_11;
}
else
{
strcpy(intbuffer, *(const char **)(commandLineArgs + 24));
LODWORD(v0) = (_DWORD)intbuffer;
if ( !*intbuffer )
return (int)v0;
if ( numOfArgs == 1 )
{
LABEL_11:
printf("Enter your choice:");
_isoc99_scanf("%s", intbuffer);
goto LABEL_3;
}
}
LABEL_3:
v0 = *_ctype_b_loc();
if ( (v0[*intbuffer] & 0x800) != 0 )
{
LODWORD(v0) = atoi(intbuffer);
selectedAnswer = (int)v0;
if ( (int)v0 <= numOfAnswers && (int)v0 > 0 )
break;
}
if ( numOfArgs > 3 )
return (int)v0;
puts("\nInvalid Answer Number!");
}
LODWORD(v0) = addUpPoints();
return (int)v0;
}

canonical_decompiled_code:
int func4()
{
const unsigned __int16 *v0; // rax

while ( 1 )
{
*intbuffer = 0;
if ( numOfArgs <= 3 )
{
if ( numOfArgs == 1 )
goto LABEL_11;
}
else
{
strcpy(intbuffer, *(const char **)(commandLineArgs + 24));
LODWORD(v0) = (_DWORD)intbuffer;
if ( !*intbuffer )
return (int)v0;
if ( numOfArgs == 1 )
{
LABEL_11:
printf("Enter your choice:");
_isoc99_scanf("%s", intbuffer);
goto LABEL_3;
}
}
LABEL_3:
v0 = *_ctype_b_loc();
if ( (v0[*intbuffer] & 0x800) != 0 )
{
LODWORD(v0) = atoi(intbuffer);
selectedAnswer = (int)v0;
if ( (int)v0 <= numOfAnswers && (int)v0 > 0 )
break;
}
if ( numOfArgs > 3 )
return (int)v0;
puts("\nInvalid Answer Number!");
}
LODWORD(v0) = func3();
return (int)v0;
}

original_code:
void enterAnswer() {
    strcpy(intbuffer, "");
    if (numOfArgs > 3) {
        strcpy(intbuffer, commandLineArgs[3]);
        if (strcmp(intbuffer, "") == 0) {
            return;
        }
    }
    if (numOfArgs == 1) {
        printf("Enter your choice:");
        scanf("%s", intbuffer);
    }
    if (!((*__ctype_b_loc ())[(int) ((intbuffer[0]))] & (unsigned short int) _ISdigit)) {
        if (numOfArgs < 4) {
            printf("\nInvalid Answer Number!\n");
            enterAnswer();
        }
        return;
    }
    selectedAnswer = atoi(intbuffer);
    if (selectedAnswer > numOfAnswers || selectedAnswer < 1) {
        if (numOfArgs < 4) {
            printf("\nInvalid Answer Number!\n");
            enterAnswer();
        }
        return;
    }
    addUpPoints();
}

canonical_original_code:
void enterAnswer() {
    strcpy(intbuffer, "");
    if (numOfArgs > 3) {
        strcpy(intbuffer, commandLineArgs[3]);
        if (strcmp(intbuffer, "") == 0) {
            return;
        }
    }
    if (numOfArgs == 1) {
        printf("Enter your choice:");
        scanf("%s", intbuffer);
    }
    if (!((*__ctype_b_loc ())[(int) ((intbuffer[0]))] & (unsigned short) _ISdigit)) {
        if (numOfArgs < 4) {
            printf("\nInvalid Answer Number!\n");
            enterAnswer();
        }
        return;
    }
    selectedAnswer = atoi(intbuffer);
    if (selectedAnswer > numOfAnswers || selectedAnswer < 1) {
        if (numOfArgs < 4) {
            printf("\nInvalid Answer Number!\n");
            enterAnswer();
        }
        return;
    }
    addUpPoints();
}


selectQuestion

decompiled_code:
int selectQuestion()
{
char *v0; // rbp
unsigned __int64 v1; // rax
const unsigned __int16 *v2; // rax
int v3; // edx
int v4; // esi

while ( 1 )
{
*intbuffer = 0;
if ( numOfArgs <= 2 )
{
if ( numOfArgs != 1 )
goto LABEL_3;
LABEL_15:
printf("Enter question number to display (1 - %i) or R for a random question:", (unsigned int)numOfQuestions);
_isoc99_scanf("%s", intbuffer);
goto LABEL_3;
}
strcpy(intbuffer, *(const char **)(commandLineArgs + 16));
LODWORD(v2) = (_DWORD)intbuffer;
if ( !*intbuffer )
return (int)v2;
if ( numOfArgs == 1 )
goto LABEL_15;
LABEL_3:
v0 = intbuffer;
v1 = strlen(intbuffer);
if ( v1 > 2 )
v1 = 2LL;
if ( !memcmp(v0, "R", v1) )
break;
v2 = *_ctype_b_loc();
if ( (v2[*v0] & 0x800) != 0 )
{
LODWORD(v2) = atoi(v0);
selQSNum = (int)v2;
if ( (int)v2 <= numOfQuestions && (int)v2 > 0 )
goto LABEL_18;
if ( numOfArgs > 2 )
return (int)v2;
printf(
"There are only %i questions! Enter a number between 1 and %i.\n",
(unsigned int)numOfQuestions,
(unsigned int)numOfQuestions);
}
else
{
if ( numOfArgs > 2 )
return (int)v2;
printf("Input is not a number or R!");
}
}
LODWORD(v2) = rand() % numOfQuestions + 1;
selQSNum = (int)v2;
LABEL_18:
printf("Your Question is: %i)%s\n", (unsigned int)v2, *((const char **)questions + (int)v2 - 1));
puts("Choose the Correct Answer:");
v3 = numOfAnswers;
v4 = 0;
for ( i = 0; v4 < numOfAnswers; i = v4 )
{
printf("%i) %s\n", (unsigned int)(v4 + 1), *((const char **)answers + v4 + v3 * (selQSNum - 1)));
v3 = numOfAnswers;
v4 = i + 1;
}
LODWORD(v2) = enterAnswer();
return (int)v2;
}

canonical_decompiled_code:
int func5()
{
char *v0; // rbp
unsigned __int64 v1; // rax
const unsigned __int16 *v2; // rax
int v3; // edx
int v4; // esi

while ( 1 )
{
*intbuffer = 0;
if ( numOfArgs <= 2 )
{
if ( numOfArgs != 1 )
goto LABEL_3;
LABEL_15:
printf("Enter question number to display (1 - %i) or R for a random question:", (unsigned int)numOfQuestions);
_isoc99_scanf("%s", intbuffer);
goto LABEL_3;
}
strcpy(intbuffer, *(const char **)(commandLineArgs + 16));
LODWORD(v2) = (_DWORD)intbuffer;
if ( !*intbuffer )
return (int)v2;
if ( numOfArgs == 1 )
goto LABEL_15;
LABEL_3:
v0 = intbuffer;
v1 = strlen(intbuffer);
if ( v1 > 2 )
v1 = 2LL;
if ( !memcmp(v0, "R", v1) )
break;
v2 = *_ctype_b_loc();
if ( (v2[*v0] & 0x800) != 0 )
{
LODWORD(v2) = atoi(v0);
selQSNum = (int)v2;
if ( (int)v2 <= numOfQuestions && (int)v2 > 0 )
goto LABEL_18;
if ( numOfArgs > 2 )
return (int)v2;
printf(
"There are only %i questions! Enter a number between 1 and %i.\n",
(unsigned int)numOfQuestions,
(unsigned int)numOfQuestions);
}
else
{
if ( numOfArgs > 2 )
return (int)v2;
printf("Input is not a number or R!");
}
}
LODWORD(v2) = rand() % numOfQuestions + 1;
selQSNum = (int)v2;
LABEL_18:
printf("Your Question is: %i)%s\n", (unsigned int)v2, *((const char **)questions + (int)v2 - 1));
puts("Choose the Correct Answer:");
v3 = numOfAnswers;
v4 = 0;
for ( i = 0; v4 < numOfAnswers; i = v4 )
{
printf("%i) %s\n", (unsigned int)(v4 + 1), *((const char **)answers + v4 + v3 * (selQSNum - 1)));
v3 = numOfAnswers;
v4 = i + 1;
}
LODWORD(v2) = func4();
return (int)v2;
}

original_code:
void selectQuestion() {
    strcpy(intbuffer, "");
    if (numOfArgs > 2) {
        strcpy(intbuffer, commandLineArgs[2]);
        if (strcmp(intbuffer, "") == 0) {
            return;
        }
    }
    if (numOfArgs == 1) {
        printf("Enter question number to display (1 - %i) or R for a random question:", numOfQuestions);
        scanf("%s", intbuffer);
    }
    if (strncmp(intbuffer, "R", strlen(intbuffer)) == 0) {
        selQSNum = rand() % numOfQuestions + 1;
    } else {
        if (!((*__ctype_b_loc ())[(int) ((intbuffer[0]))] & (unsigned short int) _ISdigit)) {
            if (numOfArgs < 3) {
                printf("Input is not a number or R!");
                selectQuestion();
            }
            return;
        } else {
            selQSNum = atoi(intbuffer);
            if (selQSNum > numOfQuestions || selQSNum < 1) {
                if (numOfArgs < 3) {
                    printf("There are only %i questions! Enter a number between 1 and %i.\n", numOfQuestions, numOfQuestions);
                    selectQuestion();
                }
                return;
            }
        }
    }
    printf("Your Question is: %i)%s\n", selQSNum, questions[selQSNum - 1]);
    printf("Choose the Correct Answer:\n");
    for (i = 0; i < numOfAnswers; i++) {
        printf("%i) %s\n", (i + 1), answers[((selQSNum - 1) * numOfAnswers) + i]);
    }
    enterAnswer();
}

canonical_original_code:
void selectQuestion() {
    strcpy(intbuffer, "");
    if (numOfArgs > 2) {
        strcpy(intbuffer, commandLineArgs[2]);
        if (strcmp(intbuffer, "") == 0) {
            return;
        }
    }
    if (numOfArgs == 1) {
        printf("Enter question number to display (1 - %i) or R for a random question:", numOfQuestions);
        scanf("%s", intbuffer);
    }
    if (strncmp(intbuffer, "R", strlen(intbuffer)) == 0) {
        selQSNum = rand() % numOfQuestions + 1;
    } else {
        if (!((*__ctype_b_loc ())[(int) ((intbuffer[0]))] & (unsigned short) _ISdigit)) {
            if (numOfArgs < 3) {
                printf("Input is not a number or R!");
                selectQuestion();
            }
            return;
        } else {
            selQSNum = atoi(intbuffer);
            if (selQSNum > numOfQuestions || selQSNum < 1) {
                if (numOfArgs < 3) {
                    printf("There are only %i questions! Enter a number between 1 and %i.\n", numOfQuestions, numOfQuestions);
                    selectQuestion();
                }
                return;
            }
        }
    }
    printf("Your Question is: %i)%s\n", selQSNum, questions[selQSNum - 1]);
    printf("Choose the Correct Answer:\n");
    for (i = 0; i < numOfAnswers; i++) {
        printf("%i) %s\n", (i + 1), answers[((selQSNum - 1) * numOfAnswers) + i]);
    }
    enterAnswer();
}


answerNew

decompiled_code:
unsigned int answerNew()
{
unsigned int result; // eax
char dest[9]; // [rsp+Fh] [rbp-9h] BYREF

dest[0] = 0;
if ( numOfArgs <= 4 )
{
if ( numOfArgs == 1 )
{
printf("Do you want to answer another question? Y or N: ");
_isoc99_scanf("%s", dest);
}
return selectQuestion();
}
result = (unsigned int)strcpy(dest, *(const char **)(commandLineArgs + 32));
if ( dest[0] )
return selectQuestion();
return result;
}

canonical_decompiled_code:
unsigned int func6()
{
unsigned int result; // eax
char dest[9]; // [rsp+Fh] [rbp-9h] BYREF

dest[0] = 0;
if ( numOfArgs <= 4 )
{
if ( numOfArgs == 1 )
{
printf("Do you want to answer another question? Y or N: ");
_isoc99_scanf("%s", dest);
}
return func5();
}
result = (unsigned int)strcpy(dest, *(const char **)(commandLineArgs + 32));
if ( dest[0] )
return func5();
return result;
}

original_code:
void answerNew() {
    char response[1];
    strcpy(response, "");
    if (numOfArgs > 4) {
        strcpy(response, commandLineArgs[4]);
        if (strcmp(response, "") == 0) {
            return;
        }
    }
    if (numOfArgs == 1) {
        printf("Do you want to answer another question? Y or N: ");
        scanf("%s", response);
    }
    if (strncmp(response, "Y", strlen(response)) == 0) {
        selectQuestion();
        return;
    } else {
        printReport();
    }
}

variable_types:
response
char [1]


substring

decompiled_code:
int __fastcall substring(int a1, int a2, char *a3)
{
return sprintf(a3, "%.*s", a2 - a1, &a3[a1]);
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2, char *a3)
{
return sprintf(a3, "%.*s", a2 - a1, &a3[a1]);
}

original_code:
void substring(int start, int stop, char *text) {
    sprintf(text, "%.*s", stop - start, &text[start]);
}

variable_types: start int

variable_types: stop int

variable_types:
text
char *


selectQuizFile

decompiled_code:
int selectQuizFile()
{
int result; // eax
int v1; // eax

result = numOfArgs;
while ( 1 )
{
while ( 1 )
{
i = 0;
quizname = 0;
if ( result > 1 )
break;
if ( result != 1 )
goto LABEL_10;
printQuizFiles();
result = numOfQuizzes;
if ( !numOfQuizzes )
return result;
printf("Enter number of quiz to start: ");
_isoc99_scanf("%s", intbuffer);
if ( ((*_ctype_b_loc())[*intbuffer] & 0x800) != 0 )
{
v1 = atoi(intbuffer);
if ( v1 > 0 && v1 <= numOfQuizzes )
{
strcpy(&quizname, *((const char **)quizFiles + v1));
goto LABEL_10;
}
printf("\nQuiz Number Out of Range (max is %i)!\n", (unsigned int)numOfQuizzes);
result = numOfArgs;
}
else
{
puts("\nInvalid Quiz Number!");
result = numOfArgs;
}
}
result = (unsigned int)strcpy(&quizname, *(const char **)(commandLineArgs + 8));
if ( !quizname )
return result;
LABEL_10:
printf("You selected file %s!\n", &quizname);
numOfQuestions = readInQuizFile(&quizname);
if ( numOfQuestions )
return selectQuestion();
result = numOfArgs;
if ( numOfArgs > 1 )
return result;
}
}

canonical_decompiled_code:
int func10()
{
int result; // eax
int v1; // eax

result = numOfArgs;
while ( 1 )
{
while ( 1 )
{
i = 0;
quizname = 0;
if ( result > 1 )
break;
if ( result != 1 )
goto LABEL_10;
func8();
result = numOfQuizzes;
if ( !numOfQuizzes )
return result;
printf("Enter number of quiz to start: ");
_isoc99_scanf("%s", intbuffer);
if ( ((*_ctype_b_loc())[*intbuffer] & 0x800) != 0 )
{
v1 = atoi(intbuffer);
if ( v1 > 0 && v1 <= numOfQuizzes )
{
strcpy(&quizname, *((const char **)quizFiles + v1));
goto LABEL_10;
}
printf("\nQuiz Number Out of Range (max is %i)!\n", (unsigned int)numOfQuizzes);
result = numOfArgs;
}
else
{
puts("\nInvalid Quiz Number!");
result = numOfArgs;
}
}
result = (unsigned int)strcpy(&quizname, *(const char **)(commandLineArgs + 8));
if ( !quizname )
return result;
LABEL_10:
printf("You selected file %s!\n", &quizname);
numOfQuestions = func9(&quizname);
if ( numOfQuestions )
return func5();
result = numOfArgs;
if ( numOfArgs > 1 )
return result;
}
}

original_code:
void selectQuizFile() {
    i = 0;
    strcpy(quizname, "");
    if (numOfArgs > 1) {
        strcpy(quizname, commandLineArgs[1]);
        if (strcmp(quizname, "") == 0) {
            return;
        }
    }
    if (numOfArgs == 1) {
        printQuizFiles();
        if (numOfQuizzes == 0) return;
        printf("Enter number of quiz to start: ");
        scanf("%s", intbuffer);
        if (!((*__ctype_b_loc ())[(int) ((intbuffer[0]))] & (unsigned short int) _ISdigit)) {
            printf("\nInvalid Quiz Number!\n");
            selectQuizFile();
            return;
        }
        int selectedQuizFile = atoi(intbuffer);
        if (selectedQuizFile < 1 || selectedQuizFile > numOfQuizzes) {
            printf("\nQuiz Number Out of Range (max is %i)!\n", numOfQuizzes);
            selectQuizFile();
            return;
        } else {
            strcpy(quizname, quizFiles[atoi(intbuffer)]);
        }
    }
    printf("You selected file %s!\n", quizname);
    numOfQuestions = readInQuizFile(quizname);
    if (numOfQuestions == 0) {
        if (numOfArgs < 2) {
            selectQuizFile();
        }
        return;
    }
    selectQuestion();
}

canonical_original_code:
void selectQuizFile() {
    i = 0;
    strcpy(quizname, "");
    if (numOfArgs > 1) {
        strcpy(quizname, commandLineArgs[1]);
        if (strcmp(quizname, "") == 0) {
            return;
        }
    }
    if (numOfArgs == 1) {
        printQuizFiles();
        if (numOfQuizzes == 0) return;
        printf("Enter number of quiz to start: ");
        scanf("%s", intbuffer);
        if (!((*__ctype_b_loc ())[(int) ((intbuffer[0]))] & (unsigned short) _ISdigit)) {
            printf("\nInvalid Quiz Number!\n");
            selectQuizFile();
            return;
        }
        int selectedQuizFile = atoi(intbuffer);
        if (selectedQuizFile < 1 || selectedQuizFile > numOfQuizzes) {
            printf("\nQuiz Number Out of Range (max is %i)!\n", numOfQuizzes);
            selectQuizFile();
            return;
        } else {
            strcpy(quizname, quizFiles[atoi(intbuffer)]);
        }
    }
    printf("You selected file %s!\n", quizname);
    numOfQuestions = readInQuizFile(quizname);
    if (numOfQuestions == 0) {
        if (numOfArgs < 2) {
            selectQuizFile();
        }
        return;
    }
    selectQuestion();
}

variable_types: selectedQuizFile int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // eax
int arg; // [rsp+8h] [rbp-20h] BYREF
int v7; // [rsp+Ch] [rbp-1Ch] BYREF
pthread_t newthread; // [rsp+10h] [rbp-18h] BYREF
pthread_t th[2]; // [rsp+18h] [rbp-10h] BYREF

arg = 1;
v7 = 2;
v3 = pthread_create(&newthread, 0LL, controller, &arg);
if ( v3 )
printf("Thread creation failed: %d\n", v3);
v4 = pthread_create(th, 0LL, devDriver, &v7);
if ( v4 )
printf("Thread creation failed: %d\n", v4);
pthread_join(newthread, 0LL);
pthread_join(th[0], 0LL);
puts("\nthe end");
return 0;
}

original_code:
int main()
{
    int rc1, rc2;
    int x = 1, y = 2;
    pthread_t thread1, thread2;
    if( (rc1=pthread_create( &thread1, ((void *)0), controller, &x)) )
    {
        printf("Thread creation failed: %d\n", rc1);
    }
    if( (rc2=pthread_create( &thread2, ((void *)0), devDriver, &y)) )
    {
        printf("Thread creation failed: %d\n", rc2);
    }
    pthread_join( thread1, ((void *)0));
    pthread_join( thread2, ((void *)0));
    printf("\nthe end\n");
    return 0;
}

canonical_original_code:
int main()
{
    int rc1; int rc2;
    int x = 1; int y = 2;
    unsigned long thread1; unsigned long thread2;
    if( (rc1=pthread_create( &thread1, ((void *)0), controller, &x)) )
    {
        printf("Thread creation failed: %d\n", rc1);
    }
    if( (rc2=pthread_create( &thread2, ((void *)0), devDriver, &y)) )
    {
        printf("Thread creation failed: %d\n", rc2);
    }
    pthread_join( thread1, ((void *)0));
    pthread_join( thread2, ((void *)0));
    printf("\nthe end\n");
    return 0;
}

variable_types: x int

variable_types: y int


bufferReader

decompiled_code:
__int64 bufferReader()
{
__int64 v0; // rax
unsigned int v1; // er12

pthread_mutex_lock(&mutex);
v0 = current;
if ( current == 7 )
{
pthread_cond_wait(&writing_done, &mutex);
v0 = current;
}
v1 = (unsigned __int8)*(&buffer + v0);
current = v0 + 1;
if ( (_DWORD)v0 == 6 )
pthread_cond_signal(&reading_done);
pthread_mutex_unlock(&mutex);
return v1;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax
unsigned int v1; // er12

pthread_mutex_lock(&mutex);
v0 = current;
if ( current == 7 )
{
pthread_cond_wait(&writing_done, &mutex);
v0 = current;
}
v1 = (unsigned __int8)*(&buffer + v0);
current = v0 + 1;
if ( (_DWORD)v0 == 6 )
pthread_cond_signal(&reading_done);
pthread_mutex_unlock(&mutex);
return v1;
}

original_code:
char bufferReader()
{
    char ch;
    pthread_mutex_lock( &mutex );
    if (current == 7)
  pthread_cond_wait( &writing_done, &mutex );
    ch = buffer[current++];
    if (current == 7)
  pthread_cond_signal(&reading_done);
    pthread_mutex_unlock( &mutex );
    return ch;
}

variable_types: ch char

return_type: char


execComm

decompiled_code:
int execComm()
{
char *v0; // rbx
int result; // eax
char v2; // [rsp+Bh] [rbp-1Dh] BYREF
char v3; // [rsp+10h] [rbp-18h] BYREF

v0 = &v2;
do
*v0++ = bufferReader();
while ( v0 != &v3 );
result = bufferReader();
if ( (_BYTE)result == 93 )
result = puts("\nError: unrecognized command");
return result;
}

canonical_decompiled_code:
int func8()
{
char *v0; // rbx
int result; // eax
char v2; // [rsp+Bh] [rbp-1Dh] BYREF
char v3; // [rsp+10h] [rbp-18h] BYREF

v0 = &v2;
do
*v0++ = func7();
while ( v0 != &v3 );
result = func7();
if ( (_BYTE)result == 93 )
result = puts("\nError: unrecognized command");
return result;
}

original_code:
void execComm (){
    char comm[5];
    int i;
    char ch;
    for (i = 0; i < 5; i++) {
        ch = bufferReader();
        comm[i] = ch;
    }
    if (bufferReader() == ']'){
        if (!strcmp(comm, "NEWLN")){
            printf("\n");
            linepos=0;
        }
        else if (!strcmp(comm, "DELAY")){
            sleep(1);
        }
        else if (!strcmp(comm, "DBNLN")){
            printf("\n\n");
            linepos = 0;
        }
        else if (!strcmp(comm, "INDNT")){
            printf("\n     ");
            linepos = 5;
        }
        else{
            printf("\nError: unrecognized command\n");
        }
    }
}

canonical_original_code:
void execComm(){
    char comm[5];
    int i;
    char ch;
    for (i = 0; i < 5; i++) {
        ch = bufferReader();
        comm[i] = ch;
    }
    if (bufferReader() == ']'){
        if (!strcmp(comm, "NEWLN")){
            printf("\n");
            linepos=0;
        }
        else if (!strcmp(comm, "DELAY")){
            sleep(1);
        }
        else if (!strcmp(comm, "DBNLN")){
            printf("\n\n");
            linepos = 0;
        }
        else if (!strcmp(comm, "INDNT")){
            printf("\n     ");
            linepos = 5;
        }
        else{
            printf("\nError: unrecognized command\n");
        }
    }
}

variable_types:
comm
char [5]

variable_types: i int


displayText

decompiled_code:
int __fastcall displayText(char a1)
{
int result; // eax

if ( !isprint(a1) )
return puts("\nError: non-displayable character");
if ( a1 == 91 )
return execComm();
result = putchar(a1);
++linepos;
return result;
}

canonical_decompiled_code:
int __fastcall func9(char a1)
{
int result; // eax

if ( !isprint(a1) )
return puts("\nError: non-displayable character");
if ( a1 == 91 )
return func8();
result = putchar(a1);
++linepos;
return result;
}

original_code:
void displayText (char ch) {
    if (isprint(ch))
        if (ch == '[')
            execComm();
        else{
            printf("%c", ch);
            linepos++;
        }
    else
        printf("\nError: non-displayable character\n");
}

canonical_original_code:
void displayText(char ch) {
    if (isprint(ch))
        if (ch == '[')
            execComm();
        else{
            printf("%c", ch);
            linepos++;
        }
    else
        printf("\nError: non-displayable character\n");
}


controller

decompiled_code:
void *__fastcall controller(void *a1)
{
char v1; // al

while ( linepos != 30 )
{
v1 = bufferReader();
if ( v1 == -1 )
return 0LL;
LABEL_3:
displayText(v1);
}
putchar(10);
linepos = 0;
v1 = bufferReader();
if ( v1 != -1 )
goto LABEL_3;
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func10(void *a1)
{
char v1; // al

while ( linepos != 30 )
{
v1 = func7();
if ( v1 == -1 )
return 0LL;
LABEL_3:
func9(v1);
}
putchar(10);
linepos = 0;
v1 = func7();
if ( v1 != -1 )
goto LABEL_3;
return 0LL;
}

original_code:
void * controller(void * arg)
{
    char ch;
    int j;
    char command[7];
    while(1) {
        if (linepos == 30){
            printf("\n");
            linepos = 0;
        }
        ch = bufferReader();
        if (ch!=(-1))
            displayText(ch);
        else
            break;
    }
 return 0;
}

canonical_original_code:
void *controller(void *arg)
{
    char ch;
    int j;
    char command[7];
    while(1) {
        if (linepos == 30){
            printf("\n");
            linepos = 0;
        }
        ch = bufferReader();
        if (ch!=(-1))
            displayText(ch);
        else
            break;
    }
 return 0;
}

variable_types:
arg
void *

variable_types: j int

variable_types:
command
char [7]

return_type: void *


bufferWriter

decompiled_code:
int __fastcall bufferWriter(char *src)
{
pthread_mutex_lock(&mutex);
if ( current <= 6 )
pthread_cond_wait(&reading_done, &mutex);
strncpy(&buffer, src, 7uLL);
current = 0;
pthread_cond_signal(&writing_done);
return pthread_mutex_unlock(&mutex);
}

canonical_decompiled_code:
int __fastcall func11(char *src)
{
pthread_mutex_lock(&mutex);
if ( current <= 6 )
pthread_cond_wait(&reading_done, &mutex);
strncpy(&buffer, src, 7uLL);
current = 0;
pthread_cond_signal(&writing_done);
return pthread_mutex_unlock(&mutex);
}

original_code:
void bufferWriter(char data[])
{
    pthread_mutex_lock(&mutex);
 if (current < 7)
  pthread_cond_wait(&reading_done, &mutex);
  strncpy(buffer, data, 7);
 current = 0;
 pthread_cond_signal(&writing_done);
   pthread_mutex_unlock(&mutex);
}

variable_types:
data
char []


devDriver

decompiled_code:
void *__fastcall devDriver(void *a1)
{
__int64 v1; // rbx
char v2; // al
char src[31]; // [rsp+9h] [rbp-1Fh] BYREF

LABEL_1:
v1 = 0LL;
while ( 1 )
{
v2 = getchar();
if ( v2 == -1 )
break;
src[v1++] = v2;
if ( v1 == 7 )
{
bufferWriter(src);
goto LABEL_1;
}
}
src[(int)v1] = -1;
bufferWriter(src);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func12(void *a1)
{
__int64 v1; // rbx
char v2; // al
char src[31]; // [rsp+9h] [rbp-1Fh] BYREF

LABEL_1:
v1 = 0LL;
while ( 1 )
{
v2 = getchar();
if ( v2 == -1 )
break;
src[v1++] = v2;
if ( v1 == 7 )
{
func11(src);
goto LABEL_1;
}
}
src[(int)v1] = -1;
func11(src);
return 0LL;
}

original_code:
void * devDriver(void * arg)
{
    int i;
    int n = 0;
    char ch;
    char buff[7];
    while(1){
        for (i=0;i<7;i++){
            ch = getchar();
            if (ch!= (-1))
                buff[i] = ch;
            else {
                buff[i] = ch;
                bufferWriter(buff);
                return 0;
            }
        }
            bufferWriter(buff);
    }
 return 0;
}

canonical_original_code:
void *devDriver(void *arg)
{
    int i;
    int n = 0;
    char ch;
    char buff[7];
    while(1){
        for (i=0;i<7;i++){
            ch = getchar();
            if (ch!= (-1))
                buff[i] = ch;
            else {
                buff[i] = ch;
                bufferWriter(buff);
                return 0;
            }
        }
            bufferWriter(buff);
    }
 return 0;
}

variable_types: n int

variable_types:
buff
char [7]


repo: ryanlayer/nway

decompiled_code:
__int64 __fastcall mslab_grow(__int64 a1)
{
_QWORD *v1; // rbx
void *v2; // rax
__int64 result; // rax

v1 = malloc(0x18uLL);
v2 = malloc(*(_QWORD *)(a1 + 24) * *(int *)(a1 + 16));
v1[2] = 0LL;
*v1 = v2;
result = *(_QWORD *)(a1 + 8);
*((_DWORD *)v1 + 2) = 0;
*(_QWORD *)(result + 16) = v1;
*(_QWORD *)(a1 + 8) = v1;
return result;
}

original_code:
void mslab_grow(struct mslab *slab)
{
    struct mslabs *new_slab = (struct mslabs *) malloc (sizeof(struct mslabs));
    new_slab->slab = (void *) malloc(slab->slab_size * slab->element_size);
    new_slab->next = ((void *)0);
    new_slab->next_free = 0;
    slab->tail->next = new_slab;
    slab->tail = new_slab;
}

variable_types: struct mslab { struct mslabs { void *slab; int next_free; struct mslabs *next; } *head; int slab_size; unsigned long element_size; } *

user_defined_types: struct mslab { struct mslabs *head; int slab_size; unsigned long element_size; }


original_code:
void *mslab_get(struct mslab *slab)
{
    struct mslabs *tail = slab->tail;
    if (tail->next_free == slab->slab_size)
        mslab_grow(slab);
    void *next_slab = (void *)
        (tail->slab + (tail->next_free * slab->element_size));
    tail->next_free += 1;
    return next_slab;
}

variable_types: struct mslabs { void *slab; int next_free; struct mslabs *next; } *


amortize

original_code:
double amortize(double amt, double rate, double inflation, int months,
                int selloff_month, double extra_payoff, int verbose,
                double *interest_pv, double *duration, double *monthly_payment){
    double total_interest = 0;
    *interest_pv = 0;
    double mrate = rate/1200;
    *monthly_payment = amt * mrate/(1-pow(1+mrate, -months));
    if (verbose) printf("Your total monthly payment: %g\n\n", *monthly_payment);
    int end_month = (selloff_month && selloff_month < months )
                            ? selloff_month
                            : months;
    if (verbose) printf("yr/mon\tPrinc.\tInt.\t| PV Princ.\tPV Int.\tRatio\n");
    int m;
    for (m=0; m < end_month && amt > 0; m++){
        amt -= extra_payoff;
        double interest_payment = amt*mrate;
        double principal_payment = *monthly_payment - interest_payment;
        if (amt <= 0)
            principal_payment =
            interest_payment = 0;
        amt -= principal_payment;
        double deflator = pow(1+ inflation/100, -m/12.);
        *interest_pv += interest_payment * deflator;
        total_interest += interest_payment;
        if (verbose) printf("%i/%i\t%7.5g\t%7.5g\t| %7.5g\t %7.5g\t%7.5g\n",
                m/12, m-12*(m/12)+1, principal_payment, interest_payment,
                principal_payment*deflator, interest_payment*deflator,
                principal_payment/interest_payment);
    }
    *duration = m/12.;
    return total_interest;
}

variable_types: amt double

variable_types: rate double

variable_types: inflation double

variable_types: months int

variable_types: verbose int

variable_types:
duration
double *

variable_types: mrate double

variable_types: m int

variable_types: deflator double

return_type: double


main

repo: sebastianmeisner/mylib

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // rbp
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

if ( argc == 2 )
{
v4 = (unsigned int)atoi(argv[1]);
printf("Param: %8i, in Hex: %8x\n", v4, v4);
v5 = popcnt_count((unsigned int)v4);
printf("popcnt_count set bits: %2i\n", v5);
v6 = popcnt_mask((unsigned int)v4);
printf("popcnt_mask set bits: %2i\n", v6);
sethamming((unsigned int)v4);
v7 = popcnt_lut();
printf("popcnt_lut set bits: %2i\n", v7);
v8 = popcnt_builtin((unsigned int)v4);
printf("popcnt_builtin set bits: %2i\n", v8);
result = 0;
}
else
{
puts("No param given! Exiting...");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__int64 v4; // rbp
unsigned int v5; // eax
unsigned int v6; // eax
unsigned int v7; // eax
unsigned int v8; // eax

if ( argc == 2 )
{
v4 = (unsigned int)atoi(argv[1]);
printf("Param: %8i, in Hex: %8x\n", v4, v4);
v5 = func7((unsigned int)v4);
printf("popcnt_count set bits: %2i\n", v5);
v6 = func8((unsigned int)v4);
printf("popcnt_mask set bits: %2i\n", v6);
func9((unsigned int)v4);
v7 = func10();
printf("popcnt_lut set bits: %2i\n", v7);
v8 = func11((unsigned int)v4);
printf("popcnt_builtin set bits: %2i\n", v8);
result = 0;
}
else
{
puts("No param given! Exiting...");
result = 1;
}
return result;
}

original_code:
int main (int argc, char ** argv){
 if ( argc != 2 )
 {
  printf("No param given! Exiting...\n");
  return 1;
 }
 unsigned int x = atoi(argv[1]);
 printf("Param: %8i, in Hex: %8x\n", x, x);
 printf("popcnt_count set bits: %2i\n", popcnt_count(x));
 printf("popcnt_mask  set bits: %2i\n", popcnt_mask(x));
 sethamming();
 printf("popcnt_lut   set bits: %2i\n", popcnt_lut(x));
 printf("popcnt_builtin set bits: %2i\n", popcnt_builtin(x));
 return 0;
}

canonical_original_code:
int main(int argc, char **argv){
 if ( argc != 2 )
 {
  printf("No param given! Exiting...\n");
  return 1;
 }
 unsigned int x = atoi(argv[1]);
 printf("Param: %8i, in Hex: %8x\n", x, x);
 printf("popcnt_count set bits: %2i\n", popcnt_count(x));
 printf("popcnt_mask  set bits: %2i\n", popcnt_mask(x));
 sethamming();
 printf("popcnt_lut   set bits: %2i\n", popcnt_lut(x));
 printf("popcnt_builtin set bits: %2i\n", popcnt_builtin(x));
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
x
unsigned int


decompiled_code:
__int64 __fastcall popcnt_count(unsigned int a1)
{
return __popcnt(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
return __popcnt(a1);
}

original_code:
int popcnt_count(unsigned int x)
{
 int i;
 for ( i=0; x; x=x&(x-1), i++);
 return i;
}

variable_types: i int


decompiled_code:
__int64 __fastcall popcnt_mask(int a1)
{
__int64 result; // rax
__int64 v2; // rdx
int v3; // edi
int v4; // ecx
int v5; // esi
unsigned int v6; // eax

LODWORD(result) = a1;
v2 = 0LL;
v3 = 1431655765;
v4 = 1;
while ( 1 )
{
v5 = result;
v6 = (unsigned int)result >> v4;
++v2;
v4 *= 2;
result = (v3 & v5) + (v3 & v6);
if ( v2 == 5 )
break;
v3 = mask_0[v2];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 result; // rax
__int64 v2; // rdx
int v3; // edi
int v4; // ecx
int v5; // esi
unsigned int v6; // eax

LODWORD(result) = a1;
v2 = 0LL;
v3 = 1431655765;
v4 = 1;
while ( 1 )
{
v5 = result;
v6 = (unsigned int)result >> v4;
++v2;
v4 *= 2;
result = (v3 & v5) + (v3 & v6);
if ( v2 == 5 )
break;
v3 = mask_0[v2];
}
return result;
}

original_code:
int popcnt_mask(unsigned int x)
{
 static const unsigned int mask[] =
 {
   0x55555555,
   0x33333333,
   0x0f0f0f0f,
   0x00ff00ff,
   0x0000ffff
 };
 int i;
 int shift;
 for ( i=0, shift = 1; i< 5; i++, shift *= 2)
 {
  x = (x & mask[i]) + ((x>>shift) & mask[i]);
 }
 return x;
}

canonical_original_code:
int popcnt_mask(unsigned int x)
{
 static unsigned int mask[] = {
   0x55555555,
   0x33333333,
   0x0f0f0f0f,
   0x00ff00ff,
   0x0000ffff
 };
 int i;
 int shift;
 for ( i=0, shift = 1; i< 5; i++, shift *= 2)
 {
  x = (x & mask[i]) + ((x>>shift) & mask[i]);
 }
 return x;
}

variable_types:
mask
unsigned int []

variable_types: shift int


sethamming

decompiled_code:
__int64 sethamming()
{
__int64 result; // rax
char v1; // dl

hamming = 256;
for ( result = 2LL; result != 256; ++result )
{
if ( (result & 1) != 0 )
v1 = byte_40405F[result] + 1;
else
v1 = *((_BYTE *)&hamming + ((int)result >> 1));
*((_BYTE *)&hamming + result) = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
char v1; // dl

hamming = 256;
for ( result = 2LL; result != 256; ++result )
{
if ( (result & 1) != 0 )
v1 = byte_40405F[result] + 1;
else
v1 = *((_BYTE *)&hamming + ((int)result >> 1));
*((_BYTE *)&hamming + result) = v1;
}
return result;
}

original_code:
void sethamming()
{
 hamming[0]=0;
 hamming[1]=1;
 int i;
 for ( i=2; i<256; i++ )
 {
  if (i&1) { hamming[i]=hamming[i-1]+1;}
  else { hamming[i]=hamming[i>>1]; }
 }
}


decompiled_code:
__int64 __fastcall popcnt_lut(unsigned int a1)
{
return *((unsigned __int8 *)&hamming + BYTE2(a1))
+ *((unsigned __int8 *)&hamming + (unsigned __int8)a1)
+ *((unsigned __int8 *)&hamming + BYTE1(a1))
+ (unsigned int)*((unsigned __int8 *)&hamming + HIBYTE(a1));
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
return *((unsigned __int8 *)&hamming + BYTE2(a1))
+ *((unsigned __int8 *)&hamming + (unsigned __int8)a1)
+ *((unsigned __int8 *)&hamming + BYTE1(a1))
+ (unsigned int)*((unsigned __int8 *)&hamming + HIBYTE(a1));
}

original_code:
int popcnt_lut(unsigned int x)
{
 unsigned char a,b,c,d;
 a=x;
 b=x>>8;
 c=x>>16;
 d=x>>24;
 return hamming[a]+hamming[b]+hamming[c]+hamming[d];
}

canonical_original_code:
int popcnt_lut(unsigned int x)
{
 unsigned char a; unsigned char b; unsigned char c; unsigned char d;
 a=x;
 b=x>>8;
 c=x>>16;
 d=x>>24;
 return hamming[a]+hamming[b]+hamming[c]+hamming[d];
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types:
c
unsigned char

variable_types:
d
unsigned char


decompiled_code:
__int64 __fastcall popcnt_builtin(unsigned int a1)
{
return __popcnt(a1);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
return __popcnt(a1);
}

original_code:
int popcnt_builtin(unsigned int x)
{
 return __builtin_popcount(x);
}


main

repo: skagedal/xmlchar

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("NameChar\n--------");
puts("- naive:");
print_time(naive_is_name_char, argv);
printf("- bigtable:\n - uses %d kilobytes.\n", 136LL);
if ( (unsigned int)test_valid_name_char_func("bigtable_is_name_char", bigtable_is_name_char) )
puts(" - works.");
print_time(bigtable_is_name_char, bigtable_is_name_char);
printf("- pagedtable:\n - uses %d kilobytes.\n", 2LL);
if ( (unsigned int)test_valid_name_char_func("pagedtable_is_name_char", pagedtable_is_name_char) )
puts(" - works.");
print_time(pagedtable_is_name_char, pagedtable_is_name_char);
puts("\nNameStartChar\n-------------");
puts("- naive:");
print_time(naive_is_name_start_char, pagedtable_is_name_char);
printf("- bigtable:\n - uses %d kilobytes.\n", 136LL);
if ( (unsigned int)test_valid_name_start_char_func("bigtable_is_name_start_char", bigtable_is_name_start_char) )
puts(" - works.");
print_time(bigtable_is_name_start_char, bigtable_is_name_start_char);
printf("- pagedtable:\n - uses %d kilobytes.\n", 2LL);
if ( (unsigned int)test_valid_name_start_char_func("pagedtable_is_name_start_char", pagedtable_is_name_start_char) )
puts(" - works.");
print_time(pagedtable_is_name_start_char, pagedtable_is_name_start_char);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts("NameChar\n--------");
puts("- naive:");
func18(naive_is_name_char, argv);
printf("- bigtable:\n - uses %d kilobytes.\n", 136LL);
if ( (unsigned int)func13("bigtable_is_name_char", bigtable_is_name_char) )
puts(" - works.");
func18(bigtable_is_name_char, bigtable_is_name_char);
printf("- pagedtable:\n - uses %d kilobytes.\n", 2LL);
if ( (unsigned int)func13("pagedtable_is_name_char", pagedtable_is_name_char) )
puts(" - works.");
func18(pagedtable_is_name_char, pagedtable_is_name_char);
puts("\nNameStartChar\n-------------");
puts("- naive:");
func18(naive_is_name_start_char, pagedtable_is_name_char);
printf("- bigtable:\n - uses %d kilobytes.\n", 136LL);
if ( (unsigned int)func14("bigtable_is_name_start_char", bigtable_is_name_start_char) )
puts(" - works.");
func18(bigtable_is_name_start_char, bigtable_is_name_start_char);
printf("- pagedtable:\n - uses %d kilobytes.\n", 2LL);
if ( (unsigned int)func14("pagedtable_is_name_start_char", pagedtable_is_name_start_char) )
puts(" - works.");
func18(pagedtable_is_name_start_char, pagedtable_is_name_start_char);
return 0;
}

original_code:
int
main (int argc, char *argv[])
{
  printf ("NameChar\n--------\n");
  printf ("- naive:\n");
  print_time (naive_is_name_char);
  printf ("- bigtable:\n  - uses %d kilobytes.\n", sizeof NameChar / 1024);
  if (test_valid_name_char_func ("bigtable_is_name_char",
     bigtable_is_name_char))
    printf ("  - works.\n");
  print_time (bigtable_is_name_char);
  printf ("- pagedtable:\n  - uses %d kilobytes.\n",
     (sizeof NameChar_index + sizeof NameChar_pages) / 1024);
  if (test_valid_name_char_func ("pagedtable_is_name_char",
     pagedtable_is_name_char))
    printf ("  - works.\n");
  print_time (pagedtable_is_name_char);
  printf ("\nNameStartChar\n-------------\n");
  printf ("- naive:\n");
  print_time (naive_is_name_start_char);
  printf ("- bigtable:\n  - uses %d kilobytes.\n", sizeof NameStartChar / 1024);
  if (test_valid_name_start_char_func ("bigtable_is_name_start_char",
     bigtable_is_name_start_char))
    printf ("  - works.\n");
  print_time (bigtable_is_name_start_char);
  printf ("- pagedtable:\n  - uses %d kilobytes.\n",
     (sizeof NameStartChar_index + sizeof NameStartChar_pages) / 1024);
  if (test_valid_name_start_char_func ("pagedtable_is_name_start_char",
     pagedtable_is_name_start_char))
    printf ("  - works.\n");
  print_time (pagedtable_is_name_start_char);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  printf ("NameChar\n--------\n");
  printf ("- naive:\n");
  print_time (naive_is_name_char);
  printf ("- bigtable:\n  - uses %d kilobytes.\n", sizeof NameChar / 1024);
  if (test_valid_name_char_func ("bigtable_is_name_char",
     bigtable_is_name_char))
    printf ("  - works.\n");
  print_time (bigtable_is_name_char);
  printf ("- pagedtable:\n  - uses %d kilobytes.\n",
     (sizeof NameChar_index + sizeof NameChar_pages) / 1024);
  if (test_valid_name_char_func ("pagedtable_is_name_char",
     pagedtable_is_name_char))
    printf ("  - works.\n");
  print_time (pagedtable_is_name_char);
  printf ("\nNameStartChar\n-------------\n");
  printf ("- naive:\n");
  print_time (naive_is_name_start_char);
  printf ("- bigtable:\n  - uses %d kilobytes.\n", sizeof NameStartChar / 1024);
  if (test_valid_name_start_char_func ("bigtable_is_name_start_char",
     bigtable_is_name_start_char))
    printf ("  - works.\n");
  print_time (bigtable_is_name_start_char);
  printf ("- pagedtable:\n  - uses %d kilobytes.\n",
     (sizeof NameStartChar_index + sizeof NameStartChar_pages) / 1024);
  if (test_valid_name_start_char_func ("pagedtable_is_name_start_char",
     pagedtable_is_name_start_char))
    printf ("  - works.\n");
  print_time (pagedtable_is_name_start_char);
}

variable_types:
argv
char *[]


decompiled_code:
_BOOL8 __fastcall naive_is_name_start_char(unsigned int a1)
{
_BOOL8 result; // rax

if ( a1 == 95 || a1 == 58 || (a1 & 0xFFFFFFDF) - 65 <= 0x19 )
return 1LL;
result = 0LL;
if ( a1 > 0xBF )
{
result = 1LL;
if ( a1 > 0xD6 )
{
result = 0LL;
if ( a1 != 215 )
{
result = 1LL;
if ( a1 > 0xF6 )
{
result = 0LL;
if ( a1 != 247 )
{
result = 1LL;
if ( a1 > 0x2FF )
{
result = 0LL;
if ( a1 > 0x36F )
{
result = 1LL;
if ( a1 > 0x37D )
{
result = 0LL;
if ( a1 != 894 )
{
result = 1LL;
if ( a1 > 0x1FFF )
{
result = 0LL;
if ( a1 > 0x200B )
{
result = 1LL;
if ( a1 > 0x200D )
{
result = 0LL;
if ( a1 > 0x206F )
{
result = 1LL;
if ( a1 > 0x218F )
{
result = 0LL;
if ( a1 > 0x2BFF )
{
result = 1LL;
if ( a1 > 0x2FEF )
{
if ( a1 <= 0x3000 )
return 0LL;
if ( a1 > 0xD7FF )
{
if ( a1 <= 0xF8FF )
return 0LL;
if ( a1 > 0xFDCF )
{
if ( a1 > 0xFDEF )
{
if ( a1 > 0xFFFD )
return a1 - 0x10000 <= 0xDFFFF;
return 1LL;
}
return 0LL;
}
}
return 1LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

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

if ( a1 == 95 || a1 == 58 || (a1 & 0xFFFFFFDF) - 65 <= 0x19 )
return 1LL;
result = 0LL;
if ( a1 > 0xBF )
{
result = 1LL;
if ( a1 > 0xD6 )
{
result = 0LL;
if ( a1 != 215 )
{
result = 1LL;
if ( a1 > 0xF6 )
{
result = 0LL;
if ( a1 != 247 )
{
result = 1LL;
if ( a1 > 0x2FF )
{
result = 0LL;
if ( a1 > 0x36F )
{
result = 1LL;
if ( a1 > 0x37D )
{
result = 0LL;
if ( a1 != 894 )
{
result = 1LL;
if ( a1 > 0x1FFF )
{
result = 0LL;
if ( a1 > 0x200B )
{
result = 1LL;
if ( a1 > 0x200D )
{
result = 0LL;
if ( a1 > 0x206F )
{
result = 1LL;
if ( a1 > 0x218F )
{
result = 0LL;
if ( a1 > 0x2BFF )
{
result = 1LL;
if ( a1 > 0x2FEF )
{
if ( a1 <= 0x3000 )
return 0LL;
if ( a1 > 0xD7FF )
{
if ( a1 <= 0xF8FF )
return 0LL;
if ( a1 > 0xFDCF )
{
if ( a1 > 0xFDEF )
{
if ( a1 > 0xFFFD )
return a1 - 0x10000 <= 0xDFFFF;
return 1LL;
}
return 0LL;
}
}
return 1LL;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

variable_types:
c
unsigned int


decompiled_code:
_BOOL8 __fastcall naive_is_name_char(unsigned int a1)
{
_BOOL8 result; // rax
unsigned int v2; // ecx

result = naive_is_name_start_char(a1);
if ( result || v2 - 48 <= 9 || v2 - 45 <= 1 || v2 == 183 )
return 1LL;
if ( v2 > 0x2FF )
{
result = 1LL;
if ( v2 > 0x36F )
result = v2 - 8255 <= 1;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(unsigned int a1)
{
_BOOL8 result; // rax
unsigned int v2; // ecx

result = func7(a1);
if ( result || v2 - 48 <= 9 || v2 - 45 <= 1 || v2 == 183 )
return 1LL;
if ( v2 > 0x2FF )
{
result = 1LL;
if ( v2 > 0x36F )
result = v2 - 8255 <= 1;
}
return result;
}

original_code:
gboolean naive_is_name_char (gunichar c)
{
  if (naive_is_name_start_char (c))
    return (!(0));
  if (c == '-' || c == '.' ||
      (c >= '0' && c <= '9') ||
      c == 0xB7)
    return (!(0));
  if (c < 0x0300) return (0);
  if (c <= 0x036F) return (!(0));
  if (c < 0x203F) return (0);
  if (c <= 0x2040) return (!(0));
  return (0);
}


decompiled_code:
_BOOL8 __fastcall bigtable_is_name_char(unsigned int a1)
{
return (NameChar[a1 >> 5] & (1 << a1)) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(unsigned int a1)
{
return (NameChar[a1 >> 5] & (1 << a1)) != 0;
}

original_code:
gboolean
bigtable_is_name_char (gunichar c)
{
  return ((NameChar[c / 32] & (1 << (c % 32))) != 0);
}

canonical_original_code:
int bigtable_is_name_char(unsigned int c)
{
  return ((NameChar[c / 32] & (1 << (c % 32))) != 0);
}


decompiled_code:
_BOOL8 __fastcall bigtable_is_name_start_char(unsigned int a1)
{
return (NameStartChar[a1 >> 5] & (1 << a1)) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(unsigned int a1)
{
return (NameStartChar[a1 >> 5] & (1 << a1)) != 0;
}

original_code:
gboolean
bigtable_is_name_start_char (gunichar c)
{
  return ((NameStartChar[c / 32] & (1 << (c % 32))) != 0);
}

canonical_original_code:
int bigtable_is_name_start_char(unsigned int c)
{
  return ((NameStartChar[c / 32] & (1 << (c % 32))) != 0);
}


decompiled_code:
__int64 __fastcall pagedtable_is_name_char(unsigned int a1)
{
return ((unsigned int)NameChar_pages[32
* (unsigned __int64)(((unsigned int)NameStartChar_index[a1 >> 13] >> (BYTE1(a1) & 0x1C)) & 0xF)
+ ((a1 >> 5) & 0x1F)] >> a1) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1)
{
return ((unsigned int)NameChar_pages[32
* (unsigned __int64)(((unsigned int)NameStartChar_index[a1 >> 13] >> (BYTE1(a1) & 0x1C)) & 0xF)
+ ((a1 >> 5) & 0x1F)] >> a1) & 1;
}

original_code:
gboolean
pagedtable_is_name_char (gunichar c)
{
  const guint32 *page;
  gint page_index_a, page_index_b, bit_index_a, bit_index_b;
  gint page_number;
  bit_index_b = c & 0x1F;
  c >>= 5;
  bit_index_a = c & 0x1F;
  c >>= 5;
  page_index_b = c & 0x07;
  c >>= 3;
  page_index_a = c;
  page_number = (NameChar_index [page_index_a] >> (page_index_b << 2)) & 0xF;
  page = NameChar_pages [page_number];
  return (page[bit_index_a] >> bit_index_b) & 0x1;
}

canonical_original_code:
int pagedtable_is_name_char(unsigned int c)
{
  unsigned int *page;
  int page_index_a; int page_index_b; int bit_index_a; int bit_index_b;
  int page_number;
  bit_index_b = c & 0x1F;
  c >>= 5;
  bit_index_a = c & 0x1F;
  c >>= 5;
  page_index_b = c & 0x07;
  c >>= 3;
  page_index_a = c;
  page_number = (NameChar_index [page_index_a] >> (page_index_b << 2)) & 0xF;
  page = NameChar_pages [page_number];
  return (page[bit_index_a] >> bit_index_b) & 0x1;
}

variable_types:
page
unsigned int *


decompiled_code:
__int64 __fastcall pagedtable_is_name_start_char(unsigned int a1)
{
return ((unsigned int)NameStartChar_pages[32
* (unsigned __int64)(((unsigned int)NameStartChar_index[a1 >> 13] >> (BYTE1(a1) & 0x1C)) & 0xF)
+ ((a1 >> 5) & 0x1F)] >> a1) & 1;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1)
{
return ((unsigned int)NameStartChar_pages[32
* (unsigned __int64)(((unsigned int)NameStartChar_index[a1 >> 13] >> (BYTE1(a1) & 0x1C)) & 0xF)
+ ((a1 >> 5) & 0x1F)] >> a1) & 1;
}

original_code:
gboolean
pagedtable_is_name_start_char (gunichar c)
{
  const guint32 *page;
  gint page_index_a, page_index_b, bit_index_a, bit_index_b;
  gint page_number;
  bit_index_b = c & 0x1F;
  c >>= 5;
  bit_index_a = c & 0x1F;
  c >>= 5;
  page_index_b = c & 0x07;
  c >>= 3;
  page_index_a = c;
  page_number = (NameStartChar_index [page_index_a] >> (page_index_b << 2)) & 0xF;
  page = NameStartChar_pages [page_number];
  return (page[bit_index_a] >> bit_index_b) & 0x1;
}

canonical_original_code:
int pagedtable_is_name_start_char(unsigned int c)
{
  unsigned int *page;
  int page_index_a; int page_index_b; int bit_index_a; int bit_index_b;
  int page_number;
  bit_index_b = c & 0x1F;
  c >>= 5;
  bit_index_a = c & 0x1F;
  c >>= 5;
  page_index_b = c & 0x07;
  c >>= 3;
  page_index_a = c;
  page_number = (NameStartChar_index [page_index_a] >> (page_index_b << 2)) & 0xF;
  page = NameStartChar_pages [page_number];
  return (page[bit_index_a] >> bit_index_b) & 0x1;
}


decompiled_code:
__int64 __fastcall test_valid_name_char_func(__int64 a1, void (__fastcall *a2)(_QWORD))
{
unsigned int i; // ebx
int v3; // eax
int v4; // er8
char v6[48]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0; i != 1114112; ++i )
{
a2(i);
v3 = naive_is_name_char(i);
if ( v4 != v3 )
{
v6[(int)g_unichar_to_utf8()] = 0;
((void (__fastcall *)(_QWORD, char *))a2)(i, v6);
g_log();
return 0LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, void (__fastcall *a2)(_QWORD))
{
unsigned int i; // ebx
int v3; // eax
int v4; // er8
char v6[48]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0; i != 1114112; ++i )
{
a2(i);
v3 = func8(i);
if ( v4 != v3 )
{
v6[(int)g_unichar_to_utf8()] = 0;
((void (__fastcall *)(_QWORD, char *))a2)(i, v6);
g_log();
return 0LL;
}
}
return 1LL;
}

original_code:
gboolean
test_valid_name_char_func (gchar *s, chartest_func f)
{
  int i;
  for (i = 0; i < 0x110000; i++)
    {
      if (f(i) != naive_is_name_char(i))
 {
   gchar buf[8];
   buf [g_unichar_to_utf8 (i, buf)] = '\0';
   g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "%s returns %d on char 0x%x (%s), where naive implementation returns %d", s, f(i), i, buf, naive_is_name_char(i));
   return (0);
 }
    }
  return (!(0));
}

canonical_original_code:
int test_valid_name_char_func(char *s, int (*f)(unsigned int c))
{
  int i;
  for (i = 0; i < 0x110000; i++)
    {
      if (f(i) != naive_is_name_char(i))
 {
   char buf[8];
   buf [g_unichar_to_utf8 (i, buf)] = '\0';
   g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "%s returns %d on char 0x%x (%s), where naive implementation returns %d", s, f(i), i, buf, naive_is_name_char(i));
   return (0);
 }
    }
  return (!(0));
}

variable_types:
s
char *

variable_types:
f
int (*)(unsigned int c)

variable_types:
buf
char [8]


decompiled_code:
__int64 __fastcall test_valid_name_start_char_func(__int64 a1, void (__fastcall *a2)(_QWORD))
{
unsigned int i; // ebx
int v3; // eax
int v4; // ecx
char v6[48]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0; i != 1114112; ++i )
{
a2(i);
v3 = naive_is_name_start_char(i);
if ( v4 != v3 )
{
v6[(int)g_unichar_to_utf8()] = 0;
((void (__fastcall *)(_QWORD, char *))a2)(i, v6);
g_log();
return 0LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, void (__fastcall *a2)(_QWORD))
{
unsigned int i; // ebx
int v3; // eax
int v4; // ecx
char v6[48]; // [rsp+8h] [rbp-30h] BYREF

for ( i = 0; i != 1114112; ++i )
{
a2(i);
v3 = func7(i);
if ( v4 != v3 )
{
v6[(int)g_unichar_to_utf8()] = 0;
((void (__fastcall *)(_QWORD, char *))a2)(i, v6);
g_log();
return 0LL;
}
}
return 1LL;
}

original_code:
gboolean
test_valid_name_start_char_func (gchar *s, chartest_func f)
{
  int i;
  for (i = 0; i < 0x110000; i++)
    {
      if (f(i) != naive_is_name_start_char(i))
 {
   gchar buf[8];
   buf [g_unichar_to_utf8 (i, buf)] = '\0';
   g_log (((gchar*) 0), G_LOG_LEVEL_CRITICAL, "%s returns %d on char 0x%x (%s), where naive implementation returns %d", s, f(i), i, buf, naive_is_name_start_char(i));
   return (0);
 }
    }
  return (!(0));
}

canonical_original_code:
int test_valid_name_start_char_func(char *s, int (*f)(unsigned int c))
{
  int i;
  for (i = 0; i < 0x110000; i++)
    {
      if (f(i) != naive_is_name_start_char(i))
 {
   char buf[8];
   buf [g_unichar_to_utf8 (i, buf)] = '\0';
   g_log (((char *) 0), G_LOG_LEVEL_CRITICAL, "%s returns %d on char 0x%x (%s), where naive implementation returns %d", s, f(i), i, buf, naive_is_name_start_char(i));
   return (0);
 }
    }
  return (!(0));
}


decompiled_code:
double __fastcall timespec_to_double(_QWORD *a1)
{
return (double)(int)a1[1] / 1000000000.0 + (double)(int)*a1;
}

canonical_decompiled_code:
double __fastcall func15(_QWORD *a1)
{
return (double)(int)a1[1] / 1000000000.0 + (double)(int)*a1;
}

original_code:
gdouble
timespec_to_double (struct timespec *t)
{
  return t->tv_sec + (gdouble)t->tv_nsec / 1000000000.0;
}

canonical_original_code:
double timespec_to_double(struct timespec *t)
{
  return t->tv_sec + (double)t->tv_nsec / 1000000000.0;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *


decompiled_code:
void __fastcall test_time(void (__fastcall *a1)(__int64), __m128 a2)
{
int v3; // er12
unsigned int i; // ebx
__int64 v5; // rdi
struct timespec v6; // [rsp+0h] [rbp-38h] BYREF
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF

if ( clock_gettime(1, &v6) )
g_assertion_message_expr();
v3 = 100;
do
{
for ( i = 0; i != 1114112; ++i )
{
v5 = i;
a1(v5);
}
--v3;
}
while ( v3 );
if ( clock_gettime(1, &tp) )
{
g_assertion_message_expr();
test_time_ascii(0LL, "test_char.c");
}
else
{
time_diff(&tp, &v6, a2);
}
}

canonical_decompiled_code:
void __fastcall func16(void (__fastcall *a1)(__int64), __m128 a2)
{
int v3; // er12
unsigned int i; // ebx
__int64 v5; // rdi
struct timespec v6; // [rsp+0h] [rbp-38h] BYREF
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF

if ( clock_gettime(1, &v6) )
g_assertion_message_expr();
v3 = 100;
do
{
for ( i = 0; i != 1114112; ++i )
{
v5 = i;
a1(v5);
}
--v3;
}
while ( v3 );
if ( clock_gettime(1, &tp) )
{
g_assertion_message_expr();
func17(0LL, "test_char.c");
}
else
{
time_diff(&tp, &v6, a2);
}
}

original_code:
gdouble
test_time (chartest_func f)
{
  struct timespec start, end;
  int i, j;
  do { if (clock_gettime (1, &start) == 0) ; else g_assertion_message_expr (((gchar*) 0), "test_char.c", 209, ((const char*) (__func__)), "clock_gettime (CLOCK_MONOTONIC, &start) == 0"); } while (0);
  for (i = 0; i < 100; i++)
    {
      for (j = 0; j < 0x110000; j++)
 f (j);
    }
  do { if (clock_gettime (1, &end) == 0) ; else g_assertion_message_expr (((gchar*) 0), "test_char.c", 215, ((const char*) (__func__)), "clock_gettime (CLOCK_MONOTONIC, &end) == 0"); } while (0);
  return time_diff (&end, &start);
}

canonical_original_code:
double test_time(int (*f)(unsigned int c))
{
  struct timespec start; struct timespec end;
  int i; int j;
  do { if (clock_gettime (1, &start) == 0) ; else g_assertion_message_expr (((char *) 0), "test_char.c", 209, ((char *) (__func__)), "clock_gettime (CLOCK_MONOTONIC, &start) == 0"); } while (0);
  for (i = 0; i < 100; i++)
    {
      for (j = 0; j < 0x110000; j++)
 f (j);
    }
  do { if (clock_gettime (1, &end) == 0) ; else g_assertion_message_expr (((char *) 0), "test_char.c", 215, ((char *) (__func__)), "clock_gettime (CLOCK_MONOTONIC, &end) == 0"); } while (0);
  return time_diff (&end, &start);
}

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

variable_types: j int


decompiled_code:
void __fastcall test_time_ascii(void (__fastcall *a1)(__int64), __m128 a2)
{
int v3; // er12
unsigned int i; // ebx
__int64 v5; // rdi
struct timespec v6; // [rsp+0h] [rbp-38h] BYREF
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF

if ( clock_gettime(1, &v6) )
g_assertion_message_expr();
v3 = 800000;
do
{
for ( i = 0; i != 128; ++i )
{
v5 = i;
a1(v5);
}
--v3;
}
while ( v3 );
if ( clock_gettime(1, &tp) )
{
g_assertion_message_expr();
print_time(0LL, "test_char.c");
}
else
{
time_diff(&tp, &v6, a2);
}
}

canonical_decompiled_code:
void __fastcall func17(void (__fastcall *a1)(__int64), __m128 a2)
{
int v3; // er12
unsigned int i; // ebx
__int64 v5; // rdi
struct timespec v6; // [rsp+0h] [rbp-38h] BYREF
struct timespec tp; // [rsp+10h] [rbp-28h] BYREF

if ( clock_gettime(1, &v6) )
g_assertion_message_expr();
v3 = 800000;
do
{
for ( i = 0; i != 128; ++i )
{
v5 = i;
a1(v5);
}
--v3;
}
while ( v3 );
if ( clock_gettime(1, &tp) )
{
g_assertion_message_expr();
func18(0LL, "test_char.c");
}
else
{
time_diff(&tp, &v6, a2);
}
}

original_code:
gdouble
test_time_ascii (chartest_func f)
{
  struct timespec start, end;
  int i, j;
  do { if (clock_gettime (1, &start) == 0) ; else g_assertion_message_expr (((gchar*) 0), "test_char.c", 224, ((const char*) (__func__)), "clock_gettime (CLOCK_MONOTONIC, &start) == 0"); } while (0);
  for (i = 0; i < 100 * 8000; i++)
    {
      for (j = 0; j < 128; j++)
 f (j);
    }
  do { if (clock_gettime (1, &end) == 0) ; else g_assertion_message_expr (((gchar*) 0), "test_char.c", 230, ((const char*) (__func__)), "clock_gettime (CLOCK_MONOTONIC, &end) == 0"); } while (0);
  return time_diff (&end, &start);
}

canonical_original_code:
double test_time_ascii(int (*f)(unsigned int c))
{
  struct timespec start; struct timespec end;
  int i; int j;
  do { if (clock_gettime (1, &start) == 0) ; else g_assertion_message_expr (((char *) 0), "test_char.c", 224, ((char *) (__func__)), "clock_gettime (CLOCK_MONOTONIC, &start) == 0"); } while (0);
  for (i = 0; i < 100 * 8000; i++)
    {
      for (j = 0; j < 128; j++)
 f (j);
    }
  do { if (clock_gettime (1, &end) == 0) ; else g_assertion_message_expr (((char *) 0), "test_char.c", 230, ((char *) (__func__)), "clock_gettime (CLOCK_MONOTONIC, &end) == 0"); } while (0);
  return time_diff (&end, &start);
}

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


decompiled_code:
int __fastcall print_time(void (__fastcall *a1)(__int64), __m128 a2)
{
test_time(a1, a2);
printf(" - takes %.4f seconds to run through all unicode %d times\n", *(double *)a2.m128_u64, 100LL);
test_time_ascii(a1, a2);
return printf(" - takes %.4f seconds to run through ASCII %d times\n", *(double *)a2.m128_u64, 800000LL);
}

canonical_decompiled_code:
int __fastcall func18(void (__fastcall *a1)(__int64), __m128 a2)
{
func16(a1, a2);
printf(" - takes %.4f seconds to run through all unicode %d times\n", *(double *)a2.m128_u64, 100LL);
func17(a1, a2);
return printf(" - takes %.4f seconds to run through ASCII %d times\n", *(double *)a2.m128_u64, 800000LL);
}

original_code:
void
print_time (chartest_func f)
{
  printf ("  - takes %.4f seconds to run through all unicode %d times\n",
   test_time (f), 100);
  printf ("  - takes %.4f seconds to run through ASCII %d times\n",
   test_time_ascii (f), 100 * 8000);
}

canonical_original_code:
void print_time(int (*f)(unsigned int c))
{
  printf ("  - takes %.4f seconds to run through all unicode %d times\n",
   test_time (f), 100);
  printf ("  - takes %.4f seconds to run through ASCII %d times\n",
   test_time_ascii (f), 100 * 8000);
}


repo: smosher/pknative

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
int v4; // ebx
int result; // eax
const char *v6; // r9
const char *v7; // rdx
__int64 v8; // rsi
__int64 v9; // rax
unsigned int v10; // er12
unsigned int v11; // ebp
__int64 v12; // r13
__int64 v13; // rbx

Pm_Initialize();
if ( argc == 3 )
{
v10 = atoi(argv[1]);
v11 = atoi(argv[2]);
Pt_Start();
v12 = Pm_GetDeviceInfo();
v13 = Pm_GetDeviceInfo();
printf("Using device #%2d, '%s' for input\n", v10, *(const char **)(v12 + 16));
printf("Using device #%2d, '%s' for output\n", v11, *(const char **)(v13 + 16));
if ( *(_DWORD *)(v13 + 28) )
{
if ( *(_DWORD *)(v12 + 24) )
{
midi_process(v10, v11);
Pm_Terminate();
return 0;
}
puts("Selected device is unsuitable for input, exiting.");
result = -1;
}
else
{
puts("Selected device is unsuitable for output, exiting.");
result = -1;
}
}
else
{
v3 = 0;
v4 = Pm_CountDevices();
printf("\nUsage: %s <input device id> <output device id>\n\n", *argv);
printf("Listing %d devices:\n", (unsigned int)v4);
if ( v4 <= 0 )
return 0;
while ( 1 )
{
v9 = Pm_GetDeviceInfo();
if ( !v9 )
break;
v6 = "";
v7 = "input ";
if ( *(_DWORD *)(v9 + 28) )
v6 = "output";
v8 = v3;
if ( !*(_DWORD *)(v9 + 24) )
v7 = "";
++v3;
printf("\tDevice: #%2d (%s%s) '%s'\n", v8, v7, v6, *(_QWORD *)(v9 + 16));
if ( v4 == v3 )
return 0;
}
printf("\tDevice id (%2d) out of range\n", v3);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
int v4; // ebx
int result; // eax
const char *v6; // r9
const char *v7; // rdx
__int64 v8; // rsi
__int64 v9; // rax
unsigned int v10; // er12
unsigned int v11; // ebp
__int64 v12; // r13
__int64 v13; // rbx

Pm_Initialize();
if ( argc == 3 )
{
v10 = atoi(argv[1]);
v11 = atoi(argv[2]);
Pt_Start();
v12 = Pm_GetDeviceInfo();
v13 = Pm_GetDeviceInfo();
printf("Using device #%2d, '%s' for input\n", v10, *(const char **)(v12 + 16));
printf("Using device #%2d, '%s' for output\n", v11, *(const char **)(v13 + 16));
if ( *(_DWORD *)(v13 + 28) )
{
if ( *(_DWORD *)(v12 + 24) )
{
func21(v10, v11);
Pm_Terminate();
return 0;
}
puts("Selected device is unsuitable for input, exiting.");
result = -1;
}
else
{
puts("Selected device is unsuitable for output, exiting.");
result = -1;
}
}
else
{
v3 = 0;
v4 = Pm_CountDevices();
printf("\nUsage: %s <input device id> <output device id>\n\n", *argv);
printf("Listing %d devices:\n", (unsigned int)v4);
if ( v4 <= 0 )
return 0;
while ( 1 )
{
v9 = Pm_GetDeviceInfo();
if ( !v9 )
break;
v6 = "";
v7 = "input ";
if ( *(_DWORD *)(v9 + 28) )
v6 = "output";
v8 = v3;
if ( !*(_DWORD *)(v9 + 24) )
v7 = "";
++v3;
printf("\tDevice: #%2d (%s%s) '%s'\n", v8, v7, v6, *(_QWORD *)(v9 + 16));
if ( v4 == v3 )
return 0;
}
printf("\tDevice id (%2d) out of range\n", v3);
result = 0;
}
return result;
}

original_code:
int main(int c, char **v) {
  int dev_count, i;
  PmDeviceID devi, devo;
  const PmDeviceInfo *in, *out;
  Pm_Initialize();
  if(c!=3) {
    dev_count = Pm_CountDevices();
    printf("\nUsage: %s <input device id> <output device id>\n\n", v[0]);
    printf("Listing %d devices:\n", dev_count);
    for(i=0;i<dev_count;i++) {
      devi = i;
      in = Pm_GetDeviceInfo(devi);
      if(in==((void *)0)) {
        printf("\tDevice id (%2d) out of range\n", devi);
        break;
      }
      printf("\tDevice: #%2d (%s%s) '%s'\n",
        devi, (in->input ? "input " : ""), (in->output ? "output" : ""),
        in->name);
    }
    return 0;
  }
  devi=atoi(v[1]);
  devo=atoi(v[2]);
  Pt_Start(1, 0, 0);
  in=Pm_GetDeviceInfo(devi);
  out=Pm_GetDeviceInfo(devo);
  printf("Using device #%2d, '%s' for input\n", devi, in->name);
  printf("Using device #%2d, '%s' for output\n", devo, out->name);
  if(!out->output) {
    printf("Selected device is unsuitable for output, exiting.\n");
    return -1;
  }
  if(!in->input) {
    printf("Selected device is unsuitable for input, exiting.\n");
    return -1;
  }
  midi_process(devi, devo);
  Pm_Terminate();
  return 0;
}

canonical_original_code:
int main(int c, char **v) {
  int dev_count; int i;
  int devi; int devo;
  struct PmDeviceInfo *in; struct PmDeviceInfo *out;
  Pm_Initialize();
  if(c!=3) {
    dev_count = Pm_CountDevices();
    printf("\nUsage: %s <input device id> <output device id>\n\n", v[0]);
    printf("Listing %d devices:\n", dev_count);
    for(i=0;i<dev_count;i++) {
      devi = i;
      in = Pm_GetDeviceInfo(devi);
      if(in==((void *)0)) {
        printf("\tDevice id (%2d) out of range\n", devi);
        break;
      }
      printf("\tDevice: #%2d (%s%s) '%s'\n",
        devi, (in->input ? "input " : ""), (in->output ? "output" : ""),
        in->name);
    }
    return 0;
  }
  devi=atoi(v[1]);
  devo=atoi(v[2]);
  Pt_Start(1, 0, 0);
  in=Pm_GetDeviceInfo(devi);
  out=Pm_GetDeviceInfo(devo);
  printf("Using device #%2d, '%s' for input\n", devi, in->name);
  printf("Using device #%2d, '%s' for output\n", devo, out->name);
  if(!out->output) {
    printf("Selected device is unsuitable for output, exiting.\n");
    return -1;
  }
  if(!in->input) {
    printf("Selected device is unsuitable for input, exiting.\n");
    return -1;
  }
  midi_process(devi, devo);
  Pm_Terminate();
  return 0;
}

variable_types: c int

variable_types:
v
char **

variable_types: devi int

variable_types: devo int

variable_types: struct PmDeviceInfo { int structVersion; char *interf; char *name; int input; int output; int opened; } *


decompiled_code:
int __fastcall sysex_print(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi

v1 = 0LL;
printf("Sending SysEx message:");
do
{
if ( (v1 & 3) == 0 )
printf("\n\t");
v2 = (unsigned int)*(char *)(a1 + v1++);
printf("%02hhx ", v2);
}
while ( *(_BYTE *)(a1 + v1 - 1) != 0xF7 );
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rsi

v1 = 0LL;
printf("Sending SysEx message:");
do
{
if ( (v1 & 3) == 0 )
printf("\n\t");
v2 = (unsigned int)*(char *)(a1 + v1++);
printf("%02hhx ", v2);
}
while ( *(_BYTE *)(a1 + v1 - 1) != 0xF7 );
return putchar(10);
}

original_code:
void sysex_print(char *buf) {
  int i;
  printf("Sending SysEx message:");
  for(i=0;;i++) {
    if(!(i%4)) printf("\n\t");
    printf("%02hhx ", buf[i]);
    if(buf[i] == (char)0xf7) break;
  }
  printf("\n");
  return;
}

variable_types:
buf
char *

variable_types: i int


decompiled_code:
__int64 native_buttonstate()
{
Pm_WriteSysEx();
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
Pm_WriteSysEx();
return 0LL;
}

original_code:
int native_buttonstate(ButtonLightSpec button, ButtonState state, PortMidiStream *midi) {
  char buffer[] = {0xf0, 0x42, 0x40, 0x6e, 0x08, 0x01, 0x00, 0x00, 0xf7};
  buffer[6] = button;
  buffer[7] = state;
  Pm_WriteSysEx(midi, 0, buffer);
  return 0;
}

canonical_original_code:
int native_buttonstate(enum ButtonLightSpec button, enum ButtonState state, void *midi) {
  char buffer[] = {0xf0, 0x42, 0x40, 0x6e, 0x08, 0x01, 0x00, 0x00, 0xf7};
  buffer[6] = button;
  buffer[7] = state;
  Pm_WriteSysEx(midi, 0, buffer);
  return 0;
}

variable_types: enum ButtonLightSpec { ButtonLightSpec_Pad01=0, ButtonLightSpec_Pad02=1, ButtonLightSpec_Pad03=2, ButtonLightSpec_Pad04=3, ButtonLightSpec_Pad05=4, ButtonLightSpec_Pad06=5, ButtonLightSpec_Pad07=6, ButtonLightSpec_Pad08=7, ButtonLightSpec_Pad09=8, ButtonLightSpec_Pad10=9, ButtonLightSpec_Pad11=10, ButtonLightSpec_Pad12=11, ButtonLightSpec_Pad13=12, ButtonLightSpec_Pad14=13, ButtonLightSpec_Pad15=14, ButtonLightSpec_Pad16=15, ButtonLightSpec_Scene=16, ButtonLightSpec_Message=17, ButtonLightSpec_Setting=18, ButtonLightSpec_NoteCC=19, ButtonLightSpec_MidiCH=20, ButtonLightSpec_SWType=21, ButtonLightSpec_RelVal=22, ButtonLightSpec_Vel=23, ButtonLightSpec_Port=24, ButtonLightSpec_FixedVel=25, ButtonLightSpec_ProgChange=26, ButtonLightSpec_X=27, ButtonLightSpec_Y=28, ButtonLightSpec_Knob1=29, ButtonLightSpec_Knob2=30, ButtonLightSpec_Pedal=31, ButtonLightSpec_Roll=32, ButtonLightSpec_Flam=33, ButtonLightSpec_Hold=34 }

variable_types: enum ButtonState { ButtonState_Off=0, ButtonState_On=32, ButtonState_Flashing=99, ButtonState_Flash=65, ButtonState_FlashLong=95 }

variable_types:
midi
void *

variable_types:
buffer
char []


decompiled_code:
__int64 native_ledmsg()
{
Pm_WriteSysEx();
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
Pm_WriteSysEx();
return 0LL;
}

original_code:
int native_ledmsg(char abc[3], char flash, PortMidiStream *midi) {
  char led[] = {
    0xf0, 0x42, 0x40, 0x6e,
    0x08, 0x22, 0x04, 0x00,
    0x29, 0x29, 0x29, 0xf7
  };
  led[7] = flash & 0x1;
  led[8] = abc[0];
  led[9] = abc[1];
  led[10] = abc[2];
  Pm_WriteSysEx(midi, 0, led);
  return 0;
}

canonical_original_code:
int native_ledmsg(char abc[3], char flash, void *midi) {
  char led[] = {
    0xf0, 0x42, 0x40, 0x6e,
    0x08, 0x22, 0x04, 0x00,
    0x29, 0x29, 0x29, 0xf7
  };
  led[7] = flash & 0x1;
  led[8] = abc[0];
  led[9] = abc[1];
  led[10] = abc[2];
  Pm_WriteSysEx(midi, 0, led);
  return 0;
}

variable_types:
abc
char [3]

variable_types: flash char

variable_types:
led
char []


decompiled_code:
__int64 __fastcall read_native(__int64 a1, _BYTE *a2)
{
char v2; // bp
char v3; // bp
int v5; // [rsp+8h] [rbp-20h]

v2 = 0;
LABEL_2:
v3 = v2 & 1;
while ( 1 )
{
if ( (int)Pm_Read() <= 0 )
return 0LL;
if ( v5 == 247 && v3 )
return 1LL;
if ( (v5 & 8) != 0 )
{
v2 = 1;
*a2 = BYTE1(v5);
a2[1] = BYTE2(v5);
a2[2] = HIBYTE(v5);
goto LABEL_2;
}
}
}

original_code:
PmError read_native(PortMidiStream *midi, char *msg) {
  PmError c;
  PmEvent buf;
  int header=0, body=0, complete=0;
  while(c=Pm_Read(midi, &buf, 1) >0) {
    if(c<0) return c;
    if(buf.message == 0x6e4042f0) header=1;
    if((buf.message == 0xf7) && body) {
      complete = 1;
      break;
    }
    if(buf.message & 0x08) {
      body=1;
      msg[0] = (char)(buf.message>>8);
      msg[1] = (char)(buf.message>>16);
      msg[2] = (char)(buf.message>>24);
    }
  }
  return complete;
}

canonical_original_code:
enum PmError read_native(void *midi, char *msg) {
  enum PmError c;
  struct PmEvent buf;
  int header = 0; int body = 0; int complete = 0;
  while(c=Pm_Read(midi, &buf, 1) >0) {
    if(c<0) return c;
    if(buf.message == 0x6e4042f0) header=1;
    if((buf.message == 0xf7) && body) {
      complete = 1;
      break;
    }
    if(buf.message & 0x08) {
      body=1;
      msg[0] = (char)(buf.message>>8);
      msg[1] = (char)(buf.message>>16);
      msg[2] = (char)(buf.message>>24);
    }
  }
  return complete;
}

variable_types:
msg
char *

variable_types: enum PmError { pmNoError=0, pmNoData=0, pmGotData=1, pmHostError=-10000, pmInvalidDeviceId=-9999, pmInsufficientMemory=-9998, pmBufferTooSmall=-9997, pmBufferOverflow=-9996, pmBadPtr=-9995, pmBadData=-9994, pmInternalError=-9993, pmBufferMaxSize=-9992 }

variable_types: struct PmEvent { int message; int timestamp; }

variable_types: header int

variable_types: body int

variable_types: complete int


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

v1 = "enabled";
if ( *(_BYTE *)(a1 + 2) != 3 )
v1 = "disabled";
return printf("Native mode is now %s\n", v1);
}

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

v1 = "enabled";
if ( *(_BYTE *)(a1 + 2) != 3 )
v1 = "disabled";
return printf("Native mode is now %s\n", v1);
}

original_code:
void print_nativestatemsg(char *msg) {
  printf("Native mode is now %s\n", (msg[2] == 0x03 ? "enabled" : "disabled"));
  return;
}


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

v1 = (unsigned int)*(char *)(a1 + 1);
if ( *(_BYTE *)(a1 + 1) > 1u )
return printf("Data dump with params: 0x%02hhx 0x%02hhx\n", v1, (unsigned int)*(char *)(a1 + 2));
v2 = "Err";
if ( !*(_BYTE *)(a1 + 2) )
v2 = "OK";
return printf("Packet %hhd received, %s\n", v1, v2);
}

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

v1 = (unsigned int)*(char *)(a1 + 1);
if ( *(_BYTE *)(a1 + 1) > 1u )
return printf("Data dump with params: 0x%02hhx 0x%02hhx\n", v1, (unsigned int)*(char *)(a1 + 2));
v2 = "Err";
if ( !*(_BYTE *)(a1 + 2) )
v2 = "OK";
return printf("Packet %hhd received, %s\n", v1, v2);
}

original_code:
void print_datadumpmsg(char *msg) {
  if(msg[1] == 0x00 || msg[1] == 0x01) {
    printf("Packet %hhd received, %s\n", msg[1], (msg[2] ? "Err" : "OK"));
  } else {
    printf("Data dump with params: 0x%02hhx 0x%02hhx\n", msg[1], msg[2]);
  }
  return;
}


decompiled_code:
int __fastcall print_padmsg(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const char *v4; // r8
char v5; // al
unsigned int v6; // er12
char v7; // bl

v4 = "up";
v5 = *(_BYTE *)(a1 + 1);
v6 = *(char *)(a1 + 2);
v7 = v5 & 0x3F;
if ( (v5 & 0x40) != 0 )
{
native_buttonstate(*(_BYTE *)(a1 + 1) & 0x3F, (v5 & 0x38) == 0 ? 65 : 95, a2, a4, "up");
v4 = "down";
}
return printf("Pad #%02hhd is %s, velocity %03hhd\n", (unsigned int)(char)(v7 + 1), v4, v6);
}

original_code:
void print_padmsg(char *msg, PortMidiStream *midi) {
  int
    pad = msg[1] & 0x3f,
    on = msg[1] & 0x40,
    vel = msg[2];
  if(on) native_buttonstate(pad, (pad < 8 ? ButtonState_Flash : ButtonState_FlashLong), midi);
  printf("Pad #%02hhd is %s, velocity %03hhd\n", pad +1, (on ? "down" : "up"), vel);
  return;
}

canonical_original_code:
void print_padmsg(char *msg, void *midi) {
  int pad = msg[1] & 0x3f; int on = msg[1] & 0x40; int vel = msg[2];
  if(on) native_buttonstate(pad, (pad < 8 ? ButtonState_Flash : ButtonState_FlashLong), midi);
  printf("Pad #%02hhd is %s, velocity %03hhd\n", pad +1, (on ? "down" : "up"), vel);
  return;
}

variable_types: pad int

variable_types: on int

variable_types: vel int


decompiled_code:
int __fastcall print_facemsg(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v5; // rdx
int v6; // edi
const char *v7; // rbp
const char *v8; // rcx
_DWORD *v9; // rax
__int64 v10; // rdi

v5 = *(char *)(a1 + 1);
v6 = *(char *)(a1 + 2);
if ( (char)v5 > 18 )
{
v8 = "down";
v7 = off_404160;
if ( (_BYTE)v5 != 32 )
v7 = off_404158;
if ( !v6 )
v8 = "up";
}
else
{
v7 = FaceButtonStrings[(int)v5];
v8 = "up";
if ( v6 )
{
v9 = (_DWORD *)(a2 + 4 * v5);
v10 = (unsigned int)(v5 + 16);
if ( *v9 )
{
*v9 = 0;
native_buttonstate(v10, 0LL, a3, "up", a3);
}
else
{
*v9 = 1;
native_buttonstate(v10, 99LL, a3, "up", a3);
}
v5 = (unsigned int)*(char *)(a1 + 1);
v8 = "down";
}
}
return printf("%s (%02hhx) is %s\n", v7, v5, v8);
}

original_code:
void print_facemsg(char *msg, int *lights, PortMidiStream *midi) {
  const char *string;
  int
    button = msg[1],
    down = msg[2];
  if(button <= 0x12) {
    string = FaceButtonStrings[msg[1]];
    if(down) {
      if(lights[button]) {
        lights[button] = 0;
        native_buttonstate(button +0x10, ButtonState_Off, midi);
      } else {
        lights[button] = 1;
        native_buttonstate(button +0x10, ButtonState_Flashing, midi);
      }
    }
  } else if(msg[1] == 0x20) {
    string = FaceButtonStrings[0x14];
  } else {
    string = FaceButtonStrings[0x13];
  }
  printf("%s (%02hhx) is %s\n", string, msg[1], (down ? "down" : "up"));
  return;
}

canonical_original_code:
void print_facemsg(char *msg, int *lights, void *midi) {
  char *string;
  int button = msg[1]; int down = msg[2];
  if(button <= 0x12) {
    string = FaceButtonStrings[msg[1]];
    if(down) {
      if(lights[button]) {
        lights[button] = 0;
        native_buttonstate(button +0x10, ButtonState_Off, midi);
      } else {
        lights[button] = 1;
        native_buttonstate(button +0x10, ButtonState_Flashing, midi);
      }
    }
  } else if(msg[1] == 0x20) {
    string = FaceButtonStrings[0x14];
  } else {
    string = FaceButtonStrings[0x13];
  }
  printf("%s (%02hhx) is %s\n", string, msg[1], (down ? "down" : "up"));
  return;
}

variable_types:
lights
int *

variable_types:
string
char *

variable_types: button int

variable_types: down int


decompiled_code:
int __fastcall print_knobmsg(__int64 a1, __int64 a2)
{
int v2; // ebx
unsigned int v3; // er12
const char *v4; // rdi

v2 = *(char *)(a1 + 1);
v3 = *(char *)(a1 + 2);
v4 = "K-2";
if ( !v2 )
v4 = "K-1";
native_ledmsg(v4, 0LL, a2);
return printf("Knob %hhd value: %03hhd\n", (unsigned int)(v2 + 1), v3);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1, __int64 a2)
{
int v2; // ebx
unsigned int v3; // er12
const char *v4; // rdi

v2 = *(char *)(a1 + 1);
v3 = *(char *)(a1 + 2);
v4 = "K-2";
if ( !v2 )
v4 = "K-1";
func9(v4, 0LL, a2);
return printf("Knob %hhd value: %03hhd\n", (unsigned int)(v2 + 1), v3);
}

original_code:
void print_knobmsg(char *msg, PortMidiStream *midi) {
  int
    knob = msg[1],
    value = msg[2];
  native_ledmsg((knob ? "K-2" : "K-1"), 0, midi);
  printf("Knob %hhd value: %03hhd\n", knob +1, value);
  return;
}

canonical_original_code:
void print_knobmsg(char *msg, void *midi) {
  int knob = msg[1]; int value = msg[2];
  native_ledmsg((knob ? "K-2" : "K-1"), 0, midi);
  printf("Knob %hhd value: %03hhd\n", knob +1, value);
  return;
}

variable_types:
midi
void *

variable_types: knob int

variable_types: value int


decompiled_code:
int __fastcall print_encodermsg(__int64 a1, __int64 a2)
{
int result; // eax

if ( *(_BYTE *)(a1 + 2) >> 1 )
{
native_ledmsg("dec", 0LL, a2);
result = printf("Encoder %s\n", "decrement");
}
else
{
native_ledmsg("inc", 0LL, a2);
result = printf("Encoder %s\n", "increment");
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, __int64 a2)
{
int result; // eax

if ( *(_BYTE *)(a1 + 2) >> 1 )
{
func9("dec", 0LL, a2);
result = printf("Encoder %s\n", "decrement");
}
else
{
func9("inc", 0LL, a2);
result = printf("Encoder %s\n", "increment");
}
return result;
}

original_code:
void print_encodermsg(char *msg, PortMidiStream *midi) {
  int dec=msg[2]>>1;
  native_ledmsg((dec ? "dec" : "inc"), 0, midi);
  printf("Encoder %s\n", (dec ? "decrement" : "increment"));
  return;
}

canonical_original_code:
void print_encodermsg(char *msg, void *midi) {
  int dec = msg[2]>>1;
  native_ledmsg((dec ? "dec" : "inc"), 0, midi);
  printf("Encoder %s\n", (dec ? "decrement" : "increment"));
  return;
}

variable_types: dec int


decompiled_code:
int __fastcall print_xymsg(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // er12

v2 = *(char *)(a1 + 1);
v3 = *(char *)(a1 + 2);
native_ledmsg("pad", 1LL, a2);
return printf("X: %03hhd Y: %03hhd\n", v2, v3);
}

canonical_decompiled_code:
int __fastcall func17(__int64 a1, __int64 a2)
{
unsigned int v2; // ebp
unsigned int v3; // er12

v2 = *(char *)(a1 + 1);
v3 = *(char *)(a1 + 2);
func9("pad", 1LL, a2);
return printf("X: %03hhd Y: %03hhd\n", v2, v3);
}

original_code:
void print_xymsg(char *msg, PortMidiStream *midi) {
  int
    x = msg[1],
    y = msg[2];
  native_ledmsg("pad", 1, midi);
  printf("X: %03hhd Y: %03hhd\n", x, y);
  return;
}

canonical_original_code:
void print_xymsg(char *msg, void *midi) {
  int x = msg[1]; int y = msg[2];
  native_ledmsg("pad", 1, midi);
  printf("X: %03hhd Y: %03hhd\n", x, y);
  return;
}

variable_types:
msg
char *

variable_types: x int

variable_types: y int


decompiled_code:
int __fastcall print_unknownmsg(char *a1)
{
return printf(
"Unknown command: 0x%02hhx(0x%02hhx, 0x%02hhx)\n",
(unsigned int)*a1,
(unsigned int)a1[1],
(unsigned int)a1[2]);
}

canonical_decompiled_code:
int __fastcall func18(char *a1)
{
return printf(
"Unknown command: 0x%02hhx(0x%02hhx, 0x%02hhx)\n",
(unsigned int)*a1,
(unsigned int)a1[1],
(unsigned int)a1[2]);
}

original_code:
void print_unknownmsg(char *msg) {
  printf("Unknown command: 0x%02hhx(0x%02hhx, 0x%02hhx)\n", msg[0], msg[1], msg[2]);
  return;
}