decompiled_code:
int __fastcall pic_gen_font(__int64 a1, const char *a2, int a3, __int64 a4)
{
unsigned __int8 v5; // bl
int v6; // er13
unsigned __int8 v7; // al
__int16 v8; // dx
__int16 v9; // r15
unsigned __int8 v10; // bp
unsigned __int8 v11; // bl
unsigned __int8 v12; // al
__int64 v13; // rax
int v14; // eax
unsigned __int16 v15; // r14
int v16; // er15
int v17; // eax
int v18; // ebp
int v19; // er15
__int16 v20; // bx
int v21; // er13
__int64 v22; // rsi
__int64 v23; // r8
int v24; // eax
bool v25; // zf
unsigned __int16 v28; // [rsp+10h] [rbp-2A8h]
__int16 v29; // [rsp+12h] [rbp-2A6h]
__int16 v30; // [rsp+14h] [rbp-2A4h]
unsigned __int16 v31; // [rsp+16h] [rbp-2A2h]
char v33[96]; // [rsp+20h] [rbp-298h] BYREF
char s[256]; // [rsp+80h] [rbp-238h] BYREF
char command[312]; // [rsp+180h] [rbp-138h] BYREF

pic_gen_short_desc(a1, a2);
u8g_Init(v33, &u8g_dev_pbm);
v5 = u8g_font_GetFontStartEncoding(a1);
v6 = (unsigned __int8)u8g_font_GetFontEndEncoding(a1);
u8g_FirstPage(v33);
v31 = v5 - (v5 & 0xF);
do
{
u8g_SetFont(v33, a1);
u8g_GetFontBBXWidth(v33);
u8g_GetFontBBXWidth(v33);
v7 = u8g_GetFontBBXHeight(v33);
v8 = v7;
if ( v7 <= 0xDu )
v8 = 14;
v9 = v8;
v30 = v8;
sprintf(s, "%s, %s", a2, a4);
u8g_SetFont(v33, &u8g_font_7x13);
u8g_DrawStrFontBBX(v33, 0LL, 14LL, 0LL, s);
u8g_SetFont(v33, a1);
v10 = u8g_GetFontCapitalAHeight(v33);
v11 = u8g_GetFontBBXHeight(v33);
v12 = u8g_GetFontBBXWidth(v33);
sprintf(s, "BBX Width %d, Height %d, Capital A %d", v12, v11, v10);
u8g_SetFont(v33, &u8g_font_7x13);
u8g_DrawStrFontBBX(v33, 0LL, 28LL, 0LL, s);
v13 = u8g_font_GetSize(a1);
sprintf(s, "Font data size: %d", v13);
u8g_DrawStrFontBBX(v33, 0LL, 42LL, 0LL, s);
v28 = v9 + 42;
v29 = 16;
v14 = a3;
v15 = v31;
v16 = v14;
do
{
u8g_SetFont(v33, &u8g_font_7x13);
if ( (unsigned __int16)v6 >= v15 )
{
sprintf(s, "%3d/0x%02x", v15, v15);
u8g_DrawStrFontBBX(v33, 0LL, v28, 0LL, s);
}
v17 = v16;
v18 = 75;
v19 = v6;
v20 = 16;
v21 = v17;
do
{
while ( (unsigned __int16)v19 < v15 )
{
v18 += v21;
if ( !--v20 )
goto LABEL_11;
}
u8g_SetFont(v33, a1);
v22 = (unsigned __int16)v18;
v23 = v15++;
v18 += v21;
u8g_DrawGlyphFontBBX(v33, v22, v28, 0LL, v23);
--v20;
}
while ( v20 );
LABEL_11:
v28 += v30;
v24 = v21;
v6 = v19;
v25 = v29-- == 1;
v16 = v24;
}
while ( !v25 );
a3 = v24;
}
while ( (unsigned __int8)u8g_NextPage(v33) );
u8g_SetFont(v33, a1);
sprintf(command, "convert u8g.pbm -trim %s.png", a2);
return system(command);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char *a2, int a3, __int64 a4)
{
unsigned __int8 v5; // bl
int v6; // er13
unsigned __int8 v7; // al
__int16 v8; // dx
__int16 v9; // r15
unsigned __int8 v10; // bp
unsigned __int8 v11; // bl
unsigned __int8 v12; // al
__int64 v13; // rax
int v14; // eax
unsigned __int16 v15; // r14
int v16; // er15
int v17; // eax
int v18; // ebp
int v19; // er15
__int16 v20; // bx
int v21; // er13
__int64 v22; // rsi
__int64 v23; // r8
int v24; // eax
bool v25; // zf
unsigned __int16 v28; // [rsp+10h] [rbp-2A8h]
__int16 v29; // [rsp+12h] [rbp-2A6h]
__int16 v30; // [rsp+14h] [rbp-2A4h]
unsigned __int16 v31; // [rsp+16h] [rbp-2A2h]
char v33[96]; // [rsp+20h] [rbp-298h] BYREF
char s[256]; // [rsp+80h] [rbp-238h] BYREF
char command[312]; // [rsp+180h] [rbp-138h] BYREF

func0(a1, a2);
u8g_Init(v33, &u8g_dev_pbm);
v5 = u8g_font_GetFontStartEncoding(a1);
v6 = (unsigned __int8)u8g_font_GetFontEndEncoding(a1);
u8g_FirstPage(v33);
v31 = v5 - (v5 & 0xF);
do
{
u8g_SetFont(v33, a1);
u8g_GetFontBBXWidth(v33);
u8g_GetFontBBXWidth(v33);
v7 = u8g_GetFontBBXHeight(v33);
v8 = v7;
if ( v7 <= 0xDu )
v8 = 14;
v9 = v8;
v30 = v8;
sprintf(s, "%s, %s", a2, a4);
u8g_SetFont(v33, &u8g_font_7x13);
u8g_DrawStrFontBBX(v33, 0LL, 14LL, 0LL, s);
u8g_SetFont(v33, a1);
v10 = u8g_GetFontCapitalAHeight(v33);
v11 = u8g_GetFontBBXHeight(v33);
v12 = u8g_GetFontBBXWidth(v33);
sprintf(s, "BBX Width %d, Height %d, Capital A %d", v12, v11, v10);
u8g_SetFont(v33, &u8g_font_7x13);
u8g_DrawStrFontBBX(v33, 0LL, 28LL, 0LL, s);
v13 = u8g_font_GetSize(a1);
sprintf(s, "Font data size: %d", v13);
u8g_DrawStrFontBBX(v33, 0LL, 42LL, 0LL, s);
v28 = v9 + 42;
v29 = 16;
v14 = a3;
v15 = v31;
v16 = v14;
do
{
u8g_SetFont(v33, &u8g_font_7x13);
if ( (unsigned __int16)v6 >= v15 )
{
sprintf(s, "%3d/0x%02x", v15, v15);
u8g_DrawStrFontBBX(v33, 0LL, v28, 0LL, s);
}
v17 = v16;
v18 = 75;
v19 = v6;
v20 = 16;
v21 = v17;
do
{
while ( (unsigned __int16)v19 < v15 )
{
v18 += v21;
if ( !--v20 )
goto LABEL_11;
}
u8g_SetFont(v33, a1);
v22 = (unsigned __int16)v18;
v23 = v15++;
v18 += v21;
u8g_DrawGlyphFontBBX(v33, v22, v28, 0LL, v23);
--v20;
}
while ( v20 );
LABEL_11:
v28 += v30;
v24 = v21;
v6 = v19;
v25 = v29-- == 1;
v16 = v24;
}
while ( !v25 );
a3 = v24;
}
while ( (unsigned __int8)u8g_NextPage(v33) );
u8g_SetFont(v33, a1);
sprintf(command, "convert u8g.pbm -trim %s.png", a2);
return system(command);
}

original_code:
void pic_gen_font(const u8g_pgm_uint8_t *font, const char *name, u8g_uint_t width, const char *real_name)
{
  char s[256];
  const u8g_pgm_uint8_t *disp_font;
  uint16_t i;
  u8g_uint_t x,y,w,h, hcnt, disp_line_height, disp_line_indent;
  uint8_t start, end;
  u8g_t u8g;
  pic_gen_short_desc(font, name, width, real_name);
  u8g_Init(&u8g, &u8g_dev_pbm);
  disp_font = u8g_font_7x13;
  disp_line_height = 14;
  disp_line_indent = 75;
  start = u8g_font_GetFontStartEncoding(font);
  end = u8g_font_GetFontEndEncoding(font);
  u8g_FirstPage(&u8g);
  do
  {
    u8g_SetFont(&u8g, font);
    hcnt = ((&u8g)->width);
    hcnt /= u8g_GetFontBBXWidth(&u8g);
    hcnt -= 4;
    w = u8g_GetFontBBXWidth(&u8g);
    w = width;
    h = u8g_GetFontBBXHeight(&u8g);
    if ( h < disp_line_height )
      h = disp_line_height ;
    sprintf(s, "%s, %s", name,
        real_name);
    u8g_SetFont(&u8g, disp_font);
    u8g_DrawStrFontBBX(&u8g, 0, disp_line_height, 0, s);
    u8g_SetFont(&u8g, font);
    sprintf(s, "BBX Width %d, Height %d,  Capital A %d",
        u8g_GetFontBBXWidth(&u8g),
        u8g_GetFontBBXHeight(&u8g),
        u8g_GetFontCapitalAHeight(&u8g));
    u8g_SetFont(&u8g, disp_font);
    u8g_DrawStrFontBBX(&u8g, 0, disp_line_height*2, 0, s);
    sprintf(s, "Font data size: %d", u8g_font_GetSize(font));
    u8g_DrawStrFontBBX(&u8g, 0, disp_line_height*3, 0, s);
    hcnt = 16;
    i = start - start % hcnt;
    for( y = 0; y < 16; y++ )
    {
      u8g_SetFont(&u8g, disp_font);
      if ( i <= end )
      {
        sprintf(s, "%3d/0x%02x", i, i);
        u8g_DrawStrFontBBX(&u8g, 0, y*h+disp_line_height*3+h, 0, s);
      }
      for( x = 0; x < hcnt; x++ )
      {
        if ( i <= end )
        {
          u8g_SetFont(&u8g, font);
          u8g_DrawGlyphFontBBX(&u8g, x*w+disp_line_indent, y*h+disp_line_height*3+h, 0, i);
          i++;
        }
      }
    }
  }while( u8g_NextPage(&u8g) );
  {
    char cmd[256];
    u8g_SetFont(&u8g, font);
    sprintf(cmd, "convert u8g.pbm -trim %s.png", name );
    system(cmd);
  }
}

canonical_original_code:
void pic_gen_font(unsigned char *font, char *name, unsigned short width, char *real_name)
{
  char s[256];
  unsigned char *disp_font;
  unsigned short i;
  unsigned short x; unsigned short y; unsigned short w; unsigned short h; unsigned short hcnt; unsigned short disp_line_height; unsigned short disp_line_indent;
  unsigned char start; unsigned char end;
  struct _u8g_t u8g;
  pic_gen_short_desc(font, name, width, real_name);
  u8g_Init(&u8g, &u8g_dev_pbm);
  disp_font = u8g_font_7x13;
  disp_line_height = 14;
  disp_line_indent = 75;
  start = u8g_font_GetFontStartEncoding(font);
  end = u8g_font_GetFontEndEncoding(font);
  u8g_FirstPage(&u8g);
  do
  {
    u8g_SetFont(&u8g, font);
    hcnt = ((&u8g)->width);
    hcnt /= u8g_GetFontBBXWidth(&u8g);
    hcnt -= 4;
    w = u8g_GetFontBBXWidth(&u8g);
    w = width;
    h = u8g_GetFontBBXHeight(&u8g);
    if ( h < disp_line_height )
      h = disp_line_height ;
    sprintf(s, "%s, %s", name,
        real_name);
    u8g_SetFont(&u8g, disp_font);
    u8g_DrawStrFontBBX(&u8g, 0, disp_line_height, 0, s);
    u8g_SetFont(&u8g, font);
    sprintf(s, "BBX Width %d, Height %d,  Capital A %d",
        u8g_GetFontBBXWidth(&u8g),
        u8g_GetFontBBXHeight(&u8g),
        u8g_GetFontCapitalAHeight(&u8g));
    u8g_SetFont(&u8g, disp_font);
    u8g_DrawStrFontBBX(&u8g, 0, disp_line_height*2, 0, s);
    sprintf(s, "Font data size: %d", u8g_font_GetSize(font));
    u8g_DrawStrFontBBX(&u8g, 0, disp_line_height*3, 0, s);
    hcnt = 16;
    i = start - start % hcnt;
    for( y = 0; y < 16; y++ )
    {
      u8g_SetFont(&u8g, disp_font);
      if ( i <= end )
      {
        sprintf(s, "%3d/0x%02x", i, i);
        u8g_DrawStrFontBBX(&u8g, 0, y*h+disp_line_height*3+h, 0, s);
      }
      for( x = 0; x < hcnt; x++ )
      {
        if ( i <= end )
        {
          u8g_SetFont(&u8g, font);
          u8g_DrawGlyphFontBBX(&u8g, x*w+disp_line_indent, y*h+disp_line_height*3+h, 0, i);
          i++;
        }
      }
    }
  }while( u8g_NextPage(&u8g) );
  {
    char cmd[256];
    u8g_SetFont(&u8g, font);
    sprintf(cmd, "convert u8g.pbm -trim %s.png", name );
    system(cmd);
  }
}

variable_types:
i
unsigned short

variable_types:
x
unsigned short

variable_types:
y
unsigned short

variable_types:
hcnt
unsigned short

variable_types:
start
unsigned char

variable_types:
end
unsigned char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
pic_gen_font((__int64)&u8g_font_unifont_72_73, "u8g_font_unifont_72_73", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_67_75, "u8g_font_unifont_67_75", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_75r, "u8g_font_unifont_75r", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_76, "u8g_font_unifont_76", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_77, "u8g_font_unifont_77", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_78_79, "u8g_font_unifont_78_79", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_86, "u8g_font_unifont_86", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont, "u8g_font_unifont", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifontr, "u8g_font_unifontr", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_0_8, "u8g_font_unifont_0_8", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_2_3, "u8g_font_unifont_2_3", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_4_5, "u8g_font_unifont_4_5", 17, (__int64)"Unifont");
pic_gen_font((__int64)&u8g_font_unifont_8_9, "u8g_font_unifont_8_9", 17, (__int64)"Unifont");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1((__int64)&u8g_font_unifont_72_73, "u8g_font_unifont_72_73", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_67_75, "u8g_font_unifont_67_75", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_75r, "u8g_font_unifont_75r", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_76, "u8g_font_unifont_76", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_77, "u8g_font_unifont_77", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_78_79, "u8g_font_unifont_78_79", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_86, "u8g_font_unifont_86", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont, "u8g_font_unifont", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifontr, "u8g_font_unifontr", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_0_8, "u8g_font_unifont_0_8", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_2_3, "u8g_font_unifont_2_3", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_4_5, "u8g_font_unifont_4_5", 17, (__int64)"Unifont");
func1((__int64)&u8g_font_unifont_8_9, "u8g_font_unifont_8_9", 17, (__int64)"Unifont");
return 0;
}

