decompiled_code:
__int64 setup_bmps()
{
__int64 v0; // rbp
__int64 i; // rbx
__int64 v3; // [rsp+0h] [rbp-28h]
__int64 v4; // [rsp+0h] [rbp-28h]
__int64 v5; // [rsp+0h] [rbp-28h]

bufferbmp = create_bitmap(640LL, 480LL);
tilesbmp = load_bitmap("maptiles.bmp", 0LL);
v0 = load_bitmap("chars.bmp", 0LL);
for ( i = 0LL; i != 2; ++i )
{
playerdnbmp[i] = grab_frame(v0, 32LL, 32LL, 0LL, 0LL, 32LL, i);
LODWORD(v3) = i + 2;
playerupbmp[i] = grab_frame(v0, 32LL, 32LL, 0LL, 0LL, 32LL, v3);
LODWORD(v4) = i + 4;
playerrtbmp[i] = grab_frame(v0, 32LL, 32LL, 0LL, 0LL, 32LL, v4);
LODWORD(v5) = i + 6;
playerltbmp[i] = grab_frame(v0, 32LL, 32LL, 0LL, 0LL, 32LL, v5);
}
return destroy_bitmap(v0);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbp
__int64 i; // rbx
__int64 v3; // [rsp+0h] [rbp-28h]
__int64 v4; // [rsp+0h] [rbp-28h]
__int64 v5; // [rsp+0h] [rbp-28h]

bufferbmp = create_bitmap(640LL, 480LL);
tilesbmp = load_bitmap("maptiles.bmp", 0LL);
v0 = load_bitmap("chars.bmp", 0LL);
for ( i = 0LL; i != 2; ++i )
{
playerdnbmp[i] = grab_frame(v0, 32LL, 32LL, 0LL, 0LL, 32LL, i);
LODWORD(v3) = i + 2;
playerupbmp[i] = grab_frame(v0, 32LL, 32LL, 0LL, 0LL, 32LL, v3);
LODWORD(v4) = i + 4;
playerrtbmp[i] = grab_frame(v0, 32LL, 32LL, 0LL, 0LL, 32LL, v4);
LODWORD(v5) = i + 6;
playerltbmp[i] = grab_frame(v0, 32LL, 32LL, 0LL, 0LL, 32LL, v5);
}
return destroy_bitmap(v0);
}

original_code:
void setup_bmps (void) {
  int i;
  BITMAP *tempbmp;
  bufferbmp = create_bitmap (640, 480);
  tilesbmp = load_bitmap ("maptiles.bmp", ((void *)0));
  tempbmp = load_bitmap ("chars.bmp", ((void *)0));
  for (i = 0; i < 2; i++) {
    playerdnbmp[i] = grab_frame (tempbmp, 32, 32, 0, 0, 32, i);
    playerupbmp[i] = grab_frame (tempbmp, 32, 32, 0, 0, 32, i+2);
    playerrtbmp[i] = grab_frame (tempbmp, 32, 32, 0, 0, 32, i+4);
    playerltbmp[i] = grab_frame (tempbmp, 32, 32, 0, 0, 32, i+6);
  }
  destroy_bitmap (tempbmp);
}

canonical_original_code:
void setup_bmps() {
  int i;
  struct BITMAP *tempbmp;
  bufferbmp = create_bitmap (640, 480);
  tilesbmp = load_bitmap ("maptiles.bmp", ((void *)0));
  tempbmp = load_bitmap ("chars.bmp", ((void *)0));
  for (i = 0; i < 2; i++) {
    playerdnbmp[i] = grab_frame (tempbmp, 32, 32, 0, 0, 32, i);
    playerupbmp[i] = grab_frame (tempbmp, 32, 32, 0, 0, 32, i+2);
    playerrtbmp[i] = grab_frame (tempbmp, 32, 32, 0, 0, 32, i+4);
    playerltbmp[i] = grab_frame (tempbmp, 32, 32, 0, 0, 32, i+6);
  }
  destroy_bitmap (tempbmp);
}

variable_types: i int

variable_types: struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE { int w; int color_depth; int size; char dat[]; } *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH { short w; unsigned char dat[]; } *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D { int x; int u; int c; } *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f { float x; float u; int c; } *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); } *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; } *

user_defined_types: struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; }

user_defined_types: struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); }


repo: misfit/dragonfighter

decompiled_code:
__int64 destroy_bmps()
{
destroy_bitmap(bufferbmp);
destroy_bitmap(scrollbmp);
return destroy_bitmap(tilesbmp);
}

canonical_decompiled_code:
__int64 func2()
{
destroy_bitmap(bufferbmp);
destroy_bitmap(scrollbmp);
return destroy_bitmap(tilesbmp);
}

original_code:
void destroy_bmps (void) {
  destroy_bitmap (bufferbmp);
  destroy_bitmap (scrollbmp);
  destroy_bitmap (tilesbmp);
}

canonical_original_code:
void destroy_bmps() {
  destroy_bitmap (bufferbmp);
  destroy_bitmap (scrollbmp);
  destroy_bitmap (tilesbmp);
}

return_type: void


clear

decompiled_code:
__int64 clear()
{
return clear_bitmap();
}

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

original_code:
static __attribute__((unused)) __inline__ void clear(BITMAP *bmp)
         {
            clear_bitmap(bmp);
         }

canonical_original_code:
static __inline__ void clear(struct BITMAP *bmp)
         {
            clear_bitmap(bmp);
         }

user_defined_types: struct RLE_SPRITE { int w; int color_depth; int size; char dat[]; }

user_defined_types: struct FONT_GLYPH { short w; unsigned char dat[]; }

user_defined_types: struct V3D_f { float x; float u; int c; }


decompiled_code:
__int64 __fastcall draw_map(__int64 a1)
{
__int64 result; // rax
int v2; // er12
__int64 v3; // rsi
__int64 v4; // rbx
__int64 v5; // rdx

tiley = 0;
result = scrollbmp;
if ( *(int *)(scrollbmp + 4) > 0 )
{
v2 = 0;
do
{
tilex = 0;
v3 = scrollbmp;
if ( *(int *)scrollbmp > 0 )
{
v4 = v2 + 1;
v5 = 0LL;
do
{
v2 = v4;
draw_frame(
tilesbmp,
v3,
v5,
(unsigned int)tiley,
32LL,
32LL,
0LL,
0LL,
10LL,
*(unsigned int *)(a1 + 4 * v4 - 4));
v5 = (unsigned int)(tilex + 32);
tilex = v5;
v3 = scrollbmp;
++v4;
}
while ( (int)v5 < *(_DWORD *)scrollbmp );
}
result = (unsigned int)(tiley + 32);
tiley = result;
}
while ( (int)result < *(_DWORD *)(scrollbmp + 4) );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
int v2; // er12
__int64 v3; // rsi
__int64 v4; // rbx
__int64 v5; // rdx

tiley = 0;
result = scrollbmp;
if ( *(int *)(scrollbmp + 4) > 0 )
{
v2 = 0;
do
{
tilex = 0;
v3 = scrollbmp;
if ( *(int *)scrollbmp > 0 )
{
v4 = v2 + 1;
v5 = 0LL;
do
{
v2 = v4;
draw_frame(
tilesbmp,
v3,
v5,
(unsigned int)tiley,
32LL,
32LL,
0LL,
0LL,
10LL,
*(unsigned int *)(a1 + 4 * v4 - 4));
v5 = (unsigned int)(tilex + 32);
tilex = v5;
v3 = scrollbmp;
++v4;
}
while ( (int)v5 < *(_DWORD *)scrollbmp );
}
result = (unsigned int)(tiley + 32);
tiley = result;
}
while ( (int)result < *(_DWORD *)(scrollbmp + 4) );
}
return result;
}

original_code:
void draw_map (int map[]) {
  int i = 0;
  for (tiley = 0; tiley < scrollbmp->h; tiley += 32) {
    for (tilex = 0; tilex < scrollbmp->w; tilex += 32) {
      draw_frame (tilesbmp, scrollbmp, tilex, tiley, 32, 32, 0, 0,
                  10, map[i++]);
    }
  }
}

canonical_original_code:
void draw_map(int map[]) {
  int i = 0;
  for (tiley = 0; tiley < scrollbmp->h; tiley += 32) {
    for (tilex = 0; tilex < scrollbmp->w; tilex += 32) {
      draw_frame (tilesbmp, scrollbmp, tilex, tiley, 32, 32, 0, 0,
                  10, map[i++]);
    }
  }
}

variable_types:
map
int []


decompiled_code:
__int64 map_handler()
{
__int64 result; // rax
_DWORD *v1; // rax
int v2; // edx
int v3; // edx
int v4; // edx
int v5; // edx

result = currentmap;
switch ( *(_DWORD *)(currentmap + 12) )
{
case 0:
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
clear(scrollbmp);
*(_DWORD *)currentmap = 1;
*(_DWORD *)(currentmap + 4) = 0;
v1 = (_DWORD *)currentmap;
*(_DWORD *)(currentmap + 16) = 2;
v1[5] = 20;
v1[6] = 300;
v1[2] = 0;
}
return draw_map((__int64)&TCA13);
case 1:
v2 = *(_DWORD *)(currentmap + 4);
if ( !v2 )
{
if ( *(_DWORD *)(currentmap + 8) == 1 )
*(_DWORD *)(currentmap + 8) = 0;
goto LABEL_9;
}
if ( v2 == 1 )
{
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
**(_DWORD **)hero = TCA13startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCA13starty;
*(_DWORD *)(currentmap + 8) = 0;
}
LABEL_9:
result = draw_map((__int64)&TCA10);
}
return result;
case 6:
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
clear(scrollbmp);
**(_DWORD **)hero = TCCstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCCstarty;
scrollx = 0;
scrolly = 0;
*(_DWORD *)(currentmap + 8) = 0;
}
return draw_map((__int64)&TCC_L1);
case 7:
v4 = *(_DWORD *)(currentmap + 4);
if ( v4 )
{
if ( v4 == 1 && *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(3968LL, 3968LL);
clear(scrollbmp);
**(_DWORD **)hero = ALEFGARDBYstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = ALEFGARDBYstarty;
scrollx = 1300;
scrolly = 1300;
*(_DWORD *)(currentmap + 8) = 0;
}
}
else if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(3968LL, 3968LL);
clear(scrollbmp);
**(_DWORD **)hero = ALEFGARDTCstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = ALEFGARDTCstarty;
scrollx = 1300;
scrolly = 1300;
*(_DWORD *)(currentmap + 8) = 0;
}
return draw_map((__int64)&ALEFGARD);
case 9:
v5 = *(_DWORD *)(currentmap + 4);
if ( v5 )
{
if ( v5 == 1 && *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
clear(scrollbmp);
**(_DWORD **)hero = BYA2startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = BYA2starty;
scrollx = 384;
scrolly = 412;
*(_DWORD *)(currentmap + 8) = 0;
}
}
else if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
clear(scrollbmp);
**(_DWORD **)hero = BYA1startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = BYA1starty;
scrollx = 0;
scrolly = 128;
*(_DWORD *)(currentmap + 8) = 0;
}
return draw_map((__int64)&BYAL3L4);
case 0xA:
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
clear(scrollbmp);
**(_DWORD **)hero = BYBstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = BYBstarty;
scrollx = 0;
scrolly = 0;
*(_DWORD *)(currentmap + 8) = 0;
}
return draw_map((__int64)&BYB);
case 0xB:
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
clear(scrollbmp);
**(_DWORD **)hero = BYCstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = BYCstarty;
scrollx = 0;
scrolly = 0;
*(_DWORD *)(currentmap + 8) = 0;
}
return draw_map((__int64)&BYC);
case 0x14:
v3 = *(_DWORD *)(currentmap + 4);
if ( v3 == 1 )
{
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
**(_DWORD **)hero = TCB2startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCB2starty;
scrollx = 64;
scrolly = 544;
*(_DWORD *)(currentmap + 8) = 0;
}
}
else if ( v3 == 2 )
{
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
**(_DWORD **)hero = TCB3startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCB3starty;
scrollx = 384;
scrolly = 544;
*(_DWORD *)(currentmap + 8) = 0;
}
}
else
{
if ( v3 )
return result;
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
**(_DWORD **)hero = TCB1startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCB1starty;
*(_DWORD *)(currentmap + 8) = 0;
}
}
return draw_map((__int64)&TCBLALB);
default:
return result;
}
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
_DWORD *v1; // rax
int v2; // edx
int v3; // edx
int v4; // edx
int v5; // edx

