decompiled_code:
size_t __fastcall get_next(const char *a1, _DWORD *a2)
{
size_t result; // rax
int v4; // edi
int v5; // edx

result = strlen(a1);
*a2 = -1;
if ( (int)result > 0 )
{
v4 = result;
v5 = 0;
LODWORD(result) = -1;
do
{
while ( (_DWORD)result != -1 && a1[v5] != a1[(int)result] )
{
result = (unsigned int)a2[(int)result];
if ( v4 <= v5 )
return result;
}
++v5;
result = (unsigned int)(result + 1);
a2[v5] = result;
}
while ( v4 > v5 );
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(const char *a1, _DWORD *a2)
{
size_t result; // rax
int v4; // edi
int v5; // edx

result = strlen(a1);
*a2 = -1;
if ( (int)result > 0 )
{
v4 = result;
v5 = 0;
LODWORD(result) = -1;
do
{
while ( (_DWORD)result != -1 && a1[v5] != a1[(int)result] )
{
result = (unsigned int)a2[(int)result];
if ( v4 <= v5 )
return result;
}
++v5;
result = (unsigned int)(result + 1);
a2[v5] = result;
}
while ( v4 > v5 );
}
return result;
}

original_code:
int get_next(char* p, int* next)
{
    int len = strlen(p);
    int i = 0, k = -1;
    next[0] = -1;
    while(i<len)
    {
        if(k==-1 || p[i]==p[k])
        {
            i++;
            k++;
            next[i] = k;
        }else
        {
            k = next[k];
        }
    }
}

canonical_original_code:
int get_next(char *p, int *next)
{
    int len = strlen(p);
    int i = 0; int k = -1;
    next[0] = -1;
    while(i<len)
    {
        if(k==-1 || p[i]==p[k])
        {
            i++;
            k++;
            next[i] = k;
        }else
        {
            k = next[k];
        }
    }
}

variable_types:
p
char *

variable_types:
next
int *

variable_types: k int


decompiled_code:
__int64 __fastcall kmp_index(const char *a1, const char *a2, __int64 a3, int a4)
{
int v8; // er15
int v9; // eax
int v10; // edi
int v11; // esi
int v12; // eax
__int64 result; // rax

v8 = strlen(a1);
v9 = strlen(a2);
v10 = v9;
if ( v9 > 0 && a4 < v8 )
{
v11 = v9;
v12 = 0;
while ( 1 )
{
if ( v12 == -1 || a1[a4] == a2[v12] )
{
++a4;
++v12;
if ( a4 >= v8 )
goto LABEL_9;
}
else
{
v12 = *(_DWORD *)(a3 + 4LL * v12);
if ( a4 >= v8 )
goto LABEL_9;
}
if ( v12 >= v11 )
goto LABEL_9;
}
}
v12 = 0;
LABEL_9:
if ( v10 > v12 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a4 - v10);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, const char *a2, __int64 a3, int a4)
{
int v8; // er15
int v9; // eax
int v10; // edi
int v11; // esi
int v12; // eax
__int64 result; // rax

v8 = strlen(a1);
v9 = strlen(a2);
v10 = v9;
if ( v9 > 0 && a4 < v8 )
{
v11 = v9;
v12 = 0;
while ( 1 )
{
if ( v12 == -1 || a1[a4] == a2[v12] )
{
++a4;
++v12;
if ( a4 >= v8 )
goto LABEL_9;
}
else
{
v12 = *(_DWORD *)(a3 + 4LL * v12);
if ( a4 >= v8 )
goto LABEL_9;
}
if ( v12 >= v11 )
goto LABEL_9;
}
}
v12 = 0;
LABEL_9:
if ( v10 > v12 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(a4 - v10);
return result;
}

original_code:
int kmp_index(char* s, char* p, int* next, int start)
{
    int i=start,j=0;
    int slen = strlen(s);
    int plen = strlen(p);
    while(i<slen && j<plen)
    {
        if(j==-1 || s[i]==p[j])
        {
            i++;
            j++;
        }else
        {
            j = next[j];
        }
    }
    if(j>=plen)
    {
        return i-plen;
    }else
    {
        return -1;
    }
}

canonical_original_code:
int kmp_index(char *s, char *p, int *next, int start)
{
    int i = start; int j = 0;
    int slen = strlen(s);
    int plen = strlen(p);
    while(i<slen && j<plen)
    {
        if(j==-1 || s[i]==p[j])
        {
            i++;
            j++;
        }else
        {
            j = next[j];
        }
    }
    if(j>=plen)
    {
        return i-plen;
    }else
    {
        return -1;
    }
}

variable_types:
s
char *

variable_types: start int

variable_types: i int

variable_types: j int

variable_types: slen int

variable_types: plen int

return_type: int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
__int64 v4; // rsi
__int64 v5; // rcx
unsigned int v6; // eax
unsigned int v7; // ebx
_BYTE v9[32]; // [rsp+0h] [rbp-418h] BYREF
char v10; // [rsp+20h] [rbp-3F8h] BYREF

v3 = v9;
get_next("abaabcac", v9, envp);
do
{
v4 = *(unsigned int *)v3;
v3 += 4;
printf("%d ", v4);
}
while ( v3 != &v10 );
putchar(10);
v5 = 0LL;
do
{
v6 = kmp_index("xxabaabcacxxabaabcacdabaabcac99", "abaabcac", v9, v5);
v7 = v6;
if ( v6 == -1 )
break;
printf("'%s' @ %dth of '%s'\n", "abaabcac", v6, "xxabaabcacxxabaabcacdabaabcac99");
v5 = v7 + 1;
}
while ( v7 != -2 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
__int64 v4; // rsi
__int64 v5; // rcx
unsigned int v6; // eax
unsigned int v7; // ebx
_BYTE v9[32]; // [rsp+0h] [rbp-418h] BYREF
char v10; // [rsp+20h] [rbp-3F8h] BYREF

v3 = v9;
func7("abaabcac", v9, envp);
do
{
v4 = *(unsigned int *)v3;
v3 += 4;
printf("%d ", v4);
}
while ( v3 != &v10 );
putchar(10);
v5 = 0LL;
do
{
v6 = func8("xxabaabcacxxabaabcacdabaabcac99", "abaabcac", v9, v5);
v7 = v6;
if ( v6 == -1 )
break;
printf("'%s' @ %dth of '%s'\n", "abaabcac", v6, "xxabaabcacxxabaabcacdabaabcac99");
v5 = v7 + 1;
}
while ( v7 != -2 );
return 0;
}

original_code:
int main()
{
    char* str = "xxabaabcacxxabaabcacdabaabcac99";
    char* pattern = "abaabcac";
    int next[256];
    int plen = strlen(pattern);
    int i;
    get_next(pattern, next);
    for(i=0;i<plen;i++)
    {
        printf("%d ", next[i]);
    }
    printf("\n");
    i=0;
    while(i!=-1)
    {
        i = kmp_index(str, pattern, next, i);
        if(i!=-1)
        {
            printf("'%s' @ %dth of '%s'\n", pattern, i, str);
            i++;
        }
    }
    return 0;
}

canonical_original_code:
int main()
{
    char *str = "xxabaabcacxxabaabcacdabaabcac99";
    char *pattern = "abaabcac";
    int next[256];
    int plen = strlen(pattern);
    int i;
    get_next(pattern, next);
    for(i=0;i<plen;i++)
    {
        printf("%d ", next[i]);
    }
    printf("\n");
    i=0;
    while(i!=-1)
    {
        i = kmp_index(str, pattern, next, i);
        if(i!=-1)
        {
            printf("'%s' @ %dth of '%s'\n", pattern, i, str);
            i++;
        }
    }
    return 0;
}

variable_types:
str
char *

variable_types:
pattern
char *

variable_types:
next
int [256]


Initiate

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

*(_DWORD *)(a1 + 8) = a2;
v2 = malloc(8LL * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0LL;
*(_DWORD *)(a1 + 12) = 0;
return 1LL;
}

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

*(_DWORD *)(a1 + 8) = a2;
v2 = malloc(8LL * a2);
*(_QWORD *)a1 = v2;
if ( !v2 )
return 0LL;
*(_DWORD *)(a1 + 12) = 0;
return 1LL;
}

original_code:
int Initiate(HashTable *hash,int mSize)
{
    hash->tableSize=mSize;
    hash->ht=(HashItem *)malloc(sizeof(HashItem)*mSize);
    if(hash->ht==((void *)0))
        return 0;
    else
    {
        hash->currentSize=0;
        return 1;
    }
}

canonical_original_code:
int Initiate(struct HashTable *hash, int mSize)
{
    hash->tableSize=mSize;
    hash->ht=(struct HashItem *)malloc(sizeof(HashItem)*mSize);
    if(hash->ht==((void *)0))
        return 0;
    else
    {
        hash->currentSize=0;
        return 1;
    }
}

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

user_defined_types: struct HashTable { struct HashItem *ht; int tableSize; int currentSize; }

user_defined_types: struct HashItem { struct DataType data; enum KindOfItem info; }


Find

decompiled_code:
__int64 __fastcall Find(__int64 *a1, int a2)
{
int v3; // edi
int v5; // esi
__int64 v6; // r9
int v7; // edx
_DWORD *v8; // rcx

v3 = a2;
v5 = *((_DWORD *)a1 + 2);
v6 = *a1;
v7 = a2 % v5;
do
{
v8 = (_DWORD *)(v6 + 8LL * v7);
if ( v8[1] != 1 )
return (unsigned int)-v7;
if ( *v8 == v3 )
return (unsigned int)v7;
v7 = (v7 + 1) % v5;
}
while ( a2 % v5 != v7 );
return (unsigned int)-v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, int a2)
{
int v3; // edi
int v5; // esi
__int64 v6; // r9
int v7; // edx
_DWORD *v8; // rcx

v3 = a2;
v5 = *((_DWORD *)a1 + 2);
v6 = *a1;
v7 = a2 % v5;
do
{
v8 = (_DWORD *)(v6 + 8LL * v7);
if ( v8[1] != 1 )
return (unsigned int)-v7;
if ( *v8 == v3 )
return (unsigned int)v7;
v7 = (v7 + 1) % v5;
}
while ( a2 % v5 != v7 );
return (unsigned int)-v5;
}

original_code:
int Find(HashTable *hash,DataType x)
{
    int i=x.key%hash->tableSize;
    int j=i;
    while(hash->ht[j].info==Active && hash->ht[j].data.key!=x.key)
    {
        j=(j+1)%hash->tableSize;
        if(j==i)
            return -hash->tableSize;
    }
    if(hash->ht[j].info==Active)
        return j;
    else
        return -j;
}

canonical_original_code:
int Find(struct HashTable *hash, struct DataType x)
{
    int i = x.key%hash->tableSize;
    int j = i;
    while(hash->ht[j].info==Active && hash->ht[j].data.key!=x.key)
    {
        j=(j+1)%hash->tableSize;
        if(j==i)
            return -hash->tableSize;
    }
    if(hash->ht[j].info==Active)
        return j;
    else
        return -j;
}

variable_types:
x
struct DataType

user_defined_types: enum KindOfItem { Empty=0, Active=1, Deleted=2 }


Insert

original_code:
int Insert(HashTable *hash,DataType x)
{
    int i=Find(hash,x);
    if(i>0)
        return 0;
    else if(i!=-hash->tableSize)
    {
        hash->ht[-i].data=x;
        hash->ht[-i].info=Active;
        hash->currentSize++;
        return 1;
    }
    else
        return 0;
}

canonical_original_code:
int Insert(struct HashTable *hash, struct DataType x)
{
    int i = Find(hash,x);
    if(i>0)
        return 0;
    else if(i!=-hash->tableSize)
    {
        hash->ht[-i].data=x;
        hash->ht[-i].info=Active;
        hash->currentSize++;
        return 1;
    }
    else
        return 0;
}


Delete

original_code:
int Delete(HashTable *hash,DataType x)
{
    int i=Find(hash,x);
    if(i>=0)
    {
        hash->ht[i].info=Deleted;
        hash->currentSize--;
        return 1;
    }
    else
        return 0;
}

canonical_original_code:
int Delete(struct HashTable *hash, struct DataType x)
{
    int i = Find(hash,x);
    if(i>=0)
    {
        hash->ht[i].info=Deleted;
        hash->currentSize--;
        return 1;
    }
    else
        return 0;
}


Destroy

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

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

original_code:
void Destroy(HashTable *hash)
{
    free(hash->ht);
}

canonical_original_code:
void Destroy(struct HashTable *hash)
{
    free(hash->ht);
}

return_type: void


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; // r15
__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; // r15
__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; } *


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

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

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

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

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 *

variable_types: i int

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 v11; // rax
void *v12; // r12
__int64 v13; // rbx

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

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

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

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 v10; // rax
void *v11; // r15
__int64 v12; // rbx

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

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

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

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);
}


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
double v8; // xmm1_8
double v9; // xmm0_8
__int64 v10; // rbx
double v11; // xmm0_8
double v12; // xmm1_8
double v13; // xmm0_8
__int64 v15; // [rsp+0h] [rbp-40h]
double v16; // [rsp+8h] [rbp-38h]
int v17; // [rsp+14h] [rbp-2Ch]
__int64 v18; // [rsp+18h] [rbp-28h]

