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
{
while ( *(_QWORD *)result != a1 )
{
result += 8;
if ( result == "Bopen: unknown mode %d\n" )
return result;
}
*(_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
{
while ( *(_QWORD *)result != a1 )
{
result += 8;
if ( result == "Bopen: unknown mode %d\n" )
return result;
}
*(_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;
}

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

return_type: void


install

decompiled_code:
__int64 __fastcall install(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

deinstall(a1);
v2 = 0LL;
while ( 1 )
{
v3 = (int)v2;
if ( !wbufs[v2] )
break;
if ( ++v2 == 20 )
goto LABEL_5;
}
wbufs[(int)v2] = a1;
LABEL_5:
result = (unsigned int)atexitflag;
if ( !atexitflag )
{
atexitflag = 1;
result = p9atexit(batexit, a2, v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax

func0(a1);
v2 = 0LL;
while ( 1 )
{
v3 = (int)v2;
if ( !wbufs[v2] )
break;
if ( ++v2 == 20 )
goto LABEL_5;
}
wbufs[(int)v2] = a1;
LABEL_5:
result = (unsigned int)atexitflag;
if ( !atexitflag )
{
atexitflag = 1;
result = p9atexit(batexit, a2, v3);
}
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);
 }
}

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


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

return_type: int


Binit

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


Bfdopen

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

v2 = p9malloc(8272LL);
v3 = v2;
if ( v2 )
{
Binits(v2, a1, a2, v2 + 72, 8196);
*(_DWORD *)(v3 + 24) = 3227993;
}
return v3;
}

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

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // r12
int v4; // er13

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

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


qstrfmt

decompiled_code:
__int64 __fastcall qstrfmt(unsigned __int8 *a1, unsigned __int8 *a2, int *a3, __int64 a4)
{
unsigned __int8 *v4; // r12
__int64 v6; // rax
_BYTE *v7; // r15
_DWORD *v8; // r14
_DWORD *v9; // rax
unsigned __int64 v10; // rax
_BYTE *v11; // rbx
int v12; // ebx
unsigned int *v13; // rax
_BYTE *v14; // r14
unsigned __int8 *v15; // r15
unsigned int *v16; // r13
unsigned int *v17; // rsi
unsigned int v18; // eax
int v19; // eax
char v20; // al
_DWORD *v21; // rax
__int64 v22; // rdx
__int64 result; // rax
unsigned int v24; // eax
unsigned int v25; // eax
unsigned int v26; // eax
unsigned int v27; // eax
unsigned int v28; // eax
__int64 v29; // rax
unsigned __int64 v30; // [rsp+8h] [rbp-80h]
unsigned __int64 v31; // [rsp+10h] [rbp-78h]
unsigned __int8 *v32; // [rsp+18h] [rbp-70h]
unsigned __int64 v33; // [rsp+20h] [rbp-68h]
__int64 v35; // [rsp+30h] [rbp-58h]
int v36; // [rsp+3Ch] [rbp-4Ch]
unsigned int v37; // [rsp+48h] [rbp-40h] BYREF
int v38[15]; // [rsp+4Ch] [rbp-3Ch] BYREF

v4 = a2;
v32 = &a1[a3[2]];
v36 = 0;
v33 = (unsigned __int64)&a2[4 * a3[1]];
if ( (*(_QWORD *)(a4 + 96) & 1) != 0 )
v36 = *(_DWORD *)(a4 + 84);
v6 = *(_QWORD *)(a4 + 96) & 2LL;
v35 = v6;
if ( *(_BYTE *)a4 )
{
if ( v6 )
{
v7 = *(_BYTE **)(a4 + 16);
v30 = *(_QWORD *)(a4 + 24);
LABEL_6:
v8 = v7 + 4;
v9 = v7;
v31 = v30;
if ( (unsigned __int64)(v7 + 4) > v30 )
{
v9 = (_DWORD *)_fmtflush(a4, v7, 4LL);
if ( !v9 )
return 0xFFFFFFFFLL;
v8 = v9 + 1;
v31 = *(_QWORD *)(a4 + 24);
}
*v9 = 39;
goto LABEL_12;
}
if ( (int)_rfmtpad(a4, (unsigned int)(v36 - a3[3])) < 0 )
return 0xFFFFFFFFLL;
}
else
{
if ( v6 )
{
v8 = *(_DWORD **)(a4 + 16);
v10 = *(_QWORD *)(a4 + 24);
goto LABEL_10;
}
if ( (int)_fmtpad(a4, (unsigned int)(v36 - a3[4])) < 0 )
return 0xFFFFFFFFLL;
}
v10 = *(_QWORD *)(a4 + 24);
v8 = *(_DWORD **)(a4 + 16);
v30 = v10;
if ( *(_BYTE *)a4 )
{
v7 = *(_BYTE **)(a4 + 16);
goto LABEL_6;
}
LABEL_10:
v31 = v10;
v11 = v8;
v30 = v10;
if ( v10 < (unsigned __int64)(v8 + 1) )
{
v27 = runelen(39LL);
if ( v31 < (unsigned __int64)v8 + (int)v27 )
{
v11 = (_BYTE *)_fmtflush(a4, v8, v27);
if ( !v11 )
return 0xFFFFFFFFLL;
v30 = *(_QWORD *)(a4 + 24);
}
}
*v11 = 39;
v7 = v11 + 1;
LABEL_12:
v12 = a3[1];
if ( v12 <= 0 )
goto LABEL_29;
v13 = v8;
v14 = v7;
v15 = a1;
v16 = v13;
while ( !a1 )
{
if ( v33 <= (unsigned __int64)v4 )
goto LABEL_28;
v24 = *v4;
v4 += 4;
v37 = v24;
LABEL_21:
if ( *(_BYTE *)a4 )
{
v17 = v16 + 1;
if ( (unsigned __int64)(v16 + 1) > v31 )
{
v16 = (unsigned int *)_fmtflush(a4, v16, 4LL);
if ( !v16 )
return 0xFFFFFFFFLL;
v17 = v16 + 1;
v31 = *(_QWORD *)(a4 + 24);
}
v18 = v37;
*v16 = v37;
if ( v18 == 39 )
{
if ( v31 < (unsigned __int64)(v16 + 2) )
{
v17 = (unsigned int *)_fmtflush(a4, v17, 4LL);
if ( !v17 )
return 0xFFFFFFFFLL;
v31 = *(_QWORD *)(a4 + 24);
}
v16 = v17 + 1;
*v17 = v37;
}
else
{
v16 = v17;
}
goto LABEL_17;
}
if ( v30 >= (unsigned __int64)(v14 + 4) || (v25 = runelen(v37), v30 >= (unsigned __int64)&v14[v25]) )
{
v19 = v37;
if ( v37 > 0x7F )
goto LABEL_43;
}
else
{
v14 = (_BYTE *)_fmtflush(a4, v14, v25);
if ( !v14 )
return 0xFFFFFFFFLL;
v30 = *(_QWORD *)(a4 + 24);
v19 = v37;
if ( v37 > 0x7F )
{
LABEL_43:
v38[0] = v19;
v14 += (int)runetochar(v14, v38);
goto LABEL_25;
}
}
*v14++ = v19;
LABEL_25:
v20 = v37;
if ( v37 == 39 )
{
if ( v30 < (unsigned __int64)(v14 + 4) )
{
v26 = runelen(39LL);
if ( v30 < (unsigned __int64)&v14[v26] )
{
v14 = (_BYTE *)_fmtflush(a4, v14, v26);
if ( !v14 )
return 0xFFFFFFFFLL;
v30 = *(_QWORD *)(a4 + 24);
}
v20 = v37;
if ( v37 > 0x7F )
{
v38[0] = v37;
v14 += (int)runetochar(v14, v38);
goto LABEL_17;
}
}
*v14++ = v20;
if ( !--v12 )
goto LABEL_28;
}
else
{
LABEL_17:
if ( !--v12 )
goto LABEL_28;
}
}
v37 = *v15;
if ( v37 <= 0x7F )
{
++v15;
goto LABEL_21;
}
if ( v32 - v15 > 3 || (unsigned int)fullrune(v15) )
{
v15 += (int)chartorune(&v37, v15);
goto LABEL_21;
}
LABEL_28:
v7 = v14;
v8 = v16;
LABEL_29:
if ( *(_BYTE *)a4 )
{
v21 = v8 + 1;
if ( (unsigned __int64)(v8 + 1) <= v31 )
goto LABEL_31;
v29 = _fmtflush(a4, v8, 4LL);
v8 = (_DWORD *)v29;
if ( v29 )
{
v21 = (_DWORD *)(v29 + 4);
LABEL_31:
v22 = (__int64)v21 - *(_QWORD *)(a4 + 16);
*v8 = 39;
*(_DWORD *)(a4 + 48) += v22 >> 2;
*(_QWORD *)(a4 + 16) = v21;
if ( v35 )
result = (unsigned int)((int)_rfmtpad(a4, (unsigned int)(v36 - a3[3])) >> 31);
else
LABEL_32:
result = 0LL;
return result;
}
return 0xFFFFFFFFLL;
}
if ( v30 < (unsigned __int64)(v7 + 4) )
{
v28 = runelen(39LL);
if ( v30 < (unsigned __int64)&v7[v28] )
{
v7 = (_BYTE *)_fmtflush(a4, v7, v28);
if ( !v7 )
return 0xFFFFFFFFLL;
}
}
*v7 = 39;
*(_DWORD *)(a4 + 48) += (_DWORD)v7 + 1 - *(_DWORD *)(a4 + 16);
*(_QWORD *)(a4 + 16) = v7 + 1;
if ( !v35 )
goto LABEL_32;
return (unsigned int)((int)_fmtpad(a4, (unsigned int)(v36 - a3[4])) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, unsigned __int8 *a2, int *a3, __int64 a4)
{
unsigned __int8 *v4; // r12
__int64 v6; // rax
_BYTE *v7; // r15
_DWORD *v8; // r14
_DWORD *v9; // rax
unsigned __int64 v10; // rax
_BYTE *v11; // rbx
int v12; // ebx
unsigned int *v13; // rax
_BYTE *v14; // r14
unsigned __int8 *v15; // r15
unsigned int *v16; // r13
unsigned int *v17; // rsi
unsigned int v18; // eax
int v19; // eax
char v20; // al
_DWORD *v21; // rax
__int64 v22; // rdx
__int64 result; // rax
unsigned int v24; // eax
unsigned int v25; // eax
unsigned int v26; // eax
unsigned int v27; // eax
unsigned int v28; // eax
__int64 v29; // rax
unsigned __int64 v30; // [rsp+8h] [rbp-80h]
unsigned __int64 v31; // [rsp+10h] [rbp-78h]
unsigned __int8 *v32; // [rsp+18h] [rbp-70h]
unsigned __int64 v33; // [rsp+20h] [rbp-68h]
__int64 v35; // [rsp+30h] [rbp-58h]
int v36; // [rsp+3Ch] [rbp-4Ch]
unsigned int v37; // [rsp+48h] [rbp-40h] BYREF
int v38[15]; // [rsp+4Ch] [rbp-3Ch] BYREF

v4 = a2;
v32 = &a1[a3[2]];
v36 = 0;
v33 = (unsigned __int64)&a2[4 * a3[1]];
if ( (*(_QWORD *)(a4 + 96) & 1) != 0 )
v36 = *(_DWORD *)(a4 + 84);
v6 = *(_QWORD *)(a4 + 96) & 2LL;
v35 = v6;
if ( *(_BYTE *)a4 )
{
if ( v6 )
{
v7 = *(_BYTE **)(a4 + 16);
v30 = *(_QWORD *)(a4 + 24);
LABEL_6:
v8 = v7 + 4;
v9 = v7;
v31 = v30;
if ( (unsigned __int64)(v7 + 4) > v30 )
{
v9 = (_DWORD *)_fmtflush(a4, v7, 4LL);
if ( !v9 )
return 0xFFFFFFFFLL;
v8 = v9 + 1;
v31 = *(_QWORD *)(a4 + 24);
}
*v9 = 39;
goto LABEL_12;
}
if ( (int)_rfmtpad(a4, (unsigned int)(v36 - a3[3])) < 0 )
return 0xFFFFFFFFLL;
}
else
{
if ( v6 )
{
v8 = *(_DWORD **)(a4 + 16);
v10 = *(_QWORD *)(a4 + 24);
goto LABEL_10;
}
if ( (int)_fmtpad(a4, (unsigned int)(v36 - a3[4])) < 0 )
return 0xFFFFFFFFLL;
}
v10 = *(_QWORD *)(a4 + 24);
v8 = *(_DWORD **)(a4 + 16);
v30 = v10;
if ( *(_BYTE *)a4 )
{
v7 = *(_BYTE **)(a4 + 16);
goto LABEL_6;
}
LABEL_10:
v31 = v10;
v11 = v8;
v30 = v10;
if ( v10 < (unsigned __int64)(v8 + 1) )
{
v27 = runelen(39LL);
if ( v31 < (unsigned __int64)v8 + (int)v27 )
{
v11 = (_BYTE *)_fmtflush(a4, v8, v27);
if ( !v11 )
return 0xFFFFFFFFLL;
v30 = *(_QWORD *)(a4 + 24);
}
}
*v11 = 39;
v7 = v11 + 1;
LABEL_12:
v12 = a3[1];
if ( v12 <= 0 )
goto LABEL_29;
v13 = v8;
v14 = v7;
v15 = a1;
v16 = v13;
while ( !a1 )
{
if ( v33 <= (unsigned __int64)v4 )
goto LABEL_28;
v24 = *v4;
v4 += 4;
v37 = v24;
LABEL_21:
if ( *(_BYTE *)a4 )
{
v17 = v16 + 1;
if ( (unsigned __int64)(v16 + 1) > v31 )
{
v16 = (unsigned int *)_fmtflush(a4, v16, 4LL);
if ( !v16 )
return 0xFFFFFFFFLL;
v17 = v16 + 1;
v31 = *(_QWORD *)(a4 + 24);
}
v18 = v37;
*v16 = v37;
if ( v18 == 39 )
{
if ( v31 < (unsigned __int64)(v16 + 2) )
{
v17 = (unsigned int *)_fmtflush(a4, v17, 4LL);
if ( !v17 )
return 0xFFFFFFFFLL;
v31 = *(_QWORD *)(a4 + 24);
}
v16 = v17 + 1;
*v17 = v37;
}
else
{
v16 = v17;
}
goto LABEL_17;
}
if ( v30 >= (unsigned __int64)(v14 + 4) || (v25 = runelen(v37), v30 >= (unsigned __int64)&v14[v25]) )
{
v19 = v37;
if ( v37 > 0x7F )
goto LABEL_43;
}
else
{
v14 = (_BYTE *)_fmtflush(a4, v14, v25);
if ( !v14 )
return 0xFFFFFFFFLL;
v30 = *(_QWORD *)(a4 + 24);
v19 = v37;
if ( v37 > 0x7F )
{
LABEL_43:
v38[0] = v19;
v14 += (int)runetochar(v14, v38);
goto LABEL_25;
}
}
*v14++ = v19;
LABEL_25:
v20 = v37;
if ( v37 == 39 )
{
if ( v30 < (unsigned __int64)(v14 + 4) )
{
v26 = runelen(39LL);
if ( v30 < (unsigned __int64)&v14[v26] )
{
v14 = (_BYTE *)_fmtflush(a4, v14, v26);
if ( !v14 )
return 0xFFFFFFFFLL;
v30 = *(_QWORD *)(a4 + 24);
}
v20 = v37;
if ( v37 > 0x7F )
{
v38[0] = v37;
v14 += (int)runetochar(v14, v38);
goto LABEL_17;
}
}
*v14++ = v20;
if ( !--v12 )
goto LABEL_28;
}
else
{
LABEL_17:
if ( !--v12 )
goto LABEL_28;
}
}
v37 = *v15;
if ( v37 <= 0x7F )
{
++v15;
goto LABEL_21;
}
if ( v32 - v15 > 3 || (unsigned int)fullrune(v15) )
{
v15 += (int)chartorune(&v37, v15);
goto LABEL_21;
}
LABEL_28:
v7 = v14;
v8 = v16;
LABEL_29:
if ( *(_BYTE *)a4 )
{
v21 = v8 + 1;
if ( (unsigned __int64)(v8 + 1) <= v31 )
goto LABEL_31;
v29 = _fmtflush(a4, v8, 4LL);
v8 = (_DWORD *)v29;
if ( v29 )
{
v21 = (_DWORD *)(v29 + 4);
LABEL_31:
v22 = (__int64)v21 - *(_QWORD *)(a4 + 16);
*v8 = 39;
*(_DWORD *)(a4 + 48) += v22 >> 2;
*(_QWORD *)(a4 + 16) = v21;
if ( v35 )
result = (unsigned int)((int)_rfmtpad(a4, (unsigned int)(v36 - a3[3])) >> 31);
else
LABEL_32:
result = 0LL;
return result;
}
return 0xFFFFFFFFLL;
}
if ( v30 < (unsigned __int64)(v7 + 4) )
{
v28 = runelen(39LL);
if ( v30 < (unsigned __int64)&v7[v28] )
{
v7 = (_BYTE *)_fmtflush(a4, v7, v28);
if ( !v7 )
return 0xFFFFFFFFLL;
}
}
*v7 = 39;
*(_DWORD *)(a4 + 48) += (_DWORD)v7 + 1 - *(_DWORD *)(a4 + 16);
*(_QWORD *)(a4 + 16) = v7 + 1;
if ( !v35 )
goto LABEL_32;
return (unsigned int)((int)_fmtpad(a4, (unsigned int)(v36 - a3[4])) >> 31);
}

original_code:
static int
qstrfmt(char *sin, Rune *rin, Quoteinfo *q, Fmt *f)
{
 Rune r, *rm, *rme;
 char *t, *s, *m, *me;
 Rune *rt, *rs;
 _fmtulong fl;
 int nc, w;
 m = sin;
 me = m + q->nbytesin;
 rm = rin;
 rme = rm + q->nrunesin;
 fl = f->flags;
 w = 0;
 if(fl & FmtWidth)
  w = f->width;
 if(f->runes){
  if(!(fl & FmtLeft) && __rfmtpad(f, w - q->nrunesout) < 0)
   return -1;
 }else{
  if(!(fl & FmtLeft) && __fmtpad(f, w - q->nbytesout) < 0)
   return -1;
 }
 t = (char*)f->to;
 s = (char*)f->stop;
 rt = (Rune*)f->to;
 rs = (Rune*)f->stop;
 if(f->runes)
  do{ if(rt + 1 > (Rune*)rs){ rt = (Rune*)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) rs = (Rune*)f->stop; else return -1; } *rt++ = '\''; }while(0);
 else
  do{ Rune _rune; int _runelen; if(t + UTFmax > (char*)s && t + (_runelen = runelen('\'')) > (char*)s){ t = (char*)__fmtflush(f, t, _runelen); if(t != 0) s = (char*)f->stop; else return -1; } if('\'' < Runeself) *t++ = '\''; else{ _rune = '\''; t += runetochar(t, &_rune); } }while(0);
 for(nc = q->nrunesin; nc > 0; nc--){
  if(sin){
   r = *(_fmtuchar*)m;
   if(r < Runeself)
    m++;
   else if((me - m) >= UTFmax || fullrune(m, me-m))
    m += chartorune(&r, m);
   else
    break;
  }else{
   if(rm >= rme)
    break;
   r = *(_fmtuchar*)rm++;
  }
  if(f->runes){
   do{ if(rt + 1 > (Rune*)rs){ rt = (Rune*)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) rs = (Rune*)f->stop; else return -1; } *rt++ = r; }while(0);
   if(r == '\'')
    do{ if(rt + 1 > (Rune*)rs){ rt = (Rune*)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) rs = (Rune*)f->stop; else return -1; } *rt++ = r; }while(0);
  }else{
   do{ Rune _rune; int _runelen; if(t + UTFmax > (char*)s && t + (_runelen = runelen(r)) > (char*)s){ t = (char*)__fmtflush(f, t, _runelen); if(t != 0) s = (char*)f->stop; else return -1; } if(r < Runeself) *t++ = r; else{ _rune = r; t += runetochar(t, &_rune); } }while(0);
   if(r == '\'')
    do{ Rune _rune; int _runelen; if(t + UTFmax > (char*)s && t + (_runelen = runelen(r)) > (char*)s){ t = (char*)__fmtflush(f, t, _runelen); if(t != 0) s = (char*)f->stop; else return -1; } if(r < Runeself) *t++ = r; else{ _rune = r; t += runetochar(t, &_rune); } }while(0);
  }
 }
 if(f->runes){
  do{ if(rt + 1 > (Rune*)rs){ rt = (Rune*)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) rs = (Rune*)f->stop; else return -1; } *rt++ = '\''; }while(0);
  if(rs);else;
  f->nfmt += rt - (Rune *)f->to;
  f->to = rt;
  if(fl & FmtLeft && __rfmtpad(f, w - q->nrunesout) < 0)
   return -1;
 }else{
  do{ Rune _rune; int _runelen; if(t + UTFmax > (char*)s && t + (_runelen = runelen('\'')) > (char*)s){ t = (char*)__fmtflush(f, t, _runelen); if(t != 0) s = (char*)f->stop; else return -1; } if('\'' < Runeself) *t++ = '\''; else{ _rune = '\''; t += runetochar(t, &_rune); } }while(0);
  if(s);else;
  f->nfmt += t - (char *)f->to;
  f->to = t;
  if(fl & FmtLeft && __fmtpad(f, w - q->nbytesout) < 0)
   return -1;
 }
 return 0;
}

