main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
const char *v8; // rdi
int v9; // edx
__int64 v10; // rax
__int64 v13; // rax
_BYTE *v14; // rax
__int64 v15; // rax
__uid_t v16; // er13
__uid_t v17; // er14
__gid_t v18; // er12
__gid_t v19; // er15
_DWORD *v20; // rbx
__int64 v21; // rax
int *v22; // rbx
int v23; // eax
int *v24; // rbx
int v25; // eax
_BYTE *v26; // [rsp+0h] [rbp-48h]
_BOOL4 v27; // [rsp+8h] [rbp-40h]
int v28; // [rsp+Ch] [rbp-3Ch]

v3 = argc;
v28 = 32;
v27 = 1;
v26 = &flagadr;
((void (__fastcall *)(int, const char **, const char **))init_sigval)(argc, argv, envp);
mypid = getpid();
mypgid = getpgid(mypid);
mysid = getsid(mypid);
if ( !stakbot )
addblok(0LL);
if ( *(_BYTE *)simple(*argv) == 45 )
{
signal(24, 0LL);
signal(25, 0LL);
login_shell = -1;
}
stdsigs();
setup_env();
setlocale(0, &byte_7B9);
v4 = findnam("SHELL");
if ( v4 )
{
v5 = simple(*(_QWORD *)(v4 + 24));
v27 = nullsub_1("rsh", v5) != 0;
}
if ( argc > 0 )
{
v6 = simple(*argv);
if ( !(unsigned int)nullsub_1("rsh", v6) || (v21 = simple(*argv), !(unsigned int)nullsub_1("-rsh", v21)) )
v28 = 0;
}
v7 = simple(*argv);
v8 = "jsh";
if ( !(unsigned int)nullsub_1("jsh", v7) || (v15 = simple(*argv), v8 = "-jsh", !(unsigned int)nullsub_1("-jsh", v15)) )
flags |= 0x40000uLL;
hcreate((size_t)v8);
set_dotpath();
dolc = options((unsigned int)v3, argv);
v9 = dolc;
if ( dolc <= 1 )
{
flags |= 0x400uLL;
v14 = &flagadr;
if ( flagadr )
{
do
++v14;
while ( *v14 );
}
*(_WORD *)v14 = 115;
v26 = v14 + 1;
}
if ( (*(&flags + 1) & 4) == 0 )
dolc = v9 - 1;
if ( (flags & 0x100000) == 0 )
{
v16 = geteuid();
v17 = getuid();
v18 = getegid();
v19 = getgid();
if ( v16 != v17 && v16 <= 0x63 )
setuid(v17);
if ( v18 != v19 && v18 <= 0x63 && v18 != 1 )
setgid(v19);
}
dolv = &argv[v3 - dolc];
--dolc;
if ( setjmp(subshell) )
{
freejobs(subshell);
flags |= 0x200uLL;
}
replace(&cmdadr, *dolv);
assnum(&pidadr, mypid);
settmp();
assign(&ifsnod, &sptbnl);
dfault(timeoutnod, "0");
timeoutnod[10] |= 8u;
dfault(mchknod, "600");
mailchk = stoi(mchknod[3]);
v10 = lookup("OPTIND");
assign(v10, "1");
getopt_sp = 1;
setwidth();
if ( !beenhere++ )
{
if ( login_shell == -1 && (*((_BYTE *)&flags + 2) & 0x10) == 0 )
{
v22 = (int *)standin;
v23 = pathopen(&nullstr, &sysprofile);
*v22 = v23;
if ( v23 >= 0 )
exfile(v28);
v24 = (int *)standin;
v25 = pathopen(homenod[3], &profile);
*v24 = v25;
if ( v25 >= 0 )
{
exfile(v28);
flags &= 0xFFFFFFFFFFFFFFDFLL;
}
}
if ( !v27 || !v28 )
{
v13 = flags;
if ( (*(&flags + 1) & 1) == 0 )
{
for ( ; *v26; ++v26 )
;
*(_WORD *)v26 = 114;
}
BYTE1(v13) |= 1u;
flags = v13;
}
if ( comdiv )
{
estabf();
*(_DWORD *)standin = -1;
}
else
{
v20 = standin;
if ( (*(&flags + 1) & 4) != 0 )
{
*(_DWORD *)standin = 0;
}
else
{
flags |= 0x200000uLL;
*v20 = chkopen(cmdadr, 0LL);
flags &= 0xFFFFFFFFFFDFFFFFLL;
if ( *(_DWORD *)standin )
preacct(cmdadr);
}
--comdiv;
}
}
exfile(0);
done(0LL);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
const char *v8; // rdi
int v9; // edx
__int64 v10; // rax
__int64 v13; // rax
_BYTE *v14; // rax
__int64 v15; // rax
__uid_t v16; // er13
__uid_t v17; // er14
__gid_t v18; // er12
__gid_t v19; // er15
_DWORD *v20; // rbx
__int64 v21; // rax
int *v22; // rbx
int v23; // eax
int *v24; // rbx
int v25; // eax
_BYTE *v26; // [rsp+0h] [rbp-48h]
_BOOL4 v27; // [rsp+8h] [rbp-40h]
int v28; // [rsp+Ch] [rbp-3Ch]

v3 = argc;
v28 = 32;
v27 = 1;
v26 = &flagadr;
((void (__fastcall *)(int, const char **, const char **))init_sigval)(argc, argv, envp);
mypid = getpid();
mypgid = getpgid(mypid);
mysid = getsid(mypid);
if ( !stakbot )
addblok(0LL);
if ( *(_BYTE *)simple(*argv) == 45 )
{
signal(24, 0LL);
signal(25, 0LL);
login_shell = -1;
}
stdsigs();
setup_env();
setlocale(0, &byte_7B9);
v4 = findnam("SHELL");
if ( v4 )
{
v5 = simple(*(_QWORD *)(v4 + 24));
v27 = nullsub_1("rsh", v5) != 0;
}
if ( argc > 0 )
{
v6 = simple(*argv);
if ( !(unsigned int)nullsub_1("rsh", v6) || (v21 = simple(*argv), !(unsigned int)nullsub_1("-rsh", v21)) )
v28 = 0;
}
v7 = simple(*argv);
v8 = "jsh";
if ( !(unsigned int)nullsub_1("jsh", v7) || (v15 = simple(*argv), v8 = "-jsh", !(unsigned int)nullsub_1("-jsh", v15)) )
flags |= 0x40000uLL;
hcreate((size_t)v8);
set_dotpath();
dolc = options((unsigned int)v3, argv);
v9 = dolc;
if ( dolc <= 1 )
{
flags |= 0x400uLL;
v14 = &flagadr;
if ( flagadr )
{
do
++v14;
while ( *v14 );
}
*(_WORD *)v14 = 115;
v26 = v14 + 1;
}
if ( (*(&flags + 1) & 4) == 0 )
dolc = v9 - 1;
if ( (flags & 0x100000) == 0 )
{
v16 = geteuid();
v17 = getuid();
v18 = getegid();
v19 = getgid();
if ( v16 != v17 && v16 <= 0x63 )
setuid(v17);
if ( v18 != v19 && v18 <= 0x63 && v18 != 1 )
setgid(v19);
}
dolv = &argv[v3 - dolc];
--dolc;
if ( setjmp(subshell) )
{
freejobs(subshell);
flags |= 0x200uLL;
}
replace(&cmdadr, *dolv);
assnum(&pidadr, mypid);
func1();
assign(&ifsnod, &sptbnl);
dfault(timeoutnod, "0");
timeoutnod[10] |= 8u;
dfault(mchknod, "600");
mailchk = stoi(mchknod[3]);
v10 = lookup("OPTIND");
assign(v10, "1");
getopt_sp = 1;
func5();
if ( !beenhere++ )
{
if ( login_shell == -1 && (*((_BYTE *)&flags + 2) & 0x10) == 0 )
{
v22 = (int *)standin;
v23 = pathopen(&nullstr, &sysprofile);
*v22 = v23;
if ( v23 >= 0 )
func7(v28);
v24 = (int *)standin;
v25 = pathopen(homenod[3], &profile);
*v24 = v25;
if ( v25 >= 0 )
{
func7(v28);
flags &= 0xFFFFFFFFFFFFFFDFLL;
}
}
if ( !v27 || !v28 )
{
v13 = flags;
if ( (*(&flags + 1) & 1) == 0 )
{
for ( ; *v26; ++v26 )
;
*(_WORD *)v26 = 114;
}
BYTE1(v13) |= 1u;
flags = v13;
}
if ( comdiv )
{
estabf();
*(_DWORD *)standin = -1;
}
else
{
v20 = standin;
if ( (*(&flags + 1) & 4) != 0 )
{
*(_DWORD *)standin = 0;
}
else
{
flags |= 0x200000uLL;
*v20 = chkopen(cmdadr, 0LL);
flags &= 0xFFFFFFFFFFDFFFFFLL;
if ( *(_DWORD *)standin )
preacct(cmdadr);
}
--comdiv;
}
}
func7(0);
done(0LL);
return 0;
}

original_code:
int
main(int c, char *v[], char *e[])
{
 int rflag = 040;
 int rsflag = 1;
 unsigned char *flagc = flagadr;
 struct namnod *n;
 (void) &rflag;
 (void) &rsflag;
 (void) &flagc;
 init_sigval();
 mypid = getpid();
 mypgid = getpgid(mypid);
 mysid = getsid(mypid);
 if (stakbot == 0) {
 addblok((unsigned)0);
 }
 if (*simple(v[0]) == '-') {
  signal(24, ((__sighandler_t) 0));
  signal(25, ((__sighandler_t) 0));
  login_shell = (-1);
 }
 stdsigs();
 setup_env();
 setlocale(0, "");
 if (n = findnam("SHELL"))
 {
  if ((cf("rsh", simple(n->namval)) == 0))
   rsflag = 0;
 }
 if (c > 0 && ((cf("rsh", simple(*v)) == 0) || (cf("-rsh", simple(*v)) == 0)))
  rflag = 0;
 if ((cf("jsh", simple(*v)) == 0) || (cf("-jsh", simple(*v)) == 0))
  flags |= 01000000;
 hcreate();
 set_dotpath();
 dolc = options(c, (unsigned char **)v);
 if (dolc < 2)
 {
  flags |= 02000;
  {
   while (*flagc)
    flagc++;
   *flagc++ = 's';
   *flagc = 0;
  }
 }
 if ((flags & 02000) == 0)
  dolc--;
 if ((flags & 04000000) == 0) {
  register uid_t euid;
  register gid_t egid;
  register uid_t ruid;
  register gid_t rgid;
  euid = geteuid();
  ruid = getuid();
  egid = getegid();
  rgid = getgid();
  if ((euid != ruid) && (euid < 100))
   setuid(ruid);
  if ((egid != rgid) && ((egid < 100) && (egid != 1)))
   setgid(rgid);
 }
 dolv = (unsigned char **)v + c - dolc;
 dolc--;
 if (_setjmp (subshell)) {
  freejobs();
  flags |= 01000;
 }
 replace(&cmdadr, dolv[0]);
 assnum(&pidadr, (long)mypid);
 settmp();
 assign(&ifsnod, sptbnl);
 dfault(&timeoutnod, "0");
 timeoutnod.namflg |= 0010;
 dfault(&mchknod, "600");
 mailchk = stoi(mchknod.namval);
 n = lookup("OPTIND");
 assign(n, "1");
 getopt_sp = 1;
 setwidth();
 if ((beenhere++) == 0)
 {
  if ((login_shell == (-1)) && (flags & 04000000) == 0) {
   if (((standin->fdes) = pathopen(nullstr, sysprofile)) >= 0)
    exfile(rflag);
   if (((standin->fdes) = pathopen(homenod.namval, profile)) >= 0)
   {
    exfile(rflag);
    flags &= ~040;
   }
  }
  if (rsflag == 0 || rflag == 0) {
   if ((flags & 0400) == 0) {
    while (*flagc)
     flagc++;
    *flagc++ = 'r';
    *flagc = '\0';
   }
   flags |= 0400;
  }
  if (comdiv)
  {
   estabf(comdiv);
   (standin->fdes) = -1;
  }
  else
  {
   if (flags & 02000) {
    (standin->fdes) = 0;
   } else {
    flags |= 010000000;
    (standin->fdes) = chkopen(cmdadr, 0);
    flags &= ~010000000;
   }
   if ((standin->fdes) != 0)
    preacct(cmdadr);
   comdiv--;
  }
 }
 exfile(0);
 done(0);
 return 0;
}

canonical_original_code:
int main(int c, char *v[], char *e[])
{
 int rflag = 040;
 int rsflag = 1;
 unsigned char *flagc = flagadr;
 struct namnod *n;
 (void) &rflag;
 (void) &rsflag;
 (void) &flagc;
 init_sigval();
 mypid = getpid();
 mypgid = getpgid(mypid);
 mysid = getsid(mypid);
 if (stakbot == 0) {
 addblok((unsigned int)0);
 }
 if (*simple(v[0]) == '-') {
  signal(24, ((void (*)(int)) 0));
  signal(25, ((void (*)(int)) 0));
  login_shell = (-1);
 }
 stdsigs();
 setup_env();
 setlocale(0, "");
 if (n = findnam("SHELL"))
 {
  if ((cf("rsh", simple(n->namval)) == 0))
   rsflag = 0;
 }
 if (c > 0 && ((cf("rsh", simple(*v)) == 0) || (cf("-rsh", simple(*v)) == 0)))
  rflag = 0;
 if ((cf("jsh", simple(*v)) == 0) || (cf("-jsh", simple(*v)) == 0))
  flags |= 01000000;
 hcreate();
 set_dotpath();
 dolc = options(c, (unsigned char **)v);
 if (dolc < 2)
 {
  flags |= 02000;
  {
   while (*flagc)
    flagc++;
   *flagc++ = 's';
   *flagc = 0;
  }
 }
 if ((flags & 02000) == 0)
  dolc--;
 if ((flags & 04000000) == 0) {
  register unsigned int euid;
  register unsigned int egid;
  register unsigned int ruid;
  register unsigned int rgid;
  euid = geteuid();
  ruid = getuid();
  egid = getegid();
  rgid = getgid();
  if ((euid != ruid) && (euid < 100))
   setuid(ruid);
  if ((egid != rgid) && ((egid < 100) && (egid != 1)))
   setgid(rgid);
 }
 dolv = (unsigned char **)v + c - dolc;
 dolc--;
 if (_setjmp (subshell)) {
  freejobs();
  flags |= 01000;
 }
 replace(&cmdadr, dolv[0]);
 assnum(&pidadr, (long)mypid);
 settmp();
 assign(&ifsnod, sptbnl);
 dfault(&timeoutnod, "0");
 timeoutnod.namflg |= 0010;
 dfault(&mchknod, "600");
 mailchk = stoi(mchknod.namval);
 n = lookup("OPTIND");
 assign(n, "1");
 getopt_sp = 1;
 setwidth();
 if ((beenhere++) == 0)
 {
  if ((login_shell == (-1)) && (flags & 04000000) == 0) {
   if (((standin->fdes) = pathopen(nullstr, sysprofile)) >= 0)
    exfile(rflag);
   if (((standin->fdes) = pathopen(homenod.namval, profile)) >= 0)
   {
    exfile(rflag);
    flags &= ~040;
   }
  }
  if (rsflag == 0 || rflag == 0) {
   if ((flags & 0400) == 0) {
    while (*flagc)
     flagc++;
    *flagc++ = 'r';
    *flagc = '\0';
   }
   flags |= 0400;
  }
  if (comdiv)
  {
   estabf(comdiv);
   (standin->fdes) = -1;
  }
  else
  {
   if (flags & 02000) {
    (standin->fdes) = 0;
   } else {
    flags |= 010000000;
    (standin->fdes) = chkopen(cmdadr, 0);
    flags &= ~010000000;
   }
   if ((standin->fdes) != 0)
    preacct(cmdadr);
   comdiv--;
  }
 }
 exfile(0);
 done(0);
 return 0;
}

variable_types: c int

