setup

decompiled_code:
__int64 __fastcall setup(char *file)
{
void *v1; // rax
void *v2; // rbx
void *v3; // rax
unsigned int v4; // er12
__int64 v5; // rbp
bool v6; // cc
unsigned __int64 v7; // rsi
__int64 v8; // rsi
__int64 v9; // rax
bool v10; // zf
__int64 v11; // rsi
int v12; // eax
__int64 v13; // rdx
__int64 v14; // rax
__int64 v15; // rcx
__int64 v16; // rdi
__int64 v17; // rsi
__int64 v18; // rax
__int64 v19; // rdx
__int64 v21; // r12
__int64 v22; // rax
__int64 v23; // rbx
__int64 v24; // r14
__int64 v25; // r13
__int64 v26; // r12
void *v27; // rax
__int64 v28; // rdx
__int64 v29; // rcx
int v30; // eax
int v31; // ebx
int v32; // ebx
size_t v33; // rbx
__int64 v34; // rbx
__int64 v35; // rbp
void *v36; // rax
int *v37; // rax
char *v38; // rax
__int64 v39; // rdi
__int64 v40; // rsi
__int64 v41; // r8
__int64 v42; // r11
__int64 v43; // r9
__int64 v44; // rax
__int64 v45; // rsi
__int64 v46; // rdi
__int64 v47; // rsi
__int64 v48; // rax
__int64 v49; // rdx
__int64 v50; // r10
__int64 v51; // rdi
__int64 v52; // rax
__int64 v53; // rsi
int v54; // eax
int *v55; // rax
char *v56; // rax
struct stat64 v57; // [rsp+0h] [rbp-B8h] BYREF

havesb = 0;
fswritefd = -1;
if ( stat64(file, &v57) < 0 )
{
v37 = _errno_location();
v4 = 0;
v38 = strerror(*v37);
printf("Can't stat %s: %s\n", file, v38);
return v4;
}
if ( (v57.st_mode & 0xF000) != 0x2000 )
{
pfatal("%s is not a character device", file);
if ( !(unsigned int)reply("CONTINUE") )
return 0;
}
fsreadfd = open64(file, 0);
if ( fsreadfd < 0 )
{
v55 = _errno_location();
v4 = 0;
v56 = strerror(*v55);
printf("Can't open %s: %s\n", file, v56);
return v4;
}
if ( preen )
{
if ( nflag )
goto LABEL_7;
}
else
{
printf("** %s", file);
if ( nflag )
goto LABEL_7;
}
fswritefd = open64(file, 1);
if ( fswritefd >= 0 )
{
if ( preen )
goto LABEL_10;
LABEL_42:
putchar(10);
goto LABEL_10;
}
LABEL_7:
fswritefd = -1;
if ( preen )
pfatal("NO WRITE ACCESS");
printf(" (NO WRITE)");
if ( !preen )
goto LABEL_42;
LABEL_10:
*((_BYTE *)&sblk + 40) = 0;
fsmodified = 0;
lfdir = 0LL;
*((_DWORD *)&sblk + 4) = -1;
*((_DWORD *)&sblk + 7) = 0;
*((_BYTE *)&asblk + 40) = 0;
*((_DWORD *)&asblk + 4) = -1;
*((_DWORD *)&asblk + 7) = 0;
v1 = malloc(0x2000uLL);
*((_QWORD *)&sblk + 4) = v1;
v2 = v1;
v3 = malloc(0x2000uLL);
*((_QWORD *)&asblk + 4) = v3;
if ( !v3 || !v2 )
errexit("cannot allocate space for superblock\n");
secsize = 512LL;
dev_bsize = 512LL;
if ( (unsigned int)readsb(1) )
{
v5 = *((_QWORD *)&sblk + 4);
maxfsblock = *(_QWORD *)(v5 + 56);
v6 = *(_QWORD *)(v5 + 240) <= 1uLL;
maxino = *(_QWORD *)(v5 + 352) * *(_QWORD *)(v5 + 72);
if ( !v6 )
{
pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
v30 = reply("SET TO DEFAULT");
v5 = *((_QWORD *)&sblk + 4);
if ( v30 == 1 )
{
*(_QWORD *)(v5 + 240) = 0LL;
*((_BYTE *)&sblk + 40) = 1;
}
}
v7 = *(_QWORD *)(v5 + 104);
if ( v7 > 0x63 )
{
pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", v7);
v54 = reply("SET TO DEFAULT");
v5 = *((_QWORD *)&sblk + 4);
if ( v54 == 1 )
{
*(_QWORD *)(v5 + 104) = 10LL;
*((_BYTE *)&sblk + 40) = 1;
}
}
v8 = *(_QWORD *)(v5 + 256);
if ( v8 <= 0 || (v9 = *(_QWORD *)(v5 + 320), v8 > v9) )
{
pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK", v8);
v10 = preen == 0;
*(_QWORD *)(*((_QWORD *)&sblk + 4) + 256LL) = 1LL;
if ( !v10 && (puts(" (FIXED)"), preen) || (unsigned int)reply("SET TO DEFAULT") == 1 )
{
*((_BYTE *)&sblk + 40) = 1;
*((_BYTE *)&asblk + 40) = 1;
}
v5 = *((_QWORD *)&sblk + 4);
v9 = *(_QWORD *)(v5 + 320);
}
v11 = *(_QWORD *)(v5 + 248);
if ( v11 < v9 || v11 > 2 * v9 )
{
pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK", v11);
v10 = preen == 0;
*(_QWORD *)(*((_QWORD *)&sblk + 4) + 248LL) = *(_QWORD *)(*((_QWORD *)&sblk + 4) + 320LL);
if ( !v10 && (puts(" (FIXED)"), preen) || (unsigned int)reply("SET TO DEFAULT") == 1 )
{
*((_BYTE *)&sblk + 40) = 1;
*((_BYTE *)&asblk + 40) = 1;
}
v5 = *((_QWORD *)&sblk + 4);
}
v12 = cvtlevel;
if ( *(__int64 *)(v5 + 1864) > 1 )
{
newinofmt = 1;
}
else
{
v13 = *(_QWORD *)(v5 + 128);
newinofmt = 0;
*(_QWORD *)(v5 + 1880) = ~v13;
*(_QWORD *)(v5 + 1888) = ~*(_QWORD *)(v5 + 136);
if ( v12 > 1 )
{
if ( preen )
{
pwarn("CONVERTING TO NEW INODE FORMAT\n");
}
else if ( !(unsigned int)reply("CONVERT TO NEW INODE FORMAT") )
{
return 0;
}
v5 = *((_QWORD *)&sblk + 4);
++doinglevel2;
*((_BYTE *)&sblk + 40) = 1;
v14 = *(_QWORD *)(v5 + 216);
v15 = *(_QWORD *)(v5 + 80);
*(_QWORD *)(v5 + 1864) = 2LL;
*(_QWORD *)(v5 + 1856) = 60LL;
*((_BYTE *)&asblk + 40) = 1;
v16 = v15 * v14;
v17 = v15 * v14 * v14;
v18 = v17 * v14;
v19 = v17 + 12 * v15 - 1;
LODWORD(v17) = cvtlevel;
*(_QWORD *)(v5 + 1872) = v16 + v19 + v18;
*(_QWORD *)(v5 + 1880) = ~*(_QWORD *)(v5 + 128);
*(_QWORD *)(v5 + 1888) = ~*(_QWORD *)(v5 + 136);
if ( (int)v17 <= 0 || *(_QWORD *)(v5 + 1904) != -1LL )
goto LABEL_85;
goto LABEL_36;
}
}
if ( v12 <= 0 || *(_QWORD *)(v5 + 1904) != -1LL )
{
if ( !*((_BYTE *)&asblk + 40) )
{
LABEL_49:
v21 = *(_QWORD *)(v5 + 296);
if ( v21 > 0 )
{
v22 = *(_QWORD *)(v5 + 80);
v23 = 0LL;
v24 = 0LL;
v25 = 0LL;
do
{
v26 = v21 - v24;
if ( v26 > v22 )
v26 = v22;
v27 = calloc(1uLL, (unsigned int)v26);
v28 = *(_QWORD *)(v5 + 96);
v29 = *(_QWORD *)(v5 + 184);
*(_QWORD *)(v5 + 8 * v23 + 928) = v27;
if ( (unsigned int)bread((unsigned int)fsreadfd, v27, (*(int *)(v5 + 288) + v23 * v28) << v29, v26) )
{
if ( !v25 )
{
pfatal("BAD SUMMARY INFORMATION");
if ( !(unsigned int)reply("CONTINUE") )
errexit(&unk_122A);
}
v25 = 1LL;
}
v5 = *((_QWORD *)&sblk + 4);
++v23;
v22 = *(_QWORD *)(v5 + 80);
v21 = *(_QWORD *)(v5 + 296);
v24 += v22;
}
while ( v21 > v24 );
}
v31 = maxfsblock + 7;
if ( maxfsblock + 7 < 0 )
v31 = maxfsblock + 14;
v32 = (v31 >> 3) + 1;
blockmap = (__int64)calloc(v32 & 0xFFFFFFFE, 1uLL);
if ( blockmap )
{
v33 = (unsigned int)(maxino + 1);
statemap = (__int64)calloc(v33, 1uLL);
if ( statemap )
{
typemap = (__int64)calloc(v33, 1uLL);
if ( typemap )
{
lncntp = (__int64)calloc(v33, 2uLL);
if ( lncntp )
{
v34 = *(_QWORD *)(v5 + 368);
inplast = 0LL;
numdirs = v34;
listmax = v34 + 10;
inpsort = (__int64)calloc((unsigned int)(v34 + 10), 8uLL);
v35 = inpsort;
v36 = calloc((unsigned int)v34, 8uLL);
inphead = (__int64)v36;
if ( v35 && v36 )
{
v4 = 1;
bufinit();
return v4;
}
printf("cannot alloc %u bytes for inphead\n", 8LL * (unsigned int)v34);
}
else
{
printf("cannot alloc %u bytes for lncntp\n", 2 * v33);
}
}
else
{
printf("cannot alloc %u bytes for typemap\n", (unsigned int)v33);
}
}
else
{
printf("cannot alloc %u bytes for statemap\n", (unsigned int)v33);
}
}
else
{
printf("cannot alloc %u bytes for blockmap\n", v32 & 0xFFFFFFFE);
}
ckfini();
return 0;
}
LABEL_85:
if ( !bflag )
{
memmove(*((void **)&asblk + 4), (const void *)v5, *(_QWORD *)(v5 + 192));
flush((unsigned int)fswritefd, &asblk);
v5 = *((_QWORD *)&sblk + 4);
}
goto LABEL_49;
}
LABEL_36:
if ( preen )
{
pwarn("CONVERTING TO NEW CYLINDER GROUP FORMAT\n");
}
else if ( !(unsigned int)reply("CONVERT TO NEW CYLINDER GROUP FORMAT") )
{
return 0;
}
v5 = *((_QWORD *)&sblk + 4);
++doinglevel1;
v39 = *(_QWORD *)(v5 + 344);
v40 = *(_QWORD *)(v5 + 352);
*(_QWORD *)(v5 + 1904) = 1LL;
v41 = *(_QWORD *)(v5 + 232);
v42 = *(_QWORD *)(v5 + 1848);
*(_QWORD *)(v5 + 1912) = 8LL;
*(_QWORD *)(v5 + 1920) = 1192LL;
*(_QWORD *)(v5 + 1928) = 1944LL;
v43 = 2 * (12 * v39 + 176);
v44 = v40 + 14;
v45 = v40 + 7;
if ( v45 < 0 )
v45 = v44;
v46 = *(_QWORD *)(v5 + 328) * v39;
v47 = v45 >> 3;
v48 = v46 / v41 + 7;
if ( v48 < 0 )
v48 = v46 / v41 + 14;
v49 = 0LL;
v50 = v48 >> 3;
if ( v42 > 0 )
{
v51 = v46 / (v41 << *(_QWORD *)(v5 + 176));
v52 = v51 + 7;
if ( v51 + 7 < 0 )
v52 = v51 + 14;
v49 = (v52 >> 3) + 8 * v42;
}
v53 = *(_QWORD *)(v5 + 1888) + v47;
*((_BYTE *)&sblk + 40) = 1;
*((_BYTE *)&asblk + 40) = 1;
*(_QWORD *)(v5 + 304) = *(_QWORD *)(v5 + 136) & (v49 + v50 + v53 + v43);
goto LABEL_85;
}
v4 = bflag;
if ( bflag || preen || !(unsigned int)calcsb_constprop_0() || !(unsigned int)reply("LOOK FOR ALTERNATE SUPERBLOCKS") )
return 0;
printf(
"%s %s\n%s %s\n%s %s\n",
"SEARCH FOR ALTERNATE SUPER-BLOCK",
"FAILED. YOU MUST USE THE",
"-b OPTION TO FSCK TO SPECIFY THE",
"LOCATION OF AN ALTERNATE",
"SUPER-BLOCK TO SUPPLY NEEDED",
"INFORMATION; SEE fsck(8).");
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *file)
{
void *v1; // rax
void *v2; // rbx
void *v3; // rax
unsigned int v4; // er12
__int64 v5; // rbp
bool v6; // cc
unsigned __int64 v7; // rsi
__int64 v8; // rsi
__int64 v9; // rax
bool v10; // zf
__int64 v11; // rsi
int v12; // eax
__int64 v13; // rdx
__int64 v14; // rax
__int64 v15; // rcx
__int64 v16; // rdi
__int64 v17; // rsi
__int64 v18; // rax
__int64 v19; // rdx
__int64 v21; // r12
__int64 v22; // rax
__int64 v23; // rbx
__int64 v24; // r14
__int64 v25; // r13
__int64 v26; // r12
void *v27; // rax
__int64 v28; // rdx
__int64 v29; // rcx
int v30; // eax
int v31; // ebx
int v32; // ebx
size_t v33; // rbx
__int64 v34; // rbx
__int64 v35; // rbp
void *v36; // rax
int *v37; // rax
char *v38; // rax
__int64 v39; // rdi
__int64 v40; // rsi
__int64 v41; // r8
__int64 v42; // r11
__int64 v43; // r9
__int64 v44; // rax
__int64 v45; // rsi
__int64 v46; // rdi
__int64 v47; // rsi
__int64 v48; // rax
__int64 v49; // rdx
__int64 v50; // r10
__int64 v51; // rdi
__int64 v52; // rax
__int64 v53; // rsi
int v54; // eax
int *v55; // rax
char *v56; // rax
struct stat64 v57; // [rsp+0h] [rbp-B8h] BYREF

havesb = 0;
fswritefd = -1;
if ( stat64(file, &v57) < 0 )
{
v37 = _errno_location();
v4 = 0;
v38 = strerror(*v37);
printf("Can't stat %s: %s\n", file, v38);
return v4;
}
if ( (v57.st_mode & 0xF000) != 0x2000 )
{
pfatal("%s is not a character device", file);
if ( !(unsigned int)reply("CONTINUE") )
return 0;
}
fsreadfd = open64(file, 0);
if ( fsreadfd < 0 )
{
v55 = _errno_location();
v4 = 0;
v56 = strerror(*v55);
printf("Can't open %s: %s\n", file, v56);
return v4;
}
if ( preen )
{
if ( nflag )
goto LABEL_7;
}
else
{
printf("** %s", file);
if ( nflag )
goto LABEL_7;
}
fswritefd = open64(file, 1);
if ( fswritefd >= 0 )
{
if ( preen )
goto LABEL_10;
LABEL_42:
putchar(10);
goto LABEL_10;
}
LABEL_7:
fswritefd = -1;
if ( preen )
pfatal("NO WRITE ACCESS");
printf(" (NO WRITE)");
if ( !preen )
goto LABEL_42;
LABEL_10:
*((_BYTE *)&sblk + 40) = 0;
fsmodified = 0;
lfdir = 0LL;
*((_DWORD *)&sblk + 4) = -1;
*((_DWORD *)&sblk + 7) = 0;
*((_BYTE *)&asblk + 40) = 0;
*((_DWORD *)&asblk + 4) = -1;
*((_DWORD *)&asblk + 7) = 0;
v1 = malloc(0x2000uLL);
*((_QWORD *)&sblk + 4) = v1;
v2 = v1;
v3 = malloc(0x2000uLL);
*((_QWORD *)&asblk + 4) = v3;
if ( !v3 || !v2 )
errexit("cannot allocate space for superblock\n");
secsize = 512LL;
dev_bsize = 512LL;
if ( (unsigned int)func2(1) )
{
v5 = *((_QWORD *)&sblk + 4);
maxfsblock = *(_QWORD *)(v5 + 56);
v6 = *(_QWORD *)(v5 + 240) <= 1uLL;
maxino = *(_QWORD *)(v5 + 352) * *(_QWORD *)(v5 + 72);
if ( !v6 )
{
pfatal("UNDEFINED OPTIMIZATION IN SUPERBLOCK");
v30 = reply("SET TO DEFAULT");
v5 = *((_QWORD *)&sblk + 4);
if ( v30 == 1 )
{
*(_QWORD *)(v5 + 240) = 0LL;
*((_BYTE *)&sblk + 40) = 1;
}
}
v7 = *(_QWORD *)(v5 + 104);
if ( v7 > 0x63 )
{
pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", v7);
v54 = reply("SET TO DEFAULT");
v5 = *((_QWORD *)&sblk + 4);
if ( v54 == 1 )
{
*(_QWORD *)(v5 + 104) = 10LL;
*((_BYTE *)&sblk + 40) = 1;
}
}
v8 = *(_QWORD *)(v5 + 256);
if ( v8 <= 0 || (v9 = *(_QWORD *)(v5 + 320), v8 > v9) )
{
pwarn("IMPOSSIBLE INTERLEAVE=%d IN SUPERBLOCK", v8);
v10 = preen == 0;
*(_QWORD *)(*((_QWORD *)&sblk + 4) + 256LL) = 1LL;
if ( !v10 && (puts(" (FIXED)"), preen) || (unsigned int)reply("SET TO DEFAULT") == 1 )
{
*((_BYTE *)&sblk + 40) = 1;
*((_BYTE *)&asblk + 40) = 1;
}
v5 = *((_QWORD *)&sblk + 4);
v9 = *(_QWORD *)(v5 + 320);
}
v11 = *(_QWORD *)(v5 + 248);
if ( v11 < v9 || v11 > 2 * v9 )
{
pwarn("IMPOSSIBLE NPSECT=%d IN SUPERBLOCK", v11);
v10 = preen == 0;
*(_QWORD *)(*((_QWORD *)&sblk + 4) + 248LL) = *(_QWORD *)(*((_QWORD *)&sblk + 4) + 320LL);
if ( !v10 && (puts(" (FIXED)"), preen) || (unsigned int)reply("SET TO DEFAULT") == 1 )
{
*((_BYTE *)&sblk + 40) = 1;
*((_BYTE *)&asblk + 40) = 1;
}
v5 = *((_QWORD *)&sblk + 4);
}
v12 = cvtlevel;
if ( *(__int64 *)(v5 + 1864) > 1 )
{
newinofmt = 1;
}
else
{
v13 = *(_QWORD *)(v5 + 128);
newinofmt = 0;
*(_QWORD *)(v5 + 1880) = ~v13;
*(_QWORD *)(v5 + 1888) = ~*(_QWORD *)(v5 + 136);
if ( v12 > 1 )
{
if ( preen )
{
pwarn("CONVERTING TO NEW INODE FORMAT\n");
}
else if ( !(unsigned int)reply("CONVERT TO NEW INODE FORMAT") )
{
return 0;
}
v5 = *((_QWORD *)&sblk + 4);
++doinglevel2;
*((_BYTE *)&sblk + 40) = 1;
v14 = *(_QWORD *)(v5 + 216);
v15 = *(_QWORD *)(v5 + 80);
*(_QWORD *)(v5 + 1864) = 2LL;
*(_QWORD *)(v5 + 1856) = 60LL;
*((_BYTE *)&asblk + 40) = 1;
v16 = v15 * v14;
v17 = v15 * v14 * v14;
v18 = v17 * v14;
v19 = v17 + 12 * v15 - 1;
LODWORD(v17) = cvtlevel;
*(_QWORD *)(v5 + 1872) = v16 + v19 + v18;
*(_QWORD *)(v5 + 1880) = ~*(_QWORD *)(v5 + 128);
*(_QWORD *)(v5 + 1888) = ~*(_QWORD *)(v5 + 136);
if ( (int)v17 <= 0 || *(_QWORD *)(v5 + 1904) != -1LL )
goto LABEL_85;
goto LABEL_36;
}
}
if ( v12 <= 0 || *(_QWORD *)(v5 + 1904) != -1LL )
{
if ( !*((_BYTE *)&asblk + 40) )
{
LABEL_49:
v21 = *(_QWORD *)(v5 + 296);
if ( v21 > 0 )
{
v22 = *(_QWORD *)(v5 + 80);
v23 = 0LL;
v24 = 0LL;
v25 = 0LL;
do
{
v26 = v21 - v24;
if ( v26 > v22 )
v26 = v22;
v27 = calloc(1uLL, (unsigned int)v26);
v28 = *(_QWORD *)(v5 + 96);
v29 = *(_QWORD *)(v5 + 184);
*(_QWORD *)(v5 + 8 * v23 + 928) = v27;
if ( (unsigned int)bread((unsigned int)fsreadfd, v27, (*(int *)(v5 + 288) + v23 * v28) << v29, v26) )
{
if ( !v25 )
{
pfatal("BAD SUMMARY INFORMATION");
if ( !(unsigned int)reply("CONTINUE") )
errexit(&unk_122A);
}
v25 = 1LL;
}
v5 = *((_QWORD *)&sblk + 4);
++v23;
v22 = *(_QWORD *)(v5 + 80);
v21 = *(_QWORD *)(v5 + 296);
v24 += v22;
}
while ( v21 > v24 );
}
v31 = maxfsblock + 7;
if ( maxfsblock + 7 < 0 )
v31 = maxfsblock + 14;
v32 = (v31 >> 3) + 1;
blockmap = (__int64)calloc(v32 & 0xFFFFFFFE, 1uLL);
if ( blockmap )
{
v33 = (unsigned int)(maxino + 1);
statemap = (__int64)calloc(v33, 1uLL);
if ( statemap )
{
typemap = (__int64)calloc(v33, 1uLL);
if ( typemap )
{
lncntp = (__int64)calloc(v33, 2uLL);
if ( lncntp )
{
v34 = *(_QWORD *)(v5 + 368);
inplast = 0LL;
numdirs = v34;
listmax = v34 + 10;
inpsort = (__int64)calloc((unsigned int)(v34 + 10), 8uLL);
v35 = inpsort;
v36 = calloc((unsigned int)v34, 8uLL);
inphead = (__int64)v36;
if ( v35 && v36 )
{
v4 = 1;
bufinit();
return v4;
}
printf("cannot alloc %u bytes for inphead\n", 8LL * (unsigned int)v34);
}
else
{
printf("cannot alloc %u bytes for lncntp\n", 2 * v33);
}
}
else
{
printf("cannot alloc %u bytes for typemap\n", (unsigned int)v33);
}
}
else
{
printf("cannot alloc %u bytes for statemap\n", (unsigned int)v33);
}
}
else
{
printf("cannot alloc %u bytes for blockmap\n", v32 & 0xFFFFFFFE);
}
ckfini();
return 0;
}
LABEL_85:
if ( !bflag )
{
memmove(*((void **)&asblk + 4), (const void *)v5, *(_QWORD *)(v5 + 192));
flush((unsigned int)fswritefd, &asblk);
v5 = *((_QWORD *)&sblk + 4);
}
goto LABEL_49;
}
LABEL_36:
if ( preen )
{
pwarn("CONVERTING TO NEW CYLINDER GROUP FORMAT\n");
}
else if ( !(unsigned int)reply("CONVERT TO NEW CYLINDER GROUP FORMAT") )
{
return 0;
}
v5 = *((_QWORD *)&sblk + 4);
++doinglevel1;
v39 = *(_QWORD *)(v5 + 344);
v40 = *(_QWORD *)(v5 + 352);
*(_QWORD *)(v5 + 1904) = 1LL;
v41 = *(_QWORD *)(v5 + 232);
v42 = *(_QWORD *)(v5 + 1848);
*(_QWORD *)(v5 + 1912) = 8LL;
*(_QWORD *)(v5 + 1920) = 1192LL;
*(_QWORD *)(v5 + 1928) = 1944LL;
v43 = 2 * (12 * v39 + 176);
v44 = v40 + 14;
v45 = v40 + 7;
if ( v45 < 0 )
v45 = v44;
v46 = *(_QWORD *)(v5 + 328) * v39;
v47 = v45 >> 3;
v48 = v46 / v41 + 7;
if ( v48 < 0 )
v48 = v46 / v41 + 14;
v49 = 0LL;
v50 = v48 >> 3;
if ( v42 > 0 )
{
v51 = v46 / (v41 << *(_QWORD *)(v5 + 176));
v52 = v51 + 7;
if ( v51 + 7 < 0 )
v52 = v51 + 14;
v49 = (v52 >> 3) + 8 * v42;
}
v53 = *(_QWORD *)(v5 + 1888) + v47;
*((_BYTE *)&sblk + 40) = 1;
*((_BYTE *)&asblk + 40) = 1;
*(_QWORD *)(v5 + 304) = *(_QWORD *)(v5 + 136) & (v49 + v50 + v53 + v43);
goto LABEL_85;
}
v4 = bflag;
if ( bflag || preen || !(unsigned int)func0() || !(unsigned int)reply("LOOK FOR ALTERNATE SUPERBLOCKS") )
return 0;
printf(
"%s %s\n%s %s\n%s %s\n",
"SEARCH FOR ALTERNATE SUPER-BLOCK",
"FAILED. YOU MUST USE THE",
"-b OPTION TO FSCK TO SPECIFY THE",
"LOCATION OF AN ALTERNATE",
"SUPER-BLOCK TO SUPPLY NEEDED",
"INFORMATION; SEE fsck(8).");
return v4;
}

