decompiled_code:
__int64 __fastcall cmd_string_to_enum(char *s1)
{
int v1; // er8
__int64 result; // rax
int v3; // er8
int v4; // er8
int v5; // er8

v1 = strcasecmp(s1, "write");
result = 0LL;
if ( v1 )
{
v3 = strcasecmp(s1, "timer_create");
result = 1LL;
if ( v3 )
{
v4 = strcasecmp(s1, "timer_adjust");
result = 2LL;
if ( v4 )
{
v5 = strcasecmp(s1, "timer_delete");
result = 3LL;
if ( v5 )
result = strcasecmp(s1, "exit") == 0 ? 4 : -1;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
int v1; // er8
__int64 result; // rax
int v3; // er8
int v4; // er8
int v5; // er8

v1 = strcasecmp(s1, "write");
result = 0LL;
if ( v1 )
{
v3 = strcasecmp(s1, "timer_create");
result = 1LL;
if ( v3 )
{
v4 = strcasecmp(s1, "timer_adjust");
result = 2LL;
if ( v4 )
{
v5 = strcasecmp(s1, "timer_delete");
result = 3LL;
if ( v5 )
result = strcasecmp(s1, "exit") == 0 ? 4 : -1;
}
}
}
return result;
}

canonical_original_code:
enum MX_CommandType cmd_string_to_enum(char *name)
{
   if (!strcasecmp(name, "write")) return MX_CT_WRITE;
   if (!strcasecmp(name, "timer_create")) return MX_CT_TIMER_CREATE;
   if (!strcasecmp(name, "timer_adjust")) return MX_CT_TIMER_ADJUST;
   if (!strcasecmp(name, "timer_delete")) return MX_CT_TIMER_DELETE;
   if (!strcasecmp(name, "exit")) return MX_CT_EXIT;
   return -1;
}

variable_types:
name
char *

return_type: enum MX_CommandType { MX_CT_WRITE=0, MX_CT_TIMER_CREATE=1, MX_CT_TIMER_ADJUST=2, MX_CT_TIMER_DELETE=3, MX_CT_EXIT=4, NUM_COMMANDS=5 }


repo: jaccovanschaik/mx

decompiled_code:
char *__fastcall evt_enum_to_string(unsigned int a1)
{
char *result; // rax

switch ( a1 )
{
case 0u:
result = "conn";
break;
case 1u:
result = "disc";
break;
case 2u:
result = "msg";
break;
case 3u:
result = "timer";
break;
case 4u:
result = "read";
break;
case 5u:
result = "err";
break;
default:
snprintf(buf_0, 0x50uLL, "%d (out of range)", a1);
result = buf_0;
break;
}
return result;
}

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

switch ( a1 )
{
case 0u:
result = "conn";
break;
case 1u:
result = "disc";
break;
case 2u:
result = "msg";
break;
case 3u:
result = "timer";
break;
case 4u:
result = "read";
break;
case 5u:
result = "err";
break;
default:
snprintf(buf_0, 0x50uLL, "%d (out of range)", a1);
result = buf_0;
break;
}
return result;
}

original_code:
char *evt_enum_to_string(MX_EventType val)
{
   static char buf[80];
   switch(val) {
   case MX_ET_CONN: return("conn");
   case MX_ET_DISC: return("disc");
   case MX_ET_MSG: return("msg");
   case MX_ET_TIMER: return("timer");
   case MX_ET_READ: return("read");
   case MX_ET_ERR: return("err");
   default:
      snprintf(buf, sizeof(buf), "%d (out of range)", val);
      return(buf);
   }
}

canonical_original_code:
char *evt_enum_to_string(enum MX_EventType val)
{
   static char buf[80];
   switch(val) {
   case MX_ET_CONN: return("conn");
   case MX_ET_DISC: return("disc");
   case MX_ET_MSG: return("msg");
   case MX_ET_TIMER: return("timer");
   case MX_ET_READ: return("read");
   case MX_ET_ERR: return("err");
   default:
      snprintf(buf, sizeof(buf), "%d (out of range)", val);
      return(buf);
   }
}

variable_types: enum MX_EventType { MX_ET_CONN=0, MX_ET_DISC=1, MX_ET_MSG=2, MX_ET_TIMER=3, MX_ET_READ=4, MX_ET_ERR=5, NUM_EVENTS=6 }

variable_types:
buf
char [80]

return_type: char *


decompiled_code:
__int64 __fastcall evt_string_to_enum(char *s1)
{
int v1; // er8
__int64 result; // rax
int v3; // er8
int v4; // er8
int v5; // er8
int v6; // er8

v1 = strcasecmp(s1, "conn");
result = 0LL;
if ( v1 )
{
v3 = strcasecmp(s1, "disc");
result = 1LL;
if ( v3 )
{
v4 = strcasecmp(s1, "msg");
result = 2LL;
if ( v4 )
{
v5 = strcasecmp(s1, "timer");
result = 3LL;
if ( v5 )
{
v6 = strcasecmp(s1, "read");
result = 4LL;
if ( v6 )
result = strcasecmp(s1, "err") == 0 ? 5 : -1;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
int v1; // er8
__int64 result; // rax
int v3; // er8
int v4; // er8
int v5; // er8
int v6; // er8

v1 = strcasecmp(s1, "conn");
result = 0LL;
if ( v1 )
{
v3 = strcasecmp(s1, "disc");
result = 1LL;
if ( v3 )
{
v4 = strcasecmp(s1, "msg");
result = 2LL;
if ( v4 )
{
v5 = strcasecmp(s1, "timer");
result = 3LL;
if ( v5 )
{
v6 = strcasecmp(s1, "read");
result = 4LL;
if ( v6 )
result = strcasecmp(s1, "err") == 0 ? 5 : -1;
}
}
}
}
return result;
}

canonical_original_code:
enum MX_EventType evt_string_to_enum(char *name)
{
   if (!strcasecmp(name, "conn")) return MX_ET_CONN;
   if (!strcasecmp(name, "disc")) return MX_ET_DISC;
   if (!strcasecmp(name, "msg")) return MX_ET_MSG;
   if (!strcasecmp(name, "timer")) return MX_ET_TIMER;
   if (!strcasecmp(name, "read")) return MX_ET_READ;
   if (!strcasecmp(name, "err")) return MX_ET_ERR;
   return -1;
}

return_type: enum MX_EventType { MX_ET_CONN=0, MX_ET_DISC=1, MX_ET_MSG=2, MX_ET_TIMER=3, MX_ET_READ=4, MX_ET_ERR=5, NUM_EVENTS=6 }


decompiled_code:
char *__fastcall msg_enum_to_string(unsigned int a1)
{
char *result; // rax

switch ( a1 )
{
case 0u:
result = "quit_request";
break;
case 1u:
result = "hello_request";
break;
case 2u:
result = "hello_reply";
break;
case 3u:
result = "hello_report";
break;
case 4u:
result = "hello_update";
break;
case 5u:
result = "register_request";
break;
case 6u:
result = "register_reply";
break;
case 7u:
result = "register_report";
break;
case 8u:
result = "subscribe_update";
break;
case 9u:
result = "cancel_update";
break;
default:
snprintf(buf_0, 0x50uLL, "%d (out of range)", a1);
result = buf_0;
break;
}
return result;
}

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

switch ( a1 )
{
case 0u:
result = "quit_request";
break;
case 1u:
result = "hello_request";
break;
case 2u:
result = "hello_reply";
break;
case 3u:
result = "hello_report";
break;
case 4u:
result = "hello_update";
break;
case 5u:
result = "register_request";
break;
case 6u:
result = "register_reply";
break;
case 7u:
result = "register_report";
break;
case 8u:
result = "subscribe_update";
break;
case 9u:
result = "cancel_update";
break;
default:
snprintf(buf_0, 0x50uLL, "%d (out of range)", a1);
result = buf_0;
break;
}
return result;
}

original_code:
char *msg_enum_to_string(msg_enum val)
{
   static char buf[80];
   switch(val) {
   case MX_MT_QUIT_REQUEST: return("quit_request");
   case MX_MT_HELLO_REQUEST: return("hello_request");
   case MX_MT_HELLO_REPLY: return("hello_reply");
   case MX_MT_HELLO_REPORT: return("hello_report");
   case MX_MT_HELLO_UPDATE: return("hello_update");
   case MX_MT_REGISTER_REQUEST: return("register_request");
   case MX_MT_REGISTER_REPLY: return("register_reply");
   case MX_MT_REGISTER_REPORT: return("register_report");
   case MX_MT_SUBSCRIBE_UPDATE: return("subscribe_update");
   case MX_MT_CANCEL_UPDATE: return("cancel_update");
   default:
      snprintf(buf, sizeof(buf), "%d (out of range)", val);
      return(buf);
   }
}

canonical_original_code:
char *msg_enum_to_string(enum msg_enum val)
{
   static char buf[80];
   switch(val) {
   case MX_MT_QUIT_REQUEST: return("quit_request");
   case MX_MT_HELLO_REQUEST: return("hello_request");
   case MX_MT_HELLO_REPLY: return("hello_reply");
   case MX_MT_HELLO_REPORT: return("hello_report");
   case MX_MT_HELLO_UPDATE: return("hello_update");
   case MX_MT_REGISTER_REQUEST: return("register_request");
   case MX_MT_REGISTER_REPLY: return("register_reply");
   case MX_MT_REGISTER_REPORT: return("register_report");
   case MX_MT_SUBSCRIBE_UPDATE: return("subscribe_update");
   case MX_MT_CANCEL_UPDATE: return("cancel_update");
   default:
      snprintf(buf, sizeof(buf), "%d (out of range)", val);
      return(buf);
   }
}

variable_types: enum msg_enum { MX_MT_QUIT_REQUEST=0, MX_MT_HELLO_REQUEST=1, MX_MT_HELLO_REPLY=2, MX_MT_HELLO_REPORT=3, MX_MT_HELLO_UPDATE=4, MX_MT_REGISTER_REQUEST=5, MX_MT_REGISTER_REPLY=6, MX_MT_REGISTER_REPORT=7, MX_MT_SUBSCRIBE_UPDATE=8, MX_MT_CANCEL_UPDATE=9, NUM_MX_MESSAGES=10 }


decompiled_code:
__int64 __fastcall msg_string_to_enum(char *s1)
{
int v1; // er8
__int64 result; // rax
int v3; // er8
int v4; // er8
int v5; // er8
int v6; // er8
int v7; // er8
int v8; // er8
int v9; // er8
int v10; // er8

v1 = strcasecmp(s1, "quit_request");
result = 0LL;
if ( v1 )
{
v3 = strcasecmp(s1, "hello_request");
result = 1LL;
if ( v3 )
{
v4 = strcasecmp(s1, "hello_reply");
result = 2LL;
if ( v4 )
{
v5 = strcasecmp(s1, "hello_report");
result = 3LL;
if ( v5 )
{
v6 = strcasecmp(s1, "hello_update");
result = 4LL;
if ( v6 )
{
v7 = strcasecmp(s1, "register_request");
result = 5LL;
if ( v7 )
{
v8 = strcasecmp(s1, "register_reply");
result = 6LL;
if ( v8 )
{
v9 = strcasecmp(s1, "register_report");
result = 7LL;
if ( v9 )
{
v10 = strcasecmp(s1, "subscribe_update");
result = 8LL;
if ( v10 )
result = strcasecmp(s1, "cancel_update") == 0 ? 9 : -1;
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
int v1; // er8
__int64 result; // rax
int v3; // er8
int v4; // er8
int v5; // er8
int v6; // er8
int v7; // er8
int v8; // er8
int v9; // er8
int v10; // er8

v1 = strcasecmp(s1, "quit_request");
result = 0LL;
if ( v1 )
{
v3 = strcasecmp(s1, "hello_request");
result = 1LL;
if ( v3 )
{
v4 = strcasecmp(s1, "hello_reply");
result = 2LL;
if ( v4 )
{
v5 = strcasecmp(s1, "hello_report");
result = 3LL;
if ( v5 )
{
v6 = strcasecmp(s1, "hello_update");
result = 4LL;
if ( v6 )
{
v7 = strcasecmp(s1, "register_request");
result = 5LL;
if ( v7 )
{
v8 = strcasecmp(s1, "register_reply");
result = 6LL;
if ( v8 )
{
v9 = strcasecmp(s1, "register_report");
result = 7LL;
if ( v9 )
{
v10 = strcasecmp(s1, "subscribe_update");
result = 8LL;
if ( v10 )
result = strcasecmp(s1, "cancel_update") == 0 ? 9 : -1;
}
}
}
}
}
}
}
}
return result;
}

canonical_original_code:
enum msg_enum msg_string_to_enum(char *name)
{
   if (!strcasecmp(name, "quit_request")) return MX_MT_QUIT_REQUEST;
   if (!strcasecmp(name, "hello_request")) return MX_MT_HELLO_REQUEST;
   if (!strcasecmp(name, "hello_reply")) return MX_MT_HELLO_REPLY;
   if (!strcasecmp(name, "hello_report")) return MX_MT_HELLO_REPORT;
   if (!strcasecmp(name, "hello_update")) return MX_MT_HELLO_UPDATE;
   if (!strcasecmp(name, "register_request")) return MX_MT_REGISTER_REQUEST;
   if (!strcasecmp(name, "register_reply")) return MX_MT_REGISTER_REPLY;
   if (!strcasecmp(name, "register_report")) return MX_MT_REGISTER_REPORT;
   if (!strcasecmp(name, "subscribe_update")) return MX_MT_SUBSCRIBE_UPDATE;
   if (!strcasecmp(name, "cancel_update")) return MX_MT_CANCEL_UPDATE;
   return -1;
}

return_type: enum msg_enum { MX_MT_QUIT_REQUEST=0, MX_MT_HELLO_REQUEST=1, MX_MT_HELLO_REPLY=2, MX_MT_HELLO_REPORT=3, MX_MT_HELLO_UPDATE=4, MX_MT_REGISTER_REQUEST=5, MX_MT_REGISTER_REPLY=6, MX_MT_REGISTER_REPORT=7, MX_MT_SUBSCRIBE_UPDATE=8, MX_MT_CANCEL_UPDATE=9, NUM_MX_MESSAGES=10 }


calcGrid

repo: jackcarrozzo/vectorplot

original_code:
void calcGrid(XSegment *grid,Coord *plot,int divx,int divy) {
  int i,p=0;
  for (i=0;i<=256;i+=divx) {
      grid[p].x1=x2screen(i,plot);
      grid[p].y1=y2screen(0,plot);
      grid[p].x2=grid[p].x1;
      grid[p].y2=y2screen(256,plot);
      p++;
    }
    for (i=0;i<=256;i+=divy) {
      grid[p].x1=x2screen(0,plot);
      grid[p].y1=y2screen(i,plot);
      grid[p].x2=x2screen(256,plot);
      grid[p].y2=grid[p].y1;
      p++;
    }
}

canonical_original_code:
void calcGrid(struct XSegment *grid, struct Coord *plot, int divx, int divy) {
  int i; int p = 0;
  for (i=0;i<=256;i+=divx) {
      grid[p].x1=x2screen(i,plot);
      grid[p].y1=y2screen(0,plot);
      grid[p].x2=grid[p].x1;
      grid[p].y2=y2screen(256,plot);
      p++;
    }
    for (i=0;i<=256;i+=divy) {
      grid[p].x1=x2screen(0,plot);
      grid[p].y1=y2screen(i,plot);
      grid[p].x2=x2screen(256,plot);
      grid[p].y2=grid[p].y1;
      p++;
    }
}

variable_types:
grid
struct XSegment { short x1; } *

variable_types: struct Coord { int sx; int sy; int ex; int ey; } *

variable_types: divx int

variable_types: divy int

variable_types: i int

variable_types: p int

return_type: void


decompiled_code:
int need2leave()
{
return puts("Exiting cleanly.");
}

canonical_decompiled_code:
int func0()
{
return puts("Exiting cleanly.");
}

original_code:
void need2leave() {
 printf("Exiting cleanly.\n");
}


fft

canonical_original_code:
void fft(struct complex *v, int n, struct complex *tmp) {
  if (1==n) return;
  int k; int m;
  struct complex z; struct complex w; struct complex *vo; struct complex *ve;
  ve=tmp;
  vo=tmp+n/2;
  for(k=0;k<n/2;k++) {
    ve[k]=v[2*k];
    vo[k]=v[2*k+1];
  }
  fft(ve,n/2,v);
  fft(vo,n/2,v);
  for(m=0; m<n/2; m++) {
    w.Re=cos(6.28318530717958647692528676655900576*m/(double)n);
    w.Im=-sin(6.28318530717958647692528676655900576*m/(double)n);
    z.Re=w.Re*vo[m].Re-w.Im*vo[m].Im;
    z.Im=w.Re*vo[m].Im+w.Im*vo[m].Re;
    v[m].Re=ve[m].Re+z.Re;
    v[m].Im=ve[m].Im+z.Im;
    v[m+n/2].Re=ve[m].Re-z.Re;
    v[m+n/2].Im=ve[m].Im-z.Im;
  }
}

variable_types: struct complex { float Re; float Im; } *

variable_types: n int

variable_types:
tmp
struct complex *

variable_types: k int

variable_types: m int

variable_types:
z
struct complex { float Re; float Im; }

variable_types:
w
struct complex { float Re; float Im; }


original_code:
float fft2float(complex *v,int n,float *mags) {
  int i;
  int center=n/2;
  float max=0;
  for (i=0;i<center;i++) {
    mags[i+center]=mag(v[i]);
    if (mags[i+center]>max) max=mags[i+center];
  }
  for (i=center;i<n;i++) {
    mags[i-center]=mag(v[i]);
    if (mags[i-center]>max) max=mags[i-center];
  }
  return max;
}

canonical_original_code:
float fft2float(struct complex *v, int n, float *mags) {
  int i;
  int center = n/2;
  float max = 0;
  for (i=0;i<center;i++) {
    mags[i+center]=mag(v[i]);
    if (mags[i+center]>max) max=mags[i+center];
  }
  for (i=center;i<n;i++) {
    mags[i-center]=mag(v[i]);
    if (mags[i-center]>max) max=mags[i-center];
  }
  return max;
}

variable_types:
mags
float *

variable_types: center int

variable_types: max float

return_type: float


original_code:
uint16_t hist_2d(uint8_t *vals,int n,uint16_t plot[256][256]) {
  int i,j;
  uint16_t max=0;
  uint8_t thisi=0,thisq=0;
  for (i=0;i<256;i++) {
    for (j=0;j<256;j++) {
      plot[i][j]=0;
    }
  }
  n*=2;
  while(i<n) {
    thisi=vals[i++];
    thisq=vals[i++];
    plot[thisi][thisq]++;
    if (plot[thisi][thisq]>max) max=plot[thisi][thisq];
  }
  return max;
}

canonical_original_code:
unsigned short hist_2d(unsigned char *vals, int n, unsigned short plot[256][256]) {
  int i; int j;
  unsigned short max = 0;
  unsigned char thisi = 0; unsigned char thisq = 0;
  for (i=0;i<256;i++) {
    for (j=0;j<256;j++) {
      plot[i][j]=0;
    }
  }
  n*=2;
  while(i<n) {
    thisi=vals[i++];
    thisq=vals[i++];
    plot[thisi][thisq]++;
    if (plot[thisi][thisq]>max) max=plot[thisi][thisq];
  }
  return max;
}

variable_types:
vals
unsigned char *

variable_types:
plot
unsigned short [256][256]

variable_types: j int

variable_types:
max
unsigned short

variable_types:
thisi
unsigned char

variable_types:
thisq
unsigned char

return_type: unsigned short


openDevice

repo: jacobappleton/hyper-cam

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

v2 = open(a1, 2, 0LL);
*a2 = v2;
if ( v2 == 1 )
result = exitWithError("Open camera failed");
else
result = printf("Opened Camera");
return result;
}

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

v2 = open(a1, 2, 0LL);
*a2 = v2;
if ( v2 == 1 )
result = exitWithError("Open camera failed");
else
result = printf("Opened Camera");
return result;
}

original_code:
void openDevice(const char* location, int* fd)
{
 *fd = open(location, 02, 0);
 if(*fd==1)
 {
  exitWithError("Open camera failed");
 }
 else
 {
  printf("Opened Camera");
 }
}

canonical_original_code:
void openDevice(char *location, int *fd)
{
 *fd = open(location, 02, 0);
 if(*fd==1)
 {
  exitWithError("Open camera failed");
 }
 else
 {
  printf("Opened Camera");
 }
}

variable_types:
location
char *

variable_types:
fd
int *


getCapabilities

decompiled_code:
int __fastcall getCapabilities(unsigned int *a1)
{
char v2[84]; // [rsp+0h] [rbp-78h] BYREF
unsigned int v3; // [rsp+54h] [rbp-24h]

xioctl(*a1, 2154321408LL, v2);
return printf("Capabilities: %x\nDriver: %s\n", v3, v2);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int *a1)
{
char v2[84]; // [rsp+0h] [rbp-78h] BYREF
unsigned int v3; // [rsp+54h] [rbp-24h]

xioctl(*a1, 2154321408LL, v2);
return printf("Capabilities: %x\nDriver: %s\n", v3, v2);
}

original_code:
void getCapabilities(int* fd)
{
 struct v4l2_capability cap;
 xioctl(*fd, (((2U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((0)) << 0) | ((((sizeof(struct v4l2_capability)))) << ((0 +8)+8))), &cap);
 printf("Capabilities: %x\nDriver: %s\n", cap.capabilities, cap.driver);
}

canonical_original_code:
void getCapabilities(int *fd)
{
 struct v4l2_capability cap;
 xioctl(*fd, (((2U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((0)) << 0) | ((((sizeof(struct v4l2_capability)))) << ((0 +8)+8))), &cap);
 printf("Capabilities: %x\nDriver: %s\n", cap.capabilities, cap.driver);
}

variable_types: struct v4l2_capability { unsigned char driver[16]; unsigned char card[32]; unsigned char bus_info[32]; unsigned int version; unsigned int capabilities; unsigned int device_caps; unsigned int reserved[3]; }


closeDevice

decompiled_code:
int __fastcall closeDevice(_DWORD *a1)
{
__int64 v1; // rsi
int result; // eax

v1 = (unsigned int)*a1;
if ( (_DWORD)v1 != -1 )
{
close(v1);
v1 = (unsigned int)*a1;
}
result = printf("Close device successful (%d)", v1);
*a1 = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func2(_DWORD *a1)
{
__int64 v1; // rsi
int result; // eax

v1 = (unsigned int)*a1;
if ( (_DWORD)v1 != -1 )
{
close(v1);
v1 = (unsigned int)*a1;
}
result = printf("Close device successful (%d)", v1);
*a1 = -1;
return result;
}

original_code:
void closeDevice(int* fd)
{
 if(*fd != -1) close(*fd);
 printf("Close device successful (%d)", *fd);
 *fd = -1;
 return;
}

canonical_original_code:
void closeDevice(int *fd)
{
 if(*fd != -1) close(*fd);
 printf("Close device successful (%d)", *fd);
 *fd = -1;
 return;
}


writeDataToSerial

decompiled_code:
__int64 __fastcall writeDataToSerial(unsigned __int16 *a1, unsigned int a2, __int64 a3, int a4)
{
__int64 v5; // r12
__int64 v6; // rsi
__int64 v10; // rdi
int v11; // esi
__int64 v12; // rbp
__int64 v13; // r15
__int64 v14; // rdx

v5 = a3;
v6 = *a1;
if ( (_WORD)v6 && *(unsigned __int16 *)(a3 + 8) - a4 > 0 )
{
printf("Bytes requested: %d\n", v6);
v10 = *a1;
v11 = *(unsigned __int16 *)(v5 + 8) - a4;
if ( (int)v10 < v11 )
{
printf("Bytes requested: %d\n", (unsigned int)v10);
v13 = createOutputTelPkt(*a1, *a1);
memcpy(*(void **)(v13 + 8), (const void *)(a4 + *(_QWORD *)v5), *a1);
writeToUart(v13, a2);
v14 = *a1;
*(_QWORD *)v5 += v14;
*(_WORD *)(v5 + 8) -= v14;
}
else
{
v12 = createOutputTelPkt(v10, (unsigned __int16)v11);
memcpy(*(void **)(v12 + 8), (const void *)(a4 + *(_QWORD *)v5), *(unsigned __int16 *)(v5 + 8) - a4);
writeToUart(v12, a2);
v5 = *(_QWORD *)(v5 + 16);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int16 *a1, unsigned int a2, __int64 a3, int a4)
{
__int64 v5; // r12
__int64 v6; // rsi
__int64 v10; // rdi
int v11; // esi
__int64 v12; // rbp
__int64 v13; // r15
__int64 v14; // rdx

v5 = a3;
v6 = *a1;
if ( (_WORD)v6 && *(unsigned __int16 *)(a3 + 8) - a4 > 0 )
{
printf("Bytes requested: %d\n", v6);
v10 = *a1;
v11 = *(unsigned __int16 *)(v5 + 8) - a4;
if ( (int)v10 < v11 )
{
printf("Bytes requested: %d\n", (unsigned int)v10);
v13 = createOutputTelPkt(*a1, *a1);
memcpy(*(void **)(v13 + 8), (const void *)(a4 + *(_QWORD *)v5), *a1);
writeToUart(v13, a2);
v14 = *a1;
*(_QWORD *)v5 += v14;
*(_WORD *)(v5 + 8) -= v14;
}
else
{
v12 = createOutputTelPkt(v10, (unsigned __int16)v11);
memcpy(*(void **)(v12 + 8), (const void *)(a4 + *(_QWORD *)v5), *(unsigned __int16 *)(v5 + 8) - a4);
writeToUart(v12, a2);
v5 = *(_QWORD *)(v5 + 16);
}
}
return v5;
}

original_code:
struct lstnode* writeDataToSerial(struct telpkt* req, int fd,
  struct lstnode* cNode, int nOffset)
{
 if (req->bytesRequested > 0 && cNode->size - nOffset > 0)
 {
  printf("Bytes requested: %d\n", req->bytesRequested);
  if(req->bytesRequested >= cNode->size - nOffset)
  {
   struct telpkt* t = createOutputTelPkt(req->bytesRequested,
              cNode->size - nOffset);
   memcpy(t->data, cNode->img + nOffset, cNode->size - nOffset);
   writeToUart(t, fd);
   nOffset = 0;
   cNode = cNode->next;
  }
  else
  {
   printf("Bytes requested: %d\n", req->bytesRequested);
   struct telpkt* t = createOutputTelPkt(req->bytesRequested,
              req->bytesRequested);
   memcpy(t->data, cNode->img + nOffset, req->bytesRequested);
   writeToUart(t, fd);
   cNode->img += req->bytesRequested;
   cNode->size -= req->bytesRequested;
  }
 }
 return cNode;
}

canonical_original_code:
struct lstnode *writeDataToSerial(struct telpkt *req, int fd, struct lstnode *cNode, int nOffset)
{
 if (req->bytesRequested > 0 && cNode->size - nOffset > 0)
 {
  printf("Bytes requested: %d\n", req->bytesRequested);
  if(req->bytesRequested >= cNode->size - nOffset)
  {
   struct telpkt *t = createOutputTelPkt(req->bytesRequested,
              cNode->size - nOffset);
   memcpy(t->data, cNode->img + nOffset, cNode->size - nOffset);
   writeToUart(t, fd);
   nOffset = 0;
   cNode = cNode->next;
  }
  else
  {
   printf("Bytes requested: %d\n", req->bytesRequested);
   struct telpkt *t = createOutputTelPkt(req->bytesRequested,
              req->bytesRequested);
   memcpy(t->data, cNode->img + nOffset, req->bytesRequested);
   writeToUart(t, fd);
   cNode->img += req->bytesRequested;
   cNode->size -= req->bytesRequested;
  }
 }
 return cNode;
}

variable_types: struct telpkt { unsigned short bytesRequested; unsigned short bytesContained; unsigned char *data; unsigned char xor; unsigned char *output; unsigned char *outputStart; unsigned long outputSize; } *

variable_types: fd int

variable_types:
cNode
struct lstnode *

variable_types: nOffset int

return_type: struct lstnode { unsigned char *img; unsigned short size; struct lstnode *next; long tstamp; } *


writeImageContentToFile

decompiled_code:
void __fastcall __noreturn writeImageContentToFile(void *a1)
{
__int64 v1; // r13
pthread_mutex_t *v2; // r14
unsigned int v3; // ebx
char *v4; // rbp
unsigned __int16 *v5; // rax
unsigned __int16 *v6; // r12

v1 = *((_QWORD *)a1 + 1);
v2 = (pthread_mutex_t *)*((_QWORD *)a1 + 2);
free(a1);
v3 = openPort();
while ( 1 )
{
v4 = (char *)malloc(6uLL);
if ( read(v3, v4, 6uLL) == 6 )
{
pthread_mutex_lock(v2);
printf("Received: %s\n", v4);
v5 = (unsigned __int16 *)decode(v4, 5LL);
v6 = v5;
if ( *(_WORD *)(v1 + 8) )
v1 = writeDataToSerial(v5, v3, v1, 0);
free(v6);
pthread_mutex_unlock(v2);
}
free(v4);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *a1)
{
__int64 v1; // r13
pthread_mutex_t *v2; // r14
unsigned int v3; // ebx
char *v4; // rbp
unsigned __int16 *v5; // rax
unsigned __int16 *v6; // r12

v1 = *((_QWORD *)a1 + 1);
v2 = (pthread_mutex_t *)*((_QWORD *)a1 + 2);
free(a1);
v3 = openPort();
while ( 1 )
{
v4 = (char *)malloc(6uLL);
if ( read(v3, v4, 6uLL) == 6 )
{
pthread_mutex_lock(v2);
printf("Received: %s\n", v4);
v5 = (unsigned __int16 *)decode(v4, 5LL);
v6 = v5;
if ( *(_WORD *)(v1 + 8) )
v1 = func7(v5, v3, v1, 0);
free(v6);
pthread_mutex_unlock(v2);
}
free(v4);
}
}

original_code:
void* writeImageContentToFile(void* args)
{
 struct threadArgs* inputs = (struct threadArgs*)args;
 int nodeCtr = 0;
 struct lstnode* node = inputs->cNode;
 pthread_mutex_t* mutex = inputs->mutex;
 free(args);
 int fd = openPort();
 while(1)
 {
  byte* buf = (byte*)malloc(6);
  if(read(fd, buf, 6) == 6)
  {
   pthread_mutex_lock(mutex);
   printf("Received: %s\n", buf);
   struct telpkt* tp = decode(buf, 5);
   if(node->size > 0) node = writeDataToSerial(tp, fd, node, nodeCtr);
   free(tp);
   pthread_mutex_unlock(mutex);
  }
  free(buf);
 }
 free(inputs);
 pthread_exit(((void *)0));
}

canonical_original_code:
void *writeImageContentToFile(void *args)
{
 struct threadArgs *inputs = (struct threadArgs*)args;
 int nodeCtr = 0;
 struct lstnode *node = inputs->cNode;
 union pthread_mutex_t *mutex = inputs->mutex;
 free(args);
 int fd = openPort();
 while(1)
 {
  unsigned char *buf = (byte*)malloc(6);
  if(read(fd, buf, 6) == 6)
  {
   pthread_mutex_lock(mutex);
   printf("Received: %s\n", buf);
   struct telpkt *tp = decode(buf, 5);
   if(node->size > 0) node = writeDataToSerial(tp, fd, node, nodeCtr);
   free(tp);
   pthread_mutex_unlock(mutex);
  }
  free(buf);
 }
 free(inputs);
 pthread_exit(((void *)0));
}

variable_types:
args
void *

variable_types: struct threadArgs { char *imagePath; struct lstnode { unsigned char *img; unsigned short size; struct lstnode *next; long tstamp; } *cNode; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *mutex; } *

variable_types: nodeCtr int

variable_types:
buf
unsigned char *

return_type: void *

user_defined_types: struct threadArgs { char *imagePath; struct lstnode *cNode; union pthread_mutex_t *mutex; }

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

user_defined_types: struct telpkt { unsigned short bytesRequested; unsigned short bytesContained; unsigned char *data; unsigned char xor; unsigned char *output; unsigned char *outputStart; unsigned long outputSize; }

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


turnOnCamera

decompiled_code:
__int64 __fastcall turnOnCamera(int *a1, char a2)
{
if ( !a2 )
ioctl(*a1, 0x40045612uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, char a2)
{
if ( !a2 )
ioctl(*a1, 0x40045612uLL);
return 1LL;
}

original_code:
_Bool turnOnCamera(int* fd, _Bool streamOn, int* imageCaptureType)
{
 if (!streamOn) {
  ioctl(*fd, (((1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((18)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), imageCaptureType);
  streamOn = 1;
 }
 return streamOn;
}

canonical_original_code:
_Bool turnOnCamera(int *fd, _Bool streamOn, int *imageCaptureType)
{
 if (!streamOn) {
  ioctl(*fd, (((1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((18)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), imageCaptureType);
  streamOn = 1;
 }
 return streamOn;
}

variable_types:
imageCaptureType
int *


createThread

decompiled_code:
int __fastcall createThread(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x18uLL);
v2[1] = a1;
v2[2] = a2;
return pthread_create(newthread, 0LL, (void *(*)(void *))writeImageContentToFile, v2);
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x18uLL);
v2[1] = a1;
v2[2] = a2;
return pthread_create(newthread, 0LL, (void *(*)(void *))writeImageContentToFile, v2);
}

original_code:
void createThread(struct lstnode* cNode,
  pthread_mutex_t* mutex) {
 pthread_t thread;
 struct threadArgs* arg =
   (struct threadArgs*)malloc(sizeof(struct threadArgs));
 arg->cNode = cNode;
 arg->mutex = mutex;
 pthread_create(&thread, ((void *)0), writeImageContentToFile, (void*) arg);
}

canonical_original_code:
void createThread(struct lstnode *cNode, union pthread_mutex_t *mutex) {
 unsigned long thread;
 struct threadArgs *arg = (struct threadArgs*)malloc(sizeof(struct threadArgs));
 arg->cNode = cNode;
 arg->mutex = mutex;
 pthread_create(&thread, ((void *)0), writeImageContentToFile, (void *) arg);
}

variable_types: struct lstnode { unsigned char *img; unsigned short size; struct lstnode *next; long tstamp; } *

variable_types: union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *

variable_types:
thread
unsigned long


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int *v4; // r12
int v5; // er14
__useconds_t v6; // ebp
int v7; // eax
int v8; // ebx
_DWORD *v9; // rax
char v10[296]; // [rsp+0h] [rbp-128h] BYREF

v4 = (int *)malloc(4uLL);
if ( argc == 5 )
{
v3 = argv[1];
v5 = atoi(argv[2]);
if ( (unsigned int)(v5 - 1) > 0x63 )
{
v5 = 0;
exitWithError("Set JpegQuality between 1 and 100 inclusive.");
}
v6 = 0;
v7 = atoi(argv[3]);
if ( v7 >= 0 )
v6 = v7;
v8 = atoi(argv[4]);
if ( v8 <= 0 )
v8 = 0;
}
else
{
v8 = 0;
v6 = 0;
v5 = 0;
sprintf(v10, "usage: %s cameraDevice JpegQuality fps bufferSize", *argv);
exitWithError(v10);
}
puts("Camera Interface Copyright (C) 2012 Jacob Appleton\n");
puts("This program comes with ABSOLUTELY NO WARRANTY;");
puts("This is free software, and you are welcome to redistribute it ");
puts("under certain conditions.");
puts("Visit http://www.gnu.org/licenses/gpl.html for more details.\n");
*v4 = -1;
openDevice(v3, v4);
getCapabilities((unsigned int *)v4);
v9 = malloc(4uLL);
*v9 = 1;
getFrames(1, 1u, (unsigned int *)v4, (__int64)v9, v5, v6, v8);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
int *v4; // r12
int v5; // er14
__useconds_t v6; // ebp
int v7; // eax
int v8; // ebx
_DWORD *v9; // rax
char v10[296]; // [rsp+0h] [rbp-128h] BYREF

v4 = (int *)malloc(4uLL);
if ( argc == 5 )
{
v3 = argv[1];
v5 = atoi(argv[2]);
if ( (unsigned int)(v5 - 1) > 0x63 )
{
v5 = 0;
exitWithError("Set JpegQuality between 1 and 100 inclusive.");
}
v6 = 0;
v7 = atoi(argv[3]);
if ( v7 >= 0 )
v6 = v7;
v8 = atoi(argv[4]);
if ( v8 <= 0 )
v8 = 0;
}
else
{
v8 = 0;
v6 = 0;
v5 = 0;
sprintf(v10, "usage: %s cameraDevice JpegQuality fps bufferSize", *argv);
exitWithError(v10);
}
puts("Camera Interface Copyright (C) 2012 Jacob Appleton\n");
puts("This program comes with ABSOLUTELY NO WARRANTY;");
puts("This is free software, and you are welcome to redistribute it ");
puts("under certain conditions.");
puts("Visit http://www.gnu.org/licenses/gpl.html for more details.\n");
*v4 = -1;
func0(v3, v4);
func1((unsigned int *)v4);
v9 = malloc(4uLL);
*v9 = 1;
func11(1, 1u, (unsigned int *)v4, (__int64)v9, v5, v6, v8);
}

original_code:
int main(int argc, char *argv[]) {
 int *fd = (int*)malloc(sizeof(int)), qual = 0, fps = 0, bufSize = 0;
 char *camera;
 if(argc != 5)
 {
  char errorMsg[256];
  sprintf(errorMsg, "usage: %s cameraDevice JpegQuality fps bufferSize",
    argv[0]);
  exitWithError(errorMsg);
 }
 else
 {
  camera = argv[1];
  if(atoi(argv[2]) > 0 && atoi(argv[2]) <= 100) qual = atoi(argv[2]);
  else exitWithError("Set JpegQuality between 1 and 100 inclusive.");
  if(atoi(argv[3]) > 0) fps = atoi(argv[3]);
  if(atoi(argv[4]) > 0) bufSize = atoi(argv[4]);
 }
 printf("Camera Interface  Copyright (C) 2012  Jacob Appleton\n\n");
 printf("This program comes with ABSOLUTELY NO WARRANTY;\n");
    printf("This is free software, and you are welcome to redistribute it \n");
    printf("under certain conditions.\n");
    printf("Visit http://www.gnu.org/licenses/gpl.html for more details.\n\n");
 *fd = -1;
 openDevice(camera, fd);
 getCapabilities(fd);
 int* imageCaptureType = (int*)malloc(sizeof(int));
 *imageCaptureType = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 getFrames(1, 1, fd, imageCaptureType, qual, fps, bufSize);
    ioctl(*fd, (((1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((19)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), imageCaptureType);
 closeDevice(fd);
 free(fd);
 free(imageCaptureType);
 pthread_exit(((void *)0));
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int *fd = (int*)malloc(sizeof(int)); int qual = 0; int fps = 0; int bufSize = 0;
 char *camera;
 if(argc != 5)
 {
  char errorMsg[256];
  sprintf(errorMsg, "usage: %s cameraDevice JpegQuality fps bufferSize",
    argv[0]);
  exitWithError(errorMsg);
 }
 else
 {
  camera = argv[1];
  if(atoi(argv[2]) > 0 && atoi(argv[2]) <= 100) qual = atoi(argv[2]);
  else exitWithError("Set JpegQuality between 1 and 100 inclusive.");
  if(atoi(argv[3]) > 0) fps = atoi(argv[3]);
  if(atoi(argv[4]) > 0) bufSize = atoi(argv[4]);
 }
 printf("Camera Interface  Copyright (C) 2012  Jacob Appleton\n\n");
 printf("This program comes with ABSOLUTELY NO WARRANTY;\n");
    printf("This is free software, and you are welcome to redistribute it \n");
    printf("under certain conditions.\n");
    printf("Visit http://www.gnu.org/licenses/gpl.html for more details.\n\n");
 *fd = -1;
 openDevice(camera, fd);
 getCapabilities(fd);
 int *imageCaptureType = (int*)malloc(sizeof(int));
 *imageCaptureType = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 getFrames(1, 1, fd, imageCaptureType, qual, fps, bufSize);
    ioctl(*fd, (((1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((19)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), imageCaptureType);
 closeDevice(fd);
 free(fd);
 free(imageCaptureType);
 pthread_exit(((void *)0));
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: qual int

variable_types: fps int

variable_types: bufSize int

variable_types:
camera
char *

variable_types:
errorMsg
char [256]

return_type: int


openPortFd

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

result = open("/dev/ttyS0", 258);
if ( result < 0 )
{
perror("/dev/ttyS0");
exit(-1);
}
return result;
}

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

result = open("/dev/ttyS0", 258);
if ( result < 0 )
{
perror("/dev/ttyS0");
exit(-1);
}
return result;
}

original_code:
int openPortFd() {
 int comFd;
 comFd = open("/dev/ttyS0", 02 | 0400);
 if (comFd < 0) {
  perror("/dev/ttyS0");
  exit(-1);
 }
 return comFd;
}

variable_types: comFd int


openPort

decompiled_code:
__int64 openPort()
{
unsigned int v0; // er12
struct termios v2; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

v0 = openPortFd();
tcgetattr(v0, &termios_p);
*(_OWORD *)&v2.c_iflag = 0LL;
*(_OWORD *)&v2.c_line = 0LL;
*(_OWORD *)&v2.c_cc[15] = 0LL;
*(_QWORD *)&v2.c_cc[31] = 0LL;
v2.c_ospeed = 0;
v2.c_cflag = 6324;
v2.c_iflag = 4;
v2.c_cc[6] = 6;
tcflush(v0, 0);
tcsetattr(v0, 0, &v2);
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er12
struct termios v2; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

v0 = func0();
tcgetattr(v0, &termios_p);
*(_OWORD *)&v2.c_iflag = 0LL;
*(_OWORD *)&v2.c_line = 0LL;
*(_OWORD *)&v2.c_cc[15] = 0LL;
*(_QWORD *)&v2.c_cc[31] = 0LL;
v2.c_ospeed = 0;
v2.c_cflag = 6324;
v2.c_iflag = 4;
v2.c_cc[6] = 6;
tcflush(v0, 0);
tcsetattr(v0, 0, &v2);
return v0;
}

original_code:
int openPort()
{
 int fd;
 struct termios tio, oldtio;
 fd = openPortFd();
    tcgetattr(fd,&oldtio);
    bzero(&tio, sizeof(tio));
 tio.c_cflag = 0010004 | 0000060 | 0004000 | 0000200;
    tio.c_iflag = 0000004;
 tio.c_oflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 6;
 tcflush(fd, 0);
 tcsetattr(fd,0,&tio);
 return fd;
}

canonical_original_code:
int openPort()
{
 int fd;
 struct termios tio; struct termios oldtio;
 fd = openPortFd();
    tcgetattr(fd,&oldtio);
    bzero(&tio, sizeof(tio));
 tio.c_cflag = 0010004 | 0000060 | 0004000 | 0000200;
    tio.c_iflag = 0000004;
 tio.c_oflag = 0;
 tio.c_cc[5] = 0;
 tio.c_cc[6] = 6;
 tcflush(fd, 0);
 tcsetattr(fd,0,&tio);
 return fd;
}

variable_types: fd int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


calcXor

decompiled_code:
char __fastcall calcXor(_BYTE *a1, int a2)
{
__int64 v2; // rdx
char result; // al

if ( a2 <= 0 )
return 0;
v2 = (__int64)&a1[a2 - 1 + 1];
result = 0;
do
result ^= *a1++;
while ( a1 != (_BYTE *)v2 );
return result;
}

canonical_decompiled_code:
char __fastcall func2(_BYTE *a1, int a2)
{
__int64 v2; // rdx
char result; // al

if ( a2 <= 0 )
return 0;
v2 = (__int64)&a1[a2 - 1 + 1];
result = 0;
do
result ^= *a1++;
while ( a1 != (_BYTE *)v2 );
return result;
}

original_code:
byte calcXor(byte* data, int size)
{
 byte output = 0x00;
 int i;
 for(i = 0; i < size; i++)
 {
  output = output ^ data[i];
 }
 return output;
}

canonical_original_code:
unsigned char calcXor(unsigned char *data, int size)
{
 unsigned char output = 0x00;
 int i;
 for(i = 0; i < size; i++)
 {
  output = output ^ data[i];
 }
 return output;
}

variable_types:
data
unsigned char *

variable_types: size int

variable_types:
output
unsigned char

variable_types: i int

return_type: unsigned char


encode

original_code:
void encode(struct telpkt* t)
{
 unsigned int outputSize;
 outputSize = 6 + t->bytesContained;
 byte* output = (byte*)calloc(outputSize, 1);
 byte* outputStart = output;
 output[0] = 0xAA;
 output[1] = (t->bytesRequested >> 8) & 0xFF;
 output[2] = t->bytesRequested & 0xFF;
 output[3] = (t->bytesContained >> 8) & 0xFF;
 output[4] = t->bytesContained & 0xFF;
 output += 5;
 memcpy(output, t->data, t->bytesContained);
 output += t->bytesContained;
 t->xor = calcXor(outputStart, outputSize - 1);
 *output = t->xor;
 t->output = outputStart;
 t->outputSize = outputSize;
}

canonical_original_code:
void encode(struct telpkt *t)
{
 unsigned int outputSize;
 outputSize = 6 + t->bytesContained;
 unsigned char *output = (byte*)calloc(outputSize, 1);
 unsigned char *outputStart = output;
 output[0] = 0xAA;
 output[1] = (t->bytesRequested >> 8) & 0xFF;
 output[2] = t->bytesRequested & 0xFF;
 output[3] = (t->bytesContained >> 8) & 0xFF;
 output[4] = t->bytesContained & 0xFF;
 output += 5;
 memcpy(output, t->data, t->bytesContained);
 output += t->bytesContained;
 t->xor = calcXor(outputStart, outputSize - 1);
 *output = t->xor;
 t->output = outputStart;
 t->outputSize = outputSize;
}

variable_types: struct telpkt { unsigned short bytesRequested; unsigned short bytesContained; unsigned char *data; unsigned char xor; unsigned char *output; unsigned char *outputStart; unsigned long outputSize; } *

variable_types:
outputSize
unsigned int

variable_types:
output
unsigned char *

variable_types:
outputStart
unsigned char *


cleanUp

decompiled_code:
void __fastcall cleanUp(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
free(*((void **)ptr + 3));
free(ptr);
}

original_code:
void cleanUp(struct telpkt* t)
{
 free(t->output);
 free(t);
}

canonical_original_code:
void cleanUp(struct telpkt *t)
{
 free(t->output);
 free(t);
}


writeToUart

decompiled_code:
void __fastcall writeToUart(void *ptr, int fd)
{
encode((__int64)ptr);
write(fd, *((const void **)ptr + 3), *((_QWORD *)ptr + 5));
fsync(fd);
free(*((void **)ptr + 1));
cleanUp(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr, int fd)
{
func3((__int64)ptr);
write(fd, *((const void **)ptr + 3), *((_QWORD *)ptr + 5));
fsync(fd);
free(*((void **)ptr + 1));
func4(ptr);
}

original_code:
void writeToUart(struct telpkt* t, int fd)
{
 encode(t);
 write(fd, t->output, t->outputSize);
 fsync(fd);
 free(t->data);
 cleanUp(t);
}

canonical_original_code:
void writeToUart(struct telpkt *t, int fd)
{
 encode(t);
 write(fd, t->output, t->outputSize);
 fsync(fd);
 free(t->data);
 cleanUp(t);
}


exitWithError

decompiled_code:
void __fastcall __noreturn exitWithError(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void exitWithError(const char* message)
{
 perror(message);
 exit(1);
}

canonical_original_code:
void exitWithError(char *message)
{
 perror(message);
 exit(1);
}

variable_types:
message
char *


xioctl

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

result = ioctl(a1, a2);
if ( result == -1 )
exitWithError((const char *)&unk_BC);
return result;
}

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

result = ioctl(a1, a2);
if ( result == -1 )
func0((const char *)&unk_BC);
return result;
}

original_code:
void xioctl(int fd, int request, void *arg)
{
 if (-1 == ioctl(fd, request, arg)) {
  exitWithError("");
 }
}

variable_types: request int

variable_types:
arg
void *


byteToInt

decompiled_code:
__int64 __fastcall byteToInt(unsigned __int8 *a1)
{
return *a1 + (a1[1] << 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1)
{
return *a1 + (a1[1] << 8);
}

original_code:
uint16_t byteToInt(byte bytes[2])
{
 uint16_t rv = 0;
 rv += (bytes[1] & 0xFF) << 8;
 rv += (bytes[0] & 0xFF);
 return rv;
}

canonical_original_code:
unsigned short byteToInt(unsigned char bytes[2])
{
 unsigned short rv = 0;
 rv += (bytes[1] & 0xFF) << 8;
 rv += (bytes[0] & 0xFF);
 return rv;
}

variable_types:
bytes
unsigned char [2]

variable_types:
rv
unsigned short


kdestroy

decompiled_code:
__int64 __fastcall kdestroy(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 4);
if ( v4 )
free(v4);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
void *v2; // rdi
void *v3; // rdi
void *v4; // rdi

if ( !ptr )
return 0LL;
v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
v3 = (void *)*((_QWORD *)ptr + 5);
if ( v3 )
free(v3);
v4 = (void *)*((_QWORD *)ptr + 4);
if ( v4 )
free(v4);
free(ptr);
return 0LL;
}

original_code:
int kdestroy(struct Key *key)
{
  if(key != ((void *)0)) {
    if(key->bifents != ((void *)0))
      free(key->bifents);
    if(key->resents != ((void *)0))
      free(key->resents);
    if(key->strdata != ((void *)0))
      free(key->strdata);
    free(key);
  }
  return 0;
}

variable_types: struct Key { char signature[4]; char version[4]; unsigned int countbif; unsigned int countres; unsigned int offsetbif; unsigned int offsetres; struct KBifEnt { unsigned int length; unsigned int offsetfname; unsigned short lenfname; unsigned short locator; } *bifents; char *strdata; struct KResEnt { char resname[8]; unsigned short restype; unsigned int reslocator; } *resents; } *

user_defined_types: struct Key { char signature[4]; char version[4]; unsigned int countbif; unsigned int countres; unsigned int offsetbif; unsigned int offsetres; struct KBifEnt *bifents; char *strdata; struct KResEnt *resents; }


kbifstr

decompiled_code:
void *__fastcall kbifstr(__int64 a1, __int64 a2, unsigned __int16 a3)
{
void *v3; // r12
size_t v4; // r13
__int64 v5; // rbp
void *v6; // rax
int *v8; // rax
char *v9; // r8
int *v10; // rbx
int *v11; // rax
char *v12; // r8
int *v13; // rbx

if ( a1 )
{
v3 = 0LL;
if ( a3 )
{
v4 = a3;
v5 = (unsigned int)(HIDWORD(a2) - 24 - 12 * *(_DWORD *)(a1 + 8));
v6 = malloc(a3);
v3 = v6;
if ( v6 )
{
memcpy(v6, (const void *)(v5 + *(_QWORD *)(a1 + 32)), v4);
}
else
{
v11 = _errno_location();
v12 = "None";
v13 = v11;
if ( *v11 )
v12 = strerror(*v11);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/ie_c.c", 103LL, v12);
*v13 = 0;
}
}
}
else
{
v8 = _errno_location();
v9 = "None";
v10 = v8;
if ( *v8 )
v9 = strerror(*v8);
v3 = 0LL;
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) key cannot be NULL\n", "src/ie_c.c", 98LL, v9);
*v10 = 0;
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, __int64 a2, unsigned __int16 a3)
{
void *v3; // r12
size_t v4; // r13
__int64 v5; // rbp
void *v6; // rax
int *v8; // rax
char *v9; // r8
int *v10; // rbx
int *v11; // rax
char *v12; // r8
int *v13; // rbx

if ( a1 )
{
v3 = 0LL;
if ( a3 )
{
v4 = a3;
v5 = (unsigned int)(HIDWORD(a2) - 24 - 12 * *(_DWORD *)(a1 + 8));
v6 = malloc(a3);
v3 = v6;
if ( v6 )
{
memcpy(v6, (const void *)(v5 + *(_QWORD *)(a1 + 32)), v4);
}
else
{
v11 = _errno_location();
v12 = "None";
v13 = v11;
if ( *v11 )
v12 = strerror(*v11);
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) Out of memory.\n", "src/ie_c.c", 103LL, v12);
*v13 = 0;
}
}
}
else
{
v8 = _errno_location();
v9 = "None";
v10 = v8;
if ( *v8 )
v9 = strerror(*v8);
v3 = 0LL;
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) key cannot be NULL\n", "src/ie_c.c", 98LL, v9);
*v10 = 0;
}
return v3;
}

original_code:
char *kbifstr(struct Key *key, struct KBifEnt kbe)
{
  if(!(key)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "key cannot be NULL" "\n", "src/ie_c.c", 98, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  if(kbe.lenfname > 0) {
    size_t size = kbe.lenfname;
    size_t stroffset = kbe.offsetfname - (24 + 12 * key->countbif);
    char *str = malloc(size);
    if(!((str))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/ie_c.c", 103, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
    memcpy(str, &key->strdata[stroffset], size);
    return str;
  }
error:
  return ((void *)0);
}

canonical_original_code:
char *kbifstr(struct Key *key, struct KBifEnt kbe)
{
  if(!(key)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "key cannot be NULL" "\n", "src/ie_c.c", 98, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  if(kbe.lenfname > 0) {
    unsigned long size = kbe.lenfname;
    unsigned long stroffset = kbe.offsetfname - (24 + 12 * key->countbif);
    char *str = malloc(size);
    if(!((str))) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "Out of memory." "\n", "src/ie_c.c", 103, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
    memcpy(str, &key->strdata[stroffset], size);
    return str;
  }
error:
  return ((void *)0);
}

variable_types:
kbe
struct KBifEnt

variable_types:
size
unsigned long

variable_types:
stroffset
unsigned long

variable_types:
str
char *

user_defined_types: struct KBifEnt { unsigned int length; unsigned int offsetfname; unsigned short lenfname; unsigned short locator; }

user_defined_types: struct KResEnt { char resname[8]; unsigned short restype; unsigned int reslocator; }


kfindres

decompiled_code:
const char *__fastcall kfindres(char *s1, __int64 a2)
{
int v2; // edx
const char *v3; // r12
__int64 v4; // rbp
int *v6; // rax
char *v7; // r8
int *v8; // rbx

if ( !a2 )
{
v6 = _errno_location();
v7 = "None";
v8 = v6;
if ( *v6 )
v7 = strerror(*v6);
v3 = 0LL;
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) key cannot be NULL\n", "src/ie_c.c", 113LL, v7);
*v8 = 0;
return v3;
}
v2 = *(_DWORD *)(a2 + 12);
if ( v2 > 0 )
{
v3 = (const char *)(*(_QWORD *)(a2 + 40) + 14LL * v2);
v4 = (__int64)&v3[-14 * (v2 - 1) - 14];
while ( strncmp(s1, v3, 8uLL) )
{
v3 -= 14;
if ( v3 == (const char *)v4 )
return 0LL;
}
return v3;
}
return 0LL;
}

canonical_decompiled_code:
const char *__fastcall func4(char *s1, __int64 a2)
{
int v2; // edx
const char *v3; // r12
__int64 v4; // rbp
int *v6; // rax
char *v7; // r8
int *v8; // rbx

if ( !a2 )
{
v6 = _errno_location();
v7 = "None";
v8 = v6;
if ( *v6 )
v7 = strerror(*v6);
v3 = 0LL;
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) key cannot be NULL\n", "src/ie_c.c", 113LL, v7);
*v8 = 0;
return v3;
}
v2 = *(_DWORD *)(a2 + 12);
if ( v2 > 0 )
{
v3 = (const char *)(*(_QWORD *)(a2 + 40) + 14LL * v2);
v4 = (__int64)&v3[-14 * (v2 - 1) - 14];
while ( strncmp(s1, v3, 8uLL) )
{
v3 -= 14;
if ( v3 == (const char *)v4 )
return 0LL;
}
return v3;
}
return 0LL;
}

original_code:
struct KResEnt *kfindres(const char *resname, struct Key *key)
{
  if(!(key)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "key cannot be NULL" "\n", "src/ie_c.c", 113, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  int i = key->countres;
  struct KResEnt *kre;
  for(; i > 0; i--) {
    kre = &key->resents[i];
    if(strncmp(resname, kre->resname, 8) == 0)
      return kre;
  }
error:
  return ((void *)0);
}

canonical_original_code:
struct KResEnt *kfindres(char *resname, struct Key *key)
{
  if(!(key)) { fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " "key cannot be NULL" "\n", "src/ie_c.c", 113, ((*__errno_location ()) == 0 ? "None" : strerror((*__errno_location ())))); (*__errno_location ())=0; goto error; };
  int i = key->countres;
  struct KResEnt *kre;
  for(; i > 0; i--) {
    kre = &key->resents[i];
    if(strncmp(resname, kre->resname, 8) == 0)
      return kre;
  }
error:
  return ((void *)0);
}

variable_types:
resname
char *

variable_types: struct Key { char signature[4]; char version[4]; unsigned int countbif; unsigned int countres; unsigned int offsetbif; unsigned int offsetres; struct KBifEnt { unsigned int length; unsigned int offsetfname; unsigned short lenfname; unsigned short locator; } *bifents; char *strdata; struct KResEnt *resents; } *

variable_types: struct KResEnt { char resname[8]; unsigned short restype; unsigned int reslocator; } *


kfindbif

original_code:
struct KBifEnt *kfindbif(struct Key *key, struct KResEnt *kre)
{
  unsigned int bifindex = (kre->reslocator & 0xFFF00000) >> 20;
  return &key->bifents[bifindex];
}

variable_types: struct Key { char signature[4]; char version[4]; unsigned int countbif; unsigned int countres; unsigned int offsetbif; unsigned int offsetres; struct KBifEnt *bifents; char *strdata; struct KResEnt { char resname[8]; unsigned short restype; unsigned int reslocator; } *resents; } *

variable_types:
kre
struct KResEnt *

variable_types:
bifindex
unsigned int

return_type: struct KBifEnt { unsigned int length; unsigned int offsetfname; unsigned short lenfname; unsigned short locator; } *


bdestroy

decompiled_code:
__int64 __fastcall bdestroy(void *ptr)
{
char *v2; // rdi
unsigned int v3; // ebx
__int64 v4; // rax
char *v5; // rdi
unsigned int v6; // ebx
__int64 v7; // rdx

if ( !ptr )
return 0LL;
v2 = *(char **)((char *)ptr + 20);
if ( v2 )
{
if ( *((_DWORD *)ptr + 2) )
{
v3 = 0;
do
{
v4 = v3++;
free(*(void **)&v2[26 * v4 + 18]);
v2 = *(char **)((char *)ptr + 20);
}
while ( *((_DWORD *)ptr + 2) > v3 );
}
free(v2);
}
v5 = *(char **)((char *)ptr + 28);
if ( v5 )
{
if ( *((_DWORD *)ptr + 3) )
{
v6 = 0;
do
{
v7 = v6++;
free(*(void **)&v5[28 * v7 + 20]);
v5 = *(char **)((char *)ptr + 28);
}
while ( *((_DWORD *)ptr + 3) > v6 );
}
free(v5);
}
free(ptr);
return 0LL;
}

original_code:
int bdestroy(struct Bif *bif)
{
  if(bif != ((void *)0)) {
    if(bif->bfents != ((void *)0)) {
      uint32_t i;
      for(i = 0; i < bif->numfiles; i++)
        free(bif->bfents[i].data);
      free(bif->bfents);
    }
    if(bif->btents != ((void *)0)) {
      uint32_t i;
      for(i = 0; i < bif->numtilesets; i++)
        free(bif->btents[i].data);
      free(bif->btents);
    }
    free(bif);
  }
  return 0;
}

canonical_original_code:
int bdestroy(struct Bif *bif)
{
  if(bif != ((void *)0)) {
    if(bif->bfents != ((void *)0)) {
      unsigned int i;
      for(i = 0; i < bif->numfiles; i++)
        free(bif->bfents[i].data);
      free(bif->bfents);
    }
    if(bif->btents != ((void *)0)) {
      unsigned int i;
      for(i = 0; i < bif->numtilesets; i++)
        free(bif->btents[i].data);
      free(bif->btents);
    }
    free(bif);
  }
  return 0;
}

variable_types: struct Bif { char signature[4]; unsigned int numfiles; unsigned int numtilesets; unsigned int offset; struct BFileEnt { unsigned char resLoc[4]; unsigned int offset; unsigned int size; unsigned int type; void *data; } *bfents; struct BTileEnt { unsigned char resLoc[4]; unsigned int offset; unsigned int numtiles; unsigned int tilesize; unsigned short type; void *data; } *btents; } *

variable_types:
i
unsigned int

user_defined_types: struct Bif { char signature[4]; unsigned int numfiles; unsigned int numtilesets; unsigned int offset; struct BFileEnt *bfents; struct BTileEnt *btents; }


decompiled_code:
int dump_frq()
{
__int64 v0; // rbp
int result; // eax
char v2; // dl
int v3; // ebx

v0 = 0LL;
printf(
"frequency file dump utility.\nDumping file %s\n\nOriginal Size: %d\n",
frqfilename,
(unsigned int)originalsize);
result = puts("List of Frequency and Huffman Code. . .");
do
{
while ( frq[v0] <= 0 )
{
if ( ++v0 == 256 )
return result;
}
v2 = 32;
if ( (int)v0 >= 32 )
v2 = v0;
printf("Code: 0x%x\tChar: '%1c'\tFrqncy: %d\tHuffman Code: ", (unsigned int)v0, (unsigned int)v2);
v3 = bitlength[v0] - 1;
if ( v3 >= 0 )
{
do
printf("%d", (huffcode[v0] >> v3) & 1);
while ( v3-- != 0 );
}
++v0;
result = putchar(10);
}
while ( v0 != 256 );
return result;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rbp
int result; // eax
char v2; // dl
int v3; // ebx

v0 = 0LL;
printf(
"frequency file dump utility.\nDumping file %s\n\nOriginal Size: %d\n",
frqfilename,
(unsigned int)originalsize);
result = puts("List of Frequency and Huffman Code. . .");
do
{
while ( frq[v0] <= 0 )
{
if ( ++v0 == 256 )
return result;
}
v2 = 32;
if ( (int)v0 >= 32 )
v2 = v0;
printf("Code: 0x%x\tChar: '%1c'\tFrqncy: %d\tHuffman Code: ", (unsigned int)v0, (unsigned int)v2);
v3 = bitlength[v0] - 1;
if ( v3 >= 0 )
{
do
printf("%d", (huffcode[v0] >> v3) & 1);
while ( v3-- != 0 );
}
++v0;
result = putchar(10);
}
while ( v0 != 256 );
return result;
}

original_code:
void dump_frq()
{
  int i, j;
  char c;
  printf("frequency file dump utility.\nDumping file %s\n\nOriginal Size: %d\n", frqfilename, originalsize);
  printf("List of Frequency and Huffman Code. . .\n");
  for (i=0; i<256; i++) {
    if (frq[i] > 0) {
      if (i < 32) c = ' ';
      else c = (char)i;
      printf("Code: 0x%x\tChar: \'%1c\'\tFrqncy: %d\tHuffman Code: ", i, c, frq[i]);
      for (j=bitlength[i]-1; j>=0;j--)
        printf("%d", (huffcode[i] >> j) & 1);
      printf("\n");
    }
  }
}

canonical_original_code:
void dump_frq()
{
  int i; int j;
  char c;
  printf("frequency file dump utility.\nDumping file %s\n\nOriginal Size: %d\n", frqfilename, originalsize);
  printf("List of Frequency and Huffman Code. . .\n");
  for (i=0; i<256; i++) {
    if (frq[i] > 0) {
      if (i < 32) c = ' ';
      else c = (char)i;
      printf("Code: 0x%x\tChar: \'%1c\'\tFrqncy: %d\tHuffman Code: ", i, c, frq[i]);
      for (j=bitlength[i]-1; j>=0;j--)
        printf("%d", (huffcode[i] >> j) & 1);
      printf("\n");
    }
  }
}

variable_types: i int

variable_types: j int

variable_types: c char


decompiled_code:
int __fastcall file_error(const char *a1)
{
return fprintf(stderr, "Couldn't open the file: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
return fprintf(stderr, "Couldn't open the file: %s\n", a1);
}

original_code:
void file_error(char *filename)
{
  fprintf(stderr, "Couldn't open the file: %s\n", filename);
}

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall make_huffcode(unsigned __int8 *a1)
{
int v1; // edx
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rdi
int v6; // eax
__int64 v7; // rcx

v1 = tmpcode;
result = (unsigned int)tmplen;
v4 = *((_QWORD *)a1 + 1);
if ( v4 )
{
++tmplen;
tmpcode *= 2;
make_huffcode(v4);
v5 = *((_QWORD *)a1 + 2);
v6 = tmpcode | 1;
tmpcode |= 1u;
if ( v5 )
{
make_huffcode(v5);
v6 = tmpcode;
}
result = (unsigned int)(v6 >> 1);
--tmplen;
tmpcode = result;
}
else
{
v7 = *a1;
bitlength[v7] = tmplen;
huffcode[v7] = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 *a1)
{
int v1; // edx
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rdi
int v6; // eax
__int64 v7; // rcx

v1 = tmpcode;
result = (unsigned int)tmplen;
v4 = *((_QWORD *)a1 + 1);
if ( v4 )
{
++tmplen;
tmpcode *= 2;
func11(v4);
v5 = *((_QWORD *)a1 + 2);
v6 = tmpcode | 1;
tmpcode |= 1u;
if ( v5 )
{
func11(v5);
v6 = tmpcode;
}
result = (unsigned int)(v6 >> 1);
--tmplen;
tmpcode = result;
}
else
{
v7 = *a1;
bitlength[v7] = tmplen;
huffcode[v7] = v1;
}
return result;
}

original_code:
void make_huffcode(tnode_pointer tn)
{
  if (tn->left == ((void *)0)) {
    bitlength[(int)tn->c] = tmplen;
    huffcode[(int)tn->c] = tmpcode;
    return;
  }
  tmpcode = tmpcode << 1;
  tmplen++;
  make_huffcode(tn->left);
  tmpcode = tmpcode | 1;
  if (tn->right != ((void *)0)) make_huffcode(tn->right);
  tmplen--;
  tmpcode = tmpcode >> 1;
}

canonical_original_code:
void make_huffcode(struct tnode *tn)
{
  if (tn->left == ((void *)0)) {
    bitlength[(int)tn->c] = tmplen;
    huffcode[(int)tn->c] = tmpcode;
    return;
  }
  tmpcode = tmpcode << 1;
  tmplen++;
  make_huffcode(tn->left);
  tmpcode = tmpcode | 1;
  if (tn->right != ((void *)0)) make_huffcode(tn->right);
  tmplen--;
  tmpcode = tmpcode >> 1;
}

variable_types: struct tnode { unsigned char c; int frq; struct tnode *left; } *


decompiled_code:
__int64 make_hufftree()
{
__int64 v0; // rbx
__int64 v1; // rdi
__int64 v2; // rax
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v8; // rax

v0 = 0LL;
h = (void *)new_heap();
do
{
v1 = (unsigned int)frq[v0];
if ( (int)v1 > 0 )
{
v2 = new_tnode(v1, (unsigned int)v0, 0LL, 0LL);
heap_add(h, v2);
}
++v0;
}
while ( v0 != 256 );
if ( *(int *)h <= 1 )
{
v8 = ((__int64 (*)(void))heap_remove)();
v6 = new_tnode(0LL, 0LL, v8, 0LL);
}
else
{
do
{
v3 = ((__int64 (*)(void))heap_remove)();
v4 = heap_remove(h);
v5 = new_tnode((unsigned int)(*(_DWORD *)(v3 + 4) + *(_DWORD *)(v4 + 4)), 0LL, v3, v4);
heap_add(h, v5);
}
while ( *(int *)h > 1 );
v6 = heap_remove(h);
}
root = v6;
return free_heap(h);
}

original_code:
void make_hufftree()
{
  int i;
  tnode_pointer tn1, tn2;
  h = new_heap();
  for (i=0; i<256; i++)
    if (frq[i] > 0)
      heap_add(h, new_tnode(frq[i], (unsigned char)i, ((void *)0), ((void *)0)));
  if (h->size <= 1) {
    root = new_tnode(0,'\0',heap_remove(h),((void *)0));
    free_heap(h);
    return;
  }
  while (h->size > 1) {
    tn1 = heap_remove(h);
    tn2 = heap_remove(h);
    heap_add(h, new_tnode(tn1->frq+tn2->frq, '\0', tn1, tn2));
  }
  root = heap_remove(h);
  free_heap(h);
}

canonical_original_code:
void make_hufftree()
{
  int i;
  struct tnode *tn1; struct tnode *tn2;
  h = new_heap();
  for (i=0; i<256; i++)
    if (frq[i] > 0)
      heap_add(h, new_tnode(frq[i], (unsigned char)i, ((void *)0), ((void *)0)));
  if (h->size <= 1) {
    root = new_tnode(0,'\0',heap_remove(h),((void *)0));
    free_heap(h);
    return;
  }
  while (h->size > 1) {
    tn1 = heap_remove(h);
    tn2 = heap_remove(h);
    heap_add(h, new_tnode(tn1->frq+tn2->frq, '\0', tn1, tn2));
  }
  root = heap_remove(h);
  free_heap(h);
}

user_defined_types: struct tnode { unsigned char c; int frq; struct tnode *left; }


decompiled_code:
void __fastcall free_tnode(_QWORD *a1)
{
if ( a1[1] )
free_tnode();
if ( a1[2] )
free_tnode();
free(a1);
}

canonical_decompiled_code:
void __fastcall func13(_QWORD *a1)
{
if ( a1[1] )
func13();
if ( a1[2] )
func13();
free(a1);
}

original_code:
void free_tnode(tnode_pointer tn)
{
  if (tn->left != ((void *)0)) free_tnode(tn->left);
  if (tn->right != ((void *)0)) free_tnode(tn->right);
  free(tn);
}

canonical_original_code:
void free_tnode(struct tnode *tn)
{
  if (tn->left != ((void *)0)) free_tnode(tn->left);
  if (tn->right != ((void *)0)) free_tnode(tn->right);
  free(tn);
}


decompiled_code:
_DWORD *new_heap()
{
_DWORD *result; // rax

result = malloc(0x808uLL);
*result = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func14()
{
_DWORD *result; // rax

result = malloc(0x808uLL);
*result = 0;
return result;
}

original_code:
heap_pointer new_heap()
{
  heap_pointer hep = malloc(sizeof(heap_struct));
  hep->size = 0;
  return hep;
}

canonical_original_code:
struct heap *new_heap()
{
  struct heap *hep = malloc(sizeof(heap_struct));
  hep->size = 0;
  return hep;
}

variable_types: struct heap { int size; struct tnode { unsigned char c; int frq; struct tnode *left; } *node[256]; } *

user_defined_types: struct heap { int size; struct tnode *node[256]; }


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

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = (_QWORD *)*((_QWORD *)ptr + ++v2);
free_tnode(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(ptr);
}

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

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = (_QWORD *)*((_QWORD *)ptr + ++v2);
func13(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(ptr);
}

original_code:
void free_heap(heap_pointer h)
{
  int i;
  for (i=0; i < h->size; i++)
    free_tnode(h->node[i]);
  free(h);
}

canonical_original_code:
void free_heap(struct heap *h)
{
  int i;
  for (i=0; i < h->size; i++)
    free_tnode(h->node[i]);
  free(h);
}


decompiled_code:
size_t __fastcall heap_add(_DWORD *a1, __int64 a2)
{
size_t result; // rax
int v4; // er9
__int64 v5; // rdx
__int64 v6; // rsi

result = (unsigned int)*a1;
if ( (int)result > 255 )
return fwrite("Heap full error!\n", 1uLL, 0x11uLL, stderr);
*a1 = result + 1;
*(_QWORD *)&a1[2 * (int)result + 2] = a2;
if ( (int)result > 0 )
{
v4 = *(_DWORD *)(a2 + 4);
do
{
v5 = (int)result;
result = (unsigned int)(((int)result - 1) >> 1);
v6 = *(_QWORD *)&a1[2 * (int)result + 2];
if ( *(_DWORD *)(v6 + 4) <= v4 )
break;
*(_QWORD *)&a1[2 * v5 + 2] = v6;
*(_QWORD *)&a1[2 * (int)result + 2] = a2;
}
while ( (_DWORD)result );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func16(_DWORD *a1, __int64 a2)
{
size_t result; // rax
int v4; // er9
__int64 v5; // rdx
__int64 v6; // rsi

result = (unsigned int)*a1;
if ( (int)result > 255 )
return fwrite("Heap full error!\n", 1uLL, 0x11uLL, stderr);
*a1 = result + 1;
*(_QWORD *)&a1[2 * (int)result + 2] = a2;
if ( (int)result > 0 )
{
v4 = *(_DWORD *)(a2 + 4);
do
{
v5 = (int)result;
result = (unsigned int)(((int)result - 1) >> 1);
v6 = *(_QWORD *)&a1[2 * (int)result + 2];
if ( *(_DWORD *)(v6 + 4) <= v4 )
break;
*(_QWORD *)&a1[2 * v5 + 2] = v6;
*(_QWORD *)&a1[2 * (int)result + 2] = a2;
}
while ( (_DWORD)result );
}
return result;
}

original_code:
void heap_add(heap_pointer h, tnode_pointer n)
{
  int i = h->size;
  tnode_pointer tmp;
  if (h->size >= 256) {
    fprintf(stderr, "Heap full error!\n");
    return;
  }
  h->node[h->size++] = n;
  while (i>0) {
    if (h->node[i]->frq < h->node[(i-1)/2]->frq) {
      tmp = h->node[i];
      h->node[i] = h->node[(i-1)/2];
      h->node[(i-1)/2] = tmp;
      i = (i-1)/2;
    }
    else break;
  }
}

canonical_original_code:
void heap_add(struct heap *h, struct tnode *n)
{
  int i = h->size;
  struct tnode *tmp;
  if (h->size >= 256) {
    fprintf(stderr, "Heap full error!\n");
    return;
  }
  h->node[h->size++] = n;
  while (i>0) {
    if (h->node[i]->frq < h->node[(i-1)/2]->frq) {
      tmp = h->node[i];
      h->node[i] = h->node[(i-1)/2];
      h->node[(i-1)/2] = tmp;
      i = (i-1)/2;
    }
    else break;
  }
}

variable_types:
n
struct tnode *


original_code:
tnode_pointer heap_remove(heap_pointer h)
{
  int i=0;
  tnode_pointer tp = h->node[0];
  tnode_pointer tmp;
  int smaller;
  if (h->size<=0) return ((void *)0);
  h->node[0] = h->node[--h->size];
  while (i*2+1 < h->size) {
    if (i*2+2 == h->size) {
      if (h->node[i*2+1]->frq < h->node[i]->frq) {
        tmp = h->node[i*2+1];
        h->node[i*2+1] = h->node[i];
        h->node[i] = tmp;
      }
      break;
    }
    else {
      smaller = (h->node[i*2+1]->frq < h->node[i*2+2]->frq?i*2+1:i*2+2);
      if (h->node[i]->frq > h->node[smaller]->frq) {
        tmp = h->node[i];
        h->node[i] = h->node[smaller];
        h->node[smaller] = tmp;
        i=smaller;
      }
      else break;
    }
  }
  return tp;
}

canonical_original_code:
struct tnode *heap_remove(struct heap *h)
{
  int i = 0;
  struct tnode *tp = h->node[0];
  struct tnode *tmp;
  int smaller;
  if (h->size<=0) return ((void *)0);
  h->node[0] = h->node[--h->size];
  while (i*2+1 < h->size) {
    if (i*2+2 == h->size) {
      if (h->node[i*2+1]->frq < h->node[i]->frq) {
        tmp = h->node[i*2+1];
        h->node[i*2+1] = h->node[i];
        h->node[i] = tmp;
      }
      break;
    }
    else {
      smaller = (h->node[i*2+1]->frq < h->node[i*2+2]->frq?i*2+1:i*2+2);
      if (h->node[i]->frq > h->node[smaller]->frq) {
        tmp = h->node[i];
        h->node[i] = h->node[smaller];
        h->node[smaller] = tmp;
        i=smaller;
      }
      else break;
    }
  }
  return tp;
}

variable_types: struct heap { int size; struct tnode *node[256]; } *

variable_types: smaller int

return_type: struct tnode { unsigned char c; int frq; struct tnode *left; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 1 )
strcpy(frqfilename, "huffman.frq");
read_frqfile(argc, argv, envp);
make_hufftree();
make_huffcode(root);
dump_frq();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc <= 1 )
strcpy(frqfilename, "huffman.frq");
func10(argc, argv, envp);
func12();
func11(root);
func7();
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  if (argc < 2)
    strcpy(frqfilename, "huffman.frq");
  read_frqfile();
  make_hufftree();
  make_huffcode(root);
  dump_frq();
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: jahrome/curltunnel-android

decompiled_code:
int print_options()
{
return puts(
"curltunnel\n"
"Copyright 2007 curltunnel Project\n"
"V 0.1-dev\n"
"\n"
"-h --help Print help and exit\n"
"-p --proxy=STRING Proxy host:port combination to connect to\n"
"-u --user=STRING User:Password combination to send to proxy\n"
"-d --dest=STRING Host:port combination to tunnel to\n"
"-v --verbose Print messages about what's going on");
}

canonical_decompiled_code:
int func7()
{
return puts(
"curltunnel\n"
"Copyright 2007 curltunnel Project\n"
"V 0.1-dev\n"
"\n"
"-h --help Print help and exit\n"
"-p --proxy=STRING Proxy host:port combination to connect to\n"
"-u --user=STRING User:Password combination to send to proxy\n"
"-d --dest=STRING Host:port combination to tunnel to\n"
"-v --verbose Print messages about what's going on");
}

original_code:
static void print_options(void)
{
  printf("curltunnel\nCopyright 2007 curltunnel Project\nV " "0.1-dev" "\n"
      "\n"
      "-h       --help            Print help and exit\n"
      "-p       --proxy=STRING    Proxy host:port combination to connect to\n"
      "-u       --user=STRING     User:Password combination to send to proxy\n"
      "-d       --dest=STRING     Host:port combination to tunnel to\n"
      "-v       --verbose         Print messages about what's going on\n");
}

canonical_original_code:
static void print_options()
{
  printf("curltunnel\nCopyright 2007 curltunnel Project\nV " "0.1-dev" "\n"
      "\n"
      "-h       --help            Print help and exit\n"
      "-p       --proxy=STRING    Proxy host:port combination to connect to\n"
      "-u       --user=STRING     User:Password combination to send to proxy\n"
      "-d       --dest=STRING     Host:port combination to tunnel to\n"
      "-v       --verbose         Print messages about what's going on\n");
}


decompiled_code:
ssize_t __fastcall fd_write(int a1, const void *a2, size_t a3)
{
return write(a1, a2, a3);
}

canonical_decompiled_code:
ssize_t __fastcall func8(int a1, const void *a2, size_t a3)
{
return write(a1, a2, a3);
}

original_code:
static int fd_write(int fd, void *buf, size_t len)
{
  int bytes_written;
  bytes_written = write(fd,buf,len);
  return bytes_written;
}

canonical_original_code:
static int fd_write(int fd, void *buf, unsigned long len)
{
  int bytes_written;
  bytes_written = write(fd,buf,len);
  return bytes_written;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
len
unsigned long


fdcopy

decompiled_code:
__int64 __fastcall fdcopy(int a1, int a2)
{
int v2; // eax
bool v3; // zf
int v4; // ebx
__int64 result; // rax
_BYTE v6[655560]; // [rsp+0h] [rbp-A00C8h] BYREF

v2 = fd_read_constprop_0(a1, v6);
v3 = v2 == 0;
if ( v2 < 0 )
{
fwrite("Read Error\n", 1uLL, 0xBuLL, stderr);
exit(1);
}
v4 = v2;
result = 1LL;
if ( !v3 )
{
if ( (unsigned int)fd_write(a2, v6, v4) != v4 )
{
fwrite("Write Error\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2)
{
int v2; // eax
bool v3; // zf
int v4; // ebx
__int64 result; // rax
_BYTE v6[655560]; // [rsp+0h] [rbp-A00C8h] BYREF

v2 = func9(a1, v6);
v3 = v2 == 0;
if ( v2 < 0 )
{
fwrite("Read Error\n", 1uLL, 0xBuLL, stderr);
exit(1);
}
v4 = v2;
result = 1LL;
if ( !v3 )
{
if ( (unsigned int)func8(a2, v6, v4) != v4 )
{
fwrite("Write Error\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
result = 0LL;
}
return result;
}

original_code:
static int fdcopy(int fdin, int fdout)
{
  char buf[655536];
  int n;
  if((n=fd_read(fdin,buf,655536))<0)
  {
    fprintf(stderr,"Read Error\n");
    exit(1);
  }
  if(n==0)
    return 1;
  if(fd_write(fdout,buf,n)!=n)
  {
    fprintf(stderr,"Write Error\n");
    exit(1);
  }
  return 0;
}

variable_types: fdin int

variable_types: fdout int

variable_types: n int


decompiled_code:
__int64 __fastcall wait_and_act(int a1, int a2)
{
__int64 v2; // r15
int v3; // er14
int v4; // eax
int v5; // eax
int v6; // eax
__int64 result; // rax
int v8; // eax
__int64 v9; // [rsp+0h] [rbp-1E8h]
__fd_mask v10; // [rsp+10h] [rbp-1D8h]
struct timeval timeout; // [rsp+20h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-1B8h] BYREF
fd_set writefds; // [rsp+B0h] [rbp-138h] BYREF
fd_set exceptfds; // [rsp+130h] [rbp-B8h] BYREF

v2 = a1 / 64;
v9 = 1LL << (a1 % 64);
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
memset(&exceptfds, 0, sizeof(exceptfds));
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
v3 = fileno(stdin);
v4 = fileno(stdin);
readfds.fds_bits[v4 / 64] |= 1LL << (v3 % 64);
readfds.fds_bits[v2] |= v9;
v5 = select(a1 + 1, &readfds, &writefds, &exceptfds, &timeout);
if ( v5 == -1 )
break;
if ( v5 )
{
v10 = readfds.fds_bits[fileno(stdin) / 64];
if ( ((1LL << (fileno(stdin) % 64)) & v10) != 0 )
{
v8 = fileno(stdin);
result = fdcopy(v8, a1);
if ( !(_DWORD)result )
return result;
if ( a2 )
fprintf(stderr, "VERBOSE: Sent %d bytes from stdin to socket\n", (unsigned int)result);
}
if ( (readfds.fds_bits[v2] & v9) != 0 )
{
v6 = fileno(stdout);
result = fdcopy(a1, v6);
if ( !(_DWORD)result )
return result;
if ( a2 )
fprintf(stderr, "VERBOSE: Sent %d bytes from socket to stdin\n", (unsigned int)result);
}
}
else if ( a2 )
{
fprintf(stderr, "VERBOSE: Timeout after %ldms\n", 10000LL);
}
}
return fwrite("select() error\n", 1uLL, 0xFuLL, stderr);
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1, int a2)
{
__int64 v2; // r15
int v3; // er14
int v4; // eax
int v5; // eax
int v6; // eax
__int64 result; // rax
int v8; // eax
__int64 v9; // [rsp+0h] [rbp-1E8h]
__fd_mask v10; // [rsp+10h] [rbp-1D8h]
struct timeval timeout; // [rsp+20h] [rbp-1C8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-1B8h] BYREF
fd_set writefds; // [rsp+B0h] [rbp-138h] BYREF
fd_set exceptfds; // [rsp+130h] [rbp-B8h] BYREF

v2 = a1 / 64;
v9 = 1LL << (a1 % 64);
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
memset(&exceptfds, 0, sizeof(exceptfds));
timeout.tv_sec = 10LL;
timeout.tv_usec = 0LL;
v3 = fileno(stdin);
v4 = fileno(stdin);
readfds.fds_bits[v4 / 64] |= 1LL << (v3 % 64);
readfds.fds_bits[v2] |= v9;
v5 = select(a1 + 1, &readfds, &writefds, &exceptfds, &timeout);
if ( v5 == -1 )
break;
if ( v5 )
{
v10 = readfds.fds_bits[fileno(stdin) / 64];
if ( ((1LL << (fileno(stdin) % 64)) & v10) != 0 )
{
v8 = fileno(stdin);
result = func10(v8, a1);
if ( !(_DWORD)result )
return result;
if ( a2 )
fprintf(stderr, "VERBOSE: Sent %d bytes from stdin to socket\n", (unsigned int)result);
}
if ( (readfds.fds_bits[v2] & v9) != 0 )
{
v6 = fileno(stdout);
result = func10(a1, v6);
if ( !(_DWORD)result )
return result;
if ( a2 )
fprintf(stderr, "VERBOSE: Sent %d bytes from socket to stdin\n", (unsigned int)result);
}
}
else if ( a2 )
{
fprintf(stderr, "VERBOSE: Timeout after %ldms\n", 10000LL);
}
}
return fwrite("select() error\n", 1uLL, 0xFuLL, stderr);
}

original_code:
static void wait_and_act(int sockfd, int verbose)
{
  struct timeval timeout;
  int rc;
  long timeout_ms = 10000;
  fd_set fdread;
  fd_set fdwrite;
  fd_set fdexcep;
  int maxfd=sockfd;
  while(1==1)
  {
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdread)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdwrite)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdexcep)->__fds_bits)[0]) : "memory"); } while (0);
    timeout.tv_sec = timeout_ms/1000;
    timeout.tv_usec = (timeout_ms%1000)*1000;
    ((void) (((&fdread)->__fds_bits)[((fileno(stdin)) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fileno(stdin)) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&fdread)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    rc = select(maxfd+1,
          (fd_set *)&fdread,
          (fd_set *)&fdwrite,
          (fd_set *)&fdexcep, &timeout);
    if(rc==-1) {
      fprintf(stderr,"select() error\n");
      break;
    }
    if(rc==0){
      if(verbose)
          fprintf(stderr,"VERBOSE: Timeout after %ldms\n", timeout_ms);
    }
    else
    {
      if (((((&fdread)->__fds_bits)[((fileno(stdin)) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fileno(stdin)) % (8 * (int) sizeof (__fd_mask)))))) != 0))
      {
        rc=fdcopy(fileno(stdin),sockfd);
        if(!rc)
          break;
        if(verbose)
          fprintf(stderr,"VERBOSE: Sent %d bytes from stdin to socket\n", rc);
      }
      if (((((&fdread)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
      {
        rc=fdcopy(sockfd,fileno(stdout));
        if(!rc)
          break;
        if(verbose)
          fprintf(stderr,"VERBOSE: Sent %d bytes from socket to stdin\n", rc);
      }
    }
  }
}

canonical_original_code:
static void wait_and_act(int sockfd, int verbose)
{
  struct timeval timeout;
  int rc;
  long timeout_ms = 10000;
  struct fd_set fdread;
  struct fd_set fdwrite;
  struct fd_set fdexcep;
  int maxfd = sockfd;
  while(1==1)
  {
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdread)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdwrite)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fdexcep)->__fds_bits)[0]) : "memory"); } while (0);
    timeout.tv_sec = timeout_ms/1000;
    timeout.tv_usec = (timeout_ms%1000)*1000;
    ((void) (((&fdread)->__fds_bits)[((fileno(stdin)) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fileno(stdin)) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&fdread)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))));
    rc = select(maxfd+1,
          (struct fd_set *)&fdread,
          (struct fd_set *)&fdwrite,
          (struct fd_set *)&fdexcep, &timeout);
    if(rc==-1) {
      fprintf(stderr,"select() error\n");
      break;
    }
    if(rc==0){
      if(verbose)
          fprintf(stderr,"VERBOSE: Timeout after %ldms\n", timeout_ms);
    }
    else
    {
      if (((((&fdread)->__fds_bits)[((fileno(stdin)) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fileno(stdin)) % (8 * (int) sizeof (__fd_mask)))))) != 0))
      {
        rc=fdcopy(fileno(stdin),sockfd);
        if(!rc)
          break;
        if(verbose)
          fprintf(stderr,"VERBOSE: Sent %d bytes from stdin to socket\n", rc);
      }
      if (((((&fdread)->__fds_bits)[((sockfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockfd) % (8 * (int) sizeof (__fd_mask)))))) != 0))
      {
        rc=fdcopy(sockfd,fileno(stdout));
        if(!rc)
          break;
        if(verbose)
          fprintf(stderr,"VERBOSE: Sent %d bytes from socket to stdin\n", rc);
      }
    }
  }
}

variable_types: sockfd int

variable_types: verbose int

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

variable_types: rc int

variable_types:
fdread
struct fd_set { long __fds_bits[-1]; }

variable_types:
fdwrite
struct fd_set { long __fds_bits[-1]; }

variable_types:
fdexcep
struct fd_set { long __fds_bits[-1]; }

variable_types: maxfd int


hashPJW

repo: jakeleichtling/Compiler

decompiled_code:
__int64 __fastcall hashPJW(_BYTE *a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax

v2 = (char)*a1;
if ( !*a1 )
return 0LL;
v3 = 0;
do
{
v3 = v2 + 16 * v3;
if ( (v3 & 0xF0000000) != 0 )
v3 = ((v3 & 0xF0000000) >> 24) ^ v3 & 0xFFFFFFF;
v2 = (char)*++a1;
}
while ( (_BYTE)v2 );
return v3 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned int a2)
{
int v2; // edx
unsigned int v3; // eax

v2 = (char)*a1;
if ( !*a1 )
return 0LL;
v3 = 0;
do
{
v3 = v2 + 16 * v3;
if ( (v3 & 0xF0000000) != 0 )
v3 = ((v3 & 0xF0000000) >> 24) ^ v3 & 0xFFFFFFF;
v2 = (char)*++a1;
}
while ( (_BYTE)v2 );
return v3 % a2;
}

original_code:
static int hashPJW(char *s, int size) {
  unsigned h = 0, g;
  char *p;
  for (p = s; *p != '\0'; p++) {
      h = (h << 4) + *p;
      if ((g = (h & 0xf0000000)) != 0)
 h ^= (g >> 24) ^ g;
    }
  return h % size;
}

canonical_original_code:
static int hashPJW(char *s, int size) {
  unsigned int h = 0; unsigned int g;
  char *p;
  for (p = s; *p != '\0'; p++) {
      h = (h << 4) + *p;
      if ((g = (h & 0xf0000000)) != 0)
 h ^= (g >> 24) ^ g;
    }
  return h % size;
}

variable_types:
s
char *

variable_types: size int

variable_types:
h
unsigned int

variable_types:
g
unsigned int

variable_types:
p
char *


decompiled_code:
void __fastcall destroy_symnode(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

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

original_code:
static void destroy_symnode(symnode node) {
  free(node->name);
  free(node);
}

canonical_original_code:
static void destroy_symnode(struct symnode *node) {
  free(node->name);
  free(node);
}

variable_types: struct symnode { char *name; struct symnode *next; enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 } var_type; int var_addr; enum memaddrtype { off_fp=0, global=1 } mem_addr_type; enum nodetype { func_node=0, val_node=1, array_node=2 } node_type; int array_size; char *mangled_name; int num_vars; int num_temps; int num_params; struct symnode **param_symnode_array; } *

user_defined_types: struct symnode { char *name; struct symnode *next; enum vartype var_type; int var_addr; enum memaddrtype mem_addr_type; enum nodetype node_type; int array_size; char *mangled_name; int num_vars; int num_temps; int num_params; struct symnode **param_symnode_array; }


decompiled_code:
void __fastcall destroy_symhashtable(__int64 a1)
{
__int64 v2; // rbp
_QWORD *v3; // rbx
void *v4; // rdi

if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD **)(*(_QWORD *)(a1 + 8) + 8 * v2);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[1];
destroy_symnode(v4);
}
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
}

original_code:
static void destroy_symhashtable(symhashtable hashtable) {
  int i;
  for (i = 0; i < hashtable->size; i++) {
    symnode node, next;
    for (node = hashtable->table[i]; node != ((void *)0); node = next) {
      next = node->next;
      destroy_symnode(node);
    }
  }
}

canonical_original_code:
static void destroy_symhashtable(struct symhashtable *hashtable) {
  int i;
  for (i = 0; i < hashtable->size; i++) {
    struct symnode *node; struct symnode *next;
    for (node = hashtable->table[i]; node != ((void *)0); node = next) {
      next = node->next;
      destroy_symnode(node);
    }
  }
}

variable_types: struct symhashtable { int size; struct symnode { char *name; struct symnode *next; enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 } var_type; int var_addr; enum memaddrtype { off_fp=0, global=1 } mem_addr_type; enum nodetype { func_node=0, val_node=1, array_node=2 } node_type; int array_size; char *mangled_name; int num_vars; int num_temps; int num_params; struct symnode **param_symnode_array; } **table; struct symhashtable *outer_scope; int level; } *

variable_types: i int

user_defined_types: struct symhashtable { int size; struct symnode **table; struct symhashtable *outer_scope; int level; }


decompiled_code:
void __fastcall set_node_nodetype(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 16) = a2;
}

original_code:
void set_node_nodetype(symnode node, enum nodetype type)
{
  node->node_type = type;
}

canonical_original_code:
void set_node_nodetype(struct symnode *node, enum nodetype type)
{
  node->node_type = type;
}

variable_types: struct symnode { char *name; struct symnode *next; enum nodetype { identifier=0, stringconst=1 } node_type; enum vartype { inttype=0, doubletype=1, voidtype=2 } var_type; int varaddr; } *

user_defined_types: struct symnode { char *name; struct symnode *next; enum nodetype node_type; enum vartype var_type; int varaddr; }


decompiled_code:
void __fastcall set_node_vartype(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 20) = a2;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 20) = a2;
}

original_code:
void set_node_vartype(symnode node, enum vartype type)
{
  node->var_type = type;
}

canonical_original_code:
void set_node_vartype(struct symnode *node, enum vartype type)
{
  node->var_type = type;
}

variable_types: enum vartype { inttype=0, doubletype=1, voidtype=2 }

user_defined_types: enum nodetype { identifier=0, stringconst=1 }


decompiled_code:
void __fastcall set_node_addr(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 24) = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 24) = a2;
}

original_code:
void set_node_addr(symnode node, int addr)
{
  node->varaddr = addr;
}

canonical_original_code:
void set_node_addr(struct symnode *node, int addr)
{
  node->varaddr = addr;
}

variable_types: addr int

user_defined_types: enum vartype { inttype=0, doubletype=1, voidtype=2 }


decompiled_code:
_BOOL8 __fastcall name_is_equal(const char **a1, const char *a2)
{
return strcmp(*a1, a2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const char **a1, const char *a2)
{
return strcmp(*a1, a2) == 0;
}

original_code:
int name_is_equal(symnode node, char *name) {
  return !strcmp(node->name, name);
}

canonical_original_code:
int name_is_equal(struct symnode *node, char *name) {
  return !strcmp(node->name, name);
}

variable_types:
name
char *

user_defined_types: enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 }

user_defined_types: enum nodetype { func_node=0, val_node=1, array_node=2 }


decompiled_code:
void __fastcall destroy_symboltable(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // rdi

v1 = *a1;
while ( v1 )
{
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
destroy_symhashtable(v2);
}
}

original_code:
void destroy_symboltable(symboltable symtab) {
  symhashtable table, outer;
  for (table = symtab->inner_scope; table != ((void *)0); table = outer) {
    outer = table->outer_scope;
    destroy_symhashtable(table);
  }
}

canonical_original_code:
void destroy_symboltable(struct symboltable *symtab) {
  struct symhashtable *table; struct symhashtable *outer;
  for (table = symtab->inner_scope; table != ((void *)0); table = outer) {
    outer = table->outer_scope;
    destroy_symhashtable(table);
  }
}

variable_types: struct symboltable { struct symhashtable { int size; struct symnode { char *name; struct symnode *next; enum vartype { no_type=0, inttype=1, doubletype=2, voidtype=3 } var_type; int var_addr; enum memaddrtype { off_fp=0, global=1 } mem_addr_type; enum nodetype { func_node=0, val_node=1, array_node=2 } node_type; int array_size; char *mangled_name; int num_vars; int num_temps; int num_params; struct symnode **param_symnode_array; } **table; struct symhashtable *outer_scope; int level; } *inner_scope; int num_nodes; } *

user_defined_types: struct symboltable { struct symhashtable *inner_scope; int num_nodes; }


decompiled_code:
void __fastcall leave_scope(__int64 *a1)
{
__int64 v1; // r8

v1 = *a1;
*a1 = *(_QWORD *)(*a1 + 16);
destroy_symhashtable(v1);
}

original_code:
void leave_scope(symboltable symtab) {
  symhashtable hashtable = symtab->inner_scope;
  symtab->inner_scope = hashtable->outer_scope;
  destroy_symhashtable(hashtable);
}

canonical_original_code:
void leave_scope(struct symboltable *symtab) {
  struct symhashtable *hashtable = symtab->inner_scope;
  symtab->inner_scope = hashtable->outer_scope;
  destroy_symhashtable(hashtable);
}


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

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ***)a1;
v4 = *(_QWORD *)a1 + 8LL * (unsigned int)(v2 - 1) + 8;
while ( 1 )
{
v5 = *v3;
if ( *v3 )
{
if ( !strcmp(*v3, a2) )
break;
}
if ( ++v3 == (const char **)v4 )
return 0LL;
}
return v5;
}

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

v2 = *(_DWORD *)(a1 + 8);
if ( v2 <= 0 )
return 0LL;
v3 = *(const char ***)a1;
v4 = *(_QWORD *)a1 + 8LL * (unsigned int)(v2 - 1) + 8;
while ( 1 )
{
v5 = *v3;
if ( *v3 )
{
if ( !strcmp(*v3, a2) )
break;
}
if ( ++v3 == (const char **)v4 )
return 0LL;
}
return v5;
}

original_code:
char *lookup_string(Sst sst, char *str)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        char *str_bucket = *(sst->table_ptr + i);
        if (str_bucket != ((void *)0) && strcmp(str_bucket, str) == 0)
            return str_bucket;
    }
    return ((void *)0);
}

canonical_original_code:
char *lookup_string(struct simple_string_table_struct *sst, char *str)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        char *str_bucket = *(sst->table_ptr + i);
        if (str_bucket != ((void *)0) && strcmp(str_bucket, str) == 0)
            return str_bucket;
    }
    return ((void *)0);
}

variable_types: struct simple_string_table_struct { char **table_ptr; int size; } *

variable_types:
str
char *


original_code:
void expand_sst(Sst sst)
{
    int double_size = sst->size * 2;
    char **double_table_ptr = calloc(double_size, sizeof(char *));
    int i;
    for (i = 0; i < sst->size; i++)
        *(double_table_ptr + i) = *(sst->table_ptr + i);
    sst->size = double_size;
    free(sst->table_ptr);
    sst->table_ptr = double_table_ptr;
}

canonical_original_code:
void expand_sst(struct simple_string_table_struct *sst)
{
    int double_size = sst->size * 2;
    char **double_table_ptr = calloc(double_size, sizeof(char *));
    int i;
    for (i = 0; i < sst->size; i++)
        *(double_table_ptr + i) = *(sst->table_ptr + i);
    sst->size = double_size;
    free(sst->table_ptr);
    sst->table_ptr = double_table_ptr;
}

user_defined_types: struct simple_string_table_struct { char **table_ptr; int size; }


decompiled_code:
const char *__fastcall add_string(__int64 a1, const char *a2)
{
const char *result; // rax
int v3; // eax
char **v4; // rbx
__int64 v5; // rax
size_t v6; // rax
char *v7; // rax

result = lookup_string(a1, a2);
if ( !result )
{
while ( 1 )
{
v3 = *(_DWORD *)(a1 + 8);
if ( v3 > 0 )
break;
LABEL_3:
expand_sst(a1);
}
v4 = *(char ***)a1;
v5 = *(_QWORD *)a1 + 8LL * (unsigned int)(v3 - 1) + 8;
while ( *v4 )
{
if ( ++v4 == (char **)v5 )
goto LABEL_3;
}
v6 = strlen(a2);
v7 = (char *)malloc(v6 + 1);
*v4 = v7;
strcpy(v7, a2);
result = *v4;
}
return result;
}

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

result = func0(a1, a2);
if ( !result )
{
while ( 1 )
{
v3 = *(_DWORD *)(a1 + 8);
if ( v3 > 0 )
break;
LABEL_3:
func1(a1);
}
v4 = *(char ***)a1;
v5 = *(_QWORD *)a1 + 8LL * (unsigned int)(v3 - 1) + 8;
while ( *v4 )
{
if ( ++v4 == (char **)v5 )
goto LABEL_3;
}
v6 = strlen(a2);
v7 = (char *)malloc(v6 + 1);
*v4 = v7;
strcpy(v7, a2);
result = *v4;
}
return result;
}

original_code:
char *add_string(Sst sst, char *str)
{
    char *str_ptr = lookup_string(sst, str);
    if (str_ptr == ((void *)0))
    {
        while (1)
        {
            int i;
            for (i = 0; i < sst->size; i++)
            {
                if (*(sst->table_ptr + i) == ((void *)0))
                {
                    *(sst->table_ptr + i) = malloc(strlen(str) + 1);
                    strcpy(*(sst->table_ptr + i), str);
                    return *(sst->table_ptr + i);
                }
            }
            expand_sst(sst);
        }
    } else
        return str_ptr;
}

canonical_original_code:
char *add_string(struct simple_string_table_struct *sst, char *str)
{
    char *str_ptr = lookup_string(sst, str);
    if (str_ptr == ((void *)0))
    {
        while (1)
        {
            int i;
            for (i = 0; i < sst->size; i++)
            {
                if (*(sst->table_ptr + i) == ((void *)0))
                {
                    *(sst->table_ptr + i) = malloc(strlen(str) + 1);
                    strcpy(*(sst->table_ptr + i), str);
                    return *(sst->table_ptr + i);
                }
            }
            expand_sst(sst);
        }
    } else
        return str_ptr;
}


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

if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
while ( 1 )
{
v2 = (unsigned int)v1;
v3 = *(const char **)(*(_QWORD *)a1 + 8 * v1);
if ( !v3 )
break;
++v1;
printf("%d: %s\n", v2, v3);
if ( *(_DWORD *)(a1 + 8) <= (int)v1 )
return putchar(10);
}
++v1;
printf("%d: NULL\n", v2);
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
return putchar(10);
}

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

if ( *(int *)(a1 + 8) > 0 )
{
v1 = 0LL;
do
{
while ( 1 )
{
v2 = (unsigned int)v1;
v3 = *(const char **)(*(_QWORD *)a1 + 8 * v1);
if ( !v3 )
break;
++v1;
printf("%d: %s\n", v2, v3);
if ( *(_DWORD *)(a1 + 8) <= (int)v1 )
return putchar(10);
}
++v1;
printf("%d: NULL\n", v2);
}
while ( *(_DWORD *)(a1 + 8) > (int)v1 );
}
return putchar(10);
}

original_code:
void print_sst(Sst sst)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        if (*(sst->table_ptr + i) == ((void *)0))
            printf("%d: NULL\n", i);
        else
            printf("%d: %s\n", i, *(sst->table_ptr + i));
    }
    printf("\n");
}

canonical_original_code:
void print_sst(struct simple_string_table_struct *sst)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        if (*(sst->table_ptr + i) == ((void *)0))
            printf("%d: NULL\n", i);
        else
            printf("%d: %s\n", i, *(sst->table_ptr + i));
    }
    printf("\n");
}


