savstak

decompiled_code:
__int64 savstak()
{
return stakbot;
}

canonical_decompiled_code:
__int64 func3()
{
return stakbot;
}

original_code:
unsigned char *
savstak(void)
{
 ;
 return(stakbot);
}

canonical_original_code:
unsigned char *savstak()
{
 ;
 return(stakbot);
}


endstak

repo: mutoso-mirrors/heirloom-sh

decompiled_code:
__int64 __fastcall endstak(_BYTE *a1, int a2)
{
__int64 v3; // r12
unsigned __int64 v4; // rdi

if ( brkend <= (unsigned __int64)a1 )
growstak((__int64)a1, a2);
*a1 = 0;
v3 = stakbot;
v4 = (unsigned __int64)(a1 + 8) & 0xFFFFFFFFFFFFFFF8LL;
staktop = (unsigned __int64)(a1 + 8) & 0xFFFFFFFFFFFFFFF8LL;
stakbot = (unsigned __int64)(a1 + 8) & 0xFFFFFFFFFFFFFFF8LL;
if ( v4 >= brkend )
growstak(v4, a2);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1, int a2)
{
__int64 v3; // r12
unsigned __int64 v4; // rdi

if ( brkend <= (unsigned __int64)a1 )
func1((__int64)a1, a2);
*a1 = 0;
v3 = stakbot;
v4 = (unsigned __int64)(a1 + 8) & 0xFFFFFFFFFFFFFFF8LL;
staktop = (unsigned __int64)(a1 + 8) & 0xFFFFFFFFFFFFFFF8LL;
stakbot = (unsigned __int64)(a1 + 8) & 0xFFFFFFFFFFFFFFF8LL;
if ( v4 >= brkend )
func1(v4, a2);
return v3;
}

original_code:
unsigned char *
endstak (
    register unsigned char *argp
)
{
 register unsigned char *oldstak;
 if (argp >= brkend)
  growstak(argp);
 *argp++ = 0;
 oldstak = stakbot;
 stakbot = staktop = (unsigned char *)(((intptr_t)(((char *)(argp)+(sizeof (char *)))-1))&~(((sizeof (char *)))-1));
 if (staktop >= brkend)
  growstak(staktop);
 return(oldstak);
}

canonical_original_code:
unsigned char *endstak(unsigned char *argp)
{
 register unsigned char *oldstak;
 if (argp >= brkend)
  growstak(argp);
 *argp++ = 0;
 oldstak = stakbot;
 stakbot = staktop = (unsigned char *)(((long)(((char *)(argp)+(sizeof (char *)))-1))&~(((sizeof (char *)))-1));
 if (staktop >= brkend)
  growstak(staktop);
 return(oldstak);
}

variable_types:
argp
unsigned char *

variable_types:
oldstak
unsigned char *

return_type: unsigned char *


tdystak

decompiled_code:
__int64 __fastcall tdystak(unsigned __int64 a1)
{
unsigned __int64 v1; // rax

for ( ; stakbsy > a1; stakbsy = *stakbsy )
sh_free();
v1 = a1;
if ( stakbas >= a1 )
v1 = stakbas;
stakbot = v1;
staktop = v1;
return rmtemp(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 a1)
{
unsigned __int64 v1; // rax

for ( ; stakbsy > a1; stakbsy = *stakbsy )
sh_free();
v1 = a1;
if ( stakbas >= a1 )
v1 = stakbas;
stakbot = v1;
staktop = v1;
return rmtemp(a1);
}

original_code:
void
tdystak (
    register unsigned char *x
)
{
 while ((unsigned char *)stakbsy > x)
 {
  sh_free(stakbsy);
  stakbsy = stakbsy->word;
 }
 staktop = stakbot = ((x) > (stakbas)?(x):(stakbas));
 rmtemp((struct ionod *)x);
}

canonical_original_code:
void tdystak(unsigned char *x)
{
 while ((unsigned char *)stakbsy > x)
 {
  sh_free(stakbsy);
  stakbsy = stakbsy->word;
 }
 staktop = stakbot = ((x) > (stakbas)?(x):(stakbas));
 rmtemp((struct ionod *)x);
}

variable_types:
x
unsigned char *

return_type: void

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


stakchk

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

result = brkend - stakbas;
if ( (__int64)(brkend - stakbas) > 1024 )
result = setbrk(4294966784LL);
return result;
}

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

result = brkend - stakbas;
if ( (__int64)(brkend - stakbas) > 1024 )
result = setbrk(4294966784LL);
return result;
}

original_code:
void
stakchk(void)
{
 if ((brkend - stakbas) > 01000 + 01000)
  setbrk(-01000);
}

canonical_original_code:
void stakchk()
{
 if ((brkend - stakbas) > 01000 + 01000)
  setbrk(-01000);
}


cpystak

decompiled_code:
__int64 __fastcall cpystak(char *a1, int a2)
{
_BYTE *v2; // rax
int v3; // esi
_BYTE *v4; // rax

v2 = (_BYTE *)locstak((__int64)a1, a2);
v3 = (int)v2;
v4 = movstrstak(a1, v2);
return endstak(v4, v3);
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, int a2)
{
_BYTE *v2; // rax
int v3; // esi
_BYTE *v4; // rax

v2 = (_BYTE *)func0((__int64)a1, a2);
v3 = (int)v2;
v4 = movstrstak(a1, v2);
return func4(v4, v3);
}

original_code:
unsigned char *
cpystak(unsigned char *x)
{
 return(endstak(movstrstak(x, locstak())));
}

canonical_original_code:
unsigned char *cpystak(unsigned char *x)
{
 return(endstak(movstrstak(x, locstak())));
}


skipnl

decompiled_code:
__int64 skipnl()
{
while ( 1 )
{
++reserv;
if ( (unsigned int)word() != 10 )
break;
chkpr();
}
return wdval;
}

canonical_decompiled_code:
__int64 func0()
{
while ( 1 )
{
++reserv;
if ( (unsigned int)word() != 10 )
break;
chkpr();
}
return wdval;
}

original_code:
static int
skipnl(void)
{
 while ((reserv++, word() == '\n'))
  chkpr();
 return(wdval);
}

canonical_original_code:
static int skipnl()
{
 while ((reserv++, word() == '\n'))
  chkpr();
 return(wdval);
}

return_type: int


prsym

decompiled_code:
__int64 __fastcall prsym(int a1)
{
int v1; // eax
_DWORD *v2; // rax
int v3; // edx
__int64 result; // rax

if ( (a1 & 0x100) != 0 )
{
v1 = reserved[2];
if ( !v1 || a1 == v1 )
{
v2 = reserved;
}
else
{
v2 = reserved;
do
{
v3 = v2[6];
v2 += 4;
}
while ( v3 != a1 && v3 );
}
result = prs(*(_QWORD *)v2);
}
else if ( a1 == 1024 )
{
result = prs(&endoffile);
}
else if ( (a1 & 0x800) != 0 )
{
prc((unsigned __int8)a1);
result = prc((unsigned __int8)a1);
}
else if ( a1 == 10 )
{
result = prs("newline or ;");
}
else
{
result = prc((unsigned __int8)a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
_DWORD *v2; // rax
int v3; // edx
__int64 result; // rax

if ( (a1 & 0x100) != 0 )
{
v1 = reserved[2];
if ( !v1 || a1 == v1 )
{
v2 = reserved;
}
else
{
v2 = reserved;
do
{
v3 = v2[6];
v2 += 4;
}
while ( v3 != a1 && v3 );
}
result = prs(*(_QWORD *)v2);
}
else if ( a1 == 1024 )
{
result = prs(&endoffile);
}
else if ( (a1 & 0x800) != 0 )
{
prc((unsigned __int8)a1);
result = prc((unsigned __int8)a1);
}
else if ( a1 == 10 )
{
result = prs("newline or ;");
}
else
{
result = prc((unsigned __int8)a1);
}
return result;
}

original_code:
static void
prsym(int sym)
{
 if (sym & 0400)
 {
  register const struct sysnod *sp = reserved;
  while (sp->sysval && sp->sysval != sym)
   sp++;
  prs(sp->sysnam);
 }
 else if (sym == 02000)
  prs(endoffile);
 else
 {
  if (sym & 04000)
   prc(sym);
  if (sym == '\n')
   prs("newline or ;");
  else
   prc(sym);
 }
}

canonical_original_code:
static void prsym(int sym)
{
 if (sym & 0400)
 {
  register struct sysnod *sp = reserved;
  while (sp->sysval && sp->sysval != sym)
   sp++;
  prs(sp->sysnam);
 }
 else if (sym == 02000)
  prs(endoffile);
 else
 {
  if (sym & 04000)
   prc(sym);
  if (sym == '\n')
   prs("newline or ;");
  else
   prc(sym);
 }
}

variable_types: sym int

variable_types: struct sysnod { char *sysnam; int sysval; } *


synbad

decompiled_code:
__int64 synbad()
{
prp();
prs(&synmsg);
if ( (flags & 0x20) == 0 )
{
prs(&atline);
prn(*(unsigned int *)(standin + 4LL));
}
prs(&colon);
prc(96LL);
if ( wdval )
prsym(wdval);
else
prs_cntl(wdarg + 8LL);
prc(39LL);
prs(&unexpected);
prc(10LL);
return exitsh(2LL);
}

canonical_decompiled_code:
__int64 func2()
{
prp();
prs(&synmsg);
if ( (flags & 0x20) == 0 )
{
prs(&atline);
prn(*(unsigned int *)(standin + 4LL));
}
prs(&colon);
prc(96LL);
if ( wdval )
func1(wdval);
else
prs_cntl(wdarg + 8LL);
prc(39LL);
prs(&unexpected);
prc(10LL);
return exitsh(2LL);
}

original_code:
static void
synbad(void)
{
 prp();
 prs(synmsg);
 if ((flags & 040) == 0)
 {
  prs(atline);
  prn(standin->flin);
 }
 prs(colon);
 prc('`');
 if (wdval)
  prsym(wdval);
 else
  prs_cntl(wdarg->argval);
 prc('\'');
 prs(unexpected);
 prc('\n');
 exitsh(2);
}

canonical_original_code:
static void synbad()
{
 prp();
 prs(synmsg);
 if ((flags & 040) == 0)
 {
  prs(atline);
  prn(standin->flin);
 }
 prs(colon);
 prc('`');
 if (wdval)
  prsym(wdval);
 else
  prs_cntl(wdarg->argval);
 prc('\'');
 prs(unexpected);
 prc('\n');
 exitsh(2);
}


chkword

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

result = word();
if ( (_DWORD)result )
result = synbad();
return result;
}

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

result = word();
if ( (_DWORD)result )
result = func2();
return result;
}

original_code:
static void
chkword(void)
{
 if (word())
  synbad();
}

canonical_original_code:
static void chkword()
{
 if (word())
  synbad();
}


chksym

decompiled_code:
__int64 __fastcall chksym(unsigned int a1)
{
__int64 result; // rax

result = a1 & wdval;
if ( (result & 0x100) == 0 )
result = a1;
if ( wdval != (_DWORD)result )
result = synbad();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 result; // rax

result = a1 & wdval;
if ( (result & 0x100) == 0 )
result = a1;
if ( wdval != (_DWORD)result )
result = func2();
return result;
}

original_code:
static void
chksym(int sym)
{
 register int x = sym & wdval;
 if (((x & 0400) ? x : sym) != wdval)
  synbad();
}

variable_types: x int


getstor

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

if ( fndef )
result = alloc();
else
result = getstak();
return result;
}

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

if ( fndef )
result = alloc();
else
result = getstak();
return result;
}

original_code:
unsigned char *
getstor(int asize)
{
 if (fndef)
  return((unsigned char *)alloc(asize));
 else
  return(getstak(asize));
}

canonical_original_code:
unsigned char *getstor(int asize)
{
 if (fndef)
  return((unsigned char *)alloc(asize));
 else
  return(getstak(asize));
}

variable_types: asize int


inout

decompiled_code:
__int64 __fastcall inout(__int64 a1)
{
__int64 v1; // r12
int v2; // ebp
int v3; // eax
int v4; // er13
char v5; // r13
char v6; // r13
__int64 v7; // rbx
__int64 v8; // rax
char v10; // r13

v1 = a1;
v2 = wdnum;
if ( wdval == 2108 )
{
v2 = wdnum | 0x10;
v4 = 16;
goto LABEL_16;
}
if ( wdval > 2108 )
{
if ( wdval != 2110 )
return v1;
if ( !wdnum )
{
v2 = 1;
goto LABEL_10;
}
LABEL_9:
if ( wdval != 2110 )
{
v2 = wdnum | 0x20;
LABEL_4:
v3 = nextwc();
if ( v3 != 38 )
goto LABEL_5;
LABEL_14:
v6 = v2;
LOBYTE(v2) = v2 | 0x80;
v4 = v6 & 0x10;
goto LABEL_16;
}
LABEL_10:
v5 = v2;
v2 |= 0x60u;
v4 = v5 & 0x10;
goto LABEL_16;
}
if ( wdval == 60 )
goto LABEL_4;
if ( wdval != 62 )
return v1;
if ( wdnum )
goto LABEL_9;
v2 = 33;
v3 = nextwc();
if ( v3 == 38 )
goto LABEL_14;
LABEL_5:
if ( v3 == 62 )
{
v10 = v2;
v2 |= 0x100u;
v4 = v10 & 0x10;
}
else
{
peekn = v3 | 0x80000000;
v4 = v2 & 0x10;
}
LABEL_16:
chkword();
v7 = getstor(40LL);
if ( fndef )
*(_QWORD *)(v7 + 8) = make(wdarg + 8LL);
else
*(_QWORD *)(v7 + 8) = wdarg + 8LL;
*(_QWORD *)(v7 + 16) = 0LL;
*(_DWORD *)v7 = v2;
if ( v4 )
{
v8 = iopend;
iopend = v7;
*(_QWORD *)(v7 + 32) = v8;
}
word();
v1 = v7;
*(_QWORD *)(v7 + 24) = inout(a1);
return v1;
}

original_code:
static struct ionod *
inout(struct ionod *lastio)
{
 register int iof;
 register struct ionod *iop;
 register unsigned int c;
 iof = wdnum;
 switch (wdval)
 {
 case (04000|'<'):
  iof |= 16;
  break;
 case (04000|'>'):
 case '>':
  if (wdnum == 0)
   iof |= 1;
  iof |= 32;
  if (wdval == (04000|'>'))
  {
   iof |= 64;
   break;
  }
 case '<':
  if ((c = nextwc()) == '&')
   iof |= 128;
  else if (c == '>')
   iof |= 256;
  else
   peekn = c | 0x80000000;
  break;
 default:
  return(lastio);
 }
 chkword();
 iop = (struct ionod *)getstor(sizeof(struct ionod));
 if (fndef)
  iop->ioname = (char *) make(wdarg->argval);
 else
  iop->ioname = (char *) (wdarg->argval);
 iop->iolink = 0;
 iop->iofile = iof;
 if (iof & 16)
 {
  iop->iolst = iopend;
  iopend = iop;
 }
 word();
 iop->ionxt = inout(lastio);
 return(iop);
}

canonical_original_code:
static struct ionod *inout(struct ionod *lastio)
{
 register int iof;
 register struct ionod *iop;
 register unsigned int c;
 iof = wdnum;
 switch (wdval)
 {
 case (04000|'<'):
  iof |= 16;
  break;
 case (04000|'>'):
 case '>':
  if (wdnum == 0)
   iof |= 1;
  iof |= 32;
  if (wdval == (04000|'>'))
  {
   iof |= 64;
   break;
  }
 case '<':
  if ((c = nextwc()) == '&')
   iof |= 128;
  else if (c == '>')
   iof |= 256;
  else
   peekn = c | 0x80000000;
  break;
 default:
  return(lastio);
 }
 chkword();
 iop = (struct ionod *)getstor(sizeof(struct ionod));
 if (fndef)
  iop->ioname = (char *) make(wdarg->argval);
 else
  iop->ioname = (char *) (wdarg->argval);
 iop->iolink = 0;
 iop->iofile = iof;
 if (iof & 16)
 {
  iop->iolst = iopend;
  iopend = iop;
 }
 word();
 iop->ionxt = inout(lastio);
 return(iop);
}

variable_types:
lastio
struct ionod *

variable_types: iof int

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

variable_types:
c
unsigned int


makelist

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

if ( a2 && a3 )
{
result = getstor(24LL);
*(_DWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
}
else
{
synbad();
result = 0LL;
}
return result;
}

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

