main

canonical_name: main

repo: AndoniZubimendi/directfb-render

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
XVisualInfo *v3; // rax
Visual **v4; // rbp
int v5; // er12
Visual *v6; // r15
__int64 v7; // rax
__int64 v8; // rbx
const char *v9; // rsi
Colormap v10; // [rsp+8h] [rbp-2120h]
int v11; // [rsp+10h] [rbp-2118h]
char dest[4096]; // [rsp+20h] [rbp-2108h] BYREF
char s[4096]; // [rsp+1020h] [rbp-1108h] BYREF
XSetWindowAttributes v15; // [rsp+2020h] [rbp-108h] BYREF
int v16; // [rsp+209Ch] [rbp-8Ch] BYREF
XVisualInfo v17; // [rsp+20A0h] [rbp-88h] BYREF

display = XOpenDisplay(0LL);
if ( (unsigned int)XRenderQueryExtension() )
{
v17.screen = display->default_screen;
v17.depth = 32;
v17.c_class = 4;
v3 = XGetVisualInfo(display, 14LL, &v17, &v16);
if ( v16 <= 0 )
{
v8 = 0LL;
v6 = 0LL;
v10 = 0LL;
}
else
{
v4 = &v3->visual;
v5 = 0;
v11 = 0;
v6 = 0LL;
v10 = 0LL;
do
{
v7 = XRenderFindVisualFormat();
v8 = v7;
if ( *(_DWORD *)(v7 + 8) == 1 && *(_WORD *)(v7 + 30) )
{
v6 = *v4;
v10 = XCreateColormap(display, display->screens[(__int64)display->default_screen].root, *v4, 0);
v11 = 1;
}
++v5;
v4 += 8;
}
while ( v16 > v5 );
if ( v11 )
puts("ARGB Visual found.");
}
printf("Depth: %i\n", *(unsigned int *)(v8 + 12));
screen = display->default_screen;
root = display->screens[(__int64)screen].root;
v15.background_pixel = XBlackPixel(display, screen);
v15.border_pixel = XBlackPixel(display, screen);
v15.colormap = v10;
window = XCreateWindow(display, root, 0, 0, 0x2D0u, 0x240u, 0, *(_DWORD *)(v8 + 12), 1u, v6, 0x200AuLL, &v15);
printf("Window Id: 0x%lx\n", window);
XMapWindow(display, window);
XSync(display, window);
XSelectInput(display, window, 163847LL);
v9 = "main.ncl";
if ( argc > 1 )
v9 = argv[1];
strcpy(dest, v9);
sprintf(s, "DIRECTFB_WINDOWID=0x%lx ginga --ncl %s", window, dest);
printf("Lanzamos Ginga con el siguiente comando: %s\n", s);
system(s);
while ( 1 )
XNextEvent(display, &event);
}
fwrite("RENDER extension missing!\n", 1uLL, 0x1AuLL, stderr);
abort();
}

