decompiled_code:
__int64 p9syslog(int a1, const char *a2, __int64 a3, ...)
{
_QWORD *v5; // r12
__int64 v6; // rax
__int64 v7; // r13
const char *v8; // rax
char *v9; // r14
_BYTE *v10; // rax
__int64 v11; // rbx
_QWORD *v13; // rax
__int64 v14; // r12
char v15[136]; // [rsp+0h] [rbp-578h] BYREF
gcc_va_list va; // [rsp+88h] [rbp-4F0h] BYREF
char v17[1023]; // [rsp+A0h] [rbp-4D8h] BYREF
char v18; // [rsp+49Fh] [rbp-D9h] BYREF

v15[0] = 0;
errstr(v15, 128LL);
lock(&unk_3E0);
v5 = (_QWORD *)dirfstat((unsigned int)sl);
if ( sl >= 0
&& s1
&& !strcmp(s1, a2)
&& v5
&& qword_3D0
&& (*v5 & 0xFFFFFFFF0000FFFFLL) == (*(_QWORD *)qword_3D0 & 0xFFFFFFFF0000FFFFLL)
&& v5[1] == *(_QWORD *)(qword_3D0 + 8) )
{
goto LABEL_11;
}
p9free(s1);
s1 = (char *)p9strdup(a2);
if ( s1 )
{
syslogopen();
if ( sl < 0 )
a1 = 1;
p9free(qword_3D0);
qword_3D0 = (__int64)v5;
v5 = 0LL;
LABEL_11:
p9free(v5);
if ( !a1 )
goto LABEL_12;
goto LABEL_25;
}
p9free(v5);
a1 = 1;
LABEL_25:
v13 = (_QWORD *)dirfstat((unsigned int)dword_3C4);
v14 = (__int64)v13;
if ( dword_3C4 < 0
|| !v13
|| !qword_3D8
|| (*v13 & 0xFFFFFFFF0000FFFFLL) != (*(_QWORD *)qword_3D8 & 0xFFFFFFFF0000FFFFLL)
|| v13[1] != *(_QWORD *)(qword_3D8 + 8) )
{
dword_3C4 = p9open("/dev/tty", 33LL);
p9free(qword_3D8);
qword_3D8 = v14;
v14 = 0LL;
}
p9free(v14);
LABEL_12:
if ( a3 )
{
v6 = p9time(0LL);
v7 = p9ctime(v6);
werrstr(v15);
v8 = (const char *)sysname();
v9 = &v17[(int)snprint(v17, 1023LL, "%s ", v8)];
strncpy(v9, (const char *)(v7 + 4), 0xFuLL);
v9[15] = 32;
va_start(va, a3);
v10 = (_BYTE *)vseprint(v9 + 16, &v18, a3, va);
*v10 = 10;
v11 = v10 + 1 - v17;
if ( sl >= 0 )
{
p9seek((unsigned int)sl, 0LL, 2LL);
p9write((unsigned int)sl, v17, (int)v11);
}
if ( a1 && dword_3C4 >= 0 )
p9write((unsigned int)dword_3C4, v17, (int)v11);
}
return unlock(&unk_3E0);
}

canonical_decompiled_code:
__int64 func1(int a1, const char *a2, __int64 a3, ...)
{
_QWORD *v5; // r12
__int64 v6; // rax
__int64 v7; // r13
const char *v8; // rax
char *v9; // r14
_BYTE *v10; // rax
__int64 v11; // rbx
_QWORD *v13; // rax
__int64 v14; // r12
char v15[136]; // [rsp+0h] [rbp-578h] BYREF
gcc_va_list va; // [rsp+88h] [rbp-4F0h] BYREF
char v17[1023]; // [rsp+A0h] [rbp-4D8h] BYREF
char v18; // [rsp+49Fh] [rbp-D9h] BYREF

v15[0] = 0;
errstr(v15, 128LL);
lock(&unk_3E0);
v5 = (_QWORD *)dirfstat((unsigned int)sl);
if ( sl >= 0
&& s1
&& !strcmp(s1, a2)
&& v5
&& qword_3D0
&& (*v5 & 0xFFFFFFFF0000FFFFLL) == (*(_QWORD *)qword_3D0 & 0xFFFFFFFF0000FFFFLL)
&& v5[1] == *(_QWORD *)(qword_3D0 + 8) )
{
goto LABEL_11;
}
p9free(s1);
s1 = (char *)p9strdup(a2);
if ( s1 )
{
func0();
if ( sl < 0 )
a1 = 1;
p9free(qword_3D0);
qword_3D0 = (__int64)v5;
v5 = 0LL;
LABEL_11:
p9free(v5);
if ( !a1 )
goto LABEL_12;
goto LABEL_25;
}
p9free(v5);
a1 = 1;
LABEL_25:
v13 = (_QWORD *)dirfstat((unsigned int)dword_3C4);
v14 = (__int64)v13;
if ( dword_3C4 < 0
|| !v13
|| !qword_3D8
|| (*v13 & 0xFFFFFFFF0000FFFFLL) != (*(_QWORD *)qword_3D8 & 0xFFFFFFFF0000FFFFLL)
|| v13[1] != *(_QWORD *)(qword_3D8 + 8) )
{
dword_3C4 = p9open("/dev/tty", 33LL);
p9free(qword_3D8);
qword_3D8 = v14;
v14 = 0LL;
}
p9free(v14);
LABEL_12:
if ( a3 )
{
v6 = p9time(0LL);
v7 = p9ctime(v6);
werrstr(v15);
v8 = (const char *)sysname();
v9 = &v17[(int)snprint(v17, 1023LL, "%s ", v8)];
strncpy(v9, (const char *)(v7 + 4), 0xFuLL);
v9[15] = 32;
va_start(va, a3);
v10 = (_BYTE *)vseprint(v9 + 16, &v18, a3, va);
*v10 = 10;
v11 = v10 + 1 - v17;
if ( sl >= 0 )
{
p9seek((unsigned int)sl, 0LL, 2LL);
p9write((unsigned int)sl, v17, (int)v11);
}
if ( a1 && dword_3C4 >= 0 )
p9write((unsigned int)dword_3C4, v17, (int)v11);
}
return unlock(&unk_3E0);
}

original_code:
void
p9syslog(int cons, char *logname, char *fmt, ...)
{
 char buf[1024];
 char *ctim, *p;
 va_list arg;
 int n;
 Dir *d;
 char err[128];
 err[0] = '\0';
 errstr(err, sizeof err);
 lock(&sl.lk);
 d = dirfstat(sl.fd);
 if(sl.fd < 0
    || sl.name == ((void*)0)
    || strcmp(sl.name, logname)!=0
    || sl.d == ((void*)0)
    || d == ((void*)0)
    || d->dev != sl.d->dev
    || d->type != sl.d->type
    || d->qid.path != sl.d->qid.path){
  p9free(sl.name);
  sl.name = p9strdup(logname);
  if(sl.name == ((void*)0))
   cons = 1;
  else{
   _syslogopen();
   if(sl.fd < 0)
    cons = 1;
   p9free(sl.d);
   sl.d = d;
   d = ((void*)0);
  }
 }
 p9free(d);
 if(cons){
  d = dirfstat(sl.consfd);
  if(sl.consfd < 0
     || d == ((void*)0)
     || sl.consd == ((void*)0)
     || d->dev != sl.consd->dev
     || d->type != sl.consd->type
     || d->qid.path != sl.consd->qid.path){
   sl.consfd = p9open("/dev/tty", 1|32);
   p9free(sl.consd);
   sl.consd = d;
   d = ((void*)0);
  }
  p9free(d);
 }
 if(fmt == ((void*)0)){
  unlock(&sl.lk);
  return;
 }
 ctim = p9ctime(p9time(0));
 werrstr(err);
 p = buf + snprint(buf, sizeof(buf)-1, "%s ", sysname());
 strncpy(p, ctim+4, 15);
 p += 15;
 *p++ = ' ';
 __builtin_va_start(arg,fmt);
 p = vseprint(p, buf+sizeof(buf)-1, fmt, arg);
 __builtin_va_end(arg);
 *p++ = '\n';
 n = p - buf;
 if(sl.fd >= 0){
  p9seek(sl.fd, 0, 2);
  p9write(sl.fd, buf, n);
 }
 if(cons && sl.consfd >=0)
  p9write(sl.consfd, buf, n);
 unlock(&sl.lk);
}

canonical_original_code:
void p9syslog(int cons, char *logname, char *fmt, ...)
{
 char buf[1024];
 char *ctim; char *p;
 __builtin_va_list arg;
 int n;
 struct Dir *d;
 char err[128];
 err[0] = '\0';
 errstr(err, sizeof err);
 lock(&sl.lk);
 d = dirfstat(sl.fd);
 if(sl.fd < 0
    || sl.name == ((void *)0)
    || strcmp(sl.name, logname)!=0
    || sl.d == ((void *)0)
    || d == ((void *)0)
    || d->dev != sl.d->dev
    || d->type != sl.d->type
    || d->qid.path != sl.d->qid.path){
  p9free(sl.name);
  sl.name = p9strdup(logname);
  if(sl.name == ((void *)0))
   cons = 1;
  else{
   _syslogopen();
   if(sl.fd < 0)
    cons = 1;
   p9free(sl.d);
   sl.d = d;
   d = ((void *)0);
  }
 }
 p9free(d);
 if(cons){
  d = dirfstat(sl.consfd);
  if(sl.consfd < 0
     || d == ((void *)0)
     || sl.consd == ((void *)0)
     || d->dev != sl.consd->dev
     || d->type != sl.consd->type
     || d->qid.path != sl.consd->qid.path){
   sl.consfd = p9open("/dev/tty", 1|32);
   p9free(sl.consd);
   sl.consd = d;
   d = ((void *)0);
  }
  p9free(d);
 }
 if(fmt == ((void *)0)){
  unlock(&sl.lk);
  return;
 }
 ctim = p9ctime(p9time(0));
 werrstr(err);
 p = buf + snprint(buf, sizeof(buf)-1, "%s ", sysname());
 strncpy(p, ctim+4, 15);
 p += 15;
 *p++ = ' ';
 __builtin_va_start(arg,fmt);
 p = vseprint(p, buf+sizeof(buf)-1, fmt, arg);
 __builtin_va_end(arg);
 *p++ = '\n';
 n = p - buf;
 if(sl.fd >= 0){
  p9seek(sl.fd, 0, 2);
  p9write(sl.fd, buf, n);
 }
 if(cons && sl.consfd >=0)
  p9write(sl.consfd, buf, n);
 unlock(&sl.lk);
}

variable_types: cons int

variable_types:
logname
char *

variable_types:
fmt
char *

variable_types:
buf
char [1024]

variable_types:
ctim
char *

variable_types:
p
char *

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

variable_types:
err
char [128]


getcallerpc

decompiled_code:
__int64 __fastcall getcallerpc(__int64 a1)
{
return *(_QWORD *)(a1 - 8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(_QWORD *)(a1 - 8);
}

original_code:
ulong
getcallerpc(void *x)
{
 return (((ulong*)(x))[-1]);
}

canonical_original_code:
unsigned long getcallerpc(void *x)
{
 return (((unsigned long *)(x))[-1]);
}

variable_types:
x
void *

return_type: unsigned long


fprint

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

va_start(va, a2);
return vfprint(a1, a2, va);
}

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

va_start(va, a2);
return vfprint(a1, a2, va);
}

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

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

variable_types: fd int

variable_types: n int

return_type: int


fmtstrflush

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

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

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

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

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

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

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

return_type: char *


Bfildes

decompiled_code:
__int64 __fastcall Bfildes(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned int *)(a1 + 20);
}

original_code:
int
Bfildes(Biobuf *bp)
{
 return bp->fid;
}

canonical_original_code:
int Bfildes(struct Biobuf *bp)
{
 return bp->fid;
}

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


seprint

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

va_start(va, a3);
return vseprint(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 vseprint(a1, a2, a3, va);
}

original_code:
char*
seprint(char *buf, char *e, char *fmt, ...)
{
 char *p;
 va_list args;
 __builtin_va_start(args,fmt);
 p = vseprint(buf, e, fmt, args);
 __builtin_va_end(args);
 return p;
}

canonical_original_code:
char *seprint(char *buf, char *e, char *fmt, ...)
{
 char *p;
 __builtin_va_list args;
 __builtin_va_start(args,fmt);
 p = vseprint(buf, e, fmt, args);
 __builtin_va_end(args);
 return p;
}

variable_types:
buf
char *

variable_types:
e
char *


setport

