word

decompiled_code:
__int64 word()
{
int v0; // eax
unsigned int v1; // eax
unsigned int v2; // er12
char v3; // al
char *v4; // rbp
char *v5; // rbx
char *v6; // r12
char j; // r13
char *i; // r14
wchar_t v9; // eax
wchar_t v10; // er12
char *v11; // r13
char *k; // rbx
wchar_t v13; // eax
char *l; // rbx
char *v15; // rbx
char *m; // r13
wchar_t v17; // eax
wchar_t v18; // ebp
unsigned int v19; // eax
wchar_t v20; // eax
char *v21; // r13
unsigned __int8 v22; // al
unsigned int v23; // ebx
int v25; // eax
unsigned int v26; // eax
int v27; // eax
int v28; // [rsp+Ch] [rbp-4Ch]
__int64 v29; // [rsp+10h] [rbp-48h]

v29 = locstak();
wdnum = 0;
wdset = 0;
while ( 1 )
{
do
{
v1 = nextwc();
v2 = v1;
}
while ( v1 <= 0x7F && (*((_BYTE *)&sh_ctype1 + v1) & 4) != 0 );
if ( v1 != 35 )
break;
do
v0 = readwc();
while ( v0 && v0 != 10 );
peekc = v0;
}
if ( v1 <= 0x7F )
{
v3 = *((_BYTE *)&sh_ctype1 + v1);
if ( (v3 & 0x3E) == 0 )
{
v4 = (char *)(v29 + 8);
v28 = 1;
goto LABEL_64;
}
if ( (v3 & 8) != 0 )
{
v25 = nextwc();
if ( v2 == v25 )
{
v26 = v2;
BYTE1(v26) = BYTE1(v2) | 8;
wdval = v26;
if ( v2 == 60 )
{
v27 = nextwc();
if ( v27 == 45 )
wdnum |= 0x200u;
else
peekn = v27 | 0x80000000;
}
}
else
{
peekn = v25 | 0x80000000;
wdval = v2;
}
}
else
{
if ( !v2 )
v2 = 1024;
wdval = v2;
if ( iopend && (v3 & 0x30) != 0 )
{
iopend = 0LL;
copy();
}
}
goto LABEL_96;
}
v4 = (char *)(v29 + 8);
v28 = 1;
do
{
LABEL_64:
if ( v2 == 39 )
{
for ( i = v4; ; i = v5 )
{
v9 = readwc();
v10 = v9;
if ( !v9 || v9 == 39 )
break;
v11 = readw(v9);
if ( brkend <= (unsigned __int64)i )
growstak(i);
v5 = i + 1;
*i = 92;
if ( v10 == 10 )
chkpr();
v6 = v11 + 1;
for ( j = *v11; j; j = *(v6 - 1) )
{
if ( brkend <= (unsigned __int64)v5 )
growstak(v5);
*v5++ = j;
++v6;
}
}
if ( v4 == i )
{
if ( brkend <= (unsigned __int64)i )
growstak(i);
*i = 34;
if ( brkend <= (unsigned __int64)(i + 1) )
growstak(i + 1);
v4 = i + 2;
i[1] = 34;
}
else
{
v4 = i;
}
goto LABEL_62;
}
if ( !v2 )
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
*v4++ = 0;
LABEL_69:
if ( v2 > 0x7F )
{
v28 = 0;
goto LABEL_62;
}
goto LABEL_49;
}
for ( k = readw(v2); *k; *(v4 - 1) = *(k - 1) )
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
++k;
++v4;
}
if ( v2 == 92 )
{
v13 = readwc();
if ( v13 )
{
for ( l = readw(v13); *l; *(v4 - 1) = *(l - 1) )
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
++l;
++v4;
}
}
else
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
*v4++ = 0;
}
}
else
{
if ( v2 != 61 )
goto LABEL_69;
wdset |= v28;
}
LABEL_49:
if ( (*((_BYTE *)&sh_ctype2 + v2) & 0x48) == 0 )
v28 = 0;
if ( (*((_BYTE *)&sh_ctype1 + v2) & 0x40) != 0 )
{
LABEL_52:
v15 = v4;
while ( 1 )
{
v17 = nextwc();
v18 = v17;
if ( !v17 )
break;
for ( m = readw(v17); *m; *(v15 - 1) = *(m - 1) )
{
if ( brkend <= (unsigned __int64)v15 )
growstak(v15);
++m;
++v15;
}
if ( v2 == v18 )
{
v4 = v15;
goto LABEL_62;
}
if ( v18 == 10 )
{
chkpr();
}
else if ( v18 == 92 )
{
v20 = readwc();
if ( v20 )
{
v21 = readw(v20);
if ( *v21 )
{
v4 = v15;
do
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
*v4++ = *v21++;
}
while ( *v21 );
}
else
{
v4 = v15;
}
}
else
{
if ( brkend <= (unsigned __int64)v15 )
growstak(v15);
v4 = v15 + 1;
*v15 = 0;
}
goto LABEL_52;
}
}
if ( brkend <= (unsigned __int64)v15 )
growstak(v15);
v4 = v15 + 1;
*v15 = 0;
}
LABEL_62:
v19 = nextwc();
v2 = v19;
}
while ( v19 > 0x7F || (*((_BYTE *)&sh_ctype1 + v19) & 0x3E) == 0 );
endstak(v4);
v22 = *(_BYTE *)(v29 + 8);
if ( (v22 & 0x80u) != 0 )
{
wdset = 0;
peekn = v2 | 0x80000000;
}
else if ( (*((_BYTE *)&sh_ctype2 + v22) & 0x40) != 0 )
{
peekn = v2 | 0x80000000;
if ( !*(_BYTE *)(v29 + 9) )
{
v23 = v22;
LABEL_89:
if ( (*((_BYTE *)&sh_ctype2 + v23) & 8) != 0 && (v2 & 0xFFFFFFFD) == 60 )
{
word();
wdnum = v23 - 48;
goto LABEL_96;
}
}
}
else
{
wdset = 0;
peekn = v2 | 0x80000000;
if ( !*(_BYTE *)(v29 + 9) )
{
v23 = v22;
goto LABEL_89;
}
}
if ( !reserv || (wdval = syslook(v29 + 8, &reserved, no_reserved)) == 0 )
wdval = 0;
wdarg = v29;
LABEL_96:
reserv = 0;
return wdval;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // eax
unsigned int v1; // eax
unsigned int v2; // er12
char v3; // al
char *v4; // rbp
char *v5; // rbx
char *v6; // r12
char j; // r13
char *i; // r14
wchar_t v9; // eax
wchar_t v10; // er12
char *v11; // r13
char *k; // rbx
wchar_t v13; // eax
char *l; // rbx
char *v15; // rbx
char *m; // r13
wchar_t v17; // eax
wchar_t v18; // ebp
unsigned int v19; // eax
wchar_t v20; // eax
char *v21; // r13
unsigned __int8 v22; // al
unsigned int v23; // ebx
int v25; // eax
unsigned int v26; // eax
int v27; // eax
int v28; // [rsp+Ch] [rbp-4Ch]
__int64 v29; // [rsp+10h] [rbp-48h]

v29 = locstak();
wdnum = 0;
wdset = 0;
while ( 1 )
{
do
{
v1 = func3();
v2 = v1;
}
while ( v1 <= 0x7F && (*((_BYTE *)&sh_ctype1 + v1) & 4) != 0 );
if ( v1 != 35 )
break;
do
v0 = func2();
while ( v0 && v0 != 10 );
peekc = v0;
}
if ( v1 <= 0x7F )
{
v3 = *((_BYTE *)&sh_ctype1 + v1);
if ( (v3 & 0x3E) == 0 )
{
v4 = (char *)(v29 + 8);
v28 = 1;
goto LABEL_64;
}
if ( (v3 & 8) != 0 )
{
v25 = func3();
if ( v2 == v25 )
{
v26 = v2;
BYTE1(v26) = BYTE1(v2) | 8;
wdval = v26;
if ( v2 == 60 )
{
v27 = func3();
if ( v27 == 45 )
wdnum |= 0x200u;
else
peekn = v27 | 0x80000000;
}
}
else
{
peekn = v25 | 0x80000000;
wdval = v2;
}
}
else
{
if ( !v2 )
v2 = 1024;
wdval = v2;
if ( iopend && (v3 & 0x30) != 0 )
{
iopend = 0LL;
copy();
}
}
goto LABEL_96;
}
v4 = (char *)(v29 + 8);
v28 = 1;
do
{
LABEL_64:
if ( v2 == 39 )
{
for ( i = v4; ; i = v5 )
{
v9 = func2();
v10 = v9;
if ( !v9 || v9 == 39 )
break;
v11 = func1(v9);
if ( brkend <= (unsigned __int64)i )
growstak(i);
v5 = i + 1;
*i = 92;
if ( v10 == 10 )
chkpr();
v6 = v11 + 1;
for ( j = *v11; j; j = *(v6 - 1) )
{
if ( brkend <= (unsigned __int64)v5 )
growstak(v5);
*v5++ = j;
++v6;
}
}
if ( v4 == i )
{
if ( brkend <= (unsigned __int64)i )
growstak(i);
*i = 34;
if ( brkend <= (unsigned __int64)(i + 1) )
growstak(i + 1);
v4 = i + 2;
i[1] = 34;
}
else
{
v4 = i;
}
goto LABEL_62;
}
if ( !v2 )
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
*v4++ = 0;
LABEL_69:
if ( v2 > 0x7F )
{
v28 = 0;
goto LABEL_62;
}
goto LABEL_49;
}
for ( k = func1(v2); *k; *(v4 - 1) = *(k - 1) )
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
++k;
++v4;
}
if ( v2 == 92 )
{
v13 = func2();
if ( v13 )
{
for ( l = func1(v13); *l; *(v4 - 1) = *(l - 1) )
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
++l;
++v4;
}
}
else
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
*v4++ = 0;
}
}
else
{
if ( v2 != 61 )
goto LABEL_69;
wdset |= v28;
}
LABEL_49:
if ( (*((_BYTE *)&sh_ctype2 + v2) & 0x48) == 0 )
v28 = 0;
if ( (*((_BYTE *)&sh_ctype1 + v2) & 0x40) != 0 )
{
LABEL_52:
v15 = v4;
while ( 1 )
{
v17 = func3();
v18 = v17;
if ( !v17 )
break;
for ( m = func1(v17); *m; *(v15 - 1) = *(m - 1) )
{
if ( brkend <= (unsigned __int64)v15 )
growstak(v15);
++m;
++v15;
}
if ( v2 == v18 )
{
v4 = v15;
goto LABEL_62;
}
if ( v18 == 10 )
{
chkpr();
}
else if ( v18 == 92 )
{
v20 = func2();
if ( v20 )
{
v21 = func1(v20);
if ( *v21 )
{
v4 = v15;
do
{
if ( brkend <= (unsigned __int64)v4 )
growstak(v4);
*v4++ = *v21++;
}
while ( *v21 );
}
else
{
v4 = v15;
}
}
else
{
if ( brkend <= (unsigned __int64)v15 )
growstak(v15);
v4 = v15 + 1;
*v15 = 0;
}
goto LABEL_52;
}
}
if ( brkend <= (unsigned __int64)v15 )
growstak(v15);
v4 = v15 + 1;
*v15 = 0;
}
LABEL_62:
v19 = func3();
v2 = v19;
}
while ( v19 > 0x7F || (*((_BYTE *)&sh_ctype1 + v19) & 0x3E) == 0 );
endstak(v4);
v22 = *(_BYTE *)(v29 + 8);
if ( (v22 & 0x80u) != 0 )
{
wdset = 0;
peekn = v2 | 0x80000000;
}
else if ( (*((_BYTE *)&sh_ctype2 + v22) & 0x40) != 0 )
{
peekn = v2 | 0x80000000;
if ( !*(_BYTE *)(v29 + 9) )
{
v23 = v22;
LABEL_89:
if ( (*((_BYTE *)&sh_ctype2 + v23) & 8) != 0 && (v2 & 0xFFFFFFFD) == 60 )
{
func5();
wdnum = v23 - 48;
goto LABEL_96;
}
}
}
else
{
wdset = 0;
peekn = v2 | 0x80000000;
if ( !*(_BYTE *)(v29 + 9) )
{
v23 = v22;
goto LABEL_89;
}
}
if ( !reserv || (wdval = syslook(v29 + 8, &reserved, no_reserved)) == 0 )
wdval = 0;
wdarg = v29;
LABEL_96:
reserv = 0;
return wdval;
}

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

