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

repo: mutoso-mirrors/heirloom-sh

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

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

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

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

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

return_type: int


anys

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

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

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

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

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 )
return 0LL;
v2 = 0;
v3 = 0;
do
{
++a1;
++v2;
v3 += v1;
v1 = *a1;
}
while ( *a1 );
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 )
return 0LL;
v2 = 0;
v3 = 0;
do
{
++a1;
++v2;
v3 += v1;
v1 = *a1;
}
while ( *a1 );
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

return_type: unsigned int


hcreate

decompiled_code:
__int64 hcreate()
{
_QWORD *v0; // rax
void *v1; // rdi
unsigned int v2; // ecx
__int64 result; // rax

v0 = (_QWORD *)alloc(512LL);
table = (__int64)v0;
v1 = (void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL);
*v0 = 0LL;
v0[63] = 0LL;
v2 = (_DWORD)v0 - (_DWORD)v1 + 512;
result = 0LL;
memset(v1, 0, 8LL * (v2 >> 3));
bitsper = 8;
shift = 26;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
_QWORD *v0; // rax
void *v1; // rdi
unsigned int v2; // ecx
__int64 result; // rax

v0 = (_QWORD *)alloc(512LL);
table = (__int64)v0;
v1 = (void *)((unsigned __int64)(v0 + 1) & 0xFFFFFFFFFFFFFFF8LL);
*v0 = 0LL;
v0[63] = 0LL;
v2 = (_DWORD)v0 - (_DWORD)v1 + 512;
result = 0LL;
memset(v1, 0, 8LL * (v2 >> 3));
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

return_type: void

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(const void **a1, int a2, int a3)
{
const void *v3; // r15
unsigned int v4; // er13
char *v5; // r12
char v7; // al
int v8; // eax
unsigned int v9; // eax
__int64 v10; // rdi
char *dest; // [rsp+8h] [rbp-40h]

v3 = (const void *)a3;
v4 = a3;
v5 = (char *)a1 + a3 + 64;
dest = (char *)(a1 + 8);
if ( a3 )
{
memcpy(dest, a1[2], a3);
a1[2] = dest;
a1[3] = v5;
a1[4] = 0LL;
a1[5] = v3;
if ( *((_BYTE *)a1 + (int)v3 + 63) == 10 )
return v4;
}
v7 = trapnote;
LABEL_3:
if ( (v7 & 4) == 0 )
{
LABEL_4:
if ( (v7 & 2) != 0 && rwait > 0 )
{
prc(10LL);
chktrap();
clearup();
}
goto LABEL_7;
}
while ( 1 )
{
prc(10LL);
if ( (trapnote & 4) != 0 )
{
v10 = exitval;
if ( !exitval )
v10 = 2000LL;
exitsh(v10);
}
LABEL_7:
v8 = read(*(_DWORD *)a1, v5, a2);
if ( v8 >= 0 )
break;
v7 = trapnote;
if ( trapnote )
goto LABEL_3;
if ( *_errno_location() != 11 )
goto LABEL_23;
v9 = fcntl64(*(unsigned int *)a1, 3LL, 0LL);
LABEL_14:
BYTE1(v9) &= 0xF7u;
fcntl64(*(unsigned int *)a1, 4LL, v9);
v7 = trapnote;
if ( (trapnote & 4) == 0 )
goto LABEL_4;
}
if ( !v8 )
{
if ( (flags & 2) == 0 && (flags < 0 || !isatty(*standin) || (*((_BYTE *)&flags + 1) & 4) == 0) )
goto LABEL_23;
v9 = fcntl64(*(unsigned int *)a1, 3LL, 0LL);
if ( (v9 & 0x800) == 0 )
goto LABEL_23;
goto LABEL_14;
}
v4 += v8;
v3 = (const void *)(int)v4;
v5 = &dest[v4];
LABEL_23:
a1[3] = v5;
a1[4] = 0LL;
a1[2] = dest;
a1[5] = v3;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void **a1, int a2, int a3)
{
const void *v3; // r15
unsigned int v4; // er13
char *v5; // r12
char v7; // al
int v8; // eax
unsigned int v9; // eax
__int64 v10; // rdi
char *dest; // [rsp+8h] [rbp-40h]

v3 = (const void *)a3;
v4 = a3;
v5 = (char *)a1 + a3 + 64;
dest = (char *)(a1 + 8);
if ( a3 )
{
memcpy(dest, a1[2], a3);
a1[2] = dest;
a1[3] = v5;
a1[4] = 0LL;
a1[5] = v3;
if ( *((_BYTE *)a1 + (int)v3 + 63) == 10 )
return v4;
}
v7 = trapnote;
LABEL_3:
if ( (v7 & 4) == 0 )
{
LABEL_4:
if ( (v7 & 2) != 0 && rwait > 0 )
{
prc(10LL);
chktrap();
clearup();
}
goto LABEL_7;
}
while ( 1 )
{
prc(10LL);
if ( (trapnote & 4) != 0 )
{
v10 = exitval;
if ( !exitval )
v10 = 2000LL;
exitsh(v10);
}
LABEL_7:
v8 = read(*(_DWORD *)a1, v5, a2);
if ( v8 >= 0 )
break;
v7 = trapnote;
if ( trapnote )
goto LABEL_3;
if ( *_errno_location() != 11 )
goto LABEL_23;
v9 = fcntl64(*(unsigned int *)a1, 3LL, 0LL);
LABEL_14:
BYTE1(v9) &= 0xF7u;
fcntl64(*(unsigned int *)a1, 4LL, v9);
v7 = trapnote;
if ( (trapnote & 4) == 0 )
goto LABEL_4;
}
if ( !v8 )
{
if ( (flags & 2) == 0 && (flags < 0 || !isatty(*standin) || (*((_BYTE *)&flags + 1) & 4) == 0) )
goto LABEL_23;
v9 = fcntl64(*(unsigned int *)a1, 3LL, 0LL);
if ( (v9 & 0x800) == 0 )
goto LABEL_23;
goto LABEL_14;
}
v4 += v8;
v3 = (const void *)(int)v4;
v5 = &dest[v4];
LABEL_23:
a1[3] = v5;
a1[4] = 0LL;
a1[2] = dest;
a1[5] = v3;
return v4;
}

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
char *result; // rax

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

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

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

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

return_type: unsigned char *


readwc

decompiled_code:
__int64 readwc()
{
int v0; // eax
__int64 v1; // rbp
__int64 v2; // rbx
unsigned __int64 v3; // rdx
const char *v4; // rsi
__int64 result; // rax
__int64 *v6; // rax
__int64 v7; // rdi
__int16 v8; // ax
int v9; // edi
size_t v10; // r14
int v11; // edx
int v12; // eax
int v13; // esi
int v14; // eax
__int16 v15; // ax
__int64 v16; // rdx
wchar_t pwc[11]; // [rsp+0h] [rbp-2Ch] BYREF

v0 = peekn;
if ( peekn )
{
peekn = 0;
return v0 & 0x7FFFFFFF;
}
v1 = peekc;
v2 = standin;
if ( peekc )
{
peekc = 0;
return v1 & 0x7FFFFFFF;
}
LABEL_3:
v3 = *(_QWORD *)(v2 + 24);
v4 = *(const char **)(v2 + 16);
while ( 1 )
{
if ( v3 <= (unsigned __int64)v4 )
{
v8 = *(_WORD *)(v2 + 8);
if ( v8 )
{
v15 = v8 + 1;
LABEL_38:
*(_WORD *)(v2 + 8) = v15;
return 0LL;
}
if ( *(int *)v2 < 0 )
{
v15 = 1;
goto LABEL_38;
}
if ( (int)readb((const void **)v2, *(unsigned __int8 *)(v2 + 10), 0) <= 0 )
{
v9 = *(_DWORD *)v2;
if ( *(_DWORD *)v2 != *standin )
goto LABEL_16;
if ( !isatty(v9) )
{
v9 = *(_DWORD *)v2;
LABEL_16:
close(v9);
*(_DWORD *)v2 = -1;
}
++*(_WORD *)(v2 + 8);
return 0LL;
}
goto LABEL_3;
}
result = *(unsigned __int8 *)v4;
if ( (_BYTE)result )
break;
v6 = *(__int64 **)(v2 + 48);
++v4;
++*(_QWORD *)(v2 + 32);
*(_QWORD *)(v2 + 16) = v4;
if ( v6 )
{
v7 = *v6;
*(_QWORD *)(v2 + 48) = v6 + 1;
if ( (unsigned int)estabf(v7) )
{
pwc[0] = 0;
if ( (*((_BYTE *)&flags + 1) & 0x10) == 0 )
return (unsigned int)v1;
LABEL_9:
if ( !*(_QWORD *)(standin + 56LL) )
{
prc((unsigned int)v1);
LODWORD(v1) = pwc[0];
}
}
else
{
pwc[0] = 32;
LODWORD(v1) = 32;
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 )
goto LABEL_9;
}
return (unsigned int)v1;
}
}
pwc[0] = *(unsigned __int8 *)v4;
if ( (result & 0x80u) == 0LL )
{
++*(_QWORD *)(v2 + 32);
*(_QWORD *)(v2 + 16) = v4 + 1;
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 && !*(_QWORD *)(standin + 56LL) )
{
prc((unsigned int)result);
result = (unsigned int)pwc[0];
}
goto LABEL_43;
}
v10 = 1LL;
if ( mb_cur_max <= 0 )
{
LABEL_49:
result = *(unsigned __int8 *)v4;
v16 = 1LL;
v1 = 1LL;
pwc[0] = *(unsigned __int8 *)v4;
goto LABEL_50;
}
while ( 2 )
{
v11 = v3 - (_DWORD)v4;
if ( v11 < (int)v10 )
{
v12 = *(unsigned __int8 *)(v2 + 10);
v13 = v12 - v11;
if ( (_BYTE)v12 == 1 )
v13 = 1;
if ( !(unsigned int)readb((const void **)v2, v13, v11) )
{
v14 = mb_cur_max;
v4 = *(const char **)(v2 + 16);
goto LABEL_54;
}
v4 = *(const char **)(v2 + 16);
}
v14 = mb_cur_max;
if ( mb_cur_max <= 1 )
{
v1 = *(unsigned __int8 *)v4;
pwc[0] = v1;
if ( (_DWORD)v1 )
{
v1 = 1LL;
goto LABEL_54;
}
goto LABEL_25;
}
v1 = mbtowc(pwc, v4, v10);
v14 = mb_cur_max;
if ( (int)v1 <= 0 )
{
if ( mb_cur_max > 1 )
{
mbtowc(0LL, 0LL, 0LL);
v14 = mb_cur_max;
}
v4 = *(const char **)(v2 + 16);
LABEL_25:
if ( v14 < (int)++v10 )
goto LABEL_49;
v3 = *(_QWORD *)(v2 + 24);
continue;
}
break;
}
v4 = *(const char **)(v2 + 16);
LABEL_54:
if ( (int)v10 > v14 )
goto LABEL_49;
result = (unsigned int)pwc[0];
v16 = v1;
LABEL_50:
*(_QWORD *)(v2 + 32) += v16;
*(_QWORD *)(v2 + 16) = &v4[v1];
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 && !*(_QWORD *)(standin + 56LL) )
{
prwc((unsigned int)result);
result = (unsigned int)pwc[0];
}
LABEL_43:
if ( (_DWORD)result == 10 )
++*(_DWORD *)(v2 + 4);
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // eax
__int64 v1; // rbp
__int64 v2; // rbx
unsigned __int64 v3; // rdx
const char *v4; // rsi
__int64 result; // rax
__int64 *v6; // rax
__int64 v7; // rdi
__int16 v8; // ax
int v9; // edi
size_t v10; // r14
int v11; // edx
int v12; // eax
int v13; // esi
int v14; // eax
__int16 v15; // ax
__int64 v16; // rdx
wchar_t pwc[11]; // [rsp+0h] [rbp-2Ch] BYREF

