original_code:
int assign_file_out(t_cmd *cmd)
{
 char **file;
 if (ft_strstr(cmd->value, ">>") == ((void *)0))
  cmd->sfd = 2;
 else
  cmd->sfd = 6;
 file = ft_strsplit(cmd->value, '>');
 cmd->value = file[0];
 if (file[1])
  cmd->file = ft_strtrim(file[1]);
 else
  return (-1);
 free(file);
 file = ft_strsplit(cmd->value, ' ');
 cmd->name = ft_strtrim(file[0]);
 free(file);
 return (0);
}

canonical_original_code:
int assign_file_out(struct s_cmd *cmd)
{
 char **file;
 if (ft_strstr(cmd->value, ">>") == ((void *)0))
  cmd->sfd = 2;
 else
  cmd->sfd = 6;
 file = ft_strsplit(cmd->value, '>');
 cmd->value = file[0];
 if (file[1])
  cmd->file = ft_strtrim(file[1]);
 else
  return (-1);
 free(file);
 file = ft_strsplit(cmd->value, ' ');
 cmd->name = ft_strtrim(file[0]);
 free(file);
 return (0);
}

variable_types:
file
char **


decompiled_code:
__int64 __fastcall check_exp(__int64 a1)
{
unsigned int v1; // eax

if ( !a1 )
return parse_error(*(_QWORD *)(a1 + 8));
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 9 )
return check_command();
if ( v1 <= 3 )
return check_redir();
if ( v1 != 8 )
return parse_error(*(_QWORD *)(a1 + 8));
return check_colon();
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // eax

if ( !a1 )
return parse_error(*(_QWORD *)(a1 + 8));
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 9 )
return func4();
if ( v1 <= 3 )
return func3();
if ( v1 != 8 )
return parse_error(*(_QWORD *)(a1 + 8));
return func1();
}

original_code:
t_bool check_exp(t_token *token_lst)
{
 if (token_lst)
 {
  if (token_lst->type == word)
   return (check_command(token_lst));
  else if (token_lst->type == redir_in || token_lst->type == redir_out || token_lst->type == redir_err || token_lst->type == append)
   return (check_redir(token_lst));
  else if (token_lst->type == colon)
   return (check_colon(token_lst));
 }
 return (parse_error(token_lst->str));
}

canonical_original_code:
enum e_bool check_exp(struct s_token *token_lst)
{
 if (token_lst)
 {
  if (token_lst->type == word)
   return (check_command(token_lst));
  else if (token_lst->type == redir_in || token_lst->type == redir_out || token_lst->type == redir_err || token_lst->type == append)
   return (check_redir(token_lst));
  else if (token_lst->type == colon)
   return (check_colon(token_lst));
 }
 return (parse_error(token_lst->str));
}

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

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

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


decompiled_code:
__int64 __fastcall check_colon(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

if ( *(_DWORD *)a1 != 8 )
return parse_error(*(_QWORD *)(a1 + 8));
v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
result = check_exp(v1);
else
result = 1LL;
return result;
}

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

if ( *(_DWORD *)a1 != 8 )
return parse_error(*(_QWORD *)(a1 + 8));
v1 = *(_QWORD *)(a1 + 16);
if ( v1 )
result = func0(v1);
else
result = 1LL;
return result;
}

original_code:
t_bool check_colon(t_token *token_lst)
{
 if (token_lst->type == colon)
 {
  if (token_lst->next)
   return (check_exp(token_lst->next));
  return (TRUE);
 }
 return (parse_error(token_lst->str));
}

canonical_original_code:
enum e_bool check_colon(struct s_token *token_lst)
{
 if (token_lst->type == colon)
 {
  if (token_lst->next)
   return (check_exp(token_lst->next));
  return (TRUE);
 }
 return (parse_error(token_lst->str));
}

user_defined_types: enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 }


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

if ( *(_DWORD *)a1 == 4 && *(_QWORD *)(a1 + 16) )
result = check_exp(*(_QWORD *)(a1 + 16));
else
result = parse_error(*(_QWORD *)(a1 + 8));
return result;
}

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