if ( a2 && a3 )
{
result = func5(24LL);
*(_DWORD *)result = a1;
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(result + 16) = a3;
}
else
{
func2();
result = 0LL;
}
return result;
}

original_code:
static struct trenod *
makelist(int type, struct trenod *i, struct trenod *r)
{
 register struct lstnod *t = ((void *)0);
 if (i == 0 || r == 0)
  synbad();
 else
 {
  t = (struct lstnod *)getstor(sizeof(struct lstnod));
  t->lsttyp = type;
  t->lstlef = i;
  t->lstrit = r;
 }
 return((struct trenod *)t);
}

canonical_original_code:
static struct trenod *makelist(int type, struct trenod *i, struct trenod *r)
{
 register struct lstnod *t = ((void *)0);
 if (i == 0 || r == 0)
  synbad();
 else
 {
  t = (struct lstnod *)getstor(sizeof(struct lstnod));
  t->lsttyp = type;
  t->lstlef = i;
  t->lstrit = r;
 }
 return((struct trenod *)t);
}

variable_types: type int

variable_types:
i
struct trenod *

variable_types:
r
struct trenod *

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

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

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


makefork

decompiled_code:
__int64 __fastcall makefork(int a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax

v2 = a1;
LOBYTE(v2) = a1 | 0xA0;
result = getstor(24LL);
*(_DWORD *)result = v2;
*(_QWORD *)(result + 16) = a2;
*(_QWORD *)(result + 8) = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, __int64 a2)
{
int v2; // ebx
__int64 result; // rax

v2 = a1;
LOBYTE(v2) = a1 | 0xA0;
result = func5(24LL);
*(_DWORD *)result = v2;
*(_QWORD *)(result + 16) = a2;
*(_QWORD *)(result + 8) = 0LL;
return result;
}

original_code:
struct trenod *
makefork(int flgs, struct trenod *i)
{
 register struct forknod *t;
 t = (struct forknod *)getstor(sizeof(struct forknod));
 t->forktyp = flgs|0x00A0;
 t->forktre = i;
 t->forkio = 0;
 return((struct trenod *)t);
}

canonical_original_code:
struct trenod *makefork(int flgs, struct trenod *i)
{
 register struct forknod *t;
 t = (struct forknod *)getstor(sizeof(struct forknod));
 t->forktyp = flgs|0x00A0;
 t->forktre = i;
 t->forkio = 0;
 return((struct trenod *)t);
}

variable_types: flgs int

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

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

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


cmd

decompiled_code:
__int64 __fastcall cmd(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
int v3; // eax
__int64 v5; // rsi
__int64 v6; // rdx

v2 = list(a2);
v3 = wdval;
if ( wdval != 10 )
{
if ( v2 )
{
if ( wdval == 59 )
{
v6 = cmd((unsigned int)a1, a2 | 2);
if ( !v6 )
return v2;
return makelist(48, v2, v6);
}
if ( wdval != 1024 )
{
if ( wdval != 38 )
goto LABEL_6;
goto LABEL_16;
}
LABEL_11:
if ( (_DWORD)a1 == 10 || !(_DWORD)a1 )
return v2;
LABEL_13:
chksym(a1);
return v2;
}
if ( (a2 & 2) == 0 )
{
((void (*)(void))synbad)();
v3 = wdval;
}
switch ( v3 )
{
case 59:
a1 = (unsigned int)a1;
v5 = a2 | 2;
v6 = cmd((unsigned int)a1, v5);
if ( v6 )
return makelist(48, v2, v6);
goto LABEL_25;
case 1024:
goto LABEL_11;
case 38:
LABEL_24:
((void (*)(void))synbad)();
a1 = (unsigned int)a1;
v2 = 0LL;
v5 = a2 | 2;
v6 = cmd((unsigned int)a1, v5);
if ( v6 )
return makelist(48, v2, v6);
goto LABEL_25;
}
LABEL_6:
if ( !(_DWORD)a1 )
return v2;
goto LABEL_13;
}
if ( (a2 & 1) == 0 )
goto LABEL_6;
wdval = 59;
chkpr();
if ( wdval == 59 )
goto LABEL_17;
if ( wdval == 1024 )
goto LABEL_11;
if ( wdval != 38 )
goto LABEL_6;
if ( !v2 )
goto LABEL_24;
LABEL_16:
v2 = makefork(1024, v2);
LABEL_17:
a1 = (unsigned int)a1;
v5 = a2 | 2;
v6 = cmd((unsigned int)a1, v5);
if ( v6 )
return makelist(48, v2, v6);
if ( !v2 )
{
LABEL_25:
synbad(a1, v5, v6);
return 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int a2)
{
__int64 v2; // r12
int v3; // eax
__int64 v5; // rsi
__int64 v6; // rdx

v2 = func12(a2);
v3 = wdval;
if ( wdval != 10 )
{
if ( v2 )
{
if ( wdval == 59 )
{
v6 = func9((unsigned int)a1, a2 | 2);
if ( !v6 )
return v2;
return func7(48, v2, v6);
}
if ( wdval != 1024 )
{
if ( wdval != 38 )
goto LABEL_6;
goto LABEL_16;
}
LABEL_11:
if ( (_DWORD)a1 == 10 || !(_DWORD)a1 )
return v2;
LABEL_13:
func4(a1);
return v2;
}
if ( (a2 & 2) == 0 )
{
((void (*)(void))synbad)();
v3 = wdval;
}
switch ( v3 )
{
case 59:
a1 = (unsigned int)a1;
v5 = a2 | 2;
v6 = func9((unsigned int)a1, v5);
if ( v6 )
return func7(48, v2, v6);
goto LABEL_25;
case 1024:
goto LABEL_11;
case 38:
LABEL_24:
((void (*)(void))synbad)();
a1 = (unsigned int)a1;
v2 = 0LL;
v5 = a2 | 2;
v6 = func9((unsigned int)a1, v5);
if ( v6 )
return func7(48, v2, v6);
goto LABEL_25;
}
LABEL_6:
if ( !(_DWORD)a1 )
return v2;
goto LABEL_13;
}
if ( (a2 & 1) == 0 )
goto LABEL_6;
wdval = 59;
chkpr();
if ( wdval == 59 )
goto LABEL_17;
if ( wdval == 1024 )
goto LABEL_11;
if ( wdval != 38 )
goto LABEL_6;
if ( !v2 )
goto LABEL_24;
LABEL_16:
v2 = func8(1024, v2);
LABEL_17:
a1 = (unsigned int)a1;
v5 = a2 | 2;
v6 = func9((unsigned int)a1, v5);
if ( v6 )
return func7(48, v2, v6);
if ( !v2 )
{
LABEL_25:
func2(a1, v5, v6);
return 0LL;
}
return v2;
}

original_code:
struct trenod *
cmd(register int sym, int flg)
{
 register struct trenod *i, *e;
 i = list(flg);
 if (wdval == '\n')
 {
  if (flg & 1)
  {
   wdval = ';';
   chkpr();
  }
 }
 else if (i == 0 && (flg & 2) == 0)
  synbad();
 switch (wdval)
 {
 case '&':
  if (i)
   i = makefork(0x0400, i);
  else
   synbad();
 case ';':
  if (e = cmd(sym, flg | 2))
   i = makelist(0x0030, i, e);
  else if (i == 0)
   synbad();
  break;
 case 02000:
  if (sym == '\n')
   break;
 default:
  if (sym)
   chksym(sym);
 }
 return(i);
}

canonical_original_code:
struct trenod *cmd(int sym, int flg)
{
 register struct trenod *i; register struct trenod *e;
 i = list(flg);
 if (wdval == '\n')
 {
  if (flg & 1)
  {
   wdval = ';';
   chkpr();
  }
 }
 else if (i == 0 && (flg & 2) == 0)
  synbad();
 switch (wdval)
 {
 case '&':
  if (i)
   i = makefork(0x0400, i);
  else
   synbad();
 case ';':
  if (e = cmd(sym, flg | 2))
   i = makelist(0x0030, i, e);
  else if (i == 0)
   synbad();
  break;
 case 02000:
  if (sym == '\n')
   break;
 default:
  if (sym)
   chksym(sym);
 }
 return(i);
}

variable_types: flg int

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


term

decompiled_code:
__int64 __fastcall term(char a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

++reserv;
if ( (a1 & 1) != 0 )
skipnl();
else
word();
result = item(0xFFFFFFFFLL, a2);
if ( result && (wdval == 94 || wdval == 124) )
{
v3 = makefork(512, result);
v4 = term(1LL);
v5 = makefork(256, v4);
v6 = makelist(32, v3, v5);
result = makefork(0, v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

++reserv;
if ( (a1 & 1) != 0 )
func0();
else
word();
result = func10(0xFFFFFFFFLL, a2);
if ( result && (wdval == 94 || wdval == 124) )
{
v3 = func8(512, result);
v4 = func11(1LL);
v5 = func8(256, v4);
v6 = func7(32, v3, v5);
result = func8(0, v6);
}
return result;
}

original_code:
static struct trenod *
term(int flg)
{
 register struct trenod *t;
 reserv++;
 if (flg & 1)
  skipnl();
 else
  word();
 if ((t = item((-1))) && (wdval == '^' || wdval == '|'))
 {
  struct trenod *left;
  struct trenod *right;
  left = makefork(0x0200, t);
  right = makefork(0x0100, term(1));
  return(makefork(0, makelist(0x0020, left, right)));
 }
 else
  return(t);
}

canonical_original_code:
static struct trenod *term(int flg)
{
 register struct trenod *t;
 reserv++;
 if (flg & 1)
  skipnl();
 else
  word();
 if ((t = item((-1))) && (wdval == '^' || wdval == '|'))
 {
  struct trenod *left;
  struct trenod *right;
  left = makefork(0x0200, t);
  right = makefork(0x0100, term(1));
  return(makefork(0, makelist(0x0020, left, right)));
 }
 else
  return(t);
}


list

decompiled_code:
__int64 __fastcall list(char a1, __int64 a2)
{
__int64 i; // rbp
__int64 v3; // rax
__int64 v4; // rax

for ( i = term(a1, a2); i; i = makelist(144, i, v3) )
{
while ( wdval == 2086 )
{
v4 = term(1, a2);
a2 = i;
i = makelist(128, i, v4);
if ( !i )
return 0LL;
}
if ( wdval != 2172 )
return i;
v3 = term(1, a2);
a2 = i;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(char a1, __int64 a2)
{
__int64 i; // rbp
__int64 v3; // rax
__int64 v4; // rax

for ( i = func11(a1, a2); i; i = func7(144, i, v3) )
{
while ( wdval == 2086 )
{
v4 = func11(1, a2);
a2 = i;
i = func7(128, i, v4);
if ( !i )
return 0LL;
}
if ( wdval != 2172 )
return i;
v3 = func11(1, a2);
a2 = i;
}
return 0LL;
}

original_code:
static struct trenod *
list(int flg)
{
 register struct trenod *r;
 register int b;
 r = term(flg);
 while (r && ((b = (wdval == (04000|'&'))) || wdval == (04000|'|')))
  r = makelist((b ? 0x0080 : 0x0090), r, term(1));
 return(r);
}

canonical_original_code:
static struct trenod *list(int flg)
{
 register struct trenod *r;
 register int b;
 r = term(flg);
 while (r && ((b = (wdval == (04000|'&'))) || wdval == (04000|'|')))
  r = makelist((b ? 0x0080 : 0x0090), r, term(1));
 return(r);
}

variable_types: b int


initf

decompiled_code:
__int64 __fastcall initf(int a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = standin;
v2 = flags & 0x80;
*standin = a1;
*(_QWORD *)(result + 40) = 0LL;
*(_QWORD *)(result + 32) = 0LL;
*(_QWORD *)(result + 48) = 0LL;
*(_DWORD *)(result + 4) = 1;
*(_BYTE *)(result + 10) = v2 == 0 ? 0x80 : 1;
*(_QWORD *)(result + 24) = result + 64;
*(_QWORD *)(result + 16) = result + 64;
*(_WORD *)(result + 8) = 0;
return result;
}

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

result = standin;
v2 = flags & 0x80;
*standin = a1;
*(_QWORD *)(result + 40) = 0LL;
*(_QWORD *)(result + 32) = 0LL;
*(_QWORD *)(result + 48) = 0LL;
*(_DWORD *)(result + 4) = 1;
*(_BYTE *)(result + 10) = v2 == 0 ? 0x80 : 1;
*(_QWORD *)(result + 24) = result + 64;
*(_QWORD *)(result + 16) = result + 64;
*(_WORD *)(result + 8) = 0;
return result;
}

original_code:
void
initf(int fd)
{
 register struct fileblk *f = standin;
 f->fdes = fd;
 f->fsiz = ((flags & 0200) == 0 ? 128 : 1);
 f->fnxt = f->fend = f->fbuf;
 f->nxtoff = f->endoff = 0;
 f->feval = 0;
 f->flin = 1;
 f->feof = 0;
}

variable_types: fd int

variable_types: struct fileblk { int fdes; unsigned int flin; short feof; unsigned char fsiz; unsigned char *fnxt; unsigned char *fend; long nxtoff; long endoff; unsigned char **feval; struct fileblk *fstak; unsigned char fbuf[128]; } *


estabf

decompiled_code:
_BOOL8 __fastcall estabf(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
int v3; // eax
_BOOL8 result; // rax

v1 = standin;
*(_QWORD *)(standin + 16LL) = a1;
*(_DWORD *)v1 = -1;
v2 = ((__int64 (*)(void))length)();
*(_QWORD *)(v1 + 32) = 0LL;
*(_QWORD *)(v1 + 24) = a1 + v2;
v3 = length(a1);
*(_DWORD *)(v1 + 4) = 1;
*(_QWORD *)(v1 + 40) = v3;
result = a1 == 0;
*(_WORD *)(v1 + 8) = result;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
__int64 v1; // rbx
int v2; // eax
int v3; // eax
_BOOL8 result; // rax

v1 = standin;
*(_QWORD *)(standin + 16LL) = a1;
*(_DWORD *)v1 = -1;
v2 = ((__int64 (*)(void))length)();
*(_QWORD *)(v1 + 32) = 0LL;
*(_QWORD *)(v1 + 24) = a1 + v2;
v3 = length(a1);
*(_DWORD *)(v1 + 4) = 1;
*(_QWORD *)(v1 + 40) = v3;
result = a1 == 0;
*(_WORD *)(v1 + 8) = result;
return result;
}

original_code:
int
estabf(register unsigned char *s)
{
 register struct fileblk *f;
 (f = standin)->fdes = -1;
 f->fend = length(s) + (f->fnxt = s);
 f->nxtoff = 0;
 f->endoff = length(s);
 f->flin = 1;
 return (f->feof = (s == 0));
}

canonical_original_code:
int estabf(unsigned char *s)
{
 register struct fileblk *f;
 (f = standin)->fdes = -1;
 f->fend = length(s) + (f->fnxt = s);
 f->nxtoff = 0;
 f->endoff = length(s);
 f->flin = 1;
 return (f->feof = (s == 0));
}

variable_types:
s
unsigned char *

user_defined_types: struct fileblk { int fdes; unsigned int flin; short feof; unsigned char fsiz; unsigned char *fnxt; unsigned char *fend; long nxtoff; long endoff; unsigned char **feval; struct fileblk *fstak; unsigned char fbuf[128]; }


push

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

v1 = standin;
*(_QWORD *)(a1 + 48) = 0LL;
standin = a1;
*(_QWORD *)(a1 + 56) = v1;
result = 0LL;
*(_WORD *)(a1 + 8) = 0;
return result;
}

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

v1 = standin;
*(_QWORD *)(a1 + 48) = 0LL;
standin = a1;
*(_QWORD *)(a1 + 56) = v1;
result = 0LL;
*(_WORD *)(a1 + 8) = 0;
return result;
}

original_code:
void
push(struct fileblk *af)
{
 register struct fileblk *f;
 (f = af)->fstak = standin;
 f->feof = 0;
 f->feval = 0;
 standin = f;
}


pop

decompiled_code:
__int64 pop()
{
__int64 v0; // rbx
unsigned int v1; // er8
__int64 v2; // rax

v0 = standin;
v1 = 0;
v2 = *(_QWORD *)(standin + 56LL);
if ( v2 )
{
if ( (int)*standin >= 0 )
{
close(*standin);
v2 = *(_QWORD *)(v0 + 56);
}
standin = v2;
v1 = -1;
}
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbx
unsigned int v1; // er8
__int64 v2; // rax

v0 = standin;
v1 = 0;
v2 = *(_QWORD *)(standin + 56LL);
if ( v2 )
{
if ( (int)*standin >= 0 )
{
close(*standin);
v2 = *(_QWORD *)(v0 + 56);
}
standin = v2;
v1 = -1;
}
return v1;
}

original_code:
int
pop(void)
{
 register struct fileblk *f;
 if ((f = standin)->fstak)
 {
  if (f->fdes >= 0)
   close(f->fdes);
  standin = f->fstak;
  return ((-1));
 }else
  return (0);
}

canonical_original_code:
int pop()
{
 register struct fileblk *f;
 if ((f = standin)->fstak)
 {
  if (f->fdes >= 0)
   close(f->fdes);
  standin = f->fstak;
  return ((-1));
 }else
  return (0);
}


pushtemp

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

result = tmpfptr;
*(_DWORD *)a2 = a1;
tmpfptr = a2;
*(_QWORD *)(a2 + 8) = result;
return result;
}

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

result = tmpfptr;
*(_DWORD *)a2 = a1;
tmpfptr = a2;
*(_QWORD *)(a2 + 8) = result;
return result;
}

