repo: egcodes/key-syncSubtitle

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
double v4; // r14
char v5; // al
int v6; // er12
int v7; // er12
int v9; // eax
char *v10; // rax
int v11; // eax
char *v12; // rax
char *v13; // rax
int v14; // [rsp+0h] [rbp-728h] BYREF
int v15; // [rsp+4h] [rbp-724h]
int v16; // [rsp+8h] [rbp-720h]
int v17; // [rsp+Ch] [rbp-71Ch]
char newa[256]; // [rsp+10h] [rbp-718h] BYREF
char s[256]; // [rsp+110h] [rbp-618h] BYREF
char dest[256]; // [rsp+210h] [rbp-518h] BYREF
char nptr; // [rsp+310h] [rbp-418h] BYREF
char v22[2]; // [rsp+311h] [rbp-417h] BYREF
char v23[3]; // [rsp+313h] [rbp-415h] BYREF
char v24[3]; // [rsp+316h] [rbp-412h] BYREF
char v25[8]; // [rsp+319h] [rbp-40Fh] BYREF
char v26[3]; // [rsp+321h] [rbp-407h] BYREF
char v27[3]; // [rsp+324h] [rbp-404h] BYREF
char v28[3]; // [rsp+327h] [rbp-401h] BYREF
char v29[1022]; // [rsp+32Ah] [rbp-3FEh] BYREF

if ( (unsigned int)checkArgc(argc, argv, envp) )
LABEL_20:
usage();
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "hl:s:");
if ( v5 == -1 )
break;
if ( v5 == 108 )
{
v3 = _bss_start;
}
else
{
if ( v5 != 115 )
goto LABEL_20;
v4 = atof(_bss_start);
}
}
sprintf(s, "%s-temp.txt", v3);
stream = fopen(v3, "r");
if ( !stream )
{
puts("Subtitle not open...");
exit(1);
}
fD = fopen(s, "w");
if ( !fD )
{
puts("Cannot open file...");
exit(1);
}
if ( strstr(v3, ".sub") )
{
v6 = (int)(v4 * 1000.0);
while ( fgets(&nptr, 900, stream) )
{
if ( nptr == 123 )
{
v9 = atoi(v22);
fprintf(fD, "{%d}", (unsigned int)(v6 + v9));
v10 = strchr(v22, 123);
v11 = atoi(v10 + 1);
fprintf(fD, "{%d}", (unsigned int)(v6 + v11));
v12 = strchr(&nptr, 125);
v13 = strchr(v12 + 1, 125);
fputs(v13 + 1, fD);
}
}
}
v7 = 1;
if ( strstr(v3, ".srt") )
{
while ( fgets(&nptr, 900, stream) )
{
fputs(&nptr, fD);
if ( v7 == atoi(&nptr) )
{
++v7;
fgets(&nptr, 900, stream);
v14 = atoi(&nptr);
v15 = atoi(v23);
v16 = atoi(v24);
v17 = atoi(v25);
set_dur(&v14, v4);
fprint_dur();
fwrite(" --> ", 1uLL, 5uLL, fD);
v14 = atoi(v26);
v15 = atoi(v27);
v16 = atoi(v28);
v17 = atoi(v29);
set_dur(&v14, v4);
fprint_dur();
fputc(10, fD);
}
}
}
fclose(stream);
fclose(fD);
sprintf(newa, "%s(old)", v3);
rename(v3, newa);
strcpy(dest, v3);
rename(s, dest);
printf("\nNew Subtitle Path : %s\n", dest);
puts("Press any key to close");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
double v4; // r14
char v5; // al
int v6; // er12
int v7; // er12
int v9; // eax
char *v10; // rax
int v11; // eax
char *v12; // rax
char *v13; // rax
int v14; // [rsp+0h] [rbp-728h] BYREF
int v15; // [rsp+4h] [rbp-724h]
int v16; // [rsp+8h] [rbp-720h]
int v17; // [rsp+Ch] [rbp-71Ch]
char newa[256]; // [rsp+10h] [rbp-718h] BYREF
char s[256]; // [rsp+110h] [rbp-618h] BYREF
char dest[256]; // [rsp+210h] [rbp-518h] BYREF
char nptr; // [rsp+310h] [rbp-418h] BYREF
char v22[2]; // [rsp+311h] [rbp-417h] BYREF
char v23[3]; // [rsp+313h] [rbp-415h] BYREF
char v24[3]; // [rsp+316h] [rbp-412h] BYREF
char v25[8]; // [rsp+319h] [rbp-40Fh] BYREF
char v26[3]; // [rsp+321h] [rbp-407h] BYREF
char v27[3]; // [rsp+324h] [rbp-404h] BYREF
char v28[3]; // [rsp+327h] [rbp-401h] BYREF
char v29[1022]; // [rsp+32Ah] [rbp-3FEh] BYREF

if ( (unsigned int)func10(argc, argv, envp) )
LABEL_20:
func9();
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "hl:s:");
if ( v5 == -1 )
break;
if ( v5 == 108 )
{
v3 = _bss_start;
}
else
{
if ( v5 != 115 )
goto LABEL_20;
v4 = atof(_bss_start);
}
}
sprintf(s, "%s-temp.txt", v3);
stream = fopen(v3, "r");
if ( !stream )
{
puts("Subtitle not open...");
exit(1);
}
fD = fopen(s, "w");
if ( !fD )
{
puts("Cannot open file...");
exit(1);
}
if ( strstr(v3, ".sub") )
{
v6 = (int)(v4 * 1000.0);
while ( fgets(&nptr, 900, stream) )
{
if ( nptr == 123 )
{
v9 = atoi(v22);
fprintf(fD, "{%d}", (unsigned int)(v6 + v9));
v10 = strchr(v22, 123);
v11 = atoi(v10 + 1);
fprintf(fD, "{%d}", (unsigned int)(v6 + v11));
v12 = strchr(&nptr, 125);
v13 = strchr(v12 + 1, 125);
fputs(v13 + 1, fD);
}
}
}
v7 = 1;
if ( strstr(v3, ".srt") )
{
while ( fgets(&nptr, 900, stream) )
{
fputs(&nptr, fD);
if ( v7 == atoi(&nptr) )
{
++v7;
fgets(&nptr, 900, stream);
v14 = atoi(&nptr);
v15 = atoi(v23);
v16 = atoi(v24);
v17 = atoi(v25);
func8(&v14, v4);
func7();
fwrite(" --> ", 1uLL, 5uLL, fD);
v14 = atoi(v26);
v15 = atoi(v27);
v16 = atoi(v28);
v17 = atoi(v29);
func8(&v14, v4);
func7();
fputc(10, fD);
}
}
}
fclose(stream);
fclose(fD);
sprintf(newa, "%s(old)", v3);
rename(v3, newa);
strcpy(dest, v3);
rename(s, dest);
printf("\nNew Subtitle Path : %s\n", dest);
puts("Press any key to close");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    Dur time;
    char *spath;
    char snewpath[256];
    char dpath[256];
    char dnewpath[256];
    int count = 1;
    double sync;
    char buf[1000];
    char c;
    int sub, sub_sync;
    if (checkArgc(argc))
        usage();
    while ((c = getopt (argc, argv, "hl:s:")) != -1)
        switch (c)
        {
            case 'h':
                usage();
                break;
            case 'l':
                spath = optarg;
                break;
            case 's':
                sync = atof(optarg);
                break;
            default:
                usage();
                break;
        }
    sprintf(dpath, "%s-temp.txt", spath);
    sub_sync = sync * 1000;
    if ((fS = fopen(spath, "r")) == ((void *)0)) {
        printf("Subtitle not open...\n");
        exit(1);
    }
    if ((fD = fopen(dpath, "w")) == ((void *)0)) {
        printf("Cannot open file...\n");
        exit(1);
    }
    if (strstr(spath, ".sub"))
     while (((void *)0) != fgets(buf, 900, fS))
         if (buf[0] == '{') {
       sub = atoi(buf + 1);
       sub += sub_sync;
       fprintf(fD, "{%d}", sub);
       sub = atoi(strchr(buf + 1, '{') + 1);
       sub += sub_sync;
       fprintf(fD, "{%d}", sub);
       fprintf(fD, "%s", strchr(strchr(buf, '}') + 1, '}') + 1);
      }
    if (strstr(spath, ".srt"))
     while (((void *)0) != fgets(buf, 900, fS)) {
           fprintf(fD, "%s", buf);
           if (atoi(buf) == count) {
               fgets(buf, 900, fS);
               time.hour = atoi(buf);
               time.min = atoi(buf + 3);
               time.sec = atoi(buf + 6);
               time.msec = atoi(buf + 9);
               set_dur(&time, sync);
               fprint_dur(&time);
               fprintf(fD, " --> ");
               time.hour = atoi(buf + 17);
               time.min = atoi(buf + 20);
               time.sec = atoi(buf + 23);
               time.msec = atoi(buf + 26);
               set_dur(&time, sync);
               fprint_dur(&time);
               fprintf(fD, "\n");
               count++;
           }
     }
    fclose(fS);
    fclose(fD);
    sprintf(snewpath, "%s(old)", spath);
    rename(spath, snewpath);
    sprintf(dnewpath, "%s", spath);
    rename(dpath, dnewpath);
    printf("\nNew Subtitle Path : %s\n",dnewpath);
    printf("Press any key to close\n");
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct _Dur time;
    char *spath;
    char snewpath[256];
    char dpath[256];
    char dnewpath[256];
    int count = 1;
    double sync;
    char buf[1000];
    char c;
    int sub; int sub_sync;
    if (checkArgc(argc))
        usage();
    while ((c = getopt (argc, argv, "hl:s:")) != -1)
        switch (c)
        {
            case 'h':
                usage();
                break;
            case 'l':
                spath = optarg;
                break;
            case 's':
                sync = atof(optarg);
                break;
            default:
                usage();
                break;
        }
    sprintf(dpath, "%s-temp.txt", spath);
    sub_sync = sync * 1000;
    if ((fS = fopen(spath, "r")) == ((void *)0)) {
        printf("Subtitle not open...\n");
        exit(1);
    }
    if ((fD = fopen(dpath, "w")) == ((void *)0)) {
        printf("Cannot open file...\n");
        exit(1);
    }
    if (strstr(spath, ".sub"))
     while (((void *)0) != fgets(buf, 900, fS))
         if (buf[0] == '{') {
       sub = atoi(buf + 1);
       sub += sub_sync;
       fprintf(fD, "{%d}", sub);
       sub = atoi(strchr(buf + 1, '{') + 1);
       sub += sub_sync;
       fprintf(fD, "{%d}", sub);
       fprintf(fD, "%s", strchr(strchr(buf, '}') + 1, '}') + 1);
      }
    if (strstr(spath, ".srt"))
     while (((void *)0) != fgets(buf, 900, fS)) {
           fprintf(fD, "%s", buf);
           if (atoi(buf) == count) {
               fgets(buf, 900, fS);
               time.hour = atoi(buf);
               time.min = atoi(buf + 3);
               time.sec = atoi(buf + 6);
               time.msec = atoi(buf + 9);
               set_dur(&time, sync);
               fprint_dur(&time);
               fprintf(fD, " --> ");
               time.hour = atoi(buf + 17);
               time.min = atoi(buf + 20);
               time.sec = atoi(buf + 23);
               time.msec = atoi(buf + 26);
               set_dur(&time, sync);
               fprint_dur(&time);
               fprintf(fD, "\n");
               count++;
           }
     }
    fclose(fS);
    fclose(fD);
    sprintf(snewpath, "%s(old)", spath);
    rename(spath, snewpath);
    sprintf(dnewpath, "%s", spath);
    rename(dpath, dnewpath);
    printf("\nNew Subtitle Path : %s\n",dnewpath);
    printf("Press any key to close\n");
    return 0;
}

