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

state = 0;
if ( getenv("ROWS") )
{
v0 = getenv("ROWS");
result = atoi(v0);
rows = result;
if ( (_WORD)result )
{
if ( !client )
return result;
LABEL_6:
putchar(255);
result = putchar(172);
block = 1;
byte = 1;
return result;
}
}
result = 24;
rows = 24;
if ( client )
goto LABEL_6;
return result;
}

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

state = 0;
if ( getenv("ROWS") )
{
v0 = getenv("ROWS");
result = atoi(v0);
rows = result;
if ( (_WORD)result )
{
if ( !client )
return result;
LABEL_6:
putchar(255);
result = putchar(172);
block = 1;
byte = 1;
return result;
}
}
result = 24;
rows = 24;
if ( client )
goto LABEL_6;
return result;
}

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


colorize

decompiled_code:
int colorize(char *a1, ...)
{
char v1; // r12
char *v2; // r13
int i; // ebx
int v4; // eax
char *v5; // r12
gcc_va_list arg; // [rsp+8h] [rbp-520h] BYREF
char s[1072]; // [rsp+20h] [rbp-508h] BYREF

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

canonical_decompiled_code:
int func0(char *a1, ...)
{
char v1; // r12
char *v2; // r13
int i; // ebx
int v4; // eax
char *v5; // r12
gcc_va_list arg; // [rsp+8h] [rbp-520h] BYREF
char s[1072]; // [rsp+20h] [rbp-508h] BYREF

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

return_type: int


runbbs

decompiled_code:
int __fastcall runbbs(int fd, __int64 a2, int a3)
{
__pid_t v4; // eax
int v6; // er14
int *v7; // rax
unsigned int *v8; // r13
char *v9; // r12
int v10; // ebx
unsigned int v11; // eax
char *envp; // [rsp+8h] [rbp-A0h] BYREF
char v13; // [rsp+10h] [rbp-98h] BYREF
char *argv[4]; // [rsp+30h] [rbp-78h] BYREF
char s[88]; // [rsp+50h] [rbp-58h] BYREF

environ = (char **)&v13;
v4 = fork();
if ( v4 < 0 )
return puts("Out of processes, sorry.");
if ( !v4 )
{
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);
v6 = fcntl(fd, 4, 0LL);
v7 = _errno_location();
v8 = (unsigned int *)v7;
if ( v6 < 0 )
logfatal("fcntl: ", (unsigned int)*v7);
closelog();
dup2(fd, 0);
dup2(fd, 1);
close(fd);
printf(" show 0x%0lx\n", a2);
v9 = "_clientbbs";
snprintf(s, 0x28uLL, "%d.%d.%d.%d", (unsigned __int8)a2, BYTE1(a2), BYTE2(a2), BYTE3(a2));
if ( !a3 )
v9 = "_netbbs";
v10 = 4;
do
{
envp = 0LL;
argv[0] = v9;
argv[1] = s;
argv[2] = 0LL;
v11 = execve("/bbs/bin/bbs", argv, &envp);
printf("r is %d\n", v11);
fflush(stdout);
printf("errno is %d\n", *v8);
fflush(stdout);
fwrite("ERR\n", 1uLL, 4uLL, stderr);
fflush(stderr);
mysleep(5LL);
--v10;
}
while ( v10 );
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
int v6; // er14
int *v7; // rax
unsigned int *v8; // r13
char *v9; // r12
int v10; // ebx
unsigned int v11; // eax
char *envp; // [rsp+8h] [rbp-A0h] BYREF
char v13; // [rsp+10h] [rbp-98h] BYREF
char *argv[4]; // [rsp+30h] [rbp-78h] BYREF
char s[88]; // [rsp+50h] [rbp-58h] BYREF

environ = (char **)&v13;
v4 = fork();
if ( v4 < 0 )
return puts("Out of processes, sorry.");
if ( !v4 )
{
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);
v6 = fcntl(fd, 4, 0LL);
v7 = _errno_location();
v8 = (unsigned int *)v7;
if ( v6 < 0 )
logfatal("fcntl: ", (unsigned int)*v7);
closelog();
dup2(fd, 0);
dup2(fd, 1);
close(fd);
printf(" show 0x%0lx\n", a2);
v9 = "_clientbbs";
snprintf(s, 0x28uLL, "%d.%d.%d.%d", (unsigned __int8)a2, BYTE1(a2), BYTE2(a2), BYTE3(a2));
if ( !a3 )
v9 = "_netbbs";
v10 = 4;
do
{
envp = 0LL;
argv[0] = v9;
argv[1] = s;
argv[2] = 0LL;
v11 = execve("/bbs/bin/bbs", argv, &envp);
printf("r is %d\n", v11);
fflush(stdout);
printf("errno is %d\n", *v8);
fflush(stdout);
fwrite("ERR\n", 1uLL, 4uLL, stderr);
fflush(stderr);
mysleep(5LL);
--v10;
}
while ( v10 );
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 linger { int l_onoff; int l_linger; }

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

variable_types:
identname
char [16]

variable_types: fds int

variable_types:
p
char *

variable_types:
addrs
unsigned char *

variable_types:
envp
char *[]

variable_types:
argv
char *[]

variable_types: r int

return_type: void

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


openfiles

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

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

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

v1[0] = 638296;
bigbtmp = mymmap("/bbs/data/tmpdata", v1, 0LL);
if ( !bigbtmp )
return 0xFFFFFFFFLL;
v1[0] = 250003456;
msgstart = mymmap("/bbs/message/msgmain", v1, 0LL);
if ( !msgstart )
return 0xFFFFFFFFLL;
madvise(msgstart, v1[0], 1);
v1[0] = 801928;
msg = mymmap("/bbs/data/msgdata", v1, 0LL);
if ( !msg )
return 0xFFFFFFFFLL;
v1[0] = 0;
xmsg = mymmap("/bbs/data/xmsgdata", v1, 0LL);
if ( !xmsg )
return 0xFFFFFFFFLL;
madvise(xmsg, v1[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)
{
int v2; // edi
int v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

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

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

v2 = semfile;
if ( !semfile )
{
semfile = open("/bbs/data/msgdata", 2);
v2 = semfile;
if ( semfile < 0 )
{
errlog("open of MSGDATA for file locking failed somehow");
my_exit(0LL);
v2 = semfile;
}
}
v4 = 1;
v5 = 16LL * a2;
v6 = 16LL;
while ( 1 )
{
if ( fcntl(v2, 7, &v4) >= 0 )
return 0LL;
if ( *_errno_location() != 4 )
break;
v2 = semfile;
}
errlog("fcntl F_SETLKW error %d", 7LL);
my_exit(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


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

v3 = 2;
v4 = 16LL * a2;
v5 = 16LL;
return fcntl(semfile, 6, &v3);
}

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

v3 = 2;
v4 = 16LL * a2;
v5 = 16LL;
return fcntl(semfile, 6, &v3);
}

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 if ( v1[0] )
{
rows = v1[0];
}
else
{
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 if ( v1[0] )
{
rows = v1[0];
}
else
{
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)
{
int v1; // ebx
_QWORD *v2; // rax
__int64 v3; // rdx
__int64 result; // rax

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

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

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

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
__int64 v3; // rbx
int v4; // edi
char v5[32]; // [rsp+0h] [rbp-98h] BYREF
char s[120]; // [rsp+20h] [rbp-78h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, int a2)
{
__int64 result; // rax
__int64 v3; // rbx
int v4; // edi
char v5[32]; // [rsp+0h] [rbp-98h] BYREF
char s[120]; // [rsp+20h] [rbp-78h] BYREF

sprintf(s, "%s%s", "/bbs/help/", a1);
result = more(s, 1LL);
if ( a2 )
{
while ( 1 )
{
colorize("\n@YEnter help topic ->@G ");
result = get_string(&unk_12A4, 29LL, v5, 0xFFFFFFFFLL);
v3 = v5[0];
if ( !v5[0] )
break;
if ( !index(v5, 46) && !index(v5, 47) )
{
v5[0] = (*_ctype_toupper_loc())[v3];
sprintf(s, "%s%s", "/bbs/help/", v5);
v4 = open(s, 0);
if ( v4 < 0 )
{
colorize("\n@RTopic not found.@G");
}
else
{
close(v4);
more(s, 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 == 52 )
{
help("yell.voice.4", 0);
return 0LL;
}
if ( v2 == 89 )
{
putchar(10);
return 1LL;
}
goto LABEL_13;
}
if ( v2 != 49 )
{
if ( v2 == 50 )
{
help("yell.voice.2", 0);
return 0LL;
}
LABEL_13:
putchar(10);
return 0LL;
}
help("yell.voice.1", 0);
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 == 52 )
{
func1("yell.voice.4", 0);
return 0LL;
}
if ( v2 == 89 )
{
putchar(10);
return 1LL;
}
goto LABEL_13;
}
if ( v2 != 49 )
{
if ( v2 == 50 )
{
func1("yell.voice.2", 0);
return 0LL;
}
LABEL_13:
putchar(10);
return 0LL;
}
func1("yell.voice.1", 0);
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
__int64 v2; // rdx
__int64 v3; // rax
unsigned int v4; // er12
char v5; // r13
__int16 v6; // ax
__int64 v7; // rdx
__int16 v8; // r12
__int16 v9; // r12
__int16 v10; // r13
char v11; // al
char v12; // dl
__int16 v13; // [rsp+Eh] [rbp-15Ah] BYREF
char v14[8]; // [rsp+10h] [rbp-158h] BYREF
__int64 v15; // [rsp+18h] [rbp-150h] BYREF
char v16[32]; // [rsp+20h] [rbp-148h] BYREF
char buf[296]; // [rsp+40h] [rbp-128h] BYREF

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

canonical_decompiled_code:
void func5()
{
char v0; // bp
char v1; // bl
__int64 v2; // rdx
__int64 v3; // rax
unsigned int v4; // er12
char v5; // r13
__int16 v6; // ax
__int64 v7; // rdx
__int16 v8; // r12
__int16 v9; // r12
__int16 v10; // r13
char v11; // al
char v12; // dl
__int16 v13; // [rsp+Eh] [rbp-15Ah] BYREF
char v14[8]; // [rsp+10h] [rbp-158h] BYREF
__int64 v15; // [rsp+18h] [rbp-150h] BYREF
char v16[32]; // [rsp+20h] [rbp-148h] BYREF
char buf[296]; // [rsp+40h] [rbp-128h] BYREF

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

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 v1; // rbx
char *v2; // rdi
_QWORD *v3; // rbp
time_t v4; // rax
struct tm *v5; // rax
_QWORD *v6; // rbp
time_t v7; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-20h] 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
{
v3 = msg;
v4 = time(0LL);
v3[23] = v4;
timer = v4;
v5 = localtime(&timer);
mysleep((unsigned int)(60 - v5->tm_sec));
v6 = msg;
v7 = time(0LL);
v6[23] = v7;
timer = v7;
}
while ( (unsigned int)(-286331153 * localtime(&timer)->tm_min + 143165576) > 0x11111110 );
msync(msgstart, 0xEE6C000uLL, 1);
msync(msg, 0xC3C88uLL, 1);
}
}
v1 = 0LL;
bzero(bigbtmp, 0x9BD58uLL);
do
{
v2 = (char *)msg + v1;
v1 += 16LL;
msem_init(v2, 0LL);
}
while ( v1 != 112 );
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_1A4, 0LL);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rbx
char *v2; // rdi
_QWORD *v3; // rbp
time_t v4; // rax
struct tm *v5; // rax
_QWORD *v6; // rbp
time_t v7; // rax
__int64 result; // rax
time_t timer; // [rsp+8h] [rbp-20h] 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
{
v3 = msg;
v4 = time(0LL);
v3[23] = v4;
timer = v4;
v5 = localtime(&timer);
mysleep((unsigned int)(60 - v5->tm_sec));
v6 = msg;
v7 = time(0LL);
v6[23] = v7;
timer = v7;
}
while ( (unsigned int)(-286331153 * localtime(&timer)->tm_min + 143165576) > 0x11111110 );
msync(msgstart, 0xEE6C000uLL, 1);
msync(msg, 0xC3C88uLL, 1);
}
}
v1 = 0LL;
bzero(bigbtmp, 0x9BD58uLL);
do
{
v2 = (char *)msg + v1;
v1 += 16LL;
msem_init(v2, 0LL);
}
while ( v1 != 112 );
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_1A4, 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
__int64 v4; // rcx
const char *v5; // rdi
const char *v6; // rsi
char result; // al

v4 = 9LL;
v5 = "USERDATA";
v6 = a1;
do
{
if ( !v4 )
break;
v1 = *v6 < (unsigned int)*v5;
v2 = *v6++ == *v5++;
--v4;
}
while ( v2 );
if ( (!v1 && !v2) == v1 )
backupuserdata(v5, 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
__int64 v4; // rcx
const char *v5; // rdi
const char *v6; // rsi
char result; // al

v4 = 9LL;
v5 = "USERDATA";
v6 = a1;
do
{
if ( !v4 )
break;
v1 = *v6 < (unsigned int)*v5;
v2 = *v6++ == *v5++;
--v4;
}
while ( v2 );
if ( (!v1 && !v2) == v1 )
backupuserdata(v5, 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()
{
__int64 *v0; // rax
__int64 v1; // rbp
const char *v3; // rdi
__int64 v4[2]; // [rsp+8h] [rbp-10h] BYREF

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

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

setvbuf(stdout, &stdoutbuf, 0, 0x3C0uLL);
v0 = (__int64 *)func0(v4);
if ( !v0 )
{
v3 = "Error reading user files";
goto LABEL_6;
}
v1 = (__int64)v0;
if ( (unsigned int)func1(v0, v4) )
{
v3 = "Error updating aide list";
LABEL_6:
puts(v3);
fflush(stdout);
exit(1);
}
if ( (unsigned int)func2(v1, v4) )
{
v3 = "Error updating whoknowsroom lists";
goto LABEL_6;
}
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 result; // xmm0_8

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

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

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

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

return_type: double


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

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

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

v2 = a1;
putchar(91);
if ( a2 > 0 )
{
do
{
v3 = *v2++;
printf(" %f", v3);
}
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


decompiled_code:
void __fastcall __noreturn handle_error(unsigned int a1)
{
if ( a1 != -11 )
{
if ( a1 != -3 )
{
if ( a1 != -1 )
{
if ( a1 != -49 )
{
if ( a1 != -51 )
{
if ( a1 != -50 )
{
if ( a1 != -42 )
{
if ( a1 != -43 )
{
if ( a1 != -36 )
{
if ( a1 != -34 )
{
if ( a1 != -33 )
{
if ( a1 != -31 )
{
if ( a1 != -57 )
{
if ( a1 != -56 )
{
if ( a1 != -40 )
{
if ( a1 != -48 )
{
if ( a1 != -52 )
{
if ( a1 != -46 )
{
if ( a1 != -38 )
{
if ( a1 != -59 )
{
if ( a1 != -32 )
{
if ( a1 != -44 )
{
if ( a1 != -45 )
{
if ( a1 != -35 )
{
if ( a1 != -41 )
{
if ( a1 != -30 )
{
if ( a1 != -53 )
{
if ( a1 != -54 )
{
if ( a1 != -55 )
{
if ( a1 != -4 )
{
if ( a1 != -5 )
{
if ( a1 != -6 )
{
fprintf(stderr, "Unknown OpenCL Error: %d\n", a1);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_OUT_OF_HOST_MEMORY (%d)\n",
4294967290LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_OUT_OF_RESOURCES (%d)\n",
4294967291LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_MEM_OBJECT_ALLOCATION_FAILURE (%d)\n",
4294967292LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_WORK_ITEM_SIZE (%d)\n",
4294967241LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_WORK_GROUP_SIZE (%d)\n",
4294967242LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_WORK_DIMENSION (%d)\n",
4294967243LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_VALUE (%d)\n",
4294967266LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_SAMPLER (%d)\n",
4294967255LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_QUEUE_PROPERTIES (%d)\n",
4294967261LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_PROGRAM_EXECUTABLE (%d)\n",
4294967251LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_PROGRAM (%d)\n", 4294967252LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_PLATFORM (%d)\n", 4294967264LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_OPERATION (%d)\n", 4294967237LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_MEM_OBJECT (%d)\n", 4294967258LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_KERNEL_NAME (%d)\n", 4294967250LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_KERNEL_ARGS (%d)\n", 4294967244LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_KERNEL (%d)\n", 4294967248LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_IMAGE_SIZE (%d)\n", 4294967256LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_GLOBAL_OFFSET (%d)\n", 4294967240LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_EVENT_WAIT_LIST (%d)\n", 4294967239LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_DEVICE_TYPE (%d)\n", 4294967265LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_DEVICE (%d)\n", 4294967263LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_CONTEXT (%d)\n", 4294967262LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_COMMAND_QUEUE (%d)\n", 4294967260LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_BUILD_OPTIONS (%d)\n", 4294967253LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_BINARY (%d)\n", 4294967254LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_ARG_VALUE (%d)\n", 4294967246LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_ARG_SIZE (%d)\n", 4294967245LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_ARG_INDEX (%d)\n", 4294967247LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_DEVICE_NOT_FOUND (%d)\n", 0xFFFFFFFFLL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_COMPILER_NOT_AVAILABLE (%d)\n", 4294967293LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_BUILD_PROGRAM_FAILURE (%d)\n", 4294967285LL);
abort();
}

canonical_decompiled_code:
void __fastcall __noreturn func3(unsigned int a1)
{
if ( a1 != -11 )
{
if ( a1 != -3 )
{
if ( a1 != -1 )
{
if ( a1 != -49 )
{
if ( a1 != -51 )
{
if ( a1 != -50 )
{
if ( a1 != -42 )
{
if ( a1 != -43 )
{
if ( a1 != -36 )
{
if ( a1 != -34 )
{
if ( a1 != -33 )
{
if ( a1 != -31 )
{
if ( a1 != -57 )
{
if ( a1 != -56 )
{
if ( a1 != -40 )
{
if ( a1 != -48 )
{
if ( a1 != -52 )
{
if ( a1 != -46 )
{
if ( a1 != -38 )
{
if ( a1 != -59 )
{
if ( a1 != -32 )
{
if ( a1 != -44 )
{
if ( a1 != -45 )
{
if ( a1 != -35 )
{
if ( a1 != -41 )
{
if ( a1 != -30 )
{
if ( a1 != -53 )
{
if ( a1 != -54 )
{
if ( a1 != -55 )
{
if ( a1 != -4 )
{
if ( a1 != -5 )
{
if ( a1 != -6 )
{
fprintf(stderr, "Unknown OpenCL Error: %d\n", a1);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_OUT_OF_HOST_MEMORY (%d)\n",
4294967290LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_OUT_OF_RESOURCES (%d)\n",
4294967291LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_MEM_OBJECT_ALLOCATION_FAILURE (%d)\n",
4294967292LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_WORK_ITEM_SIZE (%d)\n",
4294967241LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_WORK_GROUP_SIZE (%d)\n",
4294967242LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_WORK_DIMENSION (%d)\n",
4294967243LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_VALUE (%d)\n",
4294967266LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_SAMPLER (%d)\n",
4294967255LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_QUEUE_PROPERTIES (%d)\n",
4294967261LL);
abort();
}
fprintf(
stderr,
"OpenCL Error: CL_INVALID_PROGRAM_EXECUTABLE (%d)\n",
4294967251LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_PROGRAM (%d)\n", 4294967252LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_PLATFORM (%d)\n", 4294967264LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_OPERATION (%d)\n", 4294967237LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_MEM_OBJECT (%d)\n", 4294967258LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_KERNEL_NAME (%d)\n", 4294967250LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_KERNEL_ARGS (%d)\n", 4294967244LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_KERNEL (%d)\n", 4294967248LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_IMAGE_SIZE (%d)\n", 4294967256LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_GLOBAL_OFFSET (%d)\n", 4294967240LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_EVENT_WAIT_LIST (%d)\n", 4294967239LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_DEVICE_TYPE (%d)\n", 4294967265LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_DEVICE (%d)\n", 4294967263LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_CONTEXT (%d)\n", 4294967262LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_COMMAND_QUEUE (%d)\n", 4294967260LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_BUILD_OPTIONS (%d)\n", 4294967253LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_BINARY (%d)\n", 4294967254LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_ARG_VALUE (%d)\n", 4294967246LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_ARG_SIZE (%d)\n", 4294967245LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_INVALID_ARG_INDEX (%d)\n", 4294967247LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_DEVICE_NOT_FOUND (%d)\n", 0xFFFFFFFFLL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_COMPILER_NOT_AVAILABLE (%d)\n", 4294967293LL);
abort();
}
fprintf(stderr, "OpenCL Error: CL_BUILD_PROGRAM_FAILURE (%d)\n", 4294967285LL);
abort();
}

original_code:
void handle_error(cl_int e) {
    if(e == -11) { fprintf(stderr, "OpenCL Error: " "CL_BUILD_PROGRAM_FAILURE" " (%d)\n", e); abort(); };
    if(e == -3) { fprintf(stderr, "OpenCL Error: " "CL_COMPILER_NOT_AVAILABLE" " (%d)\n", e); abort(); };
    if(e == -1) { fprintf(stderr, "OpenCL Error: " "CL_DEVICE_NOT_FOUND" " (%d)\n", e); abort(); };
 if(e == -49) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_ARG_INDEX" " (%d)\n", e); abort(); };
 if(e == -51) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_ARG_SIZE" " (%d)\n", e); abort(); };
 if(e == -50) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_ARG_VALUE" " (%d)\n", e); abort(); };
    if(e == -42) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_BINARY" " (%d)\n", e); abort(); };
    if(e == -43) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_BUILD_OPTIONS" " (%d)\n", e); abort(); };
    if(e == -36) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_COMMAND_QUEUE" " (%d)\n", e); abort(); };
    if(e == -34) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_CONTEXT" " (%d)\n", e); abort(); };
    if(e == -33) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_DEVICE" " (%d)\n", e); abort(); };
    if(e == -31) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_DEVICE_TYPE" " (%d)\n", e); abort(); };
    if(e == -57) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_EVENT_WAIT_LIST" " (%d)\n", e); abort(); };
    if(e == -56) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_GLOBAL_OFFSET" " (%d)\n", e); abort(); };
    if(e == -40) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_IMAGE_SIZE" " (%d)\n", e); abort(); };
    if(e == -48) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_KERNEL" " (%d)\n", e); abort(); };
    if(e == -52) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_KERNEL_ARGS" " (%d)\n", e); abort(); };
    if(e == -46) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_KERNEL_NAME" " (%d)\n", e); abort(); };
 if(e == -38) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_MEM_OBJECT" " (%d)\n", e); abort(); };
    if(e == -59) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_OPERATION" " (%d)\n", e); abort(); };
    if(e == -32) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_PLATFORM" " (%d)\n", e); abort(); };
    if(e == -44) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_PROGRAM" " (%d)\n", e); abort(); };
    if(e == -45) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_PROGRAM_EXECUTABLE" " (%d)\n", e); abort(); };
    if(e == -35) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_QUEUE_PROPERTIES" " (%d)\n", e); abort(); };
 if(e == -41) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_SAMPLER" " (%d)\n", e); abort(); };
    if(e == -30) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_VALUE" " (%d)\n", e); abort(); };
    if(e == -53) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_WORK_DIMENSION" " (%d)\n", e); abort(); };
    if(e == -54) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_WORK_GROUP_SIZE" " (%d)\n", e); abort(); };
    if(e == -55) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_WORK_ITEM_SIZE" " (%d)\n", e); abort(); };
    if(e == -4) { fprintf(stderr, "OpenCL Error: " "CL_MEM_OBJECT_ALLOCATION_FAILURE" " (%d)\n", e); abort(); };
    if(e == -5) { fprintf(stderr, "OpenCL Error: " "CL_OUT_OF_RESOURCES" " (%d)\n", e); abort(); };
    if(e == -6) { fprintf(stderr, "OpenCL Error: " "CL_OUT_OF_HOST_MEMORY" " (%d)\n", e); abort(); };
    fprintf(stderr, "Unknown OpenCL Error: %d\n", e);
    abort();
}

canonical_original_code:
void handle_error(int e) {
    if(e == -11) { fprintf(stderr, "OpenCL Error: " "CL_BUILD_PROGRAM_FAILURE" " (%d)\n", e); abort(); };
    if(e == -3) { fprintf(stderr, "OpenCL Error: " "CL_COMPILER_NOT_AVAILABLE" " (%d)\n", e); abort(); };
    if(e == -1) { fprintf(stderr, "OpenCL Error: " "CL_DEVICE_NOT_FOUND" " (%d)\n", e); abort(); };
 if(e == -49) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_ARG_INDEX" " (%d)\n", e); abort(); };
 if(e == -51) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_ARG_SIZE" " (%d)\n", e); abort(); };
 if(e == -50) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_ARG_VALUE" " (%d)\n", e); abort(); };
    if(e == -42) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_BINARY" " (%d)\n", e); abort(); };
    if(e == -43) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_BUILD_OPTIONS" " (%d)\n", e); abort(); };
    if(e == -36) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_COMMAND_QUEUE" " (%d)\n", e); abort(); };
    if(e == -34) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_CONTEXT" " (%d)\n", e); abort(); };
    if(e == -33) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_DEVICE" " (%d)\n", e); abort(); };
    if(e == -31) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_DEVICE_TYPE" " (%d)\n", e); abort(); };
    if(e == -57) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_EVENT_WAIT_LIST" " (%d)\n", e); abort(); };
    if(e == -56) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_GLOBAL_OFFSET" " (%d)\n", e); abort(); };
    if(e == -40) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_IMAGE_SIZE" " (%d)\n", e); abort(); };
    if(e == -48) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_KERNEL" " (%d)\n", e); abort(); };
    if(e == -52) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_KERNEL_ARGS" " (%d)\n", e); abort(); };
    if(e == -46) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_KERNEL_NAME" " (%d)\n", e); abort(); };
 if(e == -38) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_MEM_OBJECT" " (%d)\n", e); abort(); };
    if(e == -59) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_OPERATION" " (%d)\n", e); abort(); };
    if(e == -32) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_PLATFORM" " (%d)\n", e); abort(); };
    if(e == -44) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_PROGRAM" " (%d)\n", e); abort(); };
    if(e == -45) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_PROGRAM_EXECUTABLE" " (%d)\n", e); abort(); };
    if(e == -35) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_QUEUE_PROPERTIES" " (%d)\n", e); abort(); };
 if(e == -41) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_SAMPLER" " (%d)\n", e); abort(); };
    if(e == -30) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_VALUE" " (%d)\n", e); abort(); };
    if(e == -53) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_WORK_DIMENSION" " (%d)\n", e); abort(); };
    if(e == -54) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_WORK_GROUP_SIZE" " (%d)\n", e); abort(); };
    if(e == -55) { fprintf(stderr, "OpenCL Error: " "CL_INVALID_WORK_ITEM_SIZE" " (%d)\n", e); abort(); };
    if(e == -4) { fprintf(stderr, "OpenCL Error: " "CL_MEM_OBJECT_ALLOCATION_FAILURE" " (%d)\n", e); abort(); };
    if(e == -5) { fprintf(stderr, "OpenCL Error: " "CL_OUT_OF_RESOURCES" " (%d)\n", e); abort(); };
    if(e == -6) { fprintf(stderr, "OpenCL Error: " "CL_OUT_OF_HOST_MEMORY" " (%d)\n", e); abort(); };
    fprintf(stderr, "Unknown OpenCL Error: %d\n", e);
    abort();
}

variable_types: e int


decompiled_code:
void __fastcall check_status(unsigned int a1)
{
if ( a1 )
handle_error(a1);
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1)
{
if ( a1 )
func3(a1);
}

original_code:
void check_status(cl_int e) {
    if(0 != e) {
        handle_error(e);
    }
}

canonical_original_code:
void check_status(int e) {
    if(0 != e) {
        handle_error(e);
    }
}


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


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


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


repo: ehorton/horst

decompiled_code:
__int64 __fastcall device_index(int fd, const char *a2)
{
__int64 result; // rax
char v3[16]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v4; // [rsp+10h] [rbp-38h]

strncpy(v3, a2, 0x10uLL);
LOWORD(v4) = 2;
if ( ioctl(fd, 0x8933uLL, v3) < 0 || (result = v4, (v4 & 0x80000000) != 0) )
err(1, "Interface %s not found", a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd, const char *a2)
{
__int64 result; // rax
char v3[16]; // [rsp+0h] [rbp-48h] BYREF
unsigned int v4; // [rsp+10h] [rbp-38h]

strncpy(v3, a2, 0x10uLL);
LOWORD(v4) = 2;
if ( ioctl(fd, 0x8933uLL, v3) < 0 || (result = v4, (v4 & 0x80000000) != 0) )
err(1, "Interface %s not found", a2);
return result;
}

original_code:
static int
device_index(int fd, const char *devname)
{
 struct ifreq req;
 strncpy(req.ifr_ifrn.ifrn_name, devname, 16);
 req.ifr_ifru.ifru_addr.sa_family = 2;
 if (ioctl(fd, 0x8933, &req) < 0)
  err(1, "Interface %s not found", devname);
 if (req.ifr_ifru.ifru_ivalue < 0)
  err(1, "Interface %s not found", devname);
 ;
 return req.ifr_ifru.ifru_ivalue;
}

canonical_original_code:
static int device_index(int fd, char *devname)
{
 struct ifreq req;
 strncpy(req.ifr_ifrn.ifrn_name, devname, 16);
 req.ifr_ifru.ifru_addr.sa_family = 2;
 if (ioctl(fd, 0x8933, &req) < 0)
  err(1, "Interface %s not found", devname);
 if (req.ifr_ifru.ifru_ivalue < 0)
  err(1, "Interface %s not found", devname);
 ;
 return req.ifr_ifru.ifru_ivalue;
}

variable_types: fd int

variable_types:
devname
char *

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; }


decompiled_code:
int __fastcall device_promisc(int fd, const char *a2, int a3)
{
__int16 v4; // ax
__int16 v5; // ax
int result; // eax
char v7[16]; // [rsp+0h] [rbp-48h] BYREF
__int16 v8; // [rsp+10h] [rbp-38h]

strncpy(v7, a2, 0x10uLL);
v8 = 2;
if ( ioctl(fd, 0x8913uLL, v7) < 0 )
err(1, "Could not get device flags for %s", a2);
LOBYTE(v4) = v8;
HIBYTE(v4) = HIBYTE(v8) & 0xFE;
v5 = v4 | 1;
if ( a3 )
v5 = v8 | 0x101;
v8 = v5;
result = ioctl(fd, 0x8914uLL, v7);
if ( result < 0 )
err(1, "Could not set promisc mode for %s", a2);
return result;
}

canonical_decompiled_code:
int __fastcall func1(int fd, const char *a2, int a3)
{
__int16 v4; // ax
__int16 v5; // ax
int result; // eax
char v7[16]; // [rsp+0h] [rbp-48h] BYREF
__int16 v8; // [rsp+10h] [rbp-38h]

strncpy(v7, a2, 0x10uLL);
v8 = 2;
if ( ioctl(fd, 0x8913uLL, v7) < 0 )
err(1, "Could not get device flags for %s", a2);
LOBYTE(v4) = v8;
HIBYTE(v4) = HIBYTE(v8) & 0xFE;
v5 = v4 | 1;
if ( a3 )
v5 = v8 | 0x101;
v8 = v5;
result = ioctl(fd, 0x8914uLL, v7);
if ( result < 0 )
err(1, "Could not set promisc mode for %s", a2);
return result;
}

original_code:
static void
device_promisc(int fd, const char *devname, int on)
{
 struct ifreq req;
 strncpy(req.ifr_ifrn.ifrn_name, devname, 16);
 req.ifr_ifru.ifru_addr.sa_family = 2;
 if (ioctl(fd, 0x8913, &req) < 0)
  err(1, "Could not get device flags for %s", devname);
 req.ifr_ifru.ifru_flags |= IFF_UP;
 if (on)
  req.ifr_ifru.ifru_flags |= IFF_PROMISC;
 else
  req.ifr_ifru.ifru_flags &= ~IFF_PROMISC;
 if (ioctl(fd, 0x8914, &req) < 0)
  err(1, "Could not set promisc mode for %s", devname);
}

canonical_original_code:
static void device_promisc(int fd, char *devname, int on)
{
 struct ifreq req;
 strncpy(req.ifr_ifrn.ifrn_name, devname, 16);
 req.ifr_ifru.ifru_addr.sa_family = 2;
 if (ioctl(fd, 0x8913, &req) < 0)
  err(1, "Could not get device flags for %s", devname);
 req.ifr_ifru.ifru_flags |= IFF_UP;
 if (on)
  req.ifr_ifru.ifru_flags |= IFF_PROMISC;
 else
  req.ifr_ifru.ifru_flags &= ~IFF_PROMISC;
 if (ioctl(fd, 0x8914, &req) < 0)
  err(1, "Could not set promisc mode for %s", devname);
}

variable_types: on int

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

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }


decompiled_code:
__int64 __fastcall device_get_arptype(int fd, const char *a2)
{
char v3[16]; // [rsp-10h] [rbp-38h] BYREF
__int128 v4; // [rsp+0h] [rbp-28h]
__int64 v5; // [rsp+10h] [rbp-18h]

v4 = 0LL;
v5 = 0LL;
strncpy(v3, a2, 0x10uLL);
if ( ioctl(fd, 0x8927uLL, v3) < 0 )
err(1, "Could not get arptype");
return (unsigned __int16)v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, const char *a2)
{
char v3[16]; // [rsp-10h] [rbp-38h] BYREF
__int128 v4; // [rsp+0h] [rbp-28h]
__int64 v5; // [rsp+10h] [rbp-18h]

v4 = 0LL;
v5 = 0LL;
strncpy(v3, a2, 0x10uLL);
if ( ioctl(fd, 0x8927uLL, v3) < 0 )
err(1, "Could not get arptype");
return (unsigned __int16)v4;
}

original_code:
int
device_get_arptype(int fd, char* ifname)
{
 struct ifreq ifr;
 memset(&ifr, 0, sizeof(ifr));
 strncpy(ifr.ifr_ifrn.ifrn_name, ifname, sizeof(ifr.ifr_ifrn.ifrn_name));
 if (ioctl(fd, 0x8927, &ifr) < 0)
  err(1, "Could not get arptype");
 ;
 return ifr.ifr_ifru.ifru_hwaddr.sa_family;
}

canonical_original_code:
int device_get_arptype(int fd, char *ifname)
{
 struct ifreq ifr;
 memset(&ifr, 0, sizeof(ifr));
 strncpy(ifr.ifr_ifrn.ifrn_name, ifname, sizeof(ifr.ifr_ifrn.ifrn_name));
 if (ioctl(fd, 0x8927, &ifr) < 0)
  err(1, "Could not get arptype");
 ;
 return ifr.ifr_ifru.ifru_hwaddr.sa_family;
}

variable_types:
ifname
char *


decompiled_code:
__int64 __fastcall open_packet_socket(const char *a1, __int64 a2, unsigned int a3)
{
int v4; // ebx
int v5; // eax
unsigned int v6; // er12
struct sockaddr v8; // [rsp+0h] [rbp-48h] BYREF
int v9; // [rsp+10h] [rbp-38h]

v4 = (unsigned __int16)_bswap_16_constprop_0(17LL, 3LL);
v5 = socket(17, 3, v4);
if ( v5 < 0 )
err(1, "Could not create packet socket");
v6 = v5;
*(_DWORD *)&v8.sa_data[2] = device_index(v5, a1);
*(_QWORD *)&v8.sa_data[6] = 0LL;
v9 = 0;
v8.sa_family = 17;
*(_WORD *)v8.sa_data = v4;
if ( bind(v6, &v8, 0x14u) )
err(1, "bind failed");
device_promisc(v6, a1, 1);
if ( a3 )
set_receive_buffer(v6, a3);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, __int64 a2, unsigned int a3)
{
int v4; // ebx
int v5; // eax
unsigned int v6; // er12
struct sockaddr v8; // [rsp+0h] [rbp-48h] BYREF
int v9; // [rsp+10h] [rbp-38h]

v4 = (unsigned __int16)func3(17LL, 3LL);
v5 = socket(17, 3, v4);
if ( v5 < 0 )
err(1, "Could not create packet socket");
v6 = v5;
*(_DWORD *)&v8.sa_data[2] = func0(v5, a1);
*(_QWORD *)&v8.sa_data[6] = 0LL;
v9 = 0;
v8.sa_family = 17;
*(_WORD *)v8.sa_data = v4;
if ( bind(v6, &v8, 0x14u) )
err(1, "bind failed");
func1(v6, a1, 1);
if ( a3 )
func2(v6, a3);
return v6;
}

original_code:
int
open_packet_socket(char* devname, size_t bufsize, int recv_buffer_size)
{
 int ret;
 int mon_fd;
 int ifindex;
 struct sockaddr_ll sall;
 mon_fd = socket(17, SOCK_RAW, htons(0x0003));
 if (mon_fd < 0)
  err(1, "Could not create packet socket");
 ifindex = device_index(mon_fd, devname);
 memset(&sall, 0, sizeof(struct sockaddr_ll));
 sall.sll_ifindex = ifindex;
 sall.sll_family = 17;
 sall.sll_protocol = htons(0x0003);
 ret = bind(mon_fd, (struct sockaddr*)&sall, sizeof(sall));
 if (ret != 0)
  err(1, "bind failed");
 device_promisc(mon_fd, devname, 1);
 if (recv_buffer_size)
  set_receive_buffer(mon_fd, recv_buffer_size);
 return mon_fd;
}

canonical_original_code:
int open_packet_socket(char *devname, unsigned long bufsize, int recv_buffer_size)
{
 int ret;
 int mon_fd;
 int ifindex;
 struct sockaddr_ll sall;
 mon_fd = socket(17, SOCK_RAW, htons(0x0003));
 if (mon_fd < 0)
  err(1, "Could not create packet socket");
 ifindex = device_index(mon_fd, devname);
 memset(&sall, 0, sizeof(struct sockaddr_ll));
 sall.sll_ifindex = ifindex;
 sall.sll_family = 17;
 sall.sll_protocol = htons(0x0003);
 ret = bind(mon_fd, (struct sockaddr *)&sall, sizeof(sall));
 if (ret != 0)
  err(1, "bind failed");
 device_promisc(mon_fd, devname, 1);
 if (recv_buffer_size)
  set_receive_buffer(mon_fd, recv_buffer_size);
 return mon_fd;
}

variable_types:
bufsize
unsigned long

variable_types: ret int

variable_types: ifindex int

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }


decompiled_code:
ssize_t __fastcall recv_packet(int a1, void *a2, size_t a3)
{
return recv(a1, a2, a3, 64);
}

canonical_decompiled_code:
ssize_t __fastcall func6(int a1, void *a2, size_t a3)
{
return recv(a1, a2, a3, 64);
}

original_code:
inline int
recv_packet(int fd, unsigned char* buffer, size_t bufsize)
{
 return recv(fd, buffer, bufsize, MSG_DONTWAIT);
}

canonical_original_code:
inline int recv_packet(int fd, unsigned char *buffer, unsigned long bufsize)
{
 return recv(fd, buffer, bufsize, MSG_DONTWAIT);
}

variable_types:
buffer
unsigned char *


decompiled_code:
int __fastcall close_packet_socket(int fd, const char *a2)
{
int result; // eax

if ( fd > 0 )
{
device_promisc(fd, a2, 0);
result = close(fd);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int fd, const char *a2)
{
int result; // eax

if ( fd > 0 )
{
func1(fd, a2, 0);
result = close(fd);
}
return result;
}

original_code:
void
close_packet_socket(int fd, char* ifname)
{
 if (fd > 0) {
  device_promisc(fd, ifname, 0);
  close(fd);
 }
}

canonical_original_code:
void close_packet_socket(int fd, char *ifname)
{
 if (fd > 0) {
  device_promisc(fd, ifname, 0);
  close(fd);
 }
}


main

canonical_name: main

repo: ehsan/gl-samples

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er8
int result; // eax

v3 = SDL_Init();
result = 1;
if ( v3 >= 0 )
{
if ( SDL_SetVideoMode() )
{
glClearColor();
glClear();
glEnable();
glScissor();
glClearColor();
glClear();
SDL_GL_SwapBuffers();
SDL_Delay();
SDL_Quit();
result = 0;
}
else
{
result = 2;
}
}
return result;
}

original_code:
int
main(int argc, char *argv[])
{
   glutInit(&argc, argv);
   glutInitWindowSize(300, 300);
   glutInitDisplayMode(0x0002 | 0x0000 | 0x0010);
   glutCreateWindow("es2gears");
   glutIdleFunc (gears_idle);
   glutReshapeFunc(gears_reshape);
   glutDisplayFunc(gears_draw);
   glutSpecialFunc(gears_special);
   gears_init();
   glutMainLoop();
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: eichlan/usersv

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx

scanUsers(argc, argv, envp);
while ( 1 )
{
sleep(0x1Eu);
scanProcs();
scanUsers(30LL, argv, v3);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx

func10(argc, argv, envp);
while ( 1 )
{
sleep(0x1Eu);
func8();
func10(30LL, argv, v3);
}
}

original_code:
int main( int argc, char *argv[] )
{
 scanUsers();
 for(;;)
 {
  sleep( 30 );
  scanProcs();
  scanUsers();
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 scanUsers();
 for(;;)
 {
  sleep( 30 );
  scanProcs();
  scanUsers();
 }
}