parseArgs

decompiled_code:
__int64 __fastcall parseArgs(int a1, __int64 a2)
{
unsigned int v2; // er13
_BYTE *v4; // r12
const char *v5; // r12
int v6; // ebp
int v7; // ebx

if ( a1 < 0 )
{
fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
exit(1);
}
v2 = 1;
if ( a1 <= 1 )
return 0;
do
{
v4 = *(_BYTE **)(a2 + 8LL * (__int16)v2);
if ( *v4 != 45 )
{
argSanityCheck();
return v2;
}
v5 = v4 + 1;
if ( !arg[0] )
{
LABEL_18:
fprintf(stderr, "%s : invalid argument -%s%s", "randword", v5, "\n");
exit(1);
}
v6 = 0;
v7 = 0;
while ( strcmp(v5, &arg[32 * v7]) )
{
v7 = (__int16)++v6;
if ( !arg[32 * (__int16)v6] )
goto LABEL_18;
}
if ( *(_WORD *)&arg[32 * v7 + 10] )
{
if ( (__int16)v2 == a1 - 1 )
{
fprintf(stderr, "%s : %s parameter is incomplete", "randword", v5);
exit(1);
}
(*(void (__fastcall **)(_QWORD))&arg[32 * v7 + 16])(*(_QWORD *)(a2 + 8LL * (__int16)v2++ + 8));
}
else
{
(*(void (__fastcall **)(_QWORD))&arg[32 * v7 + 16])(0LL);
}
++v2;
}
while ( (__int16)v2 < a1 );
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1, __int64 a2)
{
unsigned int v2; // er13
_BYTE *v4; // r12
const char *v5; // r12
int v6; // ebp
int v7; // ebx

if ( a1 < 0 )
{
fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
exit(1);
}
v2 = 1;
if ( a1 <= 1 )
return 0;
do
{
v4 = *(_BYTE **)(a2 + 8LL * (__int16)v2);
if ( *v4 != 45 )
{
func20();
return v2;
}
v5 = v4 + 1;
if ( !arg[0] )
{
LABEL_18:
fprintf(stderr, "%s : invalid argument -%s%s", "randword", v5, "\n");
exit(1);
}
v6 = 0;
v7 = 0;
while ( strcmp(v5, &arg[32 * v7]) )
{
v7 = (__int16)++v6;
if ( !arg[32 * (__int16)v6] )
goto LABEL_18;
}
if ( *(_WORD *)&arg[32 * v7 + 10] )
{
if ( (__int16)v2 == a1 - 1 )
{
fprintf(stderr, "%s : %s parameter is incomplete", "randword", v5);
exit(1);
}
(*(void (__fastcall **)(_QWORD))&arg[32 * v7 + 16])(*(_QWORD *)(a2 + 8LL * (__int16)v2++ + 8));
}
else
{
(*(void (__fastcall **)(_QWORD))&arg[32 * v7 + 16])(0LL);
}
++v2;
}
while ( (__int16)v2 < a1 );
return 0;
}

original_code:
short parseArgs(int argc, char **argv) {
   short i, j, found;
   char *szparam = 0;
   if (argc < 0) {
      fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
      exit(1);
   }
   for (i = 1; i < argc; i++) {
      szparam = argv[i];
      if (*szparam != '-') {
         argSanityCheck();
         return i;
      }
      else
         szparam++;
      found = 0;
      j = 0;
      if (argc < 0 + 1) {
         fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
         exit(1);
      }
      while (*arg[j].argName && !found) {
         if (strcmp(szparam, arg[j].argName) == 0) {
            if (arg[j].argHasArg) {
               if (i == argc - 1) {
                  fprintf(stderr, "%s : %s parameter is incomplete", "randword", szparam);
                  exit(1);
               }
               arg[j].argFunc(argv[i+1]);
               i++;
            }
            else
               arg[j].argFunc(0);
            found = 1;
         }
         j++;
      }
      if (!found) {
         fprintf(stderr, "%s : invalid argument -%s%s", "randword", szparam, "\n");
         exit(1);
      }
   }
   return 0;
}

canonical_original_code:
short parseArgs(int argc, char **argv) {
   short i; short j; short found;
   char *szparam = 0;
   if (argc < 0) {
      fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
      exit(1);
   }
   for (i = 1; i < argc; i++) {
      szparam = argv[i];
      if (*szparam != '-') {
         argSanityCheck();
         return i;
      }
      else
         szparam++;
      found = 0;
      j = 0;
      if (argc < 0 + 1) {
         fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
         exit(1);
      }
      while (*arg[j].argName && !found) {
         if (strcmp(szparam, arg[j].argName) == 0) {
            if (arg[j].argHasArg) {
               if (i == argc - 1) {
                  fprintf(stderr, "%s : %s parameter is incomplete", "randword", szparam);
                  exit(1);
               }
               arg[j].argFunc(argv[i+1]);
               i++;
            }
            else
               arg[j].argFunc(0);
            found = 1;
         }
         j++;
      }
      if (!found) {
         fprintf(stderr, "%s : invalid argument -%s%s", "randword", szparam, "\n");
         exit(1);
      }
   }
   return 0;
}

variable_types: j short

variable_types: found short

return_type: short


SigHandler

repo: egillespie/randword

