decompiled_code:
void __fastcall p9rfork(unsigned int a1, struct sigaction *a2)
{
unsigned int v2; // ebx
struct sigaction *v3; // rdx
unsigned int v4; // ebp
__pid_t v5; // er12
int v6; // ebp
int v7; // ebp
__pid_t v8; // eax
unsigned int v9; // eax
struct sigaction v10; // [rsp+0h] [rbp-148h] BYREF
char *endptr; // [rsp+98h] [rbp-B0h] BYREF
char nptr[2]; // [rsp+A0h] [rbp-A8h] BYREF
char v13[130]; // [rsp+A2h] [rbp-A6h] BYREF
int v14; // [rsp+124h] [rbp-24h] BYREF
int fd; // [rsp+128h] [rbp-20h]
__WAIT_STATUS stat_loc; // [rsp+12Ch] [rbp-1Ch] BYREF

v2 = a1;
v3 = &v10;
memset(&v10, 0, sizeof(v10));
if ( (a1 & 0x34) == 20 )
{
a2 = (struct sigaction *)(a1 & 0xFFFFF7A0);
if ( (a1 & 0xFFFFF7A0) != 0 )
{
werrstr("unknown flags %08ux in rfork", a2);
return;
}
if ( (a1 & 0x40) != 0 )
{
sigaction(17, 0LL, &v10);
signal(17, (__sighandler_t)nop);
if ( (int)p9pipe(&v14) < 0 )
return;
v5 = fork();
if ( v5 == -1 )
return;
if ( v5 )
{
close(fd);
LODWORD(stat_loc.__uptr) = 0;
if ( wait4(v5, (__WAIT_STATUS)&stat_loc, 0, 0LL) < 0 )
{
werrstr("pipe dance - wait4 - %r");
close(v14);
return;
}
v6 = readn((unsigned int)v14, nptr, 127LL);
close(v14);
if ( ((__int64)stat_loc.__uptr & 0x7F) != 0 )
{
werrstr("pipe dance - !exited 0x%ux", LODWORD(stat_loc.__uptr));
return;
}
if ( v6 <= 0 || BYTE1(stat_loc.__uptr) )
{
if ( BYTE1(stat_loc.__uptr) )
{
werrstr("pipe dance - non-zero status 0x%ux", LODWORD(stat_loc.__uptr));
}
else if ( v6 < 0 )
{
werrstr("pipe dance - pipe read error - %r");
}
else if ( v6 )
{
werrstr("pipe dance - unknown failure");
}
else
{
werrstr("pipe dance - pipe read eof");
}
return;
}
nptr[v6] = 0;
if ( nptr[0] == 120 )
{
werrstr("%s", v13);
return;
}
v7 = strtol(nptr, &endptr, 0);
}
else
{
signal(17, p9rfork);
close(v14);
v8 = fork();
v7 = v8;
if ( v8 )
{
if ( v8 <= 0 )
fprint((unsigned int)fd, "x %r");
else
fprint((unsigned int)fd, "%d", (unsigned int)v8);
close(fd);
exit(0);
}
close(fd);
}
v2 = a1 & 0xFFFFFFA9;
a2 = &v10;
sigaction(17, &v10, 0LL);
}
else
{
v7 = fork();
if ( v7 == -1 )
return;
v2 = a1 & 0xFFFFFFE9;
}
if ( v7 )
return;
if ( (v2 & 0x800) != 0 && environ )
*environ = 0LL;
}
if ( (v2 & 0x10) != 0 )
{
werrstr("cannot use rfork for shared memory -- use libthread", a2, v3);
}
else
{
v4 = v2 & 0xFFFFFFFE;
if ( (v2 & 1) == 0 )
v4 = v2;
if ( (v4 & 8) != 0 )
{
v9 = getpid();
a2 = (struct sigaction *)v9;
setpgid(0, v9);
v4 &= 0xFFFFFFF7;
}
if ( (v4 & 0x40) != 0 )
{
werrstr("cannot use RFNOWAIT without RFPROC", a2, v3);
}
else if ( v4 )
{
werrstr("unknown flags %08ux in rfork", v4);
}
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1, struct sigaction *a2)
{
unsigned int v2; // ebx
struct sigaction *v3; // rdx
unsigned int v4; // ebp
__pid_t v5; // er12
int v6; // ebp
int v7; // ebp
__pid_t v8; // eax
unsigned int v9; // eax
struct sigaction v10; // [rsp+0h] [rbp-148h] BYREF
char *endptr; // [rsp+98h] [rbp-B0h] BYREF
char nptr[2]; // [rsp+A0h] [rbp-A8h] BYREF
char v13[130]; // [rsp+A2h] [rbp-A6h] BYREF
int v14; // [rsp+124h] [rbp-24h] BYREF
int fd; // [rsp+128h] [rbp-20h]
__WAIT_STATUS stat_loc; // [rsp+12Ch] [rbp-1Ch] BYREF

v2 = a1;
v3 = &v10;
memset(&v10, 0, sizeof(v10));
if ( (a1 & 0x34) == 20 )
{
a2 = (struct sigaction *)(a1 & 0xFFFFF7A0);
if ( (a1 & 0xFFFFF7A0) != 0 )
{
werrstr("unknown flags %08ux in rfork", a2);
return;
}
if ( (a1 & 0x40) != 0 )
{
sigaction(17, 0LL, &v10);
signal(17, (__sighandler_t)nop);
if ( (int)p9pipe(&v14) < 0 )
return;
v5 = fork();
if ( v5 == -1 )
return;
if ( v5 )
{
close(fd);
LODWORD(stat_loc.__uptr) = 0;
if ( wait4(v5, (__WAIT_STATUS)&stat_loc, 0, 0LL) < 0 )
{
werrstr("pipe dance - wait4 - %r");
close(v14);
return;
}
v6 = readn((unsigned int)v14, nptr, 127LL);
close(v14);
if ( ((__int64)stat_loc.__uptr & 0x7F) != 0 )
{
werrstr("pipe dance - !exited 0x%ux", LODWORD(stat_loc.__uptr));
return;
}
if ( v6 <= 0 || BYTE1(stat_loc.__uptr) )
{
if ( BYTE1(stat_loc.__uptr) )
{
werrstr("pipe dance - non-zero status 0x%ux", LODWORD(stat_loc.__uptr));
}
else if ( v6 < 0 )
{
werrstr("pipe dance - pipe read error - %r");
}
else if ( v6 )
{
werrstr("pipe dance - unknown failure");
}
else
{
werrstr("pipe dance - pipe read eof");
}
return;
}
nptr[v6] = 0;
if ( nptr[0] == 120 )
{
werrstr("%s", v13);
return;
}
v7 = strtol(nptr, &endptr, 0);
}
else
{
signal(17, p9rfork);
close(v14);
v8 = fork();
v7 = v8;
if ( v8 )
{
if ( v8 <= 0 )
fprint((unsigned int)fd, "x %r");
else
fprint((unsigned int)fd, "%d", (unsigned int)v8);
close(fd);
exit(0);
}
close(fd);
}
v2 = a1 & 0xFFFFFFA9;
a2 = &v10;
sigaction(17, &v10, 0LL);
}
else
{
v7 = fork();
if ( v7 == -1 )
return;
v2 = a1 & 0xFFFFFFE9;
}
if ( v7 )
return;
if ( (v2 & 0x800) != 0 && environ )
*environ = 0LL;
}
if ( (v2 & 0x10) != 0 )
{
werrstr("cannot use rfork for shared memory -- use libthread", a2, v3);
}
else
{
v4 = v2 & 0xFFFFFFFE;
if ( (v2 & 1) == 0 )
v4 = v2;
if ( (v4 & 8) != 0 )
{
v9 = getpid();
a2 = (struct sigaction *)v9;
setpgid(0, v9);
v4 &= 0xFFFFFFF7;
}
if ( (v4 & 0x40) != 0 )
{
werrstr("cannot use RFNOWAIT without RFPROC", a2, v3);
}
else if ( v4 )
{
werrstr("unknown flags %08ux in rfork", v4);
}
}
}

original_code:
int
p9rfork(int flags)
{
 int pid, status;
 int p[2];
 int n;
 char buf[128], *q;
 extern char **environ;
 struct sigaction oldchld;
 memset(&oldchld, 0, sizeof oldchld);
 if((flags&(RFPROC|RFFDG|RFMEM)) == (RFPROC|RFFDG)){
  flags &= ~(RFPROC|RFFDG|RFENVG);
  n = (flags & ~(RFNOTEG|RFNAMEG|RFNOWAIT|RFCENVG));
  if(n){
   werrstr("unknown flags %08ux in rfork", n);
   return -1;
  }
  if(flags&RFNOWAIT){
   sigaction(17, ((void*)0), &oldchld);
   signal(17, nop);
   if(p9pipe(p) < 0)
    return -1;
  }
  pid = fork();
  if(pid == -1)
   return -1;
  if(flags&RFNOWAIT){
   flags &= ~RFNOWAIT;
   if(pid){
    close(p[1]);
    status = 0;
    if(wait4(pid, &status, 0, 0) < 0){
     werrstr("pipe dance - wait4 - %r");
     close(p[0]);
     return -1;
    }
    n = readn(p[0], buf, sizeof buf-1);
    close(p[0]);
    if(!(((status) & 0x7f) == 0) || (((status) & 0xff00) >> 8)!=0 || n <= 0){
     if(!(((status) & 0x7f) == 0))
      werrstr("pipe dance - !exited 0x%ux", status);
     else if((((status) & 0xff00) >> 8) != 0)
      werrstr("pipe dance - non-zero status 0x%ux", status);
     else if(n < 0)
      werrstr("pipe dance - pipe read error - %r");
     else if(n == 0)
      werrstr("pipe dance - pipe read eof");
     else
      werrstr("pipe dance - unknown failure");
     return -1;
    }
    buf[n] = 0;
    if(buf[0] == 'x'){
     werrstr("%s", buf+2);
     return -1;
    }
    pid = strtol(buf, &q, 0);
   }else{
    signal(17, ((__sighandler_t) 1));
    close(p[0]);
    pid = fork();
    if(pid){
     if(pid > 0)
      fprint(p[1], "%d", pid);
     else
      fprint(p[1], "x %r");
     close(p[1]);
     _exit(0);
    }else{
     close(p[1]);
    }
   }
   sigaction(17, &oldchld, ((void*)0));
  }
  if(pid != 0)
   return pid;
  if(flags&RFCENVG)
   if(environ)
    *environ = ((void*)0);
 }
 if(flags&RFPROC){
  werrstr("cannot use rfork for shared memory -- use libthread");
  return -1;
 }
 if(flags&RFNAMEG){
  flags &= ~RFNAMEG;
 }
 if(flags&RFNOTEG){
  setpgid(0, getpid());
  flags &= ~RFNOTEG;
 }
 if(flags&RFNOWAIT){
  werrstr("cannot use RFNOWAIT without RFPROC");
  return -1;
 }
 if(flags){
  werrstr("unknown flags %08ux in rfork", flags);
  return -1;
 }
 return 0;
}

canonical_original_code:
int p9rfork(int flags)
{
 int pid; int status;
 int p[2];
 int n;
 char buf[128]; char *q;
 extern char **environ;
 struct sigaction oldchld;
 memset(&oldchld, 0, sizeof oldchld);
 if((flags&(RFPROC|RFFDG|RFMEM)) == (RFPROC|RFFDG)){
  flags &= ~(RFPROC|RFFDG|RFENVG);
  n = (flags & ~(RFNOTEG|RFNAMEG|RFNOWAIT|RFCENVG));
  if(n){
   werrstr("unknown flags %08ux in rfork", n);
   return -1;
  }
  if(flags&RFNOWAIT){
   sigaction(17, ((void *)0), &oldchld);
   signal(17, nop);
   if(p9pipe(p) < 0)
    return -1;
  }
  pid = fork();
  if(pid == -1)
   return -1;
  if(flags&RFNOWAIT){
   flags &= ~RFNOWAIT;
   if(pid){
    close(p[1]);
    status = 0;
    if(wait4(pid, &status, 0, 0) < 0){
     werrstr("pipe dance - wait4 - %r");
     close(p[0]);
     return -1;
    }
    n = readn(p[0], buf, sizeof buf-1);
    close(p[0]);
    if(!(((status) & 0x7f) == 0) || (((status) & 0xff00) >> 8)!=0 || n <= 0){
     if(!(((status) & 0x7f) == 0))
      werrstr("pipe dance - !exited 0x%ux", status);
     else if((((status) & 0xff00) >> 8) != 0)
      werrstr("pipe dance - non-zero status 0x%ux", status);
     else if(n < 0)
      werrstr("pipe dance - pipe read error - %r");
     else if(n == 0)
      werrstr("pipe dance - pipe read eof");
     else
      werrstr("pipe dance - unknown failure");
     return -1;
    }
    buf[n] = 0;
    if(buf[0] == 'x'){
     werrstr("%s", buf+2);
     return -1;
    }
    pid = strtol(buf, &q, 0);
   }else{
    signal(17, ((void (*)(int)) 1));
    close(p[0]);
    pid = fork();
    if(pid){
     if(pid > 0)
      fprint(p[1], "%d", pid);
     else
      fprint(p[1], "x %r");
     close(p[1]);
     _exit(0);
    }else{
     close(p[1]);
    }
   }
   sigaction(17, &oldchld, ((void *)0));
  }
  if(pid != 0)
   return pid;
  if(flags&RFCENVG)
   if(environ)
    *environ = ((void *)0);
 }
 if(flags&RFPROC){
  werrstr("cannot use rfork for shared memory -- use libthread");
  return -1;
 }
 if(flags&RFNAMEG){
  flags &= ~RFNAMEG;
 }
 if(flags&RFNOTEG){
  setpgid(0, getpid());
  flags &= ~RFNOTEG;
 }
 if(flags&RFNOWAIT){
  werrstr("cannot use RFNOWAIT without RFPROC");
  return -1;
 }
 if(flags){
  werrstr("unknown flags %08ux in rfork", flags);
  return -1;
 }
 return 0;
}

variable_types: flags int

variable_types: pid int

variable_types: status int

variable_types:
p
int [2]

variable_types:
buf
char [128]

variable_types:
q
char *

variable_types:
environ
char **

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


nop

decompiled_code:
void nop()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void
nop(int x)
{
 ((void)(x));
}

canonical_original_code:
static void nop(int x)
{
 ((void)(x));
}

variable_types: x int

return_type: void


decompiled_code:
char *__fastcall p9getwd(char *a1, int a2)
{
return getcwd(a1, a2);
}

canonical_decompiled_code:
char *__fastcall func0(char *a1, int a2)
{
return getcwd(a1, a2);
}

original_code:
char*
p9getwd(char *s, int ns)
{
 return getcwd(s, ns);
}

canonical_original_code:
char *p9getwd(char *s, int ns)
{
 return getcwd(s, ns);
}

variable_types:
s
char *

variable_types: ns int

return_type: char *


refadd

original_code:
static long
refadd(Ref *r, long a)
{
 long ref;
 lock(&r->lock);
 r->ref += a;
 ref = r->ref;
 unlock(&r->lock);
 return ref;
}

canonical_original_code:
static long refadd(struct Ref *r, long a)
{
 long ref;
 lock(&r->lock);
 r->ref += a;
 ref = r->ref;
 unlock(&r->lock);
 return ref;
}

variable_types: struct Ref { struct Lock { int held; } lock; long ref; } *

variable_types: a long

variable_types: ref long

return_type: long

user_defined_types: struct Ref { struct Lock lock; long ref; }


incref

decompiled_code:
__int64 __fastcall incref(__int64 a1)
{
return refadd(a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return func0(a1, 1LL);
}

original_code:
long
incref(Ref *r)
{
 return refadd(r, 1);
}

canonical_original_code:
long incref(struct Ref *r)
{
 return refadd(r, 1);
}


decref

decompiled_code:
__int64 __fastcall decref(__int64 a1)
{
return refadd(a1, -1LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return func0(a1, -1LL);
}

original_code:
long
decref(Ref *r)
{
 return refadd(r, -1);
}

canonical_original_code:
long decref(struct Ref *r)
{
 return refadd(r, -1);
}


ctimedysize

original_code:
static
int
ctimedysize(int y)
{
 if(y%4 == 0 && (y%100 != 0 || y%400 == 0))
  return 366;
 return 365;
}

variable_types: y int

return_type: int


original_code:
Tm*
p9gmtime(long tim)
{
 int d0, d1;
 long hms, day;
 static Tm xtime;
 hms = tim % 86400L;
 day = tim / 86400L;
 if(hms < 0) {
  hms += 86400L;
  day -= 1;
 }
 xtime.sec = hms % 60;
 d1 = hms / 60;
 xtime.min = d1 % 60;
 d1 /= 60;
 xtime.hour = d1;
 xtime.wday = (day + 7340036L) % 7;
 if(day >= 0)
  for(d1 = 1970; day >= ctimedysize(d1); d1++)
   day -= ctimedysize(d1);
 else
  for (d1 = 1970; day < 0; d1--)
   day += ctimedysize(d1-1);
 xtime.year = d1-1900;
 xtime.yday = d0 = day;
 if(ctimedysize(d1) == 366)
  dmsize[1] = 29;
 for(d1 = 0; d0 >= dmsize[d1]; d1++)
  d0 -= dmsize[d1];
 dmsize[1] = 28;
 xtime.mday = d0 + 1;
 xtime.mon = d1;
 strcpy(xtime.zone, "GMT");
 return &xtime;
}

canonical_original_code:
struct Tm *p9gmtime(long tim)
{
 int d0; int d1;
 long hms; long day;
 static struct Tm xtime;
 hms = tim % 86400L;
 day = tim / 86400L;
 if(hms < 0) {
  hms += 86400L;
  day -= 1;
 }
 xtime.sec = hms % 60;
 d1 = hms / 60;
 xtime.min = d1 % 60;
 d1 /= 60;
 xtime.hour = d1;
 xtime.wday = (day + 7340036L) % 7;
 if(day >= 0)
  for(d1 = 1970; day >= ctimedysize(d1); d1++)
   day -= ctimedysize(d1);
 else
  for (d1 = 1970; day < 0; d1--)
   day += ctimedysize(d1-1);
 xtime.year = d1-1900;
 xtime.yday = d0 = day;
 if(ctimedysize(d1) == 366)
  dmsize[1] = 29;
 for(d1 = 0; d0 >= dmsize[d1]; d1++)
  d0 -= dmsize[d1];
 dmsize[1] = 28;
 xtime.mday = d0 + 1;
 xtime.mon = d1;
 strcpy(xtime.zone, "GMT");
 return &xtime;
}

variable_types: tim long

variable_types: hms long

variable_types: day long

return_type: struct Tm { int sec; int min; int hour; int mday; int mon; int year; int wday; int yday; char zone[4]; int tzoff; } *


decompiled_code:
int *__fastcall p9localtime(__int64 a1)
{
int *v1; // rbx
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
int v4; // [rsp+8h] [rbp-20h]
char *src; // [rsp+10h] [rbp-18h]

if ( (unsigned int)p9zonelookuptinfo(&v3, a1) == -1 )
return p9gmtime(a1);
v1 = p9gmtime(a1 + v4);
strncpy((char *)v1 + 32, src, 3uLL);
*((_BYTE *)v1 + 35) = 0;
v1[9] = v4;
return v1;
}

canonical_decompiled_code:
int *__fastcall func3(__int64 a1)
{
int *v1; // rbx
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
int v4; // [rsp+8h] [rbp-20h]
char *src; // [rsp+10h] [rbp-18h]

if ( (unsigned int)p9zonelookuptinfo(&v3, a1) == -1 )
return func2(a1);
v1 = func2(a1 + v4);
strncpy((char *)v1 + 32, src, 3uLL);
*((_BYTE *)v1 + 35) = 0;
v1[9] = v4;
return v1;
}

original_code:
Tm*
p9localtime(long tim)
{
 Tinfo ti;
 Tm *ct;
 if (_p9zonelookuptinfo(&ti, tim)!=-1) {
  ct = p9gmtime(tim+ti.tzoff);
  strncpy(ct->zone, ti.zone, sizeof ct->zone);
  ct->zone[sizeof ct->zone-1] = 0;
  ct->tzoff = ti.tzoff;
  return ct;
 }
 return p9gmtime(tim);
}

canonical_original_code:
struct Tm *p9localtime(long tim)
{
 struct Tinfo ti;
 struct Tm *ct;
 if (_p9zonelookuptinfo(&ti, tim)!=-1) {
  ct = p9gmtime(tim+ti.tzoff);
  strncpy(ct->zone, ti.zone, sizeof ct->zone);
  ct->zone[sizeof ct->zone-1] = 0;
  ct->tzoff = ti.tzoff;
  return ct;
 }
 return p9gmtime(tim);
}

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

variable_types: struct Tm { int sec; int min; int hour; int mday; int mon; int year; int wday; int yday; char zone[4]; int tzoff; } *


mallocz

decompiled_code:
void *__fastcall mallocz(size_t n, int a2)
{
void *v2; // rax
void *v3; // rbx

v2 = (void *)p9malloc();
v3 = v2;
if ( a2 && v2 )
memset(v2, 0, n);
return v3;
}

canonical_decompiled_code:
void *__fastcall func0(size_t n, int a2)
{
void *v2; // rax
void *v3; // rbx

v2 = (void *)p9malloc();
v3 = v2;
if ( a2 && v2 )
memset(v2, 0, n);
return v3;
}

original_code:
void*
mallocz(unsigned long n, int clr)
{
 void *v;
 v = p9malloc(n);
 if(clr && v)
  memset(v, 0, n);
 return v;
}

canonical_original_code:
void *mallocz(unsigned long n, int clr)
{
 void *v;
 v = p9malloc(n);
 if(clr && v)
  memset(v, 0, n);
 return v;
}

variable_types:
n
unsigned long

variable_types: clr int

variable_types:
v
void *

return_type: void *


dirwstat

decompiled_code:
__int64 __fastcall dirwstat(char *file, _QWORD *a2)
{
__int64 v3; // rsi
unsigned int v4; // er12
__time_t v5; // rax
__off64_t v6; // rsi
struct utimbuf v8; // [rsp+0h] [rbp-28h] BYREF

v3 = a2[4];
v4 = 0;
if ( v3 != -1 )
v4 = chmod(file, v3) >> 31;
v5 = a2[6];
if ( v5 != -1 )
{
v8.actime = a2[6];
v8.modtime = v5;
if ( utime(file, &v8) < 0 )
v4 = -1;
}
v6 = a2[7];
if ( v6 != -1 && truncate64(file, v6) < 0 )
v4 = -1;
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *file, _QWORD *a2)
{
__int64 v3; // rsi
unsigned int v4; // er12
__time_t v5; // rax
__off64_t v6; // rsi
struct utimbuf v8; // [rsp+0h] [rbp-28h] BYREF

v3 = a2[4];
v4 = 0;
if ( v3 != -1 )
v4 = chmod(file, v3) >> 31;
v5 = a2[6];
if ( v5 != -1 )
{
v8.actime = a2[6];
v8.modtime = v5;
if ( utime(file, &v8) < 0 )
v4 = -1;
}
v6 = a2[7];
if ( v6 != -1 && truncate64(file, v6) < 0 )
v4 = -1;
return v4;
}

original_code:
int
dirwstat(char *file, Dir *dir)
{
 int ret;
 struct utimbuf ub;
 ret = 0;
 if(~dir->mode != 0){
  if(chmod(file, dir->mode) < 0)
   ret = -1;
 }
 if(~dir->mtime != 0){
  ub.actime = dir->mtime;
  ub.modtime = dir->mtime;
  if(utime(file, &ub) < 0)
   ret = -1;
 }
 if(~dir->length != 0){
  if(truncate(file, dir->length) < 0)
   ret = -1;
 }
 return ret;
}

canonical_original_code:
int dirwstat(char *file, struct Dir *dir)
{
 int ret;
 struct utimbuf ub;
 ret = 0;
 if(~dir->mode != 0){
  if(chmod(file, dir->mode) < 0)
   ret = -1;
 }
 if(~dir->mtime != 0){
  ub.actime = dir->mtime;
  ub.modtime = dir->mtime;
  if(utime(file, &ub) < 0)
   ret = -1;
 }
 if(~dir->length != 0){
  if(truncate(file, dir->length) < 0)
   ret = -1;
 }
 return ret;
}

variable_types:
file
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: ret int

variable_types: struct utimbuf { long actime; long modtime; }

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


smprint

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

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

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

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

original_code:
char*
smprint(char *fmt, ...)
{
 va_list args;
 char *p;
 __builtin_va_start(args,fmt);
 p = vsmprint(fmt, args);
 __builtin_va_end(args);
 return p;
}

canonical_original_code:
char *smprint(char *fmt, ...)
{
 __builtin_va_list args;
 char *p;
 __builtin_va_start(args,fmt);
 p = vsmprint(fmt, args);
 __builtin_va_end(args);
 return p;
}

variable_types:
fmt
char *

variable_types:
p
char *


decompiled_code:
const char *get9root()
{
const char *result; // rax

result = (const char *)s_0;
if ( !s_0 )
{
result = (const char *)p9getenv("PLAN9");
if ( result )
{
s_0 = (__int64)result;
}
else
{
s_0 = (__int64)"/usr/local/plan9";
result = "/usr/local/plan9";
}
}
return result;
}

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

result = (const char *)s_0;
if ( !s_0 )
{
result = (const char *)p9getenv("PLAN9");
if ( result )
{
s_0 = (__int64)result;
}
else
{
s_0 = (__int64)"/usr/local/plan9";
result = "/usr/local/plan9";
}
}
return result;
}

original_code:
char*
get9root(void)
{
 static char *s;
 if(s)
  return s;
 if((s = p9getenv("PLAN9")) != 0)
  return s;
 s = "/usr/local/plan9";
 return s;
}

canonical_original_code:
char *get9root()
{
 static char *s;
 if(s)
  return s;
 if((s = p9getenv("PLAN9")) != 0)
  return s;
 s = "/usr/local/plan9";
 return s;
}

variable_types:
s
char *


isany

decompiled_code:
_BOOL8 __fastcall isany(__int64 a1)
{
if ( *(_WORD *)a1 == 2 )
return *(_DWORD *)(a1 + 4) == 0;
if ( *(_WORD *)a1 == 10 )
return memcmp((const void *)(a1 + 8), &in6addr_any, 0x10uLL) == 0;
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
if ( *(_WORD *)a1 == 2 )
return *(_DWORD *)(a1 + 4) == 0;
if ( *(_WORD *)a1 == 10 )
return memcmp((const void *)(a1 + 8), &in6addr_any, 0x10uLL) == 0;
return 0LL;
}

original_code:
static int
isany(struct sockaddr_storage *ss)
{
 switch(ss->ss_family){
 case 2:
  return (((struct sockaddr_in*)ss)->sin_addr.s_addr == ((in_addr_t) 0x00000000));
 case 10:
  return (memcmp(((struct sockaddr_in6*)ss)->sin6_addr.__in6_u.__u6_addr8,
   in6addr_any.__in6_u.__u6_addr8, sizeof (struct in6_addr)) == 0);
 }
 return 0;
}

canonical_original_code:
static int isany(struct sockaddr_storage *ss)
{
 switch(ss->ss_family){
 case 2:
  return (((struct sockaddr_in *)ss)->sin_addr.s_addr == ((unsigned int) 0x00000000));
 case 10:
  return (memcmp(((struct sockaddr_in6 *)ss)->sin6_addr.__in6_u.__u6_addr8,
   in6addr_any.__in6_u.__u6_addr8, sizeof (struct in6_addr)) == 0);
 }
 return 0;
}

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

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

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


decompiled_code:
__int64 __fastcall p9dial(const char *a1, const char *a2, unsigned __int64 a3, unsigned __int64 a4)
{
__int64 v6; // rax
__int64 v7; // rbp
const char *v8; // r14
_BOOL4 v9; // ebx
bool v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
__int64 v14; // rcx
const char *v15; // rsi
int v16; // ebx
socklen_t v17; // eax
int v18; // er14
__int64 v19; // rax
__int64 v20; // rbp
socklen_t v21; // eax
socklen_t v23; // eax
int v24; // [rsp+Ch] [rbp-14Ch] BYREF
struct sockaddr v25; // [rsp+10h] [rbp-148h] BYREF
struct sockaddr addr; // [rsp+90h] [rbp-C8h] BYREF
int optval; // [rsp+114h] [rbp-44h] BYREF
socklen_t optlen; // [rsp+118h] [rbp-40h] BYREF
int v29; // [rsp+11Ch] [rbp-3Ch] BYREF
__int64 v30; // [rsp+120h] [rbp-38h] BYREF
const char *v31[6]; // [rsp+128h] [rbp-30h] BYREF

if ( __PAIR128__(a4, a3) != 0 )
{
werrstr("cannot handle extra arguments in dial");
return (unsigned int)-1;
}
v6 = ((__int64 (*)(void))p9strdup)();
v7 = v6;
if ( !v6 )
return (unsigned int)-1;
if ( (int)p9dialparse(v6, v31, &v30, &addr, &v29) < 0 )
{
p9free(v7);
return (unsigned int)-1;
}
v8 = v31[0];
v12 = strcmp(v31[0], "unix") == 0;
v9 = !v12;
if ( !v12 && isany((__int64)&addr) )
{
werrstr("invalid dial address 0.0.0.0 (aka *)");
p9free(v7);
return (unsigned int)-1;
}
v10 = strcmp(v8, "tcp") != 0;
v11 = 0;
v12 = !v10;
if ( v10 )
{
v13 = "udp";
v14 = 4LL;
v15 = v8;
do
{
if ( !v14 )
break;
v11 = *v15 < (unsigned int)*v13;
v12 = *v15++ == *v13++;
--v14;
}
while ( v12 );
if ( (!v11 && !v12) != v11 )
{
if ( v9 )
{
werrstr("can only handle tcp, udp, and unix: not %s", v8);
p9free(v7);
v16 = -1;
}
else if ( a2 )
{
werrstr("local address not supported on unix network", v15);
p9free(v7);
v16 = -1;
}
else
{
v16 = p9open(v30, 2LL);
if ( v16 < 0 )
{
p9free(v7);
v16 = socket(addr.sa_family, 1, 0);
if ( v16 < 0 )
{
werrstr("socket: %r");
v16 = -1;
}
else
{
v17 = addrlen((__int16 *)&addr);
if ( connect(v16, &addr, v17) < 0 )
{
werrstr("connect %s: %r", addr.sa_data);
close(v16);
v16 = -1;
}
}
}
}
return (unsigned int)v16;
}
v18 = 2;
}
else
{
v18 = 1;
}
p9free(v7);
v16 = socket(addr.sa_family, v18, 0);
if ( v16 < 0 )
return (unsigned int)-1;
if ( a2 )
{
v19 = p9strdup(a2);
v20 = v19;
if ( !v19 )
{
close(v16);
return (unsigned int)-1;
}
if ( (int)p9dialparse(v19, v31, &v30, &addr, &v29) >= 0 )
{
if ( v30 )
{
werrstr("bad local address %s for dial %s", a2, a1);
}
else
{
optlen = 4;
if ( v29 && getsockopt(v16, 1, 3, &optval, &optlen) >= 0 && optval == 1 )
setsockopt(v16, 1, 2, &optval, 4u);
v21 = addrlen((__int16 *)&v25);
if ( bind(v16, &v25, v21) >= 0 )
{
p9free(v20);
goto LABEL_31;
}
}
}
p9free(v20);
close(v16);
return (unsigned int)-1;
}
LABEL_31:
optval = 1;
setsockopt(v16, 1, 6, &optval, 4u);
if ( isany((__int64)&addr) || (v23 = addrlen((__int16 *)&addr), connect(v16, &addr, v23) >= 0) )
{
if ( v18 == 1 )
{
v24 = 1;
setsockopt(v16, 6, 1, &v24, 4u);
}
}
else
{
close(v16);
v16 = -1;
}
return (unsigned int)v16;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2, unsigned __int64 a3, unsigned __int64 a4)
{
__int64 v6; // rax
__int64 v7; // rbp
const char *v8; // r14
_BOOL4 v9; // ebx
bool v10; // al
bool v11; // cf
bool v12; // zf
const char *v13; // rdi
__int64 v14; // rcx
const char *v15; // rsi
int v16; // ebx
socklen_t v17; // eax
int v18; // er14
__int64 v19; // rax
__int64 v20; // rbp
socklen_t v21; // eax
socklen_t v23; // eax
int v24; // [rsp+Ch] [rbp-14Ch] BYREF
struct sockaddr v25; // [rsp+10h] [rbp-148h] BYREF
struct sockaddr addr; // [rsp+90h] [rbp-C8h] BYREF
int optval; // [rsp+114h] [rbp-44h] BYREF
socklen_t optlen; // [rsp+118h] [rbp-40h] BYREF
int v29; // [rsp+11Ch] [rbp-3Ch] BYREF
__int64 v30; // [rsp+120h] [rbp-38h] BYREF
const char *v31[6]; // [rsp+128h] [rbp-30h] BYREF

if ( __PAIR128__(a4, a3) != 0 )
{
werrstr("cannot handle extra arguments in dial");
return (unsigned int)-1;
}
v6 = ((__int64 (*)(void))p9strdup)();
v7 = v6;
if ( !v6 )
return (unsigned int)-1;
if ( (int)p9dialparse(v6, v31, &v30, &addr, &v29) < 0 )
{
p9free(v7);
return (unsigned int)-1;
}
v8 = v31[0];
v12 = strcmp(v31[0], "unix") == 0;
v9 = !v12;
if ( !v12 && func1((__int64)&addr) )
{
werrstr("invalid dial address 0.0.0.0 (aka *)");
p9free(v7);
return (unsigned int)-1;
}
v10 = strcmp(v8, "tcp") != 0;
v11 = 0;
v12 = !v10;
if ( v10 )
{
v13 = "udp";
v14 = 4LL;
v15 = v8;
do
{
if ( !v14 )
break;
v11 = *v15 < (unsigned int)*v13;
v12 = *v15++ == *v13++;
--v14;
}
while ( v12 );
if ( (!v11 && !v12) != v11 )
{
if ( v9 )
{
werrstr("can only handle tcp, udp, and unix: not %s", v8);
p9free(v7);
v16 = -1;
}
else if ( a2 )
{
werrstr("local address not supported on unix network", v15);
p9free(v7);
v16 = -1;
}
else
{
v16 = p9open(v30, 2LL);
if ( v16 < 0 )
{
p9free(v7);
v16 = socket(addr.sa_family, 1, 0);
if ( v16 < 0 )
{
werrstr("socket: %r");
v16 = -1;
}
else
{
v17 = func0((__int16 *)&addr);
if ( connect(v16, &addr, v17) < 0 )
{
werrstr("connect %s: %r", addr.sa_data);
close(v16);
v16 = -1;
}
}
}
}
return (unsigned int)v16;
}
v18 = 2;
}
else
{
v18 = 1;
}
p9free(v7);
v16 = socket(addr.sa_family, v18, 0);
if ( v16 < 0 )
return (unsigned int)-1;
if ( a2 )
{
v19 = p9strdup(a2);
v20 = v19;
if ( !v19 )
{
close(v16);
return (unsigned int)-1;
}
if ( (int)p9dialparse(v19, v31, &v30, &addr, &v29) >= 0 )
{
if ( v30 )
{
werrstr("bad local address %s for dial %s", a2, a1);
}
else
{
optlen = 4;
if ( v29 && getsockopt(v16, 1, 3, &optval, &optlen) >= 0 && optval == 1 )
setsockopt(v16, 1, 2, &optval, 4u);
v21 = func0((__int16 *)&v25);
if ( bind(v16, &v25, v21) >= 0 )
{
p9free(v20);
goto LABEL_31;
}
}
}
p9free(v20);
close(v16);
return (unsigned int)-1;
}
LABEL_31:
optval = 1;
setsockopt(v16, 1, 6, &optval, 4u);
if ( func1((__int64)&addr) || (v23 = func0((__int16 *)&addr), connect(v16, &addr, v23) >= 0) )
{
if ( v18 == 1 )
{
v24 = 1;
setsockopt(v16, 6, 1, &v24, 4u);
}
}
else
{
close(v16);
v16 = -1;
}
return (unsigned int)v16;
}

original_code:
int
p9dial(char *addr, char *local, char *dummy2, int *dummy3)
{
 char *buf;
 char *net, *xunix;
 int port;
 int proto;
 socklen_t sn;
 int n;
 struct sockaddr_storage ss, ssl;
 int s;
 if(dummy2 || dummy3){
  werrstr("cannot handle extra arguments in dial");
  return -1;
 }
 buf = p9strdup(addr);
 if(buf == ((void*)0))
  return -1;
 if(p9dialparse(buf, &net, &xunix, &ss, &port) < 0){
  p9free(buf);
  return -1;
 }
 if(strcmp(net, "unix") != 0 && isany(&ss)){
  werrstr("invalid dial address 0.0.0.0 (aka *)");
  p9free(buf);
  return -1;
 }
 if(strcmp(net, "tcp") == 0)
  proto = SOCK_STREAM;
 else if(strcmp(net, "udp") == 0)
  proto = SOCK_DGRAM;
 else if(strcmp(net, "unix") == 0)
  goto Unix;
 else{
  werrstr("can only handle tcp, udp, and unix: not %s", net);
  p9free(buf);
  return -1;
 }
 p9free(buf);
 if((s = socket(ss.ss_family, proto, 0)) < 0)
  return -1;
 if(local){
  buf = p9strdup(local);
  if(buf == ((void*)0)){
   close(s);
   return -1;
  }
  if(p9dialparse(buf, &net, &xunix, &ss, &port) < 0){
  badlocal:
   p9free(buf);
   close(s);
   return -1;
  }
  if(xunix){
   werrstr("bad local address %s for dial %s", local, addr);
   goto badlocal;
  }
  sn = sizeof n;
  if(port && getsockopt(s, 1, 3, (void*)&n, &sn) >= 0
  && n == SOCK_STREAM){
   n = 1;
   setsockopt(s, 1, 2, (char*)&n, sizeof n);
  }
  if(bind(s, (struct sockaddr*)&ssl, addrlen(&ssl)) < 0)
   goto badlocal;
  p9free(buf);
 }
 n = 1;
 setsockopt(s, 1, 6, &n, sizeof n);
 if(!isany(&ss)){
  if(connect(s, (struct sockaddr*)&ss, addrlen(&ss)) < 0){
   close(s);
   return -1;
  }
 }
 if(proto == SOCK_STREAM){
  int one = 1;
  setsockopt(s, IPPROTO_TCP, 1, (char*)&one, sizeof one);
 }
 return s;
Unix:
 if(local){
  werrstr("local address not supported on unix network");
  p9free(buf);
  return -1;
 }
 if((s = p9open(xunix, 2)) >= 0)
  return s;
 p9free(buf);
 if((s = socket(ss.ss_family, SOCK_STREAM, 0)) < 0){
  werrstr("socket: %r");
  return -1;
 }
 if(connect(s, (struct sockaddr*)&ss, addrlen(&ss)) < 0){
  werrstr("connect %s: %r", ((struct sockaddr_un*)&ss)->sun_path);
  close(s);
  return -1;
 }
 return s;
}

canonical_original_code:
int p9dial(char *addr, char *local, char *dummy2, int *dummy3)
{
 char *buf;
 char *net; char *xunix;
 int port;
 int proto;
 unsigned int sn;
 int n;
 struct sockaddr_storage ss; struct sockaddr_storage ssl;
 int s;
 if(dummy2 || dummy3){
  werrstr("cannot handle extra arguments in dial");
  return -1;
 }
 buf = p9strdup(addr);
 if(buf == ((void *)0))
  return -1;
 if(p9dialparse(buf, &net, &xunix, &ss, &port) < 0){
  p9free(buf);
  return -1;
 }
 if(strcmp(net, "unix") != 0 && isany(&ss)){
  werrstr("invalid dial address 0.0.0.0 (aka *)");
  p9free(buf);
  return -1;
 }
 if(strcmp(net, "tcp") == 0)
  proto = SOCK_STREAM;
 else if(strcmp(net, "udp") == 0)
  proto = SOCK_DGRAM;
 else if(strcmp(net, "unix") == 0)
  goto Unix;
 else{
  werrstr("can only handle tcp, udp, and unix: not %s", net);
  p9free(buf);
  return -1;
 }
 p9free(buf);
 if((s = socket(ss.ss_family, proto, 0)) < 0)
  return -1;
 if(local){
  buf = p9strdup(local);
  if(buf == ((void *)0)){
   close(s);
   return -1;
  }
  if(p9dialparse(buf, &net, &xunix, &ss, &port) < 0){
  badlocal:
   p9free(buf);
   close(s);
   return -1;
  }
  if(xunix){
   werrstr("bad local address %s for dial %s", local, addr);
   goto badlocal;
  }
  sn = sizeof n;
  if(port && getsockopt(s, 1, 3, (void *)&n, &sn) >= 0
  && n == SOCK_STREAM){
   n = 1;
   setsockopt(s, 1, 2, (char *)&n, sizeof n);
  }
  if(bind(s, (struct sockaddr *)&ssl, addrlen(&ssl)) < 0)
   goto badlocal;
  p9free(buf);
 }
 n = 1;
 setsockopt(s, 1, 6, &n, sizeof n);
 if(!isany(&ss)){
  if(connect(s, (struct sockaddr *)&ss, addrlen(&ss)) < 0){
   close(s);
   return -1;
  }
 }
 if(proto == SOCK_STREAM){
  int one = 1;
  setsockopt(s, IPPROTO_TCP, 1, (char *)&one, sizeof one);
 }
 return s;
Unix:
 if(local){
  werrstr("local address not supported on unix network");
  p9free(buf);
  return -1;
 }
 if((s = p9open(xunix, 2)) >= 0)
  return s;
 p9free(buf);
 if((s = socket(ss.ss_family, SOCK_STREAM, 0)) < 0){
  werrstr("socket: %r");
  return -1;
 }
 if(connect(s, (struct sockaddr *)&ss, addrlen(&ss)) < 0){
  werrstr("connect %s: %r", ((struct sockaddr_un *)&ss)->sun_path);
  close(s);
  return -1;
 }
 return s;
}

variable_types:
addr
char *

variable_types:
local
char *

variable_types:
buf
char *

variable_types:
net
char *

variable_types:
xunix
char *

variable_types: port int

variable_types: proto int

variable_types:
sn
unsigned int

variable_types: n int

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

variable_types: s int

variable_types: one int

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

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


chartorune

original_code:
int
chartorune(Rune *rune, char *str)
{
 int c, c1, c2, c3;
 long l;
 c = *(_utfuchar*)str;
 if(c < Tx) {
  *rune = c;
  return 1;
 }
 c1 = *(_utfuchar*)(str+1) ^ Tx;
 if(c1 & Testx)
  goto bad;
 if(c < T3) {
  if(c < T2)
   goto bad;
  l = ((c << Bitx) | c1) & Rune2;
  if(l <= Rune1)
   goto bad;
  *rune = l;
  return 2;
 }
 c2 = *(_utfuchar*)(str+2) ^ Tx;
 if(c2 & Testx)
  goto bad;
 if(c < T4) {
  l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
  if(l <= Rune2)
   goto bad;
  *rune = l;
  return 3;
 }
 if(UTFmax >= 4) {
  c3 = *(_utfuchar*)(str+3) ^ Tx;
  if(c3 & Testx)
   goto bad;
  if(c < T5) {
   l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
   if(l <= Rune3)
    goto bad;
   if(l > Runemax)
    goto bad;
   *rune = l;
   return 4;
  }
 }
bad:
 *rune = Bad;
 return 1;
}

canonical_original_code:
int chartorune(unsigned int *rune, char *str)
{
 int c; int c1; int c2; int c3;
 long l;
 c = *(unsigned char *)str;
 if(c < Tx) {
  *rune = c;
  return 1;
 }
 c1 = *(unsigned char *)(str+1) ^ Tx;
 if(c1 & Testx)
  goto bad;
 if(c < T3) {
  if(c < T2)
   goto bad;
  l = ((c << Bitx) | c1) & Rune2;
  if(l <= Rune1)
   goto bad;
  *rune = l;
  return 2;
 }
 c2 = *(unsigned char *)(str+2) ^ Tx;
 if(c2 & Testx)
  goto bad;
 if(c < T4) {
  l = ((((c << Bitx) | c1) << Bitx) | c2) & Rune3;
  if(l <= Rune2)
   goto bad;
  *rune = l;
  return 3;
 }
 if(UTFmax >= 4) {
  c3 = *(unsigned char *)(str+3) ^ Tx;
  if(c3 & Testx)
   goto bad;
  if(c < T5) {
   l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
   if(l <= Rune3)
    goto bad;
   if(l > Runemax)
    goto bad;
   *rune = l;
   return 4;
  }
 }
bad:
 *rune = Bad;
 return 1;
}

variable_types:
rune
unsigned int *

variable_types:
str
char *

variable_types: c int

variable_types: l long


runetochar

original_code:
int
runetochar(char *str, Rune *rune)
{
 long c;
 c = *rune;
 if(c <= Rune1) {
  str[0] = c;
  return 1;
 }
 if(c <= Rune2) {
  str[0] = T2 | (c >> 1*Bitx);
  str[1] = Tx | (c & Maskx);
  return 2;
 }
 if(c > Runemax)
  c = Runeerror;
 if(c <= Rune3) {
  str[0] = T3 | (c >> 2*Bitx);
  str[1] = Tx | ((c >> 1*Bitx) & Maskx);
  str[2] = Tx | (c & Maskx);
  return 3;
 }
 str[0] = T4 | (c >> 3*Bitx);
 str[1] = Tx | ((c >> 2*Bitx) & Maskx);
 str[2] = Tx | ((c >> 1*Bitx) & Maskx);
 str[3] = Tx | (c & Maskx);
 return 4;
}

canonical_original_code:
int runetochar(char *str, unsigned int *rune)
{
 long c;
 c = *rune;
 if(c <= Rune1) {
  str[0] = c;
  return 1;
 }
 if(c <= Rune2) {
  str[0] = T2 | (c >> 1*Bitx);
  str[1] = Tx | (c & Maskx);
  return 2;
 }
 if(c > Runemax)
  c = Runeerror;
 if(c <= Rune3) {
  str[0] = T3 | (c >> 2*Bitx);
  str[1] = Tx | ((c >> 1*Bitx) & Maskx);
  str[2] = Tx | (c & Maskx);
  return 3;
 }
 str[0] = T4 | (c >> 3*Bitx);
 str[1] = Tx | ((c >> 2*Bitx) & Maskx);
 str[2] = Tx | ((c >> 1*Bitx) & Maskx);
 str[3] = Tx | (c & Maskx);
 return 4;
}

variable_types: c long


runelen

decompiled_code:
__int64 __fastcall runelen(unsigned int a1)
{
char v2[10]; // [rsp+2h] [rbp-Eh] BYREF
unsigned int v3; // [rsp+Ch] [rbp-4h] BYREF

v3 = a1;
return runetochar(v2, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
char v2[10]; // [rsp+2h] [rbp-Eh] BYREF
unsigned int v3; // [rsp+Ch] [rbp-4h] BYREF

v3 = a1;
return func1(v2, &v3);
}

original_code:
int
runelen(long c)
{
 Rune rune;
 char str[10];
 rune = c;
 return runetochar(str, &rune);
}

canonical_original_code:
int runelen(long c)
{
 unsigned int rune;
 char str[10];
 rune = c;
 return runetochar(str, &rune);
}

variable_types:
rune
unsigned int

variable_types:
str
char [10]


runenlen

original_code:
int
runenlen(Rune *r, int nrune)
{
 int nb, c;
 nb = 0;
 while(nrune--) {
  c = *r++;
  if(c <= Rune1)
   nb++;
  else
  if(c <= Rune2)
   nb += 2;
  else
  if(c <= Rune3 || c > Runemax)
   nb += 3;
  else
   nb += 4;
 }
 return nb;
}

canonical_original_code:
int runenlen(unsigned int *r, int nrune)
{
 int nb; int c;
 nb = 0;
 while(nrune--) {
  c = *r++;
  if(c <= Rune1)
   nb++;
  else
  if(c <= Rune2)
   nb += 2;
  else
  if(c <= Rune3 || c > Runemax)
   nb += 3;
  else
   nb += 4;
 }
 return nb;
}

variable_types:
r
unsigned int *

variable_types: nrune int

variable_types: nb int


fullrune

decompiled_code:
_BOOL8 __fastcall fullrune(unsigned __int8 *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 > 0 )
{
result = 1LL;
if ( *a1 > 0x7Fu )
{
if ( *a1 <= 0xDFu )
{
result = a2 > 1;
}
else
{
result = a2 > 3;
if ( *a1 <= 0xEFu )
result = a2 > 2;
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(unsigned __int8 *a1, int a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( a2 > 0 )
{
result = 1LL;
if ( *a1 > 0x7Fu )
{
if ( *a1 <= 0xDFu )
{
result = a2 > 1;
}
else
{
result = a2 > 3;
if ( *a1 <= 0xEFu )
result = a2 > 2;
}
}
}
return result;
}

original_code:
int
fullrune(char *str, int n)
{
 int c;
 if(n <= 0)
  return 0;
 c = *(_utfuchar*)str;
 if(c < Tx)
  return 1;
 if(c < T3)
  return n >= 2;
 if(UTFmax == 3 || c < T4)
  return n >= 3;
 return n >= 4;
}

canonical_original_code:
int fullrune(char *str, int n)
{
 int c;
 if(n <= 0)
  return 0;
 c = *(unsigned char *)str;
 if(c < Tx)
  return 1;
 if(c < T3)
  return n >= 2;
 if(UTFmax == 3 || c < T4)
  return n >= 3;
 return n >= 4;
}


getuser

decompiled_code:
const char *getuser()
{
__uid_t v0; // eax
struct passwd *v1; // rax
const char *v2; // rdx

v0 = getuid();
v1 = getpwuid(v0);
v2 = "none";
if ( v1 )
{
strecpy(&user_0, "none", v1->pw_name);
v2 = (const char *)&user_0;
}
return v2;
}

canonical_decompiled_code:
const char *func0()
{
__uid_t v0; // eax
struct passwd *v1; // rax
const char *v2; // rdx

v0 = getuid();
v1 = getpwuid(v0);
v2 = "none";
if ( v1 )
{
strecpy(&user_0, "none", v1->pw_name);
v2 = (const char *)&user_0;
}
return v2;
}

original_code:
char*
getuser(void)
{
 static char user[64];
 struct passwd *pw;
 pw = getpwuid(getuid());
 if(pw == ((void*)0))
  return "none";
 strecpy(user, user+sizeof user, pw->pw_name);
 return user;
}

canonical_original_code:
char *getuser()
{
 static char user[64];
 struct passwd *pw;
 pw = getpwuid(getuid());
 if(pw == ((void *)0))
  return "none";
 strecpy(user, user+sizeof user, pw->pw_name);
 return user;
}

variable_types:
user
char [64]

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


newinst

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

result = freep;
*(_DWORD *)freep = a1;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
freep = result + 24;
return result;
}

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

result = freep;
*(_DWORD *)freep = a1;
*(_QWORD *)(result + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
freep = result + 24;
return result;
}

original_code:
static Reinst*
newinst(int t)
{
 freep->type = t;
 freep->u2.left = 0;
 freep->u1.right = 0;
 return freep++;
}

canonical_original_code:
static struct Reinst *newinst(int t)
{
 freep->type = t;
 freep->u2.left = 0;
 freep->u1.right = 0;
 return freep++;
}

variable_types: t int

return_type: struct Reinst { int type; union { struct Reclass { unsigned int *end; unsigned int spans[64]; } *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; } *

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


nextc

decompiled_code:
__int64 __fastcall nextc(_DWORD *a1)
{
unsigned int v1; // ebp
__int64 v3; // rsi

v1 = lexdone;
if ( lexdone )
{
*a1 = 0;
v1 = 1;
}
else
{
v3 = exprp + (int)chartorune(a1, exprp);
exprp = v3;
if ( *a1 == 92 )
{
exprp += (int)chartorune(a1, v3);
v1 = 1;
}
else if ( !*a1 )
{
lexdone = 1;
}
}
return v1;
}

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

v1 = lexdone;
if ( lexdone )
{
*a1 = 0;
v1 = 1;
}
else
{
v3 = exprp + (int)chartorune(a1, exprp);
exprp = v3;
if ( *a1 == 92 )
{
exprp += (int)chartorune(a1, v3);
v1 = 1;
}
else if ( !*a1 )
{
lexdone = 1;
}
}
return v1;
}

original_code:
static int
nextc(Rune *rp)
{
 if(lexdone){
  *rp = 0;
  return 1;
 }
 exprp += chartorune(rp, exprp);
 if(*rp == '\\'){
  exprp += chartorune(rp, exprp);
  return 1;
 }
 if(*rp == 0)
  lexdone = 1;
 return 0;
}

canonical_original_code:
static int nextc(unsigned int *rp)
{
 if(lexdone){
  *rp = 0;
  return 1;
 }
 exprp += chartorune(rp, exprp);
 if(*rp == '\\'){
  exprp += chartorune(rp, exprp);
  return 1;
 }
 if(*rp == 0)
  lexdone = 1;
 return 0;
}

variable_types:
rp
unsigned int *


rcerror

decompiled_code:
__int64 rcerror()
{
++errors;
regerror9();
return p9longjmp(&regkaboom, 1LL);
}

canonical_decompiled_code:
__int64 func2()
{
++errors;
regerror9();
return p9longjmp(&regkaboom, 1LL);
}

original_code:
static void
rcerror(char *s)
{
 errors++;
 regerror9(s);
 p9longjmp(regkaboom, 1);
}

variable_types:
s
char *


cant

decompiled_code:
__int64 __fastcall cant(char *src)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

strcpy(v2, "can't happen: ");
strcat(v2, src);
return rcerror(v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

strcpy(v2, "can't happen: ");
strcat(v2, src);
return func2(v2);
}

original_code:
static void
cant(char *s)
{
 char buf[100];
 strcpy(buf, "can't happen: ");
 strcat(buf, s);
 rcerror(buf);
}

variable_types:
buf
char [100]


pushand

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

if ( andp >= (unsigned __int64)"operator stack overflow" )
cant("operand stack overflow");
v2 = andp;
*(_QWORD *)andp = a1;
*(_QWORD *)(v2 + 8) = a2;
result = v2 + 16;
andp = result;
return result;
}

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

if ( andp >= (unsigned __int64)"operator stack overflow" )
func3("operand stack overflow");
v2 = andp;
*(_QWORD *)andp = a1;
*(_QWORD *)(v2 + 8) = a2;
result = v2 + 16;
andp = result;
return result;
}

original_code:
static void
pushand(Reinst *f, Reinst *l)
{
 if(andp >= &andstack[20])
  cant("operand stack overflow");
 andp->first = f;
 andp->last = l;
 andp++;
}

canonical_original_code:
static void pushand(struct Reinst *f, struct Reinst *l)
{
 if(andp >= &andstack[20])
  cant("operand stack overflow");
 andp->first = f;
 andp->last = l;
 andp++;
}

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

variable_types:
l
struct Reinst *


popator

decompiled_code:
__int64 popator()
{
if ( atorp <= (unsigned __int64)&atorstack )
cant("operator stack underflow");
subidp -= 4LL;
atorp -= 4LL;
return *(unsigned int *)atorp;
}

canonical_decompiled_code:
__int64 func5()
{
if ( atorp <= (unsigned __int64)&atorstack )
func3("operator stack underflow");
subidp -= 4LL;
atorp -= 4LL;
return *(unsigned int *)atorp;
}

original_code:
static int
popator(void)
{
 if(atorp <= &atorstack[0])
  cant("operator stack underflow");
 --subidp;
 return *--atorp;
}

canonical_original_code:
static int popator()
{
 if(atorp <= &atorstack[0])
  cant("operator stack underflow");
 --subidp;
 return *--atorp;
}


newclass

decompiled_code:
__int64 newclass()
{
int v0; // eax

if ( (unsigned int)nclass > 0xF )
rcerror("too many character classes; increase Reprog.class size");
v0 = nclass++;
return classp + 264LL * v0;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax

if ( (unsigned int)nclass > 0xF )
func2("too many character classes; increase Reprog.class size");
v0 = nclass++;
return classp + 264LL * v0;
}

original_code:
static Reclass*
newclass(void)
{
 if(nclass >= (sizeof(reprog->class)/sizeof((reprog->class)[0])))
  rcerror("too many character classes; increase Reprog.class size");
 return &(classp[nclass++]);
}

canonical_original_code:
static struct Reclass *newclass()
{
 if(nclass >= (sizeof(reprog->class)/sizeof((reprog->class)[0])))
  rcerror("too many character classes; increase Reprog.class size");
 return &(classp[nclass++]);
}

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


bldcclass

original_code:
static int
bldcclass(void)
{
 int type;
 Rune r[(sizeof(classp->spans)/sizeof((classp->spans)[0]))];
 Rune *p, *ep, *np;
 Rune rune;
 int quoted;
 type = 0305;
 yyclassp = newclass();
 ep = r;
 quoted = nextc(&rune);
 if(!quoted && rune == '^'){
  type = 0306;
  quoted = nextc(&rune);
  *ep++ = '\n';
  *ep++ = '\n';
 }
 while(ep < &r[(sizeof(classp->spans)/sizeof((classp->spans)[0]))-1]){
  if(rune == 0){
   rcerror("malformed '[]'");
   return 0;
  }
  if(!quoted && rune == ']')
   break;
  if(!quoted && rune == '-'){
   if(ep == r){
    rcerror("malformed '[]'");
    return 0;
   }
   quoted = nextc(&rune);
   if((!quoted && rune == ']') || rune == 0){
    rcerror("malformed '[]'");
    return 0;
   }
   *(ep-1) = rune;
  } else {
   *ep++ = rune;
   *ep++ = rune;
  }
  quoted = nextc(&rune);
 }
 if(ep >= &r[(sizeof(classp->spans)/sizeof((classp->spans)[0]))-1]) {
  rcerror("char class too large; increase Reclass.spans size");
  return 0;
 }
 for(p = r; p < ep; p += 2){
  for(np = p; np < ep; np += 2)
   if(*np < *p){
    rune = np[0];
    np[0] = p[0];
    p[0] = rune;
    rune = np[1];
    np[1] = p[1];
    p[1] = rune;
   }
 }
 np = yyclassp->spans;
 p = r;
 if(r == ep)
  yyclassp->end = np;
 else {
  np[0] = *p++;
  np[1] = *p++;
  for(; p < ep; p += 2)
   if(p[0] <= np[1] + 1){
    if(p[1] >= np[1])
     np[1] = p[1];
   } else {
    np += 2;
    np[0] = p[0];
    np[1] = p[1];
   }
  yyclassp->end = np+2;
 }
 return type;
}

canonical_original_code:
static int bldcclass()
{
 int type;
 unsigned int r[-1];
 unsigned int *p; unsigned int *ep; unsigned int *np;
 unsigned int rune;
 int quoted;
 type = 0305;
 yyclassp = newclass();
 ep = r;
 quoted = nextc(&rune);
 if(!quoted && rune == '^'){
  type = 0306;
  quoted = nextc(&rune);
  *ep++ = '\n';
  *ep++ = '\n';
 }
 while(ep < &r[(sizeof(classp->spans)/sizeof((classp->spans)[0]))-1]){
  if(rune == 0){
   rcerror("malformed '[]'");
   return 0;
  }
  if(!quoted && rune == ']')
   break;
  if(!quoted && rune == '-'){
   if(ep == r){
    rcerror("malformed '[]'");
    return 0;
   }
   quoted = nextc(&rune);
   if((!quoted && rune == ']') || rune == 0){
    rcerror("malformed '[]'");
    return 0;
   }
   *(ep-1) = rune;
  } else {
   *ep++ = rune;
   *ep++ = rune;
  }
  quoted = nextc(&rune);
 }
 if(ep >= &r[(sizeof(classp->spans)/sizeof((classp->spans)[0]))-1]) {
  rcerror("char class too large; increase Reclass.spans size");
  return 0;
 }
 for(p = r; p < ep; p += 2){
  for(np = p; np < ep; np += 2)
   if(*np < *p){
    rune = np[0];
    np[0] = p[0];
    p[0] = rune;
    rune = np[1];
    np[1] = p[1];
    p[1] = rune;
   }
 }
 np = yyclassp->spans;
 p = r;
 if(r == ep)
  yyclassp->end = np;
 else {
  np[0] = *p++;
  np[1] = *p++;
  for(; p < ep; p += 2)
   if(p[0] <= np[1] + 1){
    if(p[1] >= np[1])
     np[1] = p[1];
   } else {
    np += 2;
    np[0] = p[0];
    np[1] = p[1];
   }
  yyclassp->end = np+2;
 }
 return type;
}

variable_types: type int

variable_types:
r
unsigned int [-1]

variable_types:
p
unsigned int *

variable_types:
ep
unsigned int *

variable_types:
np
unsigned int *

variable_types: quoted int


lex

decompiled_code:
__int64 __fastcall lex(int a1, unsigned int a2)
{
__int64 result; // rax

if ( a1 | (unsigned int)nextc(&yyrune) )
return yyrune == 0 ? 255 : 127;
if ( (unsigned int)yyrune > 0x5E )
return 4 * (unsigned int)(yyrune == 124) + 127;
if ( (unsigned int)yyrune <= 0x23 )
return yyrune == 0 ? 255 : 127;
switch ( yyrune )
{
case '$':
result = 196LL;
break;
case '(':
result = 130LL;
break;
case ')':
result = 129LL;
break;
case '*':
result = 133LL;
break;
case '+':
result = 134LL;
break;
case '.':
result = a2;
break;
case '?':
result = 135LL;
break;
case '[':
result = bldcclass();
break;
case '^':
result = 195LL;
break;
default:
result = 127LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned int a2)
{
__int64 result; // rax

if ( a1 | (unsigned int)func1(&yyrune) )
return yyrune == 0 ? 255 : 127;
if ( (unsigned int)yyrune > 0x5E )
return 4 * (unsigned int)(yyrune == 124) + 127;
if ( (unsigned int)yyrune <= 0x23 )
return yyrune == 0 ? 255 : 127;
switch ( yyrune )
{
case '$':
result = 196LL;
break;
case '(':
result = 130LL;
break;
case ')':
result = 129LL;
break;
case '*':
result = 133LL;
break;
case '+':
result = 134LL;
break;
case '.':
result = a2;
break;
case '?':
result = 135LL;
break;
case '[':
result = func7();
break;
case '^':
result = 195LL;
break;
default:
result = 127LL;
break;
}
return result;
}

original_code:
static int
lex(int literal, int dot_type)
{
 int quoted;
 quoted = nextc(&yyrune);
 if(literal || quoted){
  if(yyrune == 0)
   return 0377;
  return 0177;
 }
 switch(yyrune){
 case 0:
  return 0377;
 case '*':
  return 0205;
 case '?':
  return 0207;
 case '+':
  return 0206;
 case '|':
  return 0203;
 case '.':
  return dot_type;
 case '(':
  return 0202;
 case ')':
  return 0201;
 case '^':
  return 0303;
 case '$':
  return 0304;
 case '[':
  return bldcclass();
 }
 return 0177;
}

variable_types: literal int


popand

decompiled_code:
__int64 __fastcall popand(char a1)
{
__int64 result; // rax
__int64 v2; // rax

if ( andp <= (unsigned __int64)&andstack )
{
regerr2("missing operand for ", a1);
v2 = newinst(194);
pushand(v2, v2);
}
result = andp - 16;
andp -= 16LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char a1)
{
__int64 result; // rax
__int64 v2; // rax

if ( andp <= (unsigned __int64)&andstack )
{
func9("missing operand for ", a1);
v2 = func0(194);
func4(v2, v2);
}
result = andp - 16;
andp -= 16LL;
return result;
}

original_code:
static Node*
popand(int op)
{
 Reinst *inst;
 if(andp <= &andstack[0]){
  regerr2("missing operand for ", op);
  inst = newinst(0302);
  pushand(inst,inst);
 }
 return --andp;
}

canonical_original_code:
static struct Node *popand(int op)
{
 struct Reinst *inst;
 if(andp <= &andstack[0]){
  regerr2("missing operand for ", op);
  inst = newinst(0302);
  pushand(inst,inst);
 }
 return --andp;
}

variable_types: op int

return_type: struct Node { struct Reinst { int type; union { struct Reclass { unsigned int *end; unsigned int spans[64]; } *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; } *first; struct Reinst *last; } *

user_defined_types: struct Node { struct Reinst *first; struct Reinst *last; }


evaluntil

original_code:
static void
evaluntil(int pri)
{
 Node *op1, *op2;
 Reinst *inst1, *inst2;
 while(pri==0201 || atorp[-1]>=pri){
  switch(popator()){
  default:
   rcerror("unknown operator in evaluntil");
   break;
  case 0202:
   op1 = popand('(');
   inst2 = newinst(0201);
   inst2->u1.subid = *subidp;
   op1->last->u2.next = inst2;
   inst1 = newinst(0202);
   inst1->u1.subid = *subidp;
   inst1->u2.next = op1->first;
   pushand(inst1, inst2);
   return;
  case 0203:
   op2 = popand('|');
   op1 = popand('|');
   inst2 = newinst(0302);
   op2->last->u2.next = inst2;
   op1->last->u2.next = inst2;
   inst1 = newinst(0203);
   inst1->u1.right = op1->first;
   inst1->u2.left = op2->first;
   pushand(inst1, inst2);
   break;
  case 0204:
   op2 = popand(0);
   op1 = popand(0);
   op1->last->u2.next = op2->first;
   pushand(op1->first, op2->last);
   break;
  case 0205:
   op2 = popand('*');
   inst1 = newinst(0203);
   op2->last->u2.next = inst1;
   inst1->u1.right = op2->first;
   pushand(inst1, inst1);
   break;
  case 0206:
   op2 = popand('+');
   inst1 = newinst(0203);
   op2->last->u2.next = inst1;
   inst1->u1.right = op2->first;
   pushand(op2->first, inst1);
   break;
  case 0207:
   op2 = popand('?');
   inst1 = newinst(0203);
   inst2 = newinst(0302);
   inst1->u2.left = inst2;
   inst1->u1.right = op2->first;
   op2->last->u2.next = inst2;
   pushand(inst1, inst2);
   break;
  }
 }
}

canonical_original_code:
static void evaluntil(int pri)
{
 struct Node *op1; struct Node *op2;
 struct Reinst *inst1; struct Reinst *inst2;
 while(pri==0201 || atorp[-1]>=pri){
  switch(popator()){
  default:
   rcerror("unknown operator in evaluntil");
   break;
  case 0202:
   op1 = popand('(');
   inst2 = newinst(0201);
   inst2->u1.subid = *subidp;
   op1->last->u2.next = inst2;
   inst1 = newinst(0202);
   inst1->u1.subid = *subidp;
   inst1->u2.next = op1->first;
   pushand(inst1, inst2);
   return;
  case 0203:
   op2 = popand('|');
   op1 = popand('|');
   inst2 = newinst(0302);
   op2->last->u2.next = inst2;
   op1->last->u2.next = inst2;
   inst1 = newinst(0203);
   inst1->u1.right = op1->first;
   inst1->u2.left = op2->first;
   pushand(inst1, inst2);
   break;
  case 0204:
   op2 = popand(0);
   op1 = popand(0);
   op1->last->u2.next = op2->first;
   pushand(op1->first, op2->last);
   break;
  case 0205:
   op2 = popand('*');
   inst1 = newinst(0203);
   op2->last->u2.next = inst1;
   inst1->u1.right = op2->first;
   pushand(inst1, inst1);
   break;
  case 0206:
   op2 = popand('+');
   inst1 = newinst(0203);
   op2->last->u2.next = inst1;
   inst1->u1.right = op2->first;
   pushand(op2->first, inst1);
   break;
  case 0207:
   op2 = popand('?');
   inst1 = newinst(0203);
   inst2 = newinst(0302);
   inst1->u2.left = inst2;
   inst1->u1.right = op2->first;
   op2->last->u2.next = inst2;
   pushand(inst1, inst2);
   break;
  }
 }
}

variable_types: pri int

variable_types: struct Node { struct Reinst { int type; union { struct Reclass { unsigned int *end; unsigned int spans[64]; } *cp; unsigned int r; int subid; struct Reinst *right; } u1; union { struct Reinst *left; struct Reinst *next; } u2; } *first; struct Reinst *last; } *


operator

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

switch ( a1 )
{
case 129:
if ( --nbra < 0 )
rcerror("unmatched right paren");
result = evaluntil(a1);
goto LABEL_13;
case 130:
if ( ++cursubid > 31 )
rcerror("too many subexpressions");
++nbra;
if ( lastwasand )
operator(132LL);
result = (__int64)pushator(a1);
lastwasand = 0;
break;
case 134:
LABEL_13:
lastwasand = 1;
break;
default:
evaluntil(a1);
pushator(a1);
lastwasand = 0;
result = a1 & 0xFFFFFFFD;
if ( (_DWORD)result == 133 )
goto LABEL_13;
break;
}
return result;
}

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

switch ( a1 )
{
case 129:
if ( --nbra < 0 )
func2("unmatched right paren");
result = func11(a1);
goto LABEL_13;
case 130:
if ( ++cursubid > 31 )
func2("too many subexpressions");
++nbra;
if ( lastwasand )
func12(132LL);
result = (__int64)pushator(a1);
lastwasand = 0;
break;
case 134:
LABEL_13:
lastwasand = 1;
break;
default:
func11(a1);
pushator(a1);
lastwasand = 0;
result = a1 & 0xFFFFFFFD;
if ( (_DWORD)result == 133 )
goto LABEL_13;
break;
}
return result;
}

original_code:
static void
operator(int t)
{
 if(t==0201 && --nbra<0)
  rcerror("unmatched right paren");
 if(t==0202){
  if(++cursubid >= 32)
   rcerror ("too many subexpressions");
  nbra++;
  if(lastwasand)
   operator(0204);
 } else
  evaluntil(t);
 if(t != 0201)
  pushator(t);
 lastwasand = 0;
 if(t==0205 || t==0207 || t==0206 || t==0201)
  lastwasand = 1;
}


operand

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

if ( lastwasand )
operator(132);
v2 = newinst(a1);
if ( (unsigned int)(a1 - 197) <= 1 )
{
*(_QWORD *)(v2 + 8) = yyclassp;
}
else if ( a1 == 127 )
{
*(_DWORD *)(v2 + 8) = yyrune;
}
result = pushand(v2, v2);
lastwasand = 1;
return result;
}

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

if ( lastwasand )
func12(132);
v2 = func0(a1);
if ( (unsigned int)(a1 - 197) <= 1 )
{
*(_QWORD *)(v2 + 8) = yyclassp;
}
else if ( a1 == 127 )
{
*(_DWORD *)(v2 + 8) = yyrune;
}
result = func4(v2, v2);
lastwasand = 1;
return result;
}

original_code:
static void
operand(int t)
{
 Reinst *i;
 if(lastwasand)
  operator(0204);
 i = newinst(t);
 if(t == 0305 || t == 0306)
  i->u1.cp = yyclassp;
 if(t == 0177)
  i->u1.r = yyrune;
 pushand(i, i);
 lastwasand = 1;
}

canonical_original_code:
static void operand(int t)
{
 struct Reinst *i;
 if(lastwasand)
  operator(0204);
 i = newinst(t);
 if(t == 0305 || t == 0306)
  i->u1.cp = yyclassp;
 if(t == 0177)
  i->u1.r = yyrune;
 pushand(i, i);
 lastwasand = 1;
}

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


sysname

decompiled_code:
char *sysname()
{
_BYTE *v1; // rax
_BYTE *v2; // rbx
char *v3; // rax

if ( buf_0[0] )
return buf_0;
v1 = (_BYTE *)p9getenv("sysname");
v2 = v1;
if ( !v1 )
goto LABEL_6;
if ( !*v1 )
{
p9free(v1);
LABEL_6:
if ( gethostname(buf_0, 0x200uLL) < 0 )
{
strcpy(buf_0, "gnot");
}
else
{
byte_29F = 0;
v3 = strchr(buf_0, 46);
if ( v3 )
*v3 = 0;
}
return buf_0;
}
utfecpy(buf_0, "sysname", v1);
p9free(v2);
return buf_0;
}

canonical_decompiled_code:
char *func0()
{
_BYTE *v1; // rax
_BYTE *v2; // rbx
char *v3; // rax

if ( buf_0[0] )
return buf_0;
v1 = (_BYTE *)p9getenv("sysname");
v2 = v1;
if ( !v1 )
goto LABEL_6;
if ( !*v1 )
{
p9free(v1);
LABEL_6:
if ( gethostname(buf_0, 0x200uLL) < 0 )
{
strcpy(buf_0, "gnot");
}
else
{
byte_29F = 0;
v3 = strchr(buf_0, 46);
if ( v3 )
*v3 = 0;
}
return buf_0;
}
utfecpy(buf_0, "sysname", v1);
p9free(v2);
return buf_0;
}

original_code:
char*
sysname(void)
{
 static char buf[512];
 char *p, *q;
 if(buf[0])
  return buf;
 if((q = p9getenv("sysname")) != ((void*)0) && q[0] != 0){
  utfecpy(buf, buf+sizeof buf, q);
  p9free(q);
  return buf;
 }
 if(q)
  p9free(q);
 if(gethostname(buf, sizeof buf) >= 0){
  buf[sizeof buf-1] = 0;
  if((p = strchr(buf, '.')) != ((void*)0))
   *p = 0;
  return buf;
 }
 strcpy(buf, "gnot");
 return buf;
}

canonical_original_code:
char *sysname()
{
 static char buf[512];
 char *p; char *q;
 if(buf[0])
  return buf;
 if((q = p9getenv("sysname")) != ((void *)0) && q[0] != 0){
  utfecpy(buf, buf+sizeof buf, q);
  p9free(q);
  return buf;
 }
 if(q)
  p9free(q);
 if(gethostname(buf, sizeof buf) >= 0){
  buf[sizeof buf-1] = 0;
  if((p = strchr(buf, '.')) != ((void *)0))
   *p = 0;
  return buf;
 }
 strcpy(buf, "gnot");
 return buf;
}

variable_types:
buf
char [512]

variable_types:
p
char *

variable_types:
q
char *


vfprint

decompiled_code:
__int64 __fastcall vfprint(unsigned int a1, __int64 a2, const __m128i *a3)
{
int v4; // ebx
__int64 v6; // [rsp+0h] [rbp-198h] BYREF
char v7[56]; // [rsp+100h] [rbp-98h] BYREF
__m128i v8; // [rsp+138h] [rbp-60h]
__int64 v9; // [rsp+148h] [rbp-50h]

fmtfdinit(v7, a1, &v6, 256LL);
v8 = _mm_loadu_si128(a3);
v9 = a3[1].m128i_i64[0];
v4 = dofmt(v7, a2);
if ( v4 > 0 && !(unsigned int)_fmtFdFlush(v7) )
v4 = -1;
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, const __m128i *a3)
{
int v4; // ebx
__int64 v6; // [rsp+0h] [rbp-198h] BYREF
char v7[56]; // [rsp+100h] [rbp-98h] BYREF
__m128i v8; // [rsp+138h] [rbp-60h]
__int64 v9; // [rsp+148h] [rbp-50h]

fmtfdinit(v7, a1, &v6, 256LL);
v8 = _mm_loadu_si128(a3);
v9 = a3[1].m128i_i64[0];
v4 = dofmt(v7, a2);
if ( v4 > 0 && !(unsigned int)_fmtFdFlush(v7) )
v4 = -1;
return (unsigned int)v4;
}

original_code:
int
vfprint(int fd, char *fmt, va_list args)
{
 Fmt f;
 char buf[256];
 int n;
 fmtfdinit(&f, fd, buf, sizeof(buf));
 __builtin_va_copy(f.args,args);
 n = dofmt(&f, fmt);
 __builtin_va_end(f.args);
 if(n > 0 && __fmtFdFlush(&f) == 0)
  return -1;
 return n;
}

canonical_original_code:
int vfprint(int fd, char *fmt, __builtin_va_list args)
{
 struct Fmt f;
 char buf[256];
 int n;
 fmtfdinit(&f, fd, buf, sizeof(buf));
 __builtin_va_copy(f.args,args);
 n = dofmt(&f, fmt);
 __builtin_va_end(f.args);
 if(n > 0 && __fmtFdFlush(&f) == 0)
  return -1;
 return n;
}

variable_types: fd int

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

variable_types:
buf
char [256]

variable_types: n int


decompiled_code:
__int64 __fastcall p9create(char *filename, __int64 a2, int a3)
{
int v3; // ebx
int v4; // er13
unsigned int v5; // ebp
__int64 v6; // rsi
unsigned int v7; // eax
__int16 v9[4]; // [rsp+0h] [rbp-48h] BYREF
__int64 v10; // [rsp+8h] [rbp-40h]
__int64 v11; // [rsp+10h] [rbp-38h]

v3 = a2;
v4 = a2 & 3;
if ( a3 >= 0 )
{
if ( (a2 & 0x80u) != 0LL )
{
v6 = v4 | 0x4240u;
v7 = v3 & 0xFFFFDF0C;
}
else
{
v6 = v4 | 0x240u;
v7 = v3 & 0xFFFFDF8C;
}
if ( (v7 & 0x1000) != 0 )
{
LOBYTE(v6) = v6 | 0x80;
BYTE1(v7) &= 0xEFu;
}
if ( (v7 & 0x4000) != 0 )
{
v6 = (unsigned int)v6 | 0x400;
BYTE1(v7) &= 0xBFu;
}
if ( v7 )
{
werrstr("unsupported mode in create", v6);
return (unsigned int)-1;
}
v5 = open64(filename, v6);
}
else
{
if ( (a2 & 0xFFFFDF9F) != 0 )
{
werrstr("bad mode in directory create", a2);
return (unsigned int)-1;
}
if ( mkdir(filename, a3 & 0x1FF) < 0 )
return (unsigned int)-1;
v5 = open64(filename, 0);
}
if ( (v5 & 0x80000000) == 0 )
{
if ( (v3 & 0x2000) != 0 && (v9[0] = v4 != 0, v9[1] = 0, v10 = 0LL, v11 = 0LL, (int)fcntl64(v5, 6LL, v9) < 0) )
{
close(v5);
werrstr("lock: %r");
v5 = -1;
}
else
{
if ( (v3 & 0x20) != 0 )
fcntl64(v5, 4LL, 1LL);
if ( (v3 & 0x40) != 0 )
remove(filename);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *filename, __int64 a2, int a3)
{
int v3; // ebx
int v4; // er13
unsigned int v5; // ebp
__int64 v6; // rsi
unsigned int v7; // eax
__int16 v9[4]; // [rsp+0h] [rbp-48h] BYREF
__int64 v10; // [rsp+8h] [rbp-40h]
__int64 v11; // [rsp+10h] [rbp-38h]

v3 = a2;
v4 = a2 & 3;
if ( a3 >= 0 )
{
if ( (a2 & 0x80u) != 0LL )
{
v6 = v4 | 0x4240u;
v7 = v3 & 0xFFFFDF0C;
}
else
{
v6 = v4 | 0x240u;
v7 = v3 & 0xFFFFDF8C;
}
if ( (v7 & 0x1000) != 0 )
{
LOBYTE(v6) = v6 | 0x80;
BYTE1(v7) &= 0xEFu;
}
if ( (v7 & 0x4000) != 0 )
{
v6 = (unsigned int)v6 | 0x400;
BYTE1(v7) &= 0xBFu;
}
if ( v7 )
{
werrstr("unsupported mode in create", v6);
return (unsigned int)-1;
}
v5 = open64(filename, v6);
}
else
{
if ( (a2 & 0xFFFFDF9F) != 0 )
{
werrstr("bad mode in directory create", a2);
return (unsigned int)-1;
}
if ( mkdir(filename, a3 & 0x1FF) < 0 )
return (unsigned int)-1;
v5 = open64(filename, 0);
}
if ( (v5 & 0x80000000) == 0 )
{
if ( (v3 & 0x2000) != 0 && (v9[0] = v4 != 0, v9[1] = 0, v10 = 0LL, v11 = 0LL, (int)fcntl64(v5, 6LL, v9) < 0) )
{
close(v5);
werrstr("lock: %r");
v5 = -1;
}
else
{
if ( (v3 & 0x20) != 0 )
fcntl64(v5, 4LL, 1LL);
if ( (v3 & 0x40) != 0 )
remove(filename);
}
}
return v5;
}

original_code:
int
p9create(char *path, int mode, ulong perm)
{
 int fd, cexec, umode, rclose, lock, rdwr;
 struct flock fl;
 rdwr = mode&3;
 lock = mode&0x2000;
 cexec = mode&32;
 rclose = mode&64;
 mode &= ~(64|32|0x2000);
 fd = -1;
 if(perm&0x80000000){
  if(mode != 0){
   werrstr("bad mode in directory create");
   goto out;
  }
  if(mkdir(path, perm&0777) < 0)
   goto out;
  fd = open(path, 00);
 }else{
  umode = (mode&3)|0100|01000;
  mode &= ~(3|16);
  if(mode&128){
   umode |= 040000;
   mode &= ~128;
  }
  if(mode&0x1000){
   umode |= 0200;
   mode &= ~0x1000;
  }
  if(mode&0x4000){
   umode |= 02000;
   mode &= ~0x4000;
  }
  if(mode){
   werrstr("unsupported mode in create");
   goto out;
  }
  fd = open(path, umode, perm);
 }
out:
 if(fd >= 0){
  if(lock){
   fl.l_type = (rdwr==0) ? 0 : 1;
   fl.l_whence = 0;
   fl.l_start = 0;
   fl.l_len = 0;
   if(fcntl(fd, 6, &fl) < 0){
    close(fd);
    werrstr("lock: %r");
    return -1;
   }
  }
  if(cexec)
   fcntl(fd, 4, 1);
  if(rclose)
   remove(path);
 }
 return fd;
}

canonical_original_code:
int p9create(char *path, int mode, unsigned long perm)
{
 int fd; int cexec; int umode; int rclose; int lock; int rdwr;
 struct flock fl;
 rdwr = mode&3;
 lock = mode&0x2000;
 cexec = mode&32;
 rclose = mode&64;
 mode &= ~(64|32|0x2000);
 fd = -1;
 if(perm&0x80000000){
  if(mode != 0){
   werrstr("bad mode in directory create");
   goto out;
  }
  if(mkdir(path, perm&0777) < 0)
   goto out;
  fd = open(path, 00);
 }else{
  umode = (mode&3)|0100|01000;
  mode &= ~(3|16);
  if(mode&128){
   umode |= 040000;
   mode &= ~128;
  }
  if(mode&0x1000){
   umode |= 0200;
   mode &= ~0x1000;
  }
  if(mode&0x4000){
   umode |= 02000;
   mode &= ~0x4000;
  }
  if(mode){
   werrstr("unsupported mode in create");
   goto out;
  }
  fd = open(path, umode, perm);
 }
out:
 if(fd >= 0){
  if(lock){
   fl.l_type = (rdwr==0) ? 0 : 1;
   fl.l_whence = 0;
   fl.l_start = 0;
   fl.l_len = 0;
   if(fcntl(fd, 6, &fl) < 0){
    close(fd);
    werrstr("lock: %r");
    return -1;
   }
  }
  if(cexec)
   fcntl(fd, 4, 1);
  if(rclose)
   remove(path);
 }
 return fd;
}

variable_types:
path
char *

variable_types: mode int

variable_types:
perm
unsigned long

variable_types: cexec int

variable_types: umode int

variable_types: rclose int

variable_types: lock int

variable_types: rdwr int

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


decompiled_code:
void *__fastcall p9strdup(void *src)
{
size_t v1; // rbx
void *v2; // rax
void *v3; // rbp

v1 = (int)(strlen((const char *)src) + 1);
v2 = (void *)p9malloc(v1);
v3 = v2;
if ( v2 )
memmove(v2, src, v1);
return v3;
}

canonical_decompiled_code:
void *__fastcall func0(void *src)
{
size_t v1; // rbx
void *v2; // rax
void *v3; // rbp

v1 = (int)(strlen((const char *)src) + 1);
v2 = (void *)p9malloc(v1);
v3 = v2;
if ( v2 )
memmove(v2, src, v1);
return v3;
}

original_code:
char*
p9strdup(char *s)
{
 char *t;
 int l;
 l = strlen(s);
 t = p9malloc(l+1);
 if(t == ((void*)0))
  return ((void*)0);
 memmove(t, s, l+1);
 return t;
}

canonical_original_code:
char *p9strdup(char *s)
{
 char *t;
 int l;
 l = strlen(s);
 t = p9malloc(l+1);
 if(t == ((void *)0))
  return ((void *)0);
 memmove(t, s, l+1);
 return t;
}

variable_types:
s
char *

variable_types:
t
char *

variable_types: l int


Bbuffered

decompiled_code:
__int64 __fastcall Bbuffered(_DWORD *a1)
{
__int64 result; // rax

result = (unsigned int)a1[4];
if ( (_DWORD)result == 2 )
return (unsigned int)(a1[10] + a1[1]);
if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
return (unsigned int)-*a1;
}
else
{
if ( !(_DWORD)result )
return result;
if ( (_DWORD)result == 1 )
return (unsigned int)-*a1;
}
fprint(2LL, "Bbuffered: unknown state %d\n", (unsigned int)result);
return 0LL;
}

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

result = (unsigned int)a1[4];
if ( (_DWORD)result == 2 )
return (unsigned int)(a1[10] + a1[1]);
if ( (int)result > 2 )
{
if ( (_DWORD)result == 3 )
return (unsigned int)-*a1;
}
else
{
if ( !(_DWORD)result )
return result;
if ( (_DWORD)result == 1 )
return (unsigned int)-*a1;
}
fprint(2LL, "Bbuffered: unknown state %d\n", (unsigned int)result);
return 0LL;
}

original_code:
int
Bbuffered(Biobuf *bp)
{
 switch(bp->state) {
 case Bracteof:
 case Bractive:
  return -bp->icount;
 case Bwactive:
  return bp->bsize + bp->ocount;
 case Binactive:
  return 0;
 }
 fprint(2, "Bbuffered: unknown state %d\n", bp->state);
 return 0;
}

canonical_original_code:
int Bbuffered(struct Biobuf *bp)
{
 switch(bp->state) {
 case Bracteof:
 case Bractive:
  return -bp->icount;
 case Bwactive:
  return bp->bsize + bp->ocount;
 case Binactive:
  return 0;
 }
 fprint(2, "Bbuffered: unknown state %d\n", bp->state);
 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]; } *