decompiled_code:
__int64 __fastcall setport(unsigned __int16 *a1, __int16 a2)
{
unsigned __int16 v2; // ax
__int64 result; // rax

v2 = *a1;
if ( *a1 == 2 || v2 == 10 )
{
a1[1] = _bswap_16(a2);
result = 0LL;
}
else
{
errstr("unknown protocol family %d", v2);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 *a1, __int16 a2)
{
unsigned __int16 v2; // ax
__int64 result; // rax

v2 = *a1;
if ( *a1 == 2 || v2 == 10 )
{
a1[1] = func0(a2);
result = 0LL;
}
else
{
errstr("unknown protocol family %d", v2);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int
setport(struct sockaddr_storage *ss, int port)
{
 switch(ss->ss_family){
 case 2:
  ((struct sockaddr_in*)ss)->sin_port = htons(port);
  break;
 case 10:
  ((struct sockaddr_in6*)ss)->sin6_port = htons(port);
  break;
 default:
  errstr("unknown protocol family %d", ss->ss_family);
  return -1;
 }
 return 0;
}

canonical_original_code:
static int setport(struct sockaddr_storage *ss, int port)
{
 switch(ss->ss_family){
 case 2:
  ((struct sockaddr_in *)ss)->sin_port = htons(port);
  break;
 case 10:
  ((struct sockaddr_in6 *)ss)->sin6_port = htons(port);
  break;
 default:
  errstr("unknown protocol family %d", ss->ss_family);
  return -1;
 }
 return 0;
}

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; } *

variable_types: port int

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

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


decompiled_code:
__int64 __fastcall p9dialparse(char *s2, _QWORD *a2, const char **a3, unsigned __int16 *a4, int *a5)
{
char *v7; // rax
char *v8; // r13
const char *v9; // r14
char *v10; // rax
const char *v11; // rbx
const char **v12; // r14
const char *v13; // r13
struct servent *v14; // rax
_BOOL4 v15; // er15
const char **v16; // r13
int i; // er14
__int64 result; // rax
struct hostent *v19; // rax
int v20; // edx
int v21; // edx
unsigned __int16 v22; // ax
int v23; // esi
int v24; // eax
struct servent *v25; // rax
unsigned __int16 v26; // ax
struct addrinfo *pai; // [rsp+10h] [rbp-48h] BYREF
char *endptr; // [rsp+18h] [rbp-40h] BYREF

*(_QWORD *)a4 = 0LL;
*((_QWORD *)a4 + 15) = 0LL;
memset(
(void *)((unsigned __int64)(a4 + 4) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 128) >> 3));
*a3 = 0LL;
v7 = strchr(s2, 33);
if ( !v7 )
goto LABEL_16;
v8 = v7;
v9 = v7 + 1;
*v7 = 0;
v10 = strchr(v7 + 1, 33);
if ( !v10 )
{
if ( !strcmp(s2, "unix") || !strcmp(s2, "net") )
{
LABEL_19:
if ( strlen(v9) + 1 > 0x6C )
{
werrstr("unix socket name too long");
result = 0xFFFFFFFFLL;
}
else
{
*a3 = v9;
*a2 = "unix";
*a4 = 1;
strcpy((char *)a4 + 2, v9);
*a5 = 0;
result = 0LL;
}
return result;
}
LABEL_16:
werrstr("malformed address");
return 0xFFFFFFFFLL;
}
*v10 = 0;
if ( !v8[1] )
{
werrstr("malformed address (empty host)");
return 0xFFFFFFFFLL;
}
if ( !v10[1] )
{
werrstr("malformed address (empty port)");
return 0xFFFFFFFFLL;
}
if ( !strcmp(s2, "unix") )
goto LABEL_19;
v11 = v10 + 1;
if ( strcmp(s2, "tcp") && strcmp(s2, "udp") && strcmp(s2, "net") )
{
werrstr("bad network %s!%s!%s", s2, v9, v11);
return 0xFFFFFFFFLL;
}
if ( !strcmp(v9, "*") )
{
*a4 = 10;
*(__m128i *)(a4 + 4) = _mm_loadu_si128((const __m128i *)&in6addr_any);
}
else
{
v19 = gethostbyname(v9);
if ( v19 && *v19->h_addr_list )
{
v20 = v19->h_addrtype;
*a4 = v20;
if ( (_WORD)v20 == 2 )
{
*((_DWORD *)a4 + 1) = **(_DWORD **)v19->h_addr_list;
}
else
{
if ( (_WORD)v20 != 10 )
{
errstr("unknown protocol family %d", (unsigned __int16)v20);
return 0xFFFFFFFFLL;
}
*(__m128i *)(a4 + 4) = _mm_loadu_si128((const __m128i *)*v19->h_addr_list);
}
}
else
{
if ( getaddrinfo(v9, 0LL, 0LL, &pai) )
{
werrstr("unknown host %s", v9);
return 0xFFFFFFFFLL;
}
v21 = pai->ai_family;
if ( v21 != 2 && v21 != 10 )
{
errstr("unknown protocol family %d", *a4);
return 0xFFFFFFFFLL;
}
memmove(a4, pai->ai_addr, pai->ai_addrlen);
}
}
if ( !strcmp(s2, "net") )
{
v12 = (const char **)nets;
v13 = "tcp";
while ( 1 )
{
v14 = getservbyname(v11, v13);
if ( v14 )
break;
v13 = *++v12;
if ( !*v12 )
goto LABEL_15;
}
*a2 = v13;
v22 = _bswap_16(v14->s_port);
*a5 = v22;
result = setport(a4, v22);
}
else
{
LABEL_15:
v15 = strcmp(s2, "net") != 0;
v16 = (const char **)porttbl;
for ( i = 0; i != 13; ++i )
{
if ( (!v15 || !strcmp(*v16, s2)) && !strcmp(v16[1], v11) )
{
*a2 = porttbl[3 * i];
v23 = dword_6F0[6 * i];
*a5 = v23;
return setport(a4, v23);
}
v16 += 3;
}
if ( v15 )
{
if ( !strcmp(s2, "tcp") || !strcmp(s2, "udp") )
{
*a2 = s2;
v24 = strtol(v11, &endptr, 0);
if ( *endptr )
{
v25 = getservbyname(v11, s2);
if ( v25 )
{
v26 = _bswap_16(v25->s_port);
*a5 = v26;
result = setport(a4, v26);
}
else
{
werrstr("unknown service %s!*!%s", s2, v11);
result = 0xFFFFFFFFLL;
}
}
else
{
*a5 = v24;
result = setport(a4, v24);
}
}
else
{
werrstr("unknown network %s", s2);
result = 0xFFFFFFFFLL;
}
}
else
{
werrstr("unknown service net!*!%s", v11);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s2, _QWORD *a2, const char **a3, unsigned __int16 *a4, int *a5)
{
char *v7; // rax
char *v8; // r13
const char *v9; // r14
char *v10; // rax
const char *v11; // rbx
const char **v12; // r14
const char *v13; // r13
struct servent *v14; // rax
_BOOL4 v15; // er15
const char **v16; // r13
int i; // er14
__int64 result; // rax
struct hostent *v19; // rax
int v20; // edx
int v21; // edx
unsigned __int16 v22; // ax
int v23; // esi
int v24; // eax
struct servent *v25; // rax
unsigned __int16 v26; // ax
struct addrinfo *pai; // [rsp+10h] [rbp-48h] BYREF
char *endptr; // [rsp+18h] [rbp-40h] BYREF

*(_QWORD *)a4 = 0LL;
*((_QWORD *)a4 + 15) = 0LL;
memset(
(void *)((unsigned __int64)(a4 + 4) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a4 - (((_DWORD)a4 + 8) & 0xFFFFFFF8) + 128) >> 3));
*a3 = 0LL;
v7 = strchr(s2, 33);
if ( !v7 )
goto LABEL_16;
v8 = v7;
v9 = v7 + 1;
*v7 = 0;
v10 = strchr(v7 + 1, 33);
if ( !v10 )
{
if ( !strcmp(s2, "unix") || !strcmp(s2, "net") )
{
LABEL_19:
if ( strlen(v9) + 1 > 0x6C )
{
werrstr("unix socket name too long");
result = 0xFFFFFFFFLL;
}
else
{
*a3 = v9;
*a2 = "unix";
*a4 = 1;
strcpy((char *)a4 + 2, v9);
*a5 = 0;
result = 0LL;
}
return result;
}
LABEL_16:
werrstr("malformed address");
return 0xFFFFFFFFLL;
}
*v10 = 0;
if ( !v8[1] )
{
werrstr("malformed address (empty host)");
return 0xFFFFFFFFLL;
}
if ( !v10[1] )
{
werrstr("malformed address (empty port)");
return 0xFFFFFFFFLL;
}
if ( !strcmp(s2, "unix") )
goto LABEL_19;
v11 = v10 + 1;
if ( strcmp(s2, "tcp") && strcmp(s2, "udp") && strcmp(s2, "net") )
{
werrstr("bad network %s!%s!%s", s2, v9, v11);
return 0xFFFFFFFFLL;
}
if ( !strcmp(v9, "*") )
{
*a4 = 10;
*(__m128i *)(a4 + 4) = _mm_loadu_si128((const __m128i *)&in6addr_any);
}
else
{
v19 = gethostbyname(v9);
if ( v19 && *v19->h_addr_list )
{
v20 = v19->h_addrtype;
*a4 = v20;
if ( (_WORD)v20 == 2 )
{
*((_DWORD *)a4 + 1) = **(_DWORD **)v19->h_addr_list;
}
else
{
if ( (_WORD)v20 != 10 )
{
errstr("unknown protocol family %d", (unsigned __int16)v20);
return 0xFFFFFFFFLL;
}
*(__m128i *)(a4 + 4) = _mm_loadu_si128((const __m128i *)*v19->h_addr_list);
}
}
else
{
if ( getaddrinfo(v9, 0LL, 0LL, &pai) )
{
werrstr("unknown host %s", v9);
return 0xFFFFFFFFLL;
}
v21 = pai->ai_family;
if ( v21 != 2 && v21 != 10 )
{
errstr("unknown protocol family %d", *a4);
return 0xFFFFFFFFLL;
}
memmove(a4, pai->ai_addr, pai->ai_addrlen);
}
}
if ( !strcmp(s2, "net") )
{
v12 = (const char **)nets;
v13 = "tcp";
while ( 1 )
{
v14 = getservbyname(v11, v13);
if ( v14 )
break;
v13 = *++v12;
if ( !*v12 )
goto LABEL_15;
}
*a2 = v13;
v22 = func0(v14->s_port);
*a5 = v22;
result = func1(a4, v22);
}
else
{
LABEL_15:
v15 = strcmp(s2, "net") != 0;
v16 = (const char **)porttbl;
for ( i = 0; i != 13; ++i )
{
if ( (!v15 || !strcmp(*v16, s2)) && !strcmp(v16[1], v11) )
{
*a2 = porttbl[3 * i];
v23 = dword_6F0[6 * i];
*a5 = v23;
return func1(a4, v23);
}
v16 += 3;
}
if ( v15 )
{
if ( !strcmp(s2, "tcp") || !strcmp(s2, "udp") )
{
*a2 = s2;
v24 = strtol(v11, &endptr, 0);
if ( *endptr )
{
v25 = getservbyname(v11, s2);
if ( v25 )
{
v26 = func0(v25->s_port);
*a5 = v26;
result = func1(a4, v26);
}
else
{
werrstr("unknown service %s!*!%s", s2, v11);
result = 0xFFFFFFFFLL;
}
}
else
{
*a5 = v24;
result = func1(a4, v24);
}
}
else
{
werrstr("unknown network %s", s2);
result = 0xFFFFFFFFLL;
}
}
else
{
werrstr("unknown service net!*!%s", v11);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
p9dialparse(char *addr, char **pnet, char **punix, void *phost, int *pport)
{
 char *net, *host, *port, *e;
 int i;
 struct servent *se;
 struct hostent *he;
 struct sockaddr_storage *ss;
 struct addrinfo *result;
 ss = phost;
 memset(ss, 0, sizeof *ss);
 *punix = ((void*)0);
 net = addr;
 if((host = strchr(net, '!')) == ((void*)0)){
  werrstr("malformed address");
  return -1;
 }
 *host++ = 0;
 if((port = strchr(host, '!')) == ((void*)0)){
  if(strcmp(net, "unix")==0 || strcmp(net, "net")==0){
  Unix:
   if(strlen(host)+1 > sizeof ((struct sockaddr_un*)&ss)->sun_path){
    werrstr("unix socket name too long");
    return -1;
   }
   *punix = host;
   *pnet = "unix";
   ss->ss_family = 1;
   strcpy(((struct sockaddr_un*)ss)->sun_path, host);
   *pport = 0;
   return 0;
  }
  werrstr("malformed address");
  return -1;
 }
 *port++ = 0;
 if(*host == 0){
  werrstr("malformed address (empty host)");
  return -1;
 }
 if(*port == 0){
  werrstr("malformed address (empty port)");
  return -1;
 }
 if(strcmp(net, "unix") == 0)
  goto Unix;
 if(strcmp(net, "tcp")!=0 && strcmp(net, "udp")!=0 && strcmp(net, "net") != 0){
  werrstr("bad network %s!%s!%s", net, host, port);
  return -1;
 }
 if(strcmp(host, "*") == 0){
  ss->ss_family = 10;
  ((struct sockaddr_in6*)ss)->sin6_addr = in6addr_any;
 }else if((he = gethostbyname(host)) != ((void*)0) && he->h_addr_list[0] != ((void*)0)){
  ss->ss_family = he->h_addrtype;
  switch(ss->ss_family){
  case 2:
   ((struct sockaddr_in*)ss)->sin_addr = *(struct in_addr*) *(he->h_addr_list);
   break;
  case 10:
   ((struct sockaddr_in6*)ss)->sin6_addr = *(struct in6_addr*) *(he->h_addr_list);
   break;
  default:
   errstr("unknown protocol family %d", ss->ss_family);
   return -1;
  }
 }else if(getaddrinfo(host, ((void *)0), ((void *)0), &result) == 0) {
  switch (result->ai_family) {
  case 2:
   memmove((struct sockaddr_in*)ss, result->ai_addr, result->ai_addrlen);
   break;
  case 10:
   memmove((struct sockaddr_in6*)ss, result->ai_addr, result->ai_addrlen);
   break;
  default:
   errstr("unknown protocol family %d", ss->ss_family);
   return -1;
  }
 }else{
  werrstr("unknown host %s", host);
  return -1;
 }
 if(strcmp(net, "net") == 0){
  for(i=0; nets[i]; i++){
   if((se = getservbyname(port, nets[i])) != ((void*)0)){
    *pnet = nets[i];
    *pport = ntohs(se->s_port);
    return setport(ss, *pport);
   }
  }
 }
 for(i=0; i<(sizeof(porttbl)/sizeof((porttbl)[0])); i++){
  if(strcmp(net, "net") == 0 || strcmp(porttbl[i].net, net) == 0)
  if(strcmp(porttbl[i].service, port) == 0){
   *pnet = porttbl[i].net;
   *pport = porttbl[i].port;
   return setport(ss, *pport);
  }
 }
 if(strcmp(net, "net") == 0){
  werrstr("unknown service net!*!%s", port);
  return -1;
 }
 if(strcmp(net, "tcp") != 0 && strcmp(net, "udp") != 0){
  werrstr("unknown network %s", net);
  return -1;
 }
 *pnet = net;
 i = strtol(port, &e, 0);
 if(*e == 0){
  *pport = i;
  return setport(ss, *pport);
 }
 if((se = getservbyname(port, net)) != ((void*)0)){
  *pport = ntohs(se->s_port);
  return setport(ss, *pport);
 }
 werrstr("unknown service %s!*!%s", net, port);
 return -1;
}

canonical_original_code:
int p9dialparse(char *addr, char **pnet, char **punix, void *phost, int *pport)
{
 char *net; char *host; char *port; char *e;
 int i;
 struct servent *se;
 struct hostent *he;
 struct sockaddr_storage *ss;
 struct addrinfo *result;
 ss = phost;
 memset(ss, 0, sizeof *ss);
 *punix = ((void *)0);
 net = addr;
 if((host = strchr(net, '!')) == ((void *)0)){
  werrstr("malformed address");
  return -1;
 }
 *host++ = 0;
 if((port = strchr(host, '!')) == ((void *)0)){
  if(strcmp(net, "unix")==0 || strcmp(net, "net")==0){
  Unix:
   if(strlen(host)+1 > sizeof ((struct sockaddr_un *)&ss)->sun_path){
    werrstr("unix socket name too long");
    return -1;
   }
   *punix = host;
   *pnet = "unix";
   ss->ss_family = 1;
   strcpy(((struct sockaddr_un *)ss)->sun_path, host);
   *pport = 0;
   return 0;
  }
  werrstr("malformed address");
  return -1;
 }
 *port++ = 0;
 if(*host == 0){
  werrstr("malformed address (empty host)");
  return -1;
 }
 if(*port == 0){
  werrstr("malformed address (empty port)");
  return -1;
 }
 if(strcmp(net, "unix") == 0)
  goto Unix;
 if(strcmp(net, "tcp")!=0 && strcmp(net, "udp")!=0 && strcmp(net, "net") != 0){
  werrstr("bad network %s!%s!%s", net, host, port);
  return -1;
 }
 if(strcmp(host, "*") == 0){
  ss->ss_family = 10;
  ((struct sockaddr_in6 *)ss)->sin6_addr = in6addr_any;
 }else if((he = gethostbyname(host)) != ((void *)0) && he->h_addr_list[0] != ((void *)0)){
  ss->ss_family = he->h_addrtype;
  switch(ss->ss_family){
  case 2:
   ((struct sockaddr_in *)ss)->sin_addr = *(struct in_addr *) *(he->h_addr_list);
   break;
  case 10:
   ((struct sockaddr_in6 *)ss)->sin6_addr = *(struct in6_addr *) *(he->h_addr_list);
   break;
  default:
   errstr("unknown protocol family %d", ss->ss_family);
   return -1;
  }
 }else if(getaddrinfo(host, ((void *)0), ((void *)0), &result) == 0) {
  switch (result->ai_family) {
  case 2:
   memmove((struct sockaddr_in *)ss, result->ai_addr, result->ai_addrlen);
   break;
  case 10:
   memmove((struct sockaddr_in6 *)ss, result->ai_addr, result->ai_addrlen);
   break;
  default:
   errstr("unknown protocol family %d", ss->ss_family);
   return -1;
  }
 }else{
  werrstr("unknown host %s", host);
  return -1;
 }
 if(strcmp(net, "net") == 0){
  for(i=0; nets[i]; i++){
   if((se = getservbyname(port, nets[i])) != ((void *)0)){
    *pnet = nets[i];
    *pport = ntohs(se->s_port);
    return setport(ss, *pport);
   }
  }
 }
 for(i=0; i<(sizeof(porttbl)/sizeof((porttbl)[0])); i++){
  if(strcmp(net, "net") == 0 || strcmp(porttbl[i].net, net) == 0)
  if(strcmp(porttbl[i].service, port) == 0){
   *pnet = porttbl[i].net;
   *pport = porttbl[i].port;
   return setport(ss, *pport);
  }
 }
 if(strcmp(net, "net") == 0){
  werrstr("unknown service net!*!%s", port);
  return -1;
 }
 if(strcmp(net, "tcp") != 0 && strcmp(net, "udp") != 0){
  werrstr("unknown network %s", net);
  return -1;
 }
 *pnet = net;
 i = strtol(port, &e, 0);
 if(*e == 0){
  *pport = i;
  return setport(ss, *pport);
 }
 if((se = getservbyname(port, net)) != ((void *)0)){
  *pport = ntohs(se->s_port);
  return setport(ss, *pport);
 }
 werrstr("unknown service %s!*!%s", net, port);
 return -1;
}

variable_types:
addr
char *

variable_types:
pnet
char **

variable_types:
punix
char **

variable_types:
phost
void *

variable_types:
pport
int *

variable_types:
net
char *

variable_types:
host
char *

variable_types:
port
char *

variable_types: i int

variable_types: struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; } *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

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


canlock

decompiled_code:
__int64 __fastcall canlock(_DWORD *a1)
{
__int64 (__fastcall *v1)(_DWORD *, _QWORD, __int64); // rbx
__int64 result; // rax
__int64 v3; // rax
_DWORD *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a1;
v1 = (__int64 (__fastcall *)(_DWORD *, _QWORD, __int64))lock;
if ( lock )
{
v3 = getcallerpc(&v4);
result = v1(v4, 0LL, v3);
}
else
{
result = 0LL;
if ( !*v4 )
{
*v4 = 1;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
__int64 (__fastcall *v1)(_DWORD *, _QWORD, __int64); // rbx
__int64 result; // rax
__int64 v3; // rax
_DWORD *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a1;
v1 = (__int64 (__fastcall *)(_DWORD *, _QWORD, __int64))lock;
if ( lock )
{
v3 = getcallerpc(&v4);
result = v1(v4, 0LL, v3);
}
else
{
result = 0LL;
if ( !*v4 )
{
*v4 = 1;
result = 1LL;
}
}
return result;
}

original_code:
int
canlock(Lock *l)
{
 if(_lock)
  return (*_lock)(l, 0, getcallerpc(&l));
 else{
  if(l->held)
   return 0;
  l->held = 1;
  return 1;
 }
}

canonical_original_code:
int canlock(struct Lock *l)
{
 if(_lock)
  return (*_lock)(l, 0, getcallerpc(&l));
 else{
  if(l->held)
   return 0;
  l->held = 1;
  return 1;
 }
}

variable_types:
l
struct Lock { int held; } *


Bputc

decompiled_code:
__int64 __fastcall Bputc(__int64 a1, char a2)
{
int v2; // eax
__int64 result; // rax

while ( 1 )
{
v2 = *(_DWORD *)(a1 + 4);
if ( v2 )
break;
result = Bflush(a1);
if ( (_DWORD)result == -1 )
return result;
}
*(_BYTE *)(*(_QWORD *)(a1 + 56) + v2) = a2;
*(_DWORD *)(a1 + 4) = v2 + 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2)
{
int v2; // eax
__int64 result; // rax

while ( 1 )
{
v2 = *(_DWORD *)(a1 + 4);
if ( v2 )
break;
result = Bflush(a1);
if ( (_DWORD)result == -1 )
return result;
}
*(_BYTE *)(*(_QWORD *)(a1 + 56) + v2) = a2;
*(_DWORD *)(a1 + 4) = v2 + 1;
return 0LL;
}

original_code:
int
Bputc(Biobuf *bp, int c)
{
 int i;
 for(;;) {
  i = bp->ocount;
  if(i) {
   bp->ebuf[i++] = c;
   bp->ocount = i;
   return 0;
  }
  if(Bflush(bp) == Beof)
   break;
 }
 return Beof;
}

canonical_original_code:
int Bputc(struct Biobuf *bp, int c)
{
 int i;
 for(;;) {
  i = bp->ocount;
  if(i) {
   bp->ebuf[i++] = c;
   bp->ocount = i;
   return 0;
  }
  if(Bflush(bp) == Beof)
   break;
 }
 return Beof;
}

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


rawx

decompiled_code:
__int64 __fastcall rawx(int fd, int a2)
{
unsigned int v2; // er12

if ( a2 == -1 )
return (unsigned int)-1;
if ( tcgetattr(fd, &ttmode_0) < 0 )
return (unsigned int)-1;
v2 = ttmode_0.c_lflag & 0xA;
ttmode_0.c_lflag = a2 | ttmode_0.c_lflag & 0xFFFFFFF5;
if ( tcsetattr(fd, 0, &ttmode_0) < 0 )
v2 = -1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, int a2)
{
unsigned int v2; // er12

if ( a2 == -1 )
return (unsigned int)-1;
if ( tcgetattr(fd, &ttmode_0) < 0 )
return (unsigned int)-1;
v2 = ttmode_0.c_lflag & 0xA;
ttmode_0.c_lflag = a2 | ttmode_0.c_lflag & 0xFFFFFFF5;
if ( tcsetattr(fd, 0, &ttmode_0) < 0 )
v2 = -1;
return v2;
}

original_code:
static int
rawx(int fd, int echoing)
{
 int was;
 static struct termios ttmode;
 if(echoing == -1)
  return -1;
 if(tcgetattr(fd, &ttmode) < 0)
  return -1;
 was = (ttmode.c_lflag&(0000010|0000002));
 ttmode.c_lflag &= ~(0000010|0000002);
 ttmode.c_lflag |= echoing;
 if(tcsetattr(fd, 0, &ttmode) < 0)
  return -1;
 return was;
}

variable_types: fd int

variable_types: echoing int

variable_types: was int

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


readcons

decompiled_code:
char *__fastcall readcons(const char *a1, const char *a2, int a3)
{
int v3; // ebx
int v4; // eax
unsigned int v5; // er14
char *v6; // rbp
int v8; // eax
unsigned __int8 v9; // bl
__int64 v10; // rax
int v11; // er12
char *v12; // rax
char *v13; // r13
int v15; // [rsp+Ch] [rbp-4Ch]
char buf[66]; // [rsp+16h] [rbp-42h] BYREF

v3 = a3;
v4 = open64("/dev/tty", 2);
if ( v4 < 0 )
return 0LL;
v5 = v4;
v15 = -1;
if ( v3 )
{
v15 = rawx(v4, 0);
if ( v15 == -1 )
return 0LL;
}
if ( a2 )
fprint(v5, "%s[%s]: ", a1, a2);
else
fprint(v5, "%s: ", a1);
v6 = strdup(&s);
if ( v6 )
{
while ( 1 )
{
v8 = read(v5, buf, 1uLL);
if ( v8 < 0 )
break;
if ( v8 <= 0 )
goto LABEL_14;
if ( buf[0] == 127 )
break;
v9 = buf[0];
if ( buf[0] <= 0xDu )
{
v10 = 9232LL;
if ( _bittest64(&v10, (unsigned __int8)buf[0]) )
{
LABEL_14:
if ( a3 )
{
rawx(v5, v15);
write(v5, "\n", 1uLL);
}
close(v5);
if ( !*v6 && a2 )
{
free(v6);
v6 = strdup(a2);
}
return v6;
}
}
if ( buf[0] == 8 )
{
if ( *v6 )
v6[strlen(v6) - 1] = 0;
}
else if ( buf[0] == 21 )
{
if ( a2 )
fprint(v5, "\n%s[%s]: ", a1, a2);
else
fprint(v5, "\n%s: ", a1);
*v6 = 0;
}
else
{
v11 = strlen(v6);
v12 = (char *)malloc(v11 + 2);
v13 = v12;
if ( !v12 )
{
free(v6);
return 0LL;
}
memmove(v12, v6, v11);
free(v6);
v13[v11] = v9;
v13[v11 + 1] = 0;
v6 = v13;
}
}
if ( a3 )
{
rawx(v5, v15);
write(v5, "\n", 1uLL);
}
close(v5);
free(v6);
v6 = 0LL;
}
return v6;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, const char *a2, int a3)
{
int v3; // ebx
int v4; // eax
unsigned int v5; // er14
char *v6; // rbp
int v8; // eax
unsigned __int8 v9; // bl
__int64 v10; // rax
int v11; // er12
char *v12; // rax
char *v13; // r13
int v15; // [rsp+Ch] [rbp-4Ch]
char buf[66]; // [rsp+16h] [rbp-42h] BYREF

v3 = a3;
v4 = open64("/dev/tty", 2);
if ( v4 < 0 )
return 0LL;
v5 = v4;
v15 = -1;
if ( v3 )
{
v15 = func0(v4, 0);
if ( v15 == -1 )
return 0LL;
}
if ( a2 )
fprint(v5, "%s[%s]: ", a1, a2);
else
fprint(v5, "%s: ", a1);
v6 = strdup(&s);
if ( v6 )
{
while ( 1 )
{
v8 = read(v5, buf, 1uLL);
if ( v8 < 0 )
break;
if ( v8 <= 0 )
goto LABEL_14;
if ( buf[0] == 127 )
break;
v9 = buf[0];
if ( buf[0] <= 0xDu )
{
v10 = 9232LL;
if ( _bittest64(&v10, (unsigned __int8)buf[0]) )
{
LABEL_14:
if ( a3 )
{
func0(v5, v15);
write(v5, "\n", 1uLL);
}
close(v5);
if ( !*v6 && a2 )
{
free(v6);
v6 = strdup(a2);
}
return v6;
}
}
if ( buf[0] == 8 )
{
if ( *v6 )
v6[strlen(v6) - 1] = 0;
}
else if ( buf[0] == 21 )
{
if ( a2 )
fprint(v5, "\n%s[%s]: ", a1, a2);
else
fprint(v5, "\n%s: ", a1);
*v6 = 0;
}
else
{
v11 = strlen(v6);
v12 = (char *)malloc(v11 + 2);
v13 = v12;
if ( !v12 )
{
free(v6);
return 0LL;
}
memmove(v12, v6, v11);
free(v6);
v13[v11] = v9;
v13[v11 + 1] = 0;
v6 = v13;
}
}
if ( a3 )
{
func0(v5, v15);
write(v5, "\n", 1uLL);
}
close(v5);
free(v6);
v6 = 0LL;
}
return v6;
}

original_code:
char*
readcons(char *prompt, char *def, int secret)
{
 int fd, n, raw;
 char line[10];
 char *s, *t;
 int l;
 if((fd = open("/dev/tty", 2)) < 0)
  return ((void*)0);
 raw = -1;
 if(secret){
  raw = rawx(fd, 0);
  if(raw == -1)
   return ((void*)0);
 }
 if(def)
  fprint(fd, "%s[%s]: ", prompt, def);
 else
  fprint(fd, "%s: ", prompt);
 s = strdup("");
 if(s == ((void*)0))
  return ((void*)0);
 for(;;){
  n = read(fd, line, 1);
  if(n < 0){
  Error:
   if(secret){
    rawx(fd, raw);
    write(fd, "\n", 1);
   }
   close(fd);
   free(s);
   return ((void*)0);
  }
  if(n > 0 && line[0] == 0x7F)
   goto Error;
  if(n == 0 || line[0] == 0x04 || line[0] == '\n' || line[0] == '\r'){
   if(secret){
    rawx(fd, raw);
    write(fd, "\n", 1);
   }
   close(fd);
   if(*s == 0 && def){
    free(s);
    s = strdup(def);
   }
   return s;
  }
  if(line[0] == '\b'){
   if(strlen(s) > 0)
    s[strlen(s)-1] = 0;
  }else if(line[0] == 0x15){
   if(def != ((void*)0))
    fprint(fd, "\n%s[%s]: ", prompt, def);
   else
    fprint(fd, "\n%s: ", prompt);
   s[0] = 0;
  }else{
   l = strlen(s);
   t = malloc(l+2);
   if(t)
    memmove(t, s, l);
   memset(s, 'X', l);
   free(s);
   if(t == ((void*)0))
    return ((void*)0);
   t[l] = line[0];
   t[l+1] = 0;
   s = t;
  }
 }
}

canonical_original_code:
char *readcons(char *prompt, char *def, int secret)
{
 int fd; int n; int raw;
 char line[10];
 char *s; char *t;
 int l;
 if((fd = open("/dev/tty", 2)) < 0)
  return ((void *)0);
 raw = -1;
 if(secret){
  raw = rawx(fd, 0);
  if(raw == -1)
   return ((void *)0);
 }
 if(def)
  fprint(fd, "%s[%s]: ", prompt, def);
 else
  fprint(fd, "%s: ", prompt);
 s = strdup("");
 if(s == ((void *)0))
  return ((void *)0);
 for(;;){
  n = read(fd, line, 1);
  if(n < 0){
  Error:
   if(secret){
    rawx(fd, raw);
    write(fd, "\n", 1);
   }
   close(fd);
   free(s);
   return ((void *)0);
  }
  if(n > 0 && line[0] == 0x7F)
   goto Error;
  if(n == 0 || line[0] == 0x04 || line[0] == '\n' || line[0] == '\r'){
   if(secret){
    rawx(fd, raw);
    write(fd, "\n", 1);
   }
   close(fd);
   if(*s == 0 && def){
    free(s);
    s = strdup(def);
   }
   return s;
  }
  if(line[0] == '\b'){
   if(strlen(s) > 0)
    s[strlen(s)-1] = 0;
  }else if(line[0] == 0x15){
   if(def != ((void *)0))
    fprint(fd, "\n%s[%s]: ", prompt, def);
   else
    fprint(fd, "\n%s: ", prompt);
   s[0] = 0;
  }else{
   l = strlen(s);
   t = malloc(l+2);
   if(t)
    memmove(t, s, l);
   memset(s, 'X', l);
   free(s);
   if(t == ((void *)0))
    return ((void *)0);
   t[l] = line[0];
   t[l+1] = 0;
   s = t;
  }
 }
}

variable_types:
prompt
char *

variable_types:
def
char *

variable_types: secret int

variable_types: n int

variable_types: raw int

variable_types:
line
char [10]

variable_types:
s
char *

variable_types:
t
char *

variable_types: l int


fmtfmt

decompiled_code:
void *__fastcall fmtfmt(int a1)
{
char *v2; // rdx
char *v3; // rax
int v4; // edi
int *v5; // rbp
void *result; // rax

v2 = &byte_508[16 * fmtalloc];
if ( v2 <= byte_508 )
{
LABEL_5:
_fmtlock();
v4 = knownfmt;
if ( knownfmt )
{
v5 = &knownfmt;
while ( a1 != v4 )
{
v5 += 4;
v4 = *v5;
if ( !*v5 )
goto LABEL_9;
}
_fmtinstall(v4, *((void **)v5 + 1));
_fmtunlock();
result = (void *)*((_QWORD *)v5 + 1);
}
else
{
LABEL_9:
_fmtunlock();
result = &_badfmt;
}
}
else
{
v3 = byte_508;
while ( *(_DWORD *)v3 != a1 )
{
v3 += 16;
if ( v2 <= v3 )
goto LABEL_5;
}
while ( !*((_QWORD *)v3 + 1) )
;
result = (void *)*((_QWORD *)v3 + 1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(int a1)
{
char *v2; // rdx
char *v3; // rax
int v4; // edi
int *v5; // rbp
void *result; // rax

v2 = &byte_508[16 * fmtalloc];
if ( v2 <= byte_508 )
{
LABEL_5:
_fmtlock();
v4 = knownfmt;
if ( knownfmt )
{
v5 = &knownfmt;
while ( a1 != v4 )
{
v5 += 4;
v4 = *v5;
if ( !*v5 )
goto LABEL_9;
}
func0(v4, *((void **)v5 + 1));
_fmtunlock();
result = (void *)*((_QWORD *)v5 + 1);
}
else
{
LABEL_9:
_fmtunlock();
result = &_badfmt;
}
}
else
{
v3 = byte_508;
while ( *(_DWORD *)v3 != a1 )
{
v3 += 16;
if ( v2 <= v3 )
goto LABEL_5;
}
while ( !*((_QWORD *)v3 + 1) )
;
result = (void *)*((_QWORD *)v3 + 1);
}
return result;
}

original_code:
static Fmts
fmtfmt(int c)
{
 Convfmt *p, *ep;
 ep = &fmtalloc.fmt[fmtalloc.nfmt];
 for(p=fmtalloc.fmt; p<ep; p++)
  if(p->c == c){
   while(p->fmt == 0)
    ;
   return p->fmt;
  }
 __fmtlock();
 for(p=knownfmt; p->c; p++)
  if(p->c == c){
   __fmtinstall(p->c, p->fmt);
   __fmtunlock();
   return p->fmt;
  }
 __fmtunlock();
 return __badfmt;
}

canonical_original_code:
static int (*fmtfmt(int c))(struct Fmt *)
{
 struct Convfmt *p; struct Convfmt *ep;
 ep = &fmtalloc.fmt[fmtalloc.nfmt];
 for(p=fmtalloc.fmt; p<ep; p++)
  if(p->c == c){
   while(p->fmt == 0)
    ;
   return p->fmt;
  }
 __fmtlock();
 for(p=knownfmt; p->c; p++)
  if(p->c == c){
   __fmtinstall(p->c, p->fmt);
   __fmtunlock();
   return p->fmt;
  }
 __fmtunlock();
 return __badfmt;
}

variable_types: struct Convfmt { int c; int (*fmt)(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; } *); } *

return_type: int (*)(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; } *)

user_defined_types: struct Convfmt { int c; int (*fmt)(struct Fmt *); }


fmtinstall

decompiled_code:
__int64 __fastcall fmtinstall(int a1, void *a2)
{
unsigned int v2; // ebx

_fmtlock();
v2 = _fmtinstall(a1, a2);
_fmtunlock();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, void *a2)
{
unsigned int v2; // ebx

_fmtlock();
v2 = func0(a1, a2);
_fmtunlock();
return v2;
}

original_code:
int
fmtinstall(int c, int (*f)(Fmt*))
{
 int ret;
 __fmtlock();
 ret = __fmtinstall(c, f);
 __fmtunlock();
 return ret;
}

canonical_original_code:
int fmtinstall(int c, int (*f)(struct Fmt *))
{
 int ret;
 __fmtlock();
 ret = __fmtinstall(c, f);
 __fmtunlock();
 return ret;
}

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

variable_types: ret int


sprint

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

v3 = (unsigned int)~(_DWORD)a1;
if ( a1 <= 0xFFFFFFFFBFFFFFFFLL )
v3 = 0x40000000LL;
va_start(va, a2);
return vsnprint(a1, v3, a2, va);
}

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

v3 = (unsigned int)~(_DWORD)a1;
if ( a1 <= 0xFFFFFFFFBFFFFFFFLL )
v3 = 0x40000000LL;
va_start(va, a2);
return vsnprint(a1, v3, a2, va);
}

original_code:
int
sprint(char *buf, char *fmt, ...)
{
 int n;
 _fmtuint len;
 va_list args;
 len = 1<<30;
 if((_fmtuintptr)buf+len < (_fmtuintptr)buf)
  len = -(_fmtuintptr)buf-1;
 __builtin_va_start(args,fmt);
 n = vsnprint(buf, len, fmt, args);
 __builtin_va_end(args);
 return n;
}

canonical_original_code:
int sprint(char *buf, char *fmt, ...)
{
 int n;
 unsigned int len;
 __builtin_va_list args;
 len = 1<<30;
 if((unsigned long)buf+len < (unsigned long)buf)
  len = -(unsigned long)buf-1;
 __builtin_va_start(args,fmt);
 n = vsnprint(buf, len, fmt, args);
 __builtin_va_end(args);
 return n;
}

variable_types:
buf
char *

variable_types:
fmt
char *

variable_types:
len
unsigned int


runestrlen

decompiled_code:
__int64 __fastcall runestrlen(__int64 a1)
{
return (runestrchr(a1, 0LL) - a1) >> 2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return (runestrchr(a1, 0LL) - a1) >> 2;
}

original_code:
long
runestrlen(Rune *s)
{
 return runestrchr(s, 0) - s;
}

canonical_original_code:
long runestrlen(unsigned int *s)
{
 return runestrchr(s, 0) - s;
}

variable_types:
s
unsigned int *

return_type: long


badd

original_code:
static char*
badd(char *p, int *np, char *data, int ndata, int delim, int nulldelim)
{
 int n;
 n = *np;
 p = p9realloc(p, n+ndata+1);
 if(p){
  memmove(p+n, data, ndata);
  n += ndata;
  if(n>0 && nulldelim && p[n-1]==delim)
   p[--n] = '\0';
  else
   p[n] = '\0';
  *np = n;
 }
 return p;
}

canonical_original_code:
static char *badd(char *p, int *np, char *data, int ndata, int delim, int nulldelim)
{
 int n;
 n = *np;
 p = p9realloc(p, n+ndata+1);
 if(p){
  memmove(p+n, data, ndata);
  n += ndata;
  if(n>0 && nulldelim && p[n-1]==delim)
   p[--n] = '\0';
  else
   p[n] = '\0';
  *np = n;
 }
 return p;
}

variable_types:
p
char *

variable_types:
np
int *

variable_types:
data
char *

variable_types: ndata int

variable_types: delim int

variable_types: nulldelim int


Brdstr

original_code:
char*
Brdstr(Biobuf *bp, int delim, int nulldelim)
{
 char *ip, *ep, *p;
 int i, j;
 i = -bp->icount;
 bp->rdline = 0;
 if(i == 0) {
  if(bp->state != Bractive) {
   if(bp->state == Bracteof)
    bp->state = Bractive;
   bp->gbuf = bp->ebuf;
   return ((void*)0);
  }
 }
 ip = (char*)bp->ebuf - i;
 ep = memchr(ip, delim, i);
 if(ep) {
  j = (ep - ip) + 1;
  bp->icount += j;
  return badd(((void*)0), &bp->rdline, ip, j, delim, nulldelim);
 }
 if(i < bp->bsize)
  memmove(bp->bbuf, ip, i);
 bp->gbuf = bp->bbuf;
 p = ((void*)0);
 for(;;){
  ip = (char*)bp->bbuf + i;
  while(i < bp->bsize) {
   j = read(bp->fid, ip, bp->bsize-i);
   if(j <= 0 && i == 0)
    return p;
   if(j <= 0 && i > 0){
    j = 1;
    ep = ip;
    delim = '\0';
    nulldelim = 1;
    *ep = delim;
   }else{
    bp->offset += j;
    ep = memchr(ip, delim, j);
   }
   i += j;
   if(ep) {
    ip = (char*)bp->ebuf - i;
    if(i < bp->bsize){
     memmove(ip, bp->bbuf, i);
     bp->gbuf = (unsigned char*)ip;
    }
    j = (ep - (char*)bp->bbuf) + 1;
    bp->icount = j - i;
    return badd(p, &bp->rdline, ip, j, delim, nulldelim);
   }
   ip += j;
  }
  p = badd(p, &bp->rdline, (char*)bp->bbuf, bp->bsize, 0, 0);
  i = 0;
  bp->icount = 0;
  bp->gbuf = bp->ebuf;
 }
}

canonical_original_code:
char *Brdstr(struct Biobuf *bp, int delim, int nulldelim)
{
 char *ip; char *ep; char *p;
 int i; int j;
 i = -bp->icount;
 bp->rdline = 0;
 if(i == 0) {
  if(bp->state != Bractive) {
   if(bp->state == Bracteof)
    bp->state = Bractive;
   bp->gbuf = bp->ebuf;
   return ((void *)0);
  }
 }
 ip = (char *)bp->ebuf - i;
 ep = memchr(ip, delim, i);
 if(ep) {
  j = (ep - ip) + 1;
  bp->icount += j;
  return badd(((void *)0), &bp->rdline, ip, j, delim, nulldelim);
 }
 if(i < bp->bsize)
  memmove(bp->bbuf, ip, i);
 bp->gbuf = bp->bbuf;
 p = ((void *)0);
 for(;;){
  ip = (char *)bp->bbuf + i;
  while(i < bp->bsize) {
   j = read(bp->fid, ip, bp->bsize-i);
   if(j <= 0 && i == 0)
    return p;
   if(j <= 0 && i > 0){
    j = 1;
    ep = ip;
    delim = '\0';
    nulldelim = 1;
    *ep = delim;
   }else{
    bp->offset += j;
    ep = memchr(ip, delim, j);
   }
   i += j;
   if(ep) {
    ip = (char *)bp->ebuf - i;
    if(i < bp->bsize){
     memmove(ip, bp->bbuf, i);
     bp->gbuf = (unsigned char *)ip;
    }
    j = (ep - (char *)bp->bbuf) + 1;
    bp->icount = j - i;
    return badd(p, &bp->rdline, ip, j, delim, nulldelim);
   }
   ip += j;
  }
  p = badd(p, &bp->rdline, (char *)bp->bbuf, bp->bsize, 0, 0);
  i = 0;
  bp->icount = 0;
  bp->gbuf = bp->ebuf;
 }
}

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

variable_types:
ep
char *

variable_types: i int

variable_types: j int


Bseek

decompiled_code:
__off64_t __fastcall Bseek(__int64 a1, __off64_t a2, unsigned int a3)
{
__off64_t v3; // r12
__int64 v5; // rdx
__off64_t result; // rax
__int64 v7; // rcx
__int64 v8; // rdx
int v9; // esi

v3 = a2;
v5 = *(unsigned int *)(a1 + 16);
switch ( (_DWORD)v5 )
{
case 2:
Bflush();
result = p9seek(*(unsigned int *)(a1 + 20), a2, a3);
goto LABEL_18;
case 3:
*(_DWORD *)(a1 + 16) = 1;
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 64) = *(_QWORD *)(a1 + 56);
break;
case 1:
break;
default:
fprint(2LL, "Bseek: unknown state %d\n", v5);
return -1LL;
}
if ( a3 == 1 )
{
v3 = Boffset(a1) + a2;
}
else if ( a3 )
{
goto LABEL_17;
}
v7 = v3 - Boffset(a1);
v8 = *(_QWORD *)(a1 + 56) - *(_QWORD *)(a1 + 64);
if ( *(_DWORD *)(a1 + 64) - *(_DWORD *)(a1 + 56) > v7 )
{
a3 = 0;
goto LABEL_17;
}
if ( (int)v8 < v7 )
{
a3 = 0;
goto LABEL_17;
}
v9 = *(_DWORD *)a1 + v7;
*(_DWORD *)a1 = v9;
if ( v7 >= 0 )
{
result = v3;
a3 = 0;
if ( v9 <= 0 )
return result;
goto LABEL_17;
}
result = v3;
a3 = 0;
if ( v8 < -v9 )
{
LABEL_17:
result = lseek64(*(_DWORD *)(a1 + 20), v3, a3);
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 64) = *(_QWORD *)(a1 + 56);
LABEL_18:
*(_QWORD *)(a1 + 32) = result;
}
return result;
}

canonical_decompiled_code:
__off64_t __fastcall func0(__int64 a1, __off64_t a2, unsigned int a3)
{
__off64_t v3; // r12
__int64 v5; // rdx
__off64_t result; // rax
__int64 v7; // rcx
__int64 v8; // rdx
int v9; // esi

v3 = a2;
v5 = *(unsigned int *)(a1 + 16);
switch ( (_DWORD)v5 )
{
case 2:
Bflush();
result = p9seek(*(unsigned int *)(a1 + 20), a2, a3);
goto LABEL_18;
case 3:
*(_DWORD *)(a1 + 16) = 1;
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 64) = *(_QWORD *)(a1 + 56);
break;
case 1:
break;
default:
fprint(2LL, "Bseek: unknown state %d\n", v5);
return -1LL;
}
if ( a3 == 1 )
{
v3 = Boffset(a1) + a2;
}
else if ( a3 )
{
goto LABEL_17;
}
v7 = v3 - Boffset(a1);
v8 = *(_QWORD *)(a1 + 56) - *(_QWORD *)(a1 + 64);
if ( *(_DWORD *)(a1 + 64) - *(_DWORD *)(a1 + 56) > v7 )
{
a3 = 0;
goto LABEL_17;
}
if ( (int)v8 < v7 )
{
a3 = 0;
goto LABEL_17;
}
v9 = *(_DWORD *)a1 + v7;
*(_DWORD *)a1 = v9;
if ( v7 >= 0 )
{
result = v3;
a3 = 0;
if ( v9 <= 0 )
return result;
goto LABEL_17;
}
result = v3;
a3 = 0;
if ( v8 < -v9 )
{
LABEL_17:
result = lseek64(*(_DWORD *)(a1 + 20), v3, a3);
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 64) = *(_QWORD *)(a1 + 56);
LABEL_18:
*(_QWORD *)(a1 + 32) = result;
}
return result;
}

original_code:
long long
Bseek(Biobuf *bp, long long offset, int base)
{
 vlong n, d;
 int bufsz;
 switch(bp->state) {
 default:
  fprint(2, "Bseek: unknown state %d\n", bp->state);
  return Beof;
 case Bracteof:
  bp->state = Bractive;
  bp->icount = 0;
  bp->gbuf = bp->ebuf;
 case Bractive:
  n = offset;
  if(base == 1) {
   n += Boffset(bp);
   base = 0;
  }
  if(base == 0) {
   d = n - Boffset(bp);
   bufsz = bp->ebuf - bp->gbuf;
   if(-bufsz <= d && d <= bufsz){
    bp->icount += d;
    if(d >= 0) {
     if(bp->icount <= 0)
      return n;
    } else {
     if(bp->ebuf - bp->gbuf >= -bp->icount)
      return n;
    }
   }
  }
  n = lseek(bp->fid, n, base);
  bp->icount = 0;
  bp->gbuf = bp->ebuf;
  break;
 case Bwactive:
  Bflush(bp);
  n = p9seek(bp->fid, offset, base);
  break;
 }
 bp->offset = n;
 return n;
}

canonical_original_code:
long long Bseek(struct Biobuf *bp, long long offset, int base)
{
 long long n; long long d;
 int bufsz;
 switch(bp->state) {
 default:
  fprint(2, "Bseek: unknown state %d\n", bp->state);
  return Beof;
 case Bracteof:
  bp->state = Bractive;
  bp->icount = 0;
  bp->gbuf = bp->ebuf;
 case Bractive:
  n = offset;
  if(base == 1) {
   n += Boffset(bp);
   base = 0;
  }
  if(base == 0) {
   d = n - Boffset(bp);
   bufsz = bp->ebuf - bp->gbuf;
   if(-bufsz <= d && d <= bufsz){
    bp->icount += d;
    if(d >= 0) {
     if(bp->icount <= 0)
      return n;
    } else {
     if(bp->ebuf - bp->gbuf >= -bp->icount)
      return n;
    }
   }
  }
  n = lseek(bp->fid, n, base);
  bp->icount = 0;
  bp->gbuf = bp->ebuf;
  break;
 case Bwactive:
  Bflush(bp);
  n = p9seek(bp->fid, offset, base);
  break;
 }
 bp->offset = n;
 return n;
}

variable_types:
offset
long long

variable_types: base int

variable_types:
n
long long

variable_types:
d
long long

variable_types: bufsz int

return_type: long long

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


decompiled_code:
__int64 __fastcall p9nrand(int a1)
{
__int64 result; // rax
__int64 v2; // rax

result = (unsigned int)a1;
if ( a1 >= 0 )
{
do
v2 = p9lrand();
while ( 0x7FFFFFFFLL % a1 >= v2 );
result = (unsigned int)(v2 % a1);
}
return result;
}

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

result = (unsigned int)a1;
if ( a1 >= 0 )
{
do
v2 = p9lrand();
while ( 0x7FFFFFFFLL % a1 >= v2 );
result = (unsigned int)(v2 % a1);
}
return result;
}

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

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

