printQueue

decompiled_code:
int __fastcall printQueue(unsigned int **a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = *a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("Node: %p\nData: %i\n", i, *i);
return result;
}

canonical_decompiled_code:
int __fastcall func11(unsigned int **a1)
{
unsigned int *i; // rbx
int result; // eax

for ( i = *a1; i; i = (unsigned int *)*((_QWORD *)i + 1) )
result = printf("Node: %p\nData: %i\n", i, *i);
return result;
}

original_code:
void printQueue(queue aQueue) {
  queueNode current = aQueue->first;
  while(current != ((void *)0)) {
    printf("Node: %p\nData: %i\n", (void*) current,
    current->data);
    current = current->next;
  }
}

canonical_original_code:
void printQueue(struct queueStruct *aQueue) {
  struct aNode *current = aQueue->first;
  while(current != ((void *)0)) {
    printf("Node: %p\nData: %i\n", (void *) current,
    current->data);
    current = current->next;
  }
}


emptyQueue

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

while ( 1 )
{
result = isQueueEmpty(a1);
if ( result )
break;
takeFromQueue(a1);
}
return result;
}

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

while ( 1 )
{
result = func8(a1);
if ( result )
break;
func7(a1);
}
return result;
}

original_code:
void emptyQueue(queue aQueue) {
  while(!isQueueEmpty(aQueue)) {
    takeFromQueue(aQueue);
  }
}

canonical_original_code:
void emptyQueue(struct queueStruct *aQueue) {
  while(!isQueueEmpty(aQueue)) {
    takeFromQueue(aQueue);
  }
}

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

return_type: void

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


wci

decompiled_code:
float __fastcall wci(int a1, int a2)
{
float result; // xmm0_4

if ( a2 > 3 && a1 <= 49 )
result = ((double)a1 * 0.4275 - 35.75) * powf((float)a2, 0.16) + (double)a1 * 0.6215000000000001 + 35.74;
else
result = (float)a1;
return result;
}

canonical_decompiled_code:
float __fastcall func7(int a1, int a2)
{
float result; // xmm0_4

if ( a2 > 3 && a1 <= 49 )
result = ((double)a1 * 0.4275 - 35.75) * powf((float)a2, 0.16) + (double)a1 * 0.6215000000000001 + 35.74;
else
result = (float)a1;
return result;
}

original_code:
float wci(int temperature, int wind_speed) {
 float result;
 if(wind_speed <= 3 || temperature >= 50) {
  result = temperature;
 } else {
 result = 35.74 + 0.6215*temperature + (0.4275*temperature - 35.75) *
  powf(wind_speed,0.16);
 }
 return result;
}

variable_types: temperature int

variable_types: result float

return_type: float


GetArrayMinMax

repo: rreusser/octree-gravity

