original_code:
int cid_parse_buffer(callerid_t *cid, const uint8_t* buf, size_t len)
{
    size_t seizure_count = 0;
    int end;
    int i=0;
    while (i<len) {
        if (buf[i] == 0x55) {
            break;
        } else {
            i++;
        }
    }
    while (i<len) {
        if (buf[i] == 0x55 || buf[i] == 0xD5) {
            seizure_count++;
            i++;
        } else {
            break;
        }
    }
    if (seizure_count < 12) {
        printf("Failed to find enough seizure bytes\n");
        return -1;
    }
    if (buf[i] != 0x80) {
        printf("Message type is not 0x80 (CLIP)\n");
        return -2;
    } else {
        i++;
    }
    end = buf[i] + i;
    if (end >= len) {
        printf("Not enough bytes in buffer\n");
        return -3;
    } else {
        i++;
    }
    if (check_checksum(&buf[i-2], buf[i-1]+2)) {
        printf("Error: checksum did not validate\n");
        return -4;
    }
    while (i < end) {
        int param_type = buf[i++];
        int param_len = buf[i++];
        switch(param_type) {
            case CID_PARAM_DATE_TIME:
              cid->month = parse_ascii_num(&buf[i]);
              cid->day = parse_ascii_num(&buf[i+2]);
              cid->hour = parse_ascii_num(&buf[i+4]);
              cid->min = parse_ascii_num(&buf[i+6]);
            break;
            case CID_PARAM_CALLER:
              memcpy(cid->caller, &buf[i], param_len);
              cid->caller[param_len] = '\0';
            break;
            case CID_PARAM_CALLED:
              memcpy(cid->called, &buf[i], param_len);
              cid->called[param_len] = '\0';
            break;
            case CID_PARAM_REASON_DN:
              cid->reason_dn = buf[i];
            break;
            case CID_PARAM_NAME:
              memcpy(cid->name, &buf[i], param_len);
              cid->called[param_len] = '\0';
            break;
            case CID_PARAM_REASON_NAME:
              cid->reason_name = buf[i];
            break;
            case CID_PARAM_CALL_TYPE:
              cid->call_type = buf[i];
            break;
            default:
              fprintf(stderr, "Warning: unknown param type: 0x%2.2x\n", param_type);
            break;
        }
        i += param_len;
    }
    return 0;
}

canonical_original_code:
int cid_parse_buffer(struct callerid_t *cid, unsigned char *buf, unsigned long len)
{
    unsigned long seizure_count = 0;
    int end;
    int i = 0;
    while (i<len) {
        if (buf[i] == 0x55) {
            break;
        } else {
            i++;
        }
    }
    while (i<len) {
        if (buf[i] == 0x55 || buf[i] == 0xD5) {
            seizure_count++;
            i++;
        } else {
            break;
        }
    }
    if (seizure_count < 12) {
        printf("Failed to find enough seizure bytes\n");
        return -1;
    }
    if (buf[i] != 0x80) {
        printf("Message type is not 0x80 (CLIP)\n");
        return -2;
    } else {
        i++;
    }
    end = buf[i] + i;
    if (end >= len) {
        printf("Not enough bytes in buffer\n");
        return -3;
    } else {
        i++;
    }
    if (check_checksum(&buf[i-2], buf[i-1]+2)) {
        printf("Error: checksum did not validate\n");
        return -4;
    }
    while (i < end) {
        int param_type = buf[i++];
        int param_len = buf[i++];
        switch(param_type) {
            case CID_PARAM_DATE_TIME:
              cid->month = parse_ascii_num(&buf[i]);
              cid->day = parse_ascii_num(&buf[i+2]);
              cid->hour = parse_ascii_num(&buf[i+4]);
              cid->min = parse_ascii_num(&buf[i+6]);
            break;
            case CID_PARAM_CALLER:
              memcpy(cid->caller, &buf[i], param_len);
              cid->caller[param_len] = '\0';
            break;
            case CID_PARAM_CALLED:
              memcpy(cid->called, &buf[i], param_len);
              cid->called[param_len] = '\0';
            break;
            case CID_PARAM_REASON_DN:
              cid->reason_dn = buf[i];
            break;
            case CID_PARAM_NAME:
              memcpy(cid->name, &buf[i], param_len);
              cid->called[param_len] = '\0';
            break;
            case CID_PARAM_REASON_NAME:
              cid->reason_name = buf[i];
            break;
            case CID_PARAM_CALL_TYPE:
              cid->call_type = buf[i];
            break;
            default:
              fprintf(stderr, "Warning: unknown param type: 0x%2.2x\n", param_type);
            break;
        }
        i += param_len;
    }
    return 0;
}

variable_types: struct callerid_t { int call_type; int month; int day; int hour; int min; char caller[19]; char called[19]; char reason_dn; char name[21]; char reason_name; } *

variable_types: end int


main

canonical_name: main

repo: nkopa/GSuma

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r14
__int64 v4; // rdx
unsigned int v5; // er12
unsigned int v6; // ebx
unsigned int v7; // er13
unsigned int v8; // eax
unsigned int v9; // ebp
_BYTE v11[128]; // [rsp+0h] [rbp-128h] BYREF
char v12[168]; // [rsp+80h] [rbp-A8h] BYREF

v3 = 122;
czyscTab(v11, argv, envp);
do
{
v5 = 0;
v6 = 0;
v7 = 0;
czyscTab(v12, argv, v4);
zasady();
wyswietl(0LL, 0LL, 0LL);
while ( (unsigned int)czyKoniec(v6) )
{
v3 = 99;
v8 = ruchCzl(v6);
v6 += v8;
v9 = v8;
if ( (unsigned int)czyKoniec(v6) )
{
v3 = 107;
v7 = ruchKom(v5, v12, v11, v6);
v6 += v7;
}
++v5;
wyswietl(v9, v7, v6);
}
argv = (const char **)v12;
ktoWygr((unsigned int)v3, v12, v11);
}
while ( (unsigned int)czyJeszcze() );
puts("Dzieki za gre. Do zobaczenia nastepnym razem ;)");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // r14
__int64 v4; // rdx
unsigned int v5; // er12
unsigned int v6; // ebx
unsigned int v7; // er13
unsigned int v8; // eax
unsigned int v9; // ebp
_BYTE v11[128]; // [rsp+0h] [rbp-128h] BYREF
char v12[168]; // [rsp+80h] [rbp-A8h] BYREF

v3 = 122;
czyscTab(v11, argv, envp);
do
{
v5 = 0;
v6 = 0;
v7 = 0;
czyscTab(v12, argv, v4);
func7();
func8(0LL, 0LL, 0LL);
while ( (unsigned int)func13(v6) )
{
v3 = 99;
v8 = func16(v6);
v6 += v8;
v9 = v8;
if ( (unsigned int)func13(v6) )
{
v3 = 107;
v7 = func11(v5, v12, v11, v6);
v6 += v7;
}
++v5;
func8(v9, v7, v6);
}
argv = (const char **)v12;
func15((unsigned int)v3, v12, v11);
}
while ( (unsigned int)func17() );
puts("Dzieki za gre. Do zobaczenia nastepnym razem ;)");
return 0;
}

original_code:
int main(){
  int czl;
  int kom;
  int suma;
  int licznik;
  int nau[3][20/2];
  int pomnau[3][20/2];
  char ruch='z';
  czyscTab(nau);
  do{
    czyscTab(pomnau);
    suma=0;
    czl=0;
    kom=0;
    licznik=0;
    zasady();
    wyswietl(czl,kom,suma);
    while(czyKoniec(suma)){
      czl=ruchCzl(suma);
      ruch='c';
      suma+=czl;
      if(czyKoniec(suma)){
 kom=ruchKom(licznik,pomnau,nau,suma);
        ruch='k';
 suma+=kom;
      }
      wyswietl(czl,kom,suma);
      licznik++;
    }
    ktoWygr(ruch,pomnau,nau);
  }while(czyJeszcze());
  printf("Dzieki za gre. Do zobaczenia nastepnym razem ;)\n");
  return 0;
}

canonical_original_code:
int main(){
  int czl;
  int kom;
  int suma;
  int licznik;
  int nau[3][-1];
  int pomnau[3][-1];
  char ruch = 'z';
  czyscTab(nau);
  do{
    czyscTab(pomnau);
    suma=0;
    czl=0;
    kom=0;
    licznik=0;
    zasady();
    wyswietl(czl,kom,suma);
    while(czyKoniec(suma)){
      czl=ruchCzl(suma);
      ruch='c';
      suma+=czl;
      if(czyKoniec(suma)){
 kom=ruchKom(licznik,pomnau,nau,suma);
        ruch='k';
 suma+=kom;
      }
      wyswietl(czl,kom,suma);
      licznik++;
    }
    ktoWygr(ruch,pomnau,nau);
  }while(czyJeszcze());
  printf("Dzieki za gre. Do zobaczenia nastepnym razem ;)\n");
  return 0;
}

