decompiled_code:
__int64 __fastcall exec_env(__int64 *a1, char **a2)
{
_BYTE *v2; // r12
char **v3; // rbx
_BYTE *v4; // rsi
__int64 v6; // rax
char v7; // [rsp+1h] [rbp-25h] BYREF
unsigned int v8; // [rsp+2h] [rbp-24h] BYREF
void *ptr; // [rsp+6h] [rbp-20h] BYREF

if ( !a1 )
return print_env();
v2 = (_BYTE *)*a1;
v3 = environ;
environ = a2;
ptr = 0LL;
v4 = v2;
if ( *v2 == 46 )
goto LABEL_3;
if ( !v2[my_strilen(v2, 47LL)] )
{
v6 = seek_cmd(*a1, &ptr);
*a1 = v6;
v4 = (_BYTE *)v6;
if ( !v6 )
{
environ = v3;
return seek_fail(ptr);
}
LABEL_3:
environ = v3;
goto LABEL_4;
}
v4 = (_BYTE *)*a1;
environ = v3;
if ( !v4 )
goto LABEL_9;
LABEL_4:
if ( (unsigned int)my_strcmp(v2, v4) )
LABEL_9:
free(v2);
exec_form(a1, &v7, &v8);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, char **a2)
{
_BYTE *v2; // r12
char **v3; // rbx
_BYTE *v4; // rsi
__int64 v6; // rax
char v7; // [rsp+1h] [rbp-25h] BYREF
unsigned int v8; // [rsp+2h] [rbp-24h] BYREF
void *ptr; // [rsp+6h] [rbp-20h] BYREF

if ( !a1 )
return func0();
v2 = (_BYTE *)*a1;
v3 = environ;
environ = a2;
ptr = 0LL;
v4 = v2;
if ( *v2 == 46 )
goto LABEL_3;
if ( !v2[my_strilen(v2, 47LL)] )
{
v6 = seek_cmd(*a1, &ptr);
*a1 = v6;
v4 = (_BYTE *)v6;
if ( !v6 )
{
environ = v3;
return func1(ptr);
}
LABEL_3:
environ = v3;
goto LABEL_4;
}
v4 = (_BYTE *)*a1;
environ = v3;
if ( !v4 )
goto LABEL_9;
LABEL_4:
if ( (unsigned int)my_strcmp(v2, v4) )
LABEL_9:
free(v2);
exec_form(a1, &v7, &v8);
return v8;
}

original_code:
int exec_env(t_words *word, char **save)
{
  int st;
  unsigned char ef;
  char *r;
  char *f;
  char **safe;
  if (!word)
    return (print_env());
  f = word->word;
  r = ((void *)0);
  safe = environ;
  environ = save;
  if (!((word->word)[0] == '.' || (((word->word))[my_strilen((word->word), '/')] != 0)))
    if ((word->word = seek_cmd(word->word, &r)) == ((void *)0))
      {
 environ = safe;
 return (seek_fail(r));
      }
  environ = safe;
  if (!((f && word->word) ? (!my_strcmp(f, word->word)) : (0)))
    free(f);
  exec_form(word, &ef, &st);
  return (st);
}

canonical_original_code:
int exec_env(struct s_words *word, char **save)
{
  int st;
  unsigned char ef;
  char *r;
  char *f;
  char **safe;
  if (!word)
    return (print_env());
  f = word->word;
  r = ((void *)0);
  safe = environ;
  environ = save;
  if (!((word->word)[0] == '.' || (((word->word))[my_strilen((word->word), '/')] != 0)))
    if ((word->word = seek_cmd(word->word, &r)) == ((void *)0))
      {
 environ = safe;
 return (seek_fail(r));
      }
  environ = safe;
  if (!((f && word->word) ? (!my_strcmp(f, word->word)) : (0)))
    free(f);
  exec_form(word, &ef, &st);
  return (st);
}

variable_types:
save
char **

variable_types: st int

variable_types:
ef
unsigned char

variable_types:
f
char *

variable_types:
safe
char **


decompiled_code:
__int64 clean_screen()
{
__int64 v1[11]; // [rsp+0h] [rbp-58h] BYREF

retain_struct_options(2LL, v1);
my_putstr(v1[0], 1LL);
return prompt(1LL);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v1[11]; // [rsp+0h] [rbp-58h] BYREF

retain_struct_options(2LL, v1);
my_putstr(v1[0], 1LL);
return prompt(1LL);
}

original_code:
void clean_screen(char value, int *reverse_case, char **cmd)
{
  t_options tmp;
  retain_struct_options(2, &tmp);
  (void)value;
  (void)reverse_case;
  (void)cmd;
  my_putstr(tmp.clear, 1);
  prompt(1);
}

canonical_original_code:
void clean_screen(char value, int *reverse_case, char **cmd)
{
  struct s_options tmp;
  retain_struct_options(2, &tmp);
  (void)value;
  (void)reverse_case;
  (void)cmd;
  my_putstr(tmp.clear, 1);
  prompt(1);
}

variable_types: value char

variable_types:
cmd
char **

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

return_type: void


decompiled_code:
__int64 __fastcall clean_str(__int64 a1, _DWORD *a2, __int64 *a3)
{
__int64 v4; // rax
__int64 result; // rax

my_putstr(&unk_80, 1LL);
*a2 = 0;
remind_save_str(1LL, a3);
v4 = my_strlen(*a3);
result = my_memset(*a3, 0LL, v4);
*a3 = result;
return result;
}

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

my_putstr(&unk_80, 1LL);
*a2 = 0;
remind_save_str(1LL, a3);
v4 = my_strlen(*a3);
result = my_memset(*a3, 0LL, v4);
*a3 = result;
return result;
}

original_code:
void clean_str(char value, int *reverse_case, char **cmd)
{
  (void)value;
  my_putstr("\r", 1);
  (*reverse_case) = 0;
  remind_save_str(1, cmd);
  (*cmd) = my_memset(*cmd, 0, my_strlen(*cmd));
}


deset

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

v2 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
if ( *v2 )
{
if ( a2 )
{
v3 = ((__int64 (*)(void))my_strlen)();
if ( !(unsigned int)my_strncmp(*v2, a2, v3) && *(_BYTE *)(a2 + my_strlen(*v2)) == 61 )
break;
}
}
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return 1LL;
}

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

v2 = a1;
if ( !a1 )
return 0LL;
while ( 1 )
{
if ( *v2 )
{
if ( a2 )
{
v3 = ((__int64 (*)(void))my_strlen)();
if ( !(unsigned int)my_strncmp(*v2, a2, v3) && *(_BYTE *)(a2 + my_strlen(*v2)) == 61 )
break;
}
}
v2 = (_QWORD *)v2[1];
if ( !v2 )
return 0LL;
}
return 1LL;
}

original_code:
static unsigned char deset(t_words *cmd, char *env)
{
  if (!cmd)
    return (0);
  if ((((cmd->word) && (env)) ? (!my_strncmp((cmd->word), (env), my_strlen(cmd->word))) : (0))
      && env[my_strlen(cmd->word)] == '=')
    return (1);
  return (deset(cmd->next, env));
}

canonical_original_code:
static unsigned char deset(struct s_words *cmd, char *env)
{
  if (!cmd)
    return (0);
  if ((((cmd->word) && (env)) ? (!my_strncmp((cmd->word), (env), my_strlen(cmd->word))) : (0))
      && env[my_strlen(cmd->word)] == '=')
    return (1);
  return (deset(cmd->next, env));
}

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

variable_types:
env
char *

return_type: unsigned char


decompiled_code:
__int64 __fastcall switch_env(char **a1, char a2)
{
if ( !a2 )
{
if ( environ )
free(environ);
goto LABEL_4;
}
if ( !environ )
{
LABEL_4:
environ = a1;
return 0LL;
}
destroy_env(environ);
environ = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char **a1, char a2)
{
if ( !a2 )
{
if ( environ )
free(environ);
goto LABEL_4;
}
if ( !environ )
{
LABEL_4:
environ = a1;
return 0LL;
}
destroy_env(environ);
environ = a1;
return 0LL;
}

original_code:
int switch_env(char **tab, unsigned char destroy)
{
  if (!destroy)
    if (environ)
      free(environ);
  if (destroy && environ)
    destroy_env();
  environ = tab;
  return (0);
}

variable_types:
tab
char **

variable_types:
destroy
unsigned char

return_type: int