original_code:
int main(int argc, char *argv[])
{
 display=XOpenDisplay(((void *)0));
 Colormap colormap = 0;
 Visual *visual = 0;
 int render_event_base, render_error_base;
 int render_present=XRenderQueryExtension(display, &render_event_base, &render_error_base);
 if (!render_present) {
  fprintf(stderr, "RENDER extension missing!\n");
  abort();
 }
 XVisualInfo templ;
 int nvi;
 templ.screen = (((_XPrivDisplay)(display))->default_screen);
 templ.depth = 32;
 templ.class = 4;
 XVisualInfo *xvi = XGetVisualInfo(display, 0x2 | 0x4 | 0x8, &templ, &nvi );
 int argbVisual = 0;
 XRenderPictFormat *fmt= 0;
 int i;
 for (i = 0;i < nvi; ++i) {
  fmt=XRenderFindVisualFormat(display, xvi[i].visual);
  if (fmt->type == 1 && fmt->direct.alphaMask) {
   visual = xvi[i].visual;
   colormap = XCreateColormap(display, ((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay)(display))->default_screen)])->root), visual, 0);
   argbVisual = 1;
  }
 }
 if (argbVisual) {
  printf("ARGB Visual found.\n");
 }
 printf("Depth: %i\n", fmt->depth);
 screen=(((_XPrivDisplay)(display))->default_screen);
 root=((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay)(display))->default_screen)])->root);
 int x_pos = 0;
 int y_pos = 0;
 int width = 720;
 int height = 576;
 int border_width = 0;
  XSetWindowAttributes winattr;
  winattr.background_pixel = XBlackPixel(display, screen);
  winattr.border_pixel = XBlackPixel(display, screen);
  winattr.colormap = colormap;
  long unsigned int winattr_mask = 0;
  winattr_mask |= (1L<<1);
  winattr_mask |= (1L<<3);
  winattr_mask |= (1L<<13);
 window=XCreateWindow(display, root, x_pos, y_pos,
     width, height, border_width,
  fmt->depth, 1,
  visual, winattr_mask, &winattr);
 printf("Window Id: 0x%lx\n", window);
 XMapWindow(display, window);
 XSync(display, window);
 XSelectInput(display, window, (1L<<0)|(1L<<1)|(1L<<15)
  |(1L<<2)|(1L<<17));
 char cmdGinga[4096];
 char nclApp[4096];
 strcpy(nclApp, ((argc>1)?argv[1]:"main.ncl"));
 sprintf(cmdGinga, "DIRECTFB_WINDOWID=0x%lx ginga --ncl %s", window, nclApp);
 printf("Lanzamos Ginga con el siguiente comando: %s\n", cmdGinga);
 system(cmdGinga);
 while(1) {
  XNextEvent(display, &event);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 display=XOpenDisplay(((void *)0));
 unsigned long colormap = 0;
 struct Visual *visual = 0;
 int render_event_base; int render_error_base;
 int render_present = XRenderQueryExtension(display, &render_event_base, &render_error_base);
 if (!render_present) {
  fprintf(stderr, "RENDER extension missing!\n");
  abort();
 }
 struct XVisualInfo templ;
 int nvi;
 templ.screen = (((_XPrivDisplay)(display))->default_screen);
 templ.depth = 32;
 templ.class = 4;
 struct XVisualInfo *xvi = XGetVisualInfo(display, 0x2 | 0x4 | 0x8, &templ, &nvi );
 int argbVisual = 0;
 struct XRenderPictFormat *fmt = 0;
 int i;
 for (i = 0;i < nvi; ++i) {
  fmt=XRenderFindVisualFormat(display, xvi[i].visual);
  if (fmt->type == 1 && fmt->direct.alphaMask) {
   visual = xvi[i].visual;
   colormap = XCreateColormap(display, ((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay)(display))->default_screen)])->root), visual, 0);
   argbVisual = 1;
  }
 }
 if (argbVisual) {
  printf("ARGB Visual found.\n");
 }
 printf("Depth: %i\n", fmt->depth);
 screen=(((_XPrivDisplay)(display))->default_screen);
 root=((&((_XPrivDisplay)(display))->screens[(((_XPrivDisplay)(display))->default_screen)])->root);
 int x_pos = 0;
 int y_pos = 0;
 int width = 720;
 int height = 576;
 int border_width = 0;
  struct XSetWindowAttributes winattr;
  winattr.background_pixel = XBlackPixel(display, screen);
  winattr.border_pixel = XBlackPixel(display, screen);
  winattr.colormap = colormap;
  unsigned long winattr_mask = 0;
  winattr_mask |= (1L<<1);
  winattr_mask |= (1L<<3);
  winattr_mask |= (1L<<13);
 window=XCreateWindow(display, root, x_pos, y_pos,
     width, height, border_width,
  fmt->depth, 1,
  visual, winattr_mask, &winattr);
 printf("Window Id: 0x%lx\n", window);
 XMapWindow(display, window);
 XSync(display, window);
 XSelectInput(display, window, (1L<<0)|(1L<<1)|(1L<<15)
  |(1L<<2)|(1L<<17));
 char cmdGinga[4096];
 char nclApp[4096];
 strcpy(nclApp, ((argc>1)?argv[1]:"main.ncl"));
 sprintf(cmdGinga, "DIRECTFB_WINDOWID=0x%lx ginga --ncl %s", window, nclApp);
 printf("Lanzamos Ginga con el siguiente comando: %s\n", cmdGinga);
 system(cmdGinga);
 while(1) {
  XNextEvent(display, &event);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
colormap
unsigned long

variable_types: nvi int

variable_types: struct XVisualInfo { struct Visual { struct _XExtData { int number; struct _XExtData *next; int (*free_private)(struct _XExtData *extension); char *private_data; } *ext_data; unsigned long visualid; int class; unsigned long red_mask; int bits_per_rgb; int map_entries; } *visual; unsigned long visualid; int screen; int depth; int class; unsigned long red_mask; unsigned long green_mask; unsigned long blue_mask; int colormap_size; int bits_per_rgb; } *

variable_types: argbVisual int

variable_types: struct XRenderPictFormat { unsigned long id; int type; int depth; struct XRenderDirectFormat { short red; short redMask; short green; short greenMask; short blue; short blueMask; short alpha; short alphaMask; } direct; unsigned long colormap; } *

variable_types: i int

variable_types: width int

variable_types: height int

variable_types: struct XSetWindowAttributes { unsigned long background_pixmap; unsigned long background_pixel; unsigned long border_pixmap; unsigned long border_pixel; int bit_gravity; int win_gravity; int backing_store; unsigned long backing_planes; unsigned long backing_pixel; int save_under; long event_mask; long do_not_propagate_mask; int override_redirect; unsigned long colormap; unsigned long cursor; }

variable_types:
cmdGinga
char [4096]

variable_types:
nclApp
char [4096]

user_defined_types: struct XVisualInfo { struct Visual *visual; unsigned long visualid; int screen; int depth; int class; unsigned long red_mask; unsigned long green_mask; unsigned long blue_mask; int colormap_size; int bits_per_rgb; }

user_defined_types: struct Visual { struct _XExtData *ext_data; unsigned long visualid; int class; unsigned long red_mask; int bits_per_rgb; int map_entries; }

user_defined_types: struct XRenderPictFormat { unsigned long id; int type; int depth; struct XRenderDirectFormat direct; unsigned long colormap; }


vpsmemPoolDataSize

decompiled_code:
__int64 vpsmemPoolDataSize()
{
return 32LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 32LL;
}

original_code:
static int
vpsmemPoolDataSize( void )
{
     return sizeof(VPSMemPoolData);
}

canonical_original_code:
static int vpsmemPoolDataSize()
{
     return sizeof(VPSMemPoolData);
}

return_type: int


vpsmemPoolLocalDataSize

decompiled_code:
__int64 vpsmemPoolLocalDataSize()
{
return 16LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 16LL;
}

original_code:
static int
vpsmemPoolLocalDataSize( void )
{
     return sizeof(VPSMemPoolLocalData);
}

canonical_original_code:
static int vpsmemPoolLocalDataSize()
{
     return sizeof(VPSMemPoolLocalData);
}


vpsmemAllocationDataSize

decompiled_code:
__int64 vpsmemAllocationDataSize()
{
return 24LL;
}

canonical_decompiled_code:
__int64 func2()
{
return 24LL;
}

original_code:
static int
vpsmemAllocationDataSize( void )
{
     return sizeof(VPSMemAllocationData);
}

canonical_original_code:
static int vpsmemAllocationDataSize()
{
     return sizeof(VPSMemAllocationData);
}


decompiled_code:
__int64 __fastcall direct_util_align(signed int a1, int a2)
{
int v2; // edx
int v3; // esi

if ( a2 > 1 )
{
v2 = a1 % a2;
v3 = a1 + a2 - a1 % a2;
if ( v2 )
a1 = v3;
}
return (unsigned int)a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(signed int a1, int a2)
{
int v2; // edx
int v3; // esi

if ( a2 > 1 )
{
v2 = a1 % a2;
v3 = a1 + a2 - a1 % a2;
if ( v2 )
a1 = v3;
}
return (unsigned int)a1;
}

original_code:
static inline int
direct_util_align( int value,
                   int alignment )
{
     if (alignment > 1) {
          int tail = value % alignment;
          if (tail)
               value += alignment - tail;
     }
     return value;
}

canonical_original_code:
static inline int direct_util_align(int value, int alignment)
{
     if (alignment > 1) {
          int tail = value % alignment;
          if (tail)
               value += alignment - tail;
     }
     return value;
}

variable_types: value int

variable_types: alignment int

variable_types: tail int


check

repo: AndrewBelt/RMSTalk

decompiled_code:
void *check(char a1, const char *a2, ...)
{
void *result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = arg[0].reg_save_area;
if ( !a1 )
{
if ( a2 )
{
vfprintf(stderr, a2, arg);
fputc(10, stderr);
}
abort();
}
return result;
}

canonical_decompiled_code:
void *func7(char a1, const char *a2, ...)
{
void *result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = arg[0].reg_save_area;
if ( !a1 )
{
if ( a2 )
{
vfprintf(stderr, a2, arg);
fputc(10, stderr);
}
abort();
}
return result;
}

original_code:
void check(_Bool success, const char *err_format, ...)
{
 va_list vl;
 __builtin_va_start(vl,err_format);
 if (!success)
 {
  if (err_format)
  {
   vfprintf(stderr, err_format, vl);
   fprintf(stderr, "\n");
  }
  abort();
 }
 __builtin_va_end(vl);
}

canonical_original_code:
void check(_Bool success, char *err_format, ...)
{
 __builtin_va_list vl;
 __builtin_va_start(vl,err_format);
 if (!success)
 {
  if (err_format)
  {
   vfprintf(stderr, err_format, vl);
   fprintf(stderr, "\n");
  }
  abort();
 }
 __builtin_va_end(vl);
}

return_type: void


main

repo: AndrewBelt/pandemic

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

world_init(argc, argv, envp);
model_init();
v3 = 256;
do
{
putchar(46);
fflush(stdout);
world_step();
--v3;
}
while ( v3 );
putchar(10);
field_save_png(fields[0], "output/elevation.png", -490.0, 2500.0);
field_save_png(fields[1], "output/prey_population.png", 0.0, 1.0);
field_save_png(fields[2], "output/predator_population.png", 0.0, 1.0);
world_destroy();
return 0;
}

original_code:
int main(int argc, const char **argv)
{
 world_init();
 model_init();
 for (int i = 0; i < 256; i++)
 {
  printf(".");
  fflush(stdout);
  world_step();
 }
 printf("\n");
 field_save_png(fields[ELEVATION],
  "output/elevation.png", -490, 2500);
 field_save_png(fields[PREY_POPULATION],
  "output/prey_population.png", 0.0, 1.0);
 field_save_png(fields[PREDATOR_POPULATION],
  "output/predator_population.png", 0.0, 1.0);
 world_destroy();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 world_init();
 model_init();
 for (int i = 0; i < 256; i++)
 {
  printf(".");
  fflush(stdout);
  world_step();
 }
 printf("\n");
 field_save_png(fields[ELEVATION],
  "output/elevation.png", -490, 2500);
 field_save_png(fields[PREY_POPULATION],
  "output/prey_population.png", 0.0, 1.0);
 field_save_png(fields[PREDATOR_POPULATION],
  "output/predator_population.png", 0.0, 1.0);
 world_destroy();
 return 0;
}

variable_types:
argv
char **


decompiled_code:
float __fastcall field_get(__int64 a1, int a2, int a3)
{
return *(float *)(a1 + 4LL * (a2 + (a3 << 10)));
}

canonical_decompiled_code:
float __fastcall func0(__int64 a1, int a2, int a3)
{
return *(float *)(a1 + 4LL * (a2 + (a3 << 10)));
}

original_code:
static inline float field_get(const float *field, int x, int y)
{
 return field[x + 1024 * y];
}

canonical_original_code:
static inline float field_get(float *field, int x, int y)
{
 return field[x + 1024 * y];
}

variable_types:
field
float *

variable_types: x int

variable_types: y int

return_type: float


decompiled_code:
bool __fastcall land_boundary(unsigned int a1, unsigned int a2)
{
return field_get_safe(fields, a1, a2) > -490.0;
}

canonical_decompiled_code:
bool __fastcall func2(unsigned int a1, unsigned int a2)
{
return field_get_safe(fields, a1, a2) > -490.0;
}

original_code:
_Bool land_boundary(int x, int y)
{
 return field_get_safe(fields[ELEVATION], x, y) > -490.0f;
}


decompiled_code:
float __fastcall prey_callback(unsigned int a1, unsigned int a2)
{
__int64 v2; // r12
float v4; // [rsp+8h] [rbp-20h]
float v5; // [rsp+Ch] [rbp-1Ch]

v2 = fields[1];
v4 = field_get(v2, a1, a2);
v5 = field_laplacian_boundary(v2, a1, a2, land_boundary);
return (float)((float)((float)((float)((float)(v4 + v4) * (float)(1.0 - v4)) + (float)(v5 + v5))
- (float)((float)(v4 * 4.0) * field_get(fields[2], a1, a2)))
* 0.1)
+ v4;
}

canonical_decompiled_code:
float __fastcall func3(unsigned int a1, unsigned int a2)
{
__int64 v2; // r12
float v4; // [rsp+8h] [rbp-20h]
float v5; // [rsp+Ch] [rbp-1Ch]

v2 = fields[1];
v4 = func0(v2, a1, a2);
v5 = field_laplacian_boundary(v2, a1, a2, land_boundary);
return (float)((float)((float)((float)((float)(v4 + v4) * (float)(1.0 - v4)) + (float)(v5 + v5))
- (float)((float)(v4 * 4.0) * func0(fields[2], a1, a2)))
* 0.1)
+ v4;
}

original_code:
float prey_callback(int x, int y)
{
 static const float difn_alpha = 2.0f;
 static const float growth_rate = 2.0f;
 static const float carrying_capacity = 1.0f;
 static const float predator_beta = 4.0f;
 float u = field_get(fields[PREY_POPULATION], x, y);
 float lapl_u = field_laplacian_boundary(fields[PREY_POPULATION],
  x, y, land_boundary);
 float v = field_get(fields[PREDATOR_POPULATION], x, y);
 float D_u = difn_alpha * lapl_u +
  growth_rate * u * (1.0f - u / carrying_capacity) -
  predator_beta * u * v;
 return u + 0.1f * D_u;
}

canonical_original_code:
float prey_callback(int x, int y)
{
 static float difn_alpha = 2.0f;
 static float growth_rate = 2.0f;
 static float carrying_capacity = 1.0f;
 static float predator_beta = 4.0f;
 float u = field_get(fields[PREY_POPULATION], x, y);
 float lapl_u = field_laplacian_boundary(fields[PREY_POPULATION],
  x, y, land_boundary);
 float v = field_get(fields[PREDATOR_POPULATION], x, y);
 float D_u = difn_alpha * lapl_u +
  growth_rate * u * (1.0f - u / carrying_capacity) -
  predator_beta * u * v;
 return u + 0.1f * D_u;
}

variable_types: u float

variable_types: v float


decompiled_code:
float __fastcall predator_callback(unsigned int a1, unsigned int a2)
{
__int64 v2; // r12
float v4; // [rsp+8h] [rbp-20h]
float v5; // [rsp+Ch] [rbp-1Ch]

v2 = fields[2];
v4 = field_get(v2, a1, a2);
v5 = field_laplacian(v2, a1, a2);
return (float)((float)((float)((float)((float)(v4 * -0.1) * (float)(1.0 - v4)) + v5)
+ (float)(field_get(fields[1], a1, a2) * v4))
* 0.1)
+ v4;
}

canonical_decompiled_code:
float __fastcall func4(unsigned int a1, unsigned int a2)
{
__int64 v2; // r12
float v4; // [rsp+8h] [rbp-20h]
float v5; // [rsp+Ch] [rbp-1Ch]

v2 = fields[2];
v4 = func0(v2, a1, a2);
v5 = field_laplacian(v2, a1, a2);
return (float)((float)((float)((float)((float)(v4 * -0.1) * (float)(1.0 - v4)) + v5)
+ (float)(func0(fields[1], a1, a2) * v4))
* 0.1)
+ v4;
}

original_code:
float predator_callback(int x, int y)
{
 static const float difn_alpha = 1.0f;
 static const float growth_rate = -0.1f;
 static const float carrying_capacity = 1.0f;
 static const float prey_beta = 1.0f;
 float u = field_get(fields[PREDATOR_POPULATION], x, y);
 float lapl_u = field_laplacian(fields[PREDATOR_POPULATION], x, y);
 float v = field_get(fields[PREY_POPULATION], x, y);
 float D_u = difn_alpha * lapl_u +
  growth_rate * u * (1.0f - u / carrying_capacity) +
  prey_beta * u * v;
 return u + 0.1f * D_u;
}

canonical_original_code:
float predator_callback(int x, int y)
{
 static float difn_alpha = 1.0f;
 static float growth_rate = -0.1f;
 static float carrying_capacity = 1.0f;
 static float prey_beta = 1.0f;
 float u = field_get(fields[PREDATOR_POPULATION], x, y);
 float lapl_u = field_laplacian(fields[PREDATOR_POPULATION], x, y);
 float v = field_get(fields[PREY_POPULATION], x, y);
 float D_u = difn_alpha * lapl_u +
  growth_rate * u * (1.0f - u / carrying_capacity) +
  prey_beta * u * v;
 return u + 0.1f * D_u;
}


decompiled_code:
void model_init()
{
unsigned int v0; // eax
int v1; // ebx
int v2; // ebp
int v3; // eax
int v4; // ebp
int v5; // eax

field_callbacks[0] = 0LL;
field_callbacks[1] = (__int64)prey_callback;
field_callbacks[2] = (__int64)predator_callback;
v0 = time(0LL);
srand(v0);
field_load(fields[0], "fields/elevation.bin");
v1 = 20;
do
{
v2 = rand();
v3 = rand();
field_set(fields[1], v3 % 1024, v2 % 512, 1.0);
v4 = rand();
v5 = rand();
field_set(fields[2], v5 % 1024, v4 % 512, 1.0);
--v1;
}
while ( v1 );
}

canonical_decompiled_code:
void func5()
{
unsigned int v0; // eax
int v1; // ebx
int v2; // ebp
int v3; // eax
int v4; // ebp
int v5; // eax

field_callbacks[0] = 0LL;
field_callbacks[1] = (__int64)prey_callback;
field_callbacks[2] = (__int64)predator_callback;
v0 = time(0LL);
srand(v0);
field_load(fields[0], "fields/elevation.bin");
v1 = 20;
do
{
v2 = rand();
v3 = rand();
func1(fields[1], v3 % 1024, v2 % 512, 1.0);
v4 = rand();
v5 = rand();
func1(fields[2], v5 % 1024, v4 % 512, 1.0);
--v1;
}
while ( v1 );
}

original_code:
void model_init()
{
 field_callbacks[ELEVATION] = ((void *)0);
 field_callbacks[PREY_POPULATION] = prey_callback;
 field_callbacks[PREDATOR_POPULATION] = predator_callback;
 srand(time(((void *)0)));
 field_load(fields[ELEVATION], "fields/elevation.bin");
 for (int i = 0; i < 20; i++)
 {
  field_set(fields[PREY_POPULATION],
   rand() % 1024, rand() % 512, 1.0f);
  field_set(fields[PREDATOR_POPULATION],
   rand() % 1024, rand() % 512, 1.0f);
 }
}


decompiled_code:
void __fastcall field_set(__int64 a1, int a2, int a3, float a4)
{
*(float *)(a1 + 4LL * (a2 + (a3 << 10))) = a4;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2, int a3, float a4)
{
*(float *)(a1 + 4LL * (a2 + (a3 << 10))) = a4;
}

original_code:
static inline void field_set(float *field, int x, int y, float value)
{
 field[x + 1024 * y] = value;
}

variable_types: value float


decompiled_code:
void *field_create()
{
return calloc(0x80000uLL, 4uLL);
}

canonical_decompiled_code:
void *func2()
{
return calloc(0x80000uLL, 4uLL);
}

original_code:
float *field_create()
{
 return calloc(1024 * 512, sizeof(float));
}

return_type: float *


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

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

original_code:
void field_destroy(float *field)
{
 free(field);
}


decompiled_code:
float __fastcall field_get_safe(__int64 a1, __int16 a2, __int16 a3)
{
return field_get(a1, a2 & 0x3FF, a3 & 0x1FF);
}

canonical_decompiled_code:
float __fastcall func6(__int64 a1, __int16 a2, __int16 a3)
{
return func0(a1, a2 & 0x3FF, a3 & 0x1FF);
}

original_code:
float field_get_safe(const float *field, int x, int y)
{
 x &= 1024 - 1;
 y &= 512 - 1;
 return field_get(field, x, y);
}

canonical_original_code:
float field_get_safe(float *field, int x, int y)
{
 x &= 1024 - 1;
 y &= 512 - 1;
 return field_get(field, x, y);
}


decompiled_code:
void __fastcall field_set_safe(__int64 a1, __int16 a2, __int16 a3, float a4)
{
field_set(a1, a2 & 0x3FF, a3 & 0x1FF, a4);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, __int16 a2, __int16 a3, float a4)
{
func1(a1, a2 & 0x3FF, a3 & 0x1FF, a4);
}

original_code:
void field_set_safe(float *field, int x, int y, float value)
{
 x &= 1024 - 1;
 y &= 512 - 1;
 field_set(field, x, y, value);
}


decompiled_code:
float __fastcall field_laplacian(__int64 a1, int a2, int a3)
{
float v4; // xmm0_4
float v6; // [rsp+0h] [rbp-28h]
float v7; // [rsp+4h] [rbp-24h]
float v8; // [rsp+8h] [rbp-20h]
float v9; // [rsp+Ch] [rbp-1Ch]

v6 = field_get_safe(a1, a2 - 1, a3);
v7 = field_get_safe(a1, a2 + 1, a3);
v8 = field_get_safe(a1, a2, a3 - 1);
v9 = field_get_safe(a1, a2, a3 + 1);
v4 = field_get(a1, a2, a3);
return (float)((float)(v6 - (float)(v4 + v4)) + v7) + (float)((float)(v8 - (float)(v4 + v4)) + v9);
}

canonical_decompiled_code:
float __fastcall func8(__int64 a1, int a2, int a3)
{
float v4; // xmm0_4
float v6; // [rsp+0h] [rbp-28h]
float v7; // [rsp+4h] [rbp-24h]
float v8; // [rsp+8h] [rbp-20h]
float v9; // [rsp+Ch] [rbp-1Ch]

v6 = func6(a1, a2 - 1, a3);
v7 = func6(a1, a2 + 1, a3);
v8 = func6(a1, a2, a3 - 1);
v9 = func6(a1, a2, a3 + 1);
v4 = func0(a1, a2, a3);
return (float)((float)(v6 - (float)(v4 + v4)) + v7) + (float)((float)(v8 - (float)(v4 + v4)) + v9);
}

original_code:
float field_laplacian(const float *field, int x, int y)
{
 float west = field_get_safe(field, x - 1, y);
 float east = field_get_safe(field, x + 1, y);
 float north = field_get_safe(field, x, y - 1);
 float south = field_get_safe(field, x, y + 1);
 float u = field_get(field, x, y);
 return (west - 2 * u + east) / (1.0f * 1.0f) +
  (north - 2 * u + south) / (1.0f * 1.0f);
}

canonical_original_code:
float field_laplacian(float *field, int x, int y)
{
 float west = field_get_safe(field, x - 1, y);
 float east = field_get_safe(field, x + 1, y);
 float north = field_get_safe(field, x, y - 1);
 float south = field_get_safe(field, x, y + 1);
 float u = field_get(field, x, y);
 return (west - 2 * u + east) / (1.0f * 1.0f) +
  (north - 2 * u + south) / (1.0f * 1.0f);
}

variable_types: west float

variable_types: east float

variable_types: north float

variable_types: south float


decompiled_code:
float __fastcall field_laplacian_boundary(__int64 a1, unsigned int a2, unsigned int a3, __int64 (__fastcall *a4)(_QWORD, _QWORD, double))
{
float result; // xmm0_4
char v7; // r12
float v8; // xmm2_4
float v9; // xmm0_4
float v10; // xmm1_4
char v11; // [rsp+9h] [rbp-4Fh]
char v12; // [rsp+Ah] [rbp-4Eh]
char v13; // [rsp+Bh] [rbp-4Dh]
float v14; // [rsp+Ch] [rbp-4Ch]
float v15; // [rsp+14h] [rbp-44h]
float v16; // [rsp+18h] [rbp-40h]
float v17; // [rsp+1Ch] [rbp-3Ch]

result = 0.0;
if ( ((unsigned __int8 (__fastcall *)(_QWORD, _QWORD))a4)(a2, a3) )
{
v11 = a4(a2 - 1, a3, 0.0);
v12 = ((__int64 (__fastcall *)(_QWORD, _QWORD))a4)(a2 + 1, a3);
v13 = ((__int64 (__fastcall *)(_QWORD, _QWORD))a4)(a2, a3 - 1);
v7 = ((__int64 (__fastcall *)(_QWORD, _QWORD))a4)(a2, a3 + 1);
v16 = field_get_safe(a1, a2 - 1, a3);
v15 = field_get_safe(a1, a2 + 1, a3);
v17 = field_get_safe(a1, a2, a3 - 1);
v14 = field_get_safe(a1, a2, a3 + 1);
v8 = field_get(a1, a2, a3) * -2.0;
if ( v11 && v12 )
{
v9 = (float)(v16 + v15) + v8;
}
else if ( v12 )
{
v9 = (float)(v15 + v15) + v8;
}
else
{
v9 = 0.0;
if ( v11 )
v9 = (float)(v16 + v16) + v8;
}
if ( v13 && v7 )
{
v10 = (float)(v17 + v14) + v8;
}
else if ( v7 )
{
v10 = (float)(v14 + v14) + v8;
}
else
{
v10 = 0.0;
if ( v13 )
v10 = (float)(v17 + v17) + v8;
}
result = v9 + v10;
}
return result;
}

original_code:
float field_laplacian_boundary(const float *field, int x, int y,
 boundary_callback bc)
{
 if (!(*bc)(x, y))
  return 0.0f;
 _Bool has_west = (*bc)(x - 1, y);
 _Bool has_east = (*bc)(x + 1, y);
 _Bool has_north = (*bc)(x, y - 1);
 _Bool has_south = (*bc)(x, y + 1);
 float west = field_get_safe(field, x - 1, y);
 float east = field_get_safe(field, x + 1, y);
 float north = field_get_safe(field, x, y - 1);
 float south = field_get_safe(field, x, y + 1);
 float ddx = -2 * field_get(field, x, y);
 float ddy = ddx;
 if (has_west && has_east)
 {
  ddx += west + east;
 }
 else if (has_east)
 {
  ddx += 2 * east;
 }
 else if (has_west)
 {
  ddx += 2 * west;
 }
 else
 {
  ddx = 0;
 }
 if (has_north && has_south)
 {
  ddy += north + south;
 }
 else if (has_south)
 {
  ddy += 2 * south;
 }
 else if (has_north)
 {
  ddy += 2 * north;
 }
 else
 {
  ddy = 0;
 }
 return ddx / (1.0f * 1.0f) + ddy / (1.0f * 1.0f);
}

canonical_original_code:
float field_laplacian_boundary(float *field, int x, int y, _Bool (*bc)(int x, int y))
{
 if (!(*bc)(x, y))
  return 0.0f;
 _Bool has_west = (*bc)(x - 1, y);
 _Bool has_east = (*bc)(x + 1, y);
 _Bool has_north = (*bc)(x, y - 1);
 _Bool has_south = (*bc)(x, y + 1);
 float west = field_get_safe(field, x - 1, y);
 float east = field_get_safe(field, x + 1, y);
 float north = field_get_safe(field, x, y - 1);
 float south = field_get_safe(field, x, y + 1);
 float ddx = -2 * field_get(field, x, y);
 float ddy = ddx;
 if (has_west && has_east)
 {
  ddx += west + east;
 }
 else if (has_east)
 {
  ddx += 2 * east;
 }
 else if (has_west)
 {
  ddx += 2 * west;
 }
 else
 {
  ddx = 0;
 }
 if (has_north && has_south)
 {
  ddy += north + south;
 }
 else if (has_south)
 {
  ddy += 2 * south;
 }
 else if (has_north)
 {
  ddy += 2 * north;
 }
 else
 {
  ddy = 0;
 }
 return ddx / (1.0f * 1.0f) + ddy / (1.0f * 1.0f);
}

variable_types:
bc
_Bool (*)(int x, int y)

variable_types: ddx float

variable_types: ddy float


decompiled_code:
int __fastcall field_print(__int64 a1)
{
int i; // ebp
int j; // ebx
float v3; // xmm0_4
int result; // eax

for ( i = 0; i != 512; ++i )
{
for ( j = 0; j != 1024; ++j )
{
v3 = field_get(a1, j, i);
printf("%6.2f ", v3);
}
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
int i; // ebp
int j; // ebx
float v3; // xmm0_4
int result; // eax

for ( i = 0; i != 512; ++i )
{
for ( j = 0; j != 1024; ++j )
{
v3 = func0(a1, j, i);
printf("%6.2f ", v3);
}
result = putchar(10);
}
return result;
}

original_code:
void field_print(const float *field)
{
 for (int y = 0; y < 512; y++)
 {
  for (int x = 0; x < 1024; x++)
  {
   printf("%6.2f ", field_get(field, x, y));
  }
  printf("\n");
 }
}

canonical_original_code:
void field_print(float *field)
{
 for (int y = 0; y < 512; y++)
 {
  for (int x = 0; x < 1024; x++)
  {
   printf("%6.2f ", field_get(field, x, y));
  }
  printf("\n");
 }
}


decompiled_code:
float *__fastcall field_sum(float *a1)
{
float *result; // rax
float v2; // xmm0_4

result = a1 + 0x80000;
v2 = 0.0;
do
v2 = v2 + *a1++;
while ( a1 != result );
return result;
}

canonical_decompiled_code:
float *__fastcall func11(float *a1)
{
float *result; // rax
float v2; // xmm0_4

result = a1 + 0x80000;
v2 = 0.0;
do
v2 = v2 + *a1++;
while ( a1 != result );
return result;
}

original_code:
float field_sum(const float *field)
{
 float sum = 0.0f;
 for (int i = 0; i < 1024 * 512; i++)
 {
  sum += field[i];
 }
 return sum;
}

canonical_original_code:
float field_sum(float *field)
{
 float sum = 0.0f;
 for (int i = 0; i < 1024 * 512; i++)
 {
  sum += field[i];
 }
 return sum;
}

variable_types: sum float

variable_types: i int


canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, int a3, float a4)
{
*(float *)(a1 + 4LL * (a2 + (a3 << 10))) = a4;
}

canonical_original_code:
static inline void field_set(float *field, int x, int y, float value)
{
 field[x + 1024 * y] = value;
}


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

fields[0] = field_create();
fields[1] = field_create();
result = field_create();
fields[2] = result;
return result;
}

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