if ( *(_DWORD *)a1 == 4 && *(_QWORD *)(a1 + 16) )
result = func0(*(_QWORD *)(a1 + 16));
else
result = parse_error(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
t_bool check_pipe(t_token *token_lst)
{
 if (token_lst->type == pipes)
 {
  if (token_lst->next)
   return (check_exp(token_lst->next));
  return (parse_error(token_lst->str));
 }
 return (parse_error(token_lst->str));
}

canonical_original_code:
enum e_bool check_pipe(struct s_token *token_lst)
{
 if (token_lst->type == pipes)
 {
  if (token_lst->next)
   return (check_exp(token_lst->next));
  return (parse_error(token_lst->str));
 }
 return (parse_error(token_lst->str));
}


decompiled_code:
__int64 __fastcall check_redir(__int64 a1)
{
__int64 v1; // rax
int *v2; // rdi
int v3; // eax

if ( *(_DWORD *)a1 == 4 )
return parse_error(*(_QWORD *)(a1 + 8));
if ( (unsigned int)is_redir_operator(*(_QWORD *)(a1 + 8)) == 11 )
return parse_error(*(_QWORD *)(a1 + 8));
v1 = *(_QWORD *)(a1 + 16);
if ( !v1 || *(_DWORD *)v1 != 10 )
return parse_error(*(_QWORD *)(a1 + 8));
v2 = *(int **)(v1 + 16);
if ( !v2 )
return 1LL;
v3 = *v2;
if ( *v2 == 4 )
return check_pipe((__int64)v2);
if ( v3 == 8 )
return check_colon((__int64)v2);
if ( (unsigned int)(v3 - 5) <= 1 )
return check_logical();
if ( v3 != 7 )
return 1LL;
return check_background();
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 v1; // rax
int *v2; // rdi
int v3; // eax

if ( *(_DWORD *)a1 == 4 )
return parse_error(*(_QWORD *)(a1 + 8));
if ( (unsigned int)is_redir_operator(*(_QWORD *)(a1 + 8)) == 11 )
return parse_error(*(_QWORD *)(a1 + 8));
v1 = *(_QWORD *)(a1 + 16);
if ( !v1 || *(_DWORD *)v1 != 10 )
return parse_error(*(_QWORD *)(a1 + 8));
v2 = *(int **)(v1 + 16);
if ( !v2 )
return 1LL;
v3 = *v2;
if ( *v2 == 4 )
return func2((__int64)v2);
if ( v3 == 8 )
return func1((__int64)v2);
if ( (unsigned int)(v3 - 5) <= 1 )
return check_logical();
if ( v3 != 7 )
return 1LL;
return check_background();
}

original_code:
t_bool check_redir(t_token *token_lst)
{
 if (token_lst->type != pipes
   && is_redir_operator(token_lst->str) != unknown)
 {
  if (token_lst->next && token_lst->next->type == redir_dest)
  {
   if (token_lst->next->next)
   {
    if (token_lst->next->next->type == pipes)
     return (check_pipe(token_lst->next->next));
    else if (token_lst->next->next->type == colon)
     return (check_colon(token_lst->next->next));
    else if (token_lst->next->next->type == log_and
      || token_lst->next->next->type == log_or)
     return (check_logical(token_lst->next->next));
    else if (token_lst->next->next->type == bg)
     return (check_background(token_lst->next->next));
   }
   return (TRUE);
  }
  return (parse_error(token_lst->str));
 }
 return (parse_error(token_lst->str));
}

canonical_original_code:
enum e_bool check_redir(struct s_token *token_lst)
{
 if (token_lst->type != pipes
   && is_redir_operator(token_lst->str) != unknown)
 {
  if (token_lst->next && token_lst->next->type == redir_dest)
  {
   if (token_lst->next->next)
   {
    if (token_lst->next->next->type == pipes)
     return (check_pipe(token_lst->next->next));
    else if (token_lst->next->next->type == colon)
     return (check_colon(token_lst->next->next));
    else if (token_lst->next->next->type == log_and
      || token_lst->next->next->type == log_or)
     return (check_logical(token_lst->next->next));
    else if (token_lst->next->next->type == bg)
     return (check_background(token_lst->next->next));
   }
   return (TRUE);
  }
  return (parse_error(token_lst->str));
 }
 return (parse_error(token_lst->str));
}


decompiled_code:
__int64 __fastcall check_command(__int64 a1)
{
__int64 v2; // rdi
int v3; // eax
int *v4; // rdi
int v5; // eax

if ( *(_DWORD *)a1 != 9 )
return parse_error(*(_QWORD *)(a1 + 8));
v2 = *(_QWORD *)(a1 + 16);
if ( !v2 )
return 1LL;
if ( *(_DWORD *)v2 == 4 )
return check_pipe(v2);
v3 = is_redir_operator(*(_QWORD *)(v2 + 8));
v4 = *(int **)(a1 + 16);
if ( v3 != 11 )
return check_redir((__int64)v4);
v5 = *v4;
if ( *v4 == 8 )
return check_colon((__int64)v4);
if ( (unsigned int)(v5 - 5) <= 1 )
return check_logical();
if ( v5 != 7 )
return parse_error(*(_QWORD *)(a1 + 8));
return check_background();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // rdi
int v3; // eax
int *v4; // rdi
int v5; // eax

if ( *(_DWORD *)a1 != 9 )
return parse_error(*(_QWORD *)(a1 + 8));
v2 = *(_QWORD *)(a1 + 16);
if ( !v2 )
return 1LL;
if ( *(_DWORD *)v2 == 4 )
return func2(v2);
v3 = is_redir_operator(*(_QWORD *)(v2 + 8));
v4 = *(int **)(a1 + 16);
if ( v3 != 11 )
return func3((__int64)v4);
v5 = *v4;
if ( *v4 == 8 )
return func1((__int64)v4);
if ( (unsigned int)(v5 - 5) <= 1 )
return check_logical();
if ( v5 != 7 )
return parse_error(*(_QWORD *)(a1 + 8));
return check_background();
}

original_code:
t_bool check_command(t_token *token_lst)
{
 if (token_lst->type == word)
 {
  if (token_lst->next)
  {
   if (token_lst->next->type == pipes)
    return (check_pipe(token_lst->next));
   else if (is_redir_operator(token_lst->next->str) != unknown)
    return (check_redir(token_lst->next));
   else if (token_lst->next->type == colon)
    return (check_colon(token_lst->next));
   else if (token_lst->next->type == log_or
     || token_lst->next->type == log_and)
    return (check_logical(token_lst->next));
   else if (token_lst->next->type == bg)
    return (check_background(token_lst->next));
   return (parse_error(token_lst->str));
  }
  return (TRUE);
 }
 else
  return (parse_error(token_lst->str));
}

canonical_original_code:
enum e_bool check_command(struct s_token *token_lst)
{
 if (token_lst->type == word)
 {
  if (token_lst->next)
  {
   if (token_lst->next->type == pipes)
    return (check_pipe(token_lst->next));
   else if (is_redir_operator(token_lst->next->str) != unknown)
    return (check_redir(token_lst->next));
   else if (token_lst->next->type == colon)
    return (check_colon(token_lst->next));
   else if (token_lst->next->type == log_or
     || token_lst->next->type == log_and)
    return (check_logical(token_lst->next));
   else if (token_lst->next->type == bg)
    return (check_background(token_lst->next));
   return (parse_error(token_lst->str));
  }
  return (TRUE);
 }
 else
  return (parse_error(token_lst->str));
}


decompiled_code:
void __fastcall launch_job(__int64 a1, __int64 a2)
{
__int64 i; // rbx
int v3; // edx
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

for ( i = *(_QWORD *)(a1 + 16); i; i = *(_QWORD *)(i + 24) )
{
if ( *(_QWORD *)(i + 24) )
{
if ( pipe(pipedes) < 0 )
ft_putstr("42sh : error pipe \n");
v3 = pipedes[0];
*(_DWORD *)(i + 12) = pipedes[1];
*(_DWORD *)(*(_QWORD *)(i + 24) + 8LL) = v3;
}
ft_fork(i, a2);
ft_close_pipe(i);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2)
{
__int64 i; // rbx
int v3; // edx
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

for ( i = *(_QWORD *)(a1 + 16); i; i = *(_QWORD *)(i + 24) )
{
if ( *(_QWORD *)(i + 24) )
{
if ( pipe(pipedes) < 0 )
ft_putstr("42sh : error pipe \n");
v3 = pipedes[0];
*(_DWORD *)(i + 12) = pipedes[1];
*(_DWORD *)(*(_QWORD *)(i + 24) + 8LL) = v3;
}
ft_fork(i, a2);
ft_close_pipe(i);
}
}

original_code:
void launch_job(t_job *j, t_gen *envp)
{
 t_process *p;
 int mypipe[2];
 p = j->first_process;
 while (p)
 {
  if (p->next)
  {
   if (pipe(mypipe) < 0)
    ft_putstr("42sh : error pipe \n");
   p->fd[1] = mypipe[1];
   p->next->fd[0] = mypipe[0];
  }
  ft_fork(p, envp);
  ft_close_pipe(p);
  p = p->next;
 }
}

canonical_original_code:
void launch_job(struct s_job *j, struct s_gen *envp)
{
 struct s_process *p;
 int mypipe[2];
 p = j->first_process;
 while (p)
 {
  if (p->next)
  {
   if (pipe(mypipe) < 0)
    ft_putstr("42sh : error pipe \n");
   p->fd[1] = mypipe[1];
   p->next->fd[0] = mypipe[0];
  }
  ft_fork(p, envp);
  ft_close_pipe(p);
  p = p->next;
 }
}

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

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:
mypipe
int [2]

return_type: void

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

user_defined_types: struct s_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; }


parser

decompiled_code:
__int64 parser()
{
__int64 v0; // r12
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v0 = 0LL;
v2 = get_token_lst();
if ( (unsigned int)check_exp(v2) )
v0 = make_command_lst(v2);
token_lst_free(&v2);
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r12
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v0 = 0LL;
v2 = get_token_lst();
if ( (unsigned int)check_exp(v2) )
v0 = make_command_lst(v2);
token_lst_free(&v2);
return v0;
}

original_code:
t_command *parser(char *str)
{
 t_token *token_lst;
 t_command *command_lst;
 command_lst = ((void *)0);
 token_lst = get_token_lst(str);
 if (check_exp(token_lst))
  command_lst = make_command_lst(token_lst);
 token_lst_free(&token_lst);
 return (command_lst);
}

canonical_original_code:
struct s_command *parser(char *str)
{
 struct s_token *token_lst;
 struct s_command *command_lst;
 command_lst = ((void *)0);
 token_lst = get_token_lst(str);
 if (check_exp(token_lst))
  command_lst = make_command_lst(token_lst);
 token_lst_free(&token_lst);
 return (command_lst);
}

variable_types:
str
char *

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

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


decompiled_code:
__int64 __fastcall ft_getdir(int a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // rax
__int64 v9; // rax
_QWORD *v10; // rax
_QWORD *v11; // rbp
__int64 v12; // rax
__int64 v13; // rdx
__int64 v14; // rsi
__int64 v15; // r12

if ( a1 )
{
v1 = ft_getenv("HOME=");
v2 = (int)ft_strlen(v1);
v3 = ft_getenv("HOME=");
v4 = ft_getenv("PWD=");
if ( (unsigned int)ft_strncmp(v4, v3, v2) )
{
v8 = ft_getenv("PWD=");
result = ft_strdup(v8);
}
else
{
v5 = ft_getenv("PWD=");
v6 = ft_strdup(v5 + v2);
result = ft_joinfree("~", v6, 2LL);
}
}
else
{
v9 = ft_getenv("PWD=");
v10 = (_QWORD *)ft_strsplit(v9, 47LL);
v11 = v10;
if ( v10[1] )
{
v12 = 1LL;
do
v13 = v12++;
while ( v11[v12] );
v10 = &v11[v13];
}
v14 = ft_strdup(*v10);
v15 = ft_joinfree("/", v14, 2LL);
ft_freesplit(v11);
result = v15;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 result; // rax
__int64 v8; // rax
__int64 v9; // rax
_QWORD *v10; // rax
_QWORD *v11; // rbp
__int64 v12; // rax
__int64 v13; // rdx
__int64 v14; // rsi
__int64 v15; // r12

if ( a1 )
{
v1 = ft_getenv("HOME=");
v2 = (int)ft_strlen(v1);
v3 = ft_getenv("HOME=");
v4 = ft_getenv("PWD=");
if ( (unsigned int)ft_strncmp(v4, v3, v2) )
{
v8 = ft_getenv("PWD=");
result = ft_strdup(v8);
}
else
{
v5 = ft_getenv("PWD=");
v6 = ft_strdup(v5 + v2);
result = ft_joinfree("~", v6, 2LL);
}
}
else
{
v9 = ft_getenv("PWD=");
v10 = (_QWORD *)ft_strsplit(v9, 47LL);
v11 = v10;
if ( v10[1] )
{
v12 = 1LL;
do
v13 = v12++;
while ( v11[v12] );
v10 = &v11[v13];
}
v14 = ft_strdup(*v10);
v15 = ft_joinfree("/", v14, 2LL);
ft_freesplit(v11);
result = v15;
}
return result;
}

original_code:
char *ft_getdir(int opt)
{
 char *tmp;
 char **tmp2;
 int i;
 tmp = ((void *)0);
 i = 0;
 if (opt == 0)
 {
  tmp2 = ft_strsplit(ft_getenv("PWD="), '/');
  while (tmp2[i + 1])
   i++;
  tmp = ft_joinfree("/", ft_strdup(tmp2[i]), 2);
  ft_freesplit(tmp2);
  return (tmp);
 }
 else
 {
  i = ft_strlen(ft_getenv("HOME="));
  if (!ft_strncmp(ft_getenv("PWD="), ft_getenv("HOME="), i))
   tmp = ft_joinfree("~", ft_strdup(ft_getenv("PWD=") + i), 2);
  else
   tmp = ft_strdup(ft_getenv("PWD="));
 }
 return (tmp);
}

variable_types: opt int

variable_types:
tmp
char *

variable_types: i int

return_type: char *


decompiled_code:
__int64 __fastcall get_on_ps1(char a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
int v4; // ecx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v2 = 0LL;
v3 = 110;
while ( 1 )
{
v4 = v2;
if ( a1 == v3 )
break;
v3 = byte_5B1[v2++];
if ( !v3 )
return 0LL;
}
if ( (_DWORD)v2 )
{
switch ( (_DWORD)v2 )
{
case 1:
v6 = (__int64)ft_gettime(1);
break;
case 2:
v6 = (__int64)ft_gettime(0);
break;
case 3:
v5 = ft_getenv("PWD=");
v6 = ft_strdup(v5);
break;
default:
if ( (_DWORD)v2 == 4 || (v6 = 0LL, v4 == 5) )
{
v6 = ft_getdir(1);
}
else
{
switch ( v4 )
{
case 6:
v6 = ft_strdup("\x1B[0m");
break;
case 7:
v6 = ft_strdup("\x1B[31m");
break;
case 8:
v6 = ft_strdup("\x1B[32m");
break;
case 9:
v6 = ft_strdup("\x1B[33m");
break;
case 10:
v6 = ft_strdup("\x1B[34m");
break;
case 11:
v6 = ft_strdup("\x1B[35m");
break;
}
}
break;
}
}
else
{
v7 = ft_getenv("USER=");
v6 = ft_strdup(v7);
}
*(_QWORD *)(a2 + 8) = ft_joinfree(*(_QWORD *)(a2 + 8), v6, 3LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1, __int64 a2)
{
__int64 v2; // rax
char v3; // dl
int v4; // ecx
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

v2 = 0LL;
v3 = 110;
while ( 1 )
{
v4 = v2;
if ( a1 == v3 )
break;
v3 = byte_5B1[v2++];
if ( !v3 )
return 0LL;
}
if ( (_DWORD)v2 )
{
switch ( (_DWORD)v2 )
{
case 1:
v6 = (__int64)func0(1);
break;
case 2:
v6 = (__int64)func0(0);
break;
case 3:
v5 = ft_getenv("PWD=");
v6 = ft_strdup(v5);
break;
default:
if ( (_DWORD)v2 == 4 || (v6 = 0LL, v4 == 5) )
{
v6 = func1(1);
}
else
{
switch ( v4 )
{
case 6:
v6 = ft_strdup("\x1B[0m");
break;
case 7:
v6 = ft_strdup("\x1B[31m");
break;
case 8:
v6 = ft_strdup("\x1B[32m");
break;
case 9:
v6 = ft_strdup("\x1B[33m");
break;
case 10:
v6 = ft_strdup("\x1B[34m");
break;
case 11:
v6 = ft_strdup("\x1B[35m");
break;
}
}
break;
}
}
else
{
v7 = ft_getenv("USER=");
v6 = ft_strdup(v7);
}
*(_QWORD *)(a2 + 8) = ft_joinfree(*(_QWORD *)(a2 + 8), v6, 3LL);
return 1LL;
}

original_code:
int get_on_ps1(char c, t_ps1 *ps1)
{
 char *op;
 int i;
 char *tmp;
 i = 0;
 tmp = ((void *)0);
 op = "nt*Dd~012345\0";
 while (op[i] && op[i] != c)
  i++;
 if (op[i] == '\0')
  return (0);
 tmp = (i == 0) ? ft_strdup(ft_getenv("USER=")) : tmp;
 tmp = (i == 1) ? ft_gettime(1) : tmp;
 tmp = (i == 2) ? ft_gettime(0) : tmp;
 tmp = (i == 3) ? ft_strdup(ft_getenv("PWD=")) : tmp;
 tmp = (i == 4) ? ft_getdir(1) : tmp;
 tmp = (i == 5) ? ft_getdir(1) : tmp;
 tmp = (i == 6) ? ft_strdup("\033[0m") : tmp;
 tmp = (i == 7) ? ft_strdup("\033[31m") : tmp;
 tmp = (i == 8) ? ft_strdup("\033[32m") : tmp;
 tmp = (i == 9) ? ft_strdup("\033[33m") : tmp;
 tmp = (i == 10) ? ft_strdup("\033[34m") : tmp;
 tmp = (i == 11) ? ft_strdup("\033[35m") : tmp;
 ps1->aff = ft_joinfree(ps1->aff, tmp, 3);
 return (1);
}

canonical_original_code:
int get_on_ps1(char c, struct s_ps1 *ps1)
{
 char *op;
 int i;
 char *tmp;
 i = 0;
 tmp = ((void *)0);
 op = "nt*Dd~012345\0";
 while (op[i] && op[i] != c)
  i++;
 if (op[i] == '\0')
  return (0);
 tmp = (i == 0) ? ft_strdup(ft_getenv("USER=")) : tmp;
 tmp = (i == 1) ? ft_gettime(1) : tmp;
 tmp = (i == 2) ? ft_gettime(0) : tmp;
 tmp = (i == 3) ? ft_strdup(ft_getenv("PWD=")) : tmp;
 tmp = (i == 4) ? ft_getdir(1) : tmp;
 tmp = (i == 5) ? ft_getdir(1) : tmp;
 tmp = (i == 6) ? ft_strdup("\033[0m") : tmp;
 tmp = (i == 7) ? ft_strdup("\033[31m") : tmp;
 tmp = (i == 8) ? ft_strdup("\033[32m") : tmp;
 tmp = (i == 9) ? ft_strdup("\033[33m") : tmp;
 tmp = (i == 10) ? ft_strdup("\033[34m") : tmp;
 tmp = (i == 11) ? ft_strdup("\033[35m") : tmp;
 ps1->aff = ft_joinfree(ps1->aff, tmp, 3);
 return (1);
}

variable_types: c char

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

variable_types:
op
char *

return_type: int


original_code:
void parse_ps1(t_ps1 *ps1)
{
 int i;
 i = 0;
 ps1->len = 0;
 while (ps1->env[i])
 {
  if (ps1->env[i] == '%' && get_on_ps1(ps1->env[i + 1], ps1))
  {
   if (ps1->env[i] == '%' && ft_isdigit(ps1->env[i + 1]))
   {
    if (ps1->env[i + 1] != '0')
     ps1->len = ps1->len - 1;
    ps1->len = ps1->len - 4;
   }
   i++;
  }
  else
   ps1->aff = add_char(ps1->aff, ps1->env[i]);
  i++;
 }
 ps1->len = ps1->len + ft_strlen(ps1->aff);
 ps1->aff = ft_joinfree(ps1->aff, "\033[0m", 1);
}

canonical_original_code:
void parse_ps1(struct s_ps1 *ps1)
{
 int i;
 i = 0;
 ps1->len = 0;
 while (ps1->env[i])
 {
  if (ps1->env[i] == '%' && get_on_ps1(ps1->env[i + 1], ps1))
  {
   if (ps1->env[i] == '%' && ft_isdigit(ps1->env[i + 1]))
   {
    if (ps1->env[i + 1] != '0')
     ps1->len = ps1->len - 1;
    ps1->len = ps1->len - 4;
   }
   i++;
  }
  else
   ps1->aff = add_char(ps1->aff, ps1->env[i]);
  i++;
 }
 ps1->len = ps1->len + ft_strlen(ps1->aff);
 ps1->aff = ft_joinfree(ps1->aff, "\033[0m", 1);
}

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


decompiled_code:
__int64 __fastcall check_access(char *name)
{
int v1; // er8
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( stat(name, &v3) != -1 && (v3.st_mode & 0xF000) == 0x4000 )
return 10LL;
v1 = access(name, 0);
result = 5LL;
if ( v1 != -1 )
result = 4 * (unsigned int)(access(name, 1) == -1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *name)
{
int v1; // er8
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

if ( stat(name, &v3) != -1 && (v3.st_mode & 0xF000) == 0x4000 )
return 10LL;
v1 = access(name, 0);
result = 5LL;
if ( v1 != -1 )
result = 4 * (unsigned int)(access(name, 1) == -1);
return result;
}

original_code:
int check_access(char *path)
{
 struct stat buf;
 if (stat(path, &buf) != -1)
  if (((((buf.st_mode)) & 0170000) == (0040000)) == 1)
   return (10);
 if (access(path, 0) == -1)
  return (5);
 if (access(path, 1) == -1)
  return (4);
 return (0);
}

variable_types:
path
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall ft_vs(int a1)
{
return (unsigned int)(a1 != 2) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return (unsigned int)(a1 != 2) + 1;
}

original_code:
int ft_vs(int player)
{
 if (player == 2)
  return (1);
 return (2);
}

variable_types: player int


decompiled_code:
__int64 __fastcall valid_position(__int64 a1, int a2, int a3)
{
__int64 v3; // r10
__int64 result; // rax

v3 = 8LL * a2;
result = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)a1 + v3) + 4LL * a3);
if ( (_DWORD)result )
return 0LL;
if ( *(_DWORD *)(a1 + 8) - 1 == a2 )
return 1LL;
if ( *(_DWORD *)(a1 + 12) > a3 )
result = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + v3 + 8) + 4LL * a3) != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, int a3)
{
__int64 v3; // r10
__int64 result; // rax

v3 = 8LL * a2;
result = *(unsigned int *)(*(_QWORD *)(*(_QWORD *)a1 + v3) + 4LL * a3);
if ( (_DWORD)result )
return 0LL;
if ( *(_DWORD *)(a1 + 8) - 1 == a2 )
return 1LL;
if ( *(_DWORD *)(a1 + 12) > a3 )
result = *(_DWORD *)(*(_QWORD *)(*(_QWORD *)a1 + v3 + 8) + 4LL * a3) != 0;
return result;
}