variable_types: czl int

variable_types: kom int

variable_types: suma int

variable_types: licznik int

variable_types:
pomnau
int [3][-1]

variable_types: ruch char

return_type: int


zasady

decompiled_code:
int zasady()
{
puts("\n\n\n ZASADY GRY:\n");
return printf(
"Gra polega na podawaniu kolejno przez gracza i komputer jednej liczby: 1, 2 lub 3, ktore sa do siebie dodawan"
"e. Gra konczy sie, gdy suma liczb osiagne %i. Wygrywa ten, kto poda ostatnia liczbe do sumy.\n"
"\n",
20LL);
}

canonical_decompiled_code:
int func7()
{
puts("\n\n\n ZASADY GRY:\n");
return printf(
"Gra polega na podawaniu kolejno przez gracza i komputer jednej liczby: 1, 2 lub 3, ktore sa do siebie dodawan"
"e. Gra konczy sie, gdy suma liczb osiagne %i. Wygrywa ten, kto poda ostatnia liczbe do sumy.\n"
"\n",
20LL);
}

original_code:
void zasady(){
  printf("\n\n\n ZASADY GRY:\n\n");
  printf("Gra polega na podawaniu kolejno przez gracza i komputer jednej liczby: 1, 2 lub 3, ktore sa do siebie dodawane. Gra konczy sie, gdy suma liczb osiagne %i. Wygrywa ten, kto poda ostatnia liczbe do sumy.\n\n",20);
}

return_type: void


wyswietl

decompiled_code:
int __fastcall wyswietl(unsigned int a1, unsigned int a2, unsigned int a3)
{
return printf("\n Ruch gracza: %i\n Ruch komputera: %i\n Suma: %i\n", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, unsigned int a2, unsigned int a3)
{
return printf("\n Ruch gracza: %i\n Ruch komputera: %i\n Suma: %i\n", a1, a2, a3);
}

original_code:
void wyswietl(int czl, int kom, int suma){
  printf("\n Ruch gracza:   %i\n Ruch komputera:   %i\n Suma:   %i\n",czl,kom,suma);
}


sortuj

original_code:
void sortuj(int naupom[3][20/2], int kolej[3], int licznik){
  int i,j,x;
  for(i=0;i<3;i++){
    kolej[i]=i;
  }
  for(i=0;i<3;i++){
    for(j=i+1;j<3;j++){
      if(naupom[kolej[i]][licznik]<naupom[kolej[j]][licznik]){
 x=kolej[i];
 kolej[i]=kolej[j];
 kolej[j]=x;
      }
    }
  }
}

canonical_original_code:
void sortuj(int naupom[3][-1], int kolej[3], int licznik){
  int i; int j; int x;
  for(i=0;i<3;i++){
    kolej[i]=i;
  }
  for(i=0;i<3;i++){
    for(j=i+1;j<3;j++){
      if(naupom[kolej[i]][licznik]<naupom[kolej[j]][licznik]){
 x=kolej[i];
 kolej[i]=kolej[j];
 kolej[j]=x;
      }
    }
  }
}

variable_types:
naupom
int [3][-1]

variable_types:
kolej
int [3]

variable_types: i int

variable_types: j int

variable_types: x int


naukaCzesc

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

result = a1 + 40LL * a3 - 40;
*(_DWORD *)(result + 4LL * a2) = 1;
return result;
}

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

result = a1 + 40LL * a3 - 40;
*(_DWORD *)(result + 4LL * a2) = 1;
return result;
}

original_code:
void naukaCzesc(int pomnau[3][20/2], int licznik, int kom){
  pomnau[kom-1][licznik]=1;
}

canonical_original_code:
void naukaCzesc(int pomnau[3][-1], int licznik, int kom){
  pomnau[kom-1][licznik]=1;
}


ruchKom

decompiled_code:
__int64 __fastcall ruchKom(int a1, __int64 a2, __int64 a3, unsigned int a4)
{
__int64 v5; // rbx
unsigned int v6; // er12
int v7; // eax
bool v8; // dl
int v10; // [rsp+10h] [rbp-38h]
char v11[52]; // [rsp+14h] [rbp-34h] BYREF

v5 = 1LL;
sortuj(a3, (__int64)v11, a1);
do
{
v6 = *(&v10 + v5) + 1;
v7 = czyLegal(a4, v6);
v8 = (_DWORD)v5++ != 3;
}
while ( v7 != 0 && v8 );
naukaCzesc(a2, a1, v6);
return v6;
}

original_code:
int ruchKom(int licznik, int pomnau[3][20/2], int nau[3][20/2], int suma){
  int kolej[3];
  int i,r,kom;
  sortuj(nau,kolej,licznik);
  i=0;
  do{
    kom=kolej[i]+1;
    i++;
  }while(czyLegal(suma,kom) && i<3);
  naukaCzesc(pomnau,licznik,kom);
  return kom;
}

canonical_original_code:
int ruchKom(int licznik, int pomnau[3][-1], int nau[3][-1], int suma){
  int kolej[3];
  int i; int r; int kom;
  sortuj(nau,kolej,licznik);
  i=0;
  do{
    kom=kolej[i]+1;
    i++;
  }while(czyLegal(suma,kom) && i<3);
  naukaCzesc(pomnau,licznik,kom);
  return kom;
}

variable_types: r int


naukaCalosc

