decompiled_code:
const char *__fastcall token_to_string(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "T_UNDEF";
break;
case 1:
result = "T_VAR";
break;
case 2:
result = "T_PROC";
break;
case 3:
result = "T_FUNC";
break;
case 4:
result = "T_INT";
break;
case 5:
result = "T_LABEL";
break;
case 6:
result = "T_REAL";
break;
case 7:
result = "T_ARRAY";
break;
case 8:
result = "T_STRING";
break;
case 9:
result = "T_BOOL";
break;
case 10:
result = "T_SPECIAL";
break;
case 11:
result = "T_PROGRAM";
break;
case 12:
result = "T_NOT_LOCAL";
break;
case 13:
result = "T_PARAM";
break;
case 14:
result = "T_ARG";
break;
case 15:
result = "T_LOCAL";
break;
case 16:
result = "T_FILE";
break;
case 17:
result = "T_CONSTANT";
break;
case 18:
result = "T_SELF";
break;
case 19:
result = "T_TEMP";
break;
case 20:
result = "T_RETURN";
break;
default:
result = "ERROR NO TYPE";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 0:
result = "T_UNDEF";
break;
case 1:
result = "T_VAR";
break;
case 2:
result = "T_PROC";
break;
case 3:
result = "T_FUNC";
break;
case 4:
result = "T_INT";
break;
case 5:
result = "T_LABEL";
break;
case 6:
result = "T_REAL";
break;
case 7:
result = "T_ARRAY";
break;
case 8:
result = "T_STRING";
break;
case 9:
result = "T_BOOL";
break;
case 10:
result = "T_SPECIAL";
break;
case 11:
result = "T_PROGRAM";
break;
case 12:
result = "T_NOT_LOCAL";
break;
case 13:
result = "T_PARAM";
break;
case 14:
result = "T_ARG";
break;
case 15:
result = "T_LOCAL";
break;
case 16:
result = "T_FILE";
break;
case 17:
result = "T_CONSTANT";
break;
case 18:
result = "T_SELF";
break;
case 19:
result = "T_TEMP";
break;
case 20:
result = "T_RETURN";
break;
default:
result = "ERROR NO TYPE";
break;
}
return result;
}

original_code:
char *token_to_string(int token){
  switch (token){
  case 0:
    return "T_UNDEF";
  case 1:
    return "T_VAR";
  case 2:
    return "T_PROC";
  case 3:
    return "T_FUNC";
  case 4:
    return "T_INT";
  case 5:
    return "T_LABEL";
  case 6:
    return "T_REAL";
  case 7:
    return "T_ARRAY";
  case 8:
    return "T_STRING";
  case 9:
    return "T_BOOL";
  case 10:
    return "T_SPECIAL";
  case 11:
    return "T_PROGRAM";
  case 12:
    return "T_NOT_LOCAL";
  case 13:
    return "T_PARAM";
  case 14:
    return "T_ARG";
  case 15:
    return "T_LOCAL";
  case 16:
    return "T_FILE";
  case 17:
    return "T_CONSTANT";
  case 18:
    return "T_SELF";
  case 19:
    return "T_TEMP";
  case 20:
    return "T_RETURN";
  default:
    return "ERROR NO TYPE";
  }
}

variable_types: token int

return_type: char *


hash

repo: mikestaub/Pascal-Compiler

original_code:
int hash(char *s){
  int hval = 0;
  int i;
  for(i = 0; s[i] != '\0'; i++){
    int v = (hval >> 28) ^ (s[i] & 0xf);
    hval = (hval << 4) | v;
  }
  hval = hval & 0x7fffffff;
  return hval % 997;
}

variable_types:
s
char *

variable_types: hval int

variable_types: i int

variable_types: v int

return_type: int


decompiled_code:
__int64 get_dim()
{
return dim_p;
}

canonical_decompiled_code:
__int64 func3()
{
return dim_p;
}

original_code:
DIM_TYPE *get_dim(void){
  DIM_TYPE *dimp_p = (DIM_TYPE*)malloc(sizeof(DIM_TYPE));
  return dim_p;
}

canonical_original_code:
struct dim_type *get_dim(){
  struct dim_type *dimp_p = (DIM_TYPE*)malloc(sizeof(DIM_TYPE));
  return dim_p;
}

variable_types: struct dim_type { struct dim_type *next; struct dim_type *prev; int high; int low; int dimension; int n; int node_elements; } *


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

result = mktable(0LL);
constant_symbol_table = result;
return result;
}

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

result = func5(0LL);
constant_symbol_table = result;
return result;
}

original_code:
void init_constant_table(void){
  constant_symbol_table = mktable(((void *)0));
}

canonical_original_code:
void init_constant_table(){
  constant_symbol_table = mktable(((void *)0));
}

return_type: void


original_code:
int calculate_c(DIM_TYPE *dim_list, int w){
  int c;
  int base = 1000;
  int rest;
  int part1, part2;
  int term, final_term = 1;
  DIM_TYPE *temp = dim_list;
  while(temp->next != ((void *)0))
    temp = temp->next;
  if(temp->prev == ((void *)0)){
    rest = temp->low * w;
    c = rest;
    return c;
  }
  while(temp->prev != ((void *)0)){
    part1 = temp->low * temp->prev->node_elements + temp->prev->low;
    if(temp->prev->prev != ((void *)0))
      part2 = temp->prev->prev->node_elements + temp->prev->prev->low;
    else
      part2 = 1;
    term = part1 * part2;
    final_term = final_term * term;
    temp = temp->prev;
  }
  rest = final_term * w;
  c = rest;
  return c;
}

canonical_original_code:
int calculate_c(struct dim_type *dim_list, int w){
  int c;
  int base = 1000;
  int rest;
  int part1; int part2;
  int term; int final_term = 1;
  struct dim_type *temp = dim_list;
  while(temp->next != ((void *)0))
    temp = temp->next;
  if(temp->prev == ((void *)0)){
    rest = temp->low * w;
    c = rest;
    return c;
  }
  while(temp->prev != ((void *)0)){
    part1 = temp->low * temp->prev->node_elements + temp->prev->low;
    if(temp->prev->prev != ((void *)0))
      part2 = temp->prev->prev->node_elements + temp->prev->prev->low;
    else
      part2 = 1;
    term = part1 * part2;
    final_term = final_term * term;
    temp = temp->prev;
  }
  rest = final_term * w;
  c = rest;
  return c;
}

variable_types: w int

variable_types: c int

variable_types: base int

variable_types: rest int

variable_types: term int

user_defined_types: struct dim_type { struct dim_type *next; struct dim_type *prev; int high; int low; int dimension; int n; int node_elements; }


repo: mikeyhc/scout

decompiled_code:
void load_ifaddrs()
{
if ( !ifaddr && getifaddrs(&ifaddr) == -1 )
{
perror("getifaddrs");
exit(1);
}
}

canonical_decompiled_code:
void func3()
{
if ( !ifaddr && getifaddrs(&ifaddr) == -1 )
{
perror("getifaddrs");
exit(1);
}
}

original_code:
static void load_ifaddrs(void)
{
 if(ifaddr!=((void *)0))
  return;
 if(getifaddrs(&ifaddr)==-1){
  perror("getifaddrs");
  exit(1);
 }
}

canonical_original_code:
static void load_ifaddrs()
{
 if(ifaddr!=((void *)0))
  return;
 if(getifaddrs(&ifaddr)==-1){
  perror("getifaddrs");
  exit(1);
 }
}


decompiled_code:
void map_local_network()
{
struct ifaddrs *i; // rbx
const char *v1; // rax
const char *v2; // rax
__int64 j; // rax
int v4; // eax
struct sockaddr *v5; // rsi
struct sockaddr *v6; // rcx
__int64 v7; // r12
__int64 v8; // rax
int v9; // eax
const char *v10; // rax
const char *v11; // rax
int v12; // eax
sa_family_t *v13; // rax
sa_family_t v14; // r13
const char *v15; // rcx
socklen_t v16; // er14
int v17; // eax
int v18; // eax
__int64 v19; // r12
struct sockaddr v20; // [rsp+0h] [rbp-10A8h] BYREF
struct sockaddr v21; // [rsp+10h] [rbp-1098h] BYREF
struct sockaddr sa; // [rsp+20h] [rbp-1088h] BYREF
char v23[1040]; // [rsp+30h] [rbp-1078h] BYREF
char host[1040]; // [rsp+440h] [rbp-C68h] BYREF
char v25[1040]; // [rsp+850h] [rbp-858h] BYREF
char v26[1096]; // [rsp+C60h] [rbp-448h] BYREF

load_ifaddrs();
for ( i = ifaddr; i; i = i->ifa_next )
{
v13 = &i->ifa_addr->sa_family;
if ( v13 )
{
v14 = *v13;
if ( (*v13 & 0xFFF7) == 2 )
{
if ( strcmp(i->ifa_name, "lo") )
{
if ( v14 == 2 )
{
printf("\nusing:\n%s address family: %d%s\n", i->ifa_name, 2LL, " (AF_INET)");
v16 = 16;
}
else
{
v15 = " (AF_INET6)";
if ( v14 != 10 )
v15 = " (UNKNOWN)";
printf("\nusing:\n%s address family: %d%s\n", i->ifa_name, v14, v15);
v16 = 28;
}
v17 = getnameinfo(i->ifa_addr, v16, v26, 0x401u, 0LL, 0, 1);
if ( v17 )
{
v1 = gai_strerror(v17);
printf("getnameinfo() failed: %s\n", v1);
exit(1);
}
printf("\taddress: <%s>\n", v26);
v18 = getnameinfo(i->ifa_netmask, v16, v25, 0x401u, 0LL, 0, 1);
if ( v18 )
{
v2 = gai_strerror(v18);
printf("getnameinfo() failed: %s\n", v2);
exit(1);
}
printf("\tnetmask: <%s>\n", v25);
v19 = 16LL;
if ( v14 != 2 )
v19 = 28LL;
for ( j = 0LL; j != v19; ++j )
sa.sa_data[j] = i->ifa_netmask->sa_data[(int)j] & i->ifa_addr->sa_data[(int)j];
sa.sa_family = v14;
v4 = getnameinfo(&sa, v16, host, 0x401u, 0LL, 0, 1);
if ( v4 )
{
v10 = gai_strerror(v4);
printf("getnameinfo() failed: %s\n", v10);
exit(1);
}
printf("\tnetwork: <%s>\n", host);
v5 = i->ifa_addr;
v6 = i->ifa_netmask;
v7 = v19 + 2;
v8 = 2LL;
do
{
*((_BYTE *)&v21.sa_family + v8) = *((_BYTE *)&v5->sa_family + v8) | ~*((_BYTE *)&v6->sa_family + v8);
++v8;
}
while ( v7 != v8 );
v21.sa_family = v14;
v9 = getnameinfo(&v21, v16, v23, 0x401u, 0LL, 0, 1);
if ( v9 )
{
v11 = gai_strerror(v9);
printf("getnameinfo() failed: %s\n", v11);
exit(1);
}
printf("\tbroadcast: <%s>\n", v23);
sockaddrcpy((__int64)&v20, &sa, v14);
increase_sockaddr(&v20, v14, 1);
while ( (int)compare_sockaddr((__int64)&v21, (__int64)&v20, v14) < 0 )
{
v12 = testping((__int64)i->ifa_addr, &v20);
if ( v12 > 0 )
{
printf(
"response from: %d.%d.%d.%d\n",
(unsigned __int8)v20.sa_data[2],
(unsigned __int8)v20.sa_data[3],
(unsigned __int8)v20.sa_data[4],
(unsigned __int8)v20.sa_data[5]);
}
else if ( v12 < 0 )
{
perror("error with ping");
break;
}
increase_sockaddr(&v20, v14, 1);
}
}
}
}
}
}

