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 >> 6] & (1LL << i)) != 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 >> 6] & (1LL << i)) != 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; }


repo: FlorianHe/spacewar

decompiled_code:
int __fastcall graph_avance(__int64 *a1, unsigned int *a2)
{
__int64 v2; // rbx
__int64 v3; // r8
__int64 v4; // rcx
__int64 v5; // rdx
int result; // eax
size_t v7; // rax
size_t v8; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
v3 = a2[1];
memset(savedregs, 0, 0xF8uLL);
v4 = *a2;
*(_WORD *)&savedregs[252] = 0;
v5 = a2[5];
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Ava %d %d %d\n", v5, v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v7 = strlen(savedregs);
write(1, savedregs, v7);
v8 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v8);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, unsigned int *a2)
{
__int64 v2; // rbx
__int64 v3; // r8
__int64 v4; // rcx
__int64 v5; // rdx
int result; // eax
size_t v7; // rax
size_t v8; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
v3 = a2[1];
memset(savedregs, 0, 0xF8uLL);
v4 = *a2;
*(_WORD *)&savedregs[252] = 0;
v5 = a2[5];
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Ava %d %d %d\n", v5, v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v7 = strlen(savedregs);
write(1, savedregs, v7);
v8 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v8);
}
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: 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:
perso
struct s_player *

variable_types:
buff
char [254]

return_type: void

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


gravite

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

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
while ( 1 )
{
result = *(unsigned int *)(i + 24);
if ( (_DWORD)result )
break;
i = *(_QWORD *)(i + 40);
if ( !i )
return result;
}
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) )
{
while ( 1 )
{
result = *(unsigned int *)(i + 24);
if ( (_DWORD)result )
break;
i = *(_QWORD *)(i + 40);
if ( !i )
return result;
}
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;
    }
}

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


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; // er12

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; // er12

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

return_type: int


checking

decompiled_code:
void __fastcall checking(int *a1, int a2, __int64 a3)
{
const char **v4; // rbp
int i; // ebx
int v6; // eax
unsigned __int8 *v7; // rax
const char *v8; // rdx
const char *v9; // rdi

if ( a2 != 1 )
{
v4 = (const char **)(a3 + 16);
for ( i = 2; ; i = v6 )
{
v7 = (unsigned __int8 *)*(v4 - 1);
v8 = (const char *)*v7;
if ( (_DWORD)v8 != 45 )
{
LABEL_3:
error((int)"Usage: ./Spacewar [-n player_number -g game_number -p port]\n", a2, v8);
goto LABEL_4;
}
if ( v7[1] == 110 && !v7[2] && *a1 == 2 && a2 > i )
break;
if ( v7[1] == 103 && !v7[2] && a1[1] == 5 && a2 > i )
{
a1[1] = atoi(*v4);
LABEL_4:
v6 = i + 2;
v4 += 2;
if ( a2 == i + 1 )
return;
continue;
}
if ( v7[1] != 112 || v7[2] || a1[2] != 4242 || a2 <= i )
goto LABEL_3;
v9 = *v4;
v4 += 2;
a1[2] = atoi(v9);
v6 = i + 2;
if ( a2 == i + 1 )
return;
}
*a1 = atoi(*v4);
goto LABEL_4;
}
}

canonical_decompiled_code:
void __fastcall func0(int *a1, int a2, __int64 a3)
{
const char **v4; // rbp
int i; // ebx
int v6; // eax
unsigned __int8 *v7; // rax
const char *v8; // rdx
const char *v9; // rdi

if ( a2 != 1 )
{
v4 = (const char **)(a3 + 16);
for ( i = 2; ; i = v6 )
{
v7 = (unsigned __int8 *)*(v4 - 1);
v8 = (const char *)*v7;
if ( (_DWORD)v8 != 45 )
{
LABEL_3:
error((int)"Usage: ./Spacewar [-n player_number -g game_number -p port]\n", a2, v8);
goto LABEL_4;
}
if ( v7[1] == 110 && !v7[2] && *a1 == 2 && a2 > i )
break;
if ( v7[1] == 103 && !v7[2] && a1[1] == 5 && a2 > i )
{
a1[1] = atoi(*v4);
LABEL_4:
v6 = i + 2;
v4 += 2;
if ( a2 == i + 1 )
return;
continue;
}
if ( v7[1] != 112 || v7[2] || a1[2] != 4242 || a2 <= i )
goto LABEL_3;
v9 = *v4;
v4 += 2;
a1[2] = atoi(v9);
v6 = i + 2;
if ( a2 == i + 1 )
return;
}
*a1 = atoi(*v4);
goto LABEL_4;
}
}

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 *[]

variable_types: i int

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


decompiled_code:
int __fastcall graph_gauche(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rcx
__int64 v4; // rdx
int result; // eax
size_t v6; // rax
size_t v7; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
memset(savedregs, 0, 0xF8uLL);
v3 = *(unsigned int *)(a2 + 16);
*(_WORD *)&savedregs[252] = 0;
v4 = *(unsigned int *)(a2 + 20);
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Gau %d %d\n", v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v6 = strlen(savedregs);
write(1, savedregs, v6);
v7 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v7);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rcx
__int64 v4; // rdx
int result; // eax
size_t v6; // rax
size_t v7; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
memset(savedregs, 0, 0xF8uLL);
v3 = *(unsigned int *)(a2 + 16);
*(_WORD *)&savedregs[252] = 0;
v4 = *(unsigned int *)(a2 + 20);
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Gau %d %d\n", v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v6 = strlen(savedregs);
write(1, savedregs, v6);
v7 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v7);
}
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;
    }
}

user_defined_types: struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *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: struct s_missile { int x; int y; int rotation; int nb_tir; int time; int time_grav; struct s_missile *next; } *


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
__int64 v3; // rcx
__int64 v4; // rdx
int result; // eax
size_t v6; // rax
size_t v7; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
memset(savedregs, 0, 0xF8uLL);
v3 = *(unsigned int *)(a2 + 12);
*(_WORD *)&savedregs[252] = 0;
v4 = *(unsigned int *)(a2 + 20);
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Ess %d %d\n", v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v6 = strlen(savedregs);
write(1, savedregs, v6);
v7 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v7);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 *a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v3; // rcx
__int64 v4; // rdx
int result; // eax
size_t v6; // rax
size_t v7; // rax
_BYTE savedregs[280]; // [rsp+0h] [rbp+0h] BYREF

