decompiled_code:
__int64 __fastcall sh_wait_new_commande(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
__int64 v4; // r12
char buf[30]; // [rsp+Ah] [rbp-1Eh] BYREF

init_term();
v2 = recup_term();
parse_ps1(a1);
v3 = *(_QWORD *)(v2 + 152);
*(_DWORD *)(v2 + 124) = *(_DWORD *)(a1 + 16);
*(_QWORD *)(v2 + 152) = add_or_clean(v3);
ft_bzero(buf, 5LL);
while ( (unsigned int)ft_stomp(buf, v2) )
{
ft_bzero(buf, 5LL);
buf[(int)(read(*(_DWORD *)(v2 + 120), buf, 5uLL) + 1)] = 0;
}
v4 = ft_parse_cmd(*(_QWORD *)(v2 + 152) + 4108LL);
close_term();
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v2; // rbx
__int64 v3; // rdi
__int64 v4; // r12
char buf[30]; // [rsp+Ah] [rbp-1Eh] BYREF

init_term();
v2 = recup_term();
parse_ps1(a1);
v3 = *(_QWORD *)(v2 + 152);
*(_DWORD *)(v2 + 124) = *(_DWORD *)(a1 + 16);
*(_QWORD *)(v2 + 152) = add_or_clean(v3);
ft_bzero(buf, 5LL);
while ( (unsigned int)ft_stomp(buf, v2) )
{
ft_bzero(buf, 5LL);
buf[(int)(read(*(_DWORD *)(v2 + 120), buf, 5uLL) + 1)] = 0;
}
v4 = ft_parse_cmd(*(_QWORD *)(v2 + 152) + 4108LL);
close_term();
return v4;
}

original_code:
t_cmd *sh_wait_new_commande(t_env *env, t_cmd *cmd)
{
 int ret;
 t_term *term;
 char buff[6];
 ret = 0;
 init_term();
 term = recup_term();
  parse_ps1(env);
 term->ps1_len = env->ps1_len;
 term->hist = add_or_clean(term->hist);
 ft_bzero(buff, 5);
 while (ft_stomp(buff, term))
 {
  ft_bzero(buff, 5);
  ret = read(term->fd, buff, 5);
  buff[ret + 1] = '\0';
 }
 cmd = ft_parse_cmd(term->hist->buff);
 close_term();
 return (cmd);
}

canonical_original_code:
struct s_cmd *sh_wait_new_commande(struct s_env *env, struct s_cmd *cmd)
{
 int ret;
 struct s_term *term;
 char buff[6];
 ret = 0;
 init_term();
 term = recup_term();
  parse_ps1(env);
 term->ps1_len = env->ps1_len;
 term->hist = add_or_clean(term->hist);
 ft_bzero(buff, 5);
 while (ft_stomp(buff, term))
 {
  ft_bzero(buff, 5);
  ret = read(term->fd, buff, 5);
  buff[ret + 1] = '\0';
 }
 cmd = ft_parse_cmd(term->hist->buff);
 close_term();
 return (cmd);
}

variable_types: struct s_env { char **path; char *ps1; int ps1_len; char *home; char pwd[4096]; char **environ; int pid; } *

variable_types:
cmd
struct s_cmd *

variable_types: ret int

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:
buff
char [6]


original_code:
void env_change_dir(char **av, t_env *env)
{
 char *tmp;
 av[1] = ft_strjoin("OLDPWD=", env->pwd);
 ft_setenv(av, env);
 getcwd(av[1], 4096);
 tmp = ft_strjoin("PWD=", av[1]);
 free(av[1]);
 av[1] = tmp;
 ft_setenv(av, env);
 free(av[1]);
}

canonical_original_code:
void env_change_dir(char **av, struct s_env *env)
{
 char *tmp;
 av[1] = ft_strjoin("OLDPWD=", env->pwd);
 ft_setenv(av, env);
 getcwd(av[1], 4096);
 tmp = ft_strjoin("PWD=", av[1]);
 free(av[1]);
 av[1] = tmp;
 ft_setenv(av, env);
 free(av[1]);
}

variable_types:
av
char **

variable_types:
tmp
char *

return_type: void

user_defined_types: struct s_env { char **path; char *ps1; int ps1_len; char *home; char pwd[4096]; char **environ; int pid; }


decompiled_code:
void __fastcall sh_cd(__int64 a1, __int64 a2)
{
const char *v3; // rdi
const char *v4; // rdi
void *v5; // rax
char *v6; // rax

v3 = *(const char **)(a1 + 8);
if ( v3 )
{
if ( *v3 == 126 )
{
v5 = (void *)ft_strjoin(*(_QWORD *)(a2 + 24), v3 + 1);
*(_QWORD *)(a1 + 8) = v5;
free(v5);
v3 = *(const char **)(a1 + 8);
}
else if ( *v3 == 45 )
{
v6 = getenv("OLDPWD=");
*(_QWORD *)(a1 + 8) = v6;
v3 = v6;
}
if ( chdir(v3) )
goto LABEL_6;
}
else
{
v4 = *(const char **)(a2 + 24);
*(_QWORD *)(a1 + 8) = v4;
if ( chdir(v4) )
{
LABEL_6:
ft_puterr("cd : Dossier innaxesible\n");
return;
}
}
env_change_dir(a1, a2);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2)
{
const char *v3; // rdi
const char *v4; // rdi
void *v5; // rax
char *v6; // rax

v3 = *(const char **)(a1 + 8);
if ( v3 )
{
if ( *v3 == 126 )
{
v5 = (void *)ft_strjoin(*(_QWORD *)(a2 + 24), v3 + 1);
*(_QWORD *)(a1 + 8) = v5;
free(v5);
v3 = *(const char **)(a1 + 8);
}
else if ( *v3 == 45 )
{
v6 = getenv("OLDPWD=");
*(_QWORD *)(a1 + 8) = v6;
v3 = v6;
}
if ( chdir(v3) )
goto LABEL_6;
}
else
{
v4 = *(const char **)(a2 + 24);
*(_QWORD *)(a1 + 8) = v4;
if ( chdir(v4) )
{
LABEL_6:
ft_puterr("cd : Dossier innaxesible\n");
return;
}
}
func1(a1, a2);
}

original_code:
void sh_cd(char **av, t_env *env)
{
 char *tmp;
 if (av[1])
 {
  if (av[1][0] == '~')
  {
   tmp = ft_strjoin(env->home, av[1] + 1);
   av[1] = tmp;
   free(tmp);
  }
  else if (av[1][0] == '-')
   av[1] = getenv("OLDPWD=");
  if (chdir(av[1]))
   ft_puterr("cd : Dossier innaxesible\n");
  else
   env_change_dir(av, env);
 }
 else
 {
  av[1] = env->home;
  if (chdir(av[1]))
   ft_puterr("cd : Dossier innaxesible\n");
  else
   env_change_dir(av, env);
 }
}

canonical_original_code:
void sh_cd(char **av, struct s_env *env)
{
 char *tmp;
 if (av[1])
 {
  if (av[1][0] == '~')
  {
   tmp = ft_strjoin(env->home, av[1] + 1);
   av[1] = tmp;
   free(tmp);
  }
  else if (av[1][0] == '-')
   av[1] = getenv("OLDPWD=");
  if (chdir(av[1]))
   ft_puterr("cd : Dossier innaxesible\n");
  else
   env_change_dir(av, env);
 }
 else
 {
  av[1] = env->home;
  if (chdir(av[1]))
   ft_puterr("cd : Dossier innaxesible\n");
  else
   env_change_dir(av, env);
 }
}