fields[0] = field_create();
fields[1] = field_create();
result = field_create();
fields[2] = result;
return result;
}

original_code:
void world_init()
{
 for (int i = 0; i < FIELD_TYPE_LENGTH; i++)
 {
  fields[i] = field_create();
 }
}


decompiled_code:
__int64 world_destroy()
{
field_destroy(fields[0]);
field_destroy(fields[1]);
return field_destroy(fields[2]);
}

canonical_decompiled_code:
__int64 func2()
{
field_destroy(fields[0]);
field_destroy(fields[1]);
return field_destroy(fields[2]);
}

original_code:
void world_destroy()
{
 for (int i = 0; i < FIELD_TYPE_LENGTH; i++)
 {
  field_destroy(fields[i]);
 }
}


decompiled_code:
void world_step()
{
__int64 i; // r12
__int64 v1; // r13
unsigned int j; // ebp
unsigned int k; // ebx
float v4; // xmm0_4

for ( i = 0LL; i != 3; ++i )
{
if ( field_callbacks[i] )
{
v1 = field_create();
for ( j = 0; j != 512; ++j )
{
for ( k = 0; k != 1024; ++k )
{
v4 = ((float (__fastcall *)(_QWORD, _QWORD))field_callbacks[i])(k, j);
field_set(v1, k, j, v4);
}
}
field_destroy(fields[i]);
fields[i] = v1;
}
}
}

canonical_decompiled_code:
void func3()
{
__int64 i; // r12
__int64 v1; // r13
unsigned int j; // ebp
unsigned int k; // ebx
float v4; // xmm0_4

for ( i = 0LL; i != 3; ++i )
{
if ( field_callbacks[i] )
{
v1 = field_create();
for ( j = 0; j != 512; ++j )
{
for ( k = 0; k != 1024; ++k )
{
v4 = ((float (__fastcall *)(_QWORD, _QWORD))field_callbacks[i])(k, j);
func0(v1, k, j, v4);
}
}
field_destroy(fields[i]);
fields[i] = v1;
}
}
}

original_code:
void world_step()
{
 for (int i = 0; i < FIELD_TYPE_LENGTH; i++)
 {
  if (field_callbacks[i])
  {
   float *new_field = field_create();
   for (int y = 0; y < 512; y++)
   {
    for (int x = 0; x < 1024; x++)
    {
     float u = (*field_callbacks[i])(x, y);
     field_set(new_field, x, y, u);
    }
   }
   field_destroy(fields[i]);
   fields[i] = new_field;
  }
 }
}


map

decompiled_code:
float __fastcall map(float a1, float a2, float a3, float a4, float a5)
{
return (float)((float)((float)(a1 - a2) * (float)(a5 - a4)) / (float)(a3 - a2)) + a4;
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2, float a3, float a4, float a5)
{
return (float)((float)((float)(a1 - a2) * (float)(a5 - a4)) / (float)(a3 - a2)) + a4;
}

original_code:
float map(float in, float in_low, float in_high,
 float out_low, float out_high)
{
 return (in - in_low) * (out_high - out_low) / (in_high - in_low) + out_low;
}

variable_types: in float


clip

original_code:
float clip(float in, float low, float high)
{
 if (in < low)
  in = low;
 if (in > high)
  in = high;
 return in;
}

variable_types: low float

variable_types: high float


check

decompiled_code:
void *check(char a1, const char *a2, ...)
{
void *result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = arg[0].reg_save_area;
if ( !a1 )
{
if ( a2 )
{
vfprintf(stderr, a2, arg);
fputc(10, stderr);
}
abort();
}
return result;
}

canonical_decompiled_code:
void *func0(char a1, const char *a2, ...)
{
void *result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
result = arg[0].reg_save_area;
if ( !a1 )
{
if ( a2 )
{
vfprintf(stderr, a2, arg);
fputc(10, stderr);
}
abort();
}
return result;
}

original_code:
void check(_Bool success, const char *err_format, ...)
{
 va_list vl;
 __builtin_va_start(vl,err_format);
 if (!success)
 {
  if (err_format)
  {
   vfprintf(stderr, err_format, vl);
   fprintf(stderr, "\n");
  }
  abort();
 }
 __builtin_va_end(vl);
}


append

