main

original_code:
int main(void)
{
    HashTable myHashTable;
    DataType a[]={180,750,600,430,541,900,460},item={430};
    int i,j,k,n=7,m=13;
    Initiate(&myHashTable,m);
    for(i=0;i<n;i++)
        Insert(&myHashTable,a[i]);
    for(i=0;i<n;i++)
    {
        j=Find(&myHashTable,a[i]);
        printf("j=%d  ht[]= %d\n",j,myHashTable.ht[j].data.key);
    }
    k=Find(&myHashTable,item);
    if(k>0)
        printf("查找成功,元素%d 的地址是 %d\n",item.key,k);
    else
        printf("查找失败\n");
    Delete(&myHashTable,item);
    k=Find(&myHashTable,item);
    if(k>0)
        printf("查找成功,元素%d 的地址是 %d\n",item.key,k);
    else
        printf("查找失败\n");
    Destroy(&myHashTable);
    return 0;
}

canonical_original_code:
int main()
{
    struct HashTable myHashTable;
    struct DataType a[] = {180,750,600,430,541,900,460}; struct DataType item = {430};
    int i; int j; int k; int n = 7; int m = 13;
    Initiate(&myHashTable,m);
    for(i=0;i<n;i++)
        Insert(&myHashTable,a[i]);
    for(i=0;i<n;i++)
    {
        j=Find(&myHashTable,a[i]);
        printf("j=%d  ht[]= %d\n",j,myHashTable.ht[j].data.key);
    }
    k=Find(&myHashTable,item);
    if(k>0)
        printf("查找成功,元素%d 的地址是 %d\n",item.key,k);
    else
        printf("查找失败\n");
    Delete(&myHashTable,item);
    k=Find(&myHashTable,item);
    if(k>0)
        printf("查找成功,元素%d 的地址是 %d\n",item.key,k);
    else
        printf("查找失败\n");
    Destroy(&myHashTable);
    return 0;
}

variable_types: struct HashTable { struct HashItem { struct DataType { int key; } data; enum KindOfItem { Empty=0, Active=1, Deleted=2 } info; } *ht; int tableSize; int currentSize; }

variable_types:
a
struct DataType { int key; } []

variable_types:
item
struct DataType { int key; }

variable_types: n int

variable_types: m int


repo: gnperdue/OscCalcCore

decompiled_code:
void __fastcall twoFlavorMuSurviveArray_R(double *a1, int *a2, __int64 a3, __int64 a4)
{
void *v6; // rbp
__int64 v7; // rbx

v6 = (void *)create_default_nuOscParams();
if ( *a2 > 0 )
{
v7 = 0LL;
do
{
*(double *)(a4 + 8 * v7) = twoFlavorMuSurvive(v6, *(double *)(a3 + 8 * v7), *a1);
++v7;
}
while ( *a2 > (int)v7 );
}
free(v6);
}

canonical_decompiled_code:
void __fastcall func0(double *a1, int *a2, __int64 a3, __int64 a4)
{
void *v6; // rbp
__int64 v7; // rbx

v6 = (void *)create_default_nuOscParams();
if ( *a2 > 0 )
{
v7 = 0LL;
do
{
*(double *)(a4 + 8 * v7) = twoFlavorMuSurvive(v6, *(double *)(a3 + 8 * v7), *a1);
++v7;
}
while ( *a2 > (int)v7 );
}
free(v6);
}

original_code:
void twoFlavorMuSurviveArray_R(
    double *baseline,
    int *nenergies,
    double energies[],
    double probabilities[])
{
  struct nuOscParams *params = create_default_nuOscParams();
  for (int i = 0; i<(*nenergies); ++i) {
    probabilities[i] = twoFlavorMuSurvive( params, energies[i], *baseline );
  }
  free(params);
}

canonical_original_code:
void twoFlavorMuSurviveArray_R(double *baseline, int *nenergies, double energies[], double probabilities[])
{
  struct nuOscParams *params = create_default_nuOscParams();
  for (int i = 0; i<(*nenergies); ++i) {
    probabilities[i] = twoFlavorMuSurvive( params, energies[i], *baseline );
  }
  free(params);
}

variable_types:
baseline
double *

variable_types:
nenergies
int *

variable_types:
energies
double []

variable_types:
probabilities
double []

variable_types: struct nuOscParams { double delta_m12_squared; double delta_m23_squared; double delta_m13_squared; double delta_m21_squared; double delta_m32_squared; double delta_m31_squared; double theta12; double theta23; double theta13; int hierarchy; int helicity; double deltaCP; } *

variable_types: i int

return_type: void


decompiled_code:
void __fastcall threeFlavorMuSurviveArray_R(double *a1, _QWORD *a2, _QWORD *a3, int *a4, __int64 a5, __int64 a6)
{
_QWORD *v9; // rbx
__int64 v10; // r15

v9 = (_QWORD *)create_default_nuOscParams();
v9[10] = *a2;
v9[7] = *a3;
if ( *a4 > 0 )
{
v10 = 0LL;
do
{
*(double *)(a6 + 8 * v10) = threeFlavorMuSurvive(v9, *(double *)(a5 + 8 * v10), *a1);
++v10;
}
while ( *a4 > (int)v10 );
}
free(v9);
}

canonical_decompiled_code:
void __fastcall func1(double *a1, _QWORD *a2, _QWORD *a3, int *a4, __int64 a5, __int64 a6)
{
_QWORD *v9; // rbx
__int64 v10; // r15

v9 = (_QWORD *)create_default_nuOscParams();
v9[10] = *a2;
v9[7] = *a3;
if ( *a4 > 0 )
{
v10 = 0LL;
do
{
*(double *)(a6 + 8 * v10) = threeFlavorMuSurvive(v9, *(double *)(a5 + 8 * v10), *a1);
++v10;
}
while ( *a4 > (int)v10 );
}
free(v9);
}

original_code:
void threeFlavorMuSurviveArray_R(
    double *baseline,
    double *deltaCP,
    double *theta23,
    int *nenergies,
    double energies[],
    double probabilities[])
{
  struct nuOscParams *params = create_default_nuOscParams();
  params->deltaCP = *deltaCP;
  params->theta23 = *theta23;
  for (int i = 0; i<(*nenergies); ++i) {
    probabilities[i] = threeFlavorMuSurvive( params, energies[i], *baseline );
  }
  free(params);
}

canonical_original_code:
void threeFlavorMuSurviveArray_R(double *baseline, double *deltaCP, double *theta23, int *nenergies, double energies[], double probabilities[])
{
  struct nuOscParams *params = create_default_nuOscParams();
  params->deltaCP = *deltaCP;
  params->theta23 = *theta23;
  for (int i = 0; i<(*nenergies); ++i) {
    probabilities[i] = threeFlavorMuSurvive( params, energies[i], *baseline );
  }
  free(params);
}

variable_types:
deltaCP
double *

user_defined_types: struct nuOscParams { double delta_m12_squared; double delta_m23_squared; double delta_m13_squared; double delta_m21_squared; double delta_m32_squared; double delta_m31_squared; double theta12; double theta23; double theta13; int hierarchy; int helicity; double deltaCP; }


decompiled_code:
void __fastcall threeFlavorNuMuToNuEMatterArray_R(double *a1, _QWORD *a2, double *a3, int *a4, _DWORD *a5, int *a6, __int64 a7, __int64 a8)
{
__int64 v10; // rbp
__int64 v11; // rbx

v10 = create_default_nuOscParams();
*(_QWORD *)(v10 + 80) = *a2;
*(_DWORD *)(v10 + 76) = *a5;
if ( *a4 < 0 )
invert_hierarchy(v10);
if ( *a6 > 0 )
{
v11 = 0LL;
do
{
*(double *)(a8 + 8 * v11) = threeFlavorNuMuToNuEMatter(v10, *(double *)(a7 + 8 * v11), *a1, *a3);
++v11;
}
while ( *a6 > (int)v11 );
}
free((void *)v10);
}

canonical_decompiled_code:
void __fastcall func2(double *a1, _QWORD *a2, double *a3, int *a4, _DWORD *a5, int *a6, __int64 a7, __int64 a8)
{
__int64 v10; // rbp
__int64 v11; // rbx

v10 = create_default_nuOscParams();
*(_QWORD *)(v10 + 80) = *a2;
*(_DWORD *)(v10 + 76) = *a5;
if ( *a4 < 0 )
invert_hierarchy(v10);
if ( *a6 > 0 )
{
v11 = 0LL;
do
{
*(double *)(a8 + 8 * v11) = threeFlavorNuMuToNuEMatter(v10, *(double *)(a7 + 8 * v11), *a1, *a3);
++v11;
}
while ( *a6 > (int)v11 );
}
free((void *)v10);
}

original_code:
void threeFlavorNuMuToNuEMatterArray_R(
    double *baseline,
    double *deltaCP,
    double *matterConst,
    int *hierarchy,
    int *helicity,
    int *nenergies,
    double energies[],
    double probabilities[])
{
  struct nuOscParams *params = create_default_nuOscParams();
  params->deltaCP = *deltaCP;
  params->helicity = *helicity;
  if (*hierarchy < 0) invert_hierarchy( params );
  for (int i = 0; i<(*nenergies); ++i) {
    probabilities[i] = threeFlavorNuMuToNuEMatter(
        params, energies[i], *baseline, *matterConst );
  }
  free(params);
}

canonical_original_code:
void threeFlavorNuMuToNuEMatterArray_R(double *baseline, double *deltaCP, double *matterConst, int *hierarchy, int *helicity, int *nenergies, double energies[], double probabilities[])
{
  struct nuOscParams *params = create_default_nuOscParams();
  params->deltaCP = *deltaCP;
  params->helicity = *helicity;
  if (*hierarchy < 0) invert_hierarchy( params );
  for (int i = 0; i<(*nenergies); ++i) {
    probabilities[i] = threeFlavorNuMuToNuEMatter(
        params, energies[i], *baseline, *matterConst );
  }
  free(params);
}

variable_types:
matterConst
double *

variable_types:
hierarchy
int *

variable_types:
helicity
int *


decompiled_code:
void __fastcall threeFlavorNuMuToNuEVacuumArray_R(double *a1, _QWORD *a2, int *a3, _DWORD *a4, int *a5, __int64 a6, __int64 a7)
{
__int64 v9; // rbx
__int64 v10; // r15

v9 = create_default_nuOscParams();
*(_QWORD *)(v9 + 80) = *a2;
*(_DWORD *)(v9 + 76) = *a4;
if ( *a3 < 0 )
invert_hierarchy(v9);
if ( *a5 > 0 )
{
v10 = 0LL;
do
{
*(double *)(a7 + 8 * v10) = threeFlavorNuMuToNuEVacuum(v9, *(double *)(a6 + 8 * v10), *a1);
++v10;
}
while ( *a5 > (int)v10 );
}
free((void *)v9);
}

canonical_decompiled_code:
void __fastcall func3(double *a1, _QWORD *a2, int *a3, _DWORD *a4, int *a5, __int64 a6, __int64 a7)
{
__int64 v9; // rbx
__int64 v10; // r15

v9 = create_default_nuOscParams();
*(_QWORD *)(v9 + 80) = *a2;
*(_DWORD *)(v9 + 76) = *a4;
if ( *a3 < 0 )
invert_hierarchy(v9);
if ( *a5 > 0 )
{
v10 = 0LL;
do
{
*(double *)(a7 + 8 * v10) = threeFlavorNuMuToNuEVacuum(v9, *(double *)(a6 + 8 * v10), *a1);
++v10;
}
while ( *a5 > (int)v10 );
}
free((void *)v9);
}

original_code:
void threeFlavorNuMuToNuEVacuumArray_R(
    double *baseline,
    double *deltaCP,
    int *hierarchy,
    int *helicity,
    int *nenergies,
    double energies[],
    double probabilities[])
{
  struct nuOscParams *params = create_default_nuOscParams();
  params->deltaCP = *deltaCP;
  params->helicity = *helicity;
  if (*hierarchy < 0) invert_hierarchy( params );
  for (int i = 0; i<(*nenergies); ++i) {
    probabilities[i] = threeFlavorNuMuToNuEVacuum(
        params, energies[i], *baseline );
  }
  free(params);
}

canonical_original_code:
void threeFlavorNuMuToNuEVacuumArray_R(double *baseline, double *deltaCP, int *hierarchy, int *helicity, int *nenergies, double energies[], double probabilities[])
{
  struct nuOscParams *params = create_default_nuOscParams();
  params->deltaCP = *deltaCP;
  params->helicity = *helicity;
  if (*hierarchy < 0) invert_hierarchy( params );
  for (int i = 0; i<(*nenergies); ++i) {
    probabilities[i] = threeFlavorNuMuToNuEVacuum(
        params, energies[i], *baseline );
  }
  free(params);
}


canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
void *v3; // r13
void *v4; // rsp
void *v5; // rsp
__int64 v6; // rbx
double v7; // xmm0_8
__int64 v8; // rbx
double v9; // xmm0_8
__int64 v11; // [rsp+0h] [rbp-30h]
int v12; // [rsp+Ch] [rbp-24h]

v12 = 100;
v11 = 0x4086F80000000000LL;
printDefaultParameters();
v3 = (void *)create_default_nuOscParams();
v4 = alloca(800LL);
v5 = alloca(800LL);
v6 = 0LL;
do
{
v7 = (double)(int)v6 * 0.1 + 0.1;
*((double *)&v11 + v6) = v7;
twoFlavorMuSurvive();
*((double *)&v11 + v6) = v7;
printf("%0.2f %0.5f\n", *((double *)&v11 + v6++), v7);
}
while ( v12 > (int)v6 );
free(v3);
puts("Testing R-API function...");
twoFlavorMuSurviveArray_R();
if ( v12 > 0 )
{
v8 = 0LL;
do
{
v9 = (double)(int)v8 * 0.1 + 0.1;
*((double *)&v11 + v8) = v9;
twoFlavorMuSurvive();
*((double *)&v11 + v8) = v9;
printf("%0.2f %0.5f\n", *((double *)&v11 + v8++), v9);
}
while ( v12 > (int)v8 );
}
return 0;
}

original_code:
int main( int argc, char* argv[] )
{
  int nenergies = 100;
  double baseline = 735.0;
  printDefaultParameters();
  struct nuOscParams *params = create_default_nuOscParams();
  double energies[nenergies];
  double probabilities[nenergies];
  for (int i = 0; i < nenergies; ++i) {
    energies[i] = i * 0.1 + 0.1;
    probabilities[i] = twoFlavorMuSurvive(params, energies[i], baseline);
    printf("%0.2f  %0.5f\n", energies[i], probabilities[i]);
  }
  free(params);
  printf("Testing R-API function...\n");
  twoFlavorMuSurviveArray_R( &baseline, &nenergies, energies, probabilities);
  for (int i = 0; i < nenergies; ++i) {
    energies[i] = i * 0.1 + 0.1;
    probabilities[i] = twoFlavorMuSurvive(params, energies[i], baseline);
    printf("%0.2f  %0.5f\n", energies[i], probabilities[i]);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  int nenergies = 100;
  double baseline = 735.0;
  printDefaultParameters();
  struct nuOscParams *params = create_default_nuOscParams();
  double energies[-1];
  double probabilities[-1];
  for (int i = 0; i < nenergies; ++i) {
    energies[i] = i * 0.1 + 0.1;
    probabilities[i] = twoFlavorMuSurvive(params, energies[i], baseline);
    printf("%0.2f  %0.5f\n", energies[i], probabilities[i]);
  }
  free(params);
  printf("Testing R-API function...\n");
  twoFlavorMuSurviveArray_R( &baseline, &nenergies, energies, probabilities);
  for (int i = 0; i < nenergies; ++i) {
    energies[i] = i * 0.1 + 0.1;
    probabilities[i] = twoFlavorMuSurvive(params, energies[i], baseline);
    printf("%0.2f  %0.5f\n", energies[i], probabilities[i]);
  }
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: nenergies int

variable_types: baseline double

variable_types:
energies
double [-1]

variable_types:
probabilities
double [-1]

return_type: int


modExp

repo: gnsantos/primality

decompiled_code:
__int64 __fastcall modExp(__int64 a1, __int64 a2, unsigned __int64 a3)
{
double v5; // xmm0_8
int v6; // ecx
__int64 v7; // rdi
__int64 v8; // rdx

if ( a2 < 0 )
v5 = (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)) + (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1));
else
v5 = (double)(int)a2;
v6 = (int)log2(v5);
if ( v6 < 0 )
return 1LL;
v7 = 1LL;
do
{
v8 = v7 * v7 % a3;
v7 = v8;
if ( (unsigned int)((a2 & (unsigned __int64)(1 << v6)) >> v6) == 1 )
v7 = a1 * v8 % a3;
--v6;
}
while ( v6 != -1 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, unsigned __int64 a3)
{
double v5; // xmm0_8
int v6; // ecx
__int64 v7; // rdi
__int64 v8; // rdx

if ( a2 < 0 )
v5 = (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)) + (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1));
else
v5 = (double)(int)a2;
v6 = (int)log2(v5);
if ( v6 < 0 )
return 1LL;
v7 = 1LL;
do
{
v8 = v7 * v7 % a3;
v7 = v8;
if ( (unsigned int)((a2 & (unsigned __int64)(1 << v6)) >> v6) == 1 )
v7 = a1 * v8 % a3;
--v6;
}
while ( v6 != -1 );
return v7;
}

original_code:
static unsigned long modExp(unsigned long m, unsigned long e, unsigned long n){
  unsigned long temp = 1;
  int j;
  int b;
  for(j = log2(e); j >= 0; j--){
    temp = (temp*temp)%n;
    b = (e & (1 << j)) >> j;
    if(b == 1)
      temp = (temp*m)%n;
  }
  return temp;
}

variable_types:
m
unsigned long

variable_types:
e
unsigned long

variable_types:
n
unsigned long

variable_types:
temp
unsigned long

variable_types: j int

variable_types: b int

return_type: unsigned long


millerRabinTest