decompiled_code:
__int64 __fastcall sh_exec(_BYTE *a1, char *const *a2, __int64 a3)
{
_QWORD *i; // rbp
char *v5; // r15
int v6; // ebx

for ( i = *(_QWORD **)a3; *(_BYTE *)*i; ++i )
{
v5 = (char *)ft_strjoin(*i, a1);
v6 = execve(v5, a2, *(char *const **)(a3 + 4128));
if ( !v6 )
{
free(v5);
return 0LL;
}
if ( !i[1] && *a1 && execve(*(const char **)a2, a2, *(char *const **)(a3 + 4128)) == v6 )
{
ft_puterr("ft_sh2 : command invalide : ");
ft_puterr(a1);
ft_puterr("\n");
free(v5);
exit(-1);
}
free(v5);
if ( v6 >= 0 )
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1, char *const *a2, __int64 a3)
{
_QWORD *i; // rbp
char *v5; // r15
int v6; // ebx

for ( i = *(_QWORD **)a3; *(_BYTE *)*i; ++i )
{
v5 = (char *)ft_strjoin(*i, a1);
v6 = execve(v5, a2, *(char *const **)(a3 + 4128));
if ( !v6 )
{
free(v5);
return 0LL;
}
if ( !i[1] && *a1 && execve(*(const char **)a2, a2, *(char *const **)(a3 + 4128)) == v6 )
{
ft_puterr("ft_sh2 : command invalide : ");
ft_puterr(a1);
ft_puterr("\n");
free(v5);
exit(-1);
}
free(v5);
if ( v6 >= 0 )
return 0LL;
}
return 0LL;
}

original_code:
int sh_exec(char *name, char **av, t_env *env)
{
 int ret_exe;
 int i;
 char *tmp;
 char **path;
 ret_exe = -1;
 i = 0;
 path = env->path;
 while (ret_exe < 0 && *path[i] != 0)
 {
  tmp = ft_strjoin(path[i], name);
  if ((ret_exe = execve(tmp, av, env->environ))
    && path[++i] == 0 && name[0] != '\0'
    && (ret_exe == execve(av[0], av, env->environ)))
  {
   ft_puterr("ft_sh2 : command invalide : ");
   ft_puterr(name);
   ft_puterr("\n");
   free(tmp);
   exit (-1);
  }
 free(tmp);
 }
 return (0);
}

canonical_original_code:
int sh_exec(char *name, char **av, struct s_env *env)
{
 int ret_exe;
 int i;
 char *tmp;
 char **path;
 ret_exe = -1;
 i = 0;
 path = env->path;
 while (ret_exe < 0 && *path[i] != 0)
 {
  tmp = ft_strjoin(path[i], name);
  if ((ret_exe = execve(tmp, av, env->environ))
    && path[++i] == 0 && name[0] != '\0'
    && (ret_exe == execve(av[0], av, env->environ)))
  {
   ft_puterr("ft_sh2 : command invalide : ");
   ft_puterr(name);
   ft_puterr("\n");
   free(tmp);
   exit (-1);
  }
 free(tmp);
 }
 return (0);
}

variable_types:
name
char *

variable_types: i int

variable_types:
path
char **

return_type: int


decompiled_code:
__int64 __fastcall sh_execute(_BYTE *a1, char *const *a2, __int64 a3)
{
__pid_t v4; // eax
__int64 result; // rax

v4 = fork();
*(_DWORD *)(a3 + 4136) = v4;
if ( v4 < 0 )
{
ft_puterr("fork fail");
result = 1LL;
}
else
{
if ( v4 )
wait(0LL);
else
sh_exec(a1, a2, a3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, char *const *a2, __int64 a3)
{
__pid_t v4; // eax
__int64 result; // rax

v4 = fork();
*(_DWORD *)(a3 + 4136) = v4;
if ( v4 < 0 )
{
ft_puterr("fork fail");
result = 1LL;
}
else
{
if ( v4 )
wait(0LL);
else
func3(a1, a2, a3);
result = 1LL;
}
return result;
}

original_code:
int sh_execute(char *name, char **av, t_env *env)
{
 if ((env->pid = fork()) < 0)
  ft_puterr("fork fail");
 else if (env->pid == 0)
 {
  sh_exec(name, av , env);
 }
 else
 {
  wait(((void *)0));
 }
 return (1);
}

canonical_original_code:
int sh_execute(char *name, char **av, struct s_env *env)
{
 if ((env->pid = fork()) < 0)
  ft_puterr("fork fail");
 else if (env->pid == 0)
 {
  sh_exec(name, av , env);
 }
 else
 {
  wait(((void *)0));
 }
 return (1);
}


decompiled_code:
void __fastcall ft_free_cmd(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[4];
free(*v2);
free(v2[1]);
free(v2[2]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

if ( ptr )
{
v1 = (void **)ptr;
do
{
v2 = v1;
v1 = (void **)v1[4];
free(*v2);
free(v2[1]);
free(v2[2]);
free(v2);
}
while ( v1 );
}
}

original_code:
void ft_free_cmd(t_cmd *cmd)
{
 t_cmd *tmp;
 while (cmd)
 {
  tmp = cmd;
  cmd = cmd->next;
  free(tmp->name);
  free(tmp->value);
  free(tmp->file);
  free(tmp);
 }
}

canonical_original_code:
void ft_free_cmd(struct s_cmd *cmd)
{
 struct s_cmd *tmp;
 while (cmd)
 {
  tmp = cmd;
  cmd = cmd->next;
  free(tmp->name);
  free(tmp->value);
  free(tmp->file);
  free(tmp);
 }
}

variable_types: struct s_cmd { char *name; char *value; char *file; int sfd; struct s_cmd *next; } *


decompiled_code:
void *return_env()
{
void *result; // rax

result = (void *)env_0;
if ( !env_0 )
{
result = malloc(0x1030uLL);
env_0 = (__int64)result;
}
return result;
}

canonical_decompiled_code:
void *func3()
{
void *result; // rax

result = (void *)env_0;
if ( !env_0 )
{
result = malloc(0x1030uLL);
env_0 = (__int64)result;
}
return result;
}

original_code:
t_env *return_env(void)
{
 static t_env *env = ((void *)0);
 if (env == ((void *)0))
  env = (t_env *)malloc(sizeof(t_env));
 return (env);
}

canonical_original_code:
struct s_env *return_env()
{
 static struct s_env *env = ((void *)0);
 if (env == ((void *)0))
  env = (struct s_env *)malloc(sizeof(t_env));
 return (env);
}

return_type: struct s_env { char **path; char *ps1; int ps1_len; char *home; char pwd[4096]; char **environ; int pid; } *


decompiled_code:
__int64 __fastcall ft_getenv(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rbx
int v3; // eax
__int64 v4; // rdi
__int64 v5; // rbp

v2 = a1;
v3 = ft_strlen(a2);
v4 = *a1;
v5 = v3;
if ( !v4 )
return 0LL;
while ( !*(_BYTE *)(v4 + v5) || (unsigned int)ft_strncmp(v4, a2, v5) )
{
v4 = v2[1];
++v2;
if ( !v4 )
return 0LL;
}
return *v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rbx
int v3; // eax
__int64 v4; // rdi
__int64 v5; // rbp

v2 = a1;
v3 = ft_strlen(a2);
v4 = *a1;
v5 = v3;
if ( !v4 )
return 0LL;
while ( !*(_BYTE *)(v4 + v5) || (unsigned int)ft_strncmp(v4, a2, v5) )
{
v4 = v2[1];
++v2;
if ( !v4 )
return 0LL;
}
return *v2;
}

original_code:
char *ft_getenv(char **env, char *search)
{
 int i;
 int len;
 i = 0;
 len = ft_strlen(search);
 while (env[i])
 {
  if (*(env[i] + len) && !ft_strncmp(env[i], search, len))
   return (env[i]);
  i++;
 }
 return (((void *)0));
}

variable_types:
env
char **

variable_types:
search
char *

variable_types: len int

return_type: char *


original_code:
void parse_ps1(t_env *env)
{
 char *name;
 char **ret;
 int i;
 i = 0;
 if (env->ps1 == ((void *)0))
 {
  if ((name = ft_getenv(env->environ, "USER")) == ((void *)0))
   name = ft_strdup("(-_-)");
  ret = ft_strsplit(env->pwd, '/');
  while (ret[i])
   i++;
  env->ps1_len = ft_strlen(name + 5) + ft_strlen(ret[--i]) + 8;
  env->ps1 = (char *)malloc(sizeof(char) * env->ps1_len + 1);
  env->ps1 = ft_strcat(env->ps1, "\033[0m[\033[31m");
  env->ps1 = ft_strcat(env->ps1, name + 5);
  env->ps1 = ft_strcat(env->ps1, "\033[0m]-[\033[32m/");
  env->ps1 = ft_strcat(env->ps1, ret[i]);
  env->ps1 = ft_strcat(env->ps1, "\033[0m]>");
  env->ps1_len = ft_strlen(env->ps1);
  while (i > -1)
   free(ret[i--]);
  free(ret);
 }
 ft_putstr(env->ps1);
}

canonical_original_code:
void parse_ps1(struct s_env *env)
{
 char *name;
 char **ret;
 int i;
 i = 0;
 if (env->ps1 == ((void *)0))
 {
  if ((name = ft_getenv(env->environ, "USER")) == ((void *)0))
   name = ft_strdup("(-_-)");
  ret = ft_strsplit(env->pwd, '/');
  while (ret[i])
   i++;
  env->ps1_len = ft_strlen(name + 5) + ft_strlen(ret[--i]) + 8;
  env->ps1 = (char *)malloc(sizeof(char) * env->ps1_len + 1);
  env->ps1 = ft_strcat(env->ps1, "\033[0m[\033[31m");
  env->ps1 = ft_strcat(env->ps1, name + 5);
  env->ps1 = ft_strcat(env->ps1, "\033[0m]-[\033[32m/");
  env->ps1 = ft_strcat(env->ps1, ret[i]);
  env->ps1 = ft_strcat(env->ps1, "\033[0m]>");
  env->ps1_len = ft_strlen(env->ps1);
  while (i > -1)
   free(ret[i--]);
  free(ret);
 }
 ft_putstr(env->ps1);
}

variable_types:
ret
char **


main

canonical_name: main

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

if ( argc && argv )
v3 = return_env();
v3[516] = envp;
*((_DWORD *)v3 + 1034) = 0;
copy_env(v3, argv);
parse_environ(v3);
start();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // rbp

if ( argc && argv )
v3 = func3();
v3[516] = envp;
*((_DWORD *)v3 + 1034) = 0;
copy_env(v3, argv);
parse_environ(v3);
start();
return 0;
}

original_code:
int main(int ac, char **av, char **environ)
{
 t_env *env;
 if (ac && av)
  env = return_env();
 env->environ = environ;
 env->pid = 0;
 copy_env(env);
 parse_environ(env);
 start();
 return (0);
}

canonical_original_code:
int main(int ac, char **av, char **environ)
{
 struct s_env *env;
 if (ac && av)
  env = return_env();
 env->environ = environ;
 env->pid = 0;
 copy_env(env);
 parse_environ(env);
 start();
 return (0);
}

variable_types: ac int

variable_types:
environ
char **


decompiled_code:
void *ft_init_sig()
{
int v1; // eax

if ( first_time_1 )
{
first_time_1 = 0;
dword_278 = tgetnum("co");
v1 = tgetnum("li");
qword_288 = 0LL;
dword_27C = v1;
}
return &sig_0;
}

canonical_decompiled_code:
void *func0()
{
int v1; // eax

if ( first_time_1 )
{
first_time_1 = 0;
dword_278 = tgetnum("co");
v1 = tgetnum("li");
qword_288 = 0LL;
dword_27C = v1;
}
return &sig_0;
}

original_code:
t_sig *ft_init_sig(void)
{
 static t_sig sig;
 static int first_time = 1;
 if (first_time)
 {
  first_time = 0;
  sig.x = tgetnum("co");
  sig.y = tgetnum("li");
  sig.lst = ((void *)0);
 }
 return (&sig);
}

canonical_original_code:
struct s_sig *ft_init_sig()
{
 static struct s_sig sig;
 static int first_time = 1;
 if (first_time)
 {
  first_time = 0;
  sig.x = tgetnum("co");
  sig.y = tgetnum("li");
  sig.lst = ((void *)0);
 }
 return (&sig);
}

return_type: 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 { char *value; int sel; int pnt; struct s_lstsel *next; struct s_lstsel *prev; } *lst; } *

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_close(const struct termios *a1)
{
char *v1; // rax
char *v2; // rax

v1 = tgetstr("te", 0LL);
tputs(v1, 1, (int (*)(int))&ft_putc);
v2 = tgetstr("ve", 0LL);
tputs(v2, 1, (int (*)(int))&ft_putc);
tcsetattr(0, 0, a1 + 1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const struct termios *a1)
{
char *v1; // rax
char *v2; // rax

v1 = tgetstr("te", 0LL);
tputs(v1, 1, (int (*)(int))&ft_putc);
v2 = tgetstr("ve", 0LL);
tputs(v2, 1, (int (*)(int))&ft_putc);
tcsetattr(0, 0, a1 + 1);
return 0LL;
}

original_code:
int ft_close(t_sig *sig)
{
 tputs(tgetstr("te", ((void *)0)), 1, ft_putc);
 tputs(tgetstr("ve", ((void *)0)), 1, ft_putc);
 tcsetattr(0, 0, &sig->termo);
 return (0);
}

canonical_original_code:
int ft_close(struct s_sig *sig)
{
 tputs(tgetstr("te", ((void *)0)), 1, ft_putc);
 tputs(tgetstr("ve", ((void *)0)), 1, ft_putc);
 tcsetattr(0, 0, &sig->termo);
 return (0);
}

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 { char *value; int sel; int pnt; struct s_lstsel *next; struct s_lstsel *prev; } *lst; } *


decompiled_code:
__int64 __fastcall ft_start(struct termios *a1)
{
__int64 v1; // r12
struct termios *i; // rbp
__int64 v3; // rax

for ( i = init_term(a1); ; aff_lst(v3, i) )
{
v3 = ft_read(i);
*(_QWORD *)&i[2].c_line = v3;
if ( !v3 )
break;
v1 = v3;
}
ft_close(i);
return affret(v1);
}

canonical_decompiled_code:
__int64 __fastcall func3(struct termios *a1)
{
__int64 v1; // r12
struct termios *i; // rbp
__int64 v3; // rax

for ( i = func2(a1); ; aff_lst(v3, i) )
{
v3 = ft_read(i);
*(_QWORD *)&i[2].c_line = v3;
if ( !v3 )
break;
v1 = v3;
}
func1(i);
return affret(v1);
}

original_code:
void ft_start(t_sig *sig)
{
 t_lstsel *last_lst;
 sig = init_term(sig);
 while ((sig->lst = ft_read(sig)))
 {
  last_lst = sig->lst;
  aff_lst(sig->lst, sig);
 }
 ft_close (sig);
 affret(last_lst);
}

canonical_original_code:
void ft_start(struct s_sig *sig)
{
 struct s_lstsel *last_lst;
 sig = init_term(sig);
 while ((sig->lst = ft_read(sig)))
 {
  last_lst = sig->lst;
  aff_lst(sig->lst, sig);
 }
 ft_close (sig);
 affret(last_lst);
}

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

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


decompiled_code:
struct termios *__fastcall init_term(struct termios *termios_p)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
struct termios *result; // rax
char v5[2072]; // [rsp+0h] [rbp-818h] BYREF

v1 = getenv("TERM");
if ( v1 )
{
if ( tgetent(v5, v1) <= 0 )
ft_perr("no acces termtype");
tcgetattr(0, termios_p + 1);
ft_memcpy(termios_p, &termios_p[1], 60LL);
termios_p->c_lflag &= 0xFFFFFFF5;
v2 = tgetstr("ti", 0LL);
tputs(v2, 1, (int (*)(int))&ft_putc);
v3 = tgetstr("vi", 0LL);
tputs(v3, 1, (int (*)(int))&ft_putc);
tcsetattr(0, 0, termios_p);
aff_lst(*(_QWORD *)&termios_p[2].c_line, termios_p);
result = termios_p;
}
else
{
ft_perr("term not found in env");
result = termios_p;
}
return result;
}

canonical_decompiled_code:
struct termios *__fastcall func2(struct termios *termios_p)
{
char *v1; // rax
char *v2; // rax
char *v3; // rax
struct termios *result; // rax
char v5[2072]; // [rsp+0h] [rbp-818h] BYREF

v1 = getenv("TERM");
if ( v1 )
{
if ( tgetent(v5, v1) <= 0 )
ft_perr("no acces termtype");
tcgetattr(0, termios_p + 1);
ft_memcpy(termios_p, &termios_p[1], 60LL);
termios_p->c_lflag &= 0xFFFFFFF5;
v2 = tgetstr("ti", 0LL);
tputs(v2, 1, (int (*)(int))&ft_putc);
v3 = tgetstr("vi", 0LL);
tputs(v3, 1, (int (*)(int))&ft_putc);
tcsetattr(0, 0, termios_p);
aff_lst(*(_QWORD *)&termios_p[2].c_line, termios_p);
result = termios_p;
}
else
{
ft_perr("term not found in env");
result = termios_p;
}
return result;
}

original_code:
t_sig *init_term(t_sig *sig)
{
 char *termtype;
 char buffer[2048];
 int ret;
 if ((termtype = getenv("TERM")) == 0)
 {
  ft_perr("term not found in env");
  return (sig);
 }
 if ((ret = tgetent(buffer, termtype)) < 1)
  ft_perr("no acces termtype");
 tcgetattr(0, &sig->termo);
 ft_memcpy(&sig->term, &sig->termo, sizeof(struct termios));
 sig->term.c_lflag &= ~(0000002 | 0000010);
 tputs(tgetstr("ti", ((void *)0)), 1, ft_putc);
 tputs(tgetstr("vi", ((void *)0)), 1, ft_putc);
 tcsetattr(0, 0, &sig->term);
 aff_lst(sig->lst, sig);
 return (sig);
}

canonical_original_code:
struct s_sig *init_term(struct s_sig *sig)
{
 char *termtype;
 char buffer[2048];
 int ret;
 if ((termtype = getenv("TERM")) == 0)
 {
  ft_perr("term not found in env");
  return (sig);
 }
 if ((ret = tgetent(buffer, termtype)) < 1)
  ft_perr("no acces termtype");
 tcgetattr(0, &sig->termo);
 ft_memcpy(&sig->term, &sig->termo, sizeof(struct termios));
 sig->term.c_lflag &= ~(0000002 | 0000010);
 tputs(tgetstr("ti", ((void *)0)), 1, ft_putc);
 tputs(tgetstr("vi", ((void *)0)), 1, ft_putc);
 tcsetattr(0, 0, &sig->term);
 aff_lst(sig->lst, sig);
 return (sig);
}

variable_types:
sig
struct s_sig *

variable_types:
termtype
char *

variable_types:
buffer
char [2048]

variable_types: ret int

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


decompiled_code:
__int64 __fastcall ft_nbword(char *a1, char a2)
{
char v2; // al
unsigned int v3; // er8

v2 = *a1;
v3 = 0;
while ( v2 )
{
if ( a2 == v2 )
{
v2 = *++a1;
}
else
{
v2 = *a1;
++v3;
if ( !*a1 )
return v3;
if ( a2 != v2 )
{
while ( 1 )
{
v2 = *++a1;
if ( v2 == a2 )
break;
if ( !v2 )
return v3;
}
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, char a2)
{
char v2; // al
unsigned int v3; // er8

v2 = *a1;
v3 = 0;
while ( v2 )
{
if ( a2 == v2 )
{
v2 = *++a1;
}
else
{
v2 = *a1;
++v3;
if ( !*a1 )
return v3;
if ( a2 != v2 )
{
while ( 1 )
{
v2 = *++a1;
if ( v2 == a2 )
break;
if ( !v2 )
return v3;
}
}
}
}
return v3;
}

original_code:
static unsigned int ft_nbword(char const *s, char c)
{
 unsigned int nbword;
 nbword = 0;
 while (*s)
 {
  while (*s && *s == c)
   s++;
  nbword = (*s ? nbword + 1 : nbword);
  while (*s && *s != c)
   s++;
 }
 return (nbword);
}

canonical_original_code:
static unsigned int ft_nbword(char *s, char c)
{
 unsigned int nbword;
 nbword = 0;
 while (*s)
 {
  while (*s && *s == c)
   s++;
  nbword = (*s ? nbword + 1 : nbword);
  while (*s && *s != c)
   s++;
 }
 return (nbword);
}

variable_types:
s
char *

variable_types: c char

variable_types:
nbword
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall ft_nextwordlen(__int64 a1, unsigned int a2, char a3)
{
char v4; // al
__int64 result; // rax
char v6; // dl

v4 = *(_BYTE *)(a1 + a2);
if ( v4 == a3 || !v4 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v6 = *(_BYTE *)(a1 + a2 + (unsigned int)result);
}
while ( v6 != a3 && v6 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, char a3)
{
char v4; // al
__int64 result; // rax
char v6; // dl

v4 = *(_BYTE *)(a1 + a2);
if ( v4 == a3 || !v4 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
v6 = *(_BYTE *)(a1 + a2 + (unsigned int)result);
}
while ( v6 != a3 && v6 );
return result;
}

original_code:
static unsigned int ft_nextwordlen(char const *s, unsigned int i, char c)
{
 unsigned int len;
 len = 0;
 while (s[i + len] != '\0' && s[i + len] != c)
  len++;
 return (len);
}

canonical_original_code:
static unsigned int ft_nextwordlen(char *s, unsigned int i, char c)
{
 unsigned int len;
 len = 0;
 while (s[i + len] != '\0' && s[i + len] != c)
  len++;
 return (len);
}

variable_types:
i
unsigned int

variable_types:
len
unsigned int


decompiled_code:
void __fastcall ft_freesplit(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
do
{
free(v2);
v2 = *(void **)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
do
{
free(v2);
v2 = *(void **)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
}
}

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

variable_types:
s
char **

variable_types: i int


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

result = (_QWORD *)game_0;
if ( !game_0 )
{
result = malloc(0x20uLL);
game_0 = (__int64)result;
*result = 0LL;
result[2] = 0x100000005LL;
*((_DWORD *)result + 6) = 1;
}
return result;
}

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

result = (_QWORD *)game_0;
if ( !game_0 )
{
result = malloc(0x20uLL);
game_0 = (__int64)result;
*result = 0LL;
result[2] = 0x100000005LL;
*((_DWORD *)result + 6) = 1;
}
return result;
}

original_code:
t_game *init_game(void)
{
 static t_game *game = ((void *)0);
 if (game == ((void *)0))
 {
  game = (t_game *)malloc(sizeof(t_game));
  game->grid = ((void *)0);
  game->ia_lvl = 5;
  game->player[0] = 1;
  game->player[1] = 1;
 }
 return (game);
}

canonical_original_code:
struct s_game *init_game()
{
 static struct s_game *game = ((void *)0);
 if (game == ((void *)0))
 {
  game = (struct s_game *)malloc(sizeof(t_game));
  game->grid = ((void *)0);
  game->ia_lvl = 5;
  game->player[0] = 1;
  game->player[1] = 1;
 }
 return (game);
}

variable_types: struct s_game { int **grid; int max_x; int max_y; int ia_lvl; int player[2]; int player_in; } *


decompiled_code:
__int64 __fastcall ex_pipe(char **argv, _QWORD *a2, char *const *a3)
{
char *v5; // rbp
int v6; // ebx

while ( 1 )
{
if ( !*(_BYTE *)*a2 )
return 1LL;
v5 = (char *)ft_strjoin(*a2, *argv);
v6 = execve(v5, argv, a3);
if ( !v6 )
goto LABEL_8;
if ( !a2[1] && **argv )
break;
++a2;
free(v5);
if ( v6 >= 0 )
return 1LL;
}
if ( execve(*argv, argv, a3) )
{
ft_puterr("ft_sh2 : command invalide : ");
ft_puterr(*argv);
ft_puterr("\n");
exit(-1);
}
LABEL_8:
free(v5);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **argv, _QWORD *a2, char *const *a3)
{
char *v5; // rbp
int v6; // ebx

while ( 1 )
{
if ( !*(_BYTE *)*a2 )
return 1LL;
v5 = (char *)ft_strjoin(*a2, *argv);
v6 = execve(v5, argv, a3);
if ( !v6 )
goto LABEL_8;
if ( !a2[1] && **argv )
break;
++a2;
free(v5);
if ( v6 >= 0 )
return 1LL;
}
if ( execve(*argv, argv, a3) )
{
ft_puterr("ft_sh2 : command invalide : ");
ft_puterr(*argv);
ft_puterr("\n");
exit(-1);
}
LABEL_8:
free(v5);
return 1LL;
}

original_code:
int ex_pipe(char **av, char **path, char **env)
{
 int i;
 int ret_exe;
 char *tmp;
 ret_exe = -1;
 i = 0;
 while (ret_exe < 0 && *path[i] != 0)
 {
  tmp = ft_strjoin(path[i], av[0]);
  if ((ret_exe = execve(tmp, av, env))
   && path[i + 1] == 0 && av[0][0] != '\0')
  {
   if ((ret_exe = execve(av[0], av, env)))
   {
    ft_puterr("ft_sh2 : command invalide : ");
    ft_puterr(av[0]);
    ft_puterr("\n");
    exit(-1);
   }
  }
  i++;
  free(tmp);
 }
 return (1);
}

variable_types:
av
char **

variable_types:
path
char **

variable_types:
env
char **

variable_types:
tmp
char *


decompiled_code:
int __fastcall outputs_file(char *file, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er14
int v5; // eax

v5 = *(_DWORD *)(a4 + 24);
if ( v5 != 2 )
{
if ( v5 != 6 )
goto LABEL_3;
goto LABEL_7;
}
v4 = open(file, 578, 420LL);
if ( v4 == -1 )
ft_puterr("output fail");
if ( *(_DWORD *)(a4 + 24) == 6 )
{
LABEL_7:
v4 = open(file, 1090, 420LL);
if ( v4 == -1 )
ft_puterr("output fail");
}
LABEL_3:
dup2(v4, 1);
ft_sh1_relance(a4, a2, a3);
return close(*(_DWORD *)(a4 + 24));
}

canonical_decompiled_code:
int __fastcall func1(char *file, __int64 a2, __int64 a3, __int64 a4)
{
int v4; // er14
int v5; // eax

v5 = *(_DWORD *)(a4 + 24);
if ( v5 != 2 )
{
if ( v5 != 6 )
goto LABEL_3;
goto LABEL_7;
}
v4 = open(file, 578, 420LL);
if ( v4 == -1 )
ft_puterr("output fail");
if ( *(_DWORD *)(a4 + 24) == 6 )
{
LABEL_7:
v4 = open(file, 1090, 420LL);
if ( v4 == -1 )
ft_puterr("output fail");
}
LABEL_3:
dup2(v4, 1);
ft_sh1_relance(a4, a2, a3);
return close(*(_DWORD *)(a4 + 24));
}

original_code:
void outputs_file(char *file, char **av, t_env *env, t_cmd *cmd)
{
 int file_out;
 if (cmd->sfd == 2)
  if ((file_out = open(file, 02 | 0100 | 01000, 0644)) == -1)
   ft_puterr("output fail");
 if (cmd->sfd == 6)
  if ((file_out = open(file, 02 | 0100 | 02000, 0644)) == -1)
   ft_puterr("output fail");
 dup2(file_out, 1);
 ft_sh1_relance(cmd, av, env);
 close(cmd->sfd);
}

canonical_original_code:
void outputs_file(char *file, char **av, struct s_env *env, struct s_cmd *cmd)
{
 int file_out;
 if (cmd->sfd == 2)
  if ((file_out = open(file, 02 | 0100 | 01000, 0644)) == -1)
   ft_puterr("output fail");
 if (cmd->sfd == 6)
  if ((file_out = open(file, 02 | 0100 | 02000, 0644)) == -1)
   ft_puterr("output fail");
 dup2(file_out, 1);
 ft_sh1_relance(cmd, av, env);
 close(cmd->sfd);
}

variable_types:
file
char *

variable_types: struct s_env { char **path; char *ps1; int ps1_len; char *home; char pwd[4096]; char **environ; int pid; } *

variable_types: struct s_cmd { char *name; char *value; char *file; int sfd; struct s_cmd *next; } *


decompiled_code:
int __fastcall inputs_file(char *file, __int64 a2, __int64 a3, __int64 a4)
{
int v6; // er12
int v7; // ebp
__int64 v8; // rax

v6 = dup(0);
v7 = open(file, 0);
if ( v7 == -1 )
ft_puterr("input file not open");
dup2(v7, 0);
v8 = ft_parse_cmd(*(_QWORD *)(a4 + 8));
ft_sh2_relance2(a2, a3, v8, 0LL);
close(v7);
dup2(v6, 0);
return close(*(_DWORD *)(a4 + 24));
}

canonical_decompiled_code:
int __fastcall func2(char *file, __int64 a2, __int64 a3, __int64 a4)
{
int v6; // er12
int v7; // ebp
__int64 v8; // rax

v6 = dup(0);
v7 = open(file, 0);
if ( v7 == -1 )
ft_puterr("input file not open");
dup2(v7, 0);
v8 = ft_parse_cmd(*(_QWORD *)(a4 + 8));
ft_sh2_relance2(a2, a3, v8, 0LL);
close(v7);
dup2(v6, 0);
return close(*(_DWORD *)(a4 + 24));
}

original_code:
void inputs_file(char *file, char **av, t_env *env, t_cmd *cmd)
{
 int file_in;
 int input;
 input = dup(0);
 if ((file_in = open(file, 00)) == -1)
  ft_puterr("input file not open");
 dup2(file_in, 0);
 ft_sh2_relance2(av, env, ft_parse_cmd(cmd->value), 0);
 close(file_in);
 dup2(input, 0);
 close(cmd->sfd);
}

canonical_original_code:
void inputs_file(char *file, char **av, struct s_env *env, struct s_cmd *cmd)
{
 int file_in;
 int input;
 input = dup(0);
 if ((file_in = open(file, 00)) == -1)
  ft_puterr("input file not open");
 dup2(file_in, 0);
 ft_sh2_relance2(av, env, ft_parse_cmd(cmd->value), 0);
 close(file_in);
 dup2(input, 0);
 close(cmd->sfd);
}

variable_types: input int

user_defined_types: struct s_cmd { char *name; char *value; char *file; int sfd; struct s_cmd *next; }


decompiled_code:
__pid_t __fastcall ft_pipe(__int64 a1, __int64 a2, __int64 a3)
{
int v4; // er12
int v5; // er14
__pid_t v6; // eax
__int64 v7; // rax
char *const *v9; // r12
_QWORD *v10; // rbp
char **v11; // rax
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

v4 = dup(0);
v5 = dup(1);
pipe(pipedes);
v6 = fork();
*(_DWORD *)(a3 + 4136) = v6;
if ( v6 < 0 )
return ft_puterr("fork fail");
if ( v6 )
{
close(pipedes[1]);
dup2(pipedes[0], 0);
v7 = ft_parse_cmd(*(_QWORD *)(a1 + 16));
ft_sh2_relance2(a2, a3, v7, 0LL);
close(pipedes[0]);
dup2(v4, 0);
}
else
{
close(pipedes[0]);
dup2(pipedes[1], 1);
v9 = *(char *const **)(a3 + 4128);
v10 = *(_QWORD **)a3;
v11 = (char **)ft_strsplit(*(_QWORD *)(a1 + 8), 32LL);
ex_pipe(v11, v10, v9);
dup2(v5, 1);
}
return wait(0LL);
}

canonical_decompiled_code:
__pid_t __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
int v4; // er12
int v5; // er14
__pid_t v6; // eax
__int64 v7; // rax
char *const *v9; // r12
_QWORD *v10; // rbp
char **v11; // rax
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

v4 = dup(0);
v5 = dup(1);
pipe(pipedes);
v6 = fork();
*(_DWORD *)(a3 + 4136) = v6;
if ( v6 < 0 )
return ft_puterr("fork fail");
if ( v6 )
{
close(pipedes[1]);
dup2(pipedes[0], 0);
v7 = ft_parse_cmd(*(_QWORD *)(a1 + 16));
ft_sh2_relance2(a2, a3, v7, 0LL);
close(pipedes[0]);
dup2(v4, 0);
}
else
{
close(pipedes[0]);
dup2(pipedes[1], 1);
v9 = *(char *const **)(a3 + 4128);
v10 = *(_QWORD **)a3;
v11 = (char **)ft_strsplit(*(_QWORD *)(a1 + 8), 32LL);
func0(v11, v10, v9);
dup2(v5, 1);
}
return wait(0LL);
}

original_code:
void ft_pipe(t_cmd *cmd, char **av, t_env *env)
{
 int fd[2];
 int save_fd[2];
 save_fd[0] = dup(0);
 save_fd[1] = dup(1);
 pipe(fd);
 if ((env->pid = fork()) < 0)
  ft_puterr("fork fail");
 else if (env->pid == 0)
 {
  close(fd[0]);
  dup2(fd[1], 1);
  ex_pipe(ft_strsplit(cmd->value, ' '), env->path, env->environ);
  dup2(save_fd[1], 1);
  wait(((void *)0));
 }
 else
 {
  close(fd[1]);
  dup2(fd[0], 0);
  ft_sh2_relance2(av, env, ft_parse_cmd(cmd->file), 0);
  close(fd[0]);
  dup2(save_fd[0], 0);
  wait(((void *)0));
 }
}

canonical_original_code:
void ft_pipe(struct s_cmd *cmd, char **av, struct s_env *env)
{
 int fd[2];
 int save_fd[2];
 save_fd[0] = dup(0);
 save_fd[1] = dup(1);
 pipe(fd);
 if ((env->pid = fork()) < 0)
  ft_puterr("fork fail");
 else if (env->pid == 0)
 {
  close(fd[0]);
  dup2(fd[1], 1);
  ex_pipe(ft_strsplit(cmd->value, ' '), env->path, env->environ);
  dup2(save_fd[1], 1);
  wait(((void *)0));
 }
 else
 {
  close(fd[1]);
  dup2(fd[0], 0);
  ft_sh2_relance2(av, env, ft_parse_cmd(cmd->file), 0);
  close(fd[0]);
  dup2(save_fd[0], 0);
  wait(((void *)0));
 }
}

variable_types:
fd
int [2]


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

v2 = a2;
ft_putstr(&unk_1D7);
if ( a2 || a1 <= 0 )
{
if ( a2 == 1 && a1 > 0 )
{
v3 = 0;
do
{
ft_putnbr((unsigned int)++v3);
ft_putchar(32LL);
}
while ( v3 < a1 );
}
}
else
{
do
{
++v2;
ft_putstr("____");
}
while ( a1 > v2 );
}
return ft_putstr("\n");
}

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

v2 = a2;
ft_putstr(&unk_1D7);
if ( a2 || a1 <= 0 )
{
if ( a2 == 1 && a1 > 0 )
{
v3 = 0;
do
{
ft_putnbr((unsigned int)++v3);
ft_putchar(32LL);
}
while ( v3 < a1 );
}
}
else
{
do
{
++v2;
ft_putstr("____");
}
while ( a1 > v2 );
}
return ft_putstr("\n");
}

original_code:
void drow_line(int y, int first)
{
 int i;
 i = 0;
 ft_putstr("\n  ");
 while (i < y && first == 0)
 {
  ft_putstr("____");
  i++;
 }
 while (i < y && first == 1)
 {
  ft_putnbr(i + 1);
  ft_putchar(' ');
  i++;
 }
 ft_putstr("\n");
}

variable_types: y int

variable_types: first int


decompiled_code:
__int64 __fastcall print_grid(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r13
__int64 v3; // rbx
int v4; // eax

result = drow_line(*(_DWORD *)(a1 + 12), 1);
if ( *(int *)(a1 + 8) > 0 )
{
v2 = 0LL;
while ( 1 )
{
ft_putnbr((unsigned int)(v2 + 1));
if ( *(int *)(a1 + 12) > 0 )
break;
LABEL_10:
++v2;
ft_putstr(" |");
result = drow_line(*(_DWORD *)(a1 + 12), 0);
if ( *(_DWORD *)(a1 + 8) <= (int)v2 )
return result;
}
v3 = 0LL;
while ( 1 )
{
ft_putstr(" | ");
v4 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2) + 4 * v3);
if ( v4 == 1 )
break;
if ( v4 == 2 )
{
ft_putchar(120LL);
goto LABEL_5;
}
if ( v4 )
{
LABEL_5:
if ( *(_DWORD *)(a1 + 12) <= (int)++v3 )
goto LABEL_10;
}
else
{
++v3;
ft_putchar(32LL);
if ( *(_DWORD *)(a1 + 12) <= (int)v3 )
goto LABEL_10;
}
}
ft_putchar(48LL);
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r13
__int64 v3; // rbx
int v4; // eax

result = func0(*(_DWORD *)(a1 + 12), 1);
if ( *(int *)(a1 + 8) > 0 )
{
v2 = 0LL;
while ( 1 )
{
ft_putnbr((unsigned int)(v2 + 1));
if ( *(int *)(a1 + 12) > 0 )
break;
LABEL_10:
++v2;
ft_putstr(" |");
result = func0(*(_DWORD *)(a1 + 12), 0);
if ( *(_DWORD *)(a1 + 8) <= (int)v2 )
return result;
}
v3 = 0LL;
while ( 1 )
{
ft_putstr(" | ");
v4 = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2) + 4 * v3);
if ( v4 == 1 )
break;
if ( v4 == 2 )
{
ft_putchar(120LL);
goto LABEL_5;
}
if ( v4 )
{
LABEL_5:
if ( *(_DWORD *)(a1 + 12) <= (int)++v3 )
goto LABEL_10;
}
else
{
++v3;
ft_putchar(32LL);
if ( *(_DWORD *)(a1 + 12) <= (int)v3 )
goto LABEL_10;
}
}
ft_putchar(48LL);
goto LABEL_5;
}
return result;
}