decompiled_code:
void __fastcall GetArrayMinMax(double *a1, int a2, double *a3, double *a4)
{
double *v6; // rbx

*(_QWORD *)a3 = COERCE_UNSIGNED_INT64(log(0.0)) ^ LC4;
*a4 = log(0.0);
if ( a2 > 0 )
{
v6 = a1;
do
{
*a3 = fmin(*v6, *a3);
*a4 = fmax(*v6++, *a4);
}
while ( v6 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

canonical_decompiled_code:
void __fastcall func1(double *a1, int a2, double *a3, double *a4)
{
double *v6; // rbx

*(_QWORD *)a3 = COERCE_UNSIGNED_INT64(log(0.0)) ^ LC4;
*a4 = log(0.0);
if ( a2 > 0 )
{
v6 = a1;
do
{
*a3 = fmin(*v6, *a3);
*a4 = fmax(*v6++, *a4);
}
while ( v6 != &a1[(unsigned int)(a2 - 1) + 1] );
}
}

original_code:
void GetArrayMinMax( real* a, const int n, real* min, real* max) {
    int i;
    *min = -log(0);
    *max = log(0);
    for(i=0;i<n;i++) {
 *min = fmin(a[i],*min);
 *max = fmax(a[i],*max);
    }
}

canonical_original_code:
void GetArrayMinMax(double *a, int n, double *min, double *max) {
    int i;
    *min = -log(0);
    *max = log(0);
    for(i=0;i<n;i++) {
 *min = fmin(a[i],*min);
 *max = fmax(a[i],*max);
    }
}

variable_types:
a
double *

variable_types: n int

variable_types:
min
double *

variable_types:
max
double *

variable_types: i int


GetIntArrayMinMax

decompiled_code:
unsigned __int64 __fastcall GetIntArrayMinMax(_DWORD *a1, int a2, int *a3, int *a4)
{
unsigned __int64 result; // rax
int v7; // edx
int v8; // edx

*a3 = (int)COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(0.0)) ^ LC4);
result = (unsigned int)(int)log(0.0);
*a4 = result;
if ( a2 > 0 )
{
result = (unsigned __int64)a1;
do
{
v7 = *(_DWORD *)result;
if ( *a3 <= *(_DWORD *)result )
v7 = *a3;
*a3 = v7;
v8 = *a4;
if ( *(_DWORD *)result >= *a4 )
v8 = *(_DWORD *)result;
*a4 = v8;
result += 4LL;
}
while ( (_DWORD *)result != &a1[a2 - 1 + 1] );
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_DWORD *a1, int a2, int *a3, int *a4)
{
unsigned __int64 result; // rax
int v7; // edx
int v8; // edx

*a3 = (int)COERCE_DOUBLE(COERCE_UNSIGNED_INT64(log(0.0)) ^ LC4);
result = (unsigned int)(int)log(0.0);
*a4 = result;
if ( a2 > 0 )
{
result = (unsigned __int64)a1;
do
{
v7 = *(_DWORD *)result;
if ( *a3 <= *(_DWORD *)result )
v7 = *a3;
*a3 = v7;
v8 = *a4;
if ( *(_DWORD *)result >= *a4 )
v8 = *(_DWORD *)result;
*a4 = v8;
result += 4LL;
}
while ( (_DWORD *)result != &a1[a2 - 1 + 1] );
}
return result;
}

original_code:
void GetIntArrayMinMax( int* a, const int n, int* min, int* max) {
    int i;
    *min = -log(0);
    *max = log(0);
    for(i=0;i<n;i++) {
 *min = ((a[i])<(*min)?(a[i]):(*min));
 *max = ((a[i])<(*max)?(*max):(a[i]));
    }
}

canonical_original_code:
void GetIntArrayMinMax(int *a, int n, int *min, int *max) {
    int i;
    *min = -log(0);
    *max = log(0);
    for(i=0;i<n;i++) {
 *min = ((a[i])<(*min)?(a[i]):(*min));
 *max = ((a[i])<(*max)?(*max):(a[i]));
    }
}

variable_types:
a
int *

variable_types:
min
int *

variable_types:
max
int *


dbgp

decompiled_code:
int __fastcall dbgp(const char *a1, __int64 a2)
{
return fprintf(stderr, "%s = 0x%x\n", a1, a2);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, __int64 a2)
{
return fprintf(stderr, "%s = 0x%x\n", a1, a2);
}

original_code:
void dbgp( const char* s, void* ptr ) {
    fprintf(stderr,"%s = 0x%x\n",s,(unsigned int)ptr);
}

canonical_original_code:
void dbgp(char *s, void *ptr) {
    fprintf(stderr,"%s = 0x%x\n",s,(unsigned int)ptr);
}

variable_types:
s
char *

variable_types:
ptr
void *


decompiled_code:
char *__fastcall create_filename(char *s, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5)
{
char *result; // rax
int v8; // edx
char *v9; // rdx
char sa[50]; // [rsp+6h] [rbp-32h] BYREF

sprintf(sa, "%%s%%%ii%%s", a4);
sprintf(s, sa, a2, a3, a5);
result = (char *)strlen(s);
if ( (int)result > 0 )
{
v8 = (int)result;
result = s;
v9 = &s[v8 - 1 + 1];
do
{
if ( *result == 32 )
*result = 48;
++result;
}
while ( result != v9 );
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *s, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5)
{
char *result; // rax
int v8; // edx
char *v9; // rdx
char sa[50]; // [rsp+6h] [rbp-32h] BYREF

sprintf(sa, "%%s%%%ii%%s", a4);
sprintf(s, sa, a2, a3, a5);
result = (char *)strlen(s);
if ( (int)result > 0 )
{
v8 = (int)result;
result = s;
v9 = &s[v8 - 1 + 1];
do
{
if ( *result == 32 )
*result = 48;
++result;
}
while ( result != v9 );
}
return result;
}

original_code:
void create_filename(char* dest, const char* prefix, int i, int digits, const char* suffix ) {
    char fmt[10];
    int l;
    sprintf(fmt,"%%s%%%ii%%s",digits);
    sprintf(dest,fmt,prefix,i,suffix);
    l=strlen(dest);
    for(i=0;i<l;i++) {
 if(dest[i]==' ') {
     dest[i]='0';
 }
    }
}

canonical_original_code:
void create_filename(char *dest, char *prefix, int i, int digits, char *suffix) {
    char fmt[10];
    int l;
    sprintf(fmt,"%%s%%%ii%%s",digits);
    sprintf(dest,fmt,prefix,i,suffix);
    l=strlen(dest);
    for(i=0;i<l;i++) {
 if(dest[i]==' ') {
     dest[i]='0';
 }
    }
}

variable_types:
dest
char *

variable_types:
prefix
char *

variable_types: digits int

variable_types:
suffix
char *

variable_types:
fmt
char [10]

variable_types: l int


vfAdd

decompiled_code:
float *__fastcall vfAdd(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = *a2 + *a3;
a1[1] = a2[1] + a3[1];
a1[2] = a2[2] + a3[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func0(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = *a2 + *a3;
a1[1] = a2[1] + a3[1];
a1[2] = a2[2] + a3[2];
return result;
}

original_code:
vector3f* vfAdd(vector3f* A, vector3f* B, vector3f* C) {
    A->x = B->x+C->x;
    A->y = B->y+C->y;
    A->z = B->z+C->z;
    return A;
}

canonical_original_code:
struct vector3f *vfAdd(struct vector3f *A, struct vector3f *B, struct vector3f *C) {
    A->x = B->x+C->x;
    A->y = B->y+C->y;
    A->z = B->z+C->z;
    return A;
}

variable_types:
A
struct vector3f *

variable_types:
B
struct vector3f *

variable_types:
C
struct vector3f *

return_type: struct vector3f { float x; } *


vfPlusEq

decompiled_code:
float *__fastcall vfPlusEq(float *a1, float *a2)
{
float *result; // rax

result = a1;
*a1 = *a1 + *a2;
a1[1] = a1[1] + a2[1];
a1[2] = a1[2] + a2[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func1(float *a1, float *a2)
{
float *result; // rax

result = a1;
*a1 = *a1 + *a2;
a1[1] = a1[1] + a2[1];
a1[2] = a1[2] + a2[2];
return result;
}

original_code:
vector3f* vfPlusEq(vector3f* A, vector3f* B) {
    A->x += B->x;
    A->y += B->y;
    A->z += B->z;
    return A;
}

canonical_original_code:
struct vector3f *vfPlusEq(struct vector3f *A, struct vector3f *B) {
    A->x += B->x;
    A->y += B->y;
    A->z += B->z;
    return A;
}


vfSub

decompiled_code:
float *__fastcall vfSub(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = *a2 - *a3;
a1[1] = a2[1] - a3[1];
a1[2] = a2[2] - a3[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func2(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = *a2 - *a3;
a1[1] = a2[1] - a3[1];
a1[2] = a2[2] - a3[2];
return result;
}

original_code:
vector3f* vfSub(vector3f* A, vector3f* B, vector3f* C) {
    A->x = B->x-C->x;
    A->y = B->y-C->y;
    A->z = B->z-C->z;
    return A;
}

canonical_original_code:
struct vector3f *vfSub(struct vector3f *A, struct vector3f *B, struct vector3f *C) {
    A->x = B->x-C->x;
    A->y = B->y-C->y;
    A->z = B->z-C->z;
    return A;
}


vfMinusEq

decompiled_code:
float *__fastcall vfMinusEq(float *a1, float *a2)
{
float *result; // rax

result = a1;
*a1 = *a1 - *a2;
a1[1] = a1[1] - a2[1];
a1[2] = a1[2] - a2[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func3(float *a1, float *a2)
{
float *result; // rax

result = a1;
*a1 = *a1 - *a2;
a1[1] = a1[1] - a2[1];
a1[2] = a1[2] - a2[2];
return result;
}

original_code:
vector3f* vfMinusEq(vector3f* A, vector3f* B) {
    A->x -= B->x;
    A->y -= B->y;
    A->z -= B->z;
    return A;
}

canonical_original_code:
struct vector3f *vfMinusEq(struct vector3f *A, struct vector3f *B) {
    A->x -= B->x;
    A->y -= B->y;
    A->z -= B->z;
    return A;
}


vfMult

decompiled_code:
float *__fastcall vfMult(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = *a2 * *a3;
a1[1] = a2[1] * a3[1];
a1[2] = a2[2] * a3[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func4(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = *a2 * *a3;
a1[1] = a2[1] * a3[1];
a1[2] = a2[2] * a3[2];
return result;
}

original_code:
vector3f* vfMult(vector3f* A, vector3f* B, vector3f* C) {
    A->x = B->x*C->x;
    A->y = B->y*C->y;
    A->z = B->z*C->z;
    return A;
}

canonical_original_code:
struct vector3f *vfMult(struct vector3f *A, struct vector3f *B, struct vector3f *C) {
    A->x = B->x*C->x;
    A->y = B->y*C->y;
    A->z = B->z*C->z;
    return A;
}


vfTimesEq

decompiled_code:
float *__fastcall vfTimesEq(float *a1, float *a2)
{
float *result; // rax

result = a1;
*a1 = *a1 * *a2;
a1[1] = a1[1] * a2[1];
a1[2] = a1[2] * a2[2];
return result;
}

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

result = a1;
*a1 = *a1 * *a2;
a1[1] = a1[1] * a2[1];
a1[2] = a1[2] * a2[2];
return result;
}

original_code:
vector3f* vfTimesEq(vector3f* A, vector3f* B) {
    A->x *= B->x;
    A->y *= B->y;
    A->z *= B->z;
    return A;
}

canonical_original_code:
struct vector3f *vfTimesEq(struct vector3f *A, struct vector3f *B) {
    A->x *= B->x;
    A->y *= B->y;
    A->z *= B->z;
    return A;
}


vffMult

decompiled_code:
float *__fastcall vffMult(float *a1, float *a2, float a3)
{
float *result; // rax

result = a1;
*a1 = a3 * *a2;
a1[1] = a3 * a2[1];
a1[2] = a3 * a2[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func6(float *a1, float *a2, float a3)
{
float *result; // rax

result = a1;
*a1 = a3 * *a2;
a1[1] = a3 * a2[1];
a1[2] = a3 * a2[2];
return result;
}

original_code:
vector3f* vffMult(vector3f* A, vector3f* B, float mult) {
    A->x = B->x * mult;
    A->y = B->y * mult;
    A->z = B->z * mult;
    return A;
}

canonical_original_code:
struct vector3f *vffMult(struct vector3f *A, struct vector3f *B, float mult) {
    A->x = B->x * mult;
    A->y = B->y * mult;
    A->z = B->z * mult;
    return A;
}

variable_types: mult float


vffTimesEq

decompiled_code:
float *__fastcall vffTimesEq(float *a1, float a2)
{
float *result; // rax

result = a1;
*a1 = a2 * *a1;
a1[1] = a2 * a1[1];
a1[2] = a2 * a1[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func7(float *a1, float a2)
{
float *result; // rax

result = a1;
*a1 = a2 * *a1;
a1[1] = a2 * a1[1];
a1[2] = a2 * a1[2];
return result;
}

original_code:
vector3f* vffTimesEq(vector3f* A, float mult) {
    A->x *= mult;
    A->y *= mult;
    A->z *= mult;
    return A;
}

canonical_original_code:
struct vector3f *vffTimesEq(struct vector3f *A, float mult) {
    A->x *= mult;
    A->y *= mult;
    A->z *= mult;
    return A;
}


vfDiv

decompiled_code:
float *__fastcall vfDiv(float *a1, float *a2)
{
float *result; // rax

result = a1;
*a1 = *a1 / *a2;
a1[1] = a1[1] / a2[1];
a1[2] = a1[2] / a2[2];
return result;
}

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

result = a1;
*a1 = *a1 / *a2;
a1[1] = a1[1] / a2[1];
a1[2] = a1[2] / a2[2];
return result;
}

original_code:
vector3f* vfDiv(vector3f* A, vector3f* B, vector3f* C) {
    A->x = A->x/B->x;
    A->y = A->y/B->y;
    A->z = A->z/B->z;
    return A;
}

canonical_original_code:
struct vector3f *vfDiv(struct vector3f *A, struct vector3f *B, struct vector3f *C) {
    A->x = A->x/B->x;
    A->y = A->y/B->y;
    A->z = A->z/B->z;
    return A;
}


vfDivEq

decompiled_code:
float *__fastcall vfDivEq(float *a1, float *a2)
{
float *result; // rax

result = a1;
*a1 = *a1 / *a2;
a1[1] = a1[1] / a2[1];
a1[2] = a1[2] / a2[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func9(float *a1, float *a2)
{
float *result; // rax

result = a1;
*a1 = *a1 / *a2;
a1[1] = a1[1] / a2[1];
a1[2] = a1[2] / a2[2];
return result;
}

original_code:
vector3f* vfDivEq(vector3f* A, vector3f* B) {
    A->x /= B->x;
    A->y /= B->y;
    A->z /= B->z;
    return A;
}

canonical_original_code:
struct vector3f *vfDivEq(struct vector3f *A, struct vector3f *B) {
    A->x /= B->x;
    A->y /= B->y;
    A->z /= B->z;
    return A;
}


vffDiv

decompiled_code:
float *__fastcall vffDiv(float *a1, float *a2, float a3)
{
float *result; // rax

result = a1;
*a1 = *a2 / a3;
a1[1] = a2[1] / a3;
a1[2] = a2[2] / a3;
return result;
}

canonical_decompiled_code:
float *__fastcall func10(float *a1, float *a2, float a3)
{
float *result; // rax

result = a1;
*a1 = *a2 / a3;
a1[1] = a2[1] / a3;
a1[2] = a2[2] / a3;
return result;
}

original_code:
vector3f* vffDiv(vector3f* A, vector3f* B, float div) {
    A->x = B->x / div;
    A->y = B->y / div;
    A->z = B->z / div;
    return A;
}

canonical_original_code:
struct vector3f *vffDiv(struct vector3f *A, struct vector3f *B, float div) {
    A->x = B->x / div;
    A->y = B->y / div;
    A->z = B->z / div;
    return A;
}

variable_types: div float


vffDivEq

decompiled_code:
float *__fastcall vffDivEq(float *a1, float a2)
{
float *result; // rax

result = a1;
*a1 = *a1 / a2;
a1[1] = a1[1] / a2;
a1[2] = a1[2] / a2;
return result;
}

canonical_decompiled_code:
float *__fastcall func11(float *a1, float a2)
{
float *result; // rax

result = a1;
*a1 = *a1 / a2;
a1[1] = a1[1] / a2;
a1[2] = a1[2] / a2;
return result;
}

original_code:
vector3f* vffDivEq(vector3f* A, float div) {
    A->x /= div;
    A->y /= div;
    A->z /= div;
    return A;
}

canonical_original_code:
struct vector3f *vffDivEq(struct vector3f *A, float div) {
    A->x /= div;
    A->y /= div;
    A->z /= div;
    return A;
}


vfDot

decompiled_code:
float __fastcall vfDot(float *a1, float *a2)
{
return (float)(a1[2] * a2[2]) + (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1]));
}

canonical_decompiled_code:
float __fastcall func12(float *a1, float *a2)
{
return (float)(a1[2] * a2[2]) + (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1]));
}

original_code:
float vfDot(vector3f* A, vector3f* B) {
    float sum;
    sum=A->x*B->x;
    sum+=A->y*B->y;
    sum+=A->z*B->z;
    return sum;
}

canonical_original_code:
float vfDot(struct vector3f *A, struct vector3f *B) {
    float sum;
    sum=A->x*B->x;
    sum+=A->y*B->y;
    sum+=A->z*B->z;
    return sum;
}

variable_types:
A
struct vector3f { float x; } *

variable_types: sum float


vfLength

decompiled_code:
float __fastcall vfLength(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = (float)(a1[2] * a1[2]) + (float)((float)(*a1 * *a1) + (float)(a1[1] * a1[1]));
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

canonical_decompiled_code:
float __fastcall func13(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = (float)(a1[2] * a1[2]) + (float)((float)(*a1 * *a1) + (float)(a1[1] * a1[1]));
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

original_code:
float vfLength(vector3f* A) {
    float len = sqrt(A->x*A->x+A->y*A->y+A->z*A->z);
    return len;
}

canonical_original_code:
float vfLength(struct vector3f *A) {
    float len = sqrt(A->x*A->x+A->y*A->y+A->z*A->z);
    return len;
}

variable_types: len float


vfNormalize

decompiled_code:
float *__fastcall vfNormalize(float *a1)
{
float v1; // xmm0_4

v1 = vfLength(a1);
*a1 = *a1 / v1;
a1[1] = a1[1] / v1;
a1[2] = a1[2] / v1;
return a1;
}

original_code:
vector3f* vfNormalize(vector3f* A) {
    float len = vfLength(A);
    A->x /= len;
    A->y /= len;
    A->z /= len;
    return A;
}

canonical_original_code:
struct vector3f *vfNormalize(struct vector3f *A) {
    float len = vfLength(A);
    A->x /= len;
    A->y /= len;
    A->z /= len;
    return A;
}


vfCross

decompiled_code:
float *__fastcall vfCross(float *a1, float *a2, float *a3)
{
float *result; // rax

result = a1;
*a1 = (float)(a2[1] * a3[2]) - (float)(a2[2] * a3[1]);
a1[1] = (float)(a2[2] * *a3) - (float)(*a2 * a3[2]);
a1[2] = (float)(*a2 * a3[1]) - (float)(a2[1] * *a3);
return result;
}

original_code:
vector3f* vfCross(vector3f* A, vector3f* B, vector3f* C) {
    A->x = B->y*C->z - B->z*C->y;
    A->y = B->z*C->x - B->x*C->z;
    A->z = B->x*C->y - B->y*C->x;
    return A;
}

canonical_original_code:
struct vector3f *vfCross(struct vector3f *A, struct vector3f *B, struct vector3f *C) {
    A->x = B->y*C->z - B->z*C->y;
    A->y = B->z*C->x - B->x*C->z;
    A->z = B->x*C->y - B->y*C->x;
    return A;
}


vfAxisRotate

original_code:
vector3f* vfAxisRotate(vector3f* target, vector3f* origin, vector3f* axis, double theta) {
    double x = target->x;
    double y = target->y;
    double z = target->z;
    double a = origin->x;
    double b = origin->y;
    double c = origin->z;
    double u = axis->x;
    double v = axis->y;
    double w = axis->z;
    target->x = (a*(v*v+w*w)+u*(-b*v-c*w+u*x+v*y+w*z)+
 ((x-a)*(v*v+w*w)+u*(b*v+c*w-v*y-w*z))*cos(theta)+
 sqrt(u*u+v*v+w*w)*(b*w-c*v-w*y+v*z)*sin(theta))/
 (u*u+v*v+w*w);
    target->y = (b*(u*u+w*w)+v*(-a*u-c*w+u*x+v*y+w*z)+
 ((y-b)*(u*u+w*w)+v*(a*u+c*w-u*x-w*z))*cos(theta)+
 sqrt(u*u+v*v+w*w)*(-a*w+c*u+w*x-u*z)*sin(theta))/
 (u*u+v*v+w*w);
    target->z = (c*(u*u+v*v)+w*(-a*u-b*v+u*x+v*y+w*z)+
 ((z-c)*(u*u+v*v)+w*(a*u+b*v-u*x-v*y))*cos(theta)+
 sqrt(u*u+v*v+w*w)*(a*v-b*u-v*x+u*y)*sin(theta))/
 (u*u+v*v+w*w);
    return target;
}

canonical_original_code:
struct vector3f *vfAxisRotate(struct vector3f *target, struct vector3f *origin, struct vector3f *axis, double theta) {
    double x = target->x;
    double y = target->y;
    double z = target->z;
    double a = origin->x;
    double b = origin->y;
    double c = origin->z;
    double u = axis->x;
    double v = axis->y;
    double w = axis->z;
    target->x = (a*(v*v+w*w)+u*(-b*v-c*w+u*x+v*y+w*z)+
 ((x-a)*(v*v+w*w)+u*(b*v+c*w-v*y-w*z))*cos(theta)+
 sqrt(u*u+v*v+w*w)*(b*w-c*v-w*y+v*z)*sin(theta))/
 (u*u+v*v+w*w);
    target->y = (b*(u*u+w*w)+v*(-a*u-c*w+u*x+v*y+w*z)+
 ((y-b)*(u*u+w*w)+v*(a*u+c*w-u*x-w*z))*cos(theta)+
 sqrt(u*u+v*v+w*w)*(-a*w+c*u+w*x-u*z)*sin(theta))/
 (u*u+v*v+w*w);
    target->z = (c*(u*u+v*v)+w*(-a*u-b*v+u*x+v*y+w*z)+
 ((z-c)*(u*u+v*v)+w*(a*u+b*v-u*x-v*y))*cos(theta)+
 sqrt(u*u+v*v+w*w)*(a*v-b*u-v*x+u*y)*sin(theta))/
 (u*u+v*v+w*w);
    return target;
}

variable_types:
target
struct vector3f *

variable_types:
origin
struct vector3f *

variable_types:
axis
struct vector3f *

variable_types: theta double

variable_types: x double

variable_types: y double

variable_types: z double

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: u double

variable_types: v double

variable_types: w double


glDisplay

decompiled_code:
__int64 glDisplay()
{
int i; // ebx
__m128i v2; // xmm3
unsigned int v3; // er14
__int64 v4; // [rsp+0h] [rbp-38h] BYREF

glClear(16640LL);
if ( axisOn )
{
glBegin(1LL);
for ( i = -10; i != 12; i += 2 )
{
glColor3f(0.2, 0.2);
v2 = 0LL;
*(float *)v2.m128i_i32 = (double)i / 10.0;
v3 = _mm_cvtsi128_si32(v2);
glVertex3f(*(double *)v2.m128i_i64, -0.50099999, 1.0);
glVertex3f(*(double *)_mm_cvtsi32_si128(v3).m128i_i64, -0.50099999, -1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC4), -0.50099999, *(float *)&v3);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC2), -0.50099999, *(float *)&v3);
glColor3f(1.0, 1.0);
glVertex3f(*(double *)_mm_cvtsi32_si128(v3).m128i_i64, -0.50099999, 0.02);
glVertex3f(*(double *)_mm_cvtsi32_si128(v3).m128i_i64, -0.50099999, -0.02);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC6), -0.50099999, *(float *)&v3);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC5), -0.50099999, *(float *)&v3);
}
glColor3f(1.0, 1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC4), -0.50099999, 0.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC2), -0.50099999, 0.0);
glVertex3f(0.0, -0.50099999, -1.0);
glVertex3f(0.0, -0.50099999, 1.0);
glEnd();
}
if ( simulationOn == 1 && nextdisp == 1 )
{
iterate();
++frame;
nextdisp = 0;
}
if ( sampleForceOn )
{
glColor3f(0.0, 1.0);
octree_add_forces_draw(&v4, ot, p, (unsigned int)sample, 0.0, 1.0, 0.5);
}
if ( drawOctreeOn )
{
glColor3f(0.0, 0.0);
draw_octree(ot, 0.0, 0.0, 1.0);
}
if ( drawTreeOn )
{
glColor3f(0.0, 1.0);
draw_children(*(_QWORD *)(ot + 56LL));
}
glColor3f(1.0, 1.0);
draw_particles(p);
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func0()
{
int i; // ebx
__m128i v2; // xmm3
unsigned int v3; // er14
__int64 v4; // [rsp+0h] [rbp-38h] BYREF

glClear(16640LL);
if ( axisOn )
{
glBegin(1LL);
for ( i = -10; i != 12; i += 2 )
{
glColor3f(0.2, 0.2);
v2 = 0LL;
*(float *)v2.m128i_i32 = (double)i / 10.0;
v3 = _mm_cvtsi128_si32(v2);
glVertex3f(*(double *)v2.m128i_i64, -0.50099999, 1.0);
glVertex3f(*(double *)_mm_cvtsi32_si128(v3).m128i_i64, -0.50099999, -1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC4), -0.50099999, *(float *)&v3);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC2), -0.50099999, *(float *)&v3);
glColor3f(1.0, 1.0);
glVertex3f(*(double *)_mm_cvtsi32_si128(v3).m128i_i64, -0.50099999, 0.02);
glVertex3f(*(double *)_mm_cvtsi32_si128(v3).m128i_i64, -0.50099999, -0.02);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC6), -0.50099999, *(float *)&v3);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC5), -0.50099999, *(float *)&v3);
}
glColor3f(1.0, 1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC4), -0.50099999, 0.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC2), -0.50099999, 0.0);
glVertex3f(0.0, -0.50099999, -1.0);
glVertex3f(0.0, -0.50099999, 1.0);
glEnd();
}
if ( simulationOn == 1 && nextdisp == 1 )
{
iterate();
++frame;
nextdisp = 0;
}
if ( sampleForceOn )
{
glColor3f(0.0, 1.0);
octree_add_forces_draw(&v4, ot, p, (unsigned int)sample, 0.0, 1.0, 0.5);
}
if ( drawOctreeOn )
{
glColor3f(0.0, 0.0);
draw_octree(ot, 0.0, 0.0, 1.0);
}
if ( drawTreeOn )
{
glColor3f(0.0, 1.0);
draw_children(*(_QWORD *)(ot + 56LL));
}
glColor3f(1.0, 1.0);
draw_particles(p);
return glutSwapBuffers();
}