decompiled_code:
void __fastcall SigHandler(int a1)
{
if ( a1 == 2 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
exit(0);
}

original_code:
void SigHandler(int sig) {
   if (sig == 2)
      exit(0);
}

variable_types: sig int

return_type: void


ExitProgram

decompiled_code:
void ExitProgram()
{
void *v0; // r15
void **v1; // r13
__int64 v2; // r14
__int64 v3; // r12
__int64 v4; // rbx
void *v5; // rdi

if ( !quiet )
{
putchar(10);
printf("Tries: %ld%s", totalcount, "\n");
printf("Hits: %ld%s", numfound, "\n");
printf("Misses: %ld%s", totalcount - numfound, "\n");
}
if ( !searchOnDisk )
{
v0 = dict;
if ( dict )
{
if ( maxWordLength - minWordLength >= 0 )
{
v1 = (void **)dict;
v2 = 0LL;
while ( *v1 )
{
v3 = wordsOnPage[v2];
if ( v3 )
{
v4 = 0LL;
while ( 1 )
{
v5 = (void *)*((_QWORD *)*v1 + v4);
if ( !v5 )
break;
free(v5);
if ( ++v4 == v3 )
goto LABEL_7;
}
free(*v1);
break;
}
LABEL_7:
free(*v1);
++v2;
++v1;
if ( maxWordLength - minWordLength < (int)v2 )
break;
}
}
free(v0);
}
}
}

canonical_decompiled_code:
void func1()
{
void *v0; // r15
void **v1; // r13
__int64 v2; // r14
__int64 v3; // r12
__int64 v4; // rbx
void *v5; // rdi

if ( !quiet )
{
putchar(10);
printf("Tries: %ld%s", totalcount, "\n");
printf("Hits: %ld%s", numfound, "\n");
printf("Misses: %ld%s", totalcount - numfound, "\n");
}
if ( !searchOnDisk )
{
v0 = dict;
if ( dict )
{
if ( maxWordLength - minWordLength >= 0 )
{
v1 = (void **)dict;
v2 = 0LL;
while ( *v1 )
{
v3 = wordsOnPage[v2];
if ( v3 )
{
v4 = 0LL;
while ( 1 )
{
v5 = (void *)*((_QWORD *)*v1 + v4);
if ( !v5 )
break;
free(v5);
if ( ++v4 == v3 )
goto LABEL_7;
}
free(*v1);
break;
}
LABEL_7:
free(*v1);
++v2;
++v1;
if ( maxWordLength - minWordLength < (int)v2 )
break;
}
}
free(v0);
}
}
}

original_code:
void ExitProgram(void) {
   int i;
   unsigned long j;
   short stop = 0;
   if (!quiet) {
      printf("%s", "\n");
      printf("Tries:  %ld%s", totalcount, "\n");
      printf("Hits:   %ld%s", numfound, "\n");
      printf("Misses: %ld%s", totalcount - numfound, "\n");
   }
   if (!searchOnDisk) {
      if (dict != ((void *)0)) {
  for (i = 0; i < maxWordLength - minWordLength + 1 && !stop; i++) {
     if (dict[i] != ((void *)0)) {
        for (j = 0; j < wordsOnPage[i]; j++) {
    if (dict[i][j] != ((void *)0))
       free(dict[i][j]);
    else {
       stop = 1;
       break;
    }
        }
        free(dict[i]);
     }
     else
        break;
  }
  free(dict);
      }
   }
}

canonical_original_code:
void ExitProgram() {
   int i;
   unsigned long j;
   short stop = 0;
   if (!quiet) {
      printf("%s", "\n");
      printf("Tries:  %ld%s", totalcount, "\n");
      printf("Hits:   %ld%s", numfound, "\n");
      printf("Misses: %ld%s", totalcount - numfound, "\n");
   }
   if (!searchOnDisk) {
      if (dict != ((void *)0)) {
  for (i = 0; i < maxWordLength - minWordLength + 1 && !stop; i++) {
     if (dict[i] != ((void *)0)) {
        for (j = 0; j < wordsOnPage[i]; j++) {
    if (dict[i][j] != ((void *)0))
       free(dict[i][j]);
    else {
       stop = 1;
       break;
    }
        }
        free(dict[i]);
     }
     else
        break;
  }
  free(dict);
      }
   }
}

variable_types: i int

variable_types:
j
unsigned long

variable_types: stop short


CheckInMem

decompiled_code:
__int64 __fastcall CheckInMem(char *s1, int a2)
{
__int64 v2; // rcx
__int64 v3; // r13
_QWORD *v4; // r12
int v5; // eax

lwr_2 = -1LL;
v2 = wordsOnPage[a2 - minWordLength];
upr_1 = v2;
cur_0 = (v2 - 1) / 2;
if ( v2 == cur_0 )
return 0LL;
v3 = (v2 - 1) / 2;
v4 = (char *)dict + 8 * (a2 - minWordLength);
do
{
if ( lwr_2 == v3 )
return 0LL;
v5 = strncmp(s1, *(const char **)(*v4 + 8 * v3), a2);
if ( !v5 )
return 1LL;
if ( v5 <= 0 )
upr_1 = v3;
else
lwr_2 = v3;
v3 = (lwr_2 + upr_1) / 2;
cur_0 = v3;
}
while ( upr_1 != v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s1, int a2)
{
__int64 v2; // rcx
__int64 v3; // r13
_QWORD *v4; // r12
int v5; // eax

lwr_2 = -1LL;
v2 = wordsOnPage[a2 - minWordLength];
upr_1 = v2;
cur_0 = (v2 - 1) / 2;
if ( v2 == cur_0 )
return 0LL;
v3 = (v2 - 1) / 2;
v4 = (char *)dict + 8 * (a2 - minWordLength);
do
{
if ( lwr_2 == v3 )
return 0LL;
v5 = strncmp(s1, *(const char **)(*v4 + 8 * v3), a2);
if ( !v5 )
return 1LL;
if ( v5 <= 0 )
upr_1 = v3;
else
lwr_2 = v3;
v3 = (lwr_2 + upr_1) / 2;
cur_0 = v3;
}
while ( upr_1 != v3 );
return 0LL;
}

original_code:
int CheckInMem(const char *aword, int buflen) {
   static long lwr, upr, cur;
   register int cmp;
   register int idx = buflen - minWordLength;
   lwr = -1;
   upr = wordsOnPage[idx];
   cur = (upr + lwr) / 2;
   while ((cur != upr) && (cur != lwr)) {
      cmp = strncmp(aword, dict[idx][cur], buflen);
      if (cmp == 0)
  return 1;
      else if (cmp > 0)
  lwr = cur;
      else
  upr = cur;
      cur = (lwr + upr) / 2;
   }
   return 0;
}

canonical_original_code:
int CheckInMem(char *aword, int buflen) {
   static long lwr; static long upr; static long cur;
   register int cmp;
   register int idx = buflen - minWordLength;
   lwr = -1;
   upr = wordsOnPage[idx];
   cur = (upr + lwr) / 2;
   while ((cur != upr) && (cur != lwr)) {
      cmp = strncmp(aword, dict[idx][cur], buflen);
      if (cmp == 0)
  return 1;
      else if (cmp > 0)
  lwr = cur;
      else
  upr = cur;
      cur = (lwr + upr) / 2;
   }
   return 0;
}

variable_types:
aword
char *

variable_types: buflen int

variable_types: lwr long

variable_types: upr long

variable_types: cur long

variable_types: cmp int

variable_types: idx int

return_type: int


CheckWord

decompiled_code:
__int64 __fastcall CheckWord(char *a1, unsigned int a2)
{
__int64 result; // rax

if ( searchOnDisk )
result = CheckOnDisk(a1, a2);
else
result = CheckInMem(a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, unsigned int a2)
{
__int64 result; // rax

if ( searchOnDisk )
result = func4(a1, a2);
else
result = func5(a1, a2);
return result;
}

original_code:
int CheckWord(const char *aword, int buflen) {
   return (searchOnDisk ? CheckOnDisk(aword, buflen) : CheckInMem(aword, buflen));
}

canonical_original_code:
int CheckWord(char *aword, int buflen) {
   return (searchOnDisk ? CheckOnDisk(aword, buflen) : CheckInMem(aword, buflen));
}


main

canonical_name: main

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

chdir("/bbs/core/bbs");
umask(0x17u);
if ( (int)openfiles() < 0 )
return -1;
if ( argc <= 1 )
{
v4 = 1;
}
else
{
v3 = argv[1];
v4 = 1;
if ( *v3 == 45 )
{
switch ( v3[1] )
{
case 'b':
v4 = 0;
if ( argc == 3 )
v4 = 7;
break;
case 'c':
v4 = 8;
break;
case 'f':
v4 = 2;
break;
case 'i':
v4 = 4;
break;
case 'q':
v4 = 3;
break;
case 's':
v4 = 5;
break;
case 'u':
v4 = 6;
break;
default:
exit(1);
}
}
}
while ( 2 )
{
switch ( v4 )
{
case 1:
ARGV = argv;
bbsstart();
result = 0;
break;
case 2:
bbsfinger();
result = 0;
break;
case 3:
v6 = getenv("INIT_VERSION");
bbsqueue(v6 == 0LL);
result = 0;
break;
case 4:
v4 = bbssync(1LL);
continue;
case 5:
bbssync(0LL);
result = 0;
break;
case 6:
nice(40);
bbsupdate();
result = 0;
break;
case 7:
nice(40);
bbsbackup(argv[2]);
result = 0;
break;
case 8:
clone_populate_forums();
clone_populate_posts();
clone_populate_users();
result = 0;
break;
default:
result = 0;
break;
}
break;
}
return result;
}

original_code:
int
main(register int argc, register char **argv)
{
  register int cmd = 0;
  chdir("/bbs/core/bbs");
  umask(027);
  if (openfiles() < 0)
    return(-1);
  if (argc < 2 || *argv[1] != '-')
    cmd = 1;
  else
    switch (argv[1][1])
    {
      case 'b':
 if (argc == 3)
          cmd = 7;
        break;
      case 'f':
        cmd = 2;
        break;
      case 'i':
        cmd = 4;
        break;
      case 's':
        cmd = 5;
        break;
      case 'q':
        cmd = 3;
        break;
      case 'u':
        cmd = 6;
        break;
      case 'c':
        cmd = 8;
        break;
      default:
        _exit(1);
        break;
    }
  for (;;)
  {
    switch (cmd)
    {
      case 1:
        ARGV = argv;
        bbsstart();
        break;
      case 2:
        bbsfinger();
        break;
      case 4:
        cmd = bbssync(1);
        continue;
      case 5:
        bbssync(0);
        break;
      case 6:
 nice(40);
        bbsupdate();
        break;
      case 7:
 nice(40);
        bbsbackup(argv[2]);
        break;
      case 3:
        bbsqueue(getenv("INIT_VERSION") ? 0 : 1);
 break;
      case 8:
 if (1) clone_populate_forums();
        if (1) clone_populate_posts();
 if (1) clone_populate_users();
 break;
      default:
        break;
    }
    break;
  }
  return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  register int cmd = 0;
  chdir("/bbs/core/bbs");
  umask(027);
  if (openfiles() < 0)
    return(-1);
  if (argc < 2 || *argv[1] != '-')
    cmd = 1;
  else
    switch (argv[1][1])
    {
      case 'b':
 if (argc == 3)
          cmd = 7;
        break;
      case 'f':
        cmd = 2;
        break;
      case 'i':
        cmd = 4;
        break;
      case 's':
        cmd = 5;
        break;
      case 'q':
        cmd = 3;
        break;
      case 'u':
        cmd = 6;
        break;
      case 'c':
        cmd = 8;
        break;
      default:
        _exit(1);
        break;
    }
  for (;;)
  {
    switch (cmd)
    {
      case 1:
        ARGV = argv;
        bbsstart();
        break;
      case 2:
        bbsfinger();
        break;
      case 4:
        cmd = bbssync(1);
        continue;
      case 5:
        bbssync(0);
        break;
      case 6:
 nice(40);
        bbsupdate();
        break;
      case 7:
 nice(40);
        bbsbackup(argv[2]);
        break;
      case 3:
        bbsqueue(getenv("INIT_VERSION") ? 0 : 1);
 break;
      case 8:
 if (1) clone_populate_forums();
        if (1) clone_populate_posts();
 if (1) clone_populate_users();
 break;
      default:
        break;
    }
    break;
  }
  return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: cmd int


decompiled_code:
const char *__fastcall login_user(const char *a1, const char *a2)
{
bool v2; // cf
bool v3; // zf
const char *v6; // rdi
__int64 v7; // rcx
const char *v8; // rsi
const char *v9; // rbx
char *v10; // rbp
char *v12; // rsi

v2 = 0;
v3 = 0;
v6 = "Guest";
v7 = 6LL;
v8 = a1;
do
{
if ( !v7 )
break;
v2 = *v8 < (unsigned int)*v6;
v3 = *v8++ == *v6++;
--v7;
}
while ( v3 );
guest = (!v2 && !v3) == v2;
v9 = (const char *)getuser(a1, v8);
if ( v9 )
{
if ( guest )
{
v10 = (char *)mmap(0LL, 0x1808uLL, 3, 34, -1, 0LL);
if ( (unsigned __int64)(v10 - 1) > 0xFFFFFFFFFFFFFFFDLL )
{
v9 = 0LL;
}
else
{
bcopy(v9, v10, 0x1808uLL);
v9 = v10;
}
}
else if ( !getenv("BBSNAME") )
{
v12 = crypt(a2, v9 + 76);
if ( strncmp(v9 + 76, v12, 0xDuLL) )
{
freeuser(v9);
v9 = 0LL;
}
}
}
return v9;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1, const char *a2)
{
bool v2; // cf
bool v3; // zf
const char *v6; // rdi
__int64 v7; // rcx
const char *v8; // rsi
const char *v9; // rbx
char *v10; // rbp
char *v12; // rsi

v2 = 0;
v3 = 0;
v6 = "Guest";
v7 = 6LL;
v8 = a1;
do
{
if ( !v7 )
break;
v2 = *v8 < (unsigned int)*v6;
v3 = *v8++ == *v6++;
--v7;
}
while ( v3 );
guest = (!v2 && !v3) == v2;
v9 = (const char *)getuser(a1, v8);
if ( v9 )
{
if ( guest )
{
v10 = (char *)mmap(0LL, 0x1808uLL, 3, 34, -1, 0LL);
if ( (unsigned __int64)(v10 - 1) > 0xFFFFFFFFFFFFFFFDLL )
{
v9 = 0LL;
}
else
{
bcopy(v9, v10, 0x1808uLL);
v9 = v10;
}
}
else if ( !getenv("BBSNAME") )
{
v12 = crypt(a2, v9 + 76);
if ( strncmp(v9 + 76, v12, 0xDuLL) )
{
freeuser(v9);
v9 = 0LL;
}
}
}
return v9;
}

original_code:
struct user *
login_user(char *name, char *passwd)
{
struct user *up;
char *cp;
  guest = !strcmp(name, "Guest");
  if (!(up = getuser(name)))
    return(((void *)0));
  if (guest)
  {
    struct user *tmpuser;
    tmpuser = (struct user *)mmap(0, sizeof(struct user), 0x1 | 0x2, 0x20 | 0x02, -1, 0);
    if (!tmpuser || tmpuser == (struct user *)-1)
      return(((void *)0));
    bcopy(up, tmpuser, sizeof(struct user));
    return(up = tmpuser);
  }
  if (!getenv("BBSNAME"))
  {
    cp = crypt(passwd, up->passwd);
    if (strncmp(up->passwd, cp, 13))
    {
      freeuser(up);
      return (((void *)0));
    }
  }
  return (up);
}

canonical_original_code:
struct user *login_user(char *name, char *passwd)
{
struct user *up;
char *cp;
  guest = !strcmp(name, "Guest");
  if (!(up = getuser(name)))
    return(((void *)0));
  if (guest)
  {
    struct user *tmpuser;
    tmpuser = (struct user *)mmap(0, sizeof(struct user), 0x1 | 0x2, 0x20 | 0x02, -1, 0);
    if (!tmpuser || tmpuser == (struct user *)-1)
      return(((void *)0));
    bcopy(up, tmpuser, sizeof(struct user));
    return(up = tmpuser);
  }
  if (!getenv("BBSNAME"))
  {
    cp = crypt(passwd, up->passwd);
    if (strncmp(up->passwd, cp, 13))
    {
      freeuser(up);
      return (((void *)0));
    }
  }
  return (up);
}

variable_types:
name
char *

variable_types:
passwd
char *

variable_types: struct user { long usernum; int; int; unsigned int; unsigned int an_all; unsigned int an_name; unsigned int an_addr; unsigned int an_location; unsigned int an_phone; unsigned int an_mail; unsigned int an_site; unsigned int an_www; unsigned int f_deleted; unsigned int f_inactive; unsigned int f_newbie; unsigned int f_badinfo; unsigned int f_prog; unsigned int f_restricted; unsigned int f_admin; unsigned int f_duplicate; unsigned int f_autoelf; unsigned int f_invisible; unsigned int f_trouble; unsigned int f_ansi; unsigned int f_noclient; unsigned int f_noanon; unsigned int f_namechanged; unsigned int f_ownnew; unsigned int f_twit; unsigned int; unsigned int f_xmsg; unsigned int f_nobeep; unsigned int f_elf; unsigned int; unsigned int f_aide; unsigned int; unsigned int f_xoff; unsigned int; int timescalled; int posted; long time; long timeoff; long timetot; char name[-1]; char passwd[14]; char remote[40]; char unused1[11]; char real_name[-1]; char addr1[-1]; char addr2[-1]; char city[21]; char state[21]; char zip[11]; char phone[21]; char mail[41]; char desc1[81]; char desc2[81]; char desc3[81]; char desc4[81]; char desc5[81]; char generation[200]; char forget[200]; long lastseen[200]; struct xconf { unsigned int which; unsigned int; unsigned int usernum; } xconf[60]; char www[60]; long xconftime; char unused2[176]; struct usermail { long num; long pos; } mr[150]; char unused3[9]; char aideinfo[81]; char reminder[81]; char loginname[16]; int; long totalx; char A_real_name[-1]; char A_addr1[-1]; char A_city[21]; char A_state[21]; char A_zip[11]; char A_phone[21]; char A_mail[41]; char dob_year; char dob_month; char dob_day; int; short btmpindex; unsigned short key; long keytime; long xseenpos; long xmaxpos; short xmsgnum; int; long xminpos; unsigned short yells; unsigned short vals; char unused4[24]; } *

variable_types:
cp
char *

user_defined_types: struct user { long usernum; int; int; unsigned int; unsigned int an_all; unsigned int an_name; unsigned int an_addr; unsigned int an_location; unsigned int an_phone; unsigned int an_mail; unsigned int an_site; unsigned int an_www; unsigned int f_deleted; unsigned int f_inactive; unsigned int f_newbie; unsigned int f_badinfo; unsigned int f_prog; unsigned int f_restricted; unsigned int f_admin; unsigned int f_duplicate; unsigned int f_autoelf; unsigned int f_invisible; unsigned int f_trouble; unsigned int f_ansi; unsigned int f_noclient; unsigned int f_noanon; unsigned int f_namechanged; unsigned int f_ownnew; unsigned int f_twit; unsigned int; unsigned int f_xmsg; unsigned int f_nobeep; unsigned int f_elf; unsigned int; unsigned int f_aide; unsigned int; unsigned int f_xoff; unsigned int; int timescalled; int posted; long time; long timeoff; long timetot; char name[-1]; char passwd[14]; char remote[40]; char unused1[11]; char real_name[-1]; char addr1[-1]; char addr2[-1]; char city[21]; char state[21]; char zip[11]; char phone[21]; char mail[41]; char desc1[81]; char desc2[81]; char desc3[81]; char desc4[81]; char desc5[81]; char generation[200]; char forget[200]; long lastseen[200]; struct xconf xconf[60]; char www[60]; long xconftime; char unused2[176]; struct usermail mr[150]; char unused3[9]; char aideinfo[81]; char reminder[81]; char loginname[16]; int; long totalx; char A_real_name[-1]; char A_addr1[-1]; char A_city[21]; char A_state[21]; char A_zip[11]; char A_phone[21]; char A_mail[41]; char dob_year; char dob_month; char dob_day; int; short btmpindex; unsigned short key; long keytime; long xseenpos; long xmaxpos; short xmsgnum; int; long xminpos; unsigned short yells; unsigned short vals; char unused4[24]; }


decompiled_code:
__int64 __fastcall change_password(__int64 a1, __int64 a2, const char *a3)
{
int v4; // edx
time_t v5; // rax
char v6; // si
int v7; // ecx
int v8; // edx
char v9; // cl
int v10; // edx
int v11; // eax
char *v12; // rsi
char salt[4]; // [rsp+4h] [rbp-24h] BYREF
time_t timer; // [rsp+8h] [rbp-20h] BYREF

time(&timer);
v4 = 9 * pid;
timer = v4;
LOBYTE(v4) = v4 & 0x3F;
v5 = (timer >> 6) & 0x3F;
v6 = v4 + 46;
v7 = (char)(v4 + 46);
v8 = (char)(v4 + 53);
if ( v6 > 57 )
v7 = v8;
if ( v7 > 90 )
LOBYTE(v7) = v7 + 6;
salt[0] = v7;
v9 = v5 + 46;
v10 = (char)(v5 + 46);
v11 = (char)(v5 + 53);
if ( v9 > 57 )
v10 = v11;
if ( v10 > 90 )
LOBYTE(v10) = v10 + 6;
salt[1] = v10;
salt[2] = 0;
locks(2LL);
v12 = crypt(a3, salt);
strcpy((char *)(a1 + 76), v12);
return unlocks(2LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, const char *a3)
{
int v4; // edx
time_t v5; // rax
char v6; // si
int v7; // ecx
int v8; // edx
char v9; // cl
int v10; // edx
int v11; // eax
char *v12; // rsi
char salt[4]; // [rsp+4h] [rbp-24h] BYREF
time_t timer; // [rsp+8h] [rbp-20h] BYREF

time(&timer);
v4 = 9 * pid;
timer = v4;
LOBYTE(v4) = v4 & 0x3F;
v5 = (timer >> 6) & 0x3F;
v6 = v4 + 46;
v7 = (char)(v4 + 46);
v8 = (char)(v4 + 53);
if ( v6 > 57 )
v7 = v8;
if ( v7 > 90 )
LOBYTE(v7) = v7 + 6;
salt[0] = v7;
v9 = v5 + 46;
v10 = (char)(v5 + 46);
v11 = (char)(v5 + 53);
if ( v9 > 57 )
v10 = v11;
if ( v10 > 90 )
LOBYTE(v10) = v10 + 6;
salt[1] = v10;
salt[2] = 0;
locks(2LL);
v12 = crypt(a3, salt);
strcpy((char *)(a1 + 76), v12);
return unlocks(2LL);
}

original_code:
void
change_password(struct user *up, char *old, char *new, int noold)
{
time_t salt;
char saltc[4];
int c,
        i;
                time(&salt);
  salt = 9 * pid;
  saltc[0] = salt & 077;
  saltc[1] = (salt >> 6) & 077;
  for (i = 0; i < 2; i++)
  {
    c = saltc[i] + '.';
    if (c > '9')
      c += 7;
    if (c > 'Z')
      c += 6;
    saltc[i] = c;
  }
  saltc[2] = 0;
  locks(2);
  strcpy(up->passwd, crypt(new, saltc));
  unlocks(2);
}

canonical_original_code:
void change_password(struct user *up, char *old, char *new, int noold)
{
long salt;
char saltc[4];
int c; int i;
                time(&salt);
  salt = 9 * pid;
  saltc[0] = salt & 077;
  saltc[1] = (salt >> 6) & 077;
  for (i = 0; i < 2; i++)
  {
    c = saltc[i] + '.';
    if (c > '9')
      c += 7;
    if (c > 'Z')
      c += 6;
    saltc[i] = c;
  }
  saltc[2] = 0;
  locks(2);
  strcpy(up->passwd, crypt(new, saltc));
  unlocks(2);
}

variable_types:
old
char *

variable_types:
new
char *

variable_types: noold int

variable_types: salt long

variable_types:
saltc
char [4]

variable_types: c int

variable_types: i int

user_defined_types: struct xconf { unsigned int which; unsigned int; unsigned int usernum; }


decompiled_code:
int __fastcall check_quit(char *s1)
{
int result; // eax

if ( !strcasecmp(s1, "exit") || !strcasecmp(s1, "quit") || (result = strcasecmp(s1, "logout")) == 0 )
{
puts("\n\nQuitting...");
result = my_exit(3LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1)
{
int result; // eax

if ( !strcasecmp(s1, "exit") || !strcasecmp(s1, "quit") || (result = strcasecmp(s1, "logout")) == 0 )
{
puts("\n\nQuitting...");
result = my_exit(3LL);
}
return result;
}

original_code:
void
check_quit(register char *s)
{
  if (!strcasecmp(s, "exit") || !strcasecmp(s, "quit") || !strcasecmp(s, "logout"))
  {
    printf("\n\nQuitting...\n");
    my_exit(3);
  }
}

canonical_original_code:
void check_quit(char *s)
{
  if (!strcasecmp(s, "exit") || !strcasecmp(s, "quit") || !strcasecmp(s, "logout"))
  {
    printf("\n\nQuitting...\n");
    my_exit(3);
  }
}

variable_types:
s
char *


decompiled_code:
__int64 new_user()
{
__int64 v0; // rdx
unsigned int v1; // er12
int v3; // eax
char *v4; // rbx
int v5; // ebp
const __int32_t *v6; // rsi
__int64 v7; // rax
__int64 v8; // rdx
char *v9; // rax
bool v10; // cf
bool v11; // zf
char *v12; // rsi
const char *v13; // rdi
__int64 v14; // rcx
__int64 v15; // rdi
const char *v16; // rsi
__int64 v17; // rax
char v18; // dl
size_t v19; // rbp
const unsigned __int16 *v20; // rdi
char *v21; // rbp
char v22; // r14
int v23; // eax
char v24; // r14
char v25; // cl
int v26; // eax
int v27; // edx
int v28; // edx
char *v29; // rax
__int64 v30; // rsi
__int64 v31; // r13
void *v32; // rdi
char *v33; // rbp
char v34; // al
__int64 i; // rax
__int64 v36; // rbp
const char *v37; // rsi
_BYTE *v38; // rbx
const char *v39; // rsi
const char *v40; // rcx
char salt[3]; // [rsp+Dh] [rbp-1ABh] BYREF
char v42[80]; // [rsp+10h] [rbp-1A8h] BYREF
char haystack[32]; // [rsp+60h] [rbp-158h] BYREF
char v44[48]; // [rsp+80h] [rbp-138h] BYREF
char v45[21]; // [rsp+B0h] [rbp-108h] BYREF
char v46[11]; // [rsp+C5h] [rbp-F3h] BYREF
char v47[32]; // [rsp+D0h] [rbp-E8h] BYREF
char v48[32]; // [rsp+F0h] [rbp-C8h] BYREF
char src[48]; // [rsp+110h] [rbp-A8h] BYREF
char s1[41]; // [rsp+140h] [rbp-78h] BYREF
char s2[14]; // [rsp+169h] [rbp-4Fh] BYREF
char s[65]; // [rsp+177h] [rbp-41h] BYREF

termset();
if ( nonew == 2 )
{
help("new.disallow", 0LL);
my_exit(10LL);
}
help("new.areyousure", 0LL);
mysleep(0LL);
printf("Do you still want to create a new account? (Y/N) -> ");
flush_input(0LL);
if ( !(unsigned int)yesno(0xFFFFFFFFLL) )
{
puts("\n\nOK, you'll be put back at the regular login prompt where you may login as\n'Guest' to look around.\n");
mysleep(0LL);
return (unsigned int)-1;
}
help("new.pauses", 0LL);
mysleep(0LL);
hit_return_now();
if ( nonew )
{
help("new.restricted", 0LL);
mysleep(0LL);
hit_return_now();
}
v0 = mybtmp;
*(_QWORD *)(mybtmp + 36LL) = 0x6573552077654E3CLL;
strcpy((char *)(v0 + 44), "r>");
nonew = ~nonew;
help("new.outline", 0LL);
mysleep(0LL);
hit_return_now();
while ( 2 )
{
while ( 2 )
{
help("new.name", 0LL);
mysleep(0LL);
while ( 1 )
{
while ( 1 )
{
printf("\nPlease choose a name, up to %d letters long: ", 18LL);
flush_input(0LL);
v4 = (char *)get_name(&::src, 1LL);
check_quit(v4);
v5 = strlen(v4);
if ( v5 <= 0 )
{
v3 = 0;
}
else
{
v6 = *_ctype_tolower_loc();
v7 = 0LL;
do
{
haystack[v7] = v6[v4[v7]];
v8 = v7++;
}
while ( v8 != v5 - 1 );
v3 = v5;
}
haystack[v3] = 0;
if ( !strcmp(haystack, "new") )
goto LABEL_11;
if ( strstr(haystack, "sysop") )
goto LABEL_11;
if ( strstr(haystack, "moderator") )
goto LABEL_11;
v9 = strstr(haystack, "isca");
v10 = 0;
v11 = v9 == 0LL;
if ( v9 )
goto LABEL_11;
v12 = haystack;
v13 = "guest";
v14 = 6LL;
do
{
if ( !v14 )
break;
v10 = (unsigned __int8)*v12 < (unsigned int)*v13;
v11 = *v12++ == *v13++;
--v14;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
LABEL_11:
printf("\nThat name is not allowed.");
goto LABEL_12;
}
v15 = getuser(v4, v12);
if ( !v15 )
break;
freeuser(v15);
printf("\nThat name is already in use.");
LABEL_12:
puts("\nPlease try again or hit ctrl-D to exit.");
}
if ( v5 != 1 && v5 <= 18 )
break;
v16 = "long";
if ( v5 == 1 )
v16 = "short";
printf("\nThat name is too %s. Please choose another.\n", v16);
}
help("new.password", 0LL);
mysleep(0LL);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
flush_input(0LL);
get_string("Choose a password, at least six characters long: ", 4294967288LL, s, 0xFFFFFFFFLL);
check_quit(s);
if ( (int)strlen(s) > 5 )
break;
puts("\nYour password must be at least 6 characters long. Please try again.\n");
}
if ( strcasecmp(v4, s) )
break;
puts("\nYou cannot use your username as your password!\n");
}
flush_input(0LL);
get_string("Again for verification: ", 4294967288LL, s2, 0xFFFFFFFFLL);
check_quit(s2);
v1 = strcasecmp(s, s2);
if ( !v1 )
break;
puts("\nYour passwords didn't match. Please try again.\n");
}
help("new.willneed", 0LL);
mysleep(0LL);
hit_return_now();
help("new.realname", 0LL);
mysleep(0LL);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
flush_input(0LL);
get_string("\nYour full name (first AND last!): ", 40LL, s1, 0xFFFFFFFFLL);
check_quit(s1);
v19 = strlen(s1);
if ( (int)v19 > 0 )
break;
puts("\nYou have to provide your name!");
}
v20 = *_ctype_b_loc();
v17 = 0LL;
while ( 1 )
{
v18 = s1[v17];
if ( (v20[v18] & 0x400) == 0 && v18 != 32 && (unsigned __int8)(v18 - 44) > 2u )
break;
if ( ++v17 == v19 )
goto LABEL_46;
}
if ( (int)v19 <= (int)v17 )
break;
printf("\nThe character \"%c\" is not allowed in a name.\n", (unsigned int)s1[(int)v17]);
}
LABEL_46:
if ( (int)v19 > 3
&& strchr(s1, 32)
&& s1[(int)v19 - 2] != 32
&& (s1[(int)v19 - 3] != 32 || s1[(int)v19 - 1] != 46) )
{
break;
}
puts("\nYou must provide both your full first and last names!");
}
if ( !strcmp(s1, v4) || !strcmp(s1, haystack) )
{
help("new.namesame", 0LL);
mysleep(0LL);
printf("Are you sure you want to do this? (Y/N) -> ");
flush_input(0LL);
if ( !(unsigned int)yesno(0xFFFFFFFFLL) )
{
puts("\n\nOK, we'll let you select a different name for yourself...\n");
mysleep(0LL);
continue;
}
}
break;
}
help("new.address", 0LL);
mysleep(0LL);
while ( 1 )
{
flush_input(0LL);
get_string("\nStreet address: ", 40LL, src, 0xFFFFFFFFLL);
check_quit(src);
if ( src[0] )
break;
puts("\nYou have to provide your address!");
}
help("new.city", 0LL);
mysleep(0LL);
while ( 1 )
{
flush_input(0LL);
get_string("\nCity: ", 21LL, v48, 0xFFFFFFFFLL);
check_quit(v48);
if ( v48[0] )
break;
puts("\nYou have to provide your city!");
}
help("new.state", 0LL);
mysleep(0LL);
while ( 1 )
{
flush_input(0LL);
get_string("\nState/country: ", 20LL, v47, 0xFFFFFFFFLL);
check_quit(v47);
if ( v47[0] )
break;
puts("\nYou have to provide your state/country!");
}
help("new.zip", 0LL);
mysleep(0LL);
while ( 1 )
{
flush_input(0LL);
get_string("\nZIP or mail code: ", 10LL, v46, 0xFFFFFFFFLL);
check_quit(v46);
if ( v46[0] )
break;
puts("\nYou have to provide your ZIP or mail code!");
}
help("new.phone", 0LL);
flush_input(0LL);
get_string("Phone number (including area code): ", 20LL, v45, 0xFFFFFFFFLL);
check_quit(v45);
help("new.email", 0LL);
mysleep(0LL);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
flush_input(0LL);
get_string("E-mail address: ", 40LL, v44, 0xFFFFFFFFLL);
check_quit(v44);
if ( v44[0] )
break;
puts(
"\n"
"You MUST enter a valid e-mail address to be allowed to use this BBS! If you do\n"
"not have one, we are sorry, you cannot be allowed to use this BBS!\n");
}
if ( memcmp(v44, "in%", 3uLL)
&& memcmp(v44, "IN%", 3uLL)
&& memcmp(v44, "smtp%", 5uLL)
&& memcmp(v44, "SMTP%", 5uLL) )
{
break;
}
printf(
"\n"
"If your e-mail address begins with IN%% or SMTP%%, please provide it without that\n"
"header and with any \"'s (quotation marks) removed. It should be of the form\n"
"accountname@sitename. An example would be bbs@bbs.isca.uiowa.edu\n"
"\n");
}
if ( !strchr(v44, 34) )
break;
puts(
"\n"
"A valid e-mail address does not have any \"'s (quotation marks) in it. Please\n"
"provide your e-mail address absent any quotation marks.\n");
}
v21 = strchr(v44, 64);
if ( v21 )
{
if ( strchr(v44, 46) && !strchr(v44, 32) )
break;
}
puts("\nThat is not a valid e-mail address, please try again.\n");
}
if ( ((*_ctype_b_loc())[v21[1]] & 0x800) == 0 )
break;
puts(
"\n"
"You must use a name, not a numeric address, following the '@' in your e-mail\n"
"address. Please try again.\n");
}
if ( strcasecmp(v21, "@bbs.isca.uiowa.edu") && strcasecmp(v21, "@whip.isca.uiowa.edu") )
break;
puts("\nThat is NOT your e-mail address. Please try again.\n");
}
if ( strcasecmp(v21, "@chop.isca.uiowa.edu")
&& strcasecmp(v21, "@panda.isca.uiowa.edu")
&& strcasecmp(v21, "@panda.uiowa.edu") )
{
break;
}
puts(
"\n"
"Sorry, that e-mail address is not valid for validation purposes. You cannot\n"
"use an e-mail address from the Panda system. Please try again.\n");
}
v22 = v21[5];
v21[5] = 0;
v23 = strcasecmp(v21, "@anon");
if ( v22 != 46 || v23 )
break;
puts("\nYou may not use an anonymous site as your e-mail address!\n");
}
v21[5] = v22;
printf(
"\n"
"\n"
"\n"
"\n"
"OK, now we've got everything we need. You can now review what you have\n"
"provided and be given a chance to correct yourself if you made a mistake.\n"
"\n"
"You entered:\n"
"\n"
"Name: %s\n"
"Street: %s\n"
"City: %s\n"
"State/Country: %s\n"
"ZIP/mail code: %s\n"
"Phone: %s\n"
"\n"
"E-mail address: %s\n"
"\n"
"\n",
s1,
src,
v48,
v47,
v46,
v45,
v44);
mysleep(0LL);
printf("Does this look correct? (Y/N) -> ");
flush_input(0LL);
if ( !(unsigned int)yesno(0xFFFFFFFFLL) )
{
puts(
"\n"
"\n"
"\n"
"OK, we'll start again from the beginning. Now that you know what we need, it\n"
"should go much more quickly this time...(and we'll make the pauses shorter for\n"
"you since you now hopefully know what you are doing!)\n"
"\n");
flush_input(0LL);
continue;
}
break;
}
help("new.anonymous", 0LL);
mysleep(0LL);
printf("Hide your real identity? (Y/N) -> ");
flush_input(0LL);
v24 = yesno(0xFFFFFFFFLL);
printf("\n\n\nOK, that's it, your account is now being created...");
fflush(stdout);
v25 = (9 * pid) & 0x3F;
v26 = ((9 * pid) >> 6) & 0x3F;
v27 = (char)(v25 + 46);
if ( (char)(v25 + 46) > 57 )
v27 = (char)(v25 + 53);
if ( v27 > 90 )
LOBYTE(v27) = v27 + 6;
salt[0] = v27;
v28 = (char)(v26 + 46);
if ( (char)(v26 + 46) > 57 )
v28 = (char)(v26 + 53);
if ( v28 > 90 )
LOBYTE(v28) = v28 + 6;
salt[1] = v28;
salt[2] = 0;
v29 = crypt(s, salt);
strcpy(s2, v29);
locks(4LL);
v30 = *(_QWORD *)(msg + 112LL);
v31 = v30 + 1;
if ( (v30 + 1) % 10000 )
{
*(_QWORD *)(msg + 112LL) = v31;
}
else
{
v31 = v30 + 2;
*(_QWORD *)(msg + 112LL) = v30 + 2;
}
unlocks(4LL);
v32 = (void *)adduser(v4, v31);
ouruser = v32;
if ( v32 )
{
bzero(v32, 0x1808uLL);
v33 = (char *)ouruser;
strcpy((char *)ouruser + 56, v4);
strcpy(v33 + 76, s2);
strcpy(v33 + 141, s1);
strcpy(v33 + 182, src);
strcpy(v33 + 264, v48);
strcpy(v33 + 285, v47);
strcpy(v33 + 306, v46);
strcpy(v33 + 317, v45);
strcpy(v33 + 338, v44);
v33[19] = (2 * (v24 & 1)) | ((4 * (v24 & 1)) | (8 * (v24 & 1)) | ((16 * (v24 & 1)) | (32 * (v24 & 1)) | v33[19] & 0xCF) & 0xF3) & 0xFD;
*((_DWORD *)v33 + 6) = 1;
v33[22] |= 0x10u;
v34 = v33[20] | 4;
v33[20] = v34;
v33[21] = (4 * (nonew == 0xFC)) | v33[21] & 0xFB;
v33[20] = (16 * (v31 == 1)) | ((v31 == 1) << 6) | v34 & 0xAF;
for ( i = 0LL; i != 195; ++i )
{
v33[i + 989] = -3;
v33[i + 789] = -3;
}
*((_QWORD *)v33 + 4) = *(_QWORD *)(mybtmp + 16LL);
*(_QWORD *)v33 = v31;
msync(ouruser, 0x1808uLL, 4);
v36 = ARGV;
v37 = *(const char **)(ARGV + 8LL);
if ( !v37 )
v37 = "local";
v38 = ouruser;
strncpy((char *)ouruser + 90, v37, 0x27uLL);
v38[129] = 0;
*((_QWORD *)v38 + 4) = *(_QWORD *)(mybtmp + 16LL);
if ( *(_QWORD *)(v36 + 8) )
{
v39 = *(const char **)(v36 + 16);
if ( !v39 )
v39 = &::src;
}
else
{
v39 = &::src;
}
strcpy(v38 + 5843, v39);
add_loggedin(v38);
v40 = "@";
if ( !*((_BYTE *)ouruser + 5843) )
v40 = &::src;
sprintf(v42, "NEWUSER %s%s%s", (const char *)ouruser + 5843, v40, (const char *)ouruser + 90);
logevent(v42);
*((_QWORD *)ouruser + 760) = 1LL;
puts("\n\n\n\nYour account has been created.\n\n");
mysleep(0LL);
if ( (*((_BYTE *)ouruser + 21) & 4) == 0 )
genkey();
hit_return_now();
help("new.reminder", 0LL);
mysleep(1LL);
hit_return_now();
help("new.newinfo", 0LL);
mysleep(1LL);
hit_return_now();
if ( (*((_BYTE *)ouruser + 21) & 4) != 0 )
{
help("new.restrictedbye", 0LL);
my_exit(10LL);
}
*(_BYTE *)(mybtmp + 118LL) = 0;
nonew = 0;
v1 = 1;
}
else
{
errlog("Failed user creation of %s", v4);
}
return v1;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rdx
unsigned int v1; // er12
int v3; // eax
char *v4; // rbx
int v5; // ebp
const __int32_t *v6; // rsi
__int64 v7; // rax
__int64 v8; // rdx
char *v9; // rax
bool v10; // cf
bool v11; // zf
char *v12; // rsi
const char *v13; // rdi
__int64 v14; // rcx
__int64 v15; // rdi
const char *v16; // rsi
__int64 v17; // rax
char v18; // dl
size_t v19; // rbp
const unsigned __int16 *v20; // rdi
char *v21; // rbp
char v22; // r14
int v23; // eax
char v24; // r14
char v25; // cl
int v26; // eax
int v27; // edx
int v28; // edx
char *v29; // rax
__int64 v30; // rsi
__int64 v31; // r13
void *v32; // rdi
char *v33; // rbp
char v34; // al
__int64 i; // rax
__int64 v36; // rbp
const char *v37; // rsi
_BYTE *v38; // rbx
const char *v39; // rsi
const char *v40; // rcx
char salt[3]; // [rsp+Dh] [rbp-1ABh] BYREF
char v42[80]; // [rsp+10h] [rbp-1A8h] BYREF
char haystack[32]; // [rsp+60h] [rbp-158h] BYREF
char v44[48]; // [rsp+80h] [rbp-138h] BYREF
char v45[21]; // [rsp+B0h] [rbp-108h] BYREF
char v46[11]; // [rsp+C5h] [rbp-F3h] BYREF
char v47[32]; // [rsp+D0h] [rbp-E8h] BYREF
char v48[32]; // [rsp+F0h] [rbp-C8h] BYREF
char src[48]; // [rsp+110h] [rbp-A8h] BYREF
char s1[41]; // [rsp+140h] [rbp-78h] BYREF
char s2[14]; // [rsp+169h] [rbp-4Fh] BYREF
char s[65]; // [rsp+177h] [rbp-41h] BYREF