original_code:
int main(void)
{
  pic_gen_font(u8g_font_unifont_72_73, "u8g_font_unifont_72_73", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_67_75, "u8g_font_unifont_67_75", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_75r, "u8g_font_unifont_75r", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_76, "u8g_font_unifont_76", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_77, "u8g_font_unifont_77", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_78_79, "u8g_font_unifont_78_79", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_86, "u8g_font_unifont_86", 17, "Unifont");
  pic_gen_font(u8g_font_unifont, "u8g_font_unifont", 17, "Unifont");
  pic_gen_font(u8g_font_unifontr, "u8g_font_unifontr", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_0_8, "u8g_font_unifont_0_8", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_2_3, "u8g_font_unifont_2_3", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_4_5, "u8g_font_unifont_4_5", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_8_9, "u8g_font_unifont_8_9", 17, "Unifont");
  return 0;
}

canonical_original_code:
int main()
{
  pic_gen_font(u8g_font_unifont_72_73, "u8g_font_unifont_72_73", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_67_75, "u8g_font_unifont_67_75", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_75r, "u8g_font_unifont_75r", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_76, "u8g_font_unifont_76", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_77, "u8g_font_unifont_77", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_78_79, "u8g_font_unifont_78_79", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_86, "u8g_font_unifont_86", 17, "Unifont");
  pic_gen_font(u8g_font_unifont, "u8g_font_unifont", 17, "Unifont");
  pic_gen_font(u8g_font_unifontr, "u8g_font_unifontr", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_0_8, "u8g_font_unifont_0_8", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_2_3, "u8g_font_unifont_2_3", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_4_5, "u8g_font_unifont_4_5", 17, "Unifont");
  pic_gen_font(u8g_font_unifont_8_9, "u8g_font_unifont_8_9", 17, "Unifont");
  return 0;
}

return_type: int


xmain

decompiled_code:
__int64 xmain()
{
_BYTE v1[104]; // [rsp+0h] [rbp-68h] BYREF

u8g_Init(v1, &u8g_dev_sdl_1bit);
u8g_FirstPage(v1);
u8g_SetCursorFont(v1, &u8g_font_cursor);
do
{
u8g_SetColorIndex(v1, 1LL);
u8g_SetFont(v1, &u8g_font_9x18);
u8g_GetFontBBXWidth(v1);
u8g_GetFontBBXHeight(v1);
u8g_DrawStrDir(v1, 0LL, 5LL, 0LL, &unk_260);
u8g_DrawStrDir(v1, 10LL, 7LL, 0LL, &unk_260);
u8g_DrawStrDir(v1, 20LL, 9LL, 0LL, &unk_260);
u8g_DrawStrDir(v1, 20LL, 9LL, 0LL, &unk_262);
u8g_DrawStr(v1, 73LL, 25LL, "gabc");
u8g_DrawStr90(v1, 70LL, 28LL, "gabc");
u8g_DrawStr180(v1, 67LL, 25LL, "gabc");
u8g_DrawStr270(v1, 70LL, 22LL, "gabc");
u8g_SetColorIndex(v1, 1LL);
u8g_DrawHLine(v1, 0LL, 3LL, 127LL);
u8g_SetColorIndex(v1, 0LL);
u8g_DrawHLine(v1, 0LL, 4LL, 127LL);
}
while ( (unsigned __int8)u8g_NextPage(v1) );
while ( (int)u8g_sdl_get_key() < 0 )
;
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
_BYTE v1[104]; // [rsp+0h] [rbp-68h] BYREF

u8g_Init(v1, &u8g_dev_sdl_1bit);
u8g_FirstPage(v1);
u8g_SetCursorFont(v1, &u8g_font_cursor);
do
{
u8g_SetColorIndex(v1, 1LL);
u8g_SetFont(v1, &u8g_font_9x18);
u8g_GetFontBBXWidth(v1);
u8g_GetFontBBXHeight(v1);
u8g_DrawStrDir(v1, 0LL, 5LL, 0LL, &unk_260);
u8g_DrawStrDir(v1, 10LL, 7LL, 0LL, &unk_260);
u8g_DrawStrDir(v1, 20LL, 9LL, 0LL, &unk_260);
u8g_DrawStrDir(v1, 20LL, 9LL, 0LL, &unk_262);
u8g_DrawStr(v1, 73LL, 25LL, "gabc");
u8g_DrawStr90(v1, 70LL, 28LL, "gabc");
u8g_DrawStr180(v1, 67LL, 25LL, "gabc");
u8g_DrawStr270(v1, 70LL, 22LL, "gabc");
u8g_SetColorIndex(v1, 1LL);
u8g_DrawHLine(v1, 0LL, 3LL, 127LL);
u8g_SetColorIndex(v1, 0LL);
u8g_DrawHLine(v1, 0LL, 4LL, 127LL);
}
while ( (unsigned __int8)u8g_NextPage(v1) );
while ( (int)u8g_sdl_get_key() < 0 )
;
return 0LL;
}

original_code:
int xmain(void)
{
  u8g_uint_t w,h;
  u8g_t u8g;
  u8g_Init(&u8g, &u8g_dev_sdl_1bit);
  u8g_FirstPage(&u8g);
  u8g_SetCursorFont(&u8g, u8g_font_cursor);
  do
  {
    u8g_SetColorIndex(&u8g, 1);
    u8g_SetFont(&u8g, u8g_font_9x18);
    w = u8g_GetFontBBXWidth(&u8g);
    h = u8g_GetFontBBXHeight(&u8g);
    u8g_DrawStrDir(&u8g, 0, 5, 0, "g");
    u8g_DrawStrDir(&u8g, 10, 7, 0, "g");
    u8g_DrawStrDir(&u8g, 20, 9, 0, "g");
    u8g_DrawStrDir(&u8g, 20, 9, 0, "ga");
    u8g_DrawStr(&u8g, 70+3, 25, "gabc");
    u8g_DrawStr90(&u8g, 70, 25+3, "gabc");
    u8g_DrawStr180(&u8g, 70-3, 25, "gabc");
    u8g_DrawStr270(&u8g, 70, 25-3, "gabc");
    u8g_SetColorIndex(&u8g, 1);
    u8g_DrawHLine( &u8g, 0, 3, 127 );
    u8g_SetColorIndex(&u8g, 0);
    u8g_DrawHLine( &u8g, 0, 4, 127 );
  }while( u8g_NextPage(&u8g) );
  while( u8g_sdl_get_key() < 0 )
    ;
  return 0;
}

canonical_original_code:
int xmain()
{
  unsigned short w; unsigned short h;
  struct _u8g_t u8g;
  u8g_Init(&u8g, &u8g_dev_sdl_1bit);
  u8g_FirstPage(&u8g);
  u8g_SetCursorFont(&u8g, u8g_font_cursor);
  do
  {
    u8g_SetColorIndex(&u8g, 1);
    u8g_SetFont(&u8g, u8g_font_9x18);
    w = u8g_GetFontBBXWidth(&u8g);
    h = u8g_GetFontBBXHeight(&u8g);
    u8g_DrawStrDir(&u8g, 0, 5, 0, "g");
    u8g_DrawStrDir(&u8g, 10, 7, 0, "g");
    u8g_DrawStrDir(&u8g, 20, 9, 0, "g");
    u8g_DrawStrDir(&u8g, 20, 9, 0, "ga");
    u8g_DrawStr(&u8g, 70+3, 25, "gabc");
    u8g_DrawStr90(&u8g, 70, 25+3, "gabc");
    u8g_DrawStr180(&u8g, 70-3, 25, "gabc");
    u8g_DrawStr270(&u8g, 70, 25-3, "gabc");
    u8g_SetColorIndex(&u8g, 1);
    u8g_DrawHLine( &u8g, 0, 3, 127 );
    u8g_SetColorIndex(&u8g, 0);
    u8g_DrawHLine( &u8g, 0, 4, 127 );
  }while( u8g_NextPage(&u8g) );
  while( u8g_sdl_get_key() < 0 )
    ;
  return 0;
}

variable_types:
w
unsigned short

variable_types:
h
unsigned short

variable_types: struct _u8g_t { unsigned short width; unsigned short height; struct _u8g_dev_t { unsigned char (*dev_fn)(struct _u8g_t *u8g, struct _u8g_dev_t *dev, unsigned char msg, void *arg); void *dev_mem; unsigned char (*com_fn)(struct _u8g_t *u8g, unsigned char msg, unsigned char arg_val, void *arg_ptr); } *dev; unsigned char *font; unsigned char *cursor_font; unsigned char cursor_fg_color; unsigned char cursor_encoding; unsigned char mode; unsigned short cursor_x; unsigned short cursor_y; void (*cursor_fn)(struct _u8g_t *u8g); char glyph_dx; char glyph_x; char glyph_y; unsigned char glyph_width; unsigned char glyph_height; unsigned short (*font_calc_vref)(struct _u8g_t *u8g); unsigned char font_height_mode; char font_ref_ascent; char font_ref_descent; unsigned char font_line_spacing_factor; unsigned char line_spacing; struct _u8g_dev_arg_pixel_t { unsigned short x; unsigned char pixel; unsigned char dir; unsigned char color; unsigned char hi_color; unsigned char blue; } arg_pixel; void (*state_cb)(unsigned char msg); struct _u8g_box_t { unsigned short x0; } current_page; }

user_defined_types: struct _u8g_t { unsigned short width; unsigned short height; struct _u8g_dev_t *dev; unsigned char *font; unsigned char *cursor_font; unsigned char cursor_fg_color; unsigned char cursor_encoding; unsigned char mode; unsigned short cursor_x; unsigned short cursor_y; void (*cursor_fn)(struct _u8g_t *u8g); char glyph_dx; char glyph_x; char glyph_y; unsigned char glyph_width; unsigned char glyph_height; unsigned short (*font_calc_vref)(struct _u8g_t *u8g); unsigned char font_height_mode; char font_ref_ascent; char font_ref_descent; unsigned char font_line_spacing_factor; unsigned char line_spacing; struct _u8g_dev_arg_pixel_t arg_pixel; void (*state_cb)(unsigned char msg); struct _u8g_box_t current_page; }


draw

decompiled_code:
__int64 draw()
{
u8g_SetFont(&u8g, &u8g_font_helvR08);
u8g_SetFontPosTop(&u8g);
u8g_DrawStr(&u8g, 0LL, 0LL, "Hello World!");
u8g_SetFont(&u8g, &u8g_font_profont11);
u8g_SetFontPosTop(&u8g);
u8g_DrawStr(&u8g, 32LL, 25LL, "see yah!");
return u8g_DrawPixel(&u8g, 32LL, 25LL);
}

canonical_decompiled_code:
__int64 func1()
{
u8g_SetFont(&u8g, &u8g_font_helvR08);
u8g_SetFontPosTop(&u8g);
u8g_DrawStr(&u8g, 0LL, 0LL, "Hello World!");
u8g_SetFont(&u8g, &u8g_font_profont11);
u8g_SetFontPosTop(&u8g);
u8g_DrawStr(&u8g, 32LL, 25LL, "see yah!");
return u8g_DrawPixel(&u8g, 32LL, 25LL);
}

original_code:
void draw(void) {
  u8g_SetFont(&u8g, u8g_font_helvR08);
  u8g_SetFontPosTop(&u8g);
  u8g_DrawStr( &u8g, 0, 0, "Hello World!");
  u8g_SetFont(&u8g, u8g_font_profont11);
  u8g_SetFontPosTop(&u8g);
  u8g_DrawStr( &u8g, 32, 25, "see yah!");
  u8g_DrawPixel(&u8g, 32, 25);
}

canonical_original_code:
void draw() {
  u8g_SetFont(&u8g, u8g_font_helvR08);
  u8g_SetFontPosTop(&u8g);
  u8g_DrawStr( &u8g, 0, 0, "Hello World!");
  u8g_SetFont(&u8g, u8g_font_profont11);
  u8g_SetFontPosTop(&u8g);
  u8g_DrawStr( &u8g, 32, 25, "see yah!");
  u8g_DrawPixel(&u8g, 32, 25);
}

return_type: void


