decompiled_code:
__int64 __fastcall load_image(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r12
unsigned int v3; // ebx
__int64 v4; // r13
__int64 v5; // rbp
size_t v6; // r14
char *v7; // r15
__int64 v8; // rbp
int v9; // ebx
void *v10; // rdi
const char *v12; // rsi
__int64 v13; // rdi
const char *v14; // rax
__int64 v15; // [rsp+0h] [rbp-48h]
__int64 v16; // [rsp+8h] [rbp-40h]

v1 = FreeImage_Load(13LL, a1, 0LL);
v2 = v1;
if ( v1 )
{
v3 = FreeImage_GetWidth(v1);
v4 = (unsigned int)FreeImage_GetHeight(v2);
v16 = FreeImage_Allocate(v3, v4, 32LL, 16711680LL, 65280LL, 255LL);
if ( (unsigned int)FreeImage_Paste(v16, v2, 0LL, 0LL, 255LL) )
{
FreeImage_Unload(v2);
v5 = FreeImage_GetBits(v16);
v2 = image_create(v3, (unsigned int)v4);
if ( (int)v4 > 0 )
{
v6 = 4LL * (int)v3;
v15 = 4LL * -v3;
v7 = (char *)(v5 + 4LL * (int)((v4 - 1) * v3));
v8 = 0LL;
v9 = 0;
do
{
++v9;
v10 = (void *)(v8 + *(_QWORD *)(v2 + 8));
v8 += v6;
memcpy(v10, v7, v6);
v7 += v15;
}
while ( (_DWORD)v4 != v9 );
}
FreeImage_Unload(v16);
}
else
{
v12 = (const char *)geterrmsg();
seterrmsg("FreeImage_Paste: %s", v12);
v13 = v2;
v2 = 0LL;
FreeImage_Unload(v13);
FreeImage_Unload(v16);
}
}
else
{
v14 = (const char *)geterrmsg();
seterrmsg("FreeImage_Load: %s", v14);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // r12
unsigned int v3; // ebx
__int64 v4; // r13
__int64 v5; // rbp
size_t v6; // r14
char *v7; // r15
__int64 v8; // rbp
int v9; // ebx
void *v10; // rdi
const char *v12; // rsi
__int64 v13; // rdi
const char *v14; // rax
__int64 v15; // [rsp+0h] [rbp-48h]
__int64 v16; // [rsp+8h] [rbp-40h]

v1 = FreeImage_Load(13LL, a1, 0LL);
v2 = v1;
if ( v1 )
{
v3 = FreeImage_GetWidth(v1);
v4 = (unsigned int)FreeImage_GetHeight(v2);
v16 = FreeImage_Allocate(v3, v4, 32LL, 16711680LL, 65280LL, 255LL);
if ( (unsigned int)FreeImage_Paste(v16, v2, 0LL, 0LL, 255LL) )
{
FreeImage_Unload(v2);
v5 = FreeImage_GetBits(v16);
v2 = image_create(v3, (unsigned int)v4);
if ( (int)v4 > 0 )
{
v6 = 4LL * (int)v3;
v15 = 4LL * -v3;
v7 = (char *)(v5 + 4LL * (int)((v4 - 1) * v3));
v8 = 0LL;
v9 = 0;
do
{
++v9;
v10 = (void *)(v8 + *(_QWORD *)(v2 + 8));
v8 += v6;
memcpy(v10, v7, v6);
v7 += v15;
}
while ( (_DWORD)v4 != v9 );
}
FreeImage_Unload(v16);
}
else
{
v12 = (const char *)geterrmsg();
seterrmsg("FreeImage_Paste: %s", v12);
v13 = v2;
v2 = 0LL;
FreeImage_Unload(v13);
FreeImage_Unload(v16);
}
}
else
{
v14 = (const char *)geterrmsg();
seterrmsg("FreeImage_Load: %s", v14);
}
return v2;
}

original_code:
image *load_image(const char *path)
{
 FIBITMAP *src;
 FIBITMAP *dest;
 int width, height;
 int ok;
 int x, y;
 image *val = ((void *)0);
 color *bitmap;
 src = FreeImage_Load(FIF_PNG, path, 0);
 if(src == ((void *)0)) {
  seterrmsg("FreeImage_Load: %s", geterrmsg());
  return ((void *)0);
 }
 width = FreeImage_GetWidth(src);
 height = FreeImage_GetHeight(src);
 dest = FreeImage_Allocate(width, height, 32,
  0x00FF0000,
  0x0000FF00,
  0x000000FF);
 ok = FreeImage_Paste(dest, src, 0, 0, 255);
 if(!ok) {
  seterrmsg("FreeImage_Paste: %s", geterrmsg());
  FreeImage_Unload(src);
  FreeImage_Unload(dest);
  return ((void *)0);
 }
 FreeImage_Unload(src);
 bitmap = (color *)FreeImage_GetBits(dest);
 val = image_create(width, height);
 for(y = 0; y < height; y++)
  memcpy(&(val->pix[y * width]), &(bitmap[(height - 1 - y) * width]), width * sizeof(color));
 FreeImage_Unload(dest);
 return val;
}

canonical_original_code:
struct _image *load_image(char *path)
{
 struct FIBITMAP *src;
 struct FIBITMAP *dest;
 int width; int height;
 int ok;
 int x; int y;
 struct _image *val = ((void *)0);
 unsigned int *bitmap;
 src = FreeImage_Load(FIF_PNG, path, 0);
 if(src == ((void *)0)) {
  seterrmsg("FreeImage_Load: %s", geterrmsg());
  return ((void *)0);
 }
 width = FreeImage_GetWidth(src);
 height = FreeImage_GetHeight(src);
 dest = FreeImage_Allocate(width, height, 32,
  0x00FF0000,
  0x0000FF00,
  0x000000FF);
 ok = FreeImage_Paste(dest, src, 0, 0, 255);
 if(!ok) {
  seterrmsg("FreeImage_Paste: %s", geterrmsg());
  FreeImage_Unload(src);
  FreeImage_Unload(dest);
  return ((void *)0);
 }
 FreeImage_Unload(src);
 bitmap = (unsigned int *)FreeImage_GetBits(dest);
 val = image_create(width, height);
 for(y = 0; y < height; y++)
  memcpy(&(val->pix[y * width]), &(bitmap[(height - 1 - y) * width]), width * sizeof(color));
 FreeImage_Unload(dest);
 return val;
}

variable_types:
path
char *

variable_types:
src
struct FIBITMAP { void *data; } *

variable_types:
dest
struct FIBITMAP { void *data; } *

variable_types: width int

variable_types: height int

variable_types: ok int

variable_types: x int

variable_types: y int

variable_types: struct _image { int w; unsigned int *pix; void *private; } *

variable_types:
bitmap
unsigned int *


repo: ivartj/platformer

decompiled_code:
void *array_create()
{
return calloc(1uLL, 0x10uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(1uLL, 0x10uLL);
}

original_code:
array *array_create(void)
{
 return (array *)calloc(1, sizeof(array));
}

canonical_original_code:
struct _array *array_create()
{
 return (struct _array *)calloc(1, sizeof(array));
}

return_type: struct _array { int len; void **els; } *


decompiled_code:
__int64 __fastcall array_add(unsigned int *a1, __int64 a2)
{
__int64 result; // rax
void *v5; // rdi
int v6; // eax
size_t v7; // rsi
void *v8; // rax

result = *a1;
v5 = (void *)*((_QWORD *)a1 + 1);
if ( (_DWORD)result == a1[1] )
{
if ( (_DWORD)result )
{
v6 = 2 * result;
v7 = 8LL * v6;
}
else
{
v7 = 2048LL;
v6 = 256;
}
a1[1] = v6;
v8 = realloc(v5, v7);
*((_QWORD *)a1 + 1) = v8;
v5 = v8;
result = *a1;
}
*a1 = result + 1;
*((_QWORD *)v5 + (int)result) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, __int64 a2)
{
__int64 result; // rax
void *v5; // rdi
int v6; // eax
size_t v7; // rsi
void *v8; // rax

result = *a1;
v5 = (void *)*((_QWORD *)a1 + 1);
if ( (_DWORD)result == a1[1] )
{
if ( (_DWORD)result )
{
v6 = 2 * result;
v7 = 8LL * v6;
}
else
{
v7 = 2048LL;
v6 = 256;
}
a1[1] = v6;
v8 = realloc(v5, v7);
*((_QWORD *)a1 + 1) = v8;
v5 = v8;
result = *a1;
}
*a1 = result + 1;
*((_QWORD *)v5 + (int)result) = a2;
return result;
}

original_code:
int array_add(array *a, void *el)
{
 if(a->len == a->cap) {
  if(a->cap == 0)
   a->cap = 256;
  else
   a->cap <<= 1;
  a->els = realloc(a->els, a->cap * sizeof(void *));
 }
 a->els[a->len++] = el;
 return a->len - 1;
}

canonical_original_code:
int array_add(struct _array *a, void *el)
{
 if(a->len == a->cap) {
  if(a->cap == 0)
   a->cap = 256;
  else
   a->cap <<= 1;
  a->els = realloc(a->els, a->cap * sizeof(void *));
 }
 a->els[a->len++] = el;
 return a->len - 1;
}

variable_types: struct _array { int len; void **els; } *

variable_types:
el
void *

return_type: int


decompiled_code:
__int64 __fastcall array_get(__int64 a1, int a2)
{
__int64 result; // rax

if ( *(_DWORD *)a1 <= a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 result; // rax

if ( *(_DWORD *)a1 <= a2 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * a2);
return result;
}

original_code:
void *array_get(array *a, int idx)
{
 if(idx >= a->len)
  return ((void *)0);
 return a->els[idx];
}

canonical_original_code:
void *array_get(struct _array *a, int idx)
{
 if(idx >= a->len)
  return ((void *)0);
 return a->els[idx];
}

variable_types: idx int

return_type: void *


rgba

decompiled_code:
__int64 __fastcall rgba(double a1, double a2, double a3, double a4)
{
return (unsigned __int8)(int)(a3 * 255.0) | ((((((unsigned __int8)(int)(a4 * 255.0) << 8) | (unsigned __int8)(int)(a1 * 255.0)) << 8) | (unsigned int)(unsigned __int8)(int)(a2 * 255.0)) << 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(double a1, double a2, double a3, double a4)
{
return (unsigned __int8)(int)(a3 * 255.0) | ((((((unsigned __int8)(int)(a4 * 255.0) << 8) | (unsigned __int8)(int)(a1 * 255.0)) << 8) | (unsigned int)(unsigned __int8)(int)(a2 * 255.0)) << 8);
}

canonical_original_code:
unsigned int rgba(double r, double g, double b, double a)
{
 unsigned int c;
 c = 0;
 c |= (unsigned char)(a * 255.0); c <<= 8;
 c |= (unsigned char)(r * 255.0); c <<= 8;
 c |= (unsigned char)(g * 255.0); c <<= 8;
 c |= (unsigned char)(b * 255.0);
 return c;
}

variable_types: r double

variable_types: g double

variable_types: b double

variable_types: a double

variable_types:
c
unsigned int

return_type: unsigned int


rgb

decompiled_code:
__int64 __fastcall rgb(double a1, double a2, double a3)
{
return (unsigned __int8)(int)(a3 * 255.0) | (((unsigned __int8)(int)(a2 * 255.0) | ((unsigned __int8)(int)(a1 * 255.0) << 8)) << 8) | 0xFF000000;
}

canonical_decompiled_code:
__int64 __fastcall func1(double a1, double a2, double a3)
{
return (unsigned __int8)(int)(a3 * 255.0) | (((unsigned __int8)(int)(a2 * 255.0) | ((unsigned __int8)(int)(a1 * 255.0) << 8)) << 8) | 0xFF000000;
}

canonical_original_code:
unsigned int rgb(double r, double g, double b)
{
 unsigned int c;
 double a;
 a = 1.0;
 c = 0;
 c |= (unsigned char)(a * 255.0); c <<= 8;
 c |= (unsigned char)(r * 255.0); c <<= 8;
 c |= (unsigned char)(g * 255.0); c <<= 8;
 c |= (unsigned char)(b * 255.0);
 return c;
}


getrgb

decompiled_code:
__int64 __fastcall getrgb(int a1, double *a2, double *a3, double *a4)
{
__int64 result; // rax

result = (unsigned __int8)a1;
*a2 = (double)BYTE2(a1) / 255.0;
*a3 = (double)BYTE1(a1) / 255.0;
*a4 = (double)(unsigned __int8)a1 / 255.0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, double *a2, double *a3, double *a4)
{
__int64 result; // rax

result = (unsigned __int8)a1;
*a2 = (double)BYTE2(a1) / 255.0;
*a3 = (double)BYTE1(a1) / 255.0;
*a4 = (double)(unsigned __int8)a1 / 255.0;
return result;
}

variable_types:
r
double *

variable_types:
g
double *

variable_types:
b
double *

return_type: void


decompiled_code:
__int64 __fastcall prime_check(int a1)
{
int v1; // ecx
int v2; // ebp
int v3; // ecx

v1 = prime_get(0LL);
if ( a1 < v1 * v1 )
return 1LL;
v2 = 0;
if ( a1 % v1 )
{
while ( 1 )
{
v3 = prime_get((unsigned int)++v2);
if ( v3 * v3 > a1 )
break;
if ( !(a1 % v3) )
return 0LL;
}
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // ecx
int v2; // ebp
int v3; // ecx

v1 = func3(0LL);
if ( a1 < v1 * v1 )
return 1LL;
v2 = 0;
if ( a1 % v1 )
{
while ( 1 )
{
v3 = func3((unsigned int)++v2);
if ( v3 * v3 > a1 )
break;
if ( !(a1 % v3) )
return 0LL;
}
return 1LL;
}
return 0LL;
}

original_code:
int prime_check(int num)
{
 int i;
 int prime;
 for(prime = prime_get(i = 0);
     (prime * prime <= num) && (num % prime != 0);
     prime = prime_get(++i));
 if(prime * prime > num)
  return 1;
 else
  return 0;
}

variable_types: num int

variable_types: i int

variable_types: prime int


decompiled_code:
__int64 __fastcall prime_get(int a1)
{
while ( len <= a1 )
inc_isra_0();
return *((unsigned int *)primes + a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
while ( len <= a1 )
func2();
return *((unsigned int *)primes + a1);
}

original_code:
int prime_get(int idx)
{
 while(len <= idx)
  inc();
 return primes[idx];
}


decompiled_code:
__int64 __fastcall prime_above(int a1)
{
unsigned int i; // er12

for ( i = a1 + 1; !(unsigned int)prime_check(i); ++i )
;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
unsigned int i; // er12

for ( i = a1 + 1; !(unsigned int)func1(i); ++i )
;
return i;
}

original_code:
int prime_above(int num)
{
 for(++num; !prime_check(num); num++);
 return num;
}


lockcanvas

decompiled_code:
_QWORD *lockcanvas()
{
__int64 v0; // rbp
_QWORD *result; // rax
int v2; // edx

v0 = canvas;
if ( *(_DWORD *)(canvas + 40) || (*(_DWORD *)canvas & 0x4005) != 0 )
{
SDL_LockSurface(canvas);
result = (_QWORD *)video;
v0 = canvas;
if ( video )
goto LABEL_4;
LABEL_6:
result = calloc(1uLL, 0x18uLL);
video = (__int64)result;
goto LABEL_4;
}
result = (_QWORD *)video;
if ( !video )
goto LABEL_6;
LABEL_4:
result[1] = *(_QWORD *)(v0 + 32);
*(_DWORD *)result = *(_DWORD *)(v0 + 16);
v2 = *(_DWORD *)(v0 + 20);
result[2] = v0;
*((_DWORD *)result + 1) = v2;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
__int64 v0; // rbp
_QWORD *result; // rax
int v2; // edx

v0 = canvas;
if ( *(_DWORD *)(canvas + 40) || (*(_DWORD *)canvas & 0x4005) != 0 )
{
SDL_LockSurface(canvas);
result = (_QWORD *)video;
v0 = canvas;
if ( video )
goto LABEL_4;
LABEL_6:
result = calloc(1uLL, 0x18uLL);
video = (__int64)result;
goto LABEL_4;
}
result = (_QWORD *)video;
if ( !video )
goto LABEL_6;
LABEL_4:
result[1] = *(_QWORD *)(v0 + 32);
*(_DWORD *)result = *(_DWORD *)(v0 + 16);
v2 = *(_DWORD *)(v0 + 20);
result[2] = v0;
*((_DWORD *)result + 1) = v2;
return result;
}

original_code:
void lockcanvas(void)
{
 if((canvas->offset || ((canvas->flags & (0x00000001|0x00000004|0x00004000)) != 0)))
  SDL_LockSurface(canvas);
 if(video == ((void *)0))
  video = calloc(1, sizeof(image));
 video->pix = canvas->pixels;
 video->w = canvas->w;
 video->h = canvas->h;
 video->private = canvas;
}

canonical_original_code:
void lockcanvas()
{
 if((canvas->offset || ((canvas->flags & (0x00000001|0x00000004|0x00004000)) != 0)))
  SDL_LockSurface(canvas);
 if(video == ((void *)0))
  video = calloc(1, sizeof(image));
 video->pix = canvas->pixels;
 video->w = canvas->w;
 video->h = canvas->h;
 video->private = canvas;
}


unlockcanvas

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

result = *(unsigned int *)(canvas + 40);
if ( (_DWORD)result || (*(_DWORD *)canvas & 0x4005) != 0 )
result = SDL_UnlockSurface();
return result;
}

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

result = *(unsigned int *)(canvas + 40);
if ( (_DWORD)result || (*(_DWORD *)canvas & 0x4005) != 0 )
result = SDL_UnlockSurface();
return result;
}

original_code:
void unlockcanvas(void)
{
 if((canvas->offset || ((canvas->flags & (0x00000001|0x00000004|0x00004000)) != 0)))
  SDL_UnlockSurface(canvas);
}

canonical_original_code:
void unlockcanvas()
{
 if((canvas->offset || ((canvas->flags & (0x00000001|0x00000004|0x00004000)) != 0)))
  SDL_UnlockSurface(canvas);
}


decompiled_code:
__int64 sdl_init()
{
__int64 result; // rax
const char *v1; // rax

if ( sdl_initialized )
return 0LL;
if ( (unsigned int)SDL_Init(32LL) )
{
v1 = (const char *)SDL_GetError();
result = seterrmsg("SDL failed to initialize: %s", v1);
}
else
{
atexit((void (*)(void))&SDL_Quit);
result = 0LL;
sdl_initialized = 1;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
const char *v1; // rax

if ( sdl_initialized )
return 0LL;
if ( (unsigned int)SDL_Init(32LL) )
{
v1 = (const char *)SDL_GetError();
result = seterrmsg("SDL failed to initialize: %s", v1);
}
else
{
atexit((void (*)(void))&SDL_Quit);
result = 0LL;
sdl_initialized = 1;
}
return result;
}

original_code:
int sdl_init(void)
{
 int err;
 if(sdl_initialized)
  return 0;
 err = SDL_Init(0x00000020);
 if(err)
  return seterrmsg("SDL failed to initialize: %s", SDL_GetError());
 atexit(SDL_Quit);
 sdl_initialized = 1;
 return 0;
}

canonical_original_code:
int sdl_init()
{
 int err;
 if(sdl_initialized)
  return 0;
 err = SDL_Init(0x00000020);
 if(err)
  return seterrmsg("SDL failed to initialize: %s", SDL_GetError());
 atexit(SDL_Quit);
 sdl_initialized = 1;
 return 0;
}

variable_types: err int


decompiled_code:
__int64 __fastcall video_init(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // rsi
__int64 v5; // rsi

v2 = sdl_init();
if ( v2 )
return v2;
canvas = SDL_CreateRGBSurface(1LL, a1, a2, 32LL, 16711680LL, 65280LL, 255LL, -16777216LL);
if ( canvas )
{
window = SDL_SetVideoMode(a1, a2, 32LL, 1LL);
if ( window )
{
lockcanvas();
result = v2;
}
else
{
v5 = SDL_GetError();
result = seterrmsg("Failed to open SDL window: %s", v5);
}
}
else
{
v4 = SDL_GetError();
result = seterrmsg("Failed to create SDL canvas: %s", v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12
__int64 result; // rax
__int64 v4; // rsi
__int64 v5; // rsi

v2 = func3();
if ( v2 )
return v2;
canvas = SDL_CreateRGBSurface(1LL, a1, a2, 32LL, 16711680LL, 65280LL, 255LL, -16777216LL);
if ( canvas )
{
window = SDL_SetVideoMode(a1, a2, 32LL, 1LL);
if ( window )
{
func0();
result = v2;
}
else
{
v5 = SDL_GetError();
result = seterrmsg("Failed to open SDL window: %s", v5);
}
}
else
{
v4 = SDL_GetError();
result = seterrmsg("Failed to create SDL canvas: %s", v4);
}
return result;
}

original_code:
int video_init(int w, int h)
{
 int err;
 err = sdl_init();
 if(err)
  return err;
 canvas = SDL_CreateRGBSurface(0x00000001, w, h, 32,
  0x00FF0000,
  0x0000FF00,
  0x000000FF,
  0xFF000000);
 if(canvas == ((void *)0))
  return seterrmsg("Failed to create SDL canvas: %s", SDL_GetError());
 window = SDL_SetVideoMode(w, h, 32, 0x00000001);
 if(window == ((void *)0))
  return seterrmsg("Failed to open SDL window: %s", SDL_GetError());
 lockcanvas();
 return 0;
}

variable_types: w int

variable_types: h int


decompiled_code:
_QWORD *video_update()
{
unlockcanvas();
SDL_UpperBlit(canvas, 0LL, window, 0LL);
SDL_Flip(window);
return lockcanvas();
}

canonical_decompiled_code:
_QWORD *func5()
{
func1();
SDL_UpperBlit(canvas, 0LL, window, 0LL);
SDL_Flip(window);
return func0();
}

original_code:
void video_update(void)
{
 unlockcanvas();
 SDL_UpperBlit(canvas, ((void *)0), window, ((void *)0));
 SDL_Flip(window);
 lockcanvas();
}

canonical_original_code:
void video_update()
{
 unlockcanvas();
 SDL_UpperBlit(canvas, ((void *)0), window, ((void *)0));
 SDL_Flip(window);
 lockcanvas();
}


blitxymask

decompiled_code:
__int64 blitxymask()
{
return seterrmsg("Unimplemented method blitxymask");
}

canonical_decompiled_code:
__int64 func11()
{
return seterrmsg("Unimplemented method blitxymask");
}

original_code:
int blitxymask(image *src, image *dest, int x, int y, image *mask)
{
 return seterrmsg("Unimplemented method blitxymask");
}

canonical_original_code:
int blitxymask(struct _image *src, struct _image *dest, int x, int y, struct _image *mask)
{
 return seterrmsg("Unimplemented method blitxymask");
}

variable_types: struct _image { int w; unsigned int *pix; void *private; } *

variable_types:
dest
struct _image *

variable_types: x int

variable_types: y int

variable_types:
mask
struct _image *


decompiled_code:
__int64 __fastcall ps2rect(unsigned int a1, signed int a2, signed int a3, signed int a4)
{
__int64 v4; // rax

v4 = (unsigned int)a2;
if ( (int)a1 >= a3 )
{
a1 = a3;
if ( a2 < a4 )
return (v4 << 32) | a1;
LABEL_5:
v4 = (unsigned int)a4;
return (v4 << 32) | a1;
}
if ( a2 >= a4 )
goto LABEL_5;
return (v4 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, signed int a2, signed int a3, signed int a4)
{
__int64 v4; // rax

v4 = (unsigned int)a2;
if ( (int)a1 >= a3 )
{
a1 = a3;
if ( a2 < a4 )
return (v4 << 32) | a1;
LABEL_5:
v4 = (unsigned int)a4;
return (v4 << 32) | a1;
}
if ( a2 >= a4 )
goto LABEL_5;
return (v4 << 32) | a1;
}

original_code:
rect ps2rect(int x, int y, int x2, int y2)
{
 rect r;
 if(x < x2) {
  r.x = x;
  r.w = x2 - x;
 } else {
  r.x = x2;
  r.w = x - x2;
 }
 if(y < y2) {
  r.y = y;
  r.h = y2 - y;
 } else {
  r.y = y2;
  r.h = y - y2;
 }
 return r;
}

canonical_original_code:
struct rect ps2rect(int x, int y, int x2, int y2)
{
 struct rect r;
 if(x < x2) {
  r.x = x;
  r.w = x2 - x;
 } else {
  r.x = x2;
  r.w = x - x2;
 }
 if(y < y2) {
  r.y = y;
  r.h = y2 - y;
 } else {
  r.y = y2;
  r.h = y - y2;
 }
 return r;
}

variable_types:
r
struct rect { int x; }

return_type: struct rect { int x; }


original_code:
int rect_isoverlap(rect *a, rect *b)
{
 if(b->x >= a->x + a->w)
  return 0;
 if(a->x >= b->x + b->w)
  return 0;
 if(b->y >= a->y + a->h)
  return 0;
 if(a->y >= b->y + b->h)
  return 0;
 return 1;
}

canonical_original_code:
int rect_isoverlap(struct rect *a, struct rect *b)
{
 if(b->x >= a->x + a->w)
  return 0;
 if(a->x >= b->x + b->w)
  return 0;
 if(b->y >= a->y + a->h)
  return 0;
 if(a->y >= b->y + b->h)
  return 0;
 return 1;
}

variable_types:
a
struct rect { int x; } *

variable_types:
b
struct rect *


original_code:
int rect_iswithin(rect *a, rect *b)
{
 if(a->x > b->x)
  return 0;
 if(a->x + a->w < b->x + b->w)
  return 0;
 if(a->y > b->y)
  return 0;
 if(a->y + a->h < b->y + b->h)
  return 0;
 return 1;
}

canonical_original_code:
int rect_iswithin(struct rect *a, struct rect *b)
{
 if(a->x > b->x)
  return 0;
 if(a->x + a->w < b->x + b->w)
  return 0;
 if(a->y > b->y)
  return 0;
 if(a->y + a->h < b->y + b->h)
  return 0;
 return 1;
}


iterate

decompiled_code:
__int64 __fastcall iterate(__int64 a1)
{
return (*(__int64 (**)(void))((char *)&off_8 + a1))();
}

original_code:
int iterate(iter *i, void *retval)
{
 return i->next(i, retval);
}

canonical_original_code:
int iterate(struct _iter *i, void *retval)
{
 return i->next(i, retval);
}

variable_types: struct _iter { union _data { void *v; int i; double d; } data; int (*next)(struct _iter *i, void *retval); } *

variable_types:
retval
void *

user_defined_types: struct _iter { union _data data; int (*next)(struct _iter *i, void *retval); }


repo: iveteran/HelloWorld

decompiled_code:
int __fastcall looking_enter(const void *a1)
{
return printf("looking_enter %p\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1)
{
return printf("looking_enter %p\n", a1);
}

original_code:
void looking_enter(void *node, void *object, struct node_operations *ops)
{
    printf("looking_enter %p\n", node);
}

variable_types:
node
void *

variable_types:
object
void *

variable_types: struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *


decompiled_code:
int __fastcall looking_exit(const void *a1)
{
return printf("looking_exit %p\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const void *a1)
{
return printf("looking_exit %p\n", a1);
}

original_code:
void looking_exit(void *node, void *object, struct node_operations *ops)
{
    printf("looking_exit %p\n", node);
}

user_defined_types: struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); }


decompiled_code:
int __fastcall standing_enter(const void *a1)
{
return printf("standing_enter %p\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const void *a1)
{
return printf("standing_enter %p\n", a1);
}

original_code:
void standing_enter(void *node, void *object, struct node_operations *ops)
{
    printf("standing_enter %p\n", node);
}


decompiled_code:
int __fastcall standing_exit(const void *a1)
{
return printf("standing_exit %p\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(const void *a1)
{
return printf("standing_exit %p\n", a1);
}

original_code:
void standing_exit(void *node, void *object, struct node_operations *ops)
{
    printf("standing_exit %p\n", node);
}


decompiled_code:
__int64 __fastcall looking_tick(const void *a1, __int64 a2, __int64 a3)
{
__int64 (__fastcall *v4)(__int64); // rbx
__int64 v5; // rax

printf("looking_tick %p\n", a1);
v4 = *(__int64 (__fastcall **)(__int64))(a3 + 8);
v5 = node_control(a1);
return v4(v5);
}

canonical_decompiled_code:
__int64 __fastcall func4(const void *a1, __int64 a2, __int64 a3)
{
__int64 (__fastcall *v4)(__int64); // rbx
__int64 v5; // rax

printf("looking_tick %p\n", a1);
v4 = *(__int64 (__fastcall **)(__int64))(a3 + 8);
v5 = node_control(a1);
return v4(v5);
}

original_code:
void looking_tick(void *node, void *object, struct node_operations *ops)
{
    printf("looking_tick %p\n", node);
    ops->success(node_control(node));
}


decompiled_code:
int __fastcall running_enter(const void *a1)
{
int *v1; // rax

v1 = (int *)node_blackboard();
return printf("running_enter %p %s\n", a1, (const char *)DIR_NAME[*v1]);
}

canonical_decompiled_code:
int __fastcall func5(const void *a1)
{
int *v1; // rax

v1 = (int *)node_blackboard();
return printf("running_enter %p %s\n", a1, (const char *)DIR_NAME[*v1]);
}

original_code:
void running_enter(void *node, void *object, struct node_operations *ops)
{
    int dir = *(int *) node_blackboard(node);
    printf("running_enter %p %s\n", node, DIR_NAME[dir]);
}

variable_types: dir int


decompiled_code:
int __fastcall running_exit(const void *a1)
{
int *v1; // rax

v1 = (int *)node_blackboard();
return printf("running_exit %p %s\n", a1, (const char *)DIR_NAME[*v1]);
}

canonical_decompiled_code:
int __fastcall func6(const void *a1)
{
int *v1; // rax

v1 = (int *)node_blackboard();
return printf("running_exit %p %s\n", a1, (const char *)DIR_NAME[*v1]);
}

original_code:
void running_exit(void *node, void *object, struct node_operations *ops)
{
    int dir = *(int *) node_blackboard(node);
    printf("running_exit %p %s\n", node, DIR_NAME[dir]);
}


decompiled_code:
__int64 __fastcall running_tick(const void *a1, __int64 a2, __int64 a3)
{
int *v4; // rax
__int64 (__fastcall *v5)(__int64); // rbx
__int64 v6; // rax

v4 = (int *)node_blackboard();
printf("running_tick %p %s\n", a1, (const char *)DIR_NAME[*v4]);
v5 = *(__int64 (__fastcall **)(__int64))(a3 + 8);
v6 = node_control(a1);
return v5(v6);
}

canonical_decompiled_code:
__int64 __fastcall func7(const void *a1, __int64 a2, __int64 a3)
{
int *v4; // rax
__int64 (__fastcall *v5)(__int64); // rbx
__int64 v6; // rax

v4 = (int *)node_blackboard();
printf("running_tick %p %s\n", a1, (const char *)DIR_NAME[*v4]);
v5 = *(__int64 (__fastcall **)(__int64))(a3 + 8);
v6 = node_control(a1);
return v5(v6);
}

original_code:
void running_tick(void *node, void *object, struct node_operations *ops)
{
    int dir = *(int *) node_blackboard(node);
    printf("running_tick %p %s\n", node, DIR_NAME[dir]);
    ops->success(node_control(node));
}


decompiled_code:
__int64 __fastcall standing_tick(const void *a1, __int64 a2, __int64 (__fastcall **a3)(__int64))
{
int *v4; // rbx
__int64 v5; // rdx
__int64 (__fastcall *v6)(__int64); // rbx
__int64 v7; // rdi

v4 = (int *)node_blackboard();
v5 = (unsigned int)(*v4 + 1);
*v4 = v5;
printf("standing_tick %p, stanging_count %d\n", a1, v5);
if ( *v4 > 4 )
{
v6 = a3[1];
}
else if ( (unsigned int)(*v4 - 3) <= 1 )
{
v6 = a3[2];
}
else
{
v6 = *a3;
}
v7 = node_control(a1);
return v6(v7);
}

canonical_decompiled_code:
__int64 __fastcall func8(const void *a1, __int64 a2, __int64 (__fastcall **a3)(__int64))
{
int *v4; // rbx
__int64 v5; // rdx
__int64 (__fastcall *v6)(__int64); // rbx
__int64 v7; // rdi

v4 = (int *)node_blackboard();
v5 = (unsigned int)(*v4 + 1);
*v4 = v5;
printf("standing_tick %p, stanging_count %d\n", a1, v5);
if ( *v4 > 4 )
{
v6 = a3[1];
}
else if ( (unsigned int)(*v4 - 3) <= 1 )
{
v6 = a3[2];
}
else
{
v6 = *a3;
}
v7 = node_control(a1);
return v6(v7);
}

original_code:
void standing_tick(void *node, void *object, struct node_operations *ops)
{
    int *standing_count = node_blackboard(node);
    *standing_count = *standing_count+1;
    printf("standing_tick %p, stanging_count %d\n", node, *standing_count);
    if (*standing_count > 4)
        ops->success(node_control(node));
    else if (*standing_count >= 3 && *standing_count <= 4)
        ops->fail(node_control(node));
    else
        ops->running(node_control(node));
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int (__fastcall **v3)(const void *); // r12
__int64 v4; // rax
int (__fastcall *v5)(const void *); // rbx
void *v6; // rax
__int64 *v7; // rbx
__int64 v8; // rax
int (__fastcall *v9)(const void *); // r13
__int64 *v10; // rsi
unsigned int v11; // ebx
void *v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // r12
__int64 v16; // rsi
__int64 v18[2]; // [rsp+0h] [rbp-78h] BYREF
__int64 v19[4]; // [rsp+10h] [rbp-68h] BYREF
int (__fastcall *v20)(const void *); // [rsp+30h] [rbp-48h] BYREF
void *v21; // [rsp+38h] [rbp-40h]
int (__fastcall *v22)(const void *); // [rsp+40h] [rbp-38h]

behaviourtree_init(argc, argv, envp);
v20 = standing_enter;
LODWORD(v19[0]) = 0;
v3 = &v20;
v21 = standing_tick;
v22 = standing_exit;
v4 = node_create(&v20, v19);
v20 = looking_enter;
v21 = looking_tick;
v5 = (int (__fastcall *)(const void *))v4;
v22 = looking_exit;
v6 = (void *)node_create(&v20, 0LL);
v20 = v5;
v7 = v18;
v21 = v6;
v8 = branch_create(1LL, 2LL, &v20);
v19[0] = (__int64)running_enter;
v19[1] = (__int64)running_tick;
v9 = (int (__fastcall *)(const void *))v8;
v18[0] = 0x400000002LL;
v19[2] = (__int64)running_exit;
v18[1] = 0x800000006LL;
do
{
v10 = v7;
v7 = (__int64 *)((char *)v7 + 4);
*v3++ = (int (__fastcall *)(const void *))node_create(v19, v10);
}
while ( v7 != v19 );
v11 = 0;
v12 = (void *)branch_create(2LL, 4LL, &v20);
v20 = v9;
v21 = v12;
v13 = branch_create(0LL, 2LL, &v20);
v14 = behaviourtree_create(v13);
LODWORD(v19[0]) = 1;
v15 = v14;
do
{
v16 = v11++;
printf(">>> behaviourtree_tick %d\n", v16);
behaviourtree_tick(v15, v19);
}
while ( v11 != 10 );
putchar(10);
behaviourtree_tick(v15, v19);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    behaviourtree_init();
    void *priority_checking_node = 0;
    void *random_running_node = 0;
    {
        void *standing_node = 0;
        void *looking_node = 0;
        {
            struct node_callbacks standing_cbs = {
                .enter = standing_enter,
                .tick = standing_tick,
                .exit = standing_exit
            };
            int standing_count = 0;
            standing_node = node_create(&standing_cbs, &standing_count);
        }
        {
            struct node_callbacks looking_cbs = {
                .enter = looking_enter,
                .tick = looking_tick,
                .exit = looking_exit
            };
            looking_node = node_create(&looking_cbs, 0);
        }
        void *node_list[2] = { standing_node, looking_node };
        priority_checking_node = branch_create(BRANCH_TYPE_PRIORITY, 2, node_list);
    }
    {
        struct node_callbacks running_cbs = {
            .enter = running_enter,
            .tick = running_tick,
            .exit = running_exit
        };
        int running_dir[4] = { DIR_S, DIR_W, DIR_E, DIR_N };
        void *running_node[4];
        int i = 0;
        for (; i < 4; ++i)
        {
            running_node[i] = node_create(&running_cbs, &running_dir[i]);
        }
        random_running_node = branch_create(BRANCH_TYPE_RANDOM, 4, running_node);
    }
    void *node_list[2] = { priority_checking_node, random_running_node };
    void *branch = branch_create(BRANCH_TYPE_SEQUENCE, 2, node_list);
    void *tree = behaviourtree_create(branch);
    int ctx = 1;
    int tick = 0;
    for (tick = 0; tick < 10; ++tick)
    {
        printf(">>> behaviourtree_tick %d\n", tick);
        behaviourtree_tick(tree, (void *)&ctx);
    }
    printf("\n");
    behaviourtree_tick(tree, (void *)&ctx);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); }

variable_types: i int

variable_types:
branch
void *

variable_types:
tree
void *

variable_types: ctx int

variable_types: tick int

user_defined_types: struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); }


decompiled_code:
__int64 __fastcall node_running(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (**(__int64 (***)(void))(*(_QWORD *)v1 + 8LL))();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (**(__int64 (***)(void))(*(_QWORD *)v1 + 8LL))();
return result;
}

original_code:
void node_running(void *node)
{
    struct node* this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->running(this->control); } while(0);
    }
}

canonical_original_code:
void node_running(void *node)
{
    struct node *this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->running(this->control); } while(0);
    }
}

variable_types: struct node { struct node_vtable { struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); } *cbs; struct node_operations *ops; void (*release)(void *node); } *vtable; struct node *control; void *object; void *blackboard; } *

user_defined_types: struct node { struct node_vtable *vtable; struct node *control; void *object; void *blackboard; }

user_defined_types: struct node_vtable { struct node_callbacks *cbs; struct node_operations *ops; void (*release)(void *node); }


decompiled_code:
__int64 __fastcall node_success(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (*(__int64 (**)(void))(*(_QWORD *)(*(_QWORD *)v1 + 8LL) + 8LL))();
return result;
}

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

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (*(__int64 (**)(void))(*(_QWORD *)(*(_QWORD *)v1 + 8LL) + 8LL))();
return result;
}

original_code:
void node_success(void *node)
{
    struct node* this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->success(this->control); } while(0);
    }
}

canonical_original_code:
void node_success(void *node)
{
    struct node *this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->success(this->control); } while(0);
    }
}


decompiled_code:
__int64 __fastcall node_fail(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (*(__int64 (**)(void))(*(_QWORD *)(*(_QWORD *)v1 + 8LL) + 16LL))();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
result = (*(__int64 (**)(void))(*(_QWORD *)(*(_QWORD *)v1 + 8LL) + 16LL))();
return result;
}

original_code:
void node_fail(void *node)
{
    struct node* this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->fail(this->control); } while(0);
    }
}