variable_types:
argv
char *[]

variable_types:
time
struct _Dur { int hour; }

variable_types:
spath
char *

variable_types:
snewpath
char [256]

variable_types:
dpath
char [256]

variable_types:
dnewpath
char [256]

variable_types: count int

variable_types: sync double

variable_types:
buf
char [1000]

variable_types: c char

variable_types: sub int


decompiled_code:
int __fastcall fprint_dur(unsigned int *a1)
{
return fprintf(fD, "0%d:%02d:%02d,%03d", *a1, a1[1], a1[2], a1[3]);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
return fprintf(fD, "0%d:%02d:%02d,%03d", *a1, a1[1], a1[2], a1[3]);
}

original_code:
void fprint_dur(const Dur *p)
{
    fprintf(fD, "0%d:%02d:%02d,%03d", p->hour, p->min, p->sec, p->msec);
}

canonical_original_code:
void fprint_dur(struct _Dur *p)
{
    fprintf(fD, "0%d:%02d:%02d,%03d", p->hour, p->min, p->sec, p->msec);
}

variable_types:
p
struct _Dur { int hour; } *

return_type: void


variable_types: sum int


usage

decompiled_code:
void __noreturn usage()
{
printf(
"\n"
"Key v%s (Usage)\n"
"Sync : key -l <subtitle-path> -s <second>\n"
"( 5) -> add 5 second\n"
"(-5) -> reduce 5 second\n"
"\n"
"Help : key -h\n"
"\n",
"0.1");
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
printf(
"\n"
"Key v%s (Usage)\n"
"Sync : key -l <subtitle-path> -s <second>\n"
"( 5) -> add 5 second\n"
"(-5) -> reduce 5 second\n"
"\n"
"Help : key -h\n"
"\n",
"0.1");
exit(1);
}

original_code:
void usage(void)
{
    printf("\nKey v%s (Usage)\n"
           "Sync  : key -l <subtitle-path> -s <second>\n"
           "( 5)   -> add 5 second\n"
           "(-5)   -> reduce 5 second\n\n"
           "Help  : key -h\n\n", "0.1");
    exit(1);
}

canonical_original_code:
void usage()
{
    printf("\nKey v%s (Usage)\n"
           "Sync  : key -l <subtitle-path> -s <second>\n"
           "( 5)   -> add 5 second\n"
           "(-5)   -> reduce 5 second\n\n"
           "Help  : key -h\n\n", "0.1");
    exit(1);
}


checkArgc

decompiled_code:
__int64 __fastcall checkArgc(int a1)
{
if ( a1 <= 1 )
usage();
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
if ( a1 <= 1 )
func9();
return 0LL;
}

original_code:
int checkArgc(int argc)
{
    if (argc < 2)
        usage();
    return 0;
}

variable_types: argc int

return_type: int


decompiled_code:
void __fastcall __noreturn count_down(int a1)
{
unsigned int v1; // ebx

v1 = a1;
strcpy(buf, "time to die");
puts("\nChild 2 process executing...");
if ( close(pfd2[0]) != -1 )
{
if ( close(fd) != -1 )
{
if ( close(pfd1[0]) != -1 )
{
if ( a1 > 0 )
{
do
{
printf("Count Down: 00:0%d\n", v1);
write(dword_4040BC, "not die yet", 0xCuLL);
sleep(1u);
--v1;
}
while ( v1 );
}
write(dword_4040BC, buf, 0xCuLL);
if ( close(dword_4040BC) != -1 )
{
puts("Count Down: 0");
puts("End of Count Down(child 2) process...");
exit(1);
}
printf("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing reading end of pipe 1");
_exit(1);
}
puts("Error closing writing end of pipe 1");
_exit(1);
}
puts("Error closing reading end of pipe 2");
_exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int a1)
{
unsigned int v1; // ebx

v1 = a1;
strcpy(buf, "time to die");
puts("\nChild 2 process executing...");
if ( close(pfd2[0]) != -1 )
{
if ( close(fd) != -1 )
{
if ( close(pfd1[0]) != -1 )
{
if ( a1 > 0 )
{
do
{
printf("Count Down: 00:0%d\n", v1);
write(dword_4040BC, "not die yet", 0xCuLL);
sleep(1u);
--v1;
}
while ( v1 );
}
write(dword_4040BC, buf, 0xCuLL);
if ( close(dword_4040BC) != -1 )
{
puts("Count Down: 0");
puts("End of Count Down(child 2) process...");
exit(1);
}
printf("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing reading end of pipe 1");
_exit(1);
}
puts("Error closing writing end of pipe 1");
_exit(1);
}
puts("Error closing reading end of pipe 2");
_exit(1);
}

original_code:
void count_down(int start)
{
 strcpy(buf, "time to die");
    printf("\nChild 2 process executing...\n");
    if (close(pfd2[0]) == -1)
    {
        printf("Error closing reading end of pipe 2\n");
        _exit(1);
    }
 if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of pipe 1\n");
        _exit(1);
    }
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of pipe 1\n");
        _exit(1);
    }
    for( ;start>0; start--)
    {
  printf("Count Down: 00:0%d\n", start);
        write(pfd2[1], "not die yet",12);
  sleep(1);
    }
    write(pfd2[1], buf, sizeof(buf));
    if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of pipe 2");
        _exit(1);
    }
    printf("Count Down: 0\n");
 printf("End of Count Down(child 2) process...\n");
    exit(1);
}

variable_types: start int


decompiled_code:
void __noreturn wall_clock()
{
struct tm *v0; // rbx
time_t timer; // [rsp+8h] [rbp-20h] BYREF
char s1[20]; // [rsp+14h] [rbp-14h] BYREF

strcpy(s1, "time to die");
puts("\nChild 1 process executing...");
if ( close(pfd1[0]) != -1 )
{
if ( close(dword_4040BC) != -1 )
{
if ( close(fd) == -1 )
{
puts("Error closing writing end of pipe 1");
_exit(1);
}
while ( 1 )
{
timer = time(0LL);
v0 = localtime(&timer);
read(pfd2[0], buf, 0xCuLL);
if ( !strcmp(s1, buf) )
break;
printf("The time is %d:%d:%d\n", (unsigned int)v0->tm_hour, (unsigned int)v0->tm_min, (unsigned int)v0->tm_sec);
sleep(1u);
}
if ( close(pfd2[0]) != -1 )
{
puts("End of Wall Clock(child 1) process...");
exit(1);
}
}
puts("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing reading end of pipe 1");
_exit(1);
}

canonical_decompiled_code:
void __noreturn func8()
{
struct tm *v0; // rbx
time_t timer; // [rsp+8h] [rbp-20h] BYREF
char s1[20]; // [rsp+14h] [rbp-14h] BYREF

strcpy(s1, "time to die");
puts("\nChild 1 process executing...");
if ( close(pfd1[0]) != -1 )
{
if ( close(dword_4040BC) != -1 )
{
if ( close(fd) == -1 )
{
puts("Error closing writing end of pipe 1");
_exit(1);
}
while ( 1 )
{
timer = time(0LL);
v0 = localtime(&timer);
read(pfd2[0], buf, 0xCuLL);
if ( !strcmp(s1, buf) )
break;
printf("The time is %d:%d:%d\n", (unsigned int)v0->tm_hour, (unsigned int)v0->tm_min, (unsigned int)v0->tm_sec);
sleep(1u);
}
if ( close(pfd2[0]) != -1 )
{
puts("End of Wall Clock(child 1) process...");
exit(1);
}
}
puts("Error closing writing end of pipe 2");
_exit(1);
}
puts("Error closing reading end of pipe 1");
_exit(1);
}

original_code:
void wall_clock()
{
 char str1[12];
 strcpy(str1, "time to die");
 printf("\nChild 1 process executing...\n");
    time_t now;
    struct tm *lcltime;
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of pipe 1\n");
        _exit(1);
    }
 if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of pipe 2\n");
        _exit(1);
    }
 if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of pipe 1\n");
        _exit(1);
    }
    for(;;)
    {
        now = time ( ((void *)0) );
        lcltime = localtime ( &now );
  int status = read(pfd2[0], buf, 12);
        int ret = strcmp(str1, buf);
  if (ret != 0)
  {
            printf ("The time is %d:%d:%d\n", lcltime->tm_hour, lcltime->tm_min, lcltime->tm_sec );
            sleep(1);
  }
  if(ret == 0)
        {
            if (close(pfd2[0]) == -1)
            {
                printf("Error closing writing end of pipe 2\n");
                _exit(1);
            }
            printf("End of Wall Clock(child 1) process...\n");
            exit(1);
        }
    }
}