variable_types: n int

variable_types: slop long

variable_types: v long


fmtvprint

original_code:
int
fmtvprint(Fmt *f, char *fmt, va_list args)
{
 va_list va;
 int n;
 f->flags = 0;
 f->width = 0;
 f->prec = 0;
 __builtin_va_copy(va,f->args);
 __builtin_va_end(f->args);
 __builtin_va_copy(f->args,args);
 n = dofmt(f, fmt);
 f->flags = 0;
 f->width = 0;
 f->prec = 0;
 __builtin_va_end(f->args);
 __builtin_va_copy(f->args,va);
 __builtin_va_end(va);
 if(n >= 0)
  return 0;
 return n;
}

canonical_original_code:
int fmtvprint(struct Fmt *f, char *fmt, __builtin_va_list args)
{
 __builtin_va_list va;
 int n;
 f->flags = 0;
 f->width = 0;
 f->prec = 0;
 __builtin_va_copy(va,f->args);
 __builtin_va_end(f->args);
 __builtin_va_copy(f->args,args);
 n = dofmt(f, fmt);
 f->flags = 0;
 f->width = 0;
 f->prec = 0;
 __builtin_va_end(f->args);
 __builtin_va_copy(f->args,va);
 __builtin_va_end(va);
 if(n >= 0)
  return 0;
 return n;
}

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