v17 = 100;
v18 = 0x4086F80000000000LL;
printDefaultParameters();
v3 = (void *)create_default_nuOscParams();
v4 = alloca(800LL);
v5 = alloca(800LL);
v6 = 0LL;
v16 = 0.1;
do
{
v7 = (double)(int)v6 * v16 + v16;
*((double *)&v15 + v6) = v7;
twoFlavorMuSurvive();
*((double *)&v15 + v6) = v7;
v8 = v7;
v9 = *((double *)&v15 + v6++);
printf("%0.2f %0.5f\n", v9, v8);
}
while ( v17 > (int)v6 );
free(v3);
puts("Testing R-API function...");
twoFlavorMuSurviveArray_R();
if ( v17 > 0 )
{
v10 = 0LL;
v16 = 0.1;
do
{
v11 = (double)(int)v10 * v16 + v16;
*((double *)&v15 + v10) = v11;
twoFlavorMuSurvive();
*((double *)&v15 + v10) = v11;
v12 = v11;
v13 = *((double *)&v15 + v10++);
printf("%0.2f %0.5f\n", v13, v12);
}
while ( v17 > (int)v10 );
}
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]


modExp

repo: gnsantos/primality

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

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

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

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

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)
{
unsigned int v3; // eax
int v4; // er12
int v5; // eax
__int64 v6; // rcx
unsigned __int64 v7; // rdx
int v8; // esi
int v10; // [rsp+4h] [rbp-34h] BYREF
__int64 v11[6]; // [rsp+8h] [rbp-30h] BYREF

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

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: 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; } *