result = currentmap;
switch ( *(_DWORD *)(currentmap + 12) )
{
case 0:
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
func0(scrollbmp);
*(_DWORD *)currentmap = 1;
*(_DWORD *)(currentmap + 4) = 0;
v1 = (_DWORD *)currentmap;
*(_DWORD *)(currentmap + 16) = 2;
v1[5] = 20;
v1[6] = 300;
v1[2] = 0;
}
return func1((__int64)&TCA13);
case 1:
v2 = *(_DWORD *)(currentmap + 4);
if ( !v2 )
{
if ( *(_DWORD *)(currentmap + 8) == 1 )
*(_DWORD *)(currentmap + 8) = 0;
goto LABEL_9;
}
if ( v2 == 1 )
{
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
**(_DWORD **)hero = TCA13startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCA13starty;
*(_DWORD *)(currentmap + 8) = 0;
}
LABEL_9:
result = func1((__int64)&TCA10);
}
return result;
case 6:
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
func0(scrollbmp);
**(_DWORD **)hero = TCCstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCCstarty;
scrollx = 0;
scrolly = 0;
*(_DWORD *)(currentmap + 8) = 0;
}
return func1((__int64)&TCC_L1);
case 7:
v4 = *(_DWORD *)(currentmap + 4);
if ( v4 )
{
if ( v4 == 1 && *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(3968LL, 3968LL);
func0(scrollbmp);
**(_DWORD **)hero = ALEFGARDBYstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = ALEFGARDBYstarty;
scrollx = 1300;
scrolly = 1300;
*(_DWORD *)(currentmap + 8) = 0;
}
}
else if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(3968LL, 3968LL);
func0(scrollbmp);
**(_DWORD **)hero = ALEFGARDTCstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = ALEFGARDTCstarty;
scrollx = 1300;
scrolly = 1300;
*(_DWORD *)(currentmap + 8) = 0;
}
return func1((__int64)&ALEFGARD);
case 9:
v5 = *(_DWORD *)(currentmap + 4);
if ( v5 )
{
if ( v5 == 1 && *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
func0(scrollbmp);
**(_DWORD **)hero = BYA2startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = BYA2starty;
scrollx = 384;
scrolly = 412;
*(_DWORD *)(currentmap + 8) = 0;
}
}
else if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
func0(scrollbmp);
**(_DWORD **)hero = BYA1startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = BYA1starty;
scrollx = 0;
scrolly = 128;
*(_DWORD *)(currentmap + 8) = 0;
}
return func1((__int64)&BYAL3L4);
case 0xA:
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
func0(scrollbmp);
**(_DWORD **)hero = BYBstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = BYBstarty;
scrollx = 0;
scrolly = 0;
*(_DWORD *)(currentmap + 8) = 0;
}
return func1((__int64)&BYB);
case 0xB:
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(640LL, 480LL);
func0(scrollbmp);
**(_DWORD **)hero = BYCstartx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = BYCstarty;
scrollx = 0;
scrolly = 0;
*(_DWORD *)(currentmap + 8) = 0;
}
return func1((__int64)&BYC);
case 0x14:
v3 = *(_DWORD *)(currentmap + 4);
if ( v3 == 1 )
{
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
**(_DWORD **)hero = TCB2startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCB2starty;
scrollx = 64;
scrolly = 544;
*(_DWORD *)(currentmap + 8) = 0;
}
}
else if ( v3 == 2 )
{
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
**(_DWORD **)hero = TCB3startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCB3starty;
scrollx = 384;
scrolly = 544;
*(_DWORD *)(currentmap + 8) = 0;
}
}
else
{
if ( v3 )
return result;
if ( *(_DWORD *)(currentmap + 8) == 1 )
{
scrollbmp = create_bitmap(1024LL, 1024LL);
**(_DWORD **)hero = TCB1startx;
*(_DWORD *)(*(_QWORD *)hero + 4LL) = TCB1starty;
*(_DWORD *)(currentmap + 8) = 0;
}
}
return func1((__int64)&TCBLALB);
default:
return result;
}
}

original_code:
void map_handler (void) {
  switch (currentmap->idnumber) {
  case 0:
    if (currentmap->initflag == 1) {
      scrollbmp = create_bitmap (20*32, 15*32);
      clear (scrollbmp);
      currentmap->lockeddoors = 0x1;
      currentmap->pointofentry = 0;
      currentmap->chests = 0x2;
      currentmap->width = 20;
      currentmap->maplen = 20*15;
      currentmap->initflag = 0;
    }
    draw_map (TCA13);
    break;
  case 1:
    switch (currentmap->pointofentry) {
    case 0:
      if (currentmap->initflag == 1) {
 currentmap->initflag = 0;
      }
      draw_map (TCA10);
      break;
    case 1:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (20*32, 15*32);
 hero->player->x = TCA13startx;
 hero->player->y = TCA13starty;
 currentmap->initflag = 0;
      }
      draw_map (TCA10);
      break;
    }
    break;
  case 20:
    switch (currentmap->pointofentry) {
    case 0:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 hero->player->x = TCB1startx;
 hero->player->y = TCB1starty;
 currentmap->initflag = 0;
      }
      draw_map (TCBLALB);
      break;
    case 1:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 hero->player->x = TCB2startx;
 hero->player->y = TCB2starty;
 scrollx = 64;
 scrolly = 544;
 currentmap->initflag = 0;
      }
      draw_map (TCBLALB);
      break;
    case 2:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 hero->player->x = TCB3startx;
 hero->player->y = TCB3starty;
 scrollx = 384;
 scrolly = 544;
 currentmap->initflag = 0;
      }
      draw_map (TCBLALB);
      break;
    }
    break;
  case 6:
    if (currentmap->initflag == 1) {
      scrollbmp = create_bitmap (20*32, 15*32);
      clear (scrollbmp);
      hero->player->x = TCCstartx;
      hero->player->y = TCCstarty;
      scrollx = 0;
      scrolly = 0;
      currentmap->initflag = 0;
    }
    draw_map (TCC_L1);
    break;
  case 7:
    switch (currentmap->pointofentry) {
    case 0:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (124*32, 124*32);
 clear (scrollbmp);
 hero->player->x = ALEFGARDTCstartx;
 hero->player->y = ALEFGARDTCstarty;
 scrollx = 1300;
 scrolly = 1300;
 currentmap->initflag = 0;
      }
      break;
    case 1:
      if (currentmap-> initflag == 1) {
 scrollbmp = create_bitmap (124*32, 124*32);
 clear (scrollbmp);
 hero->player->x = ALEFGARDBYstartx;
 hero->player->y = ALEFGARDBYstarty;
 scrollx = 1300;
 scrolly = 1300;
 currentmap->initflag = 0;
      }
    }
    draw_map (ALEFGARD);
    break;
  case 8:
    break;
  case 9:
    switch (currentmap->pointofentry) {
    case 0:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 clear (scrollbmp);
 hero->player->x = BYA1startx;
 hero->player->y = BYA1starty;
 scrollx = 0;
 scrolly = 128;
 currentmap->initflag = 0;
      }
      break;
    case 1:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 clear (scrollbmp);
 hero->player->x = BYA2startx;
 hero->player->y = BYA2starty;
 scrollx = 384;
 scrolly = 412;
 currentmap->initflag = 0;
      }
      break;
    case 2:
      break;
    }
    draw_map (BYAL3L4);
    break;
  case 10:
    if (currentmap->initflag == 1) {
      scrollbmp = create_bitmap (20*32, 15*32);
      clear (scrollbmp);
      hero->player->x = BYBstartx;
      hero->player->y = BYBstarty;
      scrollx = 0;
      scrolly = 0;
      currentmap->initflag = 0;
    }
    draw_map (BYB);
    break;
  case 11:
    if (currentmap->initflag == 1) {
      scrollbmp = create_bitmap (20*32, 15*32);
      clear (scrollbmp);
      hero->player->x = BYCstartx;
      hero->player->y = BYCstarty;
      scrollx = 0;
      scrolly = 0;
      currentmap->initflag = 0;
    }
    draw_map (BYC);
    break;
  }
}

canonical_original_code:
void map_handler() {
  switch (currentmap->idnumber) {
  case 0:
    if (currentmap->initflag == 1) {
      scrollbmp = create_bitmap (20*32, 15*32);
      clear (scrollbmp);
      currentmap->lockeddoors = 0x1;
      currentmap->pointofentry = 0;
      currentmap->chests = 0x2;
      currentmap->width = 20;
      currentmap->maplen = 20*15;
      currentmap->initflag = 0;
    }
    draw_map (TCA13);
    break;
  case 1:
    switch (currentmap->pointofentry) {
    case 0:
      if (currentmap->initflag == 1) {
 currentmap->initflag = 0;
      }
      draw_map (TCA10);
      break;
    case 1:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (20*32, 15*32);
 hero->player->x = TCA13startx;
 hero->player->y = TCA13starty;
 currentmap->initflag = 0;
      }
      draw_map (TCA10);
      break;
    }
    break;
  case 20:
    switch (currentmap->pointofentry) {
    case 0:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 hero->player->x = TCB1startx;
 hero->player->y = TCB1starty;
 currentmap->initflag = 0;
      }
      draw_map (TCBLALB);
      break;
    case 1:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 hero->player->x = TCB2startx;
 hero->player->y = TCB2starty;
 scrollx = 64;
 scrolly = 544;
 currentmap->initflag = 0;
      }
      draw_map (TCBLALB);
      break;
    case 2:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 hero->player->x = TCB3startx;
 hero->player->y = TCB3starty;
 scrollx = 384;
 scrolly = 544;
 currentmap->initflag = 0;
      }
      draw_map (TCBLALB);
      break;
    }
    break;
  case 6:
    if (currentmap->initflag == 1) {
      scrollbmp = create_bitmap (20*32, 15*32);
      clear (scrollbmp);
      hero->player->x = TCCstartx;
      hero->player->y = TCCstarty;
      scrollx = 0;
      scrolly = 0;
      currentmap->initflag = 0;
    }
    draw_map (TCC_L1);
    break;
  case 7:
    switch (currentmap->pointofentry) {
    case 0:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (124*32, 124*32);
 clear (scrollbmp);
 hero->player->x = ALEFGARDTCstartx;
 hero->player->y = ALEFGARDTCstarty;
 scrollx = 1300;
 scrolly = 1300;
 currentmap->initflag = 0;
      }
      break;
    case 1:
      if (currentmap-> initflag == 1) {
 scrollbmp = create_bitmap (124*32, 124*32);
 clear (scrollbmp);
 hero->player->x = ALEFGARDBYstartx;
 hero->player->y = ALEFGARDBYstarty;
 scrollx = 1300;
 scrolly = 1300;
 currentmap->initflag = 0;
      }
    }
    draw_map (ALEFGARD);
    break;
  case 8:
    break;
  case 9:
    switch (currentmap->pointofentry) {
    case 0:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 clear (scrollbmp);
 hero->player->x = BYA1startx;
 hero->player->y = BYA1starty;
 scrollx = 0;
 scrolly = 128;
 currentmap->initflag = 0;
      }
      break;
    case 1:
      if (currentmap->initflag == 1) {
 scrollbmp = create_bitmap (32*32, 32*32);
 clear (scrollbmp);
 hero->player->x = BYA2startx;
 hero->player->y = BYA2starty;
 scrollx = 384;
 scrolly = 412;
 currentmap->initflag = 0;
      }
      break;
    case 2:
      break;
    }
    draw_map (BYAL3L4);
    break;
  case 10:
    if (currentmap->initflag == 1) {
      scrollbmp = create_bitmap (20*32, 15*32);
      clear (scrollbmp);
      hero->player->x = BYBstartx;
      hero->player->y = BYBstarty;
      scrollx = 0;
      scrolly = 0;
      currentmap->initflag = 0;
    }
    draw_map (BYB);
    break;
  case 11:
    if (currentmap->initflag == 1) {
      scrollbmp = create_bitmap (20*32, 15*32);
      clear (scrollbmp);
      hero->player->x = BYCstartx;
      hero->player->y = BYCstarty;
      scrollx = 0;
      scrolly = 0;
      currentmap->initflag = 0;
    }
    draw_map (BYC);
    break;
  }
}