findsig

decompiled_code:
int *__fastcall findsig(int a1)
{
__int64 v1; // rax

v1 = 0LL;
while ( sigs[2 * v1] != a1 )
{
if ( ++v1 == 19 )
return 0LL;
}
return &sigs[2 * (int)v1];
}

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

v1 = 0LL;
while ( sigs[2 * v1] != a1 )
{
if ( ++v1 == 19 )
return 0LL;
}
return &sigs[2 * (int)v1];
}

original_code:
static Sig*
findsig(int s)
{
 int i;
 for(i=0; i<(sizeof(sigs)/sizeof((sigs)[0])); i++)
  if(sigs[i].sig == s)
   return &sigs[i];
 return ((void*)0);
}

canonical_original_code:
static struct Sig *findsig(int s)
{
 int i;
 for(i=0; i<(sizeof(sigs)/sizeof((sigs)[0])); i++)
  if(sigs[i].sig == s)
   return &sigs[i];
 return ((void *)0);
}

variable_types: s int

variable_types: i int

return_type: struct Sig { int sig; int flags; } *


getonejmp

decompiled_code:
void *getonejmp()
{
return &onejmp;
}

canonical_decompiled_code:
void *func1()
{
return &onejmp;
}

original_code:
static Jmp*
getonejmp(void)
{
 return &onejmp;
}