decompiled_code:
__int64 __fastcall built_unsetenv(__int64 a1)
{
_QWORD *v2; // rdi
char *v3; // rsi
__int64 v4; // r12
__int64 v5; // rbx
__int64 v6; // rbx
char **v7; // rax
char **v8; // r13
char *v9; // rsi
__int64 v10; // r12
__int64 v11; // rbx
char *v12; // rdx
bool v13; // zf
char **v14; // rax
char *v15; // rdi

v2 = *(_QWORD **)(a1 + 8);
if ( !v2 )
return my_putstr("(sh): unsetenv: Too few arguments.\n", 2LL) != 0;
if ( !environ )
return switch_env(0LL, 1);
v3 = *environ;
if ( !*environ )
return switch_env(0LL, 1);
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
++v5;
v4 -= ((unsigned __int8)deset(v2, (__int64)v3) == 0) - 1LL;
v3 = environ[v5];
if ( !v3 )
break;
v2 = *(_QWORD **)(a1 + 8);
}
if ( v4 == v5 )
return switch_env(0LL, 1);
v6 = 8 * (v5 - v4) + 8;
v7 = (char **)xmalloc(v6);
v8 = v7;
if ( !v7 )
return 1LL;
*(char **)((char *)v7 + v6 - 8) = 0LL;
v9 = *environ;
if ( *environ )
{
v10 = 0LL;
v11 = 0LL;
do
{
while ( 1 )
{
v13 = (unsigned __int8)deset(*(_QWORD **)(a1 + 8), (__int64)v9) == 0;
v14 = environ;
if ( !v13 )
break;
v12 = environ[v11++];
v8[v10] = v12;
v9 = v14[v11];
++v10;
if ( !v9 )
goto LABEL_14;
}
v15 = environ[v11++];
free(v15);
v9 = environ[v11];
}
while ( v9 );
LABEL_14:
v7 = &v8[v10];
}
*v7 = 0LL;
return switch_env(v8, 0);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
_QWORD *v2; // rdi
char *v3; // rsi
__int64 v4; // r12
__int64 v5; // rbx
__int64 v6; // rbx
char **v7; // rax
char **v8; // r13
char *v9; // rsi
__int64 v10; // r12
__int64 v11; // rbx
char *v12; // rdx
bool v13; // zf
char **v14; // rax
char *v15; // rdi

v2 = *(_QWORD **)(a1 + 8);
if ( !v2 )
return my_putstr("(sh): unsetenv: Too few arguments.\n", 2LL) != 0;
if ( !environ )
return func1(0LL, 1);
v3 = *environ;
if ( !*environ )
return func1(0LL, 1);
v4 = 0LL;
v5 = 0LL;
while ( 1 )
{
++v5;
v4 -= ((unsigned __int8)func0(v2, (__int64)v3) == 0) - 1LL;
v3 = environ[v5];
if ( !v3 )
break;
v2 = *(_QWORD **)(a1 + 8);
}
if ( v4 == v5 )
return func1(0LL, 1);
v6 = 8 * (v5 - v4) + 8;
v7 = (char **)xmalloc(v6);
v8 = v7;
if ( !v7 )
return 1LL;
*(char **)((char *)v7 + v6 - 8) = 0LL;
v9 = *environ;
if ( *environ )
{
v10 = 0LL;
v11 = 0LL;
do
{
while ( 1 )
{
v13 = (unsigned __int8)func0(*(_QWORD **)(a1 + 8), (__int64)v9) == 0;
v14 = environ;
if ( !v13 )
break;
v12 = environ[v11++];
v8[v10] = v12;
v9 = v14[v11];
++v10;
if ( !v9 )
goto LABEL_14;
}
v15 = environ[v11++];
free(v15);
v9 = environ[v11];
}
while ( v9 );
LABEL_14:
v7 = &v8[v10];
}
*v7 = 0LL;
return func1(v8, 0);
}

original_code:
int built_unsetenv(t_words *cmd, void *null)
{
  char **tab;
  size_t i;
  size_t n;
  (void)null;
  if (!cmd->next)
    return (my_putstr("(sh): unsetenv: Too few arguments.\n", 2) != 0);
  i = (n = 0);
  if (environ)
    while (environ[i])
      if (deset(cmd->next, environ[i++]))
 n++;
  if (i == n)
    return (switch_env(((void *)0), 1));
  if ((tab = xmalloc(sizeof(char*) * (i - n + 1))) == ((void *)0))
    return (1);
  tab[i - n] = ((void *)0);
  i = (n = 0);
  while (environ[i])
    if (!deset(cmd->next, environ[i]))
      tab[n++] = environ[i++];
    else
      free(environ[i++]);
  tab[n] = ((void *)0);
  return (switch_env(tab, 0));
}

canonical_original_code:
int built_unsetenv(struct s_words *cmd, void *null)
{
  char **tab;
  unsigned long i;
  unsigned long n;
  (void)null;
  if (!cmd->next)
    return (my_putstr("(sh): unsetenv: Too few arguments.\n", 2) != 0);
  i = (n = 0);
  if (environ)
    while (environ[i])
      if (deset(cmd->next, environ[i++]))
 n++;
  if (i == n)
    return (switch_env(((void *)0), 1));
  if ((tab = xmalloc(sizeof(char *) * (i - n + 1))) == ((void *)0))
    return (1);
  tab[i - n] = ((void *)0);
  i = (n = 0);
  while (environ[i])
    if (!deset(cmd->next, environ[i]))
      tab[n++] = environ[i++];
    else
      free(environ[i++]);
  tab[n] = ((void *)0);
  return (switch_env(tab, 0));
}

variable_types:
i
unsigned long

variable_types:
n
unsigned long

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


original_code:
static int add_after(t_alias *put, t_alias *link)
{
  link->next = put->next;
  if (link->next)
    link->next->prev = link;
  link->prev = put;
  link->prev->next = link;
  return (0);
}

canonical_original_code:
static int add_after(struct s_alias *put, struct s_alias *link)
{
  link->next = put->next;
  if (link->next)
    link->next->prev = link;
  link->prev = put;
  link->prev->next = link;
  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; } *

variable_types:
link
struct s_alias *


decompiled_code:
__int64 __fastcall mod_alias(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 v4; // rax
_QWORD *v5; // rbp
__int64 v6; // rax
__int64 v7; // rax

v4 = xmalloc(48LL);
if ( !v4 )
return 1LL;
v5 = (_QWORD *)v4;
v6 = my_strdup(a1);
*v5 = v6;
if ( !v6 )
return 1LL;
v7 = my_strdup(a2);
v5[1] = v7;
if ( !v7 )
return 1LL;
v5[3] = 0LL;
v5[2] = 0LL;
if ( *a3 )
return add_link_constprop_0((__int64)v5, a1, a3);
*a3 = (__int64)v5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 v4; // rax
_QWORD *v5; // rbp
__int64 v6; // rax
__int64 v7; // rax

v4 = xmalloc(48LL);
if ( !v4 )
return 1LL;
v5 = (_QWORD *)v4;
v6 = my_strdup(a1);
*v5 = v6;
if ( !v6 )
return 1LL;
v7 = my_strdup(a2);
v5[1] = v7;
if ( !v7 )
return 1LL;
v5[3] = 0LL;
v5[2] = 0LL;
if ( *a3 )
return func1((__int64)v5, a1, a3);
*a3 = (__int64)v5;
return 0LL;
}

original_code:
int mod_alias(char *a, char *f, t_alias **alias)
{
  t_alias *link;
  if ((link = xmalloc(sizeof(*link))) == ((void *)0))
    return (1);
  if ((link->name = my_strdup(a)) == ((void *)0))
    return (1);
  if ((link->fill = my_strdup(f)) == ((void *)0))
    return (1);
  link->prev = ((void *)0);
  link->next = ((void *)0);
  if (*alias)
    return (add_link(link, a, alias));
  *alias = link;
  return (0);
}

canonical_original_code:
int mod_alias(char *a, char *f, struct s_alias **alias)
{
  struct s_alias *link;
  if ((link = xmalloc(sizeof(*link))) == ((void *)0))
    return (1);
  if ((link->name = my_strdup(a)) == ((void *)0))
    return (1);
  if ((link->fill = my_strdup(f)) == ((void *)0))
    return (1);
  link->prev = ((void *)0);
  link->next = ((void *)0);
  if (*alias)
    return (add_link(link, a, alias));
  *alias = link;
  return (0);
}

