decompiled_code:
__int64 __fastcall print_alloc(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 24);
ft_putstr("TINY : ");
ft_putpoint(v1);
ft_putstr("\n");
print_table(*(_QWORD *)(v1 + 16));
v2 = *(_QWORD *)(v1 + 24);
ft_putstr("SMALL : ");
ft_putpoint(v2);
ft_putstr("\n");
print_table(*(_QWORD *)(v2 + 16));
v3 = *(_QWORD *)(v2 + 24);
ft_putstr("LARGE : ");
ft_putpoint(v3);
for ( result = ft_putstr("\n"); v3; v3 = *(_QWORD *)(v3 + 24) )
result = print_table(*(_QWORD *)(v3 + 16));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbx
__int64 v3; // rbx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 24);
ft_putstr("TINY : ");
ft_putpoint(v1);
ft_putstr("\n");
func2(*(_QWORD *)(v1 + 16));
v2 = *(_QWORD *)(v1 + 24);
ft_putstr("SMALL : ");
ft_putpoint(v2);
ft_putstr("\n");
func2(*(_QWORD *)(v2 + 16));
v3 = *(_QWORD *)(v2 + 24);
ft_putstr("LARGE : ");
ft_putpoint(v3);
for ( result = ft_putstr("\n"); v3; v3 = *(_QWORD *)(v3 + 24) )
result = func2(*(_QWORD *)(v3 + 16));
return result;
}

original_code:
void print_alloc(t_table *table)
{
 table = table->next;
 ft_putstr("TINY : ");
 ft_putpoint((unsigned long int)table);
 ft_putstr("\n");
 print_table(table->page);
 table = table->next;
 ft_putstr("SMALL : ");
 ft_putpoint((unsigned long int)table);
 ft_putstr("\n");
 print_table(table->page);
 table = table->next;
 ft_putstr("LARGE : ");
 ft_putpoint((unsigned long int)table);
 ft_putstr("\n");
 while (table)
 {
  print_table(table->page);
  table = table->next;
 }
}

canonical_original_code:
void print_alloc(struct s_table *table)
{
 table = table->next;
 ft_putstr("TINY : ");
 ft_putpoint((unsigned long)table);
 ft_putstr("\n");
 print_table(table->page);
 table = table->next;
 ft_putstr("SMALL : ");
 ft_putpoint((unsigned long)table);
 ft_putstr("\n");
 print_table(table->page);
 table = table->next;
 ft_putstr("LARGE : ");
 ft_putpoint((unsigned long)table);
 ft_putstr("\n");
 while (table)
 {
  print_table(table->page);
  table = table->next;
 }
}

variable_types: struct s_table { unsigned long max_len; int page_len; void *page; void *next; } *


decompiled_code:
__int64 show_alloc_mem()
{
__int64 v0; // rax

v0 = paye_ton_thon();
return print_alloc(v0);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax

v0 = paye_ton_thon();
return func3(v0);
}

original_code:
void show_alloc_mem(void)
{
 print_alloc(paye_ton_thon());
}

canonical_original_code:
void show_alloc_mem()
{
 print_alloc(paye_ton_thon());
}

return_type: void


decompiled_code:
__pid_t __fastcall ft_launch(__int64 a1, __int64 a2, int a3, int a4)
{
const char **v4; // r14
const char *v8; // rdi
__int64 v9; // rdi
const char *v10; // rax
__pid_t result; // eax
char **v12; // rbp

v4 = (const char **)(a1 + 8LL * a3);
if ( access(*v4, 0) == -1 || (v8 = *v4, **v4 != 46) || v8[1] != 47 )
{
*(_DWORD *)(a2 + 48) = 5;
v9 = 5LL;
LABEL_4:
v10 = (const char *)strror(v9);
return ft_dprintf(2LL, "env: %s: %s\n", *v4, v10);
}
if ( access(v8, 1) == -1 )
{
*(_DWORD *)(a2 + 48) = 4;
v9 = 4LL;
goto LABEL_4;
}
v12 = ft_tmpenv(a1, a2, a4, a3);
result = fork();
if ( result > 0 )
{
wait(0LL);
result = ft_freetmpenv(v12);
}
else if ( !result )
{
result = execve(*v4, (char *const *)v4, (char *const *)*v12);
}
v9 = *(unsigned int *)(a2 + 48);
if ( (_DWORD)v9 )
goto LABEL_4;
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func3(__int64 a1, __int64 a2, int a3, int a4)
{
const char **v4; // r14
const char *v8; // rdi
__int64 v9; // rdi
const char *v10; // rax
__pid_t result; // eax
char **v12; // rbp

v4 = (const char **)(a1 + 8LL * a3);
if ( access(*v4, 0) == -1 || (v8 = *v4, **v4 != 46) || v8[1] != 47 )
{
*(_DWORD *)(a2 + 48) = 5;
v9 = 5LL;
LABEL_4:
v10 = (const char *)strror(v9);
return ft_dprintf(2LL, "env: %s: %s\n", *v4, v10);
}
if ( access(v8, 1) == -1 )
{
*(_DWORD *)(a2 + 48) = 4;
v9 = 4LL;
goto LABEL_4;
}
v12 = func2(a1, a2, a4, a3);
result = fork();
if ( result > 0 )
{
wait(0LL);
result = ft_freetmpenv(v12);
}
else if ( !result )
{
result = execve(*v4, (char *const *)v4, (char *const *)*v12);
}
v9 = *(unsigned int *)(a2 + 48);
if ( (_DWORD)v9 )
goto LABEL_4;
return result;
}

original_code:
void ft_launch(char **com, t_gen *env, int i, int use_env)
{
 pid_t father;
 t_gen *tmpenv;
 if (access(com[i], 0) != -1 && com[i][0] == '.' && com[i][1] == '/')
  if (access(com[i], 1) != -1)
  {
   tmpenv = ft_tmpenv(com, env, use_env, i);
   father = fork();
   if (father > 0)
   {
    wait(0);
    ft_freetmpenv(tmpenv);
   }
   else if (father == 0)
    execve(com[i], &(com[i]), tmpenv->env);
  }
  else
   env->ret = 4;
 else
  env->ret = 5;
 if (env->ret != 0)
  ft_dprintf(2, "env: %s: %s\n", com[i], strror(env->ret));
}

canonical_original_code:
void ft_launch(char **com, struct s_gen *env, int i, int use_env)
{
 int father;
 struct s_gen *tmpenv;
 if (access(com[i], 0) != -1 && com[i][0] == '.' && com[i][1] == '/')
  if (access(com[i], 1) != -1)
  {
   tmpenv = ft_tmpenv(com, env, use_env, i);
   father = fork();
   if (father > 0)
   {
    wait(0);
    ft_freetmpenv(tmpenv);
   }
   else if (father == 0)
    execve(com[i], &(com[i]), tmpenv->env);
  }
  else
   env->ret = 4;
 else
  env->ret = 5;
 if (env->ret != 0)
  ft_dprintf(2, "env: %s: %s\n", com[i], strror(env->ret));
}

variable_types:
com
char **

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

variable_types: i int

variable_types: father int

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

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


decompiled_code:
int __fastcall ft_env(unsigned int *a1, _QWORD *a2)
{
__int64 v4; // rax
__int64 v5; // rdi
__int64 v6; // rsi
char *v7; // rdi
int v8; // ecx
__int64 v9; // r9
__int64 v10; // rbx
const char *v11; // rdx
int v12; // ebx
const char *v13; // rdx
__int64 i; // rbx

v4 = *(_QWORD *)a1;
v5 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( !v5 )
goto LABEL_10;
LODWORD(v4) = ft_strcmp(v5, "-i");
if ( (_DWORD)v4 )
{
v6 = 1LL;
v7 = *(char **)(*(_QWORD *)a1 + 8LL);
if ( v7 )
goto LABEL_6;
LABEL_10:
if ( !a2 )
return v4;
goto LABEL_11;
}
v6 = 2LL;
v7 = *(char **)(*(_QWORD *)a1 + 16LL);
if ( !v7 )
return v4;
do
{
LABEL_6:
if ( (unsigned int)ft_s_constprop_0(v7) == -1 )
{
LODWORD(v4) = ft_launch(v9, (__int64)a2, v6, v8);
return v4;
}
++v6;
v7 = *(char **)(v9 + 8 * v6);
}
while ( v7 );
if ( v8 )
{
v4 = 16LL;
v12 = 2;
}
else
{
if ( a2 )
{
LABEL_11:
v10 = 0LL;
while ( *a2 )
{
v11 = *(const char **)(*a2 + v10);
v10 += 8LL;
if ( !v11 )
break;
ft_dprintf(a1[3], "%s\n", v11);
}
v9 = *(_QWORD *)a1;
v4 = 8LL;
v12 = 1;
goto LABEL_18;
}
v4 = 8LL;
v12 = 1;
}
LABEL_18:
v13 = *(const char **)(v9 + v4);
for ( i = 8LL * (v12 + 1); v13; i += 8LL )
{
ft_dprintf(a1[3], "%s\n", v13);
v4 = *(_QWORD *)a1;
v13 = *(const char **)(*(_QWORD *)a1 + i);
}
return v4;
}

canonical_decompiled_code:
int __fastcall func4(unsigned int *a1, _QWORD *a2)
{
__int64 v4; // rax
__int64 v5; // rdi
__int64 v6; // rsi
char *v7; // rdi
int v8; // ecx
__int64 v9; // r9
__int64 v10; // rbx
const char *v11; // rdx
int v12; // ebx
const char *v13; // rdx
__int64 i; // rbx

v4 = *(_QWORD *)a1;
v5 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
if ( !v5 )
goto LABEL_10;
LODWORD(v4) = ft_strcmp(v5, "-i");
if ( (_DWORD)v4 )
{
v6 = 1LL;
v7 = *(char **)(*(_QWORD *)a1 + 8LL);
if ( v7 )
goto LABEL_6;
LABEL_10:
if ( !a2 )
return v4;
goto LABEL_11;
}
v6 = 2LL;
v7 = *(char **)(*(_QWORD *)a1 + 16LL);
if ( !v7 )
return v4;
do
{
LABEL_6:
if ( (unsigned int)func0(v7) == -1 )
{
LODWORD(v4) = func3(v9, (__int64)a2, v6, v8);
return v4;
}
++v6;
v7 = *(char **)(v9 + 8 * v6);
}
while ( v7 );
if ( v8 )
{
v4 = 16LL;
v12 = 2;
}
else
{
if ( a2 )
{
LABEL_11:
v10 = 0LL;
while ( *a2 )
{
v11 = *(const char **)(*a2 + v10);
v10 += 8LL;
if ( !v11 )
break;
ft_dprintf(a1[3], "%s\n", v11);
}
v9 = *(_QWORD *)a1;
v4 = 8LL;
v12 = 1;
goto LABEL_18;
}
v4 = 8LL;
v12 = 1;
}
LABEL_18:
v13 = *(const char **)(v9 + v4);
for ( i = 8LL * (v12 + 1); v13; i += 8LL )
{
ft_dprintf(a1[3], "%s\n", v13);
v4 = *(_QWORD *)a1;
v13 = *(const char **)(*(_QWORD *)a1 + i);
}
return v4;
}

original_code:
void ft_env(t_process *p, t_gen *env)
{
 int i;
 int use_env;
 use_env = 0;
 i = 1;
 if (p->av[i] && ft_strcmp(p->av[i], "-i") == 0)
  use_env = i++;
 while (p->av[i] && ft_s(p->av[i], '=') != -1)
  i++;
 if (p->av[i] == ((void *)0))
 {
  if (use_env == 0)
  {
   i = -1;
   while (env && env->env && env->env[++i] != ((void *)0))
    ft_dprintf(p->fd[1], "%s\n", env->env[i]);
   i = 1;
  }
  else
   i = 2;
  while (p->av[i])
   ft_dprintf(p->fd[1], "%s\n", p->av[i++]);
 }
 else
  ft_launch(p->av, env, i, use_env);
}

canonical_original_code:
void ft_env(struct s_process *p, struct s_gen *env)
{
 int i;
 int use_env;
 use_env = 0;
 i = 1;
 if (p->av[i] && ft_strcmp(p->av[i], "-i") == 0)
  use_env = i++;
 while (p->av[i] && ft_s(p->av[i], '=') != -1)
  i++;
 if (p->av[i] == ((void *)0))
 {
  if (use_env == 0)
  {
   i = -1;
   while (env && env->env && env->env[++i] != ((void *)0))
    ft_dprintf(p->fd[1], "%s\n", env->env[i]);
   i = 1;
  }
  else
   i = 2;
  while (p->av[i])
   ft_dprintf(p->fd[1], "%s\n", p->av[i++]);
 }
 else
  ft_launch(p->av, env, i, use_env);
}

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

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

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

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

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


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

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

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

if ( a1 > 0xF )
{
v3 = a1;
v4 = a1 & 0xF;
v5 = a1 >> 4;
v6 = v3 & 0xF;
if ( v4 <= 9 )
{
v8 = func3(v5);
result = v8 + (unsigned int)func1(v6 + 48);
}
else
{
v7 = func3(v5);
result = v7 + (unsigned int)func1(v6 + 87);
}
}
else
{
v1 = func2(&unk_1BE);
if ( a1 > 9 )
result = v1 + (unsigned int)func1((unsigned __int8)a1 + 87);
else
result = v1 + (unsigned int)func1((unsigned __int8)a1 + 48);
}
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'));
 }
}