original_code:
void print_grid(t_game *game)
{
 int x;
 int y;
 x = 0;
 y = 0;
 drow_line(game->max_y, 1);
 while (x < game->max_x)
 {
  y = 0;
  ft_putnbr(x + 1);
  while (y < game->max_y)
  {
   ft_putstr(" | ");
   if (game->grid[x][y] == 1)
    ft_putchar('0');
   else if (game->grid[x][y] == 2)
    ft_putchar('x');
   else if (game->grid[x][y] == 0)
    ft_putchar(' ');
   y++;
  }
  ft_putstr(" |");
  drow_line(game->max_y, 0);
  x++;
 }
}

canonical_original_code:
void print_grid(struct s_game *game)
{
 int x;
 int y;
 x = 0;
 y = 0;
 drow_line(game->max_y, 1);
 while (x < game->max_x)
 {
  y = 0;
  ft_putnbr(x + 1);
  while (y < game->max_y)
  {
   ft_putstr(" | ");
   if (game->grid[x][y] == 1)
    ft_putchar('0');
   else if (game->grid[x][y] == 2)
    ft_putchar('x');
   else if (game->grid[x][y] == 0)
    ft_putchar(' ');
   y++;
  }
  ft_putstr(" |");
  drow_line(game->max_y, 0);
  x++;
 }
}

