main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // r13
_DWORD *v8; // rax
void (*v9)(void); // rdx

modlist = 0LL;
f = fopen(*argv, "r");
if ( f )
{
if ( (unsigned int)ReadBootHeader() )
{
if ( nofMods <= 0 )
{
LABEL_17:
fclose(f);
v5 = ThisModule(kernel);
v6 = ThisModule(mainmod);
v7 = v6;
if ( v5 )
{
if ( v6 )
{
v8 = calloc(1uLL, 0x18uLL);
bootInfo = (__int64)v8;
*(_QWORD *)v8 = modlist;
v8[2] = argc;
*((_QWORD *)v8 + 2) = argv;
*(_DWORD *)*(int *)(v5 + 84) = (_DWORD)v8;
v9 = (void (*)(void))*(int *)(v7 + 68);
*(_DWORD *)(v5 + 8) |= 0x10000u;
v9();
}
else
{
printf("no main module");
}
}
else
{
puts("no kernel");
}
PrintMods();
}
else
{
v3 = 0;
while ( (unsigned int)ReadHeader() )
{
if ( !(unsigned int)ReadModule() )
{
printf("Incorrect module: %s\n", (const char *)(unsigned int)((_DWORD)&mod + 8));
goto LABEL_10;
}
RegisterModule();
if ( nofMods <= ++v3 )
goto LABEL_17;
}
printf("Incorrect header: %s\n", (const char *)(unsigned int)((_DWORD)&mod + 8));
LABEL_10:
fclose(f);
}
}
else
{
puts("Invalid BlackBox executable, make sure that the constant exeSize is correctly set");
}
}
else
{
printf("Couldn't find file: %s\n", "./bb.boot");
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // r13
_DWORD *v8; // rax
void (*v9)(void); // rdx

modlist = 0LL;
f = fopen(*argv, "r");
if ( f )
{
if ( (unsigned int)func13() )
{
if ( nofMods <= 0 )
{
LABEL_17:
fclose(f);
v5 = func4(kernel);
v6 = func4(mainmod);
v7 = v6;
if ( v5 )
{
if ( v6 )
{
v8 = calloc(1uLL, 0x18uLL);
bootInfo = (__int64)v8;
*(_QWORD *)v8 = modlist;
v8[2] = argc;
*((_QWORD *)v8 + 2) = argv;
*(_DWORD *)*(int *)(v5 + 84) = (_DWORD)v8;
v9 = (void (*)(void))*(int *)(v7 + 68);
*(_DWORD *)(v5 + 8) |= 0x10000u;
v9();
}
else
{
printf("no main module");
}
}
else
{
puts("no kernel");
}
func3();
}
else
{
v3 = 0;
while ( (unsigned int)func14() )
{
if ( !(unsigned int)func15() )
{
printf("Incorrect module: %s\n", (const char *)(unsigned int)((_DWORD)&mod + 8));
goto LABEL_10;
}
func2();
if ( nofMods <= ++v3 )
goto LABEL_17;
}
printf("Incorrect header: %s\n", (const char *)(unsigned int)((_DWORD)&mod + 8));
LABEL_10:
fclose(f);
}
}
else
{
puts("Invalid BlackBox executable, make sure that the constant exeSize is correctly set");
}
}
else
{
printf("Couldn't find file: %s\n", "./bb.boot");
}
return 0;
}

original_code:
int main (int argc, char *argv[])
{
  int i, ok;
  BodyProc body;
  int callBackAdr;
  Module *k, *m;
  modlist = ((void *)0);
  donothing("initializing BlackBox for Linux...\n");
  f = fopen(argv[0], "r");
  if (f != ((void *)0))
    {
      if (ReadBootHeader())
 {
   i = 0; ok = 1;
   while ((i < nofMods) && (ok)){
     ok = ReadHeader();
     if (ok) {
       ok = ReadModule();
       if (ok)
  RegisterModule();
       else
  printf("Incorrect module: %s\n", mod.name);
     } else
       printf("Incorrect header: %s\n", mod.name);
     i++;
   }
   fclose(f);
   if (ok) {
     k = ThisModule(kernel);
     m = ThisModule(mainmod);
     if (k == ((void *)0))
       printf("no kernel\n");
     else
       {
  if (m == ((void *)0))
    printf("no main module");
  else
    {
      bootInfo = calloc(1, sizeof(BootInfo));
      bootInfo->modList = modlist;
      bootInfo->argc = argc;
      bootInfo->argv = argv;
      *((int*)(k->varBase)) = (int)bootInfo;
      donothing("before body\n");
      body = (BodyProc)(m->code);
      k->opts = k->opts | 0x10000;
      body();
      donothing("after body\n");
    }
       }
     PrintMods();
   }
 } else
   printf("Invalid BlackBox executable, make sure that the constant exeSize is correctly set\n");
    } else
      printf("Couldn't find file: %s\n", bbfile);
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int i; int ok;
  void (*body)();
  int callBackAdr;
  struct Module *k; struct Module *m;
  modlist = ((void *)0);
  donothing("initializing BlackBox for Linux...\n");
  f = fopen(argv[0], "r");
  if (f != ((void *)0))
    {
      if (ReadBootHeader())
 {
   i = 0; ok = 1;
   while ((i < nofMods) && (ok)){
     ok = ReadHeader();
     if (ok) {
       ok = ReadModule();
       if (ok)
  RegisterModule();
       else
  printf("Incorrect module: %s\n", mod.name);
     } else
       printf("Incorrect header: %s\n", mod.name);
     i++;
   }
   fclose(f);
   if (ok) {
     k = ThisModule(kernel);
     m = ThisModule(mainmod);
     if (k == ((void *)0))
       printf("no kernel\n");
     else
       {
  if (m == ((void *)0))
    printf("no main module");
  else
    {
      bootInfo = calloc(1, sizeof(BootInfo));
      bootInfo->modList = modlist;
      bootInfo->argc = argc;
      bootInfo->argv = argv;
      *((int *)(k->varBase)) = (int)bootInfo;
      donothing("before body\n");
      body = (BodyProc)(m->code);
      k->opts = k->opts | 0x10000;
      body();
      donothing("after body\n");
    }
       }
     PrintMods();
   }
 } else
   printf("Invalid BlackBox executable, make sure that the constant exeSize is correctly set\n");
    } else
      printf("Couldn't find file: %s\n", bbfile);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: ok int

variable_types:
body
void (*)()

variable_types: callBackAdr int


printUsage

decompiled_code:
int __fastcall printUsage(const char *a1)
{
return printf("Usage: %s <iterm file to convert>\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return printf("Usage: %s <iterm file to convert>\n", a1);
}

original_code:
void printUsage(char * name) {
    printf("Usage: %s <iterm file to convert>\n", name);
}

canonical_original_code:
void printUsage(char *name) {
    printf("Usage: %s <iterm file to convert>\n", name);
}

variable_types:
name
char *

return_type: void


main

canonical_name: main

repo: ronas/GPCAZ

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return 0;
}

original_code:
int main(int argc, char** argv) {
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    return (0);
}

variable_types:
argv
char **

return_type: int


repo: ronyrus/timing-play

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
__int64 v5; // [rsp+0h] [rbp-28h] BYREF

while ( 1 )
{
puts("what is the password?:");
fflush(_bss_start);
if ( (unsigned int)__isoc99_scanf() != 1 )
{
puts("something wrong with the input, bye bye");
fflush(_bss_start);
return 1;
}
v3 = memcmp(&v5, "verysecretpassword", 0x12uLL);
if ( !v3 )
break;
puts("wrong password, try again!");
fflush(_bss_start);
}
puts("the password is correct, congrads!");
fflush(_bss_start);
return v3;
}

