estabf

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

repo: mutoso-mirrors/heirloom-sh

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

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

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

result = standin;
*(_QWORD *)(a1 + 56) = standin;
*(_WORD *)(a1 + 8) = 0;
*(_QWORD *)(a1 + 48) = 0LL;
standin = a1;
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;
}

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

return_type: void


pop

decompiled_code:
__int64 pop()
{
__int64 v0; // rbx
__int64 result; // rax

v0 = standin;
result = 0LL;
if ( *(_QWORD *)(standin + 56LL) )
{
if ( (int)*standin >= 0 )
close(*standin);
standin = *(_QWORD *)(v0 + 56);
result = 0xFFFFFFFFLL;
}
return result;
}

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

v0 = standin;
result = 0LL;
if ( *(_QWORD *)(standin + 56LL) )
{
if ( (int)*standin >= 0 )
close(*standin);
standin = *(_QWORD *)(v0 + 56);
result = 0xFFFFFFFFLL;
}
return result;
}

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

return_type: int


pushtemp

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

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

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

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

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

variable_types: fd int

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


poptemp

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

result = 0LL;
if ( tmpfptr )
{
close(*(_DWORD *)tmpfptr);
tmpfptr = *(_QWORD *)(tmpfptr + 8);
result = 0xFFFFFFFFLL;
}
return result;
}

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

result = 0LL;
if ( tmpfptr )
{
close(*(_DWORD *)tmpfptr);
tmpfptr = *(_QWORD *)(tmpfptr + 8);
result = 0xFFFFFFFFLL;
}
return result;
}

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 || *a1 < 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 || *a1 < 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:
__int64 __fastcall chkopen(const char *a1, int a2)
{
int v2; // ebx

v2 = open64(a1, a2, 438LL);
if ( v2 < 0 )
failed(a1, &badopen);
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, int a2)
{
int v2; // ebx

v2 = open64(a1, a2, 438LL);
if ( v2 < 0 )
failed(a1, &badopen);
return (unsigned int)v2;
}

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:
__int64 __fastcall create(const char *a1)
{
int v1; // ebx

v1 = creat64(a1, 0x1B6u);
if ( v1 < 0 )
failed(a1, &badcreate);
return (unsigned int)v1;
}

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

v1 = creat64(a1, 0x1B6u);
if ( v1 < 0 )
failed(a1, &badcreate);
return (unsigned int)v1;
}

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

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

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)
{
_BYTE *v1; // r14
int v2; // er15
unsigned int v3; // eax
__int64 v4; // rdi
_BYTE *i; // rbp
_BYTE *v6; // rbx
unsigned int v7; // eax
unsigned int v8; // er12
_BYTE *j; // rbp
unsigned int v10; // eax
_BYTE *v11; // rbp
_BYTE *v12; // r13
int v13; // eax
unsigned int v14; // eax
int v15; // er13
_BYTE *buf; // [rsp+0h] [rbp-58h]
int fd; // [rsp+Ch] [rbp-4Ch]
char v18[72]; // [rsp+10h] [rbp-48h] BYREF

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

canonical_decompiled_code:
void __fastcall func11(__int64 a1)
{
_BYTE *v1; // r14
int v2; // er15
unsigned int v3; // eax
__int64 v4; // rdi
_BYTE *i; // rbp
_BYTE *v6; // rbx
unsigned int v7; // eax
unsigned int v8; // er12
_BYTE *j; // rbp
unsigned int v10; // eax
_BYTE *v11; // rbp
_BYTE *v12; // r13
int v13; // eax
unsigned int v14; // eax
int v15; // er13
_BYTE *buf; // [rsp+0h] [rbp-58h]
int fd; // [rsp+Ch] [rbp-4Ch]
char v18[72]; // [rsp+10h] [rbp-48h] BYREF

if ( a1 )
{
func11(*(_QWORD *)(a1 + 32));
v1 = (_BYTE *)mactrim(*(_QWORD *)(a1 + 8));
v2 = *(_DWORD *)a1 & 0x200;
if ( nosubst )
*(_DWORD *)a1 &= 0xFFFFFFEF;
fd = func10((__int64)v18);
if ( fndef )
*(_QWORD *)(a1 + 8) = make(&tmpout);
else
*(_QWORD *)(a1 + 8) = cpystak(&tmpout);
*(_QWORD *)(a1 + 32) = iotemp;
iotemp = a1;
buf = (_BYTE *)locstak();
if ( v2 )
{
for ( *(_DWORD *)a1 &= 0xFFFFFDFF; *v1 == 9; ++v1 )
;
}
LABEL_57:
v12 = buf;
while ( 1 )
{
chkpr();
if ( nosubst )
{
v14 = readwc();
v4 = v14;
if ( v2 && v14 == 9 )
{
do
{
v3 = readwc();
v4 = v3;
}
while ( v3 == 9 );
}
v6 = v12;
while ( (unsigned int)v4 > 0x7F || (*((_BYTE *)&sh_ctype1 + (unsigned int)v4) & 0x30) == 0 )
{
for ( i = (_BYTE *)readw(v4); *i; *(v6 - 1) = *(i - 1) )
{
if ( brkend <= (unsigned __int64)v6 )
growstak(v6);
++i;
++v6;
}
v4 = (unsigned int)readwc();
}
}
else
{
v7 = nextwc();
v8 = v7;
if ( v2 && v7 == 9 )
{
do
v8 = nextwc();
while ( v8 == 9 );
}
v6 = v12;
while ( v8 > 0x7F || (*((_BYTE *)&sh_ctype1 + v8) & 0x30) == 0 )
{
for ( j = (_BYTE *)readw(v8); *j; *(v6 - 1) = *(j - 1) )
{
if ( brkend <= (unsigned __int64)v6 )
growstak(v6);
++j;
++v6;
}
if ( v8 == 92 )
{
v10 = readwc();
v11 = (_BYTE *)readw(v10);
if ( *v11 )
{
do
{
if ( brkend <= (unsigned __int64)v6 )
growstak(v6);
*v6++ = *v11++;
}
while ( *v11 );
}
else
{
if ( brkend <= (unsigned __int64)v6 )
growstak(v6);
*v6++ = *v11;
}
}
v8 = nextwc();
}
}
if ( brkend <= (unsigned __int64)v6 )
growstak(v6);
*v6 = 0;
if ( *(_WORD *)(standin + 8LL) || !(unsigned int)nullsub_1(v12, v1) )
break;
if ( brkend <= (unsigned __int64)v6 )
growstak(v6);
v12 = v6 + 1;
*v6 = 10;
v13 = (_DWORD)v6 + 1 - (_DWORD)buf;
if ( v13 > 511 )
{
write(fd, buf, v13);
goto LABEL_57;
}
}
v15 = (_DWORD)v12 - (_DWORD)buf;
if ( v15 > 0 )
write(fd, buf, v15);
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_4:
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_4;
}
}
*(_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_4:
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_4;
}
}
*(_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

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


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)
{
__int64 v2; // rbx
int v3; // edi

LODWORD(v2) = topfd - 1;
if ( (int)v2 >= a1 )
{
v2 = (int)v2;
do
{
v3 = *((_DWORD *)&fdmap + 2 * v2 + 1);
if ( v3 > 0 )
renamef(v3, *((_DWORD *)&fdmap + 2 * v2));
else
close(*((_DWORD *)&fdmap + 2 * v2));
--v2;
}
while ( a1 <= (int)v2 );
}
topfd = a1;
}