original_code:
void glDisplay() {
    int i;
    glClear(0x00004000 | 0x00000100);
    if(axisOn) {
 glBegin( 0x0001 );
 float eps = 0.501;
 for(i=-10; i<=10; i+=2) {
     glColor3f(0.2,0.2,0.2);
     glVertex3f(i/10.0,-eps,1.0);
     glVertex3f(i/10.0,-eps,-1.0);
     glVertex3f(-1.0,-eps,i/10.0);
     glVertex3f(1.0,-eps,i/10.0);
     glColor3f(1.0,1.0,1.0);
     glVertex3f(i/10.0,-eps,0.02);
     glVertex3f(i/10.0,-eps,-0.02);
     glVertex3f(-0.02,-eps,i/10.0);
     glVertex3f(0.02,-eps,i/10.0);
 }
 glColor3f(1.0,1.0,1.0);
 glVertex3f(-1.0,-eps,0.0);
 glVertex3f(1.0,-eps,0.0);
 glVertex3f(0.0,-eps,-1.0);
 glVertex3f(0.0,-eps,1.0);
 glEnd();
    }
    if(simulationOn==1 && nextdisp==1) {
 iterate();
 frame++;
 nextdisp=0;
    }
    if(sampleForceOn) {
 glColor3f(0.0,1.0,0.5);
 octree_add_forces_draw( ot, p, sample );
    }
    if(drawOctreeOn) {
 glColor3f(0.0,0.0,1.0);
 draw_octree( ot );
    }
    if(drawTreeOn) {
 glColor3f(0.0,1.0,1.0);
 draw_children( ot->root );
    }
    glColor3f(1.0,1.0,1.0);
    draw_particles( p );
    glutSwapBuffers();
}

variable_types: i int

variable_types: eps float


glRedisplay

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

if ( a1 == 1 )
result = glDisplay();
if ( simulationOn == 1 )
{
result = glutTimerFunc((unsigned int)(1000 / fps), glRedisplay, 1LL);
nextdisp = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax

if ( a1 == 1 )
result = func0();
if ( simulationOn == 1 )
{
result = glutTimerFunc((unsigned int)(1000 / fps), glRedisplay, 1LL);
nextdisp = 1;
}
return result;
}

original_code:
void glRedisplay(int value) {
    if(value==1) {
 glDisplay();
    }
    if(simulationOn==1) {
 glutTimerFunc(1000/fps,glRedisplay,1);
 nextdisp=1;
    }
}

variable_types: value int


glReView

decompiled_code:
__int64 glReView()
{
return MakeOGLCamera(cam);
}

canonical_decompiled_code:
__int64 func2()
{
return MakeOGLCamera(cam);
}

original_code: void glReView() { MakeOGLCamera(cam); }

canonical_original_code: void glReView() { MakeOGLCamera(cam); }


glReshape

decompiled_code:
__int64 __fastcall glReshape(unsigned int a1, unsigned int a2)
{
CameraReshapeWindow(cam, a1, a2);
return glReView();
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2)
{
CameraReshapeWindow(cam, a1, a2);
return func2();
}

original_code:
void glReshape(int w, int h) {
    CameraReshapeWindow(cam,w,h);
    glReView();
}

variable_types: w int

variable_types: h int


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

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

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

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

original_code:
void free_particles( particles* p ) {
    if(p) {
 if(p->x) { free(p->x); }
 if(p->m) { free(p->m); }
 free(p);
    }
}

canonical_original_code:
void free_particles(struct particles *p) {
    if(p) {
 if(p->x) { free(p->x); }
 if(p->m) { free(p->m); }
 free(p);
    }
}

variable_types: struct particles { int n; double *x; double *m; double G; double dt; void (*gravity)(double, double *, int, double *, void *); void (*integrate)(double *y, void (*deriv_func)(double, double *, int, double *, void *), double x, int n, double h, void *data); } *


original_code:
void randomize_particles( particles* p, real xmin, real xmax, real ymin, real ymax, real zmin, real zmax, real vel_scale ) {
    int i;
    srand48(21);
    real dx = xmax-xmin;
    real dy = ymax-ymin;
    real dz = zmax-zmin;
    for(i=0;i<p->n*6;i+=6) {
 p->x[i ] = xmin + dx*drand48();
 p->x[i+1] = ymin + dy*drand48();
 p->x[i+2] = zmin + dz*drand48();
 p->x[i+3] = 2.0*(drand48()-0.5)*vel_scale;
 p->x[i+4] = 2.0*(drand48()-0.5)*vel_scale;
 p->x[i+5] = 2.0*(drand48()-0.5)*vel_scale;
    }
}

canonical_original_code:
void randomize_particles(struct particles *p, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double vel_scale) {
    int i;
    srand48(21);
    double dx = xmax-xmin;
    double dy = ymax-ymin;
    double dz = zmax-zmin;
    for(i=0;i<p->n*6;i+=6) {
 p->x[i ] = xmin + dx*drand48();
 p->x[i+1] = ymin + dy*drand48();
 p->x[i+2] = zmin + dz*drand48();
 p->x[i+3] = 2.0*(drand48()-0.5)*vel_scale;
 p->x[i+4] = 2.0*(drand48()-0.5)*vel_scale;
 p->x[i+5] = 2.0*(drand48()-0.5)*vel_scale;
    }
}

variable_types: xmin double

variable_types: xmax double

variable_types: ymin double

variable_types: ymax double

variable_types: zmin double

variable_types: zmax double

variable_types: dx double

variable_types: dy double

variable_types: dz double

user_defined_types: struct particles { int n; double *x; double *m; double G; double dt; void (*gravity)(double, double *, int, double *, void *); void (*integrate)(double *y, void (*deriv_func)(double, double *, int, double *, void *), double x, int n, double h, void *data); }


decompiled_code:
void __fastcall uniform_masses(__int64 a1, double a2)
{
__int64 v2; // rax

if ( *(int *)a1 > 0 )
{
v2 = 0LL;
do
*(double *)(*(_QWORD *)(a1 + 16) + 8 * v2++) = a2;
while ( *(_DWORD *)a1 > (int)v2 );
}
}

original_code:
void uniform_masses( particles* p, real mass ) {
    int i;
    for(i=0;i<p->n;i++) {
 p->m[i] = mass;
    }
}

canonical_original_code:
void uniform_masses(struct particles *p, double mass) {
    int i;
    for(i=0;i<p->n;i++) {
 p->m[i] = mass;
    }
}

variable_types: mass double


decompiled_code:
__int64 __fastcall randomize_masses(__int64 a1, double a2, double a3)
{
__int64 v4; // rbx
double v5; // xmm1_8
__int64 result; // rax

if ( *(int *)a1 > 0 )
{
v4 = 0LL;
do
{
v5 = drand48();
result = *(_QWORD *)(a1 + 16);
*(double *)(result + 8 * v4++) = (a3 - a2) * v5 + a2;
}
while ( *(_DWORD *)a1 > (int)v4 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, double a2, double a3)
{
__int64 v4; // rbx
double v5; // xmm1_8
__int64 result; // rax

if ( *(int *)a1 > 0 )
{
v4 = 0LL;
do
{
v5 = drand48();
result = *(_QWORD *)(a1 + 16);
*(double *)(result + 8 * v4++) = (a3 - a2) * v5 + a2;
}
while ( *(_DWORD *)a1 > (int)v4 );
}
return result;
}

original_code:
void randomize_masses( particles* p, real mmin, real mmax ) {
    int i;
    for(i=0;i<p->n;i++) {
 p->m[i] = mmin + drand48()*(mmax-mmin);
    }
}

canonical_original_code:
void randomize_masses(struct particles *p, double mmin, double mmax) {
    int i;
    for(i=0;i<p->n;i++) {
 p->m[i] = mmin + drand48()*(mmax-mmin);
    }
}

variable_types: mmin double

variable_types: mmax double


decompiled_code:
__int64 __fastcall draw_particles(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
__int64 v3; // rax
float v4; // xmm0_4
float v5; // xmm2_4
float v6; // xmm1_4

glPointSize(2.0);
glBegin(0LL);
if ( *(int *)a1 > 0 )
{
v1 = 16LL;
v2 = 0;
do
{
v3 = *(_QWORD *)(a1 + 8);
v4 = *(double *)(v3 + v1 - 16);
v5 = *(double *)(v3 + v1);
v6 = *(double *)(v3 + v1 - 8);
glVertex3f(v4, v6, v5);
++v2;
v1 += 48LL;
}
while ( *(_DWORD *)a1 > v2 );
}
return glEnd();
}

original_code:
void draw_particles( particles* p ) {
    int i;
    glPointSize(2.0);
    glBegin( 0x0000 );
    for(i=0;i<p->n;i++) {
 glVertex3f( p->x[6*i], p->x[6*i+1], p->x[6*i+2] );
    }
    glEnd();
}

canonical_original_code:
void draw_particles(struct particles *p) {
    int i;
    glPointSize(2.0);
    glBegin( 0x0000 );
    for(i=0;i<p->n;i++) {
 glVertex3f( p->x[6*i], p->x[6*i+1], p->x[6*i+2] );
    }
    glEnd();
}

variable_types: i int


original_code:
void bound_particles( particles* p, real range ) {
    int i,i6,j;
    for(i=0;i<p->n;i++) {
 i6 = i*6;
 for(j=0;j<3;j++) {
     if(fabs(p->x[i6+j]) > range ) {
  p->x[i6+j] = ((p->x[i6+j]<0.0)?(-1):(1))*range;
     }
 }
    }
}

canonical_original_code:
void bound_particles(struct particles *p, double range) {
    int i; int i6; int j;
    for(i=0;i<p->n;i++) {
 i6 = i*6;
 for(j=0;j<3;j++) {
     if(fabs(p->x[i6+j]) > range ) {
  p->x[i6+j] = ((p->x[i6+j]<0.0)?(-1):(1))*range;
     }
 }
    }
}

variable_types: range double

variable_types: j int


glKeyboard

decompiled_code:
void __fastcall glKeyboard(char a1)
{
switch ( a1 )
{
case ' ':
if ( simulationOn )
{
simulationOn = 0;
}
else
{
simulationOn = 1;
glRedisplay(1LL);
}
break;
case ')':
glutFullScreen();
full = 1;
break;
case '-':
*(double *)(p + 32LL) = *(double *)(p + 32LL) / 1.1;
break;
case '0':
if ( full == 1 )
{
glutReshapeWindow(500LL, 500LL);
glutPositionWindow(100LL, 100LL);
}
else
{
glutReshapeWindow(1024LL, 768LL);
glutPositionWindow(0LL, 4294967286LL);
}
full = full == 0;
break;
case '=':
*(double *)(p + 32LL) = 1.1 * *(double *)(p + 32LL);
break;
case 'a':
axisOn = 1 - axisOn;
glDisplay();
break;
case 'i':
switch ( rk_number )
{
case 4:
rk_number = 8;
*(_QWORD *)(p + 56LL) = &rk8;
break;
case 8:
rk_number = 2;
*(_QWORD *)(p + 56LL) = &rk2;
break;
case 2:
rk_number = 4;
*(_QWORD *)(p + 56LL) = &rk4;
break;
}
fprintf(stderr, "Using RK%i integrator\n", rk_number);
break;
case 'o':
drawOctreeOn = 1 - drawOctreeOn;
glDisplay();
break;
case 'q':
glutDestroyWindow(win);
exit(0);
case 'r':
simulationOn = 0;
fprintf(stderr, "p->n = %i\n", (unsigned int)*p);
init_particles(p);
free_octree(ot);
build_octree_from_particles(ot, p);
get_bounds(ot, p);
octree_calculate_masses(ot);
glDisplay();
break;
case 's':
sampleForceOn = 1 - sampleForceOn;
glDisplay();
break;
case 't':
drawTreeOn = 1 - drawTreeOn;
glDisplay();
break;
case 'v':
glDisplay();
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func0(char a1)
{
switch ( a1 )
{
case ' ':
if ( simulationOn )
{
simulationOn = 0;
}
else
{
simulationOn = 1;
glRedisplay(1LL);
}
break;
case ')':
glutFullScreen();
full = 1;
break;
case '-':
*(double *)(p + 32LL) = *(double *)(p + 32LL) / 1.1;
break;
case '0':
if ( full == 1 )
{
glutReshapeWindow(500LL, 500LL);
glutPositionWindow(100LL, 100LL);
}
else
{
glutReshapeWindow(1024LL, 768LL);
glutPositionWindow(0LL, 4294967286LL);
}
full = full == 0;
break;
case '=':
*(double *)(p + 32LL) = 1.1 * *(double *)(p + 32LL);
break;
case 'a':
axisOn = 1 - axisOn;
glDisplay();
break;
case 'i':
switch ( rk_number )
{
case 4:
rk_number = 8;
*(_QWORD *)(p + 56LL) = &rk8;
break;
case 8:
rk_number = 2;
*(_QWORD *)(p + 56LL) = &rk2;
break;
case 2:
rk_number = 4;
*(_QWORD *)(p + 56LL) = &rk4;
break;
}
fprintf(stderr, "Using RK%i integrator\n", rk_number);
break;
case 'o':
drawOctreeOn = 1 - drawOctreeOn;
glDisplay();
break;
case 'q':
glutDestroyWindow(win);
exit(0);
case 'r':
simulationOn = 0;
fprintf(stderr, "p->n = %i\n", (unsigned int)*p);
init_particles(p);
free_octree(ot);
build_octree_from_particles(ot, p);
get_bounds(ot, p);
octree_calculate_masses(ot);
glDisplay();
break;
case 's':
sampleForceOn = 1 - sampleForceOn;
glDisplay();
break;
case 't':
drawTreeOn = 1 - drawTreeOn;
glDisplay();
break;
case 'v':
glDisplay();
break;
default:
return;
}
}

original_code:
void glKeyboard(unsigned char key, int x, int y) {
    switch(key) {
 case '-':
     p->dt /= 1.1;
 break;
 case '=':
     p->dt *= 1.1;
 break;
 case '0':
     if(full==1) {
  glutReshapeWindow(500,500);
  glutPositionWindow(100,100);
     } else {
  glutReshapeWindow(1024,768);
  glutPositionWindow(0,-10);
     }
     full=!full;
 break;
 case 'i':
     switch(rk_number) {
  case 2: rk_number = 4; p->integrate = rk4; break;
  case 4: rk_number = 8; p->integrate = rk8; break;
  case 8: rk_number = 2; p->integrate = rk2; break;
     }
     fprintf(stderr,"Using RK%i integrator\n",rk_number);
 break;
 case 'r':
     simulationOn=0;
     fprintf(stderr,"p->n = %i\n",p->n);
     init_particles( p );
     free_octree( ot );
     build_octree_from_particles( ot, p );
     get_bounds( ot, p );
     octree_calculate_masses( ot );
     glDisplay();
 break;
 case 's':
     sampleForceOn = 1-sampleForceOn;
     glDisplay();
 break;
 case ' ':
     if(simulationOn==0) {
  simulationOn=1;
  glRedisplay(1);
     } else {
  simulationOn=0;
     }
 break;
 case 't':
     drawTreeOn = 1-drawTreeOn;
     glDisplay();
 break;
 case 'o':
     drawOctreeOn = 1-drawOctreeOn;
     glDisplay();
 break;
 case 'a': axisOn = 1-axisOn; glDisplay(); break;
 case ')': glutFullScreen(); full=1; break;
 case 'v': glDisplay(); break;
 case 'q': glutDestroyWindow(win); exit(0); break;
    }
}

variable_types:
key
unsigned char

variable_types: x int

variable_types: y int


glSpecialKeys

decompiled_code:
__int64 __fastcall glSpecialKeys(int a1)
{
int v1; // edx
int v2; // eax

if ( a1 == 102 )
{
++sample;
glDisplay();
}
else if ( a1 > 102 )
{
if ( a1 == 103 )
{
bh_factor = bh_factor - 0.05;
fprintf(stderr, "Barnes Hut factor = %f\n", bh_factor);
glDisplay();
}
}
else if ( a1 == 100 )
{
--sample;
glDisplay();
}
else if ( a1 == 101 )
{
bh_factor = bh_factor + 0.05;
fprintf(stderr, "Barnes Hut factor = %f\n", bh_factor);
glDisplay();
}
v1 = *p;
v2 = 0;
if ( sample >= 0 )
v2 = sample;
if ( v1 <= v2 )
v2 = v1 - 1;
sample = v2;
return glDisplay();
}

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

if ( a1 == 102 )
{
++sample;
glDisplay();
}
else if ( a1 > 102 )
{
if ( a1 == 103 )
{
bh_factor = bh_factor - 0.05;
fprintf(stderr, "Barnes Hut factor = %f\n", bh_factor);
glDisplay();
}
}
else if ( a1 == 100 )
{
--sample;
glDisplay();
}
else if ( a1 == 101 )
{
bh_factor = bh_factor + 0.05;
fprintf(stderr, "Barnes Hut factor = %f\n", bh_factor);
glDisplay();
}
v1 = *p;
v2 = 0;
if ( sample >= 0 )
v2 = sample;
if ( v1 <= v2 )
v2 = v1 - 1;
sample = v2;
return glDisplay();
}

original_code:
void glSpecialKeys(int key, int x, int y) {
    switch(key) {
 case 0x0066:
     sample++;
     glDisplay();
 break;
 case 0x0064:
     sample--;
     glDisplay();
 break;
 case 0x0067:
     bh_factor -= 0.05;
     fprintf(stderr,"Barnes Hut factor = %f\n",(bh_factor));
     glDisplay();
 break;
 case 0x0065:
     bh_factor += 0.05;
     fprintf(stderr,"Barnes Hut factor = %f\n",(bh_factor));
     glDisplay();
 break;
    }
    sample = ((p->n-1)<(((0)<(sample)?(sample):(0)))?(p->n-1):(((0)<(sample)?(sample):(0))));
    glDisplay();
}

variable_types: key int


decompiled_code:
void *__fastcall Alloc1DArray(size_t size, int a2)
{
return calloc(a2, size);
}

canonical_decompiled_code:
void *__fastcall func0(size_t size, int a2)
{
return calloc(a2, size);
}

original_code:
void* Alloc1DArray(const size_t size, const int num) {
    void* ptr = calloc(num,size);
    return ptr;
}

canonical_original_code:
void *Alloc1DArray(unsigned long size, int num) {
    void *ptr = calloc(num,size);
    return ptr;
}

variable_types:
size
unsigned long

variable_types: num int

variable_types:
ptr
void *

return_type: void *


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

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

original_code:
void Free1DArray(void* array) {
    if(array)
 free(array);
}

canonical_original_code:
void Free1DArray(void *array) {
    if(array)
 free(array);
}

variable_types:
array
void *


decompiled_code:
void __fastcall Free2DArray(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
if ( ptr )
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr, int a2)
{
void **v2; // rbx

if ( a2 > 0 )
{
v2 = (void **)ptr;
do
{
if ( *v2 )
free(*v2);
++v2;
}
while ( v2 != (void **)((char *)ptr + 8 * (unsigned int)(a2 - 1) + 8) );
}
if ( ptr )
free(ptr);
}

original_code:
void Free2DArray(void** array, const int ni) {
    int i;
    for(i=0;i<ni;i++) {
 if(array[i])
     free(array[i]);
    }
    if(array)
 free(array);
}

canonical_original_code:
void Free2DArray(void **array, int ni) {
    int i;
    for(i=0;i<ni;i++) {
 if(array[i])
     free(array[i]);
    }
    if(array)
 free(array);
}

variable_types:
array
void **

variable_types: ni int


original_code:
void Free3DArray(void*** array, const int ni, const int nj) {
    int i,j;
    for(i=0;i<ni;i++) {
 for(j=0;j<nj;j++) {
     if(array[i][j])
  free(array[i][j]);
 }
    }
    for(i=0;i<ni;i++) {
 if(array[i])
     free(array[i]);
    }
    if(array)
 free(array);
}

canonical_original_code:
void Free3DArray(void ***array, int ni, int nj) {
    int i; int j;
    for(i=0;i<ni;i++) {
 for(j=0;j<nj;j++) {
     if(array[i][j])
  free(array[i][j]);
 }
    }
    for(i=0;i<ni;i++) {
 if(array[i])
     free(array[i]);
    }
    if(array)
 free(array);
}

variable_types:
array
void ***

variable_types: nj int


original_code:
void Free4DArray(void**** array, const int ni, const int nj, const int nk) {
    int i,j,k;
    for(i=0;i<ni;i++) {
 for(j=0;j<nj;j++) {
     for(k=0;k<nk;k++) {
  if(array[i][j][k])
      free(array[i][j][k]);
     }
 }
    }
    for(i=0;i<ni;i++) {
 for(j=0;j<nj;j++) {
     if(array[i][j])
  free(array[i][j]);
 }
    }
    for(i=0;i<ni;i++) {
 if(array[i])
     free(array[i]);
    }
    if(array)
 free(array);
}

canonical_original_code:
void Free4DArray(void ****array, int ni, int nj, int nk) {
    int i; int j; int k;
    for(i=0;i<ni;i++) {
 for(j=0;j<nj;j++) {
     for(k=0;k<nk;k++) {
  if(array[i][j][k])
      free(array[i][j][k]);
     }
 }
    }
    for(i=0;i<ni;i++) {
 for(j=0;j<nj;j++) {
     if(array[i][j])
  free(array[i][j]);
 }
    }
    for(i=0;i<ni;i++) {
 if(array[i])
     free(array[i]);
    }
    if(array)
 free(array);
}

variable_types:
array
void ****

variable_types: nk int

variable_types: k int


FreeCamera

decompiled_code:
void __fastcall FreeCamera(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*(void **)ptr);
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(ptr);
}

original_code:
void FreeCamera(struct camera* cam) {
    free(cam->location);
    free(cam->location0);
    free(cam->lookAt);
    free(cam->lookAt0);
    free(cam->sky);
    free(cam->sky0);
    free(cam);
    cam=((void *)0);
}

canonical_original_code:
void FreeCamera(struct camera *cam) {
    free(cam->location);
    free(cam->location0);
    free(cam->lookAt);
    free(cam->lookAt0);
    free(cam->sky);
    free(cam->sky0);
    free(cam);
    cam=((void *)0);
}

variable_types: struct camera { struct vector3f { float x; } *location; struct vector3f *lookAt; struct vector3f *sky; struct vector3f *camx; struct vector3f *camy; struct vector3f *camz; float angle; float theta; float dist; float phi; float close; int width; float ratio; } *

user_defined_types: struct camera { struct vector3f *location; struct vector3f *lookAt; struct vector3f *sky; struct vector3f *camx; struct vector3f *camy; struct vector3f *camz; float angle; float theta; float dist; float phi; float close; int width; float ratio; }


CameraReshapeWindow

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

result = 1LL;
if ( !a3 )
a3 = 1;
if ( !a2 )
a2 = 1;
*(_DWORD *)(a1 + 112) = a2;
*(_DWORD *)(a1 + 116) = a3;
*(float *)(a1 + 120) = (float)a2 / (float)a3;
return result;
}

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

result = 1LL;
if ( !a3 )
a3 = 1;
if ( !a2 )
a2 = 1;
*(_DWORD *)(a1 + 112) = a2;
*(_DWORD *)(a1 + 116) = a3;
*(float *)(a1 + 120) = (float)a2 / (float)a3;
return result;
}