variable_types:
fmt
char *


child

decompiled_code:
__int64 child()
{
struct rlimit64 v1; // [rsp+0h] [rbp-28h] BYREF
int stat_loc; // [rsp+1Ch] [rbp-Ch] BYREF

notedisable("sys: child");
if ( waitpid(sigpid, &stat_loc, 0) < 0 )
{
fprint(2LL, "%s: wait: %r\n", argv0);
exit(97);
}
if ( (stat_loc & 0x7F) == 0 )
exit(BYTE1(stat_loc));
if ( !__OFSUB__((stat_loc & 0x7F) + 1, 1) && (stat_loc & 0x7F) != 0 )
{
v1.rlim_cur = 0LL;
v1.rlim_max = 0LL;
setrlimit64(RLIMIT_CORE, &v1);
signal(stat_loc & 0x7F, 0LL);
raise(stat_loc & 0x7F);
exit(98);
}
if ( (_BYTE)stat_loc == 127 )
return fprint(2LL, "%s: wait pid %d stopped\n", argv0);
if ( stat_loc != 0xFFFF )
{
fprint(2LL, "%s: wait pid %d status 0x%ux\n", argv0);
exit(99);
}
return fprint(2LL, "%s: wait pid %d continued\n", argv0);
}

canonical_decompiled_code:
__int64 func0()
{
struct rlimit64 v1; // [rsp+0h] [rbp-28h] BYREF
int stat_loc; // [rsp+1Ch] [rbp-Ch] BYREF

notedisable("sys: child");
if ( waitpid(sigpid, &stat_loc, 0) < 0 )
{
fprint(2LL, "%s: wait: %r\n", argv0);
exit(97);
}
if ( (stat_loc & 0x7F) == 0 )
exit(BYTE1(stat_loc));
if ( !__OFSUB__((stat_loc & 0x7F) + 1, 1) && (stat_loc & 0x7F) != 0 )
{
v1.rlim_cur = 0LL;
v1.rlim_max = 0LL;
setrlimit64(RLIMIT_CORE, &v1);
signal(stat_loc & 0x7F, 0LL);
raise(stat_loc & 0x7F);
exit(98);
}
if ( (_BYTE)stat_loc == 127 )
return fprint(2LL, "%s: wait pid %d stopped\n", argv0);
if ( stat_loc != 0xFFFF )
{
fprint(2LL, "%s: wait pid %d status 0x%ux\n", argv0);
exit(99);
}
return fprint(2LL, "%s: wait pid %d continued\n", argv0);
}

