decompiled_code:
__int64 __fastcall is_cmd(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
_BYTE *v3; // r8
__int64 result; // rax

v2 = 8240LL * (int)a2;
v3 = (_BYTE *)ft_strtrim(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24));
result = 1LL;
if ( *v3 == 47 )
{
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24), "/nick ", 6LL) )
change_nickname(a1, a2);
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24), "/join ", 6LL) )
change_chan(a1, a2);
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24), "/leave", 6LL) )
leave_chan(a1, a2);
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24), "/send ", 6LL) )
send_priv(a1, a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
_BYTE *v3; // r8
__int64 result; // rax

v2 = 8240LL * (int)a2;
v3 = (_BYTE *)ft_strtrim(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24));
result = 1LL;
if ( *v3 == 47 )
{
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24), "/nick ", 6LL) )
change_nickname(a1, a2);
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24), "/join ", 6LL) )
change_chan(a1, a2);
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24), "/leave", 6LL) )
leave_chan(a1, a2);
if ( !(unsigned int)ft_strncmp(*(_QWORD *)(*(_QWORD *)(a1 + 24) + v2 + 24), "/send ", 6LL) )
send_priv(a1, a2);
result = 0LL;
}
return result;
}

original_code:
int is_cmd(t_env *env, int cs)
{
 char *tmp;
 tmp = ((void *)0);
 tmp = ft_strtrim(env->fds[cs].save);
 if (tmp[0] == '/')
 {
  if (ft_strncmp(env->fds[cs].save, "/nick ", 6) == 0)
   change_nickname(env, cs);
  if (ft_strncmp(env->fds[cs].save, "/join ", 6) == 0)
   change_chan(env, cs);
  if (ft_strncmp(env->fds[cs].save, "/leave", 6) == 0)
   leave_chan(env, cs);
  if (ft_strncmp(env->fds[cs].save, "/send ", 6) == 0)
   send_priv(env, cs);
  return (0);
 }
 return (1);
}

canonical_original_code:
int is_cmd(struct s_env *env, int cs)
{
 char *tmp;
 tmp = ((void *)0);
 tmp = ft_strtrim(env->fds[cs].save);
 if (tmp[0] == '/')
 {
  if (ft_strncmp(env->fds[cs].save, "/nick ", 6) == 0)
   change_nickname(env, cs);
  if (ft_strncmp(env->fds[cs].save, "/join ", 6) == 0)
   change_chan(env, cs);
  if (ft_strncmp(env->fds[cs].save, "/leave", 6) == 0)
   leave_chan(env, cs);
  if (ft_strncmp(env->fds[cs].save, "/send ", 6) == 0)
   send_priv(env, cs);
  return (0);
 }
 return (1);
}

user_defined_types: struct s_fd { int type; void (*fct_read)(); void (*fct_write)(); char *save; char *nick; int channel; char buff_read[-1]; char buff_write[-1]; }


original_code:
int print_pkg(t_env *env, int cs, int ret)
{
 int i;
 char *tmp;
 tmp = ((void *)0);
 if (env->fds[cs].buff_read[ret - 1] == '\n')
 {
  i = 0;
  save_char(env, cs, ret);
  if (is_cmd(env, cs) && env->fds[cs].channel != -1)
  {
   tmp = ft_strdup(env->fds[cs].nick);
   env->fds[cs].save = ft_joinfree(tmp, env->fds[cs].save, 3);
   while (i <= env->max_fd)
   {
    if ((env->fds[i].type == 50) && (i != cs)
     && (env->fds[cs].channel == env->fds[i].channel))
     ft_strcat(env->fds[i].buff_write, env->fds[cs].save);
    i++;
   }
  }
  return (1);
 }
 else
  save_char(env, cs, ret);
 return (0);
}

canonical_original_code:
int print_pkg(struct s_env *env, int cs, int ret)
{
 int i;
 char *tmp;
 tmp = ((void *)0);
 if (env->fds[cs].buff_read[ret - 1] == '\n')
 {
  i = 0;
  save_char(env, cs, ret);
  if (is_cmd(env, cs) && env->fds[cs].channel != -1)
  {
   tmp = ft_strdup(env->fds[cs].nick);
   env->fds[cs].save = ft_joinfree(tmp, env->fds[cs].save, 3);
   while (i <= env->max_fd)
   {
    if ((env->fds[i].type == 50) && (i != cs)
     && (env->fds[cs].channel == env->fds[i].channel))
     ft_strcat(env->fds[i].buff_write, env->fds[cs].save);
    i++;
   }
  }
  return (1);
 }
 else
  save_char(env, cs, ret);
 return (0);
}

variable_types: struct s_env { char *prg_name; int port; int max; int max_fd; struct s_fd { int type; void (*fct_read)(); void (*fct_write)(); char *save; char *nick; int channel; char buff_read[-1]; char buff_write[-1]; } *fds; struct s_chan { int id; char *name; } chan[100]; int ret; struct fd_set { long __fds_bits[-1]; } fd_read; struct fd_set fd_write; } *

variable_types: cs int

variable_types: ret int

variable_types: i int

variable_types:
tmp
char *

return_type: int

user_defined_types: struct s_env { char *prg_name; int port; int max; int max_fd; struct s_fd *fds; struct s_chan chan[100]; int ret; struct fd_set fd_read; struct fd_set fd_write; }


original_code:
void client_read(t_env *env, int cs)
{
 int ret;
 ret = recv(cs, env->fds[cs].buff_read, 4096, 0);
 env->fds[cs].buff_read[ret] = 0;
 if (ret <= 0)
 {
  close(cs);
  env->fds[cs].type = 0;
  env->fds[cs].fct_read = ((void *)0);
  env->fds[cs].fct_write = ((void *)0);
  env->fds[cs].save = ((void *)0);
  free(env->fds[cs].nick);
  env->fds[cs].nick = ((void *)0);
  env->fds[cs].channel = -1;
  printf("client #%d disconected\n", cs);
 }
 else
 {
  if (print_pkg(env, cs, ret))
  {
   free(env->fds[cs].save);
   env->fds[cs].save = ((void *)0);
  }
 }
}

canonical_original_code:
void client_read(struct s_env *env, int cs)
{
 int ret;
 ret = recv(cs, env->fds[cs].buff_read, 4096, 0);
 env->fds[cs].buff_read[ret] = 0;
 if (ret <= 0)
 {
  close(cs);
  env->fds[cs].type = 0;
  env->fds[cs].fct_read = ((void *)0);
  env->fds[cs].fct_write = ((void *)0);
  env->fds[cs].save = ((void *)0);
  free(env->fds[cs].nick);
  env->fds[cs].nick = ((void *)0);
  env->fds[cs].channel = -1;
  printf("client #%d disconected\n", cs);
 }
 else
 {
  if (print_pkg(env, cs, ret))
  {
   free(env->fds[cs].save);
   env->fds[cs].save = ((void *)0);
  }
 }
}

return_type: void


original_code:
void client_write(t_env *env, int cs)
{
 send(cs, env->fds[cs].buff_write, ft_strlen(env->fds[cs].buff_write), 0);
 ft_bzero(env->fds[cs].buff_write, 4096);
}

canonical_original_code:
void client_write(struct s_env *env, int cs)
{
 send(cs, env->fds[cs].buff_write, ft_strlen(env->fds[cs].buff_write), 0);
 ft_bzero(env->fds[cs].buff_write, 4096);
}


decompiled_code:
__int64 __fastcall search_team(__int64 a1)
{
int v1; // er13
unsigned int v2; // ebx
unsigned int v3; // eax
__int64 v4; // rsi
unsigned int v5; // er12
unsigned int v6; // eax

v1 = *(_DWORD *)(*(_QWORD *)(a1 + 64) + 43420LL)
+ *(_DWORD *)(*(_QWORD *)(a1 + 64) + 43420LL) * *(_DWORD *)(*(_QWORD *)(a1 + 64) + 43416LL);
if ( v1 > 0 )
{
v2 = 0;
do
{
v3 = return_y(a1, v2);
v4 = v2++;
v5 = v3;
v6 = return_x(a1, v4);
check_case(a1, v6, v5);
}
while ( v1 != v2 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v1; // er13
unsigned int v2; // ebx
unsigned int v3; // eax
__int64 v4; // rsi
unsigned int v5; // er12
unsigned int v6; // eax

v1 = *(_DWORD *)(*(_QWORD *)(a1 + 64) + 43420LL)
+ *(_DWORD *)(*(_QWORD *)(a1 + 64) + 43420LL) * *(_DWORD *)(*(_QWORD *)(a1 + 64) + 43416LL);
if ( v1 > 0 )
{
v2 = 0;
do
{
v3 = return_y(a1, v2);
v4 = v2++;
v5 = v3;
v6 = return_x(a1, v4);
check_case(a1, v6, v5);
}
while ( v1 != v2 );
}
return 0LL;
}

original_code:
int search_team(t_env *env)
{
 int i;
 int max;
 char c;
 int total;
 c = 0;
 total = 0;
 i = 0;
 max = env->mem->size_x * env->mem->size_y + env->mem->size_y;
 while (i < max)
 {
  if (check_case(env, return_x(env, i), return_y(env, i)) == -1)
  {
   if (c == 0)
    c = env->map[i];
   else if (c != env->map[i])
    total++;
   else if (c != env->map[i] && total > 2)
    return (1);
  }
  i++;
 }
 return (0);
}

canonical_original_code:
int search_team(struct s_env *env)
{
 int i;
 int max;
 char c;
 int total;
 c = 0;
 total = 0;
 i = 0;
 max = env->mem->size_x * env->mem->size_y + env->mem->size_y;
 while (i < max)
 {
  if (check_case(env, return_x(env, i), return_y(env, i)) == -1)
  {
   if (c == 0)
    c = env->map[i];
   else if (c != env->map[i])
    total++;
   else if (c != env->map[i] && total > 2)
    return (1);
  }
  i++;
 }
 return (0);
}

variable_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem { int start; int team_nb; int team_max; struct s_team { char id; char name[60]; char nb_player; } team[700]; int size; int size_x; int size_y; } *mem; char player_id; int wait; int brk; int init; } *

variable_types: max int

variable_types: c char

variable_types: total int

user_defined_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem *mem; char player_id; int wait; int brk; int init; }

user_defined_types: struct s_mem { int start; int team_nb; int team_max; struct s_team team[700]; int size; int size_x; int size_y; }


decompiled_code:
int __fastcall close_connection(sem_t *sem, unsigned int *a2)
{
__int64 v2; // r12

if ( *((_DWORD *)&sem[2].__align + 5) )
{
while ( (unsigned int)search_team((__int64)sem) )
{
sem_rel(sem);
sem_wait(sem);
sem_block(sem);
if ( !*((_DWORD *)&sem[2].__align + 5) )
goto LABEL_7;
}
if ( *((_DWORD *)&sem[2].__align + 5) )
{
clearmap(sem);
exit(0);
}
}
LABEL_7:
v2 = *(&sem[1].__align + 2);
*(_BYTE *)(v2 + (int)return_pose(sem, *a2, a2[1])) = 0;
return shmdt((const void *)sem[2].__align);
}

canonical_decompiled_code:
int __fastcall func1(sem_t *sem, unsigned int *a2)
{
__int64 v2; // r12

if ( *((_DWORD *)&sem[2].__align + 5) )
{
while ( (unsigned int)func0((__int64)sem) )
{
sem_rel(sem);
sem_wait(sem);
sem_block(sem);
if ( !*((_DWORD *)&sem[2].__align + 5) )
goto LABEL_7;
}
if ( *((_DWORD *)&sem[2].__align + 5) )
{
clearmap(sem);
exit(0);
}
}
LABEL_7:
v2 = *(&sem[1].__align + 2);
*(_BYTE *)(v2 + (int)return_pose(sem, *a2, a2[1])) = 0;
return shmdt((const void *)sem[2].__align);
}

original_code:
void close_connection(t_env *env, t_play *p)
{
 while (env->init && search_team(env))
 {
  sem_rel(env);
  sem_wait(env);
  sem_block(env);
 }
 if (env->init)
 {
  clearmap(env);
  exit(0);
 }
 env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 shmdt (env->mem);
}

canonical_original_code:
void close_connection(struct s_env *env, struct s_play *p)
{
 while (env->init && search_team(env))
 {
  sem_rel(env);
  sem_wait(env);
  sem_block(env);
 }
 if (env->init)
 {
  clearmap(env);
  exit(0);
 }
 env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 shmdt (env->mem);
}

variable_types: struct s_play { struct s_move { int x; int y; } init; struct s_move to_do; int etats; } *

user_defined_types: struct s_play { struct s_move init; struct s_move to_do; int etats; }

user_defined_types: struct s_team { char id; char name[60]; char nb_player; }


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

switch ( a2 )
{
case 1:
result = (unsigned int)(*a1 - 1);
a1[2] = result;
break;
case 2:
result = (unsigned int)(a1[1] + 1);
a1[3] = result;
break;
case 3:
result = (unsigned int)(*a1 + 1);
a1[2] = result;
break;
case 4:
result = (unsigned int)(a1[1] - 1);
a1[3] = result;
break;
default:
result = ft_printf("rien a faire\n");
break;
}
return result;
}

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

switch ( a2 )
{
case 1:
result = (unsigned int)(*a1 - 1);
a1[2] = result;
break;
case 2:
result = (unsigned int)(a1[1] + 1);
a1[3] = result;
break;
case 3:
result = (unsigned int)(*a1 + 1);
a1[2] = result;
break;
case 4:
result = (unsigned int)(a1[1] - 1);
a1[3] = result;
break;
default:
result = ft_printf("rien a faire\n");
break;
}
return result;
}

original_code:
void init_moove(t_play *p, int act)
{
 if (act == 1)
  p->to_do.x = p->init.x - 1;
 else if (act == 2)
  p->to_do.y = p->init.y + 1;
 else if (act == 3)
  p->to_do.x = p->init.x + 1;
 else if (act == 4)
  p->to_do.y = p->init.y - 1;
 else
  ft_printf("rien a faire\n");
}

canonical_original_code:
void init_moove(struct s_play *p, int act)
{
 if (act == 1)
  p->to_do.x = p->init.x - 1;
 else if (act == 2)
  p->to_do.y = p->init.y + 1;
 else if (act == 3)
  p->to_do.x = p->init.x + 1;
 else if (act == 4)
  p->to_do.y = p->init.y - 1;
 else
  ft_printf("rien a faire\n");
}

variable_types: act int


decompiled_code:
__int64 __fastcall moove_to(__int64 a1, _DWORD *a2, unsigned int a3)
{
__int64 v5; // rsi
int v6; // eax
int v7; // er14
int v8; // er13

v5 = a3;
if ( (int)return_x(a1, a3) <= *a2 )
{
v6 = return_y(a1, v5);
v7 = a2[1];
v8 = v6;
if ( (int)return_x(a1, a3) < *a2 )
{
if ( v8 <= v7 )
{
if ( (int)return_y(a1, a3) < a2[1] && (rand() & 1) != 0 )
return 4LL;
return 1LL;
}
return (rand() & 1u) + 1;
}
if ( (int)return_y(a1, a3) >= a2[1] || v8 <= v7 )
return 1LL;
return (rand() & 1u) + 3;
}
if ( (int)return_y(a1, v5) > a2[1] )
return 3 - (rand() & 1u);
if ( *a2 <= (int)return_x(a1, a3) )
{
if ( a2[1] <= (int)return_y(a1, a3) )
return 1LL;
return (rand() & 1u) + 3;
}
return (rand() & 1u) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2, unsigned int a3)
{
__int64 v5; // rsi
int v6; // eax
int v7; // er14
int v8; // er13

v5 = a3;
if ( (int)return_x(a1, a3) <= *a2 )
{
v6 = return_y(a1, v5);
v7 = a2[1];
v8 = v6;
if ( (int)return_x(a1, a3) < *a2 )
{
if ( v8 <= v7 )
{
if ( (int)return_y(a1, a3) < a2[1] && (rand() & 1) != 0 )
return 4LL;
return 1LL;
}
return (rand() & 1u) + 1;
}
if ( (int)return_y(a1, a3) >= a2[1] || v8 <= v7 )
return 1LL;
return (rand() & 1u) + 3;
}
if ( (int)return_y(a1, v5) > a2[1] )
return 3 - (rand() & 1u);
if ( *a2 <= (int)return_x(a1, a3) )
{
if ( a2[1] <= (int)return_y(a1, a3) )
return 1LL;
return (rand() & 1u) + 3;
}
return (rand() & 1u) + 1;
}