original_code:
int
setup (char *dev)
{
  struct stat st;
  int changedsb;
  size_t bmapsize;
  device_name = dev;
  if (stat (dev, &st) == -1)
    {
      error (0, (*__errno_location ()), "%s", dev);
      return 0;
    }
  if (!((((st.st_mode)) & 0170000) == (0020000)) && !((((st.st_mode)) & 0170000) == (0060000)))
    {
      problem (1, "%s is not a character or block device", dev);
      if (! reply ("CONTINUE"))
 return 0;
    }
  if (preen == 0)
    printf ("** %s", dev);
  if (!nowrite)
    readfd = open (dev, 02);
  if (nowrite || readfd == -1)
    {
      readfd = open (dev, 00);
      if (readfd == -1)
 {
   error (0, (*__errno_location ()), "%s", dev);
   return 0;
 }
      writefd = -1;
      nowrite = 1;
      if (preen)
 warning (1, "NO WRITE ACCESS");
      printf (" (NO WRITE)");
    }
  else
    writefd = readfd;
  if (preen == 0)
    printf ("\n");
  lfdir = 0;
  readblock (((daddr_t)(((daddr_t)(0)) + 8192 / 512)), sblock, 8192);
  changedsb = 0;
  if (sblock->fs_magic != 0x011954)
    {
      warning (1, "BAD MAGIC NUMBER");
      return 0;
    }
  if (sblock->fs_ncg < 1)
    {
      warning (1, "NCG OUT OF RANGE");
      return 0;
    }
  if (sblock->fs_cpg < 1)
    {
      warning (1, "CPG OUT OF RANGE");
      return 0;
    }
  if (sblock->fs_ncg * sblock->fs_cpg < sblock->fs_ncyl
      || (sblock->fs_ncg - 1) * sblock->fs_cpg >= sblock->fs_ncyl)
    {
      warning (1, "NCYL INCONSISTENT WITH NCG AND CPG");
      return 0;
    }
  if (sblock->fs_sbsize > 8192)
    {
      warning (1, "SBLOCK SIZE PREPONTEROUSLY LARGE");
      return 0;
    }
  if (sblock->fs_optim != 0 && sblock->fs_optim != 1)
    {
      problem (1, "UNDEFINED OPTIMIZATION IN SUPERBLOCK");
      if (reply ("SET TO DEFAULT"))
 {
   sblock->fs_optim = 0;
   changedsb = 1;
 }
    }
  if (sblock->fs_minfree < 0 || sblock->fs_minfree > 99)
    {
      problem (0, "IMPOSSIBLE MINFREE=%ld IN SUPERBLOCK", sblock->fs_minfree);
      if (preen || reply ("SET TO DEFAULT"))
 {
   sblock->fs_minfree = 10;
   changedsb = 1;
   pfix ("SET TO DEFAULT");
 }
    }
  if (sblock->fs_interleave < 1
      || sblock->fs_interleave > sblock->fs_nsect)
    {
      problem (0, "IMPOSSIBLE INTERLEAVE=%ld IN SUPERBLOCK",
        sblock->fs_interleave);
      if (preen || reply ("SET TO DEFAULT"))
 {
   sblock->fs_interleave = 1;
   changedsb = 1;
   pfix ("SET TO DEFAULT");
 }
    }
  if (sblock->fs_npsect < sblock->fs_nsect
      || sblock->fs_npsect > sblock->fs_nsect * 2)
    {
      problem (0, "IMPOSSIBLE NPSECT=%ld IN SUPERBLOCK", sblock->fs_npsect);
      if (preen || reply ("SET TO DEFAULT"))
 {
   sblock->fs_npsect = sblock->fs_nsect;
   changedsb = 1;
   pfix ("SET TO DEFAULT");
 }
    }
  if (sblock->fs_inodefmt >= 2)
    newinofmt = 1;
  else
    {
      sblock->fs_qbmask = ~sblock->fs_bmask;
      sblock->fs_qfmask = ~sblock->fs_fmask;
      newinofmt = 0;
    }
  if (changedsb)
    writeblock (((daddr_t)(((daddr_t)(0)) + 8192 / 512)), sblock, 8192);
  maxfsblock = sblock->fs_size;
  maxino = sblock->fs_ncg * sblock->fs_ipg;
  direct_symlink_extension = sblock->fs_maxsymlinklen > 0;
  bmapsize = (((((((maxfsblock)+((8)-1))/(8)))+((sizeof (short))-1))/(sizeof (short)))*(sizeof (short)));
  blockmap = calloc (bmapsize, sizeof (char));
  inodestate = calloc (maxino + 1, sizeof (char));
  typemap = calloc (maxino + 1, sizeof (char));
  linkcount = calloc (maxino + 1, sizeof (nlink_t));
  linkfound = calloc (maxino + 1, sizeof (nlink_t));
  return 1;
}