decompiled_code:
__int64 __fastcall col_find(char *s2)
{
int v1; // er13
const char *v2; // rbx
unsigned int v3; // er12

v1 = col_cnt;
if ( col_cnt <= 0 )
return 0xFFFFFFFFLL;
v2 = col_name;
v3 = 0;
while ( strcmp(v2, s2) )
{
++v3;
v2 += 1024;
if ( v3 == v1 )
return 0xFFFFFFFFLL;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2)
{
int v1; // er13
const char *v2; // rbx
unsigned int v3; // er12

v1 = col_cnt;
if ( col_cnt <= 0 )
return 0xFFFFFFFFLL;
v2 = col_name;
v3 = 0;
while ( strcmp(v2, s2) )
{
++v3;
v2 += 1024;
if ( v3 == v1 )
return 0xFFFFFFFFLL;
}
return v3;
}

original_code:
int col_find(const char *name)
{
  int i;
  for( i = 0; i < col_cnt; i++ )
    if ( strcmp(col_name[i], name) == 0 )
      return i;
  return -1;
}

canonical_original_code:
int col_find(char *name)
{
  int i;
  for( i = 0; i < col_cnt; i++ )
    if ( strcmp(col_name[i], name) == 0 )
      return i;
  return -1;
}

variable_types:
name
char *

variable_types: i int


decompiled_code:
__int64 __fastcall col_add(char *src)
{
unsigned int v1; // er12

v1 = col_cnt;
if ( col_cnt > 15 )
{
fwrite("maximum number of columns reached\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
strcpy((char *)(((__int64)col_cnt << 10) + 4243008), src);
col_cnt = v1 + 1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *src)
{
unsigned int v1; // er12

v1 = col_cnt;
if ( col_cnt > 15 )
{
fwrite("maximum number of columns reached\n", 1uLL, 0x22uLL, stderr);
exit(1);
}
strcpy((char *)(((__int64)col_cnt << 10) + 4243008), src);
col_cnt = v1 + 1;
return v1;
}

original_code:
int col_add(const char *name)
{
  if ( col_cnt >= 16 )
  {
    fprintf(stderr, "maximum number of columns reached\n");
    exit(1);
  }
  strcpy(col_name[col_cnt], name);
  col_cnt++;
  return col_cnt-1;
}

canonical_original_code:
int col_add(char *name)
{
  if ( col_cnt >= 16 )
  {
    fprintf(stderr, "maximum number of columns reached\n");
    exit(1);
  }
  strcpy(col_name[col_cnt], name);
  col_cnt++;
  return col_cnt-1;
}


decompiled_code:
void *col_clear_field_visibility()
{
void *result; // rax

if ( col_cnt > 0 )
result = memset(&col_field_visible, 0, 4LL * col_cnt);
return result;
}

canonical_decompiled_code:
void *func9()
{
void *result; // rax

if ( col_cnt > 0 )
result = memset(&col_field_visible, 0, 4LL * col_cnt);
return result;
}

original_code:
void col_clear_field_visibility(void)
{
  int i;
  for( i = 0; i < col_cnt; i++ )
    col_field_visible[i] = 0;
}

canonical_original_code:
void col_clear_field_visibility()
{
  int i;
  for( i = 0; i < col_cnt; i++ )
    col_field_visible[i] = 0;
}


decompiled_code:
void __fastcall col_mark_field_visible(int a1)
{
col_field_visible[a1] = 1;
}

canonical_decompiled_code:
void __fastcall func10(int a1)
{
col_field_visible[a1] = 1;
}

original_code:
void col_mark_field_visible(int pos)
{
  col_field_visible[pos] = 1;
}

variable_types: pos int


decompiled_code:
__int64 __fastcall col_is_field_visible(int a1)
{
return (unsigned int)col_field_visible[a1];
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
return (unsigned int)col_field_visible[a1];
}

original_code:
int col_is_field_visible(int pos)
{
  return col_field_visible[pos];
}


decompiled_code:
void *table_next_line()
{
++table_line;
return col_clear_field_visibility();
}

canonical_decompiled_code:
void *func12()
{
++table_line;
return func9();
}

original_code:
void table_next_line(void)
{
  table_line++;
  col_clear_field_visibility();
}

canonical_original_code:
void table_next_line()
{
  table_line++;
  col_clear_field_visibility();
}


decompiled_code:
void *table_finish_line()
{
__int64 v0; // rdx
__int64 v1; // rsi
char v2; // al
__int64 v3; // rdx
__int64 v4; // rcx

if ( col_cnt > 0 )
{
LODWORD(v0) = 0;
v1 = 16LL * table_line;
do
{
v2 = col_is_field_visible(v0);
table_visibility[v3 + v1] = v2;
v0 = v3 + 1;
}
while ( v0 != v4 );
}
return table_next_line();
}

canonical_decompiled_code:
void *func13()
{
__int64 v0; // rdx
__int64 v1; // rsi
char v2; // al
__int64 v3; // rdx
__int64 v4; // rcx

if ( col_cnt > 0 )
{
LODWORD(v0) = 0;
v1 = 16LL * table_line;
do
{
v2 = func11(v0);
table_visibility[v3 + v1] = v2;
v0 = v3 + 1;
}
while ( v0 != v4 );
}
return func12();
}

original_code:
void table_finish_line(void)
{
  int i;
  for( i = 0; i < col_cnt; i++ )
    table_visibility[table_line][i] = (unsigned char)col_is_field_visible(i);
  table_next_line();
}

canonical_original_code:
void table_finish_line()
{
  int i;
  for( i = 0; i < col_cnt; i++ )
    table_visibility[table_line][i] = (unsigned char)col_is_field_visible(i);
  table_next_line();
}


decompiled_code:
void __fastcall table_add_field(int a1)
{
if ( (unsigned int)col_is_field_visible(a1) )
table_finish_line();
col_mark_field_visible(a1);
}

canonical_decompiled_code:
void __fastcall func14(int a1)
{
if ( (unsigned int)func11(a1) )
func13();
func10(a1);
}

original_code:
void table_add_field(int pos)
{
  if ( col_is_field_visible(pos) == 0 )
  {
    col_mark_field_visible(pos);
  }
  else
  {
    table_finish_line();
    col_mark_field_visible(pos);
  }
}


decompiled_code:
__int64 __fastcall table_get_row_span(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx
_BYTE *v4; // rdx

result = 0LL;
v3 = 16LL * a1;
if ( table_visibility[a2 + v3] )
{
if ( a1 + 1 >= table_lines )
{
result = 1LL;
}
else
{
v4 = (char *)&unk_4040F0 + a2 + v3;
result = 1LL;
do
{
if ( *v4 )
break;
result = (unsigned int)(result + 1);
v4 += 16;
}
while ( (_DWORD)result != table_lines - a1 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rdx
_BYTE *v4; // rdx

result = 0LL;
v3 = 16LL * a1;
if ( table_visibility[a2 + v3] )
{
if ( a1 + 1 >= table_lines )
{
result = 1LL;
}
else
{
v4 = (char *)&unk_4040F0 + a2 + v3;
result = 1LL;
do
{
if ( *v4 )
break;
result = (unsigned int)(result + 1);
v4 += 16;
}
while ( (_DWORD)result != table_lines - a1 );
}
}
return result;
}

original_code:
int table_get_row_span(int row, int pos)
{
  int i, span = 1;
  if ( table_visibility[row][pos] == 0 )
    return 0;
  i = row+1;
  while(i < table_lines)
  {
    if ( table_visibility[i][pos] != 0 )
      break;
    span++;
    i++;
  }
  return span;
}

canonical_original_code:
int table_get_row_span(int row, int pos)
{
  int i; int span = 1;
  if ( table_visibility[row][pos] == 0 )
    return 0;
  i = row+1;
  while(i < table_lines)
  {
    if ( table_visibility[i][pos] != 0 )
      break;
    span++;
    i++;
  }
  return span;
}

variable_types: row int

variable_types: span int


decompiled_code:
int __fastcall html_out(const char *a1)
{
return printf("%s", a1);
}

canonical_decompiled_code:
int __fastcall func16(const char *a1)
{
return printf("%s", a1);
}

original_code:
void html_out(const char *s)
{
  printf("%s", s);
}

canonical_original_code:
void html_out(char *s)
{
  printf("%s", s);
}

variable_types:
s
char *


decompiled_code:
int html_start_table()
{
return html_out("<table border=\"1\" cellspacing=\"0\">\n");
}

canonical_decompiled_code:
int func17()
{
return func16("<table border=\"1\" cellspacing=\"0\">\n");
}

original_code:
void html_start_table(void)
{
  html_out("<table border=\"1\" cellspacing=\"0\">\n");
}

canonical_original_code:
void html_start_table()
{
  html_out("<table border=\"1\" cellspacing=\"0\">\n");
}


decompiled_code:
int html_end_table()
{
return html_out("</table>\n");
}

canonical_decompiled_code:
int func18()
{
return func16("</table>\n");
}

original_code:
void html_end_table(void)
{
  html_out("</table>\n");
}

canonical_original_code:
void html_end_table()
{
  html_out("</table>\n");
}


decompiled_code:
int html_start_row()
{
is_in_row = 1;
return html_out("<tr>\n");
}

canonical_decompiled_code:
int func19()
{
is_in_row = 1;
return func16("<tr>\n");
}

original_code:
void html_start_row(void)
{
  is_in_row = 1;
  html_out("<tr>\n");
}

canonical_original_code:
void html_start_row()
{
  is_in_row = 1;
  html_out("<tr>\n");
}


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

result = is_in_row;
if ( is_in_row )
{
is_in_row = 0;
result = html_out("</tr>\n");
}
return result;
}

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

result = is_in_row;
if ( is_in_row )
{
is_in_row = 0;
result = func16("</tr>\n");
}
return result;
}

original_code:
void html_end_row(void)
{
  if ( is_in_row == 0 )
    return;
  is_in_row = 0;
  html_out("</tr>\n");
}

canonical_original_code:
void html_end_row()
{
  if ( is_in_row == 0 )
    return;
  is_in_row = 0;
  html_out("</tr>\n");
}


decompiled_code:
int __fastcall html_start_field(int a1)
{
int v1; // eax
__m128i v3; // [rsp+0h] [rbp-408h] BYREF
char v4[8]; // [rsp+10h] [rbp-3F8h] BYREF

is_in_field = 1;
v1 = table_get_row_span(table_line, a1);
if ( v1 <= 1 )
{
strcpy(v4, "-1\">\n");
v3 = _mm_load_si128((const __m128i *)&xmmword_4020D0);
}
else
{
sprintf(v3.m128i_i8, "\n", (unsigned int)v1);
}
return html_out(v3.m128i_i8);
}

canonical_decompiled_code:
int __fastcall func21(int a1)
{
int v1; // eax
__m128i v3; // [rsp+0h] [rbp-408h] BYREF
char v4[8]; // [rsp+10h] [rbp-3F8h] BYREF

is_in_field = 1;
v1 = func15(table_line, a1);
if ( v1 <= 1 )
{
strcpy(v4, "-1\">\n");
v3 = _mm_load_si128((const __m128i *)&xmmword_4020D0);
}
else
{
sprintf(v3.m128i_i8, "\n", (unsigned int)v1);
}
return func16(v3.m128i_i8);
}

original_code:
void html_start_field(int pos)
{
  char buf[1024];
  int rowspan;
  is_in_field = 1;
  rowspan = table_get_row_span(table_line, pos);
  if ( rowspan >= 2 )
    sprintf(buf, "\n", rowspan);
  else
    sprintf(buf, "\n");
  html_out(buf);
}

variable_types:
buf
char [1024]

variable_types: rowspan int


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

result = is_in_field;
if ( is_in_field )
{
is_in_field = 0;
result = html_out("	\n");
}
return result;
}

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

result = is_in_field;
if ( is_in_field )
{
is_in_field = 0;
result = func16("	\n");
}
return result;
}

original_code:
void html_end_field(int pos)
{
  if ( is_in_field == 0 )
    return;
  is_in_field = 0;
  html_out("	\n");
}


decompiled_code:
int __fastcall table_add_field_phase2(int a1)
{
if ( (unsigned int)col_is_field_visible(a1) )
{
html_end_field();
html_end_row();
table_next_line();
html_start_row();
}
else
{
html_end_field();
}
col_mark_field_visible(a1);
return html_start_field(a1);
}

canonical_decompiled_code:
int __fastcall func23(int a1)
{
if ( (unsigned int)func11(a1) )
{
func22();
func20();
func12();
func19();
}
else
{
func22();
}
func10(a1);
return func21(a1);
}

original_code:
void table_add_field_phase2(int pos)
{
  if ( col_is_field_visible(pos) == 0 )
  {
    html_end_field(col_last);
    col_mark_field_visible(pos);
    html_start_field(pos);
  }
  else
  {
    html_end_field(col_last);
    html_end_row();
    table_next_line();
    html_start_row();
    col_mark_field_visible(pos);
    html_start_field(pos);
  }
}


decompiled_code:
void table_show_visibilty_matrx()
{
__int64 v0; // r13
int v1; // er12
__int64 i; // rbx
int v3; // esi
unsigned int v4; // eax

if ( table_lines > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
for ( i = 0LL; col_cnt > (int)i; ++i )
{
if ( table_visibility[v0 + i] )
putchar(120);
else
putchar(46);
v3 = i;
v4 = table_get_row_span(v1, v3);
printf("%d", v4);
}
++v1;
v0 += 16LL;
putchar(10);
}
while ( table_lines > v1 );
}
}

canonical_decompiled_code:
void func24()
{
__int64 v0; // r13
int v1; // er12
__int64 i; // rbx
int v3; // esi
unsigned int v4; // eax

if ( table_lines > 0 )
{
v0 = 0LL;
v1 = 0;
do
{
for ( i = 0LL; col_cnt > (int)i; ++i )
{
if ( table_visibility[v0 + i] )
putchar(120);
else
putchar(46);
v3 = i;
v4 = func15(v1, v3);
printf("%d", v4);
}
++v1;
v0 += 16LL;
putchar(10);
}
while ( table_lines > v1 );
}
}

original_code:
void table_show_visibilty_matrx(void)
{
  int i, j;
  for( j = 0; j < table_lines; j++ )
  {
    for( i = 0; i < col_cnt; i++ )
    {
      if ( table_visibility[j][i] == 0 )
        printf(".");
      else
        printf("x");
      printf("%d", table_get_row_span(j,i));
    }
    printf("\n");
  }
}

canonical_original_code:
void table_show_visibilty_matrx()
{
  int i; int j;
  for( j = 0; j < table_lines; j++ )
  {
    for( i = 0; i < col_cnt; i++ )
    {
      if ( table_visibility[j][i] == 0 )
        printf(".");
      else
        printf("x");
      printf("%d", table_get_row_span(j,i));
    }
    printf("\n");
  }
}

variable_types: j int


decompiled_code:
void __fastcall table_column(char *src)
{
if ( phase )
{
if ( phase == 1 )
{
col_last = col_find(src);
if ( col_last >= 0 )
{
table_add_field(col_last);
return;
}
}
else
{
if ( phase != 2 )
return;
col_last = col_find(src);
if ( col_last >= 0 )
{
table_add_field_phase2(col_last);
return;
}
}
exit(0);
}
col_last = col_find(src);
if ( col_last < 0 )
col_last = col_add(src);
}

canonical_decompiled_code:
void __fastcall func25(char *src)
{
if ( phase )
{
if ( phase == 1 )
{
col_last = func7(src);
if ( col_last >= 0 )
{
func14(col_last);
return;
}
}
else
{
if ( phase != 2 )
return;
col_last = func7(src);
if ( col_last >= 0 )
{
func23(col_last);
return;
}
}
exit(0);
}
col_last = func7(src);
if ( col_last < 0 )
col_last = func8(src);
}

original_code:
void table_column(const char *name)
{
  if ( phase == 0 )
  {
    col_last = col_find(name);
    if ( col_last < 0 )
      col_last = col_add(name);
  }
  else if ( phase == 1 )
  {
    col_last = col_find(name);
    if ( col_last < 0 )
      exit(0);
    table_add_field(col_last);
  }
  else if ( phase == 2 )
  {
    col_last = col_find(name);
    if ( col_last < 0 )
      exit(0);
    table_add_field_phase2(col_last);
  }
}

canonical_original_code:
void table_column(char *name)
{
  if ( phase == 0 )
  {
    col_last = col_find(name);
    if ( col_last < 0 )
      col_last = col_add(name);
  }
  else if ( phase == 1 )
  {
    col_last = col_find(name);
    if ( col_last < 0 )
      exit(0);
    table_add_field(col_last);
  }
  else if ( phase == 2 )
  {
    col_last = col_find(name);
    if ( col_last < 0 )
      exit(0);
    table_add_field_phase2(col_last);
  }
}


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

if ( phase == 2 )
result = html_out(a1);
return result;
}

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

if ( phase == 2 )
result = func16(a1);
return result;
}

original_code:
void table_text(const char *text)
{
  if ( phase == 2 )
  {
    html_out(text);
  }
}

canonical_original_code:
void table_text(char *text)
{
  if ( phase == 2 )
  {
    html_out(text);
  }
}

variable_types:
text
char *


main

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

if ( argc <= 1 )
{
printf("%s <tablefile>\n", *argv);
result = 1;
}
else
{
table_read_file((char *)argv[1]);
result = 0;
}
return result;
}

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

if ( argc <= 1 )
{
printf("%s <tablefile>\n", *argv);
result = 1;
}
else
{
func28((char *)argv[1]);
result = 0;
}
return result;
}

