decompiled_code:
__int64 __fastcall dlaunch_cmd(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // er12
__int64 result; // rax

if ( !a1 )
return 1LL;
v3 = a3;
result = get_cmd(*(_QWORD *)(a1 + 16), a2, 0LL, a3);
if ( (_BYTE)result )
{
if ( (unsigned __int8)dlaunch_cmd(*(_QWORD *)(a1 + 8), a2, v3) )
result = 1LL;
else
result = nullify_all_pipes(*(_QWORD *)(a1 + 16));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // er12
__int64 result; // rax

if ( !a1 )
return 1LL;
v3 = a3;
result = get_cmd(*(_QWORD *)(a1 + 16), a2, 0LL, a3);
if ( (_BYTE)result )
{
if ( (unsigned __int8)func2(*(_QWORD *)(a1 + 8), a2, v3) )
result = 1LL;
else
result = nullify_all_pipes(*(_QWORD *)(a1 + 16));
}
return result;
}

original_code:
static unsigned char dlaunch_cmd(t_exec *exec, char **bad_sintax, unsigned char sub)
{
  if (!exec)
    return (1);
  if (!get_cmd(exec->pipes, bad_sintax, ((void *)0), sub))
    return (0);
  if (dlaunch_cmd(exec->next, bad_sintax, sub) == 0)
    return (nullify_all_pipes(exec->pipes));
  return (1);
}

canonical_original_code:
static unsigned char dlaunch_cmd(struct s_exec *exec, char **bad_sintax, unsigned char sub)
{
  if (!exec)
    return (1);
  if (!get_cmd(exec->pipes, bad_sintax, ((void *)0), sub))
    return (0);
  if (dlaunch_cmd(exec->next, bad_sintax, sub) == 0)
    return (nullify_all_pipes(exec->pipes));
  return (1);
}

variable_types:
sub
unsigned char


decompiled_code:
__int64 __fastcall launch_cmd(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // er12
char v5; // al
__int64 v6; // rdi
__int64 v8; // rsi

if ( !a1 )
return 1LL;
v3 = a3;
v5 = dlaunch_cmd(*(_QWORD *)(a1 + 16), a2, a3);
v6 = *(_QWORD *)(a1 + 8);
if ( v5 )
{
if ( (unsigned __int8)launch_cmd(v6, a2, v3) )
return 1LL;
v8 = 0LL;
}
else
{
nullify_all_jobs(v6);
v8 = 1LL;
}
return nullify_jobs(a1, v8);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // er12
char v5; // al
__int64 v6; // rdi
__int64 v8; // rsi

if ( !a1 )
return 1LL;
v3 = a3;
v5 = func2(*(_QWORD *)(a1 + 16), a2, a3);
v6 = *(_QWORD *)(a1 + 8);
if ( v5 )
{
if ( (unsigned __int8)func3(v6, a2, v3) )
return 1LL;
v8 = 0LL;
}
else
{
nullify_all_jobs(v6);
v8 = 1LL;
}
return nullify_jobs(a1, v8);
}

original_code:
static unsigned char launch_cmd(t_jobs *exec, char **bad_sintax, unsigned char sub)
{
  if (!exec)
    return (1);
  if (!dlaunch_cmd(exec->exec, bad_sintax, sub))
    {
      nullify_all_jobs(exec->next);
      return (nullify_jobs(exec, 1));
    }
  if (launch_cmd(exec->next, bad_sintax, sub) == 0)
    return (nullify_jobs(exec, 0));
  return (1);
}

canonical_original_code:
static unsigned char launch_cmd(struct s_jobs *exec, char **bad_sintax, unsigned char sub)
{
  if (!exec)
    return (1);
  if (!dlaunch_cmd(exec->exec, bad_sintax, sub))
    {
      nullify_all_jobs(exec->next);
      return (nullify_jobs(exec, 1));
    }
  if (launch_cmd(exec->next, bad_sintax, sub) == 0)
    return (nullify_jobs(exec, 0));
  return (1);
}

variable_types: struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes { struct s_pipes *next; struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *tmp; struct s_cmd { struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *redir; unsigned int type; struct s_words { char *word; struct s_words *next; } *params; struct s_jobs *parents; } *cmd; } *pipes; struct s_get *tmp; } *exec; struct s_get *tmp; } *

return_type: unsigned char

user_defined_types: struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec *exec; struct s_get *tmp; }

user_defined_types: struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes *pipes; struct s_get *tmp; }

user_defined_types: struct s_pipes { struct s_pipes *next; struct s_get *tmp; struct s_cmd *cmd; }

user_defined_types: struct s_cmd { struct s_redir *redir; unsigned int type; struct s_words *params; struct s_jobs *parents; }


decompiled_code:
void __fastcall catch_signal(int a1)
{
__int64 v1; // rax
unsigned int v2; // [rsp+4h] [rbp-64h] BYREF
__int64 v3; // [rsp+8h] [rbp-60h] BYREF
char v4[88]; // [rsp+10h] [rbp-58h] BYREF

retain_struct_options(2LL, v4);
retain_cmd(2LL, &v3);
if ( a1 == 2 )
{
v2 = 0;
show_cmd(10LL, 0LL, v3, 0LL);
my_putstr(&unk_131, 1LL);
prompt(1LL);
v1 = my_strlen(v3);
v3 = my_memset(v3, 0LL, v1);
retain_reverse_case(1LL, &v2);
show_cmd(0LL, 10LL, v3, v2);
my_putstr(&unk_133, 1LL);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
__int64 v1; // rax
unsigned int v2; // [rsp+4h] [rbp-64h] BYREF
__int64 v3; // [rsp+8h] [rbp-60h] BYREF
char v4[88]; // [rsp+10h] [rbp-58h] BYREF

retain_struct_options(2LL, v4);
retain_cmd(2LL, &v3);
if ( a1 == 2 )
{
v2 = 0;
show_cmd(10LL, 0LL, v3, 0LL);
my_putstr(&unk_131, 1LL);
prompt(1LL);
v1 = my_strlen(v3);
v3 = my_memset(v3, 0LL, v1);
retain_reverse_case(1LL, &v2);
show_cmd(0LL, 10LL, v3, v2);
my_putstr(&unk_133, 1LL);
}
}

original_code:
void catch_signal(int num)
{
  char *save_cmd;
  t_options tmp;
  int rev_c;
  retain_struct_options(2, &tmp);
  retain_cmd(2, &save_cmd);
  if (num == 2)
    {
      rev_c = 0;
      show_cmd(10, 0, save_cmd, rev_c);
      my_putstr("\n", 1);
      prompt(1);
      save_cmd = my_memset(save_cmd, 0, my_strlen(save_cmd));
      retain_reverse_case(1, &rev_c);
      show_cmd(0, 10, save_cmd, rev_c);
      my_putstr("\r", 1);
    }
}

canonical_original_code:
void catch_signal(int num)
{
  char *save_cmd;
  struct s_options tmp;
  int rev_c;
  retain_struct_options(2, &tmp);
  retain_cmd(2, &save_cmd);
  if (num == 2)
    {
      rev_c = 0;
      show_cmd(10, 0, save_cmd, rev_c);
      my_putstr("\n", 1);
      prompt(1);
      save_cmd = my_memset(save_cmd, 0, my_strlen(save_cmd));
      retain_reverse_case(1, &rev_c);
      show_cmd(0, 10, save_cmd, rev_c);
      my_putstr("\r", 1);
    }
}

variable_types: num int

variable_types: struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; }

return_type: void


decompiled_code:
unsigned __int64 __fastcall go_down_of_cmd_high(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rtt
int v3; // ebx
char v5[2]; // [rsp+8h] [rbp-20h] BYREF
unsigned __int16 v6; // [rsp+Ah] [rbp-1Eh]

ioctl(0, 0x5413uLL, v5);
v2 = my_strlen(a1);
result = v2 / v6;
v3 = result - 1;
if ( (int)result - 1 >= 0 )
{
do
result = my_putstr(&unk_131, 1LL);
while ( v3-- != 0 );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1)
{
unsigned __int64 result; // rax
unsigned __int64 v2; // rtt
int v3; // ebx
char v5[2]; // [rsp+8h] [rbp-20h] BYREF
unsigned __int16 v6; // [rsp+Ah] [rbp-1Eh]

ioctl(0, 0x5413uLL, v5);
v2 = my_strlen(a1);
result = v2 / v6;
v3 = result - 1;
if ( (int)result - 1 >= 0 )
{
do
result = my_putstr(&unk_131, 1LL);
while ( v3-- != 0 );
}
return result;
}

original_code:
void go_down_of_cmd_high(char *cmd)
{
  int high;
  struct winsize ws;
  ioctl(0, 0x5413, &ws);
  high = (my_strlen(cmd)) / ws.ws_col;
  while (--high >= 0)
    my_putstr("\n", 1);
}

variable_types:
cmd
char *

variable_types: high int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
__sighandler_t configure_signals()
{
return signal(2, catch_signal);
}

canonical_decompiled_code:
__sighandler_t func2()
{
return signal(2, catch_signal);
}

original_code:
void configure_signals()
{
  signal(2, catch_signal);
}


original_code:
void retain_struct_options(int opt, t_options *options)
{
  static t_options save_opt;
  if (opt == 1)
    save_opt = (*options);
  else
    (*options) = save_opt;
}

canonical_original_code:
void retain_struct_options(int opt, struct s_options *options)
{
  static struct s_options save_opt;
  if (opt == 1)
    save_opt = (*options);
  else
    (*options) = save_opt;
}

variable_types: opt int

variable_types: struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; } *


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

if ( a1 == 1 )
{
result = *a2;
save_1 = *a2;
}
else if ( a1 == 2 )
{
result = save_1;
*a2 = save_1;
}
return result;
}

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

if ( a1 == 1 )
{
result = *a2;
save_1 = *a2;
}
else if ( a1 == 2 )
{
result = save_1;
*a2 = save_1;
}
return result;
}

original_code:
void retain_cmd(int opt, char **cmd)
{
  static char *save = ((void *)0);
  if (opt == 1)
    save = (*cmd);
  else if (opt == 2)
    (*cmd) = save;
}

variable_types:
cmd
char **

variable_types:
save
char *


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

if ( a1 == 1 )
{
result = (unsigned int)*a2;
save_0 = *a2;
}
else if ( a1 == 2 )
{
result = (unsigned int)save_0;
*a2 = save_0;
}
return result;
}

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

if ( a1 == 1 )
{
result = (unsigned int)*a2;
save_0 = *a2;
}
else if ( a1 == 2 )
{
result = (unsigned int)save_0;
*a2 = save_0;
}
return result;
}

original_code:
void retain_reverse_case(int opt, int *rev_c)
{
  static int save;
  if (opt == 1)
    save = (*rev_c);
  else if (opt == 2)
    (*rev_c) = save;
}

variable_types: save int


