dirpackage

original_code:
static int
dirpackage(int fd, char *buf, int n, Dir **dp)
{
 int oldwd;
 char *p, *str, *estr;
 int i, nstr, m;
 struct dirent *de;
 struct stat st, lst;
 Dir *d;
 n = countde(buf, n);
 if(n <= 0)
  return n;
 if((oldwd = open(".", 00)) < 0)
  return -1;
 if(fchdir(fd) < 0)
  return -1;
 p = buf;
 nstr = 0;
 for(i=0; i<n; i++){
  de = (struct dirent*)p;
  memset(&lst, 0, sizeof lst);
  if(de->d_name[0] == 0)
                 {}
  else if(lstat(de->d_name, &lst) < 0)
   de->d_name[0] = 0;
  else{
   st = lst;
   if(((((lst.st_mode)) & 0170000) == (0120000)))
    stat(de->d_name, &st);
   nstr += _p9dir(&lst, &st, de->d_name, ((void*)0), ((void*)0), ((void*)0));
  }
  p += de->d_reclen;
 }
 d = malloc(sizeof(Dir)*n+nstr);
 if(d == ((void*)0)){
  fchdir(oldwd);
  close(oldwd);
  return -1;
 }
 str = (char*)&d[n];
 estr = str+nstr;
 p = buf;
 m = 0;
 for(i=0; i<n; i++){
  de = (struct dirent*)p;
  if(de->d_name[0] != 0 && lstat(de->d_name, &lst) >= 0){
   st = lst;
   if((lst.st_mode&0170000) == 0120000)
    stat(de->d_name, &st);
   _p9dir(&lst, &st, de->d_name, &d[m++], &str, estr);
  }
  p += de->d_reclen;
 }
 fchdir(oldwd);
 close(oldwd);
 *dp = d;
 return m;
}

canonical_original_code:
static int dirpackage(int fd, char *buf, int n, struct Dir **dp)
{
 int oldwd;
 char *p; char *str; char *estr;
 int i; int nstr; int m;
 struct dirent *de;
 struct stat st; struct stat lst;
 struct Dir *d;
 n = countde(buf, n);
 if(n <= 0)
  return n;
 if((oldwd = open(".", 00)) < 0)
  return -1;
 if(fchdir(fd) < 0)
  return -1;
 p = buf;
 nstr = 0;
 for(i=0; i<n; i++){
  de = (struct dirent *)p;
  memset(&lst, 0, sizeof lst);
  if(de->d_name[0] == 0)
                 {}
  else if(lstat(de->d_name, &lst) < 0)
   de->d_name[0] = 0;
  else{
   st = lst;
   if(((((lst.st_mode)) & 0170000) == (0120000)))
    stat(de->d_name, &st);
   nstr += _p9dir(&lst, &st, de->d_name, ((void *)0), ((void *)0), ((void *)0));
  }
  p += de->d_reclen;
 }
 d = malloc(sizeof(Dir)*n+nstr);
 if(d == ((void *)0)){
  fchdir(oldwd);
  close(oldwd);
  return -1;
 }
 str = (char *)&d[n];
 estr = str+nstr;
 p = buf;
 m = 0;
 for(i=0; i<n; i++){
  de = (struct dirent *)p;
  if(de->d_name[0] != 0 && lstat(de->d_name, &lst) >= 0){
   st = lst;
   if((lst.st_mode&0170000) == 0120000)
    stat(de->d_name, &st);
   _p9dir(&lst, &st, de->d_name, &d[m++], &str, estr);
  }
  p += de->d_reclen;
 }
 fchdir(oldwd);
 close(oldwd);
 *dp = d;
 return m;
}

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: oldwd int

variable_types:
str
char *

variable_types:
estr
char *

variable_types: i int

variable_types: nstr int

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

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

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


dirread

decompiled_code:
__int64 __fastcall dirread(int fd, _QWORD *a2)
{
int v3; // ebx
__blksize_t v4; // rdi
char *v5; // rax
char *v6; // rbp
int v7; // edx
int v8; // er12
struct stat64 v10; // [rsp+0h] [rbp-B8h] BYREF

*a2 = 0LL;
if ( fstat64(fd, &v10) >= 0 )
{
v3 = v10.st_blksize;
v4 = v10.st_blksize;
if ( v10.st_blksize <= 0x1FFF )
{
v10.st_blksize = 0x2000LL;
v4 = 0x2000LL;
v3 = 0x2000;
}
v5 = (char *)malloc(v4);
v6 = v5;
if ( v5 )
{
v7 = mygetdents((unsigned int)fd, v5, v3);
if ( v7 >= 0 )
{
v8 = dirpackage(fd, (unsigned __int64)v6, v7, a2);
free(v6);
return v8;
}
free(v6);
}
}
return -1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, _QWORD *a2)
{
int v3; // ebx
__blksize_t v4; // rdi
char *v5; // rax
char *v6; // rbp
int v7; // edx
int v8; // er12
struct stat64 v10; // [rsp+0h] [rbp-B8h] BYREF

*a2 = 0LL;
if ( fstat64(fd, &v10) >= 0 )
{
v3 = v10.st_blksize;
v4 = v10.st_blksize;
if ( v10.st_blksize <= 0x1FFF )
{
v10.st_blksize = 0x2000LL;
v4 = 0x2000LL;
v3 = 0x2000;
}
v5 = (char *)malloc(v4);
v6 = v5;
if ( v5 )
{
v7 = func1((unsigned int)fd, v5, v3);
if ( v7 >= 0 )
{
v8 = func2(fd, (unsigned __int64)v6, v7, a2);
free(v6);
return v8;
}
free(v6);
}
}
return -1LL;
}