original_code:
void
pushtemp(int fd, struct tempblk *tb)
{
 tb->fdes = fd;
 tb->fstak = tmpfptr;
 tmpfptr = tb;
}

variable_types: struct tempblk { int fdes; struct tempblk *fstak; } *


poptemp

decompiled_code:
__int64 poptemp()
{
if ( !tmpfptr )
return 0LL;
close(*(_DWORD *)tmpfptr);
tmpfptr = *(_QWORD *)(tmpfptr + 8);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func5()
{
if ( !tmpfptr )
return 0LL;
close(*(_DWORD *)tmpfptr);
tmpfptr = *(_QWORD *)(tmpfptr + 8);
return 0xFFFFFFFFLL;
}

original_code:
int
poptemp(void)
{
 if (tmpfptr){
  close(tmpfptr->fdes);
  tmpfptr = tmpfptr->fstak;
  return ((-1));
 }else
  return (0);
}

canonical_original_code:
int poptemp()
{
 if (tmpfptr){
  close(tmpfptr->fdes);
  tmpfptr = tmpfptr->fstak;
  return ((-1));
 }else
  return (0);
}


chkpipe

decompiled_code:
void __fastcall chkpipe(int *a1, int a2)
{
const char *v2; // rdx

if ( pipe(a1) < 0 || (v2 = (const char *)(unsigned int)*a1, (int)v2 < 0) || a1[1] < 0 )
error((int)&piperr, a2, v2);
}

canonical_decompiled_code:
void __fastcall func6(int *a1, int a2)
{
const char *v2; // rdx

if ( pipe(a1) < 0 || (v2 = (const char *)(unsigned int)*a1, (int)v2 < 0) || a1[1] < 0 )
error((int)&piperr, a2, v2);
}

original_code:
void
chkpipe(int *pv)
{
 if (pipe(pv) < 0 || pv[0] < 0 || pv[1] < 0)
  error(piperr);
}

variable_types:
pv
int *


chkopen

decompiled_code:
int __fastcall chkopen(const char *a1, int a2)
{
int result; // eax
int v3; // [rsp+Ch] [rbp-Ch]

result = open64(a1, a2, 438LL);
if ( result < 0 )
{
v3 = result;
failed(a1, &badopen);
result = v3;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, int a2)
{
int result; // eax
int v3; // [rsp+Ch] [rbp-Ch]

result = open64(a1, a2, 438LL);
if ( result < 0 )
{
v3 = result;
failed(a1, &badopen);
result = v3;
}
return result;
}

original_code:
int
chkopen(const unsigned char *idf, int mode)
{
 register int rc;
 if ((rc = open((const char *)idf, mode, 0666)) < 0)
  failed(idf, badopen);
 return (rc);
}

canonical_original_code:
int chkopen(unsigned char *idf, int mode)
{
 register int rc;
 if ((rc = open((char *)idf, mode, 0666)) < 0)
  failed(idf, badopen);
 return (rc);
}

variable_types:
idf
unsigned char *

variable_types: mode int

variable_types: rc int


renamef

decompiled_code:
void __fastcall renamef(int fd, unsigned int a2)
{
int v2; // er12

if ( fd != a2 )
{
v2 = fcntl64(a2, 1LL, 0LL);
close(a2);
fcntl64((unsigned int)fd, 0LL, a2);
close(fd);
if ( v2 == 1 )
fcntl64(a2, 2LL, 1LL);
if ( !a2 )
ioset |= 1u;
}
}

canonical_decompiled_code:
void __fastcall func8(int fd, unsigned int a2)
{
int v2; // er12

if ( fd != a2 )
{
v2 = fcntl64(a2, 1LL, 0LL);
close(a2);
fcntl64((unsigned int)fd, 0LL, a2);
close(fd);
if ( v2 == 1 )
fcntl64(a2, 2LL, 1LL);
if ( !a2 )
ioset |= 1u;
}
}

original_code:
void
renamef(register int f1, register int f2)
{
 int fs;
 if (f1 != f2)
 {
  fs = fcntl(f2, 1, 0);
  close(f2);
  fcntl(f1, 0, f2);
  close(f1);
  if (fs == 1)
   fcntl(f2, 2, 1);
  if (f2 == 0)
   ioset |= 1;
 }
}

canonical_original_code:
void renamef(int f1, int f2)
{
 int fs;
 if (f1 != f2)
 {
  fs = fcntl(f2, 1, 0);
  close(f2);
  fcntl(f1, 0, f2);
  close(f1);
  if (fs == 1)
   fcntl(f2, 2, 1);
  if (f2 == 0)
   ioset |= 1;
 }
}

variable_types: fs int


create

decompiled_code:
int __fastcall create(const char *a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-Ch]

result = creat64(a1, 0x1B6u);
if ( result < 0 )
{
v2 = result;
failed(a1, &badcreate);
result = v2;
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(const char *a1)
{
int result; // eax
int v2; // [rsp+Ch] [rbp-Ch]

result = creat64(a1, 0x1B6u);
if ( result < 0 )
{
v2 = result;
failed(a1, &badcreate);
result = v2;
}
return result;
}

original_code:
int
create(unsigned char *s)
{
 register int rc;
 if ((rc = creat((char *)s, 0666)) < 0)
  failed(s, badcreate);
 return (rc);
}


tmpfil

decompiled_code:
__int64 __fastcall tmpfil(__int64 a1)
{
unsigned int v1; // er12

while ( 1 )
{
++serial;
itos();
movstr(&numbuf, tmpname);
v1 = open64(&tmpout, 194, 384LL);
if ( v1 != -1 )
break;
if ( *_errno_location() != 17 )
{
failed(&tmpout, &badcreate);
break;
}
}
pushtemp(v1, a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v1; // er12

while ( 1 )
{
++serial;
itos();
movstr(&numbuf, tmpname);
v1 = open64(&tmpout, 194, 384LL);
if ( v1 != -1 )
break;
if ( *_errno_location() != 17 )
{
failed(&tmpout, &badcreate);
break;
}
}
func4(v1, a1);
return v1;
}

original_code:
int
tmpfil(struct tempblk *tb)
{
 int fd;
 do {
  itos(serial++);
  movstr(numbuf, tmpname);
  fd = open((char *)tmpout, 02|0100|0200, 0600);
 } while ((fd == -1) && ((*__errno_location ()) == 17));
 if (fd == -1)
  failed(tmpout, badcreate);
 pushtemp(fd, tb);
 return (fd);
}

user_defined_types: struct tempblk { int fdes; struct tempblk *fstak; }


copy

decompiled_code:
void __fastcall copy(__int64 a1, char *a2)
{
char *v3; // r12
int v4; // er14
char *v5; // rdi
__int64 v6; // rax
char *v7; // r13
char *v8; // rbp
unsigned __int64 v9; // rdi
char *v10; // r15
char *i; // rsi
int v12; // eax
unsigned int v13; // ebx
char *v14; // rdi
char *j; // rsi
char *v16; // rbx
char v17; // al
bool v18; // zf
int v19; // ebp
unsigned int fd; // [rsp+Ch] [rbp-4Ch]
char v21[72]; // [rsp+10h] [rbp-48h] BYREF

if ( a1 )
{
copy(*(_QWORD *)(a1 + 32));
v3 = (char *)mactrim(*(_QWORD *)(a1 + 8));
v4 = *(_DWORD *)a1 & 0x200;
if ( nosubst )
*(_DWORD *)a1 &= 0xFFFFFFEF;
v5 = &tmpout;
fd = tmpfil((__int64)v21);
if ( fndef )
*(_QWORD *)(a1 + 8) = make(&tmpout);
else
*(_QWORD *)(a1 + 8) = cpystak(&tmpout);
v6 = iotemp;
iotemp = a1;
*(_QWORD *)(a1 + 32) = v6;
v7 = (char *)locstak();
if ( v4 )
{
for ( *(_DWORD *)a1 &= 0xFFFFFDFF; *v3 == 9; ++v3 )
;
}
LABEL_9:
v8 = v7;
while ( 1 )
{
chkpr();
if ( nosubst )
{
v9 = (unsigned int)readwc(v5, a2);
if ( v4 )
{
while ( (_DWORD)v9 == 9 )
v9 = (unsigned int)readwc(v9, a2);
}
v10 = v8;
while ( (unsigned int)v9 > 0x7F || (*((_BYTE *)&sh_ctype1 + (unsigned int)v9) & 0x30) == 0 )
{
for ( i = (char *)readw(v9); *i; ++v10 )
{
while ( brkend > (unsigned __int64)v10 )
{
*v10 = *i++;
v9 = (unsigned __int64)++v10;
if ( !*i )
goto LABEL_20;
}
growstak(v10);
*v10 = *i++;
v9 = (unsigned __int64)(v10 + 1);
}
LABEL_20:
v9 = (unsigned int)readwc(v9, i);
}
}
else
{
v13 = ((__int64 (*)(void))nextwc)();
if ( v4 )
{
while ( v13 == 9 )
v13 = ((__int64 (*)(void))nextwc)();
}
v10 = v8;
while ( v13 > 0x7F || (*((_BYTE *)&sh_ctype1 + v13) & 0x30) == 0 )
{
v14 = (char *)v13;
for ( j = (char *)readw(v13); *j; ++v10 )
{
while ( brkend > (unsigned __int64)v10 )
{
*v10 = *j++;
v14 = ++v10;
if ( !*j )
goto LABEL_42;
}
growstak(v10);
*v10 = *j++;
v14 = v10 + 1;
}
LABEL_42:
if ( v13 == 92 )
{
v14 = (char *)(unsigned int)readwc(v14, j);
v16 = (char *)readw(v14);
v17 = *v16;
if ( *v16 )
{
do
{
if ( brkend <= (unsigned __int64)v10 )
growstak(v10);
*v10 = *v16;
j = v16 + 1;
v14 = v10 + 1;
v18 = *++v16 == 0;
++v10;
}
while ( !v18 );
}
else
{
if ( brkend <= (unsigned __int64)v10 )
{
v14 = v10;
growstak(v10);
v17 = *v16;
}
*v10++ = v17;
}
}
v13 = nextwc(v14, j);
}
}
if ( brkend <= (unsigned __int64)v10 )
growstak(v10);
*v10 = 0;
if ( *(_WORD *)(standin + 8LL) )
break;
a2 = v3;
v5 = v8;
if ( !(unsigned int)nullsub_1(v8, v3) )
break;
if ( brkend <= (unsigned __int64)v10 )
{
v5 = v10;
growstak(v10);
}
v8 = v10 + 1;
*v10 = 10;
v12 = (_DWORD)v10 + 1 - (_DWORD)v7;
if ( v12 > 511 )
{
v5 = (char *)fd;
a2 = v7;
write(fd, v7, v12);
goto LABEL_9;
}
}
v19 = (_DWORD)v8 - (_DWORD)v7;
if ( v19 > 0 )
write(fd, v7, v19);
poptemp();
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, char *a2)
{
char *v3; // r12
int v4; // er14
char *v5; // rdi
__int64 v6; // rax
char *v7; // r13
char *v8; // rbp
unsigned __int64 v9; // rdi
char *v10; // r15
char *i; // rsi
int v12; // eax
unsigned int v13; // ebx
char *v14; // rdi
char *j; // rsi
char *v16; // rbx
char v17; // al
bool v18; // zf
int v19; // ebp
unsigned int fd; // [rsp+Ch] [rbp-4Ch]
char v21[72]; // [rsp+10h] [rbp-48h] BYREF

if ( a1 )
{
func11(*(_QWORD *)(a1 + 32));
v3 = (char *)mactrim(*(_QWORD *)(a1 + 8));
v4 = *(_DWORD *)a1 & 0x200;
if ( nosubst )
*(_DWORD *)a1 &= 0xFFFFFFEF;
v5 = &tmpout;
fd = func10((__int64)v21);
if ( fndef )
*(_QWORD *)(a1 + 8) = make(&tmpout);
else
*(_QWORD *)(a1 + 8) = cpystak(&tmpout);
v6 = iotemp;
iotemp = a1;
*(_QWORD *)(a1 + 32) = v6;
v7 = (char *)locstak();
if ( v4 )
{
for ( *(_DWORD *)a1 &= 0xFFFFFDFF; *v3 == 9; ++v3 )
;
}
LABEL_9:
v8 = v7;
while ( 1 )
{
chkpr();
if ( nosubst )
{
v9 = (unsigned int)readwc(v5, a2);
if ( v4 )
{
while ( (_DWORD)v9 == 9 )
v9 = (unsigned int)readwc(v9, a2);
}
v10 = v8;
while ( (unsigned int)v9 > 0x7F || (*((_BYTE *)&sh_ctype1 + (unsigned int)v9) & 0x30) == 0 )
{
for ( i = (char *)readw(v9); *i; ++v10 )
{
while ( brkend > (unsigned __int64)v10 )
{
*v10 = *i++;
v9 = (unsigned __int64)++v10;
if ( !*i )
goto LABEL_20;
}
growstak(v10);
*v10 = *i++;
v9 = (unsigned __int64)(v10 + 1);
}
LABEL_20:
v9 = (unsigned int)readwc(v9, i);
}
}
else
{
v13 = ((__int64 (*)(void))nextwc)();
if ( v4 )
{
while ( v13 == 9 )
v13 = ((__int64 (*)(void))nextwc)();
}
v10 = v8;
while ( v13 > 0x7F || (*((_BYTE *)&sh_ctype1 + v13) & 0x30) == 0 )
{
v14 = (char *)v13;
for ( j = (char *)readw(v13); *j; ++v10 )
{
while ( brkend > (unsigned __int64)v10 )
{
*v10 = *j++;
v14 = ++v10;
if ( !*j )
goto LABEL_42;
}
growstak(v10);
*v10 = *j++;
v14 = v10 + 1;
}
LABEL_42:
if ( v13 == 92 )
{
v14 = (char *)(unsigned int)readwc(v14, j);
v16 = (char *)readw(v14);
v17 = *v16;
if ( *v16 )
{
do
{
if ( brkend <= (unsigned __int64)v10 )
growstak(v10);
*v10 = *v16;
j = v16 + 1;
v14 = v10 + 1;
v18 = *++v16 == 0;
++v10;
}
while ( !v18 );
}
else
{
if ( brkend <= (unsigned __int64)v10 )
{
v14 = v10;
growstak(v10);
v17 = *v16;
}
*v10++ = v17;
}
}
v13 = nextwc(v14, j);
}
}
if ( brkend <= (unsigned __int64)v10 )
growstak(v10);
*v10 = 0;
if ( *(_WORD *)(standin + 8LL) )
break;
a2 = v3;
v5 = v8;
if ( !(unsigned int)nullsub_1(v8, v3) )
break;
if ( brkend <= (unsigned __int64)v10 )
{
v5 = v10;
growstak(v10);
}
v8 = v10 + 1;
*v10 = 10;
v12 = (_DWORD)v10 + 1 - (_DWORD)v7;
if ( v12 > 511 )
{
v5 = (char *)fd;
a2 = v7;
write(fd, v7, v12);
goto LABEL_9;
}
}
v19 = (_DWORD)v8 - (_DWORD)v7;
if ( v19 > 0 )
write(fd, v7, v19);
func5();
}
}

original_code:
void
copy(struct ionod *ioparg)
{
 register unsigned char *cline;
 register unsigned char *clinep;
 register struct ionod *iop;
 unsigned int c;
 unsigned char *ends;
 unsigned char *start;
 int fd;
 int i;
 int stripflg;
 unsigned char *pc;
 if (iop = ioparg)
 {
  struct tempblk tb;
  copy(iop->iolst);
  ends = mactrim(iop->ioname);
  stripflg = iop->iofile & 512;
  if (nosubst)
   iop->iofile &= ~16;
  fd = tmpfil(&tb);
  if (fndef)
   iop->ioname = (char *) make(tmpout);
  else
   iop->ioname = (char *) cpystak(tmpout);
  iop->iolst = iotemp;
  iotemp = iop;
  cline = clinep = start = locstak();
  if (stripflg)
  {
   iop->iofile &= ~512;
   while (*ends == '\t')
    ends++;
  }
  for (;;)
  {
   chkpr();
   if (nosubst)
   {
    c = readwc();
    if (stripflg)
     while (c == '\t')
      c = readwc();
    while (!((c<0200) && sh_ctype1[c]&(040|020)))
    {
     pc = readw(c);
     while (*pc) {
      if (clinep >= brkend)
       growstak(clinep);
      *clinep++ = *pc++;
     }
     c = readwc();
    }
   }else{
    c = nextwc();
    if (stripflg)
     while (c == '\t')
      c = nextwc();
    while (!((c<0200) && sh_ctype1[c]&(040|020)))
    {
     pc = readw(c);
     while (*pc) {
      if (clinep >= brkend)
       growstak(clinep);
      *clinep++ = *pc++;
     }
     if (c == '\\')
     {
      pc = readw(readwc());
      if (*pc) {
       while (*pc) {
        if (clinep >= brkend)
         growstak(clinep);
        *clinep++ = *pc++;
       }
      } else {
       if (clinep >= brkend)
        growstak(clinep);
       *clinep++ = *pc;
      }
     }
     c = nextwc();
    }
   }
   if (clinep >= brkend)
    growstak(clinep);
   *clinep = 0;
   if ((standin->feof) || (cf(cline, ends) == 0))
   {
    if ((i = cline - start) > 0)
     write(fd, start, i);
    break;
   }else{
    if (clinep >= brkend)
     growstak(clinep);
    *clinep++ = '\n';
   }
   if ((i = clinep - start) < 512)
    cline = clinep;
   else
   {
    write(fd, start, i);
    cline = clinep = start;
   }
  }
  poptemp();
 }
}

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

variable_types:
cline
unsigned char *

variable_types:
clinep
unsigned char *

variable_types:
c
unsigned int

variable_types:
ends
unsigned char *

variable_types:
start
unsigned char *

variable_types: i int

variable_types: stripflg int

variable_types:
pc
unsigned char *

variable_types: struct tempblk { int fdes; struct tempblk *fstak; }


decompiled_code:
void __fastcall link_iodocs(__int64 a1)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 32) )
{
LABEL_2:
sh_free(*(_QWORD *)(i + 16));
while ( 1 )
{
++serial;
itos();
movstr(&numbuf, tmpname);
if ( link(*(const char **)(i + 8), &tmpout) != -1 )
break;
if ( *_errno_location() != 17 )
{
failed(&tmpout, &badcreate);
goto LABEL_2;
}
}
*(_QWORD *)(i + 16) = make(&tmpout);
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 32) )
{
LABEL_2:
sh_free(*(_QWORD *)(i + 16));
while ( 1 )
{
++serial;
itos();
movstr(&numbuf, tmpname);
if ( link(*(const char **)(i + 8), &tmpout) != -1 )
break;
if ( *_errno_location() != 17 )
{
failed(&tmpout, &badcreate);
goto LABEL_2;
}
}
*(_QWORD *)(i + 16) = make(&tmpout);
}
}

original_code:
void
link_iodocs(struct ionod *i)
{
 int r;
 while (i)
 {
  sh_free(i->iolink);
  do {
   itos(serial++);
   movstr(numbuf, tmpname);
   r = link(i->ioname, (char *)tmpout);
  } while (r == -1 && (*__errno_location ()) == 17);
  if (r != -1) {
   i->iolink = (char *)make(tmpout);
   i = i->iolst;
  } else
   failed(tmpout, badcreate);
 }
}

variable_types: r int


savefd

decompiled_code:
__int64 __fastcall savefd(__int64 a1)
{
return fcntl64(a1, 0LL, 10LL);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return fcntl64(a1, 0LL, 10LL);
}

original_code:
int
savefd(int fd)
{
 register int f;
 f = fcntl(fd, 0, 10);
 return (f);
}

variable_types: fd int

variable_types: f int


restore

decompiled_code:
void __fastcall restore(int a1)
{
int v2; // eax
__int64 v3; // rbx
int v4; // edi
unsigned int v5; // esi

v2 = topfd - 1;
v3 = v2;
if ( v2 >= a1 )
{
do
{
while ( 1 )
{
v4 = *((_DWORD *)&fdmap + 2 * v3 + 1);
v5 = *((_DWORD *)&fdmap + 2 * v3);
if ( v4 <= 0 )
break;
renamef(v4, v5);
if ( a1 > (int)--v3 )
goto LABEL_6;
}
--v3;
close(v5);
}
while ( a1 <= (int)v3 );
}
LABEL_6:
topfd = a1;
}

canonical_decompiled_code:
void __fastcall func15(int a1)
{
int v2; // eax
__int64 v3; // rbx
int v4; // edi
unsigned int v5; // esi

v2 = topfd - 1;
v3 = v2;
if ( v2 >= a1 )
{
do
{
while ( 1 )
{
v4 = *((_DWORD *)&fdmap + 2 * v3 + 1);
v5 = *((_DWORD *)&fdmap + 2 * v3);
if ( v4 <= 0 )
break;
func8(v4, v5);
if ( a1 > (int)--v3 )
goto LABEL_6;
}
--v3;
close(v5);
}
while ( a1 <= (int)v3 );
}
LABEL_6:
topfd = a1;
}

original_code:
void
restore(register int last)
{
 register int i;
 register int dupfd;
 for (i = topfd - 1; i >= last; i--)
 {
  if ((dupfd = fdmap[i].dup_fd) > 0)
   renamef(dupfd, fdmap[i].org_fd);
  else
   close(fdmap[i].org_fd);
 }
 topfd = last;
}

canonical_original_code:
void restore(int last)
{
 register int i;
 register int dupfd;
 for (i = topfd - 1; i >= last; i--)
 {
  if ((dupfd = fdmap[i].dup_fd) > 0)
   renamef(dupfd, fdmap[i].org_fd);
  else
   close(fdmap[i].org_fd);
 }
 topfd = last;
}

variable_types: last int

variable_types: dupfd int


freedolh

original_code:
static void
freedolh(void)
{
 register unsigned char **argp;
 register struct dolnod *argblk;
 if (argblk = dolh)
 {
  if ((--argblk->doluse) == 0)
  {
   for (argp = argblk->dolarg; *argp != (unsigned char *)0; argp++)
    sh_free(*argp);
   sh_free(argblk->dolarg);
   sh_free(argblk);
  }
 }
}

canonical_original_code:
static void freedolh()
{
 register unsigned char **argp;
 register struct dolnod *argblk;
 if (argblk = dolh)
 {
  if ((--argblk->doluse) == 0)
  {
   for (argp = argblk->dolarg; *argp != (unsigned char *)0; argp++)
    sh_free(*argp);
   sh_free(argblk->dolarg);
   sh_free(argblk);
  }
 }
}

variable_types:
argp
unsigned char **

variable_types: struct dolnod { struct dolnod *dolnxt; int doluse; unsigned char **dolarg; } *


copyargs

original_code:
static struct dolnod *
copyargs(unsigned char *from[], int n)
{
 register struct dolnod *np = (struct dolnod *)alloc(sizeof(struct dolnod));
 register unsigned char **fp = from;
 register unsigned char **pp;
 np -> dolnxt = 0;
 np->doluse = 1;
 pp = np->dolarg = (unsigned char **)alloc((n+1)*sizeof(char *));
 dolv = pp;
 while (n--)
  *pp++ = make(*fp++);
 *pp++ = 0;
 return(np);
}

canonical_original_code:
static struct dolnod *copyargs(unsigned char *from[], int n)
{
 register struct dolnod *np = (struct dolnod *)alloc(sizeof(struct dolnod));
 register unsigned char **fp = from;
 register unsigned char **pp;
 np -> dolnxt = 0;
 np->doluse = 1;
 pp = np->dolarg = (unsigned char **)alloc((n+1)*sizeof(char *));
 dolv = pp;
 while (n--)
  *pp++ = make(*fp++);
 *pp++ = 0;
 return(np);
}

variable_types:
from
unsigned char *[]

variable_types: n int

variable_types:
fp
unsigned char **

variable_types:
pp
unsigned char **

return_type: struct dolnod { struct dolnod *dolnxt; int doluse; unsigned char **dolarg; } *


options

decompiled_code:
__int64 __fastcall options(int a1, _QWORD *a2)
{
unsigned int v2; // ebp
_BYTE *v3; // rdx
__int64 v4; // rdi
char *v5; // rsi
char v6; // dl
char *v7; // rax
__int64 result; // rax
wchar_t v9; // eax
const char *v10; // r14
_QWORD *v11; // r13
__int64 v12; // rax
int v13; // eax
char *v14; // rbx
wchar_t v15; // eax
const char *i; // r14
__int64 v17; // r13
int v18; // eax
char *v19; // rbx
int v20; // eax
__int64 v21; // rdi
__int64 v22; // rax
wchar_t pwc[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = a1;
if ( a1 > 1 )
{
v3 = (_BYTE *)a2[1];
if ( *v3 != 45 )
{
if ( *v3 == 43 )
{
v15 = (unsigned __int8)v3[1];
for ( i = v3 + 1; (_BYTE)v15; v15 = *(unsigned __int8 *)i )
{
if ( mb_cur_max > 1 && (v15 & 0x80u) != 0 )
{
v17 = mbtowc(pwc, i, mb_cur_max);
}
else
{
pwc[0] = v15;
v17 = v15 != 0;
}
if ( (int)v17 <= 0 )
{
++i;
}
else
{
v18 = (unsigned __int8)flagchar;
v19 = &flagchar;
if ( flagchar )
{
do
{
if ( v18 == pwc[0] )
break;
v18 = (unsigned __int8)*++v19;
}
while ( (_BYTE)v18 );
}
if ( !(unsigned int)any((unsigned int)pwc[0], "sicrp") )
{
v20 = (unsigned __int8)*v19;
if ( v20 == pwc[0] )
{
flags &= ~(unsigned __int64)*(&flagval + v19 - &flagchar);
if ( v20 == 101 )
eflag = 0;
}
}
i += v17;
}
}
v2 = a1 - 1;
a2[1] = *a2;
}
goto LABEL_4;
}
v9 = (unsigned __int8)v3[1];
if ( (_BYTE)v9 == 45 )
{
result = (unsigned int)(a1 - 1);
a2[1] = *a2;
return result;
}
if ( (_BYTE)v9 )
{
v10 = v3 + 1;
goto LABEL_14;
}
flags &= 0xFFFFFFFFFFFFE7FFLL;
v9 = (unsigned __int8)v3[1];
v10 = v3 + 1;
v11 = a2;
if ( (_BYTE)v9 )
{
LABEL_14:
v11 = a2;
while ( 1 )
{
if ( mb_cur_max > 1 && (v9 & 0x80u) != 0 )
{
LODWORD(v12) = mbtowc(pwc, v10, mb_cur_max);
}
else
{
pwc[0] = v9;
LODWORD(v12) = v9 != 0;
}
if ( (int)v12 <= 0 )
{
v21 = a2[1];
pwc[0] = *(unsigned __int8 *)v10;
failed(v21, &badopt);
v12 = 1LL;
}
else
{
v12 = (int)v12;
}
v10 += v12;
v13 = (unsigned __int8)flagchar;
v14 = &flagchar;
if ( flagchar )
break;
LABEL_43:
if ( !pwc[0] )
goto LABEL_24;
if ( pwc[0] == 99 && v2 != 2 && !comdiv )
{
v22 = v11[2];
--v2;
++v11;
comdiv = v22;
*v11 = *(v11 - 1);
goto LABEL_27;
}
LABEL_46:
failed(a2[1], &badopt);
LABEL_27:
v9 = *(unsigned __int8 *)v10;
if ( !(_BYTE)v9 )
goto LABEL_28;
}
while ( v13 != pwc[0] )
{
v13 = (unsigned __int8)*++v14;
if ( !(_BYTE)v13 )
goto LABEL_43;
}
LABEL_24:
if ( (unsigned int)nullsub_1(*a2, &unk_880) || !(unsigned int)any((unsigned int)pwc[0], "sicrp") )
{
flags |= (unsigned __int64)*(&flagval + v14 - &flagchar);
if ( (flags & 0x10) != 0 )
eflag = 16;
goto LABEL_27;
}
goto LABEL_46;
}
LABEL_28:
--v2;
v11[1] = *v11;
}
LABEL_4:
v4 = flags;
v5 = (char *)&flagadr;
if ( flags )
{
v6 = flagchar;
if ( flagchar )
{
v7 = &flagchar;
do
{
if ( ((unsigned __int64)*(&flagval + v7 - &flagchar) & v4) != 0 )
*v5++ = v6;
v6 = *++v7;
}
while ( v6 );
}
}
*v5 = 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, _QWORD *a2)
{
unsigned int v2; // ebp
_BYTE *v3; // rdx
__int64 v4; // rdi
char *v5; // rsi
char v6; // dl
char *v7; // rax
__int64 result; // rax
wchar_t v9; // eax
const char *v10; // r14
_QWORD *v11; // r13
__int64 v12; // rax
int v13; // eax
char *v14; // rbx
wchar_t v15; // eax
const char *i; // r14
__int64 v17; // r13
int v18; // eax
char *v19; // rbx
int v20; // eax
__int64 v21; // rdi
__int64 v22; // rax
wchar_t pwc[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = a1;
if ( a1 > 1 )
{
v3 = (_BYTE *)a2[1];
if ( *v3 != 45 )
{
if ( *v3 == 43 )
{
v15 = (unsigned __int8)v3[1];
for ( i = v3 + 1; (_BYTE)v15; v15 = *(unsigned __int8 *)i )
{
if ( mb_cur_max > 1 && (v15 & 0x80u) != 0 )
{
v17 = mbtowc(pwc, i, mb_cur_max);
}
else
{
pwc[0] = v15;
v17 = v15 != 0;
}
if ( (int)v17 <= 0 )
{
++i;
}
else
{
v18 = (unsigned __int8)flagchar;
v19 = &flagchar;
if ( flagchar )
{
do
{
if ( v18 == pwc[0] )
break;
v18 = (unsigned __int8)*++v19;
}
while ( (_BYTE)v18 );
}
if ( !(unsigned int)any((unsigned int)pwc[0], "sicrp") )
{
v20 = (unsigned __int8)*v19;
if ( v20 == pwc[0] )
{
flags &= ~(unsigned __int64)*(&flagval + v19 - &flagchar);
if ( v20 == 101 )
eflag = 0;
}
}
i += v17;
}
}
v2 = a1 - 1;
a2[1] = *a2;
}
goto LABEL_4;
}
v9 = (unsigned __int8)v3[1];
if ( (_BYTE)v9 == 45 )
{
result = (unsigned int)(a1 - 1);
a2[1] = *a2;
return result;
}
if ( (_BYTE)v9 )
{
v10 = v3 + 1;
goto LABEL_14;
}
flags &= 0xFFFFFFFFFFFFE7FFLL;
v9 = (unsigned __int8)v3[1];
v10 = v3 + 1;
v11 = a2;
if ( (_BYTE)v9 )
{
LABEL_14:
v11 = a2;
while ( 1 )
{
if ( mb_cur_max > 1 && (v9 & 0x80u) != 0 )
{
LODWORD(v12) = mbtowc(pwc, v10, mb_cur_max);
}
else
{
pwc[0] = v9;
LODWORD(v12) = v9 != 0;
}
if ( (int)v12 <= 0 )
{
v21 = a2[1];
pwc[0] = *(unsigned __int8 *)v10;
failed(v21, &badopt);
v12 = 1LL;
}
else
{
v12 = (int)v12;
}
v10 += v12;
v13 = (unsigned __int8)flagchar;
v14 = &flagchar;
if ( flagchar )
break;
LABEL_43:
if ( !pwc[0] )
goto LABEL_24;
if ( pwc[0] == 99 && v2 != 2 && !comdiv )
{
v22 = v11[2];
--v2;
++v11;
comdiv = v22;
*v11 = *(v11 - 1);
goto LABEL_27;
}
LABEL_46:
failed(a2[1], &badopt);
LABEL_27:
v9 = *(unsigned __int8 *)v10;
if ( !(_BYTE)v9 )
goto LABEL_28;
}
while ( v13 != pwc[0] )
{
v13 = (unsigned __int8)*++v14;
if ( !(_BYTE)v13 )
goto LABEL_43;
}
LABEL_24:
if ( (unsigned int)nullsub_1(*a2, &unk_880) || !(unsigned int)any((unsigned int)pwc[0], "sicrp") )
{
flags |= (unsigned __int64)*(&flagval + v14 - &flagchar);
if ( (flags & 0x10) != 0 )
eflag = 16;
goto LABEL_27;
}
goto LABEL_46;
}
LABEL_28:
--v2;
v11[1] = *v11;
}
LABEL_4:
v4 = flags;
v5 = (char *)&flagadr;
if ( flags )
{
v6 = flagchar;
if ( flagchar )
{
v7 = &flagchar;
do
{
if ( ((unsigned __int64)*(&flagval + v7 - &flagchar) & v4) != 0 )
*v5++ = v6;
v6 = *++v7;
}
while ( v6 );
}
}
*v5 = 0;
return v2;
}

original_code:
int
options(int argc, unsigned char **argv)
{
 register unsigned char *cp;
 register unsigned char **argp = argv;
 register unsigned char *flagc;
 unsigned char *flagp;
 int len;
 wchar_t wc;
 if (argc > 1 && *argp[1] == '-')
 {
  cp = argp[1];
  if (cp[1] == '-')
  {
   argp[1] = argp[0];
   argc--;
   return(argc);
  }
  if (cp[1] == '\0')
   flags &= ~(04000|010000);
  cp++;
  while (*cp) {
   if ((len = (mb_cur_max > 1 && *((char *)cp) & 0200 ? mbtowc(&wc, (char *)cp, mb_cur_max) : (*(&wc) = *((char *)cp) & 0377, *(&wc) != 0))) <= 0) {
    len = 1;
    wc = (unsigned char)*cp;
    failed(argv[1],badopt);
   }
   cp += len;
   flagc = flagchar;
   while (*flagc && wc != *flagc)
    flagc++;
   if (wc == *flagc)
   {
    if ((cf(argv[0], "set") == 0) && any(wc, "sicrp"))
     failed(argv[1], badopt);
    else
    {
     flags |= flagval[flagc-flagchar];
     if (flags & 020)
      eflag = 020;
    }
   }
   else if (wc == 'c' && argc > 2 && comdiv == 0)
   {
    comdiv = argp[2];
    argp[1] = argp[0];
    argp++;
    argc--;
   }
   else
    failed(argv[1],badopt);
  }
  argp[1] = argp[0];
  argc--;
 }
 else if (argc > 1 && *argp[1] == '+')
 {
  cp = argp[1];
  cp++;
  while (*cp)
  {
   if ((len = (mb_cur_max > 1 && *((char *)cp) & 0200 ? mbtowc(&wc, (char *)cp, mb_cur_max) : (*(&wc) = *((char *)cp) & 0377, *(&wc) != 0))) <= 0) {
    cp++;
    continue;
   }
   flagc = flagchar;
   while (*flagc && wc != *flagc)
    flagc++;
   if (!any(wc, "sicrp") && wc == *flagc) {
    flags &= ~(flagval[flagc-flagchar]);
    if (wc == 'e')
     eflag = 0;
   }
   cp += len;
  }
  argp[1] = argp[0];
  argc--;
 }
 flagp = flagadr;
 if (flags)
 {
  flagc = flagchar;
  while (*flagc)
  {
   if (flags & flagval[flagc-flagchar])
    *flagp++ = *flagc;
   flagc++;
  }
 }
 *flagp = 0;
 return(argc);
}

canonical_original_code:
int options(int argc, unsigned char **argv)
{
 register unsigned char *cp;
 register unsigned char **argp = argv;
 register unsigned char *flagc;
 unsigned char *flagp;
 int len;
 int wc;
 if (argc > 1 && *argp[1] == '-')
 {
  cp = argp[1];
  if (cp[1] == '-')
  {
   argp[1] = argp[0];
   argc--;
   return(argc);
  }
  if (cp[1] == '\0')
   flags &= ~(04000|010000);
  cp++;
  while (*cp) {
   if ((len = (mb_cur_max > 1 && *((char *)cp) & 0200 ? mbtowc(&wc, (char *)cp, mb_cur_max) : (*(&wc) = *((char *)cp) & 0377, *(&wc) != 0))) <= 0) {
    len = 1;
    wc = (unsigned char)*cp;
    failed(argv[1],badopt);
   }
   cp += len;
   flagc = flagchar;
   while (*flagc && wc != *flagc)
    flagc++;
   if (wc == *flagc)
   {
    if ((cf(argv[0], "set") == 0) && any(wc, "sicrp"))
     failed(argv[1], badopt);
    else
    {
     flags |= flagval[flagc-flagchar];
     if (flags & 020)
      eflag = 020;
    }
   }
   else if (wc == 'c' && argc > 2 && comdiv == 0)
   {
    comdiv = argp[2];
    argp[1] = argp[0];
    argp++;
    argc--;
   }
   else
    failed(argv[1],badopt);
  }
  argp[1] = argp[0];
  argc--;
 }
 else if (argc > 1 && *argp[1] == '+')
 {
  cp = argp[1];
  cp++;
  while (*cp)
  {
   if ((len = (mb_cur_max > 1 && *((char *)cp) & 0200 ? mbtowc(&wc, (char *)cp, mb_cur_max) : (*(&wc) = *((char *)cp) & 0377, *(&wc) != 0))) <= 0) {
    cp++;
    continue;
   }
   flagc = flagchar;
   while (*flagc && wc != *flagc)
    flagc++;
   if (!any(wc, "sicrp") && wc == *flagc) {
    flags &= ~(flagval[flagc-flagchar]);
    if (wc == 'e')
     eflag = 0;
   }
   cp += len;
  }
  argp[1] = argp[0];
  argc--;
 }
 flagp = flagadr;
 if (flags)
 {
  flagc = flagchar;
  while (*flagc)
  {
   if (flags & flagval[flagc-flagchar])
    *flagp++ = *flagc;
   flagc++;
  }
 }
 *flagp = 0;
 return(argc);
}

variable_types: argc int

variable_types:
argv
unsigned char **

variable_types:
cp
unsigned char *

variable_types:
flagc
unsigned char *

variable_types:
flagp
unsigned char *

variable_types: len int

variable_types: wc int


setargs

decompiled_code:
__int64 __fastcall setargs(__int64 *a1)
{
__int64 *v1; // rax
int v2; // ebp
int v3; // ebx
__int64 result; // rax

if ( *a1 )
{
v1 = a1 + 1;
v2 = 0;
do
{
++v1;
v3 = v2++;
}
while ( *(v1 - 1) );
}
else
{
v3 = -1;
v2 = 0;
}
freedolh();
result = copyargs(a1, v2);
dolc = v3;
dolh = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1)
{
__int64 *v1; // rax
int v2; // ebp
int v3; // ebx
__int64 result; // rax

if ( *a1 )
{
v1 = a1 + 1;
v2 = 0;
do
{
++v1;
v3 = v2++;
}
while ( *(v1 - 1) );
}
else
{
v3 = -1;
v2 = 0;
}
func0();
result = func1(a1, v2);
dolc = v3;
dolh = result;
return result;
}

original_code:
void
setargs(unsigned char *argi[])
{
 register unsigned char **argp = argi;
 register int argn = 0;
 while (*argp++ != (unsigned char *)0)
  argn++;
 freedolh();
 dolh = copyargs(argi, argn);
 dolc = argn - 1;
}

variable_types:
argi
unsigned char *[]

variable_types: argn int


original_code:
struct dolnod *
clean_args(struct dolnod *blk)
{
 register unsigned char **argp;
 register struct dolnod *argr = 0;
 register struct dolnod *argblk;
 if (argblk = blk)
 {
  argr = argblk->dolnxt;
  if (argblk == dolh)
   argblk->doluse = 1;
  else
  {
   for (argp = argblk->dolarg; *argp != (unsigned char *)0; argp++)
    sh_free(*argp);
   sh_free(argblk->dolarg);
   sh_free(argblk);
  }
 }
 return(argr);
}

canonical_original_code:
struct dolnod *clean_args(struct dolnod *blk)
{
 register unsigned char **argp;
 register struct dolnod *argr = 0;
 register struct dolnod *argblk;
 if (argblk = blk)
 {
  argr = argblk->dolnxt;
  if (argblk == dolh)
   argblk->doluse = 1;
  else
  {
   for (argp = argblk->dolarg; *argp != (unsigned char *)0; argp++)
    sh_free(*argp);
   sh_free(argblk->dolarg);
   sh_free(argblk);
  }
 }
 return(argr);
}

variable_types:
blk
struct dolnod *

user_defined_types: struct dolnod { struct dolnod *dolnxt; int doluse; unsigned char **dolarg; }


clearup

decompiled_code:
__int64 clearup()
{
__int64 *v0; // rdi
__int64 result; // rax

if ( globdolv )
dolv = globdolv;
if ( globdolc )
dolc = globdolc;
if ( globdolh )
dolh = globdolh;
globdolv = 0LL;
v0 = (__int64 *)argfor;
globdolc = 0;
globdolh = 0LL;
do
{
argfor = clean_args(v0);
v0 = (__int64 *)argfor;
}
while ( argfor );
while ( (unsigned int)pop(0LL) )
;
if ( savpipe != -1 )
{
close(savpipe);
savpipe = -1;
}
do
result = poptemp();
while ( (_DWORD)result );
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 *v0; // rdi
__int64 result; // rax

if ( globdolv )
dolv = globdolv;
if ( globdolc )
dolc = globdolc;
if ( globdolh )
dolh = globdolh;
globdolv = 0LL;
v0 = (__int64 *)argfor;
globdolc = 0;
globdolh = 0LL;
do
{
argfor = func4(v0);
v0 = (__int64 *)argfor;
}
while ( argfor );
while ( (unsigned int)pop(0LL) )
;
if ( savpipe != -1 )
{
close(savpipe);
savpipe = -1;
}
do
result = poptemp();
while ( (_DWORD)result );
return result;
}

original_code:
void
clearup(void)
{
 if(globdolv)
  dolv = globdolv;
 if(globdolc)
  dolc = globdolc;
 if(globdolh)
  dolh = globdolh;
 globdolv = 0;
 globdolc = 0;
 globdolh = 0;
 while (argfor = clean_args(argfor))
  ;
 while (pop())
  ;
 if(savpipe != -1) {
  close(savpipe);
  savpipe = -1;
 }
 while (poptemp())
  ;
}

canonical_original_code:
void clearup()
{
 if(globdolv)
  dolv = globdolv;
 if(globdolc)
  dolc = globdolc;
 if(globdolh)
  dolh = globdolh;
 globdolv = 0;
 globdolc = 0;
 globdolh = 0;
 while (argfor = clean_args(argfor))
  ;
 while (pop())
  ;
 if(savpipe != -1) {
  close(savpipe);
  savpipe = -1;
 }
 while (poptemp())
  ;
}


useargs

decompiled_code:
_QWORD *useargs()
{
_QWORD *result; // rax
int v1; // edx

result = (_QWORD *)dolh;
if ( dolh )
{
v1 = *(_DWORD *)(dolh + 8);
*(_DWORD *)(dolh + 8) = v1 + 1;
if ( v1 == 1 )
{
*result = argfor;
argfor = result;
}
}
return result;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *result; // rax
int v1; // edx

result = (_QWORD *)dolh;
if ( dolh )
{
v1 = *(_DWORD *)(dolh + 8);
*(_DWORD *)(dolh + 8) = v1 + 1;
if ( v1 == 1 )
{
*result = argfor;
argfor = result;
}
}
return result;
}

original_code:
struct dolnod *
useargs(void)
{
 if (dolh)
 {
  if (dolh->doluse++ == 1)
  {
   dolh->dolnxt = argfor;
   argfor = dolh;
  }
 }
 return(dolh);
}

canonical_original_code:
struct dolnod *useargs()
{
 if (dolh)
 {
  if (dolh->doluse++ == 1)
  {
   dolh->dolnxt = argfor;
   argfor = dolh;
  }
 }
 return(dolh);
}


savargs

decompiled_code:
__int64 __fastcall savargs(int a1)
{
__int64 v1; // r8

if ( !a1 )
{
globdolh = dolh;
globdolv = dolv;
globdolc = dolc;
}
useargs();
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // r8

if ( !a1 )
{
globdolh = dolh;
globdolv = dolv;
globdolc = dolc;
}
func7();
return v1;
}

original_code:
struct dolnod *
savargs(int funcnt)
{
 if (!funcnt) {
  globdolh = dolh;
  globdolv = dolv;
  globdolc = dolc;
 }
 useargs();
 return(dolh);
}

canonical_original_code:
struct dolnod *savargs(int funcnt)
{
 if (!funcnt) {
  globdolh = dolh;
  globdolv = dolv;
  globdolc = dolc;
 }
 useargs();
 return(dolh);
}

variable_types: funcnt int


cwd

decompiled_code:
__int64 __fastcall cwd(__int128 a1)
{
unsigned __int8 *v1; // rbp
char *v2; // rbx
char v3; // dl
char v4; // al
_BYTE *i; // rbx
__int64 result; // rax
unsigned int v7; // ecx
unsigned __int8 *v8; // rcx
char *v9; // rdx
_BYTE *v10; // rsi
_BYTE *v11; // rdx

v1 = (unsigned __int8 *)a1;
v2 = (char *)a1;
rmslash((_BYTE *)a1);
v3 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 47 )
{
v3 = *(_BYTE *)(a1 + 1);
v2 = (char *)(a1 + 1);
}
if ( v3 )
{
do
{
v4 = v2[1];
if ( v3 == 46 && v4 == 47 )
{
movstr(v2 + 2, v2);
}
else
{
for ( i = v2 + 1; v4; v4 = *++i )
{
if ( v4 == 47 )
break;
}
v2 = &i[-(v4 == 0) + 1];
}
v3 = *v2;
}
while ( *v2 );
}
if ( *(v2 - 1) == 46 && (unsigned __int64)a1 < (unsigned __int64)(v2 - 1) && *(v2 - 2) == 47 )
{
if ( (unsigned __int64)a1 >= (unsigned __int64)(v2 - 2) )
*(v2 - 1) = 0;
else
*(v2 - 2) = 0;
}
rmslash((_BYTE *)a1);
result = *(unsigned __int8 *)a1;
if ( (_BYTE)result == 46 )
{
if ( !*(_BYTE *)(a1 + 1) )
return result;
result = (unsigned int)didpwd;
if ( !didpwd )
return result;
}
else
{
if ( (_BYTE)result == 47 )
{
cwdname[0] = 47;
v1 = (unsigned __int8 *)(a1 + 1);
didpwd = 2;
goto LABEL_20;
}
result = (unsigned int)didpwd;
if ( !didpwd )
return result;
}
didpwd = 2;
*((_QWORD *)&a1 + 1) = (int)length(cwdname);
if ( *((_QWORD *)&a1 + 1) != 2LL )
{
cwdname[*((_QWORD *)&a1 + 1) - 1] = 47;
result = *(unsigned __int8 *)a1;
*((_QWORD *)&a1 + 1) += cwdname;
if ( (_BYTE)result )
goto LABEL_21;
LABEL_35:
if ( *((_QWORD *)&a1 + 1) >= (unsigned __int64)&cwdname[4097] )
{
LABEL_32:
didpwd = 0;
}
else
{
result = *((_QWORD *)&a1 + 1) - 1LL;
**((_BYTE **)&a1 + 1) = 0;
if ( *((_QWORD *)&a1 + 1) - 1LL > (unsigned __int64)cwdname && *(_BYTE *)(*((_QWORD *)&a1 + 1) - 1LL) == 47 )
*(_BYTE *)(*((_QWORD *)&a1 + 1) - 1LL) = 0;
}
return result;
}
LABEL_20:
result = *v1;
*((_QWORD *)&a1 + 1) = (unsigned int)((_DWORD)cwdname + 1);
if ( (_BYTE)result )
{
while ( 1 )
{
LABEL_21:
if ( (_BYTE)result == 46 && v1[1] == 46 && ((v7 = v1[2], (_BYTE)v7 == 47) || !(_BYTE)v7) )
{
*(_QWORD *)&a1 = (unsigned int)((_DWORD)cwdname + 2);
v10 = (_BYTE *)((a1 - (unsigned __int128)*((unsigned __int64 *)&a1 + 1)) >> 64);
do
v11 = v10--;
while ( *v10 != 47 );
if ( (_BYTE)v7 == 47 )
{
result = v1[3];
*((_QWORD *)&a1 + 1) = v11;
v1 += 3;
}
else
{
v1 += 2;
result = v7;
*((_QWORD *)&a1 + 1) = v11;
}
}
else
{
if ( *((_QWORD *)&a1 + 1) >= (unsigned __int64)&cwdname[4097] )
goto LABEL_32;
**((_BYTE **)&a1 + 1) = result;
result = v1[1];
v8 = v1 + 1;
v9 = (char *)(*((_QWORD *)&a1 + 1) + 1LL);
if ( (_BYTE)result == 47 )
{
LABEL_45:
if ( v9 >= &cwdname[4097] )
goto LABEL_32;
*v9 = result;
v1 = v8 + 1;
result = v8[1];
*((_QWORD *)&a1 + 1) = v9 + 1;
}
else
{
if ( (_BYTE)result )
{
if ( v9 >= &cwdname[4097] )
goto LABEL_32;
while ( 1 )
{
++v8;
*v9++ = result;
result = *v8;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 47 )
goto LABEL_45;
if ( v9 == &cwdname[4097] )
goto LABEL_32;
}
}
result = *v8;
*((_QWORD *)&a1 + 1) = v9;
v1 = v8;
}
}
if ( !(_BYTE)result )
goto LABEL_35;
}
}
cwdname[1] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int128 a1)
{
unsigned __int8 *v1; // rbp
char *v2; // rbx
char v3; // dl
char v4; // al
_BYTE *i; // rbx
__int64 result; // rax
unsigned int v7; // ecx
unsigned __int8 *v8; // rcx
char *v9; // rdx
_BYTE *v10; // rsi
_BYTE *v11; // rdx

v1 = (unsigned __int8 *)a1;
v2 = (char *)a1;
rmslash((_BYTE *)a1);
v3 = *(_BYTE *)a1;
if ( *(_BYTE *)a1 == 47 )
{
v3 = *(_BYTE *)(a1 + 1);
v2 = (char *)(a1 + 1);
}
if ( v3 )
{
do
{
v4 = v2[1];
if ( v3 == 46 && v4 == 47 )
{
movstr(v2 + 2, v2);
}
else
{
for ( i = v2 + 1; v4; v4 = *++i )
{
if ( v4 == 47 )
break;
}
v2 = &i[-(v4 == 0) + 1];
}
v3 = *v2;
}
while ( *v2 );
}
if ( *(v2 - 1) == 46 && (unsigned __int64)a1 < (unsigned __int64)(v2 - 1) && *(v2 - 2) == 47 )
{
if ( (unsigned __int64)a1 >= (unsigned __int64)(v2 - 2) )
*(v2 - 1) = 0;
else
*(v2 - 2) = 0;
}
rmslash((_BYTE *)a1);
result = *(unsigned __int8 *)a1;
if ( (_BYTE)result == 46 )
{
if ( !*(_BYTE *)(a1 + 1) )
return result;
result = (unsigned int)didpwd;
if ( !didpwd )
return result;
}
else
{
if ( (_BYTE)result == 47 )
{
cwdname[0] = 47;
v1 = (unsigned __int8 *)(a1 + 1);
didpwd = 2;
goto LABEL_20;
}
result = (unsigned int)didpwd;
if ( !didpwd )
return result;
}
didpwd = 2;
*((_QWORD *)&a1 + 1) = (int)length(cwdname);
if ( *((_QWORD *)&a1 + 1) != 2LL )
{
cwdname[*((_QWORD *)&a1 + 1) - 1] = 47;
result = *(unsigned __int8 *)a1;
*((_QWORD *)&a1 + 1) += cwdname;
if ( (_BYTE)result )
goto LABEL_21;
LABEL_35:
if ( *((_QWORD *)&a1 + 1) >= (unsigned __int64)&cwdname[4097] )
{
LABEL_32:
didpwd = 0;
}
else
{
result = *((_QWORD *)&a1 + 1) - 1LL;
**((_BYTE **)&a1 + 1) = 0;
if ( *((_QWORD *)&a1 + 1) - 1LL > (unsigned __int64)cwdname && *(_BYTE *)(*((_QWORD *)&a1 + 1) - 1LL) == 47 )
*(_BYTE *)(*((_QWORD *)&a1 + 1) - 1LL) = 0;
}
return result;
}
LABEL_20:
result = *v1;
*((_QWORD *)&a1 + 1) = (unsigned int)((_DWORD)cwdname + 1);
if ( (_BYTE)result )
{
while ( 1 )
{
LABEL_21:
if ( (_BYTE)result == 46 && v1[1] == 46 && ((v7 = v1[2], (_BYTE)v7 == 47) || !(_BYTE)v7) )
{
*(_QWORD *)&a1 = (unsigned int)((_DWORD)cwdname + 2);
v10 = (_BYTE *)((a1 - (unsigned __int128)*((unsigned __int64 *)&a1 + 1)) >> 64);
do
v11 = v10--;
while ( *v10 != 47 );
if ( (_BYTE)v7 == 47 )
{
result = v1[3];
*((_QWORD *)&a1 + 1) = v11;
v1 += 3;
}
else
{
v1 += 2;
result = v7;
*((_QWORD *)&a1 + 1) = v11;
}
}
else
{
if ( *((_QWORD *)&a1 + 1) >= (unsigned __int64)&cwdname[4097] )
goto LABEL_32;
**((_BYTE **)&a1 + 1) = result;
result = v1[1];
v8 = v1 + 1;
v9 = (char *)(*((_QWORD *)&a1 + 1) + 1LL);
if ( (_BYTE)result == 47 )
{
LABEL_45:
if ( v9 >= &cwdname[4097] )
goto LABEL_32;
*v9 = result;
v1 = v8 + 1;
result = v8[1];
*((_QWORD *)&a1 + 1) = v9 + 1;
}
else
{
if ( (_BYTE)result )
{
if ( v9 >= &cwdname[4097] )
goto LABEL_32;
while ( 1 )
{
++v8;
*v9++ = result;
result = *v8;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 47 )
goto LABEL_45;
if ( v9 == &cwdname[4097] )
goto LABEL_32;
}
}
result = *v8;
*((_QWORD *)&a1 + 1) = v9;
v1 = v8;
}
}
if ( !(_BYTE)result )
goto LABEL_35;
}
}
cwdname[1] = 0;
return result;
}