original_code:
static void
child(void)
{
 int status, pid;
 struct rlimit rl;
 notedisable("sys: child");
 pid = waitpid(sigpid, &status, 0);
 if(pid < 0){
  fprint(2, "%s: wait: %r\n", argv0);
  _exit(97);
 }
 if((((status) & 0x7f) == 0))
   _exit((((status) & 0xff00) >> 8));
 if((((signed char) (((status) & 0x7f) + 1) >> 1) > 0)){
  rl.rlim_cur = 0;
  rl.rlim_max = 0;
  setrlimit(RLIMIT_CORE, &rl);
  signal(((status) & 0x7f), ((__sighandler_t) 0));
  raise(((status) & 0x7f));
  _exit(98);
 }
 if((((status) & 0xff) == 0x7f)){
  fprint(2, "%s: wait pid %d stopped\n", argv0, pid);
  return;
 }
 if(((status) == 0xffff)){
  fprint(2, "%s: wait pid %d continued\n", argv0, pid);
  return;
 }
 fprint(2, "%s: wait pid %d status 0x%ux\n", argv0, pid, status);
 _exit(99);
}

canonical_original_code:
static void child()
{
 int status; int pid;
 struct rlimit rl;
 notedisable("sys: child");
 pid = waitpid(sigpid, &status, 0);
 if(pid < 0){
  fprint(2, "%s: wait: %r\n", argv0);
  _exit(97);
 }
 if((((status) & 0x7f) == 0))
   _exit((((status) & 0xff00) >> 8));
 if((((char) (((status) & 0x7f) + 1) >> 1) > 0)){
  rl.rlim_cur = 0;
  rl.rlim_max = 0;
  setrlimit(RLIMIT_CORE, &rl);
  signal(((status) & 0x7f), ((void (*)(int)) 0));
  raise(((status) & 0x7f));
  _exit(98);
 }
 if((((status) & 0xff) == 0x7f)){
  fprint(2, "%s: wait pid %d stopped\n", argv0, pid);
  return;
 }
 if(((status) == 0xffff)){
  fprint(2, "%s: wait pid %d continued\n", argv0, pid);
  return;
 }
 fprint(2, "%s: wait pid %d status 0x%ux\n", argv0, pid, status);
 _exit(99);
}

variable_types: status int

variable_types: pid int

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

return_type: void


sigpass

decompiled_code:
void __fastcall sigpass(int a1)
{
if ( sigpid == 1 )
{
gotsigchld = 1;
}
else if ( a1 == 17 )
{
child();
}
else
{
kill(sigpid, a1);
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
if ( sigpid == 1 )
{
gotsigchld = 1;
}
else if ( a1 == 17 )
{
func0();
}
else
{
kill(sigpid, a1);
}
}

original_code:
static void
sigpass(int sig)
{
 if(sigpid == 1){
  gotsigchld = 1;
  return;
 }
 if(sig == 17)
  child();
 else
  kill(sigpid, sig);
}

variable_types: sig int


variable_types:
dest
unsigned char *

variable_types: ndest int

variable_types:
src
char *

variable_types: nsrc int

variable_types:
s
char *

variable_types:
tab
char *

variable_types:
start
unsigned char *

variable_types:
u
int [8]


variable_types:
dest
char *

variable_types:
src
unsigned char *

variable_types:
start
char *

variable_types: j int


fmtcharstod

variable_types:
f
int (*)(void *)

variable_types:
vp
void *

variable_types: num double

variable_types: dem double

variable_types: neg int

variable_types: eneg int

variable_types: dig int

variable_types: exp int

variable_types: c int

return_type: double


decompiled_code:
__pid_t p9wait()
{
unsigned int v0; // eax
__int64 v2; // [rsp+0h] [rbp-108h] BYREF

v0 = await(&v2, 255LL);
return wait((__WAIT_STATUS)v0);
}

canonical_decompiled_code:
__pid_t func1()
{
unsigned int v0; // eax
__int64 v2; // [rsp+0h] [rbp-108h] BYREF

v0 = await(&v2, 255LL);
return func0((__WAIT_STATUS)v0);
}

original_code:
Waitmsg*
p9wait(void)
{
 char buf[256];
 return _wait(await(buf, sizeof buf-1), buf);
}

canonical_original_code:
struct Waitmsg *p9wait()
{
 char buf[256];
 return _wait(await(buf, sizeof buf-1), buf);
}

variable_types:
buf
char [256]

return_type: struct Waitmsg { int pid; unsigned long p9time[3]; char *msg; } *


waitnohang

decompiled_code:
__pid_t waitnohang()
{
unsigned int v0; // eax
__int64 v2; // [rsp+0h] [rbp-108h] BYREF

v0 = awaitnohang(&v2, 255LL);
return wait((__WAIT_STATUS)v0);
}

canonical_decompiled_code:
__pid_t func2()
{
unsigned int v0; // eax
__int64 v2; // [rsp+0h] [rbp-108h] BYREF

v0 = awaitnohang(&v2, 255LL);
return func0((__WAIT_STATUS)v0);
}

original_code:
Waitmsg*
waitnohang(void)
{
 char buf[256];
 return _wait(awaitnohang(buf, sizeof buf-1), buf);
}

canonical_original_code:
struct Waitmsg *waitnohang()
{
 char buf[256];
 return _wait(awaitnohang(buf, sizeof buf-1), buf);
}

user_defined_types: struct Waitmsg { int pid; unsigned long p9time[3]; char *msg; }


decompiled_code:
__pid_t __fastcall p9waitfor(__int64 a1)
{
unsigned int v1; // eax
__int64 v3; // [rsp+0h] [rbp-108h] BYREF

v1 = awaitfor(a1, &v3, 255LL);
return wait((__WAIT_STATUS)v1);
}

canonical_decompiled_code:
__pid_t __fastcall func3(__int64 a1)
{
unsigned int v1; // eax
__int64 v3; // [rsp+0h] [rbp-108h] BYREF

v1 = awaitfor(a1, &v3, 255LL);
return func0((__WAIT_STATUS)v1);
}

original_code:
Waitmsg*
p9waitfor(int pid)
{
 char buf[256];
 return _wait(awaitfor(pid, buf, sizeof buf-1), buf);
}

canonical_original_code:
struct Waitmsg *p9waitfor(int pid)
{
 char buf[256];
 return _wait(awaitfor(pid, buf, sizeof buf-1), buf);
}

variable_types: pid int


runestrncat

original_code:
Rune*
runestrncat(Rune *s1, Rune *s2, long n)
{
 Rune *os1;
 os1 = s1;
 s1 = runestrchr(s1, 0);
 while(*s1++ = *s2++)
  if(--n < 0) {
   s1[-1] = 0;
   break;
  }
 return os1;
}

canonical_original_code:
unsigned int *runestrncat(unsigned int *s1, unsigned int *s2, long n)
{
 unsigned int *os1;
 os1 = s1;
 s1 = runestrchr(s1, 0);
 while(*s1++ = *s2++)
  if(--n < 0) {
   s1[-1] = 0;
   break;
  }
 return os1;
}

variable_types: n long

return_type: unsigned int *


decompiled_code:
__int64 p9rand()
{
return p9lrand() & 0x7FFF;
}

canonical_decompiled_code:
__int64 func0()
{
return p9lrand() & 0x7FFF;
}

original_code:
int
p9rand(void)
{
 return p9lrand() & 0x7fff;
}

canonical_original_code:
int p9rand()
{
 return p9lrand() & 0x7fff;
}


Bgetc

original_code:
int
Bgetc(Biobuf *bp)
{
 int i;
loop:
 i = bp->icount;
 if(i != 0) {
  bp->icount = i+1;
  return bp->ebuf[i];
 }
 if(bp->state != Bractive) {
  if(bp->state == Bracteof)
   bp->state = Bractive;
  return Beof;
 }
 memmove(bp->bbuf-Bungetsize, bp->ebuf-Bungetsize, Bungetsize);
 i = read(bp->fid, bp->bbuf, bp->bsize);
 bp->gbuf = bp->bbuf;
 if(i <= 0) {
  bp->state = Bracteof;
  if(i < 0)
   bp->state = Binactive;
  return Beof;
 }
 if(i < bp->bsize) {
  memmove(bp->ebuf-i-Bungetsize, bp->bbuf-Bungetsize, i+Bungetsize);
  bp->gbuf = bp->ebuf-i;
 }
 bp->icount = -i;
 bp->offset += i;
 goto loop;
}

canonical_original_code:
int Bgetc(struct Biobuf *bp)
{
 int i;
loop:
 i = bp->icount;
 if(i != 0) {
  bp->icount = i+1;
  return bp->ebuf[i];
 }
 if(bp->state != Bractive) {
  if(bp->state == Bracteof)
   bp->state = Bractive;
  return Beof;
 }
 memmove(bp->bbuf-Bungetsize, bp->ebuf-Bungetsize, Bungetsize);
 i = read(bp->fid, bp->bbuf, bp->bsize);
 bp->gbuf = bp->bbuf;
 if(i <= 0) {
  bp->state = Bracteof;
  if(i < 0)
   bp->state = Binactive;
  return Beof;
 }
 if(i < bp->bsize) {
  memmove(bp->ebuf-i-Bungetsize, bp->bbuf-Bungetsize, i+Bungetsize);
  bp->gbuf = bp->ebuf-i;
 }
 bp->icount = -i;
 bp->offset += i;
 goto loop;
}

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


Bungetc

decompiled_code:
__int64 __fastcall Bungetc(_DWORD *a1)
{
int v1; // eax
unsigned int v2; // edx

v1 = a1[4];
if ( v1 == 3 )
{
a1[4] = 1;
goto LABEL_5;
}
v2 = -1;
if ( v1 == 1 )
{
LABEL_5:
--*a1;
v2 = 1;
}
return v2;
}

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

v1 = a1[4];
if ( v1 == 3 )
{
a1[4] = 1;
goto LABEL_5;
}
v2 = -1;
if ( v1 == 1 )
{
LABEL_5:
--*a1;
v2 = 1;
}
return v2;
}

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

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


