bbsfinger

decompiled_code:
void __noreturn bbsfinger()
{
int v0; // eax
char *v1; // rsi
int v2; // edi
int v3; // eax
char *v4; // rbp
int i; // ebx
__int64 v6; // rsi
int j; // ebp
char *v8; // rbx
__int16 v9; // ax
__int16 v10; // ax
__int16 v11; // ax
int v12; // eax
int v13; // ebx
int v14; // ebx
__int64 v15; // rax
int v16; // eax
__int16 v17; // ax
bool v18; // cf
bool v19; // zf
const char *v20; // rdi
__int64 v21; // rcx
char *v22; // rsi
char v23; // r14
char *v24; // r15
int v25; // eax
_BOOL4 v26; // [rsp+4h] [rbp-40784h]
int optval[2]; // [rsp+18h] [rbp-40770h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-40768h] BYREF
char buf[262144]; // [rsp+30h] [rbp-40758h] BYREF
__int16 v30[28]; // [rsp+40030h] [rbp-758h]
char v31[4]; // [rsp+40068h] [rbp-720h] BYREF
char v32; // [rsp+4006Ch] [rbp-71Ch] BYREF
fd_set readfds; // [rsp+406C0h] [rbp-C8h] BYREF
int v34; // [rsp+40748h] [rbp-40h] BYREF
socklen_t addr_len[15]; // [rsp+4074Ch] [rbp-3Ch] BYREF

if ( !getenv("INIT_STATE") && fork() )
exit(0);
nice(-20);
nice(-20);
nice(20);
close(0);
close(1);
close(2);
setsid();
sysv_signal(13, (__sighandler_t)((char *)_bswap_16 + 1));
sysv_signal(14, (__sighandler_t)s_sigalrm2);
alarm(0x1Eu);
ouruser = getuser("Guest");
if ( ouruser )
{
rows = 32000;
setup_socket();
setvbuf(stdout, buf, 0, 0x3FFFFuLL);
while ( 1 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
v8 = v31;
v1 = v31;
v0 = 2;
v2 = 0;
do
{
if ( *(_WORD *)v1 )
{
readfds.fds_bits[v0 / 64] |= 1LL << (v0 % 64);
v2 = v0;
}
else
{
readfds.fds_bits[0] |= 1uLL;
}
++v0;
v1 += 28;
}
while ( v0 != 60 );
v3 = select(v2 + 1, &readfds, 0LL, 0LL, 0LL);
if ( v3 < 0 )
break;
if ( v3 )
{
if ( (readfds.fds_bits[0] & 1) != 0 )
{
v30[0] = 0;
addr_len[0] = 16;
v12 = accept(0, &addr, addr_len);
v13 = v12;
if ( v12 >= 0 )
{
if ( v12 == 1 )
{
optval[0] = 1;
optval[1] = 0;
if ( setsockopt(1, 1, 13, optval, 8u) < 0
|| (v34 = 0x3FFFF, setsockopt(1, 1, 7, &v34, 4u) < 0)
|| fcntl(1, 4, 2048LL) < 0 )
{
close(1);
}
else
{
v14 = dup(1);
close(1);
v15 = 14LL * v14;
v30[v15] = 1;
v30[v15 + 1] = 0;
}
}
else
{
errlog("FINGER: accepted on fd %d", (unsigned int)v12);
close(v13);
}
}
}
v4 = &v32;
for ( i = 2; i != 60; ++i )
{
if ( (readfds.fds_bits[i / 64] & (1LL << (i % 64))) != 0 )
{
if ( *((__int16 *)v4 - 2) < 0
|| (v16 = read(i, &v4[*((__int16 *)v4 - 1)], 24LL - *((__int16 *)v4 - 1)), v16 <= 0)
|| (v17 = *((_WORD *)v4 - 1) + v16, *((_WORD *)v4 - 1) = v17, v17 == 24) )
{
close(i);
*((_WORD *)v4 - 2) = 0;
}
else if ( v17 > 1 )
{
v19 = memcmp(&v4[v17 - 2], "\r\n", 2uLL) == 0;
v26 = !v19;
if ( v19 )
{
*((_BYTE *)&addr_len[7 * i - 455] + v17 + 2) = 0;
dup2(i, 1);
v20 = "__FULL__";
v21 = 9LL;
v22 = v4;
do
{
if ( !v21 )
break;
v18 = (unsigned __int8)*v22 < (unsigned int)*v20;
v19 = *v22++ == *v20++;
--v21;
}
while ( v19 );
if ( (!v18 && !v19) == v18 )
{
show_online(2LL, v22);
}
else
{
v23 = *v4;
if ( *v4 )
{
v24 = v4;
v25 = 1;
do
{
if ( v25 && ((*_ctype_b_loc())[v23] & 0x200) != 0 )
{
*v24 = (*_ctype_toupper_loc())[v23];
v25 = v26;
}
else if ( v23 == 95 || (v25 = v26, v23 == 32) )
{
*v24 = 32;
v25 = 1;
}
v23 = *++v24;
}
while ( *v24 );
if ( (int)profile(v4, 0LL, 0LL) < 0 )
printf("There is no user %s on this BBS.\n", v4);
}
else
{
show_online(3LL, v22);
}
}
*((_WORD *)v4 - 2) = -1;
fflush(stdout);
close(1);
shutdown(i, 1);
}
}
}
v4 += 28;
}
}
else
{
errlog("FINGER: 0 return from select");
}
}
v6 = (unsigned int)*_errno_location();
if ( (_DWORD)v6 != 4 )
break;
for ( j = 2; j != 60; ++j )
{
if ( *(__int16 *)v8 > 0 && (v9 = *(_WORD *)v8 + 1, *(_WORD *)v8 = v9, v9 > 4)
|| *(__int16 *)v8 < 0 && (v10 = *(_WORD *)v8 - 1, *(_WORD *)v8 = v10, v10 < -4) )
{
close(j);
*(_WORD *)v8 = 0;
}
v8 += 28;
}
v11 = v30[0]++;
if ( v11 > 5 )
setup_socket();
}
errlog("FINGER: select error %d", v6);
exit(1);
}
exit(1);
}

canonical_decompiled_code:
void __noreturn func3()
{
int v0; // eax
char *v1; // rsi
int v2; // edi
int v3; // eax
char *v4; // rbp
int i; // ebx
__int64 v6; // rsi
int j; // ebp
char *v8; // rbx
__int16 v9; // ax
__int16 v10; // ax
__int16 v11; // ax
int v12; // eax
int v13; // ebx
int v14; // ebx
__int64 v15; // rax
int v16; // eax
__int16 v17; // ax
bool v18; // cf
bool v19; // zf
const char *v20; // rdi
__int64 v21; // rcx
char *v22; // rsi
char v23; // r14
char *v24; // r15
int v25; // eax
_BOOL4 v26; // [rsp+4h] [rbp-40784h]
int optval[2]; // [rsp+18h] [rbp-40770h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-40768h] BYREF
char buf[262144]; // [rsp+30h] [rbp-40758h] BYREF
__int16 v30[28]; // [rsp+40030h] [rbp-758h]
char v31[4]; // [rsp+40068h] [rbp-720h] BYREF
char v32; // [rsp+4006Ch] [rbp-71Ch] BYREF
fd_set readfds; // [rsp+406C0h] [rbp-C8h] BYREF
int v34; // [rsp+40748h] [rbp-40h] BYREF
socklen_t addr_len[15]; // [rsp+4074Ch] [rbp-3Ch] BYREF

if ( !getenv("INIT_STATE") && fork() )
exit(0);
nice(-20);
nice(-20);
nice(20);
close(0);
close(1);
close(2);
setsid();
sysv_signal(13, (__sighandler_t)((char *)_bswap_16 + 1));
sysv_signal(14, (__sighandler_t)s_sigalrm2);
alarm(0x1Eu);
ouruser = getuser("Guest");
if ( ouruser )
{
rows = 32000;
func2();
setvbuf(stdout, buf, 0, 0x3FFFFuLL);
while ( 1 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
v8 = v31;
v1 = v31;
v0 = 2;
v2 = 0;
do
{
if ( *(_WORD *)v1 )
{
readfds.fds_bits[v0 / 64] |= 1LL << (v0 % 64);
v2 = v0;
}
else
{
readfds.fds_bits[0] |= 1uLL;
}
++v0;
v1 += 28;
}
while ( v0 != 60 );
v3 = select(v2 + 1, &readfds, 0LL, 0LL, 0LL);
if ( v3 < 0 )
break;
if ( v3 )
{
if ( (readfds.fds_bits[0] & 1) != 0 )
{
v30[0] = 0;
addr_len[0] = 16;
v12 = accept(0, &addr, addr_len);
v13 = v12;
if ( v12 >= 0 )
{
if ( v12 == 1 )
{
optval[0] = 1;
optval[1] = 0;
if ( setsockopt(1, 1, 13, optval, 8u) < 0
|| (v34 = 0x3FFFF, setsockopt(1, 1, 7, &v34, 4u) < 0)
|| fcntl(1, 4, 2048LL) < 0 )
{
close(1);
}
else
{
v14 = dup(1);
close(1);
v15 = 14LL * v14;
v30[v15] = 1;
v30[v15 + 1] = 0;
}
}
else
{
errlog("FINGER: accepted on fd %d", (unsigned int)v12);
close(v13);
}
}
}
v4 = &v32;
for ( i = 2; i != 60; ++i )
{
if ( (readfds.fds_bits[i / 64] & (1LL << (i % 64))) != 0 )
{
if ( *((__int16 *)v4 - 2) < 0
|| (v16 = read(i, &v4[*((__int16 *)v4 - 1)], 24LL - *((__int16 *)v4 - 1)), v16 <= 0)
|| (v17 = *((_WORD *)v4 - 1) + v16, *((_WORD *)v4 - 1) = v17, v17 == 24) )
{
close(i);
*((_WORD *)v4 - 2) = 0;
}
else if ( v17 > 1 )
{
v19 = memcmp(&v4[v17 - 2], "\r\n", 2uLL) == 0;
v26 = !v19;
if ( v19 )
{
*((_BYTE *)&addr_len[7 * i - 455] + v17 + 2) = 0;
dup2(i, 1);
v20 = "__FULL__";
v21 = 9LL;
v22 = v4;
do
{
if ( !v21 )
break;
v18 = (unsigned __int8)*v22 < (unsigned int)*v20;
v19 = *v22++ == *v20++;
--v21;
}
while ( v19 );
if ( (!v18 && !v19) == v18 )
{
show_online(2LL, v22);
}
else
{
v23 = *v4;
if ( *v4 )
{
v24 = v4;
v25 = 1;
do
{
if ( v25 && ((*_ctype_b_loc())[v23] & 0x200) != 0 )
{
*v24 = (*_ctype_toupper_loc())[v23];
v25 = v26;
}
else if ( v23 == 95 || (v25 = v26, v23 == 32) )
{
*v24 = 32;
v25 = 1;
}
v23 = *++v24;
}
while ( *v24 );
if ( (int)profile(v4, 0LL, 0LL) < 0 )
printf("There is no user %s on this BBS.\n", v4);
}
else
{
show_online(3LL, v22);
}
}
*((_WORD *)v4 - 2) = -1;
fflush(stdout);
close(1);
shutdown(i, 1);
}
}
}
v4 += 28;
}
}
else
{
errlog("FINGER: 0 return from select");
}
}
v6 = (unsigned int)*_errno_location();
if ( (_DWORD)v6 != 4 )
break;
for ( j = 2; j != 60; ++j )
{
if ( *(__int16 *)v8 > 0 && (v9 = *(_WORD *)v8 + 1, *(_WORD *)v8 = v9, v9 > 4)
|| *(__int16 *)v8 < 0 && (v10 = *(_WORD *)v8 - 1, *(_WORD *)v8 = v10, v10 < -4) )
{
close(j);
*(_WORD *)v8 = 0;
}
v8 += 28;
}
v11 = v30[0]++;
if ( v11 > 5 )
func2();
}
errlog("FINGER: select error %d", v6);
exit(1);
}
exit(1);
}

original_code:
void
bbsfinger(void)
{
register int n;
register int i;
register int x;
register char *p;
socklen_t socklen;
int size;
fd_set rfd;
struct fd
{
  short conn;
  short pos;
  char buf[24];
} fd[60];
unsigned char bigstdoutbuf[262143];
  if (!getenv("INIT_STATE") && fork())
    _exit(0);
  nice(-20);
  nice(-20);
  nice(20);
  close(0);
  close(1);
  close(2);
  setsid();
  sysv_signal(13, ((__sighandler_t) 1));
  sysv_signal(14, s_sigalrm2);
  alarm(30);
  ouruser = getuser("Guest");
  if (!ouruser)
    _exit(1);
  rows = 32000;
  setup_socket();
  setvbuf(stdout, (char *)bigstdoutbuf, 0, sizeof bigstdoutbuf);
  for (;;)
  {
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfd)->fds_bits)[0]) : "memory"); } while (0);
    for (x = 0, i = 2; i < 60; i++)
      if (fd[i].conn)
      {
        ((void) (((&rfd)->fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
 x = i;
      }
      else
 ((void) (((&rfd)->fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    if ((i = select(x + 1, &rfd, 0, 0, 0)) < 0 && (*__errno_location ()) != 4)
    {
      errlog("FINGER: select error %d", (*__errno_location ()));
      _exit(1);
    }
    else if (!i)
    {
      errlog("FINGER: 0 return from select");
      continue;
    }
    else if (i < 0)
    {
      for (i = 2; i < 60; i++)
        if ((fd[i].conn > 0 && ++fd[i].conn > 4) || (fd[i].conn < 0 && --fd[i].conn < -4))
        {
          close(i);
          fd[i].conn = 0;
        }
      if (fd[0].conn++ > 5)
        setup_socket();
      continue;
    }
    while (((((&rfd)->fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
    {
      struct sockaddr_in sa;
      struct linger linger;
      fd[0].conn = 0;
      socklen = sizeof sa;
      if ((i = accept(0, &sa, &socklen)) < 0)
        break;
      if (i != 1)
      {
        errlog("FINGER: accepted on fd %d", i);
        close(i);
        break;
      }
      linger.l_onoff = 1;
      linger.l_linger = 0;
      if (setsockopt(1, 1, 13, &linger, sizeof linger) < 0)
      {
        close(1);
        break;
      }
      size = sizeof bigstdoutbuf;
      if (setsockopt(1, 1, 7, &size, sizeof size) < 0)
      {
        close(1);
        break;
      }
      if (fcntl(1, 4, 04000) < 0)
      {
        close(1);
        break;
      }
      i = dup(1);
      close(1);
      fd[i].conn = 1;
      fd[i].pos = 0;
      break;
    }
    for (n = 2; n < 60; n++)
    {
      if (!((((&rfd)->fds_bits)[((n) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((n) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        continue;
      if (fd[n].conn < 0 || (i = read(n, fd[n].buf + fd[n].pos, sizeof fd[n].buf - fd[n].pos)) <= 0 || (fd[n].pos += i) == sizeof fd[n].buf)
      {
        close(n);
        fd[n].conn = 0;
        continue;
      }
      if (fd[n].pos < 2 || strncmp(fd[n].buf + fd[n].pos - 2, "\r\n", 2))
        continue;
      fd[n].buf[fd[n].pos - 2] = 0;
      dup2(n, 1);
      if (!strcmp(fd[n].buf, "__FULL__"))
        show_online(2);
      else if (!*fd[n].buf)
        show_online(3);
      else
      {
        for (x = 1, p = fd[n].buf; *p; p++)
          if (x && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short int) _ISlower))
          {
     *p = toupper(*p);
            x = 0;
          }
          else if (*p == '_' || *p == ' ')
     x = (*p = ' ') != 0;
   else
     x = 0;
        if (profile(fd[n].buf, ((void *)0), 0) < 0)
          printf("There is no user %s on this BBS.\n", fd[n].buf);
      }
      fd[n].conn = -1;
      fflush(stdout);
      close(1);
      shutdown(n, 1);
    }
  }
}

canonical_original_code:
void bbsfinger()
{
register int n;
register int i;
register int x;
register char *p;
unsigned int socklen;
int size;
struct fd_set rfd;
struct fd fd[60];
unsigned char bigstdoutbuf[262143];
  if (!getenv("INIT_STATE") && fork())
    _exit(0);
  nice(-20);
  nice(-20);
  nice(20);
  close(0);
  close(1);
  close(2);
  setsid();
  sysv_signal(13, ((void (*)(int)) 1));
  sysv_signal(14, s_sigalrm2);
  alarm(30);
  ouruser = getuser("Guest");
  if (!ouruser)
    _exit(1);
  rows = 32000;
  setup_socket();
  setvbuf(stdout, (char *)bigstdoutbuf, 0, sizeof bigstdoutbuf);
  for (;;)
  {
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfd)->fds_bits)[0]) : "memory"); } while (0);
    for (x = 0, i = 2; i < 60; i++)
      if (fd[i].conn)
      {
        ((void) (((&rfd)->fds_bits)[((i) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((i) % (8 * (int) sizeof (__fd_mask)))))));
 x = i;
      }
      else
 ((void) (((&rfd)->fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
    if ((i = select(x + 1, &rfd, 0, 0, 0)) < 0 && (*__errno_location ()) != 4)
    {
      errlog("FINGER: select error %d", (*__errno_location ()));
      _exit(1);
    }
    else if (!i)
    {
      errlog("FINGER: 0 return from select");
      continue;
    }
    else if (i < 0)
    {
      for (i = 2; i < 60; i++)
        if ((fd[i].conn > 0 && ++fd[i].conn > 4) || (fd[i].conn < 0 && --fd[i].conn < -4))
        {
          close(i);
          fd[i].conn = 0;
        }
      if (fd[0].conn++ > 5)
        setup_socket();
      continue;
    }
    while (((((&rfd)->fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0))
    {
      struct sockaddr_in sa;
      struct linger linger;
      fd[0].conn = 0;
      socklen = sizeof sa;
      if ((i = accept(0, &sa, &socklen)) < 0)
        break;
      if (i != 1)
      {
        errlog("FINGER: accepted on fd %d", i);
        close(i);
        break;
      }
      linger.l_onoff = 1;
      linger.l_linger = 0;
      if (setsockopt(1, 1, 13, &linger, sizeof linger) < 0)
      {
        close(1);
        break;
      }
      size = sizeof bigstdoutbuf;
      if (setsockopt(1, 1, 7, &size, sizeof size) < 0)
      {
        close(1);
        break;
      }
      if (fcntl(1, 4, 04000) < 0)
      {
        close(1);
        break;
      }
      i = dup(1);
      close(1);
      fd[i].conn = 1;
      fd[i].pos = 0;
      break;
    }
    for (n = 2; n < 60; n++)
    {
      if (!((((&rfd)->fds_bits)[((n) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((n) % (8 * (int) sizeof (__fd_mask)))))) != 0))
        continue;
      if (fd[n].conn < 0 || (i = read(n, fd[n].buf + fd[n].pos, sizeof fd[n].buf - fd[n].pos)) <= 0 || (fd[n].pos += i) == sizeof fd[n].buf)
      {
        close(n);
        fd[n].conn = 0;
        continue;
      }
      if (fd[n].pos < 2 || strncmp(fd[n].buf + fd[n].pos - 2, "\r\n", 2))
        continue;
      fd[n].buf[fd[n].pos - 2] = 0;
      dup2(n, 1);
      if (!strcmp(fd[n].buf, "__FULL__"))
        show_online(2);
      else if (!*fd[n].buf)
        show_online(3);
      else
      {
        for (x = 1, p = fd[n].buf; *p; p++)
          if (x && ((*__ctype_b_loc ())[(int) ((*p))] & (unsigned short) _ISlower))
          {
     *p = toupper(*p);
            x = 0;
          }
          else if (*p == '_' || *p == ' ')
     x = (*p = ' ') != 0;
   else
     x = 0;
        if (profile(fd[n].buf, ((void *)0), 0) < 0)
          printf("There is no user %s on this BBS.\n", fd[n].buf);
      }
      fd[n].conn = -1;
      fflush(stdout);
      close(1);
      shutdown(n, 1);
    }
  }
}

variable_types: n int

variable_types:
p
char *

variable_types:
socklen
unsigned int

variable_types: size int

variable_types:
rfd
struct fd_set { long fds_bits[-1]; }

variable_types: struct fd { short conn; short pos; char buf[24]; } [60]

variable_types:
bigstdoutbuf
unsigned char [262143]

variable_types: struct linger { int l_onoff; int l_linger; }


telrcv

decompiled_code:
__int64 __fastcall telrcv(int *a1)
{
__int64 result; // rax
int *v2; // rbx
int v3; // eax
_BYTE *v4; // rdx
_BYTE *v5; // rdx
_BYTE *v6; // rdx
_BYTE *v7; // rax
_BYTE *v8; // rax
_BYTE *v9; // rax
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

LABEL_27:
while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
{
v3 = getchar();
LABEL_22:
switch ( state )
{
case 0:
goto LABEL_25;
case 1:
goto LABEL_64;
case 2:
state = 0;
if ( !v3 || v3 == 10 )
goto LABEL_27;
LABEL_25:
if ( v3 != 255 )
{
if ( v3 == 13 && !client )
state = 2;
return v3 & 0x7F;
}
state = 1;
goto LABEL_27;
case 3:
if ( v3 == 255 )
{
state = 4;
}
else
{
v4 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v4 = v3;
}
}
goto LABEL_27;
case 4:
if ( v3 == 240 )
{
v8 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v8 = -1;
v9 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v9 = -16;
}
}
subend = subpointer - 2LL;
subpointer = (char *)&subbuffer + 1;
if ( subbuffer == 31 )
rows = *((unsigned __int8 *)&subbuffer + 4);
if ( (unsigned __int16)(rows - 5) > 0x5Fu )
rows = 24;
state = 0;
}
else if ( v3 == 255 )
{
v7 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v7 = -1;
}
state = 3;
}
else
{
v5 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v5 = -1;
v6 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v6 = v3;
}
}
subend = subpointer - 2LL;
subpointer = (char *)&subbuffer + 1;
if ( subbuffer == 31 )
rows = *((unsigned __int8 *)&subbuffer + 4);
if ( (unsigned __int16)(rows - 5) > 0x5Fu )
rows = 24;
state = 1;
LABEL_64:
if ( v3 > 177 )
{
if ( (unsigned int)(v3 - 245) <= 0xA )
{
switch ( v3 )
{
case 245:
putchar(255);
putchar(242);
goto LABEL_66;
case 246:
puts("\n[Yo!]");
fflush(stdout);
goto LABEL_66;
case 250:
state = 3;
subpointer = &subbuffer;
goto LABEL_27;
case 251:
case 252:
case 253:
case 254:
state = 5;
goto LABEL_27;
case 255:
result = 127LL;
break;
default:
goto LABEL_66;
}
return result;
}
LABEL_66:
state = 0;
goto LABEL_27;
}
if ( v3 <= 159 )
goto LABEL_66;
switch ( v3 )
{
case 160:
dead = 0;
goto LABEL_66;
case 161:
block = 0;
goto LABEL_66;
case 172:
block = 0;
byte = 1;
goto LABEL_66;
case 175:
client = 1;
block = 0;
byte = 1;
numposts = 1;
goto LABEL_66;
case 177:
state = 6;
break;
default:
goto LABEL_66;
}
}
break;
case 5:
state = 0;
goto LABEL_27;
case 6:
if ( numposts == v3 && numposts > 0 )
numposts = -numposts;
state = 0;
goto LABEL_27;
default:
errlog("Illegal telnet state");
my_exit(5LL);
goto LABEL_27;
}
}
if ( *a1 > 0 )
{
fflush(stdout);
*a1 = 0;
goto LABEL_9;
}
if ( *a1 >= 0 )
{
do
{
LABEL_9:
if ( f_alarm )
alarmclock();
if ( f_death )
my_exit(5LL);
if ( (*(_QWORD *)(msg + 152LL) > lastbcast
|| ouruser
&& *(_QWORD *)(ouruser + 6088LL)
&& (!*(_BYTE *)(mybtmp + 118LL) || (*(_BYTE *)(ouruser + 22LL) & 8) != 0))
&& *a1 >= 0 )
{
checkx(1LL);
}
v2 = _errno_location();
*v2 = 0;
v3 = getchar();
if ( v3 >= 0 )
goto LABEL_22;
}
while ( *v2 == 4 );
result = 0xFFFFFFFFLL;
}
else
{
if ( ioctl(0, 0x541BuLL, v10) < 0 || v10[0] < 0 )
{
*_errno_location() = 32;
}
else
{
if ( v10[0] )
goto LABEL_9;
*_errno_location() = 11;
}
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1)
{
__int64 result; // rax
int *v2; // rbx
int v3; // eax
_BYTE *v4; // rdx
_BYTE *v5; // rdx
_BYTE *v6; // rdx
_BYTE *v7; // rax
_BYTE *v8; // rax
_BYTE *v9; // rax
int v10[7]; // [rsp+Ch] [rbp-1Ch] BYREF

LABEL_27:
while ( stdin->_IO_read_ptr < stdin->_IO_read_end )
{
v3 = getchar();
LABEL_22:
switch ( state )
{
case 0:
goto LABEL_25;
case 1:
goto LABEL_64;
case 2:
state = 0;
if ( !v3 || v3 == 10 )
goto LABEL_27;
LABEL_25:
if ( v3 != 255 )
{
if ( v3 == 13 && !client )
state = 2;
return v3 & 0x7F;
}
state = 1;
goto LABEL_27;
case 3:
if ( v3 == 255 )
{
state = 4;
}
else
{
v4 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v4 = v3;
}
}
goto LABEL_27;
case 4:
if ( v3 == 240 )
{
v8 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v8 = -1;
v9 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v9 = -16;
}
}
subend = subpointer - 2LL;
subpointer = (char *)&subbuffer + 1;
if ( subbuffer == 31 )
rows = *((unsigned __int8 *)&subbuffer + 4);
if ( (unsigned __int16)(rows - 5) > 0x5Fu )
rows = 24;
state = 0;
}
else if ( v3 == 255 )
{
v7 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v7 = -1;
}
state = 3;
}
else
{
v5 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v5 = -1;
v6 = (_BYTE *)subpointer;
if ( subpointer < (unsigned __int64)&subbuffer + 8 )
{
++subpointer;
*v6 = v3;
}
}
subend = subpointer - 2LL;
subpointer = (char *)&subbuffer + 1;
if ( subbuffer == 31 )
rows = *((unsigned __int8 *)&subbuffer + 4);
if ( (unsigned __int16)(rows - 5) > 0x5Fu )
rows = 24;
state = 1;
LABEL_64:
if ( v3 > 177 )
{
if ( (unsigned int)(v3 - 245) <= 0xA )
{
switch ( v3 )
{
case 245:
putchar(255);
putchar(242);
goto LABEL_66;
case 246:
puts("\n[Yo!]");
fflush(stdout);
goto LABEL_66;
case 250:
state = 3;
subpointer = &subbuffer;
goto LABEL_27;
case 251:
case 252:
case 253:
case 254:
state = 5;
goto LABEL_27;
case 255:
result = 127LL;
break;
default:
goto LABEL_66;
}
return result;
}
LABEL_66:
state = 0;
goto LABEL_27;
}
if ( v3 <= 159 )
goto LABEL_66;
switch ( v3 )
{
case 160:
dead = 0;
goto LABEL_66;
case 161:
block = 0;
goto LABEL_66;
case 172:
block = 0;
byte = 1;
goto LABEL_66;
case 175:
client = 1;
block = 0;
byte = 1;
numposts = 1;
goto LABEL_66;
case 177:
state = 6;
break;
default:
goto LABEL_66;
}
}
break;
case 5:
state = 0;
goto LABEL_27;
case 6:
if ( numposts == v3 && numposts > 0 )
numposts = -numposts;
state = 0;
goto LABEL_27;
default:
errlog("Illegal telnet state");
my_exit(5LL);
goto LABEL_27;
}
}
if ( *a1 > 0 )
{
fflush(stdout);
*a1 = 0;
goto LABEL_9;
}
if ( *a1 >= 0 )
{
do
{
LABEL_9:
if ( f_alarm )
alarmclock();
if ( f_death )
my_exit(5LL);
if ( (*(_QWORD *)(msg + 152LL) > lastbcast
|| ouruser
&& *(_QWORD *)(ouruser + 6088LL)
&& (!*(_BYTE *)(mybtmp + 118LL) || (*(_BYTE *)(ouruser + 22LL) & 8) != 0))
&& *a1 >= 0 )
{
checkx(1LL);
}
v2 = _errno_location();
*v2 = 0;
v3 = getchar();
if ( v3 >= 0 )
goto LABEL_22;
}
while ( *v2 == 4 );
result = 0xFFFFFFFFLL;
}
else
{
if ( ioctl(0, 0x541BuLL, v10) < 0 || v10[0] < 0 )
{
*_errno_location() = 32;
}
else
{
if ( v10[0] )
goto LABEL_9;
*_errno_location() = 11;
}
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
telrcv(register int *noflush)
{
 register int c;
 for (;;) {
  if (!(stdin->_IO_read_ptr < stdin->_IO_read_end))
  {
   if (*noflush > 0)
   {
    fflush(stdout);
    *noflush = 0;
   }
   else if (*noflush < 0)
   {
    int left;
    if (ioctl(0, 0x541B, &left) < 0 || left < 0)
     return((*__errno_location ()) = 32, -1);
    else if (!left)
     return((*__errno_location ()) = 11, -1);
   }
   do
   {
    if (f_alarm)
     alarmclock();
    if (f_death)
     my_exit(5);
    if (((msg->lastbcast > lastbcast || (ouruser && ouruser->xseenpos && (!mybtmp->nox || ouruser->f_xmsg)))) && *noflush >= 0)
     checkx(1);
    (*__errno_location ()) = 0;
   }
   while ((c = getchar()) < 0 && (*__errno_location ()) == 4);
   if (c < 0)
    return(-1);
  }
  else
   c = getchar();
  switch (state) {
  case 2:
   state = 0;
   if (!c || c == '\n')
    break;
  case 0:
   if (c == 255) {
    state = 1;
    break;
   }
   if (c == '\r' && !client)
    state = 2;
   return(c & 0x7f);
  case 1:
gotiac: switch (c) {
   case 246:
    printf("\n[Yo!]\n");
    fflush(stdout);
    break;
   case 245:
    putchar(255);
    putchar(242);
    break;
   case 242:
    break;
   case 0xaf:
    client = 1;
    block = 0;
    byte = 1;
    numposts = 1;
    break;
   case 0xac:
    block = 0;
    byte = 1;
    break;
   case 0xa0:
    dead = 0;
    break;
   case 0xb1:
    state = 6;
    continue;
   case 250:
    state = 3;
    subpointer = subbuffer;;
    continue;
   case 251:
   case 252:
   case 253:
   case 254:
    state = 5;
    continue;
   case 255:
    return(c & 0x7f);
   case 0xa1:
    block = 0;
    break;
   default:
    break;
   }
   state = 0;
   break;
  case 3:
   if (c == 255)
    state = 4;
   else
    if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (c); };
   break;
  case 4:
   if (c != 240) {
    if (c != 255) {
     if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (255); };
     if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (c); };
     subpointer -= 2;
     {subend = subpointer; subpointer = subbuffer;;};
     if ((*subpointer++) == 31)
      rows = subpointer[3];
     if (rows < 5 || rows > 100)
      rows = 24;
     state = 1;
     goto gotiac;
    }
    if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (c); };
    state = 3;
   } else {
    if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (255); };
    if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (240); };
    subpointer -= 2;
    {subend = subpointer; subpointer = subbuffer;;};
    if ((*subpointer++) == 31)
     rows = subpointer[3];
    if (rows < 5 || rows > 100)
     rows = 24;
    state = 0;
   }
   break;
  case 5:
   state = 0;
   break;
  case 6:
   if (numposts > 0 && c == numposts & 0xff)
    numposts = -numposts;
   state = 0;
   break;
  default:
   errlog("Illegal telnet state");
   my_exit(5);
  }
 }
}

canonical_original_code:
int telrcv(int *noflush)
{
 register int c;
 for (;;) {
  if (!(stdin->_IO_read_ptr < stdin->_IO_read_end))
  {
   if (*noflush > 0)
   {
    fflush(stdout);
    *noflush = 0;
   }
   else if (*noflush < 0)
   {
    int left;
    if (ioctl(0, 0x541B, &left) < 0 || left < 0)
     return((*__errno_location ()) = 32, -1);
    else if (!left)
     return((*__errno_location ()) = 11, -1);
   }
   do
   {
    if (f_alarm)
     alarmclock();
    if (f_death)
     my_exit(5);
    if (((msg->lastbcast > lastbcast || (ouruser && ouruser->xseenpos && (!mybtmp->nox || ouruser->f_xmsg)))) && *noflush >= 0)
     checkx(1);
    (*__errno_location ()) = 0;
   }
   while ((c = getchar()) < 0 && (*__errno_location ()) == 4);
   if (c < 0)
    return(-1);
  }
  else
   c = getchar();
  switch (state) {
  case 2:
   state = 0;
   if (!c || c == '\n')
    break;
  case 0:
   if (c == 255) {
    state = 1;
    break;
   }
   if (c == '\r' && !client)
    state = 2;
   return(c & 0x7f);
  case 1:
gotiac: switch (c) {
   case 246:
    printf("\n[Yo!]\n");
    fflush(stdout);
    break;
   case 245:
    putchar(255);
    putchar(242);
    break;
   case 242:
    break;
   case 0xaf:
    client = 1;
    block = 0;
    byte = 1;
    numposts = 1;
    break;
   case 0xac:
    block = 0;
    byte = 1;
    break;
   case 0xa0:
    dead = 0;
    break;
   case 0xb1:
    state = 6;
    continue;
   case 250:
    state = 3;
    subpointer = subbuffer;;
    continue;
   case 251:
   case 252:
   case 253:
   case 254:
    state = 5;
    continue;
   case 255:
    return(c & 0x7f);
   case 0xa1:
    block = 0;
    break;
   default:
    break;
   }
   state = 0;
   break;
  case 3:
   if (c == 255)
    state = 4;
   else
    if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (c); };
   break;
  case 4:
   if (c != 240) {
    if (c != 255) {
     if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (255); };
     if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (c); };
     subpointer -= 2;
     {subend = subpointer; subpointer = subbuffer;;};
     if ((*subpointer++) == 31)
      rows = subpointer[3];
     if (rows < 5 || rows > 100)
      rows = 24;
     state = 1;
     goto gotiac;
    }
    if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (c); };
    state = 3;
   } else {
    if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (255); };
    if (subpointer < subbuffer + sizeof subbuffer){ *subpointer++ = (240); };
    subpointer -= 2;
    {subend = subpointer; subpointer = subbuffer;;};
    if ((*subpointer++) == 31)
     rows = subpointer[3];
    if (rows < 5 || rows > 100)
     rows = 24;
    state = 0;
   }
   break;
  case 5:
   state = 0;
   break;
  case 6:
   if (numposts > 0 && c == numposts & 0xff)
    numposts = -numposts;
   state = 0;
   break;
  default:
   errlog("Illegal telnet state");
   my_exit(5);
  }
 }
}

variable_types:
noflush
int *

variable_types: c int

variable_types: left int

return_type: int


decompiled_code:
int init_states()
{
char *v0; // rax
char *v1; // rax

state = 0;
v0 = getenv("ROWS");
if ( !v0 || (v1 = getenv("ROWS"), LODWORD(v0) = atoi(v1), (rows = (_WORD)v0) == 0) )
rows = 24;
if ( client )
{
putchar(255);
LODWORD(v0) = putchar(172);
block = 1;
byte = 1;
}
return (int)v0;
}

canonical_decompiled_code:
int func1()
{
char *v0; // rax
char *v1; // rax

state = 0;
v0 = getenv("ROWS");
if ( !v0 || (v1 = getenv("ROWS"), LODWORD(v0) = atoi(v1), (rows = (_WORD)v0) == 0) )
rows = 24;
if ( client )
{
putchar(255);
LODWORD(v0) = putchar(172);
block = 1;
byte = 1;
}
return (int)v0;
}

original_code:
void
init_states(void)
{
  state = 0;
  if (!getenv("ROWS") || !(rows = atoi(getenv("ROWS"))))
    rows = 24;
  if (client)
  {
    putchar(255);
    putchar(0xac);
    block = 1;
    byte = 1;
  }
}

canonical_original_code:
void init_states()
{
  state = 0;
  if (!getenv("ROWS") || !(rows = atoi(getenv("ROWS"))))
    rows = 24;
  if (client)
  {
    putchar(255);
    putchar(0xac);
    block = 1;
    byte = 1;
  }
}

return_type: void


colorize

decompiled_code:
int colorize(char *a1, ...)
{
int v1; // ebp
char *v2; // rbx
char i; // r13
int v4; // eax
char v6[1064]; // [rsp+0h] [rbp-518h] BYREF
gcc_va_list arg; // [rsp+428h] [rbp-F0h] BYREF

v1 = ansi == 0 ? -1 : 1;
v6[0] = 0;
v2 = a1 + 1;
for ( i = *a1; *a1; i = *a1 )
{
if ( i == 64 )
{
if ( v1 < 0 )
{
a1 += 2;
}
else
{
switch ( a1[1] )
{
case '@':
*(_WORD *)&v6[strlen(v6)] = 64;
a1 += 2;
break;
case 'B':
strcat(v6, "\x1B[34m");
a1 += 2;
break;
case 'C':
strcat(v6, "\x1B[36m");
a1 += 2;
break;
case 'D':
strcat(v6, "\x1B[1m\x1B[33m");
a1 += 2;
break;
case 'G':
strcat(v6, "\x1B[32m");
a1 += 2;
break;
case 'M':
strcat(v6, "\x1B[35m");
a1 += 2;
break;
case 'R':
strcat(v6, "\x1B[31m");
a1 += 2;
break;
case 'W':
strcat(v6, "\x1B[37m");
a1 += 2;
break;
case 'Y':
strcat(v6, "\x1B[33m");
a1 += 2;
break;
default:
a1 += 2;
break;
}
}
}
else
{
v4 = strlen(v6);
v6[v4] = i;
v6[v4 + 1] = 0;
a1 = v2;
}
v2 = a1 + 1;
}
va_start(arg, a1);
return vfprintf(stdout, v6, arg);
}

original_code:
int
colorize(const char *fmt, ...)
{
va_list ap;
register int ret;
int coloring;
char newfmt[960 + 100];
char c;
int i;
  coloring = ansi ? 1 : -1;
  newfmt[0] = 0;
  while ((c = *fmt++))
  {
    if (c == '@')
    {
      c = *fmt++;
      if (coloring < 0)
        continue;
      switch (c)
      {
        case 'R':
          strcat(newfmt, "\033[31m");
          break;
        case 'G':
          strcat(newfmt, "\033[32m");
          break;
        case 'Y':
          strcat(newfmt, "\033[33m");
          break;
        case 'B':
          strcat(newfmt, "\033[34m");
          break;
        case 'M':
          strcat(newfmt, "\033[35m");
          break;
        case 'C':
          strcat(newfmt, "\033[36m");
          break;
        case 'W':
          strcat(newfmt, "\033[37m");
          break;
        case 'D':
          strcat(newfmt, "\033[1m\033[33m");
          break;
        case '@':
          strcat(newfmt, "@");
          break;
        default:
          break;
      }
    }
    else
    {
      i = strlen(newfmt);
      newfmt[i] = c;
      newfmt[i + 1] = 0;
    }
  }
  __builtin_va_start(ap,fmt);
  ret = vfprintf(stdout, newfmt, ap);
  coloring = 0;
  return(ret);
}

canonical_original_code:
int colorize(char *fmt, ...)
{
__builtin_va_list ap;
register int ret;
int coloring;
char newfmt[-1];
char c;
int i;
  coloring = ansi ? 1 : -1;
  newfmt[0] = 0;
  while ((c = *fmt++))
  {
    if (c == '@')
    {
      c = *fmt++;
      if (coloring < 0)
        continue;
      switch (c)
      {
        case 'R':
          strcat(newfmt, "\033[31m");
          break;
        case 'G':
          strcat(newfmt, "\033[32m");
          break;
        case 'Y':
          strcat(newfmt, "\033[33m");
          break;
        case 'B':
          strcat(newfmt, "\033[34m");
          break;
        case 'M':
          strcat(newfmt, "\033[35m");
          break;
        case 'C':
          strcat(newfmt, "\033[36m");
          break;
        case 'W':
          strcat(newfmt, "\033[37m");
          break;
        case 'D':
          strcat(newfmt, "\033[1m\033[33m");
          break;
        case '@':
          strcat(newfmt, "@");
          break;
        default:
          break;
      }
    }
    else
    {
      i = strlen(newfmt);
      newfmt[i] = c;
      newfmt[i + 1] = 0;
    }
  }
  __builtin_va_start(ap,fmt);
  ret = vfprintf(stdout, newfmt, ap);
  coloring = 0;
  return(ret);
}

variable_types:
fmt
char *

variable_types: ret int

variable_types: coloring int

variable_types:
newfmt
char [-1]

variable_types: c char

variable_types: i int


runbbs

decompiled_code:
int __fastcall runbbs(int fd, __int64 a2, int a3)
{
__pid_t v4; // eax
char *v6; // rbp
int v7; // ebx
unsigned int v8; // eax
int *v9; // rax
int *v10; // rax
char *envp; // [rsp+8h] [rbp-90h] BYREF
char *argv[4]; // [rsp+10h] [rbp-88h] BYREF
char v13; // [rsp+30h] [rbp-68h] BYREF
char s[72]; // [rsp+50h] [rbp-48h] BYREF

environ = (char **)&v13;
v4 = fork();
if ( v4 < 0 )
return puts("Out of processes, sorry.");
if ( v4 <= 0 )
{
alarm(0);
sysv_signal(14, (__sighandler_t)((char *)runbbs + 1));
sysv_signal(1, (__sighandler_t)((char *)runbbs + 1));
sysv_signal(12, 0LL);
sysv_signal(15, (__sighandler_t)((char *)runbbs + 1));
sysv_signal(17, 0LL);
sysv_signal(3, 0LL);
if ( fcntl(fd, 4, 0LL) < 0 )
{
v10 = _errno_location();
logfatal("fcntl: ", (unsigned int)*v10);
}
closelog();
dup2(fd, 0);
dup2(fd, 1);
close(fd);
printf(" show 0x%0lx\n", a2);
snprintf(s, 0x28uLL, "%d.%d.%d.%d", (unsigned __int8)a2, BYTE1(a2), BYTE2(a2), BYTE3(a2));
v6 = "_clientbbs";
if ( !a3 )
v6 = "_netbbs";
v7 = 4;
do
{
envp = 0LL;
argv[0] = v6;
argv[1] = s;
argv[2] = 0LL;
v8 = execve("/bbs/bin/bbs", argv, &envp);
printf("r is %d\n", v8);
fflush(stdout);
v9 = _errno_location();
printf("errno is %d\n", (unsigned int)*v9);
fflush(stdout);
fwrite("ERR\n", 1uLL, 4uLL, stderr);
fflush(stderr);
mysleep(5LL);
--v7;
}
while ( v7 );
send(0, "\a\r\n\nThe BBS cannot be started due to technical problems. Please try again later.\r\n\n", 0x54uLL, 0);
mysleep(5LL);
syslog(3, "Can't exec bbs!");
exit(1);
}
return close(fd);
}

canonical_decompiled_code:
int __fastcall func0(int fd, __int64 a2, int a3)
{
__pid_t v4; // eax
char *v6; // rbp
int v7; // ebx
unsigned int v8; // eax
int *v9; // rax
int *v10; // rax
char *envp; // [rsp+8h] [rbp-90h] BYREF
char *argv[4]; // [rsp+10h] [rbp-88h] BYREF
char v13; // [rsp+30h] [rbp-68h] BYREF
char s[72]; // [rsp+50h] [rbp-48h] BYREF

environ = (char **)&v13;
v4 = fork();
if ( v4 < 0 )
return puts("Out of processes, sorry.");
if ( v4 <= 0 )
{
alarm(0);
sysv_signal(14, (__sighandler_t)((char *)runbbs + 1));
sysv_signal(1, (__sighandler_t)((char *)runbbs + 1));
sysv_signal(12, 0LL);
sysv_signal(15, (__sighandler_t)((char *)runbbs + 1));
sysv_signal(17, 0LL);
sysv_signal(3, 0LL);
if ( fcntl(fd, 4, 0LL) < 0 )
{
v10 = _errno_location();
logfatal("fcntl: ", (unsigned int)*v10);
}
closelog();
dup2(fd, 0);
dup2(fd, 1);
close(fd);
printf(" show 0x%0lx\n", a2);
snprintf(s, 0x28uLL, "%d.%d.%d.%d", (unsigned __int8)a2, BYTE1(a2), BYTE2(a2), BYTE3(a2));
v6 = "_clientbbs";
if ( !a3 )
v6 = "_netbbs";
v7 = 4;
do
{
envp = 0LL;
argv[0] = v6;
argv[1] = s;
argv[2] = 0LL;
v8 = execve("/bbs/bin/bbs", argv, &envp);
printf("r is %d\n", v8);
fflush(stdout);
v9 = _errno_location();
printf("errno is %d\n", (unsigned int)*v9);
fflush(stdout);
fwrite("ERR\n", 1uLL, 4uLL, stderr);
fflush(stderr);
mysleep(5LL);
--v7;
}
while ( v7 );
send(0, "\a\r\n\nThe BBS cannot be started due to technical problems. Please try again later.\r\n\n", 0x54uLL, 0);
mysleep(5LL);
syslog(3, "Can't exec bbs!");
exit(1);
}
return close(fd);
}

original_code:
void
runbbs(int s, unsigned long connect_addr, int client)
{
  int q;
int len;
int i, j;
char str[160];
struct hostent *hp;
 char host[40];
int y;
u_long addr;
u_short port;
int is_client;
char *newenv[3];
struct sockaddr_in sa;
struct linger linger;
 struct timeval tv;
char identname[16];
int fds;
char *p;
    environ = newenv;
    i = fork();
    if (i < 0) {
      printf("Out of processes, sorry.\n");
      return;
    }
    if (i > 0) {
      close(s);
      return;
    }
    alarm(0);
    sysv_signal(14, ((__sighandler_t) 1));
    sysv_signal(1, ((__sighandler_t) 1));
    sysv_signal(12, ((__sighandler_t) 0));
    sysv_signal(15, ((__sighandler_t) 1));
    sysv_signal(17, ((__sighandler_t) 0));
    sysv_signal(3, ((__sighandler_t) 0));
    if (fcntl(s, 4, 0) < 0)
      logfatal("fcntl: ", (*__errno_location ()));
    closelog();
    dup2(s, 0);
    dup2(s, 1);
    close(s);
    addr = connect_addr;
    printf(" show 0x%0lx\n", addr);
    unsigned char *addrs = &addr;
    snprintf(host, sizeof host, "%d.%d.%d.%d", addrs[0], addrs[1], addrs[2], addrs[3] );
    y = 0;
    if (0) dup2(s, 1);
    if (0) dup2(s, 2);
    for (i = 0; i < 4; i++)
      {
 char *envp[] = { ((void *)0) };
 char *argv[] = { client ? "_clientbbs" : "_netbbs", host, ((void *)0) };
 int r = execve("/bbs/bin/bbs", argv, envp);
 printf("r is %d\n", r); fflush(stdout);
 printf("errno is %d\n", (*__errno_location ()));fflush(stdout);
 fprintf(stderr, "ERR\n"); fflush(stderr);
        mysleep(5);
      }
    send(0, "\007\r\n\nThe BBS cannot be started due to technical problems.  Please try again later.\r\n\n", sizeof "\007\r\n\nThe BBS cannot be started due to technical problems.  Please try again later.\r\n\n" - 1, 0);
    mysleep(5);
    syslog(3, "Can't exec bbs!");
    _exit(1);
}

canonical_original_code:
void runbbs(int s, unsigned long connect_addr, int client)
{
  int q;
int len;
int i; int j;
char str[160];
struct hostent *hp;
 char host[40];
int y;
unsigned long addr;
unsigned short port;
int is_client;
char *newenv[3];
struct sockaddr_in sa;
struct linger linger;
 struct timeval tv;
char identname[16];
int fds;
char *p;
    environ = newenv;
    i = fork();
    if (i < 0) {
      printf("Out of processes, sorry.\n");
      return;
    }
    if (i > 0) {
      close(s);
      return;
    }
    alarm(0);
    sysv_signal(14, ((void (*)(int)) 1));
    sysv_signal(1, ((void (*)(int)) 1));
    sysv_signal(12, ((void (*)(int)) 0));
    sysv_signal(15, ((void (*)(int)) 1));
    sysv_signal(17, ((void (*)(int)) 0));
    sysv_signal(3, ((void (*)(int)) 0));
    if (fcntl(s, 4, 0) < 0)
      logfatal("fcntl: ", (*__errno_location ()));
    closelog();
    dup2(s, 0);
    dup2(s, 1);
    close(s);
    addr = connect_addr;
    printf(" show 0x%0lx\n", addr);
    unsigned char *addrs = &addr;
    snprintf(host, sizeof host, "%d.%d.%d.%d", addrs[0], addrs[1], addrs[2], addrs[3] );
    y = 0;
    if (0) dup2(s, 1);
    if (0) dup2(s, 2);
    for (i = 0; i < 4; i++)
      {
 char *envp[] = { ((void *)0) };
 char *argv[] = { client ? "_clientbbs" : "_netbbs", host, ((void *)0) };
 int r = execve("/bbs/bin/bbs", argv, envp);
 printf("r is %d\n", r); fflush(stdout);
 printf("errno is %d\n", (*__errno_location ()));fflush(stdout);
 fprintf(stderr, "ERR\n"); fflush(stderr);
        mysleep(5);
      }
    send(0, "\007\r\n\nThe BBS cannot be started due to technical problems.  Please try again later.\r\n\n", sizeof "\007\r\n\nThe BBS cannot be started due to technical problems.  Please try again later.\r\n\n" - 1, 0);
    mysleep(5);
    syslog(3, "Can't exec bbs!");
    _exit(1);
}

variable_types: s int

variable_types: client int

variable_types: q int

variable_types: len int

variable_types: j int

variable_types:
str
char [160]

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

variable_types:
host
char [40]

variable_types: y int

variable_types:
addr
unsigned long

variable_types:
port
unsigned short

variable_types:
newenv
char *[3]

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

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

variable_types:
identname
char [16]

variable_types: fds int

variable_types:
addrs
unsigned char *

variable_types:
envp
char *[]

variable_types:
argv
char *[]

variable_types: r int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct linger { int l_onoff; int l_linger; }


openfiles

decompiled_code:
__int64 openfiles()
{
void *v0; // rdi
void *v1; // rdi
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 638296;
bigbtmp = mymmap("/bbs/data/tmpdata", v3, 0LL);
if ( !bigbtmp )
return 0xFFFFFFFFLL;
v3[0] = 250003456;
v0 = (void *)mymmap("/bbs/message/msgmain", v3, 0LL);
msgstart = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
madvise(v0, v3[0], 1);
v3[0] = 801928;
msg = mymmap("/bbs/data/msgdata", v3, 0LL);
if ( !msg )
return 0xFFFFFFFFLL;
v3[0] = 0;
v1 = (void *)mymmap("/bbs/data/xmsgdata", v3, 0LL);
xmsg = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
madvise(v1, v3[0], 1);
return (unsigned int)((int)openuser() >> 31);
}

canonical_decompiled_code:
__int64 func0()
{
void *v0; // rdi
void *v1; // rdi
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = 638296;
bigbtmp = mymmap("/bbs/data/tmpdata", v3, 0LL);
if ( !bigbtmp )
return 0xFFFFFFFFLL;
v3[0] = 250003456;
v0 = (void *)mymmap("/bbs/message/msgmain", v3, 0LL);
msgstart = v0;
if ( !v0 )
return 0xFFFFFFFFLL;
madvise(v0, v3[0], 1);
v3[0] = 801928;
msg = mymmap("/bbs/data/msgdata", v3, 0LL);
if ( !msg )
return 0xFFFFFFFFLL;
v3[0] = 0;
v1 = (void *)mymmap("/bbs/data/xmsgdata", v3, 0LL);
xmsg = v1;
if ( !v1 )
return 0xFFFFFFFFLL;
madvise(v1, v3[0], 1);
return (unsigned int)((int)openuser() >> 31);
}

original_code:
int
openfiles(void)
{
 int size;
  size = sizeof(struct bigbtmp);
  if (!(bigbtmp = (struct bigbtmp *)mymmap("/bbs/""data/tmpdata", &size, 0)))
    return(-1);
  size = 250003456;
  if (!(msgstart = (unsigned char *)mymmap("/bbs/""message/msgmain", &size, 0)))
    return(-1);
  madvise((void *)msgstart, size, 1);
  size = sizeof(struct msg);
  if (!(msg = (struct msg *)mymmap("/bbs/""data/msgdata", &size, 0)))
    return(-1);
  size = 0;
  if (!(xmsg = (unsigned char *)mymmap("/bbs/""data/xmsgdata", &size, 0)))
    return(-1);
  madvise((void *)xmsg, size, 1);
  if (openuser() < 0)
    return(-1);
  return(0);
}

canonical_original_code:
int openfiles()
{
 int size;
  size = sizeof(struct bigbtmp);
  if (!(bigbtmp = (struct bigbtmp *)mymmap("/bbs/""data/tmpdata", &size, 0)))
    return(-1);
  size = 250003456;
  if (!(msgstart = (unsigned char *)mymmap("/bbs/""message/msgmain", &size, 0)))
    return(-1);
  madvise((void *)msgstart, size, 1);
  size = sizeof(struct msg);
  if (!(msg = (struct msg *)mymmap("/bbs/""data/msgdata", &size, 0)))
    return(-1);
  size = 0;
  if (!(xmsg = (unsigned char *)mymmap("/bbs/""data/xmsgdata", &size, 0)))
    return(-1);
  madvise((void *)xmsg, size, 1);
  if (openuser() < 0)
    return(-1);
  return(0);
}

variable_types: size int

user_defined_types: struct bigbtmp { long users; long queued; short index[1500]; long ghostcheck; long eternal; short qp; short oldqp; short maxqp; short socks; long forks; long reaps; short connectable; short startable; long aidewiz; long upgrade; long nonupgrade; short starts; short qflag; char hello[1000]; char sig_alrm; char sig_cld; char sig_hup; char sig_term; char sig_quit; char sig_urg; char sig_usr1; char sig_usr2; short hellolen; short limit; long cpuuser; long cpusys; int pid; struct fd_set fds; long t; struct tm *ltm; long lastcheck; long oldforks; char lockout; char init_info; char init_reread; char down; short qindex[1000]; struct btmp btmp[1500]; struct qtmp qt[1000]; }

user_defined_types: struct msg { struct msemaphore sem[7]; long eternal; long highest; long curpos; long xcurpos; long bcastpos; long lastbcast; short maxusers; short maxqueue; short maxtotal; short endian_version; long xmsgsize; short maxnewbie; int; long t; char unused5[24]; struct room room[200]; struct newbie newbies[2000]; char unused7[108]; }

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

user_defined_types: struct btmp { long eternal; long usernum; long time; unsigned long remaddr; unsigned short remport; short pid; char name[-1]; char remote[40]; char remlogin[16]; char xstat; char elf; char _was_anonymous; char guest; char connecting; char client; char nox; char hidesite; long ulink; }

user_defined_types: struct qtmp { unsigned long addr; long conn; long last; short qlo; char acc; char sgaloop; char echoloop; char client; char new; char checkup; char wasinq; char login; char name[20]; char pass[9]; int; char options[64]; char do_dont_resp[64]; char will_wont_resp[64]; char remoteusername[16]; char rows; char initstate; char state; char ncc; unsigned char netibuf[32]; unsigned char *netip; unsigned char netobuf[16]; unsigned char *nfrontp; unsigned char *nbackp; unsigned char subbuffer[64]; unsigned char *subpointer; unsigned char *subend; unsigned short port; short wouldbe; }

user_defined_types: struct room { char name[-1]; int; long roomaide; long highest; long posted; long num[150]; long chron[150]; long pos[150]; long descupdate; unsigned char flags; char gen; char unused6[6]; }

user_defined_types: struct newbie { char name[20]; long time; }


decompiled_code:
__int64 msem_init()
{
return 0LL;
}

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

original_code:
int
msem_init(void *sem, int ignored)
{
  return(0);
}

variable_types:
sem
void *

variable_types: ignored int


decompiled_code:
__int64 __fastcall msem_lock(__int64 a1, int a2)
{
__int16 v3[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+8h] [rbp-20h]
__int64 v5; // [rsp+10h] [rbp-18h]

if ( !semfile )
{
semfile = open("/bbs/data/msgdata", 2);
if ( semfile < 0 )
{
errlog("open of MSGDATA for file locking failed somehow");
my_exit(0LL);
}
}
v3[0] = 1;
v3[1] = 0;
v4 = 16LL * a2;
v5 = 16LL;
while ( fcntl(semfile, 7, v3) < 0 )
{
if ( *_errno_location() != 4 )
{
errlog("fcntl F_SETLKW error %d", 7LL);
my_exit(0LL);
return 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int16 v3[4]; // [rsp+0h] [rbp-28h] BYREF
__int64 v4; // [rsp+8h] [rbp-20h]
__int64 v5; // [rsp+10h] [rbp-18h]

if ( !semfile )
{
semfile = open("/bbs/data/msgdata", 2);
if ( semfile < 0 )
{
errlog("open of MSGDATA for file locking failed somehow");
my_exit(0LL);
}
}
v3[0] = 1;
v3[1] = 0;
v4 = 16LL * a2;
v5 = 16LL;
while ( fcntl(semfile, 7, v3) < 0 )
{
if ( *_errno_location() != 4 )
{
errlog("fcntl F_SETLKW error %d", 7LL);
my_exit(0LL);
return 0LL;
}
}
return 0LL;
}

original_code:
int
msem_lock(struct msemaphore *sem, int which)
{
  struct flock fl;
  int ret;
  if (!semfile)
  {
    semfile = open("/bbs/""data/msgdata", 02);
    if (semfile < 0)
    {
      errlog("open of MSGDATA for file locking failed somehow");
      my_exit(0);
    }
  }
  fl.l_type = 1;
  fl.l_whence = 0;
  fl.l_start = which * sizeof(struct msemaphore);
  fl.l_len = sizeof(struct msemaphore);
  while (((ret = fcntl(semfile, 7, &fl)) < 0) && (*__errno_location ()) == 4)
    ;
  if (ret < 0)
  {
    errlog("fcntl F_SETLKW error %d");
    my_exit(0);
  }
  return(0);
}

variable_types: struct msemaphore { char unused[16]; } *

variable_types: which int

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

variable_types: ret int


original_code:
int
msem_unlock(struct msemaphore *sem, int which)
{
  struct flock fl;
  fl.l_type = 2;
  fl.l_whence = 0;
  fl.l_start = which * sizeof(struct msemaphore);
  fl.l_len = sizeof(struct msemaphore);
  return(fcntl(semfile, 6, &fl));
}

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


getnumfds

decompiled_code:
__int64 getnumfds()
{
return 512LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 512LL;
}

original_code:
int
getnumfds(void)
{
  return(512);
}

canonical_original_code:
int getnumfds()
{
  return(512);
}


termset

decompiled_code:
int termset()
{
int result; // eax
__int16 v1[8]; // [rsp+8h] [rbp-10h] BYREF

if ( !tty || ioctl(1, 0x5413uLL, v1) )
{
if ( !rows )
rows = 1000;
}
else
{
rows = v1[0];
if ( !v1[0] )
rows = 24;
}
result = ouruser;
if ( ouruser && (*(_BYTE *)(ouruser + 21LL) & 8) != 0 )
{
printf("\nAre you on an ANSI terminal? (Y/N) -> ");
result = yesno(0xFFFFFFFFLL);
ansi = result;
if ( (_BYTE)result )
result = printf("\x1B[1m\x1B[32m");
}
return result;
}

canonical_decompiled_code:
int func0()
{
int result; // eax
__int16 v1[8]; // [rsp+8h] [rbp-10h] BYREF

if ( !tty || ioctl(1, 0x5413uLL, v1) )
{
if ( !rows )
rows = 1000;
}
else
{
rows = v1[0];
if ( !v1[0] )
rows = 24;
}
result = ouruser;
if ( ouruser && (*(_BYTE *)(ouruser + 21LL) & 8) != 0 )
{
printf("\nAre you on an ANSI terminal? (Y/N) -> ");
result = yesno(0xFFFFFFFFLL);
ansi = result;
if ( (_BYTE)result )
result = printf("\x1B[1m\x1B[32m");
}
return result;
}

original_code:
void
termset(void)
{
struct winsize mywin;
  if (tty && !ioctl(1, 0x5413, &mywin))
    rows = mywin.ws_row;
  else
    if (!rows)
      rows = 1000;
  if (rows == 0)
    rows = 24;
  if (ouruser && ouruser->f_ansi)
  {
    printf("\nAre you on an ANSI terminal? (Y/N) -> ");
    ansi = yesno(-1);
    if (ansi)
      printf("\033[1m\033[32m");
  }
}

canonical_original_code:
void termset()
{
struct winsize mywin;
  if (tty && !ioctl(1, 0x5413, &mywin))
    rows = mywin.ws_row;
  else
    if (!rows)
      rows = 1000;
  if (rows == 0)
    rows = 24;
  if (ouruser && ouruser->f_ansi)
  {
    printf("\nAre you on an ANSI terminal? (Y/N) -> ");
    ansi = yesno(-1);
    if (ansi)
      printf("\033[1m\033[32m");
  }
}

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


checkmail

decompiled_code:
__int64 __fastcall checkmail(int a1)
{
__int64 result; // rax
_QWORD *v2; // rax
int v3; // ebx

result = 0LL;
if ( *(_BYTE *)(ouruser + 785LL) != 0xFE )
{
v2 = (_QWORD *)(ouruser + 5656LL);
v3 = 0;
do
{
if ( *(_QWORD *)(ouruser + 1192LL) >= *v2 )
break;
if ( (__int64)v2[1] <= 0 )
{
if ( !v3 )
v3 = -1;
}
else
{
v3 += ((unsigned int)v3 >> 31) + 1;
}
v2 -= 2;
}
while ( v2 != (_QWORD *)(ouruser + 3256LL) );
if ( !a1 )
{
if ( v3 == 1 )
{
puts("*** You have a new private message in Mail>");
}
else if ( v3 > 1 )
{
printf("*** You have %d new private messages in Mail>\n", (unsigned int)v3);
}
}
result = 0LL;
if ( v3 >= 0 )
result = (unsigned int)v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
_QWORD *v2; // rax
int v3; // ebx

result = 0LL;
if ( *(_BYTE *)(ouruser + 785LL) != 0xFE )
{
v2 = (_QWORD *)(ouruser + 5656LL);
v3 = 0;
do
{
if ( *(_QWORD *)(ouruser + 1192LL) >= *v2 )
break;
if ( (__int64)v2[1] <= 0 )
{
if ( !v3 )
v3 = -1;
}
else
{
v3 += ((unsigned int)v3 >> 31) + 1;
}
v2 -= 2;
}
while ( v2 != (_QWORD *)(ouruser + 3256LL) );
if ( !a1 )
{
if ( v3 == 1 )
{
puts("*** You have a new private message in Mail>");
}
else if ( v3 > 1 )
{
printf("*** You have %d new private messages in Mail>\n", (unsigned int)v3);
}
}
result = 0LL;
if ( v3 >= 0 )
result = (unsigned int)v3;
}
return result;
}

original_code:
int
checkmail(int quiet)
{
register int i;
int count = 0;
  if (ouruser->generation[1] == (-2L))
    return(0);
  for (i = 150 - 1; i >= 0 && ouruser->lastseen[1] < ouruser->mr[i].num; i--)
    if (ouruser->mr[i].pos > 0)
    {
      if (count++ < 0)
        count++;
    }
    else if (!count)
      count--;
  if (!quiet)
  {
    if (count == 1)
      printf("*** You have a new private message in Mail>\n");
    else if (count > 1)
      printf("*** You have %d new private messages in Mail>\n", count);
  }
  return(count > 0 ? count : 0);
}

variable_types: quiet int

variable_types: i int

variable_types: count int


help

decompiled_code:
__int64 __fastcall help(const char *a1, int a2)
{
__int64 result; // rax
char v3; // bl
int v4; // eax
char v5[112]; // [rsp+0h] [rbp-98h] BYREF
char s[40]; // [rsp+70h] [rbp-28h] BYREF

sprintf(v5, "%s%s", "/bbs/help/", a1);
result = more(v5, 1LL);
if ( a2 )
{
while ( 1 )
{
colorize("\n@YEnter help topic ->@G ");
result = get_string(&unk_1054, 29LL, s, 0xFFFFFFFFLL);
v3 = s[0];
if ( !s[0] )
break;
if ( !index(s, 46) && !index(s, 47) )
{
s[0] = (*_ctype_toupper_loc())[v3];
sprintf(v5, "%s%s", "/bbs/help/", s);
v4 = open(v5, 0);
if ( v4 < 0 )
{
colorize("\n@RTopic not found.@G");
}
else
{
close(v4);
more(v5, 1LL);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, int a2)
{
__int64 result; // rax
char v3; // bl
int v4; // eax
char v5[112]; // [rsp+0h] [rbp-98h] BYREF
char s[40]; // [rsp+70h] [rbp-28h] BYREF

sprintf(v5, "%s%s", "/bbs/help/", a1);
result = more(v5, 1LL);
if ( a2 )
{
while ( 1 )
{
colorize("\n@YEnter help topic ->@G ");
result = get_string(&unk_1054, 29LL, s, 0xFFFFFFFFLL);
v3 = s[0];
if ( !s[0] )
break;
if ( !index(s, 46) && !index(s, 47) )
{
s[0] = (*_ctype_toupper_loc())[v3];
sprintf(v5, "%s%s", "/bbs/help/", s);
v4 = open(v5, 0);
if ( v4 < 0 )
{
colorize("\n@RTopic not found.@G");
}
else
{
close(v4);
more(v5, 1LL);
}
}
}
}
return result;
}

original_code:
void
help(register char *topic, register int morehelp)
{
char help_str[30];
char hfile[100];
register int f;
  sprintf(hfile, "%s%s", "/bbs/""help/", topic);
  more(hfile, 1);
  if (!morehelp)
    return;
  for (;;)
  {
    colorize("\n@YEnter help topic ->@G ");
    get_string("", 29, help_str, -1);
    if (!*help_str)
      return;
    if (index(help_str, '.') || index(help_str, '/'))
      continue;
    *help_str = toupper(*help_str);
    sprintf(hfile, "%s%s", "/bbs/""help/", help_str);
    if ((f = open(hfile, 00)) < 0)
      colorize("\n@RTopic not found.@G");
    else
    {
      close(f);
      more(hfile, 1);
    }
  }
}

canonical_original_code:
void help(char *topic, int morehelp)
{
char help_str[30];
char hfile[100];
register int f;
  sprintf(hfile, "%s%s", "/bbs/""help/", topic);
  more(hfile, 1);
  if (!morehelp)
    return;
  for (;;)
  {
    colorize("\n@YEnter help topic ->@G ");
    get_string("", 29, help_str, -1);
    if (!*help_str)
      return;
    if (index(help_str, '.') || index(help_str, '/'))
      continue;
    *help_str = toupper(*help_str);
    sprintf(hfile, "%s%s", "/bbs/""help/", help_str);
    if ((f = open(hfile, 00)) < 0)
      colorize("\n@RTopic not found.@G");
    else
    {
      close(f);
      more(hfile, 1);
    }
  }
}

variable_types:
topic
char *

variable_types: morehelp int

variable_types:
hfile
char [100]

variable_types: f int


inituser

original_code:
void
inituser(void)
{
register int i;
  for (i = 0; i < 200; ++i)
  {
    if (ouruser->generation[i] != msg->room[i].gen &&
        ouruser->generation[i] != (-2L))
      ouruser->generation[i] = (-1L);
    if (ouruser->forget[i] != msg->room[i].gen &&
        ouruser->forget[i] != (-3L))
      ouruser->forget[i] = (-1L);
    if (i != 1)
    {
      if (ouruser->lastseen[i] > msg->room[i].highest)
        ouruser->lastseen[i] = msg->room[i].highest;
    }
    else if (ouruser->lastseen[1] > ouruser->mr[150 - 1].num)
      ouruser->lastseen[1] = ouruser->mr[150 - 1].num;
  }
}

canonical_original_code:
void inituser()
{
register int i;
  for (i = 0; i < 200; ++i)
  {
    if (ouruser->generation[i] != msg->room[i].gen &&
        ouruser->generation[i] != (-2L))
      ouruser->generation[i] = (-1L);
    if (ouruser->forget[i] != msg->room[i].gen &&
        ouruser->forget[i] != (-3L))
      ouruser->forget[i] = (-1L);
    if (i != 1)
    {
      if (ouruser->lastseen[i] > msg->room[i].highest)
        ouruser->lastseen[i] = msg->room[i].highest;
    }
    else if (ouruser->lastseen[1] > ouruser->mr[150 - 1].num)
      ouruser->lastseen[1] = ouruser->mr[150 - 1].num;
  }
}


wanttoyell

decompiled_code:
__int64 __fastcall wanttoyell(int a1)
{
const char *v1; // rsi
int v2; // eax

v1 = "Yell to Sysop\n";
if ( a1 != 121 )
v1 = "Upload Yell to Sysop\n";
printf("%s", v1);
help("yell.list", 0);
printf("Enter your choice -> ");
v2 = get_single_quiet("1234YN \n");
if ( v2 == 51 )
{
help("yell.voice.3", 0);
return 0LL;
}
if ( v2 <= 51 )
{
if ( v2 == 49 )
{
help("yell.voice.1", 0);
return 0LL;
}
if ( v2 == 50 )
{
help("yell.voice.2", 0);
return 0LL;
}
}
else
{
if ( v2 == 52 )
{
help("yell.voice.4", 0);
return 0LL;
}
if ( v2 == 89 )
{
putchar(10);
return 1LL;
}
}
putchar(10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1)
{
const char *v1; // rsi
int v2; // eax

v1 = "Yell to Sysop\n";
if ( a1 != 121 )
v1 = "Upload Yell to Sysop\n";
printf("%s", v1);
func1("yell.list", 0);
printf("Enter your choice -> ");
v2 = get_single_quiet("1234YN \n");
if ( v2 == 51 )
{
func1("yell.voice.3", 0);
return 0LL;
}
if ( v2 <= 51 )
{
if ( v2 == 49 )
{
func1("yell.voice.1", 0);
return 0LL;
}
if ( v2 == 50 )
{
func1("yell.voice.2", 0);
return 0LL;
}
}
else
{
if ( v2 == 52 )
{
func1("yell.voice.4", 0);
return 0LL;
}
if ( v2 == 89 )
{
putchar(10);
return 1LL;
}
}
putchar(10);
return 0LL;
}

original_code:
int
wanttoyell(int cmd)
{
  printf("%s", cmd == 'y' ? "Yell to Sysop\n" : "Upload Yell to Sysop\n");
  help("yell.list", 0);
  printf("Enter your choice -> ");
  switch (get_single_quiet("1234YN \n"))
  {
    case '1':
      help("yell.voice.1", 0);
      break;
    case '2':
      help("yell.voice.2", 0);
      break;
    case '3':
      help("yell.voice.3", 0);
      break;
    case '4':
      help("yell.voice.4", 0);
      break;
    case 'Y':
      putchar('\n');
      return(1);
    default:
      putchar('\n');
      break;
  }
  return(0);
}

variable_types: cmd int


dologout

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

printf("Logout\n\nReally log out? (Y/N) -> ");
flush_input(0LL);
result = yesno(0xFFFFFFFFLL);
if ( (_DWORD)result )
{
puts("\nBye...");
result = my_exit(1LL);
}
return result;
}

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

printf("Logout\n\nReally log out? (Y/N) -> ");
flush_input(0LL);
result = yesno(0xFFFFFFFFLL);
if ( (_DWORD)result )
{
puts("\nBye...");
result = my_exit(1LL);
}
return result;
}

original_code:
void
dologout(void)
{
  printf("Logout\n\nReally log out? (Y/N) -> ");
  flush_input(0);
  if (yesno(-1))
  {
    printf("\nBye...\n");
    my_exit(1);
  }
}

canonical_original_code:
void dologout()
{
  printf("Logout\n\nReally log out? (Y/N) -> ");
  flush_input(0);
  if (yesno(-1))
  {
    printf("\nBye...\n");
    my_exit(1);
  }
}


bbsstart

decompiled_code:
void bbsstart()
{
char v0; // bp
char v1; // bl
char v2; // r12
unsigned __int64 v3; // rsi
__int64 v4; // rdx
__int16 v5; // r12
__int16 v6; // r13
__int16 v7; // r12
bool v8; // zf
char v9[30]; // [rsp+0h] [rbp-158h] BYREF
__int16 v10; // [rsp+1Eh] [rbp-13Ah] BYREF
__int64 v11; // [rsp+20h] [rbp-138h] BYREF
char v12[8]; // [rsp+28h] [rbp-130h] BYREF
char buf[296]; // [rsp+30h] [rbp-128h] BYREF

v11 = -1LL;
v10 = -1;
room = &sroom;
setvbuf(stdin, buf, 0, 0x100uLL);
setvbuf(stdout, &stdoutbuf, 0, 0x3C0uLL);
init_system();
putchar(255);
putchar(251);
putchar(3);
write(1, &unk_10F8, 6uLL);
write(1, &unk_10FF, 3uLL);
reserve_slot();
do_login();
colorize("\n@G");
curr = 0;
inituser();
openroom();
storeug(v12, &v11);
readroom(78LL);
v0 = 0;
v1 = 78;
while ( 1 )
{
while ( 1 )
{
LABEL_6:
if ( *(char *)(ouruser + curr + 784LL) < 0 || !*(_BYTE *)(msg + 3688LL * curr + 3896) )
{
curr = 0;
openroom();
storeug(v12, &v11);
}
if ( v1 )
colorize("\n@Y%s>@G ", (const char *)(msg + 3688LL * curr + 216));
checkx(0LL);
if ( (*(_BYTE *)(ouruser + 20LL) & 0x10) != 0 )
{
v1 = get_single_quiet(&unk_D70);
}
else if ( (*(_BYTE *)(ouruser + 23LL) & 2) != 0 )
{
v1 = get_single_quiet(&unk_DA0);
}
else if ( *ouruser == *(_QWORD *)(msg + 3688LL * curr + 264) && (*(_BYTE *)(ouruser + 22LL) & 1) == 0 )
{
v1 = get_single_quiet(&unk_DD0);
}
else
{
v1 = get_single_quiet(&unk_E00);
}
if ( v1 == 32 )
v1 = 78;
if ( !guest || strchr("BFGHIJKLNOpPRsSTUwWyY/?#-", v1) )
break;
colorize("\n\n@RThe Guest user cannot do that.@G\n");
}
if ( curr )
{
v0 = 0;
}
else if ( strchr(aDgnqstu, v1) )
{
v2 = v0 + 1;
if ( v0 > 11 )
flush_input((unsigned int)((char)(v0 + 1) / 25));
++v0;
if ( v2 > 99 )
{
colorize("@R\n\n\nGo away until you have something useful to do!\n\n\n@G");
my_exit(10LL);
}
}
else
{
v0 = 0;
}
v3 = (unsigned int)v1;
if ( strchr(aAc, v3) )
*(_BYTE *)(mybtmp + 118LL) = 1;
switch ( v1 )
{
case 5:
if ( *ouruser != *(_QWORD *)(msg + 3688LL * curr + 264) )
{
if ( (*(_BYTE *)(ouruser + 20LL) & 0x40) != 0 )
{
puts("Enter Sysop message\n\nNOTE: You are entering this message as Sysop!\n");
sysopflags |= 2u;
}
goto LABEL_39;
}
printf("Enter Forum Moderator message\n\nAre you sure you want to enter a message as Forum Moderator? (Y/N) -> ");
if ( (unsigned int)yesno(0xFFFFFFFFLL) )
{
sysopflags |= 8u;
LABEL_39:
if ( (*(_BYTE *)(ouruser + 20LL) & 4) == 0 )
goto LABEL_48;
LABEL_44:
if ( curr == 1 || curr > 4 )
{
help("newuseraccess", 0);
}
else
{
LABEL_46:
if ( v1 == 69 )
{
puts("Upload message\n");
LABEL_48:
v9[0] = 0;
v4 = 2LL;
goto LABEL_49;
}
if ( v1 != 101 )
goto LABEL_48;
puts("Enter message\n");
v9[0] = 0;
v4 = 0LL;
LABEL_49:
entermessage((unsigned int)curr, v9, v4);
sysopflags &= 0xF5u;
}
}
goto LABEL_6;
case 23:
if ( client )
clientwho();
else
v1 = client;
goto LABEL_6;
case 24:
old_express();
goto LABEL_6;
case 34:
puts("Quote X messages to Sysop");
v9[0] = 0;
entermessage(0xFFFFFFFFLL, v9, 0xFFFFFFFFLL);
goto LABEL_6;
case 35:
readroom(35LL);
goto LABEL_6;
case 37:
if ( (*(_DWORD *)(ouruser + 20LL) & 0x210020) == 0x200000 )
{
if ( *(_BYTE *)(mybtmp + 112LL) )
{
if ( *(_BYTE *)(mybtmp + 113LL) )
{
*(_BYTE *)(mybtmp + 113LL) = 0;
goto LABEL_94;
}
puts("\n\nYou can't enable yourself as a guide while your X's are disabled.");
}
else
{
v8 = *(_BYTE *)(mybtmp + 113LL) == 0;
*(_BYTE *)(mybtmp + 113LL) = v8;
if ( v8 )
puts("\n\nYou are now marked as being available to help others.");
else
LABEL_94:
puts("\n\nYou are no longer marked as being available to help others.");
}
}
else
{
v1 = 0;
}
break;
case 45:
readroom(45LL);
goto LABEL_6;
case 47:
case 63:
if ( guest )
help("guestforumlevel", 0);
else
help("doccmd", 0);
goto LABEL_6;
case 64:
puts("Sysops, programmers, and forum moderators");
more("/bbs/etc/aidelist", 0LL);
goto LABEL_6;
case 65:
printf("Sysop commands (%s)\n", (const char *)(msg + 3688LL * curr + 216));
aide_menu();
goto LABEL_6;
case 66:
case 82:
puts("Read Reverse");
readroom(82LL);
v1 = 82;
goto LABEL_6;
case 67:
puts("Change config");
change_setup(0LL);
goto LABEL_6;
case 68:
puts("Debug");
debug();
goto LABEL_6;
case 69:
case 101:
if ( (*(_BYTE *)(ouruser + 20LL) & 4) != 0 )
goto LABEL_44;
goto LABEL_46;
case 70:
puts("Read Forward");
readroom(70LL);
goto LABEL_6;
case 71:
goto LABEL_54;
case 72:
puts("Help!");
help("topics", 1);
goto LABEL_6;
case 73:
puts("Forum Info");
readdesc();
goto LABEL_6;
case 74:
printf("Jump to ");
v5 = curr;
if ( (unsigned int)findroom() == 1 )
{
*(_BYTE *)(mybtmp + 118LL) = 0;
v6 = curr;
curr = v5;
updatels(&v10);
curr = v6;
openroom();
storeug(v12, &v11);
}
goto LABEL_6;
case 75:
puts("Known forums and zapped list");
knrooms();
goto LABEL_6;
case 76:
dologout();
goto LABEL_6;
case 78:
if ( *(_QWORD *)(ouruser + 8LL * curr + 1184) >= *(_QWORD *)(room + 1264LL) )
{
LABEL_54:
printf("Goto ");
updatels(&v10);
nextroom();
openroom();
storeug(v12, &v11);
}
else
{
puts("Read New");
readroom(78LL);
}
goto LABEL_6;
case 79:
puts("Read Old messages reverse");
readroom(79LL);
goto LABEL_6;
case 80:
case 112:
profile_user(v1 == 80);
goto LABEL_6;
case 81:
case 113:
get_syself_help((unsigned int)v1);
goto LABEL_6;
case 83:
printf("Skip %s to ", (const char *)(msg + 3688LL * curr + 216));
v7 = curr;
if ( (unsigned int)findroom() == 1 )
{
*(_BYTE *)(mybtmp + 118LL) = 0;
*((_BYTE *)&skipping + (v7 >> 3)) |= 1 << (v7 & 7);
openroom();
v11 = *(_QWORD *)(ouruser + 8LL * curr + 1184);
}
goto LABEL_6;
case 84:
printdate("Time\n\n%s", (const char *)v3);
goto LABEL_6;
case 85:
puts("Ungoto");
ungoto((unsigned int)v10, v12, &v11);
goto LABEL_6;
case 86:
puts("Validate new users");
validate_users(1LL);
goto LABEL_6;
case 87:
show_online(0LL);
goto LABEL_6;
case 88:
change_express(1LL);
goto LABEL_6;
case 89:
case 121:
if ( (unsigned int)wanttoyell(v1) )
entermessage(0xFFFFFFFFLL, &unk_1054, 2 * (unsigned int)(v1 != 121));
goto LABEL_6;
case 90:
puts("Zap forum");
if ( (unsigned int)forgetroom() )
{
nextroom();
openroom();
v11 = *(_QWORD *)(ouruser + 8LL * curr + 1184);
}
goto LABEL_6;
case 115:
printf("Skip %s\n", (const char *)(msg + 3688LL * curr + 216));
*((_BYTE *)&skipping + ((__int16)curr >> 3)) |= 1 << (curr & 7);
nextroom();
openroom();
v11 = *(_QWORD *)(ouruser + 8LL * curr + 1184);
goto LABEL_6;
case 118:
v1 = 0;
goto LABEL_6;
case 119:
show_online(3LL);
goto LABEL_6;
case 120:
express();
goto LABEL_6;
default:
goto LABEL_6;
}
}
}

canonical_decompiled_code:
void func5()
{
char v0; // bp
char v1; // bl
char v2; // r12
unsigned __int64 v3; // rsi
__int64 v4; // rdx
__int16 v5; // r12
__int16 v6; // r13
__int16 v7; // r12
bool v8; // zf
char v9[30]; // [rsp+0h] [rbp-158h] BYREF
__int16 v10; // [rsp+1Eh] [rbp-13Ah] BYREF
__int64 v11; // [rsp+20h] [rbp-138h] BYREF
char v12[8]; // [rsp+28h] [rbp-130h] BYREF
char buf[296]; // [rsp+30h] [rbp-128h] BYREF

v11 = -1LL;
v10 = -1;
room = &sroom;
setvbuf(stdin, buf, 0, 0x100uLL);
setvbuf(stdout, &stdoutbuf, 0, 0x3C0uLL);
init_system();
putchar(255);
putchar(251);
putchar(3);
write(1, &unk_10F8, 6uLL);
write(1, &unk_10FF, 3uLL);
reserve_slot();
do_login();
colorize("\n@G");
curr = 0;
func2();
openroom();
storeug(v12, &v11);
readroom(78LL);
v0 = 0;
v1 = 78;
while ( 1 )
{
while ( 1 )
{
LABEL_6:
if ( *(char *)(ouruser + curr + 784LL) < 0 || !*(_BYTE *)(msg + 3688LL * curr + 3896) )
{
curr = 0;
openroom();
storeug(v12, &v11);
}
if ( v1 )
colorize("\n@Y%s>@G ", (const char *)(msg + 3688LL * curr + 216));
checkx(0LL);
if ( (*(_BYTE *)(ouruser + 20LL) & 0x10) != 0 )
{
v1 = get_single_quiet(&unk_D70);
}
else if ( (*(_BYTE *)(ouruser + 23LL) & 2) != 0 )
{
v1 = get_single_quiet(&unk_DA0);
}
else if ( *ouruser == *(_QWORD *)(msg + 3688LL * curr + 264) && (*(_BYTE *)(ouruser + 22LL) & 1) == 0 )
{
v1 = get_single_quiet(&unk_DD0);
}
else
{
v1 = get_single_quiet(&unk_E00);
}
if ( v1 == 32 )
v1 = 78;
if ( !guest || strchr("BFGHIJKLNOpPRsSTUwWyY/?#-", v1) )
break;
colorize("\n\n@RThe Guest user cannot do that.@G\n");
}
if ( curr )
{
v0 = 0;
}
else if ( strchr(aDgnqstu, v1) )
{
v2 = v0 + 1;
if ( v0 > 11 )
flush_input((unsigned int)((char)(v0 + 1) / 25));
++v0;
if ( v2 > 99 )
{
colorize("@R\n\n\nGo away until you have something useful to do!\n\n\n@G");
my_exit(10LL);
}
}
else
{
v0 = 0;
}
v3 = (unsigned int)v1;
if ( strchr(aAc, v3) )
*(_BYTE *)(mybtmp + 118LL) = 1;
switch ( v1 )
{
case 5:
if ( *ouruser != *(_QWORD *)(msg + 3688LL * curr + 264) )
{
if ( (*(_BYTE *)(ouruser + 20LL) & 0x40) != 0 )
{
puts("Enter Sysop message\n\nNOTE: You are entering this message as Sysop!\n");
sysopflags |= 2u;
}
goto LABEL_39;
}
printf("Enter Forum Moderator message\n\nAre you sure you want to enter a message as Forum Moderator? (Y/N) -> ");
if ( (unsigned int)yesno(0xFFFFFFFFLL) )
{
sysopflags |= 8u;
LABEL_39:
if ( (*(_BYTE *)(ouruser + 20LL) & 4) == 0 )
goto LABEL_48;
LABEL_44:
if ( curr == 1 || curr > 4 )
{
func1("newuseraccess", 0);
}
else
{
LABEL_46:
if ( v1 == 69 )
{
puts("Upload message\n");
LABEL_48:
v9[0] = 0;
v4 = 2LL;
goto LABEL_49;
}
if ( v1 != 101 )
goto LABEL_48;
puts("Enter message\n");
v9[0] = 0;
v4 = 0LL;
LABEL_49:
entermessage((unsigned int)curr, v9, v4);
sysopflags &= 0xF5u;
}
}
goto LABEL_6;
case 23:
if ( client )
clientwho();
else
v1 = client;
goto LABEL_6;
case 24:
old_express();
goto LABEL_6;
case 34:
puts("Quote X messages to Sysop");
v9[0] = 0;
entermessage(0xFFFFFFFFLL, v9, 0xFFFFFFFFLL);
goto LABEL_6;
case 35:
readroom(35LL);
goto LABEL_6;
case 37:
if ( (*(_DWORD *)(ouruser + 20LL) & 0x210020) == 0x200000 )
{
if ( *(_BYTE *)(mybtmp + 112LL) )
{
if ( *(_BYTE *)(mybtmp + 113LL) )
{
*(_BYTE *)(mybtmp + 113LL) = 0;
goto LABEL_94;
}
puts("\n\nYou can't enable yourself as a guide while your X's are disabled.");
}
else
{
v8 = *(_BYTE *)(mybtmp + 113LL) == 0;
*(_BYTE *)(mybtmp + 113LL) = v8;
if ( v8 )
puts("\n\nYou are now marked as being available to help others.");
else
LABEL_94:
puts("\n\nYou are no longer marked as being available to help others.");
}
}
else
{
v1 = 0;
}
break;
case 45:
readroom(45LL);
goto LABEL_6;
case 47:
case 63:
if ( guest )
func1("guestforumlevel", 0);
else
func1("doccmd", 0);
goto LABEL_6;
case 64:
puts("Sysops, programmers, and forum moderators");
more("/bbs/etc/aidelist", 0LL);
goto LABEL_6;
case 65:
printf("Sysop commands (%s)\n", (const char *)(msg + 3688LL * curr + 216));
aide_menu();
goto LABEL_6;
case 66:
case 82:
puts("Read Reverse");
readroom(82LL);
v1 = 82;
goto LABEL_6;
case 67:
puts("Change config");
change_setup(0LL);
goto LABEL_6;
case 68:
puts("Debug");
debug();
goto LABEL_6;
case 69:
case 101:
if ( (*(_BYTE *)(ouruser + 20LL) & 4) != 0 )
goto LABEL_44;
goto LABEL_46;
case 70:
puts("Read Forward");
readroom(70LL);
goto LABEL_6;
case 71:
goto LABEL_54;
case 72:
puts("Help!");
func1("topics", 1);
goto LABEL_6;
case 73:
puts("Forum Info");
readdesc();
goto LABEL_6;
case 74:
printf("Jump to ");
v5 = curr;
if ( (unsigned int)findroom() == 1 )
{
*(_BYTE *)(mybtmp + 118LL) = 0;
v6 = curr;
curr = v5;
updatels(&v10);
curr = v6;
openroom();
storeug(v12, &v11);
}
goto LABEL_6;
case 75:
puts("Known forums and zapped list");
knrooms();
goto LABEL_6;
case 76:
func4();
goto LABEL_6;
case 78:
if ( *(_QWORD *)(ouruser + 8LL * curr + 1184) >= *(_QWORD *)(room + 1264LL) )
{
LABEL_54:
printf("Goto ");
updatels(&v10);
nextroom();
openroom();
storeug(v12, &v11);
}
else
{
puts("Read New");
readroom(78LL);
}
goto LABEL_6;
case 79:
puts("Read Old messages reverse");
readroom(79LL);
goto LABEL_6;
case 80:
case 112:
profile_user(v1 == 80);
goto LABEL_6;
case 81:
case 113:
get_syself_help((unsigned int)v1);
goto LABEL_6;
case 83:
printf("Skip %s to ", (const char *)(msg + 3688LL * curr + 216));
v7 = curr;
if ( (unsigned int)findroom() == 1 )
{
*(_BYTE *)(mybtmp + 118LL) = 0;
*((_BYTE *)&skipping + (v7 >> 3)) |= 1 << (v7 & 7);
openroom();
v11 = *(_QWORD *)(ouruser + 8LL * curr + 1184);
}
goto LABEL_6;
case 84:
printdate("Time\n\n%s", (const char *)v3);
goto LABEL_6;
case 85:
puts("Ungoto");
ungoto((unsigned int)v10, v12, &v11);
goto LABEL_6;
case 86:
puts("Validate new users");
validate_users(1LL);
goto LABEL_6;
case 87:
show_online(0LL);
goto LABEL_6;
case 88:
change_express(1LL);
goto LABEL_6;
case 89:
case 121:
if ( (unsigned int)func3(v1) )
entermessage(0xFFFFFFFFLL, &unk_1054, 2 * (unsigned int)(v1 != 121));
goto LABEL_6;
case 90:
puts("Zap forum");
if ( (unsigned int)forgetroom() )
{
nextroom();
openroom();
v11 = *(_QWORD *)(ouruser + 8LL * curr + 1184);
}
goto LABEL_6;
case 115:
printf("Skip %s\n", (const char *)(msg + 3688LL * curr + 216));
*((_BYTE *)&skipping + ((__int16)curr >> 3)) |= 1 << (curr & 7);
nextroom();
openroom();
v11 = *(_QWORD *)(ouruser + 8LL * curr + 1184);
goto LABEL_6;
case 118:
v1 = 0;
goto LABEL_6;
case 119:
show_online(3LL);
goto LABEL_6;
case 120:
express();
goto LABEL_6;
default:
goto LABEL_6;
}
}
}

original_code:
void
bbsstart(void)
{
unsigned char stdinbuf[256];
long uglastmsg;
long ugtemp = (-1L);
short prev_rm = (-1L);
char cit_cmd;
char bueller = 0;
  room = &sroom;
  setvbuf(stdin, (char *)stdinbuf, 0, 256);
  setvbuf(stdout, (char *)stdoutbuf, 0, 960);
  init_system();
  putchar(255); putchar(251); putchar(3);
  write(1,"\377\375\042\377\373\001",6);
  write(1,"\377\375\037",3);
  reserve_slot();
  do_login();
  colorize("\n@G");
  curr = 0;
  inituser();
  openroom();
  storeug(&uglastmsg, &ugtemp);
  cit_cmd = 'N';
  readroom(cit_cmd);
  for(;;)
  {
    if (ouruser->generation[curr] < 0 || !msg->room[curr].flags)
    {
      curr = 0;
      openroom();
      storeug(&uglastmsg, &ugtemp);
    }
    if (cit_cmd)
      colorize("\n@Y%s>@G ", msg->room[curr].name);
    checkx(0);
    if (ouruser->f_prog)
      cit_cmd = get_single_quiet("ABCD\005eEFGHIJKLNOpPqQRsSTUvVwWxX\027\030yYZ /?#%@-\"");
    else if (ouruser->f_aide)
      cit_cmd = get_single_quiet("ABC\005eEFGHIJKLNOpPqQRsSTUvVwWxX\027\030yYZ /?#%@-\"");
    else if (ouruser->usernum == msg->room[curr].roomaide && !ouruser->f_twit)
      cit_cmd = get_single_quiet("ABC\005eEFGHIJKLNOpPqQRsSTUwWxX\027\030yYZ /?#%-\"");
    else
      cit_cmd = get_single_quiet("BCeEFGHIJKLNOpPqQRsSTUwWxX\027\030yYZ /?#%-\"");
    if (cit_cmd == 32)
      cit_cmd = 'N';
    if (guest && !strchr("BFGHIJKLNOpPRsSTUwWyY/?#-", cit_cmd))
    {
      colorize("\n\n@RThe Guest user cannot do that.@G\n");
      continue;
    }
    if (curr == 0 && strchr("DGNqsTU\027X\030Z% ", cit_cmd))
    {
      if (bueller++ >= 12)
        flush_input(bueller / 25);
      if (bueller >= 100)
      {
        colorize("@R\n\n\nGo away until you have something useful to do!\n\n\n@G");
        my_exit(10);
      }
    }
    else
      bueller = 0;
    if (strchr("AC\005eEHJpPQSvVx\030yYZ#-\"", cit_cmd))
      mybtmp->nox = 1;
    switch (cit_cmd)
    {
      case 'A':
 printf("Sysop commands (%s)\n", msg->room[curr].name);
 aide_menu();
 break;
      case 'R':
      case 'B':
 cit_cmd = 'R';
 printf("Read Reverse\n");
 readroom(cit_cmd);
 break;
      case 'C':
        printf("Change config\n");
        change_setup(((void *)0));
 break;
      case 'D':
 printf("Debug\n");
 debug();
 break;
      case '\005':
 if (ouruser->usernum == msg->room[curr].roomaide)
 {
   printf("Enter Forum Moderator message\n\nAre you sure you want to enter a message as Forum Moderator? (Y/N) -> ");
   if (!yesno(-1))
     break;
   sysopflags |= 8;
 }
 else if (ouruser->f_admin)
        {
   printf("Enter Sysop message\n\nNOTE: You are entering this message as Sysop!\n\n");
   sysopflags |= 2;
        }
      case 'e':
      case 'E':
 {
   char work[20];
   if (ouruser->f_newbie && (curr == 1 || curr > 4))
     help("newuseraccess", 0);
   else
   {
     if (cit_cmd == 'E')
       printf("Upload message\n\n");
     else if (cit_cmd == 'e')
       printf("Enter message\n\n");
     *work = 0;
     (void)entermessage(curr, work, cit_cmd == 'e' ? 0 : 2);
     sysopflags &= ~(2 | 8);
   }
 }
 break;
      case 'F':
 printf("Read Forward\n");
 readroom(cit_cmd);
 break;
      case 'G':
 printf("Goto ");
 updatels(&prev_rm);
 nextroom();
 openroom();
 storeug(&uglastmsg, &ugtemp);
 break;
      case 'H':
 printf("Help!\n");
 help("topics", 1);
 break;
      case 'q':
      case 'Q':
        get_syself_help(cit_cmd);
        break;
      case 'I':
 printf("Forum Info\n");
 readdesc();
 break;
      case 'J':
 {
   int old_rm;
   printf("Jump to ");
   old_rm = curr;
   if (findroom() == 1)
   {
     int save_rm;
            mybtmp->nox = 0;
     save_rm = curr;
     curr = old_rm;
     updatels(&prev_rm);
     curr = save_rm;
     openroom();
     storeug(&uglastmsg, &ugtemp);
   }
 }
 break;
      case 'K':
 printf("Known forums and zapped list\n");
 knrooms();
 break;
      case 'L':
        dologout();
 break;
      case 'N':
 if (ouruser->lastseen[curr] < room->num[150 - 1])
 {
   printf("Read New\n");
   readroom(cit_cmd);
 }
 else
 {
   printf("Goto ");
   updatels(&prev_rm);
   nextroom();
   openroom();
   storeug(&uglastmsg, &ugtemp);
 }
 break;
      case 'O':
 printf("Read Old messages reverse\n");
 readroom(cit_cmd);
 break;
      case 'p':
      case 'P':
 profile_user(cit_cmd == 'P');
 break;
      case 's':
 printf("Skip %s\n", msg->room[curr].name);
 skipping[curr >> 3] |= 1 << (curr & 7);
 nextroom();
 openroom();
 ugtemp = ouruser->lastseen[curr];
 break;
      case 'S':
 {
   int old_rm;
   printf("Skip %s to ", msg->room[curr].name);
   old_rm = curr;
   if (findroom() == 1)
   {
            mybtmp->nox = 0;
     skipping[old_rm >> 3] |= 1 << (old_rm & 7);
     openroom();
     ugtemp = ouruser->lastseen[curr];
   }
 }
 break;
      case 'T':
 printdate("Time\n\n%s");
 break;
      case 'U':
 printf("Ungoto\n");
 ungoto(prev_rm, &uglastmsg, &ugtemp);
 break;
      case 'v':
 cit_cmd = 0;
 break;
      case 'V':
 printf("Validate new users\n");
 validate_users(1);
 break;
      case '\027':
 if (client)
   clientwho();
 else
   cit_cmd = 0;
 break;
      case 'w':
 show_online(3);
 break;
      case 'W':
 show_online(0);
 break;
      case 'x':
 express();
 break;
      case 'X':
 change_express(1);
 break;
      case 24:
 old_express();
 break;
      case 'y':
      case 'Y':
        if (!wanttoyell(cit_cmd))
          break;
 (void)entermessage(-1, "", cit_cmd == 'y' ? 0 : 2);
 break;
      case 'Z':
 printf("Zap forum\n");
 if (forgetroom())
        {
   nextroom();
   openroom();
   ugtemp = ouruser->lastseen[curr];
        }
 break;
      case '?':
      case '/':
 if (guest)
   help("guestforumlevel", 0);
 else
   help("doccmd", 0);
 break;
      case '#':
 readroom(cit_cmd);
 break;
      case '%':
 if (ouruser->f_elf && !ouruser->f_restricted && !ouruser->f_twit)
          if (mybtmp->xstat && !mybtmp->elf)
            printf("\n\nYou can't enable yourself as a guide while your X's are disabled.\n");
   else if ((mybtmp->elf = !mybtmp->elf))
     printf("\n\nYou are now marked as being available to help others.\n");
   else
     printf("\n\nYou are no longer marked as being available to help others.\n");
 else
   cit_cmd = 0;
 break;
      case '-':
 readroom(cit_cmd);
 break;
      case '@':
 printf("Sysops, programmers, and forum moderators\n");
 more("/bbs/""etc/aidelist", 0);
 break;
      case '"':
 {
   char work[20];
   printf("Quote X messages to Sysop\n");
          *work = 0;
          (void)entermessage(-1, work, -1);
 }
 break;
      default:
 break;
    }
  }
}

canonical_original_code:
void bbsstart()
{
unsigned char stdinbuf[256];
long uglastmsg;
long ugtemp = (-1L);
short prev_rm = (-1L);
char cit_cmd;
char bueller = 0;
  room = &sroom;
  setvbuf(stdin, (char *)stdinbuf, 0, 256);
  setvbuf(stdout, (char *)stdoutbuf, 0, 960);
  init_system();
  putchar(255); putchar(251); putchar(3);
  write(1,"\377\375\042\377\373\001",6);
  write(1,"\377\375\037",3);
  reserve_slot();
  do_login();
  colorize("\n@G");
  curr = 0;
  inituser();
  openroom();
  storeug(&uglastmsg, &ugtemp);
  cit_cmd = 'N';
  readroom(cit_cmd);
  for(;;)
  {
    if (ouruser->generation[curr] < 0 || !msg->room[curr].flags)
    {
      curr = 0;
      openroom();
      storeug(&uglastmsg, &ugtemp);
    }
    if (cit_cmd)
      colorize("\n@Y%s>@G ", msg->room[curr].name);
    checkx(0);
    if (ouruser->f_prog)
      cit_cmd = get_single_quiet("ABCD\005eEFGHIJKLNOpPqQRsSTUvVwWxX\027\030yYZ /?#%@-\"");
    else if (ouruser->f_aide)
      cit_cmd = get_single_quiet("ABC\005eEFGHIJKLNOpPqQRsSTUvVwWxX\027\030yYZ /?#%@-\"");
    else if (ouruser->usernum == msg->room[curr].roomaide && !ouruser->f_twit)
      cit_cmd = get_single_quiet("ABC\005eEFGHIJKLNOpPqQRsSTUwWxX\027\030yYZ /?#%-\"");
    else
      cit_cmd = get_single_quiet("BCeEFGHIJKLNOpPqQRsSTUwWxX\027\030yYZ /?#%-\"");
    if (cit_cmd == 32)
      cit_cmd = 'N';
    if (guest && !strchr("BFGHIJKLNOpPRsSTUwWyY/?#-", cit_cmd))
    {
      colorize("\n\n@RThe Guest user cannot do that.@G\n");
      continue;
    }
    if (curr == 0 && strchr("DGNqsTU\027X\030Z% ", cit_cmd))
    {
      if (bueller++ >= 12)
        flush_input(bueller / 25);
      if (bueller >= 100)
      {
        colorize("@R\n\n\nGo away until you have something useful to do!\n\n\n@G");
        my_exit(10);
      }
    }
    else
      bueller = 0;
    if (strchr("AC\005eEHJpPQSvVx\030yYZ#-\"", cit_cmd))
      mybtmp->nox = 1;
    switch (cit_cmd)
    {
      case 'A':
 printf("Sysop commands (%s)\n", msg->room[curr].name);
 aide_menu();
 break;
      case 'R':
      case 'B':
 cit_cmd = 'R';
 printf("Read Reverse\n");
 readroom(cit_cmd);
 break;
      case 'C':
        printf("Change config\n");
        change_setup(((void *)0));
 break;
      case 'D':
 printf("Debug\n");
 debug();
 break;
      case '\005':
 if (ouruser->usernum == msg->room[curr].roomaide)
 {
   printf("Enter Forum Moderator message\n\nAre you sure you want to enter a message as Forum Moderator? (Y/N) -> ");
   if (!yesno(-1))
     break;
   sysopflags |= 8;
 }
 else if (ouruser->f_admin)
        {
   printf("Enter Sysop message\n\nNOTE: You are entering this message as Sysop!\n\n");
   sysopflags |= 2;
        }
      case 'e':
      case 'E':
 {
   char work[20];
   if (ouruser->f_newbie && (curr == 1 || curr > 4))
     help("newuseraccess", 0);
   else
   {
     if (cit_cmd == 'E')
       printf("Upload message\n\n");
     else if (cit_cmd == 'e')
       printf("Enter message\n\n");
     *work = 0;
     (void)entermessage(curr, work, cit_cmd == 'e' ? 0 : 2);
     sysopflags &= ~(2 | 8);
   }
 }
 break;
      case 'F':
 printf("Read Forward\n");
 readroom(cit_cmd);
 break;
      case 'G':
 printf("Goto ");
 updatels(&prev_rm);
 nextroom();
 openroom();
 storeug(&uglastmsg, &ugtemp);
 break;
      case 'H':
 printf("Help!\n");
 help("topics", 1);
 break;
      case 'q':
      case 'Q':
        get_syself_help(cit_cmd);
        break;
      case 'I':
 printf("Forum Info\n");
 readdesc();
 break;
      case 'J':
 {
   int old_rm;
   printf("Jump to ");
   old_rm = curr;
   if (findroom() == 1)
   {
     int save_rm;
            mybtmp->nox = 0;
     save_rm = curr;
     curr = old_rm;
     updatels(&prev_rm);
     curr = save_rm;
     openroom();
     storeug(&uglastmsg, &ugtemp);
   }
 }
 break;
      case 'K':
 printf("Known forums and zapped list\n");
 knrooms();
 break;
      case 'L':
        dologout();
 break;
      case 'N':
 if (ouruser->lastseen[curr] < room->num[150 - 1])
 {
   printf("Read New\n");
   readroom(cit_cmd);
 }
 else
 {
   printf("Goto ");
   updatels(&prev_rm);
   nextroom();
   openroom();
   storeug(&uglastmsg, &ugtemp);
 }
 break;
      case 'O':
 printf("Read Old messages reverse\n");
 readroom(cit_cmd);
 break;
      case 'p':
      case 'P':
 profile_user(cit_cmd == 'P');
 break;
      case 's':
 printf("Skip %s\n", msg->room[curr].name);
 skipping[curr >> 3] |= 1 << (curr & 7);
 nextroom();
 openroom();
 ugtemp = ouruser->lastseen[curr];
 break;
      case 'S':
 {
   int old_rm;
   printf("Skip %s to ", msg->room[curr].name);
   old_rm = curr;
   if (findroom() == 1)
   {
            mybtmp->nox = 0;
     skipping[old_rm >> 3] |= 1 << (old_rm & 7);
     openroom();
     ugtemp = ouruser->lastseen[curr];
   }
 }
 break;
      case 'T':
 printdate("Time\n\n%s");
 break;
      case 'U':
 printf("Ungoto\n");
 ungoto(prev_rm, &uglastmsg, &ugtemp);
 break;
      case 'v':
 cit_cmd = 0;
 break;
      case 'V':
 printf("Validate new users\n");
 validate_users(1);
 break;
      case '\027':
 if (client)
   clientwho();
 else
   cit_cmd = 0;
 break;
      case 'w':
 show_online(3);
 break;
      case 'W':
 show_online(0);
 break;
      case 'x':
 express();
 break;
      case 'X':
 change_express(1);
 break;
      case 24:
 old_express();
 break;
      case 'y':
      case 'Y':
        if (!wanttoyell(cit_cmd))
          break;
 (void)entermessage(-1, "", cit_cmd == 'y' ? 0 : 2);
 break;
      case 'Z':
 printf("Zap forum\n");
 if (forgetroom())
        {
   nextroom();
   openroom();
   ugtemp = ouruser->lastseen[curr];
        }
 break;
      case '?':
      case '/':
 if (guest)
   help("guestforumlevel", 0);
 else
   help("doccmd", 0);
 break;
      case '#':
 readroom(cit_cmd);
 break;
      case '%':
 if (ouruser->f_elf && !ouruser->f_restricted && !ouruser->f_twit)
          if (mybtmp->xstat && !mybtmp->elf)
            printf("\n\nYou can't enable yourself as a guide while your X's are disabled.\n");
   else if ((mybtmp->elf = !mybtmp->elf))
     printf("\n\nYou are now marked as being available to help others.\n");
   else
     printf("\n\nYou are no longer marked as being available to help others.\n");
 else
   cit_cmd = 0;
 break;
      case '-':
 readroom(cit_cmd);
 break;
      case '@':
 printf("Sysops, programmers, and forum moderators\n");
 more("/bbs/""etc/aidelist", 0);
 break;
      case '"':
 {
   char work[20];
   printf("Quote X messages to Sysop\n");
          *work = 0;
          (void)entermessage(-1, work, -1);
 }
 break;
      default:
 break;
    }
  }
}

variable_types:
stdinbuf
unsigned char [256]

variable_types: uglastmsg long

variable_types: ugtemp long

variable_types: bueller char

variable_types:
work
char [20]


bbssync

decompiled_code:
__int64 __fastcall bbssync(int a1)
{
__int64 i; // rbx
_QWORD *v2; // rbx
time_t v3; // rax
struct tm *v4; // rax
_QWORD *v5; // rbx
time_t v6; // rax
struct tm *v7; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( fork() )
exit(0);
close(0);
close(1);
close(2);
setsid();
sysv_signal(17, handler);
if ( !a1 )
{
LABEL_7:
nice(-20);
nice(-20);
while ( 1 )
{
do
{
v2 = msg;
v3 = time(0LL);
v2[23] = v3;
timer = v3;
v4 = localtime(&timer);
mysleep((unsigned int)(60 - v4->tm_sec));
v5 = msg;
v6 = time(0LL);
v5[23] = v6;
timer = v6;
v7 = localtime(&timer);
}
while ( v7->tm_min != 15 * (v7->tm_min / 15) );
msync(msgstart, 0xEE6C000uLL, 1);
msync(msg, 0xC3C88uLL, 1);
}
}
bzero(bigbtmp, 0x9BD58uLL);
for ( i = 0LL; i != 112; i += 16LL )
msem_init((char *)msg + i, 0LL);
if ( fork() )
{
if ( fork() )
goto LABEL_7;
setsid();
mysleep(60LL);
execl("/bbs/bin/bbs", "/bbs/bin/bbs", "-q", 0LL);
result = 3LL;
}
else
{
setsid();
execl("/bbs/bin/bbs", "/bbs/bin/bbs", &unk_1CD, 0LL);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 i; // rbx
_QWORD *v2; // rbx
time_t v3; // rax
struct tm *v4; // rax
_QWORD *v5; // rbx
time_t v6; // rax
struct tm *v7; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( fork() )
exit(0);
close(0);
close(1);
close(2);
setsid();
sysv_signal(17, handler);
if ( !a1 )
{
LABEL_7:
nice(-20);
nice(-20);
while ( 1 )
{
do
{
v2 = msg;
v3 = time(0LL);
v2[23] = v3;
timer = v3;
v4 = localtime(&timer);
mysleep((unsigned int)(60 - v4->tm_sec));
v5 = msg;
v6 = time(0LL);
v5[23] = v6;
timer = v6;
v7 = localtime(&timer);
}
while ( v7->tm_min != 15 * (v7->tm_min / 15) );
msync(msgstart, 0xEE6C000uLL, 1);
msync(msg, 0xC3C88uLL, 1);
}
}
bzero(bigbtmp, 0x9BD58uLL);
for ( i = 0LL; i != 112; i += 16LL )
msem_init((char *)msg + i, 0LL);
if ( fork() )
{
if ( fork() )
goto LABEL_7;
setsid();
mysleep(60LL);
execl("/bbs/bin/bbs", "/bbs/bin/bbs", "-q", 0LL);
result = 3LL;
}
else
{
setsid();
execl("/bbs/bin/bbs", "/bbs/bin/bbs", &unk_1CD, 0LL);
result = 2LL;
}
return result;
}

original_code:
int
bbssync(int initialize)
{
  time_t t;
  register struct tm *tm;
  register int i;
  if (fork())
    _exit(0);
  close(0);
  close(1);
  close(2);
  setsid();
  sysv_signal(17, ((__sighandler_t) 1));
  if (initialize)
  {
    bzero((void *)bigbtmp, sizeof(struct bigbtmp));
    for (i = 0; i < 7; i++)
      msem_init(&msg->sem[i], 0);
    if (!fork())
    {
      setsid();
      execl("/bbs/bin/bbs", "/bbs/bin/bbs", "-f", 0);
      return(2);
    }
    if (!fork())
    {
      setsid();
      mysleep(60);
      execl("/bbs/bin/bbs", "/bbs/bin/bbs", "-q", 0);
      return(3);
    }
  }
  nice(-20);
  nice(-20);
  for (;;)
  {
    t = msg->t = time(0);
    tm = localtime(&t);
    mysleep(60 - tm->tm_sec);
    t = msg->t = time(0);
    tm = localtime(&t);
    if (tm->tm_min % 15 == 0)
    {
      msync((caddr_t)msgstart, 61036*4096, 1);
      msync((caddr_t)msg, sizeof(struct msg), 1);
    }
  }
}

canonical_original_code:
int bbssync(int initialize)
{
  long t;
  register struct tm *tm;
  register int i;
  if (fork())
    _exit(0);
  close(0);
  close(1);
  close(2);
  setsid();
  sysv_signal(17, ((void (*)(int)) 1));
  if (initialize)
  {
    bzero((void *)bigbtmp, sizeof(struct bigbtmp));
    for (i = 0; i < 7; i++)
      msem_init(&msg->sem[i], 0);
    if (!fork())
    {
      setsid();
      execl("/bbs/bin/bbs", "/bbs/bin/bbs", "-f", 0);
      return(2);
    }
    if (!fork())
    {
      setsid();
      mysleep(60);
      execl("/bbs/bin/bbs", "/bbs/bin/bbs", "-q", 0);
      return(3);
    }
  }
  nice(-20);
  nice(-20);
  for (;;)
  {
    t = msg->t = time(0);
    tm = localtime(&t);
    mysleep(60 - tm->tm_sec);
    t = msg->t = time(0);
    tm = localtime(&t);
    if (tm->tm_min % 15 == 0)
    {
      msync((char *)msgstart, 61036*4096, 1);
      msync((char *)msg, sizeof(struct msg), 1);
    }
  }
}

variable_types: initialize int

variable_types: t long

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


bbsbackup

decompiled_code:
char __fastcall bbsbackup(const char *a1)
{
bool v1; // cf
bool v2; // zf
const char *v4; // rdi
__int64 v5; // rcx
const char *v6; // rsi
char result; // al

v4 = "USERDATA";
v5 = 9LL;
v6 = a1;
do
{
if ( !v5 )
break;
v1 = *v6 < (unsigned int)*v4;
v2 = *v6++ == *v4++;
--v5;
}
while ( v2 );
if ( (!v1 && !v2) == v1 )
backupuserdata(v4, v6);
if ( !strcmp(a1, "MSGDATA") )
write(1, msg, 0xC3C88uLL);
v2 = strcmp(a1, "MSGMAIN") == 0;
result = !v2;
if ( v2 )
result = write(1, msgstart, 0xEE6C000uLL);
return result;
}

canonical_decompiled_code:
char __fastcall func0(const char *a1)
{
bool v1; // cf
bool v2; // zf
const char *v4; // rdi
__int64 v5; // rcx
const char *v6; // rsi
char result; // al

v4 = "USERDATA";
v5 = 9LL;
v6 = a1;
do
{
if ( !v5 )
break;
v1 = *v6 < (unsigned int)*v4;
v2 = *v6++ == *v4++;
--v5;
}
while ( v2 );
if ( (!v1 && !v2) == v1 )
backupuserdata(v4, v6);
if ( !strcmp(a1, "MSGDATA") )
write(1, msg, 0xC3C88uLL);
v2 = strcmp(a1, "MSGMAIN") == 0;
result = !v2;
if ( v2 )
result = write(1, msgstart, 0xEE6C000uLL);
return result;
}

original_code:
void
bbsbackup(register char *what)
{
  if (!strcmp(what, "USERDATA"))
    backupuserdata();
  if (!strcmp(what, "MSGDATA"))
    write(1, msg, sizeof(struct msg));
  if (!strcmp(what, "MSGMAIN"))
    write(1, msgstart, 250003456);
}

canonical_original_code:
void bbsbackup(char *what)
{
  if (!strcmp(what, "USERDATA"))
    backupuserdata();
  if (!strcmp(what, "MSGDATA"))
    write(1, msg, sizeof(struct msg));
  if (!strcmp(what, "MSGMAIN"))
    write(1, msgstart, 250003456);
}

variable_types:
what
char *


bbsupdate

decompiled_code:
int bbsupdate()
{
char *v0; // rax
__int64 v1; // rbx
__int64 v3[2]; // [rsp+8h] [rbp-10h] BYREF

setvbuf(stdout, &stdoutbuf, 0, 0x3C0uLL);
v0 = getusers(v3);
if ( !v0 )
{
puts("Error reading user files");
fflush(stdout);
exit(1);
}
v1 = (__int64)v0;
if ( (unsigned int)update_aides(v0, v3) )
{
puts("Error updating aide list");
fflush(stdout);
exit(1);
}
if ( (unsigned int)update_whoknows(v1, v3) )
{
puts("Error updating whoknowsroom lists");
fflush(stdout);
exit(1);
}
return fflush(stdout);
}

canonical_decompiled_code:
int func3()
{
char *v0; // rax
__int64 v1; // rbx
__int64 v3[2]; // [rsp+8h] [rbp-10h] BYREF

setvbuf(stdout, &stdoutbuf, 0, 0x3C0uLL);
v0 = func0(v3);
if ( !v0 )
{
puts("Error reading user files");
fflush(stdout);
exit(1);
}
v1 = (__int64)v0;
if ( (unsigned int)func1(v0, v3) )
{
puts("Error updating aide list");
fflush(stdout);
exit(1);
}
if ( (unsigned int)func2(v1, v3) )
{
puts("Error updating whoknowsroom lists");
fflush(stdout);
exit(1);
}
return fflush(stdout);
}

original_code:
void
bbsupdate(void)
{
struct userinfo *start;
long ucount;
  setvbuf(stdout, (char *)stdoutbuf, 0, 960);
  if (!(start = getusers(&ucount)))
  {
    printf("Error reading user files\n");
    fflush(stdout);
    _exit(1);
  }
  if (update_aides(start, &ucount))
  {
    printf("Error updating aide list\n");
    fflush(stdout);
    _exit(1);
  }
  if (update_whoknows(start, &ucount))
  {
    printf("Error updating whoknowsroom lists\n");
    fflush(stdout);
    _exit(1);
  }
  fflush(stdout);
}

canonical_original_code:
void bbsupdate()
{
struct userinfo *start;
long ucount;
  setvbuf(stdout, (char *)stdoutbuf, 0, 960);
  if (!(start = getusers(&ucount)))
  {
    printf("Error reading user files\n");
    fflush(stdout);
    _exit(1);
  }
  if (update_aides(start, &ucount))
  {
    printf("Error updating aide list\n");
    fflush(stdout);
    _exit(1);
  }
  if (update_whoknows(start, &ucount))
  {
    printf("Error updating whoknowsroom lists\n");
    fflush(stdout);
    _exit(1);
  }
  fflush(stdout);
}

variable_types: struct userinfo { long usernum; char name[-1]; char generation[200]; char forget[200]; unsigned int f_admin; unsigned int f_prog; unsigned int f_aide; unsigned int; } *

variable_types: ucount long


repo: ehayon/Perseus-II

decompiled_code:
void update_filter()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void update_filter(float g_x, float g_y, float g_z, float a_x, float a_y, float a_z, float m_x, float m_y, float m_z) {
}


nanotime

repo: eholk/RustGPU

decompiled_code:
__syscall_slong_t nanotime()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return v1.tv_nsec + 1000000000 * v1.tv_sec;
}

canonical_decompiled_code:
__syscall_slong_t func0()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(1, &v1);
return v1.tv_nsec + 1000000000 * v1.tv_sec;
}

original_code:
uint64_t nanotime() {
    uint64_t ns_per_s = 1000000000LL;
    struct timespec ts;
    clock_gettime(1, &ts);
    return (ts.tv_sec * ns_per_s + ts.tv_nsec);
}

canonical_original_code:
unsigned long nanotime() {
    unsigned long ns_per_s = 1000000000LL;
    struct timespec ts;
    clock_gettime(1, &ts);
    return (ts.tv_sec * ns_per_s + ts.tv_nsec);
}

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

return_type: unsigned long


decompiled_code:
double time_s()
{
__syscall_slong_t v0; // rax
double v1; // xmm0_8

v0 = nanotime();
if ( v0 < 0 )
v1 = (double)(int)(v0 & 1 | ((unsigned __int64)v0 >> 1)) + (double)(int)(v0 & 1 | ((unsigned __int64)v0 >> 1));
else
v1 = (double)(int)v0;
return v1 / 1000000000.0;
}

canonical_decompiled_code:
double func1()
{
__syscall_slong_t v0; // rax
double v1; // xmm0_8

v0 = func0();
if ( v0 < 0 )
v1 = (double)(int)(v0 & 1 | ((unsigned __int64)v0 >> 1)) + (double)(int)(v0 & 1 | ((unsigned __int64)v0 >> 1));
else
v1 = (double)(int)v0;
return v1 / 1000000000.0;
}

original_code:
double time_s() {
    return nanotime() / 1e9;
}

return_type: double


decompiled_code:
int __fastcall print_vector(double *a1, int a2)
{
double *v2; // rbx

putchar(91);
if ( a2 > 0 )
{
v2 = a1;
do
printf(" %f", *v2++);
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return puts(" ]");
}

canonical_decompiled_code:
int __fastcall func2(double *a1, int a2)
{
double *v2; // rbx

putchar(91);
if ( a2 > 0 )
{
v2 = a1;
do
printf(" %f", *v2++);
while ( v2 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return puts(" ]");
}

original_code:
void print_vector(double *x, int len) {
  printf("[");
  for(int i = 0; i < len; ++i) {
 printf(" %f", x[i]);
  }
  printf(" ]\n");
}

variable_types:
x
double *

variable_types: len int

variable_types: i int