original_code:
int main(int argc, char *argv[])
{
    char buf[30 + 1];
    while (1)
    {
        do { printf("what is the password?:\n"); fflush(stdout); } while (0);
        if (scanf("%30s", buf) != 1)
        {
            do { printf("something wrong with the input, bye bye\n"); fflush(stdout); } while (0);
            return 1;
        }
        if (memcmp(buf, "verysecretpassword", strlen("verysecretpassword")))
            do { printf("wrong password, try again!\n"); fflush(stdout); } while (0);
        else
        {
            do { printf("the password is correct, congrads!\n"); fflush(stdout); } while (0);
            break;
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    char buf[-1];
    while (1)
    {
        do { printf("what is the password?:\n"); fflush(stdout); } while (0);
        if (scanf("%30s", buf) != 1)
        {
            do { printf("something wrong with the input, bye bye\n"); fflush(stdout); } while (0);
            return 1;
        }
        if (memcmp(buf, "verysecretpassword", strlen("verysecretpassword")))
            do { printf("wrong password, try again!\n"); fflush(stdout); } while (0);
        else
        {
            do { printf("the password is correct, congrads!\n"); fflush(stdout); } while (0);
            break;
        }
    }
    return 0;
}

variable_types:
buf
char [-1]


planeBoxOverlap

repo: rools/voxl

original_code:
int planeBoxOverlap(float normal[3],float d, float maxbox[3])
{
 int q;
 float vmin[3],vmax[3];
 for(q=0;q<=2;q++)
 {
  if(normal[q]>0.0f)
  {
   vmin[q]=-maxbox[q];
   vmax[q]=maxbox[q];
  }
  else
  {
   vmin[q]=maxbox[q];
   vmax[q]=-maxbox[q];
  }
 }
 if((normal[0]*vmin[0]+normal[1]*vmin[1]+normal[2]*vmin[2])+d>0.0f) return 0;
 if((normal[0]*vmax[0]+normal[1]*vmax[1]+normal[2]*vmax[2])+d>=0.0f) return 1;
 return 0;
}

canonical_original_code:
int planeBoxOverlap(float normal[3], float d, float maxbox[3])
{
 int q;
 float vmin[3]; float vmax[3];
 for(q=0;q<=2;q++)
 {
  if(normal[q]>0.0f)
  {
   vmin[q]=-maxbox[q];
   vmax[q]=maxbox[q];
  }
  else
  {
   vmin[q]=maxbox[q];
   vmax[q]=-maxbox[q];
  }
 }
 if((normal[0]*vmin[0]+normal[1]*vmin[1]+normal[2]*vmin[2])+d>0.0f) return 0;
 if((normal[0]*vmax[0]+normal[1]*vmax[1]+normal[2]*vmax[2])+d>=0.0f) return 1;
 return 0;
}

variable_types:
normal
float [3]

variable_types: d float

variable_types:
maxbox
float [3]

variable_types: q int

variable_types:
vmin
float [3]

variable_types:
vmax
float [3]


triBoxOverlap

decompiled_code:
_BOOL8 __fastcall triBoxOverlap(float *a1, float *a2, float **a3)
{
float *v3; // r8
float v4; // xmm3_4
float v5; // xmm2_4
float v6; // xmm0_4
float v7; // xmm1_4
float *v8; // rcx
float v9; // xmm7_4
float v10; // xmm8_4
float *v11; // rdx
float v12; // xmm6_4
float v13; // xmm3_4
float v14; // xmm5_4
float v15; // xmm4_4
float v16; // xmm11_4
float v17; // xmm0_4
float v18; // xmm9_4
float v19; // xmm12_4
float v20; // er10
float v21; // xmm15_4
float v22; // xmm10_4
_BOOL8 result; // rax
float v24; // xmm14_4
float v25; // xmm10_4
float v26; // xmm9_4
float v27; // edx
float v28; // xmm0_4
float v29; // xmm9_4
float v30; // xmm0_4
float v31; // xmm11_4
float v32; // xmm11_4
float v33; // xmm13_4
float v34; // xmm9_4
float v35; // xmm10_4
float v36; // xmm0_4
float v37; // xmm9_4
float v38; // xmm0_4
float v39; // xmm13_4
float v40; // xmm10_4
float v41; // xmm0_4
float v42; // xmm9_4
float v43; // xmm13_4
float v44; // xmm0_4
float v45; // xmm13_4
float v46; // xmm10_4
float v47; // xmm0_4
float v48; // xmm10_4
float v49; // xmm10_4
float v50; // xmm0_4
float v51; // xmm9_4
float v52; // xmm13_4
float v53; // xmm0_4
float v54; // xmm7_4
float v55; // xmm7_4
float v56; // xmm3_4
float v57; // [rsp+0h] [rbp-34h]
float v58; // [rsp+4h] [rbp-30h]
float v59; // [rsp+8h] [rbp-2Ch]
float v60; // [rsp+Ch] [rbp-28h]
float v61; // [rsp+Ch] [rbp-28h]
float v62; // [rsp+Ch] [rbp-28h]
float v63; // [rsp+10h] [rbp-24h]
float v64; // [rsp+14h] [rbp-20h]
float v65; // [rsp+18h] [rbp-1Ch]
float v66; // [rsp+18h] [rbp-1Ch]
float v67; // [rsp+1Ch] [rbp-18h]
float v68; // [rsp+20h] [rbp-14h]
int v69; // [rsp+28h] [rbp-Ch] BYREF

v3 = *a3;
v4 = a1[1];
v5 = (*a3)[1] - v4;
v6 = a1[2];
v7 = (*a3)[2] - v6;
v8 = a3[1];
v9 = v8[1] - v4;
v10 = v8[2] - v6;
v11 = a3[2];
v12 = v11[1] - v4;
v13 = v11[2] - v6;
v14 = v9 - v5;
v15 = v10 - v7;
LODWORD(v16) = COERCE_UNSIGNED_INT(v9 - v5) & LC2;
LODWORD(v17) = LC2 & COERCE_UNSIGNED_INT(v10 - v7);
v18 = (float)(v5 * (float)(v10 - v7)) - (float)(v7 * (float)(v9 - v5));
v19 = (float)(v12 * (float)(v10 - v7)) - (float)(v13 * (float)(v9 - v5));
if ( v19 <= v18 )
{
v18 = (float)(v12 * (float)(v10 - v7)) - (float)(v13 * (float)(v9 - v5));
v19 = (float)(v5 * (float)(v10 - v7)) - (float)(v7 * (float)(v9 - v5));
}
v20 = a2[1];
v21 = a2[2];
v22 = (float)(v20 * v17) + (float)(v21 * v16);
result = 0LL;
if ( v18 <= v22 && COERCE_FLOAT(LODWORD(v22) ^ LC1) <= v19 )
{
v59 = *v3 - *a1;
v57 = *v8 - *a1;
v58 = *v11 - *a1;
v24 = v57 - v59;
v25 = (float)(v7 * (float)(v57 - v59)) + (float)(v59 * COERCE_FLOAT(LODWORD(v15) ^ LC1));
v26 = (float)(COERCE_FLOAT(LODWORD(v15) ^ LC1) * v58) + (float)(v13 * (float)(v57 - v59));
if ( v26 <= v25 )
{
v25 = (float)(COERCE_FLOAT(LODWORD(v15) ^ LC1) * v58) + (float)(v13 * (float)(v57 - v59));
v26 = (float)(v7 * (float)(v57 - v59)) + (float)(v59 * COERCE_FLOAT(LODWORD(v15) ^ LC1));
}
v27 = *a2;
v28 = (float)(v17 * *a2) + (float)(v21 * COERCE_FLOAT(LODWORD(v24) & LC2));
result = 0LL;
if ( v25 <= v28 && COERCE_FLOAT(LODWORD(v28) ^ LC1) <= v26 )
{
v29 = (float)(v57 * v14) - (float)(v9 * v24);
v30 = (float)(v58 * v14) - (float)(v12 * v24);
if ( v29 <= v30 )
{
v30 = (float)(v57 * v14) - (float)(v9 * v24);
v29 = (float)(v58 * v14) - (float)(v12 * v24);
}
v31 = (float)(v16 * v27) + (float)(COERCE_FLOAT(LODWORD(v24) & LC2) * v20);
result = 0LL;
if ( v30 <= v31 && COERCE_FLOAT(LODWORD(v31) ^ LC1) <= v29 )
{
v64 = v12 - v9;
v32 = v13 - v10;
LODWORD(v60) = COERCE_UNSIGNED_INT(v12 - v9) & LC2;
LODWORD(v33) = LC2 & COERCE_UNSIGNED_INT(v13 - v10);
v34 = (float)(v5 * (float)(v13 - v10)) - (float)((float)(v12 - v9) * v7);
v35 = (float)(v12 * (float)(v13 - v10)) - (float)((float)(v12 - v9) * v13);
if ( v35 <= v34 )
{
v34 = (float)(v12 * (float)(v13 - v10)) - (float)((float)(v12 - v9) * v13);
v35 = (float)(v5 * (float)(v13 - v10)) - (float)((float)(v12 - v9) * v7);
}
v36 = (float)(v60 * v21) + (float)(v20 * v33);
result = 0LL;
if ( v34 <= v36 && COERCE_FLOAT(LODWORD(v36) ^ LC1) <= v35 )
{
v63 = v58 - v57;
v37 = (float)((float)(v58 - v57) * v7) + (float)(v59 * COERCE_FLOAT(LODWORD(v32) ^ LC1));
v38 = (float)(COERCE_FLOAT(LODWORD(v32) ^ LC1) * v58) + (float)((float)(v58 - v57) * v13);
if ( v38 <= v37 )
{
v37 = (float)(COERCE_FLOAT(LODWORD(v32) ^ LC1) * v58) + (float)((float)(v58 - v57) * v13);
v38 = (float)((float)(v58 - v57) * v7) + (float)(v59 * COERCE_FLOAT(LODWORD(v32) ^ LC1));
}
LODWORD(v65) = LODWORD(v63) & LC2;
v39 = (float)(v33 * v27) + (float)(COERCE_FLOAT(LODWORD(v63) & LC2) * v21);
result = 0LL;
if ( v37 <= v39 && COERCE_FLOAT(LODWORD(v39) ^ LC1) <= v38 )
{
v40 = (float)(v64 * v59) - (float)(v63 * v5);
v41 = (float)(v57 * v64) - (float)(v63 * v9);
if ( v41 <= v40 )
{
v40 = (float)(v57 * v64) - (float)(v63 * v9);
v41 = (float)(v64 * v59) - (float)(v63 * v5);
}
result = 0LL;
if ( v40 <= (float)((float)(v20 * v65) + (float)(v27 * v60))
&& COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(v20 * v65) + (float)(v27 * v60)) ^ LC1) <= v41 )
{
v42 = v5 - v12;
LODWORD(v67) = COERCE_UNSIGNED_INT(v5 - v12) & LC2;
LODWORD(v66) = LC2 & COERCE_UNSIGNED_INT(v7 - v13);
v61 = (float)(v5 * (float)(v7 - v13)) - (float)(v7 * (float)(v5 - v12));
v43 = (float)(v9 * (float)(v7 - v13)) - (float)(v10 * (float)(v5 - v12));
if ( v43 <= v61 )
{
v61 = (float)(v9 * (float)(v7 - v13)) - (float)(v10 * (float)(v5 - v12));
v43 = (float)(v5 * (float)(v7 - v13)) - (float)(v7 * (float)(v5 - v12));
}
v44 = (float)(v67 * v21) + (float)(v20 * v66);
result = 0LL;
if ( v61 <= v44 && COERCE_FLOAT(LODWORD(v44) ^ LC1) <= v43 )
{
v45 = v59 - v58;
LODWORD(v46) = COERCE_UNSIGNED_INT(v7 - v13) ^ LC1;
v47 = (float)(v7 * (float)(v59 - v58)) + (float)(v59 * v46);
v62 = v47;
v48 = (float)(v46 * v57) + (float)(v10 * (float)(v59 - v58));
if ( v48 <= v47 )
{
v62 = v48;
v48 = v47;
}
LODWORD(v68) = LODWORD(v45) & LC2;
result = 0LL;
if ( v62 <= (float)((float)(v27 * v66) + (float)(COERCE_FLOAT(LODWORD(v45) & LC2) * v21))
&& COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(v27 * v66) + (float)(COERCE_FLOAT(LODWORD(v45) & LC2) * v21)) ^ LC1) <= v48 )
{
v49 = (float)(v57 * v42) - (float)(v9 * v45);
v50 = (float)(v42 * v58) - (float)(v45 * v12);
v51 = v50;
if ( v49 <= v50 )
{
v51 = v49;
v49 = v50;
}
result = 0LL;
if ( v51 <= (float)((float)(v20 * v68) + (float)(v27 * v67)) )
{
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(v20 * v68) + (float)(v27 * v67)) ^ LC1) > v49 )
{
result = 0LL;
}
else
{
v52 = fmaxf(v58, fmaxf(v57, v59));
if ( fminf(v58, fminf(v57, v59)) > v27 )
{
result = 0LL;
}
else if ( COERCE_FLOAT(LODWORD(v27) ^ LC1) > v52 )
{
result = 0LL;
}
else
{
v53 = fminf(v9, v5);
v54 = fmaxf(v12, fmaxf(v9, v5));
if ( fminf(v12, v53) > v20 )
{
result = 0LL;
}
else if ( COERCE_FLOAT(LODWORD(v20) ^ LC1) > v54 )
{
result = 0LL;
}
else
{
v55 = fminf(v13, fminf(v10, v7));
v56 = fmaxf(v13, fmaxf(v10, v7));
if ( v55 > v21 )
{
result = 0LL;
}
else if ( COERCE_FLOAT(LODWORD(v21) ^ LC1) > v56 )
{
result = 0LL;
}
else
{
result = planeBoxOverlap(
(float *)&v69,
(__int64)a2,
COERCE_FLOAT(COERCE_UNSIGNED_INT(
(float)((float)(v5
* (float)((float)(v15 * v63) - (float)(v32 * v24)))
+ (float)(v59
* (float)((float)(v14 * v32) - (float)(v64 * v15))))
+ (float)(v7 * (float)((float)(v24 * v64) - (float)(v14 * v63)))) ^ LC1));
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(float *a1, float *a2, float **a3)
{
float *v3; // r8
float v4; // xmm3_4
float v5; // xmm2_4
float v6; // xmm0_4
float v7; // xmm1_4
float *v8; // rcx
float v9; // xmm7_4
float v10; // xmm8_4
float *v11; // rdx
float v12; // xmm6_4
float v13; // xmm3_4
float v14; // xmm5_4
float v15; // xmm4_4
float v16; // xmm11_4
float v17; // xmm0_4
float v18; // xmm9_4
float v19; // xmm12_4
float v20; // er10
float v21; // xmm15_4
float v22; // xmm10_4
_BOOL8 result; // rax
float v24; // xmm14_4
float v25; // xmm10_4
float v26; // xmm9_4
float v27; // edx
float v28; // xmm0_4
float v29; // xmm9_4
float v30; // xmm0_4
float v31; // xmm11_4
float v32; // xmm11_4
float v33; // xmm13_4
float v34; // xmm9_4
float v35; // xmm10_4
float v36; // xmm0_4
float v37; // xmm9_4
float v38; // xmm0_4
float v39; // xmm13_4
float v40; // xmm10_4
float v41; // xmm0_4
float v42; // xmm9_4
float v43; // xmm13_4
float v44; // xmm0_4
float v45; // xmm13_4
float v46; // xmm10_4
float v47; // xmm0_4
float v48; // xmm10_4
float v49; // xmm10_4
float v50; // xmm0_4
float v51; // xmm9_4
float v52; // xmm13_4
float v53; // xmm0_4
float v54; // xmm7_4
float v55; // xmm7_4
float v56; // xmm3_4
float v57; // [rsp+0h] [rbp-34h]
float v58; // [rsp+4h] [rbp-30h]
float v59; // [rsp+8h] [rbp-2Ch]
float v60; // [rsp+Ch] [rbp-28h]
float v61; // [rsp+Ch] [rbp-28h]
float v62; // [rsp+Ch] [rbp-28h]
float v63; // [rsp+10h] [rbp-24h]
float v64; // [rsp+14h] [rbp-20h]
float v65; // [rsp+18h] [rbp-1Ch]
float v66; // [rsp+18h] [rbp-1Ch]
float v67; // [rsp+1Ch] [rbp-18h]
float v68; // [rsp+20h] [rbp-14h]
int v69; // [rsp+28h] [rbp-Ch] BYREF

v3 = *a3;
v4 = a1[1];
v5 = (*a3)[1] - v4;
v6 = a1[2];
v7 = (*a3)[2] - v6;
v8 = a3[1];
v9 = v8[1] - v4;
v10 = v8[2] - v6;
v11 = a3[2];
v12 = v11[1] - v4;
v13 = v11[2] - v6;
v14 = v9 - v5;
v15 = v10 - v7;
LODWORD(v16) = COERCE_UNSIGNED_INT(v9 - v5) & LC2;
LODWORD(v17) = LC2 & COERCE_UNSIGNED_INT(v10 - v7);
v18 = (float)(v5 * (float)(v10 - v7)) - (float)(v7 * (float)(v9 - v5));
v19 = (float)(v12 * (float)(v10 - v7)) - (float)(v13 * (float)(v9 - v5));
if ( v19 <= v18 )
{
v18 = (float)(v12 * (float)(v10 - v7)) - (float)(v13 * (float)(v9 - v5));
v19 = (float)(v5 * (float)(v10 - v7)) - (float)(v7 * (float)(v9 - v5));
}
v20 = a2[1];
v21 = a2[2];
v22 = (float)(v20 * v17) + (float)(v21 * v16);
result = 0LL;
if ( v18 <= v22 && COERCE_FLOAT(LODWORD(v22) ^ LC1) <= v19 )
{
v59 = *v3 - *a1;
v57 = *v8 - *a1;
v58 = *v11 - *a1;
v24 = v57 - v59;
v25 = (float)(v7 * (float)(v57 - v59)) + (float)(v59 * COERCE_FLOAT(LODWORD(v15) ^ LC1));
v26 = (float)(COERCE_FLOAT(LODWORD(v15) ^ LC1) * v58) + (float)(v13 * (float)(v57 - v59));
if ( v26 <= v25 )
{
v25 = (float)(COERCE_FLOAT(LODWORD(v15) ^ LC1) * v58) + (float)(v13 * (float)(v57 - v59));
v26 = (float)(v7 * (float)(v57 - v59)) + (float)(v59 * COERCE_FLOAT(LODWORD(v15) ^ LC1));
}
v27 = *a2;
v28 = (float)(v17 * *a2) + (float)(v21 * COERCE_FLOAT(LODWORD(v24) & LC2));
result = 0LL;
if ( v25 <= v28 && COERCE_FLOAT(LODWORD(v28) ^ LC1) <= v26 )
{
v29 = (float)(v57 * v14) - (float)(v9 * v24);
v30 = (float)(v58 * v14) - (float)(v12 * v24);
if ( v29 <= v30 )
{
v30 = (float)(v57 * v14) - (float)(v9 * v24);
v29 = (float)(v58 * v14) - (float)(v12 * v24);
}
v31 = (float)(v16 * v27) + (float)(COERCE_FLOAT(LODWORD(v24) & LC2) * v20);
result = 0LL;
if ( v30 <= v31 && COERCE_FLOAT(LODWORD(v31) ^ LC1) <= v29 )
{
v64 = v12 - v9;
v32 = v13 - v10;
LODWORD(v60) = COERCE_UNSIGNED_INT(v12 - v9) & LC2;
LODWORD(v33) = LC2 & COERCE_UNSIGNED_INT(v13 - v10);
v34 = (float)(v5 * (float)(v13 - v10)) - (float)((float)(v12 - v9) * v7);
v35 = (float)(v12 * (float)(v13 - v10)) - (float)((float)(v12 - v9) * v13);
if ( v35 <= v34 )
{
v34 = (float)(v12 * (float)(v13 - v10)) - (float)((float)(v12 - v9) * v13);
v35 = (float)(v5 * (float)(v13 - v10)) - (float)((float)(v12 - v9) * v7);
}
v36 = (float)(v60 * v21) + (float)(v20 * v33);
result = 0LL;
if ( v34 <= v36 && COERCE_FLOAT(LODWORD(v36) ^ LC1) <= v35 )
{
v63 = v58 - v57;
v37 = (float)((float)(v58 - v57) * v7) + (float)(v59 * COERCE_FLOAT(LODWORD(v32) ^ LC1));
v38 = (float)(COERCE_FLOAT(LODWORD(v32) ^ LC1) * v58) + (float)((float)(v58 - v57) * v13);
if ( v38 <= v37 )
{
v37 = (float)(COERCE_FLOAT(LODWORD(v32) ^ LC1) * v58) + (float)((float)(v58 - v57) * v13);
v38 = (float)((float)(v58 - v57) * v7) + (float)(v59 * COERCE_FLOAT(LODWORD(v32) ^ LC1));
}
LODWORD(v65) = LODWORD(v63) & LC2;
v39 = (float)(v33 * v27) + (float)(COERCE_FLOAT(LODWORD(v63) & LC2) * v21);
result = 0LL;
if ( v37 <= v39 && COERCE_FLOAT(LODWORD(v39) ^ LC1) <= v38 )
{
v40 = (float)(v64 * v59) - (float)(v63 * v5);
v41 = (float)(v57 * v64) - (float)(v63 * v9);
if ( v41 <= v40 )
{
v40 = (float)(v57 * v64) - (float)(v63 * v9);
v41 = (float)(v64 * v59) - (float)(v63 * v5);
}
result = 0LL;
if ( v40 <= (float)((float)(v20 * v65) + (float)(v27 * v60))
&& COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(v20 * v65) + (float)(v27 * v60)) ^ LC1) <= v41 )
{
v42 = v5 - v12;
LODWORD(v67) = COERCE_UNSIGNED_INT(v5 - v12) & LC2;
LODWORD(v66) = LC2 & COERCE_UNSIGNED_INT(v7 - v13);
v61 = (float)(v5 * (float)(v7 - v13)) - (float)(v7 * (float)(v5 - v12));
v43 = (float)(v9 * (float)(v7 - v13)) - (float)(v10 * (float)(v5 - v12));
if ( v43 <= v61 )
{
v61 = (float)(v9 * (float)(v7 - v13)) - (float)(v10 * (float)(v5 - v12));
v43 = (float)(v5 * (float)(v7 - v13)) - (float)(v7 * (float)(v5 - v12));
}
v44 = (float)(v67 * v21) + (float)(v20 * v66);
result = 0LL;
if ( v61 <= v44 && COERCE_FLOAT(LODWORD(v44) ^ LC1) <= v43 )
{
v45 = v59 - v58;
LODWORD(v46) = COERCE_UNSIGNED_INT(v7 - v13) ^ LC1;
v47 = (float)(v7 * (float)(v59 - v58)) + (float)(v59 * v46);
v62 = v47;
v48 = (float)(v46 * v57) + (float)(v10 * (float)(v59 - v58));
if ( v48 <= v47 )
{
v62 = v48;
v48 = v47;
}
LODWORD(v68) = LODWORD(v45) & LC2;
result = 0LL;
if ( v62 <= (float)((float)(v27 * v66) + (float)(COERCE_FLOAT(LODWORD(v45) & LC2) * v21))
&& COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(v27 * v66) + (float)(COERCE_FLOAT(LODWORD(v45) & LC2) * v21)) ^ LC1) <= v48 )
{
v49 = (float)(v57 * v42) - (float)(v9 * v45);
v50 = (float)(v42 * v58) - (float)(v45 * v12);
v51 = v50;
if ( v49 <= v50 )
{
v51 = v49;
v49 = v50;
}
result = 0LL;
if ( v51 <= (float)((float)(v20 * v68) + (float)(v27 * v67)) )
{
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(v20 * v68) + (float)(v27 * v67)) ^ LC1) > v49 )
{
result = 0LL;
}
else
{
v52 = fmaxf(v58, fmaxf(v57, v59));
if ( fminf(v58, fminf(v57, v59)) > v27 )
{
result = 0LL;
}
else if ( COERCE_FLOAT(LODWORD(v27) ^ LC1) > v52 )
{
result = 0LL;
}
else
{
v53 = fminf(v9, v5);
v54 = fmaxf(v12, fmaxf(v9, v5));
if ( fminf(v12, v53) > v20 )
{
result = 0LL;
}
else if ( COERCE_FLOAT(LODWORD(v20) ^ LC1) > v54 )
{
result = 0LL;
}
else
{
v55 = fminf(v13, fminf(v10, v7));
v56 = fmaxf(v13, fmaxf(v10, v7));
if ( v55 > v21 )
{
result = 0LL;
}
else if ( COERCE_FLOAT(LODWORD(v21) ^ LC1) > v56 )
{
result = 0LL;
}
else
{
result = func0(
(float *)&v69,
(__int64)a2,
COERCE_FLOAT(COERCE_UNSIGNED_INT(
(float)((float)(v5
* (float)((float)(v15 * v63) - (float)(v32 * v24)))
+ (float)(v59
* (float)((float)(v14 * v32) - (float)(v64 * v15))))
+ (float)(v7 * (float)((float)(v24 * v64) - (float)(v14 * v63)))) ^ LC1));
}
}
}
}
}
}
}
}
}
}
}
}
}
return result;
}

variable_types:
boxcenter
float [3]

variable_types:
boxhalfsize
float [3]

variable_types:
triverts
float *[3]

variable_types: min float

variable_types: max float

variable_types: rad float

variable_types: fex float

variable_types: fey float

variable_types: fez float


original_code:
struct vx_voxel *vx_get_octree_voxel(struct vx_octree *octree, float x, float y, float z, int detail) {
 uint32_t node = 0;
 float mid_point[3] = {0.5f, 0.5f, 0.5f};
 float node_size = 0.5f;
 struct vx_voxel *voxel = ((void *)0);
 for (int i = detail - 1; i >= 0; --i) {
  int octant = x > mid_point[0] ? 1 : 0;
  octant |= y > mid_point[1] ? 2 : 0;
  octant |= z > mid_point[2] ? 4 : 0;
  node_size *= 0.5f;
  mid_point[0] += x > mid_point[0] ? node_size : - node_size;
  mid_point[1] += y > mid_point[1] ? node_size : - node_size;
  mid_point[2] += z > mid_point[2] ? node_size : - node_size;
  if (i == 0) {
   if (octree->root[node].valid_masks & (1 << octant) && octree->root[node].leaf_mask & (1 << octant)) {
    voxel = (struct vx_voxel *)&octree->root[octree->root[node].child_pointers[octant]];
   } else {
    struct vx_voxel new_voxel;
    int pointer = vx_append_to_octree(octree, &new_voxel, 1);
    octree->root[node].valid_masks |= (1 << octant);
    octree->root[node].leaf_mask |= (1 << octant);
    octree->root[node].child_pointers[octant] = pointer;
    voxel = (struct vx_voxel *)&octree->root[pointer];
   }
  } else {
   if (octree->root[node].valid_masks & (1 << octant)) {
    node = octree->root[node].child_pointers[octant];
   } else {
    struct vx_node new_node;
    new_node.leaf_mask = 0;
    new_node.valid_masks = 0;
    int pointer = vx_append_to_octree(octree, &new_node, 1);
    octree->root[node].child_pointers[octant] = pointer;
    octree->root[node].valid_masks |= (1 << octant);
    node = pointer;
   }
  }
 }
 return voxel;
}

canonical_original_code:
struct vx_voxel *vx_get_octree_voxel(struct vx_octree *octree, float x, float y, float z, int detail) {
 unsigned int node = 0;
 float mid_point[3] = {0.5f, 0.5f, 0.5f};
 float node_size = 0.5f;
 struct vx_voxel *voxel = ((void *)0);
 for (int i = detail - 1; i >= 0; --i) {
  int octant = x > mid_point[0] ? 1 : 0;
  octant |= y > mid_point[1] ? 2 : 0;
  octant |= z > mid_point[2] ? 4 : 0;
  node_size *= 0.5f;
  mid_point[0] += x > mid_point[0] ? node_size : - node_size;
  mid_point[1] += y > mid_point[1] ? node_size : - node_size;
  mid_point[2] += z > mid_point[2] ? node_size : - node_size;
  if (i == 0) {
   if (octree->root[node].valid_masks & (1 << octant) && octree->root[node].leaf_mask & (1 << octant)) {
    voxel = (struct vx_voxel *)&octree->root[octree->root[node].child_pointers[octant]];
   } else {
    struct vx_voxel new_voxel;
    int pointer = vx_append_to_octree(octree, &new_voxel, 1);
    octree->root[node].valid_masks |= (1 << octant);
    octree->root[node].leaf_mask |= (1 << octant);
    octree->root[node].child_pointers[octant] = pointer;
    voxel = (struct vx_voxel *)&octree->root[pointer];
   }
  } else {
   if (octree->root[node].valid_masks & (1 << octant)) {
    node = octree->root[node].child_pointers[octant];
   } else {
    struct vx_node new_node;
    new_node.leaf_mask = 0;
    new_node.valid_masks = 0;
    int pointer = vx_append_to_octree(octree, &new_node, 1);
    octree->root[node].child_pointers[octant] = pointer;
    octree->root[node].valid_masks |= (1 << octant);
    node = pointer;
   }
  }
 }
 return voxel;
}

variable_types: struct vx_octree { struct vx_node { unsigned int child_pointers[8]; unsigned char valid_masks; unsigned char leaf_mask; unsigned short padding; } *root; unsigned int size; unsigned int allocated_size; unsigned int models[16]; int model_count; } *

variable_types: x float

variable_types: y float

variable_types: z float

variable_types: detail int

variable_types:
node
unsigned int

variable_types: struct vx_voxel { char normals[3]; unsigned char colors[4]; char padding; unsigned int padding2[7]; } *

variable_types: i int

variable_types: octant int

variable_types: pointer int

user_defined_types: struct vx_octree { struct vx_node *root; unsigned int size; unsigned int allocated_size; unsigned int models[16]; int model_count; }


repo: rosmo/mysql-jsonget

decompiled_code:
__int64 __fastcall json_get_init(__int64 a1, __int64 a2, char *a3)
{
_DWORD *v3; // rax
__int64 result; // rax

if ( *(_DWORD *)a2 == 2 )
{
v3 = *(_DWORD **)(a2 + 8);
if ( v3[1] )
{
strcpy(a3, "Wrong type of argument, string is expected");
result = 1LL;
}
else
{
*v3 = 0;
*(_BYTE *)a1 = 1;
*(_DWORD *)(a1 + 8) = 0xFFFF;
result = 0LL;
}
}
else
{
strcpy(a3, "Too few or many arguments");
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, char *a3)
{
_DWORD *v3; // rax
__int64 result; // rax

if ( *(_DWORD *)a2 == 2 )
{
v3 = *(_DWORD **)(a2 + 8);
if ( v3[1] )
{
strcpy(a3, "Wrong type of argument, string is expected");
result = 1LL;
}
else
{
*v3 = 0;
*(_BYTE *)a1 = 1;
*(_DWORD *)(a1 + 8) = 0xFFFF;
result = 0LL;
}
}
else
{
strcpy(a3, "Too few or many arguments");
result = 1LL;
}
return result;
}

original_code:
my_bool json_get_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
  if (args->arg_count != 2)
  {
    strcpy(message, "Too few or many arguments");
    return 1;
  }
  if (args->arg_type[1] != STRING_RESULT)
  {
    strcpy(message, "Wrong type of argument, string is expected");
    return 1;
  }
  args->arg_type[0] = STRING_RESULT;
  initid->maybe_null = 1;
  initid->max_length = 0xFFFF;
  return 0;
}

canonical_original_code:
char json_get_init(struct st_udf_init *initid, struct st_udf_args *args, char *message)
{
  if (args->arg_count != 2)
  {
    strcpy(message, "Too few or many arguments");
    return 1;
  }
  if (args->arg_type[1] != STRING_RESULT)
  {
    strcpy(message, "Wrong type of argument, string is expected");
    return 1;
  }
  args->arg_type[0] = STRING_RESULT;
  initid->maybe_null = 1;
  initid->max_length = 0xFFFF;
  return 0;
}

variable_types: struct st_udf_init { char maybe_null; unsigned int decimals; unsigned int max_length; char *ptr; char const_item; } *

variable_types: struct st_udf_args { unsigned int arg_count; enum Item_result { STRING_RESULT=0, REAL_RESULT=1, INT_RESULT=2, ROW_RESULT=3, DECIMAL_RESULT=4 } *arg_type; char **args; unsigned long *lengths; char *maybe_null; } *

variable_types:
message
char *

return_type: char

user_defined_types: struct st_udf_args { unsigned int arg_count; enum Item_result *arg_type; char **args; unsigned long *lengths; char *maybe_null; }


decompiled_code:
void __fastcall json_get_deinit(__int64 a1)
{
void *v1; // rdi

v1 = *(void **)(a1 + 16);
if ( v1 )
free(v1);
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1)
{
void *v1; // rdi

v1 = *(void **)(a1 + 16);
if ( v1 )
free(v1);
}

original_code:
void json_get_deinit(UDF_INIT *initid)
{
  if (initid->ptr != ((void *)0)) {
    free(initid->ptr);
  }
}

canonical_original_code:
void json_get_deinit(struct st_udf_init *initid)
{
  if (initid->ptr != ((void *)0)) {
    free(initid->ptr);
  }
}

user_defined_types: struct st_udf_init { char maybe_null; unsigned int decimals; unsigned int max_length; char *ptr; char const_item; }


repo: rothrock/Roxanne

decompiled_code:
int __fastcall keydb_lock(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[2]; // [rsp+0h] [rbp-408h] BYREF
char v4[1008]; // [rsp+10h] [rbp-3F8h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
memset(v4, 0, sizeof(v4));
sprintf((char *)v3, "%llu", a1);
v1 = get_hash_val(10LL, v3);
while ( 1 )
{
sem_wait(KEYDB_LOCK);
if ( !(unsigned int)bit_array_test(SHM_KEYDB_BITMAP, v1) )
break;
sem_post(KEYDB_LOCK);
}
bit_array_set(SHM_KEYDB_BITMAP, v1);
return sem_post(KEYDB_LOCK);
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[2]; // [rsp+0h] [rbp-408h] BYREF
char v4[1008]; // [rsp+10h] [rbp-3F8h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
memset(v4, 0, sizeof(v4));
sprintf((char *)v3, "%llu", a1);
v1 = get_hash_val(10LL, v3);
while ( 1 )
{
sem_wait(KEYDB_LOCK);
if ( !(unsigned int)bit_array_test(SHM_KEYDB_BITMAP, v1) )
break;
sem_post(KEYDB_LOCK);
}
bit_array_set(SHM_KEYDB_BITMAP, v1);
return sem_post(KEYDB_LOCK);
}

original_code:
void keydb_lock(int64_t pos) {
  char key[1024] = "";
  int hash_number;
  sprintf(key, "%llu", pos);
  hash_number = get_hash_val(10, key);
  while (1) {
    sem_wait(KEYDB_LOCK);
    if ((bit_array_test(SHM_KEYDB_BITMAP, hash_number)) == 0) {
      bit_array_set(SHM_KEYDB_BITMAP, hash_number);
      sem_post(KEYDB_LOCK);
      break;
    }
    sem_post(KEYDB_LOCK);
  }
}

canonical_original_code:
void keydb_lock(long pos) {
  char key[1024] = "";
  int hash_number;
  sprintf(key, "%llu", pos);
  hash_number = get_hash_val(10, key);
  while (1) {
    sem_wait(KEYDB_LOCK);
    if ((bit_array_test(SHM_KEYDB_BITMAP, hash_number)) == 0) {
      bit_array_set(SHM_KEYDB_BITMAP, hash_number);
      sem_post(KEYDB_LOCK);
      break;
    }
    sem_post(KEYDB_LOCK);
  }
}

variable_types: pos long

variable_types:
key
char [1024]


decompiled_code:
int __fastcall keydb_unlock(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[2]; // [rsp+0h] [rbp-408h] BYREF
char v4[1008]; // [rsp+10h] [rbp-3F8h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
memset(v4, 0, sizeof(v4));
sprintf((char *)v3, "%llu", a1);
v1 = get_hash_val(10LL, v3);
sem_wait(KEYDB_LOCK);
bit_array_clear(SHM_KEYDB_BITMAP, v1);
return sem_post(KEYDB_LOCK);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
unsigned int v1; // ebx
__int64 v3[2]; // [rsp+0h] [rbp-408h] BYREF
char v4[1008]; // [rsp+10h] [rbp-3F8h] BYREF

v3[0] = 0LL;
v3[1] = 0LL;
memset(v4, 0, sizeof(v4));
sprintf((char *)v3, "%llu", a1);
v1 = get_hash_val(10LL, v3);
sem_wait(KEYDB_LOCK);
bit_array_clear(SHM_KEYDB_BITMAP, v1);
return sem_post(KEYDB_LOCK);
}

original_code:
void keydb_unlock(int64_t pos) {
  char key[1024] = "";
  int hash_number;
  sprintf(key, "%llu", pos);
  hash_number = get_hash_val(10, key);
  sem_wait(KEYDB_LOCK);
  bit_array_clear(SHM_KEYDB_BITMAP, hash_number);
  sem_post(KEYDB_LOCK);
}

canonical_original_code:
void keydb_unlock(long pos) {
  char key[1024] = "";
  int hash_number;
  sprintf(key, "%llu", pos);
  hash_number = get_hash_val(10, key);
  sem_wait(KEYDB_LOCK);
  bit_array_clear(SHM_KEYDB_BITMAP, hash_number);
  sem_post(KEYDB_LOCK);
}


decompiled_code:
__int64 __fastcall keydb_tree(unsigned int a1, __off_t a2, _QWORD *a3)
{
void *v4; // rax
void *v5; // rbx
_QWORD *v6; // rbp
__int64 v7; // rsi
__int64 v8; // rsi

v4 = key_buf_read(a1, a2);
if ( v4 )
{
v5 = v4;
v6 = malloc(0x400uLL);
if ( !v6 )
{
perror(0LL);
cleanup_and_exit(0LL);
}
v6[127] = 0LL;
if ( *((int *)v5 + 252) > 0 )
qmemcpy(v6, v5, 0x3F4uLL);
else
*(_BYTE *)v6 = 0;
v7 = *((_QWORD *)v5 + 128);
if ( v7 )
keydb_tree(a1, v7, a3);
v6[127] = *a3;
*a3 = v6;
v8 = *((_QWORD *)v5 + 127);
if ( v8 )
keydb_tree(a1, v8, a3);
free(v5);
}
return 0LL;
}

original_code:
void* keydb_tree(int fd, int64_t pos, struct keydb_column **list) {
  struct keydb_node* parent;
  struct keydb_node* buffer;
  struct keydb_column *mid = ((void *)0);
  int64_t next_pos;
  int64_t n;
  buffer = key_buf_read(fd, pos);
  if (buffer == ((void *)0)) return ((void *)0);
  if ((mid = malloc(sizeof(struct keydb_column))) == ((void *)0)) {
    perror(((void *)0));
    cleanup_and_exit(0);
  }
  mid->next = ((void *)0);
  if (buffer->refcount <= 0) {
    mid->column[0] = '\0';
  } else {
    memcpy(mid->column, buffer->column, (1024 - 2*(sizeof(int)) - sizeof(int64_t)));
    mid->refcount = buffer->refcount;
  }
  if (buffer->right != 0) keydb_tree(fd, buffer->right, list);
  mid->next = *list;
  *list = mid;
  if (buffer->left != 0) keydb_tree(fd, buffer->left, list);
  free(buffer);
  return ((void *)0);
}

canonical_original_code:
void *keydb_tree(int fd, long pos, struct keydb_column **list) {
  struct keydb_node *parent;
  struct keydb_node *buffer;
  struct keydb_column *mid = ((void *)0);
  long next_pos;
  long n;
  buffer = key_buf_read(fd, pos);
  if (buffer == ((void *)0)) return ((void *)0);
  if ((mid = malloc(sizeof(struct keydb_column))) == ((void *)0)) {
    perror(((void *)0));
    cleanup_and_exit(0);
  }
  mid->next = ((void *)0);
  if (buffer->refcount <= 0) {
    mid->column[0] = '\0';
  } else {
    memcpy(mid->column, buffer->column, (1024 - 2*(sizeof(int)) - sizeof(long)));
    mid->refcount = buffer->refcount;
  }
  if (buffer->right != 0) keydb_tree(fd, buffer->right, list);
  mid->next = *list;
  *list = mid;
  if (buffer->left != 0) keydb_tree(fd, buffer->left, list);
  free(buffer);
  return ((void *)0);
}

variable_types: fd int

variable_types: struct keydb_column { char column[-1]; int refcount; struct keydb_column *next; } **

variable_types: struct keydb_node { char column[-1]; int refcount; long left; long right; long next; long pos; } *

variable_types: n long

return_type: void *


decompiled_code:
__int64 __fastcall composite_delete(int fd, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // r12
_DWORD *v4; // rax
_DWORD *v5; // rbx
__int64 v6; // r12

if ( !a2 )
return 0LL;
v2 = a2;
v3 = 0LL;
while ( 1 )
{
keydb_lock(v3);
v4 = (_DWORD *)keydb_find(fd, (const char *)v2, v3);
v5 = v4;
if ( !v4 )
{
keydb_unlock(v3);
return 0xFFFFFFFFLL;
}
if ( !v4[252] )
{
free(v4);
keydb_unlock(v3);
return 0xFFFFFFFFLL;
}
keydb_unlock(v3);
v6 = *((_QWORD *)v5 + 130);
keydb_lock(v6);
--v5[252];
if ( pwrite(fd, v5, 0x418uLL, v6) == -1 )
break;
keydb_unlock(v6);
v3 = *((_QWORD *)v5 + 129);
v2 = *(_QWORD *)(v2 + 1016);
free(v5);
if ( !v2 )
return 0LL;
}
fprintf(stderr, "Problem writing node at %llu in composite_delete().\n", v6);
keydb_unlock(v6);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, __int64 a2)
{
__int64 v2; // rbp
__int64 v3; // r12
_DWORD *v4; // rax
_DWORD *v5; // rbx
__int64 v6; // r12

if ( !a2 )
return 0LL;
v2 = a2;
v3 = 0LL;
while ( 1 )
{
func0(v3);
v4 = (_DWORD *)func4(fd, (const char *)v2, v3);
v5 = v4;
if ( !v4 )
{
func1(v3);
return 0xFFFFFFFFLL;
}
if ( !v4[252] )
{
free(v4);
func1(v3);
return 0xFFFFFFFFLL;
}
func1(v3);
v6 = *((_QWORD *)v5 + 130);
func0(v6);
--v5[252];
if ( pwrite(fd, v5, 0x418uLL, v6) == -1 )
break;
func1(v6);
v3 = *((_QWORD *)v5 + 129);
v2 = *(_QWORD *)(v2 + 1016);
free(v5);
if ( !v2 )
return 0LL;
}
fprintf(stderr, "Problem writing node at %llu in composite_delete().\n", v6);
func1(v6);
return 0xFFFFFFFFLL;
}

original_code:
int composite_delete(int fd, struct keydb_column *tuple) {
  int64_t pos = 0;
  struct keydb_node *node;
  while (tuple) {
    keydb_lock(pos);
    node = keydb_find(fd, tuple->column, pos);
    if (node == ((void *)0)) {
      keydb_unlock(pos);
      return -1;
    }
    if (node->refcount == 0) {
      free(node);
      keydb_unlock(pos);
      return(-1);
    }
    keydb_unlock(pos);
    pos = node->pos;
    keydb_lock(pos);
    node->refcount--;
    if ((pwrite(fd, node, sizeof(struct keydb_node), pos)) == -1) {
      fprintf(stderr, "Problem writing node at %llu in composite_delete().\n", pos);
      keydb_unlock(pos);
      return(-1);
      free(node);
    };
    keydb_unlock(pos);
    pos = node->next;
    tuple = tuple->next;
    free(node);
  }
  return 0;
}

canonical_original_code:
int composite_delete(int fd, struct keydb_column *tuple) {
  long pos = 0;
  struct keydb_node *node;
  while (tuple) {
    keydb_lock(pos);
    node = keydb_find(fd, tuple->column, pos);
    if (node == ((void *)0)) {
      keydb_unlock(pos);
      return -1;
    }
    if (node->refcount == 0) {
      free(node);
      keydb_unlock(pos);
      return(-1);
    }
    keydb_unlock(pos);
    pos = node->pos;
    keydb_lock(pos);
    node->refcount--;
    if ((pwrite(fd, node, sizeof(struct keydb_node), pos)) == -1) {
      fprintf(stderr, "Problem writing node at %llu in composite_delete().\n", pos);
      keydb_unlock(pos);
      return(-1);
      free(node);
    };
    keydb_unlock(pos);
    pos = node->next;
    tuple = tuple->next;
    free(node);
  }
  return 0;
}

variable_types: struct keydb_column { char column[-1]; int refcount; struct keydb_column *next; } *

user_defined_types: struct keydb_node { char column[-1]; int refcount; long left; long right; long next; long pos; }


decompiled_code:
__int64 __fastcall find_free_key_node(int fd)
{
__off_t v1; // rax
unsigned int v2; // ebx
__int64 result; // rax
_BYTE v4[1080]; // [rsp+0h] [rbp-438h] BYREF

memset(v4, 0, 0x418uLL);
v1 = lseek(fd, 0LL, 2);
if ( v1 == -1 )
{
perror("lseek failed in find_free_key_node\n");
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
if ( pwrite(fd, v4, 0x418uLL, v1) == -1 )
{
perror("pwrite() failed in find_free_key_node.");
result = 0xFFFFFFFFLL;
}
else
{
result = v2;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd)
{
__off_t v1; // rax
unsigned int v2; // ebx
__int64 result; // rax
_BYTE v4[1080]; // [rsp+0h] [rbp-438h] BYREF

memset(v4, 0, 0x418uLL);
v1 = lseek(fd, 0LL, 2);
if ( v1 == -1 )
{
perror("lseek failed in find_free_key_node\n");
result = 0xFFFFFFFFLL;
}
else
{
v2 = v1;
if ( pwrite(fd, v4, 0x418uLL, v1) == -1 )
{
perror("pwrite() failed in find_free_key_node.");
result = 0xFFFFFFFFLL;
}
else
{
result = v2;
}
}
return result;
}

original_code:
int find_free_key_node(int fd) {
  uint64_t pos = 0;
  struct keydb_node buffer = {};
  if (pos == 0) {
    if ((pos = lseek(fd, 0, 2)) == -1) {
      perror("lseek failed in find_free_key_node\n");
      return -1;
    } else {
      if (pwrite(fd, &buffer, sizeof(buffer), pos) == -1) {
        perror("pwrite() failed in find_free_key_node.");
        return -1;
      }
    }
  }
 return pos;
}

canonical_original_code:
int find_free_key_node(int fd) {
  unsigned long pos = 0;
  struct keydb_node buffer = {};
  if (pos == 0) {
    if ((pos = lseek(fd, 0, 2)) == -1) {
      perror("lseek failed in find_free_key_node\n");
      return -1;
    } else {
      if (pwrite(fd, &buffer, sizeof(buffer), pos) == -1) {
        perror("pwrite() failed in find_free_key_node.");
        return -1;
      }
    }
  }
 return pos;
}

variable_types:
pos
unsigned long

variable_types: struct keydb_node { char column[-1]; int refcount; long left; long right; long next; long pos; }


decompiled_code:
__int64 __fastcall new_subkey_tree(int fd, char *src, __off_t offset, char *dest)
{
signed int v6; // eax
unsigned int v7; // ebp
__off_t v8; // r14

v6 = find_free_key_node(fd);
v7 = v6;
if ( v6 == -1 )
{
fwrite("find_free_key_node_failed.\n", 1uLL, 0x1BuLL, stderr);
free(dest);
}
else
{
v8 = v6;
*((_QWORD *)dest + 129) = v6;
if ( pwrite(fd, dest, 0x418uLL, offset) == -1
|| (*(_QWORD *)dest = 0LL,
*((_QWORD *)dest + 130) = 0LL,
memset(
(void *)((unsigned __int64)(dest + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)dest - (((_DWORD)dest + 8) & 0xFFFFFFF8) + 1048) >> 3)),
strcpy(dest, src),
*((_DWORD *)dest + 252) = 1,
*((_QWORD *)dest + 130) = v8,
pwrite(fd, dest, 0x418uLL, v8) == -1) )
{
perror("pwrite() failed in new_subkey_tree.");
free(dest);
v7 = -1;
}
else
{
free(dest);
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, char *src, __off_t offset, char *dest)
{
signed int v6; // eax
unsigned int v7; // ebp
__off_t v8; // r14

v6 = func6(fd);
v7 = v6;
if ( v6 == -1 )
{
fwrite("find_free_key_node_failed.\n", 1uLL, 0x1BuLL, stderr);
free(dest);
}
else
{
v8 = v6;
*((_QWORD *)dest + 129) = v6;
if ( pwrite(fd, dest, 0x418uLL, offset) == -1
|| (*(_QWORD *)dest = 0LL,
*((_QWORD *)dest + 130) = 0LL,
memset(
(void *)((unsigned __int64)(dest + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)dest - (((_DWORD)dest + 8) & 0xFFFFFFF8) + 1048) >> 3)),
strcpy(dest, src),
*((_DWORD *)dest + 252) = 1,
*((_QWORD *)dest + 130) = v8,
pwrite(fd, dest, 0x418uLL, v8) == -1) )
{
perror("pwrite() failed in new_subkey_tree.");
free(dest);
v7 = -1;
}
else
{
free(dest);
}
}
return v7;
}

original_code:
int new_subkey_tree(int fd, char column[], int64_t pos, struct keydb_node *buffer) {
  int64_t next_pos;
  if ((next_pos = find_free_key_node(fd)) == -1) {
    fprintf(stderr, "find_free_key_node_failed.\n");
    free(buffer);
    return -1;
  }
  buffer->next = next_pos;
  if (pwrite(fd, buffer, sizeof(struct keydb_node), pos) == -1) {
    perror("pwrite() failed in new_subkey_tree.");
    free(buffer);
    return -1;
  }
  bzero(buffer, sizeof(struct keydb_node));
  strcpy(buffer->column, column);
  buffer->refcount = 1;
  buffer->pos = next_pos;
  if (pwrite(fd, buffer, sizeof(struct keydb_node), next_pos) == -1) {
    perror("pwrite() failed in new_subkey_tree.");
    free(buffer);
    return -1;
  }
  free(buffer);
  return next_pos;
}

canonical_original_code:
int new_subkey_tree(int fd, char column[], long pos, struct keydb_node *buffer) {
  long next_pos;
  if ((next_pos = find_free_key_node(fd)) == -1) {
    fprintf(stderr, "find_free_key_node_failed.\n");
    free(buffer);
    return -1;
  }
  buffer->next = next_pos;
  if (pwrite(fd, buffer, sizeof(struct keydb_node), pos) == -1) {
    perror("pwrite() failed in new_subkey_tree.");
    free(buffer);
    return -1;
  }
  bzero(buffer, sizeof(struct keydb_node));
  strcpy(buffer->column, column);
  buffer->refcount = 1;
  buffer->pos = next_pos;
  if (pwrite(fd, buffer, sizeof(struct keydb_node), next_pos) == -1) {
    perror("pwrite() failed in new_subkey_tree.");
    free(buffer);
    return -1;
  }
  free(buffer);
  return next_pos;
}

variable_types:
column
char []


decompiled_code:
__int64 keydb_txlog_append()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
return 0LL;
}

original_code:
int keydb_txlog_append(int64_t pos) {
  return 0;
}

canonical_original_code:
int keydb_txlog_append(long pos) {
  return 0;
}


decompiled_code:
__int64 __fastcall connect_and_add_node(int a1, _QWORD *a2, char *a3, int a4, int a5)
{
int v8; // eax
int v9; // ebp

v8 = find_free_key_node(a5);
v9 = v8;
if ( v8 == -1 )
{
fwrite("find_free_key_node_failed.\n", 1uLL, 0x1BuLL, stderr);
free(a2);
}
else
{
if ( a1 )
a2[128] = v8;
else
a2[127] = v8;
if ( pwrite(a5, a2, 0x418uLL, a4) == -1 )
{
perror("Call to pwrite failed in connect_and_add_node.\n");
v9 = -1;
}
else
{
*a2 = 0LL;
a2[130] = 0LL;
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 1048) >> 3));
*a2 = *(_QWORD *)a3;
a2[125] = *((_QWORD *)a3 + 125);
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 1008) >> 3));
*((_DWORD *)a2 + 252) = 1;
a2[130] = v9;
if ( pwrite(a5, a2, 0x418uLL, v9) == -1 )
{
perror("Call to pwrite failed in connect_and_add_node.\n");
free(a2);
v9 = -1;
}
else
{
free(a2);
}
}
}
return (unsigned int)v9;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, _QWORD *a2, char *a3, int a4, int a5)
{
int v8; // eax
int v9; // ebp

v8 = func6(a5);
v9 = v8;
if ( v8 == -1 )
{
fwrite("find_free_key_node_failed.\n", 1uLL, 0x1BuLL, stderr);
free(a2);
}
else
{
if ( a1 )
a2[128] = v8;
else
a2[127] = v8;
if ( pwrite(a5, a2, 0x418uLL, a4) == -1 )
{
perror("Call to pwrite failed in connect_and_add_node.\n");
v9 = -1;
}
else
{
*a2 = 0LL;
a2[130] = 0LL;
memset(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 1048) >> 3));
*a2 = *(_QWORD *)a3;
a2[125] = *((_QWORD *)a3 + 125);
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(a3 - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 1008) >> 3));
*((_DWORD *)a2 + 252) = 1;
a2[130] = v9;
if ( pwrite(a5, a2, 0x418uLL, v9) == -1 )
{
perror("Call to pwrite failed in connect_and_add_node.\n");
free(a2);
v9 = -1;
}
else
{
free(a2);
}
}
}
return (unsigned int)v9;
}

