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


repo: padawin/Conqueror

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: 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: n int

return_type: short

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


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 *

return_type: int

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 init_board(__int64 a1, unsigned __int8 a2, unsigned __int8 a3)
{
char *v5; // rax
size_t v6; // rdi
char *v7; // r12
__int64 v8; // rbx
__int64 v9; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
if ( !a3 )
return 4294967294LL;
*(_BYTE *)(a1 + 16) = a2;
v5 = (char *)calloc(a2, 0x18uLL);
*(_BYTE *)(a1 + 18) = a3;
v6 = a3;
*(_QWORD *)(a1 + 8) = v5;
v7 = v5;
v8 = 0LL;
*(_BYTE *)(a1 + 17) = 0;
*(_QWORD *)a1 = calloc(v6, 8uLL);
while ( 1 )
{
v9 = 3 * v8++;
init_cell(&v7[8 * v9], (unsigned int)v8, a2);
if ( a2 <= (int)v8 )
break;
v7 = *(char **)(a1 + 8);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned __int8 a2, unsigned __int8 a3)
{
char *v5; // rax
size_t v6; // rdi
char *v7; // r12
__int64 v8; // rbx
__int64 v9; // rax

if ( !a2 )
return 0xFFFFFFFFLL;
if ( !a3 )
return 4294967294LL;
*(_BYTE *)(a1 + 16) = a2;
v5 = (char *)calloc(a2, 0x18uLL);
*(_BYTE *)(a1 + 18) = a3;
v6 = a3;
*(_QWORD *)(a1 + 8) = v5;
v7 = v5;
v8 = 0LL;
*(_BYTE *)(a1 + 17) = 0;
*(_QWORD *)a1 = calloc(v6, 8uLL);
while ( 1 )
{
v9 = 3 * v8++;
init_cell(&v7[8 * v9], (unsigned int)v8, a2);
if ( a2 <= (int)v8 )
break;
v7 = *(char **)(a1 + 8);
}
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; } *

variable_types: c int

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


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

return_type: void


decompiled_code:
__int64 __fastcall board_add_player(__int64 a1, __int64 a2)
{
signed int v3; // eax
unsigned int v4; // er12
__int64 v5; // rbx
_QWORD *v6; // rdi
unsigned __int8 v7; // al

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 *)(v5 + *(_QWORD *)(a1 + 8));
}
while ( *v6 );
cell_set_owner(v6, a2);
cell_set_nb_pawns(*(_QWORD *)(a1 + 8) + v5, *(unsigned __int16 *)(a2 + 58));
v7 = *(_BYTE *)(a1 + 17);
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v7) = a2;
*(_BYTE *)(a1 + 17) = v7 + 1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
signed int v3; // eax
unsigned int v4; // er12
__int64 v5; // rbx
_QWORD *v6; // rdi
unsigned __int8 v7; // al

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 *)(v5 + *(_QWORD *)(a1 + 8));
}
while ( *v6 );
cell_set_owner(v6, a2);
cell_set_nb_pawns(*(_QWORD *)(a1 + 8) + v5, *(unsigned __int16 *)(a2 + 58));
v7 = *(_BYTE *)(a1 + 17);
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v7) = a2;
*(_BYTE *)(a1 + 17) = v7 + 1;
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;
}

variable_types:
p
struct s_player *


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; // ebp
__int64 result; // rax
int v7; // er15
int v8; // er13
__int64 v9; // r15
__int64 v10; // rsi
unsigned int v12; // [rsp+Ch] [rbp-FCh]
char v13[32]; // [rsp+10h] [rbp-F8h] BYREF
char v14[64]; // [rsp+30h] [rbp-D8h] BYREF
char s[152]; // [rsp+70h] [rbp-98h] 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 )
{
v7 = 0;
v12 = a4;
do
{
while ( 1 )
{
v8 = v7 + 1;
sprintf(v13, "Name of player %d: ", (unsigned int)(v7 + 1));
result = ui_prompt(v13, v14, 50LL);
if ( !v14[0] )
break;
v9 = a2 + 68LL * v7;
init_player(v9, (unsigned int)v8, v14, 1LL, 0LL, v12);
v10 = v9;
v7 = v8;
result = board_add_player(a1, v10);
if ( v5 <= v8 )
return result;
}
}
while ( v7 <= 1 && v5 > v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned __int8 a3, unsigned __int16 a4)
{
int v5; // ebp
__int64 result; // rax
int v7; // er15
int v8; // er13
__int64 v9; // r15
__int64 v10; // rsi
unsigned int v12; // [rsp+Ch] [rbp-FCh]
char v13[32]; // [rsp+10h] [rbp-F8h] BYREF
char v14[64]; // [rsp+30h] [rbp-D8h] BYREF
char s[152]; // [rsp+70h] [rbp-98h] 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 )
{
v7 = 0;
v12 = a4;
do
{
while ( 1 )
{
v8 = v7 + 1;
sprintf(v13, "Name of player %d: ", (unsigned int)(v7 + 1));
result = ui_prompt(v13, v14, 50LL);
if ( !v14[0] )
break;
v9 = a2 + 68LL * v7;
init_player(v9, (unsigned int)v8, v14, 1LL, 0LL, v12);
v10 = v9;
v7 = v8;
result = board_add_player(a1, v10);
if ( v5 <= v8 )
return result;
}
}
while ( v7 <= 1 && 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; // r12
int v2; // eax
__int64 v3; // r14
unsigned int v4; // eax
char *v5; // rbx
__int64 v6; // r15
unsigned __int16 v7; // ax
__int16 v8; // ax
unsigned __int16 v10; // [rsp+Ch] [rbp-9Ch]
int i; // [rsp+1Ch] [rbp-8Ch] BYREF
char s[136]; // [rsp+20h] [rbp-88h] BYREF

v1 = (char *)calloc(*(unsigned __int8 *)(a1 + 16), 8uLL);
v2 = select_starting_player(*(unsigned __int8 *)(a1 + 17));
for ( i = v2; ; v2 = i )
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v2);
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);
v7 = player_select_nb_pawns(v3, *(_QWORD *)v5);
if ( *(_QWORD *)v6 && *(_DWORD *)(v3 + 52) != *(_DWORD *)(*(_QWORD *)v6 + 52LL) )
{
v10 = v7;
ui_info("You're engaging a fight");
v7 = v10;
}
v8 = player_move_to_cell(v3, v7, *(_QWORD *)v5, v6);
if ( v8 == 2 )
{
ui_info("You lost the fight");
if ( *(_WORD *)(v3 + 58) != *(unsigned __int8 *)(v3 + 56) )
goto LABEL_5;
LABEL_12:
ui_info("You cannot play anymore, all your cells contain one pawn");
goto LABEL_5;
}
if ( v8 == 1 )
ui_info("You won the fight");
if ( *(_WORD *)(v3 + 58) == *(unsigned __int8 *)(v3 + 56) )
goto LABEL_12;
LABEL_5:
if ( !(unsigned __int16)set_next_player_index((__int64 *)a1, &i, v3) )
break;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
char *v1; // r12
int v2; // eax
__int64 v3; // r14
unsigned int v4; // eax
char *v5; // rbx
__int64 v6; // r15
unsigned __int16 v7; // ax
__int16 v8; // ax
unsigned __int16 v10; // [rsp+Ch] [rbp-9Ch]
int i; // [rsp+1Ch] [rbp-8Ch] BYREF
char s[136]; // [rsp+20h] [rbp-88h] BYREF

v1 = (char *)calloc(*(unsigned __int8 *)(a1 + 16), 8uLL);
v2 = func2(*(unsigned __int8 *)(a1 + 17));
for ( i = v2; ; v2 = i )
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v2);
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);
v7 = player_select_nb_pawns(v3, *(_QWORD *)v5);
if ( *(_QWORD *)v6 && *(_DWORD *)(v3 + 52) != *(_DWORD *)(*(_QWORD *)v6 + 52LL) )
{
v10 = v7;
ui_info("You're engaging a fight");
v7 = v10;
}
v8 = player_move_to_cell(v3, v7, *(_QWORD *)v5, v6);
if ( v8 == 2 )
{
ui_info("You lost the fight");
if ( *(_WORD *)(v3 + 58) != *(unsigned __int8 *)(v3 + 56) )
goto LABEL_5;
LABEL_12:
ui_info("You cannot play anymore, all your cells contain one pawn");
goto LABEL_5;
}
if ( v8 == 1 )
ui_info("You won the fight");
if ( *(_WORD *)(v3 + 58) == *(unsigned __int8 *)(v3 + 56) )
goto LABEL_12;
LABEL_5:
if ( !(unsigned __int16)func3((__int64 *)a1, &i, v3) )
break;
}
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: result short

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


