addmarkedlist

decompiled_code:
__int64 __fastcall addmarkedlist(int *a1, const char *a2, const char *a3, int a4)
{
__int64 v5; // r12
const char *v6; // rbp
int v7; // ebx
__int64 v9; // rbp
__int64 v10; // rbp

v5 = *a1;
if ( (int)v5 <= 0 )
{
v9 = 4LL;
v5 = 0LL;
goto LABEL_9;
}
v6 = (const char *)(a1 + 1);
v7 = 0;
do
{
if ( !strncmp(v6, a2, 0x64uLL) )
{
addmiauthor((__int64)v6, a3);
LODWORD(v5) = *a1;
return (unsigned int)v5;
}
++v7;
v6 += 192;
}
while ( (_DWORD)v5 != v7 );
if ( (int)v5 <= 8 )
{
v9 = 192 * v5 + 4;
LABEL_9:
v10 = (__int64)a1 + v9;
strsncpy(v10, a2, 100LL);
addmiauthor(v10, a3);
a1[48 * v5 + 48] = a4;
LODWORD(v5) = *a1 + 1;
*a1 = v5;
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1, const char *a2, const char *a3, int a4)
{
__int64 v5; // r12
const char *v6; // rbp
int v7; // ebx
__int64 v9; // rbp
__int64 v10; // rbp

v5 = *a1;
if ( (int)v5 <= 0 )
{
v9 = 4LL;
v5 = 0LL;
goto LABEL_9;
}
v6 = (const char *)(a1 + 1);
v7 = 0;
do
{
if ( !strncmp(v6, a2, 0x64uLL) )
{
func4((__int64)v6, a3);
LODWORD(v5) = *a1;
return (unsigned int)v5;
}
++v7;
v6 += 192;
}
while ( (_DWORD)v5 != v7 );
if ( (int)v5 <= 8 )
{
v9 = 192 * v5 + 4;
LABEL_9:
v10 = (__int64)a1 + v9;
strsncpy(v10, a2, 100LL);
func4(v10, a3);
a1[48 * v5 + 48] = a4;
LODWORD(v5) = *a1 + 1;
*a1 = v5;
}
return (unsigned int)v5;
}

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

repo: deepurple/bbssrc

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

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

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

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

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 *

variable_types: i int

return_type: int


testPOWERJUNK

decompiled_code:
__int64 __fastcall testPOWERJUNK(const char *a1, const char *a2)
{
bool v2; // cf
bool v3; // zf
const char *v4; // rdi
__int64 v5; // rcx
__int64 v7; // rbp
__int64 v8; // rbp
__int64 v9[129]; // [rsp+0h] [rbp-408h] BYREF

sprintf((char *)v9, "%s/%s", a1, a2);
v4 = ".POWER";
v5 = 6LL;
do
{
if ( !v5 )
break;
v2 = *a2 < (unsigned int)*v4;
v3 = *a2++ == *v4++;
--v5;
}
while ( v3 );
if ( (!v2 && !v3) != v2
&& v9[0] != 0x454E4F454D4F532ELL
&& (LODWORD(v9[0]) != 1380865326 || WORD2(v9[0]) != 16709 || BYTE6(v9[0]) != 68) )
{
return 0LL;
}
v7 = (int)nowtime;
if ( v7 - *(_QWORD *)(f_stat(v9, a2) + 88) <= 17999 )
return 0LL;
v8 = *(_QWORD *)(f_stat(v9, a2) + 48);
unlink((const char *)v9);
printf("%s %d\n", (const char *)v9, (unsigned int)v8);
totalsize += v8;
return 0LL;
}

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)
{
unsigned int v1; // er14
void *v2; // r13
unsigned int v3; // er12
int *v4; // rbp
char *v5; // r15
__int64 v6; // rbx
int v7; // eax
unsigned int v9; // [rsp+Ch] [rbp-103Ch]
char s[4152]; // [rsp+10h] [rbp-1038h] BYREF

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

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

v1 = 0;
v2 = 0LL;
v3 = 0;
v4 = nfile;
v9 = 0;
do
{
v9 += *v4;
if ( *v4 > 0 )
{
v5 = &allpost[5 * (_QWORD)v2];
v6 = 0LL;
do
{
v7 = *(int *)((char *)refcount + (_QWORD)v2 + 4 * v6);
v1 += v7;
if ( !v7 )
{
++v3;
if ( (int)nowtime - atoi(v5 + 2) > 49999 )
{
sprintf(s, "%s/%s", a1, v5);
unlink(s);
}
}
++v6;
v5 += 20;
}
while ( *v4 > (int)v6 );
}
v2 = (char *)v2 + 2000000;
++v4;
}
while ( v2 != &unk_4C4B400 );
allfile += v9;
allref += v1;
alllost += v3;
printf(" total %d, refcount %d, %d file(s) was lost\n", v9, v1, v3);
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: 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)
{
char v2[216]; // [rsp+0h] [rbp-D8h] BYREF

otherfile[0] = 0;
memset(nfile, 0, sizeof(nfile));
sprintf(v2, "/home/bbs/boards/%s", a1);
if ( (int)getallpost(v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.DIR", a1);
if ( dashf(v2) && (int)useindexfile((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.DIGEST", a1);
if ( dashf(v2) && (int)useindexfile((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.DELETED", a1);
if ( dashf(v2) && (int)useindexfile((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.JUNK", a1);
if ( dashf(v2) && (int)useindexfile((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s", a1);
rm_lost(v2);
return 0LL;
}

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

otherfile[0] = 0;
memset(nfile, 0, sizeof(nfile));
sprintf(v2, "/home/bbs/boards/%s", a1);
if ( (int)func5(v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.DIR", a1);
if ( func8(v2) && (int)func6((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.DIGEST", a1);
if ( func8(v2) && (int)func6((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.DELETED", a1);
if ( func8(v2) && (int)func6((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.JUNK", a1);
if ( func8(v2) && (int)func6((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s", a1);
func7(v2);
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

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // eax
int v5; // er12
char *v6; // rax
char *v7; // rax
int v8; // edi
char v10[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, v10, 0x200uLL) == 512 )
{
if ( v10[0] )
{
printf("processing %s\n", v10);
fflush(stdout);
if ( (int)find_rm_lost(v10) < 0 )
{
time(&nowtime);
v7 = ctime(&nowtime);
printf(" FAILED! %s", v7);
}
else
{
time(&nowtime);
v6 = ctime(&nowtime);
printf(" ....OK. %s", v6);
}
}
}
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);
v8 = v5;
v5 = 0;
close(v8);
printf("totalsize = %d", (unsigned int)totalsize);
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // eax
int v5; // er12
char *v6; // rax
char *v7; // rax
int v8; // edi
char v10[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, v10, 0x200uLL) == 512 )
{
if ( v10[0] )
{
printf("processing %s\n", v10);
fflush(stdout);
if ( (int)func9(v10) < 0 )
{
time(&nowtime);
v7 = ctime(&nowtime);
printf(" FAILED! %s", v7);
}
else
{
time(&nowtime);
v6 = ctime(&nowtime);
printf(" ....OK. %s", v6);
}
}
}
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);
v8 = v5;
v5 = 0;
close(v8);
printf("totalsize = %d", (unsigned int)totalsize);
}
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 *

return_type: 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
char *v5; // rax

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

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

v1 = nboard_0;
if ( nboard_0 <= 0 )
goto LABEL_8;
v2 = bname_2;
v3 = 0;
do
{
if ( !strcmp(v2, src) )
{
result = (unsigned int)count_1[v3];
count_1[v3] = result + 1;
return result;
}
++v3;
v2 += 20;
}
while ( v1 != v3 );
result = 0LL;
if ( v1 <= 799 )
{
LABEL_8:
v5 = strncpy(&bname_2[20 * v1], src, 0x13uLL);
nboard_0 = v1 + 1;
v5[19] = 0;
result = 0LL;
count_1[v1] = 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

variable_types: i int


getlogtime

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

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

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

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

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

return_type: void


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);
result[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);
result[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 v3; // er15
const char *v6; // r13
size_t v7; // rax
size_t v8; // rax
char *v9; // rbp

v3 = 0;
while ( 1 )
{
v9 = strstr(haystack, s);
if ( !v9 )
break;
++v3;
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 v3;
}

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

v3 = 0;
while ( 1 )
{
v9 = strstr(haystack, s);
if ( !v9 )
break;
++v3;
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 v3;
}

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 *


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

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


decompiled_code:
__int64 __fastcall delete_old_junk(char *a1)
{
unsigned int v1; // er12
time_t v3; // rbx
int v4; // er13
int v5; // ebx
int i; // eax
int v7; // eax
unsigned int v8; // er15
unsigned int v9; // er14
const char *v10; // rax
int j; // edx
int v12; // eax
char v13; // r13
unsigned int v14; // [rsp+Ch] [rbp-24Ch]
time_t timer; // [rsp+18h] [rbp-240h] BYREF
char file[80]; // [rsp+20h] [rbp-238h] BYREF
char newa[80]; // [rsp+70h] [rbp-1E8h] BYREF
char s[80]; // [rsp+C0h] [rbp-198h] BYREF
char buf[12]; // [rsp+110h] [rbp-148h] BYREF
int v20; // [rsp+11Ch] [rbp-13Ch]
char v21; // [rsp+16Fh] [rbp-E9h]
struct stat v22; // [rsp+190h] [rbp-C8h] BYREF

if ( stat(a1, &v22) )
return (unsigned int)-(*_errno_location() != 2);
v1 = 0;
time(&timer);
v3 = timer;
tmpfilename(a1, file, newa);
if ( (unsigned int)(digestmode - 4) <= 1 )
{
v13 = 68;
if ( digestmode != 4 )
v13 = 74;
*((_BYTE *)&timer + strlen(file) + 7) = v13;
file[strlen(newa) + 79] = v13;
}
v4 = open(a1, 0, 0LL);
if ( v4 == -1 )
{
if ( *_errno_location() != 2 )
v1 = -2;
}
else
{
v5 = v3 / 86400 % 100;
do
{
if ( read(v4, buf, 0x80uLL) != 128 )
{
close(v4);
return v1;
}
for ( i = v21; v5 < i; i -= 100 )
;
}
while ( (v20 & 4) != 0 || v5 - i <= 29 );
if ( lseek(v4, 0LL, 0) < 0 )
{
v1 = -3;
close(v4);
}
else
{
v7 = open(file, 193, 432LL);
v8 = v7;
if ( v7 == -1 )
{
v1 = -4;
close(v4);
}
else
{
v9 = 1;
flock(v7, 2);
v14 = 0;
while ( read(v4, buf, 0x80uLL) == 128 )
{
v10 = (const char *)fh2fname(buf);
sprintf(s, "/home/bbs/boards/%s/%s", currboard, v10);
for ( j = v21; v5 < j; j -= 100 )
;
v12 = v5 - j;
if ( (v20 & 4) != 0 || v12 <= 19 )
{
if ( (unsigned int)(v12 - 4) <= 2 && *(__int64 *)(f_stat(s) + 48) > 30000 && (v20 & 0x20) != 0 )
{
filter_attach(s);
v20 &= 0xFFFFFFDF;
}
if ( (unsigned int)safewrite(v8, buf, 128LL) == -1 )
{
v1 = -5;
unlink(file);
flock(v8, 8);
close(v8);
close(v4);
return v1;
}
}
else
{
++v14;
}
++v9;
}
close(v4);
if ( rename(a1, newa) == -1 )
{
v1 = -6;
flock(v8, 8);
close(v8);
}
else if ( rename(file, a1) == -1 )
{
flock(v8, 8);
v1 = -7;
close(v8);
}
else
{
flock(v8, 8);
close(v8);
printf("%d %d ", v9, v14);
}
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
unsigned int v1; // er12
time_t v3; // rbx
int v4; // er13
int v5; // ebx
int i; // eax
int v7; // eax
unsigned int v8; // er15
unsigned int v9; // er14
const char *v10; // rax
int j; // edx
int v12; // eax
char v13; // r13
unsigned int v14; // [rsp+Ch] [rbp-24Ch]
time_t timer; // [rsp+18h] [rbp-240h] BYREF
char file[80]; // [rsp+20h] [rbp-238h] BYREF
char newa[80]; // [rsp+70h] [rbp-1E8h] BYREF
char s[80]; // [rsp+C0h] [rbp-198h] BYREF
char buf[12]; // [rsp+110h] [rbp-148h] BYREF
int v20; // [rsp+11Ch] [rbp-13Ch]
char v21; // [rsp+16Fh] [rbp-E9h]
struct stat v22; // [rsp+190h] [rbp-C8h] BYREF

if ( stat(a1, &v22) )
return (unsigned int)-(*_errno_location() != 2);
v1 = 0;
time(&timer);
v3 = timer;
tmpfilename(a1, file, newa);
if ( (unsigned int)(digestmode - 4) <= 1 )
{
v13 = 68;
if ( digestmode != 4 )
v13 = 74;
*((_BYTE *)&timer + strlen(file) + 7) = v13;
file[strlen(newa) + 79] = v13;
}
v4 = open(a1, 0, 0LL);
if ( v4 == -1 )
{
if ( *_errno_location() != 2 )
v1 = -2;
}
else
{
v5 = v3 / 86400 % 100;
do
{
if ( read(v4, buf, 0x80uLL) != 128 )
{
close(v4);
return v1;
}
for ( i = v21; v5 < i; i -= 100 )
;
}
while ( (v20 & 4) != 0 || v5 - i <= 29 );
if ( lseek(v4, 0LL, 0) < 0 )
{
v1 = -3;
close(v4);
}
else
{
v7 = open(file, 193, 432LL);
v8 = v7;
if ( v7 == -1 )
{
v1 = -4;
close(v4);
}
else
{
v9 = 1;
flock(v7, 2);
v14 = 0;
while ( read(v4, buf, 0x80uLL) == 128 )
{
v10 = (const char *)fh2fname(buf);
sprintf(s, "/home/bbs/boards/%s/%s", currboard, v10);
for ( j = v21; v5 < j; j -= 100 )
;
v12 = v5 - j;
if ( (v20 & 4) != 0 || v12 <= 19 )
{
if ( (unsigned int)(v12 - 4) <= 2 && *(__int64 *)(f_stat(s) + 48) > 30000 && (v20 & 0x20) != 0 )
{
filter_attach(s);
v20 &= 0xFFFFFFDF;
}
if ( (unsigned int)safewrite(v8, buf, 128LL) == -1 )
{
v1 = -5;
unlink(file);
flock(v8, 8);
close(v8);
close(v4);
return v1;
}
}
else
{
++v14;
}
++v9;
}
close(v4);
if ( rename(a1, newa) == -1 )
{
v1 = -6;
flock(v8, 8);
close(v8);
}
else if ( rename(file, a1) == -1 )
{
flock(v8, 8);
v1 = -7;
close(v8);
}
else
{
flock(v8, 8);
close(v8);
printf("%d %d ", v9, v14);
}
}
}
}
return v1;
}

original_code:
int
delete_old_junk(char *filename)
{
 struct fileheader fhdr;
 char tmpfile[80], deleted[80];
 int fdr, fdw;
 int count, mday, fmday, total, ndeleted;
 time_t now;
 struct stat statbuf;
 if (stat(filename, &statbuf)) {
  if ((*__errno_location ()) == 2)
   return 0;
  return -1;
 }
 total = statbuf.st_size / ((int)sizeof(fhdr));
 time(&now);
 mday = now / (3600 * 24) % 100;
 tmpfilename(filename, tmpfile, deleted);
 if (digestmode == 4 || digestmode == 5) {
  tmpfile[strlen(tmpfile) - 1] = (digestmode == 4) ? 'D' : 'J';
  deleted[strlen(deleted) - 1] = (digestmode == 4) ? 'D' : 'J';
 }
 if ((fdr = open(filename, 00, 0)) == -1) {
  if ((*__errno_location ()) == 2)
   return 0;
  return -2;
 }
 ndeleted = 0;
 while (read(fdr, &fhdr, ((int)sizeof(fhdr))) == ((int)sizeof(fhdr))) {
  fmday = fhdr.deltime;
  while (fmday > mday)
   fmday -= 100;
  if (fhdr.accessed & 0x4 || mday - fmday < 30)
   continue;
  ndeleted++;
  break;
 }
 if (ndeleted == 0) {
  close(fdr);
  return 0;
 }
 if (lseek(fdr, 0, 0) < 0) {
  close(fdr);
  return -3;
 }
 if ((fdw = open(tmpfile, 01 | 0100 | 0200, 0660)) == -1) {
  close(fdr);
  return -4;
 }
 flock(fdw, 2);
 count = 1;
 ndeleted = 0;
 while (read(fdr, &fhdr, ((int)sizeof(fhdr))) == ((int)sizeof(fhdr))) {
  char fullpath[80];
  sprintf(fullpath, "/home/bbs" "/boards/%s/%s", currboard,
   fh2fname(&fhdr));
  fmday = fhdr.deltime;
  while (fmday > mday)
   fmday -= 100;
  if (fhdr.accessed & 0x4 || mday - fmday < 20) {
   if (mday - fmday > 3 && mday - fmday < 7
       && (f_stat(fullpath)->st_size) > 30000 && fhdr.accessed & 0x20) {
    filter_attach(fullpath);
    fhdr.accessed &= ~0x20;
   }
   if ((safewrite(fdw, &fhdr, ((int)sizeof(fhdr))) == -1)) {
    unlink(tmpfile);
    flock(fdw, 8);
    close(fdw);
    close(fdr);
    return -5;
   }
  } else {
   ndeleted++;
  }
  count++;
 }
 close(fdr);
 if (rename(filename, deleted) == -1) {
  flock(fdw, 8);
  close(fdw);
  return -6;
 }
 if (rename(tmpfile, filename) == -1) {
  flock(fdw, 8);
  close(fdw);
  return -7;
 }
 flock(fdw, 8);
 close(fdw);
 printf("%d %d ", count, ndeleted);
 return 0;
}

canonical_original_code:
int delete_old_junk(char *filename)
{
 struct fileheader fhdr;
 char tmpfile[80]; char deleted[80];
 int fdr; int fdw;
 int count; int mday; int fmday; int total; int ndeleted;
 long now;
 struct stat statbuf;
 if (stat(filename, &statbuf)) {
  if ((*__errno_location ()) == 2)
   return 0;
  return -1;
 }
 total = statbuf.st_size / ((int)sizeof(fhdr));
 time(&now);
 mday = now / (3600 * 24) % 100;
 tmpfilename(filename, tmpfile, deleted);
 if (digestmode == 4 || digestmode == 5) {
  tmpfile[strlen(tmpfile) - 1] = (digestmode == 4) ? 'D' : 'J';
  deleted[strlen(deleted) - 1] = (digestmode == 4) ? 'D' : 'J';
 }
 if ((fdr = open(filename, 00, 0)) == -1) {
  if ((*__errno_location ()) == 2)
   return 0;
  return -2;
 }
 ndeleted = 0;
 while (read(fdr, &fhdr, ((int)sizeof(fhdr))) == ((int)sizeof(fhdr))) {
  fmday = fhdr.deltime;
  while (fmday > mday)
   fmday -= 100;
  if (fhdr.accessed & 0x4 || mday - fmday < 30)
   continue;
  ndeleted++;
  break;
 }
 if (ndeleted == 0) {
  close(fdr);
  return 0;
 }
 if (lseek(fdr, 0, 0) < 0) {
  close(fdr);
  return -3;
 }
 if ((fdw = open(tmpfile, 01 | 0100 | 0200, 0660)) == -1) {
  close(fdr);
  return -4;
 }
 flock(fdw, 2);
 count = 1;
 ndeleted = 0;
 while (read(fdr, &fhdr, ((int)sizeof(fhdr))) == ((int)sizeof(fhdr))) {
  char fullpath[80];
  sprintf(fullpath, "/home/bbs" "/boards/%s/%s", currboard,
   fh2fname(&fhdr));
  fmday = fhdr.deltime;
  while (fmday > mday)
   fmday -= 100;
  if (fhdr.accessed & 0x4 || mday - fmday < 20) {
   if (mday - fmday > 3 && mday - fmday < 7
       && (f_stat(fullpath)->st_size) > 30000 && fhdr.accessed & 0x20) {
    filter_attach(fullpath);
    fhdr.accessed &= ~0x20;
   }
   if ((safewrite(fdw, &fhdr, ((int)sizeof(fhdr))) == -1)) {
    unlink(tmpfile);
    flock(fdw, 8);
    close(fdw);
    close(fdr);
    return -5;
   }
  } else {
   ndeleted++;
  }
  count++;
 }
 close(fdr);
 if (rename(filename, deleted) == -1) {
  flock(fdw, 8);
  close(fdw);
  return -6;
 }
 if (rename(tmpfile, filename) == -1) {
  flock(fdw, 8);
  close(fdw);
  return -7;
 }
 flock(fdw, 8);
 close(fdw);
 printf("%d %d ", count, ndeleted);
 return 0;
}

variable_types:
filename
char *

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

variable_types:
tmpfile
char [80]

variable_types:
deleted
char [80]

variable_types: fdr int

variable_types: fdw int

variable_types: mday int

variable_types: fmday int

variable_types: total int

variable_types: ndeleted int

variable_types: now long

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

variable_types:
fullpath
char [80]

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


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

sprintf(v2, "/home/bbs/boards/%s/.DELETED", src);
digestmode = 4;
strcpy(currboard, src);
printf(".DELETED ");
if ( (unsigned int)delete_old_junk(v2) )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.JUNK", src);
digestmode = 5;
strcpy(currboard, src);
printf(".JUNK ");
return (unsigned int)-((unsigned int)delete_old_junk(v2) != 0);
}

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

sprintf(v2, "/home/bbs/boards/%s/.DELETED", src);
digestmode = 4;
strcpy(currboard, src);
printf(".DELETED ");
if ( (unsigned int)func0(v2) )
return 0xFFFFFFFFLL;
sprintf(v2, "/home/bbs/boards/%s/.JUNK", src);
digestmode = 5;
strcpy(currboard, src);
printf(".JUNK ");
return (unsigned int)-((unsigned int)func0(v2) != 0);
}

original_code:
int
rm_junk(struct boardheader *bhp)
{
 char buf[200];
 sprintf(buf, "/home/bbs" "/boards/%s/.DELETED", bhp->filename);
 digestmode = 4;
 sprintf(currboard, "%s", bhp->filename);
 printf(".DELETED ");
 if (delete_old_junk(buf) != 0)
  return -1;
 sprintf(buf, "/home/bbs" "/boards/%s/.JUNK", bhp->filename);
 digestmode = 5;
 sprintf(currboard, "%s", bhp->filename);
 printf(".JUNK ");
 if (delete_old_junk(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]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // eax
int v5; // er12
char *v6; // rax
char *v7; // rax
int v8; // edi
time_t timer; // [rsp+8h] [rbp-210h] BYREF
char buf[520]; // [rsp+10h] [rbp-208h] BYREF

chdir("/home/bbs");
timer = time(0LL);
v3 = ctime(&timer);
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, buf, 0x200uLL) == 512 )
{
if ( buf[0] )
{
printf("processing %s...", buf);
if ( (int)rm_junk(buf) < 0 )
{
time(&timer);
v7 = ctime(&timer);
printf("FAILED! %s", v7);
}
else
{
time(&timer);
v6 = ctime(&timer);
printf("....OK. %s", v6);
}
sync();
}
}
flock(v5, 8);
v8 = v5;
v5 = 0;
close(v8);
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // eax
int v5; // er12
char *v6; // rax
char *v7; // rax
int v8; // edi
time_t timer; // [rsp+8h] [rbp-210h] BYREF
char buf[520]; // [rsp+10h] [rbp-208h] BYREF

chdir("/home/bbs");
timer = time(0LL);
v3 = ctime(&timer);
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, buf, 0x200uLL) == 512 )
{
if ( buf[0] )
{
printf("processing %s...", buf);
if ( (int)func1(buf) < 0 )
{
time(&timer);
v7 = ctime(&timer);
printf("FAILED! %s", v7);
}
else
{
time(&timer);
v6 = ctime(&timer);
printf("....OK. %s", v6);
}
sync();
}
}
flock(v5, 8);
v8 = v5;
v5 = 0;
close(v8);
}
return v5;
}

original_code:
int
main()
{
 int b_fd;
 struct boardheader bh;
 int size;
 time_t nowtime;
 size = ((int)sizeof(bh));
 chdir("/home/bbs");
 nowtime = time(((void *)0));
 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...", bh.filename);
  if (rm_junk(&bh) < 0) {
   time(&nowtime);
   printf("FAILED! %s", ctime(&nowtime));
  } else {
   time(&nowtime);
   printf("....OK. %s", ctime(&nowtime));
  }
  sync();
 }
 flock(b_fd, 8);
 close(b_fd);
 return 0;
}

canonical_original_code:
int main()
{
 int b_fd;
 struct boardheader bh;
 int size;
 long nowtime;
 size = ((int)sizeof(bh));
 chdir("/home/bbs");
 nowtime = time(((void *)0));
 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...", bh.filename);
  if (rm_junk(&bh) < 0) {
   time(&nowtime);
   printf("FAILED! %s", ctime(&nowtime));
  } else {
   time(&nowtime);
   printf("....OK. %s", ctime(&nowtime));
  }
  sync();
 }
 flock(b_fd, 8);
 close(b_fd);
 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

variable_types: nowtime long


dosetpty

decompiled_code:
int dosetpty()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v1);
v1.c_iflag |= 1u;
v1.c_cc[11] = 0;
v1.c_lflag = v1.c_lflag & 0xFFFFFEFE | 0x5A;
return tcsetattr(0, 1, &v1);
}

canonical_decompiled_code:
int func7()
{
struct termios v1; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(0, &v1);
v1.c_iflag |= 1u;
v1.c_cc[11] = 0;
v1.c_lflag = v1.c_lflag & 0xFFFFFEFE | 0x5A;
return tcsetattr(0, 1, &v1);
}

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


pipedata

decompiled_code:
int __fastcall pipedata(int a1, int a2)
{
int v2; // ebx
int v3; // er13
__int64 v4; // rbx
int v5; // eax
__int64 v6; // r12
__int64 v7; // rax
int v8; // ebx
__int64 v9; // rbp
int result; // eax
__int64 v11; // [rsp+8h] [rbp-260h]
int v12; // [rsp+14h] [rbp-254h]
fd_set readfds; // [rsp+30h] [rbp-238h] BYREF
fd_set writefds; // [rsp+B0h] [rbp-1B8h] BYREF
char buf[312]; // [rsp+130h] [rbp-138h] BYREF

memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
v2 = a1 + 63;
v3 = a2 + 1;
if ( a1 >= 0 )
v2 = a1;
v4 = v2 >> 6;
v5 = a2 + 63;
v6 = 1LL << (a1 % 64);
if ( a2 >= 0 )
v5 = a2;
v12 = v5 >> 6;
if ( a1 > a2 )
v3 = a1 + 1;
v11 = 1LL << (a2 % 64);
v7 = v4;
v8 = 0;
v9 = v7;
while ( 1 )
{
if ( v8 > 255 || (readfds.fds_bits[v9] |= v6, v8) )
writefds.fds_bits[v12] |= v11;
result = select(v3, &readfds, &writefds, 0LL, 0LL);
if ( result < 0 )
break;
if ( (readfds.fds_bits[v9] & v6) != 0 )
{
result = read(a1, &buf[v8], 256LL - v8);
if ( result <= 0 )
return result;
v8 += result;
readfds.fds_bits[v9] &= ~v6;
}
if ( (writefds.fds_bits[v12] & v11) != 0 )
{
result = write(a2, buf, v8);
if ( result <= 0 )
return result;
v8 -= result;
memmove(buf, &buf[result], v8);
writefds.fds_bits[v12] &= ~v11;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1, int a2)
{
int v2; // ebx
int v3; // er13
__int64 v4; // rbx
int v5; // eax
__int64 v6; // r12
__int64 v7; // rax
int v8; // ebx
__int64 v9; // rbp
int result; // eax
__int64 v11; // [rsp+8h] [rbp-260h]
int v12; // [rsp+14h] [rbp-254h]
fd_set readfds; // [rsp+30h] [rbp-238h] BYREF
fd_set writefds; // [rsp+B0h] [rbp-1B8h] BYREF
char buf[312]; // [rsp+130h] [rbp-138h] BYREF

memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
v2 = a1 + 63;
v3 = a2 + 1;
if ( a1 >= 0 )
v2 = a1;
v4 = v2 >> 6;
v5 = a2 + 63;
v6 = 1LL << (a1 % 64);
if ( a2 >= 0 )
v5 = a2;
v12 = v5 >> 6;
if ( a1 > a2 )
v3 = a1 + 1;
v11 = 1LL << (a2 % 64);
v7 = v4;
v8 = 0;
v9 = v7;
while ( 1 )
{
if ( v8 > 255 || (readfds.fds_bits[v9] |= v6, v8) )
writefds.fds_bits[v12] |= v11;
result = select(v3, &readfds, &writefds, 0LL, 0LL);
if ( result < 0 )
break;
if ( (readfds.fds_bits[v9] & v6) != 0 )
{
result = read(a1, &buf[v8], 256LL - v8);
if ( result <= 0 )
return result;
v8 += result;
readfds.fds_bits[v9] &= ~v6;
}
if ( (writefds.fds_bits[v12] & v11) != 0 )
{
result = write(a2, buf, v8);
if ( result <= 0 )
return result;
v8 -= result;
memmove(buf, &buf[result], v8);
writefds.fds_bits[v12] &= ~v11;
}
}
return result;
}

canonical_original_code:
int pipedata(int fdr, int fdw)
{
 char ch;
 char buf[256];
 int i = 0; int retv; int n;
 struct fd_set fsr; struct fd_set fsw;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fsr)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fsw)->__fds_bits)[0]) : "memory"); } while (0);
 while (1) {
  if (i < 256)
   ((void) (((&fsr)->__fds_bits)[((fdr) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fdr) % (8 * (int) sizeof (__fd_mask)))))));
  if (i)
   ((void) (((&fsw)->__fds_bits)[((fdw) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((fdw) % (8 * (int) sizeof (__fd_mask)))))));
  retv =
      select((fdr > fdw) ? (1 + fdr) : (1 + fdw), &fsr, &fsw,
      ((void *)0), ((void *)0));
  if (retv < 0)
   return;
  if (((((&fsr)->__fds_bits)[((fdr) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fdr) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   n = read(fdr, buf + i, sizeof (buf) - i);
   if (n <= 0)
    return;
   i += n;
   ((void) (((&fsr)->__fds_bits)[((fdr) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fdr) % (8 * (int) sizeof (__fd_mask)))))));
  }
  if (((((&fsw)->__fds_bits)[((fdw) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((fdw) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   n = write(fdw, buf, i);
   if (n <= 0)
    return;
   i -= n;
   memmove(buf, buf + n, i);
   ((void) (((&fsw)->__fds_bits)[((fdw) / (8 * (int) sizeof (__fd_mask)))] &= ~((__fd_mask) (1UL << ((fdw) % (8 * (int) sizeof (__fd_mask)))))));
  }
 }
}

variable_types: ch char

variable_types:
buf
char [256]

variable_types: i int

variable_types: retv int

variable_types: n int

variable_types:
fsr
struct fd_set { long __fds_bits[-1]; }

variable_types:
fsw
struct fd_set { long __fds_bits[-1]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // ebp
__pid_t v5; // eax
__pid_t v6; // eax
int amaster; // [rsp+Ch] [rbp-3Ch] BYREF
char name[56]; // [rsp+10h] [rbp-38h] BYREF

setsid();
result = forkpty(&amaster, name, 0LL, 0LL);
if ( result >= 0 )
{
if ( result || (dosetpty(), execvp(argv[1], (char *const *)argv + 1) >= 0) )
{
result = fork();
v4 = result;
if ( result >= 0 )
{
if ( result )
{
pipedata((unsigned int)amaster, 1LL);
kill(v4, 9);
result = 0;
}
else
{
pipedata(0LL, (unsigned int)amaster);
v5 = getppid();
kill(v5, 9);
result = 0;
}
}
}
else
{
v6 = getppid();
result = kill(v6, 15);
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
int v4; // ebp
__pid_t v5; // eax
__pid_t v6; // eax
int amaster; // [rsp+Ch] [rbp-3Ch] BYREF
char name[56]; // [rsp+10h] [rbp-38h] BYREF

setsid();
result = forkpty(&amaster, name, 0LL, 0LL);
if ( result >= 0 )
{
if ( result || (func7(), execvp(argv[1], (char *const *)argv + 1) >= 0) )
{
result = fork();
v4 = result;
if ( result >= 0 )
{
if ( result )
{
func8((unsigned int)amaster, 1LL);
kill(v4, 9);
result = 0;
}
else
{
func8(0LL, (unsigned int)amaster);
v5 = getppid();
kill(v5, 9);
result = 0;
}
}
}
else
{
v6 = getppid();
result = kill(v6, 15);
}
}
return result;
}

original_code:
int
main(int argc, char *argv[])
{
 int fdm, n;
 pid_t pid;
 char slave_name[20];
 char buf[256];
 setsid();
 pid = forkpty(&fdm, slave_name, ((void *)0), ((void *)0));
 if (pid < 0)
  return;
 else if (pid == 0) {
  dosetpty();
  if (execvp(argv[1], &argv[1]) < 0)
   return kill(getppid(), 15);
 }
 pid = fork();
 if (pid < 0)
  return;
 else if (pid == 0) {
  pipedata(0, fdm);
  kill(getppid(), 9);
 } else {
  pipedata(fdm, 1);
  kill(pid, 9);
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fdm; int n;
 int pid;
 char slave_name[20];
 char buf[256];
 setsid();
 pid = forkpty(&fdm, slave_name, ((void *)0), ((void *)0));
 if (pid < 0)
  return;
 else if (pid == 0) {
  dosetpty();
  if (execvp(argv[1], &argv[1]) < 0)
   return kill(getppid(), 15);
 }
 pid = fork();
 if (pid < 0)
  return;
 else if (pid == 0) {
  pipedata(0, fdm);
  kill(getppid(), 9);
 } else {
  pipedata(fdm, 1);
  kill(pid, 9);
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fdm int

variable_types: pid int


addscore

decompiled_code:
int __fastcall addscore(char *src, int a2, int a3)
{
int v4; // er15
const char *v5; // r14
int v6; // ebx
char *v7; // rax

v4 = num;
if ( num <= 0 )
goto LABEL_8;
v5 = alist;
v6 = 0;
do
{
LODWORD(v7) = strcmp(v5, src);
if ( !(_DWORD)v7 )
{
v7 = (char *)(32LL * v6);
*(int *)((char *)&dword_4040D8 + (_QWORD)v7) += a2;
*(int *)((char *)&dword_4040DC + (_QWORD)v7) += a3;
return (int)v7;
}
++v6;
v5 += 32;
}
while ( v4 != v6 );
if ( v4 <= 499 )
{
LABEL_8:
v7 = strcpy((char *)(32LL * v4 + 4210880), src);
num = v4 + 1;
*((_DWORD *)v7 + 6) = a2;
*((_DWORD *)v7 + 7) = a3;
}
return (int)v7;
}

canonical_decompiled_code:
int __fastcall func7(char *src, int a2, int a3)
{
int v4; // er15
const char *v5; // r14
int v6; // ebx
char *v7; // rax

v4 = num;
if ( num <= 0 )
goto LABEL_8;
v5 = alist;
v6 = 0;
do
{
LODWORD(v7) = strcmp(v5, src);
if ( !(_DWORD)v7 )
{
v7 = (char *)(32LL * v6);
*(int *)((char *)&dword_4040D8 + (_QWORD)v7) += a2;
*(int *)((char *)&dword_4040DC + (_QWORD)v7) += a3;
return (int)v7;
}
++v6;
v5 += 32;
}
while ( v4 != v6 );
if ( v4 <= 499 )
{
LABEL_8:
v7 = strcpy((char *)(32LL * v4 + 4210880), src);
num = v4 + 1;
*((_DWORD *)v7 + 6) = a2;
*((_DWORD *)v7 + 7) = a3;
}
return (int)v7;
}

original_code:
int
addscore(char *author, int sum, int n)
{
 int i;
 for (i = 0; i < num; i++) {
  if (strcmp(alist[i].author, author))
   continue;
  alist[i].score += sum;
  alist[i].n += n;
  return;
 }
 if (num < 500) {
  strcpy(alist[num].author, author);
  alist[num].score = sum;
  alist[num].n = n;
  num++;
 }
}

variable_types:
author
char *

variable_types: sum int


printscore

decompiled_code:
int printscore()
{
int result; // eax
int v1; // ebp
char *v2; // rbx
__int64 v3; // rdx
__int64 v4; // rsi
const char *v5; // rcx

result = num;
if ( num > 0 )
{
v1 = 0;
v2 = alist;
do
{
v3 = *((unsigned int *)v2 + 7);
v4 = *((unsigned int *)v2 + 6);
v5 = v2;
++v1;
v2 += 32;
result = printf("%10d %10d %s\n", v4, v3, v5);
}
while ( num > v1 );
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
int v1; // ebp
char *v2; // rbx
__int64 v3; // rdx
__int64 v4; // rsi
const char *v5; // rcx

result = num;
if ( num > 0 )
{
v1 = 0;
v2 = alist;
do
{
v3 = *((unsigned int *)v2 + 7);
v4 = *((unsigned int *)v2 + 6);
v5 = v2;
++v1;
v2 += 32;
result = printf("%10d %10d %s\n", v4, v3, v5);
}
while ( num > v1 );
}
return result;
}

original_code:
int
printscore()
{
 int i;
 for (i = 0; i < num; i++) {
  printf("%10d %10d %s\n", alist[i].score, alist[i].n,
         alist[i].author);
 }
}


decompiled_code:
__int64 __fastcall copy_brc(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // ebx
int v5; // eax
int v6; // ebp
int v7; // eax
_BYTE v9[25032]; // [rsp+0h] [rbp-61C8h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = read(v2, v9, 0x61A8uLL);
close(v3);
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
v5 = open(a2, 65, 432LL);
v6 = v5;
if ( v5 < 0 )
return 0xFFFFFFFFLL;
v7 = write(v5, v9, v4);
if ( v7 <= 0 )
{
close(v6);
return 0xFFFFFFFFLL;
}
ftruncate(v6, v7);
close(v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
int v2; // eax
int v3; // ebp
int v4; // ebx
int v5; // eax
int v6; // ebp
int v7; // eax
_BYTE v9[25032]; // [rsp+0h] [rbp-61C8h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = read(v2, v9, 0x61A8uLL);
close(v3);
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
v5 = open(a2, 65, 432LL);
v6 = v5;
if ( v5 < 0 )
return 0xFFFFFFFFLL;
v7 = write(v5, v9, v4);
if ( v7 <= 0 )
{
close(v6);
return 0xFFFFFFFFLL;
}
ftruncate(v6, v7);
close(v6);
return 0LL;
}

original_code:
int
copy_brc(char *ent, char *toent)
{
 int fd;
 char buf[25000];
 int size;
 fd = open(ent, 00);
 if (fd < 0)
  return -1;
 size = read(fd, buf, 25000);
 close(fd);
 if (size <= 0)
  return -1;
 fd = open(toent, 01 | 0100, 0660);
 if (fd < 0)
  return -1;
 size = write(fd, buf, size);
 if (size > 0)
  ftruncate(fd, size);
 close(fd);
 if (size <= 0)
  return -1;
 return 0;
}

variable_types:
ent
char *

variable_types:
toent
char *

variable_types: fd int

variable_types:
buf
char [25000]


original_code:
int
compute_user_value(struct userec *urec)
{
 int value;
 if ((urec->userlevel & 000400)
     || strcmp(urec->userid, "guest") == 0)
  return 999;
 value = (time(0) - urec->lastlogin) / 60;
 if (strcmp(urec->userid, "new") == 0)
  return (30 - value) * 60;
 if (urec->numlogins <= 3)
  return (15 * 1440 - value) / 1440;
 if (!(urec->userlevel & 000020))
  return (30 * 1440 - value) / 1440;
 return (120 * 1440 - value) / 1440;
}

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


ascii

decompiled_code:
__int64 __fastcall ascii(char *a1)
{
char v1; // al
char *v2; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1 + 1;
while ( v1 >= 0 )
{
v1 = *v2++;
if ( !v1 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
char v1; // al
char *v2; // rdi

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1 + 1;
while ( v1 >= 0 )
{
v1 = *v2++;
if ( !v1 )
return 1LL;
}
return 0LL;
}

original_code:
int
ascii(char *s)
{
 int i;
 i = 0;
 while (1) {
  if (!s[i])
   break;
  if (!(((s[i]) & ~0x7f) == 0))
   return 0;
  i++;
 }
 return 1;
}

variable_types:
s
char *

variable_types: i int


cmpfiletime

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

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

original_code:
int
cmpfiletime(struct lastmark *a, struct lastmark *b)
{
 return b->filetime - a->filetime;
}

variable_types: struct lastmark { char title[100]; char board[30]; char boardtitle[80]; int thread; int filetime; char sec[10]; } *

variable_types:
b
struct lastmark *


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

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

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

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

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

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

variable_types:
s
unsigned char *

variable_types: flag int


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

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

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

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

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

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

variable_types:
buf
char [512]

variable_types:
tmp
char [256]

variable_types:
ptr
char *


dofilter

decompiled_code:
__int64 __fastcall dofilter(char *haystack)
{
int v1; // er12
const char *v2; // rbp
int v3; // ebx

v1 = nfilterstr;
if ( nfilterstr )
{
if ( nfilterstr <= 0 )
{
v3 = 0;
}
else
{
v2 = filterstr;
v3 = 0;
do
{
if ( strstr(haystack, v2) )
break;
++v3;
v2 += 60;
}
while ( v1 != v3 );
}
v1 = v1 > v3;
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *haystack)
{
int v1; // er12
const char *v2; // rbp
int v3; // ebx

v1 = nfilterstr;
if ( nfilterstr )
{
if ( nfilterstr <= 0 )
{
v3 = 0;
}
else
{
v2 = filterstr;
v3 = 0;
do
{
if ( strstr(haystack, v2) )
break;
++v3;
v2 += 60;
}
while ( v1 != v3 );
}
v1 = v1 > v3;
}
return (unsigned int)v1;
}

original_code:
int
dofilter(char *str)
{
 int i;
 if (!nfilterstr)
  return 0;
 for (i = 0; i < nfilterstr; i++) {
  if (strstr(str, filterstr[i]))
   break;
 }
 if (i < nfilterstr)
  return 1;
 return 0;
}

variable_types:
str
char *


thinktime

decompiled_code:
float thinktime()
{
__time_t v0; // rdx
__suseconds_t v1; // rax

gettimeofday(&after, 0LL);
v0 = after.tv_sec - before[0];
v1 = after.tv_usec - before[1];
after.tv_sec -= before[0];
after.tv_usec = v1;
if ( v1 < 0 )
{
--v0;
v1 += 1000000LL;
after.tv_sec = v0;
after.tv_usec = v1;
}
return (float)((float)(int)v1 / 1000000.0) + (float)(int)v0;
}

canonical_decompiled_code:
float func0()
{
__time_t v0; // rdx
__suseconds_t v1; // rax

gettimeofday(&after, 0LL);
v0 = after.tv_sec - before[0];
v1 = after.tv_usec - before[1];
after.tv_sec -= before[0];
after.tv_usec = v1;
if ( v1 < 0 )
{
--v0;
v1 += 1000000LL;
after.tv_sec = v0;
after.tv_usec = v1;
}
return (float)((float)(int)v1 / 1000000.0) + (float)(int)v0;
}

original_code:
float thinktime()
{
  float t;
  char msg_buf[80];
  gettimeofday(&after, (struct timezone *) 0);
  after.tv_sec-=before.tv_sec;
  after.tv_usec-=before.tv_usec;
  if(after.tv_usec<0)
  {
    after.tv_sec--;
    after.tv_usec+=1000000;
  }
  t=(float) after.tv_sec+(float) after.tv_usec/1000000;
  return(t);
}

variable_types: t float

return_type: float

user_defined_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


toobigmesg

decompiled_code:
void toobigmesg()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void
toobigmesg()
{
}

canonical_original_code:
void toobigmesg()
{
}


fixabnormalfn

decompiled_code:
__int64 __fastcall fixabnormalfn(char *src, char *s)
{
int v2; // eax
unsigned int v3; // er13
size_t v4; // rax
unsigned int v5; // er13
char v7[256]; // [rsp+0h] [rbp-218h] BYREF
char sa[280]; // [rsp+100h] [rbp-118h] BYREF

v2 = (unsigned __int8)*s;
if ( (v2 != 77 || s[1] != 46) && (v2 != 71 || s[1] != 46) )
return 0LL;
v3 = 0;
if ( ((*_ctype_b_loc())[s[3]] & 0x800) != 0 )
{
v4 = strlen(s);
if ( v4 <= 0x13 && s[v4 - 1] != 65 )
{
v5 = atoi(s + 2) + 1;
sprintf(sa, "%s/%s", src, s);
strcpy(v7, src);
if ( (int)trycreatefile(v7, "M.%d.A", v5) <= 0 )
v3 = -1;
else
v3 = rename(sa, v7);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src, char *s)
{
int v2; // eax
unsigned int v3; // er13
size_t v4; // rax
unsigned int v5; // er13
char v7[256]; // [rsp+0h] [rbp-218h] BYREF
char sa[280]; // [rsp+100h] [rbp-118h] BYREF

v2 = (unsigned __int8)*s;
if ( (v2 != 77 || s[1] != 46) && (v2 != 71 || s[1] != 46) )
return 0LL;
v3 = 0;
if ( ((*_ctype_b_loc())[s[3]] & 0x800) != 0 )
{
v4 = strlen(s);
if ( v4 <= 0x13 && s[v4 - 1] != 65 )
{
v5 = atoi(s + 2) + 1;
sprintf(sa, "%s/%s", src, s);
strcpy(v7, src);
if ( (int)trycreatefile(v7, "M.%d.A", v5) <= 0 )
v3 = -1;
else
v3 = rename(sa, v7);
}
}
return v3;
}

original_code:
int
fixabnormalfn(char *path, char *file)
{
 char newfilepath[256], oldfilepath[256];
 int l, t;
 if (strncmp(file, "M.", 2) && strncmp(file, "G.", 2))
  return 0;
 if (!((*__ctype_b_loc ())[(int) ((file[3]))] & (unsigned short int) _ISdigit))
  return 0;
 if (strlen(file) >= 20)
  return 0;
 l = strlen(file);
 if (file[l - 1] == 'A')
  return 0;
 t = atoi(file + 2) + 1;
 sprintf(oldfilepath, "%s/%s", path, file);
 strcpy(newfilepath, path);
 t = trycreatefile(newfilepath, "M.%d.A", t, 100);
 if (t <= 0)
  return -1;
 return rename(oldfilepath, newfilepath);
}

canonical_original_code:
int fixabnormalfn(char *path, char *file)
{
 char newfilepath[256]; char oldfilepath[256];
 int l; int t;
 if (strncmp(file, "M.", 2) && strncmp(file, "G.", 2))
  return 0;
 if (!((*__ctype_b_loc ())[(int) ((file[3]))] & (unsigned short) _ISdigit))
  return 0;
 if (strlen(file) >= 20)
  return 0;
 l = strlen(file);
 if (file[l - 1] == 'A')
  return 0;
 t = atoi(file + 2) + 1;
 sprintf(oldfilepath, "%s/%s", path, file);
 strcpy(newfilepath, path);
 t = trycreatefile(newfilepath, "M.%d.A", t, 100);
 if (t <= 0)
  return -1;
 return rename(oldfilepath, newfilepath);
}

variable_types:
path
char *

variable_types:
file
char *

variable_types:
newfilepath
char [256]

variable_types:
oldfilepath
char [256]

variable_types: l int

variable_types: t int


useindexfile

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

canonical_decompiled_code:
__int64 __fastcall func5(__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 *


decompiled_code:
__int64 __fastcall find_lost_mail(char *src)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

otherfile[0] = 0;
memset(nfile, 0, 0x78uLL);
if ( (int)getallpost(src) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "%s/.DIR", src);
if ( dashf(v2) && (int)useindexfile((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "%s/.DIGEST", src);
if ( dashf(v2) && (int)useindexfile((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "%s/.DELETED", src);
if ( dashf(v2) && (int)useindexfile((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "%s/.JUNK", src);
if ( dashf(v2) && (int)useindexfile((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
save_lost(src);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *src)
{
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

otherfile[0] = 0;
memset(nfile, 0, 0x78uLL);
if ( (int)func4(src) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "%s/.DIR", src);
if ( func7(v2) && (int)func5((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "%s/.DIGEST", src);
if ( func7(v2) && (int)func5((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "%s/.DELETED", src);
if ( func7(v2) && (int)func5((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
sprintf(v2, "%s/.JUNK", src);
if ( func7(v2) && (int)func5((__int64)v2) < 0 )
return 0xFFFFFFFFLL;
func6(src);
return 0LL;
}

original_code:
int
find_lost_mail(char *path)
{
 char buf[1024];
 int i;
 for (i = 0; i < 30; i++) {
  nfile[i] = 0;
 }
 otherfile[0] = 0;
 if (getallpost(path) < 0)
  return -1;
 sprintf(buf, "%s/.DIR", path);
 if (dashf(buf))
  if (useindexfile(buf) < 0)
   return -1;
 sprintf(buf, "%s/.DIGEST", path);
 if (dashf(buf))
  if (useindexfile(buf) < 0)
   return -1;
 sprintf(buf, "%s/.DELETED", path);
 if (dashf(buf))
  if (useindexfile(buf) < 0)
   return -1;
 sprintf(buf, "%s/.JUNK", path);
 if (dashf(buf))
  if (useindexfile(buf) < 0)
   return -1;
 save_lost(path);
 return 0;
}

variable_types:
buf
char [1024]

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
char *v4; // rax
DIR *v5; // r12
struct dirent *v6; // rax
const char *v7; // rbp
struct stat v9; // [rsp+0h] [rbp-8A8h] BYREF
char s[1024]; // [rsp+90h] [rbp-818h] BYREF
char file[1048]; // [rsp+490h] [rbp-418h] BYREF

v3 = 65;
chdir("/home/bbs");
LODWORD(nowtime) = time(0LL);
puts("find_lost_mail is running~");
v4 = ctime(&nowtime);
printf("\x1B[1mbbs home=%s now time = %s\x1B[0m\n", "/home/bbs", v4);
do
{
sprintf(s, "/home/bbs/mail/%c", v3);
printf("processing %s\n", s);
v5 = opendir(s);
if ( v5 )
{
while ( 1 )
{
v6 = readdir(v5);
if ( !v6 )
break;
while ( v6->d_name[0] != 46 )
{
v7 = v6->d_name;
sprintf(file, "%s/%s", s, v6->d_name);
if ( stat(file, &v9) || (v9.st_mode & 0xF000) != 0x4000 || (int)find_lost_mail(file) >= 0 )
break;
printf(" %s failed\n", v7);
v6 = readdir(v5);
if ( !v6 )
goto LABEL_9;
}
}
LABEL_9:
closedir(v5);
}
++v3;
}
while ( v3 != 91 );
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);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
char *v4; // rax
DIR *v5; // r12
struct dirent *v6; // rax
const char *v7; // rbp
struct stat v9; // [rsp+0h] [rbp-8A8h] BYREF
char s[1024]; // [rsp+90h] [rbp-818h] BYREF
char file[1048]; // [rsp+490h] [rbp-418h] BYREF

v3 = 65;
chdir("/home/bbs");
LODWORD(nowtime) = time(0LL);
puts("find_lost_mail is running~");
v4 = ctime(&nowtime);
printf("\x1B[1mbbs home=%s now time = %s\x1B[0m\n", "/home/bbs", v4);
do
{
sprintf(s, "/home/bbs/mail/%c", v3);
printf("processing %s\n", s);
v5 = opendir(s);
if ( v5 )
{
while ( 1 )
{
v6 = readdir(v5);
if ( !v6 )
break;
while ( v6->d_name[0] != 46 )
{
v7 = v6->d_name;
sprintf(file, "%s/%s", s, v6->d_name);
if ( stat(file, &v9) || (v9.st_mode & 0xF000) != 0x4000 || (int)func8(file) >= 0 )
break;
printf(" %s failed\n", v7);
v6 = readdir(v5);
if ( !v6 )
goto LABEL_9;
}
}
LABEL_9:
closedir(v5);
}
++v3;
}
while ( v3 != 91 );
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);
return 0;
}

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


decompiled_code:
__int64 __fastcall is_free(int a1)
{
__int64 v1; // rax

get_free_list();
if ( !free_num )
return 0LL;
v1 = 0LL;
while ( free_mask[v1] != (free_mask[v1] | a1 ^ free_addr[v1]) )
{
if ( free_num == ++v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rax

func1();
if ( !free_num )
return 0LL;
v1 = 0LL;
while ( free_mask[v1] != (free_mask[v1] | a1 ^ free_addr[v1]) )
{
if ( free_num == ++v1 )
return 0LL;
}
return 1LL;
}

original_code:
int
is_free(unsigned int x)
{
 int n;
 get_free_list();
 for (n = 0; n < free_num; n++)
  if (((x ^ free_addr[n]) | free_mask[n]) == free_mask[n])
   return 1;
 return 0;
}

variable_types:
x
unsigned int

variable_types: n int


decompiled_code:
_BOOL8 __fastcall anc_hidetitle(char *haystack)
{
_BOOL4 v1; // er12

v1 = 1;
if ( !strstr(haystack, "(BM: SYSOPS)") && !strstr(haystack, "(BM: SECRET)") && !strstr(haystack, "(BM: BMS)") )
v1 = strstr(haystack, "<HIDE>") != 0LL;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *haystack)
{
_BOOL4 v1; // er12

v1 = 1;
if ( !strstr(haystack, "(BM: SYSOPS)") && !strstr(haystack, "(BM: SECRET)") && !strstr(haystack, "(BM: BMS)") )
v1 = strstr(haystack, "<HIDE>") != 0LL;
return v1;
}

original_code:
int
anc_hidetitle(char *title)
{
 if (strstr(title, "(BM: SYSOPS)") != ((void *)0)
     || strstr(title, "(BM: SECRET)") != ((void *)0)
     || strstr(title, "(BM: BMS)") != ((void *)0))
  return 1;
 if (strstr(title, "<HIDE>") != ((void *)0))
  return 1;
 return 0;
}

variable_types:
title
char *


countdb

decompiled_code:
__int64 __fastcall countdb(char *a1)
{
char v1; // al
char *v2; // rdx
char v3; // dl

v1 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = v1;
v1 = a1[1];
if ( v3 >= 0 )
{
v2 = a1 + 1;
if ( !v1 )
return 0LL;
goto LABEL_4;
}
if ( !v1 )
return 1LL;
v1 = a1[2];
v2 = a1 + 2;
if ( !v1 )
return 0LL;
LABEL_4:
a1 = v2;
}
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char v1; // al
char *v2; // rdx
char v3; // dl

v1 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = v1;
v1 = a1[1];
if ( v3 >= 0 )
{
v2 = a1 + 1;
if ( !v1 )
return 0LL;
goto LABEL_4;
}
if ( !v1 )
return 1LL;
v1 = a1[2];
v2 = a1 + 2;
if ( !v1 )
return 0LL;
LABEL_4:
a1 = v2;
}
}

original_code:
int
countdb(char *str)
{
 int db = 0;
 unsigned char *ptr = str;
 while (*ptr) {
  if (db)
   db = 0;
  else if (*ptr >= 128)
   db = 1;
  *ptr++;
 }
 return db;
}

variable_types: db int

variable_types:
ptr
unsigned char *


decompiled_code:
char *__fastcall encode_url(char *a1)
{
char v1; // dl
unsigned __int8 *v2; // r12
int v3; // ebx
int v4; // ebp
char *result; // rax
int v6; // eax
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v1 = *a1;
if ( *a1 )
{
v2 = (unsigned __int8 *)a1;
v3 = 0;
do
{
v4 = v3 + 1;
switch ( v1 )
{
case ' ':
case '"':
case '#':
case '%':
case '&':
case '\'':
case '+':
case ',':
case '=':
case '?':
buf_0[v3] = 37;
sprintf(s, "%02X", *v2);
v6 = v3 + 2;
v3 += 3;
buf_0[v4] = s[0];
buf_0[v6] = s[1];
break;
default:
buf_0[v3++] = v1;
break;
}
v1 = *++v2;
}
while ( v1 );
}
else
{
v3 = 0;
}
result = buf_0;
buf_0[v3] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1)
{
char v1; // dl
unsigned __int8 *v2; // r12
int v3; // ebx
int v4; // ebp
char *result; // rax
int v6; // eax
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

v1 = *a1;
if ( *a1 )
{
v2 = (unsigned __int8 *)a1;
v3 = 0;
do
{
v4 = v3 + 1;
switch ( v1 )
{
case ' ':
case '"':
case '#':
case '%':
case '&':
case '\'':
case '+':
case ',':
case '=':
case '?':
buf_0[v3] = 37;
sprintf(s, "%02X", *v2);
v6 = v3 + 2;
v3 += 3;
buf_0[v4] = s[0];
buf_0[v6] = s[1];
break;
default:
buf_0[v3++] = v1;
break;
}
v1 = *++v2;
}
while ( v1 );
}
else
{
v3 = 0;
}
result = buf_0;
buf_0[v3] = 0;
return result;
}

original_code:
char *
encode_url(unsigned char *s)
{
 int i, j;
 static char buf[512];
 char a[3];
 j = 0;
 for (i = 0; s[i]; i++) {
  switch (s[i]) {
  case '\'':
  case '&':
  case '%':
  case '?':
  case '=':
  case '#':
  case '+':
  case ' ':
  case ',':
  case '\"':
   buf[j++] = '%';
   sprintf(a, "%02X", s[i]);
   buf[j++] = a[0];
   buf[j++] = a[1];
   break;
  default:
   buf[j++] = s[i];
  }
 }
 buf[j] = 0;
 return buf;
}

canonical_original_code:
char *encode_url(unsigned char *s)
{
 int i; int j;
 static char buf[512];
 char a[3];
 j = 0;
 for (i = 0; s[i]; i++) {
  switch (s[i]) {
  case '\'':
  case '&':
  case '%':
  case '?':
  case '=':
  case '#':
  case '+':
  case ' ':
  case ',':
  case '\"':
   buf[j++] = '%';
   sprintf(a, "%02X", s[i]);
   buf[j++] = a[0];
   buf[j++] = a[1];
   break;
  default:
   buf[j++] = s[i];
  }
 }
 buf[j] = 0;
 return buf;
}

variable_types:
s
unsigned char *

variable_types: j int

variable_types:
buf
char [512]

variable_types:
a
char [3]


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v5; // eax
__int64 v6; // rcx
char *v7; // rdi
_DWORD *v8; // rsi
char *v9; // rax
unsigned int v10; // er13
const char *v11; // r12
const char *v12; // rax
unsigned int v13; // [rsp+0h] [rbp-14Ch]
char dest[2]; // [rsp+4h] [rbp-148h] BYREF
char nptr[30]; // [rsp+6h] [rbp-146h] BYREF
__int128 v16; // [rsp+24h] [rbp-128h] BYREF
unsigned __int64 v17; // [rsp+34h] [rbp-118h]
char s[112]; // [rsp+44h] [rbp-108h] BYREF
char v19[8]; // [rsp+B4h] [rbp-98h] BYREF
unsigned int v20; // [rsp+BCh] [rbp-90h]
char v21; // [rsp+C3h] [rbp-89h]
char v22[136]; // [rsp+C4h] [rbp-88h] BYREF

v17 = 0LL;
v16 = 0LL;
if ( argc == 3 )
{
v3 = argv[1];
if ( strlen(v3) <= 0x14 )
{
strncpy(dest, argv[2], 0x13uLL);
nptr[17] = 0;
v13 = atoi(nptr);
if ( v13 )
{
sprintf(s, "/home/bbs/boards/%s/.DIR", v3);
if ( _sigsetjmp(&bus_jump, 1) || (signal(7, (__sighandler_t)&sigbus), (unsigned int)mmapfile(s, &v16) == -1) )
{
signal(7, (__sighandler_t)((char *)encode_url + 1));
}
else
{
v5 = Search_Bin(v16, v13, 0LL, (unsigned int)(v17 >> 7) - 1);
if ( v5 >= 0 )
{
v6 = 32LL;
v7 = v19;
v8 = (_DWORD *)(v16 + (v5 << 7));
while ( v6 )
{
*(_DWORD *)v7 = *v8++;
v7 += 4;
--v6;
}
signal(7, (__sighandler_t)((char *)encode_url + 1));
mmapfile(0LL, &v16);
if ( (unsigned __int8)(v22[76] - 1) > 0x12u )
{
if ( (unsigned int)countdb(v22) )
*(&v21 + strlen(v22)) = 0;
v9 = encode_url(v22);
v10 = v20;
v11 = v9;
v12 = (const char *)fh2owner(v19);
printf("%s,%d,%s,%s\n", v12, v10, v11, v22);
}
}
}
}
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v5; // eax
__int64 v6; // rcx
char *v7; // rdi
_DWORD *v8; // rsi
char *v9; // rax
unsigned int v10; // er13
const char *v11; // r12
const char *v12; // rax
unsigned int v13; // [rsp+0h] [rbp-14Ch]
char dest[2]; // [rsp+4h] [rbp-148h] BYREF
char nptr[30]; // [rsp+6h] [rbp-146h] BYREF
__int128 v16; // [rsp+24h] [rbp-128h] BYREF
unsigned __int64 v17; // [rsp+34h] [rbp-118h]
char s[112]; // [rsp+44h] [rbp-108h] BYREF
char v19[8]; // [rsp+B4h] [rbp-98h] BYREF
unsigned int v20; // [rsp+BCh] [rbp-90h]
char v21; // [rsp+C3h] [rbp-89h]
char v22[136]; // [rsp+C4h] [rbp-88h] BYREF

v17 = 0LL;
v16 = 0LL;
if ( argc == 3 )
{
v3 = argv[1];
if ( strlen(v3) <= 0x14 )
{
strncpy(dest, argv[2], 0x13uLL);
nptr[17] = 0;
v13 = atoi(nptr);
if ( v13 )
{
sprintf(s, "/home/bbs/boards/%s/.DIR", v3);
if ( _sigsetjmp(&bus_jump, 1) || (signal(7, (__sighandler_t)&sigbus), (unsigned int)mmapfile(s, &v16) == -1) )
{
signal(7, (__sighandler_t)((char *)encode_url + 1));
}
else
{
v5 = Search_Bin(v16, v13, 0LL, (unsigned int)(v17 >> 7) - 1);
if ( v5 >= 0 )
{
v6 = 32LL;
v7 = v19;
v8 = (_DWORD *)(v16 + (v5 << 7));
while ( v6 )
{
*(_DWORD *)v7 = *v8++;
v7 += 4;
--v6;
}
signal(7, (__sighandler_t)((char *)encode_url + 1));
mmapfile(0LL, &v16);
if ( (unsigned __int8)(v22[76] - 1) > 0x12u )
{
if ( (unsigned int)func1(v22) )
*(&v21 + strlen(v22)) = 0;
v9 = func0(v22);
v10 = v20;
v11 = v9;
v12 = (const char *)fh2owner(v19);
printf("%s,%d,%s,%s\n", v12, v10, v11, v22);
}
}
}
}
}
}
return 0;
}

original_code:
int
main(int argn, char **argv)
{
 int retv, total;
 int filetime;
 char fn[20];
 char path[100];
 struct fileheader fh;
 struct mmapfile mf = { ptr:((void *)0) };
 if (argn != 3 || strlen(argv[1]) > 20)
  return 0;
 strncpy(fn, argv[2], 20);
 fn[19] = 0;
 filetime = atoi(fn + 2);
 if (filetime == 0)
  return 0;
 sprintf(path, "/home/bbs" "/boards/%s/.DIR", argv[1]);
 if (!__sigsetjmp (bus_jump, 1)) { signal(7, sigbus); {
  if (mmapfile(path, &mf) == -1)
   {signal(7, ((__sighandler_t) 1));return (0);};
  total = mf.size / ((int)sizeof(struct fileheader)) - 1;
  retv = Search_Bin(mf.ptr, filetime, 0, total);
  if (retv < 0)
   return 0;
  memcpy(&fh,
         (struct fileheader *) (mf.ptr +
           retv *
           ((int)sizeof(struct fileheader))),
         ((int)sizeof(struct fileheader)));
 }
 } else { {
  {signal(7, ((__sighandler_t) 1));return (0);};
 }
 } signal(7, ((__sighandler_t) 1)); mmapfile(((void *)0), &mf);
 if (fh.sizebyte && fh.sizebyte < 20)
  return 0;
 if (countdb(fh.title)) {
  fh.title[strlen(fh.title) - 1] = 0;
 }
 printf("%s,%d,%s,%s\n", fh2owner(&fh), fh.thread, encode_url(fh.title),
        fh.title);
 return 0;
}

canonical_original_code:
int main(int argn, char **argv)
{
 int retv; int total;
 int filetime;
 char fn[20];
 char path[100];
 struct fileheader fh;
 struct mmapfile mf = { ptr:((void *)0) };
 if (argn != 3 || strlen(argv[1]) > 20)
  return 0;
 strncpy(fn, argv[2], 20);
 fn[19] = 0;
 filetime = atoi(fn + 2);
 if (filetime == 0)
  return 0;
 sprintf(path, "/home/bbs" "/boards/%s/.DIR", argv[1]);
 if (!__sigsetjmp (bus_jump, 1)) { signal(7, sigbus); {
  if (mmapfile(path, &mf) == -1)
   {signal(7, ((void (*)(int)) 1));return (0);};
  total = mf.size / ((int)sizeof(struct fileheader)) - 1;
  retv = Search_Bin(mf.ptr, filetime, 0, total);
  if (retv < 0)
   return 0;
  memcpy(&fh,
         (struct fileheader *) (mf.ptr +
           retv *
           ((int)sizeof(struct fileheader))),
         ((int)sizeof(struct fileheader)));
 }
 } else { {
  {signal(7, ((void (*)(int)) 1));return (0);};
 }
 } signal(7, ((void (*)(int)) 1)); mmapfile(((void *)0), &mf);
 if (fh.sizebyte && fh.sizebyte < 20)
  return 0;
 if (countdb(fh.title)) {
  fh.title[strlen(fh.title) - 1] = 0;
 }
 printf("%s,%d,%s,%s\n", fh2owner(&fh), fh.thread, encode_url(fh.title),
        fh.title);
 return 0;
}

variable_types: argn int

variable_types:
argv
char **

variable_types: retv int

variable_types: total int

variable_types: filetime int

variable_types:
fn
char [20]

variable_types:
path
char [100]

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

variable_types: struct mmapfile { char *ptr; long mtime; unsigned long size; }


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

v1 = brd_num;
if ( brd_num <= 0 )
goto LABEL_8;
v2 = brds;
v3 = 0;
while ( strcasecmp(s1, v2) )
{
++v3;
v2 += 512;
if ( v3 == v1 )
goto LABEL_8;
}
if ( dword_404110[128 * (__int64)v3] && (byte_404118[512 * (__int64)v3] & 0x10) == 0 )
LABEL_8:
result = 0xFFFFFFFFLL;
else
result = (unsigned int)dword_404114[128 * (__int64)v3];
return result;
}

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

v1 = brd_num;
if ( brd_num <= 0 )
goto LABEL_8;
v2 = brds;
v3 = 0;
while ( strcasecmp(s1, v2) )
{
++v3;
v2 += 512;
if ( v3 == v1 )
goto LABEL_8;
}
if ( dword_404110[128 * (__int64)v3] && (byte_404118[512 * (__int64)v3] & 0x10) == 0 )
LABEL_8:
result = 0xFFFFFFFFLL;
else
result = (unsigned int)dword_404114[128 * (__int64)v3];
return result;
}

original_code:
int brd_level(char *brd) {
 int i;
 for(i=0; i<brd_num; i++)
  if(!strcasecmp(brd, brds[i].filename)) {
   if (brds[i].clubnum && !(brds[i].flag&0x10)) return -1;
   return brds[i].level;
  }
 return -1;
}

variable_types:
brd
char *

variable_types: i int


decompiled_code:
__int64 __fastcall is_specialid(char *s1)
{
char *v1; // rbx

v1 = special_userid;
while ( 1 )
{
if ( !*v1 )
return 0LL;
if ( !strcmp(s1, v1) )
break;
v1 += 14;
if ( v1 == &special_userid[700] )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
char *v1; // rbx

v1 = special_userid;
while ( 1 )
{
if ( !*v1 )
return 0LL;
if ( !strcmp(s1, v1) )
break;
v1 += 14;
if ( v1 == &special_userid[700] )
return 0LL;
}
return 1LL;
}

original_code:
int is_specialid(char* userid)
{
 int i;
 for(i=0; i<50; i++){
  if(!special_userid[i][0])
   break;
  if(!strcmp(userid, special_userid[i]))
   return 1;
 }
 return 0;
}

canonical_original_code:
int is_specialid(char *userid)
{
 int i;
 for(i=0; i<50; i++){
  if(!special_userid[i][0])
   break;
  if(!strcmp(userid, special_userid[i]))
   return 1;
 }
 return 0;
}

variable_types:
userid
char *


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

if ( (unsigned int)get_userid(argc, argv, envp) )
printf("unable to open file %s\n", "check_ulevel.special");
v3 = do_check();
if ( v3 == 1 )
{
puts("unable to open file .PASSWDS");
}
else if ( v3 == 2 )
{
printf("unable to write to file .PASSWDS");
}
return 0;
}

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

if ( (unsigned int)func0(argc, argv, envp) )
printf("unable to open file %s\n", "check_ulevel.special");
v3 = func2();
if ( v3 == 1 )
{
puts("unable to open file .PASSWDS");
}
else if ( v3 == 2 )
{
printf("unable to write to file .PASSWDS");
}
return 0;
}

original_code:
int main(int argc, char* argv[])
{
 if(get_userid())
  printf("unable to open file %s\n", "check_ulevel.special");
 switch(do_check()){
  case 1:
   printf("unable to open file .PASSWDS\n");
   break;
  case 2:
   printf("unable to write to file .PASSWDS");
   break;
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(get_userid())
  printf("unable to open file %s\n", "check_ulevel.special");
 switch(do_check()){
  case 1:
   printf("unable to open file .PASSWDS\n");
   break;
  case 2:
   printf("unable to write to file .PASSWDS");
   break;
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


mmapfile

decompiled_code:
void *__fastcall mmapfile(const char *a1)
{
void *v1; // r12
int v2; // eax
int v3; // ebp
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v1 = 0LL;
v2 = open(a1, 0);
if ( v2 >= 0 )
{
v3 = v2;
if ( (int)fstat(v2, &v5) >= 0 && (v5.st_mode & 0xF000) == 0x8000 && v5.st_size > 0 )
v1 = mmap(0LL, v5.st_size, 1, 1, v3, 0LL);
close(v3);
}
return v1;
}

canonical_decompiled_code:
void *__fastcall func7(const char *a1)
{
void *v1; // r12
int v2; // eax
int v3; // ebp
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v1 = 0LL;
v2 = open(a1, 0);
if ( v2 >= 0 )
{
v3 = v2;
if ( (int)func18(v2, &v5) >= 0 && (v5.st_mode & 0xF000) == 0x8000 && v5.st_size > 0 )
v1 = mmap(0LL, v5.st_size, 1, 1, v3, 0LL);
close(v3);
}
return v1;
}

original_code:
char *
mmapfile(char *fn)
{
 char *ptr;
 int fd;
 struct stat st;
 fd = open(fn, 00);
 if (fd < 0)
  return ((void *)0);
 if (fstat(fd, &st) < 0) {
  close(fd);
  return ((void *)0);
 }
 if (!((((st.st_mode)) & 0170000) == (0100000))) {
  close(fd);
  return ((void *)0);
 }
 if (st.st_size <= 0) {
  close(fd);
  return ((void *)0);
 }
 ptr = mmap(((void *)0), st.st_size, 0x1, 0x01, fd, 0);
 close(fd);
 return ptr;
}

canonical_original_code:
char *mmapfile(char *fn)
{
 char *ptr;
 int fd;
 struct stat st;
 fd = open(fn, 00);
 if (fd < 0)
  return ((void *)0);
 if (fstat(fd, &st) < 0) {
  close(fd);
  return ((void *)0);
 }
 if (!((((st.st_mode)) & 0170000) == (0100000))) {
  close(fd);
  return ((void *)0);
 }
 if (st.st_size <= 0) {
  close(fd);
  return ((void *)0);
 }
 ptr = mmap(((void *)0), st.st_size, 0x1, 0x01, fd, 0);
 close(fd);
 return ptr;
}

variable_types:
fn
char *

variable_types:
ptr
char *

variable_types: fd int

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


decompiled_code:
int __fastcall compare_word(char *s1, char *src)
{
int v2; // eax
bool v3; // cc
int v4; // edx
int v5; // eax
size_t v6; // r12
int v7; // ebx
__int64 v8; // rax
char *v10; // rax
char *v11; // r8
char v12[152]; // [rsp+0h] [rbp-98h] BYREF

v2 = strlen(s1);
v3 = v2 <= 99;
v4 = v2;
v5 = 99;
if ( v3 )
v5 = v4;
v6 = 0LL;
if ( v4 > 0 )
{
while ( 1 )
{
v7 = v6;
if ( src[v6] == 1 )
break;
v7 = ++v6;
if ( v5 <= (int)v6 )
{
v6 = v7;
v10 = strncpy(v12, src, v7);
v12[v7] = 0;
v11 = v10;
goto LABEL_8;
}
}
v11 = strncpy(v12, src, v6);
v12[(int)v6] = 0;
if ( !(_DWORD)v6 )
return strncasecmp(s1, v11, v6);
LABEL_8:
v8 = 0LL;
do
v11[v8++] += 30;
while ( v7 > (int)v8 );
}
else
{
v12[0] = 0;
v11 = v12;
}
return strncasecmp(s1, v11, v6);
}

canonical_decompiled_code:
int __fastcall func8(char *s1, char *src)
{
int v2; // eax
bool v3; // cc
int v4; // edx
int v5; // eax
size_t v6; // r12
int v7; // ebx
__int64 v8; // rax
char *v10; // rax
char *v11; // r8
char v12[152]; // [rsp+0h] [rbp-98h] BYREF

v2 = strlen(s1);
v3 = v2 <= 99;
v4 = v2;
v5 = 99;
if ( v3 )
v5 = v4;
v6 = 0LL;
if ( v4 > 0 )
{
while ( 1 )
{
v7 = v6;
if ( src[v6] == 1 )
break;
v7 = ++v6;
if ( v5 <= (int)v6 )
{
v6 = v7;
v10 = strncpy(v12, src, v7);
v12[v7] = 0;
v11 = v10;
goto LABEL_8;
}
}
v11 = strncpy(v12, src, v6);
v12[(int)v6] = 0;
if ( !(_DWORD)v6 )
return strncasecmp(s1, v11, v6);
LABEL_8:
v8 = 0LL;
do
v11[v8++] += 30;
while ( v7 > (int)v8 );
}
else
{
v12[0] = 0;
v11 = v12;
}
return strncasecmp(s1, v11, v6);
}

original_code:
int
compare_word(char *word, char *item)
{
 char nword[100];
 int i, n = strlen(word);
 if (n >= 100)
  n = 99;
 for (i = 0; i < n && item[i] != 1; i++) ;
 n = i;
 strncpy(nword, item, n);
 nword[n] = 0;
 for (i = 0; i < n; i++)
  nword[i] += 30;
 return strncasecmp(word, nword, n);
}

canonical_original_code:
int compare_word(char *word, char *item)
{
 char nword[100];
 int i; int n = strlen(word);
 if (n >= 100)
  n = 99;
 for (i = 0; i < n && item[i] != 1; i++) ;
 n = i;
 strncpy(nword, item, n);
 nword[n] = 0;
 for (i = 0; i < n; i++)
  nword[i] += 30;
 return strncasecmp(word, nword, n);
}

variable_types:
word
char *

variable_types:
item
char *

variable_types:
nword
char [100]

variable_types: n int


decompiled_code:
char *__fastcall cat_item(const char *a1, __int64 a2, int a3)
{
size_t v5; // rdi
__int64 v6; // rax
char v7; // dl
__int64 v8; // rcx
int v9; // eax
__int64 v10; // rdx
char *result; // rax
char v12[136]; // [rsp+0h] [rbp-88h] BYREF

v5 = strlen(a1);
v6 = 0LL;
while ( 1 )
{
while ( 1 )
{
v7 = *(_BYTE *)(a2 + v6);
v8 = (int)v6;
if ( v7 )
break;
v12[v6++] = 32;
if ( v6 == 98 )
goto LABEL_6;
}
if ( v7 == 1 )
break;
v12[v6++] = v7 + 30;
if ( v6 == 98 )
{
LABEL_6:
v9 = 99;
v8 = 98LL;
goto LABEL_8;
}
}
v9 = v6 + 1;
LABEL_8:
v10 = v9;
result = (char *)(unsigned int)(v9 + v5 + 1);
v12[v8] = 10;
v12[v10] = 0;
if ( (int)result < a3 )
result = strcpy((char *)&a1[v5], v12);
return result;
}

canonical_decompiled_code:
char *__fastcall func9(const char *a1, __int64 a2, int a3)
{
size_t v5; // rdi
__int64 v6; // rax
char v7; // dl
__int64 v8; // rcx
int v9; // eax
__int64 v10; // rdx
char *result; // rax
char v12[136]; // [rsp+0h] [rbp-88h] BYREF

v5 = strlen(a1);
v6 = 0LL;
while ( 1 )
{
while ( 1 )
{
v7 = *(_BYTE *)(a2 + v6);
v8 = (int)v6;
if ( v7 )
break;
v12[v6++] = 32;
if ( v6 == 98 )
goto LABEL_6;
}
if ( v7 == 1 )
break;
v12[v6++] = v7 + 30;
if ( v6 == 98 )
{
LABEL_6:
v9 = 99;
v8 = 98LL;
goto LABEL_8;
}
}
v9 = v6 + 1;
LABEL_8:
v10 = v9;
result = (char *)(unsigned int)(v9 + v5 + 1);
v12[v8] = 10;
v12[v10] = 0;
if ( (int)result < a3 )
result = strcpy((char *)&a1[v5], v12);
return result;
}

original_code:
void
cat_item(char *str, char *item, int maxlen)
{
 char nitem[100];
 int i, l = strlen(str);
 for (i = 0; i < 98; i++) {
  if (item[i] == 0) {
   nitem[i] = ' ';
  } else if (item[i] == 1) {
   break;
  } else
   nitem[i] = item[i] + 30;
 }
 nitem[i++] = '\n';
 nitem[i] = 0;
 if (l + i + 1 >= maxlen)
  return;
 strcat(str, nitem);
 return;
}

canonical_original_code:
void cat_item(char *str, char *item, int maxlen)
{
 char nitem[100];
 int i; int l = strlen(str);
 for (i = 0; i < 98; i++) {
  if (item[i] == 0) {
   nitem[i] = ' ';
  } else if (item[i] == 1) {
   break;
  } else
   nitem[i] = item[i] + 30;
 }
 nitem[i++] = '\n';
 nitem[i] = 0;
 if (l + i + 1 >= maxlen)
  return;
 strcat(str, nitem);
 return;
}

variable_types:
str
char *

variable_types: maxlen int

variable_types:
nitem
char [100]

variable_types: l int


getsenv

decompiled_code:
char *__fastcall getsenv(const char *a1)
{
char *result; // rax

result = getenv(a1);
if ( !result )
result = (_BYTE *)("&" + 1);
return result;
}

canonical_decompiled_code:
char *__fastcall func11(const char *a1)
{
char *result; // rax

result = getenv(a1);
if ( !result )
result = (_BYTE *)("&" + 1);
return result;
}

original_code:
char *
getsenv(char *s)
{
 char *t = getenv(s);
 if (t)
  return t;
 return "";
}

canonical_original_code:
char *getsenv(char *s)
{
 char *t = getenv(s);
 if (t)
  return t;
 return "";
}

variable_types:
s
char *

variable_types:
t
char *


strsncpy

decompiled_code:
void __fastcall strsncpy(char *dest, char *src, int a3)
{
int v4; // ebx

if ( a3 >= 0 )
{
v4 = strlen(src) + 1;
if ( v4 > a3 )
v4 = a3;
strncpy(dest, src, v4 - 1);
dest[v4 - 1] = 0;
}
}

canonical_decompiled_code:
void __fastcall func14(char *dest, char *src, int a3)
{
int v4; // ebx

if ( a3 >= 0 )
{
v4 = strlen(src) + 1;
if ( v4 > a3 )
v4 = a3;
strncpy(dest, src, v4 - 1);
dest[v4 - 1] = 0;
}
}

original_code:
void
strsncpy(char *s1, char *s2, int n)
{
 int l = strlen(s2);
 if (n < 0)
  return;
 if (n > l + 1)
  n = l + 1;
 strncpy(s1, s2, n - 1);
 s1[n - 1] = 0;
}


mmapfile

canonical_decompiled_code:
void *__fastcall func7(const char *a1)
{
void *v1; // r12
int v2; // eax
int v3; // ebp
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

v1 = 0LL;
v2 = open(a1, 0);
if ( v2 >= 0 )
{
v3 = v2;
if ( (int)func14(v2, &v5) >= 0 && (v5.st_mode & 0xF000) == 0x8000 && v5.st_size > 0 )
v1 = mmap(0LL, v5.st_size, 1, 1, v3, 0LL);
close(v3);
}
return v1;
}

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


report

decompiled_code:
// attributes: thunk
int report(const char *s)
{
return puts(s);
}

canonical_decompiled_code:
int func0(const char *s)
{
return puts(s);
}

original_code:
int
report()
{
 return;
}

canonical_original_code:
int report()
{
 return;
}


decompiled_code:
void report()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}


getsenv

decompiled_code:
char *__fastcall getsenv(const char *a1)
{
char *result; // rax

result = getenv(a1);
if ( !result )
result = (char *)&unk_1801;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1)
{
char *result; // rax

result = getenv(a1);
if ( !result )
result = (char *)&unk_1801;
return result;
}


strsncpy

canonical_decompiled_code:
void __fastcall func0(char *dest, char *src, int a3)
{
int v4; // ebx

if ( a3 >= 0 )
{
v4 = strlen(src) + 1;
if ( v4 > a3 )
v4 = a3;
strncpy(dest, src, v4 - 1);
dest[v4 - 1] = 0;
}
}

canonical_original_code:
void strsncpy(char *s1, char *s2, int n)
{
 int l = strlen(s2);
 if (n < 0)
  return;
 if (n > l + 1)
  n = l + 1;
 strncpy(s1, s2, n - 1);
 s1[n - 1] = 0;
}


mmapfile

decompiled_code:
int __fastcall mmapfile(char *file, __int64 a2)
{
int result; // eax
void *v5; // rdi
size_t v6; // rsi
__time_t v7; // rax
void *v8; // rdi
size_t v9; // rsi
int v10; // eax
int v11; // ebp
struct stat v12; // [rsp+0h] [rbp-A8h] BYREF

if ( !file )
{
v8 = *(void **)a2;
if ( !*(_QWORD *)a2 )
return 0;
v9 = *(_QWORD *)(a2 + 16);
if ( v9 )
LABEL_20:
munmap(v8, v9);
LABEL_14:
*(_QWORD *)a2 = 0LL;
return -(file != 0LL);
}
result = stat(file, &v12);
if ( result == -1 )
{
v8 = *(void **)a2;
if ( !*(_QWORD *)a2 )
return result;
v9 = *(_QWORD *)(a2 + 16);
if ( v9 )
goto LABEL_20;
goto LABEL_14;
}
v5 = *(void **)a2;
if ( *(_QWORD *)a2 )
{
if ( v12.st_mtim.tv_sec == *(_QWORD *)(a2 + 8) )
return 0;
v6 = *(_QWORD *)(a2 + 16);
if ( v6 )
munmap(v5, v6);
*(_QWORD *)a2 = 0LL;
}
if ( !v12.st_size )
{
v7 = v12.st_mtim.tv_sec;
*(_QWORD *)a2 = &c_2;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 8) = v7;
return 0;
}
v10 = open(file, 0);
v11 = v10;
if ( v10 < 0 || (*(_QWORD *)a2 = mmap(0LL, v12.st_size, 1, 1, v10, 0LL), close(v11), *(_QWORD *)a2 == -1LL) )
{
*(_QWORD *)a2 = 0LL;
result = -1;
}
else
{
*(_QWORD *)(a2 + 8) = v12.st_mtim.tv_sec;
*(_QWORD *)(a2 + 16) = v12.st_size;
result = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(char *file, __int64 a2)
{
int result; // eax
void *v5; // rdi
size_t v6; // rsi
__time_t v7; // rax
void *v8; // rdi
size_t v9; // rsi
int v10; // eax
int v11; // ebp
struct stat v12; // [rsp+0h] [rbp-A8h] BYREF

if ( !file )
{
v8 = *(void **)a2;
if ( !*(_QWORD *)a2 )
return 0;
v9 = *(_QWORD *)(a2 + 16);
if ( v9 )
LABEL_20:
munmap(v8, v9);
LABEL_14:
*(_QWORD *)a2 = 0LL;
return -(file != 0LL);
}
result = stat(file, &v12);
if ( result == -1 )
{
v8 = *(void **)a2;
if ( !*(_QWORD *)a2 )
return result;
v9 = *(_QWORD *)(a2 + 16);
if ( v9 )
goto LABEL_20;
goto LABEL_14;
}
v5 = *(void **)a2;
if ( *(_QWORD *)a2 )
{
if ( v12.st_mtim.tv_sec == *(_QWORD *)(a2 + 8) )
return 0;
v6 = *(_QWORD *)(a2 + 16);
if ( v6 )
munmap(v5, v6);
*(_QWORD *)a2 = 0LL;
}
if ( !v12.st_size )
{
v7 = v12.st_mtim.tv_sec;
*(_QWORD *)a2 = &c_2;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 8) = v7;
return 0;
}
v10 = open(file, 0);
v11 = v10;
if ( v10 < 0 || (*(_QWORD *)a2 = mmap(0LL, v12.st_size, 1, 1, v10, 0LL), close(v11), *(_QWORD *)a2 == -1LL) )
{
*(_QWORD *)a2 = 0LL;
result = -1;
}
else
{
*(_QWORD *)(a2 + 8) = v12.st_mtim.tv_sec;
*(_QWORD *)(a2 + 16) = v12.st_size;
result = 0;
}
return result;
}


repo: defuse/gadgetrie

decompiled_code:
void __fastcall gadget_list_destroy(_QWORD *a1)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1)
{
_QWORD *v1; // rbx
void *v2; // rdi

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = v1;
v1 = (_QWORD *)v1[1];
free(v2);
}
while ( v1 );
}
}

original_code:
void gadget_list_destroy(gadget_list_t *list)
{
    gadget_list_item_t *cursor = list->head;
    while (cursor != ((void *)0)) {
        gadget_list_item_t *to_free = cursor;
        cursor = cursor->next;
        free(to_free);
    }
}

canonical_original_code:
void gadget_list_destroy(struct GadgetList *list)
{
    struct GadgetListItem *cursor = list->head;
    while (cursor != ((void *)0)) {
        struct GadgetListItem *to_free = cursor;
        cursor = cursor->next;
        free(to_free);
    }
}

variable_types: struct GadgetList { struct GadgetListItem { struct GadgetTree { unsigned char instr[8]; unsigned long instr_len; unsigned int virtual_address; struct GadgetList previous; struct GadgetTree *next; } *gadget; struct GadgetListItem *next; } *head; } *

variable_types: struct GadgetListItem { struct GadgetTree { unsigned char instr[8]; unsigned long instr_len; unsigned int virtual_address; struct GadgetList { struct GadgetListItem *head; } previous; struct GadgetTree *next; } *gadget; struct GadgetListItem *next; } *

user_defined_types: struct GadgetListItem { struct GadgetTree *gadget; struct GadgetListItem *next; }


decompiled_code:
_BOOL8 __fastcall has_zero_byte(unsigned int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (_BYTE)a1 && (a1 & 0xFF00) != 0 && (a1 & 0xFF0000) != 0 )
result = HIBYTE(a1) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (_BYTE)a1 && (a1 & 0xFF00) != 0 && (a1 & 0xFF0000) != 0 )
result = HIBYTE(a1) == 0;
return result;
}

variable_types:
n
unsigned int


rstrip

decompiled_code:
__int64 __fastcall rstrip(const char *a1)
{
int v1; // eax
bool v2; // sf
int v3; // ebx
__int64 result; // rax
const unsigned __int16 *v5; // rcx
int v6; // edx

v1 = strlen(a1);
v2 = v1 - 1 < 0;
v3 = v1 - 1;
result = v1 - 1;
if ( !v2 )
{
v5 = *_ctype_b_loc();
result = v3;
while ( (v5[a1[result]] & 0x2000) != 0 )
{
v6 = --result;
if ( (_DWORD)result == -1 )
{
result = v6;
a1[v6 + 1] = 0;
return result;
}
}
}
a1[result + 1] = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
int v1; // eax
bool v2; // sf
int v3; // ebx
__int64 result; // rax
const unsigned __int16 *v5; // rcx
int v6; // edx

v1 = strlen(a1);
v2 = v1 - 1 < 0;
v3 = v1 - 1;
result = v1 - 1;
if ( !v2 )
{
v5 = *_ctype_b_loc();
result = v3;
while ( (v5[a1[result]] & 0x2000) != 0 )
{
v6 = --result;
if ( (_DWORD)result == -1 )
{
result = v6;
a1[v6 + 1] = 0;
return result;
}
}
}
a1[result + 1] = 0;
return result;
}

original_code:
void rstrip(char *text)
{
    int end;
    for (end = strlen(text) - 1; end >= 0 && ((*__ctype_b_loc ())[(int) ((text[end]))] & (unsigned short int) _ISspace); end--)
        ;
    text[end+1] = 0;
}

canonical_original_code:
void rstrip(char *text)
{
    int end;
    for (end = strlen(text) - 1; end >= 0 && ((*__ctype_b_loc ())[(int) ((text[end]))] & (unsigned short) _ISspace); end--)
        ;
    text[end+1] = 0;
}

variable_types:
text
char *

variable_types: end int


decompiled_code:
__int64 __fastcall tab_to_space(_BYTE *a1)
{
__int64 result; // rax

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 9 )
*a1 = 32;
++a1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1)
{
__int64 result; // rax

while ( 1 )
{
result = (unsigned __int8)*a1;
if ( !(_BYTE)result )
break;
if ( (_BYTE)result == 9 )
*a1 = 32;
++a1;
}
return result;
}

original_code:
void tab_to_space(char *text)
{
    while (*text != 0) {
        if (*text == '\t')
            *text = ' ';
        text++;
    }
}