canonical_original_code:
void wall_clock()
{
 char str1[12];
 strcpy(str1, "time to die");
 printf("\nChild 1 process executing...\n");
    long now;
    struct tm *lcltime;
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of pipe 1\n");
        _exit(1);
    }
 if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of pipe 2\n");
        _exit(1);
    }
 if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of pipe 1\n");
        _exit(1);
    }
    for(;;)
    {
        now = time ( ((void *)0) );
        lcltime = localtime ( &now );
  int status = read(pfd2[0], buf, 12);
        int ret = strcmp(str1, buf);
  if (ret != 0)
  {
            printf ("The time is %d:%d:%d\n", lcltime->tm_hour, lcltime->tm_min, lcltime->tm_sec );
            sleep(1);
  }
  if(ret == 0)
        {
            if (close(pfd2[0]) == -1)
            {
                printf("Error closing writing end of pipe 2\n");
                _exit(1);
            }
            printf("End of Wall Clock(child 1) process...\n");
            exit(1);
        }
    }
}

variable_types: now long

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

variable_types: status int

variable_types: ret int


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__pid_t v4; // eax
__pid_t v5; // eax

v3 = 6;
if ( argc == 2 )
v3 = atoi(argv[1]);
if ( pipe(pfd1) != -1 )
{
if ( pipe(pfd2) != -1 )
{
puts("Pipes opened, now creating child process!");
v4 = fork();
if ( v4 != -1 )
{
if ( v4 )
{
v5 = fork();
if ( v5 != -1 )
{
if ( v5 )
{
puts("Parent closing pipes");
if ( close(pfd1[0]) != -1 )
{
if ( close(fd) != -1 )
{
if ( close(pfd2[0]) != -1 )
{
if ( close(dword_4040BC) != -1 )
{
puts("Parent waiting for children completion...");
if ( wait(0LL) != -1 && wait(0LL) != -1 )
{
puts("Time to print out a Friendly Message!");
puts("Parent process finishing, bye!");
exit(0);
}
puts("Error wating, no child process is ended!");
exit(1);
}
puts("Error closing writing end of the pipe 2");
exit(1);
}
puts("Error closing reading end of the pipe 2");
exit(1);
}
puts("Error closing writing end of the pipe 1");
exit(1);
}
puts("Error closing reading end of the pipe 1");
exit(1);
}
count_down(v3, argv);
}
puts("Error forking child 2!");
exit(1);
}
wall_clock("Pipes opened, now creating child process!", argv);
}
puts("Error forking child 1!");
exit(1);
}
puts("Error opening pipe 2!");
exit(1);
}
puts("Error opening pipe 1!");
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__pid_t v4; // eax
__pid_t v5; // eax

v3 = 6;
if ( argc == 2 )
v3 = atoi(argv[1]);
if ( pipe(pfd1) != -1 )
{
if ( pipe(pfd2) != -1 )
{
puts("Pipes opened, now creating child process!");
v4 = fork();
if ( v4 != -1 )
{
if ( v4 )
{
v5 = fork();
if ( v5 != -1 )
{
if ( v5 )
{
puts("Parent closing pipes");
if ( close(pfd1[0]) != -1 )
{
if ( close(fd) != -1 )
{
if ( close(pfd2[0]) != -1 )
{
if ( close(dword_4040BC) != -1 )
{
puts("Parent waiting for children completion...");
if ( wait(0LL) != -1 && wait(0LL) != -1 )
{
puts("Time to print out a Friendly Message!");
puts("Parent process finishing, bye!");
exit(0);
}
puts("Error wating, no child process is ended!");
exit(1);
}
puts("Error closing writing end of the pipe 2");
exit(1);
}
puts("Error closing reading end of the pipe 2");
exit(1);
}
puts("Error closing writing end of the pipe 1");
exit(1);
}
puts("Error closing reading end of the pipe 1");
exit(1);
}
func7(v3, argv);
}
puts("Error forking child 2!");
exit(1);
}
func8("Pipes opened, now creating child process!", argv);
}
puts("Error forking child 1!");
exit(1);
}
puts("Error opening pipe 2!");
exit(1);
}
puts("Error opening pipe 1!");
exit(1);
}

original_code:
int main(int argc, const char * argv[])
{
    int time=6;
    if(argc==2)
    {
        time=atoi(argv[1]);
    }
    if (pipe(pfd1) == -1)
    {
        printf("Error opening pipe 1!\n");
        exit(1);
    }
    if (pipe(pfd2) == -1)
    {
        printf("Error opening pipe 2!\n");
        exit(1);
    }
    printf("Pipes opened, now creating child process!\n");
    switch (fork())
    {
        case -1:
            printf("Error forking child 1!\n");
            exit(1);
        case 0:
            wall_clock();
            exit(1);
        default:
            break;
    }
    switch (fork())
    {
        case -1:
            printf("Error forking child 2!\n");
            exit(1);
        case 0:
            count_down(time);
            exit(1);
        default:
            break;
    }
    printf("Parent closing pipes\n");
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of the pipe 1\n");
        exit(1);
    }
    if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of the pipe 1\n");
        exit(1);
    }
    if (close(pfd2[0]) == -1)
    {
        printf("Error closing reading end of the pipe 2\n");
        exit(1);
    }
    if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of the pipe 2\n");
        exit(1);
    }
    printf("Parent waiting for children completion...\n");
    if (wait(((void *)0)) == -1)
    {
        printf("Error wating, no child process is ended!\n");
        exit(1);
    }
    if (wait(((void *)0)) == -1)
    {
        printf("Error wating, no child process is ended!\n");
        exit(1);
    }
    printf("Time to print out a Friendly Message!\n");
 printf("Parent process finishing, bye!\n");
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int time = 6;
    if(argc==2)
    {
        time=atoi(argv[1]);
    }
    if (pipe(pfd1) == -1)
    {
        printf("Error opening pipe 1!\n");
        exit(1);
    }
    if (pipe(pfd2) == -1)
    {
        printf("Error opening pipe 2!\n");
        exit(1);
    }
    printf("Pipes opened, now creating child process!\n");
    switch (fork())
    {
        case -1:
            printf("Error forking child 1!\n");
            exit(1);
        case 0:
            wall_clock();
            exit(1);
        default:
            break;
    }
    switch (fork())
    {
        case -1:
            printf("Error forking child 2!\n");
            exit(1);
        case 0:
            count_down(time);
            exit(1);
        default:
            break;
    }
    printf("Parent closing pipes\n");
    if (close(pfd1[0]) == -1)
    {
        printf("Error closing reading end of the pipe 1\n");
        exit(1);
    }
    if (close(pfd1[1]) == -1)
    {
        printf("Error closing writing end of the pipe 1\n");
        exit(1);
    }
    if (close(pfd2[0]) == -1)
    {
        printf("Error closing reading end of the pipe 2\n");
        exit(1);
    }
    if (close(pfd2[1]) == -1)
    {
        printf("Error closing writing end of the pipe 2\n");
        exit(1);
    }
    printf("Parent waiting for children completion...\n");
    if (wait(((void *)0)) == -1)
    {
        printf("Error wating, no child process is ended!\n");
        exit(1);
    }
    if (wait(((void *)0)) == -1)
    {
        printf("Error wating, no child process is ended!\n");
        exit(1);
    }
    printf("Time to print out a Friendly Message!\n");
 printf("Parent process finishing, bye!\n");
    exit(0);
}

variable_types:
argv
char *[]

variable_types: time int


repo: egillespie/randword

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // edi
int v4; // ebx
int v5; // er12
__int64 v6; // rbp
__int16 v7; // bx
char v9[56]; // [rsp+0h] [rbp-38h] BYREF

parseArgs(argc, argv, envp);
v3 = time(0LL);
srand(v3);
InitProgram();
signal(2, (__sighandler_t)&SigHandler);
atexit((void (*)(void))&ExitProgram);
do
{
v4 = rand() % (maxWordLength - minWordLength + 1) + minWordLength;
if ( v4 > 0 )
{
v5 = 0;
v6 = 0LL;
do
{
++v5;
v9[v6] = rand() % 26 + 97;
v6 = (__int16)v5;
}
while ( (__int16)v5 < v4 );
}
++totalcount;
v9[v4] = 0;
if ( !(unsigned int)CheckWord(v9, (unsigned int)v4) )
{
if ( verbose )
printf("%s%s", v9, "\n");
LABEL_8:
v7 = 0;
continue;
}
++numfound;
printf("%s", v9);
if ( verbose )
printf(" *");
putchar(10);
if ( !stopAfterLength )
goto LABEL_8;
v7 = xLength == v4;
}
while ( (!stopAfterWord || strcmp(xWord, v9)) && (!stopAfterHits || numfound != xHits) && !v7 );
return 0;
}

original_code:
int main(int argc, char **argv) {
   char randword[20 + 1];
   int randlen;
   short i, stop = 0;
   parseArgs(argc, argv);
   srand(time(((void *)0)));
   InitProgram();
   signal(2, SigHandler);
   atexit(ExitProgram);
   while (!stop) {
      randlen = rand() % (maxWordLength - minWordLength + 1) + minWordLength;
      for (i = 0; i < randlen; i++)
         randword[i] = (unsigned char)(rand() % 26 + 97);
      randword[randlen] = '\0';
      totalcount++;
      if (CheckWord(randword, randlen)) {
         numfound++;
         printf("%s", randword);
         if (verbose)
            printf(" *");
         printf("%s", "\n");
         if (stopAfterLength && randlen == xLength)
            stop = 1;
      }
      else if (verbose)
         printf("%s%s", randword, "\n");
      if (stopAfterWord && strcmp(xWord, randword) == 0)
         stop = 1;
      if (stopAfterHits && numfound == xHits)
         stop = 1;
   }
   return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
   char randword[-1];
   int randlen;
   short i; short stop = 0;
   parseArgs(argc, argv);
   srand(time(((void *)0)));
   InitProgram();
   signal(2, SigHandler);
   atexit(ExitProgram);
   while (!stop) {
      randlen = rand() % (maxWordLength - minWordLength + 1) + minWordLength;
      for (i = 0; i < randlen; i++)
         randword[i] = (unsigned char)(rand() % 26 + 97);
      randword[randlen] = '\0';
      totalcount++;
      if (CheckWord(randword, randlen)) {
         numfound++;
         printf("%s", randword);
         if (verbose)
            printf(" *");
         printf("%s", "\n");
         if (stopAfterLength && randlen == xLength)
            stop = 1;
      }
      else if (verbose)
         printf("%s%s", randword, "\n");
      if (stopAfterWord && strcmp(xWord, randword) == 0)
         stop = 1;
      if (stopAfterHits && numfound == xHits)
         stop = 1;
   }
   return 0;
}