variable_types:
n
unsigned long

return_type: int


decompiled_code:
__int64 __fastcall ft_putchar(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(1, buf, 1uLL);
return 1LL;
}

original_code:
int ft_putchar(char c)
{
 write(1, &c, 1);
 return (1);
}

variable_types: c char


decompiled_code:
__int64 __fastcall ft_putstr(void *buf)
{
unsigned int v1; // ebx

v1 = ft_strlen(buf);
write(1, buf, (int)v1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *buf)
{
unsigned int v1; // ebx

v1 = func0(buf);
write(1, buf, (int)v1);
return v1;
}

original_code:
int ft_putstr(char const *s)
{
 int i;
 i = ft_strlen(s);
 write(1, s, i);
 return (i);
}

canonical_original_code:
int ft_putstr(char *s)
{
 int i;
 i = ft_strlen(s);
 write(1, s, i);
 return (i);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall ft_putnbr(int a1)
{
int v1; // ebx
int v2; // ebp
int v3; // er12

v1 = a1;
if ( a1 >= 0 )
{
v2 = 0;
}
else
{
v1 = -a1;
v2 = ft_putchar(45);
}
if ( v1 <= 9 )
return v2 + (unsigned int)ft_putchar((unsigned __int8)v1 + 48);
v3 = ft_putnbr(v1 / 0xAu);
return v2 + v3 + (unsigned int)ft_putchar((unsigned __int8)(v1 % 0xAu) + 48);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v1; // ebx
int v2; // ebp
int v3; // er12

v1 = a1;
if ( a1 >= 0 )
{
v2 = 0;
}
else
{
v1 = -a1;
v2 = func1(45);
}
if ( v1 <= 9 )
return v2 + (unsigned int)func1((unsigned __int8)v1 + 48);
v3 = func4(v1 / 0xAu);
return v2 + v3 + (unsigned int)func1((unsigned __int8)(v1 % 0xAu) + 48);
}

variable_types: n int


decompiled_code:
void __fastcall ft_sh1_relance(_QWORD *a1, __int64 a2, __int64 a3)
{
void *v4; // rbp

if ( !(unsigned int)ft_strcmp(a1[1], "exit") )
exit(0);
v4 = (void *)ft_strsplit(a1[1], 32LL);
if ( !(unsigned int)ft_strcmp(*a1, "cd") )
{
sh_cd(v4, a3);
LABEL_5:
free(v4);
return;
}
if ( (unsigned int)ft_strcmp(*a1, "setenv") )
{
if ( (unsigned int)ft_strcmp(*a1, "unsetenv") )
sh_execute(*a1, v4, a3);
else
ft_unsetenv(v4, a3);
goto LABEL_5;
}
ft_setenv(v4, a3);
free(v4);
}

canonical_decompiled_code:
void __fastcall func0(_QWORD *a1, __int64 a2, __int64 a3)
{
void *v4; // rbp

if ( !(unsigned int)ft_strcmp(a1[1], "exit") )
exit(0);
v4 = (void *)ft_strsplit(a1[1], 32LL);
if ( !(unsigned int)ft_strcmp(*a1, "cd") )
{
sh_cd(v4, a3);
LABEL_5:
free(v4);
return;
}
if ( (unsigned int)ft_strcmp(*a1, "setenv") )
{
if ( (unsigned int)ft_strcmp(*a1, "unsetenv") )
sh_execute(*a1, v4, a3);
else
ft_unsetenv(v4, a3);
goto LABEL_5;
}
ft_setenv(v4, a3);
free(v4);
}

original_code:
void ft_sh1_relance(t_cmd *cmd, char **av, t_env *env)
{
 if (!ft_strcmp(cmd->value, "exit"))
  exit (0);
 av = ft_strsplit(cmd->value, ' ');
 if (!ft_strcmp(cmd->name, "cd"))
  sh_cd(av, env);
 else if (!ft_strcmp(cmd->name, "setenv"))
  ft_setenv(av, env);
 else if (!ft_strcmp(cmd->name, "unsetenv"))
  ft_unsetenv(av, env);
 else
  sh_execute(cmd->name, av, env);
 free(av);
}

canonical_original_code:
void ft_sh1_relance(struct s_cmd *cmd, char **av, struct s_env *env)
{
 if (!ft_strcmp(cmd->value, "exit"))
  exit (0);
 av = ft_strsplit(cmd->value, ' ');
 if (!ft_strcmp(cmd->name, "cd"))
  sh_cd(av, env);
 else if (!ft_strcmp(cmd->name, "setenv"))
  ft_setenv(av, env);
 else if (!ft_strcmp(cmd->name, "unsetenv"))
  ft_unsetenv(av, env);
 else
  sh_execute(cmd->name, av, env);
 free(av);
}

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

variable_types:
av
char **

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


decompiled_code:
void __fastcall ft_sh2_relance2(__int64 a1, __int64 a2, __int64 a3, int a4)
{
int v5; // eax

if ( a4 == 1 )
{
save_in_1 = dup(0);
save_out_0 = dup(1);
}
while ( a3 )
{
v5 = *(_DWORD *)(a3 + 24);
switch ( v5 )
{
case 1:
ft_sh1_relance((_QWORD *)a3, a1, a2);
goto LABEL_8;
case 2:
goto LABEL_12;
case 3:
goto LABEL_13;
}
if ( v5 != 4 )
{
if ( v5 != 5 )
{
if ( v5 != 6 )
goto LABEL_8;
LABEL_12:
outputs_file(*(_QWORD *)(a3 + 16), a1, a2, a3);
goto LABEL_8;
}
LABEL_13:
inputs_file(*(_QWORD *)(a3 + 16), a1, a2, a3);
goto LABEL_8;
}
ft_pipe(a3, a1, a2);
LABEL_8:
dup2(save_out_0, 1);
dup2(save_in_1, 0);
a3 = *(_QWORD *)(a3 + 32);
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, __int64 a3, int a4)
{
int v5; // eax

if ( a4 == 1 )
{
save_in_1 = dup(0);
save_out_0 = dup(1);
}
while ( a3 )
{
v5 = *(_DWORD *)(a3 + 24);
switch ( v5 )
{
case 1:
func0((_QWORD *)a3, a1, a2);
goto LABEL_8;
case 2:
goto LABEL_12;
case 3:
goto LABEL_13;
}
if ( v5 != 4 )
{
if ( v5 != 5 )
{
if ( v5 != 6 )
goto LABEL_8;
LABEL_12:
outputs_file(*(_QWORD *)(a3 + 16), a1, a2, a3);
goto LABEL_8;
}
LABEL_13:
inputs_file(*(_QWORD *)(a3 + 16), a1, a2, a3);
goto LABEL_8;
}
ft_pipe(a3, a1, a2);
LABEL_8:
dup2(save_out_0, 1);
dup2(save_in_1, 0);
a3 = *(_QWORD *)(a3 + 32);
}
}

original_code:
void ft_sh2_relance2(char **av, t_env *env, t_cmd *cmd, int i)
{
 static int save_out;
 static int save_in;
 if (i == 1)
 {
  save_in = dup(0);
  save_out = dup(1);
 }
 while (cmd)
 {
  if (cmd->sfd == 1)
   ft_sh1_relance(cmd, av, env);
  else if (cmd->sfd == 2)
   outputs_file(cmd->file, av, env, cmd);
  else if (cmd->sfd == 3)
   inputs_file(cmd->file, av, env, cmd);
  else if (cmd->sfd == 4)
   ft_pipe(cmd, av, env);
  else if (cmd->sfd == 5)
   inputs_file(cmd->file, av, env, cmd);
  else if (cmd->sfd == 6)
   outputs_file(cmd->file, av, env, cmd);
  dup2(save_out, 1);
  dup2(save_in, 0);
  cmd = cmd->next;
 }
}

canonical_original_code:
void ft_sh2_relance2(char **av, struct s_env *env, struct s_cmd *cmd, int i)
{
 static int save_out;
 static int save_in;
 if (i == 1)
 {
  save_in = dup(0);
  save_out = dup(1);
 }
 while (cmd)
 {
  if (cmd->sfd == 1)
   ft_sh1_relance(cmd, av, env);
  else if (cmd->sfd == 2)
   outputs_file(cmd->file, av, env, cmd);
  else if (cmd->sfd == 3)
   inputs_file(cmd->file, av, env, cmd);
  else if (cmd->sfd == 4)
   ft_pipe(cmd, av, env);
  else if (cmd->sfd == 5)
   inputs_file(cmd->file, av, env, cmd);
  else if (cmd->sfd == 6)
   outputs_file(cmd->file, av, env, cmd);
  dup2(save_out, 1);
  dup2(save_in, 0);
  cmd = cmd->next;
 }
}

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

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


decompiled_code:
__int64 __fastcall ft_init_prompte(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax
__int64 v5; // rbp

v4 = sh_wait_new_commande(a2, 0LL);
v5 = v4;
if ( v4 && **(_BYTE **)(v4 + 8) )
ft_sh2_relance2(a1, a2, v4, a3);
return ft_free_cmd(v5);
}

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

v4 = sh_wait_new_commande(a2, 0LL);
v5 = v4;
if ( v4 && **(_BYTE **)(v4 + 8) )
func1(a1, a2, v4, a3);
return ft_free_cmd(v5);
}

original_code:
void ft_init_prompte(char **av, t_env *env, int i)
{
 t_cmd *cmd;
 cmd = ((void *)0);
 if ((cmd = sh_wait_new_commande(env, cmd)) != ((void *)0))
 {
  if (cmd->value[0] != '\0')
   ft_sh2_relance2(av, env, cmd, i);
 }
 ft_free_cmd(cmd);
}

canonical_original_code:
void ft_init_prompte(char **av, struct s_env *env, int i)
{
 struct s_cmd *cmd;
 cmd = ((void *)0);
 if ((cmd = sh_wait_new_commande(env, cmd)) != ((void *)0))
 {
  if (cmd->value[0] != '\0')
   ft_sh2_relance2(av, env, cmd, i);
 }
 ft_free_cmd(cmd);
}


start

decompiled_code:
void __noreturn start()
{
__int64 v0; // rbp
__int64 i; // rbx

v0 = recup_term();
ft_init_signal();
for ( i = return_env(); ; ft_init_prompte(0LL, i, 1) )
clean_hist(*(_QWORD *)(v0 + 152));
}

canonical_decompiled_code:
void __noreturn func3()
{
__int64 v0; // rbp
__int64 i; // rbx

v0 = recup_term();
ft_init_signal();
for ( i = return_env(); ; func2(0LL, i, 1) )
clean_hist(*(_QWORD *)(v0 + 152));
}

original_code:
void start(void)
{
 char **av;
 t_env *env;
 t_term *term;
 term = recup_term();
 ft_init_signal();
 env = return_env();
 while (1)
 {
  clean_hist(term->hist);
  ft_init_prompte(av, env, 1);
 }
}

canonical_original_code:
void start()
{
 char **av;
 struct s_env *env;
 struct s_term *term;
 term = recup_term();
 ft_init_signal();
 env = return_env();
 while (1)
 {
  clean_hist(term->hist);
  ft_init_prompte(av, env, 1);
 }
}

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

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


decompiled_code:
__int64 __fastcall process_lst_print(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
ft_putstr("process : ");
if ( a1 )
{
do
{
ft_putstr(" [");
ft_putstr(**(_QWORD **)v1);
ft_putstr(" IN : ");
ft_putnbr(*(unsigned int *)(v1 + 8));
ft_putstr(" OUT : ");
ft_putnbr(*(unsigned int *)(v1 + 12));
ft_putstr(" ERR : ");
ft_putnbr(*(unsigned int *)(v1 + 16));
ft_putstr("] ");
if ( !*(_QWORD *)(v1 + 24) )
break;
ft_putstr("->");
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
return ft_putchar(10LL);
}

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

v1 = a1;
ft_putstr("process : ");
if ( a1 )
{
do
{
ft_putstr(" [");
ft_putstr(**(_QWORD **)v1);
ft_putstr(" IN : ");
ft_putnbr(*(unsigned int *)(v1 + 8));
ft_putstr(" OUT : ");
ft_putnbr(*(unsigned int *)(v1 + 12));
ft_putstr(" ERR : ");
ft_putnbr(*(unsigned int *)(v1 + 16));
ft_putstr("] ");
if ( !*(_QWORD *)(v1 + 24) )
break;
ft_putstr("->");
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
return ft_putchar(10LL);
}

original_code:
void process_lst_print(t_process *process)
{
 ft_putstr("process : ");
 while (process)
 {
  ft_putstr(" [");
  ft_putstr(process->av[0]);
  ft_putstr(" IN : ");
  ft_putnbr(process->fd[0]);
  ft_putstr(" OUT : ");
  ft_putnbr(process->fd[1]);
  ft_putstr(" ERR : ");
  ft_putnbr(process->fd[2]);
  ft_putstr("] ");
  if (process->next)
   ft_putstr("->");
  process = process->next;
 }
 ft_putchar('\n');
}

canonical_original_code:
void process_lst_print(struct s_process *process)
{
 ft_putstr("process : ");
 while (process)
 {
  ft_putstr(" [");
  ft_putstr(process->av[0]);
  ft_putstr(" IN : ");
  ft_putnbr(process->fd[0]);
  ft_putstr(" OUT : ");
  ft_putnbr(process->fd[1]);
  ft_putstr(" ERR : ");
  ft_putnbr(process->fd[2]);
  ft_putstr("] ");
  if (process->next)
   ft_putstr("->");
  process = process->next;
 }
 ft_putchar('\n');
}

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


decompiled_code:
int __fastcall launch_process(char *const *__attribute__((__org_arrdim(0,0))) *status, __int64 a2)
{
const char *v2; // rax
const char *v3; // rdx

check_redirection();
v2 = (const char *)check_and_get_path(**status, a2);
*(_QWORD *)(a2 + 56) = v2;
if ( !v2 )
{
error((int)status, 0, v3);
exit(-1);
}
return execve(v2, *status, *(char *const **)a2);
}

canonical_decompiled_code:
int __fastcall func0(char *const *__attribute__((__org_arrdim(0,0))) *status, __int64 a2)
{
const char *v2; // rax
const char *v3; // rdx

check_redirection();
v2 = (const char *)check_and_get_path(**status, a2);
*(_QWORD *)(a2 + 56) = v2;
if ( !v2 )
{
error((int)status, 0, v3);
exit(-1);
}
return execve(v2, *status, *(char *const **)a2);
}

original_code:
void launch_process(t_process *p, t_gen *envp)
{
 check_redirection(p, envp);
 if ((envp->path = check_and_get_path(p->av[0], envp)) != ((void *)0))
  execve(envp->path, p->av, envp->env);
 else
 {
  error(p, 0);
  exit(-1);
 }
}

canonical_original_code:
void launch_process(struct s_process *p, struct s_gen *envp)
{
 check_redirection(p, envp);
 if ((envp->path = check_and_get_path(p->av[0], envp)) != ((void *)0))
  execve(envp->path, p->av, envp->env);
 else
 {
  error(p, 0);
  exit(-1);
 }
}


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

result = *(_QWORD *)(a1 + 32);
v3 = *(_DWORD *)(result + 4096);
if ( a2 )
{
v4 = a2;
do
{
tc_move_right(a1, 1LL, 0LL);
result = *(_QWORD *)(a1 + 32);
++*(_DWORD *)(result + 4096);
--v4;
}
while ( v4 );
}
*(_DWORD *)(result + 4096) = v3;
return result;
}

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

result = *(_QWORD *)(a1 + 32);
v3 = *(_DWORD *)(result + 4096);
if ( a2 )
{
v4 = a2;
do
{
tc_move_right(a1, 1LL, 0LL);
result = *(_QWORD *)(a1 + 32);
++*(_DWORD *)(result + 4096);
--v4;
}
while ( v4 );
}
*(_DWORD *)(result + 4096) = v3;
return result;
}

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

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

variable_types: tmp int


original_code:
void tc_del_char(t_gen *gen, int i)
{
 int tmp;
 tmp = gen->hist->pose_buff;
 while (i--)
 {
  gen->hist->pose_buff--;
  gen_tc_move_left(gen, 1);
  ft_putstr_fd(tgetstr("dc", ((void *)0)), gen->term->fd);
 }
 gen->hist->pose_buff = tmp;
}

canonical_original_code:
void tc_del_char(struct s_gen *gen, int i)
{
 int tmp;
 tmp = gen->hist->pose_buff;
 while (i--)
 {
  gen->hist->pose_buff--;
  gen_tc_move_left(gen, 1);
  ft_putstr_fd(tgetstr("dc", ((void *)0)), gen->term->fd);
 }
 gen->hist->pose_buff = tmp;
}


decompiled_code:
__int64 __fastcall go_end(__int64 a1)
{
__int64 result; // rax
int v2; // edx
int v3; // esi

result = *(_QWORD *)(a1 + 32);
v2 = *(_DWORD *)(result + 4096);
v3 = *(_DWORD *)(result + 4100);
if ( v2 != v3 )
{
gen_tc_move_right(a1, v3 - v2);
result = *(_QWORD *)(a1 + 32);
*(_DWORD *)(result + 4096) = *(_DWORD *)(result + 4100);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
int v2; // edx
int v3; // esi

result = *(_QWORD *)(a1 + 32);
v2 = *(_DWORD *)(result + 4096);
v3 = *(_DWORD *)(result + 4100);
if ( v2 != v3 )
{
func0(a1, v3 - v2);
result = *(_QWORD *)(a1 + 32);
*(_DWORD *)(result + 4096) = *(_DWORD *)(result + 4100);
}
return result;
}

original_code:
void go_end(t_gen *gen, char *key)
{
 if (gen->hist->pose_buff != gen->hist->len)
 {
  (void)key;
  gen_tc_move_right(gen, gen->hist->len - gen->hist->pose_buff);
  gen->hist->pose_buff = gen->hist->len;
 }
}

canonical_original_code:
void go_end(struct s_gen *gen, char *key)
{
 if (gen->hist->pose_buff != gen->hist->len)
 {
  (void)key;
  gen_tc_move_right(gen, gen->hist->len - gen->hist->pose_buff);
  gen->hist->pose_buff = gen->hist->len;
 }
}

variable_types:
key
char *


original_code:
void tc_clean_line(t_gen *gen)
{
 int tmp;
 tmp = gen->hist->pose_buff;
 go_end(gen, ((void *)0));
 gen->hist->pose_buff = gen->hist->len;
 while (gen->hist->pose_buff--)
 {
  if (ft_isnl(gen, gen->hist->pose_buff))
   ft_putstr_fd(tgetstr("ku", ((void *)0)), gen->term->fd);
  ft_putstr_fd(tgetstr("dl", ((void *)0)), gen->term->fd);
 }
 gen->hist->pose_buff = tmp;
 tmp = tgetnum("co");
 while (tmp--)
  ft_putstr_fd(tgetstr("kl", ((void *)0)), gen->term->fd);
 ft_putstr(gen->ps1->aff);
}

canonical_original_code:
void tc_clean_line(struct s_gen *gen)
{
 int tmp;
 tmp = gen->hist->pose_buff;
 go_end(gen, ((void *)0));
 gen->hist->pose_buff = gen->hist->len;
 while (gen->hist->pose_buff--)
 {
  if (ft_isnl(gen, gen->hist->pose_buff))
   ft_putstr_fd(tgetstr("ku", ((void *)0)), gen->term->fd);
  ft_putstr_fd(tgetstr("dl", ((void *)0)), gen->term->fd);
 }
 gen->hist->pose_buff = tmp;
 tmp = tgetnum("co");
 while (tmp--)
  ft_putstr_fd(tgetstr("kl", ((void *)0)), gen->term->fd);
 ft_putstr(gen->ps1->aff);
}


decompiled_code:
__int64 __fastcall go_start(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rsi

result = *(_QWORD *)(a1 + 32);
v2 = *(unsigned int *)(result + 4096);
if ( (int)v2 > 0 )
{
gen_tc_move_left(a1, v2);
result = *(_QWORD *)(a1 + 32);
*(_DWORD *)(result + 4096) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rsi

result = *(_QWORD *)(a1 + 32);
v2 = *(unsigned int *)(result + 4096);
if ( (int)v2 > 0 )
{
gen_tc_move_left(a1, v2);
result = *(_QWORD *)(a1 + 32);
*(_DWORD *)(result + 4096) = 0;
}
return result;
}

original_code:
void go_start(t_gen *gen, char *key)
{
 if (gen->hist->pose_buff > 0)
 {
  (void)key;
  gen_tc_move_left(gen, gen->hist->pose_buff);
  gen->hist->pose_buff = 0;
 }
}

canonical_original_code:
void go_start(struct s_gen *gen, char *key)
{
 if (gen->hist->pose_buff > 0)
 {
  (void)key;
  gen_tc_move_left(gen, gen->hist->pose_buff);
  gen->hist->pose_buff = 0;
 }
}


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

while ( !*(_DWORD *)(a1 + 12) )
a1 = *(_QWORD *)(a1 + 16);
result = *(_QWORD *)(a1 + 16);
*(_DWORD *)(a1 + 12) = 0;
if ( !result )
{
do
{
result = a1;
v2 = *(_QWORD *)(a1 + 24);
if ( !v2 )
break;
result = v2;
a1 = *(_QWORD *)(v2 + 24);
}
while ( a1 );
}
*(_DWORD *)(result + 12) = 1;
return result;
}

original_code:
void ft_pntnext(t_lstsel *lst)
{
 while (lst->pnt == 0)
  lst = lst->next;
 lst->pnt = 0;
 if (lst->next)
  lst->next->pnt = 1;
 else
 {
  while (lst->prev)
   lst = lst->prev;
  lst->pnt = 1;
 }
}

canonical_original_code:
void ft_pntnext(struct s_lstsel *lst)
{
 while (lst->pnt == 0)
  lst = lst->next;
 lst->pnt = 0;
 if (lst->next)
  lst->next->pnt = 1;
 else
 {
  while (lst->prev)
   lst = lst->prev;
  lst->pnt = 1;
 }
}

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


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

while ( !*(_DWORD *)(a1 + 12) )
a1 = *(_QWORD *)(a1 + 16);
result = *(_QWORD *)(a1 + 24);
*(_DWORD *)(a1 + 12) = 0;
if ( !result )
{
do
{
result = a1;
v2 = *(_QWORD *)(a1 + 16);
if ( !v2 )
break;
result = v2;
a1 = *(_QWORD *)(v2 + 16);
}
while ( a1 );
}
*(_DWORD *)(result + 12) = 1;
return result;
}

original_code:
void ft_pntprev(t_lstsel *lst)
{
 while (lst->pnt == 0)
  lst = lst->next;
 lst->pnt = 0;
 if (lst->prev)
  lst->prev->pnt = 1;
 else
 {
  while (lst->next)
   lst = lst->next;
  lst->pnt = 1;
 }
}

canonical_original_code:
void ft_pntprev(struct s_lstsel *lst)
{
 while (lst->pnt == 0)
  lst = lst->next;
 lst->pnt = 0;
 if (lst->prev)
  lst->prev->pnt = 1;
 else
 {
  while (lst->next)
   lst = lst->next;
  lst->pnt = 1;
 }
}

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_read(__int64 a1)
{
__int64 v1; // r13
char *v2; // rbp
char i; // al

v1 = *(_QWORD *)(a1 + 136);
v2 = (char *)ft_memalloc(4LL);
for ( i = *v2; !*v2; i = *v2 )
read(0, v2, 4uLL);
switch ( i )
{
case 27:
if ( v2[1] == 91 )
ft_mvflech((unsigned int)v2[2], v1);
break;
case 32:
ft_selectopt(v1);
break;
case 10:
return 0LL;
case 127:
v1 = ft_delet(v1);
break;
}
if ( *v2 == 27 && !v2[1] )
{
ft_close(a1);
exit(0);
}
free(v2);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // r13
char *v2; // rbp
char i; // al

v1 = *(_QWORD *)(a1 + 136);
v2 = (char *)ft_memalloc(4LL);
for ( i = *v2; !*v2; i = *v2 )
read(0, v2, 4uLL);
switch ( i )
{
case 27:
if ( v2[1] == 91 )
ft_mvflech((unsigned int)v2[2], v1);
break;
case 32:
ft_selectopt(v1);
break;
case 10:
return 0LL;
case 127:
v1 = ft_delet(v1);
break;
}
if ( *v2 == 27 && !v2[1] )
{
ft_close(a1);
exit(0);
}
free(v2);
return v1;
}

original_code:
t_lstsel *ft_read(t_sig *sig)
{
 t_lstsel *tmp;
 char *readc;
 tmp = sig->lst;
 readc = ft_memalloc(4);
 while (readc[0] == 0)
  read(0, readc, 4);
 if (readc[0] == 27 && readc[1] == '[')
  ft_mvflech(readc[2], tmp);
 else if (readc[0] == ' ')
  ft_selectopt(tmp);
 else if (readc[0] == '\n')
  return (0);
 else if (readc[0] == 127)
  tmp = ft_delet(tmp);
 if (readc[0] == 27 && readc[1] == '\0')
 {
  ft_close(sig);
  exit(0);
 }
 free (readc);
 return (tmp);
}

canonical_original_code:
struct s_lstsel *ft_read(struct s_sig *sig)
{
 struct s_lstsel *tmp;
 char *readc;
 tmp = sig->lst;
 readc = ft_memalloc(4);
 while (readc[0] == 0)
  read(0, readc, 4);
 if (readc[0] == 27 && readc[1] == '[')
  ft_mvflech(readc[2], tmp);
 else if (readc[0] == ' ')
  ft_selectopt(tmp);
 else if (readc[0] == '\n')
  return (0);
 else if (readc[0] == 127)
  tmp = ft_delet(tmp);
 if (readc[0] == 27 && readc[1] == '\0')
 {
  ft_close(sig);
  exit(0);
 }
 free (readc);
 return (tmp);
}

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

variable_types:
readc
char *

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4; // r12

if ( argc > 1 )
{
v4 = ft_init_sig(argc, argv, envp);
ft_init_signal();
*(_QWORD *)(v4 + 136) = ft_inilst((__int64)argv, *(_DWORD **)(v4 + 136));
ft_start(v4);
}
return 0;
}

original_code:
int main(int ac, char **av)
{
 t_sig *sig;
 if (ac > 1)
 {
  sig = ft_init_sig();
  ft_init_signal();
  sig->lst = ft_inilst(av, sig->lst);
  ft_start(sig);
 }
 return (0);
}

canonical_original_code:
int main(int ac, char **av)
{
 struct s_sig *sig;
 if (ac > 1)
 {
  sig = ft_init_sig();
  ft_init_signal();
  sig->lst = ft_inilst(av, sig->lst);
  ft_start(sig);
 }
 return (0);
}

variable_types: ac int

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:
void __fastcall command_lst_free(void *ptr)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
job_lst_free(v2[1]);
v2[1] = 0LL;
token_lst_free(v2);
free(v2);
}
while ( v1 );
}
}

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

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (_QWORD *)v1[3];
job_lst_free(v2[1]);
v2[1] = 0LL;
token_lst_free(v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void command_lst_free(t_command *command_lst)
{
 t_command *curr;
 t_command *to_free;
 curr = command_lst;
 while (curr)
 {
  to_free = curr;
  curr = curr->next;
  job_lst_free(to_free->first_job);
  to_free->first_job = ((void *)0);
  token_lst_free(&(to_free->token_lst));
  to_free->background = 0;
  to_free->next = ((void *)0);
  to_free->prev = ((void *)0);
  free(to_free);
  to_free = ((void *)0);
 }
 command_lst = ((void *)0);
}

canonical_original_code:
void command_lst_free(struct s_command *command_lst)
{
 struct s_command *curr;
 struct s_command *to_free;
 curr = command_lst;
 while (curr)
 {
  to_free = curr;
  curr = curr->next;
  job_lst_free(to_free->first_job);
  to_free->first_job = ((void *)0);
  token_lst_free(&(to_free->token_lst));
  to_free->background = 0;
  to_free->next = ((void *)0);
  to_free->prev = ((void *)0);
  free(to_free);
  to_free = ((void *)0);
 }
 command_lst = ((void *)0);
}

variable_types: struct s_command { 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; struct s_job { struct s_token *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; } *first_job; char background; struct s_command *next; struct s_command *prev; } *

user_defined_types: struct s_command { struct s_token *token_lst; struct s_job *first_job; char background; struct s_command *next; struct s_command *prev; }

user_defined_types: struct s_token { enum e_sym type; char *str; struct s_token *next; struct s_token *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; }


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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

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

do
{
result = a1;
a1 = *(_QWORD *)(a1 + 24);
}
while ( a1 );
return result;
}