v0 = peekn;
if ( peekn )
{
peekn = 0;
return v0 & 0x7FFFFFFF;
}
v1 = peekc;
v2 = standin;
if ( peekc )
{
peekc = 0;
return v1 & 0x7FFFFFFF;
}
LABEL_3:
v3 = *(_QWORD *)(v2 + 24);
v4 = *(const char **)(v2 + 16);
while ( 1 )
{
if ( v3 <= (unsigned __int64)v4 )
{
v8 = *(_WORD *)(v2 + 8);
if ( v8 )
{
v15 = v8 + 1;
LABEL_38:
*(_WORD *)(v2 + 8) = v15;
return 0LL;
}
if ( *(int *)v2 < 0 )
{
v15 = 1;
goto LABEL_38;
}
if ( (int)func0((const void **)v2, *(unsigned __int8 *)(v2 + 10), 0) <= 0 )
{
v9 = *(_DWORD *)v2;
if ( *(_DWORD *)v2 != *standin )
goto LABEL_16;
if ( !isatty(v9) )
{
v9 = *(_DWORD *)v2;
LABEL_16:
close(v9);
*(_DWORD *)v2 = -1;
}
++*(_WORD *)(v2 + 8);
return 0LL;
}
goto LABEL_3;
}
result = *(unsigned __int8 *)v4;
if ( (_BYTE)result )
break;
v6 = *(__int64 **)(v2 + 48);
++v4;
++*(_QWORD *)(v2 + 32);
*(_QWORD *)(v2 + 16) = v4;
if ( v6 )
{
v7 = *v6;
*(_QWORD *)(v2 + 48) = v6 + 1;
if ( (unsigned int)estabf(v7) )
{
pwc[0] = 0;
if ( (*((_BYTE *)&flags + 1) & 0x10) == 0 )
return (unsigned int)v1;
LABEL_9:
if ( !*(_QWORD *)(standin + 56LL) )
{
prc((unsigned int)v1);
LODWORD(v1) = pwc[0];
}
}
else
{
pwc[0] = 32;
LODWORD(v1) = 32;
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 )
goto LABEL_9;
}
return (unsigned int)v1;
}
}
pwc[0] = *(unsigned __int8 *)v4;
if ( (result & 0x80u) == 0LL )
{
++*(_QWORD *)(v2 + 32);
*(_QWORD *)(v2 + 16) = v4 + 1;
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 && !*(_QWORD *)(standin + 56LL) )
{
prc((unsigned int)result);
result = (unsigned int)pwc[0];
}
goto LABEL_43;
}
v10 = 1LL;
if ( mb_cur_max <= 0 )
{
LABEL_49:
result = *(unsigned __int8 *)v4;
v16 = 1LL;
v1 = 1LL;
pwc[0] = *(unsigned __int8 *)v4;
goto LABEL_50;
}
while ( 2 )
{
v11 = v3 - (_DWORD)v4;
if ( v11 < (int)v10 )
{
v12 = *(unsigned __int8 *)(v2 + 10);
v13 = v12 - v11;
if ( (_BYTE)v12 == 1 )
v13 = 1;
if ( !(unsigned int)func0((const void **)v2, v13, v11) )
{
v14 = mb_cur_max;
v4 = *(const char **)(v2 + 16);
goto LABEL_54;
}
v4 = *(const char **)(v2 + 16);
}
v14 = mb_cur_max;
if ( mb_cur_max <= 1 )
{
v1 = *(unsigned __int8 *)v4;
pwc[0] = v1;
if ( (_DWORD)v1 )
{
v1 = 1LL;
goto LABEL_54;
}
goto LABEL_25;
}
v1 = mbtowc(pwc, v4, v10);
v14 = mb_cur_max;
if ( (int)v1 <= 0 )
{
if ( mb_cur_max > 1 )
{
mbtowc(0LL, 0LL, 0LL);
v14 = mb_cur_max;
}
v4 = *(const char **)(v2 + 16);
LABEL_25:
if ( v14 < (int)++v10 )
goto LABEL_49;
v3 = *(_QWORD *)(v2 + 24);
continue;
}
break;
}
v4 = *(const char **)(v2 + 16);
LABEL_54:
if ( (int)v10 > v14 )
goto LABEL_49;
result = (unsigned int)pwc[0];
v16 = v1;
LABEL_50:
*(_QWORD *)(v2 + 32) += v16;
*(_QWORD *)(v2 + 16) = &v4[v1];
if ( (*((_BYTE *)&flags + 1) & 0x10) != 0 && !*(_QWORD *)(standin + 56LL) )
{
prwc((unsigned int)result);
result = (unsigned int)pwc[0];
}
LABEL_43:
if ( (_DWORD)result == 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

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


nextwc

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

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

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

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

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


word

decompiled_code:
__int16 word()
{
__int64 v0; // rax
unsigned int v1; // eax
unsigned int v2; // ebx
char v3; // al
int v4; // eax
char *v5; // r12
int v6; // er13
unsigned int v7; // eax
__int64 v8; // rax
int v9; // ebp
unsigned int v10; // eax
wchar_t v11; // eax
char *v12; // rbp
unsigned int v13; // eax
unsigned int v14; // er12
_BYTE *v15; // rdi
char *k; // rsi
wchar_t v17; // eax
char *v18; // r15
wchar_t v19; // ebp
char *v20; // r14
char *v21; // rbx
char v22; // bp
char *m; // r15
char *v24; // rdi
char *i; // rsi
wchar_t v26; // eax
char *j; // rsi
__int64 v28; // rdi
char *l; // rsi
int v30; // eax
char *v32; // [rsp+10h] [rbp-48h]
__int64 v33; // [rsp+18h] [rbp-40h]

v0 = locstak();
wdnum = 0;
v33 = v0;
v32 = (char *)(v0 + 8);
wdset = 0;
LABEL_2:
v1 = nextwc();
v2 = v1;
if ( v1 > 0x7F )
goto LABEL_10;
while ( 1 )
{
v3 = *((_BYTE *)&sh_ctype1 + v1);
if ( (v3 & 4) != 0 )
goto LABEL_2;
if ( v2 != 35 )
break;
while ( 1 )
{
v4 = ((__int64 (*)(void))readwc)();
if ( v4 == 10 )
break;
if ( !v4 )
goto LABEL_9;
}
v4 = 10;
LABEL_9:
peekc = v4;
v1 = nextwc();
v2 = v1;
if ( v1 > 0x7F )
goto LABEL_10;
}
if ( (v3 & 0x3E) == 0 )
{
LABEL_10:
v5 = v32;
v6 = 1;
while ( v2 != 39 )
{
if ( !v2 )
goto LABEL_13;
v24 = (char *)v2;
for ( i = readw(v2); *i; ++v5 )
{
while ( brkend > (unsigned __int64)v5 )
{
*v5 = *i++;
v24 = ++v5;
if ( !*i )
goto LABEL_66;
}
growstak(v5);
*v5 = *i++;
v24 = v5 + 1;
}
LABEL_66:
if ( v2 == 92 )
{
v26 = readwc(v24, i);
if ( v26 )
{
for ( j = readw(v26); *j; ++v5 )
{
if ( brkend <= (unsigned __int64)v5 )
growstak(v5);
*v5 = *j++;
}
}
else
{
LABEL_13:
if ( brkend <= (unsigned __int64)v5 )
growstak(v5);
*v5++ = 0;
}
goto LABEL_16;
}
if ( v2 == 61 )
{
wdset |= v6;
goto LABEL_16;
}
if ( v2 <= 0x7F )
{
LABEL_16:
if ( (*((_BYTE *)&sh_ctype2 + v2) & 0x48) == 0 )
v6 = 0;
if ( (*((_BYTE *)&sh_ctype1 + v2) & 0x40) != 0 )
{
LABEL_36:
v12 = v5;
while ( 1 )
{
v13 = nextwc();
v14 = v13;
if ( !v13 )
break;
v15 = (_BYTE *)v13;
for ( k = readw(v13); *k; ++v12 )
{
if ( brkend <= (unsigned __int64)v12 )
growstak(v12);
*v12 = *k++;
v15 = v12 + 1;
}
if ( v2 == v14 )
{
v5 = v12;
goto LABEL_19;
}
if ( v14 == 10 )
{
chkpr(v15, k);
}
else if ( v14 == 92 )
{
v11 = readwc(v15, k);
if ( v11 )
{
v5 = v12;
for ( l = readw(v11); *l; ++v5 )
{
if ( brkend <= (unsigned __int64)v5 )
growstak(v5);
*v5 = *l++;
}
}
else
{
if ( brkend <= (unsigned __int64)v12 )
growstak(v12);
*v12 = 0;
v5 = v12 + 1;
}
goto LABEL_36;
}
}
if ( brkend <= (unsigned __int64)v12 )
growstak(v12);
*v12 = 0;
v5 = v12 + 1;
}
goto LABEL_19;
}
v6 = 0;
LABEL_19:
v7 = nextwc();
v2 = v7;
if ( v7 <= 0x7F && (*((_BYTE *)&sh_ctype1 + v7) & 0x3E) != 0 )
{
endstak(v5);
v8 = *(unsigned __int8 *)(v33 + 8);
if ( (v8 & 0x80u) != 0LL )
{
peekn = v2 | 0x80000000;
wdset = 0;
if ( !reserv )
{
LABEL_26:
wdval = 0;
LOWORD(v10) = 0;
LABEL_27:
wdarg = v33;
goto LABEL_28;
}
}
else
{
v9 = (unsigned __int8)v8;
if ( (*((_BYTE *)&sh_ctype2 + v8) & 0x40) == 0 )
wdset = 0;
peekn = v2 | 0x80000000;
if ( !*(_BYTE *)(v33 + 9)
&& (*((_BYTE *)&sh_ctype2 + (unsigned __int8)v8) & 8) != 0
&& (v2 & 0xFFFFFFFD) == 60 )
{
word();
LOWORD(v10) = wdval;
wdnum = v9 - 48;
goto LABEL_28;
}
if ( !reserv )
goto LABEL_26;
}
v10 = syslook(v32, &reserved, no_reserved);
wdval = v10;
if ( v10 )
goto LABEL_27;
goto LABEL_26;
}
}
v17 = ((__int64 (*)(void))readwc)();
v18 = v5;
v19 = v17;
if ( v17 == 39 )
{
LABEL_57:
if ( v5 == v18 )
{
if ( brkend <= (unsigned __int64)v18 )
growstak(v18);
*v18 = 34;
if ( brkend <= (unsigned __int64)(v18 + 1) )
{
growstak(v18 + 1);
v5 = v18 + 2;
v18[1] = 34;
}
else
{
v18[1] = 34;
v5 = v18 + 2;
}
}
else
{
v5 = v18;
}
goto LABEL_19;
}
while ( 1 )
{
if ( !v17 )
goto LABEL_57;
v20 = readw(v19);
if ( brkend <= (unsigned __int64)v18 )
{
v21 = v18 + 1;
growstak(v18);
*v18 = 92;
if ( v19 == 10 )
{
LABEL_60:
((void (*)(void))chkpr)();
goto LABEL_51;
}
}
else
{
*v18 = 92;
v21 = v18 + 1;
if ( v19 == 10 )
goto LABEL_60;
}
LABEL_51:
v22 = *v20;
for ( m = v20 + 1; v22; v22 = *(m - 1) )
{
if ( brkend <= (unsigned __int64)v21 )
growstak(v21);
++m;
*v21++ = v22;
}
v17 = ((__int64 (*)(void))readwc)();
v18 = v21;
v19 = v17;
if ( v17 == 39 )
goto LABEL_57;
}
}
if ( (v3 & 8) != 0 )
{
v10 = nextwc();
if ( v2 == v10 )
{
v10 = v2;
BYTE1(v10) = BYTE1(v2) | 8;
wdval = v10;
if ( v2 == 60 )
{
v30 = nextwc();
if ( v30 == 45 )
wdnum |= 0x200u;
else
peekn = v30 | 0x80000000;
LOWORD(v10) = wdval;
}
}
else
{
wdval = v2;
peekn = v10 | 0x80000000;
LOWORD(v10) = v2;
}
}
else
{
v28 = iopend;
if ( !v2 )
v2 = 1024;
wdval = v2;
if ( iopend && (v3 & 0x30) != 0 )
{
iopend = 0LL;
copy(v28);
}
LOWORD(v10) = wdval;
}
LABEL_28:
reserv = 0;
return v10;
}

canonical_decompiled_code:
__int16 func5()
{
__int64 v0; // rax
unsigned int v1; // eax
unsigned int v2; // ebx
char v3; // al
int v4; // eax
char *v5; // r12
int v6; // er13
unsigned int v7; // eax
__int64 v8; // rax
int v9; // ebp
unsigned int v10; // eax
wchar_t v11; // eax
char *v12; // rbp
unsigned int v13; // eax
unsigned int v14; // er12
_BYTE *v15; // rdi
char *k; // rsi
wchar_t v17; // eax
char *v18; // r15
wchar_t v19; // ebp
char *v20; // r14
char *v21; // rbx
char v22; // bp
char *m; // r15
char *v24; // rdi
char *i; // rsi
wchar_t v26; // eax
char *j; // rsi
__int64 v28; // rdi
char *l; // rsi
int v30; // eax
char *v32; // [rsp+10h] [rbp-48h]
__int64 v33; // [rsp+18h] [rbp-40h]

v0 = locstak();
wdnum = 0;
v33 = v0;
v32 = (char *)(v0 + 8);
wdset = 0;
LABEL_2:
v1 = func3();
v2 = v1;
if ( v1 > 0x7F )
goto LABEL_10;
while ( 1 )
{
v3 = *((_BYTE *)&sh_ctype1 + v1);
if ( (v3 & 4) != 0 )
goto LABEL_2;
if ( v2 != 35 )
break;
while ( 1 )
{
v4 = ((__int64 (*)(void))readwc)();
if ( v4 == 10 )
break;
if ( !v4 )
goto LABEL_9;
}
v4 = 10;
LABEL_9:
peekc = v4;
v1 = func3();
v2 = v1;
if ( v1 > 0x7F )
goto LABEL_10;
}
if ( (v3 & 0x3E) == 0 )
{
LABEL_10:
v5 = v32;
v6 = 1;
while ( v2 != 39 )
{
if ( !v2 )
goto LABEL_13;
v24 = (char *)v2;
for ( i = func1(v2); *i; ++v5 )
{
while ( brkend > (unsigned __int64)v5 )
{
*v5 = *i++;
v24 = ++v5;
if ( !*i )
goto LABEL_66;
}
growstak(v5);
*v5 = *i++;
v24 = v5 + 1;
}
LABEL_66:
if ( v2 == 92 )
{
v26 = func2(v24, i);
if ( v26 )
{
for ( j = func1(v26); *j; ++v5 )
{
if ( brkend <= (unsigned __int64)v5 )
growstak(v5);
*v5 = *j++;
}
}
else
{
LABEL_13:
if ( brkend <= (unsigned __int64)v5 )
growstak(v5);
*v5++ = 0;
}
goto LABEL_16;
}
if ( v2 == 61 )
{
wdset |= v6;
goto LABEL_16;
}
if ( v2 <= 0x7F )
{
LABEL_16:
if ( (*((_BYTE *)&sh_ctype2 + v2) & 0x48) == 0 )
v6 = 0;
if ( (*((_BYTE *)&sh_ctype1 + v2) & 0x40) != 0 )
{
LABEL_36:
v12 = v5;
while ( 1 )
{
v13 = func3();
v14 = v13;
if ( !v13 )
break;
v15 = (_BYTE *)v13;
for ( k = func1(v13); *k; ++v12 )
{
if ( brkend <= (unsigned __int64)v12 )
growstak(v12);
*v12 = *k++;
v15 = v12 + 1;
}
if ( v2 == v14 )
{
v5 = v12;
goto LABEL_19;
}
if ( v14 == 10 )
{
chkpr(v15, k);
}
else if ( v14 == 92 )
{
v11 = func2(v15, k);
if ( v11 )
{
v5 = v12;
for ( l = func1(v11); *l; ++v5 )
{
if ( brkend <= (unsigned __int64)v5 )
growstak(v5);
*v5 = *l++;
}
}
else
{
if ( brkend <= (unsigned __int64)v12 )
growstak(v12);
*v12 = 0;
v5 = v12 + 1;
}
goto LABEL_36;
}
}
if ( brkend <= (unsigned __int64)v12 )
growstak(v12);
*v12 = 0;
v5 = v12 + 1;
}
goto LABEL_19;
}
v6 = 0;
LABEL_19:
v7 = func3();
v2 = v7;
if ( v7 <= 0x7F && (*((_BYTE *)&sh_ctype1 + v7) & 0x3E) != 0 )
{
endstak(v5);
v8 = *(unsigned __int8 *)(v33 + 8);
if ( (v8 & 0x80u) != 0LL )
{
peekn = v2 | 0x80000000;
wdset = 0;
if ( !reserv )
{
LABEL_26:
wdval = 0;
LOWORD(v10) = 0;
LABEL_27:
wdarg = v33;
goto LABEL_28;
}
}
else
{
v9 = (unsigned __int8)v8;
if ( (*((_BYTE *)&sh_ctype2 + v8) & 0x40) == 0 )
wdset = 0;
peekn = v2 | 0x80000000;
if ( !*(_BYTE *)(v33 + 9)
&& (*((_BYTE *)&sh_ctype2 + (unsigned __int8)v8) & 8) != 0
&& (v2 & 0xFFFFFFFD) == 60 )
{
func5();
LOWORD(v10) = wdval;
wdnum = v9 - 48;
goto LABEL_28;
}
if ( !reserv )
goto LABEL_26;
}
v10 = syslook(v32, &reserved, no_reserved);
wdval = v10;
if ( v10 )
goto LABEL_27;
goto LABEL_26;
}
}
v17 = ((__int64 (*)(void))readwc)();
v18 = v5;
v19 = v17;
if ( v17 == 39 )
{
LABEL_57:
if ( v5 == v18 )
{
if ( brkend <= (unsigned __int64)v18 )
growstak(v18);
*v18 = 34;
if ( brkend <= (unsigned __int64)(v18 + 1) )
{
growstak(v18 + 1);
v5 = v18 + 2;
v18[1] = 34;
}
else
{
v18[1] = 34;
v5 = v18 + 2;
}
}
else
{
v5 = v18;
}
goto LABEL_19;
}
while ( 1 )
{
if ( !v17 )
goto LABEL_57;
v20 = func1(v19);
if ( brkend <= (unsigned __int64)v18 )
{
v21 = v18 + 1;
growstak(v18);
*v18 = 92;
if ( v19 == 10 )
{
LABEL_60:
((void (*)(void))chkpr)();
goto LABEL_51;
}
}
else
{
*v18 = 92;
v21 = v18 + 1;
if ( v19 == 10 )
goto LABEL_60;
}
LABEL_51:
v22 = *v20;
for ( m = v20 + 1; v22; v22 = *(m - 1) )
{
if ( brkend <= (unsigned __int64)v21 )
growstak(v21);
++m;
*v21++ = v22;
}
v17 = ((__int64 (*)(void))readwc)();
v18 = v21;
v19 = v17;
if ( v17 == 39 )
goto LABEL_57;
}
}
if ( (v3 & 8) != 0 )
{
v10 = func3();
if ( v2 == v10 )
{
v10 = v2;
BYTE1(v10) = BYTE1(v2) | 8;
wdval = v10;
if ( v2 == 60 )
{
v30 = func3();
if ( v30 == 45 )
wdnum |= 0x200u;
else
peekn = v30 | 0x80000000;
LOWORD(v10) = wdval;
}
}
else
{
wdval = v2;
peekn = v10 | 0x80000000;
LOWORD(v10) = v2;
}
}
else
{
v28 = iopend;
if ( !v2 )
v2 = 1024;
wdval = v2;
if ( iopend && (v3 & 0x30) != 0 )
{
iopend = 0LL;
copy(v28);
}
LOWORD(v10) = wdval;
}
LABEL_28:
reserv = 0;
return v10;
}

original_code:
int
word(void)
{
 register unsigned int c, d, cc;
 struct argnod *arg = (struct argnod *)locstak();
 register unsigned char *argp = arg->argval;
 unsigned char *oldargp;
 int alpha = 1;
 unsigned char *pc;
 wdnum = 0;
 wdset = 0;
 while (1)
 {
  while (c = nextwc(), ((c<0200) && sh_ctype1[c]&(04)))
   ;
  if (c == '#')
  {
   while ((c = readwc()) != '\n' && c != 0);
   peekc = c;
  }
  else
  {
   break;
  }
 }
 if (!((c<0200) && sh_ctype1[c]&((04|010|02|040)|020)))
 {
  do
  {
   if (c == '\'')
   {
    oldargp = argp;
    while ((c = readwc()) && c != '\''){
     pc = readw(c);
     if (argp >= brkend)
      growstak(argp);
     *argp++='\\';
     if (c == '\n')
      chkpr();
     while (c = *pc++) {
      if (argp >= brkend)
       growstak(argp);
      *argp++ = (unsigned char)c;
     }
    }
    if (argp == oldargp) {
     if (argp >= brkend)
      growstak(argp);
     *argp++ = '"';
     if (argp >= brkend)
      growstak(argp);
     *argp++ = '"';
    }
   }
   else
   {
    if (c == 0) {
     if (argp >= brkend)
      growstak(argp);
     *argp++ = 0;
    } else {
     pc = readw(c);
     while (*pc) {
      if (argp >= brkend)
       growstak(argp);
      *argp++ = *pc++;
     }
    }
    if (c == '\\') {
     if ((cc = readwc()) == 0) {
      if (argp >= brkend)
       growstak(argp);
      *argp++ = 0;
     } else {
      pc = readw(cc);
      while (*pc) {
       if (argp >= brkend)
        growstak(argp);
       *argp++ = *pc++;
      }
     }
    }
    if (c == '=')
     wdset |= alpha;
    if (!((c<0200) && sh_ctype2[c]&((0100|010))))
     alpha = 0;
    if (((c<0200) && sh_ctype1[c]&(0100)))
    {
     d = c;
     for (;;)
     {
      if ((c = nextwc()) == 0) {
       if (argp >= brkend)
        growstak(argp);
       *argp++ = 0;
      } else {
       pc = readw(c);
       while (*pc) {
        if (argp >= brkend)
         growstak(argp);
        *argp++ = *pc++;
       }
      }
      if (c == 0 || c == d)
       break;
      if (c == '\n')
       chkpr();
      if (c == '\\') {
       if ((cc = readwc()) == 0) {
        if (argp >= brkend)
         growstak(argp);
        *argp++ = 0;
       } else {
        pc = readw(cc);
        while (*pc) {
         if (argp >= brkend)
          growstak(argp);
         *argp++ = *pc++;
        }
       }
      }
     }
    }
   }
  } while ((c = nextwc(), !((c<0200) && sh_ctype1[c]&((04|010|02|040)|020))));
  argp = endstak(argp);
  if (!((arg->argval[0]<0200) && sh_ctype2[arg->argval[0]]&(0100)))
   wdset = 0;
  peekn = c | 0x80000000;
  if (arg->argval[1] == 0 &&
      (d = arg->argval[0], ((d<0200) && sh_ctype2[d]&(010))) &&
      (c == '>' || c == '<'))
  {
   word();
   wdnum = d - '0';
  }else{
   if (reserv == 0 ||
       (wdval = syslook(arg->argval,
     reserved, no_reserved)) == 0) {
    wdval = 0;
   }
   wdarg = arg;
  }
 }else if (((c<0200) && sh_ctype1[c]&(010))){
  if ((d = nextwc()) == c)
  {
   wdval = c | 04000;
   if (c == '<')
   {
    if ((d = nextwc()) == '-')
     wdnum |= 512;
    else
     peekn = d | 0x80000000;
   }
  }
  else
  {
   peekn = d | 0x80000000;
   wdval = c;
  }
 }
 else
 {
  if ((wdval = c) == 0)
   wdval = 02000;
  if (iopend && ((c<0200) && sh_ctype1[c]&(040|020)))
  {
   struct ionod *tmp_iopend;
   tmp_iopend = iopend;
   iopend = 0;
   copy(tmp_iopend);
  }
 }
 reserv = 0;
 return (wdval);
}

canonical_original_code:
int word()
{
 register unsigned int c; register unsigned int d; register unsigned int cc;
 struct argnod *arg = (struct argnod *)locstak();
 register unsigned char *argp = arg->argval;
 unsigned char *oldargp;
 int alpha = 1;
 unsigned char *pc;
 wdnum = 0;
 wdset = 0;
 while (1)
 {
  while (c = nextwc(), ((c<0200) && sh_ctype1[c]&(04)))
   ;
  if (c == '#')
  {
   while ((c = readwc()) != '\n' && c != 0);
   peekc = c;
  }
  else
  {
   break;
  }
 }
 if (!((c<0200) && sh_ctype1[c]&((04|010|02|040)|020)))
 {
  do
  {
   if (c == '\'')
   {
    oldargp = argp;
    while ((c = readwc()) && c != '\''){
     pc = readw(c);
     if (argp >= brkend)
      growstak(argp);
     *argp++='\\';
     if (c == '\n')
      chkpr();
     while (c = *pc++) {
      if (argp >= brkend)
       growstak(argp);
      *argp++ = (unsigned char)c;
     }
    }
    if (argp == oldargp) {
     if (argp >= brkend)
      growstak(argp);
     *argp++ = '"';
     if (argp >= brkend)
      growstak(argp);
     *argp++ = '"';
    }
   }
   else
   {
    if (c == 0) {
     if (argp >= brkend)
      growstak(argp);
     *argp++ = 0;
    } else {
     pc = readw(c);
     while (*pc) {
      if (argp >= brkend)
       growstak(argp);
      *argp++ = *pc++;
     }
    }
    if (c == '\\') {
     if ((cc = readwc()) == 0) {
      if (argp >= brkend)
       growstak(argp);
      *argp++ = 0;
     } else {
      pc = readw(cc);
      while (*pc) {
       if (argp >= brkend)
        growstak(argp);
       *argp++ = *pc++;
      }
     }
    }
    if (c == '=')
     wdset |= alpha;
    if (!((c<0200) && sh_ctype2[c]&((0100|010))))
     alpha = 0;
    if (((c<0200) && sh_ctype1[c]&(0100)))
    {
     d = c;
     for (;;)
     {
      if ((c = nextwc()) == 0) {
       if (argp >= brkend)
        growstak(argp);
       *argp++ = 0;
      } else {
       pc = readw(c);
       while (*pc) {
        if (argp >= brkend)
         growstak(argp);
        *argp++ = *pc++;
       }
      }
      if (c == 0 || c == d)
       break;
      if (c == '\n')
       chkpr();
      if (c == '\\') {
       if ((cc = readwc()) == 0) {
        if (argp >= brkend)
         growstak(argp);
        *argp++ = 0;
       } else {
        pc = readw(cc);
        while (*pc) {
         if (argp >= brkend)
          growstak(argp);
         *argp++ = *pc++;
        }
       }
      }
     }
    }
   }
  } while ((c = nextwc(), !((c<0200) && sh_ctype1[c]&((04|010|02|040)|020))));
  argp = endstak(argp);
  if (!((arg->argval[0]<0200) && sh_ctype2[arg->argval[0]]&(0100)))
   wdset = 0;
  peekn = c | 0x80000000;
  if (arg->argval[1] == 0 &&
      (d = arg->argval[0], ((d<0200) && sh_ctype2[d]&(010))) &&
      (c == '>' || c == '<'))
  {
   word();
   wdnum = d - '0';
  }else{
   if (reserv == 0 ||
       (wdval = syslook(arg->argval,
     reserved, no_reserved)) == 0) {
    wdval = 0;
   }
   wdarg = arg;
  }
 }else if (((c<0200) && sh_ctype1[c]&(010))){
  if ((d = nextwc()) == c)
  {
   wdval = c | 04000;
   if (c == '<')
   {
    if ((d = nextwc()) == '-')
     wdnum |= 512;
    else
     peekn = d | 0x80000000;
   }
  }
  else
  {
   peekn = d | 0x80000000;
   wdval = c;
  }
 }
 else
 {
  if ((wdval = c) == 0)
   wdval = 02000;
  if (iopend && ((c<0200) && sh_ctype1[c]&(040|020)))
  {
   struct ionod *tmp_iopend;
   tmp_iopend = iopend;
   iopend = 0;
   copy(tmp_iopend);
  }
 }
 reserv = 0;
 return (wdval);
}

variable_types:
cc
unsigned int

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

variable_types:
argp
unsigned char *

variable_types:
oldargp
unsigned char *

variable_types: alpha int

variable_types:
pc
unsigned char *

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


free

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

if ( a1 )
{
result = *(_QWORD *)(a1 - 8);
*(_QWORD *)(result + 24) = a1 - 16;
*(_QWORD *)(a1 - 16) &= 0xFFFFFFFFFFFFFFFELL;
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 - 8);
*(_QWORD *)(result + 24) = a1 - 16;
*(_QWORD *)(a1 - 16) &= 0xFFFFFFFFFFFFFFFELL;
}
return result;
}

