original_code:
t_hist *creat_new_hist(void)
{
 t_hist *tmp;
 if (!(tmp = (t_hist *)malloc(sizeof(*tmp))))
  return (((void *)0));
 tmp->pose_buff = 0;
 tmp->len = 0;
 tmp->modif = 0;
 ft_memset(tmp->value, 0, 4096);
 ft_memset(tmp->buff, 0, 4096);
 tmp->next = ((void *)0);
 tmp->prev = ((void *)0);
 tmp->number = 1;
 return (tmp);
}

canonical_original_code:
struct s_hist *creat_new_hist()
{
 struct s_hist *tmp;
 if (!(tmp = (struct s_hist *)malloc(sizeof(*tmp))))
  return (((void *)0));
 tmp->pose_buff = 0;
 tmp->len = 0;
 tmp->modif = 0;
 ft_memset(tmp->value, 0, 4096);
 ft_memset(tmp->buff, 0, 4096);
 tmp->next = ((void *)0);
 tmp->prev = ((void *)0);
 tmp->number = 1;
 return (tmp);
}

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


original_code:
void hist_cp_cmd(t_hist *hist)
{
 t_hist *exec;
 exec = hist;
 while (hist->next)
  hist = hist->next;
 ft_memcpy(hist->value, exec->buff, 4096);
}

canonical_original_code:
void hist_cp_cmd(struct s_hist *hist)
{
 struct s_hist *exec;
 exec = hist;
 while (hist->next)
  hist = hist->next;
 ft_memcpy(hist->value, exec->buff, 4096);
}

return_type: void

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


original_code:
t_hist *save_hist(t_hist *hist)
{
 hist_cp_cmd(hist);
 while (hist->prev)
  hist = hist->prev;
 while (hist->next)
 {
  if (hist->modif)
   restor_hist(hist);
  hist = hist->next;
 }
 restor_hist(hist);
 return (hist);
}

canonical_original_code:
struct s_hist *save_hist(struct s_hist *hist)
{
 hist_cp_cmd(hist);
 while (hist->prev)
  hist = hist->prev;
 while (hist->next)
 {
  if (hist->modif)
   restor_hist(hist);
  hist = hist->next;
 }
 restor_hist(hist);
 return (hist);
}

variable_types:
hist
struct s_hist *

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


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

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

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

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

original_code:
void job_lst_free(t_job *job_lst)
{
 t_job *curr;
 t_job *to_free;
 curr = job_lst;
 while (curr)
 {
  to_free = curr;
  curr = curr->next;
  process_lst_free(to_free->first_process);
  to_free->first_process = ((void *)0);
  token_lst_free(&(to_free->token_lst));
  to_free->need_success = 0;
  to_free->next = ((void *)0);
  to_free->prev = ((void *)0);
  free(to_free);
  to_free = ((void *)0);
 }
 job_lst = ((void *)0);
}

canonical_original_code:
void job_lst_free(struct s_job *job_lst)
{
 struct s_job *curr;
 struct s_job *to_free;
 curr = job_lst;
 while (curr)
 {
  to_free = curr;
  curr = curr->next;
  process_lst_free(to_free->first_process);
  to_free->first_process = ((void *)0);
  token_lst_free(&(to_free->token_lst));
  to_free->need_success = 0;
  to_free->next = ((void *)0);
  to_free->prev = ((void *)0);
  free(to_free);
  to_free = ((void *)0);
 }
 job_lst = ((void *)0);
}

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

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

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


decompiled_code:
void __fastcall ft_sig_segv(int a1)
{
__int64 v1; // rbx

v1 = return_env();
if ( a1 == 11 )
ft_putstr("ft_sh : segmentation fault\n");
if ( *(int *)(v1 + 4136) > 0 )
exit(0);
start();
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
__int64 v1; // rbx

v1 = return_env();
if ( a1 == 11 )
ft_putstr("ft_sh : segmentation fault\n");
if ( *(int *)(v1 + 4136) > 0 )
exit(0);
start();
}

original_code:
void ft_sig_segv(int x)
{
 t_env *env;
 env = return_env();
 if (x == 11)
  ft_putstr("ft_sh : segmentation fault\n");
 if (env->pid > 0)
  exit (0);
 start();
}

canonical_original_code:
void ft_sig_segv(int x)
{
 struct s_env *env;
 env = return_env();
 if (x == 11)
  ft_putstr("ft_sh : segmentation fault\n");
 if (env->pid > 0)
  exit (0);
 start();
}

variable_types: x int

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


decompiled_code:
void ft_sig_int()
{
ft_putstr(*((_QWORD *)cur_term->type.Strings + 1));
}

canonical_decompiled_code:
void func0()
{
ft_putstr(*((_QWORD *)cur_term->type.Strings + 1));
}

original_code:
void ft_sig_int(int x)
{
 x = x;
 ft_putstr(((TERMTYPE *)(cur_term))-> Strings[1]);
}

canonical_original_code:
void ft_sig_int(int x)
{
 x = x;
 ft_putstr(((struct termtype *)(cur_term))-> Strings[1]);
}

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:
void ft_sig_tstp()
{
if ( *(int *)(return_env() + 4136) > 0 )
start();
}

canonical_decompiled_code:
void func1()
{
if ( *(int *)(return_env() + 4136) > 0 )
start();
}

original_code:
void ft_sig_tstp(int x)
{
 t_env *env;
 env = return_env();
 (void)x;
 if (env->pid > 0)
 {
  start();
 }
}

canonical_original_code:
void ft_sig_tstp(int x)
{
 struct s_env *env;
 env = return_env();
 (void)x;
 if (env->pid > 0)
 {
  start();
 }
}

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


decompiled_code:
__sighandler_t ft_init_signal()
{
signal(2, (__sighandler_t)ft_sig_int);
signal(20, (__sighandler_t)ft_sig_tstp);
return signal(11, ft_sig_segv);
}

canonical_decompiled_code:
__sighandler_t func3()
{
signal(2, (__sighandler_t)ft_sig_int);
signal(20, (__sighandler_t)ft_sig_tstp);
return signal(11, ft_sig_segv);
}

original_code:
void ft_init_signal(void)
{
 signal(2, &ft_sig_int);
 signal(20, ft_sig_tstp);
 signal(11, ft_sig_segv);
}

canonical_original_code:
void ft_init_signal()
{
 signal(2, &ft_sig_int);
 signal(20, ft_sig_tstp);
 signal(11, ft_sig_segv);
}