original_code:
void
cwd(register unsigned char *dir)
{
 register unsigned char *pcwd;
 register unsigned char *pdir;
 rmslash(dir);
 pdir = dir;
 if(*dir == '/')
  pdir++;
 while(*pdir)
 {
  if((*pdir=='.') && (*(pdir+1)=='/'))
  {
   movstr(pdir+2, pdir);
   continue;
  }
  pdir++;
  while ((*pdir) && (*pdir != '/'))
   pdir++;
  if (*pdir)
   pdir++;
 }
 if(*(--pdir)=='.' && pdir > dir && *(--pdir)=='/') {
  if(pdir > dir) {
   *pdir = '\0';
  } else {
   *(pdir+1) = '\0';
  }
 }
 rmslash(dir);
 if(*dir=='.' && *(dir+1)=='\0')
 {
  return;
 }
 if(*dir=='/')
 {
  pcwd = cwdname;
  *pcwd++ = *dir++;
  didpwd = 2;
 }
 else
 {
  if (didpwd == 0)
   return;
  didpwd = 2;
  pcwd = cwdname + length(cwdname) - 1;
  if(pcwd != cwdname+1)
   *pcwd++ = '/';
 }
 while(*dir)
 {
  if(*dir=='.' &&
     *(dir+1)=='.' &&
     (*(dir+2)=='/' || *(dir+2)=='\0'))
  {
   if( pcwd > cwdname+2 )
    --pcwd;
   while(*(--pcwd) != '/')
    ;
   pcwd++;
   dir += 2;
   if(*dir=='/')
   {
    dir++;
   }
   continue;
  }
   if (pcwd >= &cwdname[4096 +1])
  {
   didpwd=0;
   return;
  }
  *pcwd++ = *dir++;
  while((*dir) && (*dir != '/'))
  {
    if (pcwd >= &cwdname[4096 +1])
   {
    didpwd=0;
    return;
   }
   *pcwd++ = *dir++;
  }
  if (*dir)
  {
    if (pcwd >= &cwdname[4096 +1])
   {
    didpwd=0;
    return;
   }
   *pcwd++ = *dir++;
  }
 }
 if (pcwd >= &cwdname[4096 +1])
 {
  didpwd=0;
  return;
 }
 *pcwd = '\0';
 --pcwd;
 if(pcwd>cwdname && *pcwd=='/')
 {
  *pcwd = '\0';
 }
 return;
}