decompiled_code:
__int64 __fastcall redir_type(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
int v5; // er8
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = my_strlen(&unk_3E8);
if ( !(unsigned int)my_strncmp(&unk_3E8, a1, v1) )
return 4LL;
v2 = my_strlen(&unk_3EF);
if ( !(unsigned int)my_strncmp(&unk_3EF, a1, v2) )
return 8LL;
v3 = my_strlen(&unk_3ED);
if ( !(unsigned int)my_strncmp(&unk_3ED, a1, v3) )
return 1LL;
v4 = my_strlen(&unk_3EB);
v5 = my_strncmp(&unk_3EB, a1, v4);
result = 2LL;
if ( v5 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
int v5; // er8
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = my_strlen(&unk_3E8);
if ( !(unsigned int)my_strncmp(&unk_3E8, a1, v1) )
return 4LL;
v2 = my_strlen(&unk_3EF);
if ( !(unsigned int)my_strncmp(&unk_3EF, a1, v2) )
return 8LL;
v3 = my_strlen(&unk_3ED);
if ( !(unsigned int)my_strncmp(&unk_3ED, a1, v3) )
return 1LL;
v4 = my_strlen(&unk_3EB);
v5 = my_strncmp(&unk_3EB, a1, v4);
result = 2LL;
if ( v5 )
result = 0LL;
return result;
}

variable_types:
s
char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall test_file_redir(const char *a1, _QWORD *a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er8
void *v7; // rbp
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
struct stat v11; // [rsp+0h] [rbp-A8h] BYREF

v2 = stat(a1, &v11);
v5 = 1;
if ( v2 != -1 && (v11.st_mode & 0xF000) == 0x4000 )
{
v7 = (void *)my_strcat("(sh):error : ", a1, v3, v4, 1LL);
*a2 = my_strcat(v7, " : is a directory", v8, v9, v10);
free(v7);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, _QWORD *a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 v4; // rcx
unsigned int v5; // er8
void *v7; // rbp
__int64 v8; // rdx
__int64 v9; // rcx
__int64 v10; // r8
struct stat v11; // [rsp+0h] [rbp-A8h] BYREF

v2 = stat(a1, &v11);
v5 = 1;
if ( v2 != -1 && (v11.st_mode & 0xF000) == 0x4000 )
{
v7 = (void *)my_strcat("(sh):error : ", a1, v3, v4, 1LL);
*a2 = my_strcat(v7, " : is a directory", v8, v9, v10);
free(v7);
v5 = 0;
}
return v5;
}

original_code:
static unsigned char test_file_redir(char *file, char **bad_sintax)
{
  char *pre;
  struct stat st;
  if (stat(file, &st) == -1)
    return (1);
  if ((st.st_mode & 0170000) == 0040000)
      {
 pre = my_strcat("(sh):error : ", file);
 *bad_sintax = my_strcat(pre, " : is a directory");
 free(pre);
 return (0);
      }
  return (1);
}

variable_types:
file
char *

variable_types:
pre
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:
bool __fastcall get_file_part(_QWORD *a1, _QWORD *a2, __int64 a3, _QWORD *a4)
{
bool result; // al

if ( a2 )
{
*a1 = a2[2];
*(_QWORD *)(a3 + 16) = *a2;
free(a2);
if ( *(_DWORD *)a3 == 4 )
result = 1;
else
result = (unsigned __int8)test_file_redir(*(const char **)(a3 + 16), a4) != 0;
}
else
{
*a4 = my_strdup("(sh): unexpected EOS after redirection");
result = 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func2(_QWORD *a1, _QWORD *a2, __int64 a3, _QWORD *a4)
{
bool result; // al

if ( a2 )
{
*a1 = a2[2];
*(_QWORD *)(a3 + 16) = *a2;
free(a2);
if ( *(_DWORD *)a3 == 4 )
result = 1;
else
result = (unsigned __int8)func1(*(const char **)(a3 + 16), a4) != 0;
}
else
{
*a4 = my_strdup("(sh): unexpected EOS after redirection");
result = 0;
}
return result;
}

original_code:
static unsigned char get_file_part(t_get **words, t_get *word,
         t_redir *link, char **bad_sintax)
{
  if (!word)
    *bad_sintax = my_strdup("(sh): unexpected EOS after redirection");
  if (!word)
    return (0);
  *words = word->next;
  link->file = word->word;
  free(word);
  if (link->redir != 0b0100)
    if (test_file_redir(link->file, bad_sintax) == 0)
      return (0);
  return (1);
}

canonical_original_code:
static unsigned char get_file_part(struct s_get **words, struct s_get *word, struct s_redir *link, char **bad_sintax)
{
  if (!word)
    *bad_sintax = my_strdup("(sh): unexpected EOS after redirection");
  if (!word)
    return (0);
  *words = word->next;
  link->file = word->word;
  free(word);
  if (link->redir != 0b0100)
    if (test_file_redir(link->file, bad_sintax) == 0)
      return (0);
  return (1);
}

variable_types: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } **

variable_types:
word
struct s_get *

variable_types: struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *


original_code:
static unsigned char link_redir(t_get *word, t_get **words,
      t_redir *link, char **bad_sintax)
{
  size_t i;
  i = (!((word->word)[0] == '<') && !((word->word)[0] == '>'));
  if ((!((word->word)[my_strilen(word->word, '<')] != 0) && !((word->word)[my_strilen(word->word, '>')] != 0)) || word->inter == 1)
    {
      *bad_sintax = my_strdup("(sh): wrong redirection");
      return (0);
    }
  if (i)
    link->in = ((word->word)[0]) - '0';
  if (((word->word)[i + 1]) == '&')
    {
      link->type = 0b01;
      link->out = ((word->word)[i + 2]) - '0';
    }
  link->redir = redir_type(word->word + i);
  *words = word->next;
  rm_words(word);
  if (!link->type)
    if (get_file_part(words, *words, link, bad_sintax) == 0)
      return (0);
  return (1);
}

canonical_original_code:
static unsigned char link_redir(struct s_get *word, struct s_get **words, struct s_redir *link, char **bad_sintax)
{
  unsigned long i;
  i = (!((word->word)[0] == '<') && !((word->word)[0] == '>'));
  if ((!((word->word)[my_strilen(word->word, '<')] != 0) && !((word->word)[my_strilen(word->word, '>')] != 0)) || word->inter == 1)
    {
      *bad_sintax = my_strdup("(sh): wrong redirection");
      return (0);
    }
  if (i)
    link->in = ((word->word)[0]) - '0';
  if (((word->word)[i + 1]) == '&')
    {
      link->type = 0b01;
      link->out = ((word->word)[i + 2]) - '0';
    }
  link->redir = redir_type(word->word + i);
  *words = word->next;
  rm_words(word);
  if (!link->type)
    if (get_file_part(words, *words, link, bad_sintax) == 0)
      return (0);
  return (1);
}

variable_types: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *

variable_types:
words
struct s_get **

variable_types:
i
unsigned long

user_defined_types: struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; }


original_code:
t_redir *redir_part(t_get *words, t_get **word, char **bad_sintax)
{
  t_redir *link;
  if ((link = xmalloc(sizeof(*link))) == ((void *)0))
    return ((void*)(long)nullify_words(words));
  link->next = ((void *)0);
  link->file = ((void *)0);
  link->type = 0;
  link->in = ((words->word)[my_strilen(words->word, '>')] != 0);
  if (link_redir(words, &words, link, bad_sintax) == 0)
    {
      nullify_words(words);
      if (link->file)
 free(link->file);
      free(link);
      return (((void *)0));
    }
  if (link->type != 0b01)
    link->type = 0b10;
  *word = words;
  return (link);
}

canonical_original_code:
struct s_redir *redir_part(struct s_get *words, struct s_get **word, char **bad_sintax)
{
  struct s_redir *link;
  if ((link = xmalloc(sizeof(*link))) == ((void *)0))
    return ((void *)(long)nullify_words(words));
  link->next = ((void *)0);
  link->file = ((void *)0);
  link->type = 0;
  link->in = ((words->word)[my_strilen(words->word, '>')] != 0);
  if (link_redir(words, &words, link, bad_sintax) == 0)
    {
      nullify_words(words);
      if (link->file)
 free(link->file);
      free(link);
      return (((void *)0));
    }
  if (link->type != 0b01)
    link->type = 0b10;
  *word = words;
  return (link);
}

variable_types:
word
struct s_get **

return_type: struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *

user_defined_types: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; }


original_code:
int my_getnbr(const char *str)
{
  int signe;
  int pos;
  int nb;
  signe = 1;
  pos = 0;
  nb = 0;
  while (str[pos] == '+' || str[pos] == '-')
    {
      if (str[pos] == '-')
 signe = signe * -1;
      pos = pos + 1;
    }
  str = str + pos;
  pos = 0;
  while (str[pos] >= '0' && str[pos] <= '9')
    {
      nb = nb * 10;
      nb = nb - (str[pos] - '0');
      pos = pos + 1;
    }
  return (nb * signe * -1);
}

canonical_original_code:
int my_getnbr(char *str)
{
  int signe;
  int pos;
  int nb;
  signe = 1;
  pos = 0;
  nb = 0;
  while (str[pos] == '+' || str[pos] == '-')
    {
      if (str[pos] == '-')
 signe = signe * -1;
      pos = pos + 1;
    }
  str = str + pos;
  pos = 0;
  while (str[pos] >= '0' && str[pos] <= '9')
    {
      nb = nb * 10;
      nb = nb - (str[pos] - '0');
      pos = pos + 1;
    }
  return (nb * signe * -1);
}

variable_types:
str
char *

variable_types: signe int

variable_types: pos int

variable_types: nb int

return_type: int


decompiled_code:
__int64 __fastcall built_exit(__int64 a1)
{
_QWORD *v1; // rax
__int64 result; // rax

v1 = *(_QWORD **)(a1 + 8);
if ( v1 && *v1 )
result = my_getnbr();
else
result = 0LL;
return result;
}

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

v1 = *(_QWORD **)(a1 + 8);
if ( v1 && *v1 )
result = my_getnbr();
else
result = 0LL;
return result;
}

original_code:
int built_exit(t_words *cmd, void *bool)
{
  (void)bool;
  if (cmd->next)
    if (cmd->next->word)
      return (my_getnbr(cmd->next->word));
  return (0);
}

canonical_original_code:
int built_exit(struct s_words *cmd, void *bool)
{
  (void)bool;
  if (cmd->next)
    if (cmd->next->word)
      return (my_getnbr(cmd->next->word));
  return (0);
}

variable_types: struct s_words { char *word; struct s_words *next; } *

variable_types:
bool
void *