original_code:
int connect_and_add_node(int direction, struct keydb_node* buffer, char column[], int pos, int fd) {
  int next_pos;
  if ((next_pos = find_free_key_node(fd)) == -1) {
    fprintf(stderr, "find_free_key_node_failed.\n");
    free(buffer);
    return -1;
  }
  if (direction == 0) {
    buffer->left = next_pos;
  } else {
    buffer->right = next_pos;
  }
  if ((pwrite(fd, buffer, sizeof(struct keydb_node), pos)) == -1) {
    perror("Call to pwrite failed in connect_and_add_node.\n");
    return -1;
  }
  bzero(buffer, sizeof(struct keydb_node));
  memcpy(buffer->column, column, (1024 - 2*(sizeof(int)) - sizeof(int64_t)));
  buffer->refcount = 1;
  buffer->pos = next_pos;
  if ((pwrite(fd, buffer, sizeof(struct keydb_node), next_pos)) == -1) {
    perror("Call to pwrite failed in connect_and_add_node.\n");
    free(buffer);
    return -1;
  }
  free(buffer);
  return next_pos;
}

canonical_original_code:
int connect_and_add_node(int direction, struct keydb_node *buffer, char column[], int pos, int fd) {
  int next_pos;
  if ((next_pos = find_free_key_node(fd)) == -1) {
    fprintf(stderr, "find_free_key_node_failed.\n");
    free(buffer);
    return -1;
  }
  if (direction == 0) {
    buffer->left = next_pos;
  } else {
    buffer->right = next_pos;
  }
  if ((pwrite(fd, buffer, sizeof(struct keydb_node), pos)) == -1) {
    perror("Call to pwrite failed in connect_and_add_node.\n");
    return -1;
  }
  bzero(buffer, sizeof(struct keydb_node));
  memcpy(buffer->column, column, (1024 - 2*(sizeof(int)) - sizeof(long)));
  buffer->refcount = 1;
  buffer->pos = next_pos;
  if ((pwrite(fd, buffer, sizeof(struct keydb_node), next_pos)) == -1) {
    perror("Call to pwrite failed in connect_and_add_node.\n");
    free(buffer);
    return -1;
  }
  free(buffer);
  return next_pos;
}

