decompiled_code:
__int64 __fastcall fn_prewrite(__int64 a1, char *a2)
{
__int64 result; // rax
char v5; // di
char *v6; // r12
char v7; // al
char i; // si
int v9; // [rsp+8h] [rbp-20h] BYREF
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

init_var(v10, &v9);
while ( 1 )
{
result = ++v10[0];
v5 = a2[v10[0]];
if ( !v5 )
break;
v6 = &a2[v9];
v7 = format_str((unsigned int)v5);
*v6 = v7;
if ( v7 )
++v9;
}
v10[0] = 0;
for ( i = *a2; i; i = a2[v10[0]] )
{
if ( i == 10 )
{
go_end(a1, 0LL);
*(_QWORD *)(a1 + 32) = save_hist(*(_QWORD *)(a1 + 32));
ft_putchar(10LL);
ft_parse_and_exec(*(_QWORD *)(a1 + 32) + 4108LL, a1);
updat_prompt(*(_QWORD *)(a1 + 16));
ft_putstr(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL));
*(_QWORD *)(a1 + 32) = add_element(*(_QWORD *)(a1 + 32));
}
else
{
fn_write_char(a1, i);
}
result = ++v10[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2)
{
__int64 result; // rax
char v5; // di
char *v6; // r12
char v7; // al
char i; // si
int v9; // [rsp+8h] [rbp-20h] BYREF
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

func2(v10, &v9);
while ( 1 )
{
result = ++v10[0];
v5 = a2[v10[0]];
if ( !v5 )
break;
v6 = &a2[v9];
v7 = format_str((unsigned int)v5);
*v6 = v7;
if ( v7 )
++v9;
}
v10[0] = 0;
for ( i = *a2; i; i = a2[v10[0]] )
{
if ( i == 10 )
{
go_end(a1, 0LL);
*(_QWORD *)(a1 + 32) = save_hist(*(_QWORD *)(a1 + 32));
ft_putchar(10LL);
ft_parse_and_exec(*(_QWORD *)(a1 + 32) + 4108LL, a1);
updat_prompt(*(_QWORD *)(a1 + 16));
ft_putstr(*(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL));
*(_QWORD *)(a1 + 32) = add_element(*(_QWORD *)(a1 + 32));
}
else
{
func3(a1, i);
}
result = ++v10[0];
}
return result;
}

original_code:
void fn_prewrite(t_gen *gen, char *key)
{
 int j;
 int i;
 init_var(&j, &i);
 while (key[++j])
 {
  if ((key[i] = format_str(key[j])) != 0)
   i++;
 }
 j = -1;
 while (key[++j])
 {
  if (key[j] == '\n')
  {
   go_end(gen, ((void *)0));
   gen->hist = save_hist(gen->hist);
   ft_putchar('\n');
   ft_parse_and_exec(gen->hist->buff, gen);
   updat_prompt(gen->ps1);
   ft_putstr(gen->ps1->aff);
   gen->hist = add_element(gen->hist);
  }
  else
   fn_write_char(gen, key[j]);
 }
}

canonical_original_code:
void fn_prewrite(struct s_gen *gen, char *key)
{
 int j;
 int i;
 init_var(&j, &i);
 while (key[++j])
 {
  if ((key[i] = format_str(key[j])) != 0)
   i++;
 }
 j = -1;
 while (key[++j])
 {
  if (key[j] == '\n')
  {
   go_end(gen, ((void *)0));
   gen->hist = save_hist(gen->hist);
   ft_putchar('\n');
   ft_parse_and_exec(gen->hist->buff, gen);
   updat_prompt(gen->ps1);
   ft_putstr(gen->ps1->aff);
   gen->hist = add_element(gen->hist);
  }
  else
   fn_write_char(gen, key[j]);
 }
}

variable_types: j int


original_code:
void parse_environ(t_env *env)
{
 int i[2];
 char *tmp;
 i[0] = 0 * (i[1] = 0);
 while (env->environ[i[0]])
 {
  if (!ft_strncmp(env->environ[i[0]], "PATH=", 5))
  {
   tmp = ft_strjoin(env->environ[i[0]] + 5, ":./");
   env->path = ft_strsplit(tmp, ':');
   free(tmp);
   while (env->path[i[1]] != 0)
   {
    tmp = ft_strjoin(env->path[i[1]], "/");
    free(env->path[i[1]]);
    env->path[i[1]] = tmp;
    i[1]++;
   }
  }
  else if (!ft_strncmp(env->environ[i[0]], "HOME=", 5))
   env->home = ft_strdup(env->environ[i[0]] + 5);
  i[0]++;
 }
 getcwd(env->pwd, 4096);
}

canonical_original_code:
void parse_environ(struct s_env *env)
{
 int i[2];
 char *tmp;
 i[0] = 0 * (i[1] = 0);
 while (env->environ[i[0]])
 {
  if (!ft_strncmp(env->environ[i[0]], "PATH=", 5))
  {
   tmp = ft_strjoin(env->environ[i[0]] + 5, ":./");
   env->path = ft_strsplit(tmp, ':');
   free(tmp);
   while (env->path[i[1]] != 0)
   {
    tmp = ft_strjoin(env->path[i[1]], "/");
    free(env->path[i[1]]);
    env->path[i[1]] = tmp;
    i[1]++;
   }
  }
  else if (!ft_strncmp(env->environ[i[0]], "HOME=", 5))
   env->home = ft_strdup(env->environ[i[0]] + 5);
  i[0]++;
 }
 getcwd(env->pwd, 4096);
}

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

variable_types:
i
int [2]

variable_types:
tmp
char *

return_type: void


original_code:
void ft_unsetenv(char **av, t_env *env)
{
 char **tmp;
 int i;
 int j;
 i = 0;
 j = 0;
 while (env->environ[j])
  j++;
 tmp = (char **)malloc(sizeof(char *) * j);
 j = 0;
 i = 0;
 while (env->environ[j])
 {
  if (ft_strncmp(env->environ[j], av[1], ft_strlen(av[1])))
  {
   tmp[i] = env->environ[j];
   i++;
  }
  j++;
 }
 tmp[i + 1] = ((void *)0);
 free(env->environ);
 env->environ = tmp;
 parse_environ(env);
}

canonical_original_code:
void ft_unsetenv(char **av, struct s_env *env)
{
 char **tmp;
 int i;
 int j;
 i = 0;
 j = 0;
 while (env->environ[j])
  j++;
 tmp = (char **)malloc(sizeof(char *) * j);
 j = 0;
 i = 0;
 while (env->environ[j])
 {
  if (ft_strncmp(env->environ[j], av[1], ft_strlen(av[1])))
  {
   tmp[i] = env->environ[j];
   i++;
  }
  j++;
 }
 tmp[i + 1] = ((void *)0);
 free(env->environ);
 env->environ = tmp;
 parse_environ(env);
}

variable_types:
av
char **

variable_types:
tmp
char **

variable_types: i int

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


original_code:
void ft_setenv(char **av, t_env *env)
{
 int i;
 int j;
 i = 0;
 j = 0;
 while (av[1][i] != '=' && av[1][i] != '\0')
  i++;
 if (av[1][i] == '\0')
 {
  ft_puterr("setenv : usage VAR=VALEUR\n");
  return ;
 }
 while (env->environ[j] && ft_strncmp(env->environ[j], av[1], i))
  j++;
 if (env->environ[j])
 {
  free(env->environ[j]);
  env->environ[j] = ft_strdelc(av[1], '"');
 }
 else
  create_env(env, j, ft_strdelc(av[1], '"'));
 parse_environ(env);
}

canonical_original_code:
void ft_setenv(char **av, struct s_env *env)
{
 int i;
 int j;
 i = 0;
 j = 0;
 while (av[1][i] != '=' && av[1][i] != '\0')
  i++;
 if (av[1][i] == '\0')
 {
  ft_puterr("setenv : usage VAR=VALEUR\n");
  return ;
 }
 while (env->environ[j] && ft_strncmp(env->environ[j], av[1], i))
  j++;
 if (env->environ[j])
 {
  free(env->environ[j]);
  env->environ[j] = ft_strdelc(av[1], '"');
 }
 else
  create_env(env, j, ft_strdelc(av[1], '"'));
 parse_environ(env);
}


decompiled_code:
__int64 __fastcall swap_file_in(void *ptr)
{
_QWORD *v1; // rbp
void *v2; // r13
void *v3; // r12
void *v4; // r13
__int64 v5; // r12
__int64 v6; // rax
void *v7; // r12
__int64 v8; // rbx

v1 = (_QWORD *)ft_strsplit(*((_QWORD *)ptr + 1), 32LL);
v2 = (void *)ft_strjoin(&unk_2D5, *v1);
v3 = (void *)ft_strjoin(v2, &unk_2D8);
free(v2);
v4 = (void *)ft_strjoin(v3, *(_QWORD *)ptr);
free(v3);
v5 = *((_QWORD *)ptr + 1);
v6 = ft_strlen(*v1);
v7 = (void *)ft_strjoin(v4, v5 + v6 + 1);
free(v4);
free(v1);
free(ptr);
v8 = ft_strsplit(v7, 60LL);
free(v7);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
_QWORD *v1; // rbp
void *v2; // r13
void *v3; // r12
void *v4; // r13
__int64 v5; // r12
__int64 v6; // rax
void *v7; // r12
__int64 v8; // rbx

v1 = (_QWORD *)ft_strsplit(*((_QWORD *)ptr + 1), 32LL);
v2 = (void *)ft_strjoin(&unk_2D5, *v1);
v3 = (void *)ft_strjoin(v2, &unk_2D8);
free(v2);
v4 = (void *)ft_strjoin(v3, *(_QWORD *)ptr);
free(v3);
v5 = *((_QWORD *)ptr + 1);
v6 = ft_strlen(*v1);
v7 = (void *)ft_strjoin(v4, v5 + v6 + 1);
free(v4);
free(v1);
free(ptr);
v8 = ft_strsplit(v7, 60LL);
free(v7);
return v8;
}

original_code:
char **swap_file_in(char **file)
{
 char **tmp;
 char *tmp2;
 char *tmp3;
 tmp = ft_strsplit(file[1], ' ');
 tmp2 = ft_strjoin("< " , tmp[0]);
 tmp3 = ft_strjoin(tmp2 , " ");
 free(tmp2);
 tmp2 = ft_strjoin(tmp3 , file[0]);
 free(tmp3);
 tmp3 = ft_strjoin(tmp2, file[1] + ft_strlen(tmp[0]) + 1);
 free(tmp2);
 free(tmp);
 free(file);
 file = ft_strsplit(tmp3, '<');
 free(tmp3);
 return (file);
}

variable_types:
file
char **

return_type: char **


original_code:
void assign_file_in(t_cmd *cmd)
{
 char **file;
 file = ft_strsplit(cmd->value, '<');
 cmd->sfd = 3;
 if (file[1] != ((void *)0))
  file = swap_file_in(file);
 cmd->value = ft_strtrim(file[0]);
 free(file);
 file = ft_strsplit(cmd->value, ' ');
 cmd->file = file[0];
 cmd->value = ft_strcpy(cmd->value, cmd->value + ft_strlen(file[0]));
 cmd->value = ft_strtrim(cmd->value);
 free(file);
}

canonical_original_code:
void assign_file_in(struct s_cmd *cmd)
{
 char **file;
 file = ft_strsplit(cmd->value, '<');
 cmd->sfd = 3;
 if (file[1] != ((void *)0))
  file = swap_file_in(file);
 cmd->value = ft_strtrim(file[0]);
 free(file);
 file = ft_strsplit(cmd->value, ' ');
 cmd->file = file[0];
 cmd->value = ft_strcpy(cmd->value, cmd->value + ft_strlen(file[0]));
 cmd->value = ft_strtrim(cmd->value);
 free(file);
}

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


decompiled_code:
__int64 __fastcall assign_pipe(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbp
__int64 v3; // r12
__int64 v4; // rax
_QWORD *v5; // rbp

*(_DWORD *)(a1 + 24) = 4;
v1 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 124LL);
if ( !v1[1] )
return 0xFFFFFFFFLL;
v2 = v1;
v3 = *(_QWORD *)(a1 + 8);
v4 = ft_strlen(*v1);
*(_QWORD *)(a1 + 16) = ft_strtrim(v3 + v4 + 1);
*(_QWORD *)(a1 + 8) = *v2;
free(v2);
v5 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 32LL);
*(_QWORD *)a1 = ft_strtrim(*v5);
free(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbp
__int64 v3; // r12
__int64 v4; // rax
_QWORD *v5; // rbp

*(_DWORD *)(a1 + 24) = 4;
v1 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 124LL);
if ( !v1[1] )
return 0xFFFFFFFFLL;
v2 = v1;
v3 = *(_QWORD *)(a1 + 8);
v4 = ft_strlen(*v1);
*(_QWORD *)(a1 + 16) = ft_strtrim(v3 + v4 + 1);
*(_QWORD *)(a1 + 8) = *v2;
free(v2);
v5 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 32LL);
*(_QWORD *)a1 = ft_strtrim(*v5);
free(v5);
return 0LL;
}