canonical_original_code:
static int qstrfmt(char *sin, unsigned int *rin, struct Quoteinfo *q, struct Fmt *f)
{
 unsigned int r; unsigned int *rm; unsigned int *rme;
 char *t; char *s; char *m; char *me;
 unsigned int *rt; unsigned int *rs;
 unsigned long fl;
 int nc; int w;
 m = sin;
 me = m + q->nbytesin;
 rm = rin;
 rme = rm + q->nrunesin;
 fl = f->flags;
 w = 0;
 if(fl & FmtWidth)
  w = f->width;
 if(f->runes){
  if(!(fl & FmtLeft) && __rfmtpad(f, w - q->nrunesout) < 0)
   return -1;
 }else{
  if(!(fl & FmtLeft) && __fmtpad(f, w - q->nbytesout) < 0)
   return -1;
 }
 t = (char *)f->to;
 s = (char *)f->stop;
 rt = (unsigned int *)f->to;
 rs = (unsigned int *)f->stop;
 if(f->runes)
  do{ if(rt + 1 > (unsigned int *)rs){ rt = (unsigned int *)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) rs = (unsigned int *)f->stop; else return -1; } *rt++ = '\''; }while(0);
 else
  do{ unsigned int _rune; int _runelen; if(t + UTFmax > (char *)s && t + (_runelen = runelen('\'')) > (char *)s){ t = (char *)__fmtflush(f, t, _runelen); if(t != 0) s = (char *)f->stop; else return -1; } if('\'' < Runeself) *t++ = '\''; else{ _rune = '\''; t += runetochar(t, &_rune); } }while(0);
 for(nc = q->nrunesin; nc > 0; nc--){
  if(sin){
   r = *(unsigned char *)m;
   if(r < Runeself)
    m++;
   else if((me - m) >= UTFmax || fullrune(m, me-m))
    m += chartorune(&r, m);
   else
    break;
  }else{
   if(rm >= rme)
    break;
   r = *(unsigned char *)rm++;
  }
  if(f->runes){
   do{ if(rt + 1 > (unsigned int *)rs){ rt = (unsigned int *)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) rs = (unsigned int *)f->stop; else return -1; } *rt++ = r; }while(0);
   if(r == '\'')
    do{ if(rt + 1 > (unsigned int *)rs){ rt = (unsigned int *)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) rs = (unsigned int *)f->stop; else return -1; } *rt++ = r; }while(0);
  }else{
   do{ unsigned int _rune; int _runelen; if(t + UTFmax > (char *)s && t + (_runelen = runelen(r)) > (char *)s){ t = (char *)__fmtflush(f, t, _runelen); if(t != 0) s = (char *)f->stop; else return -1; } if(r < Runeself) *t++ = r; else{ _rune = r; t += runetochar(t, &_rune); } }while(0);
   if(r == '\'')
    do{ unsigned int _rune; int _runelen; if(t + UTFmax > (char *)s && t + (_runelen = runelen(r)) > (char *)s){ t = (char *)__fmtflush(f, t, _runelen); if(t != 0) s = (char *)f->stop; else return -1; } if(r < Runeself) *t++ = r; else{ _rune = r; t += runetochar(t, &_rune); } }while(0);
  }
 }
 if(f->runes){
  do{ if(rt + 1 > (unsigned int *)rs){ rt = (unsigned int *)__fmtflush(f, rt, sizeof(Rune)); if(rt != 0) rs = (unsigned int *)f->stop; else return -1; } *rt++ = '\''; }while(0);
  if(rs);else;
  f->nfmt += rt - (unsigned int *)f->to;
  f->to = rt;
  if(fl & FmtLeft && __rfmtpad(f, w - q->nrunesout) < 0)
   return -1;
 }else{
  do{ unsigned int _rune; int _runelen; if(t + UTFmax > (char *)s && t + (_runelen = runelen('\'')) > (char *)s){ t = (char *)__fmtflush(f, t, _runelen); if(t != 0) s = (char *)f->stop; else return -1; } if('\'' < Runeself) *t++ = '\''; else{ _rune = '\''; t += runetochar(t, &_rune); } }while(0);
  if(s);else;
  f->nfmt += t - (char *)f->to;
  f->to = t;
  if(fl & FmtLeft && __fmtpad(f, w - q->nbytesout) < 0)
   return -1;
 }
 return 0;
}

variable_types:
sin
char *

variable_types:
rin
unsigned int *

variable_types: struct Quoteinfo { int quoted; int nrunesin; int nbytesin; int nrunesout; int nbytesout; } *

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
unsigned int

variable_types:
rm
unsigned int *

variable_types:
rme
unsigned int *

variable_types:
t
char *

variable_types:
s
char *

variable_types:
m
char *

variable_types:
me
char *

variable_types:
rt
unsigned int *

variable_types:
rs
unsigned int *

variable_types:
fl
unsigned long

variable_types: nc int

variable_types: w int


quotestrfmt

