decompiled_code:
__int64 __fastcall camera_process_image(__int64 a1)
{
manip_decompress(320LL, 240LL, a1, uncompressed_src);
bayer2rgb24(rgb, uncompressed_src, 320LL, 240LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
manip_decompress(320LL, 240LL, a1, uncompressed_src);
bayer2rgb24(rgb, uncompressed_src, 320LL, 240LL);
return 1LL;
}

original_code:
gboolean camera_process_image(unsigned char *p)
{
 unsigned char *src = (unsigned char *) p;
 unsigned char *reader = src;
 manip_decompress(320, 240, src, uncompressed_src);
 reader = uncompressed_src;
 bayer2rgb24(rgb ,reader ,320, 240);
 return (!(0));
}

canonical_original_code:
int camera_process_image(unsigned char *p)
{
 unsigned char *src = (unsigned char *) p;
 unsigned char *reader = src;
 manip_decompress(320, 240, src, uncompressed_src);
 reader = uncompressed_src;
 bayer2rgb24(rgb ,reader ,320, 240);
 return (!(0));
}

variable_types:
p
unsigned char *

variable_types:
src
unsigned char *

variable_types:
reader
unsigned char *


repo: ElFeesho/OldCProjects

decompiled_code:
__int64 camera_stop_capturing()
{
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 1;
if ( (unsigned int)xioctl(fd, 1074026003, (__int64)v1) == -1 )
errno_exit("VIDIOC_STREAMOFF");
return 1LL;
}

canonical_decompiled_code:
__int64 func5()
{
int v1[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1[0] = 1;
if ( (unsigned int)func0(fd, 1074026003, (__int64)v1) == -1 )
func1("VIDIOC_STREAMOFF");
return 1LL;
}

original_code:
gboolean camera_stop_capturing(void)
{
  capturing = (0);
  enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  if (-1 == xioctl (fd, (((1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((19)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &type))
    errno_exit ("VIDIOC_STREAMOFF");
  return (!(0));
}

canonical_original_code:
int camera_stop_capturing()
{
  capturing = (0);
  enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  if (-1 == xioctl (fd, (((1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((19)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &type))
    errno_exit ("VIDIOC_STREAMOFF");
  return (!(0));
}

variable_types: enum v4l2_buf_type { V4L2_BUF_TYPE_VIDEO_CAPTURE=1, V4L2_BUF_TYPE_VIDEO_OUTPUT=2, V4L2_BUF_TYPE_VIDEO_OVERLAY=3, V4L2_BUF_TYPE_VBI_CAPTURE=4, V4L2_BUF_TYPE_VBI_OUTPUT=5, V4L2_BUF_TYPE_SLICED_VBI_CAPTURE=6, V4L2_BUF_TYPE_SLICED_VBI_OUTPUT=7, V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY=8, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE=9, V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE=10, V4L2_BUF_TYPE_SDR_CAPTURE=11, V4L2_BUF_TYPE_SDR_OUTPUT=12, V4L2_BUF_TYPE_META_CAPTURE=13, V4L2_BUF_TYPE_PRIVATE=128 }

return_type: int


decompiled_code:
int camera_shutdown()
{
__int64 v0; // rbp
__int64 v1; // rbx
int result; // eax

if ( n_buffers )
{
v0 = 16 * ((unsigned int)(n_buffers - 1) + 1LL);
v1 = 0LL;
do
{
if ( munmap(*(void **)((char *)buffers + v1), *(_QWORD *)((char *)buffers + v1 + 8)) == -1 )
errno_exit("munmap");
v1 += 16LL;
}
while ( v1 != v0 );
}
free(buffers);
free(rgb);
free(uncompressed_src);
result = close(fd);
if ( result == -1 )
errno_exit("close");
fd = -1;
return result;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rbp
__int64 v1; // rbx
int result; // eax

if ( n_buffers )
{
v0 = 16 * ((unsigned int)(n_buffers - 1) + 1LL);
v1 = 0LL;
do
{
if ( munmap(*(void **)((char *)buffers + v1), *(_QWORD *)((char *)buffers + v1 + 8)) == -1 )
func1("munmap");
v1 += 16LL;
}
while ( v1 != v0 );
}
free(buffers);
free(rgb);
free(uncompressed_src);
result = close(fd);
if ( result == -1 )
func1("close");
fd = -1;
return result;
}

original_code:
void camera_shutdown()
{
  unsigned int i;
  for (i = 0; i < n_buffers; ++i)
    if (-1 == munmap (buffers[i].start, buffers[i].length))
      errno_exit ("munmap");
  free (buffers);
  free(rgb);
  free(uncompressed_src);
  if (-1 == close (fd))
    errno_exit ("close");
  fd = -1;
}

variable_types:
i
unsigned int

return_type: void


decompiled_code:
__int64 __fastcall camera_set_gain(float a1)
{
if ( !max_0 )
max_0 = controls_get_max_gain((unsigned int)fd);
controls_set_gain((unsigned int)fd, (unsigned __int8)(int)(float)((float)max_0 * a1));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(float a1)
{
if ( !max_0 )
max_0 = controls_get_max_gain((unsigned int)fd);
controls_set_gain((unsigned int)fd, (unsigned __int8)(int)(float)((float)max_0 * a1));
return 1LL;
}

original_code:
gboolean camera_set_gain(float v)
{
 static int max = 0;
 if(max == 0)
  max = controls_get_max_gain(fd);
  gain = v;
  unsigned char val = (unsigned char)(max*v);
  controls_set_gain(fd, val);
  return (!(0));
}

canonical_original_code:
int camera_set_gain(float v)
{
 static int max = 0;
 if(max == 0)
  max = controls_get_max_gain(fd);
  gain = v;
  unsigned char val = (unsigned char)(max*v);
  controls_set_gain(fd, val);
  return (!(0));
}

variable_types: v float

variable_types: max int

variable_types:
val
unsigned char


xioctl

decompiled_code:
__int64 __fastcall xioctl(int fd, int a2, __int64 a3)
{
unsigned int v4; // ebx

do
v4 = ioctl(fd, a2, a3);
while ( v4 == -1 && *_errno_location() == 4 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, int a2, __int64 a3)
{
unsigned int v4; // ebx

do
v4 = ioctl(fd, a2, a3);
while ( v4 == -1 && *_errno_location() == 4 );
return v4;
}

original_code:
static int xioctl
(
  int fd,
  int request,
  void *arg
)
{
  int r;
  do
  {
    r = ioctl (fd, request, arg);
  } while (-1 == r && 4 == (*__errno_location ()));
  return r;
}

canonical_original_code:
static int xioctl(int fd, int request, void *arg)
{
  int r;
  do
  {
    r = ioctl (fd, request, arg);
  } while (-1 == r && 4 == (*__errno_location ()));
  return r;
}

variable_types: fd int

variable_types: request int

variable_types:
arg
void *

variable_types: r int


decompiled_code:
__int64 gfx_cls()
{
__int64 v0; // rcx
__int64 result; // rax

SDL_FillRect(screen, 0LL, 0LL);
v0 = screenBuffer;
*(_QWORD *)screenBuffer = 0LL;
*(_QWORD *)(v0 + 2040) = 0LL;
result = 0LL;
memset(
(void *)((v0 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 2048) >> 3));
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rcx
__int64 result; // rax

SDL_FillRect(screen, 0LL, 0LL);
v0 = screenBuffer;
*(_QWORD *)screenBuffer = 0LL;
*(_QWORD *)(v0 + 2040) = 0LL;
result = 0LL;
memset(
(void *)((v0 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)v0 - (((_DWORD)v0 + 8) & 0xFFFFFFF8) + 2048) >> 3));
return result;
}

original_code:
void gfx_cls()
{
 SDL_FillRect(screen, ((void *)0), 0);
 memset(screenBuffer, 0, 64*32);
}


decompiled_code:
__int64 gfx_init()
{
SDL_Init(32LL);
screen = SDL_SetVideoMode(640LL, 320LL, 24LL, 0LL);
screenBuffer = (__int64)malloc(0x800uLL);
return gfx_cls();
}

canonical_decompiled_code:
__int64 func1()
{
SDL_Init(32LL);
screen = SDL_SetVideoMode(640LL, 320LL, 24LL, 0LL);
screenBuffer = (__int64)malloc(0x800uLL);
return func0();
}

original_code:
void gfx_init()
{
 SDL_Init(0x00000020);
 screen = SDL_SetVideoMode(640, 320, 24, 0x00000000);
 screenBuffer = malloc(64*32);
 gfx_cls();
}


decompiled_code:
__int64 __fastcall gfx_get_pixel(int a1, int a2)
{
return *(unsigned __int8 *)(screenBuffer + a1 + (a2 << 6));
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
return *(unsigned __int8 *)(screenBuffer + a1 + (a2 << 6));
}

original_code:
int gfx_get_pixel(int x, int y)
{
 return screenBuffer[y*64 + x];
}

variable_types: x int

variable_types: y int


decompiled_code:
_BOOL8 __fastcall gfx_draw_pixel_on(char a1, char a2)
{
int v2; // eax

v2 = gfx_get_pixel(a1 & 0x3F, a2 & 0x1F);
*(_BYTE *)(screenBuffer + (a1 & 0x3F) + ((a2 & 0x1F) << 6)) = v2 == 0;
return v2 != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char a1, char a2)
{
int v2; // eax

v2 = func2(a1 & 0x3F, a2 & 0x1F);
*(_BYTE *)(screenBuffer + (a1 & 0x3F) + ((a2 & 0x1F) << 6)) = v2 == 0;
return v2 != 0;
}

original_code:
int gfx_draw_pixel_on(int x, int y)
{
 int colour = 1;
 x &= 63;
 y &= 31;
 if(gfx_get_pixel(x, y))
 {
  colour = 0;
 }
 screenBuffer[y*64 + x] = colour;
 return colour != 1;
}

variable_types: colour int


decompiled_code:
__int64 __fastcall gfx_draw(char a1, int a2, unsigned __int8 *a3, int a4)
{
int v5; // er13
unsigned int v6; // er14
int i; // ebx
unsigned __int8 v8; // bp
int v10; // [rsp+4h] [rbp-34h]

if ( a4 <= 0 )
return 0;
v5 = a2;
v10 = a4 + a2;
v6 = 0;
do
{
v8 = *a3;
for ( i = 7; i != -1; --i )
{
if ( (v8 & (1 << i)) != 0 )
v6 |= gfx_draw_pixel_on(a1 + 7 - i, v5);
}
++a3;
++v5;
}
while ( v5 != v10 );
return v6;
}

original_code:
int gfx_draw(int x, int y, unsigned char *mem, int count)
{
 int shouldFlip = 0;
 for(int j = 0; j < count; j++)
 {
  unsigned char byte = mem[j];
  for(int i = 0; i < 8; i++)
  {
   int pixelOn = byte & (1 << (8-(i+1)));
   if(pixelOn)
   {
    shouldFlip |= gfx_draw_pixel_on(x+i, y + j);
   }
  }
 }
 return shouldFlip;
}

variable_types:
mem
unsigned char *

variable_types: count int

variable_types: shouldFlip int

variable_types: j int

variable_types:
byte
unsigned char

variable_types: i int

variable_types: pixelOn int


original_code:
void gfx_flip()
{
 SDL_Rect brush = { 0, 0, 10, 10 };
 for(int y = 0; y < 32; y++)
 {
  for(int x = 0; x < 64; x++)
  {
   brush.x = x*10;
   brush.y = y*10;
   SDL_FillRect(screen, &brush, screenBuffer[y*64 + x] * 0xffffffff);
  }
 }
 SDL_Flip(screen);
}

canonical_original_code:
void gfx_flip()
{
 struct SDL_Rect brush = { 0, 0, 10, 10 };
 for(int y = 0; y < 32; y++)
 {
  for(int x = 0; x < 64; x++)
  {
   brush.x = x*10;
   brush.y = y*10;
   SDL_FillRect(screen, &brush, screenBuffer[y*64 + x] * 0xffffffff);
  }
 }
 SDL_Flip(screen);
}

variable_types: struct SDL_Rect { short x; unsigned short w; }


decompiled_code:
void asm_var_list_clear()
{
variable_list = 0LL;
mem_offset = 0;
}

canonical_decompiled_code:
void func0()
{
variable_list = 0LL;
mem_offset = 0;
}

original_code:
static void asm_var_list_clear()
{
 variable_list = ((void *)0);
 mem_offset = 0;
}


decompiled_code:
__int16 __fastcall asm_lookup_reg(char *s1, _DWORD *a2)
{
__int16 result; // ax

if ( !strcasecmp(s1, "ax") )
return word_526E;
if ( !strcasecmp(s1, "bx") )
return word_526C;
if ( !strcasecmp(s1, "cx") )
return word_526A;
if ( !strcasecmp(s1, "dx") )
return word_5268;
if ( !strcasecmp(s1, "ah") )
return SHIBYTE(word_526E);
if ( !strcasecmp(s1, "bh") )
return SHIBYTE(word_526C);
if ( !strcasecmp(s1, "ch") )
return SHIBYTE(word_526A);
if ( !strcasecmp(s1, "dh") )
return SHIBYTE(word_5268);
if ( !strcasecmp(s1, "al") )
return (unsigned __int8)word_526E;
if ( !strcasecmp(s1, "bl") )
return (unsigned __int8)word_526C;
if ( !strcasecmp(s1, "cl") )
return (unsigned __int8)word_526A;
if ( !strcasecmp(s1, "dl") )
return (unsigned __int8)word_5268;
result = 0;
if ( a2 )
*a2 = 1;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func1(char *s1, _DWORD *a2)
{
__int16 result; // ax

if ( !strcasecmp(s1, "ax") )
return word_526E;
if ( !strcasecmp(s1, "bx") )
return word_526C;
if ( !strcasecmp(s1, "cx") )
return word_526A;
if ( !strcasecmp(s1, "dx") )
return word_5268;
if ( !strcasecmp(s1, "ah") )
return SHIBYTE(word_526E);
if ( !strcasecmp(s1, "bh") )
return SHIBYTE(word_526C);
if ( !strcasecmp(s1, "ch") )
return SHIBYTE(word_526A);
if ( !strcasecmp(s1, "dh") )
return SHIBYTE(word_5268);
if ( !strcasecmp(s1, "al") )
return (unsigned __int8)word_526E;
if ( !strcasecmp(s1, "bl") )
return (unsigned __int8)word_526C;
if ( !strcasecmp(s1, "cl") )
return (unsigned __int8)word_526A;
if ( !strcasecmp(s1, "dl") )
return (unsigned __int8)word_5268;
result = 0;
if ( a2 )
*a2 = 1;
return result;
}

original_code:
static short asm_lookup_reg(char *name, int *not_found)
{
 if(strcasecmp(name,"ax")==0)
 {
  return ax;
 }
 if(strcasecmp(name,"bx")==0)
 {
  return bx;
 }
 if(strcasecmp(name,"cx")==0)
 {
  return cx;
 }
 if(strcasecmp(name,"dx")==0)
 {
  return dx;
 }
 if(strcasecmp(name,"ah")==0)
 {
  return ax>>8;
 }
 if(strcasecmp(name,"bh")==0)
 {
  return bx>>8;
 }
 if(strcasecmp(name,"ch")==0)
 {
  return cx>>8;
 }
 if(strcasecmp(name,"dh")==0)
 {
  return dx>>8;
 }
 if(strcasecmp(name,"al")==0)
 {
  return ax&0xff;
 }
 if(strcasecmp(name,"bl")==0)
 {
  return bx&0xff;
 }
 if(strcasecmp(name,"cl")==0)
 {
  return cx&0xff;
 }
 if(strcasecmp(name,"dl")==0)
 {
  return dx&0xff;
 }
 if(not_found)
  *not_found = 1;
 return 0;
}

variable_types:
name
char *

return_type: short


decompiled_code:
__int64 __fastcall asm_convert_number(char *nptr, _DWORD *a2)
{
size_t v2; // rax
char v3; // bp
int v4; // er12
unsigned int v5; // ebp
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = strlen(nptr);
printf("End char is %c\n", (unsigned int)nptr[v2 - 1]);
v3 = nptr[strlen(nptr) - 1];
if ( isalpha(v3) )
{
if ( v3 == 98 )
{
v4 = 2;
}
else if ( v3 > 98 )
{
v4 = 10;
if ( v3 == 104 )
v4 = 16;
}
else
{
v4 = 2;
if ( v3 != 66 )
{
v4 = 10;
if ( v3 == 72 )
v4 = 16;
}
}
printf("Converting: %s to a number\n", nptr);
nptr[strlen(nptr)] = 0;
v5 = strtol(nptr, &endptr, v4);
if ( endptr == nptr )
{
fwrite("Failed parsing number\n", 1uLL, 0x16uLL, stderr);
*a2 = 1;
}
}
else if ( v3 == 36 )
{
*a2 = 1;
v5 = 0;
}
else
{
v5 = atoi(nptr);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *nptr, _DWORD *a2)
{
size_t v2; // rax
char v3; // bp
int v4; // er12
unsigned int v5; // ebp
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v2 = strlen(nptr);
printf("End char is %c\n", (unsigned int)nptr[v2 - 1]);
v3 = nptr[strlen(nptr) - 1];
if ( isalpha(v3) )
{
if ( v3 == 98 )
{
v4 = 2;
}
else if ( v3 > 98 )
{
v4 = 10;
if ( v3 == 104 )
v4 = 16;
}
else
{
v4 = 2;
if ( v3 != 66 )
{
v4 = 10;
if ( v3 == 72 )
v4 = 16;
}
}
printf("Converting: %s to a number\n", nptr);
nptr[strlen(nptr)] = 0;
v5 = strtol(nptr, &endptr, v4);
if ( endptr == nptr )
{
fwrite("Failed parsing number\n", 1uLL, 0x16uLL, stderr);
*a2 = 1;
}
}
else if ( v3 == 36 )
{
*a2 = 1;
v5 = 0;
}
else
{
v5 = atoi(nptr);
}
return v5;
}

original_code:
static short asm_convert_number(char *string, int *not_num)
{
 short return_val;
 printf("End char is %c\n",string[strlen(string)-1]);
 if(isalpha(string[strlen(string)-1]))
 {
  int base = 0;
  switch(string[strlen(string)-1])
  {
   case 'b':
   case 'B':
    base = 2;
    break;
   case 'h':
   case 'H':
    base = 16;
    break;
   default:
    base = 10;
    break;
  }
  printf("Converting: %s to a number\n",string);
  char *endptr;
  string[strlen(string)]='\0';
  return_val = strtol(string,&endptr,base);
  if(endptr==string)
  {
   fprintf(stderr, "Failed parsing number\n");
   *not_num = 1;
  }
 }
 else
 {
  if(string[strlen(string)-1]=='$')
  {
   *not_num = 1;
   return 0;
  }
  return_val = atoi(string);
 }
 return return_val;
}

variable_types:
string
char *

variable_types: base int

variable_types:
endptr
char *


decompiled_code:
void *__fastcall memory_add_var(char a1, __int64 a2, unsigned __int16 a3, const void *a4)
{
__int64 v6; // rbp
int v7; // er13
char *v8; // rdi
void *result; // rax
int v10; // edx
__int64 v11; // rax
int v12; // ebp
char *v13; // rdi

if ( variable_list )
{
v6 = (int)g_malloc0(8LL);
*(_QWORD *)v6 = (int)g_strdup(a2);
*(_BYTE *)(v6 + 8) = a1;
*(_WORD *)(v6 + 10) = a3;
v7 = mem_offset;
v8 = (char *)&memory + (unsigned int)mem_offset;
*(_QWORD *)(v6 + 16) = v8;
*(_DWORD *)(v6 + 24) = v7;
*(_QWORD *)(v6 + 32) = variable_list;
variable_list = v6;
result = memcpy(v8, a4, a3);
mem_offset = v7 + a3;
}
else
{
variable_list = (int)g_malloc0(8LL);
v10 = g_strdup(a2);
v11 = variable_list;
*(_QWORD *)variable_list = v10;
*(_BYTE *)(v11 + 8) = a1;
*(_WORD *)(v11 + 10) = a3;
v12 = mem_offset;
v13 = (char *)&memory + (unsigned int)mem_offset;
*(_QWORD *)(v11 + 16) = v13;
*(_DWORD *)(v11 + 24) = v12;
*(_QWORD *)(v11 + 32) = 0LL;
result = memcpy(v13, a4, a3);
mem_offset = v12 + a3;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(char a1, __int64 a2, unsigned __int16 a3, const void *a4)
{
__int64 v6; // rbp
int v7; // er13
char *v8; // rdi
void *result; // rax
int v10; // edx
__int64 v11; // rax
int v12; // ebp
char *v13; // rdi

if ( variable_list )
{
v6 = (int)g_malloc0(8LL);
*(_QWORD *)v6 = (int)g_strdup(a2);
*(_BYTE *)(v6 + 8) = a1;
*(_WORD *)(v6 + 10) = a3;
v7 = mem_offset;
v8 = (char *)&memory + (unsigned int)mem_offset;
*(_QWORD *)(v6 + 16) = v8;
*(_DWORD *)(v6 + 24) = v7;
*(_QWORD *)(v6 + 32) = variable_list;
variable_list = v6;
result = memcpy(v8, a4, a3);
mem_offset = v7 + a3;
}
else
{
variable_list = (int)g_malloc0(8LL);
v10 = g_strdup(a2);
v11 = variable_list;
*(_QWORD *)variable_list = v10;
*(_BYTE *)(v11 + 8) = a1;
*(_WORD *)(v11 + 10) = a3;
v12 = mem_offset;
v13 = (char *)&memory + (unsigned int)mem_offset;
*(_QWORD *)(v11 + 16) = v13;
*(_DWORD *)(v11 + 24) = v12;
*(_QWORD *)(v11 + 32) = 0LL;
result = memcpy(v13, a4, a3);
mem_offset = v12 + a3;
}
return result;
}

original_code:
static void memory_add_var(char type, char *name, unsigned short size, void *data)
{
 if(variable_list == ((void *)0))
 {
  variable_list = (asm_var*)g_malloc0(sizeof(variable_list));
  variable_list->name = (char*)g_strdup(name);
  variable_list->type = type;
  variable_list->size = size;
  variable_list->ptr = (void*)(memory+mem_offset);
  variable_list->sptr = mem_offset;
  variable_list->next = 0;
  memcpy(memory+mem_offset,data,size);
  mem_offset+=size;
 }
 else
 {
  asm_var *tmp = (asm_var*)g_malloc0(sizeof(variable_list));
  tmp->name = (char*)g_strdup(name);
  tmp->type = type;
  tmp->size = size;
  tmp->ptr = (void*)(memory+mem_offset);
  tmp->sptr = mem_offset;
  tmp->next = variable_list;
  variable_list = tmp;
  memcpy(memory+mem_offset,data,size);
  mem_offset+=size;
 }
}

canonical_original_code:
static void memory_add_var(char type, char *name, unsigned short size, void *data)
{
 if(variable_list == ((void *)0))
 {
  variable_list = (struct asm_var *)g_malloc0(sizeof(variable_list));
  variable_list->name = (char *)g_strdup(name);
  variable_list->type = type;
  variable_list->size = size;
  variable_list->ptr = (void *)(memory+mem_offset);
  variable_list->sptr = mem_offset;
  variable_list->next = 0;
  memcpy(memory+mem_offset,data,size);
  mem_offset+=size;
 }
 else
 {
  struct asm_var *tmp = (asm_var*)g_malloc0(sizeof(variable_list));
  tmp->name = (char *)g_strdup(name);
  tmp->type = type;
  tmp->size = size;
  tmp->ptr = (void *)(memory+mem_offset);
  tmp->sptr = mem_offset;
  tmp->next = variable_list;
  variable_list = tmp;
  memcpy(memory+mem_offset,data,size);
  mem_offset+=size;
 }
}

variable_types: type char

variable_types:
size
unsigned short

variable_types:
data
void *

variable_types: struct asm_var { char *name; char type; unsigned short size; void *ptr; int sptr; void *next; } *


decompiled_code:
__int64 __fastcall asm_find_label(char *s2)
{
__int64 i; // rbx
unsigned int v2; // er12
size_t v3; // rax

if ( prog_length )
{
for ( i = 0LL; prog_length > (unsigned int)i; ++i )
{
v2 = i;
printf("%s == %s?\n", *((const char **)prog + i), s2);
v3 = strlen(s2);
if ( !strncmp(*((const char **)prog + i), s2, v3) )
{
puts("found the label!");
if ( *(_BYTE *)(*((_QWORD *)prog + i) + strlen(s2)) == 58 )
return v2;
puts("Didn't find the semi-colon :(");
}
}
}
puts("Couldn't find loop!");
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
__int64 i; // rbx
unsigned int v2; // er12
size_t v3; // rax

if ( prog_length )
{
for ( i = 0LL; prog_length > (unsigned int)i; ++i )
{
v2 = i;
printf("%s == %s?\n", *((const char **)prog + i), s2);
v3 = strlen(s2);
if ( !strncmp(*((const char **)prog + i), s2, v3) )
{
puts("found the label!");
if ( *(_BYTE *)(*((_QWORD *)prog + i) + strlen(s2)) == 58 )
return v2;
puts("Didn't find the semi-colon :(");
}
}
}
puts("Couldn't find loop!");
return 1;
}

original_code:
static unsigned int asm_find_label(char *label)
{
 int i = 0;
 for(i = 0;i<prog_length;i++)
 {
  printf("%s == %s?\n",prog[i], label);
  if(strncmp(prog[i],label,strlen(label)) == 0)
  {
   printf("found the label!\n");
   if(prog[i][strlen(label)]==':')
   {
    return i;
   }
   printf("Didn't find the semi-colon :(\n");
  }
 }
 printf("Couldn't find loop!\n");
 return 1;
}

variable_types:
label
char *

return_type: unsigned int


decompiled_code:
__int64 asm_get_var_list()
{
return variable_list;
}

canonical_decompiled_code:
__int64 func7()
{
return variable_list;
}

original_code:
asm_var *asm_get_var_list(void)
{
 return variable_list;
}

canonical_original_code:
struct asm_var *asm_get_var_list()
{
 return variable_list;
}

return_type: struct asm_var { char *name; char type; unsigned short size; void *ptr; int sptr; void *next; } *


original_code:
void asm_reset_vm(void)
{
 ax = 0;
 bx = 0;
 cx = 0;
 dx = 0;
 di = 0;
 bp = 0;
 si = 0;
 sp = 0xfffe;
 pc = 0;
 gui_update();
}

canonical_original_code:
void asm_reset_vm()
{
 ax = 0;
 bx = 0;
 cx = 0;
 dx = 0;
 di = 0;
 bp = 0;
 si = 0;
 sp = 0xfffe;
 pc = 0;
 gui_update();
}


decompiled_code:
void __fastcall asm_set_prog(void *a1, unsigned int a2)
{
void *v2; // r14
void **v3; // rbx
void **v4; // rbp
__int64 v5; // rbp
const char **v6; // r13
const char *v7; // rbx
size_t v8; // r14
const char *v9; // r13
size_t v10; // rax
const char *v11; // r13
size_t v12; // r14
size_t v13; // rax
char *v14; // r14
size_t v15; // rax
__int16 v16; // [rsp+Ah] [rbp-2Eh] BYREF
int v17[11]; // [rsp+Ch] [rbp-2Ch] BYREF

memset(&memory, 48, 0x4000uLL);
asm_var_list_clear();
v2 = prog;
if ( prog )
{
if ( prog_length )
{
v3 = (void **)prog;
v4 = (void **)((char *)prog + 8 * (unsigned int)(prog_length - 1) + 8);
do
free(*v3++);
while ( v3 != v4 );
}
free(v2);
}
prog = a1;
prog_length = a2;
if ( a2 )
{
v5 = 0LL;
do
{
printf("Examining %s\n", *(const char **)((char *)prog + v5));
v6 = (const char **)((char *)prog + v5);
v7 = (const char *)asm_get_operand(*(char **)((char *)prog + v5));
if ( !strcmp(v7, "add")
|| !strcmp(v7, "sub")
|| !strcmp(v7, "inc")
|| !strcmp(v7, "dec")
|| !strcmp(v7, "mul")
|| !strcmp(v7, "div")
|| !strcmp(v7, "mov")
|| !strcmp(v7, "jmp")
|| !strcmp(v7, "hlt") )
{
printf("Op1: %s\n", v7);
}
else
{
v8 = strlen(v7);
v9 = *v6;
if ( v8 == strlen(v9) )
{
printf("Found a label? %s\n", v9);
}
else
{
printf("Found a possible variable :O! %s\n", v7);
v10 = strlen(v7);
v11 = (const char *)asm_get_operand((char *)(*(_QWORD *)((char *)prog + v5) + v10 + 1));
printf("Type: %s\n", v11);
v12 = strlen(v7);
v13 = strlen(v11);
v14 = (char *)asm_get_operand((char *)(*(_QWORD *)((char *)prog + v5) + v12 + v13 + 1));
printf("Value: %s\n", v14);
v17[0] = 0;
if ( !strcasecmp(v11, "db") )
{
LOBYTE(v16) = 0;
LOBYTE(v16) = asm_convert_number(v14, v17);
printf("BVALUE: %d and NOTNUM: %d\n", (unsigned int)(char)v16, (unsigned int)v17[0]);
if ( v17[0] )
{
puts("Adding string");
v15 = strlen(v14);
if ( v14[v15 - 1] == 36 )
memory_add_var(0, (__int64)v7, v15 + 1, v14);
else
fwrite("8086 spec doesn't allow non dollar terminated strings!\n", 1uLL, 0x37uLL, stderr);
}
else
{
puts("Adding byte");
memory_add_var(0, (__int64)v7, 1u, &v16);
}
}
if ( !strcasecmp(v11, "dw") )
{
v16 = 0;
v16 = asm_convert_number(v14, v17);
if ( v17[0] )
fwrite("Unrecognized dw number\n", 1uLL, 0x17uLL, stderr);
memory_add_var(1, (__int64)v7, 2u, &v16);
}
}
}
v5 += 8LL;
}
while ( 8LL * a2 != v5 );
}
}

canonical_decompiled_code:
void __fastcall func9(void *a1, unsigned int a2)
{
void *v2; // r14
void **v3; // rbx
void **v4; // rbp
__int64 v5; // rbp
const char **v6; // r13
const char *v7; // rbx
size_t v8; // r14
const char *v9; // r13
size_t v10; // rax
const char *v11; // r13
size_t v12; // r14
size_t v13; // rax
char *v14; // r14
size_t v15; // rax
__int16 v16; // [rsp+Ah] [rbp-2Eh] BYREF
int v17[11]; // [rsp+Ch] [rbp-2Ch] BYREF

memset(&memory, 48, 0x4000uLL);
func0();
v2 = prog;
if ( prog )
{
if ( prog_length )
{
v3 = (void **)prog;
v4 = (void **)((char *)prog + 8 * (unsigned int)(prog_length - 1) + 8);
do
free(*v3++);
while ( v3 != v4 );
}
free(v2);
}
prog = a1;
prog_length = a2;
if ( a2 )
{
v5 = 0LL;
do
{
printf("Examining %s\n", *(const char **)((char *)prog + v5));
v6 = (const char **)((char *)prog + v5);
v7 = (const char *)func2(*(char **)((char *)prog + v5));
if ( !strcmp(v7, "add")
|| !strcmp(v7, "sub")
|| !strcmp(v7, "inc")
|| !strcmp(v7, "dec")
|| !strcmp(v7, "mul")
|| !strcmp(v7, "div")
|| !strcmp(v7, "mov")
|| !strcmp(v7, "jmp")
|| !strcmp(v7, "hlt") )
{
printf("Op1: %s\n", v7);
}
else
{
v8 = strlen(v7);
v9 = *v6;
if ( v8 == strlen(v9) )
{
printf("Found a label? %s\n", v9);
}
else
{
printf("Found a possible variable :O! %s\n", v7);
v10 = strlen(v7);
v11 = (const char *)func2((char *)(*(_QWORD *)((char *)prog + v5) + v10 + 1));
printf("Type: %s\n", v11);
v12 = strlen(v7);
v13 = strlen(v11);
v14 = (char *)func2((char *)(*(_QWORD *)((char *)prog + v5) + v12 + v13 + 1));
printf("Value: %s\n", v14);
v17[0] = 0;
if ( !strcasecmp(v11, "db") )
{
LOBYTE(v16) = 0;
LOBYTE(v16) = func3(v14, v17);
printf("BVALUE: %d and NOTNUM: %d\n", (unsigned int)(char)v16, (unsigned int)v17[0]);
if ( v17[0] )
{
puts("Adding string");
v15 = strlen(v14);
if ( v14[v15 - 1] == 36 )
func4(0, (__int64)v7, v15 + 1, v14);
else
fwrite("8086 spec doesn't allow non dollar terminated strings!\n", 1uLL, 0x37uLL, stderr);
}
else
{
puts("Adding byte");
func4(0, (__int64)v7, 1u, &v16);
}
}
if ( !strcasecmp(v11, "dw") )
{
v16 = 0;
v16 = func3(v14, v17);
if ( v17[0] )
fwrite("Unrecognized dw number\n", 1uLL, 0x17uLL, stderr);
func4(1, (__int64)v7, 2u, &v16);
}
}
}
v5 += 8LL;
}
while ( 8LL * a2 != v5 );
}
}

original_code:
void asm_set_prog(char **aprog, unsigned int lines)
{
 memset(memory, '0', 16384);
 asm_var_list_clear();
 if(prog!=((void *)0))
 {
  int i;
  for(i = 0;i<prog_length;i++)
  {
   free(prog[i]);
  }
  free(prog);
 }
 prog = aprog;
 prog_length = lines;
 int i;
 for(i = 0;i<lines;i++)
 {
  printf("Examining %s\n",prog[i]);
  char *op1 = asm_get_operand(prog[i]);
  if(strcmp(op1,"add")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"sub")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"inc")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"dec")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"mul")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"div")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"mov")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"jmp")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strcmp(op1,"hlt")==0)
  {
   printf("Op1: %s\n",op1);
  }
  else if(strlen(op1)==strlen(prog[i]))
  {
   printf("Found a label? %s\n",prog[i]);
  }
  else
  {
   printf("Found a possible variable :O! %s\n",op1);
   char *type = asm_get_operand(prog[i]+strlen(op1)+1);
   printf("Type: %s\n",type);
   char *value = asm_get_operand(prog[i]+strlen(op1)+strlen(type)+1);
   printf("Value: %s\n",value);
   int not_num = 0;
   if(strcasecmp(type,"db")==0)
   {
    char bvalue = 0;
    bvalue = asm_convert_number(value, &not_num);
    printf("BVALUE: %d and NOTNUM: %d\n",bvalue, not_num);
    if(not_num)
    {
     printf("Adding string\n");
     if(value[strlen(value)-1]=='$')
      memory_add_var(0, op1, strlen(value)+1, value);
     else
      fprintf(stderr,"8086 spec doesn't allow non dollar terminated strings!\n");
    }
    else
    {
     printf("Adding byte\n");
     memory_add_var(0, op1, 1, &bvalue);
    }
   }
   if(strcasecmp(type,"dw")==0)
   {
    short wvalue = 0;
    wvalue = asm_convert_number(value, &not_num);
    if(not_num)
    {
     fprintf(stderr, "Unrecognized dw number\n");
    }
    memory_add_var(1, op1, 2, &wvalue);
   }
  }
 }
}

variable_types:
aprog
char **

variable_types:
lines
unsigned int

variable_types:
type
char *

variable_types:
value
char *

variable_types: bvalue char

variable_types: wvalue short


decompiled_code:
int __fastcall asm_set_reg(char *s1, __int16 a2)
{
char v2; // bp
__int16 v3; // ax
__int16 v4; // ax
__int16 v5; // ax
int result; // eax
__int16 v7; // si

v2 = a2;
printf("Setting %s to %d\n", s1, (unsigned int)a2);
if ( !strcasecmp(s1, "ax") )
word_526E = a2;
if ( !strcasecmp(s1, "bx") )
word_526C = a2;
if ( !strcasecmp(s1, "cx") )
word_526A = a2;
if ( !strcasecmp(s1, "dx") )
word_5268 = a2;
if ( !strcasecmp(s1, "ah") )
word_526E = (a2 << 8) + (unsigned __int8)word_526E;
if ( !strcasecmp(s1, "bh") )
word_526C = (a2 << 8) + (unsigned __int8)word_526C;
if ( !strcasecmp(s1, "ch") )
word_526A = (a2 << 8) + (unsigned __int8)word_526A;
if ( !strcasecmp(s1, "dh") )
word_5268 = (a2 << 8) + (unsigned __int8)word_5268;
if ( !strcasecmp(s1, "al") )
{
HIBYTE(v3) = HIBYTE(word_526E);
LOBYTE(v3) = 0;
word_526E = (char)a2 + v3;
}
if ( !strcasecmp(s1, "bl") )
{
HIBYTE(v4) = HIBYTE(word_526C);
LOBYTE(v4) = 0;
word_526C = (char)a2 + v4;
}
if ( !strcasecmp(s1, "cl") )
{
HIBYTE(v5) = HIBYTE(word_526A);
LOBYTE(v5) = 0;
word_526A = (char)a2 + v5;
}
result = strcasecmp(s1, "dl");
if ( !result )
{
HIBYTE(v7) = HIBYTE(word_5268);
LOBYTE(v7) = 0;
word_5268 = v7 + v2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(char *s1, __int16 a2)
{
char v2; // bp
__int16 v3; // ax
__int16 v4; // ax
__int16 v5; // ax
int result; // eax
__int16 v7; // si

v2 = a2;
printf("Setting %s to %d\n", s1, (unsigned int)a2);
if ( !strcasecmp(s1, "ax") )
word_526E = a2;
if ( !strcasecmp(s1, "bx") )
word_526C = a2;
if ( !strcasecmp(s1, "cx") )
word_526A = a2;
if ( !strcasecmp(s1, "dx") )
word_5268 = a2;
if ( !strcasecmp(s1, "ah") )
word_526E = (a2 << 8) + (unsigned __int8)word_526E;
if ( !strcasecmp(s1, "bh") )
word_526C = (a2 << 8) + (unsigned __int8)word_526C;
if ( !strcasecmp(s1, "ch") )
word_526A = (a2 << 8) + (unsigned __int8)word_526A;
if ( !strcasecmp(s1, "dh") )
word_5268 = (a2 << 8) + (unsigned __int8)word_5268;
if ( !strcasecmp(s1, "al") )
{
HIBYTE(v3) = HIBYTE(word_526E);
LOBYTE(v3) = 0;
word_526E = (char)a2 + v3;
}
if ( !strcasecmp(s1, "bl") )
{
HIBYTE(v4) = HIBYTE(word_526C);
LOBYTE(v4) = 0;
word_526C = (char)a2 + v4;
}
if ( !strcasecmp(s1, "cl") )
{
HIBYTE(v5) = HIBYTE(word_526A);
LOBYTE(v5) = 0;
word_526A = (char)a2 + v5;
}
result = strcasecmp(s1, "dl");
if ( !result )
{
HIBYTE(v7) = HIBYTE(word_5268);
LOBYTE(v7) = 0;
word_5268 = v7 + v2;
}
return result;
}

original_code:
void asm_set_reg(char *name, short data)
{
 printf("Setting %s to %d\n",name, data);
 if(strcasecmp(name,"ax")==0)
 {
  ax = data;
 }
 if(strcasecmp(name,"bx")==0)
 {
  bx = data;
 }
 if(strcasecmp(name,"cx")==0)
 {
  cx = data;
 }
 if(strcasecmp(name,"dx")==0)
 {
  dx = data;
 }
 if(strcasecmp(name,"ah")==0)
 {
  ax = ax&0x00ff;
  ax += ((char)data)<<8;
 }
 if(strcasecmp(name,"bh")==0)
 {
  bx = bx&0x00ff;
  bx += ((char)data)<<8;
 }
 if(strcasecmp(name,"ch")==0)
 {
  cx = cx&0x00ff;
  cx += ((char)data)<<8;
 }
 if(strcasecmp(name,"dh")==0)
 {
  dx = dx&0x00ff;
  dx += ((char)data)<<8;
 }
 if(strcasecmp(name,"al")==0)
 {
  ax = ax&0xff00;
  ax += ((char)data);
 }
 if(strcasecmp(name,"bl")==0)
 {
  bx = bx&0xff00;
  bx += ((char)data);
 }
 if(strcasecmp(name,"cl")==0)
 {
  cx = cx&0xff00;
  cx += ((char)data);
 }
 if(strcasecmp(name,"dl")==0)
 {
  dx = dx&0xff00;
  dx += ((char)data);
 }
}

variable_types: data short


decompiled_code:
__int64 asm_step()
{
const void **v0; // rbx
char *v1; // rax
__int64 result; // rax
char *v3; // rbp
size_t v4; // rax
char *v5; // r12
__int16 v6; // bx
__int16 v7; // ax
char *v8; // rbp
size_t v9; // rax
char *v10; // r12
__int16 v11; // bx
__int16 v12; // dx
char *v13; // rbx
__int16 v14; // ax
char *v15; // rbx
__int16 v16; // ax
char *v17; // rbp
size_t v18; // rax
char *v19; // r12
__int16 v20; // si
__int16 v21; // bx
char *v22; // rbp
__int16 v23; // bx
__int16 v24; // si
char *v25; // rbp
unsigned __int16 v26; // bx
unsigned __int16 v27; // bp
char *v28; // rax
int v29; // [rsp+8h] [rbp-20h] BYREF
int v30[7]; // [rsp+Ch] [rbp-1Ch] BYREF

gui_update();
v0 = (const void **)((char *)prog + 8 * (unsigned int)pc);
v1 = (char *)*v0;
if ( !memcmp(*v0, "add", 3uLL) )
{
v3 = (char *)asm_get_operand(v1 + 4);
v4 = strlen(v3);
v5 = (char *)asm_get_operand((char *)*v0 + v4 + 4);
v29 = 0;
v30[0] = 0;
v6 = asm_lookup_reg(v3, &v29);
if ( v29 )
{
fwrite("Couldn't find register to add to\n", 1uLL, 0x21uLL, stderr);
}
else
{
v7 = asm_lookup_reg(v5, &v29);
if ( !v29 || (v7 = asm_convert_number(v5, v30), !v30[0]) )
{
asm_set_reg(v3, v6 + v7);
goto LABEL_16;
}
fwrite("Second operand is not a numeric or variable value\n", 1uLL, 0x32uLL, stderr);
}
return 0xFFFFFFFFLL;
}
if ( !memcmp(*v0, "sub", 3uLL) )
{
v8 = (char *)asm_get_operand(v1 + 4);
v9 = strlen(v8);
v10 = (char *)asm_get_operand((char *)*v0 + v9 + 4);
v29 = 0;
v30[0] = 0;
v11 = asm_lookup_reg(v8, &v29);
if ( v29 )
{
fwrite("Couldn't find register to subtract from\n", 1uLL, 0x28uLL, stderr);
}
else
{
v12 = asm_lookup_reg(v10, &v29);
if ( !v29 || (v12 = asm_convert_number(v10, v30), !v30[0]) )
{
asm_set_reg(v8, v11 - v12);
goto LABEL_16;
}
fwrite("Second operand is not a numeric or variable value\n", 1uLL, 0x32uLL, stderr);
}
return 0xFFFFFFFFLL;
}
if ( !memcmp(*v0, "inc", 3uLL) )
{
v13 = (char *)asm_get_operand(v1 + 4);
v30[0] = 0;
v14 = asm_lookup_reg(v13, v30);
if ( v30[0] )
{
fwrite("Failed to find register/variable to increment\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}
asm_set_reg(v13, v14 + 1);
}
else if ( !memcmp(*v0, "dec", 3uLL) )
{
v15 = (char *)asm_get_operand(v1 + 4);
v30[0] = 0;
v16 = asm_lookup_reg(v15, v30);
if ( v30[0] )
{
fwrite("Failed to find register/variable to decrement\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}
asm_set_reg(v15, v16 - 1);
}
else if ( !memcmp(*v0, "mov", 3uLL) )
{
v17 = (char *)asm_get_operand(v1 + 4);
v18 = strlen(v17);
v19 = (char *)asm_get_operand((char *)*v0 + v18 + 4);
v29 = 0;
if ( !isalpha(*v19) || (v21 = asm_lookup_reg(v19, &v29), !isalpha(*v19)) || (v20 = v21, v29) )
{
v30[0] = 0;
v20 = asm_convert_number(v19, v30);
if ( v30[0] )
{
fwrite("Failed to find a value to move into register\n", 1uLL, 0x2DuLL, stderr);
return 0xFFFFFFFFLL;
}
}
asm_set_reg(v17, v20);
}
else if ( !memcmp(*v0, "mul", 3uLL) )
{
v22 = (char *)asm_get_operand(v1 + 4);
v30[0] = 0;
v23 = asm_lookup_reg("al", 0LL);
v24 = asm_lookup_reg(v22, v30);
if ( v30[0] )
{
fwrite("Failed to find register to multiply by\n", 1uLL, 0x27uLL, stderr);
return 0xFFFFFFFFLL;
}
asm_set_reg("ax", v24 * v23);
}
else if ( !memcmp(*v0, "div", 3uLL) )
{
v25 = (char *)asm_get_operand(v1 + 4);
v30[0] = 0;
v26 = asm_lookup_reg("ax", 0LL);
v27 = asm_lookup_reg(v25, v30);
if ( v30[0] )
fwrite("Failed to find register to divide by\n", 1uLL, 0x25uLL, stderr);
asm_set_reg("al", v26 / v27);
asm_set_reg("ah", v26 % v27);
}
else if ( !memcmp(*v0, "jmp", 3uLL) || !memcmp(*v0, "int", 3uLL) )
{
v28 = (char *)asm_get_operand(v1 + 4);
pc = asm_find_label(v28);
}
else if ( !memcmp(*v0, "hlt", 3uLL) )
{
pc = 0;
return 0xFFFFFFFFLL;
}
LABEL_16:
result = (unsigned int)(pc + 1);
pc = result;
if ( (unsigned int)result >= prog_length )
{
puts("Shouldn't of got this far!");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
const void **v0; // rbx
char *v1; // rax
__int64 result; // rax
char *v3; // rbp
size_t v4; // rax
char *v5; // r12
__int16 v6; // bx
__int16 v7; // ax
char *v8; // rbp
size_t v9; // rax
char *v10; // r12
__int16 v11; // bx
__int16 v12; // dx
char *v13; // rbx
__int16 v14; // ax
char *v15; // rbx
__int16 v16; // ax
char *v17; // rbp
size_t v18; // rax
char *v19; // r12
__int16 v20; // si
__int16 v21; // bx
char *v22; // rbp
__int16 v23; // bx
__int16 v24; // si
char *v25; // rbp
unsigned __int16 v26; // bx
unsigned __int16 v27; // bp
char *v28; // rax
int v29; // [rsp+8h] [rbp-20h] BYREF
int v30[7]; // [rsp+Ch] [rbp-1Ch] BYREF

gui_update();
v0 = (const void **)((char *)prog + 8 * (unsigned int)pc);
v1 = (char *)*v0;
if ( !memcmp(*v0, "add", 3uLL) )
{
v3 = (char *)func2(v1 + 4);
v4 = strlen(v3);
v5 = (char *)func2((char *)*v0 + v4 + 4);
v29 = 0;
v30[0] = 0;
v6 = func1(v3, &v29);
if ( v29 )
{
fwrite("Couldn't find register to add to\n", 1uLL, 0x21uLL, stderr);
}
else
{
v7 = func1(v5, &v29);
if ( !v29 || (v7 = func3(v5, v30), !v30[0]) )
{
func10(v3, v6 + v7);
goto LABEL_16;
}
fwrite("Second operand is not a numeric or variable value\n", 1uLL, 0x32uLL, stderr);
}
return 0xFFFFFFFFLL;
}
if ( !memcmp(*v0, "sub", 3uLL) )
{
v8 = (char *)func2(v1 + 4);
v9 = strlen(v8);
v10 = (char *)func2((char *)*v0 + v9 + 4);
v29 = 0;
v30[0] = 0;
v11 = func1(v8, &v29);
if ( v29 )
{
fwrite("Couldn't find register to subtract from\n", 1uLL, 0x28uLL, stderr);
}
else
{
v12 = func1(v10, &v29);
if ( !v29 || (v12 = func3(v10, v30), !v30[0]) )
{
func10(v8, v11 - v12);
goto LABEL_16;
}
fwrite("Second operand is not a numeric or variable value\n", 1uLL, 0x32uLL, stderr);
}
return 0xFFFFFFFFLL;
}
if ( !memcmp(*v0, "inc", 3uLL) )
{
v13 = (char *)func2(v1 + 4);
v30[0] = 0;
v14 = func1(v13, v30);
if ( v30[0] )
{
fwrite("Failed to find register/variable to increment\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}
func10(v13, v14 + 1);
}
else if ( !memcmp(*v0, "dec", 3uLL) )
{
v15 = (char *)func2(v1 + 4);
v30[0] = 0;
v16 = func1(v15, v30);
if ( v30[0] )
{
fwrite("Failed to find register/variable to decrement\n", 1uLL, 0x2EuLL, stderr);
return 0xFFFFFFFFLL;
}
func10(v15, v16 - 1);
}
else if ( !memcmp(*v0, "mov", 3uLL) )
{
v17 = (char *)func2(v1 + 4);
v18 = strlen(v17);
v19 = (char *)func2((char *)*v0 + v18 + 4);
v29 = 0;
if ( !isalpha(*v19) || (v21 = func1(v19, &v29), !isalpha(*v19)) || (v20 = v21, v29) )
{
v30[0] = 0;
v20 = func3(v19, v30);
if ( v30[0] )
{
fwrite("Failed to find a value to move into register\n", 1uLL, 0x2DuLL, stderr);
return 0xFFFFFFFFLL;
}
}
func10(v17, v20);
}
else if ( !memcmp(*v0, "mul", 3uLL) )
{
v22 = (char *)func2(v1 + 4);
v30[0] = 0;
v23 = func1("al", 0LL);
v24 = func1(v22, v30);
if ( v30[0] )
{
fwrite("Failed to find register to multiply by\n", 1uLL, 0x27uLL, stderr);
return 0xFFFFFFFFLL;
}
func10("ax", v24 * v23);
}
else if ( !memcmp(*v0, "div", 3uLL) )
{
v25 = (char *)func2(v1 + 4);
v30[0] = 0;
v26 = func1("ax", 0LL);
v27 = func1(v25, v30);
if ( v30[0] )
fwrite("Failed to find register to divide by\n", 1uLL, 0x25uLL, stderr);
func10("al", v26 / v27);
func10("ah", v26 % v27);
}
else if ( !memcmp(*v0, "jmp", 3uLL) || !memcmp(*v0, "int", 3uLL) )
{
v28 = (char *)func2(v1 + 4);
pc = func5(v28);
}
else if ( !memcmp(*v0, "hlt", 3uLL) )
{
pc = 0;
return 0xFFFFFFFFLL;
}
LABEL_16:
result = (unsigned int)(pc + 1);
pc = result;
if ( (unsigned int)result >= prog_length )
{
puts("Shouldn't of got this far!");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int asm_step()
{
 gui_update();
 if(strncmp(prog[pc],"add",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int not_found = 0, not_number = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Couldn't find register to add to\n");
   return -1;
  }
  short cval2 = asm_lookup_reg(op2, &not_found);
  if(not_found)
  {
   cval2 = asm_convert_number(op2,&not_number);
   if(not_number)
   {
    fprintf(stderr, "Second operand is not a numeric or variable value\n");
    return -1;
   }
  }
  cval += cval2;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"sub",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int not_found = 0, not_number = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Couldn't find register to subtract from\n");
   return -1;
  }
  short cval2 = asm_lookup_reg(op2, &not_found);
  if(not_found)
  {
   cval2 = asm_convert_number(op2,&not_number);
   if(not_number)
   {
    fprintf(stderr, "Second operand is not a numeric or variable value\n");
    return -1;
   }
  }
  cval -= cval2;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"inc",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register/variable to increment\n");
   return -1;
  }
  cval++;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"dec",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  short cval = asm_lookup_reg(op1, &not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register/variable to decrement\n");
   return -1;
  }
  cval--;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"mov",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int data = 0;
  int not_found = 0;
  if(isalpha(op2[0]))
  {
   data = asm_lookup_reg(op2,&not_found);
  }
  if(!isalpha(op2[0])||not_found)
  {
   int not_number = 0;
   data = asm_convert_number(op2, &not_number);
   if(not_number)
   {
    fprintf(stderr, "Failed to find a value to move into register\n");
    return -1;
   }
  }
  asm_set_reg(op1, data);
 }
 else if(strncmp(prog[pc],"mul",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  unsigned short val = asm_lookup_reg("al",((void *)0));
  unsigned short val2 = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register to multiply by\n");
   return -1;
  }
  asm_set_reg("ax",val*val2);
 }
 else if(strncmp(prog[pc],"div",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  unsigned short val = asm_lookup_reg("ax",((void *)0));
  unsigned short val2 = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register to divide by\n");
  }
  asm_set_reg("al",val/val2);
  asm_set_reg("ah",val%val2);
 }
 else if(strncmp(prog[pc],"jmp",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  pc = asm_find_label(op1);
 }
 else if(strncmp(prog[pc],"int",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int int_num = atoi(op1);
  pc = asm_find_label(op1);
 }
 else if(strncmp(prog[pc],"hlt",3)==0)
 {
  pc = 0;
  return -1;
 }
 pc++;
 if(pc>=prog_length)
 {
  printf("Shouldn't of got this far!\n");
  return -1;
 }
 return pc;
}

canonical_original_code:
int asm_step()
{
 gui_update();
 if(strncmp(prog[pc],"add",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int not_found = 0; int not_number = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Couldn't find register to add to\n");
   return -1;
  }
  short cval2 = asm_lookup_reg(op2, &not_found);
  if(not_found)
  {
   cval2 = asm_convert_number(op2,&not_number);
   if(not_number)
   {
    fprintf(stderr, "Second operand is not a numeric or variable value\n");
    return -1;
   }
  }
  cval += cval2;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"sub",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int not_found = 0; int not_number = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Couldn't find register to subtract from\n");
   return -1;
  }
  short cval2 = asm_lookup_reg(op2, &not_found);
  if(not_found)
  {
   cval2 = asm_convert_number(op2,&not_number);
   if(not_number)
   {
    fprintf(stderr, "Second operand is not a numeric or variable value\n");
    return -1;
   }
  }
  cval -= cval2;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"inc",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  short cval = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register/variable to increment\n");
   return -1;
  }
  cval++;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"dec",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  short cval = asm_lookup_reg(op1, &not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register/variable to decrement\n");
   return -1;
  }
  cval--;
  asm_set_reg(op1, cval);
 }
 else if(strncmp(prog[pc],"mov",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  char *op2 = asm_get_operand(((prog[pc])+4)+strlen(op1));
  int data = 0;
  int not_found = 0;
  if(isalpha(op2[0]))
  {
   data = asm_lookup_reg(op2,&not_found);
  }
  if(!isalpha(op2[0])||not_found)
  {
   int not_number = 0;
   data = asm_convert_number(op2, &not_number);
   if(not_number)
   {
    fprintf(stderr, "Failed to find a value to move into register\n");
    return -1;
   }
  }
  asm_set_reg(op1, data);
 }
 else if(strncmp(prog[pc],"mul",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  unsigned short val = asm_lookup_reg("al",((void *)0));
  unsigned short val2 = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register to multiply by\n");
   return -1;
  }
  asm_set_reg("ax",val*val2);
 }
 else if(strncmp(prog[pc],"div",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int not_found = 0;
  unsigned short val = asm_lookup_reg("ax",((void *)0));
  unsigned short val2 = asm_lookup_reg(op1,&not_found);
  if(not_found)
  {
   fprintf(stderr, "Failed to find register to divide by\n");
  }
  asm_set_reg("al",val/val2);
  asm_set_reg("ah",val%val2);
 }
 else if(strncmp(prog[pc],"jmp",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  pc = asm_find_label(op1);
 }
 else if(strncmp(prog[pc],"int",3)==0)
 {
  char *op1 = asm_get_operand(((prog[pc])+4));
  int int_num = atoi(op1);
  pc = asm_find_label(op1);
 }
 else if(strncmp(prog[pc],"hlt",3)==0)
 {
  pc = 0;
  return -1;
 }
 pc++;
 if(pc>=prog_length)
 {
  printf("Shouldn't of got this far!\n");
  return -1;
 }
 return pc;
}

variable_types: cval short

variable_types: data int

variable_types:
val
unsigned short


variable_types: struct wiimote_t { int unid; struct bdaddr_t { unsigned char b[6]; } bdaddr; char bdaddr_str[18]; int out_sock; int in_sock; int state; int leds; int flags; void (*event_cb)(struct wiimote_t *wm); void (*dis_cb)(struct wiimote_t *wm); void (*stat_cb)(struct wiimote_t *wm, int attachment, int speaker, int ir, int led[4], float battery_level); unsigned char handshake_state; struct read_req_t { void (*cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len); unsigned char *buf; unsigned int addr; unsigned short size; unsigned short wait; struct read_req_t *next; } *read_req; struct accel_t { struct vec3b_t { unsigned char x; } cal_zero; struct vec3b_t cal_g; float st_roll; float st_pitch; float st_alpha; } accel_calib; struct expansion_t { enum { EXP_NONE=0, EXP_NUNCHUK=1, EXP_CLASSIC=2 } type; union { struct nunchuk_t { struct accel_t accel_calib; struct joystick_t { struct vec2b_t { unsigned char x; } max; struct vec2b_t min; struct vec2b_t center; float ang; float mag; } js; int *flags; unsigned char btns; unsigned char btns_held; unsigned char btns_released; struct vec3b_t accel; struct orient_t { float roll; float pitch; float yaw; } orient; struct gforce_t { float x; } gforce; } nunchuk; struct classic_ctrl_t { short btns; short btns_held; short btns_released; float r_shoulder; float l_shoulder; struct joystick_t ljs; struct joystick_t rjs; } classic; }; } exp; struct vec3b_t accel; struct orient_t orient; struct gforce_t gforce; struct ir_t { struct ir_dot_t { unsigned char visible; unsigned int x; unsigned int y; short rx; short ry; unsigned char order; unsigned char size; } dot[4]; unsigned char num_dots; enum aspect_t { WIIUSE_ASPECT_4_3=0, WIIUSE_ASPECT_16_9=1 } aspect; enum ir_position_t { WIIUSE_IR_ABOVE=0, WIIUSE_IR_BELOW=1 } pos; unsigned int vres[2]; int offset[2]; int state; int ax; int ay; int x; int y; float distance; float z; } ir; unsigned short btns; unsigned short btns_held; unsigned short btns_released; float orient_threshold; struct wiimote_state_t { float exp_ljs_ang; float exp_rjs_ang; float exp_ljs_mag; float exp_rjs_mag; unsigned char exp_btns; struct orient_t exp_orient; float exp_r_shoulder; float exp_l_shoulder; int ir_ax; int ir_ay; float ir_distance; struct orient_t orient; unsigned short btns; } lstate; unsigned char event[32]; } *

user_defined_types: struct wiimote_t { int unid; struct bdaddr_t bdaddr; char bdaddr_str[18]; int out_sock; int in_sock; int state; int leds; int flags; void (*event_cb)(struct wiimote_t *wm); void (*dis_cb)(struct wiimote_t *wm); void (*stat_cb)(struct wiimote_t *wm, int attachment, int speaker, int ir, int led[4], float battery_level); unsigned char handshake_state; struct read_req_t *read_req; struct accel_t accel_calib; struct expansion_t exp; struct vec3b_t accel; struct orient_t orient; struct gforce_t gforce; struct ir_t ir; unsigned short btns; unsigned short btns_held; unsigned short btns_released; float orient_threshold; struct wiimote_state_t lstate; unsigned char event[32]; }

user_defined_types: struct accel_t { struct vec3b_t cal_zero; struct vec3b_t cal_g; float st_roll; float st_pitch; float st_alpha; }

user_defined_types: struct expansion_t { enum { EXP_NONE=0, EXP_NUNCHUK=1, EXP_CLASSIC=2 } type; union { struct nunchuk_t nunchuk; struct classic_ctrl_t classic; }; }

user_defined_types: struct ir_t { struct ir_dot_t dot[4]; unsigned char num_dots; enum aspect_t aspect; enum ir_position_t pos; unsigned int vres[2]; int offset[2]; int state; int ax; int ay; int x; int y; float distance; float z; }

user_defined_types: struct nunchuk_t { struct accel_t accel_calib; struct joystick_t js; int *flags; unsigned char btns; unsigned char btns_held; unsigned char btns_released; struct vec3b_t accel; struct orient_t orient; struct gforce_t gforce; }

user_defined_types: struct joystick_t { struct vec2b_t max; struct vec2b_t min; struct vec2b_t center; float ang; float mag; }


decompiled_code:
int __fastcall handle_read(unsigned int *a1, __int64 a2, unsigned __int16 a3)
{
__int64 v4; // rbx

printf("\n\n--- DATA READ [wiimote id %i] ---\n", *a1);
printf("finished read of size %i\n", a3);
if ( a3 )
{
v4 = 0LL;
do
{
if ( (v4 & 0xF) == 0 )
putchar(10);
printf("%x ", *(unsigned __int8 *)(a2 + v4++));
}
while ( a3 > (int)v4 );
}
return puts("\n");
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1, __int64 a2, unsigned __int16 a3)
{
__int64 v4; // rbx

printf("\n\n--- DATA READ [wiimote id %i] ---\n", *a1);
printf("finished read of size %i\n", a3);
if ( a3 )
{
v4 = 0LL;
do
{
if ( (v4 & 0xF) == 0 )
putchar(10);
printf("%x ", *(unsigned __int8 *)(a2 + v4++));
}
while ( a3 > (int)v4 );
}
return puts("\n");
}

original_code:
void handle_read(struct wiimote_t* wm, byte* data, unsigned short len) {
 int i = 0;
 printf("\n\n--- DATA READ [wiimote id %i] ---\n", wm->unid);
 printf("finished read of size %i\n", len);
 for (; i < len; ++i) {
  if (!(i%16))
   printf("\n");
  printf("%x ", data[i]);
 }
 printf("\n\n");
}

canonical_original_code:
void handle_read(struct wiimote_t *wm, unsigned char *data, unsigned short len) {
 int i = 0;
 printf("\n\n--- DATA READ [wiimote id %i] ---\n", wm->unid);
 printf("finished read of size %i\n", len);
 for (; i < len; ++i) {
  if (!(i%16))
   printf("\n");
  printf("%x ", data[i]);
 }
 printf("\n\n");
}

variable_types:
data
unsigned char *

variable_types:
len
unsigned short

variable_types: i int

user_defined_types: struct wiimote_state_t { float exp_ljs_ang; float exp_rjs_ang; float exp_ljs_mag; float exp_rjs_mag; unsigned char exp_btns; struct orient_t exp_orient; float exp_r_shoulder; float exp_l_shoulder; int ir_ax; int ir_ay; float ir_distance; struct orient_t orient; unsigned short btns; }

user_defined_types: struct read_req_t { void (*cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len); unsigned char *buf; unsigned int addr; unsigned short size; unsigned short wait; struct read_req_t *next; }

user_defined_types: enum aspect_t { WIIUSE_ASPECT_4_3=0, WIIUSE_ASPECT_16_9=1 }

user_defined_types: enum ir_position_t { WIIUSE_IR_ABOVE=0, WIIUSE_IR_BELOW=1 }

user_defined_types: struct classic_ctrl_t { short btns; short btns_held; short btns_released; float r_shoulder; float l_shoulder; struct joystick_t ljs; struct joystick_t rjs; }

user_defined_types: struct ir_dot_t { unsigned char visible; unsigned int x; unsigned int y; short rx; short ry; unsigned char order; unsigned char size; }

user_defined_types: struct orient_t { float roll; float pitch; float yaw; }


decompiled_code:
int __fastcall handle_ctrl_status(unsigned int *a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int *a5, float a6)
{
printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", *a1);
printf("attachment: %i\n", a2);
printf("speaker: %i\n", a3);
printf("ir: %i\n", a4);
printf("leds: %i %i %i %i\n", *a5, a5[1], a5[2], a5[3]);
return printf("battery: %f %%\n", a6);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1, unsigned int a2, unsigned int a3, unsigned int a4, unsigned int *a5, float a6)
{
printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", *a1);
printf("attachment: %i\n", a2);
printf("speaker: %i\n", a3);
printf("ir: %i\n", a4);
printf("leds: %i %i %i %i\n", *a5, a5[1], a5[2], a5[3]);
return printf("battery: %f %%\n", a6);
}

original_code:
void handle_ctrl_status(struct wiimote_t* wm, int attachment, int speaker, int ir, int led[4], float battery_level) {
 printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", wm->unid);
 printf("attachment:      %i\n", attachment);
 printf("speaker:         %i\n", speaker);
 printf("ir:              %i\n", ir);
 printf("leds:            %i %i %i %i\n", led[0], led[1], led[2], led[3]);
 printf("battery:         %f %%\n", battery_level);
}

canonical_original_code:
void handle_ctrl_status(struct wiimote_t *wm, int attachment, int speaker, int ir, int led[4], float battery_level) {
 printf("\n\n--- CONTROLLER STATUS [wiimote id %i] ---\n", wm->unid);
 printf("attachment:      %i\n", attachment);
 printf("speaker:         %i\n", speaker);
 printf("ir:              %i\n", ir);
 printf("leds:            %i %i %i %i\n", led[0], led[1], led[2], led[3]);
 printf("battery:         %f %%\n", battery_level);
}

variable_types: attachment int

variable_types: speaker int

variable_types: ir int

variable_types:
led
int [4]


decompiled_code:
int __fastcall handle_disconnect(unsigned int *a1)
{
return printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", *a1);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int *a1)
{
return printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", *a1);
}

original_code:
void handle_disconnect(wiimote* wm) {
 printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", wm->unid);
}

canonical_original_code:
void handle_disconnect(struct wiimote_t *wm) {
 printf("\n\n--- DISCONNECTED [wiimote id %i] ---\n", wm->unid);
}


decompiled_code:
int vid_open_device()
{
return open("/dev/video0", 2);
}

canonical_decompiled_code:
int func2()
{
return open("/dev/video0", 2);
}

original_code:
int vid_open_device(char *device)
{
 int handle = open("/dev/video0",02);
 return handle;
}

variable_types:
device
char *

variable_types: handle int


original_code:
void vid_get_standards(int handle)
{
 struct v4l2_input input;
 struct v4l2_standard standard;
 memset (&input, 0, sizeof (input));
 if (-1 == xioctl (handle, (((2U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((38)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &input.index))
 {
  perror ("VIDIOC_G_INPUT");
  exit (1);
 }
 if (-1 == xioctl (handle, (((2U|1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((26)) << 0) | ((((sizeof(struct v4l2_input)))) << ((0 +8)+8))), &input))
 {
  perror ("VIDIOC_ENUM_INPUT");
  exit (1);
 }
 printf ("Current input %s supports:\n", input.name);
 memset (&standard, 0, sizeof (standard));
 standard.index = 0;
 while (0 == xioctl (handle, (((2U|1U) << (((0 +8)+8)+14)) | ((('V')) << (0 +8)) | (((25)) << 0) | ((((sizeof(struct v4l2_standard)))) << ((0 +8)+8))), &standard))
 {
  if (standard.id & input.std)
   printf ("%s\n", standard.name);
  standard.index++;
 }
 if ((*__errno_location ()) != 22 || standard.index == 0)
 {
  perror ("VIDIOC_ENUMSTD");
  exit (1);
 }
}

variable_types: struct v4l2_input { unsigned int index; unsigned char name[32]; unsigned int type; unsigned int audioset; unsigned int tuner; unsigned long long std; unsigned int status; unsigned int capabilities; unsigned int reserved[3]; }

variable_types: struct v4l2_standard { unsigned int index; unsigned long long id; unsigned char name[24]; struct v4l2_fract { unsigned int numerator; unsigned int denominator; } frameperiod; unsigned int framelines; unsigned int reserved[4]; }

user_defined_types: struct v4l2_standard { unsigned int index; unsigned long long id; unsigned char name[24]; struct v4l2_fract frameperiod; unsigned int framelines; unsigned int reserved[4]; }


decompiled_code:
__int64 __fastcall xioctl(int fd, int a2, __int64 a3)
{
unsigned int v4; // ebx

do
v4 = ioctl(fd, a2, a3);
while ( v4 == -1 && *_errno_location() == 4 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, int a2, __int64 a3)
{
unsigned int v4; // ebx

do
v4 = ioctl(fd, a2, a3);
while ( v4 == -1 && *_errno_location() == 4 );
return v4;
}

original_code:
static int xioctl(int fd, int32_t request, void *arg)
{
 int r;
 do
 {
  r = ioctl (fd, request, arg);
 } while (-1 == r && 4 == (*__errno_location ()));
 return r;
}

canonical_original_code:
static int xioctl(int fd, int request, void *arg)
{
 int r;
 do
 {
  r = ioctl (fd, request, arg);
 } while (-1 == r && 4 == (*__errno_location ()));
 return r;
}

variable_types: fd int

variable_types: request int

variable_types:
arg
void *

variable_types: r int


decompiled_code:
__int64 groups_get_id()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func11()
{
return 0xFFFFFFFFLL;
}

original_code:
extern int groups_get_id()
{
 return groups_selected;
}


decompiled_code:
void *__fastcall thread_entry(void *a1)
{
__int64 v1; // rbx
double v2; // xmm0_8

v1 = 1000000000LL;
while ( ++v1 != 15000000000LL )
{
if ( v1 < 0 )
v2 = (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)) + (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1));
else
v2 = (double)(int)v1;
if ( v2 < 0.0 )
sqrt(v2);
}
return 0LL;
}

original_code:
void *thread_entry(void *data)
{
 unsigned long int i;
 for(i=1000000000;i<15000000000;i++)
 {
  double res = sqrt(i);
 }
 return ((void *)0);
}

canonical_original_code:
void *thread_entry(void *data)
{
 unsigned long i;
 for(i=1000000000;i<15000000000;i++)
 {
  double res = sqrt(i);
 }
 return ((void *)0);
}

variable_types:
data
void *

variable_types:
i
unsigned long

variable_types: res double

return_type: void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pthread_t *v3; // rbx
__int64 i; // rbx
pthread_t th[256]; // [rsp+0h] [rbp-818h] BYREF
char v7; // [rsp+800h] [rbp-18h] BYREF

v3 = th;
do
pthread_create(v3++, 0LL, thread_entry, 0LL);
while ( v3 != (pthread_t *)&v7 );
for ( i = 0LL; i != 256; ++i )
{
pthread_join(th[i], 0LL);
printf("Thread: %d done!\n", (unsigned int)i);
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
 pthread_t threads[256];
 int i;
 for(i = 0;i<256;i++)
  pthread_create(&threads[i],((void *)0),thread_entry,((void *)0));
 for (i=0; i<256; i++)
 {
  pthread_join(threads[i], ((void *)0));
  printf("Thread: %d done!\n",i);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned long threads[256];
 int i;
 for(i = 0;i<256;i++)
  pthread_create(&threads[i],((void *)0),thread_entry,((void *)0));
 for (i=0; i<256; i++)
 {
  pthread_join(threads[i], ((void *)0));
  printf("Thread: %d done!\n",i);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
threads
unsigned long [256]


decompiled_code:
void get_folder_contents()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
char *get_folder_contents(char *dir_name)
{
 char *ret_string = malloc(32);
}

return_type: char *


decompiled_code:
int __fastcall print_details(__int64 a1, const char *a2)
{
struct stat *v2; // rbx
void *v3; // rbp
const char *v4; // r15
const char *v5; // r14
const char *v6; // r13
const char *v7; // rbp
const char *v8; // rax

v2 = (struct stat *)malloc(0x90uLL);
v3 = malloc(0x100uLL);
memset(v3, 0, 0x100uLL);
strcpy((char *)v3, a2);
strcat((char *)v3, (const char *)(a1 + 19));
lstat((const char *)v3, v2);
free(v3);
v4 = (const char *)time_format(&v2->st_mtim);
v5 = (const char *)size_format(v2->st_size);
v6 = (const char *)group_format(v2->st_gid);
v7 = (const char *)user_format(v2->st_uid);
v8 = (const char *)mode_format(v2->st_mode);
return printf("%10s %s %s %4s %16s \x1B[32;1m%-16s\x1B[34;0m\n", v8, v7, v6, v5, v4, (const char *)(a1 + 19));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char *a2)
{
struct stat *v2; // rbx
void *v3; // rbp
const char *v4; // r15
const char *v5; // r14
const char *v6; // r13
const char *v7; // rbp
const char *v8; // rax

v2 = (struct stat *)malloc(0x90uLL);
v3 = malloc(0x100uLL);
memset(v3, 0, 0x100uLL);
strcpy((char *)v3, a2);
strcat((char *)v3, (const char *)(a1 + 19));
lstat((const char *)v3, v2);
free(v3);
v4 = (const char *)time_format(&v2->st_mtim);
v5 = (const char *)size_format(v2->st_size);
v6 = (const char *)group_format(v2->st_gid);
v7 = (const char *)user_format(v2->st_uid);
v8 = (const char *)mode_format(v2->st_mode);
return printf("%10s %s %s %4s %16s \x1B[32;1m%-16s\x1B[34;0m\n", v8, v7, v6, v5, v4, (const char *)(a1 + 19));
}

original_code:
void print_details(struct dirent *dir, char *root_dir)
{
 struct stat *file_mode = malloc(sizeof(struct stat));
 char *cfile_name = malloc(256);
 memset(cfile_name,'\0',256);
 strcpy(cfile_name,root_dir);
 strcat(cfile_name,dir->d_name);
 lstat(cfile_name, file_mode);
 free(cfile_name);
 char *user = malloc(32);
 char *group = malloc(32);
 printf("%10s %s %s %4s %16s \x1b[32;1m%-16s\x1b[34;0m\n",mode_format(file_mode->st_mode),user_format(file_mode->st_uid),group_format(file_mode->st_gid), size_format(file_mode->st_size), time_format(&file_mode->st_mtim.tv_sec), dir->d_name);
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *

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

variable_types:
user
char *

variable_types:
group
char *

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


decompiled_code:
__int64 res_load_resources()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax

if ( !res_mutex )
res_mutex = SDL_CreateMutex();
SDL_mutexP(res_mutex);
v0 = SDL_RWFromFile("sound/bass.wav", &unk_318);
samples = Mix_LoadWAV_RW(v0, 1LL);
v1 = SDL_RWFromFile("sound/cym.wav", &unk_318);
qword_2C8 = Mix_LoadWAV_RW(v1, 1LL);
v2 = SDL_RWFromFile("sound/hihat.wav", &unk_318);
qword_2D0 = Mix_LoadWAV_RW(v2, 1LL);
v3 = SDL_RWFromFile("sound/hihat2.wav", &unk_318);
qword_2D8 = Mix_LoadWAV_RW(v3, 1LL);
v4 = SDL_RWFromFile("sound/snare.wav", &unk_318);
qword_2E0 = Mix_LoadWAV_RW(v4, 1LL);
v5 = SDL_RWFromFile("sound/cra.wav", &unk_318);
qword_2E8 = Mix_LoadWAV_RW(v5, 1LL);
v6 = SDL_RWFromFile("sound/hi.wav", &unk_318);
qword_2F0 = Mix_LoadWAV_RW(v6, 1LL);
v7 = SDL_RWFromFile("sound/mid.wav", &unk_318);
qword_2F8 = Mix_LoadWAV_RW(v7, 1LL);
v8 = SDL_RWFromFile("sound/low.wav", &unk_318);
qword_300 = Mix_LoadWAV_RW(v8, 1LL);
v9 = SDL_RWFromFile("sound/stick.wav", &unk_318);
qword_308 = Mix_LoadWAV_RW(v9, 1LL);
kit = IMG_Load("kit.png");
SDL_mutexV(res_mutex);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax

if ( !res_mutex )
res_mutex = SDL_CreateMutex();
SDL_mutexP(res_mutex);
v0 = SDL_RWFromFile("sound/bass.wav", &unk_318);
samples = Mix_LoadWAV_RW(v0, 1LL);
v1 = SDL_RWFromFile("sound/cym.wav", &unk_318);
qword_2C8 = Mix_LoadWAV_RW(v1, 1LL);
v2 = SDL_RWFromFile("sound/hihat.wav", &unk_318);
qword_2D0 = Mix_LoadWAV_RW(v2, 1LL);
v3 = SDL_RWFromFile("sound/hihat2.wav", &unk_318);
qword_2D8 = Mix_LoadWAV_RW(v3, 1LL);
v4 = SDL_RWFromFile("sound/snare.wav", &unk_318);
qword_2E0 = Mix_LoadWAV_RW(v4, 1LL);
v5 = SDL_RWFromFile("sound/cra.wav", &unk_318);
qword_2E8 = Mix_LoadWAV_RW(v5, 1LL);
v6 = SDL_RWFromFile("sound/hi.wav", &unk_318);
qword_2F0 = Mix_LoadWAV_RW(v6, 1LL);
v7 = SDL_RWFromFile("sound/mid.wav", &unk_318);
qword_2F8 = Mix_LoadWAV_RW(v7, 1LL);
v8 = SDL_RWFromFile("sound/low.wav", &unk_318);
qword_300 = Mix_LoadWAV_RW(v8, 1LL);
v9 = SDL_RWFromFile("sound/stick.wav", &unk_318);
qword_308 = Mix_LoadWAV_RW(v9, 1LL);
kit = IMG_Load("kit.png");
SDL_mutexV(res_mutex);
return 0LL;
}

original_code:
int res_load_resources(void *data)
{
 if(!res_mutex)
  res_mutex = SDL_CreateMutex();
 SDL_mutexP(res_mutex);
 int i = 0;
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/bass.wav", "rb"), 1);
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/cym.wav", "rb"), 1);
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/hihat.wav", "rb"), 1);
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/hihat2.wav", "rb"), 1);
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/snare.wav", "rb"), 1);
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/cra.wav", "rb"), 1);
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/hi.wav", "rb"), 1);
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/mid.wav", "rb"), 1);
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/low.wav", "rb"), 1);
 samples[i++] = Mix_LoadWAV_RW(SDL_RWFromFile("sound/stick.wav", "rb"), 1);
 kit = IMG_Load("kit.png");
 SDL_mutexV(res_mutex);
 return 0;
}

variable_types: i int


decompiled_code:
__int64 res_loaded()
{
SDL_mutexP(res_mutex);
SDL_mutexV(res_mutex);
return SDL_DestroyMutex(res_mutex);
}

canonical_decompiled_code:
__int64 func1()
{
SDL_mutexP(res_mutex);
SDL_mutexV(res_mutex);
return SDL_DestroyMutex(res_mutex);
}

original_code:
void res_loaded()
{
 SDL_mutexP(res_mutex);
 SDL_mutexV(res_mutex);
 SDL_DestroyMutex(res_mutex);
}


decompiled_code:
__int64 __fastcall res_play(int a1, unsigned int a2)
{
return Mix_PlayChannelTimed(a2, samples[a1], 0LL, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, unsigned int a2)
{
return Mix_PlayChannelTimed(a2, samples[a1], 0LL, 0xFFFFFFFFLL);
}

original_code:
void res_play(drum_sounds sound, int channel)
{
 Mix_PlayChannelTimed(channel,samples[sound],0,-1);
}

canonical_original_code:
void res_play(enum drum_sounds sound, int channel)
{
 Mix_PlayChannelTimed(channel,samples[sound],0,-1);
}

variable_types: enum drum_sounds { BASS=0, CYM=1, HIHAT=2, HIHAT2=3, SNARE=4, CRASH=5, HITOM=6, MIDTOM=7, FLOORTOM=8, STICK=9 }

variable_types: channel int


decompiled_code:
__int64 __fastcall _(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return a1;
}

original_code:
char *_(char *str)
{
 return str;
}

canonical_original_code:
char *_(char *str)
{
 return str;
}

variable_types:
str
char *


split

decompiled_code:
char *__fastcall split(char *s, char a2, int a3)
{
int v3; // er12
size_t v5; // rcx
size_t v6; // rax
int v7; // edx
int v8; // ebp
char *v9; // r13
size_t v11; // rax
int v12; // esi
size_t v13; // rcx

v3 = a3;
if ( a3 )
{
v13 = strlen(s);
v11 = 0LL;
v12 = 0;
while ( 1 )
{
if ( s[v11] == a2 && v3 == ++v12 )
{
v3 = v11 + 1;
goto LABEL_2;
}
if ( v11 == v13 )
break;
v7 = ++v11;
if ( v13 < v11 )
{
v3 = v7;
goto LABEL_5;
}
}
v9 = 0LL;
}
else
{
LABEL_2:
v5 = strlen(s);
v6 = v3;
do
{
v7 = v6;
if ( v5 < v6 )
break;
++v6;
}
while ( s[v6 - 1] != a2 );
LABEL_5:
v8 = v7 - v3;
v9 = (char *)malloc(v7 - v3 + 1);
strncpy(v9, &s[v3], v8);
v9[v8] = 0;
}
return v9;
}

canonical_decompiled_code:
char *__fastcall func2(char *s, char a2, int a3)
{
int v3; // er12
size_t v5; // rcx
size_t v6; // rax
int v7; // edx
int v8; // ebp
char *v9; // r13
size_t v11; // rax
int v12; // esi
size_t v13; // rcx

v3 = a3;
if ( a3 )
{
v13 = strlen(s);
v11 = 0LL;
v12 = 0;
while ( 1 )
{
if ( s[v11] == a2 && v3 == ++v12 )
{
v3 = v11 + 1;
goto LABEL_2;
}
if ( v11 == v13 )
break;
v7 = ++v11;
if ( v13 < v11 )
{
v3 = v7;
goto LABEL_5;
}
}
v9 = 0LL;
}
else
{
LABEL_2:
v5 = strlen(s);
v6 = v3;
do
{
v7 = v6;
if ( v5 < v6 )
break;
++v6;
}
while ( s[v6 - 1] != a2 );
LABEL_5:
v8 = v7 - v3;
v9 = (char *)malloc(v7 - v3 + 1);
strncpy(v9, &s[v3], v8);
v9[v8] = 0;
}
return v9;
}

original_code:
char *split(char *str, char splits, int ret)
{
  char *ptr;
  int a, b, c=0;
  if(ret!=0)
  {
    for(a=0;a<=strlen(str);a++)
    {
      if(str[a]==splits && ++c==ret)
      {
        a++;
        break;
      }
      if(a==strlen(str))
        return ((void *)0);
    }
  } else
  {
    a = 0;
  }
  for(b=a;b<=strlen(str);b++)
    if(str[b]==splits) break;
  ptr = (char *)malloc(sizeof(char)*(b-a+1));
  strncpy(ptr, &str[a], b-a);
  ptr[b-a]=0x0;
  return (char *)ptr;
}

canonical_original_code:
char *split(char *str, char splits, int ret)
{
  char *ptr;
  int a; int b; int c = 0;
  if(ret!=0)
  {
    for(a=0;a<=strlen(str);a++)
    {
      if(str[a]==splits && ++c==ret)
      {
        a++;
        break;
      }
      if(a==strlen(str))
        return ((void *)0);
    }
  } else
  {
    a = 0;
  }
  for(b=a;b<=strlen(str);b++)
    if(str[b]==splits) break;
  ptr = (char *)malloc(sizeof(char)*(b-a+1));
  strncpy(ptr, &str[a], b-a);
  ptr[b-a]=0x0;
  return (char *)ptr;
}

variable_types: splits char

variable_types: ret int

variable_types:
ptr
char *

variable_types: a int

variable_types: b int

variable_types: c int


decompiled_code:
__int64 __fastcall MSN_url_encode(char *s, __int64 a2, int a3)
{
size_t v4; // rbp
int i; // ebx
size_t v6; // rax
char v7; // r12
__int64 result; // rax

v4 = 0LL;
for ( i = 0; ; ++i )
{
v6 = strlen(s);
if ( i >= a3 || v6 <= v4 )
break;
v7 = s[v4];
if ( isalnum(v7) )
{
*(_BYTE *)(a2 + i) = v7;
}
else
{
snprintf((char *)(a2 + i), a3 - (int)v4, "%%%x", (unsigned int)v7);
i += 2;
}
++v4;
}
result = a2;
*(_BYTE *)(a2 + i) = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, __int64 a2, int a3)
{
size_t v4; // rbp
int i; // ebx
size_t v6; // rax
char v7; // r12
__int64 result; // rax

v4 = 0LL;
for ( i = 0; ; ++i )
{
v6 = strlen(s);
if ( i >= a3 || v6 <= v4 )
break;
v7 = s[v4];
if ( isalnum(v7) )
{
*(_BYTE *)(a2 + i) = v7;
}
else
{
snprintf((char *)(a2 + i), a3 - (int)v4, "%%%x", (unsigned int)v7);
i += 2;
}
++v4;
}
result = a2;
*(_BYTE *)(a2 + i) = 0;
return result;
}

original_code:
char *MSN_url_encode(char *str, char *ret, int ret_len)
{
  int i, a;
  for(i=0, a=0;i<strlen(str) && a<ret_len;i++, a++)
  {
    if(!isalnum(str[i]))
    {
      snprintf(&ret[a], ret_len-i, "%%%x", str[i]);
      a+=2;
    }
    else
    {
      ret[a] = str[i];
    }
  }
  ret[a]=0x0;
  return ret;
}

canonical_original_code:
char *MSN_url_encode(char *str, char *ret, int ret_len)
{
  int i; int a;
  for(i=0, a=0;i<strlen(str) && a<ret_len;i++, a++)
  {
    if(!isalnum(str[i]))
    {
      snprintf(&ret[a], ret_len-i, "%%%x", str[i]);
      a+=2;
    }
    else
    {
      ret[a] = str[i];
    }
  }
  ret[a]=0x0;
  return ret;
}

variable_types:
ret
char *


decompiled_code:
__int64 __fastcall tcp_connect(char *name, __int16 a2)
{
unsigned int v2; // ebp
struct hostent *v3; // r12
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
v3 = gethostbyname(name);
v5.sa_family = 2;
*(_WORD *)v5.sa_data = _bswap_16(a2);
*(_DWORD *)&v5.sa_data[2] = **(_DWORD **)v3->h_addr_list;
connect(v2, &v5, 0x10u);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *name, __int16 a2)
{
unsigned int v2; // ebp
struct hostent *v3; // r12
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
v3 = gethostbyname(name);
v5.sa_family = 2;
*(_WORD *)v5.sa_data = func0(a2);
*(_DWORD *)&v5.sa_data[2] = **(_DWORD **)v3->h_addr_list;
connect(v2, &v5, 0x10u);
return v2;
}

original_code:
int tcp_connect(char *host, short port)
{
 int rsock = socket(2, SOCK_STREAM, 0);
 struct hostent *hent = gethostbyname(host);
 struct sockaddr_in sock_dst;
 sock_dst.sin_family = 2;
 sock_dst.sin_port = htons(port);
 sock_dst.sin_addr = *((struct in_addr*)hent->h_addr_list[0]);
 connect(rsock, (struct sockaddr*)&sock_dst, sizeof(sock_dst));
 return rsock;
}

canonical_original_code:
int tcp_connect(char *host, short port)
{
 int rsock = socket(2, SOCK_STREAM, 0);
 struct hostent *hent = gethostbyname(host);
 struct sockaddr_in sock_dst;
 sock_dst.sin_family = 2;
 sock_dst.sin_port = htons(port);
 sock_dst.sin_addr = *((struct in_addr *)hent->h_addr_list[0]);
 connect(rsock, (struct sockaddr *)&sock_dst, sizeof(sock_dst));
 return rsock;
}

variable_types:
host
char *

variable_types: port short

variable_types: rsock int

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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

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

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


decompiled_code:
void __fastcall __noreturn berr_exit(const char *a1)
{
BIO_printf(bio_err, "%s\n", a1);
ERR_print_errors(bio_err);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func5(const char *a1)
{
BIO_printf(bio_err, "%s\n", a1);
ERR_print_errors(bio_err);
exit(0);
}

original_code:
int berr_exit(char *string)
{
  BIO_printf(bio_err,"%s\n",string);
  ERR_print_errors(bio_err);
  exit(0);
}

variable_types:
string
char *


decompiled_code:
__int64 __fastcall https_auth(char *s, __int16 a2, const char *a3, char *a4, char *a5, __int64 a6, char *dest, int a8, __int64 a9)
{
char *v13; // r13
char *v14; // rbx
char *v15; // rbp
size_t v16; // rax
void *v17; // r14
int v18; // eax
__int64 v19; // rax
unsigned int v20; // er12
char *v21; // rax
char *v22; // rbp
char *v23; // rax
char *v24; // rax
char *v25; // rax
char *v26; // rbx
char format[144]; // [rsp+10h] [rbp-10E8h] BYREF
char v29[2048]; // [rsp+A0h] [rbp-1058h] BYREF
char sa[2048]; // [rsp+8A0h] [rbp-858h] BYREF
struct timeval tv; // [rsp+10A0h] [rbp-58h] BYREF
int v32[15]; // [rsp+10BCh] [rbp-3Ch] BYREF

strcpy(
format,
"GET /%s HTTP/1.1\r\n"
"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom,sign-in=%s,pwd=%s,%sHost: %s\r\n\r\n");
v32[0] = getpid();
RAND_add(v32, 4LL, 0.01);
v32[0] = getpgrp();
RAND_add(v32, 4LL, 0.01);
v32[0] = getppid();
RAND_add(v32, 4LL, 0.01);
v32[0] = 0;
gettimeofday(&tv, 0LL);
RAND_add(&tv, 16LL, 0.1);
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
MSN_url_encode(a5, (__int64)sa, 2047);
v13 = strdup(sa);
v14 = strdup(s);
v15 = strdup(a3);
if ( v14 == 0LL || v13 == 0LL || !v15 )
{
if ( a9 )
{
v19 = _((__int64)"Cannot allocate memory");
((void (__fastcall *)(__int64, __int64))a9)(0xFFFFFFFFLL, v19);
}
v20 = -1;
}
else
{
printf("MSN LOGIN: %s\n", a4);
v16 = strlen(a4);
v17 = malloc(3 * v16 + 1);
puts("Done!");
puts("OT OH");
v18 = strlen(a4);
MSN_url_encode(a4, (__int64)v17, 3 * v18);
puts("SPAGHETTIOHS!");
snprintf(v29, 0x7FFuLL, format, v15, v17, v13, a6, v14);
printf("Request: %s\n", v29);
while ( 1 )
{
v20 = get_https(v14, a2, v29, sa, 2047);
if ( v20 != -2 )
break;
free(v14);
free(v15);
v21 = strstr(sa, "Location:");
v22 = v21;
if ( !v21 )
{
puts("No 'Location:' in HTTP header");
return (unsigned int)-1;
}
v21[strlen(v21) - 4] = 0;
v14 = split(v22, 47, 2);
v23 = split(v22, 47, 3);
v15 = v23;
if ( !v14 || !v23 )
{
puts("Couldn't parse URL");
return (unsigned int)-1;
}
v24 = strstr(v23, "\r\n");
if ( v24 )
*v24 = 0;
snprintf(v29, 0x7FFuLL, format, v15, v17, v13, a6, v14);
}
free(v14);
free(v15);
free(v13);
if ( v20 == -1 )
{
puts("Bad username or password!");
}
else
{
v25 = split(sa, 39, 1);
v26 = v25;
if ( v25 )
{
strncpy(dest, v25, a8);
free(v26);
v20 = 0;
}
else
{
puts("Couldn't extract ticket");
v20 = -1;
}
}
}
return v20;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *s, __int16 a2, const char *a3, char *a4, char *a5, __int64 a6, char *dest, int a8, __int64 a9)
{
char *v13; // r13
char *v14; // rbx
char *v15; // rbp
size_t v16; // rax
void *v17; // r14
int v18; // eax
__int64 v19; // rax
unsigned int v20; // er12
char *v21; // rax
char *v22; // rbp
char *v23; // rax
char *v24; // rax
char *v25; // rax
char *v26; // rbx
char format[144]; // [rsp+10h] [rbp-10E8h] BYREF
char v29[2048]; // [rsp+A0h] [rbp-1058h] BYREF
char sa[2048]; // [rsp+8A0h] [rbp-858h] BYREF
struct timeval tv; // [rsp+10A0h] [rbp-58h] BYREF
int v32[15]; // [rsp+10BCh] [rbp-3Ch] BYREF

strcpy(
format,
"GET /%s HTTP/1.1\r\n"
"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom,sign-in=%s,pwd=%s,%sHost: %s\r\n\r\n");
v32[0] = getpid();
RAND_add(v32, 4LL, 0.01);
v32[0] = getpgrp();
RAND_add(v32, 4LL, 0.01);
v32[0] = getppid();
RAND_add(v32, 4LL, 0.01);
v32[0] = 0;
gettimeofday(&tv, 0LL);
RAND_add(&tv, 16LL, 0.1);
tv.tv_sec = 0LL;
tv.tv_usec = 0LL;
func3(a5, (__int64)sa, 2047);
v13 = strdup(sa);
v14 = strdup(s);
v15 = strdup(a3);
if ( v14 == 0LL || v13 == 0LL || !v15 )
{
if ( a9 )
{
v19 = func1((__int64)"Cannot allocate memory");
((void (__fastcall *)(__int64, __int64))a9)(0xFFFFFFFFLL, v19);
}
v20 = -1;
}
else
{
printf("MSN LOGIN: %s\n", a4);
v16 = strlen(a4);
v17 = malloc(3 * v16 + 1);
puts("Done!");
puts("OT OH");
v18 = strlen(a4);
func3(a4, (__int64)v17, 3 * v18);
puts("SPAGHETTIOHS!");
snprintf(v29, 0x7FFuLL, format, v15, v17, v13, a6, v14);
printf("Request: %s\n", v29);
while ( 1 )
{
v20 = func8(v14, a2, v29, sa, 2047);
if ( v20 != -2 )
break;
free(v14);
free(v15);
v21 = strstr(sa, "Location:");
v22 = v21;
if ( !v21 )
{
puts("No 'Location:' in HTTP header");
return (unsigned int)-1;
}
v21[strlen(v21) - 4] = 0;
v14 = func2(v22, 47, 2);
v23 = func2(v22, 47, 3);
v15 = v23;
if ( !v14 || !v23 )
{
puts("Couldn't parse URL");
return (unsigned int)-1;
}
v24 = strstr(v23, "\r\n");
if ( v24 )
*v24 = 0;
snprintf(v29, 0x7FFuLL, format, v15, v17, v13, a6, v14);
}
free(v14);
free(v15);
free(v13);
if ( v20 == -1 )
{
puts("Bad username or password!");
}
else
{
v25 = func2(sa, 39, 1);
v26 = v25;
if ( v25 )
{
strncpy(dest, v25, a8);
free(v26);
v20 = 0;
}
else
{
puts("Couldn't extract ticket");
v20 = -1;
}
}
}
return v20;
}

original_code:
int https_auth(char *origHost,int port,char *origFile,char *msnLogin,char *msnPasswd,char *idString,char *ticket,int ticketLen, void (*callback)(int,void *))
{
  int r;
  pid_t pid;
  struct timeval tv;
  char buf[2048], request[2048], *host, *encodedPasswd, *file, *ptr;
  char requestTemplate[] = "GET /%s HTTP/1.1\r\nAuthorization: "
                           "Passport1.4 OrgVerb=GET,"
                           "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom,"
                           "sign-in=%s,pwd=%s,%sHost: "
         "%s\r\n\r\n";
  pid = getpid();
  RAND_add(&pid, sizeof(pid),0.01);
  pid = getpgrp();
  RAND_add(&pid, sizeof(pid),0.01);
  pid = getppid();
  RAND_add(&pid, sizeof(pid),0.01);
  pid = 0;
  gettimeofday(&tv,((void *)0));
  RAND_add(&tv, sizeof(tv),0.1);
  memset(&tv, '\0', sizeof(tv));
  MSN_url_encode(msnPasswd, buf, sizeof(buf)-1);
  encodedPasswd = strdup(buf);
  host = strdup(origHost);
  file = strdup(origFile);
  if(encodedPasswd==((void *)0) || host==((void *)0) || file==((void *)0))
  {
    if(callback!=((void *)0)) callback(-1,_("Cannot allocate memory"));
    return -1;
  }
 printf("MSN LOGIN: %s\n",msnLogin);
 char *escaped_msnLogin = malloc(strlen(msnLogin)*3+1);
 printf("Done!\n");
 memset(escaped_msnLogin,strlen(msnLogin)*3+1,'\0');
 printf("OT OH\n");
 MSN_url_encode(msnLogin, escaped_msnLogin, strlen(msnLogin)*3);
 printf("SPAGHETTIOHS!\n");
  snprintf(request, 2048 -1, requestTemplate, file, escaped_msnLogin, encodedPasswd, idString, host);
 printf("Request: %s\n", request);
  while((r=get_https(host, port, request, buf, sizeof(buf)-1))==-2)
  {
    free(host);
    free(file);
    if((ptr = strstr(buf, "Location:"))==((void *)0))
    {
      printf("No 'Location:' in HTTP header\n");
      return -1;
    }
    ptr[strlen(ptr)-4]=0x0;
    host = split(ptr, '/', 2);
    file = split(ptr, '/', 3);
    if(host==((void *)0) || file==((void *)0))
    {
      printf("Couldn't parse URL\n");
      return -1;
    }
    if((ptr = strstr(file, "\r\n")) != ((void *)0))
      *ptr = 0x0;
    snprintf(request, sizeof(request)-1, requestTemplate,file, escaped_msnLogin, encodedPasswd, idString, host );
  }
  free(host);
  free(file);
  free(encodedPasswd);
  if(r==-1)
  {
    printf("Bad username or password!\n");
    return -1;
  }
  if((ptr=split(buf, '\'',1))==((void *)0))
  {
    printf("Couldn't extract ticket\n");
    return -1;
  }
  strncpy(ticket, ptr, ticketLen);
  free(ptr);
  return 0;
}

canonical_original_code:
int https_auth(char *origHost, int port, char *origFile, char *msnLogin, char *msnPasswd, char *idString, char *ticket, int ticketLen, void (*callback)(int, void *))
{
  int r;
  int pid;
  struct timeval tv;
  char buf[2048]; char request[2048]; char *host; char *encodedPasswd; char *file; char *ptr;
  char requestTemplate[] = "GET /%s HTTP/1.1\r\nAuthorization: "
                           "Passport1.4 OrgVerb=GET,"
                           "OrgURL=http%%3A%%2F%%2Fmessenger%%2Emsn%%2Ecom,"
                           "sign-in=%s,pwd=%s,%sHost: "
         "%s\r\n\r\n";
  pid = getpid();
  RAND_add(&pid, sizeof(pid),0.01);
  pid = getpgrp();
  RAND_add(&pid, sizeof(pid),0.01);
  pid = getppid();
  RAND_add(&pid, sizeof(pid),0.01);
  pid = 0;
  gettimeofday(&tv,((void *)0));
  RAND_add(&tv, sizeof(tv),0.1);
  memset(&tv, '\0', sizeof(tv));
  MSN_url_encode(msnPasswd, buf, sizeof(buf)-1);
  encodedPasswd = strdup(buf);
  host = strdup(origHost);
  file = strdup(origFile);
  if(encodedPasswd==((void *)0) || host==((void *)0) || file==((void *)0))
  {
    if(callback!=((void *)0)) callback(-1,_("Cannot allocate memory"));
    return -1;
  }
 printf("MSN LOGIN: %s\n",msnLogin);
 char *escaped_msnLogin = malloc(strlen(msnLogin)*3+1);
 printf("Done!\n");
 memset(escaped_msnLogin,strlen(msnLogin)*3+1,'\0');
 printf("OT OH\n");
 MSN_url_encode(msnLogin, escaped_msnLogin, strlen(msnLogin)*3);
 printf("SPAGHETTIOHS!\n");
  snprintf(request, 2048 -1, requestTemplate, file, escaped_msnLogin, encodedPasswd, idString, host);
 printf("Request: %s\n", request);
  while((r=get_https(host, port, request, buf, sizeof(buf)-1))==-2)
  {
    free(host);
    free(file);
    if((ptr = strstr(buf, "Location:"))==((void *)0))
    {
      printf("No 'Location:' in HTTP header\n");
      return -1;
    }
    ptr[strlen(ptr)-4]=0x0;
    host = split(ptr, '/', 2);
    file = split(ptr, '/', 3);
    if(host==((void *)0) || file==((void *)0))
    {
      printf("Couldn't parse URL\n");
      return -1;
    }
    if((ptr = strstr(file, "\r\n")) != ((void *)0))
      *ptr = 0x0;
    snprintf(request, sizeof(request)-1, requestTemplate,file, escaped_msnLogin, encodedPasswd, idString, host );
  }
  free(host);
  free(file);
  free(encodedPasswd);
  if(r==-1)
  {
    printf("Bad username or password!\n");
    return -1;
  }
  if((ptr=split(buf, '\'',1))==((void *)0))
  {
    printf("Couldn't extract ticket\n");
    return -1;
  }
  strncpy(ticket, ptr, ticketLen);
  free(ptr);
  return 0;
}

variable_types:
origHost
char *

variable_types: port int

variable_types:
origFile
char *

variable_types:
msnLogin
char *

variable_types:
msnPasswd
char *

variable_types:
idString
char *

variable_types:
ticket
char *

variable_types: ticketLen int

variable_types:
callback
void (*)(int, void *)

variable_types: r int

variable_types: pid int

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

variable_types:
buf
char [2048]

variable_types:
request
char [2048]

variable_types:
encodedPasswd
char *

variable_types:
file
char *

variable_types:
requestTemplate
char []


decompiled_code:
char *__fastcall time_format(time_t *timer)
{
char *v1; // rbx
struct tm *v2; // rax

v1 = (char *)malloc(0x10uLL);
*(_QWORD *)v1 = 0LL;
*((_QWORD *)v1 + 1) = 0LL;
v2 = localtime(timer);
sprintf(
v1,
"%d-%02d-%02d %02d:%02d",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday,
(unsigned int)v2->tm_hour,
(unsigned int)v2->tm_min);
return v1;
}

canonical_decompiled_code:
char *__fastcall func1(time_t *timer)
{
char *v1; // rbx
struct tm *v2; // rax

v1 = (char *)malloc(0x10uLL);
*(_QWORD *)v1 = 0LL;
*((_QWORD *)v1 + 1) = 0LL;
v2 = localtime(timer);
sprintf(
v1,
"%d-%02d-%02d %02d:%02d",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday,
(unsigned int)v2->tm_hour,
(unsigned int)v2->tm_min);
return v1;
}

original_code:
extern char *time_format(time_t *mod_time)
{
 char *rtn = malloc(16);
 memset(rtn,'\0',16);
 struct tm *timeinf = localtime(mod_time);
 sprintf(rtn,"%d-%02d-%02d %02d:%02d",1900+timeinf->tm_year,timeinf->tm_mon+1,timeinf->tm_mday,timeinf->tm_hour,timeinf->tm_min);
 return rtn;
}

canonical_original_code:
extern char *time_format(long *mod_time)
{
 char *rtn = malloc(16);
 memset(rtn,'\0',16);
 struct tm *timeinf = localtime(mod_time);
 sprintf(rtn,"%d-%02d-%02d %02d:%02d",1900+timeinf->tm_year,timeinf->tm_mon+1,timeinf->tm_mday,timeinf->tm_hour,timeinf->tm_min);
 return rtn;
}

variable_types:
rtn
char *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *


decompiled_code:
char *__fastcall user_format(__uid_t a1)
{
struct passwd *v1; // rax
char *v2; // rbx

v1 = getpwuid(a1);
if ( v1 )
return strdup(v1->pw_name);
v2 = (char *)malloc(0xAuLL);
*(_QWORD *)v2 = 0LL;
*((_WORD *)v2 + 4) = 0;
sprintf(v2, "%d", a1);
return v2;
}

canonical_decompiled_code:
char *__fastcall func2(__uid_t a1)
{
struct passwd *v1; // rax
char *v2; // rbx

v1 = getpwuid(a1);
if ( v1 )
return strdup(v1->pw_name);
v2 = (char *)malloc(0xAuLL);
*(_QWORD *)v2 = 0LL;
*((_WORD *)v2 + 4) = 0;
sprintf(v2, "%d", a1);
return v2;
}

original_code:
extern char *user_format(int uid)
{
 struct passwd *c_filepass = getpwuid(uid);
 if(c_filepass!=((void *)0))
 {
  return strdup(c_filepass->pw_name);
 }
 else
 {
  char *ret_str = malloc(10);
  memset(ret_str,'\0',10);
  sprintf(ret_str,"%d",uid);
  return ret_str;
 }
}

variable_types: uid int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


decompiled_code:
char *__fastcall group_format(__gid_t a1)
{
struct group *v1; // rax
char *v2; // rbx

v1 = getgrgid(a1);
if ( v1 )
return strdup(v1->gr_name);
v2 = (char *)malloc(0xAuLL);
*(_QWORD *)v2 = 0LL;
*((_WORD *)v2 + 4) = 0;
sprintf(v2, "%d", a1);
return v2;
}

canonical_decompiled_code:
char *__fastcall func3(__gid_t a1)
{
struct group *v1; // rax
char *v2; // rbx

v1 = getgrgid(a1);
if ( v1 )
return strdup(v1->gr_name);
v2 = (char *)malloc(0xAuLL);
*(_QWORD *)v2 = 0LL;
*((_WORD *)v2 + 4) = 0;
sprintf(v2, "%d", a1);
return v2;
}

original_code:
extern char *group_format(int gid)
{
 struct group *c_filegroup = getgrgid(gid);
 if(c_filegroup!=((void *)0))
 {
  return strdup(c_filegroup->gr_name);
 }
 else
 {
  char *ret_str = malloc(10);
  memset(ret_str,'\0',10);
  sprintf(ret_str,"%d",gid);
  return ret_str;
 }
}

variable_types: gid int

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


decompiled_code:
__int64 net_init()
{
unsigned int v0; // ebx
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = socket(2, 2, 0);
optval[0] = 1;
if ( setsockopt(v0, 1, 6, optval, 4u) == -1 )
{
mvprintw(
LINES__NCURSES6_TINFO_5_0_19991023 / 2 - 1,
COLS__NCURSES6_TINFO_5_0_19991023 / 2 - 28,
"Failed to initialise network");
v0 = -1;
}
else
{
udp_sock_dst = 2;
word_4040F2 = _bswap_16(9348);
inet_aton("255.255.255.255", &inp);
}
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // ebx
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = socket(2, 2, 0);
optval[0] = 1;
if ( setsockopt(v0, 1, 6, optval, 4u) == -1 )
{
mvprintw(
LINES__NCURSES6_TINFO_5_0_19991023 / 2 - 1,
COLS__NCURSES6_TINFO_5_0_19991023 / 2 - 28,
"Failed to initialise network");
v0 = -1;
}
else
{
udp_sock_dst = 2;
word_4040F2 = func7(9348);
inet_aton("255.255.255.255", &inp);
}
return v0;
}

original_code:
static int net_init()
{
 int udp_sock = socket(2, SOCK_DGRAM, 0);
 int bc = 1;
 if (setsockopt(udp_sock, 1, 6, &bc, sizeof bc) == -1)
 {
  mvprintw(LINES/2-1,COLS/2-strlen("Failed to initialise Network"),"Failed to initialise network");
  return -1;
 }
 udp_sock_dst.sin_family = 2;
 udp_sock_dst.sin_port = htons(9348);
 inet_aton("255.255.255.255",&(udp_sock_dst.sin_addr));
 return udp_sock;
}

variable_types: bc int


terminate

decompiled_code:
void __noreturn terminate()
{
endwin();
exit(0);
}

canonical_decompiled_code:
void __noreturn func9()
{
endwin();
exit(0);
}

original_code:
static void terminate(int signumber)
{
 endwin();
 exit(0);
}

variable_types: signumber int


decompiled_code:
int __fastcall print_header(char a1)
{
char *v1; // rbx

v1 = (char *)malloc(6uLL);
sprintf(v1, "%%%ds", (unsigned int)COLS__NCURSES6_TINFO_5_0_19991023);
wattr_on(_bss_start, 0x40000uLL, 0LL);
mvprintw(0, 0, v1, " ");
mvprintw(0, 2, "GMU mamo 2.0.6");
mvprintw(0, (COLS__NCURSES6_TINFO_5_0_19991023 - 16) / 2, "File: UDsPlat");
if ( a1 )
mvprintw(0, COLS__NCURSES6_TINFO_5_0_19991023 - 10, "Modified");
wattr_off(_bss_start, 0x40000uLL, 0LL);
return wmove(_bss_start, 1, 0);
}

canonical_decompiled_code:
int __fastcall func10(char a1)
{
char *v1; // rbx

v1 = (char *)malloc(6uLL);
sprintf(v1, "%%%ds", (unsigned int)COLS__NCURSES6_TINFO_5_0_19991023);
wattr_on(_bss_start, 0x40000uLL, 0LL);
mvprintw(0, 0, v1, " ");
mvprintw(0, 2, "GMU mamo 2.0.6");
mvprintw(0, (COLS__NCURSES6_TINFO_5_0_19991023 - 16) / 2, "File: UDsPlat");
if ( a1 )
mvprintw(0, COLS__NCURSES6_TINFO_5_0_19991023 - 10, "Modified");
wattr_off(_bss_start, 0x40000uLL, 0LL);
return wmove(_bss_start, 1, 0);
}

original_code:
void print_header(_Bool modified)
{
 char *print_blank = malloc(6);
 sprintf(print_blank,"%%%ds",COLS);
 wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((10) + 8)))), ((void *)0));
 mvprintw(0,0,print_blank," ");
 mvprintw(0,2,"GMU mamo 2.0.6");
 mvprintw(0,(COLS-16)/2,"File: UDsPlat");
 if(modified==1)
 {
  mvprintw(0,COLS-10, "Modified");
 }
 wattr_off(stdscr, (attr_t)((((chtype)((1U)) << ((10) + 8)))), ((void *)0));
 wmove(stdscr,(1),(0));
}


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

signal(2, (__sighandler_t)terminate);
initscr();
keypad(_bss_start, 1);
nonl();
cbreak();
noecho();
print_header(1);
if ( (unsigned int)net_init() != -1 )
{
do
{
v3 = wgetch(_bss_start);
print_header(1);
wrefresh(_bss_start);
}
while ( v3 != 65 );
terminate();
}
wgetch(_bss_start);
terminate();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

signal(2, (__sighandler_t)terminate);
initscr();
keypad(_bss_start, 1);
nonl();
cbreak();
noecho();
func10(1);
if ( (unsigned int)func8() != -1 )
{
do
{
v3 = wgetch(_bss_start);
func10(1);
wrefresh(_bss_start);
}
while ( v3 != 65 );
func9();
}
wgetch(_bss_start);
func9();
}

original_code:
int main(int argc, char **argv)
{
 signal(2, terminate);
 initscr();
 keypad(stdscr, 1);
 nonl();
 cbreak();
 noecho();
 print_header(1);
 int sock = net_init();
 if(sock==-1)
 {
  wgetch(stdscr);
  terminate(0);
 }
 for(;;)
 {
  int c = wgetch(stdscr);
  print_header(1);
  wrefresh(stdscr);
  if(c == 65)
   break;
 }
 terminate(0);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: sock int

variable_types: c int


decompiled_code:
void __noreturn jump_func()
{
struct __jmp_buf_tag v0; // [rsp+0h] [rbp-D8h] BYREF

_setjmp(&v0);
puts("Here");
longjmp(&v0, 0);
}

canonical_decompiled_code:
void __noreturn func7()
{
struct __jmp_buf_tag v0; // [rsp+0h] [rbp-D8h] BYREF

_setjmp(&v0);
puts("Here");
longjmp(&v0, 0);
}

original_code:
void jump_func()
{
 jmp_buf env;
 int i = 0;
 _setjmp (env);
 printf("Here\n");
 if(i == 0)
 {
  i=1;
  longjmp(env,0);
 }
}

canonical_original_code:
void jump_func()
{
 struct __jmp_buf_tag env[1];
 int i = 0;
 _setjmp (env);
 printf("Here\n");
 if(i == 0)
 {
  i=1;
  longjmp(env,0);
 }
}

variable_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1]

variable_types: i int

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
jump_func(argc, argv, envp);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
func7(argc, argv, envp);
}

original_code:
int main(int argc, char **argv)
{
 jump_func();
 return 0;
}


original_code:
void manip_decompress_init()
{
 int i;
 int is_abs, val, len, unk;
 for (i = 0; i < 256; i++)
 {
  is_abs = 0;
  val = 0;
  len = 0;
  unk = 0;
  if ((i & 0x80) == 0)
  {
   val = 0;
   len = 1;
  }
  else if ((i & 0xE0) == 0x80)
  {
   val = +4;
   len = 3;
  }
  else if ((i & 0xE0) == 0xA0)
  {
   val = -4;
   len = 3;
  }
  else if ((i & 0xF0) == 0xD0)
  {
   val = +11;
   len = 4;
  }
  else if ((i & 0xF0) == 0xF0)
  {
   val = -11;
   len = 4;
  }
  else if ((i & 0xF8) == 0xC8)
  {
   val = +20;
   len = 5;
  }
  else if ((i & 0xFC) == 0xC0)
  {
   val = -20;
   len = 6;
  }
  else if ((i & 0xFC) == 0xC4)
  {
   val = 0;
   len = 8;
   unk = 1;
  }
  else if ((i & 0xF0) == 0xE0)
  {
   is_abs = 1;
   val = (i & 0x0F) << 4;
   len = 8;
  }
  table[i].is_abs = is_abs;
  table[i].val = val;
  table[i].len = len;
  table[i].unk = unk;
 }
}

canonical_original_code:
void manip_decompress_init()
{
 int i;
 int is_abs; int val; int len; int unk;
 for (i = 0; i < 256; i++)
 {
  is_abs = 0;
  val = 0;
  len = 0;
  unk = 0;
  if ((i & 0x80) == 0)
  {
   val = 0;
   len = 1;
  }
  else if ((i & 0xE0) == 0x80)
  {
   val = +4;
   len = 3;
  }
  else if ((i & 0xE0) == 0xA0)
  {
   val = -4;
   len = 3;
  }
  else if ((i & 0xF0) == 0xD0)
  {
   val = +11;
   len = 4;
  }
  else if ((i & 0xF0) == 0xF0)
  {
   val = -11;
   len = 4;
  }
  else if ((i & 0xF8) == 0xC8)
  {
   val = +20;
   len = 5;
  }
  else if ((i & 0xFC) == 0xC0)
  {
   val = -20;
   len = 6;
  }
  else if ((i & 0xFC) == 0xC4)
  {
   val = 0;
   len = 8;
   unk = 1;
  }
  else if ((i & 0xF0) == 0xE0)
  {
   is_abs = 1;
   val = (i & 0x0F) << 4;
   len = 8;
  }
  table[i].is_abs = is_abs;
  table[i].val = val;
  table[i].len = len;
  table[i].unk = unk;
 }
}

variable_types: val int

variable_types: len int

variable_types: unk int


original_code:
int manip_decompress(int width, int height, unsigned char *inp, unsigned char *outp)
{
 int row, col;
 int val;
 int bitpos;
 unsigned char code;
 unsigned char *addr;
 bitpos = 0;
 for (row = 0; row < height; row++)
 {
  col = 0;
  if (row < 2)
  {
   addr = inp + (bitpos >> 3);
   code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7)));
   bitpos += 8;
   *outp++ = code;
   addr = inp + (bitpos >> 3);
   code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7)));
   bitpos += 8;
   *outp++ = code;
   col += 2;
  }
  while (col < width)
  {
   addr = inp + (bitpos >> 3);
   code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7)));
   bitpos += table[code].len;
   val = table[code].val;
   if (!table[code].is_abs)
   {
    if (col < 2)
    {
     val += outp[-2*width];
    }
    else if (row < 2)
    {
     val += outp[-2];
    }
    else
    {
     val += (outp[-2] + outp[-2*width]) / 2;
    }
   }
   *outp++ = ((val)<0?0:((val)>255)?255:(val));
   col++;
  }
 }
 return 0;
}

canonical_original_code:
int manip_decompress(int width, int height, unsigned char *inp, unsigned char *outp)
{
 int row; int col;
 int val;
 int bitpos;
 unsigned char code;
 unsigned char *addr;
 bitpos = 0;
 for (row = 0; row < height; row++)
 {
  col = 0;
  if (row < 2)
  {
   addr = inp + (bitpos >> 3);
   code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7)));
   bitpos += 8;
   *outp++ = code;
   addr = inp + (bitpos >> 3);
   code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7)));
   bitpos += 8;
   *outp++ = code;
   col += 2;
  }
  while (col < width)
  {
   addr = inp + (bitpos >> 3);
   code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7)));
   bitpos += table[code].len;
   val = table[code].val;
   if (!table[code].is_abs)
   {
    if (col < 2)
    {
     val += outp[-2*width];
    }
    else if (row < 2)
    {
     val += outp[-2];
    }
    else
    {
     val += (outp[-2] + outp[-2*width]) / 2;
    }
   }
   *outp++ = ((val)<0?0:((val)>255)?255:(val));
   col++;
  }
 }
 return 0;
}

variable_types: width int

variable_types: height int

variable_types:
inp
unsigned char *

variable_types:
outp
unsigned char *

variable_types: row int

variable_types: col int

variable_types: bitpos int

variable_types:
code
unsigned char

variable_types:
addr
unsigned char *


decompiled_code:
__int64 gtk_vimage_get_type_once()
{
__int64 v0; // rbx
__int64 v1; // rax

v0 = g_intern_static_string("GtkVImage");
v1 = gtk_widget_get_type();
return g_type_register_static_simple(v1, v0, 720LL, gtk_vimage_class_intern_init, 112LL, gtk_vimage_init, 0LL);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
__int64 v1; // rax

v0 = g_intern_static_string("GtkVImage");
v1 = gtk_widget_get_type();
return g_type_register_static_simple(v1, v0, 720LL, gtk_vimage_class_intern_init, 112LL, gtk_vimage_init, 0LL);
}

original_code: __attribute__((noinline)) static GType gtk_vimage_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((gtk_widget_get_type ()), g_intern_static_string ("GtkVImage"), sizeof (GtkVImageClass), (GClassInitFunc)(void (*)(void)) gtk_vimage_class_intern_init, sizeof (GtkVImage), (GInstanceInitFunc)(void (*)(void)) gtk_vimage_init, (GTypeFlags) 0); { {{};} } return g_define_type_id; }

canonical_original_code: static unsigned long gtk_vimage_get_type_once() { unsigned long g_define_type_id = g_type_register_static_simple ((gtk_widget_get_type ()), g_intern_static_string ("GtkVImage"), sizeof (GtkVImageClass), (GClassInitFunc)(void (*)(void)) gtk_vimage_class_intern_init, sizeof (GtkVImage), (GInstanceInitFunc)(void (*)(void)) gtk_vimage_init, (GTypeFlags) 0); { {{};} } return g_define_type_id; }

return_type: unsigned long