canonical_original_code:
void node_fail(void *node)
{
    struct node *this = node;
    if (this->control)
    {
        do { this->control->vtable->ops->fail(this->control); } while(0);
    }
}


original_code:
void branch_enter(void *node, void *object, struct node_operations *ops)
{
    struct branch *this = node;
    if (!this->is_running)
    {
        this->node.object = object;
        this->running_idx = 0;
    }
}

variable_types: struct branch { struct node { struct node_vtable { struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); } *cbs; struct node_operations *ops; void (*release)(void *node); } *vtable; struct node *control; void *object; void *blackboard; } node; char is_running; int running_idx; int child_num; struct node *child_list[]; } *

user_defined_types: struct branch { struct node node; char is_running; int running_idx; int child_num; struct node *child_list[]; }


decompiled_code:
void branch_exit()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void branch_exit(void *node, void *object, struct node_operations *ops)
{
}


original_code:
void branch_running(void *node)
{
    struct branch *this = node;
    this->is_running = 1;
    do { this->node.control->vtable->ops->running(this->node.control); } while(0);
}


decompiled_code:
__int64 __fastcall behaviourtree_running(__int64 a1)
{
__int64 result; // rax

result = node_running(a1);
*(_BYTE *)(a1 + 40) = 0;
return result;
}

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

