decompiled_code:
size_t __fastcall yftpdutmp_pidexists(int a1)
{
size_t result; // rax
_DWORD v2[78]; // [rsp+0h] [rbp-138h] BYREF

rewind(yftpdutmp);
while ( 1 )
{
result = fread(v2, 0x130uLL, 1uLL, yftpdutmp);
if ( !result )
break;
if ( v2[1] == a1 )
return 1LL;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func3(int a1)
{
size_t result; // rax
_DWORD v2[78]; // [rsp+0h] [rbp-138h] BYREF

rewind(yftpdutmp);
while ( 1 )
{
result = fread(v2, 0x130uLL, 1uLL, yftpdutmp);
if ( !result )
break;
if ( v2[1] == a1 )
return 1LL;
}
return result;
}

original_code:
char
yftpdutmp_pidexists(pid_t pid)
{
 struct yftpdutmp tmp;
 rewind(yftpdutmp);
 while (fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
  if (tmp.bu_pid == pid)
   return 1;
 }
 return 0;
}

canonical_original_code:
char yftpdutmp_pidexists(int pid)
{
 struct yftpdutmp tmp;
 rewind(yftpdutmp);
 while (fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
  if (tmp.bu_pid == pid)
   return 1;
 }
 return 0;
}

variable_types: pid int

user_defined_types: struct yftpdutmp { char bu_type; int bu_pid; char bu_name[-1]; char bu_host[256]; long bu_time; }


repo: deepurple/bbssrc

decompiled_code:
size_t __fastcall yftpdutmp_userexists(char *s2)
{
size_t result; // rax
__int64 v2; // [rsp+0h] [rbp-138h] BYREF
char s1[304]; // [rsp+8h] [rbp-130h] BYREF

rewind(yftpdutmp);
while ( 1 )
{
result = fread(&v2, 0x130uLL, 1uLL, yftpdutmp);
if ( !result )
break;
if ( !strcmp(s1, s2) )
return 1LL;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func4(char *s2)
{
size_t result; // rax
__int64 v2; // [rsp+0h] [rbp-138h] BYREF
char s1[304]; // [rsp+8h] [rbp-130h] BYREF

rewind(yftpdutmp);
while ( 1 )
{
result = fread(&v2, 0x130uLL, 1uLL, yftpdutmp);
if ( !result )
break;
if ( !strcmp(s1, s2) )
return 1LL;
}
return result;
}

original_code:
char
yftpdutmp_userexists(char *username)
{
 struct yftpdutmp tmp;
 rewind(yftpdutmp);
 while (fread((void *) &tmp, ((int)sizeof(tmp)), 1, yftpdutmp)) {
  if (!strcmp(tmp.bu_name, username))
   return 1;
 }
 return 0;
}

variable_types:
username
char *

variable_types: struct yftpdutmp { char bu_type; int bu_pid; char bu_name[-1]; char bu_host[256]; long bu_time; }

return_type: char


getnum

decompiled_code:
__int64 __fastcall getnum(__int64 a1, int *a2, int a3)
{
__int64 v3; // rdi
__int64 v4; // rcx
__int64 v5; // rax
__int64 v6; // rdx
unsigned int v7; // er8

if ( a3 <= 0 )
return 0LL;
v3 = a1 - *a2;
if ( v3 <= 0 )
return 0LL;
v4 = a3;
v5 = 1LL;
do
{
v7 = v5;
if ( v5 == v4 )
break;
v6 = a2[v5++];
v3 -= v6;
}
while ( v3 > 0 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int *a2, int a3)
{
__int64 v3; // rdi
__int64 v4; // rcx
__int64 v5; // rax
__int64 v6; // rdx
unsigned int v7; // er8

if ( a3 <= 0 )
return 0LL;
v3 = a1 - *a2;
if ( v3 <= 0 )
return 0LL;
v4 = a3;
v5 = 1LL;
do
{
v7 = v5;
if ( v5 == v4 )
break;
v6 = a2[v5++];
v3 -= v6;
}
while ( v3 > 0 );
return v7;
}

original_code:
int
getnum(long residue, int score[1000], int count)
{
 int i;
 for (i = 0; i < count; i++) {
  residue -= score[i];
  if (residue <= 0)
   break;
 }
 return i;
}

variable_types: residue long

variable_types:
score
int [1000]

variable_types: count int

variable_types: i int

return_type: int


decompiled_code:
FILE *log_init()
{
FILE *result; // rax

result = fopen64("/home/bbs/ftphome/log", "a");
logfile = result;
if ( !result )
{
prints("421-Could not open log file.\r\n421 Server disabled for security reasons.");
exit(1);
}
return result;
}

canonical_decompiled_code:
FILE *func0()
{
FILE *result; // rax

result = fopen64("/home/bbs/ftphome/log", "a");
logfile = result;
if ( !result )
{
prints("421-Could not open log file.\r\n421 Server disabled for security reasons.");
exit(1);
}
return result;
}

original_code:
void
log_init()
{
 if (!(logfile = fopen("/home/bbs" "/ftphome" "/log", "a"))) {
  prints("421-Could not open log file.\r\n"
         "421 Server disabled for security reasons.");
  exit(1);
 }
}

return_type: void


decompiled_code:
int yftpd_log(char *format, ...)
{
int result; // eax
char *v2; // rax
unsigned int v3; // eax
time_t v4; // [rsp+0h] [rbp-508h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-500h] BYREF
char dest[48]; // [rsp+20h] [rbp-4E8h] BYREF
char s[1024]; // [rsp+50h] [rbp-4B8h] BYREF

va_start(arg, format);
result = vsnprintf(s, 0x400uLL, format, arg);
if ( logfile )
{
fseek(logfile, 0LL, 2);
time(&v4);
v2 = ctime(&v4);
*((_BYTE *)&arg[0].reg_save_area + stpcpy(dest, v2) - dest + 7) = 0;
v3 = getpid();
fprintf(logfile, "%s yftpd[%i]: %s", dest, v3, s);
result = fflush(logfile);
}
return result;
}

canonical_decompiled_code:
int func1(char *format, ...)
{
int result; // eax
char *v2; // rax
unsigned int v3; // eax
time_t v4; // [rsp+0h] [rbp-508h] BYREF
gcc_va_list arg; // [rsp+8h] [rbp-500h] BYREF
char dest[48]; // [rsp+20h] [rbp-4E8h] BYREF
char s[1024]; // [rsp+50h] [rbp-4B8h] BYREF

va_start(arg, format);
result = vsnprintf(s, 0x400uLL, format, arg);
if ( logfile )
{
fseek(logfile, 0LL, 2);
time(&v4);
v2 = ctime(&v4);
*((_BYTE *)&arg[0].reg_save_area + stpcpy(dest, v2) - dest + 7) = 0;
v3 = getpid();
fprintf(logfile, "%s yftpd[%i]: %s", dest, v3, s);
result = fflush(logfile);
}
return result;
}

original_code:
void
yftpd_log(char *format, ...)
{
 va_list val;
 char buffer[1024], timestr[40];
 time_t t;
 __builtin_va_start(val,format);
 vsnprintf(buffer, ((int)sizeof(buffer)), format, val);
 __builtin_va_end(val);
 if (logfile) {
  fseek(logfile, 0, 2);
  time(&t);
  strcpy(timestr, (char *) ctime(&t));
  timestr[strlen(timestr) - 1] = '\0';
  fprintf(logfile, "%s yftpd[%i]: %s", timestr,
   (int) getpid(), buffer);
  fflush(logfile);
 }
}

canonical_original_code:
void yftpd_log(char *format, ...)
{
 __builtin_va_list val;
 char buffer[1024]; char timestr[40];
 long t;
 __builtin_va_start(val,format);
 vsnprintf(buffer, ((int)sizeof(buffer)), format, val);
 __builtin_va_end(val);
 if (logfile) {
  fseek(logfile, 0, 2);
  time(&t);
  strcpy(timestr, (char *) ctime(&t));
  timestr[strlen(timestr) - 1] = '\0';
  fprintf(logfile, "%s yftpd[%i]: %s", timestr,
   (int) getpid(), buffer);
  fflush(logfile);
 }
}

variable_types:
format
char *

variable_types:
buffer
char [1024]

variable_types:
timestr
char [40]

variable_types: t long


decompiled_code:
int log_end()
{
int result; // eax

if ( logfile )
{
result = fclose(logfile);
logfile = 0LL;
}
return result;
}

canonical_decompiled_code:
int func2()
{
int result; // eax

if ( logfile )
{
result = fclose(logfile);
logfile = 0LL;
}
return result;
}

original_code:
void
log_end()
{
 if (logfile) {
  fclose(logfile);
  logfile = ((void *)0);
 }
}


decompiled_code:
__int64 shm_init()
{
shm_utmp = try_get_shm(3785LL, 7495048LL, 0LL);
if ( !shm_utmp )
return 0xFFFFFFFFLL;
uindexshm = try_get_shm(3787LL, 2400000LL, 0LL);
if ( !uindexshm )
return 0xFFFFFFFFLL;
shm_bcache = try_get_shm(7813LL, 460824LL, 0LL);
if ( !shm_bcache )
return 0xFFFFFFFFLL;
shm_ucache = try_get_shm(7912LL, 1300056LL, 0LL);
return (unsigned int)-(shm_ucache == 0);
}

canonical_decompiled_code:
__int64 func0()
{
shm_utmp = try_get_shm(3785LL, 7495048LL, 0LL);
if ( !shm_utmp )
return 0xFFFFFFFFLL;
uindexshm = try_get_shm(3787LL, 2400000LL, 0LL);
if ( !uindexshm )
return 0xFFFFFFFFLL;
shm_bcache = try_get_shm(7813LL, 460824LL, 0LL);
if ( !shm_bcache )
return 0xFFFFFFFFLL;
shm_ucache = try_get_shm(7912LL, 1300056LL, 0LL);
return (unsigned int)-(shm_ucache == 0);
}

original_code:
int
shm_init()
{
 shm_utmp =
     (struct UTMPFILE *) try_get_shm(3785,((int)sizeof(struct UTMPFILE)),0);
 if (shm_utmp == ((void *)0))
  return -1;
 uindexshm =
     (struct UINDEX *) try_get_shm(3787,((int)sizeof(struct UINDEX)),0);
 if (uindexshm == ((void *)0))
  return -1;
 shm_bcache =
     (struct BCACHE *) try_get_shm(7813,((int)sizeof(struct BCACHE)),0);
 if (shm_bcache == ((void *)0))
  return -1;
 shm_ucache =
     (struct UCACHE *) try_get_shm(7912,((int)sizeof(struct UCACHE)),0);
 if (shm_ucache == ((void *)0))
  return -1;
 return 0;
}

user_defined_types: struct UTMPFILE { struct user_info uinfo[-1]; long uptime; unsigned short activeuser; unsigned short maxuser; unsigned short maxtoday; unsigned short wwwguest; long activetime; int ave_score; int allprize; long watchman; unsigned int unlock; int nouse[5]; struct moneyCenter mc; }

user_defined_types: struct BCACHE { struct boardmem bcache[800]; int number; long uptime; long pollvote; }

user_defined_types: struct UCACHE { char userid[100000][-1]; int number; int usersum; long uptime; int nouse[10]; }

user_defined_types: struct moneyCenter { int ave_score; int prize777; int prize367; int prizeSoccer; unsigned char transfer_rate; unsigned char deposit_rate; unsigned char lend_rate; unsigned char isSalaryTime; }

user_defined_types: struct user_info { int active; int uid; int pid; int invisible; int sockactive; int sockaddr; int destuid; int mode; int pager; int in_chat; int fnum; short ext_idle; short isssh; long lasttime; unsigned int userlevel; int nouse1; char chatid[10]; char from[20]; char sessionid[40]; char userid[20]; char realname[20]; char username[40]; unsigned int unreadmsg; int nouse2; short curboard; int nouse3; int clubrights[4]; unsigned int friend[-1]; unsigned int reject[-1]; struct wwwsession wwwinfo; struct onebrc brc; char user_state_temp[16]; }

user_defined_types: struct boardmem { struct boardheader header; int lastpost; int total; short inboard; short bmonline; short bmcloak; int stocknum; int score; int unused[10]; }

user_defined_types: struct wwwsession { unsigned char used; unsigned char link_mode; char iskicked; char unused; long login_start_time; long lastposttime; long lastinboardtime; }

user_defined_types: struct onebrc { short num; short cur; short changed; char board[15]; int list[60]; int notetime; }

user_defined_types: struct boardheader { char filename[24]; char title[24]; int clubnum; unsigned int level; char flag; char secnumber1; char secnumber2; char type[5]; char bm[16][-1]; int hiretime[16]; int board_ctime; int board_mtime; char sec1[4]; char sec2[4]; char keyword[64]; char unused[96]; }


decompiled_code:
__int64 __fastcall add_uindex(int a1, int a2)
{
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rax

result = (unsigned int)(a1 - 1);
if ( (unsigned int)result <= 0x1869F )
{
v4 = (int)result;
v5 = uindexshm + 24LL * (int)result;
result = 0LL;
while ( *(_DWORD *)(v5 + 4 * result) != a2 )
{
if ( ++result == 6 )
{
v6 = 0LL;
while ( 1 )
{
v7 = *(int *)(v5 + 4 * v6);
if ( (int)v7 <= 0 )
break;
result = shm_utmp + 1496 * v7;
if ( !*(_DWORD *)(result - 1496) || *(_DWORD *)(result - 1492) != a1 )
break;
if ( ++v6 == 6 )
return result;
}
result = (int)v6 + 6 * v4;
*(_DWORD *)(uindexshm + 4 * result) = a2;
return result;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
__int64 result; // rax
__int64 v4; // rdi
__int64 v5; // rcx
__int64 v6; // rdx
__int64 v7; // rax

result = (unsigned int)(a1 - 1);
if ( (unsigned int)result <= 0x1869F )
{
v4 = (int)result;
v5 = uindexshm + 24LL * (int)result;
result = 0LL;
while ( *(_DWORD *)(v5 + 4 * result) != a2 )
{
if ( ++result == 6 )
{
v6 = 0LL;
while ( 1 )
{
v7 = *(int *)(v5 + 4 * v6);
if ( (int)v7 <= 0 )
break;
result = shm_utmp + 1496 * v7;
if ( !*(_DWORD *)(result - 1496) || *(_DWORD *)(result - 1492) != a1 )
break;
if ( ++v6 == 6 )
return result;
}
result = (int)v6 + 6 * v4;
*(_DWORD *)(uindexshm + 4 * result) = a2;
return result;
}
}
}
return result;
}

original_code:
void
add_uindex(int uid, int utmpent)
{
 int i, uent;
 if (uid <= 0 || uid > 100000)
  return;
 for (i = 0; i < 6; i++)
  if (uindexshm->user[uid - 1][i] == utmpent)
   return;
 for (i = 0; i < 6; i++) {
  uent = uindexshm->user[uid - 1][i];
  if (uent <= 0 || !shm_utmp->uinfo[uent - 1].active ||
      shm_utmp->uinfo[uent - 1].uid != uid) {
   uindexshm->user[uid - 1][i] = utmpent;
   return;
  }
 }
}

canonical_original_code:
void add_uindex(int uid, int utmpent)
{
 int i; int uent;
 if (uid <= 0 || uid > 100000)
  return;
 for (i = 0; i < 6; i++)
  if (uindexshm->user[uid - 1][i] == utmpent)
   return;
 for (i = 0; i < 6; i++) {
  uent = uindexshm->user[uid - 1][i];
  if (uent <= 0 || !shm_utmp->uinfo[uent - 1].active ||
      shm_utmp->uinfo[uent - 1].uid != uid) {
   uindexshm->user[uid - 1][i] = utmpent;
   return;
  }
 }
}

variable_types: uid int

variable_types: utmpent int

variable_types: uent int


decompiled_code:
_DWORD *syn_uindxexshm()
{
int i; // esi
__int64 v1; // rax
_DWORD *v2; // rax
int j; // er10
_DWORD *result; // rax

for ( i = 0; i != 5010; add_uindex(v2[1], i) )
{
while ( 1 )
{
v1 = i++;
v2 = (_DWORD *)(shm_utmp + 1496 * v1);
if ( *v2 )
break;
if ( i == 5010 )
goto LABEL_5;
}
}
LABEL_5:
for ( j = 0; j != 100000; result = rmdup_uindex(j + 1) )
;
return result;
}

canonical_decompiled_code:
_DWORD *func2()
{
int i; // esi
__int64 v1; // rax
_DWORD *v2; // rax
int j; // er10
_DWORD *result; // rax

for ( i = 0; i != 5010; func1(v2[1], i) )
{
while ( 1 )
{
v1 = i++;
v2 = (_DWORD *)(shm_utmp + 1496 * v1);
if ( *v2 )
break;
if ( i == 5010 )
goto LABEL_5;
}
}
LABEL_5:
for ( j = 0; j != 100000; result = rmdup_uindex(j + 1) )
;
return result;
}

original_code:
void
syn_uindxexshm()
{
 int i;
 for (i = 0; i < (5000 + 10); i++) {
  if (shm_utmp->uinfo[i].active) {
   add_uindex(shm_utmp->uinfo[i].uid, i + 1);
  }
 }
 for (i = 0; i < 100000; i++)
  rmdup_uindex(i + 1);
}


bonlinesync

decompiled_code:
__int64 bonlinesync()
{
__int64 v0; // rsi
int v1; // edx
__int64 v2; // rax
__int64 v3; // rdx
__int64 result; // rax
__int64 v5; // rcx

v0 = shm_bcache;
v1 = *(_DWORD *)(shm_bcache + 460800);
if ( v1 > 0 )
{
v2 = shm_bcache + 520;
v3 = shm_bcache + 576LL * (unsigned int)(v1 - 1) + 1096;
do
{
v2 += 576LL;
*(_WORD *)(v2 - 576) = 0;
}
while ( v2 != v3 );
}
result = shm_utmp;
v5 = shm_utmp + 7494960;
do
{
if ( *(_DWORD *)result && *(_DWORD *)(result + 8) )
{
if ( *(_WORD *)(result + 224) )
++*(_WORD *)(v0 + 576LL * (*(__int16 *)(result + 224) - 1) + 520);
}
result += 1496LL;
}
while ( result != v5 );
return result;
}

original_code:
void
bonlinesync()
{
 int i, numboards;
 struct user_info *uentp;
 numboards = shm_bcache->number;
 for (i = 0; i < numboards; i++)
  shm_bcache->bcache[i].inboard = 0;
 for (i = 0; i < (5000 + 10); i++) {
  uentp = &(shm_utmp->uinfo[i]);
  if (uentp->active && uentp->pid && uentp->curboard)
   shm_bcache->bcache[uentp->curboard - 1].inboard++;
 }
}

canonical_original_code:
void bonlinesync()
{
 int i; int numboards;
 struct user_info *uentp;
 numboards = shm_bcache->number;
 for (i = 0; i < numboards; i++)
  shm_bcache->bcache[i].inboard = 0;
 for (i = 0; i < (5000 + 10); i++) {
  uentp = &(shm_utmp->uinfo[i]);
  if (uentp->active && uentp->pid && uentp->curboard)
   shm_bcache->bcache[uentp->curboard - 1].inboard++;
 }
}

variable_types: numboards int

variable_types: struct user_info { int active; int uid; int pid; int invisible; int sockactive; int sockaddr; int destuid; int mode; int pager; int in_chat; int fnum; short ext_idle; short isssh; long lasttime; unsigned int userlevel; int nouse1; char chatid[10]; char from[20]; char sessionid[40]; char userid[20]; char realname[20]; char username[40]; unsigned int unreadmsg; int nouse2; short curboard; int nouse3; int clubrights[4]; unsigned int friend[-1]; unsigned int reject[-1]; struct wwwsession { unsigned char used; unsigned char link_mode; char iskicked; char unused; long login_start_time; long lastposttime; long lastinboardtime; } wwwinfo; struct onebrc { short num; short cur; short changed; char board[15]; int list[60]; int notetime; } brc; char user_state_temp[16]; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // r8
const char *v5; // rax
const char *v6; // r8
struct tm *v7; // rax
struct tm *v8; // rbx
int v9; // eax
int v10; // ebp

if ( (int)shm_init(argc, argv, envp) < 0 )
return 0;
item = time(0LL);
get_load((unsigned int)((_DWORD)&item + 8));
v3 = get_netflow();
v4 = shm_utmp;
*((_DWORD *)&item + 12) = v3;
*((_DWORD *)&item + 5) = *(_DWORD *)(shm_ucache + 1300000);
v5 = (const char *)(v4 + 74);
v6 = (const char *)(v4 + 7495034);
do
{
while ( 1 )
{
if ( *(_DWORD *)(v5 - 74) )
{
++*((_DWORD *)&item + 6);
if ( *(_DWORD *)(v5 - 66) != 1 )
{
++*((_DWORD *)&item + 7);
if ( !memcmp("162.105", v5, 7uLL) )
{
++*((_DWORD *)&item + 9);
++*((_DWORD *)&item + 10);
}
goto LABEL_5;
}
if ( !strcmp(v5 + 60, "guest") )
++*((_DWORD *)&item + 11);
else
++*((_DWORD *)&item + 8);
if ( !memcmp("162.105", v5, 7uLL) )
break;
}
LABEL_5:
v5 += 1496;
if ( v6 == v5 )
goto LABEL_12;
}
v5 += 1496;
++*((_DWORD *)&item + 9);
}
while ( v6 != v5 );
LABEL_12:
v7 = localtime(&item);
v8 = v7;
if ( !v7->tm_hour && v7->tm_min <= 5 )
*(_WORD *)(shm_utmp + 7494972) = *((_DWORD *)&item + 6);
v9 = open("/home/bbs/reclog/bbsstat.log", 65, 384LL);
v10 = v9;
if ( v9 >= 0 )
{
lseek(v9, (v8->tm_min / 6 + 10 * (v8->tm_hour + 24 * v8->tm_mday)) << 7, 0);
write(v10, &item, 0x80uLL);
close(v10);
}
syn_uindxexshm();
bonlinesync();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // r8
const char *v5; // rax
const char *v6; // r8
struct tm *v7; // rax
struct tm *v8; // rbx
int v9; // eax
int v10; // ebp

if ( (int)func0(argc, argv, envp) < 0 )
return 0;
item = time(0LL);
get_load((unsigned int)((_DWORD)&item + 8));
v3 = func4();
v4 = shm_utmp;
*((_DWORD *)&item + 12) = v3;
*((_DWORD *)&item + 5) = *(_DWORD *)(shm_ucache + 1300000);
v5 = (const char *)(v4 + 74);
v6 = (const char *)(v4 + 7495034);
do
{
while ( 1 )
{
if ( *(_DWORD *)(v5 - 74) )
{
++*((_DWORD *)&item + 6);
if ( *(_DWORD *)(v5 - 66) != 1 )
{
++*((_DWORD *)&item + 7);
if ( !memcmp("162.105", v5, 7uLL) )
{
++*((_DWORD *)&item + 9);
++*((_DWORD *)&item + 10);
}
goto LABEL_5;
}
if ( !strcmp(v5 + 60, "guest") )
++*((_DWORD *)&item + 11);
else
++*((_DWORD *)&item + 8);
if ( !memcmp("162.105", v5, 7uLL) )
break;
}
LABEL_5:
v5 += 1496;
if ( v6 == v5 )
goto LABEL_12;
}
v5 += 1496;
++*((_DWORD *)&item + 9);
}
while ( v6 != v5 );
LABEL_12:
v7 = localtime(&item);
v8 = v7;
if ( !v7->tm_hour && v7->tm_min <= 5 )
*(_WORD *)(shm_utmp + 7494972) = *((_DWORD *)&item + 6);
v9 = open("/home/bbs/reclog/bbsstat.log", 65, 384LL);
v10 = v9;
if ( v9 >= 0 )
{
lseek(v9, (v8->tm_min / 6 + 10 * (v8->tm_hour + 24 * v8->tm_mday)) << 7, 0);
write(v10, &item, 0x80uLL);
close(v10);
}
func2();
func3();
return 0;
}

original_code:
int
main()
{
 int i, fd;
 struct user_info *p;
 struct tm *ptm;
 if (shm_init() < 0)
  return 0;
 item.time = time(((void *)0));
 get_load(item.load);
 item.netflow = get_netflow();
 item.naccount = shm_ucache->number;
 for (i = 0; i < (5000 + 10); i++) {
  p = &shm_utmp->uinfo[i];
  if (!p->active)
   continue;
  item.nonline++;
  if (p->pid == 1 && strcmp(p->userid, "guest"))
   item.nwww++;
  else if (p->pid == 1)
   item.nwwwguest++;
  else
   item.ntelnet++;
  if (!strncmp("162.105", p->from, 7)) {
   item.n162105++;
   if (p->pid != 1)
    item.n162105telnet++;
  }
 }
 ptm = localtime(&item.time);
 if (ptm->tm_hour == 0 && ptm->tm_min < 6)
  shm_utmp->maxtoday = item.nonline;
 fd = open("/home/bbs""/reclog/bbsstat.log", 01 | 0100, 0600);
 if (fd >= 0) {
  lseek(fd,
        ((ptm->tm_mday * 24 + ptm->tm_hour) * 10 +
         ptm->tm_min / 6) * ((int)sizeof(item)), 0);
  write(fd, &item, ((int)sizeof(item)));
  close(fd);
 }
 syn_uindxexshm();
 bonlinesync();
}

canonical_original_code:
int main()
{
 int i; int fd;
 struct user_info *p;
 struct tm *ptm;
 if (shm_init() < 0)
  return 0;
 item.time = time(((void *)0));
 get_load(item.load);
 item.netflow = get_netflow();
 item.naccount = shm_ucache->number;
 for (i = 0; i < (5000 + 10); i++) {
  p = &shm_utmp->uinfo[i];
  if (!p->active)
   continue;
  item.nonline++;
  if (p->pid == 1 && strcmp(p->userid, "guest"))
   item.nwww++;
  else if (p->pid == 1)
   item.nwwwguest++;
  else
   item.ntelnet++;
  if (!strncmp("162.105", p->from, 7)) {
   item.n162105++;
   if (p->pid != 1)
    item.n162105telnet++;
  }
 }
 ptm = localtime(&item.time);
 if (ptm->tm_hour == 0 && ptm->tm_min < 6)
  shm_utmp->maxtoday = item.nonline;
 fd = open("/home/bbs""/reclog/bbsstat.log", 01 | 0100, 0600);
 if (fd >= 0) {
  lseek(fd,
        ((ptm->tm_mday * 24 + ptm->tm_hour) * 10 +
         ptm->tm_min / 6) * ((int)sizeof(item)), 0);
  write(fd, &item, ((int)sizeof(item)));
  close(fd);
 }
 syn_uindxexshm();
 bonlinesync();
}

variable_types: fd int

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


getusernum

decompiled_code:
__int64 __fastcall getusernum(char *s2)
{
__int64 v1; // rax
const void *v2; // r13
const char *v3; // rbx
unsigned int i; // er12

if ( *s2 )
{
v1 = try_get_shm(7912LL, 1300056LL, 0LL);
v2 = (const void *)v1;
if ( v1 )
{
v3 = (const char *)v1;
for ( i = 0; i != 100000; ++i )
{
if ( !strcasecmp(v3, s2) )
{
shmdt(v2);
return i;
}
v3 += 13;
}
shmdt(v2);
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s2)
{
__int64 v1; // rax
const void *v2; // r13
const char *v3; // rbx
unsigned int i; // er12

if ( *s2 )
{
v1 = try_get_shm(7912LL, 1300056LL, 0LL);
v2 = (const void *)v1;
if ( v1 )
{
v3 = (const char *)v1;
for ( i = 0; i != 100000; ++i )
{
if ( !strcasecmp(v3, s2) )
{
shmdt(v2);
return i;
}
v3 += 13;
}
shmdt(v2);
}
}
return 0xFFFFFFFFLL;
}

original_code:
int
getusernum(char *id)
{
 int i;
 struct UCACHE *shm_ucache;
 if (id[0] == 0)
  return -1;
 shm_ucache =
     (struct UCACHE *) try_get_shm(7912,((int)sizeof(struct UCACHE)),0);
 if (shm_ucache == ((void *)0))
  return -1;
 for (i = 0; i < 100000; i++) {
  if (!strcasecmp(shm_ucache->userid[i], id)) {
   shmdt(shm_ucache);
   return i;
  }
 }
 shmdt(shm_ucache);
 return -1;
}

variable_types:
id
char *

variable_types: struct UCACHE { char userid[100000][-1]; int number; int usersum; long uptime; int nouse[10]; } *


getuser

decompiled_code:
__int64 __fastcall getuser(int a1, _QWORD *a2)
{
int v2; // eax
int v3; // er12
int v4; // edi

if ( a1 < 0 )
return 0xFFFFFFFFLL;
v2 = open64("/home/bbs/.PASSWDS", 0);
v3 = v2;
if ( v2 < 0 )
return 0xFFFFFFFFLL;
if ( lseek64(v2, 480 * a1, 0) == -1 )
{
v4 = v3;
goto LABEL_8;
}
*a2 = 0LL;
a2[59] = 0LL;
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 480) >> 3));
v4 = v3;
if ( read(v3, a2, 0x1E0uLL) != 480 )
{
LABEL_8:
close(v4);
return 0xFFFFFFFFLL;
}
close(v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _QWORD *a2)
{
int v2; // eax
int v3; // er12
int v4; // edi

if ( a1 < 0 )
return 0xFFFFFFFFLL;
v2 = open64("/home/bbs/.PASSWDS", 0);
v3 = v2;
if ( v2 < 0 )
return 0xFFFFFFFFLL;
if ( lseek64(v2, 480 * a1, 0) == -1 )
{
v4 = v3;
goto LABEL_8;
}
*a2 = 0LL;
a2[59] = 0LL;
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 480) >> 3));
v4 = v3;
if ( read(v3, a2, 0x1E0uLL) != 480 )
{
LABEL_8:
close(v4);
return 0xFFFFFFFFLL;
}
close(v3);
return 0LL;
}

original_code:
int
getuser(int uid, struct userec *userec1)
{
 int fd;
 if (uid < 0)
  return -1;
 fd = open("/home/bbs" "/" ".PASSWDS", 00);
 if (fd < 0)
  return -1;
 if ((off_t) - 1 == lseek(fd, uid * ((int)sizeof(struct userec)), 0)) {
  close(fd);
  return -1;
 }
 bzero(userec1, ((int)sizeof(struct userec)));
 if (((int)sizeof(struct userec)) != read(fd, userec1, ((int)sizeof(struct userec)))) {
  close(fd);
  return -1;
 }
 close(fd);
 return 0;
}

variable_types: struct userec { char userid[-1]; long firstlogin; char lasthost[16]; unsigned int numlogins; unsigned int numposts; char flags[2]; char passwd[14]; char username[40]; unsigned short numdays; char unuse[30]; long dietime; long lastlogout; char ip[16]; char realmail[-1]; unsigned int userlevel; long lastlogin; long stay; char realname[40]; char address[80]; char email[80]; int signature; unsigned int userdefine; long notedate_nouse; int noteline_nouse; int notemode_nouse; } *


checkuser

decompiled_code:
__int64 __fastcall checkuser(char *s1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
time_t v5; // rax

v2 = getusernum(s1);
if ( v2 < 0
|| (int)getuser(v2, currentuser) < 0
|| strcasecmp(s1, currentuser)
|| (unsigned int)userbansite(currentuser, remotehostname) )
{
return 0;
}
if ( isanonymous )
return 1;
if ( (currentuser[232] & 1) != 0 )
{
v3 = checkpasswd((unsigned int)((_DWORD)currentuser + 50), a2);
if ( !v3 )
{
v5 = time(0LL);
logattempt(currentuser, remotehostname, "FTP", v5);
return v3;
}
return 1;
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
time_t v5; // rax

v2 = func0(s1);
if ( v2 < 0
|| (int)func1(v2, currentuser) < 0
|| strcasecmp(s1, currentuser)
|| (unsigned int)userbansite(currentuser, remotehostname) )
{
return 0;
}
if ( isanonymous )
return 1;
if ( (currentuser[232] & 1) != 0 )
{
v3 = checkpasswd((unsigned int)((_DWORD)currentuser + 50), a2);
if ( !v3 )
{
v5 = time(0LL);
logattempt(currentuser, remotehostname, "FTP", v5);
return v3;
}
return 1;
}
return 0;
}

original_code:
int
checkuser(char *id, char *pw)
{
 int currentuid;
 if ((currentuid = getusernum(id)) < 0)
  return 0;
 if (getuser(currentuid, &currentuser) < 0)
  return 0;
 if (strcasecmp(id, currentuser.userid))
  return 0;
 if (userbansite(currentuser.userid, remotehostname))
  return 0;
 if (isanonymous)
  return 1;
 if (!(((000001)&0100000000)?(currentuser.dietime):((000001)?currentuser.userlevel&(000001):1)))
  return 0;
 if (!checkpasswd(currentuser.passwd, pw)) {
  time_t t = time(((void *)0));
  logattempt(currentuser.userid, remotehostname, "FTP", t);
  return 0;
 }
 return 1;
}

canonical_original_code:
int checkuser(char *id, char *pw)
{
 int currentuid;
 if ((currentuid = getusernum(id)) < 0)
  return 0;
 if (getuser(currentuid, &currentuser) < 0)
  return 0;
 if (strcasecmp(id, currentuser.userid))
  return 0;
 if (userbansite(currentuser.userid, remotehostname))
  return 0;
 if (isanonymous)
  return 1;
 if (!(((000001)&0100000000)?(currentuser.dietime):((000001)?currentuser.userlevel&(000001):1)))
  return 0;
 if (!checkpasswd(currentuser.passwd, pw)) {
  long t = time(((void *)0));
  logattempt(currentuser.userid, remotehostname, "FTP", t);
  return 0;
 }
 return 1;
}

variable_types:
pw
char *

variable_types: currentuid int


hasreadperm

decompiled_code:
__int64 __fastcall hasreadperm(int a1, char a2, int a3)
{
__int64 result; // rax
int v4; // edx

if ( a1 )
{
v4 = *((int *)&clubrights + a1 / 32) >> (a1 % 32);
result = v4 & 1;
if ( (v4 & 1) == 0 )
result = (a2 & 0x10) != 0;
}
else
{
result = 1LL;
if ( (a3 & 0x8000) != 0 )
return result;
if ( (a3 & 0x1000000) != 0 )
{
if ( !*(_QWORD *)&currentuser[136] )
return (a3 & 0x80000) != 0;
}
else if ( a3 && (*(_DWORD *)&currentuser[232] & a3) == 0 )
{
return (a3 & 0x80000) != 0;
}
}
return result;
}

original_code:
int
hasreadperm(int clubnum, char flag, int level)
{
 if (clubnum != 0)
  return ((((clubnum)?(clubrights[clubnum/32]&(1<<(clubnum%32))):1))
   || (flag & 0x10));
 return level & 0100000 || (((level)&0100000000)?(currentuser.dietime):((level)?currentuser.userlevel&(level):1))
     || (level & 02000000);
}

variable_types: clubnum int

variable_types: flag char

variable_types: level int


decompiled_code:
__int64 __fastcall yftpd_login(__int64 a1)
{
unsigned int v1; // er12
int v2; // eax
int *v4; // rax
char *v5; // rax
struct stat64 v6; // [rsp+0h] [rbp-A8h] BYREF

if ( !stat64("/home/bbs/ftphome/deny_login", &v6) )
{
prints("421-Server disabled.\r\n");
print_file(421LL, "/home/bbs/ftphome/deny_login");
yftpd_log("Login as user '%s' failed: Server disabled.\n", &user);
exit(0);
}
if ( !strcasecmp(&user, "anonymous") || !strcasecmp(&user, "guest") )
{
strcpy(&user, "guest");
isanonymous = 1;
}
v1 = 1;
if ( (unsigned int)checkuser(&user, a1) )
{
if ( (unsigned int)seek_in_file("/home/bbs/ftphome/ftp_adm", &user) )
*(_DWORD *)&currentuser[232] |= 0x4000u;
readclubrights();
v1 = chdir("/home/bbs/ftphome/root");
if ( v1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
prints("421 Couldn't change cwd to ftp root: %s.", v5);
exit(1);
}
v2 = yftpdutmp_log(1LL);
switch ( v2 )
{
case -2:
prints("421 Multilogin is not allowed.");
exit(1);
case -1:
prints("421 Internel error, sorry...");
exit(1);
case -3:
prints("421 MAXUSER %d reached. Couldn't login", 60LL);
exit(1);
}
prints("230 User %s logged in.", currentuser);
yftpd_log("Successfully logged in as user '%s'.\n", &user);
state = 2;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // er12
int v2; // eax
int *v4; // rax
char *v5; // rax
struct stat64 v6; // [rsp+0h] [rbp-A8h] BYREF

if ( !stat64("/home/bbs/ftphome/deny_login", &v6) )
{
prints("421-Server disabled.\r\n");
print_file(421LL, "/home/bbs/ftphome/deny_login");
yftpd_log("Login as user '%s' failed: Server disabled.\n", &user);
exit(0);
}
if ( !strcasecmp(&user, "anonymous") || !strcasecmp(&user, "guest") )
{
strcpy(&user, "guest");
isanonymous = 1;
}
v1 = 1;
if ( (unsigned int)func2(&user, a1) )
{
if ( (unsigned int)func5("/home/bbs/ftphome/ftp_adm", &user) )
*(_DWORD *)&currentuser[232] |= 0x4000u;
func3();
v1 = chdir("/home/bbs/ftphome/root");
if ( v1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
prints("421 Couldn't change cwd to ftp root: %s.", v5);
exit(1);
}
v2 = yftpdutmp_log(1LL);
switch ( v2 )
{
case -2:
prints("421 Multilogin is not allowed.");
exit(1);
case -1:
prints("421 Internel error, sorry...");
exit(1);
case -3:
prints("421 MAXUSER %d reached. Couldn't login", 60LL);
exit(1);
}
prints("230 User %s logged in.", currentuser);
yftpd_log("Successfully logged in as user '%s'.\n", &user);
state = 2;
}
return v1;
}

original_code:
int
yftpd_login(char *password)
{
 struct stat buf;
 if (stat("/home/bbs" "/ftphome" "/deny_login", &buf) == 0) {
  prints("421-Server disabled.\r\n");
  print_file(421, "/home/bbs" "/ftphome" "/deny_login");
  yftpd_log
      ("Login as user '%s' failed: Server disabled.\n", user);
  exit(0);
 }
 if (!strcasecmp(user, "anonymous") || !strcasecmp(user, "guest")) {
  strcpy(user, "guest");
  isanonymous = 1;
 }
 if (!checkuser(user, password))
  return 1;
 if (seek_in_file("/home/bbs" "/ftphome" "/ftp_adm", user))
  currentuser.userlevel |= 040000;
 readclubrights();
 if (chdir("/home/bbs" "/ftphome" "/root")) {
  prints("421 Couldn't change cwd to ftp root: %s.",
         strerror((*__errno_location ())));
  exit(1);
 }
 switch (yftpdutmp_log(1)) {
 case -1:
  prints("421 Internel error, sorry...");
  exit(1);
 case -2:
  prints("421 Multilogin is not allowed.");
  exit(1);
 case -3:
  prints("421 MAXUSER %d reached. Couldn't login", 60);
  exit(1);
 default:
  break;
 }
 prints("230 User %s logged in.", currentuser.userid);
 yftpd_log("Successfully logged in as user '%s'.\n", user);
 state = STATE_AUTHENTICATED;
 return 0;
}

variable_types:
password
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


report

decompiled_code:
int __fastcall report(const char *format)
{
return printf(format);
}

canonical_decompiled_code:
int __fastcall func0(const char *format)
{
return printf(format);
}

original_code:
int
report()
{
 return;
}

canonical_original_code:
int report()
{
 return;
}


decompiled_code:
int expire_grp()
{
int v0; // eax
unsigned int i; // ebx
char v3[80]; // [rsp+0h] [rbp-238h] BYREF
char v4[80]; // [rsp+50h] [rbp-1E8h] BYREF
char s[80]; // [rsp+A0h] [rbp-198h] BYREF
char v6[95]; // [rsp+F0h] [rbp-148h] BYREF
char v7[17]; // [rsp+14Fh] [rbp-E9h] BYREF
char command[216]; // [rsp+160h] [rbp-D8h] BYREF

sprintf(v3, "%s/2nd/%s", "/home/bbs", ".GRP");
sprintf(s, "%s/2nd/%s.new", "/home/bbs", ".GRP");
v0 = open(s, 576, 384LL);
if ( v0 > 0 )
close(v0);
for ( i = 1; !(unsigned int)get_record(v3, v6, 112LL, i); ++i )
{
if ( (v6[8] & 2) != 0 )
{
sprintf(v4, "2nd/%s", v7);
sprintf(command, "/bin/rm -fr %s/%s 1>/dev/null 2>/dev/null", "/home/bbs", v4);
system(command);
}
else
{
append_record(s, v6, 112LL);
}
}
sprintf(v4, "%s/2nd/%s.old", "/home/bbs", ".GRP");
sprintf(command, "cp %s %s 1>/dev/null 2>/dev/null", v3, v4);
system(command);
sprintf(command, "mv %s %s 1>/dev/null 2>/dev/null", s, v3);
return system(command);
}

canonical_decompiled_code:
int func1()
{
int v0; // eax
unsigned int i; // ebx
char v3[80]; // [rsp+0h] [rbp-238h] BYREF
char v4[80]; // [rsp+50h] [rbp-1E8h] BYREF
char s[80]; // [rsp+A0h] [rbp-198h] BYREF
char v6[95]; // [rsp+F0h] [rbp-148h] BYREF
char v7[17]; // [rsp+14Fh] [rbp-E9h] BYREF
char command[216]; // [rsp+160h] [rbp-D8h] BYREF

sprintf(v3, "%s/2nd/%s", "/home/bbs", ".GRP");
sprintf(s, "%s/2nd/%s.new", "/home/bbs", ".GRP");
v0 = open(s, 576, 384LL);
if ( v0 > 0 )
close(v0);
for ( i = 1; !(unsigned int)get_record(v3, v6, 112LL, i); ++i )
{
if ( (v6[8] & 2) != 0 )
{
sprintf(v4, "2nd/%s", v7);
sprintf(command, "/bin/rm -fr %s/%s 1>/dev/null 2>/dev/null", "/home/bbs", v4);
system(command);
}
else
{
append_record(s, v6, 112LL);
}
}
sprintf(v4, "%s/2nd/%s.old", "/home/bbs", ".GRP");
sprintf(command, "cp %s %s 1>/dev/null 2>/dev/null", v3, v4);
system(command);
sprintf(command, "mv %s %s 1>/dev/null 2>/dev/null", s, v3);
return system(command);
}

original_code:
void
expire_grp()
{
 int pos, fd;
 char fgrp[80], fold[80], fnew[80];
 char buf[200];
 SLOT grp;
 pos = 1;
 sprintf(fgrp, "%s/2nd/%s", "/home/bbs", ".GRP");
 sprintf(fnew, "%s/2nd/%s.new", "/home/bbs", ".GRP");
 fd = open(fnew, 0100 | 01000, 0600);
 if (fd > 0)
  close(fd);
 while (get_record(fgrp, &grp, ((int)sizeof(SLOT)), pos) == 0) {
  if (grp.prop & 0x0002) {
   sprintf(fold, "2nd/%s", grp.fn);
   sprintf(buf,
    "/bin/rm -fr %s/%s 1>/dev/null 2>/dev/null",
    "/home/bbs", fold);
   system(buf);
  } else {
   append_record(fnew, &grp, ((int)sizeof(SLOT)));
  }
  pos++;
 }
 sprintf(fold, "%s/2nd/%s.old", "/home/bbs", ".GRP");
 sprintf(buf, "cp %s %s 1>/dev/null 2>/dev/null", fgrp, fold);
 system(buf);
 sprintf(buf, "mv %s %s 1>/dev/null 2>/dev/null", fnew, fgrp);
 system(buf);
 return;
}

canonical_original_code:
void expire_grp()
{
 int pos; int fd;
 char fgrp[80]; char fold[80]; char fnew[80];
 char buf[200];
 struct SLOT grp;
 pos = 1;
 sprintf(fgrp, "%s/2nd/%s", "/home/bbs", ".GRP");
 sprintf(fnew, "%s/2nd/%s.new", "/home/bbs", ".GRP");
 fd = open(fnew, 0100 | 01000, 0600);
 if (fd > 0)
  close(fd);
 while (get_record(fgrp, &grp, ((int)sizeof(SLOT)), pos) == 0) {
  if (grp.prop & 0x0002) {
   sprintf(fold, "2nd/%s", grp.fn);
   sprintf(buf,
    "/bin/rm -fr %s/%s 1>/dev/null 2>/dev/null",
    "/home/bbs", fold);
   system(buf);
  } else {
   append_record(fnew, &grp, ((int)sizeof(SLOT)));
  }
  pos++;
 }
 sprintf(fold, "%s/2nd/%s.old", "/home/bbs", ".GRP");
 sprintf(buf, "cp %s %s 1>/dev/null 2>/dev/null", fgrp, fold);
 system(buf);
 sprintf(buf, "mv %s %s 1>/dev/null 2>/dev/null", fnew, fgrp);
 system(buf);
 return;
}

variable_types: pos int

variable_types:
fgrp
char [80]

variable_types:
fold
char [80]

variable_types:
fnew
char [80]

variable_types:
buf
char [200]

variable_types: struct SLOT { long chrono; int prop; int reply; char title[30]; char userid[-1]; char price[10]; char contact[20]; char date[6]; char fn[15]; }


decompiled_code:
__int64 expire_item()
{
unsigned int v0; // er13
time_t v1; // r12
__int64 result; // rax
int v3; // ebp
int v4; // edi
unsigned int i; // ebx
__int64 v6; // rcx
char v7[80]; // [rsp+0h] [rbp-368h] BYREF
char s[80]; // [rsp+50h] [rbp-318h] BYREF
char name[80]; // [rsp+A0h] [rbp-2C8h] BYREF
char v10[80]; // [rsp+F0h] [rbp-278h] BYREF
char file[80]; // [rsp+140h] [rbp-228h] BYREF
char v12[12]; // [rsp+190h] [rbp-1D8h] BYREF
int v13; // [rsp+19Ch] [rbp-1CCh]
char v14[17]; // [rsp+1EFh] [rbp-179h] BYREF
time_t v15; // [rsp+200h] [rbp-168h] BYREF
char v16; // [rsp+208h] [rbp-160h]
char v17[17]; // [rsp+25Fh] [rbp-109h] BYREF
char command[248]; // [rsp+270h] [rbp-F8h] BYREF

v0 = 1;
v1 = time(0LL) - 7776000;
sprintf(v7, "%s/2nd/%s", "/home/bbs", ".GRP");
while ( 1 )
{
result = get_record(v7, v12, 112LL, v0);
v3 = result;
if ( (_DWORD)result )
break;
sprintf(s, "%s/2nd/%s/%s", "/home/bbs", v14, ".ITEM");
sprintf(file, "%s/2nd/%s/%s.new", "/home/bbs", v14, ".ITEM");
v4 = open(file, 576, 384LL);
if ( v4 > 0 )
close(v4);
for ( i = 1; !(unsigned int)get_record(s, &v15, 112LL, i); ++i )
{
if ( (v16 & 0x40) != 0 || v15 < v1 )
{
sprintf(name, "%s/2nd/%s/%s", "/home/bbs", v14, v17);
unlink(name);
}
else
{
++v3;
append_record(file, &v15, 112LL);
}
}
sprintf(v10, "%s/2nd/%s/%s.old", "/home/bbs", v14, ".ITEM");
sprintf(command, "cp %s %s 1>/dev/null 2>/dev/null", s, v10);
system(command);
sprintf(command, "mv %s %s 1>/dev/null 2>/dev/null", file, s);
system(command);
v6 = v0;
v13 = v3;
++v0;
substitute_record(v7, v12, 112LL, v6);
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er13
time_t v1; // r12
__int64 result; // rax
int v3; // ebp
int v4; // edi
unsigned int i; // ebx
__int64 v6; // rcx
char v7[80]; // [rsp+0h] [rbp-368h] BYREF
char s[80]; // [rsp+50h] [rbp-318h] BYREF
char name[80]; // [rsp+A0h] [rbp-2C8h] BYREF
char v10[80]; // [rsp+F0h] [rbp-278h] BYREF
char file[80]; // [rsp+140h] [rbp-228h] BYREF
char v12[12]; // [rsp+190h] [rbp-1D8h] BYREF
int v13; // [rsp+19Ch] [rbp-1CCh]
char v14[17]; // [rsp+1EFh] [rbp-179h] BYREF
time_t v15; // [rsp+200h] [rbp-168h] BYREF
char v16; // [rsp+208h] [rbp-160h]
char v17[17]; // [rsp+25Fh] [rbp-109h] BYREF
char command[248]; // [rsp+270h] [rbp-F8h] BYREF

v0 = 1;
v1 = time(0LL) - 7776000;
sprintf(v7, "%s/2nd/%s", "/home/bbs", ".GRP");
while ( 1 )
{
result = get_record(v7, v12, 112LL, v0);
v3 = result;
if ( (_DWORD)result )
break;
sprintf(s, "%s/2nd/%s/%s", "/home/bbs", v14, ".ITEM");
sprintf(file, "%s/2nd/%s/%s.new", "/home/bbs", v14, ".ITEM");
v4 = open(file, 576, 384LL);
if ( v4 > 0 )
close(v4);
for ( i = 1; !(unsigned int)get_record(s, &v15, 112LL, i); ++i )
{
if ( (v16 & 0x40) != 0 || v15 < v1 )
{
sprintf(name, "%s/2nd/%s/%s", "/home/bbs", v14, v17);
unlink(name);
}
else
{
++v3;
append_record(file, &v15, 112LL);
}
}
sprintf(v10, "%s/2nd/%s/%s.old", "/home/bbs", v14, ".ITEM");
sprintf(command, "cp %s %s 1>/dev/null 2>/dev/null", s, v10);
system(command);
sprintf(command, "mv %s %s 1>/dev/null 2>/dev/null", file, s);
system(command);
v6 = v0;
v13 = v3;
++v0;
substitute_record(v7, v12, 112LL, v6);
}
return result;
}

original_code:
void
expire_item()
{
 int pos, pos1, fd;
 char fgrp[80], fitem[80], fname[80], fold[80], fnew[80];
 char buf[200];
 time_t expire;
 SLOT grp, item;
 expire = time(0) - 90 * 86400;
 pos = pos1 = 1;
 sprintf(fgrp, "%s/2nd/%s", "/home/bbs", ".GRP");
 while (get_record(fgrp, &grp, ((int)sizeof(SLOT)), pos) == 0) {
  sprintf(fitem, "%s/2nd/%s/%s", "/home/bbs", grp.fn, ".ITEM");
  -sprintf(fnew, "%s/2nd/%s/%s.new", "/home/bbs", grp.fn,
    ".ITEM");
  fd = open(fnew, 0100 | 01000, 0600);
  if (fd > 0)
   close(fd);
  fd = 0;
  while (get_record(fitem, &item, ((int)sizeof(SLOT)), pos1) == 0) {
   if ((item.prop & 0x0040)
       || item.chrono < expire) {
    sprintf(fname, "%s/2nd/%s/%s", "/home/bbs",
     grp.fn, item.fn);
    unlink(fname);
   } else {
    fd++;
    append_record(fnew, &item, ((int)sizeof(SLOT)));
   }
   pos1++;
  }
  sprintf(fold, "%s/2nd/%s/%s.old", "/home/bbs", grp.fn, ".ITEM");
  sprintf(buf, "cp %s %s 1>/dev/null 2>/dev/null", fitem, fold);
  system(buf);
  sprintf(buf, "mv %s %s 1>/dev/null 2>/dev/null", fnew, fitem);
  system(buf);
  grp.reply = fd;
  substitute_record(fgrp, &grp, ((int)sizeof(SLOT)), pos);
  pos++;
  pos1 = 1;
 }
 return;
}

canonical_original_code:
void expire_item()
{
 int pos; int pos1; int fd;
 char fgrp[80]; char fitem[80]; char fname[80]; char fold[80]; char fnew[80];
 char buf[200];
 long expire;
 struct SLOT grp; struct SLOT item;
 expire = time(0) - 90 * 86400;
 pos = pos1 = 1;
 sprintf(fgrp, "%s/2nd/%s", "/home/bbs", ".GRP");
 while (get_record(fgrp, &grp, ((int)sizeof(SLOT)), pos) == 0) {
  sprintf(fitem, "%s/2nd/%s/%s", "/home/bbs", grp.fn, ".ITEM");
  -sprintf(fnew, "%s/2nd/%s/%s.new", "/home/bbs", grp.fn,
    ".ITEM");
  fd = open(fnew, 0100 | 01000, 0600);
  if (fd > 0)
   close(fd);
  fd = 0;
  while (get_record(fitem, &item, ((int)sizeof(SLOT)), pos1) == 0) {
   if ((item.prop & 0x0040)
       || item.chrono < expire) {
    sprintf(fname, "%s/2nd/%s/%s", "/home/bbs",
     grp.fn, item.fn);
    unlink(fname);
   } else {
    fd++;
    append_record(fnew, &item, ((int)sizeof(SLOT)));
   }
   pos1++;
  }
  sprintf(fold, "%s/2nd/%s/%s.old", "/home/bbs", grp.fn, ".ITEM");
  sprintf(buf, "cp %s %s 1>/dev/null 2>/dev/null", fitem, fold);
  system(buf);
  sprintf(buf, "mv %s %s 1>/dev/null 2>/dev/null", fnew, fitem);
  system(buf);
  grp.reply = fd;
  substitute_record(fgrp, &grp, ((int)sizeof(SLOT)), pos);
  pos++;
  pos1 = 1;
 }
 return;
}

variable_types: fd int

variable_types:
fitem
char [80]

variable_types:
fname
char [80]

variable_types: expire long

user_defined_types: struct SLOT { long chrono; int prop; int reply; char title[30]; char userid[-1]; char price[10]; char contact[20]; char date[6]; char fn[15]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
expire_grp();
expire_item(argc, argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func1();
func2(argc, argv);
return 0;
}

original_code:
int
main()
{
 expire_grp();
 expire_item();
 return 0;
}


cmpstat

decompiled_code:
__int64 __fastcall cmpstat(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a2 - *(_DWORD *)a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(const void *a1, const void *a2)
{
return (unsigned int)(*(_DWORD *)a2 - *(_DWORD *)a1);
}

original_code:
int cmpstat(struct mystat *a, struct mystat *b) {
 return (b->key - a->key);
}

variable_types:
a
struct mystat { int key; int num; } *

variable_types:
b
struct mystat *


decompiled_code:
__int64 __fastcall insert_data(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD *, char *), char *a3)
{
__int64 result; // rax
_QWORD *v5; // r12
_QWORD *v6; // r14
int v7; // eax
_QWORD *v8; // rcx

result = a2(a1 + 5940, a3);
if ( result )
{
v5 = a1 + 6000;
while ( 1 )
{
v6 = v5;
v5 -= 60;
v7 = a2(v5, a3);
v8 = v6;
if ( v7 <= 0 )
break;
*v6 = *v5;
v6[59] = v5[59];
qmemcpy(
(void *)((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v5 - ((char *)v6 - ((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8) + 480) >> 3));
if ( a1 == v5 )
{
v8 = a1;
break;
}
}
*v8 = *(_QWORD *)a3;
result = *((_QWORD *)a3 + 59);
v8[59] = result;
qmemcpy(
(void *)((unsigned __int64)(v8 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)v8 - ((unsigned __int64)(v8 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v8 - (((_DWORD)v8 + 8) & 0xFFFFFFF8) + 480) >> 3));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int64 (__fastcall *a2)(_QWORD *, char *), char *a3)
{
__int64 result; // rax
_QWORD *v5; // r12
_QWORD *v6; // r14
int v7; // eax
_QWORD *v8; // rcx

result = a2(a1 + 5940, a3);
if ( result )
{
v5 = a1 + 6000;
while ( 1 )
{
v6 = v5;
v5 -= 60;
v7 = a2(v5, a3);
v8 = v6;
if ( v7 <= 0 )
break;
*v6 = *v5;
v6[59] = v5[59];
qmemcpy(
(void *)((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)v5 - ((char *)v6 - ((unsigned __int64)(v6 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v6 - (((_DWORD)v6 + 8) & 0xFFFFFFF8) + 480) >> 3));
if ( a1 == v5 )
{
v8 = a1;
break;
}
}
*v8 = *(_QWORD *)a3;
result = *((_QWORD *)a3 + 59);
v8[59] = result;
qmemcpy(
(void *)((unsigned __int64)(v8 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)v8 - ((unsigned __int64)(v8 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v8 - (((_DWORD)v8 + 8) & 0xFFFFFFF8) + 480) >> 3));
}
return result;
}

original_code:
void
insert_data(struct userec *queue, int *comp_f(struct userec *, struct userec *),
     struct userec *aman)
{
 int i, j;
 if (comp_f(&(queue[100 - 1]), aman) <= 0)
  return;
 for (i = 100 - 1; i >= 0; i--) {
  j = (*comp_f) (&(queue[i]), aman);
  if (j > 0)
   memcpy(&(queue[i + 1]), &(queue[i]),
          ((int)sizeof(struct userec)));
  else
   break;
 }
 memcpy(&(queue[i + 1]), aman, ((int)sizeof(struct userec)));
}

canonical_original_code:
void insert_data(struct userec *queue, int *comp_f(struct userec *, struct userec *), struct userec *aman)
{
 int i; int j;
 if (comp_f(&(queue[100 - 1]), aman) <= 0)
  return;
 for (i = 100 - 1; i >= 0; i--) {
  j = (*comp_f) (&(queue[i]), aman);
  if (j > 0)
   memcpy(&(queue[i + 1]), &(queue[i]),
          ((int)sizeof(struct userec)));
  else
   break;
 }
 memcpy(&(queue[i + 1]), aman, ((int)sizeof(struct userec)));
}

variable_types: struct userec { char userid[-1]; long firstlogin; char lasthost[16]; unsigned int numlogins; unsigned int numposts; char flags[2]; char passwd[14]; char username[40]; unsigned short numdays; char unuse[30]; long dietime; long lastlogout; char ip[16]; char realmail[-1]; unsigned int userlevel; long lastlogin; long stay; char realname[40]; char address[80]; char email[80]; int signature; unsigned int userdefine; long notedate_nouse; int noteline_nouse; int notemode_nouse; } *

variable_types:
aman
struct userec *

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall insert_logins(__int64 a1)
{
int v1; // esi
int v2; // ecx
__int64 result; // rax

v1 = login_c;
v2 = *(_DWORD *)(a1 + 40);
LODWORD(result) = login_c - 1;
if ( login_c - 1 < 0 )
{
LABEL_6:
result = login_c;
login_s[2 * login_c] = v2;
login_s[2 * v1 + 1] = 1;
login_c = v1 + 1;
}
else
{
result = (int)result;
while ( login_s[2 * result] != v2 )
{
if ( (int)--result < 0 )
goto LABEL_6;
}
++login_s[2 * (int)result + 1];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
int v1; // esi
int v2; // ecx
__int64 result; // rax

v1 = login_c;
v2 = *(_DWORD *)(a1 + 40);
LODWORD(result) = login_c - 1;
if ( login_c - 1 < 0 )
{
LABEL_6:
result = login_c;
login_s[2 * login_c] = v2;
login_s[2 * v1 + 1] = 1;
login_c = v1 + 1;
}
else
{
result = (int)result;
while ( login_s[2 * result] != v2 )
{
if ( (int)--result < 0 )
goto LABEL_6;
}
++login_s[2 * (int)result + 1];
}
return result;
}

original_code:
void
insert_logins(struct userec *aman)
{
 int i;
 for (i=login_c - 1; i>=0; i--) {
  if (aman->numlogins == login_s[i].key) {
   login_s[i].num++;
   return;
  }
 }
 login_s[login_c].key=aman->numlogins;
 login_s[login_c].num=1;
 login_c ++;
}

user_defined_types: struct userec { char userid[-1]; long firstlogin; char lasthost[16]; unsigned int numlogins; unsigned int numposts; char flags[2]; char passwd[14]; char username[40]; unsigned short numdays; char unuse[30]; long dietime; long lastlogout; char ip[16]; char realmail[-1]; unsigned int userlevel; long lastlogin; long stay; char realname[40]; char address[80]; char email[80]; int signature; unsigned int userdefine; long notedate_nouse; int noteline_nouse; int notemode_nouse; }


decompiled_code:
__int64 __fastcall insert_stays(__int64 a1)
{
int v2; // edi
__int64 v3; // rcx
__int64 result; // rax

v2 = stay_c;
v3 = *(_QWORD *)(a1 + 248) / 3600LL;
LODWORD(result) = stay_c - 1;
if ( stay_c - 1 < 0 )
{
LABEL_6:
result = stay_c;
stay_s[2 * stay_c] = v3;
stay_s[2 * v2 + 1] = 1;
stay_c = v2 + 1;
}
else
{
result = (int)result;
while ( stay_s[2 * result] != v3 )
{
if ( (int)--result < 0 )
goto LABEL_6;
}
++stay_s[2 * (int)result + 1];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v2; // edi
__int64 v3; // rcx
__int64 result; // rax

v2 = stay_c;
v3 = *(_QWORD *)(a1 + 248) / 3600LL;
LODWORD(result) = stay_c - 1;
if ( stay_c - 1 < 0 )
{
LABEL_6:
result = stay_c;
stay_s[2 * stay_c] = v3;
stay_s[2 * v2 + 1] = 1;
stay_c = v2 + 1;
}
else
{
result = (int)result;
while ( stay_s[2 * result] != v3 )
{
if ( (int)--result < 0 )
goto LABEL_6;
}
++stay_s[2 * (int)result + 1];
}
return result;
}

original_code:
void
insert_stays(struct userec *aman)
{
 int i;
 for (i=stay_c - 1; i>=0; i--) {
  if (aman->stay / 60 / 60 == stay_s[i].key) {
   stay_s[i].num++;
   return;
  }
 }
 stay_s[stay_c].key=aman->stay / 60 / 60;
 stay_s[stay_c].num=1;
 stay_c ++;
}


decompiled_code:
__int64 __fastcall insert_posts(__int64 a1)
{
int v1; // esi
int v2; // ecx
__int64 result; // rax

v1 = post_c;
v2 = *(_DWORD *)(a1 + 44);
LODWORD(result) = post_c - 1;
if ( post_c - 1 < 0 )
{
LABEL_6:
result = post_c;
post_s[2 * post_c] = v2;
post_s[2 * v1 + 1] = 1;
post_c = v1 + 1;
}
else
{
result = (int)result;
while ( post_s[2 * result] != v2 )
{
if ( (int)--result < 0 )
goto LABEL_6;
}
++post_s[2 * (int)result + 1];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int v1; // esi
int v2; // ecx
__int64 result; // rax

v1 = post_c;
v2 = *(_DWORD *)(a1 + 44);
LODWORD(result) = post_c - 1;
if ( post_c - 1 < 0 )
{
LABEL_6:
result = post_c;
post_s[2 * post_c] = v2;
post_s[2 * v1 + 1] = 1;
post_c = v1 + 1;
}
else
{
result = (int)result;
while ( post_s[2 * result] != v2 )
{
if ( (int)--result < 0 )
goto LABEL_6;
}
++post_s[2 * (int)result + 1];
}
return result;
}

original_code:
void
insert_posts(struct userec *aman)
{
 int i;
 for (i=post_c - 1; i>=0; i--) {
  if (aman->numposts == post_s[i].key) {
   post_s[i].num++;
   return;
  }
 }
 post_s[post_c].key=aman->numposts;
 post_s[post_c].num=1;
 post_c ++;
}


decompiled_code:
__int64 __fastcall insert_ages(__int64 a1)
{
int v1; // edi
__int64 v2; // rsi
int v3; // ecx
__int64 result; // rax

result = now - *(_QWORD *)(a1 + 16);
v1 = age_c;
v2 = result / 86400;
v3 = (int)result / 86400;
LODWORD(result) = age_c - 1;
if ( age_c - 1 < 0 )
{
LABEL_6:
result = age_c;
age_s[2 * age_c] = v2;
age_s[2 * v1 + 1] = 1;
age_c = v1 + 1;
}
else
{
result = (int)result;
while ( age_s[2 * result] != v3 )
{
if ( (int)--result < 0 )
goto LABEL_6;
}
++age_s[2 * (int)result + 1];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
int v1; // edi
__int64 v2; // rsi
int v3; // ecx
__int64 result; // rax

result = now - *(_QWORD *)(a1 + 16);
v1 = age_c;
v2 = result / 86400;
v3 = (int)result / 86400;
LODWORD(result) = age_c - 1;
if ( age_c - 1 < 0 )
{
LABEL_6:
result = age_c;
age_s[2 * age_c] = v2;
age_s[2 * v1 + 1] = 1;
age_c = v1 + 1;
}
else
{
result = (int)result;
while ( age_s[2 * result] != v3 )
{
if ( (int)--result < 0 )
goto LABEL_6;
}
++age_s[2 * (int)result + 1];
}
return result;
}

original_code:
void
insert_ages(struct userec *aman)
{
 int i;
 int key;
 key = (now - aman->firstlogin)/60/60/24;
 for (i=age_c - 1; i>=0; i--) {
  if (key == age_s[i].key) {
   age_s[i].num++;
   return;
  }
 }
 age_s[age_c].key=key;
 age_s[age_c].num=1;
 age_c ++;
}

variable_types: key int


decompiled_code:
int __fastcall output_c(const char *a1, int a2)
{
int v2; // ebx
int *v3; // rbp
int result; // eax
int v5; // er12
int *v6; // rax
char v7[104]; // [rsp+0h] [rbp-68h] BYREF

if ( a2 == 3 )
{
v2 = stay_c;
v3 = stay_s;
}
else if ( a2 > 3 )
{
if ( a2 == 4 )
{
v2 = age_c;
v3 = age_s;
}
}
else if ( a2 == 1 )
{
v2 = login_c;
v3 = login_s;
}
else if ( a2 == 2 )
{
v2 = post_c;
v3 = post_s;
}
sprintf(v7, "/home/bbs/%s", a1);
result = open(v7, 65, 432LL);
v5 = result;
if ( result )
{
qsort(v3, v2, 8uLL, (__compar_fn_t)cmpstat);
if ( v2 > 1 )
{
v6 = v3 + 3;
do
{
*v6 += *(v6 - 2);
v6 += 2;
}
while ( v6 != &v3[2 * (v2 - 2) + 5] );
}
write(v5, v3, 8 * v2);
result = close(v5);
}
return result;
}

canonical_decompiled_code:
int __fastcall func15(const char *a1, int a2)
{
int v2; // ebx
int *v3; // rbp
int result; // eax
int v5; // er12
int *v6; // rax
char v7[104]; // [rsp+0h] [rbp-68h] BYREF

if ( a2 == 3 )
{
v2 = stay_c;
v3 = stay_s;
}
else if ( a2 > 3 )
{
if ( a2 == 4 )
{
v2 = age_c;
v3 = age_s;
}
}
else if ( a2 == 1 )
{
v2 = login_c;
v3 = login_s;
}
else if ( a2 == 2 )
{
v2 = post_c;
v3 = post_s;
}
sprintf(v7, "/home/bbs/%s", a1);
result = open(v7, 65, 432LL);
v5 = result;
if ( result )
{
qsort(v3, v2, 8uLL, (__compar_fn_t)cmpstat);
if ( v2 > 1 )
{
v6 = v3 + 3;
do
{
*v6 += *(v6 - 2);
v6 += 2;
}
while ( v6 != &v3[2 * (v2 - 2) + 5] );
}
write(v5, v3, 8 * v2);
result = close(v5);
}
return result;
}

original_code:
void
output_c(char *file, int mode)
{
 int fd;
 char fn[80];
 int count;
 int i;
 struct mystat *ms;
 switch (mode) {
  case 1:
   count = login_c;
   ms = login_s;
   break;
  case 2:
   count = post_c;
   ms = post_s;
   break;
  case 3:
   count = stay_c;
   ms = stay_s;
   break;
  case 4:
   count = age_c;
   ms = age_s;
   break;
 }
 sprintf(fn, "/home/bbs" "/%s", file);
 fd = open(fn, 01 | 0100, 0660);
 if (fd) {
  qsort(ms, count, ((int)sizeof(struct mystat)), cmpstat);
  for (i=1; i<count;i++) {
   (ms+i)->num += (ms+i-1)->num;
  }
  write(fd, ms, count*((int)sizeof(struct mystat)));
  close(fd);
 }
}

variable_types:
file
char *

variable_types: mode int

variable_types:
fn
char [80]

variable_types: count int

variable_types:
ms
struct mystat { int key; int num; } *


gentree

original_code:
int
gentree(char *basestr, struct sectree *tree)
{
 int i, len;
 struct sectree *subsec;
 len = strlen(basestr);
 strsncpy(tree->basestr, basestr, ((int)sizeof(tree->basestr)));
 strsncpy(tree->introstr, getintrostr(basestr), ((int)sizeof(tree->introstr)));
 strsncpy(tree->des, getdes(basestr), ((int)sizeof(tree->des)));
 tree->nsubsec = 0;
 bzero(tree->seccodes, ((int)sizeof(tree->seccodes)));
 for (i = 0; i < npairs && tree->nsubsec <= 20; i++) {
  if (pairs[i].seccode[0] == '*')
   continue;
  if (strlen(pairs[i].seccode) != len + 1)
   continue;
  if (strncmp(pairs[i].seccode, basestr, len))
   continue;
  subsec = malloc(((int)sizeof(struct sectree)));
  subsec->parent = tree;
  strsncpy(subsec->title, pairs[i].title, ((int)sizeof(subsec->title)));
  gentree(pairs[i].seccode, subsec);
  tree->subsec[tree->nsubsec] = subsec;
  tree->seccodes[tree->nsubsec] = pairs[i].seccode[len];
  tree->nsubsec++;
 }
 return 0;
}

canonical_original_code:
int gentree(char *basestr, struct sectree *tree)
{
 int i; int len;
 struct sectree *subsec;
 len = strlen(basestr);
 strsncpy(tree->basestr, basestr, ((int)sizeof(tree->basestr)));
 strsncpy(tree->introstr, getintrostr(basestr), ((int)sizeof(tree->introstr)));
 strsncpy(tree->des, getdes(basestr), ((int)sizeof(tree->des)));
 tree->nsubsec = 0;
 bzero(tree->seccodes, ((int)sizeof(tree->seccodes)));
 for (i = 0; i < npairs && tree->nsubsec <= 20; i++) {
  if (pairs[i].seccode[0] == '*')
   continue;
  if (strlen(pairs[i].seccode) != len + 1)
   continue;
  if (strncmp(pairs[i].seccode, basestr, len))
   continue;
  subsec = malloc(((int)sizeof(struct sectree)));
  subsec->parent = tree;
  strsncpy(subsec->title, pairs[i].title, ((int)sizeof(subsec->title)));
  gentree(pairs[i].seccode, subsec);
  tree->subsec[tree->nsubsec] = subsec;
  tree->seccodes[tree->nsubsec] = pairs[i].seccode[len];
  tree->nsubsec++;
 }
 return 0;
}

variable_types:
basestr
char *

variable_types: struct sectree { struct sectree *parent; char basestr[20]; char seccodes[20]; char introstr[-1]; struct sectree *subsec[20]; char title[30]; char des[30]; int nsubsec; } *

variable_types: len int


printtree

decompiled_code:
__int64 __fastcall printtree(const char *a1, __int64 a2, unsigned int a3)
{
__int64 v5; // rbp
__int64 v6; // rsi
int v8; // ebp
char v9[73]; // [rsp+1h] [rbp-49h]
char v10[72]; // [rsp+2h] [rbp-48h] BYREF

if ( a3 )
{
printf("/*------ %s -------*/\n", a1);
if ( *(_BYTE *)(a2 + 8) )
printf("static ");
printf("const struct sectree %s%s\n", a1, " = {");
if ( *(_QWORD *)a2 )
{
strncpy(v10, a1, 0x14uLL);
v9[strlen(v10)] = 0;
printf("\tparent: &%s,\n", v10);
}
else
{
puts("\tparent: NULL,");
}
printf("\ttitle: \"%s\",\n", (const char *)(a2 + 232));
printf("\tbasestr: \"%s\",\n", (const char *)(a2 + 8));
printf("\tseccodes: \"%s\",\n", (const char *)(a2 + 28));
printf("\tintrostr: \"%s\",\n", (const char *)(a2 + 48));
printf("\tdes: \"%s\",\n", (const char *)(a2 + 262));
printf("\tnsubsec: %d,\n", *(unsigned int *)(a2 + 292));
puts("\tsubsec: {");
if ( *(int *)(a2 + 292) > 0 )
{
v8 = 0;
do
{
printf("\t\t&%s%c,\n", a1, (unsigned int)(v8 + 65));
++v8;
}
while ( *(_DWORD *)(a2 + 292) > v8 );
}
puts("\t}\n};");
}
else
{
if ( *(_BYTE *)(a2 + 8) )
printf("static ");
printf("const struct sectree %s%s\n", a1, ";");
}
if ( *(int *)(a2 + 292) > 0 )
{
v5 = 0LL;
do
{
sprintf(v10, "%s%c", a1, (unsigned int)(v5 + 65));
v6 = *(_QWORD *)(a2 + 8 * v5++ + 72);
printtree(v10, v6, a3);
}
while ( *(_DWORD *)(a2 + 292) > (int)v5 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int64 a2, unsigned int a3)
{
__int64 v5; // rbp
__int64 v6; // rsi
int v8; // ebp
char v9[73]; // [rsp+1h] [rbp-49h]
char v10[72]; // [rsp+2h] [rbp-48h] BYREF

if ( a3 )
{
printf("/*------ %s -------*/\n", a1);
if ( *(_BYTE *)(a2 + 8) )
printf("static ");
printf("const struct sectree %s%s\n", a1, " = {");
if ( *(_QWORD *)a2 )
{
strncpy(v10, a1, 0x14uLL);
v9[strlen(v10)] = 0;
printf("\tparent: &%s,\n", v10);
}
else
{
puts("\tparent: NULL,");
}
printf("\ttitle: \"%s\",\n", (const char *)(a2 + 232));
printf("\tbasestr: \"%s\",\n", (const char *)(a2 + 8));
printf("\tseccodes: \"%s\",\n", (const char *)(a2 + 28));
printf("\tintrostr: \"%s\",\n", (const char *)(a2 + 48));
printf("\tdes: \"%s\",\n", (const char *)(a2 + 262));
printf("\tnsubsec: %d,\n", *(unsigned int *)(a2 + 292));
puts("\tsubsec: {");
if ( *(int *)(a2 + 292) > 0 )
{
v8 = 0;
do
{
printf("\t\t&%s%c,\n", a1, (unsigned int)(v8 + 65));
++v8;
}
while ( *(_DWORD *)(a2 + 292) > v8 );
}
puts("\t}\n};");
}
else
{
if ( *(_BYTE *)(a2 + 8) )
printf("static ");
printf("const struct sectree %s%s\n", a1, ";");
}
if ( *(int *)(a2 + 292) > 0 )
{
v5 = 0LL;
do
{
sprintf(v10, "%s%c", a1, (unsigned int)(v5 + 65));
v6 = *(_QWORD *)(a2 + 8 * v5++ + 72);
func4(v10, v6, a3);
}
while ( *(_DWORD *)(a2 + 292) > (int)v5 );
}
return 0LL;
}

original_code:
int
printtree(char *name0, const struct sectree *sec, int mode)
{
 char name[20];
 int i;
 if (mode)
  printf("/*------ %s -------*/\n", name0);
 if (sec->basestr[0])
  printf("static ");
 printf("const struct sectree %s%s\n", name0, mode ? " = {" : ";");
 if (mode) {
  if (sec->parent == ((void *)0))
   printf("\tparent: NULL,\n");
  else {
   strncpy(name, name0, 20);
   name[strlen(name) - 1] = 0;
   printf("\tparent: &%s,\n", name);
  }
  printf("\ttitle: \"%s\",\n", sec->title);
  printf("\tbasestr: \"%s\",\n", sec->basestr);
  printf("\tseccodes: \"%s\",\n", sec->seccodes);
  printf("\tintrostr: \"%s\",\n", sec->introstr);
  printf("\tdes: \"%s\",\n", sec->des);
  printf("\tnsubsec: %d,\n", sec->nsubsec);
  printf("\tsubsec: {\n");
  for (i = 0; i < sec->nsubsec; i++) {
   printf("\t\t&%s%c,\n", name0, 'A' + i);
  }
  printf("\t}\n};\n");
 }
 for (i = 0; i < sec->nsubsec; i++) {
  sprintf(name, "%s%c", name0, 'A' + i);
  printtree(name, sec->subsec[i], mode);
 }
 return 0;
}

canonical_original_code:
int printtree(char *name0, struct sectree *sec, int mode)
{
 char name[20];
 int i;
 if (mode)
  printf("/*------ %s -------*/\n", name0);
 if (sec->basestr[0])
  printf("static ");
 printf("const struct sectree %s%s\n", name0, mode ? " = {" : ";");
 if (mode) {
  if (sec->parent == ((void *)0))
   printf("\tparent: NULL,\n");
  else {
   strncpy(name, name0, 20);
   name[strlen(name) - 1] = 0;
   printf("\tparent: &%s,\n", name);
  }
  printf("\ttitle: \"%s\",\n", sec->title);
  printf("\tbasestr: \"%s\",\n", sec->basestr);
  printf("\tseccodes: \"%s\",\n", sec->seccodes);
  printf("\tintrostr: \"%s\",\n", sec->introstr);
  printf("\tdes: \"%s\",\n", sec->des);
  printf("\tnsubsec: %d,\n", sec->nsubsec);
  printf("\tsubsec: {\n");
  for (i = 0; i < sec->nsubsec; i++) {
   printf("\t\t&%s%c,\n", name0, 'A' + i);
  }
  printf("\t}\n};\n");
 }
 for (i = 0; i < sec->nsubsec; i++) {
  sprintf(name, "%s%c", name0, 'A' + i);
  printtree(name, sec->subsec[i], mode);
 }
 return 0;
}

variable_types:
name
char [20]

user_defined_types: struct sectree { struct sectree *parent; char basestr[20]; char seccodes[20]; char introstr[-1]; struct sectree *subsec[20]; char title[30]; char des[30]; int nsubsec; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
readseclist("seclist.local");
gentree((const char *)&unk_4914, (__int64)&rootsec);
puts("#include <stdio.h>");
puts("#include \"sectree.h\"");
printtree("sectree", (__int64)&rootsec, 0);
printtree("sectree", (__int64)&rootsec, 1u);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0("seclist.local");
func3((const char *)&unk_4914, (__int64)&rootsec);
puts("#include <stdio.h>");
puts("#include \"sectree.h\"");
func4("sectree", (__int64)&rootsec, 0);
func4("sectree", (__int64)&rootsec, 1u);
return 0;
}

original_code:
int
main()
{
 readseclist("seclist.local");
 gentree("", &rootsec);
 printf("#include <stdio.h>\n");
 printf("#include \"sectree.h\"\n");
 printtree("sectree", &rootsec, 0);
 printtree("sectree", &rootsec, 1);
 return 0;
}


isfakedir

decompiled_code:
int __fastcall isfakedir(char *s1)
{
const char *v1; // rsi
const char **i; // rbx
int result; // eax

v1 = spcname[0];
if ( !spcname[0] )
return 1;
for ( i = (const char **)off_4040C8; ; ++i )
{
result = strcmp(s1, v1);
if ( !result )
break;
v1 = *i;
if ( !v1 )
return 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(char *s1)
{
const char *v1; // rsi
const char **i; // rbx
int result; // eax

v1 = spcname[0];
if ( !spcname[0] )
return 1;
for ( i = (const char **)off_4040C8; ; ++i )
{
result = strcmp(s1, v1);
if ( !result )
break;
v1 = *i;
if ( !v1 )
return 1;
}
return result;
}

original_code:
int
isfakedir(char *file)
{
 int i;
 for (i = 0; spcname[i] != ((void *)0); i++)
  if (!strcmp(file, spcname[i]))
   return 0;
 return 1;
}


decompiled_code:
__int64 __fastcall auto_rm_fakedir(const char *a1)
{
char v2[216]; // [rsp+0h] [rbp-D8h] BYREF

sprintf(v2, "/home/bbs/boards/%s", a1);
return (unsigned int)((int)rm_fakedir(v2) >> 31);
}

canonical_decompiled_code:
__int64 __fastcall func9(const char *a1)
{
char v2[216]; // [rsp+0h] [rbp-D8h] BYREF

sprintf(v2, "/home/bbs/boards/%s", a1);
return (unsigned int)((int)func8(v2) >> 31);
}

original_code:
int
auto_rm_fakedir(struct boardheader *bhp)
{
 char buf[200];
 int i;
 sprintf(buf, "/home/bbs" "/boards/%s", bhp->filename);
 if (rm_fakedir(buf) < 0)
  return -1;
 return 0;
}

variable_types: struct boardheader { char filename[24]; char title[24]; int clubnum; unsigned int level; char flag; char secnumber1; char secnumber2; char type[5]; char bm[16][-1]; int hiretime[16]; int board_ctime; int board_mtime; char sec1[4]; char sec2[4]; char keyword[64]; char unused[96]; } *

variable_types:
buf
char [200]


decompiled_code:
void end_child(void)
{
yftpd_log("Quitting.\n");
yftpdutmp_end();
log_end();
close(sock);
}

canonical_decompiled_code:
void func0(void)
{
yftpd_log("Quitting.\n");
yftpdutmp_end();
log_end();
close(sock);
}

original_code:
void
end_child()
{
 yftpd_log("Quitting.\n");
 yftpdutmp_end();
 log_end();
 close(sock);
}


decompiled_code:
void handler_sigchld()
{
while ( waitpid(-1, 0LL, 3) > 0 )
;
}

canonical_decompiled_code:
void func1()
{
while ( waitpid(-1, 0LL, 3) > 0 )
;
}

original_code:
void
handler_sigchld(int sig)
{
 while (waitpid(-1, ((void *)0), 1 | 2) > 0) ;
}

variable_types: sig int


decompiled_code:
void __noreturn handler_sigterm()
{
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
exit(0);
}

original_code:
void
handler_sigterm(int signum)
{
 exit(0);
}

variable_types: signum int


decompiled_code:
void __noreturn handler_sigalrm()
{
if ( alarm_type )
{
close(alarm_type);
yftpd_log("Kicked from the server due to data connection timeout.\n");
prints("421 Kicked from the server due to data connection timeout.");
exit(0);
}
yftpd_log("Kicked from the server due to control connection timeout.\n");
prints("421 Kicked from the server due to control connection timeout.");
exit(0);
}

canonical_decompiled_code:
void __noreturn func3()
{
if ( alarm_type )
{
close(alarm_type);
yftpd_log("Kicked from the server due to data connection timeout.\n");
prints("421 Kicked from the server due to data connection timeout.");
exit(0);
}
yftpd_log("Kicked from the server due to control connection timeout.\n");
prints("421 Kicked from the server due to control connection timeout.");
exit(0);
}

original_code:
void
handler_sigalrm(int signum)
{
 if (alarm_type) {
  close(alarm_type);
  yftpd_log
      ("Kicked from the server due to data connection timeout.\n");
  prints
      ("421 Kicked from the server due to data connection timeout.");
  exit(0);
 } else {
  yftpd_log
      ("Kicked from the server due to control connection timeout.\n");
  prints
      ("421 Kicked from the server due to control connection timeout.");
  exit(0);
 }
}


decompiled_code:
__int64 init_everything()
{
struct rlimit64 v1; // [rsp+0h] [rbp-18h] BYREF

getrlimit64(RLIMIT_CORE, &v1);
v1.rlim_cur = 0LL;
v1.rlim_max = 0LL;
if ( setrlimit64(RLIMIT_CORE, &v1) )
exit(-1);
log_init();
return yftpdutmp_init();
}

canonical_decompiled_code:
__int64 func6()
{
struct rlimit64 v1; // [rsp+0h] [rbp-18h] BYREF

getrlimit64(RLIMIT_CORE, &v1);
v1.rlim_cur = 0LL;
v1.rlim_max = 0LL;
if ( setrlimit64(RLIMIT_CORE, &v1) )
exit(-1);
log_init();
return yftpdutmp_init();
}

original_code:
void
init_everything()
{
 struct rlimit rlim;
 getrlimit(RLIMIT_CORE, &rlim);
 rlim.rlim_max = rlim.rlim_cur = 0;
 if (setrlimit(RLIMIT_CORE, &rlim))
  exit(-1);
 log_init();
 yftpdutmp_init();
}

variable_types: struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }


decompiled_code:
__int64 __fastcall do_savequota(int a1)
{
__int64 v1; // rsi
_QWORD *v2; // rcx
__int64 v3; // rax
__int64 v4; // rdx
_QWORD *v5; // rax
__int64 v6; // rcx
__int64 v7; // rdi
char *v8; // rax
const void *v9; // rdx
__int64 result; // rax

if ( !a1 )
{
while ( 1 )
{
do
{
sleep(0x258u);
v1 = quota;
}
while ( !*(_DWORD *)(quota + 536LL) );
v2 = (_QWORD *)quotaf;
v3 = *quota;
*(_DWORD *)(quota + 536LL) = 0;
*v2 = v3;
v2[67] = *(_QWORD *)(v1 + 536);
qmemcpy(
(void *)((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v1 - ((_QWORD)v2 - ((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 544) >> 3));
}
}
v4 = quota;
v5 = (_QWORD *)quotaf;
v6 = *quota;
v7 = quotaf + 8LL;
*(_DWORD *)(quota + 536LL) = 0;
v7 &= 0xFFFFFFFFFFFFFFF8LL;
*v5 = v6;
v5[67] = *(_QWORD *)(v4 + 536);
v8 = (char *)v5 - v7;
v9 = (const void *)(v4 - (_QWORD)v8);
result = (unsigned int)((_DWORD)v8 + 544) >> 3;
qmemcpy((void *)v7, v9, 8LL * (unsigned int)result);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
__int64 v1; // rsi
_QWORD *v2; // rcx
__int64 v3; // rax
__int64 v4; // rdx
_QWORD *v5; // rax
__int64 v6; // rcx
__int64 v7; // rdi
char *v8; // rax
const void *v9; // rdx
__int64 result; // rax

if ( !a1 )
{
while ( 1 )
{
do
{
sleep(0x258u);
v1 = quota;
}
while ( !*(_DWORD *)(quota + 536LL) );
v2 = (_QWORD *)quotaf;
v3 = *quota;
*(_DWORD *)(quota + 536LL) = 0;
*v2 = v3;
v2[67] = *(_QWORD *)(v1 + 536);
qmemcpy(
(void *)((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(v1 - ((_QWORD)v2 - ((unsigned __int64)(v2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 544) >> 3));
}
}
v4 = quota;
v5 = (_QWORD *)quotaf;
v6 = *quota;
v7 = quotaf + 8LL;
*(_DWORD *)(quota + 536LL) = 0;
v7 &= 0xFFFFFFFFFFFFFFF8LL;
*v5 = v6;
v5[67] = *(_QWORD *)(v4 + 536);
v8 = (char *)v5 - v7;
v9 = (const void *)(v4 - (_QWORD)v8);
result = (unsigned int)((_DWORD)v8 + 544) >> 3;
qmemcpy((void *)v7, v9, 8LL * (unsigned int)result);
return result;
}

original_code:
void
do_savequota(int n)
{
 if (n) {
  quota->changed = 0;
  memcpy(quotaf, quota, ((int)sizeof(*quota)));
  return;
 }
 while (1) {
  sleep(10 * 60);
  if (quota->changed) {
   quota->changed = 0;
   memcpy(quotaf, quota, ((int)sizeof(*quota)));
  }
 }
}

variable_types: n int


decompiled_code:
void __noreturn do_sem()
{
int v0; // ebp
__int64 v1; // rbx
unsigned __int16 v2; // ax
struct sembuf sops; // [rsp+4h] [rbp-24h] BYREF
struct sembuf v4; // [rsp+Ah] [rbp-1Eh] BYREF

v0 = open64("/home/bbs/ftphome/flowlock", 64, 432LL);
while ( 1 )
{
v1 = try_get_shm(3785LL, 7495048LL, 0LL);
if ( v1 )
break;
sleep(0xAu);
}
if ( flock(v0, 6) >= 0 && semctl(flow_semid.s_addr, 0, 16, 0LL) >= 0 )
{
*(_DWORD *)&sops.sem_num = 0;
sops.sem_flg = 0;
v4.sem_num = 0;
v4.sem_flg = 0;
while ( 1 )
{
v2 = *(_WORD *)(v1 + 7494968);
if ( v2 <= 0x1F3u )
{
v4.sem_op = 16;
}
else if ( v2 > 0x3E7u )
{
v4.sem_op = v2 < 0x5DCu ? 8 : 4;
}
else
{
v4.sem_op = 12;
}
semop(flow_semid.s_addr, &sops, 1uLL);
semop(flow_semid.s_addr, &v4, 1uLL);
usleep(0x30D40u);
}
}
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
int v0; // ebp
__int64 v1; // rbx
unsigned __int16 v2; // ax
struct sembuf sops; // [rsp+4h] [rbp-24h] BYREF
struct sembuf v4; // [rsp+Ah] [rbp-1Eh] BYREF

v0 = open64("/home/bbs/ftphome/flowlock", 64, 432LL);
while ( 1 )
{
v1 = try_get_shm(3785LL, 7495048LL, 0LL);
if ( v1 )
break;
sleep(0xAu);
}
if ( flock(v0, 6) >= 0 && semctl(flow_semid.s_addr, 0, 16, 0LL) >= 0 )
{
*(_DWORD *)&sops.sem_num = 0;
sops.sem_flg = 0;
v4.sem_num = 0;
v4.sem_flg = 0;
while ( 1 )
{
v2 = *(_WORD *)(v1 + 7494968);
if ( v2 <= 0x1F3u )
{
v4.sem_op = 16;
}
else if ( v2 > 0x3E7u )
{
v4.sem_op = v2 < 0x5DCu ? 8 : 4;
}
else
{
v4.sem_op = 12;
}
semop(flow_semid.s_addr, &sops, 1uLL);
semop(flow_semid.s_addr, &v4, 1uLL);
usleep(0x30D40u);
}
}
exit(0);
}

original_code:
void
do_sem()
{
 struct sembuf sop0, sop1;
 union semun arg;
 int fd = open("/home/bbs" "/ftphome" "/flowlock", 0100 | 00, 0660);
 struct UTMPFILE *shm_utmp;
      AGAIN:
 shm_utmp =
     (struct UTMPFILE *) try_get_shm(3785,((int)sizeof(struct UTMPFILE)),0);
 if (!shm_utmp) {
  sleep(10);
  goto AGAIN;
 }
 if (flock(fd, 2 | 4) < 0)
  exit(0);
 arg.val = 0;
 if (semctl(flow_semid, 0, 16, arg) < 0)
  exit(0);
 sop0.sem_num = 0;
 sop0.sem_op = 0;
 sop0.sem_flg = 0;
 sop1.sem_num = 0;
 sop1.sem_flg = 0;
 while (1) {
  if (shm_utmp->activeuser < 500) {
   sop1.sem_op = 4 * 4;
  } else if (shm_utmp->activeuser < 1000) {
   sop1.sem_op = 4 * 3;
  } else if (shm_utmp->activeuser < 1500) {
   sop1.sem_op = 4 * 2;
  } else
   sop1.sem_op = 4;
  semop(flow_semid, &sop0, 1);
  semop(flow_semid, &sop1, 1);
  usleep(200000);
 }
}

canonical_original_code:
void do_sem()
{
 struct sembuf sop0; struct sembuf sop1;
 union semun arg;
 int fd = open("/home/bbs" "/ftphome" "/flowlock", 0100 | 00, 0660);
 struct UTMPFILE *shm_utmp;
      AGAIN:
 shm_utmp =
     (struct UTMPFILE *) try_get_shm(3785,((int)sizeof(struct UTMPFILE)),0);
 if (!shm_utmp) {
  sleep(10);
  goto AGAIN;
 }
 if (flock(fd, 2 | 4) < 0)
  exit(0);
 arg.val = 0;
 if (semctl(flow_semid, 0, 16, arg) < 0)
  exit(0);
 sop0.sem_num = 0;
 sop0.sem_op = 0;
 sop0.sem_flg = 0;
 sop1.sem_num = 0;
 sop1.sem_flg = 0;
 while (1) {
  if (shm_utmp->activeuser < 500) {
   sop1.sem_op = 4 * 4;
  } else if (shm_utmp->activeuser < 1000) {
   sop1.sem_op = 4 * 3;
  } else if (shm_utmp->activeuser < 1500) {
   sop1.sem_op = 4 * 2;
  } else
   sop1.sem_op = 4;
  semop(flow_semid, &sop0, 1);
  semop(flow_semid, &sop1, 1);
  usleep(200000);
 }
}

variable_types: struct sembuf { unsigned short sem_num; short sem_op; short sem_flg; }

variable_types: union semun { int val; struct semid_ds { struct ipc_perm { int __key; unsigned int uid; unsigned int gid; unsigned int cuid; unsigned int cgid; unsigned short mode; unsigned short __pad1; unsigned short __seq; unsigned short __pad2; unsigned long __glibc_reserved1; unsigned long __glibc_reserved2; } sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; } *buf; unsigned short *array; struct seminfo { int semmap; int semmni; int semmns; int semmnu; int semmsl; int semopm; int semume; int semusz; int semvmx; int semaem; } *__buf; }

variable_types: fd int

variable_types: struct UTMPFILE { struct user_info { int active; int uid; int pid; int invisible; int sockactive; int sockaddr; int destuid; int mode; int pager; int in_chat; int fnum; short ext_idle; short isssh; long lasttime; unsigned int userlevel; int nouse1; char chatid[10]; char from[20]; char sessionid[40]; char userid[20]; char realname[20]; char username[40]; unsigned int unreadmsg; int nouse2; short curboard; int nouse3; int clubrights[4]; unsigned int friend[-1]; unsigned int reject[-1]; struct wwwsession { unsigned char used; unsigned char link_mode; char iskicked; char unused; long login_start_time; long lastposttime; long lastinboardtime; } wwwinfo; struct onebrc { short num; short cur; short changed; char board[15]; int list[60]; int notetime; } brc; char user_state_temp[16]; } uinfo[-1]; long uptime; unsigned short activeuser; unsigned short maxuser; unsigned short maxtoday; unsigned short wwwguest; long activetime; int ave_score; int allprize; long watchman; unsigned int unlock; int nouse[5]; struct moneyCenter { int ave_score; int prize777; int prize367; int prizeSoccer; unsigned char transfer_rate; unsigned char deposit_rate; unsigned char lend_rate; unsigned char isSalaryTime; } mc; } *

user_defined_types: union semun { int val; struct semid_ds *buf; unsigned short *array; struct seminfo *__buf; }

user_defined_types: struct semid_ds { struct ipc_perm sem_perm; long sem_otime; unsigned long __glibc_reserved1; long sem_ctime; unsigned long __glibc_reserved2; unsigned long sem_nsems; unsigned long __glibc_reserved3; unsigned long __glibc_reserved4; }


freeitems

decompiled_code:
void __fastcall freeitems(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void freeitems(struct items *items)
{
 free(items->item);
 free(items);
}

variable_types: struct items { int n; int max; struct item { char name[50]; int value; } *item; } *

user_defined_types: struct items { int n; int max; struct item *item; }


readvalue

decompiled_code:
__int64 __fastcall readvalue(__int64 a1, const char *a2, _DWORD *a3)
{
int v4; // er13
const char *v5; // rbx
int v6; // ebp
const char *v7; // r14

v4 = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v5 = *(const char **)(a1 + 8);
v6 = 0;
while ( 1 )
{
v7 = v5;
if ( !strncmp(v5, a2, 0x32uLL) )
break;
++v6;
v5 += 56;
if ( v4 == v6 )
return 0xFFFFFFFFLL;
}
goto LABEL_5;
}
if ( v4 )
{
v7 = *(const char **)(a1 + 8);
LABEL_5:
*a3 = *((_DWORD *)v7 + 13);
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2, _DWORD *a3)
{
int v4; // er13
const char *v5; // rbx
int v6; // ebp
const char *v7; // r14

v4 = *(_DWORD *)a1;
if ( *(int *)a1 > 0 )
{
v5 = *(const char **)(a1 + 8);
v6 = 0;
while ( 1 )
{
v7 = v5;
if ( !strncmp(v5, a2, 0x32uLL) )
break;
++v6;
v5 += 56;
if ( v4 == v6 )
return 0xFFFFFFFFLL;
}
goto LABEL_5;
}
if ( v4 )
{
v7 = *(const char **)(a1 + 8);
LABEL_5:
*a3 = *((_DWORD *)v7 + 13);
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int readvalue(struct items *items, const char *name, int *value)
{
 int i;
 for(i=0;i<items->n;i++) {
  if(strncmp(items->item[i].name, name, sizeof(items->item[i].name))==0)
   break;
 }
 if(i==items->n)
  return -1;
 *value=items->item[i].value;
 return 0;
}

canonical_original_code:
int readvalue(struct items *items, char *name, int *value)
{
 int i;
 for(i=0;i<items->n;i++) {
  if(strncmp(items->item[i].name, name, sizeof(items->item[i].name))==0)
   break;
 }
 if(i==items->n)
  return -1;
 *value=items->item[i].value;
 return 0;
}

variable_types:
name
char *

variable_types:
value
int *

variable_types: i int

user_defined_types: struct item { char name[50]; int value; }


additemf

decompiled_code:
__int64 __fastcall additemf(const char *a1, int a2, const char *a3, int a4)
{
int *v6; // rax
int *v7; // rbp
__int64 result; // rax

v6 = (int *)creatitems(a2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
readitems(v6, a1);
additem(v7, a3, a4);
if ( (int)saveitems((__int64)v7, a1) < 0 )
{
freeitems(v7);
result = 0xFFFFFFFFLL;
}
else
{
freeitems(v7);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1, int a2, const char *a3, int a4)
{
int *v6; // rax
int *v7; // rbp
__int64 result; // rax

v6 = (int *)creatitems(a2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
func1(v6, a1);
func3(v7, a3, a4);
if ( (int)func2((__int64)v7, a1) < 0 )
{
func0(v7);
result = 0xFFFFFFFFLL;
}
else
{
func0(v7);
result = 0LL;
}
return result;
}

original_code:
int additemf(const char *filename, int max, const char *name, int value)
{
        struct items *its;
        its=creatitems(max);
        if(its==((void *)0)) return -1;
        readitems(its, filename);
 additem(its, name, value);
 if(saveitems(its,filename)>=0) {
  freeitems(its);
  return 0;
 }
        freeitems(its);
        return -1;
}

canonical_original_code:
int additemf(char *filename, int max, char *name, int value)
{
        struct items *its;
        its=creatitems(max);
        if(its==((void *)0)) return -1;
        readitems(its, filename);
 additem(its, name, value);
 if(saveitems(its,filename)>=0) {
  freeitems(its);
  return 0;
 }
        freeitems(its);
        return -1;
}

variable_types:
filename
char *

variable_types: max int

variable_types: value int


readvaluef

decompiled_code:
__int64 __fastcall readvaluef(const char *a1, int a2, const char *a3, _DWORD *a4)
{
int *v6; // rax
int *v7; // rbp
__int64 result; // rax

v6 = (int *)creatitems(a2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
if ( (int)readitems(v6, a1) < 0 || (int)readvalue((__int64)v7, a3, a4) < 0 )
{
freeitems(v7);
result = 0xFFFFFFFFLL;
}
else
{
freeitems(v7);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, int a2, const char *a3, _DWORD *a4)
{
int *v6; // rax
int *v7; // rbp
__int64 result; // rax

v6 = (int *)creatitems(a2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
if ( (int)func1(v6, a1) < 0 || (int)func4((__int64)v7, a3, a4) < 0 )
{
func0(v7);
result = 0xFFFFFFFFLL;
}
else
{
func0(v7);
result = 0LL;
}
return result;
}

original_code:
int readvaluef(const char *filename, int max, const char *name, int *value)
{
        struct items *its;
        its=creatitems(max);
        if(its==((void *)0)) return -1;
        if(readitems(its, filename)<0||readvalue(its,name,value)<0) {
                freeitems(its);
                return -1;
        }
        freeitems(its);
        return 0;
}

canonical_original_code:
int readvaluef(char *filename, int max, char *name, int *value)
{
        struct items *its;
        its=creatitems(max);
        if(its==((void *)0)) return -1;
        if(readitems(its, filename)<0||readvalue(its,name,value)<0) {
                freeitems(its);
                return -1;
        }
        freeitems(its);
        return 0;
}


decompiled_code:
__int64 __fastcall bs_cmp(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a2 + 2734) - *((_DWORD *)a1 + 2734));
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
return (unsigned int)(*((_DWORD *)a2 + 2734) - *((_DWORD *)a1 + 2734));
}

original_code:
int
bs_cmp(struct bscore *b, struct bscore *a)
{
 return a->score - b->score;
}

variable_types: struct bscore { char board[20]; char expname[80]; struct hword { char str[80]; void *value; struct hword *next; } *user[-1]; struct hword *author[-1]; int person; int post; int stay; int noread; int score; } *

variable_types:
a
struct bscore *

user_defined_types: struct bscore { char board[20]; char expname[80]; struct hword *user[-1]; struct hword *author[-1]; int person; int post; int stay; int noread; int score; }


decompiled_code:
__int64 __fastcall bs_post(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6; // rbp
char *v7; // r14
__int64 v8[2]; // [rsp+0h] [rbp-D8h] BYREF
char v9[32]; // [rsp+10h] [rbp-C8h] BYREF
char v10; // [rsp+30h] [rbp-A8h] BYREF

v8[0] = (__int64)v9;
v8[1] = (__int64)&v10;
mystrtok(a4, 32LL, v8, 2LL);
result = finddic(&bsstat, v9);
if ( result )
{
v6 = *(_QWORD *)(result + 80);
result = finddic(v6 + 5512, a3);
if ( !result )
{
v7 = (char *)malloc(0x60uLL);
snprintf(v7, 0x50uLL, "%s", a3);
result = insertdic(v6 + 5512, v7);
++*(_DWORD *)(v6 + 10924);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6; // rbp
char *v7; // r14
__int64 v8[2]; // [rsp+0h] [rbp-D8h] BYREF
char v9[32]; // [rsp+10h] [rbp-C8h] BYREF
char v10; // [rsp+30h] [rbp-A8h] BYREF

v8[0] = (__int64)v9;
v8[1] = (__int64)&v10;
mystrtok(a4, 32LL, v8, 2LL);
result = finddic(&bsstat, v9);
if ( result )
{
v6 = *(_QWORD *)(result + 80);
result = finddic(v6 + 5512, a3);
if ( !result )
{
v7 = (char *)malloc(0x60uLL);
snprintf(v7, 0x50uLL, "%s", a3);
result = insertdic(v6 + 5512, v7);
++*(_DWORD *)(v6 + 10924);
}
}
return result;
}

original_code:
void
bs_post(int day, char *time, char *user, char *other)
{
 struct hword *a, *tmp;
 struct bscore *data;
 char board[30], title[128];
 char *temp[2] = { board, title };
 int i;
 i = mystrtok(other, ' ', temp, 2);
 a = finddic(bsstat, board);
 if (a != ((void *)0)) {
  data = a->value;
  a = finddic(data->author, user);
  if (a == ((void *)0)) {
   tmp = malloc(((int)sizeof(struct hword)));
   snprintf(tmp->str, 80, "%s", user);
   insertdic(data->author, tmp);
   data->post++;
  }
 }
}

canonical_original_code:
void bs_post(int day, char *time, char *user, char *other)
{
 struct hword *a; struct hword *tmp;
 struct bscore *data;
 char board[30]; char title[128];
 char *temp[2] = { board, title };
 int i;
 i = mystrtok(other, ' ', temp, 2);
 a = finddic(bsstat, board);
 if (a != ((void *)0)) {
  data = a->value;
  a = finddic(data->author, user);
  if (a == ((void *)0)) {
   tmp = malloc(((int)sizeof(struct hword)));
   snprintf(tmp->str, 80, "%s", user);
   insertdic(data->author, tmp);
   data->post++;
  }
 }
}

variable_types: day int

variable_types:
time
char *

variable_types:
user
char *

variable_types:
other
char *

variable_types: struct hword { char str[80]; void *value; struct hword *next; } *

variable_types:
board
char [30]

variable_types:
title
char [128]

variable_types:
temp
char *[2]


decompiled_code:
__int64 bs_init()
{
__int64 v0; // rax
__int64 v1; // r12
__int64 v2; // rbx
const char *v3; // r13
char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // rax
__int64 v8; // r13

v0 = *(int *)(brdshm + 460800LL);
if ( (int)v0 > 0 )
{
v1 = 576 * v0;
v2 = 0LL;
do
{
v3 = (const char *)(v2 + bcache);
if ( *(_BYTE *)(v2 + bcache) )
{
v4 = (char *)malloc(0x60uLL);
v5 = v4;
if ( !v4 )
{
errlog("boardscore.c:%s line %d Can't malloc in board_init!", "bs_init", 170LL);
exit(-1);
}
snprintf(v4, 0x14uLL, "%s", v3);
v6 = (char *)calloc(1uLL, 0x2AC0uLL);
*((_QWORD *)v5 + 10) = v6;
if ( !v6 )
{
errlog("boardscore.c:%s line %d Can't malloc value in board_init!", "bs_init", 176LL);
exit(-1);
}
v7 = strcpy(v6, v5);
snprintf(v7 + 20, 0x50uLL, "[%s] %s", (const char *)(v2 + bcache + 59), (const char *)(v2 + bcache + 24));
v8 = *((_QWORD *)v5 + 10);
*(_DWORD *)(v8 + 10932) = boardnoread(v2 + bcache);
insertdic(&bsstat, v5);
}
v2 += 576LL;
}
while ( v2 != v1 );
}
return register_stat(&bs, bs_exit);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rax
__int64 v1; // r12
__int64 v2; // rbx
const char *v3; // r13
char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // rax
__int64 v8; // r13

v0 = *(int *)(brdshm + 460800LL);
if ( (int)v0 > 0 )
{
v1 = 576 * v0;
v2 = 0LL;
do
{
v3 = (const char *)(v2 + bcache);
if ( *(_BYTE *)(v2 + bcache) )
{
v4 = (char *)malloc(0x60uLL);
v5 = v4;
if ( !v4 )
{
errlog("boardscore.c:%s line %d Can't malloc in board_init!", "bs_init", 170LL);
exit(-1);
}
snprintf(v4, 0x14uLL, "%s", v3);
v6 = (char *)calloc(1uLL, 0x2AC0uLL);
*((_QWORD *)v5 + 10) = v6;
if ( !v6 )
{
errlog("boardscore.c:%s line %d Can't malloc value in board_init!", "bs_init", 176LL);
exit(-1);
}
v7 = strcpy(v6, v5);
snprintf(v7 + 20, 0x50uLL, "[%s] %s", (const char *)(v2 + bcache + 59), (const char *)(v2 + bcache + 24));
v8 = *((_QWORD *)v5 + 10);
*(_DWORD *)(v8 + 10932) = boardnoread(v2 + bcache);
insertdic(&bsstat, v5);
}
v2 += 576LL;
}
while ( v2 != v1 );
}
return register_stat(&bs, bs_exit);
}

original_code:
void
bs_init()
{
 int i;
 struct hword *tmp;
 int numboards;
 numboards = brdshm->number;
 for (i = 0; i < numboards; i++) {
  if (!bcache[i].header.filename[0])
   continue;
  tmp = malloc(((int)sizeof(struct hword)));
  if (tmp == ((void *)0)) {
   _errlog("boardscore.c" ":%s line %d " "Can't malloc in board_init!", __FUNCTION__,170);
   exit(-1);
  }
  snprintf(tmp->str, 20, "%s", bcache[i].header.filename);
  tmp->value = calloc(1, ((int)sizeof(struct bscore)));
  if (tmp->value == ((void *)0)) {
   _errlog("boardscore.c" ":%s line %d " "Can't malloc value in board_init!", __FUNCTION__,176);
   exit(-1);
  }
  strcpy(((struct bscore *) (tmp->value))->board, tmp->str);
  snprintf(((struct bscore *) (tmp->value))->expname, 80,
    "[%s] %s", bcache[i].header.type,
    bcache[i].header.title);
  ((struct bscore *) (tmp->value))->noread =
      boardnoread(&(bcache[i].header));
  insertdic(bsstat, tmp);
 }
 register_stat(bs, bs_exit);
}

variable_types: numboards int

user_defined_types: struct hword { char str[80]; void *value; struct hword *next; }


h

decompiled_code:
__int64 __fastcall h(unsigned __int8 *a1)
{
unsigned __int8 v1; // r8
unsigned int v2; // ecx
unsigned int v3; // edx
unsigned __int8 v4; // r8

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0;
v3 = 0;
do
{
v3 += v1 % 0x1Au;
v4 = a1[1];
if ( !v4 )
return 26 * (v3 % 0x1A) + v2 % 0x1A;
a1 += 2;
v2 += v4 % 0x1Au;
v1 = *a1;
}
while ( *a1 );
return 26 * (v3 % 0x1A) + v2 % 0x1A;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int8 *a1)
{
unsigned __int8 v1; // r8
unsigned int v2; // ecx
unsigned int v3; // edx
unsigned __int8 v4; // r8

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0;
v3 = 0;
do
{
v3 += v1 % 0x1Au;
v4 = a1[1];
if ( !v4 )
return 26 * (v3 % 0x1A) + v2 % 0x1A;
a1 += 2;
v2 += v4 % 0x1Au;
v1 = *a1;
}
while ( *a1 );
return 26 * (v3 % 0x1A) + v2 % 0x1A;
}

original_code:
int
h(char *id)
{
 int n1 = 0;
 int n2 = 0;
 while (*id) {
  n1 += ((unsigned char) *id) % 26;
  id++;
  if (!*id)
   break;
  n2 += ((unsigned char) *id) % 26;
  id++;
 }
 n1 %= 26;
 n2 %= 26;
 return n1 * 26 + n2;
}

variable_types:
id
char *


timeout

decompiled_code:
void __noreturn timeout()
{
reset_tty();
exit(0);
}

canonical_decompiled_code:
void __noreturn func11()
{
func10();
exit(0);
}

original_code:
static void
timeout()
{
 reset_tty();
 exit(0);
}


telnetopt

decompiled_code:
ssize_t __fastcall telnetopt(int fd, __int64 a2, int a3)
{
int v3; // er15
int v6; // ebx
_BYTE *v7; // rsi
_BYTE *v8; // rax
ssize_t result; // rax
char v10; // bp
__int64 v11; // rax
bool v12; // si
bool v13; // dl
char v14; // [rsp+Fh] [rbp-59h]
__int64 buf; // [rsp+10h] [rbp-58h] BYREF
__int16 v16; // [rsp+18h] [rbp-50h]

v3 = 0;
LABEL_2:
v6 = v3;
v7 = (_BYTE *)(a2 + v3);
v8 = v7;
while ( v6 < a3 )
{
if ( *v8++ == 0xFF )
{
if ( v3 < v6 && write(1, v7, v6 - v3) < 0 )
return 0xFFFFFFFFLL;
v3 = v6 + 3;
v10 = *(_BYTE *)(a2 + v6 + 1);
v14 = *(_BYTE *)(a2 + v6 + 2);
fflush(stdout);
if ( v10 == -3 )
{
if ( v14 == 3 || v14 == 24 )
LOWORD(buf) = -1025;
else
LABEL_25:
LOWORD(buf) = -769;
LABEL_14:
BYTE2(buf) = v14;
write(fd, &buf, 3uLL);
goto LABEL_2;
}
if ( (unsigned __int8)(v10 + 5) <= 1u )
{
if ( (v14 & 0xFD) == 1 || v14 == 24 )
LOWORD(buf) = -513;
else
LOWORD(buf) = -257;
goto LABEL_14;
}
switch ( v10 )
{
case -2:
goto LABEL_25;
case -6:
if ( a3 > v3 && v14 != -16 )
{
v11 = v6 + 4;
do
{
v3 = v11;
v12 = *(_BYTE *)(a2 + v11 - 1) != 0xF0;
v13 = a3 > (int)v11++;
}
while ( v13 && v12 );
}
buf = 0x49534E410018FAFFLL;
v16 = -3841;
write(fd, &buf, 0xAuLL);
break;
case -1:
LOBYTE(buf) = -1;
BYTE1(buf) = v14;
if ( a3 <= v3 )
write(fd, &buf, 1uLL);
else
write(fd, &buf, 2uLL);
break;
}
goto LABEL_2;
}
++v6;
}
result = 0LL;
if ( v3 < a3 )
result = write(1, v7, a3 - v3) >> 63;
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func12(int fd, __int64 a2, int a3)
{
int v3; // er15
int v6; // ebx
_BYTE *v7; // rsi
_BYTE *v8; // rax
ssize_t result; // rax
char v10; // bp
__int64 v11; // rax
bool v12; // si
bool v13; // dl
char v14; // [rsp+Fh] [rbp-59h]
__int64 buf; // [rsp+10h] [rbp-58h] BYREF
__int16 v16; // [rsp+18h] [rbp-50h]

v3 = 0;
LABEL_2:
v6 = v3;
v7 = (_BYTE *)(a2 + v3);
v8 = v7;
while ( v6 < a3 )
{
if ( *v8++ == 0xFF )
{
if ( v3 < v6 && write(1, v7, v6 - v3) < 0 )
return 0xFFFFFFFFLL;
v3 = v6 + 3;
v10 = *(_BYTE *)(a2 + v6 + 1);
v14 = *(_BYTE *)(a2 + v6 + 2);
fflush(stdout);
if ( v10 == -3 )
{
if ( v14 == 3 || v14 == 24 )
LOWORD(buf) = -1025;
else
LABEL_25:
LOWORD(buf) = -769;
LABEL_14:
BYTE2(buf) = v14;
write(fd, &buf, 3uLL);
goto LABEL_2;
}
if ( (unsigned __int8)(v10 + 5) <= 1u )
{
if ( (v14 & 0xFD) == 1 || v14 == 24 )
LOWORD(buf) = -513;
else
LOWORD(buf) = -257;
goto LABEL_14;
}
switch ( v10 )
{
case -2:
goto LABEL_25;
case -6:
if ( a3 > v3 && v14 != -16 )
{
v11 = v6 + 4;
do
{
v3 = v11;
v12 = *(_BYTE *)(a2 + v11 - 1) != 0xF0;
v13 = a3 > (int)v11++;
}
while ( v13 && v12 );
}
buf = 0x49534E410018FAFFLL;
v16 = -3841;
write(fd, &buf, 0xAuLL);
break;
case -1:
LOBYTE(buf) = -1;
BYTE1(buf) = v14;
if ( a3 <= v3 )
write(fd, &buf, 1uLL);
else
write(fd, &buf, 2uLL);
break;
}
goto LABEL_2;
}
++v6;
}
result = 0LL;
if ( v3 < a3 )
result = write(1, v7, a3 - v3) >> 63;
return result;
}

original_code:
int
telnetopt(int fd, char *buf, int max)
{
 unsigned char c, d, e;
 int pp = 0, start = 0;
 unsigned char tmp[30];
 while (pp < max) {
  c = buf[pp++];
  if (c == 255) {
   if (pp - 1 > start)
    if (write(1, buf+start, pp-start-1) < 0)
     return -1;
   d = buf[pp++];
   e = buf[pp++];
   fflush(stdout);
   if ((d == 253) && (e == 3 || e == 24)) {
    tmp[0] = 255;
    tmp[1] = 251;
    tmp[2] = e;
    write(fd, tmp, 3);
    start = pp;
    continue;
   }
   if ((d == 251 || d == 252)
       && (e == 1 || e == 3 || e == 24)) {
    tmp[0] = 255;
    tmp[1] = 253;
    tmp[2] = e;
    write(fd, tmp, 3);
    start = pp;
    continue;
   }
   if (d == 251 || d == 252) {
    tmp[0] = 255;
    tmp[1] = 254;
    tmp[2] = e;
    write(fd, tmp, 3);
    start = pp;
    continue;
   }
   if (d == 253 || d == 254) {
    tmp[0] = 255;
    tmp[1] = 252;
    tmp[2] = e;
    write(fd, tmp, 3);
    start = pp;
    continue;
   }
   if (d == 250) {
    while (e != 240 && pp < max)
     e = buf[pp++];
    tmp[0] = 255;
    tmp[1] = 250;
    tmp[2] = 24;
    tmp[3] = 0;
    tmp[4] = 65;
    tmp[5] = 78;
    tmp[6] = 83;
    tmp[7] = 73;
    tmp[8] = 255;
    tmp[9] = 240;
    write(fd, tmp, 10);
    start = pp;
    continue;
   }
   if (d == 255) {
    tmp[0] = d;
    tmp[1] = e;
    if (pp < max) {
     write(fd, tmp, 2);
    } else
     write(fd, tmp, 1);
   }
   start = pp;
  }
 }
 if (start < max)
  if (write(1, buf+start, max-start)<0)
   return -1;
 return 0;
}

canonical_original_code:
int telnetopt(int fd, char *buf, int max)
{
 unsigned char c; unsigned char d; unsigned char e;
 int pp = 0; int start = 0;
 unsigned char tmp[30];
 while (pp < max) {
  c = buf[pp++];
  if (c == 255) {
   if (pp - 1 > start)
    if (write(1, buf+start, pp-start-1) < 0)
     return -1;
   d = buf[pp++];
   e = buf[pp++];
   fflush(stdout);
   if ((d == 253) && (e == 3 || e == 24)) {
    tmp[0] = 255;
    tmp[1] = 251;
    tmp[2] = e;
    write(fd, tmp, 3);
    start = pp;
    continue;
   }
   if ((d == 251 || d == 252)
       && (e == 1 || e == 3 || e == 24)) {
    tmp[0] = 255;
    tmp[1] = 253;
    tmp[2] = e;
    write(fd, tmp, 3);
    start = pp;
    continue;
   }
   if (d == 251 || d == 252) {
    tmp[0] = 255;
    tmp[1] = 254;
    tmp[2] = e;
    write(fd, tmp, 3);
    start = pp;
    continue;
   }
   if (d == 253 || d == 254) {
    tmp[0] = 255;
    tmp[1] = 252;
    tmp[2] = e;
    write(fd, tmp, 3);
    start = pp;
    continue;
   }
   if (d == 250) {
    while (e != 240 && pp < max)
     e = buf[pp++];
    tmp[0] = 255;
    tmp[1] = 250;
    tmp[2] = 24;
    tmp[3] = 0;
    tmp[4] = 65;
    tmp[5] = 78;
    tmp[6] = 83;
    tmp[7] = 73;
    tmp[8] = 255;
    tmp[9] = 240;
    write(fd, tmp, 10);
    start = pp;
    continue;
   }
   if (d == 255) {
    tmp[0] = d;
    tmp[1] = e;
    if (pp < max) {
     write(fd, tmp, 2);
    } else
     write(fd, tmp, 1);
   }
   start = pp;
  }
 }
 if (start < max)
  if (write(1, buf+start, max-start)<0)
   return -1;
 return 0;
}

variable_types: fd int

variable_types:
buf
char *

variable_types:
c
unsigned char

variable_types:
d
unsigned char

variable_types:
e
unsigned char

variable_types: pp int

variable_types: start int

variable_types:
tmp
unsigned char [30]


decompiled_code:
char *__fastcall void1(char *s)
{
char v1; // al
int v3; // ecx
char v4; // di
__int64 v5; // rsi
char *v6; // rdx

v1 = *s;
v3 = 0;
if ( !*s )
return s;
while ( 1 )
{
while ( 1 )
{
v4 = v1;
v5 = v3 + 1;
v1 = s[v5];
if ( v4 < 0 )
break;
if ( !v1 )
return s;
++v3;
}
if ( !v1 )
break;
v3 += 2;
v6 = &s[v3];
if ( (unsigned __int8)v1 > 0x1Fu )
{
v1 = *v6;
if ( !*v6 )
return s;
}
else
{
s[v5 - 1] = 32;
v1 = *v6;
if ( !*v6 )
return s;
}
}
s[strlen(s) - 1] = 0;
return s;
}

canonical_decompiled_code:
char *__fastcall func2(char *s)
{
char v1; // al
int v3; // ecx
char v4; // di
__int64 v5; // rsi
char *v6; // rdx

v1 = *s;
v3 = 0;
if ( !*s )
return s;
while ( 1 )
{
while ( 1 )
{
v4 = v1;
v5 = v3 + 1;
v1 = s[v5];
if ( v4 < 0 )
break;
if ( !v1 )
return s;
++v3;
}
if ( !v1 )
break;
v3 += 2;
v6 = &s[v3];
if ( (unsigned __int8)v1 > 0x1Fu )
{
v1 = *v6;
if ( !*v6 )
return s;
}
else
{
s[v5 - 1] = 32;
v1 = *v6;
if ( !*v6 )
return s;
}
}
s[strlen(s) - 1] = 0;
return s;
}

original_code:
char *
void1(unsigned char *s)
{
 int i;
 int flag = 0;
 for (i = 0; s[i]; i++) {
  if (flag == 0) {
   if (s[i] >= 128)
    flag = 1;
   continue;
  }
  flag = 0;
  if (s[i] < 32)
   s[i - 1] = 32;
 }
 if (flag)
  s[strlen(s) - 1] = 0;
 return s;
}

canonical_original_code:
char *void1(unsigned char *s)
{
 int i;
 int flag = 0;
 for (i = 0; s[i]; i++) {
  if (flag == 0) {
   if (s[i] >= 128)
    flag = 1;
   continue;
  }
  flag = 0;
  if (s[i] < 32)
   s[i - 1] = 32;
 }
 if (flag)
  s[strlen(s) - 1] = 0;
 return s;
}

variable_types:
s
unsigned char *

variable_types: i int

variable_types: flag int

return_type: char *


decompiled_code:
char *__fastcall userid_str(__int64 a1)
{
char *v1; // rbp
char *v2; // rax
int *v3; // rax
char v5[256]; // [rsp+0h] [rbp-208h] BYREF
char s[264]; // [rsp+100h] [rbp-108h] BYREF

strsncpy(s, a1, 255LL);
buf_0[0] = 0;
v1 = strtok(s, " ,();\r\n\t");
if ( v1 )
{
while ( strlen(buf_0) <= 0x18F )
{
v2 = strchr(v1, 46);
if ( v2 )
{
v2[1] = 0;
strcat(buf_0, v1);
}
else
{
v3 = nohtml(v1);
sprintf(v5, "%s", (const char *)v3, (const char *)v3);
strcat(buf_0, v5);
}
v1 = strtok(0LL, " ,();\r\n\t");
if ( !v1 )
break;
*(_WORD *)&buf_0[strlen(buf_0)] = 32;
}
}
return buf_0;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1)
{
char *v1; // rbp
char *v2; // rax
int *v3; // rax
char v5[256]; // [rsp+0h] [rbp-208h] BYREF
char s[264]; // [rsp+100h] [rbp-108h] BYREF

strsncpy(s, a1, 255LL);
buf_0[0] = 0;
v1 = strtok(s, " ,();\r\n\t");
if ( v1 )
{
while ( strlen(buf_0) <= 0x18F )
{
v2 = strchr(v1, 46);
if ( v2 )
{
v2[1] = 0;
strcat(buf_0, v1);
}
else
{
v3 = func1(v1);
sprintf(v5, "%s", (const char *)v3, (const char *)v3);
strcat(buf_0, v5);
}
v1 = strtok(0LL, " ,();\r\n\t");
if ( !v1 )
break;
*(_WORD *)&buf_0[strlen(buf_0)] = 32;
}
}
return buf_0;
}

original_code:
char *
userid_str(char *s)
{
 static char buf[512];
 char buf2[256], tmp[256], *ptr, *ptr2;
 strsncpy(tmp, s, 255);
 buf[0] = 0;
 ptr = strtok(tmp, " ,();\r\n\t");
 while (ptr && strlen(buf) < 400) {
  if ((ptr2 = strchr(ptr, '.'))) {
   ptr2[1] = 0;
   strcat(buf, ptr);
  } else {
   ptr = nohtml(ptr);
   sprintf(buf2, "%s", ptr, ptr);
   strcat(buf, buf2);
  }
  ptr = strtok(0, " ,();\r\n\t");
  if (ptr)
   strcat(buf, " ");
 }
 return buf;
}

canonical_original_code:
char *userid_str(char *s)
{
 static char buf[512];
 char buf2[256]; char tmp[256]; char *ptr; char *ptr2;
 strsncpy(tmp, s, 255);
 buf[0] = 0;
 ptr = strtok(tmp, " ,();\r\n\t");
 while (ptr && strlen(buf) < 400) {
  if ((ptr2 = strchr(ptr, '.'))) {
   ptr2[1] = 0;
   strcat(buf, ptr);
  } else {
   ptr = nohtml(ptr);
   sprintf(buf2, "%s", ptr, ptr);
   strcat(buf, buf2);
  }
  ptr = strtok(0, " ,();\r\n\t");
  if (ptr)
   strcat(buf, " ");
 }
 return buf;
}

variable_types:
s
char *

variable_types:
buf
char [512]

variable_types:
tmp
char [256]

variable_types:
ptr
char *


addmiauthor

decompiled_code:
__int64 __fastcall addmiauthor(__int64 a1, const char *a2)
{
int v3; // er13
const char *v4; // rbx
int i; // ebp
__int64 v7; // rdi
unsigned int v8; // er13

v3 = *(_DWORD *)(a1 + 100);
if ( v3 <= 0 )
{
v7 = 104LL;
}
else
{
v4 = (const char *)(a1 + 104);
for ( i = 0; ; ++i )
{
if ( !strncmp(v4, a2, 0x10uLL) )
return (unsigned int)v3;
v4 += 16;
if ( i + 1 == v3 )
break;
}
if ( v3 > 4 )
return (unsigned int)-1;
v7 = 16LL * (i + 7) + 8;
}
strsncpy(a1 + v7, a2, 16LL);
v8 = *(_DWORD *)(a1 + 100) + 1;
*(_DWORD *)(a1 + 100) = v8;
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
int v3; // er13
const char *v4; // rbx
int i; // ebp
__int64 v7; // rdi
unsigned int v8; // er13

v3 = *(_DWORD *)(a1 + 100);
if ( v3 <= 0 )
{
v7 = 104LL;
}
else
{
v4 = (const char *)(a1 + 104);
for ( i = 0; ; ++i )
{
if ( !strncmp(v4, a2, 0x10uLL) )
return (unsigned int)v3;
v4 += 16;
if ( i + 1 == v3 )
break;
}
if ( v3 > 4 )
return (unsigned int)-1;
v7 = 16LL * (i + 7) + 8;
}
strsncpy(a1 + v7, a2, 16LL);
v8 = *(_DWORD *)(a1 + 100) + 1;
*(_DWORD *)(a1 + 100) = v8;
return v8;
}

original_code:
int
addmiauthor(struct markeditem *mi, char *author)
{
 int i;
 for (i = 0; i < mi->n; i++) {
  if (!strncmp(mi->author[i], author, ((int)sizeof(mi->author[i])))) {
   return mi->n;
  }
 }
 if (i >= 5)
  return -1;
 strsncpy(mi->author[i], author, ((int)sizeof(mi->author[i])));
 mi->n++;
 return mi->n;
}

variable_types: struct markeditem { char title[100]; int n; char author[5][16]; int time; int thread; } *

variable_types:
author
char *