original_code:
int moove_to(t_env *env, t_play *p, int pose)
{
 int i;
 int j;
 i = 0;
 if (return_x(env, pose) > p->init.x)
  i++;
 if (return_y(env, pose) > p->init.y)
  i++;
 if (i == 2)
  return ((rand() % 2 == 0) ? 3 : 2);
 j = (i == 0) ? 1 : 0;
 if (return_x(env, pose) < p->init.x)
  i++;
 if (i == 2)
  return ((rand() % 2 == 0) ? 1 : 2);
 if (return_y(env, pose) < p->init.y)
  i++;
 if (i == 2)
 {
  if (j == 0)
   return ((rand() % 2 == 0) ? 3 : 4);
  else
   return ((rand() % 2 == 0) ? 1 : 4);
 }
 return (1);
}

canonical_original_code:
int moove_to(struct s_env *env, struct s_play *p, int pose)
{
 int i;
 int j;
 i = 0;
 if (return_x(env, pose) > p->init.x)
  i++;
 if (return_y(env, pose) > p->init.y)
  i++;
 if (i == 2)
  return ((rand() % 2 == 0) ? 3 : 2);
 j = (i == 0) ? 1 : 0;
 if (return_x(env, pose) < p->init.x)
  i++;
 if (i == 2)
  return ((rand() % 2 == 0) ? 1 : 2);
 if (return_y(env, pose) < p->init.y)
  i++;
 if (i == 2)
 {
  if (j == 0)
   return ((rand() % 2 == 0) ? 3 : 4);
  else
   return ((rand() % 2 == 0) ? 1 : 4);
 }
 return (1);
}

variable_types: pose int

variable_types: j int


decompiled_code:
__int64 __fastcall ft_strstrlen(_QWORD *a1)
{
unsigned int v1; // er8
__int64 v2; // rax

v1 = 0;
if ( a1 && *a1 )
{
v2 = 1LL;
do
v1 = v2++;
while ( a1[v2 - 1] );
}
return v1;
}

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

v1 = 0;
if ( a1 && *a1 )
{
v2 = 1LL;
do
v1 = v2++;
while ( a1[v2 - 1] );
}
return v1;
}

original_code:
int ft_strstrlen(char **s)
{
 int i;
 i = 0;
 if (s && *s)
 {
  while (s[i] != ((void *)0))
   i++;
 }
 return (i);
}

variable_types:
s
char **


decompiled_code:
__int64 __fastcall ft_found(__int64 a1, __int64 **a2)
{
unsigned int v2; // er12
__int64 v4; // rbx
__int64 v5; // r13
__int64 i; // rsi
bool v7; // zf
__int64 *v8; // rax

v2 = 0;
v4 = 0LL;
v5 = (int)ft_strlen();
for ( i = **a2; i; i = v8[v4] )
{
v7 = (unsigned int)ft_strncmp(a1, i, v5) == 0;
v8 = *a2;
if ( v7 )
{
i = v8[v4];
if ( *(_BYTE *)(i + v5) == 61 )
break;
}
++v4;
++v2;
}
if ( (unsigned int)ft_strncmp(a1, i, v5) )
v2 = 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 **a2)
{
unsigned int v2; // er12
__int64 v4; // rbx
__int64 v5; // r13
__int64 i; // rsi
bool v7; // zf
__int64 *v8; // rax

v2 = 0;
v4 = 0LL;
v5 = (int)ft_strlen();
for ( i = **a2; i; i = v8[v4] )
{
v7 = (unsigned int)ft_strncmp(a1, i, v5) == 0;
v8 = *a2;
if ( v7 )
{
i = v8[v4];
if ( *(_BYTE *)(i + v5) == 61 )
break;
}
++v4;
++v2;
}
if ( (unsigned int)ft_strncmp(a1, i, v5) )
v2 = 0;
return v2;
}

original_code:
int ft_found(char *s, t_gen *env)
{
 int len;
 int i;
 len = ft_strlen(s);
 i = 0;
 while (env->env[i] != ((void *)0) && (ft_strncmp(s, env->env[i], len) != 0
    || env->env[i][len] != '='))
  i++;
 if (ft_strncmp(s, env->env[i], len) == 0)
  return (i);
 return (0);
}

canonical_original_code:
int ft_found(char *s, struct s_gen *env)
{
 int len;
 int i;
 len = ft_strlen(s);
 i = 0;
 while (env->env[i] != ((void *)0) && (ft_strncmp(s, env->env[i], len) != 0
    || env->env[i][len] != '='))
  i++;
 if (ft_strncmp(s, env->env[i], len) == 0)
  return (i);
 return (0);
}

variable_types:
s
char *

variable_types: struct s_gen { char **env; char **env_orig; struct s_ps1 { char *env; char *aff; int len; } *ps1; struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int wait; char **key; } *term; struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; } *hist; struct s_builtin { char *name; char *help; } **builtin; int ret; int status; char *path; int pid_fork; } *

variable_types: len int

user_defined_types: struct s_gen { char **env; char **env_orig; struct s_ps1 *ps1; struct s_term *term; struct s_hist *hist; struct s_builtin **builtin; int ret; int status; char *path; int pid_fork; }

user_defined_types: struct s_term { struct termios term; struct termios term_ori; int fd; int wait; char **key; }


decompiled_code:
void __fastcall ft_freetmpenv(void *ptr)
{
void **v2; // r8
void *v3; // rdi
__int64 v4; // rbx

if ( ptr )
{
v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
v3 = *v2;
if ( *v2 )
{
v4 = 8LL;
do
{
free(v3);
v2 = *(void ***)ptr;
v3 = *(void **)(*(_QWORD *)ptr + v4);
v4 += 8LL;
}
while ( v3 );
}
free(v2);
}
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void **v2; // r8
void *v3; // rdi
__int64 v4; // rbx

if ( ptr )
{
v2 = *(void ***)ptr;
if ( *(_QWORD *)ptr )
{
v3 = *v2;
if ( *v2 )
{
v4 = 8LL;
do
{
free(v3);
v2 = *(void ***)ptr;
v3 = *(void **)(*(_QWORD *)ptr + v4);
v4 += 8LL;
}
while ( v3 );
}
free(v2);
}
}
free(ptr);
}

original_code:
void ft_freetmpenv(t_gen *tmpenv)
{
 int j;
 j = 0;
 if (tmpenv)
 {
  if (tmpenv->env)
  {
   while (tmpenv->env[j])
    free(tmpenv->env[j++]);
   free(tmpenv->env);
  }
 }
 free(tmpenv);
 tmpenv = ((void *)0);
}

canonical_original_code:
void ft_freetmpenv(struct s_gen *tmpenv)
{
 int j;
 j = 0;
 if (tmpenv)
 {
  if (tmpenv->env)
  {
   while (tmpenv->env[j])
    free(tmpenv->env[j++]);
   free(tmpenv->env);
  }
 }
 free(tmpenv);
 tmpenv = ((void *)0);
}

user_defined_types: struct s_ps1 { char *env; char *aff; int len; }

user_defined_types: struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; }

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

user_defined_types: struct s_builtin { char *name; char *help; }


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

result = *(_QWORD *)(a1 + 24);
*(_DWORD *)(result + 124) = 0;
return result;
}

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

result = *(_QWORD *)(a1 + 24);
*(_DWORD *)(result + 124) = 0;
return result;
}

original_code:
void fn_return(t_gen *gen, char *buff)
{
 (void)buff;
 gen->term->wait = 0;
}

canonical_original_code:
void fn_return(struct s_gen *gen, char *buff)
{
 (void)buff;
 gen->term->wait = 0;
}

variable_types:
buff
char *


decompiled_code:
__int64 __fastcall tc_call_fn(__int64 a1, __int64 a2, unsigned int a3)
{
return (*(&fn_1 + a3))();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int a3)
{
return (*(&fn_1 + a3))();
}

original_code:
void tc_call_fn(t_gen *gen, char *line, enum e_key key)
{
 static t_fn *fn[K_REGULAR + 1] =
 {
 &fn_return,
 &fn_curs_left,
 &fn_curs_down,
 &fn_curs_up,
 &fn_curs_right,
 &fn_char_backsp,
 &fn_char_del,
 &go_end,
 &go_start,
 &go_kill,
 &clear,
 &fn_prewrite
 };
 (*fn[key])(gen, line);
}

canonical_original_code:
void tc_call_fn(struct s_gen *gen, char *line, enum e_key key)
{
 static void (*fn[-1])(struct s_gen *gen, char *buff) = {
 &fn_return,
 &fn_curs_left,
 &fn_curs_down,
 &fn_curs_up,
 &fn_curs_right,
 &fn_char_backsp,
 &fn_char_del,
 &go_end,
 &go_start,
 &go_kill,
 &clear,
 &fn_prewrite
 };
 (*fn[key])(gen, line);
}

variable_types:
line
char *

variable_types: enum e_key { K_ENTER=0, K_LEFT=1, K_DOWN=2, K_UP=3, K_RIGHT=4, K_BACKSP=5, K_DEL=6, K_END=7, K_START=8, K_KILL=9, K_CL=10, K_REGULAR=11 }

variable_types: void (*[-1])(struct s_gen { char **env; char **env_orig; struct s_ps1 { char *env; char *aff; int len; } *ps1; struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int wait; char **key; } *term; struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; } *hist; struct s_builtin { char *name; char *help; } **builtin; int ret; int status; char *path; int pid_fork; } *gen, char *buff)


decompiled_code:
__int64 __fastcall tc_search_key(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // er13

v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( !(unsigned int)ft_strcmp(a1, *(_QWORD *)(a2 + 8 * v2)) )
break;
if ( ++v2 == 11 )
return 11;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
unsigned int v3; // er13

v2 = 0LL;
while ( 1 )
{
v3 = v2;
if ( !(unsigned int)ft_strcmp(a1, *(_QWORD *)(a2 + 8 * v2)) )
break;
if ( ++v2 == 11 )
return 11;
}
return v3;
}

original_code:
int tc_search_key(char *buff, char **keyref)
{
 int i;
 i = 0;
 while (i < K_REGULAR)
 {
  if (!ft_strcmp(buff, keyref[i]))
   return (i);
  ++i;
 }
 return (K_REGULAR);
}

variable_types:
keyref
char **

variable_types: i int


decompiled_code:
__int64 __fastcall tc_get_key(__int64 a1)
{
if ( !keyref_0 )
{
keyref_0 = key_to_str(10LL, 0LL, 0LL, 0LL);
qword_1C8 = (__int64)tgetstr("kl", 0LL);
qword_1D0 = (__int64)tgetstr("kd", 0LL);
qword_1D8 = (__int64)tgetstr("ku", 0LL);
qword_1E0 = (__int64)tgetstr("kr", 0LL);
qword_1E8 = (__int64)tgetstr("kb", 0LL);
qword_1F0 = (__int64)tgetstr("kD", 0LL);
qword_1F8 = key_to_str(5LL, 0LL, 0LL, 0LL);
qword_200 = key_to_str(1LL, 0LL, 0LL, 0LL);
qword_208 = key_to_str(4LL, 0LL, 0LL, 0LL);
qword_210 = key_to_str(12LL, 0LL, 0LL, 0LL);
qword_218 = 0LL;
}
return tc_search_key(a1, (__int64)&keyref_0);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( !keyref_0 )
{
keyref_0 = key_to_str(10LL, 0LL, 0LL, 0LL);
qword_1C8 = (__int64)tgetstr("kl", 0LL);
qword_1D0 = (__int64)tgetstr("kd", 0LL);
qword_1D8 = (__int64)tgetstr("ku", 0LL);
qword_1E0 = (__int64)tgetstr("kr", 0LL);
qword_1E8 = (__int64)tgetstr("kb", 0LL);
qword_1F0 = (__int64)tgetstr("kD", 0LL);
qword_1F8 = key_to_str(5LL, 0LL, 0LL, 0LL);
qword_200 = key_to_str(1LL, 0LL, 0LL, 0LL);
qword_208 = key_to_str(4LL, 0LL, 0LL, 0LL);
qword_210 = key_to_str(12LL, 0LL, 0LL, 0LL);
qword_218 = 0LL;
}
return func2(a1, (__int64)&keyref_0);
}

original_code:
int tc_get_key(char *buff)
{
 static char *keyref[K_REGULAR + 1] = {((void *)0)};
 if (keyref[0] == ((void *)0))
 {
  keyref[K_ENTER] = key_to_str('\n', 0, 0, 0);
  keyref[K_LEFT] = tgetstr("kl", ((void *)0));
  keyref[K_DOWN] = tgetstr("kd", ((void *)0));
  keyref[K_UP] = tgetstr("ku", ((void *)0));
  keyref[K_RIGHT] = tgetstr("kr", ((void *)0));
  keyref[K_BACKSP] = tgetstr("kb", ((void *)0));
  keyref[K_DEL] = tgetstr("kD", ((void *)0));
  keyref[K_END] = key_to_str(5, 0, 0, 0);
  keyref[K_START] = key_to_str(1, 0, 0, 0);
  keyref[K_KILL] = key_to_str(4, 0, 0, 0);
  keyref[K_CL] = key_to_str(12, 0, 0, 0);
  keyref[K_REGULAR] = ((void *)0);
 }
 return (tc_search_key(buff, keyref));
}

canonical_original_code:
int tc_get_key(char *buff)
{
 static char *keyref[-1] = {((void *)0)};
 if (keyref[0] == ((void *)0))
 {
  keyref[K_ENTER] = key_to_str('\n', 0, 0, 0);
  keyref[K_LEFT] = tgetstr("kl", ((void *)0));
  keyref[K_DOWN] = tgetstr("kd", ((void *)0));
  keyref[K_UP] = tgetstr("ku", ((void *)0));
  keyref[K_RIGHT] = tgetstr("kr", ((void *)0));
  keyref[K_BACKSP] = tgetstr("kb", ((void *)0));
  keyref[K_DEL] = tgetstr("kD", ((void *)0));
  keyref[K_END] = key_to_str(5, 0, 0, 0);
  keyref[K_START] = key_to_str(1, 0, 0, 0);
  keyref[K_KILL] = key_to_str(4, 0, 0, 0);
  keyref[K_CL] = key_to_str(12, 0, 0, 0);
  keyref[K_REGULAR] = ((void *)0);
 }
 return (tc_search_key(buff, keyref));
}

variable_types:
keyref
char *[-1]


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

v2 = tc_get_key(a1);
return tc_call_fn(a2, a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
unsigned int v2; // eax

v2 = func3(a1);
return func1(a2, a1, v2);
}