canonical_original_code:
int setup(char *dev)
{
  struct stat st;
  int changedsb;
  unsigned long bmapsize;
  device_name = dev;
  if (stat (dev, &st) == -1)
    {
      error (0, (*__errno_location ()), "%s", dev);
      return 0;
    }
  if (!((((st.st_mode)) & 0170000) == (0020000)) && !((((st.st_mode)) & 0170000) == (0060000)))
    {
      problem (1, "%s is not a character or block device", dev);
      if (! reply ("CONTINUE"))
 return 0;
    }
  if (preen == 0)
    printf ("** %s", dev);
  if (!nowrite)
    readfd = open (dev, 02);
  if (nowrite || readfd == -1)
    {
      readfd = open (dev, 00);
      if (readfd == -1)
 {
   error (0, (*__errno_location ()), "%s", dev);
   return 0;
 }
      writefd = -1;
      nowrite = 1;
      if (preen)
 warning (1, "NO WRITE ACCESS");
      printf (" (NO WRITE)");
    }
  else
    writefd = readfd;
  if (preen == 0)
    printf ("\n");
  lfdir = 0;
  readblock (((daddr_t)(((daddr_t)(0)) + 8192 / 512)), sblock, 8192);
  changedsb = 0;
  if (sblock->fs_magic != 0x011954)
    {
      warning (1, "BAD MAGIC NUMBER");
      return 0;
    }
  if (sblock->fs_ncg < 1)
    {
      warning (1, "NCG OUT OF RANGE");
      return 0;
    }
  if (sblock->fs_cpg < 1)
    {
      warning (1, "CPG OUT OF RANGE");
      return 0;
    }
  if (sblock->fs_ncg * sblock->fs_cpg < sblock->fs_ncyl
      || (sblock->fs_ncg - 1) * sblock->fs_cpg >= sblock->fs_ncyl)
    {
      warning (1, "NCYL INCONSISTENT WITH NCG AND CPG");
      return 0;
    }
  if (sblock->fs_sbsize > 8192)
    {
      warning (1, "SBLOCK SIZE PREPONTEROUSLY LARGE");
      return 0;
    }
  if (sblock->fs_optim != 0 && sblock->fs_optim != 1)
    {
      problem (1, "UNDEFINED OPTIMIZATION IN SUPERBLOCK");
      if (reply ("SET TO DEFAULT"))
 {
   sblock->fs_optim = 0;
   changedsb = 1;
 }
    }
  if (sblock->fs_minfree < 0 || sblock->fs_minfree > 99)
    {
      problem (0, "IMPOSSIBLE MINFREE=%ld IN SUPERBLOCK", sblock->fs_minfree);
      if (preen || reply ("SET TO DEFAULT"))
 {
   sblock->fs_minfree = 10;
   changedsb = 1;
   pfix ("SET TO DEFAULT");
 }
    }
  if (sblock->fs_interleave < 1
      || sblock->fs_interleave > sblock->fs_nsect)
    {
      problem (0, "IMPOSSIBLE INTERLEAVE=%ld IN SUPERBLOCK",
        sblock->fs_interleave);
      if (preen || reply ("SET TO DEFAULT"))
 {
   sblock->fs_interleave = 1;
   changedsb = 1;
   pfix ("SET TO DEFAULT");
 }
    }
  if (sblock->fs_npsect < sblock->fs_nsect
      || sblock->fs_npsect > sblock->fs_nsect * 2)
    {
      problem (0, "IMPOSSIBLE NPSECT=%ld IN SUPERBLOCK", sblock->fs_npsect);
      if (preen || reply ("SET TO DEFAULT"))
 {
   sblock->fs_npsect = sblock->fs_nsect;
   changedsb = 1;
   pfix ("SET TO DEFAULT");
 }
    }
  if (sblock->fs_inodefmt >= 2)
    newinofmt = 1;
  else
    {
      sblock->fs_qbmask = ~sblock->fs_bmask;
      sblock->fs_qfmask = ~sblock->fs_fmask;
      newinofmt = 0;
    }
  if (changedsb)
    writeblock (((daddr_t)(((daddr_t)(0)) + 8192 / 512)), sblock, 8192);
  maxfsblock = sblock->fs_size;
  maxino = sblock->fs_ncg * sblock->fs_ipg;
  direct_symlink_extension = sblock->fs_maxsymlinklen > 0;
  bmapsize = (((((((maxfsblock)+((8)-1))/(8)))+((sizeof (short))-1))/(sizeof (short)))*(sizeof (short)));
  blockmap = calloc (bmapsize, sizeof (char));
  inodestate = calloc (maxino + 1, sizeof (char));
  typemap = calloc (maxino + 1, sizeof (char));
  linkcount = calloc (maxino + 1, sizeof (nlink_t));
  linkfound = calloc (maxino + 1, sizeof (nlink_t));
  return 1;
}

variable_types:
dev
char *

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

variable_types: changedsb int

variable_types:
bmapsize
unsigned long


repo: jeremie-koenig/hurd

decompiled_code:
unsigned __int64 __fastcall inode_iterate(_QWORD *a1, __int64 (__fastcall *a2)(__int64, _QWORD), unsigned int a3)
{
unsigned __int64 result; // rax
__int64 v4; // rsi
unsigned __int64 v5; // rbp
__int64 v7; // r13
__int64 v8; // rdx
unsigned __int64 v9; // rbp
__int64 v10; // rbx
__int64 v11; // rdi
__int64 v12; // rbx
__int64 v13; // rdi
__int64 v14; // rdi
__int64 v15; // [rsp+0h] [rbp-48h]

result = *(unsigned __int16 *)a1;
v15 = 0LL;
if ( (result & 0xB000) != 0x2000 )
{
v4 = sblock;
v5 = a1[2];
if ( (result & 0xF000) != 0xA000
|| (result = *(_QWORD *)(sblock + 1856LL), result == -1LL)
|| result <= v5 && (result || a1[18]) )
{
v7 = 0LL;
v8 = 0LL;
v9 = (v5 - 1) >> *(_QWORD *)(sblock + 144LL);
while ( 1 )
{
if ( (_DWORD)v9 == (_DWORD)v7 && ((_DWORD)a1[2] & (unsigned int)*(_QWORD *)(v4 + 1880)) != 0 )
v10 = (*(_QWORD *)(v4 + 136) & (*(_QWORD *)(v4 + 1888) + (int)(a1[2] & *(_QWORD *)(v4 + 1880)))) >> *(_QWORD *)(v4 + 152);
else
LODWORD(v10) = *(_DWORD *)(v4 + 96);
v11 = *((unsigned int *)a1 + v7 + 18);
if ( (_DWORD)v11 )
{
result = a2(v11, (unsigned int)v10);
if ( (_DWORD)result != 1 )
return result;
v8 = v15;
}
++v7;
v8 += 8LL * (int)v10;
v15 = v8;
if ( v7 == 12 )
break;
v4 = sblock;
}
v12 = 0LL;
while ( 1 )
{
v13 = *((unsigned int *)a1 + v12 + 30);
if ( (_DWORD)v13 )
{
result = scaniblock_0(v13, v12);
if ( (_DWORD)result != 1 )
break;
}
if ( ++v12 == 3 )
{
result = a3;
if ( a3 )
{
v14 = a1[23];
if ( v14 )
result = ((__int64 (__fastcall *)(__int64, _QWORD, __int64))a2)(v14, *(_QWORD *)(sblock + 96LL), v15);
}
return result;
}
}
}
}
return result;
}

original_code:
static void
inode_iterate (struct dinode *dp,
        int (*fn) (daddr_t, int, off_t),
        int doaddrblocks)
{
  mode_t mode = dp->di_model & 0170000;
  int nb, maxb;
  off_t totaloffset = 0;
  int
  scaniblock (daddr_t iblock, int level)
    {
      int cont;
      daddr_t ptrs[((sblock)->fs_nindir)];
      int i;
      if (doaddrblocks)
 {
   cont = (*fn)(iblock, sblock->fs_frag, totaloffset);
   if (cont == RET_STOP)
     return RET_STOP;
   else if (cont == RET_BAD)
     return RET_GOOD;
 }
      readblock (((iblock) << (sblock)->fs_fsbtodb), ptrs, sblock->fs_bsize);
      for (i = 0; i < ((sblock)->fs_nindir); i++)
 {
   if (!ptrs[i])
     continue;
   if (level == 0)
     {
       cont = (*fn)(ptrs[i], sblock->fs_frag, totaloffset);
       totaloffset += sblock->fs_bsize;
     }
   else
     cont = scaniblock (ptrs[i], level - 1);
   if (cont == RET_STOP)
     return RET_STOP;
 }
      return RET_GOOD;
    }
  if (mode == 0060000 || mode == 0020000
      || (mode == 0120000 && sblock->fs_maxsymlinklen != -1
   && (dp->di_size < sblock->fs_maxsymlinklen
       || (sblock->fs_maxsymlinklen == 0 && dp->di_blocks == 0))))
    return;
  maxb = ((dp->di_size - 1) >> (sblock)->fs_bshift);
  totaloffset = 0;
  for (nb = 0; nb < 12; nb++)
    {
      int offset;
      int nfrags;
      if (nb == maxb && (offset = ((dp->di_size) & (sblock)->fs_qbmask)))
 nfrags = (((((offset) + (sblock)->fs_qfmask) & (sblock)->fs_fmask)) >> (sblock)->fs_fshift);
      else
 nfrags = sblock->fs_frag;
      if (dp->di_db[nb]
   && (*fn)(dp->di_db[nb], nfrags, totaloffset) != RET_GOOD)
 return;
      totaloffset += nfrags * sizeof (sblock->fs_fsize);
    }
  for (nb = 0; nb < 3; nb++)
    if (dp->di_ib[nb] && scaniblock (dp->di_ib[nb], nb) != RET_GOOD)
      return;
  if (doaddrblocks && dp->di_trans)
    (*fn)(dp->di_trans, sblock->fs_frag, totaloffset);
}

canonical_original_code:
static void inode_iterate(struct dinode *dp, int (*fn)(int, int, long), int doaddrblocks)
{
  unsigned int mode = dp->di_model & 0170000;
  int nb; int maxb;
  long totaloffset = 0;
  int
  scaniblock (daddr_t iblock, int level)
    {
      int cont;
      int ptrs[-1];
      int i;
      if (doaddrblocks)
 {
   cont = (*fn)(iblock, sblock->fs_frag, totaloffset);
   if (cont == RET_STOP)
     return RET_STOP;
   else if (cont == RET_BAD)
     return RET_GOOD;
 }
      readblock (((iblock) << (sblock)->fs_fsbtodb), ptrs, sblock->fs_bsize);
      for (i = 0; i < ((sblock)->fs_nindir); i++)
 {
   if (!ptrs[i])
     continue;
   if (level == 0)
     {
       cont = (*fn)(ptrs[i], sblock->fs_frag, totaloffset);
       totaloffset += sblock->fs_bsize;
     }
   else
     cont = scaniblock (ptrs[i], level - 1);
   if (cont == RET_STOP)
     return RET_STOP;
 }
      return RET_GOOD;
    }
  if (mode == 0060000 || mode == 0020000
      || (mode == 0120000 && sblock->fs_maxsymlinklen != -1
   && (dp->di_size < sblock->fs_maxsymlinklen
       || (sblock->fs_maxsymlinklen == 0 && dp->di_blocks == 0))))
    return;
  maxb = ((dp->di_size - 1) >> (sblock)->fs_bshift);
  totaloffset = 0;
  for (nb = 0; nb < 12; nb++)
    {
      int offset;
      int nfrags;
      if (nb == maxb && (offset = ((dp->di_size) & (sblock)->fs_qbmask)))
 nfrags = (((((offset) + (sblock)->fs_qfmask) & (sblock)->fs_fmask)) >> (sblock)->fs_fshift);
      else
 nfrags = sblock->fs_frag;
      if (dp->di_db[nb]
   && (*fn)(dp->di_db[nb], nfrags, totaloffset) != RET_GOOD)
 return;
      totaloffset += nfrags * sizeof (sblock->fs_fsize);
    }
  for (nb = 0; nb < 3; nb++)
    if (dp->di_ib[nb] && scaniblock (dp->di_ib[nb], nb) != RET_GOOD)
      return;
  if (doaddrblocks && dp->di_trans)
    (*fn)(dp->di_trans, sblock->fs_frag, totaloffset);
}