decompiled_code:
unsigned int __fastcall append(int a1)
{
_DWORD *v1; // rcx
int v2; // eax
int v3; // eax
unsigned int result; // eax

v1 = buffer;
v2 = *((_DWORD *)buffer + 1);
*((_DWORD *)buffer + v2 + 3) = a1;
v1[1] = (v2 + 1) % 20;
v3 = *((_DWORD *)buffer + 2);
if ( v3 > 19 )
{
puts(s);
result = sleep(1u);
}
else
{
result = v3 + 1;
*((_DWORD *)buffer + 2) = result;
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func7(int a1)
{
_DWORD *v1; // rcx
int v2; // eax
int v3; // eax
unsigned int result; // eax

v1 = buffer;
v2 = *((_DWORD *)buffer + 1);
*((_DWORD *)buffer + v2 + 3) = a1;
v1[1] = (v2 + 1) % 20;
v3 = *((_DWORD *)buffer + 2);
if ( v3 > 19 )
{
puts(s);
result = sleep(1u);
}
else
{
result = v3 + 1;
*((_DWORD *)buffer + 2) = result;
}
return result;
}

original_code:
void append(int value) {
 buffer->values[buffer->out_index] = value;
     buffer->out_index = (buffer->out_index + 1) % 20;
     if (buffer->active < 20){
      buffer->active++;
     } else {
         printf("Shouldn't get here, go away.( ͡° ͜ʖ ͡°)\n");
  sleep(1);
     }
}

variable_types: value int


take

decompiled_code:
__int64 take()
{
unsigned int v0; // ebx
unsigned int v2; // eax

v0 = *(_DWORD *)(buffer + 8);
if ( v0 )
{
v0 = *(_DWORD *)(buffer + 4LL * *(int *)buffer + 12);
*(_DWORD *)buffer = (*(_DWORD *)buffer + 1) % 20;
--*(_DWORD *)(buffer + 8);
}
else
{
v2 = getpid();
printf("Buffer is empty. Consumer %d waiting.", v2);
}
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // ebx
unsigned int v2; // eax

v0 = *(_DWORD *)(buffer + 8);
if ( v0 )
{
v0 = *(_DWORD *)(buffer + 4LL * *(int *)buffer + 12);
*(_DWORD *)buffer = (*(_DWORD *)buffer + 1) % 20;
--*(_DWORD *)(buffer + 8);
}
else
{
v2 = getpid();
printf("Buffer is empty. Consumer %d waiting.", v2);
}
return v0;
}

original_code:
int take(void)
{
 if (!(buffer->active))
 {
  printf("Buffer is empty. Consumer %d waiting.", getpid());
  return ((void *)0);
 }
     int v = buffer->values[buffer->in_index];
     buffer->in_index = (buffer->in_index + 1) % 20;
     buffer->active--;
     return v;
}

canonical_original_code:
int take()
{
 if (!(buffer->active))
 {
  printf("Buffer is empty. Consumer %d waiting.", getpid());
  return ((void *)0);
 }
     int v = buffer->values[buffer->in_index];
     buffer->in_index = (buffer->in_index + 1) % 20;
     buffer->active--;
     return v;
}

variable_types: v int


keyPressed

repo: AndrewFromMelbourne/raspidmx

decompiled_code:
__int64 __fastcall keyPressed(int *a1)
{
unsigned int v1; // ebx
int v3; // eax
struct termios v4; // [rsp+0h] [rbp-58h] BYREF
int v5[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

if ( stdin_fd == -1 )
{
v1 = fileno(stdin);
stdin_fd = v1;
tcgetattr(v1, &original);
*(__m128i *)&v4.c_iflag = _mm_load_si128((const __m128i *)&original);
*(__m128i *)&v4.c_line = _mm_load_si128((const __m128i *)&original.c_line);
*(__m128i *)&v4.c_cc[15] = _mm_load_si128((const __m128i *)&original.c_cc[15]);
*(_QWORD *)&v4.c_cc[31] = *(_QWORD *)&original.c_cc[31];
v4.c_ospeed = original.c_ospeed;
v4.c_lflag &= 0xFFFFFFF5;
tcsetattr(v1, 0, &v4);
setbuf(stdin, 0LL);
}
v5[0] = 0;
ioctl(stdin_fd, 0x541BuLL, v5);
LOBYTE(v1) = v5[0] != 0;
if ( v5[0] == 1 )
{
v3 = fgetc(stdin);
if ( a1 )
*a1 = v3;
}
else if ( v5[0] > 1 )
{
do
{
fgetc(stdin);
--v5[0];
}
while ( v5[0] );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
unsigned int v1; // ebx
int v3; // eax
struct termios v4; // [rsp+0h] [rbp-58h] BYREF
int v5[7]; // [rsp+3Ch] [rbp-1Ch] BYREF

if ( stdin_fd == -1 )
{
v1 = fileno(stdin);
stdin_fd = v1;
tcgetattr(v1, &original);
*(__m128i *)&v4.c_iflag = _mm_load_si128((const __m128i *)&original);
*(__m128i *)&v4.c_line = _mm_load_si128((const __m128i *)&original.c_line);
*(__m128i *)&v4.c_cc[15] = _mm_load_si128((const __m128i *)&original.c_cc[15]);
*(_QWORD *)&v4.c_cc[31] = *(_QWORD *)&original.c_cc[31];
v4.c_ospeed = original.c_ospeed;
v4.c_lflag &= 0xFFFFFFF5;
tcsetattr(v1, 0, &v4);
setbuf(stdin, 0LL);
}
v5[0] = 0;
ioctl(stdin_fd, 0x541BuLL, v5);
LOBYTE(v1) = v5[0] != 0;
if ( v5[0] == 1 )
{
v3 = fgetc(stdin);
if ( a1 )
*a1 = v3;
}
else if ( v5[0] > 1 )
{
do
{
fgetc(stdin);
--v5[0];
}
while ( v5[0] );
}
return v1;
}

original_code:
_Bool keyPressed(int *character)
{
    if (stdin_fd == -1)
    {
        stdin_fd = fileno(stdin);
        tcgetattr(stdin_fd, &original);
        struct termios term;
        memcpy(&term, &original, sizeof(term));
        term.c_lflag &= ~(0000002|0000010);
        tcsetattr(stdin_fd, 0, &term);
        setbuf(stdin, ((void *)0));
    }
    int characters_buffered = 0;
    ioctl(stdin_fd, 0x541B, &characters_buffered);
    _Bool pressed = (characters_buffered != 0);
    if (characters_buffered == 1)
    {
        int c = fgetc(stdin);
        if (character != ((void *)0))
        {
            *character = c;
        }
    }
    else if (characters_buffered > 1)
    {
        while (characters_buffered)
        {
            fgetc(stdin);
            --characters_buffered;
        }
    }
    return pressed;
}

variable_types:
character
int *

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

variable_types: c int


keyboardReset

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

if ( stdin_fd != -1 )
result = tcsetattr(stdin_fd, 0, &original);
return result;
}

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

if ( stdin_fd != -1 )
result = tcsetattr(stdin_fd, 0, &original);
return result;
}

original_code:
void keyboardReset(void)
{
    if (stdin_fd != -1)
    {
        tcsetattr(stdin_fd, 0, &original);
    }
}

canonical_original_code:
void keyboardReset()
{
    if (stdin_fd != -1)
    {
        tcsetattr(stdin_fd, 0, &original);
    }
}


resize

decompiled_code:
int __fastcall resize(const char *a1, const char *a2, __int64 a3)
{
int v4; // er12
int result; // eax
__int64 v6[6]; // [rsp+0h] [rbp-178h] BYREF
struct stat v7; // [rsp+30h] [rbp-148h] BYREF
struct stat v8; // [rsp+C0h] [rbp-B8h] BYREF

v4 = stat(a1, &v8);
result = stat(a2, &v7);
if ( result || !v4 && (result = v7.st_mtim.tv_sec, v8.st_mtim.tv_sec > v7.st_mtim.tv_sec) )
{
v6[0] = (__int64)"convert";
v6[1] = (__int64)"-resize";
v6[2] = a3;
v6[3] = (__int64)a1;
v6[4] = (__int64)a2;
v6[5] = 0LL;
result = g_spawn_sync(0LL, v6, 0LL, 4LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2, __int64 a3)
{
int v4; // er12
int result; // eax
__int64 v6[6]; // [rsp+0h] [rbp-178h] BYREF
struct stat v7; // [rsp+30h] [rbp-148h] BYREF
struct stat v8; // [rsp+C0h] [rbp-B8h] BYREF

v4 = stat(a1, &v8);
result = stat(a2, &v7);
if ( result || !v4 && (result = v7.st_mtim.tv_sec, v8.st_mtim.tv_sec > v7.st_mtim.tv_sec) )
{
v6[0] = (__int64)"convert";
v6[1] = (__int64)"-resize";
v6[2] = a3;
v6[3] = (__int64)a1;
v6[4] = (__int64)a2;
v6[5] = 0LL;
result = g_spawn_sync(0LL, v6, 0LL, 4LL, 0LL, 0LL, 0LL, 0LL, 0LL, 0LL);
}
return result;
}

original_code:
void resize(gchar *orig, gchar *thumb, gchar *size)
{
 GStatBuf oinfo, tinfo;
 int oval = stat(orig, &oinfo);
 int tval = stat(thumb, &tinfo);
 if (tval || (!oval && oinfo.st_mtime > tinfo.st_mtime)) {
  gchar *argv[] = {"convert", "-resize", size, orig, thumb, ((void *)0)};
  g_spawn_sync(((void *)0), argv, ((void *)0), G_SPAWN_SEARCH_PATH,
   ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0));
 }
}

canonical_original_code:
void resize(char *orig, char *thumb, char *size)
{
 struct stat oinfo; struct stat tinfo;
 int oval = stat(orig, &oinfo);
 int tval = stat(thumb, &tinfo);
 if (tval || (!oval && oinfo.st_mtime > tinfo.st_mtime)) {
  char *argv[] = {"convert", "-resize", size, orig, thumb, ((void *)0)};
  g_spawn_sync(((void *)0), argv, ((void *)0), G_SPAWN_SEARCH_PATH,
   ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0), ((void *)0));
 }
}

variable_types:
orig
char *

variable_types:
thumb
char *

variable_types:
size
char *

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; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

variable_types: oval int

variable_types: tval int

variable_types:
argv
char *[]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // r12
_QWORD *v5; // rdi
_QWORD *v6; // rax
_QWORD *v7; // rbp

ct_print_header("text/html", 0LL, envp);
v3 = ct_get_path_info();
v4 = ct_get_query_string();
v5 = (_QWORD *)read_dir((__int64)"large");
v6 = gen_thumbs(v5);
if ( v3 && (v7 = v6, !(unsigned int)g_str_equal(v3, "/")) )
{
if ( (unsigned int)g_str_equal(v3, "/head") )
{
frame_head();
}
else if ( (unsigned int)g_str_equal(v3, "/nav") )
{
frame_nav(0LL, v7);
}
else if ( (unsigned int)g_str_equal(v3, "/noframe") )
{
frame_nav(1LL, v7);
}
else if ( (unsigned int)g_str_equal(v3, "/show_small") )
{
frame_show("small", "show_large", v4);
}
else if ( (unsigned int)g_str_equal(v3, "/show_large") )
{
frame_show("large", "show_small", v4);
}
}
else
{
frame_index();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // r12
_QWORD *v5; // rdi
_QWORD *v6; // rax
_QWORD *v7; // rbp

ct_print_header("text/html", 0LL, envp);
v3 = ct_get_path_info();
v4 = ct_get_query_string();
v5 = (_QWORD *)func1((__int64)"large");
v6 = gen_thumbs(v5);
if ( v3 && (v7 = v6, !(unsigned int)g_str_equal(v3, "/")) )
{
if ( (unsigned int)g_str_equal(v3, "/head") )
{
frame_head();
}
else if ( (unsigned int)g_str_equal(v3, "/nav") )
{
frame_nav(0LL, v7);
}
else if ( (unsigned int)g_str_equal(v3, "/noframe") )
{
frame_nav(1LL, v7);
}
else if ( (unsigned int)g_str_equal(v3, "/show_small") )
{
frame_show("small", "show_large", v4);
}
else if ( (unsigned int)g_str_equal(v3, "/show_large") )
{
frame_show("large", "show_small", v4);
}
}
else
{
frame_index();
}
return 0;
}

original_code:
int main()
{
 ct_print_header("text/html", ((void *)0));
 const gchar *path = ct_get_path_info();
 const gchar *query = ct_get_query_string();
 GList *thumbs = gen_thumbs(read_dir("large"));
 if (!path || g_str_equal(path, "/"))
  frame_index();
 else if (g_str_equal(path, "/head"))
  frame_head();
 else if (g_str_equal(path, "/nav"))
  frame_nav((0), thumbs);
 else if (g_str_equal(path, "/noframe"))
  frame_nav((!(0)), thumbs);
 else if (g_str_equal(path, "/show_small"))
  frame_show("small", "show_large", query);
 else if (g_str_equal(path, "/show_large"))
  frame_show("large", "show_small", query);
}

canonical_original_code:
int main()
{
 ct_print_header("text/html", ((void *)0));
 char *path = ct_get_path_info();
 char *query = ct_get_query_string();
 struct _GList *thumbs = gen_thumbs(read_dir("large"));
 if (!path || g_str_equal(path, "/"))
  frame_index();
 else if (g_str_equal(path, "/head"))
  frame_head();
 else if (g_str_equal(path, "/nav"))
  frame_nav((0), thumbs);
 else if (g_str_equal(path, "/noframe"))
  frame_nav((!(0)), thumbs);
 else if (g_str_equal(path, "/show_small"))
  frame_show("small", "show_large", query);
 else if (g_str_equal(path, "/show_large"))
  frame_show("large", "show_small", query);
}

variable_types:
path
char *

variable_types:
query
char *

variable_types: struct _GList { void *data; struct _GList *next; struct _GList *prev; } *


decompiled_code:
__int64 __fastcall yysyntax_error(unsigned __int64 *a1, const char **a2, __int16 *a3, int a4)
{
char *v6; // r12
_BYTE *v7; // rax
__int64 v8; // r13
__int64 v9; // rbx
int v10; // er12
int v11; // ebp
char *v12; // rsi
_BYTE *v13; // rax
bool v14; // cf
_BYTE *v15; // rax
const char *v16; // rbx
size_t v17; // rax
unsigned int v18; // edx
unsigned __int64 v19; // rax
char *v20; // r12
char v21; // al
int v22; // edx
int v23; // er13
_BYTE *v25; // [rsp+8h] [rbp-80h]
_BYTE *v26; // [rsp+10h] [rbp-78h]
__int64 v28[13]; // [rsp+20h] [rbp-68h]

v6 = yytname[a4];
v7 = yytnamerr(0LL, v6);
v26 = v7;
if ( a4 == -2 )
{
v11 = 0;
v16 = "syntax error";
}
else
{
LOBYTE(v8) = yypact[*a3];
v28[0] = (__int64)v6;
if ( (_BYTE)v8 == 0xFA )
{
v11 = 1;
v16 = "syntax error, unexpected %s";
}
else
{
LODWORD(v9) = -(char)v8;
if ( (v8 & 0x80u) == 0LL )
LODWORD(v9) = 0;
v10 = 14 - (char)v8;
if ( v10 > 8 )
v10 = 8;
if ( (int)v9 >= v10 )
{
LABEL_41:
v25 = v26;
LABEL_42:
v26 = v25;
v11 = 1;
v16 = "syntax error, unexpected %s";
}
else
{
v9 = (int)v9;
v25 = v7;
v11 = 1;
v8 = (char)v8;
do
{
if ( yycheck[v8 + v9] == (_DWORD)v9 && (_DWORD)v9 != 1 )
{
if ( v11 == 5 )
goto LABEL_41;
v12 = yytname[v9];
v28[v11] = (__int64)v12;
v13 = yytnamerr(0LL, v12);
v14 = __CFADD__(v25, v13);
v15 = &v13[(_QWORD)v25];
if ( v14 )
return 2;
++v11;
v25 = v15;
}
++v9;
}
while ( v10 > (int)v9 );
switch ( v11 )
{
case 1:
goto LABEL_42;
case 2:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s";
break;
case 3:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s";
break;
case 4:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s or %s";
break;
case 5:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s or %s or %s";
break;
default:
v26 = v25;
v16 = "syntax error";
break;
}
}
}
}
v17 = strlen(v16);
v18 = 2;
v14 = __CFADD__(v26, v17);
v19 = (unsigned __int64)&v26[v17];
if ( !v14 )
{
if ( *a1 < v19 )
{
if ( 2 * v19 < v19 )
*a1 = -1LL;
else
*a1 = 2 * v19;
v18 = 1;
}
else
{
v20 = (char *)*a2;
v21 = *v16;
**a2 = *v16;
if ( v21 )
{
v22 = 0;
do
{
if ( v21 == 37 && v16[1] == 115 && v11 > v22 )
{
v23 = v22 + 1;
v20 = &v20[(_QWORD)yytnamerr(v20, (char *)v28[v22])];
v16 += 2;
v22 = v23;
}
else
{
++v20;
++v16;
}
v21 = *v16;
*v20 = *v16;
}
while ( v21 );
v18 = 0;
}
else
{
v18 = 0;
}
}
}
return v18;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int64 *a1, const char **a2, __int16 *a3, int a4)
{
char *v6; // r12
_BYTE *v7; // rax
__int64 v8; // r13
__int64 v9; // rbx
int v10; // er12
int v11; // ebp
char *v12; // rsi
_BYTE *v13; // rax
bool v14; // cf
_BYTE *v15; // rax
const char *v16; // rbx
size_t v17; // rax
unsigned int v18; // edx
unsigned __int64 v19; // rax
char *v20; // r12
char v21; // al
int v22; // edx
int v23; // er13
_BYTE *v25; // [rsp+8h] [rbp-80h]
_BYTE *v26; // [rsp+10h] [rbp-78h]
__int64 v28[13]; // [rsp+20h] [rbp-68h]

v6 = yytname[a4];
v7 = yytnamerr(0LL, v6);
v26 = v7;
if ( a4 == -2 )
{
v11 = 0;
v16 = "syntax error";
}
else
{
LOBYTE(v8) = yypact[*a3];
v28[0] = (__int64)v6;
if ( (_BYTE)v8 == 0xFA )
{
v11 = 1;
v16 = "syntax error, unexpected %s";
}
else
{
LODWORD(v9) = -(char)v8;
if ( (v8 & 0x80u) == 0LL )
LODWORD(v9) = 0;
v10 = 14 - (char)v8;
if ( v10 > 8 )
v10 = 8;
if ( (int)v9 >= v10 )
{
LABEL_41:
v25 = v26;
LABEL_42:
v26 = v25;
v11 = 1;
v16 = "syntax error, unexpected %s";
}
else
{
v9 = (int)v9;
v25 = v7;
v11 = 1;
v8 = (char)v8;
do
{
if ( yycheck[v8 + v9] == (_DWORD)v9 && (_DWORD)v9 != 1 )
{
if ( v11 == 5 )
goto LABEL_41;
v12 = yytname[v9];
v28[v11] = (__int64)v12;
v13 = yytnamerr(0LL, v12);
v14 = __CFADD__(v25, v13);
v15 = &v13[(_QWORD)v25];
if ( v14 )
return 2;
++v11;
v25 = v15;
}
++v9;
}
while ( v10 > (int)v9 );
switch ( v11 )
{
case 1:
goto LABEL_42;
case 2:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s";
break;
case 3:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s";
break;
case 4:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s or %s";
break;
case 5:
v26 = v25;
v16 = "syntax error, unexpected %s, expecting %s or %s or %s or %s";
break;
default:
v26 = v25;
v16 = "syntax error";
break;
}
}
}
}
v17 = strlen(v16);
v18 = 2;
v14 = __CFADD__(v26, v17);
v19 = (unsigned __int64)&v26[v17];
if ( !v14 )
{
if ( *a1 < v19 )
{
if ( 2 * v19 < v19 )
*a1 = -1LL;
else
*a1 = 2 * v19;
v18 = 1;
}
else
{
v20 = (char *)*a2;
v21 = *v16;
**a2 = *v16;
if ( v21 )
{
v22 = 0;
do
{
if ( v21 == 37 && v16[1] == 115 && v11 > v22 )
{
v23 = v22 + 1;
v20 = &v20[(_QWORD)yytnamerr(v20, (char *)v28[v22])];
v16 += 2;
v22 = v23;
}
else
{
++v20;
++v16;
}
v21 = *v16;
*v20 = *v16;
}
while ( v21 );
v18 = 0;
}
else
{
v18 = 0;
}
}
}
return v18;
}

original_code:
static int
yysyntax_error (long unsigned int *yymsg_alloc, char **yymsg,
                yytype_int16 *yyssp, int yytoken)
{
  long unsigned int yysize0 = yytnamerr (((void*)0), yytname[yytoken]);
  long unsigned int yysize = yysize0;
  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  const char *yyformat = ((void*)0);
  char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
  int yycount = 0;
  if (yytoken != (-2))
    {
      int yyn = yypact[*yyssp];
      yyarg[yycount++] = yytname[yytoken];
      if (!(!!((yyn) == (-6))))
        {
          int yyxbegin = yyn < 0 ? -yyn : 0;
          int yychecklim = 13 - yyn + 1;
          int yyxend = yychecklim < 8 ? yychecklim : 8;
          int yyx;
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
            if (yycheck[yyx + yyn] == yyx && yyx != 1
                && !0)
              {
                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
                  {
                    yycount = 1;
                    yysize = yysize0;
                    break;
                  }
                yyarg[yycount++] = yytname[yyx];
                {
                  long unsigned int yysize1 = yysize + yytnamerr (((void*)0), yytname[yyx]);
                  if (yysize <= yysize1 && yysize1 <= ((long unsigned int) -1))
                    yysize = yysize1;
                  else
                    return 2;
                }
              }
        }
    }
  switch (yycount)
    {
    default:
      case 0: yyformat = "syntax error"; break;
      case 1: yyformat = "syntax error, unexpected %s"; break;
      case 2: yyformat = "syntax error, unexpected %s, expecting %s"; break;
      case 3: yyformat = "syntax error, unexpected %s, expecting %s or %s"; break;
      case 4: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s"; break;
      case 5: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s or %s"; break;
    }
  {
    long unsigned int yysize1 = yysize + strlen (yyformat);
    if (yysize <= yysize1 && yysize1 <= ((long unsigned int) -1))
      yysize = yysize1;
    else
      return 2;
  }
  if (*yymsg_alloc < yysize)
    {
      *yymsg_alloc = 2 * yysize;
      if (! (yysize <= *yymsg_alloc
             && *yymsg_alloc <= ((long unsigned int) -1)))
        *yymsg_alloc = ((long unsigned int) -1);
      return 1;
    }
  {
    char *yyp = *yymsg;
    int yyi = 0;
    while ((*yyp = *yyformat) != '\0')
      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
        {
          yyp += yytnamerr (yyp, yyarg[yyi++]);
          yyformat += 2;
        }
      else
        {
          yyp++;
          yyformat++;
        }
  }
  return 0;
}

canonical_original_code:
static int yysyntax_error(unsigned long *yymsg_alloc, char **yymsg, short *yyssp, int yytoken)
{
  unsigned long yysize0 = yytnamerr (((void*)0), yytname[yytoken]);
  unsigned long yysize = yysize0;
  enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
  char *yyformat = ((void*)0);
  char *yyarg[-1];
  int yycount = 0;
  if (yytoken != (-2))
    {
      int yyn = yypact[*yyssp];
      yyarg[yycount++] = yytname[yytoken];
      if (!(!!((yyn) == (-6))))
        {
          int yyxbegin = yyn < 0 ? -yyn : 0;
          int yychecklim = 13 - yyn + 1;
          int yyxend = yychecklim < 8 ? yychecklim : 8;
          int yyx;
          for (yyx = yyxbegin; yyx < yyxend; ++yyx)
            if (yycheck[yyx + yyn] == yyx && yyx != 1
                && !0)
              {
                if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
                  {
                    yycount = 1;
                    yysize = yysize0;
                    break;
                  }
                yyarg[yycount++] = yytname[yyx];
                {
                  unsigned long yysize1 = yysize + yytnamerr (((void*)0), yytname[yyx]);
                  if (yysize <= yysize1 && yysize1 <= ((unsigned long) -1))
                    yysize = yysize1;
                  else
                    return 2;
                }
              }
        }
    }
  switch (yycount)
    {
    default:
      case 0: yyformat = "syntax error"; break;
      case 1: yyformat = "syntax error, unexpected %s"; break;
      case 2: yyformat = "syntax error, unexpected %s, expecting %s"; break;
      case 3: yyformat = "syntax error, unexpected %s, expecting %s or %s"; break;
      case 4: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s"; break;
      case 5: yyformat = "syntax error, unexpected %s, expecting %s or %s or %s or %s"; break;
    }
  {
    unsigned long yysize1 = yysize + strlen (yyformat);
    if (yysize <= yysize1 && yysize1 <= ((unsigned long) -1))
      yysize = yysize1;
    else
      return 2;
  }
  if (*yymsg_alloc < yysize)
    {
      *yymsg_alloc = 2 * yysize;
      if (! (yysize <= *yymsg_alloc
             && *yymsg_alloc <= ((unsigned long) -1)))
        *yymsg_alloc = ((unsigned long) -1);
      return 1;
    }
  {
    char *yyp = *yymsg;
    int yyi = 0;
    while ((*yyp = *yyformat) != '\0')
      if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
        {
          yyp += yytnamerr (yyp, yyarg[yyi++]);
          yyformat += 2;
        }
      else
        {
          yyp++;
          yyformat++;
        }
  }
  return 0;
}

variable_types:
yymsg
char **

variable_types:
yyssp
short *

variable_types: yytoken int

variable_types:
yysize
unsigned long

variable_types:
yyformat
char *

variable_types:
yyarg
char *[-1]

variable_types: yycount int

variable_types: yyn int

variable_types: yyxbegin int

variable_types: yychecklim int

variable_types: yyxend int

variable_types: yyx int

variable_types:
yyp
char *

variable_types: yyi int


yyerror

decompiled_code:
void __fastcall __noreturn yyerror(__int64 a1, const char *a2)
{
g_log(0LL, 4LL, "[%s]\n", a2);
while ( 1 )
;
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1, const char *a2)
{
g_log(0LL, 4LL, "[%s]\n", a2);
while ( 1 )
;
}

original_code:
void yyerror(gpointer root, char const *s)
{
 do { g_log (((gchar*) 0), G_LOG_LEVEL_ERROR, "[%s]\n", s); for (;;) ; } while (0);
}

canonical_original_code:
void yyerror(void *root, char *s)
{
 do { g_log (((char *) 0), G_LOG_LEVEL_ERROR, "[%s]\n", s); for (;;) ; } while (0);
}

variable_types:
root
void *

variable_types:
s
char *


yyparse

decompiled_code:
__int64 __fastcall yyparse(__int64 a1)
{
int v1; // ebp
unsigned __int64 v2; // r12
char *v3; // r14
__int16 *v4; // rbx
__int16 *v5; // r15
int v6; // edx
unsigned int v7; // er13
__int16 *v8; // rcx
__int64 v9; // r13
int v10; // eax
unsigned __int8 v11; // bp
unsigned __int8 v12; // dl
__int64 v13; // rax
__int64 v14; // rax
int v15; // ebp
int v16; // eax
const char *v17; // rsi
__int64 v18; // rax
const char *v19; // rax
__int64 v20; // rax
__int64 v21; // rax
int v22; // eax
unsigned int v23; // edx
unsigned __int64 v24; // rax
__int64 v25; // rbx
__int16 *v26; // rax
__int16 *v27; // r13
size_t v28; // r14
int v29; // er13
__int64 v30; // rax
unsigned int v31; // ebp
char *v33; // [rsp+0h] [rbp-8B8h]
size_t size; // [rsp+20h] [rbp-898h] BYREF
void *ptr; // [rsp+28h] [rbp-890h] BYREF
char v36[128]; // [rsp+30h] [rbp-888h] BYREF
char v37[1600]; // [rsp+B0h] [rbp-808h] BYREF
__int16 src[228]; // [rsp+6F0h] [rbp-1C8h] BYREF

ptr = v36;
size = 128LL;
yynerrs = 0;
yychar = -2;
src[0] = 0;
v1 = 0;
v2 = 200LL;
v3 = v37;
v33 = v37;
v4 = src;
v5 = src;
do
{
v29 = yypact[v1];
if ( v29 == -6 )
goto LABEL_8;
if ( yychar == -2 )
yychar = yylex();
if ( yychar <= 0 )
{
yychar = 0;
v6 = 0;
}
else
{
v6 = 2;
if ( (unsigned int)yychar <= 0x106 )
v6 = (unsigned __int8)yytranslate[yychar];
}
v7 = v6 + v29;
if ( v7 > 0xD || yycheck[v7] != v6 )
{
LABEL_8:
v12 = yydefact[v1];
v10 = v12;
if ( !v12 )
{
v15 = yychar;
if ( yychar != -2 )
{
if ( (unsigned int)yychar > 0x106 )
v15 = 2;
else
v15 = (unsigned __int8)yytranslate[yychar];
}
++yynerrs;
v16 = yysyntax_error(&size, (const char **)&ptr, v4, v15);
if ( v16 )
{
v17 = "syntax error";
if ( v16 == 1 )
{
if ( ptr != v36 )
free(ptr);
ptr = malloc(size);
if ( ptr )
{
yysyntax_error(&size, (const char **)&ptr, v4, v15);
v17 = (const char *)ptr;
}
else
{
ptr = v36;
size = 128LL;
v17 = "syntax error";
}
}
}
else
{
v17 = (const char *)ptr;
}
yyerror(a1, v17);
}
v11 = yyr2[v12];
v9 = *(_QWORD *)&v3[8 * (1 - v11)];
if ( v12 == 10 )
{
v30 = g_strdup_printf("printf(\"%%s\", %s);\n", *((const char **)v3 - 1));
code = g_list_prepend(code, v30);
v10 = 10;
}
else if ( v12 > 0xAu )
{
if ( v12 == 11 )
{
v18 = g_strdup_printf("printf(%s);\n", *((const char **)v3 - 1));
code = g_list_prepend(code, v18);
v10 = 11;
}
}
else if ( v12 == 8 )
{
v19 = (const char *)g_strescape(*(_QWORD *)v3, &unk_90F);
v20 = g_strdup_printf("static char data%d[] = \"%s\";\n", (unsigned int)i_0, v19);
data = g_list_prepend(data, v20);
v21 = g_strdup_printf("fwrite(data%d, sizeof(data%d)-1, 1, stdout);\n", (unsigned int)i_0, (unsigned int)i_0);
code = g_list_prepend(code, v21);
++i_0;
v10 = 8;
}
else if ( v12 == 9 )
{
v13 = g_strdup_printf("#line %d \"%s\"\n", yylineno, (const char *)name);
code = g_list_prepend(code, v13);
v14 = g_strdup_printf("%s\n", *((const char **)v3 - 1));
code = g_list_prepend(code, v14);
v10 = 9;
}
}
else
{
v1 = (unsigned __int8)yytable[v7];
if ( yytable[v7] )
{
yychar = -2;
*((_QWORD *)v3 + 1) = yylval;
v3 += 8;
v8 = v4;
goto LABEL_26;
}
v9 = *((_QWORD *)v3 + 1);
v10 = 0;
v11 = 0;
}
v8 = &v4[-v11];
v3 = &v3[-8 * v11 + 8];
*(_QWORD *)v3 = v9;
v22 = (unsigned __int8)yyr1[v10] - 8;
v23 = *v8 + yypgoto[v22];
if ( v23 <= 0xD && *v8 == yycheck[v23] )
v1 = (unsigned __int8)yytable[v23];
else
v1 = yydefgoto[v22];
LABEL_26:
v4 = v8 + 1;
v8[1] = v1;
v24 = 2 * v2;
if ( v8 + 1 >= &v5[v2 - 1] )
{
v25 = (char *)v4 - (char *)v5;
if ( v2 > 0x270F )
goto LABEL_51;
v2 = 10000LL;
if ( v24 <= 0x2710 )
v2 = v24;
v26 = (__int16 *)malloc(10 * v2 + 7);
v27 = v26;
if ( !v26 )
LABEL_51:
yyerror(a1, "memory exhausted");
memcpy(v26, v5, v25 + 2);
v28 = 4 * ((v25 >> 1) + 1);
memcpy(&v27[v2], v33, v28 * 2);
if ( v5 != src )
free(v5);
v4 = (__int16 *)((char *)v27 + v25);
v3 = (char *)&v27[v2 - 4 + v28];
if ( v4 >= &v27[v2 - 1] )
{
v5 = v27;
v31 = 1;
if ( v27 == v4 )
goto LABEL_56;
goto LABEL_54;
}
v33 = (char *)&v27[v2];
v5 = v27;
}
}
while ( v1 != 12 );
if ( v5 == v4 )
{
v31 = 0;
goto LABEL_55;
}
v31 = 0;
do
LABEL_54:
--v4;
while ( v4 != v5 );
LABEL_55:
if ( v5 == src )
goto LABEL_57;
LABEL_56:
free(v5);
LABEL_57:
if ( ptr != v36 )
free(ptr);
return v31;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // ebp
unsigned __int64 v2; // r12
char *v3; // r14
__int16 *v4; // rbx
__int16 *v5; // r15
int v6; // edx
unsigned int v7; // er13
__int16 *v8; // rcx
__int64 v9; // r13
int v10; // eax
unsigned __int8 v11; // bp
unsigned __int8 v12; // dl
__int64 v13; // rax
__int64 v14; // rax
int v15; // ebp
int v16; // eax
const char *v17; // rsi
__int64 v18; // rax
const char *v19; // rax
__int64 v20; // rax
__int64 v21; // rax
int v22; // eax
unsigned int v23; // edx
unsigned __int64 v24; // rax
__int64 v25; // rbx
__int16 *v26; // rax
__int16 *v27; // r13
size_t v28; // r14
int v29; // er13
__int64 v30; // rax
unsigned int v31; // ebp
char *v33; // [rsp+0h] [rbp-8B8h]
size_t size; // [rsp+20h] [rbp-898h] BYREF
void *ptr; // [rsp+28h] [rbp-890h] BYREF
char v36[128]; // [rsp+30h] [rbp-888h] BYREF
char v37[1600]; // [rsp+B0h] [rbp-808h] BYREF
__int16 src[228]; // [rsp+6F0h] [rbp-1C8h] BYREF

ptr = v36;
size = 128LL;
yynerrs = 0;
yychar = -2;
src[0] = 0;
v1 = 0;
v2 = 200LL;
v3 = v37;
v33 = v37;
v4 = src;
v5 = src;
do
{
v29 = yypact[v1];
if ( v29 == -6 )
goto LABEL_8;
if ( yychar == -2 )
yychar = yylex();
if ( yychar <= 0 )
{
yychar = 0;
v6 = 0;
}
else
{
v6 = 2;
if ( (unsigned int)yychar <= 0x106 )
v6 = (unsigned __int8)yytranslate[yychar];
}
v7 = v6 + v29;
if ( v7 > 0xD || yycheck[v7] != v6 )
{
LABEL_8:
v12 = yydefact[v1];
v10 = v12;
if ( !v12 )
{
v15 = yychar;
if ( yychar != -2 )
{
if ( (unsigned int)yychar > 0x106 )
v15 = 2;
else
v15 = (unsigned __int8)yytranslate[yychar];
}
++yynerrs;
v16 = func0(&size, (const char **)&ptr, v4, v15);
if ( v16 )
{
v17 = "syntax error";
if ( v16 == 1 )
{
if ( ptr != v36 )
free(ptr);
ptr = malloc(size);
if ( ptr )
{
func0(&size, (const char **)&ptr, v4, v15);
v17 = (const char *)ptr;
}
else
{
ptr = v36;
size = 128LL;
v17 = "syntax error";
}
}
}
else
{
v17 = (const char *)ptr;
}
func1(a1, v17);
}
v11 = yyr2[v12];
v9 = *(_QWORD *)&v3[8 * (1 - v11)];
if ( v12 == 10 )
{
v30 = g_strdup_printf("printf(\"%%s\", %s);\n", *((const char **)v3 - 1));
code = g_list_prepend(code, v30);
v10 = 10;
}
else if ( v12 > 0xAu )
{
if ( v12 == 11 )
{
v18 = g_strdup_printf("printf(%s);\n", *((const char **)v3 - 1));
code = g_list_prepend(code, v18);
v10 = 11;
}
}
else if ( v12 == 8 )
{
v19 = (const char *)g_strescape(*(_QWORD *)v3, &unk_90F);
v20 = g_strdup_printf("static char data%d[] = \"%s\";\n", (unsigned int)i_0, v19);
data = g_list_prepend(data, v20);
v21 = g_strdup_printf("fwrite(data%d, sizeof(data%d)-1, 1, stdout);\n", (unsigned int)i_0, (unsigned int)i_0);
code = g_list_prepend(code, v21);
++i_0;
v10 = 8;
}
else if ( v12 == 9 )
{
v13 = g_strdup_printf("#line %d \"%s\"\n", yylineno, (const char *)name);
code = g_list_prepend(code, v13);
v14 = g_strdup_printf("%s\n", *((const char **)v3 - 1));
code = g_list_prepend(code, v14);
v10 = 9;
}
}
else
{
v1 = (unsigned __int8)yytable[v7];
if ( yytable[v7] )
{
yychar = -2;
*((_QWORD *)v3 + 1) = yylval;
v3 += 8;
v8 = v4;
goto LABEL_26;
}
v9 = *((_QWORD *)v3 + 1);
v10 = 0;
v11 = 0;
}
v8 = &v4[-v11];
v3 = &v3[-8 * v11 + 8];
*(_QWORD *)v3 = v9;
v22 = (unsigned __int8)yyr1[v10] - 8;
v23 = *v8 + yypgoto[v22];
if ( v23 <= 0xD && *v8 == yycheck[v23] )
v1 = (unsigned __int8)yytable[v23];
else
v1 = yydefgoto[v22];
LABEL_26:
v4 = v8 + 1;
v8[1] = v1;
v24 = 2 * v2;
if ( v8 + 1 >= &v5[v2 - 1] )
{
v25 = (char *)v4 - (char *)v5;
if ( v2 > 0x270F )
goto LABEL_51;
v2 = 10000LL;
if ( v24 <= 0x2710 )
v2 = v24;
v26 = (__int16 *)malloc(10 * v2 + 7);
v27 = v26;
if ( !v26 )
LABEL_51:
func1(a1, "memory exhausted");
memcpy(v26, v5, v25 + 2);
v28 = 4 * ((v25 >> 1) + 1);
memcpy(&v27[v2], v33, v28 * 2);
if ( v5 != src )
free(v5);
v4 = (__int16 *)((char *)v27 + v25);
v3 = (char *)&v27[v2 - 4 + v28];
if ( v4 >= &v27[v2 - 1] )
{
v5 = v27;
v31 = 1;
if ( v27 == v4 )
goto LABEL_56;
goto LABEL_54;
}
v33 = (char *)&v27[v2];
v5 = v27;
}
}
while ( v1 != 12 );
if ( v5 == v4 )
{
v31 = 0;
goto LABEL_55;
}
v31 = 0;
do
LABEL_54:
--v4;
while ( v4 != v5 );
LABEL_55:
if ( v5 == src )
goto LABEL_57;
LABEL_56:
free(v5);
LABEL_57:
if ( ptr != v36 )
free(ptr);
return v31;
}

original_code:
int
yyparse (gpointer root)
{
    int yystate;
    int yyerrstatus;
    yytype_int16 yyssa[200];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;
    char * yyvsa[200];
    char * *yyvs;
    char * *yyvsp;
    long unsigned int yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  char * yyval;
  char yymsgbuf[128];
  char *yymsg = yymsgbuf;
  long unsigned int yymsg_alloc = sizeof yymsgbuf;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (yytype_int16) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      long unsigned int yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (char *)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { long unsigned int yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 12)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-6))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 13 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 8:
    {
 static int i = 0;
 data = g_list_prepend(data, g_strdup_printf(
  "static char data%d[] = \"%s\";\n",
  i, g_strescape(yyvsp[0], "")));
 code = g_list_prepend(code, g_strdup_printf(
  "fwrite(data%d, sizeof(data%d)-1, 1, stdout);\n",
  i, i));
 i++;
}
    break;
  case 9:
    {
 code = g_list_prepend(code, g_strdup_printf("#line %d \"%s\"\n", yylineno, name));
 code = g_list_prepend(code, g_strdup_printf("%s\n", yyvsp[-1]));
}
    break;
  case 10:
    {
 code = g_list_prepend(code, g_strdup_printf("printf(\"%%s\", %s);\n", yyvsp[-1]));
}
    break;
  case 11:
    {
 code = g_list_prepend(code, g_strdup_printf("printf(%s);\n", yyvsp[-1]));
}
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    const int yylhs = yyr1[yyn] - 8;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 13 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      {
        char const *yymsgp = "syntax error";
        int yysyntax_error_status;
        yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, yyssp, yytoken);
        if (yysyntax_error_status == 0)
          yymsgp = yymsg;
        else if (yysyntax_error_status == 1)
          {
            if (yymsg != yymsgbuf)
              free (yymsg);
            yymsg = (char *) malloc (yymsg_alloc);
            if (!yymsg)
              {
                yymsg = yymsgbuf;
                yymsg_alloc = sizeof yymsgbuf;
                yysyntax_error_status = 2;
              }
            else
              {
                yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, yyssp, yytoken);
                yymsgp = yymsg;
              }
          }
        yyerror (root, yymsgp);
        if (yysyntax_error_status == 2)
          goto yyexhaustedlab;
      }
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval, root);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-6))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 13 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp, root);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror (root, "memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned) (yychar) <= 262 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval, root);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp, root);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  if (yymsg != yymsgbuf)
    free (yymsg);
  return yyresult;
}

