decompiled_code:
__int64 __fastcall exec_cmd(__int64 a1, unsigned int a2, const char *a3)
{
__int64 result; // rax

result = a1;
if ( !strcmp(a3, "Avance\n") )
return avance(a1 + 6160, a2);
if ( !strcmp(a3, "Droite\n") )
return droite(a1 + 6160, a2);
if ( !strcmp(a3, "Gauche\n") )
return gauche(a1 + 6160, a2);
if ( !strcmp(a3, "Tir\n") )
result = tir(a1 + 6160, a2);
return result;
}

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

result = a1;
if ( !strcmp(a3, "Avance\n") )
return avance(a1 + 6160, a2);
if ( !strcmp(a3, "Droite\n") )
return droite(a1 + 6160, a2);
if ( !strcmp(a3, "Gauche\n") )
return gauche(a1 + 6160, a2);
if ( !strcmp(a3, "Tir\n") )
result = tir(a1 + 6160, a2);
return result;
}

original_code:
void exec_cmd(t_serv *serv, int fd, char *buff)
{
  if (strcmp(buff, "Avance\n") == 0)
    avance(&(serv->next), fd);
  else if (strcmp(buff, "Droite\n") == 0)
    droite(&(serv->next), fd);
  else if (strcmp(buff, "Gauche\n") == 0)
    gauche(&(serv->next), fd);
  else if (strcmp(buff, "Tir\n") == 0)
    tir(&(serv->next), fd);
}

canonical_original_code:
void exec_cmd(struct s_serv *serv, int fd, char *buff)
{
  if (strcmp(buff, "Avance\n") == 0)
    avance(&(serv->next), fd);
  else if (strcmp(buff, "Droite\n") == 0)
    droite(&(serv->next), fd);
  else if (strcmp(buff, "Gauche\n") == 0)
    gauche(&(serv->next), fd);
  else if (strcmp(buff, "Tir\n") == 0)
    tir(&(serv->next), fd);
}

variable_types:
buff
char *


repo: FlorianHe/spacewar

decompiled_code:
void __fastcall client_read(__int64 a1, unsigned int a2)
{
int v2; // er13
void *ptr; // [rsp+0h] [rbp-38h] BYREF
__int16 buf[21]; // [rsp+Eh] [rbp-2Ah] BYREF

asprintf((char **)&ptr, &fmt);
while ( strcmp((const char *)buf, "\n") )
{
buf[0] = 0;
v2 = read(a2, buf, 1uLL);
if ( v2 <= 0 )
{
connection_close(a1, a2);
buf[0] = 10;
}
asprintf((char **)&ptr, "%s%s", (const char *)ptr, (const char *)buf);
}
if ( v2 > 0 )
exec_cmd(a1, a2, (const char *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, unsigned int a2)
{
int v2; // er13
void *ptr; // [rsp+0h] [rbp-38h] BYREF
__int16 buf[21]; // [rsp+Eh] [rbp-2Ah] BYREF

asprintf((char **)&ptr, &fmt);
while ( strcmp((const char *)buf, "\n") )
{
buf[0] = 0;
v2 = read(a2, buf, 1uLL);
if ( v2 <= 0 )
{
func0(a1, a2);
buf[0] = 10;
}
asprintf((char **)&ptr, "%s%s", (const char *)ptr, (const char *)buf);
}
if ( v2 > 0 )
func1(a1, a2, (const char *)ptr);
free(ptr);
}

original_code:
void client_read(t_serv *e, int fd)
{
  int r;
  char tmp[2];
  char *buff;
  asprintf(&buff, "");
  while (strcmp(tmp, "\n") != 0)
    {
      memset(tmp, '\0', 2);
      r = read(fd, tmp, 1);
      if (r <= 0)
 {
   connection_close(e, fd);
   sprintf(tmp, "\n");
 }
      asprintf(&buff, "%s%s", buff, tmp);
    }
  if (r > 0)
    exec_cmd(e, fd, buff);
  free(buff);
}

canonical_original_code:
void client_read(struct s_serv *e, int fd)
{
  int r;
  char tmp[2];
  char *buff;
  asprintf(&buff, "");
  while (strcmp(tmp, "\n") != 0)
    {
      memset(tmp, '\0', 2);
      r = read(fd, tmp, 1);
      if (r <= 0)
 {
   connection_close(e, fd);
   sprintf(tmp, "\n");
 }
      asprintf(&buff, "%s%s", buff, tmp);
    }
  if (r > 0)
    exec_cmd(e, fd, buff);
  free(buff);
}

variable_types: struct s_serv { int player; int game; int port; int id_player; int fd_type[512]; void (*fct_read[512])(); struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } *next; } *

variable_types: fd int

variable_types: r int

variable_types:
tmp
char [2]

return_type: void

user_defined_types: struct s_serv { int player; int game; int port; int id_player; int fd_type[512]; void (*fct_read[512])(); struct s_player *next; }

user_defined_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile *missile; struct s_player *next; }


deletemissile

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

result = graph_tir_suppr(a1, a3);
*(_DWORD *)(a3 + 12) = 0;
--*(_DWORD *)(a2 + 28);
return result;
}

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

result = graph_tir_suppr(a1, a3);
*(_DWORD *)(a3 + 12) = 0;
--*(_DWORD *)(a2 + 28);
return result;
}

original_code:
void deletemissile(t_player **l, t_player *pl, t_missile *tir)
{
  graph_tir_suppr(l, tir);
  tir->nb_tir = 0;
  pl->nb_missile--;
}

canonical_original_code:
void deletemissile(struct s_player **l, struct s_player *pl, struct s_missile *tir)
{
  graph_tir_suppr(l, tir);
  tir->nb_tir = 0;
  pl->nb_missile--;
}

variable_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } **

variable_types:
pl
struct s_player *

variable_types:
tir
struct s_missile *


original_code:
void collide_vaisseau(t_player **list, t_missile *tir)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if ((tir->x >= tmp->X - 20 && tir->x <= tmp->X + 20)
   && (tir->y >= tmp->Y - 20 && tir->y <= tmp->Y + 20))
 is_dead(list, tmp);
      tmp = tmp->next;
    }
}

canonical_original_code:
void collide_vaisseau(struct s_player **list, struct s_missile *tir)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if ((tir->x >= tmp->X - 20 && tir->x <= tmp->X + 20)
   && (tir->y >= tmp->Y - 20 && tir->y <= tmp->Y + 20))
 is_dead(list, tmp);
      tmp = tmp->next;
    }
}

variable_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } *


decompiled_code:
__int64 __fastcall collide_tir(__int64 *a1, __int64 a2, _DWORD *a3)
{
unsigned int v4; // edx
__int64 result; // rax

collide_vaisseau(a1, a3);
if ( *a3 > 0x320u )
return deletemissile((__int64)a1, a2, (__int64)a3);
v4 = a3[1];
if ( v4 > 0x320 )
return deletemissile((__int64)a1, a2, (__int64)a3);
result = (unsigned int)(*a3 - 385);
if ( (unsigned int)result <= 0x1E || v4 - 385 <= 0x1E )
result = deletemissile((__int64)a1, a2, (__int64)a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 a2, _DWORD *a3)
{
unsigned int v4; // edx
__int64 result; // rax

func1(a1, a3);
if ( *a3 > 0x320u )
return func0((__int64)a1, a2, (__int64)a3);
v4 = a3[1];
if ( v4 > 0x320 )
return func0((__int64)a1, a2, (__int64)a3);
result = (unsigned int)(*a3 - 385);
if ( (unsigned int)result <= 0x1E || v4 - 385 <= 0x1E )
result = func0((__int64)a1, a2, (__int64)a3);
return result;
}

original_code:
void collide_tir(t_player **list, t_player *pl, t_missile *tir)
{
  collide_vaisseau(list, tir);
  if (tir->x < 0 || tir->x > 800 || tir->y < 0 || tir->y > 800)
    deletemissile(list, pl, tir);
  else if (tir->x >= 385 && tir->x <= 415)
    deletemissile(list, pl, tir);
  else if (tir->y >= 385 && tir->y <= 415)
    deletemissile(list, pl, tir);
}

canonical_original_code:
void collide_tir(struct s_player **list, struct s_player *pl, struct s_missile *tir)
{
  collide_vaisseau(list, tir);
  if (tir->x < 0 || tir->x > 800 || tir->y < 0 || tir->y > 800)
    deletemissile(list, pl, tir);
  else if (tir->x >= 385 && tir->x <= 415)
    deletemissile(list, pl, tir);
  else if (tir->y >= 385 && tir->y <= 415)
    deletemissile(list, pl, tir);
}

user_defined_types: struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; }


original_code:
void move_tir(t_player **list, t_player *pl)
{
  static int i = 0;
  int j;
  t_missile *tmp2;
  tmp2 = pl->missile;
  while (tmp2 != ((void *)0))
    {
      j = 0;
      while (j < 8 && tmp2->rotation != tab_value_tir[j].rotation_)
 j++;
      if (j != 8 && tmp2->time >= 3500 && tmp2->nb_tir != 0)
 {
   tab_value_tir[j].funct(tmp2, 1);
   gravite_tir(list, tmp2);
   collide_tir(list, pl, tmp2);
   graph_tir(list, tmp2);
   tmp2->time = 0;
 }
      else
 tmp2->time++;
      tmp2 = tmp2->next;
    }
}

canonical_original_code:
void move_tir(struct s_player **list, struct s_player *pl)
{
  static int i = 0;
  int j;
  struct s_missile *tmp2;
  tmp2 = pl->missile;
  while (tmp2 != ((void *)0))
    {
      j = 0;
      while (j < 8 && tmp2->rotation != tab_value_tir[j].rotation_)
 j++;
      if (j != 8 && tmp2->time >= 3500 && tmp2->nb_tir != 0)
 {
   tab_value_tir[j].funct(tmp2, 1);
   gravite_tir(list, tmp2);
   collide_tir(list, pl, tmp2);
   graph_tir(list, tmp2);
   tmp2->time = 0;
 }
      else
 tmp2->time++;
      tmp2 = tmp2->next;
    }
}

variable_types: i int

variable_types: j int

variable_types: struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *


decompiled_code:
__int64 __fastcall pop_tir(__int64 a1)
{
_DWORD *v1; // rdx
__int64 result; // rax

v1 = &tab_value_tir;
LODWORD(result) = 0;
while ( *(_DWORD *)(a1 + 8) != *v1 )
{
result = (unsigned int)(result + 1);
v1 += 4;
if ( (_DWORD)result == 8 )
return result;
}
return ((__int64 (__fastcall *)(__int64, __int64))*(&off_108 + 2 * (int)result))(a1, 30LL);
}

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

v1 = &tab_value_tir;
LODWORD(result) = 0;
while ( *(_DWORD *)(a1 + 8) != *v1 )
{
result = (unsigned int)(result + 1);
v1 += 4;
if ( (_DWORD)result == 8 )
return result;
}
return ((__int64 (__fastcall *)(__int64, __int64))*(&off_108 + 2 * (int)result))(a1, 30LL);
}

original_code:
void pop_tir(t_missile *tir)
{
  int j;
  j = 0;
  while (j < 8 && tir->rotation != tab_value_tir[j].rotation_)
    j++;
  if (j != 8)
    tab_value_tir[j].funct(tir, 30);
}

canonical_original_code:
void pop_tir(struct s_missile *tir)
{
  int j;
  j = 0;
  while (j < 8 && tir->rotation != tab_value_tir[j].rotation_)
    j++;
  if (j != 8)
    tab_value_tir[j].funct(tir, 30);
}


setType

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

for ( result = 0LL; result != 512; ++result )
{
if ( *(_DWORD *)(a1 + 4 * result + 16) )
*(_QWORD *)(a2 + 8LL * ((int)result / 64)) |= 1LL << ((int)result % 64);
}
return result;
}

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

for ( result = 0LL; result != 512; ++result )
{
if ( *(_DWORD *)(a1 + 4 * result + 16) )
*(_QWORD *)(a2 + 8LL * ((int)result / 64)) |= 1LL << ((int)result % 64);
}
return result;
}

original_code:
int setType(t_serv *e, fd_set *fd_read)
{
  int i;
  int fd_max;
  i = 0;
  fd_max = 0;
  while (i < 512)
    {
      if (e->fd_type[i] != 0)
        {
          ((void) (((fd_read)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
          fd_max = i;
        }
      i++;
    }
  return (i);
}

canonical_original_code:
int setType(struct s_serv *e, struct fd_set *fd_read)
{
  int i;
  int fd_max;
  i = 0;
  fd_max = 0;
  while (i < 512)
    {
      if (e->fd_type[i] != 0)
        {
          ((void) (((fd_read)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
          fd_max = i;
        }
      i++;
    }
  return (i);
}

variable_types: struct fd_set { long __fds_bits[-1]; } *

return_type: int


Zero

decompiled_code:
void __fastcall Zero(__int64 a1)
{
--*(_DWORD *)(a1 + 4);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
--*(_DWORD *)(a1 + 4);
}

original_code:
void Zero(t_player *player)
{
  player->Y = player->Y - 1;
}

canonical_original_code:
void Zero(struct s_player *player)
{
  player->Y = player->Y - 1;
}


decompiled_code:
void __fastcall Hundred_eighty(__int64 a1)
{
++*(_DWORD *)(a1 + 4);
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
++*(_DWORD *)(a1 + 4);
}

original_code:
void Hundred_eighty(t_player *player)
{
  player->Y = player->Y + 1;
}

canonical_original_code:
void Hundred_eighty(struct s_player *player)
{
  player->Y = player->Y + 1;
}


original_code:
void tir2(t_player **list, t_player *player)
{
  static int i = 1;
  t_missile *missile;
  missile = xmalloc(sizeof(t_missile));
  missile->rotation = player->rotation;
  missile->x = player->X;
  missile->y = player->Y;
  pop_tir(missile);
  missile->nb_tir = i++;
  graph_tir(list, missile);
  addmissile(&(player->missile), missile);
}

canonical_original_code:
void tir2(struct s_player **list, struct s_player *player)
{
  static int i = 1;
  struct s_missile *missile;
  missile = xmalloc(sizeof(t_missile));
  missile->rotation = player->rotation;
  missile->x = player->X;
  missile->y = player->Y;
  pop_tir(missile);
  missile->nb_tir = i++;
  graph_tir(list, missile);
  addmissile(&(player->missile), missile);
}

variable_types:
player
struct s_player *


tir

original_code:
void *tir(t_player **list, int num_player)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   if (tmp->nb_missile < 5)
     {
       tir2(list, tmp);
       tmp->nb_missile++;
     }
   return (((void *)0));
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void *tir(struct s_player **list, int num_player)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   if (tmp->nb_missile < 5)
     {
       tir2(list, tmp);
       tmp->nb_missile++;
     }
   return (((void *)0));
 }
      tmp = tmp->next;
    }
}

return_type: void *


serveur

decompiled_code:
__int64 __fastcall serveur(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = (unsigned int)xsocket();
xbind(v1, a1);
result = xlisten((unsigned int)v1);
*(_DWORD *)(a1 + 4LL * (int)v1 + 16) = 1;
*(_QWORD *)(a1 + 8LL * (int)v1 + 2064) = &serveur_read;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

v1 = (unsigned int)xsocket();
xbind(v1, a1);
result = xlisten((unsigned int)v1);
*(_DWORD *)(a1 + 4LL * (int)v1 + 16) = 1;
*(_QWORD *)(a1 + 8LL * (int)v1 + 2064) = &serveur_read;
return result;
}

original_code:
int serveur(t_serv *e)
{
  int fd;
  fd = xsocket();
  xbind(fd, e);
  xlisten(fd);
  e->fd_type[fd] = 1;
  e->fct_read[fd] = serveur_read;
}

canonical_original_code:
int serveur(struct s_serv *e)
{
  int fd;
  fd = xsocket();
  xbind(fd, e);
  xlisten(fd);
  e->fd_type[fd] = 1;
  e->fct_read[fd] = serveur_read;
}


droite

original_code:
void droite(t_player **list, int num_player)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   tmp->rotation = tmp->rotation + 45;
   if (tmp->rotation >= 360)
     tmp->rotation = 0;
   graph_droite(list, tmp);
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void droite(struct s_player **list, int num_player)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   tmp->rotation = tmp->rotation + 45;
   if (tmp->rotation >= 360)
     tmp->rotation = 0;
   graph_droite(list, tmp);
 }
      tmp = tmp->next;
    }
}