decompiled_code:
int __fastcall p9sleep(__int64 a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

if ( a1 )
{
v2.tv_sec = a1 / 1000;
v2.tv_usec = 1000 * (a1 % 1000);
result = select(0, 0LL, 0LL, 0LL, &v2);
}
else
{
sched_yield();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int result; // eax
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

if ( a1 )
{
v2.tv_sec = a1 / 1000;
v2.tv_usec = 1000 * (a1 % 1000);
result = select(0, 0LL, 0LL, 0LL, &v2);
}
else
{
sched_yield();
result = 0;
}
return result;
}

original_code:
int
p9sleep(long milli)
{
 struct timeval tv;
 if(milli == 0){
  sched_yield();
  return 0;
 }
 tv.tv_sec = milli/1000;
 tv.tv_usec = (milli%1000)*1000;
 return select(0, 0, 0, 0, &tv);
}

variable_types: milli long

variable_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__time_t __fastcall p9alarm(unsigned __int64 a1)
{
__time_t result; // rax
struct itimerval v2; // [rsp+0h] [rbp-48h] BYREF
struct itimerval newa; // [rsp+20h] [rbp-28h] BYREF

newa.it_interval.tv_sec = 0LL;
newa.it_interval.tv_usec = 0LL;
newa.it_value.tv_sec = a1 / 0x3E8;
newa.it_value.tv_usec = 1000 * (a1 % 0x3E8);
if ( setitimer(ITIMER_REAL, &newa, &v2) < 0 )
result = -1LL;
else
result = 1000 * v2.it_value.tv_sec + v2.it_value.tv_usec / 1000;
return result;
}

canonical_decompiled_code:
__time_t __fastcall func1(unsigned __int64 a1)
{
__time_t result; // rax
struct itimerval v2; // [rsp+0h] [rbp-48h] BYREF
struct itimerval newa; // [rsp+20h] [rbp-28h] BYREF

newa.it_interval.tv_sec = 0LL;
newa.it_interval.tv_usec = 0LL;
newa.it_value.tv_sec = a1 / 0x3E8;
newa.it_value.tv_usec = 1000 * (a1 % 0x3E8);
if ( setitimer(ITIMER_REAL, &newa, &v2) < 0 )
result = -1LL;
else
result = 1000 * v2.it_value.tv_sec + v2.it_value.tv_usec / 1000;
return result;
}

original_code:
long
p9alarm(ulong milli)
{
 struct itimerval itv;
 struct itimerval oitv;
 itv.it_interval.tv_sec = 0;
 itv.it_interval.tv_usec = 0;
 itv.it_value.tv_sec = milli/1000;
 itv.it_value.tv_usec = (milli%1000)*1000;
 if(setitimer(ITIMER_REAL, &itv, &oitv) < 0)
  return -1;
 return oitv.it_value.tv_sec*1000+oitv.it_value.tv_usec/1000;
}

canonical_original_code:
long p9alarm(unsigned long milli)
{
 struct itimerval itv;
 struct itimerval oitv;
 itv.it_interval.tv_sec = 0;
 itv.it_interval.tv_usec = 0;
 itv.it_value.tv_sec = milli/1000;
 itv.it_value.tv_usec = (milli%1000)*1000;
 if(setitimer(ITIMER_REAL, &itv, &oitv) < 0)
  return -1;
 return oitv.it_value.tv_sec*1000+oitv.it_value.tv_usec/1000;
}

variable_types:
milli
unsigned long

variable_types: struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }


fmtrune

original_code:
int
fmtrune(Fmt *f, int r)
{
 Rune *rt;
 char *t;
 int n;
 if(f->runes){
  rt = (Rune*)f->to;
  do{ if(rt + 1 > (Rune*)f->stop){ rt = (Rune*)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) f->stop = (Rune*)f->stop; else return -1; } *rt++ = r; }while(0);
  f->to = rt;
  n = 1;
 }else{
  t = (char*)f->to;
  do{ Rune _rune; int _runelen; if(t + UTFmax > (char*)f->stop && t + (_runelen = runelen(r)) > (char*)f->stop){ t = (char*)__fmtflush(f, t, _runelen); if(t != 0) f->stop = (char*)f->stop; else return -1; } if(r < Runeself) *t++ = r; else{ _rune = r; t += runetochar(t, &_rune); } }while(0);
  n = t - (char*)f->to;
  f->to = t;
 }
 f->nfmt += n;
 return 0;
}

canonical_original_code:
int fmtrune(struct Fmt *f, int r)
{
 unsigned int *rt;
 char *t;
 int n;
 if(f->runes){
  rt = (unsigned int *)f->to;
  do{ if(rt + 1 > (unsigned int *)f->stop){ rt = (unsigned int *)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) f->stop = (unsigned int *)f->stop; else return -1; } *rt++ = r; }while(0);
  f->to = rt;
  n = 1;
 }else{
  t = (char *)f->to;
  do{ unsigned int _rune; int _runelen; if(t + UTFmax > (char *)f->stop && t + (_runelen = runelen(r)) > (char *)f->stop){ t = (char *)__fmtflush(f, t, _runelen); if(t != 0) f->stop = (char *)f->stop; else return -1; } if(r < Runeself) *t++ = r; else{ _rune = r; t += runetochar(t, &_rune); } }while(0);
  n = t - (char *)f->to;
  f->to = t;
 }
 f->nfmt += n;
 return 0;
}

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

variable_types: r int

variable_types:
rt
unsigned int *

variable_types:
t
char *

variable_types: n int


exitcode

decompiled_code:
__int64 exitcode()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
int
exitcode(char *s)
{
 return 1;
}

canonical_original_code:
int exitcode(char *s)
{
 return 1;
}

variable_types:
s
char *


runestrncmp

decompiled_code:
__int64 __fastcall runestrncmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
unsigned int v7; // edx
unsigned int v8; // ecx

for ( i = 0LL; a3 - i > 0; ++i )
{
v7 = *(_DWORD *)(a1 + 4 * i);
v8 = *(_DWORD *)(a2 + 4 * i);
if ( v7 != v8 )
return v8 < v7 ? 1 : -1;
if ( !v7 )
return 0LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
unsigned int v7; // edx
unsigned int v8; // ecx

for ( i = 0LL; a3 - i > 0; ++i )
{
v7 = *(_DWORD *)(a1 + 4 * i);
v8 = *(_DWORD *)(a2 + 4 * i);
if ( v7 != v8 )
return v8 < v7 ? 1 : -1;
if ( !v7 )
return 0LL;
}
return 0LL;
}

original_code:
int
runestrncmp(Rune *s1, Rune *s2, long n)
{
 Rune c1, c2;
 while(n > 0) {
  c1 = *s1++;
  c2 = *s2++;
  n--;
  if(c1 != c2) {
   if(c1 > c2)
    return 1;
   return -1;
  }
  if(c1 == 0)
   break;
 }
 return 0;
}

canonical_original_code:
int runestrncmp(unsigned int *s1, unsigned int *s2, long n)
{
 unsigned int c1; unsigned int c2;
 while(n > 0) {
  c1 = *s1++;
  c2 = *s2++;
  n--;
  if(c1 != c2) {
   if(c1 > c2)
    return 1;
   return -1;
  }
  if(c1 == 0)
   break;
 }
 return 0;
}


unsharp

decompiled_code:
char *__fastcall unsharp(char *s1)
{
__int64 v1; // rbx
const char *v2; // r15
const char *v3; // r14
int v4; // er13
char *v5; // r12
char *v6; // r13
int v7; // er14
int v8; // ebx
int v10; // [rsp+Ch] [rbp-3Ch]

if ( !qword_148[0] )
qword_148[0] = get9root();
v1 = 0LL;
while ( 1 )
{
v10 = v1;
v2 = (const char *)qword_148[2 * v1];
if ( v2 )
{
v3 = (&replace)[2 * v1];
v4 = strlen(v3);
if ( !strncmp(s1, v3, v4) )
{
v5 = &s1[v4];
if ( !*v5 || *v5 == 47 )
break;
}
}
if ( ++v1 == 2 )
return s1;
}
v7 = strlen(v2);
v8 = strlen(s1) + v7 - v4;
v6 = (char *)p9malloc(v8 + 1);
if ( !v6 )
sysfatal("out of memory translating %s to %s%s", s1, (const char *)qword_148[2 * v10], v5);
strcpy(v6, (const char *)qword_148[2 * v10]);
strcpy(&v6[v7], v5);
if ( strlen(v6) != v8 )
_assert_fail("strlen(new) == len", "unsharp.c", 0x28u, "unsharp");
return v6;
}

canonical_decompiled_code:
char *__fastcall func0(char *s1)
{
__int64 v1; // rbx
const char *v2; // r15
const char *v3; // r14
int v4; // er13
char *v5; // r12
char *v6; // r13
int v7; // er14
int v8; // ebx
int v10; // [rsp+Ch] [rbp-3Ch]

if ( !qword_148[0] )
qword_148[0] = get9root();
v1 = 0LL;
while ( 1 )
{
v10 = v1;
v2 = (const char *)qword_148[2 * v1];
if ( v2 )
{
v3 = (&replace)[2 * v1];
v4 = strlen(v3);
if ( !strncmp(s1, v3, v4) )
{
v5 = &s1[v4];
if ( !*v5 || *v5 == 47 )
break;
}
}
if ( ++v1 == 2 )
return s1;
}
v7 = strlen(v2);
v8 = strlen(s1) + v7 - v4;
v6 = (char *)p9malloc(v8 + 1);
if ( !v6 )
sysfatal("out of memory translating %s to %s%s", s1, (const char *)qword_148[2 * v10], v5);
strcpy(v6, (const char *)qword_148[2 * v10]);
strcpy(&v6[v7], v5);
if ( strlen(v6) != v8 )
_assert_fail("strlen(new) == len", "unsharp.c", 0x28u, "unsharp");
return v6;
}

original_code:
char*
unsharp(char *old)
{
 char *new;
 int i, olen, nlen, len;
 if(replace[0].new == ((void*)0))
  replace[0].new = get9root();
 for(i=0; i<(sizeof(replace)/sizeof((replace)[0])); i++){
  if(!replace[i].new)
   continue;
  olen = strlen(replace[i].old);
  if(strncmp(old, replace[i].old, olen) != 0
  || (old[olen] != '\0' && old[olen] != '/'))
   continue;
  nlen = strlen(replace[i].new);
  len = strlen(old)+nlen-olen;
  new = p9malloc(len+1);
  if(new == ((void*)0))
   sysfatal("out of memory translating %s to %s%s", old, replace[i].new, old+olen);
  strcpy(new, replace[i].new);
  strcpy(new+nlen, old+olen);
  ((void) sizeof ((strlen(new) == len) ? 1 : 0), __extension__ ({ if (strlen(new) == len) ; else __assert_fail ("strlen(new) == len", "unsharp.c", 40, __extension__ __PRETTY_FUNCTION__); }));
  return new;
 }
 return old;
}

canonical_original_code:
char *unsharp(char *old)
{
 char *new;
 int i; int olen; int nlen; int len;
 if(replace[0].new == ((void *)0))
  replace[0].new = get9root();
 for(i=0; i<(sizeof(replace)/sizeof((replace)[0])); i++){
  if(!replace[i].new)
   continue;
  olen = strlen(replace[i].old);
  if(strncmp(old, replace[i].old, olen) != 0
  || (old[olen] != '\0' && old[olen] != '/'))
   continue;
  nlen = strlen(replace[i].new);
  len = strlen(old)+nlen-olen;
  new = p9malloc(len+1);
  if(new == ((void *)0))
   sysfatal("out of memory translating %s to %s%s", old, replace[i].new, old+olen);
  strcpy(new, replace[i].new);
  strcpy(new+nlen, old+olen);
  ((void) sizeof ((strlen(new) == len) ? 1 : 0), __extension__ ({ if (strlen(new) == len) ; else __assert_fail ("strlen(new) == len", "unsharp.c", 40, __extension__ __PRETTY_FUNCTION__); }));
  return new;
 }
 return old;
}

variable_types:
old
char *

variable_types:
new
char *

variable_types: olen int

variable_types: nlen int

variable_types: len int


runestrrchr