variable_types: direction int

variable_types: pos int


decompiled_code:
__int64 __fastcall keydb_insert(unsigned int a1, char *a2, __off_t a3, char a4)
{
_QWORD *v6; // rax
_QWORD *v7; // rbx
unsigned int v8; // eax
unsigned int v9; // er14
__int64 v10; // r14
int v12; // eax

v6 = malloc(0x418uLL);
if ( !v6 )
{
perror("Call to malloc() failed in keydb_insert.");
return (unsigned int)-1;
}
v7 = v6;
memset(v6, 0, 0x418uLL);
v8 = pread(a1, v6, 0x418uLL, a3);
v9 = v8;
if ( v8 == -1 )
{
perror("pread() failed in keydb_insert.");
free(v7);
return v9;
}
if ( !a4 )
{
if ( v8 )
{
v12 = strcmp((const char *)v7, a2);
if ( v12 > 0 )
{
v10 = v7[127];
if ( !v10 )
return (unsigned int)connect_and_add_node(0, v7, a2, a3, a1);
goto LABEL_22;
}
if ( v12 < 0 )
{
v10 = v7[128];
if ( !v10 )
return (unsigned int)connect_and_add_node(1, v7, a2, a3, a1);
goto LABEL_22;
}
++*((_DWORD *)v7 + 252);
if ( pwrite(a1, v7, 0x418uLL, a3) == -1 )
{
LABEL_25:
perror("pwrite() failed in keydb_insert.");
free(v7);
return (unsigned int)-1;
}
}
else
{
qmemcpy(v7, a2, 0x3F0uLL);
*((_DWORD *)v7 + 252) = 1;
v7[130] = a3;
if ( pwrite(a1, v7, 0x418uLL, a3) == -1 )
goto LABEL_25;
}
free(v7);
return (unsigned int)a3;
}
if ( !v8 )
{
fwrite("pos is at EOF but we need to read a real record.\n", 1uLL, 0x31uLL, stderr);
free(v7);
return (unsigned int)-1;
}
v10 = v7[129];
if ( v10 )
{
LABEL_22:
free(v7);
return (unsigned int)keydb_insert(a1, a2, v10, 0LL);
}
return (unsigned int)new_subkey_tree(a1, a2, a3, (char *)v7);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, char *a2, __off_t a3, char a4)
{
_QWORD *v6; // rax
_QWORD *v7; // rbx
unsigned int v8; // eax
unsigned int v9; // er14
__int64 v10; // r14
int v12; // eax

v6 = malloc(0x418uLL);
if ( !v6 )
{
perror("Call to malloc() failed in keydb_insert.");
return (unsigned int)-1;
}
v7 = v6;
memset(v6, 0, 0x418uLL);
v8 = pread(a1, v6, 0x418uLL, a3);
v9 = v8;
if ( v8 == -1 )
{
perror("pread() failed in keydb_insert.");
free(v7);
return v9;
}
if ( !a4 )
{
if ( v8 )
{
v12 = strcmp((const char *)v7, a2);
if ( v12 > 0 )
{
v10 = v7[127];
if ( !v10 )
return (unsigned int)func9(0, v7, a2, a3, a1);
goto LABEL_22;
}
if ( v12 < 0 )
{
v10 = v7[128];
if ( !v10 )
return (unsigned int)func9(1, v7, a2, a3, a1);
goto LABEL_22;
}
++*((_DWORD *)v7 + 252);
if ( pwrite(a1, v7, 0x418uLL, a3) == -1 )
{
LABEL_25:
perror("pwrite() failed in keydb_insert.");
free(v7);
return (unsigned int)-1;
}
}
else
{
qmemcpy(v7, a2, 0x3F0uLL);
*((_DWORD *)v7 + 252) = 1;
v7[130] = a3;
if ( pwrite(a1, v7, 0x418uLL, a3) == -1 )
goto LABEL_25;
}
free(v7);
return (unsigned int)a3;
}
if ( !v8 )
{
fwrite("pos is at EOF but we need to read a real record.\n", 1uLL, 0x31uLL, stderr);
free(v7);
return (unsigned int)-1;
}
v10 = v7[129];
if ( v10 )
{
LABEL_22:
free(v7);
return (unsigned int)func10(a1, a2, v10, 0LL);
}
return (unsigned int)func7(a1, a2, a3, (char *)v7);
}