decompiled_code:
__int64 __fastcall builder_create_board(int a1, __int64 a2, _BYTE *a3, _WORD *a4)
{
if ( a1 != 1 )
return 0xFFFFFFFFLL;
create_small_board(a2, a3, a4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, _BYTE *a3, _WORD *a4)
{
if ( a1 != 1 )
return 0xFFFFFFFFLL;
func0(a2, a3, a4);
return 1LL;
}

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
int *v2; // r12
__int64 result; // rax
char nptr[4]; // [rsp+4h] [rbp-74h] BYREF
char *endptr; // [rsp+8h] [rbp-70h] BYREF
char s[104]; // [rsp+10h] [rbp-68h] 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);
v2 = _errno_location();
while ( 1 )
{
while ( 1 )
{
ui_prompt("Number of pawns: ", nptr, 4LL);
result = strtol(nptr, &endptr, 10);
if ( *v2 == 34 )
{
if ( (unsigned __int64)(result + 0x7FFFFFFFFFFFFFFFLL) > 0xFFFFFFFFFFFFFFFDLL )
goto LABEL_12;
}
else if ( !*v2 )
{
goto LABEL_4;
}
if ( !result )
goto LABEL_12;
LABEL_4:
if ( (!*endptr || endptr == nptr) && result > 0 && result <= v1 )
break;
LABEL_12:
ui_error("Invalid number of pawns");
}
if ( endptr != nptr )
return result;
ui_error("No value found");
}
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // ebp
int *v2; // r12
__int64 result; // rax
char nptr[4]; // [rsp+4h] [rbp-74h] BYREF
char *endptr; // [rsp+8h] [rbp-70h] BYREF
char s[104]; // [rsp+10h] [rbp-68h] 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);
v2 = _errno_location();
while ( 1 )
{
while ( 1 )
{
ui_prompt("Number of pawns: ", nptr, 4LL);
result = strtol(nptr, &endptr, 10);
if ( *v2 == 34 )
{
if ( (unsigned __int64)(result + 0x7FFFFFFFFFFFFFFFLL) > 0xFFFFFFFFFFFFFFFDLL )
goto LABEL_12;
}
else if ( !*v2 )
{
goto LABEL_4;
}
if ( !result )
goto LABEL_12;
LABEL_4:
if ( (!*endptr || endptr == nptr) && result > 0 && result <= v1 )
break;
LABEL_12:
ui_error("Invalid number of pawns");
}
if ( endptr != nptr )
return result;
ui_error("No value found");
}
}

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:
msg
char [64]

variable_types:
endptr
char *

return_type: unsigned short


decompiled_code:
__int64 __fastcall human_select_cell_to_leave(__int64 a1, unsigned int a2)
{
int v2; // eax
__int64 result; // rax
char v4[72]; // [rsp+0h] [rbp-48h] 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[72]; // [rsp+0h] [rbp-48h] 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:
command
char [-1]


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

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


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

return_type: unsigned int


success

repo: padenot/vagg

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

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

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

v1 = stdout;
v2 = pthread_self();
if ( v2 )
{
fprintf(v1, "[%ld] ", v2);
v1 = stdout;
}
fprintf(v1, "\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)
{
FILE *v1; // rbp
pthread_t v2; // rax

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

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

v1 = stdout;
v2 = pthread_self();
if ( v2 )
{
fprintf(v1, "[%ld] ", v2);
v1 = stdout;
}
fprintf(v1, "\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)
{
FILE *v1; // r12
pthread_t v2; // rax

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

canonical_decompiled_code:
int __fastcall func2(int a1)
{
FILE *v1; // r12
pthread_t v2; // rax

show_success = a1;
success_count = 0;
test_index = 0;
v1 = stdout;
v2 = pthread_self();
if ( v2 )
{
fprintf(v1, "[%ld] ", v2);
v1 = stdout;
}
fwrite("starting test suite.", 1uLL, 0x14uLL, v1);
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);
result = show_success;
++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);
result = show_success;
++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);
result = show_success;
++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);
result = show_success;
++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


decompiled_code:
int __fastcall vagg_bufeq(void *s1, size_t n, void *s2, __int64 a4, const char *a5)
{
int result; // eax

++test_index;
if ( n != a4 )
failed(a5);
if ( memcmp(s1, s2, n) )
return failed(a5);
result = show_success;
if ( show_success )
result = success(a5);
++success_count;
return result;
}

canonical_decompiled_code:
int __fastcall func5(void *s1, size_t n, void *s2, __int64 a4, const char *a5)
{
int result; // eax

++test_index;
if ( n != a4 )
func1(a5);
if ( memcmp(s1, s2, n) )
return func1(a5);
result = show_success;
if ( show_success )
result = func0(a5);
++success_count;
return result;
}

original_code:
void vagg_bufeq(const void* buf1, size_t buf1_len, const void* buf2, size_t buf2_len, const char* msg) {
  test_index++;
  if(buf1_len != buf2_len) {
    failed(msg);
  }
  if (bcmp(buf1, buf2, buf1_len)) {
    failed(msg);
  } else {
    if (show_success) {
      success(msg);
    }
    success_count++;
  }
}

canonical_original_code:
void vagg_bufeq(void *buf1, unsigned long buf1_len, void *buf2, unsigned long buf2_len, char *msg) {
  test_index++;
  if(buf1_len != buf2_len) {
    failed(msg);
  }
  if (bcmp(buf1, buf2, buf1_len)) {
    failed(msg);
  } else {
    if (show_success) {
      success(msg);
    }
    success_count++;
  }
}


decompiled_code:
int vagg_end()
{
unsigned int v0; // er12
unsigned int v1; // er13
FILE *v2; // rbp
pthread_t v3; // rax

v0 = success_count;
v1 = test_index;
v2 = stdout;
v3 = pthread_self();
if ( v0 == v1 )
{
if ( v3 )
{
fprintf(v2, "[%ld] ", v3);
v1 = test_index;
v0 = success_count;
v2 = stdout;
}
fprintf(v2, "test suite ended : %u/%u passed. success.", v0, v1);
}
else
{
if ( v3 )
{
fprintf(v2, "[%ld] ", v3);
v1 = test_index;
v0 = success_count;
v2 = stdout;
}
fprintf(v2, "test suite ended : %u/%u passed. failed.", v0, v1);
}
return fputc(10, stdout);
}

canonical_decompiled_code:
int func6()
{
unsigned int v0; // er12
unsigned int v1; // er13
FILE *v2; // rbp
pthread_t v3; // rax

v0 = success_count;
v1 = test_index;
v2 = stdout;
v3 = pthread_self();
if ( v0 == v1 )
{
if ( v3 )
{
fprintf(v2, "[%ld] ", v3);
v1 = test_index;
v0 = success_count;
v2 = stdout;
}
fprintf(v2, "test suite ended : %u/%u passed. success.", v0, v1);
}
else
{
if ( v3 )
{
fprintf(v2, "[%ld] ", v3);
v1 = test_index;
v0 = success_count;
v2 = stdout;
}
fprintf(v2, "test suite ended : %u/%u passed. failed.", v0, v1);
}
return fputc(10, stdout);
}

original_code:
void vagg_end() {
  if (success_count == test_index) {
    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, "test suite ended : %u/%u passed. success.", success_count, test_index); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
  } else {
    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, "test suite ended : %u/%u passed. failed.", success_count, test_index); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
  }
}

canonical_original_code:
void vagg_end() {
  if (success_count == test_index) {
    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, "test suite ended : %u/%u passed. success.", success_count, test_index); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
  } else {
    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, "test suite ended : %u/%u passed. failed.", success_count, test_index); fprintf(stdout, "\n"); fprintf(stdout, "%s", VAGG_COLORS[VAGG_COLOR_RESET]); } } while(0);;
  }
}


decompiled_code:
__int64 __fastcall sgemm_reference(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-20h] BYREF
int v6; // [rsp+10h] [rbp-10h]
int v7; // [rsp+14h] [rbp-Ch]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(sgemm_reference__omp_fn_0, v5, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, __int64 a3, __int64 a4)
{
__int64 v5[2]; // [rsp+0h] [rbp-20h] BYREF
int v6; // [rsp+10h] [rbp-10h]
int v7; // [rsp+14h] [rbp-Ch]

v5[1] = a4;
v5[0] = a3;
v7 = a2;
v6 = a1;
return GOMP_parallel(sgemm_reference__omp_fn_0, v5, 0LL, 0LL);
}

original_code:
void sgemm_reference(int m, int n, float *A, float *C) {

#pragma omp parallel for
 for (int i = 0; i < n; i++)
  for (int k = 0; k < m; k++)
   for (int j = 0; j < n; j++)
    C[i + j * n] += A[i + k * (n)] * A[j * (n + 1) + k * (n)];
}

variable_types: m int

variable_types: n int

variable_types:
A
float *

variable_types:
C
float *

variable_types: i int

variable_types: k int

variable_types: j int


main

canonical_name: main