termset();
if ( nonew == 2 )
{
help("new.disallow", 0LL);
my_exit(10LL);
}
help("new.areyousure", 0LL);
mysleep(0LL);
printf("Do you still want to create a new account? (Y/N) -> ");
flush_input(0LL);
if ( !(unsigned int)yesno(0xFFFFFFFFLL) )
{
puts("\n\nOK, you'll be put back at the regular login prompt where you may login as\n'Guest' to look around.\n");
mysleep(0LL);
return (unsigned int)-1;
}
help("new.pauses", 0LL);
mysleep(0LL);
hit_return_now();
if ( nonew )
{
help("new.restricted", 0LL);
mysleep(0LL);
hit_return_now();
}
v0 = mybtmp;
*(_QWORD *)(mybtmp + 36LL) = 0x6573552077654E3CLL;
strcpy((char *)(v0 + 44), "r>");
nonew = ~nonew;
help("new.outline", 0LL);
mysleep(0LL);
hit_return_now();
while ( 2 )
{
while ( 2 )
{
help("new.name", 0LL);
mysleep(0LL);
while ( 1 )
{
while ( 1 )
{
printf("\nPlease choose a name, up to %d letters long: ", 18LL);
flush_input(0LL);
v4 = (char *)get_name(&::src, 1LL);
func2(v4);
v5 = strlen(v4);
if ( v5 <= 0 )
{
v3 = 0;
}
else
{
v6 = *_ctype_tolower_loc();
v7 = 0LL;
do
{
haystack[v7] = v6[v4[v7]];
v8 = v7++;
}
while ( v8 != v5 - 1 );
v3 = v5;
}
haystack[v3] = 0;
if ( !strcmp(haystack, "new") )
goto LABEL_11;
if ( strstr(haystack, "sysop") )
goto LABEL_11;
if ( strstr(haystack, "moderator") )
goto LABEL_11;
v9 = strstr(haystack, "isca");
v10 = 0;
v11 = v9 == 0LL;
if ( v9 )
goto LABEL_11;
v12 = haystack;
v13 = "guest";
v14 = 6LL;
do
{
if ( !v14 )
break;
v10 = (unsigned __int8)*v12 < (unsigned int)*v13;
v11 = *v12++ == *v13++;
--v14;
}
while ( v11 );
if ( (!v10 && !v11) == v10 )
{
LABEL_11:
printf("\nThat name is not allowed.");
goto LABEL_12;
}
v15 = getuser(v4, v12);
if ( !v15 )
break;
freeuser(v15);
printf("\nThat name is already in use.");
LABEL_12:
puts("\nPlease try again or hit ctrl-D to exit.");
}
if ( v5 != 1 && v5 <= 18 )
break;
v16 = "long";
if ( v5 == 1 )
v16 = "short";
printf("\nThat name is too %s. Please choose another.\n", v16);
}
help("new.password", 0LL);
mysleep(0LL);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
flush_input(0LL);
get_string("Choose a password, at least six characters long: ", 4294967288LL, s, 0xFFFFFFFFLL);
func2(s);
if ( (int)strlen(s) > 5 )
break;
puts("\nYour password must be at least 6 characters long. Please try again.\n");
}
if ( strcasecmp(v4, s) )
break;
puts("\nYou cannot use your username as your password!\n");
}
flush_input(0LL);
get_string("Again for verification: ", 4294967288LL, s2, 0xFFFFFFFFLL);
func2(s2);
v1 = strcasecmp(s, s2);
if ( !v1 )
break;
puts("\nYour passwords didn't match. Please try again.\n");
}
help("new.willneed", 0LL);
mysleep(0LL);
hit_return_now();
help("new.realname", 0LL);
mysleep(0LL);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
flush_input(0LL);
get_string("\nYour full name (first AND last!): ", 40LL, s1, 0xFFFFFFFFLL);
func2(s1);
v19 = strlen(s1);
if ( (int)v19 > 0 )
break;
puts("\nYou have to provide your name!");
}
v20 = *_ctype_b_loc();
v17 = 0LL;
while ( 1 )
{
v18 = s1[v17];
if ( (v20[v18] & 0x400) == 0 && v18 != 32 && (unsigned __int8)(v18 - 44) > 2u )
break;
if ( ++v17 == v19 )
goto LABEL_46;
}
if ( (int)v19 <= (int)v17 )
break;
printf("\nThe character \"%c\" is not allowed in a name.\n", (unsigned int)s1[(int)v17]);
}
LABEL_46:
if ( (int)v19 > 3
&& strchr(s1, 32)
&& s1[(int)v19 - 2] != 32
&& (s1[(int)v19 - 3] != 32 || s1[(int)v19 - 1] != 46) )
{
break;
}
puts("\nYou must provide both your full first and last names!");
}
if ( !strcmp(s1, v4) || !strcmp(s1, haystack) )
{
help("new.namesame", 0LL);
mysleep(0LL);
printf("Are you sure you want to do this? (Y/N) -> ");
flush_input(0LL);
if ( !(unsigned int)yesno(0xFFFFFFFFLL) )
{
puts("\n\nOK, we'll let you select a different name for yourself...\n");
mysleep(0LL);
continue;
}
}
break;
}
help("new.address", 0LL);
mysleep(0LL);
while ( 1 )
{
flush_input(0LL);
get_string("\nStreet address: ", 40LL, src, 0xFFFFFFFFLL);
func2(src);
if ( src[0] )
break;
puts("\nYou have to provide your address!");
}
help("new.city", 0LL);
mysleep(0LL);
while ( 1 )
{
flush_input(0LL);
get_string("\nCity: ", 21LL, v48, 0xFFFFFFFFLL);
func2(v48);
if ( v48[0] )
break;
puts("\nYou have to provide your city!");
}
help("new.state", 0LL);
mysleep(0LL);
while ( 1 )
{
flush_input(0LL);
get_string("\nState/country: ", 20LL, v47, 0xFFFFFFFFLL);
func2(v47);
if ( v47[0] )
break;
puts("\nYou have to provide your state/country!");
}
help("new.zip", 0LL);
mysleep(0LL);
while ( 1 )
{
flush_input(0LL);
get_string("\nZIP or mail code: ", 10LL, v46, 0xFFFFFFFFLL);
func2(v46);
if ( v46[0] )
break;
puts("\nYou have to provide your ZIP or mail code!");
}
help("new.phone", 0LL);
flush_input(0LL);
get_string("Phone number (including area code): ", 20LL, v45, 0xFFFFFFFFLL);
func2(v45);
help("new.email", 0LL);
mysleep(0LL);
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
flush_input(0LL);
get_string("E-mail address: ", 40LL, v44, 0xFFFFFFFFLL);
func2(v44);
if ( v44[0] )
break;
puts(
"\n"
"You MUST enter a valid e-mail address to be allowed to use this BBS! If you do\n"
"not have one, we are sorry, you cannot be allowed to use this BBS!\n");
}
if ( memcmp(v44, "in%", 3uLL)
&& memcmp(v44, "IN%", 3uLL)
&& memcmp(v44, "smtp%", 5uLL)
&& memcmp(v44, "SMTP%", 5uLL) )
{
break;
}
printf(
"\n"
"If your e-mail address begins with IN%% or SMTP%%, please provide it without that\n"
"header and with any \"'s (quotation marks) removed. It should be of the form\n"
"accountname@sitename. An example would be bbs@bbs.isca.uiowa.edu\n"
"\n");
}
if ( !strchr(v44, 34) )
break;
puts(
"\n"
"A valid e-mail address does not have any \"'s (quotation marks) in it. Please\n"
"provide your e-mail address absent any quotation marks.\n");
}
v21 = strchr(v44, 64);
if ( v21 )
{
if ( strchr(v44, 46) && !strchr(v44, 32) )
break;
}
puts("\nThat is not a valid e-mail address, please try again.\n");
}
if ( ((*_ctype_b_loc())[v21[1]] & 0x800) == 0 )
break;
puts(
"\n"
"You must use a name, not a numeric address, following the '@' in your e-mail\n"
"address. Please try again.\n");
}
if ( strcasecmp(v21, "@bbs.isca.uiowa.edu") && strcasecmp(v21, "@whip.isca.uiowa.edu") )
break;
puts("\nThat is NOT your e-mail address. Please try again.\n");
}
if ( strcasecmp(v21, "@chop.isca.uiowa.edu")
&& strcasecmp(v21, "@panda.isca.uiowa.edu")
&& strcasecmp(v21, "@panda.uiowa.edu") )
{
break;
}
puts(
"\n"
"Sorry, that e-mail address is not valid for validation purposes. You cannot\n"
"use an e-mail address from the Panda system. Please try again.\n");
}
v22 = v21[5];
v21[5] = 0;
v23 = strcasecmp(v21, "@anon");
if ( v22 != 46 || v23 )
break;
puts("\nYou may not use an anonymous site as your e-mail address!\n");
}
v21[5] = v22;
printf(
"\n"
"\n"
"\n"
"\n"
"OK, now we've got everything we need. You can now review what you have\n"
"provided and be given a chance to correct yourself if you made a mistake.\n"
"\n"
"You entered:\n"
"\n"
"Name: %s\n"
"Street: %s\n"
"City: %s\n"
"State/Country: %s\n"
"ZIP/mail code: %s\n"
"Phone: %s\n"
"\n"
"E-mail address: %s\n"
"\n"
"\n",
s1,
src,
v48,
v47,
v46,
v45,
v44);
mysleep(0LL);
printf("Does this look correct? (Y/N) -> ");
flush_input(0LL);
if ( !(unsigned int)yesno(0xFFFFFFFFLL) )
{
puts(
"\n"
"\n"
"\n"
"OK, we'll start again from the beginning. Now that you know what we need, it\n"
"should go much more quickly this time...(and we'll make the pauses shorter for\n"
"you since you now hopefully know what you are doing!)\n"
"\n");
flush_input(0LL);
continue;
}
break;
}
help("new.anonymous", 0LL);
mysleep(0LL);
printf("Hide your real identity? (Y/N) -> ");
flush_input(0LL);
v24 = yesno(0xFFFFFFFFLL);
printf("\n\n\nOK, that's it, your account is now being created...");
fflush(stdout);
v25 = (9 * pid) & 0x3F;
v26 = ((9 * pid) >> 6) & 0x3F;
v27 = (char)(v25 + 46);
if ( (char)(v25 + 46) > 57 )
v27 = (char)(v25 + 53);
if ( v27 > 90 )
LOBYTE(v27) = v27 + 6;
salt[0] = v27;
v28 = (char)(v26 + 46);
if ( (char)(v26 + 46) > 57 )
v28 = (char)(v26 + 53);
if ( v28 > 90 )
LOBYTE(v28) = v28 + 6;
salt[1] = v28;
salt[2] = 0;
v29 = crypt(s, salt);
strcpy(s2, v29);
locks(4LL);
v30 = *(_QWORD *)(msg + 112LL);
v31 = v30 + 1;
if ( (v30 + 1) % 10000 )
{
*(_QWORD *)(msg + 112LL) = v31;
}
else
{
v31 = v30 + 2;
*(_QWORD *)(msg + 112LL) = v30 + 2;
}
unlocks(4LL);
v32 = (void *)adduser(v4, v31);
ouruser = v32;
if ( v32 )
{
bzero(v32, 0x1808uLL);
v33 = (char *)ouruser;
strcpy((char *)ouruser + 56, v4);
strcpy(v33 + 76, s2);
strcpy(v33 + 141, s1);
strcpy(v33 + 182, src);
strcpy(v33 + 264, v48);
strcpy(v33 + 285, v47);
strcpy(v33 + 306, v46);
strcpy(v33 + 317, v45);
strcpy(v33 + 338, v44);
v33[19] = (2 * (v24 & 1)) | ((4 * (v24 & 1)) | (8 * (v24 & 1)) | ((16 * (v24 & 1)) | (32 * (v24 & 1)) | v33[19] & 0xCF) & 0xF3) & 0xFD;
*((_DWORD *)v33 + 6) = 1;
v33[22] |= 0x10u;
v34 = v33[20] | 4;
v33[20] = v34;
v33[21] = (4 * (nonew == 0xFC)) | v33[21] & 0xFB;
v33[20] = (16 * (v31 == 1)) | ((v31 == 1) << 6) | v34 & 0xAF;
for ( i = 0LL; i != 195; ++i )
{
v33[i + 989] = -3;
v33[i + 789] = -3;
}
*((_QWORD *)v33 + 4) = *(_QWORD *)(mybtmp + 16LL);
*(_QWORD *)v33 = v31;
msync(ouruser, 0x1808uLL, 4);
v36 = ARGV;
v37 = *(const char **)(ARGV + 8LL);
if ( !v37 )
v37 = "local";
v38 = ouruser;
strncpy((char *)ouruser + 90, v37, 0x27uLL);
v38[129] = 0;
*((_QWORD *)v38 + 4) = *(_QWORD *)(mybtmp + 16LL);
if ( *(_QWORD *)(v36 + 8) )
{
v39 = *(const char **)(v36 + 16);
if ( !v39 )
v39 = &::src;
}
else
{
v39 = &::src;
}
strcpy(v38 + 5843, v39);
add_loggedin(v38);
v40 = "@";
if ( !*((_BYTE *)ouruser + 5843) )
v40 = &::src;
sprintf(v42, "NEWUSER %s%s%s", (const char *)ouruser + 5843, v40, (const char *)ouruser + 90);
logevent(v42);
*((_QWORD *)ouruser + 760) = 1LL;
puts("\n\n\n\nYour account has been created.\n\n");
mysleep(0LL);
if ( (*((_BYTE *)ouruser + 21) & 4) == 0 )
genkey();
hit_return_now();
help("new.reminder", 0LL);
mysleep(1LL);
hit_return_now();
help("new.newinfo", 0LL);
mysleep(1LL);
hit_return_now();
if ( (*((_BYTE *)ouruser + 21) & 4) != 0 )
{
help("new.restrictedbye", 0LL);
my_exit(10LL);
}
*(_BYTE *)(mybtmp + 118LL) = 0;
nonew = 0;
v1 = 1;
}
else
{
errlog("Failed user creation of %s", v4);
}
return v1;
}