decompiled_code:
__int64 __fastcall move_to_prev_word(__int64 a1, _DWORD *a2, __int64 *a3)
{
__int64 result; // rax
__int64 v4; // rdi
char v5; // dl
char v6; // cl
int v7; // edx

result = (unsigned int)*a2;
if ( (_DWORD)result )
{
v4 = *a3;
v5 = *(_BYTE *)(*a3 + (int)result);
if ( v5 != 9 && v5 != 32 )
{
result = (unsigned int)(result - 1);
*a2 = result;
if ( !(_DWORD)result )
return result;
v5 = *(_BYTE *)(v4 + (int)result);
}
result = (int)result - 1;
while ( v5 == 32 || v5 == 9 )
{
*a2 = result;
if ( !(_DWORD)result )
return result;
v5 = *(_BYTE *)(v4 + result--);
}
result = (int)*a2;
if ( (_DWORD)result )
{
while ( 1 )
{
v6 = *(_BYTE *)(v4 + result);
v7 = result;
if ( v6 == 9 || v6 == 32 )
break;
--result;
*a2 = v7 - 1;
if ( !(_DWORD)result )
return result;
}
*a2 = result + 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2, __int64 *a3)
{
__int64 result; // rax
__int64 v4; // rdi
char v5; // dl
char v6; // cl
int v7; // edx

result = (unsigned int)*a2;
if ( (_DWORD)result )
{
v4 = *a3;
v5 = *(_BYTE *)(*a3 + (int)result);
if ( v5 != 9 && v5 != 32 )
{
result = (unsigned int)(result - 1);
*a2 = result;
if ( !(_DWORD)result )
return result;
v5 = *(_BYTE *)(v4 + (int)result);
}
result = (int)result - 1;
while ( v5 == 32 || v5 == 9 )
{
*a2 = result;
if ( !(_DWORD)result )
return result;
v5 = *(_BYTE *)(v4 + result--);
}
result = (int)*a2;
if ( (_DWORD)result )
{
while ( 1 )
{
v6 = *(_BYTE *)(v4 + result);
v7 = result;
if ( v6 == 9 || v6 == 32 )
break;
--result;
*a2 = v7 - 1;
if ( !(_DWORD)result )
return result;
}
*a2 = result + 1;
}
}
return result;
}

variable_types: c char

variable_types:
cmd
char **


decompiled_code:
__int64 __fastcall move_to_next_word(__int64 a1, _DWORD *a2, _QWORD *a3)
{
int v5; // esi
__int64 result; // rax
__int64 v7; // rcx
char v8; // dl
__int64 v9; // rdx
__int64 v10; // rsi
char v11; // dl

v5 = my_strlen(*a3);
result = (unsigned int)*a2;
if ( (int)result < v5 )
{
v7 = *a3;
v8 = *(_BYTE *)(*a3 + (int)result);
if ( v8 != 32 && v8 != 9 )
{
result = (unsigned int)(result + 1);
*a2 = result;
if ( (int)result >= v5 )
return result;
v8 = *(_BYTE *)(v7 + (int)result);
}
result = (int)result + 1;
while ( v8 == 32 || v8 == 9 )
{
*a2 = result;
if ( v5 <= (int)result )
return result;
v8 = *(_BYTE *)(v7 + result++);
}
v9 = (int)*a2;
if ( v5 > (int)v9 )
{
result = (int)v9 + 1;
v10 = (unsigned int)(v5 - 1 - v9) + v9 + 2;
do
{
v11 = *(_BYTE *)(v7 + result - 1);
if ( v11 == 9 )
break;
if ( v11 == 32 )
break;
*a2 = result++;
}
while ( result != v10 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2, _QWORD *a3)
{
int v5; // esi
__int64 result; // rax
__int64 v7; // rcx
char v8; // dl
__int64 v9; // rdx
__int64 v10; // rsi
char v11; // dl

v5 = my_strlen(*a3);
result = (unsigned int)*a2;
if ( (int)result < v5 )
{
v7 = *a3;
v8 = *(_BYTE *)(*a3 + (int)result);
if ( v8 != 32 && v8 != 9 )
{
result = (unsigned int)(result + 1);
*a2 = result;
if ( (int)result >= v5 )
return result;
v8 = *(_BYTE *)(v7 + (int)result);
}
result = (int)result + 1;
while ( v8 == 32 || v8 == 9 )
{
*a2 = result;
if ( v5 <= (int)result )
return result;
v8 = *(_BYTE *)(v7 + result++);
}
v9 = (int)*a2;
if ( v5 > (int)v9 )
{
result = (int)v9 + 1;
v10 = (unsigned int)(v5 - 1 - v9) + v9 + 2;
do
{
v11 = *(_BYTE *)(v7 + result - 1);
if ( v11 == 9 )
break;
if ( v11 == 32 )
break;
*a2 = result++;
}
while ( result != v10 );
}
}
return result;
}

original_code:
void move_to_next_word(char c, int *rev_c, char **cmd)
{
  int len;
  (void)c;
  len = my_strlen(*cmd);
  if (*rev_c < len && (*cmd)[*rev_c] != ' ' && (*cmd)[*rev_c] != '\t')
    (*rev_c)++;
  while (*rev_c < len && ((*cmd)[*rev_c] == ' ' || (*cmd)[*rev_c] == '\t'))
    (*rev_c)++;
  while (*rev_c < len && (*cmd)[*rev_c] != ' ' && (*cmd)[*rev_c] != '\t')
    (*rev_c)++;
}

variable_types: len int


seek

decompiled_code:
void *__fastcall seek(_BYTE *a1, __int64 a2, _QWORD *a3)
{
_BYTE *i; // rbx
__int64 v5; // rax
__int64 v6; // rax
void *v7; // rbp
__int64 v8; // rbp

if ( !a1 )
return 0LL;
for ( i = a1; *i; i += v8 - ((i[my_strilen(i, 58LL)] == 0) - 1LL) )
{
v5 = my_strilen(i, 58LL);
v6 = my_strndup(i, v5);
v7 = (void *)v6;
if ( !v6 )
return 0LL;
if ( (unsigned __int8)in_directory(v6, a2) )
return v7;
free(v7);
if ( !i[my_strilen(i, 58LL)] )
break;
v8 = my_strilen(i, 58LL);
}
v7 = 0LL;
*a3 = my_strcat("(sh): command not found : ", a2);
return v7;
}

canonical_decompiled_code:
void *__fastcall func0(_BYTE *a1, __int64 a2, _QWORD *a3)
{
_BYTE *i; // rbx
__int64 v5; // rax
__int64 v6; // rax
void *v7; // rbp
__int64 v8; // rbp

if ( !a1 )
return 0LL;
for ( i = a1; *i; i += v8 - ((i[my_strilen(i, 58LL)] == 0) - 1LL) )
{
v5 = my_strilen(i, 58LL);
v6 = my_strndup(i, v5);
v7 = (void *)v6;
if ( !v6 )
return 0LL;
if ( (unsigned __int8)in_directory(v6, a2) )
return v7;
free(v7);
if ( !i[my_strilen(i, 58LL)] )
break;
v8 = my_strilen(i, 58LL);
}
v7 = 0LL;
*a3 = my_strcat("(sh): command not found : ", a2);
return v7;
}

original_code:
static char *seek(char *path, char *cmd, char **bad_sintax)
{
  char *dir;
  if (!path)
    return (((void *)0));
  if (!path[0])
    {
      *bad_sintax = my_strcat("(sh): command not found : ", cmd);
      return (((void *)0));
    }
  if ((dir = my_strndup(path, my_strilen(path, ':'))) == ((void *)0))
    return (((void *)0));
  if (in_directory(dir, cmd))
    return (dir);
  free(dir);
  if (!((path)[my_strilen(path, ':')] != 0))
    {
      *bad_sintax = my_strcat("(sh): command not found : ", cmd);
      return (((void *)0));
    }
  return (seek(path + my_strilen(path, ':') + ((path)[my_strilen(path, ':')] != 0), cmd, bad_sintax));
}

variable_types:
path
char *

variable_types:
cmd
char *

variable_types:
dir
char *

return_type: char *


decompiled_code:
__int64 __fastcall seek_cmd(__int64 a1, _QWORD *a2)
{
_BYTE *v2; // rbp
void *v3; // rax
void *v4; // rbp
__int64 v5; // r12

v2 = (_BYTE *)get_env("PATH");
if ( !v2 )
*a2 = my_strcat("(sh): command not found : ", a1);
v3 = seek(v2, a1, a2);
v4 = v3;
if ( !v3 )
return my_strdup(a1);
v5 = my_stricat(v3, a1, 47LL);
free(v4);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
_BYTE *v2; // rbp
void *v3; // rax
void *v4; // rbp
__int64 v5; // r12

v2 = (_BYTE *)get_env("PATH");
if ( !v2 )
*a2 = my_strcat("(sh): command not found : ", a1);
v3 = func0(v2, a1, a2);
v4 = v3;
if ( !v3 )
return my_strdup(a1);
v5 = my_stricat(v3, a1, 47LL);
free(v4);
return v5;
}

original_code:
char *seek_cmd(char *cmd, char **bad_sintax)
{
  char *r;
  char *wh;
  char *path;
  (void)bad_sintax;
  if ((path = get_env("PATH")) == ((void *)0))
    *bad_sintax = my_strcat("(sh): command not found : ", cmd);
  if ((wh = seek(path, cmd, bad_sintax)) == ((void *)0))
    return (my_strdup(cmd));
  r = my_stricat(wh, cmd, '/');
  free(wh);
  return (r);
}

variable_types:
r
char *

variable_types:
wh
char *


decompiled_code:
__int64 __fastcall read_cmd(int fd, void **a2, _QWORD *a3, __int64 a4)
{
__int64 result; // rax

retain_cmd(1LL, a3);
*a2 = (void *)my_memset(*a2, 0LL, 5LL);
retain_reverse_case(1LL, a4);
if ( read(fd, *a2, 4uLL) > 0 && *(_BYTE *)*a2 != 4 || my_strlen(*a3) )
{
retain_reverse_case(2LL, a4);
result = modif_cmd(a3, *a2, a4);
}
else
{
free_str_edit_lines(*a2, *a3);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, void **a2, _QWORD *a3, __int64 a4)
{
__int64 result; // rax

retain_cmd(1LL, a3);
*a2 = (void *)my_memset(*a2, 0LL, 5LL);
retain_reverse_case(1LL, a4);
if ( read(fd, *a2, 4uLL) > 0 && *(_BYTE *)*a2 != 4 || my_strlen(*a3) )
{
retain_reverse_case(2LL, a4);
result = modif_cmd(a3, *a2, a4);
}
else
{
free_str_edit_lines(*a2, *a3);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int read_cmd(int fd, char **str, char **cmd, int *reverse_case)
{
  retain_cmd(1, cmd);
  (*str) = my_memset((*str), 0, 5);
  retain_reverse_case(1, reverse_case);
  if ((read(fd, (*str), 4) <= 0 || (*str)[0] == 4) && my_strlen(*cmd) == 0)
    {
      free_str_edit_lines((*str), (*cmd));
      return (-1);
    }
  retain_reverse_case(2, reverse_case);
  return (modif_cmd(cmd, *str, reverse_case));
}

variable_types: fd int

variable_types:
str
char **


decompiled_code:
__int64 __fastcall init_values(_DWORD *a1, _DWORD *a2, void **a3, _QWORD *a4)
{
void *v6; // rax
void *v7; // rax

*a1 = 0;
*a2 = 0;
v6 = malloc(5uLL);
*a3 = v6;
if ( v6 )
{
v7 = malloc(2uLL);
*a4 = v7;
if ( v7 )
{
*a3 = (void *)my_memset(*a3, 0LL, 5LL);
*a4 = my_memset(*a4, 0LL, 2LL);
prompt(1LL);
return 0LL;
}
if ( *a3 )
free(*a3);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, _DWORD *a2, void **a3, _QWORD *a4)
{
void *v6; // rax
void *v7; // rax

*a1 = 0;
*a2 = 0;
v6 = malloc(5uLL);
*a3 = v6;
if ( v6 )
{
v7 = malloc(2uLL);
*a4 = v7;
if ( v7 )
{
*a3 = (void *)my_memset(*a3, 0LL, 5LL);
*a4 = my_memset(*a4, 0LL, 2LL);
prompt(1LL);
return 0LL;
}
if ( *a3 )
free(*a3);
}
return 0xFFFFFFFFLL;
}

original_code:
int init_values(int *history_pl, int *reverse_case,
       char **str, char **cmd)
{
  *history_pl = 0;
  *reverse_case = 0;
  if (((*str) = malloc(sizeof(**str) * 5)) == ((void *)0) ||
      ((*cmd) = malloc(sizeof(**cmd) * 2)) == ((void *)0))
    {
      if ((*str) != ((void *)0))
 free(*str);
      return (-1);
    }
  (*str) = my_memset((*str), 0, 5);
  (*cmd) = my_memset((*cmd), 0, 2);
  prompt(1);
  return (0);
}


decompiled_code:
__int64 __fastcall usr_cmd(int fd, __int64 a2)
{
int v2; // er8
int v3; // eax
bool v5; // zf
unsigned int v6; // [rsp+48h] [rbp-B0h] BYREF
int v7; // [rsp+4Ch] [rbp-ACh] BYREF
char *v8; // [rsp+50h] [rbp-A8h] BYREF
__int64 v9; // [rsp+58h] [rbp-A0h] BYREF
char v10[64]; // [rsp+60h] [rbp-98h] BYREF
__int128 v11; // [rsp+A0h] [rbp-58h] BYREF

if ( (unsigned int)init_termios(v10, &v11) == -1 || (unsigned int)init_values(&v7, &v6, (void **)&v8, &v9) == -1 )
return unset_termios(&v11);
while ( 1 )
{
show_cmd((unsigned int)*v8, (unsigned int)fd, v9, v6);
if ( *v8 == 10 && !v8[1] && !v8[2] )
break;
if ( (unsigned int)read_cmd(fd, (void **)&v8, &v9, (__int64)&v6) == -1 )
return unset_termios(&v11);
v2 = length_of_history(a2);
v3 = v7;
if ( v2 > v7 )
{
v5 = (unsigned int)chk_str_constprop_0(v8, 65) == 0;
v3 = v7;
if ( v5 )
{
if ( (unsigned int)take_cmd_from_history((unsigned int)++v7, &v6, &v9, a2) == -1 )
return unset_termios(&v11);
v3 = v7;
}
}
if ( v3 > 0
&& !(unsigned int)chk_str_constprop_0(v8, 66)
&& (unsigned int)take_cmd_from_history((unsigned int)--v7, &v6, &v9, a2) == -1 )
{
return unset_termios(&v11);
}
}
return finish_usr_cmd(v9);
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, __int64 a2)
{
int v2; // er8
int v3; // eax
bool v5; // zf
unsigned int v6; // [rsp+48h] [rbp-B0h] BYREF
int v7; // [rsp+4Ch] [rbp-ACh] BYREF
char *v8; // [rsp+50h] [rbp-A8h] BYREF
__int64 v9; // [rsp+58h] [rbp-A0h] BYREF
char v10[64]; // [rsp+60h] [rbp-98h] BYREF
__int128 v11; // [rsp+A0h] [rbp-58h] BYREF

if ( (unsigned int)init_termios(v10, &v11) == -1 || (unsigned int)func2(&v7, &v6, (void **)&v8, &v9) == -1 )
return unset_termios(&v11);
while ( 1 )
{
show_cmd((unsigned int)*v8, (unsigned int)fd, v9, v6);
if ( *v8 == 10 && !v8[1] && !v8[2] )
break;
if ( (unsigned int)func0(fd, (void **)&v8, &v9, (__int64)&v6) == -1 )
return unset_termios(&v11);
v2 = length_of_history(a2);
v3 = v7;
if ( v2 > v7 )
{
v5 = (unsigned int)func1(v8, 65) == 0;
v3 = v7;
if ( v5 )
{
if ( (unsigned int)take_cmd_from_history((unsigned int)++v7, &v6, &v9, a2) == -1 )
return unset_termios(&v11);
v3 = v7;
}
}
if ( v3 > 0
&& !(unsigned int)func1(v8, 66)
&& (unsigned int)take_cmd_from_history((unsigned int)--v7, &v6, &v9, a2) == -1 )
{
return unset_termios(&v11);
}
}
return finish_usr_cmd(v9);
}

original_code:
char *usr_cmd(int fd, t_history *histo, t_options options)
{
  struct termios set;
  struct termios unset;
  char *str;
  char *cmd;
  int rev_c;
  int histo_pl;
  (void)options;
  if (init_termios(&set, &unset) == -1 ||
      init_values(&histo_pl, &rev_c, &str, &cmd) == -1)
    return (unset_termios(&unset));
  show_cmd(str[0], fd, cmd, rev_c);
  while (str[0] != 10 || str[1] != 0 || str[2] != 0)
    {
      if (read_cmd(fd, &str, &cmd, &rev_c) == -1)
 return (unset_termios(&unset));
      if (histo_pl < length_of_history(histo) && chk_str(str, 27, 91, 65) == 0)
 if (take_cmd_from_history(++histo_pl, &rev_c, &cmd, histo) == -1)
   return (unset_termios(&unset));
      if (histo_pl > 0 && chk_str(str, 27, 91, 66) == 0)
 if (take_cmd_from_history(--histo_pl, &rev_c, &cmd, histo) == -1)
   return (unset_termios(&unset));
      show_cmd(str[0], fd, cmd, rev_c);
    }
  return (finish_usr_cmd(cmd, str, unset));
}

canonical_original_code:
char *usr_cmd(int fd, struct s_history *histo, struct s_options options)
{
  struct termios set;
  struct termios unset;
  char *str;
  char *cmd;
  int rev_c;
  int histo_pl;
  (void)options;
  if (init_termios(&set, &unset) == -1 ||
      init_values(&histo_pl, &rev_c, &str, &cmd) == -1)
    return (unset_termios(&unset));
  show_cmd(str[0], fd, cmd, rev_c);
  while (str[0] != 10 || str[1] != 0 || str[2] != 0)
    {
      if (read_cmd(fd, &str, &cmd, &rev_c) == -1)
 return (unset_termios(&unset));
      if (histo_pl < length_of_history(histo) && chk_str(str, 27, 91, 65) == 0)
 if (take_cmd_from_history(++histo_pl, &rev_c, &cmd, histo) == -1)
   return (unset_termios(&unset));
      if (histo_pl > 0 && chk_str(str, 27, 91, 66) == 0)
 if (take_cmd_from_history(--histo_pl, &rev_c, &cmd, histo) == -1)
   return (unset_termios(&unset));
      show_cmd(str[0], fd, cmd, rev_c);
    }
  return (finish_usr_cmd(cmd, str, unset));
}

variable_types: struct s_history { char *str; struct s_history *prev; struct s_history *next; } *

variable_types: struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; }

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


decompiled_code:
__int64 __fastcall check_bad_sintax(const char *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
{
fprintf(stderr, "%s\n", a1);
result = 1LL;
}
return result;
}

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

result = 0LL;
if ( a1 )
{
fprintf(stderr, "%s\n", a1);
result = 1LL;
}
return result;
}

original_code:
static unsigned char check_bad_sintax(char *s)
{
  if (!s)
    return (0);
  fprintf(stderr, "%s\n", s);
  return (1);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall call_parents(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
int v3; // eax
bool v4; // zf
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = 1;
v3 = fork();
if ( v3 < 0 )
return v2;
if ( v3 )
{
waitpid(v3, &stat_loc, 0);
v4 = BYTE1(stat_loc) == 0;
*(_DWORD *)(a2 + 108) = BYTE1(stat_loc);
v2 = 0;
*(_DWORD *)(a2 + 104) = !v4;
return v2;
}
pre_exec(*(_QWORD *)(a1 + 24), a2, 1LL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
unsigned int v2; // er12
int v3; // eax
bool v4; // zf
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = 1;
v3 = fork();
if ( v3 < 0 )
return v2;
if ( v3 )
{
waitpid(v3, &stat_loc, 0);
v4 = BYTE1(stat_loc) == 0;
*(_DWORD *)(a2 + 108) = BYTE1(stat_loc);
v2 = 0;
*(_DWORD *)(a2 + 104) = !v4;
return v2;
}
pre_exec(*(_QWORD *)(a1 + 24), a2, 1LL);
return 1LL;
}

original_code:
static unsigned char call_parents(t_cmd *cmd, t_info *info)
{
  pid_t pid;
  int chien;
  if ((pid = fork()) < 0)
    return (1);
  if (!pid)
    {
      pre_exec(cmd->parents, info, 1);
      return (1);
    }
  else
    waitpid(pid, &chien, 0);
  info->st = (0 != (info->value = (((chien) & 0xff00) >> 8)));
  return (0);
}

canonical_original_code:
static unsigned char call_parents(struct s_cmd *cmd, struct s_info *info)
{
  int pid;
  int chien;
  if ((pid = fork()) < 0)
    return (1);
  if (!pid)
    {
      pre_exec(cmd->parents, info, 1);
      return (1);
    }
  else
    waitpid(pid, &chien, 0);
  info->st = (0 != (info->value = (((chien) & 0xff00) >> 8)));
  return (0);
}

variable_types: struct s_cmd { struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *redir; unsigned int type; struct s_words { char *word; struct s_words *next; } *params; struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes { struct s_pipes *next; struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *tmp; struct s_cmd *cmd; } *pipes; struct s_get *tmp; } *exec; struct s_get *tmp; } *parents; } *

variable_types: struct s_info { struct s_history { char *str; struct s_history *prev; struct s_history *next; } *hist; struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; } termcaps; unsigned char term_caps; int *wr; int st; int value; unsigned int son; struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } *alias; } *

variable_types: pid int

variable_types: chien int

user_defined_types: struct s_info { struct s_history *hist; struct s_options termcaps; unsigned char term_caps; int *wr; int st; int value; unsigned int son; struct s_alias *alias; }


original_code:
static unsigned char exec_built_in(t_cmd *cmd, t_info *info)
{
  size_t i;
  t_call *call;
  i = 0;
  call = builtins();
  while ((call[i]).name)
    {
      if ((((call[i]).name && cmd->params->word) ? (!my_strcmp((call[i]).name, cmd->params->word)) : (0)))
 {
   info->st = (0 !=
        (info->value =
         ((call[i]).ptr)(cmd->params, (void*)&(info->alias))));
   if (((cmd->params->word && "exit") ? (!my_strcmp(cmd->params->word, "exit")) : (0)))
     return (2);
   return (1);
 }
      i++;
    }
  free(call);
  return (0);
}

canonical_original_code:
static unsigned char exec_built_in(struct s_cmd *cmd, struct s_info *info)
{
  unsigned long i;
  struct s_call *call;
  i = 0;
  call = builtins();
  while ((call[i]).name)
    {
      if ((((call[i]).name && cmd->params->word) ? (!my_strcmp((call[i]).name, cmd->params->word)) : (0)))
 {
   info->st = (0 !=
        (info->value =
         ((call[i]).ptr)(cmd->params, (void *)&(info->alias))));
   if (((cmd->params->word && "exit") ? (!my_strcmp(cmd->params->word, "exit")) : (0)))
     return (2);
   return (1);
 }
      i++;
    }
  free(call);
  return (0);
}

variable_types:
i
unsigned long

variable_types: struct s_call { char *name; int (*ptr)(struct s_words { char *word; struct s_words *next; } *, void *); } *

user_defined_types: struct s_call { char *name; int (*ptr)(struct s_words *, void *); }

user_defined_types: struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; }

user_defined_types: struct s_history { char *str; struct s_history *prev; struct s_history *next; }

user_defined_types: struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; }


original_code:
unsigned char exec_cmd(t_cmd *cmd, t_info *info, unsigned int son, int w[3])
{
  int r;
  unsigned char sys_fail;
  char *bad_sintax;
  bad_sintax = (void*)((unsigned long)(r = (sys_fail = 0)));
  if (set_redir(cmd->redir, w, &bad_sintax, info) == 0)
    if ((r = check_bad_sintax(bad_sintax)) == 0)
      return (0);
  if (cmd->type == 0b01 && !r)
    sys_fail = call_parents(cmd, info);
  if (cmd->type == 0b10 && !r)
    if (!(r = exec_built_in(cmd, info)))
      info->st = exec_form(cmd->params, &sys_fail, &(info->value));
  cmd->parents = ((void *)0);
  if (son & 0b10)
    close(w[1]);
  if ((son & 0b01) || w[0] != 0)
    close(0);
  if ((son & 0b10) || w[1] != 1)
    close(1);
  if (w[2] != 2)
    close(2);
  if (sys_fail == 1)
    return (0);
  return (((son & 0b01) == 0) * (r != 2) * (sys_fail != 1));
}

canonical_original_code:
unsigned char exec_cmd(struct s_cmd *cmd, struct s_info *info, unsigned int son, int w[3])
{
  int r;
  unsigned char sys_fail;
  char *bad_sintax;
  bad_sintax = (void *)((unsigned long)(r = (sys_fail = 0)));
  if (set_redir(cmd->redir, w, &bad_sintax, info) == 0)
    if ((r = check_bad_sintax(bad_sintax)) == 0)
      return (0);
  if (cmd->type == 0b01 && !r)
    sys_fail = call_parents(cmd, info);
  if (cmd->type == 0b10 && !r)
    if (!(r = exec_built_in(cmd, info)))
      info->st = exec_form(cmd->params, &sys_fail, &(info->value));
  cmd->parents = ((void *)0);
  if (son & 0b10)
    close(w[1]);
  if ((son & 0b01) || w[0] != 0)
    close(0);
  if ((son & 0b10) || w[1] != 1)
    close(1);
  if (w[2] != 2)
    close(2);
  if (sys_fail == 1)
    return (0);
  return (((son & 0b01) == 0) * (r != 2) * (sys_fail != 1));
}

variable_types:
son
unsigned int

variable_types:
w
int [3]

variable_types: r int

user_defined_types: struct s_words { char *word; struct s_words *next; }


builtins

decompiled_code:
void builtins()
{
_QWORD *v0; // rax

v0 = (_QWORD *)xmalloc(144LL);
if ( v0 )
init_built(v0);
}

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

v0 = (_QWORD *)xmalloc(144LL);
if ( v0 )
func0(v0);
}

original_code:
t_call *builtins(void)
{
  t_call *built;
  if ((built = xmalloc(sizeof(t_call) * 9)) == ((void *)0))
    return (((void *)0));
  init_built(built);
  return (built);
}

canonical_original_code:
struct s_call *builtins()
{
  struct s_call *built;
  if ((built = xmalloc(sizeof(t_call) * 9)) == ((void *)0))
    return (((void *)0));
  init_built(built);
  return (built);
}

return_type: struct s_call { char *name; int (*ptr)(struct s_words { char *word; struct s_words *next; } *, void *); } *


decompiled_code:
__int64 __fastcall check_for_dleft(__int64 a1)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == 4 )
break;
a1 = *(_QWORD *)(a1 + 24);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
while ( 1 )
{
if ( !a1 )
return 0LL;
if ( *(_DWORD *)a1 == 4 )
break;
a1 = *(_QWORD *)(a1 + 24);
}
return 1LL;
}