original_code:
void CameraReshapeWindow(struct camera* cam, int winWidth, int winHeight) {
    if(winHeight==0) winHeight=1;
    if(winWidth==0) winWidth=1;
    cam->width = winWidth;
    cam->height = winHeight;
    cam->ratio = (float)winWidth/(float)winHeight;
}

canonical_original_code:
void CameraReshapeWindow(struct camera *cam, int winWidth, int winHeight) {
    if(winHeight==0) winHeight=1;
    if(winWidth==0) winWidth=1;
    cam->width = winWidth;
    cam->height = winHeight;
    cam->ratio = (float)winWidth/(float)winHeight;
}

variable_types: winWidth int

variable_types: winHeight int


CameraLimits

decompiled_code:
void __fastcall CameraLimits(__int64 a1, float a2, float a3)
{
*(float *)(a1 + 104) = a2;
*(float *)(a1 + 108) = a3;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, float a2, float a3)
{
*(float *)(a1 + 104) = a2;
*(float *)(a1 + 108) = a3;
}

original_code:
void CameraLimits(struct camera* cam, float close, float far) {
    cam->close = close;
    cam->far = far;
}

canonical_original_code:
void CameraLimits(struct camera *cam, float close, float far) {
    cam->close = close;
    cam->far = far;
}

variable_types: close float

variable_types: far float


MakeOGLCamera

decompiled_code:
__int64 __fastcall MakeOGLCamera(__int64 a1)
{
glMatrixMode(5889LL);
glLoadIdentity();
glViewport(0LL, 0LL, *(unsigned int *)(a1 + 112), *(unsigned int *)(a1 + 116));
gluPerspective(
*(float *)(a1 + 72),
*(float *)(a1 + 120),
*(float *)(a1 + 104),
(float)(*(float *)(a1 + 108) + *(float *)(a1 + 88)));
glMatrixMode(5888LL);
glLoadIdentity();
return gluLookAt(
**(float **)a1,
*(float *)(*(_QWORD *)a1 + 4LL),
*(float *)(*(_QWORD *)a1 + 8LL),
**(float **)(a1 + 16),
*(float *)(*(_QWORD *)(a1 + 16) + 4LL),
*(float *)(*(_QWORD *)(a1 + 16) + 8LL),
**(float **)(a1 + 32),
*(float *)(*(_QWORD *)(a1 + 32) + 4LL),
5888LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
glMatrixMode(5889LL);
glLoadIdentity();
glViewport(0LL, 0LL, *(unsigned int *)(a1 + 112), *(unsigned int *)(a1 + 116));
gluPerspective(
*(float *)(a1 + 72),
*(float *)(a1 + 120),
*(float *)(a1 + 104),
(float)(*(float *)(a1 + 108) + *(float *)(a1 + 88)));
glMatrixMode(5888LL);
glLoadIdentity();
return gluLookAt(
**(float **)a1,
*(float *)(*(_QWORD *)a1 + 4LL),
*(float *)(*(_QWORD *)a1 + 8LL),
**(float **)(a1 + 16),
*(float *)(*(_QWORD *)(a1 + 16) + 4LL),
*(float *)(*(_QWORD *)(a1 + 16) + 8LL),
**(float **)(a1 + 32),
*(float *)(*(_QWORD *)(a1 + 32) + 4LL),
5888LL);
}

original_code:
void MakeOGLCamera(struct camera* cam) {
    glMatrixMode(0x1701);
    glLoadIdentity();
    glViewport(0, 0, cam->width, cam->height);
    gluPerspective(cam->angle,cam->ratio,cam->close, cam->far + cam->dist);
    glMatrixMode(0x1700);
    glLoadIdentity();
    gluLookAt(
 cam->location->x,
 cam->location->y,
 cam->location->z,
 cam->lookAt->x,
 cam->lookAt->y,
 cam->lookAt->z,
 cam->sky->x,
 cam->sky->y,
 cam->sky->z
    );
}

canonical_original_code:
void MakeOGLCamera(struct camera *cam) {
    glMatrixMode(0x1701);
    glLoadIdentity();
    glViewport(0, 0, cam->width, cam->height);
    gluPerspective(cam->angle,cam->ratio,cam->close, cam->far + cam->dist);
    glMatrixMode(0x1700);
    glLoadIdentity();
    gluLookAt(
 cam->location->x,
 cam->location->y,
 cam->location->z,
 cam->lookAt->x,
 cam->lookAt->y,
 cam->lookAt->z,
 cam->sky->x,
 cam->sky->y,
 cam->sky->z
    );
}


CameraPositionVecVec

decompiled_code:
__int64 __fastcall CameraPositionVecVec(_QWORD *a1)
{
vfCopy(*a1);
return vfCopy(a1[2]);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
vfCopy(*a1);
return vfCopy(a1[2]);
}

original_code:
void CameraPositionVecVec(struct camera* cam, vector3f* location, vector3f* lookAt) {
    vfCopy(cam->location, location);
    vfCopy(cam->lookAt, lookAt);
}

canonical_original_code:
void CameraPositionVecVec(struct camera *cam, struct vector3f *location, struct vector3f *lookAt) {
    vfCopy(cam->location, location);
    vfCopy(cam->lookAt, lookAt);
}

variable_types:
location
struct vector3f *

variable_types:
lookAt
struct vector3f *


CameraPositionXYZXYZ

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

**a1 = a2;
(*a1)[1] = a3;
(*a1)[2] = a4;
*a1[2] = a5;
a1[2][1] = a6;
result = a1[2];
result[2] = a7;
return result;
}

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

**a1 = a2;
(*a1)[1] = a3;
(*a1)[2] = a4;
*a1[2] = a5;
a1[2][1] = a6;
result = a1[2];
result[2] = a7;
return result;
}

original_code:
void CameraPositionXYZXYZ(struct camera* cam, float camx, float camy, float camz, float lax, float lay, float laz) {
    cam->location->x = camx;
    cam->location->y = camy;
    cam->location->z = camz;
    cam->lookAt->x = lax;
    cam->lookAt->y = lay;
    cam->lookAt->z = laz;
}

canonical_original_code:
void CameraPositionXYZXYZ(struct camera *cam, float camx, float camy, float camz, float lax, float lay, float laz) {
    cam->location->x = camx;
    cam->location->y = camy;
    cam->location->z = camz;
    cam->lookAt->x = lax;
    cam->lookAt->y = lay;
    cam->lookAt->z = laz;
}

variable_types: camx float

variable_types: camy float

variable_types: camz float

variable_types: lax float

variable_types: lay float

variable_types: laz float


CameraPositionRPTVec

original_code:
void CameraPositionRPTVec(struct camera* cam, float dist, float phi, float theta, vector3f* lookAt) {
    cam->dist = dist;
    cam->phi = phi;
    cam->theta = theta;
    cam->location->x = lookAt->x+cam->dist*cos(radians(theta))*sin(radians(phi));
    cam->location->y = lookAt->y+cam->dist*cos(radians(phi));
    cam->location->z = lookAt->z+cam->dist*sin(radians(theta))*sin(radians(phi));
    vfCopy(cam->lookAt, lookAt);
}

