writeFlipDiscMatrixRow

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

for ( i = 0; i != 7; ++i )
{
v3 = a2;
if ( a1 )
{
do
{
if ( ((1 << i) & *v3) != 0 )
putchar(42);
else
putchar(46);
++v3;
}
while ( v3 != &a2[(unsigned __int8)(a1 - 1) + 1] );
}
result = putchar(10);
}
return result;
}

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

for ( i = 0; i != 7; ++i )
{
v3 = a2;
if ( a1 )
{
do
{
if ( ((1 << i) & *v3) != 0 )
putchar(42);
else
putchar(46);
++v3;
}
while ( v3 != &a2[(unsigned __int8)(a1 - 1) + 1] );
}
result = putchar(10);
}
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

return_type: void


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

v0 = u8g_sdl_get_key();
if ( v0 <= 0 )
return 0;
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; // edx

v0 = u8g_sdl_get_key();
if ( v0 <= 0 )
return 0;
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':
if ( !menu_current )
menu_current = 4;
--menu_current;
menu_redraw_required = 1;
break;
case 'q':
exit(0);
case 'n':
result = (unsigned int)(unsigned __int8)menu_current + 1;
if ( (unsigned __int8)(menu_current + 1) > 3u )
result = 0LL;
menu_current = result;
menu_redraw_required = 1;
break;
}
return result;
}

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

result = u8g_sdl_get_key();
switch ( (_DWORD)result )
{
case 'p':
if ( !menu_current )
menu_current = 4;
--menu_current;
menu_redraw_required = 1;
break;
case 'q':
exit(0);
case 'n':
result = (unsigned int)(unsigned __int8)menu_current + 1;
if ( (unsigned __int8)(menu_current + 1) > 3u )
result = 0LL;
menu_current = result;
menu_redraw_required = 1;
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 __int8 v0; // r15
unsigned __int16 v1; // r13
__int64 v2; // r12
unsigned int v3; // er14
__int64 result; // rax
int v5; // ebx

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

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

u8g_SetFont(&u8g, &u8g_font_6x13);
u8g_SetFontRefHeightText(&u8g);
u8g_SetFontPosTop(&u8g);
v0 = *((_BYTE *)&u8g + 65) - *((_BYTE *)&u8g + 66);
v1 = 0;
v2 = 0LL;
v3 = (unsigned __int16)u8g;
do
{
v5 = (int)(v3 - (unsigned __int16)u8g_GetStrWidth(&u8g, (&menu_strings)[v2])) / 2;
u8g_SetDefaultForegroundColor(&u8g);
if ( menu_current == (_BYTE)v2 )
{
u8g_DrawBox(&u8g, 0LL, (unsigned __int16)(v1 + 1), v3, v0);
u8g_SetDefaultBackgroundColor(&u8g);
}
result = u8g_DrawStr(&u8g, (unsigned __int16)v5, v1, (&menu_strings)[v2++]);
v1 += v0;
}
while ( v2 != 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(char *a1)
{
char v1; // al
int v2; // edx

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

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

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v2 += v1;
v1 = *++a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
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

return_type: int


usage

repo: pacew/bcard

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);
}

variable_types:
outname
char *


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);
}

variable_types: x double

variable_types: y double


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", v2, &v1);
draw_text(12.0, 15.0);
setup_text(mono_font, "atw@mit.edu", v2, &v1);
draw_text(12.0, 37.0);
setup_text(mono_font, "774-277-9494", v2, &v1);
draw_text(12.0, 59.0);
set_gray(30.0);
setup_text(main_font, "3 Ames Street, Wa203", v2, &v1);
draw_text(12.0, 84.0);
setup_text(main_font, "Cambridge, MA 02139", v2, &v1);
draw_text(12.0, 99.0);
set_gray(0.0);
setup_text(mono_font, "http://alex.willisson.org", v2, &v1);
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", v2, &v1);
func13(12.0, 15.0);
func12(mono_font, "atw@mit.edu", v2, &v1);
func13(12.0, 37.0);
func12(mono_font, "774-277-9494", v2, &v1);
func13(12.0, 59.0);
func14(30.0);
func12(main_font, "3 Ames Street, Wa203", v2, &v1);
func13(12.0, 84.0);
func12(main_font, "Cambridge, MA 02139", v2, &v1);
func13(12.0, 99.0);
func14(0.0);
func12(mono_font, "http://alex.willisson.org", v2, &v1);
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


main

canonical_name: main

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

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "n");
if ( v3 == -1 )
break;
if ( v3 != 110 )
usage();
draw_outline = 0;
}
if ( optind != argc )
usage();
init_pdf("cards.pdf");
setup_fonts();
code_surface = cairo_image_surface_create_from_png();
code_pattern = cairo_pattern_create_for_surface();
for ( i = 0; i != 720; i += 144 )
{
cairo_save();
v5 = cr;
cairo_translate();
draw_card(v5, 54.0, (double)i + 36.0);
cairo_restore();
cairo_save();
v6 = cr;
cairo_translate();
draw_card(v6, 306.0, (double)i + 36.0);
cairo_restore();
}
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 i; // ebx
__int64 v5; // rdi
__int64 v6; // rdi

while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "n");
if ( v3 == -1 )
break;
if ( v3 != 110 )
func7();
draw_outline = 0;
}
if ( optind != argc )
func7();
func8("cards.pdf");
func10();
code_surface = cairo_image_surface_create_from_png();
code_pattern = cairo_pattern_create_for_surface();
for ( i = 0; i != 720; i += 144 )
{
cairo_save();
v5 = cr;
cairo_translate();
func15(v5, 54.0, (double)i + 36.0);
cairo_restore();
cairo_save();
v6 = cr;
cairo_translate();
func15(v6, 306.0, (double)i + 36.0);
cairo_restore();
}
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: argc int

variable_types:
argv
char **

variable_types: c int

variable_types: row int

variable_types: col int


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 __int8 *v2; // r15
unsigned __int8 *v3; // rbp
unsigned int v4; // er14
unsigned __int8 *v5; // rbx
unsigned __int8 *v6; // rbx
unsigned int v7; // edi
int result; // eax
unsigned int v9; // er12

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

