decompiled_code:
void addr_show()
{
const char *v0; // rbp
__int64 *v1; // rbx
__int64 *v2; // rbx
__int64 v3; // rax
__int64 *v4; // rdi
unsigned int v5; // er13
__int64 *v6; // r12
_QWORD *v7; // rbx
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // r14
char *v11; // rbx
__int64 v12; // rax
__int128 v13[4]; // [rsp+0h] [rbp-78h] BYREF
__int128 dest; // [rsp+40h] [rbp-38h] BYREF
char v15; // [rsp+50h] [rbp-28h] BYREF

v0 = (const char *)&flow_hash;
puts("\n### IP address Information ###");
while ( 1 )
{
v1 = *(__int64 **)v0;
if ( *(_QWORD *)v0 )
break;
LABEL_15:
v0 += 8;
if ( v0 == "\n### IP address Information ###" )
{
v5 = total_addr;
if ( total_addr > 0 )
{
v6 = addr_hash;
v13[0] = 0LL;
v13[1] = 0LL;
v13[2] = 0LL;
v13[3] = 0LL;
dest = 0LL;
do
{
v7 = (_QWORD *)*v6;
if ( *v6 )
{
do
{
v8 = 0LL;
while ( 1 )
{
v9 = *((_QWORD *)v13 + v8);
v10 = (int)v8;
if ( !v9 || v7[3] > *(_QWORD *)(v9 + 24) )
break;
if ( ++v8 == 10 )
goto LABEL_23;
}
if ( (_DWORD)v8 != 9 )
memmove(
(char *)&dest - 8 * (unsigned int)(8 - v8) + 8,
(char *)&dest - 8 * (unsigned int)(8 - v8),
8LL * (unsigned int)(9 - v8));
*((_QWORD *)v13 + v10) = v7;
LABEL_23:
v7 = (_QWORD *)*v7;
}
while ( v7 );
}
++v6;
}
while ( v6 != &flow_hash );
v11 = (char *)v13;
printf("# of IPv4 addresses: %d \n", v5);
printf("Top %d bandwidth usage (bytes/total in %%):\n", 10LL);
do
{
v12 = *(_QWORD *)v11;
if ( !*(_QWORD *)v11 )
break;
v11 += 8;
printf(" %4.1f%%", (double)(int)*(_QWORD *)(v12 + 24) / (double)(int)(v4_total_bytes / 2) * 100.0);
}
while ( v11 != &v15 );
putchar(10);
}
goto LABEL_8;
}
}
while ( *((_DWORD *)v1 + 4) != 2
|| !(unsigned int)addr_count_constprop_0((unsigned int *)v1 + 5, *((_DWORD *)v1 + 7), v1[4])
&& !(unsigned int)addr_count_constprop_0((unsigned int *)v1 + 6, *((_DWORD *)v1 + 7), v1[4]) )
{
v1 = (__int64 *)*v1;
if ( !v1 )
goto LABEL_15;
}
LABEL_8:
v2 = addr_hash;
do
{
while ( 1 )
{
v4 = (__int64 *)*v2;
if ( !*v2 )
break;
v3 = *v4;
if ( *v4 )
*(_QWORD *)(v3 + 8) = v4[1];
*(_QWORD *)v4[1] = v3;
free(v4);
}
++v2;
}
while ( v2 != &flow_hash );
}

canonical_decompiled_code:
void func3()
{
const char *v0; // rbp
__int64 *v1; // rbx
__int64 *v2; // rbx
__int64 v3; // rax
__int64 *v4; // rdi
unsigned int v5; // er13
__int64 *v6; // r12
_QWORD *v7; // rbx
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // r14
char *v11; // rbx
__int64 v12; // rax
__int128 v13[4]; // [rsp+0h] [rbp-78h] BYREF
__int128 dest; // [rsp+40h] [rbp-38h] BYREF
char v15; // [rsp+50h] [rbp-28h] BYREF

v0 = (const char *)&flow_hash;
puts("\n### IP address Information ###");
while ( 1 )
{
v1 = *(__int64 **)v0;
if ( *(_QWORD *)v0 )
break;
LABEL_15:
v0 += 8;
if ( v0 == "\n### IP address Information ###" )
{
v5 = total_addr;
if ( total_addr > 0 )
{
v6 = addr_hash;
v13[0] = 0LL;
v13[1] = 0LL;
v13[2] = 0LL;
v13[3] = 0LL;
dest = 0LL;
do
{
v7 = (_QWORD *)*v6;
if ( *v6 )
{
do
{
v8 = 0LL;
while ( 1 )
{
v9 = *((_QWORD *)v13 + v8);
v10 = (int)v8;
if ( !v9 || v7[3] > *(_QWORD *)(v9 + 24) )
break;
if ( ++v8 == 10 )
goto LABEL_23;
}
if ( (_DWORD)v8 != 9 )
memmove(
(char *)&dest - 8 * (unsigned int)(8 - v8) + 8,
(char *)&dest - 8 * (unsigned int)(8 - v8),
8LL * (unsigned int)(9 - v8));
*((_QWORD *)v13 + v10) = v7;
LABEL_23:
v7 = (_QWORD *)*v7;
}
while ( v7 );
}
++v6;
}
while ( v6 != &flow_hash );
v11 = (char *)v13;
printf("# of IPv4 addresses: %d \n", v5);
printf("Top %d bandwidth usage (bytes/total in %%):\n", 10LL);
do
{
v12 = *(_QWORD *)v11;
if ( !*(_QWORD *)v11 )
break;
v11 += 8;
printf(" %4.1f%%", (double)(int)*(_QWORD *)(v12 + 24) / (double)(int)(v4_total_bytes / 2) * 100.0);
}
while ( v11 != &v15 );
putchar(10);
}
goto LABEL_8;
}
}
while ( *((_DWORD *)v1 + 4) != 2
|| !(unsigned int)func2((unsigned int *)v1 + 5, *((_DWORD *)v1 + 7), v1[4])
&& !(unsigned int)func2((unsigned int *)v1 + 6, *((_DWORD *)v1 + 7), v1[4]) )
{
v1 = (__int64 *)*v1;
if ( !v1 )
goto LABEL_15;
}
LABEL_8:
v2 = addr_hash;
do
{
while ( 1 )
{
v4 = (__int64 *)*v2;
if ( !*v2 )
break;
v3 = *v4;
if ( *v4 )
*(_QWORD *)(v3 + 8) = v4[1];
*(_QWORD *)v4[1] = v3;
free(v4);
}
++v2;
}
while ( v2 != &flow_hash );
}

original_code:
static void addr_show(void)
{
 struct flow_entry *flow;
 struct in_addr *src, *dst;
 struct addr_entry *addr, *big_addrs[10];
 int af, hash, i, j, k;
 printf("\n### IP address Information ###\n");
 for (i = 0; i < 256; i++) {
  for (flow = ((&flow_hash[i])->lh_first); flow != ((void *)0);
       flow = ((flow)->f_next.le_next)) {
   af = flow->f_flow.flow_af;
   if (af == 2) {
    src = &flow->f_flow.flow_un._ip.ip_src;
    dst = &flow->f_flow.flow_un._ip.ip_dst;
   }
   else
    continue;
   if (addr_count(af, src, flow->f_packets,
           flow->f_bytes) != 0)
    goto out;
   if (addr_count(af, dst, flow->f_packets,
           flow->f_bytes) != 0)
    goto out;
  }
 }
 if (total_addr > 0) {
  for (i = 0; i < 10; i++)
   big_addrs[i] = ((void *)0);
  for (hash = 0; hash < 256; hash++)
   for (addr = ((&addr_hash[hash])->lh_first); addr != ((void *)0);
        addr = ((addr)->addr_next.le_next)) {
    for (j = 0; j < 10; j++) {
     if (big_addrs[j] == ((void *)0) ||
         addr->addr_bytes >
         big_addrs[j]->addr_bytes) {
      for (k = 10 -1; k > j; k--)
       big_addrs[k] = big_addrs[k-1];
      big_addrs[j] = addr;
      break;
     }
    }
   }
  printf("# of IPv4 addresses: %d \n", total_addr);
  printf("Top %d bandwidth usage (bytes/total in %%):\n", 10);
  for (i = 0; i < 10; i++) {
   if (big_addrs[i] == ((void *)0))
    break;
   printf(" %4.1f%%",
          (double)big_addrs[i]->addr_bytes /
          (double)(v4_total_bytes / 2) * 100);
  }
  printf("\n");
 }
  out:
 for (hash = 0; hash < 256; hash++)
  while ((addr = ((&addr_hash[hash])->lh_first)) != ((void *)0)) {
   do { if ((((addr))->addr_next.le_next) != ((void *)0)) (((addr))->addr_next.le_next)->addr_next.le_prev = (addr)->addr_next.le_prev; *(addr)->addr_next.le_prev = (((addr))->addr_next.le_next); } while (0);
   free(addr);
  }
}

canonical_original_code:
static void addr_show()
{
 struct flow_entry *flow;
 struct in_addr *src; struct in_addr *dst;
 struct addr_entry *addr; struct addr_entry *big_addrs[10];
 int af; int hash; int i; int j; int k;
 printf("\n### IP address Information ###\n");
 for (i = 0; i < 256; i++) {
  for (flow = ((&flow_hash[i])->lh_first); flow != ((void *)0);
       flow = ((flow)->f_next.le_next)) {
   af = flow->f_flow.flow_af;
   if (af == 2) {
    src = &flow->f_flow.flow_un._ip.ip_src;
    dst = &flow->f_flow.flow_un._ip.ip_dst;
   }
   else
    continue;
   if (addr_count(af, src, flow->f_packets,
           flow->f_bytes) != 0)
    goto out;
   if (addr_count(af, dst, flow->f_packets,
           flow->f_bytes) != 0)
    goto out;
  }
 }
 if (total_addr > 0) {
  for (i = 0; i < 10; i++)
   big_addrs[i] = ((void *)0);
  for (hash = 0; hash < 256; hash++)
   for (addr = ((&addr_hash[hash])->lh_first); addr != ((void *)0);
        addr = ((addr)->addr_next.le_next)) {
    for (j = 0; j < 10; j++) {
     if (big_addrs[j] == ((void *)0) ||
         addr->addr_bytes >
         big_addrs[j]->addr_bytes) {
      for (k = 10 -1; k > j; k--)
       big_addrs[k] = big_addrs[k-1];
      big_addrs[j] = addr;
      break;
     }
    }
   }
  printf("# of IPv4 addresses: %d \n", total_addr);
  printf("Top %d bandwidth usage (bytes/total in %%):\n", 10);
  for (i = 0; i < 10; i++) {
   if (big_addrs[i] == ((void *)0))
    break;
   printf(" %4.1f%%",
          (double)big_addrs[i]->addr_bytes /
          (double)(v4_total_bytes / 2) * 100);
  }
  printf("\n");
 }
  out:
 for (hash = 0; hash < 256; hash++)
  while ((addr = ((&addr_hash[hash])->lh_first)) != ((void *)0)) {
   do { if ((((addr))->addr_next.le_next) != ((void *)0)) (((addr))->addr_next.le_next)->addr_next.le_prev = (addr)->addr_next.le_prev; *(addr)->addr_next.le_prev = (((addr))->addr_next.le_next); } while (0);
   free(addr);
  }
}

variable_types: struct flow_entry { struct { struct flow_entry *le_next; struct flow_entry **le_prev; } f_next; struct flow { int flow_af; union { struct { struct in_addr { unsigned int s_addr; } ip_src; struct in_addr ip_dst; } _ip; } flow_un; } f_flow; int f_packets; long long f_bytes; } *

variable_types: struct in_addr { unsigned int s_addr; } *

variable_types: struct addr_entry { struct { struct addr_entry *le_next; struct addr_entry **le_prev; } addr_next; union { struct in_addr { unsigned int s_addr; } ua_ip; } a_un; int addr_packets; long long addr_bytes; } *[10]

variable_types: af int

variable_types: hash int

variable_types: j int

variable_types: k int

user_defined_types: struct flow_entry { struct { struct flow_entry *le_next; struct flow_entry **le_prev; } f_next; struct flow f_flow; int f_packets; long long f_bytes; }

user_defined_types: struct addr_entry { struct { struct addr_entry *le_next; struct addr_entry **le_prev; } addr_next; union { struct in_addr ua_ip; } a_un; int addr_packets; long long addr_bytes; }

user_defined_types: struct flow { int flow_af; union { struct { struct in_addr ip_src; struct in_addr ip_dst; } _ip; } flow_un; }


repo: netik/tcpdstat

decompiled_code:
void ipflow_show()
{
__int64 v0; // rbx
_QWORD *v1; // r15
int v2; // er13
int v3; // er14
__int64 v4; // rax
__int64 v5; // rdx
int v6; // ebp
__int64 v7; // rsi
int *v8; // rbx
__int64 v9; // rax
int v10; // er12
char *v11; // rdx
int v12; // ebp
double v13; // xmm2_8
double v14; // xmm0_8
int v15; // eax
double v16; // xmm0_8
double v17; // xmm1_8
__int64 v18; // rbx
int v19; // [rsp+8h] [rbp-490h]
double v20; // [rsp+8h] [rbp-490h]
__int128 v21[4]; // [rsp+10h] [rbp-488h] BYREF
__int128 dest; // [rsp+50h] [rbp-448h] BYREF
unsigned int v23[256]; // [rsp+60h] [rbp-438h] BYREF
char v24; // [rsp+460h] [rbp-38h] BYREF

v0 = 0LL;
puts("### IP flow (unique src/dst pair) Information ###");
v19 = 0;
v21[0] = 0LL;
v21[1] = 0LL;
v21[2] = 0LL;
v21[3] = 0LL;
dest = 0LL;
do
{
v1 = (_QWORD *)flow_hash[v0];
v23[v0] = 0;
if ( v1 )
{
v2 = 1;
LABEL_4:
while ( 2 )
{
v3 = v2;
v4 = 0LL;
while ( 1 )
{
v5 = *((_QWORD *)v21 + v4);
v6 = v4;
if ( !v5 || v1[4] > *(_QWORD *)(v5 + 32) )
break;
if ( ++v4 == 10 )
{
v1 = (_QWORD *)*v1;
++v2;
if ( v1 )
goto LABEL_4;
goto LABEL_9;
}
}
if ( (_DWORD)v4 != 9 )
memmove(
(char *)&dest - 8 * (unsigned int)(8 - v4) + 8,
(char *)&dest - 8 * (unsigned int)(8 - v4),
8LL * (unsigned int)(9 - v4));
++v2;
*((_QWORD *)v21 + v6) = v1;
v1 = (_QWORD *)*v1;
if ( v1 )
continue;
break;
}
LABEL_9:
v19 += v3;
v23[v0] = v3;
}
++v0;
}
while ( v0 != 256 );
v7 = (unsigned int)v19;
if ( v19 )
{
v8 = (int *)v21;
v20 = (double)v19;
printf("# of flows: %d (avg. %.2f pkts/flow)\n", v7, (double)tcpdstat / (double)(int)v7);
printf("Top %d big flow size (bytes/total in %%):\n", 10LL);
do
{
v9 = *(_QWORD *)v8;
if ( !*(_QWORD *)v8 )
break;
v8 += 2;
printf(" %4.1f%%", (double)(int)*(_QWORD *)(v9 + 32) / (double)(int)*((_QWORD *)&tcpdstat + 1) * 100.0);
}
while ( v23 != (unsigned int *)v8 );
putchar(10);
if ( debug )
{
v10 = 0;
v11 = (char *)v23;
v12 = 0x7FFFFFFF;
v13 = v20 * 0.00390625;
v14 = 0.0;
do
{
v15 = *(_DWORD *)v11;
if ( v10 < *(_DWORD *)v11 )
v10 = *(_DWORD *)v11;
if ( v12 > v15 )
v12 = *(_DWORD *)v11;
v11 += 4;
v14 = v14 + (double)v15 * (double)v15;
}
while ( v11 != &v24 );
v16 = v14 * 0.00390625 - v13 * v13;
if ( v16 < 0.0 )
{
v13 = v20 * 0.00390625;
v17 = sqrt(v16);
}
else
{
v17 = sqrt(v16);
}
v18 = 1LL;
printf("flow hash: min/avg/max:%d/%.3f/%d stddev:%.3f\n", (unsigned int)v12, v13, (unsigned int)v10, v17);
printf("hash: [");
printf(" %d", v23[0]);
while ( v18 != 256 )
{
printf(" %d", v23[v18]);
if ( (unsigned int)v18 % 0xA == 9 )
printf("\n\t");
++v18;
}
puts("]");
}
addr_show();
}
}