original_code:
void
free(register void *ap)
{
 register union store *p = ap;
 struct pool *o;
 ;
 if (ap == 0)
  return;
 o = p[-1].pool;
 ;
 ;
 (o->Allocp) = p -= 2;
 ;
 p->ptr = (union store *)((intptr_t)(p->ptr)&~((intptr_t)1));
 ;
}

canonical_original_code:
void free(void *ap)
{
 register union store *p = ap;
 struct pool *o;
 ;
 if (ap == 0)
  return;
 o = p[-1].pool;
 ;
 ;
 (o->Allocp) = p -= 2;
 ;
 p->ptr = (union store *)((long)(p->ptr)&~((long)1));
 ;
}

variable_types:
ap
void *

variable_types: union store { union store *ptr; struct pool { struct pool *Next; union store Allocs[2]; union store *Allocp; union store *Alloct; union store *Allocx; char *Brk; char *End; long Dummy[1]; } *pool; long dummy[1]; long callocsp; } *

variable_types: struct pool { struct pool *Next; union store { union store *ptr; struct pool *pool; long dummy[1]; long callocsp; } Allocs[2]; union store *Allocp; union store *Alloct; union store *Allocx; char *Brk; char *End; long Dummy[1]; } *


calloc

decompiled_code:
void *__fastcall calloc(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
void *v3; // r8
unsigned __int64 v4; // rbx

v2 = a2 * a1;
v3 = malloc(v2);
if ( v3 )
{
v4 = (unsigned __int64)(v2 + 7) >> 3;
if ( (int)v4 > 0 )
v3 = memset(v3, 0, 8LL * (unsigned int)(v4 - 1) + 8);
}
return v3;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
void *v3; // r8
unsigned __int64 v4; // rbx

v2 = a2 * a1;
v3 = malloc(v2);
if ( v3 )
{
v4 = (unsigned __int64)(v2 + 7) >> 3;
if ( (int)v4 > 0 )
v3 = memset(v3, 0, 8LL * (unsigned int)(v4 - 1) + 8);
}
return v3;
}