canonical_original_code:
void cwd(unsigned char *dir)
{
 register unsigned char *pcwd;
 register unsigned char *pdir;
 rmslash(dir);
 pdir = dir;
 if(*dir == '/')
  pdir++;
 while(*pdir)
 {
  if((*pdir=='.') && (*(pdir+1)=='/'))
  {
   movstr(pdir+2, pdir);
   continue;
  }
  pdir++;
  while ((*pdir) && (*pdir != '/'))
   pdir++;
  if (*pdir)
   pdir++;
 }
 if(*(--pdir)=='.' && pdir > dir && *(--pdir)=='/') {
  if(pdir > dir) {
   *pdir = '\0';
  } else {
   *(pdir+1) = '\0';
  }
 }
 rmslash(dir);
 if(*dir=='.' && *(dir+1)=='\0')
 {
  return;
 }
 if(*dir=='/')
 {
  pcwd = cwdname;
  *pcwd++ = *dir++;
  didpwd = 2;
 }
 else
 {
  if (didpwd == 0)
   return;
  didpwd = 2;
  pcwd = cwdname + length(cwdname) - 1;
  if(pcwd != cwdname+1)
   *pcwd++ = '/';
 }
 while(*dir)
 {
  if(*dir=='.' &&
     *(dir+1)=='.' &&
     (*(dir+2)=='/' || *(dir+2)=='\0'))
  {
   if( pcwd > cwdname+2 )
    --pcwd;
   while(*(--pcwd) != '/')
    ;
   pcwd++;
   dir += 2;
   if(*dir=='/')
   {
    dir++;
   }
   continue;
  }
   if (pcwd >= &cwdname[4096 +1])
  {
   didpwd=0;
   return;
  }
  *pcwd++ = *dir++;
  while((*dir) && (*dir != '/'))
  {
    if (pcwd >= &cwdname[4096 +1])
   {
    didpwd=0;
    return;
   }
   *pcwd++ = *dir++;
  }
  if (*dir)
  {
    if (pcwd >= &cwdname[4096 +1])
   {
    didpwd=0;
    return;
   }
   *pcwd++ = *dir++;
  }
 }
 if (pcwd >= &cwdname[4096 +1])
 {
  didpwd=0;
  return;
 }
 *pcwd = '\0';
 --pcwd;
 if(pcwd>cwdname && *pcwd=='/')
 {
  *pcwd = '\0';
 }
 return;
}