result = func0(a1);
*(_BYTE *)(a1 + 40) = 0;
return result;
}

original_code:
void behaviourtree_running(void *bt)
{
    struct behaviourtree *this = (struct behaviourtree *)bt;
    node_running((struct node *)this);
    this->started = 0;
}

variable_types:
bt
void *

variable_types: struct behaviourtree { struct node { struct node_vtable { struct node_callbacks { void (*enter)(void *node, void *object, struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *ops); void (*tick)(void *node, void *object, struct node_operations *ops); void (*exit)(void *node, void *object, struct node_operations *ops); } *cbs; struct node_operations *ops; void (*release)(void *node); } *vtable; struct node *control; void *object; void *blackboard; } node; struct branch { struct node node; char is_running; int running_idx; int child_num; struct node *child_list[]; } *root; char started; } *

user_defined_types: struct behaviourtree { struct node node; struct branch *root; char started; }


original_code:
void behaviourtree_success(void *bt)
{
    struct behaviourtree *this = (struct behaviourtree *)bt;
    do { (&this->root->node)->vtable->cbs->exit((&this->root->node), this->node.object, (&this->root->node)->control->vtable->ops); } while(0);
    this->started = 0;
    node_success((struct node *)this);
}


original_code:
void behaviourtree_fail(void *bt)
{
    struct behaviourtree *this = (struct behaviourtree *)bt;
    do { (&this->root->node)->vtable->cbs->exit((&this->root->node), this->node.object, (&this->root->node)->control->vtable->ops); } while(0);
    this->started = 0;
    node_fail((struct node *)this);
}


decompiled_code:
int __fastcall random_enter(__int64 a1, __int64 a2)
{
unsigned int v2; // edx

branch_enter(a1, a2);
v2 = (int)random() % *(_DWORD *)(a1 + 40);
*(_DWORD *)(a1 + 36) = v2;
return printf(">>> random_enter running_idx %d\n", v2);
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, __int64 a2)
{
unsigned int v2; // edx

func3(a1, a2);
v2 = (int)random() % *(_DWORD *)(a1 + 40);
*(_DWORD *)(a1 + 36) = v2;
return printf(">>> random_enter running_idx %d\n", v2);
}

original_code:
void random_enter(void *node, void *object, struct node_operations *ops)
{
    struct branch *this = node;
    branch_enter(this, object, ops);
    int rand = random();
    this->running_idx = rand % this->child_num;
    printf(">>> random_enter running_idx %d\n", this->running_idx);
}

variable_types: rand int


