hasreadperm

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

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

canonical_decompiled_code:
__int64 __fastcall func4(int a1, char a2, int a3)
{
__int64 result; // rax

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


repo: deepurple/bbssrc

decompiled_code:
__int64 __fastcall yftpd_login(__int64 a1)
{
unsigned int v1; // ebx
int v3; // eax
int *v4; // rax
char *v5; // rax
struct stat64 v6; // [rsp+0h] [rbp-98h] 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);
}
v3 = yftpdutmp_log(1LL);
switch ( v3 )
{
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; // ebx
int v3; // eax
int *v4; // rax
char *v5; // rax
struct stat64 v6; // [rsp+0h] [rbp-98h] 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);
}
v3 = yftpdutmp_log(1LL);
switch ( v3 )
{
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]; }

return_type: int

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 *a1)
{
return printf(a1);
}

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

original_code:
int
report()
{
 return;
}

canonical_original_code:
int report()
{
 return;
}


decompiled_code:
int expire_grp()
{
int v0; // eax
unsigned int i; // ebx
_BYTE v3[95]; // [rsp+0h] [rbp-238h] BYREF
char v4[17]; // [rsp+5Fh] [rbp-1D9h] BYREF
char command[208]; // [rsp+70h] [rbp-1C8h] BYREF
char file[80]; // [rsp+140h] [rbp-F8h] BYREF
char v7[80]; // [rsp+190h] [rbp-A8h] BYREF
char s[88]; // [rsp+1E0h] [rbp-58h] BYREF

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

canonical_decompiled_code:
int func1()
{
int v0; // eax
unsigned int i; // ebx
_BYTE v3[95]; // [rsp+0h] [rbp-238h] BYREF
char v4[17]; // [rsp+5Fh] [rbp-1D9h] BYREF
char command[208]; // [rsp+70h] [rbp-1C8h] BYREF
char file[80]; // [rsp+140h] [rbp-F8h] BYREF
char v7[80]; // [rsp+190h] [rbp-A8h] BYREF
char s[88]; // [rsp+1E0h] [rbp-58h] BYREF

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

return_type: void


decompiled_code:
__int64 expire_item()
{
time_t v0; // r12
unsigned int i; // er13
unsigned int j; // ebx
int v3; // ebp
__int64 result; // rax
int v5; // eax
time_t v6; // [rsp+0h] [rbp-368h] BYREF
char v7; // [rsp+8h] [rbp-360h]
char v8[17]; // [rsp+5Fh] [rbp-309h] BYREF
char v9[12]; // [rsp+70h] [rbp-2F8h] BYREF
int v10; // [rsp+7Ch] [rbp-2ECh]
char v11[17]; // [rsp+CFh] [rbp-299h] BYREF
char command[208]; // [rsp+E0h] [rbp-288h] BYREF
char file[80]; // [rsp+1B0h] [rbp-1B8h] BYREF
char v14[80]; // [rsp+200h] [rbp-168h] BYREF
char name[80]; // [rsp+250h] [rbp-118h] BYREF
char v16[80]; // [rsp+2A0h] [rbp-C8h] BYREF
char s[120]; // [rsp+2F0h] [rbp-78h] BYREF

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

canonical_decompiled_code:
__int64 func2()
{
time_t v0; // r12
unsigned int i; // er13
unsigned int j; // ebx
int v3; // ebp
__int64 result; // rax
int v5; // eax
time_t v6; // [rsp+0h] [rbp-368h] BYREF
char v7; // [rsp+8h] [rbp-360h]
char v8[17]; // [rsp+5Fh] [rbp-309h] BYREF
char v9[12]; // [rsp+70h] [rbp-2F8h] BYREF
int v10; // [rsp+7Ch] [rbp-2ECh]
char v11[17]; // [rsp+CFh] [rbp-299h] BYREF
char command[208]; // [rsp+E0h] [rbp-288h] BYREF
char file[80]; // [rsp+1B0h] [rbp-1B8h] BYREF
char v14[80]; // [rsp+200h] [rbp-168h] BYREF
char name[80]; // [rsp+250h] [rbp-118h] BYREF
char v16[80]; // [rsp+2A0h] [rbp-C8h] BYREF
char s[120]; // [rsp+2F0h] [rbp-78h] BYREF

v0 = time(0LL) - 7776000;
sprintf(s, "%s/2nd/%s", "/home/bbs", ".GRP");
for ( i = 1; ; ++i )
{
result = get_record(s, v9, 112LL, i);
v3 = result;
if ( (_DWORD)result )
break;
sprintf(v16, "%s/2nd/%s/%s", "/home/bbs", v11, ".ITEM");
sprintf(file, "%s/2nd/%s/%s.new", "/home/bbs", v11, ".ITEM");
v5 = open(file, 576, 384LL);
if ( v5 > 0 )
close(v5);
for ( j = 1; !(unsigned int)get_record(v16, &v6, 112LL, j); ++j )
{
if ( (v7 & 0x40) != 0 || v6 < v0 )
{
sprintf(name, "%s/2nd/%s/%s", "/home/bbs", v11, v8);
unlink(name);
}
else
{
++v3;
append_record(file, &v6, 112LL);
}
}
sprintf(v14, "%s/2nd/%s/%s.old", "/home/bbs", v11, ".ITEM");
sprintf(command, "cp %s %s 1>/dev/null 2>/dev/null", v16, v14);
system(command);
sprintf(command, "mv %s %s 1>/dev/null 2>/dev/null", file, v16);
system(command);
v10 = v3;
substitute_record(s, v9, 112LL, i);
}
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:
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

canonical_name: 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(__int64 a1, __int64 (__fastcall *a2)(__int64, char *), char *a3)
{
_QWORD *v4; // rbx
__int64 result; // rax
int i; // ebp
_QWORD *v7; // r13

v4 = (_QWORD *)(a1 + 47520);
result = a2(a1 + 47520, a3);
if ( result )
{
for ( i = 99; i != -1; --i )
{
if ( (int)a2((__int64)v4, a3) <= 0 )
break;
v4[60] = *v4;
v4[119] = v4[59];
qmemcpy(
(void *)((unsigned __int64)(v4 + 61) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(((unsigned __int64)(v4 + 61) & 0xFFFFFFFFFFFFFFF8LL) - 480),
8LL * (((_DWORD)v4 + 480 - (((_DWORD)v4 + 488) & 0xFFFFFFF8) + 480) >> 3));
v4 -= 60;
}
v7 = (_QWORD *)(480 * (i + 1LL) + a1);
*v7 = *(_QWORD *)a3;
result = *((_QWORD *)a3 + 59);
v7[59] = result;
qmemcpy(
(void *)((unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)v7 - ((unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v7 - (((_DWORD)v7 + 8) & 0xFFFFFFF8) + 480) >> 3));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 (__fastcall *a2)(__int64, char *), char *a3)
{
_QWORD *v4; // rbx
__int64 result; // rax
int i; // ebp
_QWORD *v7; // r13

v4 = (_QWORD *)(a1 + 47520);
result = a2(a1 + 47520, a3);
if ( result )
{
for ( i = 99; i != -1; --i )
{
if ( (int)a2((__int64)v4, a3) <= 0 )
break;
v4[60] = *v4;
v4[119] = v4[59];
qmemcpy(
(void *)((unsigned __int64)(v4 + 61) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(((unsigned __int64)(v4 + 61) & 0xFFFFFFFFFFFFFFF8LL) - 480),
8LL * (((_DWORD)v4 + 480 - (((_DWORD)v4 + 488) & 0xFFFFFFF8) + 480) >> 3));
v4 -= 60;
}
v7 = (_QWORD *)(480 * (i + 1LL) + a1);
*v7 = *(_QWORD *)a3;
result = *((_QWORD *)a3 + 59);
v7[59] = result;
qmemcpy(
(void *)((unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)v7 - ((unsigned __int64)(v7 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)v7 - (((_DWORD)v7 + 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
__int64 result; // rax

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

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

v1 = login_c;
LODWORD(result) = login_c - 1;
if ( login_c - 1 < 0 )
{
LABEL_5:
result = login_c;
login_s[2 * login_c] = *(_DWORD *)(a1 + 40);
login_s[2 * v1 + 1] = 1;
login_c = v1 + 1;
}
else
{
result = (int)result;
while ( *(_DWORD *)(a1 + 40) != login_s[2 * result] )
{
if ( (int)--result < 0 )
goto LABEL_5;
}
++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 result; // rax

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

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

v2 = stay_c;
if ( stay_c - 1 < 0 )
{
LABEL_5:
result = 0x48D159E26AF37C05LL * *(_QWORD *)(a1 + 248);
stay_s[2 * stay_c] = *(_QWORD *)(a1 + 248) / 3600LL;
stay_s[2 * v2 + 1] = 1;
stay_c = v2 + 1;
}
else
{
result = stay_c - 1;
while ( *(_QWORD *)(a1 + 248) / 3600LL != stay_s[2 * result] )
{
if ( (int)--result < 0 )
goto LABEL_5;
}
++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
__int64 result; // rax

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

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

v1 = post_c;
LODWORD(result) = post_c - 1;
if ( post_c - 1 < 0 )
{
LABEL_5:
result = post_c;
post_s[2 * post_c] = *(_DWORD *)(a1 + 44);
post_s[2 * v1 + 1] = 1;
post_c = v1 + 1;
}
else
{
result = (int)result;
while ( *(_DWORD *)(a1 + 44) != post_s[2 * result] )
{
if ( (int)--result < 0 )
goto LABEL_5;
}
++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)
{
__int64 v1; // rsi
int v2; // edi
__int64 result; // rax

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

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

v1 = (now - *(_QWORD *)(a1 + 16)) / 86400;
v2 = age_c;
LODWORD(result) = age_c - 1;
if ( age_c - 1 < 0 )
{
LABEL_5:
result = age_c;
age_s[2 * age_c] = v1;
age_s[2 * v2 + 1] = 1;
age_c = v2 + 1;
}
else
{
result = (int)result;
while ( age_s[2 * result] != (_DWORD)v1 )
{
if ( (int)--result < 0 )
goto LABEL_5;
}
++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)
{
int v4; // ebp
__int64 v5; // rbp
char v7[73]; // [rsp+1h] [rbp-49h]
char v8[72]; // [rsp+2h] [rbp-48h] BYREF

if ( a3 )
{
printf("/*------ %s -------*/\n", a1);
if ( !*(_BYTE *)(a2 + 8) )
goto LABEL_6;
}
else if ( !*(_BYTE *)(a2 + 8) )
{
LABEL_3:
printf("const struct sectree %s%s\n", a1, ";");
goto LABEL_12;
}
printf("static ");
if ( !a3 )
goto LABEL_3;
LABEL_6:
printf("const struct sectree %s%s\n", a1, " = {");
if ( *(_QWORD *)a2 )
{
strncpy(v8, a1, 0x14uLL);
v7[strlen(v8)] = 0;
printf("\tparent: &%s,\n", v8);
}
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 )
{
v4 = 0;
do
{
printf("\t\t&%s%c,\n", a1, (unsigned int)(v4 + 65));
++v4;
}
while ( *(_DWORD *)(a2 + 292) > v4 );
}
puts("\t}\n};");
LABEL_12:
if ( *(int *)(a2 + 292) > 0 )
{
v5 = 0LL;
do
{
sprintf(v8, "%s%c", a1, (unsigned int)(v5 + 65));
printtree(v8, *(_QWORD *)(a2 + 8 * v5++ + 72), a3);
}
while ( *(_DWORD *)(a2 + 292) > (int)v5 );
}
return 0LL;
}

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

if ( a3 )
{
printf("/*------ %s -------*/\n", a1);
if ( !*(_BYTE *)(a2 + 8) )
goto LABEL_6;
}
else if ( !*(_BYTE *)(a2 + 8) )
{
LABEL_3:
printf("const struct sectree %s%s\n", a1, ";");
goto LABEL_12;
}
printf("static ");
if ( !a3 )
goto LABEL_3;
LABEL_6:
printf("const struct sectree %s%s\n", a1, " = {");
if ( *(_QWORD *)a2 )
{
strncpy(v8, a1, 0x14uLL);
v7[strlen(v8)] = 0;
printf("\tparent: &%s,\n", v8);
}
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 )
{
v4 = 0;
do
{
printf("\t\t&%s%c,\n", a1, (unsigned int)(v4 + 65));
++v4;
}
while ( *(_DWORD *)(a2 + 292) > v4 );
}
puts("\t}\n};");
LABEL_12:
if ( *(int *)(a2 + 292) > 0 )
{
v5 = 0LL;
do
{
sprintf(v8, "%s%c", a1, (unsigned int)(v5 + 65));
func4(v8, *(_QWORD *)(a2 + 8 * v5++ + 72), 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_4934, (__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_4934, (__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
char **v2; // rbx
int result; // eax

v1 = spcname;
if ( !spcname )
return 1;
v2 = off_4040C8;
while ( 1 )
{
result = strcmp(s1, v1);
if ( !result )
break;
v1 = *v2++;
if ( !v1 )
return 1;
}
return result;
}

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

v1 = spcname;
if ( !spcname )
return 1;
v2 = off_4040C8;
while ( 1 )
{
result = strcmp(s1, v1);
if ( !result )
break;
v1 = *v2++;
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)
{
_QWORD *v1; // rsi
__int64 v2; // rcx
_QWORD *v3; // rdx
__int64 v4; // rax
char *v5; // rdi
__int64 v6; // rax
char *v7; // rdx
__int64 result; // rax

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

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

if ( !a1 )
{
while ( 1 )
{
do
{
sleep(0x258u);
v1 = (_QWORD *)quota;
}
while ( !*(_DWORD *)(quota + 536LL) );
*(_DWORD *)(quota + 536LL) = 0;
v2 = quotaf;
*quotaf = *v1;
*(_QWORD *)(v2 + 536) = v1[67];
qmemcpy(
(void *)((v2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
(char *)v1 - (v2 - ((v2 + 8) & 0xFFFFFFFFFFFFFFF8LL)),
8LL * (((unsigned int)v2 - (((_DWORD)v2 + 8) & 0xFFFFFFF8) + 544) >> 3));
}
}
v3 = (_QWORD *)quota;
*(_DWORD *)(quota + 536LL) = 0;
v4 = quotaf;
*quotaf = *v3;
*(_QWORD *)(v4 + 536) = v3[67];
v5 = (char *)((v4 + 8) & 0xFFFFFFFFFFFFFFF8LL);
v6 = v4 - (_QWORD)v5;
v7 = (char *)v3 - v6;
result = (unsigned int)(v6 + 544) >> 3;
qmemcpy(v5, v7, 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 v3; // [rsp+4h] [rbp-24h] BYREF
struct sembuf sops; // [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 )
{
if ( semctl(flow_semid.s_addr, 0, 16, 0LL) >= 0 )
{
sops.sem_num = 0;
sops.sem_op = 0;
sops.sem_flg = 0;
v3.sem_num = 0;
v3.sem_flg = 0;
while ( 1 )
{
v2 = *(_WORD *)(v1 + 7494968);
if ( v2 <= 0x1F3u )
{
v3.sem_op = 16;
}
else if ( v2 > 0x3E7u )
{
v3.sem_op = v2 < 0x5DCu ? 8 : 4;
}
else
{
v3.sem_op = 12;
}
semop(flow_semid.s_addr, &sops, 1uLL);
semop(flow_semid.s_addr, &v3, 1uLL);
usleep(0x30D40u);
}
}
exit(0);
}
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
int v0; // ebp
__int64 v1; // rbx
unsigned __int16 v2; // ax
struct sembuf v3; // [rsp+4h] [rbp-24h] BYREF
struct sembuf sops; // [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 )
{
if ( semctl(flow_semid.s_addr, 0, 16, 0LL) >= 0 )
{
sops.sem_num = 0;
sops.sem_op = 0;
sops.sem_flg = 0;
v3.sem_num = 0;
v3.sem_flg = 0;
while ( 1 )
{
v2 = *(_WORD *)(v1 + 7494968);
if ( v2 <= 0x1F3u )
{
v3.sem_op = 16;
}
else if ( v2 > 0x3E7u )
{
v3.sem_op = v2 < 0x5DCu ? 8 : 4;
}
else
{
v3.sem_op = 12;
}
semop(flow_semid.s_addr, &sops, 1uLL);
semop(flow_semid.s_addr, &v3, 1uLL);
usleep(0x30D40u);
}
}
exit(0);
}
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 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 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; }

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


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; // er15
const char *v5; // rbp
int v6; // ebx

v4 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
{
v6 = 0;
}
else
{
v5 = *(const char **)(a1 + 8);
v6 = 0;
while ( strncmp(v5, a2, 0x32uLL) )
{
++v6;
v5 += 56;
if ( v6 == v4 )
return 0xFFFFFFFFLL;
}
}
if ( v4 == v6 )
return 0xFFFFFFFFLL;
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 56LL * v6 + 52);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, const char *a2, _DWORD *a3)
{
int v4; // er15
const char *v5; // rbp
int v6; // ebx

v4 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
{
v6 = 0;
}
else
{
v5 = *(const char **)(a1 + 8);
v6 = 0;
while ( strncmp(v5, a2, 0x32uLL) )
{
++v6;
v5 += 56;
if ( v6 == v4 )
return 0xFFFFFFFFLL;
}
}
if ( v4 == v6 )
return 0xFFFFFFFFLL;
*a3 = *(_DWORD *)(*(_QWORD *)(a1 + 8) + 56LL * v6 + 52);
return 0LL;
}

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
unsigned int *v7; // rbx
__int64 result; // rax

v6 = (int *)creatitems(a2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = (unsigned int *)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 func4(const char *a1, int a2, const char *a3, int a4)
{
int *v6; // rax
unsigned int *v7; // rbx
__int64 result; // rax

v6 = (int *)creatitems(a2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = (unsigned int *)v6;
func1(v6, a1);
additem(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; // rbx
__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 func5(const char *a1, int a2, const char *a3, _DWORD *a4)
{
int *v6; // rax
int *v7; // rbx
__int64 result; // rax

v6 = (int *)creatitems(a2);
if ( !v6 )
return 0xFFFFFFFFLL;
v7 = v6;
if ( (int)func1(v6, a1) < 0 || (int)func3((__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; // r13
__int64 v8[2]; // [rsp+0h] [rbp-D8h] BYREF
char v9; // [rsp+10h] [rbp-C8h] BYREF
char v10[72]; // [rsp+90h] [rbp-48h] BYREF

v8[0] = (__int64)v10;
v8[1] = (__int64)&v9;
mystrtok(a4, 32LL, v8, 2LL);
result = finddic(&bsstat, v10);
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 func1(__int64 a1, __int64 a2, const char *a3, __int64 a4)
{
__int64 result; // rax
__int64 v6; // rbp
char *v7; // r13
__int64 v8[2]; // [rsp+0h] [rbp-D8h] BYREF
char v9; // [rsp+10h] [rbp-C8h] BYREF
char v10[72]; // [rsp+90h] [rbp-48h] BYREF

v8[0] = (__int64)v10;
v8[1] = (__int64)&v9;
mystrtok(a4, 32LL, v8, 2LL);
result = finddic(&bsstat, v10);
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()
{
int v0; // eax
__int64 v1; // r13
__int64 v2; // rbx
const char *v3; // r12
char *v4; // rax
char *v5; // rbp
char *v6; // rax
char *v7; // r12
__int64 v8; // r12

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

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

v0 = *(_DWORD *)(brdshm + 460800LL);
if ( v0 > 0 )
{
v1 = 576LL * (unsigned int)v0;
v2 = 0LL;
do
{
v3 = (const char *)(bcache + v2);
if ( *(_BYTE *)(bcache + v2) )
{
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);
v7 = v6;
*((_QWORD *)v5 + 10) = v6;
if ( !v6 )
{
errlog("boardscore.c:%s line %d Can't malloc value in board_init!", "bs_init", 176LL);
exit(-1);
}
strcpy(v6, v5);
snprintf(v7 + 20, 0x50uLL, "[%s] %s", (const char *)(bcache + v2 + 59), (const char *)(bcache + v2 + 24));
v8 = *((_QWORD *)v5 + 10);
*(_DWORD *)(v8 + 10932) = boardnoread(bcache + v2);
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

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

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; // dl
char *v2; // rax
unsigned int v3; // ecx

v1 = *s;
if ( *s )
{
v2 = s + 1;
v3 = 0;
do
{
if ( v3 )
{
v3 = 0;
if ( (unsigned __int8)v1 <= 0x1Fu )
*(v2 - 2) = 32;
}
else
{
v3 = (unsigned int)v1 >> 31;
}
v1 = *v2++;
}
while ( v1 );
if ( v3 )
s[strlen(s) - 1] = 0;
}
return s;
}

canonical_decompiled_code:
char *__fastcall func2(char *s)
{
char v1; // dl
char *v2; // rax
unsigned int v3; // ecx

v1 = *s;
if ( *s )
{
v2 = s + 1;
v3 = 0;
do
{
if ( v3 )
{
v3 = 0;
if ( (unsigned __int8)v1 <= 0x1Fu )
*(v2 - 2) = 32;
}
else
{
v3 = (unsigned int)v1 >> 31;
}
v1 = *v2++;
}
while ( v1 );
if ( v3 )
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; // rbx
char *v2; // rax
int *v3; // rax
char v5[256]; // [rsp+0h] [rbp-208h] BYREF
char s[264]; // [rsp+100h] [rbp-108h] BYREF

strsncpy(v5, a1, 255LL);
buf_0[0] = 0;
v1 = strtok(v5, " ,();\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(s, "%s", (const char *)v3, (const char *)v3);
strcat(buf_0, s);
}
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; // rbx
char *v2; // rax
int *v3; // rax
char v5[256]; // [rsp+0h] [rbp-208h] BYREF
char s[264]; // [rsp+100h] [rbp-108h] BYREF

strsncpy(v5, a1, 255LL);
buf_0[0] = 0;
v1 = strtok(v5, " ,();\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(s, "%s", (const char *)v3, (const char *)v3);
strcat(buf_0, s);
}
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 v2; // er12
const char *v3; // rbx
int v4; // ebp

v2 = *(_DWORD *)(a1 + 100);
if ( v2 <= 0 )
{
v2 = 0;
LABEL_6:
strsncpy(a1 + 16LL * v2 + 104, a2, 16LL);
v2 = *(_DWORD *)(a1 + 100) + 1;
*(_DWORD *)(a1 + 100) = v2;
}
else
{
v3 = (const char *)(a1 + 104);
v4 = 0;
while ( strncmp(v3, a2, 0x10uLL) )
{
++v4;
v3 += 16;
if ( v4 == v2 )
{
if ( v2 <= 4 )
goto LABEL_6;
return (unsigned int)-1;
}
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
int v2; // er12
const char *v3; // rbx
int v4; // ebp

v2 = *(_DWORD *)(a1 + 100);
if ( v2 <= 0 )
{
v2 = 0;
LABEL_6:
strsncpy(a1 + 16LL * v2 + 104, a2, 16LL);
v2 = *(_DWORD *)(a1 + 100) + 1;
*(_DWORD *)(a1 + 100) = v2;
}
else
{
v3 = (const char *)(a1 + 104);
v4 = 0;
while ( strncmp(v3, a2, 0x10uLL) )
{
++v4;
v3 += 16;
if ( v4 == v2 )
{
if ( v2 <= 4 )
goto LABEL_6;
return (unsigned int)-1;
}
}
}
return (unsigned int)v2;
}

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 *


addmarkedlist

decompiled_code:
__int64 __fastcall addmarkedlist(int *a1, const char *a2, const char *a3, unsigned int a4)
{
int v4; // er12
const char *v5; // rbx
int v6; // ebp

v4 = *a1;
if ( *a1 <= 0 )
{
v4 = 0;
}
else
{
v5 = (const char *)(a1 + 1);
v6 = 0;
do
{
if ( !strncmp(v5, a2, 0x64uLL) )
{
addmiauthor((__int64)v5, a3);
return (unsigned int)*a1;
}
++v6;
v5 += 192;
}
while ( v4 != v6 );
if ( v4 > 8 )
return (unsigned int)v4;
}
strsncpy(&a1[48 * v4 + 1], a2, 100LL);
addmiauthor((__int64)&a1[48 * v4 + 1], a3);
a1[48 * v4 + 48] = a4;
v4 = *a1 + 1;
*a1 = v4;
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, const char *a2, const char *a3, unsigned int a4)
{
int v4; // er12
const char *v5; // rbx
int v6; // ebp

v4 = *a1;
if ( *a1 <= 0 )
{
v4 = 0;
}
else
{
v5 = (const char *)(a1 + 1);
v6 = 0;
do
{
if ( !strncmp(v5, a2, 0x64uLL) )
{
func4((__int64)v5, a3);
return (unsigned int)*a1;
}
++v6;
v5 += 192;
}
while ( v4 != v6 );
if ( v4 > 8 )
return (unsigned int)v4;
}
strsncpy(&a1[48 * v4 + 1], a2, 100LL);
func4((__int64)&a1[48 * v4 + 1], a3);
a1[48 * v4 + 48] = a4;
v4 = *a1 + 1;
*a1 = v4;
return (unsigned int)v4;
}

original_code:
int
addmarkedlist(struct markedlist *ml, char *title, char *author, int thread)
{
 int i;
 for (i = 0; i < ml->n; i++) {
  if (!strncmp(ml->mi[i].title, title, ((int)sizeof(ml->mi[i].title)))) {
   addmiauthor(&ml->mi[i], author);
   return ml->n;
  }
 }
 if (i >= 9)
  return ml->n;
 strsncpy(ml->mi[i].title, title, ((int)sizeof(ml->mi[0].title)));
 addmiauthor(&ml->mi[i], author);
 ml->mi[i].thread = thread;
 ml->n++;
 return ml->n;
}

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

variable_types:
title
char *

variable_types: thread int

user_defined_types: struct markedlist { int n; struct markeditem mi[9]; }


isspcname

decompiled_code:
__int64 __fastcall isspcname(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx

v1 = spcname;
if ( !spcname )
return 0LL;
v2 = (unsigned int)((_DWORD)&spcname + 8);
while ( strcmp(s1, v1) )
{
v2 += 8LL;
v1 = *(const char **)(v2 - 8);
if ( !v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
const char *v1; // rsi
__int64 v2; // rbx

v1 = spcname;
if ( !spcname )
return 0LL;
v2 = (unsigned int)((_DWORD)&spcname + 8);
while ( strcmp(s1, v1) )
{
v2 += 8LL;
v1 = *(const char **)(v2 - 8);
if ( !v1 )
return 0LL;
}
return 1LL;
}

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

variable_types:
file
char *


testPOWERJUNK

original_code:
int
testPOWERJUNK(char *path, char *fn)
{
 char buf[1024];
 int s;
 sprintf(buf, "%s/%s", path, fn);
 if (strncmp(fn, ".POWER", 6) && strncmp(buf, ".SOMEONE", 8)
     && strncmp(buf, ".UNREAD", 7))
  return 0;
 if (nowtime - (f_stat(buf)->st_mtim.tv_sec) < 3600 * 5)
  return 0;
 s = (f_stat(buf)->st_size);
 unlink(buf);
 printf("%s %d\n", buf, s);
 totalsize += s;
 return 0;
}

variable_types:
path
char *

variable_types:
fn
char *

variable_types:
buf
char [1024]

variable_types: s int


useindexfile

decompiled_code:
__int64 __fastcall useindexfile(__int64 a1)
{
return new_apply_record(a1, 128LL, countfile, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return new_apply_record(a1, 128LL, countfile, 0LL);
}

original_code:
int
useindexfile(char *filename)
{
 return new_apply_record(filename, ((int)sizeof(struct fileheader)), countfile,
    ((void *)0));
}

variable_types:
filename
char *

user_defined_types: struct fileheader { int filetime; int edittime; int thread; unsigned int accessed; char title[60]; char owner[14]; unsigned short viewtime; unsigned char sizebyte; unsigned char staravg50; unsigned char hasvoted; char deltime; char unused[32]; }


decompiled_code:
__int64 __fastcall rm_lost(const char *a1)
{
void *v1; // r13
unsigned int v2; // er15
unsigned int v3; // er12
__int64 v4; // rbx
char *v5; // rbp
int v6; // eax
int *v8; // [rsp+10h] [rbp-1048h]
unsigned int v9; // [rsp+1Ch] [rbp-103Ch]
char s[4152]; // [rsp+20h] [rbp-1038h] BYREF

v8 = nfile;
v1 = 0LL;
v2 = 0;
v3 = 0;
v9 = 0;
do
{
v9 += *v8;
if ( *v8 > 0 )
{
v5 = &allpost[5 * (_QWORD)v1];
v4 = 0LL;
do
{
v6 = *(int *)((char *)refcount + (_QWORD)v1 + 4 * v4);
v3 += v6;
if ( !v6 )
{
++v2;
if ( (int)nowtime - atoi(v5 + 2) > 49999 )
{
sprintf(s, "%s/%s", a1, v5);
unlink(s);
}
}
++v4;
v5 += 20;
}
while ( *v8 > (int)v4 );
}
++v8;
v1 = (char *)v1 + 2000000;
}
while ( v1 != &unk_4C4B400 );
allfile += v9;
allref += v3;
alllost += v2;
printf(" total %d, refcount %d, %d file(s) was lost\n", v9, v3, v2);
if ( otherfile[0] )
puts(otherfile);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
void *v1; // r13
unsigned int v2; // er15
unsigned int v3; // er12
__int64 v4; // rbx
char *v5; // rbp
int v6; // eax
int *v8; // [rsp+10h] [rbp-1048h]
unsigned int v9; // [rsp+1Ch] [rbp-103Ch]
char s[4152]; // [rsp+20h] [rbp-1038h] BYREF

v8 = nfile;
v1 = 0LL;
v2 = 0;
v3 = 0;
v9 = 0;
do
{
v9 += *v8;
if ( *v8 > 0 )
{
v5 = &allpost[5 * (_QWORD)v1];
v4 = 0LL;
do
{
v6 = *(int *)((char *)refcount + (_QWORD)v1 + 4 * v4);
v3 += v6;
if ( !v6 )
{
++v2;
if ( (int)nowtime - atoi(v5 + 2) > 49999 )
{
sprintf(s, "%s/%s", a1, v5);
unlink(s);
}
}
++v4;
v5 += 20;
}
while ( *v8 > (int)v4 );
}
++v8;
v1 = (char *)v1 + 2000000;
}
while ( v1 != &unk_4C4B400 );
allfile += v9;
allref += v3;
alllost += v2;
printf(" total %d, refcount %d, %d file(s) was lost\n", v9, v3, v2);
if ( otherfile[0] )
puts(otherfile);
return 0LL;
}

original_code:
int
rm_lost(char *path)
{
 int i, h, total, totalref, lost, t;
 char buf[4096];
 for (h = 0, total = 0, totalref = 0, lost = 0; h < 40; h++) {
  total += nfile[h];
  for (i = 0; i < nfile[h]; i++) {
   totalref += refcount[h][i];
   if (!refcount[h][i]) {
    lost++;
    t = atoi(allpost[h][i] + 2);
    if (nowtime - t < 50000) {
     continue;
    }
    sprintf(buf, "%s/%s", path, allpost[h][i]);
    unlink(buf);
   }
  }
 }
 allfile += total;
 allref += totalref;
 alllost += lost;
 printf(" total %d, refcount %d, %d file(s) was lost\n", total, totalref,
        lost);
 if (strlen(otherfile) > 0)
  printf("%s\n", otherfile);
 return 0;
}

canonical_original_code:
int rm_lost(char *path)
{
 int i; int h; int total; int totalref; int lost; int t;
 char buf[4096];
 for (h = 0, total = 0, totalref = 0, lost = 0; h < 40; h++) {
  total += nfile[h];
  for (i = 0; i < nfile[h]; i++) {
   totalref += refcount[h][i];
   if (!refcount[h][i]) {
    lost++;
    t = atoi(allpost[h][i] + 2);
    if (nowtime - t < 50000) {
     continue;
    }
    sprintf(buf, "%s/%s", path, allpost[h][i]);
    unlink(buf);
   }
  }
 }
 allfile += total;
 allref += totalref;
 alllost += lost;
 printf(" total %d, refcount %d, %d file(s) was lost\n", total, totalref,
        lost);
 if (strlen(otherfile) > 0)
  printf("%s\n", otherfile);
 return 0;
}

variable_types: i int

variable_types: h int

variable_types: total int

variable_types: totalref int

variable_types: lost int

variable_types: t int

variable_types:
buf
char [4096]


decompiled_code:
__int64 __fastcall find_rm_lost(const char *a1)
{
int *v1; // rax
char v3[216]; // [rsp+0h] [rbp-D8h] BYREF

v1 = nfile;
do
*v1++ = 0;
while ( v1 != (int *)(unsigned int)((_DWORD)nfile + 160) );
otherfile[0] = 0;
sprintf(v3, "/home/bbs/boards/%s", a1);
if ( (int)getallpost(v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s/.DIR", a1);
if ( dashf(v3) && (int)useindexfile((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s/.DIGEST", a1);
if ( dashf(v3) && (int)useindexfile((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s/.DELETED", a1);
if ( dashf(v3) && (int)useindexfile((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s/.JUNK", a1);
if ( dashf(v3) && (int)useindexfile((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s", a1);
rm_lost(v3);
return 0LL;
}

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

v1 = nfile;
do
*v1++ = 0;
while ( v1 != (int *)(unsigned int)((_DWORD)nfile + 160) );
otherfile[0] = 0;
sprintf(v3, "/home/bbs/boards/%s", a1);
if ( (int)func5(v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s/.DIR", a1);
if ( func8(v3) && (int)func6((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s/.DIGEST", a1);
if ( func8(v3) && (int)func6((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s/.DELETED", a1);
if ( func8(v3) && (int)func6((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s/.JUNK", a1);
if ( func8(v3) && (int)func6((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "/home/bbs/boards/%s", a1);
func7(v3);
return 0LL;
}

original_code:
int
find_rm_lost(struct boardheader *bhp)
{
 char buf[200];
 int i;
 for (i = 0; i < 40; i++) {
  nfile[i] = 0;
 }
 otherfile[0] = 0;
 sprintf(buf, "/home/bbs" "/boards/%s", bhp->filename);
 if (getallpost(buf) < 0)
  return -1;
 sprintf(buf, "/home/bbs" "/boards/%s/.DIR", bhp->filename);
 if (dashf(buf))
  if (useindexfile(buf) < 0)
   return -1;
 sprintf(buf, "/home/bbs" "/boards/%s/.DIGEST", bhp->filename);
 if (dashf(buf))
  if (useindexfile(buf) < 0)
   return -1;
 sprintf(buf, "/home/bbs" "/boards/%s/.DELETED", bhp->filename);
 if (dashf(buf))
  if (useindexfile(buf) < 0)
   return -1;
 sprintf(buf, "/home/bbs" "/boards/%s/.JUNK", bhp->filename);
 if (dashf(buf))
  if (useindexfile(buf) < 0)
   return -1;
 sprintf(buf, "/home/bbs" "/boards/%s", bhp->filename);
 rm_lost(buf);
 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]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // eax
int v5; // ebx
char *v6; // rax
char *v7; // rax
char v9[520]; // [rsp+0h] [rbp-208h] BYREF

chdir("/home/bbs");
LODWORD(nowtime) = time(0LL);
puts("find_rm_lost is running~");
v3 = ctime(&nowtime);
printf("\x1B[1mbbs home=%s now time = %s\x1B[0m\n", "/home/bbs", v3);
v4 = open("/home/bbs/.BOARDS", 0);
v5 = v4;
if ( v4 != -1 )
{
flock(v4, 2);
while ( read(v5, v9, 0x200uLL) == 512 )
{
if ( v9[0] )
{
printf("processing %s\n", v9);
fflush(stdout);
if ( (int)find_rm_lost(v9) < 0 )
{
time(&nowtime);
v6 = ctime(&nowtime);
printf(" FAILED! %s", v6);
}
else
{
time(&nowtime);
v7 = ctime(&nowtime);
printf(" ....OK. %s", v7);
}
}
}
printf("allfile %d, allref %d, alllost %d\n", (unsigned int)allfile, (unsigned int)allref, (unsigned int)alllost);
printf(
"unknownfn %d, nindexitem %d, nstrangeitem %d\n",
(unsigned int)unknownfn,
(unsigned int)nindexitem,
(unsigned int)nstrangeitem);
flock(v5, 8);
close(v5);
printf("totalsize = %d", (unsigned int)totalsize);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // eax
int v5; // ebx
char *v6; // rax
char *v7; // rax
char v9[520]; // [rsp+0h] [rbp-208h] BYREF

chdir("/home/bbs");
LODWORD(nowtime) = time(0LL);
puts("find_rm_lost is running~");
v3 = ctime(&nowtime);
printf("\x1B[1mbbs home=%s now time = %s\x1B[0m\n", "/home/bbs", v3);
v4 = open("/home/bbs/.BOARDS", 0);
v5 = v4;
if ( v4 != -1 )
{
flock(v4, 2);
while ( read(v5, v9, 0x200uLL) == 512 )
{
if ( v9[0] )
{
printf("processing %s\n", v9);
fflush(stdout);
if ( (int)func9(v9) < 0 )
{
time(&nowtime);
v6 = ctime(&nowtime);
printf(" FAILED! %s", v6);
}
else
{
time(&nowtime);
v7 = ctime(&nowtime);
printf(" ....OK. %s", v7);
}
}
}
printf("allfile %d, allref %d, alllost %d\n", (unsigned int)allfile, (unsigned int)allref, (unsigned int)alllost);
printf(
"unknownfn %d, nindexitem %d, nstrangeitem %d\n",
(unsigned int)unknownfn,
(unsigned int)nindexitem,
(unsigned int)nstrangeitem);
flock(v5, 8);
close(v5);
printf("totalsize = %d", (unsigned int)totalsize);
v5 = 0;
}
return v5;
}

original_code:
int
main()
{
 int b_fd;
 struct boardheader bh;
 int size;
 size = ((int)sizeof(bh));
 chdir("/home/bbs");
 nowtime = time(((void *)0));
 printf("find_rm_lost is running~\n");
 printf("\033[1mbbs home=%s now time = %s\033[0m\n", "/home/bbs",
        ctime(&nowtime));
 if ((b_fd = open("/home/bbs" "/.BOARDS", 00)) == -1)
  return -1;
 flock(b_fd, 2);
 while (read(b_fd, &bh, size) == size) {
  if (!bh.filename[0])
   continue;
  printf("processing %s\n", bh.filename);
  fflush(stdout);
  if (find_rm_lost(&bh) < 0) {
   time(&nowtime);
   printf(" FAILED! %s", ctime(&nowtime));
  } else {
   time(&nowtime);
   printf(" ....OK. %s", ctime(&nowtime));
  }
 }
 printf("allfile %d, allref %d, alllost %d\n", allfile, allref, alllost);
 printf("unknownfn %d, nindexitem %d, nstrangeitem %d\n", unknownfn,
        nindexitem, nstrangeitem);
 flock(b_fd, 8);
 close(b_fd);
 printf("totalsize = %d", totalsize);
 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: size int


setuserfile

decompiled_code:
char *__fastcall setuserfile(char *s, const char *a2, const char *a3)
{
char v4; // al

v4 = mytoupper(*(unsigned __int8 *)a2);
sprintf(s, "/home/bbs/home/%c/%s/%s", (unsigned int)v4, a2, a3);
return s;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, const char *a2, const char *a3)
{
char v4; // al

v4 = mytoupper(*(unsigned __int8 *)a2);
sprintf(s, "/home/bbs/home/%c/%s/%s", (unsigned int)v4, a2, a3);
return s;
}

original_code:
char* setuserfile(char *buf, const char *userid, const char *filename)
{
 sprintf(buf, "/home/bbs" "/home/%c/%s/%s", mytoupper(userid[0]), userid,
  filename);
 return buf;
}

canonical_original_code:
char *setuserfile(char *buf, char *userid, char *filename)
{
 sprintf(buf, "/home/bbs" "/home/%c/%s/%s", mytoupper(userid[0]), userid,
  filename);
 return buf;
}

variable_types:
buf
char *

variable_types:
userid
char *


main

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

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

original_code:
int main()
{
 setdefaultkey();
 return 0;
}


cmpboardt

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

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

original_code:
int cmpboardt(struct boardheader *a,struct boardheader *b) {
 return (b->board_ctime - a->board_ctime);
}

canonical_original_code:
int cmpboardt(struct boardheader *a, struct boardheader *b) {
 return (b->board_ctime - a->board_ctime);
}

variable_types:
b
struct boardheader *

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


boardcount

decompiled_code:
__int64 __fastcall boardcount(char *src)
{
int v1; // er13
const char *v2; // rbp
int v3; // ebx
__int64 result; // rax

v1 = nboard_0;
if ( nboard_0 <= 0 )
{
LABEL_5:
result = 0LL;
if ( v1 <= 799 )
{
strncpy(&bname_2[20 * v1], src, 0x13uLL);
byte_404E13[20 * v1] = 0;
count_1[v1] = 1;
nboard_0 = v1 + 1;
result = 0LL;
}
}
else
{
v2 = bname_2;
v3 = 0;
while ( strcmp(v2, src) )
{
++v3;
v2 += 20;
if ( v3 == v1 )
goto LABEL_5;
}
result = (unsigned int)count_1[v3];
count_1[v3] = result + 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *src)
{
int v1; // er13
const char *v2; // rbp
int v3; // ebx
__int64 result; // rax

v1 = nboard_0;
if ( nboard_0 <= 0 )
{
LABEL_5:
result = 0LL;
if ( v1 <= 799 )
{
strncpy(&bname_2[20 * v1], src, 0x13uLL);
byte_404E13[20 * v1] = 0;
count_1[v1] = 1;
nboard_0 = v1 + 1;
result = 0LL;
}
}
else
{
v2 = bname_2;
v3 = 0;
while ( strcmp(v2, src) )
{
++v3;
v2 += 20;
if ( v3 == v1 )
goto LABEL_5;
}
result = (unsigned int)count_1[v3];
count_1[v3] = result + 1;
}
return result;
}

original_code:
int
boardcount(char *bn)
{
 static char bname[800][20];
 static int count[800];
 static int nboard = 0;
 int i;
 for (i = 0; i < nboard; i++) {
  if (!strcmp(bname[i], bn)) {
   return count[i]++;
  }
 }
 if (nboard >= 800)
  return 0;
 strncpy(bname[nboard], bn, 19);
 bname[nboard][19] = 0;
 count[nboard] = 1;
 nboard++;
 return 0;
}

variable_types:
bn
char *

variable_types:
bname
char [800][20]

variable_types:
count
int [800]

variable_types: nboard int


getlogtime

decompiled_code:
__int64 __fastcall getlogtime(const char *a1)
{
int v2; // [rsp+8h] [rbp-10h]
int v3; // [rsp+Ch] [rbp-Ch]

if ( !strstr(a1, "2002:") )
return 0xFFFFFFFFLL;
if ( (unsigned int)__isoc99_sscanf() == 2 )
return (unsigned int)(v3 + 60 * v2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
int v2; // [rsp+8h] [rbp-10h]
int v3; // [rsp+Ch] [rbp-Ch]

if ( !strstr(a1, "2002:") )
return 0xFFFFFFFFLL;
if ( (unsigned int)__isoc99_sscanf() == 2 )
return (unsigned int)(v3 + 60 * v2);
return 0xFFFFFFFFLL;
}

original_code:
int
getlogtime(char *line)
{
 int s, m;
 char *ptr;
 ptr = strstr(line, "2002:");
 if (!ptr)
  return -1;
 ptr += 8;
 if (sscanf(ptr, "%d:%d", &m, &s) != 2)
  return -1;
 return m * 60 + s;
}

canonical_original_code:
int getlogtime(char *line)
{
 int s; int m;
 char *ptr;
 ptr = strstr(line, "2002:");
 if (!ptr)
  return -1;
 ptr += 8;
 if (sscanf(ptr, "%d:%d", &m, &s) != 2)
  return -1;
 return m * 60 + s;
}

variable_types:
line
char *

variable_types: s int

variable_types: m int

variable_types:
ptr
char *


pos

decompiled_code:
__int64 __fastcall pos(const char *a1, const char *a2)
{
char *v2; // rax
__int64 result; // rax

v2 = strstr(a1, a2);
if ( v2 )
result = (unsigned int)((_DWORD)v2 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
char *v2; // rax
__int64 result; // rax

v2 = strstr(a1, a2);
if ( v2 )
result = (unsigned int)((_DWORD)v2 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int
pos(char *haystack, char *needle)
{
 if (strstr(haystack, needle)) {
  return (int) strstr(haystack, needle) - (int) haystack;
 } else {
  return -1;
 }
}

variable_types:
haystack
char *

variable_types:
needle
char *


cutto

decompiled_code:
void *__fastcall cutto(void *dest, int a2)
{
size_t v2; // rax

v2 = strlen((const char *)dest);
return memmove(dest, (char *)dest + a2, v2 - a2 + 1);
}

canonical_decompiled_code:
void *__fastcall func1(void *dest, int a2)
{
size_t v2; // rax

v2 = strlen((const char *)dest);
return memmove(dest, (char *)dest + a2, v2 - a2 + 1);
}

original_code:
void
cutto(char *str, int len)
{
 memmove(str, str + len, strlen(str) - len + 1);
}

variable_types:
str
char *

variable_types: len int


mystrncpy

decompiled_code:
char *__fastcall mystrncpy(char *a1, const char *a2, int a3)
{
__int64 v3; // rbx
char *result; // rax

v3 = a3;
result = strncpy(a1, a2, a3);
a1[v3] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *a1, const char *a2, int a3)
{
__int64 v3; // rbx
char *result; // rax

v3 = a3;
result = strncpy(a1, a2, a3);
a1[v3] = 0;
return result;
}

original_code:
void
mystrncpy(char *dest, char *src, int len)
{
 strncpy(dest, src, len);
 *(dest + len) = 0;
}

variable_types:
dest
char *

variable_types:
src
char *


replace

decompiled_code:
__int64 __fastcall replace(char *haystack, char *s, void *src)
{
unsigned int i; // er15
const char *v6; // r12
size_t v7; // rax
size_t v8; // rax
char *v9; // rbx

for ( i = 0; ; ++i )
{
v9 = strstr(haystack, s);
if ( !v9 )
break;
haystack = &v9[strlen((const char *)src)];
v6 = &v9[strlen(s)];
v7 = strlen(v6);
memmove(haystack, v6, v7 + 1);
v8 = strlen((const char *)src);
memcpy(v9, src, v8);
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *haystack, char *s, void *src)
{
unsigned int i; // er15
const char *v6; // r12
size_t v7; // rax
size_t v8; // rax
char *v9; // rbx

for ( i = 0; ; ++i )
{
v9 = strstr(haystack, s);
if ( !v9 )
break;
haystack = &v9[strlen((const char *)src)];
v6 = &v9[strlen(s)];
v7 = strlen(v6);
memmove(haystack, v6, v7 + 1);
v8 = strlen((const char *)src);
memcpy(v9, src, v8);
}
return i;
}

original_code:
int
replace(char *str, char *what, char *by)
{
 char *foo, *bar = str;
 int i = 0;
 while ((foo = strstr(bar, what))) {
  bar = foo + strlen(by);
  memmove(bar,
   foo + strlen(what), strlen(foo + strlen(what)) + 1);
  memcpy(foo, by, strlen(by));
  i++;
 }
 return i;
}

canonical_original_code:
int replace(char *str, char *what, char *by)
{
 char *foo; char *bar = str;
 int i = 0;
 while ((foo = strstr(bar, what))) {
  bar = foo + strlen(by);
  memmove(bar,
   foo + strlen(what), strlen(foo + strlen(what)) + 1);
  memcpy(foo, by, strlen(by));
  i++;
 }
 return i;
}

variable_types:
what
char *

variable_types:
by
char *

variable_types:
foo
char *

variable_types:
bar
char *

variable_types: i int


decompiled_code:
int __fastcall int_from_list(char *src, int a2)
{
size_t v2; // rax
void *v3; // rax
void *v4; // rbx
size_t v5; // rax
size_t v6; // rax
char *v7; // rbx
int v8; // er12
char *v9; // rax
const char *v10; // r13
int v11; // ebx
int v12; // eax

v2 = strlen(src);
v3 = malloc(v2 + 2);
if ( !v3 )
return -1;
v4 = v3;
v5 = strlen(src);
memset(v4, 0, v5 + 2);
v6 = strlen(src);
strncpy((char *)v4, src, v6);
*((_BYTE *)v4 + strlen(src)) = 44;
v7 = strtok((char *)v4, ",");
if ( !v7 )
return -1;
v8 = -1;
while ( 1 )
{
if ( !*v7 )
return -1;
v9 = strchr(v7, 45);
if ( !v9 )
{
if ( ++v8 == a2 )
return atoi(v7);
goto LABEL_5;
}
*v9 = 0;
v10 = v9 + 1;
if ( !*v7 )
return -1;
if ( !v9[1] )
return -1;
v11 = atoi(v7);
v12 = atoi(v10);
if ( v12 <= 0 || v11 <= 0 || v11 > v12 )
return -1;
v8 += v12 - v11 + 1;
if ( a2 <= v8 )
return v12 - (v8 - a2);
LABEL_5:
v7 = strtok(0LL, ",");
if ( !v7 )
return -1;
}
}

canonical_decompiled_code:
int __fastcall func4(char *src, int a2)
{
size_t v2; // rax
void *v3; // rax
void *v4; // rbx
size_t v5; // rax
size_t v6; // rax
char *v7; // rbx
int v8; // er12
char *v9; // rax
const char *v10; // r13
int v11; // ebx
int v12; // eax

v2 = strlen(src);
v3 = malloc(v2 + 2);
if ( !v3 )
return -1;
v4 = v3;
v5 = strlen(src);
memset(v4, 0, v5 + 2);
v6 = strlen(src);
strncpy((char *)v4, src, v6);
*((_BYTE *)v4 + strlen(src)) = 44;
v7 = strtok((char *)v4, ",");
if ( !v7 )
return -1;
v8 = -1;
while ( 1 )
{
if ( !*v7 )
return -1;
v9 = strchr(v7, 45);
if ( !v9 )
{
if ( ++v8 == a2 )
return atoi(v7);
goto LABEL_5;
}
*v9 = 0;
v10 = v9 + 1;
if ( !*v7 )
return -1;
if ( !v9[1] )
return -1;
v11 = atoi(v7);
v12 = atoi(v10);
if ( v12 <= 0 || v11 <= 0 || v11 > v12 )
return -1;
v8 += v12 - v11 + 1;
if ( a2 <= v8 )
return v12 - (v8 - a2);
LABEL_5:
v7 = strtok(0LL, ",");
if ( !v7 )
return -1;
}
}

original_code:
int
int_from_list(char *list, int n)
{
 char *str, *tok;
 int count = -1, firstrun = 1;
 str = (char *) malloc(sizeof (char) * strlen(list) + 2);
 if (!str)
  return -1;
 memset(str, 0, strlen(list) + 2);
 strncpy(str, list, strlen(list));
 *(str + strlen(list)) = ',';
 for (;;) {
  if (firstrun)
   tok = strtok(str, ",");
  else
   tok = strtok(((void *)0), ",");
  if (!tok || *tok == '\0')
   return -1;
  if (strchr(tok, '-')) {
   char *start, *end;
   int s, e;
   start = tok;
   end = strchr(tok, '-');
   *end = '\0';
   end++;
   if (!*start || !*end)
    return -1;
   s = atoi(start);
   e = atoi(end);
   if (s < 1 || e < 1 || e < s)
    return -1;
   count += e - s + 1;
   if (count >= n)
    return (e - (count - n));
  } else {
   count++;
   if (count == n)
    return (atoi(tok));
  }
  firstrun = 0;
 }
}

canonical_original_code:
int int_from_list(char *list, int n)
{
 char *str; char *tok;
 int count = -1; int firstrun = 1;
 str = (char *) malloc(sizeof (char) * strlen(list) + 2);
 if (!str)
  return -1;
 memset(str, 0, strlen(list) + 2);
 strncpy(str, list, strlen(list));
 *(str + strlen(list)) = ',';
 for (;;) {
  if (firstrun)
   tok = strtok(str, ",");
  else
   tok = strtok(((void *)0), ",");
  if (!tok || *tok == '\0')
   return -1;
  if (strchr(tok, '-')) {
   char *start; char *end;
   int s; int e;
   start = tok;
   end = strchr(tok, '-');
   *end = '\0';
   end++;
   if (!*start || !*end)
    return -1;
   s = atoi(start);
   e = atoi(end);
   if (s < 1 || e < 1 || e < s)
    return -1;
   count += e - s + 1;
   if (count >= n)
    return (e - (count - n));
  } else {
   count++;
   if (count == n)
    return (atoi(tok));
  }
  firstrun = 0;
 }
}

variable_types:
list
char *

variable_types: n int

variable_types:
tok
char *

variable_types: count int

variable_types: firstrun int

variable_types:
start
char *

variable_types:
end
char *

variable_types: e int