original_code:
int valid_position(t_game *game, int x, int y)
{
 if (game->grid[x][y] == 0)
 {
  if (x == game->max_x - 1)
   return (1);
  if (y < game->max_y && game->grid[x + 1][y] != 0)
   return (1);
 }
 return (0);
}

canonical_original_code:
int valid_position(struct s_game *game, int x, int y)
{
 if (game->grid[x][y] == 0)
 {
  if (x == game->max_x - 1)
   return (1);
  if (y < game->max_y && game->grid[x + 1][y] != 0)
   return (1);
 }
 return (0);
}

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

variable_types: x int

variable_types: y int


original_code:
int mini_max(int player, int deph, t_game *game)
{
 int check;
 int max;
 int tmp;
 int x;
 int y;
 check = check_winner();
 max = 0;
 tmp = 0;
 if (check == player)
  return (2);
 else if (check == ft_vs(player))
  return (-1);
 else if (check == 100)
  return (1);
 else if (deph == 0)
  return (0);
 x = 0;
 while (x < game->max_x)
 {
  y = 0;
  while (y < game->max_y)
  {
   if (!game->grid[x][y] && valid_position(game, x, y))
   {
    game->grid[x][y] = player;
    if (player == 2)
    {
     tmp = mini_max(1, deph - 1, game);
     if (tmp >= max)
      max = tmp;
    }
    else if (player == 1)
    {
     tmp = mini_max(2, deph - 1, game);
     if (tmp <= max)
      max = tmp;
    }
    game->grid[x][y] = 0;
   }
   y++;
  }
  x++;
 }
 return (max);
}

canonical_original_code:
int mini_max(int player, int deph, struct s_game *game)
{
 int check;
 int max;
 int tmp;
 int x;
 int y;
 check = check_winner();
 max = 0;
 tmp = 0;
 if (check == player)
  return (2);
 else if (check == ft_vs(player))
  return (-1);
 else if (check == 100)
  return (1);
 else if (deph == 0)
  return (0);
 x = 0;
 while (x < game->max_x)
 {
  y = 0;
  while (y < game->max_y)
  {
   if (!game->grid[x][y] && valid_position(game, x, y))
   {
    game->grid[x][y] = player;
    if (player == 2)
    {
     tmp = mini_max(1, deph - 1, game);
     if (tmp >= max)
      max = tmp;
    }
    else if (player == 1)
    {
     tmp = mini_max(2, deph - 1, game);
     if (tmp <= max)
      max = tmp;
    }
    game->grid[x][y] = 0;
   }
   y++;
  }
  x++;
 }
 return (max);
}