canonical_decompiled_code:
int __fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // r15
unsigned __int8 *v3; // rbp
unsigned int v4; // er14
unsigned __int8 *v5; // rbx
unsigned __int8 *v6; // rbx
unsigned int v7; // edi
int result; // eax
unsigned int v9; // er12

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rbp
FILE *v5; // rax
FILE *v6; // r12
char *v7; // rbx
char *i; // rbp
unsigned int v9; // eax
int v11; // [rsp+8h] [rbp-450h] BYREF
unsigned int v12; // [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 )
usage();
v3 = optind;
if ( optind >= argc )
usage();
++optind;
v4 = argv[v3];
if ( v3 + 1 != argc )
usage();
v5 = fopen(v4, "r");
v6 = v5;
if ( !v5 )
{
fprintf(stderr, "can't open %s\n", v4);
exit(1);
}
if ( !fgets(s, 1000, v5) )
{
fwrite("unexpected EOF\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 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_year -= 1900;
--tp.tm_mon;
tp.tm_isdst = -1;
file_timestamp = mktime(&tp);
v7 = 0LL;
while ( fgets(s, 1000, v6) )
{
if ( (unsigned int)_isoc99_sscanf(s, "bank%d", &v12) == 1 )
{
if ( v12 > 9 )
{
fprintf(stderr, "invalid banknum %d\n", v12);
exit(1);
}
v7 = (char *)&banks + 102404 * (int)v12;
}
else
{
for ( i = s; (unsigned int)_isoc99_sscanf(i, "%2x", &v11) == 1; i += 2 )
{
v9 = *(int *)((char *)&dword_19000 + (_QWORD)v7);
if ( v9 > (unsigned int)&unk_18FFF )
{
fprintf(stderr, "bank %d overflow\n", 0xA11D1BDE70F9C01LL * ((v7 - (char *)&banks) >> 2));
exit(1);
}
*(int *)((char *)&dword_19000 + (_QWORD)v7) = v9 + 1;
v7[v9] = v11;
}
}
}
process_bank0((__int64)&banks, *((_DWORD *)&banks + 25600));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
const char *v4; // rbp
FILE *v5; // rax
FILE *v6; // r12
char *v7; // rbx
char *i; // rbp
unsigned int v9; // eax
int v11; // [rsp+8h] [rbp-450h] BYREF
unsigned int v12; // [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 )
func1();
v3 = optind;
if ( optind >= argc )
func1();
++optind;
v4 = argv[v3];
if ( v3 + 1 != argc )
func1();
v5 = fopen(v4, "r");
v6 = v5;
if ( !v5 )
{
fprintf(stderr, "can't open %s\n", v4);
exit(1);
}
if ( !fgets(s, 1000, v5) )
{
fwrite("unexpected EOF\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
*(_QWORD *)&tp.tm_sec = 0LL;
*(_QWORD *)&tp.tm_hour = 0LL;
*(_QWORD *)&tp.tm_mon = 0LL;
*(_QWORD *)&tp.tm_wday = 0LL;
*(_QWORD *)&tp.tm_isdst = 0LL;
tp.tm_gmtoff = 0LL;
tp.tm_zone = 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_year -= 1900;
--tp.tm_mon;
tp.tm_isdst = -1;
file_timestamp = mktime(&tp);
v7 = 0LL;
while ( fgets(s, 1000, v6) )
{
if ( (unsigned int)_isoc99_sscanf(s, "bank%d", &v12) == 1 )
{
if ( v12 > 9 )
{
fprintf(stderr, "invalid banknum %d\n", v12);
exit(1);
}
v7 = (char *)&banks + 102404 * (int)v12;
}
else
{
for ( i = s; (unsigned int)_isoc99_sscanf(i, "%2x", &v11) == 1; i += 2 )
{
v9 = *(int *)((char *)&dword_19000 + (_QWORD)v7);
if ( v9 > (unsigned int)&unk_18FFF )
{
fprintf(stderr, "bank %d overflow\n", 0xA11D1BDE70F9C01LL * ((v7 - (char *)&banks) >> 2));
exit(1);
}
*(int *)((char *)&dword_19000 + (_QWORD)v7) = v9 + 1;
v7[v9] = v11;
}
}
}
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: rc int

variable_types:
rbuf
unsigned char [10000]

variable_types:
filename
char [1000]

variable_types: t long

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:
cmd
char [1000]


decompiled_code:
void __fastcall print_bank0(__int64 a1, int a2)
{
int v2; // er14
int v3; // ebp
struct tm *v4; // rax
unsigned __int8 *v5; // r13
int v6; // edx
struct tm *v7; // rax
double v8; // rbx
unsigned int v9; // er13
unsigned int v10; // [rsp+Ch] [rbp-4Ch]
time_t v11; // [rsp+10h] [rbp-48h] BYREF
time_t timer; // [rsp+18h] [rbp-40h] BYREF

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

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
int v2; // er14
int v3; // ebp
struct tm *v4; // rax
unsigned __int8 *v5; // r13
int v6; // edx
struct tm *v7; // rax
double v8; // rbx
unsigned int v9; // er13
unsigned int v10; // [rsp+Ch] [rbp-4Ch]
time_t v11; // [rsp+10h] [rbp-48h] BYREF
time_t timer; // [rsp+18h] [rbp-40h] BYREF

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

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: steps 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; }


decompiled_code:
int __fastcall print_bank2(__int64 a1, int a2)
{
int v2; // er14
_BYTE *v3; // r12
int i; // er13
_BYTE *v5; // rbx
int result; // eax
int v7; // eax
struct tm *v8; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF

puts("bank2");
if ( a2 <= 14 )
{
result = 0;
}
else
{
v3 = (_BYTE *)(a1 + 15);
for ( i = 0; ; i += 15 )
{
v7 = ((unsigned __int8)*(v3 - 12) << 24) | (unsigned __int8)*(v3 - 15) | ((unsigned __int8)*(v3 - 13) << 16) | ((unsigned __int8)*(v3 - 14) << 8);
timer = v7;
if ( !i )
v2 = v7;
v5 = v3 - 11;
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
{
if ( *v5++ )
printf(" %02x", (unsigned __int8)*(v5 - 1));
else
printf(" %2s", ".");
}
while ( v5 != v3 );
putchar(10);
result = i + 15;
v3 += 15;
if ( a2 <= i + 29 )
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; // er14
_BYTE *v3; // r12
int i; // er13
_BYTE *v5; // rbx
int result; // eax
int v7; // eax
struct tm *v8; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF

puts("bank2");
if ( a2 <= 14 )
{
result = 0;
}
else
{
v3 = (_BYTE *)(a1 + 15);
for ( i = 0; ; i += 15 )
{
v7 = ((unsigned __int8)*(v3 - 12) << 24) | (unsigned __int8)*(v3 - 15) | ((unsigned __int8)*(v3 - 13) << 16) | ((unsigned __int8)*(v3 - 14) << 8);
timer = v7;
if ( !i )
v2 = v7;
v5 = v3 - 11;
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
{
if ( *v5++ )
printf(" %02x", (unsigned __int8)*(v5 - 1));
else
printf(" %2s", ".");
}
while ( v5 != v3 );
putchar(10);
result = i + 15;
v3 += 15;
if ( a2 <= i + 29 )
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: val int


repo: padawin/Conqueror

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int8 v3; // r12
void *v4; // rbx
unsigned __int16 v6; // [rsp+Ch] [rbp-3Ch] BYREF
unsigned __int8 v7; // [rsp+Fh] [rbp-39h] BYREF
char v8[56]; // [rsp+10h] [rbp-38h] BYREF

game_select_map(v8, &v7, &v6);
v3 = v7;
v4 = calloc(v7, 0x44uLL);
game_select_players(v8, v4, v3, v6);
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; // ebx
int v6; // eax

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

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

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

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


decompiled_code:
__int64 __fastcall init_player(char *dest, int a2, const char *a3, __int16 a4, int a5, __int16 a6)
{
if ( !*a3 )
return 0xFFFFFFFFLL;
if ( a4 && a5 )
return 4294967294LL;
if ( (unsigned int)(a5 - 1) > 1 && !a4 )
return 4294967294LL;
if ( !a6 )
return 4294967293LL;
*((_WORD *)dest + 29) = a6;
*((_DWORD *)dest + 15) = a5;
*((_DWORD *)dest + 13) = a2;
strncpy(dest, a3, 0x32uLL);
*((_DWORD *)dest + 16) = a4;
dest[56] = 0;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *dest, int a2, const char *a3, __int16 a4, int a5, __int16 a6)
{
if ( !*a3 )
return 0xFFFFFFFFLL;
if ( a4 && a5 )
return 4294967294LL;
if ( (unsigned int)(a5 - 1) > 1 && !a4 )
return 4294967294LL;
if ( !a6 )
return 4294967293LL;
*((_WORD *)dest + 29) = a6;
*((_DWORD *)dest + 15) = a5;
*((_DWORD *)dest + 13) = a2;
strncpy(dest, a3, 0x32uLL);
*((_DWORD *)dest + 16) = a4;
dest[56] = 0;
return 1LL;
}

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:
int __fastcall ui_list_cells(const char ***a1, int a2, __int16 a3)
{
const char ***v4; // rbx
int result; // eax
const char *v6; // rdx

if ( a2 > 0 )
{
v4 = a1;
do
{
if ( a3 == 1 )
{
v6 = **v4;
if ( !v6 )
v6 = "nobody";
result = printf(
"Cell %d: owned by %s with %d pawns\n",
*((unsigned int *)*v4 + 4),
v6,
*((unsigned __int16 *)*v4 + 10));
}
else
{
result = printf("Cell %d: %d pawns\n", *((unsigned int *)*v4 + 4), *((unsigned __int16 *)*v4 + 10));
}
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char ***a1, int a2, __int16 a3)
{
const char ***v4; // rbx
int result; // eax
const char *v6; // rdx

if ( a2 > 0 )
{
v4 = a1;
do
{
if ( a3 == 1 )
{
v6 = **v4;
if ( !v6 )
v6 = "nobody";
result = printf(
"Cell %d: owned by %s with %d pawns\n",
*((unsigned int *)*v4 + 4),
v6,
*((unsigned __int16 *)*v4 + 10));
}
else
{
result = printf("Cell %d: %d pawns\n", *((unsigned int *)*v4 + 4), *((unsigned __int16 *)*v4 + 10));
}
++v4;
}
while ( v4 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

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:
__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:
int __fastcall ui_info(const char *a1)
{
return puts(a1);
}

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

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)
{
__int64 result; // rax
unsigned __int8 v4; // dl

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, char a3)
{
__int64 result; // rax
unsigned __int8 v4; // dl

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

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 *


decompiled_code:
__int64 __fastcall cell_set_nb_pawns(_WORD *a1, unsigned __int16 a2)
{
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
if ( *(_WORD *)(*(_QWORD *)a1 + 58LL) < a2 )
return 4294967294LL;
a1[10] = a2;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_WORD *a1, unsigned __int16 a2)
{
if ( !*(_QWORD *)a1 )
return 0xFFFFFFFFLL;
if ( *(_WORD *)(*(_QWORD *)a1 + 58LL) < a2 )
return 4294967294LL;
a1[10] = a2;
return 1LL;
}

original_code:
int cell_set_nb_pawns(s_cell *c, const uint16_t nb_pawns)
{
 if (c->owner == ((void *)0)) {
  return -1;
 }
 if (nb_pawns > c->owner->nb_pawns) {
  return -2;
 }
 c->nb_pawns = nb_pawns;
 return 1;
}

canonical_original_code:
int cell_set_nb_pawns(struct s_cell *c, unsigned short nb_pawns)
{
 if (c->owner == ((void *)0)) {
  return -1;
 }
 if (nb_pawns > c->owner->nb_pawns) {
  return -2;
 }
 c->nb_pawns = nb_pawns;
 return 1;
}


original_code:
short cell_are_neighbours(s_cell *c1, s_cell *c2)
{
 int n;
 for (n = 0; n < c1->nb_neighbours && c1->neighbours[n]->id != c2->id; n++);
 return n < c1->nb_neighbours;
}

canonical_original_code:
short cell_are_neighbours(struct s_cell *c1, struct s_cell *c2)
{
 int n;
 for (n = 0; n < c1->nb_neighbours && c1->neighbours[n]->id != c2->id; n++);
 return n < c1->nb_neighbours;
}

variable_types: n int


original_code:
int cell_add_neighbour(s_cell *c, s_cell *neighbour)
{
 if (
  c->nb_neighbours == c->nb_max_neighbours
  || neighbour->nb_neighbours == neighbour->nb_max_neighbours
 )
  return -1;
 if (cell_are_neighbours(c, neighbour)) {
  return -2;
 }
 c->neighbours[c->nb_neighbours++] = neighbour;
 neighbour->neighbours[neighbour->nb_neighbours++] = c;
 return 1;
}

canonical_original_code:
int cell_add_neighbour(struct s_cell *c, struct s_cell *neighbour)
{
 if (
  c->nb_neighbours == c->nb_max_neighbours
  || neighbour->nb_neighbours == neighbour->nb_max_neighbours
 )
  return -1;
 if (cell_are_neighbours(c, neighbour)) {
  return -2;
 }
 c->neighbours[c->nb_neighbours++] = neighbour;
 neighbour->neighbours[neighbour->nb_neighbours++] = c;
 return 1;
}

variable_types:
neighbour
struct s_cell *


decompiled_code:
__int64 __fastcall init_board(__int64 a1, unsigned __int8 a2, unsigned __int8 a3)
{
__int64 v4; // rbx

if ( !a2 )
return 0xFFFFFFFFLL;
if ( !a3 )
return 4294967294LL;
*(_BYTE *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 8) = calloc(a2, 0x18uLL);
*(_BYTE *)(a1 + 18) = a3;
*(_BYTE *)(a1 + 17) = 0;
*(_QWORD *)a1 = calloc(a3, 8uLL);
v4 = 0LL;
do
{
init_cell(*(_QWORD *)(a1 + 8) + 24 * v4, (unsigned int)(v4 + 1), a2);
++v4;
}
while ( a2 > (int)v4 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2, unsigned __int8 a3)
{
__int64 v4; // rbx

if ( !a2 )
return 0xFFFFFFFFLL;
if ( !a3 )
return 4294967294LL;
*(_BYTE *)(a1 + 16) = a2;
*(_QWORD *)(a1 + 8) = calloc(a2, 0x18uLL);
*(_BYTE *)(a1 + 18) = a3;
*(_BYTE *)(a1 + 17) = 0;
*(_QWORD *)a1 = calloc(a3, 8uLL);
v4 = 0LL;
do
{
init_cell(*(_QWORD *)(a1 + 8) + 24 * v4, (unsigned int)(v4 + 1), a2);
++v4;
}
while ( a2 > (int)v4 );
return 1LL;
}

original_code:
int init_board(s_board *b, uint8_t nb_cells, uint8_t nb_players)
{
 int c;
 if (nb_cells < 1) {
  return -1;
 }
 if (nb_players < 1) {
  return -2;
 }
 b->nb_cells = nb_cells;
 b->cells = (s_cell*) calloc((size_t) nb_cells, sizeof(s_cell));
 b->nb_total_players = nb_players;
 b->nb_players = 0;
 b->players = (s_player **) calloc((size_t) nb_players, sizeof(s_player *));
 for (c = 0; c < nb_cells; c++) {
  init_cell(&b->cells[c], c + 1, nb_cells);
 }
 return 1;
}

canonical_original_code:
int init_board(struct s_board *b, unsigned char nb_cells, unsigned char nb_players)
{
 int c;
 if (nb_cells < 1) {
  return -1;
 }
 if (nb_players < 1) {
  return -2;
 }
 b->nb_cells = nb_cells;
 b->cells = (struct s_cell *) calloc((unsigned long) nb_cells, sizeof(s_cell));
 b->nb_total_players = nb_players;
 b->nb_players = 0;
 b->players = (struct s_player **) calloc((unsigned long) nb_players, sizeof(struct s_player *));
 for (c = 0; c < nb_cells; c++) {
  init_cell(&b->cells[c], c + 1, nb_cells);
 }
 return 1;
}

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; } *


original_code:
void free_board(s_board *b)
{
 int c;
 for (c = 0; c < b->nb_cells; c++) {
  free_cell(&b->cells[c]);
 }
 free(b->cells);
 free(b->players);
 b->cells = ((void *)0);
 b->players = ((void *)0);
}

canonical_original_code:
void free_board(struct s_board *b)
{
 int c;
 for (c = 0; c < b->nb_cells; c++) {
  free_cell(&b->cells[c]);
 }
 free(b->cells);
 free(b->players);
 b->cells = ((void *)0);
 b->players = ((void *)0);
}


decompiled_code:
__int64 __fastcall board_add_player(__int64 a1, __int64 a2)
{
signed int v3; // eax
unsigned int v4; // ebx
__int64 v5; // rbp
_QWORD *v6; // rdi

if ( *(_BYTE *)(a1 + 17) == *(_BYTE *)(a1 + 18) )
return (unsigned int)-1;
do
{
do
{
v3 = utils_get_random_int(0LL, *(unsigned __int8 *)(a1 + 16));
v4 = v3;
}
while ( v3 == -1 );
v5 = 24LL * v3;
v6 = (_QWORD *)(*(_QWORD *)(a1 + 8) + v5);
}
while ( *v6 );
cell_set_owner(v6, a2);
cell_set_nb_pawns(*(_QWORD *)(a1 + 8) + v5, *(unsigned __int16 *)(a2 + 58));
*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned __int8)(*(_BYTE *)(a1 + 17))++) = a2;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
signed int v3; // eax
unsigned int v4; // ebx
__int64 v5; // rbp
_QWORD *v6; // rdi

if ( *(_BYTE *)(a1 + 17) == *(_BYTE *)(a1 + 18) )
return (unsigned int)-1;
do
{
do
{
v3 = utils_get_random_int(0LL, *(unsigned __int8 *)(a1 + 16));
v4 = v3;
}
while ( v3 == -1 );
v5 = 24LL * v3;
v6 = (_QWORD *)(*(_QWORD *)(a1 + 8) + v5);
}
while ( *v6 );
cell_set_owner(v6, a2);
cell_set_nb_pawns(*(_QWORD *)(a1 + 8) + v5, *(unsigned __int16 *)(a2 + 58));
*(_QWORD *)(*(_QWORD *)a1 + 8LL * (unsigned __int8)(*(_BYTE *)(a1 + 17))++) = a2;
return v4;
}

original_code:
int board_add_player(s_board *b, s_player *p)
{
 int cell_index = -1;
 if (b->nb_players == b->nb_total_players) {
  return cell_index;
 }
 do {
  cell_index = (int) utils_get_random_int(0, (unsigned int) b->nb_cells);
 } while (cell_index == -1 || b->cells[cell_index].owner != ((void *)0));
 cell_set_owner(&b->cells[cell_index], p);
 cell_set_nb_pawns(&b->cells[cell_index], p->nb_pawns);
 b->players[b->nb_players] = p;
 b->nb_players++;
 return cell_index;
}

canonical_original_code:
int board_add_player(struct s_board *b, struct s_player *p)
{
 int cell_index = -1;
 if (b->nb_players == b->nb_total_players) {
  return cell_index;
 }
 do {
  cell_index = (int) utils_get_random_int(0, (unsigned int) b->nb_cells);
 } while (cell_index == -1 || b->cells[cell_index].owner != ((void *)0));
 cell_set_owner(&b->cells[cell_index], p);
 cell_set_nb_pawns(&b->cells[cell_index], p->nb_pawns);
 b->players[b->nb_players] = p;
 b->nb_players++;
 return cell_index;
}


original_code:
int board_get_player_cells(s_board *b, s_player *p, s_cell **player_cells)
{
 int c, nb_cells;
 nb_cells = 0;
 for (c = 0; c < b->nb_cells; c++) {
  if (b->cells[c].owner != ((void *)0) && b->cells[c].owner->id == p->id) {
   player_cells[nb_cells++] = &b->cells[c];
  }
 }
 return nb_cells;
}

canonical_original_code:
int board_get_player_cells(struct s_board *b, struct s_player *p, struct s_cell **player_cells)
{
 int c; int nb_cells;
 nb_cells = 0;
 for (c = 0; c < b->nb_cells; c++) {
  if (b->cells[c].owner != ((void *)0) && b->cells[c].owner->id == p->id) {
   player_cells[nb_cells++] = &b->cells[c];
  }
 }
 return nb_cells;
}


decompiled_code:
__int64 __fastcall game_select_map(__int64 a1, __int64 a2, __int64 a3)
{
return builder_create_board(1LL, a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
return builder_create_board(1LL, a1, a2, a3);
}

original_code:
void game_select_map(s_board *b, uint8_t *nb_max_players, uint16_t *pawns_per_player)
{
 builder_create_board(1, b, nb_max_players, pawns_per_player);
}

canonical_original_code:
void game_select_map(struct s_board *b, unsigned char *nb_max_players, unsigned short *pawns_per_player)
{
 builder_create_board(1, b, nb_max_players, pawns_per_player);
}


decompiled_code:
__int64 __fastcall game_select_players(__int64 a1, __int64 a2, unsigned __int8 a3, unsigned __int16 a4)
{
int v5; // er13
__int64 result; // rax
int v7; // ebx
__int64 v8; // rbx
unsigned int v9; // ebp
char s[96]; // [rsp+10h] [rbp-F8h] BYREF
char v11[32]; // [rsp+70h] [rbp-98h] BYREF
char v12[120]; // [rsp+90h] [rbp-78h] BYREF

v5 = a3;
sprintf(s, "Please select between 2 and %d players.\nValidate an empty name when you have enough players.", a3);
result = ui_info(s);
if ( v5 > 0 )
{
v7 = 0;
do
{
v9 = v7 + 1;
sprintf(v11, "Name of player %d: ", (unsigned int)(v7 + 1));
result = ui_prompt(v11, v12, 50LL);
if ( v12[0] )
{
v8 = a2 + 68LL * v7;
init_player(v8, v9, v12, 1LL, 0LL, a4);
result = board_add_player(a1, v8);
v7 = v9;
}
else if ( v7 > 1 )
{
return result;
}
}
while ( v5 > v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned __int8 a3, unsigned __int16 a4)
{
int v5; // er13
__int64 result; // rax
int v7; // ebx
__int64 v8; // rbx
unsigned int v9; // ebp
char s[96]; // [rsp+10h] [rbp-F8h] BYREF
char v11[32]; // [rsp+70h] [rbp-98h] BYREF
char v12[120]; // [rsp+90h] [rbp-78h] BYREF

v5 = a3;
sprintf(s, "Please select between 2 and %d players.\nValidate an empty name when you have enough players.", a3);
result = ui_info(s);
if ( v5 > 0 )
{
v7 = 0;
do
{
v9 = v7 + 1;
sprintf(v11, "Name of player %d: ", (unsigned int)(v7 + 1));
result = ui_prompt(v11, v12, 50LL);
if ( v12[0] )
{
v8 = a2 + 68LL * v7;
init_player(v8, v9, v12, 1LL, 0LL, a4);
result = board_add_player(a1, v8);
v7 = v9;
}
else if ( v7 > 1 )
{
return result;
}
}
while ( v5 > v7 );
}
return result;
}

original_code:
void game_select_players(s_board *b, s_player *players, const uint8_t nb_max_players, const uint16_t nb_pawns_per_player)
{
 int p;
 p = 0;
 char player_name[50];
 char name_prompt[19], names_informations[96];
 sprintf(names_informations, "Please select between 2 and %d players.\nValidate an empty name when you have enough players.", nb_max_players);
 ui_info(names_informations);
 while (p < nb_max_players) {
  sprintf(name_prompt, "Name of player %d: ", p+1);
  ui_prompt(name_prompt, player_name, (size_t) 50);
  if (strlen(player_name) > 0) {
   init_player(&players[p], p+1, player_name, 1, 0, nb_pawns_per_player);
   board_add_player(b, &players[p]);
   p++;
  }
  else if (p >= 2) {
   break;
  }
 }
}

canonical_original_code:
void game_select_players(struct s_board *b, struct s_player *players, unsigned char nb_max_players, unsigned short nb_pawns_per_player)
{
 int p;
 p = 0;
 char player_name[50];
 char name_prompt[19]; char names_informations[96];
 sprintf(names_informations, "Please select between 2 and %d players.\nValidate an empty name when you have enough players.", nb_max_players);
 ui_info(names_informations);
 while (p < nb_max_players) {
  sprintf(name_prompt, "Name of player %d: ", p+1);
  ui_prompt(name_prompt, player_name, (unsigned long) 50);
  if (strlen(player_name) > 0) {
   init_player(&players[p], p+1, player_name, 1, 0, nb_pawns_per_player);
   board_add_player(b, &players[p]);
   p++;
  }
  else if (p >= 2) {
   break;
  }
 }
}

variable_types:
players
struct s_player *

variable_types: p int


decompiled_code:
__int64 __fastcall game_start(__int64 a1)
{
char *v1; // r14
__int16 v2; // ax
__int64 v3; // rbx
unsigned int v4; // eax
char *v5; // r12
__int64 v6; // rbp
unsigned __int16 v8; // [rsp+Eh] [rbp-8Ah]
char s[76]; // [rsp+10h] [rbp-88h] BYREF
int v10[15]; // [rsp+5Ch] [rbp-3Ch] BYREF

v1 = (char *)calloc(*(unsigned __int8 *)(a1 + 16), 8uLL);
v10[0] = select_starting_player(*(unsigned __int8 *)(a1 + 17));
do
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v10[0]);
sprintf(s, "%s's turn to play", (const char *)v3);
ui_info(s);
v4 = board_get_player_cells(a1, v3, v1);
v5 = &v1[8 * (int)player_select_cell_to_leave(v3, v1, v4)];
v6 = player_select_cell_to_go_to(v3, *(_QWORD *)v5);
v8 = player_select_nb_pawns(v3, *(_QWORD *)v5);
if ( *(_QWORD *)v6 && *(_DWORD *)(v3 + 52) != *(_DWORD *)(*(_QWORD *)v6 + 52LL) )
ui_info("You're engaging a fight");
v2 = player_move_to_cell(v3, v8, *(_QWORD *)v5, v6);
if ( v2 == 2 )
{
ui_info("You lost the fight");
}
else if ( v2 == 1 )
{
ui_info("You won the fight");
}
if ( *(_WORD *)(v3 + 58) == *(unsigned __int8 *)(v3 + 56) )
ui_info("You cannot play anymore, all your cells contain one pawn");
}
while ( (unsigned __int16)set_next_player_index((__int64 *)a1, v10, v3, 0LL) );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
char *v1; // r14
__int16 v2; // ax
__int64 v3; // rbx
unsigned int v4; // eax
char *v5; // r12
__int64 v6; // rbp
unsigned __int16 v8; // [rsp+Eh] [rbp-8Ah]
char s[76]; // [rsp+10h] [rbp-88h] BYREF
int v10[15]; // [rsp+5Ch] [rbp-3Ch] BYREF

v1 = (char *)calloc(*(unsigned __int8 *)(a1 + 16), 8uLL);
v10[0] = func2(*(unsigned __int8 *)(a1 + 17));
do
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v10[0]);
sprintf(s, "%s's turn to play", (const char *)v3);
ui_info(s);
v4 = board_get_player_cells(a1, v3, v1);
v5 = &v1[8 * (int)player_select_cell_to_leave(v3, v1, v4)];
v6 = player_select_cell_to_go_to(v3, *(_QWORD *)v5);
v8 = player_select_nb_pawns(v3, *(_QWORD *)v5);
if ( *(_QWORD *)v6 && *(_DWORD *)(v3 + 52) != *(_DWORD *)(*(_QWORD *)v6 + 52LL) )
ui_info("You're engaging a fight");
v2 = player_move_to_cell(v3, v8, *(_QWORD *)v5, v6);
if ( v2 == 2 )
{
ui_info("You lost the fight");
}
else if ( v2 == 1 )
{
ui_info("You won the fight");
}
if ( *(_WORD *)(v3 + 58) == *(unsigned __int8 *)(v3 + 56) )
ui_info("You cannot play anymore, all your cells contain one pawn");
}
while ( (unsigned __int16)func3((__int64 *)a1, v10, v3, 0LL) );
return 0LL;
}

original_code:
s_player *game_start(s_board *b)
{
 int current_player_index, player_nb_cells, cell_to_leave;
 uint16_t nb_pawns_to_move;
 short result;
 s_player *winner, *current_player;
 s_cell **player_cells;
 s_cell *cell_to_goto;
 char next_player_msg[65];
 winner = ((void *)0);
 player_cells = calloc((size_t) b->nb_cells, sizeof(struct s_cell *));
 current_player_index = _select_starting_player(b->nb_players);
 do {
  current_player = b->players[current_player_index];
  sprintf(next_player_msg, "%s's turn to play", current_player->name);
  ui_info(next_player_msg);
  player_nb_cells = board_get_player_cells(b, current_player, player_cells);
  cell_to_leave = player_select_cell_to_leave(current_player, player_cells, player_nb_cells);
  cell_to_goto = player_select_cell_to_go_to(current_player, player_cells[cell_to_leave]);
  nb_pawns_to_move = player_select_nb_pawns(current_player, player_cells[cell_to_leave]);
  if (cell_to_goto->owner != ((void *)0) && current_player->id != cell_to_goto->owner->id)
   ui_info("You're engaging a fight");
  result = player_move_to_cell(
   current_player,
   nb_pawns_to_move,
   player_cells[cell_to_leave],
   cell_to_goto
  );
  if (result == 2) {
   ui_info("You lost the fight");
  }
  else if (result == 1) {
   ui_info("You won the fight");
  }
  if (current_player->nb_pawns == current_player->nb_cells) {
   ui_info("You cannot play anymore, all your cells contain one pawn");
  }
  if (!_set_next_player_index(b, &current_player_index, current_player, winner)) {
   break;
  }
 } while (winner == ((void *)0));
 return winner;
}

canonical_original_code:
struct s_player *game_start(struct s_board *b)
{
 int current_player_index; int player_nb_cells; int cell_to_leave;
 unsigned short nb_pawns_to_move;
 short result;
 struct s_player *winner; struct s_player *current_player;
 struct s_cell **player_cells;
 struct s_cell *cell_to_goto;
 char next_player_msg[65];
 winner = ((void *)0);
 player_cells = calloc((unsigned long) b->nb_cells, sizeof(struct s_cell *));
 current_player_index = _select_starting_player(b->nb_players);
 do {
  current_player = b->players[current_player_index];
  sprintf(next_player_msg, "%s's turn to play", current_player->name);
  ui_info(next_player_msg);
  player_nb_cells = board_get_player_cells(b, current_player, player_cells);
  cell_to_leave = player_select_cell_to_leave(current_player, player_cells, player_nb_cells);
  cell_to_goto = player_select_cell_to_go_to(current_player, player_cells[cell_to_leave]);
  nb_pawns_to_move = player_select_nb_pawns(current_player, player_cells[cell_to_leave]);
  if (cell_to_goto->owner != ((void *)0) && current_player->id != cell_to_goto->owner->id)
   ui_info("You're engaging a fight");
  result = player_move_to_cell(
   current_player,
   nb_pawns_to_move,
   player_cells[cell_to_leave],
   cell_to_goto
  );
  if (result == 2) {
   ui_info("You lost the fight");
  }
  else if (result == 1) {
   ui_info("You won the fight");
  }
  if (current_player->nb_pawns == current_player->nb_cells) {
   ui_info("You cannot play anymore, all your cells contain one pawn");
  }
  if (!_set_next_player_index(b, &current_player_index, current_player, winner)) {
   break;
  }
 } while (winner == ((void *)0));
 return winner;
}

variable_types: struct s_board { struct s_player **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; } *

variable_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 builder_create_board(int a1, __int64 a2, _BYTE *a3, _WORD *a4)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( a1 == 1 )
{
create_small_board(a2, a3, a4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, _BYTE *a3, _WORD *a4)
{
__int64 result; // rax

result = 0xFFFFFFFFLL;
if ( a1 == 1 )
{
func0(a2, a3, a4);
result = 1LL;
}
return result;
}

original_code:
int builder_create_board(int size, s_board *b, uint8_t *nb_max_players, uint16_t *pawns_per_player)
{
 int result;
 result = 1;
 if (size == 1) {
  _create_small_board(b, nb_max_players, pawns_per_player);
 }
 else {
  result = -1;
 }
 return result;
}

canonical_original_code:
int builder_create_board(int size, struct s_board *b, unsigned char *nb_max_players, unsigned short *pawns_per_player)
{
 int result;
 result = 1;
 if (size == 1) {
  _create_small_board(b, nb_max_players, pawns_per_player);
 }
 else {
  result = -1;
 }
 return result;
}

variable_types: size int

variable_types: result int


decompiled_code:
__int64 __fastcall human_select_nb_pawns(__int64 a1)
{
int v1; // ebp
__int64 v2; // rbx
int v3; // eax
char *endptr; // [rsp+8h] [rbp-70h] BYREF
char s[76]; // [rsp+10h] [rbp-68h] BYREF
char nptr[28]; // [rsp+5Ch] [rbp-1Ch] BYREF

v1 = *(unsigned __int16 *)(a1 + 20) - 1;
sprintf(s, "Choose a number of pawns to move between 1 and %d", (unsigned int)v1);
ui_info(s);
while ( 1 )
{
while ( 1 )
{
ui_prompt("Number of pawns: ", nptr, 4LL);
v2 = strtol(nptr, &endptr, 10);
v3 = *_errno_location();
if ( (v3 != 34 || (unsigned __int64)(v2 + 0x7FFFFFFFFFFFFFFFLL) <= 0xFFFFFFFFFFFFFFFDLL)
&& (v2 || !v3)
&& (!*endptr || endptr == nptr)
&& v2 > 0
&& v1 >= v2 )
{
break;
}
ui_error("Invalid number of pawns");
}
if ( endptr != nptr )
break;
ui_error("No value found");
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // ebp
__int64 v2; // rbx
int v3; // eax
char *endptr; // [rsp+8h] [rbp-70h] BYREF
char s[76]; // [rsp+10h] [rbp-68h] BYREF
char nptr[28]; // [rsp+5Ch] [rbp-1Ch] BYREF

v1 = *(unsigned __int16 *)(a1 + 20) - 1;
sprintf(s, "Choose a number of pawns to move between 1 and %d", (unsigned int)v1);
ui_info(s);
while ( 1 )
{
while ( 1 )
{
ui_prompt("Number of pawns: ", nptr, 4LL);
v2 = strtol(nptr, &endptr, 10);
v3 = *_errno_location();
if ( (v3 != 34 || (unsigned __int64)(v2 + 0x7FFFFFFFFFFFFFFFLL) <= 0xFFFFFFFFFFFFFFFDLL)
&& (v2 || !v3)
&& (!*endptr || endptr == nptr)
&& v2 > 0
&& v1 >= v2 )
{
break;
}
ui_error("Invalid number of pawns");
}
if ( endptr != nptr )
break;
ui_error("No value found");
}
return (unsigned int)v2;
}

original_code:
uint16_t human_select_nb_pawns(struct s_cell *src_cell)
{
 char nb_pawns_str[4], msg[64];
 char *endptr;
 long nb_pawns;
 int max_pawns_number;
 nb_pawns = -1;
 max_pawns_number = src_cell->nb_pawns - 1;
 sprintf(msg, "Choose a number of pawns to move between 1 and %d", max_pawns_number);
 ui_info(msg);
 do {
  ui_prompt("Number of pawns: ", nb_pawns_str, (size_t) 4);
  nb_pawns = strtol(nb_pawns_str, &endptr, 10);
  if (((*__errno_location ()) == 34 && (nb_pawns == 0x7fffffffffffffffL || nb_pawns == (-0x7fffffffffffffffL - 1L)))
   || ((*__errno_location ()) != 0 && nb_pawns == 0)
   || (*endptr != '\0' && endptr != nb_pawns_str)
   || nb_pawns < 1
   || nb_pawns > max_pawns_number
  ) {
   ui_error("Invalid number of pawns");
   nb_pawns = -1;
   continue;
  }
  else if (endptr == nb_pawns_str) {
   ui_error("No value found");
   nb_pawns = -1;
   continue;
  }
 } while (nb_pawns == -1);
 return (uint16_t) nb_pawns;
}

canonical_original_code:
unsigned short human_select_nb_pawns(struct s_cell *src_cell)
{
 char nb_pawns_str[4]; char msg[64];
 char *endptr;
 long nb_pawns;
 int max_pawns_number;
 nb_pawns = -1;
 max_pawns_number = src_cell->nb_pawns - 1;
 sprintf(msg, "Choose a number of pawns to move between 1 and %d", max_pawns_number);
 ui_info(msg);
 do {
  ui_prompt("Number of pawns: ", nb_pawns_str, (unsigned long) 4);
  nb_pawns = strtol(nb_pawns_str, &endptr, 10);
  if (((*__errno_location ()) == 34 && (nb_pawns == 0x7fffffffffffffffL || nb_pawns == (-0x7fffffffffffffffL - 1L)))
   || ((*__errno_location ()) != 0 && nb_pawns == 0)
   || (*endptr != '\0' && endptr != nb_pawns_str)
   || nb_pawns < 1
   || nb_pawns > max_pawns_number
  ) {
   ui_error("Invalid number of pawns");
   nb_pawns = -1;
   continue;
  }
  else if (endptr == nb_pawns_str) {
   ui_error("No value found");
   nb_pawns = -1;
   continue;
  }
 } while (nb_pawns == -1);
 return (unsigned short) 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:
msg
char [64]

variable_types:
endptr
char *


decompiled_code:
__int64 __fastcall human_select_cell_to_leave(__int64 a1, unsigned int a2)
{
int v2; // eax
__int64 result; // rax
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

ui_info("Choose a cell to leave");
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
ui_prompt("Command: ", v4, 30LL);
if ( !check_command(v4, "cells", 1) )
break;
ui_list_cells(a1, a2, 0LL);
}
if ( !check_command(v4, "neighbours ", 0) )
break;
v2 = get_cell_from_command(v4, a1, a2);
if ( v2 != -1 )
ui_list_cells(
*(_QWORD *)(*(_QWORD *)(a1 + 8LL * v2) + 8LL),
*(unsigned __int8 *)(*(_QWORD *)(a1 + 8LL * v2) + 22LL),
1LL);
}
if ( check_command(v4, "cell ", 0) )
{
result = get_cell_from_command(v4, a1, a2);
if ( (_DWORD)result != -1 )
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
int v2; // eax
__int64 result; // rax
char v4[56]; // [rsp+0h] [rbp-38h] BYREF

ui_info("Choose a cell to leave");
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
ui_prompt("Command: ", v4, 30LL);
if ( !func1(v4, "cells", 1) )
break;
ui_list_cells(a1, a2, 0LL);
}
if ( !func1(v4, "neighbours ", 0) )
break;
v2 = func3(v4, a1, a2);
if ( v2 != -1 )
ui_list_cells(
*(_QWORD *)(*(_QWORD *)(a1 + 8LL * v2) + 8LL),
*(unsigned __int8 *)(*(_QWORD *)(a1 + 8LL * v2) + 22LL),
1LL);
}
if ( func1(v4, "cell ", 0) )
{
result = func3(v4, a1, a2);
if ( (_DWORD)result != -1 )
break;
}
}
return result;
}

original_code:
int human_select_cell_to_leave(struct s_cell **player_cells, int nb_cells)
{
 int command_size, choosen_cell;
 command_size = 30;
 char command[command_size];
 choosen_cell = -1;
 ui_info("Choose a cell to leave");
 do {
  ui_prompt("Command: ", command, (size_t) command_size);
  if (_check_command(command, "cells", 1)) {
   ui_list_cells(player_cells, nb_cells, 0);
  }
  else if (_check_command(command, "neighbours ", 0)) {
   int c = _get_cell_from_command(command, player_cells, nb_cells);
   if (c == -1)
    continue;
   ui_list_cells(player_cells[c]->neighbours, player_cells[c]->nb_neighbours, 1);
  }
  else if (_check_command(command, "cell ", 0)) {
   int c = _get_cell_from_command(command, player_cells, nb_cells);
   if (c == -1)
    continue;
   choosen_cell = c;
  }
 } while (choosen_cell == -1);
 return choosen_cell;
}

canonical_original_code:
int human_select_cell_to_leave(struct s_cell **player_cells, int nb_cells)
{
 int command_size; int choosen_cell;
 command_size = 30;
 char command[-1];
 choosen_cell = -1;
 ui_info("Choose a cell to leave");
 do {
  ui_prompt("Command: ", command, (unsigned long) command_size);
  if (_check_command(command, "cells", 1)) {
   ui_list_cells(player_cells, nb_cells, 0);
  }
  else if (_check_command(command, "neighbours ", 0)) {
   int c = _get_cell_from_command(command, player_cells, nb_cells);
   if (c == -1)
    continue;
   ui_list_cells(player_cells[c]->neighbours, player_cells[c]->nb_neighbours, 1);
  }
  else if (_check_command(command, "cell ", 0)) {
   int c = _get_cell_from_command(command, player_cells, nb_cells);
   if (c == -1)
    continue;
   choosen_cell = c;
  }
 } while (choosen_cell == -1);
 return choosen_cell;
}

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:
command
char [-1]

variable_types: c int


decompiled_code:
__int64 __fastcall human_select_cell_to_go_to(__int64 a1)
{
int v1; // eax
__int64 result; // rax
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

ui_info("Choose a cell to go to");
while ( 1 )
{
while ( 1 )
{
ui_prompt("Command: ", v3, 30LL);
if ( !check_command(v3, "cells", 1) )
break;
ui_list_cells(*(_QWORD *)(a1 + 8), *(unsigned __int8 *)(a1 + 22), 1LL);
}
if ( check_command(v3, "cell ", 0) )
{
v1 = get_cell_from_command(v3, *(_QWORD *)(a1 + 8), *(unsigned __int8 *)(a1 + 22));
if ( v1 != -1 )
{
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v1);
if ( result )
break;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // eax
__int64 result; // rax
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

ui_info("Choose a cell to go to");
while ( 1 )
{
while ( 1 )
{
ui_prompt("Command: ", v3, 30LL);
if ( !func1(v3, "cells", 1) )
break;
ui_list_cells(*(_QWORD *)(a1 + 8), *(unsigned __int8 *)(a1 + 22), 1LL);
}
if ( func1(v3, "cell ", 0) )
{
v1 = func3(v3, *(_QWORD *)(a1 + 8), *(unsigned __int8 *)(a1 + 22));
if ( v1 != -1 )
{
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v1);
if ( result )
break;
}
}
}
return result;
}

original_code:
struct s_cell *human_select_cell_to_go_to(struct s_cell *src_cell)
{
 int command_size;
 struct s_cell *choosen_cell;
 command_size = 30;
 char command[command_size];
 choosen_cell = ((void *)0);
 ui_info("Choose a cell to go to");
 do {
  ui_prompt("Command: ", command, (size_t) command_size);
  if (_check_command(command, "cells", 1)) {
   ui_list_cells(src_cell->neighbours, src_cell->nb_neighbours, 1);
  }
  else if (_check_command(command, "cell ", 0)) {
   int c = _get_cell_from_command(command, src_cell->neighbours, src_cell->nb_neighbours);
   if (c == -1)
    continue;
   choosen_cell = src_cell->neighbours[c];
  }
 } while (choosen_cell == ((void *)0));
 return choosen_cell;
}

canonical_original_code:
struct s_cell *human_select_cell_to_go_to(struct s_cell *src_cell)
{
 int command_size;
 struct s_cell *choosen_cell;
 command_size = 30;
 char command[-1];
 choosen_cell = ((void *)0);
 ui_info("Choose a cell to go to");
 do {
  ui_prompt("Command: ", command, (unsigned long) command_size);
  if (_check_command(command, "cells", 1)) {
   ui_list_cells(src_cell->neighbours, src_cell->nb_neighbours, 1);
  }
  else if (_check_command(command, "cell ", 0)) {
   int c = _get_cell_from_command(command, src_cell->neighbours, src_cell->nb_neighbours);
   if (c == -1)
    continue;
   choosen_cell = src_cell->neighbours[c];
  }
 } while (choosen_cell == ((void *)0));
 return choosen_cell;
}


repo: padawin/sdl-sandbox

decompiled_code:
__int64 __fastcall 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 func13(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 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


success

repo: padenot/vagg

decompiled_code:
int __fastcall success(const char *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
if ( v1 )
fprintf(stdout, "[%ld] ", v1);
fprintf(stdout, "\ttest %d succeeded : %s", (unsigned int)test_index, a1);
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
if ( v1 )
fprintf(stdout, "[%ld] ", v1);
fprintf(stdout, "\ttest %d succeeded : %s", (unsigned int)test_index, a1);
return fputc(10, stdout);
}

original_code:
static void success(const char* msg) {
    do { if(VAGG_LOG_OK <= VAGG_LOG_DEBUG) { size_t i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_OK]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "\ttest %d succeeded : %s", test_index, msg); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
}

canonical_original_code:
static void success(char *msg) {
    do { if(VAGG_LOG_OK <= VAGG_LOG_DEBUG) { unsigned long i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_OK]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "\ttest %d succeeded : %s", test_index, msg); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
}

variable_types:
msg
char *

variable_types:
i
unsigned long


failed

decompiled_code:
int __fastcall failed(const char *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
if ( v1 )
fprintf(stdout, "[%ld] ", v1);
fprintf(stdout, "\ttest %d failed : %s", (unsigned int)test_index, a1);
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
if ( v1 )
fprintf(stdout, "[%ld] ", v1);
fprintf(stdout, "\ttest %d failed : %s", (unsigned int)test_index, a1);
return fputc(10, stdout);
}

original_code:
static void failed(const char* msg) {
    do { if(VAGG_LOG_CRITICAL <= VAGG_LOG_DEBUG) { size_t i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_CRITICAL]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "\ttest %d failed : %s", test_index, msg); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
}

canonical_original_code:
static void failed(char *msg) {
    do { if(VAGG_LOG_CRITICAL <= VAGG_LOG_DEBUG) { unsigned long i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_CRITICAL]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "\ttest %d failed : %s", test_index, msg); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
}


decompiled_code:
int __fastcall vagg_start(int a1)
{
pthread_t v1; // rax

show_success = a1;
success_count = 0;
test_index = 0;
v1 = pthread_self();
if ( v1 )
fprintf(stdout, "[%ld] ", v1);
fwrite("starting test suite.", 1uLL, 0x14uLL, stdout);
return fputc(10, stdout);
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
pthread_t v1; // rax

show_success = a1;
success_count = 0;
test_index = 0;
v1 = pthread_self();
if ( v1 )
fprintf(stdout, "[%ld] ", v1);
fwrite("starting test suite.", 1uLL, 0x14uLL, stdout);
return fputc(10, stdout);
}

original_code:
void vagg_start(enum vagg_show show_all) {
  show_success = show_all;
  success_count = 0;
  test_index = 0;
  do { if(VAGG_LOG_DEBUG <= VAGG_LOG_DEBUG) { size_t i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_DEBUG]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "starting test suite."); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
}

canonical_original_code:
void vagg_start(enum vagg_show show_all) {
  show_success = show_all;
  success_count = 0;
  test_index = 0;
  do { if(VAGG_LOG_DEBUG <= VAGG_LOG_DEBUG) { unsigned long i; fprintf(stdout, "%s", VAGG_COLORS[VAGG_LOG_DEBUG]); for(i=0; i < vagg_log_indent_level ; i++) { fprintf(stdout, "\t"); } if (pthread_self() != 0) { fprintf(stdout, "[%ld] ", pthread_self()); } fprintf(stdout, "starting test suite."); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
}

variable_types: enum vagg_show { vagg_display_success=0, vagg_hide_sucess=1 }


decompiled_code:
int __fastcall vagg_ok(int a1, const char *a2)
{
int result; // eax

++test_index;
if ( !a1 )
return failed(a2);
++success_count;
if ( show_success )
result = success(a2);
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1, const char *a2)
{
int result; // eax

++test_index;
if ( !a1 )
return func1(a2);
++success_count;
if ( show_success )
result = func0(a2);
return result;
}

original_code:
void vagg_ok(int predicate, const char* msg) {
  test_index++;
  if(predicate) {
    success_count++;
    if (show_success) {
      success(msg);
    }
  } else {
    failed(msg);
  }
}

canonical_original_code:
void vagg_ok(int predicate, char *msg) {
  test_index++;
  if(predicate) {
    success_count++;
    if (show_success) {
      success(msg);
    }
  } else {
    failed(msg);
  }
}

variable_types: predicate int


decompiled_code:
int __fastcall vagg_range(const char *a1, double a2, double a3, double a4)
{
int result; // eax

++test_index;
if ( a4 < COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a2 - a3) & LC4) )
return failed(a1);
++success_count;
if ( show_success )
result = success(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func4(const char *a1, double a2, double a3, double a4)
{
int result; // eax

++test_index;
if ( a4 < COERCE_DOUBLE(COERCE_UNSIGNED_INT64(a2 - a3) & LC4) )
return func1(a1);
++success_count;
if ( show_success )
result = func0(a1);
return result;
}

original_code:
void vagg_range(double value, double ref, double threshold, const char* msg) {
  test_index++;
  if (fabs(value - ref) <= threshold) {
    success_count++;
    if (show_success) {
      success(msg);
    }
  } else {
    failed(msg);
  }
}

canonical_original_code:
void vagg_range(double value, double ref, double threshold, char *msg) {
  test_index++;
  if (fabs(value - ref) <= threshold) {
    success_count++;
    if (show_success) {
      success(msg);
    }
  } else {
    failed(msg);
  }
}

variable_types: value double

variable_types: ref double

variable_types: threshold double