original_code:
int main(int argc, char **argv) {
 srand(time(((void *)0) ));
 int counter = 0;
 float sum = 0;
 int nStart = 401;
 int nEnd = 1500;
 int mStart = 32;
 int mEnd = 150;
 int loopEnd = 1;
 if (argc == 3) {
  nStart = atoi(argv[1]);
  nEnd = nStart + 1;
  mStart = atoi(argv[2]);
  mEnd = mStart + 1;
  loopEnd = 10;
 }
 for (int loop = 0; loop < loopEnd; loop++)
  for (int n = nStart; n < nEnd; n = n + 1 + n/10) {
   for (int m = mStart; m < mEnd; m = m + 1 + m/10) {
    float *A = (float*) malloc((n + m) * n * sizeof(float));
    float *C = (float*) malloc(n * n * sizeof(float));
    float *C_ref = (float*) malloc(n * n * sizeof(float));
    for (int i = 0; i < (n + m) * n; i++)
     A[i] = 2 * drand48() - 1;
    memset( C_ref, 0, sizeof( float ) * n * n);
    sgemm_reference(m, n, A, C_ref);
    memset( C, 0, sizeof( float ) * n * n);
    sgemm(m, n, m, A, C);
    for (int i = 0; i < n * n; i++) {
     C[i] -= C_ref[i];
    }
    for (int i = 0; i < n * n; i++) {
     if (i < 100) {
     }
     if (C[i] * C[i] > 0.0001) {
      printf(
        "FAILURE: error in matrix multiply exceeds an acceptable margin\n");
      printf(
        "Off by: %f, from the reference: %f, at n = %d, m = %d, i = %d\n",
        C[i], C_ref[i], n, m, i);
      return -1;
     }
    }
    double Gflop_s, seconds = -1.0;
    for (int n_iterations = 1; seconds < 0.1; n_iterations *= 2) {
     sgemm(m, n, m, A, C);
     struct timeval start, end;
     gettimeofday(&start, ((void *)0) );
     for (int i = 0; i < n_iterations; i++)
      sgemm(m, n, m, A, C);
     gettimeofday(&end, ((void *)0) );
     seconds = (end.tv_sec - start.tv_sec)
       + 1.0e-6 * (end.tv_usec - start.tv_usec);
     Gflop_s = 2e-9 * n_iterations * m * n * n / seconds;
    }
    printf("n = %d, m =  %d \t %g Gflop/s\n", n, m, Gflop_s);
    counter++;
    sum += Gflop_s;
    free(C_ref);
    free(C);
    free(A);
   }
  }
 printf("Average Gflops: %f\n", sum / counter);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 srand(time(((void *)0) ));
 int counter = 0;
 float sum = 0;
 int nStart = 401;
 int nEnd = 1500;
 int mStart = 32;
 int mEnd = 150;
 int loopEnd = 1;
 if (argc == 3) {
  nStart = atoi(argv[1]);
  nEnd = nStart + 1;
  mStart = atoi(argv[2]);
  mEnd = mStart + 1;
  loopEnd = 10;
 }
 for (int loop = 0; loop < loopEnd; loop++)
  for (int n = nStart; n < nEnd; n = n + 1 + n/10) {
   for (int m = mStart; m < mEnd; m = m + 1 + m/10) {
    float *A = (float*) malloc((n + m) * n * sizeof(float));
    float *C = (float*) malloc(n * n * sizeof(float));
    float *C_ref = (float*) malloc(n * n * sizeof(float));
    for (int i = 0; i < (n + m) * n; i++)
     A[i] = 2 * drand48() - 1;
    memset( C_ref, 0, sizeof( float ) * n * n);
    sgemm_reference(m, n, A, C_ref);
    memset( C, 0, sizeof( float ) * n * n);
    sgemm(m, n, m, A, C);
    for (int i = 0; i < n * n; i++) {
     C[i] -= C_ref[i];
    }
    for (int i = 0; i < n * n; i++) {
     if (i < 100) {
     }
     if (C[i] * C[i] > 0.0001) {
      printf(
        "FAILURE: error in matrix multiply exceeds an acceptable margin\n");
      printf(
        "Off by: %f, from the reference: %f, at n = %d, m = %d, i = %d\n",
        C[i], C_ref[i], n, m, i);
      return -1;
     }
    }
    double Gflop_s; double seconds = -1.0;
    for (int n_iterations = 1; seconds < 0.1; n_iterations *= 2) {
     sgemm(m, n, m, A, C);
     struct timeval start; struct timeval end;
     gettimeofday(&start, ((void *)0) );
     for (int i = 0; i < n_iterations; i++)
      sgemm(m, n, m, A, C);
     gettimeofday(&end, ((void *)0) );
     seconds = (end.tv_sec - start.tv_sec)
       + 1.0e-6 * (end.tv_usec - start.tv_usec);
     Gflop_s = 2e-9 * n_iterations * m * n * n / seconds;
    }
    printf("n = %d, m =  %d \t %g Gflop/s\n", n, m, Gflop_s);
    counter++;
    sum += Gflop_s;
    free(C_ref);
    free(C);
    free(A);
   }
  }
 printf("Average Gflops: %f\n", sum / counter);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: counter int

variable_types: sum float

variable_types: nStart int

variable_types: nEnd int

variable_types: mStart int

variable_types: mEnd int

variable_types: loopEnd int

variable_types: loop int

variable_types: seconds double

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
void *__fastcall net_run_server(void *a1)
{
int v2; // edi
int v3; // eax
int *v4; // rax
char *v5; // rax
socklen_t addr_len; // [rsp+0h] [rbp-44Ch] BYREF
char buf[16]; // [rsp+4h] [rbp-448h] BYREF
struct sockaddr addr; // [rsp+14h] [rbp-438h] BYREF
char v10[1064]; // [rsp+24h] [rbp-428h] BYREF

if ( !*((_BYTE *)a1 + 32) )
return 0LL;
do
{
while ( 1 )
{
v2 = *((_DWORD *)a1 + 4);
addr_len = 16;
v3 = recvfrom(v2, v10, 0x400uLL, 0, &addr, &addr_len);
if ( v3 == -1 )
break;
v10[v3] = 0;
inet_ntop(2, &addr.sa_data[2], buf, 0x10u);
e2log(1LL, "Message from %s: %s", buf, v10);
if ( !*((_BYTE *)a1 + 32) )
return 0LL;
}
v4 = _errno_location();
v5 = strerror(*v4);
e2log(2LL, "recvfrom: %s", v5);
}
while ( *((_BYTE *)a1 + 32) );
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func1(void *a1)
{
int v2; // edi
int v3; // eax
int *v4; // rax
char *v5; // rax
socklen_t addr_len; // [rsp+0h] [rbp-44Ch] BYREF
char buf[16]; // [rsp+4h] [rbp-448h] BYREF
struct sockaddr addr; // [rsp+14h] [rbp-438h] BYREF
char v10[1064]; // [rsp+24h] [rbp-428h] BYREF

if ( !*((_BYTE *)a1 + 32) )
return 0LL;
do
{
while ( 1 )
{
v2 = *((_DWORD *)a1 + 4);
addr_len = 16;
v3 = recvfrom(v2, v10, 0x400uLL, 0, &addr, &addr_len);
if ( v3 == -1 )
break;
v10[v3] = 0;
inet_ntop(2, &addr.sa_data[2], buf, 0x10u);
e2log(1LL, "Message from %s: %s", buf, v10);
if ( !*((_BYTE *)a1 + 32) )
return 0LL;
}
v4 = _errno_location();
v5 = strerror(*v4);
e2log(2LL, "recvfrom: %s", v5);
}
while ( *((_BYTE *)a1 + 32) );
return 0LL;
}

original_code:
static void * net_run_server(void *arg)
{
 char buffer[1024];
 char addrbuff[16];
 net_server *server = (net_server *)arg;
 struct sockaddr from;
 int alen, rlen;
 while(server->running) {
  alen = sizeof(from);
  rlen = recvfrom(server->socket, buffer, 1024, 0, &from, &alen);
  if (rlen == -1)
  {
   e2log(LOG_ERR, "recvfrom: %s", strerror((*__errno_location ())));
  }
  else
  {
   buffer[rlen] = 0;
   inet_ntop(2,
     &((struct sockaddr_in *)&from)->sin_addr,
     addrbuff,
     16);
   e2log(LOG_MON, "Message from %s: %s", addrbuff, buffer);
  }
 }
 return ((void *)0);
}

canonical_original_code:
static void *net_run_server(void *arg)
{
 char buffer[1024];
 char addrbuff[16];
 struct net_srv_t *server = (net_server *)arg;
 struct sockaddr from;
 int alen; int rlen;
 while(server->running) {
  alen = sizeof(from);
  rlen = recvfrom(server->socket, buffer, 1024, 0, &from, &alen);
  if (rlen == -1)
  {
   e2log(LOG_ERR, "recvfrom: %s", strerror((*__errno_location ())));
  }
  else
  {
   buffer[rlen] = 0;
   inet_ntop(2,
     &((struct sockaddr_in *)&from)->sin_addr,
     addrbuff,
     16);
   e2log(LOG_MON, "Message from %s: %s", addrbuff, buffer);
  }
 }
 return ((void *)0);
}

variable_types:
arg
void *

variable_types:
buffer
char [1024]

variable_types:
addrbuff
char [16]

variable_types: struct net_srv_t { struct net_cfg_t { short port; char *application_name; } config; int socket; unsigned long net_listener; char running; int connection_count; struct net_con_t { struct sockaddr { unsigned short sa_family; char sa_data[14]; } remote; enum net_status { NetStatus_Connecting=0, NetStatus_Connected=1, NetStatus_Disconnected=2 } status; } *connections; } *

variable_types: alen int

variable_types: rlen int

return_type: void *

user_defined_types: struct net_srv_t { struct net_cfg_t config; int socket; unsigned long net_listener; char running; int connection_count; struct net_con_t *connections; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct net_con_t { struct sockaddr remote; enum net_status status; }


decompiled_code:
void *__fastcall net_create_server(unsigned int a1, __int64 a2)
{
void *v2; // r12
__int16 v3; // ax
int v4; // edx
int v5; // eax
int v6; // eax
const char *v8; // rax
void *v9; // rdi
void *v10; // rdi
struct addrinfo *ai; // [rsp+0h] [rbp-68h] BYREF
char s[8]; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

v2 = malloc(0x30uLL);
e2log(1LL, "Creating server on port %u", a1);
v3 = _bswap_16(a1);
*((_QWORD *)v2 + 1) = a2;
*(_WORD *)v2 = v3;
v5 = socket(2, 2, v4);
*((_DWORD *)v2 + 4) = v5;
if ( v5 == -1 )
{
perror("socket");
v9 = v2;
v2 = 0LL;
free(v9);
return v2;
}
*(_OWORD *)&req.ai_flags = 0LL;
req.ai_socktype = 2;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 8uLL, "%u", a1);
v6 = getaddrinfo(0LL, s, &req, &ai);
if ( !v6 )
{
if ( bind(*((_DWORD *)v2 + 4), ai->ai_addr, ai->ai_addrlen) == -1 )
{
perror("bind");
v10 = v2;
v2 = 0LL;
free(v10);
}
freeaddrinfo(ai);
return v2;
}
v8 = gai_strerror(v6);
e2log(2LL, "getaddrinfo: %s", v8);
free(v2);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func2(unsigned int a1, __int64 a2)
{
void *v2; // r12
__int16 v3; // ax
int v4; // edx
int v5; // eax
int v6; // eax
const char *v8; // rax
void *v9; // rdi
void *v10; // rdi
struct addrinfo *ai; // [rsp+0h] [rbp-68h] BYREF
char s[8]; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF

v2 = malloc(0x30uLL);
e2log(1LL, "Creating server on port %u", a1);
v3 = func0(a1);
*((_QWORD *)v2 + 1) = a2;
*(_WORD *)v2 = v3;
v5 = socket(2, 2, v4);
*((_DWORD *)v2 + 4) = v5;
if ( v5 == -1 )
{
perror("socket");
v9 = v2;
v2 = 0LL;
free(v9);
return v2;
}
*(_OWORD *)&req.ai_flags = 0LL;
req.ai_socktype = 2;
req.ai_flags = 1;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
snprintf(s, 8uLL, "%u", a1);
v6 = getaddrinfo(0LL, s, &req, &ai);
if ( !v6 )
{
if ( bind(*((_DWORD *)v2 + 4), ai->ai_addr, ai->ai_addrlen) == -1 )
{
perror("bind");
v10 = v2;
v2 = 0LL;
free(v10);
}
freeaddrinfo(ai);
return v2;
}
v8 = gai_strerror(v6);
e2log(2LL, "getaddrinfo: %s", v8);
free(v2);
return 0LL;
}

original_code:
net_server *net_create_server(int port, const char *application_name)
{
 char buff[8];
 int status;
 struct addrinfo hints, *res;
 net_server *ret = malloc(sizeof(net_server));
 e2log(LOG_MON, "Creating server on port %u", (int)port);
 ret->config.port = htons(port);
 ret->config.application_name = application_name;
 ret->socket = socket(2, SOCK_DGRAM, 0);
 if (ret->socket == -1)
 {
  perror("socket");
  free(ret);
  return ((void *)0);
 }
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_DGRAM;
 hints.ai_flags = 0x0001;
 snprintf(buff, 8, "%u", port);
 status = getaddrinfo(((void *)0), buff, &hints, &res);
 if (status != 0)
 {
  e2log(LOG_ERR, "getaddrinfo: %s", gai_strerror(status));
  free(ret);
  return ((void *)0);
 }
 if (bind(ret->socket, res->ai_addr, res->ai_addrlen) == -1)
 {
  perror("bind");
  free(ret);
  freeaddrinfo(res);
  return ((void *)0);
 }
 freeaddrinfo(res);
 return ret;
}

canonical_original_code:
struct net_srv_t *net_create_server(int port, char *application_name)
{
 char buff[8];
 int status;
 struct addrinfo hints; struct addrinfo *res;
 struct net_srv_t *ret = malloc(sizeof(net_server));
 e2log(LOG_MON, "Creating server on port %u", (int)port);
 ret->config.port = htons(port);
 ret->config.application_name = application_name;
 ret->socket = socket(2, SOCK_DGRAM, 0);
 if (ret->socket == -1)
 {
  perror("socket");
  free(ret);
  return ((void *)0);
 }
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_DGRAM;
 hints.ai_flags = 0x0001;
 snprintf(buff, 8, "%u", port);
 status = getaddrinfo(((void *)0), buff, &hints, &res);
 if (status != 0)
 {
  e2log(LOG_ERR, "getaddrinfo: %s", gai_strerror(status));
  free(ret);
  return ((void *)0);
 }
 if (bind(ret->socket, res->ai_addr, res->ai_addrlen) == -1)
 {
  perror("bind");
  free(ret);
  freeaddrinfo(res);
  return ((void *)0);
 }
 freeaddrinfo(res);
 return ret;
}

variable_types: port int

variable_types:
buff
char [8]

variable_types: status int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

return_type: struct net_srv_t { struct net_cfg_t { short port; char *application_name; } config; int socket; unsigned long net_listener; char running; int connection_count; struct net_con_t { struct sockaddr { unsigned short sa_family; char sa_data[14]; } remote; enum net_status { NetStatus_Connecting=0, NetStatus_Connected=1, NetStatus_Disconnected=2 } status; } *connections; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


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

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

original_code:
void net_free_server(net_server *server)
{
 if (server)
 {
  free(server);
 }
}

canonical_original_code:
void net_free_server(struct net_srv_t *server)
{
 if (server)
 {
  free(server);
 }
}

user_defined_types: struct net_cfg_t { short port; char *application_name; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: enum net_status { NetStatus_Connecting=0, NetStatus_Connected=1, NetStatus_Disconnected=2 }


decompiled_code:
int __fastcall net_start_server(void *arg)
{
int result; // eax

if ( !arg )
return e2log(2LL, "net_start_server: null server");
*((_BYTE *)arg + 32) = 1;
result = pthread_create((pthread_t *)arg + 3, 0LL, net_run_server, arg);
if ( result )
result = e2log(2LL, "net_start_server: failed creating thread");
return result;
}

canonical_decompiled_code:
int __fastcall func4(void *arg)
{
int result; // eax

if ( !arg )
return e2log(2LL, "net_start_server: null server");
*((_BYTE *)arg + 32) = 1;
result = pthread_create((pthread_t *)arg + 3, 0LL, net_run_server, arg);
if ( result )
result = e2log(2LL, "net_start_server: failed creating thread");
return result;
}

original_code:
void net_start_server(net_server *server, int backlog)
{
 if (!server)
 {
  e2log(LOG_ERR, "net_start_server: null server");
  return;
 }
 server->running = 1;
 if (pthread_create(&server->net_listener, ((void *)0), &net_run_server, server)) {
  e2log(LOG_ERR, "net_start_server: failed creating thread");
  return;
 }
}

canonical_original_code:
void net_start_server(struct net_srv_t *server, int backlog)
{
 if (!server)
 {
  e2log(LOG_ERR, "net_start_server: null server");
  return;
 }
 server->running = 1;
 if (pthread_create(&server->net_listener, ((void *)0), &net_run_server, server)) {
  e2log(LOG_ERR, "net_start_server: failed creating thread");
  return;
 }
}

variable_types: backlog int


decompiled_code:
int __fastcall net_stop_server(__int64 a1)
{
*(_BYTE *)(a1 + 32) = 0;
return pthread_join(*(_QWORD *)(a1 + 24), 0LL);
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
*(_BYTE *)(a1 + 32) = 0;
return pthread_join(*(_QWORD *)(a1 + 24), 0LL);
}

original_code:
void net_stop_server(net_server *server, const char *reason)
{
 server->running = 0;
 pthread_join(server->net_listener, ((void *)0));
}

canonical_original_code:
void net_stop_server(struct net_srv_t *server, char *reason)
{
 server->running = 0;
 pthread_join(server->net_listener, ((void *)0));
}

variable_types:
reason
char *


decompiled_code:
int e2log(int a1, const char *a2, ...)
{
struct tm *v2; // rax
time_t v4; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v4 = time(0LL);
v2 = localtime(&v4);
printf(
"[%04i/%02i/%02i %02i:%02i:%02i] [%s] ",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday,
(unsigned int)v2->tm_hour,
(unsigned int)v2->tm_min,
(unsigned int)v2->tm_sec,
log_level_names[a1]);
vprintf(a2, arg);
return putchar(10);
}

canonical_decompiled_code:
int func0(int a1, const char *a2, ...)
{
struct tm *v2; // rax
time_t v4; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
v4 = time(0LL);
v2 = localtime(&v4);
printf(
"[%04i/%02i/%02i %02i:%02i:%02i] [%s] ",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday,
(unsigned int)v2->tm_hour,
(unsigned int)v2->tm_min,
(unsigned int)v2->tm_sec,
log_level_names[a1]);
vprintf(a2, arg);
return putchar(10);
}

original_code:
void e2log(enum LOG_LEVEL lvl, const char *fmt, ...) {
 va_list ap;
 __builtin_va_start(ap,fmt);
 time_t t;
 t = time(((void *)0));
 struct tm *tm = localtime(&t);
 printf("[%04i/%02i/%02i %02i:%02i:%02i] [%s] ",
  tm->tm_year+1900,
  tm->tm_mon+1,
  tm->tm_mday,
  tm->tm_hour,
  tm->tm_min,
  tm->tm_sec,
  log_level_names[lvl]
 );
 vprintf(fmt, ap);
 printf("\n");
 __builtin_va_end(ap);
}

canonical_original_code:
void e2log(enum LOG_LEVEL lvl, char *fmt, ...) {
 __builtin_va_list ap;
 __builtin_va_start(ap,fmt);
 long t;
 t = time(((void *)0));
 struct tm *tm = localtime(&t);
 printf("[%04i/%02i/%02i %02i:%02i:%02i] [%s] ",
  tm->tm_year+1900,
  tm->tm_mon+1,
  tm->tm_mday,
  tm->tm_hour,
  tm->tm_min,
  tm->tm_sec,
  log_level_names[lvl]
 );
 vprintf(fmt, ap);
 printf("\n");
 __builtin_va_end(ap);
}

variable_types: enum LOG_LEVEL { LOG_DBG=0, LOG_MON=1, LOG_ERR=2 }

variable_types:
fmt
char *

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


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

if ( *(_DWORD *)(a1 + 8) + a2 > *(_DWORD *)(a1 + 4) )
result = resize_message();
return result;
}

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

if ( *(_DWORD *)(a1 + 8) + a2 > *(_DWORD *)(a1 + 4) )
result = resize_message();
return result;
}

original_code:
static void require_len(net_outgoing_message *msg, int len)
{
 if (msg->pos + len <= msg->allocated_length) return;
 resize_message(msg);
}

canonical_original_code:
static void require_len(struct net_msgo_t *msg, int len)
{
 if (msg->pos + len <= msg->allocated_length) return;
 resize_message(msg);
}

variable_types: struct net_msgo_t { char flags; int allocated_length; int pos; char *buffer; } *

variable_types: len int


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

require_len(a1, 1);
result = *(int *)(a1 + 8);
*(_BYTE *)(*(_QWORD *)(a1 + 16) + result) = a2;
++*(_DWORD *)(a1 + 8);
return result;
}

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

func0(a1, 1);
result = *(int *)(a1 + 8);
*(_BYTE *)(*(_QWORD *)(a1 + 16) + result) = a2;
++*(_DWORD *)(a1 + 8);
return result;
}

original_code:
void net_msg_write_byte(net_outgoing_message *msg, char data)
{
 require_len(msg, sizeof(char));
 msg->buffer[msg->pos] = data;
 msg->pos += sizeof(char);
}

canonical_original_code:
void net_msg_write_byte(struct net_msgo_t *msg, char data)
{
 require_len(msg, sizeof(char));
 msg->buffer[msg->pos] = data;
 msg->pos += sizeof(char);
}

variable_types: data char

user_defined_types: struct net_msgo_t { char flags; int allocated_length; int pos; char *buffer; }


decompiled_code:
__int64 __fastcall net_msg_write_int16(__int64 a1, __int16 a2)
{
__int16 v2; // r8
int v3; // eax
__int64 result; // rax

require_len(a1, 2);
v2 = _bswap_16(a2);
v3 = *(_DWORD *)(a1 + 8);
*(_WORD *)(*(_QWORD *)(a1 + 16) + v3) = v2;
result = (unsigned int)(v3 + 2);
*(_DWORD *)(a1 + 8) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int16 a2)
{
__int16 v2; // r8
int v3; // eax
__int64 result; // rax

func0(a1, 2);
v2 = func1(a2);
v3 = *(_DWORD *)(a1 + 8);
*(_WORD *)(*(_QWORD *)(a1 + 16) + v3) = v2;
result = (unsigned int)(v3 + 2);
*(_DWORD *)(a1 + 8) = result;
return result;
}

original_code:
void net_msg_write_int16(net_outgoing_message *msg, int16_t data)
{
 require_len(msg, sizeof(int16_t));
 *((int16_t *)(msg->buffer + msg->pos)) = htons(data);
 msg->pos += sizeof(int16_t);
}

canonical_original_code:
void net_msg_write_int16(struct net_msgo_t *msg, short data)
{
 require_len(msg, sizeof(short));
 *((short *)(msg->buffer + msg->pos)) = htons(data);
 msg->pos += sizeof(short);
}

variable_types: data short


decompiled_code:
__int64 __fastcall net_msg_write_int32(__int64 a1, unsigned int a2)
{
int v2; // er8
__int64 result; // rax

require_len(a1, 4);
v2 = _bswap_32(a2);
result = *(int *)(a1 + 8);
*(_DWORD *)(*(_QWORD *)(a1 + 16) + result) = v2;
*(_DWORD *)(a1 + 8) += 4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
int v2; // er8
__int64 result; // rax

func0(a1, 4);
v2 = func2(a2);
result = *(int *)(a1 + 8);
*(_DWORD *)(*(_QWORD *)(a1 + 16) + result) = v2;
*(_DWORD *)(a1 + 8) += 4;
return result;
}

original_code:
void net_msg_write_int32(net_outgoing_message *msg, int32_t data)
{
 require_len(msg, sizeof(int32_t));
 *((int32_t *)(msg->buffer + msg->pos)) = htonl(data);
 msg->pos += sizeof(int32_t);
}

canonical_original_code:
void net_msg_write_int32(struct net_msgo_t *msg, int data)
{
 require_len(msg, sizeof(int));
 *((int *)(msg->buffer + msg->pos)) = htonl(data);
 msg->pos += sizeof(int);
}

variable_types: data int


decompiled_code:
char *__fastcall net_msg_write_string(__int64 a1, const char *a2)
{
__int16 v2; // ax
int v3; // er13
__int16 v4; // bp
char *result; // rax

v2 = strlen(a2);
v3 = v2;
v4 = v2;
require_len(a1, v2 + 2);
net_msg_write_int16(a1, v3);
result = strncpy((char *)(*(_QWORD *)(a1 + 16) + *(int *)(a1 + 8)), a2, v4);
*(_DWORD *)(a1 + 8) += v3;
return result;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1, const char *a2)
{
__int16 v2; // ax
int v3; // er13
__int16 v4; // bp
char *result; // rax

v2 = strlen(a2);
v3 = v2;
v4 = v2;
func0(a1, v2 + 2);
func4(a1, v3);
result = strncpy((char *)(*(_QWORD *)(a1 + 16) + *(int *)(a1 + 8)), a2, v4);
*(_DWORD *)(a1 + 8) += v3;
return result;
}

original_code:
void net_msg_write_string(net_outgoing_message *msg, const char *data)
{
 short slen = strlen(data);
 require_len(msg, slen + sizeof(int16_t));
 net_msg_write_int16(msg, slen);
 strncpy(msg->buffer + msg->pos, data, (size_t)slen);
 msg->pos += slen;
}

canonical_original_code:
void net_msg_write_string(struct net_msgo_t *msg, char *data)
{
 short slen = strlen(data);
 require_len(msg, slen + sizeof(short));
 net_msg_write_int16(msg, slen);
 strncpy(msg->buffer + msg->pos, data, (unsigned long)slen);
 msg->pos += slen;
}

variable_types:
data
char *

variable_types: slen short


decompiled_code:
// attributes: thunk
__int64 __fastcall net_msg_write_fix(__int64 a1, unsigned int a2)
{
return net_msg_write_int32(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
return func5(a1, a2);
}

original_code:
void net_msg_write_fix(net_outgoing_message *msg, fix data)
{
 net_msg_write_int32(msg, (int32_t)data);
}

canonical_original_code:
void net_msg_write_fix(struct net_msgo_t *msg, int data)
{
 net_msg_write_int32(msg, (int)data);
}


original_code:
char net_msg_read_byte(net_incoming_message *msg)
{
 return msg->buffer[msg->pos++];
}

canonical_original_code:
char net_msg_read_byte(struct net_msgi_t *msg)
{
 return msg->buffer[msg->pos++];
}

variable_types: struct net_msgi_t { enum message_type { NetMsg_Error=0, NetMsg_Connect=1, NetMsg_ConnectResponse=2, NetMsg_StatusChanged=3, NetMsg_Data=4 } type; char flags; struct net_con_t { struct sockaddr { unsigned short sa_family; char sa_data[14]; } remote; enum net_status { NetStatus_Connecting=0, NetStatus_Connected=1, NetStatus_Disconnected=2 } status; } *connection; int len; int pos; char *buffer; } *

return_type: char

user_defined_types: struct net_msgi_t { enum message_type type; char flags; struct net_con_t *connection; int len; int pos; char *buffer; }


decompiled_code:
__int16 __fastcall net_msg_read_int16(__int64 a1)
{
__int16 result; // ax
__int64 v2; // rdx
int v3; // ecx

result = _bswap_16(*(_WORD *)(*(_QWORD *)(a1 + 24) + *(int *)(a1 + 20)));
*(_DWORD *)(v2 + 20) = v3;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func9(__int64 a1)
{
__int16 result; // ax
__int64 v2; // rdx
int v3; // ecx

result = func1(*(_WORD *)(*(_QWORD *)(a1 + 24) + *(int *)(a1 + 20)));
*(_DWORD *)(v2 + 20) = v3;
return result;
}

original_code:
int16_t net_msg_read_int16(net_incoming_message *msg)
{
 int16_t ret = ntohs(*((int16_t *)(msg->buffer+msg->pos)));
 msg->pos += sizeof(int16_t);
 return ret;
}

canonical_original_code:
short net_msg_read_int16(struct net_msgi_t *msg)
{
 short ret = ntohs(*((int16_t *)(msg->buffer+msg->pos)));
 msg->pos += sizeof(short);
 return ret;
}

variable_types: ret short

user_defined_types: enum message_type { NetMsg_Error=0, NetMsg_Connect=1, NetMsg_ConnectResponse=2, NetMsg_StatusChanged=3, NetMsg_Data=4 }


decompiled_code:
__int64 __fastcall net_msg_read_int32(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx
int v3; // ecx

result = _bswap_32(*(_DWORD *)(*(_QWORD *)(a1 + 24) + *(int *)(a1 + 20)));
*(_DWORD *)(v2 + 20) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx
int v3; // ecx

result = func2(*(_DWORD *)(*(_QWORD *)(a1 + 24) + *(int *)(a1 + 20)));
*(_DWORD *)(v2 + 20) = v3;
return result;
}

original_code:
int32_t net_msg_read_int32(net_incoming_message *msg)
{
 int32_t ret = ntohl(*((int32_t *)(msg->buffer+msg->pos)));
 msg->pos += sizeof(int32_t);
 return ret;
}

canonical_original_code:
int net_msg_read_int32(struct net_msgi_t *msg)
{
 int ret = ntohl(*((int32_t *)(msg->buffer+msg->pos)));
 msg->pos += sizeof(int);
 return ret;
}

variable_types: ret int


decompiled_code:
char *__fastcall net_msg_read_string(__int64 a1)
{
size_t v1; // r13
char *v2; // rax
__int64 v3; // r12
char *result; // rax

v1 = net_msg_read_int16(a1);
v2 = (char *)malloc((int)v1 + 1);
v3 = *(int *)(a1 + 20);
result = strncpy(v2, (const char *)(*(_QWORD *)(a1 + 24) + v3), v1);
result[v1] = 0;
*(_DWORD *)(a1 + 20) = v1 + v3;
return result;
}

canonical_decompiled_code:
char *__fastcall func11(__int64 a1)
{
size_t v1; // r13
char *v2; // rax
__int64 v3; // r12
char *result; // rax

v1 = func9(a1);
v2 = (char *)malloc((int)v1 + 1);
v3 = *(int *)(a1 + 20);
result = strncpy(v2, (const char *)(*(_QWORD *)(a1 + 24) + v3), v1);
result[v1] = 0;
*(_DWORD *)(a1 + 20) = v1 + v3;
return result;
}

original_code:
char *net_msg_read_string(net_incoming_message *msg)
{
 int slen;
 char *buff;
 slen = net_msg_read_int16(msg);
 buff = malloc(slen+1);
 strncpy(buff, msg->buffer+msg->pos, slen);
 buff[slen] = 0;
 msg->pos += slen;
 return buff;
}

canonical_original_code:
char *net_msg_read_string(struct net_msgi_t *msg)
{
 int slen;
 char *buff;
 slen = net_msg_read_int16(msg);
 buff = malloc(slen+1);
 strncpy(buff, msg->buffer+msg->pos, slen);
 buff[slen] = 0;
 msg->pos += slen;
 return buff;
}

variable_types: slen int

variable_types:
buff
char *

return_type: char *


decompiled_code:
// attributes: thunk
__int64 __fastcall net_msg_read_fix(__int64 a1)
{
return net_msg_read_int32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return func10(a1);
}

original_code:
fix net_msg_read_fix(net_incoming_message *msg)
{
 return (fix)(net_msg_read_int32(msg));
}

canonical_original_code:
int net_msg_read_fix(struct net_msgi_t *msg)
{
 return (fix)(net_msg_read_int32(msg));
}


original_code:
int resize_message(net_outgoing_message *msg)
{
 char *b;
 int new_size = msg->allocated_length << 1;
 b = realloc(msg->buffer, new_size);
 if (b == ((void *)0))
  return 1;
 msg->allocated_length = new_size;
 if (b == msg->buffer) return 0;
 msg->buffer = b;
 return 0;
}

canonical_original_code:
int resize_message(struct net_msgo_t *msg)
{
 char *b;
 int new_size = msg->allocated_length << 1;
 b = realloc(msg->buffer, new_size);
 if (b == ((void *)0))
  return 1;
 msg->allocated_length = new_size;
 if (b == msg->buffer) return 0;
 msg->buffer = b;
 return 0;
}

variable_types:
b
char *


decompiled_code:
void __fastcall net_free_outgoing_message(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void net_free_outgoing_message(net_outgoing_message *msg)
{
 if (msg->buffer) free(msg->buffer);
 msg->buffer = ((void *)0);
 free(msg);
}

canonical_original_code:
void net_free_outgoing_message(struct net_msgo_t *msg)
{
 if (msg->buffer) free(msg->buffer);
 msg->buffer = ((void *)0);
 free(msg);
}


decompiled_code:
void __fastcall net_free_incoming_message(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 3);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void net_free_incoming_message(net_incoming_message *msg)
{
 if (msg->buffer) free(msg->buffer);
 msg->buffer = ((void *)0);
 free(msg);
}

canonical_original_code:
void net_free_incoming_message(struct net_msgi_t *msg)
{
 if (msg->buffer) free(msg->buffer);
 msg->buffer = ((void *)0);
 free(msg);
}


repo: palexster/Genetic

original_code:
void parent_selection(long *parents,population_t *pop){
    char *chosen=(char *)malloc(sizeof(char)*pop->pop_dim);
    long i,tmp;
    for(i=0;i<pop->pop_dim;i++)
        chosen[i]=FALSE;
    for(i=0;i<pop->elite;i++)
        parents[i]=-i-1;
    for(;i<pop->gen_n;i++){
        tmp=rand()%(pop->pop_dim-pop->elite)+pop->elite;
        while(chosen[tmp])
            tmp=((tmp+1)%pop->pop_dim)+(pop->elite*(tmp/pop->pop_dim));
        parents[i]=-(tmp+1);
        chosen[tmp]=TRUE;
    }
    free(chosen);
    return;
}

canonical_original_code:
void parent_selection(long *parents, struct population_s *pop){
    char *chosen = (char *)malloc(sizeof(char)*pop->pop_dim);
    long i; long tmp;
    for(i=0;i<pop->pop_dim;i++)
        chosen[i]=FALSE;
    for(i=0;i<pop->elite;i++)
        parents[i]=-i-1;
    for(;i<pop->gen_n;i++){
        tmp=rand()%(pop->pop_dim-pop->elite)+pop->elite;
        while(chosen[tmp])
            tmp=((tmp+1)%pop->pop_dim)+(pop->elite*(tmp/pop->pop_dim));
        parents[i]=-(tmp+1);
        chosen[tmp]=TRUE;
    }
    free(chosen);
    return;
}

variable_types:
parents
long *

variable_types: struct population_s { struct solution_s { unsigned char ***matrice_pezzi; unsigned short fitness; } *soluzioni; double bests[2][3]; long current_iteration; long pop_dim; long gen_n; long elite; long mutation; } *

variable_types:
chosen
char *

variable_types: i long

variable_types: tmp long

user_defined_types: struct population_s { struct solution_s *soluzioni; double bests[2][3]; long current_iteration; long pop_dim; long gen_n; long elite; long mutation; }


original_code:
void offspring_generation(int **pieces,int npieces,population_t *pop,long *parents,solution_t *offspring,int row, int col){
    long i,j,tmp;
    long cnt;
    long gen[2];

#pragma omp parallel default(none) shared(pieces,npieces,pop,parents,offspring,row,col) firstprivate(i,j,cnt,tmp,gen)
{

#pragma omp for
    for(i=0;i<pop->gen_n;i+=2){
        j=i+1;

#pragma omp critical (print_tid)
      {
        for(cnt=0;cnt<2;cnt++){
                tmp=rand()%pop->gen_n;
                while(parents[tmp]>0)
                        tmp=((tmp+1)%pop->gen_n);
                gen[cnt]=tmp;
                parents[tmp]*=-1;
        }
      }
        offspring[i].matrice_pezzi=matalloc(row,col);
        offspring[j].matrice_pezzi=matalloc(row,col);
        crossover(&pop->soluzioni[parents[gen[0]]-1],&pop->soluzioni[parents[gen[1]]-1],&offspring[i],&offspring[j],pieces,npieces,row,col);
        offspring[i].fitness=fitness_solution_evaluation(pieces,&offspring[i],npieces,row,col);
        offspring[j].fitness=fitness_solution_evaluation(pieces,&offspring[j],npieces,row,col);
    }
    }
    return;
}

canonical_original_code:
void offspring_generation(int **pieces, int npieces, struct population_s *pop, long *parents, struct solution_s *offspring, int row, int col){
    long i; long j; long tmp;
    long cnt;
    long gen[2];

#pragma omp parallel default(none) shared(pieces,npieces,pop,parents,offspring,row,col) firstprivate(i,j,cnt,tmp,gen)
{

#pragma omp for
    for(i=0;i<pop->gen_n;i+=2){
        j=i+1;

#pragma omp critical (print_tid)
      {
        for(cnt=0;cnt<2;cnt++){
                tmp=rand()%pop->gen_n;
                while(parents[tmp]>0)
                        tmp=((tmp+1)%pop->gen_n);
                gen[cnt]=tmp;
                parents[tmp]*=-1;
        }
      }
        offspring[i].matrice_pezzi=matalloc(row,col);
        offspring[j].matrice_pezzi=matalloc(row,col);
        crossover(&pop->soluzioni[parents[gen[0]]-1],&pop->soluzioni[parents[gen[1]]-1],&offspring[i],&offspring[j],pieces,npieces,row,col);
        offspring[i].fitness=fitness_solution_evaluation(pieces,&offspring[i],npieces,row,col);
        offspring[j].fitness=fitness_solution_evaluation(pieces,&offspring[j],npieces,row,col);
    }
    }
    return;
}

variable_types:
pieces
int **

variable_types: npieces int

variable_types:
offspring
struct solution_s *

variable_types: row int

variable_types: col int

variable_types: j long

variable_types: cnt long

variable_types:
gen
long [2]

user_defined_types: struct solution_s { unsigned char ***matrice_pezzi; unsigned short fitness; }


original_code:
void sub1(population_t *pop,solution_t *offspring,int row, int col){
    char *chosen=(char *)malloc(sizeof(char)*pop->pop_dim);
    long i,cnt;
    float tmp_rnd,
            sum_inv_fit,
            pi;
    sum_inv_fit=0;
    for(i=0;i<pop->pop_dim;i++){
        chosen[i]=FALSE;
        sum_inv_fit+=(float)1/(float)pop->soluzioni[i].fitness;
    }
    cnt=0;
    for(i=0;cnt<pop->gen_n;i=((i+1)%pop->pop_dim)){
        tmp_rnd=(float)rand()/(float)2147483647;
        pi=((float)1/(float)pop->soluzioni[i].fitness);
        if((!chosen[i])&&(tmp_rnd<pi)){
            dealloc_soluzioni(&pop->soluzioni[i],row,col);
            pop->soluzioni[i]=offspring[cnt++];
            chosen[i]=TRUE;
        }
    }
    free(chosen);
}

canonical_original_code:
void sub1(struct population_s *pop, struct solution_s *offspring, int row, int col){
    char *chosen = (char *)malloc(sizeof(char)*pop->pop_dim);
    long i; long cnt;
    float tmp_rnd; float sum_inv_fit; float pi;
    sum_inv_fit=0;
    for(i=0;i<pop->pop_dim;i++){
        chosen[i]=FALSE;
        sum_inv_fit+=(float)1/(float)pop->soluzioni[i].fitness;
    }
    cnt=0;
    for(i=0;cnt<pop->gen_n;i=((i+1)%pop->pop_dim)){
        tmp_rnd=(float)rand()/(float)2147483647;
        pi=((float)1/(float)pop->soluzioni[i].fitness);
        if((!chosen[i])&&(tmp_rnd<pi)){
            dealloc_soluzioni(&pop->soluzioni[i],row,col);
            pop->soluzioni[i]=offspring[cnt++];
            chosen[i]=TRUE;
        }
    }
    free(chosen);
}

variable_types: pi float


original_code:
void sub2(population_t *pop,solution_t *offspring,int row, int col){
    char *chosen=(char *)malloc(sizeof(char)*pop->pop_dim);
    long i,cnt;
    double tmp_rnd,
            sum_inv_fit;
    double *distribution=(double *)malloc(sizeof(double)*pop->pop_dim);;
    sum_inv_fit=0;
    for(i=0;i<pop->pop_dim;i++){
        chosen[i]=FALSE;
        sum_inv_fit+=(double)1/(double)pop->soluzioni[i].fitness;
    }
    distribution[0]=(double)1/(double)pop->soluzioni[0].fitness/sum_inv_fit;
    for(i=1;i<pop->pop_dim;i++){
        distribution[i]=distribution[i-1]+((double)1/(double)pop->soluzioni[i].fitness)/sum_inv_fit;
    }
    for(cnt=0;cnt<pop->gen_n;cnt++){
        tmp_rnd=(double)rand()/(double)2147483647;
        for(i=0;(distribution[i]<tmp_rnd)&&(i<pop->pop_dim);i++);
        while(chosen[i])
            i=(i+1)%pop->pop_dim;
        dealloc_soluzioni(&pop->soluzioni[i],row,col);
        pop->soluzioni[i]=offspring[cnt];
        chosen[i]=TRUE;
    }
    free(chosen);
    free(distribution);
}

canonical_original_code:
void sub2(struct population_s *pop, struct solution_s *offspring, int row, int col){
    char *chosen = (char *)malloc(sizeof(char)*pop->pop_dim);
    long i; long cnt;
    double tmp_rnd; double sum_inv_fit;
    double *distribution = (double *)malloc(sizeof(double)*pop->pop_dim);;
    sum_inv_fit=0;
    for(i=0;i<pop->pop_dim;i++){
        chosen[i]=FALSE;
        sum_inv_fit+=(double)1/(double)pop->soluzioni[i].fitness;
    }
    distribution[0]=(double)1/(double)pop->soluzioni[0].fitness/sum_inv_fit;
    for(i=1;i<pop->pop_dim;i++){
        distribution[i]=distribution[i-1]+((double)1/(double)pop->soluzioni[i].fitness)/sum_inv_fit;
    }
    for(cnt=0;cnt<pop->gen_n;cnt++){
        tmp_rnd=(double)rand()/(double)2147483647;
        for(i=0;(distribution[i]<tmp_rnd)&&(i<pop->pop_dim);i++);
        while(chosen[i])
            i=(i+1)%pop->pop_dim;
        dealloc_soluzioni(&pop->soluzioni[i],row,col);
        pop->soluzioni[i]=offspring[cnt];
        chosen[i]=TRUE;
    }
    free(chosen);
    free(distribution);
}

variable_types:
distribution
double *


substitution

decompiled_code:
// attributes: thunk
void __fastcall substitution(__int64 *a1, __int64 a2, unsigned int a3, unsigned int a4)
{
sub2(a1, a2, a3, a4);
}

canonical_decompiled_code:
void __fastcall func5(__int64 *a1, __int64 a2, unsigned int a3, unsigned int a4)
{
func4(a1, a2, a3, a4);
}

original_code:
void substitution(population_t *pop,solution_t *offspring,int row, int col){
    sub2(pop,offspring,row,col);
}

canonical_original_code:
void substitution(struct population_s *pop, struct solution_s *offspring, int row, int col){
    sub2(pop,offspring,row,col);
}


decompiled_code:
void __fastcall light_mutation(__int64 a1, __int64 a2, _QWORD *a3, unsigned int a4, unsigned int a5)
{
__int64 v8; // rbx
int v9; // eax
__int64 v10; // rdi

if ( (__int64)a3[8] > 0 )
{
v8 = 0LL;
do
{
while ( 1 )
{
v9 = rand();
v10 = *a3 + 16 * v8;
if ( 1.0 / (double)*(unsigned __int16 *)(v10 + 8) > (double)v9 / 2147483647.0 )
break;
if ( a3[8] <= ++v8 )
return;
}
++v8;
random_rotate(v10, a4, a5);
}
while ( a3[8] > v8 );
}
}

original_code:
void light_mutation(int **pieces,int npieces,population_t *pop,int row, int col,int *border){
    long i;
    double tmp_rnd,
            pi;
    for(i=0;i<pop->pop_dim;i++){
        tmp_rnd=(double)rand()/(double)2147483647;
        pi=((double)1/(double)pop->soluzioni[i].fitness);
        if(tmp_rnd<pi){
            random_rotate(&(pop->soluzioni[i]),row,col);
        }
    }
}

canonical_original_code:
void light_mutation(int **pieces, int npieces, struct population_s *pop, int row, int col, int *border){
    long i;
    double tmp_rnd; double pi;
    for(i=0;i<pop->pop_dim;i++){
        tmp_rnd=(double)rand()/(double)2147483647;
        pi=((double)1/(double)pop->soluzioni[i].fitness);
        if(tmp_rnd<pi){
            random_rotate(&(pop->soluzioni[i]),row,col);
        }
    }
}

variable_types:
border
int *

variable_types: pi double


repo: pamolloy/pong

decompiled_code:
int __fastcall set_ticker(int a1)
{
int result; // eax
int *v2; // rax
struct itimerval v3; // [rsp+0h] [rbp-48h] BYREF
struct itimerval old; // [rsp+20h] [rbp-28h] BYREF

v3.it_interval.tv_sec = a1 / 1000;
v3.it_interval.tv_usec = 1000LL * (a1 % 1000);
v3.it_value = v3.it_interval;
result = setitimer(ITIMER_REAL, &v3, &old);
if ( result )
{
v2 = _errno_location();
printf("Error with timer..errno=%d\n", (unsigned int)*v2);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int result; // eax
int *v2; // rax
struct itimerval v3; // [rsp+0h] [rbp-48h] BYREF
struct itimerval old; // [rsp+20h] [rbp-28h] BYREF

v3.it_interval.tv_sec = a1 / 1000;
v3.it_interval.tv_usec = 1000LL * (a1 % 1000);
v3.it_value = v3.it_interval;
result = setitimer(ITIMER_REAL, &v3, &old);
if ( result )
{
v2 = _errno_location();
printf("Error with timer..errno=%d\n", (unsigned int)*v2);
exit(1);
}
return result;
}

original_code:
void set_ticker( int n_msecs )
{
    struct itimerval new_timeset, old_timeset;
    long n_sec, n_usecs;
    n_sec = n_msecs / 1000 ;
    n_usecs = ( n_msecs % 1000 ) * 1000L ;
    new_timeset.it_interval.tv_sec = n_sec;
    new_timeset.it_interval.tv_usec = n_usecs;
    new_timeset.it_value.tv_sec = n_sec ;
    new_timeset.it_value.tv_usec = n_usecs ;
    if ( setitimer( ITIMER_REAL, &new_timeset, &old_timeset ) != 0 ){
        printf("Error with timer..errno=%d\n", (*__errno_location ()) );
        exit(1);
    }
}

canonical_original_code:
void set_ticker(int n_msecs)
{
    struct itimerval new_timeset; struct itimerval old_timeset;
    long n_sec; long n_usecs;
    n_sec = n_msecs / 1000 ;
    n_usecs = ( n_msecs % 1000 ) * 1000L ;
    new_timeset.it_interval.tv_sec = n_sec;
    new_timeset.it_interval.tv_usec = n_usecs;
    new_timeset.it_value.tv_sec = n_sec ;
    new_timeset.it_value.tv_usec = n_usecs ;
    if ( setitimer( ITIMER_REAL, &new_timeset, &old_timeset ) != 0 ){
        printf("Error with timer..errno=%d\n", (*__errno_location ()) );
        exit(1);
    }
}

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


decompiled_code:
void my_handler()
{
set_ticker(0);
}

canonical_decompiled_code:
void func1()
{
func0(0);
}

original_code:
static void
my_handler(int s)
{
    set_ticker( 0 );
}

variable_types: s int


millisleep

decompiled_code:
int __fastcall millisleep(int a1)
{
signal(14, (__sighandler_t)my_handler);
set_ticker(a1);
return pause();
}

canonical_decompiled_code:
int __fastcall func2(int a1)
{
signal(14, (__sighandler_t)my_handler);
func0(a1);
return pause();
}

original_code:
void millisleep( int n )
{
    signal( 14 , my_handler);
    set_ticker( n );
    pause();
}

canonical_original_code:
void millisleep(int n)
{
    signal( 14 , my_handler);
    set_ticker( n );
    pause();
}

variable_types: n int


pong

decompiled_code:
_BOOL8 __fastcall pong(_DWORD *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1[1] < a2 )
result = *a1 > a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(_DWORD *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1[1] < a2 )
result = *a1 > a2;
return result;
}

original_code:
int pong ( struct bar *paddle, int x )
{
    if ( paddle->lower < x && x < paddle->upper )
        return 1;
    else
        return 0;
}

canonical_original_code:
int pong(struct bar *paddle, int x)
{
    if ( paddle->lower < x && x < paddle->upper )
        return 1;
    else
        return 0;
}

variable_types: struct bar { int upper; int lower; int len; } *

variable_types: x int


decompiled_code:
void add_tick()
{
++ticks;
}

canonical_decompiled_code:
void func0()
{
++ticks;
}

original_code:
void add_tick( int signal )
{
    ticks++;
}

canonical_original_code:
void add_tick(int signal)
{
    ticks++;
}

variable_types: signal int


decompiled_code:
__int64 setup_signal()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

signal(2, (__sighandler_t)((char *)add_tick + 1));
v1.sa_flags = 0;
v1.sa_handler = (__sighandler_t)add_tick;
sigemptyset(&v1.sa_mask);
sigaction(14, &v1, 0LL);
return set_ticker(20LL);
}

canonical_decompiled_code:
__int64 func2()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

signal(2, (__sighandler_t)((char *)add_tick + 1));
v1.sa_flags = 0;
v1.sa_handler = (__sighandler_t)add_tick;
sigemptyset(&v1.sa_mask);
sigaction(14, &v1, 0LL);
return set_ticker(20LL);
}

original_code:
void setup_signal()
{
    struct sigaction siginfo;
    signal(2, ((__sighandler_t) 1));
    siginfo.sa_flags = 0;
    siginfo.__sigaction_handler.sa_handler = add_tick;
    sigemptyset(&siginfo.sa_mask);
    sigaction(14, &siginfo, ((void *)0));
    set_ticker( 1000 / 50 );
}

canonical_original_code:
void setup_signal()
{
    struct sigaction siginfo;
    signal(2, ((void (*)(int)) 1));
    siginfo.sa_flags = 0;
    siginfo.__sigaction_handler.sa_handler = add_tick;
    sigemptyset(&siginfo.sa_mask);
    sigaction(14, &siginfo, ((void *)0));
    set_ticker( 1000 / 50 );
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


start

decompiled_code:
void start()
{
unsigned int v0; // eax

if ( !initscr() )
{
fwrite("initscr: failed to initialize curses", 1uLL, 0x24uLL, stderr);
exit(1);
}
noecho();
cbreak();
halfdelay(1);
nonl();
intrflush(0LL, 0);
if ( curs_set(0) == -1 )
{
fwrite("curs_set: failed to set cursor to invisible", 1uLL, 0x2BuLL, stderr);
exit(1);
}
v0 = getpid();
srand(v0);
}

canonical_decompiled_code:
void func3()
{
unsigned int v0; // eax

if ( !initscr() )
{
fwrite("initscr: failed to initialize curses", 1uLL, 0x24uLL, stderr);
exit(1);
}
noecho();
cbreak();
halfdelay(1);
nonl();
intrflush(0LL, 0);
if ( curs_set(0) == -1 )
{
fwrite("curs_set: failed to set cursor to invisible", 1uLL, 0x2BuLL, stderr);
exit(1);
}
v0 = getpid();
srand(v0);
}

original_code:
void start()
{
    if ( initscr() == ((void *)0) ) {
        fprintf(stderr, "initscr: failed to initialize curses");
        exit(1);
    }
    noecho();
    cbreak();
    halfdelay(1);
    nonl();
    intrflush(((void *)0), 0);
    if ( curs_set(0) == (-1) ) {
        fprintf(stderr, "curs_set: failed to set cursor to invisible");
        exit(1);
    }
    srand(getpid());
}


end

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

result = endwin();
if ( result == -1 )
{
fwrite("endwin: failed to restore terminal settings", 1uLL, 0x2BuLL, stderr);
exit(1);
}
return result;
}

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

result = endwin();
if ( result == -1 )
{
fwrite("endwin: failed to restore terminal settings", 1uLL, 0x2BuLL, stderr);
exit(1);
}
return result;
}

original_code:
void end()
{
    if ( endwin() == (-1) ) {
        fprintf(stderr, "endwin: failed to restore terminal settings");
        exit(1);
    }
}


main

repo: pamolloy/sttyl

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

program_name = (__int64)*argv;
if ( tcgetattr(0, &v3) != -1 )
{
if ( argc <= 1 )
print_all(&v3);
else
set_argvs(&v3);
exit(0);
}
perror("tcgetattr of stdin");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
struct termios v3; // [rsp+0h] [rbp-58h] BYREF

program_name = (__int64)*argv;
if ( tcgetattr(0, &v3) != -1 )
{
if ( argc <= 1 )
func7(&v3);
else
func11(&v3);
exit(0);
}
perror("tcgetattr of stdin");
exit(1);
}