canonical_original_code:
void CameraPositionRPTVec(struct camera *cam, float dist, float phi, float theta, struct vector3f *lookAt) {
    cam->dist = dist;
    cam->phi = phi;
    cam->theta = theta;
    cam->location->x = lookAt->x+cam->dist*cos(radians(theta))*sin(radians(phi));
    cam->location->y = lookAt->y+cam->dist*cos(radians(phi));
    cam->location->z = lookAt->z+cam->dist*sin(radians(theta))*sin(radians(phi));
    vfCopy(cam->lookAt, lookAt);
}

variable_types: dist float

variable_types: phi float

variable_types: theta float


CameraPositionRPTXYZ

decompiled_code:
__int64 __fastcall CameraPositionRPTXYZ(__int64 a1, float a2, float a3, float a4, float a5, float a6, float a7)
{
double v7; // xmm0_8
double v8; // xmm0_8
float v9; // xmm0_4
double v10; // xmm0_8
float v11; // xmm0_4
double v12; // xmm0_8
double v13; // xmm0_8
float v14; // xmm0_4
__int64 result; // rax
double v18; // [rsp+10h] [rbp-28h]
double v19; // [rsp+10h] [rbp-28h]
double v20; // [rsp+10h] [rbp-28h]
double v21; // [rsp+10h] [rbp-28h]

*(float *)(a1 + 88) = a2;
*(float *)(a1 + 96) = a3;
*(float *)(a1 + 80) = a4;
v7 = radians(a4);
v18 = a2 * cos(v7);
v8 = radians(a3);
v9 = sin(v8) * v18 + a5;
**(float **)a1 = v9;
v19 = *(float *)(a1 + 88);
v10 = radians(a3);
v11 = cos(v10) * v19 + a6;
*(float *)(*(_QWORD *)a1 + 4LL) = v11;
v20 = *(float *)(a1 + 88);
v12 = radians(a4);
v21 = sin(v12) * v20;
v13 = radians(a3);
v14 = sin(v13) * v21 + a7;
*(float *)(*(_QWORD *)a1 + 8LL) = v14;
**(float **)(a1 + 16) = a5;
*(float *)(*(_QWORD *)(a1 + 16) + 4LL) = a6;
result = *(_QWORD *)(a1 + 16);
*(float *)(result + 8) = a7;
return result;
}

original_code:
void CameraPositionRPTXYZ(struct camera* cam, float dist, float phi, float theta, float lax, float lay, float laz) {
    cam->dist = dist;
    cam->phi = phi;
    cam->theta = theta;
    cam->location->x = lax+cam->dist*cos(radians(theta))*sin(radians(phi));
    cam->location->y = lay+cam->dist*cos(radians(phi));
    cam->location->z = laz+cam->dist*sin(radians(theta))*sin(radians(phi));
    cam->lookAt->x = lax;
    cam->lookAt->y = lay;
    cam->lookAt->z = laz;
}

canonical_original_code:
void CameraPositionRPTXYZ(struct camera *cam, float dist, float phi, float theta, float lax, float lay, float laz) {
    cam->dist = dist;
    cam->phi = phi;
    cam->theta = theta;
    cam->location->x = lax+cam->dist*cos(radians(theta))*sin(radians(phi));
    cam->location->y = lay+cam->dist*cos(radians(phi));
    cam->location->z = laz+cam->dist*sin(radians(theta))*sin(radians(phi));
    cam->lookAt->x = lax;
    cam->lookAt->y = lay;
    cam->lookAt->z = laz;
}


CameraReposition

original_code:
void CameraReposition(struct camera* cam) {
    cam->location->x = cam->lookAt->x+cam->dist*cos(radians(cam->theta))*sin(radians(cam->phi));
    cam->location->y = cam->lookAt->y+cam->dist*cos(radians(cam->phi));
    cam->location->z = cam->lookAt->z+cam->dist*sin(radians(cam->theta))*sin(radians(cam->phi));
}

canonical_original_code:
void CameraReposition(struct camera *cam) {
    cam->location->x = cam->lookAt->x+cam->dist*cos(radians(cam->theta))*sin(radians(cam->phi));
    cam->location->y = cam->lookAt->y+cam->dist*cos(radians(cam->phi));
    cam->location->z = cam->lookAt->z+cam->dist*sin(radians(cam->theta))*sin(radians(cam->phi));
}


CameraTarget

decompiled_code:
__int64 __fastcall CameraTarget(__int64 a1, float a2, float a3, float a4)
{
**(float **)(a1 + 16) = a2;
*(float *)(*(_QWORD *)(a1 + 16) + 4LL) = a3;
*(float *)(*(_QWORD *)(a1 + 16) + 8LL) = a4;
return CameraReposition((float *)a1);
}

original_code:
void CameraTarget(struct camera* cam, float x, float y, float z) {
    cam->lookAt->x = x;
    cam->lookAt->y = y;
    cam->lookAt->z = z;
    CameraReposition(cam);
}

canonical_original_code:
void CameraTarget(struct camera *cam, float x, float y, float z) {
    cam->lookAt->x = x;
    cam->lookAt->y = y;
    cam->lookAt->z = z;
    CameraReposition(cam);
}

variable_types: x float

variable_types: y float

variable_types: z float


CameraRemember

original_code:
void CameraRemember(struct camera* cam) {
    cam->angle0 = cam->angle;
    cam->theta0 = cam->theta;
    cam->dist0 = cam->dist;
    cam->phi0 = cam->phi;
    vfCopy(cam->location0,cam->location);
    vfCopy(cam->lookAt0,cam->lookAt);
    vfCopy(cam->sky0,cam->sky);
}

canonical_original_code:
void CameraRemember(struct camera *cam) {
    cam->angle0 = cam->angle;
    cam->theta0 = cam->theta;
    cam->dist0 = cam->dist;
    cam->phi0 = cam->phi;
    vfCopy(cam->location0,cam->location);
    vfCopy(cam->lookAt0,cam->lookAt);
    vfCopy(cam->sky0,cam->sky);
}

variable_types: struct camera { struct vector3f { float x; } *location; struct vector3f *lookAt; struct vector3f *sky; struct vector3f *camx; struct vector3f *camy; struct vector3f *camz; float angle; float theta; float dist; float phi; float close; int width; float ratio; } *


CameraCalculateAxes

decompiled_code:
__int64 __fastcall CameraCalculateAxes(_QWORD *a1)
{
vfSub(a1[8], a1[2], *a1);
vfCross(a1[6], a1[8], a1[4]);
vfCross(a1[7], a1[6], a1[8]);
vfNormalize(a1[6]);
vfNormalize(a1[7]);
return vfNormalize(a1[8]);
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
vfSub(a1[8], a1[2], *a1);
vfCross(a1[6], a1[8], a1[4]);
vfCross(a1[7], a1[6], a1[8]);
vfNormalize(a1[6]);
vfNormalize(a1[7]);
return vfNormalize(a1[8]);
}

original_code:
void CameraCalculateAxes(struct camera* cam) {
    vfSub(cam->camz,cam->lookAt,cam->location);
    vfCross(cam->camx,cam->camz,cam->sky);
    vfCross(cam->camy,cam->camx,cam->camz);
    vfNormalize(cam->camx);
    vfNormalize(cam->camy);
    vfNormalize(cam->camz);
}

canonical_original_code:
void CameraCalculateAxes(struct camera *cam) {
    vfSub(cam->camz,cam->lookAt,cam->location);
    vfCross(cam->camx,cam->camz,cam->sky);
    vfCross(cam->camy,cam->camx,cam->camz);
    vfNormalize(cam->camx);
    vfNormalize(cam->camy);
    vfNormalize(cam->camz);
}


glReEnableMouse

decompiled_code:
void glReEnableMouse()
{
mouseDisabled = 0;
}

canonical_decompiled_code:
void func0()
{
mouseDisabled = 0;
}

original_code:
void glReEnableMouse(int value) {
    mouseDisabled=0;
}

variable_types: value int


glMouseFunc

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

result = CameraRemember(cam);
if ( !a2 )
{
*(double *)&mpx0 = (float)((float)a3 / (float)*(int *)(cam + 112LL));
*(double *)&mpy0 = 1.0 - (float)((float)a4 / (float)*(int *)(cam + 116LL));
switch ( a1 )
{
case 1:
clickMode = 1;
break;
case 2:
clickMode = 2;
result = CameraCalculateAxes();
break;
case 0:
clickMode = 0;
break;
}
}
return result;
}

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

result = CameraRemember(cam);
if ( !a2 )
{
*(double *)&mpx0 = (float)((float)a3 / (float)*(int *)(cam + 112LL));
*(double *)&mpy0 = 1.0 - (float)((float)a4 / (float)*(int *)(cam + 116LL));
switch ( a1 )
{
case 1:
clickMode = 1;
break;
case 2:
clickMode = 2;
result = CameraCalculateAxes();
break;
case 0:
clickMode = 0;
break;
}
}
return result;
}

original_code:
void glMouseFunc(int button, int state, int x, int y) {
    CameraRemember(cam);
    switch(state) {
 case 0x0000:
     mpx0 = (float)x/(float)cam->width;
     mpy0 = 1.0-(float)y/(float)cam->height;
     switch(button) {
     case 0x0000:
  clickMode = 0;
     break;
     case 0x0001:
  clickMode = 1;
     break;
     case 0x0002:
  clickMode = 2;
  CameraCalculateAxes(cam);
     break;
     }
 break;
 case 0x0001:
 break;
    }
}

variable_types: button int

variable_types: state int

variable_types: x int

variable_types: y int


glMotionFunc