variable_types:
argv
char **

variable_types:
randword
char [-1]

variable_types: randlen int

variable_types: i short

variable_types: stop short


argSetSearchOnDisk

decompiled_code:
__int64 argSetSearchOnDisk()
{
__int64 result; // rax

result = 1LL;
searchOnDisk = 1;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax

result = 1LL;
searchOnDisk = 1;
return result;
}

original_code:
void argSetSearchOnDisk(char* szparam) {
   searchOnDisk = 1;
}

canonical_original_code:
void argSetSearchOnDisk(char *szparam) {
   searchOnDisk = 1;
}

variable_types:
szparam
char *


argSetQuiet

decompiled_code:
__int64 argSetQuiet()
{
__int64 result; // rax

result = 1LL;
quiet = 1;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

result = 1LL;
quiet = 1;
return result;
}

original_code:
void argSetQuiet(char* szparam) {
   quiet = 1;
}

canonical_original_code:
void argSetQuiet(char *szparam) {
   quiet = 1;
}


argSetVerbose

decompiled_code:
__int64 argSetVerbose()
{
__int64 result; // rax

result = 1LL;
verbose = 1;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

result = 1LL;
verbose = 1;
return result;
}

original_code:
void argSetVerbose(char *szparam) {
   verbose = 1;
}


infoSetSearchOnDisk

decompiled_code:
int infoSetSearchOnDisk()
{
return printf("Keep the dictionary on the disk when searching%s", "\n");
}

canonical_decompiled_code:
int func3()
{
return printf("Keep the dictionary on the disk when searching%s", "\n");
}

original_code:
void infoSetSearchOnDisk(void) {
   printf("Keep the dictionary on the disk when searching%s", "\n");
}

canonical_original_code:
void infoSetSearchOnDisk() {
   printf("Keep the dictionary on the disk when searching%s", "\n");
}


infoSetMinWordLength

decompiled_code:
int infoSetMinWordLength()
{
return printf("Sets the minimum word length (default = %d).%s", 3LL, "\n");
}

canonical_decompiled_code:
int func4()
{
return printf("Sets the minimum word length (default = %d).%s", 3LL, "\n");
}

original_code:
void infoSetMinWordLength(void) {
   printf("Sets the minimum word length (default = %d).%s", 3, "\n");
}

canonical_original_code:
void infoSetMinWordLength() {
   printf("Sets the minimum word length (default = %d).%s", 3, "\n");
}


infoSetMaxWordLength

decompiled_code:
int infoSetMaxWordLength()
{
return printf("Sets the maximum word length (default = %d).%s", 20LL, "\n");
}

canonical_decompiled_code:
int func5()
{
return printf("Sets the maximum word length (default = %d).%s", 20LL, "\n");
}

original_code:
void infoSetMaxWordLength(void) {
   printf("Sets the maximum word length (default = %d).%s", 20, "\n");
}

canonical_original_code:
void infoSetMaxWordLength() {
   printf("Sets the maximum word length (default = %d).%s", 20, "\n");
}


infoSetStopHits

decompiled_code:
int infoSetStopHits()
{
return printf("Stop after arg words are generated.%s", "\n");
}

canonical_decompiled_code:
int func6()
{
return printf("Stop after arg words are generated.%s", "\n");
}

original_code:
void infoSetStopHits(void) {
   printf("Stop after arg words are generated.%s", "\n");
}

canonical_original_code:
void infoSetStopHits() {
   printf("Stop after arg words are generated.%s", "\n");
}


infoSetStopWord

decompiled_code:
int infoSetStopWord()
{
return printf("Stop after specified word is generated.%s", "\n");
}

canonical_decompiled_code:
int func7()
{
return printf("Stop after specified word is generated.%s", "\n");
}

original_code:
void infoSetStopWord(void) {
   printf("Stop after specified word is generated.%s", "\n");
}

canonical_original_code:
void infoSetStopWord() {
   printf("Stop after specified word is generated.%s", "\n");
}


infoSetStopLength

decompiled_code:
int infoSetStopLength()
{
return printf("Stop after arg length word is found.%s", "\n");
}

canonical_decompiled_code:
int func8()
{
return printf("Stop after arg length word is found.%s", "\n");
}

original_code:
void infoSetStopLength(void) {
   printf("Stop after arg length word is found.%s", "\n");
}

canonical_original_code:
void infoSetStopLength() {
   printf("Stop after arg length word is found.%s", "\n");
}


infoSetQuiet

decompiled_code:
int infoSetQuiet()
{
return printf("Quiet mode. Only print words found in the dictionary.%s", "\n");
}

canonical_decompiled_code:
int func9()
{
return printf("Quiet mode. Only print words found in the dictionary.%s", "\n");
}

original_code:
void infoSetQuiet(void) {
   printf("Quiet mode.  Only print words found in the dictionary.%s", "\n");
}

canonical_original_code:
void infoSetQuiet() {
   printf("Quiet mode.  Only print words found in the dictionary.%s", "\n");
}


infoSetVerbose

decompiled_code:
int infoSetVerbose()
{
return printf("Verbose mode. Print all randomly generated strings.%s", "\n");
}

canonical_decompiled_code:
int func10()
{
return printf("Verbose mode. Print all randomly generated strings.%s", "\n");
}

original_code:
void infoSetVerbose(void) {
   printf("Verbose mode.  Print all randomly generated strings.%s", "\n");
}

canonical_original_code:
void infoSetVerbose() {
   printf("Verbose mode.  Print all randomly generated strings.%s", "\n");
}


infoPrintHelp

decompiled_code:
int infoPrintHelp()
{
return printf("Displays this help message and exits.%s", "\n");
}

canonical_decompiled_code:
int func11()
{
return printf("Displays this help message and exits.%s", "\n");
}

original_code:
void infoPrintHelp(void) {
   printf("Displays this help message and exits.%s", "\n");
}

canonical_original_code:
void infoPrintHelp() {
   printf("Displays this help message and exits.%s", "\n");
}


argPrintVersion

decompiled_code:
void __noreturn argPrintVersion()
{
printf("%s %s.%s%s", "randword", "1", "1", "\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func12()
{
printf("%s %s.%s%s", "randword", "1", "1", "\n");
exit(0);
}

original_code:
void argPrintVersion(char* szparam) {
   printf("%s %s.%s%s", "randword", "1", "1", "\n");
   exit(0);
}

canonical_original_code:
void argPrintVersion(char *szparam) {
   printf("%s %s.%s%s", "randword", "1", "1", "\n");
   exit(0);
}


infoPrintVersion

decompiled_code:
int infoPrintVersion()
{
return printf("Displays %s's version information and exits.%s", "randword", "\n");
}

canonical_decompiled_code:
int func13()
{
return printf("Displays %s's version information and exits.%s", "randword", "\n");
}

original_code:
void infoPrintVersion(void) {
   printf("Displays %s's version information and exits.%s", "randword", "\n");
}

canonical_original_code:
void infoPrintVersion() {
   printf("Displays %s's version information and exits.%s", "randword", "\n");
}


argSetMinWordLength

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

minWordLength = atoi(a1);
result = (unsigned int)(minWordLength - 3);
if ( (unsigned int)result > 0x11 )
{
fprintf(stderr, "%s : Invalid minimum word length%s", "randword", "\n");
exit(1);
}
return result;
}

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

minWordLength = atoi(a1);
result = (unsigned int)(minWordLength - 3);
if ( (unsigned int)result > 0x11 )
{
fprintf(stderr, "%s : Invalid minimum word length%s", "randword", "\n");
exit(1);
}
return result;
}

original_code:
void argSetMinWordLength(char* szparam) {
   minWordLength = atoi(szparam);
   if (minWordLength < 3 || minWordLength > 20) {
      fprintf(stderr, "%s : Invalid minimum word length%s", "randword", "\n");
      exit(1);
   }
}

canonical_original_code:
void argSetMinWordLength(char *szparam) {
   minWordLength = atoi(szparam);
   if (minWordLength < 3 || minWordLength > 20) {
      fprintf(stderr, "%s : Invalid minimum word length%s", "randword", "\n");
      exit(1);
   }
}


argSetMaxWordLength

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

maxWordLength = atoi(a1);
result = (unsigned int)(maxWordLength - 3);
if ( (unsigned int)result > 0x11 )
{
fprintf(stderr, "%s : Invalid maximum word length%s", "randword", "\n");
exit(1);
}
return result;
}

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

maxWordLength = atoi(a1);
result = (unsigned int)(maxWordLength - 3);
if ( (unsigned int)result > 0x11 )
{
fprintf(stderr, "%s : Invalid maximum word length%s", "randword", "\n");
exit(1);
}
return result;
}

original_code:
void argSetMaxWordLength(char* szparam) {
   maxWordLength = atoi(szparam);
   if (maxWordLength < 3 || maxWordLength > 20) {
      fprintf(stderr, "%s : Invalid maximum word length%s", "randword", "\n");
      exit(1);
   }
}

canonical_original_code:
void argSetMaxWordLength(char *szparam) {
   maxWordLength = atoi(szparam);
   if (maxWordLength < 3 || maxWordLength > 20) {
      fprintf(stderr, "%s : Invalid maximum word length%s", "randword", "\n");
      exit(1);
   }
}


argSetStopLength

