decompiled_code:
__int64 new_user()
{
char v0; // al
__int64 v1; // rcx
const unsigned __int16 **v2; // rbx
char *v3; // r14
int v4; // er15
const __int32_t *v5; // rsi
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rax
__int64 v9; // rdi
unsigned int v10; // er15
const char *v12; // rsi
size_t v13; // r13
__int64 v14; // rax
__int64 v15; // rcx
char v16; // dl
char *v17; // r13
char v18; // cl
int v19; // eax
char v20; // bl
char v21; // dl
int v22; // eax
char v23; // cl
char v24; // dl
char *v25; // rax
__int64 v26; // rsi
__int64 v27; // r13
char *v28; // r15
__int64 v29; // rax
__int64 v30; // rbx
const char *v31; // rsi
_BYTE *v32; // rbp
__int64 v33; // rax
bool v34; // zf
const char *v35; // rsi
const char *v36; // rcx
char v37; // [rsp+Fh] [rbp-1C9h]
char salt[3]; // [rsp+1Bh] [rbp-1BDh] BYREF
char s[9]; // [rsp+1Eh] [rbp-1BAh] BYREF
char v40[11]; // [rsp+27h] [rbp-1B1h] BYREF
char s2[14]; // [rsp+32h] [rbp-1A6h] BYREF
char haystack[4]; // [rsp+40h] [rbp-198h] BYREF
__int16 v43; // [rsp+44h] [rbp-194h]
char v44[32]; // [rsp+60h] [rbp-178h] BYREF
char v45[32]; // [rsp+80h] [rbp-158h] BYREF
char v46[32]; // [rsp+A0h] [rbp-138h] BYREF
char s1[48]; // [rsp+C0h] [rbp-118h] BYREF
char src[48]; // [rsp+F0h] [rbp-E8h] BYREF
int v49; // [rsp+120h] [rbp-B8h] BYREF
char v50; // [rsp+124h] [rbp-B4h]
char v51[136]; // [rsp+150h] [rbp-88h] 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) )
{
v10 = -1;
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 v10;
}
help("new.pauses", 0LL);
mysleep(0LL);
hit_return_now();
v0 = nonew;
if ( nonew )
{
help("new.restricted", 0LL);
mysleep(0LL);
hit_return_now();
v0 = nonew;
}
v1 = mybtmp;
nonew = ~v0;
*(_QWORD *)(mybtmp + 36LL) = 0x6573552077654E3CLL;
strcpy((char *)(v1 + 44), "r>");
help("new.outline", 0LL);
mysleep(0LL);
hit_return_now();
v2 = _ctype_b_loc();
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);
v3 = (char *)get_name(&unk_F99, 1LL);
check_quit(v3);
v4 = strlen(v3);
if ( v4 <= 0 )
{
v8 = 0LL;
}
else
{
v5 = *_ctype_tolower_loc();
v6 = 0LL;
do
{
haystack[v6] = v5[v3[v6]];
v7 = v6++;
}
while ( v4 - 1 != v7 );
v8 = v4;
}
haystack[v8] = 0;
if ( *(_DWORD *)haystack == 7824750
|| strstr(haystack, "sysop")
|| strstr(haystack, "moderator")
|| strstr(haystack, "isca") )
{
LABEL_14:
printf("\nThat name is not allowed.");
goto LABEL_15;
}
if ( *(_DWORD *)haystack != 1936029031 )
break;
if ( v43 == 116 )
goto LABEL_14;
v9 = getuser(v3, "isca");
if ( !v9 )
goto LABEL_26;
LABEL_20:
freeuser(v9);
printf("\nThat name is already in use.");
LABEL_15:
puts("\nPlease try again or hit ctrl-D to exit.");
}
v9 = getuser(v3, "isca");
if ( v9 )
goto LABEL_20;
LABEL_26:
if ( v4 != 1 && v4 <= 18 )
break;
v12 = "long";
if ( v4 == 1 )
v12 = "short";
printf("\nThat name is too %s. Please choose another.\n", v12);
}
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 ( strlen(s) > 5 )
break;
puts("\nYour password must be at least 6 characters long. Please try again.\n");
}
if ( strcasecmp(v3, 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);
v10 = strcasecmp(s, s2);
if ( !v10 )
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);
v13 = strlen(s1);
if ( v13 )
break;
puts("\nYou have to provide your name!");
}
v14 = 0LL;
while ( 1 )
{
v15 = s1[v14];
v16 = s1[v14];
if ( ((*v2)[v15] & 0x400) == 0 && v16 != 32 && (unsigned __int8)(v15 - 44) > 2u )
break;
if ( v13 == ++v14 )
goto LABEL_44;
}
if ( (int)v14 >= (int)v13 )
break;
printf("\nThe character \"%c\" is not allowed in a name.\n", (unsigned int)v16);
}
LABEL_44:
if ( (int)v13 > 3
&& strchr(s1, 32)
&& s1[(int)v13 - 2] != 32
&& (s1[(int)v13 - 3] != 32 || s1[(int)v13 - 1] != 46) )
{
break;
}
puts("\nYou must provide both your full first and last names!");
}
if ( !strcmp(s1, v3) || !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, v44, 0xFFFFFFFFLL);
check_quit(v44);
if ( v44[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, v45, 0xFFFFFFFFLL);
check_quit(v45);
if ( v45[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, v40, 0xFFFFFFFFLL);
check_quit(v40);
if ( v40[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, v46, 0xFFFFFFFFLL);
check_quit(v46);
help("new.email", 0LL);
mysleep(0LL);
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 1 )
{
flush_input(0LL);
get_string("E-mail address: ", 40LL, &v49, 0xFFFFFFFFLL);
check_quit((char *)&v49);
if ( (_BYTE)v49 )
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 ( (_WORD)v49 == 28265 && BYTE2(v49) == 37 )
{
LABEL_79:
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");
continue;
}
break;
}
if ( (_WORD)v49 == 20041 )
{
if ( BYTE2(v49) == 37 )
goto LABEL_79;
if ( v49 == 1886678387 )
goto LABEL_82;
}
else
{
if ( v49 != 1886678387 )
goto LABEL_73;
LABEL_82:
if ( v50 == 37 )
goto LABEL_79;
}
LABEL_73:
if ( v49 == 1347702099 && v50 == 37 )
goto LABEL_79;
if ( strchr((const char *)&v49, 34) )
{
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");
continue;
}
break;
}
v17 = strchr((const char *)&v49, 64);
if ( !v17 || !strchr((const char *)&v49, 46) || strchr((const char *)&v49, 32) )
{
puts("\nThat is not a valid e-mail address, please try again.\n");
continue;
}
break;
}
if ( ((*v2)[v17[1]] & 0x800) != 0 )
{
puts(
"\n"
"You must use a name, not a numeric address, following the '@' in your e-mail\n"
"address. Please try again.\n");
continue;
}
break;
}
if ( !strcasecmp(v17, "@bbs.isca.uiowa.edu") || !strcasecmp(v17, "@whip.isca.uiowa.edu") )
{
puts("\nThat is NOT your e-mail address. Please try again.\n");
continue;
}
break;
}
if ( !strcasecmp(v17, "@chop.isca.uiowa.edu")
|| !strcasecmp(v17, "@panda.isca.uiowa.edu")
|| !strcasecmp(v17, "@panda.uiowa.edu") )
{
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");
continue;
}
break;
}
v18 = v17[5];
v17[5] = 0;
v37 = v18;
v19 = strcasecmp(v17, "@anon");
if ( v37 == 46 && !v19 )
{
puts("\nYou may not use an anonymous site as your e-mail address!\n");
continue;
}
break;
}
v17[5] = v37;
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,
v44,
v45,
v40,
v46,
(const char *)&v49);
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);
v20 = yesno(0xFFFFFFFFLL);
printf("\n\n\nOK, that's it, your account is now being created...");
fflush(stdout);
v21 = (9 * pid) & 0x3F;
v22 = ((9 * pid) >> 6) & 0x3F;
v23 = v21 + 46;
if ( (char)(v21 + 46) > 57 )
{
v23 = v21 + 53;
if ( (char)(v21 + 53) > 90 )
v23 = v21 + 59;
}
salt[0] = v23;
v24 = v22 + 46;
if ( (char)(v22 + 46) > 57 )
{
v24 = v22 + 53;
if ( (char)(v22 + 53) > 90 )
v24 = v22 + 59;
}
salt[1] = v24;
salt[2] = 0;
v25 = crypt(s, salt);
strcpy(s2, v25);
locks(4LL);
v26 = *(_QWORD *)(msg + 112LL);
v27 = v26 + 1;
if ( !((v26 + 1) % 10000) )
v27 = v26 + 2;
*(_QWORD *)(msg + 112LL) = v27;
unlocks(4LL);
ouruser = (void *)adduser(v3, v27);
if ( ouruser )
{
bzero(ouruser, 0x1808uLL);
v28 = (char *)ouruser;
strcpy((char *)ouruser + 56, v3);
strcpy(v28 + 76, s2);
strcpy(v28 + 141, s1);
strcpy(v28 + 182, src);
strcpy(v28 + 264, v44);
strcpy(v28 + 285, v45);
strcpy(v28 + 306, v40);
strcpy(v28 + 317, v46);
strcpy(v28 + 338, (const char *)&v49);
*((_DWORD *)v28 + 6) = 1;
*((_QWORD *)v28 + 2) = *((_QWORD *)v28 + 2) & 0xFFEFFBABC1FFFFFFLL | ((unsigned __int64)(nonew == 0xFC) << 42) | ((unsigned __int64)(v27 == 1) << 38) | ((unsigned __int64)(v27 == 1) << 36) | ((unsigned __int64)(v20 & 1) << 29) | ((unsigned __int64)(v20 & 1) << 28) | ((unsigned __int64)(v20 & 1) << 27) | ((unsigned __int64)(v20 & 1) << 26) | ((unsigned __int64)(v20 & 1) << 25) | 0x10000400000000LL;
memset(v28 + 789, -3, 0xC3uLL);
memset(v28 + 989, -3, 0xC3uLL);
v29 = *(_QWORD *)(mybtmp + 16LL);
*(_QWORD *)v28 = v27;
*((_QWORD *)v28 + 4) = v29;
msync(v28, 0x1808uLL, 4);
v30 = ARGV;
v31 = *(const char **)(ARGV + 8LL);
if ( !v31 )
v31 = "local";
v32 = ouruser;
strncpy((char *)ouruser + 90, v31, 0x27uLL);
v33 = mybtmp;
v32[129] = 0;
v34 = *(_QWORD *)(v30 + 8) == 0LL;
*((_QWORD *)v32 + 4) = *(_QWORD *)(v33 + 16);
if ( v34 || (v35 = *(const char **)(v30 + 16)) == 0LL )
v35 = (const char *)&unk_F99;
strcpy(v32 + 5843, v35);
add_loggedin(v32);
v36 = "@";
if ( !*((_BYTE *)ouruser + 5843) )
v36 = (const char *)&unk_F99;
sprintf(v51, "NEWUSER %s%s%s", (char *)ouruser + 5843, v36, (char *)ouruser + 90);
logevent(v51);
*((_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);
}
nonew = 0;
v10 = 1;
*(_BYTE *)(mybtmp + 118LL) = 0;
}
else
{
errlog("Failed user creation of %s", v3);
}
return v10;
}