original_code:
void *
calloc(size_t num, size_t size)
{
 register char *mp;
 register intptr_t *q;
 register int m;
 num *= size;
 mp = malloc(num);
 if(mp==0)
  return(0);
 q = (intptr_t *) mp;
 m = (num+(sizeof(intptr_t)/sizeof(char))-1)/(sizeof(intptr_t)/sizeof(char));
 while(--m >= 0)
  *q++ = 0;
 return(mp);
}

canonical_original_code:
void *calloc(unsigned long num, unsigned long size)
{
 register char *mp;
 register long *q;
 register int m;
 num *= size;
 mp = malloc(num);
 if(mp==0)
  return(0);
 q = (long *) mp;
 m = (num+(sizeof(long)/sizeof(char))-1)/(sizeof(long)/sizeof(char));
 while(--m >= 0)
  *q++ = 0;
 return(mp);
}

variable_types:
num
unsigned long

variable_types:
size
unsigned long

variable_types:
mp
char *

variable_types:
q
long *

variable_types: m int

return_type: void *


exitsh

decompiled_code:
__int64 __fastcall exitsh(__int64 a1)
{
exitval = a1;
flags |= eflag;
if ( (flags & 0x200070) == 32LL )
{
clearup(a1);
restore(0LL);
setb(1LL);
funcnt = 0;
breakcnt = 0;
execbrk = 0;
longjmp(errshell, 1);
}
return done(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
exitval = a1;
flags |= eflag;
if ( (flags & 0x200070) == 32LL )
{
clearup(a1);
restore(0LL);
setb(1LL);
funcnt = 0;
breakcnt = 0;
execbrk = 0;
longjmp(errshell, 1);
}
return done(0LL);
}

original_code:
void
exitsh(int xno)
{
 exitval = xno;
 flags |= eflag;
 if ((flags & (010000000 | 0100 | 020 | 040)) != 040)
  done(0);
 else
 {
  clearup();
  restore(0);
  setb(1);
  execbrk = breakcnt = funcnt = 0;
  longjmp(errshell, 1);
 }
}

variable_types: xno int


failed

decompiled_code:
__int64 __fastcall failed(__int64 a1, __int64 a2)
{
prp();
prs_cntl(a1);
if ( a2 )
{
prs(&colon);
prs(a2);
}
prc(10LL);
return exitsh(1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
prp();
prs_cntl(a1);
if ( a2 )
{
prs(&colon);
prs(a2);
}
prc(10LL);
return func0(1LL);
}

original_code:
void
failed(const unsigned char *s1, const unsigned char *s2)
{
 prp();
 prs_cntl(s1);
 if (s2)
 {
  prs(colon);
  prs(s2);
 }
 prc('\n');
 exitsh(1);
}

canonical_original_code:
void failed(unsigned char *s1, unsigned char *s2)
{
 prp();
 prs_cntl(s1);
 if (s2)
 {
  prs(colon);
  prs(s2);
 }
 prc('\n');
 exitsh(1);
}


error

decompiled_code:
__int64 __fastcall error(__int64 a1)
{
return failed(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return func1(a1, 0LL);
}

original_code:
void
error(const unsigned char *s)
{
 failed(s, ((char*)0));
}

canonical_original_code:
void error(unsigned char *s)
{
 failed(s, ((char *)0));
}

variable_types:
s
unsigned char *


rmtemp

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

for ( result = iotemp; result > a1; iotemp = result )
{
unlink(*(const char **)(result + 8));
sh_free(*(_QWORD *)(iotemp + 16LL));
result = *(_QWORD *)(iotemp + 32LL);
}
return result;
}

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

for ( result = iotemp; result > a1; iotemp = result )
{
unlink(*(const char **)(result + 8));
sh_free(*(_QWORD *)(iotemp + 16LL));
result = *(_QWORD *)(iotemp + 32LL);
}
return result;
}

original_code:
void
rmtemp(struct ionod *base)
{
 while (iotemp > base)
 {
  unlink(iotemp->ioname);
  sh_free(iotemp->iolink);
  iotemp = iotemp->iolst;
 }
}

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


rmfunctmp

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

for ( result = fiotemp; result; fiotemp = result )
{
unlink(*(const char **)(result + 8));
result = *(_QWORD *)(fiotemp + 32LL);
}
return result;
}

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

for ( result = fiotemp; result; fiotemp = result )
{
unlink(*(const char **)(result + 8));
result = *(_QWORD *)(fiotemp + 32LL);
}
return result;
}

original_code:
void
rmfunctmp(void)
{
 while (fiotemp)
 {
  unlink(fiotemp->ioname);
  fiotemp = fiotemp->iolst;
 }
}

canonical_original_code:
void rmfunctmp()
{
 while (fiotemp)
 {
  unlink(fiotemp->ioname);
  fiotemp = fiotemp->iolst;
 }
}


failure

decompiled_code:
__int64 __fastcall failure(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

prp();
prs_cntl(a1);
if ( a2 )
{
prs(&colon);
prs(a2);
}
prc(10LL);
v2 = flags;
if ( (flags & 0x10) != 0 )
{
exitsh(1LL);
v2 = flags;
}
exitval = 1;
retval = 1;
result = v2 | eflag;
flags = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

prp();
prs_cntl(a1);
if ( a2 )
{
prs(&colon);
prs(a2);
}
prc(10LL);
v2 = flags;
if ( (flags & 0x10) != 0 )
{
func0(1LL);
v2 = flags;
}
exitval = 1;
retval = 1;
result = v2 | eflag;
flags = result;
return result;
}

original_code:
void
failure(const unsigned char *s1, const unsigned char *s2)
{
 prp();
 prs_cntl(s1);
 if (s2)
 {
  prs(colon);
  prs(s2);
 }
 prc('\n');
 if (flags & 020)
  exitsh(1);
 flags |= eflag;
 exitval = 1;
 retval = exitval;
}

canonical_original_code:
void failure(unsigned char *s1, unsigned char *s2)
{
 prp();
 prs_cntl(s1);
 if (s2)
 {
  prs(colon);
  prs(s2);
 }
 prc('\n');
 if (flags & 020)
  exitsh(1);
 flags |= eflag;
 exitval = 1;
 retval = exitval;
}


echo

original_code:
int
echo(int argc, unsigned char **argv)
{
 register unsigned char *cp;
 register int i, wd;
 int nflg = 0;
 int j;
 int len;
 wchar_t wc;
 struct namnod *sysv3;
 int do_sysv3 = 0;
 sysv3 = findnam("SYSV3");
 if (sysv3 && (sysv3->namflg & (0004 | 0002)))
  do_sysv3 = 1;
 if (ucb_builtins && !do_sysv3) {
  nflg = 0;
  if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'n') {
   nflg++;
   argc--;
   argv++;
  }
  for (i = 1; i < argc; i++) {
   if (trapnote & 4) exitsh(exitval ? exitval : 2000);
   for (cp = argv[i]; *cp; cp++) {
    prc_buff(*cp);
   }
   if (i < argc-1)
    prc_buff(' ');
  }
  if (nflg == 0)
   prc_buff('\n');
  flushb(); return (0);
 } else {
  if (--argc == 0) {
   prc_buff('\n');
   flushb(); return (0);
  }
  if (do_sysv3) {
   if (argc > 1 && argv[1][0] == '-' &&
     argv[1][1] == 'n') {
    nflg++;
    argc--;
    argv++;
   }
  }
  for (i = 1; i <= argc; i++)
  {
   if (trapnote & 4) exitsh(exitval ? exitval : 2000);
   for (cp = argv[i]; *cp; cp++) {
    if ((len = (mb_cur_max > 1 && *((char *)cp) & 0200 ? mbtowc(&wc, (char *)cp, mb_cur_max) : (*(&wc) = *((char *)cp) & 0377, *(&wc) != 0))) <= 0) {
     prc_buff(*cp);
     continue;
    }
    if (wc == '\\') {
     switch (*++cp) {
     case 'b':
      prc_buff('\b');
      continue;
     case 'c':
      flushb(); return (0);
     case 'f':
      prc_buff('\f');
      continue;
     case 'n':
      prc_buff('\n');
      continue;
     case 'r':
      prc_buff('\r');
      continue;
     case 't':
      prc_buff('\t');
      continue;
     case 'v':
      prc_buff('\v');
      continue;
     case '\\':
      prc_buff('\\');
      continue;
     case '0':
      j = wd = 0;
      while ((*++cp >= '0' &&
      *cp <= '7') && j++ < 3) {
       wd <<= 3;
       wd |= (*cp - '0');
      }
      prc_buff(wd);
      --cp;
      continue;
     default:
      cp--;
     }
     prc_buff(*cp);
     continue;
    } else {
     for (; len > 0; len--)
      prc_buff(*cp++);
     cp--;
     continue;
    }
   }
   if (!(nflg && i == argc))
    prc_buff(i == argc? '\n': ' ');
  }
  flushb(); return (0);
 }
}

canonical_original_code:
int echo(int argc, unsigned char **argv)
{
 register unsigned char *cp;
 register int i; register int wd;
 int nflg = 0;
 int j;
 int len;
 int wc;
 struct namnod *sysv3;
 int do_sysv3 = 0;
 sysv3 = findnam("SYSV3");
 if (sysv3 && (sysv3->namflg & (0004 | 0002)))
  do_sysv3 = 1;
 if (ucb_builtins && !do_sysv3) {
  nflg = 0;
  if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'n') {
   nflg++;
   argc--;
   argv++;
  }
  for (i = 1; i < argc; i++) {
   if (trapnote & 4) exitsh(exitval ? exitval : 2000);
   for (cp = argv[i]; *cp; cp++) {
    prc_buff(*cp);
   }
   if (i < argc-1)
    prc_buff(' ');
  }
  if (nflg == 0)
   prc_buff('\n');
  flushb(); return (0);
 } else {
  if (--argc == 0) {
   prc_buff('\n');
   flushb(); return (0);
  }
  if (do_sysv3) {
   if (argc > 1 && argv[1][0] == '-' &&
     argv[1][1] == 'n') {
    nflg++;
    argc--;
    argv++;
   }
  }
  for (i = 1; i <= argc; i++)
  {
   if (trapnote & 4) exitsh(exitval ? exitval : 2000);
   for (cp = argv[i]; *cp; cp++) {
    if ((len = (mb_cur_max > 1 && *((char *)cp) & 0200 ? mbtowc(&wc, (char *)cp, mb_cur_max) : (*(&wc) = *((char *)cp) & 0377, *(&wc) != 0))) <= 0) {
     prc_buff(*cp);
     continue;
    }
    if (wc == '\\') {
     switch (*++cp) {
     case 'b':
      prc_buff('\b');
      continue;
     case 'c':
      flushb(); return (0);
     case 'f':
      prc_buff('\f');
      continue;
     case 'n':
      prc_buff('\n');
      continue;
     case 'r':
      prc_buff('\r');
      continue;
     case 't':
      prc_buff('\t');
      continue;
     case 'v':
      prc_buff('\v');
      continue;
     case '\\':
      prc_buff('\\');
      continue;
     case '0':
      j = wd = 0;
      while ((*++cp >= '0' &&
      *cp <= '7') && j++ < 3) {
       wd <<= 3;
       wd |= (*cp - '0');
      }
      prc_buff(wd);
      --cp;
      continue;
     default:
      cp--;
     }
     prc_buff(*cp);
     continue;
    } else {
     for (; len > 0; len--)
      prc_buff(*cp++);
     cp--;
     continue;
    }
   }
   if (!(nflg && i == argc))
    prc_buff(i == argc? '\n': ' ');
  }
  flushb(); return (0);
 }
}

variable_types: argc int

variable_types:
argv
unsigned char **

variable_types:
cp
unsigned char *

variable_types: i int