canonical_decompiled_code:
void func7()
{
__int64 v0; // rbx
_QWORD *v1; // r15
int v2; // er13
int v3; // er14
__int64 v4; // rax
__int64 v5; // rdx
int v6; // ebp
__int64 v7; // rsi
int *v8; // rbx
__int64 v9; // rax
int v10; // er12
char *v11; // rdx
int v12; // ebp
double v13; // xmm2_8
double v14; // xmm0_8
int v15; // eax
double v16; // xmm0_8
double v17; // xmm1_8
__int64 v18; // rbx
int v19; // [rsp+8h] [rbp-490h]
double v20; // [rsp+8h] [rbp-490h]
__int128 v21[4]; // [rsp+10h] [rbp-488h] BYREF
__int128 dest; // [rsp+50h] [rbp-448h] BYREF
unsigned int v23[256]; // [rsp+60h] [rbp-438h] BYREF
char v24; // [rsp+460h] [rbp-38h] BYREF

v0 = 0LL;
puts("### IP flow (unique src/dst pair) Information ###");
v19 = 0;
v21[0] = 0LL;
v21[1] = 0LL;
v21[2] = 0LL;
v21[3] = 0LL;
dest = 0LL;
do
{
v1 = (_QWORD *)flow_hash[v0];
v23[v0] = 0;
if ( v1 )
{
v2 = 1;
LABEL_4:
while ( 2 )
{
v3 = v2;
v4 = 0LL;
while ( 1 )
{
v5 = *((_QWORD *)v21 + v4);
v6 = v4;
if ( !v5 || v1[4] > *(_QWORD *)(v5 + 32) )
break;
if ( ++v4 == 10 )
{
v1 = (_QWORD *)*v1;
++v2;
if ( v1 )
goto LABEL_4;
goto LABEL_9;
}
}
if ( (_DWORD)v4 != 9 )
memmove(
(char *)&dest - 8 * (unsigned int)(8 - v4) + 8,
(char *)&dest - 8 * (unsigned int)(8 - v4),
8LL * (unsigned int)(9 - v4));
++v2;
*((_QWORD *)v21 + v6) = v1;
v1 = (_QWORD *)*v1;
if ( v1 )
continue;
break;
}
LABEL_9:
v19 += v3;
v23[v0] = v3;
}
++v0;
}
while ( v0 != 256 );
v7 = (unsigned int)v19;
if ( v19 )
{
v8 = (int *)v21;
v20 = (double)v19;
printf("# of flows: %d (avg. %.2f pkts/flow)\n", v7, (double)tcpdstat / (double)(int)v7);
printf("Top %d big flow size (bytes/total in %%):\n", 10LL);
do
{
v9 = *(_QWORD *)v8;
if ( !*(_QWORD *)v8 )
break;
v8 += 2;
printf(" %4.1f%%", (double)(int)*(_QWORD *)(v9 + 32) / (double)(int)*((_QWORD *)&tcpdstat + 1) * 100.0);
}
while ( v23 != (unsigned int *)v8 );
putchar(10);
if ( debug )
{
v10 = 0;
v11 = (char *)v23;
v12 = 0x7FFFFFFF;
v13 = v20 * 0.00390625;
v14 = 0.0;
do
{
v15 = *(_DWORD *)v11;
if ( v10 < *(_DWORD *)v11 )
v10 = *(_DWORD *)v11;
if ( v12 > v15 )
v12 = *(_DWORD *)v11;
v11 += 4;
v14 = v14 + (double)v15 * (double)v15;
}
while ( v11 != &v24 );
v16 = v14 * 0.00390625 - v13 * v13;
if ( v16 < 0.0 )
{
v13 = v20 * 0.00390625;
v17 = sqrt(v16);
}
else
{
v17 = sqrt(v16);
}
v18 = 1LL;
printf("flow hash: min/avg/max:%d/%.3f/%d stddev:%.3f\n", (unsigned int)v12, v13, (unsigned int)v10, v17);
printf("hash: [");
printf(" %d", v23[0]);
while ( v18 != 256 )
{
printf(" %d", v23[v18]);
if ( (unsigned int)v18 % 0xA == 9 )
printf("\n\t");
++v18;
}
puts("]");
}
func3();
}
}

original_code:
void ipflow_show(void)
{
 struct flow_entry *flow, *big_flows[10];
 int fhash[256], total, i, j, k;
 printf("### IP flow (unique src/dst pair) Information ###\n");
 total = 0;
 for (i = 0; i < 10; i++)
  big_flows[i] = ((void *)0);
 for (i = 0; i < 256; i++) {
  fhash[i] = 0;
  for (flow = ((&flow_hash[i])->lh_first); flow != ((void *)0);
       flow = ((flow)->f_next.le_next)) {
   fhash[i]++;
   for (j = 0; j < 10; j++) {
    if (big_flows[j] == ((void *)0) ||
        (long long)flow->f_bytes > big_flows[j]->f_bytes) {
     for (k = 10 -1; k > j; k--)
      big_flows[k] = big_flows[k-1];
     big_flows[j] = flow;
     break;
    }
   }
  }
  total += fhash[i];
 }
 if (total == 0)
  return;
 printf("# of flows: %d  (avg. %.2f pkts/flow)\n",
        total, (double)tcpdstat[TOTAL].packets / total);
 printf("Top %d big flow size (bytes/total in %%):\n", 10);
 for (i = 0; i < 10; i++) {
  if (big_flows[i] == ((void *)0))
   break;
  printf(" %4.1f%%",
         (double)big_flows[i]->f_bytes /
         (double)tcpdstat[TOTAL].bytes * 100);
 }
 printf("\n");
 if (debug) {
  double avg, var;
  int max, min;
  avg = (double)total / (double)256;
  max = 0;
  min = 0x7fffffff;
  var = 0.0;
  for (i = 0; i < 256; i++) {
   var += (double)fhash[i] * (double)fhash[i];
   if (fhash[i] > max)
    max = fhash[i];
   if (fhash[i] < min)
    min = fhash[i];
  }
  var = var / (double)256 - avg * avg;
  printf("flow hash: min/avg/max:%d/%.3f/%d stddev:%.3f\n",
         min, avg, max, sqrt(var));
  printf("hash: [");
  for (i = 0; i < 256; i++) {
   printf(" %d", fhash[i]);
   if (i % 10 == 9)
    printf("\n\t");
  }
  printf("]\n");
 }
 addr_show();
}

canonical_original_code:
void ipflow_show()
{
 struct flow_entry *flow; struct flow_entry *big_flows[10];
 int fhash[256]; int total; int i; int j; int k;
 printf("### IP flow (unique src/dst pair) Information ###\n");
 total = 0;
 for (i = 0; i < 10; i++)
  big_flows[i] = ((void *)0);
 for (i = 0; i < 256; i++) {
  fhash[i] = 0;
  for (flow = ((&flow_hash[i])->lh_first); flow != ((void *)0);
       flow = ((flow)->f_next.le_next)) {
   fhash[i]++;
   for (j = 0; j < 10; j++) {
    if (big_flows[j] == ((void *)0) ||
        (long long)flow->f_bytes > big_flows[j]->f_bytes) {
     for (k = 10 -1; k > j; k--)
      big_flows[k] = big_flows[k-1];
     big_flows[j] = flow;
     break;
    }
   }
  }
  total += fhash[i];
 }
 if (total == 0)
  return;
 printf("# of flows: %d  (avg. %.2f pkts/flow)\n",
        total, (double)tcpdstat[TOTAL].packets / total);
 printf("Top %d big flow size (bytes/total in %%):\n", 10);
 for (i = 0; i < 10; i++) {
  if (big_flows[i] == ((void *)0))
   break;
  printf(" %4.1f%%",
         (double)big_flows[i]->f_bytes /
         (double)tcpdstat[TOTAL].bytes * 100);
 }
 printf("\n");
 if (debug) {
  double avg; double var;
  int max; int min;
  avg = (double)total / (double)256;
  max = 0;
  min = 0x7fffffff;
  var = 0.0;
  for (i = 0; i < 256; i++) {
   var += (double)fhash[i] * (double)fhash[i];
   if (fhash[i] > max)
    max = fhash[i];
   if (fhash[i] < min)
    min = fhash[i];
  }
  var = var / (double)256 - avg * avg;
  printf("flow hash: min/avg/max:%d/%.3f/%d stddev:%.3f\n",
         min, avg, max, sqrt(var));
  printf("hash: [");
  for (i = 0; i < 256; i++) {
   printf(" %d", fhash[i]);
   if (i % 10 == 9)
    printf("\n\t");
  }
  printf("]\n");
 }
 addr_show();
}

variable_types: struct flow_entry { struct { struct flow_entry *le_next; struct flow_entry **le_prev; } f_next; struct flow { int flow_af; union { struct { struct in_addr { unsigned int s_addr; } ip_src; struct in_addr ip_dst; } _ip; } flow_un; } f_flow; int f_packets; long long f_bytes; } *[10]

variable_types:
fhash
int [256]

variable_types: total int

variable_types: i int

variable_types: avg double

variable_types: var double

variable_types: max int

variable_types: min int

return_type: void


main

canonical_name: main

repo: netj/libzygote

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rbp
size_t v5; // rax
int v6; // eax
unsigned int v7; // er12
int v8; // ebx
char **i; // rax
char **v10; // rbx
char *v11; // rdi
int v12; // edi
const char **v14; // r15
int v15; // edi
int buf; // [rsp+0h] [rbp-30ACh] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-30A8h] BYREF
int v18; // [rsp+6Ch] [rbp-3040h]
__int16 v19; // [rsp+70h] [rbp-303Ch]
char resolved[4096]; // [rsp+74h] [rbp-3038h] BYREF
char s[16]; // [rsp+1074h] [rbp-2038h] BYREF
char v22[8176]; // [rsp+1084h] [rbp-2028h] BYREF

*(_OWORD *)s = 0LL;
memset(&addr, 0, 0x68uLL);
v18 = 0;
v19 = 0;
memset(v22, 0, sizeof(v22));
if ( argc <= 2 )
{
v7 = 1;
fwrite(
"grow -- Feed a runnable to grow the libzygote process\n"
"Usage: grow ZYGOTE_SOCKET_PATH RUNNABLE_SHARED_OBJECT_PATH [ARG]...\n"
"\n"
"For more info, see: https://github.com/netj/libzygote/#readme\n",
1uLL,
0xB9uLL,
stdout);
}
else
{
v4 = argv[1];
if ( !realpath(argv[2], resolved) )
{
v7 = -1;
perror(argv[2]);
return v7;
}
addr.sa_family = 1;
v5 = strlen(v4);
if ( v5 > 0x6A )
{
v7 = -1;
fprintf(stderr, "%s: pathname too long", v4);
return v7;
}
qmemcpy(addr.sa_data, v4, (unsigned int)(v5 + 1));
v6 = socket(1, 1, 0);
v7 = v6;
if ( v6 == -1 )
{
perror(v4);
return v7;
}
v8 = connect(v6, &addr, 0x6Eu);
if ( v8 )
{
perror(v4);
v15 = v7;
v7 = -1;
close(v15);
return v7;
}
buf = 2;
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("version write");
}
else if ( read(v7, &pid, 4uLL) == -1 )
{
perror("pid read");
}
else
{
signal(1, forward_signal);
signal(2, forward_signal);
signal(3, forward_signal);
signal(6, forward_signal);
signal(10, forward_signal);
signal(12, forward_signal);
signal(14, forward_signal);
signal(15, forward_signal);
for ( i = environ; *i; ++v8 )
++i;
buf = v8;
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("envc write");
}
else
{
v10 = environ;
v11 = *environ;
if ( *environ )
{
while ( 1 )
{
buf = strlen(v11);
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("environ_i length write");
goto LABEL_17;
}
if ( write(v7, *v10, buf) == -1 )
break;
v11 = v10[1];
++v10;
if ( !v11 )
goto LABEL_20;
}
perror("environ_i write");
}
else
{
LABEL_20:
getcwd(s, 0x2000uLL);
buf = strlen(s);
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("cwd length write");
}
else if ( write(v7, s, buf) == -1 )
{
perror("cwd write");
}
else
{
buf = argc - 2;
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("argc write");
}
else
{
buf = strlen(resolved);
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("argv_0 length write");
}
else if ( write(v7, resolved, buf) == -1 )
{
perror("argv_0 write");
}
else if ( argc == 3 )
{
LABEL_32:
if ( write_fd_constprop_0(v7, s, 2LL) == -1 )
{
perror("stderr send_fd");
}
else if ( write_fd_constprop_0(v7, s, 1LL) == -1 )
{
perror("stdout send_fd");
}
else if ( write_fd_constprop_0(v7, s, 0LL) == -1 )
{
perror("stdin send_fd");
}
else
{
if ( read(v7, &buf, 4uLL) != -1 )
{
close(v7);
return buf;
}
perror("exitcode read");
}
}
else
{
v14 = argv + 3;
while ( 1 )
{
buf = strlen(*v14);
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("argv_i length write");
goto LABEL_17;
}
if ( write(v7, *v14, buf) == -1 )
break;
if ( ++v14 == &argv[(unsigned int)(argc - 4) + 4] )
goto LABEL_32;
}
perror("argv_i write");
}
}
}
}
}
}
LABEL_17:
v12 = v7;
v7 = -1;
close(v12);
}
return v7;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // rbp
size_t v5; // rax
int v6; // eax
unsigned int v7; // er12
int v8; // ebx
char **i; // rax
char **v10; // rbx
char *v11; // rdi
int v12; // edi
const char **v14; // r15
int v15; // edi
int buf; // [rsp+0h] [rbp-30ACh] BYREF
struct sockaddr addr; // [rsp+4h] [rbp-30A8h] BYREF
int v18; // [rsp+6Ch] [rbp-3040h]
__int16 v19; // [rsp+70h] [rbp-303Ch]
char resolved[4096]; // [rsp+74h] [rbp-3038h] BYREF
char s[16]; // [rsp+1074h] [rbp-2038h] BYREF
char v22[8176]; // [rsp+1084h] [rbp-2028h] BYREF