decompiled_code:
__int64 print_scroll_debug_messages()
{
unsigned int v0; // eax
int v1; // ebp
__int64 v2; // rbx
unsigned int v3; // eax
__int64 v4; // rbp
__int64 v5; // rbx
unsigned int v6; // eax
__int64 v8; // [rsp+0h] [rbp-28h]

v0 = makecol(255LL, 255LL, 255LL);
textprintf_ex(bufferbmp, font, 0LL, 0LL, v0, 0xFFFFFFFFLL, "Scroll Window Position:");
v1 = scrolly;
v2 = (unsigned int)scrollx;
v3 = makecol(255LL, 255LL, 255LL);
LODWORD(v8) = v1;
textprintf_ex(bufferbmp, font, 0LL, 10LL, v3, 0xFFFFFFFFLL, "tl = (%d,%d)", v2, v8);
v4 = (unsigned int)(scrolly + 240);
v5 = (unsigned int)(scrollx + 320);
v6 = makecol(255LL, 255LL, 255LL);
return textprintf_ex(bufferbmp, font, 0LL, 20LL, v6, 0xFFFFFFFFLL, "center = (%d,%d)", v5, v4);
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
int v1; // ebp
__int64 v2; // rbx
unsigned int v3; // eax
__int64 v4; // rbp
__int64 v5; // rbx
unsigned int v6; // eax
__int64 v8; // [rsp+0h] [rbp-28h]

v0 = makecol(255LL, 255LL, 255LL);
textprintf_ex(bufferbmp, font, 0LL, 0LL, v0, 0xFFFFFFFFLL, "Scroll Window Position:");
v1 = scrolly;
v2 = (unsigned int)scrollx;
v3 = makecol(255LL, 255LL, 255LL);
LODWORD(v8) = v1;
textprintf_ex(bufferbmp, font, 0LL, 10LL, v3, 0xFFFFFFFFLL, "tl = (%d,%d)", v2, v8);
v4 = (unsigned int)(scrolly + 240);
v5 = (unsigned int)(scrollx + 320);
v6 = makecol(255LL, 255LL, 255LL);
return textprintf_ex(bufferbmp, font, 0LL, 20LL, v6, 0xFFFFFFFFLL, "center = (%d,%d)", v5, v4);
}

original_code:
void print_scroll_debug_messages (void) {
  textprintf_ex (bufferbmp, font, 0, 0, makecol (255,255,255), -1,
   "Scroll Window Position:");
  textprintf_ex (bufferbmp, font, 0, 10, makecol (255,255,255), -1,
   "tl = (%d,%d)", scrollx, scrolly);
  textprintf_ex (bufferbmp, font, 0, 20, makecol (255,255,255), -1,
   "center = (%d,%d)", scrollx+640/2, scrolly+480/2);
}

canonical_original_code:
void print_scroll_debug_messages() {
  textprintf_ex (bufferbmp, font, 0, 0, makecol (255,255,255), -1,
   "Scroll Window Position:");
  textprintf_ex (bufferbmp, font, 0, 10, makecol (255,255,255), -1,
   "tl = (%d,%d)", scrollx, scrolly);
  textprintf_ex (bufferbmp, font, 0, 20, makecol (255,255,255), -1,
   "center = (%d,%d)", scrollx+640/2, scrolly+480/2);
}


decompiled_code:
__int64 print_player_debug_messages()
{
unsigned int v0; // eax
int v1; // ebp
__int64 v2; // rbx
unsigned int v3; // eax
__int64 v5; // [rsp+0h] [rbp-28h]

v0 = makecol(255LL, 255LL, 255LL);
textprintf_ex(bufferbmp, font, 200LL, 0LL, v0, 0xFFFFFFFFLL, "Player Position:");
v1 = *(_DWORD *)(*(_QWORD *)hero + 4LL);
v2 = **(unsigned int **)hero;
v3 = makecol(255LL, 255LL, 255LL);
LODWORD(v5) = v1;
return textprintf_ex(bufferbmp, font, 200LL, 10LL, v3, 0xFFFFFFFFLL, "tl = (%d,%d)", v2, v5);
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // eax
int v1; // ebp
__int64 v2; // rbx
unsigned int v3; // eax
__int64 v5; // [rsp+0h] [rbp-28h]

v0 = makecol(255LL, 255LL, 255LL);
textprintf_ex(bufferbmp, font, 200LL, 0LL, v0, 0xFFFFFFFFLL, "Player Position:");
v1 = *(_DWORD *)(*(_QWORD *)hero + 4LL);
v2 = **(unsigned int **)hero;
v3 = makecol(255LL, 255LL, 255LL);
LODWORD(v5) = v1;
return textprintf_ex(bufferbmp, font, 200LL, 10LL, v3, 0xFFFFFFFFLL, "tl = (%d,%d)", v2, v5);
}

original_code:
void print_player_debug_messages (void) {
  textprintf_ex (bufferbmp, font, 200, 0, makecol (255,255,255), -1,
   "Player Position:");
  textprintf_ex (bufferbmp, font, 200, 10, makecol (255,255,255), -1,
   "tl = (%d,%d)", hero->player->x, hero->player->y);
}

canonical_original_code:
void print_player_debug_messages() {
  textprintf_ex (bufferbmp, font, 200, 0, makecol (255,255,255), -1,
   "Player Position:");
  textprintf_ex (bufferbmp, font, 200, 10, makecol (255,255,255), -1,
   "tl = (%d,%d)", hero->player->x, hero->player->y);
}


main

canonical_name: main

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

setup_allegro(2LL, 640LL, 480LL, 16LL);
setup_bmps();
setup_player();
scrollx = 0;
scrolly = 0;
v3 = malloc(0x1CuLL);
currentmap = (__int64)v3;
v3[2] = 1;
v3[3] = 0;
map_handler();
while ( !key[59] )
{
get_input();
move_player();
scroll_window();
animate_player();
map_event_handler();
map_handler();
draw_player();
blit(scrollbmp, bufferbmp, (unsigned int)scrollx, (unsigned int)scrolly, 0LL, 0LL, 639LL, 479LL);
print_scroll_debug_messages();
print_player_debug_messages();
acquire_screen();
blit(bufferbmp, screen, 0LL, 0LL, 0LL, 0LL, 639LL, 479LL);
release_screen();
rest(20LL);
}
destroy_bmps();
allegro_exit();
return 0;
}

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

setup_allegro(2LL, 640LL, 480LL, 16LL);
setup_bmps();
setup_player();
scrollx = 0;
scrolly = 0;
v3 = malloc(0x1CuLL);
currentmap = (__int64)v3;
v3[2] = 1;
v3[3] = 0;
map_handler();
while ( !key[59] )
{
get_input();
move_player();
scroll_window();
animate_player();
map_event_handler();
map_handler();
draw_player();
blit(scrollbmp, bufferbmp, (unsigned int)scrollx, (unsigned int)scrolly, 0LL, 0LL, 639LL, 479LL);
func0();
func1();
acquire_screen();
blit(bufferbmp, screen, 0LL, 0LL, 0LL, 0LL, 639LL, 479LL);
release_screen();
rest(20LL);
}
destroy_bmps();
allegro_exit();
return 0;
}

original_code:
int main (void) {
  setup_allegro (2, 640, 480, 16);
  setup_bmps();
  setup_player();
  scrollx = 0;
  scrolly = 0;
  currentmap = (MAP*)malloc (sizeof (MAP));
  currentmap->initflag = 1;
  currentmap->idnumber = 0;
  map_handler();
  while (!key[__allegro_KEY_ESC]) {
    get_input();
    move_player();
    scroll_window();
    animate_player();
    map_event_handler();
    map_handler();
    draw_player();
    blit (scrollbmp, bufferbmp, scrollx, scrolly, 0, 0, 640 -1, 480 -1);
    print_scroll_debug_messages();
    print_player_debug_messages();
    acquire_screen();
    blit (bufferbmp, screen, 0, 0, 0, 0, 640 -1, 480 -1);
    release_screen();
    rest (20);
  }
  destroy_bmps();
  allegro_exit();
  return 0;
}

canonical_original_code:
int main() {
  setup_allegro (2, 640, 480, 16);
  setup_bmps();
  setup_player();
  scrollx = 0;
  scrolly = 0;
  currentmap = (struct MAP *)malloc (sizeof (MAP));
  currentmap->initflag = 1;
  currentmap->idnumber = 0;
  map_handler();
  while (!key[__allegro_KEY_ESC]) {
    get_input();
    move_player();
    scroll_window();
    animate_player();
    map_event_handler();
    map_handler();
    draw_player();
    blit (scrollbmp, bufferbmp, scrollx, scrolly, 0, 0, 640 -1, 480 -1);
    print_scroll_debug_messages();
    print_player_debug_messages();
    acquire_screen();
    blit (bufferbmp, screen, 0, 0, 0, 0, 640 -1, 480 -1);
    release_screen();
    rest (20);
  }
  destroy_bmps();
  allegro_exit();
  return 0;
}

return_type: int

user_defined_types: struct MAP { int lockeddoors; int pointofentry; int initflag; int idnumber; int chests; int width; int maplen; }


decompiled_code:
void is_collision()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
int is_collision (int map[]) {
  int playerleft = hero->player->x;
  int playerright = hero->player->x+hero->player->width;
  int playertop = hero->player->y;
  int playerbottom = hero->player->y+hero->player->height;
  int tileleft;
  int tileright;
}

canonical_original_code:
int is_collision(int map[]) {
  int playerleft = hero->player->x;
  int playerright = hero->player->x+hero->player->width;
  int playertop = hero->player->y;
  int playerbottom = hero->player->y+hero->player->height;
  int tileleft;
  int tileright;
}

variable_types: playerleft int

variable_types: playerright int

variable_types: playertop int

variable_types: playerbottom int

variable_types: tileleft int

variable_types: tileright int


decompiled_code:
__int64 map_event_handler()
{
__int64 result; // rax
__int64 v1; // rcx
int v2; // edx

result = currentmap;
if ( *(_DWORD *)(currentmap + 12) == 9 )
{
v1 = *(_QWORD *)hero;
v2 = **(_DWORD **)hero;
if ( v2 )
{
if ( v2 == 736 )
{
if ( *(_DWORD *)(v1 + 4) == 768 )
{
*(_DWORD *)(currentmap + 12) = 11;
*(_DWORD *)(result + 8) = 1;
*(_DWORD *)(result + 4) = 0;
}
}
else if ( v2 == 704 && *(_DWORD *)(v1 + 4) == 224 )
{
*(_DWORD *)(currentmap + 12) = 10;
*(_DWORD *)(result + 8) = 1;
*(_DWORD *)(result + 4) = 0;
}
}
else
{
*(_DWORD *)(currentmap + 12) = 7;
*(_DWORD *)(result + 8) = 1;
*(_DWORD *)(result + 4) = 1;
}
}
return result;
}

original_code:
void map_event_handler (void) {
  switch (currentmap->idnumber) {
  case 0:
    break;
  case 2:
    break;
  case 20:
    break;
  case 9:
    if (hero->player->x == 0) {
      currentmap->idnumber = 7;
      currentmap->initflag = 1;
      currentmap->pointofentry = 1;
    } else if (hero->player->x == 736 && hero->player->y == 768) {
      currentmap->idnumber = 11;
      currentmap->initflag = 1;
      currentmap->pointofentry = 0;
    } else if (hero->player->x == 704 && hero->player->y == 224) {
      currentmap->idnumber = 10;
      currentmap->initflag = 1;
      currentmap->pointofentry = 0;
    }
    break;
  }
}

canonical_original_code:
void map_event_handler() {
  switch (currentmap->idnumber) {
  case 0:
    break;
  case 2:
    break;
  case 20:
    break;
  case 9:
    if (hero->player->x == 0) {
      currentmap->idnumber = 7;
      currentmap->initflag = 1;
      currentmap->pointofentry = 1;
    } else if (hero->player->x == 736 && hero->player->y == 768) {
      currentmap->idnumber = 11;
      currentmap->initflag = 1;
      currentmap->pointofentry = 0;
    } else if (hero->player->x == 704 && hero->player->y == 224) {
      currentmap->idnumber = 10;
      currentmap->initflag = 1;
      currentmap->pointofentry = 0;
    }
    break;
  }
}


original_code:
void get_input (void) {
  if (key[__allegro_KEY_RIGHT]) {
    hero->player->direction = 2;
    hero->player->xspeed = 2;
  } else if (key[__allegro_KEY_LEFT]) {
    hero->player->direction = 3;
    hero->player->xspeed = -2;
  } else if (key[__allegro_KEY_DOWN]) {
    hero->player->direction = 0;
    hero->player->yspeed = 2;
  } else if (key[__allegro_KEY_UP]) {
    hero->player->direction = 1;
    hero->player->yspeed = -2;
  } else {
    hero->player->xspeed = 0;
    hero->player->yspeed = 0;
  }
  if (key[__allegro_KEY_X]) {
    switch (currentmap->idnumber) {
    case 0:
      break;
    }
  }
}