canonical_decompiled_code:
void func6()
{
struct ifaddrs *i; // rbx
const char *v1; // rax
const char *v2; // rax
__int64 j; // rax
int v4; // eax
struct sockaddr *v5; // rsi
struct sockaddr *v6; // rcx
__int64 v7; // r12
__int64 v8; // rax
int v9; // eax
const char *v10; // rax
const char *v11; // rax
int v12; // eax
sa_family_t *v13; // rax
sa_family_t v14; // r13
const char *v15; // rcx
socklen_t v16; // er14
int v17; // eax
int v18; // eax
__int64 v19; // r12
struct sockaddr v20; // [rsp+0h] [rbp-10A8h] BYREF
struct sockaddr v21; // [rsp+10h] [rbp-1098h] BYREF
struct sockaddr sa; // [rsp+20h] [rbp-1088h] BYREF
char v23[1040]; // [rsp+30h] [rbp-1078h] BYREF
char host[1040]; // [rsp+440h] [rbp-C68h] BYREF
char v25[1040]; // [rsp+850h] [rbp-858h] BYREF
char v26[1096]; // [rsp+C60h] [rbp-448h] BYREF

func3();
for ( i = ifaddr; i; i = i->ifa_next )
{
v13 = &i->ifa_addr->sa_family;
if ( v13 )
{
v14 = *v13;
if ( (*v13 & 0xFFF7) == 2 )
{
if ( strcmp(i->ifa_name, "lo") )
{
if ( v14 == 2 )
{
printf("\nusing:\n%s address family: %d%s\n", i->ifa_name, 2LL, " (AF_INET)");
v16 = 16;
}
else
{
v15 = " (AF_INET6)";
if ( v14 != 10 )
v15 = " (UNKNOWN)";
printf("\nusing:\n%s address family: %d%s\n", i->ifa_name, v14, v15);
v16 = 28;
}
v17 = getnameinfo(i->ifa_addr, v16, v26, 0x401u, 0LL, 0, 1);
if ( v17 )
{
v1 = gai_strerror(v17);
printf("getnameinfo() failed: %s\n", v1);
exit(1);
}
printf("\taddress: <%s>\n", v26);
v18 = getnameinfo(i->ifa_netmask, v16, v25, 0x401u, 0LL, 0, 1);
if ( v18 )
{
v2 = gai_strerror(v18);
printf("getnameinfo() failed: %s\n", v2);
exit(1);
}
printf("\tnetmask: <%s>\n", v25);
v19 = 16LL;
if ( v14 != 2 )
v19 = 28LL;
for ( j = 0LL; j != v19; ++j )
sa.sa_data[j] = i->ifa_netmask->sa_data[(int)j] & i->ifa_addr->sa_data[(int)j];
sa.sa_family = v14;
v4 = getnameinfo(&sa, v16, host, 0x401u, 0LL, 0, 1);
if ( v4 )
{
v10 = gai_strerror(v4);
printf("getnameinfo() failed: %s\n", v10);
exit(1);
}
printf("\tnetwork: <%s>\n", host);
v5 = i->ifa_addr;
v6 = i->ifa_netmask;
v7 = v19 + 2;
v8 = 2LL;
do
{
*((_BYTE *)&v21.sa_family + v8) = *((_BYTE *)&v5->sa_family + v8) | ~*((_BYTE *)&v6->sa_family + v8);
++v8;
}
while ( v7 != v8 );
v21.sa_family = v14;
v9 = getnameinfo(&v21, v16, v23, 0x401u, 0LL, 0, 1);
if ( v9 )
{
v11 = gai_strerror(v9);
printf("getnameinfo() failed: %s\n", v11);
exit(1);
}
printf("\tbroadcast: <%s>\n", v23);
func0((__int64)&v20, &sa, v14);
func2(&v20, v14, 1);
while ( (int)func1((__int64)&v21, (__int64)&v20, v14) < 0 )
{
v12 = func5((__int64)i->ifa_addr, &v20);
if ( v12 > 0 )
{
printf(
"response from: %d.%d.%d.%d\n",
(unsigned __int8)v20.sa_data[2],
(unsigned __int8)v20.sa_data[3],
(unsigned __int8)v20.sa_data[4],
(unsigned __int8)v20.sa_data[5]);
}
else if ( v12 < 0 )
{
perror("error with ping");
break;
}
func2(&v20, v14, 1);
}
}
}
}
}
}

original_code:
void
map_local_network(void)
{
 struct ifaddrs *ifa;
 int family, s, i, j, t;
 char host[1025], mask[1025], network[1025],
    broadcast[1025], host_temp[1025];
 struct sockaddr net, broad, sa_temp;
 load_ifaddrs();
 for(ifa = ifaddr; ifa != ((void *)0); ifa = ifa->ifa_next){
  if(ifa->ifa_addr==((void *)0)) continue;
  family = ifa->ifa_addr->sa_family;
  if(family != 2 && family != 10) continue;
                if(!strcmp(ifa->ifa_name, "lo")) continue;
  printf("\nusing:\n%s address family: %d%s\n",
   ifa->ifa_name, family, (family == 2) ?
   " (AF_INET)" : (family == 10) ?
   " (AF_INET6)" : " (UNKNOWN)");
  s = getnameinfo(ifa->ifa_addr, (family == 2) ?
   sizeof(struct sockaddr_in) :
   sizeof(struct sockaddr_in6),
   host, 1025, ((void *)0), 0, 1);
  if(s!=0){
   printf("getnameinfo() failed: %s\n",
     gai_strerror(s));
   exit(1);
  }
  printf("\taddress:   <%s>\n", host);
  s = getnameinfo(ifa->ifa_netmask, (family == 2) ?
   sizeof(struct sockaddr_in) :
   sizeof(struct sockaddr_in6),
   mask, 1025, ((void *)0), 0 , 1);
  if(s!=0){
   printf("getnameinfo() failed: %s\n",
     gai_strerror(s));
   exit(1);
  }
  printf("\tnetmask:   <%s>\n", mask);
  for(i=0; i<(family == 2 ?
    sizeof(struct sockaddr_in) :
    sizeof(struct sockaddr_in6)); i++)
   net.sa_data[i] = ifa->ifa_addr->sa_data[i] &
     ifa->ifa_netmask->sa_data[i];
  net.sa_family = family;
  s = getnameinfo(&net, (family == 2) ?
    sizeof(struct sockaddr_in) :
    sizeof(struct sockaddr_in6), network,
    1025, ((void *)0), 0, 1);
  if(s!=0){
   printf("getnameinfo() failed: %s\n",
     gai_strerror(s));
   exit(1);
  }
  printf("\tnetwork:   <%s>\n", network);
  for(i=0; i<(family == 2 ?
    sizeof(struct sockaddr_in) :
    sizeof(struct sockaddr_in6)); i++)
   broad.sa_data[i] = (ifa->ifa_addr->sa_data[i] &
     ifa->ifa_netmask->sa_data[i]) |
     ~ifa->ifa_netmask->sa_data[i];
  broad.sa_family = family;
  s = getnameinfo(&broad, (family == 2) ?
    sizeof(struct sockaddr_in) :
    sizeof(struct sockaddr_in6), broadcast,
    1025, ((void *)0), 0, 1);
  if(s!=0){
   printf("getnameinfo() failed: %s\n",
     gai_strerror(s));
   exit(1);
  }
  printf("\tbroadcast: <%s>\n", broadcast);
  sockaddrcpy(&sa_temp, &net, family);
  increase_sockaddr(&sa_temp, family, 1);
  while(compare_sockaddr(&broad, &sa_temp, family)<0){
   if((t = testping(ifa->ifa_addr, &sa_temp)) > 0)
    printf("response from: %d.%d.%d.%d\n",
      sa_temp.sa_data[2] & 0xFF,
      sa_temp.sa_data[3] & 0xFF,
      sa_temp.sa_data[4] & 0xFF,
      sa_temp.sa_data[5] & 0xFF);
   else if(t < 0){
    perror("error with ping");
    break;
   }
   increase_sockaddr(&sa_temp, family, 1);
  }
 }
}

canonical_original_code:
void map_local_network()
{
 struct ifaddrs *ifa;
 int family; int s; int i; int j; int t;
 char host[1025]; char mask[1025]; char network[1025]; char broadcast[1025]; char host_temp[1025];
 struct sockaddr net; struct sockaddr broad; struct sockaddr sa_temp;
 load_ifaddrs();
 for(ifa = ifaddr; ifa != ((void *)0); ifa = ifa->ifa_next){
  if(ifa->ifa_addr==((void *)0)) continue;
  family = ifa->ifa_addr->sa_family;
  if(family != 2 && family != 10) continue;
                if(!strcmp(ifa->ifa_name, "lo")) continue;
  printf("\nusing:\n%s address family: %d%s\n",
   ifa->ifa_name, family, (family == 2) ?
   " (AF_INET)" : (family == 10) ?
   " (AF_INET6)" : " (UNKNOWN)");
  s = getnameinfo(ifa->ifa_addr, (family == 2) ?
   sizeof(struct sockaddr_in) :
   sizeof(struct sockaddr_in6),
   host, 1025, ((void *)0), 0, 1);
  if(s!=0){
   printf("getnameinfo() failed: %s\n",
     gai_strerror(s));
   exit(1);
  }
  printf("\taddress:   <%s>\n", host);
  s = getnameinfo(ifa->ifa_netmask, (family == 2) ?
   sizeof(struct sockaddr_in) :
   sizeof(struct sockaddr_in6),
   mask, 1025, ((void *)0), 0 , 1);
  if(s!=0){
   printf("getnameinfo() failed: %s\n",
     gai_strerror(s));
   exit(1);
  }
  printf("\tnetmask:   <%s>\n", mask);
  for(i=0; i<(family == 2 ?
    sizeof(struct sockaddr_in) :
    sizeof(struct sockaddr_in6)); i++)
   net.sa_data[i] = ifa->ifa_addr->sa_data[i] &
     ifa->ifa_netmask->sa_data[i];
  net.sa_family = family;
  s = getnameinfo(&net, (family == 2) ?
    sizeof(struct sockaddr_in) :
    sizeof(struct sockaddr_in6), network,
    1025, ((void *)0), 0, 1);
  if(s!=0){
   printf("getnameinfo() failed: %s\n",
     gai_strerror(s));
   exit(1);
  }
  printf("\tnetwork:   <%s>\n", network);
  for(i=0; i<(family == 2 ?
    sizeof(struct sockaddr_in) :
    sizeof(struct sockaddr_in6)); i++)
   broad.sa_data[i] = (ifa->ifa_addr->sa_data[i] &
     ifa->ifa_netmask->sa_data[i]) |
     ~ifa->ifa_netmask->sa_data[i];
  broad.sa_family = family;
  s = getnameinfo(&broad, (family == 2) ?
    sizeof(struct sockaddr_in) :
    sizeof(struct sockaddr_in6), broadcast,
    1025, ((void *)0), 0, 1);
  if(s!=0){
   printf("getnameinfo() failed: %s\n",
     gai_strerror(s));
   exit(1);
  }
  printf("\tbroadcast: <%s>\n", broadcast);
  sockaddrcpy(&sa_temp, &net, family);
  increase_sockaddr(&sa_temp, family, 1);
  while(compare_sockaddr(&broad, &sa_temp, family)<0){
   if((t = testping(ifa->ifa_addr, &sa_temp)) > 0)
    printf("response from: %d.%d.%d.%d\n",
      sa_temp.sa_data[2] & 0xFF,
      sa_temp.sa_data[3] & 0xFF,
      sa_temp.sa_data[4] & 0xFF,
      sa_temp.sa_data[5] & 0xFF);
   else if(t < 0){
    perror("error with ping");
    break;
   }
   increase_sockaddr(&sa_temp, family, 1);
  }
 }
}

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types: family int