decompiled_code:
void __fastcall glMotionFunc(int a1, int a2)
{
__int64 v2; // rax
float v3; // xmm3_4
float v4; // xmm4_4
float v5; // xmm0_4
float v6; // xmm0_4
float v7; // xmm0_4
__int64 v8; // rbx
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rbx
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
float v16; // [rsp+0h] [rbp-44h]
double v17; // [rsp+4h] [rbp-40h]
char v18[12]; // [rsp+Ch] [rbp-38h] BYREF
char v19[12]; // [rsp+18h] [rbp-2Ch] BYREF
char v20[12]; // [rsp+24h] [rbp-20h] BYREF
char v21[20]; // [rsp+30h] [rbp-14h] BYREF

if ( !mouseDisabled )
{
v2 = cam;
*(double *)&mpx = (float)((float)a1 / (float)*(int *)(cam + 112LL));
*(double *)&mpy = 1.0 - (float)((float)a2 / (float)*(int *)(cam + 116LL));
v3 = *(double *)&mpx - *(double *)&mpx0;
v4 = *(double *)&mpy - *(double *)&mpy0;
v16 = v4;
switch ( clickMode )
{
case 1:
v17 = *(float *)(cam + 92LL);
v7 = exp(v4 * 4.0) * v17;
*(float *)(cam + 88LL) = v7;
((void (*)(void))CameraReposition)();
glReView();
break;
case 2:
v8 = vffMult(v21, *(_QWORD *)(cam + 56LL), v4 * *(float *)(cam + 88LL));
v9 = vffMult(v20, *(_QWORD *)(cam + 48LL), v3 * *(float *)(cam + 88LL));
v10 = vfAdd(v19, v9, v8);
v11 = vfSub(v18, *(_QWORD *)(cam + 8LL), v10);
vfCopy(*cam, v11);
v12 = vffMult(v21, *(_QWORD *)(cam + 56LL), v16 * *(float *)(cam + 88LL));
v13 = vffMult(v20, *(_QWORD *)(cam + 48LL), v3 * *(float *)(cam + 88LL));
v14 = vfAdd(v19, v13, v12);
v15 = vfSub(v18, *(_QWORD *)(cam + 24LL), v14);
vfCopy(*(_QWORD *)(cam + 16LL), v15);
glReView();
break;
case 0:
v5 = v3 * 360.0 + *(float *)(cam + 84LL);
*(float *)(cam + 80LL) = v5;
v6 = v4 * 180.0 + *(float *)(v2 + 100);
*(float *)(v2 + 96) = v6;
CameraReposition(v2);
glReView();
break;
}
glDisplay();
mouseDisabled = 1;
glutTimerFunc(16LL, glReEnableMouse, 1LL);
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2)
{
__int64 v2; // rax
float v3; // xmm3_4
float v4; // xmm4_4
float v5; // xmm0_4
float v6; // xmm0_4
float v7; // xmm0_4
__int64 v8; // rbx
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rbx
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
float v16; // [rsp+0h] [rbp-44h]
double v17; // [rsp+4h] [rbp-40h]
char v18[12]; // [rsp+Ch] [rbp-38h] BYREF
char v19[12]; // [rsp+18h] [rbp-2Ch] BYREF
char v20[12]; // [rsp+24h] [rbp-20h] BYREF
char v21[20]; // [rsp+30h] [rbp-14h] BYREF

if ( !mouseDisabled )
{
v2 = cam;
*(double *)&mpx = (float)((float)a1 / (float)*(int *)(cam + 112LL));
*(double *)&mpy = 1.0 - (float)((float)a2 / (float)*(int *)(cam + 116LL));
v3 = *(double *)&mpx - *(double *)&mpx0;
v4 = *(double *)&mpy - *(double *)&mpy0;
v16 = v4;
switch ( clickMode )
{
case 1:
v17 = *(float *)(cam + 92LL);
v7 = exp(v4 * 4.0) * v17;
*(float *)(cam + 88LL) = v7;
((void (*)(void))CameraReposition)();
glReView();
break;
case 2:
v8 = vffMult(v21, *(_QWORD *)(cam + 56LL), v4 * *(float *)(cam + 88LL));
v9 = vffMult(v20, *(_QWORD *)(cam + 48LL), v3 * *(float *)(cam + 88LL));
v10 = vfAdd(v19, v9, v8);
v11 = vfSub(v18, *(_QWORD *)(cam + 8LL), v10);
vfCopy(*cam, v11);
v12 = vffMult(v21, *(_QWORD *)(cam + 56LL), v16 * *(float *)(cam + 88LL));
v13 = vffMult(v20, *(_QWORD *)(cam + 48LL), v3 * *(float *)(cam + 88LL));
v14 = vfAdd(v19, v13, v12);
v15 = vfSub(v18, *(_QWORD *)(cam + 24LL), v14);
vfCopy(*(_QWORD *)(cam + 16LL), v15);
glReView();
break;
case 0:
v5 = v3 * 360.0 + *(float *)(cam + 84LL);
*(float *)(cam + 80LL) = v5;
v6 = v4 * 180.0 + *(float *)(v2 + 100);
*(float *)(v2 + 96) = v6;
CameraReposition(v2);
glReView();
break;
}
glDisplay();
mouseDisabled = 1;
glutTimerFunc(16LL, glReEnableMouse, 1LL);
}
}

original_code:
void glMotionFunc(int x, int y) {
    if(mouseDisabled==0) {
 vector3f temp1,temp2,temp3,temp4;
 float dx,dy;
 mpx = (float)x/(float)cam->width;
 mpy = 1.0-(float)y/(float)cam->height;
 dx = mpx-mpx0;
 dy = mpy-mpy0;
 switch(clickMode) {
     case 0:
  cam->theta = cam->theta0 + dx*360.0;
  cam->phi = cam->phi0 + dy*180.0;
  CameraReposition(cam);
  glReView();
     break;
     case 1:
  cam->dist = cam->dist0*exp(dy*4.0);
  CameraReposition(cam);
  glReView();
     break;
     case 2:
  vfCopy(cam->location,vfSub(&temp1,cam->location0,vfAdd(&temp2,
      vffMult(&temp3,cam->camx,dx*cam->dist),vffMult(&temp4,cam->camy,dy*cam->dist))));
  vfCopy(cam->lookAt,vfSub(&temp1,cam->lookAt0,vfAdd(&temp2,
      vffMult(&temp3,cam->camx,dx*cam->dist),vffMult(&temp4,cam->camy,dy*cam->dist))));
  glReView();
     break;
 }
 glDisplay();
 mouseDisabled=1;
 glutTimerFunc(1000/60,glReEnableMouse,1);
    }
}

canonical_original_code:
void glMotionFunc(int x, int y) {
    if(mouseDisabled==0) {
 struct vector3f temp1; struct vector3f temp2; struct vector3f temp3; struct vector3f temp4;
 float dx; float dy;
 mpx = (float)x/(float)cam->width;
 mpy = 1.0-(float)y/(float)cam->height;
 dx = mpx-mpx0;
 dy = mpy-mpy0;
 switch(clickMode) {
     case 0:
  cam->theta = cam->theta0 + dx*360.0;
  cam->phi = cam->phi0 + dy*180.0;
  CameraReposition(cam);
  glReView();
     break;
     case 1:
  cam->dist = cam->dist0*exp(dy*4.0);
  CameraReposition(cam);
  glReView();
     break;
     case 2:
  vfCopy(cam->location,vfSub(&temp1,cam->location0,vfAdd(&temp2,
      vffMult(&temp3,cam->camx,dx*cam->dist),vffMult(&temp4,cam->camy,dy*cam->dist))));
  vfCopy(cam->lookAt,vfSub(&temp1,cam->lookAt0,vfAdd(&temp2,
      vffMult(&temp3,cam->camx,dx*cam->dist),vffMult(&temp4,cam->camy,dy*cam->dist))));
  glReView();
     break;
 }
 glDisplay();
 mouseDisabled=1;
 glutTimerFunc(1000/60,glReEnableMouse,1);
    }
}

variable_types: dx float

variable_types: dy float


decompiled_code:
__int64 __fastcall init_glut(int a1, __int64 a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a1;
cam = NewCamera();
CameraPositionRPTXYZ(cam, 2.5, 20.0, 90.0, 0.0, 0.0);
glutInit(v3, a2);
glutInitDisplayMode(18LL);
glutInitWindowSize(640LL, 480LL);
glutInitWindowPosition(0LL, 0LL);
win = glutCreateWindow("Window");
fwrite("\n\n*********** N-Body Gravity Example ***********\n", 1uLL, 0x32uLL, stderr);
fwrite("| |\n", 1uLL, 0x30uLL, stderr);
fwrite("| by Ricky Reusser (rsreusser@gmail.com) |\n", 1uLL, 0x30uLL, stderr);
fwrite("| Enjoy, just let me know if it's useful! |\n", 1uLL, 0x30uLL, stderr);
fwrite("| |\n", 1uLL, 0x30uLL, stderr);
fwrite("***********************************************\n", 1uLL, 0x30uLL, stderr);
fwrite("\nUse the three mouse buttons to rotate, pan, and zoom.\n\n", 1uLL, 0x38uLL, stderr);
fwrite("spacebar to start/stop calculation\n", 1uLL, 0x23uLL, stderr);
fwrite("=/- to inc/dec timestep\n\n", 1uLL, 0x19uLL, stderr);
fwrite("t to toggle tree display\n", 1uLL, 0x19uLL, stderr);
fwrite("o to toggle octree display\n", 1uLL, 0x1BuLL, stderr);
fwrite("s for sample force tree (only once simulation has\n", 1uLL, 0x32uLL, stderr);
fwrite(" been started, or you can expect a bus error!\n\n", 1uLL, 0x30uLL, stderr);
fwrite("a to toggle axis\n", 1uLL, 0x11uLL, stderr);
fwrite("left/right arrow to sample force at different points\n", 1uLL, 0x35uLL, stderr);
fwrite("up/down arrow to inc/dec Barnes Hut octree threshold\n\n", 1uLL, 0x36uLL, stderr);
fwrite("r to restart\n", 1uLL, 0xDuLL, stderr);
fwrite("q to quit\n", 1uLL, 0xAuLL, stderr);
fwrite("\nFor more info, read the source!!!\n\n\n", 1uLL, 0x25uLL, stderr);
glutDisplayFunc(&glDisplay);
glutReshapeFunc(&glReshape);
glutKeyboardFunc(&glKeyboard);
glutMouseFunc(&glMouseFunc);
glutMotionFunc(&glMotionFunc);
glutSpecialFunc(&glSpecialKeys);
glHint(3154LL, 4354LL);
glEnable(2848LL);
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glEnable(2929LL);
glDepthFunc(515LL);
glLineWidth(1.0);
glPointSize(1.0);
glClearColor(0.0, 0.0, 0.0);
return glClearDepth(1.0);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2)
{
int v3[3]; // [rsp+Ch] [rbp-Ch] BYREF

v3[0] = a1;
cam = NewCamera();
CameraPositionRPTXYZ(cam, 2.5, 20.0, 90.0, 0.0, 0.0);
glutInit(v3, a2);
glutInitDisplayMode(18LL);
glutInitWindowSize(640LL, 480LL);
glutInitWindowPosition(0LL, 0LL);
win = glutCreateWindow("Window");
fwrite("\n\n*********** N-Body Gravity Example ***********\n", 1uLL, 0x32uLL, stderr);
fwrite("| |\n", 1uLL, 0x30uLL, stderr);
fwrite("| by Ricky Reusser (rsreusser@gmail.com) |\n", 1uLL, 0x30uLL, stderr);
fwrite("| Enjoy, just let me know if it's useful! |\n", 1uLL, 0x30uLL, stderr);
fwrite("| |\n", 1uLL, 0x30uLL, stderr);
fwrite("***********************************************\n", 1uLL, 0x30uLL, stderr);
fwrite("\nUse the three mouse buttons to rotate, pan, and zoom.\n\n", 1uLL, 0x38uLL, stderr);
fwrite("spacebar to start/stop calculation\n", 1uLL, 0x23uLL, stderr);
fwrite("=/- to inc/dec timestep\n\n", 1uLL, 0x19uLL, stderr);
fwrite("t to toggle tree display\n", 1uLL, 0x19uLL, stderr);
fwrite("o to toggle octree display\n", 1uLL, 0x1BuLL, stderr);
fwrite("s for sample force tree (only once simulation has\n", 1uLL, 0x32uLL, stderr);
fwrite(" been started, or you can expect a bus error!\n\n", 1uLL, 0x30uLL, stderr);
fwrite("a to toggle axis\n", 1uLL, 0x11uLL, stderr);
fwrite("left/right arrow to sample force at different points\n", 1uLL, 0x35uLL, stderr);
fwrite("up/down arrow to inc/dec Barnes Hut octree threshold\n\n", 1uLL, 0x36uLL, stderr);
fwrite("r to restart\n", 1uLL, 0xDuLL, stderr);
fwrite("q to quit\n", 1uLL, 0xAuLL, stderr);
fwrite("\nFor more info, read the source!!!\n\n\n", 1uLL, 0x25uLL, stderr);
glutDisplayFunc(&glDisplay);
glutReshapeFunc(&glReshape);
glutKeyboardFunc(&glKeyboard);
glutMouseFunc(&glMouseFunc);
glutMotionFunc(&glMotionFunc);
glutSpecialFunc(&glSpecialKeys);
glHint(3154LL, 4354LL);
glEnable(2848LL);
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glEnable(2929LL);
glDepthFunc(515LL);
glLineWidth(1.0);
glPointSize(1.0);
glClearColor(0.0, 0.0, 0.0);
return glClearDepth(1.0);
}

original_code:
void init_glut( int argc, char **argv ) {
    cam = NewCamera();
    CameraPositionRPTXYZ( cam, 2.5, 20.0, 90.0, 0.0, 0.0, 0.0 );
    glutInit(&argc, argv);
    glutInitDisplayMode(0x0010 | 0x0002 | 0x0000 );
    glutInitWindowSize(640,480);
    glutInitWindowPosition(0,0);
    win = glutCreateWindow("Window");
    fprintf(stderr,"\n\n*********** N-Body Gravity Example  ***********\n");
    fprintf(stderr, "|                                             |\n");
    fprintf(stderr, "|    by Ricky Reusser  (rsreusser@gmail.com)  |\n");
    fprintf(stderr, "|    Enjoy, just let me know if it's useful!  |\n");
    fprintf(stderr, "|                                             |\n");
    fprintf(stderr, "***********************************************\n");
    fprintf(stderr,"\nUse the three mouse buttons to rotate, pan, and zoom.\n\n");
    fprintf(stderr,"spacebar to start/stop calculation\n");
    fprintf(stderr,"=/- to inc/dec timestep\n\n");
    fprintf(stderr,"t to toggle tree display\n");
    fprintf(stderr,"o to toggle octree display\n");
    fprintf(stderr,"s for sample force tree (only once simulation has\n");
    fprintf(stderr,"  been started, or you can expect a bus error!\n\n");
    fprintf(stderr,"a to toggle axis\n");
    fprintf(stderr,"left/right arrow to sample force at different points\n");
    fprintf(stderr,"up/down arrow to inc/dec Barnes Hut octree threshold\n\n");
    fprintf(stderr,"r to restart\n");
    fprintf(stderr,"q to quit\n");
    fprintf(stderr,"\nFor more info, read the source!!!\n\n\n");
    glutDisplayFunc(glDisplay);
    glutReshapeFunc(glReshape);
    glutKeyboardFunc(glKeyboard);
    glutMouseFunc(glMouseFunc);
    glutMotionFunc(glMotionFunc);
    glutSpecialFunc(glSpecialKeys);
    if(1) {
 glHint(0x0C52, 0x1102);
 glEnable(0x0B20);
 glEnable(0x0BE2);
 glBlendFunc(0x0302, 0x0303);
 glEnable(0x0B71);
 glDepthFunc(0x0203);
 glLineWidth( 1.0 );
 glPointSize( 1.0 );
 glClearColor(0.0, 0.0, 0.0, 0.0);
 glClearDepth( 1.0f );
    }
}

canonical_original_code:
void init_glut(int argc, char **argv) {
    cam = NewCamera();
    CameraPositionRPTXYZ( cam, 2.5, 20.0, 90.0, 0.0, 0.0, 0.0 );
    glutInit(&argc, argv);
    glutInitDisplayMode(0x0010 | 0x0002 | 0x0000 );
    glutInitWindowSize(640,480);
    glutInitWindowPosition(0,0);
    win = glutCreateWindow("Window");
    fprintf(stderr,"\n\n*********** N-Body Gravity Example  ***********\n");
    fprintf(stderr, "|                                             |\n");
    fprintf(stderr, "|    by Ricky Reusser  (rsreusser@gmail.com)  |\n");
    fprintf(stderr, "|    Enjoy, just let me know if it's useful!  |\n");
    fprintf(stderr, "|                                             |\n");
    fprintf(stderr, "***********************************************\n");
    fprintf(stderr,"\nUse the three mouse buttons to rotate, pan, and zoom.\n\n");
    fprintf(stderr,"spacebar to start/stop calculation\n");
    fprintf(stderr,"=/- to inc/dec timestep\n\n");
    fprintf(stderr,"t to toggle tree display\n");
    fprintf(stderr,"o to toggle octree display\n");
    fprintf(stderr,"s for sample force tree (only once simulation has\n");
    fprintf(stderr,"  been started, or you can expect a bus error!\n\n");
    fprintf(stderr,"a to toggle axis\n");
    fprintf(stderr,"left/right arrow to sample force at different points\n");
    fprintf(stderr,"up/down arrow to inc/dec Barnes Hut octree threshold\n\n");
    fprintf(stderr,"r to restart\n");
    fprintf(stderr,"q to quit\n");
    fprintf(stderr,"\nFor more info, read the source!!!\n\n\n");
    glutDisplayFunc(glDisplay);
    glutReshapeFunc(glReshape);
    glutKeyboardFunc(glKeyboard);
    glutMouseFunc(glMouseFunc);
    glutMotionFunc(glMotionFunc);
    glutSpecialFunc(glSpecialKeys);
    if(1) {
 glHint(0x0C52, 0x1102);
 glEnable(0x0B20);
 glEnable(0x0BE2);
 glBlendFunc(0x0302, 0x0303);
 glEnable(0x0B71);
 glDepthFunc(0x0203);
 glLineWidth( 1.0 );
 glPointSize( 1.0 );
 glClearColor(0.0, 0.0, 0.0, 0.0);
 glClearDepth( 1.0f );
    }
}

variable_types: argc int

variable_types:
argv
char **


radians

decompiled_code:
double __fastcall radians(double a1)
{
return a1 * 3.141592653589793 / 180.0;
}

variable_types: deg double

return_type: double


degrees

decompiled_code:
double __fastcall degrees(double a1)
{
return a1 * 180.0 / 3.141592653589793;
}

variable_types: rad double


dabs

decompiled_code:
__m128d __fastcall dabs(__m128d result)
{
if ( result.m128d_f64[0] < 0.0 )
result = _mm_xor_pd(result, (__m128d)LC3);
return result;
}

canonical_decompiled_code:
__m128d __fastcall func2(__m128d result)
{
if ( result.m128d_f64[0] < 0.0 )
result = _mm_xor_pd(result, (__m128d)LC3);
return result;
}

original_code: double dabs(double A){ return (A<0.0)?(-A):(A); }

variable_types: A double


dsgn

decompiled_code:
double __fastcall dsgn(double a1)
{
double result; // xmm0_8

if ( a1 < 0.0 )
result = *(double *)&LC4;
else
result = *(double *)&LC5;
return result;
}

canonical_decompiled_code:
double __fastcall func3(double a1)
{
double result; // xmm0_8

if ( a1 < 0.0 )
result = *(double *)&LC4;
else
result = *(double *)&LC5;
return result;
}

original_code: double dsgn(double A){ return (A<0.0)?(-1.0):(1.0); }


dmax

decompiled_code:
double __fastcall dmax(double a1, double a2)
{
return fmax(a1, a2);
}

canonical_decompiled_code:
double __fastcall func4(double a1, double a2)
{
return fmax(a1, a2);
}

original_code: double dmax(double A,double B){ return (A>B)?(A):(B); }

canonical_original_code: double dmax(double A, double B){ return (A>B)?(A):(B); }

variable_types: B double


dmin

decompiled_code:
__m128 __fastcall dmin(double a1, __m128 a2)
{
*(double *)a2.m128_u64 = fmin(*(double *)a2.m128_u64, a1);
return a2;
}

canonical_decompiled_code:
__m128 __fastcall func5(double a1, __m128 a2)
{
*(double *)a2.m128_u64 = fmin(*(double *)a2.m128_u64, a1);
return a2;
}

original_code: double dmin(double A,double B){ return (A>B)?(B):(A); }

canonical_original_code: double dmin(double A, double B){ return (A>B)?(B):(A); }


original_code:
void rk2(real* y, void (*deriv_func)(real, real*, int, real*, void*), real x, const int n, const real h, void* data) {
    int i;
    real k1[n], k2[n], ym[n];
    real xm;
    deriv_func(x,y,n,k1,data);
    for(i=0;i<n;i++) {
 ym[i]=y[i]+k1[i]*0.5*h;
    }
    xm=x+0.5*h;
    deriv_func(xm,ym,n,k2,data);
    for(i=0;i<n;i++) {
 y[i]=y[i]+k2[i]*h;
    }
}

canonical_original_code:
void rk2(double *y, void (*deriv_func)(double, double *, int, double *, void *), double x, int n, double h, void *data) {
    int i;
    double k1[-1]; double k2[-1]; double ym[-1];
    double xm;
    deriv_func(x,y,n,k1,data);
    for(i=0;i<n;i++) {
 ym[i]=y[i]+k1[i]*0.5*h;
    }
    xm=x+0.5*h;
    deriv_func(xm,ym,n,k2,data);
    for(i=0;i<n;i++) {
 y[i]=y[i]+k2[i]*h;
    }
}

variable_types:
y
double *

variable_types: void (*)(double, double *, int, double *, void *)

variable_types: x double

variable_types: n int

variable_types: h double

variable_types:
data
void *

variable_types: i int

variable_types:
ym
double [-1]

variable_types: xm double


original_code:
void rk4(real* y, void (*deriv_func)(real, real*, int, real*, void*), real t, const int n, const real h, void* data) {
    int i;
    real k1[n], k2[n], k3[n], k4[n], ym[n];
    real tm, k5;
    deriv_func(t,y,n,k1,data);
    for(i=0;i<n;i++) {
 ym[i]=y[i]+k1[i]*0.5*h;
    }
    tm=t+0.5*h;
    deriv_func(tm,ym,n,k2,data);
    for(i=0;i<n;i++) {
 ym[i]=y[i]+k2[i]*0.5*h;
    }
    deriv_func(tm,ym,n,k3,data);
    for(i=0;i<n;i++) {
 ym[i]=y[i]+k3[i]*h;
    }
    tm=t+h;
    deriv_func(tm,ym,n,k4,data);
    for(i=0;i<n;i++) {
 k5=(k1[i]+2.0*(k2[i]+k3[i])+k4[i])/6.0;
 y[i]=y[i]+k5*h;
    }
}

canonical_original_code:
void rk4(double *y, void (*deriv_func)(double, double *, int, double *, void *), double t, int n, double h, void *data) {
    int i;
    double k1[-1]; double k2[-1]; double k3[-1]; double k4[-1]; double ym[-1];
    double tm; double k5;
    deriv_func(t,y,n,k1,data);
    for(i=0;i<n;i++) {
 ym[i]=y[i]+k1[i]*0.5*h;
    }
    tm=t+0.5*h;
    deriv_func(tm,ym,n,k2,data);
    for(i=0;i<n;i++) {
 ym[i]=y[i]+k2[i]*0.5*h;
    }
    deriv_func(tm,ym,n,k3,data);
    for(i=0;i<n;i++) {
 ym[i]=y[i]+k3[i]*h;
    }
    tm=t+h;
    deriv_func(tm,ym,n,k4,data);
    for(i=0;i<n;i++) {
 k5=(k1[i]+2.0*(k2[i]+k3[i])+k4[i])/6.0;
 y[i]=y[i]+k5*h;
    }
}

variable_types: t double

variable_types: tm double


decompiled_code:
__int64 __fastcall rk8(void *dest, void (__fastcall *a2)(void *, _QWORD, _QWORD, __int64, double), int a3, __int64 a4, double a5, double a6)
{
int v7; // ebx
__int64 v8; // r12
__int64 v9; // r15
unsigned __int64 v10; // rbx
__int64 v11; // rbp
int i; // er13
double *v13; // rdi
__int64 v14; // rsi
unsigned __int64 v15; // rax
void *src; // [rsp+8h] [rbp-70h]
__int64 n; // [rsp+38h] [rbp-40h]

v7 = a3;
src = (void *)Alloc1DArray(8LL, (unsigned int)a3);
v8 = Alloc2DArray(8LL, 22LL, (unsigned int)v7);
n = 8LL * v7;
memcpy(src, dest, n);
v9 = (__int64)src + 8 * (unsigned int)(v7 - 1) + 8;
v10 = 8LL;
v11 = 0LL;
for ( i = 0; i != 11; ++i )
{
a2(src, (unsigned int)a3, *(_QWORD *)(v8 + v10 - 8), a4, a6 * *(double *)&c[v10 / 8 - 1] + a5);
if ( a3 > 0 )
{
v13 = (double *)src;
v14 = 0LL;
do
{
*v13 = *(double *)((char *)dest + v14);
if ( i >= 0 )
{
v15 = 0LL;
do
{
*v13 = a6 * *(double *)&a[v11 + v15 / 8] * *(double *)(*(_QWORD *)(v8 + v15) + v14) + *v13;
v15 += 8LL;
}
while ( v15 != v10 );
}
++v13;
v14 += 8LL;
}
while ( v13 != (double *)v9 );
}
v11 += 12LL;
v10 += 8LL;
}
memcpy(dest, src, n);
Free1DArray(src);
return Free2DArray(v8, 11LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(void *dest, void (__fastcall *a2)(void *, _QWORD, _QWORD, __int64, double), int a3, __int64 a4, double a5, double a6)
{
int v7; // ebx
__int64 v8; // r12
__int64 v9; // r15
unsigned __int64 v10; // rbx
__int64 v11; // rbp
int i; // er13
double *v13; // rdi
__int64 v14; // rsi
unsigned __int64 v15; // rax
void *src; // [rsp+8h] [rbp-70h]
__int64 n; // [rsp+38h] [rbp-40h]

v7 = a3;
src = (void *)Alloc1DArray(8LL, (unsigned int)a3);
v8 = Alloc2DArray(8LL, 22LL, (unsigned int)v7);
n = 8LL * v7;
memcpy(src, dest, n);
v9 = (__int64)src + 8 * (unsigned int)(v7 - 1) + 8;
v10 = 8LL;
v11 = 0LL;
for ( i = 0; i != 11; ++i )
{
a2(src, (unsigned int)a3, *(_QWORD *)(v8 + v10 - 8), a4, a6 * *(double *)&c[v10 / 8 - 1] + a5);
if ( a3 > 0 )
{
v13 = (double *)src;
v14 = 0LL;
do
{
*v13 = *(double *)((char *)dest + v14);
if ( i >= 0 )
{
v15 = 0LL;
do
{
*v13 = a6 * *(double *)&a[v11 + v15 / 8] * *(double *)(*(_QWORD *)(v8 + v15) + v14) + *v13;
v15 += 8LL;
}
while ( v15 != v10 );
}
++v13;
v14 += 8LL;
}
while ( v13 != (double *)v9 );
}
v11 += 12LL;
v10 += 8LL;
}
memcpy(dest, src, n);
Free1DArray(src);
return Free2DArray(v8, 11LL);
}

original_code:
void rk8(real* y, void (*deriv_func)(real, real*, int, real*, void*), real t, const int n, const real h, void* data) {
    int i,j,k;
    int nrk=11;
    real *ym = (real* )Alloc1DArray( sizeof(real), n );
    real **kn = (real**)Alloc2DArray( sizeof(real), nrk*2, n );
    memcpy( ym, y, sizeof(real)*n );
    for(i=0;i<nrk;i++) {
 deriv_func( t+h*c[i], ym, n, kn[i], data );
 for(j=0;j<n;j++) {
     ym[j] = y[j];
     for(k=0;k<i+1;k++) {
  ym[j] += a[i][k]*h*kn[k][j];
     }
 }
    }
    memcpy( y, ym, sizeof(real)*n );
    Free1DArray( (void*)ym );
    Free2DArray( (void**)kn, nrk);
}

canonical_original_code:
void rk8(double *y, void (*deriv_func)(double, double *, int, double *, void *), double t, int n, double h, void *data) {
    int i; int j; int k;
    int nrk = 11;
    double *ym = (real* )Alloc1DArray( sizeof(real), n );
    double **kn = (real**)Alloc2DArray( sizeof(real), nrk*2, n );
    memcpy( ym, y, sizeof(real)*n );
    for(i=0;i<nrk;i++) {
 deriv_func( t+h*c[i], ym, n, kn[i], data );
 for(j=0;j<n;j++) {
     ym[j] = y[j];
     for(k=0;k<i+1;k++) {
  ym[j] += a[i][k]*h*kn[k][j];
     }
 }
    }
    memcpy( y, ym, sizeof(real)*n );
    Free1DArray( (void *)ym );
    Free2DArray( (void **)kn, nrk);
}

variable_types: j int

variable_types: k int

variable_types: nrk int

variable_types:
ym
double *

variable_types:
kn
double **


iterate

decompiled_code:
__int64 iterate()
{
_BYTE v1[136]; // [rsp+0h] [rbp-88h] BYREF

(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, double, double))(p + 56LL))(
*(_QWORD *)(p + 8LL),
*(_QWORD *)(p + 48LL),
(unsigned int)(6 * *p),
ot,
0.0,
*(double *)(p + 32LL));
*(double *)(p + 40LL) = *(double *)(p + 40LL) + *(double *)(p + 32LL);
create_filename(v1, "../dat/data_", frame, 6LL, ".dat");
return write_particles(p, v1);
}

canonical_decompiled_code:
__int64 func0()
{
_BYTE v1[136]; // [rsp+0h] [rbp-88h] BYREF

(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD, double, double))(p + 56LL))(
*(_QWORD *)(p + 8LL),
*(_QWORD *)(p + 48LL),
(unsigned int)(6 * *p),
ot,
0.0,
*(double *)(p + 32LL));
*(double *)(p + 40LL) = *(double *)(p + 40LL) + *(double *)(p + 32LL);
create_filename(v1, "../dat/data_", frame, 6LL, ".dat");
return write_particles(p, v1);
}