decompiled_code:
void __fastcall destroy_sst(void *ptr)
{
_QWORD *v2; // r8
__int64 v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
if ( *((int *)ptr + 2) > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3];
if ( v4 )
{
free(v4);
v2 = *(_QWORD **)ptr;
}
++v3;
}
while ( *((_DWORD *)ptr + 2) > (int)v3 );
}
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v2; // r8
__int64 v3; // rbx
void *v4; // rdi

v2 = *(_QWORD **)ptr;
if ( *((int *)ptr + 2) > 0 )
{
v3 = 0LL;
do
{
v4 = (void *)v2[v3];
if ( v4 )
{
free(v4);
v2 = *(_QWORD **)ptr;
}
++v3;
}
while ( *((_DWORD *)ptr + 2) > (int)v3 );
}
free(v2);
free(ptr);
}

original_code:
void destroy_sst(Sst sst)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        if (*(sst->table_ptr + i) != ((void *)0))
            free(*(sst->table_ptr + i));
    }
    free(sst->table_ptr);
    free(sst);
}

canonical_original_code:
void destroy_sst(struct simple_string_table_struct *sst)
{
    int i;
    for (i = 0; i < sst->size; i++)
    {
        if (*(sst->table_ptr + i) != ((void *)0))
            free(*(sst->table_ptr + i));
    }
    free(sst->table_ptr);
    free(sst);
}