original_code:
static t_process *get_last_process(t_process *process_lst)
{
 t_process *lst;
 lst = process_lst;
 while (lst->next != ((void *)0))
  lst = lst->next;
 return (lst);
}

canonical_original_code:
static struct s_process *get_last_process(struct s_process *process_lst)
{
 struct s_process *lst;
 lst = process_lst;
 while (lst->next != ((void *)0))
  lst = lst->next;
 return (lst);
}

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


decompiled_code:
bool __fastcall is_ok_redir(__int64 a1)
{
bool result; // al
_DWORD *v2; // rdx

result = 0;
if ( *(_DWORD *)a1 <= 3u )
{
v2 = *(_DWORD **)(a1 + 16);
if ( v2 )
result = *v2 == 10;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
bool result; // al
_DWORD *v2; // rdx

result = 0;
if ( *(_DWORD *)a1 <= 3u )
{
v2 = *(_DWORD **)(a1 + 16);
if ( v2 )
result = *v2 == 10;
}
return result;
}

original_code:
static char is_ok_redir(t_token *token)
{
 if (token->type == redir_in || token->type == redir_out
   || token->type == append || token->type == redir_err)
 {
  if (token->next && token->next->type == redir_dest)
  {
   return (1);
  }
 }
 return (0);
}

canonical_original_code:
static char is_ok_redir(struct s_token *token)
{
 if (token->type == redir_in || token->type == redir_out
   || token->type == append || token->type == redir_err)
 {
  if (token->next && token->next->type == redir_dest)
  {
   return (1);
  }
 }
 return (0);
}

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

return_type: char


original_code:
static void do_redir(t_token **token, t_process **current,
       t_process **process)
{
 char state;
 state = check_state(*token);
 if (state == 3 || state == 4)
  *process = process_lst_add(*process, (*token)->next->next->str);
 else if (state == 5)
  *process = process_lst_add(*process,
    (*token)->next->next->next->next->str);
 else if (state == 6 || state == 7)
  *process = process_lst_add(*process, "cat");
 *current = get_last_process(*process);
 *current = update_fd(*token, current);
 if (state == 2 || state == 6 || state == 5 || state == 3)
  *token = (*token)->next->next;
 else if (state == 4)
  *token = (*token)->next->next->next;
 if (state == 2 || state == 6 || state == 5 || state == 4)
  *current = update_fd(*token, current);
 if (state == 5)
  *token = (*token)->next;
 *token = ((*token)->next) ? (*token)->next->next : (*token)->next;
}

canonical_original_code:
static void do_redir(struct s_token **token, struct s_process **current, struct s_process **process)
{
 char state;
 state = check_state(*token);
 if (state == 3 || state == 4)
  *process = process_lst_add(*process, (*token)->next->next->str);
 else if (state == 5)
  *process = process_lst_add(*process,
    (*token)->next->next->next->next->str);
 else if (state == 6 || state == 7)
  *process = process_lst_add(*process, "cat");
 *current = get_last_process(*process);
 *current = update_fd(*token, current);
 if (state == 2 || state == 6 || state == 5 || state == 3)
  *token = (*token)->next->next;
 else if (state == 4)
  *token = (*token)->next->next->next;
 if (state == 2 || state == 6 || state == 5 || state == 4)
  *current = update_fd(*token, current);
 if (state == 5)
  *token = (*token)->next;
 *token = ((*token)->next) ? (*token)->next->next : (*token)->next;
}

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

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

variable_types:
process
struct s_process **

variable_types: state char


original_code:
t_process *make_process_lst(t_token *token)
{
 t_process *process;
 t_process *current;
 process = ((void *)0);
 current = ((void *)0);
 while (token)
 {
  if (token->type == word)
  {
   process = process_lst_add(process, token->str);
   token = token->next;
  }
  else if (is_ok_redir(token))
   do_redir(&token, &current, &process);
  else if (token->type == pipes)
   token = token->next;
 }
 return (process);
}

canonical_original_code:
struct s_process *make_process_lst(struct s_token *token)
{
 struct s_process *process;
 struct s_process *current;
 process = ((void *)0);
 current = ((void *)0);
 while (token)
 {
  if (token->type == word)
  {
   process = process_lst_add(process, token->str);
   token = token->next;
  }
  else if (is_ok_redir(token))
   do_redir(&token, &current, &process);
  else if (token->type == pipes)
   token = token->next;
 }
 return (process);
}

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

user_defined_types: 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 }