canonical_original_code:
void get_input() {
  if (key[__allegro_KEY_RIGHT]) {
    hero->player->direction = 2;
    hero->player->xspeed = 2;
  } else if (key[__allegro_KEY_LEFT]) {
    hero->player->direction = 3;
    hero->player->xspeed = -2;
  } else if (key[__allegro_KEY_DOWN]) {
    hero->player->direction = 0;
    hero->player->yspeed = 2;
  } else if (key[__allegro_KEY_UP]) {
    hero->player->direction = 1;
    hero->player->yspeed = -2;
  } else {
    hero->player->xspeed = 0;
    hero->player->yspeed = 0;
  }
  if (key[__allegro_KEY_X]) {
    switch (currentmap->idnumber) {
    case 0:
      break;
    }
  }
}


decompiled_code:
_DWORD *setup_player()
{
_DWORD *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x18uLL);
hero = (__int64)v0;
result = malloc(0x2CuLL);
*(_QWORD *)v0 = result;
*result = TCA13startx;
result[1] = TCA13starty;
result[2] = 3;
result[3] = 32;
result[4] = 32;
result[5] = 0;
result[6] = 0;
result[7] = 0;
result[8] = 1;
result[9] = 0;
result[10] = 8;
v0[2] = 0;
v0[3] = 0;
v0[4] = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *v0; // rbx
_DWORD *result; // rax

v0 = malloc(0x18uLL);
hero = (__int64)v0;
result = malloc(0x2CuLL);
*(_QWORD *)v0 = result;
*result = TCA13startx;
result[1] = TCA13starty;
result[2] = 3;
result[3] = 32;
result[4] = 32;
result[5] = 0;
result[6] = 0;
result[7] = 0;
result[8] = 1;
result[9] = 0;
result[10] = 8;
v0[2] = 0;
v0[3] = 0;
v0[4] = 0;
return result;
}

original_code:
void setup_player (void) {
  hero = (HERO*)malloc (sizeof (HERO));
  hero->player = (SPRITE*)malloc (sizeof (SPRITE));
  hero->player->x = TCA13startx;
  hero->player->y = TCA13starty;
  hero->player->direction = 3;
  hero->player->width = 32;
  hero->player->height = 32;
  hero->player->xspeed = 0;
  hero->player->yspeed = 0;
  hero->player->curframe = 0;
  hero->player->maxframe = 1;
  hero->player->framecount = 0;
  hero->player->framedelay = 8;
  hero->keys = 0;
  hero->gold = 0;
  hero->experience = 0;
}

canonical_original_code:
void setup_player() {
  hero = (struct HERO *)malloc (sizeof (HERO));
  hero->player = (struct SPRITE *)malloc (sizeof (SPRITE));
  hero->player->x = TCA13startx;
  hero->player->y = TCA13starty;
  hero->player->direction = 3;
  hero->player->width = 32;
  hero->player->height = 32;
  hero->player->xspeed = 0;
  hero->player->yspeed = 0;
  hero->player->curframe = 0;
  hero->player->maxframe = 1;
  hero->player->framecount = 0;
  hero->player->framedelay = 8;
  hero->keys = 0;
  hero->gold = 0;
  hero->experience = 0;
}

user_defined_types: struct HERO { struct SPRITE *player; int keys; int gold; int experience; }

user_defined_types: struct SPRITE { int x; int y; int direction; int width; int height; int xspeed; int yspeed; int curframe; int maxframe; int framecount; int framedelay; }


decompiled_code:
__int64 draw_player()
{
unsigned int *v0; // rdx
__int64 result; // rax

v0 = *(unsigned int **)hero;
result = *(unsigned int *)(*(_QWORD *)hero + 8LL);
if ( (_DWORD)result == 2 )
return draw_sprite(scrollbmp, playerrtbmp[v0[7]], *v0, v0[1]);
if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
result = draw_sprite(scrollbmp, playerltbmp[v0[7]], *v0, v0[1]);
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = draw_sprite(scrollbmp, playerupbmp[v0[7]], *v0, v0[1]);
}
else
{
result = draw_sprite(scrollbmp, playerdnbmp[v0[7]], *v0, v0[1]);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int *v0; // rdx
__int64 result; // rax

v0 = *(unsigned int **)hero;
result = *(unsigned int *)(*(_QWORD *)hero + 8LL);
if ( (_DWORD)result == 2 )
return draw_sprite(scrollbmp, playerrtbmp[v0[7]], *v0, v0[1]);
if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
result = draw_sprite(scrollbmp, playerltbmp[v0[7]], *v0, v0[1]);
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = draw_sprite(scrollbmp, playerupbmp[v0[7]], *v0, v0[1]);
}
else
{
result = draw_sprite(scrollbmp, playerdnbmp[v0[7]], *v0, v0[1]);
}
return result;
}

original_code:
void draw_player (void) {
  switch (hero->player->direction) {
  case 0:
    draw_sprite (scrollbmp, playerdnbmp[hero->player->curframe],
   hero->player->x, hero->player->y);
    break;
  case 1:
    draw_sprite (scrollbmp, playerupbmp[hero->player->curframe],
   hero->player->x, hero->player->y);
    break;
  case 3:
    draw_sprite (scrollbmp, playerltbmp[hero->player->curframe],
   hero->player->x, hero->player->y);
    break;
  case 2:
    draw_sprite (scrollbmp, playerrtbmp[hero->player->curframe],
   hero->player->x, hero->player->y);
    break;
  }
}

canonical_original_code:
void draw_player() {
  switch (hero->player->direction) {
  case 0:
    draw_sprite (scrollbmp, playerdnbmp[hero->player->curframe],
   hero->player->x, hero->player->y);
    break;
  case 1:
    draw_sprite (scrollbmp, playerupbmp[hero->player->curframe],
   hero->player->x, hero->player->y);
    break;
  case 3:
    draw_sprite (scrollbmp, playerltbmp[hero->player->curframe],
   hero->player->x, hero->player->y);
    break;
  case 2:
    draw_sprite (scrollbmp, playerrtbmp[hero->player->curframe],
   hero->player->x, hero->player->y);
    break;
  }
}


decompiled_code:
_DWORD *animate_player()
{
__int64 v0; // rdx
_DWORD *result; // rax
int v2; // ecx

v0 = hero;
result = *(_DWORD **)hero;
if ( *(_DWORD *)(*(_QWORD *)hero + 20LL) || result[6] )
{
v2 = result[9];
result[9] = v2 + 1;
result = *(_DWORD **)v0;
if ( v2 > *(_DWORD *)(*(_QWORD *)v0 + 40LL) )
{
result[9] = 0;
++*(_DWORD *)(*(_QWORD *)v0 + 28LL);
result = *(_DWORD **)v0;
if ( *(_DWORD *)(*(_QWORD *)v0 + 28LL) > *(_DWORD *)(*(_QWORD *)v0 + 32LL) )
result[7] = 0;
}
}
return result;
}

canonical_decompiled_code:
_DWORD *func2()
{
__int64 v0; // rdx
_DWORD *result; // rax
int v2; // ecx

v0 = hero;
result = *(_DWORD **)hero;
if ( *(_DWORD *)(*(_QWORD *)hero + 20LL) || result[6] )
{
v2 = result[9];
result[9] = v2 + 1;
result = *(_DWORD **)v0;
if ( v2 > *(_DWORD *)(*(_QWORD *)v0 + 40LL) )
{
result[9] = 0;
++*(_DWORD *)(*(_QWORD *)v0 + 28LL);
result = *(_DWORD **)v0;
if ( *(_DWORD *)(*(_QWORD *)v0 + 28LL) > *(_DWORD *)(*(_QWORD *)v0 + 32LL) )
result[7] = 0;
}
}
return result;
}

original_code:
void animate_player (void) {
  if (hero->player->xspeed != 0 || hero->player->yspeed != 0) {
    if (hero->player->framecount++ > hero->player->framedelay) {
      hero->player->framecount = 0;
      hero->player->curframe++;
      if (hero->player->curframe > hero->player->maxframe)
 hero->player->curframe = 0;
    }
  }
}

canonical_original_code:
void animate_player() {
  if (hero->player->xspeed != 0 || hero->player->yspeed != 0) {
    if (hero->player->framecount++ > hero->player->framedelay) {
      hero->player->framecount = 0;
      hero->player->curframe++;
      if (hero->player->curframe > hero->player->maxframe)
 hero->player->curframe = 0;
    }
  }
}


decompiled_code:
__int64 move_player()
{
int *v0; // rdx
__int64 result; // rax
int v2; // ecx

v0 = *(int **)hero;
result = *(unsigned int *)(*(_QWORD *)hero + 8LL);
if ( (_DWORD)result == 2 )
{
result = (unsigned int)(*(_DWORD *)scrollbmp - 32);
if ( *v0 < (int)result )
*v0 += v0[5];
}
else if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
{
result = (unsigned int)*v0;
if ( (int)result > scrollx )
{
result = (unsigned int)(v0[5] + result);
*v0 = result;
}
}
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
result = (unsigned int)v0[1];
if ( (int)result > scrolly )
{
result = (unsigned int)(v0[6] + result);
v0[1] = result;
}
}
}
else
{
v2 = v0[1];
result = (unsigned int)(*(_DWORD *)(scrollbmp + 4) - 32);
if ( v2 < (int)result )
v0[1] = v0[6] + v2;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
int *v0; // rdx
__int64 result; // rax
int v2; // ecx

v0 = *(int **)hero;
result = *(unsigned int *)(*(_QWORD *)hero + 8LL);
if ( (_DWORD)result == 2 )
{
result = (unsigned int)(*(_DWORD *)scrollbmp - 32);
if ( *v0 < (int)result )
*v0 += v0[5];
}
else if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
{
result = (unsigned int)*v0;
if ( (int)result > scrollx )
{
result = (unsigned int)(v0[5] + result);
*v0 = result;
}
}
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
result = (unsigned int)v0[1];
if ( (int)result > scrolly )
{
result = (unsigned int)(v0[6] + result);
v0[1] = result;
}
}
}
else
{
v2 = v0[1];
result = (unsigned int)(*(_DWORD *)(scrollbmp + 4) - 32);
if ( v2 < (int)result )
v0[1] = v0[6] + v2;
}
return result;
}

original_code:
void move_player (void) {
  switch (hero->player->direction) {
  case 0:
    if (hero->player->y < scrollbmp->h-32) hero->player->y +=
          hero->player->yspeed;
    break;
  case 1:
    if (hero->player->y > scrolly) hero->player->y += hero->player->yspeed;
    break;
  case 3:
    if (hero->player->x > scrollx) hero->player->x += hero->player->xspeed;
    break;
  case 2:
    if (hero->player->x < scrollbmp->w-32) hero->player->x +=
          hero->player->xspeed;
    break;
  }
}

canonical_original_code:
void move_player() {
  switch (hero->player->direction) {
  case 0:
    if (hero->player->y < scrollbmp->h-32) hero->player->y +=
          hero->player->yspeed;
    break;
  case 1:
    if (hero->player->y > scrolly) hero->player->y += hero->player->yspeed;
    break;
  case 3:
    if (hero->player->x > scrollx) hero->player->x += hero->player->xspeed;
    break;
  case 2:
    if (hero->player->x < scrollbmp->w-32) hero->player->x +=
          hero->player->xspeed;
    break;
  }
}