variable_types: x int

user_defined_types: struct s_game { int **grid; int max_x; int max_y; int ia_lvl; int player[2]; int player_in; }


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

result = ft_putstr("And the winner is :");
switch ( a1 )
{
case 2:
return ft_putstr("X \n");
case 1:
return ft_putstr("0 \n");
case 100:
result = ft_putstr(" egaliter\n");
break;
}
return result;
}

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

result = ft_putstr("And the winner is :");
switch ( a1 )
{
case 2:
return ft_putstr("X \n");
case 1:
return ft_putstr("0 \n");
case 100:
result = ft_putstr(" egaliter\n");
break;
}
return result;
}

original_code:
void ft_print_winner(int winner)
{
 ft_putstr("And the winner is :");
 if (winner == 2)
  ft_putstr("X \n");
 if (winner == 1)
  ft_putstr("0 \n");
 if (winner == 100)
  ft_putstr(" egaliter\n");
}

variable_types: winner int


play

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

*(_DWORD *)(a2 + 28) = a1;
result = a1 - 1;
if ( *(_DWORD *)(a2 + 4 * result + 20) == 1 )
result = ia();
return result;
}

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

*(_DWORD *)(a2 + 28) = a1;
result = a1 - 1;
if ( *(_DWORD *)(a2 + 4 * result + 20) == 1 )
result = ia();
return result;
}

original_code:
void play(int player, t_game *game)
{
 game->player_in = player;
 if (game->player[player - 1] == 1)
  ia(player, game);
}

canonical_original_code:
void play(int player, struct s_game *game)
{
 game->player_in = player;
 if (game->player[player - 1] == 1)
  ia(player, game);
}

variable_types: player int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // ebp
__int64 v5; // rbx
int v6; // eax

if ( argc != 4 )
return 0;
v4 = 2;
v5 = init_game(argc, argv, envp);
init_grid(argv[1], argv[2], v5);
while ( !(unsigned int)check_winner() )
{
v4 = ft_vs(v4);
play(v4, v5);
print_grid(v5);
}
v6 = check_winner();
ft_print_winner(v6);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // ebp
__int64 v5; // rbx
int v6; // eax

if ( argc != 4 )
return 0;
v4 = 2;
v5 = init_game(argc, argv, envp);
init_grid(argv[1], argv[2], v5);
while ( !(unsigned int)check_winner() )
{
v4 = ft_vs(v4);
func3(v4, v5);
func1(v5);
}
v6 = check_winner();
func2(v6);
return 0;
}

original_code:
int main(int ac, char **av)
{
 t_game *game;
 int player = 2;
 if (ac != 4)
  return (0);
 game = init_game();
 init_grid(av[1], av[2], game);
 while (check_winner() == 0)
 {
  play((player = ft_vs(player)), game);
  print_grid(game);
 }
 ft_print_winner(check_winner());
 return(0);
}

canonical_original_code:
int main(int ac, char **av)
{
 struct s_game *game;
 int player = 2;
 if (ac != 4)
  return (0);
 game = init_game();
 init_grid(av[1], av[2], game);
 while (check_winner() == 0)
 {
  play((player = ft_vs(player)), game);
  print_grid(game);
 }
 ft_print_winner(check_winner());
 return(0);
}

variable_types: ac int


original_code:
t_gen *recup_gen(void)
{
 static t_gen *gen = ((void *)0);
 if (gen == ((void *)0))
 {
  gen = (t_gen *)malloc(sizeof(t_gen));
  gen->ps1 = (t_ps1 *)malloc(sizeof(t_ps1));
  gen->term = (t_term *)malloc(sizeof(t_term));
  gen->term->key = ((void *)0);
  gen->hist = ((void *)0);
  gen->ps1->aff = ((void *)0);
  gen->ps1->env = ((void *)0);
  gen->ps1->len = 0;
  gen->path = ((void *)0);
  gen->ret = 0;
  gen->builtin = ((void *)0);
  gen->env = ((void *)0);
  gen->env_orig = ((void *)0);
  gen->pid_fork = 1;
 }
 return (gen);
}

canonical_original_code:
struct s_gen *recup_gen()
{
 static struct s_gen *gen = ((void *)0);
 if (gen == ((void *)0))
 {
  gen = (struct s_gen *)malloc(sizeof(t_gen));
  gen->ps1 = (struct s_ps1 *)malloc(sizeof(t_ps1));
  gen->term = (struct s_term *)malloc(sizeof(t_term));
  gen->term->key = ((void *)0);
  gen->hist = ((void *)0);
  gen->ps1->aff = ((void *)0);
  gen->ps1->env = ((void *)0);
  gen->ps1->len = 0;
  gen->path = ((void *)0);
  gen->ret = 0;
  gen->builtin = ((void *)0);
  gen->env = ((void *)0);
  gen->env_orig = ((void *)0);
  gen->pid_fork = 1;
 }
 return (gen);
}

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

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 free_gen()
{
void *v0; // rax

v0 = (void *)recup_gen();
free(v0);
}

canonical_decompiled_code:
void func1()
{
void *v0; // rax

v0 = (void *)func0();
free(v0);
}

original_code:
void free_gen(void)
{
 t_gen *gen;
 gen = recup_gen();
 free(gen);
 gen = ((void *)0);
}