decompiled_code:
__int64 __fastcall quotestrfmt(unsigned __int8 *a1)
{
return _quotestrfmt(0, a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned __int8 *a1)
{
return func2(0, a1);
}

original_code:
int
quotestrfmt(Fmt *f)
{
 return __quotestrfmt(0, f);
}

canonical_original_code:
int quotestrfmt(struct Fmt *f)
{
 return __quotestrfmt(0, f);
}

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


quoterunestrfmt

decompiled_code:
__int64 __fastcall quoterunestrfmt(unsigned __int8 *a1)
{
return _quotestrfmt(1, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned __int8 *a1)
{
return func2(1, a1);
}

original_code:
int
quoterunestrfmt(Fmt *f)
{
 return __quotestrfmt(1, f);
}

canonical_original_code:
int quoterunestrfmt(struct Fmt *f)
{
 return __quotestrfmt(1, f);
}


quotefmtinstall

decompiled_code:
__int64 quotefmtinstall()
{
fmtinstall(113LL, quotestrfmt);
return fmtinstall(81LL, quoterunestrfmt);
}

canonical_decompiled_code:
__int64 func5()
{
fmtinstall(113LL, quotestrfmt);
return fmtinstall(81LL, quoterunestrfmt);
}

original_code:
void
quotefmtinstall(void)
{
 fmtinstall('q', quotestrfmt);
 fmtinstall('Q', quoterunestrfmt);
}

canonical_original_code:
void quotefmtinstall()
{
 fmtinstall('q', quotestrfmt);
 fmtinstall('Q', quoterunestrfmt);
}


utfecpy

decompiled_code:
char *__fastcall utfecpy(_BYTE *a1, unsigned __int64 a2, const void *a3)
{
_BYTE *v3; // r12
char *v5; // rax
_BYTE *v6; // rsi
char v7; // al

v3 = a1;
if ( (unsigned __int64)a1 >= a2 )
return a1;
v5 = (char *)memccpy(a1, a3, 0, a2 - (_QWORD)a1);
if ( v5 )
return v5 - 1;
v6 = (_BYTE *)(a2 - 1);
while ( v6 != a1 )
{
v7 = *--v6;
if ( (v7 & 0xC0) != 128 )
{
v3 = v6;
break;
}
}
*v3 = 0;
return v3;
}

canonical_decompiled_code:
char *__fastcall func0(_BYTE *a1, unsigned __int64 a2, const void *a3)
{
_BYTE *v3; // r12
char *v5; // rax
_BYTE *v6; // rsi
char v7; // al

v3 = a1;
if ( (unsigned __int64)a1 >= a2 )
return a1;
v5 = (char *)memccpy(a1, a3, 0, a2 - (_QWORD)a1);
if ( v5 )
return v5 - 1;
v6 = (_BYTE *)(a2 - 1);
while ( v6 != a1 )
{
v7 = *--v6;
if ( (v7 & 0xC0) != 128 )
{
v3 = v6;
break;
}
}
*v3 = 0;
return v3;
}

original_code:
char*
utfecpy(char *to, char *e, char *from)
{
 char *end;
 if(to >= e)
  return to;
 end = memccpy(to, from, '\0', e - to);
 if(end == 0){
  end = e-1;
  while(end>to && (*--end&0xC0)==0x80)
   ;
  *end = '\0';
 }else{
  end--;
 }
 return end;
}

canonical_original_code:
char *utfecpy(char *to, char *e, char *from)
{
 char *end;
 if(to >= e)
  return to;
 end = memccpy(to, from, '\0', e - to);
 if(end == 0){
  end = e-1;
  while(end>to && (*--end&0xC0)==0x80)
   ;
  *end = '\0';
 }else{
  end--;
 }
 return end;
}

variable_types:
to
char *

variable_types:
e
char *

variable_types:
from
char *

variable_types:
end
char *

return_type: char *


runestrstr

decompiled_code:
__int64 __fastcall runestrstr(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebp
unsigned int v4; // edx
__int64 v5; // rax

v2 = *a2;
if ( *a2 )
{
while ( 1 )
{
a1 = runestrchr(a1, v2);
if ( !a1 )
break;
v4 = a2[1];
if ( !v4 )
return a1;
v5 = 0LL;
while ( *(_DWORD *)(a1 + v5 * 4 + 4) == v4 )
{
v4 = a2[++v5 + 1];
if ( !v4 )
return a1;
}
a1 += 4LL;
}
a1 = 0LL;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebp
unsigned int v4; // edx
__int64 v5; // rax

v2 = *a2;
if ( *a2 )
{
while ( 1 )
{
a1 = runestrchr(a1, v2);
if ( !a1 )
break;
v4 = a2[1];
if ( !v4 )
return a1;
v5 = 0LL;
while ( *(_DWORD *)(a1 + v5 * 4 + 4) == v4 )
{
v4 = a2[++v5 + 1];
if ( !v4 )
return a1;
}
a1 += 4LL;
}
a1 = 0LL;
}
return a1;
}

original_code:
Rune*
runestrstr(Rune *s1, Rune *s2)
{
 Rune *p, *pa, *pb;
 int c0, c;
 c0 = *s2;
 if(c0 == 0)
  return s1;
 s2++;
 for(p=runestrchr(s1, c0); p; p=runestrchr(p+1, c0)) {
  pa = p;
  for(pb=s2;; pb++) {
   c = *pb;
   if(c == 0)
    return p;
   if(c != *++pa)
    break;
  }
 }
 return 0;
}

canonical_original_code:
unsigned int *runestrstr(unsigned int *s1, unsigned int *s2)
{
 unsigned int *p; unsigned int *pa; unsigned int *pb;
 int c0; int c;
 c0 = *s2;
 if(c0 == 0)
  return s1;
 s2++;
 for(p=runestrchr(s1, c0); p; p=runestrchr(p+1, c0)) {
  pa = p;
  for(pb=s2;; pb++) {
   c = *pb;
   if(c == 0)
    return p;
   if(c != *++pa)
    break;
  }
 }
 return 0;
}

variable_types:
p
unsigned int *

variable_types:
pa
unsigned int *

variable_types:
pb
unsigned int *

variable_types: c int

return_type: unsigned int *


getsyserr

decompiled_code:
void *getsyserr()
{
void *result; // rax

if ( !syserrstr )
return &xsyserr;
result = (void *)syserrstr();
if ( !result )
result = &xsyserr;
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

if ( !syserrstr )
return &xsyserr;
result = (void *)syserrstr();
if ( !result )
result = &xsyserr;
return result;
}

original_code:
static char*
getsyserr(void)
{
 char *s;
 s = ((void*)0);
 if(_syserrstr)
  s = (*_syserrstr)();
 if(s == ((void*)0))
  s = xsyserr;
 return s;
}

canonical_original_code:
static char *getsyserr()
{
 char *s;
 s = ((void *)0);
 if(_syserrstr)
  s = (*_syserrstr)();
 if(s == ((void *)0))
  s = xsyserr;
 return s;
}


rerrstr

decompiled_code:
__int64 __fastcall rerrstr(__int64 a1, unsigned int a2)
{
char *v3; // r12
int v4; // edi
char *v6; // rax

v3 = (char *)getsyserr();
v4 = *_errno_location();
if ( v4 == 4 )
{
strcpy(v3, "interrupted");
}
else if ( v4 != 422065989 )
{
v6 = strerror(v4);
strcpy(v3, v6);
}
return strecpy(a1, a1 + a2, v3);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
char *v3; // r12
int v4; // edi
char *v6; // rax

v3 = (char *)func0();
v4 = *_errno_location();
if ( v4 == 4 )
{
strcpy(v3, "interrupted");
}
else if ( v4 != 422065989 )
{
v6 = strerror(v4);
strcpy(v3, v6);
}
return strecpy(a1, a1 + a2, v3);
}

original_code:
void
rerrstr(char *err, uint n)
{
 char *syserr;
 syserr = getsyserr();
 if((*__errno_location ()) == 4)
  strcpy(syserr, "interrupted");
 else if((*__errno_location ()) != EPLAN9)
  strcpy(syserr, strerror((*__errno_location ())));
 strecpy(err, err+n, syserr);
}

canonical_original_code:
void rerrstr(char *err, unsigned int n)
{
 char *syserr;
 syserr = getsyserr();
 if((*__errno_location ()) == 4)
  strcpy(syserr, "interrupted");
 else if((*__errno_location ()) != EPLAN9)
  strcpy(syserr, strerror((*__errno_location ())));
 strecpy(err, err+n, syserr);
}

variable_types:
err
char *

variable_types:
n
unsigned int

variable_types:
syserr
char *


errstr

decompiled_code:
__int64 __fastcall errstr(__int64 a1, unsigned int a2)
{
char *v2; // rax
_BYTE v4[128]; // [rsp+0h] [rbp-98h] BYREF
char v5[24]; // [rsp+80h] [rbp-18h] BYREF

strecpy(v4, v5, a1);
rerrstr(a1, a2);
v2 = (char *)getsyserr();
strecpy(v2, v2 + 128, v4);
*_errno_location() = 422065989;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
char *v2; // rax
_BYTE v4[128]; // [rsp+0h] [rbp-98h] BYREF
char v5[24]; // [rsp+80h] [rbp-18h] BYREF

strecpy(v4, v5, a1);
func1(a1, a2);
v2 = (char *)func0();
strecpy(v2, v2 + 128, v4);
*_errno_location() = 422065989;
return 0LL;
}

original_code:
int
errstr(char *err, uint n)
{
 char tmp[128];
 char *syserr;
 strecpy(tmp, tmp+128, err);
 rerrstr(err, n);
 syserr = getsyserr();
 strecpy(syserr, syserr+128, tmp);
 (*__errno_location ()) = EPLAN9;
 return 0;
}

canonical_original_code:
int errstr(char *err, unsigned int n)
{
 char tmp[128];
 char *syserr;
 strecpy(tmp, tmp+128, err);
 rerrstr(err, n);
 syserr = getsyserr();
 strecpy(syserr, syserr+128, tmp);
 (*__errno_location ()) = EPLAN9;
 return 0;
}

variable_types:
tmp
char [128]


werrstr

decompiled_code:
__int64 werrstr(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-150h] BYREF
char v3[128]; // [rsp+20h] [rbp-138h] BYREF
char v4[8]; // [rsp+A0h] [rbp-B8h] BYREF

va_start(va, a1);
vseprint(v3, v4, a1, va);
return errstr((__int64)v3, 0x80u);
}

canonical_decompiled_code:
__int64 func4(__int64 a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-150h] BYREF
char v3[128]; // [rsp+20h] [rbp-138h] BYREF
char v4[8]; // [rsp+A0h] [rbp-B8h] BYREF

va_start(va, a1);
vseprint(v3, v4, a1, va);
return func2((__int64)v3, 0x80u);
}

original_code:
void
werrstr(char *fmt, ...)
{
 va_list arg;
 char buf[128];
 __builtin_va_start(arg,fmt);
 vseprint(buf, buf+128, fmt, arg);
 __builtin_va_end(arg);
 errstr(buf, 128);
}

canonical_original_code:
void werrstr(char *fmt, ...)
{
 __builtin_va_list arg;
 char buf[128];
 __builtin_va_start(arg,fmt);
 vseprint(buf, buf+128, fmt, arg);
 __builtin_va_end(arg);
 errstr(buf, 128);
}

variable_types:
fmt
char *

variable_types:
buf
char [128]


decompiled_code:
__int64 __fastcall regerror9(char *src)
{
char *v1; // rax
_BYTE vars0[10]; // [rsp+0h] [rbp+0h] BYREF
char dest; // [rsp+Ah] [rbp+Ah] BYREF

qmemcpy(vars0, "regerror: ", sizeof(vars0));
v1 = stpcpy(&dest, src);
*(_WORD *)v1 = 10;
p9write(2LL, vars0, v1 - vars0 + 1);
return exits("regerr");
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
char *v1; // rax
_BYTE vars0[10]; // [rsp+0h] [rbp+0h] BYREF
char dest; // [rsp+Ah] [rbp+Ah] BYREF

qmemcpy(vars0, "regerror: ", sizeof(vars0));
v1 = stpcpy(&dest, src);
*(_WORD *)v1 = 10;
p9write(2LL, vars0, v1 - vars0 + 1);
return exits("regerr");
}

original_code:
void
regerror9(char *s)
{
 char buf[132];
 strcpy(buf, "regerror: ");
 strcat(buf, s);
 strcat(buf, "\n");
 p9write(2, buf, strlen(buf));
 exits("regerr");
}

variable_types:
s
char *

variable_types:
buf
char [132]


isrand

decompiled_code:
unsigned __int64 __fastcall isrand(__int64 a1)
{
__int64 v1; // rdi
unsigned __int64 v2; // rcx
__int64 i; // rsi
unsigned __int64 v4; // rdx
unsigned __int64 v5; // rcx
bool v6; // sf
unsigned __int64 result; // rax

rng_tap = rng_vec;
rng_feed = (__int64)&unk_C30;
v1 = a1 % 0x7FFFFFFF;
v2 = v1;
if ( v1 < 0 )
{
v2 = v1 + 0x7FFFFFFF;
}
else if ( !v1 )
{
v2 = 89482311LL;
}
for ( i = -20LL; i != 607; ++i )
{
v4 = -3399LL * (v2 / 0xADC8);
v5 = 48271 * (v2 % 0xADC8);
v6 = (__int64)(v4 + v5) < 0;
v2 = v4 + v5;
result = v2 + 0x7FFFFFFF;
if ( v6 )
v2 += 0x7FFFFFFFLL;
if ( (int)i >= 0 )
rng_vec[i] = v2;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rdi
unsigned __int64 v2; // rcx
__int64 i; // rsi
unsigned __int64 v4; // rdx
unsigned __int64 v5; // rcx
bool v6; // sf
unsigned __int64 result; // rax

rng_tap = rng_vec;
rng_feed = (__int64)&unk_C30;
v1 = a1 % 0x7FFFFFFF;
v2 = v1;
if ( v1 < 0 )
{
v2 = v1 + 0x7FFFFFFF;
}
else if ( !v1 )
{
v2 = 89482311LL;
}
for ( i = -20LL; i != 607; ++i )
{
v4 = -3399LL * (v2 / 0xADC8);
v5 = 48271 * (v2 % 0xADC8);
v6 = (__int64)(v4 + v5) < 0;
v2 = v4 + v5;
result = v2 + 0x7FFFFFFF;
if ( v6 )
v2 += 0x7FFFFFFFLL;
if ( (int)i >= 0 )
rng_vec[i] = v2;
}
return result;
}

variable_types: seed long

variable_types: lo long

variable_types: hi long

variable_types: x long

variable_types: i int


decompiled_code:
__int64 __fastcall p9srand(__int64 a1)
{
lock(&lk);
isrand(a1);
return unlock(&lk);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
lock(&lk);
func0(a1);
return unlock(&lk);
}

original_code:
void
p9srand(long seed)
{
 lock(&lk);
 isrand(seed);
 unlock(&lk);
}


decompiled_code:
__int64 p9lrand()
{
__int64 v0; // rcx
__int64 *v1; // rax
_QWORD *v2; // rdx
__int64 v3; // r12

lock(&lk);
v0 = rng_feed;
v1 = rng_tap - 1;
rng_tap = v1;
if ( v1 < rng_vec )
{
if ( !rng_feed )
{
isrand(1LL);
v0 = rng_feed;
v1 = rng_tap - 1;
}
v1 += 607;
rng_tap = v1;
}
v2 = (_QWORD *)(v0 - 8);
if ( v0 - 8 < (unsigned __int64)rng_vec )
v2 = (_QWORD *)(v0 + 4848);
v3 = *v2 + *v1;
rng_feed = (__int64)v2;
LODWORD(v3) = v3 & 0x7FFFFFFF;
*v2 = (unsigned int)v3;
unlock(&lk);
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rcx
__int64 *v1; // rax
_QWORD *v2; // rdx
__int64 v3; // r12

lock(&lk);
v0 = rng_feed;
v1 = rng_tap - 1;
rng_tap = v1;
if ( v1 < rng_vec )
{
if ( !rng_feed )
{
func0(1LL);
v0 = rng_feed;
v1 = rng_tap - 1;
}
v1 += 607;
rng_tap = v1;
}
v2 = (_QWORD *)(v0 - 8);
if ( v0 - 8 < (unsigned __int64)rng_vec )
v2 = (_QWORD *)(v0 + 4848);
v3 = *v2 + *v1;
rng_feed = (__int64)v2;
LODWORD(v3) = v3 & 0x7FFFFFFF;
*v2 = (unsigned int)v3;
unlock(&lk);
return (unsigned int)v3;
}

original_code:
long
p9lrand(void)
{
 ulong x;
 lock(&lk);
 rng_tap--;
 if(rng_tap < rng_vec) {
  if(rng_feed == 0) {
   isrand(1);
   rng_tap--;
  }
  rng_tap += 607;
 }
 rng_feed--;
 if(rng_feed < rng_vec)
  rng_feed += 607;
 x = (*rng_feed + *rng_tap) & 0x7fffffffL;
 *rng_feed = x;
 unlock(&lk);
 return x;
}

canonical_original_code:
long p9lrand()
{
 unsigned long x;
 lock(&lk);
 rng_tap--;
 if(rng_tap < rng_vec) {
  if(rng_feed == 0) {
   isrand(1);
   rng_tap--;
  }
  rng_tap += 607;
 }
 rng_feed--;
 if(rng_feed < rng_vec)
  rng_feed += 607;
 x = (*rng_feed + *rng_tap) & 0x7fffffffL;
 *rng_feed = x;
 unlock(&lk);
 return x;
}

variable_types:
x
unsigned long

return_type: long


snprint

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

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

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

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

variable_types:
buf
char *

variable_types: len int

variable_types: n int


rwx

decompiled_code:
char *__fastcall rwx(__int64 a1, char *a2)
{
return strncpy(a2, (const char *)*(&modes + a1), 3uLL);
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, char *a2)
{
return strncpy(a2, (const char *)*(&modes + a1), 3uLL);
}

original_code:
static void
rwx(long m, char *s)
{
 strncpy(s, modes[m], 3);
}

variable_types: m long


dirmodefmt

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 [16]

variable_types:
m
unsigned long


runeFmtStrFlush

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

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

variable_types:
s
unsigned int *


runefmtstrinit

decompiled_code:
__int64 __fastcall runefmtstrinit(__int64 a1)
{
__int64 v2; // rdi
char *v3; // rax

v2 = a1 + 8;
*(_QWORD *)(v2 - 8) = 0LL;
*(_QWORD *)(v2 + 112) = 0LL;
memset(
(void *)(v2 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v2 & 0xFFFFFFF8) + 128) >> 3));
*(_BYTE *)a1 = 1;
v3 = (char *)malloc(0x80uLL);
*(_QWORD *)(a1 + 8) = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = v3;
*(_QWORD *)(a1 + 24) = v3 + 124;
*(_QWORD *)(a1 + 32) = runeFmtStrFlush;
*(_QWORD *)(a1 + 40) = 32LL;
fmtlocaleinit(a1, 0LL, 0LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v2; // rdi
char *v3; // rax

v2 = a1 + 8;
*(_QWORD *)(v2 - 8) = 0LL;
*(_QWORD *)(v2 + 112) = 0LL;
memset(
(void *)(v2 & 0xFFFFFFFFFFFFFFF8LL),
0,
8 * ((unsigned __int64)((unsigned int)a1 - (v2 & 0xFFFFFFF8) + 128) >> 3));
*(_BYTE *)a1 = 1;
v3 = (char *)malloc(0x80uLL);
*(_QWORD *)(a1 + 8) = v3;
if ( !v3 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 16) = v3;
*(_QWORD *)(a1 + 24) = v3 + 124;
*(_QWORD *)(a1 + 32) = runeFmtStrFlush;
*(_QWORD *)(a1 + 40) = 32LL;
fmtlocaleinit(a1, 0LL, 0LL, 0LL);
return 0LL;
}

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

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


runevsmprint

original_code:
Rune*
runevsmprint(char *fmt, va_list args)
{
 Fmt f;
 int n;
 if(runefmtstrinit(&f) < 0)
  return 0;
 __builtin_va_copy(f.args,args);
 n = dofmt(&f, fmt);
 __builtin_va_end(f.args);
 if(f.start == 0)
  return 0;
 if(n < 0){
  free(f.start);
  return 0;
 }
 *(Rune*)f.to = '\0';
 return (Rune*)f.start;
}

canonical_original_code:
unsigned int *runevsmprint(char *fmt, __builtin_va_list args)
{
 struct Fmt f;
 int n;
 if(runefmtstrinit(&f) < 0)
  return 0;
 __builtin_va_copy(f.args,args);
 n = dofmt(&f, fmt);
 __builtin_va_end(f.args);
 if(f.start == 0)
  return 0;
 if(n < 0){
  free(f.start);
  return 0;
 }
 *(unsigned int *)f.to = '\0';
 return (unsigned int *)f.start;
}

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


Bflush

original_code:
int
Bflush(Biobuf *bp)
{
 int n, c;
 switch(bp->state) {
 case Bwactive:
  n = bp->bsize+bp->ocount;
  if(n == 0)
   return 0;
  c = p9write(bp->fid, bp->bbuf, n);
  if(n == c) {
   bp->offset += n;
   bp->ocount = -bp->bsize;
   return 0;
  }
  bp->state = Binactive;
  bp->ocount = 0;
  break;
 case Bracteof:
  bp->state = Bractive;
 case Bractive:
  bp->icount = 0;
  bp->gbuf = bp->ebuf;
  return 0;
 }
 return Beof;
}

canonical_original_code:
int Bflush(struct Biobuf *bp)
{
 int n; int c;
 switch(bp->state) {
 case Bwactive:
  n = bp->bsize+bp->ocount;
  if(n == 0)
   return 0;
  c = p9write(bp->fid, bp->bbuf, n);
  if(n == c) {
   bp->offset += n;
   bp->ocount = -bp->bsize;
   return 0;
  }
  bp->state = Binactive;
  bp->ocount = 0;
  break;
 case Bracteof:
  bp->state = Bractive;
 case Bractive:
  bp->icount = 0;
  bp->gbuf = bp->ebuf;
  return 0;
 }
 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


decompiled_code:
__int64 __fastcall p9times(__suseconds_t *a1)
{
__time_t v2; // r9
__suseconds_t v3; // r10
__time_t v4; // r8
__suseconds_t v5; // rcx
__suseconds_t v6; // rax
__suseconds_t v7; // rdi
__int64 v8; // r9
__suseconds_t v9; // rax
__suseconds_t v10; // rdi
__int64 v11; // rdx
__time_t v12; // rdi
__int64 v13; // r8
__time_t v14; // rsi
struct rusage v16; // [rsp+0h] [rbp-128h] BYREF
struct rusage usage; // [rsp+90h] [rbp-98h] BYREF

if ( getrusage(RUSAGE_SELF, &v16) < 0 || getrusage(RUSAGE_CHILDREN, &usage) < 0 )
return -1LL;
v2 = 1000 * v16.ru_stime.tv_sec;
v3 = usage.ru_stime.tv_usec;
v4 = 1000 * usage.ru_utime.tv_sec;
v5 = v16.ru_utime.tv_usec / 1000 + 1000 * v16.ru_utime.tv_sec;
v6 = v16.ru_stime.tv_usec;
v7 = v16.ru_stime.tv_usec >> 63;
*a1 = v5;
v8 = ((__int64)((unsigned __int128)(0x20C49BA5E353F7CFLL * (__int128)v6) >> 64) >> 7) - v7 + v2;
v9 = usage.ru_utime.tv_usec;
v10 = usage.ru_utime.tv_usec >> 63;
a1[1] = v8;
v11 = ((__int64)((unsigned __int128)(0x20C49BA5E353F7CFLL * (__int128)v9) >> 64) >> 7) - v10;
v12 = 1000 * usage.ru_stime.tv_sec;
v13 = v11 + v4;
a1[2] = v13;
v14 = v12 + v3 / 1000;
a1[3] = v14;
return v14 + v13 + v5 + v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(__suseconds_t *a1)
{
__time_t v2; // r9
__suseconds_t v3; // r10
__time_t v4; // r8
__suseconds_t v5; // rcx
__suseconds_t v6; // rax
__suseconds_t v7; // rdi
__int64 v8; // r9
__suseconds_t v9; // rax
__suseconds_t v10; // rdi
__int64 v11; // rdx
__time_t v12; // rdi
__int64 v13; // r8
__time_t v14; // rsi
struct rusage v16; // [rsp+0h] [rbp-128h] BYREF
struct rusage usage; // [rsp+90h] [rbp-98h] BYREF

if ( getrusage(RUSAGE_SELF, &v16) < 0 || getrusage(RUSAGE_CHILDREN, &usage) < 0 )
return -1LL;
v2 = 1000 * v16.ru_stime.tv_sec;
v3 = usage.ru_stime.tv_usec;
v4 = 1000 * usage.ru_utime.tv_sec;
v5 = v16.ru_utime.tv_usec / 1000 + 1000 * v16.ru_utime.tv_sec;
v6 = v16.ru_stime.tv_usec;
v7 = v16.ru_stime.tv_usec >> 63;
*a1 = v5;
v8 = ((__int64)((unsigned __int128)(0x20C49BA5E353F7CFLL * (__int128)v6) >> 64) >> 7) - v7 + v2;
v9 = usage.ru_utime.tv_usec;
v10 = usage.ru_utime.tv_usec >> 63;
a1[1] = v8;
v11 = ((__int64)((unsigned __int128)(0x20C49BA5E353F7CFLL * (__int128)v9) >> 64) >> 7) - v10;
v12 = 1000 * usage.ru_stime.tv_sec;
v13 = v11 + v4;
a1[2] = v13;
v14 = v12 + v3 / 1000;
a1[3] = v14;
return v14 + v13 + v5 + v8;
}

original_code:
long
p9times(long *t)
{
 struct rusage ru, cru;
 if(getrusage(0, &ru) < 0 || getrusage(-1, &cru) < 0)
  return -1;
 t[0] = ru.ru_utime.tv_sec*1000 + ru.ru_utime.tv_usec/1000;
 t[1] = ru.ru_stime.tv_sec*1000 + ru.ru_stime.tv_usec/1000;
 t[2] = cru.ru_utime.tv_sec*1000 + cru.ru_utime.tv_usec/1000;
 t[3] = cru.ru_stime.tv_sec*1000 + cru.ru_stime.tv_usec/1000;
 return t[0]+t[1]+t[2]+t[3];
}

canonical_original_code:
long p9times(long *t)
{
 struct rusage ru; struct rusage cru;
 if(getrusage(0, &ru) < 0 || getrusage(-1, &cru) < 0)
  return -1;
 t[0] = ru.ru_utime.tv_sec*1000 + ru.ru_utime.tv_usec/1000;
 t[1] = ru.ru_stime.tv_sec*1000 + ru.ru_stime.tv_usec/1000;
 t[2] = cru.ru_utime.tv_sec*1000 + cru.ru_utime.tv_usec/1000;
 t[3] = cru.ru_stime.tv_sec*1000 + cru.ru_stime.tv_usec/1000;
 return t[0]+t[1]+t[2]+t[3];
}

variable_types:
t
long *

variable_types: struct rusage { struct timeval { long tv_sec; long tv_usec; } ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }

user_defined_types: struct rusage { struct timeval ru_utime; struct timeval ru_stime; union { long ru_maxrss; long __ru_maxrss_word; }; union { long ru_ixrss; long __ru_ixrss_word; }; union { long ru_idrss; long __ru_idrss_word; }; union { long ru_isrss; long __ru_isrss_word; }; union { long ru_minflt; long __ru_minflt_word; }; union { long ru_majflt; long __ru_majflt_word; }; union { long ru_nswap; long __ru_nswap_word; }; union { long ru_inblock; long __ru_inblock_word; }; union { long ru_oublock; long __ru_oublock_word; }; union { long ru_msgsnd; long __ru_msgsnd_word; }; union { long ru_msgrcv; long __ru_msgrcv_word; }; union { long ru_nsignals; long __ru_nsignals_word; }; union { long ru_nvcsw; long __ru_nvcsw_word; }; union { long ru_nivcsw; long __ru_nivcsw_word; }; }


decompiled_code:
double p9cputime()
{
double result; // xmm0_8
__suseconds_t v1; // [rsp+0h] [rbp-28h] BYREF
__int64 v2; // [rsp+8h] [rbp-20h]
__int64 v3; // [rsp+10h] [rbp-18h]
__int64 v4; // [rsp+18h] [rbp-10h]

result = *(double *)&LC0;
if ( p9times(&v1) >= 0 )
result = ((double)(int)v1 + (double)(int)v2 + (double)(int)v3 + (double)(int)v4) / 1000.0;
return result;
}

canonical_decompiled_code:
double func1()
{
double result; // xmm0_8
__suseconds_t v1; // [rsp+0h] [rbp-28h] BYREF
__int64 v2; // [rsp+8h] [rbp-20h]
__int64 v3; // [rsp+10h] [rbp-18h]
__int64 v4; // [rsp+18h] [rbp-10h]

result = *(double *)&LC0;
if ( func0(&v1) >= 0 )
result = ((double)(int)v1 + (double)(int)v2 + (double)(int)v3 + (double)(int)v4) / 1000.0;
return result;
}

original_code:
double
p9cputime(void)
{
 long t[4];
 double d;
 if(p9times(t) < 0)
  return -1.0;
 d = (double)t[0]+(double)t[1]+(double)t[2]+(double)t[3];
 return d/1000.0;
}

canonical_original_code:
double p9cputime()
{
 long t[4];
 double d;
 if(p9times(t) < 0)
  return -1.0;
 d = (double)t[0]+(double)t[1]+(double)t[2]+(double)t[3];
 return d/1000.0;
}

variable_types:
t
long [4]

variable_types: d double

return_type: double


decompiled_code:
__suseconds_t p9nsec()
{
__suseconds_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) < 0 )
result = -1LL;
else
result = 1000 * v1.tv_usec + 1000000000 * v1.tv_sec;
return result;
}

canonical_decompiled_code:
__suseconds_t func2()
{
__suseconds_t result; // rax
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v1, 0LL) < 0 )
result = -1LL;
else
result = 1000 * v1.tv_usec + 1000000000 * v1.tv_sec;
return result;
}