original_code:
void tc_stomp(char *buff, t_gen *gen)
{
 int key;
 key = tc_get_key(buff);
 tc_call_fn(gen, buff, key);
}

canonical_original_code:
void tc_stomp(char *buff, struct s_gen *gen)
{
 int key;
 key = tc_get_key(buff);
 tc_call_fn(gen, buff, key);
}

variable_types: key int


decompiled_code:
__int64 __fastcall ft_comp(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // rax
char v3; // dl

if ( *a1 != *a2 )
return 0LL;
v2 = 1LL;
while ( a2[v2] )
{
v3 = a1[v2++];
if ( v3 != a2[v2 - 1] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, _BYTE *a2)
{
__int64 v2; // rax
char v3; // dl

if ( *a1 != *a2 )
return 0LL;
v2 = 1LL;
while ( a2[v2] )
{
v3 = a1[v2++];
if ( v3 != a2[v2 - 1] )
return 0LL;
}
return 1LL;
}

original_code:
static int ft_comp(char *s1, char *s2)
{
 int i;
 i = 0;
 while (s1[i] == s2[i])
 {
  if (s2[i + 1] == '\0')
   return (1);
  i++;
 }
 return (0);
}


original_code:
t_process *update_fd(t_token *token, t_process **current)
{
 int fd;
 fd = 0;
 if (token->type == append)
 {
  fd = open(token->next->str, 02000 | 0100 | 01, 0644);
  (*current)->fd[1] = fd;
 }
 else if (token->type == redir_out)
 {
  fd = open(token->next->str, 01000 | 0100 | 01, 0644);
  (*current)->fd[1] = fd;
 }
 else if (token->type == redir_in)
 {
  fd = open(token->next->str, 00);
  (*current)->fd[0] = fd;
 }
 else if (token->type == redir_err)
 {
  fd = open(token->next->str, 01000 | 0100 | 01, 0644);
  (*current)->fd[2] = fd;
 }
 return (*current);
}

canonical_original_code:
struct s_process *update_fd(struct s_token *token, struct s_process **current)
{
 int fd;
 fd = 0;
 if (token->type == append)
 {
  fd = open(token->next->str, 02000 | 0100 | 01, 0644);
  (*current)->fd[1] = fd;
 }
 else if (token->type == redir_out)
 {
  fd = open(token->next->str, 01000 | 0100 | 01, 0644);
  (*current)->fd[1] = fd;
 }
 else if (token->type == redir_in)
 {
  fd = open(token->next->str, 00);
  (*current)->fd[0] = fd;
 }
 else if (token->type == redir_err)
 {
  fd = open(token->next->str, 01000 | 0100 | 01, 0644);
  (*current)->fd[2] = fd;
 }
 return (*current);
}

variable_types: struct s_token { enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 } type; char *str; struct s_token *next; struct s_token *prev; } *

variable_types:
current
struct s_process **

variable_types: fd int

return_type: struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *

user_defined_types: struct s_token { enum e_sym type; char *str; struct s_token *next; struct s_token *prev; }


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

if ( a2 == 39 )
return press_quote();
if ( a2 == 34 )
result = press_dquote();
return result;
}

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

if ( a2 == 39 )
return press_quote();
if ( a2 == 34 )
result = press_dquote();
return result;
}

original_code:
void rm_special_char(t_term *term, char c)
{
 if (c == '\'')
  press_quote(term);
 if (c == '\"')
  press_dquote(term);
}

canonical_original_code:
void rm_special_char(struct s_term *term, char c)
{
 if (c == '\'')
  press_quote(term);
 if (c == '\"')
  press_dquote(term);
}

variable_types: struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int ps1_len; char **key; int quote; int dquote; int wait_fermeture; struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; } *hist; } *

variable_types: c char

user_defined_types: struct s_term { struct termios term; struct termios term_ori; int fd; int ps1_len; char **key; int quote; int dquote; int wait_fermeture; struct s_hist *hist; }


decompiled_code:
__int64 __fastcall clean_line(__int64 a1)
{
__int64 result; // rax
int i; // ebp
unsigned int v3; // er12
char *v4; // rax

result = *(_QWORD *)(a1 + 152);
for ( i = *(_DWORD *)(result + 4096); *(_DWORD *)(result + 4100) > i; result = *(_QWORD *)(a1 + 152) )
{
++i;
ft_putstr_fd(*(_QWORD *)(*(_QWORD *)(a1 + 128) + 24LL), *(unsigned int *)(a1 + 120));
}
if ( i > 0 )
{
do
{
ft_putstr_fd(*(_QWORD *)(*(_QWORD *)(a1 + 128) + 32LL), *(unsigned int *)(a1 + 120));
v3 = *(_DWORD *)(a1 + 120);
v4 = tgetstr("dc", 0LL);
result = ft_putstr_fd(v4, v3);
--i;
}
while ( i );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
int i; // ebp
unsigned int v3; // er12
char *v4; // rax

result = *(_QWORD *)(a1 + 152);
for ( i = *(_DWORD *)(result + 4096); *(_DWORD *)(result + 4100) > i; result = *(_QWORD *)(a1 + 152) )
{
++i;
ft_putstr_fd(*(_QWORD *)(*(_QWORD *)(a1 + 128) + 24LL), *(unsigned int *)(a1 + 120));
}
if ( i > 0 )
{
do
{
ft_putstr_fd(*(_QWORD *)(*(_QWORD *)(a1 + 128) + 32LL), *(unsigned int *)(a1 + 120));
v3 = *(_DWORD *)(a1 + 120);
v4 = tgetstr("dc", 0LL);
result = ft_putstr_fd(v4, v3);
--i;
}
while ( i );
}
return result;
}

original_code:
void clean_line(t_term *term)
{
 int i;
 i = term->hist->pose_cursor;
 while (i < term->hist->len)
 {
  ft_putstr_fd(term->key[3], term->fd);
  i++;
 }
 i++;
 while (--i > 0)
 {
  ft_putstr_fd(term->key[4], term->fd);
  ft_putstr_fd(tgetstr("dc", ((void *)0)), term->fd);
 }
}

canonical_original_code:
void clean_line(struct s_term *term)
{
 int i;
 i = term->hist->pose_cursor;
 while (i < term->hist->len)
 {
  ft_putstr_fd(term->key[3], term->fd);
  i++;
 }
 i++;
 while (--i > 0)
 {
  ft_putstr_fd(term->key[4], term->fd);
  ft_putstr_fd(tgetstr("dc", ((void *)0)), term->fd);
 }
}

user_defined_types: struct s_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; }


original_code:
void put_stradd(t_term *term, char *buff)
{
 int i;
 int j;
 char tmp[4096];
 i = 0;
 j = 0;
 ft_bzero(tmp, 4096);
 ft_strcpy(tmp, term->hist->buff);
 term->hist->len++;
 clean_line(term);
 while (i < term->hist->len)
 {
  if (i == term->hist->pose_cursor)
   term->hist->buff[i++] = buff[0];
  term->hist->buff[i++] = tmp[j++];
 }
 i = term->hist->len;
 ft_putstr(term->hist->buff);
 while (i - 1 != term->hist->pose_cursor)
 {
  ft_putstr_fd(term->key[4], term->fd);
  i--;
 }
 term->hist->pose_cursor++;
 term->hist->modif = 1;
}

canonical_original_code:
void put_stradd(struct s_term *term, char *buff)
{
 int i;
 int j;
 char tmp[4096];
 i = 0;
 j = 0;
 ft_bzero(tmp, 4096);
 ft_strcpy(tmp, term->hist->buff);
 term->hist->len++;
 clean_line(term);
 while (i < term->hist->len)
 {
  if (i == term->hist->pose_cursor)
   term->hist->buff[i++] = buff[0];
  term->hist->buff[i++] = tmp[j++];
 }
 i = term->hist->len;
 ft_putstr(term->hist->buff);
 while (i - 1 != term->hist->pose_cursor)
 {
  ft_putstr_fd(term->key[4], term->fd);
  i--;
 }
 term->hist->pose_cursor++;
 term->hist->modif = 1;
}

variable_types: j int

variable_types:
tmp
char [4096]


original_code:
int chr_ptr(t_chr *chr, t_table *table, t_plage *ptr)
{
 int i;
 i = 0;
 chr->tmp_old = table;
 chr->tmp = table->next;
 while (chr->tmp)
 {
  i++;
  chr->tmp_p = chr->tmp->page;
  while (chr->tmp_p)
  {
   if (chr->tmp_p == ptr)
    break ;
   chr->tmp_p = chr->tmp_p->next;
  }
  if (chr->tmp_p == ptr)
   break ;
  chr->tmp_old = chr->tmp;
  chr->tmp = chr->tmp->next;
 }
 return (i);
}

canonical_original_code:
int chr_ptr(struct s_chr *chr, struct s_table *table, struct s_plage *ptr)
{
 int i;
 i = 0;
 chr->tmp_old = table;
 chr->tmp = table->next;
 while (chr->tmp)
 {
  i++;
  chr->tmp_p = chr->tmp->page;
  while (chr->tmp_p)
  {
   if (chr->tmp_p == ptr)
    break ;
   chr->tmp_p = chr->tmp_p->next;
  }
  if (chr->tmp_p == ptr)
   break ;
  chr->tmp_old = chr->tmp;
  chr->tmp = chr->tmp->next;
 }
 return (i);
}

variable_types: struct s_chr { struct s_table { unsigned long max_len; int page_len; void *page; void *next; } *tmp; struct s_table *tmp_old; struct s_plage { unsigned long len; char aloued; void *prev; void *next; } *tmp_p; } *

variable_types:
table
struct s_table *

variable_types:
ptr
struct s_plage *

user_defined_types: struct s_chr { struct s_table *tmp; struct s_table *tmp_old; struct s_plage *tmp_p; }


decompiled_code:
int __fastcall clear_alloc(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v3; // ecx
unsigned __int64 v4; // rax
unsigned __int64 v5; // r8
char v6; // di
unsigned __int64 v7; // rsi
unsigned __int64 v8; // rdx
unsigned __int64 *v9; // rdx
void *v10; // rdi
size_t v11; // rsi
void *addr[2]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 *v14; // [rsp+10h] [rbp-18h]

v3 = chr_ptr(addr, a2, a1);
LODWORD(v4) = (_DWORD)v14;
v5 = v14[3];
v6 = *(_BYTE *)(v5 + 8);
if ( v6 == 1 )
return v4;
v7 = v14[2];
if ( !v7 )
{
if ( !*(_BYTE *)(*(_QWORD *)(v2 + 24) + 8LL) && v3 > 2 )
{
v10 = addr[0];
v11 = *((int *)addr[0] + 2);
*((_QWORD *)addr[1] + 3) = *((_QWORD *)addr[0] + 3);
LODWORD(v4) = munmap(v10, v11);
return v4;
}
goto LABEL_4;
}
if ( *(_BYTE *)(v7 + 8) )
{
LABEL_4:
if ( !v6 )
{
v8 = *(_QWORD *)v5 + *v14;
*v14 = v8;
LODWORD(v4) = addr[0];
if ( v8 > *(_QWORD *)addr[0] )
*(_QWORD *)addr[0] = v8;
}
return v4;
}
v9 = (unsigned __int64 *)addr[0];
v4 = *(_QWORD *)v7 + *v14;
*(_QWORD *)v7 = v4;
if ( v4 > *v9 )
*v9 = v4;
return v4;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
int v3; // ecx
unsigned __int64 v4; // rax
unsigned __int64 v5; // r8
char v6; // di
unsigned __int64 v7; // rsi
unsigned __int64 v8; // rdx
unsigned __int64 *v9; // rdx
void *v10; // rdi
size_t v11; // rsi
void *addr[2]; // [rsp+0h] [rbp-28h] BYREF
unsigned __int64 *v14; // [rsp+10h] [rbp-18h]

v3 = func0(addr, a2, a1);
LODWORD(v4) = (_DWORD)v14;
v5 = v14[3];
v6 = *(_BYTE *)(v5 + 8);
if ( v6 == 1 )
return v4;
v7 = v14[2];
if ( !v7 )
{
if ( !*(_BYTE *)(*(_QWORD *)(v2 + 24) + 8LL) && v3 > 2 )
{
v10 = addr[0];
v11 = *((int *)addr[0] + 2);
*((_QWORD *)addr[1] + 3) = *((_QWORD *)addr[0] + 3);
LODWORD(v4) = munmap(v10, v11);
return v4;
}
goto LABEL_4;
}
if ( *(_BYTE *)(v7 + 8) )
{
LABEL_4:
if ( !v6 )
{
v8 = *(_QWORD *)v5 + *v14;
*v14 = v8;
LODWORD(v4) = addr[0];
if ( v8 > *(_QWORD *)addr[0] )
*(_QWORD *)addr[0] = v8;
}
return v4;
}
v9 = (unsigned __int64 *)addr[0];
v4 = *(_QWORD *)v7 + *v14;
*(_QWORD *)v7 = v4;
if ( v4 > *v9 )
*v9 = v4;
return v4;
}

original_code:
void clear_alloc(t_plage *ptr, t_table *table)
{
 t_chr chr;
 int i;
 i = chr_ptr(&chr, table, ptr);
 if (((t_plage *)chr.tmp_p->next)->aloued == 1)
  return ;
 else if (chr.tmp_p->prev == ((void *)0) && ((t_plage *)ptr->next)->aloued == 0 && i > 2)
 {
  chr.tmp_old->next = chr.tmp->next;
  munmap(chr.tmp, chr.tmp->page_len);
 }
 else if ((t_plage *)chr.tmp_p->prev != ((void *)0) && ((t_plage *)chr.tmp_p->prev)->aloued == 0)
 {
  ((t_plage *)chr.tmp_p->prev)->len = ((t_plage *)chr.tmp_p->prev)->len + chr.tmp_p->len;
  if (chr.tmp->max_len < ((t_plage *)chr.tmp_p->prev)->len)
   chr.tmp->max_len = ((t_plage *)chr.tmp_p->prev)->len;
 }
 else if ((t_plage *)chr.tmp_p->next != ((void *)0) && ((t_plage *)chr.tmp_p->next)->aloued == 0)
 {
  chr.tmp_p->len = ((t_plage *)chr.tmp_p->next)->len + chr.tmp_p->len;
  if (chr.tmp->max_len < chr.tmp_p->len)
   chr.tmp->max_len = chr.tmp_p->len;
 }
}

canonical_original_code:
void clear_alloc(struct s_plage *ptr, struct s_table *table)
{
 struct s_chr chr;
 int i;
 i = chr_ptr(&chr, table, ptr);
 if (((struct s_plage *)chr.tmp_p->next)->aloued == 1)
  return ;
 else if (chr.tmp_p->prev == ((void *)0) && ((struct s_plage *)ptr->next)->aloued == 0 && i > 2)
 {
  chr.tmp_old->next = chr.tmp->next;
  munmap(chr.tmp, chr.tmp->page_len);
 }
 else if ((struct s_plage *)chr.tmp_p->prev != ((void *)0) && ((struct s_plage *)chr.tmp_p->prev)->aloued == 0)
 {
  ((struct s_plage *)chr.tmp_p->prev)->len = ((struct s_plage *)chr.tmp_p->prev)->len + chr.tmp_p->len;
  if (chr.tmp->max_len < ((struct s_plage *)chr.tmp_p->prev)->len)
   chr.tmp->max_len = ((struct s_plage *)chr.tmp_p->prev)->len;
 }
 else if ((struct s_plage *)chr.tmp_p->next != ((void *)0) && ((struct s_plage *)chr.tmp_p->next)->aloued == 0)
 {
  chr.tmp_p->len = ((struct s_plage *)chr.tmp_p->next)->len + chr.tmp_p->len;
  if (chr.tmp->max_len < chr.tmp_p->len)
   chr.tmp->max_len = chr.tmp_p->len;
 }
}