original_code:
int main( int ac, char **av )
{
 struct termios ttyopts;
 program_name = av[0];
 if ( tcgetattr(0, &ttyopts) == -1 ) {
  perror("tcgetattr of stdin");
  exit(1);
 }
 if ( ac <= 1 ) {
  print_all(&ttyopts);
 }
 else {
  set_argvs(&ttyopts, ac, av);
 }
 exit(0);
}

canonical_original_code:
int main(int ac, char **av)
{
 struct termios ttyopts;
 program_name = av[0];
 if ( tcgetattr(0, &ttyopts) == -1 ) {
  perror("tcgetattr of stdin");
  exit(1);
 }
 if ( ac <= 1 ) {
  print_all(&ttyopts);
 }
 else {
  set_argvs(&ttyopts, ac, av);
 }
 exit(0);
}

variable_types: ac int

variable_types:
av
char **

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


decompiled_code:
__int64 __fastcall print_all(__int64 a1)
{
print_speed();
print_special(a1);
return print_setting(a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
func29();
func15(a1);
return func22(a1);
}

original_code:
void print_all( struct termios *ttyopts )
{
 print_speed(ttyopts);
 print_special(ttyopts);
 print_setting(ttyopts);
}

canonical_original_code:
void print_all(struct termios *ttyopts)
{
 print_speed(ttyopts);
 print_special(ttyopts);
 print_setting(ttyopts);
}

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


decompiled_code:
__int64 __fastcall check_speed(struct termios *termios_p, char *s2)
{
__int64 result; // rax

result = is_speed(s2);
if ( (_DWORD)result != -1 )
{
set_speed(termios_p);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(struct termios *termios_p, char *s2)
{
__int64 result; // rax

result = func27(s2);
if ( (_DWORD)result != -1 )
{
func28(termios_p);
result = 0LL;
}
return result;
}

original_code:
int check_speed( struct termios *ttyopts, char *av )
{
 int i = is_speed(av);
 if ( i != -1 ) {
  set_speed(ttyopts, i);
  return 0;
 }
 else {
  return -1;
 }
}

canonical_original_code:
int check_speed(struct termios *ttyopts, char *av)
{
 int i = is_speed(av);
 if ( i != -1 ) {
  set_speed(ttyopts, i);
  return 0;
 }
 else {
  return -1;
 }
}

variable_types:
av
char *

variable_types: i int

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


decompiled_code:
__int64 __fastcall check_special(struct termios *termios_p, char *s2, const char *a3)
{
__int64 result; // rax

result = is_special(s2);
if ( (_DWORD)result != -1 )
{
if ( !a3 )
{
fprintf(_bss_start, "%s: missing argument to `erase'\n", (const char *)program_name);
exit(1);
}
if ( (unsigned int)set_special(termios_p) == -1 )
{
fprintf(_bss_start, "%s: Invalid integer argument `%s'\n", (const char *)program_name, a3);
exit(1);
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(struct termios *termios_p, char *s2, const char *a3)
{
__int64 result; // rax

result = func12(s2);
if ( (_DWORD)result != -1 )
{
if ( !a3 )
{
fprintf(_bss_start, "%s: missing argument to `erase'\n", (const char *)program_name);
exit(1);
}
if ( (unsigned int)func13(termios_p) == -1 )
{
fprintf(_bss_start, "%s: Invalid integer argument `%s'\n", (const char *)program_name, a3);
exit(1);
}
result = 0LL;
}
return result;
}

original_code:
int check_special( struct termios *ttyopts, char *av, char *next)
{
 int i = is_special(av);
 if ( i != -1) {
  if ( next == ((void *)0) ) {
   fprintf(stderr, "%s: missing argument to `erase'\n",
     program_name);
   exit(1);
  }
  if ( set_special(ttyopts, i, next) == -1 ) {
   fprintf(stderr, "%s: Invalid integer argument `%s'\n",
     program_name, next);
   exit(1);
  }
  return 0;
 }
 return -1;
}

canonical_original_code:
int check_special(struct termios *ttyopts, char *av, char *next)
{
 int i = is_special(av);
 if ( i != -1) {
  if ( next == ((void *)0) ) {
   fprintf(stderr, "%s: missing argument to `erase'\n",
     program_name);
   exit(1);
  }
  if ( set_special(ttyopts, i, next) == -1 ) {
   fprintf(stderr, "%s: Invalid integer argument `%s'\n",
     program_name, next);
   exit(1);
  }
  return 0;
 }
 return -1;
}

variable_types:
next
char *


decompiled_code:
__int64 __fastcall check_setting(__int64 a1, char *a2)
{
unsigned int v2; // er12
char *v4; // rdi
__int64 result; // rax

v2 = 1;
v4 = a2;
if ( *a2 == 45 )
{
v4 = a2 + 1;
v2 = 0;
}
result = is_setting(v4);
if ( (_DWORD)result != -1 )
{
set_setting(a1, (unsigned int)result, v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char *a2)
{
unsigned int v2; // er12
char *v4; // rdi
__int64 result; // rax

v2 = 1;
v4 = a2;
if ( *a2 == 45 )
{
v4 = a2 + 1;
v2 = 0;
}
result = func16(v4);
if ( (_DWORD)result != -1 )
{
func17(a1, (unsigned int)result, v2);
result = 0LL;
}
return result;
}

original_code:
int check_setting( struct termios *ttyopts, char *av )
{
 int on = 1;
 if (av[0] == '-') {
  on = 0;
  av++;
 }
 int i = is_setting(av);
 if ( i != -1 ) {
  set_setting(ttyopts, i, on);
  return 0;
 }
 return -1;
}

canonical_original_code:
int check_setting(struct termios *ttyopts, char *av)
{
 int on = 1;
 if (av[0] == '-') {
  on = 0;
  av++;
 }
 int i = is_setting(av);
 if ( i != -1 ) {
  set_setting(ttyopts, i, on);
  return 0;
 }
 return -1;
}

variable_types: on int