variable_types: deph int

variable_types: check int

variable_types: max int

variable_types: tmp 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 search_first_posi(int *a1, _DWORD *a2, __int64 a3)
{
int *v3; // rbp
__int64 result; // rax
int v7; // er12
int v8; // esi
int v9; // edx

v3 = a1;
*a1 = 0;
result = *(unsigned int *)(a3 + 8);
if ( (int)result > 0 )
{
while ( 1 )
{
*a2 = 0;
v7 = *(_DWORD *)(a3 + 12);
if ( v7 > 0 )
break;
LABEL_7:
++v3;
result = *(unsigned int *)(a3 + 8);
if ( *v3 >= (int)result )
return result;
}
v8 = *v3;
v9 = 0;
while ( 1 )
{
result = valid_position(a3, v8, v9);
if ( (_DWORD)result )
break;
v9 = a2[1];
++a2;
if ( v9 >= v7 )
goto LABEL_7;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, _DWORD *a2, __int64 a3)
{
int *v3; // rbp
__int64 result; // rax
int v7; // er12
int v8; // esi
int v9; // edx

v3 = a1;
*a1 = 0;
result = *(unsigned int *)(a3 + 8);
if ( (int)result > 0 )
{
while ( 1 )
{
*a2 = 0;
v7 = *(_DWORD *)(a3 + 12);
if ( v7 > 0 )
break;
LABEL_7:
++v3;
result = *(unsigned int *)(a3 + 8);
if ( *v3 >= (int)result )
return result;
}
v8 = *v3;
v9 = 0;
while ( 1 )
{
result = func1(a3, v8, v9);
if ( (_DWORD)result )
break;
v9 = a2[1];
++a2;
if ( v9 >= v7 )
goto LABEL_7;
}
}
return result;
}

original_code:
void search_first_posi(int *x, int *y, t_game *game)
{
 *x = 0;
 while (*x < game->max_x)
 {
  *y = 0;
  while(*y < game->max_y)
  {
   if (valid_position(game, *x, *y))
    return ;
   y++;
  }
  x++;
 }
}

canonical_original_code:
void search_first_posi(int *x, int *y, struct s_game *game)
{
 *x = 0;
 while (*x < game->max_x)
 {
  *y = 0;
  while(*y < game->max_y)
  {
   if (valid_position(game, *x, *y))
    return ;
   y++;
  }
  x++;
 }
}

variable_types:
x
int *

variable_types:
y
int *


ia

original_code:
void ia(int player, t_game *game)
{
 int x_tmp;
 int y_tmp;
 int tmp;
 int max;
 int x;
 int y;
 tmp = 0;
 max = -2000000;
 x = 0;
 y = 0;
 x_tmp = 0;
 while(x_tmp < game->max_x)
 {
  y_tmp = 0;
  while (y_tmp < game->max_y)
  {
   if (valid_position(game, x_tmp, y_tmp))
   {
    game->grid[x_tmp][y_tmp] = player;
    printf("prob = %d joueur : %d pose x : %d pose : Y %d \n ", tmp, player, x_tmp + 1, y_tmp + 1);
    tmp = mini_max(ft_vs(player), game->ia_lvl, game);
    if (max <= tmp)
    {
     x = x_tmp;
     y = y_tmp;
     max = tmp;
    }
    game->grid[x_tmp][y_tmp] = 0;
   }
   y_tmp++;
  }
  x_tmp++;
 }
 game->grid[x][y] = player;
}

canonical_original_code:
void ia(int player, struct s_game *game)
{
 int x_tmp;
 int y_tmp;
 int tmp;
 int max;
 int x;
 int y;
 tmp = 0;
 max = -2000000;
 x = 0;
 y = 0;
 x_tmp = 0;
 while(x_tmp < game->max_x)
 {
  y_tmp = 0;
  while (y_tmp < game->max_y)
  {
   if (valid_position(game, x_tmp, y_tmp))
   {
    game->grid[x_tmp][y_tmp] = player;
    printf("prob = %d joueur : %d pose x : %d pose : Y %d \n ", tmp, player, x_tmp + 1, y_tmp + 1);
    tmp = mini_max(ft_vs(player), game->ia_lvl, game);
    if (max <= tmp)
    {
     x = x_tmp;
     y = y_tmp;
     max = tmp;
    }
    game->grid[x_tmp][y_tmp] = 0;
   }
   y_tmp++;
  }
  x_tmp++;
 }
 game->grid[x][y] = player;
}


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

v2 = ((__int64 (*)(void))ft_strlen)();
v3 = ft_strlen(a2);
v4 = malloc(v2 + v3 + 2);
if ( !v4 )
return 0LL;
v5 = ft_strcpy(v4, a1);
v6 = ft_strcat(v5, &unk_19C);
return ft_strcat(v6, a2);
}

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

v2 = ((__int64 (*)(void))ft_strlen)();
v3 = ft_strlen(a2);
v4 = malloc(v2 + v3 + 2);
if ( !v4 )
return 0LL;
v5 = ft_strcpy(v4, a1);
v6 = ft_strcat(v5, &unk_19C);
return ft_strcat(v6, a2);
}

original_code:
char *concat_path(char *split, char *exec)
{
 size_t len;
 char *path;
 len = (ft_strlen(split) + ft_strlen(exec) + 2);
 if ((path = (char *)malloc(sizeof(char) * len)) == ((void *)0))
  return (((void *)0));
 path = ft_strcpy(path, split);
 path = ft_strcat(path, "/");
 path = ft_strcat(path, exec);
 return (path);
}

canonical_original_code:
char *concat_path(char *split, char *exec)
{
 unsigned long len;
 char *path;
 len = (ft_strlen(split) + ft_strlen(exec) + 2);
 if ((path = (char *)malloc(sizeof(char) * len)) == ((void *)0))
  return (((void *)0));
 path = ft_strcpy(path, split);
 path = ft_strcat(path, "/");
 path = ft_strcat(path, exec);
 return (path);
}

variable_types:
split
char *

variable_types:
exec
char *

variable_types:
len
unsigned long