original_code:
static unsigned char check_for_dleft(t_redir *redir)
{
  if (!redir)
    return (0);
  if (redir->redir == 0b0100)
    return (1);
  return (check_for_dleft(redir->next));
}

canonical_original_code:
static unsigned char check_for_dleft(struct s_redir *redir)
{
  if (!redir)
    return (0);
  if (redir->redir == 0b0100)
    return (1);
  return (check_for_dleft(redir->next));
}

variable_types: struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *


decompiled_code:
__int64 __fastcall get_cmd(_QWORD *a1, _QWORD *a2, __int64 a3, unsigned __int8 a4)
{
__int64 *v6; // rax
__int64 result; // rax

if ( !a1 )
return 1LL;
v6 = (__int64 *)make_cmd(a1[1], (__int64)a2);
a1[2] = v6;
if ( v6 )
{
if ( (a4 || a3) && (unsigned __int8)check_for_dleft(*v6) == 1 )
{
if ( a4 )
*a2 = my_strdup("Can't << within ()'s.");
else
*a2 = my_strdup("Ambiguous input redirect");
nullify_all_pipes(a1);
result = 0LL;
}
else if ( (unsigned __int8)get_cmd(*a1, a2, a1, a4) )
{
result = 1LL;
}
else
{
result = nullify_all_in_pipes(a1);
}
}
else
{
nullify_all_pipes(*a1);
free(a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, _QWORD *a2, __int64 a3, unsigned __int8 a4)
{
__int64 *v6; // rax
__int64 result; // rax

if ( !a1 )
return 1LL;
v6 = (__int64 *)func2(a1[1], (__int64)a2);
a1[2] = v6;
if ( v6 )
{
if ( (a4 || a3) && (unsigned __int8)func0(*v6) == 1 )
{
if ( a4 )
*a2 = my_strdup("Can't << within ()'s.");
else
*a2 = my_strdup("Ambiguous input redirect");
nullify_all_pipes(a1);
result = 0LL;
}
else if ( (unsigned __int8)func3(*a1, a2, a1, a4) )
{
result = 1LL;
}
else
{
result = nullify_all_in_pipes(a1);
}
}
else
{
nullify_all_pipes(*a1);
free(a1);
result = 0LL;
}
return result;
}

original_code:
unsigned char get_cmd(t_pipes *pipe, char **bad_sintax, t_pipes *prev, unsigned char sub)
{
  if (!pipe)
    return (1);
  if ((pipe->cmd = make_cmd(pipe->tmp, bad_sintax)) == ((void *)0))
    {
      nullify_all_pipes(pipe->next);
      free(pipe);
      return (0);
    }
  if ((sub || prev) && check_for_dleft(pipe->cmd->redir) == 1)
    {
      if (sub)
 *bad_sintax = my_strdup("Can't << within ()'s.");
      else
 *bad_sintax = my_strdup("Ambiguous input redirect");
      nullify_all_pipes(pipe);
      return (0);
    }
  if (get_cmd(pipe->next, bad_sintax, pipe, sub) == 0)
    return (nullify_all_in_pipes(pipe));
  return (1);
}

canonical_original_code:
unsigned char get_cmd(struct s_pipes *pipe, char **bad_sintax, struct s_pipes *prev, unsigned char sub)
{
  if (!pipe)
    return (1);
  if ((pipe->cmd = make_cmd(pipe->tmp, bad_sintax)) == ((void *)0))
    {
      nullify_all_pipes(pipe->next);
      free(pipe);
      return (0);
    }
  if ((sub || prev) && check_for_dleft(pipe->cmd->redir) == 1)
    {
      if (sub)
 *bad_sintax = my_strdup("Can't << within ()'s.");
      else
 *bad_sintax = my_strdup("Ambiguous input redirect");
      nullify_all_pipes(pipe);
      return (0);
    }
  if (get_cmd(pipe->next, bad_sintax, pipe, sub) == 0)
    return (nullify_all_in_pipes(pipe));
  return (1);
}

variable_types: struct s_pipes { struct s_pipes *next; struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *tmp; struct s_cmd { struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *redir; unsigned int type; struct s_words { char *word; struct s_words *next; } *params; struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes *pipes; struct s_get *tmp; } *exec; struct s_get *tmp; } *parents; } *cmd; } *

variable_types:
prev
struct s_pipes *

variable_types:
sub
unsigned char


decompiled_code:
__int64 __fastcall nullify_link(void *a1)
{
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *a1)
{
free(a1);
return 0LL;
}

original_code:
static t_cmd *nullify_link(t_cmd *cmd)
{
  free(cmd);
  return (((void *)0));
}

canonical_original_code:
static struct s_cmd *nullify_link(struct s_cmd *cmd)
{
  free(cmd);
  return (((void *)0));
}

variable_types:
cmd
struct s_cmd *

return_type: struct s_cmd { struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *redir; unsigned int type; struct s_words { char *word; struct s_words *next; } *params; struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes { struct s_pipes *next; struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *tmp; struct s_cmd *cmd; } *pipes; struct s_get *tmp; } *exec; struct s_get *tmp; } *parents; } *


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

if ( a1 == 1 )
{
result = *a2;
save_0 = *a2;
}
else
{
result = save_0;
*a2 = save_0;
}
return result;
}

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

if ( a1 == 1 )
{
result = *a2;
save_0 = *a2;
}
else
{
result = save_0;
*a2 = save_0;
}
return result;
}

original_code:
void retain_history(int opt, t_history **list)
{
  static t_history *save = ((void *)0);
  if (opt == 1)
    save = (*list);
  else
    (*list) = save;
}

canonical_original_code:
void retain_history(int opt, struct s_history **list)
{
  static struct s_history *save = ((void *)0);
  if (opt == 1)
    save = (*list);
  else
    (*list) = save;
}

variable_types: opt int

variable_types: struct s_history { char *str; struct s_history *prev; struct s_history *next; } **


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

if ( a1 )
{
v1 = a1;
do
{
printf("%s", *(const char **)v1);
if ( !*(_QWORD *)(v1 + 16) )
break;
printf(" -> ");
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return putchar(10);
}

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

if ( a1 )
{
v1 = a1;
do
{
printf("%s", *(const char **)v1);
if ( !*(_QWORD *)(v1 + 16) )
break;
printf(" -> ");
v1 = *(_QWORD *)(v1 + 16);
}
while ( v1 );
}
return putchar(10);
}

original_code:
void my_show_history(t_history *list)
{
  t_history *tmp;
  tmp = list;
  while (tmp != ((void *)0))
    {
      printf("%s", tmp->str);
      if (tmp->next != ((void *)0))
        printf(" -> ");
      tmp = tmp->next;
    }
  printf("\n");
}

canonical_original_code:
void my_show_history(struct s_history *list)
{
  struct s_history *tmp;
  tmp = list;
  while (tmp != ((void *)0))
    {
      printf("%s", tmp->str);
      if (tmp->next != ((void *)0))
        printf(" -> ");
      tmp = tmp->next;
    }
  printf("\n");
}

variable_types: struct s_history { char *str; struct s_history *prev; struct s_history *next; } *


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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 16);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 16);
return result;
}

original_code:
int length_of_history(t_history *list)
{
  int len;
  t_history *tmp;
  len = 0;
  tmp = list;
  while (tmp != ((void *)0))
    {
      len++;
      tmp = tmp->next;
    }
  return (len);
}

canonical_original_code:
int length_of_history(struct s_history *list)
{
  int len;
  struct s_history *tmp;
  len = 0;
  tmp = list;
  while (tmp != ((void *)0))
    {
      len++;
      tmp = tmp->next;
    }
  return (len);
}

variable_types: len int


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

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

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

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

original_code:
void free_history(t_history *list)
{
  t_history *tmp;
  t_history *after;
  tmp = list;
  after = list;
  while (tmp != ((void *)0))
    {
      after = after->next;
      free(tmp->str);
      free(tmp);
      tmp = after;
    }
}

canonical_original_code:
void free_history(struct s_history *list)
{
  struct s_history *tmp;
  struct s_history *after;
  tmp = list;
  after = list;
  while (tmp != ((void *)0))
    {
      after = after->next;
      free(tmp->str);
      free(tmp);
      tmp = after;
    }
}


decompiled_code:
void __fastcall catch_more(int a1)
{
if ( a1 == 2 )
stop(1);
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
if ( a1 == 2 )
func0(1);
}

original_code:
void catch_more(int num)
{
  if (num == 2)
    stop(1);
}

variable_types: num int