original_code:
long
dirread(int fd, Dir **dp)
{
 char *buf;
 struct stat st;
 int n;
 *dp = 0;
 if(fstat(fd, &st) < 0)
  return -1;
 if(st.st_blksize < 8192)
  st.st_blksize = 8192;
 buf = malloc(st.st_blksize);
 if(buf == ((void*)0))
  return -1;
 n = mygetdents(fd, (void*)buf, st.st_blksize);
 if(n < 0){
  free(buf);
  return -1;
 }
 n = dirpackage(fd, buf, n, dp);
 free(buf);
 return n;
}

canonical_original_code:
long dirread(int fd, struct Dir **dp)
{
 char *buf;
 struct stat st;
 int n;
 *dp = 0;
 if(fstat(fd, &st) < 0)
  return -1;
 if(st.st_blksize < 8192)
  st.st_blksize = 8192;
 buf = malloc(st.st_blksize);
 if(buf == ((void *)0))
  return -1;
 n = mygetdents(fd, (void *)buf, st.st_blksize);
 if(n < 0){
  free(buf);
  return -1;
 }
 n = dirpackage(fd, buf, n, dp);
 free(buf);
 return n;
}

variable_types: fd int

variable_types:
buf
char *

variable_types: n int

return_type: long

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

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


dirreadall

decompiled_code:
__int64 __fastcall dirreadall(int fd, _QWORD *a2)
{
__blksize_t v2; // rbx
__int64 v3; // r12
void *i; // r15
void *v5; // rax
void *v6; // rbp
int v7; // eax
__int64 v8; // rbx
__int64 v9; // r12
struct stat64 v11; // [rsp+0h] [rbp-C8h] BYREF

if ( fstat64(fd, &v11) < 0 )
return -1LL;
v2 = v11.st_blksize;
if ( v11.st_blksize <= 0x1FFF )
{
v11.st_blksize = 0x2000LL;
v2 = 0x2000LL;
}
v3 = 0LL;
for ( i = 0LL; ; i = v6 )
{
v5 = realloc(i, v3 + v2);
v6 = v5;
if ( !v5 )
{
free(i);
return -1LL;
}
v7 = mygetdents((unsigned int)fd, (char *)v5 + v3, v2);
v8 = v7;
if ( v7 <= 0 )
break;
v3 += v7;
v2 = v11.st_blksize;
}
v9 = (int)dirpackage(fd, (unsigned __int64)v6, v3, a2);
free(v6);
if ( !v9 && v8 < 0 )
return -1LL;
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, _QWORD *a2)
{
__blksize_t v2; // rbx
__int64 v3; // r12
void *i; // r15
void *v5; // rax
void *v6; // rbp
int v7; // eax
__int64 v8; // rbx
__int64 v9; // r12
struct stat64 v11; // [rsp+0h] [rbp-C8h] BYREF

if ( fstat64(fd, &v11) < 0 )
return -1LL;
v2 = v11.st_blksize;
if ( v11.st_blksize <= 0x1FFF )
{
v11.st_blksize = 0x2000LL;
v2 = 0x2000LL;
}
v3 = 0LL;
for ( i = 0LL; ; i = v6 )
{
v5 = realloc(i, v3 + v2);
v6 = v5;
if ( !v5 )
{
free(i);
return -1LL;
}
v7 = func1((unsigned int)fd, (char *)v5 + v3, v2);
v8 = v7;
if ( v7 <= 0 )
break;
v3 += v7;
v2 = v11.st_blksize;
}
v9 = (int)func2(fd, (unsigned __int64)v6, v3, a2);
free(v6);
if ( !v9 && v8 < 0 )
return -1LL;
return v9;
}

original_code:
long
dirreadall(int fd, Dir **d)
{
 uchar *buf, *nbuf;
 long n, ts;
 struct stat st;
 if(fstat(fd, &st) < 0)
  return -1;
 if(st.st_blksize < 8192)
  st.st_blksize = 8192;
 buf = ((void*)0);
 ts = 0;
 for(;;){
  nbuf = realloc(buf, ts+st.st_blksize);
  if(nbuf == ((void*)0)){
   free(buf);
   return -1;
  }
  buf = nbuf;
  n = mygetdents(fd, (void*)(buf+ts), st.st_blksize);
  if(n <= 0)
   break;
  ts += n;
 }
 if(ts >= 0)
  ts = dirpackage(fd, (char*)buf, ts, d);
 free(buf);
 if(ts == 0 && n < 0)
  return -1;
 return ts;
}

canonical_original_code:
long dirreadall(int fd, struct Dir **d)
{
 unsigned char *buf; unsigned char *nbuf;
 long n; long ts;
 struct stat st;
 if(fstat(fd, &st) < 0)
  return -1;
 if(st.st_blksize < 8192)
  st.st_blksize = 8192;
 buf = ((void *)0);
 ts = 0;
 for(;;){
  nbuf = realloc(buf, ts+st.st_blksize);
  if(nbuf == ((void *)0)){
   free(buf);
   return -1;
  }
  buf = nbuf;
  n = mygetdents(fd, (void *)(buf+ts), st.st_blksize);
  if(n <= 0)
   break;
  ts += n;
 }
 if(ts >= 0)
  ts = dirpackage(fd, (char *)buf, ts, d);
 free(buf);
 if(ts == 0 && n < 0)
  return -1;
 return ts;
}

variable_types:
buf
unsigned char *

variable_types:
nbuf
unsigned char *

variable_types: n long

variable_types: ts long


isme