variable_types: wd int

variable_types: nflg int

variable_types: j int

variable_types: len int

variable_types: wc int

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


err

original_code:
static void
err(const char *s, int c, const char *optstring, const char *argv0)
{
 char errbuf[256], *ep = errbuf;
 const char *cp;
 if (opterr && optstring[0] != ':') {
  for (cp = argv0; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++)
   *ep = *cp;
  for (cp = ": "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++)
   *ep = *cp;
  for (cp = s; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++)
   *ep = *cp;
  for (cp = " -- "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++)
   *ep = *cp;
  if (ep<&errbuf[sizeof errbuf])
   *ep++ = c;
  if (ep<&errbuf[sizeof errbuf])
   *ep++ = '\n';
  write(2, errbuf, ep - errbuf);
 }
}

canonical_original_code:
static void err(char *s, int c, char *optstring, char *argv0)
{
 char errbuf[256]; char *ep = errbuf;
 char *cp;
 if (opterr && optstring[0] != ':') {
  for (cp = argv0; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++)
   *ep = *cp;
  for (cp = ": "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++)
   *ep = *cp;
  for (cp = s; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++)
   *ep = *cp;
  for (cp = " -- "; *cp && ep<&errbuf[sizeof errbuf]; cp++, ep++)
   *ep = *cp;
  if (ep<&errbuf[sizeof errbuf])
   *ep++ = c;
  if (ep<&errbuf[sizeof errbuf])
   *ep++ = '\n';
  write(2, errbuf, ep - errbuf);
 }
}

variable_types:
s
char *

variable_types: c int

variable_types:
optstring
char *

variable_types:
errbuf
char [256]

variable_types:
ep
char *

variable_types:
cp
char *


getopt

decompiled_code:
__int64 __fastcall getopt(int a1, char **a2, char *a3)
{
char **v5; // r11
char *v6; // rax
__int64 v7; // rbp
int v8; // esi
char *v9; // rax
int v10; // ecx
int v11; // er8
int v12; // er9
__int64 *v13; // r11
unsigned int v14; // er10
__int64 v15; // rdx
_BYTE *v17; // rdx
int v18; // eax
bool v19; // zf
__int64 v20; // rax

if ( getopt_sp != 1 )
{
v6 = a2[optind];
goto LABEL_7;
}
if ( a1 <= optind )
return (unsigned int)-1;
v5 = &a2[optind];
v6 = *v5;
if ( **v5 != 45 || !v6[1] )
return (unsigned int)-1;
if ( v6[1] == 45 && !v6[2] )
{
v14 = -1;
++optind;
return v14;
}
LABEL_7:
v7 = getopt_sp;
v8 = v6[getopt_sp];
optarg = 0LL;
optopt = v8;
v9 = parse(a3, v8);
if ( !v9 )
err("illegal option", v8, a3, *a2);
v14 = *v9;
v15 = *v13;
optopt = v14;
if ( v9[1] != 58 )
{
getopt_sp = v10 + 1;
if ( !*(_BYTE *)(v15 + v10 + 1) )
{
getopt_sp = 1;
optind = v11 + 1;
}
return v14;
}
v17 = (_BYTE *)(v15 + v7 + 1);
v18 = v11 + 1;
v19 = *v17 == 0;
optind = v11 + 1;
if ( v19 )
{
if ( v12 <= v18 )
err("option requires an argument", v14, a3, *a2);
v20 = (__int64)a2[v18];
optind = v11 + 2;
optarg = v20;
}
else
{
optarg = (__int64)v17;
}
getopt_sp = 1;
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, char **a2, char *a3)
{
char **v5; // r11
char *v6; // rax
__int64 v7; // rbp
int v8; // esi
char *v9; // rax
int v10; // ecx
int v11; // er8
int v12; // er9
__int64 *v13; // r11
unsigned int v14; // er10
__int64 v15; // rdx
_BYTE *v17; // rdx
int v18; // eax
bool v19; // zf
__int64 v20; // rax

if ( getopt_sp != 1 )
{
v6 = a2[optind];
goto LABEL_7;
}
if ( a1 <= optind )
return (unsigned int)-1;
v5 = &a2[optind];
v6 = *v5;
if ( **v5 != 45 || !v6[1] )
return (unsigned int)-1;
if ( v6[1] == 45 && !v6[2] )
{
v14 = -1;
++optind;
return v14;
}
LABEL_7:
v7 = getopt_sp;
v8 = v6[getopt_sp];
optarg = 0LL;
optopt = v8;
v9 = func0(a3, v8);
if ( !v9 )
func1("illegal option", v8, a3, *a2);
v14 = *v9;
v15 = *v13;
optopt = v14;
if ( v9[1] != 58 )
{
getopt_sp = v10 + 1;
if ( !*(_BYTE *)(v15 + v10 + 1) )
{
getopt_sp = 1;
optind = v11 + 1;
}
return v14;
}
v17 = (_BYTE *)(v15 + v7 + 1);
v18 = v11 + 1;
v19 = *v17 == 0;
optind = v11 + 1;
if ( v19 )
{
if ( v12 <= v18 )
func1("option requires an argument", v14, a3, *a2);
v20 = (__int64)a2[v18];
optind = v11 + 2;
optarg = v20;
}
else
{
optarg = (__int64)v17;
}
getopt_sp = 1;
return v14;
}

original_code:
int
getopt(int argc, char *const *argv, const char *optstring)
{
 char c;
 char *cp;
 if (getopt_sp == 1) {
  if (optind >= argc || argv[optind][0] != '-' ||
      argv[optind] == ((void *)0) || argv[optind][1] == '\0')
   return ((-1));
  else if (strcmp(argv[optind], "--") == 0) {
   optind++;
   return ((-1));
  }
 }
 optopt = c = (unsigned char)argv[optind][getopt_sp];
 optarg = ((void *)0);
 if ((cp = parse(optstring, c)) == ((void *)0)) {
  err("illegal option", c, optstring, argv[0]);
  if (argv[optind][++getopt_sp] == '\0') {
   optind++;
   getopt_sp = 1;
  }
  return ('?');
 }
 optopt = c = *cp;
 if (*(cp + 1) == ':') {
  if (argv[optind][getopt_sp+1] != '\0') {
   optarg = &argv[optind++][getopt_sp+1];
  } else if (++optind >= argc) {
   err("option requires an argument", c, optstring, argv[0]);
   getopt_sp = 1;
   optarg = ((void *)0);
   return (optstring[0] == ':' ? ':' : '?');
  } else
   optarg = argv[optind++];
  getopt_sp = 1;
 } else {
  if (argv[optind][++getopt_sp] == '\0') {
   getopt_sp = 1;
   optind++;
  }
  optarg = ((void *)0);
 }
 return (c);
}

canonical_original_code:
int getopt(int argc, char **argv, char *optstring)
{
 char c;
 char *cp;
 if (getopt_sp == 1) {
  if (optind >= argc || argv[optind][0] != '-' ||
      argv[optind] == ((void *)0) || argv[optind][1] == '\0')
   return ((-1));
  else if (strcmp(argv[optind], "--") == 0) {
   optind++;
   return ((-1));
  }
 }
 optopt = c = (unsigned char)argv[optind][getopt_sp];
 optarg = ((void *)0);
 if ((cp = parse(optstring, c)) == ((void *)0)) {
  err("illegal option", c, optstring, argv[0]);
  if (argv[optind][++getopt_sp] == '\0') {
   optind++;
   getopt_sp = 1;
  }
  return ('?');
 }
 optopt = c = *cp;
 if (*(cp + 1) == ':') {
  if (argv[optind][getopt_sp+1] != '\0') {
   optarg = &argv[optind++][getopt_sp+1];
  } else if (++optind >= argc) {
   err("option requires an argument", c, optstring, argv[0]);
   getopt_sp = 1;
   optarg = ((void *)0);
   return (optstring[0] == ':' ? ':' : '?');
  } else
   optarg = argv[optind++];
  getopt_sp = 1;
 } else {
  if (argv[optind][++getopt_sp] == '\0') {
   getopt_sp = 1;
   optind++;
  }
  optarg = ((void *)0);
 }
 return (c);
}

variable_types:
argv
char **

variable_types: c char


execprint

decompiled_code:
__int64 __fastcall execprint(const void **a1)
{
const void *v1; // rbp
const void **v2; // rbx
int v3; // eax

prs(&execpmsg);
v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
do
{
++v2;
v3 = length(v1);
write(output, v1, v3 - 1);
prc(32LL);
v1 = *(v2 - 1);
}
while ( v1 );
}
return prc(10LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(const void **a1)
{
const void *v1; // rbp
const void **v2; // rbx
int v3; // eax

prs(&execpmsg);
v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
do
{
++v2;
v3 = length(v1);
write(output, v1, v3 - 1);
prc(32LL);
v1 = *(v2 - 1);
}
while ( v1 );
}
return prc(10LL);
}

original_code:
void
execprint(unsigned char **com)
{
 register int argn = 0;
 unsigned char *s;
 prs(execpmsg);
 while(com[argn] != 0)
 {
  s = com[argn++];
  write(output, s, length(s) - 1);
  prc(' ');
 }
 prc('\n');
}

variable_types:
com
unsigned char **

variable_types: argn int

variable_types:
s
unsigned char *


execute