decompiled_code:
void __fastcall ft_forkerror(int a1, __int64 a2, const char *a3)
{
*(_DWORD *)(a2 + 48) = 8;
error(a1, 0, a3);
}

canonical_decompiled_code:
void __fastcall func0(int a1, __int64 a2, const char *a3)
{
*(_DWORD *)(a2 + 48) = 8;
error(a1, 0, a3);
}

original_code:
void ft_forkerror(t_process *p, t_gen *env)
{
 env->ret = 8;
 error(p, 0);
}

canonical_original_code:
void ft_forkerror(struct s_process *p, struct s_gen *env)
{
 env->ret = 8;
 error(p, 0);
}

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


decompiled_code:
void __fastcall ft_fork(__int64 status, __int64 a2)
{
int v2; // eax
const char *v3; // rdx
const char *v4; // rdx
void *v5; // rdi

if ( (unsigned int)ft_checkbuiltin() == 1 )
{
*(_DWORD *)(a2 + 52) = ft_run_builtin(status, a2);
}
else
{
*(_DWORD *)(a2 + 64) = 0;
v2 = fork();
*(_DWORD *)(a2 + 64) = v2;
if ( !v2 )
{
launch_process(status, a2);
v5 = *(void **)(a2 + 56);
if ( v5 )
goto LABEL_7;
return;
}
if ( v2 < 0 )
{
ft_forkerror(status, a2, v3);
exit(1);
}
if ( waitpid(v2, (int *)(a2 + 52), 0) == -1 )
{
*(_DWORD *)(a2 + 48) = 15;
error(status, 0, v4);
}
}
v5 = *(void **)(a2 + 56);
if ( v5 )
LABEL_7:
free(v5);
}

canonical_decompiled_code:
void __fastcall func1(__int64 status, __int64 a2)
{
int v2; // eax
const char *v3; // rdx
const char *v4; // rdx
void *v5; // rdi

if ( (unsigned int)ft_checkbuiltin() == 1 )
{
*(_DWORD *)(a2 + 52) = ft_run_builtin(status, a2);
}
else
{
*(_DWORD *)(a2 + 64) = 0;
v2 = fork();
*(_DWORD *)(a2 + 64) = v2;
if ( !v2 )
{
launch_process(status, a2);
v5 = *(void **)(a2 + 56);
if ( v5 )
goto LABEL_7;
return;
}
if ( v2 < 0 )
{
func0(status, a2, v3);
exit(1);
}
if ( waitpid(v2, (int *)(a2 + 52), 0) == -1 )
{
*(_DWORD *)(a2 + 48) = 15;
error(status, 0, v4);
}
}
v5 = *(void **)(a2 + 56);
if ( v5 )
LABEL_7:
free(v5);
}

original_code:
void ft_fork(t_process *p, t_gen *env)
{
 if (ft_checkbuiltin(p, env) == 1)
  env->status = ft_run_builtin(p, env);
 else
 {
  env->pid_fork = 0;
  env->pid_fork = fork();
  if (env->pid_fork == 0)
   launch_process(p, env);
  else if (env->pid_fork < 0)
  {
   ft_forkerror(p, env);
   exit(1);
  }
  else
  {
   if ((waitpid(env->pid_fork, &(env->status), 0)) == -1)
   {
    env->ret = 15;
    error(p, 0);
   }
  }
 }
 if (env->path != ((void *)0))
  free(env->path);
}

canonical_original_code:
void ft_fork(struct s_process *p, struct s_gen *env)
{
 if (ft_checkbuiltin(p, env) == 1)
  env->status = ft_run_builtin(p, env);
 else
 {
  env->pid_fork = 0;
  env->pid_fork = fork();
  if (env->pid_fork == 0)
   launch_process(p, env);
  else if (env->pid_fork < 0)
  {
   ft_forkerror(p, env);
   exit(1);
  }
  else
  {
   if ((waitpid(env->pid_fork, &(env->status), 0)) == -1)
   {
    env->ret = 15;
    error(p, 0);
   }
  }
 }
 if (env->path != ((void *)0))
  free(env->path);
}


