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

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

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, _QWORD *a2, __int64 a3, unsigned __int8 a4)
{
__int64 result; // rax
__int64 *v7; // rax
char v8; // dl

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

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

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

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

variable_types:
prev
struct s_pipes *

variable_types:
sub
unsigned char


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

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

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

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

variable_types:
cmd
struct s_cmd *

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

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

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

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

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


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

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

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

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

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

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

variable_types: opt int

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

return_type: void


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

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

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

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

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

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

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


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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

if ( !a1 )
return 0LL;
LODWORD(result) = 0;
do
{
result = (unsigned int)(result + 1);
a1 = *(_QWORD *)(a1 + 16);
}
while ( a1 );
return result;
}

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

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

variable_types: len int

return_type: int

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


decompiled_code:
void __fastcall free_history(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 );
}
}

canonical_decompiled_code:
void __fastcall func3(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 );
}
}

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

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


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

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

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

variable_types: num int


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

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

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

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

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

variable_types:
prog
char *

variable_types: signal int

variable_types:
tab
char **


init

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

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

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


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

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

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

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

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

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

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

variable_types:
value
int *

variable_types: st int

variable_types: pid int


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

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

variable_types:
s
char *

variable_types:
c
char *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

variable_types:
si
unsigned long

variable_types:
ci
unsigned long

variable_types:
r
char *

return_type: char *


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

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

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

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

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

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

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

variable_types:
words
struct s_get **

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

return_type: unsigned char


decompiled_code:
__int64 __fastcall only_option(char *a1)
{
char v1; // si
__int64 result; // rax
char *v3; // rbx

v1 = *a1;
result = 0LL;
if ( *a1 )
{
v3 = a1 + 1;
while ( byte_1B3[my_strilen(byte_1B3, (unsigned int)v1)] )
{
v1 = *v3++;
if ( !v1 )
return 1LL;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // si
__int64 result; // rax
char *v3; // rbx

v1 = *a1;
result = 0LL;
if ( *a1 )
{
v3 = a1 + 1;
while ( byte_1B3[my_strilen(byte_1B3, (unsigned int)v1)] )
{
v1 = *v3++;
if ( !v1 )
return 1LL;
}
result = 0LL;
}
return result;
}

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

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


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

v2 = (_QWORD *)a1;
v3[0] = 0;
move_flag(*(_QWORD **)(a1 + 8), &v2, v3);
if ( (unsigned __int8)print(v3[0], v2) && (v3[0] & 1) == 0 )
my_putstr(&unk_1B7, 1LL);
return 0LL;
}

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

v2 = (_QWORD *)a1;
v3[0] = 0;
func1(*(_QWORD **)(a1 + 8), &v2, v3);
if ( (unsigned __int8)func2(v3[0], v2) && (v3[0] & 1) == 0 )
my_putstr(&unk_1B7, 1LL);
return 0LL;
}

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

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

variable_types:
echo
unsigned int

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


print

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

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

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

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

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

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

variable_types:
end
unsigned char


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

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

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

variable_types:
mod
char **


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

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

variable_types: r int

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


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

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


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

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

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

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

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

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

variable_types:
cmd
char **

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

variable_types: i int


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

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

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

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

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

variable_types:
tab
char **

return_type: char **


rdright

decompiled_code:
int __fastcall rdright(__int64 a1, __int64 a2)
{
int v2; // eax
int *v3; // rbp
int result; // eax

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

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2)
{
int v2; // eax
int *v3; // rbp
int result; // eax

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

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

variable_types:
w
int [3]

variable_types: in int


rleft

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

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

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

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

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

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

variable_types: file int

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


rright

variable_types:
l
int [3]


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

if ( !a1 )
return 1LL;
v6 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 1 )
{
result = rleft(a1, a2, a4);
if ( !(_BYTE)result )
return result;
return calque_redir(*(_QWORD *)(a1 + 24), a2, a3, a4);
}
if ( v6 != 4 )
{
if ( v6 == 2 )
{
rright(a1, a2, *(_QWORD *)(a3 + 96));
}
else if ( v6 == 8 )
{
rdright(a1, a2);
}
return calque_redir(*(_QWORD *)(a1 + 24), a2, a3, a4);
}
result = rdleft();
if ( (_BYTE)result )
return calque_redir(*(_QWORD *)(a1 + 24), a2, a3, a4);
return result;
}

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

if ( !a1 )
return 1LL;
v6 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 1 )
{
result = func1(a1, a2, a4);
if ( !(_BYTE)result )
return result;
return func3(*(_QWORD *)(a1 + 24), a2, a3, a4);
}
if ( v6 != 4 )
{
if ( v6 == 2 )
{
func2(a1, a2, *(_QWORD *)(a3 + 96));
}
else if ( v6 == 8 )
{
func0(a1, a2);
}
return func3(*(_QWORD *)(a1 + 24), a2, a3, a4);
}
result = rdleft();
if ( (_BYTE)result )
return func3(*(_QWORD *)(a1 + 24), a2, a3, a4);
return result;
}

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

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

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

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


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

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

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

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

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

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

variable_types:
word
char *

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

variable_types:
i
unsigned long

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


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

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

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

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

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

return_type: void *


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

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

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

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

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

variable_types: value char


decompiled_code:
char *__fastcall uppercase_first_letter_found(char a1, int *a2, _QWORD *a3)
{
char *result; // rax
char v4; // cl

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

canonical_decompiled_code:
char *__fastcall func1(char a1, int *a2, _QWORD *a3)
{
char *result; // rax
char v4; // cl

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

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


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

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

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

variable_types:
alias
struct s_alias **


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

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

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

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

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

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

variable_types:
alias
void *


main

canonical_name: main

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

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

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

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

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

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


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

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

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


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

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

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

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

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

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

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


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

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

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

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

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


get

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

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

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

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

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

variable_types:
tgetfail
unsigned char

variable_types: rw int

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

variable_types:
r
char *


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

if ( a2 )
{
set_env("PS1", *a1);
free(*a1);
}
else
{
v2 = get_env("PS1");
*a1 = (void *)my_strdup(v2);
set_env("PS1", "> ");
}
}

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

if ( a2 )
{
set_env("PS1", *a1);
free(*a1);
}
else
{
v2 = get_env("PS1");
*a1 = (void *)my_strdup(v2);
set_env("PS1", "> ");
}
}

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

variable_types:
pt
char **

variable_types: lap int


rdleft

decompiled_code:
__int64 __fastcall rdleft(__int64 a1, __int64 a2, __int64 a3)
{
__int64 *v5; // r12
int v6; // edi
int fd; // [rsp+0h] [rbp-28h] BYREF
int v9; // [rsp+4h] [rbp-24h]
void *v10[4]; // [rsp+8h] [rbp-20h] BYREF

set_rd_prompt(v10, 0);
fd = open("/dev/tty", 2);
v5 = get_alls(fd, 0LL, *(_QWORD *)(a1 + 16), a3);
close(fd);
set_rd_prompt(v10, 1);
if ( pipe(&fd) == -1 )
fwrite("pipes error\n", 1uLL, 0xCuLL, stderr);
put_lines(v5, (unsigned int)v9);
v6 = *(_DWORD *)(a2 + 4LL * *(int *)(a1 + 8));
if ( v6 >= 0 )
close(v6);
close(v9);
*(_DWORD *)(a2 + 4LL * *(int *)(a1 + 8)) = fd;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
__int64 *v5; // r12
int v6; // edi
int fd; // [rsp+0h] [rbp-28h] BYREF
int v9; // [rsp+4h] [rbp-24h]
void *v10[4]; // [rsp+8h] [rbp-20h] BYREF

func1(v10, 0);
fd = open("/dev/tty", 2);
v5 = get_alls(fd, 0LL, *(_QWORD *)(a1 + 16), a3);
close(fd);
func1(v10, 1);
if ( pipe(&fd) == -1 )
fwrite("pipes error\n", 1uLL, 0xCuLL, stderr);
func2(v5, (unsigned int)v9);
v6 = *(_DWORD *)(a2 + 4LL * *(int *)(a1 + 8));
if ( v6 >= 0 )
close(v6);
close(v9);
*(_DWORD *)(a2 + 4LL * *(int *)(a1 + 8)) = fd;
return 1LL;
}

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

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

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