variable_types:
a
char *

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:
void catch_after()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void catch_after(int num)
{
  (void)num;
}

variable_types: num int


built

original_code:
static void *built(char *str, char **bad_sintax, t_info *info, char **mod_s)
{
  t_get *sub;
  if (seed_alias(str, info->alias, &str) == 0)
    return (((void *)0));
  if (grow_var(str, &str, 0, info) == 0)
    return (((void *)0));
  *mod_s = str;
  if ((sub = subdivide(str, ((void *)0), bad_sintax)) == ((void *)0))
    return (((void *)0));
  if ((sub = comment(sub, ((void *)0))) == ((void *)0))
    return (((void *)0));
  return (orga(sub, bad_sintax, ((void *)0), 0));
}

canonical_original_code:
static void *built(char *str, char **bad_sintax, struct s_info *info, char **mod_s)
{
  struct s_get *sub;
  if (seed_alias(str, info->alias, &str) == 0)
    return (((void *)0));
  if (grow_var(str, &str, 0, info) == 0)
    return (((void *)0));
  *mod_s = str;
  if ((sub = subdivide(str, ((void *)0), bad_sintax)) == ((void *)0))
    return (((void *)0));
  if ((sub = comment(sub, ((void *)0))) == ((void *)0))
    return (((void *)0));
  return (orga(sub, bad_sintax, ((void *)0), 0));
}

variable_types:
str
char *

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

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

return_type: void *

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