decompiled_code:
__int64 __fastcall clean_signal(__int64 a1, unsigned __int64 a2, void *a3)
{
__int64 v4; // rax

if ( (a2 & 0xFFFFFFFD) == 4 )
{
my_putstr(a1, 2LL);
if ( (_DWORD)a2 == 4 )
{
my_putstr(" : Illegal instruction\n", 2LL);
goto LABEL_10;
}
goto LABEL_13;
}
if ( (unsigned int)a2 > 0xF )
goto LABEL_10;
v4 = 35076LL;
if ( !_bittest64(&v4, a2) )
goto LABEL_10;
my_putstr(a1, 2LL);
switch ( (_DWORD)a2 )
{
case 6:
LABEL_13:
my_putstr(" : Aborted\n", 2LL);
break;
case 8:
my_putstr(" : Floating exeception\n", 2LL);
break;
case 0xB:
my_putstr(" : Segmentation fault\n", 2LL);
break;
case 0xF:
my_putstr(" : Terminated\n", 2LL);
break;
case 2:
my_putstr(" : Killed\n", 2LL);
break;
}
LABEL_10:
free(a3);
return (unsigned int)a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 a2, void *a3)
{
__int64 v4; // rax

if ( (a2 & 0xFFFFFFFD) == 4 )
{
my_putstr(a1, 2LL);
if ( (_DWORD)a2 == 4 )
{
my_putstr(" : Illegal instruction\n", 2LL);
goto LABEL_10;
}
goto LABEL_13;
}
if ( (unsigned int)a2 > 0xF )
goto LABEL_10;
v4 = 35076LL;
if ( !_bittest64(&v4, a2) )
goto LABEL_10;
my_putstr(a1, 2LL);
switch ( (_DWORD)a2 )
{
case 6:
LABEL_13:
my_putstr(" : Aborted\n", 2LL);
break;
case 8:
my_putstr(" : Floating exeception\n", 2LL);
break;
case 0xB:
my_putstr(" : Segmentation fault\n", 2LL);
break;
case 0xF:
my_putstr(" : Terminated\n", 2LL);
break;
case 2:
my_putstr(" : Killed\n", 2LL);
break;
}
LABEL_10:
free(a3);
return (unsigned int)a2;
}

original_code:
static int clean_signal(char *prog, int signal, char **tab)
{
  if (signal == 4 || signal == 6 || signal == 8 ||
      signal == 11 || signal == 15 || signal == 2)
    my_putstr(prog, 2);
  if (signal == 4)
    my_putstr(" : Illegal instruction\n", 2);
  else if (signal == 6)
    my_putstr(" : Aborted\n", 2);
  else if (signal == 8)
    my_putstr(" : Floating exeception\n", 2);
  else if (signal == 11)
    my_putstr(" : Segmentation fault\n", 2);
  else if (signal == 15)
    my_putstr(" : Terminated\n", 2);
  else if (signal == 2)
    my_putstr(" : Killed\n", 2);
  free(tab);
  return (signal);
}

variable_types:
prog
char *

variable_types: signal int

variable_types:
tab
char **


init

decompiled_code:
__int64 init()
{
signal(21, handler);
signal(22, handler);
return stop(2);
}

canonical_decompiled_code:
__int64 func3()
{
signal(21, handler);
signal(22, handler);
return func0(2);
}

original_code:
void init(void)
{
  signal(21, ((__sighandler_t) 1));
  signal(22, ((__sighandler_t) 1));
  stop(2);
}