decompiled_code:
__int64 __fastcall runestrrchr(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = 0LL;
if ( !a2 )
return runestrchr(a1, 0LL);
while ( 1 )
{
v3 = runestrchr(a1, a2);
if ( !v3 )
break;
a1 = v3 + 4;
v2 = v3;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
__int64 v3; // rax

v2 = 0LL;
if ( !a2 )
return runestrchr(a1, 0LL);
while ( 1 )
{
v3 = runestrchr(a1, a2);
if ( !v3 )
break;
a1 = v3 + 4;
v2 = v3;
}
return v2;
}

original_code:
Rune*
runestrrchr(Rune *s, Rune c)
{
 Rune *r;
 if(c == 0)
  return runestrchr(s, 0);
 r = 0;
 while(s = runestrchr(s, c))
  r = s++;
 return r;
}

canonical_original_code:
unsigned int *runestrrchr(unsigned int *s, unsigned int c)
{
 unsigned int *r;
 if(c == 0)
  return runestrchr(s, 0);
 r = 0;
 while(s = runestrchr(s, c))
  r = s++;
 return r;
}

variable_types:
s
unsigned int *

variable_types:
c
unsigned int

variable_types:
r
unsigned int *


utflen

decompiled_code:
__int64 __fastcall utflen(_BYTE *a1)
{
unsigned int i; // ebp
char v4[28]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = 0; ; ++i )
{
if ( (unsigned __int8)*a1 > 0x7Fu )
{
a1 += (int)chartorune(v4, a1);
continue;
}
if ( !*a1 )
break;
++a1;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
unsigned int i; // ebp
char v4[28]; // [rsp+Ch] [rbp-1Ch] BYREF

for ( i = 0; ; ++i )
{
if ( (unsigned __int8)*a1 > 0x7Fu )
{
a1 += (int)chartorune(v4, a1);
continue;
}
if ( !*a1 )
break;
++a1;
}
return i;
}

original_code:
int
utflen(char *s)
{
 int c;
 long n;
 Rune rune;
 n = 0;
 for(;;) {
  c = *(_utfuchar*)s;
  if(c < Runeself) {
   if(c == 0)
    return n;
   s++;
  } else
   s += chartorune(&rune, s);
  n++;
 }
}

canonical_original_code:
int utflen(char *s)
{
 int c;
 long n;
 unsigned int rune;
 n = 0;
 for(;;) {
  c = *(unsigned char *)s;
  if(c < Runeself) {
   if(c == 0)
    return n;
   s++;
  } else
   s += chartorune(&rune, s);
  n++;
 }
}

variable_types: c int

variable_types: n long

variable_types:
rune
unsigned int


runesprint

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

va_start(va, a2);
return runevsnprint(a1, 256LL, a2, va);
}

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

va_start(va, a2);
return runevsnprint(a1, 256LL, a2, va);
}

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

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

variable_types:
buf
unsigned int *

variable_types:
fmt
char *


runesmprint

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

va_start(va, a1);
return runevsmprint(a1, va);
}

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

va_start(va, a1);
return runevsmprint(a1, va);
}

original_code:
Rune*
runesmprint(char *fmt, ...)
{
 va_list args;
 Rune *p;
 __builtin_va_start(args,fmt);
 p = runevsmprint(fmt, args);
 __builtin_va_end(args);
 return p;
}

canonical_original_code:
unsigned int *runesmprint(char *fmt, ...)
{
 __builtin_va_list args;
 unsigned int *p;
 __builtin_va_start(args,fmt);
 p = runevsmprint(fmt, args);
 __builtin_va_end(args);
 return p;
}

variable_types:
p
unsigned int *


Brdline

original_code:
void*
Brdline(Biobuf *bp, int delim)
{
 char *ip, *ep;
 int i, j;
 i = -bp->icount;
 if(i == 0) {
  if(bp->state != Bractive) {
   if(bp->state == Bracteof)
    bp->state = Bractive;
   bp->rdline = 0;
   bp->gbuf = bp->ebuf;
   return 0;
  }
 }
 ip = (char*)bp->ebuf - i;
 ep = memchr(ip, delim, i);
 if(ep) {
  j = (ep - ip) + 1;
  bp->rdline = j;
  bp->icount += j;
  return ip;
 }
 if(i < bp->bsize)
  memmove(bp->bbuf, ip, i);
 bp->gbuf = bp->bbuf;
 ip = (char*)bp->bbuf + i;
 while(i < bp->bsize) {
  j = read(bp->fid, ip, bp->bsize-i);
  if(j <= 0) {
   memmove(bp->ebuf-i, bp->bbuf, i);
   bp->rdline = i;
   bp->icount = -i;
   bp->gbuf = bp->ebuf-i;
   return 0;
  }
  bp->offset += j;
  i += j;
  ep = memchr(ip, delim, j);
  if(ep) {
   ip = (char*)bp->ebuf - i;
   if(i < bp->bsize){
    memmove(ip, bp->bbuf, i);
    bp->gbuf = (unsigned char*)ip;
   }
   j = (ep - (char*)bp->bbuf) + 1;
   bp->rdline = j;
   bp->icount = j - i;
   return ip;
  }
  ip += j;
 }
 bp->rdline = bp->bsize;
 bp->icount = -bp->bsize;
 bp->gbuf = bp->bbuf;
 return 0;
}

canonical_original_code:
void *Brdline(struct Biobuf *bp, int delim)
{
 char *ip; char *ep;
 int i; int j;
 i = -bp->icount;
 if(i == 0) {
  if(bp->state != Bractive) {
   if(bp->state == Bracteof)
    bp->state = Bractive;
   bp->rdline = 0;
   bp->gbuf = bp->ebuf;
   return 0;
  }
 }
 ip = (char *)bp->ebuf - i;
 ep = memchr(ip, delim, i);
 if(ep) {
  j = (ep - ip) + 1;
  bp->rdline = j;
  bp->icount += j;
  return ip;
 }
 if(i < bp->bsize)
  memmove(bp->bbuf, ip, i);
 bp->gbuf = bp->bbuf;
 ip = (char *)bp->bbuf + i;
 while(i < bp->bsize) {
  j = read(bp->fid, ip, bp->bsize-i);
  if(j <= 0) {
   memmove(bp->ebuf-i, bp->bbuf, i);
   bp->rdline = i;
   bp->icount = -i;
   bp->gbuf = bp->ebuf-i;
   return 0;
  }
  bp->offset += j;
  i += j;
  ep = memchr(ip, delim, j);
  if(ep) {
   ip = (char *)bp->ebuf - i;
   if(i < bp->bsize){
    memmove(ip, bp->bbuf, i);
    bp->gbuf = (unsigned char *)ip;
   }
   j = (ep - (char *)bp->bbuf) + 1;
   bp->rdline = j;
   bp->icount = j - i;
   return ip;
  }
  ip += j;
 }
 bp->rdline = bp->bsize;
 bp->icount = -bp->bsize;
 bp->gbuf = bp->bbuf;
 return 0;
}

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

variable_types:
ip
char *

variable_types:
ep
char *

variable_types: i int

variable_types: j int

return_type: void *


Blinelen