original_code:
vlong
p9nsec(void)
{
 struct timeval tv;
 if(gettimeofday(&tv, 0) < 0)
  return -1;
 return (vlong)tv.tv_sec*1000*1000*1000 + tv.tv_usec*1000;
}

canonical_original_code:
long long p9nsec()
{
 struct timeval tv;
 if(gettimeofday(&tv, 0) < 0)
  return -1;
 return (long long)tv.tv_sec*1000*1000*1000 + tv.tv_usec*1000;
}

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

return_type: long long


decompiled_code:
time_t __fastcall p9time(time_t *a1)
{
time_t result; // rax

result = time(0LL);
if ( a1 )
*a1 = result;
return result;
}

canonical_decompiled_code:
time_t __fastcall func3(time_t *a1)
{
time_t result; // rax

result = time(0LL);
if ( a1 )
*a1 = result;
return result;
}

original_code:
long
p9time(long *tt)
{
 long t;
 t = time(0);
 if(tt)
  *tt = t;
 return t;
}

variable_types:
tt
long *

variable_types: t long


putfd

decompiled_code:
__int64 __fastcall putfd(__int64 a1, unsigned int a2)
{
return snprint(a1, 40LL, "/dev/fd/%d", a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
return snprint(a1, 40LL, "/dev/fd/%d", a2);
}

original_code:
static void
putfd(char *dir, int fd)
{
 snprint(dir, 40, "/dev/fd/%d", fd);
}

variable_types:
dir
char *

variable_types: fd int


decompiled_code:
__int64 __fastcall p9announce(const char *a1, __int64 a2)
{
char *v2; // rax
char *v3; // r12
int v4; // ebx
int v5; // er12
socklen_t v6; // eax
socklen_t v8; // eax
int *v9; // rbx
socklen_t v10; // eax
socklen_t v11; // eax
int v12; // [rsp+4h] [rbp-B4h] BYREF
int optval; // [rsp+8h] [rbp-B0h] BYREF
socklen_t optlen; // [rsp+Ch] [rbp-ACh] BYREF
char *filename; // [rsp+10h] [rbp-A8h] BYREF
const char *v16; // [rsp+18h] [rbp-A0h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-98h] BYREF

v2 = strdup(a1);
if ( !v2 )
return (unsigned int)-1;
v3 = v2;
if ( (int)p9dialparse(v2, &v16, &filename, &addr, &v12) < 0 )
goto LABEL_27;
if ( strcmp(v16, "tcp") )
{
if ( !strcmp(v16, "udp") )
{
v4 = 2;
goto LABEL_6;
}
if ( !strcmp(v16, "unix") )
{
v5 = socket(addr.sa_family, 1, 0);
if ( v5 >= 0 )
{
v8 = addrlen_isra_0(addr.sa_family);
if ( bind(v5, &addr, v8) >= 0 )
goto LABEL_19;
v9 = _errno_location();
if ( *v9 != 98 )
goto LABEL_24;
v10 = addrlen_isra_0(addr.sa_family);
if ( connect(v5, &addr, v10) >= 0 || *v9 != 111 )
goto LABEL_24;
remove(filename);
close(v5);
v5 = socket(addr.sa_family, 1, 0);
if ( v5 >= 0 )
{
v11 = addrlen_isra_0(addr.sa_family);
if ( bind(v5, &addr, v11) >= 0 )
goto LABEL_19;
goto LABEL_24;
}
}
return (unsigned int)-1;
}
werrstr("can only handle tcp, udp, and unix: not %s", v16);
LABEL_27:
free(v3);
return (unsigned int)-1;
}
v4 = 1;
LABEL_6:
free(v3);
v5 = socket(addr.sa_family, v4, 0);
if ( v5 < 0 )
return (unsigned int)-1;
optlen = 4;
if ( v12 && getsockopt(v5, 1, 3, &optval, &optlen) >= 0 && optval == 1 )
setsockopt(v5, 1, 2, &optval, 4u);
v6 = addrlen_isra_0(addr.sa_family);
if ( bind(v5, &addr, v6) < 0 )
{
LABEL_24:
close(v5);
return (unsigned int)-1;
}
if ( v4 != 1 )
return (unsigned int)v5;
LABEL_19:
listen(v5, 8);
putfd(a2, v5);
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1, __int64 a2)
{
char *v2; // rax
char *v3; // r12
int v4; // ebx
int v5; // er12
socklen_t v6; // eax
socklen_t v8; // eax
int *v9; // rbx
socklen_t v10; // eax
socklen_t v11; // eax
int v12; // [rsp+4h] [rbp-B4h] BYREF
int optval; // [rsp+8h] [rbp-B0h] BYREF
socklen_t optlen; // [rsp+Ch] [rbp-ACh] BYREF
char *filename; // [rsp+10h] [rbp-A8h] BYREF
const char *v16; // [rsp+18h] [rbp-A0h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-98h] BYREF

v2 = strdup(a1);
if ( !v2 )
return (unsigned int)-1;
v3 = v2;
if ( (int)p9dialparse(v2, &v16, &filename, &addr, &v12) < 0 )
goto LABEL_27;
if ( strcmp(v16, "tcp") )
{
if ( !strcmp(v16, "udp") )
{
v4 = 2;
goto LABEL_6;
}
if ( !strcmp(v16, "unix") )
{
v5 = socket(addr.sa_family, 1, 0);
if ( v5 >= 0 )
{
v8 = func1(addr.sa_family);
if ( bind(v5, &addr, v8) >= 0 )
goto LABEL_19;
v9 = _errno_location();
if ( *v9 != 98 )
goto LABEL_24;
v10 = func1(addr.sa_family);
if ( connect(v5, &addr, v10) >= 0 || *v9 != 111 )
goto LABEL_24;
remove(filename);
close(v5);
v5 = socket(addr.sa_family, 1, 0);
if ( v5 >= 0 )
{
v11 = func1(addr.sa_family);
if ( bind(v5, &addr, v11) >= 0 )
goto LABEL_19;
goto LABEL_24;
}
}
return (unsigned int)-1;
}
werrstr("can only handle tcp, udp, and unix: not %s", v16);
LABEL_27:
free(v3);
return (unsigned int)-1;
}
v4 = 1;
LABEL_6:
free(v3);
v5 = socket(addr.sa_family, v4, 0);
if ( v5 < 0 )
return (unsigned int)-1;
optlen = 4;
if ( v12 && getsockopt(v5, 1, 3, &optval, &optlen) >= 0 && optval == 1 )
setsockopt(v5, 1, 2, &optval, 4u);
v6 = func1(addr.sa_family);
if ( bind(v5, &addr, v6) < 0 )
{
LABEL_24:
close(v5);
return (unsigned int)-1;
}
if ( v4 != 1 )
return (unsigned int)v5;
LABEL_19:
listen(v5, 8);
func0(a2, v5);
return (unsigned int)v5;
}

original_code:
int
p9announce(char *addr, char *dir)
{
 int proto;
 char *buf, *sockunix;
 char *net;
 int port, s;
 int n;
 socklen_t sn;
 struct sockaddr_storage ss;
 buf = strdup(addr);
 if(buf == ((void*)0))
  return -1;
 if(p9dialparse(buf, &net, &sockunix, &ss, &port) < 0){
  free(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);
  free(buf);
  return -1;
 }
 free(buf);
 if((s = socket(ss.ss_family, proto, 0)) < 0)
  return -1;
 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*)&ss, addrlen(&ss)) < 0){
  close(s);
  return -1;
 }
 if(proto == SOCK_STREAM){
  listen(s, 8);
  putfd(dir, s);
 }
 return s;