repo: mutoso-mirrors/heirloom-sh

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

return_type: void


calloc

decompiled_code:
unsigned __int64 __fastcall calloc(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
unsigned __int64 v3; // rax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbx
__int64 v6; // rdx

v2 = a2 * a1;
v3 = malloc(v2);
v4 = v3;
if ( v3 )
{
v5 = (unsigned __int64)(v2 + 7) >> 3;
if ( (int)v5 > 0 )
{
v6 = v3 + 8LL * (unsigned int)(v5 - 1) + 8;
do
{
v3 += 8LL;
*(_QWORD *)(v3 - 8) = 0LL;
}
while ( v3 != v6 );
}
}
return v4;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
unsigned __int64 v3; // rax
unsigned __int64 v4; // rcx
unsigned __int64 v5; // rbx
__int64 v6; // rdx

v2 = a2 * a1;
v3 = func2(v2);
v4 = v3;
if ( v3 )
{
v5 = (unsigned __int64)(v2 + 7) >> 3;
if ( (int)v5 > 0 )
{
v6 = v3 + 8LL * (unsigned int)(v5 - 1) + 8;
do
{
v3 += 8LL;
*(_QWORD *)(v3 - 8) = 0LL;
}
while ( v3 != v6 );
}
}
return v4;
}

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(int a1)
{
exitval = a1;
flags |= eflag;
if ( (flags & 0x200070) == 32LL )
{
clearup();
restore(0LL);
setb(1LL);
funcnt = 0;
breakcnt = 0;
execbrk = 0;
longjmp(errshell, 1);
}
return done(0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
exitval = a1;
flags |= eflag;
if ( (flags & 0x200070) == 32LL )
{
clearup();
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(1);
}

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

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

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

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

prp();
prs_cntl(a1);
if ( a2 )
{
prs(&colon);
prs(a2);
}
prc(10LL);
if ( (flags & 0x10) != 0 )
func0(1);
result = eflag;
flags |= eflag;
exitval = 1;
retval = 1;
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; } *

return_type: int


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)
{
int v3; // ebx
char *v4; // rsi
int v5; // er12
__int64 v6; // rbp
char **v7; // r13
int v8; // er14
char *v9; // rax
unsigned int v10; // esi
char *v11; // rax

v3 = getopt_sp;
if ( getopt_sp != 1 )
goto LABEL_6;
if ( optind >= a1 )
return (unsigned int)-1;
v4 = a2[optind];
if ( *v4 != 45 )
return (unsigned int)-1;
if ( !v4[1] )
return (unsigned int)-1;
if ( !strcmp(v4, "--") )
{
++optind;
v10 = -1;
}
else
{
LABEL_6:
v5 = optind;
v6 = optind;
v7 = &a2[v6];
v8 = a2[v6][getopt_sp];
optopt = v8;
optarg = 0LL;
v9 = parse(a3, v8);
if ( !v9 )
err("illegal option", v8, a3, *a2);
v10 = *v9;
optopt = v10;
if ( v9[1] == 58 )
{
if ( (*v7)[v3 + 1] )
{
optind = v5 + 1;
optarg = (__int64)&(*v7)[v3 + 1];
}
else
{
optind = v5 + 1;
if ( v5 + 1 >= a1 )
err("option requires an argument", v10, a3, *a2);
optind = v5 + 2;
optarg = (__int64)a2[v6 + 1];
}
getopt_sp = 1;
}
else
{
v11 = *v7;
getopt_sp = v3 + 1;
if ( !v11[v3 + 1] )
{
getopt_sp = 1;
optind = v5 + 1;
}
}
}
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, char **a2, char *a3)
{
int v3; // ebx
char *v4; // rsi
int v5; // er12
__int64 v6; // rbp
char **v7; // r13
int v8; // er14
char *v9; // rax
unsigned int v10; // esi
char *v11; // rax

v3 = getopt_sp;
if ( getopt_sp != 1 )
goto LABEL_6;
if ( optind >= a1 )
return (unsigned int)-1;
v4 = a2[optind];
if ( *v4 != 45 )
return (unsigned int)-1;
if ( !v4[1] )
return (unsigned int)-1;
if ( !strcmp(v4, "--") )
{
++optind;
v10 = -1;
}
else
{
LABEL_6:
v5 = optind;
v6 = optind;
v7 = &a2[v6];
v8 = a2[v6][getopt_sp];
optopt = v8;
optarg = 0LL;
v9 = func0(a3, v8);
if ( !v9 )
func1("illegal option", v8, a3, *a2);
v10 = *v9;
optopt = v10;
if ( v9[1] == 58 )
{
if ( (*v7)[v3 + 1] )
{
optind = v5 + 1;
optarg = (__int64)&(*v7)[v3 + 1];
}
else
{
optind = v5 + 1;
if ( v5 + 1 >= a1 )
func1("option requires an argument", v10, a3, *a2);
optind = v5 + 2;
optarg = (__int64)a2[v6 + 1];
}
getopt_sp = 1;
}
else
{
v11 = *v7;
getopt_sp = v3 + 1;
if ( !v11[v3 + 1] )
{
getopt_sp = 1;
optind = v5 + 1;
}
}
}
return v10;
}

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; // rbx
const void **v2; // rbp
int v3; // eax

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

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

prs(&execpmsg);
v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
do
{
v3 = length(v1);
write(output, v1, v3 - 1);
prc(32LL);
v1 = *v2++;
}
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

