decompiled_code:
__int64 game_world_dump()
{
unsigned int v0; // ebp
__int64 result; // rax
unsigned int v2; // ebx
__int64 v3; // rdi
_DWORD *v4; // rax
unsigned int v5; // er15
unsigned int v6; // er14
unsigned int v7; // er13
unsigned int v8; // er12
unsigned int v9; // eax
unsigned int v10; // [rsp+4h] [rbp-44h]
unsigned int v11; // [rsp+8h] [rbp-40h]
unsigned int v12; // [rsp+Ch] [rbp-3Ch]

v0 = 0;
puts("World dump");
result = g_game;
if ( *(int *)(g_game + 12LL) > 0 )
{
do
{
v2 = 0;
if ( *(int *)(result + 8) > 0 )
{
do
{
v3 = v2++;
v4 = (_DWORD *)world_get_tile(v3, v0);
v5 = v4[11];
v6 = v4[10];
v7 = v4[9];
v12 = v4[14];
v11 = v4[13];
v8 = v4[8];
v10 = v4[12];
v9 = list_size(v4);
printf("{%i %i:%i:%i:%i:%i:%i:%i} ", v9, v8, v7, v6, v5, v10, v11, v12);
}
while ( *(_DWORD *)(g_game + 8LL) > (signed int)v2 );
}
++v0;
putchar(10);
result = g_game;
}
while ( *(_DWORD *)(g_game + 12LL) > (signed int)v0 );
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebp
__int64 result; // rax
unsigned int v2; // ebx
__int64 v3; // rdi
_DWORD *v4; // rax
unsigned int v5; // er15
unsigned int v6; // er14
unsigned int v7; // er13
unsigned int v8; // er12
unsigned int v9; // eax
unsigned int v10; // [rsp+4h] [rbp-44h]
unsigned int v11; // [rsp+8h] [rbp-40h]
unsigned int v12; // [rsp+Ch] [rbp-3Ch]

v0 = 0;
puts("World dump");
result = g_game;
if ( *(int *)(g_game + 12LL) > 0 )
{
do
{
v2 = 0;
if ( *(int *)(result + 8) > 0 )
{
do
{
v3 = v2++;
v4 = (_DWORD *)world_get_tile(v3, v0);
v5 = v4[11];
v6 = v4[10];
v7 = v4[9];
v12 = v4[14];
v11 = v4[13];
v8 = v4[8];
v10 = v4[12];
v9 = list_size(v4);
printf("{%i %i:%i:%i:%i:%i:%i:%i} ", v9, v8, v7, v6, v5, v10, v11, v12);
}
while ( *(_DWORD *)(g_game + 8LL) > (signed int)v2 );
}
++v0;
putchar(10);
result = g_game;
}
while ( *(_DWORD *)(g_game + 12LL) > (signed int)v0 );
}
return result;
}

original_code:
void game_world_dump()
{
  int idx;
  int idy;
  t_tile *tile;
  idy = 0;
  printf("World dump\n");
  while (idy < g_game->world.dimensions.y)
    {
      idx = 0;
      while (idx < g_game->world.dimensions.x)
 {
   tile = world_get_tile(idx, idy);
   printf("{%i %i:%i:%i:%i:%i:%i:%i} ",
   list_size(&tile->players), tile->ressources.food,
   tile->ressources.linemate, tile->ressources.deraumere, tile->ressources.sibur,
   tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
   ++idx;
 }
      printf("\n");
      ++idy;
    }
}

canonical_original_code:
void game_world_dump()
{
  int idx;
  int idy;
  struct s_tile *tile;
  idy = 0;
  printf("World dump\n");
  while (idy < g_game->world.dimensions.y)
    {
      idx = 0;
      while (idx < g_game->world.dimensions.x)
 {
   tile = world_get_tile(idx, idy);
   printf("{%i %i:%i:%i:%i:%i:%i:%i} ",
   list_size(&tile->players), tile->ressources.food,
   tile->ressources.linemate, tile->ressources.deraumere, tile->ressources.sibur,
   tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
   ++idx;
 }
      printf("\n");
      ++idy;
    }
}

variable_types: idx int

variable_types: idy int

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


decompiled_code:
__int64 __fastcall client_init(__int64 a1, __int64 a2)
{
__int64 v3; // rdi

v3 = a1 + 16;
*(_QWORD *)(v3 - 16) = a2;
*(_QWORD *)(v3 - 8) = 0LL;
*(_BYTE *)(v3 + 24) = 0;
*(_QWORD *)(v3 + 32) = &client_player_search;
list_init();
client_manager_add(a1);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v3; // rdi

v3 = a1 + 16;
*(_QWORD *)(v3 - 16) = a2;
*(_QWORD *)(v3 - 8) = 0LL;
*(_BYTE *)(v3 + 24) = 0;
*(_QWORD *)(v3 + 32) = &client_player_search;
list_init();
client_manager_add(a1);
return a1;
}

original_code:
t_client *client_init(t_client *client, t_socket *socket)
{
  client->socket = socket;
  client->player = ((void *)0);
  client->busy = 0;
  client->exec = (t_execute_cb) &client_player_search;
  list_init(&client->actions);
  _client_manager_add(client);
  return client;
}

canonical_original_code:
struct s_client *client_init(struct s_client *client, struct s_socket *socket)
{
  client->socket = socket;
  client->player = ((void *)0);
  client->busy = 0;
  client->exec = (t_execute_cb) &client_player_search;
  list_init(&client->actions);
  _client_manager_add(client);
  return client;
}

variable_types:
client
struct s_client *

variable_types:
socket
struct s_socket *

return_type: 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 *); } *

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 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 sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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

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

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


decompiled_code:
__int64 __fastcall client_create(__int64 a1)
{
void *v1; // rax
__int64 result; // rax

v1 = malloc(0x38uLL);
if ( v1 )
result = client_init((__int64)v1, a1);
else
result = 0LL;
return result;
}

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

v1 = malloc(0x38uLL);
if ( v1 )
result = func0((__int64)v1, a1);
else
result = 0LL;
return result;
}

original_code:
t_client *client_create(t_socket *socket)
{
  t_client *client;
  if (!(client = malloc(sizeof(t_client))))
    return ((void *)0);
  return client_init(client, socket);
}

canonical_original_code:
struct s_client *client_create(struct s_socket *socket)
{
  struct s_client *client;
  if (!(client = malloc(sizeof(t_client))))
    return ((void *)0);
  return client_init(client, socket);
}

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