original_code:
void check_value(t_player *player)
{
  if (player->X > 0)
    player->X = player->X % 800;
  else if (player->X < 0)
    player->X = 800 + player->X;
  if (player->Y > 0)
    player->Y = player->Y % 800;
  else if (player->Y < 0)
    player->Y = 800 + player->Y;
}

canonical_original_code:
void check_value(struct s_player *player)
{
  if (player->X > 0)
    player->X = player->X % 800;
  else if (player->X < 0)
    player->X = 800 + player->X;
  if (player->Y > 0)
    player->Y = player->Y % 800;
  else if (player->Y < 0)
    player->Y = 800 + player->Y;
}


decompiled_code:
__int64 __fastcall check_rotation(__int64 a1)
{
_DWORD *v1; // rdx
__int64 result; // rax

v1 = &tab_value_;
LODWORD(result) = 0;
while ( *(_DWORD *)(a1 + 16) != *v1 )
{
result = (unsigned int)(result + 1);
v1 += 4;
if ( (_DWORD)result == 8 )
return result;
}
return ((__int64 (*)(void))*(&off_188 + 2 * (int)result))();
}

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

v1 = &tab_value_;
LODWORD(result) = 0;
while ( *(_DWORD *)(a1 + 16) != *v1 )
{
result = (unsigned int)(result + 1);
v1 += 4;
if ( (_DWORD)result == 8 )
return result;
}
return ((__int64 (*)(void))*(&off_188 + 2 * (int)result))();
}

original_code:
void check_rotation(t_player *player)
{
  int j;
  j = 0;
  while (j < 8 && player->rotation != tab_value_[j].rotation_)
    j++;
  if (j != 8)
    tab_value_[j].funct(player);
}

canonical_original_code:
void check_rotation(struct s_player *player)
{
  int j;
  j = 0;
  while (j < 8 && player->rotation != tab_value_[j].rotation_)
    j++;
  if (j != 8)
    tab_value_[j].funct(player);
}


avance

decompiled_code:
__int64 __fastcall avance(__int64 *a1, int a2)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
if ( *(_DWORD *)(i + 24) == a2 && *(int *)(i + 12) > 0 )
{
check_value((int *)i);
check_rotation(i);
check_value((int *)i);
--*(_DWORD *)(i + 12);
graph_avance(a1, i);
result = graph_essence(a1, i);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, int a2)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
if ( *(_DWORD *)(i + 24) == a2 && *(int *)(i + 12) > 0 )
{
func0((int *)i);
func1(i);
func0((int *)i);
--*(_DWORD *)(i + 12);
graph_avance(a1, i);
result = graph_essence(a1, i);
}
}
return result;
}

original_code:
void avance(t_player **list, int num_player)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player && tmp->essence > 0)
       {
   check_value(tmp);
   check_rotation(tmp);
   check_value(tmp);
   tmp->essence--;
   graph_avance(list, tmp);
   graph_essence(list, tmp);
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void avance(struct s_player **list, int num_player)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player && tmp->essence > 0)
       {
   check_value(tmp);
   check_rotation(tmp);
   check_value(tmp);
   tmp->essence--;
   graph_avance(list, tmp);
   graph_essence(list, tmp);
 }
      tmp = tmp->next;
    }
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(int a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
exit(1);
return result;
}

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

result = malloc(a1);
if ( !result )
exit(1);
return result;
}

original_code:
void *xmalloc(int size)
{
  void *ptr;
  ptr = malloc(size);
  if (ptr == ((void *)0))
    exit(1);
  else
    return (ptr);
}

variable_types: size int

variable_types:
ptr
void *


deletenode

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

for ( result = *a1; result; result = *(_QWORD *)(result + 40) )
{
if ( *(_DWORD *)(result + 24) == a2 )
*(_DWORD *)(result + 24) = 0;
}
return result;
}

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

for ( result = *a1; result; result = *(_QWORD *)(result + 40) )
{
if ( *(_DWORD *)(result + 24) == a2 )
*(_DWORD *)(result + 24) = 0;
}
return result;
}

original_code:
void deletenode(t_player **list, int fd_pl)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == fd_pl)
 tmp->player_fd = 0;
      tmp = tmp->next;
    }
}

canonical_original_code:
void deletenode(struct s_player **list, int fd_pl)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == fd_pl)
 tmp->player_fd = 0;
      tmp = tmp->next;
    }
}


run

decompiled_code:
__int64 __fastcall run(__int64 a1)
{
int v1; // eax
__int64 i; // rbx
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-A8h] BYREF

v4.tv_sec = 0LL;
v4.tv_usec = 100000LL;
memset(&readfds, 0, sizeof(readfds));
v1 = setType(a1, &readfds);
if ( select(v1 + 1, &readfds, 0LL, 0LL, &v4) == -1 )
perror("select");
for ( i = 0LL; i != 512; ++i )
{
if ( (readfds.fds_bits[(int)i / 64] & (1LL << ((int)i % 64))) != 0 )
(*(void (__fastcall **)(__int64, _QWORD))(a1 + 8 * i + 2064))(a1, (unsigned int)i);
gravite(a1 + 6160);
result = mort(a1 + 6160, a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // eax
__int64 i; // rbx
__int64 result; // rax
struct timeval v4; // [rsp+0h] [rbp-B8h] BYREF
fd_set readfds; // [rsp+10h] [rbp-A8h] BYREF

v4.tv_sec = 0LL;
v4.tv_usec = 100000LL;
memset(&readfds, 0, sizeof(readfds));
v1 = setType(a1, &readfds);
if ( select(v1 + 1, &readfds, 0LL, 0LL, &v4) == -1 )
perror("select");
for ( i = 0LL; i != 512; ++i )
{
if ( (readfds.fds_bits[(int)i / 64] & (1LL << ((int)i % 64))) != 0 )
(*(void (__fastcall **)(__int64, _QWORD))(a1 + 8 * i + 2064))(a1, (unsigned int)i);
gravite(a1 + 6160);
result = mort(a1 + 6160, a1);
}
return result;
}

original_code:
void run(t_serv *e)
{
  int i;
  int fd_max;
  fd_set fd_read;
  struct timeval tv;
  i = 0;
  tv.tv_sec = 0;
  tv.tv_usec = 100000;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_read)->__fds_bits)[0]) : "memory"); } while (0);
  fd_max = setType(e, &fd_read);
  if (select(fd_max + 1, &fd_read, ((void *)0), ((void *)0), &tv) == -1)
    perror("select");
  while (i < 512)
    {
      if (((((&fd_read)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        e->fct_read[i](e, i);
      gravite(&(e->next));
      mort(&(e->next), e);
      i++;
    }
}

canonical_original_code:
void run(struct s_serv *e)
{
  int i;
  int fd_max;
  struct fd_set fd_read;
  struct timeval tv;
  i = 0;
  tv.tv_sec = 0;
  tv.tv_usec = 100000;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fd_read)->__fds_bits)[0]) : "memory"); } while (0);
  fd_max = setType(e, &fd_read);
  if (select(fd_max + 1, &fd_read, ((void *)0), ((void *)0), &tv) == -1)
    perror("select");
  while (i < 512)
    {
      if (((((&fd_read)->__fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        e->fct_read[i](e, i);
      gravite(&(e->next));
      mort(&(e->next), e);
      i++;
    }
}

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


decompiled_code:
int __fastcall graph_avance(__int64 *a1, unsigned int *a2)
{
__int64 v2; // rbx
int result; // eax
size_t v4; // rax
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-108h] BYREF
int v7; // [rsp+F8h] [rbp-10h]
__int16 v8; // [rsp+FCh] [rbp-Ch]

v2 = *a1;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
for ( result = sprintf(v6, "Ava %d %d %d\n", a2[5], *a2, a2[1]); v2; v2 = *(_QWORD *)(v2 + 40) )
{
if ( *(_DWORD *)(v2 + 24) )
{
v4 = strlen(v6);
write(1, v6, v4);
v5 = strlen(v6);
result = write(*(_DWORD *)(v2 + 24), v6, v5);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, unsigned int *a2)
{
__int64 v2; // rbx
int result; // eax
size_t v4; // rax
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-108h] BYREF
int v7; // [rsp+F8h] [rbp-10h]
__int16 v8; // [rsp+FCh] [rbp-Ch]

v2 = *a1;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
for ( result = sprintf(v6, "Ava %d %d %d\n", a2[5], *a2, a2[1]); v2; v2 = *(_QWORD *)(v2 + 40) )
{
if ( *(_DWORD *)(v2 + 24) )
{
v4 = strlen(v6);
write(1, v6, v4);
v5 = strlen(v6);
result = write(*(_DWORD *)(v2 + 24), v6, v5);
}
}
return result;
}

original_code:
void graph_avance(t_player **list, t_player *perso)
{
  t_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Ava %d %d %d\n", perso->player_id, perso->X, perso->Y);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void graph_avance(struct s_player **list, struct s_player *perso)
{
  struct s_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Ava %d %d %d\n", perso->player_id, perso->X, perso->Y);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

variable_types:
perso
struct s_player *

variable_types:
buff
char [254]


gravite

decompiled_code:
__int64 __fastcall gravite(__int64 *a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
if ( *(_DWORD *)(i + 24) )
{
applique_gravite(a1, i);
result = move_tir(a1, i);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
if ( *(_DWORD *)(i + 24) )
{
applique_gravite(a1, i);
result = move_tir(a1, i);
}
}
return result;
}

original_code:
void gravite(t_player **list)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   applique_gravite(list, tmp);
   move_tir(list, tmp);
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void gravite(struct s_player **list)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   applique_gravite(list, tmp);
   move_tir(list, tmp);
 }
      tmp = tmp->next;
    }
}


error

decompiled_code:
void __fastcall __noreturn error(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
write(2, buf, v1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *buf)
{
size_t v1; // rax

v1 = strlen((const char *)buf);
write(2, buf, v1);
exit(0);
}

original_code:
void error(char *buff)
{
  write(2, buff, strlen(buff));
  exit(0);
}

variable_types:
buff
char *


xsocket

decompiled_code:
__int64 xsocket()
{
struct protoent *v0; // rax
const char *v1; // rdx
unsigned int v2; // ebx

v0 = getprotobyname("TCP");
if ( !v0 )
exit(1);
v2 = socket(2, 1, v0->p_proto);
if ( v2 == -1 )
error((int)"SOCKET ERROR\n", 1, v1);
write(1, "SOCKET SUCCESS\n", 0xFuLL);
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
struct protoent *v0; // rax
const char *v1; // rdx
unsigned int v2; // ebx

v0 = getprotobyname("TCP");
if ( !v0 )
exit(1);
v2 = socket(2, 1, v0->p_proto);
if ( v2 == -1 )
error((int)"SOCKET ERROR\n", 1, v1);
write(1, "SOCKET SUCCESS\n", 0xFuLL);
return v2;
}

original_code:
int xsocket()
{
  int fd;
  struct protoent *pe;
  pe = getprotobyname("TCP");
  if (!pe)
    exit(1);
  if ((fd = socket(2, SOCK_STREAM, pe->p_proto)) == -1)
    error("SOCKET ERROR\n");
  write(1, "SOCKET SUCCESS\n", 15);
  return (fd);
}

variable_types: fd int

variable_types: struct protoent { char *p_name; char **p_aliases; int p_proto; } *


checking

original_code:
void checking(t_serv *e, int ac, char *av[])
{
  int i;
  i = 1;
  while (i != ac)
    {
      if (strcmp(av[i], "-n") == 0 && e->player == 2 && i + 1 < ac)
        e->player = atoi(av[i + 1]);
      else if (strcmp(av[i], "-g") == 0 && e->game == 5 && i + 1 < ac)
        e->game = atoi(av[i + 1]);
      else if (strcmp(av[i], "-p") == 0 && e->port == 4242 && i + 1 < ac)
        e->port = atoi(av[i + 1]);
      else
        error("Usage: ./Spacewar [-n player_number -g game_number -p port]\n");
      i = i + 2;
    }
}

canonical_original_code:
void checking(struct s_serv *e, int ac, char *av[])
{
  int i;
  i = 1;
  while (i != ac)
    {
      if (strcmp(av[i], "-n") == 0 && e->player == 2 && i + 1 < ac)
        e->player = atoi(av[i + 1]);
      else if (strcmp(av[i], "-g") == 0 && e->game == 5 && i + 1 < ac)
        e->game = atoi(av[i + 1]);
      else if (strcmp(av[i], "-p") == 0 && e->port == 4242 && i + 1 < ac)
        e->port = atoi(av[i + 1]);
      else
        error("Usage: ./Spacewar [-n player_number -g game_number -p port]\n");
      i = i + 2;
    }
}

variable_types: struct s_serv { int player; int game; int port; int id_player; int fd_type[512]; void (*fct_read[512])(); struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } *next; } *

variable_types: ac int

variable_types:
av
char *[]


decompiled_code:
int __fastcall graph_gauche(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax
size_t v4; // rax
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-108h] BYREF
int v7; // [rsp+F8h] [rbp-10h]
__int16 v8; // [rsp+FCh] [rbp-Ch]

v2 = *a1;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
for ( result = sprintf(v6, "Gau %d %d\n", *(unsigned int *)(a2 + 20), *(unsigned int *)(a2 + 16));
v2;
v2 = *(_QWORD *)(v2 + 40) )
{
if ( *(_DWORD *)(v2 + 24) )
{
v4 = strlen(v6);
write(1, v6, v4);
v5 = strlen(v6);
result = write(*(_DWORD *)(v2 + 24), v6, v5);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax
size_t v4; // rax
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-108h] BYREF
int v7; // [rsp+F8h] [rbp-10h]
__int16 v8; // [rsp+FCh] [rbp-Ch]

v2 = *a1;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
for ( result = sprintf(v6, "Gau %d %d\n", *(unsigned int *)(a2 + 20), *(unsigned int *)(a2 + 16));
v2;
v2 = *(_QWORD *)(v2 + 40) )
{
if ( *(_DWORD *)(v2 + 24) )
{
v4 = strlen(v6);
write(1, v6, v4);
v5 = strlen(v6);
result = write(*(_DWORD *)(v2 + 24), v6, v5);
}
}
return result;
}

original_code:
void graph_gauche(t_player **list, t_player *perso)
{
  t_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Gau %d %d\n", perso->player_id, perso->rotation);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void graph_gauche(struct s_player **list, struct s_player *perso)
{
  struct s_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Gau %d %d\n", perso->player_id, perso->rotation);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

variable_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } **


decompiled_code:
void __fastcall Zero_tir(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) -= a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) -= a2;
}

original_code:
void Zero_tir(t_missile *tir, int i)
{
  tir->y = tir->y - i;
}

canonical_original_code:
void Zero_tir(struct s_missile *tir, int i)
{
  tir->y = tir->y - i;
}

variable_types: i int


decompiled_code:
void __fastcall Hundred_eighty_tir(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) += a2;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) += a2;
}