decompiled_code:
__int64 __fastcall node_release(__int64 a1)
{
return (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)a1 + 16LL))(a1);
}

original_code:
void node_release(struct node *this)
{
    this->vtable->release(this);
}


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

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

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

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

original_code:
void branch_release(void *node)
{
    struct branch *this = node;
    int i = 0;
    for (; i < this->child_num; ++i)
    {
        struct node *running_node = this->child_list[i];
        node_release(running_node);
    }
    free(this);
}

variable_types:
node
void *


decompiled_code:
void __fastcall behaviourtree_release(void *ptr)
{
node_release(*((_QWORD *)ptr + 4));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
func10(*((_QWORD *)ptr + 4));
free(ptr);
}

original_code:
void behaviourtree_release(void *bt)
{
    struct behaviourtree *this = bt;
    node_release((struct node *)this->root);
    free(this);
}


original_code:
void node_callrun(struct node *this, void *object)
{
    this->vtable->cbs->tick(this, object, this->vtable->ops);
}

variable_types:
object
void *


original_code:
void branch_run(struct branch *this, void *object)
{
    struct node *running_node = this->child_list[this->running_idx];
    if (!this->is_running)
    {
        do { running_node->vtable->cbs->enter(running_node, object, running_node->control->vtable->ops); } while(0);
    }
    do { running_node->vtable->cbs->tick(running_node, object, running_node->control->vtable->ops); } while(0);
}


decompiled_code:
__int64 __fastcall branch_tick(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 40);
if ( *(_DWORD *)(a1 + 36) < (int)result )
result = branch_run(a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 40);
if ( *(_DWORD *)(a1 + 36) < (int)result )
result = func15(a1, a2);
return result;
}

original_code:
void branch_tick(void *node, void *object, struct node_operations *ops)
{
    struct branch *this = node;
    if (this->running_idx < this->child_num)
    {
        branch_run(this, object);
    }
}

variable_types: struct node_operations { void (*running)(void *node); void (*success)(void *node); void (*fail)(void *node); } *


original_code:
void branch_success(void *node)
{
    struct branch *this = node;
    this->is_running = 0;
    struct node *running_node = this->child_list[this->running_idx];
    do { running_node->vtable->cbs->exit(running_node, this->node.object, running_node->control->vtable->ops); } while(0);
}


decompiled_code:
__int64 __fastcall sequence_success(__int64 a1)
{
int v1; // eax
__int64 result; // rax

branch_success(a1);
v1 = *(_DWORD *)(a1 + 36) + 1;
*(_DWORD *)(a1 + 36) = v1;
if ( v1 < *(_DWORD *)(a1 + 40) )
result = branch_run(a1, *(_QWORD *)(a1 + 16));
else
result = (*(__int64 (**)(void))(*(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL) + 8LL))();
return result;
}

original_code:
void sequence_success(void *node)
{
    struct branch *this = node;
    branch_success(this);
    this->running_idx++;
    if (this->running_idx < this->child_num)
    {
        branch_run(this, this->node.object);
    }
    else
    {
        do { this->node.control->vtable->ops->success(this->node.control); } while(0);
    }
}


decompiled_code:
__int64 __fastcall random_success(__int64 a1)
{
branch_success(a1);
return (*(__int64 (**)(void))(*(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL) + 8LL))();
}