decompiled_code:
const char *__fastcall find_path_exec(__int64 a1, __int64 a2)
{
const char *result; // rax
__int64 v4; // rbx
__int64 v5; // rax
int v6; // eax
__int64 v7; // rdi
const char *v8; // [rsp+0h] [rbp-28h] BYREF
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

result = (const char *)get_var_env("PATH=", *(_QWORD *)a2);
v8 = result;
if ( result )
{
v4 = 0LL;
v5 = ft_strsplit(result, 58LL);
for ( v9[0] = v5; ; v5 = v9[0] )
{
v7 = *(_QWORD *)(v5 + v4);
if ( !v7 )
break;
v8 = (const char *)concat_path(v7, a1);
if ( access(v8, 0) != -1 )
{
v6 = check_access(v8);
*(_DWORD *)(a2 + 48) = v6;
if ( !v6 )
break;
}
v4 += 8LL;
*(_DWORD *)(a2 + 48) = check_access(v8);
ft_strdel(&v8);
if ( *(_DWORD *)(a2 + 48) == 4 )
break;
}
free_split(v9);
result = v8;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(__int64 a1, __int64 a2)
{
const char *result; // rax
__int64 v4; // rbx
__int64 v5; // rax
int v6; // eax
__int64 v7; // rdi
const char *v8; // [rsp+0h] [rbp-28h] BYREF
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

result = (const char *)get_var_env("PATH=", *(_QWORD *)a2);
v8 = result;
if ( result )
{
v4 = 0LL;
v5 = ft_strsplit(result, 58LL);
for ( v9[0] = v5; ; v5 = v9[0] )
{
v7 = *(_QWORD *)(v5 + v4);
if ( !v7 )
break;
v8 = (const char *)func0(v7, a1);
if ( access(v8, 0) != -1 )
{
v6 = check_access(v8);
*(_DWORD *)(a2 + 48) = v6;
if ( !v6 )
break;
}
v4 += 8LL;
*(_DWORD *)(a2 + 48) = check_access(v8);
ft_strdel(&v8);
if ( *(_DWORD *)(a2 + 48) == 4 )
break;
}
free_split(v9);
result = v8;
}
return result;
}

original_code:
char *find_path_exec(char *exec, t_gen *envp)
{
 char *path;
 char **split;
 int i;
 i = -1;
 if ((path = get_var_env("PATH=", envp->env)) == ((void *)0))
  return (((void *)0));
 split = ft_strsplit(path, ':');
 while (split[++i])
 {
  path = concat_path(split[i], exec);
  if ((access(path, 0) != -1) &&
    ((envp->ret = check_access(path)) == 0))
   break ;
  else
  {
   envp->ret = check_access(path);
   ft_strdel(&path);
   if (envp->ret == 4)
    break ;
  }
 }
 free_split(&split);
 return (path);
}

canonical_original_code:
char *find_path_exec(char *exec, struct s_gen *envp)
{
 char *path;
 char **split;
 int i;
 i = -1;
 if ((path = get_var_env("PATH=", envp->env)) == ((void *)0))
  return (((void *)0));
 split = ft_strsplit(path, ':');
 while (split[++i])
 {
  path = concat_path(split[i], exec);
  if ((access(path, 0) != -1) &&
    ((envp->ret = check_access(path)) == 0))
   break ;
  else
  {
   envp->ret = check_access(path);
   ft_strdel(&path);
   if (envp->ret == 4)
    break ;
  }
 }
 free_split(&split);
 return (path);
}

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

variable_types: i int


decompiled_code:
const char *__fastcall check_and_get_path(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // r12
__int64 v3; // rax
int v4; // eax
int v6; // eax

v2 = a1;
if ( *a1 == 46 )
{
v2 = a1 + 2;
v6 = check_access(a1 + 2);
*(_DWORD *)(a2 + 48) = v6;
if ( !v6 )
return v2;
return 0LL;
}
if ( *a1 == 47 || (v3 = get_var_env("PWD=", *(_QWORD *)a2), !(unsigned int)ft_strcmp(&unk_19C, v3)) )
{
v4 = check_access(a1);
*(_DWORD *)(a2 + 48) = v4;
if ( !v4 )
return v2;
return 0LL;
}
return find_path_exec((__int64)a1, a2);
}

canonical_decompiled_code:
const char *__fastcall func2(_BYTE *a1, __int64 a2)
{
_BYTE *v2; // r12
__int64 v3; // rax
int v4; // eax
int v6; // eax

v2 = a1;
if ( *a1 == 46 )
{
v2 = a1 + 2;
v6 = check_access(a1 + 2);
*(_DWORD *)(a2 + 48) = v6;
if ( !v6 )
return v2;
return 0LL;
}
if ( *a1 == 47 || (v3 = get_var_env("PWD=", *(_QWORD *)a2), !(unsigned int)ft_strcmp(&unk_19C, v3)) )
{
v4 = check_access(a1);
*(_DWORD *)(a2 + 48) = v4;
if ( !v4 )
return v2;
return 0LL;
}
return func1((__int64)a1, a2);
}

original_code:
char *check_and_get_path(char *var, t_gen *envp)
{
 char *path;
 path = ((void *)0);
 if (var[0] == '.')
 {
  path = var + 2;
  if ((envp->ret = check_access(path)) != 0)
   return (((void *)0));
 }
 else if (var[0] == '/' ||
   !(ft_strcmp("/", get_var_env("PWD=", envp->env))))
 {
  path = var;
  if ((envp->ret = check_access(path)) != 0)
   return (((void *)0));
 }
 else
  path = find_path_exec(var, envp);
 return (path);
}

canonical_original_code:
char *check_and_get_path(char *var, struct s_gen *envp)
{
 char *path;
 path = ((void *)0);
 if (var[0] == '.')
 {
  path = var + 2;
  if ((envp->ret = check_access(path)) != 0)
   return (((void *)0));
 }
 else if (var[0] == '/' ||
   !(ft_strcmp("/", get_var_env("PWD=", envp->env))))
 {
  path = var;
  if ((envp->ret = check_access(path)) != 0)
   return (((void *)0));
 }
 else
  path = find_path_exec(var, envp);
 return (path);
}

variable_types:
var
char *

variable_types:
path
char *

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

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

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


decompiled_code:
unsigned __int64 __fastcall is_op_char(unsigned __int8 a1)
{
unsigned __int64 result; // rax

result = 1LL;
if ( a1 != 124 )
{
result = 0LL;
if ( a1 <= 0x3Eu )
result = (0x5800004000000000uLL >> a1) & 1;
}
return result;
}

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

result = 1LL;
if ( a1 != 124 )
{
result = 0LL;
if ( a1 <= 0x3Eu )
result = (0x5800004000000000uLL >> a1) & 1;
}
return result;
}

canonical_original_code:
enum e_bool is_op_char(char c)
{
 if (c == '|' || c == ';' || c == '<' || c == '>' || c == '&')
  return (TRUE);
 return (FALSE);
}

variable_types: c char


decompiled_code:
__int64 __fastcall my_strlen(unsigned __int8 *a1)
{
unsigned int v1; // er8
unsigned __int8 v2; // di
unsigned __int8 *v3; // rdx

v1 = 0;
if ( a1 )
{
v2 = *a1;
if ( (v2 & 0xDF) != 0 )
{
do
{
if ( (unsigned int)is_op_char(v2) )
break;
v2 = *v3;
++v1;
}
while ( (*v3 & 0xDF) != 0 );
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1)
{
unsigned int v1; // er8
unsigned __int8 v2; // di
unsigned __int8 *v3; // rdx

v1 = 0;
if ( a1 )
{
v2 = *a1;
if ( (v2 & 0xDF) != 0 )
{
do
{
if ( (unsigned int)func0(v2) )
break;
v2 = *v3;
++v1;
}
while ( (*v3 & 0xDF) != 0 );
}
}
return v1;
}

original_code:
static int my_strlen(const char *s)
{
 int i;
 i = 0;
 if (s)
 {
  while (s[i] && s[i] != ' ' && !is_op_char(s[i]))
   i++;
  return (i);
 }
 return (0);
}

canonical_original_code:
static int my_strlen(char *s)
{
 int i;
 i = 0;
 if (s)
 {
  while (s[i] && s[i] != ' ' && !is_op_char(s[i]))
   i++;
  return (i);
 }
 return (0);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall is_ok_char(char a1)
{
return (a1 == 10) | (unsigned __int8)((unsigned __int8)(a1 - 33) <= 0x5Du);
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return (a1 == 10) | (unsigned __int8)((unsigned __int8)(a1 - 33) <= 0x5Du);
}

original_code:
t_bool is_ok_char(char c)
{
 if ((c > 32 && c < 127) || c == 0x0a)
  return (TRUE);
 return (FALSE);
}

canonical_original_code:
enum e_bool is_ok_char(char c)
{
 if ((c > 32 && c < 127) || c == 0x0a)
  return (TRUE);
 return (FALSE);
}


decompiled_code:
__int64 __fastcall is_word(unsigned __int8 *a1)
{
unsigned __int8 *v2; // rsi
unsigned __int8 i; // di
int v4; // eax
int v5; // er9

v2 = &a1[*a1 == 39 || *a1 == 34];
for ( i = *v2; i; i = *++v2 )
{
if ( !(unsigned int)is_ok_char(i) )
break;
if ( (unsigned int)is_op_char(i) )
break;
}
v4 = my_strlen(a1);
return 2 * (unsigned int)(v4 != v5) + 9;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1)
{
unsigned __int8 *v2; // rsi
unsigned __int8 i; // di
int v4; // eax
int v5; // er9

v2 = &a1[*a1 == 39 || *a1 == 34];
for ( i = *v2; i; i = *++v2 )
{
if ( !(unsigned int)func2(i) )
break;
if ( (unsigned int)func0(i) )
break;
}
v4 = func1(a1);
return 2 * (unsigned int)(v4 != v5) + 9;
}

original_code:
t_sym is_word(char *str)
{
 int i;
 i = 0;
 if (str[i] == '\"' || str[i] == '\'')
 {
  i++;
 }
 while (str[i] && is_ok_char(str[i]) && !is_op_char(str[i]))
  i++;
 if (i == my_strlen(str))
  return (word);
 return (unknown);
}

canonical_original_code:
enum e_sym is_word(char *str)
{
 int i;
 i = 0;
 if (str[i] == '\"' || str[i] == '\'')
 {
  i++;
 }
 while (str[i] && is_ok_char(str[i]) && !is_op_char(str[i]))
  i++;
 if (i == my_strlen(str))
  return (word);
 return (unknown);
}

variable_types:
str
char *

return_type: enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 }


decompiled_code:
__int64 __fastcall check_background(__int64 a1)
{
if ( *(_DWORD *)a1 != 7 )
return parse_error(*(_QWORD *)(a1 + 8));
if ( *(_QWORD *)(a1 + 16) )
return check_exp();
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( *(_DWORD *)a1 != 7 )
return parse_error(*(_QWORD *)(a1 + 8));
if ( *(_QWORD *)(a1 + 16) )
return check_exp();
return 1LL;
}

original_code:
t_bool check_background(t_token *token_lst)
{
 if (token_lst->type == bg)
 {
  if (token_lst->next)
   return (check_exp(token_lst->next));
  return (TRUE);
 }
 return (parse_error(token_lst->str));
}

canonical_original_code:
enum e_bool check_background(struct s_token *token_lst)
{
 if (token_lst->type == bg)
 {
  if (token_lst->next)
   return (check_exp(token_lst->next));
  return (TRUE);
 }
 return (parse_error(token_lst->str));
}

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


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

if ( (unsigned int)(*(_DWORD *)a1 - 5) <= 1 && *(_QWORD *)(a1 + 16) )
result = check_exp(*(_QWORD *)(a1 + 16));
else
result = parse_error(*(_QWORD *)(a1 + 8));
return result;
}

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

if ( (unsigned int)(*(_DWORD *)a1 - 5) <= 1 && *(_QWORD *)(a1 + 16) )
result = check_exp(*(_QWORD *)(a1 + 16));
else
result = parse_error(*(_QWORD *)(a1 + 8));
return result;
}

original_code:
t_bool check_logical(t_token *token_lst)
{
 if (token_lst->type == log_and || token_lst->type == log_or)
 {
  if (token_lst->next)
   return (check_exp(token_lst->next));
  else
   return (parse_error(token_lst->str));
 }
 return (parse_error(token_lst->str));
}

canonical_original_code:
enum e_bool check_logical(struct s_token *token_lst)
{
 if (token_lst->type == log_and || token_lst->type == log_or)
 {
  if (token_lst->next)
   return (check_exp(token_lst->next));
  else
   return (parse_error(token_lst->str));
 }
 return (parse_error(token_lst->str));
}


decompiled_code:
__int64 __fastcall ft_parse_and_exec(_BYTE *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v4[0] = ft_strtrim();
if ( !(unsigned int)ft_strncmp(v4[0], "exit", 4LL) && (!*(_BYTE *)(v4[0] + 4) || (unsigned int)ft_isspace() == 1) )
{
ft_strdel(v4);
destroy_gen();
exit(0);
}
result = ft_strdel(v4);
if ( a1 )
{
if ( *a1 )
{
v3 = parser(a1);
ft_command(v3, a2);
result = command_lst_free(v3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v4[0] = ft_strtrim();
if ( !(unsigned int)ft_strncmp(v4[0], "exit", 4LL) && (!*(_BYTE *)(v4[0] + 4) || (unsigned int)ft_isspace() == 1) )
{
ft_strdel(v4);
destroy_gen();
exit(0);
}
result = ft_strdel(v4);
if ( a1 )
{
if ( *a1 )
{
v3 = parser(a1);
ft_command(v3, a2);
result = command_lst_free(v3);
}
}
return result;
}

original_code:
void ft_parse_and_exec(char *line, t_gen *gen)
{
 t_command *command_lst;
 char *tr;
 tr = ft_strtrim(line);
 if (ft_strncmp(tr, "exit", 4) == 0 && (!tr[4] || ft_isspace(tr[4]) == 1))
 {
  ft_strdel(&tr);
  destroy_gen();
  exit(0);
 }
 ft_strdel(&tr);
 command_lst = ((void *)0);
 if (line && line[0])
 {
  command_lst = parser(line);
  ft_command(command_lst, gen);
  command_lst_free(command_lst);
 }
}

canonical_original_code:
void ft_parse_and_exec(char *line, struct s_gen *gen)
{
 struct s_command *command_lst;
 char *tr;
 tr = ft_strtrim(line);
 if (ft_strncmp(tr, "exit", 4) == 0 && (!tr[4] || ft_isspace(tr[4]) == 1))
 {
  ft_strdel(&tr);
  destroy_gen();
  exit(0);
 }
 ft_strdel(&tr);
 command_lst = ((void *)0);
 if (line && line[0])
 {
  command_lst = parser(line);
  ft_command(command_lst, gen);
  command_lst_free(command_lst);
 }
}

variable_types:
line
char *

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

variable_types:
tr
char *


decompiled_code:
int __fastcall updat_prompt(__int64 a1)
{
__int64 v1; // rbp
int result; // eax
int v3; // ebx
unsigned int v4; // er12
char *v5; // rax

v1 = recup_gen();
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
parse_ps1(a1);
result = tgetnum("co");
if ( result )
{
v3 = result;
do
{
v4 = *(_DWORD *)(*(_QWORD *)(v1 + 24) + 120LL);
v5 = tgetstr("kl", 0LL);
result = ft_putstr_fd(v5, v4);
--v3;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
int result; // eax
int v3; // ebx
unsigned int v4; // er12
char *v5; // rax

v1 = recup_gen();
free(*(void **)(a1 + 8));
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
parse_ps1(a1);
result = tgetnum("co");
if ( result )
{
v3 = result;
do
{
v4 = *(_DWORD *)(*(_QWORD *)(v1 + 24) + 120LL);
v5 = tgetstr("kl", 0LL);
result = ft_putstr_fd(v5, v4);
--v3;
}
while ( v3 );
}
return result;
}

original_code:
void updat_prompt(t_ps1 *ps1)
{
 int i;
 t_gen *gen;
 gen = recup_gen();
 free(ps1->aff);
 ps1->aff = ((void *)0);
 ps1->len = 0;
 parse_ps1(ps1);
 i = tgetnum("co");
 while (i--)
  ft_putstr_fd(tgetstr("kl", ((void *)0)), gen->term->fd);
}

canonical_original_code:
void updat_prompt(struct s_ps1 *ps1)
{
 int i;
 struct s_gen *gen;
 gen = recup_gen();
 free(ps1->aff);
 ps1->aff = ((void *)0);
 ps1->len = 0;
 parse_ps1(ps1);
 i = tgetnum("co");
 while (i--)
  ft_putstr_fd(tgetstr("kl", ((void *)0)), gen->term->fd);
}

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


original_code:
void prompt_next_line(t_gen *gen, char **line)
{
 char buff[4096];
 int ret;
 init_term();
 updat_prompt(gen->ps1);
 ft_putstr(gen->ps1->aff);
 if (gen->hist == ((void *)0) || gen->hist->buff[0] != 0)
  gen->hist = add_element(gen->hist);
 gen->term->wait = 1;
 while (gen->term->wait)
 {
  ft_bzero(buff, 4096);
  ret = read(gen->term->fd, buff, 4096);
  buff[ret] = 0;
  tc_stomp(buff, gen);
 }
 go_end(gen, ((void *)0));
 gen->hist = save_hist(gen->hist);
 ft_putchar('\n');
 *line = gen->hist->buff;
 close_term();
}

canonical_original_code:
void prompt_next_line(struct s_gen *gen, char **line)
{
 char buff[4096];
 int ret;
 init_term();
 updat_prompt(gen->ps1);
 ft_putstr(gen->ps1->aff);
 if (gen->hist == ((void *)0) || gen->hist->buff[0] != 0)
  gen->hist = add_element(gen->hist);
 gen->term->wait = 1;
 while (gen->term->wait)
 {
  ft_bzero(buff, 4096);
  ret = read(gen->term->fd, buff, 4096);
  buff[ret] = 0;
  tc_stomp(buff, gen);
 }
 go_end(gen, ((void *)0));
 gen->hist = save_hist(gen->hist);
 ft_putchar('\n');
 *line = gen->hist->buff;
 close_term();
}

variable_types:
line
char **

variable_types:
buff
char [4096]

variable_types: ret int


decompiled_code:
void __noreturn ft_rappel()
{
__int64 *i; // rbx
__int64 v1; // rbp
_BYTE *v2; // [rsp+8h] [rbp-20h] BYREF

for ( i = (__int64 *)recup_gen(); ; close(*(_DWORD *)(i[3] + 120)) )
{
init_sig();
v1 = i[3];
*(_DWORD *)(v1 + 120) = open("/dev/tty", 2);
prompt_next_line(i, &v2);
ft_parse_and_exec(v2, (__int64)i);
}
}

original_code:
void ft_rappel(void)
{
 t_gen *gen;
 char *line;
 gen = recup_gen();
 while (1)
 {
  init_sig();
  gen->term->fd = open("/dev/tty", 02);
  prompt_next_line(gen, &line);
  ft_parse_and_exec(line, gen);
  close(gen->term->fd);
 }
}

canonical_original_code:
void ft_rappel()
{
 struct s_gen *gen;
 char *line;
 gen = recup_gen();
 while (1)
 {
  init_sig();
  gen->term->fd = open("/dev/tty", 02);
  prompt_next_line(gen, &line);
  ft_parse_and_exec(line, gen);
  close(gen->term->fd);
 }
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 *v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rdi

init_env(envp, argv);
v3 = recup_gen();
v4 = *(__int64 **)(v3 + 16);
v5 = v3;
v6 = ft_strdup("[%1%*%0]-[%2%d%0]>");
v7 = *(_QWORD *)(v5 + 16);
*v4 = v6;
parse_ps1(v7);
ft_rappel();
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 *v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rdi

init_env(envp, argv);
v3 = recup_gen();
v4 = *(__int64 **)(v3 + 16);
v5 = v3;
v6 = ft_strdup("[%1%*%0]-[%2%d%0]>");
v7 = *(_QWORD *)(v5 + 16);
*v4 = v6;
parse_ps1(v7);
func3();
}

original_code:
int main(int ac, char **av, char **env)
{
 t_gen *gen;
 (void)ac;
 (void)av;
 init_env(env);
 gen = recup_gen();
 gen->ps1->env = ft_strdup("[%1%*%0]-[%2%d%0]>");
 parse_ps1(gen->ps1);
 ft_rappel();
 ft_putnbr(gen->ps1->len);
 return (1);
}

canonical_original_code:
int main(int ac, char **av, char **env)
{
 struct s_gen *gen;
 (void)ac;
 (void)av;
 init_env(env);
 gen = recup_gen();
 gen->ps1->env = ft_strdup("[%1%*%0]-[%2%d%0]>");
 parse_ps1(gen->ps1);
 ft_rappel();
 ft_putnbr(gen->ps1->len);
 return (1);
}

variable_types: ac int

variable_types:
av
char **

variable_types:
env
char **


decompiled_code:
__int64 __fastcall is_redir_operator(char *a1)
{
char v1; // al
bool v2; // zf
__int64 result; // rax

v1 = *a1;
if ( *a1 == 50 )
return 9 * (unsigned int)(a1[1] != 62) + 2;
if ( v1 == 62 )
return 2 * (unsigned int)(a1[1] == 62) + 1;
v2 = v1 == 60;
result = 11LL;
if ( v2 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al
bool v2; // zf
__int64 result; // rax

v1 = *a1;
if ( *a1 == 50 )
return 9 * (unsigned int)(a1[1] != 62) + 2;
if ( v1 == 62 )
return 2 * (unsigned int)(a1[1] == 62) + 1;
v2 = v1 == 60;
result = 11LL;
if ( v2 )
result = 0LL;
return result;
}

original_code:
t_sym is_redir_operator(char *str)
{
 if (str[0] == '2' && str[1] == '>')
  return (redir_err);
 if (str[0] == '>' && str[1] == '>')
  return (append);
 if (str[0] == '>')
  return (redir_out);
 if (str[0] == '<')
  return (redir_in);
 return (unknown);
}

canonical_original_code:
enum e_sym is_redir_operator(char *str)
{
 if (str[0] == '2' && str[1] == '>')
  return (redir_err);
 if (str[0] == '>' && str[1] == '>')
  return (append);
 if (str[0] == '>')
  return (redir_out);
 if (str[0] == '<')
  return (redir_in);
 return (unknown);
}


decompiled_code:
__int64 __fastcall is_separator(_BYTE *a1)
{
return 3 * (unsigned int)(*a1 != 59) + 8;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1)
{
return 3 * (unsigned int)(*a1 != 59) + 8;
}

original_code:
t_sym is_separator(char *str)
{
 if (str[0] == ';')
  return (colon);
 return (unknown);
}

canonical_original_code:
enum e_sym is_separator(char *str)
{
 if (str[0] == ';')
  return (colon);
 return (unknown);
}


decompiled_code:
__int64 __fastcall is_background_operator(_BYTE *a1)
{
return 4 * (unsigned int)(*a1 != 38) + 7;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
return 4 * (unsigned int)(*a1 != 38) + 7;
}

original_code:
t_sym is_background_operator(char *str)
{
 if (str[0] == '&')
  return (bg);
 return (unknown);
}

canonical_original_code:
enum e_sym is_background_operator(char *str)
{
 if (str[0] == '&')
  return (bg);
 return (unknown);
}


decompiled_code:
__int64 __fastcall is_logical_operator(_BYTE *a1)
{
__int64 result; // rax

if ( *a1 == 124 )
return 5 * (unsigned int)(a1[1] != 124) + 6;
result = 11LL;
if ( *a1 == 38 && a1[1] == 38 )
result = 5LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_BYTE *a1)
{
__int64 result; // rax

if ( *a1 == 124 )
return 5 * (unsigned int)(a1[1] != 124) + 6;
result = 11LL;
if ( *a1 == 38 && a1[1] == 38 )
result = 5LL;
return result;
}

original_code:
t_sym is_logical_operator(char *str)
{
 if (str[0] == '|' && str[1] == '|')
  return (log_or);
 if (str[0] == '&' && str[1] == '&')
  return (log_and);
 return (unknown);
}

canonical_original_code:
enum e_sym is_logical_operator(char *str)
{
 if (str[0] == '|' && str[1] == '|')
  return (log_or);
 if (str[0] == '&' && str[1] == '&')
  return (log_and);
 return (unknown);
}


decompiled_code:
__int64 __fastcall is_operator(_BYTE *a1)
{
__int64 result; // rax

result = is_logical_operator(a1);
if ( (_DWORD)result == 11 )
{
if ( *a1 != 124 || a1[1] == 124 )
{
result = is_redir_operator(a1);
if ( (_DWORD)result == 11 )
{
result = is_separator(a1);
if ( (_DWORD)result == 11 )
result = is_background_operator(a1);
}
}
else
{
result = 4LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
__int64 result; // rax

result = func3(a1);
if ( (_DWORD)result == 11 )
{
if ( *a1 != 124 || a1[1] == 124 )
{
result = func0(a1);
if ( (_DWORD)result == 11 )
{
result = func1(a1);
if ( (_DWORD)result == 11 )
result = func2(a1);
}
}
else
{
result = 4LL;
}
}
return result;
}

original_code:
t_sym is_operator(char *str)
{
 t_sym type;
 if ((type = is_logical_operator(str)) != unknown)
  return (type);
 if (str[0] == '|' && str[1] != '|')
  return (pipes);
 if ((type = is_redir_operator(str)) != unknown)
  return (type);
 if ((type = is_separator(str)) != unknown)
  return (type);
 if ((type = is_background_operator(str)) != unknown)
  return (type);
 return (unknown);
}

canonical_original_code:
enum e_sym is_operator(char *str)
{
 enum e_sym type;
 if ((type = is_logical_operator(str)) != unknown)
  return (type);
 if (str[0] == '|' && str[1] != '|')
  return (pipes);
 if ((type = is_redir_operator(str)) != unknown)
  return (type);
 if ((type = is_separator(str)) != unknown)
  return (type);
 if ((type = is_background_operator(str)) != unknown)
  return (type);
 return (unknown);
}

variable_types: enum e_sym { redir_in=0, redir_out=1, redir_err=2, append=3, pipes=4, log_and=5, log_or=6, bg=7, colon=8, word=9, redir_dest=10, unknown=11 }


decompiled_code:
__int64 __fastcall func_cd(__int64 a1, int a2, const char *a3)
{
char *v4; // rbp
char *v5; // rax
unsigned __int64 v6; // rbx
char v8[4136]; // [rsp+0h] [rbp-1028h] BYREF

ft_bzero(v8, 4096LL);
v4 = (char *)ft_strtrim(a1 + 3);
if ( chdir(v4) == -1 )
goto LABEL_5;
v5 = getcwd(v8, 0x1000uLL);
v6 = ft_strlen(v5);
if ( v6 < ft_strlen(a3) )
{
chdir(a3);
LABEL_5:
send(a2, "ERROR you dont have right", 0x19uLL, 0);
goto LABEL_6;
}
send(a2, "SUCCESS", 7uLL, 0);
LABEL_6:
free(v4);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, const char *a3)
{
char *v4; // rbp
char *v5; // rax
unsigned __int64 v6; // rbx
char v8[4136]; // [rsp+0h] [rbp-1028h] BYREF

ft_bzero(v8, 4096LL);
v4 = (char *)ft_strtrim(a1 + 3);
if ( chdir(v4) == -1 )
goto LABEL_5;
v5 = getcwd(v8, 0x1000uLL);
v6 = ft_strlen(v5);
if ( v6 < ft_strlen(a3) )
{
chdir(a3);
LABEL_5:
send(a2, "ERROR you dont have right", 0x19uLL, 0);
goto LABEL_6;
}
send(a2, "SUCCESS", 7uLL, 0);
LABEL_6:
free(v4);
return 1LL;
}

original_code:
int func_cd(char *buff, int cs, char *pwd)
{
 char buf[4096];
 char *tmp;
 char *tmp2;
 ft_bzero(buf, 4096);
 tmp = ft_strtrim(buff + 3);
 if (chdir(tmp) != -1)
 {
  if (ft_strlen(getcwd(buf, 4096)) >= ft_strlen(pwd))
   send(cs, "SUCCESS", 7, 0);
  else
  {
   chdir(pwd);
   send(cs, "ERROR you dont have right", 25, 0);
  }
 }
 else
  send(cs, "ERROR you dont have right", 25, 0);
 free(tmp);
 return (1);
}

variable_types:
buff
char *

variable_types: cs int

variable_types:
pwd
char *

variable_types:
buf
char [4096]

variable_types:
tmp
char *


decompiled_code:
__int64 __fastcall func_pwd(int fd)
{
char *v1; // rax
size_t v2; // r12
char *v3; // rax
char v5[4120]; // [rsp+0h] [rbp-1018h] BYREF

v1 = getcwd(v5, 0x1000uLL);
v2 = ft_strlen(v1);
v3 = getcwd(v5, 0x1000uLL);
send(fd, v3, v2, 0);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
char *v1; // rax
size_t v2; // r12
char *v3; // rax
char v5[4120]; // [rsp+0h] [rbp-1018h] BYREF

v1 = getcwd(v5, 0x1000uLL);
v2 = ft_strlen(v1);
v3 = getcwd(v5, 0x1000uLL);
send(fd, v3, v2, 0);
return 1LL;
}

original_code:
int func_pwd(int cs)
{
 char buff[4096];
 send(cs, getcwd(buff, 4096), ft_strlen(getcwd(buff, 4096)), 0);
 return (1);
}


decompiled_code:
__int64 __fastcall command_lst_print(__int64 *a1)
{
unsigned int v1; // er12
__int64 *v2; // rbp
__int64 v3; // rdi
__int64 i; // rbx

if ( a1 )
{
v1 = 1;
v2 = a1;
do
{
ft_putstr("Command ");
v3 = v1++;
ft_putnbr(v3);
ft_putstr(" : [");
for ( i = *v2; i; i = *(_QWORD *)(i + 16) )
ft_putstr(*(_QWORD *)(i + 8));
ft_putstr("]\n");
job_lst_print(v2[1]);
v2 = (__int64 *)v2[3];
}
while ( v2 );
}
return ft_putstr("\n");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1)
{
unsigned int v1; // er12
__int64 *v2; // rbp
__int64 v3; // rdi
__int64 i; // rbx

if ( a1 )
{
v1 = 1;
v2 = a1;
do
{
ft_putstr("Command ");
v3 = v1++;
ft_putnbr(v3);
ft_putstr(" : [");
for ( i = *v2; i; i = *(_QWORD *)(i + 16) )
ft_putstr(*(_QWORD *)(i + 8));
ft_putstr("]\n");
job_lst_print(v2[1]);
v2 = (__int64 *)v2[3];
}
while ( v2 );
}
return ft_putstr("\n");
}

original_code:
void command_lst_print(t_command *command_lst)
{
 t_command *lst;
 t_token *token;
 int i;
 lst = command_lst;
 i = 1;
 while (lst != ((void *)0))
 {
  ft_putstr("Command ");
  ft_putnbr(i++);
  ft_putstr(" : [");
  token = lst->token_lst;
  while (token != ((void *)0))
  {
   ft_putstr(token->str);
   token = token->next;
  }
  ft_putstr("]\n");
  job_lst_print(lst->first_job);
  lst = lst->next;
 }
 ft_putstr("\n");
}

canonical_original_code:
void command_lst_print(struct s_command *command_lst)
{
 struct s_command *lst;
 struct s_token *token;
 int i;
 lst = command_lst;
 i = 1;
 while (lst != ((void *)0))
 {
  ft_putstr("Command ");
  ft_putnbr(i++);
  ft_putstr(" : [");
  token = lst->token_lst;
  while (token != ((void *)0))
  {
   ft_putstr(token->str);
   token = token->next;
  }
  ft_putstr("]\n");
  job_lst_print(lst->first_job);
  lst = lst->next;
 }
 ft_putstr("\n");
}

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

variable_types: i int

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


original_code:
void fn_char_backsp(t_gen *gen, char *key)
{
 int i;
 (void)key;
 if (gen->hist->pose_buff != 0)
 {
  tc_clean_line(gen);
  i = gen->hist->pose_buff - 1;
  while (gen->hist->buff[i])
  {
   gen->hist->buff[i] = gen->hist->buff[i + 1];
   ++i;
  }
  gen->hist->len--;
  gen->hist->pose_buff--;
  ft_putstr_fd(gen->hist->buff, gen->term->fd);
  i = gen->hist->pose_buff;
  gen->hist->pose_buff = gen->hist->len;
  gen_tc_move_left(gen, gen->hist->len - i);
  gen->hist->pose_buff = i;
  gen->hist->modif = 1;
 }
 else
  ft_putstr_fd(((TERMTYPE *)(cur_term))-> Strings[1], gen->term->fd);
}

canonical_original_code:
void fn_char_backsp(struct s_gen *gen, char *key)
{
 int i;
 (void)key;
 if (gen->hist->pose_buff != 0)
 {
  tc_clean_line(gen);
  i = gen->hist->pose_buff - 1;
  while (gen->hist->buff[i])
  {
   gen->hist->buff[i] = gen->hist->buff[i + 1];
   ++i;
  }
  gen->hist->len--;
  gen->hist->pose_buff--;
  ft_putstr_fd(gen->hist->buff, gen->term->fd);
  i = gen->hist->pose_buff;
  gen->hist->pose_buff = gen->hist->len;
  gen_tc_move_left(gen, gen->hist->len - i);
  gen->hist->pose_buff = i;
  gen->hist->modif = 1;
 }
 else
  ft_putstr_fd(((struct termtype *)(cur_term))-> Strings[1], gen->term->fd);
}

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

variable_types:
key
char *

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


decompiled_code:
__int64 __fastcall fn_char_del(__int64 a1)
{
__int64 result; // rax
int v2; // edx

result = *(_QWORD *)(a1 + 32);
v2 = *(_DWORD *)(result + 4096);
if ( v2 < *(_DWORD *)(result + 4100) )
{
*(_DWORD *)(result + 4096) = v2 + 1;
gen_tc_move_right(a1, 1LL);
result = fn_char_backsp(a1);
}
return result;
}

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

result = *(_QWORD *)(a1 + 32);
v2 = *(_DWORD *)(result + 4096);
if ( v2 < *(_DWORD *)(result + 4100) )
{
*(_DWORD *)(result + 4096) = v2 + 1;
gen_tc_move_right(a1, 1LL);
result = func0(a1);
}
return result;
}

original_code:
void fn_char_del(t_gen *gen, char *key)
{
 (void)key;
 if (gen->hist->pose_buff < gen->hist->len)
 {
  gen->hist->pose_buff++;
  gen_tc_move_right(gen, 1);
  fn_char_backsp(gen, ((void *)0));
 }
}

canonical_original_code:
void fn_char_del(struct s_gen *gen, char *key)
{
 (void)key;
 if (gen->hist->pose_buff < gen->hist->len)
 {
  gen->hist->pose_buff++;
  gen_tc_move_right(gen, 1);
  fn_char_backsp(gen, ((void *)0));
 }
}


decompiled_code:
__int64 __fastcall fn_write_char(__int64 a1, char a2)
{
__int64 v2; // rdx
int v3; // eax
__int64 result; // rax
__int64 v5; // rcx
int v6; // eax

v2 = *(_QWORD *)(a1 + 32);
v3 = *(_DWORD *)(v2 + 4100);
if ( v3 > 4094 )
return ft_putstr(*((_QWORD *)cur_term->type.Strings + 1));
if ( v3 == *(_DWORD *)(v2 + 4096) )
{
v5 = v3;
v6 = v3 + 1;
*(_BYTE *)(v2 + v5 + 4108) = a2;
*(_DWORD *)(v2 + 4096) = v6;
*(_DWORD *)(v2 + 4100) = v6;
ft_putchar_fd((unsigned int)a2, *(unsigned int *)(*(_QWORD *)(a1 + 24) + 120LL));
}
else
{
print_in(a1, (unsigned int)a2);
}
result = *(_QWORD *)(a1 + 32);
*(_DWORD *)(result + 4104) = 1;
return result;
}

original_code:
void fn_write_char(t_gen *gen, char key)
{
 if (gen->hist->len + 1 < 4096)
 {
  if (gen->hist->len == gen->hist->pose_buff)
  {
   gen->hist->buff[gen->hist->len] = key;
   gen->hist->pose_buff = gen->hist->pose_buff + 1;
   gen->hist->len = gen->hist->len + 1;
   ft_putchar_fd(key, gen->term->fd);
  }
  else
   print_in(gen, key);
  gen->hist->modif = 1;
 }
 else
  ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void fn_write_char(struct s_gen *gen, char key)
{
 if (gen->hist->len + 1 < 4096)
 {
  if (gen->hist->len == gen->hist->pose_buff)
  {
   gen->hist->buff[gen->hist->len] = key;
   gen->hist->pose_buff = gen->hist->pose_buff + 1;
   gen->hist->len = gen->hist->len + 1;
   ft_putchar_fd(key, gen->term->fd);
  }
  else
   print_in(gen, key);
  gen->hist->modif = 1;
 }
 else
  ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}

variable_types: key char


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

init_var(&i, v8);
while ( 1 )
{
result = ++i;
if ( !a2[i] )
break;
v3 = v8[0];
v4 = format_str();
a2[v3] = v4;
if ( v4 )
++v8[0];
}
v6 = *a2;
for ( i = 0; v6; v6 = a2[i] )
{
if ( v6 == 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, v6);
}
result = ++i;
}
return result;
}

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

func2(&i, v8);
while ( 1 )
{
result = ++i;
if ( !a2[i] )
break;
v3 = v8[0];
v4 = format_str();
a2[v3] = v4;
if ( v4 )
++v8[0];
}
v6 = *a2;
for ( i = 0; v6; v6 = a2[i] )
{
if ( v6 == 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, v6);
}
result = ++i;
}
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]


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

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

variable_types:
av
char **


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

v1 = (_QWORD *)ft_strsplit(*((_QWORD *)ptr + 1), 32LL);
v2 = (void *)ft_strjoin(&unk_2FA, *v1);
v3 = (void *)ft_strjoin(v2, &unk_2FD);
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; // r12
void *v2; // r14
void *v3; // r13
void *v4; // r14
__int64 v5; // r13
__int64 v6; // rax
void *v7; // r13
__int64 v8; // r12

v1 = (_QWORD *)ft_strsplit(*((_QWORD *)ptr + 1), 32LL);
v2 = (void *)ft_strjoin(&unk_2FA, *v1);
v3 = (void *)ft_strjoin(v2, &unk_2FD);
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
__int64 v2; // r12
_QWORD *v3; // rbp
__int64 v4; // rax
_QWORD *v5; // rbp

*(_DWORD *)(a1 + 24) = 4;
v1 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 124LL);
if ( !v1[1] )
return 0xFFFFFFFFLL;
v2 = *(_QWORD *)(a1 + 8);
v3 = v1;
v4 = ft_strlen(*v1);
*(_QWORD *)(a1 + 16) = ft_strtrim(v2 + v4 + 1);
*(_QWORD *)(a1 + 8) = *v3;
free(v3);
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
__int64 v2; // r12
_QWORD *v3; // rbp
__int64 v4; // rax
_QWORD *v5; // rbp

*(_DWORD *)(a1 + 24) = 4;
v1 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 124LL);
if ( !v1[1] )
return 0xFFFFFFFFLL;
v2 = *(_QWORD *)(a1 + 8);
v3 = v1;
v4 = ft_strlen(*v1);
*(_QWORD *)(a1 + 16) = ft_strtrim(v2 + v4 + 1);
*(_QWORD *)(a1 + 8) = *v3;
free(v3);
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);
}

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

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

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

if ( a1 )
{
v1 = a1;
while ( !ft_strchr(*(_QWORD *)(v1 + 8), 60LL) )
{
if ( ft_strchr(*(_QWORD *)(v1 + 8), 124LL) )
{
if ( (unsigned int)func2(v1) )
return 0xFFFFFFFFLL;
LABEL_4:
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
return 0LL;
}
else
{
if ( !ft_strchr(*(_QWORD *)(v1 + 8), 62LL) )
{
*(_DWORD *)(v1 + 24) = 1;
goto LABEL_4;
}
if ( (unsigned int)assign_file_out(v1) )
return 0xFFFFFFFFLL;
v1 = *(_QWORD *)(v1 + 32);
if ( !v1 )
return 0LL;
}
}
func1(v1);
goto LABEL_4;
}
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; // r12
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // r12
__int64 result; // rax

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

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

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

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

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

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


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

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

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
v2 = *v3++;
}
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_2E7, 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 func4(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
__int64 result; // rax

v2 = (int)ft_found(&unk_2E7, 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_process { char **av; int fd[3]; struct s_process *next; struct s_process *prev; } *


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 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();
while ( *v2++ );
}
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();
while ( *v2++ );
}
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 v3; // rax