canonical_original_code:
void free_gen()
{
 struct s_gen *gen;
 gen = recup_gen();
 free(gen);
 gen = ((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 s_builtin { char *name; char *help; }


original_code:
void wait_start(t_env *env)
{
 int msg_id;
 struct s_msgbuf buff;
 int i;
 msg_id = msgget(env->key, 01000 | 0400 | 0200);
 buff.mtext[0] = 'a';
 i = -1;
 while (++i < 700)
 {
  env->mem->team[i].id = 0;
  env->mem->team[i].nb_player = 0;
  ft_bzero(env->mem->team[i].name, 60);
 }
 sem_rel(env);
 msgrcv(msg_id, &buff, 1, 0, 0);
 env->mem->start = 1;
 shmdt (env->mem);
 msgctl (msg_id, 0, 0);
}

canonical_original_code:
void wait_start(struct s_env *env)
{
 int msg_id;
 struct s_msgbuf buff;
 int i;
 msg_id = msgget(env->key, 01000 | 0400 | 0200);
 buff.mtext[0] = 'a';
 i = -1;
 while (++i < 700)
 {
  env->mem->team[i].id = 0;
  env->mem->team[i].nb_player = 0;
  ft_bzero(env->mem->team[i].name, 60);
 }
 sem_rel(env);
 msgrcv(msg_id, &buff, 1, 0, 0);
 env->mem->start = 1;
 shmdt (env->mem);
 msgctl (msg_id, 0, 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: struct s_msgbuf { long mtype; char mtext[1]; }

variable_types: i 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 send_start(__int64 a1)
{
int v1; // eax
_BYTE v3[24]; // [rsp+0h] [rbp-18h] BYREF

v1 = msgget(*(_DWORD *)(a1 + 16), 896);
v3[8] = 97;
return msgsnd(v1, v3, 1uLL, 0);
}

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

v1 = msgget(*(_DWORD *)(a1 + 16), 896);
v3[8] = 97;
return msgsnd(v1, v3, 1uLL, 0);
}

original_code:
void send_start(t_env *env)
{
 int msg_id;
 struct s_msgbuf buff;
 msg_id = msgget(env->key, 01000 | 0400 | 0200);
 buff.mtext[0] = 'a';
 msgsnd(msg_id, &buff, 1, 0);
}

canonical_original_code:
void send_start(struct s_env *env)
{
 int msg_id;
 struct s_msgbuf buff;
 msg_id = msgget(env->key, 01000 | 0400 | 0200);
 buff.mtext[0] = 'a';
 msgsnd(msg_id, &buff, 1, 0);
}

user_defined_types: struct s_msgbuf { long mtype; char mtext[1]; }

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


original_code:
int init_memory(t_env *env)
{
 env->mem = ((void *)0);
 env->size_mem = sizeof(t_mem) + (sizeof(char)
  * (env->size_x * env->size_y));
 if ((env->seg_id = shmget (env->key, env->size_mem, 01000 | 02000
 | 0400 | 0200)) != -1)
 {
  env->init = 1;
  ft_printf("jentre\n");
  init_sem(env);
  creat_map(env, env->seg_id);
  wait_start(env);
  while (1)
   player(env);
 }
 else if ((env->seg_id = shmget (env->key, sizeof(t_mem),
  02000 | 0400 | 0200)) != -1)
 {
  env->init = 0;
  while (1)
   player(env);
 }
 else
  ft_fprintf(2, "fail to alloc memory\n");
 return (1);
}

canonical_original_code:
int init_memory(struct s_env *env)
{
 env->mem = ((void *)0);
 env->size_mem = sizeof(t_mem) + (sizeof(char)
  * (env->size_x * env->size_y));
 if ((env->seg_id = shmget (env->key, env->size_mem, 01000 | 02000
 | 0400 | 0200)) != -1)
 {
  env->init = 1;
  ft_printf("jentre\n");
  init_sem(env);
  creat_map(env, env->seg_id);
  wait_start(env);
  while (1)
   player(env);
 }
 else if ((env->seg_id = shmget (env->key, sizeof(t_mem),
  02000 | 0400 | 0200)) != -1)
 {
  env->init = 0;
  while (1)
   player(env);
 }
 else
  ft_fprintf(2, "fail to alloc memory\n");
 return (1);
}


clearmap

decompiled_code:
__int64 __fastcall clearmap(sem_t *sem)
{
*(_DWORD *)sem[2].__align = 0;
sem_rel(sem);
sem_wait(sem);
sem_block(sem);
sem_rel(sem);
sem_block(sem);
shmdt((const void *)sem[2].__align);
shmctl(*((_DWORD *)&sem->__align + 7), 0, 0LL);
semctl(*((_DWORD *)&sem[1].__align + 6), 0, 0);
return ft_putstr("netoyer\n");
}

canonical_decompiled_code:
__int64 __fastcall func3(sem_t *sem)
{
*(_DWORD *)sem[2].__align = 0;
sem_rel(sem);
sem_wait(sem);
sem_block(sem);
sem_rel(sem);
sem_block(sem);
shmdt((const void *)sem[2].__align);
shmctl(*((_DWORD *)&sem->__align + 7), 0, 0LL);
semctl(*((_DWORD *)&sem[1].__align + 6), 0, 0);
return ft_putstr("netoyer\n");
}

original_code:
void clearmap(t_env *env)
{
 env->mem->start = 0;
 sem_rel(env);
 sem_wait(env);
 sem_block(env);
 sem_rel(env);
 sem_block(env);
 shmdt (env->mem);
 shmctl (env->seg_id, 0, 0);
 semctl (env->sem_id, 0, 0);
 ft_putstr("netoyer\n");
}

canonical_original_code:
void clearmap(struct s_env *env)
{
 env->mem->start = 0;
 sem_rel(env);
 sem_wait(env);
 sem_block(env);
 sem_rel(env);
 sem_block(env);
 shmdt (env->mem);
 shmctl (env->seg_id, 0, 0);
 semctl (env->sem_id, 0, 0);
 ft_putstr("netoyer\n");
}


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

result = "command not found";
if ( a1 != 13 )
{
result = "broken pipe";
if ( a1 != 12 )
{
result = "env error";
if ( a1 != 14 )
{
result = "unknown error";
if ( a1 == 15 )
result = "error execve";
}
}
}
return result;
}

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

result = "command not found";
if ( a1 != 13 )
{
result = "broken pipe";
if ( a1 != 12 )
{
result = "env error";
if ( a1 != 14 )
{
result = "unknown error";
if ( a1 == 15 )
result = "error execve";
}
}
}
return result;
}

original_code:
char *strror2(int i)
{
 if (i == 13)
  return ("command not found");
 else if (i == 12)
  return ("broken pipe");
 else if (i == 14)
  return ("env error");
 else if (i == 15)
  return ("error execve");
 return ("unknown error");
}


strror

decompiled_code:
const char *__fastcall strror(int a1)
{
switch ( a1 )
{
case 1:
return "malloc error";
case 2:
return "too many arguments";
case 3:
return "missing argument";
case 4:
return "permission denied";
case 5:
return "no such a file or directory";
case 6:
return "file already exists";
case 7:
return "bad file descriptor";
case 8:
return "fork error";
case 9:
return "not a directory";
case 10:
return "is a directory";
case 11:
return "wrong type of argument";
}
return strror2(a1);
}

canonical_decompiled_code:
const char *__fastcall func1(int a1)
{
switch ( a1 )
{
case 1:
return "malloc error";
case 2:
return "too many arguments";
case 3:
return "missing argument";
case 4:
return "permission denied";
case 5:
return "no such a file or directory";
case 6:
return "file already exists";
case 7:
return "bad file descriptor";
case 8:
return "fork error";
case 9:
return "not a directory";
case 10:
return "is a directory";
case 11:
return "wrong type of argument";
}
return func0(a1);
}

original_code:
char *strror(int i)
{
 if (i == 1)
  return ("malloc error");
 else if (i == 2)
  return ("too many arguments");
 else if (i == 3)
  return ("missing argument");
 else if (i == 4)
  return ("permission denied");
 else if (i == 5)
  return ("no such a file or directory");
 else if (i == 6)
  return ("file already exists");
 else if (i == 7)
  return ("bad file descriptor");
 else if (i == 8)
  return ("fork error");
 else if (i == 9)
  return ("not a directory");
 else if (i == 10)
  return ("is a directory");
 else if (i == 11)
  return ("wrong type of argument");
 else
  return (strror2(i));
}


error

decompiled_code:
__int64 __fastcall error(const char ***a1, int a2)
{
int v3; // edi
const char *v4; // rax
__int64 result; // rax

v3 = *(_DWORD *)(recup_gen() + 48);
v4 = strror(v3);
if ( a2 <= 0 )
result = ft_dprintf(2LL, "%s: %s\n", **a1, v4);
else
result = ft_dprintf(2LL, "%s: %s: %s\n", **a1, (*a1)[a2], v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char ***a1, int a2)
{
int v3; // edi
const char *v4; // rax
__int64 result; // rax

v3 = *(_DWORD *)(recup_gen() + 48);
v4 = func1(v3);
if ( a2 <= 0 )
result = ft_dprintf(2LL, "%s: %s\n", **a1, v4);
else
result = ft_dprintf(2LL, "%s: %s: %s\n", **a1, (*a1)[a2], v4);
return result;
}

original_code:
void error(t_process *job, int i)
{
 t_gen *gen;
 gen = recup_gen();
 if (i > 0)
  ft_dprintf(2, "%s: %s: %s\n", job->av[0], job->av[i], strror(gen->ret));
 else
  ft_dprintf(2, "%s: %s\n", job->av[0], strror(gen->ret));
}

canonical_original_code:
void error(struct s_process *job, int i)
{
 struct s_gen *gen;
 gen = recup_gen();
 if (i > 0)
  ft_dprintf(2, "%s: %s: %s\n", job->av[0], job->av[i], strror(gen->ret));
 else
  ft_dprintf(2, "%s: %s\n", job->av[0], strror(gen->ret));
}

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


decompiled_code:
__int64 __fastcall create_serv(__int16 a1)
{
struct protoent *v1; // r12
unsigned int v2; // er12
socklen_t v3; // edx
struct sockaddr v5[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = getprotobyname("tcp");
if ( !v1 )
ft_errorexit("getprotobyname fail\n");
v2 = socket(2, 1, v1->p_proto);
if ( v2 == -1 )
ft_errorexit("socket fail\n");
v5[0].sa_family = 2;
*(_WORD *)v5[0].sa_data = _bswap_16(a1);
*(_DWORD *)&v5[0].sa_data[2] = _bswap_32_constprop_0(v2, v5);
bind(v2, v5, v3);
listen(v2, 42);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1)
{
struct protoent *v1; // r12
unsigned int v2; // er12
socklen_t v3; // edx
struct sockaddr v5[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = getprotobyname("tcp");
if ( !v1 )
ft_errorexit("getprotobyname fail\n");
v2 = socket(2, 1, v1->p_proto);
if ( v2 == -1 )
ft_errorexit("socket fail\n");
v5[0].sa_family = 2;
*(_WORD *)v5[0].sa_data = func0(a1);
*(_DWORD *)&v5[0].sa_data[2] = func1(v2, v5);
bind(v2, v5, v3);
listen(v2, 42);
return v2;
}

original_code:
int create_serv(int port)
{
 int sock;
 struct protoent *proto;
 struct sockaddr_in sin;
 if ((proto = getprotobyname("tcp")) == 0)
  ft_errorexit("getprotobyname fail\n");
 if ((sock = socket(2, SOCK_STREAM, proto->p_proto)) == -1)
  ft_errorexit("socket fail\n");
 sin.sin_family = 2;
 sin.sin_port = htons(port);
 sin.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 bind(sock, (struct sockaddr *)&sin, sizeof(sin));
 listen(sock, 42);
 return (sock);
}

canonical_original_code:
int create_serv(int port)
{
 int sock;
 struct protoent *proto;
 struct sockaddr_in sin;
 if ((proto = getprotobyname("tcp")) == 0)
  ft_errorexit("getprotobyname fail\n");
 if ((sock = socket(2, SOCK_STREAM, proto->p_proto)) == -1)
  ft_errorexit("socket fail\n");
 sin.sin_family = 2;
 sin.sin_port = htons(port);
 sin.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 bind(sock, (struct sockaddr *)&sin, sizeof(sin));
 listen(sock, 42);
 return (sock);
}

variable_types: port int

variable_types: sock int

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

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


decompiled_code:
void __fastcall __noreturn ft_quit(int a1)
{
close(a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(int a1)
{
close(a1);
exit(0);
}

original_code:
void ft_quit(int cs)
{
 close(cs);
 exit (0);
}

variable_types: cs int


decompiled_code:
int __fastcall fork_child(int fd)
{
int v1; // eax
char v3[1024]; // [rsp+0h] [rbp-1408h] BYREF
char buf[4104]; // [rsp+400h] [rbp-1008h] BYREF

getcwd(buf, 0x1000uLL);
while ( 1 )
{
v1 = read(fd, v3, 0x3FFuLL);
if ( !v1 )
break;
v3[v1] = 0;
if ( (unsigned int)ft_strncmp(v3, "ls", 2LL) )
{
if ( (unsigned int)ft_strncmp(v3, "pwd", 3LL) )
{
if ( (unsigned int)ft_strncmp(v3, "cd", 2LL) )
{
if ( !(unsigned int)ft_strncmp(v3, "quit", 4LL) )
ft_quit(fd);
if ( (unsigned int)ft_strncmp(v3, "get", 3LL) && (unsigned int)ft_strncmp(v3, "put", 3LL) )
send(fd, "ERROR unknow commande", 0x15uLL, 0);
else
file_ftp(v3, (unsigned int)fd);
}
else
{
func_cd(v3, (unsigned int)fd, buf);
}
}
else
{
func_pwd((unsigned int)fd);
}
}
else
{
func_ls((unsigned int)fd);
}
ft_bzero(v3, 1024LL);
}
return close(fd);
}

canonical_decompiled_code:
int __fastcall func5(int fd)
{
int v1; // eax
char v3[1024]; // [rsp+0h] [rbp-1408h] BYREF
char buf[4104]; // [rsp+400h] [rbp-1008h] BYREF

getcwd(buf, 0x1000uLL);
while ( 1 )
{
v1 = read(fd, v3, 0x3FFuLL);
if ( !v1 )
break;
v3[v1] = 0;
if ( (unsigned int)ft_strncmp(v3, "ls", 2LL) )
{
if ( (unsigned int)ft_strncmp(v3, "pwd", 3LL) )
{
if ( (unsigned int)ft_strncmp(v3, "cd", 2LL) )
{
if ( !(unsigned int)ft_strncmp(v3, "quit", 4LL) )
func4(fd);
if ( (unsigned int)ft_strncmp(v3, "get", 3LL) && (unsigned int)ft_strncmp(v3, "put", 3LL) )
send(fd, "ERROR unknow commande", 0x15uLL, 0);
else
file_ftp(v3, (unsigned int)fd);
}
else
{
func_cd(v3, (unsigned int)fd, buf);
}
}
else
{
func_pwd((unsigned int)fd);
}
}
else
{
func_ls((unsigned int)fd);
}
ft_bzero(v3, 1024LL);
}
return close(fd);
}

original_code:
void fork_child(int cs, int sock)
{
 int ret;
 char buff[1024];
 char pwd[4096];
 getcwd(pwd, 4096);
 while ((ret = read(cs, buff, 1023)))
 {
  buff[ret] = '\0';
  if (ft_strncmp(buff, "ls", 2) == 0)
   func_ls(cs);
  else if (ft_strncmp(buff, "pwd", 3) == 0)
   func_pwd(cs);
  else if (ft_strncmp(buff, "cd", 2) == 0)
   func_cd(buff, cs, pwd);
  else if (ft_strncmp(buff, "quit", 4) == 0)
   ft_quit(cs);
  else if (ft_strncmp(buff, "get", 3) == 0
    || ft_strncmp(buff, "put", 3) == 0)
   file_ftp(buff, cs);
  else
   send(cs, "ERROR unknow commande", 21, 0);
  ft_bzero((char *)buff, 1024);
 }
 close(cs);
}

variable_types: ret int

variable_types:
buff
char [1024]

variable_types:
pwd
char [4096]


usage

decompiled_code:
void __fastcall __noreturn usage(__int64 a1)
{
ft_putstr_fd("usage: ", 2LL);
ft_putstr_fd(a1, 2LL);
ft_putstr_fd(" <port>\n", 2LL);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(__int64 a1)
{
ft_putstr_fd("usage: ", 2LL);
ft_putstr_fd(a1, 2LL);
ft_putstr_fd(" <port>\n", 2LL);
exit(-1);
}

original_code:
void usage(char *name)
{
 ft_putstr_fd("usage: ", 2);
 ft_putstr_fd(name, 2);
 ft_putstr_fd(" <port>\n", 2);
 exit(-1);
}

variable_types:
name
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
int v4; // er12
int v5; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

if ( argc != 2 )
usage((__int64)*argv);
v3 = ft_atoi(argv[1]);
v4 = create_serv(v3);
while ( 1 )
{
v5 = accept(v4, &addr, &addr_len);
if ( !v5 )
break;
if ( !fork() )
fork_child(v5);
}
close(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // ax
int v4; // er12
int v5; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

if ( argc != 2 )
func2((__int64)*argv);
v3 = ft_atoi(argv[1]);
v4 = func3(v3);
while ( 1 )
{
v5 = accept(v4, &addr, &addr_len);
if ( !v5 )
break;
if ( !fork() )
func5(v5);
}
close(v4);
return 0;
}

original_code:
int main(int ac, char **av)
{
 int port;
 int sock;
 int cs;
 struct sockaddr_in csin;
 unsigned int cslen;
 if (ac != 2)
  usage(av[0]);
 port = ft_atoi(av[1]);
 sock = create_serv(port);
 while ((cs = accept(sock, (struct sockaddr *)&csin, &cslen)))
 {
  if (fork() == 0)
   fork_child(cs, sock);
 }
 close(sock);
 return (0);
}

variable_types:
av
char **

variable_types:
cslen
unsigned int


mystrlen

decompiled_code:
__int64 __fastcall mystrlen(_BYTE *a1)
{
unsigned __int64 v1; // rax
__int64 v2; // rdx
unsigned int v3; // er8
__int64 result; // rax

v1 = (unsigned __int8)*a1;
if ( (unsigned __int8)v1 > 0x27u )
{
v3 = 0;
LABEL_5:
while ( 1 )
{
++a1;
if ( (_BYTE)v1 == 32 )
break;
LOBYTE(v1) = *a1;
++v3;
if ( !*a1 )
goto LABEL_3;
}
result = v3;
}
else
{
v2 = 0x8400000001LL;
v3 = 0;
if ( !_bittest64(&v2, v1) )
goto LABEL_5;
LABEL_3:
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
unsigned __int64 v1; // rax
__int64 v2; // rdx
unsigned int v3; // er8
__int64 result; // rax

v1 = (unsigned __int8)*a1;
if ( (unsigned __int8)v1 > 0x27u )
{
v3 = 0;
LABEL_5:
while ( 1 )
{
++a1;
if ( (_BYTE)v1 == 32 )
break;
LOBYTE(v1) = *a1;
++v3;
if ( !*a1 )
goto LABEL_3;
}
result = v3;
}
else
{
v2 = 0x8400000001LL;
v3 = 0;
if ( !_bittest64(&v2, v1) )
goto LABEL_5;
LABEL_3:
result = v3;
}
return result;
}

original_code:
static unsigned int mystrlen(char *s)
{
 unsigned int size;
 char quote;
 size = 0;
 quote = 0;
 if (*s == '\'' || *s == '\"')
 {
  quote = *s;
  while (*s++ != quote)
   size++;
 }
 else
 {
  while (*s && *s++ != ' ')
   size++;
 }
 return (size);
}

variable_types:
s
char *

variable_types:
size
unsigned int

variable_types: quote char


original_code:
t_job *job_lst_add(t_job *lst, t_token *token_lst, char need_success)
{
 t_job *new_job;
 t_job *current;
 if (!(new_job = create_job(token_lst, need_success)))
  return (((void *)0));
 if (!lst)
  return (new_job);
 current = lst;
 while (current->next != ((void *)0))
  current = current->next;
 current->next = new_job;
 new_job->prev = current;
 return (lst);
}

canonical_original_code:
struct s_job *job_lst_add(struct s_job *lst, struct s_token *token_lst, char need_success)
{
 struct s_job *new_job;
 struct s_job *current;
 if (!(new_job = create_job(token_lst, need_success)))
  return (((void *)0));
 if (!lst)
  return (new_job);
 current = lst;
 while (current->next != ((void *)0))
  current = current->next;
 current->next = new_job;
 new_job->prev = current;
 return (lst);
}

variable_types:
lst
struct s_job *

variable_types: struct s_job { 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; } *token_lst; char need_success; struct s_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *first_process; struct s_job *next; struct s_job *prev; } *

user_defined_types: struct s_job { struct s_token *token_lst; char need_success; struct s_process *first_process; struct s_job *next; struct s_job *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 search_right(unsigned int *a1, unsigned int *a2, _DWORD *a3, _DWORD *a4)
{
int v4; // er12
unsigned int v5; // er15
__int64 result; // rax
int i; // er13

v4 = a2[1];
v5 = *a2;
result = (unsigned int)(*(_DWORD *)(*((_QWORD *)a1 + 8) + 43420LL) - 1);
if ( v4 < (int)result )
{
for ( i = 0; (unsigned int)check_case(a1, v5, (unsigned int)v4) != -1 || *a3 && *a3 <= i; ++i )
{
++v4;
result = (unsigned int)(*(_DWORD *)(*((_QWORD *)a1 + 8) + 43420LL) - 1);
if ( (int)result <= v4 )
return result;
}
result = *a1;
if ( (_DWORD)result )
result = ft_printf("enemy trouver right X: %d Y: %d\n", v5, (unsigned int)v4);
*a3 = i;
*a4 = 2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, unsigned int *a2, _DWORD *a3, _DWORD *a4)
{
int v4; // er12
unsigned int v5; // er15
__int64 result; // rax
int i; // er13

v4 = a2[1];
v5 = *a2;
result = (unsigned int)(*(_DWORD *)(*((_QWORD *)a1 + 8) + 43420LL) - 1);
if ( v4 < (int)result )
{
for ( i = 0; (unsigned int)check_case(a1, v5, (unsigned int)v4) != -1 || *a3 && *a3 <= i; ++i )
{
++v4;
result = (unsigned int)(*(_DWORD *)(*((_QWORD *)a1 + 8) + 43420LL) - 1);
if ( (int)result <= v4 )
return result;
}
result = *a1;
if ( (_DWORD)result )
result = ft_printf("enemy trouver right X: %d Y: %d\n", v5, (unsigned int)v4);
*a3 = i;
*a4 = 2;
}
return result;
}

original_code:
void search_right(t_env *env, t_play *p, int *max, int *act)
{
 int i;
 int x;
 int y;
 i = -1;
 x = p->init.x;
 y = p->init.y;
 while (++i + y < env->mem->size_y - 1)
 {
  if (check_case(env, x, y + i) == -1)
  {
   if (i < *max || *max == 0)
   {
    if (env->verbose)
     ft_printf("enemy trouver right X: %d Y: %d\n", x, y + i);
    *max = i;
    *act = 2;
    return ;
   }
  }
 }
 return ;
}

canonical_original_code:
void search_right(struct s_env *env, struct s_play *p, int *max, int *act)
{
 int i;
 int x;
 int y;
 i = -1;
 x = p->init.x;
 y = p->init.y;
 while (++i + y < env->mem->size_y - 1)
 {
  if (check_case(env, x, y + i) == -1)
  {
   if (i < *max || *max == 0)
   {
    if (env->verbose)
     ft_printf("enemy trouver right X: %d Y: %d\n", x, y + i);
    *max = i;
    *act = 2;
    return ;
   }
  }
 }
 return ;
}

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: 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 *

variable_types: i int

variable_types: x int

variable_types: y int

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


decompiled_code:
unsigned __int64 __fastcall search_bot(__int64 a1, unsigned int *a2, _DWORD *a3, _DWORD *a4)
{
unsigned int v4; // ebp
unsigned int v5; // er12
unsigned __int64 result; // rax
int i; // er13

v4 = *a2;
v5 = a2[1];
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 64) + 43416LL) - 1);
if ( (int)*a2 < (int)result )
{
for ( i = 0; (unsigned int)check_case(a1, v4, v5) != -1 || *a3 && *a3 <= i; ++i )
{
++v4;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 64) + 43416LL) - 1);
if ( (int)result <= (int)v4 )
return result;
}
if ( *(_DWORD *)a1 )
ft_printf("enemy trouver left X: %d Y: %d\n", v4, v5);
result = (unsigned __int64)a4;
*a3 = i - 1;
*a4 = 3;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, unsigned int *a2, _DWORD *a3, _DWORD *a4)
{
unsigned int v4; // ebp
unsigned int v5; // er12
unsigned __int64 result; // rax
int i; // er13

v4 = *a2;
v5 = a2[1];
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 64) + 43416LL) - 1);
if ( (int)*a2 < (int)result )
{
for ( i = 0; (unsigned int)check_case(a1, v4, v5) != -1 || *a3 && *a3 <= i; ++i )
{
++v4;
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 64) + 43416LL) - 1);
if ( (int)result <= (int)v4 )
return result;
}
if ( *(_DWORD *)a1 )
ft_printf("enemy trouver left X: %d Y: %d\n", v4, v5);
result = (unsigned __int64)a4;
*a3 = i - 1;
*a4 = 3;
}
return result;
}