original_code:
void Hundred_eighty_tir(t_missile *tir, int i)
{
  tir->y = tir->y + i;
}

canonical_original_code:
void Hundred_eighty_tir(struct s_missile *tir, int i)
{
  tir->y = tir->y + i;
}


decompiled_code:
int __fastcall graph_essence(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax
size_t v4; // rax
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-108h] BYREF
int v7; // [rsp+F8h] [rbp-10h]
__int16 v8; // [rsp+FCh] [rbp-Ch]

v2 = *a1;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
for ( result = sprintf(v6, "Ess %d %d\n", *(unsigned int *)(a2 + 20), *(unsigned int *)(a2 + 12));
v2;
v2 = *(_QWORD *)(v2 + 40) )
{
if ( *(_DWORD *)(v2 + 24) )
{
v4 = strlen(v6);
write(1, v6, v4);
v5 = strlen(v6);
result = write(*(_DWORD *)(v2 + 24), v6, v5);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax
size_t v4; // rax
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-108h] BYREF
int v7; // [rsp+F8h] [rbp-10h]
__int16 v8; // [rsp+FCh] [rbp-Ch]

v2 = *a1;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
for ( result = sprintf(v6, "Ess %d %d\n", *(unsigned int *)(a2 + 20), *(unsigned int *)(a2 + 12));
v2;
v2 = *(_QWORD *)(v2 + 40) )
{
if ( *(_DWORD *)(v2 + 24) )
{
v4 = strlen(v6);
write(1, v6, v4);
v5 = strlen(v6);
result = write(*(_DWORD *)(v2 + 24), v6, v5);
}
}
return result;
}

original_code:
void graph_essence(t_player **list, t_player *perso)
{
  t_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Ess %d %d\n", perso->player_id, perso->essence);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void graph_essence(struct s_player **list, struct s_player *perso)
{
  struct s_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Ess %d %d\n", perso->player_id, perso->essence);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 {
   write(1, buff, strlen(buff));
   write(tmp->player_fd, buff, strlen(buff));
 }
      tmp = tmp->next;
    }
}

variable_types: struct s_player { int X; int Y; int time; int essence; int rotation; int player_id; int player_fd; int nb_missile; struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *missile; struct s_player *next; } *


gauche

original_code:
void gauche(t_player **list, int num_player)
{
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   tmp->rotation = tmp->rotation - 45;
   if (tmp->rotation < 0)
     tmp->rotation = 315;
   graph_gauche(list, tmp);
 }
      tmp = tmp->next;
    }
}

canonical_original_code:
void gauche(struct s_player **list, int num_player)
{
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == num_player)
 {
   tmp->rotation = tmp->rotation - 45;
   if (tmp->rotation < 0)
     tmp->rotation = 315;
   graph_gauche(list, tmp);
 }
      tmp = tmp->next;
    }
}


decompiled_code:
int __fastcall graph_mort(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
int v4; // ebp
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-118h] BYREF
int v7; // [rsp+F8h] [rbp-20h]
__int16 v8; // [rsp+FCh] [rbp-1Ch]

v2 = *a1;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
sprintf(v6, "Mor %d\n", *(unsigned int *)(a2 + 20));
for ( ; v2; v2 = *(_QWORD *)(v2 + 40) )
{
v4 = *(_DWORD *)(v2 + 24);
if ( v4 )
{
v5 = strlen(v6);
write(v4, v6, v5);
}
}
return printf("Le joueur %d est mort\n", *(unsigned int *)(a2 + 20));
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
int v4; // ebp
size_t v5; // rax
char v6[248]; // [rsp+0h] [rbp-118h] BYREF
int v7; // [rsp+F8h] [rbp-20h]
__int16 v8; // [rsp+FCh] [rbp-1Ch]

v2 = *a1;
memset(v6, 0, sizeof(v6));
v7 = 0;
v8 = 0;
sprintf(v6, "Mor %d\n", *(unsigned int *)(a2 + 20));
for ( ; v2; v2 = *(_QWORD *)(v2 + 40) )
{
v4 = *(_DWORD *)(v2 + 24);
if ( v4 )
{
v5 = strlen(v6);
write(v4, v6, v5);
}
}
return printf("Le joueur %d est mort\n", *(unsigned int *)(a2 + 20));
}

original_code:
void graph_mort(t_player **list, t_player *pl)
{
  t_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Mor %d\n", pl->player_id);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 write(tmp->player_fd, buff, strlen(buff));
      tmp = tmp->next;
    }
  printf("Le joueur %d est mort\n", pl->player_id);
}

canonical_original_code:
void graph_mort(struct s_player **list, struct s_player *pl)
{
  struct s_player *tmp;
  char buff[254];
  tmp = *list;
  memset(buff, '\0', 254);
  sprintf(buff, "Mor %d\n", pl->player_id);
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 write(tmp->player_fd, buff, strlen(buff));
      tmp = tmp->next;
    }
  printf("Le joueur %d est mort\n", pl->player_id);
}

variable_types:
pl
struct s_player *


decompiled_code:
int __fastcall graph_close(__int64 *a1, int a2)
{
unsigned int v2; // er12
__int64 i; // rax
__int64 j; // rbx
int v6; // ebp
size_t v7; // rax
char v8[248]; // [rsp+0h] [rbp-118h] BYREF
int v9; // [rsp+F8h] [rbp-20h]
__int16 v10; // [rsp+FCh] [rbp-1Ch]

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
if ( *(_DWORD *)(i + 24) == a2 )
v2 = *(_DWORD *)(i + 20);
}
memset(v8, 0, sizeof(v8));
v9 = 0;
v10 = 0;
sprintf(v8, "Mor %d\n", v2);
for ( j = *a1; j; j = *(_QWORD *)(j + 40) )
{
v6 = *(_DWORD *)(j + 24);
if ( v6 )
{
v7 = strlen(v8);
write(v6, v8, v7);
}
}
return printf(aLeJoueurDSEstS, v2);
}

canonical_decompiled_code:
int __fastcall func1(__int64 *a1, int a2)
{
unsigned int v2; // er12
__int64 i; // rax
__int64 j; // rbx
int v6; // ebp
size_t v7; // rax
char v8[248]; // [rsp+0h] [rbp-118h] BYREF
int v9; // [rsp+F8h] [rbp-20h]
__int16 v10; // [rsp+FCh] [rbp-1Ch]

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
if ( *(_DWORD *)(i + 24) == a2 )
v2 = *(_DWORD *)(i + 20);
}
memset(v8, 0, sizeof(v8));
v9 = 0;
v10 = 0;
sprintf(v8, "Mor %d\n", v2);
for ( j = *a1; j; j = *(_QWORD *)(j + 40) )
{
v6 = *(_DWORD *)(j + 24);
if ( v6 )
{
v7 = strlen(v8);
write(v6, v8, v7);
}
}
return printf(aLeJoueurDSEstS, v2);
}

original_code:
void graph_close(t_player **list, int fd)
{
  int id;
  char buff[254];
  t_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == fd)
 id = tmp->player_id;
      tmp = tmp->next;
    }
  memset(buff, '\0', 254);
  sprintf(buff, "Mor %d\n", id);
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 write(tmp->player_fd, buff, strlen(buff));
      tmp = tmp->next;
    }
  printf("Le joueur %d s'est suicidé\n", id);
}

canonical_original_code:
void graph_close(struct s_player **list, int fd)
{
  int id;
  char buff[254];
  struct s_player *tmp;
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd == fd)
 id = tmp->player_id;
      tmp = tmp->next;
    }
  memset(buff, '\0', 254);
  sprintf(buff, "Mor %d\n", id);
  tmp = *list;
  while (tmp != ((void *)0))
    {
      if (tmp->player_fd != 0)
 write(tmp->player_fd, buff, strlen(buff));
      tmp = tmp->next;
    }
  printf("Le joueur %d s'est suicidé\n", id);
}

variable_types: id int


decompiled_code:
__int64 serveur_read()
{
return add_client();
}

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

original_code:
void serveur_read(t_serv *e, int fd)
{
  add_client(e, fd);
}

canonical_original_code:
void serveur_read(struct s_serv *e, int fd)
{
  add_client(e, fd);
}


xbind

decompiled_code:
ssize_t __fastcall xbind(int fd, __int64 a2)
{
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

v3.sa_family = 2;
*(_WORD *)v3.sa_data = _bswap_16(*(_WORD *)(a2 + 8));
*(_DWORD *)&v3.sa_data[2] = 0;
if ( bind(fd, &v3, 0x10u) == -1 )
{
write(2, "BIND ERROR\n", 0xBuLL);
if ( close(fd) == -1 )
{
write(2, "ERROR: close\n", 0xDuLL);
exit(0);
}
exit(1);
}
return write(1, "BIND SUCCESS\n", 0xDuLL);
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, __int64 a2)
{
struct sockaddr v3; // [rsp+0h] [rbp-18h] BYREF

v3.sa_family = 2;
*(_WORD *)v3.sa_data = func0(*(_WORD *)(a2 + 8));
*(_DWORD *)&v3.sa_data[2] = 0;
if ( bind(fd, &v3, 0x10u) == -1 )
{
write(2, "BIND ERROR\n", 0xBuLL);
if ( close(fd) == -1 )
{
write(2, "ERROR: close\n", 0xDuLL);
exit(0);
}
exit(1);
}
return write(1, "BIND SUCCESS\n", 0xDuLL);
}

original_code:
void xbind(int fd, t_serv *e)
{
  struct sockaddr_in sin;
  sin.sin_family = 2;
  sin.sin_port = htons(e->port);
  sin.sin_addr.s_addr = ((in_addr_t) 0x00000000);
  if (bind(fd, (const struct sockaddr *)&sin, sizeof(sin)) == -1)
    {
      write(2, "BIND ERROR\n", 11);
      if (close(fd) == -1)
 {
          write (2, "ERROR: close\n", 13);
          exit(0);
        }
      exit(1);
    }
  write(1, "BIND SUCCESS\n", 13);
}

canonical_original_code:
void xbind(int fd, struct s_serv *e)
{
  struct sockaddr_in sin;
  sin.sin_family = 2;
  sin.sin_port = htons(e->port);
  sin.sin_addr.s_addr = ((unsigned int) 0x00000000);
  if (bind(fd, (struct sockaddr *)&sin, sizeof(sin)) == -1)
    {
      write(2, "BIND ERROR\n", 11);
      if (close(fd) == -1)
 {
          write (2, "ERROR: close\n", 13);
          exit(0);
        }
      exit(1);
    }
  write(1, "BIND SUCCESS\n", 13);
}

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

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 sockaddr { unsigned short sa_family; char sa_data[14]; }


xlisten