original_code:
int
new_user(void)
{
  register int i;
  register int j;
  register int c;
  register char *p;
  register char *name;
  register struct user *tmpuser = ((void *)0);
  char pas[9];
  char pas2[14];
  char real_name[40 +1];
  char addr1[40 +1];
  char city[21];
  char statename[21];
  char zip[11];
  char phone[21];
  char mail[40 +1];
  char name2[19 +1];
  char work[80];
  int anonymous;
  int salt;
  char saltc[3];
  long usernum;
  int hold = 0;
  termset();
  if (nonew == 2)
  {
    help("new.disallow", 0);
    my_exit(10);
  }
  help("new.areyousure", 0);
  mysleep(hold);
  printf("Do you still want to create a new account? (Y/N) -> ");
  flush_input(0);
  if (!yesno(-1))
  {
    printf("\n\nOK, you'll be put back at the regular login prompt where you may login as\n'Guest' to look around.\n\n");
    mysleep(hold);
    return(-1);
  }
  help("new.pauses", 0);
  mysleep(hold * 2);
  hit_return_now();
  if (nonew)
  {
    help("new.restricted", 0);
    mysleep(hold * 6);
    hit_return_now();
  }
  strcpy(mybtmp->name, "<New User>");
  nonew = -1 - nonew;
  help("new.outline", 0);
  mysleep(hold * 4);
  hit_return_now();
  for (;;)
  {
    help("new.name", 0);
    mysleep(hold * 3);
    for (;;)
    {
      printf("\nPlease choose a name, up to %d letters long: ", 19 - 1);
      flush_input(0);
      name = get_name("", 1);
      check_quit(name);
      for (i = 0, j = strlen(name); i < j; i++)
        name2[i] = tolower(name[i]);
      name2[i] = 0;
      if (!strcmp(name2, "new") || strstr(name2, "sysop") || strstr(name2, "moderator") || strstr(name2, "isca") || !strcmp(name2, "guest") || (tmpuser = getuser(name)))
      {
        if (tmpuser)
        {
          freeuser(tmpuser);
          tmpuser = ((void *)0);
   printf("\nThat name is already in use.");
        }
 else
   printf("\nThat name is not allowed.");
        printf("\nPlease try again or hit ctrl-D to exit.\n");
      }
      else if (j == 1 || j >= 19)
        printf("\nThat name is too %s.  Please choose another.\n", j == 1 ? "short" : "long");
      else
        break;
    }
    help("new.password", 0);
    mysleep(hold * 3);
    for (;;)
    {
      flush_input(0);
      get_string("Choose a password, at least six characters long: ", -8, pas, -1);
      check_quit(pas);
      if ((j = strlen(pas)) < 6)
        printf("\nYour password must be at least 6 characters long.  Please try again.\n\n");
      else if (!strcasecmp(name, pas))
        printf("\nYou cannot use your username as your password!\n\n");
      else
      {
        flush_input(0);
        get_string("Again for verification: ", -8, pas2, -1);
        check_quit(pas2);
        if (!strcasecmp(pas, pas2))
          break;
        printf("\nYour passwords didn't match.  Please try again.\n\n");
      }
    }
    help("new.willneed", 0);
    mysleep(hold * 3);
    hit_return_now();
    help("new.realname", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nYour full name (first AND last!): ", 40, real_name, -1);
      check_quit(real_name);
      for (i = 0, j = strlen(real_name); i < j; i++)
 if (!((*__ctype_b_loc ())[(int) ((real_name[i]))] & (unsigned short int) _ISalpha) && real_name[i] != ' ' && real_name[i] != '-' && real_name[i] != '.' && real_name[i] != ',')
   break;
      if (!j)
 printf("\nYou have to provide your name!\n");
      else if (i < j)
 printf("\nThe character \"%c\" is not allowed in a name.\n", real_name[i]);
      else if (j < 4 || !strchr(real_name, ' ') || real_name[j - 2] == ' ' || (real_name[j - 3] == ' ' && real_name[j - 1] == '.'))
 printf("\nYou must provide both your full first and last names!\n");
      else if (!strcmp(real_name, name) || !strcmp(real_name, name2))
      {
 help("new.namesame", 0);
        mysleep(hold);
        printf("Are you sure you want to do this? (Y/N) -> ");
 flush_input(0);
 if (!yesno(-1))
 {
   printf("\n\nOK, we'll let you select a different name for yourself...\n\n");
   mysleep(hold);
   name = 0;
 }
 break;
      }
      else
 break;
    }
    if (!name)
      continue;
    help("new.address", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nStreet address: ", 40, addr1, -1);
      check_quit(addr1);
      if (!strlen(addr1))
        printf("\nYou have to provide your address!\n");
      else
        break;
    }
    help("new.city", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nCity: ", sizeof city, city, -1);
      check_quit(city);
      if (!strlen(city))
        printf("\nYou have to provide your city!\n");
      else
        break;
    }
    help("new.state", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nState/country: ", 20, statename, -1);
      check_quit(statename);
      if (!strlen(statename))
        printf("\nYou have to provide your state/country!\n");
      else
        break;
    }
    help("new.zip", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nZIP or mail code: ", 10, zip, -1);
      check_quit(zip);
      if (!strlen(zip))
        printf("\nYou have to provide your ZIP or mail code!\n");
      else
        break;
    }
    help("new.phone", 0);
    flush_input(hold * 3);
    get_string("Phone number (including area code): ", 20, phone, -1);
    check_quit(phone);
    help("new.email", 0);
    mysleep(hold * 4);
    for (;;)
    {
      flush_input(0);
      get_string("E-mail address: ", 40, mail, -1);
      check_quit(mail);
      if (!*mail)
        printf("\nYou MUST enter a valid e-mail address to be allowed to use this BBS!  If you do\nnot have one, we are sorry, you cannot be allowed to use this BBS!\n\n");
      else if (!strncmp(mail, "in%", 3) || !strncmp(mail, "IN%", 3) || !strncmp(mail, "smtp%", 5) || !strncmp(mail, "SMTP%", 5))
        printf("\nIf your e-mail address begins with IN%% or SMTP%%, please provide it without that\nheader and with any \"'s (quotation marks) removed.  It should be of the form\naccountname@sitename.  An example would be bbs@bbs.isca.uiowa.edu\n\n");
      else if (strchr(mail, '"'))
        printf("\nA valid e-mail address does not have any \"'s (quotation marks) in it.  Please\nprovide your e-mail address absent any quotation marks.\n\n");
      else if (!(p = strchr(mail, '@')) || !strchr(mail, '.') || strchr(mail, ' '))
        printf("\nThat is not a valid e-mail address, please try again.\n\n");
      else if (((*__ctype_b_loc ())[(int) ((p[1]))] & (unsigned short int) _ISdigit))
 printf("\nYou must use a name, not a numeric address, following the '@' in your e-mail\naddress.  Please try again.\n\n");
      else if (!strcasecmp(p, "@bbs.isca.uiowa.edu") || !strcasecmp(p, "@whip.isca.uiowa.edu"))
        printf("\nThat is NOT your e-mail address.  Please try again.\n\n");
      else if (!strcasecmp(p, "@chop.isca.uiowa.edu") || !strcasecmp(p, "@panda.isca.uiowa.edu") || !strcasecmp(p, "@panda.uiowa.edu"))
 printf("\nSorry, that e-mail address is not valid for validation purposes.  You cannot\nuse an e-mail address from the Panda system.  Please try again.\n\n");
      else
      {
 c = p[5];
 p[5] = 0;
 if (!strcasecmp(p, "@anon") && c == '.')
          printf("\nYou may not use an anonymous site as your e-mail address!\n\n");
 else
 {
   p[5] = c;
   break;
 }
      }
    }
    printf("\n\n\n\nOK, now we've got everything we need.  You can now review what you have\nprovided and be given a chance to correct yourself if you made a mistake.\n\nYou entered:\n\nName: %s\nStreet: %s\nCity: %s\nState/Country: %s\nZIP/mail code: %s\nPhone: %s\n\nE-mail address: %s\n\n\n", real_name, addr1, city, statename, zip, phone, mail);
    mysleep(hold * 3);
    printf("Does this look correct? (Y/N) -> ");
    flush_input(0);
    if (yesno(-1))
      break;
    printf("\n\n\nOK, we'll start again from the beginning.  Now that you know what we need, it\nshould go much more quickly this time...(and we'll make the pauses shorter for\nyou since you now hopefully know what you are doing!)\n\n\n");
    flush_input(hold);
    hold = 0;
  }
  hold = 0;
  help("new.anonymous", 0);
  mysleep(hold);
  printf("Hide your real identity? (Y/N) -> ");
  flush_input(0);
  anonymous = yesno(-1);
  printf("\n\n\nOK, that's it, your account is now being created...");
  fflush(stdout);
  salt = 9 * pid;
  saltc[0] = salt & 077;
  saltc[1] = (salt >> 6) & 077;
  for (i = 0; i < 2; i++)
  {
    c = saltc[i] + '.';
    if (c > '9')
      c += 7;
    if (c > 'Z')
      c += 6;
    saltc[i] = c;
  }
  saltc[2] = 0;
  strcpy(pas2, crypt(pas, saltc));
  locks(4);
  usernum = ++msg->eternal;
  if (!(usernum % 10000))
    usernum = ++msg->eternal;
  unlocks(4);
  if (!(ouruser = adduser(name, usernum)))
  {
    errlog("Failed user creation of %s", name);
    return(0);
  }
  bzero((void *)ouruser, sizeof(struct user));
  strcpy(ouruser->name, name);
  strcpy(ouruser->passwd, pas2);
  strcpy(ouruser->real_name, real_name);
  strcpy(ouruser->addr1, addr1);
  strcpy(ouruser->city, city);
  strcpy(ouruser->state, statename);
  strcpy(ouruser->zip, zip);
  strcpy(ouruser->phone, phone);
  strcpy(ouruser->mail, mail);
  ouruser->an_name = ouruser->an_addr = ouruser->an_location = ouruser->an_phone = ouruser->an_mail = anonymous;
  ouruser->timescalled = 1;
  ouruser->f_newbie = ouruser->f_nobeep = 1;
  ouruser->f_trouble = (nonew == -4);
  ouruser->f_prog = ouruser->f_admin = usernum == 1;
  for (i = 5; i < 200; i++)
    ouruser->generation[i] = ouruser->forget[i] = (-3L);
  ouruser->time = mybtmp->time;
  ouruser->usernum = usernum;
  msync((void *)ouruser, sizeof(struct user), 4);
  strncpy(ouruser->remote, ARGV[1] ? ARGV[1] : "local", sizeof ouruser->remote);
  ouruser->remote[sizeof ouruser->remote - 1] = 0;
  ouruser->time = mybtmp->time;
  strcpy(ouruser->loginname, ARGV[1] && ARGV[2] ? ARGV[2] : "");
  add_loggedin(ouruser);
  sprintf(work, "NEWUSER %s%s%s", ouruser->loginname, *ouruser->loginname ? "@" : "", ouruser->remote);
  logevent(work);
  ouruser->keytime = 1;
  printf("\n\n\n\nYour account has been created.\n\n\n");
  mysleep(hold);
  if (!ouruser->f_trouble)
    genkey(ouruser);
  hit_return_now();
  help("new.reminder", 0);
  mysleep(1);
  hit_return_now();
  help("new.newinfo", 0);
  mysleep(1);
  hit_return_now();
  if (ouruser->f_trouble)
  {
    help("new.restrictedbye", 0);
    my_exit(10);
  }
  mybtmp->nox = 0;
  nonew = 0;
  return(1);
}