variable_types: struct dinode { unsigned short di_model; short di_nlink; union { unsigned long diu_author; unsigned short diu_oldids[2]; } di_u; unsigned long di_size; struct timespec { long tv_sec; long tv_nsec; } di_atime; struct timespec di_mtime; struct timespec di_ctime; int di_db[12]; int di_ib[3]; unsigned long di_flags; long di_blocks; long di_gen; unsigned long di_uid; unsigned long di_gid; unsigned short di_modeh; unsigned short di_spare; long di_trans; } *

variable_types:
fn
int (*)(int, int, long)

variable_types: doaddrblocks int

variable_types:
mode
unsigned int

variable_types: nb int

variable_types: maxb int

variable_types: totaloffset long

variable_types: cont int

variable_types:
ptrs
int [-1]

variable_types: i int

variable_types: offset int

variable_types: nfrags int

return_type: void

user_defined_types: struct dinode { unsigned short di_model; short di_nlink; union { unsigned long diu_author; unsigned short diu_oldids[2]; } di_u; unsigned long di_size; struct timespec di_atime; struct timespec di_mtime; struct timespec di_ctime; int di_db[12]; int di_ib[3]; unsigned long di_flags; long di_blocks; long di_gen; unsigned long di_uid; unsigned long di_gid; unsigned short di_modeh; unsigned short di_spare; long di_trans; }


decompiled_code:
unsigned __int64 __fastcall datablocks_iterate(_QWORD *a1, __int64 (__fastcall *a2)(__int64, _QWORD))
{
return inode_iterate(a1, a2, 0);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(_QWORD *a1, __int64 (__fastcall *a2)(__int64, _QWORD))
{
return func1(a1, a2, 0);
}

original_code:
void
datablocks_iterate (struct dinode *dp,
      int (*fn) (daddr_t, int, off_t))
{
  inode_iterate (dp, fn, 0);
}

canonical_original_code:
void datablocks_iterate(struct dinode *dp, int (*fn)(int, int, long))
{
  inode_iterate (dp, fn, 0);
}

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


decompiled_code:
unsigned __int64 __fastcall allblock_iterate(_QWORD *a1, __int64 (__fastcall *a2)(__int64, _QWORD))
{
return inode_iterate(a1, a2, 1u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(_QWORD *a1, __int64 (__fastcall *a2)(__int64, _QWORD))
{
return func1(a1, a2, 1u);
}

original_code:
void
allblock_iterate (struct dinode *dp,
    int (*fn) (daddr_t, int, off_t))
{
  inode_iterate (dp, fn, 1);
}

canonical_original_code:
void allblock_iterate(struct dinode *dp, int (*fn)(int, int, long))
{
  inode_iterate (dp, fn, 1);
}


allocino

decompiled_code:
__int64 __fastcall allocino(__int64 a1, int a2)
{
__int64 v2; // r12
_BYTE *v3; // rdx
struct timeval v5; // [rsp+0h] [rbp-E8h] BYREF
__int16 v6[8]; // [rsp+10h] [rbp-D8h] BYREF
__int64 v7; // [rsp+20h] [rbp-C8h]
__m128i v8[2]; // [rsp+28h] [rbp-C0h] BYREF
__m128i v9; // [rsp+48h] [rbp-A0h]
__int64 v10; // [rsp+A0h] [rbp-48h]
__int16 v11; // [rsp+C0h] [rbp-28h]

if ( a1 )
{
v2 = 0LL;
v3 = (_BYTE *)(a1 + inodestate);
if ( *(_BYTE *)(a1 + inodestate) )
return v2;
v2 = a1;
LABEL_5:
*v3 = 5 * ((a2 & 0xF000) == 0x4000) + 1;
getinode(v2, v6);
v11 = HIWORD(a2);
v6[0] = a2;
gettimeofday(&v5, 0LL);
++num_files;
v8[0].m128i_i64[0] = v5.tv_sec;
v7 = 0LL;
v10 = 0LL;
v8[0].m128i_i64[1] = 1000 * v5.tv_usec;
v9 = _mm_loadu_si128(v8);
v8[1] = v9;
write_inode(v2, v6);
*(_BYTE *)(typemap + v2) = (unsigned __int16)a2 >> 12;
return v2;
}
v2 = 2LL;
if ( (unsigned __int64)maxino > 2 )
{
while ( 1 )
{
v3 = (_BYTE *)(inodestate + v2);
if ( !*(_BYTE *)(inodestate + v2) )
break;
if ( ++v2 == maxino )
return 0LL;
}
goto LABEL_5;
}
if ( maxino != 2LL )
{
v3 = (_BYTE *)(inodestate + 2);
goto LABEL_5;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
__int64 v2; // r12
_BYTE *v3; // rdx
struct timeval v5; // [rsp+0h] [rbp-E8h] BYREF
__int16 v6[8]; // [rsp+10h] [rbp-D8h] BYREF
__int64 v7; // [rsp+20h] [rbp-C8h]
__m128i v8[2]; // [rsp+28h] [rbp-C0h] BYREF
__m128i v9; // [rsp+48h] [rbp-A0h]
__int64 v10; // [rsp+A0h] [rbp-48h]
__int16 v11; // [rsp+C0h] [rbp-28h]

if ( a1 )
{
v2 = 0LL;
v3 = (_BYTE *)(a1 + inodestate);
if ( *(_BYTE *)(a1 + inodestate) )
return v2;
v2 = a1;
LABEL_5:
*v3 = 5 * ((a2 & 0xF000) == 0x4000) + 1;
getinode(v2, v6);
v11 = HIWORD(a2);
v6[0] = a2;
gettimeofday(&v5, 0LL);
++num_files;
v8[0].m128i_i64[0] = v5.tv_sec;
v7 = 0LL;
v10 = 0LL;
v8[0].m128i_i64[1] = 1000 * v5.tv_usec;
v9 = _mm_loadu_si128(v8);
v8[1] = v9;
write_inode(v2, v6);
*(_BYTE *)(typemap + v2) = (unsigned __int16)a2 >> 12;
return v2;
}
v2 = 2LL;
if ( (unsigned __int64)maxino > 2 )
{
while ( 1 )
{
v3 = (_BYTE *)(inodestate + v2);
if ( !*(_BYTE *)(inodestate + v2) )
break;
if ( ++v2 == maxino )
return 0LL;
}
goto LABEL_5;
}
if ( maxino != 2LL )
{
v3 = (_BYTE *)(inodestate + 2);
goto LABEL_5;
}
return 0LL;
}

original_code:
ino_t
allocino (ino_t request, mode_t mode)
{
  ino_t ino;
  struct dinode dino;
  struct timeval tv;
  if (request)
    {
      if (inodestate[request] != 0)
 return 0;
      ino = request;
    }
  else
    {
      for (ino = ((ino_t)2); ino < maxino; ino++)
 if (inodestate[ino] == 0)
   break;
      if (ino == maxino)
 return 0;
    }
  if ((mode & 0170000) == 0040000)
    inodestate[ino] = 2 | 4;
  else
    inodestate[ino] = 1;
  getinode (ino, &dino);
  dino.di_modeh = (mode & 0xffff0000) >> 16;
  dino.di_model = (mode & 0x0000ffff);
  gettimeofday (&tv, 0);
  dino.di_atime.tv_sec = tv.tv_sec;
  dino.di_atime.tv_nsec = tv.tv_usec * 1000;
  dino.di_mtime = dino.di_ctime = dino.di_atime;
  dino.di_size = 0;
  dino.di_blocks = 0;
  num_files++;
  write_inode (ino, &dino);
  typemap[ino] = (((mode) & 0170000) >> 12);
  return ino;
}

canonical_original_code:
unsigned long allocino(unsigned long request, unsigned int mode)
{
  unsigned long ino;
  struct dinode dino;
  struct timeval tv;
  if (request)
    {
      if (inodestate[request] != 0)
 return 0;
      ino = request;
    }
  else
    {
      for (ino = ((unsigned long)2); ino < maxino; ino++)
 if (inodestate[ino] == 0)
   break;
      if (ino == maxino)
 return 0;
    }
  if ((mode & 0170000) == 0040000)
    inodestate[ino] = 2 | 4;
  else
    inodestate[ino] = 1;
  getinode (ino, &dino);
  dino.di_modeh = (mode & 0xffff0000) >> 16;
  dino.di_model = (mode & 0x0000ffff);
  gettimeofday (&tv, 0);
  dino.di_atime.tv_sec = tv.tv_sec;
  dino.di_atime.tv_nsec = tv.tv_usec * 1000;
  dino.di_mtime = dino.di_ctime = dino.di_atime;
  dino.di_size = 0;
  dino.di_blocks = 0;
  num_files++;
  write_inode (ino, &dino);
  typemap[ino] = (((mode) & 0170000) >> 12);
  return ino;
}

variable_types:
request
unsigned long

variable_types:
ino
unsigned long

variable_types: struct dinode { unsigned short di_model; short di_nlink; union { unsigned long diu_author; unsigned short diu_oldids[2]; } di_u; unsigned long di_size; struct timespec { long tv_sec; long tv_nsec; } di_atime; struct timespec di_mtime; struct timespec di_ctime; int di_db[12]; int di_ib[3]; unsigned long di_flags; long di_blocks; long di_gen; unsigned long di_uid; unsigned long di_gid; unsigned short di_modeh; unsigned short di_spare; long di_trans; }

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

return_type: unsigned long


freeino

decompiled_code:
__int64 __fastcall freeino(__int64 a1)
{
__int64 result; // rax
_QWORD v2[25]; // [rsp+0h] [rbp-C8h] BYREF

getinode(a1, v2);
allblock_iterate(v2, (__int64 (__fastcall *)(__int64, _QWORD))clearblock_1);
clear_inode(a1, v2);
result = inodestate;
*(_BYTE *)(inodestate + a1) = 0;
--num_files;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
_QWORD v2[25]; // [rsp+0h] [rbp-C8h] BYREF

getinode(a1, v2);
func4(v2, (__int64 (__fastcall *)(__int64, _QWORD))clearblock_1);
clear_inode(a1, v2);
result = inodestate;
*(_BYTE *)(inodestate + a1) = 0;
--num_files;
return result;
}

original_code:
void
freeino (ino_t inum)
{
  struct dinode dino;
  int
  clearblock (daddr_t bno, int nfrags, off_t offset)
    {
      int i;
      for (i = 0; i < nfrags; i++)
 {
   if (check_range (bno + i, 1))
     return RET_BAD;
   if (((blockmap)[(bno + i)/8] & (1<<((bno + i)%8))))
     {
       struct dups *dlp;
       for (dlp = duplist; dlp; dlp = dlp->next)
  {
    if (dlp->dup != bno + i)
      continue;
    dlp->dup = duplist->dup;
    dlp = duplist;
    duplist = duplist->next;
    free (dlp);
    break;
  }
       if (dlp == 0)
  ((blockmap)[(bno + i)/8] &= ~(1<<(bno + i)%8));
     }
 }
      return RET_GOOD;
    }
  getinode (inum, &dino);
  allblock_iterate (&dino, clearblock);
  clear_inode (inum, &dino);
  inodestate[inum] = 0;
  num_files--;
}

canonical_original_code:
void freeino(unsigned long inum)
{
  struct dinode dino;
  int
  clearblock (daddr_t bno, int nfrags, off_t offset)
    {
      int i;
      for (i = 0; i < nfrags; i++)
 {
   if (check_range (bno + i, 1))
     return RET_BAD;
   if (((blockmap)[(bno + i)/8] & (1<<((bno + i)%8))))
     {
       struct dups *dlp;
       for (dlp = duplist; dlp; dlp = dlp->next)
  {
    if (dlp->dup != bno + i)
      continue;
    dlp->dup = duplist->dup;
    dlp = duplist;
    duplist = duplist->next;
    free (dlp);
    break;
  }
       if (dlp == 0)
  ((blockmap)[(bno + i)/8] &= ~(1<<(bno + i)%8));
     }
 }
      return RET_GOOD;
    }
  getinode (inum, &dino);
  allblock_iterate (&dino, clearblock);
  clear_inode (inum, &dino);
  inodestate[inum] = 0;
  num_files--;
}

variable_types:
inum
unsigned long

variable_types: struct dups { struct dups *next; int dup; } *


decompiled_code:
char *__fastcall shared_domain(char *s, char *a2)
{
char *v2; // rbx
size_t v3; // rax
char *v4; // r8
char *v5; // rax

if ( !s )
return 0LL;
if ( !a2 )
return 0LL;
v2 = &a2[strlen(a2)];
v3 = strlen(s);
v4 = &s[v3];
if ( a2 < v2 )
{
v5 = &s[v3];
if ( s < v4 )
{
do
{
if ( *v2 != *v5 )
break;
if ( *v5 == 46 )
v4 = v5;
--v5;
--v2;
if ( s >= v5 )
break;
}
while ( a2 < v2 );
}
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, char *a2)
{
char *v2; // rbx
size_t v3; // rax
char *v4; // r8
char *v5; // rax

if ( !s )
return 0LL;
if ( !a2 )
return 0LL;
v2 = &a2[strlen(a2)];
v3 = strlen(s);
v4 = &s[v3];
if ( a2 < v2 )
{
v5 = &s[v3];
if ( s < v4 )
{
do
{
if ( *v2 != *v5 )
break;
if ( *v5 == 46 )
v4 = v5;
--v5;
--v2;
if ( s >= v5 )
break;
}
while ( a2 < v2 );
}
}
return v4;
}

original_code:
char *
shared_domain (char *host1, char *host2)
{
  char *shared, *e1, *e2;
  if (!host1 || !host2)
    return 0;
  e2 = host2 + strlen (host2);
  e1 = host1 + strlen (host1);
  shared = e1;
  if (*e1 == '.')
    e1--;
  if (*e2 == '.')
    e2--;
  while (e1 > host1 && e2 > host2 && *e2 == *e1)
    {
      if (*e1 == '.')
 shared = e1;
      e1--;
      e2--;
    }
  return shared;
}

canonical_original_code:
char *shared_domain(char *host1, char *host2)
{
  char *shared; char *e1; char *e2;
  if (!host1 || !host2)
    return 0;
  e2 = host2 + strlen (host2);
  e1 = host1 + strlen (host1);
  shared = e1;
  if (*e1 == '.')
    e1--;
  if (*e2 == '.')
    e2--;
  while (e1 > host1 && e2 > host2 && *e2 == *e1)
    {
      if (*e1 == '.')
 shared = e1;
      e1--;
      e2--;
    }
  return shared;
}

variable_types:
shared
char *

return_type: char *


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

v1 = *(__int64 (**)(void))(a1 + 32);
if ( v1 )
result = v1();
else
result = 95LL;
return result;
}

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

v1 = *(__int64 (**)(void))(a1 + 32);
if ( v1 )
result = v1();
else
result = 95LL;
return result;
}

original_code:
error_t
ftp_conn_start_get_stats (struct ftp_conn *conn,
     const char *name, int contents,
     int *fd, void **state)
{
  if (conn->syshooks.start_get_stats)
    return
      (*conn->syshooks.start_get_stats) (conn, name, contents, fd, state);
  else
    return 95;
}

canonical_original_code:
int ftp_conn_start_get_stats(struct ftp_conn *conn, char *name, int contents, int *fd, void **state)
{
  if (conn->syshooks.start_get_stats)
    return
      (*conn->syshooks.start_get_stats) (conn, name, contents, fd, state);
  else
    return 95;
}

variable_types: struct ftp_conn { struct ftp_conn_params { void *addr; unsigned long addr_len; int addr_type; char *user; } *params; struct ftp_conn_hooks { void (*choose_syshooks)(struct ftp_conn *conn, char *syst); void (*cntl_debug)(struct ftp_conn *conn, int type, char *txt); void (*opened)(struct ftp_conn *conn); int (*get_login_param)(struct ftp_conn *conn, int type, char **txt); void (*closed)(struct ftp_conn *conn); int (*init)(struct ftp_conn *conn); void (*fini)(struct ftp_conn *conn); int (*interrupt_check)(struct ftp_conn *conn); } *hooks; struct ftp_conn_syshooks { int (*pasv_addr)(struct ftp_conn *conn, char *txt, struct sockaddr { unsigned short sa_family; char sa_data[14]; } **addr); int (*interp_err)(struct ftp_conn *conn, char *txt, int *poss_errs); int (*start_get_stats)(struct ftp_conn *conn, char *name, int contents, int *fd, void **state); int (*cont_get_stats)(struct ftp_conn *conn, int fd, void *state, int (*add_stat)(char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stat, char *symlink_target, void *hook), void *hook); int (*append_name)(struct ftp_conn *conn, char *dir, char *name, char **composite); int (*basename)(struct ftp_conn *conn, char **name); } syshooks; int syshooks_valid; int control; char *line; unsigned long line_sz; unsigned long line_offs; unsigned long line_len; char *reply_txt; unsigned long reply_txt_sz; char *cwd; char *type; void *hook; int use_passive; struct sockaddr *actv_data_addr; } *

variable_types:
name
char *

variable_types: contents int

variable_types:
fd
int *

variable_types:
state
void **

return_type: int

user_defined_types: struct ftp_conn { struct ftp_conn_params *params; struct ftp_conn_hooks *hooks; struct ftp_conn_syshooks syshooks; int syshooks_valid; int control; char *line; unsigned long line_sz; unsigned long line_offs; unsigned long line_len; char *reply_txt; unsigned long reply_txt_sz; char *cwd; char *type; void *hook; int use_passive; struct sockaddr *actv_data_addr; }

user_defined_types: struct ftp_conn_syshooks { int (*pasv_addr)(struct ftp_conn *conn, char *txt, struct sockaddr **addr); int (*interp_err)(struct ftp_conn *conn, char *txt, int *poss_errs); int (*start_get_stats)(struct ftp_conn *conn, char *name, int contents, int *fd, void **state); int (*cont_get_stats)(struct ftp_conn *conn, int fd, void *state, int (*add_stat)(char *name, struct stat *stat, char *symlink_target, void *hook), void *hook); int (*append_name)(struct ftp_conn *conn, char *dir, char *name, char **composite); int (*basename)(struct ftp_conn *conn, char **name); }

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


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

v1 = *(__int64 (**)(void))(a1 + 40);
if ( v1 )
result = v1();
else
result = 95LL;
return result;
}

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

v1 = *(__int64 (**)(void))(a1 + 40);
if ( v1 )
result = v1();
else
result = 95LL;
return result;
}

original_code:
error_t
ftp_conn_cont_get_stats (struct ftp_conn *conn, int fd, void *state,
    ftp_conn_add_stat_fun_t add_stat, void *hook)
{
  if (conn->syshooks.cont_get_stats)
    return (*conn->syshooks.cont_get_stats) (conn, fd, state, add_stat, hook);
  else
    return 95;
}

canonical_original_code:
int ftp_conn_cont_get_stats(struct ftp_conn *conn, int fd, void *state, int (*add_stat)(char *name, struct stat *stat, char *symlink_target, void *hook), void *hook)
{
  if (conn->syshooks.cont_get_stats)
    return (*conn->syshooks.cont_get_stats) (conn, fd, state, add_stat, hook);
  else
    return 95;
}

variable_types: fd int

variable_types:
state
void *

variable_types: int (*)(char *name, struct stat *stat, char *symlink_target, void *hook)

variable_types:
hook
void *

user_defined_types: struct ftp_conn_params { void *addr; unsigned long addr_len; int addr_type; char *user; }

user_defined_types: struct ftp_conn_hooks { void (*choose_syshooks)(struct ftp_conn *conn, char *syst); void (*cntl_debug)(struct ftp_conn *conn, int type, char *txt); void (*opened)(struct ftp_conn *conn); int (*get_login_param)(struct ftp_conn *conn, int type, char **txt); void (*closed)(struct ftp_conn *conn); int (*init)(struct ftp_conn *conn); void (*fini)(struct ftp_conn *conn); int (*interrupt_check)(struct ftp_conn *conn); }

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


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

result = ftp_conn_start_get_stats(a1);
if ( !(_DWORD)result )
{
do
result = ftp_conn_cont_get_stats(a1);
while ( (_DWORD)result == 11 );
}
return result;
}

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