original_code:
int keydb_insert(int fd, char column[], int64_t pos, _Bool go_next) {
  int n;
  int comparison;
  int64_t next_pos;
  struct keydb_node *buffer;
  if ((buffer = malloc(sizeof(struct keydb_node))) == ((void *)0)) {
    perror("Call to malloc() failed in keydb_insert.");
    return -1;
  }
  bzero(buffer, sizeof(struct keydb_node));
  n = pread(fd, buffer, sizeof(struct keydb_node), pos);
  if (n == -1) {
    perror("pread() failed in keydb_insert.");
    free(buffer);
    return -1;
  }
  if (go_next) {
    if (n == 0) {
      fprintf(stderr, "pos is at EOF but we need to read a real record.\n");
      free(buffer);
      return -1;
    }
    if (buffer->next == 0) {
      return(new_subkey_tree(fd, column, pos, buffer));
    } else {
      next_pos = buffer->next;
      free(buffer);
      return(keydb_insert(fd, column, next_pos, 0));
    }
  }
  if (n == 0) {
    memcpy(buffer->column, column, (1024 - 2*(sizeof(int)) - sizeof(int64_t)));
    buffer->refcount = 1;
    buffer->pos = pos;
    if (pwrite(fd, buffer, sizeof(struct keydb_node), pos) == -1) {
      perror("pwrite() failed in keydb_insert.");
      free(buffer);
      return -1;
    }
    free(buffer);
    return pos;
  }
  comparison = strcmp(buffer->column, column);
  if (comparison > 0) {
    if (buffer->left != 0) {
      pos = buffer->left;
      free(buffer);
      return keydb_insert(fd, column, pos, 0);
    } else {
      return connect_and_add_node(0, buffer, column, pos, fd);
    }
  } else if (comparison < 0) {
    if (buffer->right != 0) {
      pos = buffer->right;
      free(buffer);
      return keydb_insert(fd, column, pos, 0);
    } else {
      return connect_and_add_node(1, buffer, column, pos, fd);
    }
  } else {
    buffer->refcount++;
    if (pwrite(fd, buffer, sizeof(struct keydb_node), pos) == -1) {
      perror("pwrite() failed in keydb_insert.");
      free(buffer);
      return -1;
    }
    free(buffer);
    return pos;
  }
  return 0;
}

canonical_original_code:
int keydb_insert(int fd, char column[], long pos, _Bool go_next) {
  int n;
  int comparison;
  long next_pos;
  struct keydb_node *buffer;
  if ((buffer = malloc(sizeof(struct keydb_node))) == ((void *)0)) {
    perror("Call to malloc() failed in keydb_insert.");
    return -1;
  }
  bzero(buffer, sizeof(struct keydb_node));
  n = pread(fd, buffer, sizeof(struct keydb_node), pos);
  if (n == -1) {
    perror("pread() failed in keydb_insert.");
    free(buffer);
    return -1;
  }
  if (go_next) {
    if (n == 0) {
      fprintf(stderr, "pos is at EOF but we need to read a real record.\n");
      free(buffer);
      return -1;
    }
    if (buffer->next == 0) {
      return(new_subkey_tree(fd, column, pos, buffer));
    } else {
      next_pos = buffer->next;
      free(buffer);
      return(keydb_insert(fd, column, next_pos, 0));
    }
  }
  if (n == 0) {
    memcpy(buffer->column, column, (1024 - 2*(sizeof(int)) - sizeof(long)));
    buffer->refcount = 1;
    buffer->pos = pos;
    if (pwrite(fd, buffer, sizeof(struct keydb_node), pos) == -1) {
      perror("pwrite() failed in keydb_insert.");
      free(buffer);
      return -1;
    }
    free(buffer);
    return pos;
  }
  comparison = strcmp(buffer->column, column);
  if (comparison > 0) {
    if (buffer->left != 0) {
      pos = buffer->left;
      free(buffer);
      return keydb_insert(fd, column, pos, 0);
    } else {
      return connect_and_add_node(0, buffer, column, pos, fd);
    }
  } else if (comparison < 0) {
    if (buffer->right != 0) {
      pos = buffer->right;
      free(buffer);
      return keydb_insert(fd, column, pos, 0);
    } else {
      return connect_and_add_node(1, buffer, column, pos, fd);
    }
  } else {
    buffer->refcount++;
    if (pwrite(fd, buffer, sizeof(struct keydb_node), pos) == -1) {
      perror("pwrite() failed in keydb_insert.");
      free(buffer);
      return -1;
    }
    free(buffer);
    return pos;
  }
  return 0;
}

variable_types: n int

variable_types: comparison int