decompiled_code:
__int64 __fastcall exec_form(__int64 a1, _BYTE *a2, _DWORD *a3)
{
__int64 v4; // rax
__int64 *v5; // rbp
__pid_t v6; // eax
__pid_t v7; // ebx
__pid_t v8; // eax
__pid_t v9; // eax
int v10; // eax
__int64 result; // rax
const char *v12; // rdx
int stat_loc[11]; // [rsp+Ch] [rbp-2Ch] BYREF

init();
v4 = to_tab(a1, a2);
if ( !v4 || (v5 = (__int64 *)v4, v6 = fork(), v7 = v6, v6 == -1) )
{
*a2 = 1;
result = 1LL;
}
else
{
if ( v6 )
{
signal(2, catch_more);
while ( waitpid(v7, stat_loc, 1) != -1 )
{
if ( (unsigned int)stop(0) == 1 )
kill(v7, 2);
}
v8 = getpgrp();
tcsetpgrp(0, v8);
goto LABEL_10;
}
setpgrp();
v9 = getpgrp();
tcsetpgrp(0, v9);
if ( execve((const char *)*v5, (char *const *)v5, environ) != -1 )
{
LABEL_10:
v10 = (unsigned __int8)((unsigned __int16)clean_signal(*v5, (unsigned int)stat_loc[0], v5) >> 8);
*a3 = v10;
return v10 != 0;
}
*a2 = 1;
v12 = (const char *)*v5;
*a3 = 1;
result = (unsigned int)(fprintf(stderr, "%s: Command not found\n", v12) == 0) + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2, _DWORD *a3)
{
__int64 v4; // rax
__int64 *v5; // rbp
__pid_t v6; // eax
__pid_t v7; // ebx
__pid_t v8; // eax
__pid_t v9; // eax
int v10; // eax
__int64 result; // rax
const char *v12; // rdx
int stat_loc[11]; // [rsp+Ch] [rbp-2Ch] BYREF

func3();
v4 = to_tab(a1, a2);
if ( !v4 || (v5 = (__int64 *)v4, v6 = fork(), v7 = v6, v6 == -1) )
{
*a2 = 1;
result = 1LL;
}
else
{
if ( v6 )
{
signal(2, catch_more);
while ( waitpid(v7, stat_loc, 1) != -1 )
{
if ( (unsigned int)func0(0) == 1 )
kill(v7, 2);
}
v8 = getpgrp();
tcsetpgrp(0, v8);
goto LABEL_10;
}
setpgrp();
v9 = getpgrp();
tcsetpgrp(0, v9);
if ( execve((const char *)*v5, (char *const *)v5, environ) != -1 )
{
LABEL_10:
v10 = (unsigned __int8)((unsigned __int16)func2(*v5, (unsigned int)stat_loc[0], v5) >> 8);
*a3 = v10;
return v10 != 0;
}
*a2 = 1;
v12 = (const char *)*v5;
*a3 = 1;
result = (unsigned int)(fprintf(stderr, "%s: Command not found\n", v12) == 0) + 1;
}
return result;
}

original_code:
int exec_form(t_words *list, unsigned char *sys_fail, int *value)
{
  int st;
  pid_t pid;
  char **tab;
  init();
  if ((tab = to_tab(list, sys_fail)) == ((void *)0))
    return (1 + !((*sys_fail) = 1));
  if ((pid = fork()) == -1)
    return (1 + !((*sys_fail) = 1));
  if (pid)
    {
      signal(2, catch_more);
      while (waitpid(pid, &st, 1) != -1)
 if (stop(0) == 1)
   kill(pid, 2);
      tcsetpgrp(0, getpgrp());
    }
  else
    {
      setpgrp();
      tcsetpgrp(0, getpgrp());
      if (execve(tab[0], tab, environ) == -1)
 return ((*value = 1) + !((*sys_fail) = 1) +
  !fprintf(stderr, "%s: Command not found\n", tab[0]));
    }
  return (0 != (*value = (((clean_signal(tab[0], st, tab)) & 0xff00) >> 8)));
}

canonical_original_code:
int exec_form(struct s_words *list, unsigned char *sys_fail, int *value)
{
  int st;
  int pid;
  char **tab;
  init();
  if ((tab = to_tab(list, sys_fail)) == ((void *)0))
    return (1 + !((*sys_fail) = 1));
  if ((pid = fork()) == -1)
    return (1 + !((*sys_fail) = 1));
  if (pid)
    {
      signal(2, catch_more);
      while (waitpid(pid, &st, 1) != -1)
 if (stop(0) == 1)
   kill(pid, 2);
      tcsetpgrp(0, getpgrp());
    }
  else
    {
      setpgrp();
      tcsetpgrp(0, getpgrp());
      if (execve(tab[0], tab, environ) == -1)
 return ((*value = 1) + !((*sys_fail) = 1) +
  !fprintf(stderr, "%s: Command not found\n", tab[0]));
    }
  return (0 != (*value = (((clean_signal(tab[0], st, tab)) & 0xff00) >> 8)));
}

variable_types: struct s_words { char *word; struct s_words *next; } *

variable_types:
value
int *

variable_types: st int

variable_types: pid int


original_code:
char *my_strncat(const char *s, const char *c, size_t n)
{
  size_t i;
  size_t si;
  size_t ci;
  char *r;
  si = my_strlen(s);
  if ((ci = my_strlen(c)) > n)
    ci = n;
  if ((r = xmalloc(sizeof(char) * (si + ci + 1))) == ((void *)0))
    return (((void *)0));
  r[si + ci] = 0;
  i = 0;
  if (s)
    while (i < si)
      {
 r[i] = s[i];
 i++;
      }
  while (i < si + ci)
    {
      r[i] = c[i - si];
      i++;
    }
  r[i] = 0;
  return (r);
}

canonical_original_code:
char *my_strncat(char *s, char *c, unsigned long n)
{
  unsigned long i;
  unsigned long si;
  unsigned long ci;
  char *r;
  si = my_strlen(s);
  if ((ci = my_strlen(c)) > n)
    ci = n;
  if ((r = xmalloc(sizeof(char) * (si + ci + 1))) == ((void *)0))
    return (((void *)0));
  r[si + ci] = 0;
  i = 0;
  if (s)
    while (i < si)
      {
 r[i] = s[i];
 i++;
      }
  while (i < si + ci)
    {
      r[i] = c[i - si];
      i++;
    }
  r[i] = 0;
  return (r);
}

variable_types:
s
char *

variable_types:
c
char *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

variable_types:
si
unsigned long

variable_types:
ci
unsigned long

variable_types:
r
char *


decompiled_code:
bool __fastcall add_redir(__int64 a1, __int64 a2, __int64 a3, __int64 *a4)
{
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rax
bool result; // al
__int64 v9; // rax

v4 = *a4;
if ( *a4 )
{
do
{
v5 = v4;
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
v6 = redir_part();
*(_QWORD *)(v5 + 24) = v6;
result = v6 != 0;
}
else
{
v9 = redir_part();
*a4 = v9;
result = v9 != 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 *a4)
{
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rax
bool result; // al
__int64 v9; // rax

v4 = *a4;
if ( *a4 )
{
do
{
v5 = v4;
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
v6 = redir_part();
*(_QWORD *)(v5 + 24) = v6;
result = v6 != 0;
}
else
{
v9 = redir_part();
*a4 = v9;
result = v9 != 0;
}
return result;
}

original_code:
unsigned char add_redir(t_get *word, t_get **words,
     char **bad_sintax, t_cmd *link)
{
  t_redir *prev;
  prev = link->redir;
  if (prev)
    while (prev->next)
      prev = prev->next;
  if (prev)
    if ((prev->next = redir_part(word, words, bad_sintax)) == ((void *)0))
      return (0);
  if (!prev)
    if ((link->redir = redir_part(word, words, bad_sintax)) == ((void *)0))
      return (0);
  return (1);
}

canonical_original_code:
unsigned char add_redir(struct s_get *word, struct s_get **words, char **bad_sintax, struct s_cmd *link)
{
  struct s_redir *prev;
  prev = link->redir;
  if (prev)
    while (prev->next)
      prev = prev->next;
  if (prev)
    if ((prev->next = redir_part(word, words, bad_sintax)) == ((void *)0))
      return (0);
  if (!prev)
    if ((link->redir = redir_part(word, words, bad_sintax)) == ((void *)0))
      return (0);
  return (1);
}

variable_types: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *

variable_types:
words
struct s_get **

variable_types: struct s_cmd { struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *redir; unsigned int type; struct s_words { char *word; struct s_words *next; } *params; struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes { struct s_pipes *next; struct s_get *tmp; struct s_cmd *cmd; } *pipes; struct s_get *tmp; } *exec; struct s_get *tmp; } *parents; } *


decompiled_code:
__int64 __fastcall only_option(_BYTE *a1)
{
_BYTE *v1; // rbx

if ( !*a1 )
return 0LL;
v1 = a1 + 1;
do
{
if ( !byte_1F0[my_strilen(byte_1F0)] )
return 0LL;
}
while ( *v1++ );
return 1LL;
}

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

if ( !*a1 )
return 0LL;
v1 = a1 + 1;
do
{
if ( !byte_1F0[my_strilen(byte_1F0)] )
return 0LL;
}
while ( *v1++ );
return 1LL;
}

original_code:
static unsigned char only_option(char *s)
{
  size_t i;
  i = 0;
  if (!s[i])
    return (0);
  while (s[i])
    {
      if (!(("Een")[my_strilen("Een", s[i])] != 0))
 return (0);
      i++;
    }
  return (1);
}

canonical_original_code:
static unsigned char only_option(char *s)
{
  unsigned long i;
  i = 0;
  if (!s[i])
    return (0);
  while (s[i])
    {
      if (!(("Een")[my_strilen("Een", s[i])] != 0))
 return (0);
      i++;
    }
  return (1);
}


decompiled_code:
__int64 __fastcall built_echo(_QWORD *a1)
{
_QWORD *v1; // rdi
_QWORD *v3; // [rsp+8h] [rbp-20h] BYREF
unsigned int v4[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v3 = a1;
v1 = (_QWORD *)a1[1];
v4[0] = 0;
move_flag_constprop_0(v1, &v3, v4);
if ( !(unsigned __int8)print(v4[0], v3) || (v4[0] & 1) != 0 )
return 0LL;
my_putstr(&unk_1F4, 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
_QWORD *v1; // rdi
_QWORD *v3; // [rsp+8h] [rbp-20h] BYREF
unsigned int v4[3]; // [rsp+1Ch] [rbp-Ch] BYREF

v3 = a1;
v1 = (_QWORD *)a1[1];
v4[0] = 0;
func2(v1, &v3, v4);
if ( !(unsigned __int8)func1(v4[0], v3) || (v4[0] & 1) != 0 )
return 0LL;
my_putstr(&unk_1F4, 1LL);
return 0LL;
}

original_code:
int built_echo(t_words *cmd, void *null)
{
  unsigned int echo;
  echo = 0;
  (void)null;
  move_flag(cmd->next, &cmd, &echo);
  if (print(echo, cmd) == 0)
    return (0);
  if (!(echo & 0b001))
    my_putstr("\n", 1);
  return (0);
}

canonical_original_code:
int built_echo(struct s_words *cmd, void *null)
{
  unsigned int echo;
  echo = 0;
  (void)null;
  move_flag(cmd->next, &cmd, &echo);
  if (print(echo, cmd) == 0)
    return (0);
  if (!(echo & 0b001))
    my_putstr("\n", 1);
  return (0);
}

variable_types:
echo
unsigned int


print

decompiled_code:
__int64 __fastcall print(unsigned int a1, _QWORD *a2)
{
__int64 v4; // rbx
unsigned int v5; // er12
_BYTE *v6; // rdi
__int64 v7; // rsi
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( !a2 )
return 1LL;
v9[0] = 0;
v4 = 0LL;
while ( 1 )
{
v6 = (_BYTE *)(v4 + *a2);
if ( !*v6 )
break;
v5 = (unsigned __int8)v9[0];
v4 += print_seq(v6, a1, v9);
if ( v9[0] )
return v5;
}
v7 = a2[1];
if ( v7 )
{
my_putchar(32LL, 1LL);
v7 = a2[1];
}
return (unsigned int)print(a1, v7);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, _QWORD *a2)
{
__int64 v4; // rbx
unsigned int v5; // er12
_BYTE *v6; // rdi
__int64 v7; // rsi
char v9[41]; // [rsp+Fh] [rbp-29h] BYREF

if ( !a2 )
return 1LL;
v9[0] = 0;
v4 = 0LL;
while ( 1 )
{
v6 = (_BYTE *)(v4 + *a2);
if ( !*v6 )
break;
v5 = (unsigned __int8)v9[0];
v4 += print_seq(v6, a1, v9);
if ( v9[0] )
return v5;
}
v7 = a2[1];
if ( v7 )
{
my_putchar(32LL, 1LL);
v7 = a2[1];
}
return (unsigned int)func1(a1, v7);
}

original_code:
static unsigned char print(unsigned int echo, t_words *link)
{
  unsigned char end;
  size_t i;
  if (!link)
    return (1);
  end = 0;
  i = 0;
  while ((link->word)[i] && !end)
    {
      i += print_seq(link->word + i, echo, &end);
      if (end)
 return (0);
    }
  if (link->next)
    my_putchar(' ', 1);
  return (print(echo, link->next));
}

canonical_original_code:
static unsigned char print(unsigned int echo, struct s_words *link)
{
  unsigned char end;
  unsigned long i;
  if (!link)
    return (1);
  end = 0;
  i = 0;
  while ((link->word)[i] && !end)
    {
      i += print_seq(link->word + i, echo, &end);
      if (end)
 return (0);
    }
  if (link->next)
    my_putchar(' ', 1);
  return (print(echo, link->next));
}

variable_types:
end
unsigned char


decompiled_code:
__int64 __fastcall push_alias(__int64 a1, _QWORD *a2, _QWORD *a3, unsigned __int64 a4)
{
_QWORD *v6; // rbx
__int64 v7; // rbp
__int64 v8; // rbp
__int64 v9; // rax
unsigned __int64 v10; // rax
__int64 v11; // rbp
__int64 v12; // rax
__int64 v13; // rax
void *v14; // rbp
void *v15; // r12
char *v16; // rbp
__int64 v17; // rax

if ( !a2 )
return 0LL;
v6 = a2;
do
{
v8 = my_strlen(*v6);
if ( v8 == my_sstrlen(a1, " \\\t\"'|&;()`") || (v7 = my_strlen(*v6), v7 == my_strlen(a1)) )
{
if ( *v6 )
{
if ( a1 )
{
v9 = my_strlen(*v6);
if ( !(unsigned int)my_strncmp(*v6, a1, v9) )
{
v10 = v6[4];
if ( v10 <= a4 && v6[5] + v10 <= a4 )
{
v11 = my_strlen(v6[1]);
v12 = my_strlen(*v6);
extend(v6, a4, v11 - v12);
v13 = my_strndup(*a3);
v14 = (void *)v13;
if ( v13 )
{
v15 = (void *)my_strcat(v13, v6[1]);
if ( v15 )
{
free(v14);
LABEL_14:
v16 = (char *)*a3;
v17 = my_strlen(*v6);
*a3 = my_strcat(v15, &v16[v17 + a4]);
free(v15);
free(v16);
v6[4] = a4;
v6[5] = my_strlen(v6[1]);
return 1LL;
}
}
else if ( !a4 )
{
v15 = (void *)my_strcat(0LL, v6[1]);
if ( v15 )
goto LABEL_14;
}
return 0xFFFFFFFFLL;
}
}
}
}
}
v6 = (_QWORD *)v6[2];
}
while ( v6 );
return 0LL;
}

original_code:
static int push_alias(char *s, t_alias *alias, char **mod, size_t n)
{
  char *r;
  char *r2;
  if (!alias)
    return (0);
  if (!((my_strlen(alias->name) == my_sstrlen(s, " \\\t\"'|&;()`") ||
  my_strlen(alias->name) == my_strlen(s))&&
 (((alias->name) && (s)) ? (!my_strncmp((alias->name), (s), my_strlen(alias->name))) : (0))))
    return (push_alias(s, alias->next, mod, n));
  if ((alias->w <= n && alias->w + alias->n > n) || alias->w > n)
    return (push_alias(s, alias->next, mod, n));
  extend(alias, n, my_strlen(alias->fill) - my_strlen(alias->name));
  if ((r = my_strndup(*mod, n)) == ((void *)0) && n != 0)
    return (-1);
  if ((r2 = my_strcat(r, alias->fill)) == ((void *)0))
    return (-1);
  if (r)
    free(r);
  s = *mod;
  *mod = my_strcat(r2, s + n + my_strlen(alias->name));
  free(r2);
  free(s);
  alias->w = n;
  alias->n = my_strlen(alias->fill);
  return (1);
}

canonical_original_code:
static int push_alias(char *s, struct s_alias *alias, char **mod, unsigned long n)
{
  char *r;
  char *r2;
  if (!alias)
    return (0);
  if (!((my_strlen(alias->name) == my_sstrlen(s, " \\\t\"'|&;()`") ||
  my_strlen(alias->name) == my_strlen(s))&&
 (((alias->name) && (s)) ? (!my_strncmp((alias->name), (s), my_strlen(alias->name))) : (0))))
    return (push_alias(s, alias->next, mod, n));
  if ((alias->w <= n && alias->w + alias->n > n) || alias->w > n)
    return (push_alias(s, alias->next, mod, n));
  extend(alias, n, my_strlen(alias->fill) - my_strlen(alias->name));
  if ((r = my_strndup(*mod, n)) == ((void *)0) && n != 0)
    return (-1);
  if ((r2 = my_strcat(r, alias->fill)) == ((void *)0))
    return (-1);
  if (r)
    free(r);
  s = *mod;
  *mod = my_strcat(r2, s + n + my_strlen(alias->name));
  free(r2);
  free(s);
  alias->w = n;
  alias->n = my_strlen(alias->fill);
  return (1);
}

variable_types: struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } *

variable_types:
mod
char **


original_code:
static int grow_alias(char *s, t_alias *alias, size_t n, char **mod)
{
  int r;
  if (!s[0])
    return (0);
  if ((r = push_alias(s, alias, mod, n)))
    return (r);
  return (grow_alias(s + (my_sstrlen(s, "&|;(`")
     + (s[my_sstrlen(s, "&|;(`")] != 0)
     + hempty(s + my_sstrlen(s, "&|;(`")
       + (s[my_sstrlen(s, "&|;(`")] != 0)))
       , alias
       , n + (my_sstrlen(s, "&|;(`")
       + (s[my_sstrlen(s, "&|;(`")] != 0)
       + hempty(s + my_sstrlen(s, "&|;(`")
         + (s[my_sstrlen(s, "&|;(`")] != 0)))
       , mod));
}

canonical_original_code:
static int grow_alias(char *s, struct s_alias *alias, unsigned long n, char **mod)
{
  int r;
  if (!s[0])
    return (0);
  if ((r = push_alias(s, alias, mod, n)))
    return (r);
  return (grow_alias(s + (my_sstrlen(s, "&|;(`")
     + (s[my_sstrlen(s, "&|;(`")] != 0)
     + hempty(s + my_sstrlen(s, "&|;(`")
       + (s[my_sstrlen(s, "&|;(`")] != 0)))
       , alias
       , n + (my_sstrlen(s, "&|;(`")
       + (s[my_sstrlen(s, "&|;(`")] != 0)
       + hempty(s + my_sstrlen(s, "&|;(`")
         + (s[my_sstrlen(s, "&|;(`")] != 0)))
       , mod));
}

variable_types: r int


original_code:
unsigned char seed_alias(char *s, t_alias *alias, char **mod_s)
{
  t_alias *mod;
  int r;
  if (!alias)
    return (1);
  mod = alias;
  while (mod)
    {
      mod->w = 0;
      mod->n = 0;
      mod = mod->next;
    }
  r = 0;
  if (alias)
    while ((r = grow_alias(s + hempty(s), alias, hempty(s), &s)) > 0);
  *mod_s = s;
  if (!r)
    return (1);
  return (0);
}

canonical_original_code:
unsigned char seed_alias(char *s, struct s_alias *alias, char **mod_s)
{
  struct s_alias *mod;
  int r;
  if (!alias)
    return (1);
  mod = alias;
  while (mod)
    {
      mod->w = 0;
      mod->n = 0;
      mod = mod->next;
    }
  r = 0;
  if (alias)
    while ((r = grow_alias(s + hempty(s), alias, hempty(s), &s)) > 0);
  *mod_s = s;
  if (!r)
    return (1);
  return (0);
}


decompiled_code:
__int64 __fastcall take_cmd_from_history(int a1, _DWORD *a2, void **a3, _QWORD *a4)
{
int v6; // eax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdi
__int64 v11; // rax
__int64 v12; // rax

if ( !a1 )
{
v11 = my_strlen(*a3);
v12 = my_memset(*a3, 0LL, v11);
*a3 = (void *)v12;
v9 = v12;
LABEL_5:
*a2 = my_strlen(v9);
return 0LL;
}
v6 = 1;
if ( a1 > 1 )
{
do
{
++v6;
a4 = (_QWORD *)a4[2];
}
while ( a1 != v6 );
}
free(*a3);
v7 = my_strlen(*a4);
v8 = my_strndup(*a4, v7 + 1);
*a3 = (void *)v8;
v9 = v8;
if ( v8 )
goto LABEL_5;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, _DWORD *a2, void **a3, _QWORD *a4)
{
int v6; // eax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rdi
__int64 v11; // rax
__int64 v12; // rax

if ( !a1 )
{
v11 = my_strlen(*a3);
v12 = my_memset(*a3, 0LL, v11);
*a3 = (void *)v12;
v9 = v12;
LABEL_5:
*a2 = my_strlen(v9);
return 0LL;
}
v6 = 1;
if ( a1 > 1 )
{
do
{
++v6;
a4 = (_QWORD *)a4[2];
}
while ( a1 != v6 );
}
free(*a3);
v7 = my_strlen(*a4);
v8 = my_strndup(*a4, v7 + 1);
*a3 = (void *)v8;
v9 = v8;
if ( v8 )
goto LABEL_5;
return 0xFFFFFFFFLL;
}

original_code:
int take_cmd_from_history(int history_pl, int *rev_c,
         char **cmd, t_history *history)
{
  int i;
  i = 0;
  if (history_pl == 0)
    (*cmd) = my_memset(*cmd, 0, my_strlen(*cmd));
  else
    {
      while (++i < history_pl)
 history = history->next;
      free(*cmd);
      if (((*cmd) =
    my_strndup(history->str, my_strlen(history->str) + 1)) == ((void *)0))
 return (-1);
    }
  (*rev_c) = my_strlen(*cmd);
  return (0);
}

canonical_original_code:
int take_cmd_from_history(int history_pl, int *rev_c, char **cmd, struct s_history *history)
{
  int i;
  i = 0;
  if (history_pl == 0)
    (*cmd) = my_memset(*cmd, 0, my_strlen(*cmd));
  else
    {
      while (++i < history_pl)
 history = history->next;
      free(*cmd);
      if (((*cmd) =
    my_strndup(history->str, my_strlen(history->str) + 1)) == ((void *)0))
 return (-1);
    }
  (*rev_c) = my_strlen(*cmd);
  return (0);
}

variable_types:
cmd
char **

variable_types: struct s_history { char *str; struct s_history *prev; struct s_history *next; } *

variable_types: i int


decompiled_code:
char *env_copy()
{
char **v0; // rbx
__int64 v1; // rax
int v2; // edx
__int64 v3; // rbp
size_t v4; // rdi
char *v5; // rax
char *v6; // r12
__int64 v7; // rbx

v0 = environ;
if ( *environ )
{
v1 = 1LL;
do
{
v2 = v1;
v3 = 8 * v1++;
}
while ( environ[v1 - 1] );
v4 = 8LL * (v2 + 1);
}
else
{
v4 = 8LL;
v3 = 0LL;
}
v5 = (char *)malloc(v4);
v6 = v5;
if ( v5 )
{
*(_QWORD *)&v5[v3] = 0LL;
if ( *v0 )
{
v7 = 0LL;
do
{
*(_QWORD *)&v6[v7 * 8] = my_strdup();
++v7;
}
while ( environ[v7] );
}
}
return v6;
}

canonical_decompiled_code:
char *func0()
{
char **v0; // rbx
__int64 v1; // rax
int v2; // edx
__int64 v3; // rbp
size_t v4; // rdi
char *v5; // rax
char *v6; // r12
__int64 v7; // rbx

v0 = environ;
if ( *environ )
{
v1 = 1LL;
do
{
v2 = v1;
v3 = 8 * v1++;
}
while ( environ[v1 - 1] );
v4 = 8LL * (v2 + 1);
}
else
{
v4 = 8LL;
v3 = 0LL;
}
v5 = (char *)malloc(v4);
v6 = v5;
if ( v5 )
{
*(_QWORD *)&v5[v3] = 0LL;
if ( *v0 )
{
v7 = 0LL;
do
{
*(_QWORD *)&v6[v7 * 8] = my_strdup();
++v7;
}
while ( environ[v7] );
}
}
return v6;
}

original_code:
char **env_copy()
{
  char **tab;
  int i;
  i = 0;
  while (environ[i] != ((void *)0))
      i++;
  if ((tab = malloc(sizeof(char *) * (i + 1))) == ((void *)0))
    return (((void *)0));
  tab[i] = ((void *)0);
  i = 0;
  while (environ[i] != ((void *)0))
    {
      tab[i] = my_strdup(environ[i]);
      i++;
    }
  return (tab);
}

variable_types:
tab
char **

return_type: char **


rdright

decompiled_code:
int __fastcall rdright(__int64 a1, __int64 a2)
{
__int64 v3; // rax
int *v4; // rbx
int v5; // edi
int result; // eax

v3 = 4LL * *(int *)(a1 + 8);
if ( *(_DWORD *)(a1 + 8) >= 3u )
v3 = 4LL;
v4 = (int *)(a2 + v3);
v5 = *(_DWORD *)(a2 + v3);
if ( v5 >= 0 )
close(v5);
result = open(*(const char **)(a1 + 16), 1025);
*v4 = result;
if ( result == -1 )
{
result = open(*(const char **)(a1 + 16), 577, 420LL);
*v4 = result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v3; // rax
int *v4; // rbx
int v5; // edi
int result; // eax

v3 = 4LL * *(int *)(a1 + 8);
if ( *(_DWORD *)(a1 + 8) >= 3u )
v3 = 4LL;
v4 = (int *)(a2 + v3);
v5 = *(_DWORD *)(a2 + v3);
if ( v5 >= 0 )
close(v5);
result = open(*(const char **)(a1 + 16), 1025);
*v4 = result;
if ( result == -1 )
{
result = open(*(const char **)(a1 + 16), 577, 420LL);
*v4 = result;
}
return result;
}

variable_types: struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *

variable_types:
w
int [3]

variable_types: in int


rleft

decompiled_code:
__int64 __fastcall rleft(__int64 a1, int *a2, _QWORD *a3)
{
__int64 v4; // rax
int *v5; // rbx
int v6; // eax
__int64 result; // rax

v4 = *(int *)(a1 + 8);
v5 = a2;
if ( (unsigned int)v4 <= 2 )
v5 = &a2[v4];
if ( *v5 >= 0 )
close(*v5);
v6 = open(*(const char **)(a1 + 16), 0);
if ( v6 == -1 )
{
*a3 = my_strcat("(sh): NO such file or directory: ", *(_QWORD *)(a1 + 16));
result = 0LL;
}
else
{
*v5 = v6;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int *a2, _QWORD *a3)
{
__int64 v4; // rax
int *v5; // rbx
int v6; // eax
__int64 result; // rax

v4 = *(int *)(a1 + 8);
v5 = a2;
if ( (unsigned int)v4 <= 2 )
v5 = &a2[v4];
if ( *v5 >= 0 )
close(*v5);
v6 = open(*(const char **)(a1 + 16), 0);
if ( v6 == -1 )
{
*a3 = my_strcat("(sh): NO such file or directory: ", *(_QWORD *)(a1 + 16));
result = 0LL;
}
else
{
*v5 = v6;
result = 1LL;
}
return result;
}

original_code:
unsigned char rleft(t_redir *r, int w[3], char **bad_syntax)
{
  int file;
  int in;
  in = 0;
  if (r->in < 3 && r->in >= 0)
    in = r->in;
  if (w[in] >= 0)
    close(w[in]);
  if ((file = open(r->file, 00)) == -1)
    {
      *bad_syntax = my_strcat("(sh): NO such file or directory: ", r->file);
      return (0);
    }
  w[in] = file;
  return (1);
}

canonical_original_code:
unsigned char rleft(struct s_redir *r, int w[3], char **bad_syntax)
{
  int file;
  int in;
  in = 0;
  if (r->in < 3 && r->in >= 0)
    in = r->in;
  if (w[in] >= 0)
    close(w[in]);
  if ((file = open(r->file, 00)) == -1)
    {
      *bad_syntax = my_strcat("(sh): NO such file or directory: ", r->file);
      return (0);
    }
  w[in] = file;
  return (1);
}

variable_types: file int


rright

variable_types:
l
int [3]


decompiled_code:
__int64 __fastcall calque_redir(__int64 a1, int *a2, __int64 a3, _QWORD *a4)
{
__int64 v6; // rbx
int v7; // eax

if ( a1 )
{
v6 = a1;
while ( 1 )
{
while ( 1 )
{
v7 = *(_DWORD *)v6;
if ( *(_DWORD *)v6 != 1 )
break;
if ( !(unsigned __int8)rleft(v6, a2, a4) )
return 0LL;
LABEL_7:
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
return 1LL;
}
if ( v7 != 4 )
{
if ( v7 == 2 )
{
rright(v6, (__int64)a2, *(_QWORD *)(a3 + 96));
}
else if ( v7 == 8 )
{
rdright(v6, (__int64)a2);
}
goto LABEL_7;
}
if ( !(unsigned __int8)rdleft(v6, a2, a3) )
return 0LL;
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
return 1LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int *a2, __int64 a3, _QWORD *a4)
{
__int64 v6; // rbx
int v7; // eax

if ( a1 )
{
v6 = a1;
while ( 1 )
{
while ( 1 )
{
v7 = *(_DWORD *)v6;
if ( *(_DWORD *)v6 != 1 )
break;
if ( !(unsigned __int8)func1(v6, a2, a4) )
return 0LL;
LABEL_7:
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
return 1LL;
}
if ( v7 != 4 )
{
if ( v7 == 2 )
{
func2(v6, (__int64)a2, *(_QWORD *)(a3 + 96));
}
else if ( v7 == 8 )
{
func0(v6, (__int64)a2);
}
goto LABEL_7;
}
if ( !(unsigned __int8)rdleft(v6, a2, a3) )
return 0LL;
v6 = *(_QWORD *)(v6 + 24);
if ( !v6 )
return 1LL;
}
}
return 1LL;
}

original_code:
unsigned char calque_redir(t_redir *r, int w[3], t_info *i, char **bad_syntax)
{
  if (!r)
    return (1);
  if (r->redir == 0b0001)
    {
      if (rleft(r, w, bad_syntax) == 0)
 return (0);
    }
  else if (r->redir == 0b0100)
    {
      if (rdleft(r, w, i) == 0)
 return (0);
    }
  else if (r->redir == 0b0010)
    rright(r, w, i->wr);
  else if (r->redir == 0b1000)
    rdright(r, w);
  return (calque_redir(r->next, w, i, bad_syntax));
}

canonical_original_code:
unsigned char calque_redir(struct s_redir *r, int w[3], struct s_info *i, char **bad_syntax)
{
  if (!r)
    return (1);
  if (r->redir == 0b0001)
    {
      if (rleft(r, w, bad_syntax) == 0)
 return (0);
    }
  else if (r->redir == 0b0100)
    {
      if (rdleft(r, w, i) == 0)
 return (0);
    }
  else if (r->redir == 0b0010)
    rright(r, w, i->wr);
  else if (r->redir == 0b1000)
    rdright(r, w);
  return (calque_redir(r->next, w, i, bad_syntax));
}

variable_types: struct s_info { struct s_history { char *str; struct s_history *prev; struct s_history *next; } *hist; struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; } termcaps; unsigned char term_caps; int *wr; int st; int value; unsigned int son; struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } *alias; } *


decompiled_code:
__int64 __fastcall not_a_built_in(__int64 a1)
{
__int64 *v2; // rax
__int64 v3; // rdi
__int64 *v4; // r12
__int64 *v5; // rbx
__int64 result; // rax

v2 = (__int64 *)builtins();
v3 = *v2;
v4 = v2;
if ( *v2 )
{
v5 = v2 + 2;
while ( !a1 || (unsigned int)my_strcmp(v3, a1) )
{
v3 = *v5;
v5 += 2;
if ( !v3 )
goto LABEL_6;
}
free(v4);
result = 0LL;
}
else
{
LABEL_6:
free(v4);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 *v2; // rax
__int64 v3; // rdi
__int64 *v4; // r12
__int64 *v5; // rbx
__int64 result; // rax

v2 = (__int64 *)builtins();
v3 = *v2;
v4 = v2;
if ( *v2 )
{
v5 = v2 + 2;
while ( !a1 || (unsigned int)my_strcmp(v3, a1) )
{
v3 = *v5;
v5 += 2;
if ( !v3 )
goto LABEL_6;
}
free(v4);
result = 0LL;
}
else
{
LABEL_6:
free(v4);
result = 1LL;
}
return result;
}

original_code:
static unsigned char not_a_built_in(char *word)
{
  t_call *built_call;
  size_t i;
  i = 0;
  built_call = builtins();
  while ((built_call[i]).name)
    {
      if ((((built_call[i]).name && word) ? (!my_strcmp((built_call[i]).name, word)) : (0)))
 {
   free(built_call);
   return (0);
 }
      i++;
    }
  free(built_call);
  return (1);
}

canonical_original_code:
static unsigned char not_a_built_in(char *word)
{
  struct s_call *built_call;
  unsigned long i;
  i = 0;
  built_call = builtins();
  while ((built_call[i]).name)
    {
      if ((((built_call[i]).name && word) ? (!my_strcmp((built_call[i]).name, word)) : (0)))
 {
   free(built_call);
   return (0);
 }
      i++;
    }
  free(built_call);
  return (1);
}

variable_types:
word
char *

variable_types: struct s_call { char *name; int (*ptr)(struct s_words { char *word; struct s_words *next; } *, void *); } *

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall nullify_link(void *a1)
{
free(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1)
{
free(a1);
return 0LL;
}

original_code:
static void *nullify_link(t_words *link)
{
  free(link);
  return (((void *)0));
}

canonical_original_code:
static void *nullify_link(struct s_words *link)
{
  free(link);
  return (((void *)0));
}

variable_types: struct s_words { char *word; struct s_words *next; } *

return_type: void *


decompiled_code:
char *__fastcall lowercase_letters_found(__int64 a1, int *a2, __int64 *a3)
{
__int64 v3; // rdi
char *result; // rax
char i; // dl
int v7; // eax

v3 = *a3;
result = (char *)(*a3 + *a2);
for ( i = *result; (*result & 0xDF) != 0; i = *result )
{
if ( i == 9 )
break;
if ( (unsigned __int8)(i - 65) <= 0x19u )
{
*result = i + 32;
v3 = *a3;
}
v7 = *a2 + 1;
*a2 = v7;
result = (char *)(v3 + v7);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, int *a2, __int64 *a3)
{
__int64 v3; // rdi
char *result; // rax
char i; // dl
int v7; // eax

v3 = *a3;
result = (char *)(*a3 + *a2);
for ( i = *result; (*result & 0xDF) != 0; i = *result )
{
if ( i == 9 )
break;
if ( (unsigned __int8)(i - 65) <= 0x19u )
{
*result = i + 32;
v3 = *a3;
}
v7 = *a2 + 1;
*a2 = v7;
result = (char *)(v3 + v7);
}
return result;
}

original_code:
void lowercase_letters_found(char value, int *rev_c, char **cmd)
{
  (void)value;
  while ((*cmd)[*rev_c] != '\0' &&
         (*cmd)[*rev_c] != ' ' && (*cmd)[*rev_c] != '\t')
    {
      if ((*cmd)[*rev_c] >= 'A' && (*cmd)[*rev_c] <= 'Z')
        ((*cmd)[*rev_c]) += 32;
      (*rev_c)++;
    }
}

variable_types: value char


decompiled_code:
char *__fastcall uppercase_first_letter_found(char a1, int *a2, __int64 *a3)
{
__int64 v3; // rcx
char *result; // rax
char v5; // r8

v3 = *a2;
result = (char *)(*a3 + v3);
v5 = *result;
if ( *result )
{
if ( (unsigned __int8)(v5 - 97) <= 0x19u )
{
*result = v5 - 32;
LODWORD(v3) = *a2;
}
*a2 = v3 + 1;
result = lowercase_letters_found((unsigned int)a1, a2, a3);
}
return result;
}

canonical_decompiled_code:
char *__fastcall func1(char a1, int *a2, __int64 *a3)
{
__int64 v3; // rcx
char *result; // rax
char v5; // r8

v3 = *a2;
result = (char *)(*a3 + v3);
v5 = *result;
if ( *result )
{
if ( (unsigned __int8)(v5 - 97) <= 0x19u )
{
*result = v5 - 32;
LODWORD(v3) = *a2;
}
*a2 = v3 + 1;
result = func0((unsigned int)a1, a2, a3);
}
return result;
}

original_code:
void uppercase_first_letter_found(char value, int *rev_c, char **cmd)
{
  if ((*cmd)[*rev_c] != '\0')
    {
      if ((*cmd)[*rev_c] >= 'a' && (*cmd)[*rev_c] <= 'z')
        ((*cmd)[*rev_c]) -= 32;
      (*rev_c)++;
      lowercase_letters_found(value, rev_c, cmd);
    }
}


original_code:
int rm_alias(t_words *cmd, t_alias *link, t_alias **alias)
{
  if (!cmd)
    return (0);
  if (!link)
    return (rm_alias(cmd->next, *alias, alias));
  if (!((cmd->word && link->name) ? (!my_strcmp(cmd->word, link->name)) : (0)))
    return (rm_alias(cmd, link->next, alias));
  if (link->prev)
    link->prev->next = link->next;
  else
    *alias = link->next;
  if (link->next)
    link->next->prev = link->prev;
  free(link->name);
  free(link->fill);
  free(link);
  return (rm_alias(cmd->next, *alias, alias));
}

canonical_original_code:
int rm_alias(struct s_words *cmd, struct s_alias *link, struct s_alias **alias)
{
  if (!cmd)
    return (0);
  if (!link)
    return (rm_alias(cmd->next, *alias, alias));
  if (!((cmd->word && link->name) ? (!my_strcmp(cmd->word, link->name)) : (0)))
    return (rm_alias(cmd, link->next, alias));
  if (link->prev)
    link->prev->next = link->next;
  else
    *alias = link->next;
  if (link->next)
    link->next->prev = link->prev;
  free(link->name);
  free(link->fill);
  free(link);
  return (rm_alias(cmd->next, *alias, alias));
}

variable_types: struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } *

variable_types:
alias
struct s_alias **


decompiled_code:
__int64 __fastcall built_unalias(__int64 a1, __int64 *a2)
{
_QWORD *v2; // rdi
__int64 result; // rax

v2 = *(_QWORD **)(a1 + 8);
if ( v2 )
{
rm_alias(v2, *a2, a2);
result = 0LL;
}
else
{
print_err("unalias: too few arguments.\n");
result = 1LL;
}
return result;
}

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

v2 = *(_QWORD **)(a1 + 8);
if ( v2 )
{
func0(v2, *a2, a2);
result = 0LL;
}
else
{
print_err("unalias: too few arguments.\n");
result = 1LL;
}
return result;
}

original_code:
int built_unalias(t_words *cmd, void *alias)
{
  if (!cmd->next)
    {
      print_err("unalias: too few arguments.\n");
      return (1);
    }
  rm_alias(cmd->next, *(t_alias**)alias, alias);
  return (0);
}

canonical_original_code:
int built_unalias(struct s_words *cmd, void *alias)
{
  if (!cmd->next)
    {
      print_err("unalias: too few arguments.\n");
      return (1);
    }
  rm_alias(cmd->next, *(struct s_alias **)alias, alias);
  return (0);
}

variable_types:
alias
void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v3; // bl
struct termios v5; // [rsp+0h] [rbp-C8h] BYREF
char v6[8]; // [rsp+40h] [rbp-88h] BYREF
char v7[96]; // [rsp+48h] [rbp-80h] BYREF
__int64 v8; // [rsp+A8h] [rbp-20h]
__int64 v9; // [rsp+B8h] [rbp-10h] BYREF

signal(20, handler);
v9 = 0LL;
environ = (char **)env_copy();
scan_export(&v9);
v8 = 0LL;
if ( !get_env(&unk_3) )
set_env(&unk_3, &unk_8);
v3 = 1;
if ( (unsigned int)load_tgets_funcs() != -1 )
v3 = tcgetattr(0, &v5) == -1;
attribute_options(v7);
retain_struct_options(1LL, v7);
read_cmds(v6, v3);
destroy_env();
return HIDWORD(v8);
}

original_code:
int main(void)
{
  unsigned char tget_fail;
  t_info info;
  struct termios test;
  signal(20, ((__sighandler_t) 1));
  info.alias = ((void *)0);
  environ = env_copy();
  scan_export(&(info.alias));
  info.st = 0;
  info.value = 0;
  if (!get_env("PS1"))
    set_env("PS1", "\033[0;34m█\033[1;31m\033[0m[\033[1;31m%u\033[0m]-[\033[1;34m%d\033[0m]-[\033[1;34m%h\033[0m] ╼ [ \033[1;34m%/\033[0m ] (\033[1;31mPrompt (setenv ps1 <prompt>)\033[0m)\n\033[1;30m>\033[0m ");
  tget_fail = 0;
  if (load_tgets_funcs() == -1 || tcgetattr(0, &test) == -1)
    tget_fail = 1;
  attribute_options(&(info.termcaps));
  retain_struct_options(1, &(info.termcaps));
  read_cmds(&info, tget_fail);
  destroy_env();
  return (info.value);
}

canonical_original_code:
int main()
{
  unsigned char tget_fail;
  struct s_info info;
  struct termios test;
  signal(20, ((void (*)(int)) 1));
  info.alias = ((void *)0);
  environ = env_copy();
  scan_export(&(info.alias));
  info.st = 0;
  info.value = 0;
  if (!get_env("PS1"))
    set_env("PS1", "\033[0;34m█\033[1;31m\033[0m[\033[1;31m%u\033[0m]-[\033[1;34m%d\033[0m]-[\033[1;34m%h\033[0m] ╼ [ \033[1;34m%/\033[0m ] (\033[1;31mPrompt (setenv ps1 <prompt>)\033[0m)\n\033[1;30m>\033[0m ");
  tget_fail = 0;
  if (load_tgets_funcs() == -1 || tcgetattr(0, &test) == -1)
    tget_fail = 1;
  attribute_options(&(info.termcaps));
  retain_struct_options(1, &(info.termcaps));
  read_cmds(&info, tget_fail);
  destroy_env();
  return (info.value);
}

variable_types: struct s_info { struct s_history { char *str; struct s_history *prev; struct s_history *next; } *hist; struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; } termcaps; unsigned char term_caps; int *wr; int st; int value; unsigned int son; struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } *alias; }

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


decompiled_code:
__int64 __fastcall sintax_error(_QWORD *a1)
{
*a1 = my_strcat("(sh): syntax error near unexpected token: ", &unk_1D9);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
*a1 = my_strcat("(sh): syntax error near unexpected token: ", &unk_1D9);
return 0LL;
}

original_code:
static void *sintax_error(char **bad_sintax)
{
  *bad_sintax = my_strcat("(sh): syntax error near unexpected token: ", "(");
  return (((void *)0));
}


decompiled_code:
__int64 __fastcall nullify_all_exec(_QWORD *a1)
{
__int64 v1; // r12

if ( !a1 )
return 0LL;
v1 = a1[1];
if ( a1[2] )
nullify_all_pipes();
else
nullify_words(a1[3]);
free(a1);
nullify_all_exec(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 v1; // r12

if ( !a1 )
return 0LL;
v1 = a1[1];
if ( a1[2] )
nullify_all_pipes();
else
nullify_words(a1[3]);
free(a1);
func0(v1);
return 0LL;
}

original_code:
unsigned char nullify_all_exec(t_exec *exec)
{
  t_exec *next;
  if (!exec)
    return (0);
  next = exec->next;
  if (exec->pipes)
    nullify_all_pipes(exec->pipes);
  else
    nullify_words(exec->tmp);
  free(exec);
  nullify_all_exec(next);
  return (0);
}

canonical_original_code:
unsigned char nullify_all_exec(struct s_exec *exec)
{
  struct s_exec *next;
  if (!exec)
    return (0);
  next = exec->next;
  if (exec->pipes)
    nullify_all_pipes(exec->pipes);
  else
    nullify_words(exec->tmp);
  free(exec);
  nullify_all_exec(next);
  return (0);
}

variable_types: struct s_exec { unsigned int type; struct s_exec *next; struct s_pipes { struct s_pipes *next; struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *tmp; struct s_cmd { struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *redir; unsigned int type; struct s_words { char *word; struct s_words *next; } *params; struct s_jobs { unsigned int type; struct s_jobs *next; struct s_exec *exec; struct s_get *tmp; } *parents; } *cmd; } *pipes; struct s_get *tmp; } *


decompiled_code:
void __fastcall rm_words(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void rm_words(t_get *w)
{
  free(w->word);
  free(w);
}

canonical_original_code:
void rm_words(struct s_get *w)
{
  free(w->word);
  free(w);
}

variable_types: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *


get

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

if ( a1 )
result = get_next_line(0LL);
else
result = usr_cmd(a2, 0LL);
return result;
}

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

if ( a1 )
result = get_next_line(0LL);
else
result = usr_cmd(a2, 0LL);
return result;
}

original_code:
static char *get(unsigned char tgetfail, int rw)
{
  struct s_options termcaps;
  char *r;
  if (tgetfail == 0)
    r = usr_cmd(rw, ((void *)0), termcaps);
  else
    r = get_next_line(0);
  return (r);
}

variable_types:
tgetfail
unsigned char

variable_types: rw int

variable_types: struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; }

variable_types:
r
char *


decompiled_code:
void __fastcall set_rd_prompt(void **a1, int a2)
{
__int64 v2; // rax

if ( a2 )
{
set_env(&unk_28F, *a1);
free(*a1);
}
else
{
v2 = get_env(&unk_28F);
*a1 = (void *)my_strdup(v2);
set_env(&unk_28F, &unk_293);
}
}

canonical_decompiled_code:
void __fastcall func1(void **a1, int a2)
{
__int64 v2; // rax

if ( a2 )
{
set_env(&unk_28F, *a1);
free(*a1);
}
else
{
v2 = get_env(&unk_28F);
*a1 = (void *)my_strdup(v2);
set_env(&unk_28F, &unk_293);
}
}

original_code:
static void set_rd_prompt(char **pt, int lap)
{
  if (lap == 0)
    {
      *pt = my_strdup(get_env("PS1"));
      set_env("PS1", "> ");
      return ;
    }
  set_env("PS1", *pt);
  free(*pt);
}

variable_types:
pt
char **

variable_types: lap int


rdleft

decompiled_code:
__int64 __fastcall rdleft(__int64 a1, __int64 a2, __int64 a3)
{
int v5; // eax
unsigned __int8 v6; // cl
__int64 v7; // rdx
__int64 *v8; // r12
int v9; // edi
void *v11; // [rsp+0h] [rbp-28h] BYREF
int fd[8]; // [rsp+8h] [rbp-20h] BYREF

set_rd_prompt(&v11, 0);
v5 = open("/dev/tty", 2);
v6 = *(_BYTE *)(a3 + 88);
v7 = *(_QWORD *)(a1 + 16);
fd[0] = v5;
v8 = get_alls_isra_0(v5, 0LL, v7, v6);
close(fd[0]);
set_rd_prompt(&v11, 1);
if ( pipe(fd) == -1 )
fwrite("pipes error\n", 1uLL, 0xCuLL, stderr);
put_lines_isra_0(v8);
v9 = *(_DWORD *)(a2 + 4LL * *(int *)(a1 + 8));
if ( v9 >= 0 )
close(v9);
close(fd[1]);
*(_DWORD *)(a2 + 4LL * *(int *)(a1 + 8)) = fd[0];
return 1LL;
}

original_code:
unsigned char rdleft(t_redir *r, int w[3], t_info *info)
{
  char *pt;
  t_words *l;
  int p[2];
  set_rd_prompt(&pt, 0);
  p[0] = open("/dev/tty", 02);
  l = get_alls(p[0], ((void *)0), r->file, info);
  close(p[0]);
  set_rd_prompt(&pt, 1);
  if (pipe(p) == -1)
    fprintf(stderr, "pipes error\n");
  put_lines(l, p[1]);
  if (w[r->in] >= 0)
    close(w[r->in]);
  close(p[1]);
  w[r->in] = p[0];
  return (1);
}

canonical_original_code:
unsigned char rdleft(struct s_redir *r, int w[3], struct s_info *info)
{
  char *pt;
  struct s_words *l;
  int p[2];
  set_rd_prompt(&pt, 0);
  p[0] = open("/dev/tty", 02);
  l = get_alls(p[0], ((void *)0), r->file, info);
  close(p[0]);
  set_rd_prompt(&pt, 1);
  if (pipe(p) == -1)
    fprintf(stderr, "pipes error\n");
  put_lines(l, p[1]);
  if (w[r->in] >= 0)
    close(w[r->in]);
  close(p[1]);
  w[r->in] = p[0];
  return (1);
}

variable_types: struct s_redir { unsigned int redir; unsigned int type; int in; int out; char *file; struct s_redir *next; } *

variable_types:
w
int [3]

variable_types: struct s_info { struct s_history { char *str; struct s_history *prev; struct s_history *next; } *hist; struct s_options { char *clear; char *clean_end; char *reverse; char *forward; char *cursor; char *go2; char *invi_cursor; char *visi_cursor; char *up_cursor; char *down_cursor; } termcaps; unsigned char term_caps; int *wr; int st; int value; unsigned int son; struct s_alias { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } *alias; } *

variable_types:
pt
char *

variable_types:
p
int [2]


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *v1; // r12

v1 = malloc(a1);
if ( !v1 )
print_err("Sys fail\n");
return v1;
}

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