variable_types: s int

variable_types: j int

variable_types: t int

variable_types:
host
char [1025]

variable_types:
mask
char [1025]

variable_types:
network
char [1025]

variable_types:
broadcast
char [1025]

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


main

canonical_name: main

repo: mikkeloscar/python-cubieleds

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // edx
int result; // eax
__int64 v5; // rbx
int i; // ebp
__int64 v7; // rbx
int j; // ebx
char v9[1024]; // [rsp+0h] [rbp-438h] BYREF
__int64 v10; // [rsp+400h] [rbp-38h] BYREF
int v11; // [rsp+408h] [rbp-30h]
__int64 v12; // [rsp+410h] [rbp-28h]
int v13; // [rsp+418h] [rbp-20h]

v3 = leds_init(&v10, argv, envp);
result = 1;
if ( v3 >= 0 )
{
if ( v13 > 0 )
{
v5 = 0LL;
for ( i = 0; i < v13; ++i )
{
puts(*(const char **)(v12 + v5));
puts((const char *)(v12 + v5 + 8));
puts((const char *)(v12 + v5 + 4104));
v5 += 8200LL;
}
}
printf("triggers: %d\n", (unsigned int)v11);
if ( v11 > 0 )
{
v7 = 0LL;
do
{
printf("%d: %s\n", (unsigned int)v7, *(const char **)(v10 + 8 * v7));
++v7;
}
while ( v11 > (int)v7 );
}
for ( j = 0; j != 20; ++j )
{
if ( (j & 1) != 0 )
{
leds_off(&v10, "blue");
leds_on(&v10, "green");
}
else
{
leds_on(&v10, "blue");
leds_off(&v10, "green");
}
usleep(0x186A0u);
}
leds_off(&v10, "blue");
leds_off(&v10, "green");
leds_trigger(&v10, "blue", "usb-online");
leds_trigger_status(&v10, "blue", v9);
printf("trigger: %s\n", v9);
result = 0;
}
return result;
}

original_code:
int main()
{
    struct leds_t leds;
    if (leds_init(&leds) < 0)
        return 1;
    for (int i = 0; i < leds.num_leds; i++) {
        printf("%s\n", leds.leds[i].color);
        printf("%s\n", leds.leds[i].b_dev);
        printf("%s\n", leds.leds[i].t_dev);
    }
    printf("triggers: %d\n", leds.num_triggers);
    for (int i = 0; i < leds.num_triggers; i++) {
        printf("%d: %s\n", i, leds.triggers[i]);
    }
    for (int i=0; i < 20; i++) {
        if (i % 2 == 0) {
            leds_on(&leds, "blue");
            leds_off(&leds, "green");
        } else {
            leds_off(&leds, "blue");
            leds_on(&leds, "green");
        }
        usleep(1000*100);
    }
    leds_off(&leds, "blue");
    leds_off(&leds, "green");
    leds_trigger(&leds, "blue", "usb-online");
    char trigger[1024];
    leds_trigger_status(&leds, "blue", trigger);
    printf("trigger: %s\n", trigger);
    return 0;
}

canonical_original_code:
int main()
{
    struct leds_t leds;
    if (leds_init(&leds) < 0)
        return 1;
    for (int i = 0; i < leds.num_leds; i++) {
        printf("%s\n", leds.leds[i].color);
        printf("%s\n", leds.leds[i].b_dev);
        printf("%s\n", leds.leds[i].t_dev);
    }
    printf("triggers: %d\n", leds.num_triggers);
    for (int i = 0; i < leds.num_triggers; i++) {
        printf("%d: %s\n", i, leds.triggers[i]);
    }
    for (int i = 0; i < 20; i++) {
        if (i % 2 == 0) {
            leds_on(&leds, "blue");
            leds_off(&leds, "green");
        } else {
            leds_off(&leds, "blue");
            leds_on(&leds, "green");
        }
        usleep(1000*100);
    }
    leds_off(&leds, "blue");
    leds_off(&leds, "green");
    leds_trigger(&leds, "blue", "usb-online");
    char trigger[1024];
    leds_trigger_status(&leds, "blue", trigger);
    printf("trigger: %s\n", trigger);
    return 0;
}

variable_types: struct leds_t { char **triggers; int num_triggers; struct led_t { char *color; char b_dev[4096]; char t_dev[4096]; } *leds; int num_leds; }

variable_types: i int

variable_types:
trigger
char [1024]

user_defined_types: struct leds_t { char **triggers; int num_triggers; struct led_t *leds; int num_leds; }