canonical_original_code:
int new_user()
{
  register int i;
  register int j;
  register int c;
  register char *p;
  register char *name;
  register struct user *tmpuser = ((void *)0);
  char pas[9];
  char pas2[14];
  char real_name[-1];
  char addr1[-1];
  char city[21];
  char statename[21];
  char zip[11];
  char phone[21];
  char mail[-1];
  char name2[-1];
  char work[80];
  int anonymous;
  int salt;
  char saltc[3];
  long usernum;
  int hold = 0;
  termset();
  if (nonew == 2)
  {
    help("new.disallow", 0);
    my_exit(10);
  }
  help("new.areyousure", 0);
  mysleep(hold);
  printf("Do you still want to create a new account? (Y/N) -> ");
  flush_input(0);
  if (!yesno(-1))
  {
    printf("\n\nOK, you'll be put back at the regular login prompt where you may login as\n'Guest' to look around.\n\n");
    mysleep(hold);
    return(-1);
  }
  help("new.pauses", 0);
  mysleep(hold * 2);
  hit_return_now();
  if (nonew)
  {
    help("new.restricted", 0);
    mysleep(hold * 6);
    hit_return_now();
  }
  strcpy(mybtmp->name, "<New User>");
  nonew = -1 - nonew;
  help("new.outline", 0);
  mysleep(hold * 4);
  hit_return_now();
  for (;;)
  {
    help("new.name", 0);
    mysleep(hold * 3);
    for (;;)
    {
      printf("\nPlease choose a name, up to %d letters long: ", 19 - 1);
      flush_input(0);
      name = get_name("", 1);
      check_quit(name);
      for (i = 0, j = strlen(name); i < j; i++)
        name2[i] = tolower(name[i]);
      name2[i] = 0;
      if (!strcmp(name2, "new") || strstr(name2, "sysop") || strstr(name2, "moderator") || strstr(name2, "isca") || !strcmp(name2, "guest") || (tmpuser = getuser(name)))
      {
        if (tmpuser)
        {
          freeuser(tmpuser);
          tmpuser = ((void *)0);
   printf("\nThat name is already in use.");
        }
 else
   printf("\nThat name is not allowed.");
        printf("\nPlease try again or hit ctrl-D to exit.\n");
      }
      else if (j == 1 || j >= 19)
        printf("\nThat name is too %s.  Please choose another.\n", j == 1 ? "short" : "long");
      else
        break;
    }
    help("new.password", 0);
    mysleep(hold * 3);
    for (;;)
    {
      flush_input(0);
      get_string("Choose a password, at least six characters long: ", -8, pas, -1);
      check_quit(pas);
      if ((j = strlen(pas)) < 6)
        printf("\nYour password must be at least 6 characters long.  Please try again.\n\n");
      else if (!strcasecmp(name, pas))
        printf("\nYou cannot use your username as your password!\n\n");
      else
      {
        flush_input(0);
        get_string("Again for verification: ", -8, pas2, -1);
        check_quit(pas2);
        if (!strcasecmp(pas, pas2))
          break;
        printf("\nYour passwords didn't match.  Please try again.\n\n");
      }
    }
    help("new.willneed", 0);
    mysleep(hold * 3);
    hit_return_now();
    help("new.realname", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nYour full name (first AND last!): ", 40, real_name, -1);
      check_quit(real_name);
      for (i = 0, j = strlen(real_name); i < j; i++)
 if (!((*__ctype_b_loc ())[(int) ((real_name[i]))] & (unsigned short) _ISalpha) && real_name[i] != ' ' && real_name[i] != '-' && real_name[i] != '.' && real_name[i] != ',')
   break;
      if (!j)
 printf("\nYou have to provide your name!\n");
      else if (i < j)
 printf("\nThe character \"%c\" is not allowed in a name.\n", real_name[i]);
      else if (j < 4 || !strchr(real_name, ' ') || real_name[j - 2] == ' ' || (real_name[j - 3] == ' ' && real_name[j - 1] == '.'))
 printf("\nYou must provide both your full first and last names!\n");
      else if (!strcmp(real_name, name) || !strcmp(real_name, name2))
      {
 help("new.namesame", 0);
        mysleep(hold);
        printf("Are you sure you want to do this? (Y/N) -> ");
 flush_input(0);
 if (!yesno(-1))
 {
   printf("\n\nOK, we'll let you select a different name for yourself...\n\n");
   mysleep(hold);
   name = 0;
 }
 break;
      }
      else
 break;
    }
    if (!name)
      continue;
    help("new.address", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nStreet address: ", 40, addr1, -1);
      check_quit(addr1);
      if (!strlen(addr1))
        printf("\nYou have to provide your address!\n");
      else
        break;
    }
    help("new.city", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nCity: ", sizeof city, city, -1);
      check_quit(city);
      if (!strlen(city))
        printf("\nYou have to provide your city!\n");
      else
        break;
    }
    help("new.state", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nState/country: ", 20, statename, -1);
      check_quit(statename);
      if (!strlen(statename))
        printf("\nYou have to provide your state/country!\n");
      else
        break;
    }
    help("new.zip", 0);
    mysleep(hold);
    for (;;)
    {
      flush_input(0);
      get_string("\nZIP or mail code: ", 10, zip, -1);
      check_quit(zip);
      if (!strlen(zip))
        printf("\nYou have to provide your ZIP or mail code!\n");
      else
        break;
    }
    help("new.phone", 0);
    flush_input(hold * 3);
    get_string("Phone number (including area code): ", 20, phone, -1);
    check_quit(phone);
    help("new.email", 0);
    mysleep(hold * 4);
    for (;;)
    {
      flush_input(0);
      get_string("E-mail address: ", 40, mail, -1);
      check_quit(mail);
      if (!*mail)
        printf("\nYou MUST enter a valid e-mail address to be allowed to use this BBS!  If you do\nnot have one, we are sorry, you cannot be allowed to use this BBS!\n\n");
      else if (!strncmp(mail, "in%", 3) || !strncmp(mail, "IN%", 3) || !strncmp(mail, "smtp%", 5) || !strncmp(mail, "SMTP%", 5))
        printf("\nIf your e-mail address begins with IN%% or SMTP%%, please provide it without that\nheader and with any \"'s (quotation marks) removed.  It should be of the form\naccountname@sitename.  An example would be bbs@bbs.isca.uiowa.edu\n\n");
      else if (strchr(mail, '"'))
        printf("\nA valid e-mail address does not have any \"'s (quotation marks) in it.  Please\nprovide your e-mail address absent any quotation marks.\n\n");
      else if (!(p = strchr(mail, '@')) || !strchr(mail, '.') || strchr(mail, ' '))
        printf("\nThat is not a valid e-mail address, please try again.\n\n");
      else if (((*__ctype_b_loc ())[(int) ((p[1]))] & (unsigned short) _ISdigit))
 printf("\nYou must use a name, not a numeric address, following the '@' in your e-mail\naddress.  Please try again.\n\n");
      else if (!strcasecmp(p, "@bbs.isca.uiowa.edu") || !strcasecmp(p, "@whip.isca.uiowa.edu"))
        printf("\nThat is NOT your e-mail address.  Please try again.\n\n");
      else if (!strcasecmp(p, "@chop.isca.uiowa.edu") || !strcasecmp(p, "@panda.isca.uiowa.edu") || !strcasecmp(p, "@panda.uiowa.edu"))
 printf("\nSorry, that e-mail address is not valid for validation purposes.  You cannot\nuse an e-mail address from the Panda system.  Please try again.\n\n");
      else
      {
 c = p[5];
 p[5] = 0;
 if (!strcasecmp(p, "@anon") && c == '.')
          printf("\nYou may not use an anonymous site as your e-mail address!\n\n");
 else
 {
   p[5] = c;
   break;
 }
      }
    }
    printf("\n\n\n\nOK, now we've got everything we need.  You can now review what you have\nprovided and be given a chance to correct yourself if you made a mistake.\n\nYou entered:\n\nName: %s\nStreet: %s\nCity: %s\nState/Country: %s\nZIP/mail code: %s\nPhone: %s\n\nE-mail address: %s\n\n\n", real_name, addr1, city, statename, zip, phone, mail);
    mysleep(hold * 3);
    printf("Does this look correct? (Y/N) -> ");
    flush_input(0);
    if (yesno(-1))
      break;
    printf("\n\n\nOK, we'll start again from the beginning.  Now that you know what we need, it\nshould go much more quickly this time...(and we'll make the pauses shorter for\nyou since you now hopefully know what you are doing!)\n\n\n");
    flush_input(hold);
    hold = 0;
  }
  hold = 0;
  help("new.anonymous", 0);
  mysleep(hold);
  printf("Hide your real identity? (Y/N) -> ");
  flush_input(0);
  anonymous = yesno(-1);
  printf("\n\n\nOK, that's it, your account is now being created...");
  fflush(stdout);
  salt = 9 * pid;
  saltc[0] = salt & 077;
  saltc[1] = (salt >> 6) & 077;
  for (i = 0; i < 2; i++)
  {
    c = saltc[i] + '.';
    if (c > '9')
      c += 7;
    if (c > 'Z')
      c += 6;
    saltc[i] = c;
  }
  saltc[2] = 0;
  strcpy(pas2, crypt(pas, saltc));
  locks(4);
  usernum = ++msg->eternal;
  if (!(usernum % 10000))
    usernum = ++msg->eternal;
  unlocks(4);
  if (!(ouruser = adduser(name, usernum)))
  {
    errlog("Failed user creation of %s", name);
    return(0);
  }
  bzero((void *)ouruser, sizeof(struct user));
  strcpy(ouruser->name, name);
  strcpy(ouruser->passwd, pas2);
  strcpy(ouruser->real_name, real_name);
  strcpy(ouruser->addr1, addr1);
  strcpy(ouruser->city, city);
  strcpy(ouruser->state, statename);
  strcpy(ouruser->zip, zip);
  strcpy(ouruser->phone, phone);
  strcpy(ouruser->mail, mail);
  ouruser->an_name = ouruser->an_addr = ouruser->an_location = ouruser->an_phone = ouruser->an_mail = anonymous;
  ouruser->timescalled = 1;
  ouruser->f_newbie = ouruser->f_nobeep = 1;
  ouruser->f_trouble = (nonew == -4);
  ouruser->f_prog = ouruser->f_admin = usernum == 1;
  for (i = 5; i < 200; i++)
    ouruser->generation[i] = ouruser->forget[i] = (-3L);
  ouruser->time = mybtmp->time;
  ouruser->usernum = usernum;
  msync((void *)ouruser, sizeof(struct user), 4);
  strncpy(ouruser->remote, ARGV[1] ? ARGV[1] : "local", sizeof ouruser->remote);
  ouruser->remote[sizeof ouruser->remote - 1] = 0;
  ouruser->time = mybtmp->time;
  strcpy(ouruser->loginname, ARGV[1] && ARGV[2] ? ARGV[2] : "");
  add_loggedin(ouruser);
  sprintf(work, "NEWUSER %s%s%s", ouruser->loginname, *ouruser->loginname ? "@" : "", ouruser->remote);
  logevent(work);
  ouruser->keytime = 1;
  printf("\n\n\n\nYour account has been created.\n\n\n");
  mysleep(hold);
  if (!ouruser->f_trouble)
    genkey(ouruser);
  hit_return_now();
  help("new.reminder", 0);
  mysleep(1);
  hit_return_now();
  help("new.newinfo", 0);
  mysleep(1);
  hit_return_now();
  if (ouruser->f_trouble)
  {
    help("new.restrictedbye", 0);
    my_exit(10);
  }
  mybtmp->nox = 0;
  nonew = 0;
  return(1);
}