variable_types: struct s_chr { struct s_table { unsigned long max_len; int page_len; void *page; void *next; } *tmp; struct s_table *tmp_old; struct s_plage { unsigned long len; char aloued; void *prev; void *next; } *tmp_p; }


original_code:
void *free_me(void *ptr)
{
 size_t len;
 ptr = ((char *)ptr) - sizeof(t_plage);
 len = ((t_plage *)ptr)->len;
 ((t_plage *)ptr)->aloued = 0;
 return (ptr);
}

canonical_original_code:
void *free_me(void *ptr)
{
 unsigned long len;
 ptr = ((char *)ptr) - sizeof(t_plage);
 len = ((struct s_plage *)ptr)->len;
 ((struct s_plage *)ptr)->aloued = 0;
 return (ptr);
}

variable_types:
ptr
void *

variable_types:
len
unsigned long

return_type: void *

user_defined_types: struct s_plage { unsigned long len; char aloued; void *prev; void *next; }


free

decompiled_code:
int __fastcall free(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax

v1 = free_me(a1);
v2 = paye_ton_thon();
return clear_alloc(v1, v2);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // rax

v1 = func2(a1);
v2 = paye_ton_thon();
return func1(v1, v2);
}

original_code:
void free(void *ptr)
{
 ptr = free_me(ptr);
 clear_alloc(ptr, paye_ton_thon());
}


realloc

decompiled_code:
__int64 __fastcall realloc(__int64 a1, size_t a2)
{
__int64 v2; // r13
void *v3; // rax

v2 = a1;
if ( a2 + 32 != *(_QWORD *)(a1 - 32) )
{
v3 = malloc(a2);
v2 = ft_memcpy(v3, a1);
free(a1);
}
return v2;
}

original_code:
void *realloc(void *ptr, size_t size)
{
 void *new_ptr;
 size_t old_size;
 void *tmp;
 tmp = (char *)ptr - (sizeof(t_plage));
 old_size = ((t_plage *)tmp)->len;
 if (old_size == (size + sizeof(t_plage)))
  return (ptr);
 new_ptr = malloc(size);
 if ((old_size - sizeof(t_plage)) > size)
  new_ptr = ft_memcpy(new_ptr, ptr, (old_size - sizeof(t_plage)));
 else
  new_ptr = ft_memcpy(new_ptr, ptr, size);
 free(ptr);
 return (new_ptr);
}

canonical_original_code:
void *realloc(void *ptr, unsigned long size)
{
 void *new_ptr;
 unsigned long old_size;
 void *tmp;
 tmp = (char *)ptr - (sizeof(t_plage));
 old_size = ((struct s_plage *)tmp)->len;
 if (old_size == (size + sizeof(t_plage)))
  return (ptr);
 new_ptr = malloc(size);
 if ((old_size - sizeof(t_plage)) > size)
  new_ptr = ft_memcpy(new_ptr, ptr, (old_size - sizeof(t_plage)));
 else
  new_ptr = ft_memcpy(new_ptr, ptr, size);
 free(ptr);
 return (new_ptr);
}

variable_types:
size
unsigned long

variable_types:
tmp
void *


