runestrdup

decompiled_code:
void *__fastcall runestrdup(__int64 a1)
{
__int64 v1; // rax
void *result; // rax

v1 = runestrlen();
result = malloc(4 * v1 + 4);
if ( result )
result = (void *)runestrcpy(result, a1);
return result;
}

canonical_decompiled_code:
void *__fastcall func0(__int64 a1)
{
__int64 v1; // rax
void *result; // rax

v1 = runestrlen();
result = malloc(4 * v1 + 4);
if ( result )
result = (void *)runestrcpy(result, a1);
return result;
}

original_code:
Rune*
runestrdup(Rune *s)
{
 Rune *ns;
 ns = malloc(sizeof(Rune)*(runestrlen(s) + 1));
 if(ns == 0)
  return 0;
 return runestrcpy(ns, s);
}

canonical_original_code:
unsigned int *runestrdup(unsigned int *s)
{
 unsigned int *ns;
 ns = malloc(sizeof(Rune)*(runestrlen(s) + 1));
 if(ns == 0)
  return 0;
 return runestrcpy(ns, s);
}

variable_types:
s
unsigned int *

variable_types:
ns
unsigned int *


parsehead

decompiled_code:
__int64 parsehead()
{
__int64 v0; // rbx
int v1; // ebp
int v2; // er12

v0 = tzdata;
if ( *(_BYTE *)(tzdata + 4) != 50 && *(_BYTE *)(tzdata + 4) )
return 0xFFFFFFFFLL;
v1 = get4((unsigned __int8 *)(tzdata + 32));
z = v1;
v2 = get4((unsigned __int8 *)(v0 + 36));
dword_464 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
dword_468 = get4((unsigned __int8 *)(v0 + 40));
qword_470 = v0 + 44;
qword_478 = 4 * v1 + v0 + 44;
qword_480 = v1 + qword_478;
qword_488 = 6 * v2 + qword_480;
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rbx
int v1; // ebp
int v2; // er12

v0 = tzdata;
if ( *(_BYTE *)(tzdata + 4) != 50 && *(_BYTE *)(tzdata + 4) )
return 0xFFFFFFFFLL;
v1 = func0((unsigned __int8 *)(tzdata + 32));
z = v1;
v2 = func0((unsigned __int8 *)(v0 + 36));
dword_464 = v2;
if ( !v2 )
return 0xFFFFFFFFLL;
dword_468 = func0((unsigned __int8 *)(v0 + 40));
qword_470 = v0 + 44;
qword_478 = 4 * v1 + v0 + 44;
qword_480 = v1 + qword_478;
qword_488 = 6 * v2 + qword_480;
return 0LL;
}

original_code:
static
int
parsehead(void)
{
 uchar *p;
 int ver;
 ver = tzdata[4];
 if (ver!=0)
 if (ver!='2')
  return -1;
 p = tzdata + 4 + 1 + 15;
 z.timecnt = get4(p+3*4);
 z.typecnt = get4(p+4*4);
 if (z.typecnt==0)
  return -1;
 z.charcnt = get4(p+5*4);
 z.ptime = p+6*4;
 z.ptype = z.ptime + z.timecnt*4;
 z.ptt = z.ptype + z.timecnt;
 z.pzone = z.ptt + z.typecnt*TTinfosz;
 return 0;
}

canonical_original_code:
static int parsehead()
{
 unsigned char *p;
 int ver;
 ver = tzdata[4];
 if (ver!=0)
 if (ver!='2')
  return -1;
 p = tzdata + 4 + 1 + 15;
 z.timecnt = get4(p+3*4);
 z.typecnt = get4(p+4*4);
 if (z.typecnt==0)
  return -1;
 z.charcnt = get4(p+5*4);
 z.ptime = p+6*4;
 z.ptype = z.ptime + z.timecnt*4;
 z.ptt = z.ptype + z.timecnt;
 z.pzone = z.ptt + z.typecnt*TTinfosz;
 return 0;
}

variable_types:
p
unsigned char *

variable_types: ver int

return_type: int


decompiled_code:
__int64 __fastcall gett4(unsigned __int8 *a1)
{
__int64 result; // rax

result = get4(a1);
if ( result < 0 )
result = 0LL;
return result;
}

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

result = func0(a1);
if ( result < 0 )
result = 0LL;
return result;
}

original_code:
static
tlong
gett4(uchar *p)
{
 long l;
 l = get4(p);
 if (l<0)
  return 0;
 return l;
}

canonical_original_code:
static long gett4(unsigned char *p)
{
 long l;
 l = get4(p);
 if (l<0)
  return 0;
 return l;
}

variable_types: l long

return_type: long


readtzfile