decompiled_code:
_BOOL8 __fastcall isme(char *s2)
{
int v1; // ebx
const char *v2; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v1 = strtol(s2, &endptr, 10);
if ( !*endptr && endptr > s2 )
return getuid() == v1;
v2 = (const char *)getuser();
return strcmp(v2, s2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(char *s2)
{
int v1; // ebx
const char *v2; // rax
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v1 = strtol(s2, &endptr, 10);
if ( !*endptr && endptr > s2 )
return getuid() == v1;
v2 = (const char *)getuser();
return strcmp(v2, s2) == 0;
}

original_code:
static int
isme(char *uid)
{
 int n;
 char *p;
 n = strtol(uid, &p, 10);
 if(*p == 0 && p > uid)
  return n == getuid();
 return strcmp(getuser(), uid) == 0;
}

variable_types:
uid
char *

variable_types:
p
char *

return_type: int


nsfromdisplay

decompiled_code:
const char *nsfromdisplay()
{
const char *v0; // rax
const char *v1; // rbp
char *v2; // rax
unsigned __int8 *v3; // rbx
const unsigned __int16 *v4; // rdx
char v5; // dl
char *v6; // rax
const char *v7; // rax
const char *v8; // r12
int v9; // edi
__int64 v10; // rax
__int64 v11; // rbp
const char *result; // rax
const char *v13; // rdi

v0 = (const char *)p9getenv("DISPLAY");
if ( !v0 )
{
v8 = 0LL;
werrstr("$DISPLAY not set");
return v8;
}
v1 = v0;
v2 = strrchr(v0, 58);
if ( v2 )
{
v3 = (unsigned __int8 *)(v2 + 1);
v4 = *_ctype_b_loc();
while ( (v4[*v3] & 0x800) != 0 )
++v3;
if ( *v3 == 46 && v3[1] == 48 && !v3[2] )
*v3 = 0;
}
v5 = *v1;
if ( *v1 )
{
v6 = (char *)v1;
do
{
if ( v5 == 47 )
*v6 = 95;
v5 = *++v6;
}
while ( v5 );
}
v7 = (const char *)getuser();
v8 = (const char *)smprint("/tmp/ns.%s.%s", v7, v1);
p9free(v1);
if ( !v8 )
{
werrstr("out of memory");
return v8;
}
v9 = p9create(v8, 0LL, 2147484096LL);
if ( v9 >= 0 )
{
close(v9);
result = v8;
}
else
{
v10 = dirstat(v8);
v11 = v10;
if ( !v10 )
{
p9free(0LL);
werrstr("stat %s: %r", v8);
v13 = v8;
v8 = 0LL;
p9free(v13);
return v8;
}
if ( (*(_QWORD *)(v10 + 32) & 0x1FFLL) == 448 && isme(*(char **)(v10 + 72)) )
{
p9free(v11);
return v8;
}
werrstr("bad name space dir %s", v8);
p9free(v8);
p9free(v11);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
const char *func1()
{
const char *v0; // rax
const char *v1; // rbp
char *v2; // rax
unsigned __int8 *v3; // rbx
const unsigned __int16 *v4; // rdx
char v5; // dl
char *v6; // rax
const char *v7; // rax
const char *v8; // r12
int v9; // edi
__int64 v10; // rax
__int64 v11; // rbp
const char *result; // rax
const char *v13; // rdi

v0 = (const char *)p9getenv("DISPLAY");
if ( !v0 )
{
v8 = 0LL;
werrstr("$DISPLAY not set");
return v8;
}
v1 = v0;
v2 = strrchr(v0, 58);
if ( v2 )
{
v3 = (unsigned __int8 *)(v2 + 1);
v4 = *_ctype_b_loc();
while ( (v4[*v3] & 0x800) != 0 )
++v3;
if ( *v3 == 46 && v3[1] == 48 && !v3[2] )
*v3 = 0;
}
v5 = *v1;
if ( *v1 )
{
v6 = (char *)v1;
do
{
if ( v5 == 47 )
*v6 = 95;
v5 = *++v6;
}
while ( v5 );
}
v7 = (const char *)getuser();
v8 = (const char *)smprint("/tmp/ns.%s.%s", v7, v1);
p9free(v1);
if ( !v8 )
{
werrstr("out of memory");
return v8;
}
v9 = p9create(v8, 0LL, 2147484096LL);
if ( v9 >= 0 )
{
close(v9);
result = v8;
}
else
{
v10 = dirstat(v8);
v11 = v10;
if ( !v10 )
{
p9free(0LL);
werrstr("stat %s: %r", v8);
v13 = v8;
v8 = 0LL;
p9free(v13);
return v8;
}
if ( (*(_QWORD *)(v10 + 32) & 0x1FFLL) == 448 && func0(*(char **)(v10 + 72)) )
{
p9free(v11);
return v8;
}
werrstr("bad name space dir %s", v8);
p9free(v8);
p9free(v11);
result = 0LL;
}
return result;
}

original_code:
static char*
nsfromdisplay(void)
{
 int fd;
 Dir *d;
 char *disp, *p;
 if((disp = p9getenv("DISPLAY")) == ((void*)0)){
  werrstr("$DISPLAY not set");
  return ((void*)0);
 }
 p = strrchr(disp, ':');
 if(p){
  p++;
  while(((*__ctype_b_loc ())[(int) (((uchar)*p))] & (unsigned short int) _ISdigit))
   p++;
  if(strcmp(p, ".0") == 0)
   *p = 0;
 }
 for(p=disp; *p; p++)
  if(*p == '/')
   *p = '_';
 p = smprint("/tmp/ns.%s.%s", getuser(), disp);
 p9free(disp);
 if(p == ((void*)0)){
  werrstr("out of memory");
  return p;
 }
 if((fd=p9create(p, 0, 0x80000000|0700)) >= 0){
  close(fd);
  return p;
 }
 if((d = dirstat(p)) == ((void*)0)){
  p9free(d);
  werrstr("stat %s: %r", p);
  p9free(p);
  return ((void*)0);
 }
 if((d->mode&0777) != 0700 || !isme(d->uid)){
  werrstr("bad name space dir %s", p);
  p9free(p);
  p9free(d);
  return ((void*)0);
 }
 p9free(d);
 return p;
}

canonical_original_code:
static char *nsfromdisplay()
{
 int fd;
 struct Dir *d;
 char *disp; char *p;
 if((disp = p9getenv("DISPLAY")) == ((void *)0)){
  werrstr("$DISPLAY not set");
  return ((void *)0);
 }
 p = strrchr(disp, ':');
 if(p){
  p++;
  while(((*__ctype_b_loc ())[(int) (((uchar)*p))] & (unsigned short) _ISdigit))
   p++;
  if(strcmp(p, ".0") == 0)
   *p = 0;
 }
 for(p=disp; *p; p++)
  if(*p == '/')
   *p = '_';
 p = smprint("/tmp/ns.%s.%s", getuser(), disp);
 p9free(disp);
 if(p == ((void *)0)){
  werrstr("out of memory");
  return p;
 }
 if((fd=p9create(p, 0, 0x80000000|0700)) >= 0){
  close(fd);
  return p;
 }
 if((d = dirstat(p)) == ((void *)0)){
  p9free(d);
  werrstr("stat %s: %r", p);
  p9free(p);
  return ((void *)0);
 }
 if((d->mode&0777) != 0700 || !isme(d->uid)){
  werrstr("bad name space dir %s", p);
  p9free(p);
  p9free(d);
  return ((void *)0);
 }
 p9free(d);
 return p;
}

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:
disp
char *

return_type: char *


getns

decompiled_code:
const char *getns()
{
const char *v0; // r12

v0 = (const char *)p9getenv("NAMESPACE");
if ( !v0 )
{
v0 = nsfromdisplay();
if ( !v0 )
werrstr("$NAMESPACE not set, %r");
}
return v0;
}

canonical_decompiled_code:
const char *func2()
{
const char *v0; // r12

v0 = (const char *)p9getenv("NAMESPACE");
if ( !v0 )
{
v0 = func1();
if ( !v0 )
werrstr("$NAMESPACE not set, %r");
}
return v0;
}

original_code:
char*
getns(void)
{
 char *ns;
 ns = p9getenv("NAMESPACE");
 if(ns == ((void*)0))
  ns = nsfromdisplay();
 if(ns == ((void*)0)){
  werrstr("$NAMESPACE not set, %r");
  return ((void*)0);
 }
 return ns;
}

canonical_original_code:
char *getns()
{
 char *ns;
 ns = p9getenv("NAMESPACE");
 if(ns == ((void *)0))
  ns = nsfromdisplay();
 if(ns == ((void *)0)){
  werrstr("$NAMESPACE not set, %r");
  return ((void *)0);
 }
 return ns;
}

variable_types:
ns
char *


Bgetrune

decompiled_code:
__int64 __fastcall Bgetrune(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
int v3; // er12
int v5; // eax
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
char v7[28]; // [rsp+Ch] [rbp-1Ch] BYREF

LODWORD(result) = ((__int64 (*)(void))Bgetc)();
if ( (int)result <= 127 )
{
*(_DWORD *)(a1 + 12) = 1;
result = (int)result;
}
else
{
v7[0] = result;
v2 = 2LL;
do
{
LODWORD(result) = Bgetc(a1);
if ( (int)result < 0 )
return (int)result;
*((_BYTE *)&v6 + v2 + 3) = result;
v3 = v2;
}
while ( !(unsigned int)fullrune(v7, (unsigned int)v2++) );
v5 = chartorune(&v6, v7);
*(_DWORD *)(a1 + 12) = v5;
while ( *(_DWORD *)(a1 + 12) < v3 )
{
--v3;
Bungetc(a1);
}
result = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
int v3; // er12
int v5; // eax
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
char v7[28]; // [rsp+Ch] [rbp-1Ch] BYREF

LODWORD(result) = ((__int64 (*)(void))Bgetc)();
if ( (int)result <= 127 )
{
*(_DWORD *)(a1 + 12) = 1;
result = (int)result;
}
else
{
v7[0] = result;
v2 = 2LL;
do
{
LODWORD(result) = Bgetc(a1);
if ( (int)result < 0 )
return (int)result;
*((_BYTE *)&v6 + v2 + 3) = result;
v3 = v2;
}
while ( !(unsigned int)fullrune(v7, (unsigned int)v2++) );
v5 = chartorune(&v6, v7);
*(_DWORD *)(a1 + 12) = v5;
while ( *(_DWORD *)(a1 + 12) < v3 )
{
--v3;
Bungetc(a1);
}
result = v6;
}
return result;
}

original_code:
long
Bgetrune(Biobuf *bp)
{
 int c, i;
 Rune rune;
 char str[UTFmax];
 c = Bgetc(bp);
 if(c < Runeself) {
  bp->runesize = 1;
  return c;
 }
 str[0] = c;
 for(i=1;;) {
  c = Bgetc(bp);
  if(c < 0)
   return c;
  str[i++] = c;
  if(fullrune(str, i)) {
   bp->runesize = chartorune(&rune, str);
   while(i > bp->runesize) {
    Bungetc(bp);
    i--;
   }
   return rune;
  }
 }
}

canonical_original_code:
long Bgetrune(struct Biobuf *bp)
{
 int c; int i;
 unsigned int rune;
 char str[-1];
 c = Bgetc(bp);
 if(c < Runeself) {
  bp->runesize = 1;
  return c;
 }
 str[0] = c;
 for(i=1;;) {
  c = Bgetc(bp);
  if(c < 0)
   return c;
  str[i++] = c;
  if(fullrune(str, i)) {
   bp->runesize = chartorune(&rune, str);
   while(i > bp->runesize) {
    Bungetc(bp);
    i--;
   }
   return rune;
  }
 }
}

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 int

variable_types:
rune
unsigned int

variable_types:
str
char [-1]


Bungetrune

decompiled_code:
__int64 __fastcall Bungetrune(_DWORD *a1)
{
int v1; // eax
int v3; // eax

v1 = a1[4];
if ( v1 == 3 )
{
a1[4] = 1;
}
else if ( v1 != 1 )
{
return 0xFFFFFFFFLL;
}
v3 = a1[3];
a1[3] = 0;
*a1 -= v3;
return 1LL;
}

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

v1 = a1[4];
if ( v1 == 3 )
{
a1[4] = 1;
}
else if ( v1 != 1 )
{
return 0xFFFFFFFFLL;
}
v3 = a1[3];
a1[3] = 0;
*a1 -= v3;
return 1LL;
}

original_code:
int
Bungetrune(Biobuf *bp)
{
 if(bp->state == Bracteof)
  bp->state = Bractive;
 if(bp->state != Bractive)
  return Beof;
 bp->icount -= bp->runesize;
 bp->runesize = 0;
 return 1;
}

canonical_original_code:
int Bungetrune(struct Biobuf *bp)
{
 if(bp->state == Bracteof)
  bp->state = Bractive;
 if(bp->state != Bractive)
  return Beof;
 bp->icount -= bp->runesize;
 bp->runesize = 0;
 return 1;
}

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


searchpath

decompiled_code:
char *__fastcall searchpath(char *src)
{
char *v2; // r12
char v3; // al
int v4; // ebx
const char *v5; // r15
int v6; // er13
int v7; // er13
__int64 v8; // rax
char *v9; // rax
char *v10; // rax
const char *v11; // r14
char *v12; // rdi
__int64 v13; // [rsp+8h] [rbp-40h]

if ( *src == 46 )
{
v3 = src[1];
if ( v3 == 47 || v3 == 46 && src[2] == 47 )
goto LABEL_3;
goto LABEL_9;
}
if ( *src != 47 )
{
LABEL_9:
v4 = 0;
v2 = 0LL;
v13 = p9getenv("PATH");
v5 = (const char *)v13;
if ( !v13 )
{
LABEL_23:
v12 = v2;
v2 = 0LL;
p9free(v12);
p9free(v13);
return v2;
}
while ( 1 )
{
if ( !*v5 )
goto LABEL_23;
v10 = strchr(v5, 58);
if ( v10 )
{
*v10 = 0;
v11 = v10 + 1;
if ( !*v5 )
{
if ( access(src, 1) >= 0 )
{
p9free(v2);
p9free(v13);
return (char *)p9strdup(src);
}
goto LABEL_16;
}
}
else
{
v11 = 0LL;
}
v6 = strlen(v5);
v7 = v6 + strlen(src) + 2;
if ( v7 > v4 )
{
v8 = p9realloc(v2, v7);
if ( !v8 )
goto LABEL_23;
v4 = v7;
v2 = (char *)v8;
}
v9 = stpcpy(v2, v5);
*v9 = 47;
strcpy(v9 + 1, src);
if ( access(v2, 1) >= 0 )
{
p9free(v13);
return v2;
}
if ( !v11 )
goto LABEL_23;
LABEL_16:
v5 = v11;
}
}
LABEL_3:
if ( access(src, 1) >= 0 )
return (char *)p9strdup(src);
return 0LL;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
char *v2; // r12
char v3; // al
int v4; // ebx
const char *v5; // r15
int v6; // er13
int v7; // er13
__int64 v8; // rax
char *v9; // rax
char *v10; // rax
const char *v11; // r14
char *v12; // rdi
__int64 v13; // [rsp+8h] [rbp-40h]

if ( *src == 46 )
{
v3 = src[1];
if ( v3 == 47 || v3 == 46 && src[2] == 47 )
goto LABEL_3;
goto LABEL_9;
}
if ( *src != 47 )
{
LABEL_9:
v4 = 0;
v2 = 0LL;
v13 = p9getenv("PATH");
v5 = (const char *)v13;
if ( !v13 )
{
LABEL_23:
v12 = v2;
v2 = 0LL;
p9free(v12);
p9free(v13);
return v2;
}
while ( 1 )
{
if ( !*v5 )
goto LABEL_23;
v10 = strchr(v5, 58);
if ( v10 )
{
*v10 = 0;
v11 = v10 + 1;
if ( !*v5 )
{
if ( access(src, 1) >= 0 )
{
p9free(v2);
p9free(v13);
return (char *)p9strdup(src);
}
goto LABEL_16;
}
}
else
{
v11 = 0LL;
}
v6 = strlen(v5);
v7 = v6 + strlen(src) + 2;
if ( v7 > v4 )
{
v8 = p9realloc(v2, v7);
if ( !v8 )
goto LABEL_23;
v4 = v7;
v2 = (char *)v8;
}
v9 = stpcpy(v2, v5);
*v9 = 47;
strcpy(v9 + 1, src);
if ( access(v2, 1) >= 0 )
{
p9free(v13);
return v2;
}
if ( !v11 )
goto LABEL_23;
LABEL_16:
v5 = v11;
}
}
LABEL_3:
if ( access(src, 1) >= 0 )
return (char *)p9strdup(src);
return 0LL;
}

original_code:
char*
searchpath(char *name)
{
 char *path, *p, *next;
 char *s, *ss;
 int ns, l;
 s = ((void*)0);
 ns = 0;
 if((name[0] == '.' && name[1] == '/')
 || (name[0] == '.' && name[1] == '.' && name[2] == '/')
 || (name[0] == '/')){
  if(access(name, 1) >= 0)
   return p9strdup(name);
  return ((void*)0);
 }
 path = p9getenv("PATH");
 for(p=path; p && *p; p=next){
  if((next = strchr(p, ':')) != ((void*)0))
   *next++ = 0;
  if(*p == 0){
   if(access(name, 1) >= 0){
    p9free(s);
    p9free(path);
    return p9strdup(name);
   }
  }else{
   l = strlen(p)+1+strlen(name)+1;
   if(l > ns){
    ss = p9realloc(s, l);
    if(ss == ((void*)0)){
     p9free(s);
     p9free(path);
     return ((void*)0);
    }
    s = ss;
    ns = l;
   }
   strcpy(s, p);
   strcat(s, "/");
   strcat(s, name);
   if(access(s, 1) >= 0){
    p9free(path);
    return s;
   }
  }
 }
 p9free(s);
 p9free(path);
 return ((void*)0);
}

canonical_original_code:
char *searchpath(char *name)
{
 char *path; char *p; char *next;
 char *s; char *ss;
 int ns; int l;
 s = ((void *)0);
 ns = 0;
 if((name[0] == '.' && name[1] == '/')
 || (name[0] == '.' && name[1] == '.' && name[2] == '/')
 || (name[0] == '/')){
  if(access(name, 1) >= 0)
   return p9strdup(name);
  return ((void *)0);
 }
 path = p9getenv("PATH");
 for(p=path; p && *p; p=next){
  if((next = strchr(p, ':')) != ((void *)0))
   *next++ = 0;
  if(*p == 0){
   if(access(name, 1) >= 0){
    p9free(s);
    p9free(path);
    return p9strdup(name);
   }
  }else{
   l = strlen(p)+1+strlen(name)+1;
   if(l > ns){
    ss = p9realloc(s, l);
    if(ss == ((void *)0)){
     p9free(s);
     p9free(path);
     return ((void *)0);
    }
    s = ss;
    ns = l;
   }
   strcpy(s, p);
   strcat(s, "/");
   strcat(s, name);
   if(access(s, 1) >= 0){
    p9free(path);
    return s;
   }
  }
 }
 p9free(s);
 p9free(path);
 return ((void *)0);
}

variable_types:
name
char *

variable_types:
path
char *

variable_types:
next
char *

variable_types:
s
char *

variable_types:
ss
char *

variable_types: ns int

variable_types: l int


runestrdup

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

v1 = runestrlen();
v2 = malloc(4 * v1 + 4);
if ( v2 )
result = runestrcpy(v2, a1);
else
result = 0LL;
return result;
}

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

v1 = runestrlen();
v2 = malloc(4 * v1 + 4);
if ( v2 )
result = runestrcpy(v2, a1);
else
result = 0LL;
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 *

return_type: unsigned int *


parsehead

decompiled_code:
__int64 parsehead()
{
__int64 v0; // rsi
int v1; // eax
int v2; // er8
int v3; // er9
__int64 result; // rax

v0 = tzdata;
if ( *(_BYTE *)(tzdata + 4) != 50 && *(_BYTE *)(tzdata + 4) )
return 0xFFFFFFFFLL;
z = get4((unsigned __int8 *)(tzdata + 32));
dword_4C4 = get4((unsigned __int8 *)(v0 + 36));
if ( !dword_4C4 )
return 0xFFFFFFFFLL;
v1 = get4((unsigned __int8 *)(v0 + 40));
qword_4D0 = v0 + 44;
dword_4C8 = v1;
qword_4D8 = 4 * v2 + v0 + 44;
qword_4E0 = v2 + qword_4D8;
result = 0LL;
qword_4E8 = 6 * v3 + qword_4E0;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rsi
int v1; // eax
int v2; // er8
int v3; // er9
__int64 result; // rax

v0 = tzdata;
if ( *(_BYTE *)(tzdata + 4) != 50 && *(_BYTE *)(tzdata + 4) )
return 0xFFFFFFFFLL;
z = func0((unsigned __int8 *)(tzdata + 32));
dword_4C4 = func0((unsigned __int8 *)(v0 + 36));
if ( !dword_4C4 )
return 0xFFFFFFFFLL;
v1 = func0((unsigned __int8 *)(v0 + 40));
qword_4D0 = v0 + 44;
dword_4C8 = v1;
qword_4D8 = 4 * v2 + v0 + 44;
qword_4E0 = v2 + qword_4D8;
result = 0LL;
qword_4E8 = 6 * v3 + qword_4E0;
return result;
}

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


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


readtzfile

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

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

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

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

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 *


readtimezone

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

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

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

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

v2 = *(unsigned __int8 *)(qword_4D8 + a2);
if ( dword_4C4 <= v2 )
_assert_fail("i<z.typecnt", "zoneinfo.c", 0x6Au, "ttinfo");
v3 = (unsigned __int8 *)(qword_4E0 + 6 * v2);
v4 = get4(v3);
*(_DWORD *)(v5 + 8) = v4;
*(_DWORD *)(v5 + 12) = v3[4];
if ( v3[5] >= dword_4C8 )
_assert_fail("p[5]<z.charcnt", "zoneinfo.c", 0x6Eu, "ttinfo");
result = qword_4E8 + v3[5];
*(_QWORD *)(v5 + 16) = result;
return result;
}

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

v2 = *(unsigned __int8 *)(qword_4D8 + a2);
if ( dword_4C4 <= v2 )
_assert_fail("i<z.typecnt", "zoneinfo.c", 0x6Au, "ttinfo");
v3 = (unsigned __int8 *)(qword_4E0 + 6 * v2);
v4 = func0(v3);
*(_DWORD *)(v5 + 8) = v4;
*(_DWORD *)(v5 + 12) = v3[4];
if ( v3[5] >= dword_4C8 )
_assert_fail("p[5]<z.charcnt", "zoneinfo.c", 0x6Eu, "ttinfo");
result = qword_4E8 + v3[5];
*(_QWORD *)(v5 + 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;
}
zonefile = a1;
z = 0;
return result;
}

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

if ( tzdata )
{
result = p9free(tzdata);
tzdata = 0LL;
}
zonefile = a1;
z = 0;
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; // eax

v2 = (unsigned __int64)a1 + a2;
if ( a2 > 0x30 && *a1 + 2 == a2 )
{
v3 = (unsigned __int16 *)((char *)a1 + 41);
v4 = 4;
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; // eax

v2 = (unsigned __int64)a1 + a2;
if ( a2 > 0x30 && *a1 + 2 == a2 )
{
v3 = (unsigned __int16 *)((char *)a1 + 41);
v4 = 4;
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


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 = &v6;
a5[1] = &v8;
a5[2] = &v7;
a5[3] = &v9;
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 = &v6;
a5[1] = &v8;
a5[2] = &v7;
a5[3] = &v9;
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 *


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

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

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

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

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 *


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

v1 = getenv(a1);
if ( v1 )
result = strdup(v1);
else
result = 0LL;
return result;
}

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

v1 = getenv(a1);
if ( v1 )
result = strdup(v1);
else
result = 0LL;
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, __int16 *a2, const char **a3, const char **a4, __int64 *a5)
{
__int16 v8; // ax
unsigned __int16 v10; // ax
const char *v11; // rsi
__int64 v12; // rax
__int64 v13; // rax
char *v14; // rax
socklen_t optlen; // [rsp+8h] [rbp-40h] BYREF
int optval[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v8 = *a2;
if ( *a2 == 2 )
{
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));
goto LABEL_8;
}
}
else
{
if ( v8 != 10 )
{
if ( v8 != 1 )
{
werrstr("unknown socket family");
return 0xFFFFFFFFLL;
}
*a3 = "unknown";
*a4 = "unknown";
v13 = smprint("unix!%s", (const char *)a2 + 2);
*a5 = v13;
return (unsigned int)-(v13 == 0);
}
if ( *(_QWORD *)in6addr_any.__u6_addr8 ^ *((_QWORD *)a2 + 1) | *(_QWORD *)&in6addr_any.__u6_addr32[2] ^ *((_QWORD *)a2 + 2) )
{
v14 = (char *)malloc(0x2EuLL);
*a3 = v14;
inet_ntop(10, a2 + 4, v14, 0x2Eu);
goto LABEL_8;
}
}
*a3 = strdup("*");
LABEL_8:
v10 = _bswap_16(a2[1]);
*a4 = (const char *)smprint("%d", v10);
optlen = 4;
if ( getsockopt(fd, 1, 3, optval, &optlen) < 0 )
return 0xFFFFFFFFLL;
if ( optval[0] == 1 )
{
v11 = (const char *)&unk_3D6;
}
else
{
if ( optval[0] != 2 )
{
werrstr("unknown network type");
return 0xFFFFFFFFLL;
}
v11 = (const char *)&unk_3DA;
}
v12 = smprint("%s!%s!%s", v11, *a3, *a4);
*a5 = v12;
if ( !*a3 || !*a4 || !v12 )
return 0xFFFFFFFFLL;
return 0LL;
}

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