decompiled_code:
__int64 __fastcall OctreeNode3f__insert_sub(float *a1, double a2, double a3, double a4)
{
double v4; // xmm6_8
double v5; // xmm7_8
double v6; // xmm8_8
double v7; // xmm3_8
double v8; // xmm0_8
int v9; // eax
float v10; // xmm9_4
float v11; // xmm1_4
double v12; // xmm0_8
double v13; // xmm4_8
double v14; // xmm5_8
float v15; // xmm2_4
__int64 v16; // rbp

if ( a1 )
{
v4 = a2;
v5 = a3;
v6 = a4;
if ( *(float *)&a2 > a1[26] )
{
v10 = a1[26];
*(_QWORD *)&v8 = *((unsigned int *)a1 + 27);
*(_QWORD *)&v7 = *((unsigned int *)a1 + 29);
v9 = 1;
if ( *(float *)&a3 > *(float *)&v8 )
{
LABEL_4:
v11 = *(float *)&v8;
*(_QWORD *)&v12 = *((unsigned int *)a1 + 28);
v9 += 2;
*(_QWORD *)&v13 = *((unsigned int *)a1 + 30);
if ( *(float *)&a4 > *(float *)&v12 )
goto LABEL_5;
goto LABEL_9;
}
}
else
{
*(_QWORD *)&v7 = *((unsigned int *)a1 + 26);
*(_QWORD *)&v8 = *((unsigned int *)a1 + 27);
v9 = 0;
v10 = a1[23];
if ( *(float *)&a3 > *(float *)&v8 )
goto LABEL_4;
}
v13 = v8;
*(_QWORD *)&v12 = *((unsigned int *)a1 + 28);
v11 = a1[24];
if ( *(float *)&a4 > *(float *)&v12 )
{
LABEL_5:
*(_QWORD *)&v14 = *((unsigned int *)a1 + 31);
v15 = *(float *)&v12;
v16 = v9 + 4;
if ( *(_QWORD *)&a1[2 * v16] )
return OctreeNode3f_insert(v4, v5, v6, v7, v13, v14);
LABEL_10:
*(_QWORD *)&v6 = LODWORD(v6);
*(_QWORD *)&a1[2 * v16] = OctreeNode3f_malloc(v10, v11, v15, *(float *)&v7, *(float *)&v13, *(float *)&v14);
*(_QWORD *)&v5 = LODWORD(v5);
*(_QWORD *)&v4 = LODWORD(v4);
return OctreeNode3f_insert(v4, v5, v6, v7, v13, v14);
}
LABEL_9:
v16 = v9;
v15 = a1[25];
v14 = v12;
if ( *(_QWORD *)&a1[2 * v9] )
return OctreeNode3f_insert(v4, v5, v6, v7, v13, v14);
goto LABEL_10;
}
return 0LL;
}

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; }


