repo: nlasso/pancetaYHuevoFrito

decompiled_code:
int __fastcall check_idx(char *filename, int a2)
{
char *v2; // rbx
char *v4; // rax
char *v5; // rcx
char *v6; // rdx
__int64 v7; // rax
int v8; // edi
bool v9; // si
int v10; // er12
char v11; // dl
__int64 v12; // rax
bool v13; // si
FILE *v14; // rax
char *v15; // rdi

v2 = filename;
v4 = strrchr(filename, 46);
if ( !v4 || (v5 = v4, filename == v4) || (v6 = filename, v7 = 1LL, v5[1] == 47) )
{
v11 = *filename;
v12 = 1LL;
v8 = 0;
v10 = 0;
if ( !v11 )
goto LABEL_10;
do
{
v8 = v12;
byte_15BF[v12] = v11;
v11 = v2[v12];
v13 = (int)v12++ <= 255;
}
while ( v11 != 0 && v13 );
v10 = 0;
}
else
{
do
{
++v6;
v8 = v7;
byte_15BF[v7] = *(v6 - 1);
v9 = (int)v7++ <= 255;
}
while ( v9 && v5 != v6 );
v10 = 1;
}
if ( v8 > 255 )
{
fprintf(stderr, "Index file name %s too long (max %d).\n", base, 256LL);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
LABEL_10:
base[v8] = 0;
idx_fn = v2;
if ( a2 )
{
v14 = fopen(v2, "r");
idx_fp = (__int64)v14;
if ( v14 )
return (int)v14;
}
else
{
LODWORD(v14) = access(v2, 4);
if ( !(_DWORD)v14 )
return (int)v14;
}
if ( v10 )
{
fprintf(stderr, "Input index file %s not found.\n", idx_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
v15 = (char *)malloc(0x100uLL);
idx_fn = v15;
if ( !v15 )
{
fprintf(stderr, "Not enough core...abort.\n");
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
sprintf(v15, "%s%s", base, ".idx");
if ( a2 )
{
v14 = fopen(idx_fn, "r");
idx_fp = (__int64)v14;
if ( !v14 )
goto LABEL_23;
}
else
{
LODWORD(v14) = access(idx_fn, 4);
if ( (_DWORD)v14 )
{
LABEL_23:
fprintf(stderr, "Couldn't find input index file %s nor %s.\n", base, idx_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
}
return (int)v14;
}

canonical_decompiled_code:
int __fastcall func0(char *filename, int a2)
{
char *v2; // rbx
char *v4; // rax
char *v5; // rcx
char *v6; // rdx
__int64 v7; // rax
int v8; // edi
bool v9; // si
int v10; // er12
char v11; // dl
__int64 v12; // rax
bool v13; // si
FILE *v14; // rax
char *v15; // rdi

v2 = filename;
v4 = strrchr(filename, 46);
if ( !v4 || (v5 = v4, filename == v4) || (v6 = filename, v7 = 1LL, v5[1] == 47) )
{
v11 = *filename;
v12 = 1LL;
v8 = 0;
v10 = 0;
if ( !v11 )
goto LABEL_10;
do
{
v8 = v12;
byte_15BF[v12] = v11;
v11 = v2[v12];
v13 = (int)v12++ <= 255;
}
while ( v11 != 0 && v13 );
v10 = 0;
}
else
{
do
{
++v6;
v8 = v7;
byte_15BF[v7] = *(v6 - 1);
v9 = (int)v7++ <= 255;
}
while ( v9 && v5 != v6 );
v10 = 1;
}
if ( v8 > 255 )
{
fprintf(stderr, "Index file name %s too long (max %d).\n", base, 256LL);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
LABEL_10:
base[v8] = 0;
idx_fn = v2;
if ( a2 )
{
v14 = fopen(v2, "r");
idx_fp = (__int64)v14;
if ( v14 )
return (int)v14;
}
else
{
LODWORD(v14) = access(v2, 4);
if ( !(_DWORD)v14 )
return (int)v14;
}
if ( v10 )
{
fprintf(stderr, "Input index file %s not found.\n", idx_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
v15 = (char *)malloc(0x100uLL);
idx_fn = v15;
if ( !v15 )
{
fprintf(stderr, "Not enough core...abort.\n");
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
sprintf(v15, "%s%s", base, ".idx");
if ( a2 )
{
v14 = fopen(idx_fn, "r");
idx_fp = (__int64)v14;
if ( !v14 )
goto LABEL_23;
}
else
{
LODWORD(v14) = access(idx_fn, 4);
if ( (_DWORD)v14 )
{
LABEL_23:
fprintf(stderr, "Couldn't find input index file %s nor %s.\n", base, idx_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
}
return (int)v14;
}

original_code:
static void
check_idx(char *fn, int open_fn)
{
    char *ptr = fn;
    char *ext;
    int with_ext = 0;
    int i = 0;
    ext = strrchr(fn, '.');
    if ((ext != ((void *)0)) && (ext != fn) && (*(ext + 1) != '/')) {
 with_ext = 1;
 while ((ptr != ext) && (i < 256))
     base[i++] = *ptr++;
    } else
 while ((*ptr != '\0') && (i < 256))
     base[i++] = *ptr++;
    if (i < 256)
 base[i] = '\0';
    else
 { fprintf(stderr, "Index file name %s too long (max %d).\n", base, 256); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
    idx_fn = fn;
    if ( ( open_fn &&
  ((idx_fp = fopen(idx_fn, "r")) == ((void *)0))
  ) ||
 ((!open_fn) && (access(idx_fn, 4) != 0)))
 if (with_ext) {
     { fprintf(stderr, "Input index file %s not found.\n", idx_fn); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
 } else {
     if ((idx_fn = (char *) malloc(256)) == ((void *)0))
  { fprintf(stderr, "Not enough core...abort.\n", ""); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
     sprintf(idx_fn, "%s%s", base, ".idx");
     if ((open_fn &&
  ((idx_fp = fopen(idx_fn, "r")) == ((void *)0))
 ) ||
  ((!open_fn) && (access(idx_fn, 4) != 0))) {
  { fprintf(stderr, "Couldn't find input index file %s nor %s.\n", base, idx_fn); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
     }
 }
}

variable_types:
fn
char *

variable_types:
ptr
char *

variable_types:
ext
char *


decompiled_code:
int find_pageno()
{
int v0; // ebx
int v1; // ebp
int v2; // eax
int v3; // ebx
__int64 v4; // rbp
int v5; // er12
const unsigned __int16 *v6; // rax

fseek(log_fp, -1LL, 2);
v0 = getc(log_fp);
fseek(log_fp, -2LL, 1);
while ( 1 )
{
v1 = v0;
v0 = getc(log_fp);
if ( v0 == 91 && ((*_ctype_b_loc())[v1] & 0x800) != 0 )
break;
if ( fseek(log_fp, -2LL, 1) )
{
if ( v0 != 91 )
{
LODWORD(v6) = fprintf(ilg_fp, "Couldn't find any page number in %s...ignored\n", log_fn);
init_page = 0;
return (int)v6;
}
goto LABEL_5;
}
}
do
{
LABEL_5:
v2 = getc(log_fp);
LOBYTE(v3) = v2;
}
while ( v2 == 32 );
v4 = 1LL;
do
{
v5 = v4;
*(&pageno + v4 - 1) = v3;
v3 = getc(log_fp);
++v4;
v6 = *_ctype_b_loc();
}
while ( (v6[v3] & 0x800) != 0 );
*(&pageno + v5) = 0;
return (int)v6;
}

canonical_decompiled_code:
int func2()
{
int v0; // ebx
int v1; // ebp
int v2; // eax
int v3; // ebx
__int64 v4; // rbp
int v5; // er12
const unsigned __int16 *v6; // rax

fseek(log_fp, -1LL, 2);
v0 = getc(log_fp);
fseek(log_fp, -2LL, 1);
while ( 1 )
{
v1 = v0;
v0 = getc(log_fp);
if ( v0 == 91 && ((*_ctype_b_loc())[v1] & 0x800) != 0 )
break;
if ( fseek(log_fp, -2LL, 1) )
{
if ( v0 != 91 )
{
LODWORD(v6) = fprintf(ilg_fp, "Couldn't find any page number in %s...ignored\n", log_fn);
init_page = 0;
return (int)v6;
}
goto LABEL_5;
}
}
do
{
LABEL_5:
v2 = getc(log_fp);
LOBYTE(v3) = v2;
}
while ( v2 == 32 );
v4 = 1LL;
do
{
v5 = v4;
*(&pageno + v4 - 1) = v3;
v3 = getc(log_fp);
++v4;
v6 = *_ctype_b_loc();
}
while ( (v6[v3] & 0x800) != 0 );
*(&pageno + v5) = 0;
return (int)v6;
}

original_code:
static void
find_pageno(void)
{
    int i = 0;
    int p, c;
    fseek(log_fp, -1L, 2);
    p = getc(log_fp);
    fseek(log_fp, -2L, 1);
    do {
 c = p;
 p = getc(log_fp);
    } while (!(((p == '[') && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit)) || (fseek(log_fp, -2L, 1) != 0)));
    if (p == '[') {
 while ((c = getc(log_fp)) == ' ');
 do {
     pageno[i++] = (char) c;
     c = getc(log_fp);
 } while (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short int) _ISdigit));
 pageno[i] = '\0';
    } else {
 fprintf(ilg_fp, "Couldn't find any page number in %s...ignored\n",
  log_fn);
 init_page = 0;
    }
}

canonical_original_code:
static void find_pageno()
{
    int i = 0;
    int p; int c;
    fseek(log_fp, -1L, 2);
    p = getc(log_fp);
    fseek(log_fp, -2L, 1);
    do {
 c = p;
 p = getc(log_fp);
    } while (!(((p == '[') && ((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit)) || (fseek(log_fp, -2L, 1) != 0)));
    if (p == '[') {
 while ((c = getc(log_fp)) == ' ');
 do {
     pageno[i++] = (char) c;
     c = getc(log_fp);
 } while (((*__ctype_b_loc ())[(int) ((c))] & (unsigned short) _ISdigit));
 pageno[i] = '\0';
    } else {
 fprintf(ilg_fp, "Couldn't find any page number in %s...ignored\n",
  log_fn);
 init_page = 0;
    }
}

variable_types: i int

variable_types: p int

variable_types: c int

return_type: void


decompiled_code:
int __fastcall check_all(char *a1, int a2, int a3, int a4)
{
FILE *v6; // rax

check_idx(a1, 1);
if ( !a2 )
{
sprintf(ind, "%s%s", base, ".ind");
ind_fn = ind;
}
ind_fp = fopen(ind_fn, "w");
if ( !ind_fp )
{
fprintf(stderr, "Can't create output index file %s.\n", ind_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
if ( !a3 )
{
sprintf(ilg, "%s%s", base, ".ilg");
ilg_fn = ilg;
}
v6 = fopen(ilg_fn, "w");
ilg_fp = v6;
if ( !v6 )
{
fprintf(stderr, "Can't create transcript file %s.\n", ilg_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
if ( a4 )
{
sprintf(log_fn, "%s%s", base, ".log");
log_fp = fopen(log_fn, "r");
if ( !log_fp )
{
fprintf(stderr, "Source log file %s not found.\n", log_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
find_pageno();
LODWORD(v6) = fclose(log_fp);
}
return (int)v6;
}

canonical_decompiled_code:
int __fastcall func3(char *a1, int a2, int a3, int a4)
{
FILE *v6; // rax

func0(a1, 1);
if ( !a2 )
{
sprintf(ind, "%s%s", base, ".ind");
ind_fn = ind;
}
ind_fp = fopen(ind_fn, "w");
if ( !ind_fp )
{
fprintf(stderr, "Can't create output index file %s.\n", ind_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
if ( !a3 )
{
sprintf(ilg, "%s%s", base, ".ilg");
ilg_fn = ilg;
}
v6 = fopen(ilg_fn, "w");
ilg_fp = v6;
if ( !v6 )
{
fprintf(stderr, "Can't create transcript file %s.\n", ilg_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
if ( a4 )
{
sprintf(log_fn, "%s%s", base, ".log");
log_fp = fopen(log_fn, "r");
if ( !log_fp )
{
fprintf(stderr, "Source log file %s not found.\n", log_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
func2();
LODWORD(v6) = fclose(log_fp);
}
return (int)v6;
}

original_code:
static void
check_all(char *fn, int ind_given, int ilg_given, int log_given)
{
    check_idx(fn, 1);
    if (!ind_given) {
 sprintf(ind, "%s%s", base, ".ind");
 ind_fn = ind;
    }
    if ((ind_fp = fopen(ind_fn, "w")) == ((void *)0))
 { fprintf(stderr, "Can't create output index file %s.\n", ind_fn); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
    if (!ilg_given) {
 sprintf(ilg, "%s%s", base, ".ilg");
 ilg_fn = ilg;
    }
    if ((ilg_fp = fopen(ilg_fn, "w")) == ((void *)0))
 { fprintf(stderr, "Can't create transcript file %s.\n", ilg_fn); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
    if (log_given) {
 sprintf(log_fn, "%s%s", base, ".log");
 if ((log_fp = fopen(log_fn, "r")) == ((void *)0)) {
     { fprintf(stderr, "Source log file %s not found.\n", log_fn); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
 } else {
     find_pageno();
     fclose(log_fp);
 }
    }
}


decompiled_code:
__int64 __fastcall process_idx(char **a1, int a2, int a3, int a4, int a5, int a6)
{
int v7; // ebx
__int64 result; // rax
__int64 v9; // rbx

v7 = a5;
if ( fn_no == -1 )
{
idx_fn = "stdin";
idx_fp = (__int64)stdin;
if ( !a4 )
{
ind_fn = "stdout";
ind_fp = stdout;
goto LABEL_22;
}
if ( ind_fp )
goto LABEL_22;
LABEL_4:
ind_fp = fopen(ind_fn, "w");
if ( !ind_fp )
{
fprintf(stderr, "Can't create output index file %s.\n", ind_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
LABEL_22:
if ( !v7 )
{
ilg_fn = "stderr";
ilg_fp = stderr;
LABEL_27:
if ( fn_no == -1 && a3 )
scan_sty();
if ( german_sort && idx_quote == 34 )
{
fprintf(stderr, "Option -g ignored, quote character must be different from '%c'.\n", 34LL);
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
if ( need_version )
{
if ( verbose )
fprintf(stderr, "This is %s, ", (const char *)pgm_fn);
fprintf(ilg_fp, "This is %s, ", (const char *)pgm_fn);
if ( verbose )
fprintf(stderr, "%s.\n", "portable version 2.12 [26-May-1993]");
fprintf(ilg_fp, "%s.\n", "portable version 2.12 [26-May-1993]");
need_version = 0;
}
result = scan_idx();
++fn_no;
return result;
}
LABEL_23:
if ( !ilg_fp )
{
ilg_fp = fopen(ilg_fn, "w");
if ( !ilg_fp )
{
fprintf(stderr, "Can't create transcript file %s.\n", ilg_fn);
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
}
goto LABEL_27;
}
check_all(*a1, a4, a5, a6);
if ( verbose )
fprintf(stderr, "This is %s, ", (const char *)pgm_fn);
fprintf(ilg_fp, "This is %s, ", (const char *)pgm_fn);
if ( verbose )
fprintf(stderr, "%s.\n", "portable version 2.12 [26-May-1993]");
fprintf(ilg_fp, "%s.\n", "portable version 2.12 [26-May-1993]");
need_version = 0;
if ( a3 )
scan_sty();
if ( german_sort && idx_quote == 34 )
{
fprintf(stderr, "Option -g invalid, quote character must be different from '%c'.\n", 34LL);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
result = scan_idx();
if ( fn_no > 0 )
{
v9 = 1LL;
do
{
check_idx(a1[v9], 1);
result = scan_idx();
++v9;
}
while ( fn_no >= (int)v9 );
}
if ( a2 )
{
idx_fn = "stdin";
idx_fp = (__int64)stdin;
if ( ind_fp )
goto LABEL_23;
v7 = 1;
goto LABEL_4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char **a1, int a2, int a3, int a4, int a5, int a6)
{
int v7; // ebx
__int64 result; // rax
__int64 v9; // rbx

v7 = a5;
if ( fn_no == -1 )
{
idx_fn = "stdin";
idx_fp = (__int64)stdin;
if ( !a4 )
{
ind_fn = "stdout";
ind_fp = stdout;
goto LABEL_22;
}
if ( ind_fp )
goto LABEL_22;
LABEL_4:
ind_fp = fopen(ind_fn, "w");
if ( !ind_fp )
{
fprintf(stderr, "Can't create output index file %s.\n", ind_fn);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
LABEL_22:
if ( !v7 )
{
ilg_fn = "stderr";
ilg_fp = stderr;
LABEL_27:
if ( fn_no == -1 && a3 )
scan_sty();
if ( german_sort && idx_quote == 34 )
{
fprintf(stderr, "Option -g ignored, quote character must be different from '%c'.\n", 34LL);
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
if ( need_version )
{
if ( verbose )
fprintf(stderr, "This is %s, ", (const char *)pgm_fn);
fprintf(ilg_fp, "This is %s, ", (const char *)pgm_fn);
if ( verbose )
fprintf(stderr, "%s.\n", "portable version 2.12 [26-May-1993]");
fprintf(ilg_fp, "%s.\n", "portable version 2.12 [26-May-1993]");
need_version = 0;
}
result = scan_idx();
++fn_no;
return result;
}
LABEL_23:
if ( !ilg_fp )
{
ilg_fp = fopen(ilg_fn, "w");
if ( !ilg_fp )
{
fprintf(stderr, "Can't create transcript file %s.\n", ilg_fn);
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
}
goto LABEL_27;
}
func3(*a1, a4, a5, a6);
if ( verbose )
fprintf(stderr, "This is %s, ", (const char *)pgm_fn);
fprintf(ilg_fp, "This is %s, ", (const char *)pgm_fn);
if ( verbose )
fprintf(stderr, "%s.\n", "portable version 2.12 [26-May-1993]");
fprintf(ilg_fp, "%s.\n", "portable version 2.12 [26-May-1993]");
need_version = 0;
if ( a3 )
scan_sty();
if ( german_sort && idx_quote == 34 )
{
fprintf(stderr, "Option -g invalid, quote character must be different from '%c'.\n", 34LL);
fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", (const char *)pgm_fn);
exit(1);
}
result = scan_idx();
if ( fn_no > 0 )
{
v9 = 1LL;
do
{
func0(a1[v9], 1);
result = scan_idx();
++v9;
}
while ( fn_no >= (int)v9 );
}
if ( a2 )
{
idx_fn = "stdin";
idx_fp = (__int64)stdin;
if ( ind_fp )
goto LABEL_23;
v7 = 1;
goto LABEL_4;
}
return result;
}

original_code:
static void
process_idx(char *fn[], int use_stdin, int sty_given, int ind_given,
     int ilg_given, int log_given)
{
    int i;
    if (fn_no == -1)
 use_stdin = 1;
    else {
 check_all(fn[0], ind_given, ilg_given, log_given);
 { { if (verbose) fprintf(stderr, "This is %s, ", pgm_fn); fprintf(ilg_fp, "This is %s, ", pgm_fn); }; { if (verbose) fprintf(stderr, "%s.\n", "portable version 2.12 [26-May-1993]"); fprintf(ilg_fp, "%s.\n", "portable version 2.12 [26-May-1993]"); }; need_version = 0; };
 if (sty_given)
     scan_sty();
 if (german_sort && (idx_quote == '"'))
{ fprintf(stderr, "Option -g invalid, quote character must be different from '%c'.\n", '"'); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
 scan_idx();
 ind_given = 1;
 ilg_given = 1;
 for (i = 1; i <= fn_no; i++) {
     check_idx(fn[i], 1);
     scan_idx();
 }
    }
    if (use_stdin) {
 idx_fn = "stdin";
 idx_fp = stdin;
 if (ind_given) {
     if (!ind_fp && ((ind_fp = fopen(ind_fn, "w")) == ((void *)0)))
  { fprintf(stderr, "Can't create output index file %s.\n", ind_fn); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
 } else {
     ind_fn = "stdout";
     ind_fp = stdout;
 }
 if (ilg_given) {
     if (!ilg_fp && ((ilg_fp = fopen(ilg_fn, "w")) == ((void *)0)))
  { fprintf(stderr, "Can't create transcript file %s.\n", ilg_fn); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
 } else {
     ilg_fn = "stderr";
     ilg_fp = stderr;
 }
 if ((fn_no == -1) && (sty_given))
     scan_sty();
 if (german_sort && (idx_quote == '"'))
{ fprintf(stderr, "Option -g ignored, quote character must be different from '%c'.\n", '"'); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
 if (need_version) {
     { { if (verbose) fprintf(stderr, "This is %s, ", pgm_fn); fprintf(ilg_fp, "This is %s, ", pgm_fn); }; { if (verbose) fprintf(stderr, "%s.\n", "portable version 2.12 [26-May-1993]"); fprintf(ilg_fp, "%s.\n", "portable version 2.12 [26-May-1993]"); }; need_version = 0; };
 }
 scan_idx();
 fn_no++;
    }
}

variable_types:
fn
char *[]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char *v4; // rdx
int v5; // ebx
int v6; // er15
int v7; // ebx
_BYTE *v8; // r12
char v9; // dl
const char **v10; // r13
char *v11; // rdi
int v13; // [rsp+0h] [rbp-2158h]
int v14; // [rsp+4h] [rbp-2154h]
int v15; // [rsp+8h] [rbp-2150h]
int v16; // [rsp+Ch] [rbp-214Ch]
char s[272]; // [rsp+10h] [rbp-2148h] BYREF
char *v18[1031]; // [rsp+120h] [rbp-2038h] BYREF

v3 = argv;
pgm_fn = (__int64)strrchr(*argv, 47);
v4 = (const char *)(pgm_fn + 1);
if ( !pgm_fn )
v4 = *argv;
pgm_fn = (__int64)v4;
v5 = argc - 1;
if ( argc - 1 <= 0 )
{
v15 = 0;
v14 = 0;
v13 = 0;
v6 = 0;
v16 = 0;
}
else
{
v15 = 0;
v14 = 0;
v13 = 0;
v6 = 0;
v16 = 0;
do
{
v10 = v3 + 1;
v11 = (char *)v3[1];
if ( *v11 == 45 )
{
if ( !v11[1] )
break;
v8 = v11 + 1;
v3[1] = v11 + 1;
v9 = v11[1];
if ( v9 )
{
do
{
switch ( v9 )
{
case 'c':
compress_blanks = 1;
break;
case 'g':
german_sort = 1;
break;
case 'i':
v16 = 1;
break;
case 'l':
letter_ordering = 1;
break;
case 'o':
if ( --v5 <= 0 )
{
fprintf(stderr, "Expected -o <ind>\n");
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
ind_fn = (char *)v10[1];
++v10;
v13 = 1;
break;
case 'p':
if ( --v5 <= 0 )
{
fprintf(stderr, "Expected -p <num>\n");
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
strcpy(&pageno, v10[1]);
init_page = 1;
if ( !strcmp(&pageno, "even") )
{
even_odd = 2;
++v10;
v15 = 1;
}
else if ( !strcmp(&pageno, "odd") )
{
even_odd = 1;
++v10;
v15 = 1;
}
else
{
++v10;
if ( !strcmp(&pageno, "any") )
{
even_odd = 0;
v15 = 1;
}
}
break;
case 'q':
verbose = 0;
break;
case 'r':
merge_page = 0;
break;
case 's':
if ( --v5 <= 0 )
{
fprintf(stderr, "Expected -s <stylefile>\n");
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
open_sty((char *)v10[1]);
++v10;
v6 = 1;
break;
case 't':
if ( --v5 <= 0 )
{
fprintf(stderr, "Expected -t <logfile>\n");
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
ilg_fn = (char *)v10[1];
++v10;
v14 = 1;
break;
default:
fprintf(stderr, "Unknown option -%c.\n", (unsigned int)v9);
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
v9 = *++v8;
}
while ( *v8 );
v3 = v10;
}
else
{
++v3;
}
}
else
{
if ( fn_no > 1023 )
{
fprintf(stderr, "Too many input files (max %d).\n", 1024LL);
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
check_idx(v11, 0);
v18[++fn_no] = (char *)v3[1];
++v3;
}
--v5;
}
while ( v5 > 0 );
}
v7 = fn_no | v6;
if ( !(fn_no | v6) )
{
sprintf(s, "%s%s", base, ".mst");
if ( !access(s, 4) )
{
open_sty(s);
v7 = 1;
}
v6 = v7;
}
process_idx(v18, v16, v6, v13, v14, v15);
idx_gt = idx_tt - idx_et;
if ( fn_no > 0 )
{
if ( verbose )
fprintf(
stderr,
"Overall %d files read (%d entries accepted, %d rejected).\n",
(unsigned int)(fn_no + 1),
(unsigned int)(idx_tt - idx_et),
(unsigned int)idx_et);
fprintf(
ilg_fp,
"Overall %d files read (%d entries accepted, %d rejected).\n",
(unsigned int)(fn_no + 1),
(unsigned int)idx_gt,
(unsigned int)idx_et);
}
if ( idx_gt > 0 )
{
prepare_idx();
sort_idx();
gen_ind();
if ( verbose )
fprintf(stderr, "Output written in %s.\n", ind_fn);
fprintf(ilg_fp, "Output written in %s.\n", ind_fn);
}
else
{
if ( verbose )
fprintf(stderr, "Nothing written in %s.\n", ind_fn);
fprintf(ilg_fp, "Nothing written in %s.\n", ind_fn);
}
if ( verbose )
fprintf(stderr, "Transcript written in %s.\n", ilg_fn);
fprintf(ilg_fp, "Transcript written in %s.\n", ilg_fn);
fclose(ind_fp);
fclose(ilg_fp);
exit(0);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
const char *v4; // rdx
int v5; // ebx
int v6; // er15
int v7; // ebx
_BYTE *v8; // r12
char v9; // dl
const char **v10; // r13
char *v11; // rdi
int v13; // [rsp+0h] [rbp-2158h]
int v14; // [rsp+4h] [rbp-2154h]
int v15; // [rsp+8h] [rbp-2150h]
int v16; // [rsp+Ch] [rbp-214Ch]
char s[272]; // [rsp+10h] [rbp-2148h] BYREF
char *v18[1031]; // [rsp+120h] [rbp-2038h] BYREF

v3 = argv;
pgm_fn = (__int64)strrchr(*argv, 47);
v4 = (const char *)(pgm_fn + 1);
if ( !pgm_fn )
v4 = *argv;
pgm_fn = (__int64)v4;
v5 = argc - 1;
if ( argc - 1 <= 0 )
{
v15 = 0;
v14 = 0;
v13 = 0;
v6 = 0;
v16 = 0;
}
else
{
v15 = 0;
v14 = 0;
v13 = 0;
v6 = 0;
v16 = 0;
do
{
v10 = v3 + 1;
v11 = (char *)v3[1];
if ( *v11 == 45 )
{
if ( !v11[1] )
break;
v8 = v11 + 1;
v3[1] = v11 + 1;
v9 = v11[1];
if ( v9 )
{
do
{
switch ( v9 )
{
case 'c':
compress_blanks = 1;
break;
case 'g':
german_sort = 1;
break;
case 'i':
v16 = 1;
break;
case 'l':
letter_ordering = 1;
break;
case 'o':
if ( --v5 <= 0 )
{
fprintf(stderr, "Expected -o <ind>\n");
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
ind_fn = (char *)v10[1];
++v10;
v13 = 1;
break;
case 'p':
if ( --v5 <= 0 )
{
fprintf(stderr, "Expected -p <num>\n");
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
strcpy(&pageno, v10[1]);
init_page = 1;
if ( !strcmp(&pageno, "even") )
{
even_odd = 2;
++v10;
v15 = 1;
}
else if ( !strcmp(&pageno, "odd") )
{
even_odd = 1;
++v10;
v15 = 1;
}
else
{
++v10;
if ( !strcmp(&pageno, "any") )
{
even_odd = 0;
v15 = 1;
}
}
break;
case 'q':
verbose = 0;
break;
case 'r':
merge_page = 0;
break;
case 's':
if ( --v5 <= 0 )
{
fprintf(stderr, "Expected -s <stylefile>\n");
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
func1((char *)v10[1]);
++v10;
v6 = 1;
break;
case 't':
if ( --v5 <= 0 )
{
fprintf(stderr, "Expected -t <logfile>\n");
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
ilg_fn = (char *)v10[1];
++v10;
v14 = 1;
break;
default:
fprintf(stderr, "Unknown option -%c.\n", (unsigned int)v9);
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
v9 = *++v8;
}
while ( *v8 );
v3 = v10;
}
else
{
++v3;
}
}
else
{
if ( fn_no > 1023 )
{
fprintf(stderr, "Too many input files (max %d).\n", 1024LL);
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
func0(v11, 0);
v18[++fn_no] = (char *)v3[1];
++v3;
}
--v5;
}
while ( v5 > 0 );
}
v7 = fn_no | v6;
if ( !(fn_no | v6) )
{
sprintf(s, "%s%s", base, ".mst");
if ( !access(s, 4) )
{
func1(s);
v7 = 1;
}
v6 = v7;
}
func4(v18, v16, v6, v13, v14, v15);
idx_gt = idx_tt - idx_et;
if ( fn_no > 0 )
{
if ( verbose )
fprintf(
stderr,
"Overall %d files read (%d entries accepted, %d rejected).\n",
(unsigned int)(fn_no + 1),
(unsigned int)(idx_tt - idx_et),
(unsigned int)idx_et);
fprintf(
ilg_fp,
"Overall %d files read (%d entries accepted, %d rejected).\n",
(unsigned int)(fn_no + 1),
(unsigned int)idx_gt,
(unsigned int)idx_et);
}
if ( idx_gt > 0 )
{
func5();
sort_idx();
gen_ind();
if ( verbose )
fprintf(stderr, "Output written in %s.\n", ind_fn);
fprintf(ilg_fp, "Output written in %s.\n", ind_fn);
}
else
{
if ( verbose )
fprintf(stderr, "Nothing written in %s.\n", ind_fn);
fprintf(ilg_fp, "Nothing written in %s.\n", ind_fn);
}
if ( verbose )
fprintf(stderr, "Transcript written in %s.\n", ilg_fn);
fprintf(ilg_fp, "Transcript written in %s.\n", ilg_fn);
fclose(ind_fp);
fclose(ilg_fp);
exit(0);
}

original_code:
int
main(int argc, char *argv[])
{
    char *fns[1024];
    char *ap;
    int use_stdin = 0;
    int sty_given = 0;
    int ind_given = 0;
    int ilg_given = 0;
    int log_given = 0;
    pgm_fn = strrchr(*argv, '/');
    if (pgm_fn == ((void *)0))
 pgm_fn = *argv;
    else
 pgm_fn++;
    while (--argc > 0) {
 if (**++argv == '-') {
     if (*(*argv + 1) == '\0')
  break;
     for (ap = ++*argv; *ap != '\0'; ap++)
  switch (*ap) {
  case 'i':
      use_stdin = 1;
      break;
  case 'l':
      letter_ordering = 1;
      break;
  case 'r':
      merge_page = 0;
      break;
  case 'q':
      verbose = 0;
      break;
  case 'c':
      compress_blanks = 1;
      break;
  case 's':
      argc--;
      if (argc <= 0)
   { fprintf(stderr, "Expected -s <stylefile>\n", ""); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      open_sty(*++argv);
      sty_given = 1;
      break;
  case 'o':
      argc--;
      if (argc <= 0)
   { fprintf(stderr, "Expected -o <ind>\n", ""); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      ind_fn = *++argv;
      ind_given = 1;
      break;
  case 't':
      argc--;
      if (argc <= 0)
   { fprintf(stderr, "Expected -t <logfile>\n", ""); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      ilg_fn = *++argv;
      ilg_given = 1;
      break;
  case 'p':
      argc--;
      if (argc <= 0)
   { fprintf(stderr, "Expected -p <num>\n", ""); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      strcpy(pageno, *++argv);
      init_page = 1;
      if ((strcmp(pageno, "even") == 0)) {
   log_given = 1;
   even_odd = 2;
      } else if ((strcmp(pageno, "odd") == 0)) {
   log_given = 1;
   even_odd = 1;
      } else if ((strcmp(pageno, "any") == 0)) {
   log_given = 1;
   even_odd = 0;
      }
      break;
  case 'g':
      german_sort = 1;
      break;
  default:
      { fprintf(stderr, "Unknown option -%c.\n", *ap); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      break;
  }
 } else {
     if (fn_no < 1024) {
  check_idx(*argv, 0);
  fns[++fn_no] = *argv;
     } else {
  { fprintf(stderr, "Too many input files (max %d).\n", 1024); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
     }
 }
    }
 if (fn_no == 0 && !sty_given)
 {
  char tmp[256 + 5];
  sprintf (tmp, "%s%s", base, ".mst");
  if (0 == access(tmp, 4)) {
   open_sty (tmp);
   sty_given = 1;
  }
 }
    process_idx(fns, use_stdin, sty_given, ind_given, ilg_given, log_given);
    idx_gt = idx_tt - idx_et;
    { if (fn_no > 0) { if (verbose) fprintf(stderr, "Overall %d files read (%d entries accepted, %d rejected).\n", fn_no+1, idx_gt, idx_et); fprintf(ilg_fp, "Overall %d files read (%d entries accepted, %d rejected).\n", fn_no+1, idx_gt, idx_et); } };
    if (idx_gt > 0) {
 prepare_idx();
 sort_idx();
 gen_ind();
 { if (verbose) fprintf(stderr, "Output written in %s.\n", ind_fn); fprintf(ilg_fp, "Output written in %s.\n", ind_fn); };
    } else
 { if (verbose) fprintf(stderr, "Nothing written in %s.\n", ind_fn); fprintf(ilg_fp, "Nothing written in %s.\n", ind_fn); };
    { if (verbose) fprintf(stderr, "Transcript written in %s.\n", ilg_fn); fprintf(ilg_fp, "Transcript written in %s.\n", ilg_fn); };
    fclose(ind_fp);
    fclose(ilg_fp);
    exit(0);
    return (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char *fns[1024];
    char *ap;
    int use_stdin = 0;
    int sty_given = 0;
    int ind_given = 0;
    int ilg_given = 0;
    int log_given = 0;
    pgm_fn = strrchr(*argv, '/');
    if (pgm_fn == ((void *)0))
 pgm_fn = *argv;
    else
 pgm_fn++;
    while (--argc > 0) {
 if (**++argv == '-') {
     if (*(*argv + 1) == '\0')
  break;
     for (ap = ++*argv; *ap != '\0'; ap++)
  switch (*ap) {
  case 'i':
      use_stdin = 1;
      break;
  case 'l':
      letter_ordering = 1;
      break;
  case 'r':
      merge_page = 0;
      break;
  case 'q':
      verbose = 0;
      break;
  case 'c':
      compress_blanks = 1;
      break;
  case 's':
      argc--;
      if (argc <= 0)
   { fprintf(stderr, "Expected -s <stylefile>\n", ""); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      open_sty(*++argv);
      sty_given = 1;
      break;
  case 'o':
      argc--;
      if (argc <= 0)
   { fprintf(stderr, "Expected -o <ind>\n", ""); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      ind_fn = *++argv;
      ind_given = 1;
      break;
  case 't':
      argc--;
      if (argc <= 0)
   { fprintf(stderr, "Expected -t <logfile>\n", ""); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      ilg_fn = *++argv;
      ilg_given = 1;
      break;
  case 'p':
      argc--;
      if (argc <= 0)
   { fprintf(stderr, "Expected -p <num>\n", ""); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      strcpy(pageno, *++argv);
      init_page = 1;
      if ((strcmp(pageno, "even") == 0)) {
   log_given = 1;
   even_odd = 2;
      } else if ((strcmp(pageno, "odd") == 0)) {
   log_given = 1;
   even_odd = 1;
      } else if ((strcmp(pageno, "any") == 0)) {
   log_given = 1;
   even_odd = 0;
      }
      break;
  case 'g':
      german_sort = 1;
      break;
  default:
      { fprintf(stderr, "Unknown option -%c.\n", *ap); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
      break;
  }
 } else {
     if (fn_no < 1024) {
  check_idx(*argv, 0);
  fns[++fn_no] = *argv;
     } else {
  { fprintf(stderr, "Too many input files (max %d).\n", 1024); fprintf(stderr, "Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n", pgm_fn); exit(1); };
     }
 }
    }
 if (fn_no == 0 && !sty_given)
 {
  char tmp[-1];
  sprintf (tmp, "%s%s", base, ".mst");
  if (0 == access(tmp, 4)) {
   open_sty (tmp);
   sty_given = 1;
  }
 }
    process_idx(fns, use_stdin, sty_given, ind_given, ilg_given, log_given);
    idx_gt = idx_tt - idx_et;
    { if (fn_no > 0) { if (verbose) fprintf(stderr, "Overall %d files read (%d entries accepted, %d rejected).\n", fn_no+1, idx_gt, idx_et); fprintf(ilg_fp, "Overall %d files read (%d entries accepted, %d rejected).\n", fn_no+1, idx_gt, idx_et); } };
    if (idx_gt > 0) {
 prepare_idx();
 sort_idx();
 gen_ind();
 { if (verbose) fprintf(stderr, "Output written in %s.\n", ind_fn); fprintf(ilg_fp, "Output written in %s.\n", ind_fn); };
    } else
 { if (verbose) fprintf(stderr, "Nothing written in %s.\n", ind_fn); fprintf(ilg_fp, "Nothing written in %s.\n", ind_fn); };
    { if (verbose) fprintf(stderr, "Transcript written in %s.\n", ilg_fn); fprintf(ilg_fp, "Transcript written in %s.\n", ilg_fn); };
    fclose(ind_fp);
    fclose(ilg_fp);
    exit(0);
    return (0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
fns
char *[1024]

variable_types:
ap
char *

variable_types:
tmp
char [-1]

return_type: int


strtoint

decompiled_code:
__int64 __fastcall strtoint(char *a1)
{
char v1; // al
unsigned int v2; // edx

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v2 = v1 + 10 * v2 - 48;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

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

v1 = *a1;
if ( !*a1 )
return 0;
v2 = 0;
do
{
v2 = v1 + 10 * v2 - 48;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

original_code:
int
strtoint(char *str)
{
    int val = 0;
    while (*str != '\0') {
 val = 10 * val + *str - 48;
 str++;
    }
    return (val);
}

variable_types:
str
char *

variable_types: val int


original_code:
float sin_taylor (float x) {
 const float pi = 3.14159265359;
  float k, r;
  k = floor(x / (2 * pi));
  r = x - k * 2 * pi;
  x = r - pi;
  return x - pow(x, 3) / 6 + pow(x, 5) / 120 - pow(x, 7) / 5040;
}

canonical_original_code:
float sin_taylor(float x) {
 float pi = 3.14159265359;
  float k; float r;
  k = floor(x / (2 * pi));
  r = x - k * 2 * pi;
  x = r - pi;
  return x - pow(x, 3) / 6 + pow(x, 5) / 120 - pow(x, 7) / 5040;
}

variable_types: x float

variable_types: pi float

variable_types: k float

variable_types: r float

return_type: float


original_code:
void waves_c (
 unsigned char *src,
 unsigned char *dst,
 int h,
 int w,
 int row_size,
 float x_scale,
 float y_scale,
 float g_scale
) {
 unsigned char (*src_matrix)[row_size] = (unsigned char (*)[row_size]) src;
 unsigned char (*dst_matrix)[row_size] = (unsigned char (*)[row_size]) dst;
 int i, j, tmp;
 float prof;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      prof = (x_scale * sin_taylor(j / 8.0) + y_scale * sin_taylor(i / 8.0)) / 2.0;
      tmp = (int) (prof * g_scale + src_matrix[i][j]);
      if (tmp < 0) {
        tmp = 0;
      }
      if (tmp > 255) {
        tmp = 255;
      }
      dst_matrix[i][j] = tmp;
    }
  }
}

canonical_original_code:
void waves_c(unsigned char *src, unsigned char *dst, int h, int w, int row_size, float x_scale, float y_scale, float g_scale) {
 unsigned char (*src_matrix)[-1] = (unsigned char (*)[row_size]) src;
 unsigned char (*dst_matrix)[-1] = (unsigned char (*)[row_size]) dst;
 int i; int j; int tmp;
 float prof;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      prof = (x_scale * sin_taylor(j / 8.0) + y_scale * sin_taylor(i / 8.0)) / 2.0;
      tmp = (int) (prof * g_scale + src_matrix[i][j]);
      if (tmp < 0) {
        tmp = 0;
      }
      if (tmp > 255) {
        tmp = 255;
      }
      dst_matrix[i][j] = tmp;
    }
  }
}

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types: h int

variable_types: w int

variable_types: j int

variable_types: tmp int

variable_types: prof float


decompiled_code:
int __fastcall check_mixsym(const char *a1, const char *a2)
{
unsigned __int8 v2; // dl
int v3; // ecx

v2 = *a2 - 48;
if ( (unsigned __int8)(*a1 - 48) <= 9u )
{
v3 = 1;
if ( v2 > 9u )
return v3;
}
if ( v2 <= 9u && (unsigned __int8)(*a1 - 48) > 9u )
return -1;
return strcmp(a1, a2);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1, const char *a2)
{
unsigned __int8 v2; // dl
int v3; // ecx

v2 = *a2 - 48;
if ( (unsigned __int8)(*a1 - 48) <= 9u )
{
v3 = 1;
if ( v2 > 9u )
return v3;
}
if ( v2 <= 9u && (unsigned __int8)(*a1 - 48) > 9u )
return -1;
return strcmp(a1, a2);
}

variable_types:
x
char *

variable_types:
y
char *

variable_types: m int

variable_types: n int


decompiled_code:
__int64 __fastcall compare_string(const char *a1, const char *a2)
{
int v2; // ebx
int i; // er12
char v4; // dl
const unsigned __int16 **v5; // rax
const unsigned __int16 *v6; // r13
__int64 v7; // r15
int v8; // ebp
__int64 v9; // r15
int v10; // eax
char v11; // al
unsigned int v12; // ebp
int v14; // [rsp+Ch] [rbp-3Ch]

v14 = letter_ordering;
v2 = 0;
for ( i = 0; ; ++i )
{
v11 = a1[i];
if ( !v11 )
break;
v4 = a2[v2];
if ( !v4 )
return 1;
if ( v14 )
{
i += v11 == 32;
v2 += v4 == 32;
}
v5 = _ctype_b_loc();
v6 = *v5;
v7 = (unsigned __int8)a1[i];
v8 = (unsigned __int8)a1[i];
if ( ((*v5)[v7] & 0x100) != 0 )
v8 = LOBYTE((*_ctype_tolower_loc())[v7]);
v9 = (unsigned __int8)a2[v2];
v10 = (unsigned __int8)a2[v2];
if ( (v6[v9] & 0x100) != 0 )
v10 = LOBYTE((*_ctype_tolower_loc())[v9]);
if ( v8 != v10 )
return (unsigned int)(v8 - v10);
++v2;
}
v12 = -1;
if ( !a2[v2] )
{
if ( german_sort )
v12 = new_strcmp((__int64)a1, (__int64)a2, 0);
else
v12 = strcmp(a1, a2);
}
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
int v2; // ebx
int i; // er12
char v4; // dl
const unsigned __int16 **v5; // rax
const unsigned __int16 *v6; // r13
__int64 v7; // r15
int v8; // ebp
__int64 v9; // r15
int v10; // eax
char v11; // al
unsigned int v12; // ebp
int v14; // [rsp+Ch] [rbp-3Ch]

v14 = letter_ordering;
v2 = 0;
for ( i = 0; ; ++i )
{
v11 = a1[i];
if ( !v11 )
break;
v4 = a2[v2];
if ( !v4 )
return 1;
if ( v14 )
{
i += v11 == 32;
v2 += v4 == 32;
}
v5 = _ctype_b_loc();
v6 = *v5;
v7 = (unsigned __int8)a1[i];
v8 = (unsigned __int8)a1[i];
if ( ((*v5)[v7] & 0x100) != 0 )
v8 = LOBYTE((*_ctype_tolower_loc())[v7]);
v9 = (unsigned __int8)a2[v2];
v10 = (unsigned __int8)a2[v2];
if ( (v6[v9] & 0x100) != 0 )
v10 = LOBYTE((*_ctype_tolower_loc())[v9]);
if ( v8 != v10 )
return (unsigned int)(v8 - v10);
++v2;
}
v12 = -1;
if ( !a2[v2] )
{
if ( german_sort )
v12 = func1((__int64)a1, (__int64)a2, 0);
else
v12 = strcmp(a1, a2);
}
return v12;
}

original_code:
static int
compare_string(unsigned char *a, unsigned char *b)
{
    int i = 0;
    int j = 0;
    int al;
    int bl;
    while ((a[i] != '\0') || (b[j] != '\0')) {
 if (a[i] == '\0')
     return (-1);
 if (b[j] == '\0')
     return (1);
 if (letter_ordering) {
     if (a[i] == ' ')
  i++;
     if (b[j] == ' ')
  j++;
 }
 al = (((*__ctype_b_loc ())[(int) (((unsigned char)(a[i])))] & (unsigned short int) _ISupper) ? (unsigned char)tolower((unsigned char)(a[i])) : (unsigned char)(a[i]));
 bl = (((*__ctype_b_loc ())[(int) (((unsigned char)(b[j])))] & (unsigned short int) _ISupper) ? (unsigned char)tolower((unsigned char)(b[j])) : (unsigned char)(b[j]));
 if (al != bl)
     return (al - bl);
 i++;
 j++;
    }
    if (german_sort)
 return (new_strcmp(a, b, 0));
    else
 return (strcmp((char*)a, (char*)b));
}

canonical_original_code:
static int compare_string(unsigned char *a, unsigned char *b)
{
    int i = 0;
    int j = 0;
    int al;
    int bl;
    while ((a[i] != '\0') || (b[j] != '\0')) {
 if (a[i] == '\0')
     return (-1);
 if (b[j] == '\0')
     return (1);
 if (letter_ordering) {
     if (a[i] == ' ')
  i++;
     if (b[j] == ' ')
  j++;
 }
 al = (((*__ctype_b_loc ())[(int) (((unsigned char)(a[i])))] & (unsigned short) _ISupper) ? (unsigned char)tolower((unsigned char)(a[i])) : (unsigned char)(a[i]));
 bl = (((*__ctype_b_loc ())[(int) (((unsigned char)(b[j])))] & (unsigned short) _ISupper) ? (unsigned char)tolower((unsigned char)(b[j])) : (unsigned char)(b[j]));
 if (al != bl)
     return (al - bl);
 i++;
 j++;
    }
    if (german_sort)
 return (new_strcmp(a, b, 0));
    else
 return (strcmp((char *)a, (char *)b));
}

variable_types:
a
unsigned char *

variable_types:
b
unsigned char *

variable_types: i int

variable_types: al int

variable_types: bl int


decompiled_code:
__int64 __fastcall compare_one(const char *a1, const char *a2)
{
int v2; // ebx
int v4; // eax

if ( *a1 )
{
v2 = 1;
if ( *a2 )
{
v2 = ((__int64 (*)(void))group_type)();
v4 = group_type(a2);
if ( v2 < 0 || v4 < 0 )
{
if ( v2 < 0 )
{
if ( v4 < 0 )
{
if ( (v4 & v2) == -1 )
{
v2 = check_mixsym(a1, a2);
}
else if ( v2 != -1 )
{
v2 = 1;
if ( v4 != -1 )
v2 = compare_string(a1, a2);
}
}
else if ( german_sort || v2 == -1 )
{
v2 = -1;
}
else
{
v2 = 1;
}
}
else if ( german_sort || (v2 = -1, v4 == -1) )
{
v2 = 1;
}
}
else
{
v2 -= v4;
}
}
}
else
{
v2 = -(*a2 != 0);
}
return (unsigned int)v2;
}

original_code:
static int
compare_one(char *x,char *y)
{
    int m;
    int n;
    if ((x[0] == '\0') && (y[0] == '\0'))
 return (0);
    if (x[0] == '\0')
 return (-1);
    if (y[0] == '\0')
 return (1);
    m = group_type(x);
    n = group_type(y);
    if ((m >= 0) && (n >= 0))
 return (m - n);
    if (m >= 0) {
 if (german_sort)
     return (1);
 else
     return ((n == -1) ? 1 : -1);
    }
    if (n >= 0) {
 if (german_sort)
     return (-1);
 else
     return ((m == -1) ? -1 : 1);
    }
    if ((m == -1) && (n == -1))
 return (check_mixsym(x, y));
    if (m == -1)
 return (-1);
    if (n == -1)
 return (1);
    return (compare_string((unsigned char*)x, (unsigned char*)y));
}

canonical_original_code:
static int compare_one(char *x, char *y)
{
    int m;
    int n;
    if ((x[0] == '\0') && (y[0] == '\0'))
 return (0);
    if (x[0] == '\0')
 return (-1);
    if (y[0] == '\0')
 return (1);
    m = group_type(x);
    n = group_type(y);
    if ((m >= 0) && (n >= 0))
 return (m - n);
    if (m >= 0) {
 if (german_sort)
     return (1);
 else
     return ((n == -1) ? 1 : -1);
    }
    if (n >= 0) {
 if (german_sort)
     return (-1);
 else
     return ((m == -1) ? -1 : 1);
    }
    if ((m == -1) && (n == -1))
 return (check_mixsym(x, y));
    if (m == -1)
 return (-1);
    if (n == -1)
 return (1);
    return (compare_string((unsigned char *)x, (unsigned char *)y));
}


decompiled_code:
int sort_idx()
{
if ( verbose )
fprintf(stderr, "Sorting entries...");
fprintf(ilg_fp, "Sorting entries...");
idx_dc = 0;
idx_gc = 0LL;
qqsort(idx_key, idx_gt, 8LL, compare);
if ( verbose )
fprintf(stderr, "done (%ld comparisons).\n", idx_gc);
return fprintf(ilg_fp, "done (%ld comparisons).\n", idx_gc);
}

canonical_decompiled_code:
int func6()
{
if ( verbose )
fprintf(stderr, "Sorting entries...");
fprintf(ilg_fp, "Sorting entries...");
idx_dc = 0;
idx_gc = 0LL;
qqsort(idx_key, idx_gt, 8LL, compare);
if ( verbose )
fprintf(stderr, "done (%ld comparisons).\n", idx_gc);
return fprintf(ilg_fp, "done (%ld comparisons).\n", idx_gc);
}

original_code:
void
sort_idx(void)
{
    { if (verbose) fprintf(stderr, "Sorting entries...", ""); fprintf(ilg_fp, "Sorting entries...", ""); };
    idx_dc = 0;
    idx_gc = 0L;
    qqsort((char *) idx_key, (int) idx_gt, (int) sizeof(FIELD_PTR),
 (int (*) (char*,char*))compare);
    { if (verbose) fprintf(stderr, "done (%ld comparisons).\n", idx_gc); fprintf(ilg_fp, "done (%ld comparisons).\n", idx_gc); };
}

canonical_original_code:
void sort_idx()
{
    { if (verbose) fprintf(stderr, "Sorting entries...", ""); fprintf(ilg_fp, "Sorting entries...", ""); };
    idx_dc = 0;
    idx_gc = 0L;
    qqsort((char *) idx_key, (int) idx_gt, (int) sizeof(FIELD_PTR),
 (int (*)(char *, char *))compare);
    { if (verbose) fprintf(stderr, "done (%ld comparisons).\n", idx_gc); fprintf(ilg_fp, "done (%ld comparisons).\n", idx_gc); };
}


distancia

decompiled_code:
_BOOL8 __fastcall distancia(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, int a4, int a5, int a6, int a7)
{
double v7; // xmm0_8
double v8; // xmm0_8

v7 = (double)(a6 - a3) * (double)(a6 - a3)
+ (double)(a5 - a2) * (double)(a5 - a2)
+ (double)(a4 - a1) * (double)(a4 - a1);
if ( v7 < 0.0 )
v8 = sqrt(v7);
else
v8 = sqrt(v7);
return (int)v8 > a7;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, int a4, int a5, int a6, int a7)
{
double v7; // xmm0_8
double v8; // xmm0_8

v7 = (double)(a6 - a3) * (double)(a6 - a3)
+ (double)(a5 - a2) * (double)(a5 - a2)
+ (double)(a4 - a1) * (double)(a4 - a1);
if ( v7 < 0.0 )
v8 = sqrt(v7);
else
v8 = sqrt(v7);
return (int)v8 > a7;
}

original_code:
int distancia (unsigned char rc, unsigned char gc, unsigned char bc, int r, int g, int b, int threshold){
 int res = sqrt(pow((r - rc),2) + pow((g - gc),2) + pow((b - bc),2));
 if(res > threshold){
  return 1;
 }
 return 0;
}

canonical_original_code:
int distancia(unsigned char rc, unsigned char gc, unsigned char bc, int r, int g, int b, int threshold){
 int res = sqrt(pow((r - rc),2) + pow((g - gc),2) + pow((b - bc),2));
 if(res > threshold){
  return 1;
 }
 return 0;
}

variable_types:
rc
unsigned char

variable_types:
gc
unsigned char

variable_types:
bc
unsigned char

variable_types: r int

variable_types: g int

variable_types: b int

variable_types: threshold int

variable_types: res int


original_code:
void color_filter_c(unsigned char *src,
     unsigned char *dst,
     unsigned char rc,
     unsigned char gc,
     unsigned char bc,
     int threshold,
     int width,
     int height)
{
 unsigned char (*src_matrix)[width * 3] = (unsigned char (*)[width * 3]) src;
 unsigned char (*dst_matrix)[width * 3] = (unsigned char (*)[width * 3]) dst;
 int _row = 0;
 int _column = 0;
 while(_row <= height - 1){
  while(_column <= width * 3 - 3){
   int b = src_matrix[_row][_column];
   int g = src_matrix[_row][_column + 1];
   int r = src_matrix[_row][_column + 2];
   int dist = distancia(rc,gc,bc, r, g, b, threshold);
   if(dist == 1){
    int rgb = (r + g + b)/3;
    dst_matrix[_row][_column] = rgb;
    dst_matrix[_row][_column + 1] = rgb;
    dst_matrix[_row][_column + 2] = rgb;
   }else{
    dst_matrix[_row][_column] = src_matrix[_row][_column];
    dst_matrix[_row][_column + 1] = src_matrix[_row][_column + 1];
    dst_matrix[_row][_column + 2] = src_matrix[_row][_column + 2];
   }
   _column = _column + 3;
  }
  _column = 0;
  _row++;
 }
}

canonical_original_code:
void color_filter_c(unsigned char *src, unsigned char *dst, unsigned char rc, unsigned char gc, unsigned char bc, int threshold, int width, int height)
{
 unsigned char (*src_matrix)[-1] = (unsigned char (*)[width * 3]) src;
 unsigned char (*dst_matrix)[-1] = (unsigned char (*)[width * 3]) dst;
 int _row = 0;
 int _column = 0;
 while(_row <= height - 1){
  while(_column <= width * 3 - 3){
   int b = src_matrix[_row][_column];
   int g = src_matrix[_row][_column + 1];
   int r = src_matrix[_row][_column + 2];
   int dist = distancia(rc,gc,bc, r, g, b, threshold);
   if(dist == 1){
    int rgb = (r + g + b)/3;
    dst_matrix[_row][_column] = rgb;
    dst_matrix[_row][_column + 1] = rgb;
    dst_matrix[_row][_column + 2] = rgb;
   }else{
    dst_matrix[_row][_column] = src_matrix[_row][_column];
    dst_matrix[_row][_column + 1] = src_matrix[_row][_column + 1];
    dst_matrix[_row][_column + 2] = src_matrix[_row][_column + 2];
   }
   _column = _column + 3;
  }
  _column = 0;
  _row++;
 }
}

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types: width int

variable_types: height int

variable_types: dist int

variable_types: rgb int


qst

decompiled_code:
__int64 __fastcall qst(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // r14
unsigned __int8 *v3; // r15
int v4; // ebx
unsigned __int8 *v5; // rbx
unsigned __int8 *v6; // rsi
__int64 v7; // rdx
unsigned __int8 *v8; // rbp
unsigned __int8 *v9; // r13
__int64 v10; // rcx
unsigned __int8 v11; // al
unsigned __int8 *i; // rbx
unsigned __int8 *v13; // r12
unsigned __int8 *v14; // rbp
__int64 result; // rax
__int64 v16; // rdx
__int64 v17; // rsi
unsigned __int8 *v18; // rax

v2 = a1;
v3 = a2;
v4 = (_DWORD)a2 - (_DWORD)a1;
do
{
v7 = (unsigned int)(v4 >> 31);
LODWORD(v7) = v4 % qsz;
v13 = &v2[qsz * ((unsigned int)(v4 / qsz) >> 1)];
if ( mthresh <= v4 )
{
if ( (int)qcmp(v2, &v2[qsz * ((unsigned int)(v4 / qsz) >> 1)], v7) <= 0 )
{
v5 = &v3[-qsz];
if ( (int)qcmp(v13, v5, v16) <= 0 )
goto LABEL_40;
if ( v2 != v13 )
{
if ( (int)qcmp(v2, v5, v7) >= 0 )
v5 = v2;
goto LABEL_37;
}
}
else
{
v5 = &v3[-qsz];
if ( (int)qcmp(v2, v5, v16) <= 0 )
{
v5 = v2;
LABEL_37:
if ( v5 != v13 )
{
v17 = (__int64)&v13[qsz - 1 + 1];
v18 = v13;
do
{
v7 = *v18++;
*(v18 - 1) = *v5++;
*(v5 - 1) = v7;
}
while ( (unsigned __int8 *)v17 != v18 );
}
goto LABEL_40;
}
}
if ( (int)qcmp(v13, v5, v7) < 0 )
goto LABEL_37;
}
LABEL_40:
v9 = &v3[-qsz];
for ( i = v2; i < v13; i = v6 )
{
if ( (int)qcmp(i, v13, v7) <= 0 )
{
v6 = &i[qsz];
continue;
}
v8 = v9;
if ( v9 > v13 )
{
LABEL_14:
v8 = v9;
while ( (int)qcmp(v13, v8, v7) <= 0 )
{
v8 -= qsz;
if ( v13 >= v8 )
goto LABEL_17;
}
v6 = &i[qsz];
if ( i == v13 )
{
v13 = v8;
v9 = v8;
}
else
{
v9 = &v8[-qsz];
}
goto LABEL_9;
}
LABEL_18:
v9 = &v8[-qsz];
v6 = i;
v8 = v13;
v13 = i;
LABEL_9:
v10 = (__int64)&i[qsz - 1 + 1];
do
{
v11 = *i++;
v7 = *v8;
*(i - 1) = v7;
*v8++ = v11;
}
while ( (unsigned __int8 *)v10 != i );
}
v8 = v9;
if ( v9 > v13 )
goto LABEL_14;
LABEL_17:
if ( i != v13 )
goto LABEL_18;
v14 = &v13[qsz];
result = v3 - v14;
v4 = (_DWORD)v3 - (_DWORD)v14;
if ( (int)v13 - (int)v2 > (int)v3 - (int)v14 )
{
if ( thresh <= (int)result )
result = qst(&v13[qsz], v3);
v4 = (_DWORD)v13 - (_DWORD)v2;
v3 = v13;
}
else if ( thresh <= (int)v13 - (int)v2 )
{
result = qst(v2, v13);
v2 = v14;
}
else
{
v2 = &v13[qsz];
}
}
while ( thresh <= v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // r14
unsigned __int8 *v3; // r15
int v4; // ebx
unsigned __int8 *v5; // rbx
unsigned __int8 *v6; // rsi
__int64 v7; // rdx
unsigned __int8 *v8; // rbp
unsigned __int8 *v9; // r13
__int64 v10; // rcx
unsigned __int8 v11; // al
unsigned __int8 *i; // rbx
unsigned __int8 *v13; // r12
unsigned __int8 *v14; // rbp
__int64 result; // rax
__int64 v16; // rdx
__int64 v17; // rsi
unsigned __int8 *v18; // rax

v2 = a1;
v3 = a2;
v4 = (_DWORD)a2 - (_DWORD)a1;
do
{
v7 = (unsigned int)(v4 >> 31);
LODWORD(v7) = v4 % qsz;
v13 = &v2[qsz * ((unsigned int)(v4 / qsz) >> 1)];
if ( mthresh <= v4 )
{
if ( (int)qcmp(v2, &v2[qsz * ((unsigned int)(v4 / qsz) >> 1)], v7) <= 0 )
{
v5 = &v3[-qsz];
if ( (int)qcmp(v13, v5, v16) <= 0 )
goto LABEL_40;
if ( v2 != v13 )
{
if ( (int)qcmp(v2, v5, v7) >= 0 )
v5 = v2;
goto LABEL_37;
}
}
else
{
v5 = &v3[-qsz];
if ( (int)qcmp(v2, v5, v16) <= 0 )
{
v5 = v2;
LABEL_37:
if ( v5 != v13 )
{
v17 = (__int64)&v13[qsz - 1 + 1];
v18 = v13;
do
{
v7 = *v18++;
*(v18 - 1) = *v5++;
*(v5 - 1) = v7;
}
while ( (unsigned __int8 *)v17 != v18 );
}
goto LABEL_40;
}
}
if ( (int)qcmp(v13, v5, v7) < 0 )
goto LABEL_37;
}
LABEL_40:
v9 = &v3[-qsz];
for ( i = v2; i < v13; i = v6 )
{
if ( (int)qcmp(i, v13, v7) <= 0 )
{
v6 = &i[qsz];
continue;
}
v8 = v9;
if ( v9 > v13 )
{
LABEL_14:
v8 = v9;
while ( (int)qcmp(v13, v8, v7) <= 0 )
{
v8 -= qsz;
if ( v13 >= v8 )
goto LABEL_17;
}
v6 = &i[qsz];
if ( i == v13 )
{
v13 = v8;
v9 = v8;
}
else
{
v9 = &v8[-qsz];
}
goto LABEL_9;
}
LABEL_18:
v9 = &v8[-qsz];
v6 = i;
v8 = v13;
v13 = i;
LABEL_9:
v10 = (__int64)&i[qsz - 1 + 1];
do
{
v11 = *i++;
v7 = *v8;
*(i - 1) = v7;
*v8++ = v11;
}
while ( (unsigned __int8 *)v10 != i );
}
v8 = v9;
if ( v9 > v13 )
goto LABEL_14;
LABEL_17:
if ( i != v13 )
goto LABEL_18;
v14 = &v13[qsz];
result = v3 - v14;
v4 = (_DWORD)v3 - (_DWORD)v14;
if ( (int)v13 - (int)v2 > (int)v3 - (int)v14 )
{
if ( thresh <= (int)result )
result = func0(&v13[qsz], v3);
v4 = (_DWORD)v13 - (_DWORD)v2;
v3 = v13;
}
else if ( thresh <= (int)v13 - (int)v2 )
{
result = func0(v2, v13);
v2 = v14;
}
else
{
v2 = &v13[qsz];
}
}
while ( thresh <= v4 );
return result;
}

original_code:
static void
qst(char *base, char *max)
{
    register char *i;
    register char *j;
    register char *jj;
    register char *mid;
    register int ii;
    register char c;
    char *tmp;
    int lo;
    int hi;
    lo = (int)(max - base);
    do {
 mid = i = base + qsz * ((unsigned) (lo / qsz) >> 1);
 if (lo >= mthresh) {
     j = ((*qcmp) ((jj = base), i) > 0 ? jj : i);
     if ((*qcmp) (j, (tmp = max - qsz)) > 0) {
  j = (j == jj ? i : jj);
  if ((*qcmp) (j, tmp) < 0)
      j = tmp;
     }
     if (j != i) {
  ii = qsz;
  do {
      c = *i;
      *i++ = *j;
      *j++ = c;
  } while (--ii);
     }
 }
 for (i = base, j = max - qsz;;) {
     while (i < mid && (*qcmp) (i, mid) <= 0)
  i += qsz;
     while (j > mid) {
  if ((*qcmp) (mid, j) <= 0) {
      j -= qsz;
      continue;
  }
  tmp = i + qsz;
  if (i == mid) {
      mid = jj = j;
  } else {
      jj = j;
      j -= qsz;
  }
  goto swap;
     }
     if (i == mid) {
  break;
     } else {
  jj = mid;
  tmp = mid = i;
  j -= qsz;
     }
    swap:
     ii = qsz;
     do {
  c = *i;
  *i++ = *jj;
  *jj++ = c;
     } while (--ii);
     i = tmp;
 }
 i = (j = mid) + qsz;
 if ((lo = (int)(j - base)) <= (hi = (int)(max - i))) {
     if (lo >= thresh)
  qst(base, j);
     base = i;
     lo = hi;
 } else {
     if (hi >= thresh)
  qst(i, max);
     max = j;
 }
    } while (lo >= thresh);
}

canonical_original_code:
static void qst(char *base, char *max)
{
    register char *i;
    register char *j;
    register char *jj;
    register char *mid;
    register int ii;
    register char c;
    char *tmp;
    int lo;
    int hi;
    lo = (int)(max - base);
    do {
 mid = i = base + qsz * ((unsigned int) (lo / qsz) >> 1);
 if (lo >= mthresh) {
     j = ((*qcmp) ((jj = base), i) > 0 ? jj : i);
     if ((*qcmp) (j, (tmp = max - qsz)) > 0) {
  j = (j == jj ? i : jj);
  if ((*qcmp) (j, tmp) < 0)
      j = tmp;
     }
     if (j != i) {
  ii = qsz;
  do {
      c = *i;
      *i++ = *j;
      *j++ = c;
  } while (--ii);
     }
 }
 for (i = base, j = max - qsz;;) {
     while (i < mid && (*qcmp) (i, mid) <= 0)
  i += qsz;
     while (j > mid) {
  if ((*qcmp) (mid, j) <= 0) {
      j -= qsz;
      continue;
  }
  tmp = i + qsz;
  if (i == mid) {
      mid = jj = j;
  } else {
      jj = j;
      j -= qsz;
  }
  goto swap;
     }
     if (i == mid) {
  break;
     } else {
  jj = mid;
  tmp = mid = i;
  j -= qsz;
     }
    swap:
     ii = qsz;
     do {
  c = *i;
  *i++ = *jj;
  *jj++ = c;
     } while (--ii);
     i = tmp;
 }
 i = (j = mid) + qsz;
 if ((lo = (int)(j - base)) <= (hi = (int)(max - i))) {
     if (lo >= thresh)
  qst(base, j);
     base = i;
     lo = hi;
 } else {
     if (hi >= thresh)
  qst(i, max);
     max = j;
 }
    } while (lo >= thresh);
}

variable_types:
base
char *

variable_types:
max
char *

variable_types:
i
char *

variable_types:
j
char *

variable_types:
jj
char *

variable_types:
mid
char *

variable_types: ii int

variable_types: c char

variable_types:
tmp
char *

variable_types: lo int

variable_types: hi int


qqsort

decompiled_code:
void __fastcall qqsort(unsigned __int8 *a1, int a2, int a3, __int64 (__fastcall *a4)(_QWORD, _QWORD, _QWORD))
{
unsigned __int8 *v4; // rdx
unsigned __int8 *v5; // r12
unsigned __int8 *v6; // r14
unsigned __int8 *v7; // rbp
unsigned __int8 *v8; // rbx
unsigned __int8 *v9; // rax
unsigned __int8 v10; // cl
unsigned __int8 *i; // rbp
unsigned __int8 *v12; // rsi
unsigned __int8 *v13; // rbx
__int64 v14; // rdi
unsigned __int64 v15; // rcx
unsigned __int8 *v16; // r9
unsigned __int8 *v17; // r10
unsigned __int8 v18; // r11
unsigned __int8 *v19; // rax

if ( a2 > 1 )
{
qsz = a3;
qcmp = a4;
thresh = 4 * a3;
mthresh = 6 * a3;
v4 = (unsigned __int8 *)(unsigned int)(a2 * a3);
v5 = &a1[(int)v4];
v6 = v5;
if ( a2 > 3 )
{
qst(a1, &a1[(int)v4]);
v6 = &a1[thresh];
}
v7 = &a1[qsz];
if ( v6 > v7 )
{
v8 = a1;
do
{
if ( (int)qcmp(v8, v7, v4) > 0 )
v8 = v7;
v7 += qsz;
}
while ( v6 > v7 );
if ( v8 != a1 )
{
v4 = &a1[qsz];
if ( a1 < v4 )
{
v9 = a1;
do
{
v10 = *v8++;
*(v8 - 1) = *v9++;
*(v9 - 1) = v10;
}
while ( v4 != v9 );
}
}
}
for ( i = &a1[qsz]; v5 > i; i += v14 )
{
v13 = i;
do
v13 -= qsz;
while ( (int)qcmp(v13, i, v4) > 0 );
v14 = qsz;
v15 = (unsigned __int64)&v13[qsz];
if ( (unsigned __int8 *)v15 != i )
{
v16 = &i[qsz - 1];
if ( v16 >= i )
{
v17 = i - 1;
do
{
v18 = *v16;
v19 = v17;
if ( v15 > (unsigned __int64)v17 )
{
v12 = v16;
}
else
{
v4 = v16;
do
{
*v4 = *v19;
v12 = v19;
v19 -= v14;
v4 -= v14;
}
while ( v15 <= (unsigned __int64)v19 );
}
*v12 = v18;
--v16;
--v17;
}
while ( i - 1 != v16 );
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func1(unsigned __int8 *a1, int a2, int a3, __int64 (__fastcall *a4)(_QWORD, _QWORD, _QWORD))
{
unsigned __int8 *v4; // rdx
unsigned __int8 *v5; // r12
unsigned __int8 *v6; // r14
unsigned __int8 *v7; // rbp
unsigned __int8 *v8; // rbx
unsigned __int8 *v9; // rax
unsigned __int8 v10; // cl
unsigned __int8 *i; // rbp
unsigned __int8 *v12; // rsi
unsigned __int8 *v13; // rbx
__int64 v14; // rdi
unsigned __int64 v15; // rcx
unsigned __int8 *v16; // r9
unsigned __int8 *v17; // r10
unsigned __int8 v18; // r11
unsigned __int8 *v19; // rax

if ( a2 > 1 )
{
qsz = a3;
qcmp = a4;
thresh = 4 * a3;
mthresh = 6 * a3;
v4 = (unsigned __int8 *)(unsigned int)(a2 * a3);
v5 = &a1[(int)v4];
v6 = v5;
if ( a2 > 3 )
{
func0(a1, &a1[(int)v4]);
v6 = &a1[thresh];
}
v7 = &a1[qsz];
if ( v6 > v7 )
{
v8 = a1;
do
{
if ( (int)qcmp(v8, v7, v4) > 0 )
v8 = v7;
v7 += qsz;
}
while ( v6 > v7 );
if ( v8 != a1 )
{
v4 = &a1[qsz];
if ( a1 < v4 )
{
v9 = a1;
do
{
v10 = *v8++;
*(v8 - 1) = *v9++;
*(v9 - 1) = v10;
}
while ( v4 != v9 );
}
}
}
for ( i = &a1[qsz]; v5 > i; i += v14 )
{
v13 = i;
do
v13 -= qsz;
while ( (int)qcmp(v13, i, v4) > 0 );
v14 = qsz;
v15 = (unsigned __int64)&v13[qsz];
if ( (unsigned __int8 *)v15 != i )
{
v16 = &i[qsz - 1];
if ( v16 >= i )
{
v17 = i - 1;
do
{
v18 = *v16;
v19 = v17;
if ( v15 > (unsigned __int64)v17 )
{
v12 = v16;
}
else
{
v4 = v16;
do
{
*v4 = *v19;
v12 = v19;
v19 -= v14;
v4 -= v14;
}
while ( v15 <= (unsigned __int64)v19 );
}
*v12 = v18;
--v16;
--v17;
}
while ( i - 1 != v16 );
}
}
}
}
}

original_code:
void
qqsort(char *base, int n, int size, int (*compar) (char*,char*))
{
    register char *i;
    register char *j;
    register char *lo;
    register char *hi;
    register char *min;
    register char c;
    char *max;
    if (n <= 1)
 return;
    qsz = size;
    qcmp = compar;
    thresh = qsz * 4;
    mthresh = qsz * 6;
    max = base + n * qsz;
    if (n >= 4) {
 qst(base, max);
 hi = base + thresh;
    } else {
 hi = max;
    }
    for (j = lo = base; (lo += qsz) < hi;) {
 if ((*qcmp) (j, lo) > 0)
     j = lo;
    }
    if (j != base) {
 for (i = base, hi = base + qsz; i < hi;) {
     c = *j;
     *j++ = *i;
     *i++ = c;
 }
    }
    for (min = base; (hi = min += qsz) < max;) {
 while ((*qcmp) (hi -= qsz, min) > 0);
 if ((hi += qsz) != min) {
     for (lo = min + qsz; --lo >= min;) {
  c = *lo;
  for (i = j = lo; (j -= qsz) >= hi; i = j)
      *i = *j;
  *i = c;
     }
 }
    }
}

canonical_original_code:
void qqsort(char *base, int n, int size, int (*compar)(char *, char *))
{
    register char *i;
    register char *j;
    register char *lo;
    register char *hi;
    register char *min;
    register char c;
    char *max;
    if (n <= 1)
 return;
    qsz = size;
    qcmp = compar;
    thresh = qsz * 4;
    mthresh = qsz * 6;
    max = base + n * qsz;
    if (n >= 4) {
 qst(base, max);
 hi = base + thresh;
    } else {
 hi = max;
    }
    for (j = lo = base; (lo += qsz) < hi;) {
 if ((*qcmp) (j, lo) > 0)
     j = lo;
    }
    if (j != base) {
 for (i = base, hi = base + qsz; i < hi;) {
     c = *j;
     *j++ = *i;
     *i++ = c;
 }
    }
    for (min = base; (hi = min += qsz) < max;) {
 while ((*qcmp) (hi -= qsz, min) > 0);
 if ((hi += qsz) != min) {
     for (lo = min + qsz; --lo >= min;) {
  c = *lo;
  for (i = j = lo; (j -= qsz) >= hi; i = j)
      *i = *j;
  *i = c;
     }
 }
    }
}

variable_types: n int

variable_types: size int

variable_types:
compar
int (*)(char *, char *)

variable_types:
lo
char *

variable_types:
hi
char *

variable_types:
min
char *


original_code:
static void
insert_page(void)
{
    int i = 0;
    int j = 0;
    int page = 0;
    if (even_odd >= 0) {
 while (pageno[i++] != '\0');
 j = --i;
 while (((*__ctype_b_loc ())[(int) ((pageno[--i]))] & (unsigned short int) _ISdigit) && i > 0);
 if (!((*__ctype_b_loc ())[(int) ((pageno[i]))] & (unsigned short int) _ISdigit))
     i++;
 page = strtoint(&pageno[i]) + 1;
 if (((even_odd == 1) && (page % 2 == 0)) ||
     ((even_odd == 2) && (page % 2 == 1)))
     page++;
 pageno[j + 1] = '\0';
 while (page >= 10) {
     pageno[j--] = (char)((page % 10) + 48);
     page = page / 10;
 }
 pageno[j] = (char)((page) + 48);
 if (i < j) {
     while (pageno[j] != '\0')
  pageno[i++] = pageno[j++];
     pageno[i] = '\0';
 }
    }
    { fputs(setpage_open, ind_fp); };
    { fputs(pageno, ind_fp); };
    { fputs(setpage_close, ind_fp); };
    ind_lc += setpagelen;
}

canonical_original_code:
static void insert_page()
{
    int i = 0;
    int j = 0;
    int page = 0;
    if (even_odd >= 0) {
 while (pageno[i++] != '\0');
 j = --i;
 while (((*__ctype_b_loc ())[(int) ((pageno[--i]))] & (unsigned short) _ISdigit) && i > 0);
 if (!((*__ctype_b_loc ())[(int) ((pageno[i]))] & (unsigned short) _ISdigit))
     i++;
 page = strtoint(&pageno[i]) + 1;
 if (((even_odd == 1) && (page % 2 == 0)) ||
     ((even_odd == 2) && (page % 2 == 1)))
     page++;
 pageno[j + 1] = '\0';
 while (page >= 10) {
     pageno[j--] = (char)((page % 10) + 48);
     page = page / 10;
 }
 pageno[j] = (char)((page) + 48);
 if (i < j) {
     while (pageno[j] != '\0')
  pageno[i++] = pageno[j++];
     pageno[i] = '\0';
 }
    }
    { fputs(setpage_open, ind_fp); };
    { fputs(pageno, ind_fp); };
    { fputs(setpage_close, ind_fp); };
    ind_lc += setpagelen;
}

variable_types: i int

variable_types: j int

variable_types: page int


decompiled_code:
void __fastcall put_header(int a1)
{
int v1; // eax

if ( headings_flag )
{
fputs(&heading_pre, ind_fp);
ind_lc += headprelen;
v1 = *(_DWORD *)(curr + 48);
if ( v1 == -2 )
{
if ( headings_flag <= 0 )
{
a1 = (unsigned __int8)a1;
if ( ((*_ctype_b_loc())[(unsigned __int8)a1] & 0x100) != 0 )
a1 = LOBYTE((*_ctype_tolower_loc())[(unsigned __int8)a1]);
}
else
{
a1 = (unsigned __int8)a1;
if ( ((*_ctype_b_loc())[(unsigned __int8)a1] & 0x100) == 0 )
a1 = LOBYTE((*_ctype_toupper_loc())[(unsigned __int8)a1]);
}
fputc(a1, ind_fp);
}
else if ( v1 == -1 )
{
if ( headings_flag <= 0 )
fputs(&symhead_neg, ind_fp);
else
fputs(&symhead_pos, ind_fp);
}
else if ( headings_flag <= 0 )
{
fputs(&numhead_neg, ind_fp);
}
else
{
fputs(&numhead_pos, ind_fp);
}
fputs(&heading_suf, ind_fp);
ind_lc += headsuflen;
}
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
int v1; // eax

if ( headings_flag )
{
fputs(&heading_pre, ind_fp);
ind_lc += headprelen;
v1 = *(_DWORD *)(curr + 48);
if ( v1 == -2 )
{
if ( headings_flag <= 0 )
{
a1 = (unsigned __int8)a1;
if ( ((*_ctype_b_loc())[(unsigned __int8)a1] & 0x100) != 0 )
a1 = LOBYTE((*_ctype_tolower_loc())[(unsigned __int8)a1]);
}
else
{
a1 = (unsigned __int8)a1;
if ( ((*_ctype_b_loc())[(unsigned __int8)a1] & 0x100) == 0 )
a1 = LOBYTE((*_ctype_toupper_loc())[(unsigned __int8)a1]);
}
fputc(a1, ind_fp);
}
else if ( v1 == -1 )
{
if ( headings_flag <= 0 )
fputs(&symhead_neg, ind_fp);
else
fputs(&symhead_pos, ind_fp);
}
else if ( headings_flag <= 0 )
{
fputs(&numhead_neg, ind_fp);
}
else
{
fputs(&numhead_pos, ind_fp);
}
fputs(&heading_suf, ind_fp);
ind_lc += headsuflen;
}
}

original_code:
static void
put_header(int let)
{
    if (headings_flag)
    {
 { fputs(heading_pre, ind_fp); };
 ind_lc += headprelen;
 switch (curr->group)
 {
 case -1:
     if (headings_flag > 0)
     {
  { fputs(symhead_pos, ind_fp); };
     }
     else
     {
  { fputs(symhead_neg, ind_fp); };
     }
     break;
 case -2:
     if (headings_flag > 0)
     {
  let = (((*__ctype_b_loc ())[(int) (((unsigned char)(let)))] & (unsigned short int) _ISupper) ? (unsigned char)(let) : (unsigned char)toupper((unsigned char)(let)));
  { fputc(let, ind_fp); };
     }
     else
     {
  let = (((*__ctype_b_loc ())[(int) (((unsigned char)(let)))] & (unsigned short int) _ISupper) ? (unsigned char)tolower((unsigned char)(let)) : (unsigned char)(let));
  { fputc(let, ind_fp); };
     }
     break;
 default:
     if (headings_flag > 0)
     {
  { fputs(numhead_pos, ind_fp); };
     }
     else
     {
  { fputs(numhead_neg, ind_fp); };
     }
     break;
 }
 { fputs(heading_suf, ind_fp); };
 ind_lc += headsuflen;
    }
}

canonical_original_code:
static void put_header(int let)
{
    if (headings_flag)
    {
 { fputs(heading_pre, ind_fp); };
 ind_lc += headprelen;
 switch (curr->group)
 {
 case -1:
     if (headings_flag > 0)
     {
  { fputs(symhead_pos, ind_fp); };
     }
     else
     {
  { fputs(symhead_neg, ind_fp); };
     }
     break;
 case -2:
     if (headings_flag > 0)
     {
  let = (((*__ctype_b_loc ())[(int) (((unsigned char)(let)))] & (unsigned short) _ISupper) ? (unsigned char)(let) : (unsigned char)toupper((unsigned char)(let)));
  { fputc(let, ind_fp); };
     }
     else
     {
  let = (((*__ctype_b_loc ())[(int) (((unsigned char)(let)))] & (unsigned short) _ISupper) ? (unsigned char)tolower((unsigned char)(let)) : (unsigned char)(let));
  { fputc(let, ind_fp); };
     }
     break;
 default:
     if (headings_flag > 0)
     {
  { fputs(numhead_pos, ind_fp); };
     }
     else
     {
  { fputs(numhead_neg, ind_fp); };
     }
     break;
 }
 { fputs(heading_suf, ind_fp); };
 ind_lc += headsuflen;
    }
}

variable_types: let int


decompiled_code:
char *__fastcall make_item(const char *a1)
{
const char *v1; // r8
__int64 v2; // rbx
const char *v3; // rbp
const char *v4; // r8
const char *v5; // rcx
char *result; // rax

if ( level <= prev_level )
{
v4 = *(const char **)(curr + 8LL * level + 24);
if ( *v4 )
sprintf(line, "%s%s%s", a1, &item_r[1024 * (__int64)level], v4);
else
sprintf(line, "%s%s%s", a1, &item_r[1024 * (__int64)level], *(const char **)(curr + 8LL * level));
ind_lc += *((_DWORD *)&ilen_r + level);
}
else
{
v1 = *(const char **)(curr + 8LL * level + 24);
if ( *v1 )
sprintf(line, "%s%s%s", a1, &item_u[1024 * (__int64)level], v1);
else
sprintf(line, "%s%s%s", a1, &item_u[1024 * (__int64)level], *(const char **)(curr + 8LL * level));
ind_lc += *((_DWORD *)&ilen_u + level);
}
LODWORD(v2) = level + 1;
if ( level + 1 <= 2 )
{
v2 = (int)v2;
v3 = (char *)&item_x + 1024 * (__int64)(int)v2;
do
{
if ( !**(_BYTE **)(curr + 8LL * (int)v2) )
break;
fputs(line, ind_fp);
v5 = *(const char **)(curr + 8LL * (int)v2 + 24);
if ( *v5 )
sprintf(line, "%s%s", v3, v5);
else
sprintf(line, "%s%s", v3, *(const char **)(curr + 8LL * (int)v2));
ind_lc += *((_DWORD *)&ilen_x + v2);
level = v2++;
v3 += 1024;
}
while ( (int)v2 <= 2 );
}
ind_indent = 0;
strcat(line, &delim_p[1024 * (__int64)level]);
end = curr;
begin = curr;
result = encap;
prev_encap = encap;
return result;
}

canonical_decompiled_code:
char *__fastcall func3(const char *a1)
{
const char *v1; // r8
__int64 v2; // rbx
const char *v3; // rbp
const char *v4; // r8
const char *v5; // rcx
char *result; // rax

if ( level <= prev_level )
{
v4 = *(const char **)(curr + 8LL * level + 24);
if ( *v4 )
sprintf(line, "%s%s%s", a1, &item_r[1024 * (__int64)level], v4);
else
sprintf(line, "%s%s%s", a1, &item_r[1024 * (__int64)level], *(const char **)(curr + 8LL * level));
ind_lc += *((_DWORD *)&ilen_r + level);
}
else
{
v1 = *(const char **)(curr + 8LL * level + 24);
if ( *v1 )
sprintf(line, "%s%s%s", a1, &item_u[1024 * (__int64)level], v1);
else
sprintf(line, "%s%s%s", a1, &item_u[1024 * (__int64)level], *(const char **)(curr + 8LL * level));
ind_lc += *((_DWORD *)&ilen_u + level);
}
LODWORD(v2) = level + 1;
if ( level + 1 <= 2 )
{
v2 = (int)v2;
v3 = (char *)&item_x + 1024 * (__int64)(int)v2;
do
{
if ( !**(_BYTE **)(curr + 8LL * (int)v2) )
break;
fputs(line, ind_fp);
v5 = *(const char **)(curr + 8LL * (int)v2 + 24);
if ( *v5 )
sprintf(line, "%s%s", v3, v5);
else
sprintf(line, "%s%s", v3, *(const char **)(curr + 8LL * (int)v2));
ind_lc += *((_DWORD *)&ilen_x + v2);
level = v2++;
v3 += 1024;
}
while ( (int)v2 <= 2 );
}
ind_indent = 0;
strcat(line, &delim_p[1024 * (__int64)level]);
end = curr;
begin = curr;
result = encap;
prev_encap = encap;
return result;
}

original_code:
static void
make_item(char *term)
{
    int i;
    if (level > prev_level) {
 if (*curr->af[level] == '\0')
     sprintf(line, "%s%s%s", term, item_u[level], curr->sf[level]);
 else
     sprintf(line, "%s%s%s", term, item_u[level], curr->af[level]);
 ind_lc += ilen_u[level];
    } else {
 if (*curr->af[level] == '\0')
     sprintf(line, "%s%s%s", term, item_r[level], curr->sf[level]);
 else
     sprintf(line, "%s%s%s", term, item_r[level], curr->af[level]);
 ind_lc += ilen_r[level];
    }
    i = level + 1;
    while (i < 3 && *curr->sf[i] != '\0') {
 { fputs(line, ind_fp); };
 if (*curr->af[i] == '\0')
     sprintf(line, "%s%s", item_x[i], curr->sf[i]);
 else
     sprintf(line, "%s%s", item_x[i], curr->af[i]);
 ind_lc += ilen_x[i];
 level = i;
 i++;
    }
    ind_indent = 0;
    strcat(line, delim_p[level]);
    { begin = end = curr; prev_encap = encap; };
}

variable_types:
term
char *


decompiled_code:
int __fastcall wrap_line(int a1)
{
int v1; // ebx
int v2; // ebx
int result; // eax

v1 = strlen(line);
v2 = ind_indent + strlen(buff) + v1;
if ( a1 )
{
if ( linemax >= v2 )
{
fputs(line, ind_fp);
}
else
{
fputs(line, ind_fp);
fputc(10, ind_fp);
++ind_lc;
fputs(&indent_space, ind_fp);
ind_indent = indent_length;
}
result = fputs(buff, ind_fp);
}
else if ( linemax >= v2 )
{
strcat(buff, &delim_n);
result = (unsigned int)strcat(line, buff);
}
else
{
fputs(line, ind_fp);
fputc(10, ind_fp);
++ind_lc;
sprintf(line, "%s%s%s", &indent_space, buff, &delim_n);
result = indent_length;
ind_indent = indent_length;
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
int v1; // ebx
int v2; // ebx
int result; // eax

v1 = strlen(line);
v2 = ind_indent + strlen(buff) + v1;
if ( a1 )
{
if ( linemax >= v2 )
{
fputs(line, ind_fp);
}
else
{
fputs(line, ind_fp);
fputc(10, ind_fp);
++ind_lc;
fputs(&indent_space, ind_fp);
ind_indent = indent_length;
}
result = fputs(buff, ind_fp);
}
else if ( linemax >= v2 )
{
strcat(buff, &delim_n);
result = (unsigned int)strcat(line, buff);
}
else
{
fputs(line, ind_fp);
fputc(10, ind_fp);
++ind_lc;
sprintf(line, "%s%s%s", &indent_space, buff, &delim_n);
result = indent_length;
ind_indent = indent_length;
}
return result;
}

original_code:
static void
wrap_line(int print)
{
    int len;
    len = strlen(line) + strlen(buff) + ind_indent;
    if (print) {
 if (len > linemax) {
     { fputs(line, ind_fp); fputc('\n', ind_fp); ind_lc++; };
     { fputs(indent_space, ind_fp); };
     ind_indent = indent_length;
 } else
     { fputs(line, ind_fp); };
 { fputs(buff, ind_fp); };
    } else {
 if (len > linemax) {
     { fputs(line, ind_fp); fputc('\n', ind_fp); ind_lc++; };
     sprintf(line, "%s%s%s", indent_space, buff, delim_n);
     ind_indent = indent_length;
 } else {
     strcat(buff, delim_n);
     strcat(line, buff);
 }
    }
}

variable_types: print int

variable_types: len int


decompiled_code:
int __fastcall flush_line(int a1)
{
__int64 v1; // r13
__int64 v2; // rbp
int v3; // eax
int v4; // ebx
const char *v5; // rbx
char v7[2088]; // [rsp+0h] [rbp-828h] BYREF

v1 = end;
v2 = begin;
v3 = page_diff(begin, end);
if ( v3 )
{
v4 = v3;
if ( !encap_range && (int)page_diff(v2, prev) <= (suffix_2p == 0) )
{
sprintf(buff, "%s%s%s", (const char *)(v2 + 52), &delim_n, (const char *)(v1 + 52));
goto LABEL_9;
}
if ( v4 == 1 )
{
if ( suffix_2p )
{
sprintf(buff, "%s%s", (const char *)(v2 + 52), (const char *)&suffix_2p);
goto LABEL_8;
}
}
else
{
if ( v4 == 2 )
{
if ( suffix_3p )
{
sprintf(buff, "%s%s", (const char *)(v2 + 52), (const char *)&suffix_3p);
goto LABEL_8;
}
goto LABEL_6;
}
if ( v4 > 1 )
{
LABEL_6:
if ( suffix_mp )
{
sprintf(buff, "%s%s", (const char *)(v2 + 52), (const char *)&suffix_mp);
goto LABEL_8;
}
goto LABEL_7;
}
}
LABEL_7:
sprintf(buff, "%s%s%s", (const char *)(v2 + 52), (const char *)&delim_r, (const char *)(v1 + 52));
LABEL_8:
encap_range = 0;
goto LABEL_9;
}
encap_range = 0;
strcpy(buff, (const char *)(v2 + 52));
LABEL_9:
v5 = prev_encap;
if ( *prev_encap )
{
strcpy(v7, buff);
sprintf(buff, "%s%s%s%s%s", (const char *)&encap_p, v5, (const char *)&encap_i, v7, (const char *)&encap_s);
}
return wrap_line(a1);
}

canonical_decompiled_code:
int __fastcall func5(int a1)
{
__int64 v1; // r13
__int64 v2; // rbp
int v3; // eax
int v4; // ebx
const char *v5; // rbx
char v7[2088]; // [rsp+0h] [rbp-828h] BYREF

v1 = end;
v2 = begin;
v3 = func0(begin, end);
if ( v3 )
{
v4 = v3;
if ( !encap_range && (int)func0(v2, prev) <= (suffix_2p == 0) )
{
sprintf(buff, "%s%s%s", (const char *)(v2 + 52), &delim_n, (const char *)(v1 + 52));
goto LABEL_9;
}
if ( v4 == 1 )
{
if ( suffix_2p )
{
sprintf(buff, "%s%s", (const char *)(v2 + 52), (const char *)&suffix_2p);
goto LABEL_8;
}
}
else
{
if ( v4 == 2 )
{
if ( suffix_3p )
{
sprintf(buff, "%s%s", (const char *)(v2 + 52), (const char *)&suffix_3p);
goto LABEL_8;
}
goto LABEL_6;
}
if ( v4 > 1 )
{
LABEL_6:
if ( suffix_mp )
{
sprintf(buff, "%s%s", (const char *)(v2 + 52), (const char *)&suffix_mp);
goto LABEL_8;
}
goto LABEL_7;
}
}
LABEL_7:
sprintf(buff, "%s%s%s", (const char *)(v2 + 52), (const char *)&delim_r, (const char *)(v1 + 52));
LABEL_8:
encap_range = 0;
goto LABEL_9;
}
encap_range = 0;
strcpy(buff, (const char *)(v2 + 52));
LABEL_9:
v5 = prev_encap;
if ( *prev_encap )
{
strcpy(v7, buff);
sprintf(buff, "%s%s%s%s%s", (const char *)&encap_p, v5, (const char *)&encap_i, v7, (const char *)&encap_s);
}
return func4(a1);
}

original_code:
static void
flush_line(int print)
{
    char tmp[sizeof(buff)];
    if (page_diff(begin, end) != 0)
 if (encap_range || (page_diff(begin, prev) > (*suffix_2p ? 0 : 1)))
 {
  int diff = page_diff(begin, end);
  if ((diff == 1) && *suffix_2p)
      sprintf(buff, "%s%s", begin->lpg, suffix_2p);
  else if ((diff == 2) && *suffix_3p)
      sprintf(buff, "%s%s", begin->lpg, suffix_3p);
  else if ((diff >= 2) && *suffix_mp)
      sprintf(buff, "%s%s", begin->lpg, suffix_mp);
  else
      sprintf(buff, "%s%s%s", begin->lpg, delim_r, end->lpg);
     encap_range = 0;
 }
 else
     sprintf(buff, "%s%s%s", begin->lpg, delim_n, end->lpg);
    else
    {
 encap_range = 0;
 strcpy(buff, begin->lpg);
    }
    if (*prev_encap != '\0')
    {
 strcpy(tmp, buff);
 sprintf(buff, "%s%s%s%s%s",
  encap_p, prev_encap, encap_i, tmp, encap_s);
    }
    wrap_line(print);
}

canonical_original_code:
static void flush_line(int print)
{
    char tmp[-1];
    if (page_diff(begin, end) != 0)
 if (encap_range || (page_diff(begin, prev) > (*suffix_2p ? 0 : 1)))
 {
  int diff = page_diff(begin, end);
  if ((diff == 1) && *suffix_2p)
      sprintf(buff, "%s%s", begin->lpg, suffix_2p);
  else if ((diff == 2) && *suffix_3p)
      sprintf(buff, "%s%s", begin->lpg, suffix_3p);
  else if ((diff >= 2) && *suffix_mp)
      sprintf(buff, "%s%s", begin->lpg, suffix_mp);
  else
      sprintf(buff, "%s%s%s", begin->lpg, delim_r, end->lpg);
     encap_range = 0;
 }
 else
     sprintf(buff, "%s%s%s", begin->lpg, delim_n, end->lpg);
    else
    {
 encap_range = 0;
 strcpy(buff, begin->lpg);
    }
    if (*prev_encap != '\0')
    {
 strcpy(tmp, buff);
 sprintf(buff, "%s%s%s%s%s",
  encap_p, prev_encap, encap_i, tmp, encap_s);
    }
    wrap_line(print);
}

variable_types:
tmp
char [-1]

variable_types: diff int


decompiled_code:
int old_entry()
{
__int64 v0; // rbp
int v1; // ebx
int result; // eax
const char *v3; // rbx

v0 = curr;
v1 = page_diff(end, curr);
if ( *(_WORD *)(prev + 90) != *(_WORD *)(v0 + 90) || v1 == -1 )
{
flush_line(0);
if ( !v1 )
{
LABEL_25:
if ( *(_WORD *)(prev + 90) == *(_WORD *)(curr + 90) )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Conflicting entries: multiple encaps for the same page under same key.\n");
++ind_ec;
goto LABEL_30;
}
if ( in_range )
goto LABEL_27;
goto LABEL_30;
}
LABEL_12:
if ( in_range )
{
if ( *(_WORD *)(prev + 90) == *(_WORD *)(curr + 90) )
{
if ( v1 == -1 )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Illegal range formation: starting & ending pages cross chap/sec breaks.\n");
++ind_ec;
}
goto LABEL_30;
}
LABEL_27:
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Illegal range formation: starting & ending pages are of different types.\n");
++ind_ec;
}
LABEL_30:
end = curr;
begin = curr;
result = (int)encap;
prev_encap = encap;
return result;
}
if ( !v1 )
{
if ( !prev_encap || (result = strcmp(encap, prev_encap)) != 0 )
{
if ( !in_range )
{
flush_line(0);
goto LABEL_25;
}
goto LABEL_35;
}
LABEL_20:
end = v0;
if ( !in_range )
return result;
goto LABEL_36;
}
if ( merge_page )
{
if ( v1 == 1 )
{
if ( prev_encap )
{
result = strcmp(encap, prev_encap);
if ( !result )
goto LABEL_20;
}
}
}
if ( !in_range )
{
flush_line(0);
goto LABEL_12;
}
LABEL_35:
end = v0;
LABEL_36:
v3 = *(const char **)(v0 + 96);
result = *(unsigned __int8 *)v3;
if ( !(_BYTE)result
|| (_BYTE)result == idx_rclose
|| (result = strcmp(*(const char **)(v0 + 96), prev_encap)) == 0
|| (sprintf(
buff,
"%s%s%s%s%s",
(const char *)&encap_p,
v3,
(const char *)&encap_i,
(const char *)(v0 + 52),
(const char *)&encap_s),
result = wrap_line(0),
in_range) )
{
encap_range = 1;
}
return result;
}

canonical_decompiled_code:
int func7()
{
__int64 v0; // rbp
int v1; // ebx
int result; // eax
const char *v3; // rbx

v0 = curr;
v1 = func0(end, curr);
if ( *(_WORD *)(prev + 90) != *(_WORD *)(v0 + 90) || v1 == -1 )
{
func5(0);
if ( !v1 )
{
LABEL_25:
if ( *(_WORD *)(prev + 90) == *(_WORD *)(curr + 90) )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Conflicting entries: multiple encaps for the same page under same key.\n");
++ind_ec;
goto LABEL_30;
}
if ( in_range )
goto LABEL_27;
goto LABEL_30;
}
LABEL_12:
if ( in_range )
{
if ( *(_WORD *)(prev + 90) == *(_WORD *)(curr + 90) )
{
if ( v1 == -1 )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Illegal range formation: starting & ending pages cross chap/sec breaks.\n");
++ind_ec;
}
goto LABEL_30;
}
LABEL_27:
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Illegal range formation: starting & ending pages are of different types.\n");
++ind_ec;
}
LABEL_30:
end = curr;
begin = curr;
result = (int)encap;
prev_encap = encap;
return result;
}
if ( !v1 )
{
if ( !prev_encap || (result = strcmp(encap, prev_encap)) != 0 )
{
if ( !in_range )
{
func5(0);
goto LABEL_25;
}
goto LABEL_35;
}
LABEL_20:
end = v0;
if ( !in_range )
return result;
goto LABEL_36;
}
if ( merge_page )
{
if ( v1 == 1 )
{
if ( prev_encap )
{
result = strcmp(encap, prev_encap);
if ( !result )
goto LABEL_20;
}
}
}
if ( !in_range )
{
func5(0);
goto LABEL_12;
}
LABEL_35:
end = v0;
LABEL_36:
v3 = *(const char **)(v0 + 96);
result = *(unsigned __int8 *)v3;
if ( !(_BYTE)result
|| (_BYTE)result == idx_rclose
|| (result = strcmp(*(const char **)(v0 + 96), prev_encap)) == 0
|| (sprintf(
buff,
"%s%s%s%s%s",
(const char *)&encap_p,
v3,
(const char *)&encap_i,
(const char *)(v0 + 52),
(const char *)&encap_s),
result = func4(0),
in_range) )
{
encap_range = 1;
}
return result;
}

original_code:
static void
old_entry(void)
{
    int diff;
    diff = page_diff(end, curr);
    if ((prev->type == curr->type) && (diff != -1) &&
 (((diff == 0) && (prev_encap != ((void *)0)) && (strcmp(encap, prev_encap) == 0)) ||
  (merge_page && (diff == 1) &&
   (prev_encap != ((void *)0)) && (strcmp(encap, prev_encap) == 0)) ||
  in_range)) {
 end = curr;
 if (in_range &&
     (*curr->encap != '\0') &&
     (*curr->encap != idx_rclose) &&
     (strcmp(curr->encap, prev_encap) != 0)) {
     sprintf(buff, "%s%s%s%s%s", encap_p, curr->encap,
      encap_i, curr->lpg, encap_s);
     wrap_line(0);
 }
 if (in_range)
     encap_range = 1;
    } else {
 flush_line(0);
 if ((diff == 0) && (prev->type == curr->type)) {
{ if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Conflicting entries: multiple encaps for the same page under same key.\n", ""); ind_ec++; };
 } else if (in_range && (prev->type != curr->type)) {
{ if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Illegal range formation: starting & ending pages are of different types.\n", ""); ind_ec++; };
 } else if (in_range && (diff == -1)) {
{ if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Illegal range formation: starting & ending pages cross chap/sec breaks.\n", ""); ind_ec++; };
 }
 { begin = end = curr; prev_encap = encap; };
    }
}

canonical_original_code:
static void old_entry()
{
    int diff;
    diff = page_diff(end, curr);
    if ((prev->type == curr->type) && (diff != -1) &&
 (((diff == 0) && (prev_encap != ((void *)0)) && (strcmp(encap, prev_encap) == 0)) ||
  (merge_page && (diff == 1) &&
   (prev_encap != ((void *)0)) && (strcmp(encap, prev_encap) == 0)) ||
  in_range)) {
 end = curr;
 if (in_range &&
     (*curr->encap != '\0') &&
     (*curr->encap != idx_rclose) &&
     (strcmp(curr->encap, prev_encap) != 0)) {
     sprintf(buff, "%s%s%s%s%s", encap_p, curr->encap,
      encap_i, curr->lpg, encap_s);
     wrap_line(0);
 }
 if (in_range)
     encap_range = 1;
    } else {
 flush_line(0);
 if ((diff == 0) && (prev->type == curr->type)) {
{ if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Conflicting entries: multiple encaps for the same page under same key.\n", ""); ind_ec++; };
 } else if (in_range && (prev->type != curr->type)) {
{ if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Illegal range formation: starting & ending pages are of different types.\n", ""); ind_ec++; };
 } else if (in_range && (diff == -1)) {
{ if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Illegal range formation: starting & ending pages cross chap/sec breaks.\n", ""); ind_ec++; };
 }
 { begin = end = curr; prev_encap = encap; };
    }
}


decompiled_code:
__int64 __fastcall make_entry(int a1)
{
__int64 v1; // r13
char **v2; // r12
char *v3; // rax
__int64 v4; // rbx
const char *v5; // rdi
char v6; // al

v1 = curr;
prev = curr;
v2 = *(char ***)(idx_key + 8LL * a1);
curr = (__int64)v2;
v3 = v2[12];
if ( *v3 == idx_ropen || *v3 == idx_rclose )
++v3;
encap = v3;
if ( a1 )
{
prev_level = level;
level = 0;
v4 = 0LL;
while ( !strcmp(v2[v4], *(const char **)(v1 + 8 * v4)) && !strcmp(v2[v4 + 3], *(const char **)(v1 + 8 * v4 + 24)) )
{
level = ++v4;
if ( v4 == 3 )
goto LABEL_9;
}
if ( (int)v4 > 2 )
{
LABEL_9:
old_entry();
goto LABEL_13;
}
new_entry();
}
else
{
level = 0;
prev_level = 0;
put_header(**v2);
make_item((const char *)&unk_249F);
}
LABEL_13:
v5 = *(const char **)(curr + 96);
v6 = *v5;
if ( *v5 == idx_ropen )
{
if ( in_range )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Extra range opening operator %c.\n", (unsigned int)idx_ropen);
++ind_ec;
}
else
{
in_range = 1;
range_ptr = curr;
}
}
else if ( v6 == idx_rclose )
{
if ( in_range )
{
in_range = 0;
if ( v5[1] && strcmp(prev_encap, v5 + 1) )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(
ilg_fp,
"Range closing operator has an inconsistent encapsulator %s.\n",
(const char *)(*(_QWORD *)(curr + 96) + 1LL));
++ind_ec;
}
}
else
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Unmatched range closing operator %c.\n", (unsigned int)idx_rclose);
++ind_ec;
}
}
else if ( v6 && strcmp(v5, prev_encap) && in_range )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Inconsistent page encapsulator %s within range.\n", *(const char **)(curr + 96));
++ind_ec;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // r13
char **v2; // r12
char *v3; // rax
__int64 v4; // rbx
const char *v5; // rdi
char v6; // al

v1 = curr;
prev = curr;
v2 = *(char ***)(idx_key + 8LL * a1);
curr = (__int64)v2;
v3 = v2[12];
if ( *v3 == idx_ropen || *v3 == idx_rclose )
++v3;
encap = v3;
if ( a1 )
{
prev_level = level;
level = 0;
v4 = 0LL;
while ( !strcmp(v2[v4], *(const char **)(v1 + 8 * v4)) && !strcmp(v2[v4 + 3], *(const char **)(v1 + 8 * v4 + 24)) )
{
level = ++v4;
if ( v4 == 3 )
goto LABEL_9;
}
if ( (int)v4 > 2 )
{
LABEL_9:
func7();
goto LABEL_13;
}
func6();
}
else
{
level = 0;
prev_level = 0;
func2(**v2);
func3((const char *)&unk_249F);
}
LABEL_13:
v5 = *(const char **)(curr + 96);
v6 = *v5;
if ( *v5 == idx_ropen )
{
if ( in_range )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Extra range opening operator %c.\n", (unsigned int)idx_ropen);
++ind_ec;
}
else
{
in_range = 1;
range_ptr = curr;
}
}
else if ( v6 == idx_rclose )
{
if ( in_range )
{
in_range = 0;
if ( v5[1] && strcmp(prev_encap, v5 + 1) )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(
ilg_fp,
"Range closing operator has an inconsistent encapsulator %s.\n",
(const char *)(*(_QWORD *)(curr + 96) + 1LL));
++ind_ec;
}
}
else
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Unmatched range closing operator %c.\n", (unsigned int)idx_rclose);
++ind_ec;
}
}
else if ( v6 && strcmp(v5, prev_encap) && in_range )
{
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Inconsistent page encapsulator %s within range.\n", *(const char **)(curr + 96));
++ind_ec;
}
return 1LL;
}

original_code:
static int
make_entry(int n)
{
    int let;
    prev = curr;
    curr = idx_key[n];
    if ((*curr->encap == idx_ropen) || (*curr->encap == idx_rclose))
 encap = &(curr->encap[1]);
    else
 encap = curr->encap;
    if (n == 0) {
 prev_level = level = 0;
 let = *curr->sf[0];
 put_header(let);
 make_item("");
    } else {
 prev_level = level;
 for (level = 0; level < 3; level++)
     if ((strcmp(curr->sf[level], prev->sf[level]) != 0) ||
  (strcmp(curr->af[level], prev->af[level]) != 0))
  break;
 if (level < 3)
     new_entry();
 else
     old_entry();
    }
    if (*curr->encap == idx_ropen)
 if (in_range) {
     { if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Extra range opening operator %c.\n", idx_ropen); ind_ec++; };
 } else {
     in_range = 1;
     range_ptr = curr;
 }
    else if (*curr->encap == idx_rclose)
 if (in_range) {
     in_range = 0;
     if ((strcmp(&(curr->encap[1]), "") != 0) &&
  (strcmp(prev_encap, &(curr->encap[1])) != 0)) {
{ if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Range closing operator has an inconsistent encapsulator %s.\n", &(curr->encap[1])); ind_ec++; };
     }
 } else {
     { if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Unmatched range closing operator %c.\n", idx_rclose); ind_ec++; };
 }
    else if ((*curr->encap != '\0') &&
      (strcmp(curr->encap, prev_encap) != 0) && in_range)
 { if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Inconsistent page encapsulator %s within range.\n", curr->encap); ind_ec++; };
    return (1);
}


decompiled_code:
int gen_ind()
{
__int64 v0; // rbx
unsigned int v2; // ebx
int result; // eax

if ( verbose )
fprintf(stderr, "Generating output file %s...", ind_fn);
fprintf(ilg_fp, "Generating output file %s...", ind_fn);
fputs(&preamble, ind_fp);
ind_lc += prelen;
if ( init_page )
insert_page();
idx_dc = 0;
if ( idx_gt > 0 )
{
v0 = 0LL;
do
{
if ( *(_WORD *)(*(_QWORD *)(idx_key + 8 * v0) + 90LL) != 9999 && (unsigned int)make_entry(v0) )
{
idx_dot = 1;
if ( !idx_dc++ )
{
if ( verbose )
fputc(46, stderr);
fputc(46, ilg_fp);
}
if ( idx_dc == 1000 )
idx_dc = 0;
}
++v0;
}
while ( idx_gt > (int)v0 );
}
if ( in_range )
{
curr = range_ptr;
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Unmatched range opening operator %c.\n", (unsigned int)idx_ropen);
++ind_ec;
}
prev = curr;
flush_line(1);
fputs(&delim_t, ind_fp);
fputs(&postamble, ind_fp);
v2 = ind_lc + postlen;
if ( ind_ec == 1 )
{
if ( verbose )
fprintf(stderr, "done (%d %s, %d %s).\n", v2, "lines written", (unsigned int)ind_ec, "warning");
result = fprintf(ilg_fp, "done (%d %s, %d %s).\n", v2, "lines written", (unsigned int)ind_ec, "warning");
}
else
{
if ( verbose )
fprintf(stderr, "done (%d %s, %d %s).\n", v2, "lines written", (unsigned int)ind_ec, "warnings");
result = fprintf(ilg_fp, "done (%d %s, %d %s).\n", v2, "lines written", (unsigned int)ind_ec, "warnings");
}
return result;
}

canonical_decompiled_code:
int func9()
{
__int64 v0; // rbx
unsigned int v2; // ebx
int result; // eax

if ( verbose )
fprintf(stderr, "Generating output file %s...", ind_fn);
fprintf(ilg_fp, "Generating output file %s...", ind_fn);
fputs(&preamble, ind_fp);
ind_lc += prelen;
if ( init_page )
func1();
idx_dc = 0;
if ( idx_gt > 0 )
{
v0 = 0LL;
do
{
if ( *(_WORD *)(*(_QWORD *)(idx_key + 8 * v0) + 90LL) != 9999 && (unsigned int)func8(v0) )
{
idx_dot = 1;
if ( !idx_dc++ )
{
if ( verbose )
fputc(46, stderr);
fputc(46, ilg_fp);
}
if ( idx_dc == 1000 )
idx_dc = 0;
}
++v0;
}
while ( idx_gt > (int)v0 );
}
if ( in_range )
{
curr = range_ptr;
if ( idx_dot )
{
fputc(10, ilg_fp);
idx_dot = 0;
}
fprintf(
ilg_fp,
"## Warning (input = %s, line = %d; output = %s, line = %d):\n -- ",
*(const char **)(curr + 104),
*(unsigned int *)(curr + 112),
ind_fn,
(unsigned int)(ind_lc + 1));
fprintf(ilg_fp, "Unmatched range opening operator %c.\n", (unsigned int)idx_ropen);
++ind_ec;
}
prev = curr;
func5(1);
fputs(&delim_t, ind_fp);
fputs(&postamble, ind_fp);
v2 = ind_lc + postlen;
if ( ind_ec == 1 )
{
if ( verbose )
fprintf(stderr, "done (%d %s, %d %s).\n", v2, "lines written", (unsigned int)ind_ec, "warning");
result = fprintf(ilg_fp, "done (%d %s, %d %s).\n", v2, "lines written", (unsigned int)ind_ec, "warning");
}
else
{
if ( verbose )
fprintf(stderr, "done (%d %s, %d %s).\n", v2, "lines written", (unsigned int)ind_ec, "warnings");
result = fprintf(ilg_fp, "done (%d %s, %d %s).\n", v2, "lines written", (unsigned int)ind_ec, "warnings");
}
return result;
}

original_code:
void
gen_ind(void)
{
    int n;
    int tmp_lc;
    { if (verbose) fprintf(stderr, "Generating output file %s...", ind_fn); fprintf(ilg_fp, "Generating output file %s...", ind_fn); };
    { fputs(preamble, ind_fp); };
    ind_lc += prelen;
    if (init_page)
 insert_page();
    idx_dc = 0;
    for (n = 0; n < idx_gt; n++) {
 if (idx_key[n]->type != 9999)
     if (make_entry(n)) {
  { idx_dot = 1; if (idx_dc++ == 0) { if (verbose) fprintf(stderr, "."); fprintf(ilg_fp, "."); } if (idx_dc == 1000) idx_dc = 0; };
     }
    }
    tmp_lc = ind_lc;
    if (in_range) {
 curr = range_ptr;
 { if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Unmatched range opening operator %c.\n", idx_ropen); ind_ec++; };
    }
    prev = curr;
    flush_line(1);
    { fputs(delim_t, ind_fp); };
    { fputs(postamble, ind_fp); };
    tmp_lc = ind_lc + postlen;
    if (ind_ec == 1) {
 { if (verbose) fprintf(stderr, "done (%d %s, %d %s).\n", (tmp_lc), "lines written", ind_ec, "warning"); fprintf(ilg_fp, "done (%d %s, %d %s).\n", (tmp_lc), "lines written", ind_ec, "warning"); };
    } else {
 { if (verbose) fprintf(stderr, "done (%d %s, %d %s).\n", (tmp_lc), "lines written", ind_ec, "warnings"); fprintf(ilg_fp, "done (%d %s, %d %s).\n", (tmp_lc), "lines written", ind_ec, "warnings"); };
    }
}

canonical_original_code:
void gen_ind()
{
    int n;
    int tmp_lc;
    { if (verbose) fprintf(stderr, "Generating output file %s...", ind_fn); fprintf(ilg_fp, "Generating output file %s...", ind_fn); };
    { fputs(preamble, ind_fp); };
    ind_lc += prelen;
    if (init_page)
 insert_page();
    idx_dc = 0;
    for (n = 0; n < idx_gt; n++) {
 if (idx_key[n]->type != 9999)
     if (make_entry(n)) {
  { idx_dot = 1; if (idx_dc++ == 0) { if (verbose) fprintf(stderr, "."); fprintf(ilg_fp, "."); } if (idx_dc == 1000) idx_dc = 0; };
     }
    }
    tmp_lc = ind_lc;
    if (in_range) {
 curr = range_ptr;
 { if (idx_dot) { fprintf(ilg_fp, "\n"); idx_dot = 0; } fprintf(ilg_fp, "## Warning (input = %s, line = %d; output = %s, line = %d):\n   -- ", curr->fn, curr->lc, ind_fn, ind_lc+1); fprintf(ilg_fp, "Unmatched range opening operator %c.\n", idx_ropen); ind_ec++; };
    }
    prev = curr;
    flush_line(1);
    { fputs(delim_t, ind_fp); };
    { fputs(postamble, ind_fp); };
    tmp_lc = ind_lc + postlen;
    if (ind_ec == 1) {
 { if (verbose) fprintf(stderr, "done (%d %s, %d %s).\n", (tmp_lc), "lines written", ind_ec, "warning"); fprintf(ilg_fp, "done (%d %s, %d %s).\n", (tmp_lc), "lines written", ind_ec, "warning"); };
    } else {
 { if (verbose) fprintf(stderr, "done (%d %s, %d %s).\n", (tmp_lc), "lines written", ind_ec, "warnings"); fprintf(ilg_fp, "done (%d %s, %d %s).\n", (tmp_lc), "lines written", ind_ec, "warnings"); };
    }
}


original_code:
void umbralizar_c (
 unsigned char *src,
 unsigned char *dst,
 int h,
 int w,
 int row_size,
 unsigned char min,
 unsigned char max,
 unsigned char q
) {
 int dif = row_size - w;
 int i,j;
 for (i = h; i > 0;--i)
 {
  for (j = w; j > 0;--j)
  {
   if (*src < min)
   {
    *dst = 0;
   }
   else if (*src > max)
   {
    *dst = 255;
   }else
   {
    *dst = (*src/q)*q;
   }
   src++;
   dst++;
  }
  src += dif;
  dst += dif;
 }
}

canonical_original_code:
void umbralizar_c(unsigned char *src, unsigned char *dst, int h, int w, int row_size, unsigned char min, unsigned char max, unsigned char q) {
 int dif = row_size - w;
 int i; int j;
 for (i = h; i > 0;--i)
 {
  for (j = w; j > 0;--j)
  {
   if (*src < min)
   {
    *dst = 0;
   }
   else if (*src > max)
   {
    *dst = 255;
   }else
   {
    *dst = (*src/q)*q;
   }
   src++;
   dst++;
  }
  src += dif;
  dst += dif;
 }
}

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types: h int

variable_types: w int

variable_types:
min
unsigned char

variable_types:
max
unsigned char

variable_types:
q
unsigned char

variable_types: dif int