variable_types: j int

variable_types:
p
char *

variable_types:
pas
char [9]

variable_types:
city
char [21]

variable_types:
statename
char [21]

variable_types:
zip
char [11]

variable_types:
phone
char [21]

variable_types:
mail
char [-1]

variable_types:
work
char [80]

variable_types: anonymous int

variable_types: salt int

variable_types:
saltc
char [3]

variable_types: usernum long

variable_types: hold int


reap

decompiled_code:
void reap()
{
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

while ( wait((__WAIT_STATUS)&stat_loc) < 0 && *_errno_location() == 4 )
;
if ( LOBYTE(stat_loc.__uptr) != 127 )
++*((_QWORD *)q + 381);
sysv_signal(17, reap);
}

canonical_decompiled_code:
void func0()
{
__WAIT_STATUS stat_loc; // [rsp+Ch] [rbp-Ch] BYREF

while ( wait((__WAIT_STATUS)&stat_loc) < 0 && *_errno_location() == 4 )
;
if ( LOBYTE(stat_loc.__uptr) != 127 )
++*((_QWORD *)q + 381);
sysv_signal(17, reap);
}

original_code:
void
reap(register int unused)
{
  int stat_loc;
  while (wait(&stat_loc) < 0 && (*__errno_location ()) == 4)
    ;
  if (!(((stat_loc) & 0xff) == 0x7f))
    q->reaps++;
  sysv_signal(17, reap);
}