original_code:
int check_col(t_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (x < game->max_x)
 {
  while (y + 3 < game->max_y)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x][y + 1] == 1 &&
    game->grid[x][y + 2] == 1 &&
    game->grid[x][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x][y + 1] == 2 &&
     game->grid[x][y + 2] == 2 &&
     game->grid[x][y + 3] == 2)
    return (2);
   y++;
  }
  y = 0;
  x++;
 }
 return (0);
}

canonical_original_code:
int check_col(struct s_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (x < game->max_x)
 {
  while (y + 3 < game->max_y)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x][y + 1] == 1 &&
    game->grid[x][y + 2] == 1 &&
    game->grid[x][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x][y + 1] == 2 &&
     game->grid[x][y + 2] == 2 &&
     game->grid[x][y + 3] == 2)
    return (2);
   y++;
  }
  y = 0;
  x++;
 }
 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: y int

return_type: int


original_code:
int check_line(t_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (y < game->max_y)
 {
  while (x + 3 < game->max_x)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y] == 1 &&
    game->grid[x + 2][y] == 1 &&
    game->grid[x + 3][y] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y] == 2 &&
     game->grid[x + 2][y] == 2 &&
     game->grid[x + 3][y] == 2)
    return (2);
   x++;
  }
  x = 0;
  y++;
 }
 return (0);
}

canonical_original_code:
int check_line(struct s_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (y < game->max_y)
 {
  while (x + 3 < game->max_x)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y] == 1 &&
    game->grid[x + 2][y] == 1 &&
    game->grid[x + 3][y] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y] == 2 &&
     game->grid[x + 2][y] == 2 &&
     game->grid[x + 3][y] == 2)
    return (2);
   x++;
  }
  x = 0;
  y++;
 }
 return (0);
}

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 check_null(__int64 a1)
{
int v1; // eax
int v2; // er9
__int64 v3; // rsi
__int64 v4; // r8
unsigned int *v5; // rax
unsigned int *v6; // rcx
unsigned int v7; // edx

v1 = *(_DWORD *)(a1 + 8);
if ( v1 <= 0 )
return 100;
v2 = *(_DWORD *)(a1 + 12);
v3 = 8LL * (unsigned int)v1;
v4 = 0LL;
while ( v2 <= 0 )
{
LABEL_7:
v4 += 8LL;
if ( v4 == v3 )
return 100;
}
v5 = *(unsigned int **)(*(_QWORD *)a1 + v4);
v6 = &v5[v2 - 1 + 1];
while ( 1 )
{
v7 = *v5;
if ( !*v5 )
break;
if ( ++v5 == v6 )
goto LABEL_7;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // eax
int v2; // er9
__int64 v3; // rsi
__int64 v4; // r8
unsigned int *v5; // rax
unsigned int *v6; // rcx
unsigned int v7; // edx

v1 = *(_DWORD *)(a1 + 8);
if ( v1 <= 0 )
return 100;
v2 = *(_DWORD *)(a1 + 12);
v3 = 8LL * (unsigned int)v1;
v4 = 0LL;
while ( v2 <= 0 )
{
LABEL_7:
v4 += 8LL;
if ( v4 == v3 )
return 100;
}
v5 = *(unsigned int **)(*(_QWORD *)a1 + v4);
v6 = &v5[v2 - 1 + 1];
while ( 1 )
{
v7 = *v5;
if ( !*v5 )
break;
if ( ++v5 == v6 )
goto LABEL_7;
}
return v7;
}

original_code:
int check_null(t_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (x < game->max_x)
 {
  while (y < game->max_y)
  {
   if (game->grid[x][y] == 0)
    return (0);
   y++;
  }
  y = 0;
  x++;
 }
 return (100);
}

canonical_original_code:
int check_null(struct s_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (x < game->max_x)
 {
  while (y < game->max_y)
  {
   if (game->grid[x][y] == 0)
    return (0);
   y++;
  }
  y = 0;
  x++;
 }
 return (100);
}


original_code:
int check_diag(t_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (y + 3 < game->max_y)
 {
  while (x + 3 < game->max_x)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y + 1] == 1 &&
    game->grid[x + 2][y + 2] == 1 &&
    game->grid[x + 3][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y + 1] == 2 &&
     game->grid[x + 2][y + 2] == 2 &&
     game->grid[x + 3][y + 3] == 2)
    return (2);
   x++;
  }
  x = 0;
  y++;
 }
 return (0);
}

canonical_original_code:
int check_diag(struct s_game *game)
{
 int x;
 int y;
 x = (y = 0);
 while (y + 3 < game->max_y)
 {
  while (x + 3 < game->max_x)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y + 1] == 1 &&
    game->grid[x + 2][y + 2] == 1 &&
    game->grid[x + 3][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y + 1] == 2 &&
     game->grid[x + 2][y + 2] == 2 &&
     game->grid[x + 3][y + 3] == 2)
    return (2);
   x++;
  }
  x = 0;
  y++;
 }
 return (0);
}


original_code:
int check_diag_inv(t_game *game)
{
 int x;
 int y;
 x = 0;
 while (x + 3 < game->max_x)
 {
  y = game->max_y - 1;
  while (y - 3 > 0)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y - 1] == 1 &&
    game->grid[x + 2][y - 2] == 1 &&
    game->grid[x + 3][y - 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y - 1] == 2 &&
     game->grid[x + 2][y - 2] == 2 &&
     game->grid[x + 3][y - 3] == 2)
    return (2);
   y--;
  }
  x++;
 }
 return (0);
}

canonical_original_code:
int check_diag_inv(struct s_game *game)
{
 int x;
 int y;
 x = 0;
 while (x + 3 < game->max_x)
 {
  y = game->max_y - 1;
  while (y - 3 > 0)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x + 1][y - 1] == 1 &&
    game->grid[x + 2][y - 2] == 1 &&
    game->grid[x + 3][y - 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x + 1][y - 1] == 2 &&
     game->grid[x + 2][y - 2] == 2 &&
     game->grid[x + 3][y - 3] == 2)
    return (2);
   y--;
  }
  x++;
 }
 return (0);
}


original_code:
int check_diag_dbinv(t_game *game)
{
 int x;
 int y;
 x = game->max_x - 1;
 while (x - 3 >= 0)
 {
  y = 0;
  while (y + 3 < game->max_y)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x - 1][y + 1] == 1 &&
    game->grid[x - 2][y + 2] == 1 &&
    game->grid[x - 3][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x - 1][y + 1] == 2 &&
     game->grid[x - 2][y + 2] == 2 &&
     game->grid[x - 3][y + 3] == 2)
    return (2);
   y++;
  }
  x--;
 }
 return (0);
}