decompiled_code:
__int64 __fastcall get_trigger(const char *a1, char *a2)
{
int v2; // eax
int v3; // ebx
__int64 result; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
{
warn("failed to open to read from LED %s", a1);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
if ( read(v2, v5, 0x400uLL) < 0 )
err(1, "failed to read %s", a1);
strncpy(a2, v5, 0x400uLL);
close(v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, char *a2)
{
int v2; // eax
int v3; // ebx
__int64 result; // rax
char v5[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
{
warn("failed to open to read from LED %s", a1);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
if ( read(v2, v5, 0x400uLL) < 0 )
err(1, "failed to read %s", a1);
strncpy(a2, v5, 0x400uLL);
close(v3);
result = 0LL;
}
return result;
}

original_code:
static int get_trigger(filepath_t path, char *value)
{
    int fd = open(path, 00);
    if (fd < 0) {
        warn("failed to open to read from LED %s", path);
        return -1;
    }
    char buf[1024];
    if (read(fd, buf, 1024) < 0)
        err(1, "failed to read %s", path);
    strncpy(value, buf, 1024);
    close(fd);
    return 0;
}

canonical_original_code:
static int get_trigger(char path[4096], char *value)
{
    int fd = open(path, 00);
    if (fd < 0) {
        warn("failed to open to read from LED %s", path);
        return -1;
    }
    char buf[1024];
    if (read(fd, buf, 1024) < 0)
        err(1, "failed to read %s", path);
    strncpy(value, buf, 1024);
    close(fd);
    return 0;
}

variable_types:
path
char [4096]

variable_types:
value
char *

variable_types: fd int

variable_types:
buf
char [1024]


set

decompiled_code:
__int64 __fastcall set(const char *a1, __int64 a2)
{
int v2; // eax
int v3; // ebx
int v4; // eax
__int64 result; // rax
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = open(a1, 1);
if ( v2 < 0 )
{
warn("failed to open to write to LED %s", a1);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
v4 = snprintf(v6, 0x400uLL, "%ld", a2);
if ( write(v3, v6, v4) < 0 )
err(1, "failed to set LED");
close(v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, __int64 a2)
{
int v2; // eax
int v3; // ebx
int v4; // eax
__int64 result; // rax
char v6[1048]; // [rsp+0h] [rbp-418h] BYREF

v2 = open(a1, 1);
if ( v2 < 0 )
{
warn("failed to open to write to LED %s", a1);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
v4 = snprintf(v6, 0x400uLL, "%ld", a2);
if ( write(v3, v6, v4) < 0 )
err(1, "failed to set LED");
close(v3);
result = 0LL;
}
return result;
}

original_code:
static int set(filepath_t path, long value)
{
    int fd = open(path, 01);
    if (fd < 0) {
        warn("failed to open to write to LED %s", path);
        return -1;
    }
    char buf[1024];
    int len = snprintf(buf, 1024, "%ld", value);
    if (write(fd, buf, len) < 0)
        err(1, "failed to set LED");
    close(fd);
    return 0;
}

canonical_original_code:
static int set(char path[4096], long value)
{
    int fd = open(path, 01);
    if (fd < 0) {
        warn("failed to open to write to LED %s", path);
        return -1;
    }
    char buf[1024];
    int len = snprintf(buf, 1024, "%ld", value);
    if (write(fd, buf, len) < 0)
        err(1, "failed to set LED");
    close(fd);
    return 0;
}

variable_types: value long

variable_types: len int


decompiled_code:
__int64 __fastcall set_trigger(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebx
size_t v4; // rax
__int64 result; // rax

v2 = open(a1, 1);
if ( v2 < 0 )
{
warn("failed to open to write to LED %s", a1);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
v4 = strlen(a2);
if ( write(v3, a2, v4) < 0 )
err(1, "failed to set LED");
close(v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebx
size_t v4; // rax
__int64 result; // rax

v2 = open(a1, 1);
if ( v2 < 0 )
{
warn("failed to open to write to LED %s", a1);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
v4 = strlen(a2);
if ( write(v3, a2, v4) < 0 )
err(1, "failed to set LED");
close(v3);
result = 0LL;
}
return result;
}

original_code:
static int set_trigger(filepath_t path, const char *value)
{
    int fd = open(path, 01);
    if (fd < 0) {
        warn("failed to open to write to LED %s", path);
        return -1;
    }
    if (write(fd, value, strlen(value)) < 0)
        err(1, "failed to set LED");
    close(fd);
    return 0;
}

canonical_original_code:
static int set_trigger(char path[4096], char *value)
{
    int fd = open(path, 01);
    if (fd < 0) {
        warn("failed to open to write to LED %s", path);
        return -1;
    }
    if (write(fd, value, strlen(value)) < 0)
        err(1, "failed to set LED");
    close(fd);
    return 0;
}


decompiled_code:
__int64 __fastcall leds_status(__int64 a1, const char *a2)
{
const char **v2; // rax
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v2 = get_led(a1, a2);
if ( v2 )
{
v4 = 0LL;
result = get((const char *)v2 + 8, &v4);
if ( !(_DWORD)result )
result = v4 > 0;
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2)
{
const char **v2; // rax
__int64 result; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v2 = func0(a1, a2);
if ( v2 )
{
v4 = 0LL;
result = func4((const char *)v2 + 8, &v4);
if ( !(_DWORD)result )
result = v4 > 0;
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int leds_status(struct leds_t *l, const char *color)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    long value = 0;
    int res = 0;
    int rc = get(led->b_dev, &value);
    if (value > 0) res = 1;
    return rc ? rc : res;
}

canonical_original_code:
int leds_status(struct leds_t *l, char *color)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    long value = 0;
    int res = 0;
    int rc = get(led->b_dev, &value);
    if (value > 0) res = 1;
    return rc ? rc : res;
}

variable_types: struct leds_t { char **triggers; int num_triggers; struct led_t { char *color; char b_dev[4096]; char t_dev[4096]; } *leds; int num_leds; } *

variable_types:
color
char *

variable_types: res int

variable_types: rc int


decompiled_code:
__int64 __fastcall leds_on(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // rbx
int v4; // edx
__int64 result; // rax

v2 = get_led(a1, a2);
if ( v2 )
{
v3 = v2;
v4 = leds_status(a1, a2);
result = 1LL;
if ( !v4 )
result = set((const char *)v3 + 8, 1LL);
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // rbx
int v4; // edx
__int64 result; // rax

v2 = func0(a1, a2);
if ( v2 )
{
v3 = v2;
v4 = func8(a1, a2);
result = 1LL;
if ( !v4 )
result = func5((const char *)v3 + 8, 1LL);
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int leds_on(struct leds_t *l, const char *color)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    if (leds_status(l, color))
        return 1;
    return set(led->b_dev, 1);
}

canonical_original_code:
int leds_on(struct leds_t *l, char *color)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    if (leds_status(l, color))
        return 1;
    return set(led->b_dev, 1);
}

variable_types: struct led_t { char *color; char b_dev[4096]; char t_dev[4096]; } *


decompiled_code:
__int64 __fastcall leds_off(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // rbx
__int64 result; // rax

v2 = get_led(a1, a2);
if ( v2 )
{
v3 = v2;
result = leds_status(a1, a2);
if ( (_DWORD)result )
result = set((const char *)v3 + 8, 0LL);
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2)
{
const char **v2; // rax
const char **v3; // rbx
__int64 result; // rax

v2 = func0(a1, a2);
if ( v2 )
{
v3 = v2;
result = func8(a1, a2);
if ( (_DWORD)result )
result = func5((const char *)v3 + 8, 0LL);
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int leds_off(struct leds_t *l, const char *color)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    if (!leds_status(l, color))
        return 0;
    return set(led->b_dev, 0);
}

canonical_original_code:
int leds_off(struct leds_t *l, char *color)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    if (!leds_status(l, color))
        return 0;
    return set(led->b_dev, 0);
}

user_defined_types: struct led_t { char *color; char b_dev[4096]; char t_dev[4096]; }


decompiled_code:
__int64 __fastcall leds_trigger(__int64 a1, const char *a2, char *a3)
{
const char **v4; // rax
const char **v5; // rbx
__int64 result; // rax

v4 = get_led(a1, a2);
if ( v4 )
{
v5 = v4;
if ( (unsigned int)in_trigger_array(a3, a1) )
{
result = set_trigger((const char *)v5 + 4104, a3);
}
else
{
warn("incorrect trigger type");
result = 4294967294LL;
}
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const char *a2, char *a3)
{
const char **v4; // rax
const char **v5; // rbx
__int64 result; // rax

v4 = func0(a1, a2);
if ( v4 )
{
v5 = v4;
if ( (unsigned int)func1(a3, a1) )
{
result = func6((const char *)v5 + 4104, a3);
}
else
{
warn("incorrect trigger type");
result = 4294967294LL;
}
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int leds_trigger(struct leds_t *l, const char *color, const char *trigger)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    if (in_trigger_array(trigger, l))
        return set_trigger(led->t_dev, trigger);
    warn("incorrect trigger type");
    return -2;
}

canonical_original_code:
int leds_trigger(struct leds_t *l, char *color, char *trigger)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    if (in_trigger_array(trigger, l))
        return set_trigger(led->t_dev, trigger);
    warn("incorrect trigger type");
    return -2;
}

variable_types:
trigger
char *


decompiled_code:
__int64 __fastcall leds_trigger_status(__int64 a1, const char *a2, __int64 a3)
{
const char **v4; // rax
__int64 v5; // rax
int v6; // ecx
char v7; // dl
__int64 v8; // rax
char *v9; // rsi
int v10; // ecx
__int64 result; // rax
char v12; // [rsp+1h] [rbp-419h]
char v13[1048]; // [rsp+2h] [rbp-418h] BYREF

v4 = get_led(a1, a2);
if ( v4 )
{
if ( (int)get_trigger((const char *)v4 + 4104, v13) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v5 = 1LL;
if ( v13[0] == 91 )
{
v6 = 0;
}
else
{
do
v6 = v5++;
while ( *(&v12 + v5) != 91 );
}
v7 = v13[v6 + 1];
v8 = 1LL;
v9 = &v13[v6];
if ( v7 == 93 )
{
v10 = 0;
}
else
{
do
{
*(_BYTE *)(a3 + v8 - 1) = v7;
v10 = v8++;
v7 = v9[v8];
}
while ( v7 != 93 );
}
*(_BYTE *)(a3 + v10) = 0;
result = 0LL;
}
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2, __int64 a3)
{
const char **v4; // rax
__int64 v5; // rax
int v6; // ecx
char v7; // dl
__int64 v8; // rax
char *v9; // rsi
int v10; // ecx
__int64 result; // rax
char v12; // [rsp+1h] [rbp-419h]
char v13[1048]; // [rsp+2h] [rbp-418h] BYREF

v4 = func0(a1, a2);
if ( v4 )
{
if ( (int)func3((const char *)v4 + 4104, v13) < 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
v5 = 1LL;
if ( v13[0] == 91 )
{
v6 = 0;
}
else
{
do
v6 = v5++;
while ( *(&v12 + v5) != 91 );
}
v7 = v13[v6 + 1];
v8 = 1LL;
v9 = &v13[v6];
if ( v7 == 93 )
{
v10 = 0;
}
else
{
do
{
*(_BYTE *)(a3 + v8 - 1) = v7;
v10 = v8++;
v7 = v9[v8];
}
while ( v7 != 93 );
}
*(_BYTE *)(a3 + v10) = 0;
result = 0LL;
}
}
else
{
warn("%s LED not found", a2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int leds_trigger_status(struct leds_t *l, const char *color, char *status)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    char value[1024];
    int rc = get_trigger(led->t_dev, value);
    if (rc < 0)
        return -1;
    int i = 0;
    while (1) {
        if (value[i] == '[') {
            int j = 0;
            while (1) {
                i++;
                if (value[i] == ']') {
                    status[j] = '\0';
                    break;
                } else
                    status[j] = value[i];
                j++;
            }
            break;
        }
        i++;
    }
    return 0;
}

canonical_original_code:
int leds_trigger_status(struct leds_t *l, char *color, char *status)
{
    struct led_t *led;
    led = get_led(l, color);
    if (led == ((void *)0)) {
        warn("%s LED not found", color);
        return -1;
    }
    char value[1024];
    int rc = get_trigger(led->t_dev, value);
    if (rc < 0)
        return -1;
    int i = 0;
    while (1) {
        if (value[i] == '[') {
            int j = 0;
            while (1) {
                i++;
                if (value[i] == ']') {
                    status[j] = '\0';
                    break;
                } else
                    status[j] = value[i];
                j++;
            }
            break;
        }
        i++;
    }
    return 0;
}

variable_types:
status
char *

variable_types:
value
char [1024]

variable_types: j int


decompiled_code:
void *__fastcall thread2(void *a1)
{
const char *v1; // rax
const char *v2; // rax
__int64 v4; // [rsp+0h] [rbp-48h] BYREF
__int64 v5; // [rsp+8h] [rbp-40h]
__int64 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+18h] [rbp-30h]
__int64 v8; // [rsp+20h] [rbp-28h]
__int64 v9; // [rsp+28h] [rbp-20h]
__int16 v10; // [rsp+30h] [rbp-18h]

if ( pthread_setspecific(namekey, (const void *)(unsigned int)((_DWORD)threadnames + 45)) )
_assert_fail("0 == retval", "threads.c", 0x6Fu, "thread2");
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0;
gettimestring(&v4);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v4, v1, "thread2", 113LL);
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0;
gettimestring(&v4);
v2 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", (const char *)&v4, v2, "thread2", 122LL);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1)
{
const char *v1; // rax
const char *v2; // rax
__int64 v4; // [rsp+0h] [rbp-48h] BYREF
__int64 v5; // [rsp+8h] [rbp-40h]
__int64 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+18h] [rbp-30h]
__int64 v8; // [rsp+20h] [rbp-28h]
__int64 v9; // [rsp+28h] [rbp-20h]
__int16 v10; // [rsp+30h] [rbp-18h]

if ( pthread_setspecific(namekey, (const void *)(unsigned int)((_DWORD)threadnames + 45)) )
_assert_fail("0 == retval", "threads.c", 0x6Fu, "thread2");
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0;
gettimestring(&v4);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v4, v1, "thread2", 113LL);
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0;
gettimestring(&v4);
v2 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", (const char *)&v4, v2, "thread2", 122LL);
return 0LL;
}

original_code:
void *thread2(void)
 {
   int retval = 0;
   retval = pthread_setspecific(namekey, threadnames[3]);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 111, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 113);};
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 122);};
   return ((void *)0);
 }

canonical_original_code:
void *thread2()
 {
   int retval = 0;
   retval = pthread_setspecific(namekey, threadnames[3]);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 111, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 113);};
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 122);};
   return ((void *)0);
 }

variable_types: retval int

variable_types:
s
char [50]

return_type: void *


decompiled_code:
int create_threads()
{
const char *v0; // rax
__int64 v2[6]; // [rsp+0h] [rbp-48h] BYREF
__int16 v3; // [rsp+30h] [rbp-18h]

printf("now in %s\n\r", "create_threads");
if ( pthread_key_create(&namekey, 0LL) )
_assert_fail("0 == retval", "threads.c", 0x93u, "create_threads");
if ( pthread_setspecific(namekey, threadnames) )
_assert_fail("0 == retval", "threads.c", 0x96u, "create_threads");
if ( pthread_create(&threads, 0LL, thread0, 0LL) )
_assert_fail("0 == retval", "threads.c", 0x99u, "create_threads");
if ( pthread_create((pthread_t *)(unsigned int)((_DWORD)&threads + 8), 0LL, thread1, 0LL) )
_assert_fail("0 == retval", "threads.c", 0x9Cu, "create_threads");
if ( pthread_create((pthread_t *)(unsigned int)((_DWORD)&threads + 16), 0LL, thread2, 0LL) )
_assert_fail("0 == retval", "threads.c", 0xA0u, "create_threads");
v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v2[3] = 0LL;
v2[4] = 0LL;
v2[5] = 0LL;
v3 = 0;
gettimestring(v2);
v0 = (const char *)pthread_getspecific(namekey);
return printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r",
(const char *)v2,
v0,
"create_threads",
162LL);
}

canonical_decompiled_code:
int func1()
{
const char *v0; // rax
__int64 v2[6]; // [rsp+0h] [rbp-48h] BYREF
__int16 v3; // [rsp+30h] [rbp-18h]

printf("now in %s\n\r", "create_threads");
if ( pthread_key_create(&namekey, 0LL) )
_assert_fail("0 == retval", "threads.c", 0x93u, "create_threads");
if ( pthread_setspecific(namekey, threadnames) )
_assert_fail("0 == retval", "threads.c", 0x96u, "create_threads");
if ( pthread_create(&threads, 0LL, thread0, 0LL) )
_assert_fail("0 == retval", "threads.c", 0x99u, "create_threads");
if ( pthread_create((pthread_t *)(unsigned int)((_DWORD)&threads + 8), 0LL, thread1, 0LL) )
_assert_fail("0 == retval", "threads.c", 0x9Cu, "create_threads");
if ( pthread_create((pthread_t *)(unsigned int)((_DWORD)&threads + 16), 0LL, thread2, 0LL) )
_assert_fail("0 == retval", "threads.c", 0xA0u, "create_threads");
v2[0] = 0LL;
v2[1] = 0LL;
v2[2] = 0LL;
v2[3] = 0LL;
v2[4] = 0LL;
v2[5] = 0LL;
v3 = 0;
gettimestring(v2);
v0 = (const char *)pthread_getspecific(namekey);
return printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r",
(const char *)v2,
v0,
"create_threads",
162LL);
}

original_code:
void create_threads(void)
 {
   int retval = 0;
   printf("now in %s\n\r", __PRETTY_FUNCTION__);
   retval = pthread_key_create(&namekey, ((void *)0));
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 147, __extension__ __PRETTY_FUNCTION__); }));
   retval = pthread_setspecific(namekey, threadnames[0]);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 150, __extension__ __PRETTY_FUNCTION__); }));
   retval = pthread_create(&threads[0], ((void *)0), thread0, ((void *)0));
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 153, __extension__ __PRETTY_FUNCTION__); }));
   retval = pthread_create(&threads[1], ((void *)0), thread1, ((void *)0));
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 156, __extension__ __PRETTY_FUNCTION__); }));
   retval = pthread_create(&threads[2], ((void *)0), thread2, ((void *)0));
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 160, __extension__ __PRETTY_FUNCTION__); }));
 {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 162);};
   return;
 }