decompiled_code:
ssize_t __fastcall xlisten(int fd)
{
if ( listen(fd, 20) == -1 )
{
write(2, "LISTEN ERROR\n", 0xDuLL);
if ( close(fd) == -1 )
{
write(2, "ERROR: close\n", 0xDuLL);
exit(0);
}
exit(1);
}
return write(1, "LISTEN SUCCESS\n", 0xFuLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(int fd)
{
if ( listen(fd, 20) == -1 )
{
write(2, "LISTEN ERROR\n", 0xDuLL);
if ( close(fd) == -1 )
{
write(2, "ERROR: close\n", 0xDuLL);
exit(0);
}
exit(1);
}
return write(1, "LISTEN SUCCESS\n", 0xFuLL);
}

original_code:
void xlisten(int fd)
{
  if (listen(fd, 20) == -1)
    {
      write(2, "LISTEN ERROR\n", 13);
      if (close(fd) == -1)
 {
   write (2, "ERROR: close\n", 13);
   exit(0);
 }
      exit(1);
    }
  write(1, "LISTEN SUCCESS\n", 15);
}


main

canonical_name: main

repo: Foredoomed/CC-Compiler

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

if ( argc != 1 )
return (unsigned int)compile((char *)argv[1], (char *)argv, (const char *)envp, v3);
printf("Error : provide a file to compile");
return 1;
}

original_code:
int main(int argc, char **argv)
{
  if(argc == 1){
    printf("Error : provide a file to compile");
    return 1;
  }
  return compile(*(++argv));
}

variable_types: argc int

variable_types:
argv
char **


hash

original_code:
static int hash(const hash_t *tptr, const char *key) {
  int i=0;
  int hashvalue;
  while (*key != '\0')
     i=(i<<3)+(*key++ - '0');
  hashvalue = (((i*1103515249)>>tptr->downshift) & tptr->mask);
  if (hashvalue < 0) {
     hashvalue = 0;
   }
 return hashvalue;
}

canonical_original_code:
static int hash(struct hash_t *tptr, char *key) {
  int i = 0;
  int hashvalue;
  while (*key != '\0')
     i=(i<<3)+(*key++ - '0');
  hashvalue = (((i*1103515249)>>tptr->downshift) & tptr->mask);
  if (hashvalue < 0) {
     hashvalue = 0;
   }
 return hashvalue;
}

variable_types: struct hash_t { struct hash_node_t { char *data; char *key; struct hash_node_t *next; } **bucket; int size; int entries; int downshift; int mask; } *

variable_types:
key
char *

variable_types: hashvalue int

user_defined_types: struct hash_t { struct hash_node_t **bucket; int size; int entries; int downshift; int mask; }


original_code:
void hash_init(hash_t *tptr, int buckets) {
  if (buckets==0)
  buckets=16;
  tptr->entries=0;
  tptr->size=2;
  tptr->mask=1;
  tptr->downshift=29;
  while (tptr->size<buckets) {
    tptr->size<<=1;
    tptr->mask=(tptr->mask<<1)+1;
    tptr->downshift--;
  }
  tptr->bucket=(hash_node_t **) calloc(tptr->size, sizeof(hash_node_t *));
  return;
}

canonical_original_code:
void hash_init(struct hash_t *tptr, int buckets) {
  if (buckets==0)
  buckets=16;
  tptr->entries=0;
  tptr->size=2;
  tptr->mask=1;
  tptr->downshift=29;
  while (tptr->size<buckets) {
    tptr->size<<=1;
    tptr->mask=(tptr->mask<<1)+1;
    tptr->downshift--;
  }
  tptr->bucket=(struct hash_node_t **) calloc(tptr->size, sizeof(struct hash_node_t *));
  return;
}

variable_types: buckets int

user_defined_types: struct hash_node_t { char *data; char *key; struct hash_node_t *next; }


original_code:
static void rebuild_table(hash_t *tptr) {
  hash_node_t **old_bucket, *old_hash, *tmp;
  int old_size, h, i;
  old_bucket=tptr->bucket;
  old_size=tptr->size;
  hash_init(tptr, old_size<<1);
  for (i=0; i<old_size; i++) {
    old_hash=old_bucket[i];
    while(old_hash) {
      tmp=old_hash;
      old_hash=old_hash->next;
      h=hash(tptr, tmp->key);
      tmp->next=tptr->bucket[h];
      tptr->bucket[h]=tmp;
      tptr->entries++;
    }
  }
  free(old_bucket);
  return;
}

canonical_original_code:
static void rebuild_table(struct hash_t *tptr) {
  struct hash_node_t **old_bucket; struct hash_node_t *old_hash; struct hash_node_t *tmp;
  int old_size; int h; int i;
  old_bucket=tptr->bucket;
  old_size=tptr->size;
  hash_init(tptr, old_size<<1);
  for (i=0; i<old_size; i++) {
    old_hash=old_bucket[i];
    while(old_hash) {
      tmp=old_hash;
      old_hash=old_hash->next;
      h=hash(tptr, tmp->key);
      tmp->next=tptr->bucket[h];
      tptr->bucket[h]=tmp;
      tptr->entries++;
    }
  }
  free(old_bucket);
  return;
}

variable_types: struct hash_node_t { char *data; char *key; struct hash_node_t *next; } **

variable_types: h int


decompiled_code:
__int64 __fastcall hash_insert(__int64 a1, char *a2, const char *a3)
{
__int64 **v4; // rdx
__int64 result; // rax
int v6; // er14
_QWORD *v7; // r13
void *v8; // r15
size_t v9; // rax
void *v10; // r12
size_t v11; // rax
_QWORD *v12; // rax

v4 = hash_lookup((_QWORD *)a1, a2);
result = 0LL;
if ( !v4 )
{
while ( (double)*(int *)(a1 + 12) >= (double)*(int *)(a1 + 8) * 0.5 )
rebuild_table(a1);
v6 = hash(a1, a2);
v7 = malloc(0x18uLL);
v8 = malloc(8uLL);
*v7 = v8;
v9 = strlen(a3);
memcpy(v8, a3, v9);
v10 = malloc(8uLL);
v7[1] = v10;
v11 = strlen(a2);
memcpy(v10, a2, v11);
v12 = (_QWORD *)(*(_QWORD *)a1 + 8LL * v6);
v7[2] = *v12;
*v12 = v7;
++*(_DWORD *)(a1 + 12);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2, const char *a3)
{
__int64 **v4; // rdx
__int64 result; // rax
int v6; // er14
_QWORD *v7; // r13
void *v8; // r15
size_t v9; // rax
void *v10; // r12
size_t v11; // rax
_QWORD *v12; // rax

v4 = hash_lookup((_QWORD *)a1, a2);
result = 0LL;
if ( !v4 )
{
while ( (double)*(int *)(a1 + 12) >= (double)*(int *)(a1 + 8) * 0.5 )
func3(a1);
v6 = func0(a1, a2);
v7 = malloc(0x18uLL);
v8 = malloc(8uLL);
*v7 = v8;
v9 = strlen(a3);
memcpy(v8, a3, v9);
v10 = malloc(8uLL);
v7[1] = v10;
v11 = strlen(a2);
memcpy(v10, a2, v11);
v12 = (_QWORD *)(*(_QWORD *)a1 + 8LL * v6);
v7[2] = *v12;
*v12 = v7;
++*(_DWORD *)(a1 + 12);
result = 1LL;
}
return result;
}

original_code:
int hash_insert(hash_t *tptr, const char *key, char *data) {
  char *tmp;
  hash_node_t *node;
  int h;
  if ((tmp=hash_lookup(tptr, key)) != ((void *)0))
    return 0;
  while (tptr->entries>=0.5*tptr->size)
    rebuild_table(tptr);
  h=hash(tptr, key);
  node=(struct hash_node_t *) malloc(sizeof(hash_node_t));
  node->data=malloc(sizeof(data));
  memcpy(node->data, data, strlen(data));
  node->key=malloc(sizeof(key));
  memcpy(node->key, key, strlen(key));
  node->next=tptr->bucket[h];
  tptr->bucket[h]=node;
  tptr->entries++;
  return 1;
}

canonical_original_code:
int hash_insert(struct hash_t *tptr, char *key, char *data) {
  char *tmp;
  struct hash_node_t *node;
  int h;
  if ((tmp=hash_lookup(tptr, key)) != ((void *)0))
    return 0;
  while (tptr->entries>=0.5*tptr->size)
    rebuild_table(tptr);
  h=hash(tptr, key);
  node=(struct hash_node_t *) malloc(sizeof(hash_node_t));
  node->data=malloc(sizeof(data));
  memcpy(node->data, data, strlen(data));
  node->key=malloc(sizeof(key));
  memcpy(node->key, key, strlen(key));
  node->next=tptr->bucket[h];
  tptr->bucket[h]=node;
  tptr->entries++;
  return 1;
}

variable_types:
data
char *

variable_types:
tmp
char *

variable_types: struct hash_node_t { char *data; char *key; struct hash_node_t *next; } *


decompiled_code:
__int64 __fastcall hash_entries(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int hash_entries(hash_t *tptr) {
  return tptr->entries;
}

canonical_original_code:
int hash_entries(struct hash_t *tptr) {
  return tptr->entries;
}


original_code:
void hash_destroy(hash_t *tptr) {
  hash_node_t *node, *last;
  int i;
  for (i=0; i<tptr->size; i++) {
    node = tptr->bucket[i];
    while (node != ((void *)0)) {
      last = node;
      node = node->next;
      free(last);
    }
  }
  if (tptr->bucket != ((void *)0)) {
    free(tptr->bucket);
    memset(tptr, 0, sizeof(hash_t));
  }
}

canonical_original_code:
void hash_destroy(struct hash_t *tptr) {
  struct hash_node_t *node; struct hash_node_t *last;
  int i;
  for (i=0; i<tptr->size; i++) {
    node = tptr->bucket[i];
    while (node != ((void *)0)) {
      last = node;
      node = node->next;
      free(last);
    }
  }
  if (tptr->bucket != ((void *)0)) {
    free(tptr->bucket);
    memset(tptr, 0, sizeof(hash_t));
  }
}


decompiled_code:
char *__fastcall hash_stats(__int64 a1)
{
float v1; // xmm0_4

v1 = COERCE_FLOAT(alos(a1));
sprintf(buf_0, "%u slots, %u entries, and %1.2f ALOS", *(unsigned int *)(a1 + 8), *(unsigned int *)(a1 + 12), v1);
return buf_0;
}

canonical_decompiled_code:
char *__fastcall func7(__int64 a1)
{
float v1; // xmm0_4

v1 = COERCE_FLOAT(alos(a1));
sprintf(buf_0, "%u slots, %u entries, and %1.2f ALOS", *(unsigned int *)(a1 + 8), *(unsigned int *)(a1 + 12), v1);
return buf_0;
}

original_code:
char * hash_stats(hash_t *tptr) {
  static char buf[1024];
  sprintf(buf, "%u slots, %u entries, and %1.2f ALOS",
    (int)tptr->size, (int)tptr->entries, alos(tptr));
  return(buf);
}

canonical_original_code:
char *hash_stats(struct hash_t *tptr) {
  static char buf[1024];
  sprintf(buf, "%u slots, %u entries, and %1.2f ALOS",
    (int)tptr->size, (int)tptr->entries, alos(tptr));
  return(buf);
}

variable_types:
buf
char [1024]

return_type: char *


decompiled_code:
char *get_token()
{
return token;
}

canonical_decompiled_code:
char *func0()
{
return token;
}

original_code:
char *get_token()
{
  return token;
}

canonical_original_code:
char *get_token()
{
  return token;
}


decompiled_code:
_BOOL8 is_string()
{
return token[tpos - 1] == 34;
}

canonical_decompiled_code:
_BOOL8 func1()
{
return token[tpos - 1] == 34;
}

original_code:
BOOL is_string()
{
  return token[tpos - 1] == '"';
}

canonical_original_code:
int is_string()
{
  return token[tpos - 1] == '"';
}


decompiled_code:
_BOOL8 is_left()
{
return token[tpos - 1] == 40;
}

canonical_decompiled_code:
_BOOL8 func2()
{
return token[tpos - 1] == 40;
}

original_code:
BOOL is_left()
{
  return token[tpos - 1] == '(';
}

canonical_original_code:
int is_left()
{
  return token[tpos - 1] == '(';
}


decompiled_code:
_BOOL8 is_right()
{
return token[tpos - 1] == 41;
}

canonical_decompiled_code:
_BOOL8 func3()
{
return token[tpos - 1] == 41;
}

original_code:
BOOL is_right()
{
  return token[tpos - 1] == ')';
}

canonical_original_code:
int is_right()
{
  return token[tpos - 1] == ')';
}


decompiled_code:
_BOOL8 is_stop()
{
return token[tpos - 1] == 59;
}

canonical_decompiled_code:
_BOOL8 func4()
{
return token[tpos - 1] == 59;
}

original_code:
BOOL is_stop()
{
  return token[tpos - 1] == ';';
}

canonical_original_code:
int is_stop()
{
  return token[tpos - 1] == ';';
}


decompiled_code:
_BOOL8 is_parenthesis()
{
_BOOL4 v0; // edx
_BOOL8 result; // rax

v0 = is_left();
result = 1LL;
if ( !v0 )
result = is_right();
return result;
}

canonical_decompiled_code:
_BOOL8 func5()
{
_BOOL4 v0; // edx
_BOOL8 result; // rax

v0 = func2();
result = 1LL;
if ( !v0 )
result = func3();
return result;
}

original_code:
BOOL is_parenthesis()
{
  return is_left() || is_right();
}

canonical_original_code:
int is_parenthesis()
{
  return is_left() || is_right();
}


decompiled_code:
_BOOL8 is_call()
{
_BOOL4 v0; // ebx

v0 = 0;
if ( !is_parenthesis() )
{
v0 = 0;
if ( !is_string() )
v0 = !is_stop();
}
return v0;
}

original_code:
BOOL is_call()
{
  return !is_parenthesis() && !is_string() && !is_stop();
}

canonical_original_code:
int is_call()
{
  return !is_parenthesis() && !is_string() && !is_stop();
}


decompiled_code:
__int64 is_alpha()
{
return (*_ctype_b_loc())[token[0]] & 0x400;
}

canonical_decompiled_code:
__int64 func7()
{
return (*_ctype_b_loc())[token[0]] & 0x400;
}

original_code:
int is_alpha()
{
  return ((*__ctype_b_loc ())[(int) ((token[0]))] & (unsigned short int) _ISalpha);
}

canonical_original_code:
int is_alpha()
{
  return ((*__ctype_b_loc ())[(int) ((token[0]))] & (unsigned short) _ISalpha);
}


decompiled_code:
_BOOL8 is_assignment()
{
return token[tpos - 1] == 61;
}

canonical_decompiled_code:
_BOOL8 func8()
{
return token[tpos - 1] == 61;
}

original_code:
BOOL is_assignment()
{
  return token[tpos - 1] == '=';
}

canonical_original_code:
int is_assignment()
{
  return token[tpos - 1] == '=';
}


init

decompiled_code:
__int64 __fastcall init(__int64 a1)
{
read_char(a1, &chs);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
read_char(a1, &chs);
return 1LL;
}

original_code:
BOOL init(const char *file)
{
  read_char(file, chs);
  return chs != ((void *)0);
}

canonical_original_code:
int init(char *file)
{
  read_char(file, chs);
  return chs != ((void *)0);
}

variable_types:
file
char *


next

decompiled_code:
_BOOL8 __fastcall next(char *a1, __int64 a2)
{
const unsigned __int16 **v2; // rbx
__int64 v3; // rdx
_BOOL4 v4; // ecx
int v6; // ebx
char v7; // al
char v8; // al
char src[2]; // [rsp+Eh] [rbp-Ah] BYREF

*(_WORD *)src = 0;
*(_WORD *)src = (unsigned __int8)chs[pos];
v2 = _ctype_b_loc();
while ( 1 )
{
v3 = (*v2)[src[0]];
if ( (v3 & 0x2000) == 0 || !src[0] )
break;
a2 = 0LL;
a1 = token;
memset(token, 0, (size_t)&unk_400000);
tpos = 0;
src[0] = chs[++pos];
}
v4 = 0;
if ( src[0] )
{
if ( src[0] == 34 )
{
memset(token, 0, (size_t)&unk_400000);
strcpy(token, src);
tpos = 1;
v6 = pos++;
for ( src[0] = chs[pos]; src[0] != 34; src[0] = chs[pos] )
{
strcat(token, src);
++tpos;
v6 = pos++;
}
src[0] = 34;
strcat(token, src);
++tpos;
pos = v6 + 2;
}
else if ( (v3 & 0x400) != 0 )
{
memset(token, 0, (size_t)&unk_400000);
strcpy(token, src);
tpos = 1;
v7 = chs[++pos];
src[0] = v7;
if ( v7 )
{
while ( ((*v2)[v7] & 0x400) != 0 )
{
strcat(token, src);
++tpos;
v7 = chs[++pos];
src[0] = v7;
if ( !v7 )
goto LABEL_19;
}
v8 = src[0];
if ( ((*v2)[src[0]] & 0x2000) != 0 && src[0] )
{
do
v8 = chs[++pos];
while ( ((*v2)[v8] & 0x2000) != 0 && v8 );
src[0] = chs[pos];
}
}
else
{
LABEL_19:
v8 = src[0];
}
if ( v8 == 61 )
{
*(_WORD *)&token[strlen(token)] = 61;
++pos;
++tpos;
}
}
else if ( src[0] == 61 )
{
++pos;
next(a1, a2, v3, 0LL);
}
else
{
strcat(token, src);
++pos;
++tpos;
}
v4 = 0;
if ( pos != (_DWORD)&unk_3FFFFF )
v4 = token[0] != 0;
}
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(char *a1, __int64 a2)
{
const unsigned __int16 **v2; // rbx
__int64 v3; // rdx
_BOOL4 v4; // ecx
int v6; // ebx
char v7; // al
char v8; // al
char src[2]; // [rsp+Eh] [rbp-Ah] BYREF

*(_WORD *)src = 0;
*(_WORD *)src = (unsigned __int8)chs[pos];
v2 = _ctype_b_loc();
while ( 1 )
{
v3 = (*v2)[src[0]];
if ( (v3 & 0x2000) == 0 || !src[0] )
break;
a2 = 0LL;
a1 = token;
memset(token, 0, (size_t)&unk_400000);
tpos = 0;
src[0] = chs[++pos];
}
v4 = 0;
if ( src[0] )
{
if ( src[0] == 34 )
{
memset(token, 0, (size_t)&unk_400000);
strcpy(token, src);
tpos = 1;
v6 = pos++;
for ( src[0] = chs[pos]; src[0] != 34; src[0] = chs[pos] )
{
strcat(token, src);
++tpos;
v6 = pos++;
}
src[0] = 34;
strcat(token, src);
++tpos;
pos = v6 + 2;
}
else if ( (v3 & 0x400) != 0 )
{
memset(token, 0, (size_t)&unk_400000);
strcpy(token, src);
tpos = 1;
v7 = chs[++pos];
src[0] = v7;
if ( v7 )
{
while ( ((*v2)[v7] & 0x400) != 0 )
{
strcat(token, src);
++tpos;
v7 = chs[++pos];
src[0] = v7;
if ( !v7 )
goto LABEL_19;
}
v8 = src[0];
if ( ((*v2)[src[0]] & 0x2000) != 0 && src[0] )
{
do
v8 = chs[++pos];
while ( ((*v2)[v8] & 0x2000) != 0 && v8 );
src[0] = chs[pos];
}
}
else
{
LABEL_19:
v8 = src[0];
}
if ( v8 == 61 )
{
*(_WORD *)&token[strlen(token)] = 61;
++pos;
++tpos;
}
}
else if ( src[0] == 61 )
{
++pos;
func10(a1, a2, v3, 0LL);
}
else
{
strcat(token, src);
++pos;
++tpos;
}
v4 = 0;
if ( pos != (_DWORD)&unk_3FFFFF )
v4 = token[0] != 0;
}
return v4;
}

original_code:
BOOL next()
{
  char current[2] = "\0\0";
  current[0] = chs[pos];
  while(((*__ctype_b_loc ())[(int) ((current[0]))] & (unsigned short int) _ISspace) && current[0] != '\0'){
    memset(token, 0, sizeof(token));
    tpos = 0;
    current[0] = chs[++pos];
  }
  if(current[0] == '\0'){
    return 0;
  }
  if(current[0] == '"'){
    memset(token, 0, sizeof(token));
    strcpy(token, current);
    tpos = 1;
    while((current[0] = chs[++pos]) != '"'){
      strcat(token, current);
      tpos++;
    }
    current[0] = '"';
    strcat(token, current);
    tpos++;
    pos++;
  } else if(((*__ctype_b_loc ())[(int) ((current[0]))] & (unsigned short int) _ISalpha)){
      memset(token, 0, sizeof(token));
      strcpy(token, current);
      tpos = 1;
    while((current[0] = chs[++pos]) && ((*__ctype_b_loc ())[(int) ((current[0]))] & (unsigned short int) _ISalpha)){
      strcat(token, current);
      tpos++;
    }
    while(((*__ctype_b_loc ())[(int) ((current[0]))] & (unsigned short int) _ISspace) && current[0] != '\0'){
      current[0] = chs[++pos];
    }
    if(current[0] == '='){
      strcat(token, "=");
      pos++;
      tpos++;
    }
  } else if(current[0] == '='){
    pos++;
    next();
  } else {
    strcat(token, current);
    pos++;
    tpos++;
  }
  if((pos == 4*1024*1024 - 1) || (token[0] == 0)){
    return 0;
  }
  return 1;
}

canonical_original_code:
int next()
{
  char current[2] = "\0\0";
  current[0] = chs[pos];
  while(((*__ctype_b_loc ())[(int) ((current[0]))] & (unsigned short) _ISspace) && current[0] != '\0'){
    memset(token, 0, sizeof(token));
    tpos = 0;
    current[0] = chs[++pos];
  }
  if(current[0] == '\0'){
    return 0;
  }
  if(current[0] == '"'){
    memset(token, 0, sizeof(token));
    strcpy(token, current);
    tpos = 1;
    while((current[0] = chs[++pos]) != '"'){
      strcat(token, current);
      tpos++;
    }
    current[0] = '"';
    strcat(token, current);
    tpos++;
    pos++;
  } else if(((*__ctype_b_loc ())[(int) ((current[0]))] & (unsigned short) _ISalpha)){
      memset(token, 0, sizeof(token));
      strcpy(token, current);
      tpos = 1;
    while((current[0] = chs[++pos]) && ((*__ctype_b_loc ())[(int) ((current[0]))] & (unsigned short) _ISalpha)){
      strcat(token, current);
      tpos++;
    }
    while(((*__ctype_b_loc ())[(int) ((current[0]))] & (unsigned short) _ISspace) && current[0] != '\0'){
      current[0] = chs[++pos];
    }
    if(current[0] == '='){
      strcat(token, "=");
      pos++;
      tpos++;
    }
  } else if(current[0] == '='){
    pos++;
    next();
  } else {
    strcat(token, current);
    pos++;
    tpos++;
  }
  if((pos == 4*1024*1024 - 1) || (token[0] == 0)){
    return 0;
  }
  return 1;
}

variable_types:
current
char [2]


repo: ForsakenX/forsaken

decompiled_code:
char *__fastcall X_realloc(void *ptr, size_t size, __int64 a3, int a4)
{
int v6; // er12
char *v7; // r13
size_t v8; // rdi
__int64 v9; // rax

v6 = XMem_FindSame((__int64)ptr);
if ( v6 == -1 )
{
DebugPrintf("MEM: tried to realloc un-alloced block\n");
v7 = 0LL;
}
else
{
v7 = (char *)realloc(ptr, size);
if ( v7 )
{
BlockUsed[v6] = 1;
BlockPnts[v6] = (__int64)v7;
BlockInFile[v6] = a3;
BlockInLine[v6] = a4;
v8 = BlockSize[v6];
if ( v8 < size )
memset(&v7[v8], 0, size - v8);
v9 = BlockSize[v6];
BlockSize[v6] = size;
MemUsed += size - v9;
}
}
return v7;
}

canonical_decompiled_code:
char *__fastcall func5(void *ptr, size_t size, __int64 a3, int a4)
{
int v6; // er12
char *v7; // r13
size_t v8; // rdi
__int64 v9; // rax

v6 = func2((__int64)ptr);
if ( v6 == -1 )
{
DebugPrintf("MEM: tried to realloc un-alloced block\n");
v7 = 0LL;
}
else
{
v7 = (char *)realloc(ptr, size);
if ( v7 )
{
BlockUsed[v6] = 1;
BlockPnts[v6] = (__int64)v7;
BlockInFile[v6] = a3;
BlockInLine[v6] = a4;
v8 = BlockSize[v6];
if ( v8 < size )
memset(&v7[v8], 0, size - v8);
v9 = BlockSize[v6];
BlockSize[v6] = size;
MemUsed += size - v9;
}
}
return v7;
}

original_code:
void * X_realloc( void * Pnt , size_t size, char *in_file, int in_line )
{
 int i;
 i = XMem_FindSame( Pnt );
 if( i == -1 )
 {
  DebugPrintf( "MEM: tried to realloc un-alloced block\n");
  return ((void *)0);
 }
 Pnt = realloc( Pnt , size );
 if( !Pnt )
  return Pnt;
 BlockUsed[i] = 1;
 BlockPnts[i] = Pnt;
 BlockInFile[i] = in_file;
 BlockInLine[i] = in_line;
 if(size > BlockSize[i])
  memset(Pnt+BlockSize[i],0,size-BlockSize[i]);
 MemUsed -= BlockSize[i];
 BlockSize[i] = size;
 MemUsed += size;
 return Pnt;
}

canonical_original_code:
void *X_realloc(void *Pnt, unsigned long size, char *in_file, int in_line)
{
 int i;
 i = XMem_FindSame( Pnt );
 if( i == -1 )
 {
  DebugPrintf( "MEM: tried to realloc un-alloced block\n");
  return ((void *)0);
 }
 Pnt = realloc( Pnt , size );
 if( !Pnt )
  return Pnt;
 BlockUsed[i] = 1;
 BlockPnts[i] = Pnt;
 BlockInFile[i] = in_file;
 BlockInLine[i] = in_line;
 if(size > BlockSize[i])
  memset(Pnt+BlockSize[i],0,size-BlockSize[i]);
 MemUsed -= BlockSize[i];
 BlockSize[i] = size;
 MemUsed += size;
 return Pnt;
}

variable_types:
Pnt
void *

variable_types:
size
unsigned long

variable_types: i int


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

MemUsed = 0LL;
for ( result = 0LL; result != 0x4000; ++result )
{
BlockUsed[result] = 0;
BlockPnts[result] = 0LL;
BlockSize[result] = 0LL;
}
return result;
}

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

MemUsed = 0LL;
for ( result = 0LL; result != 0x4000; ++result )
{
BlockUsed[result] = 0;
BlockPnts[result] = 0LL;
BlockSize[result] = 0LL;
}
return result;
}

original_code:
void XMem_Init( void )
{
 int i;
 MemUsed =0;
 for( i = 0 ; i < 16384 ; i++ )
 {
  BlockUsed[i] = 0;
  BlockPnts[i] = ((void *)0);
  BlockSize[i] = 0;
 }
}

canonical_original_code:
void XMem_Init()
{
 int i;
 MemUsed =0;
 for( i = 0 ; i < 16384 ; i++ )
 {
  BlockUsed[i] = 0;
  BlockPnts[i] = ((void *)0);
  BlockSize[i] = 0;
 }
}


decompiled_code:
__int64 XMem_FindFree()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 0LL;
while ( 1 )
{
v1 = v0;
if ( !BlockUsed[v0] )
break;
if ( ++v0 == 0x4000 )
return (unsigned int)-1;
}
++BlocksUsed;
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = 0LL;
while ( 1 )
{
v1 = v0;
if ( !BlockUsed[v0] )
break;
if ( ++v0 == 0x4000 )
return (unsigned int)-1;
}
++BlocksUsed;
return v1;
}

original_code:
int XMem_FindFree( void )
{
 int i;
 for( i = 0 ; i < 16384 ; i++ )
 {
  if( !BlockUsed[i] )
  {
   BlocksUsed++;
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int XMem_FindFree()
{
 int i;
 for( i = 0 ; i < 16384 ; i++ )
 {
  if( !BlockUsed[i] )
  {
   BlocksUsed++;
   return i;
  }
 }
 return -1;
}


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

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( BlockUsed[v1] )
{
if ( BlockPnts[v1] == a1 )
break;
}
if ( ++v1 == 0x4000 )
return (unsigned int)-1;
}
return v2;
}

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

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( BlockUsed[v1] )
{
if ( BlockPnts[v1] == a1 )
break;
}
if ( ++v1 == 0x4000 )
return (unsigned int)-1;
}
return v2;
}