original_code:
int assign_pipe(t_cmd *cmd)
{
 char **cmd2;
 cmd->sfd = 4;
 cmd2 = ft_strsplit(cmd->value, '|');
 if (cmd2[1] == ((void *)0))
  return (-1);
 cmd->file = ft_strtrim(cmd->value + ft_strlen(cmd2[0]) + 1);
 cmd->value = cmd2[0];
 free(cmd2);
 cmd2 = ft_strsplit(cmd->value, ' ');
 cmd->name = ft_strtrim(cmd2[0]);
 free(cmd2);
 return (0);
}

canonical_original_code:
int assign_pipe(struct s_cmd *cmd)
{
 char **cmd2;
 cmd->sfd = 4;
 cmd2 = ft_strsplit(cmd->value, '|');
 if (cmd2[1] == ((void *)0))
  return (-1);
 cmd->file = ft_strtrim(cmd->value + ft_strlen(cmd2[0]) + 1);
 cmd->value = cmd2[0];
 free(cmd2);
 cmd2 = ft_strsplit(cmd->value, ' ');
 cmd->name = ft_strtrim(cmd2[0]);
 free(cmd2);
 return (0);
}

return_type: int

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


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

v1 = a1;
if ( !a1 )
return 0LL;
do
{
if ( ft_strchr(*(_QWORD *)(v1 + 8), 60LL) )
{
assign_file_in(v1);
}
else if ( ft_strchr(*(_QWORD *)(v1 + 8), 124LL) )
{
if ( (unsigned int)assign_pipe(v1) )
return 0xFFFFFFFFLL;
}
else if ( ft_strchr(*(_QWORD *)(v1 + 8), 62LL) )
{
if ( (unsigned int)assign_file_out(v1) )
return 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(v1 + 24) = 1;
}
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
return 0LL;
}

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