decompiled_code:
__int64 __fastcall argSetStopLength(const char *a1)
{
int v1; // eax
__int64 result; // rax

stopAfterLength = 1;
v1 = atoi(a1);
xLength = v1;
result = (unsigned int)(v1 - 3);
if ( (unsigned __int16)result > 0x11u )
{
fprintf(stderr, "%s : Specified length is invalid%s", "randword", "\n");
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(const char *a1)
{
int v1; // eax
__int64 result; // rax

stopAfterLength = 1;
v1 = atoi(a1);
xLength = v1;
result = (unsigned int)(v1 - 3);
if ( (unsigned __int16)result > 0x11u )
{
fprintf(stderr, "%s : Specified length is invalid%s", "randword", "\n");
exit(1);
}
return result;
}

original_code:
void argSetStopLength(char* szparam) {
   stopAfterLength = 1;
   xLength = atoi(szparam);
   if (xLength < 3 || xLength > 20) {
      fprintf(stderr, "%s : Specified length is invalid%s", "randword", "\n");
      exit(1);
   }
}

canonical_original_code:
void argSetStopLength(char *szparam) {
   stopAfterLength = 1;
   xLength = atoi(szparam);
   if (xLength < 3 || xLength > 20) {
      fprintf(stderr, "%s : Specified length is invalid%s", "randword", "\n");
      exit(1);
   }
}


argSetStopHits

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

stopAfterHits = 1;
result = atol(a1);
xHits = result;
if ( result <= 0 )
{
fprintf(stderr, "%s : Invalid value for parameter -h%s", "randword", "\n");
exit(1);
}
return result;
}

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

stopAfterHits = 1;
result = atol(a1);
xHits = result;
if ( result <= 0 )
{
fprintf(stderr, "%s : Invalid value for parameter -h%s", "randword", "\n");
exit(1);
}
return result;
}

original_code:
void argSetStopHits(char* szparam) {
   stopAfterHits = 1;
   xHits = atol(szparam);
   if (xHits <= 0) {
      fprintf(stderr, "%s : Invalid value for parameter -h%s", "randword", "\n");
      exit(1);
   }
}

canonical_original_code:
void argSetStopHits(char *szparam) {
   stopAfterHits = 1;
   xHits = atol(szparam);
   if (xHits <= 0) {
      fprintf(stderr, "%s : Invalid value for parameter -h%s", "randword", "\n");
      exit(1);
   }
}


argSetStopWord

decompiled_code:
char *__fastcall argSetStopWord(char *src)
{
__int16 v1; // ax

v1 = strlen(src);
stopAfterWord = 1;
if ( v1 <= 2 )
{
fprintf(stderr, "%s : Specified word is too short%s", "randword", "\n");
goto LABEL_5;
}
if ( v1 > 20 )
{
fprintf(stderr, "%s : Specified word is too long%s", "randword", "\n");
LABEL_5:
exit(1);
}
return strcpy(xWord, src);
}

canonical_decompiled_code:
char *__fastcall func18(char *src)
{
__int16 v1; // ax

v1 = strlen(src);
stopAfterWord = 1;
if ( v1 <= 2 )
{
fprintf(stderr, "%s : Specified word is too short%s", "randword", "\n");
goto LABEL_5;
}
if ( v1 > 20 )
{
fprintf(stderr, "%s : Specified word is too long%s", "randword", "\n");
LABEL_5:
exit(1);
}
return strcpy(xWord, src);
}

original_code:
void argSetStopWord(char* szparam) {
   short paramLength = strlen(szparam);
   stopAfterWord = 1;
   if (paramLength < 3) {
      fprintf(stderr, "%s : Specified word is too short%s", "randword", "\n");
      exit(1);
   }
   else if (paramLength > 20) {
      fprintf(stderr, "%s : Specified word is too long%s", "randword", "\n");
      exit(1);
   }
   strcpy(xWord, szparam);
}

canonical_original_code:
void argSetStopWord(char *szparam) {
   short paramLength = strlen(szparam);
   stopAfterWord = 1;
   if (paramLength < 3) {
      fprintf(stderr, "%s : Specified word is too short%s", "randword", "\n");
      exit(1);
   }
   else if (paramLength > 20) {
      fprintf(stderr, "%s : Specified word is too long%s", "randword", "\n");
      exit(1);
   }
   strcpy(xWord, szparam);
}

variable_types: paramLength short


argPrintHelp

decompiled_code:
void __noreturn argPrintHelp()
{
int v0; // er13
__int64 v1; // rbp
const char *v2; // rsi
unsigned __int16 v3; // bx

v0 = 0;
v1 = 0LL;
printf("Usage : %s [options] filename%s%s", "randword", "\n", "\n");
printf("Displays a list of randomly generated words.%s%s", "\n", "\n");
if ( LOBYTE(arg[0]) )
{
do
{
v2 = (const char *)&arg[4 * v1];
if ( WORD1(arg[4 * v1 + 1]) )
{
v3 = 0;
printf(" -%s arg", v2);
while ( v3 < 12 - strlen((const char *)&arg[4 * v1]) )
{
++v3;
putchar(32);
}
}
else
{
printf(" -%-10s ", v2);
}
++v0;
((void (*)(void))arg[4 * v1 + 3])();
v1 = (unsigned __int16)v0;
}
while ( LOBYTE(arg[4 * (unsigned __int16)v0]) );
}
putchar(10);
printf("Send bugs and comments to %s <%s>%s", "Erik Gillespie", "erik.gillespie@gmail.com", "\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func19()
{
int v0; // er13
__int64 v1; // rbp
const char *v2; // rsi
unsigned __int16 v3; // bx

v0 = 0;
v1 = 0LL;
printf("Usage : %s [options] filename%s%s", "randword", "\n", "\n");
printf("Displays a list of randomly generated words.%s%s", "\n", "\n");
if ( LOBYTE(arg[0]) )
{
do
{
v2 = (const char *)&arg[4 * v1];
if ( WORD1(arg[4 * v1 + 1]) )
{
v3 = 0;
printf(" -%s arg", v2);
while ( v3 < 12 - strlen((const char *)&arg[4 * v1]) )
{
++v3;
putchar(32);
}
}
else
{
printf(" -%-10s ", v2);
}
++v0;
((void (*)(void))arg[4 * v1 + 3])();
v1 = (unsigned __int16)v0;
}
while ( LOBYTE(arg[4 * (unsigned __int16)v0]) );
}
putchar(10);
printf("Send bugs and comments to %s <%s>%s", "Erik Gillespie", "erik.gillespie@gmail.com", "\n");
exit(0);
}

original_code:
void argPrintHelp(char* szparam) {
   unsigned short i, j;
   printf("Usage : %s [options] filename%s%s", "randword", "\n", "\n");
   printf("Displays a list of randomly generated words.%s%s", "\n", "\n");
   i = 0;
   while (*arg[i].argName) {
      if (arg[i].argHasArg) {
         printf("  -%s arg", arg[i].argName);
         for (j = 0; j < 12 - strlen(arg[i].argName); j++)
            printf(" ");
      }
      else
         printf("  -%-10s      ", arg[i].argName);
      arg[i].argInfo();
      i++;
   }
   printf("%s", "\n");
   printf("Send bugs and comments to %s <%s>%s", "Erik Gillespie", "erik.gillespie@gmail.com", "\n");
   exit(0);
}

canonical_original_code:
void argPrintHelp(char *szparam) {
   unsigned short i; unsigned short j;
   printf("Usage : %s [options] filename%s%s", "randword", "\n", "\n");
   printf("Displays a list of randomly generated words.%s%s", "\n", "\n");
   i = 0;
   while (*arg[i].argName) {
      if (arg[i].argHasArg) {
         printf("  -%s arg", arg[i].argName);
         for (j = 0; j < 12 - strlen(arg[i].argName); j++)
            printf(" ");
      }
      else
         printf("  -%-10s      ", arg[i].argName);
      arg[i].argInfo();
      i++;
   }
   printf("%s", "\n");
   printf("Send bugs and comments to %s <%s>%s", "Erik Gillespie", "erik.gillespie@gmail.com", "\n");
   exit(0);
}

variable_types:
i
unsigned short

variable_types:
j
unsigned short


argSanityCheck

decompiled_code:
__int64 argSanityCheck()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)maxWordLength;
if ( minWordLength > maxWordLength )
{
fprintf(stderr, "%s : Minimum word length exceeds maximum word length%s", "randword", "\n");
LABEL_15:
exit(1);
}
if ( quiet && verbose )
{
fprintf(stderr, "%s : Only one of -q and -v may be specified%s", "randword", "\n");
goto LABEL_15;
}
if ( stopAfterWord )
{
v1 = strlen(xWord);
result = CheckOnDisk(xWord, (unsigned int)v1);
if ( !(_DWORD)result )
{
fprintf(stderr, "%s : Specified word is not in the dictionary%s", "randword", "\n");
exit(1);
}
if ( minWordLength > v1 || maxWordLength < v1 )
{
fprintf(stderr, "%s : The specified word will never be found%s", "randword", "\n");
goto LABEL_15;
}
}
if ( stopAfterLength )
{
result = (unsigned int)xLength;
if ( (int)result < minWordLength || (int)result > maxWordLength )
{
fprintf(stderr, "%s : A word of the specified length will never be found%s", "randword", "\n");
goto LABEL_15;
}
}
return result;
}

canonical_decompiled_code:
__int64 func20()
{
__int64 result; // rax
int v1; // ebx

result = (unsigned int)maxWordLength;
if ( minWordLength > maxWordLength )
{
fprintf(stderr, "%s : Minimum word length exceeds maximum word length%s", "randword", "\n");
LABEL_15:
exit(1);
}
if ( quiet && verbose )
{
fprintf(stderr, "%s : Only one of -q and -v may be specified%s", "randword", "\n");
goto LABEL_15;
}
if ( stopAfterWord )
{
v1 = strlen(xWord);
result = CheckOnDisk(xWord, (unsigned int)v1);
if ( !(_DWORD)result )
{
fprintf(stderr, "%s : Specified word is not in the dictionary%s", "randword", "\n");
exit(1);
}
if ( minWordLength > v1 || maxWordLength < v1 )
{
fprintf(stderr, "%s : The specified word will never be found%s", "randword", "\n");
goto LABEL_15;
}
}
if ( stopAfterLength )
{
result = (unsigned int)xLength;
if ( (int)result < minWordLength || (int)result > maxWordLength )
{
fprintf(stderr, "%s : A word of the specified length will never be found%s", "randword", "\n");
goto LABEL_15;
}
}
return result;
}