decompiled_code:
__int64 __fastcall naukaCalosc(__int64 a1, __int64 a2, char a3)
{
bool v3; // zf
__int64 v4; // rdx
__int64 result; // rax

v3 = a3 == 45;
v4 = 120LL;
if ( v3 )
{
do
{
result = v4 - 120;
do
{
*(_DWORD *)(a2 + result) -= *(_DWORD *)(a1 + result);
result += 40LL;
}
while ( v4 != result );
v4 += 4LL;
}
while ( v4 != 160 );
}
else
{
do
{
result = v4 - 120;
do
{
*(_DWORD *)(a2 + result) += *(_DWORD *)(a1 + result);
result += 40LL;
}
while ( result != v4 );
v4 += 4LL;
}
while ( v4 != 160 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, char a3)
{
bool v3; // zf
__int64 v4; // rdx
__int64 result; // rax

v3 = a3 == 45;
v4 = 120LL;
if ( v3 )
{
do
{
result = v4 - 120;
do
{
*(_DWORD *)(a2 + result) -= *(_DWORD *)(a1 + result);
result += 40LL;
}
while ( v4 != result );
v4 += 4LL;
}
while ( v4 != 160 );
}
else
{
do
{
result = v4 - 120;
do
{
*(_DWORD *)(a2 + result) += *(_DWORD *)(a1 + result);
result += 40LL;
}
while ( result != v4 );
v4 += 4LL;
}
while ( v4 != 160 );
}
return result;
}

variable_types: znak char


czyKoniec

decompiled_code:
_BOOL8 __fastcall czyKoniec(int a1)
{
return a1 <= 19;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(int a1)
{
return a1 <= 19;
}

original_code:
int czyKoniec(int suma){
  if(suma<20)return 1;
  else return 0;
}


czyLegal

decompiled_code:
_BOOL8 __fastcall czyLegal(int a1, int a2)
{
if ( a1 <= 17 )
return (unsigned int)(a2 - 1) > 2;
if ( a1 == 18 )
return (unsigned int)(a2 - 1) > 1;
if ( a1 == 19 )
return a2 != 1;
puts("\n BLAD! PRZERWIJ GRE");
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func14(int a1, int a2)
{
if ( a1 <= 17 )
return (unsigned int)(a2 - 1) > 2;
if ( a1 == 18 )
return (unsigned int)(a2 - 1) > 1;
if ( a1 == 19 )
return a2 != 1;
puts("\n BLAD! PRZERWIJ GRE");
return 0LL;
}

original_code:
int czyLegal(int suma, int ruch){
  if(suma<=(20 -3)){
    if(ruch==1 || ruch==2 || ruch==3)return 0;
    else return 1;
  }else if(suma==(20 -2)){
    if(ruch==1 || ruch==2)return 0;
    else return 1;
  }else if(suma==(20 -1)){
    if(ruch==1)return 0;
    else return 1;
  }else{
    printf("\n BLAD! PRZERWIJ GRE\n");
    return 0;
  }
}

variable_types: ruch int


ktoWygr

decompiled_code:
int __fastcall ktoWygr(char a1, __int64 a2, __int64 a3)
{
char v5; // dl

if ( a1 == 99 )
{
puts("\nWygrales... Gratuluje...");
v5 = 45;
}
else
{
if ( a1 != 107 )
return puts("\nBLAD");
puts("\nHURRA!!! WYGRALEM!!!");
v5 = 43;
}
return naukaCalosc(a2, a3, v5);
}

canonical_decompiled_code:
int __fastcall func15(char a1, __int64 a2, __int64 a3)
{
char v5; // dl

if ( a1 == 99 )
{
puts("\nWygrales... Gratuluje...");
v5 = 45;
}
else
{
if ( a1 != 107 )
return puts("\nBLAD");
puts("\nHURRA!!! WYGRALEM!!!");
v5 = 43;
}
return func12(a2, a3, v5);
}

original_code:
void ktoWygr(char ruch, int pomnau[3][20/2], int nau[3][20/2]){
  if(ruch=='c'){
    printf("\nWygrales... Gratuluje...\n");
    naukaCalosc(pomnau,nau,'-');
  }
  else if(ruch=='k'){
    printf("\nHURRA!!! WYGRALEM!!!\n");
    naukaCalosc(pomnau,nau,'+');
  }else printf("\nBLAD\n");
}

canonical_original_code:
void ktoWygr(char ruch, int pomnau[3][-1], int nau[3][-1]){
  if(ruch=='c'){
    printf("\nWygrales... Gratuluje...\n");
    naukaCalosc(pomnau,nau,'-');
  }
  else if(ruch=='k'){
    printf("\nHURRA!!! WYGRALEM!!!\n");
    naukaCalosc(pomnau,nau,'+');
  }else printf("\nBLAD\n");
}


ruchCzl

decompiled_code:
__int64 __fastcall ruchCzl(int a1)
{
unsigned int v2; // [rsp+Ch] [rbp-Ch]

while ( 1 )
{
printf("\n Podaj liczbe: ");
__isoc99_scanf();
getchar();
if ( !czyLegal(a1, v2) )
break;
puts("\n\n Nie rozumiem.");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1)
{
unsigned int v2; // [rsp+Ch] [rbp-Ch]

while ( 1 )
{
printf("\n Podaj liczbe: ");
__isoc99_scanf();
getchar();
if ( !func14(a1, v2) )
break;
puts("\n\n Nie rozumiem.");
}
return v2;
}

original_code:
int ruchCzl(int suma){
  int czl,i=0;
  do{
    if(i!=0)printf("\n\n Nie rozumiem.\n");
    printf("\n Podaj liczbe: ");
    scanf("%i",&czl);
    getchar();
    if(i==0)i=1;
  }while(czyLegal(suma,czl));
  return czl;
}

canonical_original_code:
int ruchCzl(int suma){
  int czl; int i = 0;
  do{
    if(i!=0)printf("\n\n Nie rozumiem.\n");
    printf("\n Podaj liczbe: ");
    scanf("%i",&czl);
    getchar();
    if(i==0)i=1;
  }while(czyLegal(suma,czl));
  return czl;
}


czyJeszcze

decompiled_code:
__int64 czyJeszcze()
{
__int64 result; // rax
unsigned int v1; // [rsp+Ch] [rbp-Ch]

while ( 1 )
{
puts("\n\n Czy chcesz grac dalej?");
puts(" 0 - nie");
puts(" 1 - tak");
printf(" Podaj cyfre: ");
__isoc99_scanf();
getchar();
result = v1;
if ( v1 <= 1 )
break;
printf("\n Nie rozumiem.");
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
__int64 result; // rax
unsigned int v1; // [rsp+Ch] [rbp-Ch]

while ( 1 )
{
puts("\n\n Czy chcesz grac dalej?");
puts(" 0 - nie");
puts(" 1 - tak");
printf(" Podaj cyfre: ");
__isoc99_scanf();
getchar();
result = v1;
if ( v1 <= 1 )
break;
printf("\n Nie rozumiem.");
}
return result;
}

original_code:
int czyJeszcze(){
  int w,i=0;
  do{
    if(i!=0)printf("\n Nie rozumiem.");
    printf("\n\n Czy chcesz grac dalej?\n");
    printf(" 0 - nie\n");
    printf(" 1 - tak\n");
    printf(" Podaj cyfre: ");
    scanf("%i",&w);
    getchar();
    if(i==0)i=1;
  }while(w!=1 && w!=0);
  return w;
}

canonical_original_code:
int czyJeszcze(){
  int w; int i = 0;
  do{
    if(i!=0)printf("\n Nie rozumiem.");
    printf("\n\n Czy chcesz grac dalej?\n");
    printf(" 0 - nie\n");
    printf(" 1 - tak\n");
    printf(" Podaj cyfre: ");
    scanf("%i",&w);
    getchar();
    if(i==0)i=1;
  }while(w!=1 && w!=0);
  return w;
}

variable_types: w int


main

repo: nkurz/loop-call-weirdness

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
int v4; // er8
char v5; // al

v4 = 1;
if ( argc > 1 )
{
v5 = *argv[1];
switch ( v5 )
{
case 't':
tightloop(argc, argv, envp, v3, 0LL);
break;
case 'c':
loop_with_extra_call(argc, argv, envp, v3, 0LL);
break;
case 'e':
loop_exchange(argc, argv, envp, v3, 0LL);
break;
case 'o':
loop_exchange_other(argc, argv, envp, v3, 0LL);
break;
case 'w':
loop_write(argc, argv, envp, v3, 0LL);
break;
case '2':
loop_mod_2(argc, argv, envp, v3, 0LL);
break;
case 'd':
loop_dummy_read(argc, argv, envp, v3, 0LL);
break;
case 's':
loop_dummy_read_self(argc, argv, envp, v3, 0LL);
break;
case 'p':
loop_dummy_prefetch(argc, argv, envp, v3, 0LL);
break;
case 'j':
loop_jump(argc, argv, envp, v3, 0LL);
break;
default:
v4 = 0;
if ( v5 == 118 )
loop_var(&counter, argv, envp, v3, 0LL);
break;
}
}
return v4;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rcx
int v4; // er8
char v5; // al

v4 = 1;
if ( argc > 1 )
{
v5 = *argv[1];
switch ( v5 )
{
case 't':
func6(argc, argv, envp, v3, 0LL);
break;
case 'c':
func8(argc, argv, envp, v3, 0LL);
break;
case 'e':
func9(argc, argv, envp, v3, 0LL);
break;
case 'o':
func10(argc, argv, envp, v3, 0LL);
break;
case 'w':
func17(argc, argv, envp, v3, 0LL);
break;
case '2':
func13(argc, argv, envp, v3, 0LL);
break;
case 'd':
func14(argc, argv, envp, v3, 0LL);
break;
case 's':
func15(argc, argv, envp, v3, 0LL);
break;
case 'p':
func16(argc, argv, envp, v3, 0LL);
break;
case 'j':
func18(argc, argv, envp, v3, 0LL);
break;
default:
v4 = 0;
if ( v5 == 118 )
func7(&counter, argv, envp, v3, 0LL);
break;
}
}
return v4;
}

original_code:
int main(int argc, char** argv) {
    if (argc <= 1) {
        return 1;
    }
    if (argv[1][0] == 't') {
        tightloop();
    } else if (argv[1][0] == 'c') {
        loop_with_extra_call();
    } else if (argv[1][0] == 'e') {
        loop_exchange();
    } else if (argv[1][0] == 'o') {
        loop_exchange_other();
    } else if (argv[1][0] == 'w') {
        loop_write();
    } else if (argv[1][0] == '2') {
        loop_mod_2();
    } else if (argv[1][0] == 'd') {
        loop_dummy_read();
    } else if (argv[1][0] == 's') {
        loop_dummy_read_self();
    } else if (argv[1][0] == 'p') {
        loop_dummy_prefetch();
    } else if (argv[1][0] == 'j') {
        loop_jump();
    } else if (argv[1][0] == 'v') {
        loop_var(&counter);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
    if (argc <= 1) {
        return 1;
    }
    if (argv[1][0] == 't') {
        tightloop();
    } else if (argv[1][0] == 'c') {
        loop_with_extra_call();
    } else if (argv[1][0] == 'e') {
        loop_exchange();
    } else if (argv[1][0] == 'o') {
        loop_exchange_other();
    } else if (argv[1][0] == 'w') {
        loop_write();
    } else if (argv[1][0] == '2') {
        loop_mod_2();
    } else if (argv[1][0] == 'd') {
        loop_dummy_read();
    } else if (argv[1][0] == 's') {
        loop_dummy_read_self();
    } else if (argv[1][0] == 'p') {
        loop_dummy_prefetch();
    } else if (argv[1][0] == 'j') {
        loop_jump();
    } else if (argv[1][0] == 'v') {
        loop_var(&counter);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **


tightloop

decompiled_code:
__int64 tightloop()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

original_code:
void tightloop() {
    ;
    unsigned j;
    for (j = 0; j < N; ++j) {
        counter += j;
    }
    ;
}

canonical_original_code:
void tightloop() {
    ;
    unsigned int j;
    for (j = 0; j < N; ++j) {
        counter += j;
    }
    ;
}

variable_types:
j
unsigned int


decompiled_code:
__int64 __fastcall loop_var(_QWORD *a1)
{
__int64 result; // rax
__int64 v2; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v2 = result + *a1;
*a1 = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
__int64 result; // rax
__int64 v2; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v2 = result + *a1;
*a1 = v2;
}
return result;
}

original_code:
void loop_var(volatile unsigned long long *counter_p) {
    ;
    unsigned j;
    for (j = 0; j < N; ++j) {
        *counter_p += j;
    }
    ;
}

canonical_original_code:
void loop_var(unsigned long long *counter_p) {
    ;
    unsigned int j;
    for (j = 0; j < N; ++j) {
        *counter_p += j;
    }
    ;
}


decompiled_code:
__int64 loop_with_extra_call()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax

do
{
v0 = foo();
v1 = v0 + counter;
result = v0 + 1;
counter = v1;
}
while ( result != 400000000 );
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 v0; // rax
__int64 v1; // rdx
__int64 result; // rax

do
{
v0 = func11();
v1 = v0 + counter;
result = v0 + 1;
counter = v1;
}
while ( result != 400000000 );
return result;
}

original_code:
void loop_with_extra_call() {
    ;
    unsigned j;
    for (j = 0; j < N; ++j) {
        __asm__("call foo");
        counter += j;
    }
    ;
}

canonical_original_code:
void loop_with_extra_call() {
    ;
    unsigned int j;
    for (j = 0; j < N; ++j) {
        __asm__("call foo");
        counter += j;
    }
    ;
}


decompiled_code:
__int64 loop_exchange()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

original_code:
void loop_exchange() {
    ;
    unsigned j;
    for (j = 0; j < N; ++j) {
        __asm__("xchg %rdx, %rdx");
        counter += j;
    }
    ;
}

canonical_original_code:
void loop_exchange() {
    ;
    unsigned int j;
    for (j = 0; j < N; ++j) {
        __asm__("xchg %rdx, %rdx");
        counter += j;
    }
    ;
}


decompiled_code:
__int64 loop_exchange_other()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

original_code:
void loop_exchange_other() {
    ;
    unsigned j;
    for (j = 0; j < N; ++j) {
        __asm__("xchg %rcx, %rcx");
        counter += j;
    }
    ;
}

canonical_original_code:
void loop_exchange_other() {
    ;
    unsigned int j;
    for (j = 0; j < N; ++j) {
        __asm__("xchg %rcx, %rcx");
        counter += j;
    }
    ;
}


foo

decompiled_code:
void foo()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void foo() {
}

canonical_original_code:
void foo() {
}


decompiled_code:
void foo_full()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void foo_full() {
    __asm__("movaps %xmm0, %xmm0");
    __asm__("movaps %xmm0, %xmm0");
    __asm__("movaps %xmm0, %xmm0");
    __asm__("movaps %xmm0, %xmm0");
}


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

for ( result = 0LL; ; ++result )
{
counter += result;
if ( result == 399999999 )
break;
if ( (((_BYTE)result + 1) & 1) != 0 )
foo();
}
return result;
}

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

for ( result = 0LL; ; ++result )
{
counter += result;
if ( result == 399999999 )
break;
if ( (((_BYTE)result + 1) & 1) != 0 )
func11();
}
return result;
}

original_code:
void loop_mod_2() {
    ;
    unsigned j;
    for (j = 0; j < N; ++j) {
        if (j % 2) __asm__("call foo");
        counter += j;
    }
    ;
}

canonical_original_code:
void loop_mod_2() {
    ;
    unsigned int j;
    for (j = 0; j < N; ++j) {
        if (j % 2) __asm__("call foo");
        counter += j;
    }
    ;
}


decompiled_code:
__int64 loop_dummy_read()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

original_code:
void loop_dummy_read() {
    ;
    unsigned j;
    unsigned dummy_read;
    for (j = 0; j < N; ++j) {
        dummy_read = dummy;
        counter += j;
    }
    ;
}

canonical_original_code:
void loop_dummy_read() {
    ;
    unsigned int j;
    unsigned int dummy_read;
    for (j = 0; j < N; ++j) {
        dummy_read = dummy;
        counter += j;
    }
    ;
}


decompiled_code:
__int64 loop_dummy_read_self()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
v1 = result + counter;
counter = v1;
}
return result;
}

original_code:
void loop_dummy_read_self() {
    ;
    unsigned j;
    unsigned dummy_read;
    for (j = 0; j < N; ++j) {
        dummy_read = counter;
        counter += j;
    }
    ;
}

canonical_original_code:
void loop_dummy_read_self() {
    ;
    unsigned int j;
    unsigned int dummy_read;
    for (j = 0; j < N; ++j) {
        dummy_read = counter;
        counter += j;
    }
    ;
}


decompiled_code:
__int64 loop_dummy_prefetch()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
__asm { prefetcht0 byte ptr cs:counter }
v1 = result + counter;
counter = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func16()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
__asm { prefetcht0 byte ptr cs:counter }
v1 = result + counter;
counter = v1;
}
return result;
}