v1 = a1;
if ( !a1 )
return 0LL;
do
{
if ( ft_strchr(*(_QWORD *)(v1 + 8), 60LL) )
{
func1(v1);
}
else if ( ft_strchr(*(_QWORD *)(v1 + 8), 124LL) )
{
if ( (unsigned int)func2(v1) )
return 0xFFFFFFFFLL;
}
else if ( ft_strchr(*(_QWORD *)(v1 + 8), 62LL) )
{
if ( (unsigned int)assign_file_out(v1) )
return 0xFFFFFFFFLL;
}
else
{
*(_DWORD *)(v1 + 24) = 1;
}
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
return 0LL;
}

original_code:
int verif_fd(t_cmd *cmd)
{
 while (cmd)
 {
  if (ft_strchr(cmd->value, '<'))
  {
   assign_file_in(cmd);
  }
  else if (ft_strchr(cmd->value, '|'))
  {
   if (assign_pipe(cmd))
   return (-1);
  }
  else if (ft_strchr(cmd->value, '>'))
  {
   if (assign_file_out(cmd))
   return (-1);
  }
  else
   cmd->sfd = 1;
 cmd = cmd->next;
 }
 return (0);
}

canonical_original_code:
int verif_fd(struct s_cmd *cmd)
{
 while (cmd)
 {
  if (ft_strchr(cmd->value, '<'))
  {
   assign_file_in(cmd);
  }
  else if (ft_strchr(cmd->value, '|'))
  {
   if (assign_pipe(cmd))
   return (-1);
  }
  else if (ft_strchr(cmd->value, '>'))
  {
   if (assign_file_out(cmd))
   return (-1);
  }
  else
   cmd->sfd = 1;
 cmd = cmd->next;
 }
 return (0);
}


decompiled_code:
__int64 __fastcall ft_parse_cmd(__int64 a1)
{
void *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx

v1 = (void *)ft_strsplit(a1, 59LL);
v2 = parse_cmd(v1, 0LL);
free(v1);
v3 = clean_cmd(v2);
v4 = v3;
if ( v3 )
{
if ( (unsigned int)verif_fd(v3) )
{
ft_puterr("syntax error\n");
v4 = 0LL;
}
else
{
parse_name(v4);
}
}
else
{
ft_puterr("syntax error\n");
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
void *v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbx

v1 = (void *)ft_strsplit(a1, 59LL);
v2 = parse_cmd(v1, 0LL);
free(v1);
v3 = clean_cmd(v2);
v4 = v3;
if ( v3 )
{
if ( (unsigned int)func3(v3) )
{
ft_puterr("syntax error\n");
v4 = 0LL;
}
else
{
parse_name(v4);
}
}
else
{
ft_puterr("syntax error\n");
}
return v4;
}

original_code:
t_cmd *ft_parse_cmd(char *av)
{
 t_cmd *cmd;
 char **tmp;
 cmd = ((void *)0);
 tmp = ft_strsplit(av, ';');
 cmd = parse_cmd(tmp, cmd);
 free(tmp);
 if ((cmd = clean_cmd(cmd)) == ((void *)0))
 {
  ft_puterr("syntax error\n");
  return (((void *)0));
 }
 if (verif_fd(cmd))
 {
  ft_puterr("syntax error\n");
  return (((void *)0));
 }
 parse_name(cmd);
 return (cmd);
}

canonical_original_code:
struct s_cmd *ft_parse_cmd(char *av)
{
 struct s_cmd *cmd;
 char **tmp;
 cmd = ((void *)0);
 tmp = ft_strsplit(av, ';');
 cmd = parse_cmd(tmp, cmd);
 free(tmp);
 if ((cmd = clean_cmd(cmd)) == ((void *)0))
 {
  ft_puterr("syntax error\n");
  return (((void *)0));
 }
 if (verif_fd(cmd))
 {
  ft_puterr("syntax error\n");
  return (((void *)0));
 }
 parse_name(cmd);
 return (cmd);
}

variable_types:
av
char *

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


decompiled_code:
__int64 __fastcall ft_news(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
return ft_strdup(&unk_270);
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(ptr);
return ft_strdup(&unk_270);
}

original_code:
char *ft_news(char **tmp)
{
 free(tmp[0]);
 free(tmp[1]);
 free(tmp);
 return (ft_strdup("/"));
}

return_type: char *


decompiled_code:
void __fastcall ft_destroy(void *ptr)
{
void *v2; // rdi
char *v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (char *)ptr + 8;
do
{
free(v2);
v3 += 8;
v2 = (void *)*((_QWORD *)v3 - 1);
}
while ( v2 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
char *v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (char *)ptr + 8;
do
{
free(v2);
v3 += 8;
v2 = (void *)*((_QWORD *)v3 - 1);
}
while ( v2 );
}
free(ptr);
}
}