original_code:
int XMem_FindSame( void * Pnt )
{
 int i;
 for( i = 0 ; i < 16384 ; i++ )
 {
  if( BlockUsed[i] && ( BlockPnts[i] == Pnt ) )
   return i;
 }
 return -1;
}

canonical_original_code:
int XMem_FindSame(void *Pnt)
{
 int i;
 for( i = 0 ; i < 16384 ; i++ )
 {
  if( BlockUsed[i] && ( BlockPnts[i] == Pnt ) )
   return i;
 }
 return -1;
}


decompiled_code:
char *__fastcall X_strdup(char *s, __int64 a2, int a3)
{
int v4; // ebx
char *v5; // r12
int v6; // eax
__int64 v7; // rdx

v4 = XMem_FindFree();
if ( v4 == -1 )
{
DebugPrintf("MEM: Ran out of free memory Blocks\n");
v5 = 0LL;
}
else
{
v5 = strdup(s);
if ( v5 )
{
v6 = strlen(s);
BlockUsed[v4] = 1;
BlockPnts[v4] = (__int64)v5;
v7 = v6 + 1;
BlockSize[v4] = v7;
BlockInFile[v4] = a2;
BlockInLine[v4] = a3;
MemUsed += v7;
}
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func3(char *s, __int64 a2, int a3)
{
int v4; // ebx
char *v5; // r12
int v6; // eax
__int64 v7; // rdx

v4 = func1();
if ( v4 == -1 )
{
DebugPrintf("MEM: Ran out of free memory Blocks\n");
v5 = 0LL;
}
else
{
v5 = strdup(s);
if ( v5 )
{
v6 = strlen(s);
BlockUsed[v4] = 1;
BlockPnts[v4] = (__int64)v5;
v7 = v6 + 1;
BlockSize[v4] = v7;
BlockInFile[v4] = a2;
BlockInLine[v4] = a3;
MemUsed += v7;
}
}
return v5;
}

original_code:
void * X_strdup( char *str, char *in_file, int in_line )
{
 void * Pnt;
 int i;
 i = XMem_FindFree();
 if( i == -1 )
 {
  DebugPrintf( "MEM: Ran out of free memory Blocks\n");
  return ((void *)0);
 }
 Pnt = strdup( str );
 if( !Pnt )
  return Pnt;
 int size = strlen(str)+1;
 BlockUsed[i] = 1;
 BlockPnts[i] = Pnt;
 BlockSize[i] = size;
 BlockInFile[i] = in_file;
 BlockInLine[i] = in_line;
 MemUsed += size;
 return Pnt;
}

canonical_original_code:
void *X_strdup(char *str, char *in_file, int in_line)
{
 void *Pnt;
 int i;
 i = XMem_FindFree();
 if( i == -1 )
 {
  DebugPrintf( "MEM: Ran out of free memory Blocks\n");
  return ((void *)0);
 }
 Pnt = strdup( str );
 if( !Pnt )
  return Pnt;
 int size = strlen(str)+1;
 BlockUsed[i] = 1;
 BlockPnts[i] = Pnt;
 BlockSize[i] = size;
 BlockInFile[i] = in_file;
 BlockInLine[i] = in_line;
 MemUsed += size;
 return Pnt;
}

variable_types:
str
char *

variable_types: size int


decompiled_code:
void __fastcall X_free(void *ptr, const char *a2, unsigned int a3)
{
int v4; // ebx

if ( ptr )
{
v4 = XMem_FindSame((__int64)ptr);
if ( v4 == -1 )
{
if ( (const char *)last_file_1 != a2 || last_line_0 != a3 )
DebugPrintf("MEM: Tried to free un-malloced block in %s line %d\n", a2, a3);
last_file_1 = (__int64)a2;
last_line_0 = a3;
}
else
{
free(ptr);
BlockUsed[v4] = 0;
BlockPnts[v4] = 0LL;
BlockInFile[v4] = 0LL;
BlockInLine[v4] = 0;
MemUsed -= BlockSize[v4];
BlockSize[v4] = 0LL;
--BlocksUsed;
}
}
else
{
if ( (const char *)last_file_1 != a2 || last_line_0 != a3 )
DebugPrintf("MEM: Tried to free NULL block in %s line %d\n", a2, a3);
last_file_1 = (__int64)a2;
last_line_0 = a3;
}
}

canonical_decompiled_code:
void __fastcall func4(void *ptr, const char *a2, unsigned int a3)
{
int v4; // ebx

if ( ptr )
{
v4 = func2((__int64)ptr);
if ( v4 == -1 )
{
if ( (const char *)last_file_1 != a2 || last_line_0 != a3 )
DebugPrintf("MEM: Tried to free un-malloced block in %s line %d\n", a2, a3);
last_file_1 = (__int64)a2;
last_line_0 = a3;
}
else
{
free(ptr);
BlockUsed[v4] = 0;
BlockPnts[v4] = 0LL;
BlockInFile[v4] = 0LL;
BlockInLine[v4] = 0;
MemUsed -= BlockSize[v4];
BlockSize[v4] = 0LL;
--BlocksUsed;
}
}
else
{
if ( (const char *)last_file_1 != a2 || last_line_0 != a3 )
DebugPrintf("MEM: Tried to free NULL block in %s line %d\n", a2, a3);
last_file_1 = (__int64)a2;
last_line_0 = a3;
}
}

original_code:
void X_free( void * Pnt, char *in_file, int in_line )
{
 int i;
 static char *last_file = ((void *)0);
 static int last_line = -1;
 if ( !Pnt )
 {
  if ( in_file != last_file || in_line != last_line )
   DebugPrintf( "MEM: Tried to free NULL block in %s line %d\n", in_file, in_line );
  last_file = in_file;
  last_line = in_line;
  return;
 }
 i = XMem_FindSame( Pnt );
 if( i == -1 )
 {
  if ( in_file != last_file || in_line != last_line )
    DebugPrintf( "MEM: Tried to free un-malloced block in %s line %d\n", in_file, in_line );
  last_file = in_file;
  last_line = in_line;
  return;
 }
 free(Pnt);
 BlockUsed[i] = 0;
 BlockPnts[i] = ((void *)0);
 BlockInFile[ i ] = ((void *)0);
 BlockInLine[ i ] = 0;
 MemUsed -= BlockSize[i];
 BlockSize[i] = 0;
 BlocksUsed--;
}

canonical_original_code:
void X_free(void *Pnt, char *in_file, int in_line)
{
 int i;
 static char *last_file = ((void *)0);
 static int last_line = -1;
 if ( !Pnt )
 {
  if ( in_file != last_file || in_line != last_line )
   DebugPrintf( "MEM: Tried to free NULL block in %s line %d\n", in_file, in_line );
  last_file = in_file;
  last_line = in_line;
  return;
 }
 i = XMem_FindSame( Pnt );
 if( i == -1 )
 {
  if ( in_file != last_file || in_line != last_line )
    DebugPrintf( "MEM: Tried to free un-malloced block in %s line %d\n", in_file, in_line );
  last_file = in_file;
  last_line = in_line;
  return;
 }
 free(Pnt);
 BlockUsed[i] = 0;
 BlockPnts[i] = ((void *)0);
 BlockInFile[ i ] = ((void *)0);
 BlockInLine[ i ] = 0;
 MemUsed -= BlockSize[i];
 BlockSize[i] = 0;
 BlocksUsed--;
}


UnMallocedBlocks

decompiled_code:
__int64 UnMallocedBlocks()
{
__int64 i; // rbx

if ( BlocksUsed )
{
for ( i = 0LL; i != 0x4000; ++i )
{
if ( BlockUsed[i] )
DebugPrintf(
"MEM: Block size %d allocated in %s line %d but not freed\n",
BlockSize[i],
(const char *)BlockInFile[i],
(unsigned int)BlockInLine[i]);
}
}
DebugPrintf("MEM: MemUsed = %d BlocksUsed = %d\n", MemUsed, (unsigned int)BlocksUsed);
return (unsigned int)BlocksUsed;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 i; // rbx

if ( BlocksUsed )
{
for ( i = 0LL; i != 0x4000; ++i )
{
if ( BlockUsed[i] )
DebugPrintf(
"MEM: Block size %d allocated in %s line %d but not freed\n",
BlockSize[i],
(const char *)BlockInFile[i],
(unsigned int)BlockInLine[i]);
}
}
DebugPrintf("MEM: MemUsed = %d BlocksUsed = %d\n", MemUsed, (unsigned int)BlocksUsed);
return (unsigned int)BlocksUsed;
}

original_code:
int UnMallocedBlocks( void )
{
 int i;
 if ( BlocksUsed )
 {
  for ( i = 0; i < 16384; i++ )
  {
   if ( BlockUsed[ i ] )
   {
    DebugPrintf( "MEM: Block size %d allocated in %s line %d but not freed\n",
     BlockSize[ i ], BlockInFile[ i ], BlockInLine[ i ] );
   }
  }
 }
 DebugPrintf( "MEM: MemUsed = %d   BlocksUsed = %d\n",
  MemUsed, BlocksUsed );
 return BlocksUsed;
}

canonical_original_code:
int UnMallocedBlocks()
{
 int i;
 if ( BlocksUsed )
 {
  for ( i = 0; i < 16384; i++ )
  {
   if ( BlockUsed[ i ] )
   {
    DebugPrintf( "MEM: Block size %d allocated in %s line %d but not freed\n",
     BlockSize[ i ], BlockInFile[ i ], BlockInLine[ i ] );
   }
  }
 }
 DebugPrintf( "MEM: MemUsed = %d   BlocksUsed = %d\n",
  MemUsed, BlocksUsed );
 return BlocksUsed;
}


GetFilename

decompiled_code:
char *__fastcall GetFilename(char *src, char *dest)
{
char *v3; // rdx
char *v4; // rsi
char *result; // rax

v3 = &src[strlen(src) - 1];
v4 = v3;
if ( src == v3 )
return strcpy(dest, src);
while ( 1 )
{
result = (char *)(unsigned __int8)*v4;
if ( (_BYTE)result == 58 || (_BYTE)result == 92 )
break;
if ( src == --v4 )
return strcpy(dest, src);
}
if ( src == v4 )
return strcpy(dest, src);
if ( v3 != v4 )
return strcpy(dest, v4 + 1);
*dest = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(char *src, char *dest)
{
char *v3; // rdx
char *v4; // rsi
char *result; // rax

v3 = &src[strlen(src) - 1];
v4 = v3;
if ( src == v3 )
return strcpy(dest, src);
while ( 1 )
{
result = (char *)(unsigned __int8)*v4;
if ( (_BYTE)result == 58 || (_BYTE)result == 92 )
break;
if ( src == --v4 )
return strcpy(dest, src);
}
if ( src == v4 )
return strcpy(dest, src);
if ( v3 != v4 )
return strcpy(dest, v4 + 1);
*dest = 0;
return result;
}

original_code:
void GetFilename( u_int8_t * Src, u_int8_t * Dest )
{
 u_int8_t * Char_Ptr;
 Char_Ptr = ( Src + strlen( Src ) ) -1;
 while( Char_Ptr != Src && *Char_Ptr != '\\' && *Char_Ptr != ':' ) Char_Ptr--;
 if( Char_Ptr == Src )
 {
  strcpy( Dest, Src );
  return;
 }
 if( Char_Ptr != ( Src + strlen( Src ) - 1 ) )
 {
  strcpy( Dest, ( Char_Ptr + 1 ) );
 }
 else
 {
  *Dest = 0;
 }
}

canonical_original_code:
void GetFilename(unsigned int *Src, unsigned int *Dest)
{
 unsigned int *Char_Ptr;
 Char_Ptr = ( Src + strlen( Src ) ) -1;
 while( Char_Ptr != Src && *Char_Ptr != '\\' && *Char_Ptr != ':' ) Char_Ptr--;
 if( Char_Ptr == Src )
 {
  strcpy( Dest, Src );
  return;
 }
 if( Char_Ptr != ( Src + strlen( Src ) - 1 ) )
 {
  strcpy( Dest, ( Char_Ptr + 1 ) );
 }
 else
 {
  *Dest = 0;
 }
}

variable_types:
Src
unsigned int *

variable_types:
Dest
unsigned int *


DebugPrintf

decompiled_code:
void DebugPrintf(char *format, ...)
{
size_t v1; // rax
struct timeb timebuf; // [rsp+0h] [rbp-F0h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-D8h] BYREF

if ( Debug )
{
ftime(&timebuf);
sprintf(buf_3, "%ld.%.3d ", timebuf.time, timebuf.millitm);
v1 = strlen(buf_3);
va_start(arg, format);
vsnprintf(&buf_3[v1], 0x4000 - (int)v1, format, arg);
byte_867F = 0;
DebugPuts(buf_3);
}
}

canonical_decompiled_code:
void func6(char *format, ...)
{
size_t v1; // rax
struct timeb timebuf; // [rsp+0h] [rbp-F0h] BYREF
gcc_va_list arg; // [rsp+18h] [rbp-D8h] BYREF

if ( Debug )
{
ftime(&timebuf);
sprintf(buf_3, "%ld.%.3d ", timebuf.time, timebuf.millitm);
v1 = strlen(buf_3);
va_start(arg, format);
vsnprintf(&buf_3[v1], 0x4000 - (int)v1, format, arg);
byte_867F = 0;
func5(buf_3);
}
}

original_code:
void DebugPrintf( const char * format, ... )
{
 static char buf[0x4000];
 char *buf2;
 int buf_length;
 va_list args;
 if(!Debug)
  return;
 struct timeb now;
 ftime(&now);
 sprintf( buf, "%ld.%.3d ",
  now.time, now.millitm);
 buf2 = strchr(buf,0);
 buf_length = sizeof(buf)-strlen(buf);
 __builtin_va_start(args,format);
 vsnprintf( buf2, buf_length, format, args );
 __builtin_va_end(args);
 buf[sizeof(buf)-1]=0;
 DebugPuts(buf);
}

canonical_original_code:
void DebugPrintf(char *format, ...)
{
 static char buf[16384];
 char *buf2;
 int buf_length;
 __builtin_va_list args;
 if(!Debug)
  return;
 struct timeb now;
 ftime(&now);
 sprintf( buf, "%ld.%.3d ",
  now.time, now.millitm);
 buf2 = strchr(buf,0);
 buf_length = sizeof(buf)-strlen(buf);
 __builtin_va_start(args,format);
 vsnprintf( buf2, buf_length, format, args );
 __builtin_va_end(args);
 buf[sizeof(buf)-1]=0;
 DebugPuts(buf);
}

variable_types:
format
char *

variable_types:
buf
char [16384]

variable_types: struct timeb { long time; unsigned short millitm; short timezone; short dstflag; }


decompiled_code:
void DebugPrintf_(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-C8h] BYREF

if ( Debug )
{
va_start(arg, format);
vsnprintf(buf_2, 0x4000uLL, format, arg);
byte_467F = 0;
DebugPuts(buf_2);
}
}

canonical_decompiled_code:
void func7(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-C8h] BYREF

if ( Debug )
{
va_start(arg, format);
vsnprintf(buf_2, 0x4000uLL, format, arg);
byte_467F = 0;
func5(buf_2);
}
}

original_code:
void DebugPrintf_( const char * format, ... )
{
 static char buf[0x4000];
 va_list args;
 if(!Debug)
  return;
 __builtin_va_start(args,format);
 vsnprintf( buf, sizeof(buf), format, args );
 __builtin_va_end(args);
 buf[sizeof(buf)-1]=0;
 DebugPuts(buf);
}

canonical_original_code:
void DebugPrintf_(char *format, ...)
{
 static char buf[16384];
 __builtin_va_list args;
 if(!Debug)
  return;
 __builtin_va_start(args,format);
 vsnprintf( buf, sizeof(buf), format, args );
 __builtin_va_end(args);
 buf[sizeof(buf)-1]=0;
 DebugPuts(buf);
}


Msg

decompiled_code:
__int64 Msg(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4C8h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B0h] BYREF

va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
s[1023] = 0;
DebugPrintf("Msg: %s\n", s);
return 1LL;
}