canonical_decompiled_code:
__int64 func3()
{
char v0; // al
__int64 v1; // rcx
const unsigned __int16 **v2; // rbx
char *v3; // r14
int v4; // er15
const __int32_t *v5; // rsi
__int64 v6; // rax
__int64 v7; // rdx
__int64 v8; // rax
__int64 v9; // rdi
unsigned int v10; // er15
const char *v12; // rsi
size_t v13; // r13
__int64 v14; // rax
__int64 v15; // rcx
char v16; // dl
char *v17; // r13
char v18; // cl
int v19; // eax
char v20; // bl
char v21; // dl
int v22; // eax
char v23; // cl
char v24; // dl
char *v25; // rax
__int64 v26; // rsi
__int64 v27; // r13
char *v28; // r15
__int64 v29; // rax
__int64 v30; // rbx
const char *v31; // rsi
_BYTE *v32; // rbp
__int64 v33; // rax
bool v34; // zf
const char *v35; // rsi
const char *v36; // rcx
char v37; // [rsp+Fh] [rbp-1C9h]
char salt[3]; // [rsp+1Bh] [rbp-1BDh] BYREF
char s[9]; // [rsp+1Eh] [rbp-1BAh] BYREF
char v40[11]; // [rsp+27h] [rbp-1B1h] BYREF
char s2[14]; // [rsp+32h] [rbp-1A6h] BYREF
char haystack[4]; // [rsp+40h] [rbp-198h] BYREF
__int16 v43; // [rsp+44h] [rbp-194h]
char v44[32]; // [rsp+60h] [rbp-178h] BYREF
char v45[32]; // [rsp+80h] [rbp-158h] BYREF
char v46[32]; // [rsp+A0h] [rbp-138h] BYREF
char s1[48]; // [rsp+C0h] [rbp-118h] BYREF
char src[48]; // [rsp+F0h] [rbp-E8h] BYREF
int v49; // [rsp+120h] [rbp-B8h] BYREF
char v50; // [rsp+124h] [rbp-B4h]
char v51[136]; // [rsp+150h] [rbp-88h] 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) )
{
v10 = -1;
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 v10;
}
help("new.pauses", 0LL);
mysleep(0LL);
hit_return_now();
v0 = nonew;
if ( nonew )
{
help("new.restricted", 0LL);
mysleep(0LL);
hit_return_now();
v0 = nonew;
}
v1 = mybtmp;
nonew = ~v0;
*(_QWORD *)(mybtmp + 36LL) = 0x6573552077654E3CLL;
strcpy((char *)(v1 + 44), "r>");
help("new.outline", 0LL);
mysleep(0LL);
hit_return_now();
v2 = _ctype_b_loc();
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);
v3 = (char *)get_name(&unk_F99, 1LL);
func2(v3);
v4 = strlen(v3);
if ( v4 <= 0 )
{
v8 = 0LL;
}
else
{
v5 = *_ctype_tolower_loc();
v6 = 0LL;
do
{
haystack[v6] = v5[v3[v6]];
v7 = v6++;
}
while ( v4 - 1 != v7 );
v8 = v4;
}
haystack[v8] = 0;
if ( *(_DWORD *)haystack == 7824750
|| strstr(haystack, "sysop")
|| strstr(haystack, "moderator")
|| strstr(haystack, "isca") )
{
LABEL_14:
printf("\nThat name is not allowed.");
goto LABEL_15;
}
if ( *(_DWORD *)haystack != 1936029031 )
break;
if ( v43 == 116 )
goto LABEL_14;
v9 = getuser(v3, "isca");
if ( !v9 )
goto LABEL_26;
LABEL_20:
freeuser(v9);
printf("\nThat name is already in use.");
LABEL_15:
puts("\nPlease try again or hit ctrl-D to exit.");
}
v9 = getuser(v3, "isca");
if ( v9 )
goto LABEL_20;
LABEL_26:
if ( v4 != 1 && v4 <= 18 )
break;
v12 = "long";
if ( v4 == 1 )
v12 = "short";
printf("\nThat name is too %s. Please choose another.\n", v12);
}
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 ( strlen(s) > 5 )
break;
puts("\nYour password must be at least 6 characters long. Please try again.\n");
}
if ( strcasecmp(v3, 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);
v10 = strcasecmp(s, s2);
if ( !v10 )
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);
v13 = strlen(s1);
if ( v13 )
break;
puts("\nYou have to provide your name!");
}
v14 = 0LL;
while ( 1 )
{
v15 = s1[v14];
v16 = s1[v14];
if ( ((*v2)[v15] & 0x400) == 0 && v16 != 32 && (unsigned __int8)(v15 - 44) > 2u )
break;
if ( v13 == ++v14 )
goto LABEL_44;
}
if ( (int)v14 >= (int)v13 )
break;
printf("\nThe character \"%c\" is not allowed in a name.\n", (unsigned int)v16);
}
LABEL_44:
if ( (int)v13 > 3
&& strchr(s1, 32)
&& s1[(int)v13 - 2] != 32
&& (s1[(int)v13 - 3] != 32 || s1[(int)v13 - 1] != 46) )
{
break;
}
puts("\nYou must provide both your full first and last names!");
}
if ( !strcmp(s1, v3) || !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, v44, 0xFFFFFFFFLL);
func2(v44);
if ( v44[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, v45, 0xFFFFFFFFLL);
func2(v45);
if ( v45[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, v40, 0xFFFFFFFFLL);
func2(v40);
if ( v40[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, v46, 0xFFFFFFFFLL);
func2(v46);
help("new.email", 0LL);
mysleep(0LL);
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 2 )
{
while ( 1 )
{
flush_input(0LL);
get_string("E-mail address: ", 40LL, &v49, 0xFFFFFFFFLL);
func2((char *)&v49);
if ( (_BYTE)v49 )
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 ( (_WORD)v49 == 28265 && BYTE2(v49) == 37 )
{
LABEL_79:
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");
continue;
}
break;
}
if ( (_WORD)v49 == 20041 )
{
if ( BYTE2(v49) == 37 )
goto LABEL_79;
if ( v49 == 1886678387 )
goto LABEL_82;
}
else
{
if ( v49 != 1886678387 )
goto LABEL_73;
LABEL_82:
if ( v50 == 37 )
goto LABEL_79;
}
LABEL_73:
if ( v49 == 1347702099 && v50 == 37 )
goto LABEL_79;
if ( strchr((const char *)&v49, 34) )
{
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");
continue;
}
break;
}
v17 = strchr((const char *)&v49, 64);
if ( !v17 || !strchr((const char *)&v49, 46) || strchr((const char *)&v49, 32) )
{
puts("\nThat is not a valid e-mail address, please try again.\n");
continue;
}
break;
}
if ( ((*v2)[v17[1]] & 0x800) != 0 )
{
puts(
"\n"
"You must use a name, not a numeric address, following the '@' in your e-mail\n"
"address. Please try again.\n");
continue;
}
break;
}
if ( !strcasecmp(v17, "@bbs.isca.uiowa.edu") || !strcasecmp(v17, "@whip.isca.uiowa.edu") )
{
puts("\nThat is NOT your e-mail address. Please try again.\n");
continue;
}
break;
}
if ( !strcasecmp(v17, "@chop.isca.uiowa.edu")
|| !strcasecmp(v17, "@panda.isca.uiowa.edu")
|| !strcasecmp(v17, "@panda.uiowa.edu") )
{
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");
continue;
}
break;
}
v18 = v17[5];
v17[5] = 0;
v37 = v18;
v19 = strcasecmp(v17, "@anon");
if ( v37 == 46 && !v19 )
{
puts("\nYou may not use an anonymous site as your e-mail address!\n");
continue;
}
break;
}
v17[5] = v37;
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,
v44,
v45,
v40,
v46,
(const char *)&v49);
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);
v20 = yesno(0xFFFFFFFFLL);
printf("\n\n\nOK, that's it, your account is now being created...");
fflush(stdout);
v21 = (9 * pid) & 0x3F;
v22 = ((9 * pid) >> 6) & 0x3F;
v23 = v21 + 46;
if ( (char)(v21 + 46) > 57 )
{
v23 = v21 + 53;
if ( (char)(v21 + 53) > 90 )
v23 = v21 + 59;
}
salt[0] = v23;
v24 = v22 + 46;
if ( (char)(v22 + 46) > 57 )
{
v24 = v22 + 53;
if ( (char)(v22 + 53) > 90 )
v24 = v22 + 59;
}
salt[1] = v24;
salt[2] = 0;
v25 = crypt(s, salt);
strcpy(s2, v25);
locks(4LL);
v26 = *(_QWORD *)(msg + 112LL);
v27 = v26 + 1;
if ( !((v26 + 1) % 10000) )
v27 = v26 + 2;
*(_QWORD *)(msg + 112LL) = v27;
unlocks(4LL);
ouruser = (void *)adduser(v3, v27);
if ( ouruser )
{
bzero(ouruser, 0x1808uLL);
v28 = (char *)ouruser;
strcpy((char *)ouruser + 56, v3);
strcpy(v28 + 76, s2);
strcpy(v28 + 141, s1);
strcpy(v28 + 182, src);
strcpy(v28 + 264, v44);
strcpy(v28 + 285, v45);
strcpy(v28 + 306, v40);
strcpy(v28 + 317, v46);
strcpy(v28 + 338, (const char *)&v49);
*((_DWORD *)v28 + 6) = 1;
*((_QWORD *)v28 + 2) = *((_QWORD *)v28 + 2) & 0xFFEFFBABC1FFFFFFLL | ((unsigned __int64)(nonew == 0xFC) << 42) | ((unsigned __int64)(v27 == 1) << 38) | ((unsigned __int64)(v27 == 1) << 36) | ((unsigned __int64)(v20 & 1) << 29) | ((unsigned __int64)(v20 & 1) << 28) | ((unsigned __int64)(v20 & 1) << 27) | ((unsigned __int64)(v20 & 1) << 26) | ((unsigned __int64)(v20 & 1) << 25) | 0x10000400000000LL;
memset(v28 + 789, -3, 0xC3uLL);
memset(v28 + 989, -3, 0xC3uLL);
v29 = *(_QWORD *)(mybtmp + 16LL);
*(_QWORD *)v28 = v27;
*((_QWORD *)v28 + 4) = v29;
msync(v28, 0x1808uLL, 4);
v30 = ARGV;
v31 = *(const char **)(ARGV + 8LL);
if ( !v31 )
v31 = "local";
v32 = ouruser;
strncpy((char *)ouruser + 90, v31, 0x27uLL);
v33 = mybtmp;
v32[129] = 0;
v34 = *(_QWORD *)(v30 + 8) == 0LL;
*((_QWORD *)v32 + 4) = *(_QWORD *)(v33 + 16);
if ( v34 || (v35 = *(const char **)(v30 + 16)) == 0LL )
v35 = (const char *)&unk_F99;
strcpy(v32 + 5843, v35);
add_loggedin(v32);
v36 = "@";
if ( !*((_BYTE *)ouruser + 5843) )
v36 = (const char *)&unk_F99;
sprintf(v51, "NEWUSER %s%s%s", (char *)ouruser + 5843, v36, (char *)ouruser + 90);
logevent(v51);
*((_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);
}
nonew = 0;
v10 = 1;
*(_BYTE *)(mybtmp + 118LL) = 0;
}
else
{
errlog("Failed user creation of %s", v3);
}
return v10;
}

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

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