v8 = *a2;
if ( *a2 == 2 )
{
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));
goto LABEL_8;
}
}
else
{
if ( v8 != 10 )
{
if ( v8 != 1 )
{
werrstr("unknown socket family");
return 0xFFFFFFFFLL;
}
*a3 = "unknown";
*a4 = "unknown";
v13 = smprint("unix!%s", (const char *)a2 + 2);
*a5 = v13;
return (unsigned int)-(v13 == 0);
}
if ( *(_QWORD *)in6addr_any.__u6_addr8 ^ *((_QWORD *)a2 + 1) | *(_QWORD *)&in6addr_any.__u6_addr32[2] ^ *((_QWORD *)a2 + 2) )
{
v14 = (char *)malloc(0x2EuLL);
*a3 = v14;
inet_ntop(10, a2 + 4, v14, 0x2Eu);
goto LABEL_8;
}
}
*a3 = strdup("*");
LABEL_8:
v10 = func0(a2[1]);
*a4 = (const char *)smprint("%d", v10);
optlen = 4;
if ( getsockopt(fd, 1, 3, optval, &optlen) < 0 )
return 0xFFFFFFFFLL;
if ( optval[0] == 1 )
{
v11 = (const char *)&unk_3D6;
}
else
{
if ( optval[0] != 2 )
{
werrstr("unknown network type");
return 0xFFFFFFFFLL;
}
v11 = (const char *)&unk_3DA;
}
v12 = smprint("%s!%s!%s", v11, *a3, *a4);
*a5 = v12;
if ( !*a3 || !*a4 || !v12 )
return 0xFFFFFFFFLL;
return 0LL;
}

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 )
{
if ( a1 != "unknown" )
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func2(char *a1)
{
if ( a1 )
{
if ( a1 != "unknown" )
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 i; // rax
unsigned __int64 v2; // rbx

lock(&onexlock);
for ( i = 0LL; i != 33; ++i )
{
if ( !onex[2 * i] )
{
v2 = 16LL * (int)i;
dword_168[v2 / 4] = getpid();
onex[v2 / 8] = a1;
unlock(&onexlock);
return 1LL;
}
}
unlock(&onexlock);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 i; // rax
unsigned __int64 v2; // rbx

lock(&onexlock);
for ( i = 0LL; i != 33; ++i )
{
if ( !onex[2 * i] )
{
v2 = 16LL * (int)i;
dword_168[v2 / 4] = getpid();
onex[v2 / 8] = a1;
unlock(&onexlock);
return 1LL;
}
}
unlock(&onexlock);
return 0LL;
}

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)
{
void (**v1)(void); // rbx
__pid_t v2; // ebp
void (*v3)(void); // rax
int v4; // eax

v1 = (void (**)(void))&unk_360;
v2 = getpid();
while ( 1 )
{
v3 = *v1;
if ( *v1 && *((_DWORD *)v1 + 2) == v2 )
{
*v1 = 0LL;
v3();
}
if ( v1 == (void (**)(void))onex )
{
if ( a1 )
{
if ( *a1 )
{
v4 = exitcode(a1);
exit(v4);
}
}
exit(0);
}
v1 -= 2;
}
}

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

v1 = (void (**)(void))&unk_360;
v2 = getpid();
while ( 1 )
{
v3 = *v1;
if ( *v1 && *((_DWORD *)v1 + 2) == v2 )
{
*v1 = 0LL;
v3();
}
if ( v1 == (void (**)(void))onex )
{
if ( a1 )
{
if ( *a1 )
{
v4 = exitcode(a1);
exit(v4);
}
}
exit(0);
}
v1 -= 2;
}
}

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(__int64 a1, __int64 *a2)
{
__int64 v2; // rax
__int64 i; // rdx
_BYTE *v4; // rcx
int v5; // er8
int v6; // edx
unsigned __int64 v8; // [rsp+0h] [rbp-10h] BYREF
__int64 v9; // [rsp+8h] [rbp-8h]

v2 = *a2;
for ( i = a2[1]; ; i = v9 )
{
while ( 1 )
{
v8 = 10 * v2;
v9 = 10 * i;
frnorm(&v8);
v5 = (char)*v4;
v2 = v8 & 0xFFFFFFF;
v6 = (v8 >> 28) + 48;
if ( *v4 )
break;
if ( v6 > 48 )
return 0xFFFFFFFFLL;
i = v9;
if ( !(v9 | v2) )
return (unsigned int)v5;
}
if ( v6 < v5 )
return 1;
if ( v6 > v5 )
break;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 *a2)
{
__int64 v2; // rax
__int64 i; // rdx
_BYTE *v4; // rcx
int v5; // er8
int v6; // edx
unsigned __int64 v8; // [rsp+0h] [rbp-10h] BYREF
__int64 v9; // [rsp+8h] [rbp-8h]

v2 = *a2;
for ( i = a2[1]; ; i = v9 )
{
while ( 1 )
{
v8 = 10 * v2;
v9 = 10 * i;
func0(&v8);
v5 = (char)*v4;
v2 = v8 & 0xFFFFFFF;
v6 = (v8 >> 28) + 48;
if ( *v4 )
break;
if ( v6 > 48 )
return 0xFFFFFFFFLL;
i = v9;
if ( !(v9 | v2) )
return (unsigned int)v5;
}
if ( v6 < v5 )
return 1;
if ( v6 > v5 )
break;
}
return 0xFFFFFFFFLL;
}

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; // rsi
__int64 v8; // r10
int v9; // edx
_BYTE *i; // r9
char v11; // cl

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

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

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

variable_types:
p
char *

variable_types:
q
char *

variable_types: b int


xcmp

decompiled_code:
__int64 __fastcall xcmp(char *a1, char *a2)
{
const unsigned __int16 **v4; // rax
__int64 v5; // r14
int v6; // er13

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

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, char *a2)
{
const unsigned __int16 **v4; // rax
__int64 v5; // r14
int v6; // er13

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

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; // er12
int v4; // er13

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

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

v2 = mkstemp64(filename);
if ( v2 < 0 )
{
v4 = -1;
}
else
{
v3 = v2;
v4 = p9open(filename, a2);
if ( v4 < 0 )
{
v4 = -1;
remove(filename);
}
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(_BYTE *a1, _QWORD *a2, int a3, __int64 a4)
{
unsigned int v8; // er12

if ( a3 <= 0 )
return 0;
v8 = 0;
while ( *a1 )
{
if ( utfrune(a4) )
{
*a1++ = 0;
}
else
{
if ( !*a1 )
return v8;
*a2 = a1;
++v8;
++a2;
a1 = etoken(a1, a4);
if ( a3 == v8 )
return v8;
}
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, _QWORD *a2, int a3, __int64 a4)
{
unsigned int v8; // er12

if ( a3 <= 0 )
return 0;
v8 = 0;
while ( *a1 )
{
if ( utfrune(a4) )
{
*a1++ = 0;
}
else
{
if ( !*a1 )
return v8;
*a2 = a1;
++v8;
++a2;
a1 = etoken(a1, a4);
if ( a3 == v8 )
return v8;
}
}
return v8;
}

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(_BYTE *a1, _QWORD *a2, int a3)
{
unsigned int v6; // er12

if ( a3 <= 0 )
return 0;
v6 = 0;
while ( *a1 )
{
if ( utfrune(qsep) )
{
++a1;
}
else
{
if ( !*a1 )
return v6;
*a2 = a1;
++v6;
++a2;
a1 = qtoken_constprop_0(a1);
if ( a3 == v6 )
return v6;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, _QWORD *a2, int a3)
{
unsigned int v6; // er12

if ( a3 <= 0 )
return 0;
v6 = 0;
while ( *a1 )
{
if ( utfrune(qsep) )
{
++a1;
}
else
{
if ( !*a1 )
return v6;
*a2 = a1;
++v6;
++a2;
a1 = qtoken_constprop_0(a1);
if ( a3 == v6 )
return v6;
}
}
return v6;
}

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