canonical_original_code:
void create_threads()
 {
   int retval = 0;
   printf("now in %s\n\r", __PRETTY_FUNCTION__);
   retval = pthread_key_create(&namekey, ((void *)0));
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 147, __extension__ __PRETTY_FUNCTION__); }));
   retval = pthread_setspecific(namekey, threadnames[0]);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 150, __extension__ __PRETTY_FUNCTION__); }));
   retval = pthread_create(&threads[0], ((void *)0), thread0, ((void *)0));
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 153, __extension__ __PRETTY_FUNCTION__); }));
   retval = pthread_create(&threads[1], ((void *)0), thread1, ((void *)0));
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 156, __extension__ __PRETTY_FUNCTION__); }));
   retval = pthread_create(&threads[2], ((void *)0), thread2, ((void *)0));
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 160, __extension__ __PRETTY_FUNCTION__); }));
 {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 162);};
   return;
 }


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

printf("now in %s\n\r", "create_sems");
result = sem_init(&sem, 0, 0);
if ( result )
_assert_fail("0 == retval", "threads.c", 0xB2u, "create_sems");
return result;
}

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

printf("now in %s\n\r", "create_sems");
result = sem_init(&sem, 0, 0);
if ( result )
_assert_fail("0 == retval", "threads.c", 0xB2u, "create_sems");
return result;
}

original_code:
void create_sems(void)
 {
   int retval = 0;
   printf("now in %s\n\r", __PRETTY_FUNCTION__);
   retval = sem_init(&sem, 0, 0);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 178, __extension__ __PRETTY_FUNCTION__); }));
   return;
 }

canonical_original_code:
void create_sems()
 {
   int retval = 0;
   printf("now in %s\n\r", __PRETTY_FUNCTION__);
   retval = sem_init(&sem, 0, 0);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 178, __extension__ __PRETTY_FUNCTION__); }));
   return;
 }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbx
const char *v4; // rax
__int64 v6[6]; // [rsp+0h] [rbp-58h] BYREF
__int16 v7; // [rsp+30h] [rbp-28h]

printf("starting main ...\n\r");
create_sems();
create_threads();
v3 = &threads;
do
{
if ( pthread_join(*v3, 0LL) )
_assert_fail("0 == pthread_join(threads[i], NULL)", "threads.c", 0x3Au, "main");
++v3;
}
while ( v3 != (pthread_t *)(unsigned int)((_DWORD)&threads + 24) );
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v7 = 0;
gettimestring(v6);
v4 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", (const char *)v6, v4, "main", 61LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbx
const char *v4; // rax
__int64 v6[6]; // [rsp+0h] [rbp-58h] BYREF
__int16 v7; // [rsp+30h] [rbp-28h]

printf("starting main ...\n\r");
func2();
func1();
v3 = &threads;
do
{
if ( pthread_join(*v3, 0LL) )
_assert_fail("0 == pthread_join(threads[i], NULL)", "threads.c", 0x3Au, "main");
++v3;
}
while ( v3 != (pthread_t *)(unsigned int)((_DWORD)&threads + 24) );
v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
v6[5] = 0LL;
v7 = 0;
gettimestring(v6);
v4 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", (const char *)v6, v4, "main", 61LL);
return 0;
}

original_code:
int main(void)
 {
   int i;
   printf("starting main ...\n\r");
   create_sems();
   create_threads();
   for (i = 0; i < 3 ; i++)
     {
       ((void) sizeof ((0 == pthread_join(threads[i], ((void *)0))) ? 1 : 0), __extension__ ({ if (0 == pthread_join(threads[i], ((void *)0))) ; else __assert_fail ("0 == pthread_join(threads[i], NULL)", "threads.c", 58, __extension__ __PRETTY_FUNCTION__); }));
     }
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 61);};
   return 0;
 }

canonical_original_code:
int main()
 {
   int i;
   printf("starting main ...\n\r");
   create_sems();
   create_threads();
   for (i = 0; i < 3 ; i++)
     {
       ((void) sizeof ((0 == pthread_join(threads[i], ((void *)0))) ? 1 : 0), __extension__ ({ if (0 == pthread_join(threads[i], ((void *)0))) ; else __assert_fail ("0 == pthread_join(threads[i], NULL)", "threads.c", 58, __extension__ __PRETTY_FUNCTION__); }));
     }
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 61);};
   return 0;
 }

variable_types: i int


decompiled_code:
int __fastcall take_sem(sem_t *sem)
{
const char *v1; // rax
unsigned int v2; // ebp
const char *v3; // rax
const char *v4; // rax
int v5; // ebx
const char *v6; // rax
unsigned int v7; // ebp
const char *v8; // rax
const char *v9; // rax
__int64 v11; // [rsp+0h] [rbp-58h] BYREF
__int64 v12; // [rsp+8h] [rbp-50h]
__int64 v13; // [rsp+10h] [rbp-48h]
__int64 v14; // [rsp+18h] [rbp-40h]
__int64 v15; // [rsp+20h] [rbp-38h]
__int64 v16; // [rsp+28h] [rbp-30h]
__int16 v17; // [rsp+30h] [rbp-28h]
int sval[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

sval[0] = 0;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v11, v1, "take_sem", 188LL);
if ( sem_getvalue(sem, sval) )
_assert_fail("0 == retval", "threads.c", 0xC4u, "take_sem");
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v2 = sval[0];
v3 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t sem is now : %d\n\r",
(const char *)&v11,
v3,
"take_sem",
197LL,
v2);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v4 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t going to lock\n\r", (const char *)&v11, v4, "take_sem", 198LL);
v5 = sem_wait(sem);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v6 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t got the lock\n\r", (const char *)&v11, v6, "take_sem", 200LL);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v7 = sval[0];
v8 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t sem is now : %d\n\r",
(const char *)&v11,
v8,
"take_sem",
201LL,
v7);
if ( v5 )
_assert_fail("0 == retval", "threads.c", 0xCAu, "take_sem");
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v9 = (const char *)pthread_getspecific(namekey);
return printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r",
(const char *)&v11,
v9,
"take_sem",
204LL);
}

canonical_decompiled_code:
int __fastcall func3(sem_t *sem)
{
const char *v1; // rax
unsigned int v2; // ebp
const char *v3; // rax
const char *v4; // rax
int v5; // ebx
const char *v6; // rax
unsigned int v7; // ebp
const char *v8; // rax
const char *v9; // rax
__int64 v11; // [rsp+0h] [rbp-58h] BYREF
__int64 v12; // [rsp+8h] [rbp-50h]
__int64 v13; // [rsp+10h] [rbp-48h]
__int64 v14; // [rsp+18h] [rbp-40h]
__int64 v15; // [rsp+20h] [rbp-38h]
__int64 v16; // [rsp+28h] [rbp-30h]
__int16 v17; // [rsp+30h] [rbp-28h]
int sval[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

sval[0] = 0;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v11, v1, "take_sem", 188LL);
if ( sem_getvalue(sem, sval) )
_assert_fail("0 == retval", "threads.c", 0xC4u, "take_sem");
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v2 = sval[0];
v3 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t sem is now : %d\n\r",
(const char *)&v11,
v3,
"take_sem",
197LL,
v2);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v4 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t going to lock\n\r", (const char *)&v11, v4, "take_sem", 198LL);
v5 = sem_wait(sem);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v6 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t got the lock\n\r", (const char *)&v11, v6, "take_sem", 200LL);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v7 = sval[0];
v8 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t sem is now : %d\n\r",
(const char *)&v11,
v8,
"take_sem",
201LL,
v7);
if ( v5 )
_assert_fail("0 == retval", "threads.c", 0xCAu, "take_sem");
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v9 = (const char *)pthread_getspecific(namekey);
return printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r",
(const char *)&v11,
v9,
"take_sem",
204LL);
}

original_code:
void take_sem(sem_t *psem)
 {
   int retval = 0 ;
   int semval = 0 ;
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 188);};
   retval = sem_getvalue(psem, &semval);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 196, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "sem is now : %d" "\n\r", s, (char *)pthread_getspecific(namekey), __PRETTY_FUNCTION__, 197, semval);};
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "going to lock" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 198);};
   retval = sem_wait(psem);
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "got the lock" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 200);};
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "sem is now : %d" "\n\r", s, (char *)pthread_getspecific(namekey), __PRETTY_FUNCTION__, 201, semval);};
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 202, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 204);};
   return;
 }

canonical_original_code:
void take_sem(union sem_t *psem)
 {
   int retval = 0;
   int semval = 0;
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 188);};
   retval = sem_getvalue(psem, &semval);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 196, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "sem is now : %d" "\n\r", s, (char *)pthread_getspecific(namekey), __PRETTY_FUNCTION__, 197, semval);};
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "going to lock" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 198);};
   retval = sem_wait(psem);
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "got the lock" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 200);};
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "sem is now : %d" "\n\r", s, (char *)pthread_getspecific(namekey), __PRETTY_FUNCTION__, 201, semval);};
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 202, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 204);};
   return;
 }

variable_types: union sem_t { char __size[32]; long __align; } *

variable_types: semval int


decompiled_code:
void *__fastcall thread0(void *a1)
{
const char *v1; // rax
const char *v2; // rax
__int64 v4; // [rsp+0h] [rbp-48h] BYREF
__int64 v5; // [rsp+8h] [rbp-40h]
__int64 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+18h] [rbp-30h]
__int64 v8; // [rsp+20h] [rbp-28h]
__int64 v9; // [rsp+28h] [rbp-20h]
__int16 v10; // [rsp+30h] [rbp-18h]

if ( pthread_setspecific(namekey, (const void *)(unsigned int)((_DWORD)threadnames + 15)) )
_assert_fail("0 == retval", "threads.c", 0x46u, "thread0");
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0;
gettimestring(&v4);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v4, v1, "thread0", 72LL);
take_sem(&sem);
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0;
gettimestring(&v4);
v2 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", (const char *)&v4, v2, "thread0", 76LL);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func4(void *a1)
{
const char *v1; // rax
const char *v2; // rax
__int64 v4; // [rsp+0h] [rbp-48h] BYREF
__int64 v5; // [rsp+8h] [rbp-40h]
__int64 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+18h] [rbp-30h]
__int64 v8; // [rsp+20h] [rbp-28h]
__int64 v9; // [rsp+28h] [rbp-20h]
__int16 v10; // [rsp+30h] [rbp-18h]

if ( pthread_setspecific(namekey, (const void *)(unsigned int)((_DWORD)threadnames + 15)) )
_assert_fail("0 == retval", "threads.c", 0x46u, "thread0");
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0;
gettimestring(&v4);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v4, v1, "thread0", 72LL);
func3(&sem);
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0;
gettimestring(&v4);
v2 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", (const char *)&v4, v2, "thread0", 76LL);
return 0LL;
}

original_code:
void *thread0(void)
 {
   int retval = 0;
   retval = pthread_setspecific(namekey, threadnames[1]);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 70, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 72);};
   take_sem(&sem);
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 76);};
   return ((void *)0);
 }

canonical_original_code:
void *thread0()
 {
   int retval = 0;
   retval = pthread_setspecific(namekey, threadnames[1]);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 70, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 72);};
   take_sem(&sem);
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 76);};
   return ((void *)0);
 }