original_code:
void ft_destroy(char **tmp)
{
 int i;
 i = 0;
 if (tmp)
 {
  while (tmp[i])
  {
   free(tmp[i]);
   i++;
  }
  free(tmp);
 }
}


original_code:
char *ft_trim(char *s)
{
 char **tmp;
 int i;
 tmp = ft_strsplit(s, '/');
 if ((i = 0) == 0 && tmp[1] && ft_strcmp(tmp[1], "..") == 0 && !tmp[2])
  return (ft_news(tmp));
 while (tmp[i] && ft_strcmp(tmp[i], "..") != 0)
  i++;
 if (i != 0 && tmp[i])
 {
  while (tmp[i + 1])
  {
   free(tmp[i - 1]);
   tmp[i - 1] = ft_strdup(tmp[i + 1]);
   i++;
  }
  free(tmp[i - 1]);
  tmp[i - 1] = '\0';
  free(tmp[i]);
  free (s);
  s = ft_glue(tmp);
  s = ft_trim(s);
 }
 ft_destroy(tmp);
 return (s);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall ft_pwd(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 result; // rax

v2 = (int)ft_found(&unk_275, a1);
result = ft_strncmp(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2), "PWD=", 4LL);
if ( !(_DWORD)result )
return ft_dprintf(*(unsigned int *)(a2 + 12), "%s\n", (const char *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2) + 4LL));
*(_DWORD *)(a1 + 48) = 14;
return result;
}

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

v2 = (int)ft_found(&unk_275, a1);
result = ft_strncmp(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2), "PWD=", 4LL);
if ( !(_DWORD)result )
return ft_dprintf(*(unsigned int *)(a2 + 12), "%s\n", (const char *)(*(_QWORD *)(*(_QWORD *)a1 + 8 * v2) + 4LL));
*(_DWORD *)(a1 + 48) = 14;
return result;
}

original_code:
void ft_pwd(t_gen *env, t_process *p)
{
 int i;
 i = ft_found("PWD", env);
 if (ft_strncmp(env->env[i], "PWD=", 4) == 0)
  ft_dprintf(p->fd[1], "%s\n", (env->env[i] + 4));
 else
  env->ret = 14;
}

canonical_original_code:
void ft_pwd(struct s_gen *env, struct s_process *p)
{
 int i;
 i = ft_found("PWD", env);
 if (ft_strncmp(env->env[i], "PWD=", 4) == 0)
  ft_dprintf(p->fd[1], "%s\n", (env->env[i] + 4));
 else
  env->ret = 14;
}

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

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


original_code:
void press_quote(t_term *term)
{
 if (term->quote == 0
  && term->hist->buff[term->hist->pose_cursor - 1] != 92)
 {
  term->quote = 1;
 }
 else if (term->quote == 1
  && term->hist->buff[term->hist->pose_cursor - 1] != 92)
 {
  term->quote = 0;
 }
}

canonical_original_code:
void press_quote(struct s_term *term)
{
 if (term->quote == 0
  && term->hist->buff[term->hist->pose_cursor - 1] != 92)
 {
  term->quote = 1;
 }
 else if (term->quote == 1
  && term->hist->buff[term->hist->pose_cursor - 1] != 92)
 {
  term->quote = 0;
 }
}

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


original_code:
void press_dquote(t_term *term)
{
 if (term->dquote == 0
  && term->hist->buff[term->hist->pose_cursor - 1] != 92)
 {
  term->dquote = 1;
 }
 else if (term->dquote == 1
  && term->hist->buff[term->hist->pose_cursor - 1] != 92)
 {
  term->dquote = 0;
 }
}

canonical_original_code:
void press_dquote(struct s_term *term)
{
 if (term->dquote == 0
  && term->hist->buff[term->hist->pose_cursor - 1] != 92)
 {
  term->dquote = 1;
 }
 else if (term->dquote == 1
  && term->hist->buff[term->hist->pose_cursor - 1] != 92)
 {
  term->dquote = 0;
 }
}

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_hist { char value[4096]; int pose_cursor; int len; int modif; char buff[4096]; int exec; struct s_hist *next; struct s_hist *prev; }


decompiled_code:
__int64 __fastcall ft_print_env(_QWORD *a1)
{
__int64 result; // rax
_QWORD *v2; // rbx

result = (__int64)a1;
if ( *a1 )
{
v2 = a1 + 1;
do
{
result = ft_putendl();
++v2;
}
while ( *(v2 - 1) );
}
return result;
}

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

result = (__int64)a1;
if ( *a1 )
{
v2 = a1 + 1;
do
{
result = ft_putendl();
++v2;
}
while ( *(v2 - 1) );
}
return result;
}

original_code:
void ft_print_env(char **envp)
{
 int i;
 i = 0;
 while (envp[i] != ((void *)0))
 {
  ft_putendl(envp[i]);
  i++;
 }
}

variable_types:
envp
char **


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

v2 = a2;
result = *a2;
if ( *a2 )
{
while ( 1 )
{
v4 = ft_strlen(a1);
if ( !(unsigned int)ft_strncmp(*v2, a1, v4) )
break;
result = *++v2;
if ( !*v2 )
return result;
}
result = ft_strstr(*v2, a1);
}
return result;
}

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

v2 = a2;
result = *a2;
if ( *a2 )
{
while ( 1 )
{
v4 = ft_strlen(a1);
if ( !(unsigned int)ft_strncmp(*v2, a1, v4) )
break;
result = *++v2;
if ( !*v2 )
return result;
}
result = ft_strstr(*v2, a1);
}
return result;
}

original_code:
char *get_var_env(char *var, char **envp)
{
 char *find;
 int i;
 i = 0;
 while (envp[i])
 {
  find = ((void *)0);
  if ((ft_strncmp(envp[i], var, ft_strlen(var))) == 0)
  {
   find = ft_strstr(envp[i], var);
   break ;
  }
  i++;
 }
 return (find);
}