canonical_original_code:
static struct Jmp *getonejmp()
{
 return &onejmp;
}

return_type: struct Jmp { long b[-1]; } *


signonotify

decompiled_code:
void signonotify()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
static void
signonotify(int sig)
{
 ((void)(sig));
}

variable_types: sig int


handler

decompiled_code:
__sighandler_t __fastcall handler(int a1)
{
struct sigaction v2; // [rsp+0h] [rbp-A8h] BYREF

sigaction(a1, 0LL, &v2);
return v2.sa_handler;
}

canonical_decompiled_code:
__sighandler_t __fastcall func3(int a1)
{
struct sigaction v2; // [rsp+0h] [rbp-A8h] BYREF

sigaction(a1, 0LL, &v2);
return v2.sa_handler;
}

original_code:
static Sighandler*
handler(int s)
{
 struct sigaction sa;
 sigaction(s, ((void*)0), &sa);
 return sa.__sigaction_handler.sa_handler;
}

canonical_original_code:
static void (*handler(int s))(int)
{
 struct sigaction sa;
 sigaction(s, ((void *)0), &sa);
 return sa.__sigaction_handler.sa_handler;
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

return_type: void (*)(int)


notifyseton

decompiled_code:
__int64 __fastcall notifyseton(int a1, int a2)
{
int *v2; // rbx
__int64 result; // rax
void (*v4)(); // rax
struct sigaction v5; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-B8h] BYREF

v2 = findsig(a1);
result = 0xFFFFFFFFLL;
if ( v2 )
{
memset(&v6.sa_mask, 0, 0x90uLL);
v4 = (void (*)())signotify;
if ( !a2 )
v4 = signonotify;
v6.sa_handler = (__sighandler_t)v4;
if ( (v2[1] & 1) != 0 )
v6.sa_flags = 0x10000000;
sigfillset(&v6.sa_mask);
sigaction(*v2, &v6, &v5);
result = v5.sa_handler == (__sighandler_t)signotify;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2)
{
int *v2; // rbx
__int64 result; // rax
void (*v4)(); // rax
struct sigaction v5; // [rsp+0h] [rbp-158h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-B8h] BYREF

v2 = func0(a1);
result = 0xFFFFFFFFLL;
if ( v2 )
{
memset(&v6.sa_mask, 0, 0x90uLL);
v4 = (void (*)())signotify;
if ( !a2 )
v4 = signonotify;
v6.sa_handler = (__sighandler_t)v4;
if ( (v2[1] & 1) != 0 )
v6.sa_flags = 0x10000000;
sigfillset(&v6.sa_mask);
sigaction(*v2, &v6, &v5);
result = v5.sa_handler == (__sighandler_t)signotify;
}
return result;
}

original_code:
static int
notifyseton(int s, int on)
{
 Sig *sig;
 struct sigaction sa, osa;
 sig = findsig(s);
 if(sig == ((void*)0))
  return -1;
 memset(&sa, 0, sizeof sa);
 sa.__sigaction_handler.sa_handler = on ? signotify : signonotify;
 if(sig->flags&Restart)
  sa.sa_flags |= 0x10000000;
 sigfillset(&sa.sa_mask);
 sigaction(sig->sig, &sa, &osa);
 return osa.__sigaction_handler.sa_handler == signotify;
}

canonical_original_code:
static int notifyseton(int s, int on)
{
 struct Sig *sig;
 struct sigaction sa; struct sigaction osa;
 sig = findsig(s);
 if(sig == ((void *)0))
  return -1;
 memset(&sa, 0, sizeof sa);
 sa.__sigaction_handler.sa_handler = on ? signotify : signonotify;
 if(sig->flags&Restart)
  sa.sa_flags |= 0x10000000;
 sigfillset(&sa.sa_mask);
 sigaction(sig->sig, &sa, &osa);
 return osa.__sigaction_handler.sa_handler == signotify;
}

variable_types: on int

variable_types:
sig
struct Sig { int sig; int flags; } *

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


noteinit

decompiled_code:
__int64 noteinit()
{
int *v0; // rbx
__int64 result; // rax

v0 = sigs;
do
{
result = (__int64)handler(*v0);
if ( !result )
result = notifyseton(*v0, (v0[1] & 4) == 0);
v0 += 2;
}
while ( v0 != (int *)920 );
return result;
}

canonical_decompiled_code:
__int64 func5()
{
int *v0; // rbx
__int64 result; // rax

v0 = sigs;
do
{
result = (__int64)func3(*v0);
if ( !result )
result = func4(*v0, (v0[1] & 4) == 0);
v0 += 2;
}
while ( v0 != (int *)920 );
return result;
}

original_code:
static void
noteinit(void)
{
 int i;
 Sig *sig;
 for(i=0; i<(sizeof(sigs)/sizeof((sigs)[0])); i++){
  sig = &sigs[i];
  if(handler(sig->sig) != ((__sighandler_t) 0))
   continue;
  notifyseton(sig->sig, !(sig->flags&NoNotify));
 }
}

canonical_original_code:
static void noteinit()
{
 int i;
 struct Sig *sig;
 for(i=0; i<(sizeof(sigs)/sizeof((sigs)[0])); i++){
  sig = &sigs[i];
  if(handler(sig->sig) != ((void (*)(int)) 0))
   continue;
  notifyseton(sig->sig, !(sig->flags&NoNotify));
 }
}


signotify

decompiled_code:
int __fastcall signotify(unsigned int a1)
{
struct __jmp_buf_tag *v1; // rax
int *v2; // rax
void (__fastcall *v3)(_QWORD, __int64); // rbx
__int64 v4; // rax
char v6[72]; // [rsp+10h] [rbp-48h] BYREF

v1 = (struct __jmp_buf_tag *)notejmpbuf();
LODWORD(v2) = _sigsetjmp(v1, 1);
if ( (_DWORD)v2 != 1 )
{
if ( (_DWORD)v2 == 2 || (_DWORD)v2 )
return (int)v2;
v3 = (void (__fastcall *)(_QWORD, __int64))notifyf;
if ( notifyf )
{
v4 = p9sigstr(a1, v6);
v3(0LL, v4);
}
}
v2 = findsig(a1);
if ( !v2 || (v2[1] & 2) == 0 )
{
signal(a1, 0LL);
raise(a1);
exit(1);
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
struct __jmp_buf_tag *v1; // rax
int *v2; // rax
void (__fastcall *v3)(_QWORD, __int64); // rbx
__int64 v4; // rax
char v6[72]; // [rsp+10h] [rbp-48h] BYREF

v1 = (struct __jmp_buf_tag *)notejmpbuf();
LODWORD(v2) = _sigsetjmp(v1, 1);
if ( (_DWORD)v2 != 1 )
{
if ( (_DWORD)v2 == 2 || (_DWORD)v2 )
return (int)v2;
v3 = (void (__fastcall *)(_QWORD, __int64))notifyf;
if ( notifyf )
{
v4 = p9sigstr(a1, v6);
v3(0LL, v4);
}
}
v2 = func0(a1);
if ( !v2 || (v2[1] & 2) == 0 )
{
signal(a1, 0LL);
raise(a1);
exit(1);
}
return (int)v2;
}

original_code:
static void
signotify(int sig)
{
 char tmp[64];
 Jmp *j;
 Sig *s;
 j = (*_notejmpbuf)();
 switch(__sigsetjmp ((void*)(j->b), 1)){
 case 0:
  if(notifyf)
   (*notifyf)(((void*)0), _p9sigstr(sig, tmp));
 case 1:
  if(0)print("DEFAULT %d\n", sig);
  s = findsig(sig);
  if(s && (s->flags&Ignore))
   return;
  signal(sig, ((__sighandler_t) 0));
  raise(sig);
  _exit(1);
 case 2:
  if(0)print("HANDLED %d\n", sig);
  return;
 }
}

canonical_original_code:
static void signotify(int sig)
{
 char tmp[64];
 struct Jmp *j;
 struct Sig *s;
 j = (*_notejmpbuf)();
 switch(__sigsetjmp ((void *)(j->b), 1)){
 case 0:
  if(notifyf)
   (*notifyf)(((void *)0), _p9sigstr(sig, tmp));
 case 1:
  if(0)print("DEFAULT %d\n", sig);
  s = findsig(sig);
  if(s && (s->flags&Ignore))
   return;
  signal(sig, ((void (*)(int)) 0));
  raise(sig);
  _exit(1);
 case 2:
  if(0)print("HANDLED %d\n", sig);
  return;
 }
}

variable_types:
tmp
char [64]

variable_types:
j
struct Jmp { long b[-1]; } *

variable_types:
s
struct Sig { int sig; int flags; } *

user_defined_types:
struct Jmp { long b[-1]; }
struct Sig { int sig; int flags; }


notesetenable

decompiled_code:
__int64 __fastcall notesetenable(int signo, int a2)
{
__int64 result; // rax
sigset_t v3; // [rsp-80h] [rbp-118h] BYREF
sigset_t set; // [rsp+0h] [rbp-98h] BYREF

result = 0xFFFFFFFFLL;
if ( signo )
{
sigemptyset(&set);
sigaddset(&set, signo);
sigprocmask(a2 != 0, &set, &v3);
result = sigismember(&v3, signo) == 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int signo, int a2)
{
__int64 result; // rax
sigset_t v3; // [rsp-80h] [rbp-118h] BYREF
sigset_t set; // [rsp+0h] [rbp-98h] BYREF

result = 0xFFFFFFFFLL;
if ( signo )
{
sigemptyset(&set);
sigaddset(&set, signo);
sigprocmask(a2 != 0, &set, &v3);
result = sigismember(&v3, signo) == 0;
}
return result;
}

original_code:
static int
notesetenable(int sig, int enabled)
{
 sigset_t mask, omask;
 if(sig == 0)
  return -1;
 sigemptyset(&mask);
 sigaddset(&mask, sig);
 sigprocmask(enabled ? 1 : 0, &mask, &omask);
 return !sigismember(&omask, sig);
}

canonical_original_code:
static int notesetenable(int sig, int enabled)
{
 struct __sigset_t mask; struct __sigset_t omask;
 if(sig == 0)
  return -1;
 sigemptyset(&mask);
 sigaddset(&mask, sig);
 sigprocmask(enabled ? 1 : 0, &mask, &omask);
 return !sigismember(&omask, sig);
}

variable_types: enabled int

variable_types: struct __sigset_t { unsigned long __val[-1]; }


noted

decompiled_code:
void __fastcall __noreturn noted(int a1)
{
__int64 v1; // rax

v1 = notejmpbuf();
p9longjmp(v1, (unsigned int)(a1 == 0) + 1);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func8(int a1)
{
__int64 v1; // rax

v1 = notejmpbuf();
p9longjmp(v1, (unsigned int)(a1 == 0) + 1);
abort();
}

original_code:
int
noted(int v)
{
 p9longjmp((*_notejmpbuf)()->b, v==0 ? 2 : 1);
 abort();
 return 0;
}

variable_types: v int


notify

decompiled_code:
__int64 __fastcall notify(__int64 a1)
{
notifyf = a1;
if ( !init_0 )
{
init_0 = 1;
noteinit();
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
notifyf = a1;
if ( !init_0 )
{
init_0 = 1;
func5();
}
return 0LL;
}

original_code:
int
notify(void (*f)(void*, char*))
{
 static int init;
 notifyf = f;
 if(!init){
  init = 1;
  noteinit();
 }
 return 0;
}

canonical_original_code:
int notify(void (*f)(void *, char *))
{
 static int init;
 notifyf = f;
 if(!init){
  init = 1;
  noteinit();
 }
 return 0;
}

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

variable_types: init int


noteenable

decompiled_code:
__int64 noteenable()
{
int v0; // eax

v0 = p9strsig();
return notesetenable(v0, 1);
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // eax

v0 = p9strsig();
return func7(v0, 1);
}

original_code:
int
noteenable(char *msg)
{
 return notesetenable(_p9strsig(msg), 1);
}

variable_types:
msg
char *


notedisable

decompiled_code:
__int64 notedisable()
{
int v0; // eax

v0 = p9strsig();
return notesetenable(v0, 0);
}

canonical_decompiled_code:
__int64 func11()
{
int v0; // eax

v0 = p9strsig();
return func7(v0, 0);
}

original_code:
int
notedisable(char *msg)
{
 return notesetenable(_p9strsig(msg), 0);
}


notifyon

decompiled_code:
__int64 notifyon()
{
int v0; // eax

v0 = p9strsig();
return notifyseton(v0, 1);
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // eax

v0 = p9strsig();
return func4(v0, 1);
}

original_code:
int
notifyon(char *msg)
{
 return notifyseton(_p9strsig(msg), 1);
}


notifyoff

decompiled_code:
__int64 notifyoff()
{
int v0; // eax

v0 = p9strsig();
return notifyseton(v0, 0);
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // eax

v0 = p9strsig();
return func4(v0, 0);
}

original_code:
int
notifyoff(char *msg)
{
 return notifyseton(_p9strsig(msg), 0);
}


deinstall

decompiled_code:
char *__fastcall deinstall(__int64 a1)
{
char *result; // rax

result = (char *)&wbufs;
do
{
if ( *(_QWORD *)result == a1 )
*(_QWORD *)result = 0LL;
result += 8;
}
while ( result != "Bopen: unknown mode %d\n" );
return result;
}

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

result = (char *)&wbufs;
do
{
if ( *(_QWORD *)result == a1 )
*(_QWORD *)result = 0LL;
result += 8;
}
while ( result != "Bopen: unknown mode %d\n" );
return result;
}

original_code:
static
void
deinstall(Biobuf *bp)
{
 int i;
 for(i=0; i<MAXBUFS; i++)
  if(wbufs[i] == bp)
   wbufs[i] = 0;
}

canonical_original_code:
static void deinstall(struct Biobuf *bp)
{
 int i;
 for(i=0; i<MAXBUFS; i++)
  if(wbufs[i] == bp)
   wbufs[i] = 0;
}

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


install

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

deinstall(a1);
result = 0LL;
while ( wbufs[result] )
{
if ( ++result == 20 )
goto LABEL_6;
}
wbufs[(int)result] = a1;
LABEL_6:
if ( !atexitflag )
{
atexitflag = 1;
result = p9atexit(batexit);
}
return result;
}

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

func0(a1);
result = 0LL;
while ( wbufs[result] )
{
if ( ++result == 20 )
goto LABEL_6;
}
wbufs[(int)result] = a1;
LABEL_6:
if ( !atexitflag )
{
atexitflag = 1;
result = p9atexit(batexit);
}
return result;
}

original_code:
static
void
install(Biobuf *bp)
{
 int i;
 deinstall(bp);
 for(i=0; i<MAXBUFS; i++)
  if(wbufs[i] == 0) {
   wbufs[i] = bp;
   break;
  }
 if(atexitflag == 0) {
  atexitflag = 1;
  p9atexit(batexit);
 }
}

canonical_original_code:
static void install(struct Biobuf *bp)
{
 int i;
 deinstall(bp);
 for(i=0; i<MAXBUFS; i++)
  if(wbufs[i] == 0) {
   wbufs[i] = bp;
   break;
  }
 if(atexitflag == 0) {
  atexitflag = 1;
  p9atexit(batexit);
 }
}


batexit

decompiled_code:
__int64 batexit()
{
char *v0; // rbx
__int64 result; // rax

v0 = (char *)wbufs;
do
{
if ( *(_QWORD *)v0 )
{
*(_QWORD *)v0 = 0LL;
result = Bflush();
}
v0 += 8;
}
while ( v0 != "Bopen: unknown mode %d\n" );
return result;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rbx
__int64 result; // rax

v0 = (char *)wbufs;
do
{
if ( *(_QWORD *)v0 )
{
*(_QWORD *)v0 = 0LL;
result = Bflush();
}
v0 += 8;
}
while ( v0 != "Bopen: unknown mode %d\n" );
return result;
}

original_code:
static
void
batexit(void)
{
 Biobuf *bp;
 int i;
 for(i=0; i<MAXBUFS; i++) {
  bp = wbufs[i];
  if(bp != 0) {
   wbufs[i] = 0;
   Bflush(bp);
  }
 }
}

canonical_original_code:
static void batexit()
{
 struct Biobuf *bp;
 int i;
 for(i=0; i<MAXBUFS; i++) {
  bp = wbufs[i];
  if(bp != 0) {
   wbufs[i] = 0;
   Bflush(bp);
  }
 }
}


Binits

original_code:
int
Binits(Biobuf *bp, int f, int mode, unsigned char *p, int size)
{
 p += Bungetsize;
 size -= Bungetsize;
 switch(mode&~(32|64|16)) {
 default:
  fprint(2, "Bopen: unknown mode %d\n", mode);
  return Beof;
 case 0:
  bp->state = Bractive;
  bp->ocount = 0;
  break;
 case 1:
  install(bp);
  bp->state = Bwactive;
  bp->ocount = -size;
  break;
 }
 bp->bbuf = p;
 bp->ebuf = p+size;
 bp->bsize = size;
 bp->icount = 0;
 bp->gbuf = bp->ebuf;
 bp->fid = f;
 bp->flag = 0;
 bp->rdline = 0;
 bp->offset = 0;
 bp->runesize = 0;
 return 0;
}

canonical_original_code:
int Binits(struct Biobuf *bp, int f, int mode, unsigned char *p, int size)
{
 p += Bungetsize;
 size -= Bungetsize;
 switch(mode&~(32|64|16)) {
 default:
  fprint(2, "Bopen: unknown mode %d\n", mode);
  return Beof;
 case 0:
  bp->state = Bractive;
  bp->ocount = 0;
  break;
 case 1:
  install(bp);
  bp->state = Bwactive;
  bp->ocount = -size;
  break;
 }
 bp->bbuf = p;
 bp->ebuf = p+size;
 bp->bsize = size;
 bp->icount = 0;
 bp->gbuf = bp->ebuf;
 bp->fid = f;
 bp->flag = 0;
 bp->rdline = 0;
 bp->offset = 0;
 bp->runesize = 0;
 return 0;
}

variable_types: f int

variable_types: mode int

variable_types:
p
unsigned char *

variable_types: size int


Binit

decompiled_code:
__int64 __fastcall Binit(__int64 a1, int a2, __int64 a3)
{
return Binits(a1, a2, a3, a1 + 72, 8196);
}

original_code:
int
Binit(Biobuf *bp, int f, int mode)
{
 return Binits(bp, f, mode, bp->b, sizeof(bp->b));
}

canonical_original_code:
int Binit(struct Biobuf *bp, int f, int mode)
{
 return Binits(bp, f, mode, bp->b, sizeof(bp->b));
}

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


Bfdopen

original_code:
Biobuf*
Bfdopen(int f, int mode)
{
 Biobuf *bp;
 bp = p9malloc(sizeof(Biobuf));
 if(bp == 0)
  return 0;
 Binits(bp, f, mode, bp->b, sizeof(bp->b));
 bp->flag = Bmagic;
 return bp;
}

canonical_original_code:
struct Biobuf *Bfdopen(int f, int mode)
{
 struct Biobuf *bp;
 bp = p9malloc(sizeof(Biobuf));
 if(bp == 0)
  return 0;
 Binits(bp, f, mode, bp->b, sizeof(bp->b));
 bp->flag = Bmagic;
 return bp;
}

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


Bopen

decompiled_code:
__int64 __fastcall Bopen(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // ebp

if ( (a2 & 0xFFFFFF8F) != 0 )
{
if ( (a2 & 0xFFFFFF8F) != 1 )
{
fprint(2LL, "Bopen: unknown mode %d\n", (unsigned int)a2);
return 0LL;
}
v3 = p9create(a1, a2, 438LL);
if ( v3 < 0 )
return 0LL;
}
else
{
v3 = p9open();
if ( v3 < 0 )
return 0LL;
}
v2 = Bfdopen(v3, a2);
if ( !v2 )
close(v3);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int v3; // ebp

if ( (a2 & 0xFFFFFF8F) != 0 )
{
if ( (a2 & 0xFFFFFF8F) != 1 )
{
fprint(2LL, "Bopen: unknown mode %d\n", (unsigned int)a2);
return 0LL;
}
v3 = p9create(a1, a2, 438LL);
if ( v3 < 0 )
return 0LL;
}
else
{
v3 = p9open();
if ( v3 < 0 )
return 0LL;
}
v2 = func5(v3, a2);
if ( !v2 )
close(v3);
return v2;
}

original_code:
Biobuf*
Bopen(char *name, int mode)
{
 Biobuf *bp;
 int f;
 switch(mode&~(32|64|16)) {
 default:
  fprint(2, "Bopen: unknown mode %d\n", mode);
  return 0;
 case 0:
  f = p9open(name, mode);
  if(f < 0)
   return 0;
  break;
 case 1:
  f = p9create(name, mode, 0666);
  if(f < 0)
   return 0;
 }
 bp = Bfdopen(f, mode);
 if(bp == 0)
  close(f);
 return bp;
}

canonical_original_code:
struct Biobuf *Bopen(char *name, int mode)
{
 struct Biobuf *bp;
 int f;
 switch(mode&~(32|64|16)) {
 default:
  fprint(2, "Bopen: unknown mode %d\n", mode);
  return 0;
 case 0:
  f = p9open(name, mode);
  if(f < 0)
   return 0;
  break;
 case 1:
  f = p9create(name, mode, 0666);
  if(f < 0)
   return 0;
 }
 bp = Bfdopen(f, mode);
 if(bp == 0)
  close(f);
 return bp;
}

variable_types:
name
char *


Bterm

original_code:
int
Bterm(Biobuf *bp)
{
 deinstall(bp);
 Bflush(bp);
 if(bp->flag == Bmagic) {
  bp->flag = 0;
  close(bp->fid);
  p9free(bp);
 }
 return 0;
}

canonical_original_code:
int Bterm(struct Biobuf *bp)
{
 deinstall(bp);
 Bflush(bp);
 if(bp->flag == Bmagic) {
  bp->flag = 0;
  close(bp->fid);
  p9free(bp);
 }
 return 0;
}