original_code:
void iterate() {
    int i;
    char fname [128];
    int iters = 1;
    for(i=0;i<iters;i++) {
 p->integrate( p->x, p->gravity, 0.0, p->n*6, p->dt, (void*)ot );
 p->t += p->dt;
    }
    create_filename( fname, "../dat/data_",frame,6,".dat" );
    write_particles( p, fname );
}

canonical_original_code:
void iterate() {
    int i;
    char fname[128];
    int iters = 1;
    for(i=0;i<iters;i++) {
 p->integrate( p->x, p->gravity, 0.0, p->n*6, p->dt, (void *)ot );
 p->t += p->dt;
    }
    create_filename( fname, "../dat/data_",frame,6,".dat" );
    write_particles( p, fname );
}

variable_types:
fname
char [128]

variable_types: iters int


add

decompiled_code:
__int64 __fastcall add(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, __int64 a10, __int64 a11, __int64 a12, __int64 a13, __int64 a14, double a15, double a16, double a17, __int64 a18)
{
__int64 result; // rax

result = a1;
*(double *)a1 = a2 + a15;
*(double *)(a1 + 8) = a3 + a16;
*(double *)(a1 + 16) = a4 + a17;
*(_QWORD *)(a1 + 24) = a18;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, __int64 a10, __int64 a11, __int64 a12, __int64 a13, __int64 a14, double a15, double a16, double a17, __int64 a18)
{
__int64 result; // rax

result = a1;
*(double *)a1 = a2 + a15;
*(double *)(a1 + 8) = a3 + a16;
*(double *)(a1 + 16) = a4 + a17;
*(_QWORD *)(a1 + 24) = a18;
return result;
}

original_code:
point add(point a, real x, real y, real z) {
    point c; c.x = a.x+x; c.y = a.y+y; c.z = a.z+z; c.m = a.m;
    return c;
}

canonical_original_code:
struct point add(struct point a, double x, double y, double z) {
    struct point c; c.x = a.x+x; c.y = a.y+y; c.z = a.z+z; c.m = a.m;
    return c;
}

variable_types:
a
struct point

variable_types: y double

variable_types: z double

variable_types:
c
struct point { double x; }

return_type: struct point { double x; }


canonical_original_code:
void regular_gravity(double t, double *y, int n, double *yp, void *data) {
    int i; int j; int i6; int j6;
    double r; double r2; double r3; double dx; double dy; double dz; double Fx; double Fy; double Fz;
    struct particles *p = (particles*)data;
    double *m = p->m;
    double G = p->G;
    memset(yp,0,sizeof(real)*n);
    for(i=0;i<p->n;i++) {
 i6=i*6;
 yp[i6 ]=y[i6+3];
 yp[i6+1]=y[i6+4];
 yp[i6+2]=y[i6+5];
    }
    for(i=0;i<p->n;i++) {
 i6=6*i;
 for(j=0;j<i;j++) {
     j6=6*j;
     dx = y[i6 ]-y[j6 ];
     dy = y[i6+1]-y[j6+1];
     dz = y[i6+2]-y[j6+2];
     r2 = dx*dx+dy*dy+dz*dz;
     r = sqrt(r2);
     r3 = 1.0/((r*r2)<(0.00001)?(0.00001):(r*r2));
     Fx = G*dx*r3;
     Fy = G*dy*r3;
     Fz = G*dz*r3;
     yp[i6+3] -= Fx*m[j];
     yp[i6+4] -= Fy*m[j];
     yp[i6+5] -= Fz*m[j];
     yp[j6+3] += Fx*m[i];
     yp[j6+4] += Fy*m[i];
     yp[j6+5] += Fz*m[i];
 }
    }
}

variable_types:
y
double *

variable_types: n int

variable_types:
yp
double *

variable_types:
data
void *

variable_types: r double

variable_types: dx double

variable_types: dy double

variable_types: dz double

variable_types: Fx double

variable_types: Fy double

variable_types: Fz double

variable_types: struct particles { int n; double *x; double *m; double G; double dt; void (*gravity)(double, double *, int, double *, void *); void (*integrate)(double *y, void (*deriv_func)(double, double *, int, double *, void *), double x, int n, double h, void *data); } *

variable_types:
m
double *

variable_types: G double


emisor