original_code:
void loop_dummy_prefetch() {
    ;
    unsigned j;
    for (j = 0; j < N; ++j) {
        __builtin_prefetch((void *)&counter);
        counter += j;
    }
    ;
}

canonical_original_code:
void loop_dummy_prefetch() {
    ;
    unsigned int j;
    for (j = 0; j < N; ++j) {
        __builtin_prefetch((void *)&counter);
        counter += j;
    }
    ;
}


decompiled_code:
__int64 loop_write()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
dummy = result;
v1 = result + counter;
counter = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func17()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
dummy = result;
v1 = result + counter;
counter = v1;
}
return result;
}

original_code:
void loop_write() {
    ;
    unsigned j;
    for (j = 0; j < N; ++j) {
        dummy = j;
        counter += j;
    }
    ;
}

canonical_original_code:
void loop_write() {
    ;
    unsigned int j;
    for (j = 0; j < N; ++j) {
        dummy = j;
        counter += j;
    }
    ;
}


decompiled_code:
__int64 loop_jump()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
if ( (result & 1) == 0 )
foo();
v1 = result + counter;
counter = v1;
}
return result;
}

canonical_decompiled_code:
__int64 func18()
{
__int64 result; // rax
__int64 v1; // rdx

for ( result = 0LL; result != 400000000; ++result )
{
if ( (result & 1) == 0 )
func11();
v1 = result + counter;
counter = v1;
}
return result;
}

original_code:
void loop_jump() {
    ;
    unsigned j;
    for (j = 0; j < N; ++j) {
        __asm__("test $1, %al");
        __asm__("jnz 1f");
        __asm__("call foo");
        __asm__("1:");
        counter += j;
    }
    ;
}

canonical_original_code:
void loop_jump() {
    ;
    unsigned int j;
    for (j = 0; j < N; ++j) {
        __asm__("test $1, %al");
        __asm__("jnz 1f");
        __asm__("call foo");
        __asm__("1:");
        counter += j;
    }
    ;
}


repo: nlasso/pancetaYHuevoFrito

decompiled_code:
int __fastcall check_idx(char *filename, int a2)
{
char *v2; // rbp
char *v4; // rax
char v5; // dl
char *v6; // rsi
char *v7; // rdx
__int64 v8; // rax
__int64 v9; // rcx
bool v10; // di
int v11; // er12
__int64 v12; // rax
FILE *v13; // rax

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

canonical_decompiled_code:
int __fastcall func0(char *filename, int a2)
{
char *v2; // rbp
char *v4; // rax
char v5; // dl
char *v6; // rsi
char *v7; // rdx
__int64 v8; // rax
__int64 v9; // rcx
bool v10; // di
int v11; // er12
__int64 v12; // rax
FILE *v13; // rax

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

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
__int64 v1; // rbp
const unsigned __int16 *v2; // rax
int v3; // eax
char v4; // bl
__int64 v5; // rbp
const unsigned __int16 **v6; // r13
FILE *v7; // rdi
__int64 v8; // r12
__int64 v9; // rdx

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(v2) = fprintf(ilg_fp, "Couldn't find any page number in %s...ignored\n", log_fn);
init_page = 0;
return (int)v2;
}
goto LABEL_7;
}
}
do
{
LABEL_7:
v3 = getc(log_fp);
v4 = v3;
}
while ( v3 == 32 );
v5 = 1LL;
v6 = _ctype_b_loc();
do
{
v7 = log_fp;
*(&pageno + v5 - 1) = v4;
v8 = (int)v5++;
v9 = getc(v7);
v2 = *v6;
v4 = v9;
}
while ( ((*v6)[v9] & 0x800) != 0 );
*(&pageno + v8) = 0;
return (int)v2;
}