canonical_decompiled_code:
void __fastcall func15(int a1)
{
__int64 v2; // rbx
int v3; // edi

LODWORD(v2) = topfd - 1;
if ( (int)v2 >= a1 )
{
v2 = (int)v2;
do
{
v3 = *((_DWORD *)&fdmap + 2 * v2 + 1);
if ( v3 > 0 )
func8(v3, *((_DWORD *)&fdmap + 2 * v2));
else
close(*((_DWORD *)&fdmap + 2 * v2));
--v2;
}
while ( a1 <= (int)v2 );
}
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

decompiled_code:
__int64 freedolh()
{
__int64 v0; // rbp
__int64 result; // rax
_QWORD *i; // rbx

v0 = dolh;
if ( dolh )
{
result = (unsigned int)(*(_DWORD *)(dolh + 8) - 1);
*(_DWORD *)(dolh + 8) = result;
if ( !(_DWORD)result )
{
for ( i = *(_QWORD **)(v0 + 16); *i; ++i )
((void (*)(void))sh_free)();
sh_free(*(_QWORD *)(v0 + 16));
result = sh_free(v0);
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rbp
__int64 result; // rax
_QWORD *i; // rbx

v0 = dolh;
if ( dolh )
{
result = (unsigned int)(*(_DWORD *)(dolh + 8) - 1);
*(_DWORD *)(dolh + 8) = result;
if ( !(_DWORD)result )
{
for ( i = *(_QWORD **)(v0 + 16); *i; ++i )
((void (*)(void))sh_free)();
sh_free(*(_QWORD *)(v0 + 16));
result = sh_free(v0);
}
}
return result;
}

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)
{
int v2; // ebp
_BYTE *v3; // rax
__int64 v4; // rdi
char *v5; // rcx
char v6; // dl
char *v7; // rax
char v8; // dl
const char *v9; // r13
char v10; // al
_QWORD *v11; // r14
int v13; // eax
char *v14; // rbx
unsigned __int8 v15; // al
const char *v16; // r14
char v17; // al
int v18; // er13
char *v19; // rbx
unsigned __int8 v20; // al
wchar_t pwc[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = a1;
if ( a1 <= 1 )
goto LABEL_4;
v3 = (_BYTE *)a2[1];
if ( *v3 != 45 )
{
if ( *v3 == 43 )
{
v16 = v3 + 1;
v17 = v3[1];
if ( v17 )
{
do
{
if ( mb_cur_max > 1 && v17 < 0 )
{
v18 = mbtowc(pwc, v16, mb_cur_max);
}
else
{
pwc[0] = (unsigned __int8)v17;
v18 = v17 != 0;
}
if ( v18 <= 0 )
{
++v16;
}
else
{
v20 = flagchar;
if ( flagchar )
{
v19 = &flagchar;
do
{
if ( v20 == pwc[0] )
break;
v20 = *++v19;
}
while ( *v19 );
}
else
{
v19 = &flagchar;
}
if ( !(unsigned int)any((unsigned int)pwc[0], "sicrp") && (unsigned __int8)*v19 == pwc[0] )
{
flags &= ~(unsigned __int64)*(&flagval + v19 - &flagchar);
if ( pwc[0] == 101 )
eflag = 0;
}
v16 += v18;
}
v17 = *v16;
}
while ( *v16 );
}
a2[1] = *a2;
v2 = a1 - 1;
}
goto LABEL_4;
}
v8 = v3[1];
if ( v8 == 45 )
{
a2[1] = *a2;
return (unsigned int)(a1 - 1);
}
if ( v8 )
{
v9 = v3 + 1;
v10 = v3[1];
goto LABEL_59;
}
flags &= 0xFFFFFFFFFFFFE7FFLL;
v9 = v3 + 1;
v10 = v3[1];
v11 = a2;
if ( v10 )
{
LABEL_59:
v11 = a2;
while ( 1 )
{
if ( mb_cur_max > 1 && v10 < 0 )
{
v13 = mbtowc(pwc, v9, mb_cur_max);
}
else
{
pwc[0] = (unsigned __int8)v10;
v13 = v10 != 0;
}
if ( v13 <= 0 )
{
pwc[0] = *(unsigned __int8 *)v9;
failed(a2[1], &badopt);
v13 = 1;
}
v9 += v13;
v15 = flagchar;
if ( flagchar )
break;
v14 = &flagchar;
LABEL_29:
if ( !pwc[0] )
goto LABEL_14;
if ( v2 > 2 && pwc[0] == 99 && !comdiv )
{
comdiv = v11[2];
v11[1] = *v11;
++v11;
--v2;
goto LABEL_19;
}
LABEL_18:
failed(a2[1], &badopt);
LABEL_19:
v10 = *v9;
if ( !*v9 )
goto LABEL_10;
}
v14 = &flagchar;
while ( v15 != pwc[0] )
{
v15 = *++v14;
if ( !*v14 )
goto LABEL_29;
}
LABEL_14:
if ( (unsigned int)nullsub_1(*a2, &unk_7A0) || !(unsigned int)any((unsigned int)pwc[0], "sicrp") )
{
flags |= (unsigned __int64)*(&flagval + v14 - &flagchar);
if ( (flags & 0x10) != 0 )
eflag = 16;
goto LABEL_19;
}
goto LABEL_18;
}
LABEL_10:
v11[1] = *v11;
--v2;
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 ( *v7 );
}
else
{
v5 = (char *)&flagadr;
}
}
*v5 = 0;
return (unsigned int)v2;
}

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

v2 = a1;
if ( a1 <= 1 )
goto LABEL_4;
v3 = (_BYTE *)a2[1];
if ( *v3 != 45 )
{
if ( *v3 == 43 )
{
v16 = v3 + 1;
v17 = v3[1];
if ( v17 )
{
do
{
if ( mb_cur_max > 1 && v17 < 0 )
{
v18 = mbtowc(pwc, v16, mb_cur_max);
}
else
{
pwc[0] = (unsigned __int8)v17;
v18 = v17 != 0;
}
if ( v18 <= 0 )
{
++v16;
}
else
{
v20 = flagchar;
if ( flagchar )
{
v19 = &flagchar;
do
{
if ( v20 == pwc[0] )
break;
v20 = *++v19;
}
while ( *v19 );
}
else
{
v19 = &flagchar;
}
if ( !(unsigned int)any((unsigned int)pwc[0], "sicrp") && (unsigned __int8)*v19 == pwc[0] )
{
flags &= ~(unsigned __int64)*(&flagval + v19 - &flagchar);
if ( pwc[0] == 101 )
eflag = 0;
}
v16 += v18;
}
v17 = *v16;
}
while ( *v16 );
}
a2[1] = *a2;
v2 = a1 - 1;
}
goto LABEL_4;
}
v8 = v3[1];
if ( v8 == 45 )
{
a2[1] = *a2;
return (unsigned int)(a1 - 1);
}
if ( v8 )
{
v9 = v3 + 1;
v10 = v3[1];
goto LABEL_59;
}
flags &= 0xFFFFFFFFFFFFE7FFLL;
v9 = v3 + 1;
v10 = v3[1];
v11 = a2;
if ( v10 )
{
LABEL_59:
v11 = a2;
while ( 1 )
{
if ( mb_cur_max > 1 && v10 < 0 )
{
v13 = mbtowc(pwc, v9, mb_cur_max);
}
else
{
pwc[0] = (unsigned __int8)v10;
v13 = v10 != 0;
}
if ( v13 <= 0 )
{
pwc[0] = *(unsigned __int8 *)v9;
failed(a2[1], &badopt);
v13 = 1;
}
v9 += v13;
v15 = flagchar;
if ( flagchar )
break;
v14 = &flagchar;
LABEL_29:
if ( !pwc[0] )
goto LABEL_14;
if ( v2 > 2 && pwc[0] == 99 && !comdiv )
{
comdiv = v11[2];
v11[1] = *v11;
++v11;
--v2;
goto LABEL_19;
}
LABEL_18:
failed(a2[1], &badopt);
LABEL_19:
v10 = *v9;
if ( !*v9 )
goto LABEL_10;
}
v14 = &flagchar;
while ( v15 != pwc[0] )
{
v15 = *++v14;
if ( !*v14 )
goto LABEL_29;
}
LABEL_14:
if ( (unsigned int)nullsub_1(*a2, &unk_7A0) || !(unsigned int)any((unsigned int)pwc[0], "sicrp") )
{
flags |= (unsigned __int64)*(&flagval + v14 - &flagchar);
if ( (flags & 0x10) != 0 )
eflag = 16;
goto LABEL_19;
}
goto LABEL_18;
}
LABEL_10:
v11[1] = *v11;
--v2;
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 ( *v7 );
}
else
{
v5 = (char *)&flagadr;
}
}
*v5 = 0;
return (unsigned int)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(_QWORD *a1)
{
_QWORD *v1; // rax
unsigned int v2; // ebx
__int64 result; // rax

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

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

if ( *a1 )
{
v1 = a1 + 1;
v2 = 0;
do
{
++v2;
++v1;
}
while ( *(v1 - 1) );
}
else
{
v2 = 0;
}
func0();
result = func1((__int64)a1, v2);
dolh = result;
dolc = v2 - 1;
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 result; // rax

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

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

if ( globdolv )
dolv = globdolv;
if ( globdolc )
dolc = globdolc;
if ( globdolh )
dolh = globdolh;
globdolv = 0LL;
globdolc = 0;
globdolh = 0LL;
do
argfor = func4(argfor);
while ( argfor );
while ( (unsigned int)pop() )
;
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)
{
if ( !a1 )
{
globdolh = dolh;
globdolv = dolv;
globdolc = dolc;
}
useargs();
return dolh;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
if ( !a1 )
{
globdolh = dolh;
globdolv = dolv;
globdolc = dolc;
}
func7();
return dolh;
}

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(char *a1)
{
char *v1; // rbp
char *v2; // rbx
char i; // al
__int64 result; // rax
__int64 v5; // rsi
__int64 v6; // rax
__int128 v7; // rdi
_BYTE *v8; // rdx
char v9; // al
_BYTE *v10; // rsi
_BYTE *v11; // rax
unsigned __int8 v12; // dl
char *v13; // rcx
char *v14; // rdx

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

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char *v1; // rbp
char *v2; // rbx
char i; // al
__int64 result; // rax
__int64 v5; // rsi
__int64 v6; // rax
__int128 v7; // rdi
_BYTE *v8; // rdx
char v9; // al
_BYTE *v10; // rsi
_BYTE *v11; // rax
unsigned __int8 v12; // dl
char *v13; // rcx
char *v14; // rdx

v1 = a1;
func0(a1);
v2 = &a1[*a1 == 47];
for ( i = *v2; *v2; i = *v2 )
{
if ( i == 46 && v2[1] == 47 )
{
movstr(v2 + 2, v2);
}
else
{
v8 = v2 + 1;
v9 = v2[1];
if ( v9 && v9 != 47 )
{
do
v9 = *++v8;
while ( *v8 && v9 != 47 );
}
v2 = &v8[-(v9 == 0) + 1];
}
}
if ( a1 < v2 - 1 && *(v2 - 1) == 46 && *(v2 - 2) == 47 )
{
if ( a1 >= v2 - 2 )
*(v2 - 1) = 0;
else
*(v2 - 2) = 0;
}
func0(a1);
result = (unsigned __int8)*a1;
if ( (_BYTE)result == 46 )
{
if ( !a1[1] )
return result;
}
else if ( (_BYTE)result == 47 )
{
v1 = a1 + 1;
cwdname[0] = 47;
didpwd = 2;
LABEL_30:
result = (unsigned __int8)*v1;
*((_QWORD *)&v7 + 1) = (unsigned int)((_DWORD)cwdname + 1);
if ( (_BYTE)result )
goto LABEL_45;
cwdname[1] = 0;
return result;
}
if ( !didpwd )
return result;
didpwd = 2;
v5 = (int)length(cwdname);
v6 = v5 - 1;
if ( v5 == 2 )
goto LABEL_30;
*((_QWORD *)&v7 + 1) = &cwdname[v5];
cwdname[v6] = 47;
for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*v1 )
{
LABEL_45:
if ( (_BYTE)result == 46 && v1[1] == 46 && ((v12 = v1[2], v12 == 47) || !v12) )
{
*(_QWORD *)&v7 = (unsigned int)((_DWORD)cwdname + 2);
v10 = (_BYTE *)((v7 - (unsigned __int128)*((unsigned __int64 *)&v7 + 1)) >> 64);
do
v11 = v10--;
while ( *v10 != 47 );
if ( v12 == 47 )
v1 += 3;
else
v1 += 2;
*((_QWORD *)&v7 + 1) = v11;
}
else
{
if ( *((_QWORD *)&v7 + 1) >= (unsigned __int64)&cwdname[4097] )
{
didpwd = 0;
return result;
}
v13 = v1 + 1;
v14 = (char *)(*((_QWORD *)&v7 + 1) + 1LL);
**((_BYTE **)&v7 + 1) = result;
result = (unsigned __int8)v1[1];
if ( (_BYTE)result && (_BYTE)result != 47 )
{
if ( v14 >= &cwdname[4097] )
{
LABEL_56:
didpwd = 0;
return result;
}
while ( 1 )
{
++v13;
*v14++ = result;
result = (unsigned __int8)*v13;
if ( !(_BYTE)result || (_BYTE)result == 47 )
break;
if ( v14 == &cwdname[4097] )
goto LABEL_56;
}
}
if ( (_BYTE)result )
{
if ( v14 >= &cwdname[4097] )
{
didpwd = 0;
return result;
}
v1 = v13 + 1;
*((_QWORD *)&v7 + 1) = v14 + 1;
*v14 = result;
}
else
{
*((_QWORD *)&v7 + 1) = v14;
v1 = v13;
}
}
}
if ( *((_QWORD *)&v7 + 1) >= (unsigned __int64)&cwdname[4097] )
{
didpwd = 0;
}
else
{
**((_BYTE **)&v7 + 1) = 0;
result = *((_QWORD *)&v7 + 1) - 1LL;
if ( *((_QWORD *)&v7 + 1) - 1LL > (unsigned __int64)cwdname && *(_BYTE *)(*((_QWORD *)&v7 + 1) - 1LL) == 47 )
*(_BYTE *)(*((_QWORD *)&v7 + 1) - 1LL) = 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
unsigned __int64 v1; // rbx
_BYTE *v2; // r12
char v3; // bp
struct stat64 v4; // [rsp+0h] [rbp-138h] BYREF
struct stat64 v5; // [rsp+90h] [rbp-A8h] BYREF

result = didpwd;
if ( !didpwd )
return result;
if ( didpwd != 2 )
{
result = stat64(cwdname, &v5);
if ( result == -1 )
{
didpwd = 0;
return result;
}
goto LABEL_16;
}
if ( !cwdname[1] )
{
LABEL_14:
didpwd = -1;
LABEL_16:
result = stat64(".", &v4);
if ( result == -1 || (result = v4.st_dev, v5.st_dev != v4.st_dev) || (result = v4.st_ino, v5.st_ino != v4.st_ino) )
didpwd = 0;
return result;
}
v1 = (unsigned int)((_DWORD)cwdname + 1);
while ( 1 )
{
do
{
v2 = (_BYTE *)v1++;
v3 = *(_BYTE *)(v1 - 1);
}
while ( v3 && v3 != 47 );
*(_BYTE *)(v1 - 1) = 0;
result = lstat64(cwdname, &v5);
if ( result == -1 )
break;
result = v5.st_mode & 0xF000;
if ( result == 40960 )
break;
*(_BYTE *)(v1 - 1) = v3;
if ( !v3 )
v1 = (unsigned __int64)v2;
if ( !*(_BYTE *)v1 )
goto LABEL_14;
}
didpwd = 0;
*(_BYTE *)(v1 - 1) = v3;
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
unsigned __int64 v1; // rbx
_BYTE *v2; // r12
char v3; // bp
struct stat64 v4; // [rsp+0h] [rbp-138h] BYREF
struct stat64 v5; // [rsp+90h] [rbp-A8h] BYREF

result = didpwd;
if ( !didpwd )
return result;
if ( didpwd != 2 )
{
result = stat64(cwdname, &v5);
if ( result == -1 )
{
didpwd = 0;
return result;
}
goto LABEL_16;
}
if ( !cwdname[1] )
{
LABEL_14:
didpwd = -1;
LABEL_16:
result = stat64(".", &v4);
if ( result == -1 || (result = v4.st_dev, v5.st_dev != v4.st_dev) || (result = v4.st_ino, v5.st_ino != v4.st_ino) )
didpwd = 0;
return result;
}
v1 = (unsigned int)((_DWORD)cwdname + 1);
while ( 1 )
{
do
{
v2 = (_BYTE *)v1++;
v3 = *(_BYTE *)(v1 - 1);
}
while ( v3 && v3 != 47 );
*(_BYTE *)(v1 - 1) = 0;
result = lstat64(cwdname, &v5);
if ( result == -1 )
break;
result = v5.st_mode & 0xF000;
if ( result == 40960 )
break;
*(_BYTE *)(v1 - 1) = v3;
if ( !v3 )
v1 = (unsigned __int64)v2;
if ( !*(_BYTE *)v1 )
goto LABEL_14;
}
didpwd = 0;
*(_BYTE *)(v1 - 1) = v3;
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 )
{
if ( !getcwd(cwdname, 0x1001uLL) )
cwdname[0] = 0;
didpwd = -1;
}
return cwdname;
}