decompiled_code:
int __fastcall release_sem(sem_t *sem)
{
const char *v1; // rax
unsigned int v2; // ebp
const char *v3; // rax
const char *v4; // rax
int v5; // ebx
const char *v6; // rax
unsigned int v7; // ebp
const char *v8; // rax
const char *v9; // rax
__int64 v11; // [rsp+0h] [rbp-58h] BYREF
__int64 v12; // [rsp+8h] [rbp-50h]
__int64 v13; // [rsp+10h] [rbp-48h]
__int64 v14; // [rsp+18h] [rbp-40h]
__int64 v15; // [rsp+20h] [rbp-38h]
__int64 v16; // [rsp+28h] [rbp-30h]
__int16 v17; // [rsp+30h] [rbp-28h]
int sval[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

sval[0] = 0;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v11, v1, "release_sem", 214LL);
if ( sem_getvalue(sem, sval) )
_assert_fail("0 == retval", "threads.c", 0xD9u, "release_sem");
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v2 = sval[0];
v3 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t sem is now : %d\n\r",
(const char *)&v11,
v3,
"release_sem",
219LL,
v2);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v4 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t going to release\n\r",
(const char *)&v11,
v4,
"release_sem",
220LL);
v5 = sem_post(sem);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v6 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t released\n\r", (const char *)&v11, v6, "release_sem", 222LL);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v7 = sval[0];
v8 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t sem is now : %d\n\r",
(const char *)&v11,
v8,
"release_sem",
223LL,
v7);
if ( v5 )
_assert_fail("0 == retval", "threads.c", 0xE0u, "release_sem");
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v9 = (const char *)pthread_getspecific(namekey);
return printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r",
(const char *)&v11,
v9,
"release_sem",
226LL);
}

canonical_decompiled_code:
int __fastcall func5(sem_t *sem)
{
const char *v1; // rax
unsigned int v2; // ebp
const char *v3; // rax
const char *v4; // rax
int v5; // ebx
const char *v6; // rax
unsigned int v7; // ebp
const char *v8; // rax
const char *v9; // rax
__int64 v11; // [rsp+0h] [rbp-58h] BYREF
__int64 v12; // [rsp+8h] [rbp-50h]
__int64 v13; // [rsp+10h] [rbp-48h]
__int64 v14; // [rsp+18h] [rbp-40h]
__int64 v15; // [rsp+20h] [rbp-38h]
__int64 v16; // [rsp+28h] [rbp-30h]
__int16 v17; // [rsp+30h] [rbp-28h]
int sval[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

sval[0] = 0;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v11, v1, "release_sem", 214LL);
if ( sem_getvalue(sem, sval) )
_assert_fail("0 == retval", "threads.c", 0xD9u, "release_sem");
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v2 = sval[0];
v3 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t sem is now : %d\n\r",
(const char *)&v11,
v3,
"release_sem",
219LL,
v2);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v4 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t going to release\n\r",
(const char *)&v11,
v4,
"release_sem",
220LL);
v5 = sem_post(sem);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v6 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t released\n\r", (const char *)&v11, v6, "release_sem", 222LL);
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v7 = sval[0];
v8 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t sem is now : %d\n\r",
(const char *)&v11,
v8,
"release_sem",
223LL,
v7);
if ( v5 )
_assert_fail("0 == retval", "threads.c", 0xE0u, "release_sem");
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
v14 = 0LL;
v15 = 0LL;
v16 = 0LL;
v17 = 0;
gettimestring(&v11);
v9 = (const char *)pthread_getspecific(namekey);
return printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r",
(const char *)&v11,
v9,
"release_sem",
226LL);
}

original_code:
void release_sem(sem_t *psem)
 {
   int retval = 0;
   int semval = 0 ;
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 214);};
   retval = sem_getvalue(psem, &semval);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 217, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "sem is now : %d" "\n\r", s, (char *)pthread_getspecific(namekey), __PRETTY_FUNCTION__, 219, semval);};
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "going to release" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 220);};
   retval = sem_post(psem);
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "released" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 222);};
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "sem is now : %d" "\n\r", s, (char *)pthread_getspecific(namekey), __PRETTY_FUNCTION__, 223, semval);};
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 224, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 226);};
   return;
 }

canonical_original_code:
void release_sem(union sem_t *psem)
 {
   int retval = 0;
   int semval = 0;
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 214);};
   retval = sem_getvalue(psem, &semval);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 217, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "sem is now : %d" "\n\r", s, (char *)pthread_getspecific(namekey), __PRETTY_FUNCTION__, 219, semval);};
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "going to release" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 220);};
   retval = sem_post(psem);
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "released" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 222);};
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "sem is now : %d" "\n\r", s, (char *)pthread_getspecific(namekey), __PRETTY_FUNCTION__, 223, semval);};
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 224, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 226);};
   return;
 }

user_defined_types: union sem_t { char __size[32]; long __align; }


decompiled_code:
void *__fastcall thread1(void *a1)
{
const char *v1; // rax
const char *v2; // rax
const char *v3; // rax
__int64 v5; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+8h] [rbp-40h]
__int64 v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+18h] [rbp-30h]
__int64 v9; // [rsp+20h] [rbp-28h]
__int64 v10; // [rsp+28h] [rbp-20h]
__int16 v11; // [rsp+30h] [rbp-18h]

if ( pthread_setspecific(namekey, (const void *)(unsigned int)((_DWORD)threadnames + 30)) )
_assert_fail("0 == retval", "threads.c", 0x55u, "thread1");
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0;
gettimestring(&v5);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v5, v1, "thread1", 88LL);
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0;
gettimestring(&v5);
v2 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t going to sleep for 5 seconds\n\r",
(const char *)&v5,
v2,
"thread1",
90LL);
sleep(5u);
release_sem(&sem);
take_sem(&sem);
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0;
gettimestring(&v5);
v3 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", (const char *)&v5, v3, "thread1", 102LL);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func6(void *a1)
{
const char *v1; // rax
const char *v2; // rax
const char *v3; // rax
__int64 v5; // [rsp+0h] [rbp-48h] BYREF
__int64 v6; // [rsp+8h] [rbp-40h]
__int64 v7; // [rsp+10h] [rbp-38h]
__int64 v8; // [rsp+18h] [rbp-30h]
__int64 v9; // [rsp+20h] [rbp-28h]
__int64 v10; // [rsp+28h] [rbp-20h]
__int16 v11; // [rsp+30h] [rbp-18h]

if ( pthread_setspecific(namekey, (const void *)(unsigned int)((_DWORD)threadnames + 30)) )
_assert_fail("0 == retval", "threads.c", 0x55u, "thread1");
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0;
gettimestring(&v5);
v1 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", (const char *)&v5, v1, "thread1", 88LL);
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0;
gettimestring(&v5);
v2 = (const char *)pthread_getspecific(namekey);
printf(
"%s: in thread: %s\t in func: %s\t at line: %d\t going to sleep for 5 seconds\n\r",
(const char *)&v5,
v2,
"thread1",
90LL);
sleep(5u);
func5(&sem);
func3(&sem);
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0;
gettimestring(&v5);
v3 = (const char *)pthread_getspecific(namekey);
printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", (const char *)&v5, v3, "thread1", 102LL);
return 0LL;
}

original_code:
void *thread1(void)
 {
   int retval = 0;
   retval = pthread_setspecific(namekey, threadnames[2]);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 85, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 88);};
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "going to sleep for 5 seconds" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 90);};
   sleep(5);
   release_sem(&sem);
   take_sem(&sem);
   {char s[50] = "" ; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 102);};
   return ((void *)0);
 }

canonical_original_code:
void *thread1()
 {
   int retval = 0;
   retval = pthread_setspecific(namekey, threadnames[2]);
   ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "threads.c", 85, __extension__ __PRETTY_FUNCTION__); }));
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t entered\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 88);};
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t " "going to sleep for 5 seconds" "\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 90);};
   sleep(5);
   release_sem(&sem);
   take_sem(&sem);
   {char s[50] = ""; gettimestring(s);printf("%s: in thread: %s\t in func: %s\t at line: %d\t exiting\n\r", s, (char *)pthread_getspecific(namekey) , __PRETTY_FUNCTION__, 102);};
   return ((void *)0);
 }


gettimestring

decompiled_code:
size_t __fastcall gettimestring(char *string)
{
size_t v1; // rax
size_t result; // rax
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF
time_t timer; // [rsp+18h] [rbp-10h] BYREF

timer = time(0LL);
if ( !ctime_r(&timer, string) )
_assert_fail("NULL != ret", "msm_common.c", 0x17u, "gettimestring");
if ( gettimeofday(&v3, 0LL) )
_assert_fail("0 == retval", "msm_common.c", 0x1Bu, "gettimestring");
v1 = strnlen(string, 0x32uLL);
snprintf(&string[v1 - 1], 0x32uLL, ": %ld", v3.tv_usec);
result = strnlen(string, 0x32uLL);
string[result] = 0;
return result;
}

canonical_decompiled_code:
size_t __fastcall func0(char *string)
{
size_t v1; // rax
size_t result; // rax
struct timeval v3; // [rsp+0h] [rbp-28h] BYREF
time_t timer; // [rsp+18h] [rbp-10h] BYREF

timer = time(0LL);
if ( !ctime_r(&timer, string) )
_assert_fail("NULL != ret", "msm_common.c", 0x17u, "gettimestring");
if ( gettimeofday(&v3, 0LL) )
_assert_fail("0 == retval", "msm_common.c", 0x1Bu, "gettimestring");
v1 = strnlen(string, 0x32uLL);
snprintf(&string[v1 - 1], 0x32uLL, ": %ld", v3.tv_usec);
result = strnlen(string, 0x32uLL);
string[result] = 0;
return result;
}

original_code:
void gettimestring(char *s)
{
  int retval = 0;
  time_t t;
  char *ret = ((void *)0);
  struct timeval tval;
  t = time(((void *)0));
  ret = ctime_r(&t, s);
  ((void) sizeof ((((void *)0) != ret) ? 1 : 0), __extension__ ({ if (((void *)0) != ret) ; else __assert_fail ("NULL != ret", "msm_common.c", 23, __extension__ __PRETTY_FUNCTION__); }));
  retval = gettimeofday(&tval, ((void *)0));
  ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "msm_common.c", 27, __extension__ __PRETTY_FUNCTION__); }));
  snprintf(s+strnlen(s, 50)-1, 50, ": %ld", tval.tv_usec);
  s[strnlen(s, 50)] = '\0';
  return;
}

canonical_original_code:
void gettimestring(char *s)
{
  int retval = 0;
  long t;
  char *ret = ((void *)0);
  struct timeval tval;
  t = time(((void *)0));
  ret = ctime_r(&t, s);
  ((void) sizeof ((((void *)0) != ret) ? 1 : 0), __extension__ ({ if (((void *)0) != ret) ; else __assert_fail ("NULL != ret", "msm_common.c", 23, __extension__ __PRETTY_FUNCTION__); }));
  retval = gettimeofday(&tval, ((void *)0));
  ((void) sizeof ((0 == retval) ? 1 : 0), __extension__ ({ if (0 == retval) ; else __assert_fail ("0 == retval", "msm_common.c", 27, __extension__ __PRETTY_FUNCTION__); }));
  snprintf(s+strnlen(s, 50)-1, 50, ": %ld", tval.tv_usec);
  s[strnlen(s, 50)] = '\0';
  return;
}

variable_types:
s
char *

variable_types: t long

variable_types:
ret
char *

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


repo: millermackj/roger-the-crab

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

result = (unsigned int)((input_mode_1 + 1) % 5);
input_mode_1 = (input_mode_1 + 1) % 5;
return result;
}

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

result = (unsigned int)((input_mode_1 + 1) % 5);
input_mode_1 = (input_mode_1 + 1) % 5;
return result;
}

original_code:
int change_input_mode()
{
  static int input_mode;
  input_mode = (input_mode + 1) % N_INPUT_MODES;
  return (input_mode);
}


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

result = (unsigned int)((control_mode_0 + 1) % 5);
control_mode_0 = (control_mode_0 + 1) % 5;
init_control_flag = 1;
return result;
}

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

result = (unsigned int)((control_mode_0 + 1) % 5);
control_mode_0 = (control_mode_0 + 1) % 5;
init_control_flag = 1;
return result;
}

original_code:
int change_control_mode()
{
  static int control_mode;
  control_mode = (control_mode + 1) % N_CONTROL_MODES;
  init_control_flag = 1;
  return (control_mode);
}


newVariableType