variable_types:
v
char *[]

variable_types:
e
char *[]

variable_types: rflag int

variable_types: rsflag int

variable_types:
flagc
unsigned char *

variable_types: struct namnod { struct namnod *namlft; struct namnod *namrgt; unsigned char *namid; unsigned char *namval; unsigned char *namenv; int namflg; } *

variable_types:
euid
unsigned int

variable_types:
egid
unsigned int

variable_types:
ruid
unsigned int

variable_types:
rgid
unsigned int


prs

repo: mutoso-mirrors/heirloom-sh

decompiled_code:
void __fastcall prs(void *buf)
{
int v1; // eax

if ( buf )
{
v1 = length();
write(output, buf, v1 - 1);
}
}

canonical_decompiled_code:
void __fastcall func0(void *buf)
{
int v1; // eax

if ( buf )
{
v1 = length();
write(output, buf, v1 - 1);
}
}

original_code:
void
prs(const unsigned char *as)
{
 const char *s;
 if ((s = (char *)as) != 0) {
  write(output, s, length(s) - 1);
 }
}

canonical_original_code:
void prs(unsigned char *as)
{
 char *s;
 if ((s = (char *)as) != 0) {
  write(output, s, length(s) - 1);
 }
}

variable_types:
as
unsigned char *

variable_types:
s
char *

return_type: void


prc

decompiled_code:
ssize_t __fastcall prc(char a1)
{
ssize_t result; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 )
result = write(output, buf, 1uLL);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(char a1)
{
ssize_t result; // rax
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 )
result = write(output, buf, 1uLL);
return result;
}

original_code:
void
prc(unsigned char c)
{
 if (c) {
  write(output, &c, 1);
 }
}

variable_types:
c
unsigned char


prwc

decompiled_code:
void __fastcall prwc(wchar_t wchar)
{
size_t v1; // rdx
int v2; // eax
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

if ( wchar )
{
if ( mb_cur_max <= 1 || (wchar & 0xFFFFFF80) == 0 || (v2 = wctomb(v3, wchar), v1 = v2, v2 < 0) )
{
v3[0] = wchar;
v1 = 1LL;
}
write(output, v3, v1);
}
}

canonical_decompiled_code:
void __fastcall func2(wchar_t wchar)
{
size_t v1; // rdx
int v2; // eax
char v3[56]; // [rsp+0h] [rbp-38h] BYREF

if ( wchar )
{
if ( mb_cur_max <= 1 || (wchar & 0xFFFFFF80) == 0 || (v2 = wctomb(v3, wchar), v1 = v2, v2 < 0) )
{
v3[0] = wchar;
v1 = 1LL;
}
write(output, v3, v1);
}
}

original_code:
void
prwc(wchar_t c)
{
 char mb[16 + 1];
 int len;
 if (c == 0) {
  return;
 }
 if ((len = (mb_cur_max > 1 && c & ~(wchar_t)0177 ? wctomb(mb, c) : (*(mb) = c, 1))) < 0) {
  mb[0] = (unsigned char)c;
  len = 1;
 }
 write(output, mb, len);
}

canonical_original_code:
void prwc(int c)
{
 char mb[-1];
 int len;
 if (c == 0) {
  return;
 }
 if ((len = (mb_cur_max > 1 && c & ~(int)0177 ? wctomb(mb, c) : (*(mb) = c, 1))) < 0) {
  mb[0] = (unsigned char)c;
  len = 1;
 }
 write(output, mb, len);
}

variable_types:
mb
char [-1]

variable_types: len int


itos

decompiled_code:
char *__fastcall itos(int a1)
{
char *v1; // rsi
char v2; // al
char v4; // [rsp+13h] [rbp-15h] BYREF

v4 = 0;
v1 = &v4;
do
{
--v1;
v2 = a1 + 48;
a1 /= 10;
*v1 = v2 - 10 * a1;
}
while ( a1 );
return strncpy(&numbuf, v1, 0x15uLL);
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
char *v1; // rsi
char v2; // al
char v4; // [rsp+13h] [rbp-15h] BYREF

v4 = 0;
v1 = &v4;
do
{
--v1;
v2 = a1 + 48;
a1 /= 10;
*v1 = v2 - 10 * a1;
}
while ( a1 );
return strncpy(&numbuf, v1, 0x15uLL);
}

original_code:
void
itos(int n)
{
 unsigned char buf[21];
 unsigned char *abuf = &buf[20];
 int d;
 *--abuf = (unsigned char)'\0';
 do {
   *--abuf = (unsigned char)('0' + n - 10 * (d = n / 10));
 } while ((n = d) != 0);
 strncpy(numbuf, abuf, sizeof (numbuf));
}

variable_types: n int

variable_types:
buf
unsigned char [21]

variable_types:
abuf
unsigned char *

variable_types: d int


prn

decompiled_code:
void __fastcall prn(int a1)
{
itos(a1);
prs(&numbuf);
}

canonical_decompiled_code:
void __fastcall func4(int a1)
{
func3(a1);
func0(&numbuf);
}

original_code:
void
prn(int n)
{
 itos(n);
 prs(numbuf);
}


stoi

decompiled_code:
__int64 __fastcall stoi(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
unsigned __int8 *v2; // rdx
int v3; // er12

v1 = *a1;
v2 = a1;
v3 = 0;
if ( (*a1 & 0x80u) == 0 )
{
do
{
if ( (*((_BYTE *)&sh_ctype2 + v1) & 8) == 0 || !v1 )
break;
if ( v3 < 0 )
goto LABEL_10;
++v2;
v3 = v1 + 10 * v3 - 48;
v1 = *v2;
}
while ( (*v2 & 0x80u) == 0 );
if ( v3 >= 0 && a1 != v2 )
return (unsigned int)v3;
}
LABEL_10:
failed(a1, &badnum, v2);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
unsigned __int8 *v2; // rdx
int v3; // er12

v1 = *a1;
v2 = a1;
v3 = 0;
if ( (*a1 & 0x80u) == 0 )
{
do
{
if ( (*((_BYTE *)&sh_ctype2 + v1) & 8) == 0 || !v1 )
break;
if ( v3 < 0 )
goto LABEL_10;
++v2;
v3 = v1 + 10 * v3 - 48;
v1 = *v2;
}
while ( (*v2 & 0x80u) == 0 );
if ( v3 >= 0 && a1 != v2 )
return (unsigned int)v3;
}
LABEL_10:
failed(a1, &badnum, v2);
return (unsigned int)v3;
}

original_code:
int
stoi(const unsigned char *icp)
{
 const unsigned char *cp = icp;
 int r = 0;
 unsigned char c;
 while ((c = *cp, ((c<0200) && sh_ctype2[c]&(010))) && c && r >= 0) {
  r = r * 10 + c - '0';
  cp++;
 }
 if (r < 0 || cp == icp)
  failed(icp, badnum);
 return (r);
}

canonical_original_code:
int stoi(unsigned char *icp)
{
 unsigned char *cp = icp;
 int r = 0;
 unsigned char c;
 while ((c = *cp, ((c<0200) && sh_ctype2[c]&(010))) && c && r >= 0) {
  r = r * 10 + c - '0';
  cp++;
 }
 if (r < 0 || cp == icp)
  failed(icp, badnum);
 return (r);
}

variable_types:
icp
unsigned char *

variable_types:
cp
unsigned char *

variable_types: r int

return_type: int


stoifll

original_code:
long long
stoifll(const unsigned char *icp)
{
 const unsigned char *cp;
 long long r = 0;
 int sign = 1;
 unsigned char c;
 for (cp = icp; ((*cp<0200) && sh_ctype1[*cp]&(04)); cp++);
 if (*cp == '-') {
  sign = -1;
  cp++;
 } else if (*cp == '+')
  cp++;
 while ((c = *cp, ((c<0200) && sh_ctype2[c]&(010))) && c) {
  r = r * 10 + c - '0';
  cp++;
 }
 return (r * sign);
}

canonical_original_code:
long long stoifll(unsigned char *icp)
{
 unsigned char *cp;
 long long r = 0;
 int sign = 1;
 unsigned char c;
 for (cp = icp; ((*cp<0200) && sh_ctype1[*cp]&(04)); cp++);
 if (*cp == '-') {
  sign = -1;
  cp++;
 } else if (*cp == '+')
  cp++;
 while ((c = *cp, ((c<0200) && sh_ctype2[c]&(010))) && c) {
  r = r * 10 + c - '0';
  cp++;
 }
 return (r * sign);
}

variable_types:
r
long long

variable_types: sign int

return_type: long long


ltos