v2 = *a1;
memset(savedregs, 0, 0xF8uLL);
v3 = *(unsigned int *)(a2 + 12);
*(_WORD *)&savedregs[252] = 0;
v4 = *(unsigned int *)(a2 + 20);
*(_DWORD *)&savedregs[248] = 0;
for ( result = sprintf(savedregs, "Ess %d %d\n", v4, v3); v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
result = *(_DWORD *)(v2 + 24);
if ( result )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return result;
}
v6 = strlen(savedregs);
write(1, savedregs, v6);
v7 = strlen(savedregs);
result = write(*(_DWORD *)(v2 + 24), savedregs, v7);
}
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;
    }
}


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
__int64 v3; // rdx
int v4; // ebp
size_t v5; // rax
char v7[248]; // [rsp+0h] [rbp-128h] BYREF
int v8; // [rsp+F8h] [rbp-30h]
__int16 v9; // [rsp+FCh] [rbp-2Ch]

v2 = *a1;
memset(v7, 0, sizeof(v7));
v9 = 0;
v3 = *(unsigned int *)(a2 + 20);
v8 = 0;
sprintf(v7, "Mor %d\n", v3);
for ( ; v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
v4 = *(_DWORD *)(v2 + 24);
if ( v4 )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return printf("Le joueur %d est mort\n", *(unsigned int *)(a2 + 20));
}
v5 = strlen(v7);
write(v4, v7, 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
__int64 v3; // rdx
int v4; // ebp
size_t v5; // rax
char v7[248]; // [rsp+0h] [rbp-128h] BYREF
int v8; // [rsp+F8h] [rbp-30h]
__int16 v9; // [rsp+FCh] [rbp-2Ch]

v2 = *a1;
memset(v7, 0, sizeof(v7));
v9 = 0;
v3 = *(unsigned int *)(a2 + 20);
v8 = 0;
sprintf(v7, "Mor %d\n", v3);
for ( ; v2; v2 = *(_QWORD *)(v2 + 40) )
{
while ( 1 )
{
v4 = *(_DWORD *)(v2 + 24);
if ( v4 )
break;
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return printf("Le joueur %d est mort\n", *(unsigned int *)(a2 + 20));
}
v5 = strlen(v7);
write(v4, v7, 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 v5; // ebp
size_t v6; // rax
char v8[248]; // [rsp+0h] [rbp-128h] BYREF
int v9; // [rsp+F8h] [rbp-30h]
__int16 v10; // [rsp+FCh] [rbp-2Ch]

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
if ( *(_DWORD *)(i + 24) == a2 )
v2 = *(_DWORD *)(i + 20);
}
memset(v8, 0, sizeof(v8));
v10 = 0;
v9 = 0;
sprintf(v8, "Mor %d\n", v2);
for ( j = *a1; j; j = *(_QWORD *)(j + 40) )
{
while ( 1 )
{
v5 = *(_DWORD *)(j + 24);
if ( v5 )
break;
j = *(_QWORD *)(j + 40);
if ( !j )
return printf(aLeJoueurDSEstS, v2);
}
v6 = strlen(v8);
write(v5, v8, v6);
}
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 v5; // ebp
size_t v6; // rax
char v8[248]; // [rsp+0h] [rbp-128h] BYREF
int v9; // [rsp+F8h] [rbp-30h]
__int16 v10; // [rsp+FCh] [rbp-2Ch]

for ( i = *a1; i; i = *(_QWORD *)(i + 40) )
{
if ( *(_DWORD *)(i + 24) == a2 )
v2 = *(_DWORD *)(i + 20);
}
memset(v8, 0, sizeof(v8));
v10 = 0;
v9 = 0;
sprintf(v8, "Mor %d\n", v2);
for ( j = *a1; j; j = *(_QWORD *)(j + 40) )
{
while ( 1 )
{
v5 = *(_DWORD *)(j + 24);
if ( v5 )
break;
j = *(_QWORD *)(j + 40);
if ( !j )
return printf(aLeJoueurDSEstS, v2);
}
v6 = strlen(v8);
write(v5, v8, v6);
}
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)
{
__int16 v3; // di
__int16 v4; // ax
socklen_t v5; // edx
struct sockaddr v7; // [rsp+0h] [rbp-18h] BYREF

v3 = *(_WORD *)(a2 + 8);
v7.sa_family = 2;
v4 = _bswap_16(v3);
*(_DWORD *)&v7.sa_data[2] = 0;
*(_WORD *)v7.sa_data = v4;
if ( bind(fd, &v7, v5) == -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)
{
__int16 v3; // di
__int16 v4; // ax
socklen_t v5; // edx
struct sockaddr v7; // [rsp+0h] [rbp-18h] BYREF

v3 = *(_WORD *)(a2 + 8);
v7.sa_family = 2;
v4 = func0(v3);
*(_DWORD *)&v7.sa_data[2] = 0;
*(_WORD *)v7.sa_data = v4;
if ( bind(fd, &v7, v5) == -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; }


decompiled_code:
void *__fastcall hash_init(__int64 a1, int a2)
{
size_t v3; // rdi
int v4; // eax
int v5; // edx
int v6; // ecx
void *result; // rax

if ( a2 )
{
*(_QWORD *)(a1 + 8) = 2LL;
*(_QWORD *)(a1 + 16) = 0x10000001DLL;
v3 = 2LL;
if ( a2 <= 2 )
goto LABEL_6;
}
else
{
*(_DWORD *)(a1 + 12) = 0;
a2 = 16;
}
v4 = 28;
v5 = 1;
LODWORD(v3) = 2;
do
{
LODWORD(v3) = 2 * v3;
v6 = v4;
v5 = 2 * v5 + 1;
--v4;
}
while ( (int)v3 < a2 );
*(_DWORD *)(a1 + 20) = v5;
*(_DWORD *)(a1 + 16) = v6;
*(_DWORD *)(a1 + 8) = v3;
v3 = (int)v3;
LABEL_6:
result = calloc(v3, 8uLL);
*(_QWORD *)a1 = result;
return result;
}

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; // r8
__int64 result; // rax
int i; // ebp
_QWORD *v7; // r14
void *v8; // r15
size_t v9; // rax
void *v10; // r13
size_t v11; // rax
_QWORD *v12; // rax
int v13; // [rsp+Ch] [rbp-3Ch]

v4 = hash_lookup((_QWORD *)a1, a2);
result = 0LL;
if ( !v4 )
{
for ( i = *(_DWORD *)(a1 + 12); (double)i >= (double)*(int *)(a1 + 8) * 0.5; i = *(_DWORD *)(a1 + 12) )
rebuild_table(a1);
v13 = 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 * v13);
v7[2] = *v12;
*v12 = v7;
result = 1LL;
*(_DWORD *)(a1 + 12) = i + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2, const char *a3)
{
__int64 **v4; // r8
__int64 result; // rax
int i; // ebp
_QWORD *v7; // r14
void *v8; // r15
size_t v9; // rax
void *v10; // r13
size_t v11; // rax
_QWORD *v12; // rax
int v13; // [rsp+Ch] [rbp-3Ch]

v4 = hash_lookup((_QWORD *)a1, a2);
result = 0LL;
if ( !v4 )
{
for ( i = *(_DWORD *)(a1 + 12); (double)i >= (double)*(int *)(a1 + 8) * 0.5; i = *(_DWORD *)(a1 + 12) )
func3(a1);
v13 = 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 * v13);
v7[2] = *v12;
*v12 = v7;
result = 1LL;
*(_DWORD *)(a1 + 12) = i + 1;
}
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
__int64 v2; // r9

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

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

v1 = COERCE_FLOAT(alos(a1));
sprintf(buf_0, "%u slots, %u entries, and %1.2f ALOS", *(unsigned int *)(v2 + 8), *(unsigned int *)(v2 + 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; // er8
_BOOL8 result; // rax

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

canonical_decompiled_code:
_BOOL8 func5()
{
_BOOL4 v0; // er8
_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; // er8

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

canonical_decompiled_code:
_BOOL8 func6()
{
_BOOL4 v0; // er8

if ( func5() )
return 0LL;
if ( !func1() )
v0 = !func4();
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:
__int64 next()
{
char v0; // bl
const unsigned __int16 **v1; // r12
unsigned __int16 v2; // ax
int v3; // er13
__int64 v4; // rbp
__int64 result; // rax
__int64 v6; // rbx
__int64 v7; // rax
const unsigned __int16 *v8; // rcx
char v9; // di
__int64 v10; // rdx
__int64 v11; // rsi
size_t v12; // rax
char v13; // al
int v14; // ebx
int v15; // edx
char v16; // al
int v17; // ebx
char src[2]; // [rsp+Eh] [rbp-2Ah] BYREF

*(_WORD *)src = 0;
v0 = chs[pos];
*(_WORD *)src = (unsigned __int8)v0;
v1 = _ctype_b_loc();
while ( 1 )
{
v2 = (*v1)[v0];
if ( (v2 & 0x2000) == 0 )
break;
if ( !v0 )
return 0LL;
memset(token, 0, (size_t)&unk_400000);
tpos = 0;
v0 = chs[++pos];
src[0] = v0;
}
if ( !v0 )
return 0LL;
v3 = pos;
LODWORD(v4) = pos + 1;
if ( v0 == 34 )
{
memset(token, 0, (size_t)&unk_400000);
strcpy(token, src);
pos = v4;
v4 = (int)v4;
v13 = chs[(int)v4];
tpos = 1;
src[0] = v13;
if ( v13 == 34 )
{
v17 = 2;
}
else
{
v14 = 1 - v3;
do
{
v3 = v4;
strcat(token, src);
v15 = v14 + v4++;
pos = v4;
v16 = chs[v4];
tpos = v15;
src[0] = v16;
}
while ( v16 != 34 );
v17 = v15 + 1;
}
LODWORD(v4) = v3 + 2;
src[0] = 34;
strcat(token, src);
tpos = v17;
pos = v3 + 2;
}
else
{
if ( (v2 & 0x400) == 0 )
{
if ( v0 == 61 )
{
++pos;
next();
LODWORD(v4) = pos;
}
else
{
strcat(token, src);
++tpos;
pos = v4;
}
goto LABEL_10;
}
LODWORD(v6) = pos + 2;
memset(token, 0, (size_t)&unk_400000);
v6 = (int)v6;
strcpy(token, src);
pos = v4;
v7 = chs[(int)v4];
tpos = 1;
src[0] = v7;
if ( (_BYTE)v7 )
{
while ( 1 )
{
v8 = *v1;
LODWORD(v4) = v6 - 1;
if ( ((*v1)[v7] & 0x400) == 0 )
break;
LODWORD(v4) = v6;
strcat(token, src);
v7 = chs[v6];
pos = v6++;
++tpos;
src[0] = v7;
if ( !(_BYTE)v7 )
goto LABEL_10;
}
LOBYTE(v7) = src[0];
if ( (v8[src[0]] & 0x2000) == 0 )
{
LABEL_23:
if ( (_BYTE)v7 == 61 )
{
LODWORD(v4) = v4 + 1;
v12 = strlen(token);
++tpos;
*(_WORD *)&token[v12] = 61;
pos = v4;
}
goto LABEL_10;
}
}
else
{
v8 = *v1;
if ( (**v1 & 0x2000) == 0 )
goto LABEL_10;
}
v9 = 0;
v10 = (int)v4 + 1;
while ( (_BYTE)v7 )
{
v11 = chs[v10];
LODWORD(v4) = v10;
v9 = 1;
++v10;
LOBYTE(v7) = v11;
if ( (v8[v11] & 0x2000) == 0 )
{
pos = v4;
src[0] = v11;
goto LABEL_23;
}
}
LODWORD(v4) = pos;
if ( v9 )
{
pos = v10 - 1;
LODWORD(v4) = v10 - 1;
}
}
LABEL_10:
if ( (_DWORD)v4 == (_DWORD)&unk_3FFFFF )
return 0LL;
result = 1LL;
if ( !token[0] )
return 0LL;
return result;
}

canonical_decompiled_code:
__int64 func10()
{
char v0; // bl
const unsigned __int16 **v1; // r12
unsigned __int16 v2; // ax
int v3; // er13
__int64 v4; // rbp
__int64 result; // rax
__int64 v6; // rbx
__int64 v7; // rax
const unsigned __int16 *v8; // rcx
char v9; // di
__int64 v10; // rdx
__int64 v11; // rsi
size_t v12; // rax
char v13; // al
int v14; // ebx
int v15; // edx
char v16; // al
int v17; // ebx
char src[2]; // [rsp+Eh] [rbp-2Ah] BYREF

*(_WORD *)src = 0;
v0 = chs[pos];
*(_WORD *)src = (unsigned __int8)v0;
v1 = _ctype_b_loc();
while ( 1 )
{
v2 = (*v1)[v0];
if ( (v2 & 0x2000) == 0 )
break;
if ( !v0 )
return 0LL;
memset(token, 0, (size_t)&unk_400000);
tpos = 0;
v0 = chs[++pos];
src[0] = v0;
}
if ( !v0 )
return 0LL;
v3 = pos;
LODWORD(v4) = pos + 1;
if ( v0 == 34 )
{
memset(token, 0, (size_t)&unk_400000);
strcpy(token, src);
pos = v4;
v4 = (int)v4;
v13 = chs[(int)v4];
tpos = 1;
src[0] = v13;
if ( v13 == 34 )
{
v17 = 2;
}
else
{
v14 = 1 - v3;
do
{
v3 = v4;
strcat(token, src);
v15 = v14 + v4++;
pos = v4;
v16 = chs[v4];
tpos = v15;
src[0] = v16;
}
while ( v16 != 34 );
v17 = v15 + 1;
}
LODWORD(v4) = v3 + 2;
src[0] = 34;
strcat(token, src);
tpos = v17;
pos = v3 + 2;
}
else
{
if ( (v2 & 0x400) == 0 )
{
if ( v0 == 61 )
{
++pos;
func10();
LODWORD(v4) = pos;
}
else
{
strcat(token, src);
++tpos;
pos = v4;
}
goto LABEL_10;
}
LODWORD(v6) = pos + 2;
memset(token, 0, (size_t)&unk_400000);
v6 = (int)v6;
strcpy(token, src);
pos = v4;
v7 = chs[(int)v4];
tpos = 1;
src[0] = v7;
if ( (_BYTE)v7 )
{
while ( 1 )
{
v8 = *v1;
LODWORD(v4) = v6 - 1;
if ( ((*v1)[v7] & 0x400) == 0 )
break;
LODWORD(v4) = v6;
strcat(token, src);
v7 = chs[v6];
pos = v6++;
++tpos;
src[0] = v7;
if ( !(_BYTE)v7 )
goto LABEL_10;
}
LOBYTE(v7) = src[0];
if ( (v8[src[0]] & 0x2000) == 0 )
{
LABEL_23:
if ( (_BYTE)v7 == 61 )
{
LODWORD(v4) = v4 + 1;
v12 = strlen(token);
++tpos;
*(_WORD *)&token[v12] = 61;
pos = v4;
}
goto LABEL_10;
}
}
else
{
v8 = *v1;
if ( (**v1 & 0x2000) == 0 )
goto LABEL_10;
}
v9 = 0;
v10 = (int)v4 + 1;
while ( (_BYTE)v7 )
{
v11 = chs[v10];
LODWORD(v4) = v10;
v9 = 1;
++v10;
LOBYTE(v7) = v11;
if ( (v8[v11] & 0x2000) == 0 )
{
pos = v4;
src[0] = v11;
goto LABEL_23;
}
}
LODWORD(v4) = pos;
if ( v9 )
{
pos = v10 - 1;
LODWORD(v4) = v10 - 1;
}
}
LABEL_10:
if ( (_DWORD)v4 == (_DWORD)&unk_3FFFFF )
return 0LL;
result = 1LL;
if ( !token[0] )
return 0LL;
return result;
}

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; // eax
__int64 v7; // rbx
char *v8; // rax
char *v9; // r15
size_t v10; // rdi

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

canonical_decompiled_code:
char *__fastcall func6(void *ptr, size_t size, __int64 a3, int a4)
{
int v6; // eax
__int64 v7; // rbx
char *v8; // rax
char *v9; // r15
size_t v10; // rdi

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

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

return_type: void *


decompiled_code:
void *XMem_Init()
{
MemUsed = 0LL;
memset(BlockUsed, 0, sizeof(BlockUsed));
memset(BlockPnts, 0, sizeof(BlockPnts));
return memset(BlockSize, 0, sizeof(BlockSize));
}

canonical_decompiled_code:
void *func0()
{
MemUsed = 0LL;
memset(BlockUsed, 0, sizeof(BlockUsed));
memset(BlockPnts, 0, sizeof(BlockPnts));
return memset(BlockSize, 0, sizeof(BlockSize));
}

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 result; // rax

for ( result = 0LL; result != 0x4000; ++result )
{
if ( !BlockUsed[result] )
{
result = (unsigned int)result;
++BlocksUsed;
return result;
}
}
return 0xFFFFFFFFLL;
}

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

for ( result = 0LL; result != 0x4000; ++result )
{
if ( !BlockUsed[result] )
{
result = (unsigned int)result;
++BlocksUsed;
return result;
}
}
return 0xFFFFFFFFLL;
}

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 result; // rax

for ( result = 0LL; result != 0x4000; ++result )
{
if ( BlockUsed[result] && BlockPnts[result] == a1 )
return (unsigned int)result;
}
return 0xFFFFFFFFLL;
}

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

for ( result = 0LL; result != 0x4000; ++result )
{
if ( BlockUsed[result] && BlockPnts[result] == a1 )
return (unsigned int)result;
}
return 0xFFFFFFFFLL;
}

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; // r14
int v6; // eax
__int64 v7; // rdx

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

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

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

if ( ptr )
{
v4 = XMem_FindSame((__int64)ptr);
if ( v4 != -1 )
{
free(ptr);
--BlocksUsed;
v5 = BlockSize[v4];
BlockUsed[v4] = 0;
BlockPnts[v4] = 0LL;
MemUsed -= v5;
BlockInFile[v4] = 0LL;
BlockInLine[v4] = 0;
BlockSize[v4] = 0LL;
return;
}
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);
}
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 func5(void *ptr, const char *a2, unsigned int a3)
{
int v4; // ebx
__int64 v5; // rdx

if ( ptr )
{
v4 = func2((__int64)ptr);
if ( v4 != -1 )
{
free(ptr);
--BlocksUsed;
v5 = BlockSize[v4];
BlockUsed[v4] = 0;
BlockPnts[v4] = 0LL;
MemUsed -= v5;
BlockInFile[v4] = 0LL;
BlockInLine[v4] = 0;
BlockSize[v4] = 0LL;
return;
}
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);
}
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 v0; // rdx
__int64 i; // rbx
__int64 v2; // rcx
const char *v3; // rdx
__int64 v4; // rsi

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

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rdx
__int64 i; // rbx
__int64 v2; // rcx
const char *v3; // rdx
__int64 v4; // rsi

v0 = (unsigned int)BlocksUsed;
if ( BlocksUsed )
{
for ( i = 0LL; i != 0x4000; ++i )
{
while ( !BlockUsed[i] )
{
if ( ++i == 0x4000 )
goto LABEL_6;
}
v2 = (unsigned int)BlockInLine[i];
v3 = (const char *)BlockInFile[i];
v4 = BlockSize[i];
DebugPrintf("MEM: Block size %d allocated in %s line %d but not freed\n", v4, v3, v2);
}
LABEL_6:
v0 = (unsigned int)BlocksUsed;
}
DebugPrintf("MEM: MemUsed = %d BlocksUsed = %d\n", MemUsed, v0);
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(void *src, void *dest)
{
size_t v3; // rax
const char *v4; // rcx
size_t v5; // rdx
const char *v6; // rsi
char *result; // rax

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

canonical_decompiled_code:
char *__fastcall func3(void *src, void *dest)
{
size_t v3; // rax
const char *v4; // rcx
size_t v5; // rdx
const char *v6; // rsi
char *result; // rax

v3 = strlen((const char *)src);
v4 = (char *)src + v3 - 1;
v5 = v3;
v6 = v4;
if ( src == v4 )
return (char *)memcpy(dest, src, v5 + 1);
while ( 1 )
{
result = (char *)*(unsigned __int8 *)v6;
if ( (_BYTE)result == 58 || (_BYTE)result == 92 )
break;
if ( src == --v6 )
return (char *)memcpy(dest, src, v5 + 1);
}
if ( src == v6 )
return (char *)memcpy(dest, src, v5 + 1);
if ( v4 != v6 )
return strcpy((char *)dest, v6 + 1);
*(_BYTE *)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], (unsigned int)(0x4000 - v1), format, arg);
byte_875F = 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], (unsigned int)(0x4000 - v1), format, arg);
byte_875F = 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_475F = 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_475F = 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(void *src, void *dest, const char *a3)
{
char *v3; // r14
size_t v5; // rax
size_t v6; // rbx
__int64 v7; // rsi
_BYTE *v8; // rax
int v9; // ecx
__int64 v10; // rax
__int64 v11; // rdx

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

canonical_decompiled_code:
char *__fastcall func10(void *src, void *dest, const char *a3)
{
char *v3; // r14
size_t v5; // rax
size_t v6; // rbx
__int64 v7; // rsi
_BYTE *v8; // rax
int v9; // ecx
__int64 v10; // rax
__int64 v11; // rdx

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

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)
{
int v1; // edi
char *v2; // rbx
char v3; // al

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

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

strncpy(&temp_4, src, 0x1F4uLL);
v1 = temp_4;
if ( temp_4 )
{
v2 = &temp_4;
do
{
v3 = 47;
if ( (_BYTE)v1 != 92 )
v3 = tolower(v1);
*v2 = v3;
v1 = *++v2;
}
while ( (_BYTE)v1 );
}
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)
{
_BYTE *v1; // rbx
int v2; // edi

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

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

v1 = a1;
v2 = *a1;
if ( (_BYTE)v2 )
{
do
{
*v1++ = toupper(v2);
v2 = (char)*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; // er8

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; // er8

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)
{
__int64 v1; // rdi
const char *result; // rax

v1 = (unsigned int)(a1 - 17);
result = "UNKNOWN";
if ( (unsigned int)v1 <= 0xEE )
result = (&CSWTCH_35)[v1];
return result;
}

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

v1 = (unsigned int)(a1 - 17);
result = "UNKNOWN";
if ( (unsigned int)v1 <= 0xEE )
result = (&CSWTCH_35)[v1];
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:
__int64 __fastcall receive(__int64 a1)
{
const void *v1; // rbp
const char *v2; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
const void *v1; // rbp
const char *v2; // rdx

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

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()
{
char *v0; // rbx
int v1; // eax
unsigned __int64 v3; // [rsp+8h] [rbp-10h]

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

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

v0 = &msg_data;
v3 = __readfsqword(0x28u);
v1 = rand();
srand(v1 + (v1 == -1));
do
*v0++ = rand() % 255;
while ( v0 != &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:
__int64 __fastcall send_msg_by_index(int a1)
{
msg_data[1] = my_id;
msg_data[0] = msg_id[a1];
return network_broadcast(msg_data, msg_size[a1], 0LL, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
msg_data[1] = my_id;
msg_data[0] = msg_id[a1];
return network_broadcast(msg_data, msg_size[a1], 0LL, 1LL);
}

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:
__int64 __fastcall send_msg_by_type(unsigned int a1)
{
int v1; // edi

v1 = msg_index(a1);
return send_msg_by_index(v1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
int v1; // edi

v1 = func0(a1);
return func4(v1);
}

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:
__int64 init()
{
return _printf_chk(1LL, "my_id = %d\n", my_id);
}

canonical_decompiled_code:
__int64 func6()
{
return _printf_chk(1LL, "my_id = %d\n", my_id);
}

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


decompiled_code:
__int64 __fastcall parse_command_line(int a1, _QWORD *a2)
{
const char *v3; // rdi
int v4; // eax
const char *v5; // rdi
int v6; // eax

if ( a1 <= 1 )
return usage("You must supply at least a <player-name>.");
v3 = (const char *)a2[2];
my_player_name = a2[1];
v4 = 0;
if ( v3 )
v4 = atoi(v3);
my_connect_port = v4;
hosting = a1 <= 3;
if ( a1 > 3 )
{
v5 = (const char *)a2[4];
host_ip = a2[3];
v6 = 0;
if ( v5 )
v6 = atoi(v5);
host_port = v6;
}
_printf_chk(1LL, "-- command line arguments: ");
_printf_chk(
1LL,
"name=%s, connect_to=%d, hosting=%d host_ip=%s, host_port=%d\n",
(const char *)my_player_name,
(unsigned int)my_connect_port,
(unsigned int)hosting,
(const char *)host_ip,
(unsigned int)host_port);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, _QWORD *a2)
{
const char *v3; // rdi
int v4; // eax
const char *v5; // rdi
int v6; // eax

if ( a1 <= 1 )
return func8("You must supply at least a <player-name>.");
v3 = (const char *)a2[2];
my_player_name = a2[1];
v4 = 0;
if ( v3 )
v4 = atoi(v3);
my_connect_port = v4;
hosting = a1 <= 3;
if ( a1 > 3 )
{
v5 = (const char *)a2[4];
host_ip = a2[3];
v6 = 0;
if ( v5 )
v6 = atoi(v5);
host_port = v6;
}
_printf_chk(1LL, "-- command line arguments: ");
_printf_chk(
1LL,
"name=%s, connect_to=%d, hosting=%d host_ip=%s, host_port=%d\n",
(const char *)my_player_name,
(unsigned int)my_connect_port,
(unsigned int)hosting,
(const char *)host_ip,
(unsigned int)host_port);
return 0LL;
}

original_code:
int parse_command_line( int argc, char ** argv )
{
 if ( argc < 2 )
  return usage("You must supply at least a <player-name>.");
 my_player_name = (char*) argv[1];
 my_connect_port = argv[2] ? atoi(argv[2]) : 0 ;
 hosting = (argc < 4) ? 1 : 0 ;
 if(!hosting)
 {
  host_ip = (char*) argv[3];
  host_port = argv[4] ? atoi(argv[4]) : 0 ;
 }
 printf("-- command line arguments: ");
 printf("name=%s, connect_to=%d, hosting=%d host_ip=%s, host_port=%d\n",
  my_player_name, my_connect_port, hosting, host_ip, host_port);
 return 0;
}

canonical_original_code:
int parse_command_line(int argc, char **argv)
{
 if ( argc < 2 )
  return usage("You must supply at least a <player-name>.");
 my_player_name = (char *) argv[1];
 my_connect_port = argv[2] ? atoi(argv[2]) : 0 ;
 hosting = (argc < 4) ? 1 : 0 ;
 if(!hosting)
 {
  host_ip = (char *) argv[3];
  host_port = argv[4] ? atoi(argv[4]) : 0 ;
 }
 printf("-- command line arguments: ");
 printf("name=%s, connect_to=%d, hosting=%d host_ip=%s, host_port=%d\n",
  my_player_name, my_connect_port, hosting, host_ip, host_port);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
__int64 bind_port()
{
unsigned int v0; // er12
int v1; // eax

v0 = 0;
v1 = network_setup(my_player_name, (unsigned int)my_connect_port);
if ( v1 )
{
if ( v1 == 1 )
{
v0 = 1;
puts("-- enet failed to initialize.");
}
else
{
v0 = 1;
if ( v1 == 2 )
puts("-- either your local port is already in use or your arguments were invalid.");
}
}
return v0;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int v0; // er12
int v1; // eax

v0 = 0;
v1 = network_setup(my_player_name, (unsigned int)my_connect_port);
if ( v1 )
{
if ( v1 == 1 )
{
v0 = 1;
puts("-- enet failed to initialize.");
}
else
{
v0 = 1;
if ( v1 == 2 )
puts("-- either your local port is already in use or your arguments were invalid.");
}
}
return v0;
}

original_code:
int bind_port( void )
{
 int rv = network_setup( my_player_name, my_connect_port );
 if( rv != NETWORK_OK )
 {
  switch( rv )
  {
  case NETWORK_ERROR_BIND:
   puts("-- either your local port is already in use or your arguments were invalid.");
   break;
  case NETWORK_ERROR_INIT:
   puts("-- enet failed to initialize.");
   break;
  }
  return 1;
 }
 return 0;
}

canonical_original_code:
int bind_port()
{
 int rv = network_setup( my_player_name, my_connect_port );
 if( rv != NETWORK_OK )
 {
  switch( rv )
  {
  case NETWORK_ERROR_BIND:
   puts("-- either your local port is already in use or your arguments were invalid.");
   break;
  case NETWORK_ERROR_INIT:
   puts("-- enet failed to initialize.");
   break;
  }
  return 1;
 }
 return 0;
}

variable_types: rv int


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

v2 = __readfsqword(0x28u);
_printf_chk(
1LL,
"{ name: %s, source: %s:%d, ping: %ld/ms, bw{ in: %ld, out: %ld }, loss: %ld }\n",
(const char *)a1,
(const char *)(a1 + 15),
*(unsigned int *)(a1 + 32),
*(_QWORD *)(a1 + 40),
*(_QWORD *)(a1 + 64),
*(_QWORD *)(a1 + 72),
*(_QWORD *)(a1 + 48));
return v2 - __readfsqword(0x28u);
}

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

v2 = __readfsqword(0x28u);
_printf_chk(
1LL,
"{ name: %s, source: %s:%d, ping: %ld/ms, bw{ in: %ld, out: %ld }, loss: %ld }\n",
(const char *)a1,
(const char *)(a1 + 15),
*(unsigned int *)(a1 + 32),
*(_QWORD *)(a1 + 40),
*(_QWORD *)(a1 + 64),
*(_QWORD *)(a1 + 72),
*(_QWORD *)(a1 + 48));
return v2 - __readfsqword(0x28u);
}

original_code:
void describe_player( network_player_t * player )
{
 printf( "{ name: %s, source: %s:%d, ping: %ld/ms, bw{ in: %ld, out: %ld }, loss: %ld }\n",
  player->name, player->ip, player->port, player->ping,
  player->bw_in, player->bw_out, player->packet_loss );
}

canonical_original_code:
void describe_player(struct _network_player_t *player)
{
 printf( "{ name: %s, source: %s:%d, ping: %ld/ms, bw{ in: %ld, out: %ld }, loss: %ld }\n",
  player->name, player->ip, player->port, player->ping,
  player->bw_in, player->bw_out, player->packet_loss );
}

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


decompiled_code:
int debug_network_state()
{
unsigned __int64 v0; // rax
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
switch ( network_state )
{
case 0:
LODWORD(v0) = puts("-- network state NETWORK_CONNECTED");
break;
case 1:
LODWORD(v0) = puts("-- network state NETWORK_CONNECTING");
break;
case 2:
LODWORD(v0) = puts("-- network state NETWORK_DISCONNECTED");
break;
case 3:
LODWORD(v0) = puts("-- network state NETWORK_SYNCHING");
break;
case 4:
LODWORD(v0) = puts("-- network state NETWORK_SYNCH_FAILED");
break;
default:
v0 = v2 - __readfsqword(0x28u);
break;
}
return v0;
}

canonical_decompiled_code:
int func12()
{
unsigned __int64 v0; // rax
unsigned __int64 v2; // [rsp+8h] [rbp-10h]

v2 = __readfsqword(0x28u);
switch ( network_state )
{
case 0:
LODWORD(v0) = puts("-- network state NETWORK_CONNECTED");
break;
case 1:
LODWORD(v0) = puts("-- network state NETWORK_CONNECTING");
break;
case 2:
LODWORD(v0) = puts("-- network state NETWORK_DISCONNECTED");
break;
case 3:
LODWORD(v0) = puts("-- network state NETWORK_SYNCHING");
break;
case 4:
LODWORD(v0) = puts("-- network state NETWORK_SYNCH_FAILED");
break;
default:
v0 = v2 - __readfsqword(0x28u);
break;
}
return v0;
}

original_code:
void debug_network_state( void )
{
 switch( network_state )
 {
 case NETWORK_CONNECTED: puts("-- network state " "NETWORK_CONNECTED"); break;;
 case NETWORK_CONNECTING: puts("-- network state " "NETWORK_CONNECTING"); break;;
 case NETWORK_DISCONNECTED: puts("-- network state " "NETWORK_DISCONNECTED"); break;;
 case NETWORK_SYNCHING: puts("-- network state " "NETWORK_SYNCHING"); break;;
 case NETWORK_SYNCH_FAILED: puts("-- network state " "NETWORK_SYNCH_FAILED"); break;;
 }
}

canonical_original_code:
void debug_network_state()
{
 switch( network_state )
 {
 case NETWORK_CONNECTED: puts("-- network state " "NETWORK_CONNECTED"); break;;
 case NETWORK_CONNECTING: puts("-- network state " "NETWORK_CONNECTING"); break;;
 case NETWORK_DISCONNECTED: puts("-- network state " "NETWORK_DISCONNECTED"); break;;
 case NETWORK_SYNCHING: puts("-- network state " "NETWORK_SYNCHING"); break;;
 case NETWORK_SYNCH_FAILED: puts("-- network state " "NETWORK_SYNCH_FAILED"); break;;
 }
}


decompiled_code:
__int64 connect_to_host()
{
__int64 result; // rax
int i; // eax
int j; // eax

if ( (unsigned int)network_join(host_ip, (unsigned int)host_port) == 1 )
{
puts("-- waiting to connect to host.");
for ( i = network_state; network_state == 1; i = network_state )
network_pump();
if ( i == 2 )
{
puts("-- failed to connect to host to host.");
exit(1);
}
puts("-- synching with other players.");
for ( j = network_state; network_state == 3; j = network_state )
network_pump();
if ( j == 4 )
{
puts("-- synching failed");
exit(1);
}
if ( j )
{
debug_network_state();
puts("-- disconnect during synch");
exit(1);
}
puts("-- successfully synched with all players");
result = 0LL;
}
else
{
puts("-- failed to join game");
puts("-- most likely your arguments were invalid");
result = usage(0LL);
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
int i; // eax
int j; // eax

if ( (unsigned int)network_join(host_ip, (unsigned int)host_port) == 1 )
{
puts("-- waiting to connect to host.");
for ( i = network_state; network_state == 1; i = network_state )
network_pump();
if ( i == 2 )
{
puts("-- failed to connect to host to host.");
exit(1);
}
puts("-- synching with other players.");
for ( j = network_state; network_state == 3; j = network_state )
network_pump();
if ( j == 4 )
{
puts("-- synching failed");
exit(1);
}
if ( j )
{
func12();
puts("-- disconnect during synch");
exit(1);
}
puts("-- successfully synched with all players");
result = 0LL;
}
else
{
puts("-- failed to join game");
puts("-- most likely your arguments were invalid");
result = func8(0LL);
}
return result;
}

original_code:
int connect_to_host( void )
{
 int rv = network_join( host_ip, host_port );
 if( rv != 1 )
 {
  puts("-- failed to join game");
  puts("-- most likely your arguments were invalid");
  return usage(((void *)0));
 }
 printf("-- waiting to connect to host.\n");
 while( network_state == NETWORK_CONNECTING )
  network_pump();
 if( network_state == NETWORK_DISCONNECTED )
 {
  puts("-- failed to connect to host to host.");
  exit(1);
 }
 printf("-- synching with other players.\n");
 while( network_state == NETWORK_SYNCHING )
  network_pump();
 if( network_state == NETWORK_SYNCH_FAILED )
 {
  puts("-- synching failed");
  exit(1);
 }
 if( network_state != NETWORK_CONNECTED )
 {
  debug_network_state();
  puts("-- disconnect during synch");
  exit(1);
 }
 puts("-- successfully synched with all players");
 return 0;
}

canonical_original_code:
int connect_to_host()
{
 int rv = network_join( host_ip, host_port );
 if( rv != 1 )
 {
  puts("-- failed to join game");
  puts("-- most likely your arguments were invalid");
  return usage(((void *)0));
 }
 printf("-- waiting to connect to host.\n");
 while( network_state == NETWORK_CONNECTING )
  network_pump();
 if( network_state == NETWORK_DISCONNECTED )
 {
  puts("-- failed to connect to host to host.");
  exit(1);
 }
 printf("-- synching with other players.\n");
 while( network_state == NETWORK_SYNCHING )
  network_pump();
 if( network_state == NETWORK_SYNCH_FAILED )
 {
  puts("-- synching failed");
  exit(1);
 }
 if( network_state != NETWORK_CONNECTED )
 {
  debug_network_state();
  puts("-- disconnect during synch");
  exit(1);
 }
 puts("-- successfully synched with all players");
 return 0;
}


decompiled_code:
__int64 setup_network()
{
unsigned int v0; // er12

v0 = 1;
atexit((void (*)(void))&network_cleanup);
if ( !(unsigned int)bind_port() )
{
v0 = 0;
if ( hosting )
{
network_host();
puts("-- waiting for connections.");
}
else
{
connect_to_host();
}
}
return v0;
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int v0; // er12

v0 = 1;
atexit((void (*)(void))&network_cleanup);
if ( !(unsigned int)func10() )
{
v0 = 0;
if ( hosting )
{
network_host();
puts("-- waiting for connections.");
}
else
{
func13();
}
}
return v0;
}

original_code:
int setup_network()
{
 atexit(network_cleanup);
 if(bind_port())
  return 1;
 if(hosting)
 {
  network_host();
  printf("-- waiting for connections.\n");
 }
 else
 {
  connect_to_host();
 }
 return 0;
}


decompiled_code:
__int64 __fastcall destroy_image(_QWORD *a1)
{
__int64 result; // rax

result = X_free(a1[35], "texture_png.c", 13LL);
*a1 = 0LL;
return result;
}

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

result = X_free(a1[35], "texture_png.c", 13LL);
*a1 = 0LL;
return result;
}

original_code:
void destroy_image( texture_image_t * image )
{
 X_free( (image->data), "texture_png.c", 13 );
 memset(image,0,sizeof(image));
}

canonical_original_code:
void destroy_image(struct texture_image_t *image)
{
 X_free( (image->data), "texture_png.c", 13 );
 memset(image,0,sizeof(image));
}

variable_types: struct texture_image_t { int id; int w; int h; int size; int colorkey; char path[256]; char *data; } *


SphereNormal

decompiled_code:
void __fastcall SphereNormal(float *a1, float *a2, float *a3, float a4)
{
*a3 = (float)(*a2 - *a1) / a4;
a3[1] = (float)(a2[1] - a1[1]) / a4;
a3[2] = (float)(a2[2] - a1[2]) / a4;
}

original_code:
void SphereNormal( VECTOR * Pos , VECTOR * Point , float radius , NORMAL * Normal )
{
 Normal->nx = ( Point->x - Pos->x ) / radius;
 Normal->ny = ( Point->y - Pos->y ) / radius;
 Normal->nz = ( Point->z - Pos->z ) / radius;
}

canonical_original_code:
void SphereNormal(struct VECTOR *Pos, struct VECTOR *Point, float radius, struct NORMAL *Normal)
{
 Normal->nx = ( Point->x - Pos->x ) / radius;
 Normal->ny = ( Point->y - Pos->y ) / radius;
 Normal->nz = ( Point->z - Pos->z ) / radius;
}

variable_types: struct VECTOR { float x; float y; float z; } *

variable_types:
Point
struct VECTOR *

variable_types: radius float

variable_types: struct NORMAL { union { float nx; float x; }; union { float ny; float y; }; union { float nz; float z; }; } *


isNotZero

decompiled_code:
double __fastcall isNotZero(double result)
{
if ( *(float *)&result > -0.0000001 && *(float *)&result < 0.0000001 )
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func1(double result)
{
if ( *(float *)&result > -0.0000001 && *(float *)&result < 0.0000001 )
result = 0.0;
return result;
}

original_code:
float isNotZero(float x)
{
 if( ( x > -1e-7 ) && ( x < 1e-7 ) )
  return 0.0F;
 return x;
}

variable_types: x float

return_type: float


solveQuadric

decompiled_code:
void __fastcall solveQuadric(float *a1, float *a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
float v4; // xmm1_4
float v5; // [rsp+8h] [rbp-18h]

*(_QWORD *)&v2 = *((unsigned int *)a1 + 1);
*(float *)&v2 = (float)(*(float *)&v2 * *(float *)&v2) - *a1;
v5 = a1[1];
v3 = isNotZero(v2);
if ( *(float *)&v3 == 0.0 )
{
*((_DWORD *)a2 + 1) = LODWORD(v5) ^ LC5;
*(_DWORD *)a2 = LODWORD(v5) ^ LC5;
}
else if ( *(float *)&v2 >= 0.0 )
{
v4 = fsqrt(*(float *)&v2);
*a2 = v4 - v5;
a2[1] = COERCE_FLOAT(LODWORD(v4) ^ LC5) - v5;
}
}

canonical_decompiled_code:
void __fastcall func2(float *a1, float *a2)
{
double v2; // xmm1_8
double v3; // xmm0_8
float v4; // xmm1_4
float v5; // [rsp+8h] [rbp-18h]

*(_QWORD *)&v2 = *((unsigned int *)a1 + 1);
*(float *)&v2 = (float)(*(float *)&v2 * *(float *)&v2) - *a1;
v5 = a1[1];
v3 = func1(v2);
if ( *(float *)&v3 == 0.0 )
{
*((_DWORD *)a2 + 1) = LODWORD(v5) ^ LC5;
*(_DWORD *)a2 = LODWORD(v5) ^ LC5;
}
else if ( *(float *)&v2 >= 0.0 )
{
v4 = fsqrt(*(float *)&v2);
*a2 = v4 - v5;
a2[1] = COERCE_FLOAT(LODWORD(v4) ^ LC5) - v5;
}
}

original_code:
float solveQuadric(float * c, float * s)
{
float p, q, D;
float sqrt_D;
 p = c[1];
 q = c[0];
 D = p * p - q;
 if (!isNotZero(D))
     {
     s[0] = s[1] = -p;
     return 1.0F;
     }
 if (D < 0.0F)
     return 0.0F;
    sqrt_D = (float) sqrt(D);
    s[0] = sqrt_D - p;
    s[1] = -sqrt_D - p;
    return 2.0F;
}

canonical_original_code:
float solveQuadric(float *c, float *s)
{
float p; float q; float D;
float sqrt_D;
 p = c[1];
 q = c[0];
 D = p * p - q;
 if (!isNotZero(D))
     {
     s[0] = s[1] = -p;
     return 1.0F;
     }
 if (D < 0.0F)
     return 0.0F;
    sqrt_D = (float) sqrt(D);
    s[0] = sqrt_D - p;
    s[1] = -sqrt_D - p;
    return 2.0F;
}

variable_types:
c
float *

variable_types:
s
float *

variable_types: p float

variable_types: q float

variable_types: D float


decompiled_code:
__int64 __fastcall closest_intersection(float *a1, float a2)
{
float v3; // xmm0_4
__int64 result; // rax
float v5; // xmm1_4

v3 = 0.0;
if ( a2 != 0.0 )
v3 = *a1;
result = 2LL;
if ( a2 > 1.0 )
{
do
{
v3 = fminf(a1[result - 1], v3);
v5 = (float)(int)result++;
}
while ( a2 > v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(float *a1, float a2)
{
float v3; // xmm0_4
__int64 result; // rax
float v5; // xmm1_4

v3 = 0.0;
if ( a2 != 0.0 )
v3 = *a1;
result = 2LL;
if ( a2 > 1.0 )
{
do
{
v3 = fminf(a1[result - 1], v3);
v5 = (float)(int)result++;
}
while ( a2 > v5 );
}
return result;
}

original_code:
float closest_intersection(float * x, float x_num)
{
int i;
float x_min;
 x_min = (x_num) ? x[0] : 0.0F;
 for ( i = 1 ; i < x_num ; i++ )
 {
     if (x[i] < x_min)
  x_min = x[i];
 }
 return x_min;
}

canonical_original_code:
float closest_intersection(float *x, float x_num)
{
int i;
float x_min;
 x_min = (x_num) ? x[0] : 0.0F;
 for ( i = 1 ; i < x_num ; i++ )
 {
     if (x[i] < x_min)
  x_min = x[i];
 }
 return x_min;
}

variable_types:
x
float *

variable_types: i int