decompiled_code:
__int64 __fastcall delete_old_junk(char *a1)
{
unsigned int v1; // ebp
time_t v3; // r14
int v4; // er13
int v5; // ebx
int i; // eax
int v7; // eax
unsigned int v8; // er15
unsigned int v9; // er14
char v10; // bl
const char *v11; // rax
int j; // eax
unsigned int v13; // [rsp+Ch] [rbp-24Ch]
char v14[80]; // [rsp+10h] [rbp-248h] BYREF
struct stat v15; // [rsp+60h] [rbp-1F8h] BYREF
time_t timer; // [rsp+F8h] [rbp-160h] BYREF
char s[80]; // [rsp+100h] [rbp-158h] BYREF
char file[80]; // [rsp+150h] [rbp-108h] BYREF
char buf[12]; // [rsp+1A0h] [rbp-B8h] BYREF
int v20; // [rsp+1ACh] [rbp-ACh]
char v21; // [rsp+1FFh] [rbp-59h]

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

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
unsigned int v1; // ebp
time_t v3; // r14
int v4; // er13
int v5; // ebx
int i; // eax
int v7; // eax
unsigned int v8; // er15
unsigned int v9; // er14
char v10; // bl
const char *v11; // rax
int j; // eax
unsigned int v13; // [rsp+Ch] [rbp-24Ch]
char v14[80]; // [rsp+10h] [rbp-248h] BYREF
struct stat v15; // [rsp+60h] [rbp-1F8h] BYREF
time_t timer; // [rsp+F8h] [rbp-160h] BYREF
char s[80]; // [rsp+100h] [rbp-158h] BYREF
char file[80]; // [rsp+150h] [rbp-108h] BYREF
char buf[12]; // [rsp+1A0h] [rbp-B8h] BYREF
int v20; // [rsp+1ACh] [rbp-ACh]
char v21; // [rsp+1FFh] [rbp-59h]

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


repo: deepurple/bbssrc

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]

return_type: int


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; // ebx
char *v6; // rax
char *v7; // rax
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);
v6 = ctime(&timer);
printf("FAILED! %s", v6);
}
else
{
time(&timer);
v7 = ctime(&timer);
printf("....OK. %s", v7);
}
sync();
}
}
flock(v5, 8);
close(v5);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
int v4; // eax
int v5; // ebx
char *v6; // rax
char *v7; // rax
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);
v6 = ctime(&timer);
printf("FAILED! %s", v6);
}
else
{
time(&timer);
v7 = ctime(&timer);
printf("....OK. %s", v7);
}
sync();
}
}
flock(v5, 8);
close(v5);
v5 = 0;
}
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_lflag = v1.c_lflag & 0xFFFFFEFE | 0x5A;
v1.c_cc[11] = 0;
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_lflag = v1.c_lflag & 0xFFFFFEFE | 0x5A;
v1.c_cc[11] = 0;
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; // ebp
__int64 v3; // r14
int v4; // er12
__int64 v5; // r13
int v6; // er15
int v7; // ebx
int result; // eax
fd_set writefds; // [rsp+10h] [rbp-238h] BYREF
fd_set readfds; // [rsp+90h] [rbp-1B8h] BYREF
char buf[312]; // [rsp+110h] [rbp-138h] BYREF

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

canonical_decompiled_code:
int __fastcall func8(int a1, int a2)
{
int v2; // ebp
__int64 v3; // r14
int v4; // er12
__int64 v5; // r13
int v6; // er15
int v7; // ebx
int result; // eax
fd_set writefds; // [rsp+10h] [rbp-238h] BYREF
fd_set readfds; // [rsp+90h] [rbp-1B8h] BYREF
char buf[312]; // [rsp+110h] [rbp-138h] BYREF

memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
v2 = a1 / 64;
v3 = 1LL << (a1 % 64);
v4 = a2 / 64;
v5 = 1LL << (a2 % 64);
v6 = a2 + 1;
if ( a1 > a2 )
v6 = a1 + 1;
v7 = 0;
while ( 1 )
{
if ( v7 <= 255 )
readfds.fds_bits[v2] |= v3;
if ( v7 )
writefds.fds_bits[v4] |= v5;
result = select(v6, &readfds, &writefds, 0LL, 0LL);
if ( result < 0 )
break;
if ( (readfds.fds_bits[v2] & v3) != 0 )
{
result = read(a1, &buf[v7], 256LL - v7);
if ( result <= 0 )
return result;
v7 += result;
readfds.fds_bits[v2] &= ~v3;
}
if ( (writefds.fds_bits[v4] & v5) != 0 )
{
result = write(a2, buf, v7);
if ( result <= 0 )
return result;
v7 -= result;
memmove(buf, &buf[result], v7);
writefds.fds_bits[v4] &= ~v5;
}
}
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; // ebx
__pid_t v5; // eax
__pid_t v6; // eax
char v7[28]; // [rsp+0h] [rbp-28h] BYREF
int amaster[3]; // [rsp+1Ch] [rbp-Ch] BYREF

setsid();
result = forkpty(amaster, v7, 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(amaster[0], 1);
kill(v4, 9);
}
else
{
pipedata(0, amaster[0]);
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; // ebx
__pid_t v5; // eax
__pid_t v6; // eax
char v7[28]; // [rsp+0h] [rbp-28h] BYREF
int amaster[3]; // [rsp+1Ch] [rbp-Ch] BYREF

setsid();
result = forkpty(amaster, v7, 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(amaster[0], 1);
kill(v4, 9);
}
else
{
func8(0, amaster[0]);
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

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()
{
char *v0; // rbx
int v1; // ebp
int result; // eax

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

canonical_decompiled_code:
int func8()
{
char *v0; // rbx
int v1; // ebp
int result; // eax

if ( num > 0 )
{
v0 = alist;
v1 = 0;
do
{
result = printf("%10d %10d %s\n", *((unsigned int *)v0 + 6), *((unsigned int *)v0 + 7), v0);
++v1;
v0 += 32;
}
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
int v8; // ebx
_BYTE v10[25032]; // [rsp+0h] [rbp-61C8h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = read(v2, v10, 0x61A8uLL);
close(v3);
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
v5 = open(a2, 65, 432LL);
v6 = v5;
if ( v5 < 0 )
return 0xFFFFFFFFLL;
v7 = write(v5, v10, v4);
v8 = v7;
if ( v7 > 0 )
ftruncate(v6, v7);
close(v6);
return (unsigned int)-(v8 <= 0);
}

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
int v8; // ebx
_BYTE v10[25032]; // [rsp+0h] [rbp-61C8h] BYREF

v2 = open(a1, 0);
if ( v2 < 0 )
return 0xFFFFFFFFLL;
v3 = v2;
v4 = read(v2, v10, 0x61A8uLL);
close(v3);
if ( v4 <= 0 )
return 0xFFFFFFFFLL;
v5 = open(a2, 65, 432LL);
v6 = v5;
if ( v5 < 0 )
return 0xFFFFFFFFLL;
v7 = write(v5, v10, v4);
v8 = v7;
if ( v7 > 0 )
ftruncate(v6, v7);
close(v6);
return (unsigned int)-(v8 <= 0);
}

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]


decompiled_code:
__int64 __fastcall compute_user_value(__int64 a1)
{
__int64 result; // rax
int v2; // edx

result = 999LL;
if ( (*(_BYTE *)(a1 + 233) & 1) == 0 && strcmp((const char *)a1, "guest") )
{
v2 = (int)(time(0LL) - *(_DWORD *)(a1 + 240)) / 60;
if ( !strcmp((const char *)a1, "new") )
{
result = (unsigned int)(60 * (30 - v2));
}
else if ( *(_DWORD *)(a1 + 40) <= 3u )
{
result = (unsigned int)((21600 - v2) / 1440);
}
else if ( (*(_BYTE *)(a1 + 232) & 0x10) != 0 )
{
result = (unsigned int)((172800 - v2) / 1440);
}
else
{
result = (unsigned int)((43200 - v2) / 1440);
}
}
return result;
}

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

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

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

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

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

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

variable_types:
s
unsigned char *

variable_types: flag int

return_type: char *


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

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

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

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

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

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

variable_types:
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;
while ( !strstr(haystack, v2) )
{
++v3;
v2 += 60;
if ( v1 == v3 )
{
v3 = v1;
break;
}
}
}
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;
while ( !strstr(haystack, v2) )
{
++v3;
v2 += 60;
if ( v1 == v3 )
{
v3 = v1;
break;
}
}
}
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];
after.tv_sec -= before[0];
v1 = after.tv_usec - before[1];
after.tv_usec = v1;
if ( v1 < 0 )
{
after.tv_sec = v0 - 1;
after.tv_usec = v1 + 1000000;
}
return (float)((float)(int)after.tv_usec / 1000000.0) + (float)SLODWORD(after.tv_sec);
}

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

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

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()
{
}