decompiled_code:
int __fastcall say_usage(const char *a1)
{
return fprintf(stderr, "usage : %s <adresse> <port>\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
return fprintf(stderr, "usage : %s <adresse> <port>\n", a1);
}

original_code:
void say_usage(char *name)
{
 fprintf(stderr, "usage : %s <adresse> <port>\n", name);
}

variable_types:
name
char *


original_code:
void ft_irc(t_env *env)
{
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&env->fd_read)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&env->fd_write)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&env->fd_read)->__fds_bits)[((env->sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((env->sock) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&env->fd_read)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 if (strlen(env->buff_write) > 0)
  ((void) (((&env->fd_write)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 if (env->aff_prompt == 1)
  ft_printf("%s :", env->pseudo);
 env->ret = select(env->sock + 1, &env->fd_read, &env->fd_write, ((void *)0), ((void *)0));
 env->aff_prompt = 1;
 check_fd(env);
}

canonical_original_code:
void ft_irc(struct s_env *env)
{
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&env->fd_read)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&env->fd_write)->__fds_bits)[0]) : "memory"); } while (0);
 ((void) (((&env->fd_read)->__fds_bits)[((env->sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((env->sock) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&env->fd_read)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 if (strlen(env->buff_write) > 0)
  ((void) (((&env->fd_write)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 if (env->aff_prompt == 1)
  ft_printf("%s :", env->pseudo);
 env->ret = select(env->sock + 1, &env->fd_read, &env->fd_write, ((void *)0), ((void *)0));
 env->aff_prompt = 1;
 check_fd(env);
}

variable_types: struct s_env { int port; char *addr; int sock; int channel; char *pseudo; int ret; int aff_prompt; char buff_read[4096]; char buff_write[4096]; struct fd_set { long __fds_bits[-1]; } fd_read; struct fd_set fd_write; } *

user_defined_types: struct s_env { int port; char *addr; int sock; int channel; char *pseudo; int ret; int aff_prompt; char buff_read[4096]; char buff_write[4096]; struct fd_set fd_read; struct fd_set fd_write; }


decompiled_code:
__int64 __fastcall get_pseudo(__int64 *a1)
{
__int64 *v1; // rbx
__int64 v2; // rdi

v1 = a1;
v2 = *a1;
if ( !v2 )
{
ft_putstr_fd("env not found\n", 2LL);
exit(-1);
}
while ( (unsigned int)ft_strncmp(v2, "USER=", 5LL) )
{
v2 = v1[1];
++v1;
if ( !v2 )
return v2 + 5;
}
v2 = *v1;
return v2 + 5;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 *a1)
{
__int64 *v1; // rbx
__int64 v2; // rdi

v1 = a1;
v2 = *a1;
if ( !v2 )
{
ft_putstr_fd("env not found\n", 2LL);
exit(-1);
}
while ( (unsigned int)ft_strncmp(v2, "USER=", 5LL) )
{
v2 = v1[1];
++v1;
if ( !v2 )
return v2 + 5;
}
v2 = *v1;
return v2 + 5;
}

original_code:
char *get_pseudo(char **e)
{
 int i;
 if (e[0] == ((void *)0))
 {
  ft_putstr_fd("env not found\n", 2);
  exit (-1);
 }
 i = 0;
 while (e[i] && ft_strncmp(e[i], "USER=", 5))
  i++;
 return (e[i] + 5);
}

variable_types:
e
char **

variable_types: i int

return_type: char *


decompiled_code:
ssize_t __fastcall create_client(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rbp
__int64 v5; // r12
struct protoent *v6; // rax
__int64 v7; // r12
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // rbp
__int64 v11; // r13
unsigned int v12; // eax
int v13; // eax
const char *v14; // rdi
in_addr_t v15; // eax
__int64 v16; // rax
__int64 v17; // rdx
__int64 v18; // rbp
__int64 v19; // r12
unsigned int v20; // eax
const void *v21; // rbp
size_t v22; // rax
struct sockaddr v24; // [rsp+0h] [rbp-38h] BYREF

v2 = e_i("src/client/main.c", 51LL);
v4 = v3;
v5 = v2;
v6 = getprotobyname("tcp");
v7 = x_void(0LL, v6, "getprotobyname", v5, v4);
v8 = e_i("src/client/main.c", 52LL);
v10 = v9;
v11 = v8;
v12 = socket(2, 1, *(_DWORD *)(v7 + 16));
v13 = x_int(0xFFFFFFFFLL, v12, "socket", v11, v10);
v14 = *(const char **)(a1 + 8);
*(_DWORD *)(a1 + 16) = v13;
v24.sa_family = 2;
v15 = inet_addr(v14);
LOWORD(v14) = *(_WORD *)a1;
*(_DWORD *)&v24.sa_data[2] = v15;
*(_WORD *)v24.sa_data = _bswap_16((__int16)v14);
v16 = e_i("src/client/main.c", 56LL);
v18 = v17;
v19 = v16;
v20 = connect(*(_DWORD *)(a1 + 16), &v24, 0x10u);
x_int(0xFFFFFFFFLL, v20, "connect", v19, v18);
v21 = (const void *)ft_strjoin("/nick ", *(_QWORD *)(a1 + 24));
v22 = ft_strlen(v21);
send(*(_DWORD *)(a1 + 16), v21, v22, 0);
return send(*(_DWORD *)(a1 + 16), "\n", 1uLL, 0);
}

canonical_decompiled_code:
ssize_t __fastcall func4(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 v4; // rbp
__int64 v5; // r12
struct protoent *v6; // rax
__int64 v7; // r12
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // rbp
__int64 v11; // r13
unsigned int v12; // eax
int v13; // eax
const char *v14; // rdi
in_addr_t v15; // eax
__int64 v16; // rax
__int64 v17; // rdx
__int64 v18; // rbp
__int64 v19; // r12
unsigned int v20; // eax
const void *v21; // rbp
size_t v22; // rax
struct sockaddr v24; // [rsp+0h] [rbp-38h] BYREF

v2 = e_i("src/client/main.c", 51LL);
v4 = v3;
v5 = v2;
v6 = getprotobyname("tcp");
v7 = x_void(0LL, v6, "getprotobyname", v5, v4);
v8 = e_i("src/client/main.c", 52LL);
v10 = v9;
v11 = v8;
v12 = socket(2, 1, *(_DWORD *)(v7 + 16));
v13 = x_int(0xFFFFFFFFLL, v12, "socket", v11, v10);
v14 = *(const char **)(a1 + 8);
*(_DWORD *)(a1 + 16) = v13;
v24.sa_family = 2;
v15 = inet_addr(v14);
LOWORD(v14) = *(_WORD *)a1;
*(_DWORD *)&v24.sa_data[2] = v15;
*(_WORD *)v24.sa_data = func0((__int16)v14);
v16 = e_i("src/client/main.c", 56LL);
v18 = v17;
v19 = v16;
v20 = connect(*(_DWORD *)(a1 + 16), &v24, 0x10u);
x_int(0xFFFFFFFFLL, v20, "connect", v19, v18);
v21 = (const void *)ft_strjoin("/nick ", *(_QWORD *)(a1 + 24));
v22 = ft_strlen(v21);
send(*(_DWORD *)(a1 + 16), v21, v22, 0);
return send(*(_DWORD *)(a1 + 16), "\n", 1uLL, 0);
}

original_code:
void create_client(t_env *env)
{
 struct protoent *prot;
 struct sockaddr_in sin;
 char *nick;
 prot = (struct protoent *)(x_void(((void *)0), getprotobyname("tcp"), "getprotobyname", e_i("src/client/main.c", 51)));
 env->sock = (x_int(-1, socket(2, SOCK_STREAM, prot->p_proto), "socket", e_i("src/client/main.c", 52)));
 sin.sin_family = 2;
 sin.sin_addr.s_addr = inet_addr(env->addr);
 sin.sin_port = htons(env->port);
 (x_int(-1, connect(env->sock, (struct sockaddr *)&sin, sizeof(sin)), "connect", e_i("src/client/main.c", 56)));
 nick = ft_strjoin("/nick ", env->pseudo);
 send(env->sock, nick, ft_strlen(nick), 0);
 send(env->sock, "\n", 1, 0);
}

canonical_original_code:
void create_client(struct s_env *env)
{
 struct protoent *prot;
 struct sockaddr_in sin;
 char *nick;
 prot = (struct protoent *)(x_void(((void *)0), getprotobyname("tcp"), "getprotobyname", e_i("src/client/main.c", 51)));
 env->sock = (x_int(-1, socket(2, SOCK_STREAM, prot->p_proto), "socket", e_i("src/client/main.c", 52)));
 sin.sin_family = 2;
 sin.sin_addr.s_addr = inet_addr(env->addr);
 sin.sin_port = htons(env->port);
 (x_int(-1, connect(env->sock, (struct sockaddr *)&sin, sizeof(sin)), "connect", e_i("src/client/main.c", 56)));
 nick = ft_strjoin("/nick ", env->pseudo);
 send(env->sock, nick, ft_strlen(nick), 0);
 send(env->sock, "\n", 1, 0);
}

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

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

variable_types:
nick
char *

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


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdi
int v5; // [rsp+0h] [rbp-2148h] BYREF
const char *v6; // [rsp+8h] [rbp-2140h]
__int64 v7; // [rsp+18h] [rbp-2130h]
int v8; // [rsp+24h] [rbp-2124h]
char v9[4096]; // [rsp+28h] [rbp-2120h] BYREF
char v10[4384]; // [rsp+1028h] [rbp-1120h] BYREF

if ( argc != 3 )
say_usage(*argv);
if ( !(unsigned int)ft_strncmp(argv[1], "localhost", 9LL) )
argv[1] = "127.0.0.1";
ft_bzero(v10, 4096LL);
ft_bzero(v9, 4096LL);
v4 = argv[2];
v8 = 0;
v5 = ft_atoi(v4);
if ( !v5 )
say_usage(*argv);
v6 = argv[1];
v7 = get_pseudo((__int64 *)envp);
create_client((__int64)&v5);
while ( 1 )
ft_irc((__int64)&v5);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v4; // rdi
int v5; // [rsp+0h] [rbp-2148h] BYREF
const char *v6; // [rsp+8h] [rbp-2140h]
__int64 v7; // [rsp+18h] [rbp-2130h]
int v8; // [rsp+24h] [rbp-2124h]
char v9[4096]; // [rsp+28h] [rbp-2120h] BYREF
char v10[4384]; // [rsp+1028h] [rbp-1120h] BYREF

if ( argc != 3 )
func1(*argv);
if ( !(unsigned int)ft_strncmp(argv[1], "localhost", 9LL) )
argv[1] = "127.0.0.1";
ft_bzero(v10, 4096LL);
ft_bzero(v9, 4096LL);
v4 = argv[2];
v8 = 0;
v5 = ft_atoi(v4);
if ( !v5 )
func1(*argv);
v6 = argv[1];
v7 = func5((__int64 *)envp);
func4((__int64)&v5);
while ( 1 )
func3((__int64)&v5);
}

original_code:
int main(int ac, char **av, char **e)
{
 t_env env;
 if (ac != 3)
  say_usage(av[0]);
 if (!ft_strncmp(av[1], "localhost", 9))
  av[1] = "127.0.0.1";
 ft_bzero(env.buff_write, 4096);
 ft_bzero(env.buff_read, 4096);
 env.aff_prompt = 0;
 if ((env.port = ft_atoi(av[2])) == 0)
  say_usage(av[0]);
 env.addr = av[1];
 env.pseudo = get_pseudo(e);
 create_client(&env);
 while (1)
  ft_irc(&env);
 return (0);
}

canonical_original_code:
int main(int ac, char **av, char **e)
{
 struct s_env env;
 if (ac != 3)
  say_usage(av[0]);
 if (!ft_strncmp(av[1], "localhost", 9))
  av[1] = "127.0.0.1";
 ft_bzero(env.buff_write, 4096);
 ft_bzero(env.buff_read, 4096);
 env.aff_prompt = 0;
 if ((env.port = ft_atoi(av[2])) == 0)
  say_usage(av[0]);
 env.addr = av[1];
 env.pseudo = get_pseudo(e);
 create_client(&env);
 while (1)
  ft_irc(&env);
 return (0);
}

variable_types: ac int

variable_types:
av
char **

variable_types: struct s_env { int port; char *addr; int sock; int channel; char *pseudo; int ret; int aff_prompt; char buff_read[4096]; char buff_write[4096]; struct fd_set { long __fds_bits[-1]; } fd_read; struct fd_set fd_write; }


decompiled_code:
__int64 __fastcall e_i(__int64 a1)
{
return a1;
}

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

original_code:
t_error e_i(char *file, int line)
{
 t_error err;
 err.file = file;
 err.line = line;
 return (err);
}

canonical_original_code:
struct s_errror e_i(char *file, int line)
{
 struct s_errror err;
 err.file = file;
 err.line = line;
 return (err);
}

variable_types:
file
char *

variable_types: line int

variable_types: struct s_errror { char *file; int line; }


decompiled_code:
__int64 __fastcall x_int(int a1, unsigned int a2, const char *a3, const char *a4, __int64 a5)
{
if ( a2 == a1 )
{
ft_fprintf(2LL, "%s error (%s, %d)\n", a3, a4, a5);
exit(1);
}
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, unsigned int a2, const char *a3, const char *a4, __int64 a5)
{
if ( a2 == a1 )
{
ft_fprintf(2LL, "%s error (%s, %d)\n", a3, a4, a5);
exit(1);
}
return a2;
}

original_code:
int x_int(int err, int res, char *str, t_error e)
{
 if (res == err)
 {
  fprintf(stderr, "%s error (%s, %d)\n", str, e.file, e.line);
  exit (1);
 }
 return (res);
}

canonical_original_code:
int x_int(int err, int res, char *str, struct s_errror e)
{
 if (res == err)
 {
  fprintf(stderr, "%s error (%s, %d)\n", str, e.file, e.line);
  exit (1);
 }
 return (res);
}

variable_types: err int

variable_types: res int

variable_types:
str
char *

user_defined_types: struct s_errror { char *file; int line; }


decompiled_code:
__int64 __fastcall x_void(__int64 a1, __int64 a2, const char *a3, const char *a4, __int64 a5)
{
if ( a2 == a1 )
{
ft_fprintf(2LL, "%s error (%s, %d)\n", a3, a4, a5);
exit(1);
}
return a2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, const char *a3, const char *a4, __int64 a5)
{
if ( a2 == a1 )
{
ft_fprintf(2LL, "%s error (%s, %d)\n", a3, a4, a5);
exit(1);
}
return a2;
}

original_code:
void *x_void(void *err, void *res, char *str, t_error e)
{
 if (res == err)
 {
  fprintf(stderr, "%s error (%s, %d)\n", str, e.file, e.line);
  exit (1);
 }
 return (res);
}

canonical_original_code:
void *x_void(void *err, void *res, char *str, struct s_errror e)
{
 if (res == err)
 {
  fprintf(stderr, "%s error (%s, %d)\n", str, e.file, e.line);
  exit (1);
 }
 return (res);
}

variable_types:
err
void *

variable_types:
res
void *


original_code:
int ft_isnl(t_gen *gen, int pos)
{
 int pos_tmp;
 int len;
 len = tgetnum("co");
 if (gen->hist->buff[pos] == '\n')
  return (1);
 else
 {
  pos_tmp = pos;
  while (gen->hist->buff[pos_tmp] && gen->hist->buff[pos_tmp] != '\n')
   pos_tmp--;
  if (pos_tmp <= 0)
  {
   if ((pos + 1 + gen->ps1->len) % len == 0)
    return (1);
  }
  else if ((pos - pos_tmp) % len == 0)
  {
   if ((pos - pos_tmp) % len == 0)
    return (2);
  }
 }
 return (0);
}

canonical_original_code:
int ft_isnl(struct s_gen *gen, int pos)
{
 int pos_tmp;
 int len;
 len = tgetnum("co");
 if (gen->hist->buff[pos] == '\n')
  return (1);
 else
 {
  pos_tmp = pos;
  while (gen->hist->buff[pos_tmp] && gen->hist->buff[pos_tmp] != '\n')
   pos_tmp--;
  if (pos_tmp <= 0)
  {
   if ((pos + 1 + gen->ps1->len) % len == 0)
    return (1);
  }
  else if ((pos - pos_tmp) % len == 0)
  {
   if ((pos - pos_tmp) % len == 0)
    return (2);
  }
 }
 return (0);
}

variable_types: struct s_gen { char **env; char **env_orig; struct s_ps1 { char *env; char *aff; int len; } *ps1; struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int wait; char **key; } *term; struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; } *hist; struct s_builtin { char *name; char *help; } **builtin; int ret; int status; char *path; int pid_fork; } *

variable_types: pos int

variable_types: len int


decompiled_code:
__int64 __fastcall count_char_to_nl(__int64 a1, int a2)
{
int v2; // ebx

v2 = a2 - 1;
if ( !*(_BYTE *)(*(_QWORD *)(a1 + 32) + a2 - 1 + 4108LL) )
return 0LL;
do
{
if ( (unsigned int)ft_isnl(a1, v2) )
break;
--v2;
}
while ( *(_BYTE *)(*(_QWORD *)(a1 + 32) + v2 + 4108LL) );
return (unsigned int)(a2 - v2 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // ebx

v2 = a2 - 1;
if ( !*(_BYTE *)(*(_QWORD *)(a1 + 32) + a2 - 1 + 4108LL) )
return 0LL;
do
{
if ( (unsigned int)func0(a1, v2) )
break;
--v2;
}
while ( *(_BYTE *)(*(_QWORD *)(a1 + 32) + v2 + 4108LL) );
return (unsigned int)(a2 - v2 - 1);
}

original_code:
int count_char_to_nl(t_gen *gen, int pos)
{
 int pos_tmp;
 pos_tmp = pos - 1;
 while (gen->hist->buff[pos_tmp] && !ft_isnl(gen, pos_tmp))
  pos_tmp--;
 return (pos - pos_tmp - 1);
}

canonical_original_code:
int count_char_to_nl(struct s_gen *gen, int pos)
{
 int pos_tmp;
 pos_tmp = pos - 1;
 while (gen->hist->buff[pos_tmp] && !ft_isnl(gen, pos_tmp))
  pos_tmp--;
 return (pos - pos_tmp - 1);
}


original_code:
void tc_move_right(t_gen *gen, int i, int force)
{
 int j;
 int n_p;
 j = 0;
 while (j < i)
 {
  if (force == 1 || !ft_isnl(gen, gen->hist->pose_buff))
   ft_putstr_fd(tgetstr("nd", ((void *)0)), gen->term->fd);
  else
  {
   n_p = count_char_to_nl(gen, gen->hist->pose_buff);
   if (gen->hist->buff[gen->hist->pose_buff - n_p] == '\0'
     || (gen->hist->buff[gen->hist->pose_buff - n_p] + 1 != '\n'
      && ft_isnl(gen, gen->hist->pose_buff) == 1))
    n_p = n_p + gen->ps1->len;
   tc_move_left(gen, n_p, 1);
   ft_putstr_fd(tgetstr("kd", ((void *)0)), gen->term->fd);
  }
  j++;
 }
}

canonical_original_code:
void tc_move_right(struct s_gen *gen, int i, int force)
{
 int j;
 int n_p;
 j = 0;
 while (j < i)
 {
  if (force == 1 || !ft_isnl(gen, gen->hist->pose_buff))
   ft_putstr_fd(tgetstr("nd", ((void *)0)), gen->term->fd);
  else
  {
   n_p = count_char_to_nl(gen, gen->hist->pose_buff);
   if (gen->hist->buff[gen->hist->pose_buff - n_p] == '\0'
     || (gen->hist->buff[gen->hist->pose_buff - n_p] + 1 != '\n'
      && ft_isnl(gen, gen->hist->pose_buff) == 1))
    n_p = n_p + gen->ps1->len;
   tc_move_left(gen, n_p, 1);
   ft_putstr_fd(tgetstr("kd", ((void *)0)), gen->term->fd);
  }
  j++;
 }
}

variable_types: i int

variable_types: force int

variable_types: j int


decompiled_code:
__int64 __fastcall tc_move_left(_QWORD *a1, int a2, int a3)
{
__int64 result; // rax
int v4; // er12
int v6; // ebx
unsigned int v7; // er14
char *v8; // rax
int v9; // eax
int v10; // esi
unsigned int v11; // er14
char *v12; // rax

result = a1[4];
v4 = *(_DWORD *)(result + 4096) - a2;
if ( a2 > 0 )
{
v6 = v4 - a2;
do
{
while ( a3 == 1 || !(unsigned int)ft_isnl((__int64)a1, v4) )
{
++v6;
v7 = *(_DWORD *)(a1[3] + 120LL);
v8 = tgetstr("le", 0LL);
result = ft_putstr_fd(v8, v7);
if ( v4 == v6 )
return result;
}
v9 = count_char_to_nl((__int64)a1, v6);
v10 = v9 + 1;
if ( v4 - v9 <= 2 )
v10 += *(_DWORD *)(a1[2] + 16LL);
++v6;
tc_move_right(a1, v10, 1);
v11 = *(_DWORD *)(a1[3] + 120LL);
v12 = tgetstr("ku", 0LL);
result = ft_putstr_fd(v12, v11);
}
while ( v4 != v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, int a2, int a3)
{
__int64 result; // rax
int v4; // er12
int v6; // ebx
unsigned int v7; // er14
char *v8; // rax
int v9; // eax
int v10; // esi
unsigned int v11; // er14
char *v12; // rax

result = a1[4];
v4 = *(_DWORD *)(result + 4096) - a2;
if ( a2 > 0 )
{
v6 = v4 - a2;
do
{
while ( a3 == 1 || !(unsigned int)func0((__int64)a1, v4) )
{
++v6;
v7 = *(_DWORD *)(a1[3] + 120LL);
v8 = tgetstr("le", 0LL);
result = ft_putstr_fd(v8, v7);
if ( v4 == v6 )
return result;
}
v9 = func1((__int64)a1, v6);
v10 = v9 + 1;
if ( v4 - v9 <= 2 )
v10 += *(_DWORD *)(a1[2] + 16LL);
++v6;
func2(a1, v10, 1);
v11 = *(_DWORD *)(a1[3] + 120LL);
v12 = tgetstr("ku", 0LL);
result = ft_putstr_fd(v12, v11);
}
while ( v4 != v6 );
}
return result;
}

original_code:
void tc_move_left(t_gen *gen, int i, int force)
{
 int j;
 int n_p;
 j = gen->hist->pose_buff - i + 1;
 while (i > 0)
 {
  if (force == 1 || !ft_isnl(gen, j - 1))
   ft_putstr_fd(tgetstr("le", ((void *)0)), gen->term->fd);
  else
  {
   n_p = count_char_to_nl(gen, j - i - 1) + 1;
   if (j - n_p - 2 <= 0)
    n_p = n_p + gen->ps1->len;
   tc_move_right(gen, n_p, 1);
   ft_putstr_fd(tgetstr("ku", ((void *)0)), gen->term->fd);
  }
  i--;
 }
}

canonical_original_code:
void tc_move_left(struct s_gen *gen, int i, int force)
{
 int j;
 int n_p;
 j = gen->hist->pose_buff - i + 1;
 while (i > 0)
 {
  if (force == 1 || !ft_isnl(gen, j - 1))
   ft_putstr_fd(tgetstr("le", ((void *)0)), gen->term->fd);
  else
  {
   n_p = count_char_to_nl(gen, j - i - 1) + 1;
   if (j - n_p - 2 <= 0)
    n_p = n_p + gen->ps1->len;
   tc_move_right(gen, n_p, 1);
   ft_putstr_fd(tgetstr("ku", ((void *)0)), gen->term->fd);
  }
  i--;
 }
}


decompiled_code:
__int64 __fastcall gen_tc_move_left(_QWORD *a1, int a2)
{
__int64 result; // rax
int v3; // er12
int v4; // ebx

result = a1[4];
v3 = *(_DWORD *)(result + 4096);
if ( a2 )
{
v4 = a2;
do
{
tc_move_left(a1, 1, 0);
result = a1[4];
--*(_DWORD *)(result + 4096);
--v4;
}
while ( v4 );
}
*(_DWORD *)(result + 4096) = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, int a2)
{
__int64 result; // rax
int v3; // er12
int v4; // ebx

result = a1[4];
v3 = *(_DWORD *)(result + 4096);
if ( a2 )
{
v4 = a2;
do
{
func3(a1, 1, 0);
result = a1[4];
--*(_DWORD *)(result + 4096);
--v4;
}
while ( v4 );
}
*(_DWORD *)(result + 4096) = v3;
return result;
}

original_code:
void gen_tc_move_left(t_gen *gen, int i)
{
 int tmp;
 tmp = gen->hist->pose_buff;
 while (i--)
 {
  tc_move_left(gen, 1, 0);
  gen->hist->pose_buff--;
 }
 gen->hist->pose_buff = tmp;
}

canonical_original_code:
void gen_tc_move_left(struct s_gen *gen, int i)
{
 int tmp;
 tmp = gen->hist->pose_buff;
 while (i--)
 {
  tc_move_left(gen, 1, 0);
  gen->hist->pose_buff--;
 }
 gen->hist->pose_buff = tmp;
}

variable_types: tmp int


decompiled_code:
void __fastcall erase_list(void *ptr)
{
void *v1; // rbp
void ***v2; // rbx
void **v3; // rdi
void **v4; // rdi

if ( ptr )
{
v1 = ptr;
v2 = (void ***)ptr;
v3 = *(void ***)ptr;
if ( v3 )
{
while ( *v3 )
{
free(*v3);
v4 = *v2;
if ( **v2 )
{
free(v4[1]);
v4 = *v2;
}
free(v4);
v3 = v2[1];
++v2;
if ( !v3 )
goto LABEL_9;
}
}
else
{
LABEL_9:
v3 = 0LL;
}
free(v3);
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void *v1; // rbp
void ***v2; // rbx
void **v3; // rdi
void **v4; // rdi

if ( ptr )
{
v1 = ptr;
v2 = (void ***)ptr;
v3 = *(void ***)ptr;
if ( v3 )
{
while ( *v3 )
{
free(*v3);
v4 = *v2;
if ( **v2 )
{
free(v4[1]);
v4 = *v2;
}
free(v4);
v3 = v2[1];
++v2;
if ( !v3 )
goto LABEL_9;
}
}
else
{
LABEL_9:
v3 = 0LL;
}
free(v3);
free(v1);
}
}

original_code:
void erase_list(t_builtin **list)
{
 t_builtin **tmp;
 int i;
 if (list)
 {
  tmp = list;
  i = 0;
  while (tmp[i] && tmp[i]->name)
  {
   free(tmp[i]->name);
   if (tmp[i]->name)
    free(tmp[i]->help);
   free(tmp[i]);
   i++;
  }
  free(tmp[i]);
  free(list);
 }
}

canonical_original_code:
void erase_list(struct s_builtin **list)
{
 struct s_builtin **tmp;
 int i;
 if (list)
 {
  tmp = list;
  i = 0;
  while (tmp[i] && tmp[i]->name)
  {
   free(tmp[i]->name);
   if (tmp[i]->name)
    free(tmp[i]->help);
   free(tmp[i]);
   i++;
  }
  free(tmp[i]);
  free(list);
 }
}

variable_types: struct s_builtin { char *name; char *help; } **


decompiled_code:
void __fastcall ft_builtin2(_QWORD **a1, __int64 a2, int a3)
{
bool v3; // zf
_QWORD *v4; // rax
_QWORD *v5; // rax
_QWORD *v6; // rax
unsigned int v7; // eax

if ( a3 == 2 )
{
v3 = (unsigned int)ft_strcmp(**a1, &unk_2F7) == 0;
v4 = *a1;
if ( v3 )
{
ft_cd(v4[1], a2);
return;
}
v3 = (unsigned int)ft_strcmp(*v4, "unsetenv") == 0;
v5 = *a1;
if ( v3 )
{
ft_unsetenv(v5[1], a2);
return;
}
if ( !(unsigned int)ft_strcmp(*v5, "pwd") )
goto LABEL_4;
}
else
{
if ( a3 != 3 )
{
if ( a3 == 4 && !(unsigned int)ft_strcmp(**a1, "setenv") )
{
v7 = ft_atoi((*a1)[3]);
ft_setenv((*a1)[1], (*a1)[2], v7, a2);
return;
}
LABEL_4:
*(_DWORD *)(a2 + 48) = 2;
return;
}
v3 = (unsigned int)ft_strcmp(**a1, "putenv") == 0;
v6 = *a1;
if ( v3 )
{
ft_putenv(v6[1], v6[2], a2);
return;
}
if ( (unsigned int)ft_strcmp(*v6, "setenv") )
goto LABEL_4;
}
*(_DWORD *)(a2 + 48) = 3;
}

canonical_decompiled_code:
void __fastcall func1(_QWORD **a1, __int64 a2, int a3)
{
bool v3; // zf
_QWORD *v4; // rax
_QWORD *v5; // rax
_QWORD *v6; // rax
unsigned int v7; // eax

if ( a3 == 2 )
{
v3 = (unsigned int)ft_strcmp(**a1, &unk_2F7) == 0;
v4 = *a1;
if ( v3 )
{
ft_cd(v4[1], a2);
return;
}
v3 = (unsigned int)ft_strcmp(*v4, "unsetenv") == 0;
v5 = *a1;
if ( v3 )
{
ft_unsetenv(v5[1], a2);
return;
}
if ( !(unsigned int)ft_strcmp(*v5, "pwd") )
goto LABEL_4;
}
else
{
if ( a3 != 3 )
{
if ( a3 == 4 && !(unsigned int)ft_strcmp(**a1, "setenv") )
{
v7 = ft_atoi((*a1)[3]);
ft_setenv((*a1)[1], (*a1)[2], v7, a2);
return;
}
LABEL_4:
*(_DWORD *)(a2 + 48) = 2;
return;
}
v3 = (unsigned int)ft_strcmp(**a1, "putenv") == 0;
v6 = *a1;
if ( v3 )
{
ft_putenv(v6[1], v6[2], a2);
return;
}
if ( (unsigned int)ft_strcmp(*v6, "setenv") )
goto LABEL_4;
}
*(_DWORD *)(a2 + 48) = 3;
}

original_code:
void ft_builtin2(t_process *p, t_gen *env, int len)
{
 if (len == 2)
 {
  if (ft_strcmp(p->av[0], "cd") == 0)
   ft_cd(p->av[1], env);
  else if (ft_strcmp(p->av[0], "unsetenv") == 0)
   env = ft_unsetenv(p->av[1], env);
  else if (ft_strcmp(p->av[0], "pwd") == 0)
   env->ret = 2;
  else
   env->ret = 3;
 }
 else if (len == 3)
 {
  if (ft_strcmp(p->av[0], "putenv") == 0)
   env = ft_putenv(p->av[1], p->av[2], env);
  else if (ft_strcmp(p->av[0], "setenv") == 0)
   env->ret = 3;
  else
   env->ret = 2;
 }
 else if (len == 4 && ft_strcmp(p->av[0], "setenv") == 0)
  env = ft_setenv(p->av[1], p->av[2], ft_atoi(p->av[3]), env);
 else
  env->ret = 2;
}

canonical_original_code:
void ft_builtin2(struct s_process *p, struct s_gen *env, int len)
{
 if (len == 2)
 {
  if (ft_strcmp(p->av[0], "cd") == 0)
   ft_cd(p->av[1], env);
  else if (ft_strcmp(p->av[0], "unsetenv") == 0)
   env = ft_unsetenv(p->av[1], env);
  else if (ft_strcmp(p->av[0], "pwd") == 0)
   env->ret = 2;
  else
   env->ret = 3;
 }
 else if (len == 3)
 {
  if (ft_strcmp(p->av[0], "putenv") == 0)
   env = ft_putenv(p->av[1], p->av[2], env);
  else if (ft_strcmp(p->av[0], "setenv") == 0)
   env->ret = 3;
  else
   env->ret = 2;
 }
 else if (len == 4 && ft_strcmp(p->av[0], "setenv") == 0)
  env = ft_setenv(p->av[1], p->av[2], ft_atoi(p->av[3]), env);
 else
  env->ret = 2;
}

variable_types: struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *


decompiled_code:
void __fastcall ft_builtin(_QWORD **status, __int64 a2)
{
_QWORD *v3; // rdi
int v4; // er12
const char *v5; // rdx

v3 = *status;
*(_DWORD *)(a2 + 48) = 0;
v4 = ft_strstrlen(v3);
if ( !(unsigned int)ft_strcmp(**status, "env") )
{
ft_env(status, a2);
LABEL_3:
if ( (unsigned int)(*(_DWORD *)(a2 + 48) - 2) > 1 )
return;
LABEL_7:
error((int)status, 0, v5);
return;
}
if ( (unsigned int)ft_strcmp(**status, "echo") )
{
if ( (unsigned int)ft_strcmp(**status, "help") )
{
if ( v4 == 1 )
{
if ( (unsigned int)ft_strcmp(**status, "pwd") )
{
if ( (unsigned int)ft_strcmp(**status, &unk_2F7) )
{
*(_DWORD *)(a2 + 48) = 3;
goto LABEL_7;
}
ft_cd((*status)[1], a2);
}
else
{
ft_pwd(a2, status);
}
}
else
{
ft_builtin2(status, a2, v4);
}
}
else
{
ft_help(status, *(_QWORD *)(a2 + 40));
}
goto LABEL_3;
}
ft_echo(status);
if ( (unsigned int)(*(_DWORD *)(a2 + 48) - 2) <= 1 )
goto LABEL_7;
}

canonical_decompiled_code:
void __fastcall func2(_QWORD **status, __int64 a2)
{
_QWORD *v3; // rdi
int v4; // er12
const char *v5; // rdx

v3 = *status;
*(_DWORD *)(a2 + 48) = 0;
v4 = ft_strstrlen(v3);
if ( !(unsigned int)ft_strcmp(**status, "env") )
{
ft_env(status, a2);
LABEL_3:
if ( (unsigned int)(*(_DWORD *)(a2 + 48) - 2) > 1 )
return;
LABEL_7:
error((int)status, 0, v5);
return;
}
if ( (unsigned int)ft_strcmp(**status, "echo") )
{
if ( (unsigned int)ft_strcmp(**status, "help") )
{
if ( v4 == 1 )
{
if ( (unsigned int)ft_strcmp(**status, "pwd") )
{
if ( (unsigned int)ft_strcmp(**status, &unk_2F7) )
{
*(_DWORD *)(a2 + 48) = 3;
goto LABEL_7;
}
ft_cd((*status)[1], a2);
}
else
{
ft_pwd(a2, status);
}
}
else
{
func1(status, a2, v4);
}
}
else
{
ft_help(status, *(_QWORD *)(a2 + 40));
}
goto LABEL_3;
}
ft_echo(status);
if ( (unsigned int)(*(_DWORD *)(a2 + 48) - 2) <= 1 )
goto LABEL_7;
}

original_code:
void ft_builtin(t_process *p, t_gen *env)
{
 int len;
 env->ret = 0;
 len = ft_strstrlen(p->av);
 if (ft_strcmp(p->av[0], "env") == 0)
  ft_env(p, env);
 else if (ft_strcmp(p->av[0], "echo") == 0)
  ft_echo(p);
 else if (ft_strcmp(p->av[0], "help") == 0)
  ft_help(p, env->builtin);
 else if (len == 1)
 {
  if (ft_strcmp(p->av[0], "pwd") == 0)
   ft_pwd(env, p);
  else if (ft_strcmp(p->av[0], "cd") == 0)
   ft_cd(p->av[1], env);
  else
   env->ret = 3;
 }
 else
  ft_builtin2(p, env, len);
 if (env->ret == 2 || env->ret == 3)
  error(p, 0);
}

canonical_original_code:
void ft_builtin(struct s_process *p, struct s_gen *env)
{
 int len;
 env->ret = 0;
 len = ft_strstrlen(p->av);
 if (ft_strcmp(p->av[0], "env") == 0)
  ft_env(p, env);
 else if (ft_strcmp(p->av[0], "echo") == 0)
  ft_echo(p);
 else if (ft_strcmp(p->av[0], "help") == 0)
  ft_help(p, env->builtin);
 else if (len == 1)
 {
  if (ft_strcmp(p->av[0], "pwd") == 0)
   ft_pwd(env, p);
  else if (ft_strcmp(p->av[0], "cd") == 0)
   ft_cd(p->av[1], env);
  else
   env->ret = 3;
 }
 else
  ft_builtin2(p, env, len);
 if (env->ret == 2 || env->ret == 3)
  error(p, 0);
}

user_defined_types: struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; }


decompiled_code:
__int64 __fastcall print_key(char *a1)
{
ft_putstr("touche appuyer : [");
ft_putnbr((unsigned int)*a1);
ft_putstr("] [");
ft_putnbr((unsigned int)a1[1]);
ft_putstr("] [");
ft_putnbr((unsigned int)a1[2]);
ft_putstr("] [");
ft_putnbr((unsigned int)a1[3]);
return ft_putstr("];\n");
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
ft_putstr("touche appuyer : [");
ft_putnbr((unsigned int)*a1);
ft_putstr("] [");
ft_putnbr((unsigned int)a1[1]);
ft_putstr("] [");
ft_putnbr((unsigned int)a1[2]);
ft_putstr("] [");
ft_putnbr((unsigned int)a1[3]);
return ft_putstr("];\n");
}

original_code:
void print_key(char *key)
{
 ft_putstr("touche appuyer : [");
 ft_putnbr((int)key[0]);
 ft_putstr("] [");
 ft_putnbr((int)key[1]);
 ft_putstr("] [");
 ft_putnbr((int)key[2]);
 ft_putstr("] [");
 ft_putnbr((int)key[3]);
 ft_putstr("];\n");
}

variable_types:
key
char *


decompiled_code:
__int64 __fastcall ft_sizei(char *a1)
{
__int64 v2; // rdi
__int64 i; // rbx
char v4; // bl
unsigned int v5; // er12

v2 = (unsigned int)*a1;
LODWORD(i) = 0;
if ( (unsigned __int8)v2 <= 0x2Du )
{
v4 = 0x280900000000uLL >> v2;
v2 = (unsigned int)a1[(0x280900000000uLL >> v2) & 1];
LODWORD(i) = v4 & 1;
}
for ( i = (int)i; ; v2 = (unsigned int)a1[i] )
{
v5 = i++;
if ( (int)ft_isdigit(v2) <= 0 )
break;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
__int64 v2; // rdi
__int64 i; // rbx
char v4; // bl
unsigned int v5; // er12

v2 = (unsigned int)*a1;
LODWORD(i) = 0;
if ( (unsigned __int8)v2 <= 0x2Du )
{
v4 = 0x280900000000uLL >> v2;
v2 = (unsigned int)a1[(0x280900000000uLL >> v2) & 1];
LODWORD(i) = v4 & 1;
}
for ( i = (int)i; ; v2 = (unsigned int)a1[i] )
{
v5 = i++;
if ( (int)ft_isdigit(v2) <= 0 )
break;
}
return v5;
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall ft_dellast(char *a1)
{
char v1; // dl
__int64 v2; // rax
int v3; // ecx
__int64 v4; // rbx
__int64 result; // rax

v1 = *a1;
if ( *a1 )
{
v2 = 0LL;
v3 = -1;
do
{
if ( v1 == 47 )
v3 = v2;
v1 = a1[++v2];
}
while ( v1 );
v4 = v3;
result = ft_strdup();
*(_BYTE *)(result + v4) = 0;
}
else
{
result = ft_strdup();
*(_BYTE *)(result - 1) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // dl
__int64 v2; // rax
int v3; // ecx
__int64 v4; // rbx
__int64 result; // rax

v1 = *a1;
if ( *a1 )
{
v2 = 0LL;
v3 = -1;
do
{
if ( v1 == 47 )
v3 = v2;
v1 = a1[++v2];
}
while ( v1 );
v4 = v3;
result = ft_strdup();
*(_BYTE *)(result + v4) = 0;
}
else
{
result = ft_strdup();
*(_BYTE *)(result - 1) = 0;
}
return result;
}

original_code:
static char *ft_dellast(char *s)
{
 int i;
 int save;
 char *ret;
 i = -1;
 save = -1;
 while (s[++i])
  if (s[i] == '/')
   save = i;
 ret = ft_strdup(s);
 ret[save] = '\0';
 return (ret);
}

variable_types: save int

variable_types:
ret
char *


decompiled_code:
__int64 __fastcall ft_red(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rax
void *v4; // rax
__int64 v5; // r13
__int64 v6; // rax

v2 = ft_strlen(a2);
v3 = ft_strlen(a1);
v4 = malloc(v2 + v3 + 3);
if ( !v4 )
return 0LL;
v5 = ft_strcpy(v4, &unk_3DF);
if ( a2 )
{
if ( (unsigned int)ft_strcmp(a2, &unk_419) )
{
v5 = ft_strcat(v5, a2);
if ( a1 )
{
if ( (unsigned int)ft_strcmp(a1, &unk_419) )
v5 = ft_strcat(v5, &unk_3DF);
}
}
}
v6 = ft_strcat(v5, a1);
return ft_trim(v6);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // r13
__int64 v3; // rax
void *v4; // rax
__int64 v5; // r13
__int64 v6; // rax

v2 = ft_strlen(a2);
v3 = ft_strlen(a1);
v4 = malloc(v2 + v3 + 3);
if ( !v4 )
return 0LL;
v5 = ft_strcpy(v4, &unk_3DF);
if ( a2 )
{
if ( (unsigned int)ft_strcmp(a2, &unk_419) )
{
v5 = ft_strcat(v5, a2);
if ( a1 )
{
if ( (unsigned int)ft_strcmp(a1, &unk_419) )
v5 = ft_strcat(v5, &unk_3DF);
}
}
}
v6 = ft_strcat(v5, a1);
return ft_trim(v6);
}

original_code:
static char *ft_red(char *p, char *b)
{
 char *s;
 if (!(s = (char *)malloc((ft_strlen(b) + ft_strlen(p) + 3) * sizeof(char))))
  return (s);
 s = ft_strcpy(s, "/");
 if (b && ft_strcmp(b, "\0") != 0)
 {
  s = ft_strcat(s, b);
  if (p && ft_strcmp(p, "\0") != 0)
   s = ft_strcat(s, "/");
 }
 s = ft_strcat(s, p);
 s = ft_trim(s);
 return (s);
}

variable_types:
p
char *

variable_types:
b
char *


decompiled_code:
int __fastcall ft_checkaccess(char *path, __int64 a2, int a3)
{
__int64 v4; // rax
int result; // eax

if ( access(path, 0) == -1 )
{
*(_DWORD *)(a2 + 48) = 5;
result = ft_printf("cd: %s: no such a file or directory\n", path);
}
else if ( access(path, 1) == -1 )
{
*(_DWORD *)(a2 + 48) = 4;
result = ft_printf("cd: %s: permission denied\n", path);
}
else
{
v4 = ft_setenv("OLDPWD", *(_QWORD *)(*(_QWORD *)a2 + 8LL * a3) + 4LL, 1LL, a2);
ft_setenv("PWD", path, 1LL, v4);
result = chdir(path);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *path, __int64 a2, int a3)
{
__int64 v4; // rax
int result; // eax

if ( access(path, 0) == -1 )
{
*(_DWORD *)(a2 + 48) = 5;
result = ft_printf("cd: %s: no such a file or directory\n", path);
}
else if ( access(path, 1) == -1 )
{
*(_DWORD *)(a2 + 48) = 4;
result = ft_printf("cd: %s: permission denied\n", path);
}
else
{
v4 = ft_setenv("OLDPWD", *(_QWORD *)(*(_QWORD *)a2 + 8LL * a3) + 4LL, 1LL, a2);
ft_setenv("PWD", path, 1LL, v4);
result = chdir(path);
}
return result;
}

original_code:
static void ft_checkaccess(char *s, t_gen *env, int ip)
{
 if (access(s, 0) == -1)
 {
  env->ret = 5;
  ft_printf("cd: %s: no such a file or directory\n", s);
 }
 else if (access(s, 1) == -1)
 {
  env->ret = 4;
  ft_printf("cd: %s: permission denied\n", s);
 }
 else
 {
  env = ft_setenv("OLDPWD", env->env[ip] + 4, 1, env);
  env = ft_setenv("PWD", s, 1, env);
  chdir(s);
 }
}

canonical_original_code:
static void ft_checkaccess(char *s, struct s_gen *env, int ip)
{
 if (access(s, 0) == -1)
 {
  env->ret = 5;
  ft_printf("cd: %s: no such a file or directory\n", s);
 }
 else if (access(s, 1) == -1)
 {
  env->ret = 4;
  ft_printf("cd: %s: permission denied\n", s);
 }
 else
 {
  env = ft_setenv("OLDPWD", env->env[ip] + 4, 1, env);
  env = ft_setenv("PWD", s, 1, env);
  chdir(s);
 }
}

variable_types: ip int


decompiled_code:
int init_ncurse()
{
initscr();
start_color();
curs_set(0);
noecho();
return keypad(stdscr, 1);
}

canonical_decompiled_code:
int func0()
{
initscr();
start_color();
curs_set(0);
noecho();
return keypad(stdscr, 1);
}

original_code:
void init_ncurse(void)
{
 initscr();
 start_color();
 curs_set(0);
 noecho();
 keypad(stdscr, 1);
}

canonical_original_code:
void init_ncurse()
{
 initscr();
 start_color();
 curs_set(0);
 noecho();
 keypad(stdscr, 1);
}


original_code:
int refrech_game(t_env *env)
{
 int i;
 int j;
 int pos;
 sem_block(env);
 i = -1;
 while (++i <= env->mem->size_x)
 {
  j = 0;
  while (j < env->mem->size_y)
  {
   pos = return_pose(env, i, j);
   if (env->map[pos] != 0)
    mvprintw(i, j, "%c", env->map[pos]);
   else
    mvprintw(i, j, "%c", '*');
   j++;
  }
 }
 wrefresh(stdscr);
 return (1);
}

canonical_original_code:
int refrech_game(struct s_env *env)
{
 int i;
 int j;
 int pos;
 sem_block(env);
 i = -1;
 while (++i <= env->mem->size_x)
 {
  j = 0;
  while (j < env->mem->size_y)
  {
   pos = return_pose(env, i, j);
   if (env->map[pos] != 0)
    mvprintw(i, j, "%c", env->map[pos]);
   else
    mvprintw(i, j, "%c", '*');
   j++;
  }
 }
 wrefresh(stdscr);
 return (1);
}

variable_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem { int start; int team_nb; int team_max; struct s_team { char id; char name[60]; char nb_player; } team[700]; int size; int size_x; int size_y; } *mem; char player_id; int wait; int brk; int init; } *

user_defined_types: struct s_env { int verbose; char *team_id; int key; int size_x; int size_y; int seg_id; unsigned long turn; unsigned long size_mem; char *map; int sem_id; struct s_mem *mem; char player_id; int wait; int brk; int init; }

user_defined_types: struct s_mem { int start; int team_nb; int team_max; struct s_team team[700]; int size; int size_x; int size_y; }


decompiled_code:
char *__fastcall init_graph(__int64 a1)
{
int v2; // eax
int v3; // eax
int v4; // edi
_DWORD *v5; // rax
int v6; // ebp
int v7; // eax
int v8; // edi
char *v9; // rax
char *result; // rax

v2 = shmget(*(_DWORD *)(a1 + 16), 0xA9A0uLL, 1408);
*(_DWORD *)(a1 + 28) = v2;
if ( v2 == -1 )
{
endwin();
ft_fprintf(2LL, "please init player brefor\n");
exit(0);
}
v3 = semget(*(_DWORD *)(a1 + 16), 1, 384);
v4 = *(_DWORD *)(a1 + 28);
*(_DWORD *)(a1 + 56) = v3;
v5 = shmat(v4, 0LL, 0);
*(_QWORD *)(a1 + 64) = v5;
v6 = v5[10853];
shmdt(v5);
v7 = shmget(*(_DWORD *)(a1 + 16), v6, 1408);
*(_DWORD *)(a1 + 28) = v7;
v8 = v7;
if ( v7 == -1 )
{
ft_fprintf(2LL, "fail to read memory\n");
v8 = *(_DWORD *)(a1 + 28);
}
v9 = (char *)shmat(v8, 0LL, 0);
*(_QWORD *)(a1 + 64) = v9;
result = v9 + 43425;
*(_QWORD *)(a1 + 48) = result;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1)
{
int v2; // eax
int v3; // eax
int v4; // edi
_DWORD *v5; // rax
int v6; // ebp
int v7; // eax
int v8; // edi
char *v9; // rax
char *result; // rax

v2 = shmget(*(_DWORD *)(a1 + 16), 0xA9A0uLL, 1408);
*(_DWORD *)(a1 + 28) = v2;
if ( v2 == -1 )
{
endwin();
ft_fprintf(2LL, "please init player brefor\n");
exit(0);
}
v3 = semget(*(_DWORD *)(a1 + 16), 1, 384);
v4 = *(_DWORD *)(a1 + 28);
*(_DWORD *)(a1 + 56) = v3;
v5 = shmat(v4, 0LL, 0);
*(_QWORD *)(a1 + 64) = v5;
v6 = v5[10853];
shmdt(v5);
v7 = shmget(*(_DWORD *)(a1 + 16), v6, 1408);
*(_DWORD *)(a1 + 28) = v7;
v8 = v7;
if ( v7 == -1 )
{
ft_fprintf(2LL, "fail to read memory\n");
v8 = *(_DWORD *)(a1 + 28);
}
v9 = (char *)shmat(v8, 0LL, 0);
*(_QWORD *)(a1 + 64) = v9;
result = v9 + 43425;
*(_QWORD *)(a1 + 48) = result;
return result;
}

original_code:
void init_graph(t_env *env)
{
 int size;
 size = 0;
 if ((env->seg_id = shmget (env->key, sizeof(t_mem),
  02000 | 0400 | 0200)) != -1)
 {
  env->sem_id = semget(env->key, 1, 0400 | 0200);
  env->mem = (t_mem *)shmat (env->seg_id, 0, 0);
  size = env->mem->size;
  shmdt (env->mem);
  if ((env->seg_id = shmget (env->key, size,
     02000 | 0400 | 0200)) == -1)
   ft_fprintf(2, "fail to read memory\n");
  env->mem = (t_mem *)shmat (env->seg_id, 0, 0);
  env->map = (char *)env->mem + sizeof(t_mem) + 1;
 }
 else
 {
  endwin();
  ft_fprintf(2, "please init player brefor\n");
  exit(0);
 }
}

canonical_original_code:
void init_graph(struct s_env *env)
{
 int size;
 size = 0;
 if ((env->seg_id = shmget (env->key, sizeof(t_mem),
  02000 | 0400 | 0200)) != -1)
 {
  env->sem_id = semget(env->key, 1, 0400 | 0200);
  env->mem = (struct s_mem *)shmat (env->seg_id, 0, 0);
  size = env->mem->size;
  shmdt (env->mem);
  if ((env->seg_id = shmget (env->key, size,
     02000 | 0400 | 0200)) == -1)
   ft_fprintf(2, "fail to read memory\n");
  env->mem = (struct s_mem *)shmat (env->seg_id, 0, 0);
  env->map = (char *)env->mem + sizeof(t_mem) + 1;
 }
 else
 {
  endwin();
  ft_fprintf(2, "please init player brefor\n");
  exit(0);
 }
}

variable_types: size int

user_defined_types: struct s_team { char id; char name[60]; char nb_player; }


decompiled_code:
void __fastcall __noreturn graphique_mode(sem_t *sem)
{
_DWORD *v1; // rax

init_ncurse();
init_sem(sem);
init_graph((__int64)sem);
while ( wgetch(stdscr) != 10 )
;
send_start(sem);
sem_block(sem);
sem_rel(sem);
sem_wait(sem);
while ( (unsigned int)refrech_game((__int64)sem) != 125 )
{
v1 = (_DWORD *)sem[2].__align;
if ( !*v1 )
break;
if ( *((_DWORD *)&sem[2].__align + 3) == 1 )
{
*v1 = 0;
usleep(0xC350u);
*(_DWORD *)sem[2].__align = 1;
}
sem_rel(sem);
sem_wait(sem);
}
sem_rel(sem);
sem_wait(sem);
endwin();
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(sem_t *sem)
{
_DWORD *v1; // rax

func0();
init_sem(sem);
func2((__int64)sem);
while ( wgetch(stdscr) != 10 )
;
send_start(sem);
sem_block(sem);
sem_rel(sem);
sem_wait(sem);
while ( (unsigned int)func1((__int64)sem) != 125 )
{
v1 = (_DWORD *)sem[2].__align;
if ( !*v1 )
break;
if ( *((_DWORD *)&sem[2].__align + 3) == 1 )
{
*v1 = 0;
usleep(0xC350u);
*(_DWORD *)sem[2].__align = 1;
}
sem_rel(sem);
sem_wait(sem);
}
sem_rel(sem);
sem_wait(sem);
endwin();
exit(0);
}

original_code:
void graphique_mode(t_env *env)
{
 init_ncurse();
 init_sem(env);
 init_graph(env);
 while (wgetch(stdscr) != 10)
  ;
 send_start(env);
 sem_block(env);
 sem_rel(env);
 sem_wait(env);
 while (refrech_game(env) != 125 && env->mem->start)
 {
  if (env->wait == 1)
  {
   env->mem->start = 0;
   usleep(50000);
   env->mem->start = 1;
  }
  sem_rel(env);
  sem_wait(env);
 }
 sem_rel(env);
 sem_wait(env);
 endwin();
 exit(0);
}

canonical_original_code:
void graphique_mode(struct s_env *env)
{
 init_ncurse();
 init_sem(env);
 init_graph(env);
 while (wgetch(stdscr) != 10)
  ;
 send_start(env);
 sem_block(env);
 sem_rel(env);
 sem_wait(env);
 while (refrech_game(env) != 125 && env->mem->start)
 {
  if (env->wait == 1)
  {
   env->mem->start = 0;
   usleep(50000);
   env->mem->start = 1;
  }
  sem_rel(env);
  sem_wait(env);
 }
 sem_rel(env);
 sem_wait(env);
 endwin();
 exit(0);
}


decompiled_code:
int __fastcall do_select(__int64 a1)
{
int v1; // eax
int result; // eax
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

v1 = *(_DWORD *)(a1 + 12);
v3.tv_sec = 0LL;
v3.tv_usec = 1000LL;
result = select(v1 + 1, (fd_set *)(a1 + 1640), (fd_set *)(a1 + 1768), 0LL, &v3);
*(_DWORD *)(a1 + 1632) = result;
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
int v1; // eax
int result; // eax
struct timeval v3; // [rsp+0h] [rbp-18h] BYREF

v1 = *(_DWORD *)(a1 + 12);
v3.tv_sec = 0LL;
v3.tv_usec = 1000LL;
result = select(v1 + 1, (fd_set *)(a1 + 1640), (fd_set *)(a1 + 1768), 0LL, &v3);
*(_DWORD *)(a1 + 1632) = result;
return result;
}

original_code:
void do_select(t_env *env)
{
 struct timeval tv;
 tv.tv_sec = 0;
 tv.tv_usec = 1000;
 env->ret = select(env->max + 1, &env->fd_read, &env->fd_write, ((void *)0), &tv);
}

canonical_original_code:
void do_select(struct s_env *env)
{
 struct timeval tv;
 tv.tv_sec = 0;
 tv.tv_usec = 1000;
 env->ret = select(env->max + 1, &env->fd_read, &env->fd_write, ((void *)0), &tv);
}

variable_types: struct s_env { char *prg_name; int port; int max; int max_fd; struct s_fd { int type; void (*fct_read)(); void (*fct_write)(); char *save; char *nick; int channel; char buff_read[-1]; char buff_write[-1]; } *fds; struct s_chan { int id; char *name; } chan[100]; int ret; struct fd_set { long __fds_bits[-1]; } fd_read; struct fd_set fd_write; } *

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

user_defined_types: struct s_env { char *prg_name; int port; int max; int max_fd; struct s_fd *fds; struct s_chan chan[100]; int ret; struct fd_set fd_read; struct fd_set fd_write; }


variable_types: i int

user_defined_types: struct s_fd { int type; void (*fct_read)(); void (*fct_write)(); char *save; char *nick; int channel; char buff_read[-1]; char buff_write[-1]; }


decompiled_code:
__int64 __fastcall ft_putc(int a1)
{
int v1; // edi
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
v1 = fd_0;
if ( !fd_0 )
{
fd_0 = open("/dev/tty", 1);
v1 = fd_0;
}
write(v1, buf, 1uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // edi
int buf[3]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
v1 = fd_0;
if ( !fd_0 )
{
fd_0 = open("/dev/tty", 1);
v1 = fd_0;
}
write(v1, buf, 1uLL);
return 1LL;
}

original_code:
int ft_putc(int c)
{
 static int fd = 0;
 if (fd == 0)
  fd= open("/dev/tty", 01);
 write(fd, &c, 1);
 return (1);
}

variable_types: c int

variable_types: fd int


decompiled_code:
void __fastcall aff_tlst(__int64 a1, __int64 a2)
{
int v2; // er12
__int64 v3; // rbx
int v4; // ebp
int v5; // er14
char *v6; // rax
char *v7; // rax
char *v8; // rax
char *v9; // rax
char *v10; // rax
char *v11; // rax

v2 = 0;
v3 = a1;
while ( v3 )
{
while ( 1 )
{
v4 = 0;
if ( *(int *)(a2 + 124) >= 0 )
break;
v2 += *(_DWORD *)(a2 + 128) + 2;
}
while ( 1 )
{
v5 = v4++;
v6 = tgetstr("cm", 0LL);
v7 = tgoto(v6, v2, v5);
tputs(v7, 1, (int (*)(int))ft_putc);
if ( *(_DWORD *)(v3 + 12) == 1 )
{
v11 = tgetstr("us", 0LL);
tputs(v11, 1, (int (*)(int))ft_putc);
}
if ( *(_DWORD *)(v3 + 8) == 1 )
break;
tputs(*(const char **)v3, 1, (int (*)(int))ft_putc);
if ( *(_DWORD *)(v3 + 12) == 1 )
goto LABEL_11;
LABEL_5:
v3 = *(_QWORD *)(v3 + 16);
if ( v4 > *(_DWORD *)(a2 + 124) )
goto LABEL_12;
LABEL_6:
if ( !v3 )
return;
}
v8 = tgetstr("mr", 0LL);
tputs(v8, 1, (int (*)(int))ft_putc);
tputs(*(const char **)v3, 1, (int (*)(int))ft_putc);
v9 = tgetstr("me", 0LL);
tputs(v9, 1, (int (*)(int))ft_putc);
if ( *(_DWORD *)(v3 + 12) != 1 )
goto LABEL_5;
LABEL_11:
v10 = tgetstr("ue", 0LL);
tputs(v10, 1, (int (*)(int))ft_putc);
v3 = *(_QWORD *)(v3 + 16);
if ( v4 <= *(_DWORD *)(a2 + 124) )
goto LABEL_6;
LABEL_12:
v2 += *(_DWORD *)(a2 + 128) + 2;
}
}

original_code:
void aff_tlst(t_lstsel *lst, t_sig *sig)
{
 int x[2];
 x[0] = 0;
 while (lst)
 {
  x[1] = 0;
  while (x[1] <= sig->y && lst)
  {
   tputs(tgoto(tgetstr("cm", ((void *)0)), x[0], x[1]++), 1, ft_putc);
   if (lst->pnt == 1)
    tputs(tgetstr("us", ((void *)0)), 1, ft_putc);
   if (lst->sel == 1)
   {
    tputs(tgetstr("mr", ((void *)0)), 1, ft_putc);
    tputs(lst->value, 1, ft_putc);
    tputs(tgetstr("me", ((void *)0)), 1, ft_putc);
   }
   else
    tputs(lst->value, 1, ft_putc);
   if (lst->pnt == 1)
    tputs(tgetstr("ue", ((void *)0)), 1, ft_putc);
   lst = lst->next;
  }
  x[0] = x[0] + sig->max_len + 2;
 }
}

canonical_original_code:
void aff_tlst(struct s_lstsel *lst, struct s_sig *sig)
{
 int x[2];
 x[0] = 0;
 while (lst)
 {
  x[1] = 0;
  while (x[1] <= sig->y && lst)
  {
   tputs(tgoto(tgetstr("cm", ((void *)0)), x[0], x[1]++), 1, ft_putc);
   if (lst->pnt == 1)
    tputs(tgetstr("us", ((void *)0)), 1, ft_putc);
   if (lst->sel == 1)
   {
    tputs(tgetstr("mr", ((void *)0)), 1, ft_putc);
    tputs(lst->value, 1, ft_putc);
    tputs(tgetstr("me", ((void *)0)), 1, ft_putc);
   }
   else
    tputs(lst->value, 1, ft_putc);
   if (lst->pnt == 1)
    tputs(tgetstr("ue", ((void *)0)), 1, ft_putc);
   lst = lst->next;
  }
  x[0] = x[0] + sig->max_len + 2;
 }
}

variable_types: struct s_lstsel { char *value; int sel; int pnt; struct s_lstsel *next; struct s_lstsel *prev; } *

variable_types: struct s_sig { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios termo; int x; int y; int max_len; struct s_lstsel *lst; } *

variable_types:
x
int [2]

user_defined_types: struct s_sig { struct termios term; struct termios termo; int x; int y; int max_len; struct s_lstsel *lst; }


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

result = (unsigned int)(a1 - 66);
if ( (unsigned __int8)(a1 - 66) <= 1u )
return ft_pntnext(a2);
if ( (_BYTE)a1 == 65 || (_BYTE)a1 == 68 )
result = ft_pntprev(a2);
return result;
}

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

result = (unsigned int)(a1 - 66);
if ( (unsigned __int8)(a1 - 66) <= 1u )
return ft_pntnext(a2);
if ( (_BYTE)a1 == 65 || (_BYTE)a1 == 68 )
result = ft_pntprev(a2);
return result;
}

original_code:
void ft_mvflech(char e, t_lstsel *lst)
{
 if (e == 'B' || e == 'C')
  ft_pntnext(lst);
 else if (e == 'A' || e == 'D')
  ft_pntprev(lst);
}

canonical_original_code:
void ft_mvflech(char e, struct s_lstsel *lst)
{
 if (e == 'B' || e == 'C')
  ft_pntnext(lst);
 else if (e == 'A' || e == 'D')
  ft_pntprev(lst);
}

variable_types: e char

user_defined_types: struct s_lstsel { char *value; int sel; int pnt; struct s_lstsel *next; struct s_lstsel *prev; }


original_code:
void ft_selectopt(t_lstsel *lst)
{
 while (lst->pnt != 1)
  lst = lst->next;
 lst->sel = (lst->sel == 0) ? 1 : 0;
 ft_mvflech('B', lst);
}

canonical_original_code:
void ft_selectopt(struct s_lstsel *lst)
{
 while (lst->pnt != 1)
  lst = lst->next;
 lst->sel = (lst->sel == 0) ? 1 : 0;
 ft_mvflech('B', lst);
}


decompiled_code:
__int64 __fastcall search_enemy(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v5 = 0;
ft_printf("je cherche un enemy\n");
search_right(a1, a2, &v5, v6);
search_top(a1, a2, &v5, v6);
search_left(a1, a2, &v5, v6);
search_bot(a1, a2, &v5, v6);
if ( v5 )
{
v3 = (unsigned int)v6[0];
goto LABEL_3;
}
v6[0] = search_hard(a1, a2);
v3 = (unsigned int)v6[0];
if ( v6[0] )
{
LABEL_3:
init_moove(a2, v3);
return 0LL;
}
close_connection(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
int v5; // [rsp+8h] [rbp-20h] BYREF
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
v5 = 0;
ft_printf("je cherche un enemy\n");
search_right(a1, a2, &v5, v6);
search_top(a1, a2, &v5, v6);
search_left(a1, a2, &v5, v6);
search_bot(a1, a2, &v5, v6);
if ( v5 )
{
v3 = (unsigned int)v6[0];
goto LABEL_3;
}
v6[0] = search_hard(a1, a2);
v3 = (unsigned int)v6[0];
if ( v6[0] )
{
LABEL_3:
init_moove(a2, v3);
return 0LL;
}
close_connection(a1, a2);
return 0LL;
}

original_code:
int search_enemy(t_env *env, t_play *p)
{
 int max;
 int act;
 act = 0;
 max = 0;
 ft_printf("je cherche un enemy\n");
 search_right(env, p, &max, &act);
 search_top(env, p, &max, &act);
 search_left(env, p, &max, &act);
 search_bot(env, p, &max, &act);
 if (max == 0 && 0 == (act = search_hard(env, p)))
  close_connection(env, p);
 else
  init_moove(p, act);
 return (0);
}

canonical_original_code:
int search_enemy(struct s_env *env, struct s_play *p)
{
 int max;
 int act;
 act = 0;
 max = 0;
 ft_printf("je cherche un enemy\n");
 search_right(env, p, &max, &act);
 search_top(env, p, &max, &act);
 search_left(env, p, &max, &act);
 search_bot(env, p, &max, &act);
 if (max == 0 && 0 == (act = search_hard(env, p)))
  close_connection(env, p);
 else
  init_moove(p, act);
 return (0);
}

variable_types: struct s_play { struct s_move { int x; int y; } init; struct s_move to_do; int etats; } *

variable_types: max int

variable_types: act int

user_defined_types: struct s_play { struct s_move init; struct s_move to_do; int etats; }


original_code:
int creat_map(t_env *env, int seg_id)
{
 env->mem = (t_mem *)shmat (seg_id, 0, 0);
 ft_bzero(env->mem, env->size_mem);
 env->mem->size = env->size_mem;
 env->mem->team_nb = -1;
 env->mem->size_x = env->size_x;
 env->mem->size_y = env->size_y;
 env->mem->start = 0;
 if (env->verbose == 1)
  ft_printf("seg_id = %d size : %d memoire adresse %p\n",
  seg_id, env->mem->size, env->mem);
 env->map = (char *)env->mem + sizeof(t_mem) + 1;
 ft_bzero(env->map, env->size_y * env->size_x);
 return (1);
}

canonical_original_code:
int creat_map(struct s_env *env, int seg_id)
{
 env->mem = (struct s_mem *)shmat (seg_id, 0, 0);
 ft_bzero(env->mem, env->size_mem);
 env->mem->size = env->size_mem;
 env->mem->team_nb = -1;
 env->mem->size_x = env->size_x;
 env->mem->size_y = env->size_y;
 env->mem->start = 0;
 if (env->verbose == 1)
  ft_printf("seg_id = %d size : %d memoire adresse %p\n",
  seg_id, env->mem->size, env->mem);
 env->map = (char *)env->mem + sizeof(t_mem) + 1;
 ft_bzero(env->map, env->size_y * env->size_x);
 return (1);
}


decompiled_code:
__int64 __fastcall ft_destroyenv(void *ptr)
{
if ( !ptr )
return 1LL;
while ( *(_QWORD *)ptr )
ft_strdel(ptr);
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
if ( !ptr )
return 1LL;
while ( *(_QWORD *)ptr )
ft_strdel(ptr);
free(ptr);
return 1LL;
}

original_code:
int ft_destroyenv(char **env)
{
 int i;
 if (env)
 {
  i = 0;
  while (env[i])
   ft_strdel(&env[i]);
  free(env);
 }
 return (1);
}

variable_types:
env
char **


decompiled_code:
void *__fastcall create_blank_env(_QWORD *a1)
{
int v1; // eax

v1 = ft_strstrlen(*a1);
return malloc(8LL * (v1 + 2));
}

canonical_decompiled_code:
void *__fastcall func1(_QWORD *a1)
{
int v1; // eax

v1 = ft_strstrlen(*a1);
return malloc(8LL * (v1 + 2));
}

original_code:
char **create_blank_env(t_gen *gen)
{
 char **new_env;
 int size;
 size = ft_strstrlen(gen->env);
 if (!(new_env = (char **)malloc(sizeof(char *) * (size + 2))) && gen->ret == 1)
  return (((void *)0));
 return (new_env);
}

canonical_original_code:
char **create_blank_env(struct s_gen *gen)
{
 char **new_env;
 int size;
 size = ft_strstrlen(gen->env);
 if (!(new_env = (char **)malloc(sizeof(char *) * (size + 2))) && gen->ret == 1)
  return (((void *)0));
 return (new_env);
}

variable_types: struct s_gen { char **env; char **env_orig; struct s_ps1 { char *env; char *aff; int len; } *ps1; struct s_term { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } term; struct termios term_ori; int fd; int wait; char **key; } *term; struct s_hist { char value[4096]; int pose_buff; int len; int modif; char buff[4096]; struct s_hist *next; struct s_hist *prev; int number; } *hist; struct s_builtin { char *name; char *help; } **builtin; int ret; int status; char *path; int pid_fork; } *

return_type: char **

user_defined_types: struct s_gen { char **env; char **env_orig; struct s_ps1 *ps1; struct s_term *term; struct s_hist *hist; struct s_builtin **builtin; int ret; int status; char *path; int pid_fork; }

user_defined_types: struct s_term { struct termios term; struct termios term_ori; int fd; int wait; char **key; }


decompiled_code:
void *__fastcall active_new_page(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 v2; // r12
unsigned __int64 v3; // rax
size_t v4; // rbp
void *v5; // rax
void *v7; // [rsp+8h] [rbp-20h]

v1 = a1 + 64;
v2 = getpagesize();
do
{
v3 = v1 / v2;
++v1;
v4 = v2 * (v3 + 1);
v5 = mmap(0LL, v4, 3, 34, -1, 0LL);
}
while ( v5 == (void *)-1LL );
v7 = v5;
ft_bzero(v5, v4);
return v7;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 v2; // r12
unsigned __int64 v3; // rax
size_t v4; // rbp
void *v5; // rax
void *v7; // [rsp+8h] [rbp-20h]

v1 = a1 + 64;
v2 = getpagesize();
do
{
v3 = v1 / v2;
++v1;
v4 = v2 * (v3 + 1);
v5 = mmap(0LL, v4, 3, 34, -1, 0LL);
}
while ( v5 == (void *)-1LL );
v7 = v5;
ft_bzero(v5, v4);
return v7;
}

original_code:
void *active_new_page(size_t size)
{
 void *plen;
 size_t len;
 len = size + sizeof(t_plage) + 32;
 len = (len / getpagesize()) + 1;
 if ((plen = mmap(((void *)0), getpagesize() * len,
  0x1 | 0x2, 0x20 | 0x02, -1, 0)) == ((void *) -1))
  return (active_new_page(size + 1));
 ft_bzero(plen, getpagesize() * len);
 return (plen);
}

canonical_original_code:
void *active_new_page(unsigned long size)
{
 void *plen;
 unsigned long len;
 len = size + sizeof(t_plage) + 32;
 len = (len / getpagesize()) + 1;
 if ((plen = mmap(((void *)0), getpagesize() * len,
  0x1 | 0x2, 0x20 | 0x02, -1, 0)) == ((void *) -1))
  return (active_new_page(size + 1));
 ft_bzero(plen, getpagesize() * len);
 return (plen);
}

variable_types:
size
unsigned long

variable_types:
plen
void *

variable_types:
len
unsigned long


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

if ( a1 )
{
v1 = a1;
do
{
while ( *(_BYTE *)(v1 + 8) != 1 )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return result;
}
ft_putpoint(v1 + 32);
ft_putstr(&unk_1D7);
ft_putpoint(v1 + *(_QWORD *)v1 + 32);
ft_putstr(&unk_1DB);
ft_putnbr((unsigned int)(*(_DWORD *)v1 - 32));
result = ft_putstr(" octets\n");
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
return result;
}

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

if ( a1 )
{
v1 = a1;
do
{
while ( *(_BYTE *)(v1 + 8) != 1 )
{
v1 = *(_QWORD *)(v1 + 24);
if ( !v1 )
return result;
}
ft_putpoint(v1 + 32);
ft_putstr(&unk_1D7);
ft_putpoint(v1 + *(_QWORD *)v1 + 32);
ft_putstr(&unk_1DB);
ft_putnbr((unsigned int)(*(_DWORD *)v1 - 32));
result = ft_putstr(" octets\n");
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
return result;
}

original_code:
void print_table(t_plage *tmp)
{
 while (tmp)
 {
  if (tmp->aloued == 1)
  {
   ft_putpoint((unsigned long int)((char *)tmp + sizeof(t_plage)));
   ft_putstr(" - ");
   ft_putpoint((unsigned long int)((char *)tmp
    + (sizeof(t_plage) + tmp->len)));
   ft_putstr(" : ");
   ft_putnbr(tmp->len - sizeof(t_plage));
   ft_putstr(" octets\n");
  }
  tmp = tmp->next;
 }
}

canonical_original_code:
void print_table(struct s_plage *tmp)
{
 while (tmp)
 {
  if (tmp->aloued == 1)
  {
   ft_putpoint((unsigned long)((char *)tmp + sizeof(t_plage)));
   ft_putstr(" - ");
   ft_putpoint((unsigned long)((char *)tmp
    + (sizeof(t_plage) + tmp->len)));
   ft_putstr(" : ");
   ft_putnbr(tmp->len - sizeof(t_plage));
   ft_putstr(" octets\n");
  }
  tmp = tmp->next;
 }
}

variable_types: struct s_plage { unsigned long len; char aloued; void *prev; void *next; } *