decompiled_code:
__int64 __fastcall composite_insert(unsigned int a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // rdi

keydb_lock(0LL);
v3 = (int)keydb_insert(a1, (char *)a2, 0LL, 0);
keydb_unlock(0LL);
if ( v3 == -1 )
return 0xFFFFFFFFLL;
v4 = *(_QWORD *)(a2 + 1016);
if ( !v4 )
return 0LL;
while ( 1 )
{
keydb_lock(v3);
v5 = v3;
v3 = (int)keydb_insert(a1, (char *)v4, v3, 1);
keydb_unlock(v5);
if ( v3 == -1 )
break;
v4 = *(_QWORD *)(v4 + 1016);
if ( !v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, __int64 a2)
{
__int64 v3; // rbx
__int64 v4; // rbp
__int64 v5; // rdi

func0(0LL);
v3 = (int)func10(a1, (char *)a2, 0LL, 0);
func1(0LL);
if ( v3 == -1 )
return 0xFFFFFFFFLL;
v4 = *(_QWORD *)(a2 + 1016);
if ( !v4 )
return 0LL;
while ( 1 )
{
func0(v3);
v5 = v3;
v3 = (int)func10(a1, (char *)v4, v3, 1);
func1(v5);
if ( v3 == -1 )
break;
v4 = *(_QWORD *)(v4 + 1016);
if ( !v4 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int composite_insert(int fd, struct keydb_column *tuple) {
  int64_t pos = 0;
  int64_t previous_pos = 0;
  keydb_lock(pos);
  previous_pos = pos;
  pos = keydb_insert(fd, tuple->column, pos, 0);
  keydb_unlock(previous_pos);
  if (pos == -1) {
    return -1;
  }
  tuple = tuple->next;
  while (tuple) {
    keydb_lock(pos);
    previous_pos = pos;
    pos = keydb_insert(fd, tuple->column, pos, 1);
    keydb_unlock(previous_pos);
    if (pos == -1){
      return -1;
    }
    tuple = tuple->next;
  };
  return 0;
}

canonical_original_code:
int composite_insert(int fd, struct keydb_column *tuple) {
  long pos = 0;
  long previous_pos = 0;
  keydb_lock(pos);
  previous_pos = pos;
  pos = keydb_insert(fd, tuple->column, pos, 0);
  keydb_unlock(previous_pos);
  if (pos == -1) {
    return -1;
  }
  tuple = tuple->next;
  while (tuple) {
    keydb_lock(pos);
    previous_pos = pos;
    pos = keydb_insert(fd, tuple->column, pos, 1);
    keydb_unlock(previous_pos);
    if (pos == -1){
      return -1;
    }
    tuple = tuple->next;
  };
  return 0;
}

user_defined_types: struct keydb_column { char column[-1]; int refcount; struct keydb_column *next; }


decompiled_code:
__int64 __fastcall fnv_32_buf(unsigned __int8 *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned __int8 *v4; // rsi

result = a3;
v4 = &a1[a2];
if ( a1 < v4 )
{
do
result = *a1++ ^ (unsigned int)(16777619 * result);
while ( v4 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
unsigned __int8 *v4; // rsi

result = a3;
v4 = &a1[a2];
if ( a1 < v4 )
{
do
result = *a1++ ^ (unsigned int)(16777619 * result);
while ( v4 != a1 );
}
return result;
}

original_code:
Fnv32_t
fnv_32_buf(void *buf, size_t len, Fnv32_t hval)
{
    unsigned char *bp = (unsigned char *)buf;
    unsigned char *be = bp + len;
    while (bp < be) {
 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
 hval ^= (Fnv32_t)*bp++;
    }
    return hval;
}

canonical_original_code:
unsigned int fnv_32_buf(void *buf, unsigned long len, unsigned int hval)
{
    unsigned char *bp = (unsigned char *)buf;
    unsigned char *be = bp + len;
    while (bp < be) {
 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
 hval ^= (Fnv32_t)*bp++;
    }
    return hval;
}

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types:
hval
unsigned int

variable_types:
bp
unsigned char *

variable_types:
be
unsigned char *

return_type: unsigned int


decompiled_code:
__int64 __fastcall fnv_32_str(unsigned __int8 *a1, unsigned int a2)
{
__int64 result; // rax
unsigned __int8 i; // si

result = a2;
for ( i = *a1; *a1; i = *a1 )
{
++a1;
result = (16777619 * (_DWORD)result) ^ (unsigned int)i;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, unsigned int a2)
{
__int64 result; // rax
unsigned __int8 i; // si

result = a2;
for ( i = *a1; *a1; i = *a1 )
{
++a1;
result = (16777619 * (_DWORD)result) ^ (unsigned int)i;
}
return result;
}

original_code:
Fnv32_t
fnv_32_str(char *str, Fnv32_t hval)
{
    unsigned char *s = (unsigned char *)str;
    while (*s) {
 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
 hval ^= (Fnv32_t)*s++;
    }
    return hval;
}

canonical_original_code:
unsigned int fnv_32_str(char *str, unsigned int hval)
{
    unsigned char *s = (unsigned char *)str;
    while (*s) {
 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
 hval ^= (Fnv32_t)*s++;
    }
    return hval;
}

variable_types:
str
char *

variable_types:
s
unsigned char *


main

repo: rpoisel/feasibility

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = 1;
if ( !pthread_create(newthread, 0LL, reader, 0LL) )
{
puts("Started.");
v3 = pthread_join(newthread[0], 0LL);
if ( v3 )
v3 = 1;
else
puts("Finished.");
}
return v3;
}

original_code:
int main(void)
{
    pthread_t thread_id;
    if (pthread_create(&thread_id, ((void *)0), reader, ((void *)0)) != 0)
    {
        return 1;
    }
    printf("Started.\n");
    if (pthread_join(thread_id, ((void *)0)) != 0)
    {
        return 1;
    }
    printf("Finished.\n");
    return 0;
}

canonical_original_code:
int main()
{
    unsigned long thread_id;
    if (pthread_create(&thread_id, ((void *)0), reader, ((void *)0)) != 0)
    {
        return 1;
    }
    printf("Started.\n");
    if (pthread_join(thread_id, ((void *)0)) != 0)
    {
        return 1;
    }
    printf("Finished.\n");
    return 0;
}


reader

decompiled_code:
void *__fastcall reader(void *a1)
{
puts("Hello Thread.");
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func7(void *a1)
{
puts("Hello Thread.");
return 0LL;
}

original_code:
void* reader(void* thread_params)
{
    printf("Hello Thread.\n");
    return ((void *)0);
}

canonical_original_code:
void *reader(void *thread_params)
{
    printf("Hello Thread.\n");
    return ((void *)0);
}


main

repo: rprata/labprog-uerj

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // rdx
__int64 v5; // r12
__int64 v6; // rdx
__int64 v7; // rbp

v3 = make_point(0LL, 0LL, envp);
v5 = make_point(1LL, 2LL, v4);
v7 = make_point(0LL, 0LL, v6);
if ( (unsigned int)compare_point(v3, v5) )
puts("P1 e P2 sao iguais");
else
puts("P1 e P2 sao diferentes");
if ( (unsigned int)compare_point(v3, v7) )
puts("P1 e P3 sao iguais");
else
puts("P1 e P3 sao diferentes");
return 0;
}

original_code:
int main (int argc, char ** argv)
{
 Point p1 = make_point(0,0);
 Point p2 = make_point(1, 2);
 Point p3 = make_point(0, 0);
 int res = compare_point(p1, p2);
 if (!res)
  printf("P1 e P2 sao diferentes\n");
 else
  printf("P1 e P2 sao iguais\n");
 res = compare_point(p1, p3);
 if (!res)
  printf("P1 e P3 sao diferentes\n");
 else
  printf("P1 e P3 sao iguais\n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 struct Point_st p1 = make_point(0,0);
 struct Point_st p2 = make_point(1, 2);
 struct Point_st p3 = make_point(0, 0);
 int res = compare_point(p1, p2);
 if (!res)
  printf("P1 e P2 sao diferentes\n");
 else
  printf("P1 e P2 sao iguais\n");
 res = compare_point(p1, p3);
 if (!res)
  printf("P1 e P3 sao diferentes\n");
 else
  printf("P1 e P3 sao iguais\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: res int


decompiled_code:
__int64 __fastcall make_point(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2)
{
return (a2 << 32) | a1;
}

original_code:
Point make_point (int x, int y)
{
  Point p;
  p.x = x;
  p.y = y;
  return p;
}

canonical_original_code:
struct Point_st make_point(int x, int y)
{
  struct Point_st p;
  p.x = x;
  p.y = y;
  return p;
}

variable_types: x int

variable_types: y int

variable_types:
p
struct Point_st { int x; int y; }

return_type: struct Point_st { int x; int y; }


decompiled_code:
_BOOL8 __fastcall compare_point(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, __int64 a2)
{
_BOOL8 result; // rax

result = 0LL;
if ( (_DWORD)a1 == (_DWORD)a2 )
result = HIDWORD(a1) == HIDWORD(a2);
return result;
}

original_code:
int compare_point (Point p1, Point p2)
{
  if (p1.x == p2.x && p1.y == p2.y)
    return 1;
  else
    return 0;
}

canonical_original_code:
int compare_point(struct Point_st p1, struct Point_st p2)
{
  if (p1.x == p2.x && p1.y == p2.y)
    return 1;
  else
    return 0;
}


decompiled_code:
__int64 __fastcall add_point(__int64 a1, __int64 a2)
{
return make_point((int)a2 + (int)a1, (unsigned int)(HIDWORD(a2) + HIDWORD(a1)));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
return func0((int)a2 + (int)a1, (unsigned int)(HIDWORD(a2) + HIDWORD(a1)));
}

original_code:
Point add_point (Point p1, Point p2)
{
  return make_point(p1.x + p2.x, p1.y + p2.y);
}

canonical_original_code:
struct Point_st add_point(struct Point_st p1, struct Point_st p2)
{
  return make_point(p1.x + p2.x, p1.y + p2.y);
}


fibonacci

original_code:
unsigned long fibonacci (unsigned int n)
{
  f[0] = 0;
  f[1] = 1;
  for (int i = 2; i <= n; i++)
    f[i] = f[i - 1] + f[i - 2];
   return f[n];
}

canonical_original_code:
unsigned long fibonacci(unsigned int n)
{
  f[0] = 0;
  f[1] = 1;
  for (int i = 2; i <= n; i++)
    f[i] = f[i - 1] + f[i - 2];
   return f[n];
}

variable_types:
n
unsigned int

variable_types: i int

return_type: unsigned long


decompiled_code:
__int64 __fastcall fibonacci_rec(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // rbp

result = a1;
if ( a1 > 1 )
{
v2 = fibonacci(a1 - 1);
result = v2 + fibonacci(a1 - 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // rbp

result = a1;
if ( a1 > 1 )
{
v2 = func3(a1 - 1);
result = v2 + func3(a1 - 2);
}
return result;
}

original_code:
unsigned long fibonacci_rec (unsigned int n)
{
  return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
}

canonical_original_code:
unsigned long fibonacci_rec(unsigned int n)
{
  return n <= 1 ? n : fibonacci(n - 1) + fibonacci(n - 2);
}


swap

decompiled_code:
__int64 __fastcall swap(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap (int * a, int * b)
{
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

canonical_original_code:
void swap(int *a, int *b)
{
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

variable_types:
a
int *

variable_types:
b
int *

variable_types: tmp int


partition

decompiled_code:
__int64 __fastcall partition(__int64 a1, unsigned int a2, int a3)
{
__int64 v3; // rbx
unsigned int v5; // er13

LODWORD(v3) = a2 + 1;
if ( (int)(a2 + 1) > a3 )
{
v5 = a2;
}
else
{
v3 = (int)v3;
v5 = a2;
do
{
if ( *(_DWORD *)(a1 + 4 * v3) < *(_DWORD *)(a1 + 4LL * (int)a2) )
swap((_DWORD *)(a1 + 4LL * (int)++v5), (_DWORD *)(a1 + 4 * v3));
++v3;
}
while ( a3 >= (int)v3 );
}
swap((_DWORD *)(a1 + 4LL * (int)a2), (_DWORD *)(a1 + 4LL * (int)v5));
return v5;
}

original_code:
int partition (int vec[], int left, int right)
{
  int i, j;
  i = left;
  for (j = left + 1; j <= right; ++j) {
    if (vec[j] < vec[left]) {
      ++i;
      swap(&vec[i], &vec[j]);
    }
  }
  swap(&vec[left], &vec[i]);
  return i;
}

canonical_original_code:
int partition(int vec[], int left, int right)
{
  int i; int j;
  i = left;
  for (j = left + 1; j <= right; ++j) {
    if (vec[j] < vec[left]) {
      ++i;
      swap(&vec[i], &vec[j]);
    }
  }
  swap(&vec[left], &vec[i]);
  return i;
}

variable_types:
vec
int []

variable_types: left int

variable_types: right int

variable_types: j int


decompiled_code:
__int64 __fastcall binary_search(__int64 a1, int a2, __int64 a3, __int64 a4)
{
unsigned int v5; // esi
unsigned int v6; // er8
int v7; // er9

if ( (int)a3 < a2 )
return 0xFFFFFFFFLL;
v5 = ((int)a3 + a2) / 2;
v6 = v5;
v7 = *(_DWORD *)(a1 + 4LL * (int)v5);
if ( v7 > (int)a4 )
return (unsigned int)binary_search(a1, (unsigned int)a2, v5 - 1, a4, v5);
if ( v7 < (int)a4 )
v6 = binary_search(a1, v5 + 1, a3, a4, v5);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, __int64 a3, __int64 a4)
{
unsigned int v5; // esi
unsigned int v6; // er8
int v7; // er9

if ( (int)a3 < a2 )
return 0xFFFFFFFFLL;
v5 = ((int)a3 + a2) / 2;
v6 = v5;
v7 = *(_DWORD *)(a1 + 4LL * (int)v5);
if ( v7 > (int)a4 )
return (unsigned int)func7(a1, (unsigned int)a2, v5 - 1, a4, v5);
if ( v7 < (int)a4 )
v6 = func7(a1, v5 + 1, a3, a4, v5);
return v6;
}

original_code:
int binary_search(int a[], int low, int high, int target)
{
    if (high < low)
        return -1;
    int middle = (low + high)/2;
    if (target < a[middle])
        return binary_search(a, low, middle-1, target);
    else if (target > a[middle])
        return binary_search(a, middle+1, high, target);
    else
        return middle;
}

variable_types:
a
int []

variable_types: low int

variable_types: high int

variable_types: target int

variable_types: middle int


decompiled_code:
void __fastcall quick_sort(__int64 a1, unsigned int a2, int a3)
{
int v4; // ebp

if ( a3 > (int)a2 )
{
v4 = partition(a1, a2, a3);
quick_sort(a1, a2, (unsigned int)(v4 - 1));
quick_sort(a1, (unsigned int)(v4 + 1), (unsigned int)a3);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, unsigned int a2, int a3)
{
int v4; // ebp

if ( a3 > (int)a2 )
{
v4 = func6(a1, a2, a3);
func8(a1, a2, (unsigned int)(v4 - 1));
func8(a1, (unsigned int)(v4 + 1), (unsigned int)a3);
}
}

original_code:
void quick_sort (int vec[], int left, int right)
{
 int r;
   if (right > left)
   {
     r = partition(vec, left, right);
     quick_sort(vec, left, r - 1);
     quick_sort(vec, r + 1, right);
   }
}

canonical_original_code:
void quick_sort(int vec[], int left, int right)
{
 int r;
   if (right > left)
   {
     r = partition(vec, left, right);
     quick_sort(vec, left, r - 1);
     quick_sort(vec, r + 1, right);
   }
}

variable_types: r int


decompiled_code:
__int64 __fastcall bubble_sort(_DWORD *a1, int a2)
{
_DWORD *v2; // r12
_DWORD *v3; // rbx
__int64 v4; // r13
_DWORD *v5; // rdi
__int64 result; // rax

if ( a2 > 0 )
{
v2 = a1;
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
v5 = v3++;
if ( *v5 > v5[1] )
swap(v5, v3);
}
while ( (_DWORD *)v4 != v3 );
result = bubble_sort(v2, (unsigned int)(a2 - 1));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, int a2)
{
_DWORD *v2; // r12
_DWORD *v3; // rbx
__int64 v4; // r13
_DWORD *v5; // rdi
__int64 result; // rax

if ( a2 > 0 )
{
v2 = a1;
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
do
{
v5 = v3++;
if ( *v5 > v5[1] )
func5(v5, v3);
}
while ( (_DWORD *)v4 != v3 );
result = func9(v2, (unsigned int)(a2 - 1));
}
return result;
}

original_code:
void bubble_sort(int vec[], int length)
{
  int i;
  if(length > 0)
  {
    for(i = 0; i < length; i++)
    {
      int first = vec[i];
      int second = vec[i + 1];
      if(second < first)
      {
        swap(&vec[i], &vec[i + 1]);
      }
    }
    bubble_sort(vec,length - 1);
  }
}

variable_types: length int

variable_types: first int

variable_types: second int


decompiled_code:
unsigned __int64 __fastcall shell_sort(_DWORD *a1, int a2)
{
int v4; // esi
int v5; // er13
_DWORD *v6; // rbx
int v7; // edi
int v8; // edx
unsigned __int64 result; // rax
int v10; // er11
int v11; // ebp
__int64 v12; // r8

v4 = 1;
do
v4 = 3 * v4 + 1;
while ( v4 < a2 );
do
{
v10 = v4;
result = (unsigned int)(v4 / 3);
v4 = result;
if ( a2 > (int)result )
{
v6 = a1;
v11 = a2 - result;
v12 = 4LL * -(int)result;
v5 = 0;
do
{
v7 = v6[v4];
v8 = v5;
for ( result = (unsigned __int64)v6; v8 >= 0; v8 -= v4 )
{
if ( *(_DWORD *)result <= v7 )
break;
*(_DWORD *)(result + 4LL * v4) = *(_DWORD *)result;
result += v12;
}
a1[v4 + v8] = v7;
++v5;
++v6;
}
while ( v5 != v11 );
}
}
while ( v10 > 5 );
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(_DWORD *a1, int a2)
{
int v4; // esi
int v5; // er13
_DWORD *v6; // rbx
int v7; // edi
int v8; // edx
unsigned __int64 result; // rax
int v10; // er11
int v11; // ebp
__int64 v12; // r8

v4 = 1;
do
v4 = 3 * v4 + 1;
while ( v4 < a2 );
do
{
v10 = v4;
result = (unsigned int)(v4 / 3);
v4 = result;
if ( a2 > (int)result )
{
v6 = a1;
v11 = a2 - result;
v12 = 4LL * -(int)result;
v5 = 0;
do
{
v7 = v6[v4];
v8 = v5;
for ( result = (unsigned __int64)v6; v8 >= 0; v8 -= v4 )
{
if ( *(_DWORD *)result <= v7 )
break;
*(_DWORD *)(result + 4LL * v4) = *(_DWORD *)result;
result += v12;
}
a1[v4 + v8] = v7;
++v5;
++v6;
}
while ( v5 != v11 );
}
}
while ( v10 > 5 );
return result;
}

original_code:
void shell_sort (int vec[], int length)
{
    int i , j , value;
    int gap = 1;
    do
    {
        gap = 3*gap+1;
    } while(gap < length);
    do
    {
        gap /= 3;
        for(i = gap; i < length; i++)
        {
            value = vec[i];
            j = i - gap;
            while (j >= 0 && value < vec[j])
            {
                vec [j + gap] = vec[j];
                j -= gap;
            }
            vec [j + gap] = value;
        }
    } while ( gap > 1);
}

canonical_original_code:
void shell_sort(int vec[], int length)
{
    int i; int j; int value;
    int gap = 1;
    do
    {
        gap = 3*gap+1;
    } while(gap < length);
    do
    {
        gap /= 3;
        for(i = gap; i < length; i++)
        {
            value = vec[i];
            j = i - gap;
            while (j >= 0 && value < vec[j])
            {
                vec [j + gap] = vec[j];
                j -= gap;
            }
            vec [j + gap] = value;
        }
    } while ( gap > 1);
}

variable_types: i int

variable_types: value int

variable_types: gap int


isTreeEmpty

decompiled_code:
bool __fastcall isTreeEmpty(__int64 a1)
{
return a1 != 0;
}

canonical_decompiled_code:
bool __fastcall func8(__int64 a1)
{
return a1 != 0;
}

original_code:
_Bool isTreeEmpty ( BinaryTree aTree )
{
  _Bool returnValue = 0;
  if(aTree != ((void *)0)) {
    returnValue = 1;
  }
  return returnValue;
}

canonical_original_code:
_Bool isTreeEmpty(struct treeNode *aTree)
{
  _Bool returnValue = 0;
  if(aTree != ((void *)0)) {
    returnValue = 1;
  }
  return returnValue;
}

variable_types: struct treeNode { int data; struct treeNode *left; struct treeNode *right; } *


isTreeFull

decompiled_code:
bool isTreeFull()
{
void *v0; // rbx

v0 = malloc(8uLL);
free(v0);
return v0 == 0LL;
}

canonical_decompiled_code:
bool func9()
{
void *v0; // rbx

v0 = malloc(8uLL);
free(v0);
return v0 == 0LL;
}

original_code:
_Bool isTreeFull ( BinaryTree aTree )
{
  _Bool returnValue = 1;
  BinaryTree temp = ((void *)0);
  temp = (BinaryTree) malloc(sizeof(BinaryTree));
  if(temp != ((void *)0)) {
    returnValue = 0;
  }
  free(temp);
  return returnValue;
}

canonical_original_code:
_Bool isTreeFull(struct treeNode *aTree)
{
  _Bool returnValue = 1;
  struct treeNode *temp = ((void *)0);
  temp = (struct treeNode *) malloc(sizeof(BinaryTree));
  if(temp != ((void *)0)) {
    returnValue = 0;
  }
  free(temp);
  return returnValue;
}

user_defined_types: struct treeNode { int data; struct treeNode *left; struct treeNode *right; }


deleteFromTree

decompiled_code:
void __fastcall deleteFromTree(_QWORD **a1, int a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rdx

v2 = *a1;
if ( *a1 && *(_DWORD *)v2 == a2 )
{
v3 = (_QWORD *)v2[2];
if ( v3 )
{
if ( v2[1] )
return;
}
else
{
v3 = (_QWORD *)v2[1];
if ( !v3 )
{
*a1 = 0LL;
free(v2);
return;
}
}
*a1 = v3;
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func10(_QWORD **a1, int a2)
{
_QWORD *v2; // rax
_QWORD *v3; // rdx

v2 = *a1;
if ( *a1 && *(_DWORD *)v2 == a2 )
{
v3 = (_QWORD *)v2[2];
if ( v3 )
{
if ( v2[1] )
return;
}
else
{
v3 = (_QWORD *)v2[1];
if ( !v3 )
{
*a1 = 0LL;
free(v2);
return;
}
}
*a1 = v3;
free(v2);
}
}

original_code:
void deleteFromTree ( BinaryTree *aTree, int data )
{
  BinaryTree tempNode = ( *aTree );
  if ( tempNode != ((void *)0) )
    {
      if ( tempNode->data == data )
        {
          if ( tempNode->right != ((void *)0) )
            {
              if ( tempNode->left == ((void *)0) )
                {
                  ( *aTree ) = ( *aTree )->right;
                  free ( tempNode );
                  tempNode = ((void *)0);
                }
              else
                {
                }
            }
          else
            {
              if ( tempNode->left != ((void *)0) )
                {
                  ( *aTree ) = ( *aTree )->left;
                  free ( tempNode );
                  tempNode = ((void *)0);
                }
              else
                {
                  ( *aTree ) = ((void *)0);
                  free ( tempNode );
                  tempNode = ((void *)0);
                }
            }
        }
    }
}

canonical_original_code:
void deleteFromTree(struct treeNode **aTree, int data)
{
  struct treeNode *tempNode = ( *aTree );
  if ( tempNode != ((void *)0) )
    {
      if ( tempNode->data == data )
        {
          if ( tempNode->right != ((void *)0) )
            {
              if ( tempNode->left == ((void *)0) )
                {
                  ( *aTree ) = ( *aTree )->right;
                  free ( tempNode );
                  tempNode = ((void *)0);
                }
              else
                {
                }
            }
          else
            {
              if ( tempNode->left != ((void *)0) )
                {
                  ( *aTree ) = ( *aTree )->left;
                  free ( tempNode );
                  tempNode = ((void *)0);
                }
              else
                {
                  ( *aTree ) = ((void *)0);
                  free ( tempNode );
                  tempNode = ((void *)0);
                }
            }
        }
    }
}

variable_types: struct treeNode { int data; struct treeNode *left; struct treeNode *right; } **

variable_types: data int


printTree

decompiled_code:
void printTree()
{
;
}

canonical_decompiled_code:
void func11()
{
;
}

original_code:
void printTree ( BinaryTree* aTree )
{
}

canonical_original_code:
void printTree(struct treeNode **aTree)
{
}


emptyTree

decompiled_code:
void __fastcall emptyTree(__int64 a1)
{
_QWORD *v1; // rbx

v1 = *(_QWORD **)a1;
if ( *(_QWORD *)(*(_QWORD *)a1 + 8LL) )
emptyTree(v1 + 1);
if ( v1[2] )
emptyTree(v1 + 2);
free(v1);
}

original_code:
void emptyTree ( BinaryTree* aTree )
{
  BinaryTree temp = *aTree;
  if(temp->left != ((void *)0)) {
    emptyTree(&(temp->left));
  }
  if(temp->right != ((void *)0)) {
    emptyTree(&(temp->right));
  }
  aTree = ((void *)0);
  free(temp);
}

canonical_original_code:
void emptyTree(struct treeNode **aTree)
{
  struct treeNode *temp = *aTree;
  if(temp->left != ((void *)0)) {
    emptyTree(&(temp->left));
  }
  if(temp->right != ((void *)0)) {
    emptyTree(&(temp->right));
  }
  aTree = ((void *)0);
  free(temp);
}


takeFromTree

decompiled_code:
__int64 takeFromTree()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
return 0LL;
}

original_code:
int takeFromTree ( BinaryTree* aTree, int data )
{
  int returnValue = 0;
  return returnValue;
}

canonical_original_code:
int takeFromTree(struct treeNode **aTree, int data)
{
  int returnValue = 0;
  return returnValue;
}

variable_types: returnValue int


popStack

decompiled_code:
__int64 __fastcall popStack(unsigned int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // ebx

v1 = *a1;
v2 = **a1;
*a1 = (unsigned int *)*((_QWORD *)*a1 + 1);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // ebx

v1 = *a1;
v2 = **a1;
*a1 = (unsigned int *)*((_QWORD *)*a1 + 1);
free(v1);
return v2;
}

original_code:
int popStack(stackNode *pointerToAStack) {
  stackNode tempNode = *pointerToAStack;
  int tempData = (*pointerToAStack)->data;
  *pointerToAStack = (*pointerToAStack)->next;
  free(tempNode);
  tempNode = ((void *)0);
  return tempData;
}

canonical_original_code:
int popStack(struct aNode **pointerToAStack) {
  struct aNode *tempNode = *pointerToAStack;
  int tempData = (*pointerToAStack)->data;
  *pointerToAStack = (*pointerToAStack)->next;
  free(tempNode);
  tempNode = ((void *)0);
  return tempData;
}

variable_types: struct aNode { int data; struct aNode *next; } **

variable_types: tempData int


isStackEmpty

decompiled_code:
bool __fastcall isStackEmpty(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
bool __fastcall func9(__int64 a1)
{
return a1 == 0;
}

original_code:
_Bool isStackEmpty(stackNode stack) {
  if(stack == ((void *)0)) {
    return 1;
  } else {
    return 0;
  }
}

canonical_original_code:
_Bool isStackEmpty(struct aNode *stack) {
  if(stack == ((void *)0)) {
    return 1;
  } else {
    return 0;
  }
}

variable_types: struct aNode { int data; struct aNode *next; } *


isStackFull

decompiled_code:
bool isStackFull()
{
void *v0; // rbx

v0 = malloc(0x10uLL);
free(v0);
return v0 == 0LL;
}

canonical_decompiled_code:
bool func10()
{
void *v0; // rbx

v0 = malloc(0x10uLL);
free(v0);
return v0 == 0LL;
}

original_code:
_Bool isStackFull(stackNode stack) {
  stackNode tempNode = (struct aNode *) malloc(sizeof(struct aNode));
  _Bool returnValue = 0;
  if(tempNode == ((void *)0)) {
    returnValue = 1;
  }
  free(tempNode);
  return returnValue;
}

canonical_original_code:
_Bool isStackFull(struct aNode *stack) {
  struct aNode *tempNode = (struct aNode *) malloc(sizeof(struct aNode));
  _Bool returnValue = 0;
  if(tempNode == ((void *)0)) {
    returnValue = 1;
  }
  free(tempNode);
  return returnValue;
}

user_defined_types: struct aNode { int data; struct aNode *next; }


listStack

decompiled_code:
bool __fastcall listStack(unsigned int *a1)
{
bool result; // al

while ( 1 )
{
result = isStackEmpty((__int64)a1);
if ( result )
break;
printf("Node: %p\nData: %i\n", a1, *a1);
a1 = (unsigned int *)*((_QWORD *)a1 + 1);
}
return result;
}

canonical_decompiled_code:
bool __fastcall func11(unsigned int *a1)
{
bool result; // al

while ( 1 )
{
result = func9((__int64)a1);
if ( result )
break;
printf("Node: %p\nData: %i\n", a1, *a1);
a1 = (unsigned int *)*((_QWORD *)a1 + 1);
}
return result;
}

original_code:
void listStack(stackNode stack) {
  stackNode currentNode = stack;
  while(!isStackEmpty(currentNode)) {
    printf("Node: %p\nData: %i\n",
    (void*) currentNode, currentNode->data);
    currentNode = currentNode->next;
  }
}

canonical_original_code:
void listStack(struct aNode *stack) {
  struct aNode *currentNode = stack;
  while(!isStackEmpty(currentNode)) {
    printf("Node: %p\nData: %i\n",
    (void *) currentNode, currentNode->data);
    currentNode = currentNode->next;
  }
}


emptyStack

decompiled_code:
bool __fastcall emptyStack(_QWORD **a1)
{
_QWORD *i; // rbx
_QWORD *v2; // rbp
bool result; // al

for ( i = *a1; ; i = v2 )
{
result = isStackEmpty((__int64)i);
if ( !result )
break;
v2 = (_QWORD *)i[1];
free(i);
}
return result;
}

canonical_decompiled_code:
bool __fastcall func12(_QWORD **a1)
{
_QWORD *i; // rbx
_QWORD *v2; // rbp
bool result; // al

for ( i = *a1; ; i = v2 )
{
result = func9((__int64)i);
if ( !result )
break;
v2 = (_QWORD *)i[1];
free(i);
}
return result;
}

original_code:
void emptyStack(stackNode *pointerToAStack) {
  stackNode currentNode = *pointerToAStack;
  while(isStackEmpty(currentNode)) {
    stackNode tempNode = currentNode;
    currentNode = currentNode->next;
    free(tempNode);
  }
}

canonical_original_code:
void emptyStack(struct aNode **pointerToAStack) {
  struct aNode *currentNode = *pointerToAStack;
  while(isStackEmpty(currentNode)) {
    struct aNode *tempNode = currentNode;
    currentNode = currentNode->next;
    free(tempNode);
  }
}


printrandoms

decompiled_code:
int __fastcall printrandoms(__int64 a1, __int64 a2)
{
__int64 i; // rbx
int result; // eax

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
result = printf("%015lu\n", *(_QWORD *)(a1 + 8 * i));
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2)
{
__int64 i; // rbx
int result; // eax

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
result = printf("%015lu\n", *(_QWORD *)(a1 + 8 * i));
}
return result;
}

original_code:
void printrandoms(size_t numbers[], size_t HowManyNumbers) {
  size_t counter = 0;
  for( ; counter < HowManyNumbers; ++counter) {
    printf("%015lu\n", numbers[counter]);
  }
}

canonical_original_code:
void printrandoms(unsigned long numbers[], unsigned long HowManyNumbers) {
  unsigned long counter = 0;
  for( ; counter < HowManyNumbers; ++counter) {
    printf("%015lu\n", numbers[counter]);
  }
}

variable_types:
numbers
unsigned long []

variable_types:
HowManyNumbers
unsigned long

variable_types:
counter
unsigned long


minimum

decompiled_code:
unsigned __int64 __fastcall minimum(__int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rax

if ( a2 < a3 )
{
v3 = a2;
do
{
if ( *(_QWORD *)(a1 + 8 * v3) < *(_QWORD *)(a1 + 8 * a2) )
a2 = v3;
++v3;
}
while ( a3 != v3 );
}
return a2;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func9(__int64 a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rax

if ( a2 < a3 )
{
v3 = a2;
do
{
if ( *(_QWORD *)(a1 + 8 * v3) < *(_QWORD *)(a1 + 8 * a2) )
a2 = v3;
++v3;
}
while ( a3 != v3 );
}
return a2;
}

original_code:
size_t minimum(size_t numbers[], size_t start, size_t HowManyNumbers) {
  size_t indexOfSmallest = start;
  size_t counter = 0;
  for(counter = start; counter < HowManyNumbers; ++counter) {
    if(numbers[counter] < numbers[indexOfSmallest]) {
      indexOfSmallest = counter;
    }
  }
  return indexOfSmallest;
}

canonical_original_code:
unsigned long minimum(unsigned long numbers[], unsigned long start, unsigned long HowManyNumbers) {
  unsigned long indexOfSmallest = start;
  unsigned long counter = 0;
  for(counter = start; counter < HowManyNumbers; ++counter) {
    if(numbers[counter] < numbers[indexOfSmallest]) {
      indexOfSmallest = counter;
    }
  }
  return indexOfSmallest;
}

variable_types:
start
unsigned long

variable_types:
indexOfSmallest
unsigned long


sort

original_code:
void sort(size_t numbers[], size_t HowManyNumbers) {
  size_t counter = 0;
  size_t temporary = 0;
  for(; counter < HowManyNumbers; ++counter) {
    size_t swapwith = minimum(numbers, counter, HowManyNumbers);
    temporary = numbers[swapwith];
    numbers[swapwith] = numbers[counter];
    numbers[counter] = temporary;
  }
}

canonical_original_code:
void sort(unsigned long numbers[], unsigned long HowManyNumbers) {
  unsigned long counter = 0;
  unsigned long temporary = 0;
  for(; counter < HowManyNumbers; ++counter) {
    unsigned long swapwith = minimum(numbers, counter, HowManyNumbers);
    temporary = numbers[swapwith];
    numbers[swapwith] = numbers[counter];
    numbers[counter] = temporary;
  }
}

variable_types:
temporary
unsigned long

variable_types:
swapwith
unsigned long


decompiled_code:
char __fastcall satisfy_constraints(int a1, __int64 a2, _DWORD *a3)
{
int v3; // eax
int v5; // edx
int v6; // edx
int v7; // edx
int v8; // edx

if ( a1 == 4 )
{
v5 = __isoc99_sscanf();
LOBYTE(v3) = 0;
if ( v5 != -1 )
{
v6 = __isoc99_sscanf();
LOBYTE(v3) = 0;
if ( v6 != -1 )
{
v7 = __isoc99_sscanf();
LOBYTE(v3) = 0;
if ( v7 != -1 )
{
v8 = a3[1];
if ( *a3 >= v8 )
{
LOBYTE(v3) = 0;
if ( *a3 > v8 )
v3 = a3[2] >> 31;
}
else
{
LOBYTE(v3) = a3[2] > 0;
}
}
}
}
}
else
{
fwrite("table requires three arguments: ", 1uLL, 0x20uLL, stderr);
fwrite("\"the starting bound\" \"the ending bound\" ", 1uLL, 0x28uLL, stderr);
fwrite("\"and the increment\"\n", 1uLL, 0x14uLL, stderr);
LOBYTE(v3) = 0;
}
return v3;
}

canonical_decompiled_code:
char __fastcall func7(int a1, __int64 a2, _DWORD *a3)
{
int v3; // eax
int v5; // edx
int v6; // edx
int v7; // edx
int v8; // edx

if ( a1 == 4 )
{
v5 = __isoc99_sscanf();
LOBYTE(v3) = 0;
if ( v5 != -1 )
{
v6 = __isoc99_sscanf();
LOBYTE(v3) = 0;
if ( v6 != -1 )
{
v7 = __isoc99_sscanf();
LOBYTE(v3) = 0;
if ( v7 != -1 )
{
v8 = a3[1];
if ( *a3 >= v8 )
{
LOBYTE(v3) = 0;
if ( *a3 > v8 )
v3 = a3[2] >> 31;
}
else
{
LOBYTE(v3) = a3[2] > 0;
}
}
}
}
}
else
{
fwrite("table requires three arguments: ", 1uLL, 0x20uLL, stderr);
fwrite("\"the starting bound\" \"the ending bound\" ", 1uLL, 0x28uLL, stderr);
fwrite("\"and the increment\"\n", 1uLL, 0x14uLL, stderr);
LOBYTE(v3) = 0;
}
return v3;
}

original_code:
_Bool satisfy_constraints(int argcount, char *arguments[],
         struct bounds_struct *bounds) {
  _Bool return_value = 0;
  if(argcount == NUMBER_OF_ARGUMENTS) {
    if((sscanf(arguments[1], "%d", &bounds->starting) != (-1)) &&
       (sscanf(arguments[2], "%d", &bounds->ending) != (-1)) &&
       (sscanf(arguments[3], "%d", &bounds->increment) != (-1))) {
      if((((bounds->starting < bounds->ending) && (bounds->increment > 0))) ||
  ((bounds->starting > bounds->ending) && (bounds->increment < 0))) {
 return_value = 1;
      }
    }
  } else {
    fprintf(stderr, "table requires three arguments: ");
    fprintf(stderr, "\"the starting bound\" \"the ending bound\" ");
    fprintf(stderr, "\"and the increment\"\n");
  }
  return return_value;
}

variable_types: argcount int

variable_types:
arguments
char *[]

variable_types: struct bounds_struct { int starting; int ending; int increment; } *


decompiled_code:
int __fastcall table_generator(__int64 a1, int a2)
{
int v2; // ebx
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8
char format[33]; // [rsp+10h] [rbp-48h] BYREF
char v13[39]; // [rsp+31h] [rbp-27h] BYREF

v2 = a1;
strcpy(v13, "%d & %.4f \\\\ \n");
strcpy(format, "%d & %.4f$\\imath$ \\\\ \n");
puts("\\begin{tabular}{l|l}");
puts("Number & Square Root \\\\ \\hline");
if ( (int)a1 >= SHIDWORD(a1) )
{
do
{
if ( v2 < 0 )
{
v7 = (double)(int)abs32(v2);
if ( v7 < 0.0 )
v8 = sqrt(v7);
else
v8 = sqrt(v7);
printf(format, (unsigned int)v2, v8);
}
else
{
v10 = (double)v2;
if ( (double)v2 < 0.0 )
v9 = sqrt(v10);
else
v9 = sqrt(v10);
printf(v13, (unsigned int)v2, v9);
}
v2 += a2;
}
while ( v2 >= SHIDWORD(a1) );
}
else
{
do
{
if ( v2 < 0 )
{
v3 = (double)(int)abs32(v2);
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
printf(format, (unsigned int)v2, v4);
}
else
{
v6 = (double)v2;
if ( (double)v2 < 0.0 )
v5 = sqrt(v6);
else
v5 = sqrt(v6);
printf(v13, (unsigned int)v2, v5);
}
v2 += a2;
}
while ( v2 <= SHIDWORD(a1) );
}
return puts("\\end{tabular}");
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, int a2)
{
int v2; // ebx
double v3; // xmm0_8
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm0_8
double v7; // xmm0_8
double v8; // xmm0_8
double v9; // xmm0_8
double v10; // xmm0_8
char format[33]; // [rsp+10h] [rbp-48h] BYREF
char v13[39]; // [rsp+31h] [rbp-27h] BYREF

v2 = a1;
strcpy(v13, "%d & %.4f \\\\ \n");
strcpy(format, "%d & %.4f$\\imath$ \\\\ \n");
puts("\\begin{tabular}{l|l}");
puts("Number & Square Root \\\\ \\hline");
if ( (int)a1 >= SHIDWORD(a1) )
{
do
{
if ( v2 < 0 )
{
v7 = (double)(int)abs32(v2);
if ( v7 < 0.0 )
v8 = sqrt(v7);
else
v8 = sqrt(v7);
printf(format, (unsigned int)v2, v8);
}
else
{
v10 = (double)v2;
if ( (double)v2 < 0.0 )
v9 = sqrt(v10);
else
v9 = sqrt(v10);
printf(v13, (unsigned int)v2, v9);
}
v2 += a2;
}
while ( v2 >= SHIDWORD(a1) );
}
else
{
do
{
if ( v2 < 0 )
{
v3 = (double)(int)abs32(v2);
if ( v3 < 0.0 )
v4 = sqrt(v3);
else
v4 = sqrt(v3);
printf(format, (unsigned int)v2, v4);
}
else
{
v6 = (double)v2;
if ( (double)v2 < 0.0 )
v5 = sqrt(v6);
else
v5 = sqrt(v6);
printf(v13, (unsigned int)v2, v5);
}
v2 += a2;
}
while ( v2 <= SHIDWORD(a1) );
}
return puts("\\end{tabular}");
}

original_code:
void table_generator(struct bounds_struct bounds) {
  int counter;
  double result;
  char normal_format_string[] = "%d & %.4f \\\\ \n";
  char imaginary_format_string[] = "%d & %.4f$\\imath$ \\\\ \n";
  printf("\\begin{tabular}{l|l}\n");
  printf("Number & Square Root \\\\ \\hline\n");
  if(bounds.starting < bounds.ending) {
    counter = bounds.starting;
    while(counter <= bounds.ending) {
      if(counter < 0) {
 result = sqrt(abs(counter));
 printf(imaginary_format_string, counter, result);
      } else {
 result = sqrt(counter);
 printf(normal_format_string, counter, result);
      }
      counter += bounds.increment;
    }
  } else {
    counter = bounds.starting;
    while(counter >= bounds.ending) {
      if(counter < 0) {
 result = sqrt(abs(counter));
 printf(imaginary_format_string, counter, result);
      } else {
 result = sqrt(counter);
 printf(normal_format_string, counter, result);
      }
      counter += bounds.increment;
    }
  }
  printf("\\end{tabular}\n");
}

variable_types: struct bounds_struct { int starting; int ending; int increment; }

variable_types: counter int

variable_types: result double


SolveLinear

decompiled_code:
int __fastcall SolveLinear(float a1, float a2)
{
if ( a1 != 0.0 )
return printf("%f\n", (float)((float)-a2 / a1));
if ( a2 == 0.0 )
return puts("Infinitely many solutions");
return puts("Pure absurdity");
}

canonical_decompiled_code:
int __fastcall func7(float a1, float a2)
{
if ( a1 != 0.0 )
return printf("%f\n", (float)((float)-a2 / a1));
if ( a2 == 0.0 )
return puts("Infinitely many solutions");
return puts("Pure absurdity");
}

original_code:
void SolveLinear(float b, float c) {
  if(b == 0.0) {
    if(c != 0.0) {
      printf("Pure absurdity\n");
    } else {
      printf("Infinitely many solutions\n");
    }
  } else {
    printf("%f\n", -c/b);
  }
}

variable_types: b float

variable_types: c float


SolveQuadratic

decompiled_code:
__int64 __fastcall SolveQuadratic(float a1, float a2, float a3)
{
__int64 result; // rax

if ( (float)((float)(a2 * a2) - (float)((float)(a1 * 4.0) * a3)) < 0.0 )
result = SolveComplex();
else
result = SolveReal();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(float a1, float a2, float a3)
{
__int64 result; // rax

if ( (float)((float)(a2 * a2) - (float)((float)(a1 * 4.0) * a3)) < 0.0 )
result = func9();
else
result = func10();
return result;
}

original_code:
void SolveQuadratic(float a, float b, float c) {
  if((powf(b,2.0)-4*a*c) < 0) {
    SolveComplex(a, b, c);
  } else {
    SolveReal(a, b, c);
  }
}

variable_types: a float


SolveComplex

original_code:
void SolveComplex(float a, float b, float c) {
  printf("%f+%f*i and ", -b/(2*a), sqrtf(-1*(powf(b,2.0)-4*a*c))/(2*a));
  printf("%f-%f*i\n", -b/(2*a), sqrtf(-1*(powf(b,2.0)-4*a*c))/(2*a));
}


SolveReal

decompiled_code:
int __fastcall SolveReal(float a1, float a2, float a3)
{
float v3; // xmm3_4
float v4; // xmm1_4
float v5; // xmm0_4
float v7; // xmm0_4
float v8; // [rsp+8h] [rbp-10h]

v8 = a1 + a1;
v3 = (float)-a2 / (float)(a1 + a1);
v4 = (float)(a2 * a2) - (float)((float)(a1 * 4.0) * a3);
if ( v4 < 0.0 )
{
v7 = sqrtf(v4);
printf("%f and ", (float)((float)(v7 / v8) + v3));
if ( v4 < 0.0 )
{
v5 = sqrtf(v4);
return printf("%f\n", (float)(v3 - (float)(v5 / v8)));
}
}
else
{
printf("%f and ", (float)((float)(fsqrt(v4) / (float)(a1 + a1)) + v3));
}
v5 = fsqrt(v4);
return printf("%f\n", (float)(v3 - (float)(v5 / v8)));
}

canonical_decompiled_code:
int __fastcall func10(float a1, float a2, float a3)
{
float v3; // xmm3_4
float v4; // xmm1_4
float v5; // xmm0_4
float v7; // xmm0_4
float v8; // [rsp+8h] [rbp-10h]

v8 = a1 + a1;
v3 = (float)-a2 / (float)(a1 + a1);
v4 = (float)(a2 * a2) - (float)((float)(a1 * 4.0) * a3);
if ( v4 < 0.0 )
{
v7 = sqrtf(v4);
printf("%f and ", (float)((float)(v7 / v8) + v3));
if ( v4 < 0.0 )
{
v5 = sqrtf(v4);
return printf("%f\n", (float)(v3 - (float)(v5 / v8)));
}
}
else
{
printf("%f and ", (float)((float)(fsqrt(v4) / (float)(a1 + a1)) + v3));
}
v5 = fsqrt(v4);
return printf("%f\n", (float)(v3 - (float)(v5 / v8)));
}

original_code:
void SolveReal(float a, float b, float c) {
  printf("%f and ", -b/(2*a)+sqrtf(powf(b,2.0)-4*a*c)/(2*a));
  printf("%f\n", -b/(2*a)-sqrtf(powf(b,2.0)-4*a*c)/(2*a));
}


takeFromQueue

decompiled_code:
__int64 __fastcall takeFromQueue(unsigned int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // ebx
unsigned int *v3; // rdx

v1 = *a1;
v2 = **a1;
v3 = (unsigned int *)*((_QWORD *)*a1 + 1);
*a1 = v3;
if ( !v3 )
a1[1] = 0LL;
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int **a1)
{
unsigned int *v1; // rax
unsigned int v2; // ebx
unsigned int *v3; // rdx

v1 = *a1;
v2 = **a1;
v3 = (unsigned int *)*((_QWORD *)*a1 + 1);
*a1 = v3;
if ( !v3 )
a1[1] = 0LL;
free(v1);
return v2;
}

original_code:
int takeFromQueue(queue aQueue) {
  int data;
  queueNode temp = aQueue->first;
  data = aQueue->first->data;
  aQueue->first = aQueue->first->next;
  if(aQueue->first == ((void *)0)) {
    aQueue->last = ((void *)0);
  }
  free(temp);
  return data;
}

canonical_original_code:
int takeFromQueue(struct queueStruct *aQueue) {
  int data;
  struct aNode *temp = aQueue->first;
  data = aQueue->first->data;
  aQueue->first = aQueue->first->next;
  if(aQueue->first == ((void *)0)) {
    aQueue->last = ((void *)0);
  }
  free(temp);
  return data;
}

variable_types: struct queueStruct { struct aNode { int data; struct aNode *next; } *first; struct aNode *last; } *

variable_types: data int

user_defined_types: struct queueStruct { struct aNode *first; struct aNode *last; }


isQueueEmpty

decompiled_code:
bool __fastcall isQueueEmpty(_QWORD *a1)
{
bool result; // al

result = 0;
if ( !a1[1] )
result = *a1 == 0LL;
return result;
}

canonical_decompiled_code:
bool __fastcall func8(_QWORD *a1)
{
bool result; // al

result = 0;
if ( !a1[1] )
result = *a1 == 0LL;
return result;
}

original_code:
_Bool isQueueEmpty(queue aQueue) {
  _Bool result = 0;
  if(aQueue->last == ((void *)0) && aQueue->first == ((void *)0)) {
    result = 1;
  }
  return result;
 }

canonical_original_code:
_Bool isQueueEmpty(struct queueStruct *aQueue) {
  _Bool result = 0;
  if(aQueue->last == ((void *)0) && aQueue->first == ((void *)0)) {
    result = 1;
  }
  return result;
 }


isQueueFull

decompiled_code:
bool isQueueFull()
{
void *v0; // rbx

v0 = malloc(0x10uLL);
free(v0);
return v0 == 0LL;
}

original_code:
_Bool isQueueFull(queue aQueue) {
  _Bool result = 0;
  queueNode temp = (queueNode) malloc(sizeof(struct aNode));
  if(temp == ((void *)0)) {
    result = 1;
  }
  free(temp);
  return result;
}

canonical_original_code:
_Bool isQueueFull(struct queueStruct *aQueue) {
  _Bool result = 0;
  struct aNode *temp = (queueNode) malloc(sizeof(struct aNode));
  if(temp == ((void *)0)) {
    result = 1;
  }
  free(temp);
  return result;
}

variable_types: struct aNode { int data; struct aNode *next; } *