decompiled_code:
__int64 __fastcall execute(int *a1, __int64 a2, unsigned int a3, int *a4, __int64 a5)
{
__int64 v7; // rdi
__int16 v8; // r15
int v9; // er13
int v10; // ebx
int v11; // er13
__int64 v12; // rax
__int64 v13; // rbx
__int64 v14; // r13
__int64 v15; // r14
__int64 v16; // r14
const void **v17; // rax
__int16 v18; // ax
__int16 v19; // r14
__int64 v20; // rbx
int v21; // ebp
__int64 v22; // r13
__int64 v23; // r15
__int16 v24; // r14
int i; // er14
__int64 v26; // r14
const char *v27; // rdx
__int64 v28; // rdi
const char *v29; // rdx
const char *v30; // rdx
__int64 v31; // r13
__int64 v32; // r14
unsigned int v33; // eax
_QWORD *v34; // rbx
__int64 v35; // r14
int v36; // eax
int v37; // eax
int v38; // eax
int v39; // eax
__int64 v40; // rdi
__int64 v41; // rdi
_QWORD *v43; // rbp
__int64 v44; // rbx
__int64 v45; // [rsp+8h] [rbp-80h]
unsigned int v46; // [rsp+14h] [rbp-74h]
const void **v49; // [rsp+28h] [rbp-60h]
__int64 v50; // [rsp+30h] [rbp-58h]
int v51; // [rsp+30h] [rbp-58h]
unsigned int v52; // [rsp+38h] [rbp-50h]
unsigned int v53; // [rsp+38h] [rbp-50h]
unsigned int v54; // [rsp+38h] [rbp-50h]
unsigned __int8 v55; // [rsp+3Ch] [rbp-4Ch]
int v56; // [rsp+3Ch] [rbp-4Ch]
int fd[16]; // [rsp+48h] [rbp-40h] BYREF

v46 = a2;
v45 = savstak();
if ( (trapnote & 4) != 0 )
{
v7 = exitval;
if ( !exitval )
v7 = 2000LL;
exitsh(v7);
}
if ( !a3 )
flags &= 0xFFFFFFFFFFFFFFEFLL;
if ( a1 )
{
v8 = execbrk;
if ( !execbrk )
{
v9 = *a1;
v10 = *a1 & 0xF0;
if ( v10 == 96 )
{
LABEL_15:
++loopcnt;
v11 = 0;
do
{
if ( ((unsigned int)execute(*((_QWORD *)a1 + 1), 4LL, 0LL, 0LL, 0LL) != 0) == (v10 == 80) || (flags & 1) != 0 )
break;
v11 = execute(*((_QWORD *)a1 + 2), 4LL, a3, 0LL, 0LL);
v38 = breakcnt;
if ( breakcnt < 0 )
{
++breakcnt;
execbrk = v38 != -1;
}
}
while ( !execbrk );
v39 = breakcnt;
if ( breakcnt > 0 )
{
--breakcnt;
execbrk = v39 != 1;
}
--loopcnt;
exitval = v11;
goto LABEL_143;
}
if ( (*a1 & 0xF0u) > 0x60 )
{
if ( v10 != 160 )
{
if ( (*a1 & 0xF0u) > 0xA0 )
{
if ( v10 == 176 )
{
v31 = lookup(*((_QWORD *)a1 + 2));
if ( *((_QWORD *)a1 + 3) )
{
v32 = gchain;
gchain = 0LL;
v33 = ((__int64 (*)(void))getarg)();
v34 = (_QWORD *)scan(v33);
gchain = v32;
v35 = 0LL;
}
else
{
v34 = (_QWORD *)(dolv + 8LL);
v35 = useargs();
}
++loopcnt;
while ( *v34 )
{
if ( execbrk )
break;
++v34;
assign(v31);
execute(*((_QWORD *)a1 + 1), 4LL, a3, 0LL, 0LL);
v37 = breakcnt;
if ( breakcnt < 0 )
{
++breakcnt;
execbrk = v37 != -1;
}
}
v36 = breakcnt;
if ( breakcnt > 0 )
{
--breakcnt;
execbrk = v36 != 1;
}
--loopcnt;
if ( v35 )
argfor = freeargs(v35);
}
else if ( v10 == 192 )
{
v12 = lookup(*((_QWORD *)a1 + 1));
v13 = v12;
exitval = 0;
if ( (*(_BYTE *)(v12 + 40) & 8) != 0 )
failed(*(_QWORD *)(v12 + 16), &wtfailed);
if ( (*((_BYTE *)&flags + 1) & 1) != 0
&& ((_UNKNOWN *)v13 == &pathnod || !(unsigned int)nullsub_1(*(_QWORD *)(v13 + 16), "SHELL")) )
{
failed(*(_QWORD *)(v13 + 16), &restricted);
}
if ( (*(_BYTE *)(v13 + 40) & 1) != 0 )
{
freefunc(v13);
}
else
{
sh_free(*(_QWORD *)(v13 + 24));
sh_free(*(_QWORD *)(v13 + 32));
*(_QWORD *)(v13 + 24) = 0LL;
*(_DWORD *)(v13 + 40) &= 0xFFFFFFEB;
}
if ( funcnt )
++**((_DWORD **)a1 + 2);
*(_QWORD *)(v13 + 32) = *((_QWORD *)a1 + 2);
*(_DWORD *)(v13 + 40) |= 1u;
hash_func(*(_QWORD *)(v13 + 16));
}
goto LABEL_143;
}
if ( (*a1 & 0xE0) != 128 )
{
if ( v10 == 112 )
{
v14 = mactrim(*((_QWORD *)a1 + 1));
v15 = *((_QWORD *)a1 + 2);
if ( v15 )
{
while ( 1 )
{
v43 = *(_QWORD **)v15;
if ( *(_QWORD *)v15 )
break;
LABEL_149:
v15 = *(_QWORD *)(v15 + 16);
if ( !v15 )
goto LABEL_143;
}
while ( 1 )
{
v44 = macro(v43 + 1);
if ( (unsigned int)gmatch(v14, v44) )
break;
trim(v44);
if ( !(unsigned int)nullsub_1(v14, v44) )
break;
v43 = (_QWORD *)*v43;
if ( !v43 )
goto LABEL_149;
}
execute(*(_QWORD *)(v15 + 8), 4LL, a3, 0LL, 0LL);
}
}
goto LABEL_143;
}
if ( ((unsigned int)execute(*((_QWORD *)a1 + 1), 4LL, 0LL, 0LL, 0LL) != 0) != (v10 == 128) )
{
LABEL_116:
execute(*((_QWORD *)a1 + 2), (unsigned int)a2 | 4, a3, 0LL, 0LL);
goto LABEL_143;
}
goto LABEL_143;
}
v49 = 0LL;
}
else
{
if ( v10 == 32 )
{
LABEL_21:
chkpipe(fd);
if ( (unsigned int)execute(*((_QWORD *)a1 + 1), v46 & 4 | 8, a3, a4, fd) )
{
close(fd[0]);
close(fd[1]);
}
else
{
execute(*((_QWORD *)a1 + 2), v46, a3, fd, a5);
}
goto LABEL_143;
}
if ( (*a1 & 0xF0u) > 0x20 )
{
if ( v10 != 64 )
{
if ( v10 != 80 )
{
if ( v10 == 48 )
{
execute(*((_QWORD *)a1 + 1), a2 & 0xC, a3, 0LL, 0LL);
execute(*((_QWORD *)a1 + 2), (unsigned int)a2, a3 | eflag & 0x10, 0LL, 0LL);
}
goto LABEL_143;
}
goto LABEL_15;
}
if ( (unsigned int)execute(*((_QWORD *)a1 + 1), 4LL, 0LL, 0LL, 0LL) )
{
v40 = *((_QWORD *)a1 + 3);
if ( v40 )
execute(v40, (unsigned int)a2 | 4, a3, 0LL, 0LL);
else
exitval = 0;
goto LABEL_143;
}
goto LABEL_116;
}
if ( v10 )
{
if ( v10 == 16 )
{
LABEL_18:
if ( (v46 & 8) == 0 )
flags &= 0xFFFFFFFFFFBFFFFFLL;
clearjobs();
execute(*((_QWORD *)a1 + 1), v46, a3, 0LL, 0LL);
done(0LL);
goto LABEL_21;
}
LABEL_143:
retval = exitval;
goto LABEL_144;
}
v16 = gchain;
v50 = *((_QWORD *)a1 + 1);
exitval = 0;
gchain = 0LL;
v52 = getarg(a1);
v17 = (const void **)scan(v52);
v49 = v17;
gchain = v16;
if ( v52 )
{
LODWORD(a2) = 1;
v18 = pathlook(*v17, 1LL, *((_QWORD *)a1 + 3));
v55 = v18;
v19 = v18 & 0x1F00;
if ( (v18 & 0x1F00) == 256 )
{
LODWORD(a2) = 0;
setlist(*((_QWORD *)a1 + 3), 0LL);
}
if ( (flags & 1) == 0 )
{
if ( (*(&flags + 1) & 8) != 0 )
execprint(v49);
if ( !v19 )
{
if ( v55 == 1 )
{
failure(*v49, &notfound);
}
else if ( v55 == 2 )
{
failure(*v49, &badexec);
}
else
{
failure(*v49, &badperm);
}
goto LABEL_143;
}
if ( v19 == 4096 )
{
v8 = -1;
}
else
{
v8 = v19 & 0xC00;
if ( (v19 & 0xC00) != 0 )
{
v8 = v55;
}
else
{
if ( v19 == 256 )
{
builtin(v55, v52, v49, a1);
freejobs();
goto LABEL_143;
}
if ( v19 == 512 )
{
v20 = dolv;
v21 = dolc;
v22 = findnam(*v49);
v23 = savargs(funcnt);
++funcnt;
v24 = initio(v50, 1LL);
setargs(v49);
execute(*(_QWORD *)(v22 + 32), v46, a3, a4, a5);
execbrk = 0;
restore((unsigned int)v24);
restorargs(v23, funcnt);
dolv = v20;
dolc = v21;
--funcnt;
goto LABEL_143;
}
}
}
goto LABEL_68;
}
}
else
{
LODWORD(a2) = 0;
setlist(*((_QWORD *)a1 + 3), 0LL);
}
if ( !*((_QWORD *)a1 + 1) )
{
LABEL_48:
chktrap();
goto LABEL_143;
}
}
LABEL_68:
exitval = 0;
v53 = v46 & 1;
if ( (v46 & 1) != 0 )
{
v53 = v9 & 0x600;
if ( (v9 & 0x600) == 0 )
{
flags |= 0x400040uLL;
fiotemp = 0LL;
goto LABEL_71;
}
v51 = v9 & 0x200;
if ( (v9 & 0x200) != 0 )
{
v53 = 0;
goto LABEL_157;
}
}
else
{
v51 = v9 & 0x200;
if ( (v9 & 0x200) != 0 )
goto LABEL_82;
}
v51 = v46 & 4;
if ( (v46 & 4) == 0 && (flags & 0x4C0000) == 786432LL )
{
v54 = setb(0xFFFFFFFFLL);
v26 = stakbot;
prcmd(a1);
setb(v54);
a2 = cwdget();
allocjob(v26, a2, 1LL);
v53 = 1;
}
else
{
a2 = (__int64)&unk_CEE;
allocjob(&unk_CEE, &unk_CEE, 0LL);
v51 = 0;
v53 = 0;
}
LABEL_82:
v56 = v9 & 0x600;
if ( (v9 & 0x600) == 0 )
{
LABEL_83:
for ( i = 1; ; sh_sleep((unsigned int)i) )
{
parent = fork();
if ( parent != -1 )
break;
i *= 2;
if ( i <= 32 )
{
if ( *_errno_location() == 1 )
{
deallocjob();
error((int)&eacces, a2, v30);
break;
}
}
else if ( *_errno_location() == 12 )
{
deallocjob();
error((int)&noswap, a2, v27);
}
else
{
deallocjob();
error((int)&nofork, a2, v29);
}
if ( (trapnote & 4) != 0 )
{
v28 = exitval;
if ( !exitval )
v28 = 2000LL;
exitsh(v28);
}
}
if ( parent )
{
if ( v53 )
setpgid(parent, 0);
if ( (v9 & 0x100) != 0 )
{
close(*a4);
close(a4[1]);
}
if ( !v51 )
{
postjob((unsigned int)parent, (v9 & 0x400) == 0);
freejobs();
}
goto LABEL_48;
}
mypid = getpid();
flags |= 0x400040uLL;
fiotemp = 0LL;
if ( v56 == 1 )
{
swap_iodoc_nm(iotemp);
v46 |= 2u;
LABEL_73:
suspacct();
settmp();
oldsigs();
if ( (v9 & 0x200) != 0 )
{
if ( (v9 & 0x100) != 0 )
{
renamef((unsigned int)*a4, 0LL);
close(a4[1]);
}
close(*(_DWORD *)a5);
renamef(*(unsigned int *)(a5 + 4), 1LL);
}
else
{
makejob(v53, (v9 & 0x400) == 0);
if ( (v9 & 0x100) != 0 )
{
renamef((unsigned int)*a4, 0LL);
close(a4[1]);
}
}
initio(*((_QWORD *)a1 + 1), 0LL);
if ( v10 == 160 )
{
execute(*((_QWORD *)a1 + 2), v46 | 1, a3, 0LL, 0LL);
}
else if ( *v49 )
{
eflag = 0;
setlist(*((_QWORD *)a1 + 3), 4LL);
rmtemp(0LL);
clearjobs();
execa(v49, (unsigned int)v8);
}
done(0LL);
goto LABEL_18;
}
LABEL_71:
if ( (v46 & 2) == 0 )
iotemp = 0LL;
goto LABEL_73;
}
LABEL_157:
link_iodocs(iotemp);
v56 = 1;
goto LABEL_83;
}
}
LABEL_144:
if ( (trapnote & 4) != 0 )
{
v41 = exitval;
if ( !exitval )
v41 = 2000LL;
exitsh(v41);
}
tdystak(v45);
flags |= eflag;
return exitval;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, __int64 a2, unsigned int a3, int *a4, __int64 a5)
{
__int64 v7; // rdi
__int16 v8; // r15
int v9; // er13
int v10; // ebx
int v11; // er13
__int64 v12; // rax
__int64 v13; // rbx
__int64 v14; // r13
__int64 v15; // r14
__int64 v16; // r14
const void **v17; // rax
__int16 v18; // ax
__int16 v19; // r14
__int64 v20; // rbx
int v21; // ebp
__int64 v22; // r13
__int64 v23; // r15
__int16 v24; // r14
int i; // er14
__int64 v26; // r14
const char *v27; // rdx
__int64 v28; // rdi
const char *v29; // rdx
const char *v30; // rdx
__int64 v31; // r13
__int64 v32; // r14
unsigned int v33; // eax
_QWORD *v34; // rbx
__int64 v35; // r14
int v36; // eax
int v37; // eax
int v38; // eax
int v39; // eax
__int64 v40; // rdi
__int64 v41; // rdi
_QWORD *v43; // rbp
__int64 v44; // rbx
__int64 v45; // [rsp+8h] [rbp-80h]
unsigned int v46; // [rsp+14h] [rbp-74h]
const void **v49; // [rsp+28h] [rbp-60h]
__int64 v50; // [rsp+30h] [rbp-58h]
int v51; // [rsp+30h] [rbp-58h]
unsigned int v52; // [rsp+38h] [rbp-50h]
unsigned int v53; // [rsp+38h] [rbp-50h]
unsigned int v54; // [rsp+38h] [rbp-50h]
unsigned __int8 v55; // [rsp+3Ch] [rbp-4Ch]
int v56; // [rsp+3Ch] [rbp-4Ch]
int fd[16]; // [rsp+48h] [rbp-40h] BYREF

v46 = a2;
v45 = savstak();
if ( (trapnote & 4) != 0 )
{
v7 = exitval;
if ( !exitval )
v7 = 2000LL;
exitsh(v7);
}
if ( !a3 )
flags &= 0xFFFFFFFFFFFFFFEFLL;
if ( a1 )
{
v8 = execbrk;
if ( !execbrk )
{
v9 = *a1;
v10 = *a1 & 0xF0;
if ( v10 == 96 )
{
LABEL_15:
++loopcnt;
v11 = 0;
do
{
if ( ((unsigned int)func1(*((_QWORD *)a1 + 1), 4LL, 0LL, 0LL, 0LL) != 0) == (v10 == 80) || (flags & 1) != 0 )
break;
v11 = func1(*((_QWORD *)a1 + 2), 4LL, a3, 0LL, 0LL);
v38 = breakcnt;
if ( breakcnt < 0 )
{
++breakcnt;
execbrk = v38 != -1;
}
}
while ( !execbrk );
v39 = breakcnt;
if ( breakcnt > 0 )
{
--breakcnt;
execbrk = v39 != 1;
}
--loopcnt;
exitval = v11;
goto LABEL_143;
}
if ( (*a1 & 0xF0u) > 0x60 )
{
if ( v10 != 160 )
{
if ( (*a1 & 0xF0u) > 0xA0 )
{
if ( v10 == 176 )
{
v31 = lookup(*((_QWORD *)a1 + 2));
if ( *((_QWORD *)a1 + 3) )
{
v32 = gchain;
gchain = 0LL;
v33 = ((__int64 (*)(void))getarg)();
v34 = (_QWORD *)scan(v33);
gchain = v32;
v35 = 0LL;
}
else
{
v34 = (_QWORD *)(dolv + 8LL);
v35 = useargs();
}
++loopcnt;
while ( *v34 )
{
if ( execbrk )
break;
++v34;
assign(v31);
func1(*((_QWORD *)a1 + 1), 4LL, a3, 0LL, 0LL);
v37 = breakcnt;
if ( breakcnt < 0 )
{
++breakcnt;
execbrk = v37 != -1;
}
}
v36 = breakcnt;
if ( breakcnt > 0 )
{
--breakcnt;
execbrk = v36 != 1;
}
--loopcnt;
if ( v35 )
argfor = freeargs(v35);
}
else if ( v10 == 192 )
{
v12 = lookup(*((_QWORD *)a1 + 1));
v13 = v12;
exitval = 0;
if ( (*(_BYTE *)(v12 + 40) & 8) != 0 )
failed(*(_QWORD *)(v12 + 16), &wtfailed);
if ( (*((_BYTE *)&flags + 1) & 1) != 0
&& ((_UNKNOWN *)v13 == &pathnod || !(unsigned int)nullsub_1(*(_QWORD *)(v13 + 16), "SHELL")) )
{
failed(*(_QWORD *)(v13 + 16), &restricted);
}
if ( (*(_BYTE *)(v13 + 40) & 1) != 0 )
{
freefunc(v13);
}
else
{
sh_free(*(_QWORD *)(v13 + 24));
sh_free(*(_QWORD *)(v13 + 32));
*(_QWORD *)(v13 + 24) = 0LL;
*(_DWORD *)(v13 + 40) &= 0xFFFFFFEB;
}
if ( funcnt )
++**((_DWORD **)a1 + 2);
*(_QWORD *)(v13 + 32) = *((_QWORD *)a1 + 2);
*(_DWORD *)(v13 + 40) |= 1u;
hash_func(*(_QWORD *)(v13 + 16));
}
goto LABEL_143;
}
if ( (*a1 & 0xE0) != 128 )
{
if ( v10 == 112 )
{
v14 = mactrim(*((_QWORD *)a1 + 1));
v15 = *((_QWORD *)a1 + 2);
if ( v15 )
{
while ( 1 )
{
v43 = *(_QWORD **)v15;
if ( *(_QWORD *)v15 )
break;
LABEL_149:
v15 = *(_QWORD *)(v15 + 16);
if ( !v15 )
goto LABEL_143;
}
while ( 1 )
{
v44 = macro(v43 + 1);
if ( (unsigned int)gmatch(v14, v44) )
break;
trim(v44);
if ( !(unsigned int)nullsub_1(v14, v44) )
break;
v43 = (_QWORD *)*v43;
if ( !v43 )
goto LABEL_149;
}
func1(*(_QWORD *)(v15 + 8), 4LL, a3, 0LL, 0LL);
}
}
goto LABEL_143;
}
if ( ((unsigned int)func1(*((_QWORD *)a1 + 1), 4LL, 0LL, 0LL, 0LL) != 0) != (v10 == 128) )
{
LABEL_116:
func1(*((_QWORD *)a1 + 2), (unsigned int)a2 | 4, a3, 0LL, 0LL);
goto LABEL_143;
}
goto LABEL_143;
}
v49 = 0LL;
}
else
{
if ( v10 == 32 )
{
LABEL_21:
chkpipe(fd);
if ( (unsigned int)func1(*((_QWORD *)a1 + 1), v46 & 4 | 8, a3, a4, fd) )
{
close(fd[0]);
close(fd[1]);
}
else
{
func1(*((_QWORD *)a1 + 2), v46, a3, fd, a5);
}
goto LABEL_143;
}
if ( (*a1 & 0xF0u) > 0x20 )
{
if ( v10 != 64 )
{
if ( v10 != 80 )
{
if ( v10 == 48 )
{
func1(*((_QWORD *)a1 + 1), a2 & 0xC, a3, 0LL, 0LL);
func1(*((_QWORD *)a1 + 2), (unsigned int)a2, a3 | eflag & 0x10, 0LL, 0LL);
}
goto LABEL_143;
}
goto LABEL_15;
}
if ( (unsigned int)func1(*((_QWORD *)a1 + 1), 4LL, 0LL, 0LL, 0LL) )
{
v40 = *((_QWORD *)a1 + 3);
if ( v40 )
func1(v40, (unsigned int)a2 | 4, a3, 0LL, 0LL);
else
exitval = 0;
goto LABEL_143;
}
goto LABEL_116;
}
if ( v10 )
{
if ( v10 == 16 )
{
LABEL_18:
if ( (v46 & 8) == 0 )
flags &= 0xFFFFFFFFFFBFFFFFLL;
clearjobs();
func1(*((_QWORD *)a1 + 1), v46, a3, 0LL, 0LL);
done(0LL);
goto LABEL_21;
}
LABEL_143:
retval = exitval;
goto LABEL_144;
}
v16 = gchain;
v50 = *((_QWORD *)a1 + 1);
exitval = 0;
gchain = 0LL;
v52 = getarg(a1);
v17 = (const void **)scan(v52);
v49 = v17;
gchain = v16;
if ( v52 )
{
LODWORD(a2) = 1;
v18 = pathlook(*v17, 1LL, *((_QWORD *)a1 + 3));
v55 = v18;
v19 = v18 & 0x1F00;
if ( (v18 & 0x1F00) == 256 )
{
LODWORD(a2) = 0;
setlist(*((_QWORD *)a1 + 3), 0LL);
}
if ( (flags & 1) == 0 )
{
if ( (*(&flags + 1) & 8) != 0 )
func0(v49);
if ( !v19 )
{
if ( v55 == 1 )
{
failure(*v49, &notfound);
}
else if ( v55 == 2 )
{
failure(*v49, &badexec);
}
else
{
failure(*v49, &badperm);
}
goto LABEL_143;
}
if ( v19 == 4096 )
{
v8 = -1;
}
else
{
v8 = v19 & 0xC00;
if ( (v19 & 0xC00) != 0 )
{
v8 = v55;
}
else
{
if ( v19 == 256 )
{
builtin(v55, v52, v49, a1);
freejobs();
goto LABEL_143;
}
if ( v19 == 512 )
{
v20 = dolv;
v21 = dolc;
v22 = findnam(*v49);
v23 = savargs(funcnt);
++funcnt;
v24 = initio(v50, 1LL);
setargs(v49);
func1(*(_QWORD *)(v22 + 32), v46, a3, a4, a5);
execbrk = 0;
restore((unsigned int)v24);
restorargs(v23, funcnt);
dolv = v20;
dolc = v21;
--funcnt;
goto LABEL_143;
}
}
}
goto LABEL_68;
}
}
else
{
LODWORD(a2) = 0;
setlist(*((_QWORD *)a1 + 3), 0LL);
}
if ( !*((_QWORD *)a1 + 1) )
{
LABEL_48:
chktrap();
goto LABEL_143;
}
}
LABEL_68:
exitval = 0;
v53 = v46 & 1;
if ( (v46 & 1) != 0 )
{
v53 = v9 & 0x600;
if ( (v9 & 0x600) == 0 )
{
flags |= 0x400040uLL;
fiotemp = 0LL;
goto LABEL_71;
}
v51 = v9 & 0x200;
if ( (v9 & 0x200) != 0 )
{
v53 = 0;
goto LABEL_157;
}
}
else
{
v51 = v9 & 0x200;
if ( (v9 & 0x200) != 0 )
goto LABEL_82;
}
v51 = v46 & 4;
if ( (v46 & 4) == 0 && (flags & 0x4C0000) == 786432LL )
{
v54 = setb(0xFFFFFFFFLL);
v26 = stakbot;
prcmd(a1);
setb(v54);
a2 = cwdget();
allocjob(v26, a2, 1LL);
v53 = 1;
}
else
{
a2 = (__int64)&unk_CEE;
allocjob(&unk_CEE, &unk_CEE, 0LL);
v51 = 0;
v53 = 0;
}
LABEL_82:
v56 = v9 & 0x600;
if ( (v9 & 0x600) == 0 )
{
LABEL_83:
for ( i = 1; ; sh_sleep((unsigned int)i) )
{
parent = fork();
if ( parent != -1 )
break;
i *= 2;
if ( i <= 32 )
{
if ( *_errno_location() == 1 )
{
deallocjob();
error((int)&eacces, a2, v30);
break;
}
}
else if ( *_errno_location() == 12 )
{
deallocjob();
error((int)&noswap, a2, v27);
}
else
{
deallocjob();
error((int)&nofork, a2, v29);
}
if ( (trapnote & 4) != 0 )
{
v28 = exitval;
if ( !exitval )
v28 = 2000LL;
exitsh(v28);
}
}
if ( parent )
{
if ( v53 )
setpgid(parent, 0);
if ( (v9 & 0x100) != 0 )
{
close(*a4);
close(a4[1]);
}
if ( !v51 )
{
postjob((unsigned int)parent, (v9 & 0x400) == 0);
freejobs();
}
goto LABEL_48;
}
mypid = getpid();
flags |= 0x400040uLL;
fiotemp = 0LL;
if ( v56 == 1 )
{
swap_iodoc_nm(iotemp);
v46 |= 2u;
LABEL_73:
suspacct();
settmp();
oldsigs();
if ( (v9 & 0x200) != 0 )
{
if ( (v9 & 0x100) != 0 )
{
renamef((unsigned int)*a4, 0LL);
close(a4[1]);
}
close(*(_DWORD *)a5);
renamef(*(unsigned int *)(a5 + 4), 1LL);
}
else
{
makejob(v53, (v9 & 0x400) == 0);
if ( (v9 & 0x100) != 0 )
{
renamef((unsigned int)*a4, 0LL);
close(a4[1]);
}
}
initio(*((_QWORD *)a1 + 1), 0LL);
if ( v10 == 160 )
{
func1(*((_QWORD *)a1 + 2), v46 | 1, a3, 0LL, 0LL);
}
else if ( *v49 )
{
eflag = 0;
setlist(*((_QWORD *)a1 + 3), 4LL);
rmtemp(0LL);
clearjobs();
execa(v49, (unsigned int)v8);
}
done(0LL);
goto LABEL_18;
}
LABEL_71:
if ( (v46 & 2) == 0 )
iotemp = 0LL;
goto LABEL_73;
}
LABEL_157:
link_iodocs(iotemp);
v56 = 1;
goto LABEL_83;
}
}
LABEL_144:
if ( (trapnote & 4) != 0 )
{
v41 = exitval;
if ( !exitval )
v41 = 2000LL;
exitsh(v41);
}
tdystak(v45);
flags |= eflag;
return exitval;
}

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)
{
int v2; // ebx
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 & 0x10;
v3 = (int *)cmd(10LL, 3LL);
execute(v3, 0LL, v2, 0LL, 0LL);
return pop();
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // ebx
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 & 0x10;
v3 = (int *)cmd(10LL, 3LL);
func1(v3, 0LL, v2, 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, char *a3, __int64 a4)
{
char *v7; // rbx
_BYTE *v8; // rbp
char i; // r14
int v10; // ebp
char *v11; // rbp
char v12; // al
_QWORD *v13; // 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);
*v7++ = i;
++v8;
}
if ( v8 == (_BYTE *)(a4 + 1) )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
*v7++ = 47;
}
}
while ( 1 )
{
if ( mb_cur_max <= 1 || *a2 >= 0 )
{
pwc[0] = *(unsigned __int8 *)a2;
v10 = pwc[0] != 0;
}
else
{
v10 = mbtowc(pwc, a2, mb_cur_max);
}
if ( v10 <= 0 )
{
pwc[0] = *(unsigned __int8 *)a2;
v10 = 1;
}
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
if ( !pwc[0] )
break;
if ( pwc[0] == 92 )
{
*v7 = 92;
if ( brkend <= (unsigned __int64)(v7 + 1) )
growstak(v7 + 1);
v7[1] = 92;
++a2;
v7 += 2;
}
else
{
if ( (unsigned __int64)&v7[v10] >= brkend )
growstak(&v7[v10]);
memcpy(v7, a2, v10);
a2 += v10;
v7 += v10;
}
}
*v7 = *a2;
v11 = v7;
if ( a3 )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
v11 = v7 + 1;
*v7 = 47;
do
{
if ( brkend <= (unsigned __int64)v11 )
growstak(v11);
++a3;
++v11;
v12 = *a3;
*(v11 - 1) = *a3;
}
while ( v12 );
}
v13 = (_QWORD *)endstak(v11);
return makearg(v13);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, const char *a2, char *a3, __int64 a4)
{
char *v7; // rbx
_BYTE *v8; // rbp
char i; // r14
int v10; // ebp
char *v11; // rbp
char v12; // al
_QWORD *v13; // 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);
*v7++ = i;
++v8;
}
if ( v8 == (_BYTE *)(a4 + 1) )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
*v7++ = 47;
}
}
while ( 1 )
{
if ( mb_cur_max <= 1 || *a2 >= 0 )
{
pwc[0] = *(unsigned __int8 *)a2;
v10 = pwc[0] != 0;
}
else
{
v10 = mbtowc(pwc, a2, mb_cur_max);
}
if ( v10 <= 0 )
{
pwc[0] = *(unsigned __int8 *)a2;
v10 = 1;
}
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
if ( !pwc[0] )
break;
if ( pwc[0] == 92 )
{
*v7 = 92;
if ( brkend <= (unsigned __int64)(v7 + 1) )
growstak(v7 + 1);
v7[1] = 92;
++a2;
v7 += 2;
}
else
{
if ( (unsigned __int64)&v7[v10] >= brkend )
growstak(&v7[v10]);
memcpy(v7, a2, v10);
a2 += v10;
v7 += v10;
}
}
*v7 = *a2;
v11 = v7;
if ( a3 )
{
if ( brkend <= (unsigned __int64)v7 )
growstak(v7);
v11 = v7 + 1;
*v7 = 47;
do
{
if ( brkend <= (unsigned __int64)v11 )
growstak(v11);
++a3;
++v11;
v12 = *a3;
*(v11 - 1) = *a3;
}
while ( v12 );
}
v13 = (_QWORD *)endstak(v11);
return func0(v13);
}

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 *