original_code:
void argSanityCheck(void) {
   int xWordLen;
   if (minWordLength > maxWordLength) {
      fprintf(stderr, "%s : Minimum word length exceeds maximum word length%s", "randword", "\n");
      exit(1);
   }
   if (quiet && verbose) {
      fprintf(stderr, "%s : Only one of -q and -v may be specified%s", "randword", "\n");
      exit(1);
   }
   if (stopAfterWord) {
      xWordLen = strlen(xWord);
      if (CheckOnDisk(xWord, xWordLen) == 0) {
  fprintf(stderr, "%s : Specified word is not in the dictionary%s", "randword", "\n");
  exit(1);
      }
      else if (xWordLen < minWordLength || xWordLen > maxWordLength) {
         fprintf(stderr, "%s : The specified word will never be found%s", "randword", "\n");
         exit(1);
      }
   }
   if (stopAfterLength) {
      if (xLength < minWordLength || xLength > maxWordLength) {
         fprintf(stderr, "%s : A word of the specified length will never be found%s", "randword", "\n");
         exit(1);
      }
   }
}

canonical_original_code:
void argSanityCheck() {
   int xWordLen;
   if (minWordLength > maxWordLength) {
      fprintf(stderr, "%s : Minimum word length exceeds maximum word length%s", "randword", "\n");
      exit(1);
   }
   if (quiet && verbose) {
      fprintf(stderr, "%s : Only one of -q and -v may be specified%s", "randword", "\n");
      exit(1);
   }
   if (stopAfterWord) {
      xWordLen = strlen(xWord);
      if (CheckOnDisk(xWord, xWordLen) == 0) {
  fprintf(stderr, "%s : Specified word is not in the dictionary%s", "randword", "\n");
  exit(1);
      }
      else if (xWordLen < minWordLength || xWordLen > maxWordLength) {
         fprintf(stderr, "%s : The specified word will never be found%s", "randword", "\n");
         exit(1);
      }
   }
   if (stopAfterLength) {
      if (xLength < minWordLength || xLength > maxWordLength) {
         fprintf(stderr, "%s : A word of the specified length will never be found%s", "randword", "\n");
         exit(1);
      }
   }
}

variable_types: xWordLen int


parseArgs

decompiled_code:
__int64 __fastcall parseArgs(int a1, __int64 a2)
{
unsigned int v2; // er12
_BYTE *v3; // rcx
__int64 v4; // r15
const char *v5; // r13
int v6; // ebp
__int64 v7; // rbx
__int64 *v8; // rbx

if ( a1 < 0 )
{
fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
LABEL_18:
exit(1);
}
v2 = 1;
if ( a1 <= 1 )
return 0;
while ( 1 )
{
v3 = *(_BYTE **)(a2 + 8LL * (__int16)v2);
v4 = 8LL * (__int16)v2;
if ( *v3 != 45 )
break;
v5 = v3 + 1;
if ( !LOBYTE(arg[0]) )
{
LABEL_8:
fprintf(stderr, "%s : invalid argument -%s%s", "randword", v5, "\n");
exit(1);
}
v6 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = &arg[4 * v7];
if ( !strcmp(v5, (const char *)v8) )
break;
v7 = (__int16)++v6;
if ( !LOBYTE(arg[4 * (__int16)v6]) )
goto LABEL_8;
}
if ( *((_WORD *)v8 + 5) )
{
if ( (__int16)v2 == a1 - 1 )
{
fprintf(stderr, "%s : %s parameter is incomplete", "randword", v5);
goto LABEL_18;
}
++v2;
((void (__fastcall *)(_QWORD))v8[2])(*(_QWORD *)(a2 + v4 + 8));
}
else
{
((void (__fastcall *)(_QWORD))v8[2])(0LL);
}
if ( (__int16)++v2 >= a1 )
return 0;
}
argSanityCheck();
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1, __int64 a2)
{
unsigned int v2; // er12
_BYTE *v3; // rcx
__int64 v4; // r15
const char *v5; // r13
int v6; // ebp
__int64 v7; // rbx
__int64 *v8; // rbx

if ( a1 < 0 )
{
fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
LABEL_18:
exit(1);
}
v2 = 1;
if ( a1 <= 1 )
return 0;
while ( 1 )
{
v3 = *(_BYTE **)(a2 + 8LL * (__int16)v2);
v4 = 8LL * (__int16)v2;
if ( *v3 != 45 )
break;
v5 = v3 + 1;
if ( !LOBYTE(arg[0]) )
{
LABEL_8:
fprintf(stderr, "%s : invalid argument -%s%s", "randword", v5, "\n");
exit(1);
}
v6 = 0;
v7 = 0LL;
while ( 1 )
{
v8 = &arg[4 * v7];
if ( !strcmp(v5, (const char *)v8) )
break;
v7 = (__int16)++v6;
if ( !LOBYTE(arg[4 * (__int16)v6]) )
goto LABEL_8;
}
if ( *((_WORD *)v8 + 5) )
{
if ( (__int16)v2 == a1 - 1 )
{
fprintf(stderr, "%s : %s parameter is incomplete", "randword", v5);
goto LABEL_18;
}
++v2;
((void (__fastcall *)(_QWORD))v8[2])(*(_QWORD *)(a2 + v4 + 8));
}
else
{
((void (__fastcall *)(_QWORD))v8[2])(0LL);
}
if ( (__int16)++v2 >= a1 )
return 0;
}
func20();
return v2;
}

original_code:
short parseArgs(int argc, char **argv) {
   short i, j, found;
   char *szparam = 0;
   if (argc < 0) {
      fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
      exit(1);
   }
   for (i = 1; i < argc; i++) {
      szparam = argv[i];
      if (*szparam != '-') {
         argSanityCheck();
         return i;
      }
      else
         szparam++;
      found = 0;
      j = 0;
      if (argc < 0 + 1) {
         fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
         exit(1);
      }
      while (*arg[j].argName && !found) {
         if (strcmp(szparam, arg[j].argName) == 0) {
            if (arg[j].argHasArg) {
               if (i == argc - 1) {
                  fprintf(stderr, "%s : %s parameter is incomplete", "randword", szparam);
                  exit(1);
               }
               arg[j].argFunc(argv[i+1]);
               i++;
            }
            else
               arg[j].argFunc(0);
            found = 1;
         }
         j++;
      }
      if (!found) {
         fprintf(stderr, "%s : invalid argument -%s%s", "randword", szparam, "\n");
         exit(1);
      }
   }
   return 0;
}

canonical_original_code:
short parseArgs(int argc, char **argv) {
   short i; short j; short found;
   char *szparam = 0;
   if (argc < 0) {
      fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
      exit(1);
   }
   for (i = 1; i < argc; i++) {
      szparam = argv[i];
      if (*szparam != '-') {
         argSanityCheck();
         return i;
      }
      else
         szparam++;
      found = 0;
      j = 0;
      if (argc < 0 + 1) {
         fprintf(stderr, "%s : too few arguments%s", "randword", "\n");
         exit(1);
      }
      while (*arg[j].argName && !found) {
         if (strcmp(szparam, arg[j].argName) == 0) {
            if (arg[j].argHasArg) {
               if (i == argc - 1) {
                  fprintf(stderr, "%s : %s parameter is incomplete", "randword", szparam);
                  exit(1);
               }
               arg[j].argFunc(argv[i+1]);
               i++;
            }
            else
               arg[j].argFunc(0);
            found = 1;
         }
         j++;
      }
      if (!found) {
         fprintf(stderr, "%s : invalid argument -%s%s", "randword", szparam, "\n");
         exit(1);
      }
   }
   return 0;
}

variable_types: argc int

variable_types: j short

variable_types: found short

return_type: short


SigHandler

decompiled_code:
void __fastcall SigHandler(int a1)
{
if ( a1 == 2 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 2 )
exit(0);
}

original_code:
void SigHandler(int sig) {
   if (sig == 2)
      exit(0);
}

variable_types: sig int


ExitProgram

decompiled_code:
void ExitProgram()
{
void *v0; // r14
void **v1; // rbp
__int64 i; // r13
_QWORD *v3; // r8
__int64 v4; // r12
__int64 v5; // rbx
void *v6; // rdi

if ( !quiet )
{
putchar(10);
printf("Tries: %ld%s", totalcount, "\n");
printf("Hits: %ld%s", numfound, "\n");
printf("Misses: %ld%s", totalcount - numfound, "\n");
}
if ( !searchOnDisk )
{
v0 = dict;
if ( dict )
{
v1 = (void **)dict;
for ( i = 0LL; maxWordLength - minWordLength >= (int)i; ++i )
{
v3 = *v1;
if ( !*v1 )
break;
v4 = wordsOnPage[i];
if ( v4 )
{
v5 = 0LL;
while ( 1 )
{
v6 = (void *)v3[v5];
if ( !v6 )
break;
free(v6);
++v5;
v3 = *v1;
if ( v5 == v4 )
goto LABEL_14;
}
free(v3);
break;
}
LABEL_14:
++v1;
free(v3);
}
free(v0);
}
}
}

canonical_decompiled_code:
void func1()
{
void *v0; // r14
void **v1; // rbp
__int64 i; // r13
_QWORD *v3; // r8
__int64 v4; // r12
__int64 v5; // rbx
void *v6; // rdi

if ( !quiet )
{
putchar(10);
printf("Tries: %ld%s", totalcount, "\n");
printf("Hits: %ld%s", numfound, "\n");
printf("Misses: %ld%s", totalcount - numfound, "\n");
}
if ( !searchOnDisk )
{
v0 = dict;
if ( dict )
{
v1 = (void **)dict;
for ( i = 0LL; maxWordLength - minWordLength >= (int)i; ++i )
{
v3 = *v1;
if ( !*v1 )
break;
v4 = wordsOnPage[i];
if ( v4 )
{
v5 = 0LL;
while ( 1 )
{
v6 = (void *)v3[v5];
if ( !v6 )
break;
free(v6);
++v5;
v3 = *v1;
if ( v5 == v4 )
goto LABEL_14;
}
free(v3);
break;
}
LABEL_14:
++v1;
free(v3);
}
free(v0);
}
}
}