return_type: void


fixabnormalfn

decompiled_code:
int __fastcall fixabnormalfn(char *src, char *s)
{
int result; // eax
const unsigned __int16 *v5; // rdx
size_t v6; // rdx
unsigned int v7; // er12
char v8[256]; // [rsp+0h] [rbp-218h] BYREF
char dest[280]; // [rsp+100h] [rbp-118h] BYREF

if ( !memcmp(s, &unk_58968, 2uLL) || (result = 0, !memcmp(s, &unk_5896B, 2uLL)) )
{
v5 = *_ctype_b_loc();
result = 0;
if ( (v5[s[3]] & 0x800) != 0 )
{
v6 = strlen(s);
result = 0;
if ( v6 <= 0x13 && s[(int)v6 - 1] != 65 )
{
v7 = atoi(s + 2) + 1;
sprintf(v8, "%s/%s", src, s);
strcpy(dest, src);
if ( (int)trycreatefile(dest, "M.%d.A", v7) <= 0 )
result = -1;
else
result = rename(v8, dest);
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *src, char *s)
{
int result; // eax
const unsigned __int16 *v5; // rdx
size_t v6; // rdx
unsigned int v7; // er12
char v8[256]; // [rsp+0h] [rbp-218h] BYREF
char dest[280]; // [rsp+100h] [rbp-118h] BYREF

if ( !memcmp(s, &unk_58968, 2uLL) || (result = 0, !memcmp(s, &unk_5896B, 2uLL)) )
{
v5 = *_ctype_b_loc();
result = 0;
if ( (v5[s[3]] & 0x800) != 0 )
{
v6 = strlen(s);
result = 0;
if ( v6 <= 0x13 && s[(int)v6 - 1] != 65 )
{
v7 = atoi(s + 2) + 1;
sprintf(v8, "%s/%s", src, s);
strcpy(dest, src);
if ( (int)trycreatefile(dest, "M.%d.A", v7) <= 0 )
result = -1;
else
result = rename(v8, dest);
}
}
}
return result;
}

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 *

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 find_lost_mail(char *src)
{
int *v1; // rax
char v3[1032]; // [rsp+0h] [rbp-408h] BYREF

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

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

v1 = nfile;
do
*v1++ = 0;
while ( v1 != (int *)(unsigned int)((_DWORD)nfile + 120) );
otherfile[0] = 0;
if ( (int)func4(src) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "%s/.DIR", src);
if ( func7(v3) && (int)func5((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "%s/.DIGEST", src);
if ( func7(v3) && (int)func5((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "%s/.DELETED", src);
if ( func7(v3) && (int)func5((__int64)v3) < 0 )
return 0xFFFFFFFFLL;
sprintf(v3, "%s/.JUNK", src);
if ( func7(v3) && (int)func5((__int64)v3) < 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)
{
char *v3; // rax
unsigned int i; // er12
DIR *v5; // rbp
struct dirent *v6; // rax
const char *v7; // rbx
struct stat v9; // [rsp+0h] [rbp-8A8h] BYREF
char file[1024]; // [rsp+90h] [rbp-818h] BYREF
char s[1048]; // [rsp+490h] [rbp-418h] BYREF

chdir("/home/bbs");
LODWORD(nowtime) = time(0LL);
puts("find_lost_mail is running~");
v3 = ctime(&nowtime);
printf("\x1B[1mbbs home=%s now time = %s\x1B[0m\n", "/home/bbs", v3);
for ( i = 65; i != 91; ++i )
{
sprintf(s, "/home/bbs/mail/%c", i);
printf("processing %s\n", s);
v5 = opendir(s);
if ( v5 )
{
while ( 1 )
{
v6 = readdir(v5);
if ( !v6 )
break;
if ( 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 )
printf(" %s failed\n", v7);
}
}
closedir(v5);
}
}
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)
{
char *v3; // rax
unsigned int i; // er12
DIR *v5; // rbp
struct dirent *v6; // rax
const char *v7; // rbx
struct stat v9; // [rsp+0h] [rbp-8A8h] BYREF
char file[1024]; // [rsp+90h] [rbp-818h] BYREF
char s[1048]; // [rsp+490h] [rbp-418h] BYREF

chdir("/home/bbs");
LODWORD(nowtime) = time(0LL);
puts("find_lost_mail is running~");
v3 = ctime(&nowtime);
printf("\x1B[1mbbs home=%s now time = %s\x1B[0m\n", "/home/bbs", v3);
for ( i = 65; i != 91; ++i )
{
sprintf(s, "/home/bbs/mail/%c", i);
printf("processing %s\n", s);
v5 = opendir(s);
if ( v5 )
{
while ( 1 )
{
v6 = readdir(v5);
if ( !v6 )
break;
if ( 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 )
printf(" %s failed\n", v7);
}
}
closedir(v5);
}
}
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] | free_addr[v1] ^ a1) )
{
if ( ++v1 == free_num )
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] | free_addr[v1] ^ a1) )
{
if ( ++v1 == free_num )
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)
{
char *v1; // rdx
_BOOL8 result; // rax
char *v3; // rdx
char *v4; // rdx

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

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *haystack)
{
char *v1; // rdx
_BOOL8 result; // rax
char *v3; // rdx
char *v4; // rdx

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

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
unsigned int v2; // edx
unsigned int v3; // eax

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v3 = (unsigned int)v1 >> 31;
if ( v2 )
v3 = 0;
v2 = v3;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char v1; // al
unsigned int v2; // edx
unsigned int v3; // eax

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v3 = (unsigned int)v1 >> 31;
if ( v2 )
v3 = 0;
v2 = v3;
v1 = *++a1;
}
while ( *a1 );
return 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; // rbp
int v3; // ebx
int v4; // eax
char s[27]; // [rsp+Dh] [rbp-1Bh] BYREF

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

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

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

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; // rbp
int v5; // eax
_DWORD *v6; // rsi
__int64 v7; // rcx
char *v8; // rdi
char *v9; // rbx
unsigned int v10; // ebp
const char *v11; // rax
unsigned int v12; // [rsp+Ch] [rbp-14Ch]
__int64 v13[2]; // [rsp+10h] [rbp-148h] BYREF
unsigned __int64 v14; // [rsp+20h] [rbp-138h]
char v15[8]; // [rsp+30h] [rbp-128h] BYREF
unsigned int v16; // [rsp+38h] [rbp-120h]
char v17; // [rsp+3Fh] [rbp-119h]
char v18[112]; // [rsp+40h] [rbp-118h] BYREF
char s[112]; // [rsp+B0h] [rbp-A8h] BYREF
char dest[2]; // [rsp+120h] [rbp-38h] BYREF
char nptr[54]; // [rsp+122h] [rbp-36h] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v5; // eax
_DWORD *v6; // rsi
__int64 v7; // rcx
char *v8; // rdi
char *v9; // rbx
unsigned int v10; // ebp
const char *v11; // rax
unsigned int v12; // [rsp+Ch] [rbp-14Ch]
__int64 v13[2]; // [rsp+10h] [rbp-148h] BYREF
unsigned __int64 v14; // [rsp+20h] [rbp-138h]
char v15[8]; // [rsp+30h] [rbp-128h] BYREF
unsigned int v16; // [rsp+38h] [rbp-120h]
char v17; // [rsp+3Fh] [rbp-119h]
char v18[112]; // [rsp+40h] [rbp-118h] BYREF
char s[112]; // [rsp+B0h] [rbp-A8h] BYREF
char dest[2]; // [rsp+120h] [rbp-38h] BYREF
char nptr[54]; // [rsp+122h] [rbp-36h] BYREF

v13[0] = 0LL;
v13[1] = 0LL;
v14 = 0LL;
if ( argc == 3 )
{
v3 = argv[1];
if ( strlen(v3) <= 0x14 )
{
strncpy(dest, argv[2], 0x13uLL);
nptr[17] = 0;
v12 = atoi(nptr);
if ( v12 )
{
sprintf(s, "/home/bbs/boards/%s/.DIR", v3);
if ( _sigsetjmp(&bus_jump, 1) )
{
signal(7, handler);
}
else
{
signal(7, (__sighandler_t)&sigbus);
if ( (unsigned int)mmapfile(s, v13) == -1 )
{
signal(7, handler);
}
else
{
v5 = Search_Bin(v13[0], v12, 0LL, (unsigned int)(v14 >> 7) - 1);
if ( v5 >= 0 )
{
v6 = (_DWORD *)(v13[0] + (v5 << 7));
v7 = 32LL;
v8 = v15;
while ( v7 )
{
*(_DWORD *)v8 = *v6++;
v8 += 4;
--v7;
}
signal(7, handler);
mmapfile(0LL, v13);
if ( (unsigned __int8)(v18[76] - 1) > 0x12u )
{
if ( (unsigned int)func1(v18) )
*(&v17 + strlen(v18)) = 0;
v9 = func0(v18);
v10 = v16;
v11 = (const char *)fh2owner(v15);
printf("%s,%d,%s,%s\n", v11, v10, v9, v18);
}
}
}
}
}
}
}
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 )
return 0xFFFFFFFFLL;
v2 = brds;
v3 = 0;
while ( strcasecmp(s1, v2) )
{
++v3;
v2 += 512;
if ( v3 == v1 )
return 0xFFFFFFFFLL;
}
if ( dword_404110[128 * (__int64)v3] && (byte_404118[512 * (__int64)v3] & 0x10) == 0 )
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 )
return 0xFFFFFFFFLL;
v2 = brds;
v3 = 0;
while ( strcasecmp(s1, v2) )
{
++v3;
v2 += 512;
if ( v3 == v1 )
return 0xFFFFFFFFLL;
}
if ( dword_404110[128 * (__int64)v3] && (byte_404118[512 * (__int64)v3] & 0x10) == 0 )
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 == (char *)(unsigned int)((_DWORD)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 == (char *)(unsigned int)((_DWORD)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)
{
int v1; // eax
void *v2; // rbp
int v3; // ebx
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

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

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

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

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

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:
int __fastcall compare_word(char *s1, char *src)
{
int v2; // eax
int v3; // edx
char *v4; // rax
int v5; // ebx
size_t v6; // r13
char *v7; // rax
char v9[152]; // [rsp+0h] [rbp-98h] BYREF

v2 = strlen(s1);
v3 = 99;
if ( v2 <= 99 )
v3 = v2;
if ( v2 <= 0 )
{
v9[0] = 0;
v6 = 0LL;
}
else
{
v4 = src;
v5 = 0;
do
{
if ( *v4 == 1 )
break;
++v5;
++v4;
}
while ( v3 > v5 );
v6 = v5;
strncpy(v9, src, v5);
v9[v5] = 0;
if ( v5 > 0 )
{
v7 = v9;
do
*v7++ += 30;
while ( v7 != &v9[v5 - 1 + 1] );
}
}
return strncasecmp(s1, v9, 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(char *dest, __int64 a2, int a3)
{
int v5; // edi
__int64 i; // rax
int v7; // ecx
char v8; // dl
char *result; // rax
char v10[136]; // [rsp+0h] [rbp-88h] BYREF

v5 = strlen(dest);
for ( i = 0LL; i != 98; ++i )
{
v7 = i;
v8 = *(_BYTE *)(a2 + i);
if ( v8 )
{
if ( v8 == 1 )
break;
v10[i] = v8 + 30;
}
else
{
v10[i] = 32;
}
v7 = i + 1;
}
v10[v7] = 10;
v10[v7 + 1] = 0;
result = (char *)(unsigned int)(v7 + 1 + v5 + 1);
if ( (int)result < a3 )
result = strcat(dest, v10);
return result;
}

canonical_decompiled_code:
char *__fastcall func9(char *dest, __int64 a2, int a3)
{
int v5; // edi
__int64 i; // rax
int v7; // ecx
char v8; // dl
char *result; // rax
char v10[136]; // [rsp+0h] [rbp-88h] BYREF

v5 = strlen(dest);
for ( i = 0LL; i != 98; ++i )
{
v7 = i;
v8 = *(_BYTE *)(a2 + i);
if ( v8 )
{
if ( v8 == 1 )
break;
v10[i] = v8 + 30;
}
else
{
v10[i] = 32;
}
v7 = i + 1;
}
v10[v7] = 10;
v10[v7 + 1] = 0;
result = (char *)(unsigned int)(v7 + 1 + v5 + 1);
if ( (int)result < a3 )
result = strcat(dest, v10);
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 = (char *)"";
return result;
}

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

result = getenv(a1);
if ( !result )
result = (char *)"";
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)
{
int v1; // eax
void *v2; // rbp
int v3; // ebx
struct stat v5; // [rsp+0h] [rbp-A8h] BYREF

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

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


report

decompiled_code:
int __fastcall report(const char *a1)
{
return puts(a1);
}

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

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_1961;
return result;
}

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

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


report

canonical_decompiled_code:
void func1()
{
;
}


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:
__int64 __fastcall mmapfile(char *file, __int64 a2)
{
void *v4; // rdi
__int64 result; // rax
size_t v6; // rsi
void *v7; // rdi
size_t v8; // rsi
int v9; // eax
int v10; // ebp
struct stat v11; // [rsp+0h] [rbp-A8h] BYREF

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

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

if ( !file || stat(file, &v11) == -1 )
{
v7 = *(void **)a2;
if ( *(_QWORD *)a2 )
{
v8 = *(_QWORD *)(a2 + 16);
if ( v8 )
munmap(v7, v8);
*(_QWORD *)a2 = 0LL;
}
result = (unsigned int)-(file != 0LL);
}
else
{
v4 = *(void **)a2;
if ( *(_QWORD *)a2 )
{
result = 0LL;
if ( v11.st_mtim.tv_sec == *(_QWORD *)(a2 + 8) )
return result;
v6 = *(_QWORD *)(a2 + 16);
if ( v6 )
munmap(v4, v6);
*(_QWORD *)a2 = 0LL;
}
if ( v11.st_size )
{
v9 = open(file, 0);
v10 = v9;
if ( v9 < 0 )
{
*(_QWORD *)a2 = 0LL;
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)a2 = mmap(0LL, v11.st_size, 1, 1, v9, 0LL);
close(v10);
if ( *(_QWORD *)a2 == -1LL )
{
*(_QWORD *)a2 = 0LL;
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(a2 + 8) = v11.st_mtim.tv_sec;
*(_QWORD *)(a2 + 16) = v11.st_size;
result = 0LL;
}
}
}
else
{
*(_QWORD *)a2 = &c_2;
*(_QWORD *)(a2 + 16) = 0LL;
*(_QWORD *)(a2 + 8) = v11.st_mtim.tv_sec;
result = 0LL;
}
}
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:
const char *__fastcall rstrip(const char *a1)
{
const char *result; // rax
int v2; // ebx
const unsigned __int16 *v3; // rcx

result = (const char *)strlen(a1);
v2 = (_DWORD)result - 1;
if ( (int)result - 1 >= 0 )
{
v3 = *_ctype_b_loc();
result = &a1[v2];
do
{
if ( (v3[*result] & 0x2000) == 0 )
break;
--result;
--v2;
}
while ( v2 >= 0 );
}
a1[v2 + 1] = 0;
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
const char *result; // rax
int v2; // ebx
const unsigned __int16 *v3; // rcx

result = (const char *)strlen(a1);
v2 = (_DWORD)result - 1;
if ( (int)result - 1 >= 0 )
{
v3 = *_ctype_b_loc();
result = &a1[v2];
do
{
if ( (v3[*result] & 0x2000) == 0 )
break;
--result;
--v2;
}
while ( v2 >= 0 );
}
a1[v2 + 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

for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*a1 )
{
if ( (_BYTE)result == 9 )
*a1 = 32;
++a1;
}
return result;
}

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

for ( result = (unsigned __int8)*a1; (_BYTE)result; result = (unsigned __int8)*a1 )
{
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++;
    }
}


repo: defuse/passgen

decompiled_code:
void __fastcall ct_string_init(__int64 a1)
{
*(_DWORD *)a1 = 0;
*(_DWORD *)(a1 + 4) = 0;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
void ct_string_init(ct_string *str)
{
    str->allocated_length = 0;
    str->actual_length = 0;
    str->string = ((void *)0);
}

canonical_original_code:
void ct_string_init(struct ConstantTimeString *str)
{
    str->allocated_length = 0;
    str->actual_length = 0;
    str->string = ((void *)0);
}

variable_types: struct ConstantTimeString { unsigned int allocated_length; unsigned int actual_length; unsigned char *string; } *


decompiled_code:
__int64 __fastcall ct_string_concat(unsigned int *a1, __int64 a2, unsigned int a3, unsigned int a4)
{
void *v7; // rdi
char *v8; // rax
unsigned int v9; // ebp
unsigned int v10; // eax
__int64 v11; // rbx
unsigned int v12; // eax
char v13; // al
_BYTE *v14; // rdx
__int64 result; // rax
void *v16; // rdi
char v17; // [rsp+8h] [rbp-40h]
unsigned int v18; // [rsp+Ch] [rbp-3Ch]

if ( a3 < a4 || a3 == 0 || !a4 )
return 0LL;
v7 = (void *)*((_QWORD *)a1 + 1);
if ( v7 )
{
v8 = (char *)realloc(v7, *a1 + a3);
*((_QWORD *)a1 + 1) = v8;
if ( v8 )
{
memset(&v8[*a1], 0, a3);
*a1 += a3;
v18 = a3 - 1;
if ( a3 - 1 >= *a1 )
{
LABEL_10:
a1[1] += a4;
return 1LL;
}
LABEL_6:
v9 = 0;
do
{
v10 = ct_eq_u32(v9, a1[1]);
v17 = ct_mask_u32(v10);
v11 = 0LL;
do
{
v12 = ct_lt_u32((unsigned int)v11, a4);
v13 = ct_mask_u32(v12);
v14 = (_BYTE *)(*((_QWORD *)a1 + 1) + v9 + (unsigned int)v11);
*v14 |= v17 & *(_BYTE *)(a2 + v11++) & v13;
}
while ( v11 != v18 + 1 );
++v9;
}
while ( *a1 > v9 + v18 );
goto LABEL_10;
}
result = 0LL;
}
else
{
v16 = malloc(a3);
*((_QWORD *)a1 + 1) = v16;
if ( v16 )
{
memset(v16, 0, a3);
*a1 = a3;
v18 = a3 - 1;
goto LABEL_6;
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int *a1, __int64 a2, unsigned int a3, unsigned int a4)
{
void *v7; // rdi
char *v8; // rax
unsigned int v9; // ebp
unsigned int v10; // eax
__int64 v11; // rbx
unsigned int v12; // eax
char v13; // al
_BYTE *v14; // rdx
__int64 result; // rax
void *v16; // rdi
char v17; // [rsp+8h] [rbp-40h]
unsigned int v18; // [rsp+Ch] [rbp-3Ch]

if ( a3 < a4 || a3 == 0 || !a4 )
return 0LL;
v7 = (void *)*((_QWORD *)a1 + 1);
if ( v7 )
{
v8 = (char *)realloc(v7, *a1 + a3);
*((_QWORD *)a1 + 1) = v8;
if ( v8 )
{
memset(&v8[*a1], 0, a3);
*a1 += a3;
v18 = a3 - 1;
if ( a3 - 1 >= *a1 )
{
LABEL_10:
a1[1] += a4;
return 1LL;
}
LABEL_6:
v9 = 0;
do
{
v10 = ct_eq_u32(v9, a1[1]);
v17 = ct_mask_u32(v10);
v11 = 0LL;
do
{
v12 = ct_lt_u32((unsigned int)v11, a4);
v13 = ct_mask_u32(v12);
v14 = (_BYTE *)(*((_QWORD *)a1 + 1) + v9 + (unsigned int)v11);
*v14 |= v17 & *(_BYTE *)(a2 + v11++) & v13;
}
while ( v11 != v18 + 1 );
++v9;
}
while ( *a1 > v9 + v18 );
goto LABEL_10;
}
result = 0LL;
}
else
{
v16 = malloc(a3);
*((_QWORD *)a1 + 1) = v16;
if ( v16 )
{
memset(v16, 0, a3);
*a1 = a3;
v18 = a3 - 1;
goto LABEL_6;
}
result = 0LL;
}
return result;
}

original_code:
int ct_string_concat(ct_string *str, const unsigned char *to_append, uint32_t max_length, uint32_t actual_length)
{
    if (max_length == 0 || actual_length == 0 || actual_length > max_length) {
        return 0;
    }
    if (str->string == ((void *)0)) {
        str->string = malloc(max_length);
        if (str->string == ((void *)0)) {
            return 0;
        }
        memset(str->string, 0, max_length);
        str->allocated_length = max_length;
    } else {
        str->string = realloc(str->string, str->allocated_length + max_length);
        if (str->string == ((void *)0)) {
            return 0;
        }
        memset(str->string + str->allocated_length, 0, max_length);
        str->allocated_length += max_length;
    }
    for (uint32_t i = 0; i + max_length - 1 < str->allocated_length; i++) {
        uint32_t outer_mask = ct_mask_u32(ct_eq_u32(i, str->actual_length));
        for (uint32_t j = 0; j < max_length; j++) {
            uint32_t inner_mask = ct_mask_u32(ct_lt_u32(j, actual_length));
            str->string[i+j] |= (uint32_t)to_append[j] & outer_mask & inner_mask;
        }
    }
    str->actual_length += actual_length;
    return 1;
}

canonical_original_code:
int ct_string_concat(struct ConstantTimeString *str, unsigned char *to_append, unsigned int max_length, unsigned int actual_length)
{
    if (max_length == 0 || actual_length == 0 || actual_length > max_length) {
        return 0;
    }
    if (str->string == ((void *)0)) {
        str->string = malloc(max_length);
        if (str->string == ((void *)0)) {
            return 0;
        }
        memset(str->string, 0, max_length);
        str->allocated_length = max_length;
    } else {
        str->string = realloc(str->string, str->allocated_length + max_length);
        if (str->string == ((void *)0)) {
            return 0;
        }
        memset(str->string + str->allocated_length, 0, max_length);
        str->allocated_length += max_length;
    }
    for (unsigned int i = 0; i + max_length - 1 < str->allocated_length; i++) {
        unsigned int outer_mask = ct_mask_u32(ct_eq_u32(i, str->actual_length));
        for (unsigned int j = 0; j < max_length; j++) {
            unsigned int inner_mask = ct_mask_u32(ct_lt_u32(j, actual_length));
            str->string[i+j] |= (unsigned int)to_append[j] & outer_mask & inner_mask;
        }
    }
    str->actual_length += actual_length;
    return 1;
}

variable_types:
i
unsigned int

variable_types:
j
unsigned int

user_defined_types: struct ConstantTimeString { unsigned int allocated_length; unsigned int actual_length; unsigned char *string; }


decompiled_code:
void __fastcall ct_string_finalize(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // ebx
unsigned int v4; // er12
unsigned int v5; // eax

if ( *(_DWORD *)a1 )
{
v3 = 0;
v4 = a3;
do
{
v5 = ct_lt_u32(v3, *(unsigned int *)(a1 + 4));
*(_BYTE *)(a2 + v3) = ct_select_u32(*(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + v3), v4, v5);
++v3;
}
while ( *(_DWORD *)a1 > v3 );
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, __int64 a2, unsigned __int8 a3)
{
unsigned int v3; // ebx
unsigned int v4; // er12
unsigned int v5; // eax

if ( *(_DWORD *)a1 )
{
v3 = 0;
v4 = a3;
do
{
v5 = ct_lt_u32(v3, *(unsigned int *)(a1 + 4));
*(_BYTE *)(a2 + v3) = ct_select_u32(*(unsigned __int8 *)(*(_QWORD *)(a1 + 8) + v3), v4, v5);
++v3;
}
while ( *(_DWORD *)a1 > v3 );
}
}

original_code:
void ct_string_finalize(ct_string *str, unsigned char *buf, unsigned char filler)
{
    for (uint32_t i = 0; i < str->allocated_length; i++) {
        buf[i] = ct_select_u32(str->string[i], filler, ct_lt_u32(i, str->actual_length));
    }
}

canonical_original_code:
void ct_string_finalize(struct ConstantTimeString *str, unsigned char *buf, unsigned char filler)
{
    for (unsigned int i = 0; i < str->allocated_length; i++) {
        buf[i] = ct_select_u32(str->string[i], filler, ct_lt_u32(i, str->actual_length));
    }
}

variable_types:
buf
unsigned char *

variable_types:
filler
unsigned char


decompiled_code:
__int64 __fastcall ct_string_allocated_length(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
return *a1;
}

original_code:
uint32_t ct_string_allocated_length(ct_string *str)
{
    return str->allocated_length;
}

canonical_original_code:
unsigned int ct_string_allocated_length(struct ConstantTimeString *str)
{
    return str->allocated_length;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall ct_string_deinit(unsigned int *a1)
{
__int64 v2; // rdi

v2 = *((_QWORD *)a1 + 1);
if ( v2 )
{
memset_s(v2, 0LL, *a1);
free(*((void **)a1 + 1));
}
memset_s(a1, 0LL, 4LL);
return memset_s(a1 + 1, 0LL, 4LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
__int64 v2; // rdi

v2 = *((_QWORD *)a1 + 1);
if ( v2 )
{
memset_s(v2, 0LL, *a1);
free(*((void **)a1 + 1));
}
memset_s(a1, 0LL, 4LL);
return memset_s(a1 + 1, 0LL, 4LL);
}

original_code:
void ct_string_deinit(ct_string *str)
{
    if (str->string != ((void *)0)) {
        memset_s(str->string, 0, str->allocated_length);
        free(str->string);
    }
    memset_s(&(str->allocated_length), 0, sizeof(str->allocated_length));
    memset_s(&(str->actual_length), 0, sizeof(str->actual_length));
}

canonical_original_code:
void ct_string_deinit(struct ConstantTimeString *str)
{
    if (str->string != ((void *)0)) {
        memset_s(str->string, 0, str->allocated_length);
        free(str->string);
    }
    memset_s(&(str->allocated_length), 0, sizeof(str->allocated_length));
    memset_s(&(str->actual_length), 0, sizeof(str->actual_length));
}


showHelp

decompiled_code:
int showHelp()
{
puts("Usage: passgen <type> <optional arguments>");
puts("Where <type> is one of:");
puts(" -x, --hex\t\t\t\t64 hexadecimal characters");
puts(" -a, --ascii\t\t\t\t64 ASCII characters");
puts(" -n, --alpha\t\t\t\t64 alpha-numeric characters");
puts(" -d, --digit\t\t\t\t64 digit characters (for PINs)");
puts(" -l, --lower\t\t\t\t64 lower-alpha characters (for phones)");
printf(" -w, --words\t\t\t\t%d random words from a list of %d\n", 10LL, 7236LL);
puts(" -h, --help\t\t\t\tShow this help menu");
puts("Where <optional arguments> can be:");
puts(" -p, --password-count N\t\tSpecify number of passwords to generate");
return puts("WARNING: If automated, you MUST check that the exit status is 0.");
}

canonical_decompiled_code:
int func0()
{
puts("Usage: passgen <type> <optional arguments>");
puts("Where <type> is one of:");
puts(" -x, --hex\t\t\t\t64 hexadecimal characters");
puts(" -a, --ascii\t\t\t\t64 ASCII characters");
puts(" -n, --alpha\t\t\t\t64 alpha-numeric characters");
puts(" -d, --digit\t\t\t\t64 digit characters (for PINs)");
puts(" -l, --lower\t\t\t\t64 lower-alpha characters (for phones)");
printf(" -w, --words\t\t\t\t%d random words from a list of %d\n", 10LL, 7236LL);
puts(" -h, --help\t\t\t\tShow this help menu");
puts("Where <optional arguments> can be:");
puts(" -p, --password-count N\t\tSpecify number of passwords to generate");
return puts("WARNING: If automated, you MUST check that the exit status is 0.");
}

original_code:
void showHelp(void)
{
    puts("Usage: passgen <type> <optional arguments>");
    puts("Where <type> is one of:");
    puts("  -x, --hex\t\t\t\t64 hexadecimal characters");
    puts("  -a, --ascii\t\t\t\t64 ASCII characters");
    puts("  -n, --alpha\t\t\t\t64 alpha-numeric characters");
    puts("  -d, --digit\t\t\t\t64 digit characters (for PINs)");
    puts("  -l, --lower\t\t\t\t64 lower-alpha characters (for phones)");
    printf("  -w, --words\t\t\t\t%d random words from a list of %d\n", 10, 7236);
    puts("  -h, --help\t\t\t\tShow this help menu");
    puts("Where <optional arguments> can be:");
    puts("  -p, --password-count N\t\tSpecify number of passwords to generate");
    puts("WARNING: If automated, you MUST check that the exit status is 0.");
}

canonical_original_code:
void showHelp()
{
    puts("Usage: passgen <type> <optional arguments>");
    puts("Where <type> is one of:");
    puts("  -x, --hex\t\t\t\t64 hexadecimal characters");
    puts("  -a, --ascii\t\t\t\t64 ASCII characters");
    puts("  -n, --alpha\t\t\t\t64 alpha-numeric characters");
    puts("  -d, --digit\t\t\t\t64 digit characters (for PINs)");
    puts("  -l, --lower\t\t\t\t64 lower-alpha characters (for phones)");
    printf("  -w, --words\t\t\t\t%d random words from a list of %d\n", 10, 7236);
    puts("  -h, --help\t\t\t\tShow this help menu");
    puts("Where <optional arguments> can be:");
    puts("  -p, --password-count N\t\tSpecify number of passwords to generate");
    puts("WARNING: If automated, you MUST check that the exit status is 0.");
}


decompiled_code:
__int64 __fastcall lookup_word(_BYTE *a1, unsigned int a2)
{
_BYTE *v2; // rax
__int64 v3; // rbp
unsigned int v4; // er12
unsigned int v5; // er13
unsigned int v6; // eax
char v7; // cl
__int64 i; // rax

v2 = a1;
do
*v2++ = 0;
while ( v2 != a1 + 15 );
v3 = 0LL;
v4 = 0;
v5 = 0;
do
{
v6 = ct_eq_u32(v4, a2);
v7 = ct_mask_u32(v6);
for ( i = 0LL; i != 15; ++i )
a1[i] |= words[v3 + 1 + i] & v7;
v5 |= (unsigned __int8)(words[v3] & v7);
++v4;
v3 += 16LL;
}
while ( v4 != 7236 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, unsigned int a2)
{
_BYTE *v2; // rax
__int64 v3; // rbp
unsigned int v4; // er12
unsigned int v5; // er13
unsigned int v6; // eax
char v7; // cl
__int64 i; // rax

v2 = a1;
do
*v2++ = 0;
while ( v2 != a1 + 15 );
v3 = 0LL;
v4 = 0;
v5 = 0;
do
{
v6 = ct_eq_u32(v4, a2);
v7 = ct_mask_u32(v6);
for ( i = 0LL; i != 15; ++i )
a1[i] |= words[v3 + 1 + i] & v7;
v5 |= (unsigned __int8)(words[v3] & v7);
++v4;
v3 += 16LL;
}
while ( v4 != 7236 );
return v5;
}

original_code:
uint32_t lookup_word(unsigned char *buf, uint32_t index)
{
    uint32_t length = 0;
    for (uint32_t i = 0; i < 15; i++) {
        buf[i] = 0;
    }
    for (uint32_t i = 0; i < 7236; i++) {
        uint32_t mask = ct_mask_u32(ct_eq_u32(i, index));
        for (uint32_t j = 0; j < 15; j++) {
            buf[j] |= words[i][j+1] & mask;
        }
        length |= words[i][0] & mask;
    }
    return length;
}

canonical_original_code:
unsigned int lookup_word(unsigned char *buf, unsigned int index)
{
    unsigned int length = 0;
    for (unsigned int i = 0; i < 15; i++) {
        buf[i] = 0;
    }
    for (unsigned int i = 0; i < 7236; i++) {
        unsigned int mask = ct_mask_u32(ct_eq_u32(i, index));
        for (unsigned int j = 0; j < 15; j++) {
            buf[j] |= words[i][j+1] & mask;
        }
        length |= words[i][0] & mask;
    }
    return length;
}

variable_types:
index
unsigned int

variable_types:
length
unsigned int

variable_types:
mask
unsigned int


getLeastCoveringMask

decompiled_code:
unsigned __int64 __fastcall getLeastCoveringMask(unsigned __int64 a1)
{
unsigned __int64 result; // rax

if ( !a1 )
return 0LL;
for ( result = 0LL; result < a1; result = 2 * result + 1 )
;
return result;
}

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

if ( !a1 )
return 0LL;
for ( result = 0LL; result < a1; result = 2 * result + 1 )
;
return result;
}

original_code:
unsigned long getLeastCoveringMask(unsigned long toRepresent)
{
    unsigned long mask = 0;
    while (mask < toRepresent) {
        mask = (mask << 1) | 1;
    }
    return mask;
}

variable_types:
toRepresent
unsigned long

variable_types:
mask
unsigned long

return_type: unsigned long


getPassword

decompiled_code:
_BOOL8 __fastcall getPassword(__int64 a1, unsigned __int64 a2, __int64 a3, size_t a4)
{
void *v5; // rax
void *v6; // r12
char v7; // r15
_BOOL4 v8; // ebx
size_t v9; // r13
size_t v10; // rax
size_t v12; // rbx
unsigned __int8 v13; // dl

v5 = malloc(a4);
if ( !v5 )
return 0;
v6 = v5;
if ( a2 - 1 > 0xFF )
{
free(v5);
v8 = 0;
}
else
{
v7 = getLeastCoveringMask(a2 - 1);
v8 = getRandom(v6, a4);
if ( v8 )
{
v9 = 0LL;
v10 = 0LL;
if ( a4 )
{
while ( 1 )
{
v12 = v10 + 1;
v13 = *((_BYTE *)v6 + v10) & v7;
if ( v13 < a2 )
{
*(_BYTE *)(v9 + a3) = invariant_time_lookup(a1, (unsigned int)a2, v13);
++v9;
}
if ( v9 >= a4 )
break;
if ( a4 <= v12 )
{
v8 = getRandom(v6, a4);
if ( !v8 )
goto LABEL_8;
v12 = 0LL;
}
v10 = v12;
}
}
memset_s(v6, 0LL, a4);
free(v6);
v8 = 1;
}
else
{
LABEL_8:
memset_s(v6, 0LL, a4);
free(v6);
}
}
return v8;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, unsigned __int64 a2, __int64 a3, size_t a4)
{
void *v5; // rax
void *v6; // r12
char v7; // r15
_BOOL4 v8; // ebx
size_t v9; // r13
size_t v10; // rax
size_t v12; // rbx
unsigned __int8 v13; // dl

v5 = malloc(a4);
if ( !v5 )
return 0;
v6 = v5;
if ( a2 - 1 > 0xFF )
{
free(v5);
v8 = 0;
}
else
{
v7 = func2(a2 - 1);
v8 = func3(v6, a4);
if ( v8 )
{
v9 = 0LL;
v10 = 0LL;
if ( a4 )
{
while ( 1 )
{
v12 = v10 + 1;
v13 = *((_BYTE *)v6 + v10) & v7;
if ( v13 < a2 )
{
*(_BYTE *)(v9 + a3) = invariant_time_lookup(a1, (unsigned int)a2, v13);
++v9;
}
if ( v9 >= a4 )
break;
if ( a4 <= v12 )
{
v8 = func3(v6, a4);
if ( !v8 )
goto LABEL_8;
v12 = 0LL;
}
v10 = v12;
}
}
memset_s(v6, 0LL, a4);
free(v6);
v8 = 1;
}
else
{
LABEL_8:
memset_s(v6, 0LL, a4);
free(v6);
}
}
return v8;
}

original_code:
int getPassword(const char *set, unsigned long setLength, unsigned char *password, unsigned long passwordLength)
{
    unsigned long bufLen = passwordLength;
    unsigned long bufIdx = 0;
    unsigned char *rndBuf = (unsigned char*)malloc(bufLen);
    if (rndBuf == ((void *)0)) {
        return 0;
    }
    if (setLength < 1 || setLength > 256) {
        free(rndBuf);
        return 0;
    }
    unsigned char bitMask = getLeastCoveringMask(setLength - 1ul) & 0xFF;
    if(!getRandom(rndBuf, bufLen)) {
        memset_s(rndBuf, 0, bufLen);
        free(rndBuf);
        return 0;
    }
    unsigned long i = 0;
    while(i < passwordLength) {
        if(bufIdx >= bufLen) {
            if(!getRandom(rndBuf, bufLen)) {
                memset_s(rndBuf, 0, bufLen);
                free(rndBuf);
                return 0;
            }
            bufIdx = 0;
        }
        unsigned char c = rndBuf[bufIdx++];
        c = c & bitMask;
        if(c < setLength) {
            password[i] = invariant_time_lookup((const unsigned char*)set, setLength, c);
            i++;
        }
    }
    memset_s(rndBuf, 0, bufLen);
    free(rndBuf);
    return 1;
}

canonical_original_code:
int getPassword(char *set, unsigned long setLength, unsigned char *password, unsigned long passwordLength)
{
    unsigned long bufLen = passwordLength;
    unsigned long bufIdx = 0;
    unsigned char *rndBuf = (unsigned char*)malloc(bufLen);
    if (rndBuf == ((void *)0)) {
        return 0;
    }
    if (setLength < 1 || setLength > 256) {
        free(rndBuf);
        return 0;
    }
    unsigned char bitMask = getLeastCoveringMask(setLength - 1ul) & 0xFF;
    if(!getRandom(rndBuf, bufLen)) {
        memset_s(rndBuf, 0, bufLen);
        free(rndBuf);
        return 0;
    }
    unsigned long i = 0;
    while(i < passwordLength) {
        if(bufIdx >= bufLen) {
            if(!getRandom(rndBuf, bufLen)) {
                memset_s(rndBuf, 0, bufLen);
                free(rndBuf);
                return 0;
            }
            bufIdx = 0;
        }
        unsigned char c = rndBuf[bufIdx++];
        c = c & bitMask;
        if(c < setLength) {
            password[i] = invariant_time_lookup((unsigned char *)set, setLength, c);
            i++;
        }
    }
    memset_s(rndBuf, 0, bufLen);
    free(rndBuf);
    return 1;
}

variable_types:
set
char *

variable_types:
setLength
unsigned long

variable_types:
password
unsigned char *

variable_types:
passwordLength
unsigned long

variable_types:
bufLen
unsigned long

variable_types:
bufIdx
unsigned long

variable_types:
rndBuf
unsigned char *

variable_types:
bitMask
unsigned char

variable_types:
i
unsigned long

variable_types:
c
unsigned char


getRandomUnsignedLong

decompiled_code:
_BOOL8 __fastcall getRandomUnsignedLong(void *a1)
{
return getRandom(a1, 8uLL);
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(void *a1)
{
return func3(a1, 8uLL);
}

original_code:
int getRandomUnsignedLong(unsigned long *random)
{
    return getRandom(random, sizeof(unsigned long));
}

variable_types:
random
unsigned long *


showRandomWords

decompiled_code:
__int64 showRandomWords()
{
int v0; // ebx
__int64 result; // rax
unsigned __int64 v2; // rax
unsigned __int64 v3; // rax
unsigned int v4; // ebp
size_t v5; // rbp
void *v6; // rax
void *v7; // rbx
_BYTE v8[25]; // [rsp+0h] [rbp-48h] BYREF
char v9[15]; // [rsp+19h] [rbp-2Fh] BYREF
__int64 v10[4]; // [rsp+28h] [rbp-20h] BYREF

v10[0] = 0LL;
ct_string_init(v8);
v0 = 0;
while ( v0 != 10 )
{
result = getRandomUnsignedLong(v10);
if ( !(_DWORD)result )
return result;
v2 = getLeastCoveringMask(0x1C43uLL);
v3 = v10[0] & v2;
v10[0] = v3;
if ( v3 <= 0x1C43 )
{
v4 = lookup_word(v9, v3);
if ( v0 )
{
result = ct_string_concat(v8, ".", 1LL, 1LL);
if ( !(_DWORD)result )
return result;
}
result = ct_string_concat(v8, v9, 15LL, v4);
if ( !(_DWORD)result )
return result;
++v0;
}
}
v5 = (unsigned int)ct_string_allocated_length(v8);
v6 = malloc(v5);
v7 = v6;
if ( !v6 )
return 0LL;
ct_string_finalize(v8, v6, 46LL);
fwrite(v7, 1uLL, v5, stdout);
putchar(10);
memset_s(v10, 0LL, 8LL);
memset_s(v9, 0LL, 15LL);
memset_s(v7, 0LL, v5);
ct_string_deinit(v8);
free(v7);
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // ebx
__int64 result; // rax
unsigned __int64 v2; // rax
unsigned __int64 v3; // rax
unsigned int v4; // ebp
size_t v5; // rbp
void *v6; // rax
void *v7; // rbx
_BYTE v8[25]; // [rsp+0h] [rbp-48h] BYREF
char v9[15]; // [rsp+19h] [rbp-2Fh] BYREF
__int64 v10[4]; // [rsp+28h] [rbp-20h] BYREF

v10[0] = 0LL;
ct_string_init(v8);
v0 = 0;
while ( v0 != 10 )
{
result = func5(v10);
if ( !(_DWORD)result )
return result;
v2 = func2(0x1C43uLL);
v3 = v10[0] & v2;
v10[0] = v3;
if ( v3 <= 0x1C43 )
{
v4 = func1(v9, v3);
if ( v0 )
{
result = ct_string_concat(v8, ".", 1LL, 1LL);
if ( !(_DWORD)result )
return result;
}
result = ct_string_concat(v8, v9, 15LL, v4);
if ( !(_DWORD)result )
return result;
++v0;
}
}
v5 = (unsigned int)ct_string_allocated_length(v8);
v6 = malloc(v5);
v7 = v6;
if ( !v6 )
return 0LL;
ct_string_finalize(v8, v6, 46LL);
fwrite(v7, 1uLL, v5, stdout);
putchar(10);
memset_s(v10, 0LL, 8LL);
memset_s(v9, 0LL, 15LL);
memset_s(v7, 0LL, v5);
ct_string_deinit(v8);
free(v7);
return 1LL;
}

original_code:
int showRandomWords(void)
{
    unsigned int words_added = 0;
    unsigned long random = 0;
    unsigned char word[15];
    uint32_t word_length = 0;
    ct_string str;
    ct_string_init(&str);
    while (words_added < 10) {
        if (!getRandomUnsignedLong(&random)) {
            return 0;
        }
        random = random & getLeastCoveringMask(7236 - 1);
        if (random < 7236) {
            word_length = lookup_word(word, random);
            if (words_added > 0) {
                if (!ct_string_concat(&str, (const unsigned char *)".", 1, 1)) {
                    return 0;
                }
            }
            if (!ct_string_concat(&str, word, 15, word_length)) {
                return 0;
            }
            words_added++;
        }
    }
    uint32_t total_length = ct_string_allocated_length(&str);
    unsigned char *final = malloc(total_length);
    if (final == ((void *)0)) {
        return 0;
    }
    ct_string_finalize(&str, final, '.');
    fwrite(final, sizeof(unsigned char), total_length, stdout);
    printf("\n");
    memset_s(&random, 0, sizeof(random));
    memset_s(word, 0, 15);
    memset_s(final, 0, total_length);
    ct_string_deinit(&str);
    free(final);
    return 1;
}

canonical_original_code:
int showRandomWords()
{
    unsigned int words_added = 0;
    unsigned long random = 0;
    unsigned char word[15];
    unsigned int word_length = 0;
    struct ConstantTimeString str;
    ct_string_init(&str);
    while (words_added < 10) {
        if (!getRandomUnsignedLong(&random)) {
            return 0;
        }
        random = random & getLeastCoveringMask(7236 - 1);
        if (random < 7236) {
            word_length = lookup_word(word, random);
            if (words_added > 0) {
                if (!ct_string_concat(&str, (unsigned char *)".", 1, 1)) {
                    return 0;
                }
            }
            if (!ct_string_concat(&str, word, 15, word_length)) {
                return 0;
            }
            words_added++;
        }
    }
    unsigned int total_length = ct_string_allocated_length(&str);
    unsigned char *final = malloc(total_length);
    if (final == ((void *)0)) {
        return 0;
    }
    ct_string_finalize(&str, final, '.');
    fwrite(final, sizeof(unsigned char), total_length, stdout);
    printf("\n");
    memset_s(&random, 0, sizeof(random));
    memset_s(word, 0, 15);
    memset_s(final, 0, total_length);
    ct_string_deinit(&str);
    free(final);
    return 1;
}

variable_types:
random
unsigned long

variable_types:
word
unsigned char [15]

variable_types: struct ConstantTimeString { unsigned int allocated_length; unsigned int actual_length; unsigned char *string; }

variable_types:
final
unsigned char *