canonical_decompiled_code:
int func1()
{
int v0; // ebx
__int64 v1; // rbp
const unsigned __int16 *v2; // rax
int v3; // eax
char v4; // bl
__int64 v5; // rbp
const unsigned __int16 **v6; // r13
FILE *v7; // rdi
__int64 v8; // r12
__int64 v9; // rdx

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(v2) = fprintf(ilg_fp, "Couldn't find any page number in %s...ignored\n", log_fn);
init_page = 0;
return (int)v2;
}
goto LABEL_7;
}
}
do
{
LABEL_7:
v3 = getc(log_fp);
v4 = v3;
}
while ( v3 == 32 );
v5 = 1LL;
v6 = _ctype_b_loc();
do
{
v7 = log_fp;
*(&pageno + v5 - 1) = v4;
v8 = (int)v5++;
v9 = getc(v7);
v2 = *v6;
v4 = v9;
}
while ( ((*v6)[v9] & 0x800) != 0 );
*(&pageno + v8) = 0;
return (int)v2;
}

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

variable_types: c int


decompiled_code:
int __fastcall check_all(char *a1, int a2, int a3, int a4)
{
FILE *v6; // rax
FILE *v7; // rax
char *v8; // rdx
const char *v9; // rsi

check_idx(a1, 1);
if ( !a2 )
{
sprintf(ind, "%s%s", base, ".ind");
ind_fn = ind;
}
ind_fp = fopen(ind_fn, "w");
if ( !ind_fp )
{
v8 = ind_fn;
v9 = "Can't create output index file %s.\n";
LABEL_11:
fprintf(stderr, v9, v8);
goto LABEL_12;
}
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);
LABEL_12:
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");
v7 = fopen(log_fn, "r");
v8 = log_fn;
v9 = "Source log file %s not found.\n";
log_fp = v7;
if ( v7 )
{
find_pageno();
LODWORD(v6) = fclose(log_fp);
return (int)v6;
}
goto LABEL_11;
}
return (int)v6;
}

canonical_decompiled_code:
int __fastcall func2(char *a1, int a2, int a3, int a4)
{
FILE *v6; // rax
FILE *v7; // rax
char *v8; // rdx
const char *v9; // rsi

func0(a1, 1);
if ( !a2 )
{
sprintf(ind, "%s%s", base, ".ind");
ind_fn = ind;
}
ind_fp = fopen(ind_fn, "w");
if ( !ind_fp )
{
v8 = ind_fn;
v9 = "Can't create output index file %s.\n";
LABEL_11:
fprintf(stderr, v9, v8);
goto LABEL_12;
}
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);
LABEL_12:
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");
v7 = fopen(log_fn, "r");
v8 = log_fn;
v9 = "Source log file %s not found.\n";
log_fp = v7;
if ( v7 )
{
func1();
LODWORD(v6) = fclose(log_fp);
return (int)v6;
}
goto LABEL_11;
}
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, unsigned int a4, int a5, int a6)
{
const char *v7; // rsi
__int64 result; // rax
char *v10; // rbp
__int64 v11; // rbx
FILE *v12; // rax
int v13; // [rsp+Ch] [rbp-2Ch]

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

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, int a2, int a3, unsigned int a4, int a5, int a6)
{
const char *v7; // rsi
__int64 result; // rax
char *v10; // rbp
__int64 v11; // rbx
FILE *v12; // rax
int v13; // [rsp+Ch] [rbp-2Ch]

v7 = (const char *)a4;
if ( fn_no == -1 )
{
idx_fn = "stdin";
idx_fp = (__int64)stdin;
if ( !a4 )
{
ind_fn = "stdout";
ind_fp = stdout;
goto LABEL_4;
}
if ( ind_fp || (a1 = ind_fn, v7 = "w", v13 = a5, v12 = fopen(ind_fn, "w"), a5 = v13, (ind_fp = v12) != 0LL) )
{
LABEL_4:
if ( !a5 )
{
ilg_fn = "stderr";
ilg_fp = stderr;
LABEL_6:
if ( fn_no == -1 && a3 )
scan_sty(a1, v7);
if ( !german_sort || idx_quote != 34 )
{
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]");
a1 = (char *)ilg_fp;
v7 = "%s.\n";
fprintf(ilg_fp, "%s.\n", "portable version 2.12 [26-May-1993]");
need_version = 0;
}
result = scan_idx(a1, v7);
++fn_no;
return result;
}
fprintf(stderr, "Option -g ignored, quote character must be different from '%c'.\n", 34LL);
LABEL_34:
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
LABEL_31:
if ( !ilg_fp )
{
a1 = ilg_fn;
v7 = "w";
ilg_fp = fopen(ilg_fn, "w");
if ( !ilg_fp )
{
fprintf(stderr, "Can't create transcript file %s.\n", ilg_fn);
goto LABEL_34;
}
}
goto LABEL_6;
}
LABEL_37:
fprintf(stderr, "Can't create output index file %s.\n", ind_fn);
goto LABEL_34;
}
v10 = a1;
func2(*(char **)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]");
a1 = (char *)ilg_fp;
v7 = "%s.\n";
fprintf(ilg_fp, "%s.\n", "portable version 2.12 [26-May-1993]");
need_version = 0;
if ( a3 )
((void (*)(void))scan_sty)();
if ( german_sort && idx_quote == 34 )
{
fprintf(stderr, "Option -g invalid, quote character must be different from '%c'.\n", 34LL);
goto LABEL_34;
}
result = ((__int64 (*)(void))scan_idx)();
v11 = 1LL;
if ( fn_no > 0 )
{
do
{
a1 = *(char **)&v10[8 * v11];
v7 = (_BYTE *)(check_idx + 1);
++v11;
func0(a1, 1);
result = ((__int64 (*)(void))scan_idx)();
}
while ( fn_no >= (int)v11 );
}
if ( a2 )
{
idx_fn = "stdin";
idx_fp = (__int64)stdin;
if ( ind_fp )
goto LABEL_31;
a1 = ind_fn;
v7 = "w";
ind_fp = fopen(ind_fn, "w");
if ( ind_fp )
goto LABEL_31;
goto LABEL_37;
}
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 *[]


strtoint