decompiled_code:
__int64 scroll_window()
{
__int64 v0; // rdx
__int64 result; // rax
int v2; // edx
int v3; // edx
int v4; // eax
int v5; // ecx

v0 = *(_QWORD *)hero;
result = *(unsigned int *)(*(_QWORD *)hero + 8LL);
if ( (_DWORD)result == 2 )
{
v2 = *(_DWORD *)(v0 + 20) + scrollx;
scrollx = v2;
result = (unsigned int)(*(_DWORD *)scrollbmp - 640);
if ( v2 < *(_DWORD *)scrollbmp - 639 )
result = (unsigned int)v2;
scrollx = result;
}
else if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
{
result = (unsigned int)(*(_DWORD *)(v0 + 20) + scrollx);
if ( (int)result < 0 )
result = 0LL;
scrollx = result;
}
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
result = (unsigned int)(*(_DWORD *)(v0 + 24) + scrolly);
if ( (int)result < 0 )
result = 0LL;
scrolly = result;
}
}
else
{
v3 = *(_DWORD *)(v0 + 24) + scrolly;
v4 = *(_DWORD *)(scrollbmp + 4);
v5 = v4 - 479;
result = (unsigned int)(v4 - 480);
if ( v3 < v5 )
result = (unsigned int)v3;
scrolly = result;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rdx
__int64 result; // rax
int v2; // edx
int v3; // edx
int v4; // eax
int v5; // ecx

v0 = *(_QWORD *)hero;
result = *(unsigned int *)(*(_QWORD *)hero + 8LL);
if ( (_DWORD)result == 2 )
{
v2 = *(_DWORD *)(v0 + 20) + scrollx;
scrollx = v2;
result = (unsigned int)(*(_DWORD *)scrollbmp - 640);
if ( v2 < *(_DWORD *)scrollbmp - 639 )
result = (unsigned int)v2;
scrollx = result;
}
else if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
{
result = (unsigned int)(*(_DWORD *)(v0 + 20) + scrollx);
if ( (int)result < 0 )
result = 0LL;
scrollx = result;
}
}
else if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
{
result = (unsigned int)(*(_DWORD *)(v0 + 24) + scrolly);
if ( (int)result < 0 )
result = 0LL;
scrolly = result;
}
}
else
{
v3 = *(_DWORD *)(v0 + 24) + scrolly;
v4 = *(_DWORD *)(scrollbmp + 4);
v5 = v4 - 479;
result = (unsigned int)(v4 - 480);
if ( v3 < v5 )
result = (unsigned int)v3;
scrolly = result;
}
return result;
}

original_code:
void scroll_window (void) {
  switch (hero->player->direction) {
  case 2:
    scrollx += hero->player->xspeed;
    if (scrollx > scrollbmp->w-640) scrollx = scrollbmp->w - 640;
    break;
  case 3:
    scrollx += hero->player->xspeed;
    if (scrollx < 0) scrollx = 0;
    break;
  case 1:
    scrolly += hero->player->yspeed;
    if (scrolly < 0) scrolly = 0;
    break;
  case 0:
    scrolly += hero->player->yspeed;
    if (scrolly > scrollbmp->h-480) scrolly = scrollbmp->h - 480;
    break;
  }
}

canonical_original_code:
void scroll_window() {
  switch (hero->player->direction) {
  case 2:
    scrollx += hero->player->xspeed;
    if (scrollx > scrollbmp->w-640) scrollx = scrollbmp->w - 640;
    break;
  case 3:
    scrollx += hero->player->xspeed;
    if (scrollx < 0) scrollx = 0;
    break;
  case 1:
    scrolly += hero->player->yspeed;
    if (scrolly < 0) scrolly = 0;
    break;
  case 0:
    scrolly += hero->player->yspeed;
    if (scrolly > scrollbmp->h-480) scrolly = scrollbmp->h - 480;
    break;
  }
}


decompiled_code:
__int64 __fastcall draw_frame(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10)
{
return masked_blit(a1, a2, (unsigned int)(a7 + a5 * (a10 % a9)), (unsigned int)(a8 + a6 * (a10 / a9)), a3, a4, a5, a6);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5, __int64 a6, int a7, int a8, int a9, int a10)
{
return masked_blit(a1, a2, (unsigned int)(a7 + a5 * (a10 % a9)), (unsigned int)(a8 + a6 * (a10 / a9)), a3, a4, a5, a6);
}

original_code:
void draw_frame (BITMAP *source, BITMAP *destination, int x, int y, int width,
                int height, int startx, int starty, int columns, int frame) {
  int framex = startx + (frame%columns)*width;
  int framey = starty + (frame/columns)*height;
  masked_blit (source, destination, framex, framey, x, y, width, height);
}

canonical_original_code:
void draw_frame(struct BITMAP *source, struct BITMAP *destination, int x, int y, int width, int height, int startx, int starty, int columns, int frame) {
  int framex = startx + (frame%columns)*width;
  int framey = starty + (frame/columns)*height;
  masked_blit (source, destination, framex, framey, x, y, width, height);
}

variable_types:
destination
struct BITMAP *

variable_types: x int

variable_types: y int

variable_types: width int

variable_types: height int

variable_types: startx int

variable_types: starty int

variable_types: columns int

variable_types: frame int

variable_types: framex int

variable_types: framey int


decompiled_code:
__int64 __fastcall grab_frame(__int64 a1, unsigned int a2, unsigned int a3, int a4, int a5, int a6, int a7)
{
__int64 v7; // rbp
__int64 v10; // r12

v7 = a3;
v10 = create_bitmap(a2, a3);
blit(a1, v10, a4 + a2 * (a7 % a6), (unsigned int)(v7 * (a7 / a6) + a5), 0LL, 0LL, a2, v7);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3, int a4, int a5, int a6, int a7)
{
__int64 v7; // rbp
__int64 v10; // r12

v7 = a3;
v10 = create_bitmap(a2, a3);
blit(a1, v10, a4 + a2 * (a7 % a6), (unsigned int)(v7 * (a7 / a6) + a5), 0LL, 0LL, a2, v7);
return v10;
}

original_code:
BITMAP *grab_frame (BITMAP *source, int width, int height, int startx,
      int starty, int columns, int frame) {
  BITMAP *tempbmp = create_bitmap (width, height);
  int x = startx + (frame%columns)*width;
  int y = starty + (frame/columns)*height;
  blit (source, tempbmp, x, y, 0, 0, width, height);
  return tempbmp;
}

canonical_original_code:
struct BITMAP *grab_frame(struct BITMAP *source, int width, int height, int startx, int starty, int columns, int frame) {
  struct BITMAP *tempbmp = create_bitmap (width, height);
  int x = startx + (frame%columns)*width;
  int y = starty + (frame/columns)*height;
  blit (source, tempbmp, x, y, 0, 0, width, height);
  return tempbmp;
}

variable_types:
source
struct BITMAP *

variable_types: struct BITMAP { int w; int clip; int cl; struct GFX_VTABLE { int color_depth; int mask_color; void *unwrite_bank; void (*set_clip)(struct BITMAP *bmp); void (*acquire)(struct BITMAP *bmp); void (*release)(struct BITMAP *bmp); struct BITMAP *(*create_sub_bitmap)(struct BITMAP *parent, int x, int y, int width, int height); void (*created_sub_bitmap)(struct BITMAP *bmp, struct BITMAP *parent); int (*getpixel)(struct BITMAP *bmp, int x, int y); void (*putpixel)(struct BITMAP *bmp, int x, int y, int color); void (*vline)(struct BITMAP *bmp, int x, int y_1, int y2, int color); void (*hline)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*hfill)(struct BITMAP *bmp, int x1, int y, int x2, int color); void (*line)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*fastline)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*rectfill)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*triangle)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int x3, int y3, int color); void (*draw_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_256_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_v_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_h_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_sprite_vh_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_trans_rgba_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y); void (*draw_lit_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color); void (*draw_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE { int w; int color_depth; int size; char dat[]; } *sprite, int x, int y); void (*draw_trans_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_trans_rgba_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y); void (*draw_lit_rle_sprite)(struct BITMAP *bmp, struct RLE_SPRITE *sprite, int x, int y, int color); void (*draw_character)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int color, int bg); void (*draw_glyph)(struct BITMAP *bmp, struct FONT_GLYPH { short w; unsigned char dat[]; } *glyph, int x, int y, int color, int bg); void (*blit_from_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_memory)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_from_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_system)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_forward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_to_self_backward)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*blit_between_formats)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*masked_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height); void (*clear_to_color)(struct BITMAP *bitmap, int color); void (*pivot_scaled_sprite_flip)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int cx, int cy, int angle, int scale, int v_flip); void (*do_stretch_blit)(struct BITMAP *source, struct BITMAP *dest, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int dest_width, int dest_height, int masked); void (*draw_gouraud_sprite)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int c1, int c2, int c3, int c4); void (*draw_sprite_end)(); void (*blit_end)(); void (*polygon)(struct BITMAP *bmp, int vertices, int *points, int color); void (*rect)(struct BITMAP *bmp, int x1, int y_1, int x2, int y2, int color); void (*circle)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*circlefill)(struct BITMAP *bmp, int x, int y, int radius, int color); void (*ellipse)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*ellipsefill)(struct BITMAP *bmp, int x, int y, int rx, int ry, int color); void (*arc)(struct BITMAP *bmp, int x, int y, int ang1, int ang2, int r, int color); void (*spline)(struct BITMAP *bmp, int points[8], int color); void (*floodfill)(struct BITMAP *bmp, int x, int y, int color); void (*polygon3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D { int x; int u; int c; } *vtx[]); void (*polygon3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, int vc, struct V3D_f { float x; float u; int c; } *vtx[]); void (*triangle3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3); void (*triangle3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3); void (*quad3d)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D *v1, struct V3D *v2, struct V3D *v3, struct V3D *v4); void (*quad3d_f)(struct BITMAP *bmp, int type, struct BITMAP *texture, struct V3D_f *v1, struct V3D_f *v2, struct V3D_f *v3, struct V3D_f *v4); void (*draw_sprite_ex)(struct BITMAP *bmp, struct BITMAP *sprite, int x, int y, int mode, int flip); } *vtable; void *write_bank; void *read_bank; void *dat; unsigned long id; void *extra; int x_ofs; int y_ofs; int seg; unsigned char *line[]; } *


printmsg

repo: missManyKanistra/coreutils

decompiled_code:
int __fastcall printmsg(char *a1)
{
int v1; // ebp
int v2; // ebp
size_t i; // rbx
int result; // eax

v1 = -1;
if ( _bss_start )
v1 = _bss_start->_maxy + 1;
v2 = v1 - 1;
wmove(_bss_start, v2, 0);
for ( i = 0LL; strlen(curmsg) > i; ++i )
{
printw(" ");
wmove(_bss_start, v2, i);
}
wmove(_bss_start, v2, 0);
printw(a1);
result = wmove(_bss_start, 0, 0);
curmsg = a1;
return result;
}

canonical_decompiled_code:
int __fastcall func7(char *a1)
{
int v1; // ebp
int v2; // ebp
size_t i; // rbx
int result; // eax

v1 = -1;
if ( _bss_start )
v1 = _bss_start->_maxy + 1;
v2 = v1 - 1;
wmove(_bss_start, v2, 0);
for ( i = 0LL; strlen(curmsg) > i; ++i )
{
printw(" ");
wmove(_bss_start, v2, i);
}
wmove(_bss_start, v2, 0);
printw(a1);
result = wmove(_bss_start, 0, 0);
curmsg = a1;
return result;
}

original_code:
void printmsg(char *msg) {
  int x, y;
  (y = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), x = ((0 != (const void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  wmove(stdscr,(y - 1),(0));
  for (int i = 0; i < strlen(curmsg); i++) {
    printw(" ");
    wmove(stdscr,(y - 1),(i));
  }
  wmove(stdscr,(y - 1),(0));
  printw(msg);
  wmove(stdscr,(0),(0));
  curmsg = msg;
}

canonical_original_code:
void printmsg(char *msg) {
  int x; int y;
  (y = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxy + 1) : (-1)), x = ((0 != (void *)((stdscr))) ? ((stdscr)->_maxx + 1) : (-1)));
  wmove(stdscr,(y - 1),(0));
  for (int i = 0; i < strlen(curmsg); i++) {
    printw(" ");
    wmove(stdscr,(y - 1),(i));
  }
  wmove(stdscr,(y - 1),(0));
  printw(msg);
  wmove(stdscr,(0),(0));
  curmsg = msg;
}

variable_types:
msg
char *

variable_types: i int


repo: missimer/ttftp-server

decompiled_code:
__int64 __fastcall get_tftp_mode(__int64 a1, const char *a2)
{
int v2; // edx
__int64 result; // rax

if ( !strcasecmp(a2, "octet") )
{
*(_DWORD *)(a1 + 20) = 1;
result = 1LL;
}
else if ( !strcasecmp(a2, "netascii") )
{
*(_DWORD *)(a1 + 20) = 0;
result = 1LL;
}
else
{
v2 = strcasecmp(a2, "mail");
result = 0LL;
if ( !v2 )
{
*(_DWORD *)(a1 + 20) = 2;
result = 1LL;
}
}
return result;
}

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

if ( !strcasecmp(a2, "octet") )
{
*(_DWORD *)(a1 + 20) = 1;
result = 1LL;
}
else if ( !strcasecmp(a2, "netascii") )
{
*(_DWORD *)(a1 + 20) = 0;
result = 1LL;
}
else
{
v2 = strcasecmp(a2, "mail");
result = 0LL;
if ( !v2 )
{
*(_DWORD *)(a1 + 20) = 2;
result = 1LL;
}
}
return result;
}