if ( !*a2 )
return 0LL;
v2 = a2;
do
{
v3 = ft_strlen(a1);
if ( !(unsigned int)ft_strncmp(*v2, a1, v3) )
return ft_strstr(*v2, a1);
++v2;
}
while ( *v2 );
return 0LL;
}

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

if ( !*a2 )
return 0LL;
v2 = a2;
do
{
v3 = ft_strlen(a1);
if ( !(unsigned int)ft_strncmp(*v2, a1, v3) )
return ft_strstr(*v2, a1);
++v2;
}
while ( *v2 );
return 0LL;
}

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; // rbp
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; // rbp
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; // ebx
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; // ebx
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: i int

variable_types: j int

variable_types:
tmp
char *


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

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

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

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

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


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

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; // r14
unsigned int v6; // er13

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)


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; // r12
unsigned int v3; // eax
__int64 v4; // rax
bool v5; // zf
_WORD *v7; // [rsp+8h] [rbp-20h] BYREF

v7 = malloc(0x401uLL);
v1 = create_token();
if ( !v1 )
return 0LL;
if ( !v7 )
return 0LL;
v2 = v1;
ft_memset(v7, 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, v7) )
++*a1;
}
else
{
get_op_str(a1, v3, v7);
}
v4 = ft_strdup(v7);
v5 = v7 == 0LL;
*(_QWORD *)(v2 + 8) = v4;
if ( !v5 )
ft_strdel(&v7);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 **a1)
{
__int64 v1; // rax
__int64 v2; // r12
unsigned int v3; // eax
__int64 v4; // rax
bool v5; // zf
_WORD *v7; // [rsp+8h] [rbp-20h] BYREF

v7 = malloc(0x401uLL);
v1 = create_token();
if ( !v1 )
return 0LL;
if ( !v7 )
return 0LL;
v2 = v1;
ft_memset(v7, 0LL, 1025LL);
v3 = get_token_type(*a1);
*(_DWORD *)v2 = v3;
if ( v3 == 11 )
return 0LL;
if ( v3 == 9 )
{
if ( (unsigned __int8)func2(a1, v7) )
++*a1;
}
else
{
func0(a1, v3, v7);
}
v4 = ft_strdup(v7);
v5 = v7 == 0LL;
*(_QWORD *)(v2 + 8) = v4;
if ( !v5 )
ft_strdel(&v7);
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; // rbp
__int64 v2; // rdi
char v3; // dl
unsigned __int8 *v4; // rax
unsigned __int8 *v6; // [rsp+8h] [rbp-10h] BYREF

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

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

v1 = 0LL;
v6 = a1;
if ( *a1 )
{
do
{
v2 = func3(&v6);
if ( !v2 )
break;
v1 = token_lst_add(v2, v1);
v3 = *v6;
if ( *v6 == 32 || v3 == 9 )
{
v4 = v6 + 1;
do
{
do
{
v6 = v4;
v3 = *v4++;
}
while ( v3 == 32 );
}
while ( v3 == 9 );
}
}
while ( v3 );
}
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; } *