variable_types:
dir
unsigned char *

variable_types:
pcwd
unsigned char *

variable_types:
pdir
unsigned char *


decompiled_code:
int cwd2()
{
int result; // eax
char v1; // bl
char *v2; // r12
struct stat64 v3; // [rsp+0h] [rbp-138h] BYREF
struct stat64 v4; // [rsp+90h] [rbp-A8h] BYREF

result = didpwd;
if ( didpwd )
{
if ( didpwd != 2 )
{
result = stat64(cwdname, &v3);
if ( result == -1 )
goto LABEL_15;
goto LABEL_13;
}
v1 = cwdname[1];
v2 = (char *)(unsigned int)((_DWORD)cwdname + 1);
if ( !v1 )
{
LABEL_11:
didpwd = -1;
LABEL_13:
result = stat64(".", &v4);
if ( result != -1 )
{
result = v4.st_dev;
if ( v3.st_dev == v4.st_dev )
{
result = v4.st_ino;
if ( v3.st_ino == v4.st_ino )
return result;
}
}
LABEL_15:
didpwd = 0;
return result;
}
while ( 1 )
{
while ( v1 != 47 && v1 )
v1 = *++v2;
*v2 = 0;
result = lstat64(cwdname, &v3);
if ( result == -1 )
break;
result = v3.st_mode & 0xF000;
if ( result == 40960 )
break;
*v2 = v1;
if ( v1 )
{
v1 = *++v2;
if ( v1 )
continue;
}
goto LABEL_11;
}
*v2 = v1;
didpwd = 0;
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
char v1; // bl
char *v2; // r12
struct stat64 v3; // [rsp+0h] [rbp-138h] BYREF
struct stat64 v4; // [rsp+90h] [rbp-A8h] BYREF

result = didpwd;
if ( didpwd )
{
if ( didpwd != 2 )
{
result = stat64(cwdname, &v3);
if ( result == -1 )
goto LABEL_15;
goto LABEL_13;
}
v1 = cwdname[1];
v2 = (char *)(unsigned int)((_DWORD)cwdname + 1);
if ( !v1 )
{
LABEL_11:
didpwd = -1;
LABEL_13:
result = stat64(".", &v4);
if ( result != -1 )
{
result = v4.st_dev;
if ( v3.st_dev == v4.st_dev )
{
result = v4.st_ino;
if ( v3.st_ino == v4.st_ino )
return result;
}
}
LABEL_15:
didpwd = 0;
return result;
}
while ( 1 )
{
while ( v1 != 47 && v1 )
v1 = *++v2;
*v2 = 0;
result = lstat64(cwdname, &v3);
if ( result == -1 )
break;
result = v3.st_mode & 0xF000;
if ( result == 40960 )
break;
*v2 = v1;
if ( v1 )
{
v1 = *++v2;
if ( v1 )
continue;
}
goto LABEL_11;
}
*v2 = v1;
didpwd = 0;
}
return result;
}

original_code:
void
cwd2(void)
{
 struct stat stat1, stat2;
 unsigned char *pcwd;
 if(didpwd == 0)
  return;
 pcwd = cwdname + 1;
 if(didpwd == 2) {
  while (*pcwd)
  {
   char c;
   while((c = *pcwd++) != '/' && c != '\0');
   *--pcwd = '\0';
   if (lstat((char *)cwdname, &stat1) == -1
       || (stat1.st_mode & 0170000) == 0120000) {
    didpwd = 0;
    *pcwd = c;
    return;
   }
   *pcwd = c;
   if(c)
    pcwd++;
  }
  didpwd = (-1);
 } else
  if (stat((char *)cwdname, &stat1) == -1) {
   didpwd = 0;
   return;
  }
 if (stat(".", &stat2) == -1
     || stat1.st_dev != stat2.st_dev
     || stat1.st_ino != stat2.st_ino)
  didpwd = 0;
 return;
}

canonical_original_code:
void cwd2()
{
 struct stat stat1; struct stat stat2;
 unsigned char *pcwd;
 if(didpwd == 0)
  return;
 pcwd = cwdname + 1;
 if(didpwd == 2) {
  while (*pcwd)
  {
   char c;
   while((c = *pcwd++) != '/' && c != '\0');
   *--pcwd = '\0';
   if (lstat((char *)cwdname, &stat1) == -1
       || (stat1.st_mode & 0170000) == 0120000) {
    didpwd = 0;
    *pcwd = c;
    return;
   }
   *pcwd = c;
   if(c)
    pcwd++;
  }
  didpwd = (-1);
 } else
  if (stat((char *)cwdname, &stat1) == -1) {
   didpwd = 0;
   return;
  }
 if (stat(".", &stat2) == -1
     || stat1.st_dev != stat2.st_dev
     || stat1.st_ino != stat2.st_ino)
  didpwd = 0;
 return;
}

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: c char

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


cwdget

decompiled_code:
char *cwdget()
{
cwd2();
if ( didpwd )
return cwdname;
if ( !getcwd(cwdname, 0x1001uLL) )
cwdname[0] = 0;
didpwd = -1;
return cwdname;
}

canonical_decompiled_code:
char *func2()
{
func1();
if ( didpwd )
return cwdname;
if ( !getcwd(cwdname, 0x1001uLL) )
cwdname[0] = 0;
didpwd = -1;
return cwdname;
}

original_code:
unsigned char *
cwdget(void)
{
 cwd2();
 if (didpwd == 0) {
  if(getcwd(cwdname, 4096 +1) == (char *)0)
   *cwdname = 0;
  didpwd = (-1);
 }
 return (cwdname);
}

canonical_original_code:
unsigned char *cwdget()
{
 cwd2();
 if (didpwd == 0) {
  if(getcwd(cwdname, 4096 +1) == (char *)0)
   *cwdname = 0;
  didpwd = (-1);
 }
 return (cwdname);
}


cwdprint

decompiled_code:
__int64 cwdprint()
{
unsigned __int8 v0; // di
char *v1; // rbx
int v3; // eax
const char *v4; // rdx

cwd2();
if ( !didpwd )
{
if ( !getcwd(cwdname, 0x1001uLL) )
{
v3 = *_errno_location();
if ( !v3 || v3 == 34 )
error((int)&longpwd, 4097, v4);
else
error((int)"cannot determine current directory", 4097, v4);
}
didpwd = -1;
}
v0 = cwdname[0];
if ( cwdname[0] )
{
v1 = cwdname;
do
{
++v1;
prc_buff(v0);
v0 = *v1;
}
while ( *v1 );
}
return prc_buff(10LL);
}

canonical_decompiled_code:
__int64 func3()
{
unsigned __int8 v0; // di
char *v1; // rbx
int v3; // eax
const char *v4; // rdx

func1();
if ( !didpwd )
{
if ( !getcwd(cwdname, 0x1001uLL) )
{
v3 = *_errno_location();
if ( !v3 || v3 == 34 )
error((int)&longpwd, 4097, v4);
else
error((int)"cannot determine current directory", 4097, v4);
}
didpwd = -1;
}
v0 = cwdname[0];
if ( cwdname[0] )
{
v1 = cwdname;
do
{
++v1;
prc_buff(v0);
v0 = *v1;
}
while ( *v1 );
}
return prc_buff(10LL);
}

original_code:
void
cwdprint(void)
{
 register unsigned char *cp;
 cwd2();
 if (didpwd == 0) {
  if(getcwd(cwdname, 4096 +1) == (char *)0) {
   if((*__errno_location ()) && (*__errno_location ()) != 34)
    error("cannot determine current directory");
   else
    error(longpwd);
  }
  didpwd = (-1);
 }
 for (cp = cwdname; *cp; cp++) {
   prc_buff(*cp);
 }
 prc_buff('\n');
 return;
}

canonical_original_code:
void cwdprint()
{
 register unsigned char *cp;
 cwd2();
 if (didpwd == 0) {
  if(getcwd(cwdname, 4096 +1) == (char *)0) {
   if((*__errno_location ()) && (*__errno_location ()) != 34)
    error("cannot determine current directory");
   else
    error(longpwd);
  }
  didpwd = (-1);
 }
 for (cp = cwdname; *cp; cp++) {
   prc_buff(*cp);
 }
 prc_buff('\n');
 return;
}


blklen

decompiled_code:
__int64 __fastcall blklen(__int64 a1)
{
return (*(_QWORD *)(a1 - 8) & 0xFFFFFFFFFFFFFFFELL) - a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return (*(_QWORD *)(a1 - 8) & 0xFFFFFFFFFFFFFFFELL) - a1;
}

original_code:
size_t
blklen(char *q)
{
 register struct blk *pp = (struct blk *)q;
 register struct blk *p;
 --pp;
 p = (struct blk *)(((intptr_t)(pp->word)) & ~01);
 return ((size_t)((long)p - (long)q));
}

canonical_original_code:
unsigned long blklen(char *q)
{
 register struct blk *pp = (struct blk *)q;
 register struct blk *p;
 --pp;
 p = (struct blk *)(((long)(pp->word)) & ~01);
 return ((unsigned long)((long)p - (long)q));
}

variable_types:
q
char *

variable_types:
pp
struct blk { struct blk *word; } *

variable_types:
p
struct blk { struct blk *word; } *

return_type: unsigned long


nxtarg

decompiled_code:
__int64 __fastcall nxtarg(int a1)
{
__int64 v1; // rax

v1 = ap;
if ( ap < ac )
goto LABEL_4;
if ( !a1 )
{
failed("test", "argument expected");
v1 = ap;
LABEL_4:
ap = v1 + 1;
return *(_QWORD *)(av + 8 * v1);
}
++ap;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rax

v1 = ap;
if ( ap < ac )
goto LABEL_4;
if ( !a1 )
{
failed("test", "argument expected");
v1 = ap;
LABEL_4:
ap = v1 + 1;
return *(_QWORD *)(av + 8 * v1);
}
++ap;
return 0LL;
}

original_code:
static unsigned char *
nxtarg(int mt)
{
 if (ap >= ac)
 {
  if (mt)
  {
   ap++;
   return(0);
  }
  failed("test", "argument expected");
 }
 return(av[ap++]);
}

canonical_original_code:
static unsigned char *nxtarg(int mt)
{
 if (ap >= ac)
 {
  if (mt)
  {
   ap++;
   return(0);
  }
  failed("test", "argument expected");
 }
 return(av[ap++]);
}

variable_types: mt int


ftype

decompiled_code:
_BOOL8 __fastcall ftype(const char *a1, int a2)
{
int v2; // er8
_BOOL8 result; // rax
struct stat64 v4; // [rsp+0h] [rbp-98h] BYREF

v2 = stat64(a1, &v4);
result = 0LL;
if ( v2 >= 0 )
result = (a2 & v4.st_mode) == a2;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1, int a2)
{
int v2; // er8
_BOOL8 result; // rax
struct stat64 v4; // [rsp+0h] [rbp-98h] BYREF

v2 = stat64(a1, &v4);
result = 0LL;
if ( v2 >= 0 )
result = (a2 & v4.st_mode) == a2;
return result;
}

original_code:
static int
ftype(const unsigned char *f, int field)
{
 struct stat statb;
 if (stat((char *)f, &statb) < 0)
  return(0);
 if ((statb.st_mode & field) == field)
  return(1);
 return(0);
}

canonical_original_code:
static int ftype(unsigned char *f, int field)
{
 struct stat statb;
 if (stat((char *)f, &statb) < 0)
  return(0);
 if ((statb.st_mode & field) == field)
  return(1);
 return(0);
}

variable_types:
f
unsigned char *

variable_types: field int

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


fsizep

decompiled_code:
_BOOL8 __fastcall fsizep(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat64 v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat64(a1, &v3);
result = 0LL;
if ( v1 >= 0 )
result = v3.st_size > 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
int v1; // er8
_BOOL8 result; // rax
struct stat64 v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat64(a1, &v3);
result = 0LL;
if ( v1 >= 0 )
result = v3.st_size > 0;
return result;
}

original_code:
static int
fsizep(const unsigned char *f)
{
 struct stat statb;
 if (stat((char *)f, &statb) < 0)
  return(0);
 return(statb.st_size > 0);
}

canonical_original_code:
static int fsizep(unsigned char *f)
{
 struct stat statb;
 if (stat((char *)f, &statb) < 0)
  return(0);
 return(statb.st_size > 0);
}


decompiled_code:
int e3()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // r12
const char *v6; // rax
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // rbx
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rdi
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rdi
__int64 v18; // rdi
__int64 v19; // rdi
const char *v20; // rbp
const char *v21; // rdi
const char *v22; // rdi
const char *v23; // rdi
__int64 v24; // rdi
__int64 v25; // rdi
__int64 v26; // rdi
const char *v27; // rax
__int64 v28; // rax
int v29; // edi
__int64 v30; // rax
struct stat64 v31; // [rsp+0h] [rbp-A8h] BYREF

v0 = nxtarg(0);
if ( !(unsigned int)nullsub_1(v0, "(") )
{
LODWORD(v4) = sexp();
v7 = nxtarg(0);
if ( (unsigned int)nullsub_1(v7, ")") )
{
failed("test", ") expected");
return v4;
}
return v4;
}
v1 = nxtarg(1);
--ap;
v2 = v1;
if ( v1 && (!(unsigned int)nullsub_1(v1, "=") || !(unsigned int)nullsub_1(v2, "!=")) )
{
LABEL_4:
v3 = nxtarg(1);
v4 = v3;
if ( v3 )
{
if ( (unsigned int)nullsub_1(v3, "-a") && (unsigned int)nullsub_1(v4, "-o") )
{
if ( (unsigned int)nullsub_1(v4, "=") )
{
if ( (unsigned int)nullsub_1(v4, "!=") )
{
v8 = stoifll(v0);
v9 = nxtarg(0);
v10 = stoifll(v9);
if ( (unsigned int)nullsub_1(v4, "-eq") )
{
if ( (unsigned int)nullsub_1(v4, "-ne") )
{
if ( (unsigned int)nullsub_1(v4, "-gt") )
{
if ( (unsigned int)nullsub_1(v4, "-lt") )
{
if ( (unsigned int)nullsub_1(v4, "-ge") )
{
if ( (unsigned int)nullsub_1(v4, "-le") )
{
v26 = v4;
LODWORD(v4) = 0;
bfailed_constprop_0(v26);
}
else
{
LODWORD(v4) = v8 <= v10;
}
}
else
{
LODWORD(v4) = v8 >= v10;
}
}
else
{
LODWORD(v4) = v8 < v10;
}
}
else
{
LODWORD(v4) = v8 > v10;
}
}
else
{
LODWORD(v4) = v8 != v10;
}
}
else
{
LODWORD(v4) = v8 == v10;
}
}
else
{
v13 = nxtarg(0);
v4 = (unsigned int)nullsub_1(v13, v0) != 0;
}
}
else
{
v16 = nxtarg(0);
v4 = (unsigned int)nullsub_1(v16, v0) == 0;
}
return v4;
}
--ap;
}
return nullsub_1(v0, &unk_9B9) != 0;
}
if ( !(unsigned int)nullsub_1(v0, "-r") )
{
v11 = nxtarg(0);
return chk_access(v11, 256LL, 0LL) == 0;
}
if ( !(unsigned int)nullsub_1(v0, "-w") )
{
v12 = nxtarg(0);
return chk_access(v12, 128LL, 0LL) == 0;
}
if ( !(unsigned int)nullsub_1(v0, "-x") )
{
v15 = nxtarg(0);
return chk_access(v15, 64LL, 0LL) == 0;
}
if ( !(unsigned int)nullsub_1(v0, "-d") )
{
v17 = nxtarg(0);
return filtyp(v17, 0x4000);
}
if ( !(unsigned int)nullsub_1(v0, "-c") )
{
v14 = nxtarg(0);
return filtyp(v14, 0x2000);
}
if ( !(unsigned int)nullsub_1(v0, "-b") )
{
v18 = nxtarg(0);
return filtyp(v18, 24576);
}
LODWORD(v4) = nullsub_1(v0, "-f");
if ( !(_DWORD)v4 )
{
if ( ucb_builtins )
{
v6 = (const char *)nxtarg(0);
if ( stat64(v6, &v31) >= 0 )
LODWORD(v4) = (v31.st_mode & 0xF000) != 0x4000;
return v4;
}
v19 = nxtarg(0);
return filtyp(v19, 0x8000);
}
if ( !(unsigned int)nullsub_1(v0, "-u") )
{
v21 = (const char *)nxtarg(0);
return ftype(v21, 2048);
}
if ( !(unsigned int)nullsub_1(v0, "-g") )
{
v22 = (const char *)nxtarg(0);
return ftype(v22, 1024);
}
if ( !(unsigned int)nullsub_1(v0, "-k") )
{
v23 = (const char *)nxtarg(0);
return ftype(v23, 512);
}
if ( !(unsigned int)nullsub_1(v0, "-p") )
{
v25 = nxtarg(0);
return filtyp(v25, 4096);
}
if ( !(unsigned int)nullsub_1(v0, "-h") || !(unsigned int)nullsub_1(v0, "-L") )
{
v24 = nxtarg(0);
return filtyp(v24, 40960);
}
if ( !(unsigned int)nullsub_1(v0, "-s") )
{
v27 = (const char *)nxtarg(0);
return fsizep(v27);
}
if ( (unsigned int)nullsub_1(v0, "-t") )
{
if ( !(unsigned int)nullsub_1(v0, "-n") )
{
v30 = nxtarg(0);
return nullsub_1(v30, &unk_9B9) != 0;
}
if ( !(unsigned int)nullsub_1(v0, "-z") )
{
v28 = nxtarg(0);
return nullsub_1(v28, &unk_9B9) == 0;
}
goto LABEL_4;
}
if ( ap < ac )
{
v20 = (const char *)nxtarg(0);
if ( (unsigned int)nullsub_1(v20, "-a") && (unsigned int)nullsub_1(v20, "-o") )
{
v29 = atoi(v20);
return isatty(v29);
}
--ap;
}
return isatty(1);
}