canonical_decompiled_code:
__int64 func9(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4C8h] BYREF
char s[1024]; // [rsp+20h] [rbp-4B0h] BYREF

va_start(arg, format);
vsnprintf(s, 0x400uLL, format, arg);
s[1023] = 0;
func6("Msg: %s\n", s);
return 1LL;
}

original_code:
int Msg( const char * msg, ... )
{
 char txt[ 1024 ];
 va_list args;
 int res = 1;
 __builtin_va_start(args,msg);
 vsnprintf( txt, sizeof(txt), msg, args);
 __builtin_va_end(args);
 txt[sizeof(txt)-1] = 0;
 DebugPrintf("Msg: %s\n",txt);
 return res;
}

canonical_original_code:
int Msg(char *msg, ...)
{
 char txt[1024];
 __builtin_va_list args;
 int res = 1;
 __builtin_va_start(args,msg);
 vsnprintf( txt, sizeof(txt), msg, args);
 __builtin_va_end(args);
 txt[sizeof(txt)-1] = 0;
 DebugPrintf("Msg: %s\n",txt);
 return res;
}

variable_types:
msg
char *

variable_types:
txt
char [1024]

variable_types: res int


decompiled_code:
char *__fastcall Change_Ext(char *src, char *dest, const char *a3)
{
char *v3; // r12
int v5; // eax
char *v6; // rax
__int64 v7; // rcx
int v9; // esi
signed __int64 v10; // rax
__int64 v11; // rdx
size_t v12; // rax

v3 = dest;
v5 = strlen(src);
if ( !v5 )
{
strcpy(dest, a3);
return (char *)Msg("Change_Ext called with Src empty!");
}
v6 = &src[v5 - 1];
v7 = 0x400000001001LL;
if ( src == v6 )
{
if ( *v6 == 46 )
return strcpy(v3, a3);
}
else
{
do
{
v9 = (unsigned __int8)*v6;
if ( (unsigned __int8)(v9 - 46) <= 0x2Eu && _bittest64(&v7, (unsigned int)(v9 - 46)) )
{
if ( (_BYTE)v9 != 46 )
goto LABEL_16;
if ( src != v6 )
{
v10 = v6 - src;
v11 = 0LL;
do
{
v3[v11] = src[v11];
++v11;
}
while ( v11 != v10 );
v3 += v10;
}
return strcpy(v3, a3);
}
--v6;
}
while ( src != v6 );
if ( *v6 == 46 )
return strcpy(v3, a3);
}
LABEL_16:
strcpy(v3, src);
v12 = strlen(src);
return strcpy(&v3[v12], a3);
}