canonical_original_code:
int yyparse(void *root)
{
    int yystate;
    int yyerrstatus;
    short yyssa[200];
    short *yyss;
    short *yyssp;
    char *yyvsa[200];
    char **yyvs;
    char **yyvsp;
    unsigned long yystacksize;
  int yyn;
  int yyresult;
  int yytoken = 0;
  char *yyval;
  char yymsgbuf[128];
  char *yymsg = yymsgbuf;
  unsigned long yymsg_alloc = sizeof yymsgbuf;
  int yylen = 0;
  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = 200;
  ;
  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = (-2);
  goto yysetstate;
yynewstate:
  yyssp++;
yysetstate:
  *yyssp = (short) yystate;
  if (yyss + yystacksize - 1 <= yyssp)
    {
      unsigned long yysize = (long unsigned int) (yyssp - yyss + 1);
      if (10000 <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (10000 < yystacksize)
        yystacksize = 10000;
      {
        short *yyss1 = yyss;
        union yyalloc *yyptr = (union yyalloc *) malloc (((yystacksize) * (sizeof (yytype_int16) + sizeof (char *)) + (sizeof (union yyalloc) - 1)));
        if (! yyptr)
          goto yyexhaustedlab;
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyss_alloc, yyss, (yysize) * sizeof (*(yyss))); yyss = &yyptr->yyss_alloc; yynewbytes = yystacksize * sizeof (*yyss) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        do { unsigned long yynewbytes; __builtin_memcpy (&yyptr->yyvs_alloc, yyvs, (yysize) * sizeof (*(yyvs))); yyvs = &yyptr->yyvs_alloc; yynewbytes = yystacksize * sizeof (*yyvs) + (sizeof (union yyalloc) - 1); yyptr += yynewbytes / sizeof (*yyptr); } while (0);
        if (yyss1 != yyssa)
          free (yyss1);
      }
      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;
      ;
      if (yyss + yystacksize - 1 <= yyssp)
        goto yyabortlab;
    }
  ;
  if (yystate == 12)
    goto yyacceptlab;
  goto yybackup;
yybackup:
  yyn = yypact[yystate];
  if ((!!((yyn) == (-6))))
    goto yydefault;
  if (yychar == (-2))
    {
      ;
      yychar = yylex ();
    }
  if (yychar <= 0)
    {
      yychar = yytoken = 0;
      ;
    }
  else
    {
      yytoken = ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
      ;
    }
  yyn += yytoken;
  if (yyn < 0 || 13 < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (0)
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }
  if (yyerrstatus)
    yyerrstatus--;
  ;
  yychar = (-2);
  yystate = yyn;

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  goto yynewstate;
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;
yyreduce:
  yylen = yyr2[yyn];
  yyval = yyvsp[1-yylen];
  ;
  switch (yyn)
    {
        case 8:
    {
 static int i = 0;
 data = g_list_prepend(data, g_strdup_printf(
  "static char data%d[] = \"%s\";\n",
  i, g_strescape(yyvsp[0], "")));
 code = g_list_prepend(code, g_strdup_printf(
  "fwrite(data%d, sizeof(data%d)-1, 1, stdout);\n",
  i, i));
 i++;
}
    break;
  case 9:
    {
 code = g_list_prepend(code, g_strdup_printf("#line %d \"%s\"\n", yylineno, name));
 code = g_list_prepend(code, g_strdup_printf("%s\n", yyvsp[-1]));
}
    break;
  case 10:
    {
 code = g_list_prepend(code, g_strdup_printf("printf(\"%%s\", %s);\n", yyvsp[-1]));
}
    break;
  case 11:
    {
 code = g_list_prepend(code, g_strdup_printf("printf(%s);\n", yyvsp[-1]));
}
    break;
      default: break;
    }
  ;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  *++yyvsp = yyval;
  {
    int yylhs = yyr1[yyn] - 8;
    int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= 13 && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }
  goto yynewstate;
yyerrlab:
  yytoken = yychar == (-2) ? (-2) : ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
  if (!yyerrstatus)
    {
      ++yynerrs;
      {
        char *yymsgp = "syntax error";
        int yysyntax_error_status;
        yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, yyssp, yytoken);
        if (yysyntax_error_status == 0)
          yymsgp = yymsg;
        else if (yysyntax_error_status == 1)
          {
            if (yymsg != yymsgbuf)
              free (yymsg);
            yymsg = (char *) malloc (yymsg_alloc);
            if (!yymsg)
              {
                yymsg = yymsgbuf;
                yymsg_alloc = sizeof yymsgbuf;
                yysyntax_error_status = 2;
              }
            else
              {
                yysyntax_error_status = yysyntax_error (&yymsg_alloc, &yymsg, yyssp, yytoken);
                yymsgp = yymsg;
              }
          }
        yyerror (root, yymsgp);
        if (yysyntax_error_status == 2)
          goto yyexhaustedlab;
      }
    }
  if (yyerrstatus == 3)
    {
      if (yychar <= 0)
        {
          if (yychar == 0)
            goto yyabortlab;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval, root);
          yychar = (-2);
        }
    }
  goto yyerrlab1;
