decompiled_code:
int __fastcall Shell_Main(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

if ( a1 )
{
v1 = spiltline();
v2 = v1;
if ( v1 )
{
Process(v1);
LODWORD(v1) = free_list(v2);
}
}
else
{
LODWORD(v1) = printf("error, no commanline!");
}
return v1;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rbx

if ( a1 )
{
v1 = spiltline();
v2 = v1;
if ( v1 )
{
Process(v1);
LODWORD(v1) = free_list(v2);
}
}
else
{
LODWORD(v1) = printf("error, no commanline!");
}
return v1;
}

original_code:
void Shell_Main(char *command_line)
{
 if (!command_line)
 {
  printf("error, no commanline!");
  return;
 }
 char **arglist;
 int result = -1;
 if ((arglist = spiltline(command_line)) != ((void *)0))
 {
  result = Process(arglist);
  free_list(arglist);
 }
}

variable_types:
arglist
char **

variable_types: result int


repo: pxunl/myshell

decompiled_code:
__int64 do_redirect_double_output()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0xFFFFFFFFLL;
}

original_code:
int do_redirect_double_output(char **program, struct REDIRECT *redirection)
{
 return -1;
}

variable_types:
program
char **

variable_types: struct REDIRECT { char *word; enum Redirection_types { Re_singal_out=0, Re_singal_in=1, Re_double_out=2, Re_pipe=3 } red_type; char *re_file; struct REDIRECT *next; } *

return_type: int

user_defined_types: struct REDIRECT { char *word; enum Redirection_types red_type; char *re_file; struct REDIRECT *next; }