canonical_decompiled_code:
char *__fastcall func10(char *src, char *dest, const char *a3)
{
char *v3; // r12
int v5; // eax
char *v6; // rax
__int64 v7; // rcx
int v9; // esi
signed __int64 v10; // rax
__int64 v11; // rdx
size_t v12; // rax

v3 = dest;
v5 = strlen(src);
if ( !v5 )
{
strcpy(dest, a3);
return (char *)func9("Change_Ext called with Src empty!");
}
v6 = &src[v5 - 1];
v7 = 0x400000001001LL;
if ( src == v6 )
{
if ( *v6 == 46 )
return strcpy(v3, a3);
}
else
{
do
{
v9 = (unsigned __int8)*v6;
if ( (unsigned __int8)(v9 - 46) <= 0x2Eu && _bittest64(&v7, (unsigned int)(v9 - 46)) )
{
if ( (_BYTE)v9 != 46 )
goto LABEL_16;
if ( src != v6 )
{
v10 = v6 - src;
v11 = 0LL;
do
{
v3[v11] = src[v11];
++v11;
}
while ( v11 != v10 );
v3 += v10;
}
return strcpy(v3, a3);
}
--v6;
}
while ( src != v6 );
if ( *v6 == 46 )
return strcpy(v3, a3);
}
LABEL_16:
strcpy(v3, src);
v12 = strlen(src);
return strcpy(&v3[v12], a3);
}

original_code:
void Change_Ext( const char * Src, char * Dest, const char * Ext )
{
 u_int8_t * Char_Ptr;
 int length = strlen( Src );
 if ( ! length )
 {
  strcpy( Dest, Ext );
  Msg("Change_Ext called with Src empty!");
  return;
 }
 Char_Ptr = ( (u_int8_t*)Src + length ) - 1;
 while( Char_Ptr != (u_int8_t*)Src && *Char_Ptr != '\\' && *Char_Ptr != ':' && *Char_Ptr != '.' ) Char_Ptr--;
 if( *Char_Ptr == '.' )
 {
  while( (u_int8_t*)Src != Char_Ptr )
   *Dest++ = *Src++;
  strcpy( Dest, Ext );
 }
 else
 {
  strcpy( Dest, Src );
  Dest += strlen( Src );
  strcpy( Dest, Ext );
 }
}

canonical_original_code:
void Change_Ext(char *Src, char *Dest, char *Ext)
{
 unsigned int *Char_Ptr;
 int length = strlen( Src );
 if ( ! length )
 {
  strcpy( Dest, Ext );
  Msg("Change_Ext called with Src empty!");
  return;
 }
 Char_Ptr = ( (unsigned int *)Src + length ) - 1;
 while( Char_Ptr != (unsigned int *)Src && *Char_Ptr != '\\' && *Char_Ptr != ':' && *Char_Ptr != '.' ) Char_Ptr--;
 if( *Char_Ptr == '.' )
 {
  while( (unsigned int *)Src != Char_Ptr )
   *Dest++ = *Src++;
  strcpy( Dest, Ext );
 }
 else
 {
  strcpy( Dest, Src );
  Dest += strlen( Src );
  strcpy( Dest, Ext );
 }
}

variable_types:
Src
char *

variable_types:
Dest
char *

variable_types:
Ext
char *

variable_types: length int


decompiled_code:
const char *__fastcall convert_char(char a1, char a2, const char *a3)
{
char *i; // rax

if ( a3 )
{
for ( i = strchr(a3, a1); i; i = strchr(i + 1, a1) )
*i = a2;
}
return a3;
}

canonical_decompiled_code:
const char *__fastcall func0(char a1, char a2, const char *a3)
{
char *i; // rax

if ( a3 )
{
for ( i = strchr(a3, a1); i; i = strchr(i + 1, a1) )
*i = a2;
}
return a3;
}

original_code:
char * convert_char( char from, char to, char* in )
{
 char * pch;
 if(!in)
  return in;
 pch = strchr( in, from );
 while( pch != ((void *)0) )
 {
  *pch = to;
  pch = strchr( pch+1, from );
 }
 return in;
}

canonical_original_code:
char *convert_char(char from, char to, char *in)
{
 char *pch;
 if(!in)
  return in;
 pch = strchr( in, from );
 while( pch != ((void *)0) )
 {
  *pch = to;
  pch = strchr( pch+1, from );
 }
 return in;
}

variable_types: from char

variable_types: to char

variable_types:
in
char *

variable_types:
pch
char *


decompiled_code:
char *__fastcall convert_path(char *src)
{
char v1; // di
char *v2; // rbx
char v3; // al

strncpy(&temp_4, src, 0x1F4uLL);
v1 = temp_4;
if ( temp_4 )
{
v2 = &temp_4;
do
{
v3 = 47;
if ( v1 != 92 )
v3 = tolower(v1);
*v2++ = v3;
v1 = *v2;
}
while ( *v2 );
}
return &temp_4;
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
char v1; // di
char *v2; // rbx
char v3; // al

strncpy(&temp_4, src, 0x1F4uLL);
v1 = temp_4;
if ( temp_4 )
{
v2 = &temp_4;
do
{
v3 = 47;
if ( v1 != 92 )
v3 = tolower(v1);
*v2++ = v3;
v1 = *v2;
}
while ( *v2 );
}
return &temp_4;
}

original_code:
char* convert_path( char* _str )
{
 static char temp[500];
 char * str = temp;
 strncpy( temp, _str, sizeof(temp) );
 while (*str)
 {
  if (*str == '\\')
   *str = '/';
  else
   *str = (char) tolower(*str);
  str++;
 }
 return temp;
}

canonical_original_code:
char *convert_path(char *_str)
{
 static char temp[500];
 char *str = temp;
 strncpy( temp, _str, sizeof(temp) );
 while (*str)
 {
  if (*str == '\\')
   *str = '/';
  else
   *str = (char) tolower(*str);
  str++;
 }
 return temp;
}

variable_types:
temp
char [500]

variable_types:
str
char *


strtoupper

decompiled_code:
void __fastcall strtoupper(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
*v1++ = toupper(v2);
v2 = *v1;
}
while ( *v1 );
}
}

canonical_decompiled_code:
void __fastcall func2(char *a1)
{
char *v1; // rbx
char v2; // di

v1 = a1;
v2 = *a1;
if ( v2 )
{
do
{
*v1++ = toupper(v2);
v2 = *v1;
}
while ( *v1 );
}
}

original_code:
void strtoupper(char *str)
{
 while (*str)
 {
  *str = (char) toupper(*str);
  str++;
 }
}


DebugState

decompiled_code:
void __fastcall DebugState(char *format)
{
if ( Debug && (!last_0 || strcmp(format, last_0)) )
{
last_0 = format;
DebugPrintf(format);
}
}

canonical_decompiled_code:
void __fastcall func8(char *format)
{
if ( Debug && (!last_0 || strcmp(format, last_0)) )
{
last_0 = format;
func6(format);
}
}

original_code:
void DebugState( const char * str )
{
 static const char * last;
 if ( !Debug )
  return;
 if ( last && strcmp( str, last ) == 0 )
  return;
 last = str;
 DebugPrintf( str );
}

canonical_original_code:
void DebugState(char *str)
{
 static char *last;
 if ( !Debug )
  return;
 if ( last && strcmp( str, last ) == 0 )
  return;
 last = str;
 DebugPrintf( str );
}

variable_types:
last
char *


decompiled_code:
__int64 __fastcall msg_index(unsigned int a1)
{
__int64 v1; // rax
unsigned int v2; // ecx

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( msg_indexes[v1] == a1 )
break;
if ( ++v1 == 31 )
{
_printf_chk(1LL, "ERROR: msg_index could not find type = %d\n", a1);
return 0;
}
}
return v2;
}

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

v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( msg_indexes[v1] == a1 )
break;
if ( ++v1 == 31 )
{
_printf_chk(1LL, "ERROR: msg_index could not find type = %d\n", a1);
return 0;
}
}
return v2;
}

original_code:
int msg_index( int msg_type )
{
 int i;
 for(i=0;i<31;i++)
  if (msg_indexes[i] == msg_type)
   return i;
 printf("ERROR: msg_index could not find type = %d\n",msg_type);
 return 0;
}

canonical_original_code:
int msg_index(int msg_type)
{
 int i;
 for(i=0;i<31;i++)
  if (msg_indexes[i] == msg_type)
   return i;
 printf("ERROR: msg_index could not find type = %d\n",msg_type);
 return 0;
}

variable_types: i int


decompiled_code:
const char *__fastcall msg_to_str(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 17:
result = "MSG_UPDATE";
break;
case 31:
result = "MSG_FUPDATE";
break;
case 34:
result = "MSG_HEREIAM";
break;
case 47:
result = "MSG_SHORTMINE";
break;
case 51:
result = "MSG_INIT";
break;
case 63:
result = "MSG_TEXTMSG";
break;
case 68:
result = "MSG_SHIPHIT";
break;
case 79:
result = "MSG_SHORTREGENSLOT";
break;
case 85:
result = "MSG_PRIMBULLPOSDIR";
break;
case 95:
result = "MSG_SHORTTRIGGER";
break;
case 102:
result = "MSG_SECBULLPOSDIR";
break;
case 111:
result = "MSG_SHORTTRIGVAR";
break;
case 119:
result = "MSG_SHIPDIED";
break;
case 136:
result = "MSG_DROPPICKUP";
break;
case 143:
result = "MSG_INTERPOLATE";
break;
case 153:
result = "MSG_KILLPICKUP";
break;
case 170:
result = "MSG_NETSETTINGS";
break;
case 175:
result = "MSG_BGOUPDATE";
break;
case 187:
result = "MSG_STATUS";
break;
case 223:
result = "MSG_LONGSTATUS";
break;
case 236:
result = "MSG_GROUPONLY_VERYSHORTFUPDATE";
break;
case 237:
result = "MSG_VERYSHORTDROPPICKUP";
break;
case 238:
result = "MSG_SHORTPICKUP";
break;
case 239:
result = "MSG_SETTIME";
break;
case 241:
result = "MSG_REQTIME";
break;
case 244:
result = "MSG_BIKENUM";
break;
case 245:
result = "MSG_VERYSHORTUPDATE";
break;
case 246:
result = "MSG_VERYSHORTFUPDATE";
break;
case 248:
result = "MSG_VERYSHORTINTERPOLATE";
break;
case 249:
result = "MSG_TEAMGOALS";
break;
case 250:
result = "MSG_YOUQUIT";
break;
case 252:
result = "MSG_SHORTSHIPHIT";
break;
case 253:
result = "MSG_TITANBITS";
break;
case 255:
result = "MSG_SHOCKWAVE";
break;
default:
result = "UNKNOWN";
break;
}
return result;
}

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