canonical_decompiled_code:
int func5()
{
__int64 v0; // rbp
__int64 v1; // rax
__int64 v2; // r12
__int64 v3; // rax
__int64 v4; // r12
const char *v6; // rax
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rax
__int64 v10; // rbx
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rdi
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rdi
__int64 v18; // rdi
__int64 v19; // rdi
const char *v20; // rbp
const char *v21; // rdi
const char *v22; // rdi
const char *v23; // rdi
__int64 v24; // rdi
__int64 v25; // rdi
__int64 v26; // rdi
const char *v27; // rax
__int64 v28; // rax
int v29; // edi
__int64 v30; // rax
struct stat64 v31; // [rsp+0h] [rbp-A8h] BYREF

v0 = func1(0);
if ( !(unsigned int)nullsub_1(v0, "(") )
{
LODWORD(v4) = func8();
v7 = func1(0);
if ( (unsigned int)nullsub_1(v7, ")") )
{
failed("test", ") expected");
return v4;
}
return v4;
}
v1 = func1(1);
--ap;
v2 = v1;
if ( v1 && (!(unsigned int)nullsub_1(v1, "=") || !(unsigned int)nullsub_1(v2, "!=")) )
{
LABEL_4:
v3 = func1(1);
v4 = v3;
if ( v3 )
{
if ( (unsigned int)nullsub_1(v3, "-a") && (unsigned int)nullsub_1(v4, "-o") )
{
if ( (unsigned int)nullsub_1(v4, "=") )
{
if ( (unsigned int)nullsub_1(v4, "!=") )
{
v8 = stoifll(v0);
v9 = func1(0);
v10 = stoifll(v9);
if ( (unsigned int)nullsub_1(v4, "-eq") )
{
if ( (unsigned int)nullsub_1(v4, "-ne") )
{
if ( (unsigned int)nullsub_1(v4, "-gt") )
{
if ( (unsigned int)nullsub_1(v4, "-lt") )
{
if ( (unsigned int)nullsub_1(v4, "-ge") )
{
if ( (unsigned int)nullsub_1(v4, "-le") )
{
v26 = v4;
LODWORD(v4) = 0;
func4(v26);
}
else
{
LODWORD(v4) = v8 <= v10;
}
}
else
{
LODWORD(v4) = v8 >= v10;
}
}
else
{
LODWORD(v4) = v8 < v10;
}
}
else
{
LODWORD(v4) = v8 > v10;
}
}
else
{
LODWORD(v4) = v8 != v10;
}
}
else
{
LODWORD(v4) = v8 == v10;
}
}
else
{
v13 = func1(0);
v4 = (unsigned int)nullsub_1(v13, v0) != 0;
}
}
else
{
v16 = func1(0);
v4 = (unsigned int)nullsub_1(v16, v0) == 0;
}
return v4;
}
--ap;
}
return nullsub_1(v0, &unk_9B9) != 0;
}
if ( !(unsigned int)nullsub_1(v0, "-r") )
{
v11 = func1(0);
return chk_access(v11, 256LL, 0LL) == 0;
}
if ( !(unsigned int)nullsub_1(v0, "-w") )
{
v12 = func1(0);
return chk_access(v12, 128LL, 0LL) == 0;
}
if ( !(unsigned int)nullsub_1(v0, "-x") )
{
v15 = func1(0);
return chk_access(v15, 64LL, 0LL) == 0;
}
if ( !(unsigned int)nullsub_1(v0, "-d") )
{
v17 = func1(0);
return func0(v17, 0x4000);
}
if ( !(unsigned int)nullsub_1(v0, "-c") )
{
v14 = func1(0);
return func0(v14, 0x2000);
}
if ( !(unsigned int)nullsub_1(v0, "-b") )
{
v18 = func1(0);
return func0(v18, 24576);
}
LODWORD(v4) = nullsub_1(v0, "-f");
if ( !(_DWORD)v4 )
{
if ( ucb_builtins )
{
v6 = (const char *)func1(0);
if ( stat64(v6, &v31) >= 0 )
LODWORD(v4) = (v31.st_mode & 0xF000) != 0x4000;
return v4;
}
v19 = func1(0);
return func0(v19, 0x8000);
}
if ( !(unsigned int)nullsub_1(v0, "-u") )
{
v21 = (const char *)func1(0);
return func2(v21, 2048);
}
if ( !(unsigned int)nullsub_1(v0, "-g") )
{
v22 = (const char *)func1(0);
return func2(v22, 1024);
}
if ( !(unsigned int)nullsub_1(v0, "-k") )
{
v23 = (const char *)func1(0);
return func2(v23, 512);
}
if ( !(unsigned int)nullsub_1(v0, "-p") )
{
v25 = func1(0);
return func0(v25, 4096);
}
if ( !(unsigned int)nullsub_1(v0, "-h") || !(unsigned int)nullsub_1(v0, "-L") )
{
v24 = func1(0);
return func0(v24, 40960);
}
if ( !(unsigned int)nullsub_1(v0, "-s") )
{
v27 = (const char *)func1(0);
return func3(v27);
}
if ( (unsigned int)nullsub_1(v0, "-t") )
{
if ( !(unsigned int)nullsub_1(v0, "-n") )
{
v30 = func1(0);
return nullsub_1(v30, &unk_9B9) != 0;
}
if ( !(unsigned int)nullsub_1(v0, "-z") )
{
v28 = func1(0);
return nullsub_1(v28, &unk_9B9) == 0;
}
goto LABEL_4;
}
if ( ap < ac )
{
v20 = (const char *)func1(0);
if ( (unsigned int)nullsub_1(v20, "-a") && (unsigned int)nullsub_1(v20, "-o") )
{
v29 = atoi(v20);
return isatty(v29);
}
--ap;
}
return isatty(1);
}

