decompiled_code:
__int64 __fastcall team_add_player(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = *(_DWORD *)(a1 + 64);
if ( v2 <= 0 )
return 0LL;
*(_QWORD *)(a2 + 8) = a1;
*(_DWORD *)(a1 + 64) = v2 - 1;
list_add_end();
return 1LL;
}

original_code:
_Bool team_add_player(t_team *team, t_player *player)
{
  if (team->available_slots <= 0)
    return 0;
  player->team = team;
  team->available_slots--;
  list_add_end(&team->players, player);
  return 1;
}

canonical_original_code:
_Bool team_add_player(struct s_team *team, struct s_player *player)
{
  if (team->available_slots <= 0)
    return 0;
  player->team = team;
  team->available_slots--;
  list_add_end(&team->players, player);
  return 1;
}

variable_types: struct s_player { int id; struct s_team *team; struct s_tile { struct s_list players; struct s_pos { int x; int y; } coord; struct s_inventory { int food; int linemate; int deraumere; int sibur; int mendiane; int phiras; int thystame; } ressources; } *tile; enum t_orientation { OR_NORTH=0, OR_EAST=1, OR_SOUTH=2, OR_WEST=3 } orientation; struct s_inventory inventory; int level; int life; } *


decompiled_code:
__int64 __fastcall team_remove_player(__int64 a1)
{
return list_pop(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return list_pop(a1 + 40);
}

original_code:
void team_remove_player(t_team *team, t_player *player)
{
  list_pop(&team->players, player);
}

canonical_original_code:
void team_remove_player(struct s_team *team, struct s_player *player)
{
  list_pop(&team->players, player);
}

variable_types: struct s_team { char name[-1]; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } players; int available_slots; int free_slots; } *

return_type: void

user_defined_types: struct s_team { char name[-1]; struct s_list players; int available_slots; int free_slots; }

user_defined_types: struct s_player { int id; struct s_team *team; struct s_tile *tile; enum t_orientation orientation; struct s_inventory inventory; int level; int life; }

user_defined_types: struct s_list { unsigned int size; struct s_list_node *head; struct s_list_node *tail; }

user_defined_types: enum t_orientation { OR_NORTH=0, OR_EAST=1, OR_SOUTH=2, OR_WEST=3 }

user_defined_types: struct s_tile { struct s_list players; struct s_pos coord; struct s_inventory ressources; }

user_defined_types: struct s_inventory { int food; int linemate; int deraumere; int sibur; int mendiane; int phiras; int thystame; }


decompiled_code:
__int64 __fastcall timeval_to_time_unit(__int64 a1)
{
__int64 v1; // rax

v1 = get_clock();
return *(_DWORD *)(v1 + 48) * *(_DWORD *)a1
+ (unsigned int)(*(_QWORD *)(a1 + 8) * *(unsigned int *)(v1 + 48) / 1000000LL);
}

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

v1 = get_clock();
return *(_DWORD *)(v1 + 48) * *(_DWORD *)a1
+ (unsigned int)(*(_QWORD *)(a1 + 8) * *(unsigned int *)(v1 + 48) / 1000000LL);
}

original_code:
unsigned int timeval_to_time_unit(struct timeval *time)
{
  unsigned int res;
  t_clock *clock;
  clock = get_clock();
  res = time->tv_sec * clock->frequency;
  res += (time->tv_usec * clock->frequency) / 1000000;
  return res;
}

canonical_original_code:
unsigned int timeval_to_time_unit(struct timeval *time)
{
  unsigned int res;
  struct s_clock *clock;
  clock = get_clock();
  res = time->tv_sec * clock->frequency;
  res += (time->tv_usec * clock->frequency) / 1000000;
  return res;
}

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

variable_types:
res
unsigned int

variable_types: struct s_clock { struct timeval { long tv_sec; long tv_usec; } timeout; struct timeval begin; struct timeval current; unsigned int frequency; } *

return_type: unsigned int

user_defined_types: struct s_clock { struct timeval timeout; struct timeval begin; struct timeval current; unsigned int frequency; }


decompiled_code:
__int64 __fastcall game_add_free_player(__int64 a1)
{
return list_add_end(g_game + 40LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return list_add_end(g_game + 40LL, a1);
}

original_code:
void game_add_free_player(t_player *player)
{
  list_add_end(&g_game->slots, player);
}

canonical_original_code:
void game_add_free_player(struct s_player *player)
{
  list_add_end(&g_game->slots, player);
}

variable_types: struct s_player { int id; struct s_team { char name[-1]; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } players; int available_slots; int free_slots; } *team; struct s_tile { struct s_list players; struct s_pos { int x; int y; } coord; struct s_inventory { int food; int linemate; int deraumere; int sibur; int mendiane; int phiras; int thystame; } ressources; } *tile; enum t_orientation { OR_NORTH=0, OR_EAST=1, OR_SOUTH=2, OR_WEST=3 } orientation; struct s_inventory inventory; int level; int life; } *


decompiled_code:
__int64 __fastcall game_remove_free_player(__int64 a1)
{
return list_pop(g_game + 40LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return list_pop(g_game + 40LL, a1);
}

original_code:
void game_remove_free_player(t_player *player)
{
  list_pop(&g_game->slots, player);
}

canonical_original_code:
void game_remove_free_player(struct s_player *player)
{
  list_pop(&g_game->slots, player);
}

user_defined_types: struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; }


decompiled_code:
__int64 __fastcall game_get_slot(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // r12
unsigned int *v4; // rax

logger_verbose("[GAME] Search team '%s'", a1);
v1 = game_get_team(a1);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = 0LL;
if ( *(int *)(v1 + 68) > 0 )
{
logger_verbose("[GAME] Team %s found", a1);
v4 = (unsigned int *)list_get_to_param(g_game + 40LL, game_player_in_team, v2);
v3 = (__int64)v4;
if ( v4 )
{
logger_verbose("[GAME] Player %i found", *v4);
game_remove_free_player(v3);
--*(_DWORD *)(v2 + 68);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // r12
unsigned int *v4; // rax

logger_verbose("[GAME] Search team '%s'", a1);
v1 = game_get_team(a1);
if ( !v1 )
return 0LL;
v2 = v1;
v3 = 0LL;
if ( *(int *)(v1 + 68) > 0 )
{
logger_verbose("[GAME] Team %s found", a1);
v4 = (unsigned int *)list_get_to_param(g_game + 40LL, game_player_in_team, v2);
v3 = (__int64)v4;
if ( v4 )
{
logger_verbose("[GAME] Player %i found", *v4);
func2(v3);
--*(_DWORD *)(v2 + 68);
}
}
return v3;
}

original_code:
t_player *game_get_slot(char *name)
{
  t_team *team;
  t_player *player;
  logger_verbose("[GAME] Search team '%s'", name);
  team = game_get_team(name);
  if (team && team->free_slots > 0)
    {
      logger_verbose("[GAME] Team %s found", name);
      player = list_get_to_param(&g_game->slots, (fpredp) &_game_player_in_team, team);
      if (player)
 {
   logger_verbose("[GAME] Player %i found", player->id);
   game_remove_free_player(player);
   team->free_slots--;
   return player;
 }
    }
  return ((void *)0);
}

canonical_original_code:
struct s_player *game_get_slot(char *name)
{
  struct s_team *team;
  struct s_player *player;
  logger_verbose("[GAME] Search team '%s'", name);
  team = game_get_team(name);
  if (team && team->free_slots > 0)
    {
      logger_verbose("[GAME] Team %s found", name);
      player = list_get_to_param(&g_game->slots, (fpredp) &_game_player_in_team, team);
      if (player)
 {
   logger_verbose("[GAME] Player %i found", player->id);
   game_remove_free_player(player);
   team->free_slots--;
   return player;
 }
    }
  return ((void *)0);
}

variable_types:
name
char *

return_type: struct s_player { int id; struct s_team { char name[-1]; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } players; int available_slots; int free_slots; } *team; struct s_tile { struct s_list players; struct s_pos { int x; int y; } coord; struct s_inventory { int food; int linemate; int deraumere; int sibur; int mendiane; int phiras; int thystame; } ressources; } *tile; enum t_orientation { OR_NORTH=0, OR_EAST=1, OR_SOUTH=2, OR_WEST=3 } orientation; struct s_inventory inventory; int level; int life; } *


decompiled_code:
char *__fastcall parser_extract_elem(char *s, char a2, const char *a3)
{
size_t v4; // rbp
unsigned int v5; // er14
__int64 v6; // rax

if ( !s )
return 0LL;
if ( !a3 || a2 )
return strdup(s);
v4 = 0LL;
v5 = strlen(a3);
do
{
if ( !strncmp(&s[v4], a3, v5) )
return strndup(s, v4);
v6 = v5 + (unsigned int)v4++;
}
while ( s[v6] );
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, char a2, const char *a3)
{
size_t v4; // rbp
unsigned int v5; // er14
__int64 v6; // rax

if ( !s )
return 0LL;
if ( !a3 || a2 )
return strdup(s);
v4 = 0LL;
v5 = strlen(a3);
do
{
if ( !strncmp(&s[v4], a3, v5) )
return strndup(s, v4);
v6 = v5 + (unsigned int)v4++;
}
while ( s[v6] );
return 0LL;
}

original_code:
char *parser_extract_elem(char *data, _Bool last_arg,
         char *split_str)
{
  unsigned int len;
  int data_index;
  if (!data)
    return (((void *)0));
  if (last_arg == 1 || !split_str)
    return (strdup(data));
  data_index = 0;
  len = strlen(split_str);
  while (strncmp(&data[data_index], split_str, len) &&
         data[data_index + len])
    {
      data_index += 1;
    }
  if (!strncmp(&data[data_index], split_str, len))
    return (strndup(data, data_index));
  return (((void *)0));
}

variable_types:
data
char *

variable_types:
len
unsigned int

return_type: char *


decompiled_code:
__int64 gui_send()
{
return client_send();
}

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

original_code:
int gui_send(t_gui *gui, char *msg)
{
  return client_send(gui, msg);
}

canonical_original_code:
int gui_send(struct s_client *gui, char *msg)
{
  return client_send(gui, msg);
}

variable_types: struct s_client { struct s_socket { int fd; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned int length; void (*read)(struct s_socket *, void *); void *param; } *socket; struct s_player { int id; struct s_team { char name[-1]; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } players; int available_slots; int free_slots; } *team; struct s_tile { struct s_list players; struct s_pos { int x; int y; } coord; struct s_inventory { int food; int linemate; int deraumere; int sibur; int mendiane; int phiras; int thystame; } ressources; } *tile; enum t_orientation { OR_NORTH=0, OR_EAST=1, OR_SOUTH=2, OR_WEST=3 } orientation; struct s_inventory inventory; int level; int life; } *player; struct s_list actions; _Bool busy; void (*exec)(struct s_client *, char *); } *

variable_types:
msg
char *

return_type: int

user_defined_types: struct s_client { struct s_socket *socket; struct s_player *player; struct s_list actions; _Bool busy; void (*exec)(struct s_client *, char *); }

user_defined_types: struct s_socket { int fd; struct sockaddr_in addr; unsigned int length; void (*read)(struct s_socket *, void *); void *param; }

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


decompiled_code:
__int64 __fastcall gui_send_all(__int64 a1)
{
return list_foreach_param(g_gui_manager, gui_send, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return list_foreach_param(g_gui_manager, gui_send, a1);
}

original_code:
void gui_send_all(char *msg)
{
  list_foreach_param(&g_gui_manager->guis, (feachp) &gui_send, msg);
}


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

if ( a2 )
result = client_send(a1, &unk_34);
return result;
}

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

if ( a2 )
result = client_send(a1, &unk_34);
return result;
}

original_code:
void player_left_end_cb(t_client *client, int error)
{
  if (!error)
    {
    }
  else
    client_send(client, "ko");
}

canonical_original_code:
void player_left_end_cb(struct s_client *client, int error)
{
  if (!error)
    {
    }
  else
    client_send(client, "ko");
}

variable_types: error int