decompiled_code:
int *__fastcall newVariableType(int a1)
{
__int64 v1; // rax
int *v2; // rbx
__int64 v4; // rax

if ( a1 < 0 )
g_log(0LL, 16LL, "newVariableType(): creating variable with negative rank %d", (unsigned int)a1);
v1 = TypeCache();
v2 = (int *)g_hash_table_lookup(v1, a1);
if ( v2 )
{
g_log(0LL, 32LL, "newVariableType(): returning cached type");
}
else
{
v2 = (int *)g_malloc(8LL);
*v2 = a1;
v2[1] = 1;
v4 = TypeCache();
g_hash_table_insert(v4, a1, v2);
}
return v2;
}

canonical_decompiled_code:
int *__fastcall func1(int a1)
{
__int64 v1; // rax
int *v2; // rbx
__int64 v4; // rax

if ( a1 < 0 )
g_log(0LL, 16LL, "newVariableType(): creating variable with negative rank %d", (unsigned int)a1);
v1 = func0();
v2 = (int *)g_hash_table_lookup(v1, a1);
if ( v2 )
{
g_log(0LL, 32LL, "newVariableType(): returning cached type");
}
else
{
v2 = (int *)g_malloc(8LL);
*v2 = a1;
v2[1] = 1;
v4 = func0();
g_hash_table_insert(v4, a1, v2);
}
return v2;
}

original_code:
VariableType *newVariableType(int rank) {
    if (rank < 0) {
        g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "newVariableType(): creating variable with negative rank %d", rank);
    }
    VariableType *result = g_hash_table_lookup(TypeCache(), ((gpointer) (glong) (rank)));
    if (result != ((void *)0)) {
        g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "newVariableType(): returning cached type");
        return result;
    }
    result = ((VariableType *) g_malloc_n ((1), sizeof (VariableType)));
    result->rank = rank;
    result->primitive = PrimitiveInt;
    g_hash_table_insert(TypeCache(), ((gpointer) (glong) (rank)), result);
    return result;
}

canonical_original_code:
struct _VariableType *newVariableType(int rank) {
    if (rank < 0) {
        g_log (((char *) 0), G_LOG_LEVEL_WARNING, "newVariableType(): creating variable with negative rank %d", rank);
    }
    struct _VariableType *result = g_hash_table_lookup(TypeCache(), ((gpointer) (glong) (rank)));
    if (result != ((void *)0)) {
        g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "newVariableType(): returning cached type");
        return result;
    }
    result = ((struct _VariableType *) g_malloc_n ((1), sizeof (VariableType)));
    result->rank = rank;
    result->primitive = PrimitiveInt;
    g_hash_table_insert(TypeCache(), ((gpointer) (glong) (rank)), result);
    return result;
}

variable_types: rank int

variable_types: struct _VariableType { int rank; enum PrimitiveType { PrimitiveUndefined=0, PrimitiveInt=1 } primitive; } *

user_defined_types: struct _VariableType { int rank; enum PrimitiveType primitive; }


eqVariableType

decompiled_code:
_BOOL8 __fastcall eqVariableType(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
return *a1 == *a2;
}

original_code:
gboolean eqVariableType(VariableType *left, VariableType *right) {
    return left->rank == right->rank;
}

canonical_original_code:
int eqVariableType(struct _VariableType *left, struct _VariableType *right) {
    return left->rank == right->rank;
}

variable_types:
right
struct _VariableType *

user_defined_types: enum PrimitiveType { PrimitiveUndefined=0, PrimitiveInt=1 }


downrankVariableType

decompiled_code:
int *__fastcall downrankVariableType(_DWORD *a1)
{
if ( !a1 )
g_log(0LL, 16LL, "downrankVariableType(type: <NULL>)");
return newVariableType(*a1 - 1);
}

canonical_decompiled_code:
int *__fastcall func3(_DWORD *a1)
{
if ( !a1 )
g_log(0LL, 16LL, "downrankVariableType(type: <NULL>)");
return func1(*a1 - 1);
}

original_code:
VariableType *downrankVariableType(VariableType *type) {
    if (type == ((void *)0)) {
        g_log (((gchar*) 0), G_LOG_LEVEL_WARNING, "downrankVariableType(type: <NULL>)");
    }
    return newVariableType(type->rank - 1);
}

canonical_original_code:
struct _VariableType *downrankVariableType(struct _VariableType *type) {
    if (type == ((void *)0)) {
        g_log (((char *) 0), G_LOG_LEVEL_WARNING, "downrankVariableType(type: <NULL>)");
    }
    return newVariableType(type->rank - 1);
}

variable_types:
type
struct _VariableType *

return_type: struct _VariableType { int rank; enum PrimitiveType { PrimitiveUndefined=0, PrimitiveInt=1 } primitive; } *


stringFromType

decompiled_code:
__int64 __fastcall stringFromType(int *a1)
{
__int64 v1; // rbp
int v2; // ebx

v1 = g_string_new(&s);
if ( *a1 > 0 )
{
v2 = 0;
do
{
g_string_append(v1, "array of ");
++v2;
}
while ( *a1 > v2 );
}
g_string_append(v1, PrimitiveTypeNames[a1[1]]);
return g_string_free(v1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1)
{
__int64 v1; // rbp
int v2; // ebx

v1 = g_string_new(&s);
if ( *a1 > 0 )
{
v2 = 0;
do
{
g_string_append(v1, "array of ");
++v2;
}
while ( *a1 > v2 );
}
g_string_append(v1, PrimitiveTypeNames[a1[1]]);
return g_string_free(v1, 0LL);
}

original_code:
char *stringFromType(VariableType *type) {
    GString *result = g_string_new("");
    for (int i = 0; i < type->rank; i++) {
      g_string_append(result, "array of ");
    }
    g_string_append(result, PrimitiveTypeNames[type->primitive]);
    return g_string_free(result, (0));
}

canonical_original_code:
char *stringFromType(struct _VariableType *type) {
    struct _GString *result = g_string_new("");
    for (int i = 0; i < type->rank; i++) {
      g_string_append(result, "array of ");
    }
    g_string_append(result, PrimitiveTypeNames[type->primitive]);
    return g_string_free(result, (0));
}

variable_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *


stringFromDeclaration

decompiled_code:
__int64 __fastcall stringFromDeclaration(int **a1)
{
__int64 v1; // rbp
const char *v2; // r12

v1 = g_string_new(&s);
v2 = (const char *)stringFromType(a1[1]);
g_string_printf(v1, "<VariableDeclaration at %p> %s : %s", a1, (const char *)*a1, v2);
g_free(v2);
return g_string_free(v1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(int **a1)
{
__int64 v1; // rbp
const char *v2; // r12

v1 = g_string_new(&s);
v2 = (const char *)func4(a1[1]);
g_string_printf(v1, "<VariableDeclaration at %p> %s : %s", a1, (const char *)*a1, v2);
g_free(v2);
return g_string_free(v1, 0LL);
}

original_code:
char *stringFromDeclaration(VariableDeclaration *declaration) {
    GString *result = g_string_new("");
    char *type_s = stringFromType(declaration->type);
    g_string_printf(result, "<VariableDeclaration at %p> %s : %s", declaration, declaration->name, type_s);
    g_free(type_s);
    return g_string_free(result, (0));
}

canonical_original_code:
char *stringFromDeclaration(struct _VariableDeclaration *declaration) {
    struct _GString *result = g_string_new("");
    char *type_s = stringFromType(declaration->type);
    g_string_printf(result, "<VariableDeclaration at %p> %s : %s", declaration, declaration->name, type_s);
    g_free(type_s);
    return g_string_free(result, (0));
}

variable_types: struct _VariableDeclaration { char *name; struct _VariableType { int rank; enum PrimitiveType { PrimitiveUndefined=0, PrimitiveInt=1 } primitive; } *type; } *

user_defined_types: struct _VariableDeclaration { char *name; struct _VariableType *type; }

user_defined_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; }


newVariableDeclaration

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

v2 = (const char *)stringFromType(a2);
g_log(0LL, 32LL, "newVariableDeclaration(name: %s, type: %s)", a1, v2);
g_free(v2);
v3 = g_malloc(16LL);
*(_QWORD *)v3 = a1;
*(_QWORD *)(v3 + 8) = a2;
v4 = (const char *)stringFromDeclaration((int **)v3);
g_log(0LL, 32LL, "newVariableDeclaration() = %s", v4);
g_free(v4);
return v3;
}

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

v2 = (const char *)func4(a2);
g_log(0LL, 32LL, "newVariableDeclaration(name: %s, type: %s)", a1, v2);
g_free(v2);
v3 = g_malloc(16LL);
*(_QWORD *)v3 = a1;
*(_QWORD *)(v3 + 8) = a2;
v4 = (const char *)func5((int **)v3);
g_log(0LL, 32LL, "newVariableDeclaration() = %s", v4);
g_free(v4);
return v3;
}

original_code:
VariableDeclaration *newVariableDeclaration(char *name, VariableType *type) {
    char *type_s = stringFromType(type);
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "newVariableDeclaration(name: %s, type: %s)", name, type_s);
    g_free(type_s);
    VariableDeclaration *result = ((VariableDeclaration *) g_malloc_n ((1), sizeof (VariableDeclaration)));
    result->name = name;
    result->type = type;
    char *result_s = stringFromDeclaration(result);
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "newVariableDeclaration() = %s", result_s);
    g_free(result_s);
    return result;
}

canonical_original_code:
struct _VariableDeclaration *newVariableDeclaration(char *name, struct _VariableType *type) {
    char *type_s = stringFromType(type);
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "newVariableDeclaration(name: %s, type: %s)", name, type_s);
    g_free(type_s);
    struct _VariableDeclaration *result = ((VariableDeclaration *) g_malloc_n ((1), sizeof (VariableDeclaration)));
    result->name = name;
    result->type = type;
    char *result_s = stringFromDeclaration(result);
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "newVariableDeclaration() = %s", result_s);
    g_free(result_s);
    return result;
}

variable_types:
name
char *

return_type: struct _VariableDeclaration { char *name; struct _VariableType { int rank; enum PrimitiveType { PrimitiveUndefined=0, PrimitiveInt=1 } primitive; } *type; } *


newScopeFrame

decompiled_code:
_QWORD *newScopeFrame()
{
_QWORD *v0; // rbx

g_log(0LL, 32LL, "newScopeFrame()");
v0 = (_QWORD *)g_malloc(16LL);
*(_DWORD *)v0 = 0;
v0[1] = 0LL;
g_log(0LL, 32LL, "newScopeFrame() = <ScopeFrame at %p>", v0);
return v0;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *v0; // rbx

g_log(0LL, 32LL, "newScopeFrame()");
v0 = (_QWORD *)g_malloc(16LL);
*(_DWORD *)v0 = 0;
v0[1] = 0LL;
g_log(0LL, 32LL, "newScopeFrame() = <ScopeFrame at %p>", v0);
return v0;
}

original_code:
ScopeFrame *newScopeFrame() {
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "newScopeFrame()");
    ScopeFrame *result = ((ScopeFrame *) g_malloc_n ((1), sizeof (ScopeFrame)));
    result->len = 0;
    result->declarations = ((void *)0);
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "newScopeFrame() = <ScopeFrame at %p>", result);
    return result;
}

canonical_original_code:
struct _ScopeFrame *newScopeFrame() {
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "newScopeFrame()");
    struct _ScopeFrame *result = ((ScopeFrame *) g_malloc_n ((1), sizeof (ScopeFrame)));
    result->len = 0;
    result->declarations = ((void *)0);
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "newScopeFrame() = <ScopeFrame at %p>", result);
    return result;
}

variable_types: struct _ScopeFrame { int len; struct _GSList { void *data; struct _GSList *next; } *declarations; } *