decompiled_code:
__int64 __fastcall do_redirect_output(char **argv, __int64 a2)
{
__pid_t v2; // eax
unsigned int v3; // er12
int v4; // ebp
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

if ( !argv || !a2 )
return (unsigned int)-1;
LODWORD(stat_loc.__uptr) = -1;
v2 = fork();
v3 = v2;
if ( v2 == -1 )
{
perror("fork fail");
}
else
{
if ( !v2 )
{
v4 = open(*(const char **)(a2 + 16), 66, 256LL);
if ( v4 != -1 )
{
close(1);
dup(v4);
close(v4);
execvp(*argv, argv);
perror("illegal command!\n");
exit(1);
}
exit(1);
}
if ( wait((__WAIT_STATUS)&stat_loc) == -1 )
{
LODWORD(stat_loc.__uptr) = -1;
perror("wait\n");
}
v3 = ((__int64)stat_loc.__uptr & 0x7F) == 0 ? 1 : -1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(char **argv, __int64 a2)
{
__pid_t v2; // eax
unsigned int v3; // er12
int v4; // ebp
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

if ( !argv || !a2 )
return (unsigned int)-1;
LODWORD(stat_loc.__uptr) = -1;
v2 = fork();
v3 = v2;
if ( v2 == -1 )
{
perror("fork fail");
}
else
{
if ( !v2 )
{
v4 = open(*(const char **)(a2 + 16), 66, 256LL);
if ( v4 != -1 )
{
close(1);
dup(v4);
close(v4);
execvp(*argv, argv);
perror("illegal command!\n");
exit(1);
}
exit(1);
}
if ( wait((__WAIT_STATUS)&stat_loc) == -1 )
{
LODWORD(stat_loc.__uptr) = -1;
perror("wait\n");
}
v3 = ((__int64)stat_loc.__uptr & 0x7F) == 0 ? 1 : -1;
}
return v3;
}

original_code:
int do_redirect_output(char **program, struct REDIRECT *redirection)
{
 if (program == ((void *)0) || redirection == ((void *)0))
 {
  return -1;
 }
 int pid_f;
 int chlid_in = -1;
 if ((pid_f = fork()) == -1)
 {
  perror("fork fail");
  return -1;
 }
 else if (pid_f == 0)
 {
  int redir_file;
  if ((redir_file = open(redirection->re_file, 02 | 0100, 0400)) == -1)
  {
   exit(1);
  }
  close(1);
  dup(redir_file);
  close(redir_file);
  execvp(program[0], program);
  perror("illegal command!\n");
  exit(1);
 }
 else
 {
  if (wait(&chlid_in) == -1)
  {
   chlid_in = -1;
   perror("wait\n");
  }
  chlid_in = ((((chlid_in) & 0x7f) == 0)? 1: -1);
 }
 return chlid_in;
}

user_defined_types: enum Redirection_types { Re_singal_out=0, Re_singal_in=1, Re_double_out=2, Re_pipe=3 }


decompiled_code:
__int64 __fastcall do_redirect_input(char **argv, __int64 a2)
{
__pid_t v2; // eax
int v3; // ebp
__WAIT_STATUS stat_loc; // [rsp+0h] [rbp-1Ch] BYREF

if ( !argv )
return 0xFFFFFFFFLL;
if ( a2 )
{
LODWORD(stat_loc.__uptr) = -1;
v2 = fork();
if ( v2 == -1 )
{
perror("fork fail");
}
else
{
if ( !v2 )
{
v3 = open(*(const char **)(a2 + 16), 0, 16LL);
if ( v3 != -1 )
{
close(0);
dup(v3);
close(v3);
execvp(*argv, argv);
perror("illegal command!\n");
exit(1);
}
exit(1);
}
if ( wait((__WAIT_STATUS)&stat_loc) == -1 )
{
LODWORD(stat_loc.__uptr) = -1;
perror("wait\n");
}
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char **argv, __int64 a2)
{
__pid_t v2; // eax
int v3; // ebp
__WAIT_STATUS stat_loc; // [rsp+0h] [rbp-1Ch] BYREF

if ( !argv )
return 0xFFFFFFFFLL;
if ( a2 )
{
LODWORD(stat_loc.__uptr) = -1;
v2 = fork();
if ( v2 == -1 )
{
perror("fork fail");
}
else
{
if ( !v2 )
{
v3 = open(*(const char **)(a2 + 16), 0, 16LL);
if ( v3 != -1 )
{
close(0);
dup(v3);
close(v3);
execvp(*argv, argv);
perror("illegal command!\n");
exit(1);
}
exit(1);
}
if ( wait((__WAIT_STATUS)&stat_loc) == -1 )
{
LODWORD(stat_loc.__uptr) = -1;
perror("wait\n");
}
}
}
return 0xFFFFFFFFLL;
}

original_code:
int do_redirect_input(char **program, struct REDIRECT *redirection)
{
 if (program == ((void *)0) || redirection == ((void *)0))
 {
  return -1;
 }
 int pid_f;
 int chlid_in = -1;
 if ((pid_f = fork()) == -1)
 {
  perror("fork fail");
  return -1;
 }
 else if (pid_f == 0)
 {
  int redir_file;
  if ((redir_file = open(redirection->re_file, 00, (0200 >> 3))) == -1)
  {
   exit(1);
  }
  close(0);
  dup(redir_file);
  close(redir_file);
  execvp(program[0], program);
  perror("illegal command!\n");
  exit(1);
 }
 else
 {
  if (wait(&chlid_in) == -1)
  {
   chlid_in = -1;
   perror("wait\n");
  }
  chlid_in = ((((chlid_in) & 0x7f) == 0)? 1: -1);
 }
 return -1;
}


decompiled_code:
void __fastcall free_temp_cmd(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)ptr;
do
{
++v3;
free(v2);
v2 = *v3;
}
while ( *v3 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)ptr;
do
{
++v3;
free(v2);
v2 = *v3;
}
while ( *v3 );
}
free(ptr);
}

original_code:
void free_temp_cmd(char **cmd)
{
 char **clear = cmd;
 while (*clear)
 {
  free(*clear++);
 }
 free(cmd);
 cmd = ((void *)0);
}

variable_types:
cmd
char **

variable_types:
clear
char **

return_type: void


decompiled_code:
__int64 __fastcall do_redirect_pipe(char **argv, __int64 a2)
{
_QWORD *v2; // r12
const char *v3; // rbp
size_t v4; // rax
char *v5; // rax
__pid_t v6; // eax
int pipedes[2]; // [rsp+0h] [rbp-20h] BYREF

if ( !argv )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
pipedes[0] = 0;
pipedes[1] = 0;
v2 = malloc(0x10uLL);
v3 = *(const char **)(a2 + 16);
v4 = strlen(v3);
v5 = (char *)malloc(v4 + 1);
*v2 = v5;
strcpy(v5, v3);
v2[1] = 0LL;
if ( pipe(pipedes) == -1 )
{
perror("Can't get a new pipe");
exit(1);
}
v6 = fork();
if ( v6 == -1 )
{
perror("Can't fork!");
exit(2);
}
if ( !v6 )
{
if ( fork() != -1 )
{
close(pipedes[0]);
if ( dup2(pipedes[1], 1) != -1 )
{
close(pipedes[1]);
execvp(*argv, argv);
perror(*argv);
exit(3);
}
perror("Cloud't redirect stdout");
exit(3);
}
perror("Can't fork!");
exit(2);
}
free_temp_cmd(v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char **argv, __int64 a2)
{
_QWORD *v2; // r12
const char *v3; // rbp
size_t v4; // rax
char *v5; // rax
__pid_t v6; // eax
int pipedes[2]; // [rsp+0h] [rbp-20h] BYREF

if ( !argv )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
pipedes[0] = 0;
pipedes[1] = 0;
v2 = malloc(0x10uLL);
v3 = *(const char **)(a2 + 16);
v4 = strlen(v3);
v5 = (char *)malloc(v4 + 1);
*v2 = v5;
strcpy(v5, v3);
v2[1] = 0LL;
if ( pipe(pipedes) == -1 )
{
perror("Can't get a new pipe");
exit(1);
}
v6 = fork();
if ( v6 == -1 )
{
perror("Can't fork!");
exit(2);
}
if ( !v6 )
{
if ( fork() != -1 )
{
close(pipedes[0]);
if ( dup2(pipedes[1], 1) != -1 )
{
close(pipedes[1]);
execvp(*argv, argv);
perror(*argv);
exit(3);
}
perror("Cloud't redirect stdout");
exit(3);
}
perror("Can't fork!");
exit(2);
}
func3(v2);
return 1LL;
}

original_code:
int do_redirect_pipe(char **program, struct REDIRECT *redirection)
{
 if (program == ((void *)0) || redirection == ((void *)0))
 {
  return -1;
 }
 int re_pipe[2] = {0, 0};
 int pid_f;
 int r_parent = 1;
 int r_chind = 1;
 char **right_program = ((void *)0);
 right_program = (char **)malloc(2 * sizeof(char *));
 right_program[0] = (char *)malloc((strlen(redirection->re_file) + 1) * sizeof(char));
 strcpy(right_program[0], redirection->re_file);
 right_program[1] = ((void *)0);
 if (pipe(re_pipe) == -1)
 {
  {perror("Can't get a new pipe"); exit(1);};
 }
 if ((pid_f = fork()) == -1)
 {
  {perror("Can't fork!"); exit(2);};
  return -1;
 }
 else if (pid_f == 0)
 {
  if ((pid_f = fork()) == -1)
  {
   {perror("Can't fork!"); exit(2);};
   return -1;
  }
  close(re_pipe[0]);
  if (dup2(re_pipe[1], 1) == -1)
  {
   {perror("Cloud't redirect stdout"); exit(3);};
  }
  close(re_pipe[1]);
  r_chind = (execvp(program[0], program) == -1)? -1 : 1;
  {perror(program[0]); exit(3);};
  if (pid_f == 0)
  {
   close(re_pipe[1]);
   if (dup2(re_pipe[0], 0) == -1)
   {
    {perror("Cloud't redirect stdout"); exit(3);};
   }
   close(re_pipe[0]);
   if ((redirection->red_type == Re_pipe) && (strcmp(redirection->word, redirection_descriptor[3]) == 0))
   {
    r_parent = (execvp(right_program[0], right_program) == -1)? -1 : 1;
   }
   {perror(right_program[0]); exit(3);};
  }
 }
 free_temp_cmd(right_program);
 return ((r_chind == 1) && (r_parent == 1))? 1 : -1;
}


decompiled_code:
__int64 __fastcall is_in_descriptor_table(char *s2)
{
const char **v1; // rbx

v1 = (const char **)&redirection_descriptor;
while ( strcmp(*v1, s2) )
{
if ( ++v1 == (const char **)(unsigned int)((_DWORD)&redirection_descriptor + 32) )
return 0xFFFFFFFFLL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s2)
{
const char **v1; // rbx

v1 = (const char **)&redirection_descriptor;
while ( strcmp(*v1, s2) )
{
if ( ++v1 == (const char **)(unsigned int)((_DWORD)&redirection_descriptor + 32) )
return 0xFFFFFFFFLL;
}
return 1LL;
}

original_code:
int is_in_descriptor_table(char * str)
{
 int i = 0;
 for (i = 0; i < 4; i++)
 {
  if (strcmp(redirection_descriptor[i], str) == 0)
  {
   return 1;
  }
 }
 return -1;
}

canonical_original_code:
int is_in_descriptor_table(char *str)
{
 int i = 0;
 for (i = 0; i < 4; i++)
 {
  if (strcmp(redirection_descriptor[i], str) == 0)
  {
   return 1;
  }
 }
 return -1;
}

variable_types:
str
char *

variable_types: i int


decompiled_code:
__int64 __fastcall Need_Redirection(char **a1)
{
char *v2; // rdi
char **v3; // rbx
__int64 result; // rax

v2 = *a1;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = a1 + 1;
while ( 1 )
{
result = is_in_descriptor_table(v2);
if ( (_DWORD)result == 1 )
break;
v2 = *v3++;
if ( !v2 )
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char **a1)
{
char *v2; // rdi
char **v3; // rbx
__int64 result; // rax

v2 = *a1;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = a1 + 1;
while ( 1 )
{
result = func5(v2);
if ( (_DWORD)result == 1 )
break;
v2 = *v3++;
if ( !v2 )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int Need_Redirection(char **cmd)
{
 int i = 0;
 while (cmd[i] != ((void *)0))
 {
  if (is_in_descriptor_table(cmd[i]) == 1)
  {
   return 1;
  }
  i++;
 }
 return -1;
}


decompiled_code:
__int64 __fastcall Check_File_Name(char *a1)
{
_BYTE *v1; // rbx
const unsigned __int16 *v2; // rcx
char v3; // al
unsigned int v4; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1;
v2 = *_ctype_b_loc();
v3 = *a1;
v4 = -1;
if ( (v2[*a1] & 0x800) == 0 )
{
if ( v3 )
{
do
{
if ( (v2[v3] & 8) == 0 && v3 != 46 )
return (unsigned int)-1;
v3 = *++v1;
}
while ( *v1 );
v4 = 1;
}
else
{
v4 = 1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
_BYTE *v1; // rbx
const unsigned __int16 *v2; // rcx
char v3; // al
unsigned int v4; // edx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1;
v2 = *_ctype_b_loc();
v3 = *a1;
v4 = -1;
if ( (v2[*a1] & 0x800) == 0 )
{
if ( v3 )
{
do
{
if ( (v2[v3] & 8) == 0 && v3 != 46 )
return (unsigned int)-1;
v3 = *++v1;
}
while ( *v1 );
v4 = 1;
}
else
{
v4 = 1;
}
}
return v4;
}

original_code:
int Check_File_Name(char *file)
{
 if (!file)
 {
  return -1;
 }
 char * ck = file;
 if (((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short int) _ISdigit))
 {
  return -1;
 }
 while (*ck)
 {
  if ((((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short int) _ISalnum) == 0) && *ck != '.')
  {
   return -1;
  }
  ck++;
 }
 return 1;
}

canonical_original_code:
int Check_File_Name(char *file)
{
 if (!file)
 {
  return -1;
 }
 char *ck = file;
 if (((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short) _ISdigit))
 {
  return -1;
 }
 while (*ck)
 {
  if ((((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short) _ISalnum) == 0) && *ck != '.')
  {
   return -1;
  }
  ck++;
 }
 return 1;
}

variable_types:
file
char *

variable_types:
ck
char *


decompiled_code:
__int64 __fastcall Usage_Redirection(int a1)
{
switch ( a1 )
{
case 1:
return g_print("\nexpect file after input or output direction symbol\n");
case 2:
return g_print("\nexpect input or output direction symbol before file\n");
case 4:
return g_print("\n%s\n%s", "ilegal command program.", "Try directions --help for more information");
}
return g_print("Try directions --help for more information.\n");
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
switch ( a1 )
{
case 1:
return g_print("\nexpect file after input or output direction symbol\n");
case 2:
return g_print("\nexpect input or output direction symbol before file\n");
case 4:
return g_print("\n%s\n%s", "ilegal command program.", "Try directions --help for more information");
}
return g_print("Try directions --help for more information.\n");
}

original_code:
void Usage_Redirection(int status)
{
 if (status == 1)
 {
  g_print("\nexpect file after input or output direction symbol\n");
 }
 else if (status == 2)
 {
  g_print("\nexpect input or output direction symbol before file\n");
 }
 else if (status == 4)
 {
  g_print("\n%s\n%s"
    ,"ilegal command program."
    , "Try directions --help for more information");
 }
 else
 {
  g_print("Try directions --help for more information.\n");
  return;
 }
 return;
}

variable_types: status int


decompiled_code:
__int64 __fastcall Check_Redirection_Validity(__int64 a1)
{
const char *v1; // rbp
unsigned int v2; // ebp
char *v4; // rbp
int v5; // er12
__int64 v6; // r13
char *v7; // r13

v1 = *(const char **)a1;
if ( !*(_QWORD *)a1 || strchr(*(const char **)a1, 62) || strchr(v1, 124) || strchr(v1, 60) || strstr(v1, ">>") )
{
Usage_Redirection(4);
v2 = -1;
}
else
{
v4 = *(char **)(a1 + 8);
v5 = 1;
v6 = 1LL;
if ( v4 )
{
while ( 1 )
{
if ( (unsigned int)is_in_descriptor_table(v4) == 1 )
{
v7 = *(char **)(a1 + 8 * v6 + 8);
if ( !v7 )
return (unsigned int)-1;
v2 = is_in_descriptor_table(v7);
if ( v2 != -1 )
return (unsigned int)-1;
if ( (unsigned int)Check_File_Name(v7) != 1 )
return v2;
v5 += 2;
}
else
{
v2 = Check_File_Name(v4);
if ( v2 == -1 )
return v2;
++v5;
}
v6 = v5;
v4 = *(char **)(a1 + 8LL * v5);
if ( !v4 )
return 1;
}
}
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
const char *v1; // rbp
unsigned int v2; // ebp
char *v4; // rbp
int v5; // er12
__int64 v6; // r13
char *v7; // r13

v1 = *(const char **)a1;
if ( !*(_QWORD *)a1 || strchr(*(const char **)a1, 62) || strchr(v1, 124) || strchr(v1, 60) || strstr(v1, ">>") )
{
func9(4);
v2 = -1;
}
else
{
v4 = *(char **)(a1 + 8);
v5 = 1;
v6 = 1LL;
if ( v4 )
{
while ( 1 )
{
if ( (unsigned int)func5(v4) == 1 )
{
v7 = *(char **)(a1 + 8 * v6 + 8);
if ( !v7 )
return (unsigned int)-1;
v2 = func5(v7);
if ( v2 != -1 )
return (unsigned int)-1;
if ( (unsigned int)func8(v7) != 1 )
return v2;
v5 += 2;
}
else
{
v2 = func8(v4);
if ( v2 == -1 )
return v2;
++v5;
}
v6 = v5;
v4 = *(char **)(a1 + 8LL * v5);
if ( !v4 )
return 1;
}
}
v2 = 1;
}
return v2;
}

original_code:
int Check_Redirection_Validity(char **cmd)
{
 int flag = 1;
 if ((cmd[0] == ((void *)0))
   || (strchr(cmd[0], '>') != ((void *)0))
   || (strchr(cmd[0], '|') != ((void *)0))
   || (strchr(cmd[0], '<') != ((void *)0))
   || (strstr(cmd[0], ">>") != ((void *)0)))
 {
  Usage_Redirection(4);
  return -1;
 }
 int i = 1;
 while (cmd[i] != ((void *)0))
 {
  if (is_in_descriptor_table(cmd[i]) == 1)
  {
   if ((cmd[i+1] != ((void *)0))
     && (is_in_descriptor_table(cmd[i+1]) == -1)
        && (Check_File_Name(cmd[i+1]) == 1))
   {
    i += 2;
    continue;
   }
   else
   {
    return -1;
   }
  }
  else
  {
   if (Check_File_Name(cmd[i]) == -1)
   {
    return -1;
   }
  }
  i++;
 }
 return flag;
}

variable_types: flag int


decompiled_code:
void __fastcall free_direction_list(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 3);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 3);
free(v2);
}
}

original_code:
void free_direction_list(struct REDIRECT *pfree)
{
 struct REDIRECT *ptmp = ((void *)0);
 while (((void *)0) != pfree)
 {
  ptmp = pfree;
  pfree = pfree->next;
  free(ptmp);
  ptmp = ((void *)0);
 }
 pfree = ((void *)0);
}


decompiled_code:
__int64 Redirection_Usage()
{
return g_print("\n------Finished------\n");
}

original_code:
void Redirection_Usage()
{
 g_print("\n------Finished------\n");
}


decompiled_code:
__int64 __fastcall Process_Redirection(const char **a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbp
char *v3; // r12
__int64 v4; // rbx
unsigned int v5; // ebp
unsigned int v6; // eax

v1 = get_redirection_list(a1);
if ( !v1 )
return (unsigned int)-1;
v2 = v1;
if ( !a1 )
return (unsigned int)-1;
v3 = get_program((char **)a1);
v4 = v2[3];
if ( v4 )
{
v5 = -1;
do
{
v6 = *(_DWORD *)(v4 + 8);
if ( v6 == 2 )
{
v5 = (*(&redirect_table + 2))(v3, v4);
}
else if ( v6 > 2 )
{
if ( v6 == 3 )
v5 = (*(&redirect_table + 3))(v3, v4);
else
Redirection_Usage();
}
else if ( v6 )
{
v5 = (*(&redirect_table + 1))(v3, v4);
}
else
{
v5 = redirect_table(v3, v4);
}
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
}
else
{
v5 = -1;
}
free_temp_cmd(v3);
free_direction_list(0LL);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func13(const char **a1)
{
_QWORD *v1; // rax
_QWORD *v2; // rbp
char *v3; // r12
__int64 v4; // rbx
unsigned int v5; // ebp
unsigned int v6; // eax

v1 = get_redirection_list(a1);
if ( !v1 )
return (unsigned int)-1;
v2 = v1;
if ( !a1 )
return (unsigned int)-1;
v3 = func6((char **)a1);
v4 = v2[3];
if ( v4 )
{
v5 = -1;
do
{
v6 = *(_DWORD *)(v4 + 8);
if ( v6 == 2 )
{
v5 = (*(&redirect_table + 2))(v3, v4);
}
else if ( v6 > 2 )
{
if ( v6 == 3 )
v5 = (*(&redirect_table + 3))(v3, v4);
else
func12();
}
else if ( v6 )
{
v5 = (*(&redirect_table + 1))(v3, v4);
}
else
{
v5 = redirect_table(v3, v4);
}
v4 = *(_QWORD *)(v4 + 24);
}
while ( v4 );
}
else
{
v5 = -1;
}
func3(v3);
func11(0LL);
return v5;
}

original_code:
int Process_Redirection(char **cmd)
{
 struct REDIRECT *ph= get_redirection_list(cmd);
 if (ph == ((void *)0) || cmd == ((void *)0))
 {
  return -1;
 }
 int flag = -1;
 char **program = get_program(cmd);
 ph = ph->next;
 while (ph!= ((void *)0))
 {
  switch(ph->red_type)
  {
   case Re_singal_out:
    flag = redirect_table[0](program, ph);
    break;
   case Re_singal_in:
    flag = redirect_table[1](program, ph);
    break;
   case Re_double_out:
    flag = redirect_table[2](program, ph);
    break;
   case Re_pipe:
    flag = redirect_table[3](program, ph);
    break;
   default: Redirection_Usage();
      break;
  }
  ph = ph->next;
 }
 free_temp_cmd(program);
 free_direction_list(ph);
 return flag;
}

canonical_original_code:
int Process_Redirection(char **cmd)
{
 struct REDIRECT *ph = get_redirection_list(cmd);
 if (ph == ((void *)0) || cmd == ((void *)0))
 {
  return -1;
 }
 int flag = -1;
 char **program = get_program(cmd);
 ph = ph->next;
 while (ph!= ((void *)0))
 {
  switch(ph->red_type)
  {
   case Re_singal_out:
    flag = redirect_table[0](program, ph);
    break;
   case Re_singal_in:
    flag = redirect_table[1](program, ph);
    break;
   case Re_double_out:
    flag = redirect_table[2](program, ph);
    break;
   case Re_pipe:
    flag = redirect_table[3](program, ph);
    break;
   default: Redirection_Usage();
      break;
  }
  ph = ph->next;
 }
 free_temp_cmd(program);
 free_direction_list(ph);
 return flag;
}


decompiled_code:
__int64 __fastcall Is_Control_Cmd(const char *a1)
{
unsigned int v1; // edx

v1 = 1;
if ( strcmp(a1, "if") && strcmp(a1, "then") && strcmp(a1, "else") )
v1 = strcmp(a1, "fi") == 0 ? 1 : -1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
unsigned int v1; // edx

v1 = 1;
if ( strcmp(a1, "if") && strcmp(a1, "then") && strcmp(a1, "else") )
v1 = strcmp(a1, "fi") == 0 ? 1 : -1;
return v1;
}

original_code:
int Is_Control_Cmd(char *str)
{
 if ((strcmp(str, "if") == 0) || (strcmp(str, "then") == 0)
  || (strcmp(str, "else") == 0) || (strcmp(str, "fi") == 0 ))
 {
  return 1;
 }
 return -1;
}


decompiled_code:
int __fastcall Syntax_Error(const char *a1)
{
if_state = 0;
return fprintf(stderr, "syntax error!: %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
if_state = 0;
return fprintf(stderr, "syntax error!: %s\n", a1);
}

original_code:
void Syntax_Error(char *ckstr)
{
 if_state = NATRULE;
 fprintf(stderr, "syntax error!: %s\n", ckstr);
}

variable_types:
ckstr
char *


decompiled_code:
__int64 Ok_Execute()
{
__int64 result; // rax

if ( if_state == 1 )
{
Syntax_Error("then expected");
result = 0xFFFFFFFFLL;
}
else
{
result = 1LL;
if ( if_state == 2 )
{
result = (unsigned int)if_result;
if ( if_result != 1 && if_result != -1 )
result = 1LL;
}
}
return result;
}

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

if ( if_state == 1 )
{
func1("then expected");
result = 0xFFFFFFFFLL;
}
else
{
result = 1LL;
if ( if_state == 2 )
{
result = (unsigned int)if_result;
if ( if_result != 1 && if_result != -1 )
result = 1LL;
}
}
return result;
}

original_code:
int Ok_Execute()
{
 int flag = 1;
 if (WANT_THEN == if_state)
 {
  Syntax_Error("then expected");
  flag = -1;
 }
 else if ((THEN_BLOCK == if_state) && (1 == if_result))
 {
  flag = 1;
 }
 else if ((THEN_BLOCK == if_state) && (-1 == if_result))
 {
  flag = -1;
 }
 return flag;
}


decompiled_code:
__int64 __fastcall IS_Buildin_Cmd(const char **a1)
{
const char *v1; // rbx
__int64 result; // rax
char *v3; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
result = 1LL;
if ( strcmp(*a1, "iset") )
{
v3 = strchr(v1, 61);
result = 1LL;
if ( !v3 )
{
if ( strcmp(v1, "iexport") )
result = strcmp(v1, "icd") == 0 ? 1 : -1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char **a1)
{
const char *v1; // rbx
__int64 result; // rax
char *v3; // rdx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *a1;
result = 1LL;
if ( strcmp(*a1, "iset") )
{
v3 = strchr(v1, 61);
result = 1LL;
if ( !v3 )
{
if ( strcmp(v1, "iexport") )
result = strcmp(v1, "icd") == 0 ? 1 : -1;
}
}
return result;
}

original_code:
int IS_Buildin_Cmd(char **input)
{
 if (((void *)0) == input)
 {
  return -1;
 }
 if ((strcmp(input[0], "iset") == 0)
  || (strchr(input[0], '=') != ((void *)0))
  || (strcmp(input[0], "iexport") == 0)
  || (strcmp(input[0], "icd") == 0))
 {
  return 1;
 }
 return -1;
}

variable_types:
input
char **


decompiled_code:
__int64 __fastcall Process_Buildin_Cmd(const char **a1)
{
bool v1; // cf
bool v2; // zf
const char *v4; // rbp
const char *v5; // rdi
__int64 v6; // rcx
const char *v7; // rsi
char v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
unsigned int v12; // ebx
const char *v14; // rdi
__int64 v15; // rcx
const char *v16; // rsi
char v17; // al
bool v18; // cf
bool v19; // zf
const char *v20; // rdi
__int64 v21; // rcx
const char *v22; // rsi
const char *v23; // rdi

v1 = 0;
v2 = 0;
v4 = *a1;
v5 = "icd";
v6 = 4LL;
v7 = v4;
do
{
if ( !v6 )
break;
v1 = *v7 < (unsigned int)*v5;
v2 = *v7++ == *v5++;
--v6;
}
while ( v2 );
v8 = (!v1 && !v2) - v1;
v9 = 0;
v10 = v8 == 0;
if ( v8 )
{
v14 = "iset";
v15 = 5LL;
v16 = v4;
do
{
if ( !v15 )
break;
v9 = *v16 < (unsigned int)*v14;
v10 = *v16++ == *v14++;
--v15;
}
while ( v10 );
v17 = (!v9 && !v10) - v9;
v18 = 0;
v19 = v17 == 0;
if ( !v17 )
{
Value_List(v14, v16);
return 1;
}
v20 = "iexport";
v21 = 8LL;
v22 = v4;
do
{
if ( !v21 )
break;
v18 = *v22 < (unsigned int)*v20;
v19 = *v22++ == *v20++;
--v21;
}
while ( v19 );
if ( (!v18 && !v19) == v18 )
{
v23 = a1[1];
if ( !v23 || !(unsigned int)Check_Name(v23, v22) || (v12 = Value_Export(a1[1]), v12 == -1) )
{
g_print("Fail.\n");
return (unsigned int)-1;
}
}
else
{
if ( !strchr(v4, 61) )
return (unsigned int)-1;
v12 = Value_Store(v4);
if ( v12 == -1 )
{
g_print("Fail.\n");
return v12;
}
}
g_print("Succeed.\n");
return v12;
}
v11 = a1[1];
if ( !v11 )
{
v11 = "/home/pxunl/myshell/src/shell/";
v12 = chdir("/home/pxunl/myshell/src/shell/");
if ( v12 != -1 )
goto LABEL_7;
LABEL_11:
usage(v11, v7);
return v12;
}
v12 = chdir(v11);
if ( v12 == -1 )
goto LABEL_11;
LABEL_7:
system("pwd");
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char **a1)
{
bool v1; // cf
bool v2; // zf
const char *v4; // rbp
const char *v5; // rdi
__int64 v6; // rcx
const char *v7; // rsi
char v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rdi
unsigned int v12; // ebx
const char *v14; // rdi
__int64 v15; // rcx
const char *v16; // rsi
char v17; // al
bool v18; // cf
bool v19; // zf
const char *v20; // rdi
__int64 v21; // rcx
const char *v22; // rsi
const char *v23; // rdi

v1 = 0;
v2 = 0;
v4 = *a1;
v5 = "icd";
v6 = 4LL;
v7 = v4;
do
{
if ( !v6 )
break;
v1 = *v7 < (unsigned int)*v5;
v2 = *v7++ == *v5++;
--v6;
}
while ( v2 );
v8 = (!v1 && !v2) - v1;
v9 = 0;
v10 = v8 == 0;
if ( v8 )
{
v14 = "iset";
v15 = 5LL;
v16 = v4;
do
{
if ( !v15 )
break;
v9 = *v16 < (unsigned int)*v14;
v10 = *v16++ == *v14++;
--v15;
}
while ( v10 );
v17 = (!v9 && !v10) - v9;
v18 = 0;
v19 = v17 == 0;
if ( !v17 )
{
Value_List(v14, v16);
return 1;
}
v20 = "iexport";
v21 = 8LL;
v22 = v4;
do
{
if ( !v21 )
break;
v18 = *v22 < (unsigned int)*v20;
v19 = *v22++ == *v20++;
--v21;
}
while ( v19 );
if ( (!v18 && !v19) == v18 )
{
v23 = a1[1];
if ( !v23 || !(unsigned int)Check_Name(v23, v22) || (v12 = Value_Export(a1[1]), v12 == -1) )
{
g_print("Fail.\n");
return (unsigned int)-1;
}
}
else
{
if ( !strchr(v4, 61) )
return (unsigned int)-1;
v12 = Value_Store(v4);
if ( v12 == -1 )
{
g_print("Fail.\n");
return v12;
}
}
g_print("Succeed.\n");
return v12;
}
v11 = a1[1];
if ( !v11 )
{
v11 = "/home/pxunl/myshell/src/shell/";
v12 = chdir("/home/pxunl/myshell/src/shell/");
if ( v12 != -1 )
goto LABEL_7;
LABEL_11:
func4(v11, v7);
return v12;
}
v12 = chdir(v11);
if ( v12 == -1 )
goto LABEL_11;
LABEL_7:
system("pwd");
return 1;
}

original_code:
int Process_Buildin_Cmd(char **cmd)
{
 int flag = -1;
 if (strcmp(cmd[0], "icd") == 0 && cmd[1] != ((void *)0))
 {
  if (chdir(cmd[1]) == -1)
  {
   usage();
   return -1;
  }
  flag = 1;
  system("pwd");
 }
 else if (strcmp(cmd[0], "icd") == 0 && cmd[1] == ((void *)0))
 {
  if (chdir("/home/pxunl/myshell/src/shell/") == -1)
  {
   usage();
   return -1;
  }
  flag = 1;
  system("pwd");
 }
 else if (strcmp(cmd[0], "iset") == 0)
 {
  Value_List();
  flag = 1;
 }
 else if (strcmp(cmd[0], "iexport") == 0)
 {
  if ((cmd[1] != ((void *)0)) && (Check_Name(cmd[1])))
  {
   flag = Value_Export(cmd[1]);
  }
  else
  {
   flag = -1;
  }
  if (flag == -1)
  {
   g_print("Fail.\n");
  }
  else
  {
   g_print("Succeed.\n");
  }
 }
 else if (strchr(cmd[0], '=') != ((void *)0))
 {
  flag = Value_Store(cmd[0]);
  if (flag == -1)
  {
   g_print("Fail.\n");
  }
  else
  {
   g_print("Succeed.\n");
  }
 }
 return flag;
}


Process

decompiled_code:
__int64 __fastcall Process(const char **a1)
{
unsigned int v1; // ebx

if ( !*a1 )
return (unsigned int)-1;
if ( (unsigned int)Need_Redirection() == 1 && (unsigned int)Check_Redirection_Validity(a1) == 1 )
{
v1 = Process_Redirection(a1);
if ( v1 == 1 )
g_print("\nredirected..\n");
else
Redirection_Usage();
}
else if ( (unsigned int)Is_Control_Cmd(*a1) == 1 )
{
v1 = Do_Control_Cmd(a1);
}
else if ( (unsigned int)Ok_Execute() == 1 )
{
if ( (unsigned int)IS_Buildin_Cmd(a1) == 1 )
v1 = Process_Buildin_Cmd(a1);
else
v1 = Execute(a1);
}
else
{
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char **a1)
{
unsigned int v1; // ebx

if ( !*a1 )
return (unsigned int)-1;
if ( (unsigned int)Need_Redirection() == 1 && (unsigned int)Check_Redirection_Validity(a1) == 1 )
{
v1 = Process_Redirection(a1);
if ( v1 == 1 )
g_print("\nredirected..\n");
else
Redirection_Usage();
}
else if ( (unsigned int)func0(*a1) == 1 )
{
v1 = func7(a1);
}
else if ( (unsigned int)func2() == 1 )
{
if ( (unsigned int)func3(a1) == 1 )
v1 = func5(a1);
else
v1 = Execute(a1);
}
else
{
v1 = -1;
}
return v1;
}

original_code:
int Process(char **input)
{
 int flag = -1;
 if (((void *)0) == input[0])
 {
  return -1;
 }
 if ((Need_Redirection(input) == 1) && Check_Redirection_Validity(input) == 1)
 {
  flag = Process_Redirection(input);
  if (flag == 1)
  {
   g_print("\nredirected..\n");
  }
  else
  {
   Redirection_Usage();
  }
  return flag;
 }
 else if (Is_Control_Cmd(input[0]) == 1)
 {
  flag = Do_Control_Cmd(input);
 }
 else if (Ok_Execute() == 1)
 {
  if (IS_Buildin_Cmd(input) == 1)
  {
   flag = Process_Buildin_Cmd(input);
  }
  else
  {
   flag = Execute(input);
  }
 }
 return flag;
}


decompiled_code:
__int64 __fastcall Do_Control_Cmd(const char **a1)
{
const char *v1; // r8
__int64 result; // rax

v1 = *a1;
if ( !strcmp(*a1, "if") )
{
if ( if_state )
{
Syntax_Error("if unexpected!");
result = 0xFFFFFFFFLL;
}
else
{
if_result = Process(a1 + 1);
if_state = 1;
result = 1LL;
}
}
else if ( !strcmp(v1, "then") )
{
result = (unsigned int)if_state;
if ( if_state == 1 )
{
if_state = 2;
}
else
{
Syntax_Error("then unexpected");
result = 0xFFFFFFFFLL;
}
}
else if ( !strcmp(v1, "fi") )
{
if ( if_state == 2 )
{
if_state = 0;
result = 1LL;
}
else
{
Syntax_Error("fi unexpected");
result = 0xFFFFFFFFLL;
}
}
else
{
fatal("internal error:", v1, 2LL);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char **a1)
{
const char *v1; // r8
__int64 result; // rax

v1 = *a1;
if ( !strcmp(*a1, "if") )
{
if ( if_state )
{
func1("if unexpected!");
result = 0xFFFFFFFFLL;
}
else
{
if_result = func6(a1 + 1);
if_state = 1;
result = 1LL;
}
}
else if ( !strcmp(v1, "then") )
{
result = (unsigned int)if_state;
if ( if_state == 1 )
{
if_state = 2;
}
else
{
func1("then unexpected");
result = 0xFFFFFFFFLL;
}
}
else if ( !strcmp(v1, "fi") )
{
if ( if_state == 2 )
{
if_state = 0;
result = 1LL;
}
else
{
func1("fi unexpected");
result = 0xFFFFFFFFLL;
}
}
else
{
fatal("internal error:", v1, 2LL);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int Do_Control_Cmd(char **args)
{
 char *cmd = args[0];
 int flag = -1;
 if (strcmp(cmd, "if") == 0)
 {
  if (if_state != NATRULE)
  {
   Syntax_Error("if unexpected!");
   flag = -1;
  }
  else
  {
   last_state = Process(args + 1);
   if_result = last_state;
   if_state = WANT_THEN;
   flag = 1;
  }
 }
 else if (strcmp(cmd, "then") == 0)
 {
  if (if_state != WANT_THEN)
  {
   Syntax_Error("then unexpected");
   flag = -1;
  }
  else
  {
   if_state = THEN_BLOCK;
   flag = 1;
  }
 }
 else if (strcmp(cmd, "fi") == 0)
 {
  if (if_state != THEN_BLOCK)
  {
   Syntax_Error("fi unexpected");
   flag = -1;
  }
  else
  {
   if_state = NATRULE;
   flag = 1;
  }
 }
 else
 {
  fatal("internal error:", cmd, 2);
 }
 return flag;
}

variable_types:
args
char **

variable_types:
cmd
char *


usage

decompiled_code:
__int64 usage()
{
return g_print("Usage: cd [OPTIONS] DIRECTORY\nicd --help\n");
}

canonical_decompiled_code:
__int64 func4()
{
return g_print("Usage: cd [OPTIONS] DIRECTORY\nicd --help\n");
}

original_code:
void usage()
{
 g_print("Usage: cd [OPTIONS] DIRECTORY\nicd --help\n");
}


decompiled_code:
char *__fastcall uid_to_name(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( v1 )
return v1->pw_name;
sprintf(numstr_1, "%d", a1);
return numstr_1;
}

canonical_decompiled_code:
char *__fastcall func8(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( v1 )
return v1->pw_name;
sprintf(numstr_1, "%d", a1);
return numstr_1;
}

original_code:
char *uid_to_name(uid_t uid)
{
 struct passwd *getpwuid();
 struct passwd *pw_ptr;
 static char numstr[10];
 if (( pw_ptr = getpwuid( uid )) == ((void *)0))
 {
  sprintf(numstr,"%d", uid);
  return numstr;
 }
 else
 {
  return pw_ptr->pw_name;
 }
 return ((void *)0);
}

canonical_original_code:
char *uid_to_name(unsigned int uid)
{
 struct passwd *getpwuid();
 struct passwd *pw_ptr;
 static char numstr[10];
 if (( pw_ptr = getpwuid( uid )) == ((void *)0))
 {
  sprintf(numstr,"%d", uid);
  return numstr;
 }
 else
 {
  return pw_ptr->pw_name;
 }
 return ((void *)0);
}

variable_types:
uid
unsigned int

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *()

variable_types:
numstr
char [10]

return_type: char *


decompiled_code:
char *__fastcall gid_to_name(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( v1 )
return v1->gr_name;
sprintf(numstr_0, "%d", a1);
return numstr_0;
}

canonical_decompiled_code:
char *__fastcall func9(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( v1 )
return v1->gr_name;
sprintf(numstr_0, "%d", a1);
return numstr_0;
}

original_code:
char *gid_to_name( gid_t gid )
{
 struct group *getgrgid();
 struct group *grp_ptr;
 static char numstr[10];
 if ( ( grp_ptr = getgrgid(gid) ) == ((void *)0) )
 {
  sprintf(numstr,"%d", gid);
  return numstr;
 }
 else
 {
  return grp_ptr->gr_name;
 }
 return ((void *)0);
}

canonical_original_code:
char *gid_to_name(unsigned int gid)
{
 struct group *getgrgid();
 struct group *grp_ptr;
 static char numstr[10];
 if ( ( grp_ptr = getgrgid(gid) ) == ((void *)0) )
 {
  sprintf(numstr,"%d", gid);
  return numstr;
 }
 else
 {
  return grp_ptr->gr_name;
 }
 return ((void *)0);
}

variable_types:
gid
unsigned int

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *()


decompiled_code:
int __fastcall show_file_info(char *s, __int64 a2)
{
char *v2; // rax
char *v3; // rax
char *v4; // rax
char v6[35]; // [rsp+5h] [rbp-23h] BYREF

mode_to_letters(*(_DWORD *)(a2 + 24), v6);
printf("%s", v6);
printf("%4d ", *(unsigned int *)(a2 + 16));
v2 = uid_to_name(*(_DWORD *)(a2 + 28));
printf("%-8s ", v2);
v3 = gid_to_name(*(_DWORD *)(a2 + 32));
printf("%-8s ", v3);
printf("%8ld ", *(_QWORD *)(a2 + 48));
v4 = ctime((const time_t *)(a2 + 88));
printf("%.12s ", v4 + 4);
return puts(s);
}

original_code:
void show_file_info( char *filename, struct stat *info_p )
{
 char *uid_to_name();
 char *ctime();
 char *gid_to_name();
 char *filemode();
 void mode_to_letters();
 char modestr[11];
 mode_to_letters( info_p->st_mode, modestr );
 printf( "%s" , modestr );
 printf( "%4d " , (int) info_p->st_nlink);
 printf( "%-8s " , uid_to_name(info_p->st_uid) );
 printf( "%-8s " , gid_to_name(info_p->st_gid) );
 printf( "%8ld " , (long)info_p->st_size);
 printf( "%.12s ", 4+ctime(&info_p->st_mtim.tv_sec));
 printf( "%s\n" , filename );
}

canonical_original_code:
void show_file_info(char *filename, struct stat *info_p)
{
 char *uid_to_name();
 char *ctime();
 char *gid_to_name();
 char *filemode();
 void mode_to_letters();
 char modestr[11];
 mode_to_letters( info_p->st_mode, modestr );
 printf( "%s" , modestr );
 printf( "%4d " , (int) info_p->st_nlink);
 printf( "%-8s " , uid_to_name(info_p->st_uid) );
 printf( "%-8s " , gid_to_name(info_p->st_gid) );
 printf( "%8ld " , (long)info_p->st_size);
 printf( "%.12s ", 4+ctime(&info_p->st_mtim.tv_sec));
 printf( "%s\n" , filename );
}

variable_types:
filename
char *

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

variable_types:
ctime
char *()

variable_types:
filemode
char *()

variable_types:
modestr
char [11]

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


decompiled_code:
void __fastcall do_stat(char *s)
{
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)stat(s, &v1) == -1 )
perror(s);
else
show_file_info(s, (__int64)&v1);
}

canonical_decompiled_code:
void __fastcall func11(char *s)
{
struct stat v1; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func15(s, &v1) == -1 )
perror(s);
else
func10(s, (__int64)&v1);
}

original_code:
void do_stat( char *filename)
{
 struct stat info;
 if ( stat(filename, &info) == -1 )
 {
  perror( filename );
 }
 else
 {
  show_file_info( filename, &info );
 }
}

canonical_original_code:
void do_stat(char *filename)
{
 struct stat info;
 if ( stat(filename, &info) == -1 )
 {
  perror( filename );
 }
 else
 {
  show_file_info( filename, &info );
 }
}

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // rdx
int v6; // ebp

if ( argc == 1 )
{
do_ls(".", 0);
}
else
{
v3 = (char **)argv;
v4 = argv;
do
{
if ( !*v4 )
{
v6 = 0;
goto LABEL_9;
}
}
while ( strcmp(*v4++, "-a") != 0 );
if ( argc == 2 )
{
do_ls(".", 1);
return 0;
}
v6 = 1;
do
LABEL_9:
do_ls(*++v3, v6);
while ( v3 != (char **)&argv[argc - 1] );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx
const char **v4; // rdx
int v6; // ebp

if ( argc == 1 )
{
func12(".", 0);
}
else
{
v3 = (char **)argv;
v4 = argv;
do
{
if ( !*v4 )
{
v6 = 0;
goto LABEL_9;
}
}
while ( strcmp(*v4++, "-a") != 0 );
if ( argc == 2 )
{
func12(".", 1);
return 0;
}
v6 = 1;
do
LABEL_9:
func12(*++v3, v6);
while ( v3 != (char **)&argv[argc - 1] );
}
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
 int i = 0;
 int flag = 0;
 if ( argc == 1 )
 {
  do_ls( ".", 0);
  return 0;
 }
 while (argv[i] != ((void *)0))
 {
  if (strcmp(argv[i++], "-a") == 0)
  {
   flag = 1;
   break;
  }
 }
 if (argc == 2 && flag == 1)
 {
  do_ls( ".", 1);
  return 0;
 }
 while ( --argc )
 {
  do_ls( *(++argv), flag);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int i = 0;
 int flag = 0;
 if ( argc == 1 )
 {
  do_ls( ".", 0);
  return 0;
 }
 while (argv[i] != ((void *)0))
 {
  if (strcmp(argv[i++], "-a") == 0)
  {
   flag = 1;
   break;
  }
 }
 if (argc == 2 && flag == 1)
 {
  do_ls( ".", 1);
  return 0;
 }
 while ( --argc )
 {
  do_ls( *(++argv), flag);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int


decompiled_code:
int __fastcall copy_file(char *src, char *dest)
{
char *v2; // rax
char *v3; // rbp

v2 = strrchr(src, 47);
if ( v2 )
{
v3 = v2;
*(_WORD *)&dest[strlen(dest)] = 47;
strcat(dest, v3 + 1);
}
else
{
*(_WORD *)&dest[strlen(dest)] = 47;
strcat(dest, src);
}
return rename(src, dest);
}

canonical_decompiled_code:
int __fastcall func7(char *src, char *dest)
{
char *v2; // rax
char *v3; // rbp

v2 = strrchr(src, 47);
if ( v2 )
{
v3 = v2;
*(_WORD *)&dest[strlen(dest)] = 47;
strcat(dest, v3 + 1);
}
else
{
*(_WORD *)&dest[strlen(dest)] = 47;
strcat(dest, src);
}
return rename(src, dest);
}

original_code:
void copy_file(char *src, char *dest)
{
 char *new_file = ((void *)0);
 if ((new_file = strrchr(src, '/')) == ((void *)0))
 {
  strcat(dest, "/");
  strcat(dest, src);
 }
 else
 {
  strcat(dest, "/");
  new_file++;
  strcat(dest, new_file);
 }
 rename(src, dest);
}

variable_types:
src
char *

variable_types:
dest
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx

if ( argc <= 2 )
{
perror("Usage: icp source dest\n");
exit(1);
}
v3 = (char **)(argv + 1);
do
do_copy(*v3++, (char *)argv[argc - 1]);
while ( v3 != (char **)&argv[(unsigned int)(argc - 3) + 2] );
puts("Finish...");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char **v3; // rbx

if ( argc <= 2 )
{
perror("Usage: icp source dest\n");
exit(1);
}
v3 = (char **)(argv + 1);
do
func8(*v3++, (char *)argv[argc - 1]);
while ( v3 != (char **)&argv[(unsigned int)(argc - 3) + 2] );
puts("Finish...");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc < 3)
 {
  perror("Usage: icp source dest\n");
  exit(1);
 }
 int i;
 for (i = 1; i < argc - 1; i++)
 {
  do_copy(argv[i], argv[argc-1]);
 }
 printf("Finish...\n");
 return 0;
}


decompiled_code:
int __fastcall do_rm_files(const char *a1)
{
int result; // eax

if ( *a1 )
result = remove(a1);
else
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
int result; // eax

if ( *a1 )
result = remove(a1);
else
result = -1;
return result;
}

original_code:
int do_rm_files(char *file)
{
 if (!(*file))
 {
  return -1;
 }
 return remove(file);
}

variable_types:
file
char *


decompiled_code:
int __fastcall do_rm_empty_dirs(const char *a1)
{
int result; // eax

if ( *a1 )
result = rmdir(a1);
else
result = -1;
return result;
}

canonical_decompiled_code:
int __fastcall func8(const char *a1)
{
int result; // eax

if ( *a1 )
result = rmdir(a1);
else
result = -1;
return result;
}

original_code:
int do_rm_empty_dirs(char *dir)
{
 if (!(*dir))
 {
  return -1;
 }
 return rmdir(dir);
}

variable_types:
dir
char *


decompiled_code:
int __fastcall do_rm_no_empty_dirs(char *src)
{
size_t v1; // rax
char *v2; // rbp

if ( !*src )
return -1;
v1 = strlen(src);
v2 = (char *)malloc(v1 + 8);
*(_QWORD *)v2 = 0x2066722D206D72LL;
strcat(v2, src);
return system(v2);
}

canonical_decompiled_code:
int __fastcall func9(char *src)
{
size_t v1; // rax
char *v2; // rbp

if ( !*src )
return -1;
v1 = strlen(src);
v2 = (char *)malloc(v1 + 8);
*(_QWORD *)v2 = 0x2066722D206D72LL;
strcat(v2, src);
return system(v2);
}

original_code:
int do_rm_no_empty_dirs(char *dir)
{
 if (!(*dir))
 {
  return -1;
 }
 char *cmd = (char *)malloc(sizeof(char) * (8 + strlen(dir)));
 strcpy(cmd, "rm -rf ");
 strcat(cmd, dir);
 return system(cmd);
}

variable_types:
cmd
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // r13
const char **v5; // rbp
int v6; // er14
const char *v7; // r12
int v9; // [rsp+Ch] [rbp-3Ch]

if ( argc <= 1 )
{
perror("Usage: missing directory or file names\n");
exit(1);
}
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
v5 = argv + 1;
v6 = 0;
v9 = 0;
do
{
v7 = *v5;
if ( strstr(*v5, "-d") )
{
v9 = 1;
}
else if ( strstr(v7, "-D") )
{
v6 = 1;
}
++v5;
}
while ( v5 != v4 );
do
{
if ( strcmp(*v3, "-d") && strcmp(*v3, "-D") )
{
if ( v6 == 1 )
{
if ( do_rm_no_empty_dirs((char *)*v3) != -1 )
goto LABEL_13;
LABEL_11:
printf("\nUnable to delete directory %s\n", *v3);
goto LABEL_13;
}
if ( v9 )
{
if ( do_rm_empty_dirs(*v3) == -1 )
goto LABEL_11;
}
else if ( !(v6 | v9) && do_rm_files(*v3) )
{
printf("unable to delete file %s, maybe it's a none empty directory\n", *v3);
}
}
LABEL_13:
++v3;
}
while ( v3 != v4 );
puts("Finish...");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // r13
const char **v5; // rbp
int v6; // er14
const char *v7; // r12
int v9; // [rsp+Ch] [rbp-3Ch]

if ( argc <= 1 )
{
perror("Usage: missing directory or file names\n");
exit(1);
}
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
v5 = argv + 1;
v6 = 0;
v9 = 0;
do
{
v7 = *v5;
if ( strstr(*v5, "-d") )
{
v9 = 1;
}
else if ( strstr(v7, "-D") )
{
v6 = 1;
}
++v5;
}
while ( v5 != v4 );
do
{
if ( strcmp(*v3, "-d") && strcmp(*v3, "-D") )
{
if ( v6 == 1 )
{
if ( func9((char *)*v3) != -1 )
goto LABEL_13;
LABEL_11:
printf("\nUnable to delete directory %s\n", *v3);
goto LABEL_13;
}
if ( v9 )
{
if ( func8(*v3) == -1 )
goto LABEL_11;
}
else if ( !(v6 | v9) && func7(*v3) )
{
printf("unable to delete file %s, maybe it's a none empty directory\n", *v3);
}
}
LABEL_13:
++v3;
}
while ( v3 != v4 );
puts("Finish...");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc < 2)
 {
  perror("Usage: missing directory or file names\n");
  exit(1);
 }
 int i;
 int rm_empty_flag = 0;
 int rm_no_empty_flag = 0;
 for (i = 1; i < argc; i++)
 {
  if (strstr(argv[i], "-d") != ((void *)0))
  {
   rm_empty_flag = 1;
  }
  else if (strstr(argv[i], "-D") != ((void *)0))
  {
   rm_no_empty_flag = 1;
  }
 }
 for (i = 1; i < argc; i++)
 {
  if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "-D") == 0)
  {
   continue;
  }
  if (1 == rm_no_empty_flag)
  {
   if (do_rm_no_empty_dirs(argv[i]) == -1)
   {
    printf("\nUnable to delete directory %s\n", argv[i]);
   }
  }
  else if (0 == rm_no_empty_flag && 1 == rm_empty_flag)
  {
   if (do_rm_empty_dirs(argv[i]) == -1)
   {
    printf("\nUnable to delete directory %s\n", argv[i]);
   }
  }
  else if (0 == rm_empty_flag && 0 == rm_no_empty_flag)
  {
   if (do_rm_files(argv[i]) != 0)
   {
    printf("unable to delete file %s, maybe it's a none empty directory\n", argv[i]);
   }
  }
 }
 printf("Finish...\n");
 return 0;
}


decompiled_code:
__int64 __fastcall Submit_Cmd()
{
bool v0; // cf
bool v1; // zf
char *v2; // rsi
const char *v3; // rdi
__int64 v4; // rcx
ssize_t v5; // rax
unsigned int v6; // eax

v2 = &g_buf_cmd;
v3 = "exit";
v4 = 5LL;
do
{
if ( !v4 )
break;
v0 = (unsigned __int8)*v2 < (unsigned int)*v3;
v1 = *v2++ == *v3++;
--v4;
}
while ( v1 );
if ( (!v0 && !v1) == v0 )
exit(0);
Shell_Main(&g_buf_cmd, v2);
memset(buf, 0, sizeof(buf));
v5 = read(apipe[0], buf, 0x900uLL);
if ( v5 == -1 )
{
g_print("error,when reading from pipe\n");
exit(1);
}
if ( g_change_dir == 1 )
{
qword_870 = 0LL;
qword_878 = 0LL;
qword_880 = 0LL;
qword_888 = 0LL;
qword_890 = 0LL;
qword_898 = 0LL;
strcpy(g_dir, "pxunl@lnuxp");
byte_8BF[v5] = 35;
strcat(g_dir, buf);
memset(buf, 0, sizeof(buf));
g_change_dir = 0;
}
count = 0;
gtk_text_buffer_get_end_iter(buffer, &iter);
gtk_text_buffer_insert(buffer, &iter, "\n", 0xFFFFFFFFLL);
gtk_text_buffer_get_end_iter(buffer, &iter);
gtk_text_buffer_insert(buffer, &iter, buf, 0xFFFFFFFFLL);
memset(buf, 0, sizeof(buf));
memset(&g_buf_cmd, 0, 0x200uLL);
v6 = clear_count++;
if ( v6 > 0xA )
{
gtk_text_buffer_get_bounds(buffer, &start_iter, &end_iter);
gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
clear_count = 0;
}
gtk_text_buffer_get_end_iter(buffer, &iter);
return gtk_text_buffer_insert(buffer, &iter, g_dir, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func0()
{
bool v0; // cf
bool v1; // zf
char *v2; // rsi
const char *v3; // rdi
__int64 v4; // rcx
ssize_t v5; // rax
unsigned int v6; // eax

v2 = &g_buf_cmd;
v3 = "exit";
v4 = 5LL;
do
{
if ( !v4 )
break;
v0 = (unsigned __int8)*v2 < (unsigned int)*v3;
v1 = *v2++ == *v3++;
--v4;
}
while ( v1 );
if ( (!v0 && !v1) == v0 )
exit(0);
Shell_Main(&g_buf_cmd, v2);
memset(buf, 0, sizeof(buf));
v5 = read(apipe[0], buf, 0x900uLL);
if ( v5 == -1 )
{
g_print("error,when reading from pipe\n");
exit(1);
}
if ( g_change_dir == 1 )
{
qword_870 = 0LL;
qword_878 = 0LL;
qword_880 = 0LL;
qword_888 = 0LL;
qword_890 = 0LL;
qword_898 = 0LL;
strcpy(g_dir, "pxunl@lnuxp");
byte_8BF[v5] = 35;
strcat(g_dir, buf);
memset(buf, 0, sizeof(buf));
g_change_dir = 0;
}
count = 0;
gtk_text_buffer_get_end_iter(buffer, &iter);
gtk_text_buffer_insert(buffer, &iter, "\n", 0xFFFFFFFFLL);
gtk_text_buffer_get_end_iter(buffer, &iter);
gtk_text_buffer_insert(buffer, &iter, buf, 0xFFFFFFFFLL);
memset(buf, 0, sizeof(buf));
memset(&g_buf_cmd, 0, 0x200uLL);
v6 = clear_count++;
if ( v6 > 0xA )
{
gtk_text_buffer_get_bounds(buffer, &start_iter, &end_iter);
gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
clear_count = 0;
}
gtk_text_buffer_get_end_iter(buffer, &iter);
return gtk_text_buffer_insert(buffer, &iter, g_dir, 0xFFFFFFFFLL);
}

original_code:
static void Submit_Cmd()
{
 if (strcmp(g_buf_cmd, "exit") == 0)
 {
  exit(0);
 }
 glong len = 0;
 Shell_Main(g_buf_cmd);
 memset(buf, '\0', 2304);
 if ((len = read(apipe[0], buf, 2304)) == -1)
 {
  g_print("error,when reading from pipe\n");
  exit(1);
 }
 if (g_change_dir == 1)
 {
  memset(g_dir, '\0', 64);
  strcpy(g_dir, "pxunl@lnuxp");
  buf[len-1] = '#';
  strcat(g_dir, buf);
  memset(buf, '\0', 2304);
  g_change_dir = 0;
 }
 count = 0;
 gtk_text_buffer_get_end_iter(buffer, &iter);
 gtk_text_buffer_insert(buffer, &iter, "\n", -1);
 gtk_text_buffer_get_end_iter(buffer, &iter);
 gtk_text_buffer_insert(buffer, &iter, buf, -1);
 memset(buf, '\0', 2304);
 memset(g_buf_cmd, '\0', 512);
 if ((clear_count++) > 10)
 {
  gtk_text_buffer_get_bounds(buffer, &start_iter, &end_iter);
  gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
  clear_count = 0;
 }
 gtk_text_buffer_get_end_iter(buffer, &iter);
 gtk_text_buffer_insert(buffer, &iter, g_dir, -1);
}

canonical_original_code:
static void Submit_Cmd()
{
 if (strcmp(g_buf_cmd, "exit") == 0)
 {
  exit(0);
 }
 long len = 0;
 Shell_Main(g_buf_cmd);
 memset(buf, '\0', 2304);
 if ((len = read(apipe[0], buf, 2304)) == -1)
 {
  g_print("error,when reading from pipe\n");
  exit(1);
 }
 if (g_change_dir == 1)
 {
  memset(g_dir, '\0', 64);
  strcpy(g_dir, "pxunl@lnuxp");
  buf[len-1] = '#';
  strcat(g_dir, buf);
  memset(buf, '\0', 2304);
  g_change_dir = 0;
 }
 count = 0;
 gtk_text_buffer_get_end_iter(buffer, &iter);
 gtk_text_buffer_insert(buffer, &iter, "\n", -1);
 gtk_text_buffer_get_end_iter(buffer, &iter);
 gtk_text_buffer_insert(buffer, &iter, buf, -1);
 memset(buf, '\0', 2304);
 memset(g_buf_cmd, '\0', 512);
 if ((clear_count++) > 10)
 {
  gtk_text_buffer_get_bounds(buffer, &start_iter, &end_iter);
  gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
  clear_count = 0;
 }
 gtk_text_buffer_get_end_iter(buffer, &iter);
 gtk_text_buffer_insert(buffer, &iter, g_dir, -1);
}

variable_types: len long


initialize

decompiled_code:
__sighandler_t initialize()
{
size_t v0; // rax

g_change_dir = 0;
memset(buf, 0, sizeof(buf));
qword_868 = 0LL;
qword_870 = 0LL;
qword_878 = 0LL;
qword_880 = 0LL;
qword_888 = 0LL;
qword_890 = 0LL;
qword_898 = 0LL;
memset(g_buf_cmd, 0, sizeof(g_buf_cmd));
strcpy(g_dir, "pxunl@lnuxp");
v0 = strlen(g_dir);
*(_WORD *)&g_dir[v0] = 9006;
g_dir[v0 + 2] = 0;
Env_To_Table(environ);
if ( pipe(apipe) == -1 )
{
g_print("couldn't make pipe");
exit(1);
}
dup2(apipe[1], 1);
dup2(apipe[1], 2);
signal(2, handler);
return signal(3, handler);
}

canonical_decompiled_code:
__sighandler_t func3()
{
size_t v0; // rax

g_change_dir = 0;
memset(buf, 0, sizeof(buf));
qword_868 = 0LL;
qword_870 = 0LL;
qword_878 = 0LL;
qword_880 = 0LL;
qword_888 = 0LL;
qword_890 = 0LL;
qword_898 = 0LL;
memset(g_buf_cmd, 0, sizeof(g_buf_cmd));
strcpy(g_dir, "pxunl@lnuxp");
v0 = strlen(g_dir);
*(_WORD *)&g_dir[v0] = 9006;
g_dir[v0 + 2] = 0;
Env_To_Table(environ);
if ( pipe(apipe) == -1 )
{
g_print("couldn't make pipe");
exit(1);
}
dup2(apipe[1], 1);
dup2(apipe[1], 2);
signal(2, handler);
return signal(3, handler);
}

original_code:
void initialize()
{
 g_change_dir = 0;
 memset(buf, '\0', 2304);
 memset(g_dir, '\0', 64);
 memset(g_buf_cmd, '\0', sizeof(g_buf_cmd));
 strcpy(g_dir, "pxunl@lnuxp");
 strcat(g_dir, ".#");
 Env_To_Table(environ);
 if (pipe(apipe) == -1)
 {
  g_print("couldn't make pipe");
  exit(1);
 }
 dup2(apipe[1], 1);
 dup2(apipe[1], 2);
 signal(2, ((__sighandler_t) 1));
 signal(3, ((__sighandler_t) 1));
}

canonical_original_code:
void initialize()
{
 g_change_dir = 0;
 memset(buf, '\0', 2304);
 memset(g_dir, '\0', 64);
 memset(g_buf_cmd, '\0', sizeof(g_buf_cmd));
 strcpy(g_dir, "pxunl@lnuxp");
 strcat(g_dir, ".#");
 Env_To_Table(environ);
 if (pipe(apipe) == -1)
 {
  g_print("couldn't make pipe");
  exit(1);
 }
 dup2(apipe[1], 1);
 dup2(apipe[1], 2);
 signal(2, ((void (*)(int)) 1));
 signal(3, ((void (*)(int)) 1));
}


decompiled_code:
void sig_winch()
{
pr_winsize(1);
}

canonical_decompiled_code:
void func8()
{
func7(1);
}

original_code:
static void sig_winch(int signo)
{
 pr_winsize(1);
}

variable_types: signo int


noneprint

decompiled_code:
int __fastcall noneprint(int a1)
{
tcflag_t v1; // eax
struct termios v3; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

if ( tcgetattr(1, &termios_p) < 0 )
{
perror("Getting the attribute Error!");
exit(1);
}
*(__m128i *)&v3.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v3.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v3.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v3.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v3.c_ospeed = termios_p.c_ospeed;
if ( a1 == 1 )
v1 = v3.c_lflag & 0xFFFFFFF7;
else
v1 = v3.c_lflag | 8;
v3.c_lflag = v1;
return tcsetattr(1, 0, &v3);
}

canonical_decompiled_code:
int __fastcall func9(int a1)
{
tcflag_t v1; // eax
struct termios v3; // [rsp+0h] [rbp-88h] BYREF
struct termios termios_p; // [rsp+40h] [rbp-48h] BYREF

if ( tcgetattr(1, &termios_p) < 0 )
{
perror("Getting the attribute Error!");
exit(1);
}
*(__m128i *)&v3.c_iflag = _mm_loadu_si128((const __m128i *)&termios_p);
*(__m128i *)&v3.c_line = _mm_loadu_si128((const __m128i *)&termios_p.c_line);
*(__m128i *)&v3.c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p.c_cc[15]);
*(_QWORD *)&v3.c_cc[31] = *(_QWORD *)&termios_p.c_cc[31];
v3.c_ospeed = termios_p.c_ospeed;
if ( a1 == 1 )
v1 = v3.c_lflag & 0xFFFFFFF7;
else
v1 = v3.c_lflag | 8;
v3.c_lflag = v1;
return tcsetattr(1, 0, &v3);
}

original_code:
void noneprint(int flag)
{
 struct termios init_setting;
 struct termios pend_setting;
 if (tcgetattr(1, &init_setting) < 0)
 {
  perror("Getting the attribute Error!");
  exit (1);
 }
 pend_setting = init_setting;
 if(flag == 1)
  pend_setting.c_lflag &= ~0000010;
 else
  pend_setting.c_lflag |= 0000010;
 tcsetattr (1, 0, &pend_setting);
}

variable_types: flag int

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:
_BOOL8 __fastcall is_directory(char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)stat(a1, &v2) == -1 )
perror("stat");
return (v2.st_mode & 0xF000) != 0x4000;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func13(a1, &v2) == -1 )
perror("stat");
return (v2.st_mode & 0xF000) != 0x4000;
}

original_code:
int is_directory(const char *file)
{
 struct stat stat_ck;
 if (stat(file, &stat_ck) == -1)
 {
  perror("stat");
 }
 if (((((stat_ck.st_mode)) & 0170000) == (0040000)))
 {
  return 0;
 }
 return 1;
}

canonical_original_code:
int is_directory(char *file)
{
 struct stat stat_ck;
 if (stat(file, &stat_ck) == -1)
 {
  perror("stat");
 }
 if (((((stat_ck.st_mode)) & 0170000) == (0040000)))
 {
  return 0;
 }
 return 1;
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
int __fastcall do_cat(char *file)
{
int v1; // ebx
int v3; // eax
char v4[152]; // [rsp+0h] [rbp-98h] BYREF

if ( !is_directory(file) )
return printf("%s: %s: Is a directory\n", "icat", file);
v1 = open(file, 0);
if ( v1 == -1 )
{
printf("can't read %s, please check it's permision\n", file);
exit(1);
}
while ( 1 )
{
v3 = read(v1, v4, 0x80uLL);
if ( !v3 )
break;
v4[v3] = 0;
printf("%s", v4);
}
return close(v1);
}

canonical_decompiled_code:
int __fastcall func10(char *file)
{
int v1; // ebx
int v3; // eax
char v4[152]; // [rsp+0h] [rbp-98h] BYREF

if ( !func8(file) )
return printf("%s: %s: Is a directory\n", "icat", file);
v1 = open(file, 0);
if ( v1 == -1 )
{
printf("can't read %s, please check it's permision\n", file);
exit(1);
}
while ( 1 )
{
v3 = read(v1, v4, 0x80uLL);
if ( !v3 )
break;
v4[v3] = 0;
printf("%s", v4);
}
return close(v1);
}

original_code:
void do_cat(const char *file)
{
 if (is_directory(file) == 0)
 {
  printf("%s: %s: Is a directory\n", "icat", file);
  return;
 }
 int read_size = 0;
 char buf[128];
 int fd;
 if ((fd = open(file, 00)) == -1)
 {
  printf("can't read %s, please check it's permision\n", file);
  exit(1);
 }
 while ((read_size = read(fd, buf, 128)) != 0)
 {
  buf[read_size] = '\0';
  printf("%s", buf);
 }
 close(fd);
}

canonical_original_code:
void do_cat(char *file)
{
 if (is_directory(file) == 0)
 {
  printf("%s: %s: Is a directory\n", "icat", file);
  return;
 }
 int read_size = 0;
 char buf[128];
 int fd;
 if ((fd = open(file, 00)) == -1)
 {
  printf("can't read %s, please check it's permision\n", file);
  exit(1);
 }
 while ((read_size = read(fd, buf, 128)) != 0)
 {
  buf[read_size] = '\0';
  printf("%s", buf);
 }
 close(fd);
}

variable_types:
buf
char [128]

variable_types: fd int


usage

decompiled_code:
void __fastcall __noreturn usage(int status)
{
if ( status )
{
fprintf(stderr, "Try `%s --help' for more information.\n", "icat");
}
else
{
printf("Usage: %s [OPTION]...\n", "icat");
printf(
"\n%s\n%s\n",
"Concatenate FILE(s), or standard input, to standard output",
"-n(--number:number all output lines");
}
exit(status);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int status)
{
if ( status )
{
fprintf(stderr, "Try `%s --help' for more information.\n", "icat");
}
else
{
printf("Usage: %s [OPTION]...\n", "icat");
printf(
"\n%s\n%s\n",
"Concatenate FILE(s), or standard input, to standard output",
"-n(--number:number all output lines");
}
exit(status);
}

original_code:
void usage(int status)
{
 if (status != 0)
  fprintf (stderr, ("Try `%s --help' for more information.\n"),
    "icat");
 else
 {
  printf (("Usage: %s [OPTION]...\n"), "icat");
  printf(("\n%s\n%s\n"),"Concatenate FILE(s), or standard input, to standard output",
     "-n(--number:number all output lines");
    }
 exit (status);
}

variable_types: status int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
char *v4; // rbx

if ( (unsigned int)(argc - 2) > 1 )
usage(0);
if ( argc == 2 )
{
do_cat((char *)argv[1]);
}
else
{
v3 = (char *)argv[1];
if ( !strpbrk(v3, "-n") )
do_cat_with_option(v3, (__int64)"-n");
v4 = (char *)argv[2];
if ( !strpbrk(v4, "-n") )
do_cat_with_option(v4, (__int64)"-n");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbp
char *v4; // rbx

if ( (unsigned int)(argc - 2) > 1 )
func7(0);
if ( argc == 2 )
{
func10((char *)argv[1]);
}
else
{
v3 = (char *)argv[1];
if ( !strpbrk(v3, "-n") )
func9(v3, (__int64)"-n");
v4 = (char *)argv[2];
if ( !strpbrk(v4, "-n") )
func9(v4, (__int64)"-n");
}
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
 if (argc != 2 && argc != 3)
 {
  usage(0);
 }
 int i;
 if (argc == 2)
 {
  do_cat(argv[1]);
 }
 else if (argc == 3)
 {
  for (i = 1; i < 3; i++)
  {
   if (strpbrk(argv[i], "-n"))
   {
    continue;
   }
   do_cat_with_option(argv[i], "-n");
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if (argc != 2 && argc != 3)
 {
  usage(0);
 }
 int i;
 if (argc == 2)
 {
  do_cat(argv[1]);
 }
 else if (argc == 3)
 {
  for (i = 1; i < 3; i++)
  {
   if (strpbrk(argv[i], "-n"))
   {
    continue;
   }
   do_cat_with_option(argv[i], "-n");
  }
 }
 return 0;
}


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

result = 1LL;
if ( *a1 )
{
mkdir(a1, 0x1C0u);
result = 0LL;
}
return result;
}

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

result = 1LL;
if ( *a1 )
{
mkdir(a1, 0x1C0u);
result = 0LL;
}
return result;
}

original_code:
int do_mkdir(char *dir)
{
 if (!(*dir))
 {
  return R_FALSE;
 }
 mkdir(dir, (0400|0200|0100));
 return R_TRUE;
}


decompiled_code:
__int64 __fastcall check_name(char *a1)
{
_BYTE *v1; // rbx
const unsigned __int16 *v2; // rdx
char v3; // al
unsigned int v4; // ecx

if ( !a1 )
return 1LL;
v1 = a1;
v2 = *__ctype_b_loc();
v3 = *a1;
v4 = 1;
if ( (v2[*a1] & 0x800) == 0 )
{
if ( v3 )
{
while ( 1 )
{
if ( v3 == 32 || v3 == 61 )
return 1;
if ( (v2[v3] & 8) == 0 )
break;
v3 = *++v1;
if ( !*v1 )
return 0;
}
v4 = 1;
}
else
{
v4 = 0;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
_BYTE *v1; // rbx
const unsigned __int16 *v2; // rdx
char v3; // al
unsigned int v4; // ecx

if ( !a1 )
return 1LL;
v1 = a1;
v2 = *__ctype_b_loc();
v3 = *a1;
v4 = 1;
if ( (v2[*a1] & 0x800) == 0 )
{
if ( v3 )
{
while ( 1 )
{
if ( v3 == 32 || v3 == 61 )
return 1;
if ( (v2[v3] & 8) == 0 )
break;
v3 = *++v1;
if ( !*v1 )
return 0;
}
v4 = 1;
}
else
{
v4 = 0;
}
}
return v4;
}

original_code:
int check_name(char *name)
{
 if (!name)
 {
  return R_FALSE;
 }
 char * ck = name;
 if (((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short int) _ISdigit))
 {
  return R_FALSE;
 }
 while (*ck)
 {
  if (*ck == ' ' || *ck == '=' || !(((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short int) _ISalnum)))
  {
   return R_FALSE;
  }
  ck++;
 }
 return R_TRUE;
}

canonical_original_code:
int check_name(char *name)
{
 if (!name)
 {
  return R_FALSE;
 }
 char *ck = name;
 if (((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short) _ISdigit))
 {
  return R_FALSE;
 }
 while (*ck)
 {
  if (*ck == ' ' || *ck == '=' || !(((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short) _ISalnum)))
  {
   return R_FALSE;
  }
  ck++;
 }
 return R_TRUE;
}

variable_types:
name
char *

variable_types:
ck
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx

if ( argc <= 1 )
{
perror("Usage: missing new directory name\n");
exit(1);
}
v3 = (char *)argv[1];
if ( (unsigned int)check_name(v3) == 1 )
{
perror("valdlity directory name\n");
}
else if ( (unsigned int)do_mkdir(v3) == 1 )
{
puts("Fail");
}
else
{
puts("Finish...");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx

if ( argc <= 1 )
{
perror("Usage: missing new directory name\n");
exit(1);
}
v3 = (char *)argv[1];
if ( (unsigned int)func8(v3) == 1 )
{
perror("valdlity directory name\n");
}
else if ( (unsigned int)func7(v3) == 1 )
{
puts("Fail");
}
else
{
puts("Finish...");
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 if (argc < 2)
 {
  perror("Usage: missing new directory name\n");
  exit(1);
 }
 if (check_name(argv[1]) == R_FALSE)
 {
  perror("valdlity directory name\n");
  return 0;
 }
 if (R_FALSE == do_mkdir(argv[1]))
 {
  printf("Fail\n");
  return 0;
 }
 printf("Finish...\n");
 return 0;
}

variable_types: argc int


decompiled_code:
int __fastcall Show_Info(__int64 a1)
{
printf("%-8.8s", (const char *)(a1 + 40));
putchar(32);
printf("%-8.8s", (const char *)(a1 + 44));
putchar(32);
printf("%-8.8s", (const char *)(a1 + 8));
putchar(32);
printf("% 10ld", *(unsigned int *)(a1 + 340));
putchar(32);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
printf("%-8.8s", (const char *)(a1 + 40));
putchar(32);
printf("%-8.8s", (const char *)(a1 + 44));
putchar(32);
printf("%-8.8s", (const char *)(a1 + 8));
putchar(32);
printf("% 10ld", *(unsigned int *)(a1 + 340));
putchar(32);
return putchar(10);
}

original_code:
void Show_Info(struct utmp *buf_fp)
{
 printf("%-8.8s", buf_fp->ut_id);
 printf(" ");
 printf("%-8.8s", buf_fp->ut_user);
 printf(" ");
 printf("%-8.8s", buf_fp->ut_line);
 printf(" ");
 printf("% 10ld", buf_fp->ut_tv.tv_sec);
 printf(" ");
 printf("\n");
}

variable_types: struct utmp { short ut_type; int ut_pid; char ut_line[32]; char ut_id[4]; char ut_user[32]; char ut_host[256]; struct exit_status { short e_termination; short e_exit; } ut_exit; int ut_session; struct { int tv_sec; int tv_usec; } ut_tv; int ut_addr_v6[4]; char __glibc_reserved[20]; } *

user_defined_types: struct utmp { short ut_type; int ut_pid; char ut_line[32]; char ut_id[4]; char ut_user[32]; char ut_host[256]; struct exit_status ut_exit; int ut_session; struct { int tv_sec; int tv_usec; } ut_tv; int ut_addr_v6[4]; char __glibc_reserved[20]; }


Execute

decompiled_code:
__int64 __fastcall Execute(char **argv)
{
__pid_t v1; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

LODWORD(stat_loc.__uptr) = -1;
if ( !*argv )
return 0xFFFFFFFFLL;
v1 = fork();
if ( v1 == -1 )
{
perror("fork fail");
}
else
{
if ( !v1 )
{
environ = (char **)Table_To_Env();
signal(2, 0LL);
signal(3, 0LL);
execvp(*argv, argv);
perror("illegal command!\n");
exit(1);
}
if ( wait((__WAIT_STATUS)&stat_loc) == -1 )
{
LODWORD(stat_loc.__uptr) = -1;
perror("wait\n");
}
LODWORD(stat_loc.__uptr) = ((__int64)stat_loc.__uptr & 0x7F) == 0 ? 1 : -1;
}
return LODWORD(stat_loc.__uptr);
}

canonical_decompiled_code:
__int64 __fastcall func0(char **argv)
{
__pid_t v1; // eax
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

LODWORD(stat_loc.__uptr) = -1;
if ( !*argv )
return 0xFFFFFFFFLL;
v1 = fork();
if ( v1 == -1 )
{
perror("fork fail");
}
else
{
if ( !v1 )
{
environ = (char **)Table_To_Env();
signal(2, 0LL);
signal(3, 0LL);
execvp(*argv, argv);
perror("illegal command!\n");
exit(1);
}
if ( wait((__WAIT_STATUS)&stat_loc) == -1 )
{
LODWORD(stat_loc.__uptr) = -1;
perror("wait\n");
}
LODWORD(stat_loc.__uptr) = ((__int64)stat_loc.__uptr & 0x7F) == 0 ? 1 : -1;
}
return LODWORD(stat_loc.__uptr);
}

original_code:
int Execute(char *argv[])
{
 int pid_f;
 int chlid_in = -1;
 extern char **environ;
 if (argv[0] == ((void *)0))
  return -1;
 if ((pid_f = fork()) == -1)
 {
  perror("fork fail");
 }
 else if (pid_f == 0)
 {
  environ = Table_To_Env();
  signal(2, ((__sighandler_t) 0));
  signal(3, ((__sighandler_t) 0));
  execvp(argv[0], argv);
  perror("illegal command!\n");
  exit(1);
 }
 else
 {
  if (wait(&chlid_in) == -1)
  {
   chlid_in = -1;
   perror("wait\n");
  }
  chlid_in = ((((chlid_in) & 0x7f) == 0)? 1: -1);
 }
 return chlid_in;
}

canonical_original_code:
int Execute(char *argv[])
{
 int pid_f;
 int chlid_in = -1;
 extern char **environ;
 if (argv[0] == ((void *)0))
  return -1;
 if ((pid_f = fork()) == -1)
 {
  perror("fork fail");
 }
 else if (pid_f == 0)
 {
  environ = Table_To_Env();
  signal(2, ((void (*)(int)) 0));
  signal(3, ((void (*)(int)) 0));
  execvp(argv[0], argv);
  perror("illegal command!\n");
  exit(1);
 }
 else
 {
  if (wait(&chlid_in) == -1)
  {
   chlid_in = -1;
   perror("wait\n");
  }
  chlid_in = ((((chlid_in) & 0x7f) == 0)? 1: -1);
 }
 return chlid_in;
}

variable_types:
argv
char *[]

variable_types:
environ
char **


decompiled_code:
__int64 Value_List()
{
__int64 *v0; // rbx
__int64 result; // rax
const char *v2; // rsi

v0 = g_Value;
do
{
v2 = (const char *)*v0;
if ( !*v0 )
break;
result = *((_DWORD *)v0 + 2) ? g_print(" * %s\n", v2) : g_print(" %s\n", v2);
v0 += 2;
}
while ( v0 != (__int64 *)" * %s\n" );
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 *v0; // rbx
__int64 result; // rax
const char *v2; // rsi

v0 = g_Value;
do
{
v2 = (const char *)*v0;
if ( !*v0 )
break;
result = *((_DWORD *)v0 + 2) ? g_print(" * %s\n", v2) : g_print(" %s\n", v2);
v0 += 2;
}
while ( v0 != (__int64 *)" * %s\n" );
return result;
}

original_code:
void Value_List()
{
 int i;
 for (i = 0; (i < 50 && g_Value[i].str != ((void *)0)); i++)
 {
  if (g_Value[i].global)
  {
   g_print(" * %s\n", g_Value[i].str);
  }
  else
  {
   g_print("   %s\n", g_Value[i].str);
  }
 }
}

variable_types: i int


decompiled_code:
__int64 __fastcall Value_Export(char *a1)
{
__int64 *v1; // rax
unsigned int v2; // edx

v1 = Find_Item(a1);
v2 = -1;
if ( v1 && *v1 )
{
*((_DWORD *)v1 + 2) = 1;
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
__int64 *v1; // rax
unsigned int v2; // edx

v1 = Find_Item(a1);
v2 = -1;
if ( v1 && *v1 )
{
*((_DWORD *)v1 + 2) = 1;
v2 = 1;
}
return v2;
}

original_code:
int Value_Export(char *name)
{
 struct Value *add_item;
 int flag = -1;
 if ((add_item = Find_Item(name)) != ((void *)0) && (add_item->str))
 {
  add_item->global = 1;
  flag = 1;
 }
 return flag;
}

variable_types: struct Value { char *str; int global; } *


decompiled_code:
char *__fastcall Create_Var(const char *a1, const char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbx

v2 = strlen(a1);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 2);
v5 = v4;
if ( v4 )
sprintf(v4, "%s=%s", a1, a2);
return v5;
}

canonical_decompiled_code:
char *__fastcall func2(const char *a1, const char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rax
char *v5; // rbx

v2 = strlen(a1);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 2);
v5 = v4;
if ( v4 )
sprintf(v4, "%s=%s", a1, a2);
return v5;
}

original_code:
char *Create_Var( char *name, char *var )
{
 char *add_var;
 add_var = malloc( strlen(name) + strlen(var) + 2);
 if (add_var != ((void *)0))
  sprintf(add_var, "%s=%s", name, var);
 return add_var;
}

canonical_original_code:
char *Create_Var(char *name, char *var)
{
 char *add_var;
 add_var = malloc( strlen(name) + strlen(var) + 2);
 if (add_var != ((void *)0))
  sprintf(add_var, "%s=%s", name, var);
 return add_var;
}

variable_types:
var
char *


decompiled_code:
__int64 __fastcall Check_Name(char *a1)
{
_BYTE *v1; // rbx
const unsigned __int16 *v2; // rdx
char v3; // al
unsigned int v4; // ecx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1;
v2 = *_ctype_b_loc();
v3 = *a1;
v4 = -1;
if ( (v2[*a1] & 0x800) == 0 )
{
if ( v3 )
{
while ( 1 )
{
if ( v3 == 32 || v3 == 61 )
return (unsigned int)-1;
if ( (v2[v3] & 8) == 0 )
break;
v3 = *++v1;
if ( !*v1 )
return 1;
}
v4 = -1;
}
else
{
v4 = 1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1)
{
_BYTE *v1; // rbx
const unsigned __int16 *v2; // rdx
char v3; // al
unsigned int v4; // ecx

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = a1;
v2 = *_ctype_b_loc();
v3 = *a1;
v4 = -1;
if ( (v2[*a1] & 0x800) == 0 )
{
if ( v3 )
{
while ( 1 )
{
if ( v3 == 32 || v3 == 61 )
return (unsigned int)-1;
if ( (v2[v3] & 8) == 0 )
break;
v3 = *++v1;
if ( !*v1 )
return 1;
}
v4 = -1;
}
else
{
v4 = 1;
}
}
return v4;
}

original_code:
int Check_Name(char *name)
{
 if (!name)
 {
  return -1;
 }
 char * ck = name;
 if (((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short int) _ISdigit))
 {
  return -1;
 }
 while (*ck)
 {
  if (*ck == ' ' || *ck == '=' || !(((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short int) _ISalnum)))
  {
   return -1;
  }
  ck++;
 }
 return 1;
}

canonical_original_code:
int Check_Name(char *name)
{
 if (!name)
 {
  return -1;
 }
 char *ck = name;
 if (((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short) _ISdigit))
 {
  return -1;
 }
 while (*ck)
 {
  if (*ck == ' ' || *ck == '=' || !(((*__ctype_b_loc ())[(int) ((*ck))] & (unsigned short) _ISalnum)))
  {
   return -1;
  }
  ck++;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall Value_Store(char *s)
{
__int64 result; // rax
char *v2; // r12
int v3; // ebp
int v4; // eax
char *v5; // rbx
int v6; // edx
__int64 *v7; // rbp
char *v8; // rbx

result = 0xFFFFFFFFLL;
if ( s )
{
v2 = strchr(s, 61);
v3 = strlen(s);
v4 = strlen(v2);
v5 = (char *)create_str(s, (unsigned int)(v3 - v4));
result = 0xFFFFFFFFLL;
if ( v5 )
{
v6 = Check_Name(v5);
result = 0xFFFFFFFFLL;
if ( v6 )
{
v7 = Find_Item(v5);
result = 0xFFFFFFFFLL;
if ( v7 )
{
v8 = Create_Var(v5, v2 + 1);
result = 0xFFFFFFFFLL;
if ( v8 )
{
if ( *v7 )
free((void *)*v7);
*v7 = (__int64)v8;
result = 1LL;
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *s)
{
__int64 result; // rax
char *v2; // r12
int v3; // ebp
int v4; // eax
char *v5; // rbx
int v6; // edx
__int64 *v7; // rbp
char *v8; // rbx

result = 0xFFFFFFFFLL;
if ( s )
{
v2 = strchr(s, 61);
v3 = strlen(s);
v4 = strlen(v2);
v5 = (char *)create_str(s, (unsigned int)(v3 - v4));
result = 0xFFFFFFFFLL;
if ( v5 )
{
v6 = func3(v5);
result = 0xFFFFFFFFLL;
if ( v6 )
{
v7 = Find_Item(v5);
result = 0xFFFFFFFFLL;
if ( v7 )
{
v8 = func2(v5, v2 + 1);
result = 0xFFFFFFFFLL;
if ( v8 )
{
if ( *v7 )
free((void *)*v7);
*v7 = (__int64)v8;
result = 1LL;
}
}
}
}
}
return result;
}

original_code:
int Value_Store(char *var)
{
 if (!var)
 {
  return -1;
 }
 int flag = -1;
 char *name = var;
 char *value = var;
 char *equal = ((void *)0);
 char *new_var;
 struct Value *item = ((void *)0);
 equal = strchr(var, '=');
 name = create_str(var, strlen(var) - strlen(equal));
 value = equal + 1;
 if ((!name) || (!value) || (!Check_Name(name)))
 {
  return -1;
 }
 if ((item = Find_Item(name)) != ((void *)0)
   && (new_var = Create_Var(name, value)) != ((void *)0))
 {
  if (item->str)
  {
   free(item->str);
  }
  item->str = new_var;
  flag = 1;
 }
 return flag;
}

variable_types:
value
char *

variable_types:
equal
char *


decompiled_code:
__int64 __fastcall Env_To_Table(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
const char *v3; // r12
size_t v4; // rax
char *v5; // rax
__int64 v6; // rbp
unsigned __int64 v7; // rax
unsigned __int64 v8; // rax

v1 = 0LL;
while ( 1 )
{
v2 = v1;
v3 = *(const char **)(a1 + 8 * v1);
if ( !v3 )
{
LABEL_5:
v8 = 4LL * v2;
g_Value[v8 / 2] = 0LL;
dword_388[v8] = 0;
return 1LL;
}
v4 = strlen(*(const char **)(a1 + 8 * v1));
v5 = (char *)malloc(v4 + 1);
v6 = (__int64)v5;
if ( !v5 )
return 0xFFFFFFFFLL;
strcpy(v5, v3);
v7 = 4 * v1;
g_Value[v7 / 2] = v6;
dword_388[v7] = 1;
v2 = ++v1;
if ( v1 == 50 )
goto LABEL_5;
}
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
const char *v3; // r12
size_t v4; // rax
char *v5; // rax
__int64 v6; // rbp
unsigned __int64 v7; // rax
unsigned __int64 v8; // rax

v1 = 0LL;
while ( 1 )
{
v2 = v1;
v3 = *(const char **)(a1 + 8 * v1);
if ( !v3 )
{
LABEL_5:
v8 = 4LL * v2;
g_Value[v8 / 2] = 0LL;
dword_388[v8] = 0;
return 1LL;
}
v4 = strlen(*(const char **)(a1 + 8 * v1));
v5 = (char *)malloc(v4 + 1);
v6 = (__int64)v5;
if ( !v5 )
return 0xFFFFFFFFLL;
strcpy(v5, v3);
v7 = 4 * v1;
g_Value[v7 / 2] = v6;
dword_388[v7] = 1;
v2 = ++v1;
if ( v1 == 50 )
goto LABEL_5;
}
}

original_code:
int Env_To_Table(char *env[])
{
 char *new_str;
 int i = 0;
 while ((i < 50) && (((void *)0) != env[i]))
 {
  new_str = malloc(1 + strlen(env[i]));
  if (!new_str)
  {
   return -1;
  }
  strcpy(new_str, env[i]);
  g_Value[i].str = new_str;
  g_Value[i].global = 1;
  i++;
 }
 g_Value[i].str = ((void *)0) ;
 g_Value[i].global = 0;
 return 1;
}

variable_types:
env
char *[]


decompiled_code:
__ino_t __fastcall get_inode(char *s)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)stat(s, &v2) == -1 )
{
fwrite("Cannot stat ", 1uLL, 0xCuLL, stderr);
perror(s);
exit(1);
}
return v2.st_ino;
}

canonical_decompiled_code:
__ino_t __fastcall func8(char *s)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( (unsigned int)func12(s, &v2) == -1 )
{
fwrite("Cannot stat ", 1uLL, 0xCuLL, stderr);
perror(s);
exit(1);
}
return v2.st_ino;
}

original_code:
ino_t get_inode( char *fname )
{
 struct stat info;
 if ( stat( fname , &info ) == -1 )
 {
  fprintf(stderr, "Cannot stat ");
  perror(fname);
  exit(1);
 }
 return info.st_ino;
}

canonical_original_code:
unsigned long get_inode(char *fname)
{
 struct stat info;
 if ( stat( fname , &info ) == -1 )
 {
  fprintf(stderr, "Cannot stat ");
  perror(fname);
  exit(1);
 }
 return info.st_ino;
}

variable_types:
fname
char *

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

return_type: unsigned long


printpathto

decompiled_code:
int __fastcall printpathto(__int64 a1)
{
__ino_t v1; // rax
__ino_t v2; // rax
char v4[8200]; // [rsp+0h] [rbp-2008h] BYREF

v1 = get_inode("..");
if ( v1 != a1 )
{
chdir("..");
inum_to_name(a1, v4, 0x2000);
v2 = get_inode((char *)".");
printpathto(v2);
LODWORD(v1) = printf("/%s", v4);
}
return v1;
}

original_code:
void printpathto( ino_t this_inode )
{
 ino_t my_inode ;
 char its_name[8192];
 if ( get_inode("..") != this_inode )
 {
  chdir( ".." );
  inum_to_name(this_inode,its_name,8192);
  my_inode = get_inode( "." );
  printpathto( my_inode );
  printf("/%s", its_name );
 }
}

canonical_original_code:
void printpathto(unsigned long this_inode)
{
 unsigned long my_inode;
 char its_name[8192];
 if ( get_inode("..") != this_inode )
 {
  chdir( ".." );
  inum_to_name(this_inode,its_name,8192);
  my_inode = get_inode( "." );
  printpathto( my_inode );
  printf("/%s", its_name );
 }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax

v3 = get_inode((char *)".");
printpathto(v3);
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax

v3 = func8((char *)".");
func9(v3);
putchar(10);
return 0;
}

original_code:
int main(int argc, const char *argv[])
{
 printpathto( get_inode( "." ) );
 putchar('\n');
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 printpathto( get_inode( "." ) );
 putchar('\n');
 return 0;
}


repo: pykello/arunos

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

putchar(123);
while ( 1 )
{
v3 = fread(&buff, 1uLL, 0x1000uLL, _bss_start);
if ( !v3 )
break;
b16encode((__int64)&buff, v3, (__int64)b16, v5);
b16[v5[0]] = 0;
printf("\"%s\",\n", b16);
}
printf("0},");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

putchar(123);
while ( 1 )
{
v3 = fread(&buff, 1uLL, 0x1000uLL, _bss_start);
if ( !v3 )
break;
func7((__int64)&buff, v3, (__int64)b16, v5);
b16[v5[0]] = 0;
printf("\"%s\",\n", b16);
}
printf("0},");
return 0;
}

original_code:
int main() {
 int buff_len;
 int b16_len;
 printf("{");
 while (buff_len = fread(buff, 1, 4096, stdin)) {
  b16encode(buff, buff_len, b16, &b16_len);
  b16[b16_len] = 0;
  printf("\"%s\",\n", b16);
 }
 printf("0},");
 return 0;
}


repo: pzl/dogwatch

decompiled_code:
void detection_start()
{
barks = 0;
}

canonical_decompiled_code:
void func0()
{
barks = 0;
}

original_code:
void detection_start(void){
 barks=0;
}

canonical_original_code:
void detection_start(){
 barks=0;
}


detect

decompiled_code:
void __fastcall __noreturn detect(__int64 a1)
{
int v1; // er13
char v2; // r12
struct tm *v3; // rax
char *v4; // rax
int v5; // ebx
struct tm *v6; // rax
char *v7; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF

v1 = 0;
v2 = 0;
while ( 1 )
{
do
sem_wait(*(sem_t **)(a1 + 32));
while ( *(int *)(a1 + 12) <= 0 );
v5 = 0;
do
{
if ( v2 )
{
if ( (unsigned int)*(unsigned __int8 *)(*(_QWORD *)(a1 + 40) + v5 + *(_DWORD *)(a1 + 8)) - 121 > 0xE )
{
v1 = 0;
}
else if ( (unsigned int)++v1 > 0x95F )
{
time(&timer);
v3 = localtime(&timer);
v4 = asctime(v3);
printf("barking stopped %s", v4);
v2 = 0;
}
}
else if ( (int)abs32(*(unsigned __int8 *)(*(_QWORD *)(a1 + 40) + v5 + *(_DWORD *)(a1 + 8)) - 128) > 21 )
{
++barks;
time(&timer);
v6 = localtime(&timer);
v7 = asctime(v6);
printf("barked! %s", v7);
v2 = 1;
}
++v5;
}
while ( *(_DWORD *)(a1 + 12) > v5 );
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1)
{
int v1; // er13
char v2; // r12
struct tm *v3; // rax
char *v4; // rax
int v5; // ebx
struct tm *v6; // rax
char *v7; // rax
time_t timer; // [rsp+8h] [rbp-40h] BYREF

v1 = 0;
v2 = 0;
while ( 1 )
{
do
sem_wait(*(sem_t **)(a1 + 32));
while ( *(int *)(a1 + 12) <= 0 );
v5 = 0;
do
{
if ( v2 )
{
if ( (unsigned int)*(unsigned __int8 *)(*(_QWORD *)(a1 + 40) + v5 + *(_DWORD *)(a1 + 8)) - 121 > 0xE )
{
v1 = 0;
}
else if ( (unsigned int)++v1 > 0x95F )
{
time(&timer);
v3 = localtime(&timer);
v4 = asctime(v3);
printf("barking stopped %s", v4);
v2 = 0;
}
}
else if ( (int)abs32(*(unsigned __int8 *)(*(_QWORD *)(a1 + 40) + v5 + *(_DWORD *)(a1 + 8)) - 128) > 21 )
{
++barks;
time(&timer);
v6 = localtime(&timer);
v7 = asctime(v6);
printf("barked! %s", v7);
v2 = 1;
}
++v5;
}
while ( *(_DWORD *)(a1 + 12) > v5 );
}
}

original_code:
void *detect(void *snd){
 sound *data = (sound *)snd;
 int i;
 unsigned char barking=0;
 unsigned int ms=0;
 time_t rawtime;
 struct tm * timeinfo;
 while (1){
  sem_wait(data->detector);
  for (i=0; i<data->plen; i++){
   if (!barking){
    if (abs(data->recorded[data->pstart+i]-128) >= 150 - 128){
     barking=1;
     barks++;
     time(&rawtime);
     timeinfo = localtime(&rawtime);
     printf("barked! %s", asctime(timeinfo));
    }
   } else {
    if (abs(data->recorded[data->pstart+i] - 128) <= 135 - 128){
     ms++;
     if (ms >= 8000*300/1000){
      barking=0;
      time(&rawtime);
      timeinfo = localtime(&rawtime);
      printf("barking stopped %s", asctime(timeinfo));
     }
    } else {
     ms = 0;
    }
   }
  }
 }
 return ((void *)0);
}

canonical_original_code:
void *detect(void *snd){
 struct sound *data = (sound *)snd;
 int i;
 unsigned char barking = 0;
 unsigned int ms = 0;
 long rawtime;
 struct tm *timeinfo;
 while (1){
  sem_wait(data->detector);
  for (i=0; i<data->plen; i++){
   if (!barking){
    if (abs(data->recorded[data->pstart+i]-128) >= 150 - 128){
     barking=1;
     barks++;
     time(&rawtime);
     timeinfo = localtime(&rawtime);
     printf("barked! %s", asctime(timeinfo));
    }
   } else {
    if (abs(data->recorded[data->pstart+i] - 128) <= 135 - 128){
     ms++;
     if (ms >= 8000*300/1000){
      barking=0;
      time(&rawtime);
      timeinfo = localtime(&rawtime);
      printf("barking stopped %s", asctime(timeinfo));
     }
    } else {
     ms = 0;
    }
   }
  }
 }
 return ((void *)0);
}

variable_types:
snd
void *

variable_types: struct sound { int frameIndex; int maxFrameIndex; int pstart; int plen; union sem_t { char __size[32]; long __align; } *drawer; union sem_t *writer; union sem_t *detector; unsigned char *recorded; } *

variable_types:
barking
unsigned char

variable_types:
ms
unsigned int

variable_types: rawtime long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *

return_type: void *

user_defined_types: struct sound { int frameIndex; int maxFrameIndex; int pstart; int plen; union sem_t *drawer; union sem_t *writer; union sem_t *detector; unsigned char *recorded; }


decompiled_code:
__int64 detection_end()
{
return (unsigned int)barks;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)barks;
}

original_code:
unsigned int detection_end(void){
 return barks;
}

canonical_original_code:
unsigned int detection_end(){
 return barks;
}

return_type: unsigned int


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

while ( 1 )
{
result = Pa_IsStreamActive(a1);
if ( (_DWORD)result != 1 )
break;
Pa_Sleep(300LL);
}
if ( (int)result < 0 )
{
v2 = (const char *)Pa_GetErrorText((unsigned int)result);
printf("Error recording: %s\n", v2);
exit(1);
}
return result;
}

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

while ( 1 )
{
result = Pa_IsStreamActive(a1);
if ( (_DWORD)result != 1 )
break;
Pa_Sleep(300LL);
}
if ( (int)result < 0 )
{
v2 = (const char *)Pa_GetErrorText((unsigned int)result);
printf("Error recording: %s\n", v2);
exit(1);
}
return result;
}

original_code:
static void audio_wait(PaStream *stream){
    PaError err = paNoError;
    while ((err = Pa_IsStreamActive(stream)) == 1){
        Pa_Sleep(300);
    }
    if (err < 0){
        printf("Error recording: %s\n", Pa_GetErrorText(err));
        exit(1);
    }
}

canonical_original_code:
static void audio_wait(void *stream){
    int err = paNoError;
    while ((err = Pa_IsStreamActive(stream)) == 1){
        Pa_Sleep(300);
    }
    if (err < 0){
        printf("Error recording: %s\n", Pa_GetErrorText(err));
        exit(1);
    }
}

variable_types:
stream
void *

variable_types: err int


close

decompiled_code:
int close()
{
unsigned int v0; // eax
unsigned int v1; // eax
const char *v3; // rax

nc_stop();
puts("terminating audio connection");
v0 = Pa_Terminate();
if ( v0 )
{
v3 = (const char *)Pa_GetErrorText(v0);
printf("PA terminate Error: %s\n", v3);
}
v1 = detection_end();
return printf("barked %d times, roughly\n", v1);
}

canonical_decompiled_code:
int func1()
{
unsigned int v0; // eax
unsigned int v1; // eax
const char *v3; // rax

nc_stop();
puts("terminating audio connection");
v0 = Pa_Terminate();
if ( v0 )
{
v3 = (const char *)Pa_GetErrorText(v0);
printf("PA terminate Error: %s\n", v3);
}
v1 = detection_end();
return printf("barked %d times, roughly\n", v1);
}

original_code:
static void close(void){
    unsigned int barks;
    nc_stop();
    printf("terminating audio connection\n");
    PaError err = Pa_Terminate();
    if (err != paNoError){
        printf("PA terminate Error: %s\n", Pa_GetErrorText(err));
    }
    barks = detection_end();
    printf("barked %d times, roughly\n", barks);
}

canonical_original_code:
static void close(){
    unsigned int barks;
    nc_stop();
    printf("terminating audio connection\n");
    int err = Pa_Terminate();
    if (err != paNoError){
        printf("PA terminate Error: %s\n", Pa_GetErrorText(err));
    }
    barks = detection_end();
    printf("barked %d times, roughly\n", barks);
}

variable_types:
barks
unsigned int


shutdown

decompiled_code:
void __noreturn shutdown()
{
nc_stop();
puts("shutting down");
close();
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
nc_stop();
puts("shutting down");
func1();
exit(0);
}

original_code:
static void shutdown(int sig){
    nc_stop();
    printf("shutting down\n");
    (void) sig;
    close();
    exit(0);
}

variable_types: sig int


map

decompiled_code:
__int64 __fastcall map(unsigned __int8 a1)
{
int v1; // eax
int v2; // ebx
__int64 v3; // rax
int v4; // ebx
int v5; // edi

v1 = a1 * LINES;
v2 = (int)((unsigned __int64)(2155905153LL * v1) >> 32) >> 7;
v3 = (unsigned int)(v1 >> 31);
v4 = v2 - v3;
v5 = LINES / 2;
if ( LINES / 2 <= v4 )
{
v3 = 1LL;
if ( v5 < v4 )
{
LODWORD(v3) = LINES / -2 + v4 - 1;
v4 = v5 + 1;
}
}
else
{
LODWORD(v3) = v5 - v4;
}
return (v3 << 32) | (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 a1)
{
int v1; // eax
int v2; // ebx
__int64 v3; // rax
int v4; // ebx
int v5; // edi

v1 = a1 * LINES;
v2 = (int)((unsigned __int64)(2155905153LL * v1) >> 32) >> 7;
v3 = (unsigned int)(v1 >> 31);
v4 = v2 - v3;
v5 = LINES / 2;
if ( LINES / 2 <= v4 )
{
v3 = 1LL;
if ( v5 < v4 )
{
LODWORD(v3) = LINES / -2 + v4 - 1;
v4 = v5 + 1;
}
}
else
{
LODWORD(v3) = v5 - v4;
}
return (v3 << 32) | (unsigned int)v4;
}

original_code:
static wave_pos map(unsigned char c){
 wave_pos p;
 int peak;
 peak = (c * LINES)/255;
 if (peak < LINES/2){
  p.y = peak;
  p.height = LINES/2 - peak;
 } else if (peak > LINES/2){
  p.y = LINES/2+1;
  p.height = peak - LINES/2-1;
 } else {
  p.y = peak;
  p.height = 1;
 }
 return p;
}

canonical_original_code:
static struct wave_pos map(unsigned char c){
 struct wave_pos p;
 int peak;
 peak = (c * LINES)/255;
 if (peak < LINES/2){
  p.y = peak;
  p.height = LINES/2 - peak;
 } else if (peak > LINES/2){
  p.y = LINES/2+1;
  p.height = peak - LINES/2-1;
 } else {
  p.y = peak;
  p.height = 1;
 }
 return p;
}

variable_types:
c
unsigned char

variable_types:
p
struct wave_pos { int y; int height; }

variable_types: peak int

return_type: struct wave_pos { int y; int height; }


decompiled_code:
int nc_setup()
{
initscr();
noecho();
curs_set(0);
if ( has_colors() )
{
use_default_colors();
start_color();
init_pair(1, 1, -1);
init_pair(2, 4, 4);
}
if ( has_colors() )
wattr_on(stdscr, 0x100uLL, 0LL);
if ( wmove(stdscr, LINES / 2, 0) != -1 )
whline(stdscr, 0x2DuLL, COLS);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func1()
{
initscr();
noecho();
curs_set(0);
if ( has_colors() )
{
use_default_colors();
start_color();
init_pair(1, 1, -1);
init_pair(2, 4, 4);
}
if ( has_colors() )
wattr_on(stdscr, 0x100uLL, 0LL);
if ( wmove(stdscr, LINES / 2, 0) != -1 )
whline(stdscr, 0x2DuLL, COLS);
return wrefresh(stdscr);
}

original_code:
void nc_setup(void){
 initscr();
 noecho();
 curs_set(0);
 if (has_colors()){
  use_default_colors();
  start_color();
  init_pair(1,1,-1);
  init_pair(2,4,4);
 }
 if (has_colors()){
  wattr_on(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
 }
 (wmove((stdscr),((LINES/2)),((0))) == (-1) ? (-1) : whline((stdscr),(('-')),((COLS))));
 wrefresh(stdscr);
}


decompiled_code:
int nc_stop()
{
return endwin();
}

canonical_decompiled_code:
int func2()
{
return endwin();
}

original_code:
void nc_stop(void){
 endwin();
}

canonical_original_code:
void nc_stop(){
 endwin();
}


decompiled_code:
void __fastcall __noreturn nc_view(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
int v3; // rbp^4
__int64 v4; // r13

while ( 1 )
{
sem_wait(*(sem_t **)(a1 + 16));
wclear(stdscr);
if ( has_colors() )
wattr_on(stdscr, 0x100uLL, 0LL);
if ( wmove(stdscr, LINES / 2, 0) != -1 )
whline(stdscr, 0x2DuLL, COLS);
if ( has_colors() )
wattr_on(stdscr, 0x200uLL, 0LL);
if ( COLS > 0 )
{
v4 = *(_QWORD *)(a1 + 40) + *(int *)(a1 + 8);
v1 = 0LL;
do
{
if ( *(_DWORD *)(a1 + 12) <= (int)v1 )
break;
v2 = map(*(_BYTE *)(v4 + v1));
v3 = HIDWORD(v2);
if ( wmove(stdscr, v2, v1) != -1 )
wvline(stdscr, 0x7CuLL, v3);
++v1;
}
while ( COLS > (int)v1 );
}
wrefresh(stdscr);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func3(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rax
int v3; // rbp^4
__int64 v4; // r13

while ( 1 )
{
sem_wait(*(sem_t **)(a1 + 16));
wclear(stdscr);
if ( has_colors() )
wattr_on(stdscr, 0x100uLL, 0LL);
if ( wmove(stdscr, LINES / 2, 0) != -1 )
whline(stdscr, 0x2DuLL, COLS);
if ( has_colors() )
wattr_on(stdscr, 0x200uLL, 0LL);
if ( COLS > 0 )
{
v4 = *(_QWORD *)(a1 + 40) + *(int *)(a1 + 8);
v1 = 0LL;
do
{
if ( *(_DWORD *)(a1 + 12) <= (int)v1 )
break;
v2 = func0(*(_BYTE *)(v4 + v1));
v3 = HIDWORD(v2);
if ( wmove(stdscr, v2, v1) != -1 )
wvline(stdscr, 0x7CuLL, v3);
++v1;
}
while ( COLS > (int)v1 );
}
wrefresh(stdscr);
}
}

original_code:
void *nc_view(void *snd){
 sound *data = (sound *)snd;
 SAMPLE *packet;
 int i;
 wave_pos ln;
 while (1){
  sem_wait(data->drawer);
  wclear(stdscr);
  if (has_colors()){
   wattr_on(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  }
  (wmove((stdscr),((LINES/2)),((0))) == (-1) ? (-1) : whline((stdscr),(('-')),((COLS))));
  if (has_colors()){
   wattr_on(stdscr, (attr_t)(((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  }
  packet = &(data->recorded[data->pstart]);
  for (i=0; i<COLS && i<data->plen; i++){
   ln = map(*packet++);
   (wmove((stdscr),((ln.y)),((i))) == (-1) ? (-1) : wvline((stdscr),(('|')),((ln.height))));
  }
  wrefresh(stdscr);
 }
 return ((void *)0);
}

canonical_original_code:
void *nc_view(void *snd){
 struct sound *data = (sound *)snd;
 unsigned char *packet;
 int i;
 struct wave_pos ln;
 while (1){
  sem_wait(data->drawer);
  wclear(stdscr);
  if (has_colors()){
   wattr_on(stdscr, (attr_t)(((((chtype)(((1))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  }
  (wmove((stdscr),((LINES/2)),((0))) == (-1) ? (-1) : whline((stdscr),(('-')),((COLS))));
  if (has_colors()){
   wattr_on(stdscr, (attr_t)(((((chtype)(((2))) << ((0) + 8)) & ((chtype)((((1U) << 8) - 1U)) << ((0) + 8))))), ((void *)0));
  }
  packet = &(data->recorded[data->pstart]);
  for (i=0; i<COLS && i<data->plen; i++){
   ln = map(*packet++);
   (wmove((stdscr),((ln.y)),((i))) == (-1) ? (-1) : wvline((stdscr),(('|')),((ln.height))));
  }
  wrefresh(stdscr);
 }
 return ((void *)0);
}

variable_types:
packet
unsigned char *

variable_types: i int

variable_types:
ln
struct wave_pos { int y; int height; }

user_defined_types: union sem_t { char __size[32]; long __align; }


original_code:
static int get_audio(const void *inputBuffer, void *outputBuffer,
                         unsigned long framesPerBuffer,
                         const PaStreamCallbackTimeInfo* timeInfo,
                         PaStreamCallbackFlags statusFlags,
                         void *udata){
    sound *data = (sound*)udata;
    const SAMPLE *rptr = (const SAMPLE*)inputBuffer;
    SAMPLE *wptr;
    int fpb = (int) framesPerBuffer;
    long i;
    (void) outputBuffer;
    (void) timeInfo;
    (void) statusFlags;
    (void) udata;
    if ((data->frameIndex + fpb) > data->maxFrameIndex){
        data->frameIndex=0;
    }
    wptr = &(data->recorded[data->frameIndex]);
    if (inputBuffer == ((void *)0)){
        for (i=0; i<fpb; i++){
            *wptr++ = 128;
            if (1 == 2 ){
                *wptr++ = 128;
            }
        }
    } else {
        for (i=0; i<fpb; i++){
            *wptr++ = *rptr++;
            if (1 == 2){
                *wptr++ = *rptr++;
            }
        }
    }
    data->pstart = data->frameIndex;
    data->frameIndex += fpb;
    data->plen = fpb;
    sem_post(data->writer);
    sem_post(data->drawer);
    sem_post(data->detector);
    return paContinue;
}

canonical_original_code:
static int get_audio(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, struct PaStreamCallbackTimeInfo *timeInfo, unsigned long statusFlags, void *udata){
    struct sound *data = (sound*)udata;
    unsigned char *rptr = (const SAMPLE*)inputBuffer;
    unsigned char *wptr;
    int fpb = (int) framesPerBuffer;
    long i;
    (void) outputBuffer;
    (void) timeInfo;
    (void) statusFlags;
    (void) udata;
    if ((data->frameIndex + fpb) > data->maxFrameIndex){
        data->frameIndex=0;
    }
    wptr = &(data->recorded[data->frameIndex]);
    if (inputBuffer == ((void *)0)){
        for (i=0; i<fpb; i++){
            *wptr++ = 128;
            if (1 == 2 ){
                *wptr++ = 128;
            }
        }
    } else {
        for (i=0; i<fpb; i++){
            *wptr++ = *rptr++;
            if (1 == 2){
                *wptr++ = *rptr++;
            }
        }
    }
    data->pstart = data->frameIndex;
    data->frameIndex += fpb;
    data->plen = fpb;
    sem_post(data->writer);
    sem_post(data->drawer);
    sem_post(data->detector);
    return paContinue;
}

variable_types:
inputBuffer
void *

variable_types:
outputBuffer
void *

variable_types:
framesPerBuffer
unsigned long

variable_types: struct PaStreamCallbackTimeInfo { double inputBufferAdcTime; double currentTime; double outputBufferDacTime; } *

variable_types:
statusFlags
unsigned long

variable_types:
udata
void *

variable_types:
rptr
unsigned char *

variable_types:
wptr
unsigned char *

variable_types: fpb int

variable_types: i long