decompiled_code:
__int64 __fastcall strtoint(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 0; *a1; v1 = (char)*a1 )
{
++a1;
i = v1 + 10 * i - 48;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func5(_BYTE *a1)
{
int v1; // eax
unsigned int i; // er8

v1 = (char)*a1;
for ( i = 0; *a1; v1 = (char)*a1 )
{
++a1;
i = v1 + 10 * i - 48;
}
return i;
}

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


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // r14
const char *v4; // rdx
int v5; // er15
int v6; // er12
__int64 v7; // rsi
char *v8; // rdi
const char **v9; // rbp
char *v10; // r13
char i; // si
char *v12; // rax
char *v13; // rdi
char *v14; // rax
int v15; // ebx
int v16; // eax
unsigned int v18; // [rsp+0h] [rbp-2158h]
int v19; // [rsp+4h] [rbp-2154h]
int v20; // [rsp+8h] [rbp-2150h]
int v21; // [rsp+Ch] [rbp-214Ch]
char s[272]; // [rsp+10h] [rbp-2148h] BYREF
__int64 v23[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;
v5 = argc - 1;
pgm_fn = (__int64)v4;
v6 = 0;
v20 = 0;
v19 = 0;
v18 = 0;
v21 = 0;
if ( argc - 1 > 0 )
{
do
{
v8 = (char *)v3[1];
v9 = v3 + 1;
if ( *v8 == 45 )
{
if ( !v8[1] )
break;
v10 = v8 + 1;
v3[1] = v8 + 1;
for ( i = v8[1]; i; i = *++v10 )
{
switch ( i )
{
case 'c':
compress_blanks = 1;
continue;
case 'g':
german_sort = 1;
continue;
case 'i':
v21 = 1;
continue;
case 'l':
letter_ordering = 1;
continue;
case 'o':
if ( !--v5 )
{
fprintf(stderr, "Expected -o <ind>\n");
LABEL_13:
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
v14 = (char *)v9[1];
v18 = 1;
++v9;
ind_fn = v14;
break;
case 'p':
if ( !--v5 )
{
fprintf(stderr, "Expected -p <num>\n");
goto LABEL_13;
}
strcpy(&pageno, v9[1]);
init_page = 1;
if ( !strcmp(&pageno, "even") )
{
even_odd = 2;
++v9;
v20 = 1;
}
else if ( !strcmp(&pageno, "odd") )
{
even_odd = 1;
++v9;
v20 = 1;
}
else
{
++v9;
if ( !strcmp(&pageno, "any") )
{
even_odd = 0;
v20 = 1;
}
}
break;
case 'q':
verbose = 0;
continue;
case 'r':
merge_page = 0;
continue;
case 's':
if ( !--v5 )
{
fprintf(stderr, "Expected -s <stylefile>\n");
goto LABEL_13;
}
v13 = (char *)v9[1];
++v9;
v6 = 1;
open_sty(v13);
continue;
case 't':
if ( !--v5 )
{
fprintf(stderr, "Expected -t <logfile>\n");
goto LABEL_13;
}
v12 = (char *)v9[1];
v19 = 1;
++v9;
ilg_fn = v12;
continue;
default:
fprintf(stderr, "Unknown option -%c.\n", (unsigned int)i);
goto LABEL_13;
}
}
v3 = v9;
}
else
{
if ( fn_no > 1023 )
{
fprintf(stderr, "Too many input files (max %d).\n", 1024LL);
goto LABEL_13;
}
check_idx(v8, 0);
v7 = (__int64)v3[1];
++v3;
v23[++fn_no] = v7;
}
--v5;
}
while ( v5 );
}
v15 = fn_no | v6;
if ( !(fn_no | v6) )
{
sprintf(s, "%s%s", base, ".mst");
if ( !access(s, 4) )
{
v15 = 1;
open_sty(s);
}
v6 = v15;
}
process_idx((char *)v23, v21, v6, v18, v19, v20);
v16 = fn_no;
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);
v16 = fn_no;
}
fprintf(
ilg_fp,
"Overall %d files read (%d entries accepted, %d rejected).\n",
(unsigned int)(v16 + 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; // r14
const char *v4; // rdx
int v5; // er15
int v6; // er12
__int64 v7; // rsi
char *v8; // rdi
const char **v9; // rbp
char *v10; // r13
char i; // si
char *v12; // rax
char *v13; // rdi
char *v14; // rax
int v15; // ebx
int v16; // eax
unsigned int v18; // [rsp+0h] [rbp-2158h]
int v19; // [rsp+4h] [rbp-2154h]
int v20; // [rsp+8h] [rbp-2150h]
int v21; // [rsp+Ch] [rbp-214Ch]
char s[272]; // [rsp+10h] [rbp-2148h] BYREF
__int64 v23[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;
v5 = argc - 1;
pgm_fn = (__int64)v4;
v6 = 0;
v20 = 0;
v19 = 0;
v18 = 0;
v21 = 0;
if ( argc - 1 > 0 )
{
do
{
v8 = (char *)v3[1];
v9 = v3 + 1;
if ( *v8 == 45 )
{
if ( !v8[1] )
break;
v10 = v8 + 1;
v3[1] = v8 + 1;
for ( i = v8[1]; i; i = *++v10 )
{
switch ( i )
{
case 'c':
compress_blanks = 1;
continue;
case 'g':
german_sort = 1;
continue;
case 'i':
v21 = 1;
continue;
case 'l':
letter_ordering = 1;
continue;
case 'o':
if ( !--v5 )
{
fprintf(stderr, "Expected -o <ind>\n");
LABEL_13:
fprintf(
stderr,
"Usage: %s [-ilqrcg] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]\n",
(const char *)pgm_fn);
exit(1);
}
v14 = (char *)v9[1];
v18 = 1;
++v9;
ind_fn = v14;
break;
case 'p':
if ( !--v5 )
{
fprintf(stderr, "Expected -p <num>\n");
goto LABEL_13;
}
strcpy(&pageno, v9[1]);
init_page = 1;
if ( !strcmp(&pageno, "even") )
{
even_odd = 2;
++v9;
v20 = 1;
}
else if ( !strcmp(&pageno, "odd") )
{
even_odd = 1;
++v9;
v20 = 1;
}
else
{
++v9;
if ( !strcmp(&pageno, "any") )
{
even_odd = 0;
v20 = 1;
}
}
break;
case 'q':
verbose = 0;
continue;
case 'r':
merge_page = 0;
continue;
case 's':
if ( !--v5 )
{
fprintf(stderr, "Expected -s <stylefile>\n");
goto LABEL_13;
}
v13 = (char *)v9[1];
++v9;
v6 = 1;
open_sty(v13);
continue;
case 't':
if ( !--v5 )
{
fprintf(stderr, "Expected -t <logfile>\n");
goto LABEL_13;
}
v12 = (char *)v9[1];
v19 = 1;
++v9;
ilg_fn = v12;
continue;
default:
fprintf(stderr, "Unknown option -%c.\n", (unsigned int)i);
goto LABEL_13;
}
}
v3 = v9;
}
else
{
if ( fn_no > 1023 )
{
fprintf(stderr, "Too many input files (max %d).\n", 1024LL);
goto LABEL_13;
}
func0(v8, 0);
v7 = (__int64)v3[1];
++v3;
v23[++fn_no] = v7;
}
--v5;
}
while ( v5 );
}
v15 = fn_no | v6;
if ( !(fn_no | v6) )
{
sprintf(s, "%s%s", base, ".mst");
if ( !access(s, 4) )
{
v15 = 1;
open_sty(s);
}
v6 = v15;
}
func3((char *)v23, v21, v6, v18, v19, v20);
v16 = fn_no;
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);
v16 = fn_no;
}
fprintf(
ilg_fp,
"Overall %d files read (%d entries accepted, %d rejected).\n",
(unsigned int)(v16 + 1),
(unsigned int)idx_gt,
(unsigned int)idx_et);
}
if ( idx_gt > 0 )
{
func4();
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:
argv
char *[]

variable_types:
fns
char *[1024]

variable_types:
ap
char *

variable_types:
tmp
char [-1]


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: i 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; // er8

v2 = *a2 - 48;
if ( (unsigned __int8)(*a1 - 48) > 9u )
{
if ( v2 > 9u )
return strcmp(a1, a2);
}
else
{
v3 = 1;
if ( v2 > 9u )
return v3;
}
if ( (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; // er8

v2 = *a2 - 48;
if ( (unsigned __int8)(*a1 - 48) > 9u )
{
if ( v2 > 9u )
return strcmp(a1, a2);
}
else
{
v3 = 1;
if ( v2 > 9u )
return v3;
}
if ( (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:
int __fastcall compare_string(char *s1, char *s2)
{
char v3; // al
int v4; // er14
int v5; // ebp
int v6; // ebx
const unsigned __int16 **v7; // rax
const unsigned __int16 *v8; // rcx
__int64 v9; // rsi
int v10; // er15
const __int32_t **v11; // rax
int result; // eax
int v13; // [rsp+14h] [rbp-44h]
const unsigned __int16 *v14; // [rsp+18h] [rbp-40h]

v3 = *s1;
if ( *s1 )
{
v4 = 0;
v5 = 0;
v13 = letter_ordering;
do
{
v6 = (unsigned __int8)s2[v5];
if ( !(_BYTE)v6 )
return 1;
if ( v13 )
{
v4 += v3 == 32;
if ( (_BYTE)v6 == 32 )
v6 = (unsigned __int8)s2[++v5];
}
v7 = _ctype_b_loc();
v8 = *v7;
v9 = (unsigned __int8)s1[v4];
v10 = (unsigned __int8)v9;
if ( ((*v7)[v9] & 0x100) != 0 )
{
v14 = *v7;
v11 = _ctype_tolower_loc();
v8 = v14;
v10 = LOBYTE((*v11)[v9]);
}
if ( (v8[(unsigned __int8)v6] & 0x100) != 0 )
v6 = LOBYTE((*_ctype_tolower_loc())[(unsigned __int8)v6]);
if ( v10 != v6 )
return v10 - v6;
++v4;
++v5;
v3 = s1[v4];
}
while ( v3 );
result = -1;
if ( !s2[v5] )
goto LABEL_16;
}
else
{
result = -1;
if ( !*s2 )
{
LABEL_16:
if ( german_sort )
result = new_strcmp_constprop_0((__int64)s1, (__int64)s2);
else
result = strcmp(s1, s2);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(char *s1, char *s2)
{
char v3; // al
int v4; // er14
int v5; // ebp
int v6; // ebx
const unsigned __int16 **v7; // rax
const unsigned __int16 *v8; // rcx
__int64 v9; // rsi
int v10; // er15
const __int32_t **v11; // rax
int result; // eax
int v13; // [rsp+14h] [rbp-44h]
const unsigned __int16 *v14; // [rsp+18h] [rbp-40h]

v3 = *s1;
if ( *s1 )
{
v4 = 0;
v5 = 0;
v13 = letter_ordering;
do
{
v6 = (unsigned __int8)s2[v5];
if ( !(_BYTE)v6 )
return 1;
if ( v13 )
{
v4 += v3 == 32;
if ( (_BYTE)v6 == 32 )
v6 = (unsigned __int8)s2[++v5];
}
v7 = _ctype_b_loc();
v8 = *v7;
v9 = (unsigned __int8)s1[v4];
v10 = (unsigned __int8)v9;
if ( ((*v7)[v9] & 0x100) != 0 )
{
v14 = *v7;
v11 = _ctype_tolower_loc();
v8 = v14;
v10 = LOBYTE((*v11)[v9]);
}
if ( (v8[(unsigned __int8)v6] & 0x100) != 0 )
v6 = LOBYTE((*_ctype_tolower_loc())[(unsigned __int8)v6]);
if ( v10 != v6 )
return v10 - v6;
++v4;
++v5;
v3 = s1[v4];
}
while ( v3 );
result = -1;
if ( !s2[v5] )
goto LABEL_16;
}
else
{
result = -1;
if ( !*s2 )
{
LABEL_16:
if ( german_sort )
result = func1((__int64)s1, (__int64)s2);
else
result = strcmp(s1, s2);
}
}
return result;
}

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

variable_types: bl int


decompiled_code:
int __fastcall compare_one(char *s1, char *s2)
{
char v2; // al
int v3; // er12
int v5; // eax

v2 = *s2;
if ( !*s1 )
return -(v2 != 0);
if ( !v2 )
return 1;
v3 = ((__int64 (*)(void))group_type)();
v5 = group_type(s2);
if ( v3 >= 0 )
{
if ( v5 >= 0 )
return v3 - v5;
if ( !german_sort )
{
v3 = -1;
if ( v5 != -1 )
return v3;
}
return 1;
}
if ( v5 >= 0 )
{
if ( german_sort || v3 == -1 )
return -1;
return 1;
}
if ( (v5 & v3) == -1 )
return check_mixsym(s1, s2);
if ( v3 == -1 )
return v3;
if ( v5 == -1 )
return 1;
return compare_string(s1, s2);
}

canonical_decompiled_code:
int __fastcall func3(char *s1, char *s2)
{
char v2; // al
int v3; // er12
int v5; // eax

v2 = *s2;
if ( !*s1 )
return -(v2 != 0);
if ( !v2 )
return 1;
v3 = ((__int64 (*)(void))group_type)();
v5 = group_type(s2);
if ( v3 >= 0 )
{
if ( v5 >= 0 )
return v3 - v5;
if ( !german_sort )
{
v3 = -1;
if ( v5 != -1 )
return v3;
}
return 1;
}
if ( v5 >= 0 )
{
if ( german_sort || v3 == -1 )
return -1;
return 1;
}
if ( (v5 & v3) == -1 )
return func0(s1, s2);
if ( v3 == -1 )
return v3;
if ( v5 == -1 )
return 1;
return func2(s1, s2);
}

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)(a4 - a1) * (double)(a4 - a1)
+ (double)(a5 - a2) * (double)(a5 - a2)
+ (double)(a6 - a3) * (double)(a6 - a3);
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)(a4 - a1) * (double)(a4 - a1)
+ (double)(a5 - a2) * (double)(a5 - a2)
+ (double)(a6 - a3) * (double)(a6 - a3);
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; // r13
unsigned __int8 *v3; // r12
int v4; // ebx
int v5; // esi
__int64 v6; // rdx
unsigned __int8 *v7; // r14
__int64 v8; // rdx
unsigned __int8 *v9; // rbx
unsigned __int8 *v10; // rbp
unsigned __int8 *v11; // r15
unsigned __int8 *v12; // rbx
bool v13; // cc
__int64 v14; // rax
unsigned __int8 *v15; // rdi
__int64 v16; // rcx
unsigned __int8 v17; // al
unsigned __int8 *v18; // r14
__int64 result; // rax
int (__fastcall *v20)(unsigned __int8 *, unsigned __int8 *); // rax
__int64 v21; // rdi
unsigned __int8 *v22; // rax
unsigned __int8 v23; // cl
unsigned __int8 *v24; // rdi
unsigned __int8 *v25; // rsi

v2 = a2;
v3 = a1;
v4 = (_DWORD)a2 - (_DWORD)a1;
do
{
v5 = qsz;
v6 = (unsigned int)(v4 >> 31);
LODWORD(v6) = v4 % qsz;
v7 = &v3[qsz * ((unsigned int)(v4 / qsz) >> 1)];
if ( mthresh > v4 )
goto LABEL_8;
if ( (int)qcmp(v3, &v3[qsz * ((unsigned int)(v4 / qsz) >> 1)], v6) <= 0 )
{
v9 = &v2[-qsz];
if ( (int)qcmp(v7, v9, v8) <= 0 )
goto LABEL_7;
v20 = (int (__fastcall *)(unsigned __int8 *, unsigned __int8 *))qcmp;
if ( v3 == v7 )
goto LABEL_44;
if ( (int)qcmp(v3, v9, v6) >= 0 )
{
v9 = v3;
goto LABEL_38;
}
}
else
{
v9 = &v2[-qsz];
if ( (int)qcmp(v3, v9, v8) > 0 )
{
v20 = (int (__fastcall *)(unsigned __int8 *, unsigned __int8 *))qcmp;
LABEL_44:
if ( v20(v7, v9) >= 0 )
{
LABEL_7:
v5 = qsz;
goto LABEL_8;
}
goto LABEL_6;
}
v9 = v3;
}
LABEL_6:
if ( v9 == v7 )
goto LABEL_7;
LABEL_38:
v5 = qsz;
v21 = (__int64)&v7[qsz - 1 + 1];
v22 = v7;
do
{
v6 = *v22;
v23 = *v9;
++v22;
++v9;
*(v22 - 1) = v23;
*(v9 - 1) = v6;
}
while ( v22 != (unsigned __int8 *)v21 );
LABEL_8:
v10 = v3;
v11 = &v2[-v5];
if ( v3 < v7 )
{
while ( (int)qcmp(v10, v7, v6) <= 0 )
{
v5 = qsz;
v10 += qsz;
LABEL_18:
if ( v10 >= v7 )
goto LABEL_9;
}
if ( v11 <= v7 )
{
v14 = qsz;
v12 = v11;
v5 = qsz;
goto LABEL_14;
}
}
else
{
LABEL_9:
if ( v11 <= v7 )
{
v14 = v5;
v12 = v11;
if ( v10 == v7 )
goto LABEL_27;
LABEL_14:
v15 = v10;
v11 = &v12[-v14];
v12 = v7;
v7 = v10;
LABEL_15:
v16 = (__int64)&v10[v5 - 1 + 1];
do
{
v17 = *v10;
v6 = *v12;
++v10;
++v12;
*(v10 - 1) = v6;
*(v12 - 1) = v17;
}
while ( v10 != (unsigned __int8 *)v16 );
v10 = v15;
goto LABEL_18;
}
}
v12 = v11;
do
{
v13 = (int)qcmp(v7, v12, v6) <= 0;
v14 = qsz;
v5 = qsz;
if ( !v13 )
{
v15 = &v10[qsz];
if ( v10 == v7 )
{
v7 = v12;
v11 = v12;
}
else
{
v11 = &v12[-qsz];
}
goto LABEL_15;
}
v12 -= qsz;
}
while ( v7 < v12 );
if ( v10 != v7 )
goto LABEL_14;
LABEL_27:
v18 = &v10[v14];
result = (unsigned int)thresh;
v4 = (_DWORD)v2 - (_DWORD)v18;
if ( (int)v10 - (int)v3 > (int)v2 - (int)v18 )
{
if ( (int)v2 - (int)v18 >= thresh )
{
v25 = v2;
v4 = (_DWORD)v10 - (_DWORD)v3;
v2 = v10;
qst(v18, v25);
result = (unsigned int)thresh;
}
else
{
v4 = (_DWORD)v10 - (_DWORD)v3;
v2 = v10;
}
}
else if ( (int)v10 - (int)v3 >= thresh )
{
v24 = v3;
v3 = v18;
qst(v24, v10);
result = (unsigned int)thresh;
}
else
{
v3 = v18;
}
}
while ( v4 >= (int)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // r13
unsigned __int8 *v3; // r12
int v4; // ebx
int v5; // esi
__int64 v6; // rdx
unsigned __int8 *v7; // r14
__int64 v8; // rdx
unsigned __int8 *v9; // rbx
unsigned __int8 *v10; // rbp
unsigned __int8 *v11; // r15
unsigned __int8 *v12; // rbx
bool v13; // cc
__int64 v14; // rax
unsigned __int8 *v15; // rdi
__int64 v16; // rcx
unsigned __int8 v17; // al
unsigned __int8 *v18; // r14
__int64 result; // rax
int (__fastcall *v20)(unsigned __int8 *, unsigned __int8 *); // rax
__int64 v21; // rdi
unsigned __int8 *v22; // rax
unsigned __int8 v23; // cl
unsigned __int8 *v24; // rdi
unsigned __int8 *v25; // rsi

v2 = a2;
v3 = a1;
v4 = (_DWORD)a2 - (_DWORD)a1;
do
{
v5 = qsz;
v6 = (unsigned int)(v4 >> 31);
LODWORD(v6) = v4 % qsz;
v7 = &v3[qsz * ((unsigned int)(v4 / qsz) >> 1)];
if ( mthresh > v4 )
goto LABEL_8;
if ( (int)qcmp(v3, &v3[qsz * ((unsigned int)(v4 / qsz) >> 1)], v6) <= 0 )
{
v9 = &v2[-qsz];
if ( (int)qcmp(v7, v9, v8) <= 0 )
goto LABEL_7;
v20 = (int (__fastcall *)(unsigned __int8 *, unsigned __int8 *))qcmp;
if ( v3 == v7 )
goto LABEL_44;
if ( (int)qcmp(v3, v9, v6) >= 0 )
{
v9 = v3;
goto LABEL_38;
}
}
else
{
v9 = &v2[-qsz];
if ( (int)qcmp(v3, v9, v8) > 0 )
{
v20 = (int (__fastcall *)(unsigned __int8 *, unsigned __int8 *))qcmp;
LABEL_44:
if ( v20(v7, v9) >= 0 )
{
LABEL_7:
v5 = qsz;
goto LABEL_8;
}
goto LABEL_6;
}
v9 = v3;
}
LABEL_6:
if ( v9 == v7 )
goto LABEL_7;
LABEL_38:
v5 = qsz;
v21 = (__int64)&v7[qsz - 1 + 1];
v22 = v7;
do
{
v6 = *v22;
v23 = *v9;
++v22;
++v9;
*(v22 - 1) = v23;
*(v9 - 1) = v6;
}
while ( v22 != (unsigned __int8 *)v21 );
LABEL_8:
v10 = v3;
v11 = &v2[-v5];
if ( v3 < v7 )
{
while ( (int)qcmp(v10, v7, v6) <= 0 )
{
v5 = qsz;
v10 += qsz;
LABEL_18:
if ( v10 >= v7 )
goto LABEL_9;
}
if ( v11 <= v7 )
{
v14 = qsz;
v12 = v11;
v5 = qsz;
goto LABEL_14;
}
}
else
{
LABEL_9:
if ( v11 <= v7 )
{
v14 = v5;
v12 = v11;
if ( v10 == v7 )
goto LABEL_27;
LABEL_14:
v15 = v10;
v11 = &v12[-v14];
v12 = v7;
v7 = v10;
LABEL_15:
v16 = (__int64)&v10[v5 - 1 + 1];
do
{
v17 = *v10;
v6 = *v12;
++v10;
++v12;
*(v10 - 1) = v6;
*(v12 - 1) = v17;
}
while ( v10 != (unsigned __int8 *)v16 );
v10 = v15;
goto LABEL_18;
}
}
v12 = v11;
do
{
v13 = (int)qcmp(v7, v12, v6) <= 0;
v14 = qsz;
v5 = qsz;
if ( !v13 )
{
v15 = &v10[qsz];
if ( v10 == v7 )
{
v7 = v12;
v11 = v12;
}
else
{
v11 = &v12[-qsz];
}
goto LABEL_15;
}
v12 -= qsz;
}
while ( v7 < v12 );
if ( v10 != v7 )
goto LABEL_14;
LABEL_27:
v18 = &v10[v14];
result = (unsigned int)thresh;
v4 = (_DWORD)v2 - (_DWORD)v18;
if ( (int)v10 - (int)v3 > (int)v2 - (int)v18 )
{
if ( (int)v2 - (int)v18 >= thresh )
{
v25 = v2;
v4 = (_DWORD)v10 - (_DWORD)v3;
v2 = v10;
func0(v18, v25);
result = (unsigned int)thresh;
}
else
{
v4 = (_DWORD)v10 - (_DWORD)v3;
v2 = v10;
}
}
else if ( (int)v10 - (int)v3 >= thresh )
{
v24 = v3;
v3 = v18;
func0(v24, v10);
result = (unsigned int)thresh;
}
else
{
v3 = v18;
}
}
while ( v4 >= (int)result );
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

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
__int16 v2; // ax

if ( headings_flag )
{
fputs(&heading_pre, ind_fp);
ind_lc += headprelen;
v1 = *(_DWORD *)(curr + 48);
if ( v1 == -2 )
{
v2 = (*_ctype_b_loc())[(unsigned __int8)a1] & 0x100;
if ( headings_flag <= 0 )
{
a1 = (unsigned __int8)a1;
if ( v2 )
a1 = LOBYTE((*_ctype_tolower_loc())[(unsigned __int8)a1]);
}
else
{
a1 = (unsigned __int8)a1;
if ( !v2 )
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
__int16 v2; // ax

if ( headings_flag )
{
fputs(&heading_pre, ind_fp);
ind_lc += headprelen;
v1 = *(_DWORD *)(curr + 48);
if ( v1 == -2 )
{
v2 = (*_ctype_b_loc())[(unsigned __int8)a1] & 0x100;
if ( headings_flag <= 0 )
{
a1 = (unsigned __int8)a1;
if ( v2 )
a1 = LOBYTE((*_ctype_tolower_loc())[(unsigned __int8)a1]);
}
else
{
a1 = (unsigned __int8)a1;
if ( !v2 )
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; // rcx
char v3; // r9
const char *v4; // rcx
__int64 v5; // rsi
int v6; // er12
const char *v7; // rcx
int v8; // er12
__int64 v9; // r13
__int64 v10; // rbx
int v11; // eax
int v12; // er12
const char *v13; // rcx
const char *v14; // rdx
char *result; // rax

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

canonical_decompiled_code:
char *__fastcall func3(const char *a1)
{
const char *v1; // r8
__int64 v2; // rcx
char v3; // r9
const char *v4; // rcx
__int64 v5; // rsi
int v6; // er12
const char *v7; // rcx
int v8; // er12
__int64 v9; // r13
__int64 v10; // rbx
int v11; // eax
int v12; // er12
const char *v13; // rcx
const char *v14; // rdx
char *result; // rax

v1 = *(const char **)(curr + 8LL * level + 24);
v2 = (__int64)level << 10;
v3 = *v1;
if ( level <= prev_level )
{
v7 = (char *)&item_r + v2;
if ( v3 )
sprintf(line, "%s%s%s", a1, v7, v1);
else
sprintf(line, "%s%s%s", a1, v7, *(const char **)(curr + 8LL * level));
v5 = level;
ind_lc += *((_DWORD *)&ilen_r + level);
v6 = level;
}
else
{
v4 = (char *)&item_u + v2;
if ( v3 )
sprintf(line, "%s%s%s", a1, v4, v1);
else
sprintf(line, "%s%s%s", a1, v4, *(const char **)(curr + 8LL * level));
v5 = level;
v6 = level;
ind_lc += *((_DWORD *)&ilen_u + level);
}
v8 = v6 + 1;
v9 = curr;
v10 = v8;
if ( v8 <= 2 )
{
do
{
v9 = curr;
v12 = v10;
if ( !**(_BYTE **)(curr + 8LL * (int)v10) )
{
v5 = level;
goto LABEL_18;
}
fputs(line, ind_fp);
v13 = *(const char **)(curr + 8LL * (int)v10 + 24);
v14 = (char *)&item_x + 1024 * v10;
if ( *v13 )
sprintf(line, "%s%s", v14, v13);
else
sprintf(line, "%s%s", v14, *(const char **)(curr + 8LL * (int)v10));
v11 = *((_DWORD *)&ilen_x + v10++);
ind_lc += v11;
level = v12;
}
while ( (int)v10 <= 2 );
v9 = curr;
v5 = v12;
}
LABEL_18:
ind_indent = 0;
strcat(line, &delim_p[1024 * v5]);
result = encap;
end = v9;
begin = v9;
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 *