Unix:
 if((s = socket(ss.ss_family, SOCK_STREAM, 0)) < 0)
  return -1;
 if(bind(s, (struct sockaddr*)&ss, addrlen(&ss)) < 0){
  if((*__errno_location ()) == 98
  && connect(s, (struct sockaddr*)&ss, addrlen(&ss)) < 0
  && (*__errno_location ()) == 111){
   remove(sockunix);
   close(s);
   if((s = socket(ss.ss_family, SOCK_STREAM, 0)) < 0)
    return -1;
   if(bind(s, (struct sockaddr*)&ss, addrlen(&ss)) >= 0)
    goto Success;
  }
  close(s);
  return -1;
 }
Success:
 listen(s, 8);
 putfd(dir, s);
 return s;
}

canonical_original_code:
int p9announce(char *addr, char *dir)
{
 int proto;
 char *buf; char *sockunix;
 char *net;
 int port; int s;
 int n;
 unsigned int sn;
 struct sockaddr_storage ss;
 buf = strdup(addr);
 if(buf == ((void *)0))
  return -1;
 if(p9dialparse(buf, &net, &sockunix, &ss, &port) < 0){
  free(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);
  free(buf);
  return -1;
 }
 free(buf);
 if((s = socket(ss.ss_family, proto, 0)) < 0)
  return -1;
 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 *)&ss, addrlen(&ss)) < 0){
  close(s);
  return -1;
 }
 if(proto == SOCK_STREAM){
  listen(s, 8);
  putfd(dir, s);
 }
 return s;
Unix:
 if((s = socket(ss.ss_family, SOCK_STREAM, 0)) < 0)
  return -1;
 if(bind(s, (struct sockaddr *)&ss, addrlen(&ss)) < 0){
  if((*__errno_location ()) == 98
  && connect(s, (struct sockaddr *)&ss, addrlen(&ss)) < 0
  && (*__errno_location ()) == 111){
   remove(sockunix);
   close(s);
   if((s = socket(ss.ss_family, SOCK_STREAM, 0)) < 0)
    return -1;
   if(bind(s, (struct sockaddr *)&ss, addrlen(&ss)) >= 0)
    goto Success;
  }
  close(s);
  return -1;
 }
Success:
 listen(s, 8);
 putfd(dir, s);
 return s;
}

variable_types:
addr
char *

variable_types: proto int

variable_types:
buf
char *

variable_types:
sockunix
char *

variable_types:
net
char *

variable_types: port int

variable_types: s int

variable_types: n int

variable_types:
sn
unsigned int

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

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


decompiled_code:
__int64 __fastcall p9listen(const char *a1, __int64 a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // er12
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = p9netfd((__int64)a1);
if ( v2 < 0 )
{
v4 = -1;
werrstr("bad 'directory' in listen: %s", a1);
}
else
{
v3 = accept(v2, 0LL, 0LL);
v4 = v3;
if ( v3 < 0 )
{
v4 = -1;
}
else
{
optval[0] = 1;
setsockopt(v3, 6, 1, optval, 4u);
putfd(a2, v4);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int64 a2)
{
int v2; // eax
int v3; // eax
unsigned int v4; // er12
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = func2((__int64)a1);
if ( v2 < 0 )
{
v4 = -1;
werrstr("bad 'directory' in listen: %s", a1);
}
else
{
v3 = accept(v2, 0LL, 0LL);
v4 = v3;
if ( v3 < 0 )
{
v4 = -1;
}
else
{
optval[0] = 1;
setsockopt(v3, 6, 1, optval, 4u);
func0(a2, v4);
}
}
return v4;
}

original_code:
int
p9listen(char *dir, char *newdir)
{
 int fd, one;
 if((fd = _p9netfd(dir)) < 0){
  werrstr("bad 'directory' in listen: %s", dir);
  return -1;
 }
 if((fd = accept(fd, ((void*)0), ((void*)0))) < 0)
  return -1;
 one = 1;
 setsockopt(fd, IPPROTO_TCP, 1, (char*)&one, sizeof one);
 putfd(newdir, fd);
 return fd;
}

canonical_original_code:
int p9listen(char *dir, char *newdir)
{
 int fd; int one;
 if((fd = _p9netfd(dir)) < 0){
  werrstr("bad 'directory' in listen: %s", dir);
  return -1;
 }
 if((fd = accept(fd, ((void *)0), ((void *)0))) < 0)
  return -1;
 one = 1;
 setsockopt(fd, IPPROTO_TCP, 1, (char *)&one, sizeof one);
 putfd(newdir, fd);
 return fd;
}

variable_types:
newdir
char *

variable_types: one int


decompiled_code:
int __fastcall p9accept(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = p9netfd(a2);
if ( v2 >= 0 )
return dup(v2);
werrstr("bad 'directory' in accept");
return -1;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, __int64 a2)
{
int v2; // eax

v2 = func2(a2);
if ( v2 >= 0 )
return dup(v2);
werrstr("bad 'directory' in accept");
return -1;
}

original_code:
int
p9accept(int cfd, char *dir)
{
 int fd;
 if((fd = _p9netfd(dir)) < 0){
  werrstr("bad 'directory' in accept");
  return -1;
 }
 return dup(fd);
}

variable_types: cfd int


decompiled_code:
void *__fastcall p9malloc(size_t size)
{
size_t v2; // rdi
void *v3; // r12

lock(&malloclock);
v2 = 1LL;
if ( size )
v2 = size;
v3 = malloc(v2);
unlock(&malloclock);
return v3;
}

canonical_decompiled_code:
void *__fastcall func0(size_t size)
{
size_t v2; // rdi
void *v3; // r12

lock(&malloclock);
v2 = 1LL;
if ( size )
v2 = size;
v3 = malloc(v2);
unlock(&malloclock);
return v3;
}

original_code:
void*
p9malloc(ulong n)
{
 void *v;
 if(n == 0)
  n++;
 lock(&malloclock);
 v = malloc(n);
 unlock(&malloclock);
 return v;
}

canonical_original_code:
void *p9malloc(unsigned long n)
{
 void *v;
 if(n == 0)
  n++;
 lock(&malloclock);
 v = malloc(n);
 unlock(&malloclock);
 return v;
}

variable_types:
n
unsigned long

variable_types:
v
void *

return_type: void *


decompiled_code:
__int64 __fastcall p9free(void *ptr)
{
__int64 result; // rax

if ( ptr )
{
lock(&malloclock);
free(ptr);
result = unlock(&malloclock);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
__int64 result; // rax

if ( ptr )
{
lock(&malloclock);
free(ptr);
result = unlock(&malloclock);
}
return result;
}

original_code:
void
p9free(void *v)
{
 if(v == ((void*)0))
  return;
 lock(&malloclock);
 free(v);
 unlock(&malloclock);
}

canonical_original_code:
void p9free(void *v)
{
 if(v == ((void *)0))
  return;
 lock(&malloclock);
 free(v);
 unlock(&malloclock);
}


decompiled_code:
void *__fastcall p9calloc(__int64 a1, __int64 a2)
{
size_t v2; // rdi
void *v3; // r12

lock(&malloclock);
v2 = a2 * a1;
if ( v2 <= 1 )
v2 = 1LL;
v3 = calloc(v2, 1uLL);
unlock(&malloclock);
return v3;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, __int64 a2)
{
size_t v2; // rdi
void *v3; // r12

lock(&malloclock);
v2 = a2 * a1;
if ( v2 <= 1 )
v2 = 1LL;
v3 = calloc(v2, 1uLL);
unlock(&malloclock);
return v3;
}

original_code:
void*
p9calloc(ulong a, ulong b)
{
 void *v;
 if(a*b == 0)
  a = b = 1;
 lock(&malloclock);
 v = calloc(a*b, 1);
 unlock(&malloclock);
 return v;
}

canonical_original_code:
void *p9calloc(unsigned long a, unsigned long b)
{
 void *v;
 if(a*b == 0)
  a = b = 1;
 lock(&malloclock);
 v = calloc(a*b, 1);
 unlock(&malloclock);
 return v;
}

variable_types:
a
unsigned long

variable_types:
b
unsigned long


decompiled_code:
void *__fastcall p9realloc(void *ptr, size_t size)
{
void *v2; // r12

lock(&malloclock);
v2 = realloc(ptr, size);
unlock(&malloclock);
return v2;
}

canonical_decompiled_code:
void *__fastcall func3(void *ptr, size_t size)
{
void *v2; // r12

lock(&malloclock);
v2 = realloc(ptr, size);
unlock(&malloclock);
return v2;
}

original_code:
void*
p9realloc(void *v, ulong n)
{
 lock(&malloclock);
 v = realloc(v, n);
 unlock(&malloclock);
 return v;
}

canonical_original_code:
void *p9realloc(void *v, unsigned long n)
{
 lock(&malloclock);
 v = realloc(v, n);
 unlock(&malloclock);
 return v;
}


original_code:
int
p9open(char *name, int mode)
{
 int cexec, rclose;
 int fd, umode, lock, rdwr;
 struct flock fl;
 rdwr = mode&3;
 umode = rdwr;
 cexec = mode&32;
 rclose = mode&64;
 lock = mode&0x2000;
 mode &= ~(3|32|64|0x2000);
 if(mode&16){
  umode |= 01000;
  mode ^= 16;
 }
 if(mode&128){
  umode |= 040000;
  mode ^= 128;
 }
 if(mode&256){
  umode |= 04000;
  mode ^= 256;
 }
 if(mode&0x4000){
  umode |= 02000;
  mode ^= 0x4000;
 }
 if(mode){
  werrstr("mode 0x%x not supported", mode);
  return -1;
 }
 fd = open(name, umode);
 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(name);
 }
 return fd;
}

canonical_original_code:
int p9open(char *name, int mode)
{
 int cexec; int rclose;
 int fd; int umode; int lock; int rdwr;
 struct flock fl;
 rdwr = mode&3;
 umode = rdwr;
 cexec = mode&32;
 rclose = mode&64;
 lock = mode&0x2000;
 mode &= ~(3|32|64|0x2000);
 if(mode&16){
  umode |= 01000;
  mode ^= 16;
 }
 if(mode&128){
  umode |= 040000;
  mode ^= 128;
 }
 if(mode&256){
  umode |= 04000;
  mode ^= 256;
 }
 if(mode&0x4000){
  umode |= 02000;
  mode ^= 0x4000;
 }
 if(mode){
  werrstr("mode 0x%x not supported", mode);
  return -1;
 }
 fd = open(name, umode);
 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(name);
 }
 return fd;
}

variable_types:
name
char *

variable_types: mode int

variable_types: cexec int

variable_types: rclose int

variable_types: fd int

variable_types: umode 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; }