original_code:
void random_success(void *node)
{
    struct branch *this = node;
    branch_success(this);
    do { this->node.control->vtable->ops->success(this->node.control); } while(0);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall priority_success(__int64 a1)
{
return random_success(a1);
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
return func19(a1);
}

original_code:
void priority_success(void *node)
{
    struct branch *this = node;
    branch_success(this);
    do { this->node.control->vtable->ops->success(this->node.control); } while(0);
}


decompiled_code:
__int64 __fastcall priority_fail(__int64 a1)
{
int v1; // eax
__int64 result; // rax

branch_success(a1);
v1 = *(_DWORD *)(a1 + 36) + 1;
*(_DWORD *)(a1 + 36) = v1;
if ( v1 < *(_DWORD *)(a1 + 40) )
result = branch_run(a1, *(_QWORD *)(a1 + 16));
else
result = (*(__int64 (**)(void))(*(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL) + 16LL))();
return result;
}

original_code:
void priority_fail(void *node)
{
    struct branch *this = node;
    branch_fail(this);
    this->running_idx++;
    if (this->running_idx < this->child_num)
    {
        branch_run(this, this->node.object);
    }
    else
    {
        do { this->node.control->vtable->ops->fail(this->node.control); } while(0);
    }
}


decompiled_code:
__int64 __fastcall sequence_fail(__int64 a1)
{
branch_success(a1);
return (*(__int64 (**)(void))(*(_QWORD *)(**(_QWORD **)(a1 + 8) + 8LL) + 16LL))();
}

original_code:
void sequence_fail(void *node)
{
    struct branch *this = node;
    branch_fail(this);
    do { this->node.control->vtable->ops->fail(this->node.control); } while(0);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall random_fail(__int64 a1)
{
return sequence_fail(a1);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1)
{
return func22(a1);
}

original_code:
void random_fail(void *node)
{
    struct branch *this = node;
    branch_fail(this);
    do { this->node.control->vtable->ops->fail(this->node.control); } while(0);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall branch_fail(__int64 a1)
{
return branch_success(a1);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1)
{
return func17(a1);
}

original_code:
void branch_fail(void *node)
{
    struct branch *this = node;
    this->is_running = 0;
    struct node *running_node = this->child_list[this->running_idx];
    do { running_node->vtable->cbs->exit(running_node, this->node.object, running_node->control->vtable->ops); } while(0);
}


original_code:
void behaviourtree_tick(void *bt, void *object)
{
    if (bt == 0) return;
    struct behaviourtree *this = (struct behaviourtree *)bt;
    if (this->started)
    {
        node_running(&this->node);
    }
    else
    {
        this->started = 1;
        this->node.object = object;
        do { (&this->root->node)->vtable->cbs->enter((&this->root->node), object, (&this->root->node)->control->vtable->ops); } while(0);
        node_callrun(&this->root->node, object);
    }
}


decompiled_code:
__int64 __fastcall node_control(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
void *node_control(void *node)
{
    struct node *this = node;
    return this->control;
}


decompiled_code:
__int64 __fastcall node_blackboard(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
void *node_blackboard(void *node)
{
    struct node *this = node;
    return this->blackboard;
}


decompiled_code:
int __fastcall example_enter(const void *a1, _DWORD *a2)
{
__int64 v2; // rdx

v2 = (unsigned int)(*a2 + 1);
*a2 = v2;
return printf("example_enter %p %d\n", a1, v2);
}

canonical_decompiled_code:
int __fastcall func0(const void *a1, _DWORD *a2)
{
__int64 v2; // rdx

v2 = (unsigned int)(*a2 + 1);
*a2 = v2;
return printf("example_enter %p %d\n", a1, v2);
}

original_code:
void example_enter(void *node, void *object, struct node_operations *ops)
{
    int *ctx = (int *)object;
    *ctx = *ctx + 1;
    printf("example_enter %p %d\n", node, *ctx);
}

variable_types:
ctx
int *


decompiled_code:
int __fastcall example_exit(const void *a1, _DWORD *a2)
{
__int64 v2; // rdx

v2 = (unsigned int)(*a2 + 1);
*a2 = v2;
return printf("example_exit %p %d\n", a1, v2);
}

canonical_decompiled_code:
int __fastcall func1(const void *a1, _DWORD *a2)
{
__int64 v2; // rdx

v2 = (unsigned int)(*a2 + 1);
*a2 = v2;
return printf("example_exit %p %d\n", a1, v2);
}

original_code:
void example_exit(void *node, void *object, struct node_operations *ops)
{
    int *ctx = (int *)object;
    *ctx = *ctx + 1;
    printf("example_exit %p %d\n", node, *ctx);
}


decompiled_code:
__int64 __fastcall example_tick(const void *a1, int *a2, __int64 (__fastcall **a3)(__int64))
{
__int64 v4; // rdx
__int64 (__fastcall *v5)(__int64); // rbx
__int64 v6; // rdi

v4 = (unsigned int)(*a2 + 1);
*a2 = v4;
printf("example_tick %p %d\n", a1, v4);
if ( (const void *)node_list == a1 )
{
v5 = a3[2];
}
else if ( *a2 <= 9 )
{
v5 = *a3;
}
else
{
v5 = a3[1];
}
v6 = node_control(a1);
return v5(v6);
}

canonical_decompiled_code:
__int64 __fastcall func2(const void *a1, int *a2, __int64 (__fastcall **a3)(__int64))
{
__int64 v4; // rdx
__int64 (__fastcall *v5)(__int64); // rbx
__int64 v6; // rdi

v4 = (unsigned int)(*a2 + 1);
*a2 = v4;
printf("example_tick %p %d\n", a1, v4);
if ( (const void *)node_list == a1 )
{
v5 = a3[2];
}
else if ( *a2 <= 9 )
{
v5 = *a3;
}
else
{
v5 = a3[1];
}
v6 = node_control(a1);
return v5(v6);
}

original_code:
void example_tick(void *node, void *object, struct node_operations *ops)
{
    int *ctx = (int *)object;
    *ctx = *ctx + 1;
    printf("example_tick %p %d\n", node, *ctx);
    if (node == node_list[0])
    {
        ops->fail(node_control(node));
        return;
    }
    if (*ctx < 10) ops->running(node_control(node));
    else ops->success(node_control(node));
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // r12
unsigned int v4; // ebx
const void *v5; // rax
__int64 v6; // rax
__int64 v7; // rbp
__int64 v8; // rsi
int v10; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v11[7]; // [rsp+10h] [rbp-38h] BYREF

v3 = 0LL;
behaviourtree_init(argc, argv, envp);
v11[0] = (__int64)example_enter;
v11[1] = (__int64)example_tick;
v11[2] = (__int64)example_exit;
do
{
v4 = 0;
node_list = node_create(v11, 0LL);
printf(">>> node_create %d %p\n", 0LL, (const void *)node_list);
v5 = (const void *)node_create(v11, 0LL);
*(&node_list + 1) = (__int64)v5;
printf(">>> node_create %d %p\n", 1LL, v5);
putchar(10);
v6 = branch_create((unsigned int)v3, 2LL, &node_list);
v7 = behaviourtree_create(v6);
printf(">>> branch_type %s\n", BRANCH_NAME_0[v3]);
v10 = 1;
do
{
v8 = v4++;
printf(">>> behaviourtree_tick %d\n", v8);
behaviourtree_tick(v7, &v10);
}
while ( v4 != 10 );
++v3;
putchar(10);
behaviourtree_release(v7);
}
while ( v3 != 3 );
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    behaviourtree_init();
    struct node_callbacks example_cbs = {
        .enter = example_enter,
        .tick = example_tick,
        .exit = example_exit
    };
    int begin_type = BRANCH_TYPE_BEGIN;
    int end_type = BRANCH_TYPE_COUNT;
    int running_type = begin_type;
    for (; running_type < end_type; ++running_type)
    {
        int i = 0;
        for (i = 0; i < 2; ++i)
        {
            node_list[i] = node_create(&example_cbs, 0);
            printf(">>> node_create %d %p\n", i, node_list[i]);
        }
        printf("\n");
        void *branch = branch_create(running_type, 2, node_list);
        void *tree = behaviourtree_create(branch);
        static const char *BRANCH_NAME[3] = { "SEQUENCE", "PRIORITY", "RANDOM" };
        printf(">>> branch_type %s\n", BRANCH_NAME[running_type]);
        int ctx = 1;
        int tick = 0;
        for (tick = 0; tick < 10; ++tick)
        {
            printf(">>> behaviourtree_tick %d\n", tick);
            behaviourtree_tick(tree, (void *)&ctx);
        }
        printf("\n");
        behaviourtree_release(tree);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    behaviourtree_init();
    struct node_callbacks example_cbs = {
        .enter = example_enter,
        .tick = example_tick,
        .exit = example_exit
    };
    int begin_type = BRANCH_TYPE_BEGIN;
    int end_type = BRANCH_TYPE_COUNT;
    int running_type = begin_type;
    for (; running_type < end_type; ++running_type)
    {
        int i = 0;
        for (i = 0; i < 2; ++i)
        {
            node_list[i] = node_create(&example_cbs, 0);
            printf(">>> node_create %d %p\n", i, node_list[i]);
        }
        printf("\n");
        void *branch = branch_create(running_type, 2, node_list);
        void *tree = behaviourtree_create(branch);
        static char *BRANCH_NAME[3] = { "SEQUENCE", "PRIORITY", "RANDOM" };
        printf(">>> branch_type %s\n", BRANCH_NAME[running_type]);
        int ctx = 1;
        int tick = 0;
        for (tick = 0; tick < 10; ++tick)
        {
            printf(">>> behaviourtree_tick %d\n", tick);
            behaviourtree_tick(tree, (void *)&ctx);
        }
        printf("\n");
        behaviourtree_release(tree);
    }
    return 0;
}

variable_types: argc int


fib

decompiled_code:
__int64 __fastcall fib(unsigned int a1, __int64 a2, __int64 a3)
{
int v3; // ebp
unsigned int i; // ebx
__int64 v5; // rdi

if ( a1 <= 1 )
return 1LL;
v3 = 0;
for ( i = a1; i > 1; i -= 2 )
{
v5 = i - 1;
v3 += fib(v5, a2, a3);
}
return (unsigned int)(v3 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, __int64 a2, __int64 a3)
{
int v3; // ebp
unsigned int i; // ebx
__int64 v5; // rdi

if ( a1 <= 1 )
return 1LL;
v3 = 0;
for ( i = a1; i > 1; i -= 2 )
{
v5 = i - 1;
v3 += func6(v5, a2, a3);
}
return (unsigned int)(v3 + 1);
}

original_code:
unsigned int fib(unsigned int n) {
    if (n == 0 || n == 1) {
        return 1;
    }
    return fib(n-1) + fib(n-2);
}

variable_types:
n
unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx

fib(40LL, argv, envp);
fib(40LL, argv, v3);
fib(40LL, argv, v4);
fib(40LL, argv, v5);
fib(40LL, argv, v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx

func6(40LL, argv, envp);
func6(40LL, argv, v3);
func6(40LL, argv, v4);
func6(40LL, argv, v5);
func6(40LL, argv, v6);
return 0;
}


repo: ivoarch/antiwm

decompiled_code:
void alrm_handler()
{
__int64 v0; // rbp
int v1; // ebx
__int64 v2; // rdi

puts("alarm recieved");
if ( num_screens > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
++v1;
v2 = v0 + screens;
v0 += 200LL;
hide_bar(v2);
}
while ( num_screens > v1 );
}
XFlush(dpy);
}

canonical_decompiled_code:
void func0()
{
__int64 v0; // rbp
int v1; // ebx
__int64 v2; // rdi

puts("alarm recieved");
if ( num_screens > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
++v1;
v2 = v0 + screens;
v0 += 200LL;
hide_bar(v2);
}
while ( num_screens > v1 );
}
XFlush(dpy);
}

original_code:
void
alrm_handler ()
{
  int i;
  printf ("alarm recieved\n");
  for (i=0; i<num_screens; i++)
    {
      hide_bar (&screens[i]);
    }
  XFlush (dpy);
}

canonical_original_code:
void alrm_handler()
{
  int i;
  printf ("alarm recieved\n");
  for (i=0; i<num_screens; i++)
    {
      hide_bar (&screens[i]);
    }
  XFlush (dpy);
}


decompiled_code:
int clean_up()
{
XSync(dpy, 0);
XSetInputFocus(dpy, 1uLL, 1, 0LL);
return XCloseDisplay(dpy);
}

canonical_decompiled_code:
int func3()
{
XSync(dpy, 0);
XSetInputFocus(dpy, 1uLL, 1, 0LL);
return XCloseDisplay(dpy);
}

original_code:
void
clean_up ()
{
  XSync(dpy, 0);
  XSetInputFocus (dpy, 1L, (int)1L, 0L);
  XCloseDisplay (dpy);
}

canonical_original_code:
void clean_up()
{
  XSync(dpy, 0);
  XSetInputFocus (dpy, 1L, (int)1L, 0L);
  XCloseDisplay (dpy);
}


sighandler

decompiled_code:
void __noreturn sighandler()
{
fwrite("antiwm: sighander failure\n", 1uLL, 0x1AuLL, stderr);
clean_up();
exit(1);
}

canonical_decompiled_code:
void __noreturn func4()
{
fwrite("antiwm: sighander failure\n", 1uLL, 0x1AuLL, stderr);
func3();
exit(1);
}

original_code:
void
sighandler ()
{
  fprintf (stderr, "antiwm: sighander failure\n");
  clean_up ();
  exit (1);
}

canonical_original_code:
void sighandler()
{
  fprintf (stderr, "antiwm: sighander failure\n");
  clean_up ();
  exit (1);
}


decompiled_code:
void hup_handler()
{
fwrite("antiwm: restarting\n", 1uLL, 0x13uLL, stderr);
clean_up();
execvp(*myargv, myargv);
}

canonical_decompiled_code:
void func5()
{
fwrite("antiwm: restarting\n", 1uLL, 0x13uLL, stderr);
func3();
execvp(*myargv, myargv);
}

original_code:
void
hup_handler ()
{
  fprintf (stderr, "antiwm: restarting\n");
  clean_up ();
  execvp(myargv[0], myargv);
}

canonical_original_code:
void hup_handler()
{
  fprintf (stderr, "antiwm: restarting\n");
  clean_up ();
  execvp(myargv[0], myargv);
}


decompiled_code:
void init_window_list()
{
a_window_tail = 0LL;
a_window_head = 0LL;
a_current_window = 0LL;
}

canonical_decompiled_code:
void func3()
{
a_window_tail = 0LL;
a_window_head = 0LL;
a_current_window = 0LL;
}

original_code:
void
init_window_list ()
{
  a_window_head = a_window_tail = ((void *)0);
  a_current_window = ((void *)0);
}

canonical_original_code:
void init_window_list()
{
  a_window_head = a_window_tail = ((void *)0);
  a_current_window = ((void *)0);
}


decompiled_code:
__int64 next_window()
{
__int64 result; // rax
__int64 v1; // rdi
int v2; // eax

result = a_current_window;
if ( a_current_window )
{
v1 = *(_QWORD *)(a_current_window + 32);
a_current_window = v1;
if ( v1 )
{
if ( *(_DWORD *)(v1 + 24) )
return set_active_window((__int64 *)v1);
}
else
{
v1 = a_window_head;
v2 = *(_DWORD *)(a_window_head + 24);
a_current_window = a_window_head;
if ( v2 )
return set_active_window((__int64 *)v1);
}
next_window();
result = set_active_window((__int64 *)a_current_window);
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax
__int64 v1; // rdi
int v2; // eax

result = a_current_window;
if ( a_current_window )
{
v1 = *(_QWORD *)(a_current_window + 32);
a_current_window = v1;
if ( v1 )
{
if ( *(_DWORD *)(v1 + 24) )
return func6((__int64 *)v1);
}
else
{
v1 = a_window_head;
v2 = *(_DWORD *)(a_window_head + 24);
a_current_window = a_window_head;
if ( v2 )
return func6((__int64 *)v1);
}
func7();
result = func6((__int64 *)a_current_window);
}
return result;
}

original_code:
void
next_window ()
{
  if (a_current_window != ((void *)0))
    {
      a_current_window = a_current_window->next;
      if (a_current_window == ((void *)0))
 {
   a_current_window = a_window_head;
 }
      if (a_current_window->state == 0) next_window ();
      set_active_window (a_current_window);
    }
}

canonical_original_code:
void next_window()
{
  if (a_current_window != ((void *)0))
    {
      a_current_window = a_current_window->next;
      if (a_current_window == ((void *)0))
 {
   a_current_window = a_window_head;
 }
      if (a_current_window->state == 0) next_window ();
      set_active_window (a_current_window);
    }
}


decompiled_code:
__int64 prev_window()
{
__int64 result; // rax
__int64 *v1; // rdi
int v2; // eax

result = a_current_window;
if ( a_current_window )
{
set_current_window(*(_QWORD *)(a_current_window + 40));
v1 = (__int64 *)a_current_window;
if ( a_current_window )
{
if ( *(_DWORD *)(a_current_window + 24) )
return set_active_window(v1);
}
else
{
v1 = (__int64 *)a_window_tail;
v2 = *(_DWORD *)(a_window_tail + 24);
a_current_window = a_window_tail;
if ( v2 )
return set_active_window(v1);
}
prev_window();
result = set_active_window((__int64 *)a_current_window);
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
__int64 *v1; // rdi
int v2; // eax

result = a_current_window;
if ( a_current_window )
{
func2(*(_QWORD *)(a_current_window + 40));
v1 = (__int64 *)a_current_window;
if ( a_current_window )
{
if ( *(_DWORD *)(a_current_window + 24) )
return func6(v1);
}
else
{
v1 = (__int64 *)a_window_tail;
v2 = *(_DWORD *)(a_window_tail + 24);
a_current_window = a_window_tail;
if ( v2 )
return func6(v1);
}
func9();
result = func6((__int64 *)a_current_window);
}
return result;
}

original_code:
void
prev_window ()
{
  if (a_current_window != ((void *)0))
    {
      set_current_window (a_current_window->prev);
      if (a_current_window == ((void *)0))
 {
   a_current_window = a_window_tail;
 }
      if (a_current_window->state == 0) prev_window ();
      set_active_window (a_current_window);
    }
}

canonical_original_code:
void prev_window()
{
  if (a_current_window != ((void *)0))
    {
      set_current_window (a_current_window->prev);
      if (a_current_window == ((void *)0))
 {
   a_current_window = a_window_tail;
 }
      if (a_current_window->state == 0) prev_window ();
      set_active_window (a_current_window);
    }
}


decompiled_code:
__int64 last_window()
{
a_current_window = find_last_accessed_window();
return set_active_window((__int64 *)a_current_window);
}

canonical_decompiled_code:
__int64 func10()
{
a_current_window = func5();
return func6((__int64 *)a_current_window);
}

original_code:
void
last_window ()
{
  a_current_window = find_last_accessed_window ();
  set_active_window (a_current_window);
}

canonical_original_code:
void last_window()
{
  a_current_window = find_last_accessed_window ();
  set_active_window (a_current_window);
}


spawn

decompiled_code:
int __fastcall spawn(char *arg)
{
if ( !fork() )
{
if ( fork() )
exit(0);
putenv(dpy->display_name);
execlp(arg, arg, 0LL);
fprintf(stderr, "antiwm: exec %s ", arg);
perror(" failed");
exit(1);
}
wait(0LL);
return printf("spawned %s\n", arg);
}

canonical_decompiled_code:
int __fastcall func1(char *arg)
{
if ( !fork() )
{
if ( fork() )
exit(0);
putenv(dpy->display_name);
execlp(arg, arg, 0LL);
fprintf(stderr, "antiwm: exec %s ", arg);
perror(" failed");
exit(1);
}
wait(0LL);
return printf("spawned %s\n", arg);
}

original_code:
void
spawn(char *prog)
{
  if (fork() == 0) {
    if (fork() == 0) {
      putenv((((_XPrivDisplay)(dpy))->display_name));
      execlp(prog, prog, (char *)((void *)0));
      fprintf(stderr, "antiwm: exec %s ", prog);
      perror(" failed");
      exit(1);
    }
    exit(0);
  }
  wait((int *) 0);
  printf ("spawned %s\n", prog);
}

variable_types:
prog
char *


decompiled_code:
__int64 __fastcall grab_prefix_key(Window a1)
{
KeyCode v1; // al
__int64 v3; // [rsp-10h] [rbp-18h]

v1 = XKeysymToKeycode(dpy, 0x74uLL);
XGrabKey(dpy, v1, 4u, a1, 1, 1, 1);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(Window a1)
{
KeyCode v1; // al
__int64 v3; // [rsp-10h] [rbp-18h]

v1 = XKeysymToKeycode(dpy, 0x74uLL);
XGrabKey(dpy, v1, 4u, a1, 1, 1, 1);
return v3;
}

original_code:
static void
grab_prefix_key (Window w)
{
  XGrabKey(dpy, XKeysymToKeycode (dpy, 't' ), (1<<2), w, 1,
    1, 1);
}

canonical_original_code:
static void grab_prefix_key(unsigned long w)
{
  XGrabKey(dpy, XKeysymToKeycode (dpy, 't' ), (1<<2), w, 1,
    1, 1);
}

variable_types:
w
unsigned long


repo: ivokub/huffkub

decompiled_code:
int __fastcall parse_args(int argc, char **argv)
{
int result; // eax

opts = 0;
while ( 2 )
{
result = getopt(argc, argv, "cxiof:d:hv");
if ( result == -1 )
return result;
switch ( result )
{
case 'c':
if ( (opts & 2) != 0 )
goto LABEL_19;
opts |= 1u;
continue;
case 'd':
if ( (opts & 8) != 0 )
goto LABEL_21;
opts |= 0x20u;
strncpy(outputfile, optarg, 0x80uLL);
continue;
case 'f':
if ( (opts & 4) != 0 )
goto LABEL_20;
opts |= 0x10u;
strncpy(inputfile, optarg, 0x80uLL);
continue;
case 'i':
if ( (opts & 0x10) != 0 )
goto LABEL_20;
opts |= 4u;
continue;
case 'o':
if ( (opts & 0x20) != 0 )
goto LABEL_21;
opts |= 8u;
continue;
case 'v':
opts |= 0x40u;
continue;
case 'x':
if ( (opts & 1) == 0 )
{
opts |= 2u;
continue;
}
LABEL_19:
error(2, 0, "-c and -x are exclusive");
LABEL_20:
error(2, 0, "-f and -i are exclusive");
LABEL_21:
error(2, 0, "-d and -o are exclusive");
return verbose_print();
default:
puts(
"Simple file packer using Huffman algorithm.\n"
"\n"
"Usage:\thuffkub [-c] [-x] [-i] [-o] [-f inputfile] [-d outputfile]\n"
"\n"
"Argument usage:\n"
"\t -c\t\tPack (exclusive with -x)\n"
"\t -x\t\tUnpack (exclusive with -c)\n"
"\t -i\t\tRead input from stdin (exclusive with -f)\n"
"\t -o\t\tWrite output to stdout (exclusive with -d)\n"
"\t -f FILE\tRead input from FILE (exclusive with -i)\n"
"\t -d FILE\tWrite output to FILE (exclusive with -o)\n"
"\t -v\t\tVerbose output (only when -o is not set)\n"
"\t -h\t\tPrint this help message");
exit(0);
}
}
}

canonical_decompiled_code:
int __fastcall func0(int argc, char **argv)
{
int result; // eax

opts = 0;
while ( 2 )
{
result = getopt(argc, argv, "cxiof:d:hv");
if ( result == -1 )
return result;
switch ( result )
{
case 'c':
if ( (opts & 2) != 0 )
goto LABEL_19;
opts |= 1u;
continue;
case 'd':
if ( (opts & 8) != 0 )
goto LABEL_21;
opts |= 0x20u;
strncpy(outputfile, optarg, 0x80uLL);
continue;
case 'f':
if ( (opts & 4) != 0 )
goto LABEL_20;
opts |= 0x10u;
strncpy(inputfile, optarg, 0x80uLL);
continue;
case 'i':
if ( (opts & 0x10) != 0 )
goto LABEL_20;
opts |= 4u;
continue;
case 'o':
if ( (opts & 0x20) != 0 )
goto LABEL_21;
opts |= 8u;
continue;
case 'v':
opts |= 0x40u;
continue;
case 'x':
if ( (opts & 1) == 0 )
{
opts |= 2u;
continue;
}
LABEL_19:
error(2, 0, "-c and -x are exclusive");
LABEL_20:
error(2, 0, "-f and -i are exclusive");
LABEL_21:
error(2, 0, "-d and -o are exclusive");
return func1();
default:
puts(
"Simple file packer using Huffman algorithm.\n"
"\n"
"Usage:\thuffkub [-c] [-x] [-i] [-o] [-f inputfile] [-d outputfile]\n"
"\n"
"Argument usage:\n"
"\t -c\t\tPack (exclusive with -x)\n"
"\t -x\t\tUnpack (exclusive with -c)\n"
"\t -i\t\tRead input from stdin (exclusive with -f)\n"
"\t -o\t\tWrite output to stdout (exclusive with -d)\n"
"\t -f FILE\tRead input from FILE (exclusive with -i)\n"
"\t -d FILE\tWrite output to FILE (exclusive with -o)\n"
"\t -v\t\tVerbose output (only when -o is not set)\n"
"\t -h\t\tPrint this help message");
exit(0);
}
}
}

original_code:
void parse_args(int argc, char **argv) {
 opts = 0;
 int opt;
 while ((opt = getopt(argc, argv, "cxiof:d:hv")) != -1) {
  switch (opt) {
  case 'c':
   if (opts & 0x2)
    error(2, 0, "-c and -x are exclusive");
   opts |= 0x1;
   break;
  case 'x':
   if (opts & 0x1)
    error(2, 0, "-c and -x are exclusive");
   opts |= 0x2;
   break;
  case 'i':
   if (opts & 0x10)
    error(2, 0, "-f and -i are exclusive");
   opts |= 0x4;
   break;
  case 'o':
   if (opts & 0x20)
    error(2, 0, "-d and -o are exclusive");
   opts |= 0x8;
   break;
  case 'f':
   if (opts & 0x4)
    error(2, 0, "-f and -i are exclusive");
   opts |= 0x10;
   strncpy(inputfile, optarg, 128);
   break;
  case 'd':
   if (opts & 0x8)
    error(2, 0, "-d and -o are exclusive");
   opts |= 0x20;
   strncpy(outputfile, optarg, 128);
   break;
  case 'v':
   opts |= 0x40;
   break;
  case 'h':
  default:
   printf("Simple file packer using Huffman algorithm.\n\n"
    "Usage:\thuffkub [-c] [-x] [-i] [-o] [-f inputfile] [-d outputfile]\n\n"
    "Argument usage:\n\t -c\t\tPack (exclusive with -x)\n"
    "\t -x\t\tUnpack (exclusive with -c)\n"
    "\t -i\t\tRead input from stdin (exclusive with -f)\n"
    "\t -o\t\tWrite output to stdout (exclusive with -d)\n"
    "\t -f FILE\tRead input from FILE (exclusive with -i)\n"
    "\t -d FILE\tWrite output to FILE (exclusive with -o)\n"
    "\t -v\t\tVerbose output (only when -o is not set)\n"
    "\t -h\t\tPrint this help message\n");
   exit(0);
  }
 }
}

variable_types:
argv
char **

variable_types: opt int


decompiled_code:
size_t verbose_print()
{
_QWORD *v0; // rbx
__int64 v1; // rax

v0 = &chararray;
fwrite("/*\nCHAR\tFREQ\tCODE\n", 1uLL, 0x12uLL, stderr);
do
{
if ( *v0 )
{
fprintf(stderr, "%c\t%d\t", *(unsigned __int8 *)(*v0 + 20LL), *(unsigned int *)(*v0 + 16LL));
v1 = calc_code(*v0);
print_code(v1);
}
++v0;
}
while ( v0 != (_QWORD *)((char *)&chararray + 2048) );
return fwrite("\n*/", 1uLL, 3uLL, stderr);
}

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

v0 = &chararray;
fwrite("/*\nCHAR\tFREQ\tCODE\n", 1uLL, 0x12uLL, stderr);
do
{
if ( *v0 )
{
fprintf(stderr, "%c\t%d\t", *(unsigned __int8 *)(*v0 + 20LL), *(unsigned int *)(*v0 + 16LL));
v1 = calc_code(*v0);
print_code(v1);
}
++v0;
}
while ( v0 != (_QWORD *)((char *)&chararray + 2048) );
return fwrite("\n*/", 1uLL, 3uLL, stderr);
}

original_code:
void verbose_print() {
 int i = 0;
 fprintf(stderr, "/*\nCHAR\tFREQ\tCODE\n");
 for (i = 0; i < 256; i++) {
  if (chararray[i] != ((void *)0)) {
   fprintf(stderr, "%c\t%d\t", chararray[i]->ch, chararray[i]->freq);
   print_code(calc_code(chararray[i]));
  }
 }
 fprintf(stderr, "\n*/");
}

variable_types: i int


sanitize

decompiled_code:
__int64 __fastcall sanitize(unsigned __int8 a1)
{
__int64 result; // rax

result = 2LL;
if ( (unsigned __int8)(a1 - 32) <= 0x5Eu )
{
if ( a1 > 0x3Eu )
result = (unsigned __int8)(a1 - 123) <= 2u;
else
result = ((1LL << a1) & 0x5000000500000000LL) != 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
__int64 result; // rax

result = 2LL;
if ( (unsigned __int8)(a1 - 32) <= 0x5Eu )
{
if ( a1 > 0x3Eu )
result = (unsigned __int8)(a1 - 123) <= 2u;
else
result = ((1LL << a1) & 0x5000000500000000LL) != 0;
}
return result;
}

original_code:
int sanitize(unsigned char c) {
 if ((signed char) c < 32 || (signed char) c > 126)
  return 2;
 switch ((signed char) c){
  case 10:
  case '"':
  case '|':
  case ' ':
  case '<':
  case '>':
  case '{':
  case '}':
  case 0:
   return 1;
   break;
  default:
   return 0;
 }
}

canonical_original_code:
int sanitize(unsigned char c) {
 if ((char) c < 32 || (char) c > 126)
  return 2;
 switch ((char) c){
  case 10:
  case '"':
  case '|':
  case ' ':
  case '<':
  case '>':
  case '{':
  case '}':
  case 0:
   return 1;
   break;
  default:
   return 0;
 }
}

variable_types:
c
unsigned char


decompiled_code:
void __fastcall print_tree(_BYTE *a1)
{
_BYTE *v1; // rbx
_BYTE *v2; // r12
int v3; // eax
unsigned int v4; // er9
__int64 v5; // r8
_BYTE *v6; // r12
int v7; // eax
unsigned int v8; // er9
__int64 v9; // r8

if ( *a1 == 2 )
{
v1 = a1;
do
{
fprintf(stderr, "\t\"%p\" [shape=record,label=\"%p|%d\"]\n ", v1, v1, *((unsigned int *)v1 + 4));
v2 = (_BYTE *)*((_QWORD *)v1 + 3);
if ( *v2 == 1 )
{
v3 = sanitize(v2[20]);
v5 = *((unsigned int *)v2 + 4);
if ( v3 == 1 )
{
fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\%c|%d\"]\n ", v2, v4, v5);
}
else if ( v3 == 2 )
{
fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\\\%d|%d\"]\n ", v2, v4, v5);
}
else
{
fprintf(stderr, "\t\"%p\" [shape=record,label=\"%c|%d\"]\n ", v2, v4, v5);
}
}
fprintf(stderr, "\t\"%p\" -> \"%p\";\n", v1, v2);
print_tree(*((_QWORD *)v1 + 3));
v6 = (_BYTE *)*((_QWORD *)v1 + 4);
if ( *v6 == 1 )
{
v7 = sanitize(v6[20]);
v9 = *((unsigned int *)v6 + 4);
if ( v7 == 1 )
{
fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\%c|%d\"]\n ", v6, v8, v9);
}
else if ( v7 == 2 )
{
fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\\\%d|%d\"]\n ", v6, v8, v9);
}
else
{
fprintf(stderr, "\t\"%p\" [shape=record,label=\"%c|%d\"]\n ", v6, v8, v9);
}
}
fprintf(stderr, "\t\"%p\" -> \"%p\";\n", v1, v6);
v1 = (_BYTE *)*((_QWORD *)v1 + 4);
}
while ( *v1 == 2 );
}
}

original_code:
void print_tree(node * rr) {
 leaf *l,*r;
 int printmode;
 if (rr->type == 2) {
  fprintf(stderr, "\t\"%p\" [shape=record,label=\"%p|%d\"]\n ", rr, rr, rr->freq);
  if ( (((hub *) rr)->left)->type == 1){
   l = ( (leaf *) ((hub *) rr)->left);
   if ((printmode = sanitize(l->ch)) == 1)
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\%c|%d\"]\n ", l, l->ch, l->freq);
   else if (printmode ==2)
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\\\%d|%d\"]\n ", l, (int) l->ch, l->freq);
   else
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"%c|%d\"]\n ", l, l->ch, l->freq);
   fprintf(stderr, "\t\"%p\" -> \"%p\";\n", rr, l);
  } else {
   fprintf(stderr, "\t\"%p\" -> \"%p\";\n", rr, ((hub *) rr)->left);
  }
  print_tree(((hub *) rr)->left);
  if ( (((hub *) rr)->right)->type == 1){
   r = ( (leaf *) ((hub *) rr)->right);
   if ((printmode = sanitize(r->ch)) == 1)
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\%c|%d\"]\n ", r, r->ch, r->freq);
   else if (printmode == 2)
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\\\%d|%d\"]\n ", r, (int) r->ch, r->freq);
   else
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"%c|%d\"]\n ", r, r->ch, r->freq);
   fprintf(stderr, "\t\"%p\" -> \"%p\";\n", rr, r);
  } else {
   fprintf(stderr, "\t\"%p\" -> \"%p\";\n", rr, ((hub *) rr)->right);
  }
  print_tree(((hub *) rr)->right);
 }
}