decompiled_code:
__int64 __fastcall built_and_exec(void *a1, __int64 a2, __int64 **a3)
{
void *v4; // rbp
__int64 v5; // r14
__int64 v6; // rdi
__int64 result; // rax
void *ptr; // [rsp+8h] [rbp-40h] BYREF
void *v9; // [rsp+18h] [rbp-30h] BYREF

ptr = a1;
v9 = 0LL;
v4 = (void *)my_strdup();
if ( (unsigned __int8)empty(a1) )
goto LABEL_10;
v5 = built((__int64)ptr, (__int64)&v9, a2, &ptr);
if ( v5 )
{
if ( !(unsigned __int8)empty(v4) )
{
LABEL_4:
if ( !*a3 || (v6 = **a3, !v4) || !v6 || (unsigned int)my_strcmp(v6, v4) )
my_put_in_history(a3, v4);
}
LABEL_8:
free(v4);
free(ptr);
return pre_exec(v5, a2, 0LL);
}
result = empty(ptr);
if ( (_BYTE)result )
{
LABEL_10:
v5 = 0LL;
if ( !(unsigned __int8)empty(v4) )
goto LABEL_4;
goto LABEL_8;
}
if ( v9 )
{
fprintf(stderr, "%s\n", (const char *)v9);
free(v9);
my_put_in_history(a3, v4);
free(v4);
result = 1LL;
}
else
{
*(_DWORD *)(a2 + 104) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *a1, __int64 a2, __int64 **a3)
{
void *v4; // rbp
__int64 v5; // r14
__int64 v6; // rdi
__int64 result; // rax
void *ptr; // [rsp+8h] [rbp-40h] BYREF
void *v9; // [rsp+18h] [rbp-30h] BYREF

ptr = a1;
v9 = 0LL;
v4 = (void *)my_strdup();
if ( (unsigned __int8)empty(a1) )
goto LABEL_10;
v5 = func1((__int64)ptr, (__int64)&v9, a2, &ptr);
if ( v5 )
{
if ( !(unsigned __int8)empty(v4) )
{
LABEL_4:
if ( !*a3 || (v6 = **a3, !v4) || !v6 || (unsigned int)my_strcmp(v6, v4) )
my_put_in_history(a3, v4);
}
LABEL_8:
free(v4);
free(ptr);
return pre_exec(v5, a2, 0LL);
}
result = empty(ptr);
if ( (_BYTE)result )
{
LABEL_10:
v5 = 0LL;
if ( !(unsigned __int8)empty(v4) )
goto LABEL_4;
goto LABEL_8;
}
if ( v9 )
{
fprintf(stderr, "%s\n", (const char *)v9);
free(v9);
my_put_in_history(a3, v4);
free(v4);
result = 1LL;
}
else
{
*(_DWORD *)(a2 + 104) = 1;
}
return result;
}

original_code:
static unsigned char built_and_exec(char *str, t_info *info, t_history **history)
{
  char *retain;
  t_jobs *exec;
  char *bad_sintax;
  retain = my_strdup(str);
  exec = (void*)(bad_sintax = ((void *)0));
  if (!empty(str))
    if ((exec = built(str, &bad_sintax, info, &str)) == ((void *)0))
      if (!empty(str))
 {
   if (bad_sintax)
     {
       fprintf(stderr, "%s\n", bad_sintax);
       free(bad_sintax);
       my_put_in_history(history, retain);
       free(retain);
       return (1);
     }
   return (!(info->st = 1));
 }
  if (!empty(retain) && (!(*history) || !(((*history)->str && retain) ? (!my_strcmp((*history)->str, retain)) : (0))))
    my_put_in_history(history, retain);
  free(retain);
  free(str);
  return (pre_exec(exec, info, 0));
}

canonical_original_code:
static unsigned char built_and_exec(char *str, struct s_info *info, struct s_history **history)
{
  char *retain;
  struct s_jobs *exec;
  char *bad_sintax;
  retain = my_strdup(str);
  exec = (void *)(bad_sintax = ((void *)0));
  if (!empty(str))
    if ((exec = built(str, &bad_sintax, info, &str)) == ((void *)0))
      if (!empty(str))
 {
   if (bad_sintax)
     {
       fprintf(stderr, "%s\n", bad_sintax);
       free(bad_sintax);
       my_put_in_history(history, retain);
       free(retain);
       return (1);
     }
   return (!(info->st = 1));
 }
  if (!empty(retain) && (!(*history) || !(((*history)->str && retain) ? (!my_strcmp((*history)->str, retain)) : (0))))
    my_put_in_history(history, retain);
  free(retain);
  free(str);
  return (pre_exec(exec, info, 0));
}

variable_types:
history
struct s_history **

variable_types:
retain
char *

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

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

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

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

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


decompiled_code:
__int64 __fastcall get_usr_cmd(char a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
__int64 result; // rax
__int64 v6; // r12

if ( a1 )
{
if ( a1 == 1 )
result = get_next_line(0LL);
else
result = v3;
}
else
{
configure_signals();
my_putstr(*(_QWORD *)(a3 + 56), 1LL);
v6 = usr_cmd(0LL, a2);
my_putstr(*(_QWORD *)(a3 + 64), 1LL);
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, __int64 a2, __int64 a3)
{
__int64 v3; // r12
__int64 result; // rax
__int64 v6; // r12

if ( a1 )
{
if ( a1 == 1 )
result = get_next_line(0LL);
else
result = v3;
}
else
{
configure_signals();
my_putstr(*(_QWORD *)(a3 + 56), 1LL);
v6 = usr_cmd(0LL, a2);
my_putstr(*(_QWORD *)(a3 + 64), 1LL);
result = v6;
}
return result;
}

original_code:
static char *get_usr_cmd(unsigned char tgetfail, t_history *history,
        struct s_options t, t_info *info)
{
  char *r;
  if (tgetfail == 0)
    {
      configure_signals();
      my_putstr(info->termcaps.invi_cursor, 1);
      r = usr_cmd(0, history, t);
      my_putstr(info->termcaps.visi_cursor, 1);
    }
  if (tgetfail == 1)
    r = get_next_line(0);
  return (r);
}

canonical_original_code:
static char *get_usr_cmd(unsigned char tgetfail, struct s_history *history, struct s_options t, struct s_info *info)
{
  char *r;
  if (tgetfail == 0)
    {
      configure_signals();
      my_putstr(info->termcaps.invi_cursor, 1);
      r = usr_cmd(0, history, t);
      my_putstr(info->termcaps.visi_cursor, 1);
    }
  if (tgetfail == 1)
    r = get_next_line(0);
  return (r);
}

variable_types:
tgetfail
unsigned char

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 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 { char *name; char *fill; struct s_alias *next; struct s_alias *prev; unsigned long w; unsigned long n; } *alias; } *

variable_types:
r
char *

return_type: char *


decompiled_code:
__int64 __fastcall read_cmds(__int64 a1, char a2)
{
char v2; // r12
__int64 *v5; // rsi
char *v6; // rdi
char *s; // [rsp+0h] [rbp-28h] BYREF
__int64 *v9; // [rsp+8h] [rbp-20h] BYREF

v2 = 1;
*(_BYTE *)(a1 + 88) = a2;
v5 = 0LL;
v9 = 0LL;
while ( 1 )
{
s = (char *)get_usr_cmd(a2, (__int64)v5, a1);
if ( !s )
break;
signal(2, (__sighandler_t)catch_after);
v5 = v9;
v6 = s;
*(_QWORD *)a1 = v9;
if ( v6 )
{
if ( (unsigned __int8)grow_hist(v6, &s, 0LL, a1) <= 1u )
goto LABEL_7;
if ( s )
{
puts(s);
LABEL_7:
if ( s )
v2 = built_and_exec(s, a1, &v9);
}
v5 = v9;
if ( !v2 )
goto LABEL_10;
}
}
my_putstr("exit", 1LL);
v5 = v9;
LABEL_10:
free_history(v5);
my_putstr(*(_QWORD *)(a1 + 64), 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char a2)
{
char v2; // r12
__int64 *v5; // rsi
char *v6; // rdi
char *s; // [rsp+0h] [rbp-28h] BYREF
__int64 *v9; // [rsp+8h] [rbp-20h] BYREF

v2 = 1;
*(_BYTE *)(a1 + 88) = a2;
v5 = 0LL;
v9 = 0LL;
while ( 1 )
{
s = (char *)func3(a2, (__int64)v5, a1);
if ( !s )
break;
signal(2, (__sighandler_t)catch_after);
v5 = v9;
v6 = s;
*(_QWORD *)a1 = v9;
if ( v6 )
{
if ( (unsigned __int8)grow_hist(v6, &s, 0LL, a1) <= 1u )
goto LABEL_7;
if ( s )
{
puts(s);
LABEL_7:
if ( s )
v2 = func2(s, a1, &v9);
}
v5 = v9;
if ( !v2 )
goto LABEL_10;
}
}
my_putstr("exit", 1LL);
v5 = v9;
LABEL_10:
free_history(v5);
my_putstr(*(_QWORD *)(a1 + 64), 1LL);
return 0LL;
}

original_code:
int read_cmds(t_info *info, unsigned char tgetfail)
{
  unsigned char c;
  char *str;
  t_history *history;
  info->term_caps = tgetfail;
  c = 1;
  history = ((void *)0);
  while (c && (str = get_usr_cmd(tgetfail, history, info->termcaps, info)))
    {
      signal(2, catch_after);
      info->hist = history;
      if (str && grow_hist(str, &str, 0, info) > 1)
 if (str)
   printf("%s\n", str);
      if (str)
 c = built_and_exec(str, info, &history);
    }
  if (c)
    my_putstr("exit", 1);
  free_history(history);
  my_putstr(info->termcaps.visi_cursor, 1);
  return (0);
}

canonical_original_code:
int read_cmds(struct s_info *info, unsigned char tgetfail)
{
  unsigned char c;
  char *str;
  struct s_history *history;
  info->term_caps = tgetfail;
  c = 1;
  history = ((void *)0);
  while (c && (str = get_usr_cmd(tgetfail, history, info->termcaps, info)))
    {
      signal(2, catch_after);
      info->hist = history;
      if (str && grow_hist(str, &str, 0, info) > 1)
 if (str)
   printf("%s\n", str);
      if (str)
 c = built_and_exec(str, info, &history);
    }
  if (c)
    my_putstr("exit", 1);
  free_history(history);
  my_putstr(info->termcaps.visi_cursor, 1);
  return (0);
}

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall my_putchar(char a1, int a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(a2, buf, 1uLL);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, int a2)
{
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
write(a2, buf, 1uLL);
return 1LL;
}

original_code:
size_t my_putchar(char c, int out)
{
  write(out, &c, 1);
  return (1);
}

canonical_original_code:
unsigned long my_putchar(char c, int out)
{
  write(out, &c, 1);
  return (1);
}

variable_types: c char

variable_types: out int

return_type: unsigned long


decompiled_code:
size_t __fastcall my_putstr(void *buf, int fd)
{
size_t v2; // r12

if ( !buf )
return 0LL;
v2 = 0LL;
if ( *(_BYTE *)buf )
{
do
++v2;
while ( *((_BYTE *)buf + v2) );
}
write(fd, buf, v2);
return v2;
}

canonical_decompiled_code:
size_t __fastcall func1(void *buf, int fd)
{
size_t v2; // r12

if ( !buf )
return 0LL;
v2 = 0LL;
if ( *(_BYTE *)buf )
{
do
++v2;
while ( *((_BYTE *)buf + v2) );
}
write(fd, buf, v2);
return v2;
}

original_code:
size_t my_putstr(const char *s, int out)
{
  size_t i;
  if (!s)
    return (0);
  i = 0;
  while (s[i])
    i++;
  write(out, s, i);
  return (i);
}

canonical_original_code:
unsigned long my_putstr(char *s, int out)
{
  unsigned long i;
  if (!s)
    return (0);
  i = 0;
  while (s[i])
    i++;
  write(out, s, i);
  return (i);
}

variable_types:
s
char *

variable_types:
i
unsigned long


decompiled_code:
size_t __fastcall my_putpath(void *buf, char *file)
{
size_t v2; // r12
int v3; // eax
int v4; // er13

v2 = 0LL;
if ( *(_BYTE *)buf )
{
do
++v2;
while ( *((_BYTE *)buf + v2) );
}
v3 = open(file, 0);
v4 = v3;
if ( v3 != -1 )
{
write(v3, buf, v2);
close(v4);
}
return v2;
}

canonical_decompiled_code:
size_t __fastcall func2(void *buf, char *file)
{
size_t v2; // r12
int v3; // eax
int v4; // er13

v2 = 0LL;
if ( *(_BYTE *)buf )
{
do
++v2;
while ( *((_BYTE *)buf + v2) );
}
v3 = open(file, 0);
v4 = v3;
if ( v3 != -1 )
{
write(v3, buf, v2);
close(v4);
}
return v2;
}

original_code:
size_t my_putpath(const char *s, const char *out)
{
  int f;
  size_t i;
  i = 0;
  while (s[i])
    i++;
  if ((f = open(out, 00)) != -1)
    write(f, s, i);
  if (f != -1)
    close(f);
  return (i);
}

canonical_original_code:
unsigned long my_putpath(char *s, char *out)
{
  int f;
  unsigned long i;
  i = 0;
  while (s[i])
    i++;
  if ((f = open(out, 00)) != -1)
    write(f, s, i);
  if (f != -1)
    close(f);
  return (i);
}

variable_types:
out
char *

variable_types: f int


decompiled_code:
ssize_t __fastcall print_err(void *buf)
{
size_t v1; // rdx

v1 = 0LL;
if ( *(_BYTE *)buf )
{
do
++v1;
while ( *((_BYTE *)buf + v1) );
}
return write(2, buf, v1);
}

canonical_decompiled_code:
ssize_t __fastcall func3(void *buf)
{
size_t v1; // rdx

v1 = 0LL;
if ( *(_BYTE *)buf )
{
do
++v1;
while ( *((_BYTE *)buf + v1) );
}
return write(2, buf, v1);
}

original_code:
size_t print_err(const char *s)
{
  size_t i;
  i = 0;
  while (s[i])
    i++;
  return (write(2, s, i));
}

canonical_original_code:
unsigned long print_err(char *s)
{
  unsigned long i;
  i = 0;
  while (s[i])
    i++;
  return (write(2, s, i));
}


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

if ( a1 )
{
v1 = a1[1];
free(a1);
nullify_exec(v1);
}
return 0LL;
}

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

if ( a1 )
{
v1 = a1[1];
free(a1);
func0(v1);
}
return 0LL;
}

original_code:
unsigned char nullify_exec(t_exec *exec)
{
  t_exec *next;
  if (!exec)
    return (0);
  next = exec->next;
  free(exec);
  nullify_exec(next);
  return (0);
}

canonical_original_code:
unsigned char nullify_exec(struct s_exec *exec)
{
  struct s_exec *next;
  if (!exec)
    return (0);
  next = exec->next;
  free(exec);
  nullify_exec(next);
  return (0);
}

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


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

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

original_code:
unsigned char nullify_pipes(t_pipes *pipes)
{
  free(pipes);
  return (0);
}

canonical_original_code:
unsigned char nullify_pipes(struct s_pipes *pipes)
{
  free(pipes);
  return (0);
}

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


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

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

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

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