canonical_original_code:
int check_diag_dbinv(struct s_game *game)
{
 int x;
 int y;
 x = game->max_x - 1;
 while (x - 3 >= 0)
 {
  y = 0;
  while (y + 3 < game->max_y)
  {
   if (game->grid[x][y] == 1 &&
    game->grid[x - 1][y + 1] == 1 &&
    game->grid[x - 2][y + 2] == 1 &&
    game->grid[x - 3][y + 3] == 1)
    return (1);
   else if (game->grid[x][y] == 2 &&
     game->grid[x - 1][y + 1] == 2 &&
     game->grid[x - 2][y + 2] == 2 &&
     game->grid[x - 3][y + 3] == 2)
    return (2);
   y++;
  }
  x--;
 }
 return (0);
}


decompiled_code:
__int64 check_winner()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

v0 = init_game();
v1 = check_null(v0);
result = 100LL;
if ( !v1 )
{
result = check_col(v0);
if ( (unsigned int)(result - 1) > 1 )
{
result = check_line(v0);
if ( (unsigned int)(result - 1) > 1 )
{
result = check_diag(v0);
if ( (unsigned int)(result - 1) > 1 )
{
result = check_diag_inv(v0);
if ( (unsigned int)(result - 1) > 1 )
{
result = check_diag_dbinv(v0);
if ( (unsigned int)(result - 1) >= 2 )
result = 0LL;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

v0 = init_game();
v1 = func2(v0);
result = 100LL;
if ( !v1 )
{
result = func0(v0);
if ( (unsigned int)(result - 1) > 1 )
{
result = func1(v0);
if ( (unsigned int)(result - 1) > 1 )
{
result = func3(v0);
if ( (unsigned int)(result - 1) > 1 )
{
result = func4(v0);
if ( (unsigned int)(result - 1) > 1 )
{
result = func5(v0);
if ( (unsigned int)(result - 1) >= 2 )
result = 0LL;
}
}
}
}
}
return result;
}

original_code:
int check_winner()
{
 int ret;
 t_game *game;
 game = init_game();
 ret = 0;
 if (check_null(game))
  return (100);
 else if ((ret = check_col(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_line(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag_inv(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag_dbinv(game)) == 2 || ret == 1)
  return (ret);
 return (0);
}

canonical_original_code:
int check_winner()
{
 int ret;
 struct s_game *game;
 game = init_game();
 ret = 0;
 if (check_null(game))
  return (100);
 else if ((ret = check_col(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_line(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag_inv(game)) == 2 || ret == 1)
  return (ret);
 else if ((ret = check_diag_dbinv(game)) == 2 || ret == 1)
  return (ret);
 return (0);
}

variable_types: ret int


decompiled_code:
__int64 __fastcall say_started(__int64 a1)
{
unsigned int v1; // ebx
signed int v2; // eax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
ft_putstr_fd("Script started, output file is ", 1LL);
ft_putstr_fd(*(_QWORD *)(a1 + 16), 1LL);
ft_putstr_fd("\n", 1LL);
ft_putstr_fd("Script started on ", *(unsigned int *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 24);
v2 = (unsigned int)ctime(&v4.tv_sec);
return ft_putstr_fd(v2, v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // ebx
signed int v2; // eax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
ft_putstr_fd("Script started, output file is ", 1LL);
ft_putstr_fd(*(_QWORD *)(a1 + 16), 1LL);
ft_putstr_fd("\n", 1LL);
ft_putstr_fd("Script started on ", *(unsigned int *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 24);
v2 = (unsigned int)ctime(&v4.tv_sec);
return ft_putstr_fd(v2, v1);
}

original_code:
void say_started(t_opt *opt)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 ft_putstr_fd("Script started, output file is ", 1);
 ft_putstr_fd(opt->file_name, 1);
 ft_putstr_fd("\n", 1);
 ft_putstr_fd("Script started on ", opt->fd_file);
 ft_putstr_fd(ctime(&tv.tv_sec), opt->fd_file);
}

canonical_original_code:
void say_started(struct s_opt *opt)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 ft_putstr_fd("Script started, output file is ", 1);
 ft_putstr_fd(opt->file_name, 1);
 ft_putstr_fd("\n", 1);
 ft_putstr_fd("Script started on ", opt->fd_file);
 ft_putstr_fd(ctime(&tv.tv_sec), opt->fd_file);
}

variable_types: struct s_opt { char **env; int opt_a; int opt_q; char *file_name; int fd_file; char *cmd[4096]; char cmd_av[4096]; char *shell; int fd_slave; char *fds_name[32]; int fd_master; char *fdm_name[32]; 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; } orig; struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; } winsize; int pid_c; } *

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

user_defined_types: struct s_opt { char **env; int opt_a; int opt_q; char *file_name; int fd_file; char *cmd[4096]; char cmd_av[4096]; char *shell; int fd_slave; char *fds_name[32]; int fd_master; char *fdm_name[32]; struct termios orig; struct winsize winsize; int pid_c; }


decompiled_code:
__int64 __fastcall say_stop(__int64 a1)
{
unsigned int v1; // ebx
signed int v2; // eax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
ft_putstr_fd("\nScript done, output file is ", 1LL);
ft_putendl_fd(*(_QWORD *)(a1 + 16), 1LL);
ft_putstr_fd("Script done on ", *(unsigned int *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 24);
v2 = (unsigned int)ctime(&v4.tv_sec);
return ft_putstr_fd(v2, v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebx
signed int v2; // eax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v4, 0LL);
ft_putstr_fd("\nScript done, output file is ", 1LL);
ft_putendl_fd(*(_QWORD *)(a1 + 16), 1LL);
ft_putstr_fd("Script done on ", *(unsigned int *)(a1 + 24));
v1 = *(_DWORD *)(a1 + 24);
v2 = (unsigned int)ctime(&v4.tv_sec);
return ft_putstr_fd(v2, v1);
}

original_code:
void say_stop(t_opt *opt)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 ft_putstr_fd("\nScript done, output file is ", 1);
 ft_putendl_fd(opt->file_name, 1);
 ft_putstr_fd("Script done on ", opt->fd_file);
 ft_putstr_fd(ctime(&tv.tv_sec), opt->fd_file);
}

canonical_original_code:
void say_stop(struct s_opt *opt)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 ft_putstr_fd("\nScript done, output file is ", 1);
 ft_putendl_fd(opt->file_name, 1);
 ft_putstr_fd("Script done on ", opt->fd_file);
 ft_putstr_fd(ctime(&tv.tv_sec), opt->fd_file);
}

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

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 winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
ssize_t __fastcall wait_fd(__int64 a1)
{
int v2; // edi
int v3; // edi
ssize_t result; // rax
int v5; // ebp
int v6; // ebp
fd_set v7; // [rsp+0h] [rbp-1098h] BYREF
char buf[4120]; // [rsp+80h] [rbp-1018h] BYREF

v7.fds_bits[0] |= 1uLL;
v2 = *(_DWORD *)(a1 + 37168);
v7.fds_bits[v2 / 64] |= 1LL << (v2 % 64);
if ( select(v2 + 1, &v7, 0LL, 0LL, 0LL) == -1 )
ft_errorexit("select");
if ( (v7.fds_bits[0] & 1) != 0 )
{
v5 = read(0, buf, 0xFFFuLL);
if ( v5 <= 0 )
reset_exit(a1);
write(*(_DWORD *)(a1 + 37168), buf, v5);
}
v3 = *(_DWORD *)(a1 + 37168);
result = v3 / 64;
if ( (v7.fds_bits[result] & (1LL << (v3 % 64))) != 0 )
{
v6 = read(v3, buf, 0xFFFuLL);
if ( v6 <= 0 )
reset_exit(a1);
write(1, buf, v6);
result = write(*(_DWORD *)(a1 + 24), buf, v6);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(__int64 a1)
{
int v2; // edi
int v3; // edi
ssize_t result; // rax
int v5; // ebp
int v6; // ebp
fd_set v7; // [rsp+0h] [rbp-1098h] BYREF
char buf[4120]; // [rsp+80h] [rbp-1018h] BYREF

v7.fds_bits[0] |= 1uLL;
v2 = *(_DWORD *)(a1 + 37168);
v7.fds_bits[v2 / 64] |= 1LL << (v2 % 64);
if ( select(v2 + 1, &v7, 0LL, 0LL, 0LL) == -1 )
ft_errorexit("select");
if ( (v7.fds_bits[0] & 1) != 0 )
{
v5 = read(0, buf, 0xFFFuLL);
if ( v5 <= 0 )
reset_exit(a1);
write(*(_DWORD *)(a1 + 37168), buf, v5);
}
v3 = *(_DWORD *)(a1 + 37168);
result = v3 / 64;
if ( (v7.fds_bits[result] & (1LL << (v3 % 64))) != 0 )
{
v6 = read(v3, buf, 0xFFFuLL);
if ( v6 <= 0 )
reset_exit(a1);
write(1, buf, v6);
result = write(*(_DWORD *)(a1 + 24), buf, v6);
}
return result;
}

original_code:
void wait_fd(t_opt *opt)
{
 char buff[4096];
 int nb_read;
 fd_set fd;
 ((void) (((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&fd)->__fds_bits)[((opt->fd_master) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((opt->fd_master) % (8 * (int) sizeof (__fd_mask)))))));
 if (select(opt->fd_master + 1, &fd, ((void *)0), ((void *)0), ((void *)0)) == -1)
  ft_errorexit("select");
 if (((((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  if ((nb_read = read(0, buff, 4095)) <= 0)
   reset_exit(opt);
  write(opt->fd_master, buff, nb_read);
 }
 if (((((&fd)->__fds_bits)[((opt->fd_master) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((opt->fd_master) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  if ((nb_read = read(opt->fd_master, buff, 4095)) <= 0)
   reset_exit(opt);
  write(1, buff, nb_read);
  write(opt->fd_file, buff, nb_read);
 }
}

canonical_original_code:
void wait_fd(struct s_opt *opt)
{
 char buff[4096];
 int nb_read;
 struct fd_set fd;
 ((void) (((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
 ((void) (((&fd)->__fds_bits)[((opt->fd_master) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((opt->fd_master) % (8 * (int) sizeof (__fd_mask)))))));
 if (select(opt->fd_master + 1, &fd, ((void *)0), ((void *)0), ((void *)0)) == -1)
  ft_errorexit("select");
 if (((((&fd)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  if ((nb_read = read(0, buff, 4095)) <= 0)
   reset_exit(opt);
  write(opt->fd_master, buff, nb_read);
 }
 if (((((&fd)->__fds_bits)[((opt->fd_master) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((opt->fd_master) % (8 * (int) sizeof (__fd_mask)))))) != 0))
 {
  if ((nb_read = read(opt->fd_master, buff, 4095)) <= 0)
   reset_exit(opt);
  write(1, buff, nb_read);
  write(opt->fd_file, buff, nb_read);
 }
}

variable_types:
buff
char [4096]

variable_types:
fd
struct fd_set { long __fds_bits[-1]; }


decompiled_code:
__int64 __fastcall concat_str(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

if ( !a1 || !a2 )
return 0LL;
v4 = ft_strjoin(a1, &unk_148);
v2 = ft_strjoin(v4, a2);
ft_strdel(&v4);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

if ( !a1 || !a2 )
return 0LL;
v4 = ft_strjoin(a1, &unk_148);
v2 = ft_strjoin(v4, a2);
ft_strdel(&v4);
return v2;
}

original_code:
static char *concat_str(char *s1, char *s2)
{
 char *new_str;
 char *tmp;
 if (s1 && s2)
 {
  new_str = ft_strjoin(s1, " ");
  tmp = new_str;
  new_str = ft_strjoin(new_str, s2);
  ft_strdel(&tmp);
  return (new_str);
 }
 return (((void *)0));
}

variable_types:
tmp
char *

return_type: char *


original_code:
t_token *token_lst_add(t_token *new_token, t_token *token_list)
{
 t_token *curr;
 char *tmp;
 if (!token_list)
  return (new_token);
 if (!new_token)
  return (token_list);
 curr = token_list;
 while (curr->next)
  curr = curr->next;
 if (curr->type == word && new_token->type == word && (tmp = curr->str))
 {
  curr->str = concat_str(curr->str, new_token->str);
  token_free(&new_token);
  ft_strdel(&tmp);
 }
 else
 {
  curr->next = new_token;
  new_token->prev = curr;
  if (curr->type != pipes && is_redir_operator(curr->str) != unknown
    && new_token->type == word)
   new_token->type = redir_dest;
 }
 return (token_list);
}

canonical_original_code:
struct s_token *token_lst_add(struct s_token *new_token, struct s_token *token_list)
{
 struct s_token *curr;
 char *tmp;
 if (!token_list)
  return (new_token);
 if (!new_token)
  return (token_list);
 curr = token_list;
 while (curr->next)
  curr = curr->next;
 if (curr->type == word && new_token->type == word && (tmp = curr->str))
 {
  curr->str = concat_str(curr->str, new_token->str);
  token_free(&new_token);
  ft_strdel(&tmp);
 }
 else
 {
  curr->next = new_token;
  new_token->prev = curr;
  if (curr->type != pipes && is_redir_operator(curr->str) != unknown
    && new_token->type == word)
   new_token->type = redir_dest;
 }
 return (token_list);
}

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


original_code:
t_token *token_add(char *str, t_sym type, t_token *token_list)
{
 t_token *curr;
 t_token *new;
 if (!(new = create_token()))
  return (((void *)0));
 new->str = ft_strdup(str);
 new->type = type;
 if (!token_list)
  return (new);
 curr = token_list;
 while (curr->next)
  curr = curr->next;
 curr->next = new;
 new->prev = curr;
 return (token_list);
}

canonical_original_code:
struct s_token *token_add(char *str, enum e_sym type, struct s_token *token_list)
{
 struct s_token *curr;
 struct s_token *new;
 if (!(new = create_token()))
  return (((void *)0));
 new->str = ft_strdup(str);
 new->type = type;
 if (!token_list)
  return (new);
 curr = token_list;
 while (curr->next)
  curr = curr->next;
 curr->next = new;
 new->prev = curr;
 return (token_list);
}

variable_types:
str
char *

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


decompiled_code:
__int64 __fastcall ft_joinfree(void *ptr, void *a2, int a3)
{
__int64 v4; // r13

v4 = ft_strjoin((char *)ptr, (char *)a2);
if ( (a3 & 0xFFFFFFFD) == 1 && ptr )
free(ptr);
if ( (unsigned int)(a3 - 2) <= 1 && a2 )
free(a2);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, void *a2, int a3)
{
__int64 v4; // r13

v4 = func0((char *)ptr, (char *)a2);
if ( (a3 & 0xFFFFFFFD) == 1 && ptr )
free(ptr);
if ( (unsigned int)(a3 - 2) <= 1 && a2 )
free(a2);
return v4;
}

original_code:
char *ft_joinfree(char *s1, char *s2, int free_str)
{
 char *ret;
 ret = ((void *)0);
 if (!s1 || !s2)
  return (((void *)0));
 ret = ft_strjoin(s1, s2);
 if (free_str == 1 || free_str == 3)
  free(s1);
 if (free_str == 2 || free_str == 3)
  free(s2);
 return(ret);
}

variable_types:
ret
char *


original_code:
char *ft_strjoin(char const *s1, char const *s2)
{
 int i;
 char *ret;
 if (!s1 || !s2)
  return (((void *)0));
 if ((ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) == ((void *)0))
  return (((void *)0));
 i = 0;
 while (*s1)
  ret[i++] = *(s1++);
 while (*s2)
  ret[i++] = *(s2++);
 return (ret);
}

canonical_original_code:
char *ft_strjoin(char *s1, char *s2)
{
 int i;
 char *ret;
 if (!s1 || !s2)
  return (((void *)0));
 if ((ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) == ((void *)0))
  return (((void *)0));
 i = 0;
 while (*s1)
  ret[i++] = *(s1++);
 while (*s2)
  ret[i++] = *(s2++);
 return (ret);
}

variable_types: i int


decompiled_code:
__int64 __fastcall ft_putstr_c(__int64 a1, int a2)
{
ft_putstr("\x1B[0m");
switch ( a2 )
{
case 1:
ft_putstr("\x1B[31m");
break;
case 2:
ft_putstr("\x1B[32m");
LABEL_5:
if ( a2 == 5 )
{
ft_putstr("\x1B[35m");
goto LABEL_9;
}
goto LABEL_6;
case 3:
ft_putstr("\x1B[33m");
LABEL_6:
if ( a2 == 6 )
{
ft_putstr("\x1B[36m");
goto LABEL_9;
}
goto LABEL_7;
}
if ( a2 != 4 )
goto LABEL_5;
ft_putstr("\x1B[34m");
LABEL_7:
if ( a2 == 7 )
ft_putstr("\x1B[37m");
LABEL_9:
ft_putstr(a1);
return ft_putstr("\x1B[0m");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
ft_putstr("\x1B[0m");
switch ( a2 )
{
case 1:
ft_putstr("\x1B[31m");
break;
case 2:
ft_putstr("\x1B[32m");
LABEL_5:
if ( a2 == 5 )
{
ft_putstr("\x1B[35m");
goto LABEL_9;
}
goto LABEL_6;
case 3:
ft_putstr("\x1B[33m");
LABEL_6:
if ( a2 == 6 )
{
ft_putstr("\x1B[36m");
goto LABEL_9;
}
goto LABEL_7;
}
if ( a2 != 4 )
goto LABEL_5;
ft_putstr("\x1B[34m");
LABEL_7:
if ( a2 == 7 )
ft_putstr("\x1B[37m");
LABEL_9:
ft_putstr(a1);
return ft_putstr("\x1B[0m");
}

variable_types:
s
char *

variable_types: c int


original_code:
int search_endstr(t_cmd *start, int i)
{
 t_cmd *tmp;
 t_cmd *tmp2;
 char *str_tmp;
 tmp = start;
 while (tmp->value[i] != '"' || tmp->value[i - 1] == '\\')
 {
  if (tmp->value[i++] == '\0')
  {
   if (tmp->next == ((void *)0))
    return (-1);
   str_tmp = ft_strjoin(tmp->value, ";");
   free(tmp->value);
   tmp->value = str_tmp;
   str_tmp = ft_strjoin(tmp->value, tmp->next->value);
   free(tmp->value);
   tmp->value = str_tmp;
   tmp2 = tmp->next;
   tmp->next = tmp2->next;
   if (tmp2->next == ((void *)0))
    tmp->next = ((void *)0);
   free(tmp2);
  }
 }
 return (i + 1);
}

canonical_original_code:
int search_endstr(struct s_cmd *start, int i)
{
 struct s_cmd *tmp;
 struct s_cmd *tmp2;
 char *str_tmp;
 tmp = start;
 while (tmp->value[i] != '"' || tmp->value[i - 1] == '\\')
 {
  if (tmp->value[i++] == '\0')
  {
   if (tmp->next == ((void *)0))
    return (-1);
   str_tmp = ft_strjoin(tmp->value, ";");
   free(tmp->value);
   tmp->value = str_tmp;
   str_tmp = ft_strjoin(tmp->value, tmp->next->value);
   free(tmp->value);
   tmp->value = str_tmp;
   tmp2 = tmp->next;
   tmp->next = tmp2->next;
   if (tmp2->next == ((void *)0))
    tmp->next = ((void *)0);
   free(tmp2);
  }
 }
 return (i + 1);
}

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


original_code:
t_cmd *clean_cmd(t_cmd *start)
{
 t_cmd *tmp;
 char *cmd;
 int i;
 i = 0;
 tmp = start;
 while (tmp)
 {
  i = 0;
  while (tmp->value[i])
  {
   if (tmp->value[i] == '"' && tmp->value[i - 1] != '\\')
   {
    if ((i = search_endstr(tmp, i + 1)) == -1)
     return (((void *)0));
   }
   i++;
  }
  cmd = ft_strtrim(tmp->value);
  free(tmp->value);
  tmp->value = ft_strdelc(cmd, '"');
  free(cmd);
  tmp = tmp->next;
 }
 return (start);
}

canonical_original_code:
struct s_cmd *clean_cmd(struct s_cmd *start)
{
 struct s_cmd *tmp;
 char *cmd;
 int i;
 i = 0;
 tmp = start;
 while (tmp)
 {
  i = 0;
  while (tmp->value[i])
  {
   if (tmp->value[i] == '"' && tmp->value[i - 1] != '\\')
   {
    if ((i = search_endstr(tmp, i + 1)) == -1)
     return (((void *)0));
   }
   i++;
  }
  cmd = ft_strtrim(tmp->value);
  free(tmp->value);
  tmp->value = ft_strdelc(cmd, '"');
  free(cmd);
  tmp = tmp->next;
 }
 return (start);
}

variable_types:
start
struct s_cmd *

variable_types:
cmd
char *

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


decompiled_code:
void __fastcall parse_name(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax

v1 = a1;
while ( v1 )
{
v2 = (_QWORD *)ft_strsplit(v1[1], 32LL);
*v1 = *v2;
v1 = (_QWORD *)v1[4];
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rax

v1 = a1;
while ( v1 )
{
v2 = (_QWORD *)ft_strsplit(v1[1], 32LL);
*v1 = *v2;
v1 = (_QWORD *)v1[4];
free(v2);
}
}

original_code:
void parse_name(t_cmd *cmd)
{
 char **tmp;
 while (cmd)
 {
  tmp = ft_strsplit(cmd->value, ' ');
  cmd->name = tmp[0];
  cmd = cmd->next;
  free(tmp);
 }
}

canonical_original_code:
void parse_name(struct s_cmd *cmd)
{
 char **tmp;
 while (cmd)
 {
  tmp = ft_strsplit(cmd->value, ' ');
  cmd->name = tmp[0];
  cmd = cmd->next;
  free(tmp);
 }
}

variable_types:
tmp
char **

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


decompiled_code:
__int64 __fastcall assign_file_out(__int64 a1)
{
_QWORD *v1; // rbp
_QWORD *v2; // rbp

*(_DWORD *)(a1 + 24) = ft_strstr(*(_QWORD *)(a1 + 8), &unk_282) == 0 ? 2 : 6;
v1 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 62LL);
*(_QWORD *)(a1 + 8) = *v1;
if ( !v1[1] )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = ((__int64 (*)(void))ft_strtrim)();
free(v1);
v2 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 32LL);
*(_QWORD *)a1 = ft_strtrim(*v2);
free(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
_QWORD *v1; // rbp
_QWORD *v2; // rbp

*(_DWORD *)(a1 + 24) = ft_strstr(*(_QWORD *)(a1 + 8), &unk_282) == 0 ? 2 : 6;
v1 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 62LL);
*(_QWORD *)(a1 + 8) = *v1;
if ( !v1[1] )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = ((__int64 (*)(void))ft_strtrim)();
free(v1);
v2 = (_QWORD *)ft_strsplit(*(_QWORD *)(a1 + 8), 32LL);
*(_QWORD *)a1 = ft_strtrim(*v2);
free(v2);
return 0LL;
}

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

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

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_colon(__int64 a1)
{
__int64 v1; // rdi
__int64 result; // rax

if ( *(_DWORD *)a1 != 8 )
return parse_error(*(_QWORD *)(a1 + 8));
v1 = *(_QWORD *)(a1 + 16);
result = 1LL;
if ( v1 )
result = check_exp(v1);
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);
result = 1LL;
if ( v1 )
result = func0(v1);
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));
}


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; // edx
__int64 result; // rax

if ( *(_DWORD *)a1 == 4 || (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();
result = 1LL;
if ( v3 == 7 )
result = check_background();
return result;
}

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

if ( *(_DWORD *)a1 == 4 || (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();
result = 1LL;
if ( v3 == 7 )
result = check_background();
return result;
}

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; // rdi
int v4; // 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);
if ( (unsigned int)is_redir_operator(*(_QWORD *)(v2 + 8)) != 11 )
return check_redir(*(_QWORD *)(a1 + 16));
v3 = *(int **)(a1 + 16);
v4 = *v3;
if ( *v3 == 8 )
return check_colon((__int64)v3);
if ( (unsigned int)(v4 - 5) <= 1 )
return check_logical();
if ( v4 == 7 )
return check_background();
return parse_error(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // rdi
int *v3; // rdi
int v4; // 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);
if ( (unsigned int)is_redir_operator(*(_QWORD *)(v2 + 8)) != 11 )
return func3(*(_QWORD *)(a1 + 16));
v3 = *(int **)(a1 + 16);
v4 = *v3;
if ( *v3 == 8 )
return func1((__int64)v3);
if ( (unsigned int)(v4 - 5) <= 1 )
return check_logical();
if ( v4 == 7 )
return check_background();
return parse_error(*(_QWORD *)(a1 + 8));
}

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 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");
*(_DWORD *)(i + 12) = pipedes[1];
*(_DWORD *)(*(_QWORD *)(i + 24) + 8LL) = pipedes[0];
}
ft_fork(i, a2);
ft_close_pipe(i);
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, __int64 a2)
{
__int64 i; // rbx
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");
*(_DWORD *)(i + 12) = pipedes[1];
*(_DWORD *)(*(_QWORD *)(i + 24) + 8LL) = pipedes[0];
}
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]

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; // rbx
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

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

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

v2 = get_token_lst();
v0 = 0LL;
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: 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; // rbx
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rbp
__int64 v8; // rax
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // rsi
__int64 v14; // rax

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) )
{
v14 = ft_getenv("PWD=");
v7 = ft_strdup(v14);
}
else
{
v5 = ft_getenv("PWD=");
v6 = ft_strdup(v5 + v2);
v7 = ft_joinfree("~", v6, 2LL);
}
}
else
{
v8 = ft_getenv("PWD=");
v9 = ft_strsplit(v8, 47LL);
if ( *(_QWORD *)(v9 + 8) )
{
v10 = 1LL;
do
v11 = v10++;
while ( *(_QWORD *)(v9 + 8 * v10) );
}
else
{
v11 = 0LL;
}
v12 = ft_strdup(*(_QWORD *)(v9 + 8 * v11));
v7 = ft_joinfree("/", v12, 2LL);
ft_freesplit(v9);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rax
__int64 v2; // rbx
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rbp
__int64 v8; // rax
__int64 v9; // rbx
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // rsi
__int64 v14; // rax

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) )
{
v14 = ft_getenv("PWD=");
v7 = ft_strdup(v14);
}
else
{
v5 = ft_getenv("PWD=");
v6 = ft_strdup(v5 + v2);
v7 = ft_joinfree("~", v6, 2LL);
}
}
else
{
v8 = ft_getenv("PWD=");
v9 = ft_strsplit(v8, 47LL);
if ( *(_QWORD *)(v9 + 8) )
{
v10 = 1LL;
do
v11 = v10++;
while ( *(_QWORD *)(v9 + 8 * v10) );
}
else
{
v11 = 0LL;
}
v12 = ft_strdup(*(_QWORD *)(v9 + 8 * v11));
v7 = ft_joinfree("/", v12, 2LL);
ft_freesplit(v9);
}
return v7;
}

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


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

if ( a1 == 110 )
{
v3 = 0;
goto LABEL_22;
}
v2 = 1LL;
do
{
v3 = v2;
v4 = byte_5AF[v2++];
}
while ( v4 != a1 && v4 );
result = 0LL;
if ( v4 )
{
if ( v3 )
{
v6 = 0LL;
if ( v3 == 1 )
{
v6 = (__int64)ft_gettime(1);
goto LABEL_10;
}
LABEL_8:
if ( v3 == 2 )
{
v6 = (__int64)ft_gettime(0);
LABEL_11:
if ( v3 == 5 )
{
v6 = ft_getdir(1);
LABEL_14:
if ( v3 == 8 )
{
v6 = ft_strdup("\x1B[32m");
LABEL_17:
if ( v3 == 11 )
v6 = ft_strdup("\x1B[35m");
goto LABEL_19;
}
LABEL_15:
if ( v3 == 9 )
{
v6 = ft_strdup("\x1B[33m");
goto LABEL_19;
}
LABEL_16:
if ( v3 != 10 )
goto LABEL_17;
v6 = ft_strdup("\x1B[34m");
LABEL_19:
*(_QWORD *)(a2 + 8) = ft_joinfree(*(_QWORD *)(a2 + 8), v6, 3LL);
return 1LL;
}
goto LABEL_12;
}
if ( v3 == 3 )
{
v8 = ft_getenv("PWD=");
v6 = ft_strdup(v8);
LABEL_12:
if ( v3 == 6 )
{
v6 = ft_strdup("\x1B[0m");
goto LABEL_15;
}
goto LABEL_13;
}
LABEL_10:
if ( v3 == 4 )
{
v6 = ft_getdir(1);
LABEL_13:
if ( v3 == 7 )
{
v6 = ft_strdup("\x1B[31m");
goto LABEL_16;
}
goto LABEL_14;
}
goto LABEL_11;
}
LABEL_22:
v7 = ft_getenv("USER=");
v6 = ft_strdup(v7);
goto LABEL_8;
}
return result;
}

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

if ( a1 == 110 )
{
v3 = 0;
goto LABEL_22;
}
v2 = 1LL;
do
{
v3 = v2;
v4 = byte_5AF[v2++];
}
while ( v4 != a1 && v4 );
result = 0LL;
if ( v4 )
{
if ( v3 )
{
v6 = 0LL;
if ( v3 == 1 )
{
v6 = (__int64)func0(1);
goto LABEL_10;
}
LABEL_8:
if ( v3 == 2 )
{
v6 = (__int64)func0(0);
LABEL_11:
if ( v3 == 5 )
{
v6 = func1(1);
LABEL_14:
if ( v3 == 8 )
{
v6 = ft_strdup("\x1B[32m");
LABEL_17:
if ( v3 == 11 )
v6 = ft_strdup("\x1B[35m");
goto LABEL_19;
}
LABEL_15:
if ( v3 == 9 )
{
v6 = ft_strdup("\x1B[33m");
goto LABEL_19;
}
LABEL_16:
if ( v3 != 10 )
goto LABEL_17;
v6 = ft_strdup("\x1B[34m");
LABEL_19:
*(_QWORD *)(a2 + 8) = ft_joinfree(*(_QWORD *)(a2 + 8), v6, 3LL);
return 1LL;
}
goto LABEL_12;
}
if ( v3 == 3 )
{
v8 = ft_getenv("PWD=");
v6 = ft_strdup(v8);
LABEL_12:
if ( v3 == 6 )
{
v6 = ft_strdup("\x1B[0m");
goto LABEL_15;
}
goto LABEL_13;
}
LABEL_10:
if ( v3 == 4 )
{
v6 = func1(1);
LABEL_13:
if ( v3 == 7 )
{
v6 = ft_strdup("\x1B[31m");
goto LABEL_16;
}
goto LABEL_14;
}
goto LABEL_11;
}
LABEL_22:
v7 = ft_getenv("USER=");
v6 = ft_strdup(v7);
goto LABEL_8;
}
return result;
}

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 *

variable_types:
tmp
char *


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

variable_types: i int

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


decompiled_code:
__int64 __fastcall check_access(char *name)
{
int v1; // edx
__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; // edx
__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


decompiled_code:
void __fastcall search_first_posi(int *a1, int *a2, __int64 a3)
{
int *v3; // r14
int v6; // er12
int v7; // er13
int v8; // edx

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

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:
void *__fastcall concat_path(__int64 a1, __int64 a2)
{
__int64 v2; // r12
__int64 v3; // rax
void *result; // rax
__int64 v5; // rax
__int64 v6; // rax

v2 = ((__int64 (*)(void))ft_strlen)();
v3 = ft_strlen(a2);
result = malloc(v2 + v3 + 2);
if ( result )
{
v5 = ft_strcpy(result, a1);
v6 = ft_strcat(v5, &unk_189);
result = (void *)ft_strcat(v6, a2);
}
return result;
}

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

v2 = ((__int64 (*)(void))ft_strlen)();
v3 = ft_strlen(a2);
result = malloc(v2 + v3 + 2);
if ( result )
{
v5 = ft_strcpy(result, a1);
v6 = ft_strcat(v5, &unk_189);
result = (void *)ft_strcat(v6, a2);
}
return result;
}

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; // rdi
int v6; // eax
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
const char *v8; // [rsp+8h] [rbp-20h] BYREF

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

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

result = (const char *)get_var_env("PATH=", *(_QWORD *)a2);
v8 = result;
if ( result )
{
v7 = ft_strsplit(result, 58LL);
v4 = 0LL;
do
{
v5 = *(_QWORD *)(v7 + v4);
if ( !v5 )
break;
v8 = (const char *)func0(v5, a1);
if ( access(v8, 0) != -1 )
{
v6 = check_access(v8);
*(_DWORD *)(a2 + 48) = v6;
if ( !v6 )
break;
}
*(_DWORD *)(a2 + 48) = check_access(v8);
ft_strdel(&v8);
v4 += 8LL;
}
while ( *(_DWORD *)(a2 + 48) != 4 );
free_split(&v7);
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 **


decompiled_code:
const char *__fastcall check_and_get_path(const char *a1, __int64 a2)
{
const char *v2; // rbx
__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 )
v2 = 0LL;
}
else if ( *a1 != 47 && (v3 = get_var_env("PWD=", *(_QWORD *)a2), (unsigned int)ft_strcmp(&unk_189, v3)) )
{
v2 = find_path_exec((__int64)a1, a2);
}
else
{
v4 = check_access(a1);
*(_DWORD *)(a2 + 48) = v4;
if ( v4 )
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1, __int64 a2)
{
const char *v2; // rbx
__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 )
v2 = 0LL;
}
else if ( *a1 != 47 && (v3 = get_var_env("PWD=", *(_QWORD *)a2), (unsigned int)ft_strcmp(&unk_189, v3)) )
{
v2 = func1((__int64)a1, a2);
}
else
{
v4 = check_access(a1);
*(_DWORD *)(a2 + 48) = v4;
if ( v4 )
v2 = 0LL;
}
return v2;
}

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 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; // ebp
unsigned __int8 v3; // di
unsigned __int8 *v4; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1)
{
unsigned int v1; // ebp
unsigned __int8 v3; // di
unsigned __int8 *v4; // rbx

v1 = 0;
if ( a1 )
{
v3 = *a1;
if ( (v3 & 0xDF) != 0 )
{
v4 = a1 + 1;
do
{
if ( (unsigned int)func0(v3) )
break;
++v1;
v3 = *v4++;
}
while ( (v3 & 0xDF) != 0 );
}
else
{
v1 = 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 *

variable_types: i int


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)
{
int v1; // er12
char *v2; // rbp
char i; // al
unsigned __int8 v4; // bl

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

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1)
{
int v1; // er12
char *v2; // rbp
char i; // al
unsigned __int8 v4; // bl

v1 = *a1 == 39 || *a1 == 34;
v2 = (char *)&a1[*a1 == 39 || *a1 == 34];
for ( i = *v2; *v2; i = *++v2 )
{
v4 = i;
if ( !(unsigned int)func2(i) )
break;
if ( (unsigned int)func0(v4) )
break;
++v1;
}
return 2 * (unsigned int)((unsigned int)func1(a1) != v1) + 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)
{
__int64 result; // rax

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

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

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

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

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_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)
{
char v3; // di
__int64 result; // rax
__int64 v5; // rbx
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

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

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

v6[0] = ft_strtrim();
if ( !(unsigned int)ft_strncmp(v6[0], "exit", 4LL) )
{
v3 = *(_BYTE *)(v6[0] + 4);
if ( !v3 || (unsigned int)ft_isspace((unsigned int)v3) == 1 )
{
ft_strdel(v6);
destroy_gen();
exit(0);
}
}
result = ft_strdel(v6);
if ( a1 )
{
if ( *a1 )
{
v5 = parser(a1);
ft_command(v5, a2);
result = command_lst_free(v5);
}
}
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 *

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


decompiled_code:
int __fastcall updat_prompt(__int64 a1)
{
__int64 v1; // rbp
int result; // eax
int i; // 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");
for ( i = result; i; --i )
{
v4 = *(_DWORD *)(*(_QWORD *)(v1 + 24) + 120LL);
v5 = tgetstr("kl", 0LL);
result = ft_putstr_fd(v5, v4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
int result; // eax
int i; // 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");
for ( i = result; i; --i )
{
v4 = *(_DWORD *)(*(_QWORD *)(v1 + 24) + 120LL);
v5 = tgetstr("kl", 0LL);
result = ft_putstr_fd(v5, v4);
}
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; // rbx
_QWORD *v4; // rbp

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

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

init_env(envp, argv);
v3 = recup_gen();
v4 = *(_QWORD **)(v3 + 16);
*v4 = ft_strdup("[%1%*%0]-[%2%d%0]>");
parse_ps1(*(_QWORD *)(v3 + 16));
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(char *a1)
{
__int64 result; // rax

result = is_logical_operator(a1);
if ( (_DWORD)result == 11 )
{
if ( *a1 != 124 || (result = 4LL, 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);
}
}
}
return result;
}

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

result = func3(a1);
if ( (_DWORD)result == 11 )
{
if ( *a1 != 124 || (result = 4LL, a1[1] == 124) )
{
result = func0(a1);
if ( (_DWORD)result == 11 )
{
result = func1(a1);
if ( (_DWORD)result == 11 )
result = func2(a1);
}
}
}
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; // rbx
char *v5; // rax
unsigned __int64 v6; // r13
char v8[4136]; // [rsp+0h] [rbp-1028h] BYREF

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

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

ft_bzero(v8, 4096LL);
v4 = (char *)ft_strtrim(a1 + 3);
if ( chdir(v4) == -1 )
{
send(a2, "ERROR you dont have right", 0x19uLL, 0);
}
else
{
v5 = getcwd(v8, 0x1000uLL);
v6 = ft_strlen(v5);
if ( v6 < ft_strlen(a3) )
{
chdir(a3);
send(a2, "ERROR you dont have right", 0x19uLL, 0);
}
else
{
send(a2, "SUCCESS", 7uLL, 0);
}
}
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; // rbp
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; // rbp
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)
{
__int64 *v1; // rbp
unsigned int v2; // er12
__int64 v3; // rdi
__int64 i; // rbx

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

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

if ( a1 )
{
v1 = a1;
v2 = 1;
do
{
ft_putstr("Command ");
v3 = v2++;
ft_putnbr(v3);
ft_putstr(" : [");
for ( i = *v1; i; i = *(_QWORD *)(i + 16) )
ft_putstr(*(_QWORD *)(i + 8));
ft_putstr("]\n");
job_lst_print(v1[1]);
v1 = (__int64 *)v1[3];
}
while ( v1 );
}
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

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) )
{
*(_BYTE *)(v2 + v3 + 4108) = a2;
++*(_DWORD *)(*(_QWORD *)(a1 + 32) + 4096LL);
++*(_DWORD *)(*(_QWORD *)(a1 + 32) + 4100LL);
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