decompiled_code:
__int64 __fastcall readtzfile(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
unsigned int v3; // ebx
__int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rax

v1 = p9open(a1, 0LL);
v2 = 0LL;
if ( v1 >= 0 )
{
v3 = v1;
v4 = dirfstat((unsigned int)v1);
v5 = v4;
if ( v4 )
{
v6 = p9malloc(*(_QWORD *)(v4 + 56));
v2 = v6;
if ( v6 )
readn(v3, v6, *(_QWORD *)(v5 + 56));
p9free(v5);
close(v3);
}
else
{
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // eax
__int64 v2; // rbp
unsigned int v3; // ebx
__int64 v4; // rax
__int64 v5; // r12
__int64 v6; // rax

v1 = p9open(a1, 0LL);
v2 = 0LL;
if ( v1 >= 0 )
{
v3 = v1;
v4 = dirfstat((unsigned int)v1);
v5 = v4;
if ( v4 )
{
v6 = p9malloc(*(_QWORD *)(v4 + 56));
v2 = v6;
if ( v6 )
readn(v3, v6, *(_QWORD *)(v5 + 56));
p9free(v5);
close(v3);
}
else
{
v2 = 0LL;
}
}
return v2;
}

original_code:
static
uchar*
readtzfile(char *file)
{
 uchar *p;
 int fd;
 Dir *d;
 fd = p9open(file, 0);
 if (fd<0)
  return ((void*)0);
 d = dirfstat(fd);
 if (d==((void*)0))
  return ((void*)0);
 p = p9malloc(d->length);
 if (p!=((void*)0))
  readn(fd, p, d->length);
 p9free(d);
 close(fd);
 return p;
}

canonical_original_code:
static unsigned char *readtzfile(char *file)
{
 unsigned char *p;
 int fd;
 struct Dir *d;
 fd = p9open(file, 0);
 if (fd<0)
  return ((void *)0);
 d = dirfstat(fd);
 if (d==((void *)0))
  return ((void *)0);
 p = p9malloc(d->length);
 if (p!=((void *)0))
  readn(fd, p, d->length);
 p9free(d);
 close(fd);
 return p;
}

variable_types:
file
char *

variable_types: fd int

variable_types: struct Dir { unsigned short type; unsigned int dev; struct Qid { unsigned long long path; unsigned long vers; unsigned char type; } qid; unsigned long mode; unsigned long atime; unsigned long mtime; long long length; char *name; char *uid; char *gid; char *muid; unsigned int uidnum; unsigned int gidnum; unsigned int muidnum; char *ext; } *

return_type: unsigned char *

user_defined_types: struct Dir { unsigned short type; unsigned int dev; struct Qid qid; unsigned long mode; unsigned long atime; unsigned long mtime; long long length; char *name; char *uid; char *gid; char *muid; unsigned int uidnum; unsigned int gidnum; unsigned int muidnum; char *ext; }


readtimezone

decompiled_code:
__int64 readtimezone()
{
__int64 result; // rax
bool v1; // cf
bool v2; // zf
__int64 v3; // rbx
const char *v4; // rsi
__int64 v5; // rcx
const char *v6; // rdi
__int64 v7; // rax
__int64 v8; // rbx

z = 0;
if ( zonefile )
{
LABEL_2:
result = readtzfile(zonefile);
tzdata = result;
v1 = 0;
v2 = result == 0;
if ( !result )
return result;
goto LABEL_3;
}
v7 = p9getenv("timezone");
v8 = v7;
if ( !v7 )
{
zonefile = (__int64)"/etc/localtime";
goto LABEL_2;
}
tzdata = readtzfile(v7);
p9free(v8);
LABEL_3:
v3 = tzdata;
v4 = "TZif";
v5 = 4LL;
v6 = (const char *)tzdata;
do
{
if ( !v5 )
break;
v1 = *v4 < (unsigned int)*v6;
v2 = *v4++ == *v6++;
--v5;
}
while ( v2 );
if ( (!v1 && !v2) != v1 || (result = parsehead(v6, v4), (_DWORD)result == -1) )
{
result = p9free(v3);
tzdata = 0LL;
z = 0;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
bool v1; // cf
bool v2; // zf
__int64 v3; // rbx
const char *v4; // rsi
__int64 v5; // rcx
const char *v6; // rdi
__int64 v7; // rax
__int64 v8; // rbx

z = 0;
if ( zonefile )
{
LABEL_2:
result = func3(zonefile);
tzdata = result;
v1 = 0;
v2 = result == 0;
if ( !result )
return result;
goto LABEL_3;
}
v7 = p9getenv("timezone");
v8 = v7;
if ( !v7 )
{
zonefile = (__int64)"/etc/localtime";
goto LABEL_2;
}
tzdata = func3(v7);
p9free(v8);
LABEL_3:
v3 = tzdata;
v4 = "TZif";
v5 = 4LL;
v6 = (const char *)tzdata;
do
{
if ( !v5 )
break;
v1 = *v4 < (unsigned int)*v6;
v2 = *v4++ == *v6++;
--v5;
}
while ( v2 );
if ( (!v1 && !v2) != v1 || (result = func1(v6, v4), (_DWORD)result == -1) )
{
result = p9free(v3);
tzdata = 0LL;
z = 0;
}
return result;
}

original_code:
static
void
readtimezone(void)
{
 char *tmp;
 z.timecnt = 0;
 if(zonefile==((void*)0)) {
  if ((tmp=p9getenv("timezone"))!=((void*)0)) {
   tzdata = readtzfile(tmp);
   p9free(tmp);
   goto havedata;
  }
  zonefile = "/etc/localtime";
 }
 tzdata = readtzfile(zonefile);
 if (tzdata==((void*)0))
  return;
havedata:
 if (strncmp("TZif", (char*)tzdata, 4)!=0)
  goto errfree;
 if (parsehead()==-1) {
 errfree:
  p9free(tzdata);
  tzdata = ((void*)0);
  z.timecnt = 0;
  return;
 }
}

canonical_original_code:
static void readtimezone()
{
 char *tmp;
 z.timecnt = 0;
 if(zonefile==((void *)0)) {
  if ((tmp=p9getenv("timezone"))!=((void *)0)) {
   tzdata = readtzfile(tmp);
   p9free(tmp);
   goto havedata;
  }
  zonefile = "/etc/localtime";
 }
 tzdata = readtzfile(zonefile);
 if (tzdata==((void *)0))
  return;
havedata:
 if (strncmp("TZif", (char *)tzdata, 4)!=0)
  goto errfree;
 if (parsehead()==-1) {
 errfree:
  p9free(tzdata);
  tzdata = ((void *)0);
  z.timecnt = 0;
  return;
 }
}

variable_types:
tmp
char *

return_type: void


ttinfo

decompiled_code:
__int64 __fastcall ttinfo(__int64 a1, int a2)
{
int v2; // eax
unsigned __int8 *v3; // rbx
unsigned __int8 v4; // al
__int64 result; // rax

v2 = *(unsigned __int8 *)(qword_478 + a2);
if ( dword_464 <= v2 )
_assert_fail("i<z.typecnt", "zoneinfo.c", 0x6Au, "ttinfo");
v3 = (unsigned __int8 *)(qword_480 + 6 * v2);
*(_DWORD *)(a1 + 8) = get4(v3);
*(_DWORD *)(a1 + 12) = v3[4];
v4 = v3[5];
if ( v4 >= dword_468 )
_assert_fail("p[5]<z.charcnt", "zoneinfo.c", 0x6Eu, "ttinfo");
result = qword_488 + v4;
*(_QWORD *)(a1 + 16) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
int v2; // eax
unsigned __int8 *v3; // rbx
unsigned __int8 v4; // al
__int64 result; // rax

v2 = *(unsigned __int8 *)(qword_478 + a2);
if ( dword_464 <= v2 )
_assert_fail("i<z.typecnt", "zoneinfo.c", 0x6Au, "ttinfo");
v3 = (unsigned __int8 *)(qword_480 + 6 * v2);
*(_DWORD *)(a1 + 8) = func0(v3);
*(_DWORD *)(a1 + 12) = v3[4];
v4 = v3[5];
if ( v4 >= dword_468 )
_assert_fail("p[5]<z.charcnt", "zoneinfo.c", 0x6Eu, "ttinfo");
result = qword_488 + v4;
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
static
void
ttinfo(Tinfo *ti, int tti)
{
 uchar *p;
 int i;
 i = z.ptype[tti];
 ((void) sizeof ((i<z.typecnt) ? 1 : 0), __extension__ ({ if (i<z.typecnt) ; else __assert_fail ("i<z.typecnt", "zoneinfo.c", 106, __extension__ __PRETTY_FUNCTION__); }));
 p = z.ptt + i*TTinfosz;
 ti->tzoff = get4(p);
 ti->dlflag = p[4];
 ((void) sizeof ((p[5]<z.charcnt) ? 1 : 0), __extension__ ({ if (p[5]<z.charcnt) ; else __assert_fail ("p[5]<z.charcnt", "zoneinfo.c", 110, __extension__ __PRETTY_FUNCTION__); }));
 ti->zone = (char*)z.pzone + p[5];
}

canonical_original_code:
static void ttinfo(struct Tinfo *ti, int tti)
{
 unsigned char *p;
 int i;
 i = z.ptype[tti];
 ((void) sizeof ((i<z.typecnt) ? 1 : 0), __extension__ ({ if (i<z.typecnt) ; else __assert_fail ("i<z.typecnt", "zoneinfo.c", 106, __extension__ __PRETTY_FUNCTION__); }));
 p = z.ptt + i*TTinfosz;
 ti->tzoff = get4(p);
 ti->dlflag = p[4];
 ((void) sizeof ((p[5]<z.charcnt) ? 1 : 0), __extension__ ({ if (p[5]<z.charcnt) ; else __assert_fail ("p[5]<z.charcnt", "zoneinfo.c", 110, __extension__ __PRETTY_FUNCTION__); }));
 ti->zone = (char *)z.pzone + p[5];
}

variable_types: struct Tinfo { long t; int tzoff; int dlflag; char *zone; } *

variable_types: tti int

variable_types: i int


tzfile

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

if ( tzdata )
{
result = p9free(tzdata);
tzdata = 0LL;
}
z = 0;
zonefile = a1;
return result;
}

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

if ( tzdata )
{
result = p9free(tzdata);
tzdata = 0LL;
}
z = 0;
zonefile = a1;
return result;
}

original_code:
void
tzfile(char *f)
{
 if (tzdata!=((void*)0)) {
  p9free(tzdata);
  tzdata = ((void*)0);
 }
 z.timecnt = 0;
 zonefile = f;
}

canonical_original_code:
void tzfile(char *f)
{
 if (tzdata!=((void *)0)) {
  p9free(tzdata);
  tzdata = ((void *)0);
 }
 z.timecnt = 0;
 zonefile = f;
}

variable_types:
f
char *


decompiled_code:
int __fastcall p9pipe(int fds[2])
{
return socketpair(1, 1, 0, fds);
}

canonical_decompiled_code:
int __fastcall func0(int fds[2])
{
return socketpair(1, 1, 0, fds);
}

original_code:
int
p9pipe(int fd[2])
{
 return socketpair(1, SOCK_STREAM, 0, fd);
}

variable_types:
fd
int [2]


statcheck

decompiled_code:
__int64 __fastcall statcheck(unsigned __int16 *a1, unsigned int a2)
{
unsigned __int64 v2; // rdx
unsigned __int16 *v3; // rdi
int v4; // ecx

v2 = (unsigned __int64)a1 + a2;
if ( a2 <= 0x30 )
return 0xFFFFFFFFLL;
if ( *a1 + 2 != a2 )
return 0xFFFFFFFFLL;
if ( v2 < (unsigned __int64)a1 + 43 )
return 0xFFFFFFFFLL;
v3 = (unsigned __int16 *)((char *)a1 + *(unsigned __int16 *)((char *)a1 + 41) + 43);
v4 = 3;
while ( v2 >= (unsigned __int64)(v3 + 1) )
{
v3 = (unsigned __int16 *)((char *)v3 + *v3 + 2);
if ( !--v4 )
return (unsigned int)-(v2 != (_QWORD)v3);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int16 *a1, unsigned int a2)
{
unsigned __int64 v2; // rdx
unsigned __int16 *v3; // rdi
int v4; // ecx

v2 = (unsigned __int64)a1 + a2;
if ( a2 <= 0x30 )
return 0xFFFFFFFFLL;
if ( *a1 + 2 != a2 )
return 0xFFFFFFFFLL;
if ( v2 < (unsigned __int64)a1 + 43 )
return 0xFFFFFFFFLL;
v3 = (unsigned __int16 *)((char *)a1 + *(unsigned __int16 *)((char *)a1 + 41) + 43);
v4 = 3;
while ( v2 >= (unsigned __int64)(v3 + 1) )
{
v3 = (unsigned __int16 *)((char *)v3 + *v3 + 2);
if ( !--v4 )
return (unsigned int)-(v2 != (_QWORD)v3);
}
return 0xFFFFFFFFLL;
}

canonical_original_code:
int statcheck(unsigned char *buf, unsigned int nbuf)
{
 unsigned char *ebuf;
 int i; int nstr;
 ebuf = buf + nbuf;
 if(nbuf < (2 +(1 +4 +8)+5*2 +4*4 +1*8) || nbuf != 2 + ((buf)[0]|((buf)[1]<<8)))
  return -1;
 buf += (2 +(1 +4 +8)+5*2 +4*4 +1*8) - 4 * 2;
 nstr = 4;
 for(i = 0; i < nstr; i++){
  if(buf + 2 > ebuf)
   return -1;
  buf += 2 + ((buf)[0]|((buf)[1]<<8));
 }
 if(buf != ebuf)
  return -1;
 return 0;
}

variable_types:
buf
unsigned char *

variable_types:
nbuf
unsigned int

variable_types:
ebuf
unsigned char *

variable_types: nstr int


variable_types:
strs
char *

variable_types:
sv
char *[5]

variable_types: ns int

return_type: unsigned int

user_defined_types: struct Qid { unsigned long long path; unsigned long vers; unsigned char type; }


original_code:
static int
regexec1(Reprog *progp,
 char *bol,
 Resub *mp,
 int ms,
 Reljunk *j
)
{
 int flag=0;
 Reinst *inst;
 Relist *tlp;
 char *s;
 int i, checkstart;
 Rune r, *rp, *ep;
 int n;
 Relist* tl;
 Relist* nl;
 Relist* tle;
 Relist* nle;
 int match;
 char *p;
 match = 0;
 checkstart = j->starttype;
 if(mp)
  for(i=0; i<ms; i++) {
   mp[i].s.sp = 0;
   mp[i].e.ep = 0;
  }
 j->relist[0][0].inst = 0;
 j->relist[1][0].inst = 0;
 s = j->starts;
 do{
  if(checkstart) {
   switch(j->starttype) {
   case 0177:
    p = utfrune(s, j->startchar);
    if(p == 0 || s == j->eol)
     return match;
    s = p;
    break;
   case 0303:
    if(s == bol)
     break;
    p = utfrune(s, '\n');
    if(p == 0 || s == j->eol)
     return match;
    s = p+1;
    break;
   }
  }
  r = *(__reuchar*)s;
  if(r < Runeself)
   n = 1;
  else
   n = chartorune(&r, s);
  tl = j->relist[flag];
  tle = j->reliste[flag];
  nl = j->relist[flag^=1];
  nle = j->reliste[flag];
  nl->inst = 0;
  if(match == 0)
   _renewemptythread(tl, progp->startinst, ms, s);
  for(tlp=tl; tlp->inst; tlp++){
   for(inst = tlp->inst; ; inst = inst->u2.next){
    switch(inst->type){
    case 0177:
     if(inst->u1.r == r){
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     }
     break;
    case 0202:
     tlp->se.m[inst->u1.subid].s.sp = s;
     continue;
    case 0201:
     tlp->se.m[inst->u1.subid].e.ep = s;
     continue;
    case 0300:
     if(r != '\n')
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0301:
     if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0303:
     if(s == bol || *(s-1) == '\n')
      continue;
     break;
    case 0304:
     if(s == j->eol || r == 0 || r == '\n')
      continue;
     break;
    case 0305:
     ep = inst->u1.cp->end;
     for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
      if(r >= rp[0] && r <= rp[1]){
       if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
        return -1;
       break;
      }
     break;
    case 0306:
     ep = inst->u1.cp->end;
     for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
      if(r >= rp[0] && r <= rp[1])
       break;
     if(rp == ep)
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0203:
     if(_renewthread(tlp, inst->u1.right, ms, &tlp->se) == tle)
      return -1;
     continue;
    case 0377:
     match = 1;
     tlp->se.m[0].e.ep = s;
     if(mp != 0)
      _renewmatch(mp, ms, &tlp->se);
     break;
    }
    break;
   }
  }
  if(s == j->eol)
   break;
  checkstart = j->starttype && nl->inst==0;
  s += n;
 }while(r);
 return match;
}

canonical_original_code:
static int regexec1(struct Reprog *progp, char *bol, struct Resub *mp, int ms, struct Reljunk *j)
{
 int flag = 0;
 struct Reinst *inst;
 struct Relist *tlp;
 char *s;
 int i; int checkstart;
 unsigned int r; unsigned int *rp; unsigned int *ep;
 int n;
 struct Relist *tl;
 struct Relist *nl;
 struct Relist *tle;
 struct Relist *nle;
 int match;
 char *p;
 match = 0;
 checkstart = j->starttype;
 if(mp)
  for(i=0; i<ms; i++) {
   mp[i].s.sp = 0;
   mp[i].e.ep = 0;
  }
 j->relist[0][0].inst = 0;
 j->relist[1][0].inst = 0;
 s = j->starts;
 do{
  if(checkstart) {
   switch(j->starttype) {
   case 0177:
    p = utfrune(s, j->startchar);
    if(p == 0 || s == j->eol)
     return match;
    s = p;
    break;
   case 0303:
    if(s == bol)
     break;
    p = utfrune(s, '\n');
    if(p == 0 || s == j->eol)
     return match;
    s = p+1;
    break;
   }
  }
  r = *(unsigned char *)s;
  if(r < Runeself)
   n = 1;
  else
   n = chartorune(&r, s);
  tl = j->relist[flag];
  tle = j->reliste[flag];
  nl = j->relist[flag^=1];
  nle = j->reliste[flag];
  nl->inst = 0;
  if(match == 0)
   _renewemptythread(tl, progp->startinst, ms, s);
  for(tlp=tl; tlp->inst; tlp++){
   for(inst = tlp->inst; ; inst = inst->u2.next){
    switch(inst->type){
    case 0177:
     if(inst->u1.r == r){
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     }
     break;
    case 0202:
     tlp->se.m[inst->u1.subid].s.sp = s;
     continue;
    case 0201:
     tlp->se.m[inst->u1.subid].e.ep = s;
     continue;
    case 0300:
     if(r != '\n')
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0301:
     if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0303:
     if(s == bol || *(s-1) == '\n')
      continue;
     break;
    case 0304:
     if(s == j->eol || r == 0 || r == '\n')
      continue;
     break;
    case 0305:
     ep = inst->u1.cp->end;
     for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
      if(r >= rp[0] && r <= rp[1]){
       if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
        return -1;
       break;
      }
     break;
    case 0306:
     ep = inst->u1.cp->end;
     for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
      if(r >= rp[0] && r <= rp[1])
       break;
     if(rp == ep)
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0203:
     if(_renewthread(tlp, inst->u1.right, ms, &tlp->se) == tle)
      return -1;
     continue;
    case 0377:
     match = 1;
     tlp->se.m[0].e.ep = s;
     if(mp != 0)
      _renewmatch(mp, ms, &tlp->se);
     break;
    }
    break;
   }
  }
  if(s == j->eol)
   break;
  checkstart = j->starttype && nl->inst==0;
  s += n;
 }while(r);
 return match;
}

variable_types: struct Reprog { struct Reinst { int type; union { struct Reclass { unsigned int *end; unsigned int spans[64]; } *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; } *startinst; struct Reclass class[16]; struct Reinst firstinst[5]; } *

variable_types:
bol
char *

variable_types: struct Resub { union { char *sp; unsigned int *rsp; } s; union { char *ep; unsigned int *rep; } e; } *

variable_types: ms int

variable_types: struct Reljunk { struct Relist { struct Reinst *inst; struct Resublist { struct Resub m[32]; } se; } *relist[2]; struct Relist *reliste[2]; int starttype; unsigned int startchar; char *starts; char *eol; unsigned int *rstarts; unsigned int *reol; } *

variable_types: flag int

variable_types: struct Relist { struct Reinst { int type; union { struct Reclass { unsigned int *end; unsigned int spans[64]; } *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; } *inst; struct Resublist { struct Resub { union { char *sp; unsigned int *rsp; } s; union { char *ep; unsigned int *rep; } e; } m[32]; } se; } *

variable_types:
s
char *

variable_types: checkstart int

variable_types:
r
unsigned int

variable_types:
rp
unsigned int *

variable_types:
ep
unsigned int *

variable_types: n int

variable_types: match int

variable_types:
p
char *

user_defined_types: struct Reprog { struct Reinst *startinst; struct Reclass class[16]; struct Reinst firstinst[5]; }

user_defined_types: struct Reljunk { struct Relist *relist[2]; struct Relist *reliste[2]; int starttype; unsigned int startchar; char *starts; char *eol; unsigned int *rstarts; unsigned int *reol; }

user_defined_types: struct Reinst { int type; union { struct Reclass *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; }

user_defined_types: struct Relist { struct Reinst *inst; struct Resublist se; }


original_code:
static int
regexec2(Reprog *progp,
 char *bol,
 Resub *mp,
 int ms,
 Reljunk *j
)
{
 int rv;
 Relist *relist0, *relist1;
 relist0 = p9malloc((25*10)*sizeof(Relist));
 if(relist0 == ((void*)0))
  return -1;
 relist1 = p9malloc((25*10)*sizeof(Relist));
 if(relist1 == ((void*)0)){
  p9free(relist1);
  return -1;
 }
 j->relist[0] = relist0;
 j->relist[1] = relist1;
 j->reliste[0] = relist0 + (25*10) - 2;
 j->reliste[1] = relist1 + (25*10) - 2;
 rv = regexec1(progp, bol, mp, ms, j);
 p9free(relist0);
 p9free(relist1);
 return rv;
}

canonical_original_code:
static int regexec2(struct Reprog *progp, char *bol, struct Resub *mp, int ms, struct Reljunk *j)
{
 int rv;
 struct Relist *relist0; struct Relist *relist1;
 relist0 = p9malloc((25*10)*sizeof(Relist));
 if(relist0 == ((void *)0))
  return -1;
 relist1 = p9malloc((25*10)*sizeof(Relist));
 if(relist1 == ((void *)0)){
  p9free(relist1);
  return -1;
 }
 j->relist[0] = relist0;
 j->relist[1] = relist1;
 j->reliste[0] = relist0 + (25*10) - 2;
 j->reliste[1] = relist1 + (25*10) - 2;
 rv = regexec1(progp, bol, mp, ms, j);
 p9free(relist0);
 p9free(relist1);
 return rv;
}

variable_types: rv int

user_defined_types: struct Resub { union { char *sp; unsigned int *rsp; } s; union { char *ep; unsigned int *rep; } e; }

user_defined_types: struct Resublist { struct Resub m[32]; }

user_defined_types: struct Reclass { unsigned int *end; unsigned int spans[64]; }


original_code:
extern int
regexec9(Reprog *progp,
 char *bol,
 Resub *mp,
 int ms)
{
 Reljunk j;
 Relist relist0[10], relist1[10];
 int rv;
 j.starts = bol;
 j.eol = 0;
 if(mp && ms>0){
  if(mp->s.sp)
   j.starts = mp->s.sp;
  if(mp->e.ep)
   j.eol = mp->e.ep;
 }
 j.starttype = 0;
 j.startchar = 0;
 if(progp->startinst->type == 0177 && progp->startinst->u1.r < Runeself) {
  j.starttype = 0177;
  j.startchar = progp->startinst->u1.r;
 }
 if(progp->startinst->type == 0303)
  j.starttype = 0303;
 j.relist[0] = relist0;
 j.relist[1] = relist1;
 j.reliste[0] = relist0 + (sizeof(relist0)/sizeof((relist0)[0])) - 2;
 j.reliste[1] = relist1 + (sizeof(relist1)/sizeof((relist1)[0])) - 2;
 rv = regexec1(progp, bol, mp, ms, &j);
 if(rv >= 0)
  return rv;
 rv = regexec2(progp, bol, mp, ms, &j);
 if(rv >= 0)
  return rv;
 return -1;
}

canonical_original_code:
extern int regexec9(struct Reprog *progp, char *bol, struct Resub *mp, int ms)
{
 struct Reljunk j;
 struct Relist relist0[10]; struct Relist relist1[10];
 int rv;
 j.starts = bol;
 j.eol = 0;
 if(mp && ms>0){
  if(mp->s.sp)
   j.starts = mp->s.sp;
  if(mp->e.ep)
   j.eol = mp->e.ep;
 }
 j.starttype = 0;
 j.startchar = 0;
 if(progp->startinst->type == 0177 && progp->startinst->u1.r < Runeself) {
  j.starttype = 0177;
  j.startchar = progp->startinst->u1.r;
 }
 if(progp->startinst->type == 0303)
  j.starttype = 0303;
 j.relist[0] = relist0;
 j.relist[1] = relist1;
 j.reliste[0] = relist0 + (sizeof(relist0)/sizeof((relist0)[0])) - 2;
 j.reliste[1] = relist1 + (sizeof(relist1)/sizeof((relist1)[0])) - 2;
 rv = regexec1(progp, bol, mp, ms, &j);
 if(rv >= 0)
  return rv;
 rv = regexec2(progp, bol, mp, ms, &j);
 if(rv >= 0)
  return rv;
 return -1;
}

variable_types: struct Reljunk { struct Relist { struct Reinst { int type; union { struct Reclass { unsigned int *end; unsigned int spans[64]; } *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; } *inst; struct Resublist { struct Resub { union { char *sp; unsigned int *rsp; } s; union { char *ep; unsigned int *rep; } e; } m[32]; } se; } *relist[2]; struct Relist *reliste[2]; int starttype; unsigned int startchar; char *starts; char *eol; unsigned int *rstarts; unsigned int *reol; }

variable_types: struct Relist { struct Reinst { int type; union { struct Reclass { unsigned int *end; unsigned int spans[64]; } *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; } *inst; struct Resublist { struct Resub { union { char *sp; unsigned int *rsp; } s; union { char *ep; unsigned int *rep; } e; } m[32]; } se; } [10]


fmtfdflush

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

if ( (int)_fmtFdFlush() <= 0 )
result = 0xFFFFFFFFLL;
else
result = *(unsigned int *)(a1 + 48);
return result;
}

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

if ( (int)_fmtFdFlush() <= 0 )
result = 0xFFFFFFFFLL;
else
result = *(unsigned int *)(a1 + 48);
return result;
}

original_code:
int
fmtfdflush(Fmt *f)
{
 if(__fmtFdFlush(f) <= 0)
  return -1;
 return f->nfmt;
}

canonical_original_code:
int fmtfdflush(struct Fmt *f)
{
 if(__fmtFdFlush(f) <= 0)
  return -1;
 return f->nfmt;
}

variable_types: struct Fmt { unsigned char runes; void *start; void *to; void *stop; int (*flush)(struct Fmt *); void *farg; int nfmt; __builtin_va_list args; unsigned int r; int width; int prec; unsigned long flags; char *decimal; char *thousands; char *grouping; } *


fmtfdinit

original_code:
int
fmtfdinit(Fmt *f, int fd, char *buf, int size)
{
 f->runes = 0;
 f->start = buf;
 f->to = buf;
 f->stop = buf + size;
 f->flush = __fmtFdFlush;
 f->farg = (void*)(uintptr_t)fd;
 f->flags = 0;
 f->nfmt = 0;
 fmtlocaleinit(f, 0, 0, 0);
 return 0;
}

canonical_original_code:
int fmtfdinit(struct Fmt *f, int fd, char *buf, int size)
{
 f->runes = 0;
 f->start = buf;
 f->to = buf;
 f->stop = buf + size;
 f->flush = __fmtFdFlush;
 f->farg = (void *)(unsigned long)fd;
 f->flags = 0;
 f->nfmt = 0;
 fmtlocaleinit(f, 0, 0, 0);
 return 0;
}

variable_types: fd int

variable_types:
buf
char *

variable_types: size int

user_defined_types: struct Fmt { unsigned char runes; void *start; void *to; void *stop; int (*flush)(struct Fmt *); void *farg; int nfmt; __builtin_va_list args; unsigned int r; int width; int prec; unsigned long flags; char *decimal; char *thousands; char *grouping; }


original_code:
static int
rregexec1(Reprog *progp,
 Rune *bol,
 Resub *mp,
 int ms,
 Reljunk *j)
{
 int flag=0;
 Reinst *inst;
 Relist *tlp;
 Rune *s;
 int i, checkstart;
 Rune r, *rp, *ep;
 Relist* tl;
 Relist* nl;
 Relist* tle;
 Relist* nle;
 int match;
 Rune *p;
 match = 0;
 checkstart = j->startchar;
 if(mp)
  for(i=0; i<ms; i++) {
   mp[i].s.rsp = 0;
   mp[i].e.rep = 0;
  }
 j->relist[0][0].inst = 0;
 j->relist[1][0].inst = 0;
 s = j->rstarts;
 do{
  if(checkstart) {
   switch(j->starttype) {
   case 0177:
    p = runestrchr(s, j->startchar);
    if(p == 0 || p == j->reol)
     return match;
    s = p;
    break;
   case 0303:
    if(s == bol)
     break;
    p = runestrchr(s, '\n');
    if(p == 0 || s == j->reol)
     return match;
    s = p+1;
    break;
   }
  }
  r = *s;
  tl = j->relist[flag];
  tle = j->reliste[flag];
  nl = j->relist[flag^=1];
  nle = j->reliste[flag];
  nl->inst = 0;
  _rrenewemptythread(tl, progp->startinst, ms, s);
  for(tlp=tl; tlp->inst; tlp++){
   for(inst=tlp->inst; ; inst = inst->u2.next){
    switch(inst->type){
    case 0177:
     if(inst->u1.r == r)
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0202:
     tlp->se.m[inst->u1.subid].s.rsp = s;
     continue;
    case 0201:
     tlp->se.m[inst->u1.subid].e.rep = s;
     continue;
    case 0300:
     if(r != '\n')
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0301:
     if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0303:
     if(s == bol || *(s-1) == '\n')
      continue;
     break;
    case 0304:
     if(s == j->reol || r == 0 || r == '\n')
      continue;
     break;
    case 0305:
     ep = inst->u1.cp->end;
     for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
      if(r >= rp[0] && r <= rp[1]){
       if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
        return -1;
       break;
      }
     break;
    case 0306:
     ep = inst->u1.cp->end;
     for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
      if(r >= rp[0] && r <= rp[1])
       break;
     if(rp == ep)
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0203:
     if(_renewthread(tlp, inst->u1.right, ms, &tlp->se) == tle)
      return -1;
     continue;
    case 0377:
     match = 1;
     tlp->se.m[0].e.rep = s;
     if(mp != 0)
      _renewmatch(mp, ms, &tlp->se);
     break;
    }
    break;
   }
  }
  if(s == j->reol)
   break;
  checkstart = j->startchar && nl->inst==0;
  s++;
 }while(r);
 return match;
}

canonical_original_code:
static int rregexec1(struct Reprog *progp, unsigned int *bol, struct Resub *mp, int ms, struct Reljunk *j)
{
 int flag = 0;
 struct Reinst *inst;
 struct Relist *tlp;
 unsigned int *s;
 int i; int checkstart;
 unsigned int r; unsigned int *rp; unsigned int *ep;
 struct Relist *tl;
 struct Relist *nl;
 struct Relist *tle;
 struct Relist *nle;
 int match;
 unsigned int *p;
 match = 0;
 checkstart = j->startchar;
 if(mp)
  for(i=0; i<ms; i++) {
   mp[i].s.rsp = 0;
   mp[i].e.rep = 0;
  }
 j->relist[0][0].inst = 0;
 j->relist[1][0].inst = 0;
 s = j->rstarts;
 do{
  if(checkstart) {
   switch(j->starttype) {
   case 0177:
    p = runestrchr(s, j->startchar);
    if(p == 0 || p == j->reol)
     return match;
    s = p;
    break;
   case 0303:
    if(s == bol)
     break;
    p = runestrchr(s, '\n');
    if(p == 0 || s == j->reol)
     return match;
    s = p+1;
    break;
   }
  }
  r = *s;
  tl = j->relist[flag];
  tle = j->reliste[flag];
  nl = j->relist[flag^=1];
  nle = j->reliste[flag];
  nl->inst = 0;
  _rrenewemptythread(tl, progp->startinst, ms, s);
  for(tlp=tl; tlp->inst; tlp++){
   for(inst=tlp->inst; ; inst = inst->u2.next){
    switch(inst->type){
    case 0177:
     if(inst->u1.r == r)
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0202:
     tlp->se.m[inst->u1.subid].s.rsp = s;
     continue;
    case 0201:
     tlp->se.m[inst->u1.subid].e.rep = s;
     continue;
    case 0300:
     if(r != '\n')
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0301:
     if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0303:
     if(s == bol || *(s-1) == '\n')
      continue;
     break;
    case 0304:
     if(s == j->reol || r == 0 || r == '\n')
      continue;
     break;
    case 0305:
     ep = inst->u1.cp->end;
     for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
      if(r >= rp[0] && r <= rp[1]){
       if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
        return -1;
       break;
      }
     break;
    case 0306:
     ep = inst->u1.cp->end;
     for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
      if(r >= rp[0] && r <= rp[1])
       break;
     if(rp == ep)
      if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
       return -1;
     break;
    case 0203:
     if(_renewthread(tlp, inst->u1.right, ms, &tlp->se) == tle)
      return -1;
     continue;
    case 0377:
     match = 1;
     tlp->se.m[0].e.rep = s;
     if(mp != 0)
      _renewmatch(mp, ms, &tlp->se);
     break;
    }
    break;
   }
  }
  if(s == j->reol)
   break;
  checkstart = j->startchar && nl->inst==0;
  s++;
 }while(r);
 return match;
}

variable_types: struct Reprog { struct Reinst { int type; union { struct Reclass { unsigned int *end; unsigned int spans[64]; } *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; } *startinst; struct Reclass class[16]; struct Reinst firstinst[5]; } *

variable_types:
bol
unsigned int *

variable_types: struct Resub { union { char *sp; unsigned int *rsp; } s; union { char *ep; unsigned int *rep; } e; } *

variable_types: ms int

variable_types: struct Reljunk { struct Relist { struct Reinst *inst; struct Resublist { struct Resub m[32]; } se; } *relist[2]; struct Relist *reliste[2]; int starttype; unsigned int startchar; char *starts; char *eol; unsigned int *rstarts; unsigned int *reol; } *

variable_types: flag int

variable_types:
s
unsigned int *

variable_types: i int

variable_types:
p
unsigned int *


decompiled_code:
__int64 __fastcall rregexec2(_QWORD *a1, unsigned int *a2, _QWORD *a3, unsigned int a4, _QWORD *a5)
{
__int64 v6; // [rsp+0h] [rbp-CB28h] BYREF
char v7; // [rsp+6180h] [rbp-69A8h] BYREF
char v8; // [rsp+6590h] [rbp-6598h] BYREF
char v9; // [rsp+C710h] [rbp-418h] BYREF

*a5 = &v8;
a5[1] = &v6;
a5[2] = &v9;
a5[3] = &v7;
return rregexec1(a1, a2, a3, a4, (__int64)a5);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, unsigned int *a2, _QWORD *a3, unsigned int a4, _QWORD *a5)
{
__int64 v6; // [rsp+0h] [rbp-CB28h] BYREF
char v7; // [rsp+6180h] [rbp-69A8h] BYREF
char v8; // [rsp+6590h] [rbp-6598h] BYREF
char v9; // [rsp+C710h] [rbp-418h] BYREF

*a5 = &v8;
a5[1] = &v6;
a5[2] = &v9;
a5[3] = &v7;
return func0(a1, a2, a3, a4, (__int64)a5);
}

original_code:
static int
rregexec2(Reprog *progp,
 Rune *bol,
 Resub *mp,
 int ms,
 Reljunk *j
)
{
 Relist relist0[5*10], relist1[5*10];
 j->relist[0] = relist0;
 j->relist[1] = relist1;
 j->reliste[0] = relist0 + (sizeof(relist0)/sizeof((relist0)[0])) - 2;
 j->reliste[1] = relist1 + (sizeof(relist1)/sizeof((relist1)[0])) - 2;
 return rregexec1(progp, bol, mp, ms, j);
}

canonical_original_code:
static int rregexec2(struct Reprog *progp, unsigned int *bol, struct Resub *mp, int ms, struct Reljunk *j)
{
 struct Relist relist0[-1]; struct Relist relist1[-1];
 j->relist[0] = relist0;
 j->relist[1] = relist1;
 j->reliste[0] = relist0 + (sizeof(relist0)/sizeof((relist0)[0])) - 2;
 j->reliste[1] = relist1 + (sizeof(relist1)/sizeof((relist1)[0])) - 2;
 return rregexec1(progp, bol, mp, ms, j);
}

variable_types: struct Relist { struct Reinst { int type; union { struct Reclass { unsigned int *end; unsigned int spans[64]; } *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; } *inst; struct Resublist { struct Resub { union { char *sp; unsigned int *rsp; } s; union { char *ep; unsigned int *rep; } e; } m[32]; } se; } [-1]


original_code:
extern int
rregexec9(Reprog *progp,
 Rune *bol,
 Resub *mp,
 int ms)
{
 Reljunk j;
 Relist relist0[10], relist1[10];
 int rv;
 j.rstarts = bol;
 j.reol = 0;
 if(mp && ms>0){
  if(mp->s.sp)
   j.rstarts = mp->s.rsp;
  if(mp->e.ep)
   j.reol = mp->e.rep;
 }
 j.starttype = 0;
 j.startchar = 0;
 if(progp->startinst->type == 0177 && progp->startinst->u1.r < Runeself) {
  j.starttype = 0177;
  j.startchar = progp->startinst->u1.r;
 }
 if(progp->startinst->type == 0303)
  j.starttype = 0303;
 j.relist[0] = relist0;
 j.relist[1] = relist1;
 j.reliste[0] = relist0 + (sizeof(relist0)/sizeof((relist0)[0])) - 2;
 j.reliste[1] = relist1 + (sizeof(relist1)/sizeof((relist1)[0])) - 2;
 rv = rregexec1(progp, bol, mp, ms, &j);
 if(rv >= 0)
  return rv;
 rv = rregexec2(progp, bol, mp, ms, &j);
 if(rv >= 0)
  return rv;
 return -1;
}

canonical_original_code:
extern int rregexec9(struct Reprog *progp, unsigned int *bol, struct Resub *mp, int ms)
{
 struct Reljunk j;
 struct Relist relist0[10]; struct Relist relist1[10];
 int rv;
 j.rstarts = bol;
 j.reol = 0;
 if(mp && ms>0){
  if(mp->s.sp)
   j.rstarts = mp->s.rsp;
  if(mp->e.ep)
   j.reol = mp->e.rep;
 }
 j.starttype = 0;
 j.startchar = 0;
 if(progp->startinst->type == 0177 && progp->startinst->u1.r < Runeself) {
  j.starttype = 0177;
  j.startchar = progp->startinst->u1.r;
 }
 if(progp->startinst->type == 0303)
  j.starttype = 0303;
 j.relist[0] = relist0;
 j.relist[1] = relist1;
 j.reliste[0] = relist0 + (sizeof(relist0)/sizeof((relist0)[0])) - 2;
 j.reliste[1] = relist1 + (sizeof(relist1)/sizeof((relist1)[0])) - 2;
 rv = rregexec1(progp, bol, mp, ms, &j);
 if(rv >= 0)
  return rv;
 rv = rregexec2(progp, bol, mp, ms, &j);
 if(rv >= 0)
  return rv;
 return -1;
}

variable_types: rv int


dirstat

original_code:
Dir*
dirstat(char *file)
{
 struct stat lst;
 struct stat st;
 int nstr;
 Dir *d;
 char *str;
 if(lstat(file, &lst) < 0)
  return ((void*)0);
 st = lst;
 if((lst.st_mode&0170000) == 0120000)
  stat(file, &st);
 nstr = _p9dir(&lst, &st, file, ((void*)0), ((void*)0), ((void*)0));
 d = mallocz(sizeof(Dir)+nstr, 1);
 if(d == ((void*)0))
  return ((void*)0);
 str = (char*)&d[1];
 _p9dir(&lst, &st, file, d, &str, str+nstr);
 return d;
}

canonical_original_code:
struct Dir *dirstat(char *file)
{
 struct stat lst;
 struct stat st;
 int nstr;
 struct Dir *d;
 char *str;
 if(lstat(file, &lst) < 0)
  return ((void *)0);
 st = lst;
 if((lst.st_mode&0170000) == 0120000)
  stat(file, &st);
 nstr = _p9dir(&lst, &st, file, ((void *)0), ((void *)0), ((void *)0));
 d = mallocz(sizeof(Dir)+nstr, 1);
 if(d == ((void *)0))
  return ((void *)0);
 str = (char *)&d[1];
 _p9dir(&lst, &st, file, d, &str, str+nstr);
 return d;
}

variable_types:
file
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: nstr int

variable_types: struct Dir { unsigned short type; unsigned int dev; struct Qid { unsigned long long path; unsigned long vers; unsigned char type; } qid; unsigned long mode; unsigned long atime; unsigned long mtime; long long length; char *name; char *uid; char *gid; char *muid; unsigned int uidnum; unsigned int gidnum; unsigned int muidnum; char *ext; } *

variable_types:
str
char *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
char *__fastcall p9netmkaddr(char *name, const char *a2, const char *a3)
{
char *v3; // rbx
const char *v4; // rbp
char *v6; // rax
char *v8; // rax
char *v9; // r13
unsigned int v10; // eax
bool v11; // zf

v3 = name;
v4 = a2;
v6 = strchr(name, 33);
if ( v6 )
{
if ( !strchr(v6 + 1, 33) )
{
v11 = memcmp(name, "unix!", 5uLL) == 0;
if ( a3 )
{
if ( !v11 )
{
snprint(&addr_0, 256LL, "%s!%s", v3, a3);
v3 = (char *)&addr_0;
}
}
}
}
else
{
if ( !a2 )
v4 = (const char *)&unk_2A0;
if ( access(name, 0) >= 0 )
{
snprint(&addr_0, 256LL, "unix!%s", name);
v3 = (char *)&addr_0;
}
else
{
v8 = strchr(name, 58);
v9 = v8;
if ( v8 )
{
v10 = utfnlen(name, v8 - name);
snprint(&addr_0, 256LL, "%s!%.*s!%s", v4, v10, name, v9 + 1);
v3 = (char *)&addr_0;
}
else
{
if ( a3 )
snprint(&addr_0, 256LL, "%s!%s!%s", v4, name, a3);
else
snprint(&addr_0, 256LL, "%s!%s", v4, name);
v3 = (char *)&addr_0;
}
}
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(char *name, const char *a2, const char *a3)
{
char *v3; // rbx
const char *v4; // rbp
char *v6; // rax
char *v8; // rax
char *v9; // r13
unsigned int v10; // eax
bool v11; // zf

v3 = name;
v4 = a2;
v6 = strchr(name, 33);
if ( v6 )
{
if ( !strchr(v6 + 1, 33) )
{
v11 = memcmp(name, "unix!", 5uLL) == 0;
if ( a3 )
{
if ( !v11 )
{
snprint(&addr_0, 256LL, "%s!%s", v3, a3);
v3 = (char *)&addr_0;
}
}
}
}
else
{
if ( !a2 )
v4 = (const char *)&unk_2A0;
if ( access(name, 0) >= 0 )
{
snprint(&addr_0, 256LL, "unix!%s", name);
v3 = (char *)&addr_0;
}
else
{
v8 = strchr(name, 58);
v9 = v8;
if ( v8 )
{
v10 = utfnlen(name, v8 - name);
snprint(&addr_0, 256LL, "%s!%.*s!%s", v4, v10, name, v9 + 1);
v3 = (char *)&addr_0;
}
else
{
if ( a3 )
snprint(&addr_0, 256LL, "%s!%s!%s", v4, name, a3);
else
snprint(&addr_0, 256LL, "%s!%s", v4, name);
v3 = (char *)&addr_0;
}
}
}
return v3;
}

original_code:
char *
p9netmkaddr(char *linear, char *defnet, char *defsrv)
{
 static char addr[256];
 char *cp;
 cp = strchr(linear, '!');
 if(cp == 0){
  if(defnet == 0)
   defnet = "net";
  if(access(linear, 0) >= 0){
   snprint(addr, sizeof(addr), "unix!%s", linear);
   return addr;
  }
  if((cp = strchr(linear, ':')) != ((void*)0)){
   snprint(addr, sizeof(addr), "%s!%.*s!%s",
    defnet, utfnlen(linear, cp-linear),
    linear, cp+1);
   return addr;
  }
  if(defsrv)
   snprint(addr, sizeof(addr), "%s!%s!%s",
    defnet, linear, defsrv);
  else
   snprint(addr, sizeof(addr), "%s!%s", defnet, linear);
  return addr;
 }
 cp = strchr(cp+1, '!');
 if(cp)
  return linear;
 if(strncmp(linear, "unix!", 5) == 0)
  return linear;
 if(defsrv == 0)
  return linear;
 snprint(addr, sizeof(addr), "%s!%s", linear, defsrv);
 return addr;
}

canonical_original_code:
char *p9netmkaddr(char *linear, char *defnet, char *defsrv)
{
 static char addr[256];
 char *cp;
 cp = strchr(linear, '!');
 if(cp == 0){
  if(defnet == 0)
   defnet = "net";
  if(access(linear, 0) >= 0){
   snprint(addr, sizeof(addr), "unix!%s", linear);
   return addr;
  }
  if((cp = strchr(linear, ':')) != ((void *)0)){
   snprint(addr, sizeof(addr), "%s!%.*s!%s",
    defnet, utfnlen(linear, cp-linear),
    linear, cp+1);
   return addr;
  }
  if(defsrv)
   snprint(addr, sizeof(addr), "%s!%s!%s",
    defnet, linear, defsrv);
  else
   snprint(addr, sizeof(addr), "%s!%s", defnet, linear);
  return addr;
 }
 cp = strchr(cp+1, '!');
 if(cp)
  return linear;
 if(strncmp(linear, "unix!", 5) == 0)
  return linear;
 if(defsrv == 0)
  return linear;
 snprint(addr, sizeof(addr), "%s!%s", linear, defsrv);
 return addr;
}

variable_types:
linear
char *

variable_types:
defnet
char *

variable_types:
defsrv
char *

variable_types:
addr
char [256]

variable_types:
cp
char *

return_type: char *


decompiled_code:
char *__fastcall p9getenv(const char *a1)
{
char *result; // rax

result = getenv(a1);
if ( result )
result = strdup(result);
return result;
}

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

result = getenv(a1);
if ( result )
result = strdup(result);
return result;
}

original_code:
char*
p9getenv(char *s)
{
 char *t;
 t = getenv(s);
 if(t == 0)
  return 0;
 return strdup(t);
}

canonical_original_code:
char *p9getenv(char *s)
{
 char *t;
 t = getenv(s);
 if(t == 0)
  return 0;
 return strdup(t);
}

variable_types:
s
char *

variable_types:
t
char *


decompiled_code:
__int64 __fastcall p9putenv(const char *a1, const char *a2)
{
char *v2; // rax

v2 = (char *)smprint("%s=%s", a1, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
putenv(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2)
{
char *v2; // rax

v2 = (char *)smprint("%s=%s", a1, a2);
if ( !v2 )
return 0xFFFFFFFFLL;
putenv(v2);
return 0LL;
}

original_code:
int
p9putenv(char *s, char *v)
{
 char *t;
 t = smprint("%s=%s", s, v);
 if(t == ((void*)0))
  return -1;
 putenv(t);
 return 0;
}

canonical_original_code:
int p9putenv(char *s, char *v)
{
 char *t;
 t = smprint("%s=%s", s, v);
 if(t == ((void *)0))
  return -1;
 putenv(t);
 return 0;
}

variable_types:
v
char *


convert

decompiled_code:
__int64 __fastcall convert(int fd, const char *a2, const char **a3, const char **a4, __int64 *a5)
{
__int16 v8; // ax
__int64 result; // rax
unsigned __int16 v10; // ax
const char *v11; // rsi
__int64 v12; // rax
unsigned __int16 v13; // ax
const char *v14; // rsi
__int64 v15; // rax
char *v16; // rax
__int64 v17; // rax
int optval; // [rsp+8h] [rbp-40h] BYREF
socklen_t optlen[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v8 = *(_WORD *)a2;
if ( *(_WORD *)a2 != 2 )
{
if ( v8 != 10 )
{
if ( v8 == 1 )
{
*a3 = "unknown";
*a4 = "unknown";
v17 = smprint("unix!%s", a2 + 2);
*a5 = v17;
result = (unsigned int)-(v17 == 0);
}
else
{
werrstr("unknown socket family");
result = 0xFFFFFFFFLL;
}
return result;
}
if ( !memcmp(a2 + 8, &in6addr_any, 0x10uLL) )
{
*a3 = strdup("*");
}
else
{
v16 = (char *)malloc(0x2EuLL);
*a3 = v16;
inet_ntop(10, a2 + 8, v16, 0x2Eu);
}
v13 = _bswap_16(*((_WORD *)a2 + 1));
*a4 = (const char *)smprint("%d", v13);
optlen[0] = 4;
if ( getsockopt(fd, 1, 3, &optval, optlen) < 0 )
return 0xFFFFFFFFLL;
if ( optval == 1 )
{
v14 = (const char *)&unk_466;
LABEL_22:
v15 = smprint("%s!%s!%s", v14, *a3, *a4);
*a5 = v15;
if ( *a3 )
result = (unsigned int)-(v15 == 0 || *a4 == 0LL);
else
result = 0xFFFFFFFFLL;
return result;
}
if ( optval == 2 )
{
v14 = (const char *)&unk_46A;
goto LABEL_22;
}
LABEL_14:
werrstr("unknown network type");
return 0xFFFFFFFFLL;
}
if ( *((_DWORD *)a2 + 1) )
*a3 = (const char *)smprint(
"%d.%d.%d.%d",
*((unsigned __int8 *)a2 + 4),
*((unsigned __int8 *)a2 + 5),
*((unsigned __int8 *)a2 + 6),
*((unsigned __int8 *)a2 + 7));
else
*a3 = strdup("*");
v10 = _bswap_16(*((_WORD *)a2 + 1));
*a4 = (const char *)smprint("%d", v10);
optlen[0] = 4;
if ( getsockopt(fd, 1, 3, &optval, optlen) < 0 )
return 0xFFFFFFFFLL;
if ( optval == 1 )
{
v11 = (const char *)&unk_466;
}
else
{
if ( optval != 2 )
goto LABEL_14;
v11 = (const char *)&unk_46A;
}
v12 = smprint("%s!%s!%s", v11, *a3, *a4);
*a5 = v12;
if ( *a3 )
result = (unsigned int)-(v12 == 0 || *a4 == 0LL);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, const char *a2, const char **a3, const char **a4, __int64 *a5)
{
__int16 v8; // ax
__int64 result; // rax
unsigned __int16 v10; // ax
const char *v11; // rsi
__int64 v12; // rax
unsigned __int16 v13; // ax
const char *v14; // rsi
__int64 v15; // rax
char *v16; // rax
__int64 v17; // rax
int optval; // [rsp+8h] [rbp-40h] BYREF
socklen_t optlen[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v8 = *(_WORD *)a2;
if ( *(_WORD *)a2 != 2 )
{
if ( v8 != 10 )
{
if ( v8 == 1 )
{
*a3 = "unknown";
*a4 = "unknown";
v17 = smprint("unix!%s", a2 + 2);
*a5 = v17;
result = (unsigned int)-(v17 == 0);
}
else
{
werrstr("unknown socket family");
result = 0xFFFFFFFFLL;
}
return result;
}
if ( !memcmp(a2 + 8, &in6addr_any, 0x10uLL) )
{
*a3 = strdup("*");
}
else
{
v16 = (char *)malloc(0x2EuLL);
*a3 = v16;
inet_ntop(10, a2 + 8, v16, 0x2Eu);
}
v13 = func0(*((_WORD *)a2 + 1));
*a4 = (const char *)smprint("%d", v13);
optlen[0] = 4;
if ( getsockopt(fd, 1, 3, &optval, optlen) < 0 )
return 0xFFFFFFFFLL;
if ( optval == 1 )
{
v14 = (const char *)&unk_466;
LABEL_22:
v15 = smprint("%s!%s!%s", v14, *a3, *a4);
*a5 = v15;
if ( *a3 )
result = (unsigned int)-(v15 == 0 || *a4 == 0LL);
else
result = 0xFFFFFFFFLL;
return result;
}
if ( optval == 2 )
{
v14 = (const char *)&unk_46A;
goto LABEL_22;
}
LABEL_14:
werrstr("unknown network type");
return 0xFFFFFFFFLL;
}
if ( *((_DWORD *)a2 + 1) )
*a3 = (const char *)smprint(
"%d.%d.%d.%d",
*((unsigned __int8 *)a2 + 4),
*((unsigned __int8 *)a2 + 5),
*((unsigned __int8 *)a2 + 6),
*((unsigned __int8 *)a2 + 7));
else
*a3 = strdup("*");
v10 = func0(*((_WORD *)a2 + 1));
*a4 = (const char *)smprint("%d", v10);
optlen[0] = 4;
if ( getsockopt(fd, 1, 3, &optval, optlen) < 0 )
return 0xFFFFFFFFLL;
if ( optval == 1 )
{
v11 = (const char *)&unk_466;
}
else
{
if ( optval != 2 )
goto LABEL_14;
v11 = (const char *)&unk_46A;
}
v12 = smprint("%s!%s!%s", v11, *a3, *a4);
*a5 = v12;
if ( *a3 )
result = (unsigned int)-(v12 == 0 || *a4 == 0LL);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int
convert(int s, struct sockaddr *sa, char **lsys, char **lserv, char **laddr)
{
 struct sockaddr_un *sockun;
 struct sockaddr_in *sin;
 struct sockaddr_in6 *sin6;
 uchar *ip;
 u32int ipl;
 socklen_t sn;
 int n;
 char *net;
 switch(sa->sa_family){
 case 2:
  sin = (void*)sa;
  ip = (uchar*)&sin->sin_addr;
  ipl = *(u32int*)ip;
  if(ipl == 0)
   *lsys = strdup("*");
  else
   *lsys = smprint("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
  *lserv = smprint("%d", ntohs(sin->sin_port));
  sn = sizeof n;
  if(getsockopt(s, 1, 3, (void*)&n, &sn) < 0)
   return -1;
  if(n == SOCK_STREAM)
   net = "tcp";
  else if(n == SOCK_DGRAM)
   net = "udp";
  else{
   werrstr("unknown network type");
   return -1;
  }
  *laddr = smprint("%s!%s!%s", net, *lsys, *lserv);
  if(*lsys == ((void*)0) || *lserv == ((void*)0) || *laddr == ((void*)0))
   return -1;
  return 0;
 case 10:
  sin6 = (void*)sa;
  if (memcmp(&sin6->sin6_addr, &in6addr_any, sizeof(in6addr_any)) == 0)
   *lsys = strdup("*");
  else{
   *lsys = malloc(46);
   inet_ntop(10, &sin6->sin6_addr, *lsys, 46);
  }
  *lserv = smprint("%d", ntohs(sin6->sin6_port));
  sn = sizeof n;
  if(getsockopt(s, 1, 3, (void*)&n, &sn) < 0)
   return -1;
  if(n == SOCK_STREAM)
   net = "tcp";
  else if(n == SOCK_DGRAM)
   net = "udp";
  else{
   werrstr("unknown network type");
   return -1;
  }
  *laddr = smprint("%s!%s!%s", net, *lsys, *lserv);
  if(*lsys == ((void*)0) || *lserv == ((void*)0) || *laddr == ((void*)0))
   return -1;
  return 0;
 case 1:
  sockun = (void*)sa;
  *lsys = unknown;
  *lserv = unknown;
  *laddr = smprint("unix!%s", sockun->sun_path);
  if(*laddr == ((void*)0))
   return -1;
  return 0;
 default:
  werrstr("unknown socket family");
  return -1;
 }
}

canonical_original_code:
static int convert(int s, struct sockaddr *sa, char **lsys, char **lserv, char **laddr)
{
 struct sockaddr_un *sockun;
 struct sockaddr_in *sin;
 struct sockaddr_in6 *sin6;
 unsigned char *ip;
 unsigned int ipl;
 unsigned int sn;
 int n;
 char *net;
 switch(sa->sa_family){
 case 2:
  sin = (void *)sa;
  ip = (unsigned char *)&sin->sin_addr;
  ipl = *(unsigned int *)ip;
  if(ipl == 0)
   *lsys = strdup("*");
  else
   *lsys = smprint("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
  *lserv = smprint("%d", ntohs(sin->sin_port));
  sn = sizeof n;
  if(getsockopt(s, 1, 3, (void *)&n, &sn) < 0)
   return -1;
  if(n == SOCK_STREAM)
   net = "tcp";
  else if(n == SOCK_DGRAM)
   net = "udp";
  else{
   werrstr("unknown network type");
   return -1;
  }
  *laddr = smprint("%s!%s!%s", net, *lsys, *lserv);
  if(*lsys == ((void *)0) || *lserv == ((void *)0) || *laddr == ((void *)0))
   return -1;
  return 0;
 case 10:
  sin6 = (void *)sa;
  if (memcmp(&sin6->sin6_addr, &in6addr_any, sizeof(in6addr_any)) == 0)
   *lsys = strdup("*");
  else{
   *lsys = malloc(46);
   inet_ntop(10, &sin6->sin6_addr, *lsys, 46);
  }
  *lserv = smprint("%d", ntohs(sin6->sin6_port));
  sn = sizeof n;
  if(getsockopt(s, 1, 3, (void *)&n, &sn) < 0)
   return -1;
  if(n == SOCK_STREAM)
   net = "tcp";
  else if(n == SOCK_DGRAM)
   net = "udp";
  else{
   werrstr("unknown network type");
   return -1;
  }
  *laddr = smprint("%s!%s!%s", net, *lsys, *lserv);
  if(*lsys == ((void *)0) || *lserv == ((void *)0) || *laddr == ((void *)0))
   return -1;
  return 0;
 case 1:
  sockun = (void *)sa;
  *lsys = unknown;
  *lserv = unknown;
  *laddr = smprint("unix!%s", sockun->sun_path);
  if(*laddr == ((void *)0))
   return -1;
  return 0;
 default:
  werrstr("unknown socket family");
  return -1;
 }
}

variable_types: s int

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; } *

variable_types:
lsys
char **

variable_types:
lserv
char **

variable_types:
laddr
char **

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; } *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } *

variable_types:
ip
unsigned char *

variable_types:
ipl
unsigned int

variable_types:
sn
unsigned int

variable_types: n int

variable_types:
net
char *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


xfree

decompiled_code:
void __fastcall xfree(char *a1)
{
if ( a1 != "unknown" )
{
if ( a1 )
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func2(char *a1)
{
if ( a1 != "unknown" )
{
if ( a1 )
free(a1);
}
}

original_code:
static void
xfree(void *v)
{
 if(v != ((void*)0) && v != unknown)
  free(v);
}

canonical_original_code:
static void xfree(void *v)
{
 if(v != ((void *)0) && v != unknown)
  free(v);
}

variable_types:
v
void *


freenetconninfo

decompiled_code:
void __fastcall freenetconninfo(void *ptr)
{
if ( ptr )
{
xfree(*(char **)ptr);
xfree(*((char **)ptr + 1));
xfree(*((char **)ptr + 2));
xfree(*((char **)ptr + 3));
xfree(*((char **)ptr + 4));
xfree(*((char **)ptr + 5));
xfree(*((char **)ptr + 6));
xfree(*((char **)ptr + 7));
xfree(*((char **)ptr + 8));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
if ( ptr )
{
func2(*(char **)ptr);
func2(*((char **)ptr + 1));
func2(*((char **)ptr + 2));
func2(*((char **)ptr + 3));
func2(*((char **)ptr + 4));
func2(*((char **)ptr + 5));
func2(*((char **)ptr + 6));
func2(*((char **)ptr + 7));
func2(*((char **)ptr + 8));
free(ptr);
}
}

original_code:
void
freenetconninfo(NetConnInfo *nci)
{
 if(nci == ((void*)0))
  return;
 xfree(nci->dir);
 xfree(nci->root);
 xfree(nci->spec);
 xfree(nci->lsys);
 xfree(nci->lserv);
 xfree(nci->rsys);
 xfree(nci->rserv);
 xfree(nci->laddr);
 xfree(nci->raddr);
 free(nci);
}

canonical_original_code:
void freenetconninfo(struct NetConnInfo *nci)
{
 if(nci == ((void *)0))
  return;
 xfree(nci->dir);
 xfree(nci->root);
 xfree(nci->spec);
 xfree(nci->lsys);
 xfree(nci->lserv);
 xfree(nci->rsys);
 xfree(nci->rserv);
 xfree(nci->laddr);
 xfree(nci->raddr);
 free(nci);
}

variable_types: struct NetConnInfo { char *dir; char *root; char *spec; char *lsys; char *lserv; char *rsys; char *rserv; char *laddr; char *raddr; } *


decompiled_code:
__int64 __fastcall p9atexit(__int64 a1)
{
__int64 v1; // rax
unsigned __int64 v3; // rbx

lock(&onexlock);
v1 = 0LL;
while ( onex[2 * v1] )
{
if ( ++v1 == 33 )
{
unlock(&onexlock);
return 0LL;
}
}
v3 = 16LL * (int)v1;
dword_128[v3 / 4] = getpid();
onex[v3 / 8] = a1;
unlock(&onexlock);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rax
unsigned __int64 v3; // rbx

lock(&onexlock);
v1 = 0LL;
while ( onex[2 * v1] )
{
if ( ++v1 == 33 )
{
unlock(&onexlock);
return 0LL;
}
}
v3 = 16LL * (int)v1;
dword_128[v3 / 4] = getpid();
onex[v3 / 8] = a1;
unlock(&onexlock);
return 1LL;
}

original_code:
int
p9atexit(void (*f)(void))
{
 int i;
 lock(&onexlock);
 for(i=0; i<33; i++)
  if(onex[i].f == 0) {
   onex[i].pid = getpid();
   onex[i].f = f;
   unlock(&onexlock);
   return 1;
  }
 unlock(&onexlock);
 return 0;
}

canonical_original_code:
int p9atexit(void (*f)())
{
 int i;
 lock(&onexlock);
 for(i=0; i<33; i++)
  if(onex[i].f == 0) {
   onex[i].pid = getpid();
   onex[i].f = f;
   unlock(&onexlock);
   return 1;
  }
 unlock(&onexlock);
 return 0;
}

variable_types:
f
void (*)()

variable_types: i int


exits

decompiled_code:
void __fastcall __noreturn exits(_BYTE *a1)
{
__pid_t v1; // er12
void (**i)(void); // rbx
void (*v3)(void); // rax
int v4; // eax

v1 = getpid();
for ( i = (void (**)(void))&unk_320; ; i -= 2 )
{
v3 = *i;
if ( *i && *((_DWORD *)i + 2) == v1 )
{
*i = 0LL;
v3();
}
if ( i == (void (**)(void))onex )
{
if ( a1 )
{
if ( *a1 )
{
v4 = exitcode(a1);
exit(v4);
}
}
exit(0);
}
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(_BYTE *a1)
{
__pid_t v1; // er12
void (**i)(void); // rbx
void (*v3)(void); // rax
int v4; // eax

v1 = getpid();
for ( i = (void (**)(void))&unk_320; ; i -= 2 )
{
v3 = *i;
if ( *i && *((_DWORD *)i + 2) == v1 )
{
*i = 0LL;
v3();
}
if ( i == (void (**)(void))onex )
{
if ( a1 )
{
if ( *a1 )
{
v4 = exitcode(a1);
exit(v4);
}
}
exit(0);
}
}
}

original_code:
void
exits(char *s)
{
 int i, pid;
 void (*f)(void);
 pid = getpid();
 for(i = 33 -1; i >= 0; i--)
  if((f = onex[i].f) && pid == onex[i].pid) {
   onex[i].f = 0;
   (*f)();
  }
 if(s == 0 || *s == 0)
  exit(0);
 exit(exitcode(s));
}

canonical_original_code:
void exits(char *s)
{
 int i; int pid;
 void (*f)();
 pid = getpid();
 for(i = 33 -1; i >= 0; i--)
  if((f = onex[i].f) && pid == onex[i].pid) {
   onex[i].f = 0;
   (*f)();
  }
 if(s == 0 || *s == 0)
  exit(0);
 exit(exitcode(s));
}

variable_types:
s
char *

variable_types: pid int


fpcmp

decompiled_code:
__int64 __fastcall fpcmp(_BYTE *a1, __int64 *a2)
{
int v3; // edx
__int64 v4; // rax
int v5; // ecx
unsigned __int64 v7; // [rsp+0h] [rbp-18h] BYREF
__int64 v8; // [rsp+8h] [rbp-10h]

v7 = *a2;
v8 = a2[1];
while ( 1 )
{
while ( 1 )
{
v7 *= 10LL;
v8 *= 10LL;
frnorm(&v7);
v3 = (v7 >> 28) + 48;
v4 = v7 & 0xFFFFFFF;
v7 = v4;
v5 = (char)*a1;
if ( *a1 )
break;
if ( v3 > 48 )
return (unsigned int)-1;
if ( !(v8 | v4) )
return (unsigned int)v5;
}
if ( v3 < v5 )
return 1;
if ( v3 > v5 )
break;
++a1;
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, __int64 *a2)
{
int v3; // edx
__int64 v4; // rax
int v5; // ecx
unsigned __int64 v7; // [rsp+0h] [rbp-18h] BYREF
__int64 v8; // [rsp+8h] [rbp-10h]

v7 = *a2;
v8 = a2[1];
while ( 1 )
{
while ( 1 )
{
v7 *= 10LL;
v8 *= 10LL;
func1(&v7);
v3 = (v7 >> 28) + 48;
v4 = v7 & 0xFFFFFFF;
v7 = v4;
v5 = (char)*a1;
if ( *a1 )
break;
if ( v3 > 48 )
return (unsigned int)-1;
if ( !(v8 | v4) )
return (unsigned int)v5;
}
if ( v3 < v5 )
return 1;
if ( v3 > v5 )
break;
++a1;
}
return (unsigned int)-1;
}

original_code:
static int
fpcmp(char *a, _fmtulong* f)
{
 _fmtulong tf[Prec];
 int i, d, c;
 for(i=0; i<Prec; i++)
  tf[i] = f[i];
 for(;;) {
  for(i=0; i<Prec; i++)
   tf[i] = tf[i]*10;
  frnorm(tf);
  d = (tf[0] >> Nbits) + '0';
  tf[0] &= One-1;
  c = *a;
  if(c == 0) {
   if('0' < d)
    return -1;
   if(tf[0] != 0)
    goto cont;
   for(i=1; i<Prec; i++)
    if(tf[i] != 0)
     goto cont;
   return 0;
  }
  if(c > d)
   return +1;
  if(c < d)
   return -1;
  a++;
 cont:;
 }
}

canonical_original_code:
static int fpcmp(char *a, unsigned long *f)
{
 unsigned long tf[-1];
 int i; int d; int c;
 for(i=0; i<Prec; i++)
  tf[i] = f[i];
 for(;;) {
  for(i=0; i<Prec; i++)
   tf[i] = tf[i]*10;
  frnorm(tf);
  d = (tf[0] >> Nbits) + '0';
  tf[0] &= One-1;
  c = *a;
  if(c == 0) {
   if('0' < d)
    return -1;
   if(tf[0] != 0)
    goto cont;
   for(i=1; i<Prec; i++)
    if(tf[i] != 0)
     goto cont;
   return 0;
  }
  if(c > d)
   return +1;
  if(c < d)
   return -1;
  a++;
 cont:;
 }
}

variable_types:
a
char *

variable_types:
f
unsigned long *

variable_types:
tf
unsigned long [-1]

variable_types: d int

variable_types: c int


mulby

decompiled_code:
__int64 __fastcall mulby(unsigned __int64 a1, _BYTE *a2, __int64 a3, char a4)
{
__int64 result; // rax
__int64 v7; // r10
__int64 v8; // rsi
int v9; // edx
_BYTE *v10; // r9
char v11; // si
int v12; // edx

*a2 = 0;
result = a3 - 1;
if ( a1 <= a3 - 1 )
{
v7 = a1 - 1 - a3;
v8 = -1LL;
LODWORD(result) = 0;
do
{
v9 = result + ((*(char *)(a3 + v8) - 48) << a4);
result = (unsigned int)(v9 / 10);
a2[v8--] = v9 % 10 + 48;
}
while ( v7 != v8 );
v10 = &a2[a1 - a3];
if ( (_DWORD)result )
{
do
{
v11 = result;
v12 = (int)result / 10;
result = (unsigned int)((int)result / 10);
*--v10 = -10 * v12 + v11 + 48;
}
while ( v12 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int64 a1, _BYTE *a2, __int64 a3, char a4)
{
__int64 result; // rax
__int64 v7; // r10
__int64 v8; // rsi
int v9; // edx
_BYTE *v10; // r9
char v11; // si
int v12; // edx

*a2 = 0;
result = a3 - 1;
if ( a1 <= a3 - 1 )
{
v7 = a1 - 1 - a3;
v8 = -1LL;
LODWORD(result) = 0;
do
{
v9 = result + ((*(char *)(a3 + v8) - 48) << a4);
result = (unsigned int)(v9 / 10);
a2[v8--] = v9 % 10 + 48;
}
while ( v7 != v8 );
v10 = &a2[a1 - a3];
if ( (_DWORD)result )
{
do
{
v11 = result;
v12 = (int)result / 10;
result = (unsigned int)((int)result / 10);
*--v10 = -10 * v12 + v11 + 48;
}
while ( v12 );
}
}
return result;
}

variable_types:
p
char *

variable_types:
q
char *

variable_types: b int


xcmp

decompiled_code:
__int64 __fastcall xcmp(char *a1, char *a2)
{
unsigned int v4; // er14
char v5; // bl
int v6; // ebp

while ( 1 )
{
v4 = *a2++;
if ( !*(a2 - 1) )
break;
v5 = *a1++;
v6 = v5;
if ( ((*_ctype_b_loc())[v5] & 0x100) != 0 )
v6 = tolower(v5);
if ( v6 != v4 )
return 1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, char *a2)
{
unsigned int v4; // er14
char v5; // bl
int v6; // ebp

while ( 1 )
{
v4 = *a2++;
if ( !*(a2 - 1) )
break;
v5 = *a1++;
v6 = v5;
if ( ((*_ctype_b_loc())[v5] & 0x100) != 0 )
v6 = tolower(v5);
if ( v6 != v4 )
return 1;
}
return v4;
}

original_code:
static int
xcmp(char *a, char *b)
{
 int c1, c2;
 while((c1 = *b++) != '\0') {
  c2 = *a++;
  if(((*__ctype_b_loc ())[(int) ((c2))] & (unsigned short int) _ISupper))
   c2 = tolower(c2);
  if(c1 != c2)
   return 1;
 }
 return 0;
}

canonical_original_code:
static int xcmp(char *a, char *b)
{
 int c1; int c2;
 while((c1 = *b++) != '\0') {
  c2 = *a++;
  if(((*__ctype_b_loc ())[(int) ((c2))] & (unsigned short) _ISupper))
   c2 = tolower(c2);
  if(c1 != c2)
   return 1;
 }
 return 0;
}

variable_types:
b
char *


fmtstrtod

original_code:
double
fmtstrtod(const char *as, char **aas)
{
 int na, ex, dp, bp, c, i, flag, state;
 _fmtulong low[Prec], hig[Prec], mid[Prec];
 double d;
 char *s, a[Ndig];
 flag = 0;
 na = 0;
 dp = 0;
 ex = 0;
 state = S0;
 for(s=(char*)as;; s++) {
  c = *s;
  if(c >= '0' && c <= '9') {
   switch(state) {
   case S0:
   case S1:
   case S2:
    state = S2;
    break;
   case S3:
   case S4:
    state = S4;
    break;
   case S5:
   case S6:
   case S7:
    state = S7;
    ex = ex*10 + (c-'0');
    continue;
   }
   if(na == 0 && c == '0') {
    dp--;
    continue;
   }
   if(na < Ndig-50)
    a[na++] = c;
   continue;
  }
  switch(c) {
  case '\t':
  case '\n':
  case '\v':
  case '\f':
  case '\r':
  case ' ':
   if(state == S0)
    continue;
   break;
  case '-':
   if(state == S0)
    flag |= Fsign;
   else
    flag |= Fesign;
  case '+':
   if(state == S0)
    state = S1;
   else
   if(state == S5)
    state = S6;
   else
    break;
   continue;
  case '.':
   flag |= Fdpoint;
   dp = na;
   if(state == S0 || state == S1) {
    state = S3;
    continue;
   }
   if(state == S2) {
    state = S4;
    continue;
   }
   break;
  case 'e':
  case 'E':
   if(state == S2 || state == S4) {
    state = S5;
    continue;
   }
   break;
  }
  break;
 }
 switch(state) {
 case S0:
  if(xcmp(s, "nan") == 0) {
   if(aas != 0)
    *aas = s+3;
   goto retnan;
  }
 case S1:
  if(xcmp(s, "infinity") == 0) {
   if(aas != 0)
    *aas = s+8;
   goto retinf;
  }
  if(xcmp(s, "inf") == 0) {
   if(aas != 0)
    *aas = s+3;
   goto retinf;
  }
 case S3:
  if(aas != 0)
   *aas = (char*)as;
  goto ret0;
 case S6:
  s--;
 case S5:
  s--;
  break;
 }
 if(aas != 0)
  *aas = s;
 if(flag & Fdpoint)
 while(na > 0 && a[na-1] == '0')
  na--;
 if(na == 0)
  goto ret0;
 a[na] = 0;
 if(!(flag & Fdpoint))
  dp = na;
 if(flag & Fesign)
  ex = -ex;
 dp += ex;
 if(dp < -Maxe){
  (*__errno_location ()) = 34;
  goto ret0;
 } else
 if(dp > +Maxe)
  goto retinf;
 bp = 0;
 while(dp > 0)
  divascii(a, &na, &dp, &bp);
 while(dp < 0 || a[0] < '5')
  mulascii(a, &na, &dp, &bp);
 mid[0] = 0;
 mid[1] = 1;
 for(i=0; (c=a[i]) != '\0'; i++) {
  mid[0] = mid[0]*10 + (c-'0');
  mid[1] = mid[1]*10;
  if(i >= 8)
   break;
 }
 low[0] = umuldiv(mid[0], One, mid[1]);
 hig[0] = umuldiv(mid[0]+1, One, mid[1]);
 for(i=1; i<Prec; i++) {
  low[i] = 0;
  hig[i] = One-1;
 }
 for(;;) {
  c = 0;
  for(i=0; i<Prec; i++) {
   mid[i] = hig[i] + low[i];
   if(c)
    mid[i] += One;
   c = mid[i] & 1;
   mid[i] >>= 1;
  }
  frnorm(mid);
  c = fpcmp(a, mid);
  if(c > 0) {
   c = 1;
   for(i=0; i<Prec; i++)
    if(low[i] != mid[i]) {
     c = 0;
     low[i] = mid[i];
    }
   if(c)
    break;
   continue;
  }
  if(c < 0) {
   for(i=0; i<Prec; i++)
    hig[i] = mid[i];
   continue;
  }
  c = mid[Prec-1] & (Sigbit-1);
  if(c == Sigbit/2 && (mid[Prec-1]&Sigbit) == 0)
   mid[Prec-1] -= c;
  break;
 }
 c = mid[Prec-1] & (Sigbit-1);
 mid[Prec-1] -= c;
 if(c >= Sigbit/2) {
  mid[Prec-1] += Sigbit;
  frnorm(mid);
 }
 goto out;
ret0:
 return 0;
retnan:
 return __NaN();
retinf:
 (*__errno_location ()) = 34;
 if(flag & Fsign)
  return -(__builtin_huge_val ());
 return (__builtin_huge_val ());
out:
 d = 0;
 for(i=0; i<Prec; i++)
  d = d*One + mid[i];
 if(flag & Fsign)
  d = -d;
 d = ldexp(d, bp - Prec*Nbits);
 if(d == 0){
  (*__errno_location ()) = 34;
 }
 return d;
}

canonical_original_code:
double fmtstrtod(char *as, char **aas)
{
 int na; int ex; int dp; int bp; int c; int i; int flag; int state;
 unsigned long low[-1]; unsigned long hig[-1]; unsigned long mid[-1];
 double d;
 char *s; char a[-1];
 flag = 0;
 na = 0;
 dp = 0;
 ex = 0;
 state = S0;
 for(s=(char *)as;; s++) {
  c = *s;
  if(c >= '0' && c <= '9') {
   switch(state) {
   case S0:
   case S1:
   case S2:
    state = S2;
    break;
   case S3:
   case S4:
    state = S4;
    break;
   case S5:
   case S6:
   case S7:
    state = S7;
    ex = ex*10 + (c-'0');
    continue;
   }
   if(na == 0 && c == '0') {
    dp--;
    continue;
   }
   if(na < Ndig-50)
    a[na++] = c;
   continue;
  }
  switch(c) {
  case '\t':
  case '\n':
  case '\v':
  case '\f':
  case '\r':
  case ' ':
   if(state == S0)
    continue;
   break;
  case '-':
   if(state == S0)
    flag |= Fsign;
   else
    flag |= Fesign;
  case '+':
   if(state == S0)
    state = S1;
   else
   if(state == S5)
    state = S6;
   else
    break;
   continue;
  case '.':
   flag |= Fdpoint;
   dp = na;
   if(state == S0 || state == S1) {
    state = S3;
    continue;
   }
   if(state == S2) {
    state = S4;
    continue;
   }
   break;
  case 'e':
  case 'E':
   if(state == S2 || state == S4) {
    state = S5;
    continue;
   }
   break;
  }
  break;
 }
 switch(state) {
 case S0:
  if(xcmp(s, "nan") == 0) {
   if(aas != 0)
    *aas = s+3;
   goto retnan;
  }
 case S1:
  if(xcmp(s, "infinity") == 0) {
   if(aas != 0)
    *aas = s+8;
   goto retinf;
  }
  if(xcmp(s, "inf") == 0) {
   if(aas != 0)
    *aas = s+3;
   goto retinf;
  }
 case S3:
  if(aas != 0)
   *aas = (char *)as;
  goto ret0;
 case S6:
  s--;
 case S5:
  s--;
  break;
 }
 if(aas != 0)
  *aas = s;
 if(flag & Fdpoint)
 while(na > 0 && a[na-1] == '0')
  na--;
 if(na == 0)
  goto ret0;
 a[na] = 0;
 if(!(flag & Fdpoint))
  dp = na;
 if(flag & Fesign)
  ex = -ex;
 dp += ex;
 if(dp < -Maxe){
  (*__errno_location ()) = 34;
  goto ret0;
 } else
 if(dp > +Maxe)
  goto retinf;
 bp = 0;
 while(dp > 0)
  divascii(a, &na, &dp, &bp);
 while(dp < 0 || a[0] < '5')
  mulascii(a, &na, &dp, &bp);
 mid[0] = 0;
 mid[1] = 1;
 for(i=0; (c=a[i]) != '\0'; i++) {
  mid[0] = mid[0]*10 + (c-'0');
  mid[1] = mid[1]*10;
  if(i >= 8)
   break;
 }
 low[0] = umuldiv(mid[0], One, mid[1]);
 hig[0] = umuldiv(mid[0]+1, One, mid[1]);
 for(i=1; i<Prec; i++) {
  low[i] = 0;
  hig[i] = One-1;
 }
 for(;;) {
  c = 0;
  for(i=0; i<Prec; i++) {
   mid[i] = hig[i] + low[i];
   if(c)
    mid[i] += One;
   c = mid[i] & 1;
   mid[i] >>= 1;
  }
  frnorm(mid);
  c = fpcmp(a, mid);
  if(c > 0) {
   c = 1;
   for(i=0; i<Prec; i++)
    if(low[i] != mid[i]) {
     c = 0;
     low[i] = mid[i];
    }
   if(c)
    break;
   continue;
  }
  if(c < 0) {
   for(i=0; i<Prec; i++)
    hig[i] = mid[i];
   continue;
  }
  c = mid[Prec-1] & (Sigbit-1);
  if(c == Sigbit/2 && (mid[Prec-1]&Sigbit) == 0)
   mid[Prec-1] -= c;
  break;
 }
 c = mid[Prec-1] & (Sigbit-1);
 mid[Prec-1] -= c;
 if(c >= Sigbit/2) {
  mid[Prec-1] += Sigbit;
  frnorm(mid);
 }
 goto out;
ret0:
 return 0;
retnan:
 return __NaN();
retinf:
 (*__errno_location ()) = 34;
 if(flag & Fsign)
  return -(__builtin_huge_val ());
 return (__builtin_huge_val ());
out:
 d = 0;
 for(i=0; i<Prec; i++)
  d = d*One + mid[i];
 if(flag & Fsign)
  d = -d;
 d = ldexp(d, bp - Prec*Nbits);
 if(d == 0){
  (*__errno_location ()) = 34;
 }
 return d;
}

variable_types:
as
char *

variable_types:
aas
char **

variable_types: ex int

variable_types: dp int

variable_types: bp int

variable_types: flag int

variable_types: state int

variable_types:
low
unsigned long [-1]

variable_types:
hig
unsigned long [-1]

variable_types:
mid
unsigned long [-1]

variable_types: d double

variable_types:
a
char [-1]

return_type: double


opentemp

decompiled_code:
__int64 __fastcall opentemp(char *filename, unsigned int a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12

v2 = mkstemp64(filename);
if ( v2 < 0 )
{
v4 = -1;
}
else
{
v3 = v2;
v4 = p9open(filename, a2);
if ( v4 < 0 )
{
remove(filename);
close(v3);
v4 = -1;
}
else
{
close(v3);
}
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *filename, unsigned int a2)
{
int v2; // eax
int v3; // ebp
int v4; // er12

v2 = mkstemp64(filename);
if ( v2 < 0 )
{
v4 = -1;
}
else
{
v3 = v2;
v4 = p9open(filename, a2);
if ( v4 < 0 )
{
remove(filename);
close(v3);
v4 = -1;
}
else
{
close(v3);
}
}
return (unsigned int)v4;
}

original_code:
int
opentemp(char *template, int mode)
{
 int fd, fd1;
 fd = mkstemp(template);
 if(fd < 0)
  return -1;
 if((fd1 = p9open(template, mode)) < 0){
  remove(template);
  close(fd);
  return -1;
 }
 close(fd);
 return fd1;
}

canonical_original_code:
int opentemp(char *template, int mode)
{
 int fd; int fd1;
 fd = mkstemp(template);
 if(fd < 0)
  return -1;
 if((fd1 = p9open(template, mode)) < 0){
  remove(template);
  close(fd);
  return -1;
 }
 close(fd);
 return fd1;
}

variable_types:
template
char *

variable_types: mode int

variable_types: fd int


Boffset

decompiled_code:
__int64 __fastcall Boffset(int *a1)
{
__int64 v1; // rdx

v1 = (unsigned int)a1[4];
if ( (_DWORD)v1 == 2 )
return *((_QWORD *)a1 + 4) + a1[10] + a1[1];
if ( (v1 & 0xFFFFFFFD) == 1 )
return *((_QWORD *)a1 + 4) + *a1;
fprint(2LL, "Boffset: unknown state %d\n", v1);
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
__int64 v1; // rdx

v1 = (unsigned int)a1[4];
if ( (_DWORD)v1 == 2 )
return *((_QWORD *)a1 + 4) + a1[10] + a1[1];
if ( (v1 & 0xFFFFFFFD) == 1 )
return *((_QWORD *)a1 + 4) + *a1;
fprint(2LL, "Boffset: unknown state %d\n", v1);
return -1LL;
}

original_code:
vlong
Boffset(Biobuf *bp)
{
 vlong n;
 switch(bp->state) {
 default:
  fprint(2, "Boffset: unknown state %d\n", bp->state);
  n = Beof;
  break;
 case Bracteof:
 case Bractive:
  n = bp->offset + bp->icount;
  break;
 case Bwactive:
  n = bp->offset + (bp->bsize + bp->ocount);
  break;
 }
 return n;
}

canonical_original_code:
long long Boffset(struct Biobuf *bp)
{
 long long n;
 switch(bp->state) {
 default:
  fprint(2, "Boffset: unknown state %d\n", bp->state);
  n = Beof;
  break;
 case Bracteof:
 case Bractive:
  n = bp->offset + bp->icount;
  break;
 case Bwactive:
  n = bp->offset + (bp->bsize + bp->ocount);
  break;
 }
 return n;
}

variable_types: struct Biobuf { int icount; int ocount; int rdline; int runesize; int state; int fid; int flag; long long offset; int bsize; unsigned char *bbuf; unsigned char *ebuf; unsigned char *gbuf; unsigned char b[-1]; } *

variable_types:
n
long long

return_type: long long


print

decompiled_code:
__int64 print(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return vfprint(1LL, a1, va);
}

canonical_decompiled_code:
__int64 func0(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return vfprint(1LL, a1, va);
}

original_code:
int
print(char *fmt, ...)
{
 int n;
 va_list args;
 __builtin_va_start(args,fmt);
 n = vfprint(1, fmt, args);
 __builtin_va_end(args);
 return n;
}

canonical_original_code:
int print(char *fmt, ...)
{
 int n;
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 n = vfprint(1, fmt, args);
 __builtin_va_end(args);
 return n;
}

variable_types:
fmt
char *

variable_types: n int


gettokens

decompiled_code:
__int64 __fastcall gettokens(char *a1, char **a2, int a3, __int64 a4)
{
unsigned int i; // er13
char v9; // si

if ( a3 <= 0 )
return 0;
for ( i = 0; i != a3; ++i )
{
v9 = *a1;
if ( !*a1 )
break;
while ( utfrune(a4, v9) )
{
*a1++ = 0;
v9 = *a1;
if ( !*a1 )
return i;
}
if ( !*a1 )
break;
*a2 = a1;
a1 = etoken(a1, a4);
++a2;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, char **a2, int a3, __int64 a4)
{
unsigned int i; // er13
char v9; // si

if ( a3 <= 0 )
return 0;
for ( i = 0; i != a3; ++i )
{
v9 = *a1;
if ( !*a1 )
break;
while ( utfrune(a4, v9) )
{
*a1++ = 0;
v9 = *a1;
if ( !*a1 )
return i;
}
if ( !*a1 )
break;
*a2 = a1;
a1 = func0(a1, a4);
++a2;
}
return i;
}

original_code:
int
gettokens(char *s, char **args, int maxargs, char *sep)
{
 int nargs;
 for(nargs=0; nargs<maxargs; nargs++){
  while(*s!='\0' && utfrune(sep, *s)!=((void*)0))
   *s++ = '\0';
  if(*s == '\0')
   break;
  args[nargs] = s;
  s = etoken(s, sep);
 }
 return nargs;
}

canonical_original_code:
int gettokens(char *s, char **args, int maxargs, char *sep)
{
 int nargs;
 for(nargs=0; nargs<maxargs; nargs++){
  while(*s!='\0' && utfrune(sep, *s)!=((void *)0))
   *s++ = '\0';
  if(*s == '\0')
   break;
  args[nargs] = s;
  s = etoken(s, sep);
 }
 return nargs;
}

variable_types:
s
char *

variable_types:
args
char **

variable_types: maxargs int

variable_types:
sep
char *

variable_types: nargs int


tokenize

decompiled_code:
__int64 __fastcall tokenize(char *a1, char **a2, int a3)
{
unsigned int i; // er12
char v7; // si

if ( a3 <= 0 )
return 0;
for ( i = 0; i != a3; ++i )
{
v7 = *a1;
if ( !*a1 )
break;
while ( utfrune(qsep, v7) )
{
v7 = *++a1;
if ( !*a1 )
return i;
}
if ( !*a1 )
break;
*a2 = a1;
a1 = qtoken(a1, (__int64)qsep);
++a2;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, char **a2, int a3)
{
unsigned int i; // er12
char v7; // si

if ( a3 <= 0 )
return 0;
for ( i = 0; i != a3; ++i )
{
v7 = *a1;
if ( !*a1 )
break;
while ( utfrune(qsep, v7) )
{
v7 = *++a1;
if ( !*a1 )
return i;
}
if ( !*a1 )
break;
*a2 = a1;
a1 = func1(a1, (__int64)qsep);
++a2;
}
return i;
}

original_code:
int
tokenize(char *s, char **args, int maxargs)
{
 int nargs;
 for(nargs=0; nargs<maxargs; nargs++){
  while(*s!='\0' && utfrune(qsep, *s)!=((void*)0))
   s++;
  if(*s == '\0')
   break;
  args[nargs] = s;
  s = qtoken(s, qsep);
 }
 return nargs;
}

canonical_original_code:
int tokenize(char *s, char **args, int maxargs)
{
 int nargs;
 for(nargs=0; nargs<maxargs; nargs++){
  while(*s!='\0' && utfrune(qsep, *s)!=((void *)0))
   s++;
  if(*s == '\0')
   break;
  args[nargs] = s;
  s = qtoken(s, qsep);
 }
 return nargs;
}


getfields

original_code:
int
getfields(char *str, char **args, int max, int mflag, char *set)
{
 Rune r;
 int nr, intok, narg;
 if(max <= 0)
  return 0;
 narg = 0;
 args[narg] = str;
 if(!mflag)
  narg++;
 intok = 0;
 for(;; str += nr) {
  nr = chartorune(&r, str);
  if(r == 0)
   break;
  if(utfrune(set, r)) {
   if(narg >= max)
    break;
   *str = 0;
   intok = 0;
   args[narg] = str + nr;
   if(!mflag)
    narg++;
  } else {
   if(!intok && mflag)
    narg++;
   intok = 1;
  }
 }
 return narg;
}

canonical_original_code:
int getfields(char *str, char **args, int max, int mflag, char *set)
{
 unsigned int r;
 int nr; int intok; int narg;
 if(max <= 0)
  return 0;
 narg = 0;
 args[narg] = str;
 if(!mflag)
  narg++;
 intok = 0;
 for(;; str += nr) {
  nr = chartorune(&r, str);
  if(r == 0)
   break;
  if(utfrune(set, r)) {
   if(narg >= max)
    break;
   *str = 0;
   intok = 0;
   args[narg] = str + nr;
   if(!mflag)
    narg++;
  } else {
   if(!intok && mflag)
    narg++;
   intok = 1;
  }
 }
 return narg;
}

variable_types:
str
char *

variable_types: max int

variable_types: mflag int

variable_types:
set
char *

variable_types:
r
unsigned int

variable_types: nr int

variable_types: intok int

variable_types: narg int


runesnprint

decompiled_code:
__int64 runesnprint(__int64 a1, __int64 a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return runevsnprint(a1, a2, a3, va);
}

canonical_decompiled_code:
__int64 func0(__int64 a1, __int64 a2, __int64 a3, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a3);
return runevsnprint(a1, a2, a3, va);
}

original_code:
int
runesnprint(Rune *buf, int len, char *fmt, ...)
{
 int n;
 va_list args;
 __builtin_va_start(args,fmt);
 n = runevsnprint(buf, len, fmt, args);
 __builtin_va_end(args);
 return n;
}

canonical_original_code:
int runesnprint(unsigned int *buf, int len, char *fmt, ...)
{
 int n;
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 n = runevsnprint(buf, len, fmt, args);
 __builtin_va_end(args);
 return n;
}

variable_types:
buf
unsigned int *

variable_types: len int


original_code:
uint
sizeD2M(Dir *d)
{
 char *sv[5];
 int i, ns, nstr, fixlen;
 sv[0] = d->name;
 sv[1] = d->uid;
 sv[2] = d->gid;
 sv[3] = d->muid;
 fixlen = (2 +(1 +4 +8)+5*2 +4*4 +1*8);
 nstr = 4;
 ns = 0;
 for(i = 0; i < nstr; i++)
  if(sv[i])
   ns += strlen(sv[i]);
 return fixlen + ns;
}

canonical_original_code:
unsigned int sizeD2M(struct Dir *d)
{
 char *sv[5];
 int i; int ns; int nstr; int fixlen;
 sv[0] = d->name;
 sv[1] = d->uid;
 sv[2] = d->gid;
 sv[3] = d->muid;
 fixlen = (2 +(1 +4 +8)+5*2 +4*4 +1*8);
 nstr = 4;
 ns = 0;
 for(i = 0; i < nstr; i++)
  if(sv[i])
   ns += strlen(sv[i]);
 return fixlen + ns;
}

variable_types: struct Dir { unsigned short type; unsigned int dev; struct Qid { unsigned long long path; unsigned long vers; unsigned char type; } qid; unsigned long mode; unsigned long atime; unsigned long mtime; long long length; char *name; char *uid; char *gid; char *muid; unsigned int uidnum; unsigned int gidnum; unsigned int muidnum; char *ext; } *

variable_types:
sv
char *[5]

variable_types: i int

variable_types: ns int

variable_types: nstr int

variable_types: fixlen int


variable_types:
buf
unsigned char *

variable_types:
nbuf
unsigned int

variable_types:
p
unsigned char *

variable_types:
ebuf
unsigned char *

variable_types:
nsv
int [5]

variable_types: ss int


fmtStrFlush

original_code:
static int
fmtStrFlush(Fmt *f)
{
 char *s;
 int n;
 if(f->start == 0)
  return 0;
 n = (_fmtuintptr)f->farg;
 n *= 2;
 s = (char*)f->start;
 f->start = realloc(s, n);
 if(f->start == 0){
  f->farg = 0;
  f->to = 0;
  f->stop = 0;
  free(s);
  return 0;
 }
 f->farg = (void*)(_fmtuintptr)n;
 f->to = (char*)f->start + ((char*)f->to - s);
 f->stop = (char*)f->start + n - 1;
 return 1;
}

canonical_original_code:
static int fmtStrFlush(struct Fmt *f)
{
 char *s;
 int n;
 if(f->start == 0)
  return 0;
 n = (unsigned long)f->farg;
 n *= 2;
 s = (char *)f->start;
 f->start = realloc(s, n);
 if(f->start == 0){
  f->farg = 0;
  f->to = 0;
  f->stop = 0;
  free(s);
  return 0;
 }
 f->farg = (void *)(unsigned long)n;
 f->to = (char *)f->start + ((char *)f->to - s);
 f->stop = (char *)f->start + n - 1;
 return 1;
}

variable_types: struct Fmt { unsigned char runes; void *start; void *to; void *stop; int (*flush)(struct Fmt *); void *farg; int nfmt; __builtin_va_list args; unsigned int r; int width; int prec; unsigned long flags; char *decimal; char *thousands; char *grouping; } *

variable_types:
s
char *

variable_types: n int


fmtstrinit

decompiled_code:
__int64 __fastcall fmtstrinit(_QWORD *a1)
{
char *v1; // rax

*a1 = 0LL;
a1[15] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 128) >> 3));
v1 = (char *)malloc(0x20uLL);
a1[1] = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
a1[2] = v1;
a1[3] = v1 + 31;
a1[4] = fmtStrFlush;
a1[5] = 32LL;
fmtlocaleinit(a1, 0LL, 0LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
char *v1; // rax

*a1 = 0LL;
a1[15] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 128) >> 3));
v1 = (char *)malloc(0x20uLL);
a1[1] = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
a1[2] = v1;
a1[3] = v1 + 31;
a1[4] = fmtStrFlush;
a1[5] = 32LL;
fmtlocaleinit(a1, 0LL, 0LL, 0LL);
return 0LL;
}

original_code:
int
fmtstrinit(Fmt *f)
{
 int n;
 memset(f, 0, sizeof *f);
 f->runes = 0;
 n = 32;
 f->start = malloc(n);
 if(f->start == 0)
  return -1;
 f->to = f->start;
 f->stop = (char*)f->start + n - 1;
 f->flush = fmtStrFlush;
 f->farg = (void*)(_fmtuintptr)n;
 f->nfmt = 0;
 fmtlocaleinit(f, 0, 0, 0);
 return 0;
}

canonical_original_code:
int fmtstrinit(struct Fmt *f)
{
 int n;
 memset(f, 0, sizeof *f);
 f->runes = 0;
 n = 32;
 f->start = malloc(n);
 if(f->start == 0)
  return -1;
 f->to = f->start;
 f->stop = (char *)f->start + n - 1;
 f->flush = fmtStrFlush;
 f->farg = (void *)(unsigned long)n;
 f->nfmt = 0;
 fmtlocaleinit(f, 0, 0, 0);
 return 0;
}


vsmprint

decompiled_code:
__int64 __fastcall vsmprint(__int64 a1, const __m128i *a2)
{
int v2; // edx
__int64 result; // rax
void *v4[7]; // [rsp+0h] [rbp-98h] BYREF
__m128i v5; // [rsp+38h] [rbp-60h]
__int64 v6; // [rsp+48h] [rbp-50h]

v2 = fmtstrinit(v4);
result = 0LL;
if ( v2 >= 0 )
{
v5 = _mm_loadu_si128(a2);
v6 = a2[1].m128i_i64[0];
if ( (int)dofmt(v4, a1) < 0 )
{
free(v4[1]);
result = 0LL;
}
else
{
result = fmtstrflush(v4);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const __m128i *a2)
{
int v2; // edx
__int64 result; // rax
void *v4[7]; // [rsp+0h] [rbp-98h] BYREF
__m128i v5; // [rsp+38h] [rbp-60h]
__int64 v6; // [rsp+48h] [rbp-50h]

v2 = func1(v4);
result = 0LL;
if ( v2 >= 0 )
{
v5 = _mm_loadu_si128(a2);
v6 = a2[1].m128i_i64[0];
if ( (int)dofmt(v4, a1) < 0 )
{
free(v4[1]);
result = 0LL;
}
else
{
result = fmtstrflush(v4);
}
}
return result;
}

original_code:
char*
vsmprint(char *fmt, va_list args)
{
 Fmt f;
 int n;
 if(fmtstrinit(&f) < 0)
  return 0;
 __builtin_va_copy(f.args,args);
 n = dofmt(&f, fmt);
 __builtin_va_end(f.args);
 if(n < 0){
  free(f.start);
  return 0;
 }
 return fmtstrflush(&f);
}

canonical_original_code:
char *vsmprint(char *fmt, __builtin_va_list args)
{
 struct Fmt f;
 int n;
 if(fmtstrinit(&f) < 0)
  return 0;
 __builtin_va_copy(f.args,args);
 n = dofmt(&f, fmt);
 __builtin_va_end(f.args);
 if(n < 0){
  free(f.start);
  return 0;
 }
 return fmtstrflush(&f);
}

variable_types:
fmt
char *

variable_types: struct Fmt { unsigned char runes; void *start; void *to; void *stop; int (*flush)(struct Fmt *); void *farg; int nfmt; __builtin_va_list args; unsigned int r; int width; int prec; unsigned long flags; char *decimal; char *thousands; char *grouping; }


fdirconv

original_code:
static void
fdirconv(char *buf, char *e, Dir *d)
{
 char tmp[16];
 seprint(buf, e, "'%s' '%s' '%s' '%s' "
  "q " "(%.16llux %lud %s)" " m %#luo "
  "at %ld mt %ld l %lld "
  "t %d d %d",
   d->name, d->uid, d->gid, d->muid,
   d->qid.path, d->qid.vers, qidtype(tmp, d->qid.type), d->mode,
   d->atime, d->mtime, d->length,
   d->type, d->dev);
}

canonical_original_code:
static void fdirconv(char *buf, char *e, struct Dir *d)
{
 char tmp[16];
 seprint(buf, e, "'%s' '%s' '%s' '%s' "
  "q " "(%.16llux %lud %s)" " m %#luo "
  "at %ld mt %ld l %lld "
  "t %d d %d",
   d->name, d->uid, d->gid, d->muid,
   d->qid.path, d->qid.vers, qidtype(tmp, d->qid.type), d->mode,
   d->atime, d->mtime, d->length,
   d->type, d->dev);
}

variable_types:
buf
char *

variable_types:
e
char *

variable_types: struct Dir { unsigned short type; unsigned int dev; struct Qid { unsigned long long path; unsigned long vers; unsigned char type; } qid; unsigned long mode; unsigned long atime; unsigned long mtime; long long length; char *name; char *uid; char *gid; char *muid; unsigned int uidnum; unsigned int gidnum; unsigned int muidnum; char *ext; } *

variable_types:
tmp
char [16]


runestrcat

decompiled_code:
__int64 __fastcall runestrcat(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = runestrchr(a1, 0LL);
runestrcpy(v2, a2);
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = runestrchr(a1, 0LL);
runestrcpy(v2, a2);
return a1;
}

original_code:
Rune*
runestrcat(Rune *s1, Rune *s2)
{
 runestrcpy(runestrchr(s1, 0), s2);
 return s1;
}

canonical_original_code:
unsigned int *runestrcat(unsigned int *s1, unsigned int *s2)
{
 runestrcpy(runestrchr(s1, 0), s2);
 return s1;
}

return_type: unsigned int *


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

if ( a1 < 0 )
return a1;
do
v1 = p9lrand();
while ( 0x7FFFFFFF % a1 >= v1 );
return v1 % a1;
}

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

if ( a1 < 0 )
return a1;
do
v1 = p9lrand();
while ( 0x7FFFFFFF % a1 >= v1 );
return v1 % a1;
}

original_code:
long
p9lnrand(long n)
{
 long slop, v;
 if(n < 0)
  return n;
 slop = 0x7fffffffL % n;
 do
  v = p9lrand();
 while(v <= slop);
 return v % n;
}

canonical_original_code:
long p9lnrand(long n)
{
 long slop; long v;
 if(n < 0)
  return n;
 slop = 0x7fffffffL % n;
 do
  v = p9lrand();
 while(v <= slop);
 return v % n;
}

variable_types: n long

variable_types: slop long

variable_types: v long


notifier

decompiled_code:
__int64 __fastcall notifier(__int64 a1, __int64 a2)
{
__int64 *v2; // rbx

v2 = &onnot;
do
{
if ( *v2 && ((unsigned int (__fastcall *)(__int64, __int64))*v2)(a1, a2) )
return noted(0LL);
++v2;
}
while ( v2 != (__int64 *)&unk_268 );
return noted(1LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 *v2; // rbx

v2 = &onnot;
do
{
if ( *v2 && ((unsigned int (__fastcall *)(__int64, __int64))*v2)(a1, a2) )
return noted(0LL);
++v2;
}
while ( v2 != (__int64 *)&unk_268 );
return noted(1LL);
}

original_code:
static
void
notifier(void *v, char *s)
{
 int i;
 for(i=0; i<33; i++)
  if(onnot[i] && ((*onnot[i])(v, s))){
   noted(0);
   return;
  }
 noted(1);
}

variable_types:
v
void *

variable_types: i int


atnotify

decompiled_code:
__int64 __fastcall atnotify(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rax
unsigned int v4; // er12
__int64 *v5; // rax

v2 = a2;
if ( !init_0 )
{
notify(notifier);
init_0 = 1;
}
lock(&onnotlock);
if ( a2 )
{
v3 = 0LL;
while ( onnot[v3] )
{
if ( ++v3 == 33 )
{
v4 = 0;
goto LABEL_18;
}
}
onnot[(int)v3] = a1;
v4 = 1;
}
else
{
v5 = onnot;
v4 = 0;
do
{
if ( *v5 )
{
if ( *v5 != a1 || v4 )
{
++v2;
}
else
{
*v5 = 0LL;
v4 = 1;
}
}
++v5;
}
while ( v5 != (__int64 *)&unk_268 );
if ( !v2 )
{
init_0 = 0;
notify(0LL);
}
}
LABEL_18:
unlock(&onnotlock);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rax
unsigned int v4; // er12
__int64 *v5; // rax

v2 = a2;
if ( !init_0 )
{
notify(notifier);
init_0 = 1;
}
lock(&onnotlock);
if ( a2 )
{
v3 = 0LL;
while ( onnot[v3] )
{
if ( ++v3 == 33 )
{
v4 = 0;
goto LABEL_18;
}
}
onnot[(int)v3] = a1;
v4 = 1;
}
else
{
v5 = onnot;
v4 = 0;
do
{
if ( *v5 )
{
if ( *v5 != a1 || v4 )
{
++v2;
}
else
{
*v5 = 0LL;
v4 = 1;
}
}
++v5;
}
while ( v5 != (__int64 *)&unk_268 );
if ( !v2 )
{
init_0 = 0;
notify(0LL);
}
}
LABEL_18:
unlock(&onnotlock);
return v4;
}

original_code:
int
atnotify(int (*f)(void*, char*), int in)
{
 int i, n, ret;
 static int init;
 if(!init){
  notify(notifier);
  init = 1;
 }
 ret = 0;
 lock(&onnotlock);
 if(in){
  for(i=0; i<33; i++)
   if(onnot[i] == 0) {
    onnot[i] = f;
    ret = 1;
    break;
   }
 }else{
  n = 0;
  for(i=0; i<33; i++)
   if(onnot[i]){
    if(ret==0 && onnot[i]==f){
     onnot[i] = 0;
     ret = 1;
    }else
     n++;
   }
  if(n == 0){
   init = 0;
   notify(0);
  }
 }
 unlock(&onnotlock);
 return ret;
}

canonical_original_code:
int atnotify(int (*f)(void *, char *), int in)
{
 int i; int n; int ret;
 static int init;
 if(!init){
  notify(notifier);
  init = 1;
 }
 ret = 0;
 lock(&onnotlock);
 if(in){
  for(i=0; i<33; i++)
   if(onnot[i] == 0) {
    onnot[i] = f;
    ret = 1;
    break;
   }
 }else{
  n = 0;
  for(i=0; i<33; i++)
   if(onnot[i]){
    if(ret==0 && onnot[i]==f){
     onnot[i] = 0;
     ret = 1;
    }else
     n++;
   }
  if(n == 0){
   init = 0;
   notify(0);
  }
 }
 unlock(&onnotlock);
 return ret;
}

variable_types:
f
int (*)(void *, char *)

variable_types: in int

variable_types: ret int

variable_types: init int


decompiled_code:
__int64 __fastcall p9atol(const char *a1)
{
return strtol(a1, 0LL, 0);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
return strtol(a1, 0LL, 0);
}

original_code:
long
p9atol(char *s)
{
 return strtol(s, 0, 0);
}

variable_types:
s
char *


Bputrune

decompiled_code:
__int64 __fastcall Bputrune(__int64 a1, unsigned int a2)
{
signed int v2; // eax
unsigned int v3; // ebx
char v5[4]; // [rsp+8h] [rbp-20h] BYREF
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = a2;
if ( a2 <= 0x7F )
{
Bputc();
v3 = 1;
}
else
{
v2 = runetochar(v5, v6);
v3 = v2;
if ( v2 )
{
if ( v2 != Bwrite(a1, v5, v2) )
v3 = -1;
}
else
{
v3 = -2;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
signed int v2; // eax
unsigned int v3; // ebx
char v5[4]; // [rsp+8h] [rbp-20h] BYREF
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = a2;
if ( a2 <= 0x7F )
{
Bputc();
v3 = 1;
}
else
{
v2 = runetochar(v5, v6);
v3 = v2;
if ( v2 )
{
if ( v2 != Bwrite(a1, v5, v2) )
v3 = -1;
}
else
{
v3 = -2;
}
}
return v3;
}

original_code:
int
Bputrune(Biobuf *bp, long c)
{
 Rune rune;
 char str[UTFmax];
 int n;
 rune = c;
 if(rune < Runeself) {
  Bputc(bp, rune);
  return 1;
 }
 n = runetochar(str, &rune);
 if(n == 0)
  return Bbad;
 if(Bwrite(bp, str, n) != n)
  return Beof;
 return n;
}

canonical_original_code:
int Bputrune(struct Biobuf *bp, long c)
{
 unsigned int rune;
 char str[-1];
 int n;
 rune = c;
 if(rune < Runeself) {
  Bputc(bp, rune);
  return 1;
 }
 n = runetochar(str, &rune);
 if(n == 0)
  return Bbad;
 if(Bwrite(bp, str, n) != n)
  return Beof;
 return n;
}

variable_types: struct Biobuf { int icount; int ocount; int rdline; int runesize; int state; int fid; int flag; long long offset; int bsize; unsigned char *bbuf; unsigned char *ebuf; unsigned char *gbuf; unsigned char b[-1]; } *

variable_types: c long

variable_types:
rune
unsigned int

variable_types:
str
char [-1]

variable_types: n int


setmalloctag

decompiled_code:
void setmalloctag()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void
setmalloctag(void *v, ulong t)
{
 ((void)(v));
 ((void)(t));
}

canonical_original_code:
void setmalloctag(void *v, unsigned long t)
{
 ((void)(v));
 ((void)(t));
}

variable_types:
t
unsigned long


setrealloctag

decompiled_code:
void setrealloctag()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void
setrealloctag(void *v, ulong t)
{
 ((void)(v));
 ((void)(t));
}

canonical_original_code:
void setrealloctag(void *v, unsigned long t)
{
 ((void)(v));
 ((void)(t));
}


decompiled_code:
void __fastcall __noreturn p9longjmp(struct __jmp_buf_tag *a1, int a2)
{
siglongjmp(a1, a2);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(struct __jmp_buf_tag *a1, int a2)
{
siglongjmp(a1, a2);
}

original_code:
void
p9longjmp(p9jmp_buf buf, int val)
{
 siglongjmp((void*)buf, val);
}

canonical_original_code:
void p9longjmp(long buf[-1], int val)
{
 siglongjmp((void *)buf, val);
}

variable_types:
buf
long [-1]

variable_types: val int


decompiled_code:
void __fastcall __noreturn p9notejmp(__int64 a1, struct __jmp_buf_tag *a2, int a3)
{
siglongjmp(a2, a3);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1, struct __jmp_buf_tag *a2, int a3)
{
siglongjmp(a2, a3);
}

original_code:
void
p9notejmp(void *x, p9jmp_buf buf, int val)
{
 ((void)(x));
 siglongjmp((void*)buf, val);
}

canonical_original_code:
void p9notejmp(void *x, long buf[-1], int val)
{
 ((void)(x));
 siglongjmp((void *)buf, val);
}

variable_types:
x
void *


postnote

decompiled_code:
int __fastcall postnote(int a1, __pid_t a2, __int64 a3)
{
int v3; // eax
int v4; // ebp
int result; // eax
int v6; // edi

v3 = p9strsig(a3);
if ( v3 )
{
v4 = v3;
if ( a1 == 1 )
{
result = kill(a2, v3);
}
else if ( a1 == 2 )
{
v6 = getpgid(a2);
if ( v6 < 0 )
result = -1;
else
result = killpg(v6, v4);
}
else
{
werrstr("bad who in postnote");
result = -1;
}
}
else
{
werrstr("unknown note");
result = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, __pid_t a2, __int64 a3)
{
int v3; // eax
int v4; // ebp
int result; // eax
int v6; // edi

v3 = p9strsig(a3);
if ( v3 )
{
v4 = v3;
if ( a1 == 1 )
{
result = kill(a2, v3);
}
else if ( a1 == 2 )
{
v6 = getpgid(a2);
if ( v6 < 0 )
result = -1;
else
result = killpg(v6, v4);
}
else
{
werrstr("bad who in postnote");
result = -1;
}
}
else
{
werrstr("unknown note");
result = -1;
}
return result;
}

original_code:
int
postnote(int who, int pid, char *msg)
{
 int sig;
 sig = _p9strsig(msg);
 if(sig == 0){
  werrstr("unknown note");
  return -1;
 }
 switch(who){
 default:
  werrstr("bad who in postnote");
  return -1;
 case PNPROC:
  return kill(pid, sig);
 case PNGROUP:
  if((pid = getpgid(pid)) < 0)
   return -1;
  return killpg(pid, sig);
 }
}

variable_types: who int

variable_types: pid int

variable_types:
msg
char *

variable_types: sig int


Bread

original_code:
long
Bread(Biobuf *bp, void *ap, long count)
{
 long c;
 unsigned char *p;
 int i, n, ic;
 p = ap;
 c = count;
 ic = bp->icount;
 while(c > 0) {
  n = -ic;
  if(n > c)
   n = c;
  if(n == 0) {
   if(bp->state != Bractive)
    break;
   i = read(bp->fid, bp->bbuf, bp->bsize);
   if(i <= 0) {
    bp->state = Bracteof;
    if(i < 0)
     bp->state = Binactive;
    break;
   }
   bp->gbuf = bp->bbuf;
   bp->offset += i;
   if(i < bp->bsize) {
    memmove(bp->ebuf-i, bp->bbuf, i);
    bp->gbuf = bp->ebuf-i;
   }
   ic = -i;
   continue;
  }
  memmove(p, bp->ebuf+ic, n);
  c -= n;
  ic += n;
  p += n;
 }
 bp->icount = ic;
 return count-c;
}

canonical_original_code:
long Bread(struct Biobuf *bp, void *ap, long count)
{
 long c;
 unsigned char *p;
 int i; int n; int ic;
 p = ap;
 c = count;
 ic = bp->icount;
 while(c > 0) {
  n = -ic;
  if(n > c)
   n = c;
  if(n == 0) {
   if(bp->state != Bractive)
    break;
   i = read(bp->fid, bp->bbuf, bp->bsize);
   if(i <= 0) {
    bp->state = Bracteof;
    if(i < 0)
     bp->state = Binactive;
    break;
   }
   bp->gbuf = bp->bbuf;
   bp->offset += i;
   if(i < bp->bsize) {
    memmove(bp->ebuf-i, bp->bbuf, i);
    bp->gbuf = bp->ebuf-i;
   }
   ic = -i;
   continue;
  }
  memmove(p, bp->ebuf+ic, n);
  c -= n;
  ic += n;
  p += n;
 }
 bp->icount = ic;
 return count-c;
}

variable_types:
ap
void *

variable_types: count long

variable_types:
p
unsigned char *

variable_types: i int

variable_types: ic int

user_defined_types: struct Biobuf { int icount; int ocount; int rdline; int runesize; int state; int fid; int flag; long long offset; int bsize; unsigned char *bbuf; unsigned char *ebuf; unsigned char *gbuf; unsigned char b[-1]; }


runefmtstrflush

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

result = *(_QWORD *)(a1 + 8);
if ( result )
{
**(_DWORD **)(a1 + 16) = 0;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = result;
}
return result;
}

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

result = *(_QWORD *)(a1 + 8);
if ( result )
{
**(_DWORD **)(a1 + 16) = 0;
result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = result;
}
return result;
}

original_code:
Rune*
runefmtstrflush(Fmt *f)
{
 if(f->start == 0)
  return 0;
 *(Rune*)f->to = '\0';
 f->to = f->start;
 return f->start;
}

canonical_original_code:
unsigned int *runefmtstrflush(struct Fmt *f)
{
 if(f->start == 0)
  return 0;
 *(unsigned int *)f->to = '\0';
 f->to = f->start;
 return f->start;
}

variable_types: struct Fmt { unsigned char runes; void *start; void *to; void *stop; int (*flush)(struct Fmt *); void *farg; int nfmt; __builtin_va_list args; unsigned int r; int width; int prec; unsigned long flags; char *decimal; char *thousands; char *grouping; } *