decompiled_code:
_QWORD *init_listbuiltin()
{
_QWORD *v0; // rbp
_QWORD *v1; // rbx
__int64 v2; // rbx
void *v3; // rax
__int64 v4; // rbx
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // rbx
__int64 v10; // rbx
__int64 v11; // rbx
__int64 v12; // rbx
__int64 v13; // rbx
__int64 v14; // rbx
__int64 v15; // rbx
_QWORD *v16; // rbx
__int64 v17; // rbx
void *v18; // rax
__int64 v19; // rbx

v0 = malloc(0x58uLL);
v1 = malloc(0x10uLL);
*v0 = v1;
*v1 = ft_strdup("env");
v2 = *v0;
v3 = malloc(0x1D7uLL);
*(_QWORD *)(v2 + 8) = v3;
*(_QWORD *)(v2 + 8) = ft_strcpy(v3, "USAGE :\nenv [-i] [name=value ...] [u");
v4 = *v0;
*(_QWORD *)(v4 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "tility [argument ...]]\n\nDESCRIPTION");
v5 = *v0;
*(_QWORD *)(v5 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), " :\nenv executes utility after modify");
v6 = *v0;
*(_QWORD *)(v6 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "ing the environment as specified on t");
v7 = *v0;
*(_QWORD *)(v7 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "he command line. The option name=valu");
v8 = *v0;
*(_QWORD *)(v8 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "e specifies an environmental variable");
v9 = *v0;
*(_QWORD *)(v9 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), ", name, with a value of value of valu");
v10 = *v0;
*(_QWORD *)(v10 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "e. The option '-i' causes env to comp");
v11 = *v0;
*(_QWORD *)(v11 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "letly ignore the environment it inher");
v12 = *v0;
*(_QWORD *)(v12 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "its.\nIf no utility is specified, env");
v13 = *v0;
*(_QWORD *)(v13 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), " prints out the names and values of t");
v14 = *v0;
*(_QWORD *)(v14 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "he variables in the environment, with");
v15 = *v0;
*(_QWORD *)(v15 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), " one name=value pair per line.\n");
v16 = malloc(0x10uLL);
v0[1] = v16;
*v16 = ft_strdup("unsetenv");
v17 = v0[1];
v18 = malloc(0xD6uLL);
*(_QWORD *)(v17 + 8) = v18;
*(_QWORD *)(v17 + 8) = ft_strcpy(v18, "USAGE :\nunsetenv name\n\nDESCRIPTION");
v19 = v0[1];
*(_QWORD *)(v19 + 8) = ft_strcat(*(_QWORD *)(v19 + 8), " :\nunsetenv deletes all instances of");
return init_listbuiltin2(v0);
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbp
_QWORD *v1; // rbx
__int64 v2; // rbx
void *v3; // rax
__int64 v4; // rbx
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
__int64 v9; // rbx
__int64 v10; // rbx
__int64 v11; // rbx
__int64 v12; // rbx
__int64 v13; // rbx
__int64 v14; // rbx
__int64 v15; // rbx
_QWORD *v16; // rbx
__int64 v17; // rbx
void *v18; // rax
__int64 v19; // rbx

v0 = malloc(0x58uLL);
v1 = malloc(0x10uLL);
*v0 = v1;
*v1 = ft_strdup("env");
v2 = *v0;
v3 = malloc(0x1D7uLL);
*(_QWORD *)(v2 + 8) = v3;
*(_QWORD *)(v2 + 8) = ft_strcpy(v3, "USAGE :\nenv [-i] [name=value ...] [u");
v4 = *v0;
*(_QWORD *)(v4 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "tility [argument ...]]\n\nDESCRIPTION");
v5 = *v0;
*(_QWORD *)(v5 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), " :\nenv executes utility after modify");
v6 = *v0;
*(_QWORD *)(v6 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "ing the environment as specified on t");
v7 = *v0;
*(_QWORD *)(v7 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "he command line. The option name=valu");
v8 = *v0;
*(_QWORD *)(v8 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "e specifies an environmental variable");
v9 = *v0;
*(_QWORD *)(v9 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), ", name, with a value of value of valu");
v10 = *v0;
*(_QWORD *)(v10 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "e. The option '-i' causes env to comp");
v11 = *v0;
*(_QWORD *)(v11 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "letly ignore the environment it inher");
v12 = *v0;
*(_QWORD *)(v12 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "its.\nIf no utility is specified, env");
v13 = *v0;
*(_QWORD *)(v13 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), " prints out the names and values of t");
v14 = *v0;
*(_QWORD *)(v14 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), "he variables in the environment, with");
v15 = *v0;
*(_QWORD *)(v15 + 8) = ft_strcat(*(_QWORD *)(*v0 + 8LL), " one name=value pair per line.\n");
v16 = malloc(0x10uLL);
v0[1] = v16;
*v16 = ft_strdup("unsetenv");
v17 = v0[1];
v18 = malloc(0xD6uLL);
*(_QWORD *)(v17 + 8) = v18;
*(_QWORD *)(v17 + 8) = ft_strcpy(v18, "USAGE :\nunsetenv name\n\nDESCRIPTION");
v19 = v0[1];
*(_QWORD *)(v19 + 8) = ft_strcat(*(_QWORD *)(v19 + 8), " :\nunsetenv deletes all instances of");
return init_listbuiltin2(v0);
}

original_code:
t_builtin **init_listbuiltin(void)
{
 t_builtin **l;
 l = (t_builtin **)malloc(sizeof(t_builtin *) * 11);
 l[0] = (t_builtin *)malloc(sizeof(t_builtin));
 l[0]->name = ft_strdup("env");
 l[0]->help = (char *)malloc(sizeof(char) * 471);
 l[0]->help = ft_strcpy(l[0]->help, "USAGE :\nenv [-i] [name=value ...] [u");
 l[0]->help = ft_strcat(l[0]->help, "tility [argument ...]]\n\nDESCRIPTION");
 l[0]->help = ft_strcat(l[0]->help, " :\nenv executes utility after modify");
 l[0]->help = ft_strcat(l[0]->help, "ing the environment as specified on t");
 l[0]->help = ft_strcat(l[0]->help, "he command line. The option name=valu");
 l[0]->help = ft_strcat(l[0]->help, "e specifies an environmental variable");
 l[0]->help = ft_strcat(l[0]->help, ", name, with a value of value of valu");
 l[0]->help = ft_strcat(l[0]->help, "e. The option '-i' causes env to comp");
 l[0]->help = ft_strcat(l[0]->help, "letly ignore the environment it inher");
 l[0]->help = ft_strcat(l[0]->help, "its.\nIf no utility is specified, env");
 l[0]->help = ft_strcat(l[0]->help, " prints out the names and values of t");
 l[0]->help = ft_strcat(l[0]->help, "he variables in the environment, with");
 l[0]->help = ft_strcat(l[0]->help, " one name=value pair per line.\n");
 l[1] = (t_builtin *)malloc(sizeof(t_builtin));
 l[1]->name = ft_strdup("unsetenv");
 l[1]->help = (char *)malloc(sizeof(char) * 214);
 l[1]->help = ft_strcpy(l[1]->help, "USAGE :\nunsetenv name\n\nDESCRIPTION");
 l[1]->help = ft_strcat(l[1]->help, " :\nunsetenv deletes all instances of");
 return (init_listbuiltin2(l));
}

canonical_original_code:
struct s_builtin **init_listbuiltin()
{
 struct s_builtin **l;
 l = (struct s_builtin **)malloc(sizeof(struct s_builtin *) * 11);
 l[0] = (struct s_builtin *)malloc(sizeof(t_builtin));
 l[0]->name = ft_strdup("env");
 l[0]->help = (char *)malloc(sizeof(char) * 471);
 l[0]->help = ft_strcpy(l[0]->help, "USAGE :\nenv [-i] [name=value ...] [u");
 l[0]->help = ft_strcat(l[0]->help, "tility [argument ...]]\n\nDESCRIPTION");
 l[0]->help = ft_strcat(l[0]->help, " :\nenv executes utility after modify");
 l[0]->help = ft_strcat(l[0]->help, "ing the environment as specified on t");
 l[0]->help = ft_strcat(l[0]->help, "he command line. The option name=valu");
 l[0]->help = ft_strcat(l[0]->help, "e specifies an environmental variable");
 l[0]->help = ft_strcat(l[0]->help, ", name, with a value of value of valu");
 l[0]->help = ft_strcat(l[0]->help, "e. The option '-i' causes env to comp");
 l[0]->help = ft_strcat(l[0]->help, "letly ignore the environment it inher");
 l[0]->help = ft_strcat(l[0]->help, "its.\nIf no utility is specified, env");
 l[0]->help = ft_strcat(l[0]->help, " prints out the names and values of t");
 l[0]->help = ft_strcat(l[0]->help, "he variables in the environment, with");
 l[0]->help = ft_strcat(l[0]->help, " one name=value pair per line.\n");
 l[1] = (struct s_builtin *)malloc(sizeof(t_builtin));
 l[1]->name = ft_strdup("unsetenv");
 l[1]->help = (char *)malloc(sizeof(char) * 214);
 l[1]->help = ft_strcpy(l[1]->help, "USAGE :\nunsetenv name\n\nDESCRIPTION");
 l[1]->help = ft_strcat(l[1]->help, " :\nunsetenv deletes all instances of");
 return (init_listbuiltin2(l));
}

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


decompiled_code:
__int64 __fastcall parse_error(__int64 a1)
{
if ( write(1, "Parse error near '", 0x12uLL) )
{
ft_putstr(a1);
write(1, "'.\n", 3uLL);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( write(1, "Parse error near '", 0x12uLL) )
{
ft_putstr(a1);
write(1, "'.\n", 3uLL);
}
return 0LL;
}

original_code:
t_bool parse_error(char *str)
{
 if (!write(1, "Parse error near '", 18))
  return (FALSE);
 ft_putstr(str);
 if (!write(1, "'.\n", 3))
  return (FALSE);
 return (FALSE);
}

canonical_original_code:
enum e_bool parse_error(char *str)
{
 if (!write(1, "Parse error near '", 18))
  return (FALSE);
 ft_putstr(str);
 if (!write(1, "'.\n", 3))
  return (FALSE);
 return (FALSE);
}

variable_types:
str
char *

return_type: enum e_bool { TRUE=1, FALSE=0 }


decompiled_code:
__int64 __fastcall ft_putenv(__int64 a1, __int64 a2, __int64 a3)
{
return ft_setenv(a1, a2, 1LL, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
return ft_setenv(a1, a2, 1LL, a3);
}

original_code:
t_gen *ft_putenv(const char *n, const char *v, t_gen *env)
{
 return (ft_setenv(n, v, 1, env));
}

canonical_original_code:
struct s_gen *ft_putenv(char *n, char *v, struct s_gen *env)
{
 return (ft_setenv(n, v, 1, env));
}

variable_types:
n
char *

variable_types:
v
char *

variable_types:
env
struct s_gen *

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


decompiled_code:
void __fastcall token_free(void **a1)
{
void *v1; // rbp

v1 = *a1;
ft_strdel((char *)*a1 + 8);
free(v1);
}

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

v1 = *a1;
ft_strdel((char *)*a1 + 8);
free(v1);
}

original_code:
void token_free(t_token **token)
{
 t_token *to_free;
 to_free = *token;
 ft_strdel(&(to_free->str));
 free(to_free);
 to_free = ((void *)0);
}

canonical_original_code:
void token_free(struct s_token **token)
{
 struct s_token *to_free;
 to_free = *token;
 ft_strdel(&(to_free->str));
 free(to_free);
 to_free = ((void *)0);
}


start

decompiled_code:
// positive sp value has been detected, the output may be wrong!
void __fastcall __noreturn start(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1, __int64 a2, void (*a3)(void))
{
__int64 v3; // rax
int v4; // esi
__int64 v5; // [rsp-8h] [rbp-8h] BYREF
char *retaddr; // [rsp+0h] [rbp+0h] BYREF

v4 = v5;
v5 = v3;
_libc_start_main(
(int (__fastcall *)(int, char **, char **))main,
v4,
&retaddr,
_libc_csu_init,
_libc_csu_fini,
a3,
&v5);
__halt();
}

original_code:
void start(void)
{
 char **av;
 t_env *env;
 t_term *term;
 term = recup_term();
 ft_init_signal();
 env = return_env();
 while (1)
 {
  clean_hist(term->hist);
  ft_init_prompte(av, env, 1);
 }
}

canonical_original_code:
void start()
{
 char **av;
 struct s_env *env;
 struct s_term *term;
 term = recup_term();
 ft_init_signal();
 env = return_env();
 while (1)
 {
  clean_hist(term->hist);
  ft_init_prompte(av, env, 1);
 }
}

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


decompiled_code:
__int64 __fastcall wait_ret(int fd)
{
_BYTE v2[4104]; // [rsp+0h] [rbp-1008h] BYREF

ft_bzero(v2, 4096LL);
if ( recv(fd, v2, 0x1000uLL, 0) != -1 )
{
ft_putendl(v2);
ft_bzero(v2, 4096LL);
}
return 1LL;
}

original_code:
int wait_ret(int sock)
{
 char buff[4096];
 int ret;
 ft_bzero(buff, 4096);
 if (recv(sock, buff, sizeof(buff), 0) != -1)
 {
  ft_putendl(buff);
  ft_bzero(buff, 4096);
 }
 return (1);
}

variable_types: sock int

variable_types:
buff
char [4096]

variable_types: ret int


recall

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

if ( a1 > 1 )
{
a2[a1 - 1] = 0;
ft_putstr_fd(a2, a3);
result = ft_strncmp(a2, "quit", 4LL);
if ( !(_DWORD)result )
return result;
if ( (unsigned int)ft_strncmp(a2, "get", 3LL) && (unsigned int)ft_strncmp(a2, "put", 3LL) )
wait_ret(a3);
else
file_ftp(a2, a3);
ft_bzero(a2, 1024LL);
}
ft_putstr("F_TP > ");
return 1LL;
}

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

if ( a1 > 1 )
{
a2[a1 - 1] = 0;
func21(a2, a3);
result = func23(a2, "quit", 4LL);
if ( !(_DWORD)result )
return result;
if ( (unsigned int)func23(a2, "get", 3LL) && (unsigned int)func23(a2, "put", 3LL) )
func10(a3);
else
func15(a2, a3);
func17(a2, 1024LL);
}
func20("F_TP > ");
return 1LL;
}

