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

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

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

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

original_code:
void *nullify_all_jobs(t_jobs *jobs)
{
  t_jobs *next;
  if (!jobs)
    return (((void *)0));
  if (jobs->exec)
    nullify_all_exec(jobs->exec);
  else
    nullify_words(jobs->tmp);
  next = jobs->next;
  free(jobs);
  nullify_all_jobs(next);
  return (((void *)0));
}

canonical_original_code:
void *nullify_all_jobs(struct s_jobs *jobs)
{
  struct s_jobs *next;
  if (!jobs)
    return (((void *)0));
  if (jobs->exec)
    nullify_all_exec(jobs->exec);
  else
    nullify_words(jobs->tmp);
  next = jobs->next;
  free(jobs);
  nullify_all_jobs(next);
  return (((void *)0));
}

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

return_type: void *

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

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

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

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


decompiled_code:
__int64 __fastcall nullify_jobs(void *ptr, char a2)
{
__int64 v3; // rdi

v3 = *((_QWORD *)ptr + 2);
if ( !a2 && v3 )
{
nullify_all_exec();
}
else if ( a2 )
{
nullify_exec(v3);
}
else
{
nullify_words(*((_QWORD *)ptr + 3));
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, char a2)
{
__int64 v3; // rdi

v3 = *((_QWORD *)ptr + 2);
if ( !a2 && v3 )
{
nullify_all_exec();
}
else if ( a2 )
{
nullify_exec(v3);
}
else
{
nullify_words(*((_QWORD *)ptr + 3));
}
free(ptr);
return 0LL;
}

original_code:
unsigned char nullify_jobs(t_jobs *jobs, unsigned char ex)
{
  if (jobs->exec && !ex)
    nullify_all_exec(jobs->exec);
  else if (!ex)
    nullify_words(jobs->tmp);
  if (ex)
    nullify_exec(jobs->exec);
  free(jobs);
  return (0);
}

canonical_original_code:
unsigned char nullify_jobs(struct s_jobs *jobs, unsigned char ex)
{
  if (jobs->exec && !ex)
    nullify_all_exec(jobs->exec);
  else if (!ex)
    nullify_words(jobs->tmp);
  if (ex)
    nullify_exec(jobs->exec);
  free(jobs);
  return (0);
}

variable_types:
ex
unsigned char

return_type: unsigned char

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

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


decompiled_code:
__int64 __fastcall nullify_cmd_words(void **a1)
{
void *v2; // rbp
void *v3; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = a1[1];
v3 = *a1;
if ( v3 )
free(v3);
free(a1);
result = nullify_cmd_words(v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void **a1)
{
void *v2; // rbp
void *v3; // rdi
__int64 result; // rax

if ( a1 )
{
v2 = a1[1];
v3 = *a1;
if ( v3 )
free(v3);
free(a1);
result = func2(v2);
}
return result;
}

original_code:
void nullify_cmd_words(t_words *s)
{
  t_words *n;
  if (!s)
    return ;
  n = s->next;
  if (s->word)
    free(s->word);
  free(s);
  nullify_cmd_words(n);
}

canonical_original_code:
void nullify_cmd_words(struct s_words *s)
{
  struct s_words *n;
  if (!s)
    return ;
  n = s->next;
  if (s->word)
    free(s->word);
  free(s);
  nullify_cmd_words(n);
}

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

return_type: void


decompiled_code:
__int64 __fastcall nullify_redir(_QWORD *a1)
{
__int64 v2; // rbp
void *v3; // rdi

if ( !a1 )
return 0LL;
v2 = a1[3];
v3 = (void *)a1[2];
if ( v3 )
free(v3);
free(a1);
nullify_redir(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v2; // rbp
void *v3; // rdi

if ( !a1 )
return 0LL;
v2 = a1[3];
v3 = (void *)a1[2];
if ( v3 )
free(v3);
free(a1);
func3(v2);
return 0LL;
}

original_code:
unsigned char nullify_redir(t_redir *r)
{
  t_redir *n;
  if (!r)
    return (0);
  n = r->next;
  if (r->file)
    free(r->file);
  free(r);
  nullify_redir(n);
  return (0);
}

canonical_original_code:
unsigned char nullify_redir(struct s_redir *r)
{
  struct s_redir *n;
  if (!r)
    return (0);
  n = r->next;
  if (r->file)
    free(r->file);
  free(r);
  nullify_redir(n);
  return (0);
}

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


decompiled_code:
__int64 __fastcall nullify_cmd(void *ptr)
{
void **v2; // rdi
_QWORD *v4; // rdi

if ( !ptr )
return 0LL;
v2 = (void **)*((_QWORD *)ptr + 2);
if ( v2 )
{
nullify_cmd_words(v2);
}
else
{
v4 = (_QWORD *)*((_QWORD *)ptr + 3);
if ( v4 )
nullify_all_jobs(v4);
}
if ( *(_QWORD *)ptr )
nullify_redir(*(_QWORD **)ptr);
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(void *ptr)
{
void **v2; // rdi
_QWORD *v4; // rdi

if ( !ptr )
return 0LL;
v2 = (void **)*((_QWORD *)ptr + 2);
if ( v2 )
{
func2(v2);
}
else
{
v4 = (_QWORD *)*((_QWORD *)ptr + 3);
if ( v4 )
func0(v4);
}
if ( *(_QWORD *)ptr )
func3(*(_QWORD **)ptr);
free(ptr);
return 0LL;
}

original_code:
unsigned char nullify_cmd(t_cmd *cmd)
{
  if (!cmd)
    return (0);
  if (cmd->params)
    nullify_cmd_words(cmd->params);
  else if (cmd->parents)
    nullify_all_jobs(cmd->parents);
  if (cmd->redir)
    nullify_redir(cmd->redir);
  free(cmd);
  return (0);
}

canonical_original_code:
unsigned char nullify_cmd(struct s_cmd *cmd)
{
  if (!cmd)
    return (0);
  if (cmd->params)
    nullify_cmd_words(cmd->params);
  else if (cmd->parents)
    nullify_all_jobs(cmd->parents);
  if (cmd->redir)
    nullify_redir(cmd->redir);
  free(cmd);
  return (0);
}

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


decompiled_code:
__int64 __fastcall del_letter_in_str(__int64 a1, _DWORD *a2, __int64 *a3)
{
__int64 result; // rax
__int64 v6; // rcx
_BYTE *v7; // rdx

result = (unsigned int)*a2;
if ( (int)result > 0 )
{
v6 = *a3;
v7 = (_BYTE *)(*a3 + (int)result - 1);
if ( *v7 )
{
result = (int)result;
do
{
*v7 = *(_BYTE *)(v6 + result);
v6 = *a3;
v7 = (_BYTE *)(*a3 + result++);
}
while ( *v7 );
}
result = my_putstr(&unk_2B8, 1LL);
--*a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, _DWORD *a2, __int64 *a3)
{
__int64 result; // rax
__int64 v6; // rcx
_BYTE *v7; // rdx

result = (unsigned int)*a2;
if ( (int)result > 0 )
{
v6 = *a3;
v7 = (_BYTE *)(*a3 + (int)result - 1);
if ( *v7 )
{
result = (int)result;
do
{
*v7 = *(_BYTE *)(v6 + result);
v6 = *a3;
v7 = (_BYTE *)(*a3 + result++);
}
while ( *v7 );
}
result = my_putstr(&unk_2B8, 1LL);
--*a2;
}
return result;
}

original_code:
void del_letter_in_str(char value, int *reverse_case, char **cmd)
{
  int suppr;
  (void)value;
  suppr = (*reverse_case) - 1;
  if ((*reverse_case) > 0)
    {
      while ((*cmd)[suppr] != '\0')
        {
          (*cmd)[suppr] = (*cmd)[suppr + 1];
          suppr++;
        }
      my_putstr("\r", 1);
      (*reverse_case)--;
    }
}

variable_types: value char

variable_types:
cmd
char **

variable_types: suppr int


original_code:
int add_letter_in_str(char value, int *reverse_case, char **cmd)
{
  int len;
  len = my_strlen(*cmd) + 1;
  while (--len > (*reverse_case))
    (*cmd)[len + 1] = (*cmd)[len];
  if (my_strlen(*cmd) + 1 > 1)
    (*cmd)[len + 1] = (*cmd)[len];
  (*cmd)[len] = value;
  (*reverse_case)++;
  if (((*cmd) = my_realloc(*cmd,
      my_strlen(*cmd), my_strlen(*cmd) + 2)) == ((void *)0))
    return (-1);
  (*cmd)[my_strlen(*cmd) + 1] = '\0';
  return (0);
}

variable_types: len int

return_type: int


decompiled_code:
__int64 __fastcall modif_cmd(__int64 *a1, char *a2, _DWORD *a3)
{
char v5; // di
char *v6; // rax
unsigned int v7; // ebx
char *v8; // r14
char v10[14]; // [rsp+2h] [rbp-B6h] BYREF
__int64 v11[21]; // [rsp+10h] [rbp-A8h] BYREF

fill_tab(v10);
fill_fct_ptr(v11);
v5 = *a2;
v6 = v10;
v7 = 0;
while ( *v6 != v5 )
{
++v7;
++v6;
if ( v7 == 14 )
{
v8 = a2;
while ( *v8 > 31 )
{
v7 = add_letter_in_str(*v8, a3, a1);
if ( v7 == -1 )
return v7;
if ( ++v8 == a2 + 4 )
return 0;
}
return 0;
}
}
if ( v7 )
{
if ( v7 - 8 <= 1 || v7 == 13 )
{
((void (__fastcall *)(_QWORD, _DWORD *, __int64 *))v11[v7])((unsigned int)v5, a3, a1);
return 0;
}
}
else if ( !a2[2] )
{
((void (__fastcall *)(_QWORD, _DWORD *, __int64 *))v11[0])((unsigned int)a2[1], a3, a1);
return v7;
}
((void (__fastcall *)(_QWORD, _DWORD *, __int64 *))v11[v7])((unsigned int)a2[2], a3, a1);
return 0;
}

original_code:
int modif_cmd(char **cmd, char *str, int *reverse_case)
{
  int i;
  void (*options[15])(char, int *, char **);
  char opt[14];
  i = -1;
  fill_tab(opt);
  fill_fct_ptr(options);
  while (++i < 14 && opt[i] != str[0]);
  if (i != 14)
    if (i == 0 && str[2] == 0)
      (options[i])(str[1], reverse_case, cmd);
    else if (i == 8 || i == 9 || i == 13)
      (options[i])(str[0], reverse_case, cmd);
    else
      (options[i])(str[2], reverse_case, cmd);
  else
    {
      i = -1;
      while (++i < 4 && str[i] >= ' ')
 if (add_letter_in_str(str[i], reverse_case, cmd) == -1)
   return (-1);
    }
  return (0);
}

variable_types:
str
char *

variable_types: i int

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

variable_types:
opt
char [14]


decompiled_code:
__int64 __fastcall my_strnslen(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx

v4 = 0LL;
if ( *a1 )
{
do
{
if ( !(unsigned int)my_strncmp(a2, &a1[v4], a3) )
break;
++v4;
}
while ( a1[v4] );
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, __int64 a2, __int64 a3)
{
__int64 v4; // rbx

v4 = 0LL;
if ( *a1 )
{
do
{
if ( !(unsigned int)my_strncmp(a2, &a1[v4], a3) )
break;
++v4;
}
while ( a1[v4] );
}
return v4;
}

original_code:
size_t my_strnslen(const char *s, const char *c, size_t n)
{
  size_t i;
  i = 0;
  while (s[i] && my_strncmp(c, s + i, n))
    i++;
  return (i);
}

canonical_original_code:
unsigned long my_strnslen(char *s, char *c, unsigned long n)
{
  unsigned long i;
  i = 0;
  while (s[i] && my_strncmp(c, s + i, n))
    i++;
  return (i);
}

variable_types:
s
char *

variable_types:
c
char *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

return_type: unsigned long


decompiled_code:
char __fastcall recur_match(_BYTE *a1, _BYTE *a2, __int64 a3)
{
char result; // al
int v5; // edx
unsigned __int64 v6; // r12
unsigned __int64 v7; // rax
__int64 v8; // r12
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // r12
__int64 v13; // rax
__int64 v14; // r14
_BYTE *v15; // rbp
__int64 v16; // rax

if ( *a1 || (result = 1, *a2) && (v5 = my_strcmp(a2, &unk_3BA), result = 1, v5) )
{
result = 1;
if ( a3 )
{
if ( a2[my_strilen(a2, 42LL)] )
{
v10 = my_strilen(a2, 42LL);
v11 = my_strnslen(a1, (__int64)a2, v10);
result = 0;
if ( a1[v11] )
{
v12 = my_strilen(a2, 42LL);
v13 = my_strilen(a2, 42LL);
v14 = my_strnslen(a1, (__int64)a2, v13);
v15 = &a1[my_strilen(a2, 42LL) + v14];
v16 = my_strilen(a2, 42LL);
result = recur_match(v15, &a2[v12 + (a2[v16] != 0)], a3 - v12 - (a2[v16] != 0));
}
}
else
{
v6 = my_strlen(a1);
v7 = my_strlen(a2);
if ( a2 && v6 >= v7 )
{
my_strlen(a1);
my_strlen(a2);
v8 = my_strlen(a1);
v9 = my_strlen(a2);
result = (unsigned int)my_strcmp(a2, &a1[v8 - v9]) == 0;
}
else
{
result = 0;
}
}
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func1(_BYTE *a1, _BYTE *a2, __int64 a3)
{
char result; // al
int v5; // edx
unsigned __int64 v6; // r12
unsigned __int64 v7; // rax
__int64 v8; // r12
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rdx
__int64 v12; // r12
__int64 v13; // rax
__int64 v14; // r14
_BYTE *v15; // rbp
__int64 v16; // rax

if ( *a1 || (result = 1, *a2) && (v5 = my_strcmp(a2, &unk_3BA), result = 1, v5) )
{
result = 1;
if ( a3 )
{
if ( a2[my_strilen(a2, 42LL)] )
{
v10 = my_strilen(a2, 42LL);
v11 = func0(a1, (__int64)a2, v10);
result = 0;
if ( a1[v11] )
{
v12 = my_strilen(a2, 42LL);
v13 = my_strilen(a2, 42LL);
v14 = func0(a1, (__int64)a2, v13);
v15 = &a1[my_strilen(a2, 42LL) + v14];
v16 = my_strilen(a2, 42LL);
result = func1(v15, &a2[v12 + (a2[v16] != 0)], a3 - v12 - (a2[v16] != 0));
}
}
else
{
v6 = my_strlen(a1);
v7 = my_strlen(a2);
if ( a2 && v6 >= v7 )
{
my_strlen(a1);
my_strlen(a2);
v8 = my_strlen(a1);
v9 = my_strlen(a2);
result = (unsigned int)my_strcmp(a2, &a1[v8 - v9]) == 0;
}
else
{
result = 0;
}
}
}
}
return result;
}

original_code:
static unsigned char recur_match(const char *s, const char *c, size_t n)
{
  size_t l;
  unsigned char k;
  if ((!s[0] && (!c[0] || ((c && "*") ? (!my_strcmp(c, "*")) : (0)))) || n <= 0)
    return (1);
  if (!((c)[my_strilen(c, '*')] != 0))
    {
      if (my_strlen(s) < my_strlen(c))
 return (0);
      if (((c && s + my_strlen(s) - my_strlen(c)) ? (!my_strcmp(c, s + my_strlen(s) - my_strlen(c))) : (0)))
 return (1);
      else
 return (0);
    }
  if (!((s)[my_strnslen(s, c, my_strilen(c, '*'))] != 0))
    return (0);
  l = my_strilen(c, '*');
  s += my_strnslen(s, c, my_strilen(c, '*')) + my_strilen(c, '*');
  c += l + (k = ((c)[my_strilen(c, '*')] != 0));
  return (recur_match(s, c, n - l - k));
}

canonical_original_code:
static unsigned char recur_match(char *s, char *c, unsigned long n)
{
  unsigned long l;
  unsigned char k;
  if ((!s[0] && (!c[0] || ((c && "*") ? (!my_strcmp(c, "*")) : (0)))) || n <= 0)
    return (1);
  if (!((c)[my_strilen(c, '*')] != 0))
    {
      if (my_strlen(s) < my_strlen(c))
 return (0);
      if (((c && s + my_strlen(s) - my_strlen(c)) ? (!my_strcmp(c, s + my_strlen(s) - my_strlen(c))) : (0)))
 return (1);
      else
 return (0);
    }
  if (!((s)[my_strnslen(s, c, my_strilen(c, '*'))] != 0))
    return (0);
  l = my_strilen(c, '*');
  s += my_strnslen(s, c, my_strilen(c, '*')) + my_strilen(c, '*');
  c += l + (k = ((c)[my_strilen(c, '*')] != 0));
  return (recur_match(s, c, n - l - k));
}

variable_types:
l
unsigned long

variable_types:
k
unsigned char


decompiled_code:
__int64 __fastcall last_occur(char *a1, char a2, char a3)
{
char v4; // al
__int64 v5; // rcx
__int64 v6; // rdx

v4 = *a1;
if ( *a1 == a3 || !v4 )
return 0LL;
v5 = 0LL;
v6 = 0LL;
do
{
if ( a2 == v4 )
v5 = v6;
v4 = a1[++v6];
}
while ( v4 != a3 && v4 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char a2, char a3)
{
char v4; // al
__int64 v5; // rcx
__int64 v6; // rdx

v4 = *a1;
if ( *a1 == a3 || !v4 )
return 0LL;
v5 = 0LL;
v6 = 0LL;
do
{
if ( a2 == v4 )
v5 = v6;
v4 = a1[++v6];
}
while ( v4 != a3 && v4 );
return v5;
}

original_code:
size_t last_occur(const char *s, char c, char e)
{
  size_t i;
  size_t l;
  i = 0;
  l = 0;
  while (s[i] && s[i] != e)
    {
      if (s[i] == c)
 l = i;
      i++;
    }
  return (l);
}

canonical_original_code:
unsigned long last_occur(char *s, char c, char e)
{
  unsigned long i;
  unsigned long l;
  i = 0;
  l = 0;
  while (s[i] && s[i] != e)
    {
      if (s[i] == c)
 l = i;
      i++;
    }
  return (l);
}

variable_types: c char

variable_types: e char


match

decompiled_code:
char __fastcall match(__int64 a1, __int64 a2)
{
char result; // al
__int64 v3; // rax
int v4; // edx
__int64 v5; // r13
__int64 v6; // r13
__int64 v7; // r13
__int64 v8; // r12
_BYTE *v9; // r12
__int64 v10; // rax

if ( !a1 )
return 0;
result = 0;
if ( a2 )
{
v3 = my_strilen(a2, 42LL);
v4 = my_strncmp(a1, a2, v3);
result = 0;
if ( !v4 )
{
v5 = my_strlen(a2);
v6 = v5 - my_strilen(a2, 42LL);
v7 = (*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) + v6 - 1;
v8 = my_strilen(a2, 42LL);
v9 = (_BYTE *)(a2 + v8 - ((*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) - 1LL));
v10 = my_strilen(a2, 42LL);
result = recur_match((_BYTE *)(a1 + v10), v9, v7);
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(__int64 a1, __int64 a2)
{
char result; // al
__int64 v3; // rax
int v4; // edx
__int64 v5; // r13
__int64 v6; // r13
__int64 v7; // r13
__int64 v8; // r12
_BYTE *v9; // r12
__int64 v10; // rax

if ( !a1 )
return 0;
result = 0;
if ( a2 )
{
v3 = my_strilen(a2, 42LL);
v4 = my_strncmp(a1, a2, v3);
result = 0;
if ( !v4 )
{
v5 = my_strlen(a2);
v6 = v5 - my_strilen(a2, 42LL);
v7 = (*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) + v6 - 1;
v8 = my_strilen(a2, 42LL);
v9 = (_BYTE *)(a2 + v8 - ((*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) - 1LL));
v10 = my_strilen(a2, 42LL);
result = func1((_BYTE *)(a1 + v10), v9, v7);
}
}
return result;
}

original_code:
unsigned char match(const char *s, const char *c)
{
  if (!(s && c))
    return (0);
  if (!(((s) && (c)) ? (!my_strncmp((s), (c), my_strilen(c, '*'))) : (0)))
    return (0);
  return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*')
        + ((c)[my_strilen(c, '*')] != 0), my_strlen(c) - my_strilen(c, '*')
        - ((c)[my_strilen(c, '*')] != 0)));
}

canonical_original_code:
unsigned char match(char *s, char *c)
{
  if (!(s && c))
    return (0);
  if (!(((s) && (c)) ? (!my_strncmp((s), (c), my_strilen(c, '*'))) : (0)))
    return (0);
  return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*')
        + ((c)[my_strilen(c, '*')] != 0), my_strlen(c) - my_strilen(c, '*')
        - ((c)[my_strilen(c, '*')] != 0)));
}


nmatch

decompiled_code:
char __fastcall nmatch(__int64 a1, __int64 a2, unsigned __int64 a3)
{
char result; // al
int v5; // edx
__int64 v6; // rax
int v7; // edx
unsigned __int64 v8; // r12
__int64 v9; // r12
__int64 v10; // r13
_BYTE *v11; // r13
__int64 v12; // rax

if ( !a1 )
return 0;
result = 0;
if ( a2 )
{
if ( my_strilen(a2, 42LL) <= a3 || (v5 = my_strncmp(a1, a2, a3), result = 1, v5) )
{
v6 = my_strilen(a2, 42LL);
v7 = my_strncmp(a1, a2, v6);
result = 0;
if ( !v7 )
{
v8 = a3 - my_strilen(a2, 42LL);
v9 = (*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) + v8 - 1;
v10 = my_strilen(a2, 42LL);
v11 = (_BYTE *)(a2 + v10 - ((*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) - 1LL));
v12 = my_strilen(a2, 42LL);
result = recur_match((_BYTE *)(a1 + v12), v11, v9);
}
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func4(__int64 a1, __int64 a2, unsigned __int64 a3)
{
char result; // al
int v5; // edx
__int64 v6; // rax
int v7; // edx
unsigned __int64 v8; // r12
__int64 v9; // r12
__int64 v10; // r13
_BYTE *v11; // r13
__int64 v12; // rax

if ( !a1 )
return 0;
result = 0;
if ( a2 )
{
if ( my_strilen(a2, 42LL) <= a3 || (v5 = my_strncmp(a1, a2, a3), result = 1, v5) )
{
v6 = my_strilen(a2, 42LL);
v7 = my_strncmp(a1, a2, v6);
result = 0;
if ( !v7 )
{
v8 = a3 - my_strilen(a2, 42LL);
v9 = (*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) + v8 - 1;
v10 = my_strilen(a2, 42LL);
v11 = (_BYTE *)(a2 + v10 - ((*(_BYTE *)(a2 + my_strilen(a2, 42LL)) == 0) - 1LL));
v12 = my_strilen(a2, 42LL);
result = func1((_BYTE *)(a1 + v12), v11, v9);
}
}
}
return result;
}

original_code:
unsigned char nmatch(const char *s, const char *c, size_t n)
{
  if (!(s && c))
    return (0);
  if (n < my_strilen(c, '*') && (((s) && (c)) ? (!my_strncmp((s), (c), n)) : (0)))
    return (1);
  if (!(((s) && (c)) ? (!my_strncmp((s), (c), my_strilen(c, '*'))) : (0)))
    return (0);
  return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*')
        + ((c)[my_strilen(c, '*')] != 0), n - my_strilen(c, '*')
        - ((c)[my_strilen(c, '*')] != 0)));
}

canonical_original_code:
unsigned char nmatch(char *s, char *c, unsigned long n)
{
  if (!(s && c))
    return (0);
  if (n < my_strilen(c, '*') && (((s) && (c)) ? (!my_strncmp((s), (c), n)) : (0)))
    return (1);
  if (!(((s) && (c)) ? (!my_strncmp((s), (c), my_strilen(c, '*'))) : (0)))
    return (0);
  return (recur_match(s + my_strilen(c, '*'), c + my_strilen(c, '*')
        + ((c)[my_strilen(c, '*')] != 0), n - my_strilen(c, '*')
        - ((c)[my_strilen(c, '*')] != 0)));
}


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

if ( a1 )
{
if ( a3 && *a1 && (v4 = my_strlen(a3), !(unsigned int)my_strncmp(a3, *a1, v4)) )
*a2 = my_strdup(*a1);
else
seek_seek(a1[2], a2, a3);
}
}

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

if ( a1 )
{
if ( a3 && *a1 && (v4 = my_strlen(a3), !(unsigned int)my_strncmp(a3, *a1, v4)) )
*a2 = my_strdup(*a1);
else
func0(a1[2], a2, a3);
}
}

original_code:
static void seek_seek(t_history *hist, char **fill, char *seek)
{
  if (!hist)
    return ;
  if ((((seek) && (hist->str)) ? (!my_strncmp((seek), (hist->str), my_strlen(seek))) : (0)))
    {
      *fill = my_strdup(hist->str);
      return ;
    }
  seek_seek(hist->next, fill, seek);
}

canonical_original_code:
static void seek_seek(struct s_history *hist, char **fill, char *seek)
{
  if (!hist)
    return ;
  if ((((seek) && (hist->str)) ? (!my_strncmp((seek), (hist->str), my_strlen(seek))) : (0)))
    {
      *fill = my_strdup(hist->str);
      return ;
    }
  seek_seek(hist->next, fill, seek);
}

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

variable_types:
fill
char **

variable_types:
seek
char *


decompiled_code:
__int64 __fastcall seek_for(_QWORD *a1, _QWORD *a2, int a3, int a4)
{
unsigned int v5; // er13

if ( !a1 )
return 0;
if ( a3 >= 0 || a3 + a4 )
{
v5 = seek_for(a1[2], a2, (unsigned int)a3, (unsigned int)(a4 + 1)) + 1;
if ( a3 == v5 && !*a2 )
*a2 = my_strdup(*a1);
}
else
{
*a2 = my_strdup(*a1);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _QWORD *a2, int a3, int a4)
{
unsigned int v5; // er13

if ( !a1 )
return 0;
if ( a3 >= 0 || a3 + a4 )
{
v5 = func1(a1[2], a2, (unsigned int)a3, (unsigned int)(a4 + 1)) + 1;
if ( a3 == v5 && !*a2 )
*a2 = my_strdup(*a1);
}
else
{
*a2 = my_strdup(*a1);
v5 = 0;
}
return v5;
}

original_code:
static int seek_for(t_history *hist, char **fill, int sn, int n)
{
  int nr;
  if (!hist)
    return (0);
  if (sn < 0 && -sn == n)
    *fill = my_strdup(hist->str);
  if (sn < 0 && -sn == n)
    return (0);
  nr = seek_for(hist->next, fill, sn, n + 1) + 1;
  if (nr == sn && !*fill)
    *fill = my_strdup(hist->str);
  return (nr);
}

canonical_original_code:
static int seek_for(struct s_history *hist, char **fill, int sn, int n)
{
  int nr;
  if (!hist)
    return (0);
  if (sn < 0 && -sn == n)
    *fill = my_strdup(hist->str);
  if (sn < 0 && -sn == n)
    return (0);
  nr = seek_for(hist->next, fill, sn, n + 1) + 1;
  if (nr == sn && !*fill)
    *fill = my_strdup(hist->str);
  return (nr);
}

variable_types: sn int

variable_types: n int

variable_types: nr int

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


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

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

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

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

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

variable_types:
fill
char *

variable_types:
mod
char **

variable_types:
modif
char *[2]


canonical_original_code:
unsigned char grow_hist(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 (((("/!\\ \t(;|&")[my_strilen("/!\\ \t(;|&", s[1])] != 0) || !s[1]) || (n && s[-1] == '\\'))
    return (grow_hist(s + 1 + my_sstrlen(s + 1, "$~"), mod, n +
       1 + my_sstrlen(s + 1, "$~"), info));
  seek = ((void *)0);
  if (s[0] == '!' && !(("-+0123456789")[my_strilen("-+0123456789", s[1])] != 0))
    seek = my_strndup(s + 1, my_sstrlen(s + 1, " \"\t(;|&"));
  else
    seek = my_strndup(s + 1, (("+-")[my_strilen("+-", s[1])] != 0)
        + lenmatch(s + 1 + (("+-")[my_strilen("+-", s[1])] != 0), "0123456789"));
  if ((fill = fill_it(seek, info, mod)) == ((void *)0))
    return (0);
  if (mod_var(s, fill, mod, seek) == 0)
    return (0);
  s = *mod + n + my_strlen(fill);
  n += my_strlen(fill);
  free(fill);
  free(seek);
  return (1 + grow_hist(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; } *

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:
unsigned __int64 __fastcall plus_seq(__int64 a1, int a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
int v5; // edi
char v6; // al
int v8; // eax
unsigned __int8 v9; // si

if ( a2 != 8 )
{
if ( a2 != 16 )
return 0LL;
v4 = 1LL;
v5 = 0;
if ( !a3 )
return 0LL;
while ( 1 )
{
v8 = *(unsigned __int8 *)(a1 + v4 - 1);
v9 = v8 - 48;
if ( (unsigned __int8)(v8 - 97) > 5u && v9 > 9u )
break;
if ( v9 <= 9u )
{
v5 = v8 + 16 * v5 - 48;
goto LABEL_13;
}
if ( (unsigned __int8)(v8 - 65) <= 5u )
goto LABEL_18;
v5 = v8 + 16 * v5 - 87;
LABEL_13:
if ( v4 >= a3 )
goto LABEL_8;
++v4;
}
if ( (unsigned __int8)(v8 - 65) > 5u )
{
--v4;
LABEL_22:
if ( v4 )
goto LABEL_8;
return v4;
}
LABEL_18:
v5 = v8 + 16 * v5 - 55;
goto LABEL_13;
}
v4 = 0LL;
LOBYTE(v5) = 0;
if ( !a3 )
return 0LL;
do
{
v6 = *(_BYTE *)(a1 + v4);
if ( (unsigned __int8)(v6 - 48) > 7u )
goto LABEL_22;
++v4;
LOBYTE(v5) = v6 + 8 * v5 - 48;
}
while ( a3 != v4 );
LABEL_8:
my_putchar((unsigned int)(char)v5, 1LL);
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, int a2, unsigned __int64 a3)
{
unsigned __int64 v4; // rbx
int v5; // edi
char v6; // al
int v8; // eax
unsigned __int8 v9; // si

if ( a2 != 8 )
{
if ( a2 != 16 )
return 0LL;
v4 = 1LL;
v5 = 0;
if ( !a3 )
return 0LL;
while ( 1 )
{
v8 = *(unsigned __int8 *)(a1 + v4 - 1);
v9 = v8 - 48;
if ( (unsigned __int8)(v8 - 97) > 5u && v9 > 9u )
break;
if ( v9 <= 9u )
{
v5 = v8 + 16 * v5 - 48;
goto LABEL_13;
}
if ( (unsigned __int8)(v8 - 65) <= 5u )
goto LABEL_18;
v5 = v8 + 16 * v5 - 87;
LABEL_13:
if ( v4 >= a3 )
goto LABEL_8;
++v4;
}
if ( (unsigned __int8)(v8 - 65) > 5u )
{
--v4;
LABEL_22:
if ( v4 )
goto LABEL_8;
return v4;
}
LABEL_18:
v5 = v8 + 16 * v5 - 55;
goto LABEL_13;
}
v4 = 0LL;
LOBYTE(v5) = 0;
if ( !a3 )
return 0LL;
do
{
v6 = *(_BYTE *)(a1 + v4);
if ( (unsigned __int8)(v6 - 48) > 7u )
goto LABEL_22;
++v4;
LOBYTE(v5) = v6 + 8 * v5 - 48;
}
while ( a3 != v4 );
LABEL_8:
my_putchar((unsigned int)(char)v5, 1LL);
return v4;
}

original_code:
static size_t plus_seq(char *seq, int mult, size_t l)
{
  unsigned char n;
  size_t i;
  n = 0;
  i = 0;
  if (mult == 8)
    while (i < l && (seq[i] >= '0' && seq[i] < '8'))
      n = n * mult + seq[i++] - '0';
  if (mult == 16)
    while (i < l && ((seq[i] >= '0' && seq[i] <= '9') ||
       (seq[i] >= 'a' && seq[i] <= 'f') ||
       (seq[i] >= 'A' && seq[i] <= 'F')))
      if (seq[i] >= '0' && seq[i] <= '9')
 n = n * mult + seq[i++] - '0';
      else if (seq[i] >= 'A' && seq[i] <= 'F')
 n = n * mult + seq[i++] - 'A' + 10;
      else
 n = n * mult + seq[i++] - 'a' + 10;
  if (i)
    my_putchar((unsigned char)n, 1);
  return (i);
}

canonical_original_code:
static unsigned long plus_seq(char *seq, int mult, unsigned long l)
{
  unsigned char n;
  unsigned long i;
  n = 0;
  i = 0;
  if (mult == 8)
    while (i < l && (seq[i] >= '0' && seq[i] < '8'))
      n = n * mult + seq[i++] - '0';
  if (mult == 16)
    while (i < l && ((seq[i] >= '0' && seq[i] <= '9') ||
       (seq[i] >= 'a' && seq[i] <= 'f') ||
       (seq[i] >= 'A' && seq[i] <= 'F')))
      if (seq[i] >= '0' && seq[i] <= '9')
 n = n * mult + seq[i++] - '0';
      else if (seq[i] >= 'A' && seq[i] <= 'F')
 n = n * mult + seq[i++] - 'A' + 10;
      else
 n = n * mult + seq[i++] - 'a' + 10;
  if (i)
    my_putchar((unsigned char)n, 1);
  return (i);
}

variable_types:
seq
char *

variable_types: mult int

variable_types:
n
unsigned char


decompiled_code:
__int64 __fastcall print_seq2(char *a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rax
int v4; // ebp
__int64 v5; // rax
__int64 v6; // rax

if ( !a1 )
return my_putchar((unsigned int)*a1, 1LL);
v2 = my_strlen(&unk_3E2);
if ( !(unsigned int)my_strncmp(&unk_3E2, a1, v2) )
return my_putchar(10LL, 1LL) + 1;
v3 = my_strlen(&unk_3EB);
v4 = a2 & 4;
if ( !(v4 | (unsigned int)my_strncmp(&unk_3EB, a1, v3)) )
return my_putchar(13LL, 1LL) + 1;
v5 = my_strlen(&unk_3E8);
if ( !(v4 | (unsigned int)my_strncmp(&unk_3E8, a1, v5)) )
return my_putchar(9LL, 1LL) + 1;
v6 = my_strlen(&unk_3E5);
if ( v4 | (unsigned int)my_strncmp(&unk_3E5, a1, v6) )
return my_putchar((unsigned int)*a1, 1LL);
return my_putchar(11LL, 1LL) + 1;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, char a2)
{
__int64 v2; // rax
__int64 v3; // rax
int v4; // ebp
__int64 v5; // rax
__int64 v6; // rax

if ( !a1 )
return my_putchar((unsigned int)*a1, 1LL);
v2 = my_strlen(&unk_3E2);
if ( !(unsigned int)my_strncmp(&unk_3E2, a1, v2) )
return my_putchar(10LL, 1LL) + 1;
v3 = my_strlen(&unk_3EB);
v4 = a2 & 4;
if ( !(v4 | (unsigned int)my_strncmp(&unk_3EB, a1, v3)) )
return my_putchar(13LL, 1LL) + 1;
v5 = my_strlen(&unk_3E8);
if ( !(v4 | (unsigned int)my_strncmp(&unk_3E8, a1, v5)) )
return my_putchar(9LL, 1LL) + 1;
v6 = my_strlen(&unk_3E5);
if ( v4 | (unsigned int)my_strncmp(&unk_3E5, a1, v6) )
return my_putchar((unsigned int)*a1, 1LL);
return my_putchar(11LL, 1LL) + 1;
}

canonical_original_code:
static unsigned long print_seq2(char *seq, unsigned int echo)
{
  if (((("\\n") && (seq)) ? (!my_strncmp(("\\n"), (seq), my_strlen("\\n"))) : (0)))
    return (1 + my_putchar('\n', 1));
  else if (((("\\r") && (seq)) ? (!my_strncmp(("\\r"), (seq), my_strlen("\\r"))) : (0)) && !(echo & 4))
    return (1 + my_putchar('\r', 1));
  else if (((("\\t") && (seq)) ? (!my_strncmp(("\\t"), (seq), my_strlen("\\t"))) : (0)) && !(echo & 4))
    return (1 + my_putchar('\t', 1));
  else if (((("\\v") && (seq)) ? (!my_strncmp(("\\v"), (seq), my_strlen("\\v"))) : (0)) && !(echo & 4))
    return (1 + my_putchar('\v', 1));
  return (my_putchar(*seq, 1));
}

variable_types:
echo
unsigned int


decompiled_code:
__int64 __fastcall print_seq(char *a1, char a2, _BYTE *a3)
{
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
int v8; // er13
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 result; // rax

if ( (a2 & 2) == 0 )
return my_putchar((unsigned int)*a1, 1LL);
if ( !a1 )
return print_seq2(a1, a2);
v4 = my_strlen(&unk_3EE);
if ( !(unsigned int)my_strncmp(&unk_3EE, a1, v4) )
return plus_seq((__int64)(a1 + 2), 8, 3uLL) + 2;
v5 = my_strlen(&unk_403);
if ( !(unsigned int)my_strncmp(&unk_403, a1, v5) )
return plus_seq((__int64)(a1 + 2), 16, 2uLL) + 2;
v6 = my_strlen(&unk_400);
if ( !(unsigned int)my_strncmp(&unk_400, a1, v6) )
return my_putchar(92LL, 1LL) + 1;
v7 = my_strlen(&unk_3FD);
v8 = a2 & 4;
if ( !(v8 | (unsigned int)my_strncmp(&unk_3FD, a1, v7)) )
return my_putchar(7LL, 1LL) + 1;
v9 = my_strlen(&unk_3FA);
if ( !(v8 | (unsigned int)my_strncmp(&unk_3FA, a1, v9)) )
return my_putchar(8LL, 1LL) + 1;
v10 = my_strlen(&unk_3F7);
if ( v8 | (unsigned int)my_strncmp(&unk_3F7, a1, v10) )
{
v11 = my_strlen(&unk_3F4);
if ( v8 | (unsigned int)my_strncmp(&unk_3F4, a1, v11) )
{
v12 = my_strlen(&unk_3F1);
if ( v8 | (unsigned int)my_strncmp(&unk_3F1, a1, v12) )
return print_seq2(a1, a2);
result = my_putchar(12LL, 1LL) + 1;
}
else
{
result = my_putchar(27LL, 1LL) + 1;
}
}
else
{
*a3 = 1;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char a2, _BYTE *a3)
{
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
int v8; // er13
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 result; // rax

if ( (a2 & 2) == 0 )
return my_putchar((unsigned int)*a1, 1LL);
if ( !a1 )
return func1(a1, a2);
v4 = my_strlen(&unk_3EE);
if ( !(unsigned int)my_strncmp(&unk_3EE, a1, v4) )
return func0((__int64)(a1 + 2), 8, 3uLL) + 2;
v5 = my_strlen(&unk_403);
if ( !(unsigned int)my_strncmp(&unk_403, a1, v5) )
return func0((__int64)(a1 + 2), 16, 2uLL) + 2;
v6 = my_strlen(&unk_400);
if ( !(unsigned int)my_strncmp(&unk_400, a1, v6) )
return my_putchar(92LL, 1LL) + 1;
v7 = my_strlen(&unk_3FD);
v8 = a2 & 4;
if ( !(v8 | (unsigned int)my_strncmp(&unk_3FD, a1, v7)) )
return my_putchar(7LL, 1LL) + 1;
v9 = my_strlen(&unk_3FA);
if ( !(v8 | (unsigned int)my_strncmp(&unk_3FA, a1, v9)) )
return my_putchar(8LL, 1LL) + 1;
v10 = my_strlen(&unk_3F7);
if ( v8 | (unsigned int)my_strncmp(&unk_3F7, a1, v10) )
{
v11 = my_strlen(&unk_3F4);
if ( v8 | (unsigned int)my_strncmp(&unk_3F4, a1, v11) )
{
v12 = my_strlen(&unk_3F1);
if ( v8 | (unsigned int)my_strncmp(&unk_3F1, a1, v12) )
return func1(a1, a2);
result = my_putchar(12LL, 1LL) + 1;
}
else
{
result = my_putchar(27LL, 1LL) + 1;
}
}
else
{
*a3 = 1;
result = 1LL;
}
return result;
}

variable_types:
end
unsigned char *


decompiled_code:
__int64 __fastcall free_str_edit_lines(void *a1, void *a2)
{
void *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a1;
if ( a1 )
free(a1);
if ( a2 )
free(a2);
v3 = 0LL;
remind_save_str(1LL, &v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *a1, void *a2)
{
void *v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a1;
if ( a1 )
free(a1);
if ( a2 )
free(a2);
v3 = 0LL;
remind_save_str(1LL, &v3);
return 0LL;
}

original_code:
char *free_str_edit_lines(char *s1, char *s2)
{
  if (s1 != ((void *)0))
    free(s1);
  if (s2 != ((void *)0))
    free(s2);
  s1 = ((void *)0);
  remind_save_str(1, &s1);
  return (((void *)0));
}

return_type: char *


decompiled_code:
__int64 __fastcall finish_usr_cmd(__int64 a1, void *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
my_putstr(&unk_85, 1LL);
unset_termios(&a7);
free_str_edit_lines(a2, 0LL);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, void *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
my_putstr(&unk_85, 1LL);
unset_termios(&a7);
func0(a2, 0LL);
return a1;
}

original_code:
char *finish_usr_cmd(char *cmd, char *str, struct termios unset)
{
  my_putstr("\n", 1);
  unset_termios(&unset);
  free_str_edit_lines(str, ((void *)0));
  return (cmd);
}

variable_types:
cmd
char *

variable_types:
str
char *

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 swap_chars_on_cmd(__int64 a1, _DWORD *a2, _QWORD *a3)
{
int v5; // ecx
__int64 result; // rax
int v7; // esi
char *v8; // rdx
char v9; // r8

v5 = my_strlen(*a3);
result = (unsigned int)*a2;
if ( (int)result > 0 )
{
v7 = result == v5;
v8 = (char *)(*a3 + (int)result + ~v7);
v9 = *v8;
*v8 = *(_BYTE *)(*a3 + (int)result - v7);
*(_BYTE *)(*a3 + *a2 - v7) = v9;
result = (unsigned int)*a2;
if ( (_DWORD)result != v5 )
{
result = (unsigned int)(result + 1);
*a2 = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _DWORD *a2, _QWORD *a3)
{
int v5; // ecx
__int64 result; // rax
int v7; // esi
char *v8; // rdx
char v9; // r8

v5 = my_strlen(*a3);
result = (unsigned int)*a2;
if ( (int)result > 0 )
{
v7 = result == v5;
v8 = (char *)(*a3 + (int)result + ~v7);
v9 = *v8;
*v8 = *(_BYTE *)(*a3 + (int)result - v7);
*(_BYTE *)(*a3 + *a2 - v7) = v9;
result = (unsigned int)*a2;
if ( (_DWORD)result != v5 )
{
result = (unsigned int)(result + 1);
*a2 = result;
}
}
return result;
}

original_code:
void swap_chars_on_cmd(char value, int *reverse_case, char **cmd)
{
  char reserve;
  int len;
  int i;
  (void)value;
  i = 0;
  len = my_strlen(*cmd);
  if (*reverse_case == len)
    i--;
  if (*reverse_case > 0)
    {
      reserve = (*cmd)[(*reverse_case) + (i - 1)];
      (*cmd)[(*reverse_case) + (i - 1)] = (*cmd)[(*reverse_case) + i];
      (*cmd)[(*reverse_case) + i] = reserve;
      if (*reverse_case != len)
 (*reverse_case)++;
    }
}

variable_types: value char

variable_types:
cmd
char **

variable_types: reserve char

variable_types: len int

variable_types: i int


xfork

decompiled_code:
__int64 xfork()
{
unsigned int v0; // ebx

v0 = fork();
if ( v0 == -1 )
my_putpath("fork(): fail\n", "/dev/tty");
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx

v0 = fork();
if ( v0 == -1 )
my_putpath("fork(): fail\n", "/dev/tty");
return v0;
}

original_code:
pid_t xfork(void)
{
  pid_t pid;
  if ((pid = fork()) == -1)
    my_putpath("fork(): fail\n", "/dev/tty");
  return (pid);
}

canonical_original_code:
int xfork()
{
  int pid;
  if ((pid = fork()) == -1)
    my_putpath("fork(): fail\n", "/dev/tty");
  return (pid);
}

variable_types: pid int


decompiled_code:
_BOOL8 __fastcall test_nl(_BYTE *a1)
{
return *a1 == 10;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_BYTE *a1)
{
return *a1 == 10;
}

original_code:
int test_nl(char *str)
{
  int i;
  i = 0;
  while (i < 1)
    if (str[i++] == '\n')
      return (1);
  return (0);
}


inc

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

result = *(unsigned __int8 *)(a2 + a3);
*(_BYTE *)(a1 + a3) = result;
return result;
}

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

result = *(unsigned __int8 *)(a2 + a3);
*(_BYTE *)(a1 + a3) = result;
return result;
}

original_code:
void inc(char *str1, char *str2, int i)
{
  str1[i] = str2[i];
}


decompiled_code:
__int64 __fastcall get_next_line(int fd)
{
int v1; // ebx
__int64 result; // rax
int v3; // [rsp+4h] [rbp-24h] BYREF
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = 0;
v4[0] = 0LL;
v1 = 1;
while ( (!test_nl(&memory_0) || !v3) && v1 == 1 )
{
if ( !memory_0 )
{
v1 = read(fd, &memory_0, 1uLL);
if ( v1 <= 0 && !v3 )
return 0LL;
}
++v3;
memorize(&v3, v4, &memory_0);
result = v4[0];
if ( !v4[0] )
return result;
}
memory_0 = 0;
return v4[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
int v1; // ebx
__int64 result; // rax
int v3; // [rsp+4h] [rbp-24h] BYREF
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v3 = 0;
v4[0] = 0LL;
v1 = 1;
while ( (!func0(&memory_0) || !v3) && v1 == 1 )
{
if ( !memory_0 )
{
v1 = read(fd, &memory_0, 1uLL);
if ( v1 <= 0 && !v3 )
return 0LL;
}
++v3;
memorize(&v3, v4, &memory_0);
result = v4[0];
if ( !v4[0] )
return result;
}
memory_0 = 0;
return v4[0];
}

original_code:
char *get_next_line(const int fd)
{
  char *buffer;
  static char memory[1 + 1];
  int w;
  int lr;
  w = 0;
  lr = 1;
  buffer = ((void *)0);
  while ((!test_nl(memory) || !w) && lr == 1)
    {
      if (!memory[0])
 if ((lr = read(fd, memory, 1)) <= 0 && w == 0)
   return (((void *)0));
      w = w + 1;
      memorize(&w, &buffer, memory);
      if (buffer == ((void *)0))
 return (((void *)0));
    }
  w = 0;
  lr = 1;
  while (w + 1 < 1 && memory[w])
    memory[w++] = memory[lr++];
  memory[w] = '\0';
  return (buffer);
}

canonical_original_code:
char *get_next_line(int fd)
{
  char *buffer;
  static char memory[-1];
  int w;
  int lr;
  w = 0;
  lr = 1;
  buffer = ((void *)0);
  while ((!test_nl(memory) || !w) && lr == 1)
    {
      if (!memory[0])
 if ((lr = read(fd, memory, 1)) <= 0 && w == 0)
   return (((void *)0));
      w = w + 1;
      memorize(&w, &buffer, memory);
      if (buffer == ((void *)0))
 return (((void *)0));
    }
  w = 0;
  lr = 1;
  while (w + 1 < 1 && memory[w])
    memory[w++] = memory[lr++];
  memory[w] = '\0';
  return (buffer);
}

variable_types: fd int

variable_types:
buffer
char *

variable_types:
memory
char [-1]

variable_types: w int

variable_types: lr int


empty

decompiled_code:
bool __fastcall empty(char *a1)
{
char v1; // al
char *v2; // rdi

if ( !a1 )
return 0;
v1 = *a1;
if ( *a1 == 32 || v1 == 9 )
{
v2 = a1 + 1;
do
{
do
v1 = *v2++;
while ( v1 == 32 );
}
while ( v1 == 9 );
}
return v1 == 0;
}

original_code:
unsigned char empty(const char *s)
{
  size_t i;
  if (!s)
    return (0);
  i = 0;
  while (s[i] == ' ' || s[i] == 9)
    i++;
  return (s[i] == '\0');
}

canonical_original_code:
unsigned char empty(char *s)
{
  unsigned long i;
  if (!s)
    return (0);
  i = 0;
  while (s[i] == ' ' || s[i] == 9)
    i++;
  return (s[i] == '\0');
}

variable_types:
s
char *

variable_types:
i
unsigned long


nempty

decompiled_code:
__int64 __fastcall nempty(unsigned __int8 *a1, unsigned __int64 a2)
{
int v2; // edx
unsigned __int64 v3; // rax

v2 = *a1;
if ( ((_BYTE)v2 == 9 || (_BYTE)v2 == 32) && a2 )
{
v3 = 0LL;
do
v2 = a1[++v3];
while ( ((_BYTE)v2 == 9 || (_BYTE)v2 == 32) && a2 > v3 );
}
else
{
v3 = 0LL;
}
LOBYTE(v3) = a2 == v3;
LOBYTE(v2) = (_BYTE)v2 == 0;
return v2 | (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, unsigned __int64 a2)
{
int v2; // edx
unsigned __int64 v3; // rax

v2 = *a1;
if ( ((_BYTE)v2 == 9 || (_BYTE)v2 == 32) && a2 )
{
v3 = 0LL;
do
v2 = a1[++v3];
while ( ((_BYTE)v2 == 9 || (_BYTE)v2 == 32) && a2 > v3 );
}
else
{
v3 = 0LL;
}
LOBYTE(v3) = a2 == v3;
LOBYTE(v2) = (_BYTE)v2 == 0;
return v2 | (unsigned int)v3;
}

original_code:
unsigned char nempty(const char *s, size_t n)
{
  size_t i;
  i = 0;
  while ((s[i] == ' ' || s[i] == 9) && i < n)
    i++;
  return (s[i] == '\0' || i == n);
}

canonical_original_code:
unsigned char nempty(char *s, unsigned long n)
{
  unsigned long i;
  i = 0;
  while ((s[i] == ' ' || s[i] == 9) && i < n)
    i++;
  return (s[i] == '\0' || i == n);
}

variable_types:
n
unsigned long


hempty

decompiled_code:
__int64 __fastcall hempty(_BYTE *a1)
{
__int64 result; // rax
char v2; // dl

if ( *a1 != 32 && *a1 != 9 )
return 0LL;
result = 0LL;
do
{
do
v2 = a1[++result];
while ( v2 == 32 );
}
while ( v2 == 9 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
__int64 result; // rax
char v2; // dl

if ( *a1 != 32 && *a1 != 9 )
return 0LL;
result = 0LL;
do
{
do
v2 = a1[++result];
while ( v2 == 32 );
}
while ( v2 == 9 );
return result;
}

original_code:
size_t hempty(const char *s)
{
  size_t i;
  i = 0;
  while (s[i] == ' ' || s[i] == 9)
    i++;
  return (i);
}

canonical_original_code:
unsigned long hempty(char *s)
{
  unsigned long i;
  i = 0;
  while (s[i] == ' ' || s[i] == 9)
    i++;
  return (i);
}


decompiled_code:
unsigned __int64 __fastcall lastoccur_bf(char *a1, char a2, unsigned __int64 a3)
{
char v5; // dl
unsigned __int64 v6; // rax
unsigned __int64 v7; // rcx

v5 = *a1;
if ( !a3 || !v5 )
return 0LL;
v6 = 0LL;
v7 = 0LL;
do
{
if ( a2 == v5 )
v7 = v6;
v5 = a1[++v6];
}
while ( a3 > v6 && v5 );
return v7;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(char *a1, char a2, unsigned __int64 a3)
{
char v5; // dl
unsigned __int64 v6; // rax
unsigned __int64 v7; // rcx

v5 = *a1;
if ( !a3 || !v5 )
return 0LL;
v6 = 0LL;
v7 = 0LL;
do
{
if ( a2 == v5 )
v7 = v6;
v5 = a1[++v6];
}
while ( a3 > v6 && v5 );
return v7;
}

original_code:
size_t lastoccur_bf(const char *s, char c, size_t e)
{
  size_t cseek;
  size_t i;
  i = 0;
  cseek = 0;
  while (s[i] && i < e)
    {
      if (s[i] == c)
 cseek = i;
      i++;
    }
  return (cseek);
}

canonical_original_code:
unsigned long lastoccur_bf(char *s, char c, unsigned long e)
{
  unsigned long cseek;
  unsigned long i;
  i = 0;
  cseek = 0;
  while (s[i] && i < e)
    {
      if (s[i] == c)
 cseek = i;
      i++;
    }
  return (cseek);
}

variable_types: c char

variable_types:
e
unsigned long

variable_types:
cseek
unsigned long


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

if ( !a1 )
return 0LL;
result = 0LL;
do
{
++result;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
result = 0LL;
do
{
++result;
a1 = *(_QWORD *)(a1 + 8);
}
while ( a1 );
return result;
}

original_code:
static size_t size_list(t_words *list)
{
  size_t i;
  i = 0;
  while (list)
    {
      i++;
      list = list->next;
    }
  return (i);
}

canonical_original_code:
static unsigned long size_list(struct s_words *list)
{
  unsigned long i;
  i = 0;
  while (list)
    {
      i++;
      list = list->next;
    }
  return (i);
}

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


original_code:
char **to_tab(t_words *list, unsigned char *sys_fail)
{
  char **tab;
  size_t i;
  i = size_list(list);
  if ((tab = xmalloc(sizeof(*tab) * (i + 1))) == ((void *)0))
    {
      (*sys_fail) = 1;
      return (((void *)0));
    }
  i = 0;
  while (list)
    {
      tab[i] = list->word;
      list = list->next;
      i++;
    }
  tab[i] = ((void *)0);
  return (tab);
}

canonical_original_code:
char **to_tab(struct s_words *list, unsigned char *sys_fail)
{
  char **tab;
  unsigned long i;
  i = size_list(list);
  if ((tab = xmalloc(sizeof(*tab) * (i + 1))) == ((void *)0))
    {
      (*sys_fail) = 1;
      return (((void *)0));
    }
  i = 0;
  while (list)
    {
      tab[i] = list->word;
      list = list->next;
      i++;
    }
  tab[i] = ((void *)0);
  return (tab);
}

variable_types:
tab
char **

return_type: char **


cond

decompiled_code:
char __fastcall cond(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
char result; // al
int v5; // edx
__int64 v6; // rdx
__int64 v7; // rax

v2 = my_strilen(a2, 47LL);
v3 = a1 + 19;
result = nmatch(a1 + 19, a2, v2);
if ( result )
{
if ( !(unsigned int)my_strcmp(v3, ".") || (v5 = my_strcmp(v3, ".."), result = 1, !v5) )
{
v6 = my_strilen(a2, 47LL);
result = 1;
if ( *(_BYTE *)(a2 + v6) )
{
result = 0;
if ( a2 )
{
v7 = my_strlen("..");
result = (unsigned int)my_strncmp("..", a2, v7) == 0;
}
}
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rbx
char result; // al
int v5; // edx
__int64 v6; // rdx
__int64 v7; // rax

v2 = my_strilen(a2, 47LL);
v3 = a1 + 19;
result = nmatch(a1 + 19, a2, v2);
if ( result )
{
if ( !(unsigned int)my_strcmp(v3, ".") || (v5 = my_strcmp(v3, ".."), result = 1, !v5) )
{
v6 = my_strilen(a2, 47LL);
result = 1;
if ( *(_BYTE *)(a2 + v6) )
{
result = 0;
if ( a2 )
{
v7 = my_strlen("..");
result = (unsigned int)my_strncmp("..", a2, v7) == 0;
}
}
}
}
return result;
}

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *

variable_types:
m
char *


decompiled_code:
bool __fastcall is_dir(const char *a1)
{
int v1; // edx
bool result; // al
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0;
if ( v1 != -1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

canonical_decompiled_code:
bool __fastcall func1(const char *a1)
{
int v1; // edx
bool result; // al
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0;
if ( v1 != -1 )
result = (v3.st_mode & 0xF000) == 0x4000;
return result;
}

original_code:
static unsigned char is_dir(char *dp)
{
  struct stat st;
  if (stat(dp, &st) == -1)
    return (0);
  if ((st.st_mode & 0170000) == 0040000)
    return (1);
  return (0);
}

variable_types:
dp
char *

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

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


decompiled_code:
__int64 __fastcall cond2(__int64 a1, void *a2)
{
bool v2; // dl
__int64 result; // rax
__int64 v4; // rdx

if ( !*(_BYTE *)(a1 + my_strilen(a1, 47LL)) || (v2 = is_dir((const char *)a2), result = 1LL, !v2) )
{
v4 = my_strilen(a1, 47LL);
result = 1LL;
if ( *(_BYTE *)(a1 + v4) )
{
free(a2);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, void *a2)
{
bool v2; // dl
__int64 result; // rax
__int64 v4; // rdx

if ( !*(_BYTE *)(a1 + my_strilen(a1, 47LL)) || (v2 = func1((const char *)a2), result = 1LL, !v2) )
{
v4 = my_strilen(a1, 47LL);
result = 1LL;
if ( *(_BYTE *)(a1 + v4) )
{
free(a2);
result = 0LL;
}
}
return result;
}

original_code:
static unsigned char cond2(char *m, char *f_dp)
{
  if ((((m)[my_strilen(m, '/')] != 0) && is_dir(f_dp)) || !((m)[my_strilen(m, '/')] != 0))
    return (1);
  free(f_dp);
  return (0);
}


decompiled_code:
__int64 print_env()
{
char *v0; // rdi
__int64 v1; // rbx

if ( !environ )
return 1LL;
v0 = *environ;
if ( !*environ )
return 0LL;
v1 = 1LL;
do
{
my_putstr(v0, 1LL);
my_putstr(&unk_1E3, 1LL);
v0 = environ[v1++];
}
while ( v0 );
return 0LL;
}

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

if ( !environ )
return 1LL;
v0 = *environ;
if ( !*environ )
return 0LL;
v1 = 1LL;
do
{
my_putstr(v0, 1LL);
my_putstr(&unk_1E3, 1LL);
v0 = environ[v1++];
}
while ( v0 );
return 0LL;
}

original_code:
static int print_env()
{
  size_t i;
  if (!environ)
    return (1);
  i = 0;
  while (environ[i])
    {
      my_putstr(environ[i++], 1);
      my_putstr("\n", 1);
    }
  return (0);
}

canonical_original_code:
static int print_env()
{
  unsigned long i;
  if (!environ)
    return (1);
  i = 0;
  while (environ[i])
    {
      my_putstr(environ[i++], 1);
      my_putstr("\n", 1);
    }
  return (0);
}


decompiled_code:
__int64 __fastcall seek_fail(void *ptr)
{
if ( ptr )
{
((void (*)(void))print_err)();
print_err(&unk_1E3);
free(ptr);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
if ( ptr )
{
((void (*)(void))print_err)();
print_err(&unk_1E3);
free(ptr);
}
return 1LL;
}

original_code:
static int seek_fail(char *r)
{
  if (!r)
    return (1);
  print_err(r);
  print_err("\n");
  free(r);
  return (1);
}

variable_types:
r
char *


decompiled_code:
__int64 print_help()
{
my_putstr("Uasge: env [options]\n", 1LL);
my_putstr("env built-in loads a temporary environment, wich is setted by:\n", 1LL);
my_putstr(" -i : unset all\n", 1LL);
my_putstr(" -u {p} : unset {p}\n", 1LL);
my_putstr(" -s {v,p}: set {v} with {p}\n", 1LL);
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
my_putstr("Uasge: env [options]\n", 1LL);
my_putstr("env built-in loads a temporary environment, wich is setted by:\n", 1LL);
my_putstr(" -i : unset all\n", 1LL);
my_putstr(" -u {p} : unset {p}\n", 1LL);
my_putstr(" -s {v,p}: set {v} with {p}\n", 1LL);
return 0LL;
}

original_code:
unsigned char print_help(void)
{
  my_putstr("Uasge: env [options]\n", 1);
  my_putstr("env built-in loads a temporary environment, wich is setted by:\n",
     1);
  my_putstr("    -i      : unset all\n", 1);
  my_putstr("    -u {p}  : unset {p}\n", 1);
  my_putstr("    -s {v,p}: set {v} with {p}\n", 1);
  return (0);
}

canonical_original_code:
unsigned char print_help()
{
  my_putstr("Uasge: env [options]\n", 1);
  my_putstr("env built-in loads a temporary environment, wich is setted by:\n",
     1);
  my_putstr("    -i      : unset all\n", 1);
  my_putstr("    -u {p}  : unset {p}\n", 1);
  my_putstr("    -s {v,p}: set {v} with {p}\n", 1);
  return (0);
}


decompiled_code:
void destroy_env()
{
char **v0; // rax
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);
}
}

canonical_decompiled_code:
void func3()
{
char **v0; // rax
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);
}
}

original_code:
void destroy_env(void)
{
  size_t i;
  i = 0;
  if (!environ)
    return ;
  while (environ[i])
    free(environ[i++]);
  free(environ);
}

canonical_original_code:
void destroy_env()
{
  unsigned long i;
  i = 0;
  if (!environ)
    return ;
  while (environ[i])
    free(environ[i++]);
  free(environ);
}


decompiled_code:
__int64 __fastcall exec_env(__int64 *a1, char **a2)
{
_BYTE *v2; // rbp
char **v3; // r13
_BYTE *v4; // r12
__int64 result; // rax
__int64 v6; // rax
void *ptr; // [rsp+0h] [rbp-38h] BYREF
char v8; // [rsp+Bh] [rbp-2Dh] BYREF
unsigned int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( !a1 )
return print_env();
v2 = (_BYTE *)*a1;
ptr = 0LL;
v3 = environ;
environ = a2;
if ( *(_BYTE *)*a1 == 46
|| (v4 = (_BYTE *)*a1, v4[my_strilen(*a1, 47LL)])
|| (v6 = seek_cmd(*a1, &ptr), (*a1 = v6) != 0) )
{
environ = v3;
if ( !v2 || !*a1 || (unsigned int)my_strcmp(v2) )
free(v2);
exec_form(a1, &v8, v9);
result = v9[0];
}
else
{
environ = v3;
result = seek_fail(ptr);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, char **a2)
{
_BYTE *v2; // rbp
char **v3; // r13
_BYTE *v4; // r12
__int64 result; // rax
__int64 v6; // rax
void *ptr; // [rsp+0h] [rbp-38h] BYREF
char v8; // [rsp+Bh] [rbp-2Dh] BYREF
unsigned int v9[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( !a1 )
return func0();
v2 = (_BYTE *)*a1;
ptr = 0LL;
v3 = environ;
environ = a2;
if ( *(_BYTE *)*a1 == 46
|| (v4 = (_BYTE *)*a1, v4[my_strilen(*a1, 47LL)])
|| (v6 = seek_cmd(*a1, &ptr), (*a1 = v6) != 0) )
{
environ = v3;
if ( !v2 || !*a1 || (unsigned int)my_strcmp(v2) )
free(v2);
exec_form(a1, &v8, v9);
result = v9[0];
}
else
{
environ = v3;
result = func1(ptr);
}
return result;
}

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


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

my_putstr(&unk_81, 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_81, 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)
{
__int64 v3; // rdi
__int64 v4; // rax
__int64 result; // rax
__int64 v6; // rdx

if ( !a1 )
return 0LL;
v3 = *a1;
if ( !a2
|| !v3
|| (v4 = ((__int64 (*)(void))my_strlen)(), (unsigned int)my_strncmp(*a1, a2, v4))
|| (v6 = my_strlen(*a1), result = 1LL, *(_BYTE *)(a2 + v6) != 61) )
{
result = deset(a1[1], a2);
}
return result;
}

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

if ( !a1 )
return 0LL;
v3 = *a1;
if ( !a2
|| !v3
|| (v4 = ((__int64 (*)(void))my_strlen)(), (unsigned int)my_strncmp(*a1, a2, v4))
|| (v6 = my_strlen(*a1), result = 1LL, *(_BYTE *)(a2 + v6) != 61) )
{
result = func0(a1[1], a2);
}
return result;
}

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


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

canonical_decompiled_code:
__int64 __fastcall func1(char **a1, char a2)
{
if ( a2 )
{
if ( environ )
destroy_env();
}
else if ( environ )
{
free(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:
destroy
unsigned char


decompiled_code:
__int64 __fastcall built_unsetenv(__int64 a1)
{
char *v1; // rsi
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rbx
__int64 v5; // rax
char **v6; // r14
char *v7; // rsi
__int64 v8; // rbx
__int64 v9; // r13
__int64 v11; // r12

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

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

if ( !*(_QWORD *)(a1 + 8) )
return my_putstr("(sh): unsetenv: Too few arguments.\n", 2LL) != 0;
if ( !environ )
return func1(0LL, 1);
v1 = *environ;
if ( !*environ )
return func1(0LL, 1);
v2 = 0LL;
v3 = 0LL;
do
{
++v3;
v2 -= ((unsigned __int8)func0(*(_QWORD **)(a1 + 8), (__int64)v1) == 0) - 1LL;
v1 = environ[v3];
}
while ( v1 );
if ( v2 == v3 )
return func1(0LL, 1);
v4 = 8 * (v3 - v2) + 8;
v5 = xmalloc(v4);
v6 = (char **)v5;
if ( !v5 )
return 1LL;
*(_QWORD *)(v5 + v4 - 8) = 0LL;
v7 = *environ;
if ( *environ )
{
v8 = 1LL;
v9 = 0LL;
do
{
v11 = v8;
if ( (unsigned __int8)func0(*(_QWORD **)(a1 + 8), (__int64)v7) )
free(environ[v11 - 1]);
else
v6[v9++] = environ[v11 - 1];
v7 = environ[v8++];
}
while ( v7 );
}
else
{
v9 = 0LL;
}
v6[v9] = 0LL;
return func1(v6, 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: struct s_words { char *word; struct s_words *next; } *

variable_types:
i
unsigned long

variable_types:
n
unsigned long


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; // rbx
__int64 result; // rax
__int64 v6; // rdx
__int64 v7; // rax

v4 = (__int64 *)xmalloc(48LL);
result = 1LL;
if ( v4 )
{
v6 = my_strdup(a1);
*v4 = v6;
result = 1LL;
if ( v6 )
{
v7 = my_strdup(a2);
v4[1] = v7;
if ( v7 )
{
v4[3] = 0LL;
v4[2] = 0LL;
if ( *a3 )
{
result = add_link((__int64)v4, a1, a3);
}
else
{
*a3 = (__int64)v4;
result = 0LL;
}
}
else
{
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 *v4; // rbx
__int64 result; // rax
__int64 v6; // rdx
__int64 v7; // rax

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

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

decompiled_code:
__int64 __fastcall built(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
char v6; // dl
__int64 result; // rax
char v8; // dl
__int64 v9; // rdi
__int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

v10[0] = a1;
v6 = seed_alias(a1, *(_QWORD *)(a3 + 120), v10);
result = 0LL;
if ( v6 )
{
v8 = grow_var(v10[0], v10, 0LL, a3);
result = 0LL;
if ( v8 )
{
v9 = v10[0];
*a4 = v10[0];
result = subdivide(v9, 0LL, a2);
if ( result )
{
result = comment(result, 0LL);
if ( result )
result = orga(result, a2, 0LL, 0LL);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
char v6; // dl
__int64 result; // rax
char v8; // dl
__int64 v9; // rdi
__int64 v10[4]; // [rsp+8h] [rbp-20h] BYREF

v10[0] = a1;
v6 = seed_alias(a1, *(_QWORD *)(a3 + 120), v10);
result = 0LL;
if ( v6 )
{
v8 = grow_var(v10[0], v10, 0LL, a3);
result = 0LL;
if ( v8 )
{
v9 = v10[0];
*a4 = v10[0];
result = subdivide(v9, 0LL, a2);
if ( result )
{
result = comment(result, 0LL);
if ( result )
result = orga(result, a2, 0LL, 0LL);
}
}
}
return result;
}

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


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

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

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

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

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


decompiled_code:
__int64 __fastcall get_usr_cmd(char a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp

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

canonical_decompiled_code:
__int64 __fastcall func3(char a1, __int64 a2, __int64 a3)
{
__int64 v3; // rbp

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

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 *


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

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

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

*(_BYTE *)(a1 + 88) = a2;
v4 = 0LL;
v2 = 1;
while ( v2 )
{
s = (char *)func3(a2, (__int64)v4, a1);
if ( !s )
{
my_putstr("exit", 1LL);
break;
}
signal(2, (__sighandler_t)catch_after);
*(_QWORD *)a1 = v4;
if ( s )
{
if ( (unsigned __int8)grow_hist(s, &s, 0LL, a1) <= 1u )
{
LABEL_2:
if ( s )
v2 = func2(s, a1, &v4);
}
else if ( s )
{
puts(s);
goto LABEL_2;
}
}
}
free_history(v4);
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


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

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

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

if ( !buf )
return 0LL;
if ( *(_BYTE *)buf )
{
v2 = 0LL;
do
++v2;
while ( *((_BYTE *)buf + v2) );
}
else
{
v2 = 0LL;
}
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; // rbx
int v3; // eax
int v4; // er12

if ( *(_BYTE *)buf )
{
v2 = 0LL;
do
++v2;
while ( *((_BYTE *)buf + v2) );
}
else
{
v2 = 0LL;
}
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; // rbx
int v3; // eax
int v4; // er12

if ( *(_BYTE *)buf )
{
v2 = 0LL;
do
++v2;
while ( *((_BYTE *)buf + v2) );
}
else
{
v2 = 0LL;
}
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

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

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

if ( *(_BYTE *)buf )
{
v1 = 0LL;
do
++v1;
while ( *((_BYTE *)buf + v1) );
}
else
{
v1 = 0LL;
}
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; // rbx

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

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

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

v1 = (void **)ptr;
if ( 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

v1 = (void **)ptr;
if ( 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; // rbp

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

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


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; // rax
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; // rax
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 v2; // rbx
__int64 v3; // r12
__int64 v4; // r14
char result; // al
__int64 v7; // rax
char *v8; // r13
__int64 v9; // r13
__int64 v10; // r12
__int64 v11; // rbx
__int64 v12; // rax
char *v13; // r14

if ( !a1 )
return (unsigned __int8)print_err("env: option requires an argument -- 'u'\n") == 0;
v1 = environ;
if ( !environ )
return 1;
if ( *environ )
{
v2 = 1LL;
v3 = 1LL;
v4 = 0LL;
do
{
if ( *a1 )
{
if ( v1[v2 - 1] )
{
v7 = ((__int64 (*)(void))my_strlen)();
if ( !(unsigned int)my_strncmp(*a1, environ[v2 - 1], v7) )
{
v8 = environ[v2 - 1];
if ( v8[my_strlen(*a1)] == 34 )
v4 = 1LL;
}
}
}
v1 = environ;
++v3;
}
while ( environ[v2++] );
if ( v4 == v3 )
return (unsigned int)switch_env(0LL, 1LL) == 0;
}
else
{
v3 = 1LL;
v4 = 0LL;
}
v9 = xmalloc(8 * (v3 - v4) + 8);
if ( v9 )
{
v10 = 0LL;
v11 = 0LL;
if ( *environ )
{
do
{
if ( *a1
&& (v12 = my_strlen(*a1), !(unsigned int)my_strncmp(*a1, environ[v11], v12))
&& (v13 = environ[v11], v13[my_strlen(*a1)] == 61) )
{
free(environ[v11]);
}
else
{
*(_QWORD *)(v9 + 8 * v10++) = environ[v11];
}
++v11;
}
while ( environ[v11] );
}
*(_QWORD *)(v9 + 8 * v10) = 0LL;
result = (unsigned int)switch_env(v9, 0LL) == 0;
}
else
{
environ = 0LL;
result = 0;
}
return result;
}

canonical_decompiled_code:
char __fastcall func1(_QWORD *a1)
{
char **v1; // rax
__int64 v2; // rbx
__int64 v3; // r12
__int64 v4; // r14
char result; // al
__int64 v7; // rax
char *v8; // r13
__int64 v9; // r13
__int64 v10; // r12
__int64 v11; // rbx
__int64 v12; // rax
char *v13; // r14

if ( !a1 )
return (unsigned __int8)print_err("env: option requires an argument -- 'u'\n") == 0;
v1 = environ;
if ( !environ )
return 1;
if ( *environ )
{
v2 = 1LL;
v3 = 1LL;
v4 = 0LL;
do
{
if ( *a1 )
{
if ( v1[v2 - 1] )
{
v7 = ((__int64 (*)(void))my_strlen)();
if ( !(unsigned int)my_strncmp(*a1, environ[v2 - 1], v7) )
{
v8 = environ[v2 - 1];
if ( v8[my_strlen(*a1)] == 34 )
v4 = 1LL;
}
}
}
v1 = environ;
++v3;
}
while ( environ[v2++] );
if ( v4 == v3 )
return (unsigned int)switch_env(0LL, 1LL) == 0;
}
else
{
v3 = 1LL;
v4 = 0LL;
}
v9 = xmalloc(8 * (v3 - v4) + 8);
if ( v9 )
{
v10 = 0LL;
v11 = 0LL;
if ( *environ )
{
do
{
if ( *a1
&& (v12 = my_strlen(*a1), !(unsigned int)my_strncmp(*a1, environ[v11], v12))
&& (v13 = environ[v11], v13[my_strlen(*a1)] == 61) )
{
free(environ[v11]);
}
else
{
*(_QWORD *)(v9 + 8 * v10++) = environ[v11];
}
++v11;
}
while ( environ[v11] );
}
*(_QWORD *)(v9 + 8 * v10) = 0LL;
result = (unsigned int)switch_env(v9, 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:
bool __fastcall env_s(_QWORD *a1)
{
_QWORD *v1; // rax
char *v2; // r12
int v3; // ebp
__int64 v4; // rbx
__int64 v6; // rax
__int64 v7; // rbp
__int64 v8; // rax
char **v9; // rbx
int v10; // ecx
char *v11; // rdx
__int64 v12; // rax

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 = (char *)my_stricat(*a1, *v1, 61LL);
if ( !environ )
{
v3 = 0;
goto LABEL_12;
}
if ( !*environ )
{
v3 = 0;
LABEL_12:
v7 = 8LL * (v3 + 2);
v8 = xmalloc(v7);
v9 = (char **)v8;
if ( !v8 )
return 0;
*(_QWORD *)(v8 + v7 - 8) = 0LL;
v10 = 0;
if ( environ )
{
v11 = *environ;
if ( *environ )
{
v12 = 0LL;
do
{
v9[v12] = v11;
++v10;
v11 = environ[++v12];
}
while ( v11 );
}
else
{
v10 = 0;
}
}
v9[v10] = v2;
free(environ);
environ = v9;
return 1;
}
v3 = 0;
v4 = 0LL;
while ( 1 )
{
if ( *a1 )
{
v6 = my_strlen(*a1);
if ( !(unsigned int)my_strncmp(*a1, environ[v4], v6) )
break;
}
++v3;
if ( !environ[++v4] )
goto LABEL_12;
}
free(environ[v4]);
environ[v4] = v2;
return 1;
}

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

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 = (char *)my_stricat(*a1, *v1, 61LL);
if ( !environ )
{
v3 = 0;
goto LABEL_12;
}
if ( !*environ )
{
v3 = 0;
LABEL_12:
v7 = 8LL * (v3 + 2);
v8 = xmalloc(v7);
v9 = (char **)v8;
if ( !v8 )
return 0;
*(_QWORD *)(v8 + v7 - 8) = 0LL;
v10 = 0;
if ( environ )
{
v11 = *environ;
if ( *environ )
{
v12 = 0LL;
do
{
v9[v12] = v11;
++v10;
v11 = environ[++v12];
}
while ( v11 );
}
else
{
v10 = 0;
}
}
v9[v10] = v2;
free(environ);
environ = v9;
return 1;
}
v3 = 0;
v4 = 0LL;
while ( 1 )
{
if ( *a1 )
{
v6 = my_strlen(*a1);
if ( !(unsigned int)my_strncmp(*a1, environ[v4], v6) )
break;
}
++v3;
if ( !environ[++v4] )
goto LABEL_12;
}
free(environ[v4]);
environ[v4] = v2;
return 1;
}

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 *