original_code:
void search_bot(t_env *env, t_play *p, int *max, int *act)
{
 int i;
 int x;
 int y;
 i = -1;
 x = p->init.x;
 y = p->init.y;
 while ((++i + x) < env->mem->size_x - 1)
 {
  if (check_case(env, x + i, y) == -1)
  {
   if (i < *max || *max == 0)
   {
    if (env->verbose)
     ft_printf("enemy trouver left X: %d Y: %d\n", x + i, y);
    *max = i - 1;
    *act = 3;
    return ;
   }
  }
 }
 return ;
}

canonical_original_code:
void search_bot(struct s_env *env, struct s_play *p, int *max, int *act)
{
 int i;
 int x;
 int y;
 i = -1;
 x = p->init.x;
 y = p->init.y;
 while ((++i + x) < env->mem->size_x - 1)
 {
  if (check_case(env, x + i, y) == -1)
  {
   if (i < *max || *max == 0)
   {
    if (env->verbose)
     ft_printf("enemy trouver left X: %d Y: %d\n", x + i, y);
    *max = i - 1;
    *act = 3;
    return ;
   }
  }
 }
 return ;
}


decompiled_code:
void __fastcall search_left(_DWORD *a1, unsigned int *a2, _DWORD *a3, _DWORD *a4)
{
unsigned int v4; // er12
unsigned int v5; // er15
int v6; // ebx

v4 = a2[1];
v5 = *a2;
if ( (int)(v4 - 1) > 0 )
{
v6 = 0;
while ( (unsigned int)check_case(a1, v5, v4 - v6) != -1 || *a3 && *a3 <= v6 )
{
if ( ++v6 == v4 - 1 )
return;
}
if ( *a1 )
ft_printf("enemy trouver bot X: %d Y: %d\n", v5, v4 - v6);
*a3 = v6;
*a4 = 4;
}
}

canonical_decompiled_code:
void __fastcall func3(_DWORD *a1, unsigned int *a2, _DWORD *a3, _DWORD *a4)
{
unsigned int v4; // er12
unsigned int v5; // er15
int v6; // ebx

v4 = a2[1];
v5 = *a2;
if ( (int)(v4 - 1) > 0 )
{
v6 = 0;
while ( (unsigned int)check_case(a1, v5, v4 - v6) != -1 || *a3 && *a3 <= v6 )
{
if ( ++v6 == v4 - 1 )
return;
}
if ( *a1 )
ft_printf("enemy trouver bot X: %d Y: %d\n", v5, v4 - v6);
*a3 = v6;
*a4 = 4;
}
}

original_code:
void search_left(t_env *env, t_play *p, int *max, int *act)
{
 int i;
 int x;
 int y;
 i = -1;
 x = p->init.x;
 y = p->init.y;
 while (++i < y - 1)
 {
  if (check_case(env, x, y - i) == -1)
  {
   if (i < *max || *max == 0)
   {
    if (env->verbose)
     ft_printf("enemy trouver bot X: %d Y: %d\n", x, y - i);
    *max = i;
    *act = 4;
    return ;
   }
  }
 }
 return ;
}

canonical_original_code:
void search_left(struct s_env *env, struct s_play *p, int *max, int *act)
{
 int i;
 int x;
 int y;
 i = -1;
 x = p->init.x;
 y = p->init.y;
 while (++i < y - 1)
 {
  if (check_case(env, x, y - i) == -1)
  {
   if (i < *max || *max == 0)
   {
    if (env->verbose)
     ft_printf("enemy trouver bot X: %d Y: %d\n", x, y - i);
    *max = i;
    *act = 4;
    return ;
   }
  }
 }
 return ;
}


original_code:
int search_hard(t_env *env, t_play *p)
{
 int pose;
 int i;
 i = return_pose(env, p->init.x, p->init.y);
 pose = return_pose(env, p->init.x, p->init.y);
 while (++i < env->mem->size_x * env->mem->size_y + env->mem->size_y)
 {
  if (check_case(env, return_x(env, i), return_y(env, i)) == -1)
   break ;
  if (i - pose >= 0 && check_case(env, return_x(env, i - pose)
       , return_y(env, i - pose)) == -1)
  {
   i = pose - i;
   break ;
  }
 }
 if (i == env->mem->size_x * env->mem->size_y +
  env->mem->size_y && env->turn > 10)
 {
  if (env->init)
   return (0);
  else
   clear_me(env, p);
 }
 return (moove_to(env, p, i));
}

canonical_original_code:
int search_hard(struct s_env *env, struct s_play *p)
{
 int pose;
 int i;
 i = return_pose(env, p->init.x, p->init.y);
 pose = return_pose(env, p->init.x, p->init.y);
 while (++i < env->mem->size_x * env->mem->size_y + env->mem->size_y)
 {
  if (check_case(env, return_x(env, i), return_y(env, i)) == -1)
   break ;
  if (i - pose >= 0 && check_case(env, return_x(env, i - pose)
       , return_y(env, i - pose)) == -1)
  {
   i = pose - i;
   break ;
  }
 }
 if (i == env->mem->size_x * env->mem->size_y +
  env->mem->size_y && env->turn > 10)
 {
  if (env->init)
   return (0);
  else
   clear_me(env, p);
 }
 return (moove_to(env, p, i));
}

variable_types: pose int


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

if ( *(int *)(*(_QWORD *)(a1 + 32) + 4096LL) <= 0 )
return ft_putstr_fd(*((_QWORD *)cur_term->type.Strings + 1), *(unsigned int *)(*(_QWORD *)(a1 + 24) + 120LL));
gen_tc_move_left(a1, 1LL);
result = *(_QWORD *)(a1 + 32);
--*(_DWORD *)(result + 4096);
return result;
}

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

if ( *(int *)(*(_QWORD *)(a1 + 32) + 4096LL) <= 0 )
return ft_putstr_fd(*((_QWORD *)cur_term->type.Strings + 1), *(unsigned int *)(*(_QWORD *)(a1 + 24) + 120LL));
gen_tc_move_left(a1, 1LL);
result = *(_QWORD *)(a1 + 32);
--*(_DWORD *)(result + 4096);
return result;
}

original_code:
void fn_curs_left(t_gen *gen, char *buff)
{
 (void)buff;
 if (gen->hist->pose_buff > 0)
 {
  gen_tc_move_left(gen, 1);
  gen->hist->pose_buff--;
 }
 else
  ft_putstr_fd(((TERMTYPE *)(cur_term))-> Strings[1], gen->term->fd);
}

canonical_original_code:
void fn_curs_left(struct s_gen *gen, char *buff)
{
 (void)buff;
 if (gen->hist->pose_buff > 0)
 {
  gen_tc_move_left(gen, 1);
  gen->hist->pose_buff--;
 }
 else
  ft_putstr_fd(((struct termtype *)(cur_term))-> Strings[1], gen->term->fd);
}

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:
buff
char *

user_defined_types: struct termtype { char *term_names; char *str_table; char *Booleans; short *Numbers; char **Strings; char *ext_str_table; char **ext_Names; unsigned short num_Booleans; unsigned short num_Numbers; unsigned short num_Strings; unsigned short ext_Booleans; unsigned short ext_Numbers; unsigned short ext_Strings; }


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

if ( *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4096LL) >= *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4100LL) )
return ft_putstr_fd(*((_QWORD *)cur_term->type.Strings + 1), *(unsigned int *)(*(_QWORD *)(a1 + 24) + 120LL));
gen_tc_move_right(a1, 1LL);
result = *(_QWORD *)(a1 + 32);
++*(_DWORD *)(result + 4096);
return result;
}

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

if ( *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4096LL) >= *(_DWORD *)(*(_QWORD *)(a1 + 32) + 4100LL) )
return ft_putstr_fd(*((_QWORD *)cur_term->type.Strings + 1), *(unsigned int *)(*(_QWORD *)(a1 + 24) + 120LL));
gen_tc_move_right(a1, 1LL);
result = *(_QWORD *)(a1 + 32);
++*(_DWORD *)(result + 4096);
return result;
}

original_code:
void fn_curs_right(t_gen *gen, char *buff)
{
 (void)buff;
 if (gen->hist->pose_buff < gen->hist->len)
 {
  gen_tc_move_right(gen, 1);
  gen->hist->pose_buff++;
 }
 else
  ft_putstr_fd(((TERMTYPE *)(cur_term))-> Strings[1], gen->term->fd);
}

canonical_original_code:
void fn_curs_right(struct s_gen *gen, char *buff)
{
 (void)buff;
 if (gen->hist->pose_buff < gen->hist->len)
 {
  gen_tc_move_right(gen, 1);
  gen->hist->pose_buff++;
 }
 else
  ft_putstr_fd(((struct termtype *)(cur_term))-> Strings[1], gen->term->fd);
}

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


original_code:
int possibility_to_up(t_gen *gen)
{
 int j;
 j = gen->hist->pose_buff - 1;
 while (gen->hist->buff[j] && gen->hist->buff[j] != '\n')
  j--;
 if (j > 0)
  return (gen->hist->pose_buff - j);
 return (0);
}

canonical_original_code:
int possibility_to_up(struct s_gen *gen)
{
 int j;
 j = gen->hist->pose_buff - 1;
 while (gen->hist->buff[j] && gen->hist->buff[j] != '\n')
  j--;
 if (j > 0)
  return (gen->hist->pose_buff - j);
 return (0);
}

variable_types: j int


decompiled_code:
__int64 __fastcall fn_curs_up(__int64 a1)
{
unsigned int v2; // eax
__int64 result; // rax
__int64 v4; // r8
__int64 v5; // rdi
int v6; // eax

v2 = possibility_to_up(a1);
if ( *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8216LL) )
{
if ( v2 )
{
LABEL_3:
gen_tc_move_left(a1, v2);
result = possibility_to_up(a1);
*(_DWORD *)(v4 + 4096) -= result;
return result;
}
tc_clean_line(a1);
v5 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8216LL);
v6 = *(_DWORD *)(v5 + 4100);
*(_QWORD *)(a1 + 32) = v5;
v5 += 4108LL;
*(_DWORD *)(v5 - 12) = v6;
result = ft_putstr_fd(v5, *(unsigned int *)(*(_QWORD *)(a1 + 24) + 120LL));
}
else
{
if ( v2 )
goto LABEL_3;
result = ft_putstr(*((_QWORD *)cur_term->type.Strings + 1));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v2; // eax
__int64 result; // rax
__int64 v4; // r8
__int64 v5; // rdi
int v6; // eax

v2 = func2(a1);
if ( *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8216LL) )
{
if ( v2 )
{
LABEL_3:
gen_tc_move_left(a1, v2);
result = func2(a1);
*(_DWORD *)(v4 + 4096) -= result;
return result;
}
tc_clean_line(a1);
v5 = *(_QWORD *)(*(_QWORD *)(a1 + 32) + 8216LL);
v6 = *(_DWORD *)(v5 + 4100);
*(_QWORD *)(a1 + 32) = v5;
v5 += 4108LL;
*(_DWORD *)(v5 - 12) = v6;
result = ft_putstr_fd(v5, *(unsigned int *)(*(_QWORD *)(a1 + 24) + 120LL));
}
else
{
if ( v2 )
goto LABEL_3;
result = ft_putstr(*((_QWORD *)cur_term->type.Strings + 1));
}
return result;
}