decompiled_code:
__int64 __fastcall OctreeNode3f_insert(__int64 a1, __int64 a2, double a3, double a4, double a5)
{
double v5; // xmm3_8
double v6; // xmm4_8
double v7; // xmm5_8
int v8; // eax
__int64 result; // rax

if ( !a1 )
return 0LL;
v5 = a3;
v6 = a4;
v7 = a5;
v8 = *(_DWORD *)(a1 + 64);
if ( v8 )
{
if ( v8 == 1 )
{
OctreeNode3f__insert_sub(
(float *)a1,
COERCE_DOUBLE((unsigned __int64)*(_DWORD *)(a1 + 80)),
COERCE_DOUBLE((unsigned __int64)*(_DWORD *)(a1 + 84)),
COERCE_DOUBLE((unsigned __int64)*(_DWORD *)(a1 + 88)));
*(_QWORD *)(a1 + 72) = 0LL;
*(_QWORD *)&v7 = LODWORD(a5);
*(_QWORD *)&v6 = LODWORD(a4);
*(_QWORD *)&v5 = LODWORD(a3);
}
OctreeNode3f__insert_sub((float *)a1, v5, v6, v7);
result = (unsigned int)(*(_DWORD *)(a1 + 64) + 1);
*(_DWORD *)(a1 + 64) = result;
}
else
{
result = 1LL;
*(_QWORD *)(a1 + 72) = a2;
*(_DWORD *)(a1 + 80) = LODWORD(a3);
*(_DWORD *)(a1 + 84) = LODWORD(a4);
*(_DWORD *)(a1 + 88) = LODWORD(a5);
*(_DWORD *)(a1 + 64) = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, double a3, double a4, double a5)
{
double v5; // xmm3_8
double v6; // xmm4_8
double v7; // xmm5_8
int v8; // eax
__int64 result; // rax

if ( !a1 )
return 0LL;
v5 = a3;
v6 = a4;
v7 = a5;
v8 = *(_DWORD *)(a1 + 64);
if ( v8 )
{
if ( v8 == 1 )
{
func2(
(float *)a1,
COERCE_DOUBLE((unsigned __int64)*(_DWORD *)(a1 + 80)),
COERCE_DOUBLE((unsigned __int64)*(_DWORD *)(a1 + 84)),
COERCE_DOUBLE((unsigned __int64)*(_DWORD *)(a1 + 88)));
*(_QWORD *)(a1 + 72) = 0LL;
*(_QWORD *)&v7 = LODWORD(a5);
*(_QWORD *)&v6 = LODWORD(a4);
*(_QWORD *)&v5 = LODWORD(a3);
}
func2((float *)a1, v5, v6, v7);
result = (unsigned int)(*(_DWORD *)(a1 + 64) + 1);
*(_DWORD *)(a1 + 64) = result;
}
else
{
result = 1LL;
*(_QWORD *)(a1 + 72) = a2;
*(_DWORD *)(a1 + 80) = LODWORD(a3);
*(_DWORD *)(a1 + 84) = LODWORD(a4);
*(_DWORD *)(a1 + 88) = LODWORD(a5);
*(_DWORD *)(a1 + 64) = 1;
}
return result;
}

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 v1; // rbx
__int64 result; // rax

if ( a1 )
{
v1 = a1;
do
{
free(*(void **)(v1 + 72));
BarnesHut__free(*(_QWORD *)v1);
BarnesHut__free(*(_QWORD *)(v1 + 8));
BarnesHut__free(*(_QWORD *)(v1 + 16));
BarnesHut__free(*(_QWORD *)(v1 + 24));
BarnesHut__free(*(_QWORD *)(v1 + 32));
BarnesHut__free(*(_QWORD *)(v1 + 40));
result = BarnesHut__free(*(_QWORD *)(v1 + 48));
v1 = *(_QWORD *)(v1 + 56);
}
while ( v1 );
}
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(__int64 *a1, float a2, float a3, float a4, float a5)
{
float *v5; // rax
__int64 v6; // rdi

if ( !a1 )
return 0LL;
v5 = (float *)malloc(0x10uLL);
if ( !v5 )
return 0LL;
v6 = *a1;
*v5 = a5;
v5[1] = a2;
v5[2] = a3;
v5[3] = a4;
OctreeNode3f_insert(v6, v5);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, float a2, float a3, float a4, float a5)
{
float *v5; // rax
__int64 v6; // rdi

if ( !a1 )
return 0LL;
v5 = (float *)malloc(0x10uLL);
if ( !v5 )
return 0LL;
v6 = *a1;
*v5 = a5;
v5[1] = a2;
v5[2] = a3;
v5[3] = a4;
OctreeNode3f_insert(v6, v5);
return 1LL;
}

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;
  }
}