switch ( a1 )
{
case 17:
result = "MSG_UPDATE";
break;
case 31:
result = "MSG_FUPDATE";
break;
case 34:
result = "MSG_HEREIAM";
break;
case 47:
result = "MSG_SHORTMINE";
break;
case 51:
result = "MSG_INIT";
break;
case 63:
result = "MSG_TEXTMSG";
break;
case 68:
result = "MSG_SHIPHIT";
break;
case 79:
result = "MSG_SHORTREGENSLOT";
break;
case 85:
result = "MSG_PRIMBULLPOSDIR";
break;
case 95:
result = "MSG_SHORTTRIGGER";
break;
case 102:
result = "MSG_SECBULLPOSDIR";
break;
case 111:
result = "MSG_SHORTTRIGVAR";
break;
case 119:
result = "MSG_SHIPDIED";
break;
case 136:
result = "MSG_DROPPICKUP";
break;
case 143:
result = "MSG_INTERPOLATE";
break;
case 153:
result = "MSG_KILLPICKUP";
break;
case 170:
result = "MSG_NETSETTINGS";
break;
case 175:
result = "MSG_BGOUPDATE";
break;
case 187:
result = "MSG_STATUS";
break;
case 223:
result = "MSG_LONGSTATUS";
break;
case 236:
result = "MSG_GROUPONLY_VERYSHORTFUPDATE";
break;
case 237:
result = "MSG_VERYSHORTDROPPICKUP";
break;
case 238:
result = "MSG_SHORTPICKUP";
break;
case 239:
result = "MSG_SETTIME";
break;
case 241:
result = "MSG_REQTIME";
break;
case 244:
result = "MSG_BIKENUM";
break;
case 245:
result = "MSG_VERYSHORTUPDATE";
break;
case 246:
result = "MSG_VERYSHORTFUPDATE";
break;
case 248:
result = "MSG_VERYSHORTINTERPOLATE";
break;
case 249:
result = "MSG_TEAMGOALS";
break;
case 250:
result = "MSG_YOUQUIT";
break;
case 252:
result = "MSG_SHORTSHIPHIT";
break;
case 253:
result = "MSG_TITANBITS";
break;
case 255:
result = "MSG_SHOCKWAVE";
break;
default:
result = "UNKNOWN";
break;
}
return result;
}

original_code:
char* msg_to_str( int msg_type )
{
 switch( msg_type )
 {
 case 0xfa: return "MSG_YOUQUIT"; break;
 case 0xf4: return "MSG_BIKENUM"; break;
 case 0x22: return "MSG_HEREIAM"; break;
 case 0x33: return "MSG_INIT"; break;
 case 0xf5: return "MSG_VERYSHORTUPDATE"; break;
 case 0x11: return "MSG_UPDATE"; break;
 case 0x1f: return "MSG_FUPDATE"; break;
 case 0xf6: return "MSG_VERYSHORTFUPDATE"; break;
 case 0xec: return "MSG_GROUPONLY_VERYSHORTFUPDATE"; break;
 case 0x88: return "MSG_DROPPICKUP"; break;
 case 0xed: return "MSG_VERYSHORTDROPPICKUP"; break;
 case 0x99: return "MSG_KILLPICKUP"; break;
 case 0xf9: return "MSG_TEAMGOALS"; break;
 case 0xff: return "MSG_SHOCKWAVE"; break;
 case 0xaf: return "MSG_BGOUPDATE"; break;
 case 0x55: return "MSG_PRIMBULLPOSDIR"; break;
 case 0x66: return "MSG_SECBULLPOSDIR"; break;
 case 0xfd: return "MSG_TITANBITS"; break;
 case 0x44: return "MSG_SHIPHIT"; break;
 case 0xfc: return "MSG_SHORTSHIPHIT"; break;
 case 0x77: return "MSG_SHIPDIED"; break;
 case 0xf1: return "MSG_REQTIME"; break;
 case 0xef: return "MSG_SETTIME"; break;
 case 0xbb: return "MSG_STATUS"; break;
 case 0xaa: return "MSG_NETSETTINGS"; break;
 case 0xdf: return "MSG_LONGSTATUS"; break;
 case 0xee: return "MSG_SHORTPICKUP"; break;
 case 0x4f: return "MSG_SHORTREGENSLOT"; break;
 case 0x5f: return "MSG_SHORTTRIGGER"; break;
 case 0x6f: return "MSG_SHORTTRIGVAR"; break;
 case 0x2f: return "MSG_SHORTMINE"; break;
 case 0x3f: return "MSG_TEXTMSG"; break;
 case 0xf8: return "MSG_VERYSHORTINTERPOLATE"; break;
 case 0x8f: return "MSG_INTERPOLATE"; break;
 }
 return "UNKNOWN";
}

canonical_original_code:
char *msg_to_str(int msg_type)
{
 switch( msg_type )
 {
 case 0xfa: return "MSG_YOUQUIT"; break;
 case 0xf4: return "MSG_BIKENUM"; break;
 case 0x22: return "MSG_HEREIAM"; break;
 case 0x33: return "MSG_INIT"; break;
 case 0xf5: return "MSG_VERYSHORTUPDATE"; break;
 case 0x11: return "MSG_UPDATE"; break;
 case 0x1f: return "MSG_FUPDATE"; break;
 case 0xf6: return "MSG_VERYSHORTFUPDATE"; break;
 case 0xec: return "MSG_GROUPONLY_VERYSHORTFUPDATE"; break;
 case 0x88: return "MSG_DROPPICKUP"; break;
 case 0xed: return "MSG_VERYSHORTDROPPICKUP"; break;
 case 0x99: return "MSG_KILLPICKUP"; break;
 case 0xf9: return "MSG_TEAMGOALS"; break;
 case 0xff: return "MSG_SHOCKWAVE"; break;
 case 0xaf: return "MSG_BGOUPDATE"; break;
 case 0x55: return "MSG_PRIMBULLPOSDIR"; break;
 case 0x66: return "MSG_SECBULLPOSDIR"; break;
 case 0xfd: return "MSG_TITANBITS"; break;
 case 0x44: return "MSG_SHIPHIT"; break;
 case 0xfc: return "MSG_SHORTSHIPHIT"; break;
 case 0x77: return "MSG_SHIPDIED"; break;
 case 0xf1: return "MSG_REQTIME"; break;
 case 0xef: return "MSG_SETTIME"; break;
 case 0xbb: return "MSG_STATUS"; break;
 case 0xaa: return "MSG_NETSETTINGS"; break;
 case 0xdf: return "MSG_LONGSTATUS"; break;
 case 0xee: return "MSG_SHORTPICKUP"; break;
 case 0x4f: return "MSG_SHORTREGENSLOT"; break;
 case 0x5f: return "MSG_SHORTTRIGGER"; break;
 case 0x6f: return "MSG_SHORTTRIGVAR"; break;
 case 0x2f: return "MSG_SHORTMINE"; break;
 case 0x3f: return "MSG_TEXTMSG"; break;
 case 0xf8: return "MSG_VERYSHORTINTERPOLATE"; break;
 case 0x8f: return "MSG_INTERPOLATE"; break;
 }
 return "UNKNOWN";
}


receive

decompiled_code:
unsigned __int64 __fastcall receive(__int64 a1)
{
const void *v1; // rbp
const char *v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-20h]

v4 = __readfsqword(0x28u);
v1 = *(const void **)(a1 + 8);
v2 = msg_to_str((int)v1);
_printf_chk(1LL, "%s > %s %p\n", v2, *(const char **)(a1 + 16), v1);
return v4 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1)
{
const void *v1; // rbp
const char *v2; // rax
unsigned __int64 v4; // [rsp+8h] [rbp-20h]

v4 = __readfsqword(0x28u);
v1 = *(const void **)(a1 + 8);
v2 = func1((int)v1);
_printf_chk(1LL, "%s > %s %p\n", v2, *(const char **)(a1 + 16), v1);
return v4 - __readfsqword(0x28u);
}

original_code:
void receive(network_packet_t * packet)
{
 printf("%s > %s %p\n", msg_to_str(packet->data), packet->from->name, (unsigned char *)packet->data);
}

canonical_original_code:
void receive(struct network_packet_t *packet)
{
 printf("%s > %s %p\n", msg_to_str(packet->data), packet->from->name, (unsigned char *)packet->data);
}

variable_types: struct network_packet_t { int size; void *data; struct _network_player_t { char name[15]; char ip[16]; int port; unsigned long ping; unsigned long packet_loss; unsigned long packets_lost; unsigned long bw_in; unsigned long bw_out; struct _network_player_t *prev; struct _network_player_t *next; void *data; } *from; } *

user_defined_types: struct network_packet_t { int size; void *data; struct _network_player_t *from; }


decompiled_code:
unsigned __int64 randomize_msg_data()
{
int v0; // eax
char *v1; // rbx
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
v0 = rand();
srand(v0 + (v0 == -1));
v1 = &msg_data;
do
*v1++ = rand() % 255;
while ( v1 != (char *)(unsigned int)((_DWORD)&msg_data + 1000) );
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func3()
{
int v0; // eax
char *v1; // rbx
unsigned __int64 v3; // [rsp+8h] [rbp-20h]

v3 = __readfsqword(0x28u);
v0 = rand();
srand(v0 + (v0 == -1));
v1 = &msg_data;
do
*v1++ = rand() % 255;
while ( v1 != (char *)(unsigned int)((_DWORD)&msg_data + 1000) );
return v3 - __readfsqword(0x28u);
}

original_code:
void randomize_msg_data( void )
{
 int n;
 srand(rand()%(0x7fffffff * 2U + 1U));
 for(n=0;n<sizeof(msg_data);n++)
  msg_data[n] = rand()%(0x7f * 2 + 1);
}

canonical_original_code:
void randomize_msg_data()
{
 int n;
 srand(rand()%(0x7fffffff * 2U + 1U));
 for(n=0;n<sizeof(msg_data);n++)
  msg_data[n] = rand()%(0x7f * 2 + 1);
}

variable_types: n int


decompiled_code:
unsigned __int64 __fastcall send_msg_by_index(int a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
msg_data[1] = my_id;
msg_data[0] = msg_id[a1];
network_broadcast(msg_data, msg_size[a1], 0LL, 1LL);
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(int a1)
{
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
msg_data[1] = my_id;
msg_data[0] = msg_id[a1];
network_broadcast(msg_data, msg_size[a1], 0LL, 1LL);
return v2 - __readfsqword(0x28u);
}

original_code:
void send_msg_by_index( int i )
{
 msg_data[1] = my_id;
 msg_data[0] = msg_id[i];
 network_broadcast( msg_data, msg_size[i], 0, 1 );
}

canonical_original_code:
void send_msg_by_index(int i)
{
 msg_data[1] = my_id;
 msg_data[0] = msg_id[i];
 network_broadcast( msg_data, msg_size[i], 0, 1 );
}


decompiled_code:
unsigned __int64 __fastcall send_msg_by_type(unsigned int a1)
{
int v1; // eax
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
v1 = msg_index(a1);
send_msg_by_index(v1);
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(unsigned int a1)
{
int v1; // eax
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
v1 = func0(a1);
func4(v1);
return v3 - __readfsqword(0x28u);
}

original_code: void send_msg_by_type( int t ) { send_msg_by_index(msg_index(t)); }

canonical_original_code: void send_msg_by_type(int t) { send_msg_by_index(msg_index(t)); }

variable_types: t int


init

decompiled_code:
unsigned __int64 init()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
_printf_chk(1LL, "my_id = %d\n", my_id);
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func6()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
_printf_chk(1LL, "my_id = %d\n", my_id);
return v1 - __readfsqword(0x28u);
}

original_code: void init() { printf("my_id = %d\n",my_id); }


loop

decompiled_code:
unsigned __int64 loop()
{
int v0; // edi
int v1; // eax
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
randomize_msg_data();
send_msg_by_type(0xBBu);
_printf_chk(1LL, "Sending message %s (%d) size=%d\n", msg_name[i_0], (unsigned __int8)msg_id[i_0], msg_size[i_0]);
v0 = i_0;
if ( msg_id[i_0] == 63 )
msg_data[514] = (unsigned __int8)msg_data[514] % 0x11u;
send_msg_by_index(v0);
v1 = i_0 + 1;
if ( i_0 + 1 > 30 )
v1 = 0;
i_0 = v1;
return v3 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func7()
{
int v0; // edi
int v1; // eax
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

v3 = __readfsqword(0x28u);
func3();
func5(0xBBu);
_printf_chk(1LL, "Sending message %s (%d) size=%d\n", msg_name[i_0], (unsigned __int8)msg_id[i_0], msg_size[i_0]);
v0 = i_0;
if ( msg_id[i_0] == 63 )
msg_data[514] = (unsigned __int8)msg_data[514] % 0x11u;
func4(v0);
v1 = i_0 + 1;
if ( i_0 + 1 > 30 )
v1 = 0;
i_0 = v1;
return v3 - __readfsqword(0x28u);
}

original_code:
void loop()
{
 static int i = 0;
 randomize_msg_data();
 send_msg_by_type(0xbb);
 printf("Sending message %s (%d) size=%d\n",(char*)msg_name[i],msg_id[i],msg_size[i]);
 if(msg_id[i] == 0x3f) msg_data[2+512] %= 17;
 send_msg_by_index(i);
 if( ++i >= 31 ) i = 0;
}

canonical_original_code:
void loop()
{
 static int i = 0;
 randomize_msg_data();
 send_msg_by_type(0xbb);
 printf("Sending message %s (%d) size=%d\n",(char *)msg_name[i],msg_id[i],msg_size[i]);
 if(msg_id[i] == 0x3f) msg_data[2+512] %= 17;
 send_msg_by_index(i);
 if( ++i >= 31 ) i = 0;
}


usage

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
if ( a1 )
puts(a1);
puts("Usage: ./client <player-name> [<local-port> [<remote-address> [<remote-port>]]");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
if ( a1 )
puts(a1);
puts("Usage: ./client <player-name> [<local-port> [<remote-address> [<remote-port>]]");
return 1LL;
}

original_code:
int usage( char* str )
{
 if(str != ((void *)0))
  puts(str);
 printf( "Usage: ./client <player-name> [<local-port> [<remote-address> [<remote-port>]]\n" );
 return 1;
}

canonical_original_code:
int usage(char *str)
{
 if(str != ((void *)0))
  puts(str);
 printf( "Usage: ./client <player-name> [<local-port> [<remote-address> [<remote-port>]]\n" );
 return 1;
}