original_code:
unsigned char nullify_words(t_get *word)
{
  t_get *next;
  next = word;
  while (next)
    {
      next = word->next;
      free(word->word);
      free(word);
      word = next;
    }
  return (0);
}

canonical_original_code:
unsigned char nullify_words(struct s_get *word)
{
  struct s_get *next;
  next = word;
  while (next)
    {
      next = word->next;
      free(word->word);
      free(word);
      word = next;
    }
  return (0);
}

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


decompiled_code:
__int64 __fastcall nullify_all_pipes(void **a1)
{
void *v1; // r12

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

canonical_decompiled_code:
__int64 __fastcall func3(void **a1)
{
void *v1; // r12

if ( !a1 )
return 0LL;
if ( a1[2] )
nullify_cmd();
else
func2(a1[1]);
v1 = *a1;
free(a1);
func3(v1);
return 0LL;
}

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

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

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

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


decompiled_code:
__int64 __fastcall nullify_all_in_pipes(void *ptr)
{
if ( *((_QWORD *)ptr + 2) )
nullify_cmd();
else
nullify_words(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
if ( *((_QWORD *)ptr + 2) )
nullify_cmd();
else
func2(*((void **)ptr + 1));
free(ptr);
return 0LL;
}

original_code:
unsigned char nullify_all_in_pipes(t_pipes *pipes)
{
  if (pipes->cmd)
    nullify_cmd(pipes->cmd);
  else
    nullify_words(pipes->tmp);
  free(pipes);
  return (0);
}

canonical_original_code:
unsigned char nullify_all_in_pipes(struct s_pipes *pipes)
{
  if (pipes->cmd)
    nullify_cmd(pipes->cmd);
  else
    nullify_words(pipes->tmp);
  free(pipes);
  return (0);
}


decompiled_code:
void env_i()
{
char **v0; // r8
char *v1; // rdi
__int64 v2; // rbx

v0 = environ;
if ( environ )
{
v1 = *environ;
if ( *environ )
{
v2 = 1LL;
do
{
free(v1);
v0 = environ;
v1 = environ[v2++];
}
while ( v1 );
}
free(v0);
environ = 0LL;
}
}

canonical_decompiled_code:
void func0()
{
char **v0; // r8
char *v1; // rdi
__int64 v2; // rbx

v0 = environ;
if ( environ )
{
v1 = *environ;
if ( *environ )
{
v2 = 1LL;
do
{
free(v1);
v0 = environ;
v1 = environ[v2++];
}
while ( v1 );
}
free(v0);
environ = 0LL;
}
}

original_code:
static void env_i(void)
{
  int i;
  i = 0;
  if (!environ)
    return ;
  while (environ[i])
    {
      free(environ[i]);
      i++;
    }
  free(environ);
  environ = ((void *)0);
}

canonical_original_code:
static void env_i()
{
  int i;
  i = 0;
  if (!environ)
    return ;
  while (environ[i])
    {
      free(environ[i]);
      i++;
    }
  free(environ);
  environ = ((void *)0);
}

variable_types: i int


decompiled_code:
char __fastcall env_u(_QWORD *a1)
{
char **v1; // rax
__int64 v3; // rbp
__int64 v4; // r13
__int64 v5; // rdx
__int64 v6; // r12
__int64 v7; // rax
int v8; // er8
char *v9; // r14
__int64 v10; // r8
__int64 v11; // rdi
__int64 v12; // r13
char **v13; // rax
__int64 v14; // r12
__int64 v15; // rbp
char *v16; // rdx
__int64 v17; // rax
int v18; // er8
char *v19; // r14
__int64 v20; // r8
char *v21; // rdi
char result; // al
_QWORD *v23; // rax

if ( !a1 )
return (unsigned __int8)print_err("env: option requires an argument -- 'u'\n") == 0;
v1 = environ;
if ( !environ )
return 1;
if ( !*environ )
{
v11 = 16LL;
goto LABEL_15;
}
v3 = 1LL;
v4 = 0LL;
while ( 1 )
{
v6 = v3;
if ( *a1 )
{
if ( v1[v6 - 1] )
{
v7 = ((__int64 (*)(void))my_strlen)();
v8 = my_strncmp(*a1, environ[v6 - 1], v7);
v1 = environ;
if ( !v8 )
break;
}
}
v5 = v3 + 1;
if ( !v1[v3] )
goto LABEL_13;
LABEL_6:
v3 = v5;
}
v9 = environ[v6 - 1];
v10 = my_strlen(*a1);
v1 = environ;
if ( v9[v10] == 34 )
v4 = 1LL;
v5 = v3 + 1;
if ( environ[v3] )
goto LABEL_6;
LABEL_13:
if ( v4 == v5 )
return (unsigned int)switch_env(0LL, 1LL) == 0;
v11 = 8 * (v3 - v4) + 16;
LABEL_15:
v12 = xmalloc(v11);
if ( v12 )
{
v13 = environ;
v14 = 0LL;
v15 = 0LL;
if ( *environ )
{
do
{
while ( 1 )
{
if ( *a1 )
{
v17 = my_strlen(*a1);
v18 = my_strncmp(*a1, environ[v15], v17);
v13 = environ;
if ( !v18 )
{
v19 = environ[v15];
v20 = my_strlen(*a1);
v13 = environ;
if ( v19[v20] == 61 )
break;
}
}
v16 = v13[v15++];
*(_QWORD *)(v12 + 8 * v14++) = v16;
if ( !v13[v15] )
goto LABEL_23;
}
v21 = environ[v15++];
free(v21);
v13 = environ;
}
while ( environ[v15] );
LABEL_23:
v23 = (_QWORD *)(v12 + 8 * v14);
}
else
{
v23 = (_QWORD *)v12;
}
*v23 = 0LL;
result = (unsigned int)switch_env(v12, 0LL) == 0;
}
else
{
environ = 0LL;
result = 0;
}
return result;
}

canonical_decompiled_code:
char __fastcall func1(_QWORD *a1)
{
char **v1; // rax
__int64 v3; // rbp
__int64 v4; // r13
__int64 v5; // rdx
__int64 v6; // r12
__int64 v7; // rax
int v8; // er8
char *v9; // r14
__int64 v10; // r8
__int64 v11; // rdi
__int64 v12; // r13
char **v13; // rax
__int64 v14; // r12
__int64 v15; // rbp
char *v16; // rdx
__int64 v17; // rax
int v18; // er8
char *v19; // r14
__int64 v20; // r8
char *v21; // rdi
char result; // al
_QWORD *v23; // rax

if ( !a1 )
return (unsigned __int8)print_err("env: option requires an argument -- 'u'\n") == 0;
v1 = environ;
if ( !environ )
return 1;
if ( !*environ )
{
v11 = 16LL;
goto LABEL_15;
}
v3 = 1LL;
v4 = 0LL;
while ( 1 )
{
v6 = v3;
if ( *a1 )
{
if ( v1[v6 - 1] )
{
v7 = ((__int64 (*)(void))my_strlen)();
v8 = my_strncmp(*a1, environ[v6 - 1], v7);
v1 = environ;
if ( !v8 )
break;
}
}
v5 = v3 + 1;
if ( !v1[v3] )
goto LABEL_13;
LABEL_6:
v3 = v5;
}
v9 = environ[v6 - 1];
v10 = my_strlen(*a1);
v1 = environ;
if ( v9[v10] == 34 )
v4 = 1LL;
v5 = v3 + 1;
if ( environ[v3] )
goto LABEL_6;
LABEL_13:
if ( v4 == v5 )
return (unsigned int)switch_env(0LL, 1LL) == 0;
v11 = 8 * (v3 - v4) + 16;
LABEL_15:
v12 = xmalloc(v11);
if ( v12 )
{
v13 = environ;
v14 = 0LL;
v15 = 0LL;
if ( *environ )
{
do
{
while ( 1 )
{
if ( *a1 )
{
v17 = my_strlen(*a1);
v18 = my_strncmp(*a1, environ[v15], v17);
v13 = environ;
if ( !v18 )
{
v19 = environ[v15];
v20 = my_strlen(*a1);
v13 = environ;
if ( v19[v20] == 61 )
break;
}
}
v16 = v13[v15++];
*(_QWORD *)(v12 + 8 * v14++) = v16;
if ( !v13[v15] )
goto LABEL_23;
}
v21 = environ[v15++];
free(v21);
v13 = environ;
}
while ( environ[v15] );
LABEL_23:
v23 = (_QWORD *)(v12 + 8 * v14);
}
else
{
v23 = (_QWORD *)v12;
}
*v23 = 0LL;
result = (unsigned int)switch_env(v12, 0LL) == 0;
}
else
{
environ = 0LL;
result = 0;
}
return result;
}

original_code:
static unsigned char env_u(t_words *cmd)
{
  char **tab;
  size_t i;
  size_t n;
  if (!cmd)
    return (!(unsigned char)print_err("env: option requires an argument -- 'u'\n"));
  if (environ == ((void*)(n = (i = 0))))
    return (1);
  while (environ[i++])
    if ((((cmd->word) && (environ[i - 1])) ? (!my_strncmp((cmd->word), (environ[i - 1]), my_strlen(cmd->word))) : (0))
 && environ[i - 1][my_strlen(cmd->word)] == '"')
      n = 1;
  if (i == n)
    return (!switch_env(((void *)0), 1));
  if ((tab = xmalloc(sizeof(char*) * (i - n + 1))) == ((void *)0))
    return ((long)(environ = ((void *)0)));
  n = (i = 0);
  while (environ[i])
    if (!((((cmd->word) && (environ[i])) ? (!my_strncmp((cmd->word), (environ[i]), my_strlen(cmd->word))) : (0)) && environ[i][my_strlen(cmd->word)]
   == '='))
      tab[n++] = environ[i++];
    else
      free(environ[i++]);
  tab[n] = ((void *)0);
  return (!switch_env(tab, 0));
}

canonical_original_code:
static unsigned char env_u(struct s_words *cmd)
{
  char **tab;
  unsigned long i;
  unsigned long n;
  if (!cmd)
    return (!(unsigned char)print_err("env: option requires an argument -- 'u'\n"));
  if (environ == ((void *)(n = (i = 0))))
    return (1);
  while (environ[i++])
    if ((((cmd->word) && (environ[i - 1])) ? (!my_strncmp((cmd->word), (environ[i - 1]), my_strlen(cmd->word))) : (0))
 && environ[i - 1][my_strlen(cmd->word)] == '"')
      n = 1;
  if (i == n)
    return (!switch_env(((void *)0), 1));
  if ((tab = xmalloc(sizeof(char *) * (i - n + 1))) == ((void *)0))
    return ((long)(environ = ((void *)0)));
  n = (i = 0);
  while (environ[i])
    if (!((((cmd->word) && (environ[i])) ? (!my_strncmp((cmd->word), (environ[i]), my_strlen(cmd->word))) : (0)) && environ[i][my_strlen(cmd->word)]
   == '='))
      tab[n++] = environ[i++];
    else
      free(environ[i++]);
  tab[n] = ((void *)0);
  return (!switch_env(tab, 0));
}

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

variable_types:
tab
char **

variable_types:
n
unsigned long


decompiled_code:
char __fastcall env_s(_QWORD *a1)
{
_QWORD *v1; // rax
int v2; // ebp
char *v3; // r12
char **v4; // rax
__int64 v5; // rbx
__int64 v6; // rax
bool v7; // zf
__int64 v8; // rbp
__int64 v9; // rax
char **v10; // rbx
char **v11; // rdi
__int64 v12; // rax
char *i; // rdx
char result; // al

if ( !a1 )
return (unsigned __int8)print_err("env: option requires two argument -- 'u'") == 0;
v1 = (_QWORD *)a1[1];
if ( !v1 )
return (unsigned __int8)print_err("env: option requires two argument -- 'u'") == 0;
v2 = 0;
v3 = (char *)my_stricat(*a1, *v1, 61LL);
v4 = environ;
if ( environ && *environ )
{
v5 = 0LL;
while ( 1 )
{
if ( *a1 )
{
v6 = my_strlen(*a1);
v7 = (unsigned int)my_strncmp(*a1, environ[v5], v6) == 0;
v4 = environ;
if ( v7 )
break;
}
++v5;
++v2;
if ( !v4[v5] )
goto LABEL_9;
}
free(environ[v5]);
environ[v5] = v3;
result = 1;
}
else
{
LABEL_9:
v8 = 8LL * (v2 + 2);
v9 = xmalloc(v8);
v10 = (char **)v9;
if ( v9 )
{
*(_QWORD *)(v9 + v8 - 8) = 0LL;
v11 = environ;
v12 = 0LL;
if ( environ )
{
for ( i = *environ; i; i = v11[v12] )
v10[v12++] = i;
}
v10[v12] = v3;
free(v11);
environ = v10;
result = 1;
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func2(_QWORD *a1)
{
_QWORD *v1; // rax
int v2; // ebp
char *v3; // r12
char **v4; // rax
__int64 v5; // rbx
__int64 v6; // rax
bool v7; // zf
__int64 v8; // rbp
__int64 v9; // rax
char **v10; // rbx
char **v11; // rdi
__int64 v12; // rax
char *i; // rdx
char result; // al

if ( !a1 )
return (unsigned __int8)print_err("env: option requires two argument -- 'u'") == 0;
v1 = (_QWORD *)a1[1];
if ( !v1 )
return (unsigned __int8)print_err("env: option requires two argument -- 'u'") == 0;
v2 = 0;
v3 = (char *)my_stricat(*a1, *v1, 61LL);
v4 = environ;
if ( environ && *environ )
{
v5 = 0LL;
while ( 1 )
{
if ( *a1 )
{
v6 = my_strlen(*a1);
v7 = (unsigned int)my_strncmp(*a1, environ[v5], v6) == 0;
v4 = environ;
if ( v7 )
break;
}
++v5;
++v2;
if ( !v4[v5] )
goto LABEL_9;
}
free(environ[v5]);
environ[v5] = v3;
result = 1;
}
else
{
LABEL_9:
v8 = 8LL * (v2 + 2);
v9 = xmalloc(v8);
v10 = (char **)v9;
if ( v9 )
{
*(_QWORD *)(v9 + v8 - 8) = 0LL;
v11 = environ;
v12 = 0LL;
if ( environ )
{
for ( i = *environ; i; i = v11[v12] )
v10[v12++] = i;
}
v10[v12] = v3;
free(v11);
environ = v10;
result = 1;
}
else
{
result = 0;
}
}
return result;
}

original_code:
static unsigned char env_s(t_words *cmd)
{
  char *line;
  int i;
  char **tab;
  if (!(cmd && cmd->next))
    return (!(unsigned char)print_err("env: option requires two argument -- 'u'"));
  line = my_stricat(cmd->word, cmd->next->word, '=');
  if ((i = -(environ != ((void *)0))))
    while (environ[++i])
      if (((((cmd->word) && (environ[i])) ? (!my_strncmp((cmd->word), (environ[i]), my_strlen(cmd->word))) : (0))) == 1)
 {
   free(environ[i]);
   environ[i] = line;
   return (1);
 }
  if ((tab = xmalloc(sizeof(char *) * (i + 2))) == ((void *)0))
    return (0);
  tab[i + 1] = ((void *)0);
  if ((i = -(environ != ((void *)0))))
    while (environ[++i] != ((void *)0))
      tab[i] = environ[i];
  tab[i] = line;
  free(environ);
  environ = tab;
  return (1);
}

canonical_original_code:
static unsigned char env_s(struct s_words *cmd)
{
  char *line;
  int i;
  char **tab;
  if (!(cmd && cmd->next))
    return (!(unsigned char)print_err("env: option requires two argument -- 'u'"));
  line = my_stricat(cmd->word, cmd->next->word, '=');
  if ((i = -(environ != ((void *)0))))
    while (environ[++i])
      if (((((cmd->word) && (environ[i])) ? (!my_strncmp((cmd->word), (environ[i]), my_strlen(cmd->word))) : (0))) == 1)
 {
   free(environ[i]);
   environ[i] = line;
   return (1);
 }
  if ((tab = xmalloc(sizeof(char *) * (i + 2))) == ((void *)0))
    return (0);
  tab[i + 1] = ((void *)0);
  if ((i = -(environ != ((void *)0))))
    while (environ[++i] != ((void *)0))
      tab[i] = environ[i];
  tab[i] = line;
  free(environ);
  environ = tab;
  return (1);
}

variable_types:
line
char *


decompiled_code:
__int64 __fastcall get_opt(_QWORD *a1, _QWORD *a2)
{
_QWORD *v2; // rbx

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

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

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

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; // er12
__int64 result; // rax
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

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

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

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

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:
bool
void *

variable_types: r int

variable_types:
save
char **


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 v13; // rax

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

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 v13; // rax

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

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

variable_types:
mod
char **

variable_types:
seek
char *

variable_types:
modif
char *[2]


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

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


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


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 *


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 v4; // rbx
__int64 v5; // rdi
__int64 result; // rax
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = 0LL;
v7[0] = 0LL;
remind_save_str(2, v7);
while ( 1 )
{
result = my_strlen(v7[0]);
if ( (int)result <= (int)v4 )
break;
v5 = (unsigned int)*(char *)(v7[0] + v4++);
add_letter_in_str(v5, a2, a3);
}
return result;
}

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

v4 = 0LL;
v7[0] = 0LL;
func0(2, v7);
while ( 1 )
{
result = my_strlen(v7[0]);
if ( (int)result <= (int)v4 )
break;
v5 = (unsigned int)*(char *)(v7[0] + v4++);
add_letter_in_str(v5, 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 func0(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_162);
}

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

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; // r12
char *v3; // rdi
char v4; // al
unsigned int v6; // ebp
__int64 v7; // rax
__int64 v8; // r13
void **v9; // rdi
void **v10; // rdi

if ( ptr )
{
v2 = (void **)ptr;
v3 = *(char **)ptr;
v4 = *v3;
if ( (*v3 == 34 || v4 == 39) && !*((_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_isra_0(v2[2]);
v9 = v2;
v2 = 0LL;
free(v9);
return v2;
}
free(*v2);
fill(v2, v8);
*((_BYTE *)v2 + 8) = 1;
}
if ( !comment(v2[2]) )
{
v10 = v2;
v2 = 0LL;
rm_word(v10);
}
return v2;
}
return (void **)a2;
}

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

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 v6; // r13
_QWORD *v7; // rax
__int64 v8; // rax
_QWORD *v10; // [rsp+8h] [rbp-40h] BYREF
char v11[41]; // [rsp+1Fh] [rbp-29h] BYREF

v10 = (_QWORD *)a1;
if ( !(unsigned __int8)lvl_parents(a2, a4) )
return 0LL;
v6 = v10[2];
if ( v6 )
*(_QWORD *)(v6 + 24) = 0LL;
rm_words();
v7 = *(_QWORD **)(*(_QWORD *)a2 + 24LL);
v10 = v7;
if ( !v7 )
return check_sintax_constprop_0(a4, 1);
if ( !*v7 )
goto LABEL_8;
if ( !(unsigned int)my_strcmp(*v7, "(") )
return check_sintax_constprop_0(a4, 1);
v7 = v10;
LABEL_8:
v7[2] = 0LL;
v10 = *(_QWORD **)(*(_QWORD *)a2 + 16LL);
rm_words();
v8 = orga(v6, a4, v11, 1LL);
*(_QWORD *)(a3 + 24) = v8;
if ( !v8 )
return check_sintax_constprop_0(a4, v11[0]);
while ( v10 )
{
if ( !(unsigned __int8)add_redir(v10, &v10, a4, a3) )
return 0LL;
}
return 1LL;
}

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

v10 = (_QWORD *)a1;
if ( !(unsigned __int8)lvl_parents(a2, a4) )
return 0LL;
v6 = v10[2];
if ( v6 )
*(_QWORD *)(v6 + 24) = 0LL;
rm_words();
v7 = *(_QWORD **)(*(_QWORD *)a2 + 24LL);
v10 = v7;
if ( !v7 )
return func0(a4, 1);
if ( !*v7 )
goto LABEL_8;
if ( !(unsigned int)my_strcmp(*v7, "(") )
return func0(a4, 1);
v7 = v10;
LABEL_8:
v7[2] = 0LL;
v10 = *(_QWORD **)(*(_QWORD *)a2 + 16LL);
rm_words();
v8 = orga(v6, a4, v11, 1LL);
*(_QWORD *)(a3 + 24) = v8;
if ( !v8 )
return func0(a4, v11[0]);
while ( v10 )
{
if ( !(unsigned __int8)add_redir(v10, &v10, a4, a3) )
return 0LL;
}
return 1LL;
}

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


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


decompiled_code:
__int64 __fastcall p_one(_QWORD *a1)
{
if ( !a1 )
return 1LL;
my_putstr("alias ", 1LL);
my_putstr(*a1, 1LL);
my_putstr("=\"", 1LL);
my_putstr(a1[1], 1LL);
my_putstr("\"\n", 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
if ( !a1 )
return 1LL;
my_putstr("alias ", 1LL);
my_putstr(*a1, 1LL);
my_putstr("=\"", 1LL);
my_putstr(a1[1], 1LL);
my_putstr("\"\n", 1LL);
return 0LL;
}

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; // r8
__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; // r8
__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);
}

variable_types:
s
char *


decompiled_code:
__int64 __fastcall get_n(__int64 *a1, _QWORD *a2, __int64 a3)
{
_QWORD *v4; // rbx
_QWORD *v5; // r12
__int64 v6; // rax

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, _QWORD *a2, __int64 a3)
{
_QWORD *v4; // rbx
_QWORD *v5; // r12
__int64 v6; // rax

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

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
_QWORD *v4; // rsi
__int64 result; // rax

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

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

v2 = *(__int64 **)(a1 + 8);
v4 = (_QWORD *)*a2;
if ( v2 )
result = func3(v2, v4, (__int64)a2);
else
result = func1(v4);
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)
{
_QWORD *v1; // rbx

if ( !a1 )
return 0LL;
v1 = a1;
do
{
p_one(v1);
v1 = (_QWORD *)v1[2];
}
while ( v1 );
return 0LL;
}

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

if ( !a1 )
return 0LL;
v1 = a1;
do
{
func0(v1);
v1 = (_QWORD *)v1[2];
}
while ( v1 );
return 0LL;
}

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

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

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

if ( !a1 )
return get_env("HOME");
result = *a1;
if ( *a1 )
{
if ( (unsigned int)my_strcmp(*a1, "-") )
result = *a1;
else
result = get_env("OLD_PWD");
}
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);
}


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

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; // rbp

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)
{
char **v1; // rbp
__int64 i; // rbx
__int64 v3; // r14
__int64 v4; // rax
__int64 v5; // r12
char **v6; // rax
__int64 v7; // rdx
char *v8; // rax
__int64 j; // rbx
__int64 v11; // rax
__int64 v12; // rax

v1 = environ;
if ( environ )
{
if ( *environ )
{
for ( i = 0LL; ; ++i )
{
v3 = i;
v4 = my_strlen(a1);
if ( !(unsigned int)my_strncmp(a1, environ[i], v4) )
return old_new((void **)&environ[v3], a1);
v1 = environ;
v5 = i + 1;
if ( !environ[v3 + 1] )
break;
}
v6 = (char **)xmalloc(8 * i + 24);
environ = v6;
v7 = (__int64)v6;
if ( !v6 )
return 0LL;
v6[v5] = 0LL;
v6[v5 + 1] = 0LL;
if ( v1 )
goto LABEL_9;
LABEL_16:
j = 0LL;
LABEL_11:
free(v1);
return old_new((void **)&environ[j], a1);
}
v12 = xmalloc(16LL);
environ = (char **)v12;
v7 = v12;
if ( v12 )
{
*(_QWORD *)v12 = 0LL;
*(_QWORD *)(v12 + 8) = 0LL;
LABEL_9:
v8 = *v1;
for ( j = 0LL; v8; v8 = v1[j] )
{
*(_QWORD *)(v7 + j * 8) = v8;
++j;
}
goto LABEL_11;
}
}
else
{
v11 = xmalloc(16LL);
environ = (char **)v11;
if ( v11 )
{
*(_QWORD *)v11 = 0LL;
*(_QWORD *)(v11 + 8) = 0LL;
goto LABEL_16;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
char **v1; // rbp
__int64 i; // rbx
__int64 v3; // r14
__int64 v4; // rax
__int64 v5; // r12
char **v6; // rax
__int64 v7; // rdx
char *v8; // rax
__int64 j; // rbx
__int64 v11; // rax
__int64 v12; // rax

v1 = environ;
if ( environ )
{
if ( *environ )
{
for ( i = 0LL; ; ++i )
{
v3 = i;
v4 = my_strlen(a1);
if ( !(unsigned int)my_strncmp(a1, environ[i], v4) )
return func1((void **)&environ[v3], a1);
v1 = environ;
v5 = i + 1;
if ( !environ[v3 + 1] )
break;
}
v6 = (char **)xmalloc(8 * i + 24);
environ = v6;
v7 = (__int64)v6;
if ( !v6 )
return 0LL;
v6[v5] = 0LL;
v6[v5 + 1] = 0LL;
if ( v1 )
goto LABEL_9;
LABEL_16:
j = 0LL;
LABEL_11:
free(v1);
return func1((void **)&environ[j], a1);
}
v12 = xmalloc(16LL);
environ = (char **)v12;
v7 = v12;
if ( v12 )
{
*(_QWORD *)v12 = 0LL;
*(_QWORD *)(v12 + 8) = 0LL;
LABEL_9:
v8 = *v1;
for ( j = 0LL; v8; v8 = v1[j] )
{
*(_QWORD *)(v7 + j * 8) = v8;
++j;
}
goto LABEL_11;
}
}
else
{
v11 = xmalloc(16LL);
environ = (char **)v11;
if ( v11 )
{
*(_QWORD *)v11 = 0LL;
*(_QWORD *)(v11 + 8) = 0LL;
goto LABEL_16;
}
}
return 0LL;
}

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; // rbp
char v3; // r8
_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; // rbp
char v3; // r8
_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 func1(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]);
}