variable_types: i int

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

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)),
(__m128i)(((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a7) << 32) | (unsigned int)_mm_cvtsi128_si32(a6)));
else
result = 0LL;
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

if ( a1 )
result = func5(
*a1,
a2,
a3,
a4,
(__m128i)(((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a5) << 32) | (unsigned int)_mm_cvtsi128_si32(a8)),
(__m128i)(((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(a7) << 32) | (unsigned int)_mm_cvtsi128_si32(a6)));
else
result = 0LL;
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
_DWORD *v3; // rax

puts("Enterig alfigure_add_graph.");
if ( a1 )
{
if ( a2 )
goto LABEL_3;
}
else
{
alerror("alfigure_add_graph: fig not allocated!");
if ( a2 )
goto LABEL_3;
}
alerror("alfigure_add_graph: graph not allocated!");
LABEL_3:
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!");
v3 = *(_DWORD **)(a1 + 160);
}
v3[(*(_DWORD *)(a1 + 156))++] = v2;
return puts("Exit alfigure_add_graph.");
}

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

puts("Enterig alfigure_add_graph.");
if ( a1 )
{
if ( a2 )
goto LABEL_3;
}
else
{
alerror("alfigure_add_graph: fig not allocated!");
if ( a2 )
goto LABEL_3;
}
alerror("alfigure_add_graph: graph not allocated!");
LABEL_3:
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!");
v3 = *(_DWORD **)(a1 + 160);
}
v3[(*(_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; }


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:
double *__fastcall alfigure_create_subxticks(__int64 a1, int a2)
{
int v4; // ebx
double *result; // rax
int v6; // esi
double *v7; // rcx
__int64 v8; // r8
double v9; // xmm0_8
double v10; // xmm1_8
__int64 v11; // rdi
__int64 v12; // rax

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

canonical_decompiled_code:
double *__fastcall func5(__int64 a1, int a2)
{
int v4; // ebx
double *result; // rax
int v6; // esi
double *v7; // rcx
__int64 v8; // r8
double v9; // xmm0_8
double v10; // xmm1_8
__int64 v11; // rdi
__int64 v12; // rax

v4 = *(_DWORD *)(a1 + 64) - 1;
result = (double *)malloc(8LL * (unsigned int)(a2 * v4));
*(_QWORD *)(a1 + 88) = result;
if ( !result )
{
alerror("create_subxticks: Could not allocate memory!");
result = (double *)*(unsigned int *)(a1 + 64);
v4 = (_DWORD)result - 1;
}
if ( v4 )
{
v6 = 0;
result = *(double **)(a1 + 56);
v7 = result + 1;
v8 = (__int64)&result[(unsigned int)(v4 - 1) + 1];
while ( 1 )
{
v9 = *result;
v10 = (result[1] - *result) / (double)(a2 + 1);
if ( a2 )
{
v11 = *(_QWORD *)(a1 + 88);
v12 = v11 + 8LL * v6;
do
{
v9 = v9 + v10;
v12 += 8LL;
*(double *)(v12 - 8) = v9;
}
while ( v11 + 8 * ((unsigned int)(a2 - 1) + (__int64)v6) + 8 != v12 );
v6 += a2;
}
result = v7;
if ( (double *)v8 == v7 )
break;
++v7;
}
v4 = v6;
}
*(_DWORD *)(a1 + 96) = v4;
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:
double *__fastcall alfigure_create_subyticks(__int64 a1, int a2)
{
int v4; // ebx
double *result; // rax
int v6; // esi
double *v7; // rcx
__int64 v8; // r8
double v9; // xmm0_8
double v10; // xmm1_8
__int64 v11; // rdi
__int64 v12; // rax

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

canonical_decompiled_code:
double *__fastcall func6(__int64 a1, int a2)
{
int v4; // ebx
double *result; // rax
int v6; // esi
double *v7; // rcx
__int64 v8; // r8
double v9; // xmm0_8
double v10; // xmm1_8
__int64 v11; // rdi
__int64 v12; // rax

v4 = *(_DWORD *)(a1 + 80) - 1;
result = (double *)malloc(8LL * (unsigned int)(a2 * v4));
*(_QWORD *)(a1 + 104) = result;
if ( !result )
{
alerror("create subyticks: Could not allocate memory!");
result = (double *)*(unsigned int *)(a1 + 80);
v4 = (_DWORD)result - 1;
}
if ( v4 )
{
v6 = 0;
result = *(double **)(a1 + 72);
v7 = result + 1;
v8 = (__int64)&result[(unsigned int)(v4 - 1) + 1];
while ( 1 )
{
v9 = *result;
v10 = (result[1] - *result) / (double)(a2 + 1);
if ( a2 )
{
v11 = *(_QWORD *)(a1 + 104);
v12 = v11 + 8LL * v6;
do
{
v9 = v9 + v10;
v12 += 8LL;
*(double *)(v12 - 8) = v9;
}
while ( v11 + 8 * ((unsigned int)(a2 - 1) + (__int64)v6) + 8 != v12 );
v6 += a2;
}
result = v7;
if ( (double *)v8 == v7 )
break;
++v7;
}
v4 = v6;
}
*(_DWORD *)(a1 + 112) = v4;
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
__int64 v2; // rdx

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

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

puts("subxticks:");
if ( *(_DWORD *)(a1 + 96) )
{
v1 = 0;
do
{
v2 = v1++;
printf("%.5f ", *(double *)(*(_QWORD *)(a1 + 88) + 8 * v2));
}
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
__int64 v2; // rdx

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

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

puts("subyticks:");
if ( *(_DWORD *)(a1 + 112) )
{
v1 = 0;
do
{
v2 = v1++;
printf("%.5f ", *(double *)(*(_QWORD *)(a1 + 104) + 8 * v2));
}
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; }


main

repo: goltango/ksamp

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(argv, optarg, (unsigned int)_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(argv, optarg, (unsigned int)_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


validsOpt

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)(v2 + v1));
}

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)(v2 + v1));
}

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


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
int *result; // rax

v1 = record_descs[0];
result = 0LL;
if ( record_descs[0] )
{
do
{
if ( a1 == v1 )
return &record_descs[4 * (int)result];
result = (int *)((char *)result + 1);
v1 = record_descs[4 * (_QWORD)result];
}
while ( v1 );
result = 0LL;
}
return result;
}

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

v1 = record_descs[0];
result = 0LL;
if ( record_descs[0] )
{
do
{
if ( a1 == v1 )
return &record_descs[4 * (int)result];
result = (int *)((char *)result + 1);
v1 = record_descs[4 * (_QWORD)result];
}
while ( v1 );
result = 0LL;
}
return result;
}

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:
void *exth_header_alloc()
{
return calloc(0x18uLL, 1uLL);
}

canonical_decompiled_code:
void *func3()
{
return calloc(0x18uLL, 1uLL);
}

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
__int64 v4; // rbp
__int64 v5; // rsi
int *v6; // rax
__int64 v7; // rcx
int *v8; // rbx
__int64 v9; // rcx

puts("EXTH records");
result = *(_DWORD *)(a1 + 8);
if ( result )
{
v2 = 0LL;
do
{
v4 = 16 * v2;
v5 = *(unsigned int *)(16 * v2 + *(_QWORD *)(a1 + 16));
v6 = exth_get_record_desc(*(_DWORD *)(16 * v2 + *(_QWORD *)(a1 + 16)));
v8 = v6;
v9 = (unsigned int)(*(_DWORD *)(v7 + 4) - 8);
if ( v6 )
{
printf(" <type=%d(%s),data_length=%d>\n", v5, *((const char **)v6 + 1), v9);
v3 = v8[1];
}
else
{
printf(" <type=%d(%s),data_length=%d>\n", v5, "unknown", v9);
v3 = 0;
}
++v2;
exth_record_print_content_constprop_0(v4 + *(_QWORD *)(a1 + 16), v3);
result = putchar(10);
}
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
__int64 v4; // rbp
__int64 v5; // rsi
int *v6; // rax
__int64 v7; // rcx
int *v8; // rbx
__int64 v9; // rcx

puts("EXTH records");
result = *(_DWORD *)(a1 + 8);
if ( result )
{
v2 = 0LL;
do
{
v4 = 16 * v2;
v5 = *(unsigned int *)(16 * v2 + *(_QWORD *)(a1 + 16));
v6 = func1(*(_DWORD *)(16 * v2 + *(_QWORD *)(a1 + 16)));
v8 = v6;
v9 = (unsigned int)(*(_DWORD *)(v7 + 4) - 8);
if ( v6 )
{
printf(" <type=%d(%s),data_length=%d>\n", v5, *((const char **)v6 + 1), v9);
v3 = v8[1];
}
else
{
printf(" <type=%d(%s),data_length=%d>\n", v5, "unknown", v9);
v3 = 0;
}
++v2;
func2(v4 + *(_QWORD *)(a1 + 16), v3);
result = putchar(10);
}
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:
__int16 __fastcall bs_read_2(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func0(_WORD *a1)
{
return __ROL2__(*a1, 8);
}

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:
void *mobi_header_alloc()
{
return calloc(0xACuLL, 1uLL);
}

canonical_decompiled_code:
void *func2()
{
return calloc(0xACuLL, 1uLL);
}

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:
// attributes: thunk
void mobi_header_free(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func3(void *ptr)
{
free(ptr);
}

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; }