decompiled_code:
__int64 __fastcall Blinelen(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int
Blinelen(Biobuf *bp)
{
 return bp->rdline;
}

canonical_original_code:
int Blinelen(struct Biobuf *bp)
{
 return bp->rdline;
}


sendfd

decompiled_code:
__int64 __fastcall sendfd(int a1, int a2)
{
int v2; // eax
__int64 v4; // [rsp+0h] [rbp-88h] BYREF
int v5; // [rsp+8h] [rbp-80h]
int v6; // [rsp+Ch] [rbp-7Ch]
int v7; // [rsp+10h] [rbp-78h]
struct msghdr message; // [rsp+20h] [rbp-68h] BYREF
char *v9; // [rsp+60h] [rbp-28h] BYREF
__int64 v10; // [rsp+68h] [rbp-20h]
char v11; // [rsp+7Fh] [rbp-9h] BYREF

v11 = 0;
v9 = &v11;
v10 = 1LL;
message.msg_name = 0LL;
*(_QWORD *)&message.msg_namelen = 0LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_iov = (iovec *)&v9;
message.msg_iovlen = 1LL;
message.msg_control = &v4;
message.msg_controllen = 20LL;
v4 = 20LL;
v5 = 1;
v6 = 1;
v7 = a2;
v2 = sendmsg(a1, &message, 0);
return (unsigned int)-(v10 != v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
int v2; // eax
__int64 v4; // [rsp+0h] [rbp-88h] BYREF
int v5; // [rsp+8h] [rbp-80h]
int v6; // [rsp+Ch] [rbp-7Ch]
int v7; // [rsp+10h] [rbp-78h]
struct msghdr message; // [rsp+20h] [rbp-68h] BYREF
char *v9; // [rsp+60h] [rbp-28h] BYREF
__int64 v10; // [rsp+68h] [rbp-20h]
char v11; // [rsp+7Fh] [rbp-9h] BYREF

v11 = 0;
v9 = &v11;
v10 = 1LL;
message.msg_name = 0LL;
*(_QWORD *)&message.msg_namelen = 0LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_iov = (iovec *)&v9;
message.msg_iovlen = 1LL;
message.msg_control = &v4;
message.msg_controllen = 20LL;
v4 = 20LL;
v5 = 1;
v6 = 1;
v7 = a2;
v2 = sendmsg(a1, &message, 0);
return (unsigned int)-(v10 != v2);
}

original_code:
int
sendfd(int s, int fd)
{
 char buf[1];
 struct iovec iov;
 struct msghdr msg;
 struct cmsghdr *cmsg;
 int n;
 char cms[((((sizeof(int)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))];
 buf[0] = 0;
 iov.iov_base = buf;
 iov.iov_len = 1;
 memset(&msg, 0, sizeof msg);
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 msg.msg_control = (caddr_t)cms;
 msg.msg_controllen = ((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (sizeof(int)));
 cmsg = ((size_t) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
 cmsg->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (sizeof(int)));
 cmsg->cmsg_level = 1;
 cmsg->cmsg_type = SCM_RIGHTS;
 memmove(((cmsg)->__cmsg_data), &fd, sizeof(int));
 if((n=sendmsg(s, &msg, 0)) != iov.iov_len)
  return -1;
 return 0;
}

canonical_original_code:
int sendfd(int s, int fd)
{
 char buf[1];
 struct iovec iov;
 struct msghdr msg;
 struct cmsghdr *cmsg;
 int n;
 char cms[-1];
 buf[0] = 0;
 iov.iov_base = buf;
 iov.iov_len = 1;
 memset(&msg, 0, sizeof msg);
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 msg.msg_control = (char *)cms;
 msg.msg_controllen = ((((sizeof (struct cmsghdr)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)) + (sizeof(int)));
 cmsg = ((unsigned long) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
 cmsg->cmsg_len = ((((sizeof (struct cmsghdr)) + sizeof (unsigned long) - 1) & (unsigned long) ~(sizeof (unsigned long) - 1)) + (sizeof(int)));
 cmsg->cmsg_level = 1;
 cmsg->cmsg_type = SCM_RIGHTS;
 memmove(((cmsg)->__cmsg_data), &fd, sizeof(int));
 if((n=sendmsg(s, &msg, 0)) != iov.iov_len)
  return -1;
 return 0;
}

variable_types: s int

variable_types: fd int

variable_types:
buf
char [1]

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; } *

variable_types: n int

variable_types:
cms
char [-1]

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


recvfd

decompiled_code:
__int64 __fastcall recvfd(int a1)
{
int v1; // eax
unsigned int *v2; // rax
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-88h] BYREF
struct msghdr message; // [rsp+20h] [rbp-68h] BYREF
__int64 v6[3]; // [rsp+60h] [rbp-28h] BYREF
char v7; // [rsp+7Fh] [rbp-9h] BYREF

v6[0] = (__int64)&v7;
v6[1] = 1LL;
message.msg_name = 0LL;
*(_QWORD *)&message.msg_namelen = 0LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_iov = (iovec *)v6;
message.msg_iovlen = 1LL;
message.msg_control = &v4;
message.msg_controllen = 24LL;
v1 = recvmsg(a1, &message, 0);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
if ( v1 )
{
v2 = 0LL;
if ( message.msg_controllen > 0xF )
v2 = (unsigned int *)message.msg_control;
result = v2[4];
}
else
{
werrstr("unexpected EOF");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
int v1; // eax
unsigned int *v2; // rax
__int64 result; // rax
__int64 v4; // [rsp+0h] [rbp-88h] BYREF
struct msghdr message; // [rsp+20h] [rbp-68h] BYREF
__int64 v6[3]; // [rsp+60h] [rbp-28h] BYREF
char v7; // [rsp+7Fh] [rbp-9h] BYREF

v6[0] = (__int64)&v7;
v6[1] = 1LL;
message.msg_name = 0LL;
*(_QWORD *)&message.msg_namelen = 0LL;
*(_QWORD *)&message.msg_flags = 0LL;
message.msg_iov = (iovec *)v6;
message.msg_iovlen = 1LL;
message.msg_control = &v4;
message.msg_controllen = 24LL;
v1 = recvmsg(a1, &message, 0);
if ( v1 < 0 )
return 0xFFFFFFFFLL;
if ( v1 )
{
v2 = 0LL;
if ( message.msg_controllen > 0xF )
v2 = (unsigned int *)message.msg_control;
result = v2[4];
}
else
{
werrstr("unexpected EOF");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
recvfd(int s)
{
 int n;
 int fd;
 char buf[1];
 struct iovec iov;
 struct msghdr msg;
 struct cmsghdr *cmsg;
 char cms[((((sizeof(int)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))];
 iov.iov_base = buf;
 iov.iov_len = 1;
 memset(&msg, 0, sizeof msg);
 msg.msg_name = 0;
 msg.msg_namelen = 0;
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 msg.msg_control = (caddr_t)cms;
 msg.msg_controllen = sizeof cms;
 if((n=recvmsg(s, &msg, 0)) < 0)
  return -1;
 if(n == 0){
  werrstr("unexpected EOF");
  return -1;
 }
 cmsg = ((size_t) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
 memmove(&fd, ((cmsg)->__cmsg_data), sizeof(int));
 return fd;
}

canonical_original_code:
int recvfd(int s)
{
 int n;
 int fd;
 char buf[1];
 struct iovec iov;
 struct msghdr msg;
 struct cmsghdr *cmsg;
 char cms[-1];
 iov.iov_base = buf;
 iov.iov_len = 1;
 memset(&msg, 0, sizeof msg);
 msg.msg_name = 0;
 msg.msg_namelen = 0;
 msg.msg_iov = &iov;
 msg.msg_iovlen = 1;
 msg.msg_control = (char *)cms;
 msg.msg_controllen = sizeof cms;
 if((n=recvmsg(s, &msg, 0)) < 0)
  return -1;
 if(n == 0){
  werrstr("unexpected EOF");
  return -1;
 }
 cmsg = ((unsigned long) (&msg)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msg)->msg_control : (struct cmsghdr *) 0);
 memmove(&fd, ((cmsg)->__cmsg_data), sizeof(int));
 return fd;
}

variable_types: struct iovec { void *iov_base; unsigned long iov_len; }

user_defined_types: struct cmsghdr { unsigned long cmsg_len; int cmsg_level; int cmsg_type; unsigned char __cmsg_data[]; }


fmtBflush

original_code:
static int
fmtBflush(Fmt *f)
{
 Biobuf *bp;
 bp = f->farg;
 bp->ocount = (char*)f->to - (char*)f->stop;
 if(Bflush(bp) < 0)
  return 0;
 f->stop = bp->ebuf;
 f->to = (char*)f->stop + bp->ocount;
 f->start = f->to;
 return 1;
}

canonical_original_code:
static int fmtBflush(struct Fmt *f)
{
 struct Biobuf *bp;
 bp = f->farg;
 bp->ocount = (char *)f->to - (char *)f->stop;
 if(Bflush(bp) < 0)
  return 0;
 f->stop = bp->ebuf;
 f->to = (char *)f->stop + bp->ocount;
 f->start = f->to;
 return 1;
}

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


Bvprint

original_code:
int
Bvprint(Biobuf *bp, char *fmt, va_list arg)
{
 int n;
 Fmt f;
 f.runes = 0;
 f.stop = bp->ebuf;
 f.start = (char*)f.stop + bp->ocount;
 f.to = f.start;
 f.flush = fmtBflush;
 f.farg = bp;
 f.nfmt = 0;
 fmtlocaleinit(&f, ((void*)0), ((void*)0), ((void*)0));
 n = fmtvprint(&f, fmt, arg);
 bp->ocount = (char*)f.to - (char*)f.stop;
 if(n == 0)
  n = f.nfmt;
 return n;
}

canonical_original_code:
int Bvprint(struct Biobuf *bp, char *fmt, __builtin_va_list arg)
{
 int n;
 struct Fmt f;
 f.runes = 0;
 f.stop = bp->ebuf;
 f.start = (char *)f.stop + bp->ocount;
 f.to = f.start;
 f.flush = fmtBflush;
 f.farg = bp;
 f.nfmt = 0;
 fmtlocaleinit(&f, ((void *)0), ((void *)0), ((void *)0));
 n = fmtvprint(&f, fmt, arg);
 bp->ocount = (char *)f.to - (char *)f.stop;
 if(n == 0)
  n = f.nfmt;
 return n;
}

variable_types:
fmt
char *

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


fmtprint

original_code:
int
fmtprint(Fmt *f, char *fmt, ...)
{
 va_list va;
 int n;
 f->flags = 0;
 f->width = 0;
 f->prec = 0;
 __builtin_va_copy(va,f->args);
 __builtin_va_end(f->args);
 __builtin_va_start(f->args,fmt);
 n = dofmt(f, fmt);
 __builtin_va_end(f->args);
 f->flags = 0;
 f->width = 0;
 f->prec = 0;
 __builtin_va_copy(f->args,va);
 __builtin_va_end(va);
 if(n >= 0)
  return 0;
 return n;
}

canonical_original_code:
int fmtprint(struct Fmt *f, char *fmt, ...)
{
 __builtin_va_list va;
 int n;
 f->flags = 0;
 f->width = 0;
 f->prec = 0;
 __builtin_va_copy(va,f->args);
 __builtin_va_end(f->args);
 __builtin_va_start(f->args,fmt);
 n = dofmt(f, fmt);
 __builtin_va_end(f->args);
 f->flags = 0;
 f->width = 0;
 f->prec = 0;
 __builtin_va_copy(f->args,va);
 __builtin_va_end(va);
 if(n >= 0)
  return 0;
 return n;
}

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


cistrcmp

decompiled_code:
__int64 __fastcall cistrcmp(unsigned __int8 *a1, char *a2)
{
unsigned __int8 v4; // al
int v6; // esi
int v7; // ecx
unsigned __int8 v8; // dl

v4 = *a1;
if ( !*a1 )
return (unsigned int)-*a2;
while ( 1 )
{
++a1;
v7 = v4;
v8 = *a2++;
v6 = v8;
if ( v4 == v8 )
goto LABEL_7;
if ( (unsigned int)v4 - 65 > 0x19 )
{
if ( (unsigned int)v8 - 65 > 0x19 )
return (unsigned int)(v7 - v6);
LABEL_5:
v6 = v8 + 32;
goto LABEL_6;
}
v7 = v4 + 32;
if ( (unsigned int)v8 - 65 <= 0x19 )
goto LABEL_5;
LABEL_6:
if ( v6 != v7 )
return (unsigned int)(v7 - v6);
LABEL_7:
v4 = *a1;
if ( !*a1 )
return (unsigned int)-*a2;
}
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, char *a2)
{
unsigned __int8 v4; // al
int v6; // esi
int v7; // ecx
unsigned __int8 v8; // dl

v4 = *a1;
if ( !*a1 )
return (unsigned int)-*a2;
while ( 1 )
{
++a1;
v7 = v4;
v8 = *a2++;
v6 = v8;
if ( v4 == v8 )
goto LABEL_7;
if ( (unsigned int)v4 - 65 > 0x19 )
{
if ( (unsigned int)v8 - 65 > 0x19 )
return (unsigned int)(v7 - v6);
LABEL_5:
v6 = v8 + 32;
goto LABEL_6;
}
v7 = v4 + 32;
if ( (unsigned int)v8 - 65 <= 0x19 )
goto LABEL_5;
LABEL_6:
if ( v6 != v7 )
return (unsigned int)(v7 - v6);
LABEL_7:
v4 = *a1;
if ( !*a1 )
return (unsigned int)-*a2;
}
}

canonical_original_code:
int cistrcmp(char *s1, char *s2)
{
 int c1; int c2;
 while(*s1){
  c1 = *(unsigned char *)s1++;
  c2 = *(unsigned char *)s2++;
  if(c1 == c2)
   continue;
  if(c1 >= 'A' && c1 <= 'Z')
   c1 -= 'A' - 'a';
  if(c2 >= 'A' && c2 <= 'Z')
   c2 -= 'A' - 'a';
  if(c1 != c2)
   return c1 - c2;
 }
 return -*s2;
}


decompiled_code:
int __fastcall p9dup(int a1, int a2)
{
int result; // eax

if ( a2 == -1 )
result = dup(a1);
else
result = dup2(a1, a2);
return result;
}

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

if ( a2 == -1 )
result = dup(a1);
else
result = dup2(a1, a2);
return result;
}

original_code:
int
p9dup(int old, int new)
{
 if(new == -1)
  return dup(old);
 return dup2(old, new);
}

variable_types: old int

variable_types: new int


Bprint

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

va_start(va, a2);
return Bvprint(a1, a2, va);
}

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

va_start(va, a2);
return Bvprint(a1, a2, va);
}

original_code:
int
Bprint(Biobuf *bp, char *fmt, ...)
{
 int n;
 va_list arg;
 __builtin_va_start(arg,fmt);
 n = Bvprint(bp, fmt, arg);
 __builtin_va_end(arg);
 return n;
}

canonical_original_code:
int Bprint(struct Biobuf *bp, char *fmt, ...)
{
 int n;
 __builtin_va_list arg;
 __builtin_va_start(arg,fmt);
 n = Bvprint(bp, fmt, arg);
 __builtin_va_end(arg);
 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]; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
p9main(argc, argv, envp);
exits("main");
return 99;
}

original_code:
int
main(int argc, char **argv)
{
 p9main(argc, argv);
 exits("main");
 return 99;
}

variable_types: argc int

variable_types:
argv
char **


dirfstat

decompiled_code:
__int64 __fastcall dirfstat(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
_BYTE v5[104]; // [rsp+0h] [rbp-118h] BYREF
__int64 v6; // [rsp+68h] [rbp-B0h] BYREF
struct stat64 buf; // [rsp+70h] [rbp-A8h] BYREF

v1 = 0LL;
if ( fstat64(a1, &buf) >= 0 )
{
snprint(v5, 100LL, "/dev/fd/%d", a1);
v2 = (int)p9dir(&buf, &buf, v5, 0LL, 0LL, 0LL);
v3 = mallocz(v2 + 120, 1LL);
v1 = v3;
if ( v3 )
{
v6 = v3 + 120;
p9dir(&buf, &buf, v5, v3, &v6, v3 + 120 + v2);
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
_BYTE v5[104]; // [rsp+0h] [rbp-118h] BYREF
__int64 v6; // [rsp+68h] [rbp-B0h] BYREF
struct stat64 buf; // [rsp+70h] [rbp-A8h] BYREF

v1 = 0LL;
if ( fstat64(a1, &buf) >= 0 )
{
snprint(v5, 100LL, "/dev/fd/%d", a1);
v2 = (int)p9dir(&buf, &buf, v5, 0LL, 0LL, 0LL);
v3 = mallocz(v2 + 120, 1LL);
v1 = v3;
if ( v3 )
{
v6 = v3 + 120;
p9dir(&buf, &buf, v5, v3, &v6, v3 + 120 + v2);
}
}
return v1;
}

original_code:
Dir*
dirfstat(int fd)
{
 struct stat st;
 int nstr;
 Dir *d;
 char *str, tmp[100];
 if(fstat(fd, &st) < 0)
  return ((void*)0);
 snprint(tmp, sizeof tmp, "/dev/fd/%d", fd);
 nstr = _p9dir(&st, &st, tmp, ((void*)0), ((void*)0), ((void*)0));
 d = mallocz(sizeof(Dir)+nstr, 1);
 if(d == ((void*)0))
  return ((void*)0);
 str = (char*)&d[1];
 _p9dir(&st, &st, tmp, d, &str, str+nstr);
 return d;
}

canonical_original_code:
struct Dir *dirfstat(int fd)
{
 struct stat st;
 int nstr;
 struct Dir *d;
 char *str; char tmp[100];
 if(fstat(fd, &st) < 0)
  return ((void *)0);
 snprint(tmp, sizeof tmp, "/dev/fd/%d", fd);
 nstr = _p9dir(&st, &st, tmp, ((void *)0), ((void *)0), ((void *)0));
 d = mallocz(sizeof(Dir)+nstr, 1);
 if(d == ((void *)0))
  return ((void *)0);
 str = (char *)&d[1];
 _p9dir(&st, &st, tmp, d, &str, str+nstr);
 return d;
}

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 *

variable_types:
tmp
char [100]

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


dirfwstat

original_code:
int
dirfwstat(int fd, Dir *dir)
{
 int ret;
 struct timeval tv[2];
 ret = 0;
 if(~dir->mode != 0){
  if(fchmod(fd, dir->mode) < 0)
   ret = -1;
 }
 if(~dir->mtime != 0){
  tv[0].tv_sec = dir->mtime;
  tv[0].tv_usec = 0;
  tv[1].tv_sec = dir->mtime;
  tv[1].tv_usec = 0;
  if(futimes(fd, tv) < 0)
   ret = -1;
 }
 if(~dir->length != 0){
  if(ftruncate(fd, dir->length) < 0)
   ret = -1;
 }
 return ret;
}

canonical_original_code:
int dirfwstat(int fd, struct Dir *dir)
{
 int ret;
 struct timeval tv[2];
 ret = 0;
 if(~dir->mode != 0){
  if(fchmod(fd, dir->mode) < 0)
   ret = -1;
 }
 if(~dir->mtime != 0){
  tv[0].tv_sec = dir->mtime;
  tv[0].tv_usec = 0;
  tv[1].tv_sec = dir->mtime;
  tv[1].tv_usec = 0;
  if(futimes(fd, tv) < 0)
   ret = -1;
 }
 if(~dir->length != 0){
  if(ftruncate(fd, dir->length) < 0)
   ret = -1;
 }
 return ret;
}

variable_types: fd int

variable_types: ret int

variable_types: struct timeval { long tv_sec; long tv_usec; } [2]

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


cistrncmp

decompiled_code:
__int64 __fastcall cistrncmp(unsigned __int8 *a1, char *a2, int a3)
{
unsigned __int8 v4; // al
int v5; // er9
__int64 result; // rax
int v7; // esi
int v8; // ecx
unsigned __int8 v9; // dl

v4 = *a1;
if ( !*a1 )
{
v5 = a3;
goto LABEL_7;
}
v5 = a3 - 1;
if ( a3 > 0 )
{
while ( 1 )
{
++a1;
v8 = v4;
v9 = *a2++;
v7 = v9;
if ( v4 != v9 )
break;
LABEL_13:
v4 = *a1;
if ( !*a1 )
goto LABEL_7;
if ( --v5 == -1 )
return 0LL;
}
if ( (unsigned int)v4 - 65 > 0x19 )
{
if ( (unsigned int)v9 - 65 > 0x19 )
return (unsigned int)(v8 - v7);
}
else
{
v8 = v4 + 32;
if ( (unsigned int)v9 - 65 > 0x19 )
{
LABEL_12:
if ( v7 != v8 )
return (unsigned int)(v8 - v7);
goto LABEL_13;
}
}
v7 = v9 + 32;
goto LABEL_12;
}
LABEL_7:
if ( v5 <= 0 )
result = 0LL;
else
result = (unsigned int)-*a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, char *a2, int a3)
{
unsigned __int8 v4; // al
int v5; // er9
__int64 result; // rax
int v7; // esi
int v8; // ecx
unsigned __int8 v9; // dl

v4 = *a1;
if ( !*a1 )
{
v5 = a3;
goto LABEL_7;
}
v5 = a3 - 1;
if ( a3 > 0 )
{
while ( 1 )
{
++a1;
v8 = v4;
v9 = *a2++;
v7 = v9;
if ( v4 != v9 )
break;
LABEL_13:
v4 = *a1;
if ( !*a1 )
goto LABEL_7;
if ( --v5 == -1 )
return 0LL;
}
if ( (unsigned int)v4 - 65 > 0x19 )
{
if ( (unsigned int)v9 - 65 > 0x19 )
return (unsigned int)(v8 - v7);
}
else
{
v8 = v4 + 32;
if ( (unsigned int)v9 - 65 > 0x19 )
{
LABEL_12:
if ( v7 != v8 )
return (unsigned int)(v8 - v7);
goto LABEL_13;
}
}
v7 = v9 + 32;
goto LABEL_12;
}
LABEL_7:
if ( v5 <= 0 )
result = 0LL;
else
result = (unsigned int)-*a2;
return result;
}

canonical_original_code:
int cistrncmp(char *s1, char *s2, int n)
{
 int c1; int c2;
 while(*s1 && n-- > 0){
  c1 = *(unsigned char *)s1++;
  c2 = *(unsigned char *)s2++;
  if(c1 == c2)
   continue;
  if(c1 >= 'A' && c1 <= 'Z')
   c1 -= 'A' - 'a';
  if(c2 >= 'A' && c2 <= 'Z')
   c2 -= 'A' - 'a';
  if(c1 != c2)
   return c1 - c2;
 }
 if(n <= 0)
  return 0;
 return -*s2;
}

variable_types: n int