decompiled_code:
__int64 __fastcall and_or(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // er13
__int64 v5; // rdi
unsigned int v6; // er12
int v8; // eax
__int64 v9; // rax
__int64 v10; // rdx
int v11; // eax
__int64 v12; // [rsp+8h] [rbp-40h] BYREF
int v13; // [rsp+10h] [rbp-38h]
int v14[13]; // [rsp+14h] [rbp-34h] BYREF

if ( !a1 )
return 1LL;
v3 = a3;
to_fd(v14, a3);
v5 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a2 + 96) = &v12;
v12 = 0x100000000LL;
v13 = 2;
v6 = exec_pipes(v5, a2, 0LL);
if ( !(_BYTE)v6 )
{
while ( waitpid(-1, 0LL, 1) >= 0 )
;
return v6;
}
fd_to(v14, v3);
if ( *(_DWORD *)a1 == 1 )
{
v11 = *(_DWORD *)(a2 + 104);
if ( v11 != 1 )
{
if ( v11 )
return 1LL;
LABEL_10:
v9 = two_isra_0(*(_QWORD *)(a1 + 8));
return (unsigned int)and_or(v9, a2, v10);
}
return (unsigned int)and_or(*(_QWORD *)(a1 + 8), a2, v3);
}
if ( *(_DWORD *)a1 == 2 )
{
v8 = *(_DWORD *)(a2 + 104);
if ( v8 )
{
if ( v8 != 1 )
return 1LL;
goto LABEL_10;
}
return (unsigned int)and_or(*(_QWORD *)(a1 + 8), a2, v3);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // er13
__int64 v5; // rdi
unsigned int v6; // er12
int v8; // eax
__int64 v9; // rax
__int64 v10; // rdx
int v11; // eax
__int64 v12; // [rsp+8h] [rbp-40h] BYREF
int v13; // [rsp+10h] [rbp-38h]
int v14[13]; // [rsp+14h] [rbp-34h] BYREF

if ( !a1 )
return 1LL;
v3 = a3;
func0(v14, a3);
v5 = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a2 + 96) = &v12;
v12 = 0x100000000LL;
v13 = 2;
v6 = exec_pipes(v5, a2, 0LL);
if ( !(_BYTE)v6 )
{
while ( waitpid(-1, 0LL, 1) >= 0 )
;
return v6;
}
func1(v14, v3);
if ( *(_DWORD *)a1 == 1 )
{
v11 = *(_DWORD *)(a2 + 104);
if ( v11 != 1 )
{
if ( v11 )
return 1LL;
LABEL_10:
v9 = func2(*(_QWORD *)(a1 + 8));
return (unsigned int)func3(v9, a2, v10);
}
return (unsigned int)func3(*(_QWORD *)(a1 + 8), a2, v3);
}
if ( *(_DWORD *)a1 == 2 )
{
v8 = *(_DWORD *)(a2 + 104);
if ( v8 )
{
if ( v8 != 1 )
return 1LL;
goto LABEL_10;
}
return (unsigned int)func3(*(_QWORD *)(a1 + 8), a2, v3);
}
return 1LL;
}

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 v3; // r14
unsigned __int8 v4; // r12
__int64 result; // rax
__int64 v6; // r14
__int64 v7; // [rsp-8h] [rbp-8h]