original_code:
void ExitProgram(void) {
   int i;
   unsigned long j;
   short stop = 0;
   if (!quiet) {
      printf("%s", "\n");
      printf("Tries:  %ld%s", totalcount, "\n");
      printf("Hits:   %ld%s", numfound, "\n");
      printf("Misses: %ld%s", totalcount - numfound, "\n");
   }
   if (!searchOnDisk) {
      if (dict != ((void *)0)) {
  for (i = 0; i < maxWordLength - minWordLength + 1 && !stop; i++) {
     if (dict[i] != ((void *)0)) {
        for (j = 0; j < wordsOnPage[i]; j++) {
    if (dict[i][j] != ((void *)0))
       free(dict[i][j]);
    else {
       stop = 1;
       break;
    }
        }
        free(dict[i]);
     }
     else
        break;
  }
  free(dict);
      }
   }
}

canonical_original_code:
void ExitProgram() {
   int i;
   unsigned long j;
   short stop = 0;
   if (!quiet) {
      printf("%s", "\n");
      printf("Tries:  %ld%s", totalcount, "\n");
      printf("Hits:   %ld%s", numfound, "\n");
      printf("Misses: %ld%s", totalcount - numfound, "\n");
   }
   if (!searchOnDisk) {
      if (dict != ((void *)0)) {
  for (i = 0; i < maxWordLength - minWordLength + 1 && !stop; i++) {
     if (dict[i] != ((void *)0)) {
        for (j = 0; j < wordsOnPage[i]; j++) {
    if (dict[i][j] != ((void *)0))
       free(dict[i][j]);
    else {
       stop = 1;
       break;
    }
        }
        free(dict[i]);
     }
     else
        break;
  }
  free(dict);
      }
   }
}

variable_types: i int

variable_types:
j
unsigned long


CheckInMem