utfrrune

decompiled_code:
char *__fastcall utfrrune(const char *a1, __int64 a2)
{
const char *v2; // rbp
const char *v4; // r12
int v5; // eax
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = a1;
if ( a2 <= 127 )
return strrchr(a1, a2);
v4 = 0LL;
while ( 1 )
{
while ( *(unsigned __int8 *)v2 > 0x7FuLL )
{
v5 = chartorune(v6, v2);
if ( v6[0] == a2 )
v4 = v2;
v2 += v5;
}
if ( !*v2 )
break;
++v2;
}
return (char *)v4;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1, __int64 a2)
{
const char *v2; // rbp
const char *v4; // r12
int v5; // eax
int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = a1;
if ( a2 <= 127 )
return strrchr(a1, a2);
v4 = 0LL;
while ( 1 )
{
while ( *(unsigned __int8 *)v2 > 0x7FuLL )
{
v5 = chartorune(v6, v2);
if ( v6[0] == a2 )
v4 = v2;
v2 += v5;
}
if ( !*v2 )
break;
++v2;
}
return (char *)v4;
}

original_code:
char*
utfrrune(char *s, long c)
{
 long c1;
 Rune r;
 char *s1;
 if(c < Runesync)
  return strrchr(s, c);
 s1 = 0;
 for(;;) {
  c1 = *(_utfuchar*)s;
  if(c1 < Runeself) {
   if(c1 == 0)
    return s1;
   if(c1 == c)
    s1 = s;
   s++;
   continue;
  }
  c1 = chartorune(&r, s);
  if(r == c)
   s1 = s;
  s += c1;
 }
}

canonical_original_code:
char *utfrrune(char *s, long c)
{
 long c1;
 unsigned int r;
 char *s1;
 if(c < Runesync)
  return strrchr(s, c);
 s1 = 0;
 for(;;) {
  c1 = *(unsigned char *)s;
  if(c1 < Runeself) {
   if(c1 == 0)
    return s1;
   if(c1 == c)
    s1 = s;
   s++;
   continue;
  }
  c1 = chartorune(&r, s);
  if(r == c)
   s1 = s;
  s += c1;
 }
}

variable_types:
s
char *

variable_types: c long

variable_types:
r
unsigned int


yrsize

decompiled_code:
void *__fastcall yrsize(int a1)
{
void *result; // rax
int v2; // edi

result = &dmsize;
if ( (a1 & 3) == 0 )
{
result = &ldmsize;
v2 = -1030792151 * a1 + 85899344;
if ( __ROR4__(v2, 2) <= 0x28F5C28u && __ROR4__(v2, 4) > 0xA3D70Au )
result = &dmsize;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(int a1)
{
void *result; // rax
int v2; // edi

result = &dmsize;
if ( (a1 & 3) == 0 )
{
result = &ldmsize;
v2 = -1030792151 * a1 + 85899344;
if ( __ROR4__(v2, 2) <= 0x28F5C28u && __ROR4__(v2, 4) > 0xA3D70Au )
result = &dmsize;
}
return result;
}

original_code:
static int *
yrsize(int y)
{
 if((y%4) == 0 && ((y%100) != 0 || (y%400) == 0))
  return ldmsize;
 else
  return dmsize;
}

canonical_original_code:
static int *yrsize(int y)
{
 if((y%4) == 0 && ((y%100) != 0 || (y%400) == 0))
  return ldmsize;
 else
  return dmsize;
}

variable_types: y int

return_type: int *


original_code:
long
p9tm2sec(Tm *tm)
{
 Tinfo ti0, ti1, *ti;
 long secs;
 int i, yday, year, *d2m;
 secs = 0;
 year = tm->year + 1900;
 for(i = 1970; i < year; i++){
  d2m = yrsize(i);
  secs += d2m[0] * (24L*(60L*60L));
 }
 if(tm->mday){
  yday = 0;
  d2m = yrsize(year);
  for(i=0; i<tm->mon; i++)
   yday += d2m[i+1];
  yday += tm->mday-1;
 }else{
  yday = tm->yday;
 }
 secs += yday * (24L*(60L*60L));
 secs += tm->hour * (60L*60L);
 secs += tm->min * 60L;
 secs += tm->sec;
 if(strcmp(tm->zone, "GMT") != 0) {
  i = _p9zonelookuptinfo(&ti0, secs);
  ti = &ti0;
  if (i != -1)
  if (ti->tzoff!=0) {
   if (ti->tzoff>0) {
    if (ti->t+ti->tzoff > secs)
    if (_p9zonetinfo(&ti1, i-1)!=-1)
     ti = &ti1;
   } else
    if (_p9zonetinfo(&ti1, i+1))
    if (ti1.t+ti->tzoff < secs)
     ti = &ti1;
   secs -= ti->tzoff;
  }
 }
 if(secs < 0)
  secs = 0;
 return secs;
}

canonical_original_code:
long p9tm2sec(struct Tm *tm)
{
 struct Tinfo ti0; struct Tinfo ti1; struct Tinfo *ti;
 long secs;
 int i; int yday; int year; int *d2m;
 secs = 0;
 year = tm->year + 1900;
 for(i = 1970; i < year; i++){
  d2m = yrsize(i);
  secs += d2m[0] * (24L*(60L*60L));
 }
 if(tm->mday){
  yday = 0;
  d2m = yrsize(year);
  for(i=0; i<tm->mon; i++)
   yday += d2m[i+1];
  yday += tm->mday-1;
 }else{
  yday = tm->yday;
 }
 secs += yday * (24L*(60L*60L));
 secs += tm->hour * (60L*60L);
 secs += tm->min * 60L;
 secs += tm->sec;
 if(strcmp(tm->zone, "GMT") != 0) {
  i = _p9zonelookuptinfo(&ti0, secs);
  ti = &ti0;
  if (i != -1)
  if (ti->tzoff!=0) {
   if (ti->tzoff>0) {
    if (ti->t+ti->tzoff > secs)
    if (_p9zonetinfo(&ti1, i-1)!=-1)
     ti = &ti1;
   } else
    if (_p9zonetinfo(&ti1, i+1))
    if (ti1.t+ti->tzoff < secs)
     ti = &ti1;
   secs -= ti->tzoff;
  }
 }
 if(secs < 0)
  secs = 0;
 return secs;
}

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

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

variable_types: secs long

variable_types: i int

variable_types: yday int

variable_types: year int


unquotestrdup

original_code:
char*
unquotestrdup(char *s)
{
 char *t, *ret;
 int quoting;
 ret = s = p9strdup(s);
 if(ret == ((void*)0))
  return ret;
 quoting = 0;
 t = s;
 while(*t!='\0' && (quoting || (*t!=' ' && *t!='\t'))){
  if(*t != '\''){
   *s++ = *t++;
   continue;
  }
  if(!quoting){
   quoting = 1;
   t++;
   continue;
  }
  if(t[1] != '\''){
   t++;
   quoting = 0;
   continue;
  }
  t++;
  *s++ = *t++;
 }
 if(t != s)
  memmove(s, t, strlen(t)+1);
 return ret;
}

canonical_original_code:
char *unquotestrdup(char *s)
{
 char *t; char *ret;
 int quoting;
 ret = s = p9strdup(s);
 if(ret == ((void *)0))
  return ret;
 quoting = 0;
 t = s;
 while(*t!='\0' && (quoting || (*t!=' ' && *t!='\t'))){
  if(*t != '\''){
   *s++ = *t++;
   continue;
  }
  if(!quoting){
   quoting = 1;
   t++;
   continue;
  }
  if(t[1] != '\''){
   t++;
   quoting = 0;
   continue;
  }
  t++;
  *s++ = *t++;
 }
 if(t != s)
  memmove(s, t, strlen(t)+1);
 return ret;
}

variable_types:
t
char *

variable_types:
ret
char *

variable_types: quoting int


decompiled_code:
// attributes: thunk
__int64 NaN()
{
return _NaN();
}

canonical_decompiled_code:
__int64 func0()
{
return _NaN();
}

original_code:
double
NaN(void)
{
 return __NaN();
}

canonical_original_code:
double NaN()
{
 return __NaN();
}


Inf

decompiled_code:
// attributes: thunk
__int64 Inf()
{
return _Inf();
}

canonical_decompiled_code:
__int64 func1()
{
return _Inf();
}

original_code:
double
Inf(int sign)
{
 return __Inf(sign);
}

variable_types: sign int


isNaN

decompiled_code:
// attributes: thunk
__int64 isNaN()
{
return _isNaN();
}

canonical_decompiled_code:
__int64 func2()
{
return _isNaN();
}

original_code:
int
isNaN(double x)
{
 return __isNaN(x);
}

variable_types: x double


isInf

decompiled_code:
// attributes: thunk
__int64 isInf()
{
return _isInf();
}

canonical_decompiled_code:
__int64 func3()
{
return _isInf();
}

original_code:
int
isInf(double x, int sign)
{
 return __isInf(x, sign);
}


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

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

original_code:
int
p9atoi(char *s)
{
 return strtol(s, 0, 0);
}


needsrcquote

decompiled_code:
_BOOL8 __fastcall needsrcquote(int c)
{
_BOOL8 result; // rax

if ( c <= 32 )
result = 1LL;
else
result = strchr("`^#*[]=|\\?${}()'<>&;", c) != 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int c)
{
_BOOL8 result; // rax

if ( c <= 32 )
result = 1LL;
else
result = strchr("`^#*[]=|\\?${}()'<>&;", c) != 0LL;
return result;
}

original_code:
int
needsrcquote(int c)
{
 if(c <= ' ')
  return 1;
 if(strchr("`^#*[]=|\\?${}()'<>&;", c))
  return 1;
 return 0;
}

variable_types: c int


pqid

variable_types:
p
unsigned char *

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

return_type: unsigned char *


stringsz

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

if ( a1 )
result = (unsigned int)strlen(a1) + 2;
else
result = 2LL;
return result;
}

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

if ( a1 )
result = (unsigned int)strlen(a1) + 2;
else
result = 2LL;
return result;
}

original_code:
static
uint
stringsz(char *s)
{
 if(s == ((void*)0))
  return 2;
 return 2 +strlen(s);
}

canonical_original_code:
static unsigned int stringsz(char *s)
{
 if(s == ((void *)0))
  return 2;
 return 2 +strlen(s);
}

