glDisplay

decompiled_code:
__int64 glDisplay()
{
int v1; // ebx
double v2; // xmm3_8
char v3[40]; // [rsp+10h] [rbp-28h] BYREF

glClear(16640LL);
if ( axisOn )
{
v1 = -10;
glBegin(1LL);
do
{
glColor3f(0.2, 0.2);
v2 = (double)v1 / 10.0;
*(float *)&v2 = v2;
v1 += 2;
glVertex3f(v2, -0.50099999, 1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LODWORD(v2)), -0.50099999, -1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC4), -0.50099999, *(float *)&v2);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC2), -0.50099999, *(float *)&v2);
glColor3f(1.0, 1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LODWORD(v2)), -0.50099999, 0.02);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LODWORD(v2)), -0.50099999, -0.02);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC6), -0.50099999, *(float *)&v2);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC5), -0.50099999, *(float *)&v2);
}
while ( v1 != 12 );
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(v3, 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 v1; // ebx
double v2; // xmm3_8
char v3[40]; // [rsp+10h] [rbp-28h] BYREF

glClear(16640LL);
if ( axisOn )
{
v1 = -10;
glBegin(1LL);
do
{
glColor3f(0.2, 0.2);
v2 = (double)v1 / 10.0;
*(float *)&v2 = v2;
v1 += 2;
glVertex3f(v2, -0.50099999, 1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LODWORD(v2)), -0.50099999, -1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC4), -0.50099999, *(float *)&v2);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC2), -0.50099999, *(float *)&v2);
glColor3f(1.0, 1.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LODWORD(v2)), -0.50099999, 0.02);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LODWORD(v2)), -0.50099999, -0.02);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC6), -0.50099999, *(float *)&v2);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC5), -0.50099999, *(float *)&v2);
}
while ( v1 != 12 );
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(v3, 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

repo: rreusser/octree-gravity

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

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

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

if ( a1 != 1 )
{
if ( simulationOn != 1 )
return result;
LABEL_5:
result = glutTimerFunc((unsigned int)(1000 / fps), glRedisplay, 1LL);
nextdisp = 1;
return result;
}
result = func0();
if ( simulationOn == 1 )
goto LABEL_5;
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

return_type: void


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:
double *__fastcall uniform_masses(unsigned int *a1, double a2)
{
double *result; // rax
double *v3; // rdx
__int64 v4; // rcx
__int64 v5; // rcx

result = (double *)*a1;
if ( (int)result > 0 )
{
v3 = (double *)*((_QWORD *)a1 + 2);
v4 = (unsigned int)((_DWORD)result - 1);
result = v3 + 1;
v5 = (__int64)&v3[v4 + 1];
while ( 1 )
{
*v3 = a2;
v3 = result;
if ( result == (double *)v5 )
break;
++result;
}
}
return result;
}

canonical_decompiled_code:
double *__fastcall func4(unsigned int *a1, double a2)
{
double *result; // rax
double *v3; // rdx
__int64 v4; // rcx
__int64 v5; // rcx

result = (double *)*a1;
if ( (int)result > 0 )
{
v3 = (double *)*((_QWORD *)a1 + 2);
v4 = (unsigned int)((_DWORD)result - 1);
result = v3 + 1;
v5 = (__int64)&v3[v4 + 1];
while ( 1 )
{
*v3 = a2;
v3 = result;
if ( result == (double *)v5 )
break;
++result;
}
}
return result;
}

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(unsigned int *a1, double a2, double a3)
{
__int64 result; // rax
__int64 v4; // rbx
double v5; // xmm0_8
double v7; // [rsp+8h] [rbp-20h]

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

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, double a2, double a3)
{
__int64 result; // rax
__int64 v4; // rbx
double v5; // xmm0_8
double v7; // [rsp+8h] [rbp-20h]

result = *a1;
if ( (int)result > 0 )
{
v4 = 0LL;
v7 = a3 - a2;
do
{
v5 = drand48();
result = *((_QWORD *)a1 + 2);
*(double *)(result + 8 * v4++) = v5 * v7 + a2;
}
while ( (int)*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);
++v2;
v4 = *(double *)(v3 + v1 - 16);
v5 = *(double *)(v3 + v1);
v6 = *(double *)(v3 + v1 - 8);
v1 += 48LL;
glVertex3f(v4, v6, v5);
}
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


decompiled_code:
double *__fastcall bound_particles(unsigned int *a1, double a2)
{
double *result; // rax
int v4; // ecx
__int64 v5; // xmm5_8
int v6; // esi
__m128d v7; // xmm3
__int64 v8; // rdx
__m128d v9; // xmm0

result = (double *)*a1;
if ( (int)result > 0 )
{
v4 = 0;
v5 = *(_QWORD *)&a2 ^ LC23;
v6 = 6 * (_DWORD)result;
v7.m128d_f64[0] = 0.0;
v8 = *((_QWORD *)a1 + 1) + 24LL;
do
{
result = (double *)(v8 - 24);
do
{
if ( COERCE_DOUBLE(*(_QWORD *)result & LC22) > a2 )
{
v9.m128d_f64[0] = *result;
v9.m128d_f64[0] = _mm_cmplt_sd(v9, v7).m128d_f64[0];
*(_QWORD *)result = ~*(_QWORD *)&v9.m128d_f64[0] & *(_QWORD *)&a2 | v5 & *(_QWORD *)&v9.m128d_f64[0];
}
++result;
}
while ( (double *)v8 != result );
v4 += 6;
v8 += 48LL;
}
while ( v4 != v6 );
}
return result;
}

canonical_decompiled_code:
double *__fastcall func8(unsigned int *a1, double a2)
{
double *result; // rax
int v4; // ecx
__int64 v5; // xmm5_8
int v6; // esi
__m128d v7; // xmm3
__int64 v8; // rdx
__m128d v9; // xmm0

result = (double *)*a1;
if ( (int)result > 0 )
{
v4 = 0;
v5 = *(_QWORD *)&a2 ^ LC23;
v6 = 6 * (_DWORD)result;
v7.m128d_f64[0] = 0.0;
v8 = *((_QWORD *)a1 + 1) + 24LL;
do
{
result = (double *)(v8 - 24);
do
{
if ( COERCE_DOUBLE(*(_QWORD *)result & LC22) > a2 )
{
v9.m128d_f64[0] = *result;
v9.m128d_f64[0] = _mm_cmplt_sd(v9, v7).m128d_f64[0];
*(_QWORD *)result = ~*(_QWORD *)&v9.m128d_f64[0] & *(_QWORD *)&a2 | v5 & *(_QWORD *)&v9.m128d_f64[0];
}
++result;
}
while ( (double *)v8 != result );
v4 += 6;
v8 += 48LL;
}
while ( v4 != v6 );
}
return result;
}

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:
int __fastcall glKeyboard(char a1)
{
int result; // eax
__int64 v2; // rdx

switch ( a1 )
{
case ' ':
result = simulationOn;
if ( simulationOn )
{
simulationOn = 0;
}
else
{
simulationOn = 1;
result = glRedisplay(1LL);
}
break;
case ')':
result = glutFullScreen();
full = 1;
break;
case '-':
result = p;
*(double *)(p + 32LL) = *(double *)(p + 32LL) / 1.1;
break;
case '0':
if ( full == 1 )
{
glutReshapeWindow((_BYTE *)&loc_1F3 + 1, 500LL);
glutPositionWindow(100LL, 100LL);
}
else
{
glutReshapeWindow("%i\n", 768LL);
glutPositionWindow(0LL, 4294967286LL);
}
result = full == 0;
full = result;
break;
case '=':
result = p;
*(double *)(p + 32LL) = 1.1 * *(double *)(p + 32LL);
break;
case 'a':
axisOn = 1 - axisOn;
result = glDisplay();
break;
case 'i':
v2 = rk_number;
switch ( rk_number )
{
case 4:
v2 = 8LL;
rk_number = 8;
*(_QWORD *)(p + 56LL) = &rk8;
break;
case 8:
v2 = 2LL;
rk_number = 2;
*(_QWORD *)(p + 56LL) = &rk2;
break;
case 2:
v2 = 4LL;
rk_number = 4;
*(_QWORD *)(p + 56LL) = &rk4;
break;
}
result = fprintf(stderr, "Using RK%i integrator\n", v2);
break;
case 'o':
drawOctreeOn = 1 - drawOctreeOn;
result = 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);
result = glDisplay();
break;
case 's':
sampleForceOn = 1 - sampleForceOn;
result = glDisplay();
break;
case 't':
drawTreeOn = 1 - drawTreeOn;
result = glDisplay();
break;
case 'v':
result = glDisplay();
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char a1)
{
int result; // eax
__int64 v2; // rdx

switch ( a1 )
{
case ' ':
result = simulationOn;
if ( simulationOn )
{
simulationOn = 0;
}
else
{
simulationOn = 1;
result = glRedisplay(1LL);
}
break;
case ')':
result = glutFullScreen();
full = 1;
break;
case '-':
result = p;
*(double *)(p + 32LL) = *(double *)(p + 32LL) / 1.1;
break;
case '0':
if ( full == 1 )
{
glutReshapeWindow((_BYTE *)&loc_1F3 + 1, 500LL);
glutPositionWindow(100LL, 100LL);
}
else
{
glutReshapeWindow("%i\n", 768LL);
glutPositionWindow(0LL, 4294967286LL);
}
result = full == 0;
full = result;
break;
case '=':
result = p;
*(double *)(p + 32LL) = 1.1 * *(double *)(p + 32LL);
break;
case 'a':
axisOn = 1 - axisOn;
result = glDisplay();
break;
case 'i':
v2 = rk_number;
switch ( rk_number )
{
case 4:
v2 = 8LL;
rk_number = 8;
*(_QWORD *)(p + 56LL) = &rk8;
break;
case 8:
v2 = 2LL;
rk_number = 2;
*(_QWORD *)(p + 56LL) = &rk2;
break;
case 2:
v2 = 4LL;
rk_number = 4;
*(_QWORD *)(p + 56LL) = &rk4;
break;
}
result = fprintf(stderr, "Using RK%i integrator\n", v2);
break;
case 'o':
drawOctreeOn = 1 - drawOctreeOn;
result = 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);
result = glDisplay();
break;
case 's':
sampleForceOn = 1 - sampleForceOn;
result = glDisplay();
break;
case 't':
drawTreeOn = 1 - drawTreeOn;
result = glDisplay();
break;
case 'v':
result = glDisplay();
break;
default:
return result;
}
return result;
}

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)
{
double v1; // xmm0_8
int v2; // edx
int v3; // eax

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

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

if ( a1 == 102 )
{
++sample;
glDisplay();
}
else if ( a1 > 102 )
{
if ( a1 == 103 )
{
v1 = bh_factor - 0.05;
LABEL_6:
bh_factor = *(_QWORD *)&v1;
fprintf(stderr, "Barnes Hut factor = %f\n", v1);
glDisplay();
goto LABEL_7;
}
}
else
{
if ( a1 != 100 )
{
if ( a1 != 101 )
goto LABEL_7;
v1 = bh_factor + 0.05;
goto LABEL_6;
}
--sample;
glDisplay();
}
LABEL_7:
v2 = *p;
v3 = 0;
if ( sample >= 0 )
v3 = sample;
if ( v2 <= v3 )
v3 = v2 - 1;
sample = v3;
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 func3(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

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 func3(__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)
{
float *v2; // rax
double v4; // [rsp+0h] [rbp-18h]

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();
v2 = *(float **)(a1 + 32);
v4 = v2[2];
gluLookAt(
**(float **)a1,
*(float *)(*(_QWORD *)a1 + 4LL),
*(float *)(*(_QWORD *)a1 + 8LL),
**(float **)(a1 + 16),
*(float *)(*(_QWORD *)(a1 + 16) + 4LL),
*(float *)(*(_QWORD *)(a1 + 16) + 8LL),
*v2,
v2[1],
5888LL);
return *(_QWORD *)&v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
float *v2; // rax
double v4; // [rsp+0h] [rbp-18h]

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();
v2 = *(float **)(a1 + 32);
v4 = v2[2];
gluLookAt(
**(float **)a1,
*(float *)(*(_QWORD *)a1 + 4LL),
*(float *)(*(_QWORD *)a1 + 8LL),
**(float **)(a1 + 16),
*(float *)(*(_QWORD *)(a1 + 16) + 4LL),
*(float *)(*(_QWORD *)(a1 + 16) + 8LL),
*v2,
v2[1],
5888LL);
return *(_QWORD *)&v4;
}

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 func5(_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 *v7; // rax
float *result; // rax

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

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

v7 = *a1;
*v7 = a2;
v7[1] = a3;
v7[2] = a4;
result = a1[2];
*result = a5;
result[1] = a6;
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:
float *__fastcall CameraPositionRPTXYZ(__int64 a1, float a2, float a3, float a4, __m128i a5, __m128i a6, float a7)
{
float v7; // er15
float v8; // er14
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
float v16; // xmm0_4
float *result; // rax
double v19; // [rsp+0h] [rbp-38h]
double v20; // [rsp+0h] [rbp-38h]
double v21; // [rsp+0h] [rbp-38h]
double v22; // [rsp+0h] [rbp-38h]

v7 = COERCE_FLOAT(_mm_cvtsi128_si32(a6));
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(a5));
*(float *)(a1 + 88) = a2;
*(float *)(a1 + 96) = a3;
*(float *)(a1 + 80) = a4;
v9 = radians(a4);
v19 = a2 * cos(v9);
v10 = radians(a3);
v11 = sin(v10) * v19;
v20 = *(float *)(a1 + 88);
*(float *)&v11 = v11 + v8;
**(_DWORD **)a1 = LODWORD(v11);
v12 = radians(a3);
v13 = cos(v12) * v20;
v21 = *(float *)(a1 + 88);
*(float *)&v13 = v13 + v7;
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = LODWORD(v13);
v14 = radians(a4);
v22 = sin(v14) * v21;
v15 = radians(a3);
v16 = sin(v15) * v22 + a7;
*(float *)(*(_QWORD *)a1 + 8LL) = v16;
result = *(float **)(a1 + 16);
*result = v8;
result[1] = v7;
result[2] = a7;
return result;
}

canonical_decompiled_code:
float *__fastcall func8(__int64 a1, float a2, float a3, float a4, __m128i a5, __m128i a6, float a7)
{
float v7; // er15
float v8; // er14
double v9; // xmm0_8
double v10; // xmm0_8
double v11; // xmm0_8
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm0_8
double v15; // xmm0_8
float v16; // xmm0_4
float *result; // rax
double v19; // [rsp+0h] [rbp-38h]
double v20; // [rsp+0h] [rbp-38h]
double v21; // [rsp+0h] [rbp-38h]
double v22; // [rsp+0h] [rbp-38h]

v7 = COERCE_FLOAT(_mm_cvtsi128_si32(a6));
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(a5));
*(float *)(a1 + 88) = a2;
*(float *)(a1 + 96) = a3;
*(float *)(a1 + 80) = a4;
v9 = radians(a4);
v19 = a2 * cos(v9);
v10 = radians(a3);
v11 = sin(v10) * v19;
v20 = *(float *)(a1 + 88);
*(float *)&v11 = v11 + v8;
**(_DWORD **)a1 = LODWORD(v11);
v12 = radians(a3);
v13 = cos(v12) * v20;
v21 = *(float *)(a1 + 88);
*(float *)&v13 = v13 + v7;
*(_DWORD *)(*(_QWORD *)a1 + 4LL) = LODWORD(v13);
v14 = radians(a4);
v22 = sin(v14) * v21;
v15 = radians(a3);
v16 = sin(v15) * v22 + a7;
*(float *)(*(_QWORD *)a1 + 8LL) = v16;
result = *(float **)(a1 + 16);
*result = v8;
result[1] = v7;
result[2] = 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(float *a1, float a2, float a3, float a4)
{
float *v4; // rax

v4 = (float *)*((_QWORD *)a1 + 2);
*v4 = a2;
v4[1] = a3;
v4[2] = a4;
return CameraReposition(a1);
}

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

v4 = (float *)*((_QWORD *)a1 + 2);
*v4 = a2;
v4[1] = a3;
v4[2] = a4;
return func9(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 func12(_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
float v7; // xmm1_4

result = CameraRemember(cam);
if ( !a2 )
{
v7 = (float)*(int *)(cam + 116LL);
*(double *)&mpx0 = (float)((float)a3 / (float)*(int *)(cam + 112LL));
*(double *)&mpy0 = 1.0 - (float)((float)a4 / v7);
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
float v7; // xmm1_4

result = CameraRemember(cam);
if ( !a2 )
{
v7 = (float)*(int *)(cam + 116LL);
*(double *)&mpx0 = (float)((float)a3 / (float)*(int *)(cam + 112LL));
*(double *)&mpy0 = 1.0 - (float)((float)a4 / v7);
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:
__int64 __fastcall glMotionFunc(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // r8
float v4; // xmm1_4
double v5; // xmm0_8
double v6; // xmm2_8
double v7; // xmm1_8
double v8; // xmm2_8
__int64 v9; // rdi
float v10; // xmm0_4
__int64 v11; // r12
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // r12
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
unsigned int v19; // [rsp+0h] [rbp-48h]
double v20; // [rsp+0h] [rbp-48h]
char v21[12]; // [rsp+10h] [rbp-38h] BYREF
char v22[12]; // [rsp+1Ch] [rbp-2Ch] BYREF
char v23[12]; // [rsp+28h] [rbp-20h] BYREF
char v24[20]; // [rsp+34h] [rbp-14h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // r8
float v4; // xmm1_4
double v5; // xmm0_8
double v6; // xmm2_8
double v7; // xmm1_8
double v8; // xmm2_8
__int64 v9; // rdi
float v10; // xmm0_4
__int64 v11; // r12
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // r12
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
unsigned int v19; // [rsp+0h] [rbp-48h]
double v20; // [rsp+0h] [rbp-48h]
char v21[12]; // [rsp+10h] [rbp-38h] BYREF
char v22[12]; // [rsp+1Ch] [rbp-2Ch] BYREF
char v23[12]; // [rsp+28h] [rbp-20h] BYREF
char v24[20]; // [rsp+34h] [rbp-14h] BYREF

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

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


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()
{
__int64 v0; // rdx
_BYTE v2[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));
v0 = frame;
*(double *)(p + 40LL) = *(double *)(p + 40LL) + *(double *)(p + 32LL);
create_filename(v2, "../dat/data_", v0, 6LL, ".dat");
return write_particles(p, v2);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rdx
_BYTE v2[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));
v0 = frame;
*(double *)(p + 40LL) = *(double *)(p + 40LL) + *(double *)(p + 32LL);
create_filename(v2, "../dat/data_", v0, 6LL, ".dat");
return write_particles(p, v2);
}

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


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_QWORD *v3; // r13
_QWORD *v4; // rax
void *v5; // r12
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(&th, 0LL, emisor, v5) )
{
if ( pthread_create(newthread, 0LL, receptor, v3) )
{
fwrite("Error al crear hilo receptor\n", 1uLL, 0x1DuLL, stderr);
exit(1);
}
pthread_join(th, 0LL);
pthread_join(newthread[0], 0LL);
puts("ADIOS!");
exit(0);
}
fwrite("Error al crear hilo emisor\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
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: struct thread_args { char *canal; char *nombre; } *

variable_types:
emith
unsigned long

variable_types:
recth
unsigned long

return_type: int


emisor

decompiled_code:
void __fastcall __noreturn emisor(void *a1)
{
int v1; // eax
int v2; // ebp
char *src; // [rsp+0h] [rbp-B8h] BYREF
size_t n; // [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, &n, _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; // ebp
char *src; // [rsp+0h] [rbp-B8h] BYREF
size_t n; // [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, &n, _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: 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; }

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


receptor

decompiled_code:
void *__fastcall receptor(void *a1)
{
int v1; // ebp
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, v3, 0x84uLL);
if ( v4 == 1 )
{
printf(aConexi, v3);
while ( (int)read(v1, buf, 0x84uLL) > 0 )
{
if ( v6 )
{
fwrite(&unk_4020C8, 1uLL, 0x26uLL, stderr);
close(v1);
exit(0);
}
printf("+%s dice: %s", v3, buf);
}
close(v1);
exit(0);
}
fwrite("FALLO DE PROTOCOLO\n", 1uLL, 0x13uLL, stderr);
return 0LL;
}

canonical_decompiled_code:
void *__fastcall func8(void *a1)
{
int v1; // ebp
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, v3, 0x84uLL);
if ( v4 == 1 )
{
printf(aConexi, v3);
while ( (int)read(v1, buf, 0x84uLL) > 0 )
{
if ( v6 )
{
fwrite(&unk_4020C8, 1uLL, 0x26uLL, stderr);
close(v1);
exit(0);
}
printf("+%s dice: %s", v3, buf);
}
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: enum tipo_mensaje { MENSAJE_NORMAL=0, MENSAJE_NOMBRE=1, MENSAJE_FIN=2 }


decompiled_code:
__int64 __fastcall reader_getFileType(char *s1)
{
unsigned int v1; // er12

v1 = 1;
if ( strcasecmp(s1, "netcdf") )
{
if ( strcasecmp(s1, "cdf") )
{
if ( strcasecmp(s1, "nc") )
{
v1 = 2;
if ( strcasecmp(s1, "hdf5") )
{
if ( strcasecmp(s1, "h5") )
{
v1 = 3;
if ( strcasecmp(s1, "adiosbp") )
{
if ( strcasecmp(s1, "bp") )
v1 = strcasecmp(s1, "adios") == 0 ? 3 : 0;
}
}
}
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1)
{
unsigned int v1; // er12

v1 = 1;
if ( strcasecmp(s1, "netcdf") )
{
if ( strcasecmp(s1, "cdf") )
{
if ( strcasecmp(s1, "nc") )
{
v1 = 2;
if ( strcasecmp(s1, "hdf5") )
{
if ( strcasecmp(s1, "h5") )
{
v1 = 3;
if ( strcasecmp(s1, "adiosbp") )
{
if ( strcasecmp(s1, "bp") )
v1 = strcasecmp(s1, "adios") == 0 ? 3 : 0;
}
}
}
}
}
}
return v1;
}

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);
if ( v2 )
result = reader_getFileType(v2 + 1);
else
result = 0LL;
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);
if ( v2 )
result = func0(v2 + 1);
else
result = 0LL;
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 *


original_code:
void reader_close(DataFile df) {
    int i;
    if (df.fd == -1 && df.fh == -1)
        return;
    switch (df.type) {
 case(adiosbp_file):
     readadiosbp_close(df);
     break;
 case(ascii_file):
     break;
 default:
     fprintf(stderr, "reader_close: unknown file type is given: %d\n", (int) df.type);
     exit(200);
     break;
    }
    for (i=0; i < df.nvars; i++) {
        if (df.varinfo[i].dispname != df.varinfo[i].name)
            if (df.varinfo[i].dispname) { free(df.varinfo[i].dispname); df.varinfo[i].dispname=((void *)0); };
 if (df.varinfo[i].name) { free(df.varinfo[i].name); df.varinfo[i].name=((void *)0); };
        df.varinfo[i].dispname = ((void *)0);
 if (df.varinfo[i].groupname) { free(df.varinfo[i].groupname); df.varinfo[i].groupname=((void *)0); };
    }
    if (df.varinfo) { free(df.varinfo); df.varinfo=((void *)0); };
    df.fd = -1;
    df.fh = -1;
}

canonical_original_code:
void reader_close(struct DataFile df) {
    int i;
    if (df.fd == -1 && df.fh == -1)
        return;
    switch (df.type) {
 case(adiosbp_file):
     readadiosbp_close(df);
     break;
 case(ascii_file):
     break;
 default:
     fprintf(stderr, "reader_close: unknown file type is given: %d\n", (int) df.type);
     exit(200);
     break;
    }
    for (i=0; i < df.nvars; i++) {
        if (df.varinfo[i].dispname != df.varinfo[i].name)
            if (df.varinfo[i].dispname) { free(df.varinfo[i].dispname); df.varinfo[i].dispname=((void *)0); };
 if (df.varinfo[i].name) { free(df.varinfo[i].name); df.varinfo[i].name=((void *)0); };
        df.varinfo[i].dispname = ((void *)0);
 if (df.varinfo[i].groupname) { free(df.varinfo[i].groupname); df.varinfo[i].groupname=((void *)0); };
    }
    if (df.varinfo) { free(df.varinfo); df.varinfo=((void *)0); };
    df.fd = -1;
    df.fh = -1;
}

variable_types: struct DataFile { enum FileType { undef_file=0, netcdf_file=1, hdf5_file=2, adiosbp_file=3, ascii_file=4 } type; int fd; long fh; int nvars; int ngroups; int time_start; int time_stop; struct VarInfo { char *name; char *dispname; enum ArrayType { undefArray=0, int8Array=1, int16Array=2, int32Array=3, int64Array=4, floatArray=5, doubleArray=6 } type; int varid; int ndims; int dimsize[5]; int timedim; char *groupname; } *varinfo; }

variable_types: i int

user_defined_types: struct DataFile { enum FileType type; int fd; long fh; int nvars; int ngroups; int time_start; int time_stop; struct VarInfo *varinfo; }

user_defined_types: struct VarInfo { char *name; char *dispname; enum ArrayType type; int varid; int ndims; int dimsize[5]; int timedim; char *groupname; }


original_code:
void print_DFinfo( DataFile df) {
    int i, j;
    printf("==============================\n");
    printf("DataFile: fd=%d", df.fd);
    printf(" type=%s", fileTypeStrings[df.type]);
    printf(" nvars=%d\n", df.nvars);
    for (i=0; i < df.nvars; i++) {
 printf("  var=%s  type=%d  varid=%d  ndims=%d (",
  df.varinfo[i].name, df.varinfo[i].type,
  df.varinfo[i].varid, df.varinfo[i].ndims);
 for (j=0; j < df.varinfo[i].ndims; j++)
     printf("%d ", df.varinfo[i].dimsize[j]);
 printf(")\n");
    }
    printf("==============================\n");
}

canonical_original_code:
void print_DFinfo(struct DataFile df) {
    int i; int j;
    printf("==============================\n");
    printf("DataFile: fd=%d", df.fd);
    printf(" type=%s", fileTypeStrings[df.type]);
    printf(" nvars=%d\n", df.nvars);
    for (i=0; i < df.nvars; i++) {
 printf("  var=%s  type=%d  varid=%d  ndims=%d (",
  df.varinfo[i].name, df.varinfo[i].type,
  df.varinfo[i].varid, df.varinfo[i].ndims);
 for (j=0; j < df.varinfo[i].ndims; j++)
     printf("%d ", df.varinfo[i].dimsize[j]);
 printf(")\n");
    }
    printf("==============================\n");
}

variable_types: j int

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

user_defined_types: enum ArrayType { undefArray=0, int8Array=1, int16Array=2, int32Array=3, int64Array=4, floatArray=5, doubleArray=6 }


getbasename

decompiled_code:
char *__fastcall getbasename(const char *a1, char **a2)
{
char *v2; // rbp
char *v3; // rax
char *v4; // rax
char *v5; // rbx
char *v6; // r12
char *result; // rax
char *v8; // r12

v2 = strdup(a1);
v3 = &v2[strlen(v2) - 1];
if ( *v3 == 47 )
*v3 = 48;
v4 = rindex(v2, 47);
v5 = v4;
if ( !v4 || v2 == v4 )
{
*a2 = 0LL;
v8 = strdup(v2);
free(v2);
result = v8;
}
else
{
*v4 = 0;
*a2 = strdup(v2);
*v5 = 47;
v6 = strdup(v5 + 1);
free(v2);
result = v6;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1, char **a2)
{
char *v2; // rbp
char *v3; // rax
char *v4; // rax
char *v5; // rbx
char *v6; // r12
char *result; // rax
char *v8; // r12

v2 = strdup(a1);
v3 = &v2[strlen(v2) - 1];
if ( *v3 == 47 )
*v3 = 48;
v4 = rindex(v2, 47);
v5 = v4;
if ( !v4 || v2 == v4 )
{
*a2 = 0LL;
v8 = strdup(v2);
free(v2);
result = v8;
}
else
{
*v4 = 0;
*a2 = strdup(v2);
*v5 = 47;
v6 = strdup(v5 + 1);
free(v2);
result = v6;
}
return result;
}

original_code:
char* getbasename( char *path, char **dirname )
{
    char *work, *base, *ptr;
    work = strdup(path);
    if (work[strlen(work)-1] == '/')
  work[strlen(work)-1] = '0';
    ptr = rindex(work, '/');
    if (ptr && ptr != work) {
       ptr[0] = 0;
       *dirname = strdup(work);
       ptr[0] = '/';
       base = strdup(ptr+1);
    }
    else {
 *dirname = ((void *)0);
 base =strdup(work);
    }
    free(work);
    return base;
}

canonical_original_code:
char *getbasename(char *path, char **dirname)
{
    char *work; char *base; char *ptr;
    work = strdup(path);
    if (work[strlen(work)-1] == '/')
  work[strlen(work)-1] = '0';
    ptr = rindex(work, '/');
    if (ptr && ptr != work) {
       ptr[0] = 0;
       *dirname = strdup(work);
       ptr[0] = '/';
       base = strdup(ptr+1);
    }
    else {
 *dirname = ((void *)0);
 base =strdup(work);
    }
    free(work);
    return base;
}

variable_types:
dirname
char **

variable_types:
work
char *

variable_types:
base
char *

variable_types:
ptr
char *

return_type: char *


decompiled_code:
bool __fastcall file_exists(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

canonical_decompiled_code:
bool __fastcall func1(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

return stat(a1, &v2) == 0;
}

original_code:
bool file_exists (char * path)
{
    struct stat sb;
    int i = stat ( path, &sb );
    if ( i == 0 )
 return 1;
    return 0;
}

canonical_original_code:
char file_exists(char *path)
{
    struct stat sb;
    int i = stat ( path, &sb );
    if ( i == 0 )
 return 1;
    return 0;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

return_type: char

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 __fastcall is_dir(const char *a1)
{
int v1; // er8
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode >> 14) & 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
int v1; // er8
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 0LL;
if ( !v1 )
result = (v3.st_mode >> 14) & 1;
return result;
}

original_code:
bool is_dir(char *path) {
     struct stat sb;
     if ( !stat( path, &sb) ) {
         if ( sb.st_mode & 0040000 ) {
             return 1;
         }
     }
     return 0;
}

canonical_original_code:
char is_dir(char *path) {
     struct stat sb;
     if ( !stat( path, &sb) ) {
         if ( sb.st_mode & 0040000 ) {
             return 1;
         }
     }
     return 0;
}

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


decompiled_code:
__int64 __fastcall createdir_recursive(const char *a1)
{
char *v2; // rbp
unsigned int v3; // er13
unsigned int v5; // er13
int v6; // edi
char *v7; // rax
char *v8; // rax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = getbasename(a1, (char **)&ptr);
if ( !ptr )
{
LABEL_4:
if ( !file_exists(a1) )
{
v3 = mkdir(a1, 0x1EDu);
if ( v3 )
{
v6 = *_errno_location();
if ( v6 != 17 )
{
v7 = strerror(v6);
fprintf(stderr, "createdir %s failed: %s\n", a1, v7);
goto LABEL_6;
}
v8 = strerror(17);
fprintf(stderr, "Concurrency error: createdir %s failed: %s\n", a1, v8);
fwrite("Some other process created this dir already during this function call\n", 1uLL, 0x46uLL, stderr);
}
}
v3 = 0;
LABEL_6:
free(v2);
return v3;
}
if ( (unsigned __int8)is_dir((const char *)ptr) )
{
free(ptr);
goto LABEL_4;
}
v5 = createdir_recursive(ptr);
free(ptr);
if ( !v5 )
goto LABEL_4;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
char *v2; // rbp
unsigned int v3; // er13
unsigned int v5; // er13
int v6; // edi
char *v7; // rax
char *v8; // rax
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v2 = func0(a1, (char **)&ptr);
if ( !ptr )
{
LABEL_4:
if ( !func1(a1) )
{
v3 = mkdir(a1, 0x1EDu);
if ( v3 )
{
v6 = *_errno_location();
if ( v6 != 17 )
{
v7 = strerror(v6);
fprintf(stderr, "createdir %s failed: %s\n", a1, v7);
goto LABEL_6;
}
v8 = strerror(17);
fprintf(stderr, "Concurrency error: createdir %s failed: %s\n", a1, v8);
fwrite("Some other process created this dir already during this function call\n", 1uLL, 0x46uLL, stderr);
}
}
v3 = 0;
LABEL_6:
free(v2);
return v3;
}
if ( (unsigned __int8)func2((const char *)ptr) )
{
free(ptr);
goto LABEL_4;
}
v5 = func3(ptr);
free(ptr);
if ( !v5 )
goto LABEL_4;
return v5;
}

original_code:
int createdir_recursive( char* path)
{
    int res;
    char *dirs, *base;
    base = getbasename(path, &dirs);
    if ( dirs != ((void *)0)) {
        if ( !is_dir(dirs) ) {
            res = createdir_recursive(dirs);
 } else res = 0;
        free(dirs);
        if (res) return res;
    }
    if (file_exists(path))
        res = 0;
    else
        res = mkdir(path, (0400|0200|0100) | (0400 >> 3) | (0100 >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3));
    if (res) {
        if ((*__errno_location ()) == 17) {
            fprintf(stderr, "Concurrency error: createdir %s failed: %s\n", path, strerror((*__errno_location ())));
            fprintf(stderr, "Some other process created this dir already during this function call\n");
            res = 0;
        } else {
            fprintf(stderr, "createdir %s failed: %s\n", path, strerror((*__errno_location ())));
        }
    }
    free(base);
    return (res);
}

canonical_original_code:
int createdir_recursive(char *path)
{
    int res;
    char *dirs; char *base;
    base = getbasename(path, &dirs);
    if ( dirs != ((void *)0)) {
        if ( !is_dir(dirs) ) {
            res = createdir_recursive(dirs);
 } else res = 0;
        free(dirs);
        if (res) return res;
    }
    if (file_exists(path))
        res = 0;
    else
        res = mkdir(path, (0400|0200|0100) | (0400 >> 3) | (0100 >> 3) | ((0400 >> 3) >> 3) | ((0100 >> 3) >> 3));
    if (res) {
        if ((*__errno_location ()) == 17) {
            fprintf(stderr, "Concurrency error: createdir %s failed: %s\n", path, strerror((*__errno_location ())));
            fprintf(stderr, "Some other process created this dir already during this function call\n");
            res = 0;
        } else {
            fprintf(stderr, "createdir %s failed: %s\n", path, strerror((*__errno_location ())));
        }
    }
    free(base);
    return (res);
}

variable_types: res int

variable_types:
dirs
char *


decompiled_code:
void *init_gtable()
{
void *result; // rax

result = memset(&gtable, 0, 0x5DC0uLL);
elemnum = 0;
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

result = memset(&gtable, 0, 0x5DC0uLL);
elemnum = 0;
return result;
}

original_code:
static void init_gtable(void)
{
  memset(gtable, 0, 1000*sizeof(gelem));
  elemnum=0;
}

canonical_original_code:
static void init_gtable()
{
  memset(gtable, 0, 1000*sizeof(gelem));
  elemnum=0;
}


decompiled_code:
__int64 __fastcall gtable_get(char *s1)
{
int v1; // er13
const char **v2; // rbx
unsigned int v3; // er12

v1 = elemnum;
if ( elemnum <= 0 )
return (unsigned int)-(elemnum == 0);
v2 = (const char **)&gtable;
v3 = 0;
do
{
if ( !strcmp(s1, *v2) )
return v3;
++v3;
v2 += 3;
}
while ( v1 != v3 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
int v1; // er13
const char **v2; // rbx
unsigned int v3; // er12

v1 = elemnum;
if ( elemnum <= 0 )
return (unsigned int)-(elemnum == 0);
v2 = (const char **)&gtable;
v3 = 0;
do
{
if ( !strcmp(s1, *v2) )
return v3;
++v3;
v2 += 3;
}
while ( v1 != v3 );
return 0xFFFFFFFFLL;
}

original_code:
static int gtable_get(char * name) {
    int i;
    for (i = 0; i < elemnum; i++) {
 if (!strcmp(name, gtable[i].name)) break;
    }
    if (i == elemnum) {
 i = -1;
    }
    return i;
}

canonical_original_code:
static int gtable_get(char *name) {
    int i;
    for (i = 0; i < elemnum; i++) {
 if (!strcmp(name, gtable[i].name)) break;
    }
    if (i == elemnum) {
 i = -1;
    }
    return i;
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall minmax_open(char *src, char a2)
{
__int64 result; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( src )
strncpy(v7, src, 0x400uLL);
else
strcpy(v7, "minmax1D.dat");
if ( a2 )
{
fminmax = fopen(v7, "r");
if ( fminmax )
{
LABEL_5:
init_gtable();
return 1LL;
}
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Error at opening for reading minmax file %s: %s\n", v7, v6);
result = 0LL;
}
else
{
fminmax = fopen(v7, "a+");
if ( fminmax )
goto LABEL_5;
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Error at opening for writing minmax file %s: %s\n", v7, v4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src, char a2)
{
__int64 result; // rax
int *v3; // rax
char *v4; // rax
int *v5; // rax
char *v6; // rax
char v7[1048]; // [rsp+0h] [rbp-418h] BYREF

if ( src )
strncpy(v7, src, 0x400uLL);
else
strcpy(v7, "minmax1D.dat");
if ( a2 )
{
fminmax = fopen(v7, "r");
if ( fminmax )
{
LABEL_5:
func0();
return 1LL;
}
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Error at opening for reading minmax file %s: %s\n", v7, v6);
result = 0LL;
}
else
{
fminmax = fopen(v7, "a+");
if ( fminmax )
goto LABEL_5;
v3 = _errno_location();
v4 = strerror(*v3);
fprintf(stderr, "Error at opening for writing minmax file %s: %s\n", v7, v4);
result = 0LL;
}
return result;
}

original_code:
bool minmax_open( char *path, bool readmode) {
    char fn[1024];
    if ( path != ((void *)0))
 strncpy(fn, path, 1024);
    else
 snprintf(fn, 1024, "minmax1D.dat");
    if ( readmode ) {
 if ((fminmax = fopen(fn,"r")) == ((void *)0)) {
     fprintf(stderr, "Error at opening for reading minmax file %s: %s\n",
      fn, strerror((*__errno_location ())));
     return 0;
 }
    } else {
 if ((fminmax = fopen(fn,"a+")) == ((void *)0)) {
     fprintf(stderr, "Error at opening for writing minmax file %s: %s\n",
      fn, strerror((*__errno_location ())));
     return 0;
 }
    }
    init_gtable();
    return 1;
}

canonical_original_code:
char minmax_open(char *path, char readmode) {
    char fn[1024];
    if ( path != ((void *)0))
 strncpy(fn, path, 1024);
    else
 snprintf(fn, 1024, "minmax1D.dat");
    if ( readmode ) {
 if ((fminmax = fopen(fn,"r")) == ((void *)0)) {
     fprintf(stderr, "Error at opening for reading minmax file %s: %s\n",
      fn, strerror((*__errno_location ())));
     return 0;
 }
    } else {
 if ((fminmax = fopen(fn,"a+")) == ((void *)0)) {
     fprintf(stderr, "Error at opening for writing minmax file %s: %s\n",
      fn, strerror((*__errno_location ())));
     return 0;
 }
    }
    init_gtable();
    return 1;
}

variable_types: readmode char

variable_types:
fn
char [1024]


decompiled_code:
int minmax_close()
{
int result; // eax

if ( fminmax )
result = fclose(fminmax);
return result;
}

canonical_decompiled_code:
int func5()
{
int result; // eax

if ( fminmax )
result = fclose(fminmax);
return result;
}

original_code:
void minmax_close() {
    if (fminmax)
 fclose(fminmax);
}


decompiled_code:
int __fastcall minmax_print(const char *a1, unsigned int a2, double a3, double a4)
{
int result; // eax

if ( fminmax )
result = fprintf(fminmax, "%s;%4.4d;%.12g;%.12g\n", a1, a2, a3, a4);
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1, unsigned int a2, double a3, double a4)
{
int result; // eax

if ( fminmax )
result = fprintf(fminmax, "%s;%4.4d;%.12g;%.12g\n", a1, a2, a3, a4);
return result;
}

original_code:
void minmax_print(char* varname, int time, double min, double max) {
    if (fminmax)
 fprintf(fminmax, "%s;%4.4d;%.12g;%.12g\n", varname, time, min, max);
}

canonical_original_code:
void minmax_print(char *varname, int time, double min, double max) {
    if (fminmax)
 fprintf(fminmax, "%s;%4.4d;%.12g;%.12g\n", varname, time, min, max);
}

variable_types:
varname
char *

variable_types: time int

variable_types: min double

variable_types: max double


decompiled_code:
int __fastcall minmax_get(char *s1, double *a2, double *a3, double a4)
{
int v5; // eax
double v6; // xmm1_8
__int64 *v7; // rax
double v8; // rax
double v10; // [rsp+0h] [rbp-430h] BYREF
char s[1064]; // [rsp+8h] [rbp-428h] BYREF

sprintf(s, "%.12g", a4);
_isoc99_sscanf(s, "%lg", &v10);
if ( elemnum )
{
v5 = gtable_get(s1);
if ( v5 >= 0 )
goto LABEL_3;
LABEL_9:
LODWORD(v8) = fprintf(stderr, "Error: minmax_get: variable %s not found in minmax data\n", s1);
*a2 = a4;
LABEL_6:
*a3 = a4;
return LODWORD(v8);
}
read_minmax(v10);
v5 = gtable_get(s1);
if ( v5 < 0 )
goto LABEL_9;
LABEL_3:
v6 = v10;
v7 = &gtable[3 * v5];
*(_QWORD *)a2 = v7[1];
*(_QWORD *)a3 = v7[2];
v8 = *a2;
if ( *a2 == v6 )
v8 = a4;
*a2 = v8;
if ( v6 == *a3 )
goto LABEL_6;
return LODWORD(v8);
}

canonical_decompiled_code:
int __fastcall func7(char *s1, double *a2, double *a3, double a4)
{
int v5; // eax
double v6; // xmm1_8
__int64 *v7; // rax
double v8; // rax
double v10; // [rsp+0h] [rbp-430h] BYREF
char s[1064]; // [rsp+8h] [rbp-428h] BYREF

sprintf(s, "%.12g", a4);
_isoc99_sscanf(s, "%lg", &v10);
if ( elemnum )
{
v5 = func1(s1);
if ( v5 >= 0 )
goto LABEL_3;
LABEL_9:
LODWORD(v8) = fprintf(stderr, "Error: minmax_get: variable %s not found in minmax data\n", s1);
*a2 = a4;
LABEL_6:
*a3 = a4;
return LODWORD(v8);
}
func3(v10);
v5 = func1(s1);
if ( v5 < 0 )
goto LABEL_9;
LABEL_3:
v6 = v10;
v7 = &gtable[3 * v5];
*(_QWORD *)a2 = v7[1];
*(_QWORD *)a3 = v7[2];
v8 = *a2;
if ( *a2 == v6 )
v8 = a4;
*a2 = v8;
if ( v6 == *a3 )
goto LABEL_6;
return LODWORD(v8);
}

original_code:
void minmax_get(char* varname, double undef_value, double *gmin, double *gmax) {
    int n;
    char line[1024];
    double undef;
    sprintf(line, "%.12g", undef_value);
    sscanf(line, "%lg", &undef);
    if (elemnum == 0) {
 read_minmax(undef);
    }
    n = gtable_get(varname);
    if (n > -1) {
 *gmin = gtable[n].gmin;
 *gmax = gtable[n].gmax;
 if (*gmin == undef) *gmin = undef_value;
 if (*gmax == undef) *gmax = undef_value;
    } else {
 fprintf(stderr, "Error: minmax_get: variable %s not found in minmax data\n", varname);
        *gmin = undef_value;
 *gmax = undef_value;
    }
}

canonical_original_code:
void minmax_get(char *varname, double undef_value, double *gmin, double *gmax) {
    int n;
    char line[1024];
    double undef;
    sprintf(line, "%.12g", undef_value);
    sscanf(line, "%lg", &undef);
    if (elemnum == 0) {
 read_minmax(undef);
    }
    n = gtable_get(varname);
    if (n > -1) {
 *gmin = gtable[n].gmin;
 *gmax = gtable[n].gmax;
 if (*gmin == undef) *gmin = undef_value;
 if (*gmax == undef) *gmax = undef_value;
    } else {
 fprintf(stderr, "Error: minmax_get: variable %s not found in minmax data\n", varname);
        *gmin = undef_value;
 *gmax = undef_value;
    }
}

variable_types:
gmin
double *

variable_types:
gmax
double *

variable_types: n int

variable_types:
line
char [1024]

variable_types: undef double