decompiled_code:
__int64 __fastcall millerRabinTest(unsigned __int64 a1, int a2)
{
__int64 result; // rax
unsigned int v4; // eax
int v5; // er14
unsigned __int64 v6; // rdx
__int64 v7; // rcx
int v8; // esi
int v9; // eax
__int64 v10; // [rsp+0h] [rbp-38h] BYREF
int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v11[0] = 0;
v10 = 0LL;
if ( (a1 & 1) != 0 || (result = 0LL, a1 == 2) )
{
result = 0LL;
if ( a1 != 1 )
{
result = 1LL;
if ( a1 != 2 )
{
getParameters(v11, &v10, a1);
v4 = time(0LL);
srand(v4);
if ( a2 <= 0 )
{
result = 1LL;
}
else
{
v5 = 0;
while ( 1 )
{
v9 = rand();
v7 = modExp(v9 % (a1 - 4) + 2, v10, a1);
v6 = v7 * v7 % a1;
if ( v11[0] > 0 )
break;
LABEL_13:
if ( v6 != 1 )
return 0LL;
if ( a2 == ++v5 )
return 1LL;
}
v8 = 0;
while ( v6 != 1 || v7 == 1 || a1 - 1 == v7 )
{
LODWORD(v7) = v6;
v6 = v6 * v6 % a1;
v7 = (int)v7;
if ( ++v8 == v11[0] )
goto LABEL_13;
}
result = 0LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int64 a1, int a2)
{
__int64 result; // rax
unsigned int v4; // eax
int v5; // er14
unsigned __int64 v6; // rdx
__int64 v7; // rcx
int v8; // esi
int v9; // eax
__int64 v10; // [rsp+0h] [rbp-38h] BYREF
int v11[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v11[0] = 0;
v10 = 0LL;
if ( (a1 & 1) != 0 || (result = 0LL, a1 == 2) )
{
result = 0LL;
if ( a1 != 1 )
{
result = 1LL;
if ( a1 != 2 )
{
func8(v11, &v10, a1);
v4 = time(0LL);
srand(v4);
if ( a2 <= 0 )
{
result = 1LL;
}
else
{
v5 = 0;
while ( 1 )
{
v9 = rand();
v7 = func9(v9 % (a1 - 4) + 2, v10, a1);
v6 = v7 * v7 % a1;
if ( v11[0] > 0 )
break;
LABEL_13:
if ( v6 != 1 )
return 0LL;
if ( a2 == ++v5 )
return 1LL;
}
v8 = 0;
while ( v6 != 1 || v7 == 1 || a1 - 1 == v7 )
{
LODWORD(v7) = v6;
v6 = v6 * v6 % a1;
v7 = (int)v7;
if ( ++v8 == v11[0] )
goto LABEL_13;
}
result = 0LL;
}
}
}
}
return result;
}

original_code:
Boolean millerRabinTest(unsigned long n, int s){
  int i,j, t=0, aux;
  unsigned long c = 0, a = 0, r0, r1;
  if((n % 2 == 0 && n != 2) || n == 1 )
    return FALSE;
  if(n == 2) return TRUE;
  getParameters(&t, &c, n);
  srand(time(((void *)0)));
  for(i = 0; i < s; i++){
    a = rand()%(n-4) + 2;
    r0 = modExp(a, c, n);
    r1 = (r0 * r0)%n;
    for(j= 0; j < t; j++){
      if(r1 == 1 && r0 != 1 && r0 != n-1)
 return FALSE;
      aux = r1;
      r1 = (r1*r1)%n;
      r0 = aux;
    }
    if(r1 != 1) return FALSE;
  }
  return TRUE;
}

canonical_original_code:
enum Boolean millerRabinTest(unsigned long n, int s){
  int i; int j; int t = 0; int aux;
  unsigned long c = 0; unsigned long a = 0; unsigned long r0; unsigned long r1;
  if((n % 2 == 0 && n != 2) || n == 1 )
    return FALSE;
  if(n == 2) return TRUE;
  getParameters(&t, &c, n);
  srand(time(((void *)0)));
  for(i = 0; i < s; i++){
    a = rand()%(n-4) + 2;
    r0 = modExp(a, c, n);
    r1 = (r0 * r0)%n;
    for(j= 0; j < t; j++){
      if(r1 == 1 && r0 != 1 && r0 != n-1)
 return FALSE;
      aux = r1;
      r1 = (r1*r1)%n;
      r0 = aux;
    }
    if(r1 != 1) return FALSE;
  }
  return TRUE;
}

variable_types: s int

variable_types: i int

variable_types: t int

variable_types: aux int

variable_types:
c
unsigned long

variable_types:
a
unsigned long

return_type: enum Boolean { FALSE=0, TRUE=1 }


repo: goakley/tcnj-coctree

decompiled_code:
void __fastcall OctreeNode3f_free(void *ptr)
{
if ( ptr )
{
*((_QWORD *)ptr + 9) = 0LL;
OctreeNode3f_free(*(void **)ptr);
OctreeNode3f_free(*((void **)ptr + 1));
OctreeNode3f_free(*((void **)ptr + 2));
OctreeNode3f_free(*((void **)ptr + 3));
OctreeNode3f_free(*((void **)ptr + 4));
OctreeNode3f_free(*((void **)ptr + 5));
OctreeNode3f_free(*((void **)ptr + 6));
OctreeNode3f_free(*((void **)ptr + 7));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
*((_QWORD *)ptr + 9) = 0LL;
func1(*(void **)ptr);
func1(*((void **)ptr + 1));
func1(*((void **)ptr + 2));
func1(*((void **)ptr + 3));
func1(*((void **)ptr + 4));
func1(*((void **)ptr + 5));
func1(*((void **)ptr + 6));
func1(*((void **)ptr + 7));
free(ptr);
}
}

original_code:
void OctreeNode3f_free(OctreeNode3f *node) {
  if (!node) return;
  node->usr_val = ((void *)0);
  OctreeNode3f_free(node->children[0]);
  OctreeNode3f_free(node->children[1]);
  OctreeNode3f_free(node->children[2]);
  OctreeNode3f_free(node->children[3]);
  OctreeNode3f_free(node->children[4]);
  OctreeNode3f_free(node->children[5]);
  OctreeNode3f_free(node->children[6]);
  OctreeNode3f_free(node->children[7]);
  free(node);
}

canonical_original_code:
void OctreeNode3f_free(struct OctreeNode3f *node) {
  if (!node) return;
  node->usr_val = ((void *)0);
  OctreeNode3f_free(node->children[0]);
  OctreeNode3f_free(node->children[1]);
  OctreeNode3f_free(node->children[2]);
  OctreeNode3f_free(node->children[3]);
  OctreeNode3f_free(node->children[4]);
  OctreeNode3f_free(node->children[5]);
  OctreeNode3f_free(node->children[6]);
  OctreeNode3f_free(node->children[7]);
  free(node);
}

variable_types: struct OctreeNode3f { struct OctreeNode3f *children[8]; unsigned int elements; void *usr_val; float position_x; float position_y; float position_z; float bound_bot_x; float bound_bot_y; float bound_bot_z; float bound_mid_x; float bound_mid_y; float bound_mid_z; float bound_top_x; float bound_top_y; float bound_top_z; } *


original_code:
int OctreeNode3f__insert_sub(OctreeNode3f *node, float x, float y, float z,
        void *usr_val)
{
  if (!node) return 0;
  int sub = 0;
  float min_x, min_y, min_z;
  float max_x, max_y, max_z;
  if (x > node->bound_mid_x) {
    sub += 1;
    min_x = node->bound_mid_x;
    max_x = node->bound_top_x;
  } else {
    min_x = node->bound_bot_x;
    max_x = node->bound_mid_x;
  }
  if (y > node->bound_mid_y) {
    sub += 2;
    min_y = node->bound_mid_y;
    max_y = node->bound_top_y;
  } else {
    min_y = node->bound_bot_y;
    max_y = node->bound_mid_y;
  }
  if (z > node->bound_mid_z) {
    sub += 4;
    min_z = node->bound_mid_z;
    max_z = node->bound_top_z;
  } else {
    min_z = node->bound_bot_z;
    max_z = node->bound_mid_z;
  }
  if (!(node->children)[sub])
    (node->children)[sub] = OctreeNode3f_malloc(min_x, min_y, min_z,
      max_x, max_y, max_z);
  return OctreeNode3f_insert((node->children)[sub], x,y,z, usr_val);
}

canonical_original_code:
int OctreeNode3f__insert_sub(struct OctreeNode3f *node, float x, float y, float z, void *usr_val)
{
  if (!node) return 0;
  int sub = 0;
  float min_x; float min_y; float min_z;
  float max_x; float max_y; float max_z;
  if (x > node->bound_mid_x) {
    sub += 1;
    min_x = node->bound_mid_x;
    max_x = node->bound_top_x;
  } else {
    min_x = node->bound_bot_x;
    max_x = node->bound_mid_x;
  }
  if (y > node->bound_mid_y) {
    sub += 2;
    min_y = node->bound_mid_y;
    max_y = node->bound_top_y;
  } else {
    min_y = node->bound_bot_y;
    max_y = node->bound_mid_y;
  }
  if (z > node->bound_mid_z) {
    sub += 4;
    min_z = node->bound_mid_z;
    max_z = node->bound_top_z;
  } else {
    min_z = node->bound_bot_z;
    max_z = node->bound_mid_z;
  }
  if (!(node->children)[sub])
    (node->children)[sub] = OctreeNode3f_malloc(min_x, min_y, min_z,
      max_x, max_y, max_z);
  return OctreeNode3f_insert((node->children)[sub], x,y,z, usr_val);
}

variable_types: x float

variable_types: y float

variable_types: z float

variable_types: sub int

user_defined_types: struct OctreeNode3f { struct OctreeNode3f *children[8]; unsigned int elements; void *usr_val; float position_x; float position_y; float position_z; float bound_bot_x; float bound_bot_y; float bound_bot_z; float bound_mid_x; float bound_mid_y; float bound_mid_z; float bound_top_x; float bound_top_y; float bound_top_z; }


original_code:
int OctreeNode3f_insert(OctreeNode3f *node, float x, float y, float z,
   void *usr_val)
{
  if (!node) return 0;
  if (node->elements == 0) {
    node->position_x = x;
    node->position_y = y;
    node->position_z = z;
    node->usr_val = usr_val;
  }
  else {
    if (node->elements == 1) {
      OctreeNode3f__insert_sub(node, node->position_x, node->position_y,
          node->position_z, node->usr_val);
      node->usr_val = ((void *)0);
    }
    OctreeNode3f__insert_sub(node, x,y,z, usr_val);
  }
  (node->elements)++;
  return (node->elements);
}

canonical_original_code:
int OctreeNode3f_insert(struct OctreeNode3f *node, float x, float y, float z, void *usr_val)
{
  if (!node) return 0;
  if (node->elements == 0) {
    node->position_x = x;
    node->position_y = y;
    node->position_z = z;
    node->usr_val = usr_val;
  }
  else {
    if (node->elements == 1) {
      OctreeNode3f__insert_sub(node, node->position_x, node->position_y,
          node->position_z, node->usr_val);
      node->usr_val = ((void *)0);
    }
    OctreeNode3f__insert_sub(node, x,y,z, usr_val);
  }
  (node->elements)++;
  return (node->elements);
}


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

if ( a1 )
{
free(*(void **)(a1 + 72));
BarnesHut__free(*(_QWORD *)a1);
BarnesHut__free(*(_QWORD *)(a1 + 8));
BarnesHut__free(*(_QWORD *)(a1 + 16));
BarnesHut__free(*(_QWORD *)(a1 + 24));
BarnesHut__free(*(_QWORD *)(a1 + 32));
BarnesHut__free(*(_QWORD *)(a1 + 40));
BarnesHut__free(*(_QWORD *)(a1 + 48));
result = BarnesHut__free(*(_QWORD *)(a1 + 56));
}
return result;
}

original_code:
void BarnesHut__free(OctreeNode3f *node) {
  if (!node) return;
  free(node->usr_val);
  BarnesHut__free(node->children[0]);
  BarnesHut__free(node->children[1]);
  BarnesHut__free(node->children[2]);
  BarnesHut__free(node->children[3]);
  BarnesHut__free(node->children[4]);
  BarnesHut__free(node->children[5]);
  BarnesHut__free(node->children[6]);
  BarnesHut__free(node->children[7]);
}

canonical_original_code:
void BarnesHut__free(struct OctreeNode3f *node) {
  if (!node) return;
  free(node->usr_val);
  BarnesHut__free(node->children[0]);
  BarnesHut__free(node->children[1]);
  BarnesHut__free(node->children[2]);
  BarnesHut__free(node->children[3]);
  BarnesHut__free(node->children[4]);
  BarnesHut__free(node->children[5]);
  BarnesHut__free(node->children[6]);
  BarnesHut__free(node->children[7]);
}


decompiled_code:
void __fastcall BarnesHut_free(void *ptr)
{
BarnesHut__free(*(_QWORD *)ptr);
OctreeNode3f_free(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
func0(*(_QWORD *)ptr);
OctreeNode3f_free(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void BarnesHut_free(BarnesHut *bh) {
  BarnesHut__free(bh->octree_root);
  OctreeNode3f_free(bh->octree_root);
  free(bh);
}

canonical_original_code:
void BarnesHut_free(struct BarnesHut *bh) {
  BarnesHut__free(bh->octree_root);
  OctreeNode3f_free(bh->octree_root);
  free(bh);
}

variable_types: struct BarnesHut { struct OctreeNode3f { struct OctreeNode3f *children[8]; unsigned int elements; void *usr_val; float position_x; float position_y; float position_z; float bound_bot_x; float bound_bot_y; float bound_bot_z; float bound_mid_x; float bound_mid_y; float bound_mid_z; float bound_top_x; float bound_top_y; float bound_top_z; } *octree_root; int finalized; } *

user_defined_types: struct BarnesHut { struct OctreeNode3f *octree_root; int finalized; }


decompiled_code:
__int64 __fastcall BarnesHut_add(_QWORD *a1, __m128i a2, __m128i a3, __m128i a4, __m128i a5)
{
__int64 result; // rax
unsigned int v6; // ebp
unsigned int v7; // er12
unsigned int v8; // er13
int v9; // er14
_DWORD *v10; // rax

result = 0LL;
if ( a1 )
{
v6 = _mm_cvtsi128_si32(a2);
v7 = _mm_cvtsi128_si32(a3);
v8 = _mm_cvtsi128_si32(a4);
v9 = _mm_cvtsi128_si32(a5);
v10 = malloc(0x10uLL);
if ( v10 )
{
*v10 = v9;
v10[1] = v6;
v10[2] = v7;
v10[3] = v8;
OctreeNode3f_insert(
*a1,
v10,
*(double *)_mm_cvtsi32_si128(v6).m128i_i64,
*(double *)_mm_cvtsi32_si128(v7).m128i_i64,
*(double *)_mm_cvtsi32_si128(v8).m128i_i64);
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, __m128i a2, __m128i a3, __m128i a4, __m128i a5)
{
__int64 result; // rax
unsigned int v6; // ebp
unsigned int v7; // er12
unsigned int v8; // er13
int v9; // er14
_DWORD *v10; // rax

result = 0LL;
if ( a1 )
{
v6 = _mm_cvtsi128_si32(a2);
v7 = _mm_cvtsi128_si32(a3);
v8 = _mm_cvtsi128_si32(a4);
v9 = _mm_cvtsi128_si32(a5);
v10 = malloc(0x10uLL);
if ( v10 )
{
*v10 = v9;
v10[1] = v6;
v10[2] = v7;
v10[3] = v8;
OctreeNode3f_insert(
*a1,
v10,
*(double *)_mm_cvtsi32_si128(v6).m128i_i64,
*(double *)_mm_cvtsi32_si128(v7).m128i_i64,
*(double *)_mm_cvtsi32_si128(v8).m128i_i64);
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
int BarnesHut_add(BarnesHut *bh, float x, float y, float z, float mass) {
  if (!bh) return 0;
  BarnesHutPoint *bhp = malloc(sizeof(BarnesHutPoint));
  if (!bhp) return 0;
  bhp->mass = mass;
  bhp->com_x = x;
  bhp->com_y = y;
  bhp->com_z = z;
  OctreeNode3f_insert(bh->octree_root, x,y,z, bhp);
  return 1;
}

canonical_original_code:
int BarnesHut_add(struct BarnesHut *bh, float x, float y, float z, float mass) {
  if (!bh) return 0;
  struct BarnesHutPoint *bhp = malloc(sizeof(BarnesHutPoint));
  if (!bhp) return 0;
  bhp->mass = mass;
  bhp->com_x = x;
  bhp->com_y = y;
  bhp->com_z = z;
  OctreeNode3f_insert(bh->octree_root, x,y,z, bhp);
  return 1;
}

variable_types: mass float

variable_types: struct BarnesHutPoint { float mass; float com_x; float com_y; float com_z; } *


original_code:
void BarnesHut__treecalc(OctreeNode3f *node) {
  if (!node) return;
  if (node->elements == 1)
    return;
  else {
    node->usr_val = malloc(sizeof(BarnesHutPoint));
    BarnesHutPoint *pt = (BarnesHutPoint*)(node->usr_val);
    pt->mass = 0;
    pt->com_x = 0; pt->com_y = 0; pt->com_z = 0;
    for (int i = 0; i < 8; i++) {
      if (!node->children[i])
 continue;
      BarnesHut__treecalc(node->children[i]);
      BarnesHutPoint *child_pt = (BarnesHutPoint*)node->children[i]->usr_val;
      float child_mass = child_pt->mass;
      pt->mass += child_mass;
      pt->com_x += child_mass*(child_pt->com_x);
      pt->com_y += child_mass*(child_pt->com_y);
      pt->com_z += child_mass*(child_pt->com_z);
    }
    pt->com_x /= pt->mass;
    pt->com_y /= pt->mass;
    pt->com_z /= pt->mass;
  }
}

canonical_original_code:
void BarnesHut__treecalc(struct OctreeNode3f *node) {
  if (!node) return;
  if (node->elements == 1)
    return;
  else {
    node->usr_val = malloc(sizeof(BarnesHutPoint));
    struct BarnesHutPoint *pt = (BarnesHutPoint*)(node->usr_val);
    pt->mass = 0;
    pt->com_x = 0; pt->com_y = 0; pt->com_z = 0;
    for (int i = 0; i < 8; i++) {
      if (!node->children[i])
 continue;
      BarnesHut__treecalc(node->children[i]);
      struct BarnesHutPoint *child_pt = (BarnesHutPoint*)node->children[i]->usr_val;
      float child_mass = child_pt->mass;
      pt->mass += child_mass;
      pt->com_x += child_mass*(child_pt->com_x);
      pt->com_y += child_mass*(child_pt->com_y);
      pt->com_z += child_mass*(child_pt->com_z);
    }
    pt->com_x /= pt->mass;
    pt->com_y /= pt->mass;
    pt->com_z /= pt->mass;
  }
}

user_defined_types: struct BarnesHutPoint { float mass; float com_x; float com_y; float com_z; }


decompiled_code:
void __fastcall BarnesHut_finalize(__int64 *a1)
{
if ( a1 )
BarnesHut__treecalc(*a1);
}

canonical_decompiled_code:
void __fastcall func4(__int64 *a1)
{
if ( a1 )
func3(*a1);
}

original_code:
void BarnesHut_finalize(BarnesHut *bh) {
  if (!bh) return;
  BarnesHut__treecalc(bh->octree_root);
}

canonical_original_code:
void BarnesHut_finalize(struct BarnesHut *bh) {
  if (!bh) return;
  BarnesHut__treecalc(bh->octree_root);
}


original_code:
int BarnesHut__force(OctreeNode3f *node, BarnesHutPoint bhp,
       float *retx, float *rety, float *retz) {
  if (!node) return 0;
  *retx = *rety = *retz = 0;
  BarnesHutPoint node_bhp = *(BarnesHutPoint*)(node->usr_val);
  float radius =
    sqrtf(powf(node_bhp.com_x-bhp.com_x,2) +
   powf(node_bhp.com_y-bhp.com_y,2) +
   powf(node_bhp.com_z-bhp.com_z,2));
  if (radius == 0) return 1;
  float width = ((node->bound_top_x-node->bound_bot_x) +
   (node->bound_top_y-node->bound_bot_y) +
   (node->bound_top_z-node->bound_bot_z)) / 3;
  if (width/radius < 0.5) {
    float radius3 = powf(radius,3);
    *retx = 6.672e-11F * node_bhp.mass * bhp.mass *
      (node_bhp.com_x-bhp.com_x)/radius3;
    *rety = 6.672e-11F * node_bhp.mass * bhp.mass *
      (node_bhp.com_y-bhp.com_y)/radius3;
    *retz = 6.672e-11F * node_bhp.mass * bhp.mass *
      (node_bhp.com_z-bhp.com_z)/radius3;
  }
  else {
    for (int i = 0; i < 8; i++) {
      float child_x = 0; float child_y = 0; float child_z = 0;
      if (node->children[i]) {
 BarnesHut__force(node->children[i], bhp, &child_x,&child_y,&child_z);
 *retx += child_x;
 *rety += child_y;
 *retz += child_z;
      }
    }
  }
  return 1;
}

canonical_original_code:
int BarnesHut__force(struct OctreeNode3f *node, struct BarnesHutPoint bhp, float *retx, float *rety, float *retz) {
  if (!node) return 0;
  *retx = *rety = *retz = 0;
  struct BarnesHutPoint node_bhp = *(BarnesHutPoint*)(node->usr_val);
  float radius = sqrtf(powf(node_bhp.com_x-bhp.com_x,2) +
   powf(node_bhp.com_y-bhp.com_y,2) +
   powf(node_bhp.com_z-bhp.com_z,2));
  if (radius == 0) return 1;
  float width = ((node->bound_top_x-node->bound_bot_x) +
   (node->bound_top_y-node->bound_bot_y) +
   (node->bound_top_z-node->bound_bot_z)) / 3;
  if (width/radius < 0.5) {
    float radius3 = powf(radius,3);
    *retx = 6.672e-11F * node_bhp.mass * bhp.mass *
      (node_bhp.com_x-bhp.com_x)/radius3;
    *rety = 6.672e-11F * node_bhp.mass * bhp.mass *
      (node_bhp.com_y-bhp.com_y)/radius3;
    *retz = 6.672e-11F * node_bhp.mass * bhp.mass *
      (node_bhp.com_z-bhp.com_z)/radius3;
  }
  else {
    for (int i = 0; i < 8; i++) {
      float child_x = 0; float child_y = 0; float child_z = 0;
      if (node->children[i]) {
 BarnesHut__force(node->children[i], bhp, &child_x,&child_y,&child_z);
 *retx += child_x;
 *rety += child_y;
 *retz += child_z;
      }
    }
  }
  return 1;
}

variable_types: struct BarnesHutPoint { float mass; float com_x; float com_y; float com_z; }

variable_types:
retx
float *

variable_types:
rety
float *

variable_types:
retz
float *

variable_types: radius float

variable_types: width float


decompiled_code:
__int64 __fastcall BarnesHut_force(__int64 *a1, float *a2, float *a3, float *a4, __m128i a5, __m128i a6, __m128i a7, __m128i a8)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = BarnesHut__force(
*a1,
a2,
a3,
a4,
(__m128i)(((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a5) << 32) | (unsigned int)_mm_cvtsi128_si32(a8)),
COERCE_DOUBLE(((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a7) << 32) | (unsigned int)_mm_cvtsi128_si32(a6)));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, float *a2, float *a3, float *a4, __m128i a5, __m128i a6, __m128i a7, __m128i a8)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = func5(
*a1,
a2,
a3,
a4,
(__m128i)(((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a5) << 32) | (unsigned int)_mm_cvtsi128_si32(a8)),
COERCE_DOUBLE(((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a7) << 32) | (unsigned int)_mm_cvtsi128_si32(a6)));
return result;
}

original_code:
int BarnesHut_force(BarnesHut *bh, float x, float y, float z, float mass,
      float *retx, float *rety, float *retz) {
  if (!bh) return 0;
  BarnesHutPoint pt = {mass, x,y,z};
  return BarnesHut__force(bh->octree_root, pt, retx,rety,retz);
}

canonical_original_code:
int BarnesHut_force(struct BarnesHut *bh, float x, float y, float z, float mass, float *retx, float *rety, float *retz) {
  if (!bh) return 0;
  struct BarnesHutPoint pt = {mass, x,y,z};
  return BarnesHut__force(bh->octree_root, pt, retx,rety,retz);
}


repo: goggle/alplot

original_code:
alfigure* alfigure_create()
{
    static int id = 1;
    alfigure *fig = (alfigure *) malloc(sizeof(alfigure));
    if (fig == ((void *)0))
        alerror("alfigure_create(): Could not allocate memory.");
    fig->id = id;
    id++;
    fig->title = ((void *)0);
    fig->xlim[0] = -1.0;
    fig->xlim[1] = 1.0;
    fig->ylim[0] = -0.5;
    fig->ylim[1] = 0.5;
    fig->show_ticks[0] = 1;
    fig->show_ticks[1] = 1;
    fig->show_ticks[2] = 1;
    fig->show_ticks[3] = 1;
    fig->xticks = (double *) malloc(3 * sizeof(int));
    fig->yticks = (double *) malloc(3 * sizeof(int));
    fig->xticks[0] = -1.0;
    fig->xticks[1] = 0.0;
    fig->xticks[2] = 1.0;
    fig->yticks[0] = -0.5;
    fig->yticks[1] = 0.0;
    fig->yticks[2] = 0.5;
    fig->nxticks = 3;
    fig->nyticks = 3;
    fig->subxticks = ((void *)0);
    fig->nsubxticks = 0;
    fig->subyticks = ((void *)0);
    fig->nsubyticks = 0;
    fig->tickwidth = 1.5;
    fig->subtickwidth = 1.0;
    fig->ticklength = 12.0;
    fig->subticklength = 6.0;
    fig->show_xaxis = 0;
    fig->show_yaxis = 0;
    fig->ngraph = 0;
    fig->graph_id = ((void *)0);
    return fig;
}

canonical_original_code:
struct alfigure *alfigure_create()
{
    static int id = 1;
    struct alfigure *fig = (alfigure *) malloc(sizeof(alfigure));
    if (fig == ((void *)0))
        alerror("alfigure_create(): Could not allocate memory.");
    fig->id = id;
    id++;
    fig->title = ((void *)0);
    fig->xlim[0] = -1.0;
    fig->xlim[1] = 1.0;
    fig->ylim[0] = -0.5;
    fig->ylim[1] = 0.5;
    fig->show_ticks[0] = 1;
    fig->show_ticks[1] = 1;
    fig->show_ticks[2] = 1;
    fig->show_ticks[3] = 1;
    fig->xticks = (double *) malloc(3 * sizeof(int));
    fig->yticks = (double *) malloc(3 * sizeof(int));
    fig->xticks[0] = -1.0;
    fig->xticks[1] = 0.0;
    fig->xticks[2] = 1.0;
    fig->yticks[0] = -0.5;
    fig->yticks[1] = 0.0;
    fig->yticks[2] = 0.5;
    fig->nxticks = 3;
    fig->nyticks = 3;
    fig->subxticks = ((void *)0);
    fig->nsubxticks = 0;
    fig->subyticks = ((void *)0);
    fig->nsubyticks = 0;
    fig->tickwidth = 1.5;
    fig->subtickwidth = 1.0;
    fig->ticklength = 12.0;
    fig->subticklength = 6.0;
    fig->show_xaxis = 0;
    fig->show_yaxis = 0;
    fig->ngraph = 0;
    fig->graph_id = ((void *)0);
    return fig;
}

variable_types: id int

variable_types: struct alfigure { unsigned int id; char *title; double xlim[2]; double ylim[2]; _Bool legend; _Bool show_ticks[4]; double *xticks; unsigned int nxticks; double *yticks; unsigned int nyticks; double *subxticks; unsigned int nsubxticks; double *subyticks; unsigned int nsubyticks; double tickwidth; double subtickwidth; double ticklength; double subticklength; _Bool show_xaxis; _Bool show_yaxis; unsigned int ngraph; unsigned int *graph_id; } *


decompiled_code:
int __fastcall alfigure_add_graph(__int64 a1, __int64 a2)
{
int v2; // ebp
void *v3; // rax

puts("Enterig alfigure_add_graph.");
if ( !a1 )
alerror("alfigure_add_graph: fig not allocated!");
if ( !a2 )
alerror("alfigure_add_graph: graph not allocated!");
v2 = algraph_get_id(a2);
v3 = realloc(*(void **)(a1 + 160), 4LL * (unsigned int)(*(_DWORD *)(a1 + 156) + 1));
*(_QWORD *)(a1 + 160) = v3;
if ( !v3 )
alerror("alfigure_add_graph: Could not allocate memory!");
*(_DWORD *)(*(_QWORD *)(a1 + 160) + 4LL * (unsigned int)(*(_DWORD *)(a1 + 156))++) = v2;
return puts("Exit alfigure_add_graph.");
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, __int64 a2)
{
int v2; // ebp
void *v3; // rax

puts("Enterig alfigure_add_graph.");
if ( !a1 )
alerror("alfigure_add_graph: fig not allocated!");
if ( !a2 )
alerror("alfigure_add_graph: graph not allocated!");
v2 = algraph_get_id(a2);
v3 = realloc(*(void **)(a1 + 160), 4LL * (unsigned int)(*(_DWORD *)(a1 + 156) + 1));
*(_QWORD *)(a1 + 160) = v3;
if ( !v3 )
alerror("alfigure_add_graph: Could not allocate memory!");
*(_DWORD *)(*(_QWORD *)(a1 + 160) + 4LL * (unsigned int)(*(_DWORD *)(a1 + 156))++) = v2;
return puts("Exit alfigure_add_graph.");
}

original_code:
void alfigure_add_graph(alfigure *fig, algraph *graph)
{
    unsigned int id;
    printf("Enterig alfigure_add_graph.\n");
    if (fig == ((void *)0))
        alerror("alfigure_add_graph: fig not allocated!");
    if (graph == ((void *)0))
        alerror("alfigure_add_graph: graph not allocated!");
    id = algraph_get_id(graph);
    fig->graph_id = (unsigned int *) realloc(fig->graph_id, (fig->ngraph + 1) * sizeof(unsigned int));
    if (fig->graph_id == ((void *)0))
        alerror("alfigure_add_graph: Could not allocate memory!");
    fig->graph_id[fig->ngraph] = id;
    fig->ngraph++;
    printf("Exit alfigure_add_graph.\n");
}

canonical_original_code:
void alfigure_add_graph(struct alfigure *fig, struct algraph *graph)
{
    unsigned int id;
    printf("Enterig alfigure_add_graph.\n");
    if (fig == ((void *)0))
        alerror("alfigure_add_graph: fig not allocated!");
    if (graph == ((void *)0))
        alerror("alfigure_add_graph: graph not allocated!");
    id = algraph_get_id(graph);
    fig->graph_id = (unsigned int *) realloc(fig->graph_id, (fig->ngraph + 1) * sizeof(unsigned int));
    if (fig->graph_id == ((void *)0))
        alerror("alfigure_add_graph: Could not allocate memory!");
    fig->graph_id[fig->ngraph] = id;
    fig->ngraph++;
    printf("Exit alfigure_add_graph.\n");
}

variable_types: struct algraph { unsigned int id; struct alpoint2d { double x; double y; } *data; unsigned int ndata; _Bool visible; _Bool show_graphline; double linewidth; struct rgba_color { double r; double g; double b; double alpha; } linecolor; int linestyle; char *name; _Bool legend; int interpolation_method; struct alpoint2d *bezier_control_points; struct alpoint { _Bool show; unsigned int style; double size; double linewidth; struct rgba_color edgecolor; _Bool filled; struct rgba_color facecolor; } points; } *

variable_types:
id
unsigned int

user_defined_types: struct alfigure { unsigned int id; char *title; double xlim[2]; double ylim[2]; _Bool legend; _Bool show_ticks[4]; double *xticks; unsigned int nxticks; double *yticks; unsigned int nyticks; double *subxticks; unsigned int nsubxticks; double *subyticks; unsigned int nsubyticks; double tickwidth; double subtickwidth; double ticklength; double subticklength; _Bool show_xaxis; _Bool show_yaxis; unsigned int ngraph; unsigned int *graph_id; }

user_defined_types: struct algraph { unsigned int id; struct alpoint2d *data; unsigned int ndata; _Bool visible; _Bool show_graphline; double linewidth; struct rgba_color linecolor; int linestyle; char *name; _Bool legend; int interpolation_method; struct alpoint2d *bezier_control_points; struct alpoint points; }


decompiled_code:
int __fastcall alfigure_print(const char **a1)
{
unsigned int v2; // ebp
unsigned int v3; // ebp
unsigned int v4; // ebp
unsigned int v5; // ebp
unsigned int v6; // ebp

printf("Figure %d\n", *(unsigned int *)a1);
printf("Title: %s\n", a1[1]);
printf("x limits: %.2f, %.2f\n", *((double *)a1 + 2), *((double *)a1 + 3));
printf("y limits: %.2f, %.2f\n", *((double *)a1 + 4), *((double *)a1 + 5));
printf("Legend: %d\n", *((unsigned __int8 *)a1 + 48));
printf("xticks: ");
if ( *((_DWORD *)a1 + 16) )
{
v2 = 0;
do
printf("%.2f ", *(double *)&a1[7][8 * v2++]);
while ( *((_DWORD *)a1 + 16) > v2 );
}
printf("\nyticks: ");
if ( *((_DWORD *)a1 + 20) )
{
v3 = 0;
do
printf("%.2f ", *(double *)&a1[7][8 * v3++]);
while ( *((_DWORD *)a1 + 20) > v3 );
}
printf("\nsubxticks: ");
if ( *((_DWORD *)a1 + 24) )
{
v4 = 0;
do
printf("%.2f ", *(double *)&a1[11][8 * v4++]);
while ( *((_DWORD *)a1 + 24) > v4 );
}
printf("\nsubyticks: ");
if ( *((_DWORD *)a1 + 28) )
{
v5 = 0;
do
printf("%.2f ", *(double *)&a1[13][8 * v5++]);
while ( *((_DWORD *)a1 + 28) > v5 );
}
printf("\nGraph ids: ");
if ( *((_DWORD *)a1 + 39) )
{
v6 = 0;
do
printf("%d ", *(unsigned int *)&a1[20][4 * v6++]);
while ( *((_DWORD *)a1 + 39) > v6 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(const char **a1)
{
unsigned int v2; // ebp
unsigned int v3; // ebp
unsigned int v4; // ebp
unsigned int v5; // ebp
unsigned int v6; // ebp

printf("Figure %d\n", *(unsigned int *)a1);
printf("Title: %s\n", a1[1]);
printf("x limits: %.2f, %.2f\n", *((double *)a1 + 2), *((double *)a1 + 3));
printf("y limits: %.2f, %.2f\n", *((double *)a1 + 4), *((double *)a1 + 5));
printf("Legend: %d\n", *((unsigned __int8 *)a1 + 48));
printf("xticks: ");
if ( *((_DWORD *)a1 + 16) )
{
v2 = 0;
do
printf("%.2f ", *(double *)&a1[7][8 * v2++]);
while ( *((_DWORD *)a1 + 16) > v2 );
}
printf("\nyticks: ");
if ( *((_DWORD *)a1 + 20) )
{
v3 = 0;
do
printf("%.2f ", *(double *)&a1[7][8 * v3++]);
while ( *((_DWORD *)a1 + 20) > v3 );
}
printf("\nsubxticks: ");
if ( *((_DWORD *)a1 + 24) )
{
v4 = 0;
do
printf("%.2f ", *(double *)&a1[11][8 * v4++]);
while ( *((_DWORD *)a1 + 24) > v4 );
}
printf("\nsubyticks: ");
if ( *((_DWORD *)a1 + 28) )
{
v5 = 0;
do
printf("%.2f ", *(double *)&a1[13][8 * v5++]);
while ( *((_DWORD *)a1 + 28) > v5 );
}
printf("\nGraph ids: ");
if ( *((_DWORD *)a1 + 39) )
{
v6 = 0;
do
printf("%d ", *(unsigned int *)&a1[20][4 * v6++]);
while ( *((_DWORD *)a1 + 39) > v6 );
}
return putchar(10);
}

original_code:
void alfigure_print(alfigure *fig)
{
    unsigned int i;
    printf("Figure %d\n", fig->id);
    printf("Title: %s\n", fig->title);
    printf("x limits: %.2f, %.2f\n", fig->xlim[0], fig->xlim[1]);
    printf("y limits: %.2f, %.2f\n", fig->ylim[0], fig->ylim[1]);
    printf("Legend: %d\n", fig->legend);
    printf("xticks: ");
    for (i = 0; i < fig->nxticks; i++)
        printf("%.2f ", fig->xticks[i]);
    printf("\nyticks: ");
    for (i = 0; i < fig->nyticks; i++)
        printf("%.2f ", fig->xticks[i]);
    printf("\nsubxticks: ");
    for (i = 0; i < fig->nsubxticks; i++)
        printf("%.2f ", fig->subxticks[i]);
    printf("\nsubyticks: ");
    for (i = 0; i < fig->nsubyticks; i++)
        printf("%.2f ", fig->subyticks[i]);
    printf("\nGraph ids: ");
    for (i = 0; i < fig->ngraph; i++)
        printf("%d ", fig->graph_id[i]);
    printf("\n");
}

canonical_original_code:
void alfigure_print(struct alfigure *fig)
{
    unsigned int i;
    printf("Figure %d\n", fig->id);
    printf("Title: %s\n", fig->title);
    printf("x limits: %.2f, %.2f\n", fig->xlim[0], fig->xlim[1]);
    printf("y limits: %.2f, %.2f\n", fig->ylim[0], fig->ylim[1]);
    printf("Legend: %d\n", fig->legend);
    printf("xticks: ");
    for (i = 0; i < fig->nxticks; i++)
        printf("%.2f ", fig->xticks[i]);
    printf("\nyticks: ");
    for (i = 0; i < fig->nyticks; i++)
        printf("%.2f ", fig->xticks[i]);
    printf("\nsubxticks: ");
    for (i = 0; i < fig->nsubxticks; i++)
        printf("%.2f ", fig->subxticks[i]);
    printf("\nsubyticks: ");
    for (i = 0; i < fig->nsubyticks; i++)
        printf("%.2f ", fig->subyticks[i]);
    printf("\nGraph ids: ");
    for (i = 0; i < fig->ngraph; i++)
        printf("%d ", fig->graph_id[i]);
    printf("\n");
}

variable_types:
i
unsigned int


decompiled_code:
double __fastcall alfigure_get_height(__int64 a1)
{
return *(double *)(a1 + 40) - *(double *)(a1 + 32);
}

canonical_decompiled_code:
double __fastcall func3(__int64 a1)
{
return *(double *)(a1 + 40) - *(double *)(a1 + 32);
}

original_code:
double alfigure_get_height(alfigure *fig)
{
    return fig->ylim[1] - fig->ylim[0];
}

canonical_original_code:
double alfigure_get_height(struct alfigure *fig)
{
    return fig->ylim[1] - fig->ylim[0];
}

return_type: double


decompiled_code:
double __fastcall alfigure_get_width(__int64 a1)
{
return *(double *)(a1 + 24) - *(double *)(a1 + 16);
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1)
{
return *(double *)(a1 + 24) - *(double *)(a1 + 16);
}

original_code:
double alfigure_get_width(alfigure *fig)
{
    return fig->xlim[1] - fig->xlim[0];
}

canonical_original_code:
double alfigure_get_width(struct alfigure *fig)
{
    return fig->xlim[1] - fig->xlim[0];
}


decompiled_code:
__int64 __fastcall alfigure_create_subxticks(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int v5; // edi
unsigned int v6; // esi
__int64 v7; // rax
double v8; // xmm0_8
double v9; // xmm1_8
__int64 v10; // rax

result = (__int64)malloc(8LL * a2 * (*(_DWORD *)(a1 + 64) - 1));
*(_QWORD *)(a1 + 88) = result;
if ( !result )
result = alerror("create_subxticks: Could not allocate memory!");
v5 = 0;
v6 = 0;
if ( *(_DWORD *)(a1 + 64) == 1 )
{
v5 = 0;
}
else
{
do
{
v7 = *(_QWORD *)(a1 + 56);
v8 = *(double *)(v7 + 8LL * v6++);
v9 = (*(double *)(v7 + 8LL * v6) - v8) / (double)(int)(a2 + 1);
if ( a2 )
{
v10 = 8LL * v5;
do
{
v8 = v8 + v9;
*(double *)(*(_QWORD *)(a1 + 88) + v10) = v8;
v10 += 8LL;
}
while ( v10 != 8 * (a2 + (__int64)v5) );
v5 += a2;
}
result = (unsigned int)(*(_DWORD *)(a1 + 64) - 1);
}
while ( v6 < (unsigned int)result );
}
*(_DWORD *)(a1 + 96) = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int v5; // edi
unsigned int v6; // esi
__int64 v7; // rax
double v8; // xmm0_8
double v9; // xmm1_8
__int64 v10; // rax

result = (__int64)malloc(8LL * a2 * (*(_DWORD *)(a1 + 64) - 1));
*(_QWORD *)(a1 + 88) = result;
if ( !result )
result = alerror("create_subxticks: Could not allocate memory!");
v5 = 0;
v6 = 0;
if ( *(_DWORD *)(a1 + 64) == 1 )
{
v5 = 0;
}
else
{
do
{
v7 = *(_QWORD *)(a1 + 56);
v8 = *(double *)(v7 + 8LL * v6++);
v9 = (*(double *)(v7 + 8LL * v6) - v8) / (double)(int)(a2 + 1);
if ( a2 )
{
v10 = 8LL * v5;
do
{
v8 = v8 + v9;
*(double *)(*(_QWORD *)(a1 + 88) + v10) = v8;
v10 += 8LL;
}
while ( v10 != 8 * (a2 + (__int64)v5) );
v5 += a2;
}
result = (unsigned int)(*(_DWORD *)(a1 + 64) - 1);
}
while ( v6 < (unsigned int)result );
}
*(_DWORD *)(a1 + 96) = v5;
return result;
}

original_code:
void alfigure_create_subxticks(alfigure *fig, unsigned int n)
{
    unsigned int i, j;
    int c = 0;
    double step;
    double x;
    fig->subxticks = (double *) malloc((fig->nxticks - 1) * n * sizeof(double));
    if (fig->subxticks == ((void *)0))
        alerror("create_subxticks: Could not allocate memory!");
    for (i = 0; i < fig->nxticks - 1; i++) {
        x = fig->xticks[i];
        step = (fig->xticks[i+1] - fig->xticks[i]) / (n + 1);
        for (j = 0; j < n; j++) {
            x += step;
            fig->subxticks[c++] = x;
        }
    }
    fig->nsubxticks = c;
}

canonical_original_code:
void alfigure_create_subxticks(struct alfigure *fig, unsigned int n)
{
    unsigned int i; unsigned int j;
    int c = 0;
    double step;
    double x;
    fig->subxticks = (double *) malloc((fig->nxticks - 1) * n * sizeof(double));
    if (fig->subxticks == ((void *)0))
        alerror("create_subxticks: Could not allocate memory!");
    for (i = 0; i < fig->nxticks - 1; i++) {
        x = fig->xticks[i];
        step = (fig->xticks[i+1] - fig->xticks[i]) / (n + 1);
        for (j = 0; j < n; j++) {
            x += step;
            fig->subxticks[c++] = x;
        }
    }
    fig->nsubxticks = c;
}

variable_types:
n
unsigned int

variable_types:
j
unsigned int

variable_types: c int

variable_types: step double

variable_types: x double


decompiled_code:
__int64 __fastcall alfigure_create_subyticks(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int v5; // edi
unsigned int v6; // esi
__int64 v7; // rax
double v8; // xmm0_8
double v9; // xmm1_8
__int64 v10; // rax

result = (__int64)malloc(8LL * a2 * (*(_DWORD *)(a1 + 80) - 1));
*(_QWORD *)(a1 + 104) = result;
if ( !result )
result = alerror("create subyticks: Could not allocate memory!");
v5 = 0;
v6 = 0;
if ( *(_DWORD *)(a1 + 80) == 1 )
{
v5 = 0;
}
else
{
do
{
v7 = *(_QWORD *)(a1 + 72);
v8 = *(double *)(v7 + 8LL * v6++);
v9 = (*(double *)(v7 + 8LL * v6) - v8) / (double)(int)(a2 + 1);
if ( a2 )
{
v10 = 8LL * v5;
do
{
v8 = v8 + v9;
*(double *)(*(_QWORD *)(a1 + 104) + v10) = v8;
v10 += 8LL;
}
while ( v10 != 8 * (a2 + (__int64)v5) );
v5 += a2;
}
result = (unsigned int)(*(_DWORD *)(a1 + 80) - 1);
}
while ( v6 < (unsigned int)result );
}
*(_DWORD *)(a1 + 112) = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2)
{
__int64 result; // rax
int v5; // edi
unsigned int v6; // esi
__int64 v7; // rax
double v8; // xmm0_8
double v9; // xmm1_8
__int64 v10; // rax

result = (__int64)malloc(8LL * a2 * (*(_DWORD *)(a1 + 80) - 1));
*(_QWORD *)(a1 + 104) = result;
if ( !result )
result = alerror("create subyticks: Could not allocate memory!");
v5 = 0;
v6 = 0;
if ( *(_DWORD *)(a1 + 80) == 1 )
{
v5 = 0;
}
else
{
do
{
v7 = *(_QWORD *)(a1 + 72);
v8 = *(double *)(v7 + 8LL * v6++);
v9 = (*(double *)(v7 + 8LL * v6) - v8) / (double)(int)(a2 + 1);
if ( a2 )
{
v10 = 8LL * v5;
do
{
v8 = v8 + v9;
*(double *)(*(_QWORD *)(a1 + 104) + v10) = v8;
v10 += 8LL;
}
while ( v10 != 8 * (a2 + (__int64)v5) );
v5 += a2;
}
result = (unsigned int)(*(_DWORD *)(a1 + 80) - 1);
}
while ( v6 < (unsigned int)result );
}
*(_DWORD *)(a1 + 112) = v5;
return result;
}

original_code:
void alfigure_create_subyticks(alfigure *fig, unsigned int n)
{
    unsigned int i, j;
    int c = 0;
    double step;
    double y;
    fig->subyticks = (double *) malloc((fig->nyticks - 1) * n * sizeof(double));
    if (fig->subyticks == ((void *)0))
        alerror("create subyticks: Could not allocate memory!");
    for (i = 0; i < fig->nyticks - 1; i++) {
        y = fig->yticks[i];
        step = (fig->yticks[i+1] - fig->yticks[i]) / (n + 1);
        for (j = 0; j < n; j++) {
            y += step;
            fig->subyticks[c++] = y;
        }
    }
    fig->nsubyticks = c;
}

canonical_original_code:
void alfigure_create_subyticks(struct alfigure *fig, unsigned int n)
{
    unsigned int i; unsigned int j;
    int c = 0;
    double step;
    double y;
    fig->subyticks = (double *) malloc((fig->nyticks - 1) * n * sizeof(double));
    if (fig->subyticks == ((void *)0))
        alerror("create subyticks: Could not allocate memory!");
    for (i = 0; i < fig->nyticks - 1; i++) {
        y = fig->yticks[i];
        step = (fig->yticks[i+1] - fig->yticks[i]) / (n + 1);
        for (j = 0; j < n; j++) {
            y += step;
            fig->subyticks[c++] = y;
        }
    }
    fig->nsubyticks = c;
}

variable_types: y double


decompiled_code:
int __fastcall alfigure_print_subxticks(__int64 a1)
{
unsigned int v1; // ebx

puts("subxticks:");
if ( *(_DWORD *)(a1 + 96) )
{
v1 = 0;
do
printf("%.5f ", *(double *)(*(_QWORD *)(a1 + 88) + 8LL * v1++));
while ( *(_DWORD *)(a1 + 96) > v1 );
}
return putchar(10);
}

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

puts("subxticks:");
if ( *(_DWORD *)(a1 + 96) )
{
v1 = 0;
do
printf("%.5f ", *(double *)(*(_QWORD *)(a1 + 88) + 8LL * v1++));
while ( *(_DWORD *)(a1 + 96) > v1 );
}
return putchar(10);
}

original_code:
void alfigure_print_subxticks(alfigure *fig)
{
    unsigned int i;
    printf("subxticks:\n");
    for (i = 0; i < fig->nsubxticks; i++)
        printf("%.5f ", fig->subxticks[i]);
    printf("\n");
}

canonical_original_code:
void alfigure_print_subxticks(struct alfigure *fig)
{
    unsigned int i;
    printf("subxticks:\n");
    for (i = 0; i < fig->nsubxticks; i++)
        printf("%.5f ", fig->subxticks[i]);
    printf("\n");
}


decompiled_code:
int __fastcall alfigure_print_subyticks(__int64 a1)
{
unsigned int v1; // ebx

puts("subyticks:");
if ( *(_DWORD *)(a1 + 112) )
{
v1 = 0;
do
printf("%.5f ", *(double *)(*(_QWORD *)(a1 + 104) + 8LL * v1++));
while ( *(_DWORD *)(a1 + 112) > v1 );
}
return putchar(10);
}

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

puts("subyticks:");
if ( *(_DWORD *)(a1 + 112) )
{
v1 = 0;
do
printf("%.5f ", *(double *)(*(_QWORD *)(a1 + 104) + 8LL * v1++));
while ( *(_DWORD *)(a1 + 112) > v1 );
}
return putchar(10);
}

original_code:
void alfigure_print_subyticks(alfigure *fig)
{
    unsigned int i;
    printf("subyticks:\n");
    for (i = 0; i < fig->nsubyticks; i++)
        printf("%.5f ", fig->subyticks[i]);
    printf("\n");
}

canonical_original_code:
void alfigure_print_subyticks(struct alfigure *fig)
{
    unsigned int i;
    printf("subyticks:\n");
    for (i = 0; i < fig->nsubyticks; i++)
        printf("%.5f ", fig->subyticks[i]);
    printf("\n");
}


decompiled_code:
void __fastcall alfigure_set_show_xaxis(__int64 a1)
{
*(_BYTE *)(a1 + 152) = 1;
}

original_code:
void alfigure_set_show_xaxis(alfigure *fig)
{
    fig->show_xaxis = 1;
}

canonical_original_code:
void alfigure_set_show_xaxis(struct alfigure *fig)
{
    fig->show_xaxis = 1;
}


decompiled_code:
void __fastcall alfigure_unset_show_xaxis(__int64 a1)
{
*(_BYTE *)(a1 + 152) = 0;
}

original_code:
void alfigure_unset_show_xaxis(alfigure *fig)
{
    fig->show_xaxis = 0;
}

canonical_original_code:
void alfigure_unset_show_xaxis(struct alfigure *fig)
{
    fig->show_xaxis = 0;
}


decompiled_code:
void __fastcall alfigure_set_show_yaxis(__int64 a1)
{
*(_BYTE *)(a1 + 153) = 1;
}

original_code:
void alfigure_set_show_yaxis(alfigure *fig)
{
    fig->show_yaxis = 1;
}

canonical_original_code:
void alfigure_set_show_yaxis(struct alfigure *fig)
{
    fig->show_yaxis = 1;
}


decompiled_code:
void __fastcall alfigure_unset_show_yaxis(__int64 a1)
{
*(_BYTE *)(a1 + 153) = 0;
}

original_code:
void alfigure_unset_show_yaxis(alfigure *fig)
{
    fig->show_yaxis = 0;
}

canonical_original_code:
void alfigure_unset_show_yaxis(struct alfigure *fig)
{
    fig->show_yaxis = 0;
}


decompiled_code:
void __fastcall set_xlim(__int64 a1, double a2, double a3)
{
if ( a3 <= a2 )
_assert_fail("xmin < xmax", "src/alFigure.c", 0xE3u, "set_xlim");
*(double *)(a1 + 16) = a2;
*(double *)(a1 + 24) = a3;
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, double a2, double a3)
{
if ( a3 <= a2 )
_assert_fail("xmin < xmax", "src/alFigure.c", 0xE3u, "set_xlim");
*(double *)(a1 + 16) = a2;
*(double *)(a1 + 24) = a3;
}

original_code:
void set_xlim(alfigure *fig, double xmin, double xmax)
{
    ((void) sizeof ((xmin < xmax) ? 1 : 0), __extension__ ({ if (xmin < xmax) ; else __assert_fail ("xmin < xmax", "src/alFigure.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    fig->xlim[0] = xmin;
    fig->xlim[1] = xmax;
}

canonical_original_code:
void set_xlim(struct alfigure *fig, double xmin, double xmax)
{
    ((void) sizeof ((xmin < xmax) ? 1 : 0), __extension__ ({ if (xmin < xmax) ; else __assert_fail ("xmin < xmax", "src/alFigure.c", 227, __extension__ __PRETTY_FUNCTION__); }));
    fig->xlim[0] = xmin;
    fig->xlim[1] = xmax;
}

variable_types: xmin double

variable_types: xmax double


decompiled_code:
void __fastcall set_ylim(__int64 a1, double a2, double a3)
{
if ( a3 <= a2 )
_assert_fail("ymin < ymax", "src/alFigure.c", 0xEBu, "set_ylim");
*(double *)(a1 + 32) = a2;
*(double *)(a1 + 40) = a3;
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, double a2, double a3)
{
if ( a3 <= a2 )
_assert_fail("ymin < ymax", "src/alFigure.c", 0xEBu, "set_ylim");
*(double *)(a1 + 32) = a2;
*(double *)(a1 + 40) = a3;
}

original_code:
void set_ylim(alfigure *fig, double ymin, double ymax)
{
    ((void) sizeof ((ymin < ymax) ? 1 : 0), __extension__ ({ if (ymin < ymax) ; else __assert_fail ("ymin < ymax", "src/alFigure.c", 235, __extension__ __PRETTY_FUNCTION__); }));
    fig->ylim[0] = ymin;
    fig->ylim[1] = ymax;
}

canonical_original_code:
void set_ylim(struct alfigure *fig, double ymin, double ymax)
{
    ((void) sizeof ((ymin < ymax) ? 1 : 0), __extension__ ({ if (ymin < ymax) ; else __assert_fail ("ymin < ymax", "src/alFigure.c", 235, __extension__ __PRETTY_FUNCTION__); }));
    fig->ylim[0] = ymin;
    fig->ylim[1] = ymax;
}

variable_types: ymin double

variable_types: ymax double


decompiled_code:
__int64 __fastcall alfigure_get_nticks(unsigned int *a1, char a2, char a3)
{
__int64 result; // rax

if ( a2 == 110 || a2 == 115 )
{
if ( a3 )
result = a1[24];
else
result = a1[16];
}
else if ( a2 == 101 || (result = 0LL, a2 == 119) )
{
if ( a3 )
result = a1[28];
else
result = a1[20];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int *a1, char a2, char a3)
{
__int64 result; // rax

if ( a2 == 110 || a2 == 115 )
{
if ( a3 )
result = a1[24];
else
result = a1[16];
}
else if ( a2 == 101 || (result = 0LL, a2 == 119) )
{
if ( a3 )
result = a1[28];
else
result = a1[20];
}
return result;
}

original_code:
unsigned int alfigure_get_nticks(alfigure *fig, char pos, _Bool subticks)
{
    unsigned int n = 0;
    if (pos == 'n' || pos == 's') {
        if (!subticks)
            n = fig->nxticks;
        else
            n = fig->nsubxticks;
    }
    else if (pos == 'e' || pos == 'w') {
        if (!subticks)
            n = fig->nyticks;
        else
            n = fig->nsubyticks;
    }
    return n;
}

canonical_original_code:
unsigned int alfigure_get_nticks(struct alfigure *fig, char pos, _Bool subticks)
{
    unsigned int n = 0;
    if (pos == 'n' || pos == 's') {
        if (!subticks)
            n = fig->nxticks;
        else
            n = fig->nsubxticks;
    }
    else if (pos == 'e' || pos == 'w') {
        if (!subticks)
            n = fig->nyticks;
        else
            n = fig->nsubyticks;
    }
    return n;
}

variable_types: pos char

return_type: unsigned int


alerror

decompiled_code:
void __fastcall __noreturn alerror(char *s)
{
puts("alerror");
puts(s);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(char *s)
{
puts("alerror");
puts(s);
exit(1);
}

original_code:
void alerror(const char *msg)
{
    printf("alerror\n");
    printf("%s\n", msg);
    exit(1);
}

canonical_original_code:
void alerror(char *msg)
{
    printf("alerror\n");
    printf("%s\n", msg);
    exit(1);
}

variable_types:
msg
char *


aluierror

decompiled_code:
void __fastcall __noreturn aluierror(char *s)
{
puts("UI Error.");
puts(s);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(char *s)
{
puts("UI Error.");
puts(s);
exit(1);
}

original_code:
void aluierror(const char *msg)
{
    printf("UI Error.\n");
    printf("%s\n", msg);
    exit(1);
}

canonical_original_code:
void aluierror(char *msg)
{
    printf("UI Error.\n");
    printf("%s\n", msg);
    exit(1);
}


original_code:
alpoint2d fig_to_world(alpoint2d fig_p, alfigure *fig)
{
    alpoint2d world_p = {(70), (480)};
    world_p.x += (fig_p.x - fig->xlim[0])/(fig->xlim[1] - fig->xlim[0]) * (600);
    world_p.y -= (fig_p.y - fig->ylim[0])/(fig->ylim[1] - fig->ylim[0]) * (400);
    return world_p;
}

canonical_original_code:
struct alpoint2d fig_to_world(struct alpoint2d fig_p, struct alfigure *fig)
{
    struct alpoint2d world_p = {(70), (480)};
    world_p.x += (fig_p.x - fig->xlim[0])/(fig->xlim[1] - fig->xlim[0]) * (600);
    world_p.y -= (fig_p.y - fig->ylim[0])/(fig->ylim[1] - fig->ylim[0]) * (400);
    return world_p;
}

variable_types: struct alpoint2d { double x; double y; }


original_code:
alarrow aldraw_calculate_arrow(alpoint2d begin, alpoint2d end, double headlength, double angle)
{
    double w, h;
    double norm;
    double v1x, v1y;
    double v2x, v2y;
    double px, py;
    alarrow arrow = { .begin = {begin.x, begin.y}, .end = {end.x, end.y}, .head1 = {0.0, 0.0}, .head2 = {0.0, 0.0}, .valid = 0 };
    if (fabs(end.x - begin.x) < 1e-15 && fabs(end.y - begin.y) < 1e-15) {
        return arrow;
    }
    if (headlength <= 0.0
            || angle > 3.14159265358979323846 / 2.0
            || angle < 1e-15) {
        return arrow;
    }
    h = sin(angle) * headlength;
    if (headlength * headlength - h * h < 0) {
        return arrow;
    }
    w = sqrt(headlength * headlength - h * h);
    norm = sqrt((begin.x - end.x) * (begin.x - end.x) + (begin.y - end.y) * (begin.y - end.y));
    v1x = (begin.x - end.x) / norm;
    v1y = (begin.y - end.y) / norm;
    v2x = -v1y;
    v2y = v1x;
    px = end.x + v1x * w;
    py = end.y + v1y * w;
    px = px + v2x * h;
    py = py + v2y * h;
    arrow.head1.x = px;
    arrow.head1.y = py;
    px = end.x + v1x * w;
    py = end.y + v1y * w;
    px = px - v2x * h;
    py = py - v2y * h;
    arrow.head2.x = px;
    arrow.head2.y = py;
    arrow.valid = 1;
    return arrow;
}

canonical_original_code:
struct alarrow aldraw_calculate_arrow(struct alpoint2d begin, struct alpoint2d end, double headlength, double angle)
{
    double w; double h;
    double norm;
    double v1x; double v1y;
    double v2x; double v2y;
    double px; double py;
    struct alarrow arrow = { .begin = {begin.x, begin.y}, .end = {end.x, end.y}, .head1 = {0.0, 0.0}, .head2 = {0.0, 0.0}, .valid = 0 };
    if (fabs(end.x - begin.x) < 1e-15 && fabs(end.y - begin.y) < 1e-15) {
        return arrow;
    }
    if (headlength <= 0.0
            || angle > 3.14159265358979323846 / 2.0
            || angle < 1e-15) {
        return arrow;
    }
    h = sin(angle) * headlength;
    if (headlength * headlength - h * h < 0) {
        return arrow;
    }
    w = sqrt(headlength * headlength - h * h);
    norm = sqrt((begin.x - end.x) * (begin.x - end.x) + (begin.y - end.y) * (begin.y - end.y));
    v1x = (begin.x - end.x) / norm;
    v1y = (begin.y - end.y) / norm;
    v2x = -v1y;
    v2y = v1x;
    px = end.x + v1x * w;
    py = end.y + v1y * w;
    px = px + v2x * h;
    py = py + v2y * h;
    arrow.head1.x = px;
    arrow.head1.y = py;
    px = end.x + v1x * w;
    py = end.y + v1y * w;
    px = px - v2x * h;
    py = py - v2y * h;
    arrow.head2.x = px;
    arrow.head2.y = py;
    arrow.valid = 1;
    return arrow;
}

variable_types:
begin
struct alpoint2d

variable_types:
end
struct alpoint2d

variable_types: headlength double

variable_types: angle double

variable_types: w double

variable_types: h double

variable_types: norm double

variable_types: px double

variable_types: py double

variable_types: struct alarrow { struct alpoint2d { double x; double y; } begin; struct alpoint2d end; struct alpoint2d head1; struct alpoint2d head2; _Bool valid; }

user_defined_types: struct alarrow { struct alpoint2d begin; struct alpoint2d end; struct alpoint2d head1; struct alpoint2d head2; _Bool valid; }


validsOpt

repo: goltango/ksamp

decompiled_code:
int validsOpt()
{
puts("Wrong choice!");
printf("Valid Options: -s , -l [interval] [time]");
return puts("\n");
}

canonical_decompiled_code:
int func7()
{
puts("Wrong choice!");
printf("Valid Options: -s , -l [interval] [time]");
return puts("\n");
}

original_code:
void validsOpt(){
 printf("Wrong choice!\n");
 printf("Valid Options: -s , -l [interval] [time]");
 printf("\n\n");
}


defaultInfo

decompiled_code:
__int64 defaultInfo()
{
showCpuinfo();
showVersion();
return showUptime();
}

canonical_decompiled_code:
__int64 func11()
{
func8();
func9();
return func10();
}

original_code:
void defaultInfo(){
    showCpuinfo();
    showVersion();
    showUptime();
}


showDiskstats

decompiled_code:
int showDiskstats()
{
int v1; // [rsp+8h] [rbp-110h]
int v2; // [rsp+Ch] [rbp-10Ch]
char v3[264]; // [rsp+10h] [rbp-108h] BYREF

findStr("/proc/diskstats", v3, "sda");
__isoc99_sscanf();
__isoc99_sscanf();
return printf("Disk loads: %u\n", (unsigned int)(v1 + v2));
}

canonical_decompiled_code:
int func16()
{
int v1; // [rsp+8h] [rbp-110h]
int v2; // [rsp+Ch] [rbp-10Ch]
char v3[264]; // [rsp+10h] [rbp-108h] BYREF

func15("/proc/diskstats", v3, "sda");
__isoc99_sscanf();
__isoc99_sscanf();
return printf("Disk loads: %u\n", (unsigned int)(v1 + v2));
}

original_code:
void showDiskstats(){
 char buff[256];
 unsigned int reads, writes, requests;
 findStr("/proc/diskstats", buff, "sda");
 sscanf(buff, "sda %u", &reads);
 sscanf(buff, "sda %*u %*u %*u %*u %u", &writes);
 requests = writes + reads;
 printf("Disk loads: %u\n", requests);
}

canonical_original_code:
void showDiskstats(){
 char buff[256];
 unsigned int reads; unsigned int writes; unsigned int requests;
 findStr("/proc/diskstats", buff, "sda");
 sscanf(buff, "sda %u", &reads);
 sscanf(buff, "sda %*u %*u %*u %*u %u", &writes);
 requests = writes + reads;
 printf("Disk loads: %u\n", requests);
}

variable_types:
buff
char [256]

variable_types:
reads
unsigned int

variable_types:
writes
unsigned int

variable_types:
requests
unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax

puts("KSAMP SOFTWARE 1.0 \n==================================================");
if ( argc == 1 )
defaultInfo();
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "sl:");
if ( v3 == -1 )
break;
if ( v3 == 108 )
{
if ( argc != 4 )
goto LABEL_7;
defaultInfo();
showStats();
uptimeSystemDate();
showMeminfo();
showDiskstats();
showLoadavg((__int64)argv, (const char *)optarg, _bss_start);
}
else
{
if ( v3 != 115 )
{
validsOpt();
return 0;
}
if ( argc == 2 )
{
defaultInfo();
showStats();
uptimeSystemDate();
}
else
{
LABEL_7:
validsOpt();
}
}
}
putchar(10);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax

puts("KSAMP SOFTWARE 1.0 \n==================================================");
if ( argc == 1 )
func11();
while ( 1 )
{
v3 = getopt(argc, (char *const *)argv, "sl:");
if ( v3 == -1 )
break;
if ( v3 == 108 )
{
if ( argc != 4 )
goto LABEL_7;
func11();
func12();
func14();
func13();
func16();
func17((__int64)argv, (const char *)optarg, _bss_start);
}
else
{
if ( v3 != 115 )
{
func7();
return 0;
}
if ( argc == 2 )
{
func11();
func12();
func14();
}
else
{
LABEL_7:
func7();
}
}
}
putchar(10);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int opcion;
 printf("KSAMP SOFTWARE 1.0 \n==================================================\n");
    if (argc == 1){
  defaultInfo();
 }
  while ((opcion = getopt (argc, argv, "sl:")) != -1){
  switch (opcion) {
   case 's':
    if(argc == 2){
     defaultInfo();
     showStats();
     uptimeSystemDate();
    }else{
     validsOpt();
    }
    break;
   case 'l':
    if(argc == 4){
                    defaultInfo();
     showStats();
     uptimeSystemDate();
                    showMeminfo();
                    showDiskstats();
                    showLoadavg(argv,optarg,optind);
    }else{
     validsOpt();
    }
    break;
   default:
    validsOpt();
    return 0;
        }
 }
 printf("\n");
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opcion int


repo: gonzoua/readmobi

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

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

original_code:
static inline uint32_t
bs_read_4(unsigned char *ptr)
{
    return (ptr[0] << 24) |
        (ptr[1] << 16) |
        (ptr[2] << 8) |
        ptr[3];
}

canonical_original_code:
static inline unsigned int bs_read_4(unsigned char *ptr)
{
    return (ptr[0] << 24) |
        (ptr[1] << 16) |
        (ptr[2] << 8) |
        ptr[3];
}

variable_types:
ptr
unsigned char *


decompiled_code:
int *__fastcall exth_get_record_desc(int a1)
{
int v1; // edx
__int64 v2; // rax

v1 = record_descs[0];
if ( !record_descs[0] )
return 0LL;
v2 = 0LL;
while ( a1 != v1 )
{
++v2;
v1 = record_descs[4 * v2];
if ( !v1 )
return 0LL;
}
return &record_descs[4 * (int)v2];
}

canonical_decompiled_code:
int *__fastcall func1(int a1)
{
int v1; // edx
__int64 v2; // rax

v1 = record_descs[0];
if ( !record_descs[0] )
return 0LL;
v2 = 0LL;
while ( a1 != v1 )
{
++v2;
v1 = record_descs[4 * v2];
if ( !v1 )
return 0LL;
}
return &record_descs[4 * (int)v2];
}

original_code:
static const exth_record_desc_t *
exth_get_record_desc(uint32_t rec_type)
{
    int i;
    for (i = 0; record_descs[i].exth_rec_type != 0; i++) {
        if (record_descs[i].exth_rec_type == rec_type)
            return (&record_descs[i]);
    }
    return (((void *)0));
}

canonical_original_code:
static struct exth_record_desc *exth_get_record_desc(unsigned int rec_type)
{
    int i;
    for (i = 0; record_descs[i].exth_rec_type != 0; i++) {
        if (record_descs[i].exth_rec_type == rec_type)
            return (&record_descs[i]);
    }
    return (((void *)0));
}

variable_types: i int

return_type: struct exth_record_desc { unsigned int exth_rec_type; enum exth_record_kind { EXTH_REC_TYPE_UNKNOWN=0, EXTH_REC_TYPE_BYTES=1, EXTH_REC_TYPE_STRING=2, EXTH_REC_TYPE_INT=3 } exth_rec_kind; char *exth_rec_name; } *

user_defined_types: struct exth_record_desc { unsigned int exth_rec_type; enum exth_record_kind exth_rec_kind; char *exth_rec_name; }


decompiled_code:
_QWORD *exth_header_alloc()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
exth_header_t*
exth_header_alloc()
{
    exth_header_t *h = malloc(sizeof(exth_header_t));
    memset(h, 0, sizeof(*h));
    return h;
}

canonical_original_code:
struct exth_header *exth_header_alloc()
{
    struct exth_header *h = malloc(sizeof(exth_header_t));
    memset(h, 0, sizeof(*h));
    return h;
}

variable_types: struct exth_header { unsigned int exth_identifier; unsigned int exth_length; unsigned int exth_record_count; struct exth_record { unsigned int exth_rec_type; unsigned int exth_rec_length; unsigned char *exth_rec_data; } *exth_records; } *

user_defined_types: struct exth_header { unsigned int exth_identifier; unsigned int exth_length; unsigned int exth_record_count; struct exth_record *exth_records; }


decompiled_code:
void __fastcall exth_header_free(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 2);
if ( v2 )
free(v2);
free(ptr);
}

original_code:
void
exth_header_free(exth_header_t* header)
{
    if (header->exth_records)
        free(header->exth_records);
    free(header);
}

canonical_original_code:
void exth_header_free(struct exth_header *header)
{
    if (header->exth_records)
        free(header->exth_records);
    free(header);
}

user_defined_types: struct exth_record { unsigned int exth_rec_type; unsigned int exth_rec_length; unsigned char *exth_rec_data; }


decompiled_code:
int __fastcall exth_header_print(unsigned int *a1)
{
const char *v1; // rax

puts("EXTH header");
v1 = (const char *)id2string(*a1);
printf(" Identifier: %08x (%s)\n", *a1, v1);
printf(" Length: %d\n", a1[1]);
return printf(" Record count: %d\n", a1[2]);
}

canonical_decompiled_code:
int __fastcall func5(unsigned int *a1)
{
const char *v1; // rax

puts("EXTH header");
v1 = (const char *)id2string(*a1);
printf(" Identifier: %08x (%s)\n", *a1, v1);
printf(" Length: %d\n", a1[1]);
return printf(" Record count: %d\n", a1[2]);
}

original_code:
void
exth_header_print(exth_header_t* h)
{
    printf("EXTH header\n");
    printf("  Identifier: %08x (%s)\n", h->exth_identifier, id2string(h->exth_identifier));
    printf("  Length: %d\n", h->exth_length);
    printf("  Record count: %d\n", h->exth_record_count);
}

canonical_original_code:
void exth_header_print(struct exth_header *h)
{
    printf("EXTH header\n");
    printf("  Identifier: %08x (%s)\n", h->exth_identifier, id2string(h->exth_identifier));
    printf("  Length: %d\n", h->exth_length);
    printf("  Record count: %d\n", h->exth_record_count);
}


decompiled_code:
int __fastcall exth_header_print_records(__int64 a1)
{
int result; // eax
__int64 v2; // r12
int v3; // esi
int *v4; // r15
unsigned int v5; // er14
int *v6; // rax
int *v7; // rbx
__int64 v8; // rcx

result = puts("EXTH records");
if ( *(_DWORD *)(a1 + 8) )
{
v2 = 0LL;
do
{
v4 = (int *)(*(_QWORD *)(a1 + 16) + 16 * v2);
v5 = *v4;
v6 = exth_get_record_desc(*v4);
v7 = v6;
v8 = (unsigned int)(v4[1] - 8);
if ( v6 )
{
printf(" <type=%d(%s),data_length=%d>\n", v5, *((const char **)v6 + 1), v8);
v3 = v7[1];
}
else
{
printf(" <type=%d(%s),data_length=%d>\n", v5, "unknown", v8);
v3 = 0;
}
exth_record_print_content(*(_QWORD *)(a1 + 16) + 16 * v2, v3, " ");
result = putchar(10);
++v2;
}
while ( *(_DWORD *)(a1 + 8) > (unsigned int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
int result; // eax
__int64 v2; // r12
int v3; // esi
int *v4; // r15
unsigned int v5; // er14
int *v6; // rax
int *v7; // rbx
__int64 v8; // rcx

result = puts("EXTH records");
if ( *(_DWORD *)(a1 + 8) )
{
v2 = 0LL;
do
{
v4 = (int *)(*(_QWORD *)(a1 + 16) + 16 * v2);
v5 = *v4;
v6 = func1(*v4);
v7 = v6;
v8 = (unsigned int)(v4[1] - 8);
if ( v6 )
{
printf(" <type=%d(%s),data_length=%d>\n", v5, *((const char **)v6 + 1), v8);
v3 = v7[1];
}
else
{
printf(" <type=%d(%s),data_length=%d>\n", v5, "unknown", v8);
v3 = 0;
}
func2(*(_QWORD *)(a1 + 16) + 16 * v2, v3, " ");
result = putchar(10);
++v2;
}
while ( *(_DWORD *)(a1 + 8) > (unsigned int)v2 );
}
return result;
}

original_code:
void
exth_header_print_records(exth_header_t* h)
{
    int i;
    const exth_record_desc_t *desc;
    exth_record_kind_t kind = EXTH_REC_TYPE_UNKNOWN;
    printf("EXTH records\n");
    for (i = 0; i < h->exth_record_count; i++) {
        kind = EXTH_REC_TYPE_UNKNOWN;
        desc = exth_get_record_desc(h->exth_records[i].exth_rec_type);
        printf("  <type=%d(%s),data_length=%d>\n",
                h->exth_records[i].exth_rec_type,
                desc ? desc->exth_rec_name : "unknown",
                h->exth_records[i].exth_rec_length - 8);
        if (desc != ((void *)0))
            kind = desc->exth_rec_kind;
        exth_record_print_content(&h->exth_records[i], kind, "    ");
        printf("\n");
    }
}

canonical_original_code:
void exth_header_print_records(struct exth_header *h)
{
    int i;
    struct exth_record_desc *desc;
    enum exth_record_kind kind = EXTH_REC_TYPE_UNKNOWN;
    printf("EXTH records\n");
    for (i = 0; i < h->exth_record_count; i++) {
        kind = EXTH_REC_TYPE_UNKNOWN;
        desc = exth_get_record_desc(h->exth_records[i].exth_rec_type);
        printf("  <type=%d(%s),data_length=%d>\n",
                h->exth_records[i].exth_rec_type,
                desc ? desc->exth_rec_name : "unknown",
                h->exth_records[i].exth_rec_length - 8);
        if (desc != ((void *)0))
            kind = desc->exth_rec_kind;
        exth_record_print_content(&h->exth_records[i], kind, "    ");
        printf("\n");
    }
}

variable_types: struct exth_record_desc { unsigned int exth_rec_type; enum exth_record_kind { EXTH_REC_TYPE_UNKNOWN=0, EXTH_REC_TYPE_BYTES=1, EXTH_REC_TYPE_STRING=2, EXTH_REC_TYPE_INT=3 } exth_rec_kind; char *exth_rec_name; } *


original_code:
off_t
exth_header_read(exth_header_t* h, unsigned char *ptr, off_t size)
{
    unsigned char *orig_ptr = ptr;
    int i;
    int data_size;
    if (size < 12)
        return (-1);
    do { (h->exth_identifier) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
    if (h->exth_identifier != 0x45585448)
        return (-1);
    do { (h->exth_length) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
    do { (h->exth_record_count) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
    if (h->exth_record_count)
        h->exth_records = malloc(sizeof(exth_record_t)*h->exth_record_count);
    for (i = 0; i < h->exth_record_count; i++) {
        do { (h->exth_records[i].exth_rec_type) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
        do { (h->exth_records[i].exth_rec_length) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
        data_size = h->exth_records[i].exth_rec_length - 8;
        if (data_size > 0) {
            h->exth_records[i].exth_rec_data = malloc(data_size);
            if (h->exth_records[i].exth_rec_data == ((void *)0))
                return (-1);
            memcpy(h->exth_records[i].exth_rec_data, ptr, data_size);
        }
        ptr += h->exth_records[i].exth_rec_length - 8;
    }
    return (ptr - orig_ptr);
}

canonical_original_code:
long exth_header_read(struct exth_header *h, unsigned char *ptr, long size)
{
    unsigned char *orig_ptr = ptr;
    int i;
    int data_size;
    if (size < 12)
        return (-1);
    do { (h->exth_identifier) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
    if (h->exth_identifier != 0x45585448)
        return (-1);
    do { (h->exth_length) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
    do { (h->exth_record_count) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
    if (h->exth_record_count)
        h->exth_records = malloc(sizeof(exth_record_t)*h->exth_record_count);
    for (i = 0; i < h->exth_record_count; i++) {
        do { (h->exth_records[i].exth_rec_type) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
        do { (h->exth_records[i].exth_rec_length) = bs_read_4((ptr)); (ptr) += 4; } while (0);;
        data_size = h->exth_records[i].exth_rec_length - 8;
        if (data_size > 0) {
            h->exth_records[i].exth_rec_data = malloc(data_size);
            if (h->exth_records[i].exth_rec_data == ((void *)0))
                return (-1);
            memcpy(h->exth_records[i].exth_rec_data, ptr, data_size);
        }
        ptr += h->exth_records[i].exth_rec_length - 8;
    }
    return (ptr - orig_ptr);
}

variable_types: size long

return_type: long


decompiled_code:
__int64 __fastcall bs_read_2(unsigned __int8 *a1)
{
return (*a1 << 8) | (unsigned int)a1[1];
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
return (*a1 << 8) | (unsigned int)a1[1];
}

original_code:
static inline uint16_t
bs_read_2(unsigned char *ptr)
{
    return (ptr[0] << 8) | ptr[1];
}

canonical_original_code:
static inline unsigned short bs_read_2(unsigned char *ptr)
{
    return (ptr[0] << 8) | ptr[1];
}

return_type: unsigned short


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


decompiled_code:
_DWORD *mobi_header_alloc()
{
_DWORD *v0; // rdx

v0 = malloc(0xACuLL);
memset(v0, 0, 0xA8uLL);
v0[42] = 0;
return v0;
}

canonical_decompiled_code:
_DWORD *func2()
{
_DWORD *v0; // rdx

v0 = malloc(0xACuLL);
memset(v0, 0, 0xA8uLL);
v0[42] = 0;
return v0;
}

original_code:
mobi_header_t*
mobi_header_alloc()
{
    mobi_header_t *h = malloc(sizeof(mobi_header_t));
    memset(h, 0, sizeof(*h));
    return h;
}

canonical_original_code:
struct mobi_header *mobi_header_alloc()
{
    struct mobi_header *h = malloc(sizeof(mobi_header_t));
    memset(h, 0, sizeof(*h));
    return h;
}

variable_types: struct mobi_header { unsigned short mobi_compression; unsigned int mobi_text_length; unsigned short mobi_record_count; unsigned short mobi_record_size; unsigned short mobi_encryption_type; unsigned int mobi_identifier; unsigned int mobi_header_length; unsigned int mobi_type; unsigned int mobi_text_encoding; unsigned int mobi_uid; unsigned int mobi_file_version; unsigned int mobi_ortographic_index; unsigned int mobi_inflection_index; unsigned int mobi_index_names; unsigned int mobi_index_keys; unsigned int mobi_extra_index[6]; unsigned int mobi_first_nonbook_index; unsigned int mobi_full_name_offset; unsigned int mobi_full_name_length; unsigned int mobi_locale; unsigned int mobi_dict_input_lang; unsigned int mobi_dict_output_lang; unsigned int mobi_min_version; unsigned int mobi_first_image_rec; unsigned int mobi_huffman_record_offset; unsigned int mobi_huffman_record_count; unsigned int mobi_huffman_table_offset; unsigned int mobi_huffman_table_count; unsigned int mobi_exth_flags; unsigned int mobi_drm_offset; unsigned int mobi_drm_count; unsigned int mobi_drm_size; unsigned int mobi_drm_flags; unsigned int mobi_first_content_rec; unsigned int mobi_last_content_rec; unsigned int mobi_fcis_rec; unsigned int mobi_flis_rec; unsigned int mobi_extra_record_data_flags; unsigned int mobi_indx_record_offset; } *


decompiled_code:
void __fastcall mobi_header_free(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
free(a1);
}

original_code:
void
mobi_header_free(mobi_header_t* header)
{
    free(header);
}

canonical_original_code:
void mobi_header_free(struct mobi_header *header)
{
    free(header);
}

user_defined_types: struct mobi_header { unsigned short mobi_compression; unsigned int mobi_text_length; unsigned short mobi_record_count; unsigned short mobi_record_size; unsigned short mobi_encryption_type; unsigned int mobi_identifier; unsigned int mobi_header_length; unsigned int mobi_type; unsigned int mobi_text_encoding; unsigned int mobi_uid; unsigned int mobi_file_version; unsigned int mobi_ortographic_index; unsigned int mobi_inflection_index; unsigned int mobi_index_names; unsigned int mobi_index_keys; unsigned int mobi_extra_index[6]; unsigned int mobi_first_nonbook_index; unsigned int mobi_full_name_offset; unsigned int mobi_full_name_length; unsigned int mobi_locale; unsigned int mobi_dict_input_lang; unsigned int mobi_dict_output_lang; unsigned int mobi_min_version; unsigned int mobi_first_image_rec; unsigned int mobi_huffman_record_offset; unsigned int mobi_huffman_record_count; unsigned int mobi_huffman_table_offset; unsigned int mobi_huffman_table_count; unsigned int mobi_exth_flags; unsigned int mobi_drm_offset; unsigned int mobi_drm_count; unsigned int mobi_drm_size; unsigned int mobi_drm_flags; unsigned int mobi_first_content_rec; unsigned int mobi_last_content_rec; unsigned int mobi_fcis_rec; unsigned int mobi_flis_rec; unsigned int mobi_extra_record_data_flags; unsigned int mobi_indx_record_offset; }