original_code:
int recall(int ret, char *buff, int sock)
{
 if (ret > 1)
 {
  buff[ret - 1] = 0;
  ft_putstr_fd((char *)buff, sock);
  if (ft_strncmp(buff, "quit", 4) == 0)
   return (0);
  if (ft_strncmp(buff, "get", 3) == 0 || !ft_strncmp(buff, "put", 3))
   file_ftp(buff, sock);
  else
   wait_ret(sock);
  ft_bzero(buff, 1024);
 }
 ft_putstr("F_TP > ");
 return (1);
}

variable_types:
buff
char *


decompiled_code:
__int64 __fastcall fd_init(int *a1, __int64 a2)
{
int v3; // eax

if ( *a1 )
return 0LL;
v3 = open((const char *)(a2 + 4100), 66, 420LL);
*a1 = v3;
if ( v3 >= 0 )
return 0LL;
*(_DWORD *)(a2 + 5124) = -1;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func13(int *a1, __int64 a2)
{
int v3; // eax

if ( *a1 )
return 0LL;
v3 = open((const char *)(a2 + 4100), 66, 420LL);
*a1 = v3;
if ( v3 >= 0 )
return 0LL;
*(_DWORD *)(a2 + 5124) = -1;
return 0xFFFFFFFFLL;
}

original_code:
int fd_init(int *fd, t_pkg *pkg, int cs)
{
 if (*fd == 0 && (*fd = open(pkg->name, 02 | 0100, 00644)) < 0)
 {
  pkg->len = -1;
  while (pkg->len > 0)
   recv(cs, (char *)pkg, sizeof(t_pkg), 0);
  return (-1);
 }
 return (0);
}

canonical_original_code:
int fd_init(int *fd, struct s_pkg *pkg, int cs)
{
 if (*fd == 0 && (*fd = open(pkg->name, 02 | 0100, 00644)) < 0)
 {
  pkg->len = -1;
  while (pkg->len > 0)
   recv(cs, (char *)pkg, sizeof(t_pkg), 0);
  return (-1);
 }
 return (0);
}

variable_types:
fd
int *

variable_types: struct s_pkg { int brk; char buff[4096]; char name[1024]; int len; } *

variable_types: cs int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
_BYTE v6[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( argc != 3 )
usage((void *)*argv);
ft_atoi(argv[2]);
v3 = create_client((char *)argv[1]);
ft_putstr("F_TP > ");
do
v4 = read(0, v6, 0x3FFuLL);
while ( v4 && !(unsigned int)recall(v4, v6, v3) );
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
unsigned int v4; // eax
_BYTE v6[1032]; // [rsp+0h] [rbp-408h] BYREF

if ( argc != 3 )
func8((void *)*argv);
func16(argv[2]);
v3 = func9((char *)argv[1]);
func20("F_TP > ");
do
v4 = read(0, v6, 0x3FFuLL);
while ( v4 && !(unsigned int)func11(v4, v6, v3) );
close(v3);
return 0;
}

original_code:
int main(int ac, char **av)
{
 int port;
 int sock;
 char buff[1024];
 int ret;
 if (ac != 3)
  usage(av[0]);
 port = ft_atoi(av[2]);
 sock = create_client(av[1], port);
 ft_putstr("F_TP > ");
 while ((ret = read(0, buff, 1023)))
 {
  if (recall(ret, buff, sock))
   break ;
 }
 close(sock);
 return (0);
}

variable_types: ac int

variable_types: port int

variable_types:
buff
char [1024]


usage

decompiled_code:
void __fastcall __noreturn usage(void *buf)
{
ft_puterr("usage: ");
ft_puterr(buf);
ft_puterr(" <addr> <port>\n");
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func8(void *buf)
{
func24("usage: ");
func24(buf);
func24(" <addr> <port>\n");
exit(-1);
}

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

variable_types:
name
char *


decompiled_code:
__int64 __fastcall create_client(char *cp, __int16 a2)
{
struct protoent *v2; // rax
unsigned int v3; // er12
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v2 = getprotobyname("tcp");
if ( v2 )
{
v3 = socket(2, 1, v2->p_proto);
if ( v3 == -1 )
{
ft_puterr("socket fail\n");
}
else
{
v5.sa_family = 2;
*(_WORD *)v5.sa_data = _bswap_16(a2);
*(_DWORD *)&v5.sa_data[2] = inet_addr(cp);
if ( connect(v3, &v5, 0x10u) == -1 )
{
ft_puterr("fail to connect\n");
exit(-1);
}
}
}
else
{
v3 = -1;
ft_puterr("getprotobyname fail\n");
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *cp, __int16 a2)
{
struct protoent *v2; // rax
unsigned int v3; // er12
struct sockaddr v5; // [rsp+0h] [rbp-28h] BYREF

v2 = getprotobyname("tcp");
if ( v2 )
{
v3 = socket(2, 1, v2->p_proto);
if ( v3 == -1 )
{
func24("socket fail\n");
}
else
{
v5.sa_family = 2;
*(_WORD *)v5.sa_data = func7(a2);
*(_DWORD *)&v5.sa_data[2] = inet_addr(cp);
if ( connect(v3, &v5, 0x10u) == -1 )
{
func24("fail to connect\n");
exit(-1);
}
}
}
else
{
v3 = -1;
func24("getprotobyname fail\n");
}
return v3;
}

original_code:
int create_client(char *addr, int port)
{
 int sock;
 struct protoent *proto;
 struct sockaddr_in sin;
 if ((proto = getprotobyname("tcp")) == 0)
 {
  ft_puterr("getprotobyname fail\n");
  return (-1);
 }
 if ((sock = socket(2, SOCK_STREAM, proto->p_proto)) == -1)
 {
  ft_puterr("socket fail\n");
  return (-1);
 }
 sin.sin_family = 2;
 sin.sin_port = htons(port);
 sin.sin_addr.s_addr = inet_addr(addr);
 if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1)
 {
  ft_puterr("fail to connect\n");
  exit(-1);
 }
 return (sock);
}

variable_types:
addr
char *

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


original_code:
t_process *process_lst_add(t_process *lst, char *str)
{
 t_process *new_process;
 t_process *current;
 if (!(new_process = create_process(str)))
  return (((void *)0));
 if (!lst)
  return (new_process);
 current = lst;
 while (current->next != ((void *)0))
  current = current->next;
 current->next = new_process;
 new_process->prev = current;
 return (lst);
}

canonical_original_code:
struct s_process *process_lst_add(struct s_process *lst, char *str)
{
 struct s_process *new_process;
 struct s_process *current;
 if (!(new_process = create_process(str)))
  return (((void *)0));
 if (!lst)
  return (new_process);
 current = lst;
 while (current->next != ((void *)0))
  current = current->next;
 current->next = new_process;
 new_process->prev = current;
 return (lst);
}

variable_types:
lst
struct s_process *

variable_types:
str
char *

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


original_code:
void ft_moove_w_left(t_term *term)
{
 int i;
 i = term->hist->pose_cursor;
 if (i > 0)
 {
  while (term->hist->buff[--i])
  {
   if ((term->hist->buff[i - 1] == ' '
    && ft_isprint(term->hist->buff[i])) || (i == 0))
    break ;
  }
  while (term->hist->pose_cursor-- != i)
   ft_putstr_fd(term->key[4], term->fd);
  term->hist->pose_cursor = i;
 }
 else
  ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void ft_moove_w_left(struct s_term *term)
{
 int i;
 i = term->hist->pose_cursor;
 if (i > 0)
 {
  while (term->hist->buff[--i])
  {
   if ((term->hist->buff[i - 1] == ' '
    && ft_isprint(term->hist->buff[i])) || (i == 0))
    break ;
  }
  while (term->hist->pose_cursor-- != i)
   ft_putstr_fd(term->key[4], term->fd);
  term->hist->pose_cursor = i;
 }
 else
  ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}

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: i int

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


original_code:
void ft_moove_w_right(t_term *term)
{
 int i;
 i = term->hist->pose_cursor;
 if (term->hist->buff[i++])
 {
  while (term->hist->buff[i++])
  {
   if (term->hist->buff[i - 1] == ' '
    && ft_isprint(term->hist->buff[i]))
    break ;
  }
  while (term->hist->pose_cursor++ != i)
   ft_putstr_fd(term->key[3], term->fd);
  term->hist->pose_cursor = i;
 }
 else
  ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void ft_moove_w_right(struct s_term *term)
{
 int i;
 i = term->hist->pose_cursor;
 if (term->hist->buff[i++])
 {
  while (term->hist->buff[i++])
  {
   if (term->hist->buff[i - 1] == ' '
    && ft_isprint(term->hist->buff[i]))
    break ;
  }
  while (term->hist->pose_cursor++ != i)
   ft_putstr_fd(term->key[3], term->fd);
  term->hist->pose_cursor = i;
 }
 else
  ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}

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


original_code:
void press_ctrld(t_term *term)
{
 ft_putstr("\n");
 parse_ps1(return_env());
 term->quote = 0;
 term->dquote = 0;
 while (term->hist->next)
  term->hist = term->hist->next;
 ft_bzero(term->hist->buff, 4096);
 ft_bzero(term->hist->value, 4096);
 term->hist->exec = 1;
 term->hist->len = 0;
 term->hist->pose_cursor = 0;
}

canonical_original_code:
void press_ctrld(struct s_term *term)
{
 ft_putstr("\n");
 parse_ps1(return_env());
 term->quote = 0;
 term->dquote = 0;
 while (term->hist->next)
  term->hist = term->hist->next;
 ft_bzero(term->hist->buff, 4096);
 ft_bzero(term->hist->value, 4096);
 term->hist->exec = 1;
 term->hist->len = 0;
 term->hist->pose_cursor = 0;
}


decompiled_code:
__int64 __fastcall ft_checkbuiltin(_QWORD **a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
_QWORD *v4; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD **a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
_QWORD *v4; // rax

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

original_code:
int ft_checkbuiltin(t_process *p, t_gen *gen)
{
 int i;
 i = -1;
 if (!gen->builtin)
  gen->builtin = init_listbuiltin();
 while (gen->builtin[++i] && gen->builtin[i]->name)
  if (ft_strcmp(p->av[0], gen->builtin[i]->name) == 0)
   return (1);
 return (0);
}

canonical_original_code:
int ft_checkbuiltin(struct s_process *p, struct s_gen *gen)
{
 int i;
 i = -1;
 if (!gen->builtin)
  gen->builtin = init_listbuiltin();
 while (gen->builtin[++i] && gen->builtin[i]->name)
  if (ft_strcmp(p->av[0], gen->builtin[i]->name) == 0)
   return (1);
 return (0);
}

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

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:
__int64 __fastcall ft_run_builtin(__int64 a1, __int64 a2)
{
__int64 result; // rax

ft_builtin();
result = *(unsigned int *)(a2 + 48);
if ( (_DWORD)result )
result = 256LL;
return result;
}

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

ft_builtin();
result = *(unsigned int *)(a2 + 48);
if ( (_DWORD)result )
result = 256LL;
return result;
}

original_code:
int ft_run_builtin(t_process *p, t_gen *env)
{
 ft_builtin(p, env);
 if (env->ret == 0)
  return (0);
 return (256);
}

canonical_original_code:
int ft_run_builtin(struct s_process *p, struct s_gen *env)
{
 ft_builtin(p, env);
 if (env->ret == 0)
  return (0);
 return (256);
}

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

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

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

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


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

ft_printf("je meure\n");
v2 = *(&sem[1].__align + 2);
*(_BYTE *)(v2 + (int)return_pose(sem, *a2, a2[1])) = 0;
sem_rel(sem);
sem_wait(sem);
shmdt((const void *)sem[2].__align);
exit(0);
}

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

ft_printf("je meure\n");
v2 = *(&sem[1].__align + 2);
*(_BYTE *)(v2 + (int)return_pose(sem, *a2, a2[1])) = 0;
sem_rel(sem);
sem_wait(sem);
shmdt((const void *)sem[2].__align);
exit(0);
}

original_code:
void clear_me(t_env *env, t_play *p)
{
 ft_printf("je meure\n");
 env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 sem_rel(env);
 sem_wait(env);
 shmdt (env->mem);
 exit(0);
}

canonical_original_code:
void clear_me(struct s_env *env, struct s_play *p)
{
 ft_printf("je meure\n");
 env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 sem_rel(env);
 sem_wait(env);
 shmdt (env->mem);
 exit(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_play { struct s_move { int x; int y; } init; struct s_move to_do; int etats; } *

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_play { struct s_move init; struct s_move to_do; int etats; }

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:
__int64 __fastcall move_other(__int64 a1, unsigned int *a2)
{
int v3; // eax
__int64 v4; // rsi
__int64 result; // rax

v3 = check_case(a1, *a2, a2[1] + 1);
v4 = 2LL;
if ( v3 )
{
v4 = 3LL;
if ( (unsigned int)check_case(a1, *a2 + 1, a2[1]) )
{
v4 = 4LL;
if ( (unsigned int)check_case(a1, *a2, a2[1] - 1) )
{
result = check_case(a1, *a2 - 1, a2[1]);
if ( (_DWORD)result )
return result;
v4 = 1LL;
}
}
}
return init_moove(a2, v4);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int *a2)
{
int v3; // eax
__int64 v4; // rsi
__int64 result; // rax

v3 = check_case(a1, *a2, a2[1] + 1);
v4 = 2LL;
if ( v3 )
{
v4 = 3LL;
if ( (unsigned int)check_case(a1, *a2 + 1, a2[1]) )
{
v4 = 4LL;
if ( (unsigned int)check_case(a1, *a2, a2[1] - 1) )
{
result = check_case(a1, *a2 - 1, a2[1]);
if ( (_DWORD)result )
return result;
v4 = 1LL;
}
}
}
return init_moove(a2, v4);
}

original_code:
void move_other(t_env *env, t_play *p)
{
 if (check_case(env, p->init.x, p->init.y + 1) == 0)
  init_moove(p, 2);
 else if (check_case(env, p->init.x + 1, p->init.y) == 0)
  init_moove(p, 3);
 else if (check_case(env, p->init.x, p->init.y - 1) == 0)
  init_moove(p, 4);
 else if (check_case(env, p->init.x - 1, p->init.y) == 0)
  init_moove(p, 1);
}

canonical_original_code:
void move_other(struct s_env *env, struct s_play *p)
{
 if (check_case(env, p->init.x, p->init.y + 1) == 0)
  init_moove(p, 2);
 else if (check_case(env, p->init.x + 1, p->init.y) == 0)
  init_moove(p, 3);
 else if (check_case(env, p->init.x, p->init.y - 1) == 0)
  init_moove(p, 4);
 else if (check_case(env, p->init.x - 1, p->init.y) == 0)
  init_moove(p, 1);
}

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


move

decompiled_code:
__int64 __fastcall move(sem_t *sem, unsigned int *a2)
{
__int64 v3; // rsi
__int64 v4; // rdx
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // rbx
__int64 result; // rax
__int64 v9; // rbx

if ( *(_DWORD *)sem->__size )
ft_printf("moove to x : %d y : %d\n", a2[2], a2[3]);
if ( (int)nb_enemy(sem, a2) > 1 )
clear_me(sem, a2);
v3 = a2[2];
v4 = a2[3];
if ( *(_QWORD *)a2 != __PAIR64__(v4, v3) )
{
v5 = *(&sem[1].__align + 2);
if ( !*(_BYTE *)(v5 + (int)return_pose(sem, v3, v4)) )
{
v9 = *(&sem[1].__align + 2);
*(_BYTE *)(v9 + (int)return_pose(sem, *a2, a2[1])) = 0;
}
v4 = a2[3];
v3 = a2[2];
}
v6 = *(&sem[1].__align + 2);
if ( *(_BYTE *)(v6 + (int)return_pose(sem, v3, v4)) )
return move_other((__int64)sem, a2);
v7 = *(&sem[1].__align + 2);
*(_BYTE *)(v7 + (int)return_pose(sem, a2[2], a2[3])) = sem[2].__size[8];
result = *((_QWORD *)a2 + 1);
*(_QWORD *)a2 = result;
return result;
}

original_code:
void move(t_env *env, t_play *p)
{
 if (env->verbose)
  ft_printf("moove to x : %d y : %d\n", p->to_do.x, p->to_do.y);
 if (nb_enemy(env, p) >= 2)
  clear_me(env, p);
 if ((p->init.x != p->to_do.x || p->init.y != p->to_do.y)
  && env->map[return_pose(env, p->to_do.x, p->to_do.y)] == 0)
  env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 if (env->map[return_pose(env, p->to_do.x, p->to_do.y)] == 0)
 {
  env->map[return_pose(env, p->to_do.x, p->to_do.y)] = env->player_id;
  p->init.x = p->to_do.x;
  p->init.y = p->to_do.y;
 }
 else
  move_other(env, p);
}

canonical_original_code:
void move(struct s_env *env, struct s_play *p)
{
 if (env->verbose)
  ft_printf("moove to x : %d y : %d\n", p->to_do.x, p->to_do.y);
 if (nb_enemy(env, p) >= 2)
  clear_me(env, p);
 if ((p->init.x != p->to_do.x || p->init.y != p->to_do.y)
  && env->map[return_pose(env, p->to_do.x, p->to_do.y)] == 0)
  env->map[return_pose(env, p->init.x, p->init.y)] = 0;
 if (env->map[return_pose(env, p->to_do.x, p->to_do.y)] == 0)
 {
  env->map[return_pose(env, p->to_do.x, p->to_do.y)] = env->player_id;
  p->init.x = p->to_do.x;
  p->init.y = p->to_do.y;
 }
 else
  move_other(env, p);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall ckeck_statut(__int64 a1, __int64 a2)
{
return nb_enemy(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return nb_enemy(a1, a2);
}

original_code:
int ckeck_statut(t_env *env, t_play *p)
{
 return (nb_enemy(env, p));
}

canonical_original_code:
int ckeck_statut(struct s_env *env, struct s_play *p)
{
 return (nb_enemy(env, p));
}


play

decompiled_code:
__int64 __fastcall play(sem_t *sem, unsigned int *a2)
{
if ( *(_DWORD *)sem->__size == 1 )
ft_printf("je joue pour la team %c\n", (unsigned int)sem[2].__size[8]);
if ( *a2 == -1 )
{
*a2 = a2[2];
}
else
{
if ( (unsigned int)ckeck_statut((__int64)sem, (__int64)a2) == 1 )
return 1LL;
search_enemy(sem, a2);
}
move(sem, a2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(sem_t *sem, unsigned int *a2)
{
if ( *(_DWORD *)sem->__size == 1 )
ft_printf("je joue pour la team %c\n", (unsigned int)sem[2].__size[8]);
if ( *a2 == -1 )
{
*a2 = a2[2];
}
else
{
if ( (unsigned int)func3((__int64)sem, (__int64)a2) == 1 )
return 1LL;
search_enemy(sem, a2);
}
func2(sem, a2);
return 1LL;
}

original_code:
int play(t_env *env, t_play *p)
{
 if (env->verbose == 1)
  ft_printf("je joue pour la team %c\n", env->player_id);
 if (p->init.x != -1)
 {
  if (ckeck_statut(env, p) == 1)
   return (1);
  else
   search_enemy(env, p);
 }
 else
  p->init.x = p->to_do.x;
 move(env, p);
 return (1);
}

canonical_original_code:
int play(struct s_env *env, struct s_play *p)
{
 if (env->verbose == 1)
  ft_printf("je joue pour la team %c\n", env->player_id);
 if (p->init.x != -1)
 {
  if (ckeck_statut(env, p) == 1)
   return (1);
  else
   search_enemy(env, p);
 }
 else
  p->init.x = p->to_do.x;
 move(env, p);
 return (1);
}


original_code:
void change_nickname(t_env *env, int cs)
{
 char *tmp;
 env->fds[cs].save[ft_strlen(env->fds[cs].save) - 1] = '\0';
 printf("client %s change nick to %s\n",
   env->fds[cs].nick, env->fds[cs].save + 6);
 free(env->fds[cs].nick);
 tmp = ft_strjoin(env->fds[cs].save, " : ");
 env->fds[cs].nick = ft_strdup(tmp + 6);
 free(tmp);
 ft_strcat(env->fds[cs].buff_write, "your nick name is now : ");
 ft_strcat(env->fds[cs].buff_write, env->fds[cs].save + 6);
 ft_strcat(env->fds[cs].buff_write, "\n");
}

canonical_original_code:
void change_nickname(struct s_env *env, int cs)
{
 char *tmp;
 env->fds[cs].save[ft_strlen(env->fds[cs].save) - 1] = '\0';
 printf("client %s change nick to %s\n",
   env->fds[cs].nick, env->fds[cs].save + 6);
 free(env->fds[cs].nick);
 tmp = ft_strjoin(env->fds[cs].save, " : ");
 env->fds[cs].nick = ft_strdup(tmp + 6);
 free(tmp);
 ft_strcat(env->fds[cs].buff_write, "your nick name is now : ");
 ft_strcat(env->fds[cs].buff_write, env->fds[cs].save + 6);
 ft_strcat(env->fds[cs].buff_write, "\n");
}

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

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


original_code:
void change_chan(t_env *env, int cs)
{
 char *tmp;
 int i;
 i = 0;
 env->fds[cs].save[ft_strlen(env->fds[cs].save) - 1] = 0;
 tmp = ft_strtrim(env->fds[cs].save + 6);
 if (tmp[0] == '#')
 {
  while (i < 100 && env->chan[i].name != ((void *)0)
   && ft_strcmp(env->chan[i].name, tmp) != 0)
   i++;
  if (env->chan[i].name == ((void *)0))
  {
   env->chan[i].name = ft_strdup(tmp);
   env->chan[i].id = i;
  }
  env->fds[cs].channel = i;
  ft_strcat(env->fds[cs].buff_write, "you have changed channel to ");
  ft_strcat(env->fds[cs].buff_write, tmp);
  ft_strcat(env->fds[cs].buff_write, "\n");
  printf("client %schange channel to %s\n",
   env->fds[cs].nick, env->chan[i].name);
 }
 else
  send(cs, "channel name not valide start by #\n", 35, 0);
}

canonical_original_code:
void change_chan(struct s_env *env, int cs)
{
 char *tmp;
 int i;
 i = 0;
 env->fds[cs].save[ft_strlen(env->fds[cs].save) - 1] = 0;
 tmp = ft_strtrim(env->fds[cs].save + 6);
 if (tmp[0] == '#')
 {
  while (i < 100 && env->chan[i].name != ((void *)0)
   && ft_strcmp(env->chan[i].name, tmp) != 0)
   i++;
  if (env->chan[i].name == ((void *)0))
  {
   env->chan[i].name = ft_strdup(tmp);
   env->chan[i].id = i;
  }
  env->fds[cs].channel = i;
  ft_strcat(env->fds[cs].buff_write, "you have changed channel to ");
  ft_strcat(env->fds[cs].buff_write, tmp);
  ft_strcat(env->fds[cs].buff_write, "\n");
  printf("client %schange channel to %s\n",
   env->fds[cs].nick, env->chan[i].name);
 }
 else
  send(cs, "channel name not valide start by #\n", 35, 0);
}

variable_types: cs int

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


decompiled_code:
__int64 __fastcall leave_chan(__int64 a1, int a2)
{
__int64 v2; // rsi
__int64 v3; // rdi

v2 = *(_QWORD *)(a1 + 24) + 8240LL * a2;
v3 = v2 + 4141;
if ( *(_DWORD *)(v2 + 40) == -1 )
return ft_strcat(v3, "you are not in channel\n");
*(_DWORD *)(v2 + 40) = -1;
return ft_strcat(v3, "you are leave channel\n");
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
__int64 v2; // rsi
__int64 v3; // rdi

v2 = *(_QWORD *)(a1 + 24) + 8240LL * a2;
v3 = v2 + 4141;
if ( *(_DWORD *)(v2 + 40) == -1 )
return ft_strcat(v3, "you are not in channel\n");
*(_DWORD *)(v2 + 40) = -1;
return ft_strcat(v3, "you are leave channel\n");
}

original_code:
void leave_chan(t_env *env, int cs)
{
 if (env->fds[cs].channel == -1)
  ft_strcat(env->fds[cs].buff_write, "you are not in channel\n");
 else
 {
  env->fds[cs].channel = -1;
  ft_strcat(env->fds[cs].buff_write, "you are leave channel\n");
 }
}

canonical_original_code:
void leave_chan(struct s_env *env, int cs)
{
 if (env->fds[cs].channel == -1)
  ft_strcat(env->fds[cs].buff_write, "you are not in channel\n");
 else
 {
  env->fds[cs].channel = -1;
  ft_strcat(env->fds[cs].buff_write, "you are leave channel\n");
 }
}


original_code:
void send_priv(t_env *env, int cs)
{
 char **splt;
 int i;
 i = 0;
 splt = ft_strsplit(env->fds[cs].save, ' ');
 while (i < env->max_fd && ft_strncmp(env->fds[i].nick, splt[1],
   ft_strlen(splt[1])) != 0)
  i++;
 if (i < env->max_fd)
 {
  ft_strcat(env->fds[i].buff_write, env->fds[cs].nick);
  ft_strcat(env->fds[i].buff_write,
    env->fds[cs].save + 7 + ft_strlen(splt[1]));
 }
 else
  ft_strcat(env->fds[cs].buff_write, "client not found\n");
}

canonical_original_code:
void send_priv(struct s_env *env, int cs)
{
 char **splt;
 int i;
 i = 0;
 splt = ft_strsplit(env->fds[cs].save, ' ');
 while (i < env->max_fd && ft_strncmp(env->fds[i].nick, splt[1],
   ft_strlen(splt[1])) != 0)
  i++;
 if (i < env->max_fd)
 {
  ft_strcat(env->fds[i].buff_write, env->fds[cs].nick);
  ft_strcat(env->fds[i].buff_write,
    env->fds[cs].save + 7 + ft_strlen(splt[1]));
 }
 else
  ft_strcat(env->fds[cs].buff_write, "client not found\n");
}

variable_types:
splt
char **


original_code:
void fct_read(t_env *env)
{
 if (recv(env->sock, env->buff_read, 4096, 0) <= 0)
 {
  close(env->sock);
  exit(0);
 }
 ft_printf("\n%s", env->buff_read);
 ft_bzero(env->buff_read, 4096);
}

canonical_original_code:
void fct_read(struct s_env *env)
{
 if (recv(env->sock, env->buff_read, 4096, 0) <= 0)
 {
  close(env->sock);
  exit(0);
 }
 ft_printf("\n%s", env->buff_read);
 ft_bzero(env->buff_read, 4096);
}

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

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


original_code:
void fct_write(t_env *env)
{
 int ret;
 char *tmp;
 ret = read(0, env->buff_write, 4096 - 1);
 env->buff_write[ret] = 0;
 tmp = ft_strtrim(env->buff_write);
 if (tmp[0] == '/')
  checkcmd(env, tmp, ret);
 send(env->sock, env->buff_write, ret, 0);
 ft_bzero(env->buff_write, ret);
 free(tmp);
}

canonical_original_code:
void fct_write(struct s_env *env)
{
 int ret;
 char *tmp;
 ret = read(0, env->buff_write, 4096 - 1);
 env->buff_write[ret] = 0;
 tmp = ft_strtrim(env->buff_write);
 if (tmp[0] == '/')
  checkcmd(env, tmp, ret);
 send(env->sock, env->buff_write, ret, 0);
 ft_bzero(env->buff_write, ret);
 free(tmp);
}

variable_types: ret int


decompiled_code:
__int64 __fastcall ft_striteri(_BYTE *a1, __int64 (__fastcall *a2)(__int64, _BYTE *))
{
_BYTE *v3; // rbx
unsigned int v4; // ebp
_BYTE *v5; // rsi
__int64 v6; // rdi
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
v3 = a1;
if ( *a1 )
{
v4 = 0;
do
{
v5 = v3++;
v6 = v4++;
result = a2(v6, v5);
}
while ( *v3 );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 (__fastcall *a2)(__int64, _BYTE *))
{
_BYTE *v3; // rbx
unsigned int v4; // ebp
_BYTE *v5; // rsi
__int64 v6; // rdi
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
v3 = a1;
if ( *a1 )
{
v4 = 0;
do
{
v5 = v3++;
v6 = v4++;
result = a2(v6, v5);
}
while ( *v3 );
}
}
}
return result;
}

original_code:
void ft_striteri(char *s, void (*f)(unsigned int, char *))
{
 char *s2;
 if (s && f)
 {
  s2 = s;
  while (*s2)
  {
   (*f)((s2 - s), s2);
   s2++;
  }
 }
}

variable_types:
s
char *

variable_types:
f
void (*)(unsigned int, char *)


decompiled_code:
__int64 __fastcall ft_isalnum(int a1)
{
return ((unsigned int)(a1 - 48) <= 9) | (unsigned __int8)((a1 & 0xFFFFFFDF) - 65 <= 0x19);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return ((unsigned int)(a1 - 48) <= 9) | (unsigned __int8)((a1 & 0xFFFFFFDF) - 65 <= 0x19);
}

original_code:
int ft_isalnum(int c)
{
 if (ft_isalpha(c) || ft_isdigit(c))
  return (1);
 return (0);
}

variable_types: c int


original_code:
void free_split(char ***to_free)
{
 int i;
 i = 0;
 while ((*to_free)[i] != ((void *)0))
 {
  free((*to_free)[i]);
  (*to_free)[i] = ((void *)0);
  i++;
 }
 free(*to_free);
 *to_free = ((void *)0);
}


original_code:
void parse_av(t_env *env, char **av)
{
 int i;
 i = 0;
 while (av[++i])
 {
  if (ft_strcmp(av[i], "-v") == 0)
   env->verbose = 1;
  else if (ft_strcmp(av[i], "-x") == 0 && av[i + 1])
   env->size_x = ft_atoi(av[++i]);
  else if (ft_strcmp(av[i], "-y") == 0 && av[i + 1])
   env->size_y = ft_atoi(av[++i]);
  else if (ft_strcmp(av[i], "-g") == 0)
   graphique_mode(env);
  else if (ft_strcmp(av[i], "-s") == 0)
   env->wait = 1;
  else if (env->team_id == 0)
   env->team_id = av[i];
  else
   usage(av[0]);
 }
}

canonical_original_code:
void parse_av(struct s_env *env, char **av)
{
 int i;
 i = 0;
 while (av[++i])
 {
  if (ft_strcmp(av[i], "-v") == 0)
   env->verbose = 1;
  else if (ft_strcmp(av[i], "-x") == 0 && av[i + 1])
   env->size_x = ft_atoi(av[++i]);
  else if (ft_strcmp(av[i], "-y") == 0 && av[i + 1])
   env->size_y = ft_atoi(av[++i]);
  else if (ft_strcmp(av[i], "-g") == 0)
   graphique_mode(env);
  else if (ft_strcmp(av[i], "-s") == 0)
   env->wait = 1;
  else if (env->team_id == 0)
   env->team_id = av[i];
  else
   usage(av[0]);
 }
}

variable_types:
av
char **


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
ft_fprintf(2LL, "%s usage : %s [-v] team_id \n", a1, a1);
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
ft_fprintf(2LL, "%s usage : %s [-v] team_id \n", a1, a1);
exit(-1);
}

original_code:
void usage(char *name)
{
 ft_fprintf(2, "%s usage : %s [-v] team_id \n", name, name);
 exit(-1);
}

variable_types:
name
char *


original_code:
void init_env(t_env *env, char **av)
{
 env->key = ftok(av[0], 42);
 env->verbose = 0;
 env->team_id = 0;
 env->size_mem = 0;
 env->mem = ((void *)0);
 env->size_x = 25;
 env->size_y = 25;
 env->brk = 1;
 env->turn = 0;
}

canonical_original_code:
void init_env(struct s_env *env, char **av)
{
 env->key = ftok(av[0], 42);
 env->verbose = 0;
 env->team_id = 0;
 env->size_mem = 0;
 env->mem = ((void *)0);
 env->size_x = 25;
 env->size_y = 25;
 env->brk = 1;
 env->turn = 0;
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[104]; // [rsp+0h] [rbp-68h] BYREF

if ( argc == 1 )
usage(*argv);
init_env((__int64)v4, argv);
parse_av((__int64)v4, (__int64)argv);
if ( (unsigned int)init_memory(v4) == 1 )
clearmap(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_BYTE v4[104]; // [rsp+0h] [rbp-68h] BYREF

if ( argc == 1 )
func0(*argv);
func2((__int64)v4, argv);
func1((__int64)v4, (__int64)argv);
if ( (unsigned int)init_memory(v4) == 1 )
clearmap(v4);
return 0;
}

original_code:
int main(int ac, char **av)
{
 t_env env;
 if (ac == 1)
  usage(av[0]);
 init_env(&env, av);
 parse_av(&env, av);
 if (init_memory(&env) == 1)
  clearmap(&env);
 return (0);
}

canonical_original_code:
int main(int ac, char **av)
{
 struct s_env env;
 if (ac == 1)
  usage(av[0]);
 init_env(&env, av);
 parse_av(&env, av);
 if (init_memory(&env) == 1)
  clearmap(&env);
 return (0);
}

variable_types: ac int

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


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

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

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

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

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

variable_types: i int


decompiled_code:
__sighandler_t init_sig()
{
signal(2, (__sighandler_t)&ft_sig_int);
return signal(20, (__sighandler_t)&ft_sig_tstp);
}

canonical_decompiled_code:
__sighandler_t func2()
{
signal(2, (__sighandler_t)&ft_sig_int);
return signal(20, (__sighandler_t)&ft_sig_tstp);
}

original_code:
void init_sig(void)
{
 signal(2, ft_sig_int);
 signal(20, ft_sig_tstp);
}

canonical_original_code:
void init_sig()
{
 signal(2, ft_sig_int);
 signal(20, ft_sig_tstp);
}


decompiled_code:
int init_term()
{
__int64 v0; // rax
const char *v1; // rbp
__int64 v2; // rbx
const struct termios *v3; // rdx
char v5[2056]; // [rsp+0h] [rbp-808h] BYREF

v0 = ft_getenv("TERM_PROGRAM=");
if ( (unsigned int)ft_strncmp(v0, "iTerm.app", 5LL) )
{
v1 = (const char *)ft_getenv("TERM=");
v2 = recup_gen();
if ( !v1 )
{
ft_puterr("term not found in env");
if ( tgetent(v5, 0LL) > 0 )
goto LABEL_4;
LABEL_7:
ft_puterr("no acces termtype");
goto LABEL_4;
}
}
else
{
v1 = "linux";
v2 = recup_gen();
}
if ( tgetent(v5, v1) <= 0 )
goto LABEL_7;
LABEL_4:
tcgetattr(0, (struct termios *)(*(_QWORD *)(v2 + 24) + 60LL));
ft_memcpy(*(_QWORD *)(v2 + 24), *(_QWORD *)(v2 + 24) + 60LL, 60LL);
v3 = *(const struct termios **)(v2 + 24);
v3->c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, v3);
}

canonical_decompiled_code:
int func0()
{
__int64 v0; // rax
const char *v1; // rbp
__int64 v2; // rbx
const struct termios *v3; // rdx
char v5[2056]; // [rsp+0h] [rbp-808h] BYREF

v0 = ft_getenv("TERM_PROGRAM=");
if ( (unsigned int)ft_strncmp(v0, "iTerm.app", 5LL) )
{
v1 = (const char *)ft_getenv("TERM=");
v2 = recup_gen();
if ( !v1 )
{
ft_puterr("term not found in env");
if ( tgetent(v5, 0LL) > 0 )
goto LABEL_4;
LABEL_7:
ft_puterr("no acces termtype");
goto LABEL_4;
}
}
else
{
v1 = "linux";
v2 = recup_gen();
}
if ( tgetent(v5, v1) <= 0 )
goto LABEL_7;
LABEL_4:
tcgetattr(0, (struct termios *)(*(_QWORD *)(v2 + 24) + 60LL));
ft_memcpy(*(_QWORD *)(v2 + 24), *(_QWORD *)(v2 + 24) + 60LL, 60LL);
v3 = *(const struct termios **)(v2 + 24);
v3->c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, v3);
}

original_code:
void init_term(void)
{
 t_gen *gen;
 char buff[2024];
 char *termtype;
 int ret;
 char *term;
 term = (ft_strncmp(ft_getenv("TERM_PROGRAM="), "iTerm.app", 5) == 0) ? "linux" : ft_getenv("TERM=");
 gen = recup_gen();
 if ((termtype = term) == 0)
  ft_puterr("term not found in env");
 if ((ret = tgetent(buff, termtype)) < 1)
  ft_puterr("no acces termtype");
 tcgetattr(0, &gen->term->term_ori);
 ft_memcpy(&gen->term->term, &gen->term->term_ori, sizeof(struct termios));
 gen->term->term.c_lflag &= ~(0000010 | 0000002);
 tcsetattr(0, 0, &gen->term->term);
}

canonical_original_code:
void init_term()
{
 struct s_gen *gen;
 char buff[2024];
 char *termtype;
 int ret;
 char *term;
 term = (ft_strncmp(ft_getenv("TERM_PROGRAM="), "iTerm.app", 5) == 0) ? "linux" : ft_getenv("TERM=");
 gen = recup_gen();
 if ((termtype = term) == 0)
  ft_puterr("term not found in env");
 if ((ret = tgetent(buff, termtype)) < 1)
  ft_puterr("no acces termtype");
 tcgetattr(0, &gen->term->term_ori);
 ft_memcpy(&gen->term->term, &gen->term->term_ori, sizeof(struct termios));
 gen->term->term.c_lflag &= ~(0000010 | 0000002);
 tcsetattr(0, 0, &gen->term->term);
}

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

variable_types:
termtype
char *

variable_types:
term
char *


decompiled_code:
int close_term()
{
__int64 v0; // rax

v0 = recup_gen();
return tcsetattr(0, 0, (const struct termios *)(*(_QWORD *)(v0 + 24) + 60LL));
}

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

v0 = recup_gen();
return tcsetattr(0, 0, (const struct termios *)(*(_QWORD *)(v0 + 24) + 60LL));
}

original_code:
void close_term(void)
{
 t_gen *gen;
 gen = recup_gen();
 tcsetattr(0, 0, &gen->term->term_ori);
}

canonical_original_code:
void close_term()
{
 struct s_gen *gen;
 gen = recup_gen();
 tcsetattr(0, 0, &gen->term->term_ori);
}