canonical_original_code:
void print_tree(struct node *rr) {
 struct nodeleaf *l; struct nodeleaf *r;
 int printmode;
 if (rr->type == 2) {
  fprintf(stderr, "\t\"%p\" [shape=record,label=\"%p|%d\"]\n ", rr, rr, rr->freq);
  if ( (((struct nodehub *) rr)->left)->type == 1){
   l = ( (struct nodeleaf *) ((struct nodehub *) rr)->left);
   if ((printmode = sanitize(l->ch)) == 1)
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\%c|%d\"]\n ", l, l->ch, l->freq);
   else if (printmode ==2)
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\\\%d|%d\"]\n ", l, (int) l->ch, l->freq);
   else
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"%c|%d\"]\n ", l, l->ch, l->freq);
   fprintf(stderr, "\t\"%p\" -> \"%p\";\n", rr, l);
  } else {
   fprintf(stderr, "\t\"%p\" -> \"%p\";\n", rr, ((struct nodehub *) rr)->left);
  }
  print_tree(((struct nodehub *) rr)->left);
  if ( (((struct nodehub *) rr)->right)->type == 1){
   r = ( (struct nodeleaf *) ((struct nodehub *) rr)->right);
   if ((printmode = sanitize(r->ch)) == 1)
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\%c|%d\"]\n ", r, r->ch, r->freq);
   else if (printmode == 2)
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"\\\\%d|%d\"]\n ", r, (int) r->ch, r->freq);
   else
    fprintf(stderr, "\t\"%p\" [shape=record,label=\"%c|%d\"]\n ", r, r->ch, r->freq);
   fprintf(stderr, "\t\"%p\" -> \"%p\";\n", rr, r);
  } else {
   fprintf(stderr, "\t\"%p\" -> \"%p\";\n", rr, ((struct nodehub *) rr)->right);
  }
  print_tree(((struct nodehub *) rr)->right);
 }
}

variable_types: struct nodeleaf { char type; struct nodehub { char type; struct nodehub *parent; int freq; struct node { char type; struct node *parent; int freq; } *left; struct node *right; } *parent; int freq; unsigned char ch; } *

variable_types: printmode int

user_defined_types: struct nodeleaf { char type; struct nodehub *parent; int freq; unsigned char ch; }

user_defined_types: struct nodehub { char type; struct nodehub *parent; int freq; struct node *left; struct node *right; }


decompiled_code:
size_t __fastcall print_tree1(_BYTE *a1)
{
fwrite("digraph bt {\n\trandkir = LR;\n", 1uLL, 0x1CuLL, stderr);
print_tree(a1);
return fwrite("}\n", 1uLL, 2uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func4(_BYTE *a1)
{
fwrite("digraph bt {\n\trandkir = LR;\n", 1uLL, 0x1CuLL, stderr);
func3(a1);
return fwrite("}\n", 1uLL, 2uLL, stderr);
}

original_code:
void print_tree1(node * rr) {
 fprintf(stderr, "digraph bt {\n"
    "\trandkir = LR;\n");
 print_tree(rr);
 fprintf(stderr, "}\n");
}

canonical_original_code:
void print_tree1(struct node *rr) {
 fprintf(stderr, "digraph bt {\n"
    "\trandkir = LR;\n");
 print_tree(rr);
 fprintf(stderr, "}\n");
}

variable_types: struct node { char type; struct node *parent; int freq; } *


main

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

if ( argc <= 1 )
{
puts("Use -h for usage");
exit(0);
}
blksize = 1024;
parse_args(argc, (char **)argv);
v3 = opts;
if ( (opts & 1) != 0 )
{
compress();
v3 = opts;
}
if ( (v3 & 2) != 0 )
{
extract();
v3 = opts;
}
if ( (v3 & 0x40) != 0 )
{
print_tree1((_BYTE *)tip);
verbose_print();
}
return 0;
}

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

if ( argc <= 1 )
{
puts("Use -h for usage");
exit(0);
}
blksize = 1024;
func0(argc, (char **)argv);
v3 = opts;
if ( (opts & 1) != 0 )
{
compress();
v3 = opts;
}
if ( (v3 & 2) != 0 )
{
extract();
v3 = opts;
}
if ( (v3 & 0x40) != 0 )
{
func4((_BYTE *)tip);
func1();
}
return 0;
}

