decompiled_code:
char __fastcall get_opt(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rdi
int v4; // edx
char result; // al

*a2 = a1;
if ( !a1 )
return 1;
v3 = *a1;
if ( !v3 )
return 1;
if ( !(unsigned int)my_strcmp(v3, "-i") )
{
env_i();
return get_opt(a1[1], a2);
}
if ( !*a1 )
return 1;
if ( (unsigned int)my_strcmp(*a1, "-u") )
{
if ( *a1 )
{
if ( (unsigned int)my_strcmp(*a1, "-s") )
{
if ( *a1 )
{
v4 = my_strcmp(*a1, "--help");
result = 1;
if ( !v4 )
result = print_help();
}
else
{
result = 1;
}
}
else
{
result = env_s((_QWORD *)a1[1]);
if ( result )
result = get_opt(*(_QWORD *)(*(_QWORD *)(a1[1] + 8LL) + 8LL), a2);
}
return result;
}
return 1;
}
result = env_u((_QWORD *)a1[1]);
if ( result )
result = get_opt(*(_QWORD *)(a1[1] + 8LL), a2);
return result;
}

canonical_decompiled_code:
char __fastcall func3(_QWORD *a1, _QWORD *a2)
{
__int64 v3; // rdi
int v4; // edx
char result; // al

*a2 = a1;
if ( !a1 )
return 1;
v3 = *a1;
if ( !v3 )
return 1;
if ( !(unsigned int)my_strcmp(v3, "-i") )
{
func0();
return func3(a1[1], a2);
}
if ( !*a1 )
return 1;
if ( (unsigned int)my_strcmp(*a1, "-u") )
{
if ( *a1 )
{
if ( (unsigned int)my_strcmp(*a1, "-s") )
{
if ( *a1 )
{
v4 = my_strcmp(*a1, "--help");
result = 1;
if ( !v4 )
result = print_help();
}
else
{
result = 1;
}
}
else
{
result = func2((_QWORD *)a1[1]);
if ( result )
result = func3(*(_QWORD *)(*(_QWORD *)(a1[1] + 8LL) + 8LL), a2);
}
return result;
}
return 1;
}
result = func1((_QWORD *)a1[1]);
if ( result )
result = func3(*(_QWORD *)(a1[1] + 8LL), a2);
return result;
}

original_code:
static unsigned char get_opt(t_words *opt, t_words **call)
{
  *call = opt;
  if (!opt)
    return (1);
  if (((opt->word && "-i") ? (!my_strcmp(opt->word, "-i")) : (0)))
    {
      env_i();
      return (get_opt(opt->next, call));
    }
  if (((opt->word && "-u") ? (!my_strcmp(opt->word, "-u")) : (0)))
    {
      if (env_u(opt->next) == 0)
 return (0);
      return (get_opt(opt->next->next, call));
    }
  if (((opt->word && "-s") ? (!my_strcmp(opt->word, "-s")) : (0)))
    {
      if (env_s(opt->next) == 0)
 return (0);
      return (get_opt(opt->next->next->next, call));
    }
  if (((opt->word && "--help") ? (!my_strcmp(opt->word, "--help")) : (0)))
    return (print_help());
  return (1);
}

canonical_original_code:
static unsigned char get_opt(struct s_words *opt, struct s_words **call)
{
  *call = opt;
  if (!opt)
    return (1);
  if (((opt->word && "-i") ? (!my_strcmp(opt->word, "-i")) : (0)))
    {
      env_i();
      return (get_opt(opt->next, call));
    }
  if (((opt->word && "-u") ? (!my_strcmp(opt->word, "-u")) : (0)))
    {
      if (env_u(opt->next) == 0)
 return (0);
      return (get_opt(opt->next->next, call));
    }
  if (((opt->word && "-s") ? (!my_strcmp(opt->word, "-s")) : (0)))
    {
      if (env_s(opt->next) == 0)
 return (0);
      return (get_opt(opt->next->next->next, call));
    }
  if (((opt->word && "--help") ? (!my_strcmp(opt->word, "--help")) : (0)))
    return (print_help());
  return (1);
}

variable_types:
call
struct s_words **


decompiled_code:
__int64 __fastcall built_env(__int64 a1)
{
char **v1; // rbx
unsigned int v2; // ebp
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v4[0] = a1;
v1 = (char **)env_copy();
if ( get_opt(*(_QWORD **)(a1 + 8), v4) )
{
v2 = exec_env(v4[0], v1);
destroy_env();
environ = v1;
}
else
{
destroy_env();
environ = v1;
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
char **v1; // rbx
unsigned int v2; // ebp
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v4[0] = a1;
v1 = (char **)env_copy();
if ( func3(*(_QWORD **)(a1 + 8), v4) )
{
v2 = exec_env(v4[0], v1);
destroy_env();
environ = v1;
}
else
{
destroy_env();
environ = v1;
v2 = 1;
}
return v2;
}

original_code:
int built_env(t_words *cmd, void *bool)
{
  int r;
  char **save;
  (void)bool;
  save = env_copy();
  if (get_opt(cmd->next, &cmd) == 0)
    {
      destroy_env();
      environ = save;
      return (1);
    }
  r = exec_env(cmd, save);
  destroy_env();
  environ = save;
  return (r);
}

canonical_original_code:
int built_env(struct s_words *cmd, void *bool)
{
  int r;
  char **save;
  (void)bool;
  save = env_copy();
  if (get_opt(cmd->next, &cmd) == 0)
    {
      destroy_env();
      environ = save;
      return (1);
    }
  r = exec_env(cmd, save);
  destroy_env();
  environ = save;
  return (r);
}

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

variable_types:
bool
void *

variable_types: r int

variable_types:
save
char **

return_type: int


decompiled_code:
__int64 __fastcall mod_var(_BYTE *a1, __int64 a2, void **a3, __int64 a4)
{
void *v6; // r12
__int64 v7; // rax
void *v8; // r13
__int64 v9; // rax
void *v10; // rbp
__int64 v11; // rax
__int64 result; // rax
__int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // rdx
__int64 v16; // rdx

v6 = (void *)my_strndup(*a3, a1 - (_BYTE *)*a3);
if ( v6 || (result = 0LL, *a3 == a1) )
{
v7 = my_strlen(a4);
v8 = (void *)my_strdup(&a1[v7 + 1]);
if ( v8 || (v13 = my_strlen(a4), v14 = my_strlen(&a1[v13 + 1]), result = 0LL, !v14) )
{
free(*a3);
v9 = my_strcat(v6, a2);
*a3 = (void *)v9;
if ( v9 || !my_strlen(0LL) || (v15 = my_strlen(a2), result = 0LL, !v15) )
{
free(v6);
v10 = *a3;
v11 = my_strcat(*a3, v8);
*a3 = (void *)v11;
if ( v11 || !my_strlen(0LL) || (v16 = my_strlen(v8), result = 0LL, !v16) )
{
free(v10);
free(v8);
result = 1LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2, void **a3, __int64 a4)
{
void *v6; // r12
__int64 v7; // rax
void *v8; // r13
__int64 v9; // rax
void *v10; // rbp
__int64 v11; // rax
__int64 result; // rax
__int64 v13; // rax
__int64 v14; // rdx
__int64 v15; // rdx
__int64 v16; // rdx

v6 = (void *)my_strndup(*a3, a1 - (_BYTE *)*a3);
if ( v6 || (result = 0LL, *a3 == a1) )
{
v7 = my_strlen(a4);
v8 = (void *)my_strdup(&a1[v7 + 1]);
if ( v8 || (v13 = my_strlen(a4), v14 = my_strlen(&a1[v13 + 1]), result = 0LL, !v14) )
{
free(*a3);
v9 = my_strcat(v6, a2);
*a3 = (void *)v9;
if ( v9 || !my_strlen(0LL) || (v15 = my_strlen(a2), result = 0LL, !v15) )
{
free(v6);
v10 = *a3;
v11 = my_strcat(*a3, v8);
*a3 = (void *)v11;
if ( v11 || !my_strlen(0LL) || (v16 = my_strlen(v8), result = 0LL, !v16) )
{
free(v10);
free(v8);
result = 1LL;
}
}
}
}
return result;
}

original_code:
static unsigned char mod_var(char *s, char *fill, char **mod, char *seek)
{
  char *modif[2];
  if ((modif[0] = my_strndup(*mod, s - *mod)) == ((void *)0) && (s != *mod))
    return (0);
  if ((modif[1] = my_strdup(s + my_strlen(seek) + 1)) == ((void *)0) &&
      my_strlen(s + my_strlen(seek) + 1))
    return (0);
  free(*mod);
  if ((*mod = my_strcat(modif[0], fill)) == ((void *)0) && my_strlen(*mod) &&
      my_strlen(fill))
    return (0);
  free(modif[0]);
  s = *mod;
  if ((*mod = my_strcat(*mod, modif[1])) == ((void *)0) && my_strlen(*mod) &&
      my_strlen(modif[1]))
    return (0);
  free(s);
  free(modif[1]);
  return (1);
}

variable_types:
s
char *

variable_types:
fill
char *

variable_types:
mod
char **

variable_types:
seek
char *

variable_types:
modif
char *[2]

return_type: unsigned char


original_code:
unsigned char grow_var(char *s, char **mod, size_t n, t_info *info)
{
  char *seek;
  char *fill;
  n += my_sstrlen(s, "~$");
  s += my_sstrlen(s, "~$");
  if (!s[0])
    return (1);
  if ((n && s[-1] == '\\'))
    return (short_it(mod, &s, n, info));
  if ((n && s[-1] == '\\')
      || (((("/!\\ \t(;|&[]")[my_strilen("/!\\ \t(;|&[]", s[1])] != 0) || !s[1]) && s[0] != '~'))
    return (grow_var(s + 1 + my_sstrlen(s + 1, "$~"), mod, n +
       1 + my_sstrlen(s + 1, "$~"), info));
  seek = ((void *)0);
  if (s[0] == '$' && s[1] != '?')
    seek = my_strndup(s + 1, my_sstrlen(s + 1, "$!/!\\ \"\t(;|&[]"));
  else if (s[1] == '?' && s[0] == '$')
    seek = my_strdup("?");
  fill = fill_it(s, seek, info);
  if (mod_var(s, fill, mod, seek) == 0)
    return (0);
  s = *mod + (n += my_strlen(fill));
  free(fill);
  free(seek);
  return (grow_var(s, mod, n, info));
}

canonical_original_code:
unsigned char grow_var(char *s, char **mod, unsigned long n, struct s_info *info)
{
  char *seek;
  char *fill;
  n += my_sstrlen(s, "~$");
  s += my_sstrlen(s, "~$");
  if (!s[0])
    return (1);
  if ((n && s[-1] == '\\'))
    return (short_it(mod, &s, n, info));
  if ((n && s[-1] == '\\')
      || (((("/!\\ \t(;|&[]")[my_strilen("/!\\ \t(;|&[]", s[1])] != 0) || !s[1]) && s[0] != '~'))
    return (grow_var(s + 1 + my_sstrlen(s + 1, "$~"), mod, n +
       1 + my_sstrlen(s + 1, "$~"), info));
  seek = ((void *)0);
  if (s[0] == '$' && s[1] != '?')
    seek = my_strndup(s + 1, my_sstrlen(s + 1, "$!/!\\ \"\t(;|&[]"));
  else if (s[1] == '?' && s[0] == '$')
    seek = my_strdup("?");
  fill = fill_it(s, seek, info);
  if (mod_var(s, fill, mod, seek) == 0)
    return (0);
  s = *mod + (n += my_strlen(fill));
  free(fill);
  free(seek);
  return (grow_var(s, mod, n, info));
}

variable_types:
n
unsigned long

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

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 short_it(char **mod, char **s, size_t n, t_info *info)
{
  char *tmp2;
  char *tmp1;
  tmp1 = my_strndup(*mod, n - 1);
  tmp2 = my_strcat(tmp1, *s);
  if (*mod)
    free(*mod);
  *mod = tmp2;
  if (tmp1)
    free(tmp1);
  if (*mod)
    *s = *mod + ((n) += my_sstrlen(*mod + n, "~$"));
  return (grow_var(*s, mod, n, info));
}

canonical_original_code:
static unsigned char short_it(char **mod, char **s, unsigned long n, struct s_info *info)
{
  char *tmp2;
  char *tmp1;
  tmp1 = my_strndup(*mod, n - 1);
  tmp2 = my_strcat(tmp1, *s);
  if (*mod)
    free(*mod);
  *mod = tmp2;
  if (tmp1)
    free(tmp1);
  if (*mod)
    *s = *mod + ((n) += my_sstrlen(*mod + n, "~$"));
  return (grow_var(*s, mod, n, info));
}

variable_types:
s
char **

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


decompiled_code:
void __fastcall remind_save_str(int a1, _QWORD *a2)
{
if ( a1 == 1 )
{
if ( save_0 )
free(save_0);
if ( *a2 )
save_0 = (void *)my_strdup();
else
save_0 = 0LL;
}
else if ( a1 == 2 )
{
*a2 = save_0;
}
}

canonical_decompiled_code:
void __fastcall func0(int a1, _QWORD *a2)
{
if ( a1 == 1 )
{
if ( save_0 )
free(save_0);
if ( *a2 )
save_0 = (void *)my_strdup();
else
save_0 = 0LL;
}
else if ( a1 == 2 )
{
*a2 = save_0;
}
}

original_code:
void remind_save_str(int opt, char **str)
{
  static char *save = ((void *)0);
  if (opt == 1)
    {
      if (save != ((void *)0))
 free(save);
      if (*str != ((void *)0))
 save = my_strdup(*str);
      else
 save = ((void *)0);
    }
  else if (opt == 2)
    (*str) = save;
}

variable_types: opt int

variable_types:
str
char **

variable_types:
save
char *

return_type: void


decompiled_code:
__int64 __fastcall del_after_cursor(__int64 a1, int *a2, _QWORD *a3)
{
__int64 result; // rax
int i; // [rsp+4h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v6[0] = *a3 + *a2;
remind_save_str(1, v6);
for ( i = *a2 + 1; ; i = *a2 + 1 )
{
result = (unsigned int)my_strlen(*a3) + 1;
if ( (_DWORD)result == i )
break;
del_letter_in_str(0LL, &i, a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int *a2, _QWORD *a3)
{
__int64 result; // rax
int i; // [rsp+4h] [rbp-24h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v6[0] = *a3 + *a2;
func0(1, v6);
for ( i = *a2 + 1; ; i = *a2 + 1 )
{
result = (unsigned int)my_strlen(*a3) + 1;
if ( (_DWORD)result == i )
break;
del_letter_in_str(0LL, &i, a3);
}
return result;
}

original_code:
void del_after_cursor(char value, int *reverse_case, char **cmd)
{
  char *tmp;
  int len;
  (void)value;
  tmp = (*cmd) + (*reverse_case);
  remind_save_str(1, &tmp);
  len = (*reverse_case) + 1;
  while (len != (int)my_strlen(*cmd) + 1)
    {
      del_letter_in_str(0, &len, cmd);
      len = (*reverse_case) + 1;
    }
}

variable_types: value char

variable_types:
cmd
char **

variable_types:
tmp
char *

variable_types: len int


decompiled_code:
void __fastcall del_before_cursor(__int64 a1, int *a2, _QWORD *a3)
{
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = (void *)my_strndup(*a3, *a2);
remind_save_str(1, &ptr);
free(ptr);
while ( *a2 > 0 )
del_letter_in_str(0LL, a2, a3);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int *a2, _QWORD *a3)
{
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = (void *)my_strndup(*a3, *a2);
func0(1, &ptr);
free(ptr);
while ( *a2 > 0 )
del_letter_in_str(0LL, a2, a3);
}

original_code:
void del_before_cursor(char value, int *reverse_case, char **cmd)
{
  char *tmp;
  (void)value;
  tmp = my_strndup(*cmd, *reverse_case);
  remind_save_str(1, &tmp);
  free(tmp);
  while (*reverse_case > 0)
    del_letter_in_str(0, reverse_case, cmd);
}


decompiled_code:
__int64 __fastcall copy_part_str(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 result; // rax
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v6[0] = 0LL;
remind_save_str(2, v6);
for ( i = 0LL; ; ++i )
{
result = my_strlen(v6[0]);
if ( (int)result <= (int)i )
break;
add_letter_in_str((unsigned int)*(char *)(v6[0] + i), a2, a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rbx
__int64 result; // rax
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v6[0] = 0LL;
func0(2, v6);
for ( i = 0LL; ; ++i )
{
result = my_strlen(v6[0]);
if ( (int)result <= (int)i )
break;
add_letter_in_str((unsigned int)*(char *)(v6[0] + i), a2, a3);
}
return result;
}

original_code:
void copy_part_str(char value, int *reverse_case, char **cmd)
{
  char *tmp;
  int len;
  (void)value;
  tmp = ((void *)0);
  remind_save_str(2, &tmp);
  len = -1;
  while (++len < (int)my_strlen(tmp))
    add_letter_in_str(tmp[len], reverse_case, cmd);
}


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

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

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

canonical_original_code:
static void rm_word(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; } *


fill

decompiled_code:
void __fastcall fill(_QWORD *a1, __int64 a2)
{
if ( a2 )
*a1 = a2;
else
*a1 = my_strdup(&unk_12B);
}

canonical_decompiled_code:
void __fastcall func2(_QWORD *a1, __int64 a2)
{
if ( a2 )
*a1 = a2;
else
*a1 = my_strdup(&unk_12B);
}

original_code:
static void fill(char **word, char *s)
{
  if (!s)
    *word = my_strdup("");
  else
    *word = s;
}

variable_types:
word
char **


comment

decompiled_code:
void **__fastcall comment(void *ptr, __int64 a2)
{
void **v2; // rbx
char *v3; // rdi
char v4; // al
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // r12

if ( !ptr )
return (void **)a2;
v2 = (void **)ptr;
v3 = *(char **)ptr;
v4 = *v3;
if ( (*v3 == 39 || v4 == 34) && !*((_BYTE *)v2 + 8) )
{
v6 = v4;
v7 = my_strilen(v3 + 1, (unsigned int)v4);
v8 = my_strndup((char *)*v2 + 1, v7);
if ( !v8 && my_strilen((char *)*v2 + 1, v6) )
{
nullify_next((__int64)v2[2]);
free(v2);
return 0LL;
}
free(*v2);
fill(v2, v8);
*((_BYTE *)v2 + 8) = 1;
}
if ( !comment(v2[2]) )
{
rm_word(v2);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
void **__fastcall func3(void *ptr, __int64 a2)
{
void **v2; // rbx
char *v3; // rdi
char v4; // al
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // r12

if ( !ptr )
return (void **)a2;
v2 = (void **)ptr;
v3 = *(char **)ptr;
v4 = *v3;
if ( (*v3 == 39 || v4 == 34) && !*((_BYTE *)v2 + 8) )
{
v6 = v4;
v7 = my_strilen(v3 + 1, (unsigned int)v4);
v8 = my_strndup((char *)*v2 + 1, v7);
if ( !v8 && my_strilen((char *)*v2 + 1, v6) )
{
func0((__int64)v2[2]);
free(v2);
return 0LL;
}
free(*v2);
func2(v2, v8);
*((_BYTE *)v2 + 8) = 1;
}
if ( !func3(v2[2]) )
{
func1(v2);
v2 = 0LL;
}
return v2;
}

original_code:
t_get *comment(t_get *w, t_get *prev)
{
  char quote;
  char *s;
  if (!w)
    return (prev);
  if ((((quote = (w->word)[0]) == '"' || (w->word)[0] == '\'') && !w->inter))
    {
      if ((s = my_strndup(w->word + 1,
     my_strilen(w->word + 1, quote))) == ((void *)0))
 if (my_strilen(w->word + 1, quote))
   {
     nullify_next(w->next);
     free(w);
     return (((void *)0));
   }
      free(w->word);
      fill(&(w->word), s);
      w->inter = 1;
    }
  if (comment(w->next, w) == ((void *)0))
    {
      rm_word(w);
      return (((void *)0));
    }
  return (w);
}

canonical_original_code:
struct s_get *comment(struct s_get *w, struct s_get *prev)
{
  char quote;
  char *s;
  if (!w)
    return (prev);
  if ((((quote = (w->word)[0]) == '"' || (w->word)[0] == '\'') && !w->inter))
    {
      if ((s = my_strndup(w->word + 1,
     my_strilen(w->word + 1, quote))) == ((void *)0))
 if (my_strilen(w->word + 1, quote))
   {
     nullify_next(w->next);
     free(w);
     return (((void *)0));
   }
      free(w->word);
      fill(&(w->word), s);
      w->inter = 1;
    }
  if (comment(w->next, w) == ((void *)0))
    {
      rm_word(w);
      return (((void *)0));
    }
  return (w);
}

variable_types:
w
struct s_get *

variable_types:
prev
struct s_get *

variable_types: quote char

variable_types:
s
char *

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


parents

decompiled_code:
__int64 __fastcall parents(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax
__int64 v7; // r13
_QWORD *v8; // rax
__int64 v9; // rax
_QWORD *v10; // [rsp+8h] [rbp-40h] BYREF
char v11[41]; // [rsp+1Fh] [rbp-29h] BYREF

v10 = (_QWORD *)a1;
result = lvl_parents(a2, a4);
if ( (_BYTE)result )
{
v7 = v10[2];
if ( v7 )
*(_QWORD *)(v7 + 24) = 0LL;
rm_words();
v8 = *(_QWORD **)(*(_QWORD *)a2 + 24LL);
v10 = v8;
if ( v8 && (!*v8 || (unsigned int)my_strcmp(*v8, "(")) )
{
v10[2] = 0LL;
v10 = *(_QWORD **)(*(_QWORD *)a2 + 16LL);
rm_words();
v9 = orga(v7, a4, v11, 1LL);
*(_QWORD *)(a3 + 24) = v9;
if ( v9 )
{
while ( v10 )
{
result = add_redir(v10, &v10, a4, a3);
if ( !(_BYTE)result )
return result;
}
result = 1LL;
}
else
{
result = check_sintax(a4, v11[0], (__int64)"(sh): syntax error near unexpected token: )");
}
}
else
{
result = check_sintax(a4, 1, (__int64)"(sh): syntax error near unexpected token: )");
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
__int64 result; // rax
__int64 v7; // r13
_QWORD *v8; // rax
__int64 v9; // rax
_QWORD *v10; // [rsp+8h] [rbp-40h] BYREF
char v11[41]; // [rsp+1Fh] [rbp-29h] BYREF

v10 = (_QWORD *)a1;
result = lvl_parents(a2, a4);
if ( (_BYTE)result )
{
v7 = v10[2];
if ( v7 )
*(_QWORD *)(v7 + 24) = 0LL;
rm_words();
v8 = *(_QWORD **)(*(_QWORD *)a2 + 24LL);
v10 = v8;
if ( v8 && (!*v8 || (unsigned int)my_strcmp(*v8, "(")) )
{
v10[2] = 0LL;
v10 = *(_QWORD **)(*(_QWORD *)a2 + 16LL);
rm_words();
v9 = orga(v7, a4, v11, 1LL);
*(_QWORD *)(a3 + 24) = v9;
if ( v9 )
{
while ( v10 )
{
result = add_redir(v10, &v10, a4, a3);
if ( !(_BYTE)result )
return result;
}
result = 1LL;
}
else
{
result = func0(a4, v11[0], (__int64)"(sh): syntax error near unexpected token: )");
}
}
else
{
result = func0(a4, 1, (__int64)"(sh): syntax error near unexpected token: )");
}
}
return result;
}

original_code:
static unsigned char parents(t_get *word, t_get **words,
   t_cmd *link, char **bad_sintax)
{
  unsigned char no_word;
  t_get *organize;
  if (lvl_parents(words, bad_sintax) == 0)
    return (0);
  if ((organize = word->next))
    word->next->prev = ((void *)0);
  rm_words(word);
  if ((word = (*words)->prev) == ((void *)0))
    return (check_sintax(bad_sintax, 1, "(sh): syntax error near unexpected token: )"));
  if (((word->word && "(") ? (!my_strcmp(word->word, "(")) : (0)))
    return (check_sintax(bad_sintax, 1, "(sh): syntax error near unexpected token: )"));
  word->next = ((void *)0);
  word = (*words)->next;
  rm_words(*words);
  if ((link->parents = orga(organize, bad_sintax, &no_word, 1)) == ((void *)0))
    return (check_sintax(bad_sintax, no_word, "(sh): syntax error near unexpected token: )"));
  while (word)
    if (!add_redir(word, &word, bad_sintax, link))
      return (0);
  return (1);
}

canonical_original_code:
static unsigned char parents(struct s_get *word, struct s_get **words, struct s_cmd *link, char **bad_sintax)
{
  unsigned char no_word;
  struct s_get *organize;
  if (lvl_parents(words, bad_sintax) == 0)
    return (0);
  if ((organize = word->next))
    word->next->prev = ((void *)0);
  rm_words(word);
  if ((word = (*words)->prev) == ((void *)0))
    return (check_sintax(bad_sintax, 1, "(sh): syntax error near unexpected token: )"));
  if (((word->word && "(") ? (!my_strcmp(word->word, "(")) : (0)))
    return (check_sintax(bad_sintax, 1, "(sh): syntax error near unexpected token: )"));
  word->next = ((void *)0);
  word = (*words)->next;
  rm_words(*words);
  if ((link->parents = orga(organize, bad_sintax, &no_word, 1)) == ((void *)0))
    return (check_sintax(bad_sintax, no_word, "(sh): syntax error near unexpected token: )"));
  while (word)
    if (!add_redir(word, &word, bad_sintax, link))
      return (0);
  return (1);
}

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

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

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

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


original_code:
unsigned char cmd_part(t_get *word, t_get **words, t_cmd *link, char **bad_sintax)
{
  word->prev = ((void *)0);
  link->type = 0b01;
  if (((word->word && "(") ? (!my_strcmp(word->word, "(")) : (0)))
    return (parents(word, words, link, bad_sintax));
  link->type = 0b100;
  link->redir = ((void *)0);
  if ((link->params = list_cmd(word, link, ((void *)0), bad_sintax)) == ((void *)0))
    if (link->type != 0b100 || *bad_sintax)
      return (0);
  return (1);
}

canonical_original_code:
unsigned char cmd_part(struct s_get *word, struct s_get **words, struct s_cmd *link, char **bad_sintax)
{
  word->prev = ((void *)0);
  link->type = 0b01;
  if (((word->word && "(") ? (!my_strcmp(word->word, "(")) : (0)))
    return (parents(word, words, link, bad_sintax));
  link->type = 0b100;
  link->redir = ((void *)0);
  if ((link->params = list_cmd(word, link, ((void *)0), bad_sintax)) == ((void *)0))
    if (link->type != 0b100 || *bad_sintax)
      return (0);
  return (1);
}

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

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

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


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

result = 1LL;
if ( a1 )
{
my_putstr("alias ", 1LL);
my_putstr(*a1, 1LL);
my_putstr("=\"", 1LL);
my_putstr(a1[1], 1LL);
my_putstr("\"\n", 1LL);
result = 0LL;
}
return result;
}

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

result = 1LL;
if ( a1 )
{
my_putstr("alias ", 1LL);
my_putstr(*a1, 1LL);
my_putstr("=\"", 1LL);
my_putstr(a1[1], 1LL);
my_putstr("\"\n", 1LL);
result = 0LL;
}
return result;
}

original_code:
static int p_one(t_alias *alias)
{
  if (!alias)
    return (1);
  my_putstr("alias ", 1);
  my_putstr(alias->name, 1);
  my_putstr("=\"", 1);
  my_putstr(alias->fill, 1);
  my_putstr("\"\n", 1);
  return (0);
}

canonical_original_code:
static int p_one(struct s_alias *alias)
{
  if (!alias)
    return (1);
  my_putstr("alias ", 1);
  my_putstr(alias->name, 1);
  my_putstr("=\"", 1);
  my_putstr(alias->fill, 1);
  my_putstr("\"\n", 1);
  return (0);
}

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


decompiled_code:
__int64 __fastcall valid_str(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = my_sstrlen(a1, " \\\t\"'|;<>()`");
result = 1LL;
if ( *(_BYTE *)(a1 + v1) )
{
print_err("(sh): alias error: invalid character in sentence: ");
print_err(a1);
print_err("\n");
result = 0LL;
}
return result;
}

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

v1 = my_sstrlen(a1, " \\\t\"'|;<>()`");
result = 1LL;
if ( *(_BYTE *)(a1 + v1) )
{
print_err("(sh): alias error: invalid character in sentence: ");
print_err(a1);
print_err("\n");
result = 0LL;
}
return result;
}

original_code:
static unsigned char valid_str(char *s)
{
  if (s[my_sstrlen(s, " \\\t\"'|;<>()`")] != 0)
    {
      print_err("(sh): alias error: invalid character in sentence: ");
      print_err(s);
      print_err("\n");
      return (0);
    }
  return (1);
}


decompiled_code:
__int64 __fastcall get_n(__int64 *a1, _QWORD *a2, __int64 a3)
{
_QWORD *v3; // rbx
_QWORD *v5; // r12
char v6; // dl
__int64 result; // rax
__int64 v8; // rax

v3 = a2;
if ( a2 )
{
v5 = 0LL;
do
{
if ( *a1 && *v3 && !(unsigned int)my_strcmp() )
v5 = v3;
v3 = (_QWORD *)v3[2];
}
while ( v3 );
}
else
{
v5 = 0LL;
}
if ( !a1[1] )
return p_one(v5);
v6 = valid_str(*a1);
result = 1LL;
if ( v6 )
{
if ( v5 )
{
free((void *)v5[1]);
v8 = my_strdup(*(_QWORD *)a1[1]);
v5[1] = v8;
result = v8 == 0;
}
else
{
result = mod_alias(*a1, *(_QWORD *)a1[1], a3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, _QWORD *a2, __int64 a3)
{
_QWORD *v3; // rbx
_QWORD *v5; // r12
char v6; // dl
__int64 result; // rax
__int64 v8; // rax

v3 = a2;
if ( a2 )
{
v5 = 0LL;
do
{
if ( *a1 && *v3 && !(unsigned int)my_strcmp() )
v5 = v3;
v3 = (_QWORD *)v3[2];
}
while ( v3 );
}
else
{
v5 = 0LL;
}
if ( !a1[1] )
return func0(v5);
v6 = func2(*a1);
result = 1LL;
if ( v6 )
{
if ( v5 )
{
free((void *)v5[1]);
v8 = my_strdup(*(_QWORD *)a1[1]);
v5[1] = v8;
result = v8 == 0;
}
else
{
result = mod_alias(*a1, *(_QWORD *)a1[1], a3);
}
}
return result;
}

original_code:
static int get_n(t_words *cmd, t_alias *alias, t_alias **mod)
{
  t_alias *pnew;
  pnew = ((void *)0);
  while (alias)
    {
      if (((cmd->word && alias->name) ? (!my_strcmp(cmd->word, alias->name)) : (0)))
 pnew = alias;
      alias = alias->next;
    }
  if (!cmd->next)
    return (p_one(pnew));
  if (valid_str(cmd->word) == 0)
    return (1);
  if (!pnew)
    return (mod_alias(cmd->word, cmd->next->word, mod));
  free(pnew->fill);
  if ((pnew->fill = my_strdup(cmd->next->word)) == ((void *)0))
    return (1);
  return (0);
}

canonical_original_code:
static int get_n(struct s_words *cmd, struct s_alias *alias, struct s_alias **mod)
{
  struct s_alias *pnew;
  pnew = ((void *)0);
  while (alias)
    {
      if (((cmd->word && alias->name) ? (!my_strcmp(cmd->word, alias->name)) : (0)))
 pnew = alias;
      alias = alias->next;
    }
  if (!cmd->next)
    return (p_one(pnew));
  if (valid_str(cmd->word) == 0)
    return (1);
  if (!pnew)
    return (mod_alias(cmd->word, cmd->next->word, mod));
  free(pnew->fill);
  if ((pnew->fill = my_strdup(cmd->next->word)) == ((void *)0))
    return (1);
  return (0);
}

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

variable_types:
mod
struct s_alias **


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

v2 = *(__int64 **)(a1 + 8);
if ( v2 )
result = get_n(v2, *a2, (__int64)a2);
else
result = print(*a2);
return result;
}

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

v2 = *(__int64 **)(a1 + 8);
if ( v2 )
result = func3(v2, *a2, (__int64)a2);
else
result = func1(*a2);
return result;
}

original_code:
int built_alias(t_words *cmd, void *alias)
{
  if (!cmd->next)
    return (print(*(t_alias**)alias));
  return (get_n(cmd->next, *(t_alias**)alias, alias));
}

canonical_original_code:
int built_alias(struct s_words *cmd, void *alias)
{
  if (!cmd->next)
    return (print(*(struct s_alias **)alias));
  return (get_n(cmd->next, *(struct s_alias **)alias, alias));
}

variable_types:
alias
void *


print

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

result = 0LL;
if ( a1 )
{
p_one(a1);
result = print(a1[2]);
}
return result;
}

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

result = 0LL;
if ( a1 )
{
func0(a1);
result = func1(a1[2]);
}
return result;
}

original_code:
static int print(t_alias *alias)
{
  if (!alias)
    return (0);
  p_one(alias);
  return (print(alias->next));
}

canonical_original_code:
static int print(struct s_alias *alias)
{
  if (!alias)
    return (0);
  p_one(alias);
  return (print(alias->next));
}


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

if ( !a1 )
return get_env("HOME");
v2 = *a1;
if ( v2 && !(unsigned int)my_strcmp(v2, "-") )
result = get_env("OLD_PWD");
else
result = *a1;
return result;
}

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

if ( !a1 )
return get_env("HOME");
v2 = *a1;
if ( v2 && !(unsigned int)my_strcmp(v2, "-") )
result = get_env("OLD_PWD");
else
result = *a1;
return result;
}

original_code:
static char *new_pwd(t_words *wpwd)
{
  if (!wpwd)
    return (get_env("HOME"));
  if (((wpwd->word && "-") ? (!my_strcmp(wpwd->word, "-")) : (0)))
    return (get_env("OLD_PWD"));
  return (wpwd->word);
}

canonical_original_code:
static char *new_pwd(struct s_words *wpwd)
{
  if (!wpwd)
    return (get_env("HOME"));
  if (((wpwd->word && "-") ? (!my_strcmp(wpwd->word, "-")) : (0)))
    return (get_env("OLD_PWD"));
  return (wpwd->word);
}

return_type: char *


decompiled_code:
__int64 __fastcall old_new(void **a1, __int64 a2)
{
char *v2; // rax
char *v3; // rbx

v2 = getcwd(0LL, 0LL);
if ( !v2 )
return 0LL;
v3 = v2;
if ( *a1 )
free(*a1);
*a1 = (void *)my_stricat(a2, v3, 61LL);
free(v3);
return 1LL;
}

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

v2 = getcwd(0LL, 0LL);
if ( !v2 )
return 0LL;
v3 = v2;
if ( *a1 )
free(*a1);
*a1 = (void *)my_stricat(a2, v3, 61LL);
free(v3);
return 1LL;
}

original_code:
static int old_new(char **def, char *env)
{
  char *apwd;
  if ((apwd = getcwd(((void *)0), 0)) == ((void *)0))
    return (0);
  if (*def)
    free(*def);
  *def = my_stricat(env, apwd, '=');
  free(apwd);
  return (1);
}

variable_types:
def
char **

variable_types:
env
char *

variable_types:
apwd
char *


decompiled_code:
__int64 __fastcall set_old(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12
__int64 v3; // rax
char **v5; // r12
__int64 v6; // rbx
char **v7; // rax
__int64 v8; // rbx
char *v9; // rax

if ( !environ )
{
v1 = 0LL;
goto LABEL_9;
}
if ( !*environ )
{
v1 = 0LL;
LABEL_9:
v5 = environ;
v6 = 8 * v1 + 16;
v7 = (char **)xmalloc(v6);
environ = v7;
if ( !v7 )
return 0LL;
*(char **)((char *)v7 + v6 - 16) = 0LL;
*(char **)((char *)environ + v6 - 8) = 0LL;
v8 = 0LL;
if ( v5 )
{
v9 = *v5;
if ( *v5 )
{
do
{
environ[v8++] = v9;
v9 = v5[v8];
}
while ( v9 );
}
else
{
v8 = 0LL;
}
}
free(v5);
return old_new((void **)&environ[v8], a1);
}
v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( a1 )
{
v3 = my_strlen(a1);
if ( !(unsigned int)my_strncmp(a1, environ[v1], v3) )
return old_new((void **)&environ[v2], a1);
}
++v1;
if ( !environ[v2 + 1] )
goto LABEL_9;
}
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // r12
__int64 v3; // rax
char **v5; // r12
__int64 v6; // rbx
char **v7; // rax
__int64 v8; // rbx
char *v9; // rax

if ( !environ )
{
v1 = 0LL;
goto LABEL_9;
}
if ( !*environ )
{
v1 = 0LL;
LABEL_9:
v5 = environ;
v6 = 8 * v1 + 16;
v7 = (char **)xmalloc(v6);
environ = v7;
if ( !v7 )
return 0LL;
*(char **)((char *)v7 + v6 - 16) = 0LL;
*(char **)((char *)environ + v6 - 8) = 0LL;
v8 = 0LL;
if ( v5 )
{
v9 = *v5;
if ( *v5 )
{
do
{
environ[v8++] = v9;
v9 = v5[v8];
}
while ( v9 );
}
else
{
v8 = 0LL;
}
}
free(v5);
return func1((void **)&environ[v8], a1);
}
v1 = 0LL;
while ( 1 )
{
v2 = v1;
if ( a1 )
{
v3 = my_strlen(a1);
if ( !(unsigned int)my_strncmp(a1, environ[v1], v3) )
return func1((void **)&environ[v2], a1);
}
++v1;
if ( !environ[v2 + 1] )
goto LABEL_9;
}
}

original_code:
static unsigned char set_old(char *env)
{
  char **tab;
  size_t i;
  i = 0;
  if (environ)
    while (environ[i])
      {
 if ((((env) && (environ[i])) ? (!my_strncmp((env), (environ[i]), my_strlen(env))) : (0)))
   return (old_new(&(environ[i]), env));
 i++;
      }
  tab = environ;
  if ((environ = xmalloc(sizeof(char*) * (i + 2))) == ((void *)0))
    return (0);
  environ[i] = ((void *)0);
  i = (unsigned long)(environ[i + 1] = ((void *)0));
  if (tab)
    while (tab[i])
      {
 environ[i] = tab[i];
 i++;
      }
  free(tab);
  return (old_new(&(environ[i]), env));
}

canonical_original_code:
static unsigned char set_old(char *env)
{
  char **tab;
  unsigned long i;
  i = 0;
  if (environ)
    while (environ[i])
      {
 if ((((env) && (environ[i])) ? (!my_strncmp((env), (environ[i]), my_strlen(env))) : (0)))
   return (old_new(&(environ[i]), env));
 i++;
      }
  tab = environ;
  if ((environ = xmalloc(sizeof(char *) * (i + 2))) == ((void *)0))
    return (0);
  environ[i] = ((void *)0);
  i = (unsigned long)(environ[i + 1] = ((void *)0));
  if (tab)
    while (tab[i])
      {
 environ[i] = tab[i];
 i++;
      }
  free(tab);
  return (old_new(&(environ[i]), env));
}

variable_types:
tab
char **

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall set_new(void *ptr)
{
__int64 result; // rax

if ( chdir((const char *)ptr) == -1 )
{
print_err("(sh): no such directory: ");
print_err(ptr);
print_err("\n");
result = 0LL;
}
else
{
free(ptr);
result = set_old((__int64)"PWD");
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr)
{
__int64 result; // rax

if ( chdir((const char *)ptr) == -1 )
{
print_err("(sh): no such directory: ");
print_err(ptr);
print_err("\n");
result = 0LL;
}
else
{
free(ptr);
result = func2((__int64)"PWD");
}
return result;
}

original_code:
static unsigned char set_new(char *new)
{
  if (chdir(new) == -1)
    {
      print_err("(sh): no such directory: ");
      print_err(new);
      print_err("\n");
      return (0);
    }
  free(new);
  return (set_old("PWD"));
}

variable_types:
new
char *


decompiled_code:
_BOOL8 __fastcall built_cd(__int64 a1)
{
__int64 v1; // rax
void *v2; // rbx
char v3; // dl
_BOOL8 result; // rax

v1 = new_pwd(*(__int64 **)(a1 + 8));
if ( v1 )
{
v2 = (void *)my_strdup(v1);
v3 = set_old((__int64)"OLD_PWD");
result = 1LL;
if ( v3 )
result = (unsigned __int8)set_new(v2) == 0;
}
else
{
print_err("(sh): no such directory: ");
if ( *(_QWORD *)(a1 + 8) )
print_err("prev");
else
print_err("HOME");
print_err("\n");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
__int64 v1; // rax
void *v2; // rbx
char v3; // dl
_BOOL8 result; // rax

v1 = func0(*(__int64 **)(a1 + 8));
if ( v1 )
{
v2 = (void *)my_strdup(v1);
v3 = func2((__int64)"OLD_PWD");
result = 1LL;
if ( v3 )
result = (unsigned __int8)func3(v2) == 0;
}
else
{
print_err("(sh): no such directory: ");
if ( *(_QWORD *)(a1 + 8) )
print_err("prev");
else
print_err("HOME");
print_err("\n");
result = 1LL;
}
return result;
}

original_code:
int built_cd(t_words *cmd, void *null)
{
  char *new;
  (void)null;
  if ((new = new_pwd(cmd->next)) == ((void *)0))
    {
      print_err("(sh): no such directory: ");
      if (!cmd->next)
 print_err("HOME");
      else
 print_err("prev");
      print_err("\n");
      return (1);
    }
  new = my_strdup(new);
  if (set_old("OLD_PWD") == 0)
    return (1);
  if (set_new(new) == 0)
    return (1);
  return (0);
}

canonical_original_code:
int built_cd(struct s_words *cmd, void *null)
{
  char *new;
  (void)null;
  if ((new = new_pwd(cmd->next)) == ((void *)0))
    {
      print_err("(sh): no such directory: ");
      if (!cmd->next)
 print_err("HOME");
      else
 print_err("prev");
      print_err("\n");
      return (1);
    }
  new = my_strdup(new);
  if (set_old("OLD_PWD") == 0)
    return (1);
  if (set_new(new) == 0)
    return (1);
  return (0);
}


original_code:
static void to_fd(int w[3], unsigned char in)
{
  if (in)
    return ;
  w[0] = dup(0);
  w[1] = dup(1);
  w[2] = dup(2);
}

variable_types:
w
int [3]

variable_types:
in
unsigned char


decompiled_code:
int __fastcall fd_to(int *a1, char a2)
{
int result; // eax

if ( !a2 )
{
dup2(a1[1], 1);
close(a1[1]);
dup2(*a1, 0);
close(*a1);
dup2(a1[2], 1);
result = close(a1[2]);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(int *a1, char a2)
{
int result; // eax

if ( !a2 )
{
dup2(a1[1], 1);
close(a1[1]);
dup2(*a1, 0);
close(*a1);
dup2(a1[2], 1);
result = close(a1[2]);
}
return result;
}

original_code:
static void fd_to(int w[3], unsigned char in)
{
  if (in)
    return ;
  dup2(w[1], 1);
  close(w[1]);
  dup2(w[0], 0);
  close(w[0]);
  dup2(w[2], 1);
  close(w[2]);
}


original_code:
static unsigned char and_or(t_exec *e, t_info *info, unsigned char in)
{
  int p[3];
  int w[3];
  if (!e)
    return (1);
  to_fd(w, in);
  p[0] = 0;
  p[1] = 1;
  p[2] = 2;
  if (exec_pipes(e->pipes, info, 0, (info->wr = p)) == 0)
    {
      while (waitpid(-1, ((void *)0), 1) >= 0);
      return (0);
    }
  fd_to(w, in);
  if (e->type == 0b001 && info->st == 1)
    return (and_or(e->next, info, in));
  else if (e->type == 0b001 && info->st == 0)
    return (and_or(two(e), info, in));
  if (e->type == 0b010 && info->st == 0)
    return (and_or(e->next, info, in));
  else if (e->type == 0b010 && info->st == 1)
    return (and_or(two(e), info, in));
  return (1);
}

canonical_original_code:
static unsigned char and_or(struct s_exec *e, struct s_info *info, unsigned char in)
{
  int p[3];
  int w[3];
  if (!e)
    return (1);
  to_fd(w, in);
  p[0] = 0;
  p[1] = 1;
  p[2] = 2;
  if (exec_pipes(e->pipes, info, 0, (info->wr = p)) == 0)
    {
      while (waitpid(-1, ((void *)0), 1) >= 0);
      return (0);
    }
  fd_to(w, in);
  if (e->type == 0b001 && info->st == 1)
    return (and_or(e->next, info, in));
  else if (e->type == 0b001 && info->st == 0)
    return (and_or(two(e), info, in));
  if (e->type == 0b010 && info->st == 0)
    return (and_or(e->next, info, in));
  else if (e->type == 0b010 && info->st == 1)
    return (and_or(two(e), info, in));
  return (1);
}

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

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:
p
int [3]


decompiled_code:
__int64 __fastcall pre_exec(__int64 a1, __int64 a2, unsigned __int8 a3)
{
__int64 result; // rax
unsigned int v4; // ebx
__int64 v5; // r13

result = 1LL;
if ( a1 )
{
v4 = a3;
result = and_or(*(_QWORD *)(a1 + 16), a2, a3);
if ( (_BYTE)result )
{
v5 = *(_QWORD *)(a1 + 8);
nullify_jobs(a1, 0LL);
result = pre_exec(v5, a2, v4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned __int8 a3)
{
__int64 result; // rax
unsigned int v4; // ebx
__int64 v5; // r13

result = 1LL;
if ( a1 )
{
v4 = a3;
result = func3(*(_QWORD *)(a1 + 16), a2, a3);
if ( (_BYTE)result )
{
v5 = *(_QWORD *)(a1 + 8);
nullify_jobs(a1, 0LL);
result = func4(v5, a2, v4);
}
}
return result;
}

original_code:
unsigned char pre_exec(t_jobs *j, t_info *info, unsigned char in)
{
  t_jobs *next;
  if (!j)
    return (1);
  if (and_or(j->exec, info, in) == 0)
    return (0);
  next = j->next;
  nullify_jobs(j, 0);
  return (pre_exec(next, info, in));
}

canonical_original_code:
unsigned char pre_exec(struct s_jobs *j, struct s_info *info, unsigned char in)
{
  struct s_jobs *next;
  if (!j)
    return (1);
  if (and_or(j->exec, info, in) == 0)
    return (0);
  next = j->next;
  nullify_jobs(j, 0);
  return (pre_exec(next, info, in));
}

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


decompiled_code:
__int64 __fastcall attribute_options(char **a1)
{
*a1 = tgetstr("cl", 0LL);
a1[1] = tgetstr("cd", 0LL);
a1[2] = tgetstr("mr", 0LL);
a1[3] = tgetstr("me", 0LL);
a1[4] = tgetstr("cm", 0LL);
a1[6] = tgetstr("vi", 0LL);
a1[7] = tgetstr("ve", 0LL);
a1[8] = tgetstr("up", 0LL);
a1[9] = tgetstr("do", 0LL);
return retain_struct_options(1LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1)
{
*a1 = tgetstr("cl", 0LL);
a1[1] = tgetstr("cd", 0LL);
a1[2] = tgetstr("mr", 0LL);
a1[3] = tgetstr("me", 0LL);
a1[4] = tgetstr("cm", 0LL);
a1[6] = tgetstr("vi", 0LL);
a1[7] = tgetstr("ve", 0LL);
a1[8] = tgetstr("up", 0LL);
a1[9] = tgetstr("do", 0LL);
return retain_struct_options(1LL, a1);
}

original_code:
void attribute_options(t_options *options)
{
  options->clear = tgetstr("cl", ((void *)0));
  options->clean_end = tgetstr("cd", ((void *)0));
  options->reverse = tgetstr("mr", ((void *)0));
  options->forward = tgetstr("me", ((void *)0));
  options->cursor = tgetstr("cm", ((void *)0));
  options->invi_cursor = tgetstr("vi", ((void *)0));
  options->visi_cursor = tgetstr("ve", ((void *)0));
  options->up_cursor = tgetstr("up", ((void *)0));
  options->down_cursor = tgetstr("do", ((void *)0));
  retain_struct_options(1, options);
}

canonical_original_code:
void attribute_options(struct s_options *options)
{
  options->clear = tgetstr("cl", ((void *)0));
  options->clean_end = tgetstr("cd", ((void *)0));
  options->reverse = tgetstr("mr", ((void *)0));
  options->forward = tgetstr("me", ((void *)0));
  options->cursor = tgetstr("cm", ((void *)0));
  options->invi_cursor = tgetstr("vi", ((void *)0));
  options->visi_cursor = tgetstr("ve", ((void *)0));
  options->up_cursor = tgetstr("up", ((void *)0));
  options->down_cursor = tgetstr("do", ((void *)0));
  retain_struct_options(1, options);
}

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:
_BOOL8 __fastcall modify_terminal(struct termios *termios_p)
{
termios_p->c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, termios_p) == -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(struct termios *termios_p)
{
termios_p->c_lflag &= 0xFFFFFFF5;
return tcsetattr(0, 0, termios_p) == -1;
}

original_code:
int modify_terminal(struct termios *opt)
{
  opt->c_lflag &= ~0000002;
  opt->c_lflag &= ~0000010;
  if (tcsetattr(0, 0, opt) == -1)
    return (1);
  return (0);
}

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:
int __fastcall init_termios(struct termios *termios_p, struct termios *a2)
{
int result; // eax

result = tcgetattr(0, termios_p);
if ( result != -1 )
{
result = tcgetattr(0, a2);
if ( result != -1 )
result = -(modify_terminal(termios_p) == -1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(struct termios *termios_p, struct termios *a2)
{
int result; // eax

result = tcgetattr(0, termios_p);
if ( result != -1 )
{
result = tcgetattr(0, a2);
if ( result != -1 )
result = -(func1(termios_p) == -1);
}
return result;
}

original_code:
int init_termios(struct termios *set, struct termios *unset)
{
  if (tcgetattr(0, set) == -1 ||
      tcgetattr(0, unset) == -1)
    return (-1);
  if (modify_terminal(set) == -1)
    return (-1);
  return (0);
}

variable_types:
unset
struct termios *

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


decompiled_code:
__int64 __fastcall unset_termios(struct termios *termios_p)
{
tcsetattr(0, 0, termios_p);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(struct termios *termios_p)
{
tcsetattr(0, 0, termios_p);
return 0LL;
}

original_code:
char *unset_termios(struct termios *unset)
{
  tcsetattr(0, 0, unset);
  return (((void *)0));
}


decompiled_code:
__int64 load_tgets_funcs()
{
const char *v0; // rax
__int64 result; // rax

if ( tgetent(0LL, "xterm") == 1 || (v0 = (const char *)get_env("TERM"), tgetent(0LL, v0) == 1) )
{
set_env("TERM", "xterm");
result = 0LL;
}
else
{
my_putstr("Fail on tgetent", 2LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
const char *v0; // rax
__int64 result; // rax

if ( tgetent(0LL, "xterm") == 1 || (v0 = (const char *)get_env("TERM"), tgetent(0LL, v0) == 1) )
{
set_env("TERM", "xterm");
result = 0LL;
}
else
{
my_putstr("Fail on tgetent", 2LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int load_tgets_funcs()
{
  if (tgetent(((void *)0), "xterm") != 1)
    {
      if (tgetent(((void *)0), get_env("TERM")) != 1)
 {
   my_putstr("Fail on tgetent", 2);
   return (-1);
 }
    }
  set_env("TERM", "xterm");
  return (0);
}


decompiled_code:
__int64 __fastcall delete_first_word_met(__int64 a1, int *a2, _QWORD *a3)
{
_BYTE *v5; // rdx
int v6; // esi
int v7; // edi
int v8; // ebx
unsigned __int8 *v9; // rax
__int64 result; // rax
int v11; // edx
int v12; // [rsp+4h] [rbp-24h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v6 = my_strlen(*a3) - 1;
v7 = *a2;
v8 = *a2;
if ( v6 > *a2 )
{
v5 = (_BYTE *)(*a3 + v7);
while ( *v5 == 32 || *v5 == 9 )
{
++v8;
++v5;
if ( v6 == v8 )
goto LABEL_14;
}
if ( v6 > v8 )
{
v9 = (unsigned __int8 *)(v8 + *a3);
while ( 1 )
{
v5 = (_BYTE *)*v9;
if ( (_BYTE)v5 == 32 || (_BYTE)v5 == 9 )
break;
++v8;
++v9;
if ( v6 == v8 )
goto LABEL_14;
}
}
}
if ( v6 != v8 )
--v8;
LABEL_14:
v12 = v7 + 1;
ptr = (void *)my_strndup(*a3 + v7 + 1 - 1LL, v8 + 2 - (v7 + 1), v5);
remind_save_str(1LL, &ptr);
free(ptr);
result = (unsigned int)(v8 + 1);
if ( (int)result >= v7 + 1 )
{
do
{
del_letter_in_str(0LL, &v12, a3);
result = (unsigned int)(*a2 + 1);
v12 = result;
v11 = v8--;
}
while ( (int)result <= v11 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2, _QWORD *a3)
{
_BYTE *v5; // rdx
int v6; // esi
int v7; // edi
int v8; // ebx
unsigned __int8 *v9; // rax
__int64 result; // rax
int v11; // edx
int v12; // [rsp+4h] [rbp-24h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v6 = my_strlen(*a3) - 1;
v7 = *a2;
v8 = *a2;
if ( v6 > *a2 )
{
v5 = (_BYTE *)(*a3 + v7);
while ( *v5 == 32 || *v5 == 9 )
{
++v8;
++v5;
if ( v6 == v8 )
goto LABEL_14;
}
if ( v6 > v8 )
{
v9 = (unsigned __int8 *)(v8 + *a3);
while ( 1 )
{
v5 = (_BYTE *)*v9;
if ( (_BYTE)v5 == 32 || (_BYTE)v5 == 9 )
break;
++v8;
++v9;
if ( v6 == v8 )
goto LABEL_14;
}
}
}
if ( v6 != v8 )
--v8;
LABEL_14:
v12 = v7 + 1;
ptr = (void *)my_strndup(*a3 + v7 + 1 - 1LL, v8 + 2 - (v7 + 1), v5);
remind_save_str(1LL, &ptr);
free(ptr);
result = (unsigned int)(v8 + 1);
if ( (int)result >= v7 + 1 )
{
do
{
del_letter_in_str(0LL, &v12, a3);
result = (unsigned int)(*a2 + 1);
v12 = result;
v11 = v8--;
}
while ( (int)result <= v11 );
}
return result;
}

original_code:
void delete_first_word_met(char value, int *rev_c, char **cmd)
{
  char *save;
  int i;
  int save_rev_c;
  int len;
  (void)value;
  len = my_strlen(*cmd) - 1;
  i = (*rev_c);
  while (i < len && ((*cmd)[i] == ' ' || (*cmd)[i] == '\t'))
    i++;
  while (i < len && ((*cmd)[i] != ' ' && (*cmd)[i] != '\t'))
    i++;
  if (i != len)
    i--;
  save_rev_c = (*rev_c) + 1;
  save = my_strndup((*cmd) + save_rev_c - 1, i + 2 - save_rev_c);
  remind_save_str(1, &save);
  free(save);
  while (save_rev_c < i + 2)
    {
      del_letter_in_str(0, &save_rev_c, cmd);
      save_rev_c = (*rev_c) + 1;
      i--;
    }
}

variable_types: value char

variable_types:
cmd
char **

variable_types:
save
char *

variable_types: i int

variable_types: len int


decompiled_code:
__int64 __fastcall move_reverse_case(char a1, _DWORD *a2, _QWORD *a3)
{
int v4; // er14
__int64 result; // rax
int i; // edx
char v7[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v8[15]; // [rsp+10h] [rbp-78h] BYREF

fill_tab(v7);
v4 = my_strlen(*a3);
fill_fct_ptr(v8);
result = (__int64)v7;
for ( i = 0; i != 8; ++i )
{
if ( *(_BYTE *)result == a1 )
{
if ( a1 != 51 )
return ((__int64 (__fastcall *)(_QWORD, _DWORD *, _QWORD *))v8[i])((unsigned int)a1, a2, a3);
++*a2;
return ((__int64 (__fastcall *)(__int64, _DWORD *, _QWORD *))v8[i])(51LL, a2, a3);
}
++result;
}
if ( (a1 == 68 || a1 == 2) && (result = (unsigned int)*a2, (int)result > 0) )
{
result = (unsigned int)(result - 1);
*a2 = result;
}
else if ( a1 == 67 || a1 == 6 )
{
result = (unsigned int)*a2;
if ( (int)result < v4 )
{
result = (unsigned int)(result + 1);
*a2 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, _DWORD *a2, _QWORD *a3)
{
int v4; // er14
__int64 result; // rax
int i; // edx
char v7[8]; // [rsp+8h] [rbp-80h] BYREF
__int64 v8[15]; // [rsp+10h] [rbp-78h] BYREF

func1(v7);
v4 = my_strlen(*a3);
func0(v8);
result = (__int64)v7;
for ( i = 0; i != 8; ++i )
{
if ( *(_BYTE *)result == a1 )
{
if ( a1 != 51 )
return ((__int64 (__fastcall *)(_QWORD, _DWORD *, _QWORD *))v8[i])((unsigned int)a1, a2, a3);
++*a2;
return ((__int64 (__fastcall *)(__int64, _DWORD *, _QWORD *))v8[i])(51LL, a2, a3);
}
++result;
}
if ( (a1 == 68 || a1 == 2) && (result = (unsigned int)*a2, (int)result > 0) )
{
result = (unsigned int)(result - 1);
*a2 = result;
}
else if ( a1 == 67 || a1 == 6 )
{
result = (unsigned int)*a2;
if ( (int)result < v4 )
{
result = (unsigned int)(result + 1);
*a2 = result;
}
}
return result;
}

original_code:
void move_reverse_case(char value, int *rev_c, char **cmd)
{
  void (*options[9])(char, int *, char **);
  char opt[8];
  int len;
  int i;
  i = -1;
  fill_tab(opt);
  len = my_strlen(*cmd);
  fill_fct_ptr(options);
  while (++i < 8 && opt[i] != value);
  if (i != 8)
    {
      if (value == 51)
 {
   (*rev_c)++;
   options[i](value, rev_c, cmd);
 }
      else
 options[i](value, rev_c, cmd);
    }
  else if ((value == 68 || value == 2) && (*rev_c) > 0)
    (*rev_c)--;
  else if ((value == 67 || value == 6) && (*rev_c) < len)
    (*rev_c)++;
}

variable_types:
options
void (*[9])(char, int *, char **)

variable_types:
opt
char [8]


decompiled_code:
__int64 __fastcall launch_exec(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
char v4; // dl

result = 1LL;
if ( a1 )
{
v3 = get_exec(a1[3], 0LL, a2);
a1[2] = v3;
result = 0LL;
if ( v3 )
{
v4 = launch_exec(a1[1], a2);
result = 1LL;
if ( !v4 )
result = nullify_jobs(a1, 0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
char v4; // dl

result = 1LL;
if ( a1 )
{
v3 = get_exec(a1[3], 0LL, a2);
a1[2] = v3;
result = 0LL;
if ( v3 )
{
v4 = func0(a1[1], a2);
result = 1LL;
if ( !v4 )
result = nullify_jobs(a1, 0LL);
}
}
return result;
}

original_code:
static unsigned char launch_exec(t_jobs *exec, char **bad_sintax)
{
  if (!exec)
    return (1);
  if ((exec->exec = get_exec(exec->tmp, ((void *)0), bad_sintax)) == ((void *)0))
    return (0);
  if (launch_exec(exec->next, bad_sintax) == 0)
    return (nullify_jobs(exec, 0));
  return (1);
}

canonical_original_code:
static unsigned char launch_exec(struct s_jobs *exec, char **bad_sintax)
{
  if (!exec)
    return (1);
  if ((exec->exec = get_exec(exec->tmp, ((void *)0), bad_sintax)) == ((void *)0))
    return (0);
  if (launch_exec(exec->next, bad_sintax) == 0)
    return (nullify_jobs(exec, 0));
  return (1);
}


decompiled_code:
__int64 __fastcall launch_pipe(__int64 a1, __int64 a2)
{
__int64 result; // rax
char v3; // dl

result = 1LL;
if ( a1 )
{
if ( (unsigned __int8)get_pipe(*(_QWORD *)(a1 + 16)) )
{
v3 = launch_pipe(*(_QWORD *)(a1 + 8), a2);
result = 1LL;
if ( !v3 )
result = nullify_jobs(a1, 0LL);
}
else
{
nullify_all_jobs(*(_QWORD *)(a1 + 8));
result = nullify_jobs(a1, 1LL);
}
}
return result;
}

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

result = 1LL;
if ( a1 )
{
if ( (unsigned __int8)get_pipe(*(_QWORD *)(a1 + 16)) )
{
v3 = func1(*(_QWORD *)(a1 + 8), a2);
result = 1LL;
if ( !v3 )
result = nullify_jobs(a1, 0LL);
}
else
{
nullify_all_jobs(*(_QWORD *)(a1 + 8));
result = nullify_jobs(a1, 1LL);
}
}
return result;
}

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

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


decompiled_code:
__int64 __fastcall dlaunch_cmd(__int64 a1, __int64 a2, unsigned __int8 a3)
{
__int64 result; // rax
unsigned int v4; // ebx
char v5; // dl

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned __int8 a3)
{
__int64 result; // rax
unsigned int v4; // ebx
char v5; // dl

result = 1LL;
if ( a1 )
{
v4 = a3;
result = get_cmd(*(_QWORD *)(a1 + 16), a2, 0LL, a3);
if ( (_BYTE)result )
{
v5 = func2(*(_QWORD *)(a1 + 8), a2, v4);
result = 1LL;
if ( !v5 )
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)
{
__int64 result; // rax
unsigned int v4; // ebp
char v5; // dl

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int8 a3)
{
__int64 result; // rax
unsigned int v4; // ebp
char v5; // dl

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

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


decompiled_code:
void __fastcall catch_signal(int a1)
{
__int64 v1; // rax
unsigned int v2; // [rsp+Ch] [rbp-6Ch] BYREF
char v3[88]; // [rsp+10h] [rbp-68h] BYREF
__int64 v4; // [rsp+68h] [rbp-10h] BYREF

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

canonical_decompiled_code:
void __fastcall func0(int a1)
{
__int64 v1; // rax
unsigned int v2; // [rsp+Ch] [rbp-6Ch] BYREF
char v3[88]; // [rsp+10h] [rbp-68h] BYREF
__int64 v4; // [rsp+68h] [rbp-10h] BYREF

retain_struct_options(2LL, v3);
retain_cmd(2LL, &v4);
if ( a1 == 2 )
{
v2 = 0;
show_cmd(10LL, 0LL, v4, 0LL);
my_putstr(&unk_13A, 1LL);
prompt(1LL);
v1 = my_strlen(v4);
v4 = my_memset(v4, 0LL, v1);
retain_reverse_case(1LL, &v2);
show_cmd(0LL, 10LL, v4, v2);
my_putstr(&unk_13C, 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; }


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

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

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

ioctl(0, 0x5413uLL, v4);
v2 = my_strlen(a1);
result = v2 / v5;
v3 = result - 1;
if ( (int)result - 1 >= 0 )
{
do
{
result = my_putstr(&unk_13A, 1LL);
--v3;
}
while ( v3 != -1 );
}
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


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


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 result; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax

result = 0LL;
if ( a1 )
{
v2 = my_strlen(&unk_346);
if ( (unsigned int)my_strncmp(&unk_346, a1, v2) )
{
v3 = my_strlen(&unk_34D);
if ( (unsigned int)my_strncmp(&unk_34D, a1, v3) )
{
v4 = my_strlen(&unk_34B);
if ( (unsigned int)my_strncmp(&unk_34B, a1, v4) )
{
v5 = my_strlen(&unk_349);
result = 2 * (unsigned int)((unsigned int)my_strncmp(&unk_349, a1, v5) == 0);
}
else
{
result = 1LL;
}
}
else
{
result = 8LL;
}
}
else
{
result = 4LL;
}
}
return result;
}

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

result = 0LL;
if ( a1 )
{
v2 = my_strlen(&unk_346);
if ( (unsigned int)my_strncmp(&unk_346, a1, v2) )
{
v3 = my_strlen(&unk_34D);
if ( (unsigned int)my_strncmp(&unk_34D, a1, v3) )
{
v4 = my_strlen(&unk_34B);
if ( (unsigned int)my_strncmp(&unk_34B, a1, v4) )
{
v5 = my_strlen(&unk_349);
result = 2 * (unsigned int)((unsigned int)my_strncmp(&unk_349, a1, v5) == 0);
}
else
{
result = 1LL;
}
}
else
{
result = 8LL;
}
}
else
{
result = 4LL;
}
}
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
unsigned int v3; // edx
void *v5; // rbx
__int64 v6; // rdx
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, _QWORD *a2)
{
int v2; // eax
unsigned int v3; // edx
void *v5; // rbx
__int64 v6; // rdx
struct stat v7; // [rsp+0h] [rbp-A8h] BYREF

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

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


decompiled_code:
__int64 __fastcall redir_part(char **a1, char ***a2, _QWORD *a3)
{
__int64 v4; // rax
__int64 v5; // rbx
char *v6; // rbp
void *v8; // rdi
char **v9; // [rsp+8h] [rbp-30h] BYREF

v9 = a1;
v4 = xmalloc(32LL);
if ( !v4 )
return (unsigned __int8)nullify_words(v9);
v5 = v4;
*(_QWORD *)(v4 + 24) = 0LL;
*(_QWORD *)(v4 + 16) = 0LL;
*(_DWORD *)(v4 + 4) = 0;
v6 = *v9;
*(_DWORD *)(v4 + 8) = v6[my_strilen(*v9, 62LL)] != 0;
if ( link_redir(v9, &v9, (_DWORD *)v5, a3) )
{
if ( *(_DWORD *)(v5 + 4) != 1 )
*(_DWORD *)(v5 + 4) = 2;
*a2 = v9;
}
else
{
nullify_words(v9);
v8 = *(void **)(v5 + 16);
if ( v8 )
free(v8);
free((void *)v5);
v5 = 0LL;
}
return v5;
}

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


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


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

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

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

v1 = *(_QWORD **)(a1 + 8);
result = 0LL;
if ( v1 )
{
if ( *v1 )
result = my_getnbr();
}
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_next_word(__int64 a1, int *a2, _QWORD *a3)
{
int v4; // edi
__int64 result; // rax
char v6; // dl
__int64 i; // rdx
char v8; // cl
int v9; // ecx
char v10; // dl

v4 = my_strlen(*a3);
result = (unsigned int)*a2;
if ( (int)result < v4 )
{
v6 = *(_BYTE *)(*a3 + (int)result);
if ( v6 == 9 || v6 == 32 || (result = (unsigned int)(result + 1), *a2 = result, (int)result < v4) )
{
for ( i = (int)result; ; ++i )
{
v8 = *(_BYTE *)(*a3 + i);
if ( v8 != 32 && v8 != 9 )
break;
result = (unsigned int)(result + 1);
*a2 = result;
if ( (int)result >= v4 )
return result;
}
v9 = *a2;
if ( v4 > *a2 )
{
result = v9;
do
{
v10 = *(_BYTE *)(*a3 + result);
if ( v10 == 9 )
break;
if ( v10 == 32 )
break;
*a2 = ++result;
}
while ( result != v9 + (unsigned __int64)(unsigned int)(v4 + ~v9) + 1 );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int *a2, _QWORD *a3)
{
int v4; // edi
__int64 result; // rax
char v6; // dl
__int64 i; // rdx
char v8; // cl
int v9; // ecx
char v10; // dl

v4 = my_strlen(*a3);
result = (unsigned int)*a2;
if ( (int)result < v4 )
{
v6 = *(_BYTE *)(*a3 + (int)result);
if ( v6 == 9 || v6 == 32 || (result = (unsigned int)(result + 1), *a2 = result, (int)result < v4) )
{
for ( i = (int)result; ; ++i )
{
v8 = *(_BYTE *)(*a3 + i);
if ( v8 != 32 && v8 != 9 )
break;
result = (unsigned int)(result + 1);
*a2 = result;
if ( (int)result >= v4 )
return result;
}
v9 = *a2;
if ( v4 > *a2 )
{
result = v9;
do
{
v10 = *(_BYTE *)(*a3 + result);
if ( v10 == 9 )
break;
if ( v10 == 32 )
break;
*a2 = ++result;
}
while ( result != v9 + (unsigned __int64)(unsigned int)(v4 + ~v9) + 1 );
}
}
}
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: c char

variable_types:
cmd
char **

variable_types: len int


seek

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

if ( !a1 )
return 0LL;
if ( *a1 )
{
v4 = my_strilen(a1, 58LL);
v5 = my_strndup(a1, v4);
v6 = (void *)v5;
if ( v5 && !(unsigned __int8)in_directory(v5, a2) )
{
free(v6);
if ( a1[my_strilen(a1, 58LL)] )
{
v8 = my_strilen(a1, 58LL);
v9 = my_strilen(a1, 58LL);
v6 = (void *)seek(&a1[v8 - ((a1[v9] == 0) - 1LL)], a2, a3);
}
else
{
*a3 = my_strcat("(sh): command not found : ");
v6 = 0LL;
}
}
}
else
{
*a3 = my_strcat("(sh): command not found : ");
v6 = 0LL;
}
return v6;
}

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

if ( !a1 )
return 0LL;
if ( *a1 )
{
v4 = my_strilen(a1, 58LL);
v5 = my_strndup(a1, v4);
v6 = (void *)v5;
if ( v5 && !(unsigned __int8)in_directory(v5, a2) )
{
free(v6);
if ( a1[my_strilen(a1, 58LL)] )
{
v8 = my_strilen(a1, 58LL);
v9 = my_strilen(a1, 58LL);
v6 = (void *)func0(&a1[v8 - ((a1[v9] == 0) - 1LL)], a2, a3);
}
else
{
*a3 = my_strcat("(sh): command not found : ");
v6 = 0LL;
}
}
}
else
{
*a3 = my_strcat("(sh): command not found : ");
v6 = 0LL;
}
return v6;
}

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 *


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

v2 = (_BYTE *)get_env("PATH");
if ( !v2 )
*a2 = my_strcat("(sh): command not found : ");
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; // rbx
void *v3; // rax
void *v4; // rbx
__int64 v5; // rbp

v2 = (_BYTE *)get_env("PATH");
if ( !v2 )
*a2 = my_strcat("(sh): command not found : ");
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) )
{
free_str_edit_lines(*a2, *a3);
result = 0xFFFFFFFFLL;
}
else
{
retain_reverse_case(2LL, a4);
result = modif_cmd(a3, *a2, a4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(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) )
{
free_str_edit_lines(*a2, *a3);
result = 0xFFFFFFFFLL;
}
else
{
retain_reverse_case(2LL, a4);
result = modif_cmd(a3, *a2, a4);
}
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
__int64 result; // rax

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

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

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

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; // eax
int v4; // [rsp+48h] [rbp-B0h] BYREF
unsigned int v5; // [rsp+4Ch] [rbp-ACh] BYREF
__int64 v6; // [rsp+50h] [rbp-A8h] BYREF
char *v7; // [rsp+58h] [rbp-A0h] BYREF
char v8[16]; // [rsp+60h] [rbp-98h] BYREF
char v9[88]; // [rsp+A0h] [rbp-58h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func3(int fd, __int64 a2)
{
int v2; // eax
int v4; // [rsp+48h] [rbp-B0h] BYREF
unsigned int v5; // [rsp+4Ch] [rbp-ACh] BYREF
__int64 v6; // [rsp+50h] [rbp-A8h] BYREF
char *v7; // [rsp+58h] [rbp-A0h] BYREF
char v8[16]; // [rsp+60h] [rbp-98h] BYREF
char v9[88]; // [rsp+A0h] [rbp-58h] BYREF

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

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 func1(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)
{
int v3; // edi
__int64 result; // rax
int v5; // eax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v3; // edi
__int64 result; // rax
int v5; // eax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

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

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


decompiled_code:
char __fastcall exec_built_in(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
void *v3; // r12
_QWORD *v4; // rbx
int v5; // eax
__int64 v6; // rdi
char result; // al

v2 = (_QWORD *)builtins();
v3 = v2;
if ( *v2 )
{
v4 = v2;
while ( !**(_QWORD **)(a1 + 16) || (unsigned int)((__int64 (*)(void))my_strcmp)() )
{
v4 += 2;
if ( !*v4 )
goto LABEL_8;
}
v5 = ((__int64 (__fastcall *)(_QWORD, __int64))v4[1])(*(_QWORD *)(a1 + 16), a2 + 120);
*(_DWORD *)(a2 + 108) = v5;
*(_DWORD *)(a2 + 104) = v5 != 0;
v6 = **(_QWORD **)(a1 + 16);
result = 1;
if ( v6 )
result = ((unsigned int)my_strcmp(v6, "exit") == 0) + 1;
}
else
{
LABEL_8:
free(v3);
result = 0;
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax
void *v3; // r12
_QWORD *v4; // rbx
int v5; // eax
__int64 v6; // rdi
char result; // al

v2 = (_QWORD *)builtins();
v3 = v2;
if ( *v2 )
{
v4 = v2;
while ( !**(_QWORD **)(a1 + 16) || (unsigned int)((__int64 (*)(void))my_strcmp)() )
{
v4 += 2;
if ( !*v4 )
goto LABEL_8;
}
v5 = ((__int64 (__fastcall *)(_QWORD, __int64))v4[1])(*(_QWORD *)(a1 + 16), a2 + 120);
*(_DWORD *)(a2 + 108) = v5;
*(_DWORD *)(a2 + 104) = v5 != 0;
v6 = **(_QWORD **)(a1 + 16);
result = 1;
if ( v6 )
result = ((unsigned int)my_strcmp(v6, "exit") == 0) + 1;
}
else
{
LABEL_8:
free(v3);
result = 0;
}
return result;
}

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


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


builtins

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

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

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

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

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

if ( !a1 )
return 0LL;
result = 1LL;
if ( *(_DWORD *)a1 != 4 )
result = check_for_dleft(*(_QWORD *)(a1 + 24));
return result;
}

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

if ( !a1 )
return 0LL;
result = 1LL;
if ( *(_DWORD *)a1 != 4 )
result = func0(*(_QWORD *)(a1 + 24));
return result;
}

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