decompiled_code:
__int64 __fastcall player_left_start_cb(__int64 a1)
{
return kernel_register_wakeup(7LL, player_left_end_cb, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return kernel_register_wakeup(7LL, player_left_end_cb, a1);
}

original_code:
void player_left_start_cb(t_client *client, char *command)
{
  (void)command;
  kernel_register_wakeup(7, (kn_wakeup_cb) player_left_end_cb, client);
}

canonical_original_code:
void player_left_start_cb(struct s_client *client, char *command)
{
  (void)command;
  kernel_register_wakeup(7, (void (*)(void *, int)) player_left_end_cb, client);
}

variable_types:
command
char *


decompiled_code:
__int64 __fastcall client_player_search(__int64 a1, const char *a2)
{
unsigned int *v2; // rax
unsigned int *v3; // rbp
unsigned int v4; // er13
unsigned int v5; // eax
__int64 result; // rax

if ( !strcmp(a2, "GRAPHIC") )
{
gui_connect(a1);
result = 1LL;
}
else
{
logger_verbose("[CLIENT] Search player in team '%s'", a2);
v2 = (unsigned int *)game_get_slot(a2);
v3 = v2;
if ( v2 )
{
logger_verbose("[CLIENT] Find player %i for client", *v2);
*(_QWORD *)(a1 + 8) = v3;
client_consume_food(a1, 0LL);
client_send(a1, "%i", *(unsigned int *)(*((_QWORD *)v3 + 1) + 68LL));
v4 = game_height();
v5 = game_width();
client_send(a1, "%i %i", v5, v4);
result = 1LL;
*(_QWORD *)(a1 + 48) = &client_action_save;
}
else
{
logger_error("[CLIENT] Any player find");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
unsigned int *v2; // rax
unsigned int *v3; // rbp
unsigned int v4; // er13
unsigned int v5; // eax
__int64 result; // rax

if ( !strcmp(a2, "GRAPHIC") )
{
gui_connect(a1);
result = 1LL;
}
else
{
logger_verbose("[CLIENT] Search player in team '%s'", a2);
v2 = (unsigned int *)game_get_slot(a2);
v3 = v2;
if ( v2 )
{
logger_verbose("[CLIENT] Find player %i for client", *v2);
*(_QWORD *)(a1 + 8) = v3;
client_consume_food(a1, 0LL);
client_send(a1, "%i", *(unsigned int *)(*((_QWORD *)v3 + 1) + 68LL));
v4 = game_height();
v5 = game_width();
client_send(a1, "%i %i", v5, v4);
result = 1LL;
*(_QWORD *)(a1 + 48) = &client_action_save;
}
else
{
logger_error("[CLIENT] Any player find");
result = 0LL;
}
}
return result;
}

original_code:
_Bool client_player_search(t_client *client, char *team)
{
  t_player *player;
  if (strcmp(team, "GRAPHIC") == 0)
    {
      gui_connect(client);
      return 1;
    }
  else
    {
      logger_verbose("[CLIENT] Search player in team '%s'", team);
      player = game_get_slot(team);
      if (player)
 {
   logger_verbose("[CLIENT] Find player %i for client", player->id);
   client->player = player;
   client_consume_food(client, 0);
   client_send(client, "%i", player->team->free_slots);
   client_send(client, "%i %i", game_width(), game_height());
   client->exec = (t_execute_cb) &client_action_save;
   return 1;
 }
    }
  logger_error("[CLIENT] Any player find");
  return 0;
}

canonical_original_code:
_Bool client_player_search(struct s_client *client, char *team)
{
  struct s_player *player;
  if (strcmp(team, "GRAPHIC") == 0)
    {
      gui_connect(client);
      return 1;
    }
  else
    {
      logger_verbose("[CLIENT] Search player in team '%s'", team);
      player = game_get_slot(team);
      if (player)
 {
   logger_verbose("[CLIENT] Find player %i for client", player->id);
   client->player = player;
   client_consume_food(client, 0);
   client_send(client, "%i", player->team->free_slots);
   client_send(client, "%i %i", game_width(), game_height());
   client->exec = (t_execute_cb) &client_action_save;
   return 1;
 }
    }
  logger_error("[CLIENT] Any player find");
  return 0;
}

variable_types:
team
char *


decompiled_code:
__int64 __fastcall parser_save_data(char **a1, const char *a2, unsigned int a3)
{
void *v4; // rax
void *v5; // r13
__int64 result; // rax
char *v7; // rax

if ( *a1 )
{
v4 = malloc(0x10uLL);
v5 = v4;
if ( v4 )
{
if ( (int)parser_argument_setter(a3, a2, v4) >= 0 )
{
list_add_end(a1 + 1, v5);
return 0LL;
}
result = error_leaving_int_constprop_0(v5, 0LL, 0LL);
}
else
{
result = error_leaving_int_constprop_0(0LL, "malloc", 0LL);
}
}
else if ( a3 == 1 )
{
v7 = strdup(a2);
*a1 = v7;
if ( v7 )
return 0LL;
result = error_leaving_int_constprop_0(0LL, "strdup", 0LL);
}
else
{
result = error_leaving_int_constprop_0(0LL, 0LL, (__int64)"instruction should be a string\n");
}
return result;
}

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

if ( *a1 )
{
v4 = malloc(0x10uLL);
v5 = v4;
if ( v4 )
{
if ( (int)parser_argument_setter(a3, a2, v4) >= 0 )
{
list_add_end(a1 + 1, v5);
return 0LL;
}
result = func0(v5, 0LL, 0LL);
}
else
{
result = func0(0LL, "malloc", 0LL);
}
}
else if ( a3 == 1 )
{
v7 = strdup(a2);
*a1 = v7;
if ( v7 )
return 0LL;
result = func0(0LL, "strdup", 0LL);
}
else
{
result = func0(0LL, 0LL, (__int64)"instruction should be a string\n");
}
return result;
}

original_code:
int parser_save_data(t_command *command, char *buffer,
     int type)
{
  t_argument *argument;
  if (!(command->instruction))
    {
      if (type != 1)
 return (error_leaving_int(((void *)0), ((void *)0), ((void *)0),
      "instruction should be a string\n"));
      if (!(command->instruction = strdup(buffer)))
 return (error_leaving_int(((void *)0), ((void *)0), "strdup", ((void *)0)));
    }
  else
    {
      if (!(argument = malloc(sizeof(*argument))))
 return (error_leaving_int(((void *)0), ((void *)0), "malloc", ((void *)0)));
      if (parser_argument_setter(type, buffer, argument) < 0)
 return (error_leaving_int(argument, ((void *)0), ((void *)0), ((void *)0)));
      list_add_end(&(command->arguments), argument);
    }
  return (0);
}

canonical_original_code:
int parser_save_data(struct s_command *command, char *buffer, int type)
{
  struct s_argument *argument;
  if (!(command->instruction))
    {
      if (type != 1)
 return (error_leaving_int(((void *)0), ((void *)0), ((void *)0),
      "instruction should be a string\n"));
      if (!(command->instruction = strdup(buffer)))
 return (error_leaving_int(((void *)0), ((void *)0), "strdup", ((void *)0)));
    }
  else
    {
      if (!(argument = malloc(sizeof(*argument))))
 return (error_leaving_int(((void *)0), ((void *)0), "malloc", ((void *)0)));
      if (parser_argument_setter(type, buffer, argument) < 0)
 return (error_leaving_int(argument, ((void *)0), ((void *)0), ((void *)0)));
      list_add_end(&(command->arguments), argument);
    }
  return (0);
}

variable_types: struct s_command { char *instruction; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } arguments; char *original_str; } *

variable_types:
buffer
char *

variable_types: type int

variable_types: struct s_argument { int type; void *data; } *

user_defined_types: struct s_command { char *instruction; struct s_list arguments; char *original_str; }


decompiled_code:
__int64 game_play_free_player()
{
return logger_error("[GAME] Play free player not implemented!");
}

canonical_decompiled_code:
__int64 func1()
{
return logger_error("[GAME] Play free player not implemented!");
}

original_code:
void game_play_free_player()
{
  logger_error("[GAME] Play free player not implemented!");
}


decompiled_code:
__int64 game_start()
{
int v0; // er8
__int64 result; // rax

v0 = list_size(g_game + 16LL);
result = 0LL;
if ( v0 )
{
list_foreach(g_game + 16LL, game_start_team);
game_play_free_player();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // er8
__int64 result; // rax

v0 = list_size(g_game + 16LL);
result = 0LL;
if ( v0 )
{
list_foreach(g_game + 16LL, game_start_team);
func1();
result = 1LL;
}
return result;
}

original_code:
_Bool game_start()
{
  if (list_size(&g_game->teams) == 0)
    return 0;
  list_foreach(&g_game->teams, (feach) &_game_start_team);
  game_play_free_player();
  return 1;
}


decompiled_code:
__int64 __fastcall parser_str_check_contain(char *a1, char *a2)
{
char v2; // cl
char *v3; // rdi
char *v4; // rdx
char v5; // al
unsigned int v6; // er8
__int64 result; // rax

v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
while ( *a2 )
{
v4 = a2 + 1;
v5 = *a2;
v6 = 0;
do
{
if ( v5 == v2 )
v6 = 1;
v5 = *v4++;
}
while ( v5 );
if ( (_BYTE)v6 )
{
v2 = *v3++;
if ( v2 )
continue;
}
goto LABEL_10;
}
result = 0LL;
}
else
{
v6 = 1;
LABEL_10:
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char *a2)
{
char v2; // cl
char *v3; // rdi
char *v4; // rdx
char v5; // al
unsigned int v6; // er8
__int64 result; // rax

v2 = *a1;
if ( *a1 )
{
v3 = a1 + 1;
while ( *a2 )
{
v4 = a2 + 1;
v5 = *a2;
v6 = 0;
do
{
if ( v5 == v2 )
v6 = 1;
v5 = *v4++;
}
while ( v5 );
if ( (_BYTE)v6 )
{
v2 = *v3++;
if ( v2 )
continue;
}
goto LABEL_10;
}
result = 0LL;
}
else
{
v6 = 1;
LABEL_10:
result = v6;
}
return result;
}

original_code:
_Bool parser_str_check_contain(char *str, char *authorized)
{
  int authorized_index;
  int str_index;
  _Bool matched;
  str_index = 0;
  while (str[str_index])
    {
      matched = 0;
      authorized_index = 0;
      while (authorized[authorized_index])
 {
   if (authorized[authorized_index] == str[str_index])
     matched = 1;
   authorized_index++;
 }
      if (matched == 0)
 return (0);
      str_index++;
    }
  return (1);
}

variable_types:
str
char *

variable_types:
authorized
char *


decompiled_code:
__int64 __fastcall timeval_add(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v4; // rcx

result = a2[1] + a3[1];
v4 = *a3 + *a2;
*a1 = v4;
if ( result > 1000000 )
{
*a1 = v4 + (unsigned int)result / 0xF4240;
result = (unsigned int)result % 0xF4240;
a1[1] = (unsigned int)result;
}
else
{
a1[1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v4; // rcx

result = a2[1] + a3[1];
v4 = *a3 + *a2;
*a1 = v4;
if ( result > 1000000 )
{
*a1 = v4 + (unsigned int)result / 0xF4240;
result = (unsigned int)result % 0xF4240;
a1[1] = (unsigned int)result;
}
else
{
a1[1] = result;
}
return result;
}

original_code:
void timeval_add(struct timeval *res,
       struct timeval *date1,
       struct timeval *date2)
{
  unsigned int tmp;
  res->tv_sec = date1->tv_sec + date2->tv_sec;
  res->tv_usec = date1->tv_usec + date2->tv_usec;
  if (res->tv_usec > 1000000)
    {
      tmp = res->tv_usec;
      res->tv_usec = tmp % 1000000;
      res->tv_sec += tmp / 1000000;
    }
}

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

variable_types:
tmp
unsigned int


decompiled_code:
__int64 clock_get_time()
{
__int64 v0; // r12

v0 = get_clock() + 32;
clock_set_time_to_current(v0);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r12

v0 = get_clock() + 32;
clock_set_time_to_current(v0);
return v0;
}

original_code:
struct timeval *clock_get_time()
{
  t_clock *clock;
  clock = get_clock();
  clock_set_time_to_current(&clock->current);
  return (&(clock->current));
}

canonical_original_code:
struct timeval *clock_get_time()
{
  struct s_clock *clock;
  clock = get_clock();
  clock_set_time_to_current(&clock->current);
  return (&(clock->current));
}

variable_types: struct s_clock { struct timeval { long tv_sec; long tv_usec; } timeout; struct timeval begin; struct timeval current; unsigned int frequency; } *

return_type: struct timeval { long tv_sec; long tv_usec; } *


decompiled_code:
__int64 __fastcall game_init(unsigned int a1, unsigned int a2, int a3)
{
unsigned int v4; // er12

logger_verbose("[GAME] Starting game init");
g_game = malloc(0x48uLL);
if ( !g_game )
return 0LL;
v4 = game_world_init(a1, a2);
if ( !(_BYTE)v4 )
return 0LL;
list_init((char *)g_game + 16);
list_init((char *)g_game + 40);
*((_DWORD *)g_game + 16) = a3;
game_register();
logger_verbose("[GAME] game module correctly initialized");
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2, int a3)
{
unsigned int v4; // er12

logger_verbose("[GAME] Starting game init");
g_game = malloc(0x48uLL);
if ( !g_game )
return 0LL;
v4 = func1(a1, a2);
if ( !(_BYTE)v4 )
return 0LL;
list_init((char *)g_game + 16);
list_init((char *)g_game + 40);
*((_DWORD *)g_game + 16) = a3;
func2();
logger_verbose("[GAME] game module correctly initialized");
return v4;
}

original_code:
_Bool game_init(int x, int y, int nb_slots)
{
  logger_verbose("[GAME] Starting game init");
  if (!(g_game = malloc(sizeof(t_game))))
    return 0;
  if (_game_world_init(x, y))
    {
      list_init(&g_game->teams);
      list_init(&g_game->slots);
      g_game->nb_slots = nb_slots;
      _game_register();
      logger_verbose("[GAME] game module correctly initialized");
      return 1;
    }
  return 0;
}

variable_types: x int

variable_types: y int


decompiled_code:
void game_destroy()
{
if ( g_game )
{
logger_message("[GAME] Game destroy");
list_foreach((char *)g_game + 40, &player_free);
list_clear((char *)g_game + 40);
list_free((char *)g_game + 16);
free(*(void **)g_game);
free(g_game);
g_game = 0LL;
}
}

canonical_decompiled_code:
void func4()
{
if ( g_game )
{
logger_message("[GAME] Game destroy");
list_foreach((char *)g_game + 40, &player_free);
list_clear((char *)g_game + 40);
list_free((char *)g_game + 16);
free(*(void **)g_game);
free(g_game);
g_game = 0LL;
}
}

original_code:
void game_destroy()
{
  if (!g_game)
    return;
  logger_message("[GAME] Game destroy");
  list_foreach(&g_game->slots, (feach) &player_free);
  list_clear(&g_game->slots);
  list_free(&g_game->teams);
  free(g_game->world.tiles);
  free(g_game);
  g_game = ((void *)0);
}


decompiled_code:
_BOOL8 __fastcall debug_fpredp(__int64 a1, __int64 a2)
{
return *(_QWORD *)(a1 + 64) != a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1, __int64 a2)
{
return *(_QWORD *)(a1 + 64) != a2;
}

original_code:
int debug_fpredp(t_debug_callback *callback, void *search)
{
  return !(callback->addr == search);
}

canonical_original_code:
int debug_fpredp(struct s_debug_callback *callback, void *search)
{
  return !(callback->addr == search);
}

variable_types: struct s_debug_callback { char name[60]; void *addr; } *

variable_types:
search
void *


decompiled_code:
__int64 debug_init()
{
__int64 v0; // rbp
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax
char *v10; // rax
char *v11; // rax
char *v12; // rax
char *v13; // rax
char *v14; // rax
char *v15; // rax
char *v16; // rax
char *v17; // rax
char *v18; // rax
char *v19; // rax
char *v20; // rax
char *v21; // rax
char *v22; // rax
char *v23; // rax

v0 = list_create();
g_callback = v0;
v1 = debug_callback_create("client_consume_food", (__int64)&client_consume_food);
list_add_end(v0, v1);
v2 = debug_callback_create("player_forward_start_cb", (__int64)&player_forward_start_cb);
list_add_end(g_callback, v2);
v3 = debug_callback_create("player_forward_end_cb", (__int64)&player_forward_end_cb);
list_add_end(g_callback, v3);
v4 = debug_callback_create("player_right_start_cb", (__int64)&player_right_start_cb);
list_add_end(g_callback, v4);
v5 = debug_callback_create("player_right_end_cb", (__int64)&player_right_end_cb);
list_add_end(g_callback, v5);
v6 = debug_callback_create("player_left_start_cb", (__int64)&player_left_start_cb);
list_add_end(g_callback, v6);
v7 = debug_callback_create("player_left_end_cb", (__int64)&player_left_end_cb);
list_add_end(g_callback, v7);
v8 = debug_callback_create("player_look_start_cb", (__int64)&player_look_start_cb);
list_add_end(g_callback, v8);
v9 = debug_callback_create("player_look_end_cb", (__int64)&player_look_end_cb);
list_add_end(g_callback, v9);
v10 = debug_callback_create("player_inventory_start_cb", (__int64)&player_inventory_start_cb);
list_add_end(g_callback, v10);
v11 = debug_callback_create("player_inventory_end_cb", (__int64)&player_inventory_end_cb);
list_add_end(g_callback, v11);
v12 = debug_callback_create("player_take_start_cb", (__int64)&player_take_start_cb);
list_add_end(g_callback, v12);
v13 = debug_callback_create("player_take_end_cb", (__int64)&player_take_end_cb);
list_add_end(g_callback, v13);
v14 = debug_callback_create("player_drop_start_cb", (__int64)&player_drop_start_cb);
list_add_end(g_callback, v14);
v15 = debug_callback_create("player_drop_end_cb", (__int64)&player_drop_end_cb);
list_add_end(g_callback, v15);
v16 = debug_callback_create("player_expulse_start_cb", (__int64)&player_expulse_start_cb);
list_add_end(g_callback, v16);
v17 = debug_callback_create("player_expulse_end_cb", (__int64)&player_expulse_end_cb);
list_add_end(g_callback, v17);
v18 = debug_callback_create("player_incantation_start_cb", (__int64)&player_incantation_start_cb);
list_add_end(g_callback, v18);
v19 = debug_callback_create("player_incantation_end_cb", (__int64)&player_incantation_end_cb);
list_add_end(g_callback, v19);
v20 = debug_callback_create("player_fork_start_cb", (__int64)&player_fork_start_cb);
list_add_end(g_callback, v20);
v21 = debug_callback_create("player_fork_end_cb", (__int64)&player_fork_end_cb);
list_add_end(g_callback, v21);
v22 = debug_callback_create("player_connect_nbr_cb", (__int64)&player_connect_nbr_cb);
list_add_end(g_callback, v22);
v23 = debug_callback_create("player_death_cb", (__int64)&player_death_cb);
return list_add_end(g_callback, v23);
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbp
char *v1; // rax
char *v2; // rax
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax
char *v10; // rax
char *v11; // rax
char *v12; // rax
char *v13; // rax
char *v14; // rax
char *v15; // rax
char *v16; // rax
char *v17; // rax
char *v18; // rax
char *v19; // rax
char *v20; // rax
char *v21; // rax
char *v22; // rax
char *v23; // rax

v0 = list_create();
g_callback = v0;
v1 = func1("client_consume_food", (__int64)&client_consume_food);
list_add_end(v0, v1);
v2 = func1("player_forward_start_cb", (__int64)&player_forward_start_cb);
list_add_end(g_callback, v2);
v3 = func1("player_forward_end_cb", (__int64)&player_forward_end_cb);
list_add_end(g_callback, v3);
v4 = func1("player_right_start_cb", (__int64)&player_right_start_cb);
list_add_end(g_callback, v4);
v5 = func1("player_right_end_cb", (__int64)&player_right_end_cb);
list_add_end(g_callback, v5);
v6 = func1("player_left_start_cb", (__int64)&player_left_start_cb);
list_add_end(g_callback, v6);
v7 = func1("player_left_end_cb", (__int64)&player_left_end_cb);
list_add_end(g_callback, v7);
v8 = func1("player_look_start_cb", (__int64)&player_look_start_cb);
list_add_end(g_callback, v8);
v9 = func1("player_look_end_cb", (__int64)&player_look_end_cb);
list_add_end(g_callback, v9);
v10 = func1("player_inventory_start_cb", (__int64)&player_inventory_start_cb);
list_add_end(g_callback, v10);
v11 = func1("player_inventory_end_cb", (__int64)&player_inventory_end_cb);
list_add_end(g_callback, v11);
v12 = func1("player_take_start_cb", (__int64)&player_take_start_cb);
list_add_end(g_callback, v12);
v13 = func1("player_take_end_cb", (__int64)&player_take_end_cb);
list_add_end(g_callback, v13);
v14 = func1("player_drop_start_cb", (__int64)&player_drop_start_cb);
list_add_end(g_callback, v14);
v15 = func1("player_drop_end_cb", (__int64)&player_drop_end_cb);
list_add_end(g_callback, v15);
v16 = func1("player_expulse_start_cb", (__int64)&player_expulse_start_cb);
list_add_end(g_callback, v16);
v17 = func1("player_expulse_end_cb", (__int64)&player_expulse_end_cb);
list_add_end(g_callback, v17);
v18 = func1("player_incantation_start_cb", (__int64)&player_incantation_start_cb);
list_add_end(g_callback, v18);
v19 = func1("player_incantation_end_cb", (__int64)&player_incantation_end_cb);
list_add_end(g_callback, v19);
v20 = func1("player_fork_start_cb", (__int64)&player_fork_start_cb);
list_add_end(g_callback, v20);
v21 = func1("player_fork_end_cb", (__int64)&player_fork_end_cb);
list_add_end(g_callback, v21);
v22 = func1("player_connect_nbr_cb", (__int64)&player_connect_nbr_cb);
list_add_end(g_callback, v22);
v23 = func1("player_death_cb", (__int64)&player_death_cb);
return list_add_end(g_callback, v23);
}

original_code:
void debug_init()
{
  g_callback = list_create();
  list_add_end(g_callback, debug_callback_create("client_consume_food", &client_consume_food));
  list_add_end(g_callback, debug_callback_create("player_forward_start_cb", &player_forward_start_cb));
  list_add_end(g_callback, debug_callback_create("player_forward_end_cb", &player_forward_end_cb));
  list_add_end(g_callback, debug_callback_create("player_right_start_cb", &player_right_start_cb));
  list_add_end(g_callback, debug_callback_create("player_right_end_cb", &player_right_end_cb));
  list_add_end(g_callback, debug_callback_create("player_left_start_cb", &player_left_start_cb));
  list_add_end(g_callback, debug_callback_create("player_left_end_cb", &player_left_end_cb));
  list_add_end(g_callback, debug_callback_create("player_look_start_cb", &player_look_start_cb));
  list_add_end(g_callback, debug_callback_create("player_look_end_cb", &player_look_end_cb));
  list_add_end(g_callback, debug_callback_create("player_inventory_start_cb", &player_inventory_start_cb));
  list_add_end(g_callback, debug_callback_create("player_inventory_end_cb", &player_inventory_end_cb));
  list_add_end(g_callback, debug_callback_create("player_take_start_cb", &player_take_start_cb));
  list_add_end(g_callback, debug_callback_create("player_take_end_cb", &player_take_end_cb));
  list_add_end(g_callback, debug_callback_create("player_drop_start_cb", &player_drop_start_cb));
  list_add_end(g_callback, debug_callback_create("player_drop_end_cb", &player_drop_end_cb));
  list_add_end(g_callback, debug_callback_create("player_expulse_start_cb", &player_expulse_start_cb));
  list_add_end(g_callback, debug_callback_create("player_expulse_end_cb", &player_expulse_end_cb));
  list_add_end(g_callback, debug_callback_create("player_incantation_start_cb", &player_incantation_start_cb));
  list_add_end(g_callback, debug_callback_create("player_incantation_end_cb", &player_incantation_end_cb));
  list_add_end(g_callback, debug_callback_create("player_fork_start_cb", &player_fork_start_cb));
  list_add_end(g_callback, debug_callback_create("player_fork_end_cb", &player_fork_end_cb));
  list_add_end(g_callback, debug_callback_create("player_connect_nbr_cb", &player_connect_nbr_cb));
  list_add_end(g_callback, debug_callback_create("player_death_cb", &player_death_cb));
}


decompiled_code:
__int64 __fastcall debug_get_callback_name(__int64 a1)
{
if ( !g_callback )
debug_init();
return list_get_to_param(g_callback, debug_fpredp, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( !g_callback )
func2();
return list_get_to_param(g_callback, debug_fpredp, a1);
}

original_code:
char *debug_get_callback_name(void *search)
{
  t_debug_callback *callback;
  if (g_callback == ((void *)0))
    debug_init();
  callback = list_get_to_param(g_callback, (fpredp) &debug_fpredp, search);
  if (callback)
    return callback->name;
  return ((void *)0);
}

canonical_original_code:
char *debug_get_callback_name(void *search)
{
  struct s_debug_callback *callback;
  if (g_callback == ((void *)0))
    debug_init();
  callback = list_get_to_param(g_callback, (fpredp) &debug_fpredp, search);
  if (callback)
    return callback->name;
  return ((void *)0);
}

user_defined_types: struct s_debug_callback { char name[60]; void *addr; }


decompiled_code:
__int64 __fastcall client_read(_QWORD *a1, int *a2)
{
__int64 result; // rax
unsigned int v4; // eax
__int64 v5; // rsi
__int64 v6; // rdx
unsigned int *v7; // rax
int v8; // eax

result = 0LL;
if ( *a2 > 1023 )
{
v4 = socket_read(*a1, a2 + 4, 1024LL);
v5 = 0xFFFFFFFFLL;
*a2 = v4;
v6 = v4;
v7 = (unsigned int *)a1[1];
if ( v7 )
v5 = *v7;
logger_verbose("[CLIENT] Client %i read %i data on socket", v5, v6);
v8 = a2[3];
if ( *a2 || v8 )
{
a2[1] = 0;
a2[3] = v8 + 1;
result = 1LL;
}
else
{
client_unconnect(a1);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int *a2)
{
__int64 result; // rax
unsigned int v4; // eax
__int64 v5; // rsi
__int64 v6; // rdx
unsigned int *v7; // rax
int v8; // eax

result = 0LL;
if ( *a2 > 1023 )
{
v4 = socket_read(*a1, a2 + 4, 1024LL);
v5 = 0xFFFFFFFFLL;
*a2 = v4;
v6 = v4;
v7 = (unsigned int *)a1[1];
if ( v7 )
v5 = *v7;
logger_verbose("[CLIENT] Client %i read %i data on socket", v5, v6);
v8 = a2[3];
if ( *a2 || v8 )
{
a2[1] = 0;
a2[3] = v8 + 1;
result = 1LL;
}
else
{
client_unconnect(a1);
result = 0LL;
}
}
return result;
}

original_code:
static _Bool client_read(t_client *client, struct s_buffer *bf)
{
  if (bf->read >= 1024)
    {
      bf->read = socket_read(client->socket, bf->buffer, 1024);
      logger_verbose("[CLIENT] Client %i read %i data on socket", ((client)->player ? (client)->player->id : -1), bf->read);
      if (!(bf->read == 0 && bf->count == 0))
 {
   bf->count++;
   bf->pos = 0;
   return 1;
 }
      client_unconnect(client);
    }
  return 0;
}

canonical_original_code:
static _Bool client_read(struct s_client *client, struct s_buffer *bf)
{
  if (bf->read >= 1024)
    {
      bf->read = socket_read(client->socket, bf->buffer, 1024);
      logger_verbose("[CLIENT] Client %i read %i data on socket", ((client)->player ? (client)->player->id : -1), bf->read);
      if (!(bf->read == 0 && bf->count == 0))
 {
   bf->count++;
   bf->pos = 0;
   return 1;
 }
      client_unconnect(client);
    }
  return 0;
}

variable_types: struct s_client { struct s_socket { int fd; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned int length; void (*read)(struct s_socket *, void *); void *param; } *socket; struct s_player { int id; struct s_team { char name[-1]; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } players; int available_slots; int free_slots; } *team; struct s_tile { struct s_list players; struct s_pos { int x; int y; } coord; struct s_inventory { int food; int linemate; int deraumere; int sibur; int mendiane; int phiras; int thystame; } ressources; } *tile; enum t_orientation { OR_NORTH=0, OR_EAST=1, OR_SOUTH=2, OR_WEST=3 } orientation; struct s_inventory inventory; int level; int life; } *player; struct s_list actions; _Bool busy; void (*exec)(struct s_client *, char *); } *

variable_types: struct s_buffer { int read; int pos; int index; int count; char buffer[1024]; char command[-1]; } *


original_code:
void client_receive(t_socket *socket, t_client *client)
{
  struct s_buffer bf;
  (void) socket;
  memset(&bf, 0, sizeof(struct s_buffer));
  bf.read = bf.pos = 1024;
  while (bf.index <= 1024)
    {
      if (bf.read <= bf.pos)
 if (!client_read(client, &bf))
   return;
      if (bf.buffer[bf.pos] == '\n')
 {
   if (bf.index == 0)
     return;
   bf.command[bf.index] = '\0';
   (*client->exec)(client, bf.command);
   bf.index = 0;
 }
      else
 bf.command[bf.index++] = bf.buffer[bf.pos++];
    }
}

canonical_original_code:
void client_receive(struct s_socket *socket, struct s_client *client)
{
  struct s_buffer bf;
  (void) socket;
  memset(&bf, 0, sizeof(struct s_buffer));
  bf.read = bf.pos = 1024;
  while (bf.index <= 1024)
    {
      if (bf.read <= bf.pos)
 if (!client_read(client, &bf))
   return;
      if (bf.buffer[bf.pos] == '\n')
 {
   if (bf.index == 0)
     return;
   bf.command[bf.index] = '\0';
   (*client->exec)(client, bf.command);
   bf.index = 0;
 }
      else
 bf.command[bf.index++] = bf.buffer[bf.pos++];
    }
}

variable_types: struct s_socket { int fd; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned int length; void (*read)(struct s_socket *, void *); void *param; } *

variable_types: struct s_client { struct s_socket *socket; struct s_player { int id; struct s_team { char name[-1]; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } players; int available_slots; int free_slots; } *team; struct s_tile { struct s_list players; struct s_pos { int x; int y; } coord; struct s_inventory { int food; int linemate; int deraumere; int sibur; int mendiane; int phiras; int thystame; } ressources; } *tile; enum t_orientation { OR_NORTH=0, OR_EAST=1, OR_SOUTH=2, OR_WEST=3 } orientation; struct s_inventory inventory; int level; int life; } *player; struct s_list actions; _Bool busy; void (*exec)(struct s_client *, char *); } *

variable_types: struct s_buffer { int read; int pos; int index; int count; char buffer[1024]; char command[-1]; }


decompiled_code:
__int64 __fastcall clock_get_remaining_time(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
_BYTE v4[16]; // [rsp-10h] [rbp-28h] BYREF
char v5[24]; // [rsp+0h] [rbp-18h] BYREF

if ( !a1 )
return 0LL;
timeval_copy(v4, a1);
clock_move_date(v4, a2);
v2 = clock_get_time();
timeval_diff(v5, v4, v2);
return timeval_to_time_unit(v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
_BYTE v4[16]; // [rsp-10h] [rbp-28h] BYREF
char v5[24]; // [rsp+0h] [rbp-18h] BYREF

if ( !a1 )
return 0LL;
timeval_copy(v4, a1);
clock_move_date(v4, a2);
v2 = clock_get_time();
timeval_diff(v5, v4, v2);
return timeval_to_time_unit(v5);
}

original_code:
unsigned int clock_get_remaining_time(struct timeval *time,
      unsigned int action_dur)
{
  struct timeval end_date;
  struct timeval remaining;
  if (!time)
    return (0);
  timeval_copy(&end_date, time);
  clock_move_date(&end_date, action_dur);
  timeval_diff(&remaining, &end_date, clock_get_time());
  return (timeval_to_time_unit(&remaining));
}

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


decompiled_code:
__int64 __fastcall parser_set_type(int *a1, __int64 a2, int *a3)
{
int v4; // eax
const char *v5; // rdi

v4 = parser_find_elem_type(a2 + *a3);
*a1 = v4;
if ( v4 < 0 )
return 0xFFFFFFFFLL;
v5 = (const char *)parser_get_type_str((unsigned int)v4);
if ( !v5 )
return 0xFFFFFFFFLL;
*a3 += strlen(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, __int64 a2, int *a3)
{
int v4; // eax
const char *v5; // rdi

v4 = parser_find_elem_type(a2 + *a3);
*a1 = v4;
if ( v4 < 0 )
return 0xFFFFFFFFLL;
v5 = (const char *)parser_get_type_str((unsigned int)v4);
if ( !v5 )
return 0xFFFFFFFFLL;
*a3 += strlen(v5);
return 0LL;
}

original_code:
static int parser_set_type(int *type_int,
    char *mask, int *mask_index)
{
  char *type_str;
  if ((*type_int = parser_find_elem_type(&mask[*mask_index])) < 0)
    return (-1);
  if ((type_str = parser_get_type_str(*type_int)))
    *mask_index += strlen(type_str);
  else
    return (-1);
  return (0);
}

variable_types:
mask
char *


decompiled_code:
__int64 __fastcall parser_get_new_elem(__int64 a1, __int64 a2, int *a3, int *a4)
{
const char *v6; // rax
char *v7; // rbp
const char *v8; // rax
const char *v9; // r12
int v10; // er13
const char *v12; // rax

v6 = (const char *)parser_find_key(*a3 + a1);
v7 = (char *)v6;
if ( v6 )
{
*a3 += strlen(v6);
v8 = (const char *)parser_extract_elem(a2 + *a4, 0LL, v7);
v9 = v8;
if ( v8 )
{
v10 = strlen(v8) + *a4;
*a4 = v10;
*a4 = strlen(v7) + v10;
LABEL_4:
free(v7);
return (__int64)v9;
}
}
else
{
v12 = (const char *)parser_extract_elem(a2 + *a4, 0LL, 0LL);
v9 = v12;
if ( v12 )
{
*a4 += strlen(v12);
goto LABEL_4;
}
}
return parser_error_leaving_constprop_0(0LL, v7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, int *a3, int *a4)
{
const char *v6; // rax
char *v7; // rbp
const char *v8; // rax
const char *v9; // r12
int v10; // er13
const char *v12; // rax

v6 = (const char *)parser_find_key(*a3 + a1);
v7 = (char *)v6;
if ( v6 )
{
*a3 += strlen(v6);
v8 = (const char *)parser_extract_elem(a2 + *a4, 0LL, v7);
v9 = v8;
if ( v8 )
{
v10 = strlen(v8) + *a4;
*a4 = v10;
*a4 = strlen(v7) + v10;
LABEL_4:
free(v7);
return (__int64)v9;
}
}
else
{
v12 = (const char *)parser_extract_elem(a2 + *a4, 0LL, 0LL);
v9 = v12;
if ( v12 )
{
*a4 += strlen(v12);
goto LABEL_4;
}
}
return func1(0LL, v7);
}

original_code:
static char *parser_get_new_elem(char *mask, char *data,
         int *mask_index, int *data_index)
{
  char *elem;
  char *split_str;
  if ((split_str = parser_find_key(&mask[*mask_index])))
    *mask_index += strlen(split_str);
  if ((elem = parser_extract_elem(&data[*data_index], 0, split_str)))
    *data_index += strlen(elem);
  else
    return ((char *)parser_error_leaving(((void *)0), split_str, ((void *)0), ((void *)0)));
  if (split_str)
    *data_index += strlen(split_str);
  free(split_str);
  return (elem);
}

variable_types:
data
char *

variable_types:
elem
char *


decompiled_code:
__int64 __fastcall parser_parse(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rax
void *v4; // rbp
unsigned int v6; // [rsp+4h] [rbp-34h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v7 = 0;
v8[0] = 0;
if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = parser_command_create();
if ( !v2 )
return 0LL;
while ( 1 )
{
if ( !*(_BYTE *)(a1 + v8[0]) )
{
if ( !*(_BYTE *)(a2 + v7) )
return v2;
return parser_error_leaving_constprop_0(v2, 0LL);
}
if ( !*(_BYTE *)(a2 + v7) )
return parser_error_leaving_constprop_0(v2, 0LL);
if ( (int)parser_set_type((int *)&v6, a2, &v7) < 0 )
return parser_error_leaving_constprop_0(v2, 0LL);
v3 = parser_get_new_elem(a2, a1, &v7, v8);
v4 = (void *)v3;
if ( !v3 )
return parser_error_leaving_constprop_0(v2, 0LL);
if ( (int)parser_save_data(v2, v3, v6) < 0 )
break;
free(v4);
}
return parser_error_leaving_constprop_0(v2, v4);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rax
void *v4; // rbp
unsigned int v6; // [rsp+4h] [rbp-34h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v7 = 0;
v8[0] = 0;
if ( !a1 )
return 0LL;
if ( !a2 )
return 0LL;
v2 = parser_command_create();
if ( !v2 )
return 0LL;
while ( 1 )
{
if ( !*(_BYTE *)(a1 + v8[0]) )
{
if ( !*(_BYTE *)(a2 + v7) )
return v2;
return func1(v2, 0LL);
}
if ( !*(_BYTE *)(a2 + v7) )
return func1(v2, 0LL);
if ( (int)func0((int *)&v6, a2, &v7) < 0 )
return func1(v2, 0LL);
v3 = func2(a2, a1, &v7, v8);
v4 = (void *)v3;
if ( !v3 )
return func1(v2, 0LL);
if ( (int)parser_save_data(v2, v3, v6) < 0 )
break;
free(v4);
}
return func1(v2, v4);
}

original_code:
t_command *parser_parse(char *data, char *mask)
{
  int type_int;
  char *elem;
  int mask_index;
  int data_index;
  t_command *command;
  mask_index = 0;
  data_index = 0;
  if (!data || !mask)
    return (((void *)0));
  if (!(command = parser_command_create(data)))
    return (((void *)0));
  while (data[data_index] && mask[mask_index])
    {
      if (parser_set_type(&type_int, mask, &mask_index) < 0)
 return (parser_error_leaving(command, ((void *)0), ((void *)0), ((void *)0)));
      if (!(elem = parser_get_new_elem(mask, data, &mask_index, &data_index)))
 return (parser_error_leaving(command, ((void *)0), ((void *)0), ((void *)0)));
      if (parser_save_data(command, elem, type_int) < 0)
 return (parser_error_leaving(command, elem, ((void *)0), ((void *)0)));
      free(elem);
    }
  if (data[data_index] || mask[mask_index])
    return (parser_error_leaving(command, ((void *)0), ((void *)0), ((void *)0)));
  return (command);
}

canonical_original_code:
struct s_command *parser_parse(char *data, char *mask)
{
  int type_int;
  char *elem;
  int mask_index;
  int data_index;
  struct s_command *command;
  mask_index = 0;
  data_index = 0;
  if (!data || !mask)
    return (((void *)0));
  if (!(command = parser_command_create(data)))
    return (((void *)0));
  while (data[data_index] && mask[mask_index])
    {
      if (parser_set_type(&type_int, mask, &mask_index) < 0)
 return (parser_error_leaving(command, ((void *)0), ((void *)0), ((void *)0)));
      if (!(elem = parser_get_new_elem(mask, data, &mask_index, &data_index)))
 return (parser_error_leaving(command, ((void *)0), ((void *)0), ((void *)0)));
      if (parser_save_data(command, elem, type_int) < 0)
 return (parser_error_leaving(command, elem, ((void *)0), ((void *)0)));
      free(elem);
    }
  if (data[data_index] || mask[mask_index])
    return (parser_error_leaving(command, ((void *)0), ((void *)0), ((void *)0)));
  return (command);
}

variable_types: struct s_command { char *instruction; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } arguments; char *original_str; } *


decompiled_code:
int server_usage()
{
puts("Zappy Server\nUsage:");
puts("-p numero du port (default 3945)");
puts("-x largeur du Monde (default 10)");
puts("-y hauteur du Monde (default 10)");
puts("-n nom equipe 1 [nom equipe 2 [nom equipe n]]");
puts("-c nombre de client par equipe (default 10)");
return puts("-t delai temporel d'execution des actions (default 100)");
}

canonical_decompiled_code:
int func0()
{
puts("Zappy Server\nUsage:");
puts("-p numero du port (default 3945)");
puts("-x largeur du Monde (default 10)");
puts("-y hauteur du Monde (default 10)");
puts("-n nom equipe 1 [nom equipe 2 [nom equipe n]]");
puts("-c nombre de client par equipe (default 10)");
return puts("-t delai temporel d'execution des actions (default 100)");
}

original_code:
void server_usage()
{
  printf("Zappy Server\nUsage:\n");
  printf("-p numero du port (default 3945)\n");
  printf("-x largeur du Monde (default 10)\n");
  printf("-y hauteur du Monde (default 10)\n");
  printf("-n nom equipe 1 [nom equipe 2 [nom equipe n]]\n");
  printf("-c nombre de client par equipe (default 10)\n");
  printf("-t delai temporel d'execution des actions (default 100)\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 1 )
{
server_usage();
}
else
{
logger_init(15LL, "zappy.log", 1LL);
if ( (unsigned __int8)kernel_init_with_argv((unsigned int)argc, argv) )
kernel_run();
kernel_destroy();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc == 1 )
{
func0();
}
else
{
logger_init(15LL, "zappy.log", 1LL);
if ( (unsigned __int8)kernel_init_with_argv((unsigned int)argc, argv) )
kernel_run();
kernel_destroy();
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
  if (argc == 1)
    server_usage();
  else
    {
      logger_init(((0x1 | 0x2 | 0x4) | 0x8), "zappy.log", 1);
      if (kernel_init_with_argv(argc, argv))
 kernel_run();
      kernel_destroy();
    }
  return (0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
bool __fastcall network_add_socket(__int64 a1, __int64 a2, __int64 a3)
{
bool result; // al
__int64 v4; // rcx

result = a2 == 0 || a1 == 0;
if ( result )
return 0;
v4 = g_network;
if ( g_network )
{
*(_QWORD *)(a1 + 24) = a2;
*(_QWORD *)(a1 + 32) = a3;
list_add_begin(*(_QWORD *)(v4 + 8), a1);
result = 1;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
bool result; // al
__int64 v4; // rcx

result = a2 == 0 || a1 == 0;
if ( result )
return 0;
v4 = g_network;
if ( g_network )
{
*(_QWORD *)(a1 + 24) = a2;
*(_QWORD *)(a1 + 32) = a3;
list_add_begin(*(_QWORD *)(v4 + 8), a1);
result = 1;
}
return result;
}

original_code:
_Bool network_add_socket(t_socket *socket,
                           t_nt_read_cb callback,
                           void *param)
{
  if (!socket || !callback || !g_network)
    return (0);
  socket->read = callback;
  socket->param = param;
  list_add_begin(g_network->read, (void *)socket);
  return (1);
}

canonical_original_code:
_Bool network_add_socket(struct s_socket *socket, void (*callback)(struct s_socket *, void *), void *param)
{
  if (!socket || !callback || !g_network)
    return (0);
  socket->read = callback;
  socket->param = param;
  list_add_begin(g_network->read, (void *)socket);
  return (1);
}

variable_types:
callback
void (*)(struct s_socket *, void *)

variable_types:
param
void *


decompiled_code:
__int64 __fastcall network_del_socket(void *ptr)
{
if ( !ptr || !g_network )
return 1LL;
list_pop(*(_QWORD *)(g_network + 8LL), ptr);
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
if ( !ptr || !g_network )
return 1LL;
list_pop(*(_QWORD *)(g_network + 8LL), ptr);
free(ptr);
return 1LL;
}

original_code:
_Bool network_del_socket(t_socket *socket)
{
  if (!socket || !g_network)
    return (1);
  list_pop(g_network->read, (void *)socket);
  free(socket);
  return (1);
}

canonical_original_code:
_Bool network_del_socket(struct s_socket *socket)
{
  if (!socket || !g_network)
    return (1);
  list_pop(g_network->read, (void *)socket);
  free(socket);
  return (1);
}


decompiled_code:
__int64 __fastcall gui_action_forward(unsigned int *a1)
{
char s[72]; // [rsp+8h] [rbp-48h] BYREF

snprintf(
s,
0x40uLL,
"ppo #%i %i %i %i",
*a1,
*(unsigned int *)(*((_QWORD *)a1 + 2) + 24LL),
*(unsigned int *)(*((_QWORD *)a1 + 2) + 28LL),
a1[6] + 1);
return list_foreach_param(g_gui_manager, &gui_send, s);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
char s[72]; // [rsp+8h] [rbp-48h] BYREF

snprintf(
s,
0x40uLL,
"ppo #%i %i %i %i",
*a1,
*(unsigned int *)(*((_QWORD *)a1 + 2) + 24LL),
*(unsigned int *)(*((_QWORD *)a1 + 2) + 28LL),
a1[6] + 1);
return list_foreach_param(g_gui_manager, &gui_send, s);
}

original_code:
void gui_action_forward(t_player *player)
{
  char buffer[64];
  snprintf(buffer, 64, "ppo #%i %i %i %i", player->id, player->tile->coord.x, player->tile->coord.y, player->orientation + 1);
  list_foreach_param(&g_gui_manager->guis, (feachp) &gui_send, buffer);
}

canonical_original_code:
void gui_action_forward(struct s_player *player)
{
  char buffer[64];
  snprintf(buffer, 64, "ppo #%i %i %i %i", player->id, player->tile->coord.x, player->tile->coord.y, player->orientation + 1);
  list_foreach_param(&g_gui_manager->guis, (feachp) &gui_send, buffer);
}

variable_types: struct s_player { int id; struct s_team { char name[-1]; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } players; int available_slots; int free_slots; } *team; struct s_tile { struct s_list players; struct s_pos { int x; int y; } coord; struct s_inventory { int food; int linemate; int deraumere; int sibur; int mendiane; int phiras; int thystame; } ressources; } *tile; enum t_orientation { OR_NORTH=0, OR_EAST=1, OR_SOUTH=2, OR_WEST=3 } orientation; struct s_inventory inventory; int level; int life; } *

variable_types:
buffer
char [64]


decompiled_code:
// attributes: thunk
__int64 __fastcall gui_action_left(unsigned int *a1)
{
return gui_action_forward(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1)
{
return func0(a1);
}

original_code:
void gui_action_left(t_player *player)
{
  gui_action_forward(player);
}

canonical_original_code:
void gui_action_left(struct s_player *player)
{
  gui_action_forward(player);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall gui_action_right(unsigned int *a1)
{
return gui_action_left(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
return func1(a1);
}

original_code:
void gui_action_right(t_player *player)
{
  gui_action_forward(player);
}

canonical_original_code:
void gui_action_right(struct s_player *player)
{
  gui_action_forward(player);
}


original_code:
static void configure_socket(t_socket *socket, int port)
{
  socket->addr.sin_port = htons(port);
  socket->addr.sin_family = 2;
  socket->addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  socket->length = (sizeof(socket->addr));
}

canonical_original_code:
static void configure_socket(struct s_socket *socket, int port)
{
  socket->addr.sin_port = htons(port);
  socket->addr.sin_family = 2;
  socket->addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
  socket->length = (sizeof(socket->addr));
}

variable_types: port int


decompiled_code:
__int64 __fastcall network_listen_to(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v3; // er12
__int64 result; // rax
_QWORD *v7; // rax
_QWORD *v8; // rsi
int v9; // edx
_QWORD *v10; // rax

if ( !g_network )
return 0LL;
LOBYTE(v3) = a2 == 0 || a1 == 0;
if ( (_BYTE)v3 )
return 0LL;
configure_socket(a1, a2);
if ( bind(*(_DWORD *)a1, (const struct sockaddr *)(a1 + 4), *(_DWORD *)(a1 + 20)) == -1
|| listen(*(_DWORD *)a1, 255) == -1
|| (v7 = malloc(0x10uLL), (v8 = v7) == 0LL) )
{
logger_error("[NETWORK] Impossible to listen to port %d", a2);
result = v3;
}
else
{
*v7 = a1;
v9 = *(_DWORD *)a1;
v7[1] = a3;
v10 = (_QWORD *)g_network;
if ( v9 > *(_DWORD *)(g_network + 24LL) )
*(_DWORD *)(g_network + 24LL) = v9;
list_add_begin(*v10, v8);
logger_message("[NETWORK] server listening at port : %d", a2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3)
{
unsigned int v3; // er12
__int64 result; // rax
_QWORD *v7; // rax
_QWORD *v8; // rsi
int v9; // edx
_QWORD *v10; // rax

if ( !g_network )
return 0LL;
LOBYTE(v3) = a2 == 0 || a1 == 0;
if ( (_BYTE)v3 )
return 0LL;
func1(a1, a2);
if ( bind(*(_DWORD *)a1, (const struct sockaddr *)(a1 + 4), *(_DWORD *)(a1 + 20)) == -1
|| listen(*(_DWORD *)a1, 255) == -1
|| (v7 = malloc(0x10uLL), (v8 = v7) == 0LL) )
{
logger_error("[NETWORK] Impossible to listen to port %d", a2);
result = v3;
}
else
{
*v7 = a1;
v9 = *(_DWORD *)a1;
v7[1] = a3;
v10 = (_QWORD *)g_network;
if ( v9 > *(_DWORD *)(g_network + 24LL) )
*(_DWORD *)(g_network + 24LL) = v9;
list_add_begin(*v10, v8);
logger_message("[NETWORK] server listening at port : %d", a2);
result = 1LL;
}
return result;
}

original_code:
_Bool network_listen_to(t_socket *socket,
      int port,
      t_nt_create_cb create)
{
  t_listener *listener;
  if (!g_network)
    return (0);
  if (!socket || !port)
    return (0);
  configure_socket(socket, port);
  if (bind(socket->fd,
    (SOCKADDR *)&socket->addr,
    socket->length) == SOCKET_ERROR
      || listen(socket->fd, 255) == SOCKET_ERROR
      || !(listener = malloc(sizeof(*listener))))
    {
      logger_error("[NETWORK] Impossible to listen to port %d", port);
      return (0);
    }
  listener->socket = socket;
  listener->create = create;
  if (socket->fd > g_network->nfds)
    g_network->nfds = socket->fd;
  list_add_begin(g_network->listened, listener);
  logger_message("[NETWORK] server listening at port : %d", port);
  return (1);
}

canonical_original_code:
_Bool network_listen_to(struct s_socket *socket, int port, void (*create)(struct s_socket *))
{
  struct s_listener *listener;
  if (!g_network)
    return (0);
  if (!socket || !port)
    return (0);
  configure_socket(socket, port);
  if (bind(socket->fd,
    (struct sockaddr *)&socket->addr,
    socket->length) == SOCKET_ERROR
      || listen(socket->fd, 255) == SOCKET_ERROR
      || !(listener = malloc(sizeof(*listener))))
    {
      logger_error("[NETWORK] Impossible to listen to port %d", port);
      return (0);
    }
  listener->socket = socket;
  listener->create = create;
  if (socket->fd > g_network->nfds)
    g_network->nfds = socket->fd;
  list_add_begin(g_network->listened, listener);
  logger_message("[NETWORK] server listening at port : %d", port);
  return (1);
}

variable_types:
create
void (*)(struct s_socket *)

variable_types: struct s_listener { struct s_socket { int fd; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned int length; void (*read)(struct s_socket *, void *); void *param; } *socket; void (*create)(struct s_socket *); } *

user_defined_types: struct s_listener { struct s_socket *socket; void (*create)(struct s_socket *); }

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


decompiled_code:
__int64 kernel_run()
{
__int64 v0; // rax
__int64 v1; // rdi

if ( !(unsigned __int8)kernel_is_init(15LL) )
return logger_warning("[KERNEL] Kernel is not initialised");
game_start();
*g_kernel = 1;
logger_message("[KERNEL] Kernel start");
while ( *g_kernel )
{
v0 = list_get_begin(g_kernel + 8LL);
v1 = v0;
if ( v0 )
v1 = clock_get_timeout(v0, *(unsigned int *)(v0 + 16));
if ( !(unsigned int)network_listen(v1) )
kernel_wakeup();
}
return logger_message("[KERNEL] Kernel stop");
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // rdi

if ( !(unsigned __int8)kernel_is_init(15LL) )
return logger_warning("[KERNEL] Kernel is not initialised");
game_start();
*g_kernel = 1;
logger_message("[KERNEL] Kernel start");
while ( *g_kernel )
{
v0 = list_get_begin(g_kernel + 8LL);
v1 = v0;
if ( v0 )
v1 = clock_get_timeout(v0, *(unsigned int *)(v0 + 16));
if ( !(unsigned int)network_listen(v1) )
kernel_wakeup();
}
return logger_message("[KERNEL] Kernel stop");
}

original_code:
void kernel_run()
{
  t_kernel_callback *first;
  struct timeval *timeout;
  int count;
  if (!kernel_is_init((0x1 | 0x2 | 0x4 | 0x8)))
    {
      logger_warning("[KERNEL] Kernel is not initialised");
      return;
    }
  game_start();
  g_kernel->run = 1;
  logger_message("[KERNEL] Kernel start");
  while (g_kernel->run)
    {
      timeout = ((void *)0);
      first = list_get_begin(&g_kernel->callbacks);
      if (first)
 timeout = clock_get_timeout(&first->begin, first->time);
      count = network_listen(timeout);
      if (!count)
 kernel_wakeup();
    }
  logger_message("[KERNEL] Kernel stop");
}

canonical_original_code:
void kernel_run()
{
  struct s_kernel_callback *first;
  struct timeval *timeout;
  int count;
  if (!kernel_is_init((0x1 | 0x2 | 0x4 | 0x8)))
    {
      logger_warning("[KERNEL] Kernel is not initialised");
      return;
    }
  game_start();
  g_kernel->run = 1;
  logger_message("[KERNEL] Kernel start");
  while (g_kernel->run)
    {
      timeout = ((void *)0);
      first = list_get_begin(&g_kernel->callbacks);
      if (first)
 timeout = clock_get_timeout(&first->begin, first->time);
      count = network_listen(timeout);
      if (!count)
 kernel_wakeup();
    }
  logger_message("[KERNEL] Kernel stop");
}

variable_types: struct s_kernel_callback { struct timeval { long tv_sec; long tv_usec; } begin; unsigned int time; void (*callback)(void *, int); void *param; } *

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

variable_types: count int

user_defined_types: struct s_kernel_callback { struct timeval begin; unsigned int time; void (*callback)(void *, int); void *param; }


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

result = g_kernel;
*g_kernel = 0;
return result;
}

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

result = g_kernel;
*g_kernel = 0;
return result;
}

original_code:
void kernel_stop()
{
  g_kernel->run = 0;
}


decompiled_code:
__int64 __fastcall player_connect_nbr_cb(__int64 a1)
{
logger_verbose("[GAME] command connect_nbr treated");
client_send(a1, "%d", *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) + 68LL));
return client_action_finish(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
logger_verbose("[GAME] command connect_nbr treated");
client_send(a1, "%d", *(unsigned int *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) + 68LL));
return client_action_finish(a1);
}

original_code:
void player_connect_nbr_cb(t_client *client, char *command)
{
  (void)command;
  logger_verbose("[GAME] command connect_nbr treated");
  client_send(client, "%d", client->player->team->free_slots);
  client_action_finish(client);
}

canonical_original_code:
void player_connect_nbr_cb(struct s_client *client, char *command)
{
  (void)command;
  logger_verbose("[GAME] command connect_nbr treated");
  client_send(client, "%d", client->player->team->free_slots);
  client_action_finish(client);
}

variable_types: struct s_client { struct s_socket { int fd; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned int length; void (*read)(struct s_socket *, void *); void *param; } *socket; struct s_player { int id; struct s_team { char name[-1]; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } players; int available_slots; int free_slots; } *team; struct s_tile { struct s_list players; struct s_pos { int x; int y; } coord; struct s_inventory { int food; int linemate; int deraumere; int sibur; int mendiane; int phiras; int thystame; } ressources; } *tile; enum t_orientation { OR_NORTH=0, OR_EAST=1, OR_SOUTH=2, OR_WEST=3 } orientation; struct s_inventory inventory; int level; int life; } *player; struct s_list actions; _Bool busy; void (*exec)(struct s_client *, char *); } *

variable_types:
command
char *


decompiled_code:
__int64 __fastcall parser_count_arguments(_BYTE *a1)
{
_BYTE *v1; // rbx
unsigned int v2; // er12
int v3; // eax

if ( !*a1 )
return 0LL;
v1 = a1;
v2 = 0;
do
{
v3 = parser_find_elem_type(v1++);
v2 += v3 > 0;
}
while ( *v1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
_BYTE *v1; // rbx
unsigned int v2; // er12
int v3; // eax

if ( !*a1 )
return 0LL;
v1 = a1;
v2 = 0;
do
{
v3 = parser_find_elem_type(v1++);
v2 += v3 > 0;
}
while ( *v1 );
return v2;
}

original_code:
int parser_count_arguments(char *mask)
{
  int count;
  int i;
  i = 0;
  count = 0;
  while (mask[i])
    {
      if (parser_find_elem_type(&mask[i]) > 0)
 count++;
      i++;
    }
  return (count);
}

variable_types:
mask
char *

variable_types: i int


decompiled_code:
__int64 __fastcall parser_get_string(__int64 a1, int a2)
{
int v2; // er12
__int64 v3; // rbp
int i; // ebx
__int64 v5; // rax

v2 = 0;
v3 = a1 + 8;
for ( i = 0; ; ++i )
{
if ( (int)list_size(v3) <= i )
return 0LL;
v5 = list_get_at(v3, (unsigned int)i);
if ( *(_DWORD *)v5 == 1 )
break;
LABEL_2:
;
}
if ( v2 != a2 )
{
++v2;
goto LABEL_2;
}
return *(_QWORD *)(v5 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
int v2; // er12
__int64 v3; // rbp
int i; // ebx
__int64 v5; // rax

v2 = 0;
v3 = a1 + 8;
for ( i = 0; ; ++i )
{
if ( (int)list_size(v3) <= i )
return 0LL;
v5 = list_get_at(v3, (unsigned int)i);
if ( *(_DWORD *)v5 == 1 )
break;
LABEL_2:
;
}
if ( v2 != a2 )
{
++v2;
goto LABEL_2;
}
return *(_QWORD *)(v5 + 8);
}

original_code:
char *parser_get_string(t_command *command, unsigned int index)
{
  t_argument *argument;
  int i;
  unsigned int count_string;
  i = 0;
  count_string = 0;
  while (i < list_size(&(command->arguments)))
    {
      argument = (t_argument *)list_get_at(&(command->arguments), i);
      if (argument->type == 1)
        {
          if (count_string == index)
            return ((char *)argument->data);
          count_string++;
        }
      i++;
    }
  return (((void *)0));
}

canonical_original_code:
char *parser_get_string(struct s_command *command, unsigned int index)
{
  struct s_argument *argument;
  int i;
  unsigned int count_string;
  i = 0;
  count_string = 0;
  while (i < list_size(&(command->arguments)))
    {
      argument = (struct s_argument *)list_get_at(&(command->arguments), i);
      if (argument->type == 1)
        {
          if (count_string == index)
            return ((char *)argument->data);
          count_string++;
        }
      i++;
    }
  return (((void *)0));
}

variable_types: struct s_command { char *instruction; struct s_list { unsigned int size; struct s_list_node { void *data; struct s_list_node *prev; struct s_list_node *next; } *head; struct s_list_node *tail; } arguments; char *original_str; } *

variable_types:
index
unsigned int

variable_types: struct s_argument { int type; void *data; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v4; // rax
__int64 v5; // rdx
__int64 v6; // rax
char v8[47]; // [rsp+10h] [rbp-D0h] BYREF
char v9; // [rsp+3Fh] [rbp-A1h] BYREF
char v10[47]; // [rsp+40h] [rbp-A0h] BYREF
char v11; // [rsp+6Fh] [rbp-71h] BYREF
char v12[47]; // [rsp+70h] [rbp-70h] BYREF
char v13; // [rsp+9Fh] [rbp-41h] BYREF
char v14[47]; // [rsp+A0h] [rbp-40h] BYREF
char v15[9]; // [rsp+CFh] [rbp-11h] BYREF

if ( argc == 3 )
{
std::allocator<char>::allocator(&v9);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v8, argv[2], &v9);
std::allocator<char>::allocator(&v11);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v10, argv[1], &v11);
v3 = gui::main(v10, v8);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v10);
std::allocator<char>::~allocator(&v11);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v8);
std::allocator<char>::~allocator(&v9);
}
else
{
v4 = std::operator<<<std::char_traits<char>>(&std::cout, *argv, envp);
v6 = std::operator<<<std::char_traits<char>>(v4, " Using 127.0.0.1 4242 by default", v5);
std::ostream::operator<<(v6, &std::endl<char,std::char_traits<char>>);
std::allocator<char>::allocator(&v13);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v12, "4242", &v13);
std::allocator<char>::allocator(v15);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(v14, "127.0.0.1", v15);
v3 = gui::main(v14, v12);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v14);
std::allocator<char>::~allocator(v15);
std::__cxx11::basic_string<char,std::char_traits<char>,std::allocator<char>>::~basic_string(v12);
std::allocator<char>::~allocator(&v13);
}
return v3;
}

canonical_original_code:
int main(int argc, char **argv)
{
  if (argc == 1)
    server_usage();
  else
    {
      logger_init(((0x1 | 0x2 | 0x4) | 0x8), "zappy.log", 1);
      if (kernel_init_with_argv(argc, argv))
 kernel_run();
      kernel_destroy();
    }
  return (0);
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 __fastcall getSteamID64(char *src)
{
char *v1; // rax
char *v2; // rax
__int64 v4; // [rsp+0h] [rbp-58h] BYREF
__int64 v5; // [rsp+8h] [rbp-50h] BYREF
char dest[72]; // [rsp+10h] [rbp-48h] BYREF

strcpy(dest, src);
strtok(dest, ":");
v1 = strtok(0LL, ":");
sscanf(v1, "%lu", &v4);
v2 = strtok(0LL, ":");
sscanf(v2, "%lu", &v5);
return v4 + 0x110000100000000LL + 2 * v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
char *v1; // rax
char *v2; // rax
__int64 v4; // [rsp+0h] [rbp-58h] BYREF
__int64 v5; // [rsp+8h] [rbp-50h] BYREF
char dest[72]; // [rsp+10h] [rbp-48h] BYREF

strcpy(dest, src);
strtok(dest, ":");
v1 = strtok(0LL, ":");
sscanf(v1, "%lu", &v4);
v2 = strtok(0LL, ":");
sscanf(v2, "%lu", &v5);
return v4 + 0x110000100000000LL + 2 * v5;
}

original_code:
unsigned long int getSteamID64(char* steamID32) {
 char buffer[64];
 char* substr;
 unsigned long int steamID64;
 unsigned long int serverID;
 unsigned long int userID;
 strcpy(buffer, steamID32);
 substr = strtok(buffer, ":");
 substr = strtok(((void *)0), ":");
 sscanf(substr, "%lu", &serverID);
 substr = strtok(((void *)0), ":");
 sscanf(substr, "%lu", &userID);
 steamID64 = serverID + userID * 2LU + 76561197960265728LU;
 return steamID64;
}

canonical_original_code:
unsigned long getSteamID64(char *steamID32) {
 char buffer[64];
 char *substr;
 unsigned long steamID64;
 unsigned long serverID;
 unsigned long userID;
 strcpy(buffer, steamID32);
 substr = strtok(buffer, ":");
 substr = strtok(((void *)0), ":");
 sscanf(substr, "%lu", &serverID);
 substr = strtok(((void *)0), ":");
 sscanf(substr, "%lu", &userID);
 steamID64 = serverID + userID * 2LU + 76561197960265728LU;
 return steamID64;
}

variable_types:
substr
char *

variable_types:
serverID
unsigned long

variable_types:
userID
unsigned long

return_type: unsigned long


generateIDs

decompiled_code:
char *__fastcall generateIDs(char a1, int a2)
{
__int64 v2; // rbp
int v3; // er13
char *v4; // r12
int v5; // ebx
size_t v6; // rax
size_t v7; // rax
__int64 v8; // rax
__int64 v10; // [rsp+0h] [rbp-98h]
char dest[8]; // [rsp+17h] [rbp-81h] BYREF
char v12; // [rsp+1Fh] [rbp-79h]
char s[2]; // [rsp+20h] [rbp-78h] BYREF

v2 = a2;
v3 = a2 + 99;
v4 = (char *)malloc(0x1B58uLL);
v5 = a2;
do
{
*(_QWORD *)dest = 0x3A305F4D41455453LL;
v12 = a1 + 48;
strcpy(s, ":");
sprintf(s, "%lu", v2);
strcat(dest, s);
v8 = getSteamID64(dest);
if ( a2 == v5 )
{
sprintf(v4, "%lu", v8);
}
else
{
v10 = v8;
v6 = strlen(v4);
sprintf(&v4[v6], "%lu", v10);
}
if ( v5 != v3 )
{
v7 = strlen(v4);
sprintf(&v4[v7], "%C", 44);
}
++v5;
++v2;
}
while ( v5 <= v3 );
return v4;
}

canonical_decompiled_code:
char *__fastcall func1(char a1, int a2)
{
__int64 v2; // rbp
int v3; // er13
char *v4; // r12
int v5; // ebx
size_t v6; // rax
size_t v7; // rax
__int64 v8; // rax
__int64 v10; // [rsp+0h] [rbp-98h]
char dest[8]; // [rsp+17h] [rbp-81h] BYREF
char v12; // [rsp+1Fh] [rbp-79h]
char s[2]; // [rsp+20h] [rbp-78h] BYREF

v2 = a2;
v3 = a2 + 99;
v4 = (char *)malloc(0x1B58uLL);
v5 = a2;
do
{
*(_QWORD *)dest = 0x3A305F4D41455453LL;
v12 = a1 + 48;
strcpy(s, ":");
sprintf(s, "%lu", v2);
strcat(dest, s);
v8 = func0(dest);
if ( a2 == v5 )
{
sprintf(v4, "%lu", v8);
}
else
{
v10 = v8;
v6 = strlen(v4);
sprintf(&v4[v6], "%lu", v10);
}
if ( v5 != v3 )
{
v7 = strlen(v4);
sprintf(&v4[v7], "%C", 44);
}
++v5;
++v2;
}
while ( v5 <= v3 );
return v4;
}

original_code:
char* generateIDs(int type, int startID) {
 unsigned long int steamID64;
 char* buffer = malloc(7000);
 char generator[64];
 int i;
 for (i = startID; i < startID+100; i++) {
  char typeID = (char)(((int)'0')+type);
  char steamid[] = "STEAM_0:";
  int len = strlen(steamid);
  steamid[len] = typeID;
  steamid[len+1] = ':';
  steamid[len+2] = '\0';
  unsigned long int generatedID = i;
  sprintf(generator,"%lu",generatedID);
  strcat(steamid, generator);
  steamID64 = getSteamID64(steamid);
  if ( i == startID) {
   sprintf(buffer,"%lu",steamID64); }
  else {
   sprintf(buffer + strlen(buffer),"%lu",steamID64); }
  if ( (i+1) != (startID + 100) ) {
   sprintf(buffer + strlen(buffer), "%C", ','); }
 }
 return buffer;
}

canonical_original_code:
char *generateIDs(int type, int startID) {
 unsigned long steamID64;
 char *buffer = malloc(7000);
 char generator[64];
 int i;
 for (i = startID; i < startID+100; i++) {
  char typeID = (char)(((int)'0')+type);
  char steamid[] = "STEAM_0:";
  int len = strlen(steamid);
  steamid[len] = typeID;
  steamid[len+1] = ':';
  steamid[len+2] = '\0';
  unsigned long generatedID = i;
  sprintf(generator,"%lu",generatedID);
  strcat(steamid, generator);
  steamID64 = getSteamID64(steamid);
  if ( i == startID) {
   sprintf(buffer,"%lu",steamID64); }
  else {
   sprintf(buffer + strlen(buffer),"%lu",steamID64); }
  if ( (i+1) != (startID + 100) ) {
   sprintf(buffer + strlen(buffer), "%C", ','); }
 }
 return buffer;
}

variable_types: type int

variable_types: startID int

variable_types:
buffer
char *

variable_types:
generator
char [64]

variable_types: typeID char

variable_types:
steamid
char []

variable_types: len int

variable_types:
generatedID
unsigned long


decompiled_code:
void __fastcall swal_disconnect(void *ptr)
{
int v2; // edi
int v3; // edi

v2 = *(_DWORD *)ptr;
if ( v2 >= 0 )
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( v3 >= 0 )
close(v3);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
int v2; // edi
int v3; // edi

v2 = *(_DWORD *)ptr;
if ( v2 >= 0 )
close(v2);
v3 = *((_DWORD *)ptr + 1);
if ( v3 >= 0 )
close(v3);
free(ptr);
}

original_code:
void swal_disconnect(swal_con* connection) {
 if (connection->legacy_sock >= 0) {
  close(connection->legacy_sock);
 }
 if (connection->modern_sock >= 0) {
  close(connection->modern_sock);
 }
 free(connection);
 return;
}

canonical_original_code:
void swal_disconnect(struct swal_con *connection) {
 if (connection->legacy_sock >= 0) {
  close(connection->legacy_sock);
 }
 if (connection->modern_sock >= 0) {
  close(connection->modern_sock);
 }
 free(connection);
 return;
}

variable_types: struct swal_con { int legacy_sock; int modern_sock; char apiKey[64]; } *


decompiled_code:
__int64 __fastcall swal_execute_query(int fd, char *s, const char *a3)
{
size_t v4; // rax
int v5; // er13
int v6; // ebx
int v7; // eax
int *v9; // rax
char *v10; // rax

v4 = strlen(s);
if ( (int)v4 > 0 )
{
v5 = v4;
v6 = 0;
while ( 1 )
{
v7 = write(fd, &s[v6], v6 + v4);
if ( v7 < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "Error while writing to socket: %s\n", v10);
exit(-1);
}
v6 += v7;
if ( v5 <= v6 )
break;
v4 = strlen(s);
}
}
return swal_save_response(fd, a3);
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, char *s, const char *a3)
{
size_t v4; // rax
int v5; // er13
int v6; // ebx
int v7; // eax
int *v9; // rax
char *v10; // rax

v4 = strlen(s);
if ( (int)v4 > 0 )
{
v5 = v4;
v6 = 0;
while ( 1 )
{
v7 = write(fd, &s[v6], v6 + v4);
if ( v7 < 0 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "Error while writing to socket: %s\n", v10);
exit(-1);
}
v6 += v7;
if ( v5 <= v6 )
break;
v4 = strlen(s);
}
}
return func3(fd, a3);
}

original_code:
int swal_execute_query(int sock, char* query, char* filename) {
 int success = 0;
 int bytesToWrite = strlen(query);
 int totalBytesWritten = 0;
 int bytesWritten;
 while (totalBytesWritten < bytesToWrite) {
  bytesWritten = write(sock, query+totalBytesWritten, strlen(query)+totalBytesWritten);
  if (bytesWritten < 0) {
   fprintf(stderr, "Error while writing to socket: %s\n", strerror((*__errno_location ())));
   exit(-1);
  }
  totalBytesWritten += bytesWritten;
 }
 success = swal_save_response(sock, filename);
 return success;
}

canonical_original_code:
int swal_execute_query(int sock, char *query, char *filename) {
 int success = 0;
 int bytesToWrite = strlen(query);
 int totalBytesWritten = 0;
 int bytesWritten;
 while (totalBytesWritten < bytesToWrite) {
  bytesWritten = write(sock, query+totalBytesWritten, strlen(query)+totalBytesWritten);
  if (bytesWritten < 0) {
   fprintf(stderr, "Error while writing to socket: %s\n", strerror((*__errno_location ())));
   exit(-1);
  }
  totalBytesWritten += bytesWritten;
 }
 success = swal_save_response(sock, filename);
 return success;
}

variable_types: sock int

variable_types:
query
char *

variable_types:
filename
char *

variable_types: success int

variable_types: bytesToWrite int

variable_types: totalBytesWritten int

variable_types: bytesWritten int


decompiled_code:
__int64 __fastcall swal_get_player_summaries(__int64 a1, const char *a2, const char *a3)
{
int v4; // eax
char *v5; // rbp
unsigned int v6; // er12

v4 = strlen(a2);
v5 = (char *)malloc(v4 + 256);
sprintf(
v5,
"GET /ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n",
(const char *)(a1 + 8),
a2);
v6 = swal_execute_query(*(_DWORD *)(a1 + 4), v5, a3);
free(v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const char *a2, const char *a3)
{
int v4; // eax
char *v5; // rbp
unsigned int v6; // er12

v4 = strlen(a2);
v5 = (char *)malloc(v4 + 256);
sprintf(
v5,
"GET /ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n",
(const char *)(a1 + 8),
a2);
v6 = func4(*(_DWORD *)(a1 + 4), v5, a3);
free(v5);
return v6;
}

original_code:
int swal_get_player_summaries(swal_con* connection, char* steamIDs, char* filename) {
 int steamIDsLength = strlen(steamIDs);
 int success = 0;
 char* buffer = (char*)malloc(steamIDsLength + 256);
 sprintf(buffer, "GET /ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n", connection->apiKey, steamIDs);
 success = swal_execute_query(connection->modern_sock, buffer, filename);
 free(buffer);
 return success;
}

canonical_original_code:
int swal_get_player_summaries(struct swal_con *connection, char *steamIDs, char *filename) {
 int steamIDsLength = strlen(steamIDs);
 int success = 0;
 char *buffer = (char*)malloc(steamIDsLength + 256);
 sprintf(buffer, "GET /ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n", connection->apiKey, steamIDs);
 success = swal_execute_query(connection->modern_sock, buffer, filename);
 free(buffer);
 return success;
}

variable_types:
steamIDs
char *

variable_types: steamIDsLength int

user_defined_types: struct swal_con { int legacy_sock; int modern_sock; char apiKey[64]; }


decompiled_code:
__int64 __fastcall swal_get_friend_list(__int64 a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(
v5,
"GET /ISteamUser/GetFriendList/v0001/?key=%s&steamid=%s&relationship=friend HTTP/1.1\r\n"
"host: api.steampowered.com\r\n"
"\r\n",
(const char *)(a1 + 8),
a2);
return swal_execute_query(*(_DWORD *)(a1 + 4), v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(
v5,
"GET /ISteamUser/GetFriendList/v0001/?key=%s&steamid=%s&relationship=friend HTTP/1.1\r\n"
"host: api.steampowered.com\r\n"
"\r\n",
(const char *)(a1 + 8),
a2);
return func4(*(_DWORD *)(a1 + 4), v5, a3);
}

original_code:
int swal_get_friend_list(swal_con* connection, char* steamID, char* filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /ISteamUser/GetFriendList/v0001/?key=%s&steamid=%s&relationship=friend HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n", connection->apiKey, steamID);
 success = swal_execute_query(connection->modern_sock, buffer, filename);
 return success;
}

canonical_original_code:
int swal_get_friend_list(struct swal_con *connection, char *steamID, char *filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /ISteamUser/GetFriendList/v0001/?key=%s&steamid=%s&relationship=friend HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n", connection->apiKey, steamID);
 success = swal_execute_query(connection->modern_sock, buffer, filename);
 return success;
}

variable_types:
steamID
char *

variable_types:
buffer
char [256]


decompiled_code:
__int64 __fastcall swal_get_player_grouplist(__int64 a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(
v5,
"GET /ISteamUser/GetUserGroupList/v0001/?key=%s&steamid=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n",
(const char *)(a1 + 8),
a2);
return swal_execute_query(*(_DWORD *)(a1 + 4), v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(
v5,
"GET /ISteamUser/GetUserGroupList/v0001/?key=%s&steamid=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n",
(const char *)(a1 + 8),
a2);
return func4(*(_DWORD *)(a1 + 4), v5, a3);
}

original_code:
int swal_get_player_grouplist(swal_con* connection, char* steamID, char* filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /ISteamUser/GetUserGroupList/v0001/?key=%s&steamid=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n", connection->apiKey, steamID);
 success = swal_execute_query(connection->modern_sock, buffer, filename);
 return success;
}

canonical_original_code:
int swal_get_player_grouplist(struct swal_con *connection, char *steamID, char *filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /ISteamUser/GetUserGroupList/v0001/?key=%s&steamid=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n", connection->apiKey, steamID);
 success = swal_execute_query(connection->modern_sock, buffer, filename);
 return success;
}


decompiled_code:
__int64 __fastcall swal_get_player_achievements(__int64 a1, unsigned int a2, const char *a3, const char *a4)
{
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(
v6,
"GET /ISteamUserStats/GetPlayerAchievements/v0001/?appid=%d&key=%s&steamid=%s HTTP/1.1\r\n"
"host: api.steampowered.com\r\n"
"\r\n",
a2,
(const char *)(a1 + 8),
a3);
return swal_execute_query(*(_DWORD *)(a1 + 4), v6, a4);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2, const char *a3, const char *a4)
{
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(
v6,
"GET /ISteamUserStats/GetPlayerAchievements/v0001/?appid=%d&key=%s&steamid=%s HTTP/1.1\r\n"
"host: api.steampowered.com\r\n"
"\r\n",
a2,
(const char *)(a1 + 8),
a3);
return func4(*(_DWORD *)(a1 + 4), v6, a4);
}

original_code:
int swal_get_player_achievements(swal_con* connection, int appID, char* steamID, char* filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /ISteamUserStats/GetPlayerAchievements/v0001/?appid=%d&key=%s&steamid=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n", appID, connection->apiKey, steamID);
 success = swal_execute_query(connection->modern_sock, buffer, filename);
 return success;
}

canonical_original_code:
int swal_get_player_achievements(struct swal_con *connection, int appID, char *steamID, char *filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /ISteamUserStats/GetPlayerAchievements/v0001/?appid=%d&key=%s&steamid=%s HTTP/1.1\r\nhost: api.steampowered.com\r\n\r\n", appID, connection->apiKey, steamID);
 success = swal_execute_query(connection->modern_sock, buffer, filename);
 return success;
}

variable_types: appID int


decompiled_code:
__int64 __fastcall swal_get_player_profile(int *a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v5, "GET /profiles/%s/?xml=1&l=english HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", a2);
return swal_execute_query(*a1, v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v5, "GET /profiles/%s/?xml=1&l=english HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", a2);
return func4(*a1, v5, a3);
}

original_code:
int swal_get_player_profile(swal_con* connection, char* steamID, char* filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /profiles/%s/?xml=1&l=english HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", steamID);
 success = swal_execute_query(connection->legacy_sock, buffer, filename);
 return success;
}

canonical_original_code:
int swal_get_player_profile(struct swal_con *connection, char *steamID, char *filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /profiles/%s/?xml=1&l=english HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", steamID);
 success = swal_execute_query(connection->legacy_sock, buffer, filename);
 return success;
}


decompiled_code:
__int64 __fastcall swal_get_player_games(int *a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v5, "GET /profiles/%s/games?xml=1 HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", a2);
return swal_execute_query(*a1, v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v5, "GET /profiles/%s/games?xml=1 HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", a2);
return func4(*a1, v5, a3);
}

original_code:
int swal_get_player_games(swal_con* connection, char* steamID, char* filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /profiles/%s/games?xml=1 HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", steamID);
 success = swal_execute_query(connection->legacy_sock, buffer, filename);
 return success;
}

canonical_original_code:
int swal_get_player_games(struct swal_con *connection, char *steamID, char *filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /profiles/%s/games?xml=1 HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", steamID);
 success = swal_execute_query(connection->legacy_sock, buffer, filename);
 return success;
}


decompiled_code:
__int64 __fastcall swal_get_group_memberlist(int *a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v5, "GET /gid/%s/memberslistxml/?xml=1 HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", a2);
return swal_execute_query(*a1, v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func11(int *a1, const char *a2, const char *a3)
{
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

sprintf(v5, "GET /gid/%s/memberslistxml/?xml=1 HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", a2);
return func4(*a1, v5, a3);
}

original_code:
int swal_get_group_memberlist(swal_con* connection, char* groupID, char* filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /gid/%s/memberslistxml/?xml=1 HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", groupID);
 success = swal_execute_query(connection->legacy_sock, buffer, filename);
 return success;
}

canonical_original_code:
int swal_get_group_memberlist(struct swal_con *connection, char *groupID, char *filename) {
 int success = 0;
 char buffer[256];
 sprintf(buffer, "GET /gid/%s/memberslistxml/?xml=1 HTTP/1.1\r\nhost: steamcommunity.com\r\n\r\n", groupID);
 success = swal_execute_query(connection->legacy_sock, buffer, filename);
 return success;
}

variable_types:
groupID
char *


decompiled_code:
__int64 __fastcall swal_get_socket(int a1)
{
bool v1; // zf
const char *v2; // rdi
int v3; // eax
int v4; // er12
const char *v6; // rax
int v7; // edi
struct addrinfo *pai; // [rsp+0h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-38h] BYREF

v1 = a1 == 1;
v2 = "api.steampowered.com";
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
if ( !v1 )
v2 = "steamcommunity.com";
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(v2, "http", &req, &pai);
if ( v3 )
{
v4 = -1;
v6 = gai_strerror(v3);
fprintf(stderr, "Error in getaddrinfo: %s\n", v6);
}
else
{
v4 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
if ( v4 < 0 )
{
v4 = -1;
fwrite("Failed to create socket.\n", 1uLL, 0x19uLL, stderr);
}
else if ( connect(v4, pai->ai_addr, pai->ai_addrlen) )
{
v7 = v4;
v4 = -1;
close(v7);
fwrite("Failed to connect.\n", 1uLL, 0x13uLL, stderr);
}
else
{
freeaddrinfo(pai);
}
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
bool v1; // zf
const char *v2; // rdi
int v3; // eax
int v4; // er12
const char *v6; // rax
int v7; // edi
struct addrinfo *pai; // [rsp+0h] [rbp-40h] BYREF
struct addrinfo req; // [rsp+8h] [rbp-38h] BYREF

v1 = a1 == 1;
v2 = "api.steampowered.com";
*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 0x600000001LL;
if ( !v1 )
v2 = "steamcommunity.com";
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
v3 = getaddrinfo(v2, "http", &req, &pai);
if ( v3 )
{
v4 = -1;
v6 = gai_strerror(v3);
fprintf(stderr, "Error in getaddrinfo: %s\n", v6);
}
else
{
v4 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
if ( v4 < 0 )
{
v4 = -1;
fwrite("Failed to create socket.\n", 1uLL, 0x19uLL, stderr);
}
else if ( connect(v4, pai->ai_addr, pai->ai_addrlen) )
{
v7 = v4;
v4 = -1;
close(v7);
fwrite("Failed to connect.\n", 1uLL, 0x13uLL, stderr);
}
else
{
freeaddrinfo(pai);
}
}
return (unsigned int)v4;
}

original_code:
int swal_get_socket(int type) {
 int tcpSocket;
 int error;
 struct addrinfo* steamAddressInfo;
 struct addrinfo hints;
 memset(&hints, 0, sizeof(struct addrinfo));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_protocol = IPPROTO_TCP;
 error = getaddrinfo(type == 1 ? "api.steampowered.com" : "steamcommunity.com", "http", &hints, &steamAddressInfo);
 if (error != 0) {
  fprintf(stderr, "Error in getaddrinfo: %s\n", gai_strerror(error));
  return -1;
 }
 tcpSocket = socket(steamAddressInfo->ai_family, steamAddressInfo->ai_socktype, steamAddressInfo->ai_protocol);
 if (tcpSocket < 0) {
  fprintf(stderr, "Failed to create socket.\n");
  return -1;
 }
 if (connect(tcpSocket, steamAddressInfo->ai_addr, steamAddressInfo->ai_addrlen) != 0) {
  close(tcpSocket);
  fprintf(stderr, "Failed to connect.\n");
  return -1;
 }
 freeaddrinfo(steamAddressInfo);
 return tcpSocket;
}

canonical_original_code:
int swal_get_socket(int type) {
 int tcpSocket;
 int error;
 struct addrinfo *steamAddressInfo;
 struct addrinfo hints;
 memset(&hints, 0, sizeof(struct addrinfo));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 hints.ai_protocol = IPPROTO_TCP;
 error = getaddrinfo(type == 1 ? "api.steampowered.com" : "steamcommunity.com", "http", &hints, &steamAddressInfo);
 if (error != 0) {
  fprintf(stderr, "Error in getaddrinfo: %s\n", gai_strerror(error));
  return -1;
 }
 tcpSocket = socket(steamAddressInfo->ai_family, steamAddressInfo->ai_socktype, steamAddressInfo->ai_protocol);
 if (tcpSocket < 0) {
  fprintf(stderr, "Failed to create socket.\n");
  return -1;
 }
 if (connect(tcpSocket, steamAddressInfo->ai_addr, steamAddressInfo->ai_addrlen) != 0) {
  close(tcpSocket);
  fprintf(stderr, "Failed to connect.\n");
  return -1;
 }
 freeaddrinfo(steamAddressInfo);
 return tcpSocket;
}

variable_types: type int

variable_types: tcpSocket int

variable_types: error 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; } *

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:
char *__fastcall swal_connect(int a1, const char *a2)
{
char *v2; // rax
char *v3; // r12
char *result; // rax

v2 = (char *)malloc(0x48uLL);
v3 = v2;
if ( (a1 & 0xFFFFFFFD) != 0 )
*(_DWORD *)v2 = -1;
else
*(_DWORD *)v2 = swal_get_socket(0);
if ( (unsigned int)(a1 - 1) <= 1 )
{
if ( a2 && strlen(a2) > 1 )
{
*((_DWORD *)v3 + 1) = swal_get_socket(1);
strncpy(v3 + 8, a2, 0x20uLL);
result = v3;
}
else
{
fwrite("Please specify an API Key for modern API.\n", 1uLL, 0x2AuLL, stderr);
result = 0LL;
}
}
else
{
*((_DWORD *)v3 + 1) = -1;
result = v3;
v3[8] = 0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func13(int a1, const char *a2)
{
char *v2; // rax
char *v3; // r12
char *result; // rax

v2 = (char *)malloc(0x48uLL);
v3 = v2;
if ( (a1 & 0xFFFFFFFD) != 0 )
*(_DWORD *)v2 = -1;
else
*(_DWORD *)v2 = func12(0);
if ( (unsigned int)(a1 - 1) <= 1 )
{
if ( a2 && strlen(a2) > 1 )
{
*((_DWORD *)v3 + 1) = func12(1);
strncpy(v3 + 8, a2, 0x20uLL);
result = v3;
}
else
{
fwrite("Please specify an API Key for modern API.\n", 1uLL, 0x2AuLL, stderr);
result = 0LL;
}
}
else
{
*((_DWORD *)v3 + 1) = -1;
result = v3;
v3[8] = 0;
}
return result;
}

original_code:
swal_con* swal_connect(int type, char* apiKey) {
 swal_con* connection = (swal_con*)malloc(sizeof(swal_con));
 if (type == 0 || type == 2) {
  connection->legacy_sock = swal_get_socket(0);
 }
 else {
  connection->legacy_sock = -1;
 }
 if (type == 1 || type == 2) {
  if (apiKey == 0 || strlen(apiKey) <= 1) {
   fprintf(stderr, "Please specify an API Key for modern API.\n");
   return 0;
  }
  connection->modern_sock = swal_get_socket(1);
  strncpy(connection->apiKey, apiKey, 32);
 }
 else {
  connection->modern_sock = -1;
  connection->apiKey[0] = '\0';
 }
 return connection;
}

canonical_original_code:
struct swal_con *swal_connect(int type, char *apiKey) {
 struct swal_con *connection = (swal_con*)malloc(sizeof(swal_con));
 if (type == 0 || type == 2) {
  connection->legacy_sock = swal_get_socket(0);
 }
 else {
  connection->legacy_sock = -1;
 }
 if (type == 1 || type == 2) {
  if (apiKey == 0 || strlen(apiKey) <= 1) {
   fprintf(stderr, "Please specify an API Key for modern API.\n");
   return 0;
  }
  connection->modern_sock = swal_get_socket(1);
  strncpy(connection->apiKey, apiKey, 32);
 }
 else {
  connection->modern_sock = -1;
  connection->apiKey[0] = '\0';
 }
 return connection;
}

variable_types:
apiKey
char *

variable_types: struct swal_con { int legacy_sock; int modern_sock; char apiKey[64]; } *


handler

decompiled_code:
int __fastcall handler(unsigned int a1)
{
return printf("Recieved signal: %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
return printf("Recieved signal: %d\n", a1);
}

original_code:
void handler(int status) {
 printf("Recieved signal: %d\n", status);
}

variable_types: status int