decompiled_code:
void __fastcall __noreturn emisor(void *a1)
{
int v1; // eax
int v2; // ebx
size_t v3; // [rsp+0h] [rbp-B8h] BYREF
char *src; // [rsp+8h] [rbp-B0h] BYREF
char dest[128]; // [rsp+10h] [rbp-A8h] BYREF
int v6; // [rsp+90h] [rbp-28h]

v1 = open(*(const char **)a1, 1);
src = 0LL;
if ( v1 != -1 )
{
v2 = v1;
strncpy(dest, *((const char **)a1 + 1), 0x7FuLL);
v6 = 1;
write(v2, dest, 0x84uLL);
free(a1);
while ( (unsigned int)getline(&src, &v3, _bss_start) != -1 )
{
strncpy(dest, src, 0x7FuLL);
v6 = 0;
write(v2, dest, 0x84uLL);
}
if ( src )
free(src);
dest[0] = 0;
v6 = 2;
write(v2, dest, 0x84uLL);
close(v2);
exit(0);
}
fwrite("Error al abrir el pipe\n", 1uLL, 0x17uLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
int v1; // eax
int v2; // ebx
size_t v3; // [rsp+0h] [rbp-B8h] BYREF
char *src; // [rsp+8h] [rbp-B0h] BYREF
char dest[128]; // [rsp+10h] [rbp-A8h] BYREF
int v6; // [rsp+90h] [rbp-28h]

v1 = open(*(const char **)a1, 1);
src = 0LL;
if ( v1 != -1 )
{
v2 = v1;
strncpy(dest, *((const char **)a1 + 1), 0x7FuLL);
v6 = 1;
write(v2, dest, 0x84uLL);
free(a1);
while ( (unsigned int)getline(&src, &v3, _bss_start) != -1 )
{
strncpy(dest, src, 0x7FuLL);
v6 = 0;
write(v2, dest, 0x84uLL);
}
if ( src )
free(src);
dest[0] = 0;
v6 = 2;
write(v2, dest, 0x84uLL);
close(v2);
exit(0);
}
fwrite("Error al abrir el pipe\n", 1uLL, 0x17uLL, stderr);
exit(1);
}

original_code:
void* emisor(void *ptr){
    struct thread_args *args = (struct thread_args *)ptr;
    int pipe = open(args->canal, 01);
    struct mensaje_t m;
    char *line = ((void *)0);
    int nread;
    size_t len;
    ptr = ((void *)0);
    if(pipe == -1){
        fprintf(stderr, "Error al abrir el pipe\n");
        exit(1);
    }
    strncpy(m.contenido, args->nombre, 128 -1);
    m.tipo = MENSAJE_NOMBRE;
    write(pipe, &m, sizeof(struct mensaje_t));
    free(args);
    args = ((void *)0);
    while((nread = getline(&line, &len, stdin)) != -1){
        strncpy(m.contenido, line, 128 -1);
        m.tipo = MENSAJE_NORMAL;
        write(pipe, &m, sizeof(struct mensaje_t));
    }
    if(line != ((void *)0))
        free(line);
    m.contenido[0] = 0;
    m.tipo = MENSAJE_FIN;
    write(pipe, &m, sizeof(struct mensaje_t));
    close(pipe);
    exit(0);
}

canonical_original_code:
void *emisor(void *ptr){
    struct thread_args *args = (struct thread_args *)ptr;
    int pipe = open(args->canal, 01);
    struct mensaje_t m;
    char *line = ((void *)0);
    int nread;
    unsigned long len;
    ptr = ((void *)0);
    if(pipe == -1){
        fprintf(stderr, "Error al abrir el pipe\n");
        exit(1);
    }
    strncpy(m.contenido, args->nombre, 128 -1);
    m.tipo = MENSAJE_NOMBRE;
    write(pipe, &m, sizeof(struct mensaje_t));
    free(args);
    args = ((void *)0);
    while((nread = getline(&line, &len, stdin)) != -1){
        strncpy(m.contenido, line, 128 -1);
        m.tipo = MENSAJE_NORMAL;
        write(pipe, &m, sizeof(struct mensaje_t));
    }
    if(line != ((void *)0))
        free(line);
    m.contenido[0] = 0;
    m.tipo = MENSAJE_FIN;
    write(pipe, &m, sizeof(struct mensaje_t));
    close(pipe);
    exit(0);
}

variable_types:
ptr
void *

variable_types: struct thread_args { char *canal; char *nombre; } *

variable_types: pipe int

variable_types: struct mensaje_t { char contenido[128]; enum tipo_mensaje { MENSAJE_NORMAL=0, MENSAJE_NOMBRE=1, MENSAJE_FIN=2 } tipo; }

variable_types:
line
char *

variable_types: nread int

variable_types:
len
unsigned long

user_defined_types: struct mensaje_t { char contenido[128]; enum tipo_mensaje tipo; }


receptor

decompiled_code:
void *__fastcall receptor(void *a1)
{
int v1; // ebx
char v3[128]; // [rsp+0h] [rbp-138h] BYREF
int v4; // [rsp+80h] [rbp-B8h]
char buf[128]; // [rsp+90h] [rbp-A8h] BYREF
int v6; // [rsp+110h] [rbp-28h]

v1 = open(*(const char **)a1, 0);
free(a1);
if ( v1 == -1 )
{
fwrite("Error al abrir el pipe\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
read(v1, buf, 0x84uLL);
if ( v6 == 1 )
{
printf(format, buf);
while ( 1 )
{
if ( (int)read(v1, v3, 0x84uLL) <= 0 )
goto LABEL_9;
if ( v4 )
break;
printf("+%s dice: %s", buf, v3);
}
fwrite(&unk_4020C8, 1uLL, 0x26uLL, stderr);
LABEL_9:
close(v1);
exit(0);
}
fwrite("FALLO DE PROTOCOLO\n", 1uLL, 0x13uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // ebx
char v3[128]; // [rsp+0h] [rbp-138h] BYREF
int v4; // [rsp+80h] [rbp-B8h]
char buf[128]; // [rsp+90h] [rbp-A8h] BYREF
int v6; // [rsp+110h] [rbp-28h]

v1 = open(*(const char **)a1, 0);
free(a1);
if ( v1 == -1 )
{
fwrite("Error al abrir el pipe\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
read(v1, buf, 0x84uLL);
if ( v6 == 1 )
{
printf(format, buf);
while ( 1 )
{
if ( (int)read(v1, v3, 0x84uLL) <= 0 )
goto LABEL_9;
if ( v4 )
break;
printf("+%s dice: %s", buf, v3);
}
fwrite(&unk_4020C8, 1uLL, 0x26uLL, stderr);
LABEL_9:
close(v1);
exit(0);
}
fwrite("FALLO DE PROTOCOLO\n", 1uLL, 0x13uLL, stderr);
return 0LL;
}

original_code:
void* receptor(void *ptr){
    struct thread_args *args = (struct thread_args *) ptr;
    int pipe = open(args->canal, 00);
    struct mensaje_t nombre, m;
    int nread = 0;
    free(args);
    args = ((void *)0);
    ptr = ((void *)0);
    if(pipe == -1){
        fprintf(stderr, "Error al abrir el pipe\n");
        exit(1);
    }
    nread = read(pipe, &nombre, sizeof(struct mensaje_t));
    if(nombre.tipo != MENSAJE_NOMBRE){
        fprintf(stderr, "FALLO DE PROTOCOLO\n");
        return ((void *)0);
    }
    printf("Conexión establecida con %s\n", nombre.contenido);
    while((nread = read(pipe, &m, sizeof(struct mensaje_t))) > 0){
        if(m.tipo == MENSAJE_NORMAL)
            printf("+%s dice: %s", nombre.contenido, m.contenido);
        else{
            fprintf(stderr,"Conexión cerrada por el otro extremo\n");
            break;
        }
    }
    close(pipe);
    exit(0);
}

canonical_original_code:
void *receptor(void *ptr){
    struct thread_args *args = (struct thread_args *) ptr;
    int pipe = open(args->canal, 00);
    struct mensaje_t nombre; struct mensaje_t m;
    int nread = 0;
    free(args);
    args = ((void *)0);
    ptr = ((void *)0);
    if(pipe == -1){
        fprintf(stderr, "Error al abrir el pipe\n");
        exit(1);
    }
    nread = read(pipe, &nombre, sizeof(struct mensaje_t));
    if(nombre.tipo != MENSAJE_NOMBRE){
        fprintf(stderr, "FALLO DE PROTOCOLO\n");
        return ((void *)0);
    }
    printf("Conexión establecida con %s\n", nombre.contenido);
    while((nread = read(pipe, &m, sizeof(struct mensaje_t))) > 0){
        if(m.tipo == MENSAJE_NORMAL)
            printf("+%s dice: %s", nombre.contenido, m.contenido);
        else{
            fprintf(stderr,"Conexión cerrada por el otro extremo\n");
            break;
        }
    }
    close(pipe);
    exit(0);
}

user_defined_types: struct thread_args { char *canal; char *nombre; }

user_defined_types: enum tipo_mensaje { MENSAJE_NORMAL=0, MENSAJE_NOMBRE=1, MENSAJE_FIN=2 }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // r12
_QWORD *v4; // rax
void *v5; // rbp
pthread_t th; // [rsp+0h] [rbp-28h] BYREF
pthread_t newthread[4]; // [rsp+8h] [rbp-20h] BYREF

if ( argc != 4 )
{
fprintf(stderr, "Usage: %s Nombre fifo_out fifo_in\n", *argv);
exit(1);
}
v3 = malloc(0x10uLL);
v4 = malloc(0x10uLL);
v5 = v4;
if ( v3 && v4 )
{
*v3 = argv[3];
*v4 = argv[2];
v4[1] = argv[1];
puts("Iniciando chat...");
if ( pthread_create(newthread, 0LL, (void *(*)(void *))emisor, v5) )
{
fwrite("Error al crear hilo emisor\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
if ( pthread_create(&th, 0LL, receptor, v3) )
{
fwrite("Error al crear hilo receptor\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
pthread_join(newthread[0], 0LL);
pthread_join(th, 0LL);
puts("ADIOS!");
exit(0);
}
fwrite("Error alojar memoria\n", 1uLL, 0x15uLL, stderr);
exit(1);
}

original_code:
int main(int argc, char *argv[]) {
    struct thread_args *rec, *emi;
    pthread_t emith, recth;
    if (argc != 4){
        fprintf(stderr, "Usage: %s Nombre fifo_out fifo_in\n", argv[0]);
        exit(1);
    }
    rec = malloc(sizeof(struct thread_args));
    emi = malloc(sizeof(struct thread_args));
    if(rec == ((void *)0) || emi == ((void *)0)){
        fprintf(stderr, "Error alojar memoria\n");
        exit(1);
    }
    rec->canal = argv[3];
    emi->canal = argv[2];
    emi->nombre = argv[1];
    printf("Iniciando chat...\n");
    if(pthread_create(&emith, ((void *)0), emisor, (void *)emi) != 0){
        fprintf(stderr, "Error al crear hilo emisor\n");
        exit(1);
    }
    if(pthread_create(&recth, ((void *)0), receptor, (void *)rec) != 0){
        fprintf(stderr, "Error al crear hilo receptor\n");
        exit(1);
    }
    pthread_join(emith, ((void *)0));
    pthread_join(recth, ((void *)0));
    printf("ADIOS!\n");
    exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct thread_args *rec; struct thread_args *emi;
    unsigned long emith; unsigned long recth;
    if (argc != 4){
        fprintf(stderr, "Usage: %s Nombre fifo_out fifo_in\n", argv[0]);
        exit(1);
    }
    rec = malloc(sizeof(struct thread_args));
    emi = malloc(sizeof(struct thread_args));
    if(rec == ((void *)0) || emi == ((void *)0)){
        fprintf(stderr, "Error alojar memoria\n");
        exit(1);
    }
    rec->canal = argv[3];
    emi->canal = argv[2];
    emi->nombre = argv[1];
    printf("Iniciando chat...\n");
    if(pthread_create(&emith, ((void *)0), emisor, (void *)emi) != 0){
        fprintf(stderr, "Error al crear hilo emisor\n");
        exit(1);
    }
    if(pthread_create(&recth, ((void *)0), receptor, (void *)rec) != 0){
        fprintf(stderr, "Error al crear hilo receptor\n");
        exit(1);
    }
    pthread_join(emith, ((void *)0));
    pthread_join(recth, ((void *)0));
    printf("ADIOS!\n");
    exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
emith
unsigned long

variable_types:
recth
unsigned long

return_type: int


decompiled_code:
__int64 __fastcall reader_getFileType(char *s1)
{
int v1; // edx
__int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // edx
int v8; // edx

v1 = strcasecmp(s1, "netcdf");
result = 1LL;
if ( v1 )
{
v3 = strcasecmp(s1, "cdf");
result = 1LL;
if ( v3 )
{
v4 = strcasecmp(s1, "nc");
result = 1LL;
if ( v4 )
{
v5 = strcasecmp(s1, "hdf5");
result = 2LL;
if ( v5 )
{
v6 = strcasecmp(s1, "h5");
result = 2LL;
if ( v6 )
{
v7 = strcasecmp(s1, "adiosbp");
result = 3LL;
if ( v7 )
{
v8 = strcasecmp(s1, "bp");
result = 3LL;
if ( v8 )
result = strcasecmp(s1, "adios") == 0 ? 3 : 0;
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
int v1; // edx
__int64 result; // rax
int v3; // edx
int v4; // edx
int v5; // edx
int v6; // edx
int v7; // edx
int v8; // edx

v1 = strcasecmp(s1, "netcdf");
result = 1LL;
if ( v1 )
{
v3 = strcasecmp(s1, "cdf");
result = 1LL;
if ( v3 )
{
v4 = strcasecmp(s1, "nc");
result = 1LL;
if ( v4 )
{
v5 = strcasecmp(s1, "hdf5");
result = 2LL;
if ( v5 )
{
v6 = strcasecmp(s1, "h5");
result = 2LL;
if ( v6 )
{
v7 = strcasecmp(s1, "adiosbp");
result = 3LL;
if ( v7 )
{
v8 = strcasecmp(s1, "bp");
result = 3LL;
if ( v8 )
result = strcasecmp(s1, "adios") == 0 ? 3 : 0;
}
}
}
}
}
}
return result;
}

canonical_original_code:
enum FileType reader_getFileType(char *str) {
    if (!strcasecmp(str,"netcdf") ||
        !strcasecmp(str,"cdf") ||
        !strcasecmp(str,"nc")
       )
        return netcdf_file;
    else if (!strcasecmp(str,"hdf5") ||
             !strcasecmp(str,"h5")
            )
        return hdf5_file;
    else if (!strcasecmp(str,"adiosbp") ||
             !strcasecmp(str,"bp") ||
             !strcasecmp(str,"adios")
            )
        return adiosbp_file;
    else
        return undef_file;
}

variable_types:
str
char *

return_type: enum FileType { undef_file=0, netcdf_file=1, hdf5_file=2, adiosbp_file=3, ascii_file=4 }


decompiled_code:
__int64 __fastcall reader_guessFileType(const char *a1)
{
char *v1; // rax
char *v2; // rbx
__int64 result; // rax

v1 = strrchr(a1, 46);
v2 = v1;
if ( verbose > 1 )
printf("guess file type from ext: %s\n", v1);
result = 0LL;
if ( v2 )
result = reader_getFileType(v2 + 1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
char *v1; // rax
char *v2; // rbx
__int64 result; // rax

v1 = strrchr(a1, 46);
v2 = v1;
if ( verbose > 1 )
printf("guess file type from ext: %s\n", v1);
result = 0LL;
if ( v2 )
result = func0(v2 + 1);
return result;
}

original_code:
static FileType reader_guessFileType(char *path) {
    FileType type = undef_file;
    char *ext = strrchr(path, (int)'.');
    if (verbose>1) printf("guess file type from ext: %s\n", ext);
    if (ext != ((void *)0)) {
       ext++;
       if (ext != ((void *)0))
           type = reader_getFileType(ext);
    }
    return type;
}

canonical_original_code:
static enum FileType reader_guessFileType(char *path) {
    enum FileType type = undef_file;
    char *ext = strrchr(path, (int)'.');
    if (verbose>1) printf("guess file type from ext: %s\n", ext);
    if (ext != ((void *)0)) {
       ext++;
       if (ext != ((void *)0))
           type = reader_getFileType(ext);
    }
    return type;
}

variable_types:
path
char *

variable_types: enum FileType { undef_file=0, netcdf_file=1, hdf5_file=2, adiosbp_file=3, ascii_file=4 }

variable_types:
ext
char *