variable_types:
w
int [3]

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

variable_types:
pt
char *

variable_types:
p
int [2]


xmalloc

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

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

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

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

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

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

variable_types:
t
unsigned long

variable_types:
r
void *


echappment

decompiled_code:
__int64 __fastcall echappment(_BYTE *a1, _BYTE *a2, _QWORD *a3, char a4)
{
_BYTE *v4; // rbx
__int64 v5; // r12
__int64 v8; // rbp
void *v9; // rbp
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // [rsp+0h] [rbp-48h]

v4 = a1;
v5 = (__int64)a2;
a2[8] = 1;
if ( *a1 == 92 )
{
while ( v4[1] )
{
v9 = *(void **)a2;
v12 = subdiv(v4 + 2, a3);
v10 = my_strilen(" \\\t\"'|;<>()`", (unsigned int)(char)v4[2]);
v11 = my_strncat(v9, v4 + 1, (asc_1B2[v10] == 0) * v12 + 1);
*(_QWORD *)a2 = v11;
if ( !v11 )
return nullify_link(a2, 0, a4);
if ( !asc_1B2[my_strilen(" \\\t\"'|;<>()`", (unsigned int)(char)v4[2])] )
*a3 = 0LL;
if ( v9 )
free(v9);
v8 = subdiv(v4 + 2, a3);
v4 += v8 * (asc_1B2[my_strilen(" \\\t\"'|;<>()`", (unsigned int)(char)v4[2])] == 0) + 2;
if ( *v4 != 92 )
goto LABEL_2;
}
*a3 = my_strdup("(sh): unexpected EOS after echappment character");
v5 = nullify_link(a2, *(_QWORD *)a2 != 0LL, a4);
}
else
{
LABEL_2:
if ( !subdivide(v4, a2, a3) )
v5 = nullify_link(a2, 1, a4);
}
return v5;
}

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

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

variable_types:
s
char *

variable_types:
link
struct s_get *

variable_types:
freud
unsigned char

variable_types:
word
char *

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


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

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

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

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

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

variable_types:
l
unsigned char

variable_types:
f
unsigned char