*(_OWORD *)s = 0LL;
memset(&addr, 0, 0x68uLL);
v18 = 0;
v19 = 0;
memset(v22, 0, sizeof(v22));
if ( argc <= 2 )
{
v7 = 1;
fwrite(
"grow -- Feed a runnable to grow the libzygote process\n"
"Usage: grow ZYGOTE_SOCKET_PATH RUNNABLE_SHARED_OBJECT_PATH [ARG]...\n"
"\n"
"For more info, see: https://github.com/netj/libzygote/#readme\n",
1uLL,
0xB9uLL,
stdout);
}
else
{
v4 = argv[1];
if ( !realpath(argv[2], resolved) )
{
v7 = -1;
perror(argv[2]);
return v7;
}
addr.sa_family = 1;
v5 = strlen(v4);
if ( v5 > 0x6A )
{
v7 = -1;
fprintf(stderr, "%s: pathname too long", v4);
return v7;
}
qmemcpy(addr.sa_data, v4, (unsigned int)(v5 + 1));
v6 = socket(1, 1, 0);
v7 = v6;
if ( v6 == -1 )
{
perror(v4);
return v7;
}
v8 = connect(v6, &addr, 0x6Eu);
if ( v8 )
{
perror(v4);
v15 = v7;
v7 = -1;
close(v15);
return v7;
}
buf = 2;
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("version write");
}
else if ( read(v7, &pid, 4uLL) == -1 )
{
perror("pid read");
}
else
{
signal(1, forward_signal);
signal(2, forward_signal);
signal(3, forward_signal);
signal(6, forward_signal);
signal(10, forward_signal);
signal(12, forward_signal);
signal(14, forward_signal);
signal(15, forward_signal);
for ( i = environ; *i; ++v8 )
++i;
buf = v8;
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("envc write");
}
else
{
v10 = environ;
v11 = *environ;
if ( *environ )
{
while ( 1 )
{
buf = strlen(v11);
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("environ_i length write");
goto LABEL_17;
}
if ( write(v7, *v10, buf) == -1 )
break;
v11 = v10[1];
++v10;
if ( !v11 )
goto LABEL_20;
}
perror("environ_i write");
}
else
{
LABEL_20:
getcwd(s, 0x2000uLL);
buf = strlen(s);
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("cwd length write");
}
else if ( write(v7, s, buf) == -1 )
{
perror("cwd write");
}
else
{
buf = argc - 2;
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("argc write");
}
else
{
buf = strlen(resolved);
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("argv_0 length write");
}
else if ( write(v7, resolved, buf) == -1 )
{
perror("argv_0 write");
}
else if ( argc == 3 )
{
LABEL_32:
if ( func8(v7, s, 2LL) == -1 )
{
perror("stderr send_fd");
}
else if ( func8(v7, s, 1LL) == -1 )
{
perror("stdout send_fd");
}
else if ( func8(v7, s, 0LL) == -1 )
{
perror("stdin send_fd");
}
else
{
if ( read(v7, &buf, 4uLL) != -1 )
{
close(v7);
return buf;
}
perror("exitcode read");
}
}
else
{
v14 = argv + 3;
while ( 1 )
{
buf = strlen(*v14);
if ( write(v7, &buf, 4uLL) == -1 )
{
perror("argv_i length write");
goto LABEL_17;
}
if ( write(v7, *v14, buf) == -1 )
break;
if ( ++v14 == &argv[(unsigned int)(argc - 4) + 4] )
goto LABEL_32;
}
perror("argv_i write");
}
}
}
}
}
}
LABEL_17:
v12 = v7;
v7 = -1;
close(v12);
}
return v7;
}

original_code:
int main(int argc, char* argv[]) {
    struct sockaddr_un unix_socket_name = {0};
    int socket_fd;
    char* socket_path;
    int i;
    char code_path[4096];
    char* *env;
    int num;
    char buf[8192] = {0};
    if (argc < 3) {
        fprintf(stdout,
                "grow -- Feed a runnable to grow the libzygote process\n"
                "Usage: grow ZYGOTE_SOCKET_PATH RUNNABLE_SHARED_OBJECT_PATH [ARG]...\n"
                "\n"
                "For more info, see: https://github.com/netj/libzygote/#readme\n"
                );
        return 1;
    }
    socket_path = argv[1];
    if (realpath(argv[2], code_path) == ((void *)0)) {
        perror(argv[2]);
        return -1;
    }
    unix_socket_name.sun_family = 1;
    if (strlen(socket_path) >= sizeof(unix_socket_name.sun_path) - 1) {
        fprintf(stderr, "%s: pathname too long", socket_path);
        return -1;
    }
    strcpy(unix_socket_name.sun_path, socket_path);
    socket_fd = socket(1, SOCK_STREAM, 0);
    if (socket_fd == -1) {
        perror(socket_path);
        return -1;
    }
    if (connect(socket_fd, (struct sockaddr*)&unix_socket_name, sizeof(unix_socket_name))) {
        perror(socket_path);
        close(socket_fd);
        socket_fd = -1;
        return -1;
    }
    do { num = 0x00000002; if (write(socket_fd, &num, sizeof(num)) == -1) { perror("version"" write"); goto error; } } while (0);
    if (read(socket_fd, &pid, sizeof(pid)) == -1) { perror("pid read"); goto error; }
    signal(1, forward_signal);
    signal(2, forward_signal);
    signal(3, forward_signal);
    signal(6, forward_signal);
    signal(10, forward_signal);
    signal(12, forward_signal);
    signal(14, forward_signal);
    signal(15, forward_signal);
    for (i = 0, env = environ; *env; env++)
        i++;
    do { num = i; if (write(socket_fd, &num, sizeof(num)) == -1) { perror("envc"" write"); goto error; } } while (0);
    for (env = environ; *env; env++) {
        do { do { num = strlen(*env); if (write(socket_fd, &num, sizeof(num)) == -1) { perror("environ_i length"" write"); goto error; } } while (0); if (write(socket_fd, *env, num) == -1) { perror("environ_i" " write"); goto error; } } while (0);
    }
    getcwd(buf, sizeof(buf));
    do { do { num = strlen(buf); if (write(socket_fd, &num, sizeof(num)) == -1) { perror("cwd length"" write"); goto error; } } while (0); if (write(socket_fd, buf, num) == -1) { perror("cwd" " write"); goto error; } } while (0);
    do { num = argc - 2; if (write(socket_fd, &num, sizeof(num)) == -1) { perror("argc"" write"); goto error; } } while (0);
    do { do { num = strlen(code_path); if (write(socket_fd, &num, sizeof(num)) == -1) { perror("argv_0 length"" write"); goto error; } } while (0); if (write(socket_fd, code_path, num) == -1) { perror("argv_0" " write"); goto error; } } while (0);
    for (i=3; i<argc; i++) {
        do { do { num = strlen(argv[i]); if (write(socket_fd, &num, sizeof(num)) == -1) { perror("argv_i length"" write"); goto error; } } while (0); if (write(socket_fd, argv[i], num) == -1) { perror("argv_i" " write"); goto error; } } while (0);
    }
    if (write_fd(socket_fd, buf, 1, 2) == -1) { perror("stderr send_fd"); goto error; }
    if (write_fd(socket_fd, buf, 1, 1) == -1) { perror("stdout send_fd"); goto error; }
    if (write_fd(socket_fd, buf, 1, 0) == -1) { perror("stdin  send_fd"); goto error; }
    if (read(socket_fd, &num, sizeof(num)) == -1) { perror("exitcode read"); goto error; }
    close(socket_fd);
    return num;
error:
    close(socket_fd);
    return -1;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct sockaddr_un unix_socket_name = {0};
    int socket_fd;
    char *socket_path;
    int i;
    char code_path[4096];
    char **env;
    int num;
    char buf[8192] = {0};
    if (argc < 3) {
        fprintf(stdout,
                "grow -- Feed a runnable to grow the libzygote process\n"
                "Usage: grow ZYGOTE_SOCKET_PATH RUNNABLE_SHARED_OBJECT_PATH [ARG]...\n"
                "\n"
                "For more info, see: https://github.com/netj/libzygote/#readme\n"
                );
        return 1;
    }
    socket_path = argv[1];
    if (realpath(argv[2], code_path) == ((void *)0)) {
        perror(argv[2]);
        return -1;
    }
    unix_socket_name.sun_family = 1;
    if (strlen(socket_path) >= sizeof(unix_socket_name.sun_path) - 1) {
        fprintf(stderr, "%s: pathname too long", socket_path);
        return -1;
    }
    strcpy(unix_socket_name.sun_path, socket_path);
    socket_fd = socket(1, SOCK_STREAM, 0);
    if (socket_fd == -1) {
        perror(socket_path);
        return -1;
    }
    if (connect(socket_fd, (struct sockaddr *)&unix_socket_name, sizeof(unix_socket_name))) {
        perror(socket_path);
        close(socket_fd);
        socket_fd = -1;
        return -1;
    }
    do { num = 0x00000002; if (write(socket_fd, &num, sizeof(num)) == -1) { perror("version"" write"); goto error; } } while (0);
    if (read(socket_fd, &pid, sizeof(pid)) == -1) { perror("pid read"); goto error; }
    signal(1, forward_signal);
    signal(2, forward_signal);
    signal(3, forward_signal);
    signal(6, forward_signal);
    signal(10, forward_signal);
    signal(12, forward_signal);
    signal(14, forward_signal);
    signal(15, forward_signal);
    for (i = 0, env = environ; *env; env++)
        i++;
    do { num = i; if (write(socket_fd, &num, sizeof(num)) == -1) { perror("envc"" write"); goto error; } } while (0);
    for (env = environ; *env; env++) {
        do { do { num = strlen(*env); if (write(socket_fd, &num, sizeof(num)) == -1) { perror("environ_i length"" write"); goto error; } } while (0); if (write(socket_fd, *env, num) == -1) { perror("environ_i" " write"); goto error; } } while (0);
    }
    getcwd(buf, sizeof(buf));
    do { do { num = strlen(buf); if (write(socket_fd, &num, sizeof(num)) == -1) { perror("cwd length"" write"); goto error; } } while (0); if (write(socket_fd, buf, num) == -1) { perror("cwd" " write"); goto error; } } while (0);
    do { num = argc - 2; if (write(socket_fd, &num, sizeof(num)) == -1) { perror("argc"" write"); goto error; } } while (0);
    do { do { num = strlen(code_path); if (write(socket_fd, &num, sizeof(num)) == -1) { perror("argv_0 length"" write"); goto error; } } while (0); if (write(socket_fd, code_path, num) == -1) { perror("argv_0" " write"); goto error; } } while (0);
    for (i=3; i<argc; i++) {
        do { do { num = strlen(argv[i]); if (write(socket_fd, &num, sizeof(num)) == -1) { perror("argv_i length"" write"); goto error; } } while (0); if (write(socket_fd, argv[i], num) == -1) { perror("argv_i" " write"); goto error; } } while (0);
    }
    if (write_fd(socket_fd, buf, 1, 2) == -1) { perror("stderr send_fd"); goto error; }
    if (write_fd(socket_fd, buf, 1, 1) == -1) { perror("stdout send_fd"); goto error; }
    if (write_fd(socket_fd, buf, 1, 0) == -1) { perror("stdin  send_fd"); goto error; }
    if (read(socket_fd, &num, sizeof(num)) == -1) { perror("exitcode read"); goto error; }
    close(socket_fd);
    return num;
error:
    close(socket_fd);
    return -1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

variable_types:
env
char **

variable_types: num int

variable_types:
buf
char [8192]

return_type: int

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
void __fastcall forward_signal(int a1)
{
if ( pid != -1 )
kill(pid, a1);
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
if ( pid != -1 )
kill(pid, a1);
}

original_code:
static void forward_signal(int sig) {
    if (pid == -1)
        return;
    kill(pid, sig);
}

variable_types: sig int


repo: netj/observe

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
char *const *v4; // rbp
char v6[8216]; // [rsp+0h] [rbp-2018h] BYREF

v3 = argv[1];
v4 = (char *const *)prepare_argv(argc, argv, envp);
set_LD_PRELOAD();
execvp(v3, v4);
sprintf(v6, "%s: %s", *argv, argv[2]);
perror(v6);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
char *const *v4; // rbp
char v6[8216]; // [rsp+0h] [rbp-2018h] BYREF

v3 = argv[1];
v4 = (char *const *)prepare_argv(argc, argv, envp);
func7();
execvp(v3, v4);
sprintf(v6, "%s: %s", *argv, argv[2]);
perror(v6);
return -1;
}

original_code:
int main(int argc, char *argv[]) {
    char *file = argv[1];
    char *const *newargv = prepare_argv(argc, argv);
    ; ; ; ;
    set_LD_PRELOAD();
    execvp(file, newargv);
    {
        char name[8192];
        sprintf(name, "%s: %s", argv[0], argv[2]);
        perror(name);
    }
    return -1;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    char *file = argv[1];
    char **newargv = prepare_argv(argc, argv);
    ; ; ; ;
    set_LD_PRELOAD();
    execvp(file, newargv);
    {
        char name[8192];
        sprintf(name, "%s: %s", argv[0], argv[2]);
        perror(name);
    }
    return -1;
}

variable_types:
file
char *

variable_types:
newargv
char **

variable_types:
name
char [8192]


decompiled_code:
int set_LD_PRELOAD()
{
char *v0; // r12
char *v1; // rax
const char *v2; // rbp
size_t v3; // rbx
size_t v4; // rax
char *v5; // rbx

v0 = getenv("LD_PRELOAD");
v1 = getenv("OBSERVE_CAPTURE_SO");
v2 = v1;
if ( v0 )
{
v3 = strlen(v1);
v4 = strlen(v0);
v5 = (char *)malloc(v3 + v4 + 2);
sprintf(v5, "%s %s", v2, v0);
v2 = v5;
}
return setenv("LD_PRELOAD", v2, 1);
}

canonical_decompiled_code:
int func7()
{
char *v0; // r12
char *v1; // rax
const char *v2; // rbp
size_t v3; // rbx
size_t v4; // rax
char *v5; // rbx

v0 = getenv("LD_PRELOAD");
v1 = getenv("OBSERVE_CAPTURE_SO");
v2 = v1;
if ( v0 )
{
v3 = strlen(v1);
v4 = strlen(v0);
v5 = (char *)malloc(v3 + v4 + 2);
sprintf(v5, "%s %s", v2, v0);
v2 = v5;
}
return setenv("LD_PRELOAD", v2, 1);
}

original_code:
static void set_LD_PRELOAD(void) {
    char *preload = getenv("LD_PRELOAD");
    char *capturepath = getenv("OBSERVE_CAPTURE_SO");
    char *newpreload = ((void *)0);
    if (preload == ((void *)0)) {
        newpreload = capturepath;
    } else {
        newpreload = (char *) malloc((
                    strlen(capturepath) + 1
                    + strlen(preload) + 1) * sizeof(char));
        sprintf(newpreload, "%s %s", capturepath, preload);
    }
    setenv("LD_PRELOAD", newpreload, 1);
}

canonical_original_code:
static void set_LD_PRELOAD() {
    char *preload = getenv("LD_PRELOAD");
    char *capturepath = getenv("OBSERVE_CAPTURE_SO");
    char *newpreload = ((void *)0);
    if (preload == ((void *)0)) {
        newpreload = capturepath;
    } else {
        newpreload = (char *) malloc((
                    strlen(capturepath) + 1
                    + strlen(preload) + 1) * sizeof(char));
        sprintf(newpreload, "%s %s", capturepath, preload);
    }
    setenv("LD_PRELOAD", newpreload, 1);
}

variable_types:
preload
char *

variable_types:
capturepath
char *

variable_types:
newpreload
char *