return_type: void


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; // er12
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; // er12
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 *envp; // [rsp+8h] [rbp-40h] BYREF
char *argv[7]; // [rsp+10h] [rbp-38h] 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;
argv[0] = "/bbs/bin/bbs";
argv[1] = "-q";
argv[2] = 0LL;
execve("/bbs/bin/bbs", argv, &envp);
syslog(3, "could not restart!");
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(char *fmt, int errnum)
{
char *v2; // rax
char *envp; // [rsp+8h] [rbp-40h] BYREF
char *argv[7]; // [rsp+10h] [rbp-38h] 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;
argv[0] = "/bbs/bin/bbs";
argv[1] = "-q";
argv[2] = 0LL;
execve("/bbs/bin/bbs", argv, &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()
{
socklen_t v0; // edx
_QWORD *v1; // rbx
time_t result; // rax
int *v3; // rax
int *v4; // rax
int *v5; // rax
int *v6; // rax
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr v8; // [rsp+10h] [rbp-18h] BYREF

f_quit = 0;
optval = 1;
if ( !close(0) )
syslog(6, "Rebound listener socket");
if ( socket(2, 1, 0) )
{
v6 = _errno_location();
logfatal("socket: ", *v6);
}
if ( setsockopt(0, 1, 2, &optval, 4u) )
{
v5 = _errno_location();
logfatal("setsockopt: ", *v5);
}
*(_DWORD *)&v8.sa_data[2] = 0;
v8.sa_family = 2;
*(_DWORD *)v8.sa_data = (unsigned __int16)_bswap_16_constprop_0(0LL, &v8, 16LL);
if ( bind(0, &v8, v0) )
{
v4 = _errno_location();
logfatal("bind: ", *v4);
}
if ( listen(0, 128) )
{
v3 = _errno_location();
logfatal("listen: ", *v3);
}
v1 = q;
result = time(0LL);
v1[24789] = result;
return result;
}

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

f_quit = 0;
optval = 1;
if ( !close(0) )
syslog(6, "Rebound listener socket");
if ( socket(2, 1, 0) )
{
v6 = _errno_location();
func9("socket: ", *v6);
}
if ( setsockopt(0, 1, 2, &optval, 4u) )
{
v5 = _errno_location();
func9("setsockopt: ", *v5);
}
*(_DWORD *)&v8.sa_data[2] = 0;
v8.sa_family = 2;
*(_DWORD *)v8.sa_data = (unsigned __int16)func5(0LL, &v8, 16LL);
if ( bind(0, &v8, v0) )
{
v4 = _errno_location();
func9("bind: ", *v4);
}
if ( listen(0, 128) )
{
v3 = _errno_location();
func9("listen: ", *v3);
}
v1 = q;
result = time(0LL);
v1[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)
{
size_t v3; // r12
int v5; // ebx
int v6; // eax

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

canonical_decompiled_code:
__int64 __fastcall func14(int fd, void *buf, int a3)
{
size_t v3; // r12
int v5; // ebx
int v6; // eax

v3 = a3;
v5 = a3;
while ( 1 )
{
v6 = send(fd, buf, v3, 0);
if ( v5 == v6 )
break;
if ( v6 >= 0 )
{
v5 -= v6;
buf = (char *)buf + v6;
v3 = 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

return_type: 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 func0()
{
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()
{
socklen_t v0; // edx
int result; // eax
int optval; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr v3; // [rsp+10h] [rbp-18h] BYREF

optval = 1;
close(0);
if ( socket(2, 1, 0)
|| (optval = 1, setsockopt(0, 1, 2, &optval, 4u) < 0)
|| (*(_DWORD *)&v3.sa_data[2] = 0,
v3.sa_family = 2,
*(_DWORD *)v3.sa_data = (unsigned __int16)_bswap_16_constprop_0(0LL, &v3, 16LL),
bind(0, &v3, v0) < 0)
|| (result = listen(0, 128), result < 0) )
{
exit(1);
}
return result;
}

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

optval = 1;
close(0);
if ( socket(2, 1, 0)
|| (optval = 1, setsockopt(0, 1, 2, &optval, 4u) < 0)
|| (*(_DWORD *)&v3.sa_data[2] = 0,
v3.sa_family = 2,
*(_DWORD *)v3.sa_data = (unsigned __int16)func1(0LL, &v3, 16LL),
bind(0, &v3, v0) < 0)
|| (result = listen(0, 128), 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


bbsfinger

decompiled_code:
void __noreturn bbsfinger()
{
__int16 *v0; // r15
__fd_mask v1; // rdx
int v2; // ecx
int v3; // edi
char *v4; // rax
__int64 v5; // rsi
int v6; // eax
__fd_mask v7; // rax
char *v8; // r15
int v9; // er14
int v10; // eax
__int16 v11; // ax
char *v12; // rdx
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
char *v17; // rsi
char v18; // bp
FILE *v19; // rdi
char *v20; // r12
const unsigned __int16 *v21; // r13
const __int32_t **v22; // rax
char *v23; // rdi
bool v24; // si
bool v25; // al
__int64 v26; // rsi
int v27; // er14
__int16 v28; // ax
__int16 v29; // ax
__int16 v30; // ax
int v31; // eax
int v32; // er15
int v33; // er15
__int64 v34; // [rsp+0h] [rbp-40778h]
int *v35; // [rsp+8h] [rbp-40770h]
socklen_t addr_len; // [rsp+10h] [rbp-40768h] BYREF
int v37; // [rsp+14h] [rbp-40764h] BYREF
__int64 optval; // [rsp+18h] [rbp-40760h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-40758h] BYREF
fd_set readfds; // [rsp+30h] [rbp-40748h] BYREF
int v41[14]; // [rsp+B0h] [rbp-406C8h]
char v42[4]; // [rsp+E8h] [rbp-40690h] BYREF
char v43; // [rsp+ECh] [rbp-4068Ch] BYREF
char buf[262200]; // [rsp+740h] [rbp-40038h] BYREF

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

canonical_decompiled_code:
void __noreturn func3()
{
__int16 *v0; // r15
__fd_mask v1; // rdx
int v2; // ecx
int v3; // edi
char *v4; // rax
__int64 v5; // rsi
int v6; // eax
__fd_mask v7; // rax
char *v8; // r15
int v9; // er14
int v10; // eax
__int16 v11; // ax
char *v12; // rdx
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
char *v17; // rsi
char v18; // bp
FILE *v19; // rdi
char *v20; // r12
const unsigned __int16 *v21; // r13
const __int32_t **v22; // rax
char *v23; // rdi
bool v24; // si
bool v25; // al
__int64 v26; // rsi
int v27; // er14
__int16 v28; // ax
__int16 v29; // ax
__int16 v30; // ax
int v31; // eax
int v32; // er15
int v33; // er15
__int64 v34; // [rsp+0h] [rbp-40778h]
int *v35; // [rsp+8h] [rbp-40770h]
socklen_t addr_len; // [rsp+10h] [rbp-40768h] BYREF
int v37; // [rsp+14h] [rbp-40764h] BYREF
__int64 optval; // [rsp+18h] [rbp-40760h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-40758h] BYREF
fd_set readfds; // [rsp+30h] [rbp-40748h] BYREF
int v41[14]; // [rsp+B0h] [rbp-406C8h]
char v42[4]; // [rsp+E8h] [rbp-40690h] BYREF
char v43; // [rsp+ECh] [rbp-4068Ch] BYREF
char buf[262200]; // [rsp+740h] [rbp-40038h] BYREF

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

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

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

variable_types: n int

variable_types:
p
char *

variable_types:
socklen
unsigned int

variable_types: size int

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

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

variable_types:
bigstdoutbuf
unsigned char [262143]

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


telrcv

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

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

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

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

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

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

variable_types:
noflush
int *

variable_types: left int