canonical_original_code:
void reap(int unused)
{
  int stat_loc;
  while (wait(&stat_loc) < 0 && (*__errno_location ()) == 4)
    ;
  if (!(((stat_loc) & 0xff) == 0x7f))
    q->reaps++;
  sysv_signal(17, reap);
}

variable_types: unused int


reread

decompiled_code:
void reread()
{
f_reread = 1;
sysv_signal(1, reread);
}

canonical_decompiled_code:
void func1()
{
f_reread = 1;
sysv_signal(1, reread);
}

original_code:
void
reread(register int unused)
{
  f_reread = 1;
  sysv_signal(1, reread);
}

canonical_original_code:
void reread(int unused)
{
  f_reread = 1;
  sysv_signal(1, reread);
}


quit

decompiled_code:
void quit()
{
f_term = 1;
sysv_signal(15, quit);
}

canonical_decompiled_code:
void func2()
{
f_term = 1;
sysv_signal(15, quit);
}

original_code:
void
quit(register int unused)
{
  f_term = 1;
  sysv_signal(15, quit);
}

canonical_original_code:
void quit(int unused)
{
  f_term = 1;
  sysv_signal(15, quit);
}


restart

decompiled_code:
void restart()
{
f_restart = 1;
sysv_signal(12, restart);
}

canonical_decompiled_code:
void func3()
{
f_restart = 1;
sysv_signal(12, restart);
}

original_code:
void
restart(register int unused)
{
  f_restart = 1;
  sysv_signal(12, restart);
}

canonical_original_code:
void restart(int unused)
{
  f_restart = 1;
  sysv_signal(12, restart);
}


setup

decompiled_code:
void setup()
{
f_quit = 1;
sysv_signal(3, setup);
}

canonical_decompiled_code:
void func4()
{
f_quit = 1;
sysv_signal(3, setup);
}

original_code:
void
setup(register int unused)
{
  f_quit = 1;
  sysv_signal(3, setup);
}

canonical_original_code:
void setup(int unused)
{
  f_quit = 1;
  sysv_signal(3, setup);
}


dump

decompiled_code:
int dump()
{
_BYTE v1[15]; // [rsp+0h] [rbp-9BD70h] BYREF

bcopy(q, v1, 0x9BD58uLL);
bigbtmp = v1;
q = v1;
return raise(6);
}

canonical_decompiled_code:
int func6()
{
_BYTE v1[15]; // [rsp+0h] [rbp-9BD70h] BYREF

bcopy(q, v1, 0x9BD58uLL);
bigbtmp = v1;
q = v1;
return raise(6);
}

original_code:
void
dump(register int unused)
{
  struct bigbtmp *temp;
  temp = (struct bigbtmp *)__builtin_alloca (sizeof(struct bigbtmp));
  bcopy(q, temp, sizeof(struct bigbtmp));
  q = bigbtmp = temp;
  raise(6);
}

canonical_original_code:
void dump(int unused)
{
  struct bigbtmp *temp;
  temp = (struct bigbtmp *)__builtin_alloca (sizeof(struct bigbtmp));
  bcopy(q, temp, sizeof(struct bigbtmp));
  q = bigbtmp = temp;
  raise(6);
}

variable_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 { long fds_bits[-1]; } fds; long t; 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; } *ltm; long lastcheck; long oldforks; char lockout; char init_info; char init_reread; char down; short qindex[1000]; 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; } btmp[1500]; 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; } qt[1000]; } *

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


ring

decompiled_code:
void ring()
{
unsigned int v0; // ebx
int *v1; // rax
char *envp; // [rsp+8h] [rbp-30h] BYREF
char *argv[5]; // [rsp+10h] [rbp-28h] BYREF

syslog(6, "f_qalarm is %d", (unsigned int)f_qalarm);
++f_qalarm;
if ( f_qalarm > 4 )
{
if ( fork() )
{
close(0);
syslog(6, "Queue looping, aborting and performing restart...");
dump();
}
else
{
envp = 0LL;
argv[0] = "/bbs/bin/bbs";
argv[1] = "-q";
argv[2] = 0LL;
syslog(6, "launching bbs -q...");
v0 = execve("/bbs/bin/bbs", argv, &envp);
v1 = _errno_location();
syslog(6, "launch failed!! %d %d", v0, (unsigned int)*v1);
}
}
sysv_signal(14, ring);
}

canonical_decompiled_code:
void func7()
{
unsigned int v0; // ebx
int *v1; // rax
char *envp; // [rsp+8h] [rbp-30h] BYREF
char *argv[5]; // [rsp+10h] [rbp-28h] BYREF

syslog(6, "f_qalarm is %d", (unsigned int)f_qalarm);
++f_qalarm;
if ( f_qalarm > 4 )
{
if ( fork() )
{
close(0);
syslog(6, "Queue looping, aborting and performing restart...");
func6();
}
else
{
envp = 0LL;
argv[0] = "/bbs/bin/bbs";
argv[1] = "-q";
argv[2] = 0LL;
syslog(6, "launching bbs -q...");
v0 = execve("/bbs/bin/bbs", argv, &envp);
v1 = _errno_location();
syslog(6, "launch failed!! %d %d", v0, (unsigned int)*v1);
}
}
sysv_signal(14, ring);
}

original_code:
void
ring(register int unused)
{
  syslog(6, "f_qalarm is %d", f_qalarm);
  if (++f_qalarm > 4)
  {
    if (fork())
    {
      close(0);
      syslog(6, "Queue looping, aborting and performing restart...");
      dump(0);
    }
    else {
      char *envp[] = { ((void *)0) };
      char *argv[] = { "/bbs/bin/bbs", "-q", ((void *)0) };
      syslog(6, "launching bbs -q...");
      int r = execve("/bbs/bin/bbs", argv, envp);
      syslog(6, "launch failed!! %d %d", r, (*__errno_location ()));
    }
  }
  sysv_signal(14, ring);
}

canonical_original_code:
void ring(int unused)
{
  syslog(6, "f_qalarm is %d", f_qalarm);
  if (++f_qalarm > 4)
  {
    if (fork())
    {
      close(0);
      syslog(6, "Queue looping, aborting and performing restart...");
      dump(0);
    }
    else {
      char *envp[] = { ((void *)0) };
      char *argv[] = { "/bbs/bin/bbs", "-q", ((void *)0) };
      syslog(6, "launching bbs -q...");
      int r = execve("/bbs/bin/bbs", argv, envp);
      syslog(6, "launch failed!! %d %d", r, (*__errno_location ()));
    }
  }
  sysv_signal(14, ring);
}

variable_types:
envp
char *[]

variable_types:
argv
char *[]

variable_types: r int


decompiled_code:
void __noreturn do_quit()
{
syslog(
6,
"users %ld, queue %d, limit %d, lockout %d",
*((_QWORD *)q + 380) - *((_QWORD *)q + 381),
(unsigned int)*((__int16 *)q + 1516),
(unsigned int)*((__int16 *)q + 2051),
(unsigned int)*((char *)q + 4288));
syslog(6, "forks %ld, maxqueue %d", *((_QWORD *)q + 380), (unsigned int)*((__int16 *)q + 1518));
syslog(6, "admins %ld, upgrades %ld, users %ld", *((_QWORD *)q + 383), *((_QWORD *)q + 384), *((_QWORD *)q + 385));
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
syslog(
6,
"users %ld, queue %d, limit %d, lockout %d",
*((_QWORD *)q + 380) - *((_QWORD *)q + 381),
(unsigned int)*((__int16 *)q + 1516),
(unsigned int)*((__int16 *)q + 2051),
(unsigned int)*((char *)q + 4288));
syslog(6, "forks %ld, maxqueue %d", *((_QWORD *)q + 380), (unsigned int)*((__int16 *)q + 1518));
syslog(6, "admins %ld, upgrades %ld, users %ld", *((_QWORD *)q + 383), *((_QWORD *)q + 384), *((_QWORD *)q + 385));
exit(0);
}

original_code:
void
do_quit(void)
{
  syslog(6, "users %ld, queue %d, limit %d, lockout %d", q->forks - q->reaps, q->qp, q->limit, q->lockout);
  syslog(6, "forks %ld, maxqueue %d", q->forks, q->maxqp);
  syslog(6, "admins %ld, upgrades %ld, users %ld", q->aidewiz, q->upgrade, q->nonupgrade);
  _exit(0);
}

canonical_original_code:
void do_quit()
{
  syslog(6, "users %ld, queue %d, limit %d, lockout %d", q->forks - q->reaps, q->qp, q->limit, q->lockout);
  syslog(6, "forks %ld, maxqueue %d", q->forks, q->maxqp);
  syslog(6, "admins %ld, upgrades %ld, users %ld", q->aidewiz, q->upgrade, q->nonupgrade);
  _exit(0);
}


logfatal