decompiled_code:
void *__fastcall dlsym_libc(char *name)
{
void *v1; // rax
void *v2; // rbp
void *v3; // r12

v1 = dlopen(&LC0, 2);
if ( v1 )
{
v2 = v1;
v3 = dlsym(v1, name);
if ( !dlerror() )
return v3;
dlclose(v2);
}
*_errno_location() = 79;
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func0(char *name)
{
void *v1; // rax
void *v2; // rbp
void *v3; // r12

v1 = dlopen(&LC0, 2);
if ( v1 )
{
v2 = v1;
v3 = dlsym(v1, name);
if ( !dlerror() )
return v3;
dlclose(v2);
}
*_errno_location() = 79;
return 0LL;
}

original_code:
static void **dlsym_libc(const char *symbol) {
    void *libc = dlopen("", 0 | 0x00002);
    if (libc != ((void *)0)) {
        void *sym = dlsym(libc, symbol);
        if (dlerror() == ((void *)0))
            return sym;
        dlclose(libc);
    }
    ; ;
    (*__errno_location ()) = 79;
    return ((void *)0);
}

canonical_original_code:
static void **dlsym_libc(char *symbol) {
    void *libc = dlopen("", 0 | 0x00002);
    if (libc != ((void *)0)) {
        void *sym = dlsym(libc, symbol);
        if (dlerror() == ((void *)0))
            return sym;
        dlclose(libc);
    }
    ; ;
    (*__errno_location ()) = 79;
    return ((void *)0);
}

variable_types:
symbol
char *

variable_types:
libc
void *

variable_types:
sym
void *

return_type: void **


decompiled_code:
__int64 observe_handler()
{
__int64 result; // rax
char *v1; // r12
size_t v2; // rax

result = handler_0;
if ( !handler_0 )
{
v1 = getenv("OBSERVE_ROOT");
v2 = strlen(v1);
handler_0 = (__int64)malloc(v2 + 9);
sprintf((char *)handler_0, "%s/handle", v1);
result = handler_0;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax
char *v1; // r12
size_t v2; // rax

result = handler_0;
if ( !handler_0 )
{
v1 = getenv("OBSERVE_ROOT");
v2 = strlen(v1);
handler_0 = (__int64)malloc(v2 + 9);
sprintf((char *)handler_0, "%s/handle", v1);
result = handler_0;
}
return result;
}

original_code:
static const char *observe_handler() {
    static char *handler = ((void *)0);
    if (handler == ((void *)0)) {
        char *root = getenv("OBSERVE_ROOT");
        handler = (char *) malloc((strlen(root)
                    + sizeof("/" "handle") + 1) * sizeof(char));
        sprintf(handler, "%s" "/" "handle", root);
    }
    return handler;
}

canonical_original_code:
static char *observe_handler() {
    static char *handler = ((void *)0);
    if (handler == ((void *)0)) {
        char *root = getenv("OBSERVE_ROOT");
        handler = (char *) malloc((strlen(root)
                    + sizeof("/" "handle") + 1) * sizeof(char));
        sprintf(handler, "%s" "/" "handle", root);
    }
    return handler;
}

variable_types:
handler
char *

variable_types:
root
char *

return_type: char *


execve

decompiled_code:
__int64 __fastcall execve(char *s, const char **a2, const char **a3)
{
unsigned int (__fastcall *v4)(__int64, _QWORD *, void **); // rax
unsigned int (__fastcall *v5)(__int64, _QWORD *, void **); // rbx
void **v6; // r13
_QWORD *v7; // rbp
__int64 v8; // rax
struct stat v10; // [rsp+0h] [rbp-B8h] BYREF

v4 = (unsigned int (__fastcall *)(__int64, _QWORD *, void **))dlsym_libc("execve");
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = v4;
if ( stat(s, &v10) || (v10.st_mode & 0x40) == 0 )
return 0xFFFFFFFFLL;
v6 = reset_LD_PRELOAD(a3);
v7 = newargv(s, a2);
v8 = observe_handler();
return (unsigned int)-(v5(v8, v7, v6) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s, const char **a2, const char **a3)
{
unsigned int (__fastcall *v4)(__int64, _QWORD *, void **); // rax
unsigned int (__fastcall *v5)(__int64, _QWORD *, void **); // rbx
void **v6; // r13
_QWORD *v7; // rbp
__int64 v8; // rax
struct stat v10; // [rsp+0h] [rbp-B8h] BYREF

v4 = (unsigned int (__fastcall *)(__int64, _QWORD *, void **))func0("execve");
if ( !v4 )
return 0xFFFFFFFFLL;
v5 = v4;
if ( stat(s, &v10) || (v10.st_mode & 0x40) == 0 )
return 0xFFFFFFFFLL;
v6 = func3(a3);
v7 = newargv(s, a2);
v8 = func1();
return (unsigned int)-(v5(v8, v7, v6) != 0);
}

original_code:
int execve(const char *path, char *const argv[], char *const envp[]) {
    int (*actual)(const char *path, char *const argv[], char *const envp[]);
    *(void **) (&actual) = dlsym_libc("execve");
    if (actual == ((void *)0))
        return -1;
    {
 struct stat st;
 if (stat(path, &st) != 0 || (st.st_mode & 0100) == 0)
     return -1;
    }
    ; ; ; ;
    if (actual(observe_handler(), newargv(path, argv), reset_LD_PRELOAD(envp)) == 0)
 return 0;
    ; ;
    return -1;
}

canonical_original_code:
int execve(char *path, char *argv[], char *envp[]) {
    int (*actual)(char *path, char *argv[], char *envp[]);
    *(void **) (&actual) = dlsym_libc("execve");
    if (actual == ((void *)0))
        return -1;
    {
 struct stat st;
 if (stat(path, &st) != 0 || (st.st_mode & 0100) == 0)
     return -1;
    }
    ; ; ; ;
    if (actual(observe_handler(), newargv(path, argv), reset_LD_PRELOAD(envp)) == 0)
 return 0;
    ; ;
    return -1;
}

variable_types:
path
char *

variable_types:
argv
char *[]

variable_types:
envp
char *[]

variable_types: int (*)(char *path, char *argv[], char *envp[])

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


execvp

decompiled_code:
__int64 __fastcall execvp(char *s, const char **a2)
{
unsigned int (__fastcall *v2)(__int64, _QWORD *); // rax
unsigned int (__fastcall *v3)(__int64, _QWORD *); // rbx
_QWORD *v4; // rbp
__int64 v5; // rax

v2 = (unsigned int (__fastcall *)(__int64, _QWORD *))dlsym_libc("execvp");
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
reset_LD_PRELOAD(0LL);
v4 = newargv(s, a2);
v5 = observe_handler();
return (unsigned int)-(v3(v5, v4) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, const char **a2)
{
unsigned int (__fastcall *v2)(__int64, _QWORD *); // rax
unsigned int (__fastcall *v3)(__int64, _QWORD *); // rbx
_QWORD *v4; // rbp
__int64 v5; // rax

v2 = (unsigned int (__fastcall *)(__int64, _QWORD *))func0("execvp");
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
func3(0LL);
v4 = newargv(s, a2);
v5 = func1();
return (unsigned int)-(v3(v5, v4) != 0);
}

original_code:
int execvp(const char *file, char *const argv[]) {
    int (*actual)(const char *file, char *const argv[]);
    *(void **) (&actual) = dlsym_libc("execvp");
    if (actual == ((void *)0))
        return -1;
    ; ; ; ;
    reset_LD_PRELOAD(((void *)0));
    if (actual(observe_handler(), newargv(file, argv)) == 0)
 return 0;
    ; ;
    return -1;
}

canonical_original_code:
int execvp(char *file, char *argv[]) {
    int (*actual)(char *file, char *argv[]);
    *(void **) (&actual) = dlsym_libc("execvp");
    if (actual == ((void *)0))
        return -1;
    ; ; ; ;
    reset_LD_PRELOAD(((void *)0));
    if (actual(observe_handler(), newargv(file, argv)) == 0)
 return 0;
    ; ;
    return -1;
}

variable_types:
actual
int (*)(char *file, char *argv[])


execv

decompiled_code:
__int64 __fastcall execv(char *s, const char **a2)
{
unsigned int (__fastcall *v2)(__int64, _QWORD *); // rax
unsigned int (__fastcall *v3)(__int64, _QWORD *); // rbx
_QWORD *v4; // rbp
__int64 v5; // rax

v2 = (unsigned int (__fastcall *)(__int64, _QWORD *))dlsym_libc("execv");
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
reset_LD_PRELOAD(0LL);
v4 = newargv(s, a2);
v5 = observe_handler();
return (unsigned int)-(v3(v5, v4) != 0);
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s, const char **a2)
{
unsigned int (__fastcall *v2)(__int64, _QWORD *); // rax
unsigned int (__fastcall *v3)(__int64, _QWORD *); // rbx
_QWORD *v4; // rbp
__int64 v5; // rax

v2 = (unsigned int (__fastcall *)(__int64, _QWORD *))func0("execv");
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2;
func3(0LL);
v4 = newargv(s, a2);
v5 = func1();
return (unsigned int)-(v3(v5, v4) != 0);
}

original_code:
int execv(const char *path, char *const argv[]) {
    int (*actual)(const char *path, char *const argv[]);
    *(void **) (&actual) = dlsym_libc("execv");
    if (actual == ((void *)0))
        return -1;
    ; ; ; ;
    reset_LD_PRELOAD(((void *)0));
    if (actual(observe_handler(), newargv(path, argv)) == 0)
 return 0;
    ; ;
    return -1;
}

canonical_original_code:
int execv(char *path, char *argv[]) {
    int (*actual)(char *path, char *argv[]);
    *(void **) (&actual) = dlsym_libc("execv");
    if (actual == ((void *)0))
        return -1;
    ; ; ; ;
    reset_LD_PRELOAD(((void *)0));
    if (actual(observe_handler(), newargv(path, argv)) == 0)
 return 0;
    ; ;
    return -1;
}

variable_types:
actual
int (*)(char *path, char *argv[])


getIndexes

decompiled_code:
_BYTE *getIndexes()
{
__int64 v0; // rax
__int64 i; // rdx

v0 = 0LL;
for ( i = 49LL; ; i = a123456789abcde[v0] )
{
INDEXES[i] = v0++;
if ( v0 == 58 )
break;
}
return INDEXES;
}

canonical_decompiled_code:
_BYTE *func6()
{
__int64 v0; // rax
__int64 i; // rdx

v0 = 0LL;
for ( i = 49LL; ; i = a123456789abcde[v0] )
{
INDEXES[i] = v0++;
if ( v0 == 58 )
break;
}
return INDEXES;
}

original_code:
unsigned char * getIndexes(){
 int i;
 for (i = 0; i < 58; i++)
  INDEXES[(int)ALPHABET[i]] = i;
 return INDEXES;
}

canonical_original_code:
unsigned char *getIndexes(){
 int i;
 for (i = 0; i < 58; i++)
  INDEXES[(int)ALPHABET[i]] = i;
 return INDEXES;
}

variable_types: i int

return_type: unsigned char *


decompiled_code:
__int64 __fastcall divmod58(__int64 a1, int a2, int a3)
{
unsigned __int8 *v3; // rcx
__int64 v4; // rsi
unsigned int v5; // edx
unsigned __int8 *v6; // rsi
int v7; // eax
__int64 v8; // rax
int v9; // edx
unsigned __int64 v10; // rax

if ( a3 >= a2 )
return 0LL;
v3 = (unsigned __int8 *)(a1 + a3);
v4 = (unsigned int)(a2 - 1 - a3);
v5 = 0;
v6 = &v3[v4 + 1];
do
{
v7 = *v3++;
v8 = (v5 << 8) + v7;
v9 = v8;
v10 = (unsigned __int64)(2369637129LL * v8) >> 37;
*(v3 - 1) = v10;
v5 = v9 - 58 * v10;
}
while ( v3 != v6 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3)
{
unsigned __int8 *v3; // rcx
__int64 v4; // rsi
unsigned int v5; // edx
unsigned __int8 *v6; // rsi
int v7; // eax
__int64 v8; // rax
int v9; // edx
unsigned __int64 v10; // rax

if ( a3 >= a2 )
return 0LL;
v3 = (unsigned __int8 *)(a1 + a3);
v4 = (unsigned int)(a2 - 1 - a3);
v5 = 0;
v6 = &v3[v4 + 1];
do
{
v7 = *v3++;
v8 = (v5 << 8) + v7;
v9 = v8;
v10 = (unsigned __int64)(2369637129LL * v8) >> 37;
*(v3 - 1) = v10;
v5 = v9 - 58 * v10;
}
while ( v3 != v6 );
return v5;
}

original_code:
unsigned char divmod58(unsigned char *in, int inLen, int i){
 int rem = 0;
 for(;i<inLen; i++){
  rem = rem * 256 + in[i];
  in[i] = rem / 58;
  rem = rem % 58;
 }
 return rem & 0xFF;
}

variable_types:
in
unsigned char *

variable_types: inLen int

variable_types: rem int

return_type: unsigned char


decompiled_code:
__int64 __fastcall divmod256(__int64 a1, int a2, int a3)
{
__int64 v3; // rsi
unsigned __int8 *v4; // rdx
int v5; // ecx
unsigned __int8 *v6; // rsi
int v7; // eax
__int64 result; // rax

if ( a3 >= a2 )
return 0LL;
v3 = (unsigned int)(a2 - 1 - a3);
v4 = (unsigned __int8 *)(a1 + a3);
v5 = 0;
v6 = &v4[v3 + 1];
do
{
v7 = *v4++;
result = (unsigned int)(58 * v5 + v7);
*(v4 - 1) = BYTE1(result);
v5 = (unsigned __int8)result;
}
while ( v4 != v6 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
__int64 v3; // rsi
unsigned __int8 *v4; // rdx
int v5; // ecx
unsigned __int8 *v6; // rsi
int v7; // eax
__int64 result; // rax

if ( a3 >= a2 )
return 0LL;
v3 = (unsigned int)(a2 - 1 - a3);
v4 = (unsigned __int8 *)(a1 + a3);
v5 = 0;
v6 = &v4[v3 + 1];
do
{
v7 = *v4++;
result = (unsigned int)(58 * v5 + v7);
*(v4 - 1) = BYTE1(result);
v5 = (unsigned __int8)result;
}
while ( v4 != v6 );
return result;
}

original_code:
unsigned char divmod256(unsigned char *in, int inLen, int i){
 int rem = 0;
 for(;i<inLen; i++){
  rem = rem * 58 + in[i];
  in[i] = rem / 256;
  rem = rem % 256;
 }
 return rem & 0xFF;
}


repo: netskink/cli

decompiled_code:
// attributes: thunk
__int64 unit_test()
{
return parse_words();
}

canonical_decompiled_code:
__int64 func0()
{
return parse_words();
}

original_code:
void unit_test(char **words, int word_cnt) {
 parse_words(words,word_cnt);
}

variable_types:
words
char **


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc != 1 )
{
fprintf(stderr, "Usage: %s \n", *argv);
exit(1);
}
build_cmd_list(argc, argv, envp);
while ( !(unsigned int)prompt() )
;
exit(0);
}

original_code:
int main(int argc, char *argv[]) {
 int iRC;
 iRC=0;
 if (argc != 1) {
  fprintf(stderr, "Usage: %s \n",
  argv[0]);
  iRC=1;
  exit(iRC);
 }
 build_cmd_list();
 while(1) {
  if (prompt()) break;
 }
 exit(iRC);
}

variable_types: argc int

variable_types: iRC int


ReadLine

decompiled_code:
char *__fastcall ReadLine(char *dest)
{
int v1; // eax
char src[4]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
v1 = getchar();
*(_DWORD *)src = v1;
if ( v1 == 10 || v1 == -1 )
break;
strncat(dest, src, 0x4FuLL);
}
return dest;
}

canonical_decompiled_code:
char *__fastcall func0(char *dest)
{
int v1; // eax
char src[4]; // [rsp+Ch] [rbp-Ch] BYREF

while ( 1 )
{
v1 = getchar();
*(_DWORD *)src = v1;
if ( v1 == 10 || v1 == -1 )
break;
strncat(dest, src, 0x4FuLL);
}
return dest;
}

original_code:
char * ReadLine(char *pchLineBuffer) {
 char *pchChar;
 while (1) {
  int c = getchar();
  if (c=='\n' || c==(-1)) break;
  pchChar = (char *)&c;
  pchLineBuffer= (char *)strncat(pchLineBuffer,pchChar,79);
 }
 return pchLineBuffer;
}

canonical_original_code:
char *ReadLine(char *pchLineBuffer) {
 char *pchChar;
 while (1) {
  int c = getchar();
  if (c=='\n' || c==(-1)) break;
  pchChar = (char *)&c;
  pchLineBuffer= (char *)strncat(pchLineBuffer,pchChar,79);
 }
 return pchLineBuffer;
}

variable_types:
pchLineBuffer
char *

variable_types:
pchChar
char *

variable_types: c int


prompt

decompiled_code:
__int64 prompt()
{
char *v0; // rbp
unsigned int v1; // er12

printf("-> ");
v0 = (char *)malloc(0x50uLL);
ReadLine(v0);
v1 = process_line(v0);
free(v0);
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
char *v0; // rbp
unsigned int v1; // er12

printf("-> ");
v0 = (char *)malloc(0x50uLL);
func0(v0);
v1 = process_line(v0);
free(v0);
return v1;
}

original_code:
int prompt(void) {
 char *pchLineBuffer;
 int iRC=1;
 printf("-> ");
 pchLineBuffer = (char *)malloc(80);
 ReadLine(pchLineBuffer);
 iRC = process_line(pchLineBuffer);
 free(pchLineBuffer);
 return iRC;
}

canonical_original_code:
int prompt() {
 char *pchLineBuffer;
 int iRC = 1;
 printf("-> ");
 pchLineBuffer = (char *)malloc(80);
 ReadLine(pchLineBuffer);
 iRC = process_line(pchLineBuffer);
 free(pchLineBuffer);
 return iRC;
}


Echo

decompiled_code:
__int64 __fastcall Echo(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbp
__int64 i; // rbx
const char *v6; // rdx
__int64 v7; // rsi

v4 = a3;
puts("echo command");
if ( (int)v4 > 0 )
{
for ( i = 0LL; i != v4; ++i )
{
v6 = *(const char **)(a2 + 8 * i);
v7 = (unsigned int)i;
printf("words[%d] = %s\n", v7, v6);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rbp
__int64 i; // rbx
const char *v6; // rdx
__int64 v7; // rsi

v4 = a3;
puts("echo command");
if ( (int)v4 > 0 )
{
for ( i = 0LL; i != v4; ++i )
{
v6 = *(const char **)(a2 + 8 * i);
v7 = (unsigned int)i;
printf("words[%d] = %s\n", v7, v6);
}
}
return 0LL;
}

original_code:
int Echo(struct command *pCmd, char **words, int word_cnt) {
 int i, iRC = 0;
 printf("echo command\n");
 for (i=0;i<word_cnt;i++) {
  printf("words[%d] = %s\n", i, words[i]);
 }
 return iRC;
}

canonical_original_code:
int Echo(struct command *pCmd, char **words, int word_cnt) {
 int i; int iRC = 0;
 printf("echo command\n");
 for (i=0;i<word_cnt;i++) {
  printf("words[%d] = %s\n", i, words[i]);
 }
 return iRC;
}

variable_types: struct command { char *word; char *help_text; unsigned int code; int (*pFunc)(struct command *pCmd, char **words, int word_cnt); } *


Help

decompiled_code:
__int64 __fastcall Help(__int64 a1)
{
puts("Available commands:");
puts(*(const char **)(a1 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
puts("Available commands:");
puts(*(const char **)(a1 + 8));
return 0LL;
}

original_code:
int Help(struct command *pCmd, char **words, int word_cnt) {
 int iRC = 0;
 printf("Available commands:\n");
 printf("%s\n",pCmd->help_text);
 return iRC;
}

user_defined_types: struct command { char *word; char *help_text; unsigned int code; int (*pFunc)(struct command *pCmd, char **words, int word_cnt); }


ReadFile

decompiled_code:
__int64 ReadFile()
{
puts("readfile called");
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
puts("readfile called");
return 0LL;
}

original_code:
int ReadFile(struct command *pCmd, char **words, int word_cnt) {
 printf("readfile called\n");
 return 0;
}


WriteFile

decompiled_code:
__int64 WriteFile()
{
puts("writefile called");
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
puts("writefile called");
return 0LL;
}

original_code:
int WriteFile(struct command *pCmd, char **words, int word_cnt) {
 printf("writefile called\n");
 return 0;
}


Quit

decompiled_code:
void __noreturn Quit()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func4()
{
exit(0);
}

original_code:
int Quit(struct command *pCmd, char **words, int word_cnt) {
 exit(0);
}


doAssignment

decompiled_code:
__int64 __fastcall doAssignment(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, const char *a7)
{
printf("doAssignment %s %s\n", a7, a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, const char *a7)
{
printf("doAssignment %s %s\n", a7, a1);
return 0LL;
}

original_code:
int doAssignment(struct variable sVar,char *pValue) {
 int i, iRC = 0;
 printf("doAssignment %s %s\n",sVar.pName, pValue);
 return iRC;
}

canonical_original_code:
int doAssignment(struct variable sVar, char *pValue) {
 int i; int iRC = 0;
 printf("doAssignment %s %s\n",sVar.pName, pValue);
 return iRC;
}

variable_types: struct variable { char *pName; enum var_type_t { eINT=0, eSTRING=1, eBUFFER=2 } type; void *pValue; int iValueSize; }

variable_types:
pValue
char *

user_defined_types: struct variable { char *pName; enum var_type_t type; void *pValue; int iValueSize; }


decompiled_code:
int dump_cmd_list()
{
__int64 i; // rbx
__int64 v1; // rax
const char *v2; // rsi

for ( i = 0LL; i != 320; i += 32LL )
{
v1 = i + pCmdList;
v2 = *(const char **)(i + pCmdList);
if ( v2 )
{
printf("%s %x - ", v2, *(unsigned int *)(v1 + 16));
LODWORD(v1) = printf("%s \n", *(const char **)(pCmdList + i + 8));
}
}
return v1;
}

canonical_decompiled_code:
int func6()
{
__int64 i; // rbx
__int64 v1; // rax
const char *v2; // rsi

for ( i = 0LL; i != 320; i += 32LL )
{
v1 = i + pCmdList;
v2 = *(const char **)(i + pCmdList);
if ( v2 )
{
printf("%s %x - ", v2, *(unsigned int *)(v1 + 16));
LODWORD(v1) = printf("%s \n", *(const char **)(pCmdList + i + 8));
}
}
return v1;
}

original_code:
void dump_cmd_list(void) {
 int i;
 for(i=0;i<coniNumCommands ;i++) {
  if (((void *)0) != pCmdList[i].word ) {
   printf("%s %x - ", pCmdList[i].word, pCmdList[i].code);
   printf("%s \n", pCmdList[i].help_text);
  }
 }
}

canonical_original_code:
void dump_cmd_list() {
 int i;
 for(i=0;i<coniNumCommands ;i++) {
  if (((void *)0) != pCmdList[i].word ) {
   printf("%s %x - ", pCmdList[i].word, pCmdList[i].code);
   printf("%s \n", pCmdList[i].help_text);
  }
 }
}


decompiled_code:
__int64 __fastcall variable_exists(char *s2)
{
const char **v1; // rbx
__int64 v2; // r12

if ( iNumVarUsed <= 0 )
return 0LL;
v1 = (const char **)pVariableList;
v2 = pVariableList + 32LL * (unsigned int)(iNumVarUsed - 1) + 32;
do
{
if ( !strcmp(*v1, s2) )
return 1LL;
v1 += 4;
}
while ( v1 != (const char **)v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2)
{
const char **v1; // rbx
__int64 v2; // r12

if ( iNumVarUsed <= 0 )
return 0LL;
v1 = (const char **)pVariableList;
v2 = pVariableList + 32LL * (unsigned int)(iNumVarUsed - 1) + 32;
do
{
if ( !strcmp(*v1, s2) )
return 1LL;
v1 += 4;
}
while ( v1 != (const char **)v2 );
return 0LL;
}

original_code:
int variable_exists(char *name) {
 int i, iRC = 0;
 for (i = 0; i<iNumVarUsed; i++) {
  if (0 == strcmp(pVariableList[i].pName,name)) {
   iRC = 1;
   return iRC;
  }
 }
 return iRC;
}

canonical_original_code:
int variable_exists(char *name) {
 int i; int iRC = 0;
 for (i = 0; i<iNumVarUsed; i++) {
  if (0 == strcmp(pVariableList[i].pName,name)) {
   iRC = 1;
   return iRC;
  }
 }
 return iRC;
}

variable_types:
name
char *


Set

decompiled_code:
__int64 __fastcall Set(__int64 a1, __int64 a2, int a3)
{
const char *v3; // r8
char *v4; // rdi
int i; // er12
__int64 v6; // rbx
int v7; // eax
int v8; // eax
char *v9; // rax
const char *v10; // rbp
size_t v11; // rax
char **v12; // rbx
char *v13; // rax
_DWORD *v14; // rax
char *v15; // rax
__int64 result; // rax
__int64 v17; // r12
__int64 v18; // rbx
__int64 v19; // rdx
int v20; // eax
__int64 v21; // rax
__int64 v22; // rbp
__int64 v23; // rsi
char *save_ptr; // [rsp+8h] [rbp-30h] BYREF

if ( a3 == 1 )
{
v17 = 0LL;
puts("variables in use:");
if ( iNumVarUsed > 0 )
{
do
{
v18 = 32 * v17;
printf("%s = ", *(const char **)(pVariableList + 32 * v17));
v19 = 32 * v17 + pVariableList;
v20 = *(_DWORD *)(v19 + 8);
if ( v20 )
{
if ( v20 == 1 )
{
printf("\"%s\"\n", *(const char **)(v19 + 16));
}
else if ( v20 == 2 )
{
printf("buffer with size %d\n", *(unsigned int *)(v19 + 24));
v21 = v18 + pVariableList;
if ( *(int *)(v18 + pVariableList + 24) > 0 )
{
v22 = 0LL;
do
{
v23 = (unsigned int)*(char *)(*(_QWORD *)(v21 + 16) + v22++);
printf("%x ", v23);
v21 = v18 + pVariableList;
}
while ( *(_DWORD *)(v18 + pVariableList + 24) > (int)v22 );
}
putchar(10);
}
else
{
puts("invalid type");
}
}
else
{
printf("0x%02X\n", **(unsigned int **)(v19 + 16));
}
++v17;
}
while ( iNumVarUsed > (int)v17 );
}
LABEL_21:
result = 0LL;
}
else
{
if ( a3 == 3 )
{
v3 = *(const char **)(a2 + 8);
if ( !strcmp("int", v3) )
{
*(_DWORD *)(pVariableList + 32LL * iNumVarUsed + 8) = 0;
goto LABEL_6;
}
if ( !strcmp("string", v3) )
{
*(_DWORD *)(pVariableList + 32LL * iNumVarUsed + 8) = 1;
LABEL_6:
v4 = *(char **)(a2 + 16);
for ( i = 1; ; ++i )
{
v9 = strtok_r(v4, "=", &save_ptr);
v10 = v9;
if ( !v9 )
{
++iNumVarUsed;
goto LABEL_21;
}
if ( i == 1 )
{
if ( (unsigned int)variable_exists(v9) )
{
puts("variable exists already. Input ignored.");
return 0xFFFFFFFFLL;
}
v11 = strlen(v10);
v12 = (char **)(pVariableList + 32LL * iNumVarUsed);
v13 = (char *)malloc(v11 + 1);
*v12 = v13;
strcpy(v13, v10);
}
else if ( i == 2 )
{
v6 = pVariableList + 32LL * iNumVarUsed;
v7 = *(_DWORD *)(v6 + 8);
if ( v7 )
{
if ( v7 == 1 )
{
v15 = (char *)malloc(0x50uLL);
*(_QWORD *)(v6 + 16) = v15;
strcpy(v15, v10);
}
else
{
if ( v7 != 2 )
return 0xFFFFFFFFLL;
v8 = atoi(v10);
*(_DWORD *)(v6 + 24) = v8;
*(_QWORD *)(v6 + 16) = malloc(v8);
}
}
else
{
v14 = malloc(4uLL);
*(_QWORD *)(v6 + 16) = v14;
*v14 = atoi(v10);
}
}
v4 = 0LL;
}
}
if ( !strcmp("buffer", v3) )
{
*(_DWORD *)(pVariableList + 32LL * iNumVarUsed + 8) = 2;
goto LABEL_6;
}
}
puts("usage: set <int|string|buffer> <name>=<value|size>");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, int a3)
{
const char *v3; // r8
char *v4; // rdi
int i; // er12
__int64 v6; // rbx
int v7; // eax
int v8; // eax
char *v9; // rax
const char *v10; // rbp
size_t v11; // rax
char **v12; // rbx
char *v13; // rax
_DWORD *v14; // rax
char *v15; // rax
__int64 result; // rax
__int64 v17; // r12
__int64 v18; // rbx
__int64 v19; // rdx
int v20; // eax
__int64 v21; // rax
__int64 v22; // rbp
__int64 v23; // rsi
char *save_ptr; // [rsp+8h] [rbp-30h] BYREF

if ( a3 == 1 )
{
v17 = 0LL;
puts("variables in use:");
if ( iNumVarUsed > 0 )
{
do
{
v18 = 32 * v17;
printf("%s = ", *(const char **)(pVariableList + 32 * v17));
v19 = 32 * v17 + pVariableList;
v20 = *(_DWORD *)(v19 + 8);
if ( v20 )
{
if ( v20 == 1 )
{
printf("\"%s\"\n", *(const char **)(v19 + 16));
}
else if ( v20 == 2 )
{
printf("buffer with size %d\n", *(unsigned int *)(v19 + 24));
v21 = v18 + pVariableList;
if ( *(int *)(v18 + pVariableList + 24) > 0 )
{
v22 = 0LL;
do
{
v23 = (unsigned int)*(char *)(*(_QWORD *)(v21 + 16) + v22++);
printf("%x ", v23);
v21 = v18 + pVariableList;
}
while ( *(_DWORD *)(v18 + pVariableList + 24) > (int)v22 );
}
putchar(10);
}
else
{
puts("invalid type");
}
}
else
{
printf("0x%02X\n", **(unsigned int **)(v19 + 16));
}
++v17;
}
while ( iNumVarUsed > (int)v17 );
}
LABEL_21:
result = 0LL;
}
else
{
if ( a3 == 3 )
{
v3 = *(const char **)(a2 + 8);
if ( !strcmp("int", v3) )
{
*(_DWORD *)(pVariableList + 32LL * iNumVarUsed + 8) = 0;
goto LABEL_6;
}
if ( !strcmp("string", v3) )
{
*(_DWORD *)(pVariableList + 32LL * iNumVarUsed + 8) = 1;
LABEL_6:
v4 = *(char **)(a2 + 16);
for ( i = 1; ; ++i )
{
v9 = strtok_r(v4, "=", &save_ptr);
v10 = v9;
if ( !v9 )
{
++iNumVarUsed;
goto LABEL_21;
}
if ( i == 1 )
{
if ( (unsigned int)func7(v9) )
{
puts("variable exists already. Input ignored.");
return 0xFFFFFFFFLL;
}
v11 = strlen(v10);
v12 = (char **)(pVariableList + 32LL * iNumVarUsed);
v13 = (char *)malloc(v11 + 1);
*v12 = v13;
strcpy(v13, v10);
}
else if ( i == 2 )
{
v6 = pVariableList + 32LL * iNumVarUsed;
v7 = *(_DWORD *)(v6 + 8);
if ( v7 )
{
if ( v7 == 1 )
{
v15 = (char *)malloc(0x50uLL);
*(_QWORD *)(v6 + 16) = v15;
strcpy(v15, v10);
}
else
{
if ( v7 != 2 )
return 0xFFFFFFFFLL;
v8 = atoi(v10);
*(_DWORD *)(v6 + 24) = v8;
*(_QWORD *)(v6 + 16) = malloc(v8);
}
}
else
{
v14 = malloc(4uLL);
*(_QWORD *)(v6 + 16) = v14;
*v14 = atoi(v10);
}
}
v4 = 0LL;
}
}
if ( !strcmp("buffer", v3) )
{
*(_DWORD *)(pVariableList + 32LL * iNumVarUsed + 8) = 2;
goto LABEL_6;
}
}
puts("usage: set <int|string|buffer> <name>=<value|size>");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int Set(struct command *pCmd, char **words, int word_cnt) {
 char *str1, *token;
 char *saveptr1;
 int j;
 int i, iRC = 0;
 int value;
 for (i=0;i<word_cnt;i++) {
 }
 if (1 == word_cnt) {
  printf("variables in use:\n");
  for (i = 0; i<iNumVarUsed; i++) {
   printf("%s = ",pVariableList[i].pName);
   if (eINT == pVariableList[i].type) {
    printf("0x%02X\n",*(int *) pVariableList[i].pValue);
   } else if (eSTRING == pVariableList[i].type){
    printf("\"%s\"\n",(char *) pVariableList[i].pValue);
   } else if (eBUFFER == pVariableList[i].type) {
    printf("buffer with size %d\n",pVariableList[i].iValueSize);
    for (j=0;j<pVariableList[i].iValueSize;j++) {
     printf("%x ",((char *) (pVariableList[i].pValue))[j]);
    }
    printf("\n");
   } else {
    printf("invalid type\n");
   }
  }
  return iRC;
 }
 if (3 != word_cnt) {
  printf("usage: set <int|string|buffer> <name>=<value|size>\n");
  iRC=-1;
  return iRC;
 }
 if (0 == strcmp("int",words[1])) {
  pVariableList[iNumVarUsed].type=eINT;
 } else if (0 == strcmp("string",words[1])) {
  pVariableList[iNumVarUsed].type=eSTRING;
 } else if (0 == strcmp("buffer",words[1])) {
  pVariableList[iNumVarUsed].type=eBUFFER;
 } else {
  printf("usage: set <int|string|buffer> <name>=<value|size>\n");
  iRC=-1;
  return iRC;
 }
 for (j = 1, str1 = words[2]; ; j++, str1 = ((void *)0)) {
  token = strtok_r(str1, "=", &saveptr1);
  if (token == ((void *)0))
   break;
  if (1==j) {
   if (variable_exists(token)) {
    printf("variable exists already. Input ignored.\n");
    iRC=-1;
    return iRC;
   }
   pVariableList[iNumVarUsed].pName = (char*) malloc(strlen(token)+1);
   strcpy(pVariableList[iNumVarUsed].pName,token);
  }
  if (2==j) {
   if (eINT == pVariableList[iNumVarUsed].type) {
    pVariableList[iNumVarUsed].pValue = (int *) malloc(4);
    value = atoi(token);
    memcpy(pVariableList[iNumVarUsed].pValue,&value,4);
   } else if (eSTRING == pVariableList[iNumVarUsed].type) {
    pVariableList[iNumVarUsed].pValue = (char *) malloc(80);
    strcpy( (char *) pVariableList[iNumVarUsed].pValue, token);
   } else if (eBUFFER == pVariableList[iNumVarUsed].type) {
    value = atoi(token);
    pVariableList[iNumVarUsed].iValueSize = value;
    pVariableList[iNumVarUsed].pValue = (char *) malloc(value);
   } else {
    iRC=-1;
    return iRC;
   }
  }
 }
 iNumVarUsed++;
 return iRC;
}

canonical_original_code:
int Set(struct command *pCmd, char **words, int word_cnt) {
 char *str1; char *token;
 char *saveptr1;
 int j;
 int i; int iRC = 0;
 int value;
 for (i=0;i<word_cnt;i++) {
 }
 if (1 == word_cnt) {
  printf("variables in use:\n");
  for (i = 0; i<iNumVarUsed; i++) {
   printf("%s = ",pVariableList[i].pName);
   if (eINT == pVariableList[i].type) {
    printf("0x%02X\n",*(int *) pVariableList[i].pValue);
   } else if (eSTRING == pVariableList[i].type){
    printf("\"%s\"\n",(char *) pVariableList[i].pValue);
   } else if (eBUFFER == pVariableList[i].type) {
    printf("buffer with size %d\n",pVariableList[i].iValueSize);
    for (j=0;j<pVariableList[i].iValueSize;j++) {
     printf("%x ",((char *) (pVariableList[i].pValue))[j]);
    }
    printf("\n");
   } else {
    printf("invalid type\n");
   }
  }
  return iRC;
 }
 if (3 != word_cnt) {
  printf("usage: set <int|string|buffer> <name>=<value|size>\n");
  iRC=-1;
  return iRC;
 }
 if (0 == strcmp("int",words[1])) {
  pVariableList[iNumVarUsed].type=eINT;
 } else if (0 == strcmp("string",words[1])) {
  pVariableList[iNumVarUsed].type=eSTRING;
 } else if (0 == strcmp("buffer",words[1])) {
  pVariableList[iNumVarUsed].type=eBUFFER;
 } else {
  printf("usage: set <int|string|buffer> <name>=<value|size>\n");
  iRC=-1;
  return iRC;
 }
 for (j = 1, str1 = words[2]; ; j++, str1 = ((void *)0)) {
  token = strtok_r(str1, "=", &saveptr1);
  if (token == ((void *)0))
   break;
  if (1==j) {
   if (variable_exists(token)) {
    printf("variable exists already. Input ignored.\n");
    iRC=-1;
    return iRC;
   }
   pVariableList[iNumVarUsed].pName = (char *) malloc(strlen(token)+1);
   strcpy(pVariableList[iNumVarUsed].pName,token);
  }
  if (2==j) {
   if (eINT == pVariableList[iNumVarUsed].type) {
    pVariableList[iNumVarUsed].pValue = (int *) malloc(4);
    value = atoi(token);
    memcpy(pVariableList[iNumVarUsed].pValue,&value,4);
   } else if (eSTRING == pVariableList[iNumVarUsed].type) {
    pVariableList[iNumVarUsed].pValue = (char *) malloc(80);
    strcpy( (char *) pVariableList[iNumVarUsed].pValue, token);
   } else if (eBUFFER == pVariableList[iNumVarUsed].type) {
    value = atoi(token);
    pVariableList[iNumVarUsed].iValueSize = value;
    pVariableList[iNumVarUsed].pValue = (char *) malloc(value);
   } else {
    iRC=-1;
    return iRC;
   }
  }
 }
 iNumVarUsed++;
 return iRC;
}

variable_types:
token
char *

variable_types: j int

variable_types: value int


decompiled_code:
__int64 __fastcall calc_crc(const char *a1)
{
int v1; // eax
__int64 v2; // rsi
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rdx

v1 = strlen(a1);
if ( v1 <= 0 )
return 2863311530LL;
v2 = (unsigned int)(v1 - 1);
v3 = 0LL;
LODWORD(result) = -1431655766;
do
{
result = a1[v3] ^ ((unsigned int)result >> v3);
v5 = v3++;
}
while ( v2 != v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
int v1; // eax
__int64 v2; // rsi
__int64 v3; // rcx
__int64 result; // rax
__int64 v5; // rdx

v1 = strlen(a1);
if ( v1 <= 0 )
return 2863311530LL;
v2 = (unsigned int)(v1 - 1);
v3 = 0LL;
LODWORD(result) = -1431655766;
do
{
result = a1[v3] ^ ((unsigned int)result >> v3);
v5 = v3++;
}
while ( v2 != v5 );
return result;
}

original_code:
unsigned int calc_crc(char *word) {
 unsigned int uiCode = 0xAAAAAAAA;
 int i;
 int len;
 len = strlen(word);
 for (i=0;i<len;i++) {
  uiCode = word[i] ^ (uiCode>>i);
 }
 return uiCode;
}

variable_types:
word
char *

variable_types:
uiCode
unsigned int

variable_types: i int

variable_types: len int

return_type: unsigned int


original_code:
void build_cmd_list(void) {
 int i=0;
 pCmdList = (struct command *) malloc(sizeof(struct command)*coniNumCommands);
 bzero(pCmdList,sizeof(struct command)*coniNumCommands);
 pVariableList = (struct variable *) malloc(sizeof(struct variable)*coniNumVariables);
 bzero(pVariableList,sizeof(struct variable)*coniNumVariables);
 pCmdList[i].word = (char *)malloc(strlen("help")+1);
 strcpy(pCmdList[i].word,"help");
 pCmdList[i].help_text = (char *)malloc(strlen("readFile writeFile quit set echo")+1);
 strcpy(pCmdList[i].help_text,"readFile writeFile quit set echo");
 pCmdList[i].pFunc=Help;
 pCmdList[i].code = calc_crc("help");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("readfile")+1);
 strcpy(pCmdList[i].word,"readfile");
 pCmdList[i].help_text = (char *)malloc(strlen("This is the readfile command.")+1);
 strcpy(pCmdList[i].help_text,"This is the readfile command.");
 pCmdList[i].pFunc=ReadFile;
 pCmdList[i].code = calc_crc("readfile");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("writefile")+1);
 strcpy(pCmdList[i].word,"writefile");
 pCmdList[i].help_text = (char *)malloc(strlen("This is the writefile command.")+1);
 strcpy(pCmdList[i].help_text,"This is the writefile command.");
 pCmdList[i].pFunc=WriteFile;
 pCmdList[i].code = calc_crc("writefile");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("quit")+1);
 strcpy(pCmdList[i].word,"quit");
 pCmdList[i].help_text = (char *)malloc(strlen("This is the quit command.")+1);
 strcpy(pCmdList[i].help_text,"This is the quit command.");
 pCmdList[i].pFunc=Quit;
 pCmdList[i].code = calc_crc("quit");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("set")+1);
 strcpy(pCmdList[i].word,"set");
 pCmdList[i].help_text = (char *)malloc(strlen("usage: set <int|string> <name>=<value> \n usage: set <buffer> <name>=<size>")+1);
 strcpy(pCmdList[i].help_text,"usage: set <int|string> <name>=<value> \n usage: set <buffer> <name>=<size>");
 pCmdList[i].pFunc=Set;
 pCmdList[i].code = calc_crc("set");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("echo")+1);
 strcpy(pCmdList[i].word,"echo");
 pCmdList[i].help_text = (char *)malloc(strlen("This is the echo command.")+1);
 strcpy(pCmdList[i].help_text,"This is the echo command.");
 pCmdList[i].pFunc=Echo;
 pCmdList[i].code = calc_crc("echo");
 i++;
}

canonical_original_code:
void build_cmd_list() {
 int i = 0;
 pCmdList = (struct command *) malloc(sizeof(struct command)*coniNumCommands);
 bzero(pCmdList,sizeof(struct command)*coniNumCommands);
 pVariableList = (struct variable *) malloc(sizeof(struct variable)*coniNumVariables);
 bzero(pVariableList,sizeof(struct variable)*coniNumVariables);
 pCmdList[i].word = (char *)malloc(strlen("help")+1);
 strcpy(pCmdList[i].word,"help");
 pCmdList[i].help_text = (char *)malloc(strlen("readFile writeFile quit set echo")+1);
 strcpy(pCmdList[i].help_text,"readFile writeFile quit set echo");
 pCmdList[i].pFunc=Help;
 pCmdList[i].code = calc_crc("help");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("readfile")+1);
 strcpy(pCmdList[i].word,"readfile");
 pCmdList[i].help_text = (char *)malloc(strlen("This is the readfile command.")+1);
 strcpy(pCmdList[i].help_text,"This is the readfile command.");
 pCmdList[i].pFunc=ReadFile;
 pCmdList[i].code = calc_crc("readfile");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("writefile")+1);
 strcpy(pCmdList[i].word,"writefile");
 pCmdList[i].help_text = (char *)malloc(strlen("This is the writefile command.")+1);
 strcpy(pCmdList[i].help_text,"This is the writefile command.");
 pCmdList[i].pFunc=WriteFile;
 pCmdList[i].code = calc_crc("writefile");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("quit")+1);
 strcpy(pCmdList[i].word,"quit");
 pCmdList[i].help_text = (char *)malloc(strlen("This is the quit command.")+1);
 strcpy(pCmdList[i].help_text,"This is the quit command.");
 pCmdList[i].pFunc=Quit;
 pCmdList[i].code = calc_crc("quit");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("set")+1);
 strcpy(pCmdList[i].word,"set");
 pCmdList[i].help_text = (char *)malloc(strlen("usage: set <int|string> <name>=<value> \n usage: set <buffer> <name>=<size>")+1);
 strcpy(pCmdList[i].help_text,"usage: set <int|string> <name>=<value> \n usage: set <buffer> <name>=<size>");
 pCmdList[i].pFunc=Set;
 pCmdList[i].code = calc_crc("set");
 i++;
 pCmdList[i].word = (char *)malloc(strlen("echo")+1);
 strcpy(pCmdList[i].word,"echo");
 pCmdList[i].help_text = (char *)malloc(strlen("This is the echo command.")+1);
 strcpy(pCmdList[i].help_text,"This is the echo command.");
 pCmdList[i].pFunc=Echo;
 pCmdList[i].code = calc_crc("echo");
 i++;
}

user_defined_types: enum var_type_t { eINT=0, eSTRING=1, eBUFFER=2 }


decompiled_code:
__int64 __fastcall parse_words(const char **a1, int a2)
{
const char **v2; // rbx
const char *v3; // r14
int v4; // edx
__int64 v5; // rax
__int64 v6; // rcx
const char *v7; // rbp
unsigned int v8; // er12
size_t v9; // rbx
void *v10; // rax
char *i; // rdi
char *v12; // rax
const char *v13; // rbp
const char **v15; // rbx
__int64 v16; // r13
char *save_ptr; // [rsp+8h] [rbp-30h] BYREF

puts("parse_words()");
if ( a2 > 0 )
{
v2 = a1;
while ( 2 )
{
printf("Looking for %s\n", *v2);
v3 = *v2;
v4 = calc_crc(*v2);
v5 = pCmdList;
v6 = pCmdList + 320;
do
{
if ( *(_DWORD *)(v5 + 16) == v4 )
{
(*(void (__fastcall **)(__int64, const char **, _QWORD, __int64))(v5 + 24))(v5, a1, (unsigned int)a2, v6);
return 0LL;
}
v5 += 32LL;
}
while ( v5 != v6 );
++v2;
printf("%s is unrecognized command\n", v3);
if ( v2 != &a1[(unsigned int)(a2 - 1) + 1] )
continue;
break;
}
}
v7 = *a1;
v8 = 1;
v9 = strlen(*a1);
v10 = malloc((int)v9 + 1);
for ( i = (char *)memcpy(v10, v7, v9 + 1); ; i = 0LL )
{
v12 = strtok_r(i, "=", &save_ptr);
v13 = v12;
if ( !v12 )
break;
printf("%d: %s\n", v8, v12);
if ( v8 == 1 )
{
if ( iNumVarUsed <= 0 )
{
LABEL_18:
printf("%s is unrecognized variable\n", v13);
return 0xFFFFFFFFLL;
}
v15 = (const char **)pVariableList;
v16 = pVariableList + 32LL * (unsigned int)(iNumVarUsed - 1) + 32;
while ( strcmp(*v15, v13) )
{
v15 += 4;
if ( (const char **)v16 == v15 )
goto LABEL_18;
}
}
else if ( v8 == 2 )
{
printf("%s is value\n", v13);
}
++v8;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char **a1, int a2)
{
const char **v2; // rbx
const char *v3; // r14
int v4; // edx
__int64 v5; // rax
__int64 v6; // rcx
const char *v7; // rbp
unsigned int v8; // er12
size_t v9; // rbx
void *v10; // rax
char *i; // rdi
char *v12; // rax
const char *v13; // rbp
const char **v15; // rbx
__int64 v16; // r13
char *save_ptr; // [rsp+8h] [rbp-30h] BYREF

puts("parse_words()");
if ( a2 > 0 )
{
v2 = a1;
while ( 2 )
{
printf("Looking for %s\n", *v2);
v3 = *v2;
v4 = func9(*v2);
v5 = pCmdList;
v6 = pCmdList + 320;
do
{
if ( *(_DWORD *)(v5 + 16) == v4 )
{
(*(void (__fastcall **)(__int64, const char **, _QWORD, __int64))(v5 + 24))(v5, a1, (unsigned int)a2, v6);
return 0LL;
}
v5 += 32LL;
}
while ( v5 != v6 );
++v2;
printf("%s is unrecognized command\n", v3);
if ( v2 != &a1[(unsigned int)(a2 - 1) + 1] )
continue;
break;
}
}
v7 = *a1;
v8 = 1;
v9 = strlen(*a1);
v10 = malloc((int)v9 + 1);
for ( i = (char *)memcpy(v10, v7, v9 + 1); ; i = 0LL )
{
v12 = strtok_r(i, "=", &save_ptr);
v13 = v12;
if ( !v12 )
break;
printf("%d: %s\n", v8, v12);
if ( v8 == 1 )
{
if ( iNumVarUsed <= 0 )
{
LABEL_18:
printf("%s is unrecognized variable\n", v13);
return 0xFFFFFFFFLL;
}
v15 = (const char **)pVariableList;
v16 = pVariableList + 32LL * (unsigned int)(iNumVarUsed - 1) + 32;
while ( strcmp(*v15, v13) )
{
v15 += 4;
if ( (const char **)v16 == v15 )
goto LABEL_18;
}
}
else if ( v8 == 2 )
{
printf("%s is value\n", v13);
}
++v8;
}
return 1LL;
}

original_code:
int parse_words(char **words, int word_cnt) {
 int i,j,k;
 unsigned int uiCode;
 int iRC;
 int found;
 char *pBuf;
 int iLen;
 char *str1, *token;
 char *saveptr1;
 struct variable *pVariable;
 printf("parse_words()\n");
 for (i=0;i<word_cnt;i++) {
  printf("Looking for %s\n",words[i]);
  uiCode = calc_crc(words[i]);
  found=0;
  for (j=0; j<coniNumCommands; j++) {
   if (pCmdList[j].code == uiCode) {
    pCmdList[j].pFunc(&(pCmdList[j]),words,word_cnt);
    found=1;
    return 0;
   }
  }
  if (0==found) {
   printf("%s is unrecognized command\n",words[i]);
  }
 }
 iLen=strlen(words[0]);
 pBuf=(char *)malloc(iLen+1);
 strcpy(pBuf,words[0]);
 for (j = 1, str1 = pBuf; ; j++, str1 = ((void *)0)) {
  token = strtok_r(str1, "=", &saveptr1);
  if (token == ((void *)0))
   break;
  printf("%d: %s\n", j, token);
  if (1==j) {
   found=0;
   for (k=0; k<iNumVarUsed; k++) {
    if (0 == strcmp(pVariableList[k].pName,token)) {
     found=1;
     break;
    }
   }
   if (0==found) {
    printf("%s is unrecognized variable\n",token);
    return -1;
   }
  }
  if (2==j) {
   printf("%s is value\n",token);
  }
 }
 return 1;
}

canonical_original_code:
int parse_words(char **words, int word_cnt) {
 int i; int j; int k;
 unsigned int uiCode;
 int iRC;
 int found;
 char *pBuf;
 int iLen;
 char *str1; char *token;
 char *saveptr1;
 struct variable *pVariable;
 printf("parse_words()\n");
 for (i=0;i<word_cnt;i++) {
  printf("Looking for %s\n",words[i]);
  uiCode = calc_crc(words[i]);
  found=0;
  for (j=0; j<coniNumCommands; j++) {
   if (pCmdList[j].code == uiCode) {
    pCmdList[j].pFunc(&(pCmdList[j]),words,word_cnt);
    found=1;
    return 0;
   }
  }
  if (0==found) {
   printf("%s is unrecognized command\n",words[i]);
  }
 }
 iLen=strlen(words[0]);
 pBuf=(char *)malloc(iLen+1);
 strcpy(pBuf,words[0]);
 for (j = 1, str1 = pBuf; ; j++, str1 = ((void *)0)) {
  token = strtok_r(str1, "=", &saveptr1);
  if (token == ((void *)0))
   break;
  printf("%d: %s\n", j, token);
  if (1==j) {
   found=0;
   for (k=0; k<iNumVarUsed; k++) {
    if (0 == strcmp(pVariableList[k].pName,token)) {
     found=1;
     break;
    }
   }
   if (0==found) {
    printf("%s is unrecognized variable\n",token);
    return -1;
   }
  }
  if (2==j) {
   printf("%s is value\n",token);
  }
 }
 return 1;
}

variable_types:
words
char **

variable_types: k int

variable_types: found int

variable_types:
pBuf
char *

variable_types: iLen int

variable_types: struct variable { char *pName; enum var_type_t { eINT=0, eSTRING=1, eBUFFER=2 } type; void *pValue; int iValueSize; } *


decompiled_code:
__int64 __fastcall process_line(char *s)
{
__int64 v2; // rbx
const char **v3; // r12
size_t v4; // rax
char *v5; // rax
const char *v6; // rsi
char *v7; // rax
char *v8; // rbp
char *save_ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = 0LL;
v3 = (const char **)calloc(0x78uLL, 1uLL);
while ( 1 )
{
v7 = strtok_r(s, " ", &save_ptr);
v8 = v7;
if ( !v7 )
break;
v4 = strlen(v7);
v5 = (char *)malloc(v4 + 1);
v6 = v8;
s = 0LL;
v3[v2++] = v5;
strcpy(v5, v6);
}
parse_words(v3, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *s)
{
__int64 v2; // rbx
const char **v3; // r12
size_t v4; // rax
char *v5; // rax
const char *v6; // rsi
char *v7; // rax
char *v8; // rbp
char *save_ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = 0LL;
v3 = (const char **)calloc(0x78uLL, 1uLL);
while ( 1 )
{
v7 = strtok_r(s, " ", &save_ptr);
v8 = v7;
if ( !v7 )
break;
v4 = strlen(v7);
v5 = (char *)malloc(v4 + 1);
v6 = v8;
s = 0LL;
v3[v2++] = v5;
strcpy(v5, v6);
}
func11(v3, v2);
return 0LL;
}

original_code:
int process_line(char *line) {
 char **words;
 int word_cnt;
 char *str1, *token;
 char *saveptr1;
 int j;
 words=malloc(15*8);
 bzero(words,15*8);
 word_cnt=0;
 for (j = 1, str1 = line; ; j++, str1 = ((void *)0)) {
  token = strtok_r(str1, " ", &saveptr1);
  if (token == ((void *)0))
   break;
  words[word_cnt]=(char *) malloc(strlen(token)+1);
  strcpy(words[word_cnt++],token);
 }
 parse_words(words,word_cnt);
 return 0;
}

canonical_original_code:
int process_line(char *line) {
 char **words;
 int word_cnt;
 char *str1; char *token;
 char *saveptr1;
 int j;
 words=malloc(15*8);
 bzero(words,15*8);
 word_cnt=0;
 for (j = 1, str1 = line; ; j++, str1 = ((void *)0)) {
  token = strtok_r(str1, " ", &saveptr1);
  if (token == ((void *)0))
   break;
  words[word_cnt]=(char *) malloc(strlen(token)+1);
  strcpy(words[word_cnt++],token);
 }
 parse_words(words,word_cnt);
 return 0;
}

variable_types:
line
char *


decompiled_code:
void __fastcall dump_words(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
const char *v4; // r12
unsigned int v5; // eax
__int64 v6; // rsi

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(const char **)(a1 + 8 * i);
v5 = calc_crc(v4);
v6 = (unsigned int)i;
printf("words [%d] = %s %x\n", v6, v4, v5);
}
}
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
const char *v4; // r12
unsigned int v5; // eax
__int64 v6; // rsi

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(const char **)(a1 + 8 * i);
v5 = func9(v4);
v6 = (unsigned int)i;
printf("words [%d] = %s %x\n", v6, v4, v5);
}
}
}

original_code:
void dump_words(char **words, int word_cnt) {
 int i;
 for(i=0;i<word_cnt;i++) {
  printf("words [%d] = %s %x\n", i ,words[i], calc_crc(words[i]) );
 }
}


Nop

decompiled_code:
__int64 Nop()
{
puts("do nothing");
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
puts("do nothing");
return 0LL;
}

original_code:
int Nop(struct command *pCmd, char **words, int word_cnt) {
 printf("do nothing\n");
 return 0;
}

variable_types: struct command { char *word; char *help_text; unsigned int code; int (*pFunc)(struct command *pCmd, char **words, int word_cnt); } *


repo: netskink/google

decompiled_code:
__int64 __fastcall stack_not_empty(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
int stack_not_empty(stack_t *ps) {
    return (ps->size);
}

canonical_original_code:
int stack_not_empty(struct stack *ps) {
    return (ps->size);
}

variable_types: struct stack { unsigned long size; char items[100][256]; } *


pop

decompiled_code:
__int64 __fastcall pop(__int64 *a1)
{
__int64 v1; // rax

if ( !*a1 )
{
fwrite("Error: stack underflow!!!\n", 1uLL, 0x1AuLL, stderr);
abort();
}
v1 = *a1 - 1;
*a1 = v1;
return (__int64)&a1[32 * v1 + 1];
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1)
{
__int64 v1; // rax

if ( !*a1 )
{
fwrite("Error: stack underflow!!!\n", 1uLL, 0x1AuLL, stderr);
abort();
}
v1 = *a1 - 1;
*a1 = v1;
return (__int64)&a1[32 * v1 + 1];
}

original_code:
char * pop(stack_t *ps) {
    if (ps->size == 0){
        fputs("Error: stack underflow!!!\n", stderr);
        abort();
    } else {
        return ps->items[--ps->size];
 }
}

canonical_original_code:
char *pop(struct stack *ps) {
    if (ps->size == 0){
        fputs("Error: stack underflow!!!\n", stderr);
        abort();
    } else {
        return ps->items[--ps->size];
 }
}

user_defined_types: struct stack { unsigned long size; char items[100][256]; }


decompiled_code:
void __fastcall dump_stack(__int64 *a1)
{
const char *v1; // rax

while ( *a1 )
{
v1 = (const char *)pop(a1);
printf("%d %s\n", *(unsigned int *)a1, v1);
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 *a1)
{
const char *v1; // rax

while ( *a1 )
{
v1 = (const char *)func1(a1);
printf("%d %s\n", *(unsigned int *)a1, v1);
}
}

original_code:
void dump_stack(stack_t *ps) {
 while(ps->size != 0) {
  printf("%d %s\n",(int)ps->size,pop(ps));
 }
}

canonical_original_code:
void dump_stack(struct stack *ps) {
 while(ps->size != 0) {
  printf("%d %s\n",(int)ps->size,pop(ps));
 }
}


push

decompiled_code:
char *__fastcall push(__int64 *a1, const char *a2)
{
__int64 v2; // rax

v2 = *a1;
if ( *a1 == 100 )
{
fwrite("Error: stack overflow!!!\n", 1uLL, 0x19uLL, stderr);
dump_stack(a1);
abort();
}
*a1 = v2 + 1;
return strcpy((char *)&a1[32 * v2 + 1], a2);
}

canonical_decompiled_code:
char *__fastcall func3(__int64 *a1, const char *a2)
{
__int64 v2; // rax

v2 = *a1;
if ( *a1 == 100 )
{
fwrite("Error: stack overflow!!!\n", 1uLL, 0x19uLL, stderr);
func2(a1);
abort();
}
*a1 = v2 + 1;
return strcpy((char *)&a1[32 * v2 + 1], a2);
}

original_code:
void push(stack_t *ps, char *buffer) {
    if (ps->size == 100) {
        fputs("Error: stack overflow!!!\n", stderr);
  dump_stack(ps);
        abort();
    } else {
  strcpy(ps->items[ps->size++],buffer);
 }
}

canonical_original_code:
void push(struct stack *ps, char *buffer) {
    if (ps->size == 100) {
        fputs("Error: stack overflow!!!\n", stderr);
  dump_stack(ps);
        abort();
    } else {
  strcpy(ps->items[ps->size++],buffer);
 }
}

variable_types:
buffer
char *


decompiled_code:
__int64 test_stack()
{
unsigned int v0; // ebx
const char *v1; // rax
const char *v2; // rax
const char *v3; // rax
__int64 result; // rax
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

v0 = 0;
push(&STACK, &unk_1C8);
push(&STACK, &unk_1CC);
push(&STACK, "three");
v1 = (const char *)pop(&STACK);
puts(v1);
v2 = (const char *)pop(&STACK);
puts(v2);
v3 = (const char *)pop(&STACK);
puts(v3);
do
{
sprintf(v5, "%d", v0++);
result = push(&STACK, v5);
}
while ( v0 != 26 );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
const char *v1; // rax
const char *v2; // rax
const char *v3; // rax
__int64 result; // rax
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

v0 = 0;
push(&STACK, &unk_1C8);
push(&STACK, &unk_1CC);
push(&STACK, "three");
v1 = (const char *)pop(&STACK);
puts(v1);
v2 = (const char *)pop(&STACK);
puts(v2);
v3 = (const char *)pop(&STACK);
puts(v3);
do
{
sprintf(v5, "%d", v0++);
result = push(&STACK, v5);
}
while ( v0 != 26 );
return result;
}

original_code:
void test_stack(void) {
 int i;
 char buf[256];
 push(&STACK,"one");
 push(&STACK,"two");
 push(&STACK,"three");
 printf("%s\n",pop(&STACK));
 printf("%s\n",pop(&STACK));
 printf("%s\n",pop(&STACK));
 for(i=0;i<26;i++) {
  sprintf(buf,"%d",i);
  push(&STACK,buf);
 }
}

canonical_original_code:
void test_stack() {
 int i;
 char buf[256];
 push(&STACK,"one");
 push(&STACK,"two");
 push(&STACK,"three");
 printf("%s\n",pop(&STACK));
 printf("%s\n",pop(&STACK));
 printf("%s\n",pop(&STACK));
 for(i=0;i<26;i++) {
  sprintf(buf,"%d",i);
  push(&STACK,buf);
 }
}

variable_types:
buf
char [256]


decompiled_code:
__int64 test_hash()
{
f("this", 0LL);
f("this", 0LL);
f("is", 0LL);
f("a", 0LL);
return f("test", 0LL);
}


original_code:
void test_list(void) {
 int i;
 int iArray[] = {0,1,2,3,4,5,6,7,8,9};
 list_t *pList;
 node_t *pNode;
 pList = init_list();
 if (((void *)0) == pList) {
  fprintf(stderr, "error in list create.\n");
  exit(-1);
 }
 i=0;
 while(i<10) {
  append(pList,&iArray[i]);
  i++;
 }
 pNode=pList->pFirst;
 while(((void *)0) != pNode) {
  printf("list item => %d\n",*(int*) pNode->pData);
  pNode = pNode->pNext;
 }
}

canonical_original_code:
void test_list() {
 int i;
 int iArray[] = {0,1,2,3,4,5,6,7,8,9};
 struct list *pList;
 struct node *pNode;
 pList = init_list();
 if (((void *)0) == pList) {
  fprintf(stderr, "error in list create.\n");
  exit(-1);
 }
 i=0;
 while(i<10) {
  append(pList,&iArray[i]);
  i++;
 }
 pNode=pList->pFirst;
 while(((void *)0) != pNode) {
  printf("list item => %d\n",*(int *) pNode->pData);
  pNode = pNode->pNext;
 }
}

variable_types:
iArray
int []

variable_types: struct list { struct node { struct node *pNext; int *pData; } *pFirst; } *


calculateLRC

decompiled_code:
__int64 __fastcall calculateLRC(char *a1, int a2)
{
int v2; // eax
char *v3; // rdx
int v4; // ecx

if ( !a2 )
return 0LL;
v2 = 0;
v3 = &a1[a2];
do
{
v4 = *a1++;
v2 = ((v4 + v2) << ((v4 >> 1) & 8)) & 0xFFFFF;
}
while ( a1 != v3 );
return ((v2 ^ 0xFFFFF) + 1) & 0xFFFFF;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, int a2)
{
int v2; // eax
char *v3; // rdx
int v4; // ecx

if ( !a2 )
return 0LL;
v2 = 0;
v3 = &a1[a2];
do
{
v4 = *a1++;
v2 = ((v4 + v2) << ((v4 >> 1) & 8)) & 0xFFFFF;
}
while ( a1 != v3 );
return ((v2 ^ 0xFFFFF) + 1) & 0xFFFFF;
}

original_code:
int calculateLRC(const char *buffer, unsigned int length){
 unsigned int checksum = 0;
 int shift_fudge;
 while(length--) {
  checksum += *buffer;
  shift_fudge = (*buffer&0x10)? 8:0;
  checksum = checksum << shift_fudge;
  checksum &= MAXNUM;
  buffer++;
 }
 return (((checksum ^ MAXNUM) + 1) & MAXNUM);
}

canonical_original_code:
int calculateLRC(char *buffer, unsigned int length){
 unsigned int checksum = 0;
 int shift_fudge;
 while(length--) {
  checksum += *buffer;
  shift_fudge = (*buffer&0x10)? 8:0;
  checksum = checksum << shift_fudge;
  checksum &= MAXNUM;
  buffer++;
 }
 return (((checksum ^ MAXNUM) + 1) & MAXNUM);
}

variable_types:
length
unsigned int

variable_types:
checksum
unsigned int


f

decompiled_code:
__int64 __fastcall f(char *a1, unsigned int a2)
{
int v2; // eax

v2 = strlen(a1);
return (unsigned int)calculateLRC(a1, v2) % a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, unsigned int a2)
{
int v2; // eax

v2 = strlen(a1);
return (unsigned int)func0(a1, v2) % a2;
}

original_code:
int f(char *key,int array_size) {
 unsigned int index;
 index = calculateLRC(key, strlen(key));
 index = index % array_size;
 return (index);
}

canonical_original_code:
int f(char *key, int array_size) {
 unsigned int index;
 index = calculateLRC(key, strlen(key));
 index = index % array_size;
 return (index);
}

variable_types:
key
char *

variable_types:
index
unsigned int


decompiled_code:
__int64 init_hash_table()
{
char *v0; // rbx
__int64 v1; // rax

v0 = (char *)&hash_table;
do
{
v1 = init_list();
if ( !v1 )
{
fwrite("error in list create.\n", 1uLL, 0x16uLL, stderr);
exit(-1);
}
*(_QWORD *)v0 = v1;
v0 += 8;
}
while ( v0 != "error in list create.\n" );
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rbx
__int64 v1; // rax

v0 = (char *)&hash_table;
do
{
v1 = init_list();
if ( !v1 )
{
fwrite("error in list create.\n", 1uLL, 0x16uLL, stderr);
exit(-1);
}
*(_QWORD *)v0 = v1;
v0 += 8;
}
while ( v0 != "error in list create.\n" );
return 0LL;
}

original_code:
int init_hash_table(void) {
 int i;
 list_t *pList;
 for(i=0;i<MAXNUM;i++) {
  pList = init_list();
  if (((void *)0) == pList) {
   fprintf(stderr, "error in list create.\n");
   exit(-1);
  }
  hash_table[i]=pList;
 }
 return (0);
}

canonical_original_code:
int init_hash_table() {
 int i;
 struct list *pList;
 for(i=0;i<MAXNUM;i++) {
  pList = init_list();
  if (((void *)0) == pList) {
   fprintf(stderr, "error in list create.\n");
   exit(-1);
  }
  hash_table[i]=pList;
 }
 return (0);
}

variable_types: i int

user_defined_types: struct node { struct node *pNext; int *pData; }


decompiled_code:
__int64 __fastcall insert_word_into_hashtable(int a1)
{
append(hash_table[a1]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
append(hash_table[a1]);
return 0LL;
}

original_code:
int insert_word_into_hashtable(int index, word_entry_t *pWordEntry) {
 append(hash_table[index],pWordEntry);
 return (0);
}

canonical_original_code:
int insert_word_into_hashtable(int index, struct word_entry *pWordEntry) {
 append(hash_table[index],pWordEntry);
 return (0);
}

variable_types: index int

variable_types: struct word_entry { char *word; char *defn; } *


decompiled_code:
__int64 dump_hashtable()
{
void *v0; // rbp
__int64 **v1; // rbx

v0 = 0LL;
do
{
while ( 1 )
{
v1 = *(__int64 ***)hash_table[(_QWORD)v0];
if ( v1 )
break;
v0 = (char *)v0 + 1;
if ( v0 == &unk_FFFFF )
return 0LL;
}
printf("**** Words at hash index i = %x ******\n", (unsigned int)v0);
do
{
printf("list word => %s\n", (const char *)*v1[1]);
printf("list defn => %s\n\n", (const char *)v1[1][1]);
v1 = (__int64 **)*v1;
}
while ( v1 );
v0 = (char *)v0 + 1;
}
while ( v0 != &unk_FFFFF );
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
void *v0; // rbp
__int64 **v1; // rbx

v0 = 0LL;
do
{
while ( 1 )
{
v1 = *(__int64 ***)hash_table[(_QWORD)v0];
if ( v1 )
break;
v0 = (char *)v0 + 1;
if ( v0 == &unk_FFFFF )
return 0LL;
}
printf("**** Words at hash index i = %x ******\n", (unsigned int)v0);
do
{
printf("list word => %s\n", (const char *)*v1[1]);
printf("list defn => %s\n\n", (const char *)v1[1][1]);
v1 = (__int64 **)*v1;
}
while ( v1 );
v0 = (char *)v0 + 1;
}
while ( v0 != &unk_FFFFF );
return 0LL;
}

original_code:
int dump_hashtable(void) {
 int i;
 node_t *pNode;
 for(i=0;i<MAXNUM;i++) {
  pNode = hash_table[i]->pFirst;
  if (((void *)0) != pNode) {
   printf("****  Words at hash index i = %x ******\n",i);
   while(((void *)0) != pNode) {
    printf("list word => %s\n",((word_entry_t*) pNode->pData)->word);
    printf("list defn => %s\n\n",((word_entry_t*) pNode->pData)->defn);
    pNode = pNode->pNext;
   }
  }
 }
 return(0);
}

canonical_original_code:
int dump_hashtable() {
 int i;
 struct node *pNode;
 for(i=0;i<MAXNUM;i++) {
  pNode = hash_table[i]->pFirst;
  if (((void *)0) != pNode) {
   printf("****  Words at hash index i = %x ******\n",i);
   while(((void *)0) != pNode) {
    printf("list word => %s\n",((struct word_entry *) pNode->pData)->word);
    printf("list defn => %s\n\n",((struct word_entry *) pNode->pData)->defn);
    pNode = pNode->pNext;
   }
  }
 }
 return(0);
}

variable_types: struct node { struct node *pNext; int *pData; } *

user_defined_types: struct word_entry { char *word; char *defn; }


lookupWordLower

decompiled_code:
__int64 __fastcall lookupWordLower(char *s2)
{
__int64 **v1; // rbx
const char *v2; // rbp

v1 = *(__int64 ***)hash_table[(int)f(s2, (unsigned int)&unk_10000)];
if ( !v1 )
return 1LL;
while ( 1 )
{
v2 = (const char *)*v1[1];
if ( !strcmp(v2, s2) )
break;
v1 = (__int64 **)*v1;
if ( !v1 )
return 1LL;
}
printf("word => %s\n", v2);
printf("defn => %s\n\n", (const char *)v1[1][1]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
__int64 **v1; // rbx
const char *v2; // rbp

v1 = *(__int64 ***)hash_table[(int)func1(s2, (unsigned int)&unk_10000)];
if ( !v1 )
return 1LL;
while ( 1 )
{
v2 = (const char *)*v1[1];
if ( !strcmp(v2, s2) )
break;
v1 = (__int64 **)*v1;
if ( !v1 )
return 1LL;
}
printf("word => %s\n", v2);
printf("defn => %s\n\n", (const char *)v1[1][1]);
return 0LL;
}

original_code:
int lookupWordLower(char *pWord) {
 int i;
 node_t *pNode;
 char *pPossibleWord;
 i = f(pWord,0x10000);
 pNode = hash_table[i]->pFirst;
 if (((void *)0) != pNode) {
  while(((void *)0) != pNode) {
   pPossibleWord = (char *)((word_entry_t*) pNode->pData)->word;
   if (0 == strcmp(pPossibleWord,pWord)) {
    printf("word => %s\n",((word_entry_t*) pNode->pData)->word);
    printf("defn => %s\n\n",((word_entry_t*) pNode->pData)->defn);
    return (0);
   }
   pNode = pNode->pNext;
  }
 }
 return(1);
}

canonical_original_code:
int lookupWordLower(char *pWord) {
 int i;
 struct node *pNode;
 char *pPossibleWord;
 i = f(pWord,0x10000);
 pNode = hash_table[i]->pFirst;
 if (((void *)0) != pNode) {
  while(((void *)0) != pNode) {
   pPossibleWord = (char *)((struct word_entry *) pNode->pData)->word;
   if (0 == strcmp(pPossibleWord,pWord)) {
    printf("word => %s\n",((struct word_entry *) pNode->pData)->word);
    printf("defn => %s\n\n",((struct word_entry *) pNode->pData)->defn);
    return (0);
   }
   pNode = pNode->pNext;
  }
 }
 return(1);
}

variable_types:
pWord
char *

variable_types:
pPossibleWord
char *


append

decompiled_code:
__int64 __fastcall append(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rcx
__int64 result; // rax
_QWORD *v5; // rdx

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v2[1] = a2;
v3 = v2;
*v2 = 0LL;
result = *a1;
if ( *a1 )
{
do
{
v5 = (_QWORD *)result;
result = *(_QWORD *)result;
}
while ( result );
*v5 = v3;
}
else
{
*a1 = (__int64)v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, __int64 a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rcx
__int64 result; // rax
_QWORD *v5; // rdx

v2 = malloc(0x10uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v2[1] = a2;
v3 = v2;
*v2 = 0LL;
result = *a1;
if ( *a1 )
{
do
{
v5 = (_QWORD *)result;
result = *(_QWORD *)result;
}
while ( result );
*v5 = v3;
}
else
{
*a1 = (__int64)v3;
}
return result;
}

original_code:
int append(list_t *pList, void *pData) {
 node_t *pTip;
 node_t *pNewNode;
 pNewNode = malloc(sizeof(node_t));
 if (((void *)0) == pNewNode) {
  return(-1);
 }
 pNewNode->pData = pData;
 pNewNode->pNext = ((void *)0);
 if (((void *)0) == pList->pFirst) {
  pList->pFirst = pNewNode;
 } else {
  pTip = pList->pFirst;
  while(((void *)0) != pTip->pNext ) {
   pTip = pTip->pNext;
  }
  pTip->pNext = pNewNode;
 }
 return(0);
}

canonical_original_code:
int append(struct list *pList, void *pData) {
 struct node *pTip;
 struct node *pNewNode;
 pNewNode = malloc(sizeof(node_t));
 if (((void *)0) == pNewNode) {
  return(-1);
 }
 pNewNode->pData = pData;
 pNewNode->pNext = ((void *)0);
 if (((void *)0) == pList->pFirst) {
  pList->pFirst = pNewNode;
 } else {
  pTip = pList->pFirst;
  while(((void *)0) != pTip->pNext ) {
   pTip = pTip->pNext;
  }
  pTip->pNext = pNewNode;
 }
 return(0);
}

variable_types:
pData
void *


decompiled_code:
_QWORD *init_list()
{
_QWORD *result; // rax

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(8uLL);
if ( result )
*result = 0LL;
return result;
}

original_code:
list_t *init_list(void) {
 list_t *pList;
 pList = malloc(sizeof(list_t));
 if (((void *)0) == pList) {
  return(((void *)0));
 }
 pList->pFirst = ((void *)0);
 return (pList);
}

canonical_original_code:
struct list *init_list() {
 struct list *pList;
 pList = malloc(sizeof(list_t));
 if (((void *)0) == pList) {
  return(((void *)0));
 }
 pList->pFirst = ((void *)0);
 return (pList);
}

return_type: struct list { struct node { struct node *pNext; int *pData; } *pFirst; } *


repo: netskink/heap

decompiled_code:
int __fastcall dump_array(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = (unsigned int)i;
result = printf("%d: %d\n", v5, v4);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi
int result; // eax

if ( a2 > 0 )
{
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = (unsigned int)i;
result = printf("%d: %d\n", v5, v4);
}
}
return result;
}

original_code:
void dump_array(int *p, int len) {
 int i;
 for (i=0;i<len;i++) {
  printf("%d: %d\n",i,p[i]);
 }
}

variable_types:
p
int *

variable_types: len int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc != 1 )
{
fprintf(stderr, "Usage: %s \n", *argv);
exit(1);
}
test1(argc, argv, envp);
test2();
test3();
test4();
test5();
exit(0);
}

original_code:
int main(int argc, char *argv[]) {
 int iRC;
 iRC=0;
 if (argc != 1) {
  fprintf(stderr, "Usage: %s \n", argv[0]);
  iRC=1;
  exit(iRC);
 }
 test1();
 test2();
 test3();
 test4();
 test5();
 exit(iRC);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: iRC int