original_code:
int main(int argc, char **argv)
{
  if ( argc <= 1 )
  {
    printf("%s <tablefile>\n", argv[0]);
    return 1;
  }
  table_read_file(argv[1]);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **


writeFlipDiscMatrixRow

decompiled_code:
int __fastcall writeFlipDiscMatrixRow(char a1, unsigned __int8 *a2)
{
int v2; // er13
__int64 v3; // r12
unsigned __int8 *v4; // rbx
int result; // eax

v2 = 0;
v3 = (__int64)&a2[(unsigned __int8)(a1 - 1) + 1];
do
{
v4 = a2;
if ( a1 )
{
do
{
while ( ((1 << v2) & *v4) != 0 )
{
++v4;
putchar(42);
if ( v4 == (unsigned __int8 *)v3 )
goto LABEL_7;
}
++v4;
putchar(46);
}
while ( v4 != (unsigned __int8 *)v3 );
}
LABEL_7:
++v2;
result = putchar(10);
}
while ( v2 != 7 );
return result;
}

canonical_decompiled_code:
int __fastcall func0(char a1, unsigned __int8 *a2)
{
int v2; // er13
__int64 v3; // r12
unsigned __int8 *v4; // rbx
int result; // eax

v2 = 0;
v3 = (__int64)&a2[(unsigned __int8)(a1 - 1) + 1];
do
{
v4 = a2;
if ( a1 )
{
do
{
while ( ((1 << v2) & *v4) != 0 )
{
++v4;
putchar(42);
if ( v4 == (unsigned __int8 *)v3 )
goto LABEL_7;
}
++v4;
putchar(46);
}
while ( v4 != (unsigned __int8 *)v3 );
}
LABEL_7:
++v2;
result = putchar(10);
}
while ( v2 != 7 );
return result;
}

original_code:
void writeFlipDiscMatrixRow(uint8_t width, uint8_t *row)
{
  uint8_t i, b;
  for( b = 0; b < 7; b++ )
  {
    for( i = 0; i < width; i++ )
    {
      if ( row[i] & (1<<b) )
      {
 printf("*");
      }
      else
      {
 printf(".");
      }
    }
    printf("\n");
  }
}

canonical_original_code:
void writeFlipDiscMatrixRow(unsigned char width, unsigned char *row)
{
  unsigned char i; unsigned char b;
  for( b = 0; b < 7; b++ )
  {
    for( i = 0; i < width; i++ )
    {
      if ( row[i] & (1<<b) )
      {
 printf("*");
      }
      else
      {
 printf(".");
      }
    }
    printf("\n");
  }
}

variable_types:
width
unsigned char

variable_types:
row
unsigned char *

variable_types:
i
unsigned char

variable_types:
b
unsigned char


writeFlipDiscMatrix

decompiled_code:
int __fastcall writeFlipDiscMatrix(__int64 a1, __int64 a2, char a3, unsigned __int8 *a4, unsigned __int8 *a5)
{
writeFlipDiscMatrixRow(a3, a4);
return writeFlipDiscMatrixRow(a3, a5);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2, char a3, unsigned __int8 *a4, unsigned __int8 *a5)
{
func0(a3, a4);
return func0(a3, a5);
}

original_code:
void writeFlipDiscMatrix(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2)
{
  writeFlipDiscMatrixRow(width, row1);
  writeFlipDiscMatrixRow(width, row2);
}

canonical_original_code:
void writeFlipDiscMatrix(unsigned char id, unsigned char page, unsigned char width, unsigned char *row1, unsigned char *row2)
{
  writeFlipDiscMatrixRow(width, row1);
  writeFlipDiscMatrixRow(width, row2);
}

variable_types:
id
unsigned char

variable_types:
page
unsigned char


decompiled_code:
__int64 get_key_code()
{
int v0; // eax
unsigned int v1; // er8

v0 = u8g_sdl_get_key();
if ( v0 <= 0 )
return 0LL;
switch ( v0 )
{
case 'n':
v1 = 1;
break;
case 'p':
v1 = 2;
break;
case ' ':
v1 = 3;
break;
default:
v1 = 0;
if ( v0 == 113 )
exit(0);
break;
}
return v1;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax
unsigned int v1; // er8

v0 = u8g_sdl_get_key();
if ( v0 <= 0 )
return 0LL;
switch ( v0 )
{
case 'n':
v1 = 1;
break;
case 'p':
v1 = 2;
break;
case ' ':
v1 = 3;
break;
default:
v1 = 0;
if ( v0 == 113 )
exit(0);
break;
}
return v1;
}

original_code:
uint8_t get_key_code(void)
{
  uint8_t chess_key;
  int sdl_key;
  sdl_key = u8g_sdl_get_key();
  chess_key = 0;
  if ( sdl_key > 0 )
  {
    if ( sdl_key == 'n' )
      chess_key = 1;
    else if ( sdl_key == 'p' )
      chess_key = 2;
    else if ( sdl_key == ' ' )
      chess_key = 3;
    else if ( sdl_key == 'q' )
      exit(0);
  }
  return chess_key;
}

canonical_original_code:
unsigned char get_key_code()
{
  unsigned char chess_key;
  int sdl_key;
  sdl_key = u8g_sdl_get_key();
  chess_key = 0;
  if ( sdl_key > 0 )
  {
    if ( sdl_key == 'n' )
      chess_key = 1;
    else if ( sdl_key == 'p' )
      chess_key = 2;
    else if ( sdl_key == ' ' )
      chess_key = 3;
    else if ( sdl_key == 'q' )
      exit(0);
  }
  return chess_key;
}

return_type: unsigned char


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

result = u8g_sdl_get_key();
switch ( (_DWORD)result )
{
case 'p':
menu_redraw_required = 1;
result = (unsigned int)(unsigned __int8)menu_current - 1;
if ( !menu_current )
result = 3LL;
menu_current = result;
break;
case 'q':
exit(0);
case 'n':
menu_redraw_required = 1;
result = (unsigned int)(unsigned __int8)menu_current + 1;
if ( (unsigned __int8)(menu_current + 1) > 3u )
result = 0LL;
menu_current = result;
break;
}
return result;
}

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

result = u8g_sdl_get_key();
switch ( (_DWORD)result )
{
case 'p':
menu_redraw_required = 1;
result = (unsigned int)(unsigned __int8)menu_current - 1;
if ( !menu_current )
result = 3LL;
menu_current = result;
break;
case 'q':
exit(0);
case 'n':
menu_redraw_required = 1;
result = (unsigned int)(unsigned __int8)menu_current + 1;
if ( (unsigned __int8)(menu_current + 1) > 3u )
result = 0LL;
menu_current = result;
break;
}
return result;
}

original_code:
void update_menu(void)
{
  switch ( u8g_sdl_get_key() )
  {
    case 'n':
      menu_current++;
      if ( menu_current >= 4 )
        menu_current = 0;
      menu_redraw_required = 1;
      break;
    case 'p':
      if ( menu_current == 0 )
        menu_current = 4;
      menu_current--;
      menu_redraw_required = 1;
      break;
    case 'q':
      exit(0);
  }
}

canonical_original_code:
void update_menu()
{
  switch ( u8g_sdl_get_key() )
  {
    case 'n':
      menu_current++;
      if ( menu_current >= 4 )
        menu_current = 0;
      menu_redraw_required = 1;
      break;
    case 'p':
      if ( menu_current == 0 )
        menu_current = 4;
      menu_current--;
      menu_redraw_required = 1;
      break;
    case 'q':
      exit(0);
  }
}


decompiled_code:
__int64 draw_menu()
{
unsigned __int16 v0; // r12
__int64 v1; // r15
unsigned int v2; // er14
unsigned __int8 v3; // r13
int v4; // kr00_4
char *v5; // rcx
__int64 result; // rax

v0 = 0;
v1 = 0LL;
u8g_SetFont(&u8g, &u8g_font_6x13);
u8g_SetFontRefHeightText(&u8g);
u8g_SetFontPosTop(&u8g);
v2 = (unsigned __int16)u8g;
v3 = *((_BYTE *)&u8g + 65) - *((_BYTE *)&u8g + 66);
do
{
v4 = v2 - (unsigned __int16)u8g_GetStrWidth(&u8g, (&menu_strings)[v1]);
u8g_SetDefaultForegroundColor(&u8g);
if ( menu_current == (_BYTE)v1 )
{
u8g_DrawBox(&u8g, 0LL, (unsigned __int16)(v0 + 1), v2, v3);
u8g_SetDefaultBackgroundColor(&u8g);
}
v5 = (&menu_strings)[v1++];
result = u8g_DrawStr(&u8g, (unsigned __int16)(v4 / 2), v0, v5);
v0 += v3;
}
while ( v1 != 4 );
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned __int16 v0; // r12
__int64 v1; // r15
unsigned int v2; // er14
unsigned __int8 v3; // r13
int v4; // kr00_4
char *v5; // rcx
__int64 result; // rax

v0 = 0;
v1 = 0LL;
u8g_SetFont(&u8g, &u8g_font_6x13);
u8g_SetFontRefHeightText(&u8g);
u8g_SetFontPosTop(&u8g);
v2 = (unsigned __int16)u8g;
v3 = *((_BYTE *)&u8g + 65) - *((_BYTE *)&u8g + 66);
do
{
v4 = v2 - (unsigned __int16)u8g_GetStrWidth(&u8g, (&menu_strings)[v1]);
u8g_SetDefaultForegroundColor(&u8g);
if ( menu_current == (_BYTE)v1 )
{
u8g_DrawBox(&u8g, 0LL, (unsigned __int16)(v0 + 1), v2, v3);
u8g_SetDefaultBackgroundColor(&u8g);
}
v5 = (&menu_strings)[v1++];
result = u8g_DrawStr(&u8g, (unsigned __int16)(v4 / 2), v0, v5);
v0 += v3;
}
while ( v1 != 4 );
return result;
}

original_code:
void draw_menu(void)
{
  uint8_t i, h;
  u8g_uint_t w, d;
  u8g_SetFont(&u8g, u8g_font_6x13);
  u8g_SetFontRefHeightText(&u8g);
  u8g_SetFontPosTop(&u8g);
  h = ((&u8g)->font_ref_ascent)-((&u8g)->font_ref_descent);
  w = ((&u8g)->width);
  for( i = 0; i < 4; i++ )
  {
    d = (w-u8g_GetStrWidth(&u8g, menu_strings[i]))/2;
    u8g_SetDefaultForegroundColor(&u8g);
    if ( i == menu_current )
    {
      u8g_DrawBox(&u8g, 0, i*h+1, w, h);
      u8g_SetDefaultBackgroundColor(&u8g);
    }
    u8g_DrawStr(&u8g, d, i*h, menu_strings[i]);
  }
}

canonical_original_code:
void draw_menu()
{
  unsigned char i; unsigned char h;
  unsigned short w; unsigned short d;
  u8g_SetFont(&u8g, u8g_font_6x13);
  u8g_SetFontRefHeightText(&u8g);
  u8g_SetFontPosTop(&u8g);
  h = ((&u8g)->font_ref_ascent)-((&u8g)->font_ref_descent);
  w = ((&u8g)->width);
  for( i = 0; i < 4; i++ )
  {
    d = (w-u8g_GetStrWidth(&u8g, menu_strings[i]))/2;
    u8g_SetDefaultForegroundColor(&u8g);
    if ( i == menu_current )
    {
      u8g_DrawBox(&u8g, 0, i*h+1, w, h);
      u8g_SetDefaultBackgroundColor(&u8g);
    }
    u8g_DrawStr(&u8g, d, i*h, menu_strings[i]);
  }
}

variable_types:
h
unsigned char

variable_types:
w
unsigned short

variable_types:
d
unsigned short


warning

decompiled_code:
int __fastcall warning(const char *a1)
{
return fprintf(stderr, "AVISO! (%d, %d, %s): %s\n", lineno, linepos, (const char *)&yytext, a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return fprintf(stderr, "AVISO! (%d, %d, %s): %s\n", lineno, linepos, (const char *)&yytext, a1);
}

original_code:
void warning (char *mens)
{
    fprintf (stderr, "AVISO! (%d, %d, %s): %s\n", lineno, linepos, yytext, mens);
}

canonical_original_code:
void warning(char *mens)
{
    fprintf (stderr, "AVISO! (%d, %d, %s): %s\n", lineno, linepos, yytext, mens);
}

variable_types:
mens
char *


yyerror

decompiled_code:
void __fastcall __noreturn yyerror(const char *a1)
{
fprintf(stderr, "ERROR SINTACTICO! (%d, %d, %s): %s\n", lineno, linepos, (const char *)&yytext, a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "ERROR SINTACTICO! (%d, %d, %s): %s\n", lineno, linepos, (const char *)&yytext, a1);
exit(1);
}

original_code:
void yyerror (char *mens)
{
 fprintf (stderr, "ERROR SINTACTICO! (%d, %d, %s): %s\n", lineno, linepos, yytext, mens);
 exit (1);
}

canonical_original_code:
void yyerror(char *mens)
{
 fprintf (stderr, "ERROR SINTACTICO! (%d, %d, %s): %s\n", lineno, linepos, yytext, mens);
 exit (1);
}


decompiled_code:
int __fastcall error_semantico(const char *a1)
{
return fprintf(stderr, "ERROR SEMANTICO! (%d, %d, %s) %s\n", lineno, linepos, (const char *)&yytext, a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return fprintf(stderr, "ERROR SEMANTICO! (%d, %d, %s) %s\n", lineno, linepos, (const char *)&yytext, a1);
}

original_code:
void error_semantico (char *mens)
{
 fprintf (stderr, "ERROR SEMANTICO! (%d, %d, %s) %s\n", lineno, linepos, yytext, mens);
}

canonical_original_code:
void error_semantico(char *mens)
{
 fprintf (stderr, "ERROR SEMANTICO! (%d, %d, %s) %s\n", lineno, linepos, yytext, mens);
}


hash

decompiled_code:
__int64 __fastcall hash(_BYTE *a1)
{
int v1; // eax
int v2; // edx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 += v1;
v1 = (char)*a1;
}
while ( *a1 );
return (unsigned int)(v2 % 7);
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
int v1; // eax
int v2; // edx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 += v1;
v1 = (char)*a1;
}
while ( *a1 );
return (unsigned int)(v2 % 7);
}

original_code:
int hash (char *nombre)
{
   int r = 0;
   for ( ; *nombre; ++nombre)
    r += *nombre;
 return (r % 7);
}

canonical_original_code:
int hash(char *nombre)
{
   int r = 0;
   for ( ; *nombre; ++nombre)
    r += *nombre;
 return (r % 7);
}

variable_types:
nombre
char *

variable_types: r int


main

repo: pacew/bcard

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

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "n");
if ( v3 == -1 )
break;
if ( v3 != 110 )
goto LABEL_9;
draw_outline = 0;
}
if ( optind != argc )
LABEL_9:
usage();
v4 = 0;
init_pdf("cards.pdf");
setup_fonts();
code_surface = cairo_image_surface_create_from_png();
code_pattern = cairo_pattern_create_for_surface();
do
{
cairo_save();
v5 = cr;
v4 += 144;
cairo_translate();
draw_card(v5, 54.0);
cairo_restore();
cairo_save();
v6 = cr;
cairo_translate();
draw_card(v6, 306.0);
cairo_restore();
}
while ( v4 != 720 );
cairo_destroy();
cairo_surface_flush();
cairo_surface_destroy();
printf("evince %s\n", "cards.pdf");
return 0;
}

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

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "n");
if ( v3 == -1 )
break;
if ( v3 != 110 )
goto LABEL_9;
draw_outline = 0;
}
if ( optind != argc )
LABEL_9:
func7();
v4 = 0;
func8("cards.pdf");
func10();
code_surface = cairo_image_surface_create_from_png();
code_pattern = cairo_pattern_create_for_surface();
do
{
cairo_save();
v5 = cr;
v4 += 144;
cairo_translate();
func15(v5, 54.0);
cairo_restore();
cairo_save();
v6 = cr;
cairo_translate();
func15(v6, 306.0);
cairo_restore();
}
while ( v4 != 720 );
cairo_destroy();
cairo_surface_flush();
cairo_surface_destroy();
printf("evince %s\n", "cards.pdf");
return 0;
}

