getinode

decompiled_code:
void *__fastcall getinode(unsigned __int64 a1, void *a2)
{
char *v3; // r8
__int64 v4; // rbp
unsigned __int64 v5; // rdi
int v6; // ebx

v3 = (char *)lastifrag;
v4 = sblock;
if ( !lastifrag )
{
lastifrag = malloc(*(_QWORD *)(sblock + 80LL));
v3 = (char *)lastifrag;
}
v5 = *(_QWORD *)(v4 + 224);
v6 = ((a1 / *(_QWORD *)(v4 + 352)) & ~(unsigned int)*(_QWORD *)(v4 + 40)) * *(_DWORD *)(v4 + 32)
+ *(_DWORD *)(v4 + 24)
+ *(_DWORD *)(v4 + 360) * (a1 / *(_QWORD *)(v4 + 352))
+ ((a1 % *(_QWORD *)(v4 + 352) / v5) << *(_QWORD *)(v4 + 176));
if ( lastifragaddr != v6 )
{
readblock(v6 << *(_QWORD *)(v4 + 184), v3, *(_QWORD *)(v4 + 80));
v3 = (char *)lastifrag;
v5 = *(_QWORD *)(sblock + 224LL);
}
lastifragaddr = v6;
return memmove(a2, &v3[192 * (a1 % v5)], 0xC0uLL);
}

canonical_decompiled_code:
void *__fastcall func9(unsigned __int64 a1, void *a2)
{
char *v3; // r8
__int64 v4; // rbp
unsigned __int64 v5; // rdi
int v6; // ebx

v3 = (char *)lastifrag;
v4 = sblock;
if ( !lastifrag )
{
lastifrag = malloc(*(_QWORD *)(sblock + 80LL));
v3 = (char *)lastifrag;
}
v5 = *(_QWORD *)(v4 + 224);
v6 = ((a1 / *(_QWORD *)(v4 + 352)) & ~(unsigned int)*(_QWORD *)(v4 + 40)) * *(_DWORD *)(v4 + 32)
+ *(_DWORD *)(v4 + 24)
+ *(_DWORD *)(v4 + 360) * (a1 / *(_QWORD *)(v4 + 352))
+ ((a1 % *(_QWORD *)(v4 + 352) / v5) << *(_QWORD *)(v4 + 176));
if ( lastifragaddr != v6 )
{
func8(v6 << *(_QWORD *)(v4 + 184), v3, *(_QWORD *)(v4 + 80));
v3 = (char *)lastifrag;
v5 = *(_QWORD *)(sblock + 224LL);
}
lastifragaddr = v6;
return memmove(a2, &v3[192 * (a1 % v5)], 0xC0uLL);
}

original_code:
void
getinode (ino_t ino, struct dinode *di)
{
  daddr_t iblk;
  if (!lastifrag)
    lastifrag = malloc (sblock->fs_bsize);
  iblk = ((daddr_t)(((((daddr_t)((sblock)->fs_fpg * (((ino) / (sblock)->fs_ipg)))) + (sblock)->fs_cgoffset * ((((ino) / (sblock)->fs_ipg)) & ~((sblock)->fs_cgmask))) + (sblock)->fs_iblkno) + ((((((ino) % (sblock)->fs_ipg) / ((sblock)->fs_inopb))) << ((sblock))->fs_fragshift))));
  if (iblk != lastifragaddr)
    readblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
  lastifragaddr = iblk;
  bcopy (lastifrag + ((ino) % ((sblock)->fs_inopb)) * sizeof (struct dinode),
  di, sizeof (struct dinode));
}

canonical_original_code:
void getinode(unsigned long ino, struct dinode *di)
{
  int iblk;
  if (!lastifrag)
    lastifrag = malloc (sblock->fs_bsize);
  iblk = ((daddr_t)(((((daddr_t)((sblock)->fs_fpg * (((ino) / (sblock)->fs_ipg)))) + (sblock)->fs_cgoffset * ((((ino) / (sblock)->fs_ipg)) & ~((sblock)->fs_cgmask))) + (sblock)->fs_iblkno) + ((((((ino) % (sblock)->fs_ipg) / ((sblock)->fs_inopb))) << ((sblock))->fs_fragshift))));
  if (iblk != lastifragaddr)
    readblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
  lastifragaddr = iblk;
  bcopy (lastifrag + ((ino) % ((sblock)->fs_inopb)) * sizeof (struct dinode),
  di, sizeof (struct dinode));
}

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

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


writeblock

repo: jeremie-koenig/hurd

decompiled_code:
ssize_t __fastcall writeblock(unsigned int a1, void *buf, size_t n)
{
ssize_t result; // rax

if ( lseek64(writefd, (int)(a1 << 9), 0) == -1 )
errexit("CANNOT SEEK TO BLOCK %ld", a1);
result = write(writefd, buf, n);
if ( result != n )
errexit("CANNOT WRITE BLOCK %ld", a1);
fsmodified = 1;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func10(unsigned int a1, void *buf, size_t n)
{
ssize_t result; // rax

if ( lseek64(writefd, (int)(a1 << 9), 0) == -1 )
func7("CANNOT SEEK TO BLOCK %ld", a1);
result = write(writefd, buf, n);
if ( result != n )
func7("CANNOT WRITE BLOCK %ld", a1);
fsmodified = 1;
return result;
}

original_code:
void
writeblock (daddr_t addr, void *buf, size_t size)
{
  if (lseek (writefd, addr * 512, 0) == -1)
    errexit ("CANNOT SEEK TO BLOCK %ld", addr);
  if (write (writefd, buf, size) != size)
    errexit ("CANNOT WRITE BLOCK %ld", addr);
  fsmodified = 1;
}

canonical_original_code:
void writeblock(int addr, void *buf, unsigned long size)
{
  if (lseek (writefd, addr * 512, 0) == -1)
    errexit ("CANNOT SEEK TO BLOCK %ld", addr);
  if (write (writefd, buf, size) != size)
    errexit ("CANNOT WRITE BLOCK %ld", addr);
  fsmodified = 1;
}

variable_types: addr int

variable_types:
buf
void *

variable_types:
size
unsigned long

return_type: void


decompiled_code:
ssize_t __fastcall write_inode(unsigned __int64 a1, const void *a2)
{
unsigned __int64 v2; // r8
int v3; // ebx
void *v4; // r13

v2 = *(_QWORD *)(sblock + 224LL);
v3 = ((a1 / *(_QWORD *)(sblock + 352LL)) & ~(unsigned int)*(_QWORD *)(sblock + 40LL)) * *(_DWORD *)(sblock + 32LL)
+ *(_DWORD *)(sblock + 24LL)
+ *(_DWORD *)(sblock + 360LL) * (a1 / *(_QWORD *)(sblock + 352LL))
+ ((a1 % *(_QWORD *)(sblock + 352LL) / v2) << *(_QWORD *)(sblock + 176LL));
if ( lastifragaddr != v3 )
{
readblock(v3 << *(_QWORD *)(sblock + 184LL), lastifrag, *(_QWORD *)(sblock + 80LL));
v2 = *(_QWORD *)(sblock + 224LL);
}
v4 = lastifrag;
lastifragaddr = v3;
memmove((char *)lastifrag + 192 * (a1 % v2), a2, 0xC0uLL);
return writeblock(v3 << *(_QWORD *)(sblock + 184LL), v4, *(_QWORD *)(sblock + 80LL));
}

canonical_decompiled_code:
ssize_t __fastcall func11(unsigned __int64 a1, const void *a2)
{
unsigned __int64 v2; // r8
int v3; // ebx
void *v4; // r13

v2 = *(_QWORD *)(sblock + 224LL);
v3 = ((a1 / *(_QWORD *)(sblock + 352LL)) & ~(unsigned int)*(_QWORD *)(sblock + 40LL)) * *(_DWORD *)(sblock + 32LL)
+ *(_DWORD *)(sblock + 24LL)
+ *(_DWORD *)(sblock + 360LL) * (a1 / *(_QWORD *)(sblock + 352LL))
+ ((a1 % *(_QWORD *)(sblock + 352LL) / v2) << *(_QWORD *)(sblock + 176LL));
if ( lastifragaddr != v3 )
{
func8(v3 << *(_QWORD *)(sblock + 184LL), lastifrag, *(_QWORD *)(sblock + 80LL));
v2 = *(_QWORD *)(sblock + 224LL);
}
v4 = lastifrag;
lastifragaddr = v3;
memmove((char *)lastifrag + 192 * (a1 % v2), a2, 0xC0uLL);
return func10(v3 << *(_QWORD *)(sblock + 184LL), v4, *(_QWORD *)(sblock + 80LL));
}

original_code:
void
write_inode (ino_t ino, struct dinode *di)
{
  daddr_t iblk;
  iblk = ((daddr_t)(((((daddr_t)((sblock)->fs_fpg * (((ino) / (sblock)->fs_ipg)))) + (sblock)->fs_cgoffset * ((((ino) / (sblock)->fs_ipg)) & ~((sblock)->fs_cgmask))) + (sblock)->fs_iblkno) + ((((((ino) % (sblock)->fs_ipg) / ((sblock)->fs_inopb))) << ((sblock))->fs_fragshift))));
  if (iblk != lastifragaddr)
    readblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
  lastifragaddr = iblk;
  bcopy (di, lastifrag + ((ino) % ((sblock)->fs_inopb)) * sizeof (struct dinode),
  sizeof (struct dinode));
  writeblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
}

canonical_original_code:
void write_inode(unsigned long ino, struct dinode *di)
{
  int iblk;
  iblk = ((daddr_t)(((((daddr_t)((sblock)->fs_fpg * (((ino) / (sblock)->fs_ipg)))) + (sblock)->fs_cgoffset * ((((ino) / (sblock)->fs_ipg)) & ~((sblock)->fs_cgmask))) + (sblock)->fs_iblkno) + ((((((ino) % (sblock)->fs_ipg) / ((sblock)->fs_inopb))) << ((sblock))->fs_fragshift))));
  if (iblk != lastifragaddr)
    readblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
  lastifragaddr = iblk;
  bcopy (di, lastifrag + ((ino) % ((sblock)->fs_inopb)) * sizeof (struct dinode),
  sizeof (struct dinode));
  writeblock (((iblk) << (sblock)->fs_fsbtodb), lastifrag, sblock->fs_bsize);
}

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


decompiled_code:
ssize_t __fastcall clear_inode(unsigned __int64 a1, _QWORD *a2)
{
*a2 = 0LL;
a2[23] = 0LL;
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 192) >> 3));
return write_inode(a1, a2);
}

canonical_decompiled_code:
ssize_t __fastcall func12(unsigned __int64 a1, _QWORD *a2)
{
*a2 = 0LL;
a2[23] = 0LL;
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 192) >> 3));
return func11(a1, a2);
}

original_code:
void
clear_inode (ino_t ino, struct dinode *di)
{
  bzero (di, sizeof (struct dinode));
  write_inode (ino, di);
}

canonical_original_code:
void clear_inode(unsigned long ino, struct dinode *di)
{
  bzero (di, sizeof (struct dinode));
  write_inode (ino, di);
}


problem

decompiled_code:
__int64 problem(unsigned int a1, char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
push_problem(a2, arg);
return no_preen(a1);
}

canonical_decompiled_code:
__int64 func13(unsigned int a1, char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
func4(a2, arg);
return func15(a1);
}

original_code:
void
problem (int severe, char *fmt, ...)
{
  va_list args;
  __builtin_va_start(args,fmt);
  push_problem (fmt, args);
  __builtin_va_end(args);
  no_preen (severe);
}

canonical_original_code:
void problem(int severe, char *fmt, ...)
{
  __builtin_va_list args;
  __builtin_va_start(args,fmt);
  push_problem (fmt, args);
  __builtin_va_end(args);
  no_preen (severe);
}

variable_types: severe int

variable_types:
fmt
char *


decompiled_code:
void __fastcall no_preen(__int64 a1)
{
if ( (_DWORD)a1 )
{
if ( preen )
punt_constprop_0(a1);
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1)
{
if ( (_DWORD)a1 )
{
if ( preen )
func14(a1);
}
}

original_code:
static void
no_preen (int severe)
{
  if (severe && preen)
    punt ("PLEASE RUN fsck MANUALLY");
}

canonical_original_code:
static void no_preen(int severe)
{
  if (severe && preen)
    punt ("PLEASE RUN fsck MANUALLY");
}


pextend

decompiled_code:
void pextend(char *f, ...)
{
const char **v1; // rbp
char *v2; // r12
size_t v3; // rbx
size_t v4; // rax
const char *v5; // rax
const char *v6; // rbx
size_t v7; // rax
char *s; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v1 = (const char **)problems;
if ( !problems )
{
retch("No pending problem to add to");
LABEL_6:
retch("realloc failed");
goto LABEL_7;
}
va_start(arg, f);
if ( vasprintf(&s, f, arg) >= 0 )
{
v2 = (char *)*v1;
v3 = strlen(*v1);
v4 = strlen(s);
v5 = (const char *)realloc(v2, v3 + v4 + 2);
v6 = v5;
if ( v5 )
{
v7 = strlen(v5);
strcpy((char *)&v6[v7], s);
*v1 = v6;
free(s);
return;
}
goto LABEL_6;
}
LABEL_7:
retch("vasprintf failed");
warning();
}

canonical_decompiled_code:
void func16(char *f, ...)
{
const char **v1; // rbp
char *v2; // r12
size_t v3; // rbx
size_t v4; // rax
const char *v5; // rax
const char *v6; // rbx
size_t v7; // rax
char *s; // [rsp+0h] [rbp-E8h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

v1 = (const char **)problems;
if ( !problems )
{
func2("No pending problem to add to");
LABEL_6:
func2("realloc failed");
goto LABEL_7;
}
va_start(arg, f);
if ( vasprintf(&s, f, arg) >= 0 )
{
v2 = (char *)*v1;
v3 = strlen(*v1);
v4 = strlen(s);
v5 = (const char *)realloc(v2, v3 + v4 + 2);
v6 = v5;
if ( v5 )
{
v7 = strlen(v5);
strcpy((char *)&v6[v7], s);
*v1 = v6;
free(s);
return;
}
goto LABEL_6;
}
LABEL_7:
func2("vasprintf failed");
func17();
}

original_code:
void
pextend (char *fmt, ...)
{
  va_list args;
  char *more, *concat;
  struct problem *prob = problems;
  if (! prob)
    retch ("No pending problem to add to");
  __builtin_va_start(args,fmt);
  if (vasprintf (&more, fmt, args) < 0)
    retch ("vasprintf failed");
  __builtin_va_end(args);
  concat = realloc (prob->desc, strlen (prob->desc) + 1 + strlen (more) + 1);
  if (! concat)
    retch ("realloc failed");
  strcpy (concat + strlen (concat), more);
  prob->desc = concat;
  free (more);
}

canonical_original_code:
void pextend(char *fmt, ...)
{
  __builtin_va_list args;
  char *more; char *concat;
  struct problem *prob = problems;
  if (! prob)
    retch ("No pending problem to add to");
  __builtin_va_start(args,fmt);
  if (vasprintf (&more, fmt, args) < 0)
    retch ("vasprintf failed");
  __builtin_va_end(args);
  concat = realloc (prob->desc, strlen (prob->desc) + 1 + strlen (more) + 1);
  if (! concat)
    retch ("realloc failed");
  strcpy (concat + strlen (concat), more);
  prob->desc = concat;
  free (more);
}

variable_types:
more
char *

variable_types:
concat
char *

variable_types: struct problem { char *desc; struct problem *prev; } *


warning

decompiled_code:
void warning(unsigned int a1, char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
push_problem(a2, arg);
no_preen(a1);
resolve_problem(0LL, arg);
}

canonical_decompiled_code:
void func17(unsigned int a1, char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, a2);
func4(a2, arg);
func15(a1);
func3(0LL, arg);
}

original_code:
void
warning (int severe, char *fmt, ...)
{
  va_list args;
  __builtin_va_start(args,fmt);
  push_problem (fmt, args);
  __builtin_va_end(args);
  no_preen (severe);
  resolve_problem (0);
}

canonical_original_code:
void warning(int severe, char *fmt, ...)
{
  __builtin_va_list args;
  __builtin_va_start(args,fmt);
  push_problem (fmt, args);
  __builtin_va_end(args);
  no_preen (severe);
  resolve_problem (0);
}


pinode

decompiled_code:
void pinode(unsigned int a1, unsigned __int64 a2, char *a3, ...)
{
const char *v4; // rsi
struct passwd *v5; // rax
char *v6; // rax
gcc_va_list va; // [rsp+0h] [rbp-188h] BYREF
time_t timer; // [rsp+28h] [rbp-160h] BYREF
__uid_t uid[2]; // [rsp+A0h] [rbp-E8h]
unsigned __int16 v10; // [rsp+B0h] [rbp-D8h]

if ( a3 )
{
va_start(va, a3);
push_problem(a3, va);
}
if ( a2 > 1 && maxino >= a2 )
{
getinode(a2, va);
v4 = "DIR";
if ( (va[0].gp_offset & 0xF000) != 0x4000 )
v4 = "FILE";
pextend(" %s I=%Ld", v4, a2);
v5 = getpwuid(uid[0]);
if ( v5 )
pextend(" O=%s", v5->pw_name);
else
pextend(" O=%lu", *(_QWORD *)uid);
pextend(" M=0%o", LOWORD(va[0].gp_offset) | (v10 << 16));
pextend(" SZ=%llu", va[0].reg_save_area);
v6 = ctime(&timer);
pextend(" MT=%12.12s %4.4s", v6 + 4, v6 + 20);
}
else
{
pextend(" (BOGUS INODE) I=%Ld", a2);
}
no_preen(a1);
}

canonical_decompiled_code:
void func18(unsigned int a1, unsigned __int64 a2, char *a3, ...)
{
const char *v4; // rsi
struct passwd *v5; // rax
char *v6; // rax
gcc_va_list va; // [rsp+0h] [rbp-188h] BYREF
time_t timer; // [rsp+28h] [rbp-160h] BYREF
__uid_t uid[2]; // [rsp+A0h] [rbp-E8h]
unsigned __int16 v10; // [rsp+B0h] [rbp-D8h]

if ( a3 )
{
va_start(va, a3);
func4(a3, va);
}
if ( a2 > 1 && maxino >= a2 )
{
func9(a2, va);
v4 = "DIR";
if ( (va[0].gp_offset & 0xF000) != 0x4000 )
v4 = "FILE";
func16(" %s I=%Ld", v4, a2);
v5 = getpwuid(uid[0]);
if ( v5 )
func16(" O=%s", v5->pw_name);
else
func16(" O=%lu", *(_QWORD *)uid);
func16(" M=0%o", LOWORD(va[0].gp_offset) | (v10 << 16));
func16(" SZ=%llu", va[0].reg_save_area);
v6 = ctime(&timer);
func16(" MT=%12.12s %4.4s", v6 + 4, v6 + 20);
}
else
{
func16(" (BOGUS INODE) I=%Ld", a2);
}
func15(a1);
}

original_code:
void
pinode (int severe, ino_t ino, char *fmt, ...)
{
  if (fmt)
    {
      va_list args;
      __builtin_va_start(args,fmt);
      push_problem (fmt, args);
      __builtin_va_end(args);
    }
  if (ino < ((ino_t)2) || ino > maxino)
    pextend (" (BOGUS INODE) I=%Ld", ino);
  else
    {
      char *p;
      struct dinode dino;
      struct passwd *pw;
      getinode (ino, &dino);
      pextend (" %s I=%Ld", ((((&dino)->di_modeh << 16) | (&dino)->di_model) & 0170000) == 0040000 ? "DIR" : "FILE",
      ino);
      pw = getpwuid (dino.di_uid);
      if (pw)
 pextend (" O=%s", pw->pw_name);
      else
 pextend (" O=%lu", dino.di_uid);
      pextend (" M=0%o", (((&dino)->di_modeh << 16) | (&dino)->di_model));
      pextend (" SZ=%llu", dino.di_size);
      p = ctime (&dino.di_mtime.tv_sec);
      pextend (" MT=%12.12s %4.4s", &p[4], &p[20]);
    }
  no_preen (severe);
}

canonical_original_code:
void pinode(int severe, unsigned long ino, char *fmt, ...)
{
  if (fmt)
    {
      __builtin_va_list args;
      __builtin_va_start(args,fmt);
      push_problem (fmt, args);
      __builtin_va_end(args);
    }
  if (ino < ((unsigned long)2) || ino > maxino)
    pextend (" (BOGUS INODE) I=%Ld", ino);
  else
    {
      char *p;
      struct dinode dino;
      struct passwd *pw;
      getinode (ino, &dino);
      pextend (" %s I=%Ld", ((((&dino)->di_modeh << 16) | (&dino)->di_model) & 0170000) == 0040000 ? "DIR" : "FILE",
      ino);
      pw = getpwuid (dino.di_uid);
      if (pw)
 pextend (" O=%s", pw->pw_name);
      else
 pextend (" O=%lu", dino.di_uid);
      pextend (" M=0%o", (((&dino)->di_modeh << 16) | (&dino)->di_model));
      pextend (" SZ=%llu", dino.di_size);
      p = ctime (&dino.di_mtime.tv_sec);
      pextend (" MT=%12.12s %4.4s", &p[4], &p[20]);
    }
  no_preen (severe);
}

variable_types:
p
char *

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 passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


pfix

decompiled_code:
void __fastcall pfix(const char *a1, void *a2)
{
if ( preen )
{
if ( !a1 )
a1 = "FIXED";
resolve_problem(a1, a2);
}
}

canonical_decompiled_code:
void __fastcall func19(const char *a1, void *a2)
{
if ( preen )
{
if ( !a1 )
a1 = "FIXED";
func3(a1, a2);
}
}

original_code:
void
pfix (char *fix)
{
  if (preen)
    resolve_problem (fix ?: "FIXED");
}

canonical_original_code:
void pfix(char *fix)
{
  if (preen)
    resolve_problem (fix ?: "FIXED");
}

variable_types:
fix
char *


pfail

decompiled_code:
void __fastcall pfail(const char *a1, void *a2)
{
if ( preen )
resolve_problem(a1, a2);
}

canonical_decompiled_code:
void __fastcall func20(const char *a1, void *a2)
{
if ( preen )
func3(a1, a2);
}

original_code:
void
pfail (char *failure)
{
  if (preen)
    resolve_problem (failure);
}

canonical_original_code:
void pfail(char *failure)
{
  if (preen)
    resolve_problem (failure);
}

variable_types:
failure
char *


reply

decompiled_code:
__int64 __fastcall reply(const char *a1, void *a2)
{
unsigned int v2; // er13
char v3; // bp
char v4; // bp

v2 = preen;
if ( preen )
{
retch("Got to reply() in preen mode");
JUMPOUT(0xDBELL);
}
resolve_problem(0LL, a2);
if ( !strcmp(a1, "CONTINUE") )
{
if ( !__PAIR64__(nowrite, noquery) )
goto LABEL_4;
LABEL_16:
printf("%s? yes\n\n", a1);
return 1LL;
}
if ( nowrite || writefd < 0 )
{
fix_denied = 1;
printf("%s? no\n\n", a1);
return v2;
}
if ( noquery )
goto LABEL_16;
LABEL_4:
while ( 2 )
{
printf("%s? [yn] ", a1);
fflush(stdout);
v3 = getchar();
while ( 1 )
{
if ( v3 == 10 )
goto LABEL_4;
if ( getchar() == 10 )
break;
if ( feof(stdin) )
goto LABEL_11;
}
v4 = v3 & 0xDF;
if ( v4 != 89 )
{
if ( v4 != 78 )
continue;
putchar(10);
LABEL_11:
fix_denied = 1;
return v2;
}
break;
}
v2 = 1;
putchar(10);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func21(const char *a1, void *a2)
{
unsigned int v2; // er13
char v3; // bp
char v4; // bp

v2 = preen;
if ( preen )
{
func2("Got to reply() in preen mode");
JUMPOUT(0xDBELL);
}
func3(0LL, a2);
if ( !strcmp(a1, "CONTINUE") )
{
if ( !__PAIR64__(nowrite, noquery) )
goto LABEL_4;
LABEL_16:
printf("%s? yes\n\n", a1);
return 1LL;
}
if ( nowrite || writefd < 0 )
{
fix_denied = 1;
printf("%s? no\n\n", a1);
return v2;
}
if ( noquery )
goto LABEL_16;
LABEL_4:
while ( 2 )
{
printf("%s? [yn] ", a1);
fflush(stdout);
v3 = getchar();
while ( 1 )
{
if ( v3 == 10 )
goto LABEL_4;
if ( getchar() == 10 )
break;
if ( feof(stdin) )
goto LABEL_11;
}
v4 = v3 & 0xDF;
if ( v4 != 89 )
{
if ( v4 != 78 )
continue;
putchar(10);
LABEL_11:
fix_denied = 1;
return v2;
}
break;
}
v2 = 1;
putchar(10);
return v2;
}

original_code:
int
reply (char *question)
{
  int persevere;
  char c;
  if (preen)
    retch ("Got to reply() in preen mode");
  resolve_problem (0);
  persevere = !strcmp (question, "CONTINUE");
  if (!persevere && (nowrite || writefd < 0))
    {
      fix_denied = 1;
      printf ("%s? no\n\n", question);
      return 0;
    }
  else if (noquery || (persevere && nowrite))
    {
      printf ("%s? yes\n\n", question);
      return 1;
    }
 else
    {
      do
 {
   printf ("%s? [yn] ", question);
   fflush (stdout);
   c = getchar ();
   while (c != '\n' && getchar () != '\n')
     if (feof (stdin))
       {
  fix_denied = 1;
  return 0;
       }
 }
      while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
      putchar ('\n');
      if (c == 'y' || c == 'Y')
 return 1;
      else
 {
   fix_denied = 1;
   return 0;
 }
    }
}

canonical_original_code:
int reply(char *question)
{
  int persevere;
  char c;
  if (preen)
    retch ("Got to reply() in preen mode");
  resolve_problem (0);
  persevere = !strcmp (question, "CONTINUE");
  if (!persevere && (nowrite || writefd < 0))
    {
      fix_denied = 1;
      printf ("%s? no\n\n", question);
      return 0;
    }
  else if (noquery || (persevere && nowrite))
    {
      printf ("%s? yes\n\n", question);
      return 1;
    }
 else
    {
      do
 {
   printf ("%s? [yn] ", question);
   fflush (stdout);
   c = getchar ();
   while (c != '\n' && getchar () != '\n')
     if (feof (stdin))
       {
  fix_denied = 1;
  return 0;
       }
 }
      while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
      putchar ('\n');
      if (c == 'y' || c == 'Y')
 return 1;
      else
 {
   fix_denied = 1;
   return 0;
 }
    }
}

variable_types:
question
char *

variable_types: persevere int

variable_types: c char

return_type: int


decompiled_code:
__int64 __fastcall ftp_conn_start_get_names(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
_QWORD *v6; // r12
__int64 result; // rax
unsigned int v8; // [rsp+Ch] [rbp-34h]

v6 = malloc(0x1B80uLL);
if ( !v6 )
return 12LL;
result = ftp_conn_start_list(a1, a2, a3);
if ( (_DWORD)result )
{
v8 = result;
free(v6);
result = v8;
}
else
{
*v6 = 0LL;
v6[2] = 0LL;
v6[1] = 0LL;
*((_DWORD *)v6 + 6) = 0;
v6[4] = 0LL;
*a4 = v6;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, _QWORD *a4)
{
_QWORD *v6; // r12
__int64 result; // rax
unsigned int v8; // [rsp+Ch] [rbp-34h]

v6 = malloc(0x1B80uLL);
if ( !v6 )
return 12LL;
result = ftp_conn_start_list(a1, a2, a3);
if ( (_DWORD)result )
{
v8 = result;
free(v6);
result = v8;
}
else
{
*v6 = 0LL;
v6[2] = 0LL;
v6[1] = 0LL;
*((_DWORD *)v6 + 6) = 0;
v6[4] = 0LL;
*a4 = v6;
}
return result;
}

original_code:
error_t
ftp_conn_start_get_names (struct ftp_conn *conn,
     const char *name, int *fd, void **state)
{
  error_t err;
  struct get_names_state *s = malloc (sizeof (struct get_names_state));
  if (! s)
    return 12;
  err = ftp_conn_start_list (conn, name, fd);
  if (err)
    free (s);
  else
    {
      s->name = 0;
      s->name_len = s->name_alloced = 0;
      s->name_partial = 0;
      s->buf_len = 0;
      *state = s;
    }
  return err;
}

canonical_original_code:
int ftp_conn_start_get_names(struct ftp_conn *conn, char *name, int *fd, void **state)
{
  int err;
  struct get_names_state *s = malloc (sizeof (struct get_names_state));
  if (! s)
    return 12;
  err = ftp_conn_start_list (conn, name, fd);
  if (err)
    free (s);
  else
    {
      s->name = 0;
      s->name_len = s->name_alloced = 0;
      s->name_partial = 0;
      s->buf_len = 0;
      *state = s;
    }
  return err;
}

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:
fd
int *

variable_types:
state
void **

variable_types: err int

variable_types: struct get_names_state { char *name; unsigned long name_len; unsigned long name_alloced; int name_partial; unsigned long buf_len; char buf[7000]; } *

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_get_names(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(void *, __int64), __int64 a4)
{
__int64 result; // rax
int v7; // [rsp+4h] [rbp-2Ch] BYREF
__int64 v8[5]; // [rsp+8h] [rbp-28h] BYREF

result = ftp_conn_start_get_names(a1, a2, (__int64)&v7, v8);
if ( !(_DWORD)result )
{
do
result = ftp_conn_cont_get_names(a1, v7, v8[0], a3, a4);
while ( (_DWORD)result == 11 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(void *, __int64), __int64 a4)
{
__int64 result; // rax
int v7; // [rsp+4h] [rbp-2Ch] BYREF
__int64 v8[5]; // [rsp+8h] [rbp-28h] BYREF

result = func1(a1, a2, (__int64)&v7, v8);
if ( !(_DWORD)result )
{
do
result = func2(a1, v7, v8[0], a3, a4);
while ( (_DWORD)result == 11 );
}
return result;
}

original_code:
error_t
ftp_conn_get_names (struct ftp_conn *conn, const char *name,
      ftp_conn_add_name_fun_t add_name, void *hook)
{
  int fd;
  void *state;
  error_t err = ftp_conn_start_get_names (conn, name, &fd, &state);
  if (err)
    return err;
  do
    err = ftp_conn_cont_get_names (conn, fd, state, add_name, hook);
  while (err == 11);
  return err;
}

canonical_original_code:
int ftp_conn_get_names(struct ftp_conn *conn, char *name, int (*add_name)(char *name, void *hook), void *hook)
{
  int fd;
  void *state;
  int err = ftp_conn_start_get_names (conn, name, &fd, &state);
  if (err)
    return err;
  do
    err = ftp_conn_cont_get_names (conn, fd, state, add_name, hook);
  while (err == 11);
  return err;
}

variable_types:
hook
void *

variable_types: fd int

variable_types:
state
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_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);
}


sighup

decompiled_code:
void sighup()
{
pending_hup = 1;
}

canonical_decompiled_code:
void func0()
{
pending_hup = 1;
}

original_code:
static void
sighup (int signo)
{
  pending_hup = 1;
}

canonical_original_code:
static void sighup(int signo)
{
  pending_hup = 1;
}

variable_types: signo int


sigterm

decompiled_code:
void sigterm()
{
pending_term = 1;
}

canonical_decompiled_code:
void func1()
{
pending_term = 1;
}

original_code:
static void
sigterm (int signo)
{
  pending_term = 1;
}

canonical_original_code:
static void sigterm(int signo)
{
  pending_term = 1;
}


original_code:
static void
free_argvs (struct terminal *t)
{
  if (t->getty_argv)
    {
      free (t->getty_argv[0]);
      free (t->getty_argv);
    }
  if (t->window_argv)
    {
      free (t->window_argv[0]);
      free (t->window_argv);
    }
}

canonical_original_code:
static void free_argvs(struct terminal *t)
{
  if (t->getty_argv)
    {
      free (t->getty_argv[0]);
      free (t->getty_argv);
    }
  if (t->window_argv)
    {
      free (t->window_argv[0]);
      free (t->window_argv);
    }
}

variable_types: struct terminal { char *name; char **getty_argv; int on; int pid; int read; } *


decompiled_code:
__int64 __fastcall setup_terminal(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
const char *v7; // rdx
char **v8; // rax
char *v9; // rdi
char **v10; // rdi
__int64 result; // rax
char *ptr; // [rsp+8h] [rbp-20h] BYREF
__int64 v13; // [rsp+10h] [rbp-18h]
char *v14; // [rsp+18h] [rbp-10h]

v13 = a1;
v14 = &a7;
free_argvs(a1);
if ( (*(_BYTE *)(a2 + 24) & 1) != 0 && (v7 = *(const char **)(a2 + 8)) != 0LL )
{
asprintf(&ptr, "%s %s", v7, *(const char **)a2);
if ( ptr )
{
v8 = make_args_0(ptr);
v9 = ptr;
*(_QWORD *)(v13 + 8) = v8;
free(v9);
}
else
{
error(0, 12, "cannot allocate arguments for %s", *(const char **)v13);
*(_QWORD *)(v13 + 8) = 0LL;
}
v10 = *(char ***)(a2 + 32);
if ( v10 )
v10 = make_args_0((const char *)v10);
result = v13;
*(_QWORD *)(v13 + 16) = v10;
}
else
{
result = v13;
*(_QWORD *)(v13 + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, char a7)
{
const char *v7; // rdx
char **v8; // rax
char *v9; // rdi
char **v10; // rdi
__int64 result; // rax
char *ptr; // [rsp+8h] [rbp-20h] BYREF
__int64 v13; // [rsp+10h] [rbp-18h]
char *v14; // [rsp+18h] [rbp-10h]

v13 = a1;
v14 = &a7;
func2(a1);
if ( (*(_BYTE *)(a2 + 24) & 1) != 0 && (v7 = *(const char **)(a2 + 8)) != 0LL )
{
asprintf(&ptr, "%s %s", v7, *(const char **)a2);
if ( ptr )
{
v8 = func3(ptr);
v9 = ptr;
*(_QWORD *)(v13 + 8) = v8;
free(v9);
}
else
{
error(0, 12, "cannot allocate arguments for %s", *(const char **)v13);
*(_QWORD *)(v13 + 8) = 0LL;
}
v10 = *(char ***)(a2 + 32);
if ( v10 )
v10 = func3((const char *)v10);
result = v13;
*(_QWORD *)(v13 + 16) = v10;
}
else
{
result = v13;
*(_QWORD *)(v13 + 16) = 0LL;
*(_QWORD *)(result + 8) = 0LL;
}
return result;
}

original_code:
static void
setup_terminal (struct terminal *t, struct ttyent *tt)
{
  free_argvs (t);
  if ((tt->ty_status & 0x01) && tt->ty_getty)
    {
      char **make_args (const char *line)
 {
   int argc;
   char *argz, **argv;
   size_t len;
   argz_create_sep (line, ' ', &argz, &len);
   argc = argz_count (argz, len);
   argv = malloc ((argc + 1) * sizeof (char *));
   if (argv == 0)
     error (0, 12,
     "cannot allocate argument vector for %s", t->name);
   else
     argz_extract (argz, len, argv);
   return argv;
 }
      char *line;
      asprintf (&line, "%s %s", tt->ty_getty, tt->ty_name);
      if (line == 0)
 {
   error (0, 12,
   "cannot allocate arguments for %s", t->name);
   t->getty_argv = 0;
 }
      else
 {
   t->getty_argv = make_args (line);
   free (line);
 }
      t->window_argv = tt->ty_window ? make_args (tt->ty_window) : 0;
    }
  else
      t->getty_argv = t->window_argv = 0;
}

canonical_original_code:
static void setup_terminal(struct terminal *t, struct ttyent *tt)
{
  free_argvs (t);
  if ((tt->ty_status & 0x01) && tt->ty_getty)
    {
      char **make_args (const char *line)
 {
   int argc;
   char *argz; char **argv;
   unsigned long len;
   argz_create_sep (line, ' ', &argz, &len);
   argc = argz_count (argz, len);
   argv = malloc ((argc + 1) * sizeof (char *));
   if (argv == 0)
     error (0, 12,
     "cannot allocate argument vector for %s", t->name);
   else
     argz_extract (argz, len, argv);
   return argv;
 }
      char *line;
      asprintf (&line, "%s %s", tt->ty_getty, tt->ty_name);
      if (line == 0)
 {
   error (0, 12,
   "cannot allocate arguments for %s", t->name);
   t->getty_argv = 0;
 }
      else
 {
   t->getty_argv = make_args (line);
   free (line);
 }
      t->window_argv = tt->ty_window ? make_args (tt->ty_window) : 0;
    }
  else
      t->getty_argv = t->window_argv = 0;
}

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

variable_types: argc int

variable_types:
argz
char *

variable_types:
argv
char **

variable_types:
len
unsigned long

variable_types:
line
char *

user_defined_types: struct terminal { char *name; char **getty_argv; int on; int pid; int read; }


decompiled_code:
char **__fastcall add_terminal(const char **a1)
{
int v1; // er13
int v2; // ebx
char **v3; // r12
const char *v4; // r13
char *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
int v11; // er14
char **v12; // rax
char v13; // [rsp+0h] [rbp-28h]

v1 = ttyslen;
v2 = nttys;
if ( nttys >= ttyslen )
{
v11 = 2 * ttyslen;
v12 = (char **)realloc(ttys, 80LL * ttyslen);
v3 = v12;
if ( !v12 )
{
error(0, 12, "cannot expand terminals table past %d", (unsigned int)v1);
return v3;
}
ttys = v12;
v3 = &v12[5 * v2];
memset(v3, 0, v1);
ttyslen = v11;
}
else
{
v3 = (char **)((char *)ttys + 40 * nttys);
}
v4 = *a1;
v5 = strdup(*a1);
*v3 = v5;
if ( v5 )
{
nttys = v2 + 1;
setup_terminal((__int64)v3, (__int64)a1, v6, v7, v8, v9, v13);
if ( v3[1] )
*((_DWORD *)v3 + 6) = 1;
}
else
{
error(0, 12, "cannot allocate entry for %s", v4);
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
char **__fastcall func5(const char **a1)
{
int v1; // er13
int v2; // ebx
char **v3; // r12
const char *v4; // r13
char *v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // r8
__int64 v9; // r9
int v11; // er14
char **v12; // rax
char v13; // [rsp+0h] [rbp-28h]

v1 = ttyslen;
v2 = nttys;
if ( nttys >= ttyslen )
{
v11 = 2 * ttyslen;
v12 = (char **)realloc(ttys, 80LL * ttyslen);
v3 = v12;
if ( !v12 )
{
error(0, 12, "cannot expand terminals table past %d", (unsigned int)v1);
return v3;
}
ttys = v12;
v3 = &v12[5 * v2];
memset(v3, 0, v1);
ttyslen = v11;
}
else
{
v3 = (char **)((char *)ttys + 40 * nttys);
}
v4 = *a1;
v5 = strdup(*a1);
*v3 = v5;
if ( v5 )
{
nttys = v2 + 1;
func4((__int64)v3, (__int64)a1, v6, v7, v8, v9, v13);
if ( v3[1] )
*((_DWORD *)v3 + 6) = 1;
}
else
{
error(0, 12, "cannot allocate entry for %s", v4);
v3 = 0LL;
}
return v3;
}

original_code:
static struct terminal *
add_terminal (struct ttyent *tt)
{
  struct terminal *t;
  if (nttys >= ttyslen)
    {
      struct terminal *newttys = realloc (ttys,
       (ttyslen * 2) * sizeof ttys[0]);
      if (newttys == 0)
 {
   error (0, 12, "cannot expand terminals table past %d", ttyslen);
   return 0;
 }
      else
 {
   ttys = newttys;
   memset (&ttys[nttys], 0, ttyslen);
   ttyslen *= 2;
 }
    }
  t = &ttys[nttys];
  t->name = strdup (tt->ty_name);
  if (t->name == 0)
    {
      error (0, 12, "cannot allocate entry for %s", tt->ty_name);
      return 0;
    }
  nttys++;
  setup_terminal (t, tt);
  if (t->getty_argv)
    t->on = 1;
  return t;
}

canonical_original_code:
static struct terminal *add_terminal(struct ttyent *tt)
{
  struct terminal *t;
  if (nttys >= ttyslen)
    {
      struct terminal *newttys = realloc (ttys,
       (ttyslen * 2) * sizeof ttys[0]);
      if (newttys == 0)
 {
   error (0, 12, "cannot expand terminals table past %d", ttyslen);
   return 0;
 }
      else
 {
   ttys = newttys;
   memset (&ttys[nttys], 0, ttyslen);
   ttyslen *= 2;
 }
    }
  t = &ttys[nttys];
  t->name = strdup (tt->ty_name);
  if (t->name == 0)
    {
      error (0, 12, "cannot allocate entry for %s", tt->ty_name);
      return 0;
    }
  nttys++;
  setup_terminal (t, tt);
  if (t->getty_argv)
    t->on = 1;
  return t;
}

return_type: struct terminal { char *name; char **getty_argv; int on; int pid; int read; } *

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


run

decompiled_code:
__pid_t __fastcall run(char **argv, int a2)
{
__pid_t result; // eax
int *v3; // rax
int *v4; // r12

result = fork();
if ( result < 0 )
{
v3 = _errno_location();
error(0, *v3, "fork");
result = 0;
}
else if ( !result )
{
v4 = _errno_location();
if ( a2 )
goto LABEL_7;
while ( 1 )
{
*v4 = 0;
execv(*argv, argv);
error(127, *v4, "%s", *argv);
LABEL_7:
if ( setsid() == -1 )
error(0, *v4, "setsid");
}
}
return result;
}

canonical_decompiled_code:
__pid_t __fastcall func6(char **argv, int a2)
{
__pid_t result; // eax
int *v3; // rax
int *v4; // r12

result = fork();
if ( result < 0 )
{
v3 = _errno_location();
error(0, *v3, "fork");
result = 0;
}
else if ( !result )
{
v4 = _errno_location();
if ( a2 )
goto LABEL_7;
while ( 1 )
{
*v4 = 0;
execv(*argv, argv);
error(127, *v4, "%s", *argv);
LABEL_7:
if ( setsid() == -1 )
error(0, *v4, "setsid");
}
}
return result;
}

original_code:
static pid_t
run (char **argv, int do_setsid)
{
  pid_t pid;
  pid = fork ();
  if (pid < 0)
    {
      error (0, (*__errno_location ()), "fork");
      return 0;
    }
  if (pid > 0)
    return pid;
  else
    {
      if (do_setsid && setsid () == -1)
 error (0, (*__errno_location ()), "setsid");
      (*__errno_location ()) = 0;
      execv (argv[0], argv);
      error (127, (*__errno_location ()), "%s", argv[0]);
    }
  return -1;
}

canonical_original_code:
static int run(char **argv, int do_setsid)
{
  int pid;
  pid = fork ();
  if (pid < 0)
    {
      error (0, (*__errno_location ()), "fork");
      return 0;
    }
  if (pid > 0)
    return pid;
  else
    {
      if (do_setsid && setsid () == -1)
 error (0, (*__errno_location ()), "setsid");
      (*__errno_location ()) = 0;
      execv (argv[0], argv);
      error (127, (*__errno_location ()), "%s", argv[0]);
    }
  return -1;
}

variable_types: pid int


decompiled_code:
__int64 __fastcall startup_terminal(__int64 a1)
{
char **v2; // rdi
__pid_t v3; // eax

if ( !*(_DWORD *)(a1 + 24) )
_assert_fail("t->on", "runttys.c", 0xF2u, "startup_terminal");
v2 = *(char ***)(a1 + 8);
if ( !v2 )
_assert_fail("t->getty_argv", "runttys.c", 0xF3u, "startup_terminal");
if ( *(_QWORD *)(a1 + 16) )
{
if ( !run(*(char ***)(a1 + 16), 1) )
{
LABEL_7:
*(_QWORD *)(a1 + 24) = 0LL;
return 1LL;
}
sleep(3u);
v2 = *(char ***)(a1 + 8);
}
v3 = run(v2, 0);
if ( !v3 )
goto LABEL_7;
*(_DWORD *)(a1 + 28) = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
char **v2; // rdi
__pid_t v3; // eax

if ( !*(_DWORD *)(a1 + 24) )
_assert_fail("t->on", "runttys.c", 0xF2u, "startup_terminal");
v2 = *(char ***)(a1 + 8);
if ( !v2 )
_assert_fail("t->getty_argv", "runttys.c", 0xF3u, "startup_terminal");
if ( *(_QWORD *)(a1 + 16) )
{
if ( !func6(*(char ***)(a1 + 16), 1) )
{
LABEL_7:
*(_QWORD *)(a1 + 24) = 0LL;
return 1LL;
}
sleep(3u);
v2 = *(char ***)(a1 + 8);
}
v3 = func6(v2, 0);
if ( !v3 )
goto LABEL_7;
*(_DWORD *)(a1 + 28) = v3;
return 0LL;
}

original_code:
static int
startup_terminal (struct terminal *t)
{
  pid_t pid;
  ((void) sizeof ((t->on) ? 1 : 0), __extension__ ({ if (t->on) ; else __assert_fail ("t->on", "runttys.c", 242, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((t->getty_argv) ? 1 : 0), __extension__ ({ if (t->getty_argv) ; else __assert_fail ("t->getty_argv", "runttys.c", 243, __extension__ __PRETTY_FUNCTION__); }));
  if (t->window_argv)
    {
      pid = run (t->window_argv, 1);
      if (!pid)
 goto error;
      sleep (3);
    }
  pid = run (t->getty_argv, 0);
  if (pid == 0)
    {
    error:
      t->pid = 0;
      t->on = 0;
      return 1;
    }
  else
    {
      t->pid = pid;
      return 0;
    }
}

canonical_original_code:
static int startup_terminal(struct terminal *t)
{
  int pid;
  ((void) sizeof ((t->on) ? 1 : 0), __extension__ ({ if (t->on) ; else __assert_fail ("t->on", "runttys.c", 242, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((t->getty_argv) ? 1 : 0), __extension__ ({ if (t->getty_argv) ; else __assert_fail ("t->getty_argv", "runttys.c", 243, __extension__ __PRETTY_FUNCTION__); }));
  if (t->window_argv)
    {
      pid = run (t->window_argv, 1);
      if (!pid)
 goto error;
      sleep (3);
    }
  pid = run (t->getty_argv, 0);
  if (pid == 0)
    {
    error:
      t->pid = 0;
      t->on = 0;
      return 1;
    }
  else
    {
      t->pid = pid;
      return 0;
    }
}


decompiled_code:
const char **__fastcall find_line(char *s2)
{
const char **v1; // r12
const char **v2; // rbp

if ( nttys <= 0 )
return 0LL;
v1 = (const char **)ttys;
v2 = (const char **)((char *)ttys + 40 * (unsigned int)(nttys - 1) + 40);
while ( strcmp(*v1, s2) )
{
v1 += 5;
if ( v1 == v2 )
return 0LL;
}
return v1;
}

canonical_decompiled_code:
const char **__fastcall func8(char *s2)
{
const char **v1; // r12
const char **v2; // rbp

if ( nttys <= 0 )
return 0LL;
v1 = (const char **)ttys;
v2 = (const char **)((char *)ttys + 40 * (unsigned int)(nttys - 1) + 40);
while ( strcmp(*v1, s2) )
{
v1 += 5;
if ( v1 == v2 )
return 0LL;
}
return v1;
}

original_code:
static struct terminal *
find_line (char *line)
{
  int i;
  for (i = 0; i < nttys; i++)
    if (!strcmp (ttys[i].name, line))
      return &ttys[i];
  return 0;
}

canonical_original_code:
static struct terminal *find_line(char *line)
{
  int i;
  for (i = 0; i < nttys; i++)
    if (!strcmp (ttys[i].name, line))
      return &ttys[i];
  return 0;
}

variable_types: i int


decompiled_code:
__int64 init_ttys()
{
struct ttyent *v0; // rdi
__int64 result; // rax
int *v2; // rax

ttyslen = 10;
nttys = 0;
ttys = calloc(0xAuLL, 0x28uLL);
if ( ttys )
{
if ( setttyent() )
{
while ( 1 )
{
v0 = getttyent();
if ( !v0 )
break;
while ( v0->ty_name )
{
add_terminal((const char **)&v0->ty_name);
v0 = getttyent();
if ( !v0 )
goto LABEL_6;
}
}
LABEL_6:
endttyent();
result = 0LL;
}
else
{
v2 = _errno_location();
error(0, *v2, "%s", "/etc/ttys");
result = 1LL;
}
}
else
{
error(2, 12, "cannot allocate table");
result = free_ttys();
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
struct ttyent *v0; // rdi
__int64 result; // rax
int *v2; // rax

ttyslen = 10;
nttys = 0;
ttys = calloc(0xAuLL, 0x28uLL);
if ( ttys )
{
if ( setttyent() )
{
while ( 1 )
{
v0 = getttyent();
if ( !v0 )
break;
while ( v0->ty_name )
{
func5((const char **)&v0->ty_name);
v0 = getttyent();
if ( !v0 )
goto LABEL_6;
}
}
LABEL_6:
endttyent();
result = 0LL;
}
else
{
v2 = _errno_location();
error(0, *v2, "%s", "/etc/ttys");
result = 1LL;
}
}
else
{
error(2, 12, "cannot allocate table");
result = func11();
}
return result;
}

original_code:
int
init_ttys (void)
{
  struct ttyent *tt;
  ttyslen = 10;
  nttys = 0;
  ttys = calloc (ttyslen, sizeof ttys[0]);
  if (ttys == 0)
    error (2, 12, "cannot allocate table");
  if (!setttyent ())
    {
      error (0, (*__errno_location ()), "%s", "/etc/ttys");
      return 1;
    }
  while ((tt = getttyent ()))
    {
      if (!tt->ty_name)
 continue;
      add_terminal (tt);
    }
  endttyent ();
  return 0;
}

canonical_original_code:
int init_ttys()
{
  struct ttyent *tt;
  ttyslen = 10;
  nttys = 0;
  ttys = calloc (ttyslen, sizeof ttys[0]);
  if (ttys == 0)
    error (2, 12, "cannot allocate table");
  if (!setttyent ())
    {
      error (0, (*__errno_location ()), "%s", "/etc/ttys");
      return 1;
    }
  while ((tt = getttyent ()))
    {
      if (!tt->ty_name)
 continue;
      add_terminal (tt);
    }
  endttyent ();
  return 0;
}


decompiled_code:
void free_ttys()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp
__int64 v3; // rdi

v0 = ttys;
if ( nttys > 0 )
{
v1 = (void **)ttys;
v2 = (void **)((char *)ttys + 40 * (unsigned int)(nttys - 1) + 40);
do
{
v3 = (__int64)v1;
v1 += 5;
free_argvs(v3);
free(*(v1 - 5));
}
while ( v2 != v1 );
}
free(v0);
}

canonical_decompiled_code:
void func11()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp
__int64 v3; // rdi

v0 = ttys;
if ( nttys > 0 )
{
v1 = (void **)ttys;
v2 = (void **)((char *)ttys + 40 * (unsigned int)(nttys - 1) + 40);
do
{
v3 = (__int64)v1;
v1 += 5;
func2(v3);
free(*(v1 - 5));
}
while ( v2 != v1 );
}
free(v0);
}

original_code:
void
free_ttys (void)
{
  int i;
  for (i = 0; i < nttys; i++)
    {
      free_argvs (&ttys[i]);
      free (ttys[i].name);
    }
  free (ttys);
}

canonical_original_code:
void free_ttys()
{
  int i;
  for (i = 0; i < nttys; i++)
    {
      free_argvs (&ttys[i]);
      free (ttys[i].name);
    }
  free (ttys);
}


decompiled_code:
__int64 startup_ttys()
{
int v0; // er12
__int64 v1; // rbx
char *v2; // rdi

if ( nttys <= 0 )
return 1LL;
v0 = 0;
v1 = 0LL;
do
{
while ( 1 )
{
v2 = (char *)ttys + 40 * v1;
if ( *((_DWORD *)v2 + 6) )
break;
if ( nttys <= (int)++v1 )
return v0 ^ 1u;
}
if ( !(unsigned int)startup_terminal((__int64)v2) )
v0 = 1;
++v1;
}
while ( nttys > (int)v1 );
return v0 ^ 1u;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // er12
__int64 v1; // rbx
char *v2; // rdi

if ( nttys <= 0 )
return 1LL;
v0 = 0;
v1 = 0LL;
do
{
while ( 1 )
{
v2 = (char *)ttys + 40 * v1;
if ( *((_DWORD *)v2 + 6) )
break;
if ( nttys <= (int)++v1 )
return v0 ^ 1u;
}
if ( !(unsigned int)func7((__int64)v2) )
v0 = 1;
++v1;
}
while ( nttys > (int)v1 );
return v0 ^ 1u;
}

original_code:
int
startup_ttys (void)
{
  int i;
  int didone, fail;
  didone = 0;
  for (i = 0; i < nttys; i++)
    if (ttys[i].on)
      {
 fail = startup_terminal (&ttys[i]);
 if (!fail)
   didone = 1;
      }
  return !didone;
}

canonical_original_code:
int startup_ttys()
{
  int i;
  int didone; int fail;
  didone = 0;
  for (i = 0; i < nttys; i++)
    if (ttys[i].on)
      {
 fail = startup_terminal (&ttys[i]);
 if (!fail)
   didone = 1;
      }
  return !didone;
}

variable_types: didone int

variable_types: fail int


decompiled_code:
void __fastcall restart_terminal(int a1)
{
__int64 v1; // rbx
char *v2; // rbp
int v3; // eax

if ( nttys > 0 )
{
v1 = 0LL;
do
{
while ( 1 )
{
v2 = (char *)ttys + 40 * v1;
if ( *((_DWORD *)v2 + 7) == a1 )
{
if ( logout(*(const char **)v2) )
logwtmp(*(const char **)v2, &buf, &buf);
v3 = *((_DWORD *)v2 + 6);
*((_DWORD *)v2 + 7) = 0;
if ( v3 )
break;
}
if ( nttys <= (int)++v1 )
return;
}
++v1;
startup_terminal((__int64)v2);
}
while ( nttys > (int)v1 );
}
}

canonical_decompiled_code:
void __fastcall func13(int a1)
{
__int64 v1; // rbx
char *v2; // rbp
int v3; // eax

if ( nttys > 0 )
{
v1 = 0LL;
do
{
while ( 1 )
{
v2 = (char *)ttys + 40 * v1;
if ( *((_DWORD *)v2 + 7) == a1 )
{
if ( logout(*(const char **)v2) )
logwtmp(*(const char **)v2, &buf, &buf);
v3 = *((_DWORD *)v2 + 6);
*((_DWORD *)v2 + 7) = 0;
if ( v3 )
break;
}
if ( nttys <= (int)++v1 )
return;
}
++v1;
func7((__int64)v2);
}
while ( nttys > (int)v1 );
}
}

original_code:
void
restart_terminal (pid_t pid)
{
  int i;
  for (i = 0; i < nttys; i++)
    if (pid == ttys[i].pid)
      {
 if (logout (ttys[i].name))
   logwtmp (ttys[i].name, "", "");
 ttys[i].pid = 0;
 if (ttys[i].on)
   startup_terminal (&ttys[i]);
      }
}

canonical_original_code:
void restart_terminal(int pid)
{
  int i;
  for (i = 0; i < nttys; i++)
    if (pid == ttys[i].pid)
      {
 if (logout (ttys[i].name))
   logwtmp (ttys[i].name, "", "");
 ttys[i].pid = 0;
 if (ttys[i].on)
   startup_terminal (&ttys[i]);
      }
}


decompiled_code:
void reread_ttys()
{
struct ttyent *v0; // rbp
const char **v1; // rax
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
char **v6; // rbx
_DWORD *v7; // rbx
char *v8; // rbp
char *v9; // r12
char **v10; // rax
int *v11; // rax
char v12; // [rsp+0h] [rbp-18h]

if ( setttyent() )
{
LABEL_2:
while ( 1 )
{
v0 = getttyent();
if ( !v0 )
break;
while ( v0->ty_name )
{
v1 = find_line(v0->ty_name);
v6 = (char **)v1;
if ( v0->ty_getty && (v0->ty_status & 1) != 0 )
{
if ( v1 )
{
if ( !*((_DWORD *)v1 + 6) )
{
*((_DWORD *)v1 + 6) = 1;
setup_terminal((__int64)v1, (__int64)v0, v2, v3, v4, v5, v12);
startup_terminal((__int64)v6);
}
}
else
{
v10 = add_terminal((const char **)&v0->ty_name);
v6 = v10;
if ( !v10 )
goto LABEL_2;
startup_terminal((__int64)v10);
}
}
else if ( v1 )
{
if ( *((_DWORD *)v1 + 6) )
{
*((_DWORD *)v1 + 6) = 0;
shutdown_terminal_constprop_0((__int64)v1);
}
}
else
{
v6 = add_terminal((const char **)&v0->ty_name);
if ( !v6 )
goto LABEL_2;
}
*((_DWORD *)v6 + 8) = 1;
v0 = getttyent();
if ( !v0 )
goto LABEL_10;
}
}
LABEL_10:
endttyent();
if ( nttys > 0 )
{
v7 = ttys;
v8 = (char *)ttys + 40;
v9 = (char *)ttys + 40 * (unsigned int)(nttys - 1) + 40;
while ( 1 )
{
if ( v7[8] || !v7[6] )
{
v7[8] = 0;
v7 = v8;
if ( v9 == v8 )
return;
}
else
{
v7[6] = 0;
shutdown_terminal_constprop_0((__int64)v7);
v7[8] = 0;
v7 = v8;
if ( v9 == v8 )
return;
}
v8 += 40;
}
}
}
else
{
v11 = _errno_location();
error(0, *v11, "%s", "/etc/ttys");
}
}

original_code:
void
reread_ttys (void)
{
  struct ttyent *tt;
  struct terminal *t;
  int on;
  int i;
  if (!setttyent ())
    {
      error (0, (*__errno_location ()), "%s", "/etc/ttys");
      return;
    }
  while ((tt = getttyent ()))
    {
      if (!tt->ty_name)
 continue;
      t = find_line (tt->ty_name);
      on = tt->ty_getty && (tt->ty_status & 0x01);
      if (t)
 {
   if (t->on && !on)
     {
       t->on = 0;
       shutdown_terminal (t);
     }
   else if (!t->on && on)
     {
       t->on = 1;
       setup_terminal (t, tt);
       startup_terminal (t);
     }
 }
      else
 {
   t = add_terminal (tt);
   if (t == 0)
     continue;
   if (on)
     startup_terminal (t);
 }
      t->read = 1;
    }
  endttyent ();
  for (i = 0; i < nttys; i++)
    {
      if (!ttys[i].read && ttys[i].on)
 {
   ttys[i].on = 0;
   shutdown_terminal (&ttys[i]);
 }
      ttys[i].read = 0;
    }
}

canonical_original_code:
void reread_ttys()
{
  struct ttyent *tt;
  struct terminal *t;
  int on;
  int i;
  if (!setttyent ())
    {
      error (0, (*__errno_location ()), "%s", "/etc/ttys");
      return;
    }
  while ((tt = getttyent ()))
    {
      if (!tt->ty_name)
 continue;
      t = find_line (tt->ty_name);
      on = tt->ty_getty && (tt->ty_status & 0x01);
      if (t)
 {
   if (t->on && !on)
     {
       t->on = 0;
       shutdown_terminal (t);
     }
   else if (!t->on && on)
     {
       t->on = 1;
       setup_terminal (t, tt);
       startup_terminal (t);
     }
 }
      else
 {
   t = add_terminal (tt);
   if (t == 0)
     continue;
   if (on)
     startup_terminal (t);
 }
      t->read = 1;
    }
  endttyent ();
  for (i = 0; i < nttys; i++)
    {
      if (!ttys[i].read && ttys[i].on)
 {
   ttys[i].on = 0;
   shutdown_terminal (&ttys[i]);
 }
      ttys[i].read = 0;
    }
}

variable_types: on int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__pid_t v4; // ebp
int *v5; // rax
int *v6; // rbx
__pid_t v7; // eax
int v8; // er12
int v9; // ebp
struct sigaction v10; // [rsp+0h] [rbp-B8h] BYREF

result = init_ttys(argc, argv, envp);
if ( !result )
{
v4 = setsid();
v5 = _errno_location();
v6 = v5;
if ( v4 == -1 )
error(0, *v5, "setsid");
v10.sa_handler = (__sighandler_t)sighup;
v10.sa_flags = 0;
sigemptyset(&v10.sa_mask);
if ( sigaction(1, &v10, 0LL) )
{
error(2, *v6, "cannot set SIGHUP handler");
}
else
{
v10.sa_handler = (__sighandler_t)sigterm;
if ( !sigaction(15, &v10, 0LL) )
{
startup_ttys();
while ( 1 )
{
v7 = waitpid(-1, 0LL, 2);
v8 = *v6;
v9 = v7;
write(2, &buf, 0LL);
if ( pending_term )
{
pending_term = 0;
error(3, 0, "Got SIGTERM");
LABEL_16:
_assert_fail("pid > 0", "runttys.c", 0x1F1u, "main");
}
if ( pending_hup )
{
LABEL_14:
pending_hup = 0;
reread_ttys();
}
if ( v9 < 0 )
{
if ( v8 != 4 )
{
error(1, v8, "waitpid");
goto LABEL_14;
}
}
else
{
if ( !v9 )
goto LABEL_16;
restart_terminal(v9);
}
}
}
}
error(2, *v6, "cannot set SIGTERM handler");
JUMPOUT(0xB12LL);
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
__pid_t v4; // ebp
int *v5; // rax
int *v6; // rbx
__pid_t v7; // eax
int v8; // er12
int v9; // ebp
struct sigaction v10; // [rsp+0h] [rbp-B8h] BYREF

result = func10(argc, argv, envp);
if ( !result )
{
v4 = setsid();
v5 = _errno_location();
v6 = v5;
if ( v4 == -1 )
error(0, *v5, "setsid");
v10.sa_handler = (__sighandler_t)sighup;
v10.sa_flags = 0;
sigemptyset(&v10.sa_mask);
if ( sigaction(1, &v10, 0LL) )
{
error(2, *v6, "cannot set SIGHUP handler");
}
else
{
v10.sa_handler = (__sighandler_t)sigterm;
if ( !sigaction(15, &v10, 0LL) )
{
func12();
while ( 1 )
{
v7 = waitpid(-1, 0LL, 2);
v8 = *v6;
v9 = v7;
write(2, &buf, 0LL);
if ( pending_term )
{
pending_term = 0;
error(3, 0, "Got SIGTERM");
LABEL_16:
_assert_fail("pid > 0", "runttys.c", 0x1F1u, "main");
}
if ( pending_hup )
{
LABEL_14:
pending_hup = 0;
func14();
}
if ( v9 < 0 )
{
if ( v8 != 4 )
{
error(1, v8, "waitpid");
goto LABEL_14;
}
}
else
{
if ( !v9 )
goto LABEL_16;
func13(v9);
}
}
}
}
error(2, *v6, "cannot set SIGTERM handler");
JUMPOUT(0xB12LL);
}
return result;
}

original_code:
int
main ()
{
  int fail;
  struct sigaction sa;
  fail = init_ttys ();
  if (fail)
    return fail;
  if (setsid () == -1)
    error (0, (*__errno_location ()), "setsid");
  sa.__sigaction_handler.sa_handler = sighup;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  if (sigaction (1, &sa, ((void *)0)))
    error (2, (*__errno_location ()), "cannot set SIGHUP handler");
  sa.__sigaction_handler.sa_handler = sigterm;
  if (sigaction (15, &sa, ((void *)0)))
    error (2, (*__errno_location ()), "cannot set SIGTERM handler");
  startup_ttys ();
  while (1)
    {
      error_t waiterr;
      pid_t pid = waitpid ((-1), ((void *)0), 2);
      waiterr = (*__errno_location ());
      write (2, "", 0);
      if (pending_term)
 {
   pending_term = 0;
   error (3, 0, "Got SIGTERM");
 }
      if (pending_hup)
 {
   pending_hup = 0;
   reread_ttys ();
 }
      if (pid < 0)
 {
   if (waiterr == 4)
     continue;
   error (1, waiterr, "waitpid");
 }
      ((void) sizeof ((pid > 0) ? 1 : 0), __extension__ ({ if (pid > 0) ; else __assert_fail ("pid > 0", "runttys.c", 497, __extension__ __PRETTY_FUNCTION__); }));
      restart_terminal (pid);
    }
}

canonical_original_code:
int main()
{
  int fail;
  struct sigaction sa;
  fail = init_ttys ();
  if (fail)
    return fail;
  if (setsid () == -1)
    error (0, (*__errno_location ()), "setsid");
  sa.__sigaction_handler.sa_handler = sighup;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  if (sigaction (1, &sa, ((void *)0)))
    error (2, (*__errno_location ()), "cannot set SIGHUP handler");
  sa.__sigaction_handler.sa_handler = sigterm;
  if (sigaction (15, &sa, ((void *)0)))
    error (2, (*__errno_location ()), "cannot set SIGTERM handler");
  startup_ttys ();
  while (1)
    {
      int waiterr;
      int pid = waitpid ((-1), ((void *)0), 2);
      waiterr = (*__errno_location ());
      write (2, "", 0);
      if (pending_term)
 {
   pending_term = 0;
   error (3, 0, "Got SIGTERM");
 }
      if (pending_hup)
 {
   pending_hup = 0;
   reread_ttys ();
 }
      if (pid < 0)
 {
   if (waiterr == 4)
     continue;
   error (1, waiterr, "waitpid");
 }
      ((void) sizeof ((pid > 0) ? 1 : 0), __extension__ ({ if (pid > 0) ; else __assert_fail ("pid > 0", "runttys.c", 497, __extension__ __PRETTY_FUNCTION__); }));
      restart_terminal (pid);
    }
}

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

variable_types: waiterr int

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

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


decompiled_code:
__int64 __fastcall int_len(unsigned int a1)
{
unsigned int v1; // er8
unsigned int v2; // eax

v1 = 1;
if ( a1 > 9 )
{
do
{
++v1;
v2 = a1;
a1 /= 0xAu;
}
while ( v2 > 0x63 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
unsigned int v1; // er8
unsigned int v2; // eax

v1 = 1;
if ( a1 > 9 )
{
do
{
++v1;
v2 = a1;
a1 /= 0xAu;
}
while ( v2 > 0x63 );
}
return v1;
}

original_code:
static unsigned
int_len (unsigned n)
{
  unsigned len = 1;
  while (n >= 10)
    {
      n /= 10;
      len++;
    }
  return len;
}

canonical_original_code:
static unsigned int int_len(unsigned int n)
{
  unsigned int len = 1;
  while (n >= 10)
    {
      n /= 10;
      len++;
    }
  return len;
}

variable_types:
n
unsigned int

variable_types:
len
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall tv_div(__int64 *a1, __int64 *a2)
{
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // r8

v2 = *a1;
if ( *a2 )
return v2 / *a2;
v4 = a2[1];
result = a1[1] / v4;
if ( v2 )
result = (unsigned int)result + (unsigned int)(1000000 * v2 / v4);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 *a1, __int64 *a2)
{
__int64 v2; // rcx
__int64 result; // rax
__int64 v4; // r8

v2 = *a1;
if ( *a2 )
return v2 / *a2;
v4 = a2[1];
result = a1[1] / v4;
if ( v2 )
result = (unsigned int)result + (unsigned int)(1000000 * v2 / v4);
return result;
}

original_code:
static unsigned
tv_div (struct timeval *tv1, struct timeval *tv2)
{
  return
    tv2->tv_sec
      ? tv1->tv_sec / tv2->tv_sec
 : (tv1->tv_usec / tv2->tv_usec
    + (tv1->tv_sec ? tv1->tv_sec * 1000000 / tv2->tv_usec : 0));
}

canonical_original_code:
static unsigned int tv_div(struct timeval *tv1, struct timeval *tv2)
{
  return
    tv2->tv_sec
      ? tv1->tv_sec / tv2->tv_sec
 : (tv1->tv_usec / tv2->tv_usec
    + (tv1->tv_sec ? tv1->tv_sec * 1000000 / tv2->tv_usec : 0));
}

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


decompiled_code:
_BOOL8 __fastcall tv_is_zero(_QWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( !*a1 )
result = a1[1] == 0LL;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_QWORD *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( !*a1 )
result = a1[1] == 0LL;
return result;
}

original_code:
static inline int
tv_is_zero (struct timeval *tv)
{
  return tv->tv_sec == 0 && tv->tv_usec == 0;
}

canonical_original_code:
static inline int tv_is_zero(struct timeval *tv)
{
  return tv->tv_sec == 0 && tv->tv_usec == 0;
}

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


decompiled_code:
_BOOL8 __fastcall tv_is_ge(_QWORD *a1, _QWORD *a2)
{
_BOOL8 result; // rax

result = 1LL;
if ( *a1 <= *a2 )
{
result = 0LL;
if ( *a1 == *a2 )
result = a1[1] >= a2[1];
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_QWORD *a1, _QWORD *a2)
{
_BOOL8 result; // rax

result = 1LL;
if ( *a1 <= *a2 )
{
result = 0LL;
if ( *a1 == *a2 )
result = a1[1] >= a2[1];
}
return result;
}

original_code:
static inline int
tv_is_ge (struct timeval *tv1, struct timeval *tv2)
{
  return
    tv1->tv_sec > tv2->tv_sec
      || (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec >= tv2->tv_usec);
}

canonical_original_code:
static inline int tv_is_ge(struct timeval *tv1, struct timeval *tv2)
{
  return
    tv1->tv_sec > tv2->tv_sec
      || (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec >= tv2->tv_usec);
}


decompiled_code:
__int64 __fastcall add_field(_DWORD *a1, int a2, _DWORD *a3, unsigned __int64 a4, __int64 a5, unsigned __int64 a6, char *s)
{
unsigned int v7; // eax
const char *v8; // rsi

v7 = *a1 / a2;
if ( !v7 && (a6 < a4 || !*a3) )
return 0LL;
*a1 %= a2;
*a3 = 1;
v8 = "%d%s";
if ( a6 != a4 )
{
v8 = "%2d%s";
if ( a4 + 1 != a6 )
v8 = "%02d%s";
}
return sprintf(s, v8, v7, a5);
}

canonical_decompiled_code:
__int64 __fastcall func4(_DWORD *a1, int a2, _DWORD *a3, unsigned __int64 a4, __int64 a5, unsigned __int64 a6, char *s)
{
unsigned int v7; // eax
const char *v8; // rsi

v7 = *a1 / a2;
if ( !v7 && (a6 < a4 || !*a3) )
return 0LL;
*a1 %= a2;
*a3 = 1;
v8 = "%d%s";
if ( a6 != a4 )
{
v8 = "%2d%s";
if ( a4 + 1 != a6 )
v8 = "%02d%s";
}
return sprintf(s, v8, v7, a5);
}

original_code:
static size_t
add_field (int *secs, int unit, int *leading_zeros,
    size_t min_width, char *suffix,
    size_t width, char *buf)
{
  int units = *secs / unit;
  if (units || (width >= min_width && *leading_zeros))
    {
      *secs -= units * unit;
      *leading_zeros = 1;
      return
 sprintf (buf,
    (width == min_width ? "%d%s"
     : width == min_width + 1 ? "%2d%s"
     : "%02d%s"),
    units, suffix);
    }
  else
    return 0;
}

canonical_original_code:
static unsigned long add_field(int *secs, int unit, int *leading_zeros, unsigned long min_width, char *suffix, unsigned long width, char *buf)
{
  int units = *secs / unit;
  if (units || (width >= min_width && *leading_zeros))
    {
      *secs -= units * unit;
      *leading_zeros = 1;
      return
 sprintf (buf,
    (width == min_width ? "%d%s"
     : width == min_width + 1 ? "%2d%s"
     : "%02d%s"),
    units, suffix);
    }
  else
    return 0;
}

variable_types:
secs
int *

variable_types: unit int

variable_types:
suffix
char *

variable_types:
width
unsigned long

variable_types:
buf
char *

variable_types: units int

return_type: unsigned long


original_code:
size_t
fmt_seconds (struct timeval *tv, int leading_zeros, int frac_places,
      size_t width, char *buf, size_t buf_len)
{
  char *p = buf;
  int secs = tv->tv_sec;
  if (width <= 0 || width >= buf_len)
    width = buf_len - 1;
  if (tv->tv_sec > (24*(60*60)))
    return fmt_named_interval (tv, width, buf, buf_len);
  if (frac_places > 0)
    width -= frac_places + 1;
  if ((secs > 10*(60*60) && width < 8)
      || (secs > (60*60) && width < 7)
      || (secs > 10*60 && width < 5)
      || (secs > 60 && width < 4)
      || (secs > 10 && width < 2)
      || width < 1)
    return fmt_named_interval (tv, width, buf, buf_len);
  p += add_field (&secs, (60*60), &leading_zeros, 7, ":", width, p);
  p += add_field (&secs, 60, &leading_zeros, 4, ":", width, p);
  p += add_field (&secs, 1, &leading_zeros, 1, "", width, p);
  if (frac_places < 0 && (p - buf) < width - 2)
    frac_places = width - (p - buf) - 1;
  if (frac_places > 0)
    {
      int frac = tv->tv_usec, i;
      for (i = 6; i > frac_places; i--)
 frac /= 10;
      return (p - buf) + sprintf (p, ".%0*d", frac_places, frac);
    }
  else
    return (p - buf);
}

canonical_original_code:
unsigned long fmt_seconds(struct timeval *tv, int leading_zeros, int frac_places, unsigned long width, char *buf, unsigned long buf_len)
{
  char *p = buf;
  int secs = tv->tv_sec;
  if (width <= 0 || width >= buf_len)
    width = buf_len - 1;
  if (tv->tv_sec > (24*(60*60)))
    return fmt_named_interval (tv, width, buf, buf_len);
  if (frac_places > 0)
    width -= frac_places + 1;
  if ((secs > 10*(60*60) && width < 8)
      || (secs > (60*60) && width < 7)
      || (secs > 10*60 && width < 5)
      || (secs > 60 && width < 4)
      || (secs > 10 && width < 2)
      || width < 1)
    return fmt_named_interval (tv, width, buf, buf_len);
  p += add_field (&secs, (60*60), &leading_zeros, 7, ":", width, p);
  p += add_field (&secs, 60, &leading_zeros, 4, ":", width, p);
  p += add_field (&secs, 1, &leading_zeros, 1, "", width, p);
  if (frac_places < 0 && (p - buf) < width - 2)
    frac_places = width - (p - buf) - 1;
  if (frac_places > 0)
    {
      int frac = tv->tv_usec; int i;
      for (i = 6; i > frac_places; i--)
 frac /= 10;
      return (p - buf) + sprintf (p, ".%0*d", frac_places, frac);
    }
  else
    return (p - buf);
}

variable_types:
p
char *

variable_types: secs int

variable_types: frac int


original_code:
size_t
fmt_minutes (struct timeval *tv, int leading_zeros,
      size_t width, char *buf, size_t buf_len)
{
  char *p = buf;
  int secs = tv->tv_sec;
  if (width <= 0 || width >= buf_len)
    width = buf_len - 1;
  if (secs > (24*(60*60)))
    return fmt_named_interval (tv, width, buf, buf_len);
  if ((secs > 10*(60*60) && width < 5)
      || (secs > (60*60) && width < 4)
      || (secs > 10*60 && width < 2)
      || width < 1)
    return fmt_named_interval (tv, width, buf, buf_len);
  p += add_field (&secs, (60*60), &leading_zeros, 4, ":", width, p);
  p += add_field (&secs, 60, &leading_zeros, 1, "", width, p);
  return p - buf;
}

canonical_original_code:
unsigned long fmt_minutes(struct timeval *tv, int leading_zeros, unsigned long width, char *buf, unsigned long buf_len)
{
  char *p = buf;
  int secs = tv->tv_sec;
  if (width <= 0 || width >= buf_len)
    width = buf_len - 1;
  if (secs > (24*(60*60)))
    return fmt_named_interval (tv, width, buf, buf_len);
  if ((secs > 10*(60*60) && width < 5)
      || (secs > (60*60) && width < 4)
      || (secs > 10*60 && width < 2)
      || width < 1)
    return fmt_named_interval (tv, width, buf, buf_len);
  p += add_field (&secs, (60*60), &leading_zeros, 4, ":", width, p);
  p += add_field (&secs, 60, &leading_zeros, 1, "", width, p);
  return p - buf;
}


original_code:
size_t
fmt_past_time (struct timeval *tv, struct timeval *now,
        size_t width, char *buf, size_t buf_len)
{
  static char *time_fmts[] = { "%-r", "%-l:%M%p", "%-l%p", 0 };
  static char *week_fmts[] = { "%A", "%a", 0 };
  static char *month_fmts[] = { "%A %-d", "%a %-d", "%a%-d", 0 };
  static char *date_fmts[] =
    { "%A, %-d %B", "%a, %-d %b", "%-d %B", "%-d %b", "%-d%b", 0 };
  static char *year_fmts[] =
    { "%A, %-d %B %Y", "%a, %-d %b %Y", "%a, %-d %b %y", "%-d %b %y", "%-d%b%y", 0 };
  struct tm tm;
  int used = 0;
  long diff = now ? (now->tv_sec - tv->tv_sec) : tv->tv_sec;
  if (diff < 0)
    diff = -diff;
  bcopy (localtime ((time_t *) &tv->tv_sec), &tm, sizeof tm);
  if (width <= 0 || width >= buf_len)
    width = buf_len - 1;
  if (diff < (24*(60*60)))
    {
      char **fmt;
      for (fmt = time_fmts; *fmt && !used; fmt++)
 used = strftime (buf, width + 1, *fmt, &tm);
      if (! used)
 used = strftime (buf, buf_len, fmt[-1], &tm);
    }
  else
    {
      static char *seps[] = { ", ", " ", "", 0 };
      char **fmt, **dfmt, **dfmts, **sep;
      if (diff < (7*(24*(60*60))))
 dfmts = week_fmts;
      else if (diff < (31*(24*(60*60))))
 dfmts = month_fmts;
      else if (diff < (365*(24*(60*60))))
 dfmts = date_fmts;
      else
 dfmts = year_fmts;
      for (fmt = time_fmts; *fmt && !used; fmt++)
 for (sep = seps; *sep && !used; sep++)
   for (dfmt = dfmts; *dfmt && !used; dfmt++)
     {
       char whole_fmt[strlen (*dfmt) + strlen (*sep) + strlen (*fmt) + 1];
       char *end = whole_fmt;
       end = stpcpy (end, *dfmt);
       end = stpcpy (end, *sep);
       end = stpcpy (end, *fmt);
       used = strftime (buf, width + 1, whole_fmt, &tm);
     }
      if (! used)
 for (dfmt = dfmts; *dfmt && !used; dfmt++)
   used = strftime (buf, width + 1, *dfmt, &tm);
      if (! used)
 used = strftime (buf, buf_len, dfmt[-1], &tm);
    }
  return used;
}

canonical_original_code:
unsigned long fmt_past_time(struct timeval *tv, struct timeval *now, unsigned long width, char *buf, unsigned long buf_len)
{
  static char *time_fmts[] = { "%-r", "%-l:%M%p", "%-l%p", 0 };
  static char *week_fmts[] = { "%A", "%a", 0 };
  static char *month_fmts[] = { "%A %-d", "%a %-d", "%a%-d", 0 };
  static char *date_fmts[] = { "%A, %-d %B", "%a, %-d %b", "%-d %B", "%-d %b", "%-d%b", 0 };
  static char *year_fmts[] = { "%A, %-d %B %Y", "%a, %-d %b %Y", "%a, %-d %b %y", "%-d %b %y", "%-d%b%y", 0 };
  struct tm tm;
  int used = 0;
  long diff = now ? (now->tv_sec - tv->tv_sec) : tv->tv_sec;
  if (diff < 0)
    diff = -diff;
  bcopy (localtime ((long *) &tv->tv_sec), &tm, sizeof tm);
  if (width <= 0 || width >= buf_len)
    width = buf_len - 1;
  if (diff < (24*(60*60)))
    {
      char **fmt;
      for (fmt = time_fmts; *fmt && !used; fmt++)
 used = strftime (buf, width + 1, *fmt, &tm);
      if (! used)
 used = strftime (buf, buf_len, fmt[-1], &tm);
    }
  else
    {
      static char *seps[] = { ", ", " ", "", 0 };
      char **fmt; char **dfmt; char **dfmts; char **sep;
      if (diff < (7*(24*(60*60))))
 dfmts = week_fmts;
      else if (diff < (31*(24*(60*60))))
 dfmts = month_fmts;
      else if (diff < (365*(24*(60*60))))
 dfmts = date_fmts;
      else
 dfmts = year_fmts;
      for (fmt = time_fmts; *fmt && !used; fmt++)
 for (sep = seps; *sep && !used; sep++)
   for (dfmt = dfmts; *dfmt && !used; dfmt++)
     {
       char whole_fmt[-1];
       char *end = whole_fmt;
       end = stpcpy (end, *dfmt);
       end = stpcpy (end, *sep);
       end = stpcpy (end, *fmt);
       used = strftime (buf, width + 1, whole_fmt, &tm);
     }
      if (! used)
 for (dfmt = dfmts; *dfmt && !used; dfmt++)
   used = strftime (buf, width + 1, *dfmt, &tm);
      if (! used)
 used = strftime (buf, buf_len, dfmt[-1], &tm);
    }
  return used;
}

variable_types:
now
struct timeval *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }

variable_types: used int

variable_types: diff long

variable_types:
fmt
char **

variable_types:
seps
char *[]

variable_types:
dfmt
char **

variable_types:
dfmts
char **

variable_types:
sep
char **

variable_types:
end
char *


decompiled_code:
char *__fastcall timespec_rep(time_t *a1)
{
time_t v2; // r8
char *v3; // rax
char *v4; // rax
char *v5; // rdi
time_t v6; // rcx
char *v7; // rsi
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( *a1 || (v2 = a1[1]) != 0 )
{
timer = *a1;
v3 = ctime(&timer);
v4 = stpcpy(buf_3, v3);
v5 = v4 + 1;
if ( *(v4 - 1) == 10 )
v5 = v4--;
*v4 = 32;
v2 = a1[1];
v6 = *a1;
v7 = (char *)(&unk_5C8 - (_UNKNOWN *)v5);
}
else
{
v6 = 0LL;
v7 = (_BYTE *)(&loc_C4 + 4);
v5 = buf_3;
}
snprintf(v5, (size_t)v7, "[%ld, %ld]", v6, v2);
return buf_3;
}

canonical_decompiled_code:
char *__fastcall func2(time_t *a1)
{
time_t v2; // r8
char *v3; // rax
char *v4; // rax
char *v5; // rdi
time_t v6; // rcx
char *v7; // rsi
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( *a1 || (v2 = a1[1]) != 0 )
{
timer = *a1;
v3 = ctime(&timer);
v4 = stpcpy(buf_3, v3);
v5 = v4 + 1;
if ( *(v4 - 1) == 10 )
v5 = v4--;
*v4 = 32;
v2 = a1[1];
v6 = *a1;
v7 = (char *)(&unk_5C8 - (_UNKNOWN *)v5);
}
else
{
v6 = 0LL;
v7 = (_BYTE *)(&loc_C4 + 4);
v5 = buf_3;
}
snprintf(v5, (size_t)v7, "[%ld, %ld]", v6, v2);
return buf_3;
}

original_code:
static char *
timespec_rep (struct timespec *ts)
{
  static char buf[200];
  char *p = buf;
  if (ts->tv_sec || ts->tv_nsec)
    {
      time_t time = ts->tv_sec;
      strcpy (buf, ctime (&time));
      p += strlen (buf);
      if (p[-1] == '\n')
 p--;
      *p++ = ' ';
    }
  snprintf (p, buf + sizeof buf - p, "[%ld, %ld]", ts->tv_sec, ts->tv_nsec);
  return buf;
}

canonical_original_code:
static char *timespec_rep(struct timespec *ts)
{
  static char buf[200];
  char *p = buf;
  if (ts->tv_sec || ts->tv_nsec)
    {
      long time = ts->tv_sec;
      strcpy (buf, ctime (&time));
      p += strlen (buf);
      if (p[-1] == '\n')
 p--;
      *p++ = ' ';
    }
  snprintf (p, buf + sizeof buf - p, "[%ld, %ld]", ts->tv_sec, ts->tv_nsec);
  return buf;
}

variable_types: struct timespec { long tv_sec; long tv_nsec; } *

variable_types:
buf
char [200]

variable_types: time long

return_type: char *


decompiled_code:
char *__fastcall uid_rep(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( v1 )
snprintf(buf_2, 0xC8uLL, "%d(%s)", a1, v1->pw_name);
else
snprintf(buf_2, 0xC8uLL, "%d", a1);
return buf_2;
}

canonical_decompiled_code:
char *__fastcall func3(__uid_t a1)
{
struct passwd *v1; // rax

v1 = getpwuid(a1);
if ( v1 )
snprintf(buf_2, 0xC8uLL, "%d(%s)", a1, v1->pw_name);
else
snprintf(buf_2, 0xC8uLL, "%d", a1);
return buf_2;
}

original_code:
static char *
uid_rep (uid_t uid)
{
  static char buf[200];
  struct passwd *pw = getpwuid (uid);
  if (pw)
    snprintf (buf, sizeof buf, "%d(%s)", uid, pw->pw_name);
  else
    snprintf (buf, sizeof buf, "%d", uid);
  return buf;
}

canonical_original_code:
static char *uid_rep(unsigned int uid)
{
  static char buf[200];
  struct passwd *pw = getpwuid (uid);
  if (pw)
    snprintf (buf, sizeof buf, "%d(%s)", uid, pw->pw_name);
  else
    snprintf (buf, sizeof buf, "%d", uid);
  return buf;
}

variable_types:
uid
unsigned int

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


decompiled_code:
char *__fastcall gid_rep(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( v1 )
snprintf(buf_1, 0xC8uLL, "%d(%s)", a1, v1->gr_name);
else
snprintf(buf_1, 0xC8uLL, "%d", a1);
return buf_1;
}

canonical_decompiled_code:
char *__fastcall func4(__gid_t a1)
{
struct group *v1; // rax

v1 = getgrgid(a1);
if ( v1 )
snprintf(buf_1, 0xC8uLL, "%d(%s)", a1, v1->gr_name);
else
snprintf(buf_1, 0xC8uLL, "%d", a1);
return buf_1;
}

original_code:
static char *
gid_rep (gid_t gid)
{
  static char buf[200];
  struct group *gr = getgrgid (gid);
  if (gr)
    snprintf (buf, sizeof buf, "%d(%s)", gid, gr->gr_name);
  else
    snprintf (buf, sizeof buf, "%d", gid);
  return buf;
}

canonical_original_code:
static char *gid_rep(unsigned int gid)
{
  static char buf[200];
  struct group *gr = getgrgid (gid);
  if (gr)
    snprintf (buf, sizeof buf, "%d(%s)", gid, gr->gr_name);
  else
    snprintf (buf, sizeof buf, "%d", gid);
  return buf;
}

variable_types:
gid
unsigned int

variable_types: struct group { char *gr_name; char *gr_passwd; unsigned int gr_gid; char **gr_mem; } *


decompiled_code:
__int64 dynacolor_init()
{
vga_exchange_palette_attributes(0LL, &saved_palette_attr, 16LL);
vga_read_palette(0LL, &saved_palette, 16LL);
return vga_write_palette(0LL, &std_palette, 16LL);
}

canonical_decompiled_code:
__int64 func0()
{
vga_exchange_palette_attributes(0LL, &saved_palette_attr, 16LL);
vga_read_palette(0LL, &saved_palette, 16LL);
return vga_write_palette(0LL, &std_palette, 16LL);
}

original_code:
void
dynacolor_init (void)
{
  vga_exchange_palette_attributes (0, saved_palette_attr, 16);
  vga_read_palette (0, saved_palette[0], 16);
  vga_write_palette (0, std_palette[0], 16);
}

canonical_original_code:
void dynacolor_init()
{
  vga_exchange_palette_attributes (0, saved_palette_attr, 16);
  vga_read_palette (0, saved_palette[0], 16);
  vga_write_palette (0, std_palette[0], 16);
}


decompiled_code:
__int64 dynacolor_fini()
{
vga_write_palette(0LL, &saved_palette, 16LL);
return vga_exchange_palette_attributes(0LL, &saved_palette_attr, 16LL);
}

canonical_decompiled_code:
__int64 func1()
{
vga_write_palette(0LL, &saved_palette, 16LL);
return vga_exchange_palette_attributes(0LL, &saved_palette_attr, 16LL);
}

original_code:
void
dynacolor_fini (void)
{
  vga_write_palette (0, saved_palette[0], 16);
  vga_exchange_palette_attributes (0, saved_palette_attr, 16);
}

canonical_original_code:
void dynacolor_fini()
{
  vga_write_palette (0, saved_palette[0], 16);
  vga_exchange_palette_attributes (0, saved_palette_attr, 16);
}


decompiled_code:
__int64 __fastcall dynacolor_activate(int *a1)
{
__int64 result; // rax
char *v2; // rbx
char *v3; // rbp

result = active_dynacolor;
if ( (int *)active_dynacolor != a1 )
{
if ( *a1 < 0 )
{
if ( !active_dynacolor || *(int *)active_dynacolor >= 0 )
result = vga_write_palette(0LL, &std_palette, 16LL);
}
else if ( !active_dynacolor || (result = *(unsigned int *)active_dynacolor, (int)result < 0) )
{
v2 = (char *)&std_palette;
v3 = (char *)(a1 + 8);
do
{
if ( *v3 >= 0 )
{
vga_write_palette((unsigned int)*v3, v2, 1LL);
result = vga_write_palette((unsigned __int8)(*v3 + 8), v2, 1LL);
}
v2 += 3;
++v3;
}
while ( (char *)&std_palette + 48 != v2 );
}
active_dynacolor = (__int64)a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int *a1)
{
__int64 result; // rax
char *v2; // rbx
char *v3; // rbp

result = active_dynacolor;
if ( (int *)active_dynacolor != a1 )
{
if ( *a1 < 0 )
{
if ( !active_dynacolor || *(int *)active_dynacolor >= 0 )
result = vga_write_palette(0LL, &std_palette, 16LL);
}
else if ( !active_dynacolor || (result = *(unsigned int *)active_dynacolor, (int)result < 0) )
{
v2 = (char *)&std_palette;
v3 = (char *)(a1 + 8);
do
{
if ( *v3 >= 0 )
{
vga_write_palette((unsigned int)*v3, v2, 1LL);
result = vga_write_palette((unsigned __int8)(*v3 + 8), v2, 1LL);
}
v2 += 3;
++v3;
}
while ( (char *)&std_palette + 48 != v2 );
}
active_dynacolor = (__int64)a1;
}
return result;
}

original_code:
void
dynacolor_activate (dynacolor_t *dc)
{
  if (dc == active_dynacolor)
    return;
  if (dc->ref[0] < 0 && (!active_dynacolor || active_dynacolor->ref[0] >= 0))
    {
      vga_write_palette (0, std_palette[0], 16);
    }
  else if (dc->ref[0] >= 0
    && (!active_dynacolor || active_dynacolor->ref[0] < 0))
    {
      int i;
      for (i = 0; i < 16; i++)
 if (dc->col[i] >= 0)
   {
     vga_write_palette (dc->col[i], std_palette[i], 1);
     vga_write_palette (8 + dc->col[i], std_palette[i], 1);
   }
    }
  active_dynacolor = dc;
}

canonical_original_code:
void dynacolor_activate(struct dynacolor *dc)
{
  if (dc == active_dynacolor)
    return;
  if (dc->ref[0] < 0 && (!active_dynacolor || active_dynacolor->ref[0] >= 0))
    {
      vga_write_palette (0, std_palette[0], 16);
    }
  else if (dc->ref[0] >= 0
    && (!active_dynacolor || active_dynacolor->ref[0] < 0))
    {
      int i;
      for (i = 0; i < 16; i++)
 if (dc->col[i] >= 0)
   {
     vga_write_palette (dc->col[i], std_palette[i], 1);
     vga_write_palette (8 + dc->col[i], std_palette[i], 1);
   }
    }
  active_dynacolor = dc;
}

variable_types: struct dynacolor { int ref[8]; char col[16]; } *

variable_types: i int


decompiled_code:
__int64 __fastcall dynacolor_allocate(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rax
bool v5; // zf

v2 = 0LL;
while ( *(_DWORD *)(a1 + 4 * v2) )
{
if ( ++v2 == 8 )
return 0xFFFFFFFFLL;
}
v4 = 0LL;
while ( *(char *)(a1 + v4 + 32) != (_DWORD)v2 )
{
if ( ++v4 == 16 )
goto LABEL_9;
}
*(_BYTE *)(a1 + (int)v4 + 32) = -1;
LABEL_9:
v5 = active_dynacolor == a1;
*(_DWORD *)(a1 + 4LL * (int)v2) = 1;
result = (unsigned int)v2;
*(_BYTE *)(a1 + a2 + 32) = v2;
if ( v5 )
{
vga_write_palette((unsigned int)v2, (char *)&std_palette + 3 * a2, 1LL);
vga_write_palette((unsigned __int8)(v2 + 8), (char *)&std_palette + 3 * a2, 1LL);
result = (unsigned __int8)v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 a2)
{
__int64 v2; // rbx
__int64 result; // rax
__int64 v4; // rax
bool v5; // zf

v2 = 0LL;
while ( *(_DWORD *)(a1 + 4 * v2) )
{
if ( ++v2 == 8 )
return 0xFFFFFFFFLL;
}
v4 = 0LL;
while ( *(char *)(a1 + v4 + 32) != (_DWORD)v2 )
{
if ( ++v4 == 16 )
goto LABEL_9;
}
*(_BYTE *)(a1 + (int)v4 + 32) = -1;
LABEL_9:
v5 = active_dynacolor == a1;
*(_DWORD *)(a1 + 4LL * (int)v2) = 1;
result = (unsigned int)v2;
*(_BYTE *)(a1 + a2 + 32) = v2;
if ( v5 )
{
vga_write_palette((unsigned int)v2, (char *)&std_palette + 3 * a2, 1LL);
vga_write_palette((unsigned __int8)(v2 + 8), (char *)&std_palette + 3 * a2, 1LL);
result = (unsigned __int8)v2;
}
return result;
}

original_code:
signed char
dynacolor_allocate (dynacolor_t *dc, unsigned char col)
{
  int i;
  for (i = 0; i < 8; i++)
    if (dc->ref[i] == 0)
      {
 int j;
 for (j = 0; j < 16; j++)
   if (dc->col[j] == i)
     {
       dc->col[j] = -1;
       break;
     }
 dc->ref[i] = 1;
 dc->col[col] = i;
 if (active_dynacolor == dc)
   {
     vga_write_palette (0 + i, std_palette[col], 1);
     vga_write_palette (8 + i, std_palette[col], 1);
   }
 return i;
      }
  return -1;
}

canonical_original_code:
char dynacolor_allocate(struct dynacolor *dc, unsigned char col)
{
  int i;
  for (i = 0; i < 8; i++)
    if (dc->ref[i] == 0)
      {
 int j;
 for (j = 0; j < 16; j++)
   if (dc->col[j] == i)
     {
       dc->col[j] = -1;
       break;
     }
 dc->ref[i] = 1;
 dc->col[col] = i;
 if (active_dynacolor == dc)
   {
     vga_write_palette (0 + i, std_palette[col], 1);
     vga_write_palette (8 + i, std_palette[col], 1);
   }
 return i;
      }
  return -1;
}

variable_types:
col
unsigned char

variable_types: j int

return_type: char

user_defined_types: struct dynacolor { int ref[8]; char col[16]; }


decompiled_code:
void __fastcall dynacolor_replace_colors(int *a1, char a2, int a3, char *a4, char *a5)
{
signed __int8 v5; // r14
char v6; // r12
char v7; // r13
char v8; // r10
__int64 v9; // rax
signed __int8 *v10; // rbp
signed __int8 *v11; // r9
char v12; // al
__int64 v13; // rax
signed __int8 *v14; // rbp
signed __int8 *v15; // r15
signed __int8 v16; // al
char v17; // al
char *v18; // [rsp+8h] [rbp-60h]
char *v19; // [rsp+8h] [rbp-60h]
signed __int8 *v20; // [rsp+8h] [rbp-60h]
char *v21; // [rsp+10h] [rbp-58h]
char *v22; // [rsp+10h] [rbp-58h]
char v23; // [rsp+10h] [rbp-58h]
int v24; // [rsp+1Ch] [rbp-4Ch]
char *v25; // [rsp+20h] [rbp-48h]
char *v26; // [rsp+28h] [rbp-40h]

v5 = a3;
v6 = *a5;
v7 = *a4;
if ( *a5 != -1 )
{
LABEL_2:
if ( (_BYTE)a3 == a2 )
goto LABEL_12;
goto LABEL_3;
}
v8 = a2;
v9 = 9LL * (char)a3;
v10 = (char *)&pref_1 + v9;
v11 = (char *)&unk_609 + v9;
while ( 1 )
{
v5 = *v10;
if ( v7 != -1 && v5 == v8 )
goto LABEL_18;
if ( *a1 < 0 )
{
v6 = *v10;
goto LABEL_17;
}
v6 = *((_BYTE *)a1 + v5 + 32);
if ( v6 >= 0 )
break;
v26 = a5;
v25 = a4;
v24 = a3;
v23 = v8;
v20 = v11;
v17 = dynacolor_allocate((__int64)a1, v5);
v11 = v20;
v8 = v23;
a3 = v24;
a4 = v25;
v6 = v17;
a5 = v26;
LABEL_17:
if ( v6 >= 0 )
goto LABEL_2;
LABEL_18:
if ( v11 == ++v10 )
_assert_fail("res_bgcol >= 0", "vga-dynacolor.c", 0x125u, "dynacolor_replace_colors");
}
++a1[v6];
if ( (_BYTE)a3 != a2 )
{
LABEL_3:
if ( v6 == v7 )
_assert_fail("res_fgcol != res_bgcol", "vga-dynacolor.c", 0x130u, "dynacolor_replace_colors");
goto LABEL_4;
}
LABEL_12:
if ( v7 != -1 )
_assert_fail("res_fgcol == -1", "vga-dynacolor.c", 0x12Bu, "dynacolor_replace_colors");
if ( *a1 < 0 )
{
v7 = v5;
goto LABEL_4;
}
v7 = *((_BYTE *)a1 + v5 + 32);
if ( v7 >= 0 )
{
LABEL_24:
++a1[v7];
}
else
{
v21 = a5;
v18 = a4;
v12 = dynacolor_allocate((__int64)a1, v5);
a4 = v18;
a5 = v21;
v7 = v12;
LABEL_4:
if ( v7 == -1 )
{
v13 = 9LL * a2;
v14 = (char *)&pref_1 + v13;
v15 = (char *)&unk_609 + v13;
while ( 1 )
{
v16 = *v14;
if ( *v14 != v5 )
{
if ( *a1 >= 0 )
{
v7 = *((_BYTE *)a1 + v16 + 32);
if ( v7 >= 0 )
goto LABEL_24;
v22 = a5;
v19 = a4;
v16 = dynacolor_allocate((__int64)a1, v16);
a5 = v22;
a4 = v19;
}
if ( v16 >= 0 )
break;
}
if ( v15 == ++v14 )
_assert_fail("res_fgcol >= 0", "vga-dynacolor.c", 0x13Eu, "dynacolor_replace_colors");
}
v7 = v16;
}
}
*a4 = v7;
*a5 = v6;
}

original_code:
void
dynacolor_replace_colors (dynacolor_t *dc,
     signed char fgcol, signed char bgcol,
     signed char *r_fgcol, signed char *r_bgcol)
{
  static signed char pref[16][9] =
    {
      { CONS_COLOR_BLACK | (1 << 3), CONS_COLOR_BLUE,
 CONS_COLOR_YELLOW, CONS_COLOR_RED, CONS_COLOR_MAGENTA,
 CONS_COLOR_GREEN, CONS_COLOR_CYAN, CONS_COLOR_WHITE,
 CONS_COLOR_BLUE | (1 << 3) },
      { CONS_COLOR_RED | (1 << 3), CONS_COLOR_YELLOW,
 CONS_COLOR_MAGENTA, CONS_COLOR_BLUE, CONS_COLOR_CYAN,
 CONS_COLOR_GREEN, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_GREEN | (1 << 3), CONS_COLOR_CYAN,
 CONS_COLOR_YELLOW, CONS_COLOR_BLUE, CONS_COLOR_RED,
 CONS_COLOR_MAGENTA, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_YELLOW | (1 << 3), CONS_COLOR_RED,
 CONS_COLOR_GREEN, CONS_COLOR_MAGENTA, CONS_COLOR_BLUE,
 CONS_COLOR_CYAN, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_BLUE | (1 << 3), CONS_COLOR_CYAN,
 CONS_COLOR_MAGENTA, CONS_COLOR_RED, CONS_COLOR_GREEN,
 CONS_COLOR_YELLOW, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_RED,
 CONS_COLOR_BLUE, CONS_COLOR_YELLOW, CONS_COLOR_CYAN,
 CONS_COLOR_BLUE, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_CYAN | (1 << 3), CONS_COLOR_BLUE,
 CONS_COLOR_MAGENTA, CONS_COLOR_GREEN, CONS_COLOR_RED,
 CONS_COLOR_YELLOW, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_CYAN,
 CONS_COLOR_GREEN, CONS_COLOR_YELLOW, CONS_COLOR_MAGENTA,
 CONS_COLOR_RED, CONS_COLOR_BLUE, CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_BLACK, CONS_COLOR_BLUE | (1 << 3),
 CONS_COLOR_YELLOW | (1 << 3), CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_GREEN | (1 << 3),
 CONS_COLOR_CYAN | (1 << 3), CONS_COLOR_WHITE | (1 << 3),
 CONS_COLOR_WHITE },
      { CONS_COLOR_RED, CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_BLUE | (1 << 3),
 CONS_COLOR_CYAN | (1 << 3), CONS_COLOR_GREEN | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_GREEN, CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_YELLOW | (1 << 3), CONS_COLOR_BLUE | (1 << 3),
 CONS_COLOR_RED | (1 << 3), CONS_COLOR_MAGENTA | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_YELLOW, CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_GREEN | (1 << 3), CONS_COLOR_MAGENTA | (1 << 3),
 CONS_COLOR_BLUE | (1 << 3), CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_BLUE, CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_GREEN | (1 << 3), CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_MAGENTA, CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_BLUE | (1 << 3), CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_CYAN | (1 << 3), CONS_COLOR_GREEN | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_CYAN, CONS_COLOR_BLUE | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_GREEN | (1 << 3),
 CONS_COLOR_RED | (1 << 3), CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_WHITE, CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_GREEN | (1 << 3), CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_BLUE | (1 << 3), CONS_COLOR_CYAN,
 CONS_COLOR_BLACK | (1 << 3) },
    };
  signed char res_fgcol = *r_fgcol;
  signed char res_bgcol = *r_bgcol;
  signed char new_bgcol = bgcol;
  int i;
  if (res_bgcol == -1)
    {
      for (i = 0; i < 9; i++)
 {
   if (res_fgcol == -1 || pref[bgcol][i] != fgcol)
     {
       res_bgcol = ((*dc).ref[0] < 0 ? (pref[bgcol][i]) : ((*dc).col[(pref[bgcol][i])] >= 0 ? (*dc).ref[(*dc).col[(pref[bgcol][i])]]++, (*dc).col[(pref[bgcol][i])] : dynacolor_allocate (&(*dc), (pref[bgcol][i]))));
       if (res_bgcol >= 0)
  break;
     }
 }
      ((void) sizeof ((res_bgcol >= 0) ? 1 : 0), __extension__ ({ if (res_bgcol >= 0) ; else __assert_fail ("res_bgcol >= 0", "vga-dynacolor.c", 293, __extension__ __PRETTY_FUNCTION__); }));
      new_bgcol = pref[bgcol][i];
    }
  if (fgcol == bgcol)
    {
      ((void) sizeof ((res_fgcol == -1) ? 1 : 0), __extension__ ({ if (res_fgcol == -1) ; else __assert_fail ("res_fgcol == -1", "vga-dynacolor.c", 299, __extension__ __PRETTY_FUNCTION__); }));
      res_fgcol = ((*dc).ref[0] < 0 ? (new_bgcol) : ((*dc).col[(new_bgcol)] >= 0 ? (*dc).ref[(*dc).col[(new_bgcol)]]++, (*dc).col[(new_bgcol)] : dynacolor_allocate (&(*dc), (new_bgcol))));
    }
  else
    ((void) sizeof ((res_fgcol != res_bgcol) ? 1 : 0), __extension__ ({ if (res_fgcol != res_bgcol) ; else __assert_fail ("res_fgcol != res_bgcol", "vga-dynacolor.c", 304, __extension__ __PRETTY_FUNCTION__); }));
  if (res_fgcol == -1)
    {
      for (i = 0; i < 9; i++)
 {
   if (pref[fgcol][i] != new_bgcol)
     {
       res_fgcol = ((*dc).ref[0] < 0 ? (pref[fgcol][i]) : ((*dc).col[(pref[fgcol][i])] >= 0 ? (*dc).ref[(*dc).col[(pref[fgcol][i])]]++, (*dc).col[(pref[fgcol][i])] : dynacolor_allocate (&(*dc), (pref[fgcol][i]))));
       if (res_fgcol >= 0)
  break;
     }
 }
      ((void) sizeof ((res_fgcol >= 0) ? 1 : 0), __extension__ ({ if (res_fgcol >= 0) ; else __assert_fail ("res_fgcol >= 0", "vga-dynacolor.c", 318, __extension__ __PRETTY_FUNCTION__); }));
    }
  *r_fgcol = res_fgcol;
  *r_bgcol = res_bgcol;
}

canonical_original_code:
void dynacolor_replace_colors(struct dynacolor *dc, char fgcol, char bgcol, char *r_fgcol, char *r_bgcol)
{
  static char pref[16][9] = {
      { CONS_COLOR_BLACK | (1 << 3), CONS_COLOR_BLUE,
 CONS_COLOR_YELLOW, CONS_COLOR_RED, CONS_COLOR_MAGENTA,
 CONS_COLOR_GREEN, CONS_COLOR_CYAN, CONS_COLOR_WHITE,
 CONS_COLOR_BLUE | (1 << 3) },
      { CONS_COLOR_RED | (1 << 3), CONS_COLOR_YELLOW,
 CONS_COLOR_MAGENTA, CONS_COLOR_BLUE, CONS_COLOR_CYAN,
 CONS_COLOR_GREEN, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_GREEN | (1 << 3), CONS_COLOR_CYAN,
 CONS_COLOR_YELLOW, CONS_COLOR_BLUE, CONS_COLOR_RED,
 CONS_COLOR_MAGENTA, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_YELLOW | (1 << 3), CONS_COLOR_RED,
 CONS_COLOR_GREEN, CONS_COLOR_MAGENTA, CONS_COLOR_BLUE,
 CONS_COLOR_CYAN, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_BLUE | (1 << 3), CONS_COLOR_CYAN,
 CONS_COLOR_MAGENTA, CONS_COLOR_RED, CONS_COLOR_GREEN,
 CONS_COLOR_YELLOW, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_RED,
 CONS_COLOR_BLUE, CONS_COLOR_YELLOW, CONS_COLOR_CYAN,
 CONS_COLOR_BLUE, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_CYAN | (1 << 3), CONS_COLOR_BLUE,
 CONS_COLOR_MAGENTA, CONS_COLOR_GREEN, CONS_COLOR_RED,
 CONS_COLOR_YELLOW, CONS_COLOR_WHITE, CONS_COLOR_BLACK,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_CYAN,
 CONS_COLOR_GREEN, CONS_COLOR_YELLOW, CONS_COLOR_MAGENTA,
 CONS_COLOR_RED, CONS_COLOR_BLUE, CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_BLACK, CONS_COLOR_BLUE | (1 << 3),
 CONS_COLOR_YELLOW | (1 << 3), CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_GREEN | (1 << 3),
 CONS_COLOR_CYAN | (1 << 3), CONS_COLOR_WHITE | (1 << 3),
 CONS_COLOR_WHITE },
      { CONS_COLOR_RED, CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_BLUE | (1 << 3),
 CONS_COLOR_CYAN | (1 << 3), CONS_COLOR_GREEN | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_GREEN, CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_YELLOW | (1 << 3), CONS_COLOR_BLUE | (1 << 3),
 CONS_COLOR_RED | (1 << 3), CONS_COLOR_MAGENTA | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_YELLOW, CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_GREEN | (1 << 3), CONS_COLOR_MAGENTA | (1 << 3),
 CONS_COLOR_BLUE | (1 << 3), CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_BLUE, CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_GREEN | (1 << 3), CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_MAGENTA, CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_BLUE | (1 << 3), CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_CYAN | (1 << 3), CONS_COLOR_GREEN | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_CYAN, CONS_COLOR_BLUE | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_GREEN | (1 << 3),
 CONS_COLOR_RED | (1 << 3), CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_WHITE | (1 << 3), CONS_COLOR_WHITE,
 CONS_COLOR_BLACK | (1 << 3) },
      { CONS_COLOR_WHITE, CONS_COLOR_CYAN | (1 << 3),
 CONS_COLOR_GREEN | (1 << 3), CONS_COLOR_YELLOW | (1 << 3),
 CONS_COLOR_MAGENTA | (1 << 3), CONS_COLOR_RED | (1 << 3),
 CONS_COLOR_BLUE | (1 << 3), CONS_COLOR_CYAN,
 CONS_COLOR_BLACK | (1 << 3) },
    };
  char res_fgcol = *r_fgcol;
  char res_bgcol = *r_bgcol;
  char new_bgcol = bgcol;
  int i;
  if (res_bgcol == -1)
    {
      for (i = 0; i < 9; i++)
 {
   if (res_fgcol == -1 || pref[bgcol][i] != fgcol)
     {
       res_bgcol = ((*dc).ref[0] < 0 ? (pref[bgcol][i]) : ((*dc).col[(pref[bgcol][i])] >= 0 ? (*dc).ref[(*dc).col[(pref[bgcol][i])]]++, (*dc).col[(pref[bgcol][i])] : dynacolor_allocate (&(*dc), (pref[bgcol][i]))));
       if (res_bgcol >= 0)
  break;
     }
 }
      ((void) sizeof ((res_bgcol >= 0) ? 1 : 0), __extension__ ({ if (res_bgcol >= 0) ; else __assert_fail ("res_bgcol >= 0", "vga-dynacolor.c", 293, __extension__ __PRETTY_FUNCTION__); }));
      new_bgcol = pref[bgcol][i];
    }
  if (fgcol == bgcol)
    {
      ((void) sizeof ((res_fgcol == -1) ? 1 : 0), __extension__ ({ if (res_fgcol == -1) ; else __assert_fail ("res_fgcol == -1", "vga-dynacolor.c", 299, __extension__ __PRETTY_FUNCTION__); }));
      res_fgcol = ((*dc).ref[0] < 0 ? (new_bgcol) : ((*dc).col[(new_bgcol)] >= 0 ? (*dc).ref[(*dc).col[(new_bgcol)]]++, (*dc).col[(new_bgcol)] : dynacolor_allocate (&(*dc), (new_bgcol))));
    }
  else
    ((void) sizeof ((res_fgcol != res_bgcol) ? 1 : 0), __extension__ ({ if (res_fgcol != res_bgcol) ; else __assert_fail ("res_fgcol != res_bgcol", "vga-dynacolor.c", 304, __extension__ __PRETTY_FUNCTION__); }));
  if (res_fgcol == -1)
    {
      for (i = 0; i < 9; i++)
 {
   if (pref[fgcol][i] != new_bgcol)
     {
       res_fgcol = ((*dc).ref[0] < 0 ? (pref[fgcol][i]) : ((*dc).col[(pref[fgcol][i])] >= 0 ? (*dc).ref[(*dc).col[(pref[fgcol][i])]]++, (*dc).col[(pref[fgcol][i])] : dynacolor_allocate (&(*dc), (pref[fgcol][i]))));
       if (res_fgcol >= 0)
  break;
     }
 }
      ((void) sizeof ((res_fgcol >= 0) ? 1 : 0), __extension__ ({ if (res_fgcol >= 0) ; else __assert_fail ("res_fgcol >= 0", "vga-dynacolor.c", 318, __extension__ __PRETTY_FUNCTION__); }));
    }
  *r_fgcol = res_fgcol;
  *r_bgcol = res_bgcol;
}

variable_types: fgcol char

variable_types: bgcol char

variable_types:
pref
char [16][9]