decompiled_code:
bool __fastcall lvl_parents(__int64 a1, _QWORD *a2)
{
bool result; // al
int v3; // er14
int v4; // er12
__int64 v5; // rbx
_BOOL4 v6; // ebp
_BOOL4 v7; // er13

result = 1;
if ( **(_QWORD **)a1 )
{
v3 = my_strcmp(L"(`)");
if ( !v3 )
{
v4 = 1;
LABEL_5:
result = 1;
if ( *(_BYTE *)(*(_QWORD *)a1 + 8LL) )
return result;
v5 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
if ( !v5 )
{
LABEL_12:
if ( v4 )
*a2 = my_strdup("(sh): unexpected EOS while looking for matching `)'");
if ( v3 )
*a2 = my_strdup("(sh): syntax error near unexpected token ``'");
return (v4 | v3) == 0;
}
if ( !(v4 | v3) )
{
LABEL_8:
v4 = 0;
v3 = 0;
return (v4 | v3) == 0;
}
while ( 1 )
{
v7 = *(_BYTE *)(v5 + 8) == 0;
if ( *(_QWORD *)v5 )
{
v6 = my_strcmp(L"(`)") == 0;
if ( *(_QWORD *)v5 )
{
v4 += ((__PAIR64__(v6, my_strcmp(L")")) - 1) >> 32) * v7;
if ( *(_QWORD *)v5 && !(unsigned int)my_strcmp(L"`)") )
v3 = v3 == 0;
goto LABEL_19;
}
}
else
{
v6 = 0;
}
v4 += v7 && v6;
LABEL_19:
*(_QWORD *)a1 = v5;
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_12;
if ( !(v4 | v3) )
goto LABEL_8;
}
}
if ( !**(_QWORD **)a1 )
return 1;
v4 = my_strcmp(L"`)");
result = 1;
v3 = 1;
if ( !v4 )
goto LABEL_5;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func0(__int64 a1, _QWORD *a2)
{
bool result; // al
int v3; // er14
int v4; // er12
__int64 v5; // rbx
_BOOL4 v6; // ebp
_BOOL4 v7; // er13

result = 1;
if ( **(_QWORD **)a1 )
{
v3 = my_strcmp(L"(`)");
if ( !v3 )
{
v4 = 1;
LABEL_5:
result = 1;
if ( *(_BYTE *)(*(_QWORD *)a1 + 8LL) )
return result;
v5 = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
if ( !v5 )
{
LABEL_12:
if ( v4 )
*a2 = my_strdup("(sh): unexpected EOS while looking for matching `)'");
if ( v3 )
*a2 = my_strdup("(sh): syntax error near unexpected token ``'");
return (v4 | v3) == 0;
}
if ( !(v4 | v3) )
{
LABEL_8:
v4 = 0;
v3 = 0;
return (v4 | v3) == 0;
}
while ( 1 )
{
v7 = *(_BYTE *)(v5 + 8) == 0;
if ( *(_QWORD *)v5 )
{
v6 = my_strcmp(L"(`)") == 0;
if ( *(_QWORD *)v5 )
{
v4 += ((__PAIR64__(v6, my_strcmp(L")")) - 1) >> 32) * v7;
if ( *(_QWORD *)v5 && !(unsigned int)my_strcmp(L"`)") )
v3 = v3 == 0;
goto LABEL_19;
}
}
else
{
v6 = 0;
}
v4 += v7 && v6;
LABEL_19:
*(_QWORD *)a1 = v5;
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_12;
if ( !(v4 | v3) )
goto LABEL_8;
}
}
if ( !**(_QWORD **)a1 )
return 1;
v4 = my_strcmp(L"`)");
result = 1;
v3 = 1;
if ( !v4 )
goto LABEL_5;
}
return result;
}

original_code:
unsigned char lvl_parents(t_get **words, char **bad_sintax)
{
  t_get *link;
  int plevel;
  int blevel;
  plevel = 0;
  if ((!(blevel = (("(" && (*words)->word) ? (!my_strcmp("(", (*words)->word)) : (0)))
       && !(plevel = (("`" && (*words)->word) ? (!my_strcmp("`", (*words)->word)) : (0)))) || (*words)->inter)
    return (1);
  link = (*words)->next;
  while (link && (plevel || blevel))
    {
      blevel = blevel + !(link->inter) * ((("(" && (link)->word) ? (!my_strcmp("(", (link)->word)) : (0))
       - ((")" && (link)->word) ? (!my_strcmp(")", (link)->word)) : (0)));
      if ((("`" && (link)->word) ? (!my_strcmp("`", (link)->word)) : (0)))
 plevel = !plevel;
      *words = link;
      link = link->next;
    }
  if (blevel)
    *bad_sintax = my_strdup("(sh): unexpected EOS while looking for matching `)'");
  if (plevel)
    *bad_sintax = my_strdup("(sh): syntax error near unexpected token ``'");
  if (plevel || blevel)
    return (0);
  return (1);
}

canonical_original_code:
unsigned char lvl_parents(struct s_get **words, char **bad_sintax)
{
  struct s_get *link;
  int plevel;
  int blevel;
  plevel = 0;
  if ((!(blevel = (("(" && (*words)->word) ? (!my_strcmp("(", (*words)->word)) : (0)))
       && !(plevel = (("`" && (*words)->word) ? (!my_strcmp("`", (*words)->word)) : (0)))) || (*words)->inter)
    return (1);
  link = (*words)->next;
  while (link && (plevel || blevel))
    {
      blevel = blevel + !(link->inter) * ((("(" && (link)->word) ? (!my_strcmp("(", (link)->word)) : (0))
       - ((")" && (link)->word) ? (!my_strcmp(")", (link)->word)) : (0)));
      if ((("`" && (link)->word) ? (!my_strcmp("`", (link)->word)) : (0)))
 plevel = !plevel;
      *words = link;
      link = link->next;
    }
  if (blevel)
    *bad_sintax = my_strdup("(sh): unexpected EOS while looking for matching `)'");
  if (plevel)
    *bad_sintax = my_strdup("(sh): syntax error near unexpected token ``'");
  if (plevel || blevel)
    return (0);
  return (1);
}

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

variable_types: plevel int

variable_types: blevel int


decompiled_code:
__int64 __fastcall match_parents(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er14
int v3; // eax
unsigned int v4; // er12
_BOOL4 v5; // ebx
int v6; // ebp
_QWORD *v7; // rbx
int v8; // eax
int v9; // edx

v2 = 1;
if ( **(_QWORD **)a1 )
{
v3 = my_strcmp(L"(`)");
v4 = v3 == 0;
v5 = v3 != 0;
if ( **(_QWORD **)a1 )
v6 = my_strcmp(L"`)") == 0;
else
v6 = 0;
if ( v5 + (v6 ^ 1) == 2 )
return 1;
v2 = *(unsigned __int8 *)(*(_QWORD *)a1 + 8LL);
if ( (_BYTE)v2 )
return 1;
v7 = *(_QWORD **)(*(_QWORD *)a1 + 16LL);
if ( v7 )
{
if ( !(v4 | v6) )
{
LABEL_8:
*(_QWORD *)a1 = v7;
return 1;
}
while ( 1 )
{
if ( *v7 )
{
v4 += my_strcmp(L"(`)") == 0;
if ( *v7 )
{
v4 = (__PAIR64__(v4, my_strcmp(L")")) - 1) >> 32;
if ( *v7 )
{
v8 = my_strcmp(L"`)");
v9 = v6;
v6 ^= 1u;
if ( v8 )
v6 = v9;
}
}
}
*(_QWORD *)a1 = v7;
v7 = (_QWORD *)v7[2];
if ( !v7 )
break;
if ( !(v4 | v6) )
goto LABEL_8;
}
}
if ( v4 )
{
*a2 = my_strdup("(sh): unexpected EOS while looking for matching `)'");
if ( !v6 )
return v2;
}
else if ( !v6 )
{
return 1;
}
*a2 = my_strdup("(sh): syntax error near unexpected token ``'");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er14
int v3; // eax
unsigned int v4; // er12
_BOOL4 v5; // ebx
int v6; // ebp
_QWORD *v7; // rbx
int v8; // eax
int v9; // edx

v2 = 1;
if ( **(_QWORD **)a1 )
{
v3 = my_strcmp(L"(`)");
v4 = v3 == 0;
v5 = v3 != 0;
if ( **(_QWORD **)a1 )
v6 = my_strcmp(L"`)") == 0;
else
v6 = 0;
if ( v5 + (v6 ^ 1) == 2 )
return 1;
v2 = *(unsigned __int8 *)(*(_QWORD *)a1 + 8LL);
if ( (_BYTE)v2 )
return 1;
v7 = *(_QWORD **)(*(_QWORD *)a1 + 16LL);
if ( v7 )
{
if ( !(v4 | v6) )
{
LABEL_8:
*(_QWORD *)a1 = v7;
return 1;
}
while ( 1 )
{
if ( *v7 )
{
v4 += my_strcmp(L"(`)") == 0;
if ( *v7 )
{
v4 = (__PAIR64__(v4, my_strcmp(L")")) - 1) >> 32;
if ( *v7 )
{
v8 = my_strcmp(L"`)");
v9 = v6;
v6 ^= 1u;
if ( v8 )
v6 = v9;
}
}
}
*(_QWORD *)a1 = v7;
v7 = (_QWORD *)v7[2];
if ( !v7 )
break;
if ( !(v4 | v6) )
goto LABEL_8;
}
}
if ( v4 )
{
*a2 = my_strdup("(sh): unexpected EOS while looking for matching `)'");
if ( !v6 )
return v2;
}
else if ( !v6 )
{
return 1;
}
*a2 = my_strdup("(sh): syntax error near unexpected token ``'");
}
return v2;
}

original_code:
unsigned char match_parents(t_get **words, char **bad_sintax)
{
  t_get *link;
  int plevel;
  int blevel;
  if ((!(blevel = (("(" && (*words)->word) ? (!my_strcmp("(", (*words)->word)) : (0)))
       + !(plevel = (("`" && (*words)->word) ? (!my_strcmp("`", (*words)->word)) : (0))) == 2) || (*words)->inter)
    return (1);
  link = (*words)->next;
  while (link && (plevel || blevel))
    {
      blevel = blevel + (("(" && (link)->word) ? (!my_strcmp("(", (link)->word)) : (0)) - ((")" && (link)->word) ? (!my_strcmp(")", (link)->word)) : (0));
      if ((("`" && (link)->word) ? (!my_strcmp("`", (link)->word)) : (0)))
 plevel = !plevel;
      *words = link;
      link = link->next;
    }
  if (blevel)
    *bad_sintax = my_strdup("(sh): unexpected EOS while looking for matching `)'");
  if (plevel)
    *bad_sintax = my_strdup("(sh): syntax error near unexpected token ``'");
  if (plevel || blevel)
    return (0);
  if (link)
    *words = link;
  return (1);
}

canonical_original_code:
unsigned char match_parents(struct s_get **words, char **bad_sintax)
{
  struct s_get *link;
  int plevel;
  int blevel;
  if ((!(blevel = (("(" && (*words)->word) ? (!my_strcmp("(", (*words)->word)) : (0)))
       + !(plevel = (("`" && (*words)->word) ? (!my_strcmp("`", (*words)->word)) : (0))) == 2) || (*words)->inter)
    return (1);
  link = (*words)->next;
  while (link && (plevel || blevel))
    {
      blevel = blevel + (("(" && (link)->word) ? (!my_strcmp("(", (link)->word)) : (0)) - ((")" && (link)->word) ? (!my_strcmp(")", (link)->word)) : (0));
      if ((("`" && (link)->word) ? (!my_strcmp("`", (link)->word)) : (0)))
 plevel = !plevel;
      *words = link;
      link = link->next;
    }
  if (blevel)
    *bad_sintax = my_strdup("(sh): unexpected EOS while looking for matching `)'");
  if (plevel)
    *bad_sintax = my_strdup("(sh): syntax error near unexpected token ``'");
  if (plevel || blevel)
    return (0);
  if (link)
    *words = link;
  return (1);
}

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


decompiled_code:
__int64 __fastcall word_nullify(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 func1(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:
static void *word_nullify(t_get *word)
{
  t_get *next;
  next = word;
  while (next)
    {
      next = word->next;
      free(word->word);
      free(word);
      word = next;
    }
  return (((void *)0));
}

canonical_original_code:
static void *word_nullify(struct s_get *word)
{
  struct s_get *next;
  next = word;
  while (next)
    {
      next = word->next;
      free(word->word);
      free(word);
      word = next;
    }
  return (((void *)0));
}


decompiled_code:
__int64 __fastcall get_pipe(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
_QWORD *v3; // rdx

result = 1LL;
if ( a1 )
{
v3 = assoc_pipes(*(void **)(a1 + 24), 0LL, a2);
*(_QWORD *)(a1 + 16) = v3;
result = 0LL;
if ( v3 )
result = get_pipe(*(_QWORD *)(a1 + 8), a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
_QWORD *v3; // rdx

result = 1LL;
if ( a1 )
{
v3 = assoc_pipes(*(void **)(a1 + 24), 0LL, a2);
*(_QWORD *)(a1 + 16) = v3;
result = 0LL;
if ( v3 )
result = func3(*(_QWORD *)(a1 + 8), a2);
}
return result;
}

original_code:
unsigned char get_pipe(t_exec *execs, char **bad_sintax)
{
  if (!execs)
    return (1);
  if ((execs->pipes = assoc_pipes(execs->tmp, ((void *)0), bad_sintax)) == ((void *)0))
    return (0);
  return (get_pipe(execs->next, bad_sintax));
}

canonical_original_code:
unsigned char get_pipe(struct s_exec *execs, char **bad_sintax)
{
  if (!execs)
    return (1);
  if ((execs->pipes = assoc_pipes(execs->tmp, ((void *)0), bad_sintax)) == ((void *)0))
    return (0);
  return (get_pipe(execs->next, bad_sintax));
}

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


add

decompiled_code:
__int64 __fastcall add(__int64 a1, __int64 a2, _BYTE *a3)
{
__int64 result; // rax
_QWORD *v4; // rbx

result = 0LL;
if ( a1 )
{
*a3 = 0;
v4 = (_QWORD *)xmalloc(16LL);
result = 0LL;
if ( v4 )
{
*v4 = my_strdup(a1);
v4[1] = 0LL;
*(_QWORD *)(*(_QWORD *)a2 + 8LL) = v4;
*(_QWORD *)a2 = v4;
result = 1LL;
}
}
return result;
}

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

result = 0LL;
if ( a1 )
{
*a3 = 0;
v4 = (_QWORD *)xmalloc(16LL);
result = 0LL;
if ( v4 )
{
*v4 = my_strdup(a1);
v4[1] = 0LL;
*(_QWORD *)(*(_QWORD *)a2 + 8LL) = v4;
*(_QWORD *)a2 = v4;
result = 1LL;
}
}
return result;
}

original_code:
static unsigned char add(char *name, t_words **last, unsigned char *no_match)
{
  t_words *link;
  if (!name)
    return (0);
  *no_match = 0;
  if ((link = xmalloc(sizeof(*link))) == ((void *)0))
    return (0);
  link->word = my_strdup(name);
  link->next = ((void *)0);
  (*last)->next = link;
  *last = link;
  return (1);
}

canonical_original_code:
static unsigned char add(char *name, struct s_words **last, unsigned char *no_match)
{
  struct s_words *link;
  if (!name)
    return (0);
  *no_match = 0;
  if ((link = xmalloc(sizeof(*link))) == ((void *)0))
    return (0);
  link->word = my_strdup(name);
  link->next = ((void *)0);
  (*last)->next = link;
  *last = link;
  return (1);
}

variable_types:
name
char *

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


decompiled_code:
__int64 __fastcall add_and_last(_BYTE *a1, void *a2, __int64 a3, _BYTE *a4)
{
void *v6; // r12
__int64 result; // rax

if ( *a1 && a2 )
{
v6 = (void *)my_stricat(a2, a1, 47LL);
}
else
{
v6 = a2;
if ( !a2 )
{
v6 = (void *)my_strdup(a1);
result = add((__int64)v6, a3, a4);
if ( !(_BYTE)result )
return result;
goto LABEL_10;
}
}
result = add((__int64)v6, a3, a4);
if ( !(_BYTE)result )
return result;
free(a2);
LABEL_10:
result = 1LL;
if ( *a1 )
{
free(v6);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, void *a2, __int64 a3, _BYTE *a4)
{
void *v6; // r12
__int64 result; // rax

if ( *a1 && a2 )
{
v6 = (void *)my_stricat(a2, a1, 47LL);
}
else
{
v6 = a2;
if ( !a2 )
{
v6 = (void *)my_strdup(a1);
result = func0((__int64)v6, a3, a4);
if ( !(_BYTE)result )
return result;
goto LABEL_10;
}
}
result = func0((__int64)v6, a3, a4);
if ( !(_BYTE)result )
return result;
free(a2);
LABEL_10:
result = 1LL;
if ( *a1 )
{
free(v6);
result = 1LL;
}
return result;
}

original_code:
unsigned char add_and_last(char *m, char *dp, t_words **last, unsigned char *no_match)
{
  char *s;
  if (m[0] && (dp) != ((void *)0))
    s = my_stricat(dp, m, '/');
  else if (dp != ((void *)0))
    s = dp;
  else
    s = my_strdup(m);
  if (add(s, last, no_match) == 0)
    return (0);
  if (dp)
    free(dp);
  if (m[0])
    free(s);
  return (1);
}

canonical_original_code:
unsigned char add_and_last(char *m, char *dp, struct s_words **last, unsigned char *no_match)
{
  char *s;
  if (m[0] && (dp) != ((void *)0))
    s = my_stricat(dp, m, '/');
  else if (dp != ((void *)0))
    s = dp;
  else
    s = my_strdup(m);
  if (add(s, last, no_match) == 0)
    return (0);
  if (dp)
    free(dp);
  if (m[0])
    free(s);
  return (1);
}

variable_types:
m
char *

variable_types:
dp
char *


original_code:
void auto_completion(char value, int *rev_c, char **cmd)
{
  char *dir;
  char *s;
  (void)value;
  s = my_strndup(*cmd + lastoccur_bf(*cmd, ' ', *rev_c) +
   ((*cmd)[lastoccur_bf(*cmd, ' ', *rev_c)] == ' '), *rev_c -
   lastoccur_bf(*cmd, ' ', *rev_c));
  if (!s || empty(s))
    dir = (s = ((void *)0));
  else
    dir = my_strndup(s, lastoccur_bf(s, '/', my_strlen(s)) +
       ((s)[my_strilen(s, '/')] != 0));
  go_down_of_cmd_high(*cmd);
  printf("\n");
  if (dir)
    print_complo(dir, s + ((s)[my_strilen(s, '/')] != 0) * (lastoccur_bf(s, '/',
           my_strlen(s)) + 1));
  else
    print_complo(".", s);
  if (dir)
    free(dir);
  prompt(1);
}

variable_types: value char

variable_types:
cmd
char **

variable_types:
dir
char *


decompiled_code:
__int64 __fastcall my_realloc(void *ptr, unsigned __int64 a2, __int64 a3)
{
__int64 v4; // rbx
unsigned __int64 v5; // rax

v4 = xmalloc(a3);
if ( v4 )
{
if ( a3 )
{
v5 = 0LL;
do
{
if ( a2 <= v5 )
*(_BYTE *)(v4 + v5) = 0;
else
*(_BYTE *)(v4 + v5) = *((_BYTE *)ptr + v5);
++v5;
}
while ( a3 != v5 );
}
free(ptr);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr, unsigned __int64 a2, __int64 a3)
{
__int64 v4; // rbx
unsigned __int64 v5; // rax

v4 = xmalloc(a3);
if ( v4 )
{
if ( a3 )
{
v5 = 0LL;
do
{
if ( a2 <= v5 )
*(_BYTE *)(v4 + v5) = 0;
else
*(_BYTE *)(v4 + v5) = *((_BYTE *)ptr + v5);
++v5;
}
while ( a3 != v5 );
}
free(ptr);
}
return v4;
}

original_code:
void *my_realloc(void *ptr, size_t pre, size_t new)
{
  size_t i;
  void *r;
  i = 0;
  if ((r = xmalloc(new)) == ((void *)0))
    return (((void *)0));
  while (i < new)
    {
      if (i < pre)
 *(unsigned char*)(r + i) = *(unsigned char*)(ptr + i);
      else
 *(unsigned char*)(r + i) = 0;
      i++;
    }
  free(ptr);
  return (r);
}

canonical_original_code:
void *my_realloc(void *ptr, unsigned long pre, unsigned long new)
{
  unsigned long i;
  void *r;
  i = 0;
  if ((r = xmalloc(new)) == ((void *)0))
    return (((void *)0));
  while (i < new)
    {
      if (i < pre)
 *(unsigned char *)(r + i) = *(unsigned char *)(ptr + i);
      else
 *(unsigned char *)(r + i) = 0;
      i++;
    }
  free(ptr);
  return (r);
}

variable_types:
ptr
void *

variable_types:
pre
unsigned long

variable_types:
new
unsigned long

variable_types:
i
unsigned long

variable_types:
r
void *


decompiled_code:
__int64 __fastcall built_setenv(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v2; // rdx
__int64 result; // rax
_QWORD *v4; // rbp
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // r13
char *v8; // r15
__int64 v9; // r12
__int64 v10; // rax
char **v11; // rdi
__int64 *v12; // rax

if ( !a1[1] )
return built_env();
v1 = *a1;
v2 = my_strilen(*a1, 61LL);
result = 0LL;
if ( !*(_BYTE *)(v1 + v2) )
{
v4 = (_QWORD *)a1[1];
if ( v4 && (v5 = v4[1]) != 0 && *(_QWORD *)(v5 + 8) )
{
result = my_putstr("(sh): setenv : Too many arguments.\n", 2LL) != 0;
}
else
{
if ( environ )
{
if ( *environ )
{
v6 = 0LL;
v7 = 0LL;
do
{
v9 = v6;
if ( *v4 )
{
v10 = my_strlen(*v4);
if ( !(unsigned int)my_strncmp(*v4, environ[v6], v10) )
{
v8 = environ[v6];
if ( v8[my_strlen(*v4)] == 61 )
v7 = 1LL;
}
}
++v6;
}
while ( environ[v9 + 1] );
}
else
{
v6 = 0LL;
v7 = 0LL;
}
}
else
{
v6 = 0LL;
v7 = 0LL;
}
v11 = (char **)xmalloc(8 * ((v7 == 0) + v6 + 1));
if ( v11 )
{
v12 = (__int64 *)v4[1];
if ( v12 )
result = fill_env(v11, v4, *v12);
else
result = fill_env(v11, v4, 0LL);
}
else
{
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 v1; // rbp
__int64 v2; // rdx
__int64 result; // rax
_QWORD *v4; // rbp
__int64 v5; // rax
__int64 v6; // rbx
__int64 v7; // r13
char *v8; // r15
__int64 v9; // r12
__int64 v10; // rax
char **v11; // rdi
__int64 *v12; // rax

if ( !a1[1] )
return built_env();
v1 = *a1;
v2 = my_strilen(*a1, 61LL);
result = 0LL;
if ( !*(_BYTE *)(v1 + v2) )
{
v4 = (_QWORD *)a1[1];
if ( v4 && (v5 = v4[1]) != 0 && *(_QWORD *)(v5 + 8) )
{
result = my_putstr("(sh): setenv : Too many arguments.\n", 2LL) != 0;
}
else
{
if ( environ )
{
if ( *environ )
{
v6 = 0LL;
v7 = 0LL;
do
{
v9 = v6;
if ( *v4 )
{
v10 = my_strlen(*v4);
if ( !(unsigned int)my_strncmp(*v4, environ[v6], v10) )
{
v8 = environ[v6];
if ( v8[my_strlen(*v4)] == 61 )
v7 = 1LL;
}
}
++v6;
}
while ( environ[v9 + 1] );
}
else
{
v6 = 0LL;
v7 = 0LL;
}
}
else
{
v6 = 0LL;
v7 = 0LL;
}
v11 = (char **)xmalloc(8 * ((v7 == 0) + v6 + 1));
if ( v11 )
{
v12 = (__int64 *)v4[1];
if ( v12 )
result = func0(v11, v4, *v12);
else
result = func0(v11, v4, 0LL);
}
else
{
result = 1LL;
}
}
}
return result;
}

original_code:
int built_setenv(t_words *cmd, void *bool)
{
  size_t n;
  size_t i;
  char **tab;
  (void)bool;
  if (cmd->next == ((void*)(n = (i = 0))))
    return (built_env(cmd, bool));
  if (((cmd->word)[my_strilen(cmd->word, '=')] != 0))
    return (0);
  if ((cmd = cmd->next) && cmd->next)
    if (cmd->next->next)
      return (my_putstr("(sh): setenv : Too many arguments.\n", 2) != 0);
  if (environ)
    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)] == '=')
   n = 1;
 i++;
      }
  if ((tab = xmalloc(sizeof(char *) * (i + !n + 1))) == ((void *)0))
    return (1);
  if (cmd->next)
    return (fill_env(tab, cmd, cmd->next->word));
  return (fill_env(tab, cmd, ((void *)0)));
}

canonical_original_code:
int built_setenv(struct s_words *cmd, void *bool)
{
  unsigned long n;
  unsigned long i;
  char **tab;
  (void)bool;
  if (cmd->next == ((void *)(n = (i = 0))))
    return (built_env(cmd, bool));
  if (((cmd->word)[my_strilen(cmd->word, '=')] != 0))
    return (0);
  if ((cmd = cmd->next) && cmd->next)
    if (cmd->next->next)
      return (my_putstr("(sh): setenv : Too many arguments.\n", 2) != 0);
  if (environ)
    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)] == '=')
   n = 1;
 i++;
      }
  if ((tab = xmalloc(sizeof(char *) * (i + !n + 1))) == ((void *)0))
    return (1);
  if (cmd->next)
    return (fill_env(tab, cmd, cmd->next->word));
  return (fill_env(tab, cmd, ((void *)0)));
}

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

variable_types:
bool
void *

variable_types:
n
unsigned long

variable_types:
tab
char **


decompiled_code:
__int64 __fastcall fill_env(char **a1, _QWORD *a2, __int64 a3)
{
char v3; // r15
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rbp
__int64 v7; // rax
char *v8; // r14

if ( !*environ )
{
v4 = 0LL;
v5 = 0LL;
LABEL_12:
++v4;
*(char **)((char *)a1 + v5) = (char *)my_stricat(*a2, a3, 61LL);
goto LABEL_10;
}
v3 = 0;
v4 = 0LL;
do
{
v6 = v4;
if ( *a2
&& (v7 = ((__int64 (*)(void))my_strlen)(), !(unsigned int)my_strncmp(*a2, environ[v4], v7))
&& (v8 = environ[v4], v8[my_strlen(*a2)] == 61) )
{
free(environ[v4]);
a1[v4] = (char *)my_stricat(*a2, a3, 61LL);
v3 = 1;
}
else
{
a1[v4] = environ[v4];
}
++v4;
v5 = v6 * 8 + 8;
}
while ( environ[v6 + 1] );
if ( !v3 )
goto LABEL_12;
LABEL_10:
a1[v4] = 0LL;
free(environ);
environ = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char **a1, _QWORD *a2, __int64 a3)
{
char v3; // r15
__int64 v4; // rbx
__int64 v5; // rdx
__int64 v6; // rbp
__int64 v7; // rax
char *v8; // r14

if ( !*environ )
{
v4 = 0LL;
v5 = 0LL;
LABEL_12:
++v4;
*(char **)((char *)a1 + v5) = (char *)my_stricat(*a2, a3, 61LL);
goto LABEL_10;
}
v3 = 0;
v4 = 0LL;
do
{
v6 = v4;
if ( *a2
&& (v7 = ((__int64 (*)(void))my_strlen)(), !(unsigned int)my_strncmp(*a2, environ[v4], v7))
&& (v8 = environ[v4], v8[my_strlen(*a2)] == 61) )
{
free(environ[v4]);
a1[v4] = (char *)my_stricat(*a2, a3, 61LL);
v3 = 1;
}
else
{
a1[v4] = environ[v4];
}
++v4;
v5 = v6 * 8 + 8;
}
while ( environ[v6 + 1] );
if ( !v3 )
goto LABEL_12;
LABEL_10:
a1[v4] = 0LL;
free(environ);
environ = a1;
return 0LL;
}

original_code:
static int fill_env(char **tab, t_words *cmd, char *s)
{
  size_t i;
  unsigned char n;
  i = (n = 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[i] = environ[i];
      else
 {
   n = 1;
   free(environ[i]);
   tab[i] = my_stricat(cmd->word, s, '=');
 }
      i++;
    }
  if (n == 0)
    tab[i++] = my_stricat(cmd->word, s, '=');
  tab[i] = ((void *)0);
  free(environ);
  environ = tab;
  return (0);
}

canonical_original_code:
static int fill_env(char **tab, struct s_words *cmd, char *s)
{
  unsigned long i;
  unsigned char n;
  i = (n = 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[i] = environ[i];
      else
 {
   n = 1;
   free(environ[i]);
   tab[i] = my_stricat(cmd->word, s, '=');
 }
      i++;
    }
  if (n == 0)
    tab[i++] = my_stricat(cmd->word, s, '=');
  tab[i] = ((void *)0);
  free(environ);
  environ = tab;
  return (0);
}

variable_types:
s
char *

variable_types:
n
unsigned char


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

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


decompiled_code:
__int64 __fastcall PBI_BB_Initialise(int *a1, __int64 a2)
{
int v4; // er12
int v5; // ebx
const char **v6; // rbp
bool v7; // r8
bool v8; // cf
bool v9; // zf
__int64 v10; // rcx
const char *v11; // rsi
const char *v12; // rdi

if ( *a1 <= 1 )
{
v4 = 1;
}
else
{
v4 = 1;
v5 = 1;
do
{
v6 = (const char **)(a2 + 8LL * v5);
v7 = strcmp(*v6, "-bb") != 0;
v8 = 0;
v9 = !v7;
if ( v7 )
{
v10 = 6LL;
v11 = *v6;
v12 = "-help";
do
{
if ( !v10 )
break;
v8 = *v11 < (unsigned int)*v12;
v9 = *v11++ == *v12++;
--v10;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
Log_print("\t-bb Emulate the CSS Black Box", v11, *v6, v10);
*(_QWORD *)(a2 + 8LL * v4++) = *v6;
}
else
{
init_bb();
}
++v5;
}
while ( *a1 > v5 );
}
*a1 = v4;
return 1LL;
}

original_code:
int PBI_BB_Initialise(int *argc, char *argv[])
{
 int i, j;
 for (i = j = 1; i < *argc; i++) {
  if (strcmp(argv[i], "-bb") == 0) {
   init_bb();
  }
  else {
    if (strcmp(argv[i], "-help") == 0) {
    Log_print("\t-bb              Emulate the CSS Black Box");
   }
   argv[j++] = argv[i];
  }
 }
 *argc = j;
 return 1;
}

canonical_original_code:
int PBI_BB_Initialise(int *argc, char *argv[])
{
 int i; int j;
 for (i = j = 1; i < *argc; i++) {
  if (strcmp(argv[i], "-bb") == 0) {
   init_bb();
  }
  else {
    if (strcmp(argv[i], "-help") == 0) {
    Log_print("\t-bb              Emulate the CSS Black Box");
   }
   argv[j++] = argv[i];
  }
 }
 *argc = j;
 return 1;
}

variable_types:
argc
int *

variable_types:
argv
char *[]

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall PBI_BB_ReadConfig(const char *a1, __int64 a2)
{
unsigned int v2; // er10

if ( !strcmp(a1, "BLACK_BOX_ROM") )
{
Util_strlcpy(bb_rom_filename, a2, 4096LL);
v2 = 1;
}
else
{
v2 = 0;
if ( !strcmp(a1, "BB_SCSI_DISK") )
{
Util_strlcpy(&bb_scsi_disk_filename, a2, 4096LL);
v2 = 1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, __int64 a2)
{
unsigned int v2; // er10

if ( !strcmp(a1, "BLACK_BOX_ROM") )
{
Util_strlcpy(bb_rom_filename, a2, 4096LL);
v2 = 1;
}
else
{
v2 = 0;
if ( !strcmp(a1, "BB_SCSI_DISK") )
{
Util_strlcpy(&bb_scsi_disk_filename, a2, 4096LL);
v2 = 1;
}
}
return v2;
}

original_code:
int PBI_BB_ReadConfig(char *string, char *ptr)
{
 if (strcmp(string, "BLACK_BOX_ROM") == 0)
  Util_strlcpy(bb_rom_filename, ptr, sizeof(bb_rom_filename));
 else if (strcmp(string, "BB_SCSI_DISK") == 0)
  Util_strlcpy(bb_scsi_disk_filename, ptr, sizeof(bb_scsi_disk_filename));
 else return 0;
 return 1;
}

variable_types:
string
char *

variable_types:
ptr
char *


decompiled_code:
__int64 __fastcall PBI_BB_D1GetByte(__int16 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6)
{
int v6; // er11
unsigned int v7; // ebx
_DWORD *v8; // rcx

v7 = -1;
if ( a1 != -11842 )
{
if ( a1 == -11920 )
{
v8 = &PBI_SCSI_REQ;
LOBYTE(v8) = PBI_SCSI_BSY == 0;
LOBYTE(a6) = PBI_SCSI_SEL == 0;
LOBYTE(v6) = PBI_SCSI_CD == 0;
LOBYTE(v7) = PBI_SCSI_IO == 0;
v7 |= (2 * v6) | (4 * a6) | ((_DWORD)v8 << 6) | (PBI_SCSI_REQ == 0 ? 0xFFFFFF80 : 0);
}
else if ( a1 == -11919 )
{
v7 = 0;
if ( bb_scsi_enabled )
{
v7 = PBI_SCSI_GetByte();
if ( (((int)(unsigned __int8)bb_PCR >> 1) & 7) == 4 )
{
PBI_SCSI_PutACK(1LL);
PBI_SCSI_PutACK(0LL);
}
}
}
else
{
v7 = (unsigned __int8)byte_2A99;
if ( a1 != -11844 )
{
v7 = 0;
if ( a1 == -11777 )
v7 = PBI_IRQ != 0 ? 0xA : 0;
}
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, int a6)
{
int v6; // er11
unsigned int v7; // ebx
_DWORD *v8; // rcx

v7 = -1;
if ( a1 != -11842 )
{
if ( a1 == -11920 )
{
v8 = &PBI_SCSI_REQ;
LOBYTE(v8) = PBI_SCSI_BSY == 0;
LOBYTE(a6) = PBI_SCSI_SEL == 0;
LOBYTE(v6) = PBI_SCSI_CD == 0;
LOBYTE(v7) = PBI_SCSI_IO == 0;
v7 |= (2 * v6) | (4 * a6) | ((_DWORD)v8 << 6) | (PBI_SCSI_REQ == 0 ? 0xFFFFFF80 : 0);
}
else if ( a1 == -11919 )
{
v7 = 0;
if ( bb_scsi_enabled )
{
v7 = PBI_SCSI_GetByte();
if ( (((int)(unsigned __int8)bb_PCR >> 1) & 7) == 4 )
{
PBI_SCSI_PutACK(1LL);
PBI_SCSI_PutACK(0LL);
}
}
}
else
{
v7 = (unsigned __int8)byte_2A99;
if ( a1 != -11844 )
{
v7 = 0;
if ( a1 == -11777 )
v7 = PBI_IRQ != 0 ? 0xA : 0;
}
}
}
return v7;
}

original_code:
unsigned char PBI_BB_D1GetByte(unsigned short addr)
{
 unsigned char result = 0x00;
 if (addr == 0xd1be) result = 0xff;
 else if (addr == 0xd170) {
  result = ((!(PBI_SCSI_REQ))<<7)|((!PBI_SCSI_BSY)<<6)|((!PBI_SCSI_SEL)<<2)|((!PBI_SCSI_CD)<<1)|(!PBI_SCSI_IO);
 }
 else if (addr == 0xd171) {
  if (bb_scsi_enabled) {
   result = PBI_SCSI_GetByte();
   if (((bb_PCR & 0x0e)>>1) == 0x04) {
    PBI_SCSI_PutACK(1);
    PBI_SCSI_PutACK(0);
   }
  }
 }
 else if (addr == 0xd1bc) result = (bb_ram_bank_offset >> 8);
 else if (addr == 0xd1be) {
  result = 0x02;
 }
 else if (addr == 0xd1ff) result = PBI_IRQ ? (0x08 | 0x02) : 0 ;
 do{}while(0);
 return result;
}

variable_types:
addr
unsigned short

variable_types:
result
unsigned char


decompiled_code:
__int64 __fastcall PBI_BB_D1PutByte(__int16 a1, unsigned int a2)
{
__int64 result; // rax
int v3; // esi
char *v4; // rsi
__m128i *v5; // r9
const __m128i *v6; // r11
__int64 v7; // r8
int v8; // er9
char *v9; // rsi

result = a2;
switch ( a1 )
{
case -11920:
if ( bb_scsi_enabled )
result = PBI_SCSI_PutSEL((((unsigned __int8)a2 >> 2) ^ 1) & 1);
break;
case -11919:
if ( bb_scsi_enabled )
{
result = PBI_SCSI_PutByte((unsigned __int8)a2);
if ( (((int)(unsigned __int8)bb_PCR >> 1) & 7) == 4 )
{
PBI_SCSI_PutACK(1LL);
result = PBI_SCSI_PutACK(0LL);
}
}
break;
case -11908:
bb_PCR = a2;
result = (a2 >> 1) & 7;
if ( (_DWORD)result == 6 )
{
if ( bb_scsi_enabled )
result = PBI_SCSI_PutACK(1LL);
}
else if ( (_DWORD)result == 7 && bb_scsi_enabled )
{
result = PBI_SCSI_PutACK(0LL);
}
break;
case -11844:
v5 = (__m128i *)(bb_ram + bb_ram_bank_offset);
*v5 = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3424);
v5[1] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3425);
v5[2] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3426);
v5[3] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3427);
v5[4] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3428);
v5[5] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3429);
v5[6] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3430);
v5[7] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3431);
v5[8] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3432);
v5[9] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3433);
v5[10] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3434);
v5[11] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3435);
v5[12] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3436);
v5[13] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3437);
v5[14] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3438);
v5[15] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3439);
result = (unsigned __int8)a2 << 8;
bb_ram_bank_offset = result;
v6 = (const __m128i *)(bb_ram + (int)result);
*((__m128i *)&MEMORY_mem + 3424) = _mm_loadu_si128(v6);
*((__m128i *)&MEMORY_mem + 3425) = _mm_loadu_si128(v6 + 1);
*((__m128i *)&MEMORY_mem + 3426) = _mm_loadu_si128(v6 + 2);
*((__m128i *)&MEMORY_mem + 3427) = _mm_loadu_si128(v6 + 3);
*((__m128i *)&MEMORY_mem + 3428) = _mm_loadu_si128(v6 + 4);
*((__m128i *)&MEMORY_mem + 3429) = _mm_loadu_si128(v6 + 5);
*((__m128i *)&MEMORY_mem + 3430) = _mm_loadu_si128(v6 + 6);
*((__m128i *)&MEMORY_mem + 3431) = _mm_loadu_si128(v6 + 7);
*((__m128i *)&MEMORY_mem + 3432) = _mm_loadu_si128(v6 + 8);
*((__m128i *)&MEMORY_mem + 3433) = _mm_loadu_si128(v6 + 9);
*((__m128i *)&MEMORY_mem + 3434) = _mm_loadu_si128(v6 + 10);
*((__m128i *)&MEMORY_mem + 3435) = _mm_loadu_si128(v6 + 11);
*((__m128i *)&MEMORY_mem + 3436) = _mm_loadu_si128(v6 + 12);
*((__m128i *)&MEMORY_mem + 3437) = _mm_loadu_si128(v6 + 13);
*((__m128i *)&MEMORY_mem + 3438) = _mm_loadu_si128(v6 + 14);
v7 = v6[15].m128i_i64[1];
*((_QWORD *)&MEMORY_mem + 6878) = v6[15].m128i_i64[0];
*((_QWORD *)&MEMORY_mem + 6879) = v7;
return result;
case -11842:
v8 = (4 * (_BYTE)a2) & 0x10;
if ( v8 != bb_rom_high_bit && bb_rom_size == 0x10000 )
{
bb_rom_high_bit = (4 * (_BYTE)a2) & 0x10;
result = (unsigned __int8)bb_rom_bank;
if ( (unsigned __int8)(bb_rom_bank - 1) <= 6u )
{
v9 = (char *)bb_rom + 2048 * ((unsigned __int8)bb_rom_bank + v8);
*((_QWORD *)&MEMORY_mem + 6912) = *(_QWORD *)v9;
*((_QWORD *)&MEMORY_mem + 7167) = *((_QWORD *)v9 + 255);
qmemcpy(
(void *)(((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v9
- ((char *)&MEMORY_mem
- (((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL)
+ 55296)),
8LL * (((unsigned int)&MEMORY_mem + 55296 - (((unsigned int)&MEMORY_mem + 55304) & 0xFFFFFFF8) + 2048) >> 3));
}
}
break;
default:
if ( (a1 & 0xFFC0) == 0xD1C0 && bb_rom_bank != (_BYTE)a2 )
{
if ( bb_rom_size == 0x4000 )
{
if ( (unsigned __int8)(a2 - 8) <= 7u )
{
v3 = ((unsigned __int8)a2 - 8) << 11;
goto LABEL_11;
}
if ( (unsigned __int8)(a2 - 1) <= 6u )
{
v3 = (unsigned __int8)a2 << 11;
goto LABEL_11;
}
}
else if ( (unsigned __int8)(a2 - 1) <= 0xEu )
{
v3 = (bb_rom_high_bit + (unsigned __int8)a2) << 11;
LABEL_11:
v4 = (char *)bb_rom + v3;
*((_QWORD *)&MEMORY_mem + 6912) = *(_QWORD *)v4;
*((_QWORD *)&MEMORY_mem + 7167) = *((_QWORD *)v4 + 255);
qmemcpy(
(void *)(((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v4
- ((char *)&MEMORY_mem
- (((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL)
+ 55296)),
8LL * (((unsigned int)&MEMORY_mem + 55296 - (((unsigned int)&MEMORY_mem + 55304) & 0xFFFFFFF8) + 2048) >> 3));
LABEL_34:
bb_rom_bank = result;
return result;
}
*((_QWORD *)&MEMORY_mem + 6912) = MEMORY_os[768];
*((_QWORD *)&MEMORY_mem + 7167) = MEMORY_os[1023];
qmemcpy(
(void *)(((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)&MEMORY_os[768]
- ((char *)&MEMORY_mem
- (((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL)
+ 55296)),
8LL * (((unsigned int)&MEMORY_mem + 55296 - (((unsigned int)&MEMORY_mem + 55304) & 0xFFFFFFF8) + 2048) >> 3));
goto LABEL_34;
}
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int16 a1, unsigned int a2)
{
__int64 result; // rax
int v3; // esi
char *v4; // rsi
__m128i *v5; // r9
const __m128i *v6; // r11
__int64 v7; // r8
int v8; // er9
char *v9; // rsi

result = a2;
switch ( a1 )
{
case -11920:
if ( bb_scsi_enabled )
result = PBI_SCSI_PutSEL((((unsigned __int8)a2 >> 2) ^ 1) & 1);
break;
case -11919:
if ( bb_scsi_enabled )
{
result = PBI_SCSI_PutByte((unsigned __int8)a2);
if ( (((int)(unsigned __int8)bb_PCR >> 1) & 7) == 4 )
{
PBI_SCSI_PutACK(1LL);
result = PBI_SCSI_PutACK(0LL);
}
}
break;
case -11908:
bb_PCR = a2;
result = (a2 >> 1) & 7;
if ( (_DWORD)result == 6 )
{
if ( bb_scsi_enabled )
result = PBI_SCSI_PutACK(1LL);
}
else if ( (_DWORD)result == 7 && bb_scsi_enabled )
{
result = PBI_SCSI_PutACK(0LL);
}
break;
case -11844:
v5 = (__m128i *)(bb_ram + bb_ram_bank_offset);
*v5 = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3424);
v5[1] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3425);
v5[2] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3426);
v5[3] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3427);
v5[4] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3428);
v5[5] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3429);
v5[6] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3430);
v5[7] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3431);
v5[8] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3432);
v5[9] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3433);
v5[10] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3434);
v5[11] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3435);
v5[12] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3436);
v5[13] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3437);
v5[14] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3438);
v5[15] = _mm_loadu_si128((const __m128i *)&MEMORY_mem + 3439);
result = (unsigned __int8)a2 << 8;
bb_ram_bank_offset = result;
v6 = (const __m128i *)(bb_ram + (int)result);
*((__m128i *)&MEMORY_mem + 3424) = _mm_loadu_si128(v6);
*((__m128i *)&MEMORY_mem + 3425) = _mm_loadu_si128(v6 + 1);
*((__m128i *)&MEMORY_mem + 3426) = _mm_loadu_si128(v6 + 2);
*((__m128i *)&MEMORY_mem + 3427) = _mm_loadu_si128(v6 + 3);
*((__m128i *)&MEMORY_mem + 3428) = _mm_loadu_si128(v6 + 4);
*((__m128i *)&MEMORY_mem + 3429) = _mm_loadu_si128(v6 + 5);
*((__m128i *)&MEMORY_mem + 3430) = _mm_loadu_si128(v6 + 6);
*((__m128i *)&MEMORY_mem + 3431) = _mm_loadu_si128(v6 + 7);
*((__m128i *)&MEMORY_mem + 3432) = _mm_loadu_si128(v6 + 8);
*((__m128i *)&MEMORY_mem + 3433) = _mm_loadu_si128(v6 + 9);
*((__m128i *)&MEMORY_mem + 3434) = _mm_loadu_si128(v6 + 10);
*((__m128i *)&MEMORY_mem + 3435) = _mm_loadu_si128(v6 + 11);
*((__m128i *)&MEMORY_mem + 3436) = _mm_loadu_si128(v6 + 12);
*((__m128i *)&MEMORY_mem + 3437) = _mm_loadu_si128(v6 + 13);
*((__m128i *)&MEMORY_mem + 3438) = _mm_loadu_si128(v6 + 14);
v7 = v6[15].m128i_i64[1];
*((_QWORD *)&MEMORY_mem + 6878) = v6[15].m128i_i64[0];
*((_QWORD *)&MEMORY_mem + 6879) = v7;
return result;
case -11842:
v8 = (4 * (_BYTE)a2) & 0x10;
if ( v8 != bb_rom_high_bit && bb_rom_size == 0x10000 )
{
bb_rom_high_bit = (4 * (_BYTE)a2) & 0x10;
result = (unsigned __int8)bb_rom_bank;
if ( (unsigned __int8)(bb_rom_bank - 1) <= 6u )
{
v9 = (char *)bb_rom + 2048 * ((unsigned __int8)bb_rom_bank + v8);
*((_QWORD *)&MEMORY_mem + 6912) = *(_QWORD *)v9;
*((_QWORD *)&MEMORY_mem + 7167) = *((_QWORD *)v9 + 255);
qmemcpy(
(void *)(((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v9
- ((char *)&MEMORY_mem
- (((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL)
+ 55296)),
8LL * (((unsigned int)&MEMORY_mem + 55296 - (((unsigned int)&MEMORY_mem + 55304) & 0xFFFFFFF8) + 2048) >> 3));
}
}
break;
default:
if ( (a1 & 0xFFC0) == 0xD1C0 && bb_rom_bank != (_BYTE)a2 )
{
if ( bb_rom_size == 0x4000 )
{
if ( (unsigned __int8)(a2 - 8) <= 7u )
{
v3 = ((unsigned __int8)a2 - 8) << 11;
goto LABEL_11;
}
if ( (unsigned __int8)(a2 - 1) <= 6u )
{
v3 = (unsigned __int8)a2 << 11;
goto LABEL_11;
}
}
else if ( (unsigned __int8)(a2 - 1) <= 0xEu )
{
v3 = (bb_rom_high_bit + (unsigned __int8)a2) << 11;
LABEL_11:
v4 = (char *)bb_rom + v3;
*((_QWORD *)&MEMORY_mem + 6912) = *(_QWORD *)v4;
*((_QWORD *)&MEMORY_mem + 7167) = *((_QWORD *)v4 + 255);
qmemcpy(
(void *)(((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v4
- ((char *)&MEMORY_mem
- (((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL)
+ 55296)),
8LL * (((unsigned int)&MEMORY_mem + 55296 - (((unsigned int)&MEMORY_mem + 55304) & 0xFFFFFFF8) + 2048) >> 3));
LABEL_34:
bb_rom_bank = result;
return result;
}
*((_QWORD *)&MEMORY_mem + 6912) = MEMORY_os[768];
*((_QWORD *)&MEMORY_mem + 7167) = MEMORY_os[1023];
qmemcpy(
(void *)(((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)&MEMORY_os[768]
- ((char *)&MEMORY_mem
- (((unsigned __int64)&MEMORY_mem + 55304) & 0xFFFFFFFFFFFFFFF8LL)
+ 55296)),
8LL * (((unsigned int)&MEMORY_mem + 55296 - (((unsigned int)&MEMORY_mem + 55304) & 0xFFFFFFF8) + 2048) >> 3));
goto LABEL_34;
}
break;
}
return result;
}

original_code:
void PBI_BB_D1PutByte(unsigned short addr, unsigned char byte)
{
 do{}while(0);
 if (addr == 0xd170) {
  if (bb_scsi_enabled) PBI_SCSI_PutSEL(!(byte&0x04));
 }
 else if (addr == 0xd171) {
  if (bb_scsi_enabled) {
   PBI_SCSI_PutByte(byte);
   if (((bb_PCR & 0x0e)>>1) == 0x04) {
    PBI_SCSI_PutACK(1);
    PBI_SCSI_PutACK(0);
   }
  }
 }
 else if (addr == 0xd17c) {
  bb_PCR = byte;
  if (((bb_PCR & 0x0e)>>1) == 0x06) {
   if (bb_scsi_enabled) PBI_SCSI_PutACK(1);
  }
  else if (((bb_PCR & 0x0e)>>1) == 0x07) {
   if (bb_scsi_enabled) PBI_SCSI_PutACK(0);
  }
 }
 else if (addr == 0xd1bc) {
  memcpy(bb_ram+bb_ram_bank_offset,MEMORY_mem + 0xd600,0x100);
  bb_ram_bank_offset = (byte << 8);
  memcpy(MEMORY_mem + 0xd600, bb_ram+bb_ram_bank_offset, 0x100);
 }
 else if (addr == 0xd1be) {
  if (bb_rom_high_bit != ((byte & 0x04) << 2) && bb_rom_size == 0x10000) {
   bb_rom_high_bit = ((byte & 0x04) << 2);
   if (bb_rom_bank > 0 && bb_rom_bank < 8) {
     memcpy(MEMORY_mem + 0xd800, bb_rom + (bb_rom_bank + bb_rom_high_bit)*0x800, 0x800);
     do{}while(0);
   }
  }
 }
 else if ((addr & 0xffc0) == 0xd1c0) {
  if (bb_rom_bank != byte) {
   int offset = -1;
   if (bb_rom_size == 0x4000) {
    if (byte >= 8 && byte <= 0x0f) offset = (byte - 8)*0x800;
    else if (byte > 0 && byte < 0x08) offset = byte*0x800;
   }
   else {
    if (byte > 0 && byte < 0x10) offset = (byte + bb_rom_high_bit)*0x800;
   }
   if (offset != -1) {
     memcpy(MEMORY_mem + 0xd800, bb_rom + offset, 0x800);
     do{}while(0);
   }
   else {
     memcpy(MEMORY_mem + 0xd800, MEMORY_os + 0x1800, 0x800);
     if (byte != 0) do{}while(0);
     do{}while(0);
   }
   bb_rom_bank = byte;
  }
 }
}

variable_types:
byte
unsigned char

variable_types: offset int


decompiled_code:
__int64 __fastcall PBI_BB_D6GetByte(unsigned __int16 a1)
{
return *((unsigned __int8 *)&MEMORY_mem + a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned __int16 a1)
{
return *((unsigned __int8 *)&MEMORY_mem + a1);
}

original_code:
unsigned char PBI_BB_D6GetByte(unsigned short addr)
{
 return MEMORY_mem[addr];
}


decompiled_code:
void *__fastcall PBI_BB_D6PutByte(unsigned __int16 a1, char a2)
{
void *result; // rax

result = &MEMORY_mem;
*((_BYTE *)&MEMORY_mem + a1) = a2;
return result;
}

canonical_decompiled_code:
void *__fastcall func7(unsigned __int16 a1, char a2)
{
void *result; // rax

result = &MEMORY_mem;
*((_BYTE *)&MEMORY_mem + a1) = a2;
return result;
}

original_code:
void PBI_BB_D6PutByte(unsigned short addr, unsigned char byte)
{
 MEMORY_mem[addr]=byte;
}