original_code:
int
execute(struct trenod *argt, int xflags, int errorflg, int *pf1, int *pf2)
{
 register struct trenod *t;
 unsigned char *sav = savstak();
 if (trapnote & 4) exitsh(exitval ? exitval : 2000);
 if (!errorflg)
  flags &= ~020;
 if ((t = argt) && execbrk == 0) {
  register int treeflgs;
  register unsigned char **com = ((void *)0);
  int type;
  short pos = 0;
  treeflgs = t->tretyp;
  type = treeflgs & 0x00F0;
  switch (type)
  {
  case 0x00C0:
   {
    struct fndnod *f = (struct fndnod *)t;
    struct namnod *n = lookup(f->fndnam);
    exitval = 0;
    if (n->namflg & 0010)
     failed(n->namid, wtfailed);
    if (flags & 0400 && (n == &pathnod ||
     (cf(n->namid, "SHELL") == 0)))
     failed(n->namid, restricted);
    if (n->namflg & 0001)
     freefunc(n);
    else
    {
     sh_free(n->namval);
     sh_free(n->namenv);
     n->namval = 0;
     n->namflg &= ~(0004 | 0020);
    }
    if (funcnt)
     f->fndval->tretyp++;
    n->namenv = (unsigned char *)f->fndval;
    (n->namflg |= 0001);
    hash_func(n->namid);
    break;
   }
  case 0x0000:
   {
    unsigned char *a1;
    int argn;
    struct argnod *schain = gchain;
    struct ionod *io = t->treio;
    short cmdhash = 0;
    short comtype = 0;
    exitval = 0;
    gchain = 0;
    argn = getarg((struct comnod *)t);
    com = scan(argn);
    a1 = com[1];
    gchain = schain;
    if (argn != 0)
     cmdhash = pathlook(com[0], 1, ((struct comnod *)t)->comset);
    if (argn == 0 || (comtype = (cmdhash & 0x1F00)) == 0x0100) {
     setlist(((struct comnod *)t)->comset, 0);
    }
    if (argn && (flags&01) == 0)
    {
     if (flags & 04000)
      execprint(com);
     if (comtype == 0x0000)
     {
      pos = (cmdhash & 0x00FF);
      if (pos == 1)
       failure(*com, notfound);
      else if (pos == 2)
       failure(*com, badexec);
      else
       failure(*com, badperm);
      break;
     }
     else if (comtype == 0x1000)
     {
      pos = -1;
     }
     else if (comtype & (0x0400 | 0x0800))
     {
      pos = (cmdhash & 0x00FF);
     }
     else if (comtype == 0x0100) {
      builtin((cmdhash & 0x00FF),argn,com,t);
      freejobs();
      break;
     }
     else if (comtype == 0x0200)
     {
      struct dolnod *olddolh;
      struct namnod *n;
      short index;
      unsigned char **olddolv = dolv;
      int olddolc = dolc;
      n = findnam(com[0]);
      olddolh = (struct dolnod *)savargs(funcnt);
      funcnt++;
      index = initio(io, 1);
      setargs(com);
      execute((struct trenod *)(n->namenv), xflags, errorflg, pf1, pf2);
      execbrk = 0;
      restore(index);
      restorargs(olddolh, funcnt);
      dolv = olddolv;
      dolc = olddolc;
      funcnt--;
      break;
     }
    }
    else if (t->treio == 0)
    {
     chktrap();
     break;
    }
   }
  case 0x00A0:
  {
   int monitor = 0;
   int linked = 0;
   exitval = 0;
   if (!(xflags & 01) || treeflgs&(0x0200|0x0400))
   {
    int forkcnt = 1;
    if (!(treeflgs&0x0200))
    {
     monitor = (!(xflags & 04)
       && (flags&(01000000|02000000|020000000))
       == (01000000|02000000));
     if (monitor) {
      int savefd;
      unsigned char *savebot;
      savefd = setb(-1);
      savebot = stakbot;
      prcmd(t);
      setb(savefd);
      allocjob(savebot, cwdget(), monitor);
     } else
      allocjob("", "", 0);
    }
    if (treeflgs & (0x0200|0x0400)) {
     link_iodocs(iotemp);
     linked = 1;
    }
    while ((parent = fork()) == -1)
    {
    if ((forkcnt = (forkcnt * 2)) > 32)
    {
     switch ((*__errno_location ()))
     {
     case 12:
      deallocjob();
      error(noswap);
      break;
     default:
      deallocjob();
      error(nofork);
      break;
     }
    } else if ((*__errno_location ()) == 1) {
     deallocjob();
     error(eacces);
     break;
    }
    if (trapnote & 4) exitsh(exitval ? exitval : 2000);
    sh_sleep(forkcnt);
    }
    if (parent) {
     if (monitor)
      setpgid(parent, 0);
     if (treeflgs & 0x0100)
      (close(pf1[0]), close(pf1[1]));
     if (!(treeflgs&0x0200)) {
      postjob(parent,!(treeflgs&0x0400));
      freejobs();
     }
     chktrap();
     break;
    }
    mypid = getpid();
   }
   flags |= (0100|020000000);
   fiotemp = 0;
   if (linked == 1) {
    swap_iodoc_nm(iotemp);
    xflags |= 02;
   } else if (!(xflags & 02))
    iotemp = 0;
   suspacct();
   settmp();
   oldsigs();
   if (!(treeflgs & 0x0200))
    makejob(monitor, !(treeflgs & 0x0400));
   if (treeflgs & 0x0100)
   {
    renamef(pf1[0], 0);
    close(pf1[1]);
   }
   if (treeflgs & 0x0200)
   {
    close(pf2[0]);
    renamef(pf2[1], 1);
   }
   initio(t->treio, 0);
   if (type == 0x00A0)
    execute(((struct forknod *)t)->forktre, xflags | 01, errorflg, ((void *)0), ((void *)0));
   else if (com[0] != 0)
   {
    eflag = 0;
    setlist(((struct comnod *)t)->comset, 0004);
    rmtemp(0);
    clearjobs();
    execa(com, pos);
   }
   done(0);
  }
  case 0x0010:
   if ((xflags & 010) == 0)
    flags &= ~020000000;
   clearjobs();
   execute(((struct parnod *)t)->partre, xflags, errorflg, ((void *)0), ((void *)0));
   done(0);
  case 0x0020:
   {
    int pv[2];
    chkpipe(pv);
    if (execute(((struct lstnod *)t)->lstlef, xflags & 04 | 010, errorflg, pf1, pv) == 0)
     execute(((struct lstnod *)t)->lstrit, xflags, errorflg, pv, pf2);
    else
     (close(pv[0]), close(pv[1]));
   }
   break;
  case 0x0030:
   execute(((struct lstnod *)t)->lstlef, xflags&(04|010), errorflg, ((void *)0), ((void *)0));
   execute(((struct lstnod *)t)->lstrit, xflags, (errorflg | (eflag & 020)), ((void *)0), ((void *)0));
   break;
  case 0x0080:
  case 0x0090:
  {
   register int xval;
   xval = execute(((struct lstnod *)t)->lstlef, 04, 0, ((void *)0), ((void *)0));
   if ((xval == 0) == (type == 0x0080))
    execute(((struct lstnod *)t)->lstrit, xflags|04, errorflg, ((void *)0), ((void *)0));
   break;
  }
  case 0x00B0:
   {
    struct namnod *n = lookup(((struct fornod *)t)->fornam);
    unsigned char **args;
    struct dolnod *argsav = 0;
    if (((struct fornod *)t)->forlst == 0)
    {
     args = dolv + 1;
     argsav = useargs();
    }
    else
    {
     struct argnod *schain = gchain;
     gchain = 0;
     args = scan(getarg(((struct fornod *)t)->forlst));
     gchain = schain;
    }
    loopcnt++;
    while (*args != 0 && execbrk == 0)
    {
     assign(n, *args++);
     execute(((struct fornod *)t)->fortre, 04, errorflg, ((void *)0), ((void *)0));
     if (breakcnt < 0)
      execbrk = (++breakcnt != 0);
    }
    if (breakcnt > 0)
      execbrk = (--breakcnt != 0);
    loopcnt--;
    if(argsav)
     argfor = (struct dolnod *)freeargs(argsav);
   }
   break;
  case 0x0050:
  case 0x0060:
   {
    int i = 0;
    loopcnt++;
    while (execbrk == 0 && (execute(((struct whnod *)t)->whtre,
        04, 0, ((void *)0), ((void *)0)) == 0) == (type == 0x0050) &&
        (flags&01) == 0)
{
     i = execute(((struct whnod *)t)->dotre, 04, errorflg, ((void *)0), ((void *)0));
     if (breakcnt < 0)
      execbrk = (++breakcnt != 0);
    }
    if (breakcnt > 0)
      execbrk = (--breakcnt != 0);
    loopcnt--;
    exitval = i;
   }
   break;
  case 0x0040:
   if (execute(((struct ifnod *)t)->iftre, 04, 0, ((void *)0), ((void *)0)) == 0)
    execute(((struct ifnod *)t)->thtre, xflags|04, errorflg, ((void *)0), ((void *)0));
   else if (((struct ifnod *)t)->eltre)
    execute(((struct ifnod *)t)->eltre, xflags|04, errorflg, ((void *)0), ((void *)0));
   else
    exitval = 0;
   break;
  case 0x0070:
   {
    register unsigned char *r = mactrim(((struct swnod *)t)->swarg);
    register struct regnod *regp;
    regp = ((struct swnod *)t)->swlst;
    while (regp)
    {
     struct argnod *rex = regp->regptr;
     while (rex)
     {
      register unsigned char *s;
      if (gmatch(r, s = macro(rex->argval)) || (trim(s), (cf(r, s) == 0)))
      {
       execute(regp->regcom, 04, errorflg, ((void *)0), ((void *)0));
       regp = 0;
       break;
      }
      else
       rex = rex->argnxt;
     }
     if (regp)
      regp = regp->regnxt;
    }
   }
   break;
  }
  retval = exitval;
 }
 if (trapnote & 4) exitsh(exitval ? exitval : 2000);
 tdystak(sav);
 flags |= eflag;
 return(exitval);
}

variable_types: xflags int

variable_types: errorflg int

variable_types:
sav
unsigned char *

variable_types: treeflgs int

variable_types: type int

variable_types: pos short

variable_types: struct fndnod { int fndtyp; unsigned char *fndnam; struct trenod { int tretyp; struct ionod { int iofile; char *ioname; char *iolink; struct ionod *ionxt; struct ionod *iolst; } *treio; } *fndval; } *

variable_types: cmdhash short

variable_types: comtype short

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

variable_types: index short

variable_types:
olddolv
unsigned char **

variable_types: olddolc int

variable_types: monitor int

variable_types: linked int

variable_types: forkcnt int

variable_types: savefd int

variable_types:
savebot
unsigned char *

variable_types:
pv
int [2]

variable_types: xval int

variable_types:
args
unsigned char **

variable_types: i int

variable_types:
r
unsigned char *

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

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

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

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

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

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

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

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

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

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

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

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

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


execexp

decompiled_code:
__int64 __fastcall execexp(__int64 a1, __int64 a2)
{
char v2; // r12
int *v3; // rdi
_QWORD v5[27]; // [rsp+0h] [rbp-D8h] BYREF

push(v5);
if ( a1 )
{
estabf(a1);
v5[6] = a2;
}
else if ( a2 >= 0 )
{
initf((unsigned int)a2);
}
v2 = flags;
v3 = (int *)cmd(10LL, 3LL);
execute(v3, 0LL, v2 & 0x10, 0LL, 0LL);
return pop();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
char v2; // r12
int *v3; // rdi
_QWORD v5[27]; // [rsp+0h] [rbp-D8h] BYREF

push(v5);
if ( a1 )
{
estabf(a1);
v5[6] = a2;
}
else if ( a2 >= 0 )
{
initf((unsigned int)a2);
}
v2 = flags;
v3 = (int *)cmd(10LL, 3LL);
func1(v3, 0LL, v2 & 0x10, 0LL, 0LL);
return pop();
}

original_code:
void
execexp(unsigned char *s, intptr_t f)
{
 struct fileblk fb;
 push(&fb);
 if (s)
 {
  estabf(s);
  fb.feval = (unsigned char **)(f);
 }
 else if (f >= 0)
  initf(f);
 execute(cmd('\n', 1 | 2), 0, (int)(flags & 020), ((void *)0), ((void *)0));
 pop();
}

canonical_original_code:
void execexp(unsigned char *s, long f)
{
 struct fileblk fb;
 push(&fb);
 if (s)
 {
  estabf(s);
  fb.feval = (unsigned char **)(f);
 }
 else if (f >= 0)
  initf(f);
 execute(cmd('\n', 1 | 2), 0, (int)(flags & 020), ((void *)0), ((void *)0));
 pop();
}

variable_types:
s
unsigned char *

variable_types: f long

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


addg

decompiled_code:
__int64 __fastcall addg(char *a1, const char *a2, __int64 a3, __int64 a4)
{
char *v7; // rbp
_BYTE *v8; // rbx
char i; // r14
int v10; // eax
size_t v11; // rbx
wchar_t v12; // eax
const char *v13; // rsi
char v14; // al
char *v15; // r13
char v16; // al
_QWORD *v17; // rax
wchar_t pwc[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v7 = (char *)(locstak() + 8);
if ( a4 )
{
v8 = a1 + 1;
for ( i = *a1; i; i = *(v8 - 1) )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
++v8;
*v7++ = i;
}
if ( v8 == (_BYTE *)(a4 + 1) )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
*v7++ = 47;
}
}
while ( 1 )
{
v10 = *(unsigned __int8 *)a2;
if ( mb_cur_max > 1 && (v10 & 0x80u) != 0 )
{
v11 = mbtowc(pwc, a2, mb_cur_max);
}
else
{
pwc[0] = *(unsigned __int8 *)a2;
v11 = v10 != 0;
}
if ( (int)v11 <= 0 )
{
v11 = 1LL;
pwc[0] = *(unsigned __int8 *)a2;
}
if ( brkend <= (unsigned __int64)v7 )
break;
v12 = pwc[0];
if ( !pwc[0] )
goto LABEL_22;
LABEL_17:
if ( v12 == 92 )
{
*v7 = 92;
if ( brkend <= (unsigned __int64)(v7 + 1) )
growstak(v7 + 1);
v7[1] = 92;
++a2;
v7 += 2;
}
else
{
if ( (unsigned __int64)&v7[v11] >= brkend )
growstak(&v7[v11]);
v13 = a2;
a2 += v11;
memcpy(v7, v13, v11);
v7 += v11;
}
}
growstak(v7);
v12 = pwc[0];
if ( pwc[0] )
goto LABEL_17;
LABEL_22:
v14 = *a2;
v15 = v7;
*v7 = v14;
if ( a3 )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
*v7 = 47;
v15 = v7 + 1;
do
{
if ( brkend <= (unsigned __int64)v15 )
growstak(v15);
v16 = *(_BYTE *)++a3;
*v15++ = v16;
}
while ( v16 );
}
v17 = (_QWORD *)endstak(v15);
return makearg(v17);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, const char *a2, __int64 a3, __int64 a4)
{
char *v7; // rbp
_BYTE *v8; // rbx
char i; // r14
int v10; // eax
size_t v11; // rbx
wchar_t v12; // eax
const char *v13; // rsi
char v14; // al
char *v15; // r13
char v16; // al
_QWORD *v17; // rax
wchar_t pwc[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v7 = (char *)(locstak() + 8);
if ( a4 )
{
v8 = a1 + 1;
for ( i = *a1; i; i = *(v8 - 1) )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
++v8;
*v7++ = i;
}
if ( v8 == (_BYTE *)(a4 + 1) )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
*v7++ = 47;
}
}
while ( 1 )
{
v10 = *(unsigned __int8 *)a2;
if ( mb_cur_max > 1 && (v10 & 0x80u) != 0 )
{
v11 = mbtowc(pwc, a2, mb_cur_max);
}
else
{
pwc[0] = *(unsigned __int8 *)a2;
v11 = v10 != 0;
}
if ( (int)v11 <= 0 )
{
v11 = 1LL;
pwc[0] = *(unsigned __int8 *)a2;
}
if ( brkend <= (unsigned __int64)v7 )
break;
v12 = pwc[0];
if ( !pwc[0] )
goto LABEL_22;
LABEL_17:
if ( v12 == 92 )
{
*v7 = 92;
if ( brkend <= (unsigned __int64)(v7 + 1) )
growstak(v7 + 1);
v7[1] = 92;
++a2;
v7 += 2;
}
else
{
if ( (unsigned __int64)&v7[v11] >= brkend )
growstak(&v7[v11]);
v13 = a2;
a2 += v11;
memcpy(v7, v13, v11);
v7 += v11;
}
}
growstak(v7);
v12 = pwc[0];
if ( pwc[0] )
goto LABEL_17;
LABEL_22:
v14 = *a2;
v15 = v7;
*v7 = v14;
if ( a3 )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
*v7 = 47;
v15 = v7 + 1;
do
{
if ( brkend <= (unsigned __int64)v15 )
growstak(v15);
v16 = *(_BYTE *)++a3;
*v15++ = v16;
}
while ( v16 );
}
v17 = (_QWORD *)endstak(v15);
return func0(v17);
}

original_code:
static void
addg(unsigned char *as1, unsigned char *as2,
  unsigned char *as3, unsigned char *as4)
{
 register unsigned char *s1, *s2;
 register int c;
 int len;
 wchar_t wc;
 s2 = locstak() + (sizeof (char *));
 s1 = as1;
 if (as4) {
  while (c = *s1++)
  {
   if (s2 >= brkend)
    growstak(s2);
   *s2++ = c;
  }
  if (as4 + 1 == s1) {
   if (s2 >= brkend)
    growstak(s2);
   *s2++ = '/';
  }
 }
 s1 = as2;
 for (;;)
 {
  if ((len = (mb_cur_max > 1 && *((char *)s1) & 0200 ? mbtowc(&wc, (char *)s1, mb_cur_max) : (*(&wc) = *((char *)s1) & 0377, *(&wc) != 0))) <= 0) {
   len = 1;
   wc = (unsigned char)*s1;
  }
  if (s2 >= brkend)
   growstak(s2);
  if (wc == 0) {
   *s2 = *s1++;
   break;
  }
  if (wc == '\\') {
   *s2++ = '\\';
   if (s2 >= brkend)
    growstak(s2);
   *s2++ = '\\';
   s1++;
   continue;
  }
  if ((s2 + len) >= brkend)
   growstak(s2 + len);
  memcpy(s2, s1, len);
  s2 += len;
  s1 += len;
 }
 if (s1 = as3)
 {
  if (s2 >= brkend)
   growstak(s2);
  *s2++ = '/';
  do
  {
   if (s2 >= brkend)
    growstak(s2);
  }
  while (*s2++ = *++s1);
 }
 makearg((struct argnod *)endstak(s2));
}