yyerrorlab:
  if (0)
    goto yyerrorlab;
  (yyvsp -= (yylen), yyssp -= (yylen));
  yylen = 0;
  ;
  yystate = *yyssp;
  goto yyerrlab1;
yyerrlab1:
  yyerrstatus = 3;
  for (;;)
    {
      yyn = yypact[yystate];
      if (!(!!((yyn) == (-6))))
        {
          yyn += 1;
          if (0 <= yyn && yyn <= 13 && yycheck[yyn] == 1)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }
      if (yyssp == yyss)
        goto yyabortlab;
      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp, root);
      (yyvsp -= (1), yyssp -= (1));
      yystate = *yyssp;
      ;
    }

#pragma GCC diagnostic push

#pragma GCC diagnostic ignored "-Wuninitialized"

#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

  *++yyvsp = yylval;

#pragma GCC diagnostic pop

  ;
  yystate = yyn;
  goto yynewstate;
yyacceptlab:
  yyresult = 0;
  goto yyreturn;
yyabortlab:
  yyresult = 1;
  goto yyreturn;
yyexhaustedlab:
  yyerror (root, "memory exhausted");
  yyresult = 2;
yyreturn:
  if (yychar != (-2))
    {
      yytoken = ((unsigned int) (yychar) <= 262 ? yytranslate[yychar] : 2);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval, root);
    }
  (yyvsp -= (yylen), yyssp -= (yylen));
  ;
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp, root);
      (yyvsp -= (1), yyssp -= (1));
    }
  if (yyss != yyssa)
    free (yyss);
  if (yymsg != yymsgbuf)
    free (yymsg);
  return yyresult;
}