original_code:
static BOOL get_tftp_mode(tftp_packet_t* packet, char* mode_string)
{
  if(strcasecmp(mode_string, "octet") == 0) {
    packet->mode = TFTP_MODE_OCTET;
    return TRUE;
  }
  if(strcasecmp(mode_string, "netascii" ) == 0) {
    packet->mode = TFTP_MODE_NETASCII;
    return TRUE;
  }
  if(strcasecmp(mode_string, "mail") == 0) {
    packet->mode = TFTP_MODE_MAIL;
    return TRUE;
  }
  return FALSE;
}

canonical_original_code:
static enum BOOL get_tftp_mode(struct tftp_packet_t *packet, char *mode_string)
{
  if(strcasecmp(mode_string, "octet") == 0) {
    packet->mode = TFTP_MODE_OCTET;
    return TRUE;
  }
  if(strcasecmp(mode_string, "netascii" ) == 0) {
    packet->mode = TFTP_MODE_NETASCII;
    return TRUE;
  }
  if(strcasecmp(mode_string, "mail") == 0) {
    packet->mode = TFTP_MODE_MAIL;
    return TRUE;
  }
  return FALSE;
}

variable_types: struct tftp_packet_t { unsigned short opcode; unsigned short ack_num; char *filename; unsigned int block_size; enum tftp_mode_t { TFTP_MODE_NETASCII=0, TFTP_MODE_OCTET=1, TFTP_MODE_MAIL=2 } mode; unsigned int option_bitmap; } *

return_type: enum BOOL { FALSE=0, TRUE=1 }

user_defined_types: struct tftp_packet_t { unsigned short opcode; unsigned short ack_num; char *filename; unsigned int block_size; enum tftp_mode_t mode; unsigned int option_bitmap; }


decompiled_code:
__int64 __fastcall process_option(__int64 a1, const char *a2, const char *a3)
{
int v4; // edx
__int64 result; // rax

v4 = strcasecmp(a2, "blksize");
result = 0LL;
if ( !v4 )
{
*(_DWORD *)(a1 + 16) = atoi(a3);
*(_DWORD *)(a1 + 24) |= 1u;
result = 1LL;
}
return result;
}

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

v4 = strcasecmp(a2, "blksize");
result = 0LL;
if ( !v4 )
{
*(_DWORD *)(a1 + 16) = atoi(a3);
*(_DWORD *)(a1 + 24) |= 1u;
result = 1LL;
}
return result;
}

original_code:
static BOOL process_option(tftp_packet_t* packet, char* opt, char* opt_val)
{
  if(strcasecmp(opt, "blksize") == 0) {
    packet->block_size = atoi(opt_val);
    packet->option_bitmap |= (1 << 0);
    return TRUE;
  }
  return FALSE;
}

canonical_original_code:
static enum BOOL process_option(struct tftp_packet_t *packet, char *opt, char *opt_val)
{
  if(strcasecmp(opt, "blksize") == 0) {
    packet->block_size = atoi(opt_val);
    packet->option_bitmap |= (1 << 0);
    return TRUE;
  }
  return FALSE;
}

variable_types:
opt
char *

user_defined_types: enum tftp_mode_t { TFTP_MODE_NETASCII=0, TFTP_MODE_OCTET=1, TFTP_MODE_MAIL=2 }


original_code:
static BOOL parse_recvd_packet(tftp_packet_t* packet, u8* msg, size_t length)
{
  char* opt;
  char* opt_val;
  int opt_len;
  int opt_val_len;
  packet->opcode = ntohs(*(short*)msg);
  msg += 2;
  length -= 2;
  switch(packet->opcode) {
  case TFTP_OP_RRQ:
  case TFTP_OP_WRQ:
    if(!(packet->filename = (char*)get_next_value(msg, length))) return FALSE;
    opt_len = strlen(packet->filename);
    msg += (opt_len+1);
    length -= (opt_len+1);
    if(!(opt = (char*)get_next_value(msg, length))) return FALSE;
    opt_len = strlen(opt);
    msg += (opt_len+1);
    length -= (opt_len+1);
    if(!get_tftp_mode(packet, opt)) return FALSE;
    packet->option_bitmap = 0;
    while(length > 2) {
      if(!(opt = (char*)get_next_value(msg, length))) return FALSE;
      opt_len = strlen(opt);
      msg += (opt_len+1);
      length -= (opt_len+1);
      if(!(opt_val = (char*)get_next_value(msg, length))) return FALSE;
      opt_val_len = strlen(opt_val);
      msg += (opt_val_len+1);
      length -= (opt_val_len+1);
      if(!process_option(packet, opt, opt_val)) break;
    }
    return TRUE;
  case TFTP_OP_DATA:
    return FALSE;
  case TFTP_OP_ACK:
    packet->ack_num = ntohs(*(short*)msg);
    return TRUE;
  case TFTP_OP_ERR:
    return TRUE;
  case TFTP_OP_OACK:
    return FALSE;
  }
  return FALSE;
}

canonical_original_code:
static enum BOOL parse_recvd_packet(struct tftp_packet_t *packet, unsigned char *msg, unsigned long length)
{
  char *opt;
  char *opt_val;
  int opt_len;
  int opt_val_len;
  packet->opcode = ntohs(*(short *)msg);
  msg += 2;
  length -= 2;
  switch(packet->opcode) {
  case TFTP_OP_RRQ:
  case TFTP_OP_WRQ:
    if(!(packet->filename = (char *)get_next_value(msg, length))) return FALSE;
    opt_len = strlen(packet->filename);
    msg += (opt_len+1);
    length -= (opt_len+1);
    if(!(opt = (char *)get_next_value(msg, length))) return FALSE;
    opt_len = strlen(opt);
    msg += (opt_len+1);
    length -= (opt_len+1);
    if(!get_tftp_mode(packet, opt)) return FALSE;
    packet->option_bitmap = 0;
    while(length > 2) {
      if(!(opt = (char *)get_next_value(msg, length))) return FALSE;
      opt_len = strlen(opt);
      msg += (opt_len+1);
      length -= (opt_len+1);
      if(!(opt_val = (char *)get_next_value(msg, length))) return FALSE;
      opt_val_len = strlen(opt_val);
      msg += (opt_val_len+1);
      length -= (opt_val_len+1);
      if(!process_option(packet, opt, opt_val)) break;
    }
    return TRUE;
  case TFTP_OP_DATA:
    return FALSE;
  case TFTP_OP_ACK:
    packet->ack_num = ntohs(*(short *)msg);
    return TRUE;
  case TFTP_OP_ERR:
    return TRUE;
  case TFTP_OP_OACK:
    return FALSE;
  }
  return FALSE;
}

variable_types:
msg
unsigned char *

variable_types:
length
unsigned long