decompiled_code:
__int64 __fastcall CheckInMem(char *s1, int a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // r13
_QWORD *v5; // r14
__int64 v6; // rdx
int v7; // eax

v2 = a2 - minWordLength;
upr_1 = wordsOnPage[v2];
lwr_2 = -1LL;
v3 = (upr_1 - 1) / 2;
cur_0 = v3;
if ( upr_1 != v3 )
{
v4 = -1LL;
v5 = (char *)dict + 8 * v2;
while ( v4 != v3 )
{
v7 = strncmp(s1, *(const char **)(*v5 + 8 * v3), a2);
if ( !v7 )
return 1LL;
if ( v7 > 0 )
{
lwr_2 = v3;
v6 = upr_1;
v4 = v3;
}
else
{
upr_1 = v3;
v6 = v3;
}
v3 = (v4 + v6) / 2;
cur_0 = v3;
if ( v3 == v6 )
return 0LL;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s1, int a2)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // r13
_QWORD *v5; // r14
__int64 v6; // rdx
int v7; // eax

v2 = a2 - minWordLength;
upr_1 = wordsOnPage[v2];
lwr_2 = -1LL;
v3 = (upr_1 - 1) / 2;
cur_0 = v3;
if ( upr_1 != v3 )
{
v4 = -1LL;
v5 = (char *)dict + 8 * v2;
while ( v4 != v3 )
{
v7 = strncmp(s1, *(const char **)(*v5 + 8 * v3), a2);
if ( !v7 )
return 1LL;
if ( v7 > 0 )
{
lwr_2 = v3;
v6 = upr_1;
v4 = v3;
}
else
{
upr_1 = v3;
v6 = v3;
}
v3 = (v4 + v6) / 2;
cur_0 = v3;
if ( v3 == v6 )
return 0LL;
}
}
return 0LL;
}

original_code:
int CheckInMem(const char *aword, int buflen) {
   static long lwr, upr, cur;
   register int cmp;
   register int idx = buflen - minWordLength;
   lwr = -1;
   upr = wordsOnPage[idx];
   cur = (upr + lwr) / 2;
   while ((cur != upr) && (cur != lwr)) {
      cmp = strncmp(aword, dict[idx][cur], buflen);
      if (cmp == 0)
  return 1;
      else if (cmp > 0)
  lwr = cur;
      else
  upr = cur;
      cur = (lwr + upr) / 2;
   }
   return 0;
}

canonical_original_code:
int CheckInMem(char *aword, int buflen) {
   static long lwr; static long upr; static long cur;
   register int cmp;
   register int idx = buflen - minWordLength;
   lwr = -1;
   upr = wordsOnPage[idx];
   cur = (upr + lwr) / 2;
   while ((cur != upr) && (cur != lwr)) {
      cmp = strncmp(aword, dict[idx][cur], buflen);
      if (cmp == 0)
  return 1;
      else if (cmp > 0)
  lwr = cur;
      else
  upr = cur;
      cur = (lwr + upr) / 2;
   }
   return 0;
}

variable_types:
aword
char *

variable_types: buflen int

variable_types: lwr long

variable_types: upr long

variable_types: cur long

variable_types: cmp int

variable_types: idx int


CheckWord

decompiled_code:
__int64 __fastcall CheckWord(char *s1, unsigned int a2)
{
__int64 result; // rax

if ( searchOnDisk )
result = CheckOnDisk(s1, a2);
else
result = CheckInMem(s1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s1, unsigned int a2)
{
__int64 result; // rax

if ( searchOnDisk )
result = func4(s1, a2);
else
result = func5(s1, a2);
return result;
}

original_code:
int CheckWord(const char *aword, int buflen) {
   return (searchOnDisk ? CheckOnDisk(aword, buflen) : CheckInMem(aword, buflen));
}

canonical_original_code:
int CheckWord(char *aword, int buflen) {
   return (searchOnDisk ? CheckOnDisk(aword, buflen) : CheckInMem(aword, buflen));
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
int v4; // eax
int result; // eax
char *v6; // rax

chdir("/bbs/core/bbs");
umask(0x17u);
if ( (int)openfiles() < 0 )
return -1;
if ( argc <= 1 )
{
v4 = 1;
}
else
{
v3 = argv[1];
v4 = 1;
if ( *v3 == 45 )
{
switch ( v3[1] )
{
case 'b':
v4 = 0;
if ( argc == 3 )
v4 = 7;
break;
case 'c':
v4 = 8;
break;
case 'f':
v4 = 2;
break;
case 'i':
v4 = 4;
break;
case 'q':
v4 = 3;
break;
case 's':
v4 = 5;
break;
case 'u':
v4 = 6;
break;
default:
exit(1);
}
}
}
while ( 2 )
{
switch ( v4 )
{
case 1:
ARGV = argv;
bbsstart();
result = 0;
break;
case 2:
bbsfinger();
result = 0;
break;
case 3:
v6 = getenv("INIT_VERSION");
bbsqueue(v6 == 0LL);
result = 0;
break;
case 4:
v4 = bbssync(1LL);
continue;
case 5:
bbssync(0LL);
result = 0;
break;
case 6:
nice(40);
bbsupdate();
result = 0;
break;
case 7:
nice(40);
bbsbackup(argv[2]);
result = 0;
break;
case 8:
clone_populate_forums();
clone_populate_posts();
clone_populate_users();
result = 0;
break;
default:
result = 0;
break;
}
break;
}
return result;
}

original_code:
int
main(register int argc, register char **argv)
{
  register int cmd = 0;
  chdir("/bbs/core/bbs");
  umask(027);
  if (openfiles() < 0)
    return(-1);
  if (argc < 2 || *argv[1] != '-')
    cmd = 1;
  else
    switch (argv[1][1])
    {
      case 'b':
 if (argc == 3)
          cmd = 7;
        break;
      case 'f':
        cmd = 2;
        break;
      case 'i':
        cmd = 4;
        break;
      case 's':
        cmd = 5;
        break;
      case 'q':
        cmd = 3;
        break;
      case 'u':
        cmd = 6;
        break;
      case 'c':
        cmd = 8;
        break;
      default:
        _exit(1);
        break;
    }
  for (;;)
  {
    switch (cmd)
    {
      case 1:
        ARGV = argv;
        bbsstart();
        break;
      case 2:
        bbsfinger();
        break;
      case 4:
        cmd = bbssync(1);
        continue;
      case 5:
        bbssync(0);
        break;
      case 6:
 nice(40);
        bbsupdate();
        break;
      case 7:
 nice(40);
        bbsbackup(argv[2]);
        break;
      case 3:
        bbsqueue(getenv("INIT_VERSION") ? 0 : 1);
 break;
      case 8:
 if (1) clone_populate_forums();
        if (1) clone_populate_posts();
 if (1) clone_populate_users();
 break;
      default:
        break;
    }
    break;
  }
  return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  register int cmd = 0;
  chdir("/bbs/core/bbs");
  umask(027);
  if (openfiles() < 0)
    return(-1);
  if (argc < 2 || *argv[1] != '-')
    cmd = 1;
  else
    switch (argv[1][1])
    {
      case 'b':
 if (argc == 3)
          cmd = 7;
        break;
      case 'f':
        cmd = 2;
        break;
      case 'i':
        cmd = 4;
        break;
      case 's':
        cmd = 5;
        break;
      case 'q':
        cmd = 3;
        break;
      case 'u':
        cmd = 6;
        break;
      case 'c':
        cmd = 8;
        break;
      default:
        _exit(1);
        break;
    }
  for (;;)
  {
    switch (cmd)
    {
      case 1:
        ARGV = argv;
        bbsstart();
        break;
      case 2:
        bbsfinger();
        break;
      case 4:
        cmd = bbssync(1);
        continue;
      case 5:
        bbssync(0);
        break;
      case 6:
 nice(40);
        bbsupdate();
        break;
      case 7:
 nice(40);
        bbsbackup(argv[2]);
        break;
      case 3:
        bbsqueue(getenv("INIT_VERSION") ? 0 : 1);
 break;
      case 8:
 if (1) clone_populate_forums();
        if (1) clone_populate_posts();
 if (1) clone_populate_users();
 break;
      default:
        break;
    }
    break;
  }
  return(0);
}

variable_types:
argv
char **

variable_types: cmd int


decompiled_code:
const char *__fastcall login_user(const char *a1, const char *a2)
{
bool v2; // cf
bool v3; // zf
__int64 v5; // rcx
const char *v6; // rdi
const char *v8; // rsi
__int64 v9; // rax
const char *v10; // r12
char *v11; // rbp
char *v13; // rsi

v5 = 6LL;
v6 = "Guest";
v8 = a1;
do
{
if ( !v5 )
break;
v2 = *v8 < (unsigned int)*v6;
v3 = *v8++ == *v6++;
--v5;
}
while ( v3 );
guest = (!v2 && !v3) == v2;
v9 = getuser(a1, v8);
if ( v9 )
{
v10 = (const char *)v9;
if ( guest )
{
v11 = (char *)mmap(0LL, 0x1808uLL, 3, 34, -1, 0LL);
if ( (unsigned __int64)(v11 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
{
bcopy(v10, v11, 0x1808uLL);
return v11;
}
}
else
{
if ( getenv("BBSNAME") )
return v10;
v13 = crypt(a2, v10 + 76);
if ( !strncmp(v10 + 76, v13, 0xDuLL) )
return v10;
freeuser(v10);
}
}
return 0LL;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1, const char *a2)
{
bool v2; // cf
bool v3; // zf
__int64 v5; // rcx
const char *v6; // rdi
const char *v8; // rsi
__int64 v9; // rax
const char *v10; // r12
char *v11; // rbp
char *v13; // rsi

v5 = 6LL;
v6 = "Guest";
v8 = a1;
do
{
if ( !v5 )
break;
v2 = *v8 < (unsigned int)*v6;
v3 = *v8++ == *v6++;
--v5;
}
while ( v3 );
guest = (!v2 && !v3) == v2;
v9 = getuser(a1, v8);
if ( v9 )
{
v10 = (const char *)v9;
if ( guest )
{
v11 = (char *)mmap(0LL, 0x1808uLL, 3, 34, -1, 0LL);
if ( (unsigned __int64)(v11 - 1) <= 0xFFFFFFFFFFFFFFFDLL )
{
bcopy(v10, v11, 0x1808uLL);
return v11;
}
}
else
{
if ( getenv("BBSNAME") )
return v10;
v13 = crypt(a2, v10 + 76);
if ( !strncmp(v10 + 76, v13, 0xDuLL) )
return v10;
freeuser(v10);
}
}
return 0LL;
}

original_code:
struct user *
login_user(char *name, char *passwd)
{
struct user *up;
char *cp;
  guest = !strcmp(name, "Guest");
  if (!(up = getuser(name)))
    return(((void *)0));
  if (guest)
  {
    struct user *tmpuser;
    tmpuser = (struct user *)mmap(0, sizeof(struct user), 0x1 | 0x2, 0x20 | 0x02, -1, 0);
    if (!tmpuser || tmpuser == (struct user *)-1)
      return(((void *)0));
    bcopy(up, tmpuser, sizeof(struct user));
    return(up = tmpuser);
  }
  if (!getenv("BBSNAME"))
  {
    cp = crypt(passwd, up->passwd);
    if (strncmp(up->passwd, cp, 13))
    {
      freeuser(up);
      return (((void *)0));
    }
  }
  return (up);
}

canonical_original_code:
struct user *login_user(char *name, char *passwd)
{
struct user *up;
char *cp;
  guest = !strcmp(name, "Guest");
  if (!(up = getuser(name)))
    return(((void *)0));
  if (guest)
  {
    struct user *tmpuser;
    tmpuser = (struct user *)mmap(0, sizeof(struct user), 0x1 | 0x2, 0x20 | 0x02, -1, 0);
    if (!tmpuser || tmpuser == (struct user *)-1)
      return(((void *)0));
    bcopy(up, tmpuser, sizeof(struct user));
    return(up = tmpuser);
  }
  if (!getenv("BBSNAME"))
  {
    cp = crypt(passwd, up->passwd);
    if (strncmp(up->passwd, cp, 13))
    {
      freeuser(up);
      return (((void *)0));
    }
  }
  return (up);
}

variable_types:
name
char *

variable_types:
passwd
char *

variable_types: struct user { long usernum; int; int; unsigned int; unsigned int an_all; unsigned int an_name; unsigned int an_addr; unsigned int an_location; unsigned int an_phone; unsigned int an_mail; unsigned int an_site; unsigned int an_www; unsigned int f_deleted; unsigned int f_inactive; unsigned int f_newbie; unsigned int f_badinfo; unsigned int f_prog; unsigned int f_restricted; unsigned int f_admin; unsigned int f_duplicate; unsigned int f_autoelf; unsigned int f_invisible; unsigned int f_trouble; unsigned int f_ansi; unsigned int f_noclient; unsigned int f_noanon; unsigned int f_namechanged; unsigned int f_ownnew; unsigned int f_twit; unsigned int; unsigned int f_xmsg; unsigned int f_nobeep; unsigned int f_elf; unsigned int; unsigned int f_aide; unsigned int; unsigned int f_xoff; unsigned int; int timescalled; int posted; long time; long timeoff; long timetot; char name[-1]; char passwd[14]; char remote[40]; char unused1[11]; char real_name[-1]; char addr1[-1]; char addr2[-1]; char city[21]; char state[21]; char zip[11]; char phone[21]; char mail[41]; char desc1[81]; char desc2[81]; char desc3[81]; char desc4[81]; char desc5[81]; char generation[200]; char forget[200]; long lastseen[200]; struct xconf { unsigned int which; unsigned int; unsigned int usernum; } xconf[60]; char www[60]; long xconftime; char unused2[176]; struct usermail { long num; long pos; } mr[150]; char unused3[9]; char aideinfo[81]; char reminder[81]; char loginname[16]; int; long totalx; char A_real_name[-1]; char A_addr1[-1]; char A_city[21]; char A_state[21]; char A_zip[11]; char A_phone[21]; char A_mail[41]; char dob_year; char dob_month; char dob_day; int; short btmpindex; unsigned short key; long keytime; long xseenpos; long xmaxpos; short xmsgnum; int; long xminpos; unsigned short yells; unsigned short vals; char unused4[24]; } *

variable_types:
cp
char *

user_defined_types: struct user { long usernum; int; int; unsigned int; unsigned int an_all; unsigned int an_name; unsigned int an_addr; unsigned int an_location; unsigned int an_phone; unsigned int an_mail; unsigned int an_site; unsigned int an_www; unsigned int f_deleted; unsigned int f_inactive; unsigned int f_newbie; unsigned int f_badinfo; unsigned int f_prog; unsigned int f_restricted; unsigned int f_admin; unsigned int f_duplicate; unsigned int f_autoelf; unsigned int f_invisible; unsigned int f_trouble; unsigned int f_ansi; unsigned int f_noclient; unsigned int f_noanon; unsigned int f_namechanged; unsigned int f_ownnew; unsigned int f_twit; unsigned int; unsigned int f_xmsg; unsigned int f_nobeep; unsigned int f_elf; unsigned int; unsigned int f_aide; unsigned int; unsigned int f_xoff; unsigned int; int timescalled; int posted; long time; long timeoff; long timetot; char name[-1]; char passwd[14]; char remote[40]; char unused1[11]; char real_name[-1]; char addr1[-1]; char addr2[-1]; char city[21]; char state[21]; char zip[11]; char phone[21]; char mail[41]; char desc1[81]; char desc2[81]; char desc3[81]; char desc4[81]; char desc5[81]; char generation[200]; char forget[200]; long lastseen[200]; struct xconf xconf[60]; char www[60]; long xconftime; char unused2[176]; struct usermail mr[150]; char unused3[9]; char aideinfo[81]; char reminder[81]; char loginname[16]; int; long totalx; char A_real_name[-1]; char A_addr1[-1]; char A_city[21]; char A_state[21]; char A_zip[11]; char A_phone[21]; char A_mail[41]; char dob_year; char dob_month; char dob_day; int; short btmpindex; unsigned short key; long keytime; long xseenpos; long xmaxpos; short xmsgnum; int; long xminpos; unsigned short yells; unsigned short vals; char unused4[24]; }


original_code:
void
change_password(struct user *up, char *old, char *new, int noold)
{
time_t salt;
char saltc[4];
int c,
        i;
                time(&salt);
  salt = 9 * pid;
  saltc[0] = salt & 077;
  saltc[1] = (salt >> 6) & 077;
  for (i = 0; i < 2; i++)
  {
    c = saltc[i] + '.';
    if (c > '9')
      c += 7;
    if (c > 'Z')
      c += 6;
    saltc[i] = c;
  }
  saltc[2] = 0;
  locks(2);
  strcpy(up->passwd, crypt(new, saltc));
  unlocks(2);
}

canonical_original_code:
void change_password(struct user *up, char *old, char *new, int noold)
{
long salt;
char saltc[4];
int c; int i;
                time(&salt);
  salt = 9 * pid;
  saltc[0] = salt & 077;
  saltc[1] = (salt >> 6) & 077;
  for (i = 0; i < 2; i++)
  {
    c = saltc[i] + '.';
    if (c > '9')
      c += 7;
    if (c > 'Z')
      c += 6;
    saltc[i] = c;
  }
  saltc[2] = 0;
  locks(2);
  strcpy(up->passwd, crypt(new, saltc));
  unlocks(2);
}

variable_types:
old
char *

variable_types:
new
char *

variable_types: noold int

variable_types: salt long

variable_types:
saltc
char [4]

variable_types: c int

user_defined_types: struct xconf { unsigned int which; unsigned int; unsigned int usernum; }


decompiled_code:
int __fastcall check_quit(char *s1)
{
int result; // eax

if ( !strcasecmp(s1, "exit") || !strcasecmp(s1, "quit") || (result = strcasecmp(s1, "logout")) == 0 )
{
puts("\n\nQuitting...");
result = my_exit(3LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1)
{
int result; // eax

if ( !strcasecmp(s1, "exit") || !strcasecmp(s1, "quit") || (result = strcasecmp(s1, "logout")) == 0 )
{
puts("\n\nQuitting...");
result = my_exit(3LL);
}
return result;
}

original_code:
void
check_quit(register char *s)
{
  if (!strcasecmp(s, "exit") || !strcasecmp(s, "quit") || !strcasecmp(s, "logout"))
  {
    printf("\n\nQuitting...\n");
    my_exit(3);
  }
}

canonical_original_code:
void check_quit(char *s)
{
  if (!strcasecmp(s, "exit") || !strcasecmp(s, "quit") || !strcasecmp(s, "logout"))
  {
    printf("\n\nQuitting...\n");
    my_exit(3);
  }
}

variable_types:
s
char *