v1 = malloc(a1);
if ( !v1 )
print_err("Sys fail\n");
return v1;
}

original_code:
void *xmalloc(size_t t)
{
  void *r;
  if ((r = malloc(t)) == ((void *)0))
    {
      print_err("Sys fail\n");
      return (((void *)0));
    }
  return (r);
}

canonical_original_code:
void *xmalloc(unsigned long t)
{
  void *r;
  if ((r = malloc(t)) == ((void *)0))
    {
      print_err("Sys fail\n");
      return (((void *)0));
    }
  return (r);
}

variable_types:
t
unsigned long

variable_types:
r
void *


echappment

original_code:
t_get *echappment(char *s, t_get *link, char **bad_sintax, unsigned char freud)
{
  char *word;
  link->inter = 1;
  while (s[0] == '\\' && s[1])
    {
      word = link->word;
      s += 1;
      if ((link->word = my_strncat(word, s, subdiv(s + 1, bad_sintax)
       * (!((" \\\t\"'|;<>()`")[my_strilen(" \\\t\"'|;<>()`", s[1])] != 0)) + 1))
   == ((void *)0))
 return (nullify_link(link, (link->word) != ((void *)0), freud));
      if (!((" \\\t\"'|;<>()`")[my_strilen(" \\\t\"'|;<>()`", s[1])] != 0))
   *bad_sintax = ((void *)0);
      if (word)
 free(word);
      s += 1 + subdiv(s + 1, bad_sintax) * (!((" \\\t\"'|;<>()`")[my_strilen(" \\\t\"'|;<>()`", s[1])] != 0));
    }
  if (!s[1] && s[0] == '\\')
    {
      *bad_sintax = my_strdup("(sh): unexpected EOS after echappment character");
      return (nullify_link(link, (link->word) != ((void *)0), freud));
    }
  if (subdivide(s, link, bad_sintax) == ((void *)0))
    return (nullify_link(link, 1, freud));
  return (link);
}

canonical_original_code:
struct s_get *echappment(char *s, struct s_get *link, char **bad_sintax, unsigned char freud)
{
  char *word;
  link->inter = 1;
  while (s[0] == '\\' && s[1])
    {
      word = link->word;
      s += 1;
      if ((link->word = my_strncat(word, s, subdiv(s + 1, bad_sintax)
       * (!((" \\\t\"'|;<>()`")[my_strilen(" \\\t\"'|;<>()`", s[1])] != 0)) + 1))
   == ((void *)0))
 return (nullify_link(link, (link->word) != ((void *)0), freud));
      if (!((" \\\t\"'|;<>()`")[my_strilen(" \\\t\"'|;<>()`", s[1])] != 0))
   *bad_sintax = ((void *)0);
      if (word)
 free(word);
      s += 1 + subdiv(s + 1, bad_sintax) * (!((" \\\t\"'|;<>()`")[my_strilen(" \\\t\"'|;<>()`", s[1])] != 0));
    }
  if (!s[1] && s[0] == '\\')
    {
      *bad_sintax = my_strdup("(sh): unexpected EOS after echappment character");
      return (nullify_link(link, (link->word) != ((void *)0), freud));
    }
  if (subdivide(s, link, bad_sintax) == ((void *)0))
    return (nullify_link(link, 1, freud));
  return (link);
}

variable_types:
s
char *

variable_types:
link
struct s_get *

variable_types:
freud
unsigned char

variable_types:
word
char *

return_type: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *


decompiled_code:
__int64 __fastcall nullify_link(void *ptr, char a2, char a3)
{
if ( !a3 )
return 0LL;
if ( a2 )
free(*(void **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr, char a2, char a3)
{
if ( !a3 )
return 0LL;
if ( a2 )
free(*(void **)ptr);
free(ptr);
return 0LL;
}

original_code:
static void *nullify_link(t_get *link, unsigned char l, unsigned char f)
{
  if (!f)
    return (((void *)0));
  if (l)
    free(link->word);
  free(link);
  return (((void *)0));
}

canonical_original_code:
static void *nullify_link(struct s_get *link, unsigned char l, unsigned char f)
{
  if (!f)
    return (((void *)0));
  if (l)
    free(link->word);
  free(link);
  return (((void *)0));
}

variable_types: struct s_get { char *word; unsigned char inter; struct s_get *next; struct s_get *prev; } *

variable_types:
l
unsigned char

variable_types:
f
unsigned char