original_code:
void fn_curs_up(t_gen *gen, char *buff)
{
 (void)buff;
 if (gen->hist->prev && possibility_to_up(gen) == 0)
 {
  tc_clean_line(gen);
  gen->hist = gen->hist->prev;
  gen->hist->pose_buff = gen->hist->len;
  ft_putstr_fd(gen->hist->buff, gen->term->fd);
 }
 else if (possibility_to_up(gen))
 {
  gen_tc_move_left(gen, possibility_to_up(gen));
  gen->hist->pose_buff = gen->hist->pose_buff - possibility_to_up(gen);
 }
 else
  ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void fn_curs_up(struct s_gen *gen, char *buff)
{
 (void)buff;
 if (gen->hist->prev && possibility_to_up(gen) == 0)
 {
  tc_clean_line(gen);
  gen->hist = gen->hist->prev;
  gen->hist->pose_buff = gen->hist->len;
  ft_putstr_fd(gen->hist->buff, gen->term->fd);
 }
 else if (possibility_to_up(gen))
 {
  gen_tc_move_left(gen, possibility_to_up(gen));
  gen->hist->pose_buff = gen->hist->pose_buff - possibility_to_up(gen);
 }
 else
  ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}


original_code:
void fn_curs_down(t_gen *gen, char *buff)
{
 (void)buff;
 if (gen->hist->next)
 {
  tc_clean_line(gen);
  gen->hist = gen->hist->next;
  gen->hist->pose_buff = gen->hist->len;
  ft_putstr_fd(gen->hist->buff, gen->term->fd);
 }
 else
  ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void fn_curs_down(struct s_gen *gen, char *buff)
{
 (void)buff;
 if (gen->hist->next)
 {
  tc_clean_line(gen);
  gen->hist = gen->hist->next;
  gen->hist->pose_buff = gen->hist->len;
  ft_putstr_fd(gen->hist->buff, gen->term->fd);
 }
 else
  ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}


decompiled_code:
void __fastcall destroy_gen_hist(__int64 a1)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = *(_QWORD **)(a1 + 32);
while ( v1 )
{
v2 = v1;
v1 = (_QWORD *)v1[1026];
free(v2);
}
}

original_code:
void destroy_gen_hist(t_gen *gen)
{
 t_hist *current;
 t_hist *to_del;
 if (gen->hist)
 {
  current = gen->hist;
  while (current)
  {
   to_del = current;
   current = current->next;
   to_del->pose_buff = 0;
   to_del->len = 0;
   to_del->modif = 0;
   to_del->number = 0;
   to_del->next = ((void *)0);
   to_del->prev = ((void *)0);
   free(to_del);
   to_del = ((void *)0);
  }
 }
}

canonical_original_code:
void destroy_gen_hist(struct s_gen *gen)
{
 struct s_hist *current;
 struct s_hist *to_del;
 if (gen->hist)
 {
  current = gen->hist;
  while (current)
  {
   to_del = current;
   current = current->next;
   to_del->pose_buff = 0;
   to_del->len = 0;
   to_del->modif = 0;
   to_del->number = 0;
   to_del->next = ((void *)0);
   to_del->prev = ((void *)0);
   free(to_del);
   to_del = ((void *)0);
  }
 }
}

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


original_code:
void destroy_gen_term(t_gen *gen)
{
 if (gen->term)
 {
  gen->term->fd = 0;
  gen->term->wait = 0;
  if (gen->term->key)
   free_split(&(gen->term->key));
  free(gen->term);
  gen->term = ((void *)0);
 }
}

canonical_original_code:
void destroy_gen_term(struct s_gen *gen)
{
 if (gen->term)
 {
  gen->term->fd = 0;
  gen->term->wait = 0;
  if (gen->term->key)
   free_split(&(gen->term->key));
  free(gen->term);
  gen->term = ((void *)0);
 }
}


original_code:
void destroy_gen(void)
{
 t_gen *gen;
 gen = recup_gen();
 erase_list(gen->builtin);
 gen->ret = 0;
 gen->status = 0;
 gen->pid_fork = 0;
 if (gen->ps1)
 {
  if (gen->ps1->aff)
   ft_strdel(&(gen->ps1->aff));
  if (gen->ps1->env)
   ft_strdel(&(gen->ps1->env));
  gen->ps1->len = 0;
  free(gen->ps1);
  gen->ps1 = ((void *)0);
 }
 destroy_gen_term(gen);
 destroy_gen_hist(gen);
 ft_freetmpenv(gen);
}

canonical_original_code:
void destroy_gen()
{
 struct s_gen *gen;
 gen = recup_gen();
 erase_list(gen->builtin);
 gen->ret = 0;
 gen->status = 0;
 gen->pid_fork = 0;
 if (gen->ps1)
 {
  if (gen->ps1->aff)
   ft_strdel(&(gen->ps1->aff));
  if (gen->ps1->env)
   ft_strdel(&(gen->ps1->env));
  gen->ps1->len = 0;
  free(gen->ps1);
  gen->ps1 = ((void *)0);
 }
 destroy_gen_term(gen);
 destroy_gen_hist(gen);
 ft_freetmpenv(gen);
}


decompiled_code:
__int64 __fastcall return_x(__int64 a1, int a2)
{
return (unsigned int)(a2 / *(_DWORD *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
return (unsigned int)(a2 / *(_DWORD *)(a1 + 24));
}

original_code:
int return_x(t_env *env, int pose)
{
 return (pose / env->size_y);
}

canonical_original_code:
int return_x(struct s_env *env, int pose)
{
 return (pose / env->size_y);
}


decompiled_code:
__int64 __fastcall return_y(__int64 a1, int a2)
{
return (unsigned int)(a2 % *(_DWORD *)(a1 + 24));
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
return (unsigned int)(a2 % *(_DWORD *)(a1 + 24));
}

original_code:
int return_y(t_env *env, int pose)
{
 return (pose % env->size_y);
}

canonical_original_code:
int return_y(struct s_env *env, int pose)
{
 return (pose % env->size_y);
}


decompiled_code:
__int64 __fastcall return_pose(__int64 a1, int a2, unsigned int a3)
{
unsigned int v3; // er13
signed int v4; // ebp
int v5; // ebx
__int64 v6; // rax
int v7; // esi
int v9; // edx

v3 = a3 >> 31;
v4 = a3;
v5 = a2;
v6 = *(_QWORD *)(a1 + 64);
if ( *(_DWORD *)(v6 + 43416) >= a2 && a2 >= 0 )
goto LABEL_3;
ft_printf("invalide position X %d\n", (unsigned int)a2);
if ( a2 < 0 )
v5 = 0;
v6 = *(_QWORD *)(a1 + 64);
v9 = *(_DWORD *)(v6 + 43416);
if ( v9 >= v5 )
{
LABEL_3:
v7 = *(_DWORD *)(v6 + 43420);
if ( v4 <= v7 && !(_BYTE)v3 )
return (unsigned int)(v4 + v5 * v7 + 1);
ft_printf("invalide position Y %d\n", (unsigned int)v4);
}
else
{
v7 = *(_DWORD *)(v6 + 43420);
v5 = v9 - 1;
if ( v7 >= v4 && !(_BYTE)v3 )
return (unsigned int)(v4 + v5 * v7 + 1);
ft_printf("invalide position Y %d\n", (unsigned int)v4);
v4 &= ~v5 >> 31;
}
v7 = *(_DWORD *)(*(_QWORD *)(a1 + 64) + 43420LL);
if ( v7 < v4 )
v4 = v7 - 1;
return (unsigned int)(v4 + v5 * v7 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, unsigned int a3)
{
unsigned int v3; // er13
signed int v4; // ebp
int v5; // ebx
__int64 v6; // rax
int v7; // esi
int v9; // edx

v3 = a3 >> 31;
v4 = a3;
v5 = a2;
v6 = *(_QWORD *)(a1 + 64);
if ( *(_DWORD *)(v6 + 43416) >= a2 && a2 >= 0 )
goto LABEL_3;
ft_printf("invalide position X %d\n", (unsigned int)a2);
if ( a2 < 0 )
v5 = 0;
v6 = *(_QWORD *)(a1 + 64);
v9 = *(_DWORD *)(v6 + 43416);
if ( v9 >= v5 )
{
LABEL_3:
v7 = *(_DWORD *)(v6 + 43420);
if ( v4 <= v7 && !(_BYTE)v3 )
return (unsigned int)(v4 + v5 * v7 + 1);
ft_printf("invalide position Y %d\n", (unsigned int)v4);
}
else
{
v7 = *(_DWORD *)(v6 + 43420);
v5 = v9 - 1;
if ( v7 >= v4 && !(_BYTE)v3 )
return (unsigned int)(v4 + v5 * v7 + 1);
ft_printf("invalide position Y %d\n", (unsigned int)v4);
v4 &= ~v5 >> 31;
}
v7 = *(_DWORD *)(*(_QWORD *)(a1 + 64) + 43420LL);
if ( v7 < v4 )
v4 = v7 - 1;
return (unsigned int)(v4 + v5 * v7 + 1);
}

original_code:
int return_pose(t_env *env, int x, int y)
{
 if (x > env->mem->size_x || x < 0)
 {
  ft_printf("invalide position X %d\n", x);
  if (x < 0)
   x = 0;
  if (x > env->mem->size_x)
   x = env->mem->size_x - 1;
 }
 if (y > env->mem->size_y || y < 0)
 {
  ft_printf("invalide position Y %d\n", y);
  if (x < 0)
   y = 0;
  if (y > env->mem->size_y)
   y = env->mem->size_y - 1;
 }
 return (x * env->mem->size_y + y + 1);
}

canonical_original_code:
int return_pose(struct s_env *env, int x, int y)
{
 if (x > env->mem->size_x || x < 0)
 {
  ft_printf("invalide position X %d\n", x);
  if (x < 0)
   x = 0;
  if (x > env->mem->size_x)
   x = env->mem->size_x - 1;
 }
 if (y > env->mem->size_y || y < 0)
 {
  ft_printf("invalide position Y %d\n", y);
  if (x < 0)
   y = 0;
  if (y > env->mem->size_y)
   y = env->mem->size_y - 1;
 }
 return (x * env->mem->size_y + y + 1);
}


original_code:
int check_case(t_env *env, int x, int y)
{
 if (x >= env->mem->size_x || y >= env->mem->size_y || x < 0 || y < 0)
  return (-2);
 if (env->map[return_pose(env, x, y)] == env->player_id)
  return (1);
 else if (env->map[return_pose(env, x, y)] == 0)
  return (0);
 else
  return (-1);
}

canonical_original_code:
int check_case(struct s_env *env, int x, int y)
{
 if (x >= env->mem->size_x || y >= env->mem->size_y || x < 0 || y < 0)
  return (-2);
 if (env->map[return_pose(env, x, y)] == env->player_id)
  return (1);
 else if (env->map[return_pose(env, x, y)] == 0)
  return (0);
 else
  return (-1);
}


decompiled_code:
__int64 __fastcall nb_enemy(__int64 a1, int *a2)
{
_BOOL4 v3; // er12
int v4; // er12
int v5; // er12

v3 = check_case(a1, *a2 + 1, a2[1]) == -1;
v4 = ((unsigned int)check_case(a1, *a2 - 1, a2[1]) == -1) + v3;
v5 = ((unsigned int)check_case(a1, *a2, a2[1] + 1) == -1) + v4;
return (unsigned int)((unsigned int)check_case(a1, *a2, a2[1] - 1) == -1) + v5;
}

original_code:
int nb_enemy(t_env *env, t_play *p)
{
 int nb_e;
 nb_e = 0;
 nb_e = (check_case(env, p->init.x + 1, p->init.y) == -1) ? nb_e + 1 : nb_e;
 nb_e = (check_case(env, p->init.x - 1, p->init.y) == -1) ? nb_e + 1 : nb_e;
 nb_e = (check_case(env, p->init.x, p->init.y + 1) == -1) ? nb_e + 1 : nb_e;
 nb_e = (check_case(env, p->init.x, p->init.y - 1) == -1) ? nb_e + 1 : nb_e;
 return (nb_e);
}

canonical_original_code:
int nb_enemy(struct s_env *env, struct s_play *p)
{
 int nb_e;
 nb_e = 0;
 nb_e = (check_case(env, p->init.x + 1, p->init.y) == -1) ? nb_e + 1 : nb_e;
 nb_e = (check_case(env, p->init.x - 1, p->init.y) == -1) ? nb_e + 1 : nb_e;
 nb_e = (check_case(env, p->init.x, p->init.y + 1) == -1) ? nb_e + 1 : nb_e;
 nb_e = (check_case(env, p->init.x, p->init.y - 1) == -1) ? nb_e + 1 : nb_e;
 return (nb_e);
}


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

if ( (unsigned int)ft_isprint((unsigned int)(char)a1) )
{
result = 32LL;
if ( (_BYTE)a1 != 9 )
result = a1;
}
else
{
result = 10LL;
if ( (_BYTE)a1 != 10 )
result = 0LL;
}
return result;
}

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

if ( (unsigned int)ft_isprint((unsigned int)(char)a1) )
{
result = 32LL;
if ( (_BYTE)a1 != 9 )
result = a1;
}
else
{
result = 10LL;
if ( (_BYTE)a1 != 10 )
result = 0LL;
}
return result;
}

original_code:
char format_str(char key)
{
 if (ft_isprint(key) || key == '\n')
 {
  if (key == '\t')
   return (32);
  return (key);
 }
 return (0);
}

variable_types: key char

return_type: char


original_code:
void print_in(t_gen *gen, char k)
{
 char *tmp;
 int i;
 char key[2];
 key[0] = k;
 key[1] = '\0';
 tmp = (char *)malloc(sizeof(char) * 4096);
 ft_bzero(tmp, 4096);
 ft_strncat(tmp, gen->hist->buff, gen->hist->pose_buff);
 ft_strcat(tmp, key);
 ft_strcat(tmp, gen->hist->buff + gen->hist->pose_buff);
 ft_memcpy(gen->hist->buff, tmp, 4096);
 free(tmp);
 tc_clean_line(gen);
 gen->hist->pose_buff++;
 gen->hist->len++;
 ft_putstr_fd(gen->hist->buff, gen->term->fd);
 i = gen->hist->pose_buff;
 gen->hist->pose_buff = gen->hist->len;
 gen_tc_move_left(gen, gen->hist->len - i);
 gen->hist->pose_buff = i;
}

canonical_original_code:
void print_in(struct s_gen *gen, char k)
{
 char *tmp;
 int i;
 char key[2];
 key[0] = k;
 key[1] = '\0';
 tmp = (char *)malloc(sizeof(char) * 4096);
 ft_bzero(tmp, 4096);
 ft_strncat(tmp, gen->hist->buff, gen->hist->pose_buff);
 ft_strcat(tmp, key);
 ft_strcat(tmp, gen->hist->buff + gen->hist->pose_buff);
 ft_memcpy(gen->hist->buff, tmp, 4096);
 free(tmp);
 tc_clean_line(gen);
 gen->hist->pose_buff++;
 gen->hist->len++;
 ft_putstr_fd(gen->hist->buff, gen->term->fd);
 i = gen->hist->pose_buff;
 gen->hist->pose_buff = gen->hist->len;
 gen_tc_move_left(gen, gen->hist->len - i);
 gen->hist->pose_buff = i;
}

variable_types: k char

variable_types:
tmp
char *

variable_types:
key
char [2]


decompiled_code:
__int64 __fastcall ft_putnbru(unsigned int a1, unsigned int a2)
{
unsigned int v3; // er8
__int64 v4; // rsi
__int64 v5; // rdx
int v6; // ebp
__int64 v7; // rdi
int v8; // er12
int v9; // ebx
int v11; // ebx

if ( a2 == 117 )
{
v3 = 10;
v4 = 10LL;
if ( a1 < 0xA )
return ft_putchar((unsigned __int8)(a1 + 48), v4);
goto LABEL_11;
}
if ( a2 == 111 )
{
v3 = 8;
v4 = 8LL;
if ( a1 < 8 )
return ft_putchar((unsigned __int8)(a1 + 48), v4);
LABEL_11:
v8 = a1 % v3;
LABEL_12:
v11 = ft_putnbru(a1 / v3, v4, a1 % v3);
return v11 + (unsigned int)ft_putchar((unsigned __int8)(v8 + 48), v4);
}
v3 = 16;
if ( (a2 & 0xFFFFFFF7) != 112 )
v3 = a2;
v4 = v3;
if ( a1 >= v3 )
{
v5 = a1 % v3;
v6 = a1 % v3;
v7 = a1 / v3;
LOBYTE(v8) = v5;
if ( (unsigned int)v5 > 9 )
{
v9 = ft_putnbru(v7, v3, v5);
return v9 + (unsigned int)ft_putchar((unsigned int)(char)(v6 + 87), v4);
}
goto LABEL_12;
}
if ( a1 <= 9 )
return ft_putchar((unsigned __int8)(a1 + 48), v4);
return ft_putchar((unsigned int)(char)(a1 + 87), v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2)
{
unsigned int v3; // er8
__int64 v4; // rsi
__int64 v5; // rdx
int v6; // ebp
__int64 v7; // rdi
int v8; // er12
int v9; // ebx
int v11; // ebx

if ( a2 == 117 )
{
v3 = 10;
v4 = 10LL;
if ( a1 < 0xA )
return ft_putchar((unsigned __int8)(a1 + 48), v4);
goto LABEL_11;
}
if ( a2 == 111 )
{
v3 = 8;
v4 = 8LL;
if ( a1 < 8 )
return ft_putchar((unsigned __int8)(a1 + 48), v4);
LABEL_11:
v8 = a1 % v3;
LABEL_12:
v11 = func0(a1 / v3, v4, a1 % v3);
return v11 + (unsigned int)ft_putchar((unsigned __int8)(v8 + 48), v4);
}
v3 = 16;
if ( (a2 & 0xFFFFFFF7) != 112 )
v3 = a2;
v4 = v3;
if ( a1 >= v3 )
{
v5 = a1 % v3;
v6 = a1 % v3;
v7 = a1 / v3;
LOBYTE(v8) = v5;
if ( (unsigned int)v5 > 9 )
{
v9 = func0(v7, v3, v5);
return v9 + (unsigned int)ft_putchar((unsigned int)(char)(v6 + 87), v4);
}
goto LABEL_12;
}
if ( a1 <= 9 )
return ft_putchar((unsigned __int8)(a1 + 48), v4);
return ft_putchar((unsigned int)(char)(a1 + 87), v3);
}

original_code:
int ft_putnbru(unsigned int n, int b)
{
 if (b == 'u')
  b = 10;
 else if (b == 'o')
  b = 8;
 else if (b == 'x' || b == 'p')
  b = 16;
 if (n < (unsigned int)b)
 {
  if (n < 10)
   return (ft_putchar(n + '0'));
  else
   return (ft_putchar(n - 10 + 'a'));
 }
 else
 {
  if ((n % b) < 10)
   return (ft_putnbru((n / b), b) + ft_putchar((n % b) + '0'));
  else
   return (ft_putnbru((n / b), b) + ft_putchar((n % b) - 10 + 'a'));
 }
}

variable_types:
n
unsigned int

variable_types: b int


decompiled_code:
__int64 __fastcall ft_putnbru_fd(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v5; // er8
__int64 v6; // rsi
unsigned int v7; // edx
int v8; // er12
__int64 v9; // rdi
int v10; // er13
int v11; // ebx
__int64 v13; // rdi
int v14; // ebx

if ( a2 == 117 )
{
v5 = 10;
v6 = 10LL;
if ( a1 < 0xA )
goto LABEL_9;
}
else
{
if ( a2 != 111 )
{
v5 = 16;
if ( (a2 & 0xFFFFFFF7) != 112 )
v5 = a2;
v6 = v5;
if ( a1 >= v5 )
{
v7 = a1 % v5;
v8 = a1 % v5;
v9 = a1 / v5;
LOBYTE(v10) = v7;
if ( v7 > 9 )
{
v11 = ft_putnbru_fd(v9, v5, a3);
return v11 + (unsigned int)ft_putchar_fd((unsigned int)(char)(v8 + 87), a3);
}
goto LABEL_13;
}
if ( a1 > 9 )
{
v13 = (unsigned int)(char)(a1 + 87);
return ft_putchar_fd(v13, a3);
}
LABEL_9:
v13 = (unsigned __int8)(a1 + 48);
return ft_putchar_fd(v13, a3);
}
v5 = 8;
v6 = 8LL;
if ( a1 < 8 )
goto LABEL_9;
}
v10 = a1 % v5;
LABEL_13:
v14 = ft_putnbru_fd(a1 / v5, v6, a3);
return v14 + (unsigned int)ft_putchar_fd((unsigned __int8)(v10 + 48), a3);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned int a2, unsigned int a3)
{
unsigned int v5; // er8
__int64 v6; // rsi
unsigned int v7; // edx
int v8; // er12
__int64 v9; // rdi
int v10; // er13
int v11; // ebx
__int64 v13; // rdi
int v14; // ebx

if ( a2 == 117 )
{
v5 = 10;
v6 = 10LL;
if ( a1 < 0xA )
goto LABEL_9;
}
else
{
if ( a2 != 111 )
{
v5 = 16;
if ( (a2 & 0xFFFFFFF7) != 112 )
v5 = a2;
v6 = v5;
if ( a1 >= v5 )
{
v7 = a1 % v5;
v8 = a1 % v5;
v9 = a1 / v5;
LOBYTE(v10) = v7;
if ( v7 > 9 )
{
v11 = func1(v9, v5, a3);
return v11 + (unsigned int)ft_putchar_fd((unsigned int)(char)(v8 + 87), a3);
}
goto LABEL_13;
}
if ( a1 > 9 )
{
v13 = (unsigned int)(char)(a1 + 87);
return ft_putchar_fd(v13, a3);
}
LABEL_9:
v13 = (unsigned __int8)(a1 + 48);
return ft_putchar_fd(v13, a3);
}
v5 = 8;
v6 = 8LL;
if ( a1 < 8 )
goto LABEL_9;
}
v10 = a1 % v5;
LABEL_13:
v14 = func1(a1 / v5, v6, a3);
return v14 + (unsigned int)ft_putchar_fd((unsigned __int8)(v10 + 48), a3);
}

original_code:
int ft_putnbru_fd(unsigned int n, int b, int fd)
{
 if (b == 'u')
  b = 10;
 else if (b == 'o')
  b = 8;
 else if (b == 'x' || b == 'p')
  b = 16;
 if (n < (unsigned int)b)
 {
  if (n < 10)
   return (ft_putchar_fd(n + '0', fd));
  else
   return (ft_putchar_fd(n - 10 + 'a', fd));
 }
 else
 {
  if ((n % b) < 10)
   return (ft_putnbru_fd((n / b), b, fd) + ft_putchar_fd((n % b) + '0', fd));
  else
   return (ft_putnbru_fd((n / b), b, fd) + ft_putchar_fd((n % b) - 10 + 'a', fd));
 }
}

variable_types: fd int


decompiled_code:
__int64 __fastcall ft_putpoint_fd(unsigned __int64 a1, unsigned int a2)
{
int v2; // ebp
__int64 result; // rax
char v4; // bp
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rdi
char v7; // bp
int v8; // ebx
int v9; // ebx

if ( a1 > 0xF )
{
v4 = a1;
v5 = a1 & 0xF;
v6 = a1 >> 4;
v7 = v4 & 0xF;
if ( v5 <= 9 )
{
v9 = ft_putpoint_fd(v6);
result = v9 + (unsigned int)ft_putchar_fd((unsigned __int8)(v7 + 48), a2);
}
else
{
v8 = ft_putpoint_fd(v6);
result = v8 + (unsigned int)ft_putchar_fd((unsigned __int8)(v7 + 87), a2);
}
}
else
{
v2 = ft_putstr_fd(&unk_35E);
if ( a1 > 9 )
result = v2 + (unsigned int)ft_putchar_fd((unsigned __int8)(a1 + 87), a2);
else
result = v2 + (unsigned int)ft_putchar_fd((unsigned __int8)(a1 + 48), a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1, unsigned int a2)
{
int v2; // ebp
__int64 result; // rax
char v4; // bp
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rdi
char v7; // bp
int v8; // ebx
int v9; // ebx

if ( a1 > 0xF )
{
v4 = a1;
v5 = a1 & 0xF;
v6 = a1 >> 4;
v7 = v4 & 0xF;
if ( v5 <= 9 )
{
v9 = func2(v6);
result = v9 + (unsigned int)ft_putchar_fd((unsigned __int8)(v7 + 48), a2);
}
else
{
v8 = func2(v6);
result = v8 + (unsigned int)ft_putchar_fd((unsigned __int8)(v7 + 87), a2);
}
}
else
{
v2 = ft_putstr_fd(&unk_35E);
if ( a1 > 9 )
result = v2 + (unsigned int)ft_putchar_fd((unsigned __int8)(a1 + 87), a2);
else
result = v2 + (unsigned int)ft_putchar_fd((unsigned __int8)(a1 + 48), a2);
}
return result;
}

original_code:
int ft_putpoint_fd(long unsigned int n, int fd)
{
 if (n < 16)
 {
  if (n < 10)
   return (ft_putstr_fd("0x", fd) + ft_putchar_fd(n + '0', fd));
  else
   return (ft_putstr_fd("0x", fd) + ft_putchar_fd(n - 10 + 'a', fd));
 }
 else
 {
  if ((n % 16) < 10)
   return (ft_putpoint_fd(n / 16, fd) + ft_putchar_fd((n % 16) + '0', fd));
  else
   return (ft_putpoint_fd(n / 16, fd) + ft_putchar_fd((n % 16) - 10 + 'a', fd));
 }
}

canonical_original_code:
int ft_putpoint_fd(unsigned long n, int fd)
{
 if (n < 16)
 {
  if (n < 10)
   return (ft_putstr_fd("0x", fd) + ft_putchar_fd(n + '0', fd));
  else
   return (ft_putstr_fd("0x", fd) + ft_putchar_fd(n - 10 + 'a', fd));
 }
 else
 {
  if ((n % 16) < 10)
   return (ft_putpoint_fd(n / 16, fd) + ft_putchar_fd((n % 16) + '0', fd));
  else
   return (ft_putpoint_fd(n / 16, fd) + ft_putchar_fd((n % 16) - 10 + 'a', fd));
 }
}

variable_types:
n
unsigned long


decompiled_code:
__int64 __fastcall ft_putpoint(unsigned __int64 a1, __int64 a2)
{
int v2; // ebp
__int64 result; // rax
char v4; // bp
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rdi
char v7; // bp
int v8; // ebx
int v9; // ebx

if ( a1 > 0xF )
{
v4 = a1;
v5 = a1 & 0xF;
v6 = a1 >> 4;
v7 = v4 & 0xF;
if ( v5 <= 9 )
{
v9 = ft_putpoint(v6);
result = v9 + (unsigned int)ft_putchar((unsigned __int8)(v7 + 48), a2);
}
else
{
v8 = ft_putpoint(v6);
result = v8 + (unsigned int)ft_putchar((unsigned __int8)(v7 + 87), a2);
}
}
else
{
v2 = ft_putstr(&unk_35E);
if ( a1 > 9 )
result = v2 + (unsigned int)ft_putchar((unsigned __int8)(a1 + 87), a2);
else
result = v2 + (unsigned int)ft_putchar((unsigned __int8)(a1 + 48), a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int64 a1, __int64 a2)
{
int v2; // ebp
__int64 result; // rax
char v4; // bp
unsigned __int64 v5; // rbx
unsigned __int64 v6; // rdi
char v7; // bp
int v8; // ebx
int v9; // ebx

if ( a1 > 0xF )
{
v4 = a1;
v5 = a1 & 0xF;
v6 = a1 >> 4;
v7 = v4 & 0xF;
if ( v5 <= 9 )
{
v9 = func3(v6);
result = v9 + (unsigned int)ft_putchar((unsigned __int8)(v7 + 48), a2);
}
else
{
v8 = func3(v6);
result = v8 + (unsigned int)ft_putchar((unsigned __int8)(v7 + 87), a2);
}
}
else
{
v2 = ft_putstr(&unk_35E);
if ( a1 > 9 )
result = v2 + (unsigned int)ft_putchar((unsigned __int8)(a1 + 87), a2);
else
result = v2 + (unsigned int)ft_putchar((unsigned __int8)(a1 + 48), a2);
}
return result;
}

original_code:
int ft_putpoint(long unsigned int n)
{
 if (n < 16)
 {
  if (n < 10)
   return (ft_putstr("0x") + ft_putchar(n + '0'));
  else
   return (ft_putstr("0x") + ft_putchar(n - 10 + 'a'));
 }
 else
 {
  if ((n % 16) < 10)
   return (ft_putpoint(n / 16) + ft_putchar((n % 16) + '0'));
  else
   return (ft_putpoint(n / 16) + ft_putchar((n % 16) - 10 + 'a'));
 }
}

canonical_original_code:
int ft_putpoint(unsigned long n)
{
 if (n < 16)
 {
  if (n < 10)
   return (ft_putstr("0x") + ft_putchar(n + '0'));
  else
   return (ft_putstr("0x") + ft_putchar(n - 10 + 'a'));
 }
 else
 {
  if ((n % 16) < 10)
   return (ft_putpoint(n / 16) + ft_putchar((n % 16) + '0'));
  else
   return (ft_putpoint(n / 16) + ft_putchar((n % 16) - 10 + 'a'));
 }
}


decompiled_code:
__int64 __fastcall save_char(__int64 a1, int a2, int a3)
{
__int64 result; // rax
__int64 v6; // r12
int v7; // ebx
__int64 v8; // rbp
__int64 v9; // r15
__int64 v10; // rdi
char v11[58]; // [rsp+Eh] [rbp-3Ah] BYREF

result = ft_bzero(v11, 2LL);
if ( a3 >= 0 )
{
v6 = 8240LL * a2;
v7 = 0;
do
{
while ( 1 )
{
v8 = v7;
result = ft_isascii((unsigned int)*(char *)(v7 + v6 + *(_QWORD *)(a1 + 24) + 44));
if ( (_DWORD)result )
break;
if ( a3 < ++v7 )
return result;
}
++v7;
v9 = v6 + *(_QWORD *)(a1 + 24);
v10 = *(_QWORD *)(v9 + 24);
v11[0] = *(_BYTE *)(v9 + v8 + 44);
result = ft_joinfree(v10, v11, 1LL);
*(_QWORD *)(v9 + 24) = result;
}
while ( a3 >= v7 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3)
{
__int64 result; // rax
__int64 v6; // r12
int v7; // ebx
__int64 v8; // rbp
__int64 v9; // r15
__int64 v10; // rdi
char v11[58]; // [rsp+Eh] [rbp-3Ah] BYREF

result = ft_bzero(v11, 2LL);
if ( a3 >= 0 )
{
v6 = 8240LL * a2;
v7 = 0;
do
{
while ( 1 )
{
v8 = v7;
result = ft_isascii((unsigned int)*(char *)(v7 + v6 + *(_QWORD *)(a1 + 24) + 44));
if ( (_DWORD)result )
break;
if ( a3 < ++v7 )
return result;
}
++v7;
v9 = v6 + *(_QWORD *)(a1 + 24);
v10 = *(_QWORD *)(v9 + 24);
v11[0] = *(_BYTE *)(v9 + v8 + 44);
result = ft_joinfree(v10, v11, 1LL);
*(_QWORD *)(v9 + 24) = result;
}
while ( a3 >= v7 );
}
return result;
}

original_code:
void save_char(t_env *env, int cs, int ret)
{
 char c[2];
 int i;
 i = 0;
 ft_bzero(c, 2);
 while (i <= ret)
 {
  if (ft_isascii(env->fds[cs].buff_read[i]))
  {
   c[0] = env->fds[cs].buff_read[i];
   env->fds[cs].save = ft_joinfree(env->fds[cs].save, (char *)c, 1);
  }
  i++;
 }
}

canonical_original_code:
void save_char(struct s_env *env, int cs, int ret)
{
 char c[2];
 int i;
 i = 0;
 ft_bzero(c, 2);
 while (i <= ret)
 {
  if (ft_isascii(env->fds[cs].buff_read[i]))
  {
   c[0] = env->fds[cs].buff_read[i];
   env->fds[cs].save = ft_joinfree(env->fds[cs].save, (char *)c, 1);
  }
  i++;
 }
}

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:
c
char [2]

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