variable_types:
s
char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall sizeS2M(__int64 a1)
{
unsigned int v1; // er12
int v3; // ebp
int v4; // ebp
int v5; // eax
const char **v6; // rbp
__int64 v7; // rbx
const char *v8; // rdi

switch ( *(_BYTE *)a1 )
{
case 'b':
case 'p':
v1 = 12;
break;
case 'c':
v1 = 28;
break;
case 'd':
case 'e':
v1 = stringsz(*(const char **)(a1 + 16)) + 11;
break;
case 'f':
v4 = stringsz(*(const char **)(a1 + 104));
v1 = v4 + stringsz(*(const char **)(a1 + 112)) + 11;
break;
case 'g':
case 'i':
v1 = 20;
break;
case 'h':
v3 = stringsz(*(const char **)(a1 + 104));
v1 = v3 + stringsz(*(const char **)(a1 + 112)) + 15;
break;
case 'k':
v1 = stringsz(*(const char **)(a1 + 32)) + 7;
break;
case 'l':
v1 = 9;
break;
case 'm':
case 'y':
case '{':
case '\x7F':
v1 = 7;
break;
case 'n':
v5 = *(unsigned __int16 *)(a1 + 144);
v1 = 17;
if ( (_WORD)v5 )
{
v6 = (const char **)(a1 + 152);
v1 = 17;
v7 = a1 + 8LL * (unsigned int)(v5 - 1) + 160;
do
{
v8 = *v6++;
v1 += stringsz(v8);
}
while ( v6 != (const char **)v7 );
}
break;
case 'o':
v1 = 13 * *(unsigned __int16 *)(a1 + 280) + 9;
break;
case 'q':
case 's':
v1 = 24;
break;
case 'r':
v1 = stringsz(*(const char **)(a1 + 128)) + 16;
break;
case 't':
v1 = 23;
break;
case 'u':
v1 = *(_DWORD *)(a1 + 680) + 11;
break;
case 'v':
v1 = *(_DWORD *)(a1 + 680) + 23;
break;
case 'w':
case 'x':
case 'z':
case '|':
v1 = 11;
break;
case '}':
v1 = *(unsigned __int16 *)(a1 + 696) + 9;
break;
case '~':
v1 = *(unsigned __int16 *)(a1 + 696) + 13;
break;
default:
v1 = 0;
break;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // er12
int v3; // ebp
int v4; // ebp
int v5; // eax
const char **v6; // rbp
__int64 v7; // rbx
const char *v8; // rdi

switch ( *(_BYTE *)a1 )
{
case 'b':
case 'p':
v1 = 12;
break;
case 'c':
v1 = 28;
break;
case 'd':
case 'e':
v1 = func1(*(const char **)(a1 + 16)) + 11;
break;
case 'f':
v4 = func1(*(const char **)(a1 + 104));
v1 = v4 + func1(*(const char **)(a1 + 112)) + 11;
break;
case 'g':
case 'i':
v1 = 20;
break;
case 'h':
v3 = func1(*(const char **)(a1 + 104));
v1 = v3 + func1(*(const char **)(a1 + 112)) + 15;
break;
case 'k':
v1 = func1(*(const char **)(a1 + 32)) + 7;
break;
case 'l':
v1 = 9;
break;
case 'm':
case 'y':
case '{':
case '\x7F':
v1 = 7;
break;
case 'n':
v5 = *(unsigned __int16 *)(a1 + 144);
v1 = 17;
if ( (_WORD)v5 )
{
v6 = (const char **)(a1 + 152);
v1 = 17;
v7 = a1 + 8LL * (unsigned int)(v5 - 1) + 160;
do
{
v8 = *v6++;
v1 += func1(v8);
}
while ( v6 != (const char **)v7 );
}
break;
case 'o':
v1 = 13 * *(unsigned __int16 *)(a1 + 280) + 9;
break;
case 'q':
case 's':
v1 = 24;
break;
case 'r':
v1 = func1(*(const char **)(a1 + 128)) + 16;
break;
case 't':
v1 = 23;
break;
case 'u':
v1 = *(_DWORD *)(a1 + 680) + 11;
break;
case 'v':
v1 = *(_DWORD *)(a1 + 680) + 23;
break;
case 'w':
case 'x':
case 'z':
case '|':
v1 = 11;
break;
case '}':
v1 = *(unsigned __int16 *)(a1 + 696) + 9;
break;
case '~':
v1 = *(unsigned __int16 *)(a1 + 696) + 13;
break;
default:
v1 = 0;
break;
}
return v1;
}

original_code:
uint
sizeS2M(Fcall *f)
{
 uint n;
 int i;
 n = 0;
 n += 4;
 n += 1;
 n += 2;
 switch(f->type)
 {
 default:
  return 0;
 case Tversion:
  n += 4;
  n += stringsz(f->version);
  break;
 case Tflush:
  n += 2;
  break;
 case Tauth:
  n += 4;
  n += stringsz(f->uname);
  n += stringsz(f->aname);
  break;
 case Tattach:
  n += 4;
  n += 4;
  n += stringsz(f->uname);
  n += stringsz(f->aname);
  break;
 case Twalk:
  n += 4;
  n += 4;
  n += 2;
  for(i=0; i<f->nwname; i++)
   n += stringsz(f->wname[i]);
  break;
 case Topen:
 case Topenfd:
  n += 4;
  n += 1;
  break;
 case Tcreate:
  n += 4;
  n += stringsz(f->name);
  n += 4;
  n += 1;
  break;
 case Tread:
  n += 4;
  n += 8;
  n += 4;
  break;
 case Twrite:
  n += 4;
  n += 8;
  n += 4;
  n += f->count;
  break;
 case Tclunk:
 case Tremove:
  n += 4;
  break;
 case Tstat:
  n += 4;
  break;
 case Twstat:
  n += 4;
  n += 2;
  n += f->nstat;
  break;
 case Rversion:
  n += 4;
  n += stringsz(f->version);
  break;
 case Rerror:
  n += stringsz(f->ename);
  break;
 case Rflush:
  break;
 case Rauth:
  n += (1 +4 +8);
  break;
 case Rattach:
  n += (1 +4 +8);
  break;
 case Rwalk:
  n += 2;
  n += f->nwqid*(1 +4 +8);
  break;
 case Ropen:
 case Rcreate:
  n += (1 +4 +8);
  n += 4;
  break;
 case Ropenfd:
  n += (1 +4 +8);
  n += 4;
  n += 4;
  break;
 case Rread:
  n += 4;
  n += f->count;
  break;
 case Rwrite:
  n += 4;
  break;
 case Rclunk:
  break;
 case Rremove:
  break;
 case Rstat:
  n += 2;
  n += f->nstat;
  break;
 case Rwstat:
  break;
 }
 return n;
}

canonical_original_code:
unsigned int sizeS2M(struct Fcall *f)
{
 unsigned int n;
 int i;
 n = 0;
 n += 4;
 n += 1;
 n += 2;
 switch(f->type)
 {
 default:
  return 0;
 case Tversion:
  n += 4;
  n += stringsz(f->version);
  break;
 case Tflush:
  n += 2;
  break;
 case Tauth:
  n += 4;
  n += stringsz(f->uname);
  n += stringsz(f->aname);
  break;
 case Tattach:
  n += 4;
  n += 4;
  n += stringsz(f->uname);
  n += stringsz(f->aname);
  break;
 case Twalk:
  n += 4;
  n += 4;
  n += 2;
  for(i=0; i<f->nwname; i++)
   n += stringsz(f->wname[i]);
  break;
 case Topen:
 case Topenfd:
  n += 4;
  n += 1;
  break;
 case Tcreate:
  n += 4;
  n += stringsz(f->name);
  n += 4;
  n += 1;
  break;
 case Tread:
  n += 4;
  n += 8;
  n += 4;
  break;
 case Twrite:
  n += 4;
  n += 8;
  n += 4;
  n += f->count;
  break;
 case Tclunk:
 case Tremove:
  n += 4;
  break;
 case Tstat:
  n += 4;
  break;
 case Twstat:
  n += 4;
  n += 2;
  n += f->nstat;
  break;
 case Rversion:
  n += 4;
  n += stringsz(f->version);
  break;
 case Rerror:
  n += stringsz(f->ename);
  break;
 case Rflush:
  break;
 case Rauth:
  n += (1 +4 +8);
  break;
 case Rattach:
  n += (1 +4 +8);
  break;
 case Rwalk:
  n += 2;
  n += f->nwqid*(1 +4 +8);
  break;
 case Ropen:
 case Rcreate:
  n += (1 +4 +8);
  n += 4;
  break;
 case Ropenfd:
  n += (1 +4 +8);
  n += 4;
  n += 4;
  break;
 case Rread:
  n += 4;
  n += f->count;
  break;
 case Rwrite:
  n += 4;
  break;
 case Rclunk:
  break;
 case Rremove:
  break;
 case Rstat:
  n += 2;
  n += f->nstat;
  break;
 case Rwstat:
  break;
 }
 return n;
}

variable_types: struct Fcall { unsigned char type; unsigned int fid; unsigned short tag; unsigned int msize; char *version; unsigned short oldtag; char *ename; struct Qid { unsigned long long path; unsigned long vers; unsigned char type; } qid; unsigned int iounit; struct Qid aqid; unsigned int afid; char *uname; char *aname; unsigned int perm; char *name; unsigned char mode; unsigned int newfid; unsigned short nwname; char *wname[16]; unsigned short nwqid; struct Qid wqid[16]; long long offset; unsigned int count; char *data; unsigned short nstat; unsigned char *stat; int unixfd; int errornum; int uidnum; char *extension; } *

variable_types:
n
unsigned int

user_defined_types: struct Fcall { unsigned char type; unsigned int fid; unsigned short tag; unsigned int msize; char *version; unsigned short oldtag; char *ename; struct Qid qid; unsigned int iounit; struct Qid aqid; unsigned int afid; char *uname; char *aname; unsigned int perm; char *name; unsigned char mode; unsigned int newfid; unsigned short nwname; char *wname[16]; unsigned short nwqid; struct Qid wqid[16]; long long offset; unsigned int count; char *data; unsigned short nstat; unsigned char *stat; int unixfd; int errornum; int uidnum; char *extension; }


variable_types:
ap
unsigned char *

variable_types:
nap
unsigned int

variable_types:
i
unsigned int

variable_types:
size
unsigned int

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


vsnprint

original_code:
int
vsnprint(char *buf, int len, char *fmt, va_list args)
{
 Fmt f;
 if(len <= 0)
  return -1;
 f.runes = 0;
 f.start = buf;
 f.to = buf;
 f.stop = buf + len - 1;
 f.flush = 0;
 f.farg = 0;
 f.nfmt = 0;
 __builtin_va_copy(f.args,args);
 fmtlocaleinit(&f, 0, 0, 0);
 dofmt(&f, fmt);
 __builtin_va_end(f.args);
 *(char*)f.to = '\0';
 return (char*)f.to - buf;
}

canonical_original_code:
int vsnprint(char *buf, int len, char *fmt, __builtin_va_list args)
{
 struct Fmt f;
 if(len <= 0)
  return -1;
 f.runes = 0;
 f.start = buf;
 f.to = buf;
 f.stop = buf + len - 1;
 f.flush = 0;
 f.farg = 0;
 f.nfmt = 0;
 __builtin_va_copy(f.args,args);
 fmtlocaleinit(&f, 0, 0, 0);
 dofmt(&f, fmt);
 __builtin_va_end(f.args);
 *(char *)f.to = '\0';
 return (char *)f.to - buf;
}

variable_types:
buf
char *

variable_types: len 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; }


gstring