decompiled_code:
void __fastcall client_destroy(void *ptr)
{
list_free((char *)ptr + 16);
client_manager_remove(ptr);
if ( *((_QWORD *)ptr + 1) )
game_add_free_player();
if ( *(_QWORD *)ptr )
{
socket_close();
network_del_socket(*(_QWORD *)ptr);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
list_free((char *)ptr + 16);
client_manager_remove(ptr);
if ( *((_QWORD *)ptr + 1) )
game_add_free_player();
if ( *(_QWORD *)ptr )
{
socket_close();
network_del_socket(*(_QWORD *)ptr);
}
free(ptr);
}

original_code:
void client_destroy(t_client *client)
{
  list_free(&client->actions);
  _client_manager_remove(client);
  if (client->player)
    game_add_free_player(client->player);
  if (client->socket)
    {
      socket_close(client->socket);
      network_del_socket(client->socket);
    }
  free(client);
}

canonical_original_code:
void client_destroy(struct s_client *client)
{
  list_free(&client->actions);
  _client_manager_remove(client);
  if (client->player)
    game_add_free_player(client->player);
  if (client->socket)
    {
      socket_close(client->socket);
      network_del_socket(client->socket);
    }
  free(client);
}

return_type: void

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

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

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


decompiled_code:
__int64 __fastcall player_look_end_cb(__int64 a1)
{
return client_send(a1, &unk_24);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return client_send(a1, &unk_24);
}

original_code:
void player_look_end_cb(t_client *client, int error)
{
  (void)error;
  client_send(client, "ko");
}

canonical_original_code:
void player_look_end_cb(struct s_client *client, int error)
{
  (void)error;
  client_send(client, "ko");
}

variable_types: error int


decompiled_code:
__int64 __fastcall player_look_start_cb(__int64 a1)
{
return kernel_register_wakeup(7LL, player_look_end_cb, a1);
}

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

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

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

variable_types:
command
char *


decompiled_code:
__int64 __fastcall world_remove_player(__int64 a1)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
{
result = list_pop(v2, a1);
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = *(_QWORD *)(a1 + 16);
if ( v2 )
{
result = list_pop(v2, a1);
*(_QWORD *)(a1 + 16) = 0LL;
}
return result;
}

original_code:
void world_remove_player(t_player *player)
{
  if (player->tile)
    {
      list_pop(&player->tile->players, player);
      player->tile = ((void *)0);
    }
}

canonical_original_code:
void world_remove_player(struct s_player *player)
{
  if (player->tile)
    {
      list_pop(&player->tile->players, player);
      player->tile = ((void *)0);
    }
}

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


original_code:
t_tile *world_get_tile(int x, int y)
{
  int w;
  int h;
  w = g_game->world.dimensions.x;
  h = g_game->world.dimensions.y;
  if (x < 0)
    x = (x % w) + w;
  else if (x >= w)
    x = x % w;
  if (y < 0)
    y = (y % h) + h;
  else if (y >= h)
    y = y % h;
  return &g_game->world.tiles[y * w + x];
}

canonical_original_code:
struct s_tile *world_get_tile(int x, int y)
{
  int w;
  int h;
  w = g_game->world.dimensions.x;
  h = g_game->world.dimensions.y;
  if (x < 0)
    x = (x % w) + w;
  else if (x >= w)
    x = x % w;
  if (y < 0)
    y = (y % h) + h;
  else if (y >= h)
    y = y % h;
  return &g_game->world.tiles[y * w + x];
}

variable_types: x int

variable_types: y int

variable_types: w int

variable_types: h int

return_type: struct s_tile { 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; 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; } *


decompiled_code:
__int64 __fastcall world_add_player(__int64 a1, int a2, int a3)
{
__int64 v3; // rax
__int64 v4; // r10

v3 = world_get_tile(a2, a3);
*(_QWORD *)(v4 + 16) = v3;
return list_add_end(v3, v4);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, int a3)
{
__int64 v3; // rax
__int64 v4; // r10

v3 = func1(a2, a3);
*(_QWORD *)(v4 + 16) = v3;
return list_add_end(v3, v4);
}

original_code:
void world_add_player(t_player *player, int x, int y)
{
  t_tile *tile;
  tile = world_get_tile(x, y);
  player->tile = tile;
  list_add_end(&tile->players, player);
}

canonical_original_code:
void world_add_player(struct s_player *player, int x, int y)
{
  struct s_tile *tile;
  tile = world_get_tile(x, y);
  player->tile = tile;
  list_add_end(&tile->players, player);
}


decompiled_code:
__int64 __fastcall world_move_to(__int64 a1, int a2)
{
__int64 v2; // rax
int v3; // er12
int v4; // er13

v2 = *(_QWORD *)(a1 + 16);
if ( !v2 )
return 0LL;
v3 = *(_DWORD *)(v2 + 24);
v4 = *(_DWORD *)(v2 + 28);
if ( a2 == 1 )
{
--v4;
}
else if ( a2 )
{
if ( a2 == 3 )
++v4;
else
v3 -= a2 == 2;
}
else
{
++v3;
}
world_remove_player(a1);
world_add_player(a1, v3, v4);
return 1LL;
}

original_code:
_Bool world_move_to(t_player *player, t_orientation direction)
{
  int x;
  int y;
  if (player->tile)
    {
      x = player->tile->coord.x;
      y = player->tile->coord.y;
      if (direction == OR_EAST)
 y -= 1;
      else if (direction == OR_NORTH)
 x += 1;
      else if (direction == OR_WEST)
 y += 1;
      else if (direction == OR_SOUTH)
 x -= 1;
      world_remove_player(player);
      world_add_player(player, x, y);
      return 1;
    }
  return 0;
}

canonical_original_code:
_Bool world_move_to(struct s_player *player, enum t_orientation direction)
{
  int x;
  int y;
  if (player->tile)
    {
      x = player->tile->coord.x;
      y = player->tile->coord.y;
      if (direction == OR_EAST)
 y -= 1;
      else if (direction == OR_NORTH)
 x += 1;
      else if (direction == OR_WEST)
 y += 1;
      else if (direction == OR_SOUTH)
 x -= 1;
      world_remove_player(player);
      world_add_player(player, x, y);
      return 1;
    }
  return 0;
}

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


decompiled_code:
__int64 __fastcall world_move_player(__int64 a1)
{
return world_move_to(a1, *(_DWORD *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return func3(a1, *(_DWORD *)(a1 + 24));
}

original_code:
_Bool world_move_player(t_player *player)
{
  return world_move_to(player, player->orientation);
}

canonical_original_code:
_Bool world_move_player(struct s_player *player)
{
  return world_move_to(player, player->orientation);
}


decompiled_code:
__int64 __fastcall client_action_count(__int64 a1)
{
return list_size(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return list_size(a1 + 16);
}

original_code:
int client_action_count(t_client *client)
{
  return list_size(&client->actions);
}

canonical_original_code:
int client_action_count(struct s_client *client)
{
  return list_size(&client->actions);
}

return_type: int


decompiled_code:
__int64 __fastcall client_execute(__int64 a1, const char *a2)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rsi
const char *v6; // rcx
unsigned int *v7; // rax

*(_BYTE *)(a1 + 40) = 1;
result = clm_command_retrieve(a2);
if ( result )
{
v4 = result;
v5 = 0xFFFFFFFFLL;
v6 = (const char *)debug_get_callback_name(*(_QWORD *)(result + 72));
v7 = *(unsigned int **)(a1 + 8);
if ( v7 )
v5 = *v7;
logger_verbose("[CLIENT] Client %i execute action '%s' on call '%s'", v5, a2, v6);
result = (*(__int64 (__fastcall **)(__int64, const char *))(v4 + 72))(a1, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rsi
const char *v6; // rcx
unsigned int *v7; // rax

*(_BYTE *)(a1 + 40) = 1;
result = clm_command_retrieve(a2);
if ( result )
{
v4 = result;
v5 = 0xFFFFFFFFLL;
v6 = (const char *)debug_get_callback_name(*(_QWORD *)(result + 72));
v7 = *(unsigned int **)(a1 + 8);
if ( v7 )
v5 = *v7;
logger_verbose("[CLIENT] Client %i execute action '%s' on call '%s'", v5, a2, v6);
result = (*(__int64 (__fastcall **)(__int64, const char *))(v4 + 72))(a1, a2);
}
return result;
}

original_code:
void client_execute(t_client *client, char *action)
{
  t_command_callback *command;
  client->busy = 1;
  command = clm_command_retrieve(action);
  if (command)
    {
      logger_verbose("[CLIENT] Client %i execute action '%s' on call '%s'", ((client)->player ? (client)->player->id : -1), action, debug_get_callback_name(command->callback));
      (*command->callback)(client, action);
    }
}

canonical_original_code:
void client_execute(struct s_client *client, char *action)
{
  struct s_command_callback *command;
  client->busy = 1;
  command = clm_command_retrieve(action);
  if (command)
    {
      logger_verbose("[CLIENT] Client %i execute action '%s' on call '%s'", ((client)->player ? (client)->player->id : -1), action, debug_get_callback_name(command->callback));
      (*command->callback)(client, action);
    }
}

variable_types:
action
char *

variable_types: struct s_command_callback { char instruction[-1]; char mask[-1]; unsigned int length; void (*callback)(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 *); } *, char *); } *

user_defined_types: struct s_command_callback { char instruction[-1]; char mask[-1]; unsigned int length; void (*callback)(struct s_client *, char *); }


decompiled_code:
__int64 __fastcall client_action_save(__int64 a1, const char *a2)
{
unsigned int v3; // er13
__int64 v4; // rsi
bool v5; // cc
unsigned int *v6; // rax
char *v7; // rax
__int64 result; // rax
unsigned int *v9; // rax
__int64 v10; // rsi

if ( clm_command_retrieve(a2) )
{
v3 = *(unsigned __int8 *)(a1 + 40);
if ( (_BYTE)v3 )
{
v4 = 0xFFFFFFFFLL;
v5 = (int)list_size(a1 + 16) <= 10;
v6 = *(unsigned int **)(a1 + 8);
if ( v5 )
{
if ( v6 )
v4 = *v6;
logger_verbose("[CLIENT] Client %i save action '%s'", v4, a2);
v7 = strdup(a2);
list_add_end(a1 + 16, v7);
result = v3;
}
else
{
if ( v6 )
v4 = *v6;
logger_warning("[CLIENT] Client %i action '%s' ignored", v4, a2);
result = 0LL;
}
}
else
{
client_execute(a1, a2);
result = 1LL;
}
}
else
{
v9 = *(unsigned int **)(a1 + 8);
v10 = 0xFFFFFFFFLL;
if ( v9 )
v10 = *v9;
logger_warning("[CLIENT] Client %i try to save unknown command '%s'", v10, a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
unsigned int v3; // er13
__int64 v4; // rsi
bool v5; // cc
unsigned int *v6; // rax
char *v7; // rax
__int64 result; // rax
unsigned int *v9; // rax
__int64 v10; // rsi

if ( clm_command_retrieve(a2) )
{
v3 = *(unsigned __int8 *)(a1 + 40);
if ( (_BYTE)v3 )
{
v4 = 0xFFFFFFFFLL;
v5 = (int)list_size(a1 + 16) <= 10;
v6 = *(unsigned int **)(a1 + 8);
if ( v5 )
{
if ( v6 )
v4 = *v6;
logger_verbose("[CLIENT] Client %i save action '%s'", v4, a2);
v7 = strdup(a2);
list_add_end(a1 + 16, v7);
result = v3;
}
else
{
if ( v6 )
v4 = *v6;
logger_warning("[CLIENT] Client %i action '%s' ignored", v4, a2);
result = 0LL;
}
}
else
{
func1(a1, a2);
result = 1LL;
}
}
else
{
v9 = *(unsigned int **)(a1 + 8);
v10 = 0xFFFFFFFFLL;
if ( v9 )
v10 = *v9;
logger_warning("[CLIENT] Client %i try to save unknown command '%s'", v10, a2);
result = 0LL;
}
return result;
}

original_code:
_Bool client_action_save(t_client *client, char *action)
{
  if (clm_command_retrieve(action))
    {
      if (client->busy == 0)
 client_execute(client, action);
      else if (list_size(&client->actions) <= 10)
 {
   logger_verbose("[CLIENT] Client %i save action '%s'", ((client)->player ? (client)->player->id : -1), action);
   list_add_end(&client->actions, strdup(action));
 }
      else
 {
   logger_warning("[CLIENT] Client %i action '%s' ignored", ((client)->player ? (client)->player->id : -1), action);
   return 0;
 }
      return 1;
    }
  logger_warning("[CLIENT] Client %i try to save unknown command '%s'", ((client)->player ? (client)->player->id : -1), action);
  return 0;
}

canonical_original_code:
_Bool client_action_save(struct s_client *client, char *action)
{
  if (clm_command_retrieve(action))
    {
      if (client->busy == 0)
 client_execute(client, action);
      else if (list_size(&client->actions) <= 10)
 {
   logger_verbose("[CLIENT] Client %i save action '%s'", ((client)->player ? (client)->player->id : -1), action);
   list_add_end(&client->actions, strdup(action));
 }
      else
 {
   logger_warning("[CLIENT] Client %i action '%s' ignored", ((client)->player ? (client)->player->id : -1), action);
   return 0;
 }
      return 1;
    }
  logger_warning("[CLIENT] Client %i try to save unknown command '%s'", ((client)->player ? (client)->player->id : -1), action);
  return 0;
}


decompiled_code:
void __fastcall client_action_finish(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rsi
__int64 v3; // rdx
unsigned int *v4; // rax
unsigned int *v5; // rax
__int64 v6; // rsi
char *v7; // r13

v1 = a1 + 16;
v2 = 0xFFFFFFFFLL;
v3 = (unsigned int)list_size(a1 + 16);
v4 = *(unsigned int **)(a1 + 8);
if ( v4 )
v2 = *v4;
logger_verbose("[CLIENT] Client %i has finish action, %i pending", v2, v3);
*(_BYTE *)(a1 + 40) = 0;
if ( (unsigned int)list_size(v1) )
{
v5 = *(unsigned int **)(a1 + 8);
v6 = 0xFFFFFFFFLL;
if ( v5 )
v6 = *v5;
logger_verbose("[CLIENT] Client %i have action in stack", v6);
v7 = (char *)list_get_begin(v1);
list_pop_begin(v1);
client_execute(a1, v7);
free(v7);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rsi
__int64 v3; // rdx
unsigned int *v4; // rax
unsigned int *v5; // rax
__int64 v6; // rsi
char *v7; // r13

v1 = a1 + 16;
v2 = 0xFFFFFFFFLL;
v3 = (unsigned int)list_size(a1 + 16);
v4 = *(unsigned int **)(a1 + 8);
if ( v4 )
v2 = *v4;
logger_verbose("[CLIENT] Client %i has finish action, %i pending", v2, v3);
*(_BYTE *)(a1 + 40) = 0;
if ( (unsigned int)list_size(v1) )
{
v5 = *(unsigned int **)(a1 + 8);
v6 = 0xFFFFFFFFLL;
if ( v5 )
v6 = *v5;
logger_verbose("[CLIENT] Client %i have action in stack", v6);
v7 = (char *)list_get_begin(v1);
list_pop_begin(v1);
func1(a1, v7);
free(v7);
}
}

original_code:
void client_action_finish(t_client *client)
{
  char *action;
  logger_verbose("[CLIENT] Client %i has finish action, %i pending", ((client)->player ? (client)->player->id : -1), list_size(&client->actions));
  client->busy = 0;
  if (list_size(&client->actions))
    {
      logger_verbose("[CLIENT] Client %i have action in stack", ((client)->player ? (client)->player->id : -1));
      action = list_get_begin(&client->actions);
      list_pop_begin(&client->actions);
      client_execute(client, action);
      free(action);
    }
}

canonical_original_code:
void client_action_finish(struct s_client *client)
{
  char *action;
  logger_verbose("[CLIENT] Client %i has finish action, %i pending", ((client)->player ? (client)->player->id : -1), list_size(&client->actions));
  client->busy = 0;
  if (list_size(&client->actions))
    {
      logger_verbose("[CLIENT] Client %i have action in stack", ((client)->player ? (client)->player->id : -1));
      action = list_get_begin(&client->actions);
      list_pop_begin(&client->actions);
      client_execute(client, action);
      free(action);
    }
}


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

result = 0LL;
if ( g_game )
result = *(unsigned int *)(g_game + 8LL);
return result;
}

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

result = 0LL;
if ( g_game )
result = *(unsigned int *)(g_game + 8LL);
return result;
}

original_code:
int game_width()
{
  if (g_game)
    return g_game->world.dimensions.x;
  return 0;
}


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

result = 0LL;
if ( g_game )
result = *(unsigned int *)(g_game + 12LL);
return result;
}

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

result = 0LL;
if ( g_game )
result = *(unsigned int *)(g_game + 12LL);
return result;
}

original_code:
int game_height()
{
  if (g_game)
    return g_game->world.dimensions.y;
  return 0;
}


decompiled_code:
char *__fastcall parser_find_key(char *string)
{
size_t v1; // rbp

v1 = 0LL;
while ( (int)parser_find_elem_type(&string[v1]) < 0 )
{
if ( !string[v1++] )
return 0LL;
}
if ( string[v1] && (_DWORD)v1 )
return strndup(string, v1);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func0(char *string)
{
size_t v1; // rbp

v1 = 0LL;
while ( (int)parser_find_elem_type(&string[v1]) < 0 )
{
if ( !string[v1++] )
return 0LL;
}
if ( string[v1] && (_DWORD)v1 )
return strndup(string, v1);
return 0LL;
}

original_code:
char *parser_find_key(char *mask)
{
  int i;
  int mask_index;
  int type;
  i = 0;
  mask_index = 0;
  while ((type = parser_find_elem_type(&mask[mask_index]) < 0) &&
  mask[mask_index])
    {
      mask_index++;
    }
  if (!mask[mask_index] || mask_index == 0)
    return (((void *)0));
  return (strndup(mask, mask_index));
}

variable_types:
mask
char *

variable_types: i int

variable_types: type int

return_type: char *


decompiled_code:
__int64 clock_create()
{
if ( g_clock )
return 0LL;
g_clock = malloc(0x38uLL);
return (unsigned int)-(g_clock == 0LL);
}

canonical_decompiled_code:
__int64 func0()
{
if ( g_clock )
return 0LL;
g_clock = malloc(0x38uLL);
return (unsigned int)-(g_clock == 0LL);
}

original_code:
static int clock_create()
{
  if (g_clock)
    return (0);;
  if (!(g_clock = malloc(sizeof(*g_clock))))
    return (-1);
  return (0);
}


decompiled_code:
__int64 clock_init()
{
int v0; // er8
__int64 result; // rax
char *v2; // rdi

v0 = clock_create();
result = 0LL;
if ( v0 >= 0 )
{
v2 = (char *)g_clock;
*((_DWORD *)g_clock + 12) = 1;
clock_set_time_to_current(v2 + 16);
timeval_modif(g_clock, 0LL, 0LL);
logger_message("[CLOCK] service started");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
int v0; // er8
__int64 result; // rax
char *v2; // rdi

v0 = func0();
result = 0LL;
if ( v0 >= 0 )
{
v2 = (char *)g_clock;
*((_DWORD *)g_clock + 12) = 1;
clock_set_time_to_current(v2 + 16);
timeval_modif(g_clock, 0LL, 0LL);
logger_message("[CLOCK] service started");
result = 1LL;
}
return result;
}

original_code:
_Bool clock_init()
{
  if (clock_create() < 0)
      return (0);
  g_clock->frequency = 1;
  clock_set_time_to_current(&g_clock->begin);
  timeval_modif(&g_clock->timeout, 0, 0);
  logger_message("[CLOCK] service started");
  return (1);
}


decompiled_code:
void clock_destroy()
{
free(g_clock);
g_clock = 0LL;
}

canonical_decompiled_code:
void func2()
{
free(g_clock);
g_clock = 0LL;
}

original_code:
void clock_destroy()
{
  free(g_clock);
  g_clock = ((void *)0);
}


decompiled_code:
void *get_clock()
{
return g_clock;
}

canonical_decompiled_code:
void *func3()
{
return g_clock;
}

original_code:
t_clock *get_clock()
{
  return (g_clock);
}

canonical_original_code:
struct s_clock *get_clock()
{
  return (g_clock);
}

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

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


decompiled_code:
__int64 __fastcall clock_set_frequency(unsigned int a1)
{
__int64 result; // rax

if ( a1 )
{
logger_message("[CLOCK] game frequency set to %ld", a1);
*((_DWORD *)g_clock + 12) = a1;
result = 1LL;
}
else
{
logger_error("[CLOCK] '0' is not a valid frequency, even for slowpoke");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 result; // rax

if ( a1 )
{
logger_message("[CLOCK] game frequency set to %ld", a1);
*((_DWORD *)g_clock + 12) = a1;
result = 1LL;
}
else
{
logger_error("[CLOCK] '0' is not a valid frequency, even for slowpoke");
result = 0LL;
}
return result;
}

original_code:
_Bool clock_set_frequency(unsigned int freq)
{
  if (freq)
    {
      logger_message("[CLOCK] game frequency set to %ld", freq);
      g_clock->frequency = freq;
      return (1);
    }
  else
    {
      logger_error("[CLOCK] '0' is not a valid frequency, even for slowpoke");
      return (0);
    }
}

variable_types:
freq
unsigned int


decompiled_code:
__int64 __fastcall gui_command_msz(__int64 a1)
{
unsigned int v1; // ebx
unsigned int v2; // eax
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = game_height();
v2 = game_width();
snprintf(v4, 0x40uLL, "msz %i %i", v2, v1);
return gui_send(a1, v4);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ebx
unsigned int v2; // eax
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = game_height();
v2 = game_width();
snprintf(v4, 0x40uLL, "msz %i %i", v2, v1);
return gui_send(a1, v4);
}

original_code:
void gui_command_msz(t_gui *gui, char *command)
{
  char buffer[64];
  (void) command;
  snprintf(buffer, 64, "msz %i %i", game_width(), game_height());
  gui_send(gui, buffer);
}

canonical_original_code:
void gui_command_msz(struct s_client *gui, char *command)
{
  char buffer[64];
  (void) command;
  snprintf(buffer, 64, "msz %i %i", game_width(), game_height());
  gui_send(gui, buffer);
}

variable_types:
buffer
char [64]


decompiled_code:
__int64 __fastcall gui_command_mct(__int64 a1)
{
unsigned int v1; // ebx
int v2; // ebp
__int64 result; // rax
int v4; // er13
unsigned int v5; // er14
__int64 v6; // rsi
unsigned int *v7; // rax
char s[104]; // [rsp+0h] [rbp-68h] BYREF

v1 = 0;
v2 = game_width();
result = game_height();
v4 = result;
if ( (int)result > 0 )
{
do
{
v5 = 0;
if ( v2 > 0 )
{
do
{
v6 = v5++;
v7 = (unsigned int *)world_get_tile(v1, v6);
snprintf(
s,
0x40uLL,
"bct %i %i %i %i %i %i %i %i %i",
v7[6],
v7[7],
v7[8],
v7[9],
v7[10],
v7[11],
v7[12],
v7[13],
v7[14]);
result = gui_send(a1, s);
}
while ( v2 != v5 );
}
++v1;
}
while ( v4 != v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebx
int v2; // ebp
__int64 result; // rax
int v4; // er13
unsigned int v5; // er14
__int64 v6; // rsi
unsigned int *v7; // rax
char s[104]; // [rsp+0h] [rbp-68h] BYREF

v1 = 0;
v2 = game_width();
result = game_height();
v4 = result;
if ( (int)result > 0 )
{
do
{
v5 = 0;
if ( v2 > 0 )
{
do
{
v6 = v5++;
v7 = (unsigned int *)world_get_tile(v1, v6);
snprintf(
s,
0x40uLL,
"bct %i %i %i %i %i %i %i %i %i",
v7[6],
v7[7],
v7[8],
v7[9],
v7[10],
v7[11],
v7[12],
v7[13],
v7[14]);
result = gui_send(a1, s);
}
while ( v2 != v5 );
}
++v1;
}
while ( v4 != v1 );
}
return result;
}

original_code:
void gui_command_mct(t_gui *gui, char *command)
{
  char buffer[64];
  t_tile *tile;
  int x;
  int y;
  int i;
  int j;
  (void) command;
  x = game_width();
  y = game_height();
  i = 0;
  while (i < y)
    {
      j = 0;
      while (j < x)
 {
   tile = world_get_tile(i, j);
   snprintf(buffer, 64, "bct %i %i %i %i %i %i %i %i %i",
     tile->coord.x, tile->coord.y,
     tile->ressources.food, tile->ressources.linemate, tile->ressources.deraumere,
     tile->ressources.sibur, tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
   gui_send(gui, buffer);
   j++;
 }
      i++;
    }
}

canonical_original_code:
void gui_command_mct(struct s_client *gui, char *command)
{
  char buffer[64];
  struct s_tile *tile;
  int x;
  int y;
  int i;
  int j;
  (void) command;
  x = game_width();
  y = game_height();
  i = 0;
  while (i < y)
    {
      j = 0;
      while (j < x)
 {
   tile = world_get_tile(i, j);
   snprintf(buffer, 64, "bct %i %i %i %i %i %i %i %i %i",
     tile->coord.x, tile->coord.y,
     tile->ressources.food, tile->ressources.linemate, tile->ressources.deraumere,
     tile->ressources.sibur, tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
   gui_send(gui, buffer);
   j++;
 }
      i++;
    }
}

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

variable_types: j int


decompiled_code:
__int64 __fastcall gui_command_bct(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v5; // rbp
unsigned int v6; // er13
unsigned int v7; // eax
unsigned int *v8; // rax
char s[88]; // [rsp+0h] [rbp-58h] BYREF

result = parser_parse(a2, "bct %i %i", a3, a4);
if ( result )
{
v5 = result;
v6 = parser_get_int(result, 1LL);
v7 = parser_get_int(v5, 0LL);
v8 = (unsigned int *)world_get_tile(v7, v6);
snprintf(
s,
0x40uLL,
"bct %i %i %i %i %i %i %i %i %i",
v8[6],
v8[7],
v8[8],
v8[9],
v8[10],
v8[11],
v8[12],
v8[13],
v8[14]);
gui_send(a1, s);
result = parser_command_destroy(v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 v5; // rbp
unsigned int v6; // er13
unsigned int v7; // eax
unsigned int *v8; // rax
char s[88]; // [rsp+0h] [rbp-58h] BYREF

result = parser_parse(a2, "bct %i %i", a3, a4);
if ( result )
{
v5 = result;
v6 = parser_get_int(result, 1LL);
v7 = parser_get_int(v5, 0LL);
v8 = (unsigned int *)world_get_tile(v7, v6);
snprintf(
s,
0x40uLL,
"bct %i %i %i %i %i %i %i %i %i",
v8[6],
v8[7],
v8[8],
v8[9],
v8[10],
v8[11],
v8[12],
v8[13],
v8[14]);
gui_send(a1, s);
result = parser_command_destroy(v5);
}
return result;
}

original_code:
void gui_command_bct(t_gui *gui, char *command)
{
  char buffer[64];
  t_command *parse;
  t_tile *tile;
  parse = parser_parse(command, "bct %i %i");
  if (parse)
    {
      tile = world_get_tile(parser_get_int(parse, 0), parser_get_int(parse, 1));
      snprintf(buffer, 64, "bct %i %i %i %i %i %i %i %i %i",
        tile->coord.x, tile->coord.y,
        tile->ressources.food, tile->ressources.linemate, tile->ressources.deraumere,
        tile->ressources.sibur, tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
      gui_send(gui, buffer);
      parser_command_destroy(parse);
    }
}

canonical_original_code:
void gui_command_bct(struct s_client *gui, char *command)
{
  char buffer[64];
  struct s_command *parse;
  struct s_tile *tile;
  parse = parser_parse(command, "bct %i %i");
  if (parse)
    {
      tile = world_get_tile(parser_get_int(parse, 0), parser_get_int(parse, 1));
      snprintf(buffer, 64, "bct %i %i %i %i %i %i %i %i %i",
        tile->coord.x, tile->coord.y,
        tile->ressources.food, tile->ressources.linemate, tile->ressources.deraumere,
        tile->ressources.sibur, tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
      gui_send(gui, buffer);
      parser_command_destroy(parse);
    }
}

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

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


decompiled_code:
__int64 __fastcall gui_command_tna(__int64 a1)
{
__int64 result; // rax
__int64 i; // rbx
const char **v3; // rax
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

result = game_get_teams();
for ( i = *(_QWORD *)(result + 8); i; result = gui_send(a1, v4) )
{
v3 = (const char **)i;
i = *(_QWORD *)(i + 16);
snprintf(v4, 0x40uLL, "tna %s", *v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
__int64 i; // rbx
const char **v3; // rax
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

result = game_get_teams();
for ( i = *(_QWORD *)(result + 8); i; result = gui_send(a1, v4) )
{
v3 = (const char **)i;
i = *(_QWORD *)(i + 16);
snprintf(v4, 0x40uLL, "tna %s", *v3);
}
return result;
}

original_code:
void gui_command_tna(t_gui *gui, char *command)
{
  char buffer[64];
  t_team *team;
  (void) command;
  t_list *__list = (game_get_teams()); t_list_node *__current; t_list_node *__next = __list->head; while ((__current = __next) && (((__next && (__next = __next->next))) || 1) && (((team) = __current->data) || 1))
  {
    snprintf(buffer, 64, "tna %s", team->name);
    gui_send(gui, buffer);
  }
}

canonical_original_code:
void gui_command_tna(struct s_client *gui, char *command)
{
  char buffer[64];
  struct s_team *team;
  (void) command;
  struct s_list *__list = (game_get_teams()); struct s_list_node *__current; struct s_list_node *__next = __list->head; while ((__current = __next) && (((__next && (__next = __next->next))) || 1) && (((team) = __current->data) || 1))
  {
    snprintf(buffer, 64, "tna %s", team->name);
    gui_send(gui, buffer);
  }
}

variable_types:
command
char *

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

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


decompiled_code:
__int64 __fastcall player_take_end_cb(__int64 a1, int a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
int v4; // eax

if ( a2 )
return client_send(a1, &unk_79);
v2 = *(_QWORD *)(a1 + 8);
v3 = *(_QWORD *)(v2 + 16);
v4 = *(_DWORD *)(v3 + 32);
if ( v4 <= 0 )
return client_send(a1, &unk_79);
*(_DWORD *)(v3 + 32) = v4 - 1;
++*(_DWORD *)(v2 + 28);
return client_send(a1, &unk_76);
}

original_code:
void player_take_end_cb(t_client *client, int error)
{
  int *inventory;
  int *ressources;
  t_tile *tile;
  if (!error)
    {
      tile = client->player->tile;
      ressources = (int *)&tile->ressources;
      inventory = (int *)&client->player->inventory;
      if (ressources[item] > 0)
 {
   ressources[item] -= 1;
   inventory[item] += 1;
   client_send(client, "ok");
 }
      else
 client_send(client, "ko");
    }
  else
    client_send(client, "ko");
}

canonical_original_code:
void player_take_end_cb(struct s_client *client, int error)
{
  int *inventory;
  int *ressources;
  struct s_tile *tile;
  if (!error)
    {
      tile = client->player->tile;
      ressources = (int *)&tile->ressources;
      inventory = (int *)&client->player->inventory;
      if (ressources[item] > 0)
 {
   ressources[item] -= 1;
   inventory[item] += 1;
   client_send(client, "ok");
 }
      else
 client_send(client, "ko");
    }
  else
    client_send(client, "ko");
}

variable_types: error int

variable_types:
inventory
int *

variable_types:
ressources
int *


decompiled_code:
__int64 __fastcall player_take_start_cb(__int64 a1)
{
__int64 result; // rax

if ( *(int *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL) + 32LL) <= 0 )
result = client_send(a1, &unk_79);
else
result = kernel_register_wakeup(7LL, player_take_end_cb, a1);
return result;
}

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

if ( *(int *)(*(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL) + 32LL) <= 0 )
result = client_send(a1, &unk_79);
else
result = kernel_register_wakeup(7LL, player_take_end_cb, a1);
return result;
}

original_code:
void player_take_start_cb(t_client *client, char *command)
{
  t_tile *tile;
  int *ressources;
  (void) command;
  tile = client->player->tile;
  ressources = (int *)&tile->ressources;
  if (ressources[item] > 0)
    kernel_register_wakeup(7, (kn_wakeup_cb) player_take_end_cb, client);
  else
    client_send(client, "ko");
}

canonical_original_code:
void player_take_start_cb(struct s_client *client, char *command)
{
  struct s_tile *tile;
  int *ressources;
  (void) command;
  tile = client->player->tile;
  ressources = (int *)&tile->ressources;
  if (ressources[item] > 0)
    kernel_register_wakeup(7, (void (*)(void *, int)) player_take_end_cb, client);
  else
    client_send(client, "ko");
}


decompiled_code:
__int64 __fastcall clock_compare(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( *a1 != *a2 )
return 2 * (unsigned int)(*a1 > *a2) - 1;
v3 = a2[1];
result = 1LL;
if ( a1[1] <= v3 )
result = (unsigned int)-(a1[1] < v3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( *a1 != *a2 )
return 2 * (unsigned int)(*a1 > *a2) - 1;
v3 = a2[1];
result = 1LL;
if ( a1[1] <= v3 )
result = (unsigned int)-(a1[1] < v3);
return result;
}

original_code:
int clock_compare(struct timeval *date1, struct timeval *date2)
{
  if (date1->tv_sec != date2->tv_sec)
    {
    if (date1->tv_sec > date2->tv_sec)
      return (1);
    else
      return (-1);
    }
  else
    {
      if (date1->tv_usec > date2->tv_usec)
 return (1);
      else if (date1->tv_usec < date2->tv_usec)
 return (-1);
      else
 return (0);
    }
}

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


decompiled_code:
__int64 __fastcall gui_action_take(unsigned int *a1, unsigned int a2)
{
unsigned int *v2; // rbp
char s[88]; // [rsp+0h] [rbp-58h] BYREF

v2 = (unsigned int *)*((_QWORD *)a1 + 2);
snprintf(s, 0x40uLL, "pgt #%i %i", *a1, a2);
gui_send_all(s);
snprintf(
s,
0x40uLL,
"pin #%i %i %i %i %i %i %i %i %i %i",
*a1,
*(unsigned int *)(*((_QWORD *)a1 + 2) + 24LL),
*(unsigned int *)(*((_QWORD *)a1 + 2) + 28LL),
a1[7],
a1[8],
a1[9],
a1[10],
a1[11],
a1[12],
a1[13]);
gui_send_all(s);
snprintf(
s,
0x40uLL,
"bct %i %i %i %i %i %i %i %i %i",
v2[6],
v2[7],
v2[8],
v2[9],
v2[10],
v2[11],
v2[12],
v2[13],
v2[14]);
return gui_send_all(s);
}

original_code:
void gui_action_take(t_player* player, t_item item)
{
  char buffer[64];
  t_tile *tile;
  tile = player->tile;
  snprintf(buffer, 64, "pgt #%i %i", player->id, item);
  gui_send_all(buffer);
  snprintf(buffer, 64, "pin #%i %i %i %i %i %i %i %i %i %i",
    player->id, player->tile->coord.x, player->tile->coord.y,
    player->inventory.food, player->inventory.linemate, player->inventory.deraumere,
    player->inventory.sibur, player->inventory.mendiane, player->inventory.phiras, player->inventory.thystame);
  gui_send_all(buffer);
  snprintf(buffer, 64, "bct %i %i %i %i %i %i %i %i %i",
    tile->coord.x, tile->coord.y,
    tile->ressources.food, tile->ressources.linemate, tile->ressources.deraumere,
    tile->ressources.sibur, tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
  gui_send_all(buffer);
}

canonical_original_code:
void gui_action_take(struct s_player *player, enum t_item item)
{
  char buffer[64];
  struct s_tile *tile;
  tile = player->tile;
  snprintf(buffer, 64, "pgt #%i %i", player->id, item);
  gui_send_all(buffer);
  snprintf(buffer, 64, "pin #%i %i %i %i %i %i %i %i %i %i",
    player->id, player->tile->coord.x, player->tile->coord.y,
    player->inventory.food, player->inventory.linemate, player->inventory.deraumere,
    player->inventory.sibur, player->inventory.mendiane, player->inventory.phiras, player->inventory.thystame);
  gui_send_all(buffer);
  snprintf(buffer, 64, "bct %i %i %i %i %i %i %i %i %i",
    tile->coord.x, tile->coord.y,
    tile->ressources.food, tile->ressources.linemate, tile->ressources.deraumere,
    tile->ressources.sibur, tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
  gui_send_all(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: enum t_item { IT_FOOD=0, IT_LINEMATE=1, IT_DERAUMERE=2, IT_SIBUR=3, IT_MENDIANE=4, IT_PHIRAS=5, IT_THYSTAME=6 }


decompiled_code:
__int64 __fastcall gui_action_drop(unsigned int *a1, unsigned int a2)
{
unsigned int *v2; // rbp
char s[88]; // [rsp+0h] [rbp-58h] BYREF

v2 = (unsigned int *)*((_QWORD *)a1 + 2);
snprintf(s, 0x40uLL, "pdr #%i %i", *a1, a2);
gui_send_all(s);
snprintf(
s,
0x40uLL,
"pin #%i %i %i %i %i %i %i %i %i %i",
*a1,
*(unsigned int *)(*((_QWORD *)a1 + 2) + 24LL),
*(unsigned int *)(*((_QWORD *)a1 + 2) + 28LL),
a1[7],
a1[8],
a1[9],
a1[10],
a1[11],
a1[12],
a1[13]);
gui_send_all(s);
snprintf(
s,
0x40uLL,
"bct %i %i %i %i %i %i %i %i %i",
v2[6],
v2[7],
v2[8],
v2[9],
v2[10],
v2[11],
v2[12],
v2[13],
v2[14]);
return gui_send_all(s);
}

original_code:
void gui_action_drop(t_player* player, t_item item)
{
  char buffer[64];
  t_tile *tile;
  tile = player->tile;
  snprintf(buffer, 64, "pdr #%i %i", player->id, item);
  gui_send_all(buffer);
  snprintf(buffer, 64, "pin #%i %i %i %i %i %i %i %i %i %i",
    player->id, player->tile->coord.x, player->tile->coord.y,
    player->inventory.food, player->inventory.linemate, player->inventory.deraumere,
    player->inventory.sibur, player->inventory.mendiane, player->inventory.phiras, player->inventory.thystame);
  gui_send_all(buffer);
  snprintf(buffer, 64, "bct %i %i %i %i %i %i %i %i %i",
    tile->coord.x, tile->coord.y,
    tile->ressources.food, tile->ressources.linemate, tile->ressources.deraumere,
    tile->ressources.sibur, tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
  gui_send_all(buffer);
}

canonical_original_code:
void gui_action_drop(struct s_player *player, enum t_item item)
{
  char buffer[64];
  struct s_tile *tile;
  tile = player->tile;
  snprintf(buffer, 64, "pdr #%i %i", player->id, item);
  gui_send_all(buffer);
  snprintf(buffer, 64, "pin #%i %i %i %i %i %i %i %i %i %i",
    player->id, player->tile->coord.x, player->tile->coord.y,
    player->inventory.food, player->inventory.linemate, player->inventory.deraumere,
    player->inventory.sibur, player->inventory.mendiane, player->inventory.phiras, player->inventory.thystame);
  gui_send_all(buffer);
  snprintf(buffer, 64, "bct %i %i %i %i %i %i %i %i %i",
    tile->coord.x, tile->coord.y,
    tile->ressources.food, tile->ressources.linemate, tile->ressources.deraumere,
    tile->ressources.sibur, tile->ressources.mendiane, tile->ressources.phiras, tile->ressources.thystame);
  gui_send_all(buffer);
}

user_defined_types: enum t_item { IT_FOOD=0, IT_LINEMATE=1, IT_DERAUMERE=2, IT_SIBUR=3, IT_MENDIANE=4, IT_PHIRAS=5, IT_THYSTAME=6 }


decompiled_code:
_QWORD *parser_get_type_str()
{
_QWORD *result; // rax

result = (_QWORD *)parser_find_known_type_from_int();
if ( result )
result = (_QWORD *)*result;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = (_QWORD *)parser_find_known_type_from_int();
if ( result )
result = (_QWORD *)*result;
return result;
}

original_code:
char *parser_get_type_str(int type_int)
{
  t_known_type *known_type;
  if (!(known_type = parser_find_known_type_from_int(type_int)))
    return (((void *)0));
  return (known_type->type_str);
}

canonical_original_code:
char *parser_get_type_str(int type_int)
{
  struct s_known_type *known_type;
  if (!(known_type = parser_find_known_type_from_int(type_int)))
    return (((void *)0));
  return (known_type->type_str);
}

variable_types: struct s_known_type { char *type_str; int type_int; int (*argument_setter)(int, char *, struct s_argument { int type; void *data; } *); } *

user_defined_types: struct s_known_type { char *type_str; int type_int; int (*argument_setter)(int, char *, struct s_argument *); }


decompiled_code:
__int64 parser_get_type_int()
{
__int64 v0; // rax
__int64 result; // rax

v0 = parser_find_known_type_from_str();
if ( v0 )
result = *(unsigned int *)(v0 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

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

v0 = parser_find_known_type_from_str();
if ( v0 )
result = *(unsigned int *)(v0 + 8);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int parser_get_type_int(char *type_str)
{
  t_known_type *known_type;
  if (!(known_type = parser_find_known_type_from_str(type_str)))
    return (-1);
  return (known_type->type_int);
}

canonical_original_code:
int parser_get_type_int(char *type_str)
{
  struct s_known_type *known_type;
  if (!(known_type = parser_find_known_type_from_str(type_str)))
    return (-1);
  return (known_type->type_int);
}

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


decompiled_code:
__int64 parser_get_argument_setter_int()
{
__int64 v0; // rax
__int64 result; // rax

v0 = parser_find_known_type_from_int();
if ( v0 )
result = *(_QWORD *)(v0 + 16);
else
result = 0LL;
return result;
}

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

v0 = parser_find_known_type_from_int();
if ( v0 )
result = *(_QWORD *)(v0 + 16);
else
result = 0LL;
return result;
}

original_code:
t_f_arg_set parser_get_argument_setter_int(int type_int)
{
  t_known_type *known_type;
  if (!(known_type = parser_find_known_type_from_int(type_int)))
    return (((void *)0));
  return (known_type->argument_setter);
}

canonical_original_code:
int (*parser_get_argument_setter_int(int type_int))(int, char *, struct s_argument *)
{
  struct s_known_type *known_type;
  if (!(known_type = parser_find_known_type_from_int(type_int)))
    return (((void *)0));
  return (known_type->argument_setter);
}

return_type: int (*)(int, char *, struct s_argument { int type; void *data; } *)


decompiled_code:
__int64 parser_get_argument_setter_str()
{
__int64 v0; // rax
__int64 result; // rax

v0 = parser_find_known_type_from_str();
if ( v0 )
result = *(_QWORD *)(v0 + 16);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rax
__int64 result; // rax

v0 = parser_find_known_type_from_str();
if ( v0 )
result = *(_QWORD *)(v0 + 16);
else
result = 0LL;
return result;
}

original_code:
t_f_arg_set parser_get_argument_setter_str(char *type_str)
{
  t_known_type *known_type;
  if (!(known_type = parser_find_known_type_from_str(type_str)))
    return (((void *)0));
  return (known_type->argument_setter);
}

canonical_original_code:
int (*parser_get_argument_setter_str(char *type_str))(int, char *, struct s_argument *)
{
  struct s_known_type *known_type;
  if (!(known_type = parser_find_known_type_from_str(type_str)))
    return (((void *)0));
  return (known_type->argument_setter);
}


decompiled_code:
char *__fastcall clm_command_register(char *a1, char *a2, __int64 a3)
{
char *result; // rax

result = clm_command_create(a1, a2, a3);
if ( result )
result = (char *)list_add_end(g_client_manager + 24LL, result);
return result;
}

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

result = func0(a1, a2, a3);
if ( result )
result = (char *)list_add_end(g_client_manager + 24LL, result);
return result;
}

original_code:
void clm_command_register(char *instruction, char *mask, t_execute_cb callback)
{
  t_command_callback *command;
  command = _clm_command_create(instruction, mask, callback);
  if (command)
    list_add_end(&g_client_manager->commands, command);
}

canonical_original_code:
void clm_command_register(char *instruction, char *mask, void (*callback)(struct s_client *, char *))
{
  struct s_command_callback *command;
  command = _clm_command_create(instruction, mask, callback);
  if (command)
    list_add_end(&g_client_manager->commands, command);
}

variable_types:
instruction
char *

variable_types:
mask
char *

variable_types: void (*)(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 *); } *, char *)

variable_types: struct s_command_callback { char instruction[-1]; char mask[-1]; unsigned int length; void (*callback)(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 *); } *, char *); } *


decompiled_code:
__int64 __fastcall clm_command_retrieve(__int64 a1)
{
return list_get_to_param(g_client_manager + 24LL, clm_command_retrieve_cmp, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return list_get_to_param(g_client_manager + 24LL, clm_command_retrieve_cmp, a1);
}

original_code:
t_command_callback *clm_command_retrieve(char *action)
{
  return list_get_to_param(&g_client_manager->commands, (fpredp) &_clm_command_retrieve_cmp, action);
}

canonical_original_code:
struct s_command_callback *clm_command_retrieve(char *action)
{
  return list_get_to_param(&g_client_manager->commands, (fpredp) &_clm_command_retrieve_cmp, action);
}

variable_types:
action
char *

return_type: struct s_command_callback { char instruction[-1]; char mask[-1]; unsigned int length; void (*callback)(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 *); } *, char *); } *


decompiled_code:
void gui_command_ppo()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void gui_command_ppo(t_gui *gui, char *command)
{
  (void) gui;
  (void) command;
}

canonical_original_code:
void gui_command_ppo(struct s_client *gui, char *command)
{
  (void) gui;
  (void) command;
}

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


decompiled_code:
void gui_command_plv()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void gui_command_plv(t_gui *gui, char *command)
{
  (void) gui;
  (void) command;
}

canonical_original_code:
void gui_command_plv(struct s_client *gui, char *command)
{
  (void) gui;
  (void) command;
}


decompiled_code:
void gui_command_pin()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void gui_command_pin(t_gui *gui, char *command)
{
  (void) gui;
  (void) command;
}

canonical_original_code:
void gui_command_pin(struct s_client *gui, char *command)
{
  (void) gui;
  (void) command;
}


decompiled_code:
void gui_command_sgt()
{
;
}

canonical_decompiled_code:
void func4()
{
;
}

original_code:
void gui_command_sgt(t_gui *gui, char *command)
{
  (void) gui;
  (void) command;
}

canonical_original_code:
void gui_command_sgt(struct s_client *gui, char *command)
{
  (void) gui;
  (void) command;
}


decompiled_code:
void gui_command_sst()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void gui_command_sst(t_gui *gui, char *command)
{
  (void) gui;
  (void) command;
}

canonical_original_code:
void gui_command_sst(struct s_client *gui, char *command)
{
  (void) gui;
  (void) command;
}


decompiled_code:
__int64 __fastcall parser_get_int(__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 0xFFFFFFFFLL;
v5 = list_get_at(v3, (unsigned int)i);
if ( *(_DWORD *)v5 == 2 )
break;
LABEL_2:
;
}
if ( v2 != a2 )
{
++v2;
goto LABEL_2;
}
return **(unsigned int **)(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 0xFFFFFFFFLL;
v5 = list_get_at(v3, (unsigned int)i);
if ( *(_DWORD *)v5 == 2 )
break;
LABEL_2:
;
}
if ( v2 != a2 )
{
++v2;
goto LABEL_2;
}
return **(unsigned int **)(v5 + 8);
}

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

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

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

variable_types: i int


decompiled_code:
char **__fastcall parser_find_known_type_from_int(int a1)
{
char **v1; // r8
char **v2; // rax
int v3; // edx

v1 = (char **)g_known_type;
if ( g_known_type )
{
v2 = &g_known_type;
v3 = 0;
while ( *((_DWORD *)v2 + 2) != a1 )
{
v1 = (char **)v2[3];
v2 += 3;
++v3;
if ( !v1 )
return v1;
}
v1 = &(&g_known_type)[3 * v3];
}
return v1;
}

canonical_decompiled_code:
char **__fastcall func0(int a1)
{
char **v1; // r8
char **v2; // rax
int v3; // edx

v1 = (char **)g_known_type;
if ( g_known_type )
{
v2 = &g_known_type;
v3 = 0;
while ( *((_DWORD *)v2 + 2) != a1 )
{
v1 = (char **)v2[3];
v2 += 3;
++v3;
if ( !v1 )
return v1;
}
v1 = &(&g_known_type)[3 * v3];
}
return v1;
}

original_code:
t_known_type *parser_find_known_type_from_int(int type_int)
{
  int i;
  i = 0;
  while (g_known_type[i].type_str)
    {
      if (type_int == g_known_type[i].type_int)
 return (&g_known_type[i]);
      i++;
    }
  return (((void *)0));
}

canonical_original_code:
struct s_known_type *parser_find_known_type_from_int(int type_int)
{
  int i;
  i = 0;
  while (g_known_type[i].type_str)
    {
      if (type_int == g_known_type[i].type_int)
 return (&g_known_type[i]);
      i++;
    }
  return (((void *)0));
}

return_type: struct s_known_type { char *type_str; int type_int; int (*argument_setter)(int, char *, struct s_argument { int type; void *data; } *); } *


decompiled_code:
char **__fastcall parser_find_known_type_from_str(char *s1)
{
const char *v1; // rsi
int v2; // ebp
char **v3; // rbx

if ( !s1 )
return 0LL;
v1 = g_known_type;
if ( !g_known_type )
return (char **)v1;
v2 = 0;
v3 = &g_known_type;
while ( strcmp(s1, v1) )
{
v1 = v3[3];
v3 += 3;
++v2;
if ( !v1 )
return (char **)v1;
}
return &(&g_known_type)[3 * v2];
}

canonical_decompiled_code:
char **__fastcall func1(char *s1)
{
const char *v1; // rsi
int v2; // ebp
char **v3; // rbx

if ( !s1 )
return 0LL;
v1 = g_known_type;
if ( !g_known_type )
return (char **)v1;
v2 = 0;
v3 = &g_known_type;
while ( strcmp(s1, v1) )
{
v1 = v3[3];
v3 += 3;
++v2;
if ( !v1 )
return (char **)v1;
}
return &(&g_known_type)[3 * v2];
}

original_code:
t_known_type *parser_find_known_type_from_str(char *type_str)
{
  int i;
  i = 0;
  if (!type_str)
    return (((void *)0));
  while (g_known_type[i].type_str)
    {
      if (!(strcmp(type_str, g_known_type[i].type_str)))
        return (&g_known_type[i]);
      i++;
    }
  return (((void *)0));
}

canonical_original_code:
struct s_known_type *parser_find_known_type_from_str(char *type_str)
{
  int i;
  i = 0;
  if (!type_str)
    return (((void *)0));
  while (g_known_type[i].type_str)
    {
      if (!(strcmp(type_str, g_known_type[i].type_str)))
        return (&g_known_type[i]);
      i++;
    }
  return (((void *)0));
}


decompiled_code:
__int64 __fastcall parser_find_elem_type(char *s1)
{
const char *v1; // rbp
char **v2; // rbx
int i; // er12
size_t v4; // rax

if ( !s1 )
return 0xFFFFFFFFLL;
v1 = g_known_type;
if ( !g_known_type )
return 0xFFFFFFFFLL;
v2 = &g_known_type;
for ( i = 0; ; ++i )
{
v4 = strlen(v1);
if ( !strncmp(s1, v1, v4) )
break;
v1 = v2[3];
v2 += 3;
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)dword_148[6 * i];
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
const char *v1; // rbp
char **v2; // rbx
int i; // er12
size_t v4; // rax

if ( !s1 )
return 0xFFFFFFFFLL;
v1 = g_known_type;
if ( !g_known_type )
return 0xFFFFFFFFLL;
v2 = &g_known_type;
for ( i = 0; ; ++i )
{
v4 = strlen(v1);
if ( !strncmp(s1, v1, v4) )
break;
v1 = v2[3];
v2 += 3;
if ( !v1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)dword_148[6 * i];
}

original_code:
int parser_find_elem_type(char *mask)
{
  int i;
  i = 0;
  if (!mask)
    return (-1);
  while (g_known_type[i].type_str)
    {
      if (!(strncmp(mask, g_known_type[i].type_str,
      strlen(g_known_type[i].type_str))))
 return (g_known_type[i].type_int);
      i++;
    }
  return (-1);
}


decompiled_code:
int __fastcall execute_from_listener(__int64 a1)
{
char *v1; // rax
_DWORD *v2; // rbp

logger_message("[NETWORK] new connection detected");
v1 = (char *)malloc(0x28uLL);
if ( v1 )
{
*((_DWORD *)v1 + 5) = 16;
v2 = v1;
LODWORD(v1) = accept(**(_DWORD **)a1, (struct sockaddr *)(v1 + 4), (socklen_t *)v1 + 5);
*v2 = (_DWORD)v1;
if ( (int)v1 >= 0 )
{
logger_debug("[NETWORK] give fd %d for new client", (unsigned int)v1);
logger_debug("[NETWORK] calling creation callback");
++*(_QWORD *)(g_network + 32LL);
v1 = *(char **)(a1 + 8);
if ( v1 )
LODWORD(v1) = ((__int64 (__fastcall *)(_DWORD *))v1)(v2);
}
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
char *v1; // rax
_DWORD *v2; // rbp

logger_message("[NETWORK] new connection detected");
v1 = (char *)malloc(0x28uLL);
if ( v1 )
{
*((_DWORD *)v1 + 5) = 16;
v2 = v1;
LODWORD(v1) = accept(**(_DWORD **)a1, (struct sockaddr *)(v1 + 4), (socklen_t *)v1 + 5);
*v2 = (_DWORD)v1;
if ( (int)v1 >= 0 )
{
logger_debug("[NETWORK] give fd %d for new client", (unsigned int)v1);
logger_debug("[NETWORK] calling creation callback");
++*(_QWORD *)(g_network + 32LL);
v1 = *(char **)(a1 + 8);
if ( v1 )
LODWORD(v1) = ((__int64 (__fastcall *)(_DWORD *))v1)(v2);
}
}
return (int)v1;
}

original_code:
void execute_from_listener(void *data)
{
  t_listener *listener;
  t_socket *sock;
  logger_message("[NETWORK] new connection detected");
  if (!(sock = malloc(sizeof(*sock))))
    return;
  sock->length = sizeof(sock->addr);
  listener = (t_listener*)data;
  if ((sock->fd = accept(listener->socket->fd, (SOCKADDR *) &sock->addr, &sock->length)) < 0)
    return;
  logger_debug("[NETWORK] give fd %d for new client", sock->fd);
  logger_debug("[NETWORK] calling creation callback");
  g_network->opened_socket++;
  if (listener->create)
    (*listener->create)(sock);
}

canonical_original_code:
void execute_from_listener(void *data)
{
  struct s_listener *listener;
  struct s_socket *sock;
  logger_message("[NETWORK] new connection detected");
  if (!(sock = malloc(sizeof(*sock))))
    return;
  sock->length = sizeof(sock->addr);
  listener = (struct s_listener *)data;
  if ((sock->fd = accept(listener->socket->fd, (struct sockaddr *) &sock->addr, &sock->length)) < 0)
    return;
  logger_debug("[NETWORK] give fd %d for new client", sock->fd);
  logger_debug("[NETWORK] calling creation callback");
  g_network->opened_socket++;
  if (listener->create)
    (*listener->create)(sock);
}

variable_types:
data
void *

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 __fastcall extract_from_socket(unsigned int *a1)
{
return *a1;
}

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

original_code:
SOCKET extract_from_socket(void *data)
{
  t_socket *socket;
  socket = (t_socket*)data;
  return (socket->fd);
}

canonical_original_code:
int extract_from_socket(void *data)
{
  struct s_socket *socket;
  socket = (struct s_socket *)data;
  return (socket->fd);
}

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

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


decompiled_code:
__int64 __fastcall extract_from_listener(unsigned int **a1)
{
return **a1;
}

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

original_code:
SOCKET extract_from_listener(void *data)
{
  t_listener *listener;
  listener = (t_listener*)data;
  return (listener->socket->fd);
}

canonical_original_code:
int extract_from_listener(void *data)
{
  struct s_listener *listener;
  listener = (struct s_listener *)data;
  return (listener->socket->fd);
}


decompiled_code:
__int64 __fastcall clock_move_date(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

time_unit_to_timeval(v2);
return timeval_add(a1, v2, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
_BYTE v2[24]; // [rsp+0h] [rbp-18h] BYREF

time_unit_to_timeval(v2);
return timeval_add(a1, v2, a1);
}

original_code:
void clock_move_date(struct timeval *time,
     unsigned int next)
{
  struct timeval tmp;
  time_unit_to_timeval(&tmp, next);
  timeval_add(time, &tmp, time);
}

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

variable_types:
next
unsigned int


decompiled_code:
__int64 __fastcall player_death_cb(__int64 a1)
{
logger_verbose("[GAME] player %ud is dead", **(unsigned int **)(a1 + 8));
return client_send(a1, "mort");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
logger_verbose("[GAME] player %ud is dead", **(unsigned int **)(a1 + 8));
return client_send(a1, "mort");
}

original_code:
void player_death_cb(t_client *client, char *command)
{
  (void)command;
  logger_verbose("[GAME] player %ud is dead", client->player->id);
  client_send(client, "mort");
}

canonical_original_code:
void player_death_cb(struct s_client *client, char *command)
{
  (void)command;
  logger_verbose("[GAME] player %ud is dead", client->player->id);
  client_send(client, "mort");
}

variable_types:
command
char *

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_player { int id; struct s_team *team; struct s_tile *tile; enum t_orientation orientation; struct s_inventory inventory; int level; int life; }


decompiled_code:
__int64 __fastcall client_food_dead(__int64 a1)
{
unsigned int *v1; // rax
__int64 v2; // rsi

v1 = *(unsigned int **)(a1 + 8);
v2 = 0xFFFFFFFFLL;
if ( v1 )
v2 = *v1;
logger_message("[CLIENT] Client %i starved ... dead!", v2);
player_free(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
client_send(a1, "mort");
return client_unconnect(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int *v1; // rax
__int64 v2; // rsi

v1 = *(unsigned int **)(a1 + 8);
v2 = 0xFFFFFFFFLL;
if ( v1 )
v2 = *v1;
logger_message("[CLIENT] Client %i starved ... dead!", v2);
player_free(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
client_send(a1, "mort");
return client_unconnect(a1);
}

original_code:
void client_food_dead(t_client *client)
{
  logger_message("[CLIENT] Client %i starved ... dead!", ((client)->player ? (client)->player->id : -1));
  player_free(client->player);
  client->player = ((void *)0);
  client_send(client, "mort");
  client_unconnect(client);
}

canonical_original_code:
void client_food_dead(struct s_client *client)
{
  logger_message("[CLIENT] Client %i starved ... dead!", ((client)->player ? (client)->player->id : -1));
  player_free(client->player);
  client->player = ((void *)0);
  client_send(client, "mort");
  client_unconnect(client);
}

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

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


decompiled_code:
__int64 __fastcall client_consume_food(__int64 a1)
{
__int64 v1; // rax
int v2; // edx

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return client_food_dead(a1);
v2 = *(_DWORD *)(v1 + 28);
if ( v2 <= 0 )
return client_food_dead(a1);
*(_DWORD *)(v1 + 28) = v2 - 1;
return kernel_register_wakeup(126LL, client_consume_food, a1);
}

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

v1 = *(_QWORD *)(a1 + 8);
if ( !v1 )
return func0(a1);
v2 = *(_DWORD *)(v1 + 28);
if ( v2 <= 0 )
return func0(a1);
*(_DWORD *)(v1 + 28) = v2 - 1;
return kernel_register_wakeup(126LL, client_consume_food, a1);
}

original_code:
void client_consume_food(t_client *client, int error)
{
  (void) error;
  if (client->player && client->player->inventory.food > 0)
    {
      client->player->inventory.food--;
      kernel_register_wakeup(126, (kn_wakeup_cb) &client_consume_food, client);
    }
  else
    client_food_dead(client);
}

canonical_original_code:
void client_consume_food(struct s_client *client, int error)
{
  (void) error;
  if (client->player && client->player->inventory.food > 0)
    {
      client->player->inventory.food--;
      kernel_register_wakeup(126, (kn_wakeup_cb) &client_consume_food, client);
    }
  else
    client_food_dead(client);
}

variable_types: error int

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

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


decompiled_code:
__int64 __fastcall kernel_retrieve_flag_index(int a1, __int64 a2, const char *a3)
{
__int64 v4; // rbx

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
v4 = 0LL;
while ( strcmp(*(const char **)(a2 + 8 * v4), a3) )
{
if ( ++v4 == a1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v4;
}

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

if ( a1 <= 0 )
return 0xFFFFFFFFLL;
v4 = 0LL;
while ( strcmp(*(const char **)(a2 + 8 * v4), a3) )
{
if ( ++v4 == a1 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v4;
}

original_code:
int kernel_retrieve_flag_index(int argc, char **argv, char *flag)
{
  int i;
  i = 0;
  while (i < argc)
    {
      if (strcmp(argv[i], flag) == 0)
 return i;
      i++;
    }
  return -1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
flag
char *


decompiled_code:
int __fastcall kernel_getopt_int(int a1, __int64 a2, const char *a3, int a4)
{
const char *v5; // rax
int result; // eax

v5 = kernel_getopt(a1, a2, a3, 0LL);
if ( v5 )
result = atoi(v5);
else
result = a4;
return result;
}

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

v5 = kernel_getopt(a1, a2, a3, 0LL);
if ( v5 )
result = atoi(v5);
else
result = a4;
return result;
}

original_code:
int kernel_getopt_int(int argc, char **argv, char *flag, int defaut)
{
  char *val;
  val = kernel_getopt(argc, argv, flag, ((void *)0));
  if (val)
    return atoi(val);
  return defaut;
}

variable_types: defaut int

variable_types:
val
char *


decompiled_code:
__int64 __fastcall client_connect(__int64 a1)
{
__int64 v1; // rbp

logger_message("[CLIENT] New client connected");
v1 = client_create(a1);
network_add_socket(a1, &client_receive, v1);
return client_send(v1, "BIENVENUE");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbp

logger_message("[CLIENT] New client connected");
v1 = client_create(a1);
network_add_socket(a1, &client_receive, v1);
return client_send(v1, "BIENVENUE");
}

original_code:
void client_connect(t_socket *new_sock)
{
  t_client *client;
  logger_message("[CLIENT] New client connected");
  client = client_create(new_sock);
  network_add_socket(new_sock, (t_nt_read_cb) &client_receive, client);
  client_send(client, "BIENVENUE");
}

canonical_original_code:
void client_connect(struct s_socket *new_sock)
{
  struct s_client *client;
  logger_message("[CLIENT] New client connected");
  client = client_create(new_sock);
  network_add_socket(new_sock, (t_nt_read_cb) &client_receive, client);
  client_send(client, "BIENVENUE");
}

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


decompiled_code:
__int64 __fastcall client_unconnect(_QWORD *a1)
{
kernel_unregister_wakeup();
network_close_socket_async(*a1);
*a1 = 0LL;
return client_destroy(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
kernel_unregister_wakeup();
network_close_socket_async(*a1);
*a1 = 0LL;
return client_destroy(a1);
}

original_code:
void client_unconnect(t_client *client)
{
  kernel_unregister_wakeup(client);
  network_close_socket_async(client->socket);
  client->socket = ((void *)0);
  client_destroy(client);
}

canonical_original_code:
void client_unconnect(struct s_client *client)
{
  kernel_unregister_wakeup(client);
  network_close_socket_async(client->socket);
  client->socket = ((void *)0);
  client_destroy(client);
}

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

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


decompiled_code:
__int64 __fastcall network_close_socket_async(unsigned int *a1)
{
__int64 result; // rax

if ( g_network )
{
logger_debug("[NETWORK] required to die : %d", *a1);
result = list_add_begin(*(_QWORD *)(g_network + 16LL), a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
__int64 result; // rax

if ( g_network )
{
logger_debug("[NETWORK] required to die : %d", *a1);
result = list_add_begin(*(_QWORD *)(g_network + 16LL), a1);
}
return result;
}

original_code:
void network_close_socket_async(t_socket *socket)
{
  if (!g_network)
    return;
  logger_debug("[NETWORK] required to die : %d", socket->fd);
  list_add_begin(g_network->destroy, socket);
}

canonical_original_code:
void network_close_socket_async(struct s_socket *socket)
{
  if (!g_network)
    return;
  logger_debug("[NETWORK] required to die : %d", socket->fd);
  list_add_begin(g_network->destroy, socket);
}


decompiled_code:
__int64 __fastcall kernel_add_team(const char *a1)
{
__int64 result; // rax
unsigned __int8 v2; // [rsp+Fh] [rbp-9h]

logger_message("[KERNEL] Add team %s", a1);
result = kernel_is_init(2LL);
if ( (_BYTE)result )
{
v2 = result;
game_create_team(a1);
result = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 result; // rax
unsigned __int8 v2; // [rsp+Fh] [rbp-9h]

logger_message("[KERNEL] Add team %s", a1);
result = kernel_is_init(2LL);
if ( (_BYTE)result )
{
v2 = result;
game_create_team(a1);
result = v2;
}
return result;
}

original_code:
_Bool kernel_add_team(char* team)
{
  logger_message("[KERNEL] Add team %s", team);
  if (kernel_is_init(0x2))
    {
      game_create_team(team);
      return 1;
    }
  return 0;
}

canonical_original_code:
_Bool kernel_add_team(char *team)
{
  logger_message("[KERNEL] Add team %s", team);
  if (kernel_is_init(0x2))
    {
      game_create_team(team);
      return 1;
    }
  return 0;
}

variable_types:
team
char *


decompiled_code:
__int64 __fastcall game_create_team(__int64 a1)
{
return team_create(a1, *(unsigned int *)(g_game + 64LL));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return team_create(a1, *(unsigned int *)(g_game + 64LL));
}

original_code:
void game_create_team(char *name)
{
  team_create(name, g_game->nb_slots);
}

variable_types:
name
char *


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

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

original_code:
void game_add_team(t_team *team)
{
  list_add_end(&g_game->teams, team);
}

canonical_original_code:
void game_add_team(struct s_team *team)
{
  list_add_end(&g_game->teams, team);
}

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


decompiled_code:
__int64 __fastcall game_get_team(__int64 a1)
{
return list_get_to_param(g_game + 16LL, game_team_name_cmp, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return list_get_to_param(g_game + 16LL, game_team_name_cmp, a1);
}

original_code:
t_team *game_get_team(char *name)
{
  return list_get_to_param(&g_game->teams, (fpredp) &_game_team_name_cmp, name);
}

canonical_original_code:
struct s_team *game_get_team(char *name)
{
  return list_get_to_param(&g_game->teams, (fpredp) &_game_team_name_cmp, name);
}

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


decompiled_code:
__int64 game_get_teams()
{
return g_game + 16LL;
}

canonical_decompiled_code:
__int64 func4()
{
return g_game + 16LL;
}

original_code:
t_list *game_get_teams()
{
  return &g_game->teams;
}

canonical_original_code:
struct s_list *game_get_teams()
{
  return &g_game->teams;
}

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


decompiled_code:
void __fastcall player_free(void *ptr)
{
logger_message("[GAME] Player %i is dead", *(unsigned int *)ptr);
team_remove_player(*((_QWORD *)ptr + 1), ptr);
world_remove_player(ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
logger_message("[GAME] Player %i is dead", *(unsigned int *)ptr);
team_remove_player(*((_QWORD *)ptr + 1), ptr);
world_remove_player(ptr);
free(ptr);
}

original_code:
void player_free(t_player *player)
{
  logger_message("[GAME] Player %i is dead", player->id);
  team_remove_player(player->team, player);
  world_remove_player(player);
  free(player);
}

canonical_original_code:
void player_free(struct s_player *player)
{
  logger_message("[GAME] Player %i is dead", player->id);
  team_remove_player(player->team, player);
  world_remove_player(player);
  free(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:
// attributes: thunk
int game_action_choose(void)
{
return rand();
}

canonical_decompiled_code:
int func0(void)
{
return rand();
}

original_code:
void game_action_choose(t_player *player)
{
  int random;
  random = rand() % 100;
  if (random < 50)
    game_action_move(player);
  else if (random < 75)
    game_action_left(player);
  else
    game_action_right(player);
}

canonical_original_code:
void game_action_choose(struct s_player *player)
{
  int random;
  random = rand() % 100;
  if (random < 50)
    game_action_move(player);
  else if (random < 75)
    game_action_left(player);
  else
    game_action_right(player);
}

variable_types: random int

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


decompiled_code:
void game_action_move()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void game_action_move(t_player *player)
{
  (void) player;
}

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


decompiled_code:
void game_action_left()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void game_action_left(t_player *player)
{
  (void) player;
}

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


decompiled_code:
void game_action_right()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
void game_action_right(t_player *player)
{
  (void) player;
}

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


decompiled_code:
__int64 __fastcall player_inventory_end_cb(__int64 a1, int a2)
{
unsigned int *v2; // rax

if ( a2 )
return client_send(a1, "ko");
v2 = *(unsigned int **)(a1 + 8);
return client_send(
a1,
"nourriture %d, linemate %d, deraumere %d, sibur %d, mendiane %d, phiras %d, thystame %d",
v2[7],
v2[8],
v2[9],
v2[10],
v2[11],
v2[12],
v2[13]);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
unsigned int *v2; // rax

if ( a2 )
return client_send(a1, "ko");
v2 = *(unsigned int **)(a1 + 8);
return client_send(
a1,
"nourriture %d, linemate %d, deraumere %d, sibur %d, mendiane %d, phiras %d, thystame %d",
v2[7],
v2[8],
v2[9],
v2[10],
v2[11],
v2[12],
v2[13]);
}

original_code:
void player_inventory_end_cb(t_client *client, int error)
{
  if (!error)
    {
      client_send(client, "nourriture %d, linemate %d, deraumere %d, sibur %d, mendiane %d, phiras %d, thystame %d",
     client->player->inventory.food,
     client->player->inventory.linemate,
     client->player->inventory.deraumere,
     client->player->inventory.sibur,
     client->player->inventory.mendiane,
     client->player->inventory.phiras,
     client->player->inventory.thystame);
    }
  else
    client_send(client, "ko");
}

canonical_original_code:
void player_inventory_end_cb(struct s_client *client, int error)
{
  if (!error)
    {
      client_send(client, "nourriture %d, linemate %d, deraumere %d, sibur %d, mendiane %d, phiras %d, thystame %d",
     client->player->inventory.food,
     client->player->inventory.linemate,
     client->player->inventory.deraumere,
     client->player->inventory.sibur,
     client->player->inventory.mendiane,
     client->player->inventory.phiras,
     client->player->inventory.thystame);
    }
  else
    client_send(client, "ko");
}


decompiled_code:
__int64 __fastcall player_inventory_start_cb(__int64 a1)
{
return kernel_register_wakeup(7LL, player_inventory_end_cb, a1);
}

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

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

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


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

if ( a2 )
return client_send(a1, &unk_13D);
client_send(a1, &unk_140);
result = *(_QWORD *)(a1 + 8);
++*(_DWORD *)(result + 56);
return result;
}

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

if ( a2 )
return client_send(a1, &unk_13D);
client_send(a1, &unk_140);
result = *(_QWORD *)(a1 + 8);
++*(_DWORD *)(result + 56);
return result;
}

original_code:
void player_incantation_end_cb(t_client *client, int error)
{
  if (error)
    client_send(client, "ko");
  else
    {
      client_send(client, "ok");
      client->player->level += 1;
    }
}

canonical_original_code:
void player_incantation_end_cb(struct s_client *client, int error)
{
  if (error)
    client_send(client, "ko");
  else
    {
      client_send(client, "ok");
      client->player->level += 1;
    }
}


decompiled_code:
char __fastcall player_incantation_start_cb(__int64 a1)
{
char result; // al

result = check_prerequisite_isra_0(*(_QWORD *)(a1 + 8), *(_DWORD **)(*(_QWORD *)(a1 + 8) + 16LL));
if ( result )
{
client_send(a1, "elevation en cours niveau actuel : %d", *(unsigned int *)(*(_QWORD *)(a1 + 8) + 56LL));
result = kernel_register_wakeup(300LL, player_incantation_end_cb, a1);
}
return result;
}

canonical_decompiled_code:
char __fastcall func4(__int64 a1)
{
char result; // al

result = func3(*(_QWORD *)(a1 + 8), *(_DWORD **)(*(_QWORD *)(a1 + 8) + 16LL));
if ( result )
{
client_send(a1, "elevation en cours niveau actuel : %d", *(unsigned int *)(*(_QWORD *)(a1 + 8) + 56LL));
result = kernel_register_wakeup(300LL, player_incantation_end_cb, a1);
}
return result;
}

original_code:
void player_incantation_start_cb(t_client *client, char *command)
{
  t_tile *tile;
  (void)command;
  tile = client->player->tile;
  if (_check_prerequisite(client, tile))
    {
      client_send(client, "elevation en cours niveau actuel : %d",
     client->player->level);
      kernel_register_wakeup(300, (kn_wakeup_cb) player_incantation_end_cb, client);
    }
}

canonical_original_code:
void player_incantation_start_cb(struct s_client *client, char *command)
{
  struct s_tile *tile;
  (void)command;
  tile = client->player->tile;
  if (_check_prerequisite(client, tile))
    {
      client_send(client, "elevation en cours niveau actuel : %d",
     client->player->level);
      kernel_register_wakeup(300, (void (*)(void *, int)) player_incantation_end_cb, client);
    }
}

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


decompiled_code:
__int64 __fastcall clm_retrieve_from_player(__int64 a1)
{
cmp = a1;
return list_get_to(g_client_manager, clm_cmp_player);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
cmp = a1;
return list_get_to(g_client_manager, clm_cmp_player);
}

original_code:
t_client *clm_retrieve_from_player(t_player* player)
{
  cmp = player;
  return list_get_to(&g_client_manager->clients, (fpred) &_clm_cmp_player);
}

canonical_original_code:
struct s_client *clm_retrieve_from_player(struct s_player *player)
{
  cmp = player;
  return list_get_to(&g_client_manager->clients, (fpred) &_clm_cmp_player);
}

variable_types:
player
struct s_player *


decompiled_code:
__int64 __fastcall clm_retrieve_from_socket(__int64 a1)
{
cmp = a1;
return list_get_to(g_client_manager, clm_cmp_socket);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
cmp = a1;
return list_get_to(g_client_manager, clm_cmp_socket);
}

original_code:
t_client *clm_retrieve_from_socket(t_socket* socket)
{
  cmp = socket;
  return list_get_to(&g_client_manager->clients, (fpred) &_clm_cmp_socket);
}

canonical_original_code:
struct s_client *clm_retrieve_from_socket(struct s_socket *socket)
{
  cmp = socket;
  return list_get_to(&g_client_manager->clients, (fpred) &_clm_cmp_socket);
}

variable_types:
socket
struct s_socket *


decompiled_code:
__int64 parser_is_match()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = parser_parse();
result = 0LL;
if ( v0 )
{
parser_command_destroy();
result = 1LL;
}
return result;
}

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

v0 = parser_parse();
result = 0LL;
if ( v0 )
{
parser_command_destroy();
result = 1LL;
}
return result;
}

original_code:
_Bool parser_is_match(char *data, char *mask)
{
  t_command *command;
  if ((command = parser_parse(data, mask)))
    {
      parser_command_destroy(command);
      return (1);
    }
  return (0);
}

canonical_original_code:
_Bool parser_is_match(char *data, char *mask)
{
  struct s_command *command;
  if ((command = parser_parse(data, mask)))
    {
      parser_command_destroy(command);
      return (1);
    }
  return (0);
}

variable_types:
data
char *

variable_types:
mask
char *

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:
char *__fastcall team_create(char *src, unsigned int a2)
{
char *v2; // r12

v2 = 0LL;
if ( a2 <= 0x32 )
{
v2 = (char *)calloc(1uLL, 0x48uLL);
if ( v2 )
{
logger_verbose("[GAME] Team '%s' create", src);
strncpy(v2, src, 0x20uLL);
*((_DWORD *)v2 + 16) = a2;
*((_DWORD *)v2 + 17) = a2;
game_add_team(v2);
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *src, unsigned int a2)
{
char *v2; // r12

v2 = 0LL;
if ( a2 <= 0x32 )
{
v2 = (char *)calloc(1uLL, 0x48uLL);
if ( v2 )
{
logger_verbose("[GAME] Team '%s' create", src);
strncpy(v2, src, 0x20uLL);
*((_DWORD *)v2 + 16) = a2;
*((_DWORD *)v2 + 17) = a2;
game_add_team(v2);
}
}
return v2;
}

original_code:
t_team *team_create(char *name, int slots)
{
  t_team *team;
  if (slots < 0 || slots > 50)
    return ((void *)0);
  if ((team = calloc(1, sizeof(t_team))) == ((void *)0))
    return (((void *)0));
  logger_verbose("[GAME] Team '%s' create", name);
  strncpy(team->name, name, 32);
  team->available_slots = slots;
  team->free_slots = slots;
  game_add_team(team);
  return (team);
}

canonical_original_code:
struct s_team *team_create(char *name, int slots)
{
  struct s_team *team;
  if (slots < 0 || slots > 50)
    return ((void *)0);
  if ((team = calloc(1, sizeof(t_team))) == ((void *)0))
    return (((void *)0));
  logger_verbose("[GAME] Team '%s' create", name);
  strncpy(team->name, name, 32);
  team->available_slots = slots;
  team->free_slots = slots;
  game_add_team(team);
  return (team);
}

variable_types: slots int


decompiled_code:
void __fastcall team_free(void *ptr)
{
char *v2; // rbx
__int64 v3; // rdi

v2 = (char *)ptr + 40;
while ( 1 )
{
v3 = list_get_begin(v2);
if ( !v3 )
break;
player_free(v3);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
char *v2; // rbx
__int64 v3; // rdi

v2 = (char *)ptr + 40;
while ( 1 )
{
v3 = list_get_begin(v2);
if ( !v3 )
break;
player_free(v3);
}
free(ptr);
}

original_code:
void team_free(t_team *team)
{
  t_player *player;
  while ((player = list_get_begin(&team->players)))
    player_free(player);
  free(team);
}

canonical_original_code:
void team_free(struct s_team *team)
{
  struct s_player *player;
  while ((player = list_get_begin(&team->players)))
    player_free(player);
  free(team);
}