user_defined_types: struct _ScopeFrame { int len; struct _GSList *declarations; }


frameAddDeclaration

decompiled_code:
__int64 __fastcall frameAddDeclaration(_QWORD *a1, int **a2)
{
const char *v2; // rbx
__int64 v3; // rbx

v2 = (const char *)stringFromDeclaration(a2);
g_log(0LL, 32LL, "frameAddDeclaration(frame: <ScopeFrame at %p>, declaration: %s)", a1, v2);
g_free(v2);
v3 = g_malloc(16LL);
*(_DWORD *)v3 = *(_DWORD *)a1 + 1;
*(_QWORD *)(v3 + 8) = g_slist_prepend(a1[1], a2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int **a2)
{
const char *v2; // rbx
__int64 v3; // rbx

v2 = (const char *)func5(a2);
g_log(0LL, 32LL, "frameAddDeclaration(frame: <ScopeFrame at %p>, declaration: %s)", a1, v2);
g_free(v2);
v3 = g_malloc(16LL);
*(_DWORD *)v3 = *(_DWORD *)a1 + 1;
*(_QWORD *)(v3 + 8) = g_slist_prepend(a1[1], a2);
return v3;
}

original_code:
ScopeFrame *frameAddDeclaration(ScopeFrame *frame, VariableDeclaration *declaration) {
    char *declaration_s = stringFromDeclaration(declaration);
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "frameAddDeclaration(frame: <ScopeFrame at %p>, declaration: %s)", frame, declaration_s);
    g_free(declaration_s);
    ScopeFrame *result = ((ScopeFrame *) g_malloc_n ((1), sizeof (ScopeFrame)));
    result->len = frame->len+1;
    result->declarations = g_slist_prepend(frame->declarations, declaration);
    return result;
}

canonical_original_code:
struct _ScopeFrame *frameAddDeclaration(struct _ScopeFrame *frame, struct _VariableDeclaration *declaration) {
    char *declaration_s = stringFromDeclaration(declaration);
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "frameAddDeclaration(frame: <ScopeFrame at %p>, declaration: %s)", frame, declaration_s);
    g_free(declaration_s);
    struct _ScopeFrame *result = ((ScopeFrame *) g_malloc_n ((1), sizeof (ScopeFrame)));
    result->len = frame->len+1;
    result->declarations = g_slist_prepend(frame->declarations, declaration);
    return result;
}

variable_types:
frame
struct _ScopeFrame *

return_type: struct _ScopeFrame { int len; struct _GSList { void *data; struct _GSList *next; } *declarations; } *


printScopeFrame

decompiled_code:
int __fastcall printScopeFrame(_QWORD *a1)
{
int result; // eax
__int64 i; // rbp
const char *v3; // rbx

result = printf("<ScopeFrame at %p>\n", a1);
for ( i = a1[1]; i; i = *(_QWORD *)(i + 8) )
{
v3 = (const char *)stringFromDeclaration(*(int ***)i);
puts(v3);
result = g_free(v3);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(_QWORD *a1)
{
int result; // eax
__int64 i; // rbp
const char *v3; // rbx

result = printf("<ScopeFrame at %p>\n", a1);
for ( i = a1[1]; i; i = *(_QWORD *)(i + 8) )
{
v3 = (const char *)func5(*(int ***)i);
puts(v3);
result = g_free(v3);
}
return result;
}

original_code:
void printScopeFrame(ScopeFrame *scope) {
    printf("<ScopeFrame at %p>\n", scope);
    for (GSList *it = scope->declarations; it != ((void *)0); it = it->next) {
        VariableDeclaration *declaration = it->data;
        char *declaration_s = stringFromDeclaration(declaration);
        puts(declaration_s);
        g_free(declaration_s);
    }
}

canonical_original_code:
void printScopeFrame(struct _ScopeFrame *scope) {
    printf("<ScopeFrame at %p>\n", scope);
    for (struct _GSList *it = scope->declarations; it != ((void *)0); it = it->next) {
        struct _VariableDeclaration *declaration = it->data;
        char *declaration_s = stringFromDeclaration(declaration);
        puts(declaration_s);
        g_free(declaration_s);
    }
}

variable_types: struct _GSList { void *data; struct _GSList *next; } *


newScopeChain

decompiled_code:
_QWORD *newScopeChain()
{
_QWORD *v0; // rbx

g_log(0LL, 32LL, "newScopeChain()");
v0 = (_QWORD *)g_malloc(16LL);
*(_DWORD *)v0 = 0;
v0[1] = 0LL;
g_log(0LL, 32LL, "newScopeChain() = <ScopeChain at %p>", v0);
return v0;
}

canonical_decompiled_code:
_QWORD *func10()
{
_QWORD *v0; // rbx

g_log(0LL, 32LL, "newScopeChain()");
v0 = (_QWORD *)g_malloc(16LL);
*(_DWORD *)v0 = 0;
v0[1] = 0LL;
g_log(0LL, 32LL, "newScopeChain() = <ScopeChain at %p>", v0);
return v0;
}

original_code:
ScopeChain *newScopeChain() {
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "newScopeChain()");
    ScopeChain *result = ((ScopeChain *) g_malloc_n ((1), sizeof (ScopeChain)));
    result->len = 0;
    result->frames = ((void *)0);
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "newScopeChain() = <ScopeChain at %p>", result);
    return result;
}

canonical_original_code:
struct _ScopeChain *newScopeChain() {
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "newScopeChain()");
    struct _ScopeChain *result = ((ScopeChain *) g_malloc_n ((1), sizeof (ScopeChain)));
    result->len = 0;
    result->frames = ((void *)0);
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "newScopeChain() = <ScopeChain at %p>", result);
    return result;
}

variable_types: struct _ScopeChain { int len; struct _GSList { void *data; struct _GSList *next; } *frames; } *

user_defined_types: struct _ScopeChain { int len; struct _GSList *frames; }


printScopeChain

decompiled_code:
int __fastcall printScopeChain(_QWORD *a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
_QWORD *v3; // r12

printf("<ScopeChain at %p>\n", a1);
v1 = a1[1];
if ( v1 )
{
v2 = 0;
do
{
v3 = *(_QWORD **)v1;
printf("[ Scope %d ]\n", v2);
printScopeFrame(v3);
v1 = *(_QWORD *)(v1 + 8);
++v2;
}
while ( v1 );
}
return puts(&s);
}

canonical_decompiled_code:
int __fastcall func11(_QWORD *a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
_QWORD *v3; // r12

printf("<ScopeChain at %p>\n", a1);
v1 = a1[1];
if ( v1 )
{
v2 = 0;
do
{
v3 = *(_QWORD **)v1;
printf("[ Scope %d ]\n", v2);
func9(v3);
v1 = *(_QWORD *)(v1 + 8);
++v2;
}
while ( v1 );
}
return puts(&s);
}

original_code:
void printScopeChain(ScopeChain *chain) {
    printf("<ScopeChain at %p>\n", chain);
    int i = 0;
    for (GSList *it = chain->frames;
         it != ((void *)0);
         it = it->next, i++) {
        ScopeFrame *frame = it->data;
        printf("[ Scope %d ]\n", i);
        printScopeFrame(frame);
    }
    puts("");
}

canonical_original_code:
void printScopeChain(struct _ScopeChain *chain) {
    printf("<ScopeChain at %p>\n", chain);
    int i = 0;
    for (struct _GSList *it = chain->frames;
         it != ((void *)0);
         it = it->next, i++) {
        struct _ScopeFrame *frame = it->data;
        printf("[ Scope %d ]\n", i);
        printScopeFrame(frame);
    }
    puts("");
}

variable_types: i int

user_defined_types: struct _GSList { void *data; struct _GSList *next; }


debugScopeChain

decompiled_code:
int __fastcall debugScopeChain(const char *a1, _QWORD *a2)
{
int result; // eax

if ( debugScopeChain )
{
puts(a1);
result = printScopeChain(a2);
}
return result;
}

canonical_decompiled_code:
int __fastcall func12(const char *a1, _QWORD *a2)
{
int result; // eax

if ( debugScopeChain )
{
puts(a1);
result = func11(a2);
}
return result;
}

original_code:
void debugScopeChain(char *label, ScopeChain *chain) {
    if (!_debugScopeChain) return;
    puts(label);
    printScopeChain(chain);
}

canonical_original_code:
void debugScopeChain(char *label, struct _ScopeChain *chain) {
    if (!_debugScopeChain) return;
    puts(label);
    printScopeChain(chain);
}

variable_types:
label
char *


findDeclarationInFrame

decompiled_code:
int **__fastcall findDeclarationInFrame(const char *a1, _QWORD *a2)
{
int ***v2; // rbx
int **v3; // rbp
const char *v5; // rbx

g_log(0LL, 32LL, "findDeclarationInFrame(identifier: %s, frame: <ScopeFrame at %p>", a1, a2);
v2 = (int ***)a2[1];
if ( v2 )
{
while ( 1 )
{
v3 = *v2;
if ( !(unsigned int)g_strcmp0(a1, **v2) )
break;
v2 = (int ***)v2[1];
if ( !v2 )
goto LABEL_4;
}
v5 = (const char *)stringFromDeclaration(v3);
g_log(0LL, 32LL, "findDeclarationInFrame() = %s", v5);
g_free(v5);
}
else
{
LABEL_4:
g_log(0LL, 32LL, "findDeclarationInFrame() = NULL");
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
int **__fastcall func14(const char *a1, _QWORD *a2)
{
int ***v2; // rbx
int **v3; // rbp
const char *v5; // rbx

g_log(0LL, 32LL, "findDeclarationInFrame(identifier: %s, frame: <ScopeFrame at %p>", a1, a2);
v2 = (int ***)a2[1];
if ( v2 )
{
while ( 1 )
{
v3 = *v2;
if ( !(unsigned int)g_strcmp0(a1, **v2) )
break;
v2 = (int ***)v2[1];
if ( !v2 )
goto LABEL_4;
}
v5 = (const char *)func5(v3);
g_log(0LL, 32LL, "findDeclarationInFrame() = %s", v5);
g_free(v5);
}
else
{
LABEL_4:
g_log(0LL, 32LL, "findDeclarationInFrame() = NULL");
v3 = 0LL;
}
return v3;
}

original_code:
VariableDeclaration *findDeclarationInFrame(char *identifier, ScopeFrame *frame) {
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "findDeclarationInFrame(identifier: %s, frame: <ScopeFrame at %p>", identifier, frame);
    for (GSList *it = frame->declarations; it != ((void *)0); it = it->next) {
        VariableDeclaration *declaration = it->data;
        if (g_strcmp0(identifier, declaration->name) == 0) {
            char *declaration_s = stringFromDeclaration(declaration);
            g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "findDeclarationInFrame() = %s", declaration_s);
            g_free(declaration_s);
            return declaration;
        }
    }
    g_log (((gchar*) 0), G_LOG_LEVEL_MESSAGE, "findDeclarationInFrame() = NULL");
    return ((void *)0);
}

canonical_original_code:
struct _VariableDeclaration *findDeclarationInFrame(char *identifier, struct _ScopeFrame *frame) {
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "findDeclarationInFrame(identifier: %s, frame: <ScopeFrame at %p>", identifier, frame);
    for (struct _GSList *it = frame->declarations; it != ((void *)0); it = it->next) {
        struct _VariableDeclaration *declaration = it->data;
        if (g_strcmp0(identifier, declaration->name) == 0) {
            char *declaration_s = stringFromDeclaration(declaration);
            g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "findDeclarationInFrame() = %s", declaration_s);
            g_free(declaration_s);
            return declaration;
        }
    }
    g_log (((char *) 0), G_LOG_LEVEL_MESSAGE, "findDeclarationInFrame() = NULL");
    return ((void *)0);
}

variable_types:
identifier
char *