result = func1(a1);
if ( !(_DWORD)result )
{
do
result = func2(a1);
while ( (_DWORD)result == 11 );
}
return result;
}

original_code:
error_t
ftp_conn_get_stats (struct ftp_conn *conn,
      const char *name, int contents,
      ftp_conn_add_stat_fun_t add_stat, void *hook)
{
  int fd;
  void *state;
  error_t err = ftp_conn_start_get_stats (conn, name, contents, &fd, &state);
  if (err)
    return err;
  do
    err = ftp_conn_cont_get_stats (conn, fd, state, add_stat, hook);
  while (err == 11);
  return err;
}

canonical_original_code:
int ftp_conn_get_stats(struct ftp_conn *conn, char *name, int contents, int (*add_stat)(char *name, struct stat *stat, char *symlink_target, void *hook), void *hook)
{
  int fd;
  void *state;
  int err = ftp_conn_start_get_stats (conn, name, contents, &fd, &state);
  if (err)
    return err;
  do
    err = ftp_conn_cont_get_stats (conn, fd, state, add_stat, hook);
  while (err == 11);
  return err;
}

variable_types: err int


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

if ( (*(_BYTE *)(a1 + 64) & 1) != 0 )
result = 0LL;
else
result = ftp_conn_open();
return result;
}

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

if ( (*(_BYTE *)(a1 + 64) & 1) != 0 )
result = 0LL;
else
result = ftp_conn_open();
return result;
}

original_code:
extern inline error_t
ftp_conn_validate_syshooks (struct ftp_conn *conn)
{
  if (conn->syshooks_valid)
    return 0;
  else
    return ftp_conn_open (conn);
}

canonical_original_code:
extern inline int ftp_conn_validate_syshooks(struct ftp_conn *conn)
{
  if (conn->syshooks_valid)
    return 0;
  else
    return ftp_conn_open (conn);
}


original_code:
error_t
cacheq_set_length (struct cacheq *cq, int length)
{
  if (length != cq->length)
    {
      size_t esz = cq->entry_size;
      void *new_entries = malloc (esz * length);
      struct cacheq_hdr *fh = cq->mru;
      struct cacheq_hdr *th = new_entries;
      struct cacheq_hdr *end = new_entries + esz * (length - 1);
      struct cacheq_hdr *prev_th = 0;
      if (! new_entries)
 return 12;
      while (fh || th)
 {
   struct cacheq_hdr *next_th =
     (!th || th >= end) ? 0 : (void *)th + esz;
   if (fh && th)
     bcopy (fh, th, esz);
   else if (th)
     bzero (th, esz);
   if (th)
     {
       th->prev = prev_th;
       th->next = next_th;
     }
   if (fh && th)
     {
       if (cq->move_entry)
  (*cq->move_entry) (fh, th);
     }
   else if (th)
     {
       if (cq->init_entry)
  (*cq->init_entry) (th);
     }
   else
     {
       if (cq->finalize_entry)
  (*cq->finalize_entry) (fh);
     }
   if (fh)
     fh = fh->next;
   if (th)
     {
       prev_th = th;
       th = next_th;
     }
 }
      free (cq->entries);
      cq->entries = new_entries;
      cq->mru = new_entries;
      cq->lru = prev_th;
      cq->length = length;
    }
  return 0;
}

canonical_original_code:
int cacheq_set_length(struct cacheq *cq, int length)
{
  if (length != cq->length)
    {
      unsigned long esz = cq->entry_size;
      void *new_entries = malloc (esz * length);
      struct cacheq_hdr *fh = cq->mru;
      struct cacheq_hdr *th = new_entries;
      struct cacheq_hdr *end = new_entries + esz * (length - 1);
      struct cacheq_hdr *prev_th = 0;
      if (! new_entries)
 return 12;
      while (fh || th)
 {
   struct cacheq_hdr *next_th = (!th || th >= end) ? 0 : (void *)th + esz;
   if (fh && th)
     bcopy (fh, th, esz);
   else if (th)
     bzero (th, esz);
   if (th)
     {
       th->prev = prev_th;
       th->next = next_th;
     }
   if (fh && th)
     {
       if (cq->move_entry)
  (*cq->move_entry) (fh, th);
     }
   else if (th)
     {
       if (cq->init_entry)
  (*cq->init_entry) (th);
     }
   else
     {
       if (cq->finalize_entry)
  (*cq->finalize_entry) (fh);
     }
   if (fh)
     fh = fh->next;
   if (th)
     {
       prev_th = th;
       th = next_th;
     }
 }
      free (cq->entries);
      cq->entries = new_entries;
      cq->mru = new_entries;
      cq->lru = prev_th;
      cq->length = length;
    }
  return 0;
}

variable_types: struct cacheq { unsigned long entry_size; void (*init_entry)(void *entry); void (*move_entry)(void *from, void *to); void (*finalize_entry)(void *entry); int length; void *entries; void *lru; } *

variable_types: length int

variable_types:
esz
unsigned long

variable_types:
fh
struct cacheq_hdr { void *next; } *

variable_types:
th
struct cacheq_hdr { void *next; } *

variable_types:
end
struct cacheq_hdr { void *next; } *


localhost