original_code:
int
main (int argc, char **argv)
{
 int c;
 int row, col;
 double x, y;
 char *outname;
 outname = "cards.pdf";
 while ((c = getopt (argc, argv, "n")) != (-1)) {
  switch (c) {
  case 'n':
   draw_outline = 0;
   break;
  default:
   usage ();
  }
 }
 if (optind != argc)
  usage ();
 init_pdf (outname);
 setup_fonts ();
 code_surface
  = cairo_image_surface_create_from_png ("code-med-high.png");
 code_pattern = cairo_pattern_create_for_surface (code_surface);
 for (row = 0; row < 5; row++) {
  for (col = 0; col < 2; col++) {
   cairo_save (cr);
   x = (0.75 * 72) + col * (3.5 * 72);
   y = (0.5 * 72) + row * (2 * 72);
   cairo_translate (cr, x, y);
   draw_card ();
   cairo_restore (cr);
  }
 }
 cairo_destroy(cr);
 cairo_surface_flush(surface);
 cairo_surface_destroy(surface);
 printf ("evince %s\n", outname);
 return (0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int c;
 int row; int col;
 double x; double y;
 char *outname;
 outname = "cards.pdf";
 while ((c = getopt (argc, argv, "n")) != (-1)) {
  switch (c) {
  case 'n':
   draw_outline = 0;
   break;
  default:
   usage ();
  }
 }
 if (optind != argc)
  usage ();
 init_pdf (outname);
 setup_fonts ();
 code_surface
  = cairo_image_surface_create_from_png ("code-med-high.png");
 code_pattern = cairo_pattern_create_for_surface (code_surface);
 for (row = 0; row < 5; row++) {
  for (col = 0; col < 2; col++) {
   cairo_save (cr);
   x = (0.75 * 72) + col * (3.5 * 72);
   y = (0.5 * 72) + row * (2 * 72);
   cairo_translate (cr, x, y);
   draw_card ();
   cairo_restore (cr);
  }
 }
 cairo_destroy(cr);
 cairo_surface_flush(surface);
 cairo_surface_destroy(surface);
 printf ("evince %s\n", outname);
 return (0);
}

variable_types: c int

variable_types: row int

variable_types: col int

variable_types: x double

variable_types: y double

variable_types:
outname
char *


usage

decompiled_code:
void __noreturn usage()
{
fwrite("usage: bcard\n", 1uLL, 0xDuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func7()
{
fwrite("usage: bcard\n", 1uLL, 0xDuLL, stderr);
exit(1);
}

original_code:
void
usage (void)
{
 fprintf (stderr, "usage: bcard\n");
 exit (1);
}

canonical_original_code:
void usage()
{
 fprintf (stderr, "usage: bcard\n");
 exit (1);
}


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

surface = cairo_pdf_surface_create();
cr = cairo_create();
result = pango_cairo_create_layout();
layout = result;
return result;
}

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

surface = cairo_pdf_surface_create();
cr = cairo_create();
result = pango_cairo_create_layout();
layout = result;
return result;
}

original_code:
void
init_pdf (char *outname)
{
 surface = cairo_pdf_surface_create(outname, (8.5 * 72), (11 * 72));
 cr = cairo_create(surface);
 layout = pango_cairo_create_layout (cr);
}

canonical_original_code:
void init_pdf(char *outname)
{
 surface = cairo_pdf_surface_create(outname, (8.5 * 72), (11 * 72));
 cr = cairo_create(surface);
 layout = pango_cairo_create_layout (cr);
}


decompiled_code:
double *setup_fonts()
{
double *result; // rax

name_font = (__int64)setup_font("Lucida Sans Bold", 12.0);
main_font = (__int64)setup_font("Lucida Sans", 8.0);
result = setup_font("Courier Bold", 11.4);
mono_font = (__int64)result;
return result;
}

canonical_decompiled_code:
double *func10()
{
double *result; // rax

name_font = (__int64)func9("Lucida Sans Bold", 12.0);
main_font = (__int64)func9("Lucida Sans", 8.0);
result = func9("Courier Bold", 11.4);
mono_font = (__int64)result;
return result;
}

original_code:
void
setup_fonts (void)
{
 name_font = setup_font ("Lucida Sans Bold", 12);
 main_font = setup_font ("Lucida Sans", 8);
 mono_font = setup_font ("Courier Bold", 11.4);
}

canonical_original_code:
void setup_fonts()
{
 name_font = setup_font ("Lucida Sans Bold", 12);
 main_font = setup_font ("Lucida Sans", 8);
 mono_font = setup_font ("Courier Bold", 11.4);
}


decompiled_code:
__int64 draw_text()
{
cairo_move_to();
return pango_cairo_show_layout();
}

canonical_decompiled_code:
__int64 func13()
{
cairo_move_to();
return pango_cairo_show_layout();
}

original_code:
void
draw_text (double x, double y)
{
 cairo_move_to (cr, x, y);
 pango_cairo_show_layout (cr, layout);
}

canonical_original_code:
void draw_text(double x, double y)
{
 cairo_move_to (cr, x, y);
 pango_cairo_show_layout (cr, layout);
}


decompiled_code:
__int64 set_gray()
{
return cairo_set_source_rgb();
}

canonical_decompiled_code:
__int64 func14()
{
return cairo_set_source_rgb();
}

original_code:
void
set_gray (double pct)
{
 cairo_set_source_rgb(cr, pct / 100.0, pct / 100.0, pct / 100.0);
}

canonical_original_code:
void set_gray(double pct)
{
 cairo_set_source_rgb(cr, pct / 100.0, pct / 100.0, pct / 100.0);
}

variable_types: pct double


decompiled_code:
__int64 draw_card()
{
double v1; // [rsp+0h] [rbp-18h] BYREF
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

set_gray(80.0);
if ( draw_outline )
{
cairo_rectangle();
cairo_stroke();
}
set_gray(0.0);
setup_text(name_font, "Alex Willisson", &v1, v2);
draw_text(12.0, 15.0);
setup_text(mono_font, "atw@mit.edu", &v1, v2);
draw_text(12.0, 37.0);
setup_text(mono_font, "774-277-9494", &v1, v2);
draw_text(12.0, 59.0);
set_gray(30.0);
setup_text(main_font, "3 Ames Street, Wa203", &v1, v2);
draw_text(12.0, 84.0);
setup_text(main_font, "Cambridge, MA 02139", &v1, v2);
draw_text(12.0, 99.0);
set_gray(0.0);
setup_text(mono_font, "http://alex.willisson.org", &v1, v2);
draw_text(12.0, 119.0);
cairo_save();
cairo_translate();
cairo_scale();
cairo_image_surface_get_height();
cairo_image_surface_get_width();
cairo_rectangle();
cairo_set_source();
cairo_fill();
return cairo_restore();
}

canonical_decompiled_code:
__int64 func15()
{
double v1; // [rsp+0h] [rbp-18h] BYREF
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

func14(80.0);
if ( draw_outline )
{
cairo_rectangle();
cairo_stroke();
}
func14(0.0);
func12(name_font, "Alex Willisson", &v1, v2);
func13(12.0, 15.0);
func12(mono_font, "atw@mit.edu", &v1, v2);
func13(12.0, 37.0);
func12(mono_font, "774-277-9494", &v1, v2);
func13(12.0, 59.0);
func14(30.0);
func12(main_font, "3 Ames Street, Wa203", &v1, v2);
func13(12.0, 84.0);
func12(main_font, "Cambridge, MA 02139", &v1, v2);
func13(12.0, 99.0);
func14(0.0);
func12(mono_font, "http://alex.willisson.org", &v1, v2);
func13(12.0, 119.0);
cairo_save();
cairo_translate();
cairo_scale();
cairo_image_surface_get_height();
cairo_image_surface_get_width();
cairo_rectangle();
cairo_set_source();
cairo_fill();
return cairo_restore();
}

original_code:
void
draw_card (void)
{
 double curx, cury;
 double dx, dy;
 double scale;
 set_gray (80);
 if (draw_outline) {
  cairo_rectangle (cr, 0, 0, (3.5 * 72), (2 * 72));
  cairo_stroke (cr);
 }
 curx = 12;
 cury = 15;
 set_gray (0);
 setup_text (name_font, "Alex Willisson", &dx, &dy);
 if (0) {
  draw_text (((3.5 * 72) - dx) / 2, cury);
 } else {
  draw_text (curx, cury);
 }
 cury += 22;
 setup_text (mono_font, "atw@mit.edu", &dx, &dy);
 draw_text (curx, cury);
 cury += 22;
 setup_text (mono_font, "774-277-9494", &dx, &dy);
 draw_text (curx, cury);
 set_gray (30);
 cury += 25;
 setup_text (main_font, "3 Ames Street, Wa203", &dx, &dy);
 draw_text (curx, cury);
 cury += 15;
 setup_text (main_font, "Cambridge, MA 02139", &dx, &dy);
 draw_text (curx, cury);
 set_gray (0);
 cury = (2 * 72) - 25;
 setup_text (mono_font, "http://alex.willisson.org", &dx, &dy);
 draw_text (curx, cury);
 curx = 170;
 cury = 5;
 scale = .12;
 cairo_save (cr);
 cairo_translate (cr, curx, cury);
 cairo_scale (cr, scale, scale);
 cairo_rectangle (cr,
    0, 0,
    cairo_image_surface_get_width (code_surface),
    cairo_image_surface_get_height (code_surface));
 cairo_set_source (cr, code_pattern);
 cairo_fill (cr);
 cairo_restore (cr);
}

canonical_original_code:
void draw_card()
{
 double curx; double cury;
 double dx; double dy;
 double scale;
 set_gray (80);
 if (draw_outline) {
  cairo_rectangle (cr, 0, 0, (3.5 * 72), (2 * 72));
  cairo_stroke (cr);
 }
 curx = 12;
 cury = 15;
 set_gray (0);
 setup_text (name_font, "Alex Willisson", &dx, &dy);
 if (0) {
  draw_text (((3.5 * 72) - dx) / 2, cury);
 } else {
  draw_text (curx, cury);
 }
 cury += 22;
 setup_text (mono_font, "atw@mit.edu", &dx, &dy);
 draw_text (curx, cury);
 cury += 22;
 setup_text (mono_font, "774-277-9494", &dx, &dy);
 draw_text (curx, cury);
 set_gray (30);
 cury += 25;
 setup_text (main_font, "3 Ames Street, Wa203", &dx, &dy);
 draw_text (curx, cury);
 cury += 15;
 setup_text (main_font, "Cambridge, MA 02139", &dx, &dy);
 draw_text (curx, cury);
 set_gray (0);
 cury = (2 * 72) - 25;
 setup_text (mono_font, "http://alex.willisson.org", &dx, &dy);
 draw_text (curx, cury);
 curx = 170;
 cury = 5;
 scale = .12;
 cairo_save (cr);
 cairo_translate (cr, curx, cury);
 cairo_scale (cr, scale, scale);
 cairo_rectangle (cr,
    0, 0,
    cairo_image_surface_get_width (code_surface),
    cairo_image_surface_get_height (code_surface));
 cairo_set_source (cr, code_pattern);
 cairo_fill (cr);
 cairo_restore (cr);
}

variable_types: curx double

variable_types: cury double

variable_types: dx double

variable_types: dy double

variable_types: scale double


decompiled_code:
__int64 set_black()
{
return set_gray(0.0);
}

original_code:
void
set_black (void)
{
 set_gray (0);
}

canonical_original_code:
void set_black()
{
 set_gray (0);
}


dump

repo: pacew/fitbit

decompiled_code:
int __fastcall dump(unsigned __int8 *a1, int a2)
{
unsigned int v2; // er14
unsigned __int8 *v3; // r13
unsigned __int8 *v5; // rbx
unsigned __int8 *v6; // r15
unsigned int v7; // ebp
__int64 v8; // rsi
unsigned __int8 *v9; // r15
unsigned int v10; // edi
int result; // eax
unsigned int v12; // [rsp+0h] [rbp-3Ch]

if ( a2 > 0 )
{
v2 = 0;
v3 = a1;
v5 = a1 + 16;
v12 = ((a2 - 1) & 0xFFFFFFF0) + 16;
do
{
printf("%04x: ", v2);
v6 = v3;
v7 = v2 - (_DWORD)v3;
do
{
while ( a2 > (int)(v7 + (_DWORD)v6) )
{
v8 = *v6++;
printf("%02x ", v8);
if ( v6 == v5 )
goto LABEL_7;
}
++v6;
printf(" ");
}
while ( v6 != v5 );
LABEL_7:
v9 = v3;
printf(" ");
do
{
while ( a2 <= (int)(v7 + (_DWORD)v9) )
{
++v9;
putchar(32);
if ( v9 == v5 )
goto LABEL_14;
}
v10 = *v9 & 0x7F;
if ( v10 <= 0x1F || v10 == 127 )
putchar(46);
else
putchar(v10);
++v9;
}
while ( v9 != v5 );
LABEL_14:
v2 += 16;
v5 += 16;
v3 += 16;
result = putchar(10);
}
while ( v2 != v12 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned int v2; // er14
unsigned __int8 *v3; // r13
unsigned __int8 *v5; // rbx
unsigned __int8 *v6; // r15
unsigned int v7; // ebp
__int64 v8; // rsi
unsigned __int8 *v9; // r15
unsigned int v10; // edi
int result; // eax
unsigned int v12; // [rsp+0h] [rbp-3Ch]

if ( a2 > 0 )
{
v2 = 0;
v3 = a1;
v5 = a1 + 16;
v12 = ((a2 - 1) & 0xFFFFFFF0) + 16;
do
{
printf("%04x: ", v2);
v6 = v3;
v7 = v2 - (_DWORD)v3;
do
{
while ( a2 > (int)(v7 + (_DWORD)v6) )
{
v8 = *v6++;
printf("%02x ", v8);
if ( v6 == v5 )
goto LABEL_7;
}
++v6;
printf(" ");
}
while ( v6 != v5 );
LABEL_7:
v9 = v3;
printf(" ");
do
{
while ( a2 <= (int)(v7 + (_DWORD)v9) )
{
++v9;
putchar(32);
if ( v9 == v5 )
goto LABEL_14;
}
v10 = *v9 & 0x7F;
if ( v10 <= 0x1F || v10 == 127 )
putchar(46);
else
putchar(v10);
++v9;
}
while ( v9 != v5 );
LABEL_14:
v2 += 16;
v5 += 16;
v3 += 16;
result = putchar(10);
}
while ( v2 != v12 );
}
return result;
}

original_code:
void
dump (void *buf, int n)
{
 int i;
 int j;
 int c;
 for (i = 0; i < n; i += 16) {
  printf ("%04x: ", i);
  for (j = 0; j < 16; j++) {
   if (i+j < n)
    printf ("%02x ", ((unsigned char *)buf)[i+j]);
   else
    printf ("   ");
  }
  printf ("  ");
  for (j = 0; j < 16; j++) {
   c = ((unsigned char *)buf)[i+j] & 0x7f;
   if (i+j >= n)
    putchar (' ');
   else if (c < ' ' || c == 0x7f)
    putchar ('.');
   else
    putchar (c);
  }
  printf ("\n");
 }
}

canonical_original_code:
void dump(void *buf, int n)
{
 int i;
 int j;
 int c;
 for (i = 0; i < n; i += 16) {
  printf ("%04x: ", i);
  for (j = 0; j < 16; j++) {
   if (i+j < n)
    printf ("%02x ", ((unsigned char *)buf)[i+j]);
   else
    printf ("   ");
  }
  printf ("  ");
  for (j = 0; j < 16; j++) {
   c = ((unsigned char *)buf)[i+j] & 0x7f;
   if (i+j >= n)
    putchar (' ');
   else if (c < ' ' || c == 0x7f)
    putchar ('.');
   else
    putchar (c);
  }
  printf ("\n");
 }
}

variable_types:
buf
void *

variable_types: n int

variable_types: i int

variable_types: j int


decompiled_code:
void __fastcall print_bank0(__int64 a1, int a2)
{
int v2; // er14
int v3; // ebp
struct tm *v4; // rax
__int64 v5; // rax
unsigned __int8 *v6; // r15
int v7; // ecx
unsigned __int8 *v8; // r13
int v9; // eax
struct tm *v10; // rax
unsigned int v11; // er15
unsigned int v12; // er13
double v13; // [rsp+0h] [rbp-58h]
unsigned __int8 *v14; // [rsp+8h] [rbp-50h]
time_t timer; // [rsp+10h] [rbp-48h] BYREF
time_t v16; // [rsp+18h] [rbp-40h] BYREF

timer = 0LL;
if ( a2 > 0 )
{
v2 = 0;
v3 = 0;
do
{
while ( 1 )
{
v5 = v3;
v6 = (unsigned __int8 *)(a1 + v3 + 2);
v7 = *(unsigned __int8 *)(a1 + v3);
v8 = (unsigned __int8 *)(a1 + v3 + 1);
if ( (v7 & 0x80u) != 0 )
break;
v3 += 4;
v2 = 0;
timer = (*v8 << 16) | (*v6 << 8) | (v7 << 24) | *(unsigned __int8 *)(a1 + v5 + 3);
v4 = localtime(&timer);
printf(
"Time: %d-%02d-%02d %02d:%02d:%02d\n",
(unsigned int)(v4->tm_year + 1900),
(unsigned int)(v4->tm_mon + 1),
(unsigned int)v4->tm_mday,
(unsigned int)v4->tm_hour,
(unsigned int)v4->tm_min,
(unsigned int)v4->tm_sec);
if ( v3 >= a2 )
return;
}
v9 = 60 * v2;
v14 = (unsigned __int8 *)(a1 + v3);
v3 += 3;
++v2;
v16 = timer + v9;
v10 = localtime(&v16);
v13 = (double)(*v8 - 10) / 10.0;
v11 = *v6;
v12 = *v14 - 129;
printf(
"%04d-%02d-%02d %02d:%02d:%02d ",
(unsigned int)(v10->tm_year + 1900),
(unsigned int)(v10->tm_mon + 1),
(unsigned int)v10->tm_mday,
(unsigned int)v10->tm_hour,
(unsigned int)v10->tm_min,
(unsigned int)v10->tm_sec);
printf("unk %d; active %g; steps %d\n", v12, v13, v11);
}
while ( v3 < a2 );
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
int v2; // er14
int v3; // ebp
struct tm *v4; // rax
__int64 v5; // rax
unsigned __int8 *v6; // r15
int v7; // ecx
unsigned __int8 *v8; // r13
int v9; // eax
struct tm *v10; // rax
unsigned int v11; // er15
unsigned int v12; // er13
double v13; // [rsp+0h] [rbp-58h]
unsigned __int8 *v14; // [rsp+8h] [rbp-50h]
time_t timer; // [rsp+10h] [rbp-48h] BYREF
time_t v16; // [rsp+18h] [rbp-40h] BYREF

timer = 0LL;
if ( a2 > 0 )
{
v2 = 0;
v3 = 0;
do
{
while ( 1 )
{
v5 = v3;
v6 = (unsigned __int8 *)(a1 + v3 + 2);
v7 = *(unsigned __int8 *)(a1 + v3);
v8 = (unsigned __int8 *)(a1 + v3 + 1);
if ( (v7 & 0x80u) != 0 )
break;
v3 += 4;
v2 = 0;
timer = (*v8 << 16) | (*v6 << 8) | (v7 << 24) | *(unsigned __int8 *)(a1 + v5 + 3);
v4 = localtime(&timer);
printf(
"Time: %d-%02d-%02d %02d:%02d:%02d\n",
(unsigned int)(v4->tm_year + 1900),
(unsigned int)(v4->tm_mon + 1),
(unsigned int)v4->tm_mday,
(unsigned int)v4->tm_hour,
(unsigned int)v4->tm_min,
(unsigned int)v4->tm_sec);
if ( v3 >= a2 )
return;
}
v9 = 60 * v2;
v14 = (unsigned __int8 *)(a1 + v3);
v3 += 3;
++v2;
v16 = timer + v9;
v10 = localtime(&v16);
v13 = (double)(*v8 - 10) / 10.0;
v11 = *v6;
v12 = *v14 - 129;
printf(
"%04d-%02d-%02d %02d:%02d:%02d ",
(unsigned int)(v10->tm_year + 1900),
(unsigned int)(v10->tm_mon + 1),
(unsigned int)v10->tm_mday,
(unsigned int)v10->tm_hour,
(unsigned int)v10->tm_min,
(unsigned int)v10->tm_sec);
printf("unk %d; active %g; steps %d\n", v12, v13, v11);
}
while ( v3 < a2 );
}
}

original_code:
void
print_bank0 (unsigned char *data, int len)
{
 int i;
 time_t last_date_time, record_date;
 int time_index;
 struct tm tm;
 int steps, not_sure;
 double active_score;
 i = 0;
 last_date_time = 0;
 time_index = 0;
 while (i < len) {
  if ((data[i] & 0x80) == 0) {
   last_date_time = data[i+3]
    | (data[i+2]<<8)
    | (data[i+1]<<16)
    | (data[i]<<24);
   tm = *localtime (&last_date_time);
   printf ("Time: %d-%02d-%02d %02d:%02d:%02d\n",
    tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
    tm.tm_hour, tm.tm_min, tm.tm_sec);
   i += 4;
   time_index = 0;
  } else {
   record_date = last_date_time + 60 * time_index;
   tm = *localtime (&record_date);
   steps = data[i+2];
   active_score = (data[i+1] - 10) / 10.0;
   not_sure = data[i] - 0x81;
   printf ("%04d-%02d-%02d %02d:%02d:%02d ",
    tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
    tm.tm_hour, tm.tm_min, tm.tm_sec);
   printf ("unk %d; active %g; steps %d\n",
    not_sure, active_score, steps);
   i += 3;
   time_index++;
  }
 }
}

canonical_original_code:
void print_bank0(unsigned char *data, int len)
{
 int i;
 long last_date_time; long record_date;
 int time_index;
 struct tm tm;
 int steps; int not_sure;
 double active_score;
 i = 0;
 last_date_time = 0;
 time_index = 0;
 while (i < len) {
  if ((data[i] & 0x80) == 0) {
   last_date_time = data[i+3]
    | (data[i+2]<<8)
    | (data[i+1]<<16)
    | (data[i]<<24);
   tm = *localtime (&last_date_time);
   printf ("Time: %d-%02d-%02d %02d:%02d:%02d\n",
    tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
    tm.tm_hour, tm.tm_min, tm.tm_sec);
   i += 4;
   time_index = 0;
  } else {
   record_date = last_date_time + 60 * time_index;
   tm = *localtime (&record_date);
   steps = data[i+2];
   active_score = (data[i+1] - 10) / 10.0;
   not_sure = data[i] - 0x81;
   printf ("%04d-%02d-%02d %02d:%02d:%02d ",
    tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
    tm.tm_hour, tm.tm_min, tm.tm_sec);
   printf ("unk %d; active %g; steps %d\n",
    not_sure, active_score, steps);
   i += 3;
   time_index++;
  }
 }
}

variable_types:
data
unsigned char *

variable_types: len int

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

variable_types: steps int


decompiled_code:
int __fastcall print_bank2(__int64 a1, int a2)
{
int v2; // er13
unsigned __int8 *v4; // rbp
int i; // er12
int v6; // eax
unsigned __int8 *v7; // rbx
struct tm *v8; // rax
__int64 v9; // rsi
int result; // eax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

puts("bank2");
if ( a2 <= 14 )
{
result = 0;
}
else
{
v4 = (unsigned __int8 *)(a1 + 15);
for ( i = 0; ; i += 15 )
{
v6 = *(_DWORD *)(v4 - 15);
v7 = v4 - 11;
timer = v6;
if ( !i )
v2 = v6;
v8 = localtime(&timer);
printf(
"%04d-%02d-%02d %02d:%02d:%02d (%8.3f) ",
(unsigned int)(v8->tm_year + 1900),
(unsigned int)(v8->tm_mon + 1),
(unsigned int)v8->tm_mday,
(unsigned int)v8->tm_hour,
(unsigned int)v8->tm_min,
(unsigned int)v8->tm_sec,
(double)((int)timer - v2) / 3600.0);
do
{
while ( 1 )
{
v9 = *v7++;
if ( (_DWORD)v9 )
break;
printf(" %2s", ".");
if ( v4 == v7 )
goto LABEL_9;
}
printf(" %02x", v9);
}
while ( v4 != v7 );
LABEL_9:
v4 += 15;
putchar(10);
result = i + 15;
if ( i + 29 >= a2 )
break;
}
}
if ( a2 != result )
result = printf("dregs %d\n", (unsigned int)(a2 - result));
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, int a2)
{
int v2; // er13
unsigned __int8 *v4; // rbp
int i; // er12
int v6; // eax
unsigned __int8 *v7; // rbx
struct tm *v8; // rax
__int64 v9; // rsi
int result; // eax
time_t timer; // [rsp+8h] [rbp-30h] BYREF

puts("bank2");
if ( a2 <= 14 )
{
result = 0;
}
else
{
v4 = (unsigned __int8 *)(a1 + 15);
for ( i = 0; ; i += 15 )
{
v6 = *(_DWORD *)(v4 - 15);
v7 = v4 - 11;
timer = v6;
if ( !i )
v2 = v6;
v8 = localtime(&timer);
printf(
"%04d-%02d-%02d %02d:%02d:%02d (%8.3f) ",
(unsigned int)(v8->tm_year + 1900),
(unsigned int)(v8->tm_mon + 1),
(unsigned int)v8->tm_mday,
(unsigned int)v8->tm_hour,
(unsigned int)v8->tm_min,
(unsigned int)v8->tm_sec,
(double)((int)timer - v2) / 3600.0);
do
{
while ( 1 )
{
v9 = *v7++;
if ( (_DWORD)v9 )
break;
printf(" %2s", ".");
if ( v4 == v7 )
goto LABEL_9;
}
printf(" %02x", v9);
}
while ( v4 != v7 );
LABEL_9:
v4 += 15;
putchar(10);
result = i + 15;
if ( i + 29 >= a2 )
break;
}
}
if ( a2 != result )
result = printf("dregs %d\n", (unsigned int)(a2 - result));
return result;
}

original_code:
void
print_bank2 (unsigned char *rbuf, int n)
{
 int off;
 unsigned char *up;
 time_t start;
 time_t t;
 struct tm tm;
 int i;
 int val;
 printf ("bank2\n");
 off = 0;
 while (off + 15 <= n) {
  up = rbuf + off;
  t = up[0] | (up[1] << 8) | (up[2] << 16) | (up[3] << 24);
  if (off == 0)
   start = t;
  up += 4;
  tm = *localtime (&t);
  printf ("%04d-%02d-%02d %02d:%02d:%02d (%8.3f) ",
   tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
   tm.tm_hour, tm.tm_min, tm.tm_sec,
   (t - start) / 3600.0);
  for (i = 0; i < 11; i++) {
   val = *up++;
   if (val == 0)
    printf (" %2s", ".");
   else
    printf (" %02x", val);
  }
  printf ("\n");
  off += 15;
 }
 if (off != n)
  printf ("dregs %d\n", n - off);
}

canonical_original_code:
void print_bank2(unsigned char *rbuf, int n)
{
 int off;
 unsigned char *up;
 long start;
 long t;
 struct tm tm;
 int i;
 int val;
 printf ("bank2\n");
 off = 0;
 while (off + 15 <= n) {
  up = rbuf + off;
  t = up[0] | (up[1] << 8) | (up[2] << 16) | (up[3] << 24);
  if (off == 0)
   start = t;
  up += 4;
  tm = *localtime (&t);
  printf ("%04d-%02d-%02d %02d:%02d:%02d (%8.3f) ",
   tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
   tm.tm_hour, tm.tm_min, tm.tm_sec,
   (t - start) / 3600.0);
  for (i = 0; i < 11; i++) {
   val = *up++;
   if (val == 0)
    printf (" %2s", ".");
   else
    printf (" %02x", val);
  }
  printf ("\n");
  off += 15;
 }
 if (off != n)
  printf ("dregs %d\n", n - off);
}

variable_types:
rbuf
unsigned char *

variable_types: off int

variable_types:
up
unsigned char *

variable_types: start long

variable_types: t long

variable_types: val int

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
FILE *v4; // rax
FILE *v5; // rbp
char *v6; // rbx
char *i; // r12
__int64 v8; // rax
unsigned int v10; // [rsp+8h] [rbp-450h] BYREF
int v11; // [rsp+Ch] [rbp-44Ch] BYREF
struct tm tp; // [rsp+10h] [rbp-448h] BYREF
char s[1032]; // [rsp+50h] [rbp-408h] BYREF

if ( getopt(argc, (char *const *)argv, &shortopts) != -1
|| optind >= argc
|| (v3 = argv[optind], ++optind, optind != argc) )
{
usage();
}
v4 = fopen(v3, "r");
v5 = v4;
if ( !v4 )
{
fprintf(stderr, "can't open %s\n", v3);
exit(1);
}
if ( !fgets(s, 1000, v4) )
{
fwrite("unexpected EOF\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
tp.tm_zone = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 0LL;
if ( (unsigned int)_isoc99_sscanf(
s,
"fitbit-log-%d-%d-%d-%2d%2d%2d",
&tp.tm_year,
&tp.tm_mon,
&tp.tm_mday,
&tp.tm_hour,
&tp.tm_min,
&tp) != 6 )
{
fwrite("bad file format\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
--tp.tm_mon;
v6 = 0LL;
tp.tm_year -= 1900;
tp.tm_isdst = -1;
file_timestamp = mktime(&tp);
LABEL_8:
while ( fgets(s, 1000, v5) )
{
if ( (unsigned int)_isoc99_sscanf(s, "bank%d", &v10) != 1 )
{
for ( i = s; ; i += 2 )
{
if ( (unsigned int)_isoc99_sscanf(i, "%2x", &v11) != 1 )
goto LABEL_8;
v8 = *(int *)((char *)&dword_19000 + (_QWORD)v6);
if ( (unsigned int)v8 > (unsigned int)&unk_18FFF )
break;
*(int *)((char *)&dword_19000 + (_QWORD)v6) = v8 + 1;
v6[v8] = v11;
}
fprintf(stderr, "bank %d overflow\n", 0xA11D1BDE70F9C01LL * ((v6 - (char *)&banks) >> 2));
LABEL_17:
exit(1);
}
if ( v10 > 9 )
{
fprintf(stderr, "invalid banknum %d\n", v10);
goto LABEL_17;
}
v6 = (char *)&banks + 102404 * (int)v10;
}
process_bank0((__int64)&banks, *((_DWORD *)&banks + 25600));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
FILE *v4; // rax
FILE *v5; // rbp
char *v6; // rbx
char *i; // r12
__int64 v8; // rax
unsigned int v10; // [rsp+8h] [rbp-450h] BYREF
int v11; // [rsp+Ch] [rbp-44Ch] BYREF
struct tm tp; // [rsp+10h] [rbp-448h] BYREF
char s[1032]; // [rsp+50h] [rbp-408h] BYREF

if ( getopt(argc, (char *const *)argv, &shortopts) != -1
|| optind >= argc
|| (v3 = argv[optind], ++optind, optind != argc) )
{
func1();
}
v4 = fopen(v3, "r");
v5 = v4;
if ( !v4 )
{
fprintf(stderr, "can't open %s\n", v3);
exit(1);
}
if ( !fgets(s, 1000, v4) )
{
fwrite("unexpected EOF\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
tp.tm_zone = 0LL;
*(_OWORD *)&tp.tm_sec = 0LL;
*(_OWORD *)&tp.tm_mon = 0LL;
*(_OWORD *)&tp.tm_isdst = 0LL;
if ( (unsigned int)_isoc99_sscanf(
s,
"fitbit-log-%d-%d-%d-%2d%2d%2d",
&tp.tm_year,
&tp.tm_mon,
&tp.tm_mday,
&tp.tm_hour,
&tp.tm_min,
&tp) != 6 )
{
fwrite("bad file format\n", 1uLL, 0x10uLL, stderr);
exit(1);
}
--tp.tm_mon;
v6 = 0LL;
tp.tm_year -= 1900;
tp.tm_isdst = -1;
file_timestamp = mktime(&tp);
LABEL_8:
while ( fgets(s, 1000, v5) )
{
if ( (unsigned int)_isoc99_sscanf(s, "bank%d", &v10) != 1 )
{
for ( i = s; ; i += 2 )
{
if ( (unsigned int)_isoc99_sscanf(i, "%2x", &v11) != 1 )
goto LABEL_8;
v8 = *(int *)((char *)&dword_19000 + (_QWORD)v6);
if ( (unsigned int)v8 > (unsigned int)&unk_18FFF )
break;
*(int *)((char *)&dword_19000 + (_QWORD)v6) = v8 + 1;
v6[v8] = v11;
}
fprintf(stderr, "bank %d overflow\n", 0xA11D1BDE70F9C01LL * ((v6 - (char *)&banks) >> 2));
LABEL_17:
exit(1);
}
if ( v10 > 9 )
{
fprintf(stderr, "invalid banknum %d\n", v10);
goto LABEL_17;
}
v6 = (char *)&banks + 102404 * (int)v10;
}
func2((__int64)&banks, *((_DWORD *)&banks + 25600));
return 0;
}

original_code:
int
main (int argc, char **argv)
{
 int c;
 int rc;
 unsigned char rbuf[10000];
 int n;
 char filename[1000];
 time_t t;
 struct tm tm;
 char cmd[1000];
 if (0) {
  print_bank1 (bank1ref, sizeof bank1ref);
  exit (0);
 }
 while ((c = getopt (argc, argv, "xv")) != (-1)) {
  switch (c) {
  case 'v':
   vflag = 1;
   break;
  case 'x':
   xflag = 1;
   break;
  default:
   usage ();
  }
 }
 if (optind < argc)
  intarg = atoi (argv[optind++]);
 if (optind != argc)
  usage ();
 signal (14, intr);
 alarm (14 * 60);
 t = time (((void *)0));
 tm = *localtime (&t);
 sprintf (filename, "fitbit-log-%04d-%02d-%02d-%02d%02d%02d",
   tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
   tm.tm_hour, tm.tm_min, tm.tm_sec);
 if (libusb_init (&ctx) != 0) {
  fprintf (stderr, "libusb_init error\n");
  exit (1);
 }
 libusb_set_debug (ctx, 3);
 dev = libusb_open_device_with_vid_pid (ctx, 0x10c4, 0x84c4);
 device = libusb_get_device (dev);
 if ((rc = libusb_get_device_descriptor (device, &desc)) != 0)
  die ("get_desc", rc);
 if (0) {
  printf ("bLength = %d\n", desc.bLength);
  printf ("bDescriptorType = %d\n", desc.bDescriptorType);
  printf ("bcdUSB = 0x%x\n", desc.bcdUSB);
  printf ("bDeviceClass = %d\n", desc.bDeviceClass);
  printf ("bDeviceSubClass = %d\n", desc.bDeviceSubClass);
  printf ("bDeviceProtocol = %d\n", desc.bDeviceProtocol);
  printf ("bMaxPacketSize0 = %d\n", desc.bMaxPacketSize0);
  printf ("idVendor = 0x%x\n", desc.idVendor);
  printf ("idProduct = 0x%x\n", desc.idProduct);
  printf ("bcdDevice = 0x%x\n", desc.bcdDevice);
  printf ("iManufacturer = %d\n", desc.iManufacturer);
  printf ("iProduct = %d\n", desc.iProduct);
  printf ("iSerialNumber = %d\n", desc.iSerialNumber);
  printf ("bNumConfigurations = %d\n", desc.bNumConfigurations);
 }
 if ((rc = libusb_set_configuration (dev, -1)) != 0)
  die ("set_config", rc);
 if ((rc = libusb_set_configuration (dev, 1)) != 0)
  die ("set_config", rc);
 if ((rc = libusb_claim_interface (dev, 0)) != 0)
  die ("claim", rc);
 dbg ("*** fitbit_ant_init\n");
 fitbit_ant_init ();
 init_tracker_for_transfer ();
 get_tracker_info ();
 if ((outf = fopen (filename, "w")) == ((void *)0)) {
  fprintf (stderr, "can't create %s\n", filename);
  exit (1);
 }
 fprintf (outf, "%s\n", filename);
 n = run_data_bank_opcode (0, rbuf, sizeof rbuf);
 print_bank0 (rbuf, n);
 output_bank (0, rbuf, n);
 n = run_data_bank_opcode (1, rbuf, sizeof rbuf);
 print_bank1 (rbuf, n);
 output_bank (1, rbuf, n);
 n = run_data_bank_opcode (2, rbuf, sizeof rbuf);
 print_bank2 (rbuf, n);
 output_bank (2, rbuf, n);
 dbg ("resetting\n");
 if ((rc = libusb_reset_device (dev)) != 0)
  die ("libusb_reset_device", rc);
 fclose (outf);
 sprintf (cmd, "./parsedata %s", filename);
 dbg ("running: %s\n", cmd);
 rc = system (cmd);
 if (rc)
  dbg ("error: 0x%x\n", rc);
 dbg ("ok\n");
 return (0);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int c;
 int rc;
 unsigned char rbuf[10000];
 int n;
 char filename[1000];
 long t;
 struct tm tm;
 char cmd[1000];
 if (0) {
  print_bank1 (bank1ref, sizeof bank1ref);
  exit (0);
 }
 while ((c = getopt (argc, argv, "xv")) != (-1)) {
  switch (c) {
  case 'v':
   vflag = 1;
   break;
  case 'x':
   xflag = 1;
   break;
  default:
   usage ();
  }
 }
 if (optind < argc)
  intarg = atoi (argv[optind++]);
 if (optind != argc)
  usage ();
 signal (14, intr);
 alarm (14 * 60);
 t = time (((void *)0));
 tm = *localtime (&t);
 sprintf (filename, "fitbit-log-%04d-%02d-%02d-%02d%02d%02d",
   tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
   tm.tm_hour, tm.tm_min, tm.tm_sec);
 if (libusb_init (&ctx) != 0) {
  fprintf (stderr, "libusb_init error\n");
  exit (1);
 }
 libusb_set_debug (ctx, 3);
 dev = libusb_open_device_with_vid_pid (ctx, 0x10c4, 0x84c4);
 device = libusb_get_device (dev);
 if ((rc = libusb_get_device_descriptor (device, &desc)) != 0)
  die ("get_desc", rc);
 if (0) {
  printf ("bLength = %d\n", desc.bLength);
  printf ("bDescriptorType = %d\n", desc.bDescriptorType);
  printf ("bcdUSB = 0x%x\n", desc.bcdUSB);
  printf ("bDeviceClass = %d\n", desc.bDeviceClass);
  printf ("bDeviceSubClass = %d\n", desc.bDeviceSubClass);
  printf ("bDeviceProtocol = %d\n", desc.bDeviceProtocol);
  printf ("bMaxPacketSize0 = %d\n", desc.bMaxPacketSize0);
  printf ("idVendor = 0x%x\n", desc.idVendor);
  printf ("idProduct = 0x%x\n", desc.idProduct);
  printf ("bcdDevice = 0x%x\n", desc.bcdDevice);
  printf ("iManufacturer = %d\n", desc.iManufacturer);
  printf ("iProduct = %d\n", desc.iProduct);
  printf ("iSerialNumber = %d\n", desc.iSerialNumber);
  printf ("bNumConfigurations = %d\n", desc.bNumConfigurations);
 }
 if ((rc = libusb_set_configuration (dev, -1)) != 0)
  die ("set_config", rc);
 if ((rc = libusb_set_configuration (dev, 1)) != 0)
  die ("set_config", rc);
 if ((rc = libusb_claim_interface (dev, 0)) != 0)
  die ("claim", rc);
 dbg ("*** fitbit_ant_init\n");
 fitbit_ant_init ();
 init_tracker_for_transfer ();
 get_tracker_info ();
 if ((outf = fopen (filename, "w")) == ((void *)0)) {
  fprintf (stderr, "can't create %s\n", filename);
  exit (1);
 }
 fprintf (outf, "%s\n", filename);
 n = run_data_bank_opcode (0, rbuf, sizeof rbuf);
 print_bank0 (rbuf, n);
 output_bank (0, rbuf, n);
 n = run_data_bank_opcode (1, rbuf, sizeof rbuf);
 print_bank1 (rbuf, n);
 output_bank (1, rbuf, n);
 n = run_data_bank_opcode (2, rbuf, sizeof rbuf);
 print_bank2 (rbuf, n);
 output_bank (2, rbuf, n);
 dbg ("resetting\n");
 if ((rc = libusb_reset_device (dev)) != 0)
  die ("libusb_reset_device", rc);
 fclose (outf);
 sprintf (cmd, "./parsedata %s", filename);
 dbg ("running: %s\n", cmd);
 rc = system (cmd);
 if (rc)
  dbg ("error: 0x%x\n", rc);
 dbg ("ok\n");
 return (0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: rc int

variable_types:
rbuf
unsigned char [10000]

variable_types:
filename
char [1000]

variable_types:
cmd
char [1000]


repo: padawin/Conqueror

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // bl
void *v4; // rbp
unsigned __int8 v6; // [rsp+Dh] [rbp-3Bh] BYREF
unsigned __int16 v7; // [rsp+Eh] [rbp-3Ah] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

game_select_map(v8, &v6, &v7);
v3 = v6;
v4 = calloc(v6, 0x44uLL);
game_select_players(v8, v4, v3, v7);
game_start(v8);
free_board(v8);
free(v4);
return 0;
}

original_code:
int main()
{
 s_board b;
 uint8_t nb_players_max;
 uint16_t nb_pawns_per_player;
 s_player *players;
 game_select_map(&b, &nb_players_max, &nb_pawns_per_player);
 players = calloc((size_t) nb_players_max, sizeof(s_player));
 game_select_players(&b, players, nb_players_max, nb_pawns_per_player);
 game_start(&b);
 free_board(&b);
 free(players);
 return 0;
}

canonical_original_code:
int main()
{
 struct s_board b;
 unsigned char nb_players_max;
 unsigned short nb_pawns_per_player;
 struct s_player *players;
 game_select_map(&b, &nb_players_max, &nb_pawns_per_player);
 players = calloc((unsigned long) nb_players_max, sizeof(s_player));
 game_select_players(&b, players, nb_players_max, nb_pawns_per_player);
 game_start(&b);
 free_board(&b);
 free(players);
 return 0;
}

variable_types: struct s_board { struct s_player { char name[50]; int id; unsigned char nb_cells; unsigned short nb_pawns; int strategy; int is_human; } **players; struct s_cell { struct s_player *owner; struct s_cell **neighbours; int id; unsigned short nb_pawns; unsigned char nb_neighbours; unsigned char nb_max_neighbours; } *cells; unsigned char nb_cells; unsigned char nb_players; unsigned char nb_total_players; }

user_defined_types: struct s_board { struct s_player **players; struct s_cell *cells; unsigned char nb_cells; unsigned char nb_players; unsigned char nb_total_players; }


decompiled_code:
__int64 __fastcall utils_get_random_int(int a1, int a2)
{
int v2; // ebp
unsigned int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = open("/dev/urandom", 0);
read(v2, buf, 4uLL);
buf[0] = a1 + buf[0] % (a2 - a1);
close(v2);
return buf[0];
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
int v2; // ebp
unsigned int buf[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = open("/dev/urandom", 0);
read(v2, buf, 4uLL);
buf[0] = a1 + buf[0] % (a2 - a1);
close(v2);
return buf[0];
}

original_code:
unsigned int utils_get_random_int(unsigned int min, unsigned int max)
{
 int randomData = open("/dev/urandom", 00);
 unsigned int rInt;
 read(randomData, &rInt, sizeof rInt);
 rInt = rInt % (max - min) + min;
 close(randomData);
 return rInt;
}

variable_types:
min
unsigned int

variable_types:
max
unsigned int

variable_types: randomData int

variable_types:
rInt
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall utils_get_line(const char *a1, char *a2, int a3)
{
char *v4; // rax
unsigned int v5; // er12
__int64 result; // rax
int v7; // eax

if ( a1 )
{
printf("%s", a1);
fflush(stdout);
}
if ( !fgets(a2, a3, stdin) )
return 1LL;
v4 = &a2[strlen(a2) - 1];
v5 = 0;
if ( *v4 == 10 )
{
*v4 = 0;
result = 0LL;
}
else
{
while ( 1 )
{
v7 = getchar();
if ( v7 == -1 || v7 == 10 )
break;
v5 = 1;
}
if ( v5 == 1 )
v5 = 2;
result = v5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, char *a2, int a3)
{
char *v4; // rax
unsigned int v5; // er12
__int64 result; // rax
int v7; // eax

if ( a1 )
{
printf("%s", a1);
fflush(stdout);
}
if ( !fgets(a2, a3, stdin) )
return 1LL;
v4 = &a2[strlen(a2) - 1];
v5 = 0;
if ( *v4 == 10 )
{
*v4 = 0;
result = 0LL;
}
else
{
while ( 1 )
{
v7 = getchar();
if ( v7 == -1 || v7 == 10 )
break;
v5 = 1;
}
if ( v5 == 1 )
v5 = 2;
result = v5;
}
return result;
}

original_code:
int utils_get_line(const char *prmpt, char *buff, size_t sz)
{
 int ch, extra;
 if (prmpt != ((void *)0)) {
  printf("%s", prmpt);
  fflush(stdout);
 }
 if (fgets(buff, (int) sz, stdin) == ((void *)0))
  return 1;
 if (buff[strlen(buff)-1] != '\n') {
  extra = 0;
  while (((ch = getchar()) != '\n') && (ch != (-1)))
   extra = 1;
  return (extra == 1) ? 2 : 0;
 }
 buff[strlen(buff)-1] = '\0';
 return 0;
}

canonical_original_code:
int utils_get_line(char *prmpt, char *buff, unsigned long sz)
{
 int ch; int extra;
 if (prmpt != ((void *)0)) {
  printf("%s", prmpt);
  fflush(stdout);
 }
 if (fgets(buff, (int) sz, stdin) == ((void *)0))
  return 1;
 if (buff[strlen(buff)-1] != '\n') {
  extra = 0;
  while (((ch = getchar()) != '\n') && (ch != (-1)))
   extra = 1;
  return (extra == 1) ? 2 : 0;
 }
 buff[strlen(buff)-1] = '\0';
 return 0;
}

variable_types:
prmpt
char *

variable_types:
buff
char *

variable_types:
sz
unsigned long

variable_types: ch int

variable_types: extra int


original_code:
int init_player(
 s_player *p,
 const int id,
 const char *name,
 const short is_human,
 const int strategy,
 const uint16_t nb_pawns
)
{
 if (name[0] == '\0')
  return -1;
 if (
  (is_human && strategy != 0)
  || (!is_human && strategy != 1 && strategy != 2)
 )
  return -2;
 if (nb_pawns < 1)
  return -3;
 p->nb_pawns = nb_pawns;
 p->strategy = strategy;
 p->id = id;
 strncpy(p->name, name, 50);
 p->is_human = is_human;
 p->nb_cells = 0;
 return 1;
}

canonical_original_code:
int init_player(struct s_player *p, int id, char *name, short is_human, int strategy, unsigned short nb_pawns)
{
 if (name[0] == '\0')
  return -1;
 if (
  (is_human && strategy != 0)
  || (!is_human && strategy != 1 && strategy != 2)
 )
  return -2;
 if (nb_pawns < 1)
  return -3;
 p->nb_pawns = nb_pawns;
 p->strategy = strategy;
 p->id = id;
 strncpy(p->name, name, 50);
 p->is_human = is_human;
 p->nb_cells = 0;
 return 1;
}

variable_types: struct s_player { char name[50]; int id; unsigned char nb_cells; unsigned short nb_pawns; int strategy; int is_human; } *

variable_types: id int

variable_types:
name
char *

variable_types: strategy int


decompiled_code:
__int64 __fastcall player_select_cell_to_leave(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 64) )
result = human_select_cell_to_leave(a2, a3);
else
result = ai_select_cell_to_leave(a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

if ( *(_DWORD *)(a1 + 64) )
result = human_select_cell_to_leave(a2, a3);
else
result = ai_select_cell_to_leave(a2, a3);
return result;
}

original_code:
int player_select_cell_to_leave(s_player *p, struct s_cell **player_cells, int nb_cells)
{
 int cell_id;
 if (p->is_human) {
  cell_id = human_select_cell_to_leave(player_cells, nb_cells);
 }
 else {
  cell_id = ai_select_cell_to_leave(player_cells, nb_cells);
 }
 return cell_id;
}

canonical_original_code:
int player_select_cell_to_leave(struct s_player *p, struct s_cell **player_cells, int nb_cells)
{
 int cell_id;
 if (p->is_human) {
  cell_id = human_select_cell_to_leave(player_cells, nb_cells);
 }
 else {
  cell_id = ai_select_cell_to_leave(player_cells, nb_cells);
 }
 return cell_id;
}

variable_types: struct s_cell { struct s_player *owner; struct s_cell **neighbours; int id; unsigned short nb_pawns; unsigned char nb_neighbours; unsigned char nb_max_neighbours; } **

user_defined_types: struct s_player { char name[50]; int id; unsigned char nb_cells; unsigned short nb_pawns; int strategy; int is_human; }


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

if ( *(_DWORD *)(a1 + 64) )
result = human_select_cell_to_go_to(a2);
else
result = ai_select_cell_to_go_to(a2);
return result;
}

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

if ( *(_DWORD *)(a1 + 64) )
result = human_select_cell_to_go_to(a2);
else
result = ai_select_cell_to_go_to(a2);
return result;
}

original_code:
struct s_cell *player_select_cell_to_go_to(s_player *p, struct s_cell *src_cell)
{
 struct s_cell *dst_cell;
 if (p->is_human) {
  dst_cell = human_select_cell_to_go_to(src_cell);
 }
 else {
  dst_cell = ai_select_cell_to_go_to(src_cell);
 }
 return dst_cell;
}

canonical_original_code:
struct s_cell *player_select_cell_to_go_to(struct s_player *p, struct s_cell *src_cell)
{
 struct s_cell *dst_cell;
 if (p->is_human) {
  dst_cell = human_select_cell_to_go_to(src_cell);
 }
 else {
  dst_cell = ai_select_cell_to_go_to(src_cell);
 }
 return dst_cell;
}

variable_types:
p
struct s_player *

variable_types: struct s_cell { struct s_player { char name[50]; int id; unsigned char nb_cells; unsigned short nb_pawns; int strategy; int is_human; } *owner; struct s_cell **neighbours; int id; unsigned short nb_pawns; unsigned char nb_neighbours; unsigned char nb_max_neighbours; } *

user_defined_types: struct s_cell { struct s_player *owner; struct s_cell **neighbours; int id; unsigned short nb_pawns; unsigned char nb_neighbours; unsigned char nb_max_neighbours; }


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

if ( *(_DWORD *)(a1 + 64) )
result = human_select_nb_pawns(a2);
else
result = ai_select_nb_pawns(a2);
return result;
}

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

if ( *(_DWORD *)(a1 + 64) )
result = human_select_nb_pawns(a2);
else
result = ai_select_nb_pawns(a2);
return result;
}

original_code:
uint16_t player_select_nb_pawns(s_player *p, struct s_cell *src_cell)
{
 uint16_t nb_pawns;
 if (p->is_human) {
  nb_pawns = human_select_nb_pawns(src_cell);
 }
 else {
  nb_pawns = ai_select_nb_pawns(src_cell);
 }
 return nb_pawns;
}

canonical_original_code:
unsigned short player_select_nb_pawns(struct s_player *p, struct s_cell *src_cell)
{
 unsigned short nb_pawns;
 if (p->is_human) {
  nb_pawns = human_select_nb_pawns(src_cell);
 }
 else {
  nb_pawns = ai_select_nb_pawns(src_cell);
 }
 return nb_pawns;
}

variable_types: struct s_cell { struct s_player *owner; struct s_cell **neighbours; int id; unsigned short nb_pawns; unsigned char nb_neighbours; unsigned char nb_max_neighbours; } *

return_type: unsigned short


original_code:
short player_move_to_cell(s_player *p, uint16_t nb_pawns, struct s_cell *src_cell, struct s_cell *dst_cell)
{
 short result;
 if (nb_pawns > p->nb_pawns)
  return -3;
 else if (nb_pawns >= src_cell->nb_pawns)
  return -2;
 if (!cell_are_neighbours(src_cell, dst_cell)) {
  return -1;
 }
 if (dst_cell->owner != ((void *)0) && dst_cell->owner->id != p->id) {
  result = _fight(nb_pawns, dst_cell);
 }
 else {
  if (dst_cell->owner == ((void *)0)) {
   dst_cell->owner = p;
   p->nb_cells++;
  }
  dst_cell->nb_pawns = (uint16_t) (dst_cell->nb_pawns + nb_pawns);
  result = 0;
 }
 if (result != 3) {
  src_cell->nb_pawns = (uint16_t) (src_cell->nb_pawns - nb_pawns);
  if (result == 2) {
   p->nb_pawns = (uint16_t) (p->nb_pawns - nb_pawns);
  }
  else if (result == 1) {
   dst_cell->owner->nb_pawns = (uint16_t) (dst_cell->owner->nb_pawns - dst_cell->nb_pawns);
   dst_cell->owner->nb_cells--;
   dst_cell->owner = p;
   dst_cell->nb_pawns = nb_pawns;
   p->nb_cells = (uint8_t) (p->nb_cells + 1);
  }
 }
 return result;
}

canonical_original_code:
short player_move_to_cell(struct s_player *p, unsigned short nb_pawns, struct s_cell *src_cell, struct s_cell *dst_cell)
{
 short result;
 if (nb_pawns > p->nb_pawns)
  return -3;
 else if (nb_pawns >= src_cell->nb_pawns)
  return -2;
 if (!cell_are_neighbours(src_cell, dst_cell)) {
  return -1;
 }
 if (dst_cell->owner != ((void *)0) && dst_cell->owner->id != p->id) {
  result = _fight(nb_pawns, dst_cell);
 }
 else {
  if (dst_cell->owner == ((void *)0)) {
   dst_cell->owner = p;
   p->nb_cells++;
  }
  dst_cell->nb_pawns = (unsigned short) (dst_cell->nb_pawns + nb_pawns);
  result = 0;
 }
 if (result != 3) {
  src_cell->nb_pawns = (unsigned short) (src_cell->nb_pawns - nb_pawns);
  if (result == 2) {
   p->nb_pawns = (unsigned short) (p->nb_pawns - nb_pawns);
  }
  else if (result == 1) {
   dst_cell->owner->nb_pawns = (unsigned short) (dst_cell->owner->nb_pawns - dst_cell->nb_pawns);
   dst_cell->owner->nb_cells--;
   dst_cell->owner = p;
   dst_cell->nb_pawns = nb_pawns;
   p->nb_cells = (unsigned char) (p->nb_cells + 1);
  }
 }
 return result;
}

variable_types: result short

return_type: short


decompiled_code:
void __fastcall ui_list_cells(const char ***a1, int a2, __int16 a3)
{
__int64 v3; // r12
const char ***v5; // rbx
const char *v6; // rdx
const char **v7; // rax
__int64 v8; // rsi
__int64 v9; // rdx

if ( a2 > 0 )
{
v3 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v5 = a1;
do
{
while ( 1 )
{
v7 = *v5;
v8 = *((unsigned int *)*v5 + 4);
if ( a3 == 1 )
break;
v9 = *((unsigned __int16 *)*v5++ + 10);
printf("Cell %d: %d pawns\n", v8, v9);
if ( v5 == (const char ***)v3 )
return;
}
v6 = *v7;
if ( !*v7 )
v6 = "nobody";
++v5;
printf("Cell %d: owned by %s with %d pawns\n", v8, v6);
}
while ( v5 != (const char ***)v3 );
}
}

canonical_decompiled_code:
void __fastcall func0(const char ***a1, int a2, __int16 a3)
{
__int64 v3; // r12
const char ***v5; // rbx
const char *v6; // rdx
const char **v7; // rax
__int64 v8; // rsi
__int64 v9; // rdx

if ( a2 > 0 )
{
v3 = (__int64)&a1[(unsigned int)(a2 - 1) + 1];
v5 = a1;
do
{
while ( 1 )
{
v7 = *v5;
v8 = *((unsigned int *)*v5 + 4);
if ( a3 == 1 )
break;
v9 = *((unsigned __int16 *)*v5++ + 10);
printf("Cell %d: %d pawns\n", v8, v9);
if ( v5 == (const char ***)v3 )
return;
}
v6 = *v7;
if ( !*v7 )
v6 = "nobody";
++v5;
printf("Cell %d: owned by %s with %d pawns\n", v8, v6);
}
while ( v5 != (const char ***)v3 );
}
}

original_code:
void ui_list_cells(s_cell **cells, int nb_cells, short full_display)
{
 int c;
 for (c = 0; c < nb_cells; c++) {
  if (full_display == 1)
   printf(
    "Cell %d: owned by %s with %d pawns\n",
    cells[c]->id,
    cells[c]->owner == ((void *)0) ? "nobody" : cells[c]->owner->name,
    cells[c]->nb_pawns
   );
  else
   printf("Cell %d: %d pawns\n", cells[c]->id, cells[c]->nb_pawns);
 }
}

canonical_original_code:
void ui_list_cells(struct s_cell **cells, int nb_cells, short full_display)
{
 int c;
 for (c = 0; c < nb_cells; c++) {
  if (full_display == 1)
   printf(
    "Cell %d: owned by %s with %d pawns\n",
    cells[c]->id,
    cells[c]->owner == ((void *)0) ? "nobody" : cells[c]->owner->name,
    cells[c]->nb_pawns
   );
  else
   printf("Cell %d: %d pawns\n", cells[c]->id, cells[c]->nb_pawns);
 }
}

variable_types: struct s_cell { struct s_player { char name[50]; int id; unsigned char nb_cells; unsigned short nb_pawns; int strategy; int is_human; } *owner; struct s_cell **neighbours; int id; unsigned short nb_pawns; unsigned char nb_neighbours; unsigned char nb_max_neighbours; } **

variable_types: c int


decompiled_code:
// attributes: thunk
__int64 ui_prompt()
{
return utils_get_line();
}

canonical_decompiled_code:
__int64 func1()
{
return utils_get_line();
}

original_code:
void ui_prompt(const char *prompt, char *command, size_t command_size)
{
 utils_get_line(prompt, command, command_size);
}

canonical_original_code:
void ui_prompt(char *prompt, char *command, unsigned long command_size)
{
 utils_get_line(prompt, command, command_size);
}

variable_types:
prompt
char *

variable_types:
command
char *


decompiled_code:
int __fastcall ui_error(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func2(const char *a1)
{
return fprintf(stderr, "%s\n", a1);
}

original_code:
void ui_error(const char *msg)
{
 fprintf(stderr, "%s\n", msg);
}

canonical_original_code:
void ui_error(char *msg)
{
 fprintf(stderr, "%s\n", msg);
}

variable_types:
msg
char *


decompiled_code:
// attributes: thunk
int ui_info(const char *s)
{
return puts(s);
}

canonical_decompiled_code:
int func3(const char *s)
{
return puts(s);
}

original_code:
void ui_info(const char *msg)
{
 printf("%s\n", msg);
}

canonical_original_code:
void ui_info(char *msg)
{
 printf("%s\n", msg);
}


decompiled_code:
__int64 ai_select_cell_to_leave()
{
return 1LL;
}

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

original_code:
int ai_select_cell_to_leave(struct s_cell **player_cells, int nb_cells)
{
 return 1;
}


decompiled_code:
__int64 ai_select_cell_to_go_to()
{
return 0LL;
}

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

original_code:
struct s_cell *ai_select_cell_to_go_to(struct s_cell *src_cell)
{
 return ((void *)0);
}

return_type: struct s_cell { struct s_player { char name[50]; int id; unsigned char nb_cells; unsigned short nb_pawns; int strategy; int is_human; } *owner; struct s_cell **neighbours; int id; unsigned short nb_pawns; unsigned char nb_neighbours; unsigned char nb_max_neighbours; } *


decompiled_code:
__int64 ai_select_nb_pawns()
{
return 1LL;
}

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

original_code:
uint16_t ai_select_nb_pawns(struct s_cell *src_cell)
{
 return 1;
}

canonical_original_code:
unsigned short ai_select_nb_pawns(struct s_cell *src_cell)
{
 return 1;
}


decompiled_code:
__int64 __fastcall init_cell(__int64 a1, int a2, char a3)
{
unsigned __int8 v4; // dl

if ( !a3 )
return 0xFFFFFFFFLL;
v4 = a3 - 1;
*(_DWORD *)(a1 + 16) = a2;
*(_QWORD *)a1 = 0LL;
*(_WORD *)(a1 + 20) = 0;
*(_BYTE *)(a1 + 22) = 0;
*(_BYTE *)(a1 + 23) = v4;
*(_QWORD *)(a1 + 8) = calloc(v4, 8uLL);
return 1LL;
}

original_code:
int init_cell(s_cell *c, const int id, const uint8_t nb_cells)
{
 if (nb_cells < 1) {
  return -1;
 }
 c->id = id;
 c->owner = ((void *)0);
 c->nb_pawns = 0;
 c->nb_neighbours = 0;
 c->nb_max_neighbours = (uint8_t) (nb_cells - 1);
 c->neighbours = calloc((size_t) c->nb_max_neighbours, sizeof(s_cell*));
 return 1;
}

canonical_original_code:
int init_cell(struct s_cell *c, int id, unsigned char nb_cells)
{
 if (nb_cells < 1) {
  return -1;
 }
 c->id = id;
 c->owner = ((void *)0);
 c->nb_pawns = 0;
 c->nb_neighbours = 0;
 c->nb_max_neighbours = (unsigned char) (nb_cells - 1);
 c->neighbours = calloc((unsigned long) c->nb_max_neighbours, sizeof(struct s_cell *));
 return 1;
}


decompiled_code:
void __fastcall free_cell(__int64 a1)
{
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void free_cell(s_cell *c)
{
 free(c->neighbours);
 c->neighbours = ((void *)0);
}

canonical_original_code:
void free_cell(struct s_cell *c)
{
 free(c->neighbours);
 c->neighbours = ((void *)0);
}


decompiled_code:
void __fastcall cell_set_owner(_QWORD *a1, __int64 a2)
{
*a1 = a2;
++*(_BYTE *)(a2 + 56);
}

original_code:
void cell_set_owner(s_cell *c, struct s_player *owner)
{
 c->owner = owner;
 owner->nb_cells = (uint8_t) (owner->nb_cells + 1);
}

canonical_original_code:
void cell_set_owner(struct s_cell *c, struct s_player *owner)
{
 c->owner = owner;
 owner->nb_cells = (unsigned char) (owner->nb_cells + 1);
}

variable_types:
owner
struct s_player *