return_type: unsigned char *


sysulimit

decompiled_code:
__int64 __fastcall sysulimit(int argc, char **argv)
{
int v2; // er13
int v3; // er14
char *v4; // r15
int v5; // ebx
int v6; // eax
__int64 result; // rax
int v8; // eax
int v9; // eax
char *v10; // rcx
unsigned __int64 i; // rdx
int v12; // eax
int *v13; // r12
__int64 v14; // rax
int v15; // ebp
unsigned __int64 v16; // rax
__int64 v17; // rdx
rlim64_t v18; // rbx
__rlimit_resource_t v19; // er12
unsigned int v20; // [rsp+4h] [rbp-94h]
__int64 v21; // [rsp+8h] [rbp-90h]
int *v22; // [rsp+18h] [rbp-80h]
__rlimit_resource_t resource; // [rsp+20h] [rbp-78h] BYREF
int v24[11]; // [rsp+24h] [rbp-74h] BYREF
struct rlimit64 rlimits; // [rsp+50h] [rbp-48h] BYREF

v20 = optind;
v2 = opterr;
v3 = getopt_sp;
v4 = optarg;
optind = 1;
getopt_sp = 1;
opterr = 0;
v5 = 0;
v21 = 0LL;
while ( 1 )
{
v6 = getopt(argc, argv, "HSacdflmnstuv");
if ( v6 == -1 )
break;
if ( v5 == 11 )
goto LABEL_8;
switch ( v6 )
{
case 'H':
++HIDWORD(v21);
continue;
case 'S':
LODWORD(v21) = v21 + 1;
continue;
case 'a':
if ( v5 )
goto LABEL_8;
resource = RLIMIT_CORE;
v24[0] = 2;
v24[1] = 1;
v24[2] = 8;
v24[3] = 5;
v24[4] = 3;
v24[5] = 0;
v24[6] = 7;
v24[7] = 6;
v24[8] = 9;
v5 = 10;
continue;
case 'c':
*((_DWORD *)&resource + v5++) = 4;
continue;
case 'd':
*((_DWORD *)&resource + v5++) = 2;
continue;
case 'f':
*((_DWORD *)&resource + v5++) = 1;
continue;
case 'l':
*((_DWORD *)&resource + v5++) = 8;
continue;
case 'm':
*((_DWORD *)&resource + v5++) = 5;
continue;
case 'n':
*((_DWORD *)&resource + v5++) = 7;
continue;
case 's':
*((_DWORD *)&resource + v5++) = 3;
continue;
case 't':
*((_DWORD *)&resource + v5++) = 0;
continue;
case 'u':
v8 = v5 + 1;
*((_DWORD *)&resource + v5) = 0;
goto LABEL_20;
case 'v':
v8 = v5;
LABEL_20:
v5 = v8 + 1;
*((_DWORD *)&resource + v8) = 9;
break;
default:
goto LABEL_8;
}
}
if ( !v5 )
{
resource = RLIMIT_FSIZE;
v9 = optind;
if ( argc != optind )
goto LABEL_24;
v5 = 1;
if ( !v21 )
{
v21 = 1LL;
v5 = 1;
LABEL_34:
v13 = (int *)&resource;
while ( 1 )
{
v14 = 0LL;
while ( 1 )
{
v15 = v14;
if ( rlimtab[8 * v14] == *v13 )
break;
if ( ++v14 == 11 )
goto LABEL_48;
}
if ( getrlimit64((__rlimit_resource_t)rlimtab[8 * (int)v14], &rlimits) < 0 )
goto LABEL_48;
if ( v5 > 1 )
{
v22 = &rlimtab[8 * v15];
prs_buff(*((_QWORD *)v22 + 1));
prc_buff(40LL);
prs_buff(*((_QWORD *)v22 + 2));
prc_buff(41LL);
prc_buff(32LL);
}
if ( (_DWORD)v21 )
break;
if ( HIDWORD(v21) )
goto LABEL_43;
LABEL_47:
prc_buff(10LL);
LABEL_48:
if ( ++v13 == &v24[v5 - 1] )
goto LABEL_9;
}
if ( rlimits.rlim_cur == -1LL )
prs_buff("unlimited");
else
prull_buff(rlimits.rlim_cur / qword_718[4 * v15], &rlimits, rlimits.rlim_cur % qword_718[4 * v15]);
if ( !HIDWORD(v21) )
goto LABEL_47;
prc_buff(58LL);
LABEL_43:
if ( rlimits.rlim_max == -1LL )
prs_buff("unlimited");
else
prull_buff(rlimits.rlim_max / qword_718[4 * v15], &rlimits, rlimits.rlim_max % qword_718[4 * v15]);
goto LABEL_47;
}
LABEL_33:
if ( v5 <= 0 )
goto LABEL_9;
goto LABEL_34;
}
v9 = optind;
if ( optind == argc )
{
v12 = 1;
if ( v21 )
v12 = v21;
LODWORD(v21) = v12;
goto LABEL_33;
}
if ( v5 > 1 )
goto LABEL_8;
LABEL_24:
if ( v9 + 1 != argc )
goto LABEL_8;
if ( (unsigned int)nullsub_1(argv[v9], "unlimited") )
{
v10 = argv[optind];
for ( i = 0LL; (unsigned __int8)(*v10 - 48) <= 9u; i = v16 )
{
v16 = *v10 - 48 + 10 * i;
if ( i > v16 )
break;
if ( !*++v10 )
{
v17 = 0LL;
while ( rlimtab[8 * v17] != resource )
{
if ( ++v17 == 11 )
goto LABEL_8;
}
v18 = qword_718[4 * (int)v17] * v16;
if ( v16 <= v18 )
goto LABEL_65;
goto LABEL_8;
}
}
goto LABEL_8;
}
v18 = -1LL;
LABEL_65:
v19 = resource;
if ( getrlimit64(resource, &rlimits) < 0 )
{
LABEL_8:
failure(*argv, &badulimit);
goto LABEL_9;
}
if ( v21 )
{
if ( !HIDWORD(v21) )
goto LABEL_68;
}
else
{
LODWORD(v21) = 1;
}
rlimits.rlim_max = v18;
LABEL_68:
if ( (_DWORD)v21 )
rlimits.rlim_cur = v18;
if ( setrlimit64(v19, &rlimits) < 0 )
goto LABEL_8;
LABEL_9:
result = v20;
optind = v20;
opterr = v2;
getopt_sp = v3;
optarg = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv)
{
int v2; // er13
int v3; // er14
char *v4; // r15
int v5; // ebx
int v6; // eax
__int64 result; // rax
int v8; // eax
int v9; // eax
char *v10; // rcx
unsigned __int64 i; // rdx
int v12; // eax
int *v13; // r12
__int64 v14; // rax
int v15; // ebp
unsigned __int64 v16; // rax
__int64 v17; // rdx
rlim64_t v18; // rbx
__rlimit_resource_t v19; // er12
unsigned int v20; // [rsp+4h] [rbp-94h]
__int64 v21; // [rsp+8h] [rbp-90h]
int *v22; // [rsp+18h] [rbp-80h]
__rlimit_resource_t resource; // [rsp+20h] [rbp-78h] BYREF
int v24[11]; // [rsp+24h] [rbp-74h] BYREF
struct rlimit64 rlimits; // [rsp+50h] [rbp-48h] BYREF

v20 = optind;
v2 = opterr;
v3 = getopt_sp;
v4 = optarg;
optind = 1;
getopt_sp = 1;
opterr = 0;
v5 = 0;
v21 = 0LL;
while ( 1 )
{
v6 = getopt(argc, argv, "HSacdflmnstuv");
if ( v6 == -1 )
break;
if ( v5 == 11 )
goto LABEL_8;
switch ( v6 )
{
case 'H':
++HIDWORD(v21);
continue;
case 'S':
LODWORD(v21) = v21 + 1;
continue;
case 'a':
if ( v5 )
goto LABEL_8;
resource = RLIMIT_CORE;
v24[0] = 2;
v24[1] = 1;
v24[2] = 8;
v24[3] = 5;
v24[4] = 3;
v24[5] = 0;
v24[6] = 7;
v24[7] = 6;
v24[8] = 9;
v5 = 10;
continue;
case 'c':
*((_DWORD *)&resource + v5++) = 4;
continue;
case 'd':
*((_DWORD *)&resource + v5++) = 2;
continue;
case 'f':
*((_DWORD *)&resource + v5++) = 1;
continue;
case 'l':
*((_DWORD *)&resource + v5++) = 8;
continue;
case 'm':
*((_DWORD *)&resource + v5++) = 5;
continue;
case 'n':
*((_DWORD *)&resource + v5++) = 7;
continue;
case 's':
*((_DWORD *)&resource + v5++) = 3;
continue;
case 't':
*((_DWORD *)&resource + v5++) = 0;
continue;
case 'u':
v8 = v5 + 1;
*((_DWORD *)&resource + v5) = 0;
goto LABEL_20;
case 'v':
v8 = v5;
LABEL_20:
v5 = v8 + 1;
*((_DWORD *)&resource + v8) = 9;
break;
default:
goto LABEL_8;
}
}
if ( !v5 )
{
resource = RLIMIT_FSIZE;
v9 = optind;
if ( argc != optind )
goto LABEL_24;
v5 = 1;
if ( !v21 )
{
v21 = 1LL;
v5 = 1;
LABEL_34:
v13 = (int *)&resource;
while ( 1 )
{
v14 = 0LL;
while ( 1 )
{
v15 = v14;
if ( rlimtab[8 * v14] == *v13 )
break;
if ( ++v14 == 11 )
goto LABEL_48;
}
if ( getrlimit64((__rlimit_resource_t)rlimtab[8 * (int)v14], &rlimits) < 0 )
goto LABEL_48;
if ( v5 > 1 )
{
v22 = &rlimtab[8 * v15];
prs_buff(*((_QWORD *)v22 + 1));
prc_buff(40LL);
prs_buff(*((_QWORD *)v22 + 2));
prc_buff(41LL);
prc_buff(32LL);
}
if ( (_DWORD)v21 )
break;
if ( HIDWORD(v21) )
goto LABEL_43;
LABEL_47:
prc_buff(10LL);
LABEL_48:
if ( ++v13 == &v24[v5 - 1] )
goto LABEL_9;
}
if ( rlimits.rlim_cur == -1LL )
prs_buff("unlimited");
else
prull_buff(rlimits.rlim_cur / qword_718[4 * v15], &rlimits, rlimits.rlim_cur % qword_718[4 * v15]);
if ( !HIDWORD(v21) )
goto LABEL_47;
prc_buff(58LL);
LABEL_43:
if ( rlimits.rlim_max == -1LL )
prs_buff("unlimited");
else
prull_buff(rlimits.rlim_max / qword_718[4 * v15], &rlimits, rlimits.rlim_max % qword_718[4 * v15]);
goto LABEL_47;
}
LABEL_33:
if ( v5 <= 0 )
goto LABEL_9;
goto LABEL_34;
}
v9 = optind;
if ( optind == argc )
{
v12 = 1;
if ( v21 )
v12 = v21;
LODWORD(v21) = v12;
goto LABEL_33;
}
if ( v5 > 1 )
goto LABEL_8;
LABEL_24:
if ( v9 + 1 != argc )
goto LABEL_8;
if ( (unsigned int)nullsub_1(argv[v9], "unlimited") )
{
v10 = argv[optind];
for ( i = 0LL; (unsigned __int8)(*v10 - 48) <= 9u; i = v16 )
{
v16 = *v10 - 48 + 10 * i;
if ( i > v16 )
break;
if ( !*++v10 )
{
v17 = 0LL;
while ( rlimtab[8 * v17] != resource )
{
if ( ++v17 == 11 )
goto LABEL_8;
}
v18 = qword_718[4 * (int)v17] * v16;
if ( v16 <= v18 )
goto LABEL_65;
goto LABEL_8;
}
}
goto LABEL_8;
}
v18 = -1LL;
LABEL_65:
v19 = resource;
if ( getrlimit64(resource, &rlimits) < 0 )
{
LABEL_8:
failure(*argv, &badulimit);
goto LABEL_9;
}
if ( v21 )
{
if ( !HIDWORD(v21) )
goto LABEL_68;
}
else
{
LODWORD(v21) = 1;
}
rlimits.rlim_max = v18;
LABEL_68:
if ( (_DWORD)v21 )
rlimits.rlim_cur = v18;
if ( setrlimit64(v19, &rlimits) < 0 )
goto LABEL_8;
LABEL_9:
result = v20;
optind = v20;
opterr = v2;
getopt_sp = v3;
optarg = v4;
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; } *