original_code:
int main(int argc, char **argv) {
 if (argc < 2) {
  printf("Use -h for usage\n");
  exit(0);
 }
 blksize = 1024;
 parse_args(argc, argv);
 if (opts & 0x1) {
  compress();
 }
 if (opts & 0x2) {
  extract();
 }
 if (opts & 0x40) {
  print_tree1((node* ) tip);
  verbose_print();
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 if (argc < 2) {
  printf("Use -h for usage\n");
  exit(0);
 }
 blksize = 1024;
 parse_args(argc, argv);
 if (opts & 0x1) {
  compress();
 }
 if (opts & 0x2) {
  extract();
 }
 if (opts & 0x40) {
  print_tree1((struct node * ) tip);
  verbose_print();
 }
 return 0;
}

user_defined_types: struct node { char type; struct node *parent; int freq; }


decompiled_code:
__int64 __fastcall node_cmp_ll(const void *a1, const void *a2)
{
__int64 v2; // rdx
int v3; // ecx
__int64 result; // rax

v2 = *(_QWORD *)a1;
if ( !*(_QWORD *)a1 )
return 1LL;
if ( !*(_QWORD *)a2 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD *)(*(_QWORD *)a2 + 16LL);
result = 1LL;
if ( *(_DWORD *)(v2 + 16) <= v3 )
result = (unsigned int)-(*(_DWORD *)(v2 + 16) < v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
__int64 v2; // rdx
int v3; // ecx
__int64 result; // rax

v2 = *(_QWORD *)a1;
if ( !*(_QWORD *)a1 )
return 1LL;
if ( !*(_QWORD *)a2 )
return 0xFFFFFFFFLL;
v3 = *(_DWORD *)(*(_QWORD *)a2 + 16LL);
result = 1LL;
if ( *(_DWORD *)(v2 + 16) <= v3 )
result = (unsigned int)-(*(_DWORD *)(v2 + 16) < v3);
return result;
}

original_code:
int node_cmp_ll(const void *c1, const void *c2) {
 if (*(void **) c1 == ((void *)0)) return 1;
 if (*(void **) c2 == ((void *)0)) return -1;
 if ((*(node **) c1)->freq > (*(node **) c2)->freq)
  return 1;
 else if ((*(node **) c1)->freq < (*(node **) c2)->freq)
  return -1;
 else
  return 0;
}

canonical_original_code:
int node_cmp_ll(void *c1, void *c2) {
 if (*(void **) c1 == ((void *)0)) return 1;
 if (*(void **) c2 == ((void *)0)) return -1;
 if ((*(struct node **) c1)->freq > (*(struct node **) c2)->freq)
  return 1;
 else if ((*(struct node **) c1)->freq < (*(struct node **) c2)->freq)
  return -1;
 else
  return 0;
}


decompiled_code:
__int64 __fastcall create_tree(const void *a1)
{
_QWORD *v1; // rbp
__int64 i; // rsi
_QWORD *v3; // rax

v1 = calloc(0x100uLL, 8uLL);
qmemcpy(v1, a1, 0x800uLL);
qsort(v1, 0x100uLL, 8uLL, (__compar_fn_t)node_cmp_ll);
for ( i = v1[1]; i; i = v1[1] )
{
v3 = create_hub(*v1, i);
*(_QWORD *)(*v1 + 8LL) = v3;
*(_QWORD *)(v1[1] + 8LL) = v3;
*v1 = 0LL;
v1[1] = v3;
qsort(v1, 0x100uLL, 8uLL, (__compar_fn_t)node_cmp_ll);
}
return *v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1)
{
_QWORD *v1; // rbp
__int64 i; // rsi
_QWORD *v3; // rax

v1 = calloc(0x100uLL, 8uLL);
qmemcpy(v1, a1, 0x800uLL);
qsort(v1, 0x100uLL, 8uLL, (__compar_fn_t)node_cmp_ll);
for ( i = v1[1]; i; i = v1[1] )
{
v3 = create_hub(*v1, i);
*(_QWORD *)(*v1 + 8LL) = v3;
*(_QWORD *)(v1[1] + 8LL) = v3;
*v1 = 0LL;
v1[1] = v3;
qsort(v1, 0x100uLL, 8uLL, (__compar_fn_t)node_cmp_ll);
}
return *v1;
}

original_code:
hub * create_tree(leaf ** leafarray) {
 int i;
 int full = 0;
 node ** tree = calloc(256, sizeof(node *));
 hub * thishub;
 memcpy(tree, leafarray, sizeof(void *) * 256);
 qsort(tree, 256, sizeof(node *), node_cmp_ll);
 while (tree[1] != ((void *)0)) {
  thishub = create_hub((leaf *) tree[0], (leaf *) tree[1]);
  tree[0]->parent = (node *) thishub;
  tree[1]->parent = (node *) thishub;
  tree[0] = ((void *)0);
  tree[1] = (node *) thishub;
  qsort(tree, 256, sizeof(node *), node_cmp_ll);
 }
 return (hub *) tree[0];
}

canonical_original_code:
struct nodehub *create_tree(struct nodeleaf **leafarray) {
 int i;
 int full = 0;
 struct node **tree = calloc(256, sizeof(node *));
 struct nodehub *thishub;
 memcpy(tree, leafarray, sizeof(void *) * 256);
 qsort(tree, 256, sizeof(struct node *), node_cmp_ll);
 while (tree[1] != ((void *)0)) {
  thishub = create_hub((struct nodeleaf *) tree[0], (struct nodeleaf *) tree[1]);
  tree[0]->parent = (struct node *) thishub;
  tree[1]->parent = (struct node *) thishub;
  tree[0] = ((void *)0);
  tree[1] = (struct node *) thishub;
  qsort(tree, 256, sizeof(struct node *), node_cmp_ll);
 }
 return (struct nodehub *) tree[0];
}

variable_types: struct nodeleaf { char type; struct nodehub *parent; int freq; unsigned char ch; } **

variable_types: full int

variable_types: struct node { char type; struct node *parent; int freq; } **

variable_types: struct nodehub { char type; struct nodehub *parent; int freq; struct node { char type; struct node *parent; int freq; } *left; struct node *right; } *


decompiled_code:
void __fastcall fill_node(unsigned __int8 a1)
{
_QWORD *v1; // rbx

v1 = (_QWORD *)chararray[a1];
if ( !v1 )
{
v1 = malloc(0x18uLL);
if ( !v1 )
error(4, 0, "Cannot allocate memory!");
++leafcount;
*(_BYTE *)v1 = 1;
v1[1] = root;
chararray[a1] = (__int64)v1;
}
++*((_DWORD *)v1 + 4);
*((_BYTE *)v1 + 20) = a1;
++root[4];
}

canonical_decompiled_code:
void __fastcall func2(unsigned __int8 a1)
{
_QWORD *v1; // rbx

v1 = (_QWORD *)chararray[a1];
if ( !v1 )
{
v1 = malloc(0x18uLL);
if ( !v1 )
error(4, 0, "Cannot allocate memory!");
++leafcount;
*(_BYTE *)v1 = 1;
v1[1] = root;
chararray[a1] = (__int64)v1;
}
++*((_DWORD *)v1 + 4);
*((_BYTE *)v1 + 20) = a1;
++root[4];
}

original_code:
void fill_node(unsigned char c) {
 leaf *thisnode;
 if ((thisnode = chararray[c]) == ((void *)0)) {
  thisnode = (leaf *) malloc(sizeof(leaf));
  if (thisnode == ((void *)0))
   error(4, 0, "Cannot allocate memory!");
  thisnode->type = 1;
                thisnode->parent = &root;
  chararray[c] = thisnode;
  leafcount++;
 }
 thisnode->ch = c;
 thisnode->freq++;
 root.freq++;
}

canonical_original_code:
void fill_node(unsigned char c) {
 struct nodeleaf *thisnode;
 if ((thisnode = chararray[c]) == ((void *)0)) {
  thisnode = (struct nodeleaf *) malloc(sizeof(leaf));
  if (thisnode == ((void *)0))
   error(4, 0, "Cannot allocate memory!");
  thisnode->type = 1;
                thisnode->parent = &root;
  chararray[c] = thisnode;
  leafcount++;
 }
 thisnode->ch = c;
 thisnode->freq++;
 root.freq++;
}


decompiled_code:
int __fastcall print_code(int *a1)
{
int v1; // ebx
int v2; // er12

v1 = a1[1];
if ( *a1 > 0 )
{
v2 = 0;
do
{
++v2;
fprintf(stderr, "%d", (unsigned int)(v1 % 2));
v1 /= 2;
}
while ( *a1 > v2 );
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func3(int *a1)
{
int v1; // ebx
int v2; // er12

v1 = a1[1];
if ( *a1 > 0 )
{
v2 = 0;
do
{
++v2;
fprintf(stderr, "%d", (unsigned int)(v1 % 2));
v1 /= 2;
}
while ( *a1 > v2 );
}
return fputc(10, stderr);
}

original_code:
void print_code(code * bytecode) {
 int i = 0, bitcode = bytecode->ch;
 while (i < bytecode->len) {
  fprintf(stderr, "%d", bitcode % 2);
  bitcode /= 2;
  i++;
 }
 fprintf(stderr, "\n");
}

canonical_original_code:
void print_code(struct code *bytecode) {
 int i = 0; int bitcode = bytecode->ch;
 while (i < bytecode->len) {
  fprintf(stderr, "%d", bitcode % 2);
  bitcode /= 2;
  i++;
 }
 fprintf(stderr, "\n");
}

variable_types:
bytecode
struct code { int len; int ch; } *

variable_types: bitcode int


decompiled_code:
void __fastcall recursive_write(__int64 a1)
{
_BYTE *v2; // rdx
_BYTE *v3; // rdx

while ( 1 )
{
v2 = *(_BYTE **)(a1 + 24);
if ( *v2 == 1 )
{
if ( (opts & 0x40) != 0 )
fprintf(stderr, "1%c", (unsigned int)(char)v2[20]);
if ( (unsigned int)writebit(1LL)
|| (unsigned int)write_char_bit(*(unsigned __int8 *)(*(_QWORD *)(a1 + 24) + 20LL)) )
{
error(3, 0, "Write error!");
}
}
else
{
if ( (opts & 0x40) != 0 )
fputc(48, stderr);
writebit(0LL);
recursive_write(*(_QWORD *)(a1 + 24));
}
v3 = *(_BYTE **)(a1 + 32);
if ( *v3 == 1 )
break;
if ( (opts & 0x40) != 0 )
fputc(48, stderr);
writebit(0LL);
a1 = *(_QWORD *)(a1 + 32);
}
if ( (opts & 0x40) != 0 )
fprintf(stderr, "1%c", (unsigned int)(char)v3[20]);
if ( (unsigned int)writebit(1LL) || (unsigned int)write_char_bit(*(unsigned __int8 *)(*(_QWORD *)(a1 + 32) + 20LL)) )
error(3, 0, "Write error!");
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1)
{
_BYTE *v2; // rdx
_BYTE *v3; // rdx

while ( 1 )
{
v2 = *(_BYTE **)(a1 + 24);
if ( *v2 == 1 )
{
if ( (opts & 0x40) != 0 )
fprintf(stderr, "1%c", (unsigned int)(char)v2[20]);
if ( (unsigned int)writebit(1LL)
|| (unsigned int)write_char_bit(*(unsigned __int8 *)(*(_QWORD *)(a1 + 24) + 20LL)) )
{
error(3, 0, "Write error!");
}
}
else
{
if ( (opts & 0x40) != 0 )
fputc(48, stderr);
writebit(0LL);
func8(*(_QWORD *)(a1 + 24));
}
v3 = *(_BYTE **)(a1 + 32);
if ( *v3 == 1 )
break;
if ( (opts & 0x40) != 0 )
fputc(48, stderr);
writebit(0LL);
a1 = *(_QWORD *)(a1 + 32);
}
if ( (opts & 0x40) != 0 )
fprintf(stderr, "1%c", (unsigned int)(char)v3[20]);
if ( (unsigned int)writebit(1LL) || (unsigned int)write_char_bit(*(unsigned __int8 *)(*(_QWORD *)(a1 + 32) + 20LL)) )
error(3, 0, "Write error!");
}

original_code:
void recursive_write(hub * parent){
 if (parent->left->type == 1){
  if (opts & 0x40) fprintf(stderr, "1%c", (signed char) ((leaf *) parent->left)->ch);
  if (writebit(1) || write_char_bit(((leaf *) parent->left)->ch)) error(3, 0, "Write error!");
 } else {
  if (opts & 0x40) fprintf(stderr, "0");
  writebit(0);
  recursive_write((hub *) parent->left);
 }
 if (parent->right->type == 1){
  if (opts & 0x40) fprintf(stderr, "1%c", (signed char) ((leaf *) parent->right)->ch);
  if (writebit(1) || write_char_bit(((leaf *) parent->right)->ch)) error(3, 0, "Write error!");
 } else {
  if (opts & 0x40) fprintf(stderr, "0");
  writebit(0);
  recursive_write((hub *) parent->right);
 }
}

canonical_original_code:
void recursive_write(struct nodehub *parent){
 if (parent->left->type == 1){
  if (opts & 0x40) fprintf(stderr, "1%c", (char) ((struct nodeleaf *) parent->left)->ch);
  if (writebit(1) || write_char_bit(((struct nodeleaf *) parent->left)->ch)) error(3, 0, "Write error!");
 } else {
  if (opts & 0x40) fprintf(stderr, "0");
  writebit(0);
  recursive_write((struct nodehub *) parent->left);
 }
 if (parent->right->type == 1){
  if (opts & 0x40) fprintf(stderr, "1%c", (char) ((struct nodeleaf *) parent->right)->ch);
  if (writebit(1) || write_char_bit(((struct nodeleaf *) parent->right)->ch)) error(3, 0, "Write error!");
 } else {
  if (opts & 0x40) fprintf(stderr, "0");
  writebit(0);
  recursive_write((struct nodehub *) parent->right);
 }
}


readbit

decompiled_code:
__int64 readbit()
{
char v0; // al
int v1; // edx
int v2; // ecx
char v4; // bl
__int64 i; // rcx

v0 = bitindex;
v1 = eof_reached;
v2 = bitindex;
if ( bitindex == 8 )
{
v2 = 8;
if ( eof_reached )
goto LABEL_5;
v4 = fgetc(fbitstream);
if ( feof(fbitstream) )
eof_reached = 1;
*(_QWORD *)bitbuffer = *(_QWORD *)bitbuffer2;
v1 = eof_reached;
if ( !eof_reached )
{
for ( i = 0LL; i != 8; ++i )
*(_BYTE *)(bitbuffer2 + i) = (v4 & (1 << i)) >> i;
v1 = eof_reached;
}
bitindex = 0;
v2 = 0;
v0 = 0;
}
if ( !v1 )
{
LABEL_3:
bitindex = v0 + 1;
return *(unsigned __int8 *)(bitbuffer + 7 - v2);
}
LABEL_5:
if ( v2 + padsize != 8 )
goto LABEL_3;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
char v0; // al
int v1; // edx
int v2; // ecx
char v4; // bl
__int64 i; // rcx

v0 = bitindex;
v1 = eof_reached;
v2 = bitindex;
if ( bitindex == 8 )
{
v2 = 8;
if ( eof_reached )
goto LABEL_5;
v4 = fgetc(fbitstream);
if ( feof(fbitstream) )
eof_reached = 1;
*(_QWORD *)bitbuffer = *(_QWORD *)bitbuffer2;
v1 = eof_reached;
if ( !eof_reached )
{
for ( i = 0LL; i != 8; ++i )
*(_BYTE *)(bitbuffer2 + i) = (v4 & (1 << i)) >> i;
v1 = eof_reached;
}
bitindex = 0;
v2 = 0;
v0 = 0;
}
if ( !v1 )
{
LABEL_3:
bitindex = v0 + 1;
return *(unsigned __int8 *)(bitbuffer + 7 - v2);
}
LABEL_5:
if ( v2 + padsize != 8 )
goto LABEL_3;
return 0xFFFFFFFFLL;
}

original_code:
char readbit(){
 char c;
 int i;
 if (bitindex == 8 && !eof_reached){
  c = fgetc(fbitstream);
  if (feof(fbitstream)) {
   eof_reached = 1;
  }
  memcpy(bitbuffer, bitbuffer2, 8*sizeof(char));
  if (!eof_reached){
   for (i=0; i<8; i++){
    bitbuffer2[i] = (c & (0x1 << i)) >> i;
    }
  }
  bitindex = 0;
 }
 if (eof_reached && padsize+bitindex == 8) return -1;
 return bitbuffer[7-bitindex++];
}

variable_types: c char

return_type: char


writebit

decompiled_code:
__int64 __fastcall writebit(char a1)
{
char v1; // cl
__int64 result; // rax
int v3; // er8

v1 = 7 - bitindex++;
*(_BYTE *)bitbuffer |= (a1 & 1) << v1;
result = 0LL;
if ( bitindex == 8 )
{
v3 = fputc(*(char *)bitbuffer, fbitstream);
result = 1LL;
if ( v3 != -1 )
{
*(_BYTE *)bitbuffer = 0;
result = 0LL;
bitindex = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
char v1; // cl
__int64 result; // rax
int v3; // er8

v1 = 7 - bitindex++;
*(_BYTE *)bitbuffer |= (a1 & 1) << v1;
result = 0LL;
if ( bitindex == 8 )
{
v3 = fputc(*(char *)bitbuffer, fbitstream);
result = 1LL;
if ( v3 != -1 )
{
*(_BYTE *)bitbuffer = 0;
result = 0LL;
bitindex = 0;
}
}
return result;
}

original_code:
int writebit(char c){
 int ret;
 *bitbuffer |= (0x1&c)<<(7-bitindex++);
 if (bitindex == 8){
  if ((ret = fputc(*bitbuffer, fbitstream)) == (-1)) return 1;
  *bitbuffer = 0;
  bitindex = 0;
 }
 return 0;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall write_char_bit(unsigned __int8 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = 8;
while ( 1 )
{
result = writebit(a1 & 1);
if ( (_DWORD)result )
break;
a1 >>= 1;
if ( !--v1 )
return result;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 a1)
{
int v1; // ebp
__int64 result; // rax

v1 = 8;
while ( 1 )
{
result = func2(a1 & 1);
if ( (_DWORD)result )
break;
a1 >>= 1;
if ( !--v1 )
return result;
}
return 1LL;
}

original_code:
int write_char_bit(unsigned char c){
 int i;
 for (i=0; i<8; i++){
  if (writebit(c & 0x1)) return 1;
  c >>= 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall cmp_compresscode(const void *a1, const void *a2)
{
signed __int8 v2; // dl
__int64 result; // rax

v2 = *((_BYTE *)a2 + 2);
result = 1LL;
if ( *((char *)a1 + 2) <= v2 )
result = (unsigned int)-(*((_BYTE *)a1 + 2) < (unsigned __int8)v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
signed __int8 v2; // dl
__int64 result; // rax

v2 = *((_BYTE *)a2 + 2);
result = 1LL;
if ( *((char *)a1 + 2) <= v2 )
result = (unsigned int)-(*((_BYTE *)a1 + 2) < (unsigned __int8)v2);
return result;
}

original_code:
int cmp_compresscode(const void * c1, const void * c2){
 if (((compresscode *) c1)->len > ((compresscode *) c2)->len) return 1;
 else if (((compresscode *) c1)-> len < ((compresscode *) c2)->len) return -1;
 else return 0;
}

canonical_original_code:
int cmp_compresscode(void *c1, void *c2){
 if (((struct compresscode *) c1)->len > ((struct compresscode *) c2)->len) return 1;
 else if (((struct compresscode *) c1)-> len < ((struct compresscode *) c2)->len) return -1;
 else return 0;
}

user_defined_types: struct compresscode { short code; char len; char ch; }


reverse

original_code:
void reverse(compresscode * ctable, int arraylen){
 int i, j;
 short int code = 0;
 for (i = 0; i < arraylen; i++){
  for (j = 0; j < ctable[i].len; j++){
   code <<= 1;
   code += ctable[i].code & 0x1;
   ctable[i].code >>= 1;
  }
  ctable[i].code = code;
  code = 0;
 }
}

canonical_original_code:
void reverse(struct compresscode *ctable, int arraylen){
 int i; int j;
 short code = 0;
 for (i = 0; i < arraylen; i++){
  for (j = 0; j < ctable[i].len; j++){
   code <<= 1;
   code += ctable[i].code & 0x1;
   ctable[i].code >>= 1;
  }
  ctable[i].code = code;
  code = 0;
 }
}

variable_types: struct compresscode { short code; char len; char ch; } *

variable_types: arraylen int

variable_types: j int

variable_types: code short


decompiled_code:
__int64 __fastcall recursive_tree(__int64 a1, int a2)
{
__int64 result; // rax
_QWORD *v3; // rax
__int64 v4; // rbx
__int64 v5; // rbp
_QWORD *v6; // rax
_QWORD *v7; // rax
_QWORD *v8; // rax
_QWORD *v9; // rbp
int v10; // ebx
_QWORD *v11; // rdi
__int64 v12; // rax
int v13; // ebx
_QWORD *v14; // rax
_QWORD *v15; // r12

result = readbit();
if ( a2 )
{
if ( a2 == 1 )
{
v4 = a1;
goto LABEL_8;
}
if ( a2 == -1 )
{
v7 = malloc(0x28uLL);
v7[1] = &root;
tip2 = (__int64)v7;
recursive_tree(v7, 0LL);
v4 = tip2;
if ( (unsigned __int8)readbit() != 1 )
{
do
{
v5 = v4;
v6 = malloc(0x28uLL);
*(_BYTE *)v6 = 2;
v4 = (__int64)v6;
v6[1] = v5;
*(_QWORD *)(v5 + 32) = v6;
LABEL_7:
recursive_tree(v4, 0LL);
LOBYTE(result) = readbit();
LABEL_8:
;
}
while ( (_BYTE)result != 1 );
}
v8 = malloc(0x18uLL);
v8[1] = v4;
v9 = v8;
*(_BYTE *)v8 = 1;
*(_QWORD *)(v4 + 32) = v8;
v10 = 8;
*((_BYTE *)v8 + 20) = 0;
do
{
result = (*((_BYTE *)v9 + 20) >> 1) | ((unsigned int)readbit() << 7);
*((_BYTE *)v9 + 20) = result;
--v10;
}
while ( v10 );
if ( (opts & 0x60) == 96 )
{
printf("%c\t", (unsigned __int8)result);
v11 = v9;
LABEL_15:
v12 = calc_code(v11);
return print_code(v12);
}
}
}
else
{
if ( (_BYTE)result != 1 )
{
v3 = malloc(0x28uLL);
v3[1] = a1;
v4 = (__int64)v3;
*(_QWORD *)(a1 + 24) = v3;
*(_BYTE *)v3 = 2;
goto LABEL_7;
}
v13 = 8;
v14 = malloc(0x18uLL);
v14[1] = a1;
v15 = v14;
*(_BYTE *)v14 = 1;
*(_QWORD *)(a1 + 24) = v14;
*((_BYTE *)v14 + 20) = 0;
do
{
result = (*((_BYTE *)v15 + 20) >> 1) | ((unsigned int)readbit() << 7);
*((_BYTE *)v15 + 20) = result;
--v13;
}
while ( v13 );
if ( (opts & 0x60) == 96 )
{
printf("%c\t", (unsigned __int8)result);
v11 = v15;
goto LABEL_15;
}
}
return result;
}

original_code:
void recursive_tree(hub * parent, int direction){
 unsigned char c = readbit();
 leaf * thisleaf;
 hub * thishub;
 int i;
 if (c == -1) error(3, 0, "Read error!");
 switch (direction){
  case -1:
   tip2 = malloc(sizeof(hub));
   tip2->parent = &root;
   recursive_tree(tip2, 0);
   recursive_tree(tip2, 1);
   break;
  case 0:
   if (c == 1){
    thisleaf = malloc(sizeof(leaf));
    thisleaf->parent = parent;
    thisleaf->type = 1;
    parent->left = (node *) thisleaf;
    thisleaf->ch = 0;
    for (i=0; i<8; i++){
     if ((c = readbit()) == -1) error(3, 0, "Read error!");
     thisleaf->ch >>= 1;
     thisleaf->ch |= c<<7;
    }
    if ((opts & 0x40) && (opts & 0x20)) {
     printf("%c\t", thisleaf->ch);
     print_code(calc_code(thisleaf));
    }
   } else {
    thishub = malloc(sizeof(hub));
    thishub->parent = parent;
    parent->left = (node *) thishub;
    thishub->type = 2;
    recursive_tree(thishub, 0);
    recursive_tree(thishub, 1);
   }
   break;
  case 1:
   if (c == 1){
    thisleaf = malloc(sizeof(leaf));
    thisleaf->parent = parent;
    thisleaf->type = 1;
    parent->right = (node *) thisleaf;
    thisleaf->ch = 0;
    for (i=0; i<8; i++){
     if ((c = readbit()) == -1) error(3, 0, "Read error!");
     thisleaf->ch >>= 1;
     thisleaf->ch |= c<<7;
    }
    if ((opts & 0x40) && (opts & 0x20)) {
     printf("%c\t", thisleaf->ch);
     print_code(calc_code(thisleaf));
    }
   } else {
    thishub = malloc(sizeof(hub));
    thishub->type = 2;
    thishub->parent = parent;
    parent->right = (node *) thishub;
    recursive_tree(thishub, 0);
    recursive_tree(thishub, 1);
   }
   break;
  default:
   break;
 }
}

canonical_original_code:
void recursive_tree(struct nodehub *parent, int direction){
 unsigned char c = readbit();
 struct nodeleaf *thisleaf;
 struct nodehub *thishub;
 int i;
 if (c == -1) error(3, 0, "Read error!");
 switch (direction){
  case -1:
   tip2 = malloc(sizeof(hub));
   tip2->parent = &root;
   recursive_tree(tip2, 0);
   recursive_tree(tip2, 1);
   break;
  case 0:
   if (c == 1){
    thisleaf = malloc(sizeof(leaf));
    thisleaf->parent = parent;
    thisleaf->type = 1;
    parent->left = (struct node *) thisleaf;
    thisleaf->ch = 0;
    for (i=0; i<8; i++){
     if ((c = readbit()) == -1) error(3, 0, "Read error!");
     thisleaf->ch >>= 1;
     thisleaf->ch |= c<<7;
    }
    if ((opts & 0x40) && (opts & 0x20)) {
     printf("%c\t", thisleaf->ch);
     print_code(calc_code(thisleaf));
    }
   } else {
    thishub = malloc(sizeof(hub));
    thishub->parent = parent;
    parent->left = (struct node *) thishub;
    thishub->type = 2;
    recursive_tree(thishub, 0);
    recursive_tree(thishub, 1);
   }
   break;
  case 1:
   if (c == 1){
    thisleaf = malloc(sizeof(leaf));
    thisleaf->parent = parent;
    thisleaf->type = 1;
    parent->right = (struct node *) thisleaf;
    thisleaf->ch = 0;
    for (i=0; i<8; i++){
     if ((c = readbit()) == -1) error(3, 0, "Read error!");
     thisleaf->ch >>= 1;
     thisleaf->ch |= c<<7;
    }
    if ((opts & 0x40) && (opts & 0x20)) {
     printf("%c\t", thisleaf->ch);
     print_code(calc_code(thisleaf));
    }
   } else {
    thishub = malloc(sizeof(hub));
    thishub->type = 2;
    thishub->parent = parent;
    parent->right = (struct node *) thishub;
    recursive_tree(thishub, 0);
    recursive_tree(thishub, 1);
   }
   break;
  default:
   break;
 }
}

variable_types: direction int

variable_types: i int


decompiled_code:
__int64 __fastcall sort_compresstable(char *a1, int a2)
{
__int64 result; // rax

qsort(a1, a2, 4uLL, (__compar_fn_t)cmp_compresscode);
maxlen = a1[4 * a2 - 2];
result = (unsigned int)a1[2];
minlen = a1[2];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, int a2)
{
__int64 result; // rax

qsort(a1, a2, 4uLL, (__compar_fn_t)cmp_compresscode);
maxlen = a1[4 * a2 - 2];
result = (unsigned int)a1[2];
minlen = a1[2];
return result;
}

original_code:
void sort_compresstable(compresscode ctable[], int len){
 qsort(ctable, len, sizeof(compresscode), cmp_compresscode);
 maxlen = ctable[len-1].len;
 minlen = ctable[0].len;
}

canonical_original_code:
void sort_compresstable(struct compresscode ctable[], int len){
 qsort(ctable, len, sizeof(compresscode), cmp_compresscode);
 maxlen = ctable[len-1].len;
 minlen = ctable[0].len;
}

variable_types: struct compresscode { short code; char len; char ch; } []

variable_types: len int


original_code:
char find_char(compresscode * ctable, int code, int len){
 int i = searchpointer;
 if (len>=minlen){
  while (ctable[i].len<len) i++;
  for (; ctable[i].len == len; i++){
   if (ctable[i].code == code) return ctable[i].ch;
  }
 }
 return 0;
}

canonical_original_code:
char find_char(struct compresscode *ctable, int code, int len){
 int i = searchpointer;
 if (len>=minlen){
  while (ctable[i].len<len) i++;
  for (; ctable[i].len == len; i++){
   if (ctable[i].code == code) return ctable[i].ch;
  }
 }
 return 0;
}

variable_types: code int


getsource

repo: iwabuchiken/AI

decompiled_code:
__int64 __fastcall getsource(__int64 a1)
{
__int64 v1; // rbx
char v2; // al
unsigned int v3; // er8

v1 = 1LL;
do
{
v2 = getchar();
v3 = v1;
*(_BYTE *)(a1 + v1++ - 1) = v2;
}
while ( v2 != -1 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 v1; // rbx
char v2; // al
unsigned int v3; // er8

v1 = 1LL;
do
{
v2 = getchar();
v3 = v1;
*(_BYTE *)(a1 + v1++ - 1) = v2;
}
while ( v2 != -1 );
return v3;
}

original_code:
int getsource(char *s)
{
 int n=0;
 while((s[n++] = getchar()) != (-1));
 return n;
}

canonical_original_code:
int getsource(char *s)
{
 int n = 0;
 while((s[n++] = getchar()) != (-1));
 return n;
}

variable_types:
s
char *

variable_types: n int