decompiled_code:
__int64 __fastcall ltos(__int64 a1)
{
__int64 v1; // rcx

numbuf[20] = 0;
v1 = 19LL;
do
{
numbuf[v1] = a1 % 10 + 48;
a1 /= 10LL;
if ( !a1 )
return (unsigned int)v1;
}
while ( v1-- != 0 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rcx

numbuf[20] = 0;
v1 = 19LL;
do
{
numbuf[v1] = a1 % 10 + 48;
a1 /= 10LL;
if ( !a1 )
return (unsigned int)v1;
}
while ( v1-- != 0 );
return 0xFFFFFFFFLL;
}

variable_types: n long

variable_types: i int


ulltos

decompiled_code:
__int64 __fastcall ulltos(unsigned __int64 a1)
{
__int64 v1; // rcx
unsigned __int64 v3; // rax

numbuf[20] = 0;
v1 = 19LL;
do
{
numbuf[v1] = a1 % 0xA + 48;
v3 = a1;
a1 /= 0xAuLL;
if ( v3 <= 9 )
return (unsigned int)v1;
}
while ( v1-- != 0 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 a1)
{
__int64 v1; // rcx
unsigned __int64 v3; // rax

numbuf[20] = 0;
v1 = 19LL;
do
{
numbuf[v1] = a1 % 0xA + 48;
v3 = a1;
a1 /= 0xAuLL;
if ( v3 <= 9 )
return (unsigned int)v1;
}
while ( v1-- != 0 );
return 0xFFFFFFFFLL;
}

original_code:
int
ulltos(unsigned long long n)
{
 int i;
 numbuf[20] = '\0';
 for (i = 19; i >= 0; i--) {
  numbuf[i] = n % 10 + '0';
  if ((n /= 10) == 0) {
   break;
  }
 }
 return (i);
}

variable_types:
n
unsigned long long


flushb

decompiled_code:
ssize_t flushb()
{
ssize_t result; // rax
int v1; // eax

result = sh_index;
if ( sh_index )
{
*((_BYTE *)bufp + sh_index) = 0;
v1 = length();
result = write(buffd, bufp, v1 - 1);
sh_index = 0;
}
return result;
}

canonical_decompiled_code:
ssize_t func9()
{
ssize_t result; // rax
int v1; // eax

result = sh_index;
if ( sh_index )
{
*((_BYTE *)bufp + sh_index) = 0;
v1 = length();
result = write(buffd, bufp, v1 - 1);
sh_index = 0;
}
return result;
}

original_code:
void
flushb(void)
{
 if (sh_index) {
  bufp[sh_index] = '\0';
  write(buffd, bufp, length(bufp) - 1);
  sh_index = 0;
 }
}

canonical_original_code:
void flushb()
{
 if (sh_index) {
  bufp[sh_index] = '\0';
  write(buffd, bufp, length(bufp) - 1);
  sh_index = 0;
 }
}


decompiled_code:
ssize_t __fastcall prc_buff(char a1)
{
ssize_t result; // rax
char v2; // dl
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 )
{
result = sh_index;
v2 = a1;
if ( buffd != -1 && sh_index > 254 )
{
flushb();
result = sh_index;
v2 = buf[0];
}
sh_index = result + 1;
*((_BYTE *)bufp + result) = v2;
}
else
{
flushb();
result = write(buffd, buf, 1uLL);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func10(char a1)
{
ssize_t result; // rax
char v2; // dl
char buf[12]; // [rsp+Ch] [rbp-Ch] BYREF

buf[0] = a1;
if ( a1 )
{
result = sh_index;
v2 = a1;
if ( buffd != -1 && sh_index > 254 )
{
func9();
result = sh_index;
v2 = buf[0];
}
sh_index = result + 1;
*((_BYTE *)bufp + result) = v2;
}
else
{
func9();
result = write(buffd, buf, 1uLL);
}
return result;
}

original_code:
void
prc_buff(unsigned char c)
{
 if (c) {
  if (buffd != -1 && sh_index + 1 >= 256) {
   flushb();
  }
  bufp[sh_index++] = c;
 } else {
  flushb();
  write(buffd, &c, 1);
 }
}


decompiled_code:
ssize_t __fastcall prs_buff(void *buf)
{
int v2; // eax
int v3; // edi
int v4; // ebx
ssize_t result; // rax

v2 = length();
v3 = buffd;
v4 = v2 - 1;
if ( buffd == -1 )
goto LABEL_6;
if ( v4 + sh_index > 255 )
{
flushb();
v3 = buffd;
if ( buffd == -1 )
goto LABEL_6;
}
else if ( buffd == -1 )
{
goto LABEL_6;
}
if ( v4 > 255 )
return write(v3, buf, v4);
LABEL_6:
result = movstr(buf, (char *)bufp + sh_index);
sh_index += v4;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func11(void *buf)
{
int v2; // eax
int v3; // edi
int v4; // ebx
ssize_t result; // rax

v2 = length();
v3 = buffd;
v4 = v2 - 1;
if ( buffd == -1 )
goto LABEL_6;
if ( v4 + sh_index > 255 )
{
func9();
v3 = buffd;
if ( buffd == -1 )
goto LABEL_6;
}
else if ( buffd == -1 )
{
goto LABEL_6;
}
if ( v4 > 255 )
return write(v3, buf, v4);
LABEL_6:
result = movstr(buf, (char *)bufp + sh_index);
sh_index += v4;
return result;
}

original_code:
void
prs_buff(const unsigned char *s)
{
 int len = length((const char *)s) - 1;
 if (buffd != -1 && sh_index + len >= 256) {
  flushb();
 }
 if (buffd != -1 && len >= 256) {
  write(buffd, (const char *)s, len);
 } else {
  movstr((const char *)s, &bufp[sh_index]);
  sh_index += len;
 }
}

canonical_original_code:
void prs_buff(unsigned char *s)
{
 int len = length((const char *)s) - 1;
 if (buffd != -1 && sh_index + len >= 256) {
  flushb();
 }
 if (buffd != -1 && len >= 256) {
  write(buffd, (char *)s, len);
 } else {
  movstr((char *)s, &bufp[sh_index]);
  sh_index += len;
 }
}

variable_types:
s
unsigned char *


prl

decompiled_code:
ssize_t __fastcall prl(__int64 a1)
{
int v1; // eax

v1 = ltos(a1);
return prs_buff(&numbuf[v1]);
}

canonical_decompiled_code:
ssize_t __fastcall func12(__int64 a1)
{
int v1; // eax

v1 = func7(a1);
return func11(&numbuf[v1]);
}

original_code:
void
prl(long n)
{
 int i;
 i = ltos(n);
 prs_buff(&numbuf[i]);
}


prull

decompiled_code:
ssize_t __fastcall prull(unsigned __int64 a1)
{
int v1; // eax

v1 = ulltos(a1);
return prs_buff(&numbuf[v1]);
}

canonical_decompiled_code:
ssize_t __fastcall func13(unsigned __int64 a1)
{
int v1; // eax

v1 = func8(a1);
return func11(&numbuf[v1]);
}

original_code:
void
prull(unsigned long long n)
{
 int i;
 i = ulltos(n);
 prs_buff(&numbuf[i]);
}


original_code:
void
prs_cntl(const unsigned char *s)
{
 int n;
 wchar_t wc;
 const unsigned char *olds = s;
 unsigned char *ptr = bufp;
 wchar_t c;
 if ((n = (mb_cur_max > 1 && *((const char *)s) & 0200 ? mbtowc(&wc, (const char *)s, mb_cur_max) : (*(&wc) = *((const char *)s) & 0377, *(&wc) != 0))) <= 0) {
  n = 0;
 }
 while (n != 0) {
  if (n < 0) {
   ptr = octal(*s++, ptr);
  } else {
   c = wc;
   s += n;
   if (!(mb_cur_max > 1 ? iswprint(c) : ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISprint))) {
    if (c < '\040' && c > 0) {
     *ptr++ = '^';
     *ptr++ = (c + 0100);
    } else if (c == 0177) {
     *ptr++ = '^';
     *ptr++ = '?';
    } else {
     ptr = octal(*olds, ptr);
    }
   } else {
    while (n--) {
     *ptr++ = *olds++;
    }
   }
  }
  if (buffd != -1 && ptr >= &bufp[256 -4]) {
   *ptr = '\0';
   prs(bufp);
   ptr = bufp;
  }
  olds = s;
  if ((n = (mb_cur_max > 1 && *((const char *)s) & 0200 ? mbtowc(&wc, (const char *)s, mb_cur_max) : (*(&wc) = *((const char *)s) & 0377, *(&wc) != 0))) <= 0) {
   n = 0;
  }
 }
 *ptr = '\0';
 prs(bufp);
}

canonical_original_code:
void prs_cntl(unsigned char *s)
{
 int n;
 int wc;
 unsigned char *olds = s;
 unsigned char *ptr = bufp;
 int c;
 if ((n = (mb_cur_max > 1 && *((char *)s) & 0200 ? mbtowc(&wc, (char *)s, mb_cur_max) : (*(&wc) = *((char *)s) & 0377, *(&wc) != 0))) <= 0) {
  n = 0;
 }
 while (n != 0) {
  if (n < 0) {
   ptr = octal(*s++, ptr);
  } else {
   c = wc;
   s += n;
   if (!(mb_cur_max > 1 ? iswprint(c) : ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISprint))) {
    if (c < '\040' && c > 0) {
     *ptr++ = '^';
     *ptr++ = (c + 0100);
    } else if (c == 0177) {
     *ptr++ = '^';
     *ptr++ = '?';
    } else {
     ptr = octal(*olds, ptr);
    }
   } else {
    while (n--) {
     *ptr++ = *olds++;
    }
   }
  }
  if (buffd != -1 && ptr >= &bufp[256 -4]) {
   *ptr = '\0';
   prs(bufp);
   ptr = bufp;
  }
  olds = s;
  if ((n = (mb_cur_max > 1 && *((char *)s) & 0200 ? mbtowc(&wc, (char *)s, mb_cur_max) : (*(&wc) = *((char *)s) & 0377, *(&wc) != 0))) <= 0) {
   n = 0;
  }
 }
 *ptr = '\0';
 prs(bufp);
}

variable_types: wc int

variable_types:
olds
unsigned char *

variable_types:
ptr
unsigned char *

variable_types: c int


prp

decompiled_code:
void prp()
{
if ( (flags & 4) == 0 )
{
if ( cmdadr )
{
prs_cntl(cmdadr);
prs(&colon);
}
}
}

canonical_decompiled_code:
void func15()
{
if ( (flags & 4) == 0 )
{
if ( cmdadr )
{
func14(cmdadr);
func0(&colon);
}
}
}

original_code:
void
prp(void)
{
 if ((flags & 04) == 0 && cmdadr) {
  prs_cntl(cmdadr);
  prs((unsigned char *)colon);
 }
}

canonical_original_code:
void prp()
{
 if ((flags & 04) == 0 && cmdadr) {
  prs_cntl(cmdadr);
  prs((unsigned char *)colon);
 }
}


decompiled_code:
// attributes: thunk
ssize_t __fastcall prl_buff(__int64 a1)
{
return prl(a1);
}

canonical_decompiled_code:
ssize_t __fastcall func16(__int64 a1)
{
return func12(a1);
}

original_code:
void
prl_buff(long lc)
{
 prs_buff(&numbuf[ltos(lc)]);
}

variable_types: lc long


decompiled_code:
// attributes: thunk
ssize_t __fastcall prull_buff(unsigned __int64 a1)
{
return prull(a1);
}

canonical_decompiled_code:
ssize_t __fastcall func17(unsigned __int64 a1)
{
return func13(a1);
}

original_code:
void
prull_buff(unsigned long long lc)
{
 prs_buff(&numbuf[ulltos(lc)]);
}

variable_types:
lc
unsigned long long


decompiled_code:
ssize_t __fastcall prn_buff(int a1)
{
itos(a1);
return prs_buff(numbuf);
}

canonical_decompiled_code:
ssize_t __fastcall func18(int a1)
{
func3(a1);
return func11(numbuf);
}

original_code:
void
prn_buff(int n)
{
 itos(n);
 prs_buff(numbuf);
}

variable_types: n int


prt

decompiled_code:
ssize_t __fastcall prt(__int64 a1)
{
__int64 v1; // rcx
__int64 v2; // rbx
__int64 v3; // rcx
__int64 v4; // rbx
__int64 v5; // rbp

v1 = clk_tck_0;
if ( !clk_tck_0 )
{
clk_tck_0 = sysconf(2);
v1 = clk_tck_0;
}
v2 = (v1 / 2 + a1) / v1;
v3 = v2 / 60;
v4 = v2 % 60;
v5 = v3 % 60;
if ( (unsigned int)(v3 / 60) )
{
prn_buff(v3 / 60);
prc_buff(104);
}
prn_buff(v5);
prc_buff(109);
prn_buff(v4);
return prc_buff(115);
}

original_code:
void
prt(long t)
{
 int hr, min, sec;
 static long clk_tck;
 if (clk_tck == 0)
  clk_tck = sysconf(_SC_CLK_TCK);
 t += clk_tck / 2;
 t /= clk_tck;
 sec = t % 60;
 t /= 60;
 min = t % 60;
 if ((hr = t / 60) != 0) {
  prn_buff(hr);
  prc_buff('h');
 }
 prn_buff(min);
 prc_buff('m');
 prn_buff(sec);
 prc_buff('s');
}

canonical_original_code:
void prt(long t)
{
 int hr; int min; int sec;
 static long clk_tck;
 if (clk_tck == 0)
  clk_tck = sysconf(_SC_CLK_TCK);
 t += clk_tck / 2;
 t /= clk_tck;
 sec = t % 60;
 t /= 60;
 min = t % 60;
 if ((hr = t / 60) != 0) {
  prn_buff(hr);
  prc_buff('h');
 }
 prn_buff(min);
 prc_buff('m');
 prn_buff(sec);
 prc_buff('s');
}

variable_types: t long

variable_types: hr int

variable_types: min int

variable_types: sec int


decompiled_code:
ssize_t __fastcall prsp_buff(int a1)
{
int v1; // ebx
ssize_t result; // rax

if ( a1 )
{
v1 = a1;
do
{
result = prc_buff(32);
--v1;
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func20(int a1)
{
int v1; // ebx
ssize_t result; // rax

if ( a1 )
{
v1 = a1;
do
{
result = func10(32);
--v1;
}
while ( v1 );
}
return result;
}

original_code:
void
prsp_buff(int cnt)
{
 while (cnt--) {
  prc_buff(' ');
 }
}

variable_types: cnt int


setb

decompiled_code:
__int64 __fastcall setb(int a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // rax
_BYTE *v5; // rdi
__int64 v6; // rdx

v3 = buffd;
if ( buffd != -1 )
{
flushb();
buffd = a1;
if ( a1 != -1 )
goto LABEL_5;
LABEL_9:
bufp = (void *)locstak();
goto LABEL_6;
}
v4 = sh_index;
v5 = bufp;
v6 = sh_index;
if ( (unsigned __int64)bufp + sh_index + 1 < brkend )
{
if ( !*((char *)bufp + sh_index - 1) )
goto LABEL_4;
goto LABEL_7;
}
growstak((char *)bufp + sh_index + 1, a2, sh_index);
v4 = sh_index;
v5 = bufp;
v6 = sh_index;
if ( *((char *)bufp + sh_index - 1) )
{
LABEL_7:
v6 = (unsigned int)(v6 + 1);
v5[v4] = 0;
sh_index = v6;
v4 = (int)v6;
}
LABEL_4:
endstak(&v5[v4], a2, v6);
buffd = a1;
if ( a1 == -1 )
goto LABEL_9;
LABEL_5:
bufp = &buffer;
LABEL_6:
sh_index = 0;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1, __int64 a2)
{
unsigned int v3; // er12
__int64 v4; // rax
_BYTE *v5; // rdi
__int64 v6; // rdx

v3 = buffd;
if ( buffd != -1 )
{
func9();
buffd = a1;
if ( a1 != -1 )
goto LABEL_5;
LABEL_9:
bufp = (void *)locstak();
goto LABEL_6;
}
v4 = sh_index;
v5 = bufp;
v6 = sh_index;
if ( (unsigned __int64)bufp + sh_index + 1 < brkend )
{
if ( !*((char *)bufp + sh_index - 1) )
goto LABEL_4;
goto LABEL_7;
}
growstak((char *)bufp + sh_index + 1, a2, sh_index);
v4 = sh_index;
v5 = bufp;
v6 = sh_index;
if ( *((char *)bufp + sh_index - 1) )
{
LABEL_7:
v6 = (unsigned int)(v6 + 1);
v5[v4] = 0;
sh_index = v6;
v4 = (int)v6;
}
LABEL_4:
endstak(&v5[v4], a2, v6);
buffd = a1;
if ( a1 == -1 )
goto LABEL_9;
LABEL_5:
bufp = &buffer;
LABEL_6:
sh_index = 0;
return v3;
}

original_code:
int
setb(int fd)
{
 int ofd;
 if ((ofd = buffd) == -1) {
  if (bufp+sh_index+1 >= brkend) {
   growstak(bufp+sh_index+1);
  }
  if (bufp[sh_index-1]) {
   bufp[sh_index++] = 0;
  }
  endstak(bufp+sh_index);
 } else {
  flushb();
 }
 if ((buffd = fd) == -1) {
  bufp = locstak();
 } else {
  bufp = buffer;
 }
 sh_index = 0;
 return (ofd);
}

variable_types: fd int

variable_types: ofd int


ignoring

decompiled_code:
__int64 __fastcall ignoring(int a1)
{
__int64 result; // rax
__int16 v2; // bx
struct sigaction v3; // [rsp+0h] [rbp-B8h] BYREF

result = 1LL;
v2 = trapflg[a1];
if ( (v2 & 0x10) == 0 )
{
sigaction(a1, 0LL, &v3);
result = 0LL;
if ( v3.sa_handler == (__sighandler_t)&loc_1 )
{
result = 1LL;
trapflg[a1] = v2 | 0x10;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
__int16 v2; // bx
struct sigaction v3; // [rsp+0h] [rbp-B8h] BYREF

result = 1LL;
v2 = trapflg[a1];
if ( (v2 & 0x10) == 0 )
{
sigaction(a1, 0LL, &v3);
result = 0LL;
if ( v3.sa_handler == (__sighandler_t)&loc_1 )
{
result = 1LL;
trapflg[a1] = v2 | 0x10;
}
}
return result;
}

original_code:
static int
ignoring(register int i)
{
 struct sigaction act;
 if (trapflg[i] & 16)
  return (1);
 sigaction(i, 0, &act);
 if (act.__sigaction_handler.sa_handler == ((__sighandler_t) 1)) {
  trapflg[i] |= 16;
  return (1);
 }
 return (0);
}

canonical_original_code:
static int ignoring(int i)
{
 struct sigaction act;
 if (trapflg[i] & 16)
  return (1);
 sigaction(i, 0, &act);
 if (act.__sigaction_handler.sa_handler == ((void (*)(int)) 1)) {
  trapflg[i] |= 16;
  return (1);
 }
 return (0);
}

variable_types: i int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


handle

decompiled_code:
__int64 __fastcall handle(int sig, void (*a2)(int))
{
bool v2; // zf
__int64 result; // rax
__int16 v4; // dx
struct sigaction v5; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-B8h] BYREF

if ( a2 != (void (*)(int))&loc_1 )
{
if ( (unsigned int)(sig - 1) <= 0x3F )
{
sigemptyset(&v5.sa_mask);
if ( sig == 11 )
{
v5.sa_flags = 134217732;
v5.sa_handler = a2;
sigaction(11, &v5, &v6);
}
else
{
v5.sa_flags = 0;
v5.sa_handler = a2;
sigaction(sig, &v5, &v6);
}
}
else if ( !sig )
{
LABEL_4:
v2 = psig0_func == (_QWORD)a2;
psig0_func = (__int64)a2;
return !v2;
}
return v6.sa_handler != a2;
}
result = 0LL;
v4 = trapflg[sig];
if ( (v4 & 0x10) == 0 )
{
if ( (unsigned int)(sig - 1) <= 0x3F )
{
sigemptyset(&v5.sa_mask);
if ( sig == 11 )
{
v5.sa_flags = 134217732;
v5.sa_handler = (__sighandler_t)&loc_1;
sigaction(11, &v5, &v6);
}
else
{
v5.sa_flags = 0;
v5.sa_handler = (__sighandler_t)&loc_1;
sigaction(sig, &v5, &v6);
}
v4 = trapflg[sig];
}
trapflg[sig] = v4 | 0x10;
if ( !sig )
goto LABEL_4;
return v6.sa_handler != a2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int sig, void (*a2)(int))
{
bool v2; // zf
__int64 result; // rax
__int16 v4; // dx
struct sigaction v5; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-B8h] BYREF

if ( a2 != (void (*)(int))&loc_1 )
{
if ( (unsigned int)(sig - 1) <= 0x3F )
{
sigemptyset(&v5.sa_mask);
if ( sig == 11 )
{
v5.sa_flags = 134217732;
v5.sa_handler = a2;
sigaction(11, &v5, &v6);
}
else
{
v5.sa_flags = 0;
v5.sa_handler = a2;
sigaction(sig, &v5, &v6);
}
}
else if ( !sig )
{
LABEL_4:
v2 = psig0_func == (_QWORD)a2;
psig0_func = (__int64)a2;
return !v2;
}
return v6.sa_handler != a2;
}
result = 0LL;
v4 = trapflg[sig];
if ( (v4 & 0x10) == 0 )
{
if ( (unsigned int)(sig - 1) <= 0x3F )
{
sigemptyset(&v5.sa_mask);
if ( sig == 11 )
{
v5.sa_flags = 134217732;
v5.sa_handler = (__sighandler_t)&loc_1;
sigaction(11, &v5, &v6);
}
else
{
v5.sa_flags = 0;
v5.sa_handler = (__sighandler_t)&loc_1;
sigaction(sig, &v5, &v6);
}
v4 = trapflg[sig];
}
trapflg[sig] = v4 | 0x10;
if ( !sig )
goto LABEL_4;
return v6.sa_handler != a2;
}
return result;
}

original_code:
int
handle(int sig, void (*func)(int))
{
 int ret;
 struct sigaction act, oact;
 if (func == ((__sighandler_t) 1) && (trapflg[sig] & 16))
  return (0);
 if (sig > 0 && sig < (64 + 1)) {
  sigemptyset(&act.sa_mask);
  act.sa_flags = (sig == 11) ? (0x08000000 | 4) : 0;
  act.__sigaction_handler.sa_handler = func;
  sigaction(sig, &act, &oact);
 }
 if (func == ((__sighandler_t) 1))
  trapflg[sig] |= 16;
 if (sig == 0) {
  ret = (psig0_func != func);
  psig0_func = func;
 } else {
  ret = (func != oact.__sigaction_handler.sa_handler);
 }
 return (ret);
}

canonical_original_code:
int handle(int sig, void (*func)(int))
{
 int ret;
 struct sigaction act; struct sigaction oact;
 if (func == ((void (*)(int)) 1) && (trapflg[sig] & 16))
  return (0);
 if (sig > 0 && sig < (64 + 1)) {
  sigemptyset(&act.sa_mask);
  act.sa_flags = (sig == 11) ? (0x08000000 | 4) : 0;
  act.__sigaction_handler.sa_handler = func;
  sigaction(sig, &act, &oact);
 }
 if (func == ((void (*)(int)) 1))
  trapflg[sig] |= 16;
 if (sig == 0) {
  ret = (psig0_func != func);
  psig0_func = func;
 } else {
  ret = (func != oact.__sigaction_handler.sa_handler);
 }
 return (ret);
}

variable_types: sig int

variable_types:
func
void (*)(int)

variable_types: ret int

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


clrsig

decompiled_code:
__int64 __fastcall clrsig(int a1)
{
__int64 result; // rax
void (*v2)(int); // rsi

if ( trapcom[a1] )
{
sh_free();
trapcom[a1] = 0LL;
}
result = (unsigned __int16)trapflg[a1];
if ( (result & 8) != 0 )
{
v2 = (void (*)(int))sigval[a1];
if ( (result & 0x10) != 0 )
LOWORD(result) = result & 0xFFEF;
trapflg[a1] = result & 0xFFF7;
result = handle(a1, v2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 result; // rax
void (*v2)(int); // rsi

if ( trapcom[a1] )
{
sh_free();
trapcom[a1] = 0LL;
}
result = (unsigned __int16)trapflg[a1];
if ( (result & 8) != 0 )
{
v2 = (void (*)(int))sigval[a1];
if ( (result & 0x10) != 0 )
LOWORD(result) = result & 0xFFEF;
trapflg[a1] = result & 0xFFF7;
result = func1(a1, v2);
}
return result;
}

original_code:
static void
clrsig(int i)
{
 if (trapcom[i] != 0) {
  sh_free(trapcom[i]);
  trapcom[i] = 0;
 }
 if (trapflg[i] & 8) {
  if (trapflg[i] & 16)
   trapflg[i] &= ~16;
  trapflg[i] &= ~8;
  handle(i, sigval[i]);
 }
}


stdsigs

decompiled_code:
int stdsigs()
{
int v0; // ebp
int v1; // er13
int *v2; // rax
int *v3; // rbx
int result; // eax
int v5; // ebx
void (*v6)(int); // rsi
int v7; // edi
char *v8; // rax
struct sigaltstack v9; // [rsp+0h] [rbp-48h] BYREF

v0 = _libc_current_sigrtmin();
v9.ss_sp = &sigsegv_stack;
v9.ss_size = 0x2000LL;
v1 = _libc_current_sigrtmax();
v9.ss_flags = 0;
v2 = _errno_location();
*v2 = 0;
v3 = v2;
result = sigaltstack(&v9, 0LL);
if ( result == -1 )
{
v8 = strerror(*v3);
result = failure("sigaltstack(2) failed with", v8);
}
v5 = 1;
do
{
while ( v0 != v5 )
{
v6 = (void (*)(int))sigval[v5];
if ( v6 )
{
if ( v5 == 11 )
goto LABEL_8;
result = ignoring(v5);
if ( !result )
{
v6 = (void (*)(int))sigval[v5];
LABEL_8:
result = handle(v5, v6);
goto LABEL_9;
}
}
LABEL_9:
if ( ++v5 > 64 )
goto LABEL_12;
}
v5 = v1 + 1;
}
while ( v1 + 1 <= 64 );
LABEL_12:
while ( v1 >= v0 )
{
v7 = v0++;
result = handle(v7, (void (*)(int))done);
}
return result;
}

canonical_decompiled_code:
int func3()
{
int v0; // ebp
int v1; // er13
int *v2; // rax
int *v3; // rbx
int result; // eax
int v5; // ebx
void (*v6)(int); // rsi
int v7; // edi
char *v8; // rax
struct sigaltstack v9; // [rsp+0h] [rbp-48h] BYREF

v0 = _libc_current_sigrtmin();
v9.ss_sp = &sigsegv_stack;
v9.ss_size = 0x2000LL;
v1 = _libc_current_sigrtmax();
v9.ss_flags = 0;
v2 = _errno_location();
*v2 = 0;
v3 = v2;
result = sigaltstack(&v9, 0LL);
if ( result == -1 )
{
v8 = strerror(*v3);
result = failure("sigaltstack(2) failed with", v8);
}
v5 = 1;
do
{
while ( v0 != v5 )
{
v6 = (void (*)(int))sigval[v5];
if ( v6 )
{
if ( v5 == 11 )
goto LABEL_8;
result = func0(v5);
if ( !result )
{
v6 = (void (*)(int))sigval[v5];
LABEL_8:
result = func1(v5, v6);
goto LABEL_9;
}
}
LABEL_9:
if ( ++v5 > 64 )
goto LABEL_12;
}
v5 = v1 + 1;
}
while ( v1 + 1 <= 64 );
LABEL_12:
while ( v1 >= v0 )
{
v7 = v0++;
result = func1(v7, (void (*)(int))done);
}
return result;
}

original_code:
void
stdsigs(void)
{
 register int i;
 stack_t ss;
 int err = 0;
 int rtmin = (int)(__libc_current_sigrtmin ());
 int rtmax = (int)(__libc_current_sigrtmax ());
 ss.ss_size = 8192;
 ss.ss_sp = sigsegv_stack;
 ss.ss_flags = 0;
 (*__errno_location ()) = 0;
 if (sigaltstack(&ss, (stack_t *)((void *)0)) == -1) {
  err = (*__errno_location ());
  failure("sigaltstack(2) failed with", strerror(err));
 }
 for (i = 1; i < (64 + 1); i++) {
  if (i == rtmin) {
   i = rtmax;
   continue;
  }
  if (sigval[i] == 0)
   continue;
  if (i != 11 && ignoring(i))
   continue;
  handle(i, sigval[i]);
 }
 for (i = rtmin; i <= rtmax; i++) {
  handle(i, done);
 }
}

canonical_original_code:
void stdsigs()
{
 register int i;
 struct stack_t ss;
 int err = 0;
 int rtmin = (int)(__libc_current_sigrtmin ());
 int rtmax = (int)(__libc_current_sigrtmax ());
 ss.ss_size = 8192;
 ss.ss_sp = sigsegv_stack;
 ss.ss_flags = 0;
 (*__errno_location ()) = 0;
 if (sigaltstack(&ss, (struct stack_t *)((void *)0)) == -1) {
  err = (*__errno_location ());
  failure("sigaltstack(2) failed with", strerror(err));
 }
 for (i = 1; i < (64 + 1); i++) {
  if (i == rtmin) {
   i = rtmax;
   continue;
  }
  if (sigval[i] == 0)
   continue;
  if (i != 11 && ignoring(i))
   continue;
  handle(i, sigval[i]);
 }
 for (i = rtmin; i <= rtmax; i++) {
  handle(i, done);
 }
}

variable_types: struct stack_t { void *ss_sp; int ss_flags; unsigned long ss_size; }

variable_types: err int

variable_types: rtmin int

variable_types: rtmax int


oldsigs

decompiled_code:
__int64 oldsigs()
{
__int64 v0; // rbx
_BYTE *v1; // rax
__int64 result; // rax

v0 = 64LL;
do
{
v1 = (_BYTE *)trapcom[v0];
if ( !v1 || *v1 )
clrsig(v0);
trapflg[v0] = 0;
}
while ( v0-- != 0 );
result = 0LL;
trapnote = 0;
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
_BYTE *v1; // rax
__int64 result; // rax

v0 = 64LL;
do
{
v1 = (_BYTE *)trapcom[v0];
if ( !v1 || *v1 )
func2(v0);
trapflg[v0] = 0;
}
while ( v0-- != 0 );
result = 0LL;
trapnote = 0;
return result;
}

original_code:
void
oldsigs(void)
{
 register int i;
 register unsigned char *t;
 i = (64 + 1);
 while (i--)
 {
  t = trapcom[i];
  if (t == 0 || *t)
   clrsig(i);
  trapflg[i] = 0;
 }
 trapnote = 0;
}

canonical_original_code:
void oldsigs()
{
 register int i;
 register unsigned char *t;
 i = (64 + 1);
 while (i--)
 {
  t = trapcom[i];
  if (t == 0 || *t)
   clrsig(i);
  trapflg[i] = 0;
 }
 trapnote = 0;
}

variable_types:
t
unsigned char *


chktrap

decompiled_code:
__int64 chktrap()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rdi
int v3; // ebp

v0 = 0LL;
trapnote &= 0xFFFDu;
do
{
result = (unsigned __int16)word_BA0[v0];
if ( (result & 2) != 0 )
{
v2 = qword_DC0[v0];
result = (unsigned int)result & 0xFFFFFFFD;
word_BA0[v0] = result;
if ( v2 )
{
v3 = exitval;
result = execexp(v2, 0LL);
exitval = v3;
retval = v3;
}
}
--v0;
}
while ( v0 != -64 );
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbx
__int64 result; // rax
__int64 v2; // rdi
int v3; // ebp

v0 = 0LL;
trapnote &= 0xFFFDu;
do
{
result = (unsigned __int16)word_BA0[v0];
if ( (result & 2) != 0 )
{
v2 = qword_DC0[v0];
result = (unsigned int)result & 0xFFFFFFFD;
word_BA0[v0] = result;
if ( v2 )
{
v3 = exitval;
result = execexp(v2, 0LL);
exitval = v3;
retval = v3;
}
}
--v0;
}
while ( v0 != -64 );
return result;
}

original_code:
void
chktrap(void)
{
 register int i = (64 + 1);
 register unsigned char *t;
 trapnote &= ~2;
 while (--i)
 {
  if (trapflg[i] & 2)
  {
   trapflg[i] &= ~2;
   if (t = trapcom[i])
   {
    int savxit = exitval;
    execexp(t, 0);
    exitval = savxit;
    retval = exitval;
   }
  }
 }
}

canonical_original_code:
void chktrap()
{
 register int i = (64 + 1);
 register unsigned char *t;
 trapnote &= ~2;
 while (--i)
 {
  if (trapflg[i] & 2)
  {
   trapflg[i] &= ~2;
   if (t = trapcom[i])
   {
    int savxit = exitval;
    execexp(t, 0);
    exitval = savxit;
    retval = exitval;
   }
  }
 }
}

variable_types: savxit int


done

decompiled_code:
void __fastcall __noreturn done(int sig)
{
__int64 v2; // r12
int v3; // ebx
__int64 v4; // rdi
sigset_t v5; // [rsp+0h] [rbp-98h] BYREF

v2 = trapcom[0];
if ( trapcom[0] )
{
v3 = exitval;
v4 = trapcom[0];
trapcom[0] = 0LL;
execexp(v4, 0LL);
exitval = v3;
sh_free(v2);
}
else
{
chktrap();
}
rmtemp(0LL);
rmfunctmp();
doacct();
if ( (flags[1] & 2) != 0 )
collect_fg_job();
endjobs(0LL);
if ( sig )
{
sigemptyset(&v5);
sigaddset(&v5, sig);
sigprocmask(1, &v5, 0LL);
handle(sig, 0LL);
kill(mypid, sig);
}
exit(exitval);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(int sig)
{
__int64 v2; // r12
int v3; // ebx
__int64 v4; // rdi
sigset_t v5; // [rsp+0h] [rbp-98h] BYREF

v2 = trapcom[0];
if ( trapcom[0] )
{
v3 = exitval;
v4 = trapcom[0];
trapcom[0] = 0LL;
execexp(v4, 0LL);
exitval = v3;
sh_free(v2);
}
else
{
func5();
}
rmtemp(0LL);
rmfunctmp();
doacct();
if ( (flags[1] & 2) != 0 )
collect_fg_job();
endjobs(0LL);
if ( sig )
{
sigemptyset(&v5);
sigaddset(&v5, sig);
sigprocmask(1, &v5, 0LL);
func1(sig, 0LL);
kill(mypid, sig);
}
exit(exitval);
}

original_code:
void
done(int sig)
{
 register unsigned char *t;
 int savxit;
 if (t = trapcom[0])
 {
  trapcom[0] = 0;
  savxit = exitval;
  execexp(t, 0);
  exitval = savxit;
  sh_free(t);
 }
 else
  chktrap();
 rmtemp(0);
 rmfunctmp();
 doacct();
 if (flags & 01000) {
  collect_fg_job();
 }
 endjobs(0);
 if (sig) {
  sigset_t set;
  sigemptyset(&set);
  sigaddset(&set, sig);
  sigprocmask(1, &set, 0);
  handle(sig, ((__sighandler_t) 0));
  kill(mypid, sig);
 }
 exit(exitval);
}

canonical_original_code:
void done(int sig)
{
 register unsigned char *t;
 int savxit;
 if (t = trapcom[0])
 {
  trapcom[0] = 0;
  savxit = exitval;
  execexp(t, 0);
  exitval = savxit;
  sh_free(t);
 }
 else
  chktrap();
 rmtemp(0);
 rmfunctmp();
 doacct();
 if (flags & 01000) {
  collect_fg_job();
 }
 endjobs(0);
 if (sig) {
  struct __sigset_t set;
  sigemptyset(&set);
  sigaddset(&set, sig);
  sigprocmask(1, &set, 0);
  handle(sig, ((void (*)(int)) 0));
  kill(mypid, sig);
 }
 exit(exitval);
}

variable_types: struct __sigset_t { unsigned long __val[-1]; }


fault

decompiled_code:
__int64 __fastcall fault(int a1)
{
__int64 result; // rax
__int16 v2; // dx

if ( a1 == 14 )
{
if ( sleeping )
return result;
if ( (char)flags[2] < 0 )
done(0);
}
result = a1;
v2 = 2;
if ( !trapcom[a1] )
{
if ( (flags[1] & 2) != 0 )
done(a1);
v2 = 4;
}
trapnote |= v2;
trapflg[a1] |= v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 result; // rax
__int16 v2; // dx

if ( a1 == 14 )
{
if ( sleeping )
return result;
if ( (char)flags[2] < 0 )
func6(0);
}
result = a1;
v2 = 2;
if ( !trapcom[a1] )
{
if ( (flags[1] & 2) != 0 )
func6(a1);
v2 = 4;
}
trapnote |= v2;
trapflg[a1] |= v2;
return result;
}

original_code:
void
fault(register int sig)
{
 register int flag = 0;
 switch (sig) {
  case 14:
   if (sleeping)
    return;
   if (flags & 040000000)
    done(0);
   break;
 }
 if (trapcom[sig])
  flag = 2;
 else if (flags & 01000)
  done(sig);
 else
  flag = 4;
 trapnote |= flag;
 trapflg[sig] |= flag;
}

canonical_original_code:
void fault(int sig)
{
 register int flag = 0;
 switch (sig) {
  case 14:
   if (sleeping)
    return;
   if (flags & 040000000)
    done(0);
   break;
 }
 if (trapcom[sig])
  flag = 2;
 else if (flags & 01000)
  done(sig);
 else
  flag = 4;
 trapnote |= flag;
 trapflg[sig] |= flag;
}

variable_types: flag int


sigsegv

decompiled_code:
__int64 __fastcall sigsegv(int a1, __int64 a2)
{
if ( !a2 || *(int *)(a2 + 8) > 0 )
exit(1);
return fault(a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2)
{
if ( !a2 || *(int *)(a2 + 8) > 0 )
exit(1);
return func7(a1);
}

original_code:
void
sigsegv(int sig, siginfo_t *sip)
{
 if (sip == (siginfo_t *)((void *)0)) {
  exit(1);
 } else {
  if (sip->si_code <= 0) {
   fault(sig);
  } else {
   exit(1);
  }
 }
}

canonical_original_code:
void sigsegv(int sig, struct siginfo_t *sip)
{
 if (sip == (struct siginfo_t *)((void *)0)) {
  exit(1);
 } else {
  if (sip->si_code <= 0) {
   fault(sig);
  } else {
   exit(1);
  }
 }
}

variable_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *


systrap

decompiled_code:
__int64 __fastcall systrap(int a1, _QWORD *a2)
{
int i; // edi
_BYTE *v4; // r13
_QWORD *v5; // r14
__int64 v6; // rbp
int v7; // er12
__int64 v8; // rdi
_QWORD *v9; // rbx
int v10; // edi
__int64 *v11; // rdi
int sig[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a1 == 1 )
{
sig[0] = 0;
for ( i = 0; i <= 64; sig[0] = i )
{
if ( trapcom[i] )
{
prn_buff();
prs_buff(&colon);
prs_buff(trapcom[sig[0]]);
prc_buff(10LL);
}
i = sig[0] + 1;
}
return 0LL;
}
v4 = (_BYTE *)a2[1];
v5 = a2;
v6 = *a2;
v7 = str_2_sig(v4, sig);
if ( v7 )
v5 = a2 + 1;
v8 = v5[1];
v9 = v5 + 1;
if ( !v8 )
return 0LL;
do
{
if ( (int)str_2_sig(v8, sig) < 0 || (v10 = sig[0], sig[0] == 14 || sig[0] == 11) || sig[0] > 0x40u )
{
failure(v6, &badtrap);
goto LABEL_14;
}
if ( v7 )
{
if ( *v4 )
{
if ( (trapflg[sig[0]] & 8) != 0 || !sig[0] )
goto LABEL_20;
if ( !(unsigned int)ignoring(sig[0]) )
{
v10 = sig[0];
LABEL_20:
handle(v10, (void (*)(int))fault);
LABEL_21:
v11 = &trapcom[sig[0]];
trapflg[sig[0]] |= 8u;
replace(v11, v4);
goto LABEL_14;
}
}
else if ( (unsigned int)handle(sig[0], (void (*)(int))&loc_1) )
{
goto LABEL_21;
}
}
else
{
clrsig(sig[0]);
}
LABEL_14:
v8 = v9[1];
++v9;
}
while ( v8 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, _QWORD *a2)
{
int i; // edi
_BYTE *v4; // r13
_QWORD *v5; // r14
__int64 v6; // rbp
int v7; // er12
__int64 v8; // rdi
_QWORD *v9; // rbx
int v10; // edi
__int64 *v11; // rdi
int sig[11]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( a1 == 1 )
{
sig[0] = 0;
for ( i = 0; i <= 64; sig[0] = i )
{
if ( trapcom[i] )
{
prn_buff();
prs_buff(&colon);
prs_buff(trapcom[sig[0]]);
prc_buff(10LL);
}
i = sig[0] + 1;
}
return 0LL;
}
v4 = (_BYTE *)a2[1];
v5 = a2;
v6 = *a2;
v7 = str_2_sig(v4, sig);
if ( v7 )
v5 = a2 + 1;
v8 = v5[1];
v9 = v5 + 1;
if ( !v8 )
return 0LL;
do
{
if ( (int)str_2_sig(v8, sig) < 0 || (v10 = sig[0], sig[0] == 14 || sig[0] == 11) || sig[0] > 0x40u )
{
failure(v6, &badtrap);
goto LABEL_14;
}
if ( v7 )
{
if ( *v4 )
{
if ( (trapflg[sig[0]] & 8) != 0 || !sig[0] )
goto LABEL_20;
if ( !(unsigned int)func0(sig[0]) )
{
v10 = sig[0];
LABEL_20:
func1(v10, (void (*)(int))fault);
LABEL_21:
v11 = &trapcom[sig[0]];
trapflg[sig[0]] |= 8u;
replace(v11, v4);
goto LABEL_14;
}
}
else if ( (unsigned int)func1(sig[0], (void (*)(int))&loc_1) )
{
goto LABEL_21;
}
}
else
{
func2(sig[0]);
}
LABEL_14:
v8 = v9[1];
++v9;
}
while ( v8 );
return 0LL;
}

original_code:
int
systrap(int argc, char **argv)
{
 int sig;
 if (argc == 1) {
  for (sig = 0; sig < (64 + 1); sig++) {
   if (trapcom[sig]) {
    prn_buff(sig);
    prs_buff(colon);
    prs_buff(trapcom[sig]);
    prc_buff('\n');
   }
  }
 } else {
  char *cmd = *argv, *a1 = *(argv+1);
  BOOL noa1;
  noa1 = (str_2_sig(a1, &sig) == 0);
  if (noa1 == 0)
   ++argv;
  while (*++argv) {
   if (str_2_sig(*argv, &sig) < 0 ||
       sig >= (64 + 1) || sig < 0 ||
       sig == 11 || sig == 14) {
    failure(cmd, badtrap);
   } else if (noa1) {
    clrsig(sig);
   } else if (*a1) {
    if (trapflg[sig] & 8 || sig == 0 ||
        !ignoring(sig)) {
     handle(sig, fault);
     trapflg[sig] |= 8;
     replace(&trapcom[sig], a1);
    }
   } else if (handle(sig, ((__sighandler_t) 1))) {
    trapflg[sig] |= 8;
    replace(&trapcom[sig], a1);
   }
  }
 }
 return 0;
}

canonical_original_code:
int systrap(int argc, char **argv)
{
 int sig;
 if (argc == 1) {
  for (sig = 0; sig < (64 + 1); sig++) {
   if (trapcom[sig]) {
    prn_buff(sig);
    prs_buff(colon);
    prs_buff(trapcom[sig]);
    prc_buff('\n');
   }
  }
 } else {
  char *cmd = *argv; char *a1 = *(argv+1);
  short noa1;
  noa1 = (str_2_sig(a1, &sig) == 0);
  if (noa1 == 0)
   ++argv;
  while (*++argv) {
   if (str_2_sig(*argv, &sig) < 0 ||
       sig >= (64 + 1) || sig < 0 ||
       sig == 11 || sig == 14) {
    failure(cmd, badtrap);
   } else if (noa1) {
    clrsig(sig);
   } else if (*a1) {
    if (trapflg[sig] & 8 || sig == 0 ||
        !ignoring(sig)) {
     handle(sig, fault);
     trapflg[sig] |= 8;
     replace(&trapcom[sig], a1);
    }
   } else if (handle(sig, ((void (*)(int)) 1))) {
    trapflg[sig] |= 8;
    replace(&trapcom[sig], a1);
   }
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
cmd
char *


decompiled_code:
int __fastcall sh_sleep(unsigned int seconds)
{
sigset_t v2; // [rsp+0h] [rbp-248h] BYREF
sigset_t oset; // [rsp+80h] [rbp-1C8h] BYREF
struct sigaction v4; // [rsp+100h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+1A0h] [rbp-A8h] BYREF

sigemptyset(&v2);
sigaddset(&v2, 14);
sigprocmask(0, &v2, &oset);
sigemptyset(&v4.sa_mask);
v4.sa_flags = 0;
v4.sa_handler = (__sighandler_t)fault;
sigaction(14, &v4, &v5);
alarm(seconds);
sleeping = 1;
sigsuspend(&oset);
sleeping = 0;
alarm(0);
sigaction(14, &v5, 0LL);
return sigprocmask(2, &oset, 0LL);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int seconds)
{
sigset_t v2; // [rsp+0h] [rbp-248h] BYREF
sigset_t oset; // [rsp+80h] [rbp-1C8h] BYREF
struct sigaction v4; // [rsp+100h] [rbp-148h] BYREF
struct sigaction v5; // [rsp+1A0h] [rbp-A8h] BYREF

sigemptyset(&v2);
sigaddset(&v2, 14);
sigprocmask(0, &v2, &oset);
sigemptyset(&v4.sa_mask);
v4.sa_flags = 0;
v4.sa_handler = (__sighandler_t)fault;
sigaction(14, &v4, &v5);
alarm(seconds);
sleeping = 1;
sigsuspend(&oset);
sleeping = 0;
alarm(0);
sigaction(14, &v5, 0LL);
return sigprocmask(2, &oset, 0LL);
}

original_code:
void
sh_sleep(unsigned int ticks)
{
 sigset_t set, oset;
 struct sigaction act, oact;
 sigemptyset(&set);
 sigaddset(&set, 14);
 sigprocmask(0, &set, &oset);
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 act.__sigaction_handler.sa_handler = fault;
 sigaction(14, &act, &oact);
 alarm(ticks);
 sleeping = 1;
 sigsuspend(&oset);
 sleeping = 0;
 alarm(0);
 sigaction(14, &oact, ((void *)0));
 sigprocmask(2, &oset, 0);
}

canonical_original_code:
void sh_sleep(unsigned int ticks)
{
 struct __sigset_t set; struct __sigset_t oset;
 struct sigaction act; struct sigaction oact;
 sigemptyset(&set);
 sigaddset(&set, 14);
 sigprocmask(0, &set, &oset);
 sigemptyset(&act.sa_mask);
 act.sa_flags = 0;
 act.__sigaction_handler.sa_handler = fault;
 sigaction(14, &act, &oact);
 alarm(ticks);
 sleeping = 1;
 sigsuspend(&oset);
 sleeping = 0;
 alarm(0);
 sigaction(14, &oact, ((void *)0));
 sigprocmask(2, &oset, 0);
}

variable_types:
ticks
unsigned int


freeio

original_code:
void
freeio(register struct ionod *iop)
{
 register struct ionod *sav;
 while (iop)
 {
  if (iop->iofile & 16)
  {
   unlink(iop->ioname);
   if (fiotemp == iop)
    fiotemp = iop->iolst;
   else
   {
    struct ionod *fiop = fiotemp;
    while (fiop->iolst != iop)
     fiop = fiop->iolst;
    fiop->iolst = iop->iolst;
   }
  }
  sh_free(iop->ioname);
  sh_free(iop->iolink);
  sav = iop->ionxt;
  sh_free(iop);
  iop = sav;
 }
}

canonical_original_code:
void freeio(struct ionod *iop)
{
 register struct ionod *sav;
 while (iop)
 {
  if (iop->iofile & 16)
  {
   unlink(iop->ioname);
   if (fiotemp == iop)
    fiotemp = iop->iolst;
   else
   {
    struct ionod *fiop = fiotemp;
    while (fiop->iolst != iop)
     fiop = fiop->iolst;
    fiop->iolst = iop->iolst;
   }
  }
  sh_free(iop->ioname);
  sh_free(iop->iolink);
  sav = iop->ionxt;
  sh_free(iop);
  iop = sav;
 }
}

variable_types: struct ionod { int iofile; char *ioname; char *iolink; struct ionod *ionxt; struct ionod *iolst; } *


freereg

decompiled_code:
__int64 __fastcall freereg(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
__int64 result; // rax

if ( a1 )
{
v1 = a1;
do
{
free_arg(*(_QWORD **)v1);
freetree(*(_QWORD *)(v1 + 8));
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
result = sh_free(v2);
}
while ( v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rdi
__int64 result; // rax

if ( a1 )
{
v1 = a1;
do
{
func0(*(_QWORD **)v1);
func3(*(_QWORD *)(v1 + 8));
v2 = v1;
v1 = *(_QWORD *)(v1 + 16);
result = sh_free(v2);
}
while ( v1 );
}
return result;
}

original_code:
void
freereg(register struct regnod *regp)
{
 register struct regnod *sav;
 while (regp)
 {
  free_arg(regp->regptr);
  freetree(regp->regcom);
  sav = regp->regnxt;
  sh_free(regp);
  regp = sav;
 }
}

canonical_original_code:
void freereg(struct regnod *regp)
{
 register struct regnod *sav;
 while (regp)
 {
  free_arg(regp->regptr);
  freetree(regp->regcom);
  sav = regp->regnxt;
  sh_free(regp);
  regp = sav;
 }
}

variable_types: struct regnod { struct argnod { struct argnod *argnxt; unsigned char argval[1]; } *regptr; struct trenod { int tretyp; struct ionod { int iofile; char *ioname; char *iolink; struct ionod *ionxt; struct ionod *iolst; } *treio; } *regcom; struct regnod *regnxt; } *

user_defined_types: struct regnod { struct argnod *regptr; struct trenod *regcom; struct regnod *regnxt; }

user_defined_types: struct trenod { int tretyp; struct ionod *treio; }


freetree

original_code:
void
freetree(register struct trenod *t)
{
 if (t)
 {
  register int type;
  if (t->tretyp & 0x000F)
  {
   t->tretyp--;
   return;
  }
  type = t->tretyp & 0x00F0;
  switch (type)
  {
   case 0x00C0:
    sh_free(((struct fndnod *)t)->fndnam);
    freetree(((struct fndnod *)t)->fndval);
    break;
   case 0x0000:
    freeio(((struct comnod *)t)->comio);
    free_arg(((struct comnod *)t)->comarg);
    free_arg(((struct comnod *)t)->comset);
    break;
   case 0x00A0:
    freeio(((struct forknod *)t)->forkio);
    freetree(((struct forknod *)t)->forktre);
    break;
   case 0x0010:
    freetree(((struct parnod *)t)->partre);
    break;
   case 0x0020:
   case 0x0030:
   case 0x0080:
   case 0x0090:
    freetree(((struct lstnod *)t)->lstlef);
    freetree(((struct lstnod *)t)->lstrit);
    break;
   case 0x00B0:
   {
    struct fornod *f = (struct fornod *)t;
    sh_free(f->fornam);
    freetree(f->fortre);
    if (f->forlst)
    {
     freeio(f->forlst->comio);
     free_arg(f->forlst->comarg);
     free_arg(f->forlst->comset);
     sh_free(f->forlst);
    }
   }
   break;
   case 0x0050:
   case 0x0060:
    freetree(((struct whnod *)t)->whtre);
    freetree(((struct whnod *)t)->dotre);
    break;
   case 0x0040:
    freetree(((struct ifnod *)t)->iftre);
    freetree(((struct ifnod *)t)->thtre);
    freetree(((struct ifnod *)t)->eltre);
    break;
   case 0x0070:
    sh_free(((struct swnod *)t)->swarg);
    freereg(((struct swnod *)t)->swlst);
    break;
  }
  sh_free(t);
 }
}

canonical_original_code:
void freetree(struct trenod *t)
{
 if (t)
 {
  register int type;
  if (t->tretyp & 0x000F)
  {
   t->tretyp--;
   return;
  }
  type = t->tretyp & 0x00F0;
  switch (type)
  {
   case 0x00C0:
    sh_free(((struct fndnod *)t)->fndnam);
    freetree(((struct fndnod *)t)->fndval);
    break;
   case 0x0000:
    freeio(((struct comnod *)t)->comio);
    free_arg(((struct comnod *)t)->comarg);
    free_arg(((struct comnod *)t)->comset);
    break;
   case 0x00A0:
    freeio(((struct forknod *)t)->forkio);
    freetree(((struct forknod *)t)->forktre);
    break;
   case 0x0010:
    freetree(((struct parnod *)t)->partre);
    break;
   case 0x0020:
   case 0x0030:
   case 0x0080:
   case 0x0090:
    freetree(((struct lstnod *)t)->lstlef);
    freetree(((struct lstnod *)t)->lstrit);
    break;
   case 0x00B0:
   {
    struct fornod *f = (struct fornod *)t;
    sh_free(f->fornam);
    freetree(f->fortre);
    if (f->forlst)
    {
     freeio(f->forlst->comio);
     free_arg(f->forlst->comarg);
     free_arg(f->forlst->comset);
     sh_free(f->forlst);
    }
   }
   break;
   case 0x0050:
   case 0x0060:
    freetree(((struct whnod *)t)->whtre);
    freetree(((struct whnod *)t)->dotre);
    break;
   case 0x0040:
    freetree(((struct ifnod *)t)->iftre);
    freetree(((struct ifnod *)t)->thtre);
    freetree(((struct ifnod *)t)->eltre);
    break;
   case 0x0070:
    sh_free(((struct swnod *)t)->swarg);
    freereg(((struct swnod *)t)->swlst);
    break;
  }
  sh_free(t);
 }
}

variable_types: type int

variable_types: struct fornod { int fortyp; struct trenod { int tretyp; struct ionod { int iofile; char *ioname; char *iolink; struct ionod *ionxt; struct ionod *iolst; } *treio; } *fortre; unsigned char *fornam; struct comnod { int comtyp; struct ionod *comio; struct argnod { struct argnod *argnxt; unsigned char argval[1]; } *comarg; struct argnod *comset; } *forlst; } *

user_defined_types: struct fornod { int fortyp; struct trenod *fortre; unsigned char *fornam; struct comnod *forlst; }

user_defined_types: struct fndnod { int fndtyp; unsigned char *fndnam; struct trenod *fndval; }

user_defined_types: struct comnod { int comtyp; struct ionod *comio; struct argnod *comarg; struct argnod *comset; }

user_defined_types: struct forknod { int forktyp; struct ionod *forkio; struct trenod *forktre; }

user_defined_types: struct parnod { int partyp; struct trenod *partre; }

user_defined_types: struct lstnod { int lsttyp; struct trenod *lstlef; struct trenod *lstrit; }

user_defined_types: struct whnod { int whtyp; struct trenod *whtre; struct trenod *dotre; }

user_defined_types: struct ifnod { int iftyp; struct trenod *iftre; struct trenod *thtre; struct trenod *eltre; }

user_defined_types: struct swnod { int swtyp; unsigned char *swarg; struct regnod *swlst; }


freefunc

decompiled_code:
void __fastcall freefunc(__int64 a1)
{
freetree(*(int **)(a1 + 32));
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
func3(*(int **)(a1 + 32));
}

original_code:
void
freefunc(struct namnod *n)
{
 freetree((struct trenod *)(n->namenv));
}

variable_types: struct namnod { struct namnod *namlft; struct namnod *namrgt; unsigned char *namid; unsigned char *namval; unsigned char *namenv; int namflg; } *

user_defined_types: struct ionod { int iofile; char *ioname; char *iolink; struct ionod *ionxt; struct ionod *iolst; }


prbgnlst

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

if ( nonl )
result = prc_buff(32LL);
else
result = prc_buff(10LL);
return result;
}

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

if ( nonl )
result = prc_buff(32LL);
else
result = prc_buff(10LL);
return result;
}

original_code:
void
prbgnlst(void)
{
 if (nonl)
  prc_buff(' ');
 else
  prc_buff('\n');
}

canonical_original_code:
void prbgnlst()
{
 if (nonl)
  prc_buff(' ');
 else
  prc_buff('\n');
}


prendlst

decompiled_code:
__int64 prendlst()
{
if ( !nonl )
return prc_buff(10LL);
prc_buff(59LL);
return prc_buff(32LL);
}

canonical_decompiled_code:
__int64 func6()
{
if ( !nonl )
return prc_buff(10LL);
prc_buff(59LL);
return prc_buff(32LL);
}

original_code:
void
prendlst(void)
{
 if (nonl) {
  prc_buff(';');
  prc_buff(' ');
 }
 else
  prc_buff('\n');
}

canonical_original_code:
void prendlst()
{
 if (nonl) {
  prc_buff(';');
  prc_buff(' ');
 }
 else
  prc_buff('\n');
}


prarg

decompiled_code:
__int64 __fastcall prarg(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
while ( 1 )
{
result = prs_buff(v1 + 1);
v1 = (_QWORD *)*v1;
if ( !v1 )
break;
prc_buff(32LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
_QWORD *v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
while ( 1 )
{
result = prs_buff(v1 + 1);
v1 = (_QWORD *)*v1;
if ( !v1 )
break;
prc_buff(32LL);
}
}
return result;
}

original_code:
void
prarg(register struct argnod *argp)
{
 while (argp)
 {
  prs_buff(argp->argval);
  argp=argp->argnxt;
  if (argp)
   prc_buff(' ');
 }
}

canonical_original_code:
void prarg(struct argnod *argp)
{
 while (argp)
 {
  prs_buff(argp->argval);
  argp=argp->argnxt;
  if (argp)
   prc_buff(' ');
 }
}

variable_types: struct argnod { struct argnod *argnxt; unsigned char argval[1]; } *


prio

original_code:
void
prio(register struct ionod *iop)
{
 register int iof;
 register unsigned char *ion;
 while (iop)
 {
  iof = iop->iofile;
  ion = (unsigned char *) iop->ioname;
  if (*ion)
  {
   prc_buff(' ');
   prn_buff(iof & 15);
   if (iof & 16)
    prs_buff("<<");
   else if (iof & 128)
   {
    if (iof & 32)
     prs_buff(">&");
    else
     prs_buff("<&");
   }
   else if ((iof & 32) == 0)
    prc_buff('<');
   else if (iof & 64)
    prs_buff(">>");
   else
    prc_buff('>');
   prs_buff(ion);
  }
  iop = iop->ionxt;
 }
}

canonical_original_code:
void prio(struct ionod *iop)
{
 register int iof;
 register unsigned char *ion;
 while (iop)
 {
  iof = iop->iofile;
  ion = (unsigned char *) iop->ioname;
  if (*ion)
  {
   prc_buff(' ');
   prn_buff(iof & 15);
   if (iof & 16)
    prs_buff("<<");
   else if (iof & 128)
   {
    if (iof & 32)
     prs_buff(">&");
    else
     prs_buff("<&");
   }
   else if ((iof & 32) == 0)
    prc_buff('<');
   else if (iof & 64)
    prs_buff(">>");
   else
    prc_buff('>');
   prs_buff(ion);
  }
  iop = iop->ionxt;
 }
}

variable_types: iof int

variable_types:
ion
unsigned char *


prcmd

decompiled_code:
void __fastcall prcmd(__int64 a1)
{
++nonl;
prf(a1);
nonl = 0;
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
++nonl;
func9(a1);
nonl = 0;
}

original_code:
void
prcmd(struct trenod *t)
{
 nonl++;
 prf(t);
 nonl = 0;
}

variable_types: struct trenod { int tretyp; struct ionod { int iofile; char *ioname; char *iolink; struct ionod *ionxt; struct ionod *iolst; } *treio; } *


zapentry

decompiled_code:
void __fastcall zapentry(__int64 a1)
{
*(_WORD *)(a1 + 8) &= 0x3FFu;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_WORD *)(a1 + 8) &= 0x3FFu;
}

original_code:
static void
zapentry(ENTRY *h)
{
 h->data &= 0x03FF;
}

canonical_original_code:
static void zapentry(struct entry *h)
{
 h->data &= 0x03FF;
}

variable_types: struct entry { unsigned char *key; short data; unsigned char hits; unsigned char cost; struct entry *next; } *


argpath

original_code:
static int
argpath(register struct argnod *arg)
{
 register unsigned char *s;
 register unsigned char *start;
 while (arg)
 {
  s = arg->argval;
  start = s;
  if (((*s<0200) && sh_ctype2[*s]&(0100)))
  {
   while (((*s<0200) && sh_ctype2[*s]&((0100|010))))
    s++;
   if (*s == '=')
   {
    *s = 0;
    if ((cf(start, pathname) == 0))
    {
     *s = '=';
     return(1);
    }
    else
     *s = '=';
   }
  }
  arg = arg->argnxt;
 }
 return(0);
}

canonical_original_code:
static int argpath(struct argnod *arg)
{
 register unsigned char *s;
 register unsigned char *start;
 while (arg)
 {
  s = arg->argval;
  start = s;
  if (((*s<0200) && sh_ctype2[*s]&(0100)))
  {
   while (((*s<0200) && sh_ctype2[*s]&((0100|010))))
    s++;
   if (*s == '=')
   {
    *s = 0;
    if ((cf(start, pathname) == 0))
    {
     *s = '=';
     return(1);
    }
    else
     *s = '=';
   }
  }
  arg = arg->argnxt;
 }
 return(0);
}

variable_types:
s
unsigned char *

variable_types:
start
unsigned char *

user_defined_types: struct argnod { struct argnod *argnxt; unsigned char argval[1]; }


zaphash

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

result = hscan(zapentry);
qword_980 = 0LL;
return result;
}

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

result = hscan(zapentry);
qword_980 = 0LL;
return result;
}

original_code:
void
zaphash(void)
{
 hscan(zapentry);
 relcmd.next = 0;
}

canonical_original_code:
void zaphash()
{
 hscan(zapentry);
 relcmd.next = 0;
}


zapcd

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

for ( result = qword_980; result; result = *(_QWORD *)(result + 16) )
*(_WORD *)(result + 8) |= 0x8000u;
qword_980 = 0LL;
return result;
}

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

for ( result = qword_980; result; result = *(_QWORD *)(result + 16) )
*(_WORD *)(result + 8) |= 0x8000u;
qword_980 = 0LL;
return result;
}

original_code:
void
zapcd(void)
{
 ENTRY *ptr = relcmd.next;
 while (ptr)
 {
  ptr->data |= 0x8000;
  ptr = ptr->next;
 }
 relcmd.next = 0;
}

canonical_original_code:
void zapcd()
{
 struct entry *ptr = relcmd.next;
 while (ptr)
 {
  ptr->data |= 0x8000;
  ptr = ptr->next;
 }
 relcmd.next = 0;
}

user_defined_types: struct entry { unsigned char *key; short data; unsigned char hits; unsigned char cost; struct entry *next; }


hashpr

decompiled_code:
__int64 hashpr()
{
prs_buff("hits\tcost\tcommand\n");
return hscan(hashout);
}

canonical_decompiled_code:
__int64 func4()
{
prs_buff("hits\tcost\tcommand\n");
return hscan(hashout);
}

original_code:
void
hashpr(void)
{
 prs_buff("hits	cost	command\n");
 hscan(hashout);
}

canonical_original_code:
void hashpr()
{
 prs_buff("hits	cost	command\n");
 hscan(hashout);
}


decompiled_code:
__int64 set_dotpath()
{
int v0; // ebx
__int64 result; // rax
unsigned __int8 *v2; // rdi

v0 = 1;
dotpath = 10000;
result = getpath(&unk_9A4);
v2 = (unsigned __int8 *)result;
if ( result )
{
while ( 1 )
{
result = *v2;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 47 )
{
result = nextpath();
++v0;
v2 = (unsigned __int8 *)result;
if ( !result )
break;
}
else
{
if ( dotpath != 10000 )
{
multrel = 1;
return result;
}
dotpath = v0;
result = nextpath();
v2 = (unsigned __int8 *)result;
if ( !result )
break;
}
}
}
multrel = 0;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // ebx
__int64 result; // rax
unsigned __int8 *v2; // rdi

v0 = 1;
dotpath = 10000;
result = getpath(&unk_9A4);
v2 = (unsigned __int8 *)result;
if ( result )
{
while ( 1 )
{
result = *v2;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 47 )
{
result = nextpath();
++v0;
v2 = (unsigned __int8 *)result;
if ( !result )
break;
}
else
{
if ( dotpath != 10000 )
{
multrel = 1;
return result;
}
dotpath = v0;
result = nextpath();
v2 = (unsigned __int8 *)result;
if ( !result )
break;
}
}
}
multrel = 0;
return result;
}

original_code:
void
set_dotpath(void)
{
 register unsigned char *path;
 register int cnt = 1;
 dotpath = 10000;
 path = getpath("");
 while (path && *path)
 {
  if (*path == '/')
   cnt++;
  else
  {
   if (dotpath == 10000)
    dotpath = cnt;
   else
   {
    multrel = 1;
    return;
   }
  }
  path = nextpath(path);
 }
 multrel = 0;
}

canonical_original_code:
void set_dotpath()
{
 register unsigned char *path;
 register int cnt = 1;
 dotpath = 10000;
 path = getpath("");
 while (path && *path)
 {
  if (*path == '/')
   cnt++;
  else
  {
   if (dotpath == 10000)
    dotpath = cnt;
   else
   {
    multrel = 1;
    return;
   }
  }
  path = nextpath(path);
 }
 multrel = 0;
}

variable_types:
path
unsigned char *

variable_types: cnt int


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

result = hfind();
if ( result )
{
*(_WORD *)(result + 8) = 512;
}
else
{
make(a1);
result = henter(a1, a2, v3);
}
return result;
}

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

result = hfind();
if ( result )
{
*(_WORD *)(result + 8) = 512;
}
else
{
make(a1);
result = henter(a1, a2, v3);
}
return result;
}

original_code:
void
hash_func(unsigned char *name)
{
 ENTRY *h;
 ENTRY hentry;
 h = hfind(name);
 if (h)
  h->data = 0x0200;
 else
 {
  hentry.data = 0x0200;
  hentry.key = make(name);
  hentry.cost = 0;
  hentry.hits = 0;
  henter(hentry);
 }
}

canonical_original_code:
void hash_func(unsigned char *name)
{
 struct entry *h;
 struct entry hentry;
 h = hfind(name);
 if (h)
  h->data = 0x0200;
 else
 {
  hentry.data = 0x0200;
  hentry.key = make(name);
  hentry.cost = 0;
  hentry.hits = 0;
  henter(hentry);
 }
}

variable_types:
name
unsigned char *

variable_types: struct entry { unsigned char *key; short data; unsigned char hits; unsigned char cost; struct entry *next; }


decompiled_code:
__int64 __fastcall func_unhash(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
unsigned int v3; // eax
unsigned int v4; // edx
bool v5; // zf

result = hfind();
if ( result )
{
v2 = result;
if ( (*(_BYTE *)(result + 9) & 2) != 0 )
{
v3 = syslook(a1, &commands, no_commands);
v4 = v3;
BYTE1(v4) = BYTE1(v3) | 1;
v5 = v3 == 0;
result = 0LL;
if ( !v5 )
result = v4;
*(_WORD *)(v2 + 8) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
unsigned int v3; // eax
unsigned int v4; // edx
bool v5; // zf

result = hfind();
if ( result )
{
v2 = result;
if ( (*(_BYTE *)(result + 9) & 2) != 0 )
{
v3 = syslook(a1, &commands, no_commands);
v4 = v3;
BYTE1(v4) = BYTE1(v3) | 1;
v5 = v3 == 0;
result = 0LL;
if ( !v5 )
result = v4;
*(_WORD *)(v2 + 8) = result;
}
}
return result;
}

original_code:
void
func_unhash(unsigned char *name)
{
 ENTRY *h;
 int i;
 h = hfind(name);
 if (h && (h->data & 0x0200)) {
  if(i = syslook(name, commands, no_commands))
   h->data = (0x0100|i);
  else
   h->data = 0x0000;
 }
}

canonical_original_code:
void func_unhash(unsigned char *name)
{
 struct entry *h;
 int i;
 h = hfind(name);
 if (h && (h->data & 0x0200)) {
  if(i = syslook(name, commands, no_commands))
   h->data = (0x0100|i);
  else
   h->data = 0x0000;
 }
}

variable_types: i int


decompiled_code:
int __fastcall chk_access(char *name, unsigned int a2, int a3)
{
bool v4; // r13
int result; // eax
__uid_t v6; // eax
struct stat64 v7; // [rsp+0h] [rbp-B8h] BYREF

if ( !flag_1 )
{
v6 = geteuid();
flag_1 = 1;
euid_0 = v6;
}
if ( stat64(name, &v7) )
goto LABEL_11;
v4 = (v7.st_mode & 0xF000) != 0x8000;
if ( v4 && a3 != 0 )
{
result = 2;
if ( a2 == 64 )
return result;
}
result = access(name, a2 >> 6);
if ( result )
{
LABEL_11:
if ( *_errno_location() == 13 )
return 3;
result = 1;
}
else if ( a2 == 64 && !v4 && !(euid_0 | v7.st_mode & 0x49) )
{
return 3;
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(char *name, unsigned int a2, int a3)
{
bool v4; // r13
int result; // eax
__uid_t v6; // eax
struct stat64 v7; // [rsp+0h] [rbp-B8h] BYREF

if ( !flag_1 )
{
v6 = geteuid();
flag_1 = 1;
euid_0 = v6;
}
if ( stat64(name, &v7) )
goto LABEL_11;
v4 = (v7.st_mode & 0xF000) != 0x8000;
if ( v4 && a3 != 0 )
{
result = 2;
if ( a2 == 64 )
return result;
}
result = access(name, a2 >> 6);
if ( result )
{
LABEL_11:
if ( *_errno_location() == 13 )
return 3;
result = 1;
}
else if ( a2 == 64 && !v4 && !(euid_0 | v7.st_mode & 0x49) )
{
return 3;
}
return result;
}

original_code:
int
chk_access(register unsigned char *name, mode_t mode, int regflag)
{
 static int flag;
 static uid_t euid;
 struct stat statb;
 mode_t ftype;
 if(flag == 0) {
  euid = geteuid();
  flag = 1;
 }
 ftype = statb.st_mode & 0170000;
 if (stat((char *)name, &statb) == 0) {
  ftype = statb.st_mode & 0170000;
  if(mode == 0100 && regflag && ftype != 0100000)
   return(2);
  if(access((char *)name, mode>>6) == 0) {
   if(euid == 0) {
    if (ftype != 0100000 || mode != 0100)
     return(0);
    if (statb.st_mode & (0100|(0100>>3)|(0100>>6)))
     return(0);
    return(3);
   }
   return(0);
  }
 }
 return((*__errno_location ()) == 13 ? 3 : 1);
}

canonical_original_code:
int chk_access(unsigned char *name, unsigned int mode, int regflag)
{
 static int flag;
 static unsigned int euid;
 struct stat statb;
 unsigned int ftype;
 if(flag == 0) {
  euid = geteuid();
  flag = 1;
 }
 ftype = statb.st_mode & 0170000;
 if (stat((char *)name, &statb) == 0) {
  ftype = statb.st_mode & 0170000;
  if(mode == 0100 && regflag && ftype != 0100000)
   return(2);
  if(access((char *)name, mode>>6) == 0) {
   if(euid == 0) {
    if (ftype != 0100000 || mode != 0100)
     return(0);
    if (statb.st_mode & (0100|(0100>>3)|(0100>>6)))
     return(0);
    return(3);
   }
   return(0);
  }
 }
 return((*__errno_location ()) == 13 ? 3 : 1);
}

variable_types:
mode
unsigned int

variable_types: regflag int

variable_types: flag int

variable_types:
euid
unsigned int

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:
ftype
unsigned int

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


findpath

decompiled_code:
__int64 __fastcall findpath(__int64 a1, int a2)
{
unsigned int v2; // ebx
__int64 v3; // rbp
int v4; // er13
int v5; // er13
int v7; // ebx
__int64 v8; // rax
int v9; // eax

v2 = a2;
cost = 0;
v3 = getpath(a1);
if ( a2 )
{
v4 = dotpath - 1;
if ( dotpath == 1 )
{
v5 = 1;
}
else
{
do
{
v3 = nextpath(v3);
--v4;
}
while ( v4 );
v5 = dotpath;
}
if ( a2 > v5 )
{
catpath(v3, a1);
cost = 1;
if ( !chk_access(staktop, 0x40u, 1) )
v2 = dotpath;
return v2;
}
}
else
{
v5 = 1;
}
v7 = 1;
if ( v3 )
{
while ( 1 )
{
v8 = catpath(v3, a1);
++cost;
v3 = v8;
v9 = chk_access(staktop, 0x40u, 1);
if ( !v9 )
break;
if ( v7 < v9 )
v7 = v9;
++v5;
if ( !v3 )
return (unsigned int)-v7;
}
}
else
{
v5 = -1;
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
unsigned int v2; // ebx
__int64 v3; // rbp
int v4; // er13
int v5; // er13
int v7; // ebx
__int64 v8; // rax
int v9; // eax

v2 = a2;
cost = 0;
v3 = getpath(a1);
if ( a2 )
{
v4 = dotpath - 1;
if ( dotpath == 1 )
{
v5 = 1;
}
else
{
do
{
v3 = nextpath(v3);
--v4;
}
while ( v4 );
v5 = dotpath;
}
if ( a2 > v5 )
{
catpath(v3, a1);
cost = 1;
if ( !func8(staktop, 0x40u, 1) )
v2 = dotpath;
return v2;
}
}
else
{
v5 = 1;
}
v7 = 1;
if ( v3 )
{
while ( 1 )
{
v8 = catpath(v3, a1);
++cost;
v3 = v8;
v9 = func8(staktop, 0x40u, 1);
if ( !v9 )
break;
if ( v7 < v9 )
v7 = v9;
++v5;
if ( !v3 )
return (unsigned int)-v7;
}
}
else
{
v5 = -1;
}
return (unsigned int)v5;
}

original_code:
int
findpath(register unsigned char *name, int oldpath)
{
 register unsigned char *path;
 register int count = 1;
 unsigned char *p;
 int ok = 1;
 int e_code = 1;
 cost = 0;
 path = getpath(name);
 if (oldpath)
 {
  count = dotpath;
  while (--count)
   path = nextpath(path);
  if (oldpath > dotpath)
  {
   catpath(path, name);
   p = (staktop);
   cost = 1;
   if ((ok = chk_access(p, 0100, 1)) == 0)
    return(dotpath);
   else
    return(oldpath);
  }
  else
   count = dotpath;
 }
 while (path)
 {
  path = catpath(path, name);
  cost++;
  p = (staktop);
  if ((ok = chk_access(p, 0100, 1)) == 0)
   break;
  else
   e_code = ((e_code) > (ok)?(e_code):(ok));
  count++;
 }
 return(ok ? -e_code : count);
}

canonical_original_code:
int findpath(unsigned char *name, int oldpath)
{
 register unsigned char *path;
 register int count = 1;
 unsigned char *p;
 int ok = 1;
 int e_code = 1;
 cost = 0;
 path = getpath(name);
 if (oldpath)
 {
  count = dotpath;
  while (--count)
   path = nextpath(path);
  if (oldpath > dotpath)
  {
   catpath(path, name);
   p = (staktop);
   cost = 1;
   if ((ok = chk_access(p, 0100, 1)) == 0)
    return(dotpath);
   else
    return(oldpath);
  }
  else
   count = dotpath;
 }
 while (path)
 {
  path = catpath(path, name);
  cost++;
  p = (staktop);
  if ((ok = chk_access(p, 0100, 1)) == 0)
   break;
  else
   e_code = ((e_code) > (ok)?(e_code):(ok));
  count++;
 }
 return(ok ? -e_code : count);
}

variable_types: oldpath int

variable_types: count int

variable_types:
p
unsigned char *

variable_types: ok int


pathlook

decompiled_code:
__int64 __fastcall pathlook(__int64 a1, int a2, __int64 *a3)
{
char v4; // r12
int v5; // er8
__int64 result; // rax
__int64 v7; // rax
__int64 v8; // rbx
void *v9; // rsi
int v10; // er13
int v11; // esi
__int64 v12; // rdx
__int64 v13; // rdx

v4 = a2;
v5 = any(47LL, a1);
result = 1024LL;
if ( v5 )
return result;
v7 = hfind(a1);
v8 = v7;
if ( !v7 )
{
LABEL_10:
v9 = &commands;
if ( (unsigned int)syslook(a1, &commands, no_commands) )
{
v10 = 1;
LABEL_14:
if ( !v8 )
{
make(a1);
v8 = henter(a1, v9, v13);
}
LABEL_16:
result = *(unsigned __int16 *)(v8 + 8);
if ( !(_WORD)result )
{
result = (unsigned int)v10;
if ( dotpath <= v10 )
{
v12 = qword_980;
BYTE1(result) = BYTE1(v10) | 8;
*(_WORD *)(v8 + 8) = result;
*(_QWORD *)(v8 + 16) = v12;
qword_980 = v8;
}
else
{
BYTE1(result) = BYTE1(v10) | 4;
*(_WORD *)(v8 + 8) = result;
}
}
*(_BYTE *)(v8 + 11) += cost;
*(_BYTE *)(v8 + 10) = v4;
return result;
}
if ( !a3 || !(unsigned int)argpath(a3) )
{
v9 = 0LL;
v10 = findpath(a1, 0);
if ( v10 > 0 )
goto LABEL_14;
return (unsigned int)-v10;
}
return 4096LL;
}
result = *(unsigned __int16 *)(v7 + 8);
if ( (result & 0x300) == 0 )
{
if ( a3 )
{
if ( (unsigned int)argpath(a3) )
return 4096LL;
result = *(unsigned __int16 *)(v8 + 8);
}
if ( (result & 0x8800) == 34816 )
{
v11 = dotpath;
if ( !multrel )
{
LODWORD(result) = (unsigned __int8)result;
if ( dotpath < (unsigned __int8)result )
v11 = result;
}
*(_WORD *)(v8 + 8) = 0;
v10 = findpath(a1, v11);
if ( v10 > 0 )
goto LABEL_16;
return (unsigned int)-v10;
}
if ( (result & 0xC00) == 0 )
{
*(_BYTE *)(v8 + 11) = 0;
*(_WORD *)(v8 + 8) = 0;
goto LABEL_10;
}
}
if ( a2 )
++*(_BYTE *)(v8 + 10);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, __int64 *a3)
{
char v4; // r12
int v5; // er8
__int64 result; // rax
__int64 v7; // rax
__int64 v8; // rbx
void *v9; // rsi
int v10; // er13
int v11; // esi
__int64 v12; // rdx
__int64 v13; // rdx

v4 = a2;
v5 = any(47LL, a1);
result = 1024LL;
if ( v5 )
return result;
v7 = hfind(a1);
v8 = v7;
if ( !v7 )
{
LABEL_10:
v9 = &commands;
if ( (unsigned int)syslook(a1, &commands, no_commands) )
{
v10 = 1;
LABEL_14:
if ( !v8 )
{
make(a1);
v8 = henter(a1, v9, v13);
}
LABEL_16:
result = *(unsigned __int16 *)(v8 + 8);
if ( !(_WORD)result )
{
result = (unsigned int)v10;
if ( dotpath <= v10 )
{
v12 = qword_980;
BYTE1(result) = BYTE1(v10) | 8;
*(_WORD *)(v8 + 8) = result;
*(_QWORD *)(v8 + 16) = v12;
qword_980 = v8;
}
else
{
BYTE1(result) = BYTE1(v10) | 4;
*(_WORD *)(v8 + 8) = result;
}
}
*(_BYTE *)(v8 + 11) += cost;
*(_BYTE *)(v8 + 10) = v4;
return result;
}
if ( !a3 || !(unsigned int)func1(a3) )
{
v9 = 0LL;
v10 = func9(a1, 0);
if ( v10 > 0 )
goto LABEL_14;
return (unsigned int)-v10;
}
return 4096LL;
}
result = *(unsigned __int16 *)(v7 + 8);
if ( (result & 0x300) == 0 )
{
if ( a3 )
{
if ( (unsigned int)func1(a3) )
return 4096LL;
result = *(unsigned __int16 *)(v8 + 8);
}
if ( (result & 0x8800) == 34816 )
{
v11 = dotpath;
if ( !multrel )
{
LODWORD(result) = (unsigned __int8)result;
if ( dotpath < (unsigned __int8)result )
v11 = result;
}
*(_WORD *)(v8 + 8) = 0;
v10 = func9(a1, v11);
if ( v10 > 0 )
goto LABEL_16;
return (unsigned int)-v10;
}
if ( (result & 0xC00) == 0 )
{
*(_BYTE *)(v8 + 11) = 0;
*(_WORD *)(v8 + 8) = 0;
goto LABEL_10;
}
}
if ( a2 )
++*(_BYTE *)(v8 + 10);
return result;
}

original_code:
short
pathlook(unsigned char *com, int flg, register struct argnod *arg)
{
 register unsigned char *name = com;
 register ENTRY *h;
 ENTRY hentry;
 int count = 0;
 int i;
 int pathset = 0;
 int oldpath = 0;
 hentry.data = 0;
 if (any('/', name))
  return(0x0400);
 h = hfind(name);
 if (h)
 {
  if (h->data & (0x0100 | 0x0200))
  {
   if (flg)
    h->hits++;
   return(h->data);
  }
  if (arg && (pathset = argpath(arg)))
   return(0x1000);
  if ((h->data & 0x8800) == 0x8800)
  {
   if (multrel == 0 && (h->data & 0x00FF) > dotpath)
    oldpath = (h->data & 0x00FF);
   else
    oldpath = dotpath;
   h->data = 0;
   goto pathsrch;
  }
  if (h->data & (0x0400 | 0x0800))
  {
   if (flg)
    h->hits++;
   return(h->data);
  }
  h->data = 0;
  h->cost = 0;
 }
 if (i = syslook(name, commands, no_commands))
 {
  hentry.data = (0x0100 | i);
  count = 1;
 }
 else
 {
  if (arg && (pathset = argpath(arg)))
   return(0x1000);
pathsrch:
   count = findpath(name, oldpath);
 }
 if (count > 0)
 {
  if (h == 0)
  {
   hentry.cost = 0;
   hentry.key = make(name);
   h = henter(hentry);
  }
  if (h->data == 0)
  {
   if (count < dotpath)
    h->data = 0x0400 | count;
   else
   {
    h->data = 0x0800 | count;
    h->next = relcmd.next;
    relcmd.next = h;
   }
  }
  h->hits = flg;
  h->cost += cost;
  return(h->data);
 }
 else
 {
  return(-count);
 }
}

canonical_original_code:
short pathlook(unsigned char *com, int flg, struct argnod *arg)
{
 register unsigned char *name = com;
 register struct entry *h;
 struct entry hentry;
 int count = 0;
 int i;
 int pathset = 0;
 int oldpath = 0;
 hentry.data = 0;
 if (any('/', name))
  return(0x0400);
 h = hfind(name);
 if (h)
 {
  if (h->data & (0x0100 | 0x0200))
  {
   if (flg)
    h->hits++;
   return(h->data);
  }
  if (arg && (pathset = argpath(arg)))
   return(0x1000);
  if ((h->data & 0x8800) == 0x8800)
  {
   if (multrel == 0 && (h->data & 0x00FF) > dotpath)
    oldpath = (h->data & 0x00FF);
   else
    oldpath = dotpath;
   h->data = 0;
   goto pathsrch;
  }
  if (h->data & (0x0400 | 0x0800))
  {
   if (flg)
    h->hits++;
   return(h->data);
  }
  h->data = 0;
  h->cost = 0;
 }
 if (i = syslook(name, commands, no_commands))
 {
  hentry.data = (0x0100 | i);
  count = 1;
 }
 else
 {
  if (arg && (pathset = argpath(arg)))
   return(0x1000);
pathsrch:
   count = findpath(name, oldpath);
 }
 if (count > 0)
 {
  if (h == 0)
  {
   hentry.cost = 0;
   hentry.key = make(name);
   h = henter(hentry);
  }
  if (h->data == 0)
  {
   if (count < dotpath)
    h->data = 0x0400 | count;
   else
   {
    h->data = 0x0800 | count;
    h->next = relcmd.next;
    relcmd.next = h;
   }
  }
  h->hits = flg;
  h->cost += cost;
  return(h->data);
 }
 else
 {
  return(-count);
 }
}

variable_types:
com
unsigned char *

variable_types: flg int

variable_types: struct argnod { struct argnod *argnxt; unsigned char argval[1]; } *

variable_types: struct entry { unsigned char *key; short data; unsigned char hits; unsigned char cost; struct entry *next; } *

variable_types: pathset int

return_type: short


decompiled_code:
__int64 __fastcall hash_cmd(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 result; // rax
_QWORD *v5; // rax
_QWORD *v6; // rdx

if ( (unsigned int)any(47LL, a1) )
return 1024LL;
v2 = hfind(a1);
v3 = v2;
if ( v2 )
{
result = *(unsigned __int16 *)(v2 + 8);
if ( (result & 0x300) != 0 )
return result;
if ( (result & 0x800) != 0 )
{
v5 = &relcmd;
do
{
v6 = v5;
v5 = (_QWORD *)v5[2];
}
while ( v5 != (_QWORD *)v3 );
v6[2] = *(_QWORD *)(v3 + 16);
}
zapentry(v3);
}
return pathlook(a1, 0, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rdi
__int64 result; // rax
_QWORD *v5; // rax
_QWORD *v6; // rdx

if ( (unsigned int)any(47LL, a1) )
return 1024LL;
v2 = hfind(a1);
v3 = v2;
if ( v2 )
{
result = *(unsigned __int16 *)(v2 + 8);
if ( (result & 0x300) != 0 )
return result;
if ( (result & 0x800) != 0 )
{
v5 = &relcmd;
do
{
v6 = v5;
v5 = (_QWORD *)v5[2];
}
while ( v5 != (_QWORD *)v3 );
v6[2] = *(_QWORD *)(v3 + 16);
}
func0(v3);
}
return func10(a1, 0, 0LL);
}

original_code:
short
hash_cmd(unsigned char *name)
{
 ENTRY *h;
 if (any('/', name))
  return(0x0400);
 h = hfind(name);
 if (h)
 {
  if (h->data & (0x0100 | 0x0200))
   return(h->data);
  else if ((h->data & 0x0800) == 0x0800)
  {
   ENTRY *ptr = &relcmd;
   while(ptr-> next != h)
    ptr = ptr->next;
   ptr->next = h->next;
  }
  zapentry(h);
 }
 return(pathlook(name, 0, 0));
}

canonical_original_code:
short hash_cmd(unsigned char *name)
{
 struct entry *h;
 if (any('/', name))
  return(0x0400);
 h = hfind(name);
 if (h)
 {
  if (h->data & (0x0100 | 0x0200))
   return(h->data);
  else if ((h->data & 0x0800) == 0x0800)
  {
   struct entry *ptr = &relcmd;
   while(ptr-> next != h)
    ptr = ptr->next;
   ptr->next = h->next;
  }
  zapentry(h);
 }
 return(pathlook(name, 0, 0));
}

variable_types:
name
unsigned char *


decompiled_code:
__int64 __fastcall pr_path(__int64 a1, int a2)
{
__int64 v3; // rdi
int v4; // ebx

v3 = getpath(a1);
v4 = a2 - 1;
if ( a2 != 1 )
{
while ( v3 )
{
v3 = nextpath(v3);
if ( !--v4 )
goto LABEL_6;
}
v3 = 0LL;
}
LABEL_6:
catpath(v3, a1);
return prs_buff(staktop);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
__int64 v3; // rdi
int v4; // ebx

v3 = getpath(a1);
v4 = a2 - 1;
if ( a2 != 1 )
{
while ( v3 )
{
v3 = nextpath(v3);
if ( !--v4 )
goto LABEL_6;
}
v3 = 0LL;
}
LABEL_6:
catpath(v3, a1);
return prs_buff(staktop);
}

original_code:
void
pr_path(register unsigned char *name, int count)
{
 register unsigned char *path;
 path = getpath(name);
 while (--count && path)
  path = nextpath(path);
 catpath(path, name);
 prs_buff((staktop));
}

canonical_original_code:
void pr_path(unsigned char *name, int count)
{
 register unsigned char *path;
 path = getpath(name);
 while (--count && path)
  path = nextpath(path);
 catpath(path, name);
 prs_buff((staktop));
}

variable_types:
path
unsigned char *


hashout

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

if ( (trapnote & 4) != 0 )
{
v2 = exitval;
if ( !exitval )
v2 = 2000LL;
exitsh(v2);
}
result = *(unsigned __int16 *)(a1 + 8);
if ( (result & 0x1F00) != 0 && (result & 0x300) == 0 )
{
prn_buff(*(unsigned __int8 *)(a1 + 10));
if ( (*(_BYTE *)(a1 + 9) & 8) != 0 )
prc_buff(42LL);
prc_buff(9LL);
prn_buff(*(unsigned __int8 *)(a1 + 11));
prc_buff(9LL);
pr_path(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8));
result = prc_buff(10LL);
}
return result;
}

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

if ( (trapnote & 4) != 0 )
{
v2 = exitval;
if ( !exitval )
v2 = 2000LL;
exitsh(v2);
}
result = *(unsigned __int16 *)(a1 + 8);
if ( (result & 0x1F00) != 0 && (result & 0x300) == 0 )
{
prn_buff(*(unsigned __int8 *)(a1 + 10));
if ( (*(_BYTE *)(a1 + 9) & 8) != 0 )
prc_buff(42LL);
prc_buff(9LL);
prn_buff(*(unsigned __int8 *)(a1 + 11));
prc_buff(9LL);
func12(*(_QWORD *)a1, *(unsigned __int8 *)(a1 + 8));
result = prc_buff(10LL);
}
return result;
}

original_code:
static void
hashout(ENTRY *h)
{
 if (trapnote & 4) exitsh(exitval ? exitval : 2000);
 if ((h->data & 0x1F00) == 0x0000)
  return;
 if (h->data & (0x0100 | 0x0200))
  return;
 prn_buff(h->hits);
 if (h->data & 0x0800)
  prc_buff('*');
 prc_buff('\t');
 prn_buff(h->cost);
 prc_buff('\t');
 pr_path(h->key, (h->data & 0x00FF));
 prc_buff('\n');
}

canonical_original_code:
static void hashout(struct entry *h)
{
 if (trapnote & 4) exitsh(exitval ? exitval : 2000);
 if ((h->data & 0x1F00) == 0x0000)
  return;
 if (h->data & (0x0100 | 0x0200))
  return;
 prn_buff(h->hits);
 if (h->data & 0x0800)
  prc_buff('*');
 prc_buff('\t');
 prn_buff(h->cost);
 prc_buff('\t');
 pr_path(h->key, (h->data & 0x00FF));
 prc_buff('\n');
}


decompiled_code:
__int64 __fastcall what_is_path(__int64 a1)
{
__int64 v1; // rbx
__int16 v2; // dx
__int16 v3; // bx
__int16 v4; // ax
__int64 v5; // rbx
int v7; // er13
__int16 v8; // ax

v1 = hfind(a1);
prs_buff(a1);
if ( !v1 )
goto LABEL_11;
v2 = *(_WORD *)(v1 + 8);
v3 = (unsigned __int8)v2;
v4 = v2 & 0x1F00;
if ( (v2 & 0x1F00) == 1024 )
{
LABEL_9:
prs_buff(" is hashed (");
pr_path(a1, v3);
prs_buff(")\n");
return 0LL;
}
if ( (v2 & 0x1F00u) > 0x400 )
{
if ( v4 != 2048 )
goto LABEL_11;
if ( (v2 & 0x8800) == 34816 )
{
v8 = pathlook(a1, 0, 0LL);
v3 = (unsigned __int8)v8;
if ( (v8 & 0x1F00) == 0 )
goto LABEL_15;
}
goto LABEL_9;
}
if ( v4 == 256 )
{
LABEL_10:
prs_buff(" is a shell builtin\n");
return 0LL;
}
if ( v4 == 512 )
{
v5 = lookup(a1);
prs_buff(" is a function\n");
prs_buff(a1);
prs_buff("(){\n");
prf(*(_QWORD *)(v5 + 32));
prs_buff("\n}\n");
return 0LL;
}
LABEL_11:
if ( (unsigned int)syslook(a1, &commands, no_commands) )
goto LABEL_10;
v7 = findpath(a1, 0);
if ( v7 > 0 )
{
prs_buff(" is ");
pr_path(a1, v7);
prc_buff(10LL);
return 0LL;
}
LABEL_15:
prs_buff(" not found\n");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 v1; // rbx
__int16 v2; // dx
__int16 v3; // bx
__int16 v4; // ax
__int64 v5; // rbx
int v7; // er13
__int16 v8; // ax

v1 = hfind(a1);
prs_buff(a1);
if ( !v1 )
goto LABEL_11;
v2 = *(_WORD *)(v1 + 8);
v3 = (unsigned __int8)v2;
v4 = v2 & 0x1F00;
if ( (v2 & 0x1F00) == 1024 )
{
LABEL_9:
prs_buff(" is hashed (");
func12(a1, v3);
prs_buff(")\n");
return 0LL;
}
if ( (v2 & 0x1F00u) > 0x400 )
{
if ( v4 != 2048 )
goto LABEL_11;
if ( (v2 & 0x8800) == 34816 )
{
v8 = func10(a1, 0, 0LL);
v3 = (unsigned __int8)v8;
if ( (v8 & 0x1F00) == 0 )
goto LABEL_15;
}
goto LABEL_9;
}
if ( v4 == 256 )
{
LABEL_10:
prs_buff(" is a shell builtin\n");
return 0LL;
}
if ( v4 == 512 )
{
v5 = lookup(a1);
prs_buff(" is a function\n");
prs_buff(a1);
prs_buff("(){\n");
prf(*(_QWORD *)(v5 + 32));
prs_buff("\n}\n");
return 0LL;
}
LABEL_11:
if ( (unsigned int)syslook(a1, &commands, no_commands) )
goto LABEL_10;
v7 = func9(a1, 0);
if ( v7 > 0 )
{
prs_buff(" is ");
func12(a1, v7);
prc_buff(10LL);
return 0LL;
}
LABEL_15:
prs_buff(" not found\n");
return 1LL;
}

original_code:
int
what_is_path(register unsigned char *name)
{
 register ENTRY *h;
 int cnt;
 short hashval;
 h = hfind(name);
 prs_buff(name);
 if (h)
 {
  hashval = (h->data & 0x00FF);
  switch ((h->data & 0x1F00))
  {
   case 0x0100:
    prs_buff(" is a shell builtin\n");
    return (0);
   case 0x0200:
   {
    struct namnod *n = lookup(name);
    prs_buff(" is a function\n");
    prs_buff(name);
    prs_buff("(){\n");
    prf((struct trenod *)n->namenv);
    prs_buff("\n}\n");
    return (0);
   }
   case 0x0800:
   {
    short hash;
    if ((h->data & 0x8800) == 0x8800)
    {
     hash = pathlook(name, 0, 0);
     if ((hash & 0x1F00) == 0x0000)
     {
      prs_buff(" not found\n");
      return (1);
     }
     else
      hashval = (hash & 0x00FF);
    }
   }
   case 0x0400:
    prs_buff(" is hashed (");
    pr_path(name, hashval);
    prs_buff(")\n");
    return (0);
  }
 }
 if (syslook(name, commands, no_commands))
 {
  prs_buff(" is a shell builtin\n");
  return (0);
 }
 if ((cnt = findpath(name, 0)) > 0)
 {
  prs_buff(" is ");
  pr_path(name, cnt);
  prc_buff('\n');
  return (0);
 }
 else
 {
  prs_buff(" not found\n");
  return (1);
 }
}

canonical_original_code:
int what_is_path(unsigned char *name)
{
 register struct entry *h;
 int cnt;
 short hashval;
 h = hfind(name);
 prs_buff(name);
 if (h)
 {
  hashval = (h->data & 0x00FF);
  switch ((h->data & 0x1F00))
  {
   case 0x0100:
    prs_buff(" is a shell builtin\n");
    return (0);
   case 0x0200:
   {
    struct namnod *n = lookup(name);
    prs_buff(" is a function\n");
    prs_buff(name);
    prs_buff("(){\n");
    prf((struct trenod *)n->namenv);
    prs_buff("\n}\n");
    return (0);
   }
   case 0x0800:
   {
    short hash;
    if ((h->data & 0x8800) == 0x8800)
    {
     hash = pathlook(name, 0, 0);
     if ((hash & 0x1F00) == 0x0000)
     {
      prs_buff(" not found\n");
      return (1);
     }
     else
      hashval = (hash & 0x00FF);
    }
   }
   case 0x0400:
    prs_buff(" is hashed (");
    pr_path(name, hashval);
    prs_buff(")\n");
    return (0);
  }
 }
 if (syslook(name, commands, no_commands))
 {
  prs_buff(" is a shell builtin\n");
  return (0);
 }
 if ((cnt = findpath(name, 0)) > 0)
 {
  prs_buff(" is ");
  pr_path(name, cnt);
  prc_buff('\n');
  return (0);
 }
 else
 {
  prs_buff(" not found\n");
  return (1);
 }
}

variable_types: cnt int

variable_types: hashval short

variable_types: struct namnod { struct namnod *namlft; struct namnod *namrgt; unsigned char *namid; unsigned char *namval; unsigned char *namenv; int namflg; } *

variable_types: hash short


locstak

decompiled_code:
__int64 __fastcall locstak(__int64 a1, int a2)
{
const char *v3; // rdx

if ( (__int64)(brkend - stakbot) > 511 )
return stakbot;
if ( setbrk(brkincr) == -1 )
error((int)&nostack, a2, v3);
if ( brkincr <= 0x7FFu )
brkincr += 256;
return stakbot;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
const char *v3; // rdx

if ( (__int64)(brkend - stakbot) > 511 )
return stakbot;
if ( setbrk(brkincr) == -1 )
error((int)&nostack, a2, v3);
if ( brkincr <= 0x7FFu )
brkincr += 256;
return stakbot;
}

original_code:
unsigned char *
locstak(void)
{
 if (brkend - stakbot < 01000)
 {
  if (setbrk(brkincr) == (unsigned char *)-1)
   error(nostack);
  if (brkincr < 04000)
   brkincr += 256;
 }
 return(stakbot);
}

canonical_original_code:
unsigned char *locstak()
{
 if (brkend - stakbot < 01000)
 {
  if (setbrk(brkincr) == (unsigned char *)-1)
   error(nostack);
  if (brkincr < 04000)
   brkincr += 256;
 }
 return(stakbot);
}

return_type: unsigned char *


growstak

decompiled_code:
void __fastcall growstak(__int64 a1, int a2)
{
unsigned __int64 v2; // rdi
const char *v3; // rdx

v2 = (a1 - brkend + 8) & 0xFFFFFFFFFFFFFFF8LL;
if ( brkincr >= v2 )
v2 = brkincr;
if ( setbrk(v2) == -1 )
error((int)&nospace, a2, v3);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2)
{
unsigned __int64 v2; // rdi
const char *v3; // rdx

v2 = (a1 - brkend + 8) & 0xFFFFFFFFFFFFFFF8LL;
if ( brkincr >= v2 )
v2 = brkincr;
if ( setbrk(v2) == -1 )
error((int)&nospace, a2, v3);
}

original_code:
void
growstak(unsigned char *newtop)
{
 register uintptr_t incr;
 incr = (uintptr_t)(((intptr_t)(((char *)(newtop - brkend + 1)+(sizeof (char *)))-1))&~(((sizeof (char *)))-1));
 if (brkincr > incr)
  incr = brkincr;
 if (setbrk(incr) == (unsigned char *)-1)
  error(nospace);
}

canonical_original_code:
void growstak(unsigned char *newtop)
{
 register unsigned long incr;
 incr = (unsigned long)(((long)(((char *)(newtop - brkend + 1)+(sizeof (char *)))-1))&~(((sizeof (char *)))-1));
 if (brkincr > incr)
  incr = brkincr;
 if (setbrk(incr) == (unsigned char *)-1)
  error(nospace);
}

variable_types:
newtop
unsigned char *

variable_types:
incr
unsigned long


getstak

decompiled_code:
__int64 __fastcall getstak(int a1, int a2)
{
__int64 v2; // r12
unsigned __int64 v3; // rdi

v2 = stakbot;
v3 = stakbot + (int)((a1 + 7) & 0xFFFFFFF8);
stakbot = v3;
staktop = v3;
if ( v3 >= brkend )
growstak(v3, a2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 v2; // r12
unsigned __int64 v3; // rdi

v2 = stakbot;
v3 = stakbot + (int)((a1 + 7) & 0xFFFFFFF8);
stakbot = v3;
staktop = v3;
if ( v3 >= brkend )
func1(v3, a2);
return v2;
}

original_code:
unsigned char *
getstak (
    intptr_t asize
)
{
 register unsigned char *oldstak;
 register int size;
 size = (((intptr_t)(((char *)((intptr_t)asize)+(sizeof (char *)))-1))&~(((sizeof (char *)))-1));
 oldstak = stakbot;
 staktop = stakbot += size;
 if (staktop >= brkend)
  growstak(staktop);
 return(oldstak);
}

canonical_original_code:
unsigned char *getstak(long asize)
{
 register unsigned char *oldstak;
 register int size;
 size = (((long)(((char *)((long)asize)+(sizeof (char *)))-1))&~(((sizeof (char *)))-1));
 oldstak = stakbot;
 staktop = stakbot += size;
 if (staktop >= brkend)
  growstak(staktop);
 return(oldstak);
}

variable_types: asize long

variable_types:
oldstak
unsigned char *

variable_types: size int