variable_types:
a
unsigned char *


decompiled_code:
int e2()
{
__int64 v0; // rax

v0 = nxtarg(0);
if ( !(unsigned int)nullsub_1(v0, "!") )
return e3() == 0;
--ap;
return e3();
}

canonical_decompiled_code:
int func6()
{
__int64 v0; // rax

v0 = func1(0);
if ( !(unsigned int)nullsub_1(v0, "!") )
return func5() == 0;
--ap;
return func5();
}

original_code:
static int
e2(void)
{
 if ((cf(nxtarg(0), "!") == 0))
  return(!e3());
 ap--;
 return(e3());
}


decompiled_code:
__int64 e1()
{
unsigned int v0; // er12
__int64 v1; // rax
__int64 result; // rax

v0 = e2();
v1 = nxtarg(1);
if ( v1 && !(unsigned int)nullsub_1(v1, "-a") )
return (unsigned int)e1() & v0;
result = v0;
--ap;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er12
__int64 v1; // rax
__int64 result; // rax

v0 = func6();
v1 = func1(1);
if ( v1 && !(unsigned int)nullsub_1(v1, "-a") )
return (unsigned int)func7() & v0;
result = v0;
--ap;
return result;
}

original_code:
static int
e1(void)
{
 int p1;
 unsigned char *p2;
 p1 = e2();
 p2 = nxtarg(1);
 if ((p2 != 0) && (cf(p2, "-a") == 0))
  return(p1 & e1());
 ap--;
 return(p1);
}

canonical_original_code:
static int e1()
{
 int p1;
 unsigned char *p2;
 p1 = e2();
 p2 = nxtarg(1);
 if ((p2 != 0) && (cf(p2, "-a") == 0))
  return(p1 & e1());
 ap--;
 return(p1);
}


sexp

decompiled_code:
__int64 sexp()
{
unsigned int v0; // er12
__int64 v1; // rax
__int64 result; // rax

v0 = e1();
v1 = nxtarg(1);
if ( v1 && !(unsigned int)nullsub_1(v1, "-o") )
return (unsigned int)sexp() | v0;
result = v0;
--ap;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // er12
__int64 v1; // rax
__int64 result; // rax

v0 = func7();
v1 = func1(1);
if ( v1 && !(unsigned int)nullsub_1(v1, "-o") )
return (unsigned int)func8() | v0;
result = v0;
--ap;
return result;
}

original_code:
static int
sexp(void)
{
 int p1;
 unsigned char *p2;
 p1 = e1();
 p2 = nxtarg(1);
 if (p2 != 0)
 {
  if ((cf(p2, "-o") == 0))
   return(p1 | sexp());
 }
 ap--;
 return(p1);
}

canonical_original_code:
static int sexp()
{
 int p1;
 unsigned char *p2;
 p1 = e1();
 p2 = nxtarg(1);
 if (p2 != 0)
 {
  if ((cf(p2, "-o") == 0))
   return(p1 | sexp());
 }
 ap--;
 return(p1);
}


test

decompiled_code:
_BOOL8 __fastcall test(int a1, __int64 *a2)
{
__int64 v2; // rdi
int v3; // edx
_BOOL4 v4; // er8

ac = a1;
v2 = *a2;
av = (__int64)a2;
ap = 1;
if ( !(unsigned int)nullsub_1(v2, "[") )
{
if ( (unsigned int)nullsub_1(a2[--ac], "]") )
failed("test", "] missing");
}
v3 = ac;
v4 = 1;
a2[ac] = 0LL;
if ( v3 > 1 )
v4 = sexp() == 0;
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(int a1, __int64 *a2)
{
__int64 v2; // rdi
int v3; // edx
_BOOL4 v4; // er8

ac = a1;
v2 = *a2;
av = (__int64)a2;
ap = 1;
if ( !(unsigned int)nullsub_1(v2, "[") )
{
if ( (unsigned int)nullsub_1(a2[--ac], "]") )
failed("test", "] missing");
}
v3 = ac;
v4 = 1;
a2[ac] = 0LL;
if ( v3 > 1 )
v4 = func8() == 0;
return v4;
}

original_code:
int
test(int argn, unsigned char *com[])
{
 ac = argn;
 av = com;
 ap = 1;
 if ((cf(com[0], "[") == 0))
 {
  if (!(cf(com[--ac], "]") == 0))
   failed("test", "] missing");
 }
 com[ac] = 0;
 if (ac <= 1)
  return(1);
 return(sexp() ? 0 : 1);
}

variable_types:
com
unsigned char *[]


absol

decompiled_code:
__int64 __fastcall absol(__int64 *a1)
{
char *v1; // rcx
__int64 v2; // rdx
unsigned int v3; // eax
unsigned int v4; // esi
char *v5; // rcx
__int64 result; // rax

v1 = (char *)*a1;
v2 = *a1 + 1;
*a1 = v2;
v3 = *v1 - 48;
if ( v3 > 7 )
{
*a1 = (__int64)v1;
result = 0LL;
}
else
{
v4 = 0;
do
{
v5 = (char *)v2++;
v4 = v3 + 8 * v4;
*a1 = v2;
v3 = *(char *)(v2 - 1) - 48;
}
while ( v3 <= 7 );
*a1 = (__int64)v5;
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1)
{
char *v1; // rcx
__int64 v2; // rdx
unsigned int v3; // eax
unsigned int v4; // esi
char *v5; // rcx
__int64 result; // rax

v1 = (char *)*a1;
v2 = *a1 + 1;
*a1 = v2;
v3 = *v1 - 48;
if ( v3 > 7 )
{
*a1 = (__int64)v1;
result = 0LL;
}
else
{
v4 = 0;
do
{
v5 = (char *)v2++;
v4 = v3 + 8 * v4;
*a1 = v2;
v3 = *(char *)(v2 - 1) - 48;
}
while ( v3 <= 7 );
*a1 = (__int64)v5;
result = v4;
}
return result;
}

original_code:
static mode_t
absol(const char **ms)
{
 register int c, i;
 i = 0;
 while ((c = *(*ms)++) >= '0' && c <= '7')
  i = (i << 3) + (c - '0');
 (*ms)--;
 return(i);
}

canonical_original_code:
static unsigned int absol(char **ms)
{
 register int c; register int i;
 i = 0;
 while ((c = *(*ms)++) >= '0' && c <= '7')
  i = (i << 3) + (c - '0');
 (*ms)--;
 return(i);
}

variable_types:
ms
char **

variable_types: c int

variable_types: i int

return_type: unsigned int


who

original_code:
static mode_t
who(const char **ms, mode_t *mp)
{
 register int m;
 m = 0;
 *mp = 0;
 for (;;) switch (*(*ms)++) {
 case 'u':
  m |= 05700;
  continue;
 case 'g':
  m |= 02070;
  continue;
 case 'o':
  m |= 00007;
  continue;
 case 'a':
  m |= 07777;
  continue;
 default:
  (*ms)--;
  if (m == 0) {
   m = 07777;
   *mp = um;
  }
  return m;
 }
}

canonical_original_code:
static unsigned int who(char **ms, unsigned int *mp)
{
 register int m;
 m = 0;
 *mp = 0;
 for (;;) switch (*(*ms)++) {
 case 'u':
  m |= 05700;
  continue;
 case 'g':
  m |= 02070;
  continue;
 case 'o':
  m |= 00007;
  continue;
 case 'a':
  m |= 07777;
  continue;
 default:
  (*ms)--;
  if (m == 0) {
   m = 07777;
   *mp = um;
  }
  return m;
 }
}

variable_types:
mp
unsigned int *

variable_types: m int


what

decompiled_code:
__int64 __fastcall what(char **a1)
{
char *v1; // rax
unsigned int v2; // er8
unsigned __int64 v3; // rdx
__int64 v4; // rcx

v1 = *a1;
v2 = 0;
v3 = (unsigned __int8)**a1;
if ( (unsigned __int8)v3 <= 0x3Du )
{
v4 = 0x2000280000000000LL;
if ( _bittest64(&v4, v3) )
{
*a1 = v1 + 1;
v2 = *v1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char **a1)
{
char *v1; // rax
unsigned int v2; // er8
unsigned __int64 v3; // rdx
__int64 v4; // rcx

v1 = *a1;
v2 = 0;
v3 = (unsigned __int8)**a1;
if ( (unsigned __int8)v3 <= 0x3Du )
{
v4 = 0x2000280000000000LL;
if ( _bittest64(&v4, v3) )
{
*a1 = v1 + 1;
v2 = *v1;
}
}
return v2;
}

original_code:
static int
what(const char **ms)
{
 switch (**ms) {
 case '+':
 case '-':
 case '=':
  return *(*ms)++;
 }
 return(0);
}

canonical_original_code:
static int what(char **ms)
{
 switch (**ms) {
 case '+':
 case '-':
 case '=':
  return *(*ms)++;
 }
 return(0);
}


where

original_code:
static mode_t
where(const char **ms, mode_t om, int *lock, int *copy, const mode_t pm)
{
 register mode_t m;
 m = 0;
 *copy = 0;
 switch (**ms) {
 case 'u':
  m = (om & 05700) >> 6;
  goto dup;
 case 'g':
  m = (om & 02070) >> 3;
  goto dup;
 case 'o':
  m = (om & 00007);
 dup:
  *copy = 1;
  m &= (00444|00222|00111);
  m |= (m << 3) | (m << 6);
  ++(*ms);
  return m;
 }
 for (;;) switch (*(*ms)++) {
 case 'r':
  m |= 00444;
  continue;
 case 'w':
  m |= 00222;
  continue;
 case 'x':
  m |= 00111;
  continue;
 case 'X':
  if ((pm&0170000) == 0040000 || (pm & 00111))
   m |= 00111;
  continue;
 case 'l':
  if ((pm&0170000) != 0040000)
   *lock |= 04;
  continue;
 case 's':
  m |= 06000;
  continue;
 case 't':
  m |= 01000;
  continue;
 default:
  (*ms)--;
  return m;
 }
}

canonical_original_code:
static unsigned int where(char **ms, unsigned int om, int *lock, int *copy, unsigned int pm)
{
 register unsigned int m;
 m = 0;
 *copy = 0;
 switch (**ms) {
 case 'u':
  m = (om & 05700) >> 6;
  goto dup;
 case 'g':
  m = (om & 02070) >> 3;
  goto dup;
 case 'o':
  m = (om & 00007);
 dup:
  *copy = 1;
  m &= (00444|00222|00111);
  m |= (m << 3) | (m << 6);
  ++(*ms);
  return m;
 }
 for (;;) switch (*(*ms)++) {
 case 'r':
  m |= 00444;
  continue;
 case 'w':
  m |= 00222;
  continue;
 case 'x':
  m |= 00111;
  continue;
 case 'X':
  if ((pm&0170000) == 0040000 || (pm & 00111))
   m |= 00111;
  continue;
 case 'l':
  if ((pm&0170000) != 0040000)
   *lock |= 04;
  continue;
 case 's':
  m |= 06000;
  continue;
 case 't':
  m |= 01000;
  continue;
 default:
  (*ms)--;
  return m;
 }
}

variable_types:
om
unsigned int

variable_types:
lock
int *

variable_types:
copy
int *

variable_types:
pm
unsigned int

variable_types:
m
unsigned int


newmode

original_code:
static mode_t
newmode(const char *ms, const mode_t pm)
{
 register mode_t o, m, b;
 int lock, setsgid = 0, cleared = 0, copy = 0;
 mode_t nm, om, mm;
 nm = om = pm;
 m = absol(&ms);
 if (!*ms) {
  nm = m;
  goto out;
 }
 if ((lock = (nm&0170000) != 0040000 && (nm&(02000|(0100 >> 3))) == 02000)
   == 01)
  nm &= ~(mode_t)02000;
 do {
  m = who(&ms, &mm);
  while (o = what(&ms)) {
   b = where(&ms, nm, &lock, &copy, pm);
   switch (o) {
   case '+':
    nm |= b & m & ~mm;
    if (b & 02000)
     setsgid = 1;
    if (lock & 04)
     lock |= 02;
    break;
   case '-':
    nm &= ~(b & m & ~mm);
    if (b & 02000)
     setsgid = 1;
    if (lock & 04)
     lock = 0;
    break;
   case '=':
    nm &= ~m;
    nm |= b & m & ~mm;
    lock &= ~01;
    if (lock & 04)
     lock |= 02;
    om = 0;
    if (copy == 0)
     cleared = 1;
    break;
   }
   lock &= ~04;
  }
 } while (*ms++ == ',');
 if (*--ms)
  failed(&badumask[4], badumask);
out: if (pm & 0040000) {
  if ((pm & 02000) && setsgid == 0)
   nm |= 02000;
  else if ((nm & 02000) && setsgid == 0)
   nm &= ~(mode_t)02000;
 }
 return(nm);
}

canonical_original_code:
static unsigned int newmode(char *ms, unsigned int pm)
{
 register unsigned int o; register unsigned int m; register unsigned int b;
 int lock; int setsgid = 0; int cleared = 0; int copy = 0;
 unsigned int nm; unsigned int om; unsigned int mm;
 nm = om = pm;
 m = absol(&ms);
 if (!*ms) {
  nm = m;
  goto out;
 }
 if ((lock = (nm&0170000) != 0040000 && (nm&(02000|(0100 >> 3))) == 02000)
   == 01)
  nm &= ~(unsigned int)02000;
 do {
  m = who(&ms, &mm);
  while (o = what(&ms)) {
   b = where(&ms, nm, &lock, &copy, pm);
   switch (o) {
   case '+':
    nm |= b & m & ~mm;
    if (b & 02000)
     setsgid = 1;
    if (lock & 04)
     lock |= 02;
    break;
   case '-':
    nm &= ~(b & m & ~mm);
    if (b & 02000)
     setsgid = 1;
    if (lock & 04)
     lock = 0;
    break;
   case '=':
    nm &= ~m;
    nm |= b & m & ~mm;
    lock &= ~01;
    if (lock & 04)
     lock |= 02;
    om = 0;
    if (copy == 0)
     cleared = 1;
    break;
   }
   lock &= ~04;
  }
 } while (*ms++ == ',');
 if (*--ms)
  failed(&badumask[4], badumask);
out: if (pm & 0040000) {
  if ((pm & 02000) && setsgid == 0)
   nm |= 02000;
  else if ((nm & 02000) && setsgid == 0)
   nm &= ~(unsigned int)02000;
 }
 return(nm);
}

variable_types:
ms
char *

variable_types:
o
unsigned int

variable_types:
b
unsigned int

variable_types: lock int

variable_types: setsgid int

variable_types: cleared int

variable_types: copy int

variable_types:
nm
unsigned int

variable_types:
mm
unsigned int