canonical_decompiled_code:
char *func3()
{
func2();
if ( !didpwd )
{
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);
}

return_type: unsigned char *


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
{
prc_buff(v0);
v0 = *++v1;
}
while ( *v1 );
}
return prc_buff(10LL);
}

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

func2();
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
{
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)
{
int v1; // eax

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

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

if ( ap < ac )
goto LABEL_4;
if ( !a1 )
{
failed("test", "argument expected");
LABEL_4:
v1 = ap++;
return *(_QWORD *)(av + 8LL * 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; // edx
_BOOL8 result; // rax
struct stat64 v4; // [rsp+0h] [rbp-98h] BYREF

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

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

v2 = stat64(a1, &v4);
result = 0LL;
if ( v2 >= 0 )
result = (v4.st_mode & a2) == 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; // edx
_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; // edx
_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:
__int64 e3()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rbp
unsigned int v5; // ebp
__int64 v6; // rax
const char *v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
const char *v17; // rax
const char *v18; // rax
const char *v19; // rax
__int64 v20; // rax
const char *v21; // rbx
const char *v22; // rax
int v23; // eax
__int64 v24; // rax
__int64 v25; // rax
__int64 v26; // rbx
__int64 v27; // rax
__int64 v28; // r12
__int64 v29; // rax
__int64 v30; // rax
struct stat64 v31; // [rsp+0h] [rbp-A8h] BYREF

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

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

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

variable_types:
a
unsigned char *


decompiled_code:
__int64 e2()
{
__int64 v0; // rdi

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

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rdi

v0 = func1(0);
if ( !(unsigned int)nullsub_1(v0, "!") )
return (unsigned int)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; // ebx
__int64 v1; // rax

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

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

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

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; // ebx
__int64 v1; // rax

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

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

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

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, _QWORD *a2)
{
int v2; // eax
_BOOL4 v3; // edx

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

canonical_decompiled_code:
_BOOL8 __fastcall func9(int a1, _QWORD *a2)
{
int v2; // eax
_BOOL4 v3; // edx

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

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(_QWORD *a1)
{
char *v1; // rax
int v2; // edx
unsigned int v3; // ecx

v1 = (char *)(*a1)++;
v2 = *v1;
if ( (unsigned int)(v2 - 48) > 7 )
{
v3 = 0;
}
else
{
v3 = 0;
do
{
v3 = v2 + 8 * v3 - 48;
v1 = (char *)(*a1)++;
v2 = *v1;
}
while ( (unsigned int)(v2 - 48) <= 7 );
}
*a1 = v1;
return v3;
}

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(unsigned __int8 **a1)
{
char *v1; // rdx
unsigned __int8 v2; // cl
__int64 v3; // rax
unsigned int v4; // ecx

v1 = (char *)*a1;
v2 = **a1;
if ( v2 > 0x3Du )
return 0;
v3 = 1LL << v2;
v4 = 0;
if ( (v3 & 0x2000280000000000LL) != 0 )
{
*a1 = (unsigned __int8 *)(v1 + 1);
v4 = *v1;
}
return v4;
}

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

v1 = (char *)*a1;
v2 = **a1;
if ( v2 > 0x3Du )
return 0;
v3 = 1LL << v2;
v4 = 0;
if ( (v3 & 0x2000280000000000LL) != 0 )
{
*a1 = (unsigned __int8 *)(v1 + 1);
v4 = *v1;
}
return v4;
}

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

decompiled_code:
__int64 __fastcall where(char **a1, unsigned int a2, _DWORD *a3, _DWORD *a4, __int16 a5)
{
char v6; // al
unsigned int v7; // esi
int v8; // ecx
int v9; // er8
char *v10; // rdx
int v11; // eax

*a4 = 0;
v6 = **a1;
switch ( v6 )
{
case 'o':
v11 = a2 & 7;
goto LABEL_7;
case 'u':
v11 = (a2 >> 6) & 0x2F;
LABEL_7:
*a4 = 1;
v7 = v11 | (v11 << 6) | (8 * v11);
++*a1;
return v7;
case 'g':
v11 = (a2 >> 3) & 0x87;
goto LABEL_7;
}
v7 = 0;
v8 = a5 & 0xF000;
v9 = a5 & 0x49;
while ( 2 )
{
v10 = (*a1)++;
switch ( *v10 )
{
case 'X':
if ( v8 == 0x4000 || v9 )
v7 |= 0x49u;
continue;
case 'l':
if ( v8 != 0x4000 )
*a3 |= 4u;
continue;
case 'r':
v7 |= 0x124u;
continue;
case 's':
v7 |= 0xC00u;
continue;
case 't':
v7 |= 0x200u;
continue;
case 'w':
LOBYTE(v7) = v7 | 0x92;
continue;
case 'x':
v7 |= 0x49u;
continue;
default:
*a1 = v10;
break;
}
break;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(char **a1, unsigned int a2, _DWORD *a3, _DWORD *a4, __int16 a5)
{
char v6; // al
unsigned int v7; // esi
int v8; // ecx
int v9; // er8
char *v10; // rdx
int v11; // eax

*a4 = 0;
v6 = **a1;
switch ( v6 )
{
case 'o':
v11 = a2 & 7;
goto LABEL_7;
case 'u':
v11 = (a2 >> 6) & 0x2F;
LABEL_7:
*a4 = 1;
v7 = v11 | (v11 << 6) | (8 * v11);
++*a1;
return v7;
case 'g':
v11 = (a2 >> 3) & 0x87;
goto LABEL_7;
}
v7 = 0;
v8 = a5 & 0xF000;
v9 = a5 & 0x49;
while ( 2 )
{
v10 = (*a1)++;
switch ( *v10 )
{
case 'X':
if ( v8 == 0x4000 || v9 )
v7 |= 0x49u;
continue;
case 'l':
if ( v8 != 0x4000 )
*a3 |= 4u;
continue;
case 'r':
v7 |= 0x124u;
continue;
case 's':
v7 |= 0xC00u;
continue;
case 't':
v7 |= 0x200u;
continue;
case 'w':
LOBYTE(v7) = v7 | 0x92;
continue;
case 'x':
v7 |= 0x49u;
continue;
default:
*a1 = v10;
break;
}
break;
}
return v7;
}

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


sysumask

original_code:
void
sysumask(int argc, char **argv)
{
 BOOL symbolic = 0;
 mode_t mode;
 register int i;
 register char *cp;
 if (argc > 1 && (cf(argv[1], "-S") == 0)) {
  umask(um = mode = umask(0));
  prs_buff("u=");
  if ((mode & 0400) == 0)
   prc_buff('r');
  if ((mode & 0200) == 0)
   prc_buff('w');
  if ((mode & 0100) == 0)
   prc_buff('x');
  prs_buff(",g=");
  if ((mode & 040) == 0)
   prc_buff('r');
  if ((mode & 020) == 0)
   prc_buff('w');
  if ((mode & 010) == 0)
   prc_buff('x');
  prs_buff(",o=");
  if ((mode & 04) == 0)
   prc_buff('r');
  if ((mode & 02) == 0)
   prc_buff('w');
  if ((mode & 01) == 0)
   prc_buff('x');
  prc_buff('\n');
 } else if (argc == 1) {
  umask(um = mode = umask(0));
  prc_buff('0');
  for (i = 6; i >= 0; i -= 3)
   prc_buff(((mode >> i) & 07) +'0');
  prc_buff('\n');
 } else {
  for (cp = argv[1]; *cp; cp++) {
   if (*cp < '0' || *cp > '7') {
    symbolic = 1;
    break;
   }
  }
  if (symbolic) {
   umask(um = mode = umask(0));
   mode = newmode(argv[1], ~mode);
   mode = (~mode & 0777);
   umask(mode);
  } else {
   mode = 0;
   while ((i = *argv[1]++) >= '0' && i <= '7')
    mode = (mode << 3) + i - '0';
   umask(mode);
  }
 }
}

canonical_original_code:
void sysumask(int argc, char **argv)
{
 short symbolic = 0;
 unsigned int mode;
 register int i;
 register char *cp;
 if (argc > 1 && (cf(argv[1], "-S") == 0)) {
  umask(um = mode = umask(0));
  prs_buff("u=");
  if ((mode & 0400) == 0)
   prc_buff('r');
  if ((mode & 0200) == 0)
   prc_buff('w');
  if ((mode & 0100) == 0)
   prc_buff('x');
  prs_buff(",g=");
  if ((mode & 040) == 0)
   prc_buff('r');
  if ((mode & 020) == 0)
   prc_buff('w');
  if ((mode & 010) == 0)
   prc_buff('x');
  prs_buff(",o=");
  if ((mode & 04) == 0)
   prc_buff('r');
  if ((mode & 02) == 0)
   prc_buff('w');
  if ((mode & 01) == 0)
   prc_buff('x');
  prc_buff('\n');
 } else if (argc == 1) {
  umask(um = mode = umask(0));
  prc_buff('0');
  for (i = 6; i >= 0; i -= 3)
   prc_buff(((mode >> i) & 07) +'0');
  prc_buff('\n');
 } else {
  for (cp = argv[1]; *cp; cp++) {
   if (*cp < '0' || *cp > '7') {
    symbolic = 1;
    break;
   }
  }
  if (symbolic) {
   umask(um = mode = umask(0));
   mode = newmode(argv[1], ~mode);
   mode = (~mode & 0777);
   umask(mode);
  } else {
   mode = 0;
   while ((i = *argv[1]++) >= '0' && i <= '7')
    mode = (mode << 3) + i - '0';
   umask(mode);
  }
 }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: symbolic short

variable_types:
mode
unsigned int

variable_types: i int

variable_types:
cp
char *


any

decompiled_code:
__int64 __fastcall any(int a1, unsigned __int8 *a2)
{
unsigned __int8 v2; // al

while ( 1 )
{
v2 = *a2++;
if ( !v2 )
break;
if ( v2 == a1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

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

while ( 1 )
{
v2 = *a2++;
if ( !v2 )
break;
if ( v2 == a1 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int
any(wchar_t c, const unsigned char *s)
{
 register unsigned int d;
 while (d = *s++)
 {
  if (d == c)
   return((-1));
 }
 return(0);
}

canonical_original_code:
int any(int c, unsigned char *s)
{
 register unsigned int d;
 while (d = *s++)
 {
  if (d == c)
   return((-1));
 }
 return(0);
}

variable_types: c int

variable_types:
s
unsigned char *

variable_types:
d
unsigned int


anys

decompiled_code:
__int64 __fastcall anys(char *s, char *a2)
{
int v3; // edx
__int64 result; // rax
wchar_t v5; // ebp
int v6; // eax
wchar_t v7; // [rsp+8h] [rbp-20h] BYREF
wchar_t pwc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( mb_cur_max > 1 && *s < 0 )
{
v3 = mbtowc(pwc, s, mb_cur_max);
}
else
{
pwc[0] = (unsigned __int8)*s;
v3 = pwc[0] != 0;
}
result = 0LL;
if ( v3 > 0 )
{
v5 = pwc[0];
while ( 1 )
{
if ( mb_cur_max <= 1 || *a2 >= 0 )
{
v7 = (unsigned __int8)*a2;
v6 = v7 != 0;
}
else
{
v6 = mbtowc(&v7, a2, mb_cur_max);
}
if ( v6 <= 0 )
return 0LL;
if ( v7 == v5 )
break;
a2 += v6;
}
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s, char *a2)
{
int v3; // edx
__int64 result; // rax
wchar_t v5; // ebp
int v6; // eax
wchar_t v7; // [rsp+8h] [rbp-20h] BYREF
wchar_t pwc[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( mb_cur_max > 1 && *s < 0 )
{
v3 = mbtowc(pwc, s, mb_cur_max);
}
else
{
pwc[0] = (unsigned __int8)*s;
v3 = pwc[0] != 0;
}
result = 0LL;
if ( v3 > 0 )
{
v5 = pwc[0];
while ( 1 )
{
if ( mb_cur_max <= 1 || *a2 >= 0 )
{
v7 = (unsigned __int8)*a2;
v6 = v7 != 0;
}
else
{
v6 = mbtowc(&v7, a2, mb_cur_max);
}
if ( v6 <= 0 )
return 0LL;
if ( v7 == v5 )
break;
a2 += v6;
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
anys(const unsigned char *c, const unsigned char *s)
{
 wchar_t f, e;
 register wchar_t d;
 register int n;
 if((n = (mb_cur_max > 1 && *((const char *)c) & 0200 ? mbtowc(&f, (const char *)c, mb_cur_max) : (*(&f) = *((const char *)c) & 0377, *(&f) != 0))) <= 0)
  return(0);
 d = f;
 while(1) {
  if((n = (mb_cur_max > 1 && *((const char *)s) & 0200 ? mbtowc(&e, (const char *)s, mb_cur_max) : (*(&e) = *((const char *)s) & 0377, *(&e) != 0))) <= 0)
   return(0);
  if(d == e)
   return((-1));
  s += n;
 }
}

canonical_original_code:
int anys(unsigned char *c, unsigned char *s)
{
 int f; int e;
 register int d;
 register int n;
 if((n = (mb_cur_max > 1 && *((char *)c) & 0200 ? mbtowc(&f, (char *)c, mb_cur_max) : (*(&f) = *((char *)c) & 0377, *(&f) != 0))) <= 0)
  return(0);
 d = f;
 while(1) {
  if((n = (mb_cur_max > 1 && *((char *)s) & 0200 ? mbtowc(&e, (char *)s, mb_cur_max) : (*(&e) = *((char *)s) & 0377, *(&e) != 0))) <= 0)
   return(0);
  if(d == e)
   return((-1));
  s += n;
 }
}

variable_types:
c
unsigned char *

variable_types: f int

variable_types: e int

variable_types: d int

variable_types: n int


crunch

decompiled_code:
__int64 __fastcall crunch(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
int v2; // edx
int v3; // ecx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
v3 = 0;
do
{
++a1;
v3 += v1;
++v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
v3 = 0;
}
return (unsigned int)(v2 + v3);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
int v2; // edx
int v3; // ecx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
v3 = 0;
do
{
++a1;
v3 += v1;
++v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
v3 = 0;
}
return (unsigned int)(v2 + v3);
}

original_code:
static unsigned int
crunch(unsigned char *key)
{
 unsigned int sum = 0;
 int s;
 for (s = 0; *key; s++)
  sum += *key++;
 return(sum + s);
}

variable_types:
key
unsigned char *

variable_types:
sum
unsigned int

variable_types: s int


hcreate

decompiled_code:
__int64 hcreate()
{
_QWORD *v0; // rax
_QWORD *v1; // rdx
__int64 result; // rax

v0 = (_QWORD *)alloc(512LL);
table = (__int64)v0;
v1 = v0 + 64;
do
*v0++ = 0LL;
while ( v0 != v1 );
LODWORD(result) = 1;
do
result = (unsigned int)(result + 1);
while ( (_DWORD)result != 9 );
bitsper = 8;
shift = 26;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rax
_QWORD *v1; // rdx
__int64 result; // rax

v0 = (_QWORD *)alloc(512LL);
table = (__int64)v0;
v1 = v0 + 64;
do
*v0++ = 0LL;
while ( v0 != v1 );
LODWORD(result) = 1;
do
result = (unsigned int)(result + 1);
while ( (_DWORD)result != 9 );
bitsper = 8;
shift = 26;
return result;
}

original_code:
void
hcreate(void)
{
 unsigned char c = (unsigned char)~0;
 int j;
 table = (struct node **)alloc(64 * sizeof(struct node *));
 for (j=0; j < 64; ++j)
 {
  table[j] = 0;
 }
 bitsper = 0;
 while (c)
 {
  c = (unsigned int)c >> 1;
  bitsper++;
 }
 shift = (bitsper * sizeof(int)) - 6;
}

canonical_original_code:
void hcreate()
{
 unsigned char c = (unsigned char)~0;
 int j;
 table = (struct node **)alloc(64 * sizeof(struct node *));
 for (j=0; j < 64; ++j)
 {
  table[j] = 0;
 }
 bitsper = 0;
 while (c)
 {
  c = (unsigned int)c >> 1;
  bitsper++;
 }
 shift = (bitsper * sizeof(int)) - 6;
}

variable_types:
c
unsigned char

variable_types: j int

user_defined_types: struct node { struct entry item; struct node *next; }

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


hscan

decompiled_code:
__int64 __fastcall hscan(__int64 (__fastcall *a1)(__int64))
{
__int64 i; // r12
__int64 result; // rax
__int64 j; // rbx
__int64 v5; // rdi

for ( i = 0LL; i != 512; i += 8LL )
{
result = table;
for ( j = *(_QWORD *)(table + i); j; result = a1(v5) )
{
v5 = j;
j = *(_QWORD *)(j + 24);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 (__fastcall *a1)(__int64))
{
__int64 i; // r12
__int64 result; // rax
__int64 j; // rbx
__int64 v5; // rdi

for ( i = 0LL; i != 512; i += 8LL )
{
result = table;
for ( j = *(_QWORD *)(table + i); j; result = a1(v5) )
{
v5 = j;
j = *(_QWORD *)(j + 24);
}
}
return result;
}

original_code:
void
hscan(void (*uscan)(ENTRY *))
{
 struct node *p, *nxt;
 int j;
 for (j=0; j < 64; ++j)
 {
  p = table[j];
  while (p)
  {
   nxt = p->next;
   (*uscan)(&p->item);
   p = nxt;
  }
 }
}

canonical_original_code:
void hscan(void (*uscan)(struct entry *))
{
 struct node *p; struct node *nxt;
 int j;
 for (j=0; j < 64; ++j)
 {
  p = table[j];
  while (p)
  {
   nxt = p->next;
   (*uscan)(&p->item);
   p = nxt;
  }
 }
}

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

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


readb

decompiled_code:
__int64 __fastcall readb(unsigned int *a1, int a2, unsigned int a3)
{
unsigned int *v5; // r15
__int64 v6; // rbp
__int64 result; // rax
__int64 v8; // rdi
unsigned int v9; // eax
int v10; // eax
int v11; // ebp
unsigned int v12; // eax

if ( !a3
|| (v6 = (int)a3,
memcpy(a1 + 16, *((const void **)a1 + 2), (int)a3),
*((_QWORD *)a1 + 2) = a1 + 16,
*((_QWORD *)a1 + 3) = (char *)a1 + v6 + 64,
*((_QWORD *)a1 + 4) = 0LL,
*((_QWORD *)a1 + 5) = v6,
result = a3,
*((_BYTE *)a1 + (int)(a3 - 1) + 64) != 10) )
{
v5 = a1 + 16;
while ( 1 )
{
do
{
while ( 1 )
{
if ( (trapnote & 4) != 0 )
{
prc(10LL);
if ( (trapnote & 4) != 0 )
{
v8 = exitval;
if ( !exitval )
v8 = 2000LL;
exitsh(v8);
}
}
else if ( (trapnote & 2) != 0 && rwait > 0 )
{
prc(10LL);
chktrap();
clearup();
}
v10 = read(*a1, (char *)a1 + (int)a3 + 64, a2);
v11 = v10;
if ( v10 < 0 )
break;
if ( v10 )
goto LABEL_26;
if ( (flags & 2) == 0 )
{
if ( flags < 0 )
goto LABEL_26;
if ( !isatty(*standin) )
{
v11 = 0;
goto LABEL_26;
}
if ( (*((_BYTE *)&flags + 1) & 4) == 0 )
goto LABEL_26;
}
v12 = fcntl64(*a1, 3LL, 0LL);
v11 = v12 & 0x800;
if ( (v12 & 0x800) == 0 )
goto LABEL_26;
BYTE1(v12) &= 0xF7u;
fcntl64(*a1, 4LL, v12);
}
}
while ( trapnote );
if ( *_errno_location() != 11 )
break;
v9 = fcntl64(*a1, 3LL, 0LL);
BYTE1(v9) &= 0xF7u;
fcntl64(*a1, 4LL, v9);
}
v11 = 0;
LABEL_26:
*((_QWORD *)a1 + 2) = v5;
result = v11 + a3;
*((_QWORD *)a1 + 3) = (char *)v5 + (int)result;
*((_QWORD *)a1 + 4) = 0LL;
*((_QWORD *)a1 + 5) = (int)result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1, int a2, unsigned int a3)
{
unsigned int *v5; // r15
__int64 v6; // rbp
__int64 result; // rax
__int64 v8; // rdi
unsigned int v9; // eax
int v10; // eax
int v11; // ebp
unsigned int v12; // eax

if ( !a3
|| (v6 = (int)a3,
memcpy(a1 + 16, *((const void **)a1 + 2), (int)a3),
*((_QWORD *)a1 + 2) = a1 + 16,
*((_QWORD *)a1 + 3) = (char *)a1 + v6 + 64,
*((_QWORD *)a1 + 4) = 0LL,
*((_QWORD *)a1 + 5) = v6,
result = a3,
*((_BYTE *)a1 + (int)(a3 - 1) + 64) != 10) )
{
v5 = a1 + 16;
while ( 1 )
{
do
{
while ( 1 )
{
if ( (trapnote & 4) != 0 )
{
prc(10LL);
if ( (trapnote & 4) != 0 )
{
v8 = exitval;
if ( !exitval )
v8 = 2000LL;
exitsh(v8);
}
}
else if ( (trapnote & 2) != 0 && rwait > 0 )
{
prc(10LL);
chktrap();
clearup();
}
v10 = read(*a1, (char *)a1 + (int)a3 + 64, a2);
v11 = v10;
if ( v10 < 0 )
break;
if ( v10 )
goto LABEL_26;
if ( (flags & 2) == 0 )
{
if ( flags < 0 )
goto LABEL_26;
if ( !isatty(*standin) )
{
v11 = 0;
goto LABEL_26;
}
if ( (*((_BYTE *)&flags + 1) & 4) == 0 )
goto LABEL_26;
}
v12 = fcntl64(*a1, 3LL, 0LL);
v11 = v12 & 0x800;
if ( (v12 & 0x800) == 0 )
goto LABEL_26;
BYTE1(v12) &= 0xF7u;
fcntl64(*a1, 4LL, v12);
}
}
while ( trapnote );
if ( *_errno_location() != 11 )
break;
v9 = fcntl64(*a1, 3LL, 0LL);
BYTE1(v9) &= 0xF7u;
fcntl64(*a1, 4LL, v9);
}
v11 = 0;
LABEL_26:
*((_QWORD *)a1 + 2) = v5;
result = v11 + a3;
*((_QWORD *)a1 + 3) = (char *)v5 + (int)result;
*((_QWORD *)a1 + 4) = 0LL;
*((_QWORD *)a1 + 5) = (int)result;
}
return result;
}

original_code:
static int
readb(struct fileblk *f, int toread, int rest)
{
 int len;
 int fflags;
 if (rest) {
  memcpy(f->fbuf, f->fnxt, rest);
  f->fnxt = f->fbuf;
  f->fend = f->fnxt + rest;
  f->nxtoff = 0;
  f->endoff = rest;
  if (f->fbuf[rest - 1] == '\n') {
   return (rest);
  }
 }
retry:
 do {
  if (trapnote & 4) {
   prc('\n');
   if (trapnote & 4) exitsh(exitval ? exitval : 2000);
  } else if ((trapnote & 2) && (rwait > 0)) {
   prc('\n');
   chktrap();
   clearup();
  }
 } while ((len = read(f->fdes, f->fbuf + rest, toread)) < 0 && trapnote);
 if (len == 0) {
  if (((flags & 02) ||
      ((flags & 0200) == 0 && isatty((standin->fdes)) &&
      (flags & 02000))) &&
      ((fflags = fcntl(f->fdes, 3, 0)) & 04000)) {
   fflags &= ~04000;
   fcntl(f->fdes, 4, fflags);
   goto retry;
  }
 } else if (len < 0) {
  if ((*__errno_location ()) == 11) {
   fflags = fcntl(f->fdes, 3, 0);
   fflags &= ~04000;
   fcntl(f->fdes, 4, fflags);
   goto retry;
  }
  len = 0;
 }
 f->fnxt = f->fbuf;
 f->fend = f->fnxt + (len + rest);
 f->nxtoff = 0;
 f->endoff = len + rest;
 return (len + rest);
}

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

variable_types: toread int

variable_types: rest int

variable_types: len int

variable_types: fflags int


readw

decompiled_code:
char *__fastcall readw(wchar_t wchar)
{
int v1; // eax

if ( (wchar & 0xFFFFFF80) != 0 )
{
if ( mb_cur_max > 1 )
{
v1 = wctomb(&c_0, wchar);
if ( v1 <= 0 )
{
c_0 = wchar;
v1 = 1;
}
}
else
{
c_0 = wchar;
v1 = 1;
}
*(&c_0 + v1) = 0;
}
else
{
c_0 = wchar;
byte_AA1 = 0;
}
return &c_0;
}

canonical_decompiled_code:
char *__fastcall func1(wchar_t wchar)
{
int v1; // eax

if ( (wchar & 0xFFFFFF80) != 0 )
{
if ( mb_cur_max > 1 )
{
v1 = wctomb(&c_0, wchar);
if ( v1 <= 0 )
{
c_0 = wchar;
v1 = 1;
}
}
else
{
c_0 = wchar;
v1 = 1;
}
*(&c_0 + v1) = 0;
}
else
{
c_0 = wchar;
byte_AA1 = 0;
}
return &c_0;
}

original_code:
unsigned char *
readw(wchar_t d)
{
 static unsigned char c[16 + 1];
 int length;
 if ((((d) & ~0x7f) == 0)) {
  c[0] = d;
  c[1] = '\0';
  return (c);
 }
 length = (mb_cur_max > 1 && d & ~(wchar_t)0177 ? wctomb((char *)c, d) : (*((char *)c) = d, 1));
 if (length <= 0) {
  c[0] = (unsigned char)d;
  length = 1;
 }
 c[length] = '\0';
 return (c);
}

canonical_original_code:
unsigned char *readw(int d)
{
 static unsigned char c[-1];
 int length;
 if ((((d) & ~0x7f) == 0)) {
  c[0] = d;
  c[1] = '\0';
  return (c);
 }
 length = (mb_cur_max > 1 && d & ~(int)0177 ? wctomb((char *)c, d) : (*((char *)c) = d, 1));
 if (length <= 0) {
  c[0] = (unsigned char)d;
  length = 1;
 }
 c[length] = '\0';
 return (c);
}

variable_types:
c
unsigned char [-1]

variable_types: length int


readwc

decompiled_code:
__int64 readwc()
{
int v0; // eax
wchar_t v1; // ebp
__int64 v2; // rbx
__int64 result; // rax
size_t v4; // r12
int v5; // er13
__int64 v6; // rdx
unsigned __int8 v7; // al
int v8; // esi
__int16 v9; // ax
unsigned __int8 *v10; // rax
unsigned __int8 v11; // dl
_QWORD *v12; // rax
wchar_t pwc[11]; // [rsp+0h] [rbp-2Ch] BYREF

v0 = peekn;
if ( peekn )
{
peekn = 0;
result = v0 & 0x7FFFFFFF;
}
else
{
v1 = peekc;
v2 = standin;
if ( peekc )
{
peekc = 0;
result = v1 & 0x7FFFFFFF;
}
else
{
while ( 1 )
{
while ( 1 )
{
v10 = *(unsigned __int8 **)(v2 + 16);
if ( *(_QWORD *)(v2 + 24) > (unsigned __int64)v10 )
break;
v9 = *(_WORD *)(v2 + 8);
if ( v9 || *(int *)v2 < 0 )
{
*(_WORD *)(v2 + 8) = v9 + 1;
return 0LL;
}
if ( (int)readb((unsigned int *)v2, *(unsigned __int8 *)(v2 + 10), 0) <= 0 )
{
if ( *(_DWORD *)v2 != *standin || !isatty(*standin) )
{
close(*(_DWORD *)v2);
*(_DWORD *)v2 = -1;
}
++*(_WORD *)(v2 + 8);
return 0LL;
}
}
v11 = *v10;
if ( *v10 )
break;
*(_QWORD *)(v2 + 16) = v10 + 1;
++*(_QWORD *)(v2 + 32);
v12 = *(_QWORD **)(v2 + 48);
if ( v12 )
{
*(_QWORD *)(v2 + 48) = v12 + 1;
if ( !(unsigned int)estabf(*v12) )
v1 = 32;
pwc[0] = v1;
if ( (*((_BYTE *)&flags + 1) & 0x10) == 0 || *(_QWORD *)(standin + 56LL) )
return (unsigned int)pwc[0];
prc((unsigned int)v1);
result = (unsigned int)pwc[0];
if ( pwc[0] == 10 )
++*(_DWORD *)(v2 + 4);
return result;
}
}
pwc[0] = v11;
if ( (v11 & 0x80) != 0 )
{
v4 = 1LL;
v5 = 1;
if ( mb_cur_max > 0 )
{
while ( 1 )
{
v5 = v4;
v6 = *(_QWORD *)(v2 + 24) - *(_QWORD *)(v2 + 16);
if ( (int)v6 < (int)v4 )
{
v7 = *(_BYTE *)(v2 + 10);
v8 = v7 - (_DWORD)v6;
if ( v7 == 1 )
v8 = 1;
if ( !(unsigned int)readb((unsigned int *)v2, v8, v6) )
break;
}
if ( mb_cur_max > 1 )
{
v1 = mbtowc(pwc, *(const char **)(v2 + 16), v4);
if ( v1 > 0 )
break;
if ( mb_cur_max > 1 )
mbtowc(0LL, 0LL, 0LL);
}
else
{
pwc[0] = **(unsigned __int8 **)(v2 + 16);
v1 = pwc[0] != 0;
if ( pwc[0] )
{
v1 = 1;
break;
}
}
if ( mb_cur_max < (int)++v4 )
goto LABEL_34;
}
}
if ( mb_cur_max < v5 )
{
LABEL_34:
pwc[0] = **(unsigned __int8 **)(v2 + 16);
v1 = 1;
}
*(_QWORD *)(v2 + 16) += v1;
*(_QWORD *)(v2 + 32) += v1;
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 && !*(_QWORD *)(standin + 56LL) )
prwc((unsigned int)pwc[0]);
result = (unsigned int)pwc[0];
if ( pwc[0] == 10 )
++*(_DWORD *)(v2 + 4);
}
else
{
*(_QWORD *)(v2 + 16) = v10 + 1;
++*(_QWORD *)(v2 + 32);
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 && !*(_QWORD *)(standin + 56LL) )
prc(v11);
result = (unsigned int)pwc[0];
if ( pwc[0] == 10 )
++*(_DWORD *)(v2 + 4);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
wchar_t v1; // ebp
__int64 v2; // rbx
__int64 result; // rax
size_t v4; // r12
int v5; // er13
__int64 v6; // rdx
unsigned __int8 v7; // al
int v8; // esi
__int16 v9; // ax
unsigned __int8 *v10; // rax
unsigned __int8 v11; // dl
_QWORD *v12; // rax
wchar_t pwc[11]; // [rsp+0h] [rbp-2Ch] BYREF

v0 = peekn;
if ( peekn )
{
peekn = 0;
result = v0 & 0x7FFFFFFF;
}
else
{
v1 = peekc;
v2 = standin;
if ( peekc )
{
peekc = 0;
result = v1 & 0x7FFFFFFF;
}
else
{
while ( 1 )
{
while ( 1 )
{
v10 = *(unsigned __int8 **)(v2 + 16);
if ( *(_QWORD *)(v2 + 24) > (unsigned __int64)v10 )
break;
v9 = *(_WORD *)(v2 + 8);
if ( v9 || *(int *)v2 < 0 )
{
*(_WORD *)(v2 + 8) = v9 + 1;
return 0LL;
}
if ( (int)func0((unsigned int *)v2, *(unsigned __int8 *)(v2 + 10), 0) <= 0 )
{
if ( *(_DWORD *)v2 != *standin || !isatty(*standin) )
{
close(*(_DWORD *)v2);
*(_DWORD *)v2 = -1;
}
++*(_WORD *)(v2 + 8);
return 0LL;
}
}
v11 = *v10;
if ( *v10 )
break;
*(_QWORD *)(v2 + 16) = v10 + 1;
++*(_QWORD *)(v2 + 32);
v12 = *(_QWORD **)(v2 + 48);
if ( v12 )
{
*(_QWORD *)(v2 + 48) = v12 + 1;
if ( !(unsigned int)estabf(*v12) )
v1 = 32;
pwc[0] = v1;
if ( (*((_BYTE *)&flags + 1) & 0x10) == 0 || *(_QWORD *)(standin + 56LL) )
return (unsigned int)pwc[0];
prc((unsigned int)v1);
result = (unsigned int)pwc[0];
if ( pwc[0] == 10 )
++*(_DWORD *)(v2 + 4);
return result;
}
}
pwc[0] = v11;
if ( (v11 & 0x80) != 0 )
{
v4 = 1LL;
v5 = 1;
if ( mb_cur_max > 0 )
{
while ( 1 )
{
v5 = v4;
v6 = *(_QWORD *)(v2 + 24) - *(_QWORD *)(v2 + 16);
if ( (int)v6 < (int)v4 )
{
v7 = *(_BYTE *)(v2 + 10);
v8 = v7 - (_DWORD)v6;
if ( v7 == 1 )
v8 = 1;
if ( !(unsigned int)func0((unsigned int *)v2, v8, v6) )
break;
}
if ( mb_cur_max > 1 )
{
v1 = mbtowc(pwc, *(const char **)(v2 + 16), v4);
if ( v1 > 0 )
break;
if ( mb_cur_max > 1 )
mbtowc(0LL, 0LL, 0LL);
}
else
{
pwc[0] = **(unsigned __int8 **)(v2 + 16);
v1 = pwc[0] != 0;
if ( pwc[0] )
{
v1 = 1;
break;
}
}
if ( mb_cur_max < (int)++v4 )
goto LABEL_34;
}
}
if ( mb_cur_max < v5 )
{
LABEL_34:
pwc[0] = **(unsigned __int8 **)(v2 + 16);
v1 = 1;
}
*(_QWORD *)(v2 + 16) += v1;
*(_QWORD *)(v2 + 32) += v1;
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 && !*(_QWORD *)(standin + 56LL) )
prwc((unsigned int)pwc[0]);
result = (unsigned int)pwc[0];
if ( pwc[0] == 10 )
++*(_DWORD *)(v2 + 4);
}
else
{
*(_QWORD *)(v2 + 16) = v10 + 1;
++*(_QWORD *)(v2 + 32);
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 && !*(_QWORD *)(standin + 56LL) )
prc(v11);
result = (unsigned int)pwc[0];
if ( pwc[0] == 10 )
++*(_DWORD *)(v2 + 4);
}
}
}
return result;
}

original_code:
unsigned int
readwc(void)
{
 wchar_t c;
 int len;
 struct fileblk *f;
 int i, mlen = 0;
 if (peekn) {
  c = peekn & 0x7fffffff;
  peekn = 0;
  return (c);
 }
 if (peekc) {
  c = peekc & 0x7fffffff;
  peekc = 0;
  return (c);
 }
 f = standin;
retry:
 if (f->fend > f->fnxt) {
  if (*f->fnxt == 0) {
   f->fnxt++;
   f->nxtoff++;
   if (f->feval == 0)
    goto retry;
   if (estabf(*f->feval++))
    c = 0;
   else
    c = ' ';
   if (flags & 010000 && standin->fstak == 0)
    prc(c);
   if (c == '\n')
    f->flin++;
   return (c);
  }
  if ((((c = (unsigned char)*f->fnxt) & ~0x7f) == 0)) {
   f->fnxt++;
   f->nxtoff++;
   if (flags & 010000 && standin->fstak == 0)
    prc(c);
   if (c == '\n')
    f->flin++;
   return (c);
  }
  for (i = 1; i <= mb_cur_max; i++) {
   int rest;
   if ((rest = f->fend - f->fnxt) < i) {
    len = readb(f,
     (f->fsiz == 1) ? 1 : (f->fsiz - rest),
     rest);
    if (len == 0)
     break;
   }
   mlen = mb_cur_max > 1 ?
    mbtowc(&c, (char *)f->fnxt, i) :
    (c = *f->fnxt & 0377, c != 0);
   if (mlen > 0)
    break;
   if (mb_cur_max > 1)
    mbtowc(((void *)0), ((void *)0), 0);
  }
  if (i > mb_cur_max) {
   c = (unsigned char)*f->fnxt;
   mlen = 1;
  }
  f->fnxt += mlen;
  f->nxtoff += mlen;
  if (flags & 010000 && standin->fstak == 0)
   prwc(c);
  if (c == '\n')
   f->flin++;
  return (c);
 }
 if (f->feof || f->fdes < 0){
  c = 0;
  f->feof++;
  return (c);
 }
 if (readb(f, f->fsiz, 0) <= 0){
  if (f->fdes != (standin->fdes) || !isatty((standin->fdes))) {
   close(f->fdes);
   f->fdes = -1;
  }
  f->feof++;
  c = 0;
  return (c);
 }
 goto retry;
}

canonical_original_code:
unsigned int readwc()
{
 int c;
 int len;
 struct fileblk *f;
 int i; int mlen = 0;
 if (peekn) {
  c = peekn & 0x7fffffff;
  peekn = 0;
  return (c);
 }
 if (peekc) {
  c = peekc & 0x7fffffff;
  peekc = 0;
  return (c);
 }
 f = standin;
retry:
 if (f->fend > f->fnxt) {
  if (*f->fnxt == 0) {
   f->fnxt++;
   f->nxtoff++;
   if (f->feval == 0)
    goto retry;
   if (estabf(*f->feval++))
    c = 0;
   else
    c = ' ';
   if (flags & 010000 && standin->fstak == 0)
    prc(c);
   if (c == '\n')
    f->flin++;
   return (c);
  }
  if ((((c = (unsigned char)*f->fnxt) & ~0x7f) == 0)) {
   f->fnxt++;
   f->nxtoff++;
   if (flags & 010000 && standin->fstak == 0)
    prc(c);
   if (c == '\n')
    f->flin++;
   return (c);
  }
  for (i = 1; i <= mb_cur_max; i++) {
   int rest;
   if ((rest = f->fend - f->fnxt) < i) {
    len = readb(f,
     (f->fsiz == 1) ? 1 : (f->fsiz - rest),
     rest);
    if (len == 0)
     break;
   }
   mlen = mb_cur_max > 1 ?
    mbtowc(&c, (char *)f->fnxt, i) :
    (c = *f->fnxt & 0377, c != 0);
   if (mlen > 0)
    break;
   if (mb_cur_max > 1)
    mbtowc(((void *)0), ((void *)0), 0);
  }
  if (i > mb_cur_max) {
   c = (unsigned char)*f->fnxt;
   mlen = 1;
  }
  f->fnxt += mlen;
  f->nxtoff += mlen;
  if (flags & 010000 && standin->fstak == 0)
   prwc(c);
  if (c == '\n')
   f->flin++;
  return (c);
 }
 if (f->feof || f->fdes < 0){
  c = 0;
  f->feof++;
  return (c);
 }
 if (readb(f, f->fsiz, 0) <= 0){
  if (f->fdes != (standin->fdes) || !isatty((standin->fdes))) {
   close(f->fdes);
   f->fdes = -1;
  }
  f->feof++;
  c = 0;
  return (c);
 }
 goto retry;
}

variable_types: c int

variable_types: i int

variable_types: mlen int


nextwc

decompiled_code:
__int64 nextwc()
{
unsigned int v0; // ebx
int v1; // eax

while ( 1 )
{
v0 = readwc();
if ( v0 != 92 )
break;
v1 = readwc();
if ( v1 != 10 )
{
peekc = v1 | 0x80000000;
return v0;
}
chkpr();
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebx
int v1; // eax

while ( 1 )
{
v0 = func2();
if ( v0 != 92 )
break;
v1 = func2();
if ( v1 != 10 )
{
peekc = v1 | 0x80000000;
return v0;
}
chkpr();
}
return v0;
}

original_code:
unsigned int
nextwc(void)
{
 register unsigned int c, d;
retry:
 if ((d = readwc()) == '\\') {
  if ((c = readwc()) == '\n') {
   chkpr();
   goto retry;
  }
  peekc = c | 0x80000000;
 }
 return (d);
}

canonical_original_code:
unsigned int nextwc()
{
 register unsigned int c; register unsigned int d;
retry:
 if ((d = readwc()) == '\\') {
  if ((c = readwc()) == '\n') {
   chkpr();
   goto retry;
  }
  peekc = c | 0x80000000;
 }
 return (d);
}

variable_types:
c
unsigned int

variable_types:
d
unsigned int


skipwc

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

do
result = nextwc();
while ( (unsigned int)result <= 0x7F && (*((_BYTE *)&sh_ctype1 + (unsigned int)result) & 4) != 0 );
return result;
}

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

do
result = func3();
while ( (unsigned int)result <= 0x7F && (*((_BYTE *)&sh_ctype1 + (unsigned int)result) & 4) != 0 );
return result;
}

original_code:
unsigned int
skipwc(void)
{
 register unsigned int c;
 while (c = nextwc(), ((c<0200) && sh_ctype1[c]&(04)))
  ;
 return (c);
}

canonical_original_code:
unsigned int skipwc()
{
 register unsigned int c;
 while (c = nextwc(), ((c<0200) && sh_ctype1[c]&(04)))
  ;
 return (c);
}