decompiled_code:
unsigned __int64 __fastcall gstring(unsigned __int16 *a1, unsigned __int64 a2, _QWORD *a3)
{
size_t v4; // rdx
unsigned __int64 v5; // r13
__int64 v6; // rbp
void *v7; // rax

if ( a2 < (unsigned __int64)(a1 + 1) )
return 0LL;
v4 = *a1;
v5 = (unsigned __int64)a1 + v4 + 2;
if ( v5 > a2 )
return 0LL;
v6 = *a1;
v7 = memmove((char *)a1 + 1, a1 + 1, v4);
*((_BYTE *)a1 + v6 + 1) = 0;
*a3 = v7;
return v5;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(unsigned __int16 *a1, unsigned __int64 a2, _QWORD *a3)
{
size_t v4; // rdx
unsigned __int64 v5; // r13
__int64 v6; // rbp
void *v7; // rax

if ( a2 < (unsigned __int64)(a1 + 1) )
return 0LL;
v4 = *a1;
v5 = (unsigned __int64)a1 + v4 + 2;
if ( v5 > a2 )
return 0LL;
v6 = *a1;
v7 = memmove((char *)a1 + 1, a1 + 1, v4);
*((_BYTE *)a1 + v6 + 1) = 0;
*a3 = v7;
return v5;
}

original_code:
static
uchar*
gstring(uchar *p, uchar *ep, char **s)
{
 uint n;
 if(p+2 > ep)
  return ((void*)0);
 n = ((p)[0]|((p)[1]<<8));
 p += 2 - 1;
 if(p+n+1 > ep)
  return ((void*)0);
 memmove(p, p + 1, n);
 p[n] = '\0';
 *s = (char*)p;
 p += n+1;
 return p;
}

canonical_original_code:
static unsigned char *gstring(unsigned char *p, unsigned char *ep, char **s)
{
 unsigned int n;
 if(p+2 > ep)
  return ((void *)0);
 n = ((p)[0]|((p)[1]<<8));
 p += 2 - 1;
 if(p+n+1 > ep)
  return ((void *)0);
 memmove(p, p + 1, n);
 p[n] = '\0';
 *s = (char *)p;
 p += n+1;
 return p;
}

variable_types:
ep
unsigned char *

variable_types:
s
char **


decompiled_code:
__int64 __fastcall convM2S(int *a1, unsigned int a2, __int64 a3)
{
unsigned __int64 v3; // rbp
unsigned __int16 *v5; // rdi
unsigned int v6; // er13
char v7; // al
unsigned __int16 *v9; // r8
_DWORD *v11; // rax
bool v12; // zf
unsigned __int16 v13; // ax
_QWORD *v14; // r14
unsigned int v15; // er15
unsigned __int16 v16; // ax
__int64 v17; // rdx
__int64 v18; // rdx
int v19; // er9
unsigned __int16 *v20; // rdi
int v21; // eax
unsigned __int16 *v22; // rdi
__int64 v23; // rdx
__int64 v24; // rax
unsigned __int64 v25; // rax
unsigned __int64 v26; // rax
unsigned __int64 v27; // rdx
unsigned __int16 *v28; // rax
__int64 v29; // rdx
__int64 v30; // rax
__int64 v31; // rax
__int64 v32; // rax

v3 = (unsigned __int64)a1 + a2;
v5 = (unsigned __int16 *)((char *)a1 + 7);
if ( v3 >= (unsigned __int64)v5 )
{
v6 = *a1;
if ( (unsigned int)*a1 > 6 )
{
v7 = *((_BYTE *)a1 + 4);
v9 = v5;
*(_BYTE *)a3 = v7;
*(_WORD *)(a3 + 8) = *(_WORD *)((char *)a1 + 5);
switch ( v7 )
{
case 'b':
case 'p':
v9 = (unsigned __int16 *)(a1 + 3);
if ( (unsigned __int64)(a1 + 3) > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
*(_BYTE *)(a3 + 136) = *((_BYTE *)a1 + 11);
goto LABEL_7;
case 'c':
case 'q':
case 's':
v11 = (_DWORD *)gqid((__int64)v5, v3, a3 + 40);
if ( !v11 )
return 0;
v9 = (unsigned __int16 *)(v11 + 1);
if ( (unsigned __int64)(v11 + 1) > v3 )
return 0;
v12 = *(_BYTE *)a3 == 99;
*(_DWORD *)(a3 + 64) = *v11;
if ( !v12 )
goto LABEL_7;
v9 = (unsigned __int16 *)(v11 + 2);
if ( (unsigned __int64)(v11 + 2) > v3 )
return 0;
*(_DWORD *)(a3 + 712) = v11[1];
goto LABEL_7;
case 'd':
case 'e':
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
*(_DWORD *)(a3 + 12) = *(int *)((char *)a1 + 7);
v9 = (unsigned __int16 *)gstring((unsigned __int16 *)((char *)a1 + 11), v3, (_QWORD *)(a3 + 16));
goto LABEL_5;
case 'f':
v20 = (unsigned __int16 *)((char *)a1 + 11);
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
v21 = *(int *)((char *)a1 + 7);
goto LABEL_39;
case 'g':
v9 = (unsigned __int16 *)gqid((__int64)v5, v3, a3 + 72);
goto LABEL_5;
case 'h':
if ( v3 < (unsigned __int64)a1 + 11 )
return 0;
v20 = (unsigned __int16 *)((char *)a1 + 15);
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
if ( (unsigned __int64)a1 + 15 > v3 )
return 0;
v21 = *(int *)((char *)a1 + 11);
LABEL_39:
*(_DWORD *)(a3 + 96) = v21;
v22 = (unsigned __int16 *)gstring(v20, v3, (_QWORD *)(a3 + 104));
if ( !v22 )
return 0;
v9 = (unsigned __int16 *)gstring(v22, v3, (_QWORD *)(a3 + 112));
if ( !v9 )
return 0;
*(_DWORD *)(a3 + 720) = -1;
goto LABEL_5;
case 'i':
v9 = (unsigned __int16 *)gqid((__int64)v5, v3, a3 + 40);
goto LABEL_5;
case 'k':
v25 = gstring(v5, v3, (_QWORD *)(a3 + 32));
*(_DWORD *)(a3 + 716) = 0;
v9 = (unsigned __int16 *)v25;
goto LABEL_5;
case 'l':
v9 = (unsigned __int16 *)((char *)a1 + 9);
if ( (unsigned __int64)a1 + 9 > v3 )
return 0;
*(_WORD *)(a3 + 24) = *(_WORD *)((char *)a1 + 7);
goto LABEL_7;
case 'm':
case 'y':
case '{':
case '\x7F':
goto LABEL_5;
case 'n':
v9 = (unsigned __int16 *)((char *)a1 + 17);
if ( (unsigned __int64)a1 + 17 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
*(_DWORD *)(a3 + 140) = *(int *)((char *)a1 + 11);
v13 = *(_WORD *)((char *)a1 + 15);
*(_WORD *)(a3 + 144) = v13;
if ( v13 > 0x10u )
return 0;
if ( !v13 )
goto LABEL_7;
v14 = (_QWORD *)(a3 + 152);
v15 = 0;
while ( 1 )
{
v9 = (unsigned __int16 *)gstring(v9, v3, v14);
if ( !v9 )
return 0;
++v15;
++v14;
if ( *(unsigned __int16 *)(a3 + 144) <= v15 )
goto LABEL_5;
}
case 'o':
v9 = (unsigned __int16 *)((char *)a1 + 9);
if ( (unsigned __int64)a1 + 9 > v3 )
return 0;
v16 = *(_WORD *)((char *)a1 + 7);
*(_WORD *)(a3 + 280) = v16;
if ( v16 > 0x10u )
return 0;
if ( !v16 )
goto LABEL_7;
v17 = a3 + 288;
break;
case 'r':
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
v26 = gstring((unsigned __int16 *)((char *)a1 + 11), v3, (_QWORD *)(a3 + 128));
v27 = v26;
if ( !v26 )
return 0;
v28 = (unsigned __int16 *)(v26 + 5);
if ( v3 < (unsigned __int64)v28 )
return 0;
v9 = v28;
*(_DWORD *)(a3 + 120) = *(_DWORD *)v27;
*(_BYTE *)(a3 + 136) = *(_BYTE *)(v27 + 4);
goto LABEL_5;
case 't':
v9 = (unsigned __int16 *)((char *)a1 + 23);
if ( (unsigned __int64)a1 + 23 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
*(_QWORD *)(a3 + 672) = *(_QWORD *)((char *)a1 + 11);
*(_DWORD *)(a3 + 680) = *(int *)((char *)a1 + 19);
goto LABEL_7;
case 'u':
v29 = (__int64)a1 + 11;
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
v30 = *(unsigned int *)((char *)a1 + 7);
v9 = (unsigned __int16 *)(v29 + v30);
*(_DWORD *)(a3 + 680) = v30;
if ( v29 + v30 > v3 )
return 0;
goto LABEL_54;
case 'v':
v29 = (__int64)a1 + 23;
if ( (unsigned __int64)a1 + 23 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
*(_QWORD *)(a3 + 672) = *(_QWORD *)((char *)a1 + 11);
v31 = *(unsigned int *)((char *)a1 + 19);
v9 = (unsigned __int16 *)(v29 + v31);
*(_DWORD *)(a3 + 680) = v31;
if ( v29 + v31 > v3 )
return 0;
LABEL_54:
*(_QWORD *)(a3 + 688) = v29;
goto LABEL_7;
case 'w':
v9 = (unsigned __int16 *)((char *)a1 + 11);
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
*(_DWORD *)(a3 + 680) = *(int *)((char *)a1 + 7);
goto LABEL_7;
case 'x':
case 'z':
case '|':
v9 = (unsigned __int16 *)((char *)a1 + 11);
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
goto LABEL_7;
case '}':
v23 = (__int64)a1 + 9;
if ( (unsigned __int64)a1 + 9 > v3 )
return 0;
v32 = *(unsigned __int16 *)((char *)a1 + 7);
*(_WORD *)(a3 + 696) = v32;
v9 = (unsigned __int16 *)(v23 + v32);
if ( v23 + v32 > v3 )
return 0;
goto LABEL_44;
case '~':
v23 = (__int64)a1 + 13;
if ( (unsigned __int64)a1 + 13 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
v24 = *(unsigned __int16 *)((char *)a1 + 11);
*(_WORD *)(a3 + 696) = v24;
v9 = (unsigned __int16 *)(v23 + v24);
if ( v23 + v24 > v3 )
return 0;
LABEL_44:
*(_QWORD *)(a3 + 704) = v23;
goto LABEL_7;
default:
return 0;
}
while ( 1 )
{
v9 = (unsigned __int16 *)gqid((__int64)v9, v3, v17);
if ( !v9 )
break;
v17 = v18 + 24;
if ( *(unsigned __int16 *)(a3 + 280) <= (unsigned int)(v19 + 1) )
{
LABEL_5:
if ( v9 && (unsigned __int64)v9 <= v3 )
{
LABEL_7:
if ( v9 == (unsigned __int16 *)((char *)a1 + v6) )
return v6;
}
return 0;
}
}
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1, unsigned int a2, __int64 a3)
{
unsigned __int64 v3; // rbp
unsigned __int16 *v5; // rdi
unsigned int v6; // er13
char v7; // al
unsigned __int16 *v9; // r8
_DWORD *v11; // rax
bool v12; // zf
unsigned __int16 v13; // ax
_QWORD *v14; // r14
unsigned int v15; // er15
unsigned __int16 v16; // ax
__int64 v17; // rdx
__int64 v18; // rdx
int v19; // er9
unsigned __int16 *v20; // rdi
int v21; // eax
unsigned __int16 *v22; // rdi
__int64 v23; // rdx
__int64 v24; // rax
unsigned __int64 v25; // rax
unsigned __int64 v26; // rax
unsigned __int64 v27; // rdx
unsigned __int16 *v28; // rax
__int64 v29; // rdx
__int64 v30; // rax
__int64 v31; // rax
__int64 v32; // rax

v3 = (unsigned __int64)a1 + a2;
v5 = (unsigned __int16 *)((char *)a1 + 7);
if ( v3 >= (unsigned __int64)v5 )
{
v6 = *a1;
if ( (unsigned int)*a1 > 6 )
{
v7 = *((_BYTE *)a1 + 4);
v9 = v5;
*(_BYTE *)a3 = v7;
*(_WORD *)(a3 + 8) = *(_WORD *)((char *)a1 + 5);
switch ( v7 )
{
case 'b':
case 'p':
v9 = (unsigned __int16 *)(a1 + 3);
if ( (unsigned __int64)(a1 + 3) > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
*(_BYTE *)(a3 + 136) = *((_BYTE *)a1 + 11);
goto LABEL_7;
case 'c':
case 'q':
case 's':
v11 = (_DWORD *)func0((__int64)v5, v3, a3 + 40);
if ( !v11 )
return 0;
v9 = (unsigned __int16 *)(v11 + 1);
if ( (unsigned __int64)(v11 + 1) > v3 )
return 0;
v12 = *(_BYTE *)a3 == 99;
*(_DWORD *)(a3 + 64) = *v11;
if ( !v12 )
goto LABEL_7;
v9 = (unsigned __int16 *)(v11 + 2);
if ( (unsigned __int64)(v11 + 2) > v3 )
return 0;
*(_DWORD *)(a3 + 712) = v11[1];
goto LABEL_7;
case 'd':
case 'e':
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
*(_DWORD *)(a3 + 12) = *(int *)((char *)a1 + 7);
v9 = (unsigned __int16 *)func1((unsigned __int16 *)((char *)a1 + 11), v3, (_QWORD *)(a3 + 16));
goto LABEL_5;
case 'f':
v20 = (unsigned __int16 *)((char *)a1 + 11);
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
v21 = *(int *)((char *)a1 + 7);
goto LABEL_39;
case 'g':
v9 = (unsigned __int16 *)func0((__int64)v5, v3, a3 + 72);
goto LABEL_5;
case 'h':
if ( v3 < (unsigned __int64)a1 + 11 )
return 0;
v20 = (unsigned __int16 *)((char *)a1 + 15);
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
if ( (unsigned __int64)a1 + 15 > v3 )
return 0;
v21 = *(int *)((char *)a1 + 11);
LABEL_39:
*(_DWORD *)(a3 + 96) = v21;
v22 = (unsigned __int16 *)func1(v20, v3, (_QWORD *)(a3 + 104));
if ( !v22 )
return 0;
v9 = (unsigned __int16 *)func1(v22, v3, (_QWORD *)(a3 + 112));
if ( !v9 )
return 0;
*(_DWORD *)(a3 + 720) = -1;
goto LABEL_5;
case 'i':
v9 = (unsigned __int16 *)func0((__int64)v5, v3, a3 + 40);
goto LABEL_5;
case 'k':
v25 = func1(v5, v3, (_QWORD *)(a3 + 32));
*(_DWORD *)(a3 + 716) = 0;
v9 = (unsigned __int16 *)v25;
goto LABEL_5;
case 'l':
v9 = (unsigned __int16 *)((char *)a1 + 9);
if ( (unsigned __int64)a1 + 9 > v3 )
return 0;
*(_WORD *)(a3 + 24) = *(_WORD *)((char *)a1 + 7);
goto LABEL_7;
case 'm':
case 'y':
case '{':
case '\x7F':
goto LABEL_5;
case 'n':
v9 = (unsigned __int16 *)((char *)a1 + 17);
if ( (unsigned __int64)a1 + 17 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
*(_DWORD *)(a3 + 140) = *(int *)((char *)a1 + 11);
v13 = *(_WORD *)((char *)a1 + 15);
*(_WORD *)(a3 + 144) = v13;
if ( v13 > 0x10u )
return 0;
if ( !v13 )
goto LABEL_7;
v14 = (_QWORD *)(a3 + 152);
v15 = 0;
while ( 1 )
{
v9 = (unsigned __int16 *)func1(v9, v3, v14);
if ( !v9 )
return 0;
++v15;
++v14;
if ( *(unsigned __int16 *)(a3 + 144) <= v15 )
goto LABEL_5;
}
case 'o':
v9 = (unsigned __int16 *)((char *)a1 + 9);
if ( (unsigned __int64)a1 + 9 > v3 )
return 0;
v16 = *(_WORD *)((char *)a1 + 7);
*(_WORD *)(a3 + 280) = v16;
if ( v16 > 0x10u )
return 0;
if ( !v16 )
goto LABEL_7;
v17 = a3 + 288;
break;
case 'r':
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
v26 = func1((unsigned __int16 *)((char *)a1 + 11), v3, (_QWORD *)(a3 + 128));
v27 = v26;
if ( !v26 )
return 0;
v28 = (unsigned __int16 *)(v26 + 5);
if ( v3 < (unsigned __int64)v28 )
return 0;
v9 = v28;
*(_DWORD *)(a3 + 120) = *(_DWORD *)v27;
*(_BYTE *)(a3 + 136) = *(_BYTE *)(v27 + 4);
goto LABEL_5;
case 't':
v9 = (unsigned __int16 *)((char *)a1 + 23);
if ( (unsigned __int64)a1 + 23 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
*(_QWORD *)(a3 + 672) = *(_QWORD *)((char *)a1 + 11);
*(_DWORD *)(a3 + 680) = *(int *)((char *)a1 + 19);
goto LABEL_7;
case 'u':
v29 = (__int64)a1 + 11;
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
v30 = *(unsigned int *)((char *)a1 + 7);
v9 = (unsigned __int16 *)(v29 + v30);
*(_DWORD *)(a3 + 680) = v30;
if ( v29 + v30 > v3 )
return 0;
goto LABEL_54;
case 'v':
v29 = (__int64)a1 + 23;
if ( (unsigned __int64)a1 + 23 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
*(_QWORD *)(a3 + 672) = *(_QWORD *)((char *)a1 + 11);
v31 = *(unsigned int *)((char *)a1 + 19);
v9 = (unsigned __int16 *)(v29 + v31);
*(_DWORD *)(a3 + 680) = v31;
if ( v29 + v31 > v3 )
return 0;
LABEL_54:
*(_QWORD *)(a3 + 688) = v29;
goto LABEL_7;
case 'w':
v9 = (unsigned __int16 *)((char *)a1 + 11);
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
*(_DWORD *)(a3 + 680) = *(int *)((char *)a1 + 7);
goto LABEL_7;
case 'x':
case 'z':
case '|':
v9 = (unsigned __int16 *)((char *)a1 + 11);
if ( (unsigned __int64)a1 + 11 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
goto LABEL_7;
case '}':
v23 = (__int64)a1 + 9;
if ( (unsigned __int64)a1 + 9 > v3 )
return 0;
v32 = *(unsigned __int16 *)((char *)a1 + 7);
*(_WORD *)(a3 + 696) = v32;
v9 = (unsigned __int16 *)(v23 + v32);
if ( v23 + v32 > v3 )
return 0;
goto LABEL_44;
case '~':
v23 = (__int64)a1 + 13;
if ( (unsigned __int64)a1 + 13 > v3 )
return 0;
*(_DWORD *)(a3 + 4) = *(int *)((char *)a1 + 7);
v24 = *(unsigned __int16 *)((char *)a1 + 11);
*(_WORD *)(a3 + 696) = v24;
v9 = (unsigned __int16 *)(v23 + v24);
if ( v23 + v24 > v3 )
return 0;
LABEL_44:
*(_QWORD *)(a3 + 704) = v23;
goto LABEL_7;
default:
return 0;
}
while ( 1 )
{
v9 = (unsigned __int16 *)func0((__int64)v9, v3, v17);
if ( !v9 )
break;
v17 = v18 + 24;
if ( *(unsigned __int16 *)(a3 + 280) <= (unsigned int)(v19 + 1) )
{
LABEL_5:
if ( v9 && (unsigned __int64)v9 <= v3 )
{
LABEL_7:
if ( v9 == (unsigned __int16 *)((char *)a1 + v6) )
return v6;
}
return 0;
}
}
}
}
return 0;
}


countde

original_code:
static int
countde(char *p, int n)
{
 char *e;
 int m;
 struct dirent *de;
 e = p+n;
 m = 0;
 while(p < e){
  de = (struct dirent*)p;
  if(de->d_reclen <= 4+2+2+1 || p+de->d_reclen > e)
   break;
  if(de->d_name[0]=='.' && de->d_name[1]==0)
   de->d_name[0] = 0;
  else if(de->d_name[0]=='.' && de->d_name[1]=='.' && de->d_name[2]==0)
   de->d_name[0] = 0;
  m++;
  p += de->d_reclen;
 }
 return m;
}

canonical_original_code:
static int countde(char *p, int n)
{
 char *e;
 int m;
 struct dirent *de;
 e = p+n;
 m = 0;
 while(p < e){
  de = (struct dirent *)p;
  if(de->d_reclen <= 4+2+2+1 || p+de->d_reclen > e)
   break;
  if(de->d_name[0]=='.' && de->d_name[1]==0)
   de->d_name[0] = 0;
  else if(de->d_name[0]=='.' && de->d_name[1]=='.' && de->d_name[2]==0)
   de->d_name[0] = 0;
  m++;
  p += de->d_reclen;
 }
 return m;
}

variable_types:
p
char *

variable_types: n int

variable_types:
e
char *

variable_types: m int

variable_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; } *


mygetdents

decompiled_code:
__ssize_t __fastcall mygetdents(__int64 fd, char *buf, int a3)
{
__off64_t basep[4]; // [rsp+8h] [rbp-20h] BYREF

basep[0] = p9seek(fd, 0LL, 1LL);
return getdirentries64(fd, buf, a3, basep);
}

canonical_decompiled_code:
__ssize_t __fastcall func1(__int64 fd, char *buf, int a3)
{
__off64_t basep[4]; // [rsp+8h] [rbp-20h] BYREF

basep[0] = p9seek(fd, 0LL, 1LL);
return getdirentries64(fd, buf, a3, basep);
}

original_code:
static int
mygetdents(int fd, struct dirent *buf, int n)
{
 off_t off;
 int nn;
 off = p9seek(fd, 0, 1);
 nn = getdirentries(fd, (void*)buf, n, &off);
 return nn;
}

canonical_original_code:
static int mygetdents(int fd, struct dirent *buf, int n)
{
 long off;
 int nn;
 off = p9seek(fd, 0, 1);
 nn = getdirentries(fd, (void *)buf, n, &off);
 return nn;
}

variable_types: fd int

variable_types: off long

variable_types: nn int

user_defined_types: struct dirent { unsigned long d_ino; long d_off; unsigned short d_reclen; unsigned char d_type; char d_name[256]; }