variable_types: yystate int

variable_types: yyerrstatus int

variable_types:
yyssa
short [200]

variable_types:
yyss
short *

variable_types:
yyvsa
char *[200]

variable_types:
yyvs
char **

variable_types:
yyvsp
char **

variable_types:
yystacksize
unsigned long

variable_types: yyresult int

variable_types:
yyval
char *

variable_types:
yymsgbuf
char [128]

variable_types:
yymsg
char *

variable_types: yylen int

variable_types: union yyalloc { short yyss_alloc; char *yyvs_alloc; } *

variable_types:
yynewbytes
unsigned long

variable_types: i int

variable_types: yylhs int

variable_types:
yymsgp
char *


original_code:
static void do_tile(row_t *rows, int row, int col)
{
 tile_t *t = &rows[row].cols[col];
 switch (t->c) {
 case '-': t->top = LEFT | RIGHT; break;
 case '|': t->top = UP | DOWN; break;
 case '\'': t->top = UP; break;
 case '.': t->top = DOWN; break;
 }
 if (col > 0) {
  tile_t *l = &rows[row].cols[col-1];
  if (t->c == '|' && (l->top | l->bot) & RIGHT)
   t->bot = LEFT | RIGHT;
 }
 if (row > 0 && rows[row-1].ncols > col) {
  tile_t *u = &rows[row-1].cols[col];
  if (t->c == '-' && (u->top | u->bot) & DOWN)
   t->bot = UP | DOWN;
 }
 if (t->c == '.' || t->c == '\'') {
  tile_t *l = &rows[row].cols[col-1];
  if (col > 0 && (l->top | l->bot) & RIGHT)
   t->top |= LEFT;
  else
   t->top |= RIGHT;
 }
}

canonical_original_code:
static void do_tile(struct row_t *rows, int row, int col)
{
 struct tile_t *t = &rows[row].cols[col];
 switch (t->c) {
 case '-': t->top = LEFT | RIGHT; break;
 case '|': t->top = UP | DOWN; break;
 case '\'': t->top = UP; break;
 case '.': t->top = DOWN; break;
 }
 if (col > 0) {
  struct tile_t *l = &rows[row].cols[col-1];
  if (t->c == '|' && (l->top | l->bot) & RIGHT)
   t->bot = LEFT | RIGHT;
 }
 if (row > 0 && rows[row-1].ncols > col) {
  struct tile_t *u = &rows[row-1].cols[col];
  if (t->c == '-' && (u->top | u->bot) & DOWN)
   t->bot = UP | DOWN;
 }
 if (t->c == '.' || t->c == '\'') {
  struct tile_t *l = &rows[row].cols[col-1];
  if (col > 0 && (l->top | l->bot) & RIGHT)
   t->top |= LEFT;
  else
   t->top |= RIGHT;
 }
}

variable_types: struct row_t { struct tile_t { char c; int top; int bot; } *cols; int ncols; } *

variable_types: row int

variable_types: col int

user_defined_types: struct row_t { struct tile_t *cols; int ncols; }


main

original_code:
int main()
{
 char c;
 int row = 0, col = 0;
 row_t *rows = calloc(sizeof(row_t), (row+2));
 while ((c = getchar()) != (-1)) {
  if (c == '\n') {
   row++;
   col = 0;
   rows = realloc(rows, sizeof(row_t) * (row+2));
   rows[row+0] = (row_t){.ncols = 0};
   rows[row+1] = (row_t){.ncols = -1};
  } else {
   rows[row].cols = realloc(rows[row].cols, sizeof(tile_t) * (col+1));
   rows[row].ncols = col+1;
   rows[row].cols[col] = (tile_t){.c = c};
   do_tile(rows, row, col);
   col++;
  }
 }
 if (0)
 for (row = 0; rows[row].ncols >= 0; row++) {
  for (col = 0; col > rows[row].ncols; col++) {
   print_ptrn(rows[row].cols[col].top);
   print_ptrn(rows[row].cols[col].bot);
   printf(" ");
  }
  printf("\n");
 }
 print_index(rows);
 for (int row = 0; rows[row].ncols >= 0; row++)
  if (rows[row].cols > 0)
   free(rows[row].cols);
 free(rows);
 return 0;
}

canonical_original_code:
int main()
{
 char c;
 int row = 0; int col = 0;
 struct row_t *rows = calloc(sizeof(row_t), (row+2));
 while ((c = getchar()) != (-1)) {
  if (c == '\n') {
   row++;
   col = 0;
   rows = realloc(rows, sizeof(row_t) * (row+2));
   rows[row+0] = (struct row_t){.ncols = 0};
   rows[row+1] = (struct row_t){.ncols = -1};
  } else {
   rows[row].cols = realloc(rows[row].cols, sizeof(tile_t) * (col+1));
   rows[row].ncols = col+1;
   rows[row].cols[col] = (struct tile_t){.c = c};
   do_tile(rows, row, col);
   col++;
  }
 }
 if (0)
 for (row = 0; rows[row].ncols >= 0; row++) {
  for (col = 0; col > rows[row].ncols; col++) {
   print_ptrn(rows[row].cols[col].top);
   print_ptrn(rows[row].cols[col].bot);
   printf(" ");
  }
  printf("\n");
 }
 print_index(rows);
 for (int row = 0; rows[row].ncols >= 0; row++)
  if (rows[row].cols > 0)
   free(rows[row].cols);
 free(rows);
 return 0;
}

variable_types: c char

user_defined_types: struct tile_t { char c; int top; int bot; }


decompiled_code:
int __fastcall print_month(unsigned int a1, int a2, int a3)
{
int v3; // er14
__int64 v4; // rbx
const char *v5; // rbp
char v6; // r12
size_t v7; // rax
unsigned int i; // ebp
const char *v9; // rax
int result; // eax
unsigned int v11; // er12
int v12; // eax
int v13; // ebp
unsigned int v14; // ebp
int v15; // er14
int j; // er13
int v17; // [rsp+Ch] [rbp-4Ch]
int v18; // [rsp+10h] [rbp-48h]
int v19; // [rsp+14h] [rbp-44h]

v3 = a3;
v4 = EVENTS;
v5 = (const char *)month_to_string();
v18 = start_of_month(SEL[0], a1);
v6 = days_in_month(SEL[0], a1);
v7 = strlen(v5);
mvwprintw(win, a2, v3 + 10 - (v7 >> 1), "%s", v5);
wmove(win, a2 + 1, v3);
for ( i = 0; i != 7; ++i )
{
v9 = (const char *)day_to_st(i);
wprintw(win, "%-3s", v9);
}
result = v6;
v19 = v6;
if ( v6 > 0 )
{
v11 = 0;
do
{
v15 = (int)(v11 + v18) / 7;
v17 = (int)(v11 + v18) % 7;
for ( j = 0; v4; v4 = *(_QWORD *)(v4 + 88) )
{
if ( !(unsigned int)before(v4 + 32, SEL[0], a1, v11, 24LL, 0LL) )
break;
if ( !(unsigned int)before(v4 + 32, SEL[0], a1, v11, 0LL, 0LL) )
j = 1;
}
if ( SEL[1] == a1 && SEL[2] == v11 )
{
v12 = j == 0 ? 0x100000 : 2228224;
v13 = 0x40000;
}
else
{
v12 = j == 0 ? 0x100000 : 2228224;
v13 = 0;
}
v14 = v12 | v13;
wattr_on(win, v14, 0LL);
mvwprintw(win, v15 + a2 + 2, a3 + 3 * v17, "%2d", ++v11);
result = wattr_off(win, v14, 0LL);
}
while ( v11 != v19 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1, int a2, int a3)
{
int v3; // er14
__int64 v4; // rbx
const char *v5; // rbp
char v6; // r12
size_t v7; // rax
unsigned int i; // ebp
const char *v9; // rax
int result; // eax
unsigned int v11; // er12
int v12; // eax
int v13; // ebp
unsigned int v14; // ebp
int v15; // er14
int j; // er13
int v17; // [rsp+Ch] [rbp-4Ch]
int v18; // [rsp+10h] [rbp-48h]
int v19; // [rsp+14h] [rbp-44h]

v3 = a3;
v4 = EVENTS;
v5 = (const char *)month_to_string();
v18 = start_of_month(SEL[0], a1);
v6 = days_in_month(SEL[0], a1);
v7 = strlen(v5);
mvwprintw(win, a2, v3 + 10 - (v7 >> 1), "%s", v5);
wmove(win, a2 + 1, v3);
for ( i = 0; i != 7; ++i )
{
v9 = (const char *)day_to_st(i);
wprintw(win, "%-3s", v9);
}
result = v6;
v19 = v6;
if ( v6 > 0 )
{
v11 = 0;
do
{
v15 = (int)(v11 + v18) / 7;
v17 = (int)(v11 + v18) % 7;
for ( j = 0; v4; v4 = *(_QWORD *)(v4 + 88) )
{
if ( !(unsigned int)before(v4 + 32, SEL[0], a1, v11, 24LL, 0LL) )
break;
if ( !(unsigned int)before(v4 + 32, SEL[0], a1, v11, 0LL, 0LL) )
j = 1;
}
if ( SEL[1] == a1 && SEL[2] == v11 )
{
v12 = j == 0 ? 0x100000 : 2228224;
v13 = 0x40000;
}
else
{
v12 = j == 0 ? 0x100000 : 2228224;
v13 = 0;
}
v14 = v12 | v13;
wattr_on(win, v14, 0LL);
mvwprintw(win, v15 + a2 + 2, a3 + 3 * v17, "%2d", ++v11);
result = wattr_off(win, v14, 0LL);
}
while ( v11 != v19 );
}
return result;
}

original_code:
static void print_month(month_t month, int y, int x)
{
 event_t *event = EVENTS;
 const char *name = month_to_string(month);
 const int start = start_of_month(SEL.year, month);
 const char days = days_in_month(SEL.year, month);
 mvwprintw(win, y, x+(2*7+6)/2-strlen(name)/2, "%s", name);
 wmove(win, y+1, x);
 for (int d = 0; d < 7; d++)
  wprintw(win, "%-3s", day_to_st(d));
 for (int d = 0; d < days; d++) {
  int row = (start + d) / 7;
  int col = (start + d) % 7;
  int busy = 0;
  while (event && before(&event->start, SEL.year, month, d, 24, 0)) {
   if (!before(&event->start, SEL.year, month, d, 0, 0))
    busy = 1;
   event = event->next;
  }
  int today = month == SEL.month && d == SEL.day;
  int attr = (busy ? ((chtype)((1U)) << ((13) + 8))|((chtype)((1U)) << ((9) + 8)) : ((chtype)((1U)) << ((12) + 8)))
            | (today ? ((chtype)((1U)) << ((10) + 8)) : 0 );
  wattr_on(win, (attr_t)(attr), ((void *)0));
  mvwprintw(win, y+2+row, x+col*3, "%2d", d+1);
  wattr_off(win, (attr_t)(attr), ((void *)0));
 }
}

canonical_original_code:
static void print_month(enum month_t month, int y, int x)
{
 struct event_t *event = EVENTS;
 char *name = month_to_string(month);
 int start = start_of_month(SEL.year, month);
 char days = days_in_month(SEL.year, month);
 mvwprintw(win, y, x+(2*7+6)/2-strlen(name)/2, "%s", name);
 wmove(win, y+1, x);
 for (int d = 0; d < 7; d++)
  wprintw(win, "%-3s", day_to_st(d));
 for (int d = 0; d < days; d++) {
  int row = (start + d) / 7;
  int col = (start + d) % 7;
  int busy = 0;
  while (event && before(&event->start, SEL.year, month, d, 24, 0)) {
   if (!before(&event->start, SEL.year, month, d, 0, 0))
    busy = 1;
   event = event->next;
  }
  int today = month == SEL.month && d == SEL.day;
  int attr = (busy ? ((chtype)((1U)) << ((13) + 8))|((chtype)((1U)) << ((9) + 8)) : ((chtype)((1U)) << ((12) + 8)))
            | (today ? ((chtype)((1U)) << ((10) + 8)) : 0 );
  wattr_on(win, (attr_t)(attr), ((void *)0));
  mvwprintw(win, y+2+row, x+col*3, "%2d", d+1);
  wattr_off(win, (attr_t)(attr), ((void *)0));
 }
}

variable_types: y int

variable_types: x int

variable_types: struct event_t { char *name; char *desc; char *loc; char *cat; struct date_t { int year; enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 } month; int day; int hour; int min; int sec; } start; struct date_t end; struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *cal; struct event_t *next; struct event_t *prev; } *

variable_types:
name
char *

variable_types: start int

variable_types: days char

variable_types: d int

variable_types: busy int

variable_types: today int

variable_types: attr int

user_defined_types: struct event_t { char *name; char *desc; char *loc; char *cat; struct date_t start; struct date_t end; struct cal_t *cal; struct event_t *next; struct event_t *prev; }

user_defined_types: struct date_t { int year; enum month_t month; int day; int hour; int min; int sec; }


decompiled_code:
void year_size()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void year_size(int rows, int cols)
{
}

canonical_original_code:
void year_size(int rows, int cols)
{
}

variable_types: rows int

variable_types: cols int


decompiled_code:
int year_draw()
{
int v0; // ebx
unsigned int i; // ebp
int v2; // edx
__int64 v3; // rax
int v4; // edx
int v5; // er13
signed int v6; // ebp
int v7; // er12
__int64 *v8; // r12
int v9; // ebp
int v10; // ebp
int result; // eax
__int64 v12; // [rsp+0h] [rbp-48h] BYREF
__int64 v13; // [rsp+8h] [rbp-40h] BYREF

v0 = COLS / 2 - 33;
v12 = 0LL;
v13 = 0LL;
cal_load(SEL[0], 0LL, 0LL, 366LL);
for ( i = 0; i != 12; ++i )
{
v2 = weeks_in_month(SEL[0], i);
v3 = (int)i / 3;
v4 = v2 + 2;
if ( v4 < *((_DWORD *)&v12 + v3) )
v4 = *((_DWORD *)&v12 + v3);
*((_DWORD *)&v12 + v3) = v4;
}
v5 = HIDWORD(v13) + v13 + v12 + HIDWORD(v12);
if ( COMPACT )
{
wattr_on(win, 0x240000uLL, 0LL);
if ( COMPACT )
{
if ( wmove(win, 0, 0) != -1 )
whline(win, 0x240000uLL, COLS);
}
}
mvwprintw(win, 0, COLS / 2 - 2, "%d", SEL[0]);
if ( COMPACT )
wattr_off(win, 0x240000uLL, 0LL);
v6 = 0;
v7 = 1;
do
{
print_month(v6, v7, v0);
v0 += 23;
if ( v6 % 3 == 2 )
{
v0 = COLS / 2 - 33;
v7 += *((_DWORD *)&v12 + v6 / 3) + 1;
}
++v6;
}
while ( v6 != 12 );
if ( wmove(win, 1, v0 + 21) != -1 )
wvline(win, LODWORD(acs_map[60]), v5 + 3);
if ( wmove(win, 1, v0 + 44) != -1 )
wvline(win, LODWORD(acs_map[60]), v5 + 3);
v8 = &v12;
v9 = 1;
do
{
v10 = *(_DWORD *)v8 + v9;
if ( wmove(win, v10, v0) != -1 )
whline(win, HIDWORD(acs_map[56]), 66);
if ( wmove(win, v10, v0 + 21) != -1 )
waddch(win, LODWORD(acs_map[55]));
result = wmove(win, v10, v0 + 44);
if ( result != -1 )
result = waddch(win, LODWORD(acs_map[55]));
v9 = v10 + 1;
v8 = (__int64 *)((char *)v8 + 4);
}
while ( v8 != (__int64 *)((char *)&v13 + 4) );
return result;
}

canonical_decompiled_code:
int func3()
{
int v0; // ebx
unsigned int i; // ebp
int v2; // edx
__int64 v3; // rax
int v4; // edx
int v5; // er13
signed int v6; // ebp
int v7; // er12
__int64 *v8; // r12
int v9; // ebp
int v10; // ebp
int result; // eax
__int64 v12; // [rsp+0h] [rbp-48h] BYREF
__int64 v13; // [rsp+8h] [rbp-40h] BYREF

v0 = COLS / 2 - 33;
v12 = 0LL;
v13 = 0LL;
cal_load(SEL[0], 0LL, 0LL, 366LL);
for ( i = 0; i != 12; ++i )
{
v2 = weeks_in_month(SEL[0], i);
v3 = (int)i / 3;
v4 = v2 + 2;
if ( v4 < *((_DWORD *)&v12 + v3) )
v4 = *((_DWORD *)&v12 + v3);
*((_DWORD *)&v12 + v3) = v4;
}
v5 = HIDWORD(v13) + v13 + v12 + HIDWORD(v12);
if ( COMPACT )
{
wattr_on(win, 0x240000uLL, 0LL);
if ( COMPACT )
{
if ( wmove(win, 0, 0) != -1 )
whline(win, 0x240000uLL, COLS);
}
}
mvwprintw(win, 0, COLS / 2 - 2, "%d", SEL[0]);
if ( COMPACT )
wattr_off(win, 0x240000uLL, 0LL);
v6 = 0;
v7 = 1;
do
{
func0(v6, v7, v0);
v0 += 23;
if ( v6 % 3 == 2 )
{
v0 = COLS / 2 - 33;
v7 += *((_DWORD *)&v12 + v6 / 3) + 1;
}
++v6;
}
while ( v6 != 12 );
if ( wmove(win, 1, v0 + 21) != -1 )
wvline(win, LODWORD(acs_map[60]), v5 + 3);
if ( wmove(win, 1, v0 + 44) != -1 )
wvline(win, LODWORD(acs_map[60]), v5 + 3);
v8 = &v12;
v9 = 1;
do
{
v10 = *(_DWORD *)v8 + v9;
if ( wmove(win, v10, v0) != -1 )
whline(win, HIDWORD(acs_map[56]), 66);
if ( wmove(win, v10, v0 + 21) != -1 )
waddch(win, LODWORD(acs_map[55]));
result = wmove(win, v10, v0 + 44);
if ( result != -1 )
result = waddch(win, LODWORD(acs_map[55]));
v9 = v10 + 1;
v8 = (__int64 *)((char *)v8 + 4);
}
while ( v8 != (__int64 *)((char *)&v13 + 4) );
return result;
}

variable_types: w int

variable_types:
h
int [4]

variable_types: m int

variable_types: weeks int

variable_types: sum int

variable_types: i int


original_code:
int year_run(int key, mmask_t btn, int row, int col)
{
 day_t d = SEL.day;
 month_t m = SEL.month;
 year_t y = SEL.year;
 wday_t day = day_of_week(SEL.year, SEL.month, SEL.day);
 int week = (start_of_month(y, m) + d) / 7;
 int dir = 0;
 if (key == 'i')
  SEL.year--;
 if (key == 'o')
  SEL.year++;
 if (key == 'h' || key == 'k')
  dir = -1;
 if (key == 'j' || key == 'l')
  dir = 1;
 if (key == 'j' || key == 'k') {
  for (int i = 0; i < 90/7; i++) {
   add_days(&y, &m, &d, dir*7);
   if (day_of_week(y, m, d) == day &&
       y == SEL.year && m%3 == SEL.month%3) {
    SEL.month = m;
    SEL.day = d;
    break;
   }
  }
 }
 if (key == 'h' || key == 'l') {
  for (int i = 0; i < 90; i++) {
   add_days(&y, &m, &d, dir);
   if ((start_of_month(y, m) + d) / 7 == week &&
       y == SEL.year && m/3 == SEL.month/3) {
    SEL.month = m;
    SEL.day = d;
    break;
   }
  }
 }
 if (dir || y != SEL.year) {
  werase(win);
  year_draw();
  wrefresh(win);
 }
 return dir || y != SEL.year;
}

canonical_original_code:
int year_run(int key, unsigned int btn, int row, int col)
{
 int d = SEL.day;
 enum month_t m = SEL.month;
 int y = SEL.year;
 enum wday_t day = day_of_week(SEL.year, SEL.month, SEL.day);
 int week = (start_of_month(y, m) + d) / 7;
 int dir = 0;
 if (key == 'i')
  SEL.year--;
 if (key == 'o')
  SEL.year++;
 if (key == 'h' || key == 'k')
  dir = -1;
 if (key == 'j' || key == 'l')
  dir = 1;
 if (key == 'j' || key == 'k') {
  for (int i = 0; i < 90/7; i++) {
   add_days(&y, &m, &d, dir*7);
   if (day_of_week(y, m, d) == day &&
       y == SEL.year && m%3 == SEL.month%3) {
    SEL.month = m;
    SEL.day = d;
    break;
   }
  }
 }
 if (key == 'h' || key == 'l') {
  for (int i = 0; i < 90; i++) {
   add_days(&y, &m, &d, dir);
   if ((start_of_month(y, m) + d) / 7 == week &&
       y == SEL.year && m/3 == SEL.month/3) {
    SEL.month = m;
    SEL.day = d;
    break;
   }
  }
 }
 if (dir || y != SEL.year) {
  werase(win);
  year_draw();
  wrefresh(win);
 }
 return dir || y != SEL.year;
}

variable_types: key int

variable_types:
btn
unsigned int

variable_types: row int

variable_types: col int

variable_types: enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 }