decompiled_code:
int __fastcall str_2_sig(char *nptr, _DWORD *a2)
{
char **v3; // rbx
int v4; // ebp
const char *v5; // rsi
int result; // eax
__int64 v7; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v3 = off_420;
v4 = 0;
v5 = "EXIT";
do
{
result = strcmp(nptr, v5);
if ( !result )
{
*a2 = sig_strs[6 * v4];
return result;
}
++v4;
v3 += 3;
v5 = *(v3 - 3);
}
while ( v5 );
v7 = strtol(nptr, &endptr, 10);
if ( *endptr || v7 < 0 )
return -1;
if ( v4 <= v7 )
return -1;
if ( ((*nptr - 43) & 0xFD) == 0 )
return -1;
*a2 = v7;
return 0;
}

canonical_decompiled_code:
int __fastcall func0(char *nptr, _DWORD *a2)
{
char **v3; // rbx
int v4; // ebp
const char *v5; // rsi
int result; // eax
__int64 v7; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v3 = off_420;
v4 = 0;
v5 = "EXIT";
do
{
result = strcmp(nptr, v5);
if ( !result )
{
*a2 = sig_strs[6 * v4];
return result;
}
++v4;
v3 += 3;
v5 = *(v3 - 3);
}
while ( v5 );
v7 = strtol(nptr, &endptr, 10);
if ( *endptr || v7 < 0 )
return -1;
if ( v4 <= v7 )
return -1;
if ( ((*nptr - 43) & 0xFD) == 0 )
return -1;
*a2 = v7;
return 0;
}