canonical_original_code:
static void addg(unsigned char *as1, unsigned char *as2, unsigned char *as3, unsigned char *as4)
{
 register unsigned char *s1; register unsigned char *s2;
 register int c;
 int len;
 int wc;
 s2 = locstak() + (sizeof (char *));
 s1 = as1;
 if (as4) {
  while (c = *s1++)
  {
   if (s2 >= brkend)
    growstak(s2);
   *s2++ = c;
  }
  if (as4 + 1 == s1) {
   if (s2 >= brkend)
    growstak(s2);
   *s2++ = '/';
  }
 }
 s1 = as2;
 for (;;)
 {
  if ((len = (mb_cur_max > 1 && *((char *)s1) & 0200 ? mbtowc(&wc, (char *)s1, mb_cur_max) : (*(&wc) = *((char *)s1) & 0377, *(&wc) != 0))) <= 0) {
   len = 1;
   wc = (unsigned char)*s1;
  }
  if (s2 >= brkend)
   growstak(s2);
  if (wc == 0) {
   *s2 = *s1++;
   break;
  }
  if (wc == '\\') {
   *s2++ = '\\';
   if (s2 >= brkend)
    growstak(s2);
   *s2++ = '\\';
   s1++;
   continue;
  }
  if ((s2 + len) >= brkend)
   growstak(s2 + len);
  memcpy(s2, s1, len);
  s2 += len;
  s1 += len;
 }
 if (s1 = as3)
 {
  if (s2 >= brkend)
   growstak(s2);
  *s2++ = '/';
  do
  {
   if (s2 >= brkend)
    growstak(s2);
  }
  while (*s2++ = *++s1);
 }
 makearg((struct argnod *)endstak(s2));
}

variable_types: c int

variable_types: len int

variable_types: wc int

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


setbrk