decompiled_code:
__int64 __fastcall process_program_args(int argc, char **argv, __int64 a3)
{
int v4; // eax
char *v6; // rax
char *v7; // rbx
size_t v8; // rax
char *v9; // r14
size_t v10; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

while ( 1 )
{
while ( 1 )
{
v4 = getopt(argc, argv, "p:r:");
if ( v4 == -1 )
return 1LL;
if ( v4 != 112 )
break;
*(_DWORD *)a3 = strtol(optarg, &endptr, 10);
if ( *endptr )
return 0LL;
}
if ( v4 != 114 )
return 0LL;
v6 = strdup(optarg);
v7 = v6;
*(_QWORD *)(a3 + 16) = v6;
if ( !v6 )
break;
if ( v6[strlen(v6) - 1] != 47 )
{
v8 = strlen(v7 + 2);
v9 = (char *)malloc(v8);
if ( !v9 )
{
free(v7);
return 0LL;
}
v10 = strlen(v7);
memcpy(v9, v7, v10 + 1);
*(_WORD *)&v9[strlen(v9)] = 47;
free(v7);
*(_QWORD *)(a3 + 16) = v9;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int argc, char **argv, __int64 a3)
{
int v4; // eax
char *v6; // rax
char *v7; // rbx
size_t v8; // rax
char *v9; // r14
size_t v10; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

while ( 1 )
{
while ( 1 )
{
v4 = getopt(argc, argv, "p:r:");
if ( v4 == -1 )
return 1LL;
if ( v4 != 112 )
break;
*(_DWORD *)a3 = strtol(optarg, &endptr, 10);
if ( *endptr )
return 0LL;
}
if ( v4 != 114 )
return 0LL;
v6 = strdup(optarg);
v7 = v6;
*(_QWORD *)(a3 + 16) = v6;
if ( !v6 )
break;
if ( v6[strlen(v6) - 1] != 47 )
{
v8 = strlen(v7 + 2);
v9 = (char *)malloc(v8);
if ( !v9 )
{
free(v7);
return 0LL;
}
v10 = strlen(v7);
memcpy(v9, v7, v10 + 1);
*(_WORD *)&v9[strlen(v9)] = 47;
free(v7);
*(_QWORD *)(a3 + 16) = v9;
}
}
return 0LL;
}

original_code:
BOOL process_program_args(int argc, char* argv[], ttftps_params_t* params)
{
  char* endptr;
  int opt;
  while ((opt = getopt(argc, argv, "p:r:")) != -1) {
    switch(opt) {
    case 'p':
      params->server_port = strtol(optarg, &endptr, 10);
      if(*endptr != '\0') return FALSE;
      break;
    case 'r':
      params->path_root = strdup(optarg);
      if(!params->path_root) return FALSE;
      if(params->path_root[strlen(params->path_root)-1] != '/') {
        char* temp = malloc(strlen(params->path_root + 2));
        if(!temp) {
          free(params->path_root);
          return FALSE;
        }
        memcpy(temp, params->path_root, strlen(params->path_root)+1);
        strcat(temp, "/");
        free(params->path_root);
        params->path_root = temp;
      }
      break;
    default:
      return FALSE;
    }
  }
  return TRUE;
}

canonical_original_code:
enum BOOL process_program_args(int argc, char *argv[], struct ttftps_params_t *params)
{
  char *endptr;
  int opt;
  while ((opt = getopt(argc, argv, "p:r:")) != -1) {
    switch(opt) {
    case 'p':
      params->server_port = strtol(optarg, &endptr, 10);
      if(*endptr != '\0') return FALSE;
      break;
    case 'r':
      params->path_root = strdup(optarg);
      if(!params->path_root) return FALSE;
      if(params->path_root[strlen(params->path_root)-1] != '/') {
        char *temp = malloc(strlen(params->path_root + 2));
        if(!temp) {
          free(params->path_root);
          return FALSE;
        }
        memcpy(temp, params->path_root, strlen(params->path_root)+1);
        strcat(temp, "/");
        free(params->path_root);
        params->path_root = temp;
      }
      break;
    default:
      return FALSE;
    }
  }
  return TRUE;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct ttftps_params_t { unsigned int server_port; unsigned int client_port; char *interface; char *path_root; } *

variable_types:
endptr
char *

variable_types: opt int

variable_types:
temp
char *


decompiled_code:
size_t print_usage()
{
return fwrite("usage: ttftps [-p port_num] [-r path_root]\n", 1uLL, 0x2BuLL, stderr);
}

canonical_decompiled_code:
size_t func13()
{
return fwrite("usage: ttftps [-p port_num] [-r path_root]\n", 1uLL, 0x2BuLL, stderr);
}

original_code:
void print_usage()
{
  fprintf(stderr, "usage: ttftps [-p port_num] [-r path_root]\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

v4[0] = 69;
v4[1] = 8080;
v5 = 0LL;
v6 = 0LL;
if ( (unsigned int)process_program_args(argc, (char **)argv, (__int64)v4) )
return start_server((__int64)v4);
print_usage();
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v4[2]; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

v4[0] = 69;
v4[1] = 8080;
v5 = 0LL;
v6 = 0LL;
if ( (unsigned int)func12(argc, (char **)argv, (__int64)v4) )
return func11((__int64)v4);
func13();
return 1;
}

original_code:
int main(int argc, char* argv[])
{
  ttftps_params_t params = { .server_port = 69, .client_port = 8080, .interface = ((void *)0), .path_root = ((void *)0), };
  if(!process_program_args(argc, argv, &params)) {
    print_usage();
    return 1;
  }
  return start_server(&params);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  struct ttftps_params_t params = { .server_port = 69, .client_port = 8080, .interface = ((void *)0), .path_root = ((void *)0), };
  if(!process_program_args(argc, argv, &params)) {
    print_usage();
    return 1;
  }
  return start_server(&params);
}

variable_types: struct ttftps_params_t { unsigned int server_port; unsigned int client_port; char *interface; char *path_root; }


repo: mistotebe/skeeter

decompiled_code:
__int64 __fastcall avl_inapply(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int a4)
{
int v6; // edx
__int64 result; // rax
int v8; // edx
__int64 v9; // rdi

if ( !a1 )
return 4294967290LL;
if ( !a1[1] || (v6 = ((__int64 (*)(void))avl_inapply)(), result = a4, v6 != a4) )
{
v8 = a2(*a1, a3);
result = a4;
if ( v8 != a4 )
{
v9 = a1[2];
if ( v9 )
result = avl_inapply(v9, a2, a3, a4);
else
result = 4294967290LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int a4)
{
int v6; // edx
__int64 result; // rax
int v8; // edx
__int64 v9; // rdi

if ( !a1 )
return 4294967290LL;
if ( !a1[1] || (v6 = ((__int64 (*)(void))avl_inapply)(), result = a4, v6 != a4) )
{
v8 = a2(*a1, a3);
result = a4;
if ( v8 != a4 )
{
v9 = a1[2];
if ( v9 )
result = func0(v9, a2, a3, a4);
else
result = 4294967290LL;
}
}
return result;
}

original_code:
static int
avl_inapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
{
 if ( root == 0 )
  return( (-6) );
 if ( root->avl_link[0] != 0 )
  if ( avl_inapply( root->avl_link[0], fn, arg, stopflag )
      == stopflag )
   return( stopflag );
 if ( (*fn)( root->avl_data, arg ) == stopflag )
  return( stopflag );
 if ( root->avl_link[1] == 0 )
  return( (-6) );
 else
  return( avl_inapply( root->avl_link[1], fn, arg, stopflag ) );
}

canonical_original_code:
static int avl_inapply(struct avlnode *root, int (*fn)(void *, void *), void *arg, int stopflag)
{
 if ( root == 0 )
  return( (-6) );
 if ( root->avl_link[0] != 0 )
  if ( avl_inapply( root->avl_link[0], fn, arg, stopflag )
      == stopflag )
   return( stopflag );
 if ( (*fn)( root->avl_data, arg ) == stopflag )
  return( stopflag );
 if ( root->avl_link[1] == 0 )
  return( (-6) );
 else
  return( avl_inapply( root->avl_link[1], fn, arg, stopflag ) );
}

variable_types: struct avlnode { void *avl_data; struct avlnode *avl_link[2]; char avl_bits[2]; char avl_bf; } *

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

variable_types:
arg
void *

variable_types: stopflag int


decompiled_code:
__int64 __fastcall avl_postapply(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int a4)
{
int v7; // edx
__int64 result; // rax
__int64 v9; // rdi
int v10; // edx

if ( !a1 )
return 4294967290LL;
if ( !a1[1] || (v7 = ((__int64 (*)(void))avl_postapply)(), result = a4, v7 != a4) )
{
v9 = a1[2];
if ( !v9 || (v10 = avl_postapply(v9, a2, a3, a4), result = a4, v10 != a4) )
result = a2(*a1, a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int a4)
{
int v7; // edx
__int64 result; // rax
__int64 v9; // rdi
int v10; // edx

if ( !a1 )
return 4294967290LL;
if ( !a1[1] || (v7 = ((__int64 (*)(void))avl_postapply)(), result = a4, v7 != a4) )
{
v9 = a1[2];
if ( !v9 || (v10 = func1(v9, a2, a3, a4), result = a4, v10 != a4) )
result = a2(*a1, a3);
}
return result;
}

original_code:
static int
avl_postapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
{
 if ( root == 0 )
  return( (-6) );
 if ( root->avl_link[0] != 0 )
  if ( avl_postapply( root->avl_link[0], fn, arg, stopflag )
      == stopflag )
   return( stopflag );
 if ( root->avl_link[1] != 0 )
  if ( avl_postapply( root->avl_link[1], fn, arg, stopflag )
      == stopflag )
   return( stopflag );
 return( (*fn)( root->avl_data, arg ) );
}

canonical_original_code:
static int avl_postapply(struct avlnode *root, int (*fn)(void *, void *), void *arg, int stopflag)
{
 if ( root == 0 )
  return( (-6) );
 if ( root->avl_link[0] != 0 )
  if ( avl_postapply( root->avl_link[0], fn, arg, stopflag )
      == stopflag )
   return( stopflag );
 if ( root->avl_link[1] != 0 )
  if ( avl_postapply( root->avl_link[1], fn, arg, stopflag )
      == stopflag )
   return( stopflag );
 return( (*fn)( root->avl_data, arg ) );
}

user_defined_types: struct avlnode { void *avl_data; struct avlnode *avl_link[2]; char avl_bits[2]; char avl_bf; }


decompiled_code:
__int64 __fastcall avl_preapply(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int a4)
{
int v7; // edx
__int64 result; // rax
__int64 v9; // rdi
int v10; // edx
__int64 v11; // rdi

if ( !a1 )
return 4294967290LL;
v7 = a2(*a1, a3);
result = a4;
if ( v7 != a4 )
{
v9 = a1[1];
if ( !v9 || (v10 = avl_preapply(v9, a2, a3, a4), result = a4, v10 != a4) )
{
v11 = a1[2];
if ( v11 )
result = avl_preapply(v11, a2, a3, a4);
else
result = 4294967290LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int a4)
{
int v7; // edx
__int64 result; // rax
__int64 v9; // rdi
int v10; // edx
__int64 v11; // rdi

if ( !a1 )
return 4294967290LL;
v7 = a2(*a1, a3);
result = a4;
if ( v7 != a4 )
{
v9 = a1[1];
if ( !v9 || (v10 = func2(v9, a2, a3, a4), result = a4, v10 != a4) )
{
v11 = a1[2];
if ( v11 )
result = func2(v11, a2, a3, a4);
else
result = 4294967290LL;
}
}
return result;
}

original_code:
static int
avl_preapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
{
 if ( root == 0 )
  return( (-6) );
 if ( (*fn)( root->avl_data, arg ) == stopflag )
  return( stopflag );
 if ( root->avl_link[0] != 0 )
  if ( avl_preapply( root->avl_link[0], fn, arg, stopflag )
      == stopflag )
   return( stopflag );
 if ( root->avl_link[1] == 0 )
  return( (-6) );
 else
  return( avl_preapply( root->avl_link[1], fn, arg, stopflag ) );
}

canonical_original_code:
static int avl_preapply(struct avlnode *root, int (*fn)(void *, void *), void *arg, int stopflag)
{
 if ( root == 0 )
  return( (-6) );
 if ( (*fn)( root->avl_data, arg ) == stopflag )
  return( stopflag );
 if ( root->avl_link[0] != 0 )
  if ( avl_preapply( root->avl_link[0], fn, arg, stopflag )
      == stopflag )
   return( stopflag );
 if ( root->avl_link[1] == 0 )
  return( (-6) );
 else
  return( avl_preapply( root->avl_link[1], fn, arg, stopflag ) );
}


decompiled_code:
__int64 __fastcall avl_buildlist(__int64 a1)
{
int v1; // eax
int v2; // eax

if ( avl_list )
{
v1 = slots_0;
if ( avl_maxlist == slots_0 )
{
slots_0 += 100;
avl_list = ber_memrealloc(avl_list, 8LL * (unsigned int)(v1 + 100));
}
}
else
{
avl_list = ber_memalloc(800LL);
slots_0 = 100;
avl_maxlist = 0;
}
v2 = avl_maxlist++;
*(_QWORD *)(avl_list + 8LL * v2) = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
int v2; // eax

if ( avl_list )
{
v1 = slots_0;
if ( avl_maxlist == slots_0 )
{
slots_0 += 100;
avl_list = ber_memrealloc(avl_list, 8LL * (unsigned int)(v1 + 100));
}
}
else
{
avl_list = ber_memalloc(800LL);
slots_0 = 100;
avl_maxlist = 0;
}
v2 = avl_maxlist++;
*(_QWORD *)(avl_list + 8LL * v2) = a1;
return 0LL;
}

original_code:
static int
avl_buildlist( void* data, void* arg )
{
 static int slots;
 if ( avl_list == (void* *) 0 ) {
  avl_list = (void* *) ber_memalloc(100 * sizeof(void*));
  slots = 100;
  avl_maxlist = 0;
 } else if ( avl_maxlist == slots ) {
  slots += 100;
  avl_list = (void* *) ber_memrealloc( (char *) avl_list,
      (unsigned) slots * sizeof(void*));
 }
 avl_list[ avl_maxlist++ ] = data;
 return( 0 );
}

canonical_original_code:
static int avl_buildlist(void *data, void *arg)
{
 static int slots;
 if ( avl_list == (void **) 0 ) {
  avl_list = (void **) ber_memalloc(100 * sizeof(void *));
  slots = 100;
  avl_maxlist = 0;
 } else if ( avl_maxlist == slots ) {
  slots += 100;
  avl_list = (void **) ber_memrealloc( (char *) avl_list,
      (unsigned int) slots * sizeof(void *));
 }
 avl_list[ avl_maxlist++ ] = data;
 return( 0 );
}

variable_types:
data
void *

variable_types: slots int


original_code:
int
avl_insert( Avlnode ** root, void *data, AVL_CMP fcmp, AVL_DUP fdup )
{
    Avlnode *t, *p, *s, *q, *r;
    int a, cmp, ncmp;
 if ( *root == ((void *)0) ) {
  if (( r = (Avlnode *) ber_memalloc( sizeof( Avlnode ))) == ((void *)0) ) {
   return( -1 );
  }
  r->avl_link[0] = r->avl_link[1] = ((void *)0);
  r->avl_data = data;
  r->avl_bf = 0;
  *root = r;
  return( 0 );
 }
    t = ((void *)0);
    s = p = *root;
    while (1) {
  cmp = fcmp( data, p->avl_data );
  if ( cmp == 0 )
   return (*fdup)( p->avl_data, data );
  cmp = (cmp > 0);
  q = p->avl_link[cmp];
  if (q == ((void *)0)) {
   if (( q = (Avlnode *) ber_memalloc( sizeof( Avlnode ))) == ((void *)0) ) {
    return( -1 );
   }
   q->avl_link[0] = q->avl_link[1] = ((void *)0);
   q->avl_data = data;
   q->avl_bf = 0;
   p->avl_link[cmp] = q;
   break;
  } else if ( q->avl_bf ) {
   t = p;
   s = q;
  }
  p = q;
    }
    cmp = fcmp( data, s->avl_data ) > 0;
 r = p = s->avl_link[cmp];
 a = avl_bfs[cmp];
 while ( p != q ) {
  cmp = fcmp( data, p->avl_data ) > 0;
  p->avl_bf = avl_bfs[cmp];
  p = p->avl_link[cmp];
 }
 if ( s->avl_bf == 0 ) {
  s->avl_bf = a;
  return 0;
 } else if ( s->avl_bf == -a ) {
  s->avl_bf = 0;
  return 0;
    } else if ( s->avl_bf == a ) {
  cmp = (a > 0);
  ncmp = !cmp;
  if ( r->avl_bf == a ) {
   p = r;
   s->avl_link[cmp] = r->avl_link[ncmp];
   r->avl_link[ncmp] = s;
   s->avl_bf = 0;
   r->avl_bf = 0;
  } else if ( r->avl_bf == -a ) {
   p = r->avl_link[ncmp];
   r->avl_link[ncmp] = p->avl_link[cmp];
   p->avl_link[cmp] = r;
   s->avl_link[cmp] = p->avl_link[ncmp];
   p->avl_link[ncmp] = s;
   if ( p->avl_bf == a ) {
    s->avl_bf = -a;
    r->avl_bf = 0;
   } else if ( p->avl_bf == -a ) {
    s->avl_bf = 0;
    r->avl_bf = a;
   } else {
    s->avl_bf = 0;
    r->avl_bf = 0;
   }
   p->avl_bf = 0;
  }
  if ( t == ((void *)0) )
   *root = p;
  else if ( s == t->avl_link[1] )
   t->avl_link[1] = p;
  else
   t->avl_link[0] = p;
    }
  return 0;
}

canonical_original_code:
int avl_insert(struct avlnode **root, void *data, int (*fcmp)(void *, void *), int (*fdup)(void *, void *))
{
    struct avlnode *t; struct avlnode *p; struct avlnode *s; struct avlnode *q; struct avlnode *r;
    int a; int cmp; int ncmp;
 if ( *root == ((void *)0) ) {
  if (( r = (struct avlnode *) ber_memalloc( sizeof( Avlnode ))) == ((void *)0) ) {
   return( -1 );
  }
  r->avl_link[0] = r->avl_link[1] = ((void *)0);
  r->avl_data = data;
  r->avl_bf = 0;
  *root = r;
  return( 0 );
 }
    t = ((void *)0);
    s = p = *root;
    while (1) {
  cmp = fcmp( data, p->avl_data );
  if ( cmp == 0 )
   return (*fdup)( p->avl_data, data );
  cmp = (cmp > 0);
  q = p->avl_link[cmp];
  if (q == ((void *)0)) {
   if (( q = (struct avlnode *) ber_memalloc( sizeof( Avlnode ))) == ((void *)0) ) {
    return( -1 );
   }
   q->avl_link[0] = q->avl_link[1] = ((void *)0);
   q->avl_data = data;
   q->avl_bf = 0;
   p->avl_link[cmp] = q;
   break;
  } else if ( q->avl_bf ) {
   t = p;
   s = q;
  }
  p = q;
    }
    cmp = fcmp( data, s->avl_data ) > 0;
 r = p = s->avl_link[cmp];
 a = avl_bfs[cmp];
 while ( p != q ) {
  cmp = fcmp( data, p->avl_data ) > 0;
  p->avl_bf = avl_bfs[cmp];
  p = p->avl_link[cmp];
 }
 if ( s->avl_bf == 0 ) {
  s->avl_bf = a;
  return 0;
 } else if ( s->avl_bf == -a ) {
  s->avl_bf = 0;
  return 0;
    } else if ( s->avl_bf == a ) {
  cmp = (a > 0);
  ncmp = !cmp;
  if ( r->avl_bf == a ) {
   p = r;
   s->avl_link[cmp] = r->avl_link[ncmp];
   r->avl_link[ncmp] = s;
   s->avl_bf = 0;
   r->avl_bf = 0;
  } else if ( r->avl_bf == -a ) {
   p = r->avl_link[ncmp];
   r->avl_link[ncmp] = p->avl_link[cmp];
   p->avl_link[cmp] = r;
   s->avl_link[cmp] = p->avl_link[ncmp];
   p->avl_link[ncmp] = s;
   if ( p->avl_bf == a ) {
    s->avl_bf = -a;
    r->avl_bf = 0;
   } else if ( p->avl_bf == -a ) {
    s->avl_bf = 0;
    r->avl_bf = a;
   } else {
    s->avl_bf = 0;
    r->avl_bf = 0;
   }
   p->avl_bf = 0;
  }
  if ( t == ((void *)0) )
   *root = p;
  else if ( s == t->avl_link[1] )
   t->avl_link[1] = p;
  else
   t->avl_link[0] = p;
    }
  return 0;
}

variable_types: struct avlnode { void *avl_data; struct avlnode *avl_link[2]; char avl_bits[2]; char avl_bf; } **

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

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

variable_types: a int

variable_types: cmp int

variable_types: ncmp int


original_code:
void*
avl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
{
 Avlnode *p, *q, *r, *top;
 int side, side_bf, shorter, nside;
 Avlnode *pptr[(sizeof(void *) * 8)];
 unsigned char pdir[(sizeof(void *) * 8)];
 int depth = 0;
 if ( *root == ((void *)0) )
  return ((void *)0);
 p = *root;
 while (1) {
  side = fcmp( data, p->avl_data );
  if ( !side )
   break;
  side = ( side > 0 );
  pdir[depth] = side;
  pptr[depth++] = p;
  p = p->avl_link[side];
  if ( p == ((void *)0) )
   return p;
 }
   data = p->avl_data;
 if ( p->avl_link[0] && p->avl_link[1] ) {
  q = p->avl_link[0];
  side = depth;
  pdir[depth++] = 0;
  while (q->avl_link[1]) {
   pdir[depth] = 1;
   pptr[depth++] = q;
   q = q->avl_link[1];
  }
  r = p->avl_link[0];
  p->avl_link[0] = q->avl_link[0];
  q->avl_link[0] = r;
  q->avl_link[1] = p->avl_link[1];
  p->avl_link[1] = ((void *)0);
  q->avl_bf = p->avl_bf;
  pptr[side] = q;
  if ( side ) {
   r = pptr[side-1];
   r->avl_link[pdir[side-1]] = q;
  } else {
   *root = q;
  }
  if ( depth-side > 1 ) {
   r = pptr[depth-1];
   r->avl_link[1] = p;
  } else {
   q->avl_link[0] = p;
  }
 }
 q = p->avl_link[0] ? p->avl_link[0] : p->avl_link[1];
 ber_memfree( p );
 if ( !depth ) {
  *root = q;
  return data;
 }
 depth--;
 p = pptr[depth];
 side = pdir[depth];
 p->avl_link[side] = q;
 top = ((void *)0);
 shorter = 1;
 while ( shorter ) {
  p = pptr[depth];
  side = pdir[depth];
  nside = !side;
  side_bf = avl_bfs[side];
  if ( p->avl_bf == 0 ) {
   p->avl_bf = avl_bfs[nside];
   shorter = 0;
  } else if ( p->avl_bf == side_bf ) {
   p->avl_bf = 0;
  } else {
   if ( depth )
    top = pptr[depth-1];
   else
    top = ((void *)0);
   q = p->avl_link[nside];
   if ( q->avl_bf == 0 ) {
    p->avl_link[nside] = q->avl_link[side];
    q->avl_link[side] = p;
    shorter = 0;
    q->avl_bf = side_bf;
    p->avl_bf = (- side_bf);
   } else if ( q->avl_bf == p->avl_bf ) {
    p->avl_link[nside] = q->avl_link[side];
    q->avl_link[side] = p;
    shorter = 1;
    q->avl_bf = 0;
    p->avl_bf = 0;
   } else {
    r = q->avl_link[side];
    q->avl_link[side] = r->avl_link[nside];
    r->avl_link[nside] = q;
    p->avl_link[nside] = r->avl_link[side];
    r->avl_link[side] = p;
    if ( r->avl_bf == side_bf ) {
     q->avl_bf = (- side_bf);
     p->avl_bf = 0;
    } else if ( r->avl_bf == (- side_bf)) {
     q->avl_bf = 0;
     p->avl_bf = side_bf;
    } else {
     q->avl_bf = 0;
     p->avl_bf = 0;
    }
    r->avl_bf = 0;
    q = r;
   }
   if ( top == ((void *)0) ) {
    *root = q;
   } else if (top->avl_link[0] == p) {
    top->avl_link[0] = q;
   } else {
    top->avl_link[1] = q;
   }
   p = q;
  }
  if ( !depth )
   break;
  depth--;
 }
 return data;
}

canonical_original_code:
void *avl_delete(struct avlnode **root, void *data, int (*fcmp)(void *, void *))
{
 struct avlnode *p; struct avlnode *q; struct avlnode *r; struct avlnode *top;
 int side; int side_bf; int shorter; int nside;
 struct avlnode *pptr[-1];
 unsigned char pdir[-1];
 int depth = 0;
 if ( *root == ((void *)0) )
  return ((void *)0);
 p = *root;
 while (1) {
  side = fcmp( data, p->avl_data );
  if ( !side )
   break;
  side = ( side > 0 );
  pdir[depth] = side;
  pptr[depth++] = p;
  p = p->avl_link[side];
  if ( p == ((void *)0) )
   return p;
 }
   data = p->avl_data;
 if ( p->avl_link[0] && p->avl_link[1] ) {
  q = p->avl_link[0];
  side = depth;
  pdir[depth++] = 0;
  while (q->avl_link[1]) {
   pdir[depth] = 1;
   pptr[depth++] = q;
   q = q->avl_link[1];
  }
  r = p->avl_link[0];
  p->avl_link[0] = q->avl_link[0];
  q->avl_link[0] = r;
  q->avl_link[1] = p->avl_link[1];
  p->avl_link[1] = ((void *)0);
  q->avl_bf = p->avl_bf;
  pptr[side] = q;
  if ( side ) {
   r = pptr[side-1];
   r->avl_link[pdir[side-1]] = q;
  } else {
   *root = q;
  }
  if ( depth-side > 1 ) {
   r = pptr[depth-1];
   r->avl_link[1] = p;
  } else {
   q->avl_link[0] = p;
  }
 }
 q = p->avl_link[0] ? p->avl_link[0] : p->avl_link[1];
 ber_memfree( p );
 if ( !depth ) {
  *root = q;
  return data;
 }
 depth--;
 p = pptr[depth];
 side = pdir[depth];
 p->avl_link[side] = q;
 top = ((void *)0);
 shorter = 1;
 while ( shorter ) {
  p = pptr[depth];
  side = pdir[depth];
  nside = !side;
  side_bf = avl_bfs[side];
  if ( p->avl_bf == 0 ) {
   p->avl_bf = avl_bfs[nside];
   shorter = 0;
  } else if ( p->avl_bf == side_bf ) {
   p->avl_bf = 0;
  } else {
   if ( depth )
    top = pptr[depth-1];
   else
    top = ((void *)0);
   q = p->avl_link[nside];
   if ( q->avl_bf == 0 ) {
    p->avl_link[nside] = q->avl_link[side];
    q->avl_link[side] = p;
    shorter = 0;
    q->avl_bf = side_bf;
    p->avl_bf = (- side_bf);
   } else if ( q->avl_bf == p->avl_bf ) {
    p->avl_link[nside] = q->avl_link[side];
    q->avl_link[side] = p;
    shorter = 1;
    q->avl_bf = 0;
    p->avl_bf = 0;
   } else {
    r = q->avl_link[side];
    q->avl_link[side] = r->avl_link[nside];
    r->avl_link[nside] = q;
    p->avl_link[nside] = r->avl_link[side];
    r->avl_link[side] = p;
    if ( r->avl_bf == side_bf ) {
     q->avl_bf = (- side_bf);
     p->avl_bf = 0;
    } else if ( r->avl_bf == (- side_bf)) {
     q->avl_bf = 0;
     p->avl_bf = side_bf;
    } else {
     q->avl_bf = 0;
     p->avl_bf = 0;
    }
    r->avl_bf = 0;
    q = r;
   }
   if ( top == ((void *)0) ) {
    *root = q;
   } else if (top->avl_link[0] == p) {
    top->avl_link[0] = q;
   } else {
    top->avl_link[1] = q;
   }
   p = q;
  }
  if ( !depth )
   break;
  depth--;
 }
 return data;
}

variable_types: side int

variable_types: shorter int

variable_types: nside int

variable_types: struct avlnode { void *avl_data; struct avlnode *avl_link[2]; char avl_bits[2]; char avl_bf; } *[-1]

variable_types:
pdir
unsigned char [-1]

variable_types: depth int

return_type: void *


decompiled_code:
__int64 __fastcall avl_apply(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int a4, unsigned int a5)
{
switch ( a5 )
{
case 2u:
return avl_inapply(a1, a2, a3, a4);
case 3u:
return avl_postapply(a1, a2, a3, a4);
case 1u:
return avl_preapply(a1, a2, a3, a4);
}
fprintf(stderr, "Invalid traversal type %d\n", a5);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, unsigned int a4, unsigned int a5)
{
switch ( a5 )
{
case 2u:
return func0(a1, a2, a3, a4);
case 3u:
return func1(a1, a2, a3, a4);
case 1u:
return func2(a1, a2, a3, a4);
}
fprintf(stderr, "Invalid traversal type %d\n", a5);
return 0xFFFFFFFFLL;
}

original_code:
int
avl_apply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag, int type )
{
 switch ( type ) {
 case 2:
  return( avl_inapply( root, fn, arg, stopflag ) );
 case 1:
  return( avl_preapply( root, fn, arg, stopflag ) );
 case 3:
  return( avl_postapply( root, fn, arg, stopflag ) );
 default:
  fprintf( stderr, "Invalid traversal type %d\n", type );
  return( -1 );
 }
}

canonical_original_code:
int avl_apply(struct avlnode *root, int (*fn)(void *, void *), void *arg, int stopflag, int type)
{
 switch ( type ) {
 case 2:
  return( avl_inapply( root, fn, arg, stopflag ) );
 case 1:
  return( avl_preapply( root, fn, arg, stopflag ) );
 case 3:
  return( avl_postapply( root, fn, arg, stopflag ) );
 default:
  fprintf( stderr, "Invalid traversal type %d\n", type );
  return( -1 );
 }
}

variable_types: struct avlnode { void *avl_data; struct avlnode *avl_link[2]; char avl_bits[2]; char avl_bf; } *

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

variable_types: type int