variable_types:
var
char *

variable_types:
find
char *


decompiled_code:
int __fastcall ft_parents(int *a1, __int64 a2, char *const *a3, _QWORD *a4)
{
__int64 v6; // rbx
int result; // eax
char **v8; // rax

v6 = (unsigned int)open(*(const char **)(a2 + 32), 578, 420LL);
result = ft_puterr("open file2 fail\n", v6);
if ( result != -1 )
{
close(a1[1]);
dup2(*a1, 0);
dup2(v6, 1);
close(*a1);
v8 = (char **)ft_strsplit(*(_QWORD *)(a2 + 24), 32LL);
result = sh_execute(v8, a4, a3);
if ( result )
{
close(v6);
result = wait(0LL);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int *a1, __int64 a2, char *const *a3, _QWORD *a4)
{
__int64 v6; // rbx
int result; // eax
char **v8; // rax

v6 = (unsigned int)open(*(const char **)(a2 + 32), 578, 420LL);
result = ft_puterr("open file2 fail\n", v6);
if ( result != -1 )
{
close(a1[1]);
dup2(*a1, 0);
dup2(v6, 1);
close(*a1);
v8 = (char **)ft_strsplit(*(_QWORD *)(a2 + 24), 32LL);
result = func0(v8, a4, a3);
if ( result )
{
close(v6);
result = wait(0LL);
}
}
return result;
}

original_code:
void ft_parents(int fd[2], char **av, char **env, char **path)
{
 int file_d;
 file_d = open(av[4], 02 | 0100 | 01000, 0644);
 if (ft_puterr("open file2 fail\n", file_d) == -1)
  return ;
 close(fd[1]);
 dup2(fd[0], 0);
 dup2(file_d, 1);
 close(fd[0]);
 if (!sh_execute(ft_strsplit(av[3], ' '), path, env))
  return ;
 close(file_d);
 wait(((void *)0));
}

variable_types:
fd
int [2]

variable_types:
env
char **

variable_types:
path
char **


decompiled_code:
int __fastcall ft_pipex(__int64 a1, char *const *a2, _QWORD *a3, int a4)
{
int v6; // eax
int result; // eax
unsigned int v8; // er14
char **v9; // rax
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

v6 = pipe(pipedes);
result = ft_puterr("pipe fail\n", v6 == -1);
if ( !result )
{
v8 = fork();
result = ft_puterr("fork fail\n", v8);
if ( result != -1 )
{
if ( v8 )
{
dup2(a4, 0);
close(a4);
close(pipedes[0]);
dup2(pipedes[1], 1);
close(pipedes[1]);
v9 = (char **)ft_strsplit(*(_QWORD *)(a1 + 16), 32LL);
result = sh_execute(v9, a3, a2);
if ( result )
result = wait(0LL);
}
else
{
result = ft_parents(pipedes, a1, a2, a3);
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, char *const *a2, _QWORD *a3, int a4)
{
int v6; // eax
int result; // eax
unsigned int v8; // er14
char **v9; // rax
int pipedes[2]; // [rsp+8h] [rbp-30h] BYREF

v6 = pipe(pipedes);
result = ft_puterr("pipe fail\n", v6 == -1);
if ( !result )
{
v8 = fork();
result = ft_puterr("fork fail\n", v8);
if ( result != -1 )
{
if ( v8 )
{
dup2(a4, 0);
close(a4);
close(pipedes[0]);
dup2(pipedes[1], 1);
close(pipedes[1]);
v9 = (char **)ft_strsplit(*(_QWORD *)(a1 + 16), 32LL);
result = func0(v9, a3, a2);
if ( result )
result = wait(0LL);
}
else
{
result = func1(pipedes, a1, a2, a3);
}
}
}
return result;
}

original_code:
void ft_pipex(char **av, char **env, char **path, int in)
{
 int fd[2];
 int pid;
 if (ft_puterr("pipe fail\n", pipe(fd) == -1))
  return ;
 if (ft_puterr("fork fail\n", (pid = fork())) == -1)
  return ;
 if (pid == 0)
  ft_parents(fd, av, env, path);
 else
 {
  dup2(in, 0);
  close(in);
  close(fd[0]);
  dup2(fd[1], 1);
  close(fd[1]);
  if (!sh_execute(ft_strsplit(av[2], ' '), path, env))
   return ;
  wait(((void *)0));
 }
}

variable_types: in int

variable_types: pid int


original_code:
char **ft_path(char **env)
{
 int i;
 int j;
 char *tmp;
 char **path;
 i = 0;
 j = 0;
 while (env[i])
 {
  if (!ft_strncmp(env[i], "PATH=", 5))
  {
   tmp = ft_strjoin(env[i] + 5, ":./");
   path = ft_strsplit(tmp, ':');
   free(tmp);
   while (path[j] != 0)
   {
    tmp = ft_strjoin(path[j], "/");
    free(path[j]);
    path[j] = tmp;
    j++;
   }
  }
  i++;
 }
 return (path);
}

variable_types: j int

variable_types:
tmp
char *


decompiled_code:
__int64 __fastcall sh_execute(char **argv, _QWORD *a2, char *const *a3)
{
const char *v6; // rax
int v7; // eax

do
{
if ( !*(_BYTE *)*a2 )
return 1LL;
v6 = (const char *)ft_strjoin(*a2, *argv);
v7 = execve(v6, argv, a3);
if ( !v7 )
return 1LL;
if ( !a2[1] && **argv )
{
if ( execve(*argv, argv, a3) )
{
ft_puterr("pipex : command invalide : ", 0xFFFFFFFFLL);
ft_puterr(*argv, 0xFFFFFFFFLL);
ft_puterr("\n", 0xFFFFFFFFLL);
return 0LL;
}
return 1LL;
}
++a2;
}
while ( v7 < 0 );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **argv, _QWORD *a2, char *const *a3)
{
const char *v6; // rax
int v7; // eax

do
{
if ( !*(_BYTE *)*a2 )
return 1LL;
v6 = (const char *)ft_strjoin(*a2, *argv);
v7 = execve(v6, argv, a3);
if ( !v7 )
return 1LL;
if ( !a2[1] && **argv )
{
if ( execve(*argv, argv, a3) )
{
ft_puterr("pipex : command invalide : ", 0xFFFFFFFFLL);
ft_puterr(*argv, 0xFFFFFFFFLL);
ft_puterr("\n", 0xFFFFFFFFLL);
return 0LL;
}
return 1LL;
}
++a2;
}
while ( v7 < 0 );
return 1LL;
}

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

variable_types:
av
char **

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v5; // r13
unsigned int v6; // er12

if ( argc == 5 )
{
v5 = (_QWORD *)ft_path(envp);
v6 = open(argv[1], 0);
if ( (unsigned int)ft_puterr("open file1 fail\n", v6) != -1 )
ft_pipex((__int64)argv, (char *const *)envp, v5, v6);
}
else
{
ft_puterr("usage : ./pipex file1 cmd1 cmd2 file2\n", 0xFFFFFFFFLL);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
_QWORD *v5; // r13
unsigned int v6; // er12

if ( argc == 5 )
{
v5 = (_QWORD *)func3(envp);
v6 = open(argv[1], 0);
if ( (unsigned int)ft_puterr("open file1 fail\n", v6) != -1 )
func2((__int64)argv, (char *const *)envp, v5, v6);
}
else
{
ft_puterr("usage : ./pipex file1 cmd1 cmd2 file2\n", 0xFFFFFFFFLL);
}
return 0;
}

original_code:
int main(int ac, char **av, char **env)
{
 char **path;
 int in;
 if (ac != 5)
  ft_puterr("usage : ./pipex file1 cmd1 cmd2 file2\n", -1);
 else
 {
  path = ft_path(env);
  if (ft_puterr("open file1 fail\n", (in = open(av[1], 00))) != -1)
   ft_pipex(av, env, path, in);
 }
 return (0);
}

variable_types: ac int


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

result = a1;
if ( a1 - 65 < 0x1A )
result = a1 + 32;
return result;
}

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

result = a1;
if ( a1 - 65 < 0x1A )
result = a1 + 32;
return result;
}

original_code:
int ft_tolower(int c)
{
 if (c <= 90 && c >= 65 && c)
 {
  return (c + 32);
 }
 else
 {
  return (c);
 }
}

variable_types: c int


decompiled_code:
void __fastcall ft_lstdelone(void **a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
if ( a1 )
{
if ( a2 )
{
a2(*(_QWORD *)*a1, *((_QWORD *)*a1 + 1));
free(*a1);
*a1 = 0LL;
}
}
}

canonical_decompiled_code:
void __fastcall func0(void **a1, void (__fastcall *a2)(_QWORD, _QWORD))
{
if ( a1 )
{
if ( a2 )
{
a2(*(_QWORD *)*a1, *((_QWORD *)*a1 + 1));
free(*a1);
*a1 = 0LL;
}
}
}

original_code:
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
{
 if (alst && del)
 {
  (*del)((*alst)->content, (*alst)->content_size);
  free(*alst);
  *alst = ((void *)0);
 }
}

canonical_original_code:
void ft_lstdelone(struct s_list **alst, void (*del)(void *, unsigned long))
{
 if (alst && del)
 {
  (*del)((*alst)->content, (*alst)->content_size);
  free(*alst);
  *alst = ((void *)0);
 }
}

variable_types: struct s_list { void *content; unsigned long content_size; struct s_list *next; } **

variable_types:
del
void (*)(void *, unsigned long)


decompiled_code:
__int64 __fastcall get_word_str(unsigned __int8 **a1, unsigned __int8 *a2)
{
unsigned int v3; // er12
unsigned __int8 *v4; // rcx
int v5; // ebp
char v6; // al
unsigned __int8 *v7; // rax
signed __int8 v9; // di
unsigned __int8 *v10; // r14
char v11; // al
unsigned __int8 *v12; // rax

v3 = check_quote(a1);
if ( (char)v3 <= 0 )
{
v9 = **a1;
if ( v9 )
{
v10 = a2;
v5 = 0;
do
{
if ( !(unsigned int)is_ok_char((unsigned int)v9) || (unsigned int)is_op_char((unsigned int)(char)**a1) )
break;
v11 = **a1;
if ( v11 == 10 )
v11 = 32;
**a1 = v11;
v12 = *a1;
if ( **a1 == 92 )
v12 = a1[1];
*a1 = v12 + 1;
++v5;
*v10 = *v12;
v9 = **a1;
++v10;
}
while ( v9 );
}
else
{
v5 = 0;
}
}
else
{
v4 = a2;
v5 = 0;
do
{
v6 = **a1;
if ( !v6 )
break;
if ( v6 == 10 )
v6 = 32;
**a1 = v6;
v7 = (*a1)++;
++v5;
LOBYTE(v7) = *v7;
*v4++ = (unsigned __int8)v7;
}
while ( (_BYTE)v7 != (_BYTE)v3 || v5 == 1 );
}
a2[v5] = 0;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 **a1, unsigned __int8 *a2)
{
unsigned int v3; // er12
unsigned __int8 *v4; // rcx
int v5; // ebp
char v6; // al
unsigned __int8 *v7; // rax
signed __int8 v9; // di
unsigned __int8 *v10; // r14
char v11; // al
unsigned __int8 *v12; // rax

v3 = func0(a1);
if ( (char)v3 <= 0 )
{
v9 = **a1;
if ( v9 )
{
v10 = a2;
v5 = 0;
do
{
if ( !(unsigned int)is_ok_char((unsigned int)v9) || (unsigned int)is_op_char((unsigned int)(char)**a1) )
break;
v11 = **a1;
if ( v11 == 10 )
v11 = 32;
**a1 = v11;
v12 = *a1;
if ( **a1 == 92 )
v12 = a1[1];
*a1 = v12 + 1;
++v5;
*v10 = *v12;
v9 = **a1;
++v10;
}
while ( v9 );
}
else
{
v5 = 0;
}
}
else
{
v4 = a2;
v5 = 0;
do
{
v6 = **a1;
if ( !v6 )
break;
if ( v6 == 10 )
v6 = 32;
**a1 = v6;
v7 = (*a1)++;
++v5;
LOBYTE(v7) = *v7;
*v4++ = (unsigned __int8)v7;
}
while ( (_BYTE)v7 != (_BYTE)v3 || v5 == 1 );
}
a2[v5] = 0;
return v3;
}

original_code:
static char get_word_str(char **str, char *token_str)
{
 int i;
 char quote;
 i = 0;
 if ((quote = check_quote(str)) > 0)
 {
  while (**str)
  {
   **str = (**str == 0x0a) ? ' ' : **str;
   token_str[i++] = *(*str)++;
   if (i != 1 && token_str[i - 1] == quote)
    break ;
  }
 }
 else
 {
  while (**str && is_ok_char(**str) && !is_op_char(**str))
  {
   **str = (**str == 0x0a) ? ' ' : **str;
   *str = (**str == '\\') ? *(str + 1) : (*str);
   token_str[i++] = *(*str)++;
  }
 }
 token_str[i] = '\0';
 return (quote);
}

variable_types:
str
char **

variable_types: quote char

return_type: char


decompiled_code:
__int64 __fastcall get_token(unsigned __int8 **a1)
{
__int64 v1; // rax
__int64 v2; // rbx
unsigned int v3; // eax
unsigned __int8 *v5; // [rsp+8h] [rbp-20h] BYREF

v5 = (unsigned __int8 *)malloc(0x401uLL);
v1 = create_token();
if ( !v1 )
return 0LL;
v2 = v1;
if ( !v5 )
return 0LL;
ft_memset(v5, 0LL, 1025LL);
v3 = get_token_type(*a1);
*(_DWORD *)v2 = v3;
if ( v3 == 11 )
return 0LL;
if ( v3 == 9 )
{
if ( (unsigned __int8)get_word_str(a1, v5) )
++*a1;
}
else
{
get_op_str(a1, v3, v5);
}
*(_QWORD *)(v2 + 8) = ft_strdup(v5);
if ( v5 )
ft_strdel(&v5);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 **a1)
{
__int64 v1; // rax
__int64 v2; // rbx
unsigned int v3; // eax
unsigned __int8 *v5; // [rsp+8h] [rbp-20h] BYREF

v5 = (unsigned __int8 *)malloc(0x401uLL);
v1 = create_token();
if ( !v1 )
return 0LL;
v2 = v1;
if ( !v5 )
return 0LL;
ft_memset(v5, 0LL, 1025LL);
v3 = get_token_type(*a1);
*(_DWORD *)v2 = v3;
if ( v3 == 11 )
return 0LL;
if ( v3 == 9 )
{
if ( (unsigned __int8)func1(a1, v5) )
++*a1;
}
else
{
get_op_str(a1, v3, v5);
}
*(_QWORD *)(v2 + 8) = ft_strdup(v5);
if ( v5 )
ft_strdel(&v5);
return v2;
}

original_code:
t_token *get_token(char **str)
{
 char *token_str;
 t_token *token;
 int i;
 token_str = (char *)malloc(sizeof(char) * 1025);
 token = create_token();
 if (!token || !token_str || (i = 0))
  return (((void *)0));
 ft_memset(token_str, 0, 1025);
 token->type = get_token_type(*str);
 if (token->type == unknown)
  return (((void *)0));
 else if (token->type != word)
  get_op_str(str, token->type, token_str);
 else if (get_word_str(str, token_str))
  (*str)++;
 token->str = ft_strdup(token_str);
 if (token_str)
  ft_strdel(&token_str);
 return (token);
}

canonical_original_code:
struct s_token *get_token(char **str)
{
 char *token_str;
 struct s_token *token;
 int i;
 token_str = (char *)malloc(sizeof(char) * 1025);
 token = create_token();
 if (!token || !token_str || (i = 0))
  return (((void *)0));
 ft_memset(token_str, 0, 1025);
 token->type = get_token_type(*str);
 if (token->type == unknown)
  return (((void *)0));
 else if (token->type != word)
  get_op_str(str, token->type, token_str);
 else if (get_word_str(str, token_str))
  (*str)++;
 token->str = ft_strdup(token_str);
 if (token_str)
  ft_strdel(&token_str);
 return (token);
}

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

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


decompiled_code:
__int64 __fastcall get_token_lst(unsigned __int8 *a1)
{
__int64 v1; // rbx
unsigned __int8 *v2; // rax
char v3; // dl
__int64 v4; // rdi
unsigned __int8 *v6; // [rsp+8h] [rbp-10h] BYREF

v6 = a1;
if ( !*a1 )
return 0LL;
v1 = 0LL;
do
{
v4 = get_token(&v6);
if ( !v4 )
break;
v1 = token_lst_add(v4, v1);
if ( *v6 == 32 || *v6 == 9 )
{
v2 = v6 + 1;
do
{
do
{
v6 = v2;
v3 = *v2++;
}
while ( v3 == 32 );
}
while ( v3 == 9 );
}
}
while ( *v6 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1)
{
__int64 v1; // rbx
unsigned __int8 *v2; // rax
char v3; // dl
__int64 v4; // rdi
unsigned __int8 *v6; // [rsp+8h] [rbp-10h] BYREF

v6 = a1;
if ( !*a1 )
return 0LL;
v1 = 0LL;
do
{
v4 = func2(&v6);
if ( !v4 )
break;
v1 = token_lst_add(v4, v1);
if ( *v6 == 32 || *v6 == 9 )
{
v2 = v6 + 1;
do
{
do
{
v6 = v2;
v3 = *v2++;
}
while ( v3 == 32 );
}
while ( v3 == 9 );
}
}
while ( *v6 );
return v1;
}

original_code:
t_token *get_token_lst(char *str)
{
 t_token *token_list;
 t_token *new_token;
 token_list = ((void *)0);
 while (*str != '\0')
 {
  new_token = ((void *)0);
  if (!(new_token = get_token(&str)))
   return (token_list);
  token_list = token_lst_add(new_token, token_list);
  while (*str == ' ' || *str == '\t')
   str++;
 }
 return (token_list);
}

canonical_original_code:
struct s_token *get_token_lst(char *str)
{
 struct s_token *token_list;
 struct s_token *new_token;
 token_list = ((void *)0);
 while (*str != '\0')
 {
  new_token = ((void *)0);
  if (!(new_token = get_token(&str)))
   return (token_list);
  token_list = token_lst_add(new_token, token_list);
  while (*str == ' ' || *str == '\t')
   str++;
 }
 return (token_list);
}

variable_types:
str
char *

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


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

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

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

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

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

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

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

variable_types:
cmd
struct s_cmd *

variable_types: ret int

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

variable_types:
buff
char [6]


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

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


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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
name
char *

variable_types:
path
char **


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

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

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

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

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

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

variable_types:
av
char **


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

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

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

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

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

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

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


decompiled_code:
__int64 return_env()
{
if ( !env_0 )
env_0 = (__int64)malloc(0x1030uLL);
return env_0;
}

canonical_decompiled_code:
__int64 func3()
{
if ( !env_0 )
env_0 = (__int64)malloc(0x1030uLL);
return env_0;
}

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

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

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


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

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

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

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

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

variable_types:
env
char **

variable_types:
search
char *

variable_types: i int

variable_types: len int


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

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

variable_types:
ret
char **


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

if ( argc && argv )
v3 = return_env();
*(_QWORD *)(v3 + 4128) = envp;
*(_DWORD *)(v3 + 4136) = 0;
copy_env(v3, argv);
parse_environ(v3);
start();
return 0;
}

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

if ( argc && argv )
v3 = func3();
*(_QWORD *)(v3 + 4128) = envp;
*(_DWORD *)(v3 + 4136) = 0;
copy_env(v3, argv);
parse_environ(v3);
start();
return 0;
}

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

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

variable_types: ac int

variable_types:
environ
char **


decompiled_code:
void *ft_init_sig()
{
if ( first_time_1 )
{
first_time_1 = 0;
dword_258 = tgetnum("co");
dword_25C = tgetnum("li");
qword_268 = 0LL;
}
return &sig_0;
}

canonical_decompiled_code:
void *func0()
{
if ( first_time_1 )
{
first_time_1 = 0;
dword_258 = tgetnum("co");
dword_25C = tgetnum("li");
qword_268 = 0LL;
}
return &sig_0;
}

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
sig
struct s_sig *

variable_types:
termtype
char *

variable_types:
buffer
char [2048]

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


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

v2 = 0;
while ( *a1 )
{
for ( i = *a1; *a1 == a2 && i; i = *a1 )
++a1;
for ( v2 -= (i == 0) - 1; *a1 != a2 && *a1; ++a1 )
;
}
return v2;
}

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

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

variable_types:
s
char *

variable_types: c char

variable_types:
nbword
unsigned int

return_type: unsigned int


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

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

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

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

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

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

variable_types:
i
unsigned int

variable_types:
len
unsigned int


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

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

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

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

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

variable_types:
s
char **


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

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

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


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

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

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

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

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

variable_types:
av
char **

variable_types:
path
char **

variable_types:
env
char **

variable_types: i int

variable_types:
tmp
char *


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

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

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

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

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

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

variable_types:
file
char *

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

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


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

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

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

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

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

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

variable_types: input int


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

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

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

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

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

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

variable_types:
fd
int [2]


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

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

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

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

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

variable_types: y int

variable_types: first int


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

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

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

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

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

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

variable_types: x int

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


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

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

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

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

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

variable_types: winner int


play

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

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

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

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

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

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

variable_types: player int


main

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

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

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

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

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

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

variable_types: ac int


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

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

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


decompiled_code:
void free_gen()
{
void *v0; // rax

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

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

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

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

canonical_original_code:
void free_gen()
{
 struct s_gen *gen;
 gen = recup_gen();
 free(gen);
 gen = ((void *)0);
}

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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


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

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


clearmap

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

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

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

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


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

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

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

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

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


strror

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

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

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

result = "malloc error";
if ( a1 != 1 )
{
result = "too many arguments";
if ( a1 != 2 )
{
result = "missing argument";
if ( a1 != 3 )
{
result = "permission denied";
if ( a1 != 4 )
{
result = "no such a file or directory";
if ( a1 != 5 )
{
result = "file already exists";
if ( a1 != 6 )
{
result = "bad file descriptor";
if ( a1 != 7 )
{
result = "fork error";
if ( a1 != 8 )
{
result = "not a directory";
if ( a1 != 9 )
{
result = "is a directory";
if ( a1 != 10 )
{
result = "wrong type of argument";
if ( a1 != 11 )
result = func0(a1);
}
}
}
}
}
}
}
}
}
}
return result;
}

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


error

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

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

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

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

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

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

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


decompiled_code:
__int64 __fastcall create_serv(__int16 a1)
{
struct protoent *v1; // rbx
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func3(__int16 a1)
{
struct protoent *v1; // rbx
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-28h] BYREF

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

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

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

variable_types: port int

variable_types: sock int

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

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


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

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

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

variable_types: cs int


decompiled_code:
int __fastcall fork_child(int fd)
{
int v1; // eax
char v3[4096]; // [rsp+0h] [rbp-1408h] BYREF
char buf[1032]; // [rsp+1000h] [rbp-408h] BYREF

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

canonical_decompiled_code:
int __fastcall func5(int fd)
{
int v1; // eax
char v3[4096]; // [rsp+0h] [rbp-1408h] BYREF
char buf[1032]; // [rsp+1000h] [rbp-408h] BYREF

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

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

variable_types: ret int

variable_types:
buff
char [1024]

variable_types:
pwd
char [4096]


usage

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

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

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

variable_types:
name
char *


main

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

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

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

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

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

variable_types:
av
char **

variable_types:
cslen
unsigned int


mystrlen

decompiled_code:
__int64 __fastcall mystrlen(_BYTE *a1)
{
unsigned __int64 v1; // rax
unsigned int v2; // edx
__int64 v3; // rcx

v1 = (unsigned __int8)*a1;
if ( (unsigned __int8)v1 > 0x27u )
{
v2 = 0;
}
else
{
v2 = 0;
v3 = 0x8400000001LL;
if ( _bittest64(&v3, v1) )
return v2;
}
do
{
++a1;
if ( (_BYTE)v1 == 32 )
break;
++v2;
LOBYTE(v1) = *a1;
}
while ( *a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
unsigned __int64 v1; // rax
unsigned int v2; // edx
__int64 v3; // rcx

v1 = (unsigned __int8)*a1;
if ( (unsigned __int8)v1 > 0x27u )
{
v2 = 0;
}
else
{
v2 = 0;
v3 = 0x8400000001LL;
if ( _bittest64(&v3, v1) )
return v2;
}
do
{
++a1;
if ( (_BYTE)v1 == 32 )
break;
++v2;
LOBYTE(v1) = *a1;
}
while ( *a1 );
return v2;
}

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

variable_types:
s
char *

variable_types:
size
unsigned int

variable_types: quote char


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

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

variable_types:
lst
struct s_job *

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

user_defined_types: struct s_job { struct s_token *token_lst; char need_success; struct s_process *first_process; struct s_job *next; struct s_job *prev; }


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

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

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

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

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

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

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

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

variable_types:
max
int *

variable_types:
act
int *

variable_types: i int

variable_types: x int

variable_types: y int

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