decompiled_code:
__int64 localhost()
{
__int64 v0; // r13
void *v2; // r12
int *v3; // rbx
size_t v4; // r14

v0 = buf_1;
if ( !buf_1 )
{
v2 = 0LL;
v3 = _errno_location();
do
{
*v3 = 0;
if ( v2 )
{
buf_len_0 *= 2LL;
v2 = realloc(v2, buf_len_0);
buf_1 = (__int64)v2;
if ( !v2 )
goto LABEL_12;
}
else
{
buf_len_0 = 128LL;
v2 = malloc(0x80uLL);
buf_1 = (__int64)v2;
if ( !v2 )
{
LABEL_12:
*v3 = 12;
return 0LL;
}
}
v4 = buf_len_0;
}
while ( !gethostname((char *)v2, buf_len_0) && !memchr(v2, 0, v4) || *v3 == 36 );
if ( *v3 )
{
free(v2);
buf_1 = 0LL;
}
else
{
v0 = (__int64)v2;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // r13
void *v2; // r12
int *v3; // rbx
size_t v4; // r14

v0 = buf_1;
if ( !buf_1 )
{
v2 = 0LL;
v3 = _errno_location();
do
{
*v3 = 0;
if ( v2 )
{
buf_len_0 *= 2LL;
v2 = realloc(v2, buf_len_0);
buf_1 = (__int64)v2;
if ( !v2 )
goto LABEL_12;
}
else
{
buf_len_0 = 128LL;
v2 = malloc(0x80uLL);
buf_1 = (__int64)v2;
if ( !v2 )
{
LABEL_12:
*v3 = 12;
return 0LL;
}
}
v4 = buf_len_0;
}
while ( !gethostname((char *)v2, buf_len_0) && !memchr(v2, 0, v4) || *v3 == 36 );
if ( *v3 )
{
free(v2);
buf_1 = 0LL;
}
else
{
v0 = (__int64)v2;
}
}
return v0;
}

original_code:
char *
localhost ()
{
  static char *buf = 0;
  static size_t buf_len = 0;
  if (! buf)
    {
      do {
 (*__errno_location ()) = 0;
 if (buf) {
   buf_len += buf_len;
   buf = realloc (buf, buf_len);
 } else {
   buf_len = 128;
   buf = malloc (buf_len);
 }
 if (! buf)
   {
     (*__errno_location ()) = 12;
     return 0;
   }
      } while ((gethostname(buf, buf_len) == 0 && !memchr (buf, '\0', buf_len))
        || (*__errno_location ()) == 36);
      if ((*__errno_location ()))
 {
   free (buf);
   buf = 0;
 }
    }
  return buf;
}

canonical_original_code:
char *localhost()
{
  static char *buf = 0;
  static unsigned long buf_len = 0;
  if (! buf)
    {
      do {
 (*__errno_location ()) = 0;
 if (buf) {
   buf_len += buf_len;
   buf = realloc (buf, buf_len);
 } else {
   buf_len = 128;
   buf = malloc (buf_len);
 }
 if (! buf)
   {
     (*__errno_location ()) = 12;
     return 0;
   }
      } while ((gethostname(buf, buf_len) == 0 && !memchr (buf, '\0', buf_len))
        || (*__errno_location ()) == 36);
      if ((*__errno_location ()))
 {
   free (buf);
   buf = 0;
 }
    }
  return buf;
}

variable_types:
buf
char *


decompiled_code:
const char *__fastcall canon_host(const char *a1)
{
struct hostent *v1; // rax
struct hostent *v2; // rbx
const char *v3; // r12
char *v5; // rax
struct hostent *v6; // rax

v1 = gethostbyname(a1);
if ( v1 )
{
v2 = v1;
if ( v1->h_addrtype != 2 )
return v1->h_name;
v5 = inet_ntoa((struct in_addr)(*(struct in_addr **)v1->h_addr_list)->s_addr);
v3 = v2->h_name;
if ( !v5 || strcmp(v2->h_name, v5) )
return v3;
v6 = gethostbyaddr(*(const void **)v2->h_addr_list, v2->h_length, v2->h_addrtype);
if ( v6 )
return v6->h_name;
}
return 0LL;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
struct hostent *v1; // rax
struct hostent *v2; // rbx
const char *v3; // r12
char *v5; // rax
struct hostent *v6; // rax

v1 = gethostbyname(a1);
if ( v1 )
{
v2 = v1;
if ( v1->h_addrtype != 2 )
return v1->h_name;
v5 = inet_ntoa((struct in_addr)(*(struct in_addr **)v1->h_addr_list)->s_addr);
v3 = v2->h_name;
if ( !v5 || strcmp(v2->h_name, v5) )
return v3;
v6 = gethostbyaddr(*(const void **)v2->h_addr_list, v2->h_length, v2->h_addrtype);
if ( v6 )
return v6->h_name;
}
return 0LL;
}

original_code:
char *
canon_host (char *host)
{
  struct hostent *he = gethostbyname (host);
  if (he)
    {
      char *addr = 0;
      switch (he->h_addrtype)
 {
 case 2:
   addr = inet_ntoa (*(struct in_addr *)he->h_addr_list[0]);
   break;
 }
      if (addr && strcmp (he->h_name, addr) == 0)
 he = gethostbyaddr (he->h_addr_list[0], he->h_length, he->h_addrtype);
      if (he)
 return he->h_name;
    }
  return 0;
}

canonical_original_code:
char *canon_host(char *host)
{
  struct hostent *he = gethostbyname (host);
  if (he)
    {
      char *addr = 0;
      switch (he->h_addrtype)
 {
 case 2:
   addr = inet_ntoa (*(struct in_addr *)he->h_addr_list[0]);
   break;
 }
      if (addr && strcmp (he->h_name, addr) == 0)
 he = gethostbyaddr (he->h_addr_list[0], he->h_length, he->h_addrtype);
      if (he)
 return he->h_name;
    }
  return 0;
}

variable_types:
host
char *

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

variable_types:
addr
char *


decompiled_code:
void clear_bufs()
{
outcnt = 0;
inptr = 0;
insize = 0;
}

canonical_decompiled_code:
void func1()
{
outcnt = 0;
inptr = 0;
insize = 0;
}

original_code:
void clear_bufs()
{
    outcnt = 0;
    insize = inptr = 0;
}


decompiled_code:
__int64 __fastcall fill_inbuf(int a1)
{
__int64 v1; // rax
int v2; // eax

v1 = 0LL;
insize = 0;
while ( 1 )
{
v2 = unzip_read((char *)&inbuf + v1, (unsigned int)(0x8000 - v1));
if ( (unsigned int)(v2 + 1) <= 1 )
break;
v1 = (unsigned int)(insize + v2);
insize = v1;
if ( (unsigned int)v1 > 0x7FFF )
goto LABEL_7;
}
if ( insize )
{
LABEL_7:
inptr = 1;
return (unsigned __int8)inbuf;
}
if ( !a1 )
{
unzip_read_error();
goto LABEL_7;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rax
int v2; // eax

v1 = 0LL;
insize = 0;
while ( 1 )
{
v2 = unzip_read((char *)&inbuf + v1, (unsigned int)(0x8000 - v1));
if ( (unsigned int)(v2 + 1) <= 1 )
break;
v1 = (unsigned int)(insize + v2);
insize = v1;
if ( (unsigned int)v1 > 0x7FFF )
goto LABEL_7;
}
if ( insize )
{
LABEL_7:
inptr = 1;
return (unsigned __int8)inbuf;
}
if ( !a1 )
{
unzip_read_error();
goto LABEL_7;
}
return 0xFFFFFFFFLL;
}

original_code:
static int
fill_inbuf (int eof_ok)
{
  int len;
  insize = 0;
  do
    {
      len = (*unzip_read)((char*)inbuf+insize, 0x1000 -insize);
      if (len == 0 || len == (-1))
 break;
      insize += len;
    }
  while (insize < 0x1000);
  if (insize == 0)
    {
      if (eof_ok)
 return (-1);
      unzip_read_error();
    }
  inptr = 1;
  return inbuf[0];
}

canonical_original_code:
static int fill_inbuf(int eof_ok)
{
  int len;
  insize = 0;
  do
    {
      len = (*unzip_read)((char *)inbuf+insize, 0x1000 -insize);
      if (len == 0 || len == (-1))
 break;
      insize += len;
    }
  while (insize < 0x1000);
  if (insize == 0)
    {
      if (eof_ok)
 return (-1);
      unzip_read_error();
    }
  inptr = 1;
  return inbuf[0];
}

variable_types: len int


decompiled_code:
__int64 flush_window()
{
__int64 result; // rax

if ( outcnt )
{
updcrc(window, outcnt);
unzip_write(window, (unsigned int)outcnt);
result = (unsigned int)outcnt;
outcnt = 0;
bytes_out += result;
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax

if ( outcnt )
{
func0(window, outcnt);
unzip_write(window, (unsigned int)outcnt);
result = (unsigned int)outcnt;
outcnt = 0;
bytes_out += result;
}
return result;
}

original_code:
void flush_window()
{
    if (outcnt == 0) return;
    updcrc(window, outcnt);
    (*unzip_write) ((char *) window, outcnt);
    bytes_out += outcnt;
    outcnt = 0;
}


decompiled_code:
void alarm_handler()
{
puts("Received alarm");
fflush(stdout);
}

canonical_decompiled_code:
void func0()
{
puts("Received alarm");
fflush(stdout);
}

original_code:
void
alarm_handler (int signo)
{
  printf ("Received alarm\n");
  fflush (stdout);
}

canonical_original_code:
void alarm_handler(int signo)
{
  printf ("Received alarm\n");
  fflush (stdout);
}

variable_types: signo int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int *v4; // rax
int *v5; // rbx
unsigned int v6; // ebp
struct itimerval v7; // [rsp+0h] [rbp-38h] BYREF

v7.it_interval.tv_usec = 0LL;
v7.it_interval.tv_sec = 1LL;
v7.it_value.tv_usec = 0LL;
v7.it_value.tv_sec = 1LL;
signal(14, (__sighandler_t)alarm_handler);
v3 = setitimer(ITIMER_REAL, &v7, 0LL);
v4 = _errno_location();
v5 = v4;
if ( v3 >= 0 )
{
while ( 1 )
{
puts("Pausing for input or one second...");
fflush(stdout);
v6 = getchar();
if ( ferror(stdin) )
break;
if ( v6 == -1 )
{
puts("Saw EOF. Pausing (no input)...");
fflush(stdout);
_xpg_sigpause(0LL);
}
else
{
printf("Saw %.3o\n", v6);
}
}
error(1, *v5, "getchar");
}
error(1, *v4, "Setting timer");
JUMPOUT(0x196LL);
}

original_code:
int
main(int argc, char *argv[])
{
  struct itimerval real_timer;
  real_timer.it_interval.tv_usec = 0;
  real_timer.it_interval.tv_sec = 1;
  real_timer.it_value.tv_usec = 0;
  real_timer.it_value.tv_sec = 1;
  signal (14, alarm_handler);
  if (setitimer (ITIMER_REAL, &real_timer, 0) < 0)
    error (1, (*__errno_location ()), "Setting timer");
  while (1)
    {
      int c;
      puts ("Pausing for input or one second...");
      fflush (stdout);
      c = getchar ();
      if (ferror (stdin))
 error (1, (*__errno_location ()), "getchar");
      if (c == (-1))
 {
   puts ("Saw EOF.  Pausing (no input)...");
   fflush (stdout);
   sigpause (0);
 }
      else
 printf ("Saw %.3o\n", c);
    }
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: c int

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


decompiled_code:
void pass4()
{
unsigned __int64 v0; // rbx
char v1; // si
void **v2; // rdi
_QWORD *v3; // rax
__int128 v4; // [rsp+0h] [rbp-58h] BYREF
__int128 v5; // [rsp+10h] [rbp-48h]
__int128 v6; // [rsp+20h] [rbp-38h]
__int128 v7; // [rsp+30h] [rbp-28h]
__int128 v8; // [rsp+40h] [rbp-18h]

*(_QWORD *)&v4 = 0LL;
v8 = 0LL;
*((_QWORD *)&v4 + 1) = pass4check;
BYTE8(v8) = 2;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
if ( (unsigned __int64)lastino > 1 )
{
v0 = 2LL;
do
{
*(_QWORD *)&v5 = v0;
v1 = *(_BYTE *)(statemap + v0);
switch ( v1 )
{
case 1:
break;
case 2:
case 4:
if ( *(_WORD *)(lncntp + 2 * v0) )
{
adjust(&v4);
}
else
{
v2 = (void **)zlnhead;
if ( zlnhead )
{
v3 = zlnhead;
do
{
if ( v3[1] == v0 )
{
v3[1] = *((_QWORD *)zlnhead + 1);
zlnhead = *v2;
free(v2);
goto LABEL_15;
}
v3 = (_QWORD *)*v3;
}
while ( v3 );
}
}
break;
case 3:
LABEL_15:
clri(&v4, "UNREF", 1LL);
break;
case 5:
if ( *(_QWORD *)(ginode(v0) + 16) )
goto LABEL_9;
clri(&v4, "ZERO LENGTH", 1LL);
break;
case 6:
LABEL_9:
clri(&v4, "BAD/DUP", 1LL);
break;
default:
errexit("BAD STATE %d FOR INODE I=%d", (unsigned int)v1, v0);
break;
}
++v0;
}
while ( lastino >= v0 );
}
}

canonical_decompiled_code:
void func1()
{
unsigned __int64 v0; // rbx
char v1; // si
void **v2; // rdi
_QWORD *v3; // rax
__int128 v4; // [rsp+0h] [rbp-58h] BYREF
__int128 v5; // [rsp+10h] [rbp-48h]
__int128 v6; // [rsp+20h] [rbp-38h]
__int128 v7; // [rsp+30h] [rbp-28h]
__int128 v8; // [rsp+40h] [rbp-18h]

*(_QWORD *)&v4 = 0LL;
v8 = 0LL;
*((_QWORD *)&v4 + 1) = pass4check;
BYTE8(v8) = 2;
v5 = 0LL;
v6 = 0LL;
v7 = 0LL;
if ( (unsigned __int64)lastino > 1 )
{
v0 = 2LL;
do
{
*(_QWORD *)&v5 = v0;
v1 = *(_BYTE *)(statemap + v0);
switch ( v1 )
{
case 1:
break;
case 2:
case 4:
if ( *(_WORD *)(lncntp + 2 * v0) )
{
adjust(&v4);
}
else
{
v2 = (void **)zlnhead;
if ( zlnhead )
{
v3 = zlnhead;
do
{
if ( v3[1] == v0 )
{
v3[1] = *((_QWORD *)zlnhead + 1);
zlnhead = *v2;
free(v2);
goto LABEL_15;
}
v3 = (_QWORD *)*v3;
}
while ( v3 );
}
}
break;
case 3:
LABEL_15:
clri(&v4, "UNREF", 1LL);
break;
case 5:
if ( *(_QWORD *)(ginode(v0) + 16) )
goto LABEL_9;
clri(&v4, "ZERO LENGTH", 1LL);
break;
case 6:
LABEL_9:
clri(&v4, "BAD/DUP", 1LL);
break;
default:
errexit("BAD STATE %d FOR INODE I=%d", (unsigned int)v1, v0);
break;
}
++v0;
}
while ( lastino >= v0 );
}
}

original_code:
void
pass4()
{
  ino_t number;
  int reconn_failed = 0;
  for (number = ((ino_t)2); number < maxino; number++)
    {
      if (linkfound[number] && inodestate[number] != 0)
 {
   if (linkcount[number] != linkfound[number])
     {
       pinode (0, number,
        "LINK COUNT %d SHOULD BE %d IN",
        linkcount[number], linkfound[number]);
       if (preen || reply ("ADJUST"))
  {
    struct dinode dino;
    getinode (number, &dino);
    dino.di_nlink = linkfound[number];
    write_inode (number, &dino);
    pfix ("ADJUSTED");
  }
     }
 }
      else if (linkfound[number] && inodestate[number] == 0)
 {
   errexit ("LINK RECORDED FOR UNALLOCATED NODE");
 }
      else if (!linkfound[number] && inodestate[number] != 0)
 {
   struct dinode dino;
   pinode (0, number, "UNREF");
   getinode (number, &dino);
   if (dino.di_size && !reconn_failed)
     {
       if (((((&dino)->di_modeh << 16) | (&dino)->di_model) & 0170000) == 0040000)
  errexit ("NO LINKS TO NONZERO DIRECTORY");
       if (preen || reply ("RECONNECT"))
  reconn_failed = !linkup (number, -1);
       if (! reconn_failed)
  pfix ("RECONNECTED");
       if (preen && reconn_failed)
  pfail ("RECONNECT FAILED");
     }
   if (dino.di_size == 0 || reconn_failed)
     {
       if (reconn_failed && !preen)
  problem (0, "RECONNECT FAILED");
       if (preen || reply ("CLEAR"))
  {
    inodestate[number] = 0;
    clear_inode (number, &dino);
    pfix ("CLEARED");
  }
     }
 }
    }
}

canonical_original_code:
void pass4()
{
  unsigned long number;
  int reconn_failed = 0;
  for (number = ((unsigned long)2); number < maxino; number++)
    {
      if (linkfound[number] && inodestate[number] != 0)
 {
   if (linkcount[number] != linkfound[number])
     {
       pinode (0, number,
        "LINK COUNT %d SHOULD BE %d IN",
        linkcount[number], linkfound[number]);
       if (preen || reply ("ADJUST"))
  {
    struct dinode dino;
    getinode (number, &dino);
    dino.di_nlink = linkfound[number];
    write_inode (number, &dino);
    pfix ("ADJUSTED");
  }
     }
 }
      else if (linkfound[number] && inodestate[number] == 0)
 {
   errexit ("LINK RECORDED FOR UNALLOCATED NODE");
 }
      else if (!linkfound[number] && inodestate[number] != 0)
 {
   struct dinode dino;
   pinode (0, number, "UNREF");
   getinode (number, &dino);
   if (dino.di_size && !reconn_failed)
     {
       if (((((&dino)->di_modeh << 16) | (&dino)->di_model) & 0170000) == 0040000)
  errexit ("NO LINKS TO NONZERO DIRECTORY");
       if (preen || reply ("RECONNECT"))
  reconn_failed = !linkup (number, -1);
       if (! reconn_failed)
  pfix ("RECONNECTED");
       if (preen && reconn_failed)
  pfail ("RECONNECT FAILED");
     }
   if (dino.di_size == 0 || reconn_failed)
     {
       if (reconn_failed && !preen)
  problem (0, "RECONNECT FAILED");
       if (preen || reply ("CLEAR"))
  {
    inodestate[number] = 0;
    clear_inode (number, &dino);
    pfix ("CLEARED");
  }
     }
 }
    }
}

variable_types:
number
unsigned long

variable_types: struct dinode { unsigned short di_model; short di_nlink; union { unsigned long diu_author; unsigned short diu_oldids[2]; } di_u; unsigned long di_size; struct timespec { long tv_sec; long tv_nsec; } di_atime; struct timespec di_mtime; struct timespec di_ctime; int di_db[12]; int di_ib[3]; unsigned long di_flags; long di_blocks; long di_gen; unsigned long di_uid; unsigned long di_gid; unsigned short di_modeh; unsigned short di_spare; long di_trans; }


decompiled_code:
__int64 __fastcall deduce_term_size(int a1, __int64 a2, _DWORD *a3, _DWORD *a4)
{
int v6; // edx
__int64 result; // rax
__int16 v8[16]; // [rsp+8h] [rbp-20h] BYREF

if ( a1 < 0 || ioctl(a1, 0x5413uLL, v8) )
{
v6 = 0;
result = 0LL;
if ( !a3 )
goto LABEL_10;
}
else
{
result = (unsigned __int16)v8[1];
v6 = (unsigned __int16)v8[0];
if ( !a3 )
{
LABEL_10:
if ( !a4 )
return v6 != 0;
goto LABEL_4;
}
}
*a3 = result;
if ( a4 )
{
LABEL_4:
*a4 = v6;
return 0LL;
}
if ( (_DWORD)result )
return v6 != 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, _DWORD *a3, _DWORD *a4)
{
int v6; // edx
__int64 result; // rax
__int16 v8[16]; // [rsp+8h] [rbp-20h] BYREF

if ( a1 < 0 || ioctl(a1, 0x5413uLL, v8) )
{
v6 = 0;
result = 0LL;
if ( !a3 )
goto LABEL_10;
}
else
{
result = (unsigned __int16)v8[1];
v6 = (unsigned __int16)v8[0];
if ( !a3 )
{
LABEL_10:
if ( !a4 )
return v6 != 0;
goto LABEL_4;
}
}
*a3 = result;
if ( a4 )
{
LABEL_4:
*a4 = v6;
return 0LL;
}
if ( (_DWORD)result )
return v6 != 0;
return result;
}

original_code:
int
deduce_term_size (int fd, char *type, int *width, int *height)
{
  int w = 0, h = 0;
  struct winsize ws;
  if (fd >= 0 && ioctl (fd, 0x5413, &ws) == 0)
    {
      w = ws.ws_col;
      h = ws.ws_row;
    }
  if (((width && !w) || (height && !h)) && type)
    {
    }
  if (width)
    *width = w;
  if (height)
    *height = h;
  return (!width || w) && (!height && h);
}

canonical_original_code:
int deduce_term_size(int fd, char *type, int *width, int *height)
{
  int w = 0; int h = 0;
  struct winsize ws;
  if (fd >= 0 && ioctl (fd, 0x5413, &ws) == 0)
    {
      w = ws.ws_col;
      h = ws.ws_row;
    }
  if (((width && !w) || (height && !h)) && type)
    {
    }
  if (width)
    *width = w;
  if (height)
    *height = h;
  return (!width || w) && (!height && h);
}

variable_types: fd int

variable_types:
type
char *

variable_types:
width
int *

variable_types:
height
int *

variable_types: w int

variable_types: h int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }


decompiled_code:
speed_t __fastcall set_speed(int fd, char *nptr)
{
int *v2; // rax
int *v3; // rbx
speed_t result; // eax
speed_t v5; // ebp
char *endptr; // [rsp+8h] [rbp-60h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-58h] BYREF

v2 = _errno_location();
*v2 = 0;
v3 = v2;
result = strtoul(nptr, &endptr, 0);
if ( !*v3 )
{
v5 = result;
result = (unsigned int)endptr;
if ( !*endptr )
{
result = tcgetattr(fd, &termios_p);
if ( !result )
{
result = cfsetspeed(&termios_p, v5);
if ( !result )
result = tcsetattr(fd, 2, &termios_p);
}
}
}
return result;
}

canonical_decompiled_code:
speed_t __fastcall func0(int fd, char *nptr)
{
int *v2; // rax
int *v3; // rbx
speed_t result; // eax
speed_t v5; // ebp
char *endptr; // [rsp+8h] [rbp-60h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-58h] BYREF

v2 = _errno_location();
*v2 = 0;
v3 = v2;
result = strtoul(nptr, &endptr, 0);
if ( !*v3 )
{
v5 = result;
result = (unsigned int)endptr;
if ( !*endptr )
{
result = tcgetattr(fd, &termios_p);
if ( !result )
{
result = cfsetspeed(&termios_p, v5);
if ( !result )
result = tcsetattr(fd, 2, &termios_p);
}
}
}
return result;
}

original_code:
static void
set_speed (int tty, char *speedstr)
{
  error_t err;
  struct termios ttystat;
  speed_t speed;
  char *tail;
  (*__errno_location ()) = 0;
  speed = strtoul (speedstr, &tail, 0);
  if ((*__errno_location ()) || *tail)
    return;
  err = tcgetattr (tty, &ttystat);
  if (!err && !cfsetspeed (&ttystat, speed))
    tcsetattr (tty, 2, &ttystat);
}

canonical_original_code:
static void set_speed(int tty, char *speedstr)
{
  int err;
  struct termios ttystat;
  unsigned int speed;
  char *tail;
  (*__errno_location ()) = 0;
  speed = strtoul (speedstr, &tail, 0);
  if ((*__errno_location ()) || *tail)
    return;
  err = tcgetattr (tty, &ttystat);
  if (!err && !cfsetspeed (&ttystat, speed))
    tcsetattr (tty, 2, &ttystat);
}

variable_types: tty int

variable_types:
speedstr
char *

variable_types: err int

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

variable_types:
speed
unsigned int

variable_types:
tail
char *


decompiled_code:
ssize_t __fastcall print_banner(int fd, char *filename)
{
void *v2; // rbx
char *v3; // rax
int v4; // eax
char *ptr; // [rsp+8h] [rbp-1B0h] BYREF
struct utsname name; // [rsp+10h] [rbp-1A8h] BYREF

v2 = (void *)localhost();
if ( uname(&name) )
{
name.release[0] = 0;
name.sysname[0] = 0;
}
v3 = basename(filename);
if ( !v2 )
v2 = &unk_10A;
v4 = asprintf(&ptr, "\r\n\n%s %s (%s) (%s)\r\n\n", &name, name.release, v2, v3);
return write(fd, ptr, v4);
}

canonical_decompiled_code:
ssize_t __fastcall func1(int fd, char *filename)
{
void *v2; // rbx
char *v3; // rax
int v4; // eax
char *ptr; // [rsp+8h] [rbp-1B0h] BYREF
struct utsname name; // [rsp+10h] [rbp-1A8h] BYREF

v2 = (void *)localhost();
if ( uname(&name) )
{
name.release[0] = 0;
name.sysname[0] = 0;
}
v3 = basename(filename);
if ( !v2 )
v2 = &unk_10A;
v4 = asprintf(&ptr, "\r\n\n%s %s (%s) (%s)\r\n\n", &name, name.release, v2, v3);
return write(fd, ptr, v4);
}

original_code:
static void
print_banner (int fd, char *ttyname)
{
  int cc;
  char *s;
  struct utsname u;
  char *hostname = localhost ();
  if (uname (&u))
    u.sysname[0] = u.release[0] = '\0';
  cc = asprintf (&s, "\r\n\n%s %s (%s) (%s)\r\n\n",
   u.sysname, u.release, hostname ?: "?", basename (ttyname));
  write (fd, s, cc);
}

canonical_original_code:
static void print_banner(int fd, char *ttyname)
{
  int cc;
  char *s;
  struct utsname u;
  char *hostname = localhost ();
  if (uname (&u))
    u.sysname[0] = u.release[0] = '\0';
  cc = asprintf (&s, "\r\n\n%s %s (%s) (%s)\r\n\n",
   u.sysname, u.release, hostname ?: "?", basename (ttyname));
  write (fd, s, cc);
}

variable_types:
ttyname
char *

variable_types: cc int

variable_types:
s
char *

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char domainname[65]; }

variable_types:
hostname
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
struct ttyent *v4; // rbx
int v5; // eax
int v6; // ebp
char *file; // [rsp+0h] [rbp-28h] BYREF
char *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

openlog("getty", 7, 32);
if ( argc != 3 )
{
syslog(3, "Bad syntax");
closelog();
exit(1);
}
v3 = (char *)argv[1];
v4 = getttynam(argv[2]);
asprintf(&file, "%s/%s", "/dev/", argv[2]);
chown(file, 0, 0);
chmod(file, 0x180u);
revoke(file);
sleep(2u);
while ( 1 )
{
v5 = open64(file, 2);
v6 = v5;
if ( v5 != -1 )
break;
syslog(3, "%s: %m", file);
closelog();
sleep(0x3Cu);
}
set_speed(v5, v3);
print_banner(v6, file);
if ( login_tty(v6) == -1 )
syslog(3, "cannot set controlling terminal to %s: %m", file);
if ( v4 )
{
asprintf(ptr, "TERM=%s", v4->ty_type);
if ( !strcmp(v4->ty_type, "dialup") )
{
execl("/bin/login", "login", "-e", ptr[0], 0LL);
goto LABEL_9;
}
}
else
{
asprintf(ptr, "TERM=%s", "unknown");
}
execl("/bin/login", "login", "-e", ptr[0], "-aNOAUTH_TIMEOUT", 0LL);
LABEL_9:
syslog(3, "%s: %m", "/bin/login");
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // r12
struct ttyent *v4; // rbx
int v5; // eax
int v6; // ebp
char *file; // [rsp+0h] [rbp-28h] BYREF
char *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

openlog("getty", 7, 32);
if ( argc != 3 )
{
syslog(3, "Bad syntax");
closelog();
exit(1);
}
v3 = (char *)argv[1];
v4 = getttynam(argv[2]);
asprintf(&file, "%s/%s", "/dev/", argv[2]);
chown(file, 0, 0);
chmod(file, 0x180u);
revoke(file);
sleep(2u);
while ( 1 )
{
v5 = open64(file, 2);
v6 = v5;
if ( v5 != -1 )
break;
syslog(3, "%s: %m", file);
closelog();
sleep(0x3Cu);
}
func0(v5, v3);
func1(v6, file);
if ( login_tty(v6) == -1 )
syslog(3, "cannot set controlling terminal to %s: %m", file);
if ( v4 )
{
asprintf(ptr, "TERM=%s", v4->ty_type);
if ( !strcmp(v4->ty_type, "dialup") )
{
execl("/bin/login", "login", "-e", ptr[0], 0LL);
goto LABEL_9;
}
}
else
{
asprintf(ptr, "TERM=%s", "unknown");
}
execl("/bin/login", "login", "-e", ptr[0], "-aNOAUTH_TIMEOUT", 0LL);
LABEL_9:
syslog(3, "%s: %m", "/bin/login");
return 1;
}

original_code:
int
main (int argc, char **argv)
{
  char *linespec, *ttyname;
  int tty;
  struct ttyent *tt;
  char *arg;
  openlog ("getty", 0x04|0x02|0x01, (4<<3));
  if (argc != 3)
    {
      syslog (3, "Bad syntax");
      closelog ();
      exit (1);
    }
  linespec = argv[1];
  tt = getttynam (argv[2]);
  asprintf (&ttyname, "%s/%s", "/dev/", argv[2]);
  chown (ttyname, 0, 0);
  chmod (ttyname, 0600);
  revoke (ttyname);
  sleep (2);
  do
    {
      tty = open (ttyname, 02);
      if (tty == -1)
 {
   syslog (3, "%s: %m", ttyname);
   closelog ();
   sleep (60);
 }
    }
  while (tty == -1);
  set_speed (tty, linespec);
  print_banner (tty, ttyname);
  if (login_tty (tty) == -1)
    syslog (3, "cannot set controlling terminal to %s: %m", ttyname);
  asprintf (&arg, "TERM=%s", tt ? tt->ty_type : "unknown");
  if (tt && strcmp (tt->ty_type, "dialup") == 0)
    execl ("/bin/login", "login", "-e", arg, ((void *)0));
  else
    execl ("/bin/login", "login", "-e", arg, "-aNOAUTH_TIMEOUT", ((void *)0));
  syslog (3, "%s: %m", "/bin/login");
  return 1;
}

canonical_original_code:
int main(int argc, char **argv)
{
  char *linespec; char *ttyname;
  int tty;
  struct ttyent *tt;
  char *arg;
  openlog ("getty", 0x04|0x02|0x01, (4<<3));
  if (argc != 3)
    {
      syslog (3, "Bad syntax");
      closelog ();
      exit (1);
    }
  linespec = argv[1];
  tt = getttynam (argv[2]);
  asprintf (&ttyname, "%s/%s", "/dev/", argv[2]);
  chown (ttyname, 0, 0);
  chmod (ttyname, 0600);
  revoke (ttyname);
  sleep (2);
  do
    {
      tty = open (ttyname, 02);
      if (tty == -1)
 {
   syslog (3, "%s: %m", ttyname);
   closelog ();
   sleep (60);
 }
    }
  while (tty == -1);
  set_speed (tty, linespec);
  print_banner (tty, ttyname);
  if (login_tty (tty) == -1)
    syslog (3, "cannot set controlling terminal to %s: %m", ttyname);
  asprintf (&arg, "TERM=%s", tt ? tt->ty_type : "unknown");
  if (tt && strcmp (tt->ty_type, "dialup") == 0)
    execl ("/bin/login", "login", "-e", arg, ((void *)0));
  else
    execl ("/bin/login", "login", "-e", arg, "-aNOAUTH_TIMEOUT", ((void *)0));
  syslog (3, "%s: %m", "/bin/login");
  return 1;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
linespec
char *

variable_types: struct ttyent { char *ty_name; char *ty_getty; char *ty_type; int ty_status; char *ty_window; char *ty_comment; } *

variable_types:
arg
char *


decompiled_code:
int __fastcall do_gettimeofday(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(struct timeval *a1)
{
return gettimeofday(a1, 0LL);
}

original_code:
void
do_gettimeofday (struct timeval *tp)
{
  gettimeofday (tp, 0);
}

canonical_original_code:
void do_gettimeofday(struct timeval *tp)
{
  gettimeofday (tp, 0);
}

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


decompiled_code:
void __fastcall ftp_conn_free(void *ptr)
{
__int64 v2; // rax
void (__fastcall *v3)(void *); // rax
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi

ftp_conn_close();
v2 = *((_QWORD *)ptr + 1);
if ( v2 )
{
v3 = *(void (__fastcall **)(void *))(v2 + 48);
if ( v3 )
v3(ptr);
}
v4 = (void *)*((_QWORD *)ptr + 9);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 13);
if ( v5 )
free(v5);
v6 = (void *)*((_QWORD *)ptr + 19);
if ( v6 )
free(v6);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v2; // rax
void (__fastcall *v3)(void *); // rax
void *v4; // rdi
void *v5; // rdi
void *v6; // rdi

ftp_conn_close();
v2 = *((_QWORD *)ptr + 1);
if ( v2 )
{
v3 = *(void (__fastcall **)(void *))(v2 + 48);
if ( v3 )
v3(ptr);
}
v4 = (void *)*((_QWORD *)ptr + 9);
if ( v4 )
free(v4);
v5 = (void *)*((_QWORD *)ptr + 13);
if ( v5 )
free(v5);
v6 = (void *)*((_QWORD *)ptr + 19);
if ( v6 )
free(v6);
free(ptr);
}

original_code:
void
ftp_conn_free (struct ftp_conn *conn)
{
  ftp_conn_close (conn);
  if (conn->hooks && conn->hooks->fini)
    (* conn->hooks->fini) (conn);
  if (conn->line)
    free (conn->line);
  if (conn->reply_txt)
    free (conn->reply_txt);
  if (conn->actv_data_addr)
    free (conn->actv_data_addr);
  free (conn);
}

canonical_original_code:
void ftp_conn_free(struct ftp_conn *conn)
{
  ftp_conn_close (conn);
  if (conn->hooks && conn->hooks->fini)
    (* conn->hooks->fini) (conn);
  if (conn->line)
    free (conn->line);
  if (conn->reply_txt)
    free (conn->reply_txt);
  if (conn->actv_data_addr)
    free (conn->actv_data_addr);
  free (conn);
}

variable_types: struct ftp_conn { struct ftp_conn_params { void *addr; unsigned long addr_len; int addr_type; char *user; } *params; struct ftp_conn_hooks { void (*choose_syshooks)(struct ftp_conn *conn, char *syst); void (*cntl_debug)(struct ftp_conn *conn, int type, char *txt); void (*opened)(struct ftp_conn *conn); int (*get_login_param)(struct ftp_conn *conn, int type, char **txt); void (*closed)(struct ftp_conn *conn); int (*init)(struct ftp_conn *conn); void (*fini)(struct ftp_conn *conn); int (*interrupt_check)(struct ftp_conn *conn); } *hooks; struct ftp_conn_syshooks { int (*pasv_addr)(struct ftp_conn *conn, char *txt, struct sockaddr { unsigned short sa_family; char sa_data[14]; } **addr); int (*interp_err)(struct ftp_conn *conn, char *txt, int *poss_errs); int (*start_get_stats)(struct ftp_conn *conn, char *name, int contents, int *fd, void **state); int (*cont_get_stats)(struct ftp_conn *conn, int fd, void *state, int (*add_stat)(char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stat, char *symlink_target, void *hook), void *hook); int (*append_name)(struct ftp_conn *conn, char *dir, char *name, char **composite); int (*basename)(struct ftp_conn *conn, char **name); } syshooks; int syshooks_valid; int control; char *line; unsigned long line_sz; unsigned long line_offs; unsigned long line_len; char *reply_txt; unsigned long reply_txt_sz; char *cwd; char *type; void *hook; int use_passive; struct sockaddr *actv_data_addr; } *


original_code:
error_t
ftp_conn_create (const struct ftp_conn_params *params,
   const struct ftp_conn_hooks *hooks,
   struct ftp_conn **conn)
{
  error_t err;
  struct ftp_conn *new = malloc (sizeof (struct ftp_conn));
  if (! new)
    return 12;
  new->control = -1;
  new->line = 0;
  new->line_sz = 0;
  new->line_offs = 0;
  new->line_len = 0;
  new->reply_txt = 0;
  new->reply_txt_sz = 0;
  new->params = params;
  new->hooks = hooks;
  new->syshooks_valid = 0;
  new->use_passive = 1;
  new->actv_data_addr = 0;
  new->cwd = 0;
  new->type = 0;
  bzero (&new->syshooks, sizeof new->syshooks);
  if (new->hooks && new->hooks->init)
    err = (*new->hooks->init) (new);
  else
    err = 0;
  if (err)
    ftp_conn_free (new);
  else
    *conn = new;
  return err;
}

canonical_original_code:
int ftp_conn_create(struct ftp_conn_params *params, struct ftp_conn_hooks *hooks, struct ftp_conn **conn)
{
  int err;
  struct ftp_conn *new = malloc (sizeof (struct ftp_conn));
  if (! new)
    return 12;
  new->control = -1;
  new->line = 0;
  new->line_sz = 0;
  new->line_offs = 0;
  new->line_len = 0;
  new->reply_txt = 0;
  new->reply_txt_sz = 0;
  new->params = params;
  new->hooks = hooks;
  new->syshooks_valid = 0;
  new->use_passive = 1;
  new->actv_data_addr = 0;
  new->cwd = 0;
  new->type = 0;
  bzero (&new->syshooks, sizeof new->syshooks);
  if (new->hooks && new->hooks->init)
    err = (*new->hooks->init) (new);
  else
    err = 0;
  if (err)
    ftp_conn_free (new);
  else
    *conn = new;
  return err;
}

variable_types: struct ftp_conn_params { void *addr; unsigned long addr_len; int addr_type; char *user; } *

variable_types: struct ftp_conn_hooks { void (*choose_syshooks)(struct ftp_conn { struct ftp_conn_params *params; struct ftp_conn_hooks *hooks; struct ftp_conn_syshooks { int (*pasv_addr)(struct ftp_conn *conn, char *txt, struct sockaddr { unsigned short sa_family; char sa_data[14]; } **addr); int (*interp_err)(struct ftp_conn *conn, char *txt, int *poss_errs); int (*start_get_stats)(struct ftp_conn *conn, char *name, int contents, int *fd, void **state); int (*cont_get_stats)(struct ftp_conn *conn, int fd, void *state, int (*add_stat)(char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stat, char *symlink_target, void *hook), void *hook); int (*append_name)(struct ftp_conn *conn, char *dir, char *name, char **composite); int (*basename)(struct ftp_conn *conn, char **name); } syshooks; int syshooks_valid; int control; char *line; unsigned long line_sz; unsigned long line_offs; unsigned long line_len; char *reply_txt; unsigned long reply_txt_sz; char *cwd; char *type; void *hook; int use_passive; struct sockaddr *actv_data_addr; } *conn, char *syst); void (*cntl_debug)(struct ftp_conn *conn, int type, char *txt); void (*opened)(struct ftp_conn *conn); int (*get_login_param)(struct ftp_conn *conn, int type, char **txt); void (*closed)(struct ftp_conn *conn); int (*init)(struct ftp_conn *conn); void (*fini)(struct ftp_conn *conn); int (*interrupt_check)(struct ftp_conn *conn); } *

variable_types:
conn
struct ftp_conn **


original_code:
extern inline error_t
ftp_conn_validate_syshooks (struct ftp_conn *conn)
{
  if (conn->syshooks_valid)
    return 0;
  else
    return ftp_conn_open (conn);
}


decompiled_code:
__int64 __fastcall ftp_conn_append_name(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 (__fastcall *v7)(__int64, __int64, __int64, __int64); // rax

result = ftp_conn_validate_syshooks_localalias(a1);
if ( !(_DWORD)result )
{
v7 = *(__int64 (__fastcall **)(__int64, __int64, __int64, __int64))(a1 + 48);
if ( v7 )
result = v7(a1, a2, a3, a4);
else
result = 95LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax
__int64 (__fastcall *v7)(__int64, __int64, __int64, __int64); // rax

result = func0(a1);
if ( !(_DWORD)result )
{
v7 = *(__int64 (__fastcall **)(__int64, __int64, __int64, __int64))(a1 + 48);
if ( v7 )
result = v7(a1, a2, a3, a4);
else
result = 95LL;
}
return result;
}

original_code:
error_t
ftp_conn_append_name (struct ftp_conn *conn,
        const char *dir, const char *name,
        char **composite)
{
  error_t err = ftp_conn_validate_syshooks (conn);
  if (err)
    return err;
  else if (conn->syshooks.append_name)
    return (*conn->syshooks.append_name) (conn, dir, name, composite);
  else
    return 95;
}

canonical_original_code:
int ftp_conn_append_name(struct ftp_conn *conn, char *dir, char *name, char **composite)
{
  int err = ftp_conn_validate_syshooks (conn);
  if (err)
    return err;
  else if (conn->syshooks.append_name)
    return (*conn->syshooks.append_name) (conn, dir, name, composite);
  else
    return 95;
}

variable_types:
dir
char *

variable_types:
name
char *

variable_types:
composite
char **

variable_types: err int


decompiled_code:
__int64 __fastcall ftp_conn_basename(__int64 a1, const char *a2, char **a3)
{
unsigned int v4; // er12
__int64 (__fastcall *v5)(__int64, char **); // r12
size_t v6; // r14
char *v7; // r13
char *v9; // rbp
char *s; // [rsp+8h] [rbp-30h] BYREF

v4 = ftp_conn_validate_syshooks_localalias(a1);
if ( v4 )
return v4;
v5 = *(__int64 (__fastcall **)(__int64, char **))(a1 + 56);
if ( !v5 )
return 95LL;
v6 = strlen(a2);
s = strdup(a2);
v7 = s;
if ( !s )
return 12;
v4 = v5(a1, &s);
if ( v4 )
{
free(v7);
return v4;
}
v9 = s;
if ( s != v7 )
{
if ( s >= v7 && s < &v7[v6 + 1] )
v9 = strdup(s);
free(v7);
}
*a3 = v9;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2, char **a3)
{
unsigned int v4; // er12
__int64 (__fastcall *v5)(__int64, char **); // r12
size_t v6; // r14
char *v7; // r13
char *v9; // rbp
char *s; // [rsp+8h] [rbp-30h] BYREF

v4 = func0(a1);
if ( v4 )
return v4;
v5 = *(__int64 (__fastcall **)(__int64, char **))(a1 + 56);
if ( !v5 )
return 95LL;
v6 = strlen(a2);
s = strdup(a2);
v7 = s;
if ( !s )
return 12;
v4 = v5(a1, &s);
if ( v4 )
{
free(v7);
return v4;
}
v9 = s;
if ( s != v7 )
{
if ( s >= v7 && s < &v7[v6 + 1] )
v9 = strdup(s);
free(v7);
}
*a3 = v9;
return 0LL;
}

original_code:
error_t
ftp_conn_basename (struct ftp_conn *conn, const char *composite, char **base)
{
  error_t err = ftp_conn_validate_syshooks (conn);
  if (err)
    return err;
  if (conn->syshooks.basename)
    {
      size_t in_size = strlen (composite) + 1;
      char *in = strdup (composite), *out = in;
      if (! in)
 return 12;
      err = (*conn->syshooks.basename) (conn, &out);
      if (err || out != in)
 {
   if (!err && out >= in && out < in + in_size)
     out = strdup (out);
   free (in);
 }
      if (! err)
 *base = out;
      return err;
    }
  else
    return 95;
}

canonical_original_code:
int ftp_conn_basename(struct ftp_conn *conn, char *composite, char **base)
{
  int err = ftp_conn_validate_syshooks (conn);
  if (err)
    return err;
  if (conn->syshooks.basename)
    {
      unsigned long in_size = strlen (composite) + 1;
      char *in = strdup (composite); char *out = in;
      if (! in)
 return 12;
      err = (*conn->syshooks.basename) (conn, &out);
      if (err || out != in)
 {
   if (!err && out >= in && out < in + in_size)
     out = strdup (out);
   free (in);
 }
      if (! err)
 *base = out;
      return err;
    }
  else
    return 95;
}

variable_types:
composite
char *

variable_types:
base
char **

variable_types:
in
char *

variable_types:
out
char *