original_code:
int
str_2_sig(const char *str, int *signum)
{
 register int i;
 long n;
 char *x;
 for (i = 0; sig_strs[i].sig_str; i++)
  if (strcmp(str, sig_strs[i].sig_str) == 0)
   break;
 if (sig_strs[i].sig_str == ((void *)0)) {
  n = strtol(str, &x, 10);
  if (*x != '\0' || n < 0 || n >= i || *str == '+' || *str == '-')
   return -1;
  *signum = n;
 } else
  *signum = sig_strs[i].sig_num;
 return 0;
}

canonical_original_code:
int str_2_sig(char *str, int *signum)
{
 register int i;
 long n;
 char *x;
 for (i = 0; sig_strs[i].sig_str; i++)
  if (strcmp(str, sig_strs[i].sig_str) == 0)
   break;
 if (sig_strs[i].sig_str == ((void *)0)) {
  n = strtol(str, &x, 10);
  if (*x != '\0' || n < 0 || n >= i || *str == '+' || *str == '-')
   return -1;
  *signum = n;
 } else
  *signum = sig_strs[i].sig_num;
 return 0;
}

variable_types:
str
char *

variable_types:
signum
int *

variable_types: i int

variable_types: n long

variable_types:
x
char *


decompiled_code:
__int64 __fastcall sig_2_str(int a1, char *a2)
{
int *v3; // rax
const char *v4; // rsi

v3 = sig_strs;
v4 = "EXIT";
while ( *v3 != a1 )
{
v3 += 6;
v4 = (const char *)*((_QWORD *)v3 + 1);
if ( !v4 )
return 0xFFFFFFFFLL;
}
if ( !v4 )
return 0xFFFFFFFFLL;
strcpy(a2, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, char *a2)
{
int *v3; // rax
const char *v4; // rsi

v3 = sig_strs;
v4 = "EXIT";
while ( *v3 != a1 )
{
v3 += 6;
v4 = (const char *)*((_QWORD *)v3 + 1);
if ( !v4 )
return 0xFFFFFFFFLL;
}
if ( !v4 )
return 0xFFFFFFFFLL;
strcpy(a2, v4);
return 0LL;
}

original_code:
int
sig_2_str(int signum, char *str)
{
 register int i;
 for (i = 0; sig_strs[i].sig_str; i++)
  if (sig_strs[i].sig_num == signum)
   break;
 if (sig_strs[i].sig_str == ((void *)0))
  return -1;
 strcpy(str, sig_strs[i].sig_str);
 return 0;
}

variable_types: signum int


decompiled_code:
const char *__fastcall str_signal(int a1)
{
int *v1; // rax
const char *v2; // rdx

v1 = sig_strs;
v2 = "UNKNOWN SIGNAL";
do
{
if ( *v1 == a1 )
break;
v1 += 6;
v2 = (const char *)*((_QWORD *)v1 + 2);
}
while ( v2 );
return v2;
}

canonical_decompiled_code:
const char *__fastcall func2(int a1)
{
int *v1; // rax
const char *v2; // rdx

v1 = sig_strs;
v2 = "UNKNOWN SIGNAL";
do
{
if ( *v1 == a1 )
break;
v1 += 6;
v2 = (const char *)*((_QWORD *)v1 + 2);
}
while ( v2 );
return v2;
}

original_code:
char *
str_signal(int signum)
{
 register int i;
 for (i = 0; sig_strs[i].sig_name; i++)
  if (sig_strs[i].sig_num == signum)
   break;
 return (char *)sig_strs[i].sig_name;
}

canonical_original_code:
char *str_signal(int signum)
{
 register int i;
 for (i = 0; sig_strs[i].sig_name; i++)
  if (sig_strs[i].sig_num == signum)
   break;
 return (char *)sig_strs[i].sig_name;
}

return_type: char *


mbtowi

decompiled_code:
int __fastcall mbtowi(wchar_t *a1, const char *a2, size_t a3)
{
int result; // eax
wchar_t pwc[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = mbtowc(pwc, a2, a3);
*a1 = pwc[0];
return result;
}

canonical_decompiled_code:
int __fastcall func0(wchar_t *a1, const char *a2, size_t a3)
{
int result; // eax
wchar_t pwc[3]; // [rsp+Ch] [rbp-Ch] BYREF

result = mbtowc(pwc, a2, a3);
*a1 = pwc[0];
return result;
}

original_code:
static
 inline
 int
mbtowi(wint_t *pwi, const char *s, size_t n)
{
 wchar_t wc;
 int i;
 i = mbtowc(&wc, s, n);
 *pwi = wc;
 return i;
}

canonical_original_code:
static inline int mbtowi(unsigned int *pwi, char *s, unsigned long n)
{
 int wc;
 int i;
 i = mbtowc(&wc, s, n);
 *pwi = wc;
 return i;
}

variable_types:
pwi
unsigned int *

variable_types:
s
char *

variable_types:
n
unsigned long

variable_types: wc int


gmatch

variable_types:
p
char *

variable_types:
bs
char *

variable_types:
c
unsigned int

variable_types:
scc
unsigned int

variable_types: n int

variable_types: ok int

variable_types: excl int

variable_types:
lc
unsigned long

variable_types:
bp
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // rsp
pthread_t *v4; // r14
__int64 v5; // rbx
__int64 v6; // rbx
_QWORD v8[4]; // [rsp+0h] [rbp-20h] BYREF

if ( argc > 1 )
{
if ( atoi(argv[1]) == 1 )
numberPhilosophers = 5;
else
numberPhilosophers = atoi(argv[1]);
}
else
{
numberPhilosophers = 5;
}
puts("Initiating Dining Philosophers");
bodyCount = numberPhilosophers;
v3 = alloca(8LL * numberPhilosophers);
if ( numberPhilosophers > 0 )
{
v4 = v8;
v5 = 0LL;
do
{
philosopherLocation[v5] = v5;
pthread_mutex_init(&chopsticks[v5], 0LL);
pthread_create(v4++, 0LL, (void *(*)(void *))&transitions, &philosopherLocation[v5++]);
}
while ( numberPhilosophers > (int)v5 );
if ( numberPhilosophers > 0 )
{
v6 = 0LL;
do
pthread_join(v8[v6++], 0LL);
while ( numberPhilosophers > (int)v6 );
}
}
return 0;
}

original_code:
int main(int argc, char** argv) {
   if(argc < 2){
      numberPhilosophers = 5;
   }
   else if(atoi(argv[1]) == 1){
      numberPhilosophers = 5;
   }
   else{
      numberPhilosophers = atoi(argv[1]);
   }
   printf("Initiating Dining Philosophers\n");
   int i;
   bodyCount = numberPhilosophers;
   pthread_t philosophers[numberPhilosophers];
   for(i = 0 ; i < numberPhilosophers ; i++){
      philosopherLocation[i] = i;
      pthread_mutex_init(&chopsticks[i], ((void *)0));
      pthread_create(&philosophers[i], ((void *)0),transitions,&philosopherLocation[i]);
   }
   for (i = 0; i < numberPhilosophers; i++) {
      pthread_join(philosophers[i], ((void *)0));
   }
   return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
   if(argc < 2){
      numberPhilosophers = 5;
   }
   else if(atoi(argv[1]) == 1){
      numberPhilosophers = 5;
   }
   else{
      numberPhilosophers = atoi(argv[1]);
   }
   printf("Initiating Dining Philosophers\n");
   int i;
   bodyCount = numberPhilosophers;
   unsigned long philosophers[-1];
   for(i = 0 ; i < numberPhilosophers ; i++){
      philosopherLocation[i] = i;
      pthread_mutex_init(&chopsticks[i], ((void *)0));
      pthread_create(&philosophers[i], ((void *)0),transitions,&philosopherLocation[i]);
   }
   for (i = 0; i < numberPhilosophers; i++) {
      pthread_join(philosophers[i], ((void *)0));
   }
   return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types:
philosophers
unsigned long [-1]


ponder

decompiled_code:
__int64 __fastcall ponder(int a1)
{
int v1; // edx
__int64 result; // rax

randomwait((unsigned int)bodyCount);
v1 = rand();
result = (unsigned int)(50 * (v1 / 50));
if ( v1 % 50 > 20 )
philosopherStatus[a1] = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // edx
__int64 result; // rax

randomwait((unsigned int)bodyCount);
v1 = rand();
result = (unsigned int)(50 * (v1 / 50));
if ( v1 % 50 > 20 )
philosopherStatus[a1] = 1;
return result;
}

original_code:
void ponder (int philosopher) {
   randomwait(bodyCount);
   if( rand() % 50 > 20){
      philosopherStatus[philosopher] = 1;
   }
}

canonical_original_code:
void ponder(int philosopher) {
   randomwait(bodyCount);
   if( rand() % 50 > 20){
      philosopherStatus[philosopher] = 1;
   }
}

variable_types: philosopher int


startEating

decompiled_code:
__int64 __fastcall startEating(unsigned int a1)
{
if ( rand() % 50 > 20 )
{
chopstickGrab(a1);
chopstickGrab((unsigned int)((int)(a1 + 1) % bodyCount));
philosopherStatus[a1] = 2;
}
return randomwait((unsigned int)bodyCount);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
if ( rand() % 50 > 20 )
{
chopstickGrab(a1);
chopstickGrab((unsigned int)((int)(a1 + 1) % bodyCount));
philosopherStatus[a1] = 2;
}
return randomwait((unsigned int)bodyCount);
}

original_code:
void startEating (int philosopher) {
   if( rand() % 50 > 20){
      chopstickGrab(philosopher);
      chopstickGrab((philosopher + 1) % bodyCount);
      philosopherStatus[philosopher] = 2;
   }
   randomwait(bodyCount);
}

canonical_original_code:
void startEating(int philosopher) {
   if( rand() % 50 > 20){
      chopstickGrab(philosopher);
      chopstickGrab((philosopher + 1) % bodyCount);
      philosopherStatus[philosopher] = 2;
   }
   randomwait(bodyCount);
}


finishEating

decompiled_code:
__int64 __fastcall finishEating(unsigned int a1)
{
int v1; // edx
__int64 result; // rax

v1 = rand();
result = (unsigned int)(50 * (v1 / 50));
if ( v1 % 50 > 20 )
{
chopstickRelease(a1);
result = chopstickRelease((unsigned int)((int)(a1 + 1) % bodyCount));
philosopherStatus[a1] = 0;
}
return result;
}

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

v1 = rand();
result = (unsigned int)(50 * (v1 / 50));
if ( v1 % 50 > 20 )
{
chopstickRelease(a1);
result = chopstickRelease((unsigned int)((int)(a1 + 1) % bodyCount));
philosopherStatus[a1] = 0;
}
return result;
}

original_code:
void finishEating (int philosopher) {
   if( rand() % 50 > 20){
      chopstickRelease(philosopher);
      chopstickRelease((philosopher + 1) % bodyCount);
      philosopherStatus[philosopher] = 0;
   }
}

canonical_original_code:
void finishEating(int philosopher) {
   if( rand() % 50 > 20){
      chopstickRelease(philosopher);
      chopstickRelease((philosopher + 1) % bodyCount);
      philosopherStatus[philosopher] = 0;
   }
}


transitions

decompiled_code:
void __fastcall __noreturn transitions(unsigned int *a1)
{
unsigned int v1; // ebp
int v2; // eax

v1 = *a1;
printPhilosophers();
while ( 1 )
{
printPhilosophers();
v2 = philosopherStatus[v1];
if ( v2 )
{
if ( v2 == 1 )
{
startEating(v1);
}
else if ( v2 == 2 )
{
finishEating(v1);
}
}
else
{
ponder(v1);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func3(unsigned int *a1)
{
unsigned int v1; // ebp
int v2; // eax

v1 = *a1;
printPhilosophers();
while ( 1 )
{
printPhilosophers();
v2 = philosopherStatus[v1];
if ( v2 )
{
if ( v2 == 1 )
{
func1(v1);
}
else if ( v2 == 2 )
{
func2(v1);
}
}
else
{
func0(v1);
}
}
}

original_code:
void* transitions(void* philosopher){
   int philosopherId = *(int*)philosopher;
   printPhilosophers();
   while(1){
      printPhilosophers();
      if(philosopherStatus[philosopherId] == 0){
         ponder(philosopherId);
      }
      else if(philosopherStatus[philosopherId] == 1){
         startEating(philosopherId);
      }
      else if(philosopherStatus[philosopherId] == 2){
         finishEating(philosopherId);
      }
   }
}

canonical_original_code:
void *transitions(void *philosopher){
   int philosopherId = *(int*)philosopher;
   printPhilosophers();
   while(1){
      printPhilosophers();
      if(philosopherStatus[philosopherId] == 0){
         ponder(philosopherId);
      }
      else if(philosopherStatus[philosopherId] == 1){
         startEating(philosopherId);
      }
      else if(philosopherStatus[philosopherId] == 2){
         finishEating(philosopherId);
      }
   }
}

variable_types:
philosopher
void *

variable_types: philosopherId int


randomwait

decompiled_code:
__int64 __fastcall randomwait(int a1)
{
unsigned int v1; // ebp

v1 = rand() % a1;
sleep(v1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // ebp

v1 = rand() % a1;
sleep(v1);
return v1;
}

original_code:
int randomwait(int bound) {
    int wait = rand() % bound;
    sleep(wait);
    return wait;
}

variable_types: bound int

variable_types: wait int


printPhilosophers

decompiled_code:
int printPhilosophers()
{
__int64 v0; // rbx
int v1; // eax

if ( bodyCount > 0 )
{
v0 = 0LL;
do
{
v1 = philosopherStatus[v0];
if ( v1 )
{
if ( v1 == 1 )
{
printf(" ! ");
}
else if ( v1 == 2 )
{
printf(" \\/ ");
}
}
else
{
printf(" ? ");
}
++v0;
}
while ( bodyCount > (int)v0 );
}
return putchar(10);
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rbx
int v1; // eax

if ( bodyCount > 0 )
{
v0 = 0LL;
do
{
v1 = philosopherStatus[v0];
if ( v1 )
{
if ( v1 == 1 )
{
printf(" ! ");
}
else if ( v1 == 2 )
{
printf(" \\/ ");
}
}
else
{
printf(" ? ");
}
++v0;
}
while ( bodyCount > (int)v0 );
}
return putchar(10);
}

original_code:
void printPhilosophers () {
   int i;
   for (i = 0; i < bodyCount; i++) {
      if (philosopherStatus[i] == 0) {
         printf(" ? ");
      } else if (philosopherStatus[i] == 1) {
         printf(" ! ");
      } else if (philosopherStatus[i] == 2) {
         printf(" \\/ ");
      }
   }
   printf("\n");
}

canonical_original_code:
void printPhilosophers() {
   int i;
   for (i = 0; i < bodyCount; i++) {
      if (philosopherStatus[i] == 0) {
         printf(" ? ");
      } else if (philosopherStatus[i] == 1) {
         printf(" ! ");
      } else if (philosopherStatus[i] == 2) {
         printf(" \\/ ");
      }
   }
   printf("\n");
}


chopstickGrab

decompiled_code:
int __fastcall chopstickGrab(int a1)
{
int result; // eax

result = pthread_mutex_lock(&chopsticks[a1]);
++chopstickStatus[a1];
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
int result; // eax

result = pthread_mutex_lock(&chopsticks[a1]);
++chopstickStatus[a1];
return result;
}

original_code:
void chopstickGrab (int chopstick){
   pthread_mutex_lock(&chopsticks[chopstick]);
   chopstickStatus[chopstick] += 1;
}

canonical_original_code:
void chopstickGrab(int chopstick){
   pthread_mutex_lock(&chopsticks[chopstick]);
   chopstickStatus[chopstick] += 1;
}

variable_types: chopstick int


chopstickRelease

decompiled_code:
int __fastcall chopstickRelease(int a1)
{
int result; // eax

result = pthread_mutex_unlock(&chopsticks[a1]);
--chopstickStatus[a1];
return result;
}

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

result = pthread_mutex_unlock(&chopsticks[a1]);
--chopstickStatus[a1];
return result;
}

original_code:
void chopstickRelease(int chopstick){
   pthread_mutex_unlock(&chopsticks[chopstick]);
   chopstickStatus[chopstick] -= 1;
}