decompiled_code:
char *__fastcall setbrk(int a1)
{
char *result; // rax

result = (char *)sbrk(a1);
brkend = &result[a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int a1)
{
char *result; // rax

result = (char *)sbrk(a1);
brkend = &result[a1];
return result;
}

original_code:
unsigned char *
setbrk(int incr)
{
 register unsigned char *a = (unsigned char *)sbrk(incr);
 brkend = a + incr;
 return(a);
}

canonical_original_code:
unsigned char *setbrk(int incr)
{
 register unsigned char *a = (unsigned char *)sbrk(incr);
 brkend = a + incr;
 return(a);
}

variable_types: incr int

variable_types:
a
unsigned char *


sysulimit

decompiled_code:
char *__fastcall sysulimit(int argc, char **argv)
{
int v2; // er12
int v4; // er15
int v5; // er14
int v6; // er13
int v7; // eax
char *result; // rax
int v9; // eax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
unsigned __int64 v18; // rdx
char *v19; // rcx
char v20; // al
unsigned __int64 v21; // rsi
unsigned __int8 v22; // al
int v23; // ecx
__rlimit_resource_t *v24; // rbx
int v25; // er14
int v26; // eax
__rlimit_resource_t v27; // edi
__int64 v28; // rax
int i; // edx
int v30; // er15
unsigned __int64 v31; // rax
int *v32; // r13
__rlimit_resource_t v33; // ebp
unsigned __int64 v34; // rdx
__int64 v35; // rax
int j; // edx
char *v37; // [rsp+0h] [rbp-98h]
int v38; // [rsp+Ch] [rbp-8Ch]
unsigned int v39; // [rsp+Ch] [rbp-8Ch]
int v40; // [rsp+10h] [rbp-88h]
rlim64_t v41; // [rsp+10h] [rbp-88h]
int v42; // [rsp+18h] [rbp-80h]
int v43; // [rsp+18h] [rbp-80h]
int v44; // [rsp+1Ch] [rbp-7Ch]
struct rlimit64 rlimits; // [rsp+20h] [rbp-78h] BYREF
__rlimit_resource_t resource[2]; // [rsp+30h] [rbp-68h] BYREF
__int64 v47; // [rsp+38h] [rbp-60h]
__int64 v48; // [rsp+40h] [rbp-58h]
__int64 v49; // [rsp+48h] [rbp-50h]
__int64 v50; // [rsp+50h] [rbp-48h]

v2 = 0;
v4 = optind;
optind = 1;
v5 = opterr;
v6 = getopt_sp;
opterr = 0;
v37 = optarg;
getopt_sp = 1;
v38 = 0;
v42 = 0;
while ( 1 )
{
v7 = getopt(argc, argv, "HSacdflmnstuv");
if ( v7 == -1 )
break;
if ( v2 == 11 )
goto LABEL_8;
switch ( v7 )
{
case 'H':
++v42;
continue;
case 'S':
++v38;
continue;
case 'a':
if ( v2 )
goto LABEL_8;
v2 = 10;
*(_QWORD *)resource = 0x200000004LL;
v47 = 0x800000001LL;
v48 = 0x300000005LL;
v49 = 0x700000000LL;
v50 = 0x900000006LL;
continue;
case 'c':
v17 = v2++;
resource[v17] = RLIMIT_CORE;
continue;
case 'd':
v16 = v2++;
resource[v16] = RLIMIT_DATA;
continue;
case 'f':
v15 = v2++;
resource[v15] = RLIMIT_FSIZE;
continue;
case 'l':
v14 = v2++;
resource[v14] = __RLIMIT_MEMLOCK;
continue;
case 'm':
v13 = v2++;
resource[v13] = __RLIMIT_RSS;
continue;
case 'n':
v12 = v2++;
resource[v12] = RLIMIT_NOFILE;
continue;
case 's':
v11 = v2++;
resource[v11] = RLIMIT_STACK;
continue;
case 't':
v10 = v2++;
resource[v10] = RLIMIT_CPU;
continue;
case 'u':
v9 = v2 + 1;
resource[v2] = RLIMIT_CPU;
goto LABEL_11;
case 'v':
v9 = v2;
LABEL_11:
v2 = v9 + 1;
resource[v9] = RLIMIT_AS;
break;
default:
goto LABEL_8;
}
}
if ( v2 )
{
if ( argc != optind )
{
if ( v2 != 1 )
goto LABEL_8;
goto LABEL_7;
}
goto LABEL_36;
}
resource[0] = RLIMIT_FSIZE;
if ( argc == optind )
{
v2 = 1;
LABEL_36:
v23 = v42;
v43 = v4;
v24 = resource;
v44 = v6;
v40 = v5;
v25 = v23;
v26 = 1;
if ( v38 | v23 )
v26 = v38;
v39 = v26;
while ( 1 )
{
v27 = *v24;
v28 = 0LL;
for ( i = 4; ; i = rlimtab[8 * v28] )
{
v30 = v28;
if ( v27 == i )
break;
if ( ++v28 == 11 )
goto LABEL_43;
}
if ( getrlimit64(v27, &rlimits) < 0 )
goto LABEL_43;
if ( v2 != 1 )
{
v31 = 32LL * v30;
v32 = &rlimtab[v31 / 4];
prs_buff(off_748[v31 / 8]);
prc_buff(40LL);
prs_buff(*((_QWORD *)v32 + 2));
prc_buff(41LL);
prc_buff(32LL);
}
if ( v39 )
break;
if ( v25 )
goto LABEL_53;
LABEL_55:
prc_buff(10LL);
LABEL_43:
if ( &resource[v2 - 1 + 1] == ++v24 )
{
v4 = v43;
v5 = v40;
v6 = v44;
goto LABEL_9;
}
}
if ( rlimits.rlim_cur == -1LL )
prs_buff("unlimited");
else
prull_buff(rlimits.rlim_cur / qword_758[4 * v30], v39, rlimits.rlim_cur % qword_758[4 * v30]);
if ( !v25 )
goto LABEL_55;
prc_buff(58LL);
LABEL_53:
if ( rlimits.rlim_max == -1LL )
prs_buff("unlimited");
else
prull_buff(rlimits.rlim_max / qword_758[4 * v30], v39, rlimits.rlim_max % qword_758[4 * v30]);
goto LABEL_55;
}
LABEL_7:
if ( optind + 1 == argc )
{
if ( (unsigned int)nullsub_1(argv[optind], "unlimited") )
{
v18 = 0LL;
v19 = argv[optind];
v20 = *v19;
while ( 1 )
{
v22 = v20 - 48;
if ( v22 > 9u )
goto LABEL_8;
v21 = (char)v22 + 10 * v18;
if ( v18 > v21 )
goto LABEL_8;
v20 = *++v19;
if ( !v20 )
{
v33 = resource[0];
v35 = 0LL;
for ( j = 4; j != resource[0]; j = rlimtab[8 * v35] )
{
if ( ++v35 == 11 )
goto LABEL_8;
}
v34 = v21 * qword_758[4 * (int)v35];
if ( v21 <= v34 )
goto LABEL_61;
goto LABEL_8;
}
v18 = v21;
}
}
v33 = resource[0];
v34 = -1LL;
LABEL_61:
v41 = v34;
if ( getrlimit64(v33, &rlimits) >= 0 )
{
if ( v38 | v42 )
{
if ( v42 )
rlimits.rlim_max = v41;
if ( !v38 )
{
LABEL_65:
if ( setrlimit64(v33, &rlimits) >= 0 )
goto LABEL_9;
goto LABEL_8;
}
}
else
{
rlimits.rlim_max = v41;
}
rlimits.rlim_cur = v41;
goto LABEL_65;
}
}
LABEL_8:
failure(*argv, &badulimit);
LABEL_9:
result = v37;
optind = v4;
opterr = v5;
getopt_sp = v6;
optarg = v37;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(int argc, char **argv)
{
int v2; // er12
int v4; // er15
int v5; // er14
int v6; // er13
int v7; // eax
char *result; // rax
int v9; // eax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
unsigned __int64 v18; // rdx
char *v19; // rcx
char v20; // al
unsigned __int64 v21; // rsi
unsigned __int8 v22; // al
int v23; // ecx
__rlimit_resource_t *v24; // rbx
int v25; // er14
int v26; // eax
__rlimit_resource_t v27; // edi
__int64 v28; // rax
int i; // edx
int v30; // er15
unsigned __int64 v31; // rax
int *v32; // r13
__rlimit_resource_t v33; // ebp
unsigned __int64 v34; // rdx
__int64 v35; // rax
int j; // edx
char *v37; // [rsp+0h] [rbp-98h]
int v38; // [rsp+Ch] [rbp-8Ch]
unsigned int v39; // [rsp+Ch] [rbp-8Ch]
int v40; // [rsp+10h] [rbp-88h]
rlim64_t v41; // [rsp+10h] [rbp-88h]
int v42; // [rsp+18h] [rbp-80h]
int v43; // [rsp+18h] [rbp-80h]
int v44; // [rsp+1Ch] [rbp-7Ch]
struct rlimit64 rlimits; // [rsp+20h] [rbp-78h] BYREF
__rlimit_resource_t resource[2]; // [rsp+30h] [rbp-68h] BYREF
__int64 v47; // [rsp+38h] [rbp-60h]
__int64 v48; // [rsp+40h] [rbp-58h]
__int64 v49; // [rsp+48h] [rbp-50h]
__int64 v50; // [rsp+50h] [rbp-48h]

v2 = 0;
v4 = optind;
optind = 1;
v5 = opterr;
v6 = getopt_sp;
opterr = 0;
v37 = optarg;
getopt_sp = 1;
v38 = 0;
v42 = 0;
while ( 1 )
{
v7 = getopt(argc, argv, "HSacdflmnstuv");
if ( v7 == -1 )
break;
if ( v2 == 11 )
goto LABEL_8;
switch ( v7 )
{
case 'H':
++v42;
continue;
case 'S':
++v38;
continue;
case 'a':
if ( v2 )
goto LABEL_8;
v2 = 10;
*(_QWORD *)resource = 0x200000004LL;
v47 = 0x800000001LL;
v48 = 0x300000005LL;
v49 = 0x700000000LL;
v50 = 0x900000006LL;
continue;
case 'c':
v17 = v2++;
resource[v17] = RLIMIT_CORE;
continue;
case 'd':
v16 = v2++;
resource[v16] = RLIMIT_DATA;
continue;
case 'f':
v15 = v2++;
resource[v15] = RLIMIT_FSIZE;
continue;
case 'l':
v14 = v2++;
resource[v14] = __RLIMIT_MEMLOCK;
continue;
case 'm':
v13 = v2++;
resource[v13] = __RLIMIT_RSS;
continue;
case 'n':
v12 = v2++;
resource[v12] = RLIMIT_NOFILE;
continue;
case 's':
v11 = v2++;
resource[v11] = RLIMIT_STACK;
continue;
case 't':
v10 = v2++;
resource[v10] = RLIMIT_CPU;
continue;
case 'u':
v9 = v2 + 1;
resource[v2] = RLIMIT_CPU;
goto LABEL_11;
case 'v':
v9 = v2;
LABEL_11:
v2 = v9 + 1;
resource[v9] = RLIMIT_AS;
break;
default:
goto LABEL_8;
}
}
if ( v2 )
{
if ( argc != optind )
{
if ( v2 != 1 )
goto LABEL_8;
goto LABEL_7;
}
goto LABEL_36;
}
resource[0] = RLIMIT_FSIZE;
if ( argc == optind )
{
v2 = 1;
LABEL_36:
v23 = v42;
v43 = v4;
v24 = resource;
v44 = v6;
v40 = v5;
v25 = v23;
v26 = 1;
if ( v38 | v23 )
v26 = v38;
v39 = v26;
while ( 1 )
{
v27 = *v24;
v28 = 0LL;
for ( i = 4; ; i = rlimtab[8 * v28] )
{
v30 = v28;
if ( v27 == i )
break;
if ( ++v28 == 11 )
goto LABEL_43;
}
if ( getrlimit64(v27, &rlimits) < 0 )
goto LABEL_43;
if ( v2 != 1 )
{
v31 = 32LL * v30;
v32 = &rlimtab[v31 / 4];
prs_buff(off_748[v31 / 8]);
prc_buff(40LL);
prs_buff(*((_QWORD *)v32 + 2));
prc_buff(41LL);
prc_buff(32LL);
}
if ( v39 )
break;
if ( v25 )
goto LABEL_53;
LABEL_55:
prc_buff(10LL);
LABEL_43:
if ( &resource[v2 - 1 + 1] == ++v24 )
{
v4 = v43;
v5 = v40;
v6 = v44;
goto LABEL_9;
}
}
if ( rlimits.rlim_cur == -1LL )
prs_buff("unlimited");
else
prull_buff(rlimits.rlim_cur / qword_758[4 * v30], v39, rlimits.rlim_cur % qword_758[4 * v30]);
if ( !v25 )
goto LABEL_55;
prc_buff(58LL);
LABEL_53:
if ( rlimits.rlim_max == -1LL )
prs_buff("unlimited");
else
prull_buff(rlimits.rlim_max / qword_758[4 * v30], v39, rlimits.rlim_max % qword_758[4 * v30]);
goto LABEL_55;
}
LABEL_7:
if ( optind + 1 == argc )
{
if ( (unsigned int)nullsub_1(argv[optind], "unlimited") )
{
v18 = 0LL;
v19 = argv[optind];
v20 = *v19;
while ( 1 )
{
v22 = v20 - 48;
if ( v22 > 9u )
goto LABEL_8;
v21 = (char)v22 + 10 * v18;
if ( v18 > v21 )
goto LABEL_8;
v20 = *++v19;
if ( !v20 )
{
v33 = resource[0];
v35 = 0LL;
for ( j = 4; j != resource[0]; j = rlimtab[8 * v35] )
{
if ( ++v35 == 11 )
goto LABEL_8;
}
v34 = v21 * qword_758[4 * (int)v35];
if ( v21 <= v34 )
goto LABEL_61;
goto LABEL_8;
}
v18 = v21;
}
}
v33 = resource[0];
v34 = -1LL;
LABEL_61:
v41 = v34;
if ( getrlimit64(v33, &rlimits) >= 0 )
{
if ( v38 | v42 )
{
if ( v42 )
rlimits.rlim_max = v41;
if ( !v38 )
{
LABEL_65:
if ( setrlimit64(v33, &rlimits) >= 0 )
goto LABEL_9;
goto LABEL_8;
}
}
else
{
rlimits.rlim_max = v41;
}
rlimits.rlim_cur = v41;
goto LABEL_65;
}
}
LABEL_8:
failure(*argv, &badulimit);
LABEL_9:
result = v37;
optind = v4;
opterr = v5;
getopt_sp = v6;
optarg = v37;
return result;
}

original_code:
void
sysulimit(int argc, char **argv)
{
 int savopterr, savoptind, savsp;
 char *savoptarg;
 char *args;
 int hard, soft, c, i, res;
 rlim_t limit, new_limit;
 struct rlimit rlimit;
 int resources[sizeof rlimtab / sizeof *rlimtab];
 const struct rlimtab *rp = ((void *)0);
 savoptind = optind;
 savopterr = opterr;
 savsp = getopt_sp;
 savoptarg = optarg;
 optind = 1;
 getopt_sp = 1;
 opterr = 0;
 hard = 0;
 soft = 0;
 res = 0;
 while ((c = getopt(argc, argv, "HSacdflmnstuv")) != -1) {
  if (res == sizeof resources / sizeof *resources)
   goto fail;
  switch (c) {
  case 'S':
   soft++;
   continue;
  case 'H':
   hard++;
   continue;
  case 'a':
   if (res)
    goto fail;
   resources[res++] = RLIMIT_CORE;
   resources[res++] = RLIMIT_DATA;
   resources[res++] = RLIMIT_FSIZE;
   resources[res++] = __RLIMIT_MEMLOCK;
   resources[res++] = __RLIMIT_RSS;
   resources[res++] = RLIMIT_STACK;
   resources[res++] = RLIMIT_CPU;
   resources[res++] = RLIMIT_NOFILE;
   resources[res++] = __RLIMIT_NPROC;
   resources[res++] = RLIMIT_AS;
   continue;
  case 'c':
   resources[res++] = RLIMIT_CORE;
   break;
  case 'd':
   resources[res++] = RLIMIT_DATA;
   break;
  case 'f':
   resources[res++] = RLIMIT_FSIZE;
   break;
  case 'l':
   resources[res++] = __RLIMIT_MEMLOCK;
   break;
  case 'm':
   resources[res++] = __RLIMIT_RSS;
   break;
  case 'n':
   resources[res++] = RLIMIT_NOFILE;
   break;
  case 's':
   resources[res++] = RLIMIT_STACK;
   break;
  case 't':
   resources[res++] = RLIMIT_CPU;
   break;
  case 'u':
   resources[res++] = RLIMIT_CPU;
  case 'v':
   resources[res++] = RLIMIT_AS;
   break;
  default:
  case '?':
   goto fail;
  }
 }
 if (res == 0)
  resources[res++] = RLIMIT_FSIZE;
 if (optind == argc) {
  if (!hard && !soft)
   soft++;
  for (c = 0; c < res; c++) {
   rp = ((void *)0);
   for (i = 0; i < sizeof resources / sizeof *resources;
     i++)
    if (rlimtab[i].resource == resources[c]) {
     rp = &rlimtab[i];
     break;
    }
   if (rp == ((void *)0))
    continue;
   if (getrlimit(rp->resource, &rlimit) < 0) {
    continue;
   }
   if (res > 1) {
    prs_buff(rp->name);
    prc_buff('(');
    prs_buff(rp->scale);
    prc_buff(')');
    prc_buff(' ');
   }
   if (soft) {
    if (rlimit.rlim_cur == 0xffffffffffffffffuLL) {
     prs_buff("unlimited");
    } else {
     prull_buff(rlimit.rlim_cur /
         rp->divisor);
    }
   }
   if (hard && soft) {
    prc_buff(':');
   }
   if (hard) {
    if (rlimit.rlim_max == 0xffffffffffffffffuLL) {
     prs_buff("unlimited");
    } else {
     prull_buff(rlimit.rlim_max /
         rp->divisor);
    }
   }
   prc_buff('\n');
  }
  goto err;
 }
 if (res > 1 || optind + 1 != argc)
  goto fail;
 if ((cf(argv[optind], "unlimited") == 0)) {
  limit = 0xffffffffffffffffuLL;
 } else {
  args = argv[optind];
  new_limit = limit = 0;
  do {
   if (*args < '0' || *args > '9')
    goto fail;
   new_limit = (limit * 10) + (*args - '0');
   if (new_limit >= limit) {
    limit = new_limit;
   } else
    goto fail;
  } while (*++args);
  rp = ((void *)0);
  for (i = 0; i < sizeof resources / sizeof *resources; i++)
   if (rlimtab[i].resource == resources[0]) {
    rp = &rlimtab[i];
    break;
   }
  if (rp == ((void *)0))
   goto fail;
  new_limit = limit * rp->divisor;
  if (new_limit >= limit) {
   limit = new_limit;
  } else
   goto fail;
 }
 if (getrlimit(resources[0], &rlimit) < 0)
  goto fail;
 if (!hard && !soft) {
  hard++;
  soft++;
 }
 if (hard) {
  rlimit.rlim_max = limit;
 }
 if (soft) {
  rlimit.rlim_cur = limit;
 }
 if (setrlimit(resources[0], &rlimit) < 0) {
 fail: failure(argv[0], badulimit);
 }
err:
 optind = savoptind;
 opterr = savopterr;
 getopt_sp = savsp;
 optarg = savoptarg;
}

canonical_original_code:
void sysulimit(int argc, char **argv)
{
 int savopterr; int savoptind; int savsp;
 char *savoptarg;
 char *args;
 int hard; int soft; int c; int i; int res;
 unsigned long limit; unsigned long new_limit;
 struct rlimit rlimit;
 int resources[-1];
 struct rlimtab *rp = ((void *)0);
 savoptind = optind;
 savopterr = opterr;
 savsp = getopt_sp;
 savoptarg = optarg;
 optind = 1;
 getopt_sp = 1;
 opterr = 0;
 hard = 0;
 soft = 0;
 res = 0;
 while ((c = getopt(argc, argv, "HSacdflmnstuv")) != -1) {
  if (res == sizeof resources / sizeof *resources)
   goto fail;
  switch (c) {
  case 'S':
   soft++;
   continue;
  case 'H':
   hard++;
   continue;
  case 'a':
   if (res)
    goto fail;
   resources[res++] = RLIMIT_CORE;
   resources[res++] = RLIMIT_DATA;
   resources[res++] = RLIMIT_FSIZE;
   resources[res++] = __RLIMIT_MEMLOCK;
   resources[res++] = __RLIMIT_RSS;
   resources[res++] = RLIMIT_STACK;
   resources[res++] = RLIMIT_CPU;
   resources[res++] = RLIMIT_NOFILE;
   resources[res++] = __RLIMIT_NPROC;
   resources[res++] = RLIMIT_AS;
   continue;
  case 'c':
   resources[res++] = RLIMIT_CORE;
   break;
  case 'd':
   resources[res++] = RLIMIT_DATA;
   break;
  case 'f':
   resources[res++] = RLIMIT_FSIZE;
   break;
  case 'l':
   resources[res++] = __RLIMIT_MEMLOCK;
   break;
  case 'm':
   resources[res++] = __RLIMIT_RSS;
   break;
  case 'n':
   resources[res++] = RLIMIT_NOFILE;
   break;
  case 's':
   resources[res++] = RLIMIT_STACK;
   break;
  case 't':
   resources[res++] = RLIMIT_CPU;
   break;
  case 'u':
   resources[res++] = RLIMIT_CPU;
  case 'v':
   resources[res++] = RLIMIT_AS;
   break;
  default:
  case '?':
   goto fail;
  }
 }
 if (res == 0)
  resources[res++] = RLIMIT_FSIZE;
 if (optind == argc) {
  if (!hard && !soft)
   soft++;
  for (c = 0; c < res; c++) {
   rp = ((void *)0);
   for (i = 0; i < sizeof resources / sizeof *resources;
     i++)
    if (rlimtab[i].resource == resources[c]) {
     rp = &rlimtab[i];
     break;
    }
   if (rp == ((void *)0))
    continue;
   if (getrlimit(rp->resource, &rlimit) < 0) {
    continue;
   }
   if (res > 1) {
    prs_buff(rp->name);
    prc_buff('(');
    prs_buff(rp->scale);
    prc_buff(')');
    prc_buff(' ');
   }
   if (soft) {
    if (rlimit.rlim_cur == 0xffffffffffffffffuLL) {
     prs_buff("unlimited");
    } else {
     prull_buff(rlimit.rlim_cur /
         rp->divisor);
    }
   }
   if (hard && soft) {
    prc_buff(':');
   }
   if (hard) {
    if (rlimit.rlim_max == 0xffffffffffffffffuLL) {
     prs_buff("unlimited");
    } else {
     prull_buff(rlimit.rlim_max /
         rp->divisor);
    }
   }
   prc_buff('\n');
  }
  goto err;
 }
 if (res > 1 || optind + 1 != argc)
  goto fail;
 if ((cf(argv[optind], "unlimited") == 0)) {
  limit = 0xffffffffffffffffuLL;
 } else {
  args = argv[optind];
  new_limit = limit = 0;
  do {
   if (*args < '0' || *args > '9')
    goto fail;
   new_limit = (limit * 10) + (*args - '0');
   if (new_limit >= limit) {
    limit = new_limit;
   } else
    goto fail;
  } while (*++args);
  rp = ((void *)0);
  for (i = 0; i < sizeof resources / sizeof *resources; i++)
   if (rlimtab[i].resource == resources[0]) {
    rp = &rlimtab[i];
    break;
   }
  if (rp == ((void *)0))
   goto fail;
  new_limit = limit * rp->divisor;
  if (new_limit >= limit) {
   limit = new_limit;
  } else
   goto fail;
 }
 if (getrlimit(resources[0], &rlimit) < 0)
  goto fail;
 if (!hard && !soft) {
  hard++;
  soft++;
 }
 if (hard) {
  rlimit.rlim_max = limit;
 }
 if (soft) {
  rlimit.rlim_cur = limit;
 }
 if (setrlimit(resources[0], &rlimit) < 0) {
 fail: failure(argv[0], badulimit);
 }
err:
 optind = savoptind;
 opterr = savopterr;
 getopt_sp = savsp;
 optarg = savoptarg;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: savopterr int

variable_types: savoptind int

variable_types: savsp int

variable_types:
savoptarg
char *

variable_types:
args
char *

variable_types: hard int

variable_types: soft int

variable_types: res int

variable_types:
limit
unsigned long

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }

variable_types:
resources
int [-1]

variable_types: struct rlimtab { int resource; char *name; char *scale; unsigned long divisor; } *