variable_types: y int

variable_types: enum wday_t { SUN=0, MON=1, TUE=2, WED=3, THU=4, FRI=5, SAT=6 }

variable_types: week int

variable_types: dir int


decompiled_code:
__int64 __fastcall add_event(_QWORD *a1, __int64 a2, __int64 *a3)
{
__int64 v3; // rax
__int64 result; // rax

if ( *(_QWORD *)a2 )
*(_QWORD *)(*(_QWORD *)a2 + 88LL) = *a3;
else
*a1 = *a3;
*(_QWORD *)(*a3 + 96) = *(_QWORD *)a2;
v3 = *a3;
*(_QWORD *)a2 = *a3;
result = *(_QWORD *)(v3 + 88);
*a3 = result;
return result;
}

original_code:
static void add_event(event_t **first, event_t **last, event_t **next)
{
 if (*last)
  (*last)->next = *next;
 else
  (*first) = *next;
 (*next)->prev = *last;
 (*last) = (*next);
 (*next) = (*next)->next;
}

canonical_original_code:
static void add_event(struct event_t **first, struct event_t **last, struct event_t **next)
{
 if (*last)
  (*last)->next = *next;
 else
  (*first) = *next;
 (*next)->prev = *last;
 (*last) = (*next);
 (*next) = (*next)->next;
}

variable_types: struct event_t { char *name; char *desc; char *loc; char *cat; struct date_t { int year; enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 } month; int day; int hour; int min; int sec; } start; struct date_t end; struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *cal; struct event_t *next; struct event_t *prev; } **

variable_types:
last
struct event_t **

variable_types:
next
struct event_t **


decompiled_code:
__int64 __fastcall add_todo(_QWORD *a1, __int64 a2, __int64 *a3)
{
__int64 v3; // rax
__int64 result; // rax

if ( *(_QWORD *)a2 )
*(_QWORD *)(*(_QWORD *)a2 + 88LL) = *a3;
else
*a1 = *a3;
*(_QWORD *)(*a3 + 96) = *(_QWORD *)a2;
v3 = *a3;
*(_QWORD *)a2 = *a3;
result = *(_QWORD *)(v3 + 88);
*a3 = result;
return result;
}

original_code:
static void add_todo(todo_t **first, todo_t **last, todo_t **next)
{
 if (*last)
  (*last)->next = *next;
 else
  (*first) = *next;
 (*next)->prev = *last;
 (*last) = (*next);
 (*next) = (*next)->next;
}

canonical_original_code:
static void add_todo(struct todo_t **first, struct todo_t **last, struct todo_t **next)
{
 if (*last)
  (*last)->next = *next;
 else
  (*first) = *next;
 (*next)->prev = *last;
 (*last) = (*next);
 (*next) = (*next)->next;
}

variable_types: struct todo_t { char *name; char *desc; char *cat; enum status_t { NEW=0, DONE=100 } status; struct date_t { int year; enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 } month; int day; int hour; int min; int sec; } start; struct date_t due; struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *cal; struct todo_t *next; struct todo_t *prev; } **

variable_types:
last
struct todo_t **

variable_types:
next
struct todo_t **

user_defined_types: struct todo_t { char *name; char *desc; char *cat; enum status_t status; struct date_t start; struct date_t due; struct cal_t *cal; struct todo_t *next; struct todo_t *prev; }


decompiled_code:
__int64 __fastcall merge_cals(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx

if ( !a1 )
return a2;
if ( !a2 )
return a1;
v2 = a1;
do
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 24);
}
while ( v2 );
*(_QWORD *)(v3 + 24) = a2;
return a1;
}

original_code:
static cal_t *merge_cals(cal_t *a, cal_t *b)
{
 if (!a) return b;
 if (!b) return a;
 cal_t *last = a;
 while (last->next)
  last = last->next;
 last->next = b;
 return a;
}

canonical_original_code:
static struct cal_t *merge_cals(struct cal_t *a, struct cal_t *b)
{
 if (!a) return b;
 if (!b) return a;
 struct cal_t *last = a;
 while (last->next)
  last = last->next;
 last->next = b;
 return a;
}

variable_types:
a
struct cal_t *

variable_types:
b
struct cal_t *

variable_types: struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *


original_code:
static event_t *merge_events(event_t *a, event_t *b)
{
 event_t *first = ((void *)0), *last = ((void *)0);
 while (a && b)
  if (compare(&a->start, &b->start) <= 0)
   add_event(&first, &last, &a);
  else
   add_event(&first, &last, &b);
 while (a) add_event(&first, &last, &a);
 while (b) add_event(&first, &last, &b);
 return first;
}

canonical_original_code:
static struct event_t *merge_events(struct event_t *a, struct event_t *b)
{
 struct event_t *first = ((void *)0); struct event_t *last = ((void *)0);
 while (a && b)
  if (compare(&a->start, &b->start) <= 0)
   add_event(&first, &last, &a);
  else
   add_event(&first, &last, &b);
 while (a) add_event(&first, &last, &a);
 while (b) add_event(&first, &last, &b);
 return first;
}

variable_types:
a
struct event_t *

variable_types:
b
struct event_t *

variable_types: struct event_t { char *name; char *desc; char *loc; char *cat; struct date_t { int year; enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 } month; int day; int hour; int min; int sec; } start; struct date_t end; struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *cal; struct event_t *next; struct event_t *prev; } *


original_code:
static todo_t *merge_todos(todo_t *a, todo_t *b)
{
 todo_t *first = ((void *)0), *last = ((void *)0);
 while (a && b)
  if (compare(&a->start, &b->start) <= 0)
   add_todo(&first, &last, &a);
  else
   add_todo(&first, &last, &b);
 while (a) add_todo(&first, &last, &a);
 while (b) add_todo(&first, &last, &b);
 return first;
}

canonical_original_code:
static struct todo_t *merge_todos(struct todo_t *a, struct todo_t *b)
{
 struct todo_t *first = ((void *)0); struct todo_t *last = ((void *)0);
 while (a && b)
  if (compare(&a->start, &b->start) <= 0)
   add_todo(&first, &last, &a);
  else
   add_todo(&first, &last, &b);
 while (a) add_todo(&first, &last, &a);
 while (b) add_todo(&first, &last, &b);
 return first;
}

variable_types:
a
struct todo_t *

variable_types:
b
struct todo_t *

variable_types: struct todo_t { char *name; char *desc; char *cat; enum status_t { NEW=0, DONE=100 } status; struct date_t { int year; enum month_t { JAN=0, FEB=1, MAR=2, APR=3, MAY=4, JUN=5, JUL=6, AUG=7, SEP=8, OCT=9, NOV=10, DEC=11 } month; int day; int hour; int min; int sec; } start; struct date_t due; struct cal_t { char *type; char *name; char *desc; struct cal_t *next; } *cal; struct todo_t *next; struct todo_t *prev; } *