canonical_decompiled_code:
_BOOL8 __fastcall func4(const char **a1, const char *a2)
{
return strcmp(*a1, a2) == 0;
}


decompiled_code:
int __fastcall print_symnode(const char **a1)
{
int result; // eax

if ( a1 )
result = printf(
"Node: %s, type: %s, vartype: %s, addr: %d, addr type: %s, ptr: %p \n",
*a1,
node_type_string[*((unsigned int *)a1 + 7)],
(&var_type_string)[*((unsigned int *)a1 + 4)],
*((unsigned int *)a1 + 5),
mem_addr_type_string[*((unsigned int *)a1 + 6)],
a1);
else
result = puts("Node is null");
return result;
}

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

if ( a1 )
result = printf(
"Node: %s, type: %s, vartype: %s, addr: %d, addr type: %s, ptr: %p \n",
*a1,
node_type_string[*((unsigned int *)a1 + 7)],
(&var_type_string)[*((unsigned int *)a1 + 4)],
*((unsigned int *)a1 + 5),
mem_addr_type_string[*((unsigned int *)a1 + 6)],
a1);
else
result = puts("Node is null");
return result;
}

original_code:
void print_symnode(symnode node)
{
    if (node) {
      printf("Node: %s, type: %s, vartype: %s, addr: %d, addr type: %s, ptr: %p \n", node->name,
      node_type_string[node->node_type],
      var_type_string[node->var_type],
      node->var_addr,
      mem_addr_type_string[node->mem_addr_type],
            node
            );
    } else {
        printf("Node is null\n");
    }
}

canonical_original_code:
void print_symnode(struct symnode *node)
{
    if (node) {
      printf("Node: %s, type: %s, vartype: %s, addr: %d, addr type: %s, ptr: %p \n", node->name,
      node_type_string[node->node_type],
      var_type_string[node->var_type],
      node->var_addr,
      mem_addr_type_string[node->mem_addr_type],
            node
            );
    } else {
        printf("Node is null\n");
    }
}


decompiled_code:
int __fastcall print_symhashtable(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 i; // rbx

LODWORD(v1) = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v1 = *(_QWORD *)(a1 + 8);
for ( i = *(_QWORD *)(v1 + 8 * v2); i; i = *(_QWORD *)(i + 8) )
LODWORD(v1) = print_symnode((const char **)i);
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return v1;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 i; // rbx

LODWORD(v1) = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
{
v1 = *(_QWORD *)(a1 + 8);
for ( i = *(_QWORD *)(v1 + 8 * v2); i; i = *(_QWORD *)(i + 8) )
LODWORD(v1) = func12((const char **)i);
++v2;
}
while ( *(_DWORD *)a1 > (int)v2 );
}
return v1;
}

original_code:
void print_symhashtable(symhashtable hashtable)
{
  int i;
  for (i = 0; i < hashtable->size; i++) {
    symnode node;
    for (node = hashtable->table[i]; node != ((void *)0); node = node->next) {
      print_symnode(node);
    }
  }
}

canonical_original_code:
void print_symhashtable(struct symhashtable *hashtable)
{
  int i;
  for (i = 0; i < hashtable->size; i++) {
    struct symnode *node;
    for (node = hashtable->table[i]; node != ((void *)0); node = node->next) {
      print_symnode(node);
    }
  }
}


decompiled_code:
int __fastcall print_symboltable(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
{
printf("Table at level %d contains:\n", *(unsigned int *)(i + 24));
result = print_symhashtable(i);
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 *a1)
{
__int64 i; // rbx
int result; // eax

for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
{
printf("Table at level %d contains:\n", *(unsigned int *)(i + 24));
result = func13(i);
}
return result;
}

original_code:
void print_symboltable(symboltable symtab)
{
  symhashtable table;
  for (table = symtab->inner_scope; table != ((void *)0); table = table->outer_scope) {
    printf("Table at level %d contains:\n", table->level);
    print_symhashtable(table);
  }
}

canonical_original_code:
void print_symboltable(struct symboltable *symtab)
{
  struct symhashtable *table;
  for (table = symtab->inner_scope; table != ((void *)0); table = table->outer_scope) {
    printf("Table at level %d contains:\n", table->level);
    print_symhashtable(table);
  }
}