while ( a1 )
{
v7 = v3;
v4 = a3;
result = and_or(*(_QWORD *)(a1 + 16), a2, a3);
if ( !(_BYTE)result )
return result;
v6 = *(_QWORD *)(a1 + 8);
nullify_jobs(a1, 0LL);
a3 = v4;
a1 = v6;
v3 = v7;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned __int8 a3)
{
__int64 v3; // r14
unsigned __int8 v4; // r12
__int64 result; // rax
__int64 v6; // r14
__int64 v7; // [rsp-8h] [rbp-8h]

while ( a1 )
{
v7 = v3;
v4 = a3;
result = func3(*(_QWORD *)(a1 + 16), a2, a3);
if ( !(_BYTE)result )
return result;
v6 = *(_QWORD *)(a1 + 8);
nullify_jobs(a1, 0LL);
a3 = v4;
a1 = v6;
v3 = v7;
}
return 1LL;
}

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

if ( tcgetattr(0, termios_p) == -1 || tcgetattr(0, a2) == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(modify_terminal(termios_p) == -1);
return result;
}

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

if ( tcgetattr(0, termios_p) == -1 || tcgetattr(0, a2) == -1 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)-(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);
}


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, __int64 a3)
{
_QWORD *v4; // rdx
__int64 v5; // rax
__int64 v6; // rcx
__int64 result; // rax
__int64 (__fastcall *v8)(__int64, _DWORD *, __int64, __int64); // rax
__int64 v9; // [rsp+8h] [rbp-80h] BYREF
__int64 v10[15]; // [rsp+10h] [rbp-78h] BYREF

fill_tab(&v9);
my_strlen(*v4);
fill_fct_ptr(v10);
v6 = v5;
for ( result = 0LL; result != 8; ++result )
{
if ( *((_BYTE *)&v9 + result) == a1 )
{
v8 = (__int64 (__fastcall *)(__int64, _DWORD *, __int64, __int64))v10[(int)result];
if ( a1 != 51 )
return v8((unsigned int)a1, a2, a3, v6);
++*a2;
return v8(51LL, a2, a3, v6);
}
}
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 < (int)v6 )
{
result = (unsigned int)(result + 1);
*a2 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1, _DWORD *a2, __int64 a3)
{
_QWORD *v4; // rdx
__int64 v5; // rax
__int64 v6; // rcx
__int64 result; // rax
__int64 (__fastcall *v8)(__int64, _DWORD *, __int64, __int64); // rax
__int64 v9; // [rsp+8h] [rbp-80h] BYREF
__int64 v10[15]; // [rsp+10h] [rbp-78h] BYREF

func1(&v9);
my_strlen(*v4);
func0(v10);
v6 = v5;
for ( result = 0LL; result != 8; ++result )
{
if ( *((_BYTE *)&v9 + result) == a1 )
{
v8 = (__int64 (__fastcall *)(__int64, _DWORD *, __int64, __int64))v10[(int)result];
if ( a1 != 51 )
return v8((unsigned int)a1, a2, a3, v6);
++*a2;
return v8(51LL, a2, a3, v6);
}
}
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 < (int)v6 )
{
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 v2; // rax

if ( !a1 )
return 1LL;
v2 = get_exec(a1[3], 0LL, a2);
a1[2] = v2;
if ( !v2 )
return 0LL;
if ( (unsigned __int8)launch_exec(a1[1], a2) )
return 1LL;
return nullify_jobs(a1, 0LL);
}

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

if ( !a1 )
return 1LL;
v2 = get_exec(a1[3], 0LL, a2);
a1[2] = v2;
if ( !v2 )
return 0LL;
if ( (unsigned __int8)func0(a1[1], a2) )
return 1LL;
return nullify_jobs(a1, 0LL);
}

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)
{
char v3; // al
__int64 v4; // rdi
__int64 v6; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char v3; // al
__int64 v4; // rdi
__int64 v6; // rsi

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

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