decompiled_code:
void __fastcall __noreturn logfatal(char *fmt, int errnum)
{
char *v2; // rax
char *v3[3]; // [rsp+0h] [rbp-38h] BYREF
char *envp; // [rsp+18h] [rbp-20h] BYREF

syslog(6, "fatal");
syslog(6, fmt);
syslog(3, fmt);
v2 = strerror(errnum);
syslog(6, "fatal: %d %s", (unsigned int)errnum, v2);
syslog(6, "Starting a fresh queue process upon death in 15 seconds...");
mysleep(15LL);
envp = 0LL;
v3[0] = "/bbs/bin/bbs";
v3[1] = "-q";
v3[2] = 0LL;
execve("/bbs/bin/bbs", v3, &envp);
syslog(3, "could not restart!");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(char *fmt, int errnum)
{
char *v2; // rax
char *v3[3]; // [rsp+0h] [rbp-38h] BYREF
char *envp; // [rsp+18h] [rbp-20h] BYREF

syslog(6, "fatal");
syslog(6, fmt);
syslog(3, fmt);
v2 = strerror(errnum);
syslog(6, "fatal: %d %s", (unsigned int)errnum, v2);
syslog(6, "Starting a fresh queue process upon death in 15 seconds...");
mysleep(15LL);
envp = 0LL;
v3[0] = "/bbs/bin/bbs";
v3[1] = "-q";
v3[2] = 0LL;
execve("/bbs/bin/bbs", v3, &envp);
syslog(3, "could not restart!");
exit(1);
}

original_code:
void
logfatal(char *error, int number)
{
  syslog(6, "fatal");
  syslog(6, error);
  syslog(3, error);
  syslog(6, "fatal: %d %s", number, strerror(number));
  syslog(6, "Starting a fresh queue process upon death in 15 seconds...");
  mysleep(15);
  char *envp[] = { ((void *)0) };
  char *argv[] = { "/bbs/bin/bbs", "-q", ((void *)0) };
  int r = execve("/bbs/bin/bbs", argv, envp);
  syslog(3, "could not restart!");
  _exit(1);
}

variable_types:
error
char *

variable_types: number int


decompiled_code:
time_t do_setup()
{
_QWORD *v0; // rbx
time_t result; // rax
int *v2; // rax
int *v3; // rax
int *v4; // rax
int *v5; // rax
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
f_quit = 0;
if ( !close(0) )
syslog(6, "Rebound listener socket");
if ( socket(2, 1, 0) )
{
v2 = _errno_location();
logfatal("socket: ", *v2);
}
if ( setsockopt(0, 1, 2, &optval, 4u) )
{
v3 = _errno_location();
logfatal("setsockopt: ", *v3);
}
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = _bswap_16(23);
if ( bind(0, &addr, 0x10u) )
{
v4 = _errno_location();
logfatal("bind: ", *v4);
}
if ( listen(0, 128) )
{
v5 = _errno_location();
logfatal("listen: ", *v5);
}
v0 = q;
result = time(0LL);
v0[24789] = result;
return result;
}

canonical_decompiled_code:
time_t func11()
{
_QWORD *v0; // rbx
time_t result; // rax
int *v2; // rax
int *v3; // rax
int *v4; // rax
int *v5; // rax
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
f_quit = 0;
if ( !close(0) )
syslog(6, "Rebound listener socket");
if ( socket(2, 1, 0) )
{
v2 = _errno_location();
func9("socket: ", *v2);
}
if ( setsockopt(0, 1, 2, &optval, 4u) )
{
v3 = _errno_location();
func9("setsockopt: ", *v3);
}
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = func5(23);
if ( bind(0, &addr, 0x10u) )
{
v4 = _errno_location();
func9("bind: ", *v4);
}
if ( listen(0, 128) )
{
v5 = _errno_location();
func9("listen: ", *v5);
}
v0 = q;
result = time(0LL);
v0[24789] = result;
return result;
}

original_code:
void
do_setup(void)
{
struct sockaddr_in sa;
int on = 1;
  f_quit = 0;
  if (!close(0))
    syslog(6, "Rebound listener socket");
  if (socket(2, SOCK_STREAM, 0))
    logfatal("socket: ", (*__errno_location ()));
  if (setsockopt(0, 1, 2, &on, sizeof on))
    logfatal("setsockopt: ", (*__errno_location ()));
  sa.sin_family = 2;
  sa.sin_addr.s_addr = 0;
  sa.sin_port = htons(23);
  if (bind(0, &sa, sizeof sa))
    logfatal("bind: ", (*__errno_location ()));
  if (listen(0, 128))
    logfatal("listen: ", (*__errno_location ()));
  q->qt[0].last = time(0);
}

canonical_original_code:
void do_setup()
{
struct sockaddr_in sa;
int on = 1;
  f_quit = 0;
  if (!close(0))
    syslog(6, "Rebound listener socket");
  if (socket(2, SOCK_STREAM, 0))
    logfatal("socket: ", (*__errno_location ()));
  if (setsockopt(0, 1, 2, &on, sizeof on))
    logfatal("setsockopt: ", (*__errno_location ()));
  sa.sin_family = 2;
  sa.sin_addr.s_addr = 0;
  sa.sin_port = htons(23);
  if (bind(0, &sa, sizeof sa))
    logfatal("bind: ", (*__errno_location ()));
  if (listen(0, 128))
    logfatal("listen: ", (*__errno_location ()));
  q->qt[0].last = time(0);
}

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

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


drop

original_code:
void
drop(int s)
{
register int i, j;
  if (s > 0)
  {
    close(s);
    q->socks--;
  }
  else
  {
    s = (-s);
    shutdown(s, 2);
    q->qt[s].state = -1;
  }
  q->qt[s].conn = 0;
  ((void) (((&q->fds)->fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
  for (i = 0; i < q->qp; i++)
    if (q->qindex[i] == s)
    {
      for (q->qflag++, q->qp--, j = i; j < q->qp; j++)
        q->qindex[j] = q->qindex[j + 1];
      break;
    }
}

canonical_original_code:
void drop(int s)
{
register int i; register int j;
  if (s > 0)
  {
    close(s);
    q->socks--;
  }
  else
  {
    s = (-s);
    shutdown(s, 2);
    q->qt[s].state = -1;
  }
  q->qt[s].conn = 0;
  ((void) (((&q->fds)->fds_bits)[((s) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((s) % (8 * (int) sizeof (__fd_mask)))))));
  for (i = 0; i < q->qp; i++)
    if (q->qindex[i] == s)
    {
      for (q->qflag++, q->qp--, j = i; j < q->qp; j++)
        q->qindex[j] = q->qindex[j + 1];
      break;
    }
}

variable_types: s int

variable_types: i int

variable_types: j int


original_code:
void
do_ring(void)
{
register int z;
  f_qalarm = 0;
  q->t = time(0);
  for (z = 3; z < 1000; z++)
    if (q->qt[z].conn || q->qt[z].state < 0)
      if ((q->qt[z].initstate && q->qt[z].last + 300 < q->t) || (q->qt[z].state < 0 && q->qt[z].last + 9 < q->t))
        drop(z);
  if (q->qt[0].last + 300 < q->t)
    setup(0);
  q->startable = q->connectable = 60;
}

canonical_original_code:
void do_ring()
{
register int z;
  f_qalarm = 0;
  q->t = time(0);
  for (z = 3; z < 1000; z++)
    if (q->qt[z].conn || q->qt[z].state < 0)
      if ((q->qt[z].initstate && q->qt[z].last + 300 < q->t) || (q->qt[z].state < 0 && q->qt[z].last + 9 < q->t))
        drop(z);
  if (q->qt[0].last + 300 < q->t)
    setup(0);
  q->startable = q->connectable = 60;
}

variable_types: z int


ssend

decompiled_code:
__int64 __fastcall ssend(int fd, void *buf, int a3)
{
int v5; // eax

while ( 1 )
{
v5 = send(fd, buf, a3, 0);
if ( a3 == v5 )
break;
if ( v5 >= 0 )
{
buf = (char *)buf + v5;
a3 -= v5;
}
else if ( *_errno_location() != 4 )
{
drop(fd);
return 0xFFFFFFFFLL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(int fd, void *buf, int a3)
{
int v5; // eax

while ( 1 )
{
v5 = send(fd, buf, a3, 0);
if ( a3 == v5 )
break;
if ( v5 >= 0 )
{
buf = (char *)buf + v5;
a3 -= v5;
}
else if ( *_errno_location() != 4 )
{
func12(fd);
return 0xFFFFFFFFLL;
}
}
return 0LL;
}

original_code:
int
ssend(register int s, register char *buf, register int len)
{
  register int x;
  for (;;)
  {
    x = send(s, buf, len, 0);
    if (x == len)
      return(0);
    if (x < 0)
    {
      if ((*__errno_location ()) == 4)
        continue;
      else
      {
        drop(s);
        return(-1);
      }
    }
    buf += x;
    len -= x;
    continue;
  }
}

canonical_original_code:
int ssend(int s, char *buf, int len)
{
  register int x;
  for (;;)
  {
    x = send(s, buf, len, 0);
    if (x == len)
      return(0);
    if (x < 0)
    {
      if ((*__errno_location ()) == 4)
        continue;
      else
      {
        drop(s);
        return(-1);
      }
    }
    buf += x;
    len -= x;
    continue;
  }
}

variable_types:
buf
char *

variable_types: len int

variable_types: x int


dologin

original_code:
void
dologin(register int c, register int x)
{
  char d;
  if (q->qt[x].login == 5)
  {
    if (ssend(x, "\r\nName: ", 8))
      return;
    q->qt[x].login = 10;
  }
  else if (q->qt[x].login >= 10 && q->qt[x].login < 30)
  {
    if (c == '_')
      c = ' ';
    if (c == '\r' || c == '\n')
      if (q->qt[x].login == 10)
      {
        q->qt[x].login = 0;
        ssend(x, "\r\n", 2);
      }
      else
      {
        q->qt[x].name[q->qt[x].login - 10] = '\0';
 if (!strcmp(q->qt[x].name, "New"))
 {
   ssend(x, "\r\n\nNew users cannot be created until you have finished the queue and entered the\r\nBBS or are a sysop.\r\n\nName: ", sizeof "\r\n\nNew users cannot be created until you have finished the queue and entered the\r\nBBS or are a sysop.\r\n\nName: " - 1);
   q->qt[x].new = 1;
   q->qt[x].login = 10;
   return;
 }
        q->qt[x].login = 30;
        ssend(x, "\r\nPassword: ", 12);
      }
    else if ((c == 8 || c == 127) && q->qt[x].login > 10)
    {
      ssend(x, "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b", 3);
      q->qt[x].login--;
    }
    else if ((c == 24 || c == 21) && q->qt[x].login > 10)
    {
      ssend(x, "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b", (q->qt[x].login - 10) * 3);
      q->qt[x].login = 10;
    }
    else if (((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == ' ') && q->qt[x].login < 29)
    {
      if (c >= 'a' && c <= 'z' && (q->qt[x].login == 10 || q->qt[x].name[q->qt[x].login - 11] == ' '))
        c -= 32;
      d = c;
      ssend(x, &d, 1);
      q->qt[x].name[q->qt[x].login++ - 10] = c;
    }
    return;
  }
  else if (q->qt[x].login >= 30)
  {
    if (c == '\r' || c == '\n')
    {
      q->qt[x].pass[q->qt[x].login - 30] = '\0';
      checkauth(x);
    }
    else if ((c == 8 || c == 127) && q->qt[x].login > 30)
    {
      ssend(x, "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b", 3);
      q->qt[x].login--;
    }
    else if (c == 24 && q->qt[x].login > 30)
    {
      ssend(x, "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b", (q->qt[x].login - 30) * 3);
      q->qt[x].login = 30;
    }
    else if (c >= ' ' && q->qt[x].login < 38)
    {
      q->qt[x].pass[q->qt[x].login++ - 30] = c;
      ssend(x, ".", 1);
    }
  }
}

canonical_original_code:
void dologin(int c, int x)
{
  char d;
  if (q->qt[x].login == 5)
  {
    if (ssend(x, "\r\nName: ", 8))
      return;
    q->qt[x].login = 10;
  }
  else if (q->qt[x].login >= 10 && q->qt[x].login < 30)
  {
    if (c == '_')
      c = ' ';
    if (c == '\r' || c == '\n')
      if (q->qt[x].login == 10)
      {
        q->qt[x].login = 0;
        ssend(x, "\r\n", 2);
      }
      else
      {
        q->qt[x].name[q->qt[x].login - 10] = '\0';
 if (!strcmp(q->qt[x].name, "New"))
 {
   ssend(x, "\r\n\nNew users cannot be created until you have finished the queue and entered the\r\nBBS or are a sysop.\r\n\nName: ", sizeof "\r\n\nNew users cannot be created until you have finished the queue and entered the\r\nBBS or are a sysop.\r\n\nName: " - 1);
   q->qt[x].new = 1;
   q->qt[x].login = 10;
   return;
 }
        q->qt[x].login = 30;
        ssend(x, "\r\nPassword: ", 12);
      }
    else if ((c == 8 || c == 127) && q->qt[x].login > 10)
    {
      ssend(x, "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b", 3);
      q->qt[x].login--;
    }
    else if ((c == 24 || c == 21) && q->qt[x].login > 10)
    {
      ssend(x, "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b", (q->qt[x].login - 10) * 3);
      q->qt[x].login = 10;
    }
    else if (((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == ' ') && q->qt[x].login < 29)
    {
      if (c >= 'a' && c <= 'z' && (q->qt[x].login == 10 || q->qt[x].name[q->qt[x].login - 11] == ' '))
        c -= 32;
      d = c;
      ssend(x, &d, 1);
      q->qt[x].name[q->qt[x].login++ - 10] = c;
    }
    return;
  }
  else if (q->qt[x].login >= 30)
  {
    if (c == '\r' || c == '\n')
    {
      q->qt[x].pass[q->qt[x].login - 30] = '\0';
      checkauth(x);
    }
    else if ((c == 8 || c == 127) && q->qt[x].login > 30)
    {
      ssend(x, "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b", 3);
      q->qt[x].login--;
    }
    else if (c == 24 && q->qt[x].login > 30)
    {
      ssend(x, "\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b", (q->qt[x].login - 30) * 3);
      q->qt[x].login = 30;
    }
    else if (c >= ' ' && q->qt[x].login < 38)
    {
      q->qt[x].pass[q->qt[x].login++ - 30] = c;
      ssend(x, ".", 1);
    }
  }
}

variable_types: c int

variable_types: d char


decompiled_code:
void s_sigalrm2()
{
sysv_signal(14, s_sigalrm2);
alarm(0x1Eu);
}

canonical_decompiled_code:
void func1()
{
sysv_signal(14, s_sigalrm2);
alarm(0x1Eu);
}

original_code:
void
s_sigalrm2(register int unused)
{
  sysv_signal(14, s_sigalrm2);
  alarm(30);
}

canonical_original_code:
void s_sigalrm2(int unused)
{
  sysv_signal(14, s_sigalrm2);
  alarm(30);
}

variable_types: unused int


decompiled_code:
int setup_socket()
{
int result; // eax
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
close(0);
if ( socket(2, 1, 0) )
exit(1);
optval = 1;
if ( setsockopt(0, 1, 2, &optval, 4u) < 0 )
exit(1);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = _bswap_16(79);
if ( bind(0, &addr, 0x10u) < 0 )
exit(1);
result = listen(0, 128);
if ( result < 0 )
exit(1);
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
close(0);
if ( socket(2, 1, 0) )
exit(1);
optval = 1;
if ( setsockopt(0, 1, 2, &optval, 4u) < 0 )
exit(1);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = 0;
*(_WORD *)addr.sa_data = func0(79);
if ( bind(0, &addr, 0x10u) < 0 )
exit(1);
result = listen(0, 128);
if ( result < 0 )
exit(1);
return result;
}

original_code:
void
setup_socket(void)
{
  struct sockaddr_in sa;
  int one = 1;
  close(0);
  if (socket(2, SOCK_STREAM, 0) != 0)
    _exit(1);
  one = 1;
  if (setsockopt(0, 1, 2, &one, sizeof one) < 0)
    _exit(1);
  sa.sin_family = 2;
  sa.sin_addr.s_addr = 0;
  sa.sin_port = htons(79);
  if (bind(0, &sa, sizeof sa) < 0)
    _exit(1);
  if (listen(0, 128) < 0)
    _exit(1);
}

canonical_original_code:
void setup_socket()
{
  struct sockaddr_in sa;
  int one = 1;
  close(0);
  if (socket(2, SOCK_STREAM, 0) != 0)
    _exit(1);
  one = 1;
  if (setsockopt(0, 1, 2, &one, sizeof one) < 0)
    _exit(1);
  sa.sin_family = 2;
  sa.sin_addr.s_addr = 0;
  sa.sin_port = htons(79);
  if (bind(0, &sa, sizeof sa) < 0)
    _exit(1);
  if (listen(0, 128) < 0)
    _exit(1);
}

variable_types: one int