decompiled_code:
__int64 __fastcall weapon_HUD_ARM(double *a1, int a2, double a3)
{
int v3; // eax
int v4; // eax
double v5; // r12
double v6; // r14
double v7; // r15
int v8; // eax
double v9; // xmm0_8
double v11; // xmm2_8
double v12; // [rsp+10h] [rbp-40h]
double v13; // [rsp+18h] [rbp-38h]
double v14; // [rsp+20h] [rbp-30h]
double v15; // [rsp+20h] [rbp-30h]
double v16; // [rsp+20h] [rbp-30h]
double v17; // [rsp+28h] [rbp-28h]

v17 = a3 + a1[25];
v3 = SDL_GetTicks();
v14 = sin((double)v3 * 0.001);
v4 = SDL_GetTicks();
v13 = 0.5 * v14 + sin((double)v4 * 0.00085) * 0.5;
glPushMatrix();
v15 = *(double *)&fake_theta + *(double *)(*(_QWORD *)a1 + 8LL);
glRotated((*(double *)(*(_QWORD *)a1 + 24LL) + *(double *)&fake_rho) * -4.0, 1.0, 0.0);
glRotated(0.5 * v15, 0.0, 1.0);
v12 = *(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation;
glTranslated(
0.0,
0.0,
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation) ^ LC22)
* (*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation)
* 0.0007);
glTranslated(5.0, 0.0, -3.0);
glTranslated(v15 * 0.05, 0.0, 0.0);
glRotated(80.0, 0.0, 1.0);
glRotated(70.0, 1.0, 0.0);
glRotated(v15, 0.0, 0.0);
glRotated(v12, 0.0, 1.0);
glTranslated(0.0, 0.0, -1.0);
glLineWidth(3.0);
glPushMatrix();
v16 = v17 + v17;
v5 = 1.5 * v17;
glTranslated(0.0, 1.5 * v17, v17 + v17);
v6 = v17 * -65.0;
glRotated(v17 * -65.0, 0.0, 1.0);
v7 = v17 * -15.0;
glRotated(v17 * -15.0, 0.0, 0.0);
glRotated(v17 * 30.0 + 60.0, 0.0, 1.0);
glRotated(v17 * 30.0 + 60.0, 1.0, 0.0);
v8 = SDL_GetTicks();
v9 = sin((double)v8 * 0.0017);
glTranslated(v9 * 0.1 * (1.0 - v17) - 0.3 - 0.7 * v17, 1.0 - 0.8 * v17, v13 * (1.0 - v17) - 5.0 + v17 + v17);
glScaled(1.0, 1.0, 0.2 * v17 + 1.0);
draw_arrow_high_quality();
if ( !a2 )
{
glClear(256LL);
glPopMatrix();
glTranslated(0.0, v5, v16);
glRotated(v6, 0.0, 1.0);
glRotated(v7, 0.0, 0.0);
if ( v17 != 0.0 )
{
draw_hand(1LL, 0.3 * v17, v16, 0.0, 1.0);
LABEL_4:
draw_bow(0.2, v17 * 0.6 + 0.2);
return glPopMatrix();
}
draw_hand(0LL, 0.1 * v13 + 0.3, 0.0, 0.1 * v13, 1.0);
v11 = 0.1 * v13;
goto LABEL_7;
}
glPushMatrix();
glTranslated(-1.7, 0.0, 1.5);
glRotated(10.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glPushMatrix();
glTranslated(1.7, 0.0, 0.75);
glRotated(-10.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
if ( a2 != 2 )
{
glClear(256LL);
glPopMatrix();
glTranslated(0.0, v5, v16);
glRotated(v6, 0.0, 1.0);
glRotated(v7, 0.0, 0.0);
if ( v17 != 0.0 )
{
draw_hand(1LL, 0.3 * v17, v16, 0.0, 1.0);
if ( a2 == 1 )
{
draw_bow_v2(0.2, v17 * 0.6 + 0.2);
return glPopMatrix();
}
goto LABEL_4;
}
draw_hand(0LL, 0.1 * v13 + 0.3, 0.0, 0.1 * v13, 1.0);
v11 = 0.1 * v13;
if ( a2 == 1 )
{
draw_bow_v2(0.2, 0.1 * v13 + 0.2);
return glPopMatrix();
}
LABEL_7:
draw_bow(0.2, v11 + 0.2);
return glPopMatrix();
}
glPushMatrix();
glTranslated(-3.2, 0.0, 3.0);
glRotated(20.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glPushMatrix();
glTranslated(3.2, 0.0, 1.5);
glRotated(-20.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glClear(256LL);
glPopMatrix();
glTranslated(0.0, v5, v16);
glRotated(v6, 0.0, 1.0);
glRotated(v7, 0.0, 0.0);
if ( v17 == 0.0 )
{
draw_hand(0LL, 0.1 * v13 + 0.3, 0.0, 0.1 * v13, 1.0);
draw_bow_v3(0.2, 0.1 * v13 + 0.2);
}
else
{
draw_hand(1LL, 0.3 * v17, v16, 0.0, 1.0);
draw_bow_v3(0.2, v17 * 0.6 + 0.2);
}
return glPopMatrix();
}

canonical_decompiled_code:
__int64 __fastcall func3(double *a1, int a2, double a3)
{
int v3; // eax
int v4; // eax
double v5; // r12
double v6; // r14
double v7; // r15
int v8; // eax
double v9; // xmm0_8
double v11; // xmm2_8
double v12; // [rsp+10h] [rbp-40h]
double v13; // [rsp+18h] [rbp-38h]
double v14; // [rsp+20h] [rbp-30h]
double v15; // [rsp+20h] [rbp-30h]
double v16; // [rsp+20h] [rbp-30h]
double v17; // [rsp+28h] [rbp-28h]

v17 = a3 + a1[25];
v3 = SDL_GetTicks();
v14 = sin((double)v3 * 0.001);
v4 = SDL_GetTicks();
v13 = 0.5 * v14 + sin((double)v4 * 0.00085) * 0.5;
glPushMatrix();
v15 = *(double *)&fake_theta + *(double *)(*(_QWORD *)a1 + 8LL);
glRotated((*(double *)(*(_QWORD *)a1 + 24LL) + *(double *)&fake_rho) * -4.0, 1.0, 0.0);
glRotated(0.5 * v15, 0.0, 1.0);
v12 = *(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation;
glTranslated(
0.0,
0.0,
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation) ^ LC22)
* (*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation)
* 0.0007);
glTranslated(5.0, 0.0, -3.0);
glTranslated(v15 * 0.05, 0.0, 0.0);
glRotated(80.0, 0.0, 1.0);
glRotated(70.0, 1.0, 0.0);
glRotated(v15, 0.0, 0.0);
glRotated(v12, 0.0, 1.0);
glTranslated(0.0, 0.0, -1.0);
glLineWidth(3.0);
glPushMatrix();
v16 = v17 + v17;
v5 = 1.5 * v17;
glTranslated(0.0, 1.5 * v17, v17 + v17);
v6 = v17 * -65.0;
glRotated(v17 * -65.0, 0.0, 1.0);
v7 = v17 * -15.0;
glRotated(v17 * -15.0, 0.0, 0.0);
glRotated(v17 * 30.0 + 60.0, 0.0, 1.0);
glRotated(v17 * 30.0 + 60.0, 1.0, 0.0);
v8 = SDL_GetTicks();
v9 = sin((double)v8 * 0.0017);
glTranslated(v9 * 0.1 * (1.0 - v17) - 0.3 - 0.7 * v17, 1.0 - 0.8 * v17, v13 * (1.0 - v17) - 5.0 + v17 + v17);
glScaled(1.0, 1.0, 0.2 * v17 + 1.0);
draw_arrow_high_quality();
if ( !a2 )
{
glClear(256LL);
glPopMatrix();
glTranslated(0.0, v5, v16);
glRotated(v6, 0.0, 1.0);
glRotated(v7, 0.0, 0.0);
if ( v17 != 0.0 )
{
draw_hand(1LL, 0.3 * v17, v16, 0.0, 1.0);
LABEL_4:
draw_bow(0.2, v17 * 0.6 + 0.2);
return glPopMatrix();
}
draw_hand(0LL, 0.1 * v13 + 0.3, 0.0, 0.1 * v13, 1.0);
v11 = 0.1 * v13;
goto LABEL_7;
}
glPushMatrix();
glTranslated(-1.7, 0.0, 1.5);
glRotated(10.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glPushMatrix();
glTranslated(1.7, 0.0, 0.75);
glRotated(-10.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
if ( a2 != 2 )
{
glClear(256LL);
glPopMatrix();
glTranslated(0.0, v5, v16);
glRotated(v6, 0.0, 1.0);
glRotated(v7, 0.0, 0.0);
if ( v17 != 0.0 )
{
draw_hand(1LL, 0.3 * v17, v16, 0.0, 1.0);
if ( a2 == 1 )
{
draw_bow_v2(0.2, v17 * 0.6 + 0.2);
return glPopMatrix();
}
goto LABEL_4;
}
draw_hand(0LL, 0.1 * v13 + 0.3, 0.0, 0.1 * v13, 1.0);
v11 = 0.1 * v13;
if ( a2 == 1 )
{
draw_bow_v2(0.2, 0.1 * v13 + 0.2);
return glPopMatrix();
}
LABEL_7:
draw_bow(0.2, v11 + 0.2);
return glPopMatrix();
}
glPushMatrix();
glTranslated(-3.2, 0.0, 3.0);
glRotated(20.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glPushMatrix();
glTranslated(3.2, 0.0, 1.5);
glRotated(-20.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glClear(256LL);
glPopMatrix();
glTranslated(0.0, v5, v16);
glRotated(v6, 0.0, 1.0);
glRotated(v7, 0.0, 0.0);
if ( v17 == 0.0 )
{
draw_hand(0LL, 0.1 * v13 + 0.3, 0.0, 0.1 * v13, 1.0);
draw_bow_v3(0.2, 0.1 * v13 + 0.2);
}
else
{
draw_hand(1LL, 0.3 * v17, v16, 0.0, 1.0);
draw_bow_v3(0.2, v17 * 0.6 + 0.2);
}
return glPopMatrix();
}

original_code:
void weapon_HUD_ARM(Game* game,int mode,double time_offset){
 double time_pos=game->trigger_value+time_offset;
 double oscill_force=.5*sin(SDL_GetTicks()*.001)+.5*sin(SDL_GetTicks()*.00085);
 glPushMatrix();
 double real_rho=game->player->rho +fake_rho; double real_theta=game->player->theta+fake_theta; glRotated(real_rho*(-4),1,0,0); glRotated(real_theta*.5, 0.0, 1.0, 0.0); double real_HUD_drho_compensation=HUD_drho_compensation+fake_HUD_drho_compensation; glTranslated(0,0,-real_HUD_drho_compensation*real_HUD_drho_compensation*0.0007); glTranslated(5,0,-3); glTranslated(real_theta*(.05),0,0); glRotated(80, 0, 1, 0); glRotated(70, 1, 0, 0); glRotated(real_theta*(1),0,0,1); glRotated(real_HUD_drho_compensation,0,1,0); glTranslated(0,0,-1); glLineWidth(3.0);
   glPushMatrix();
    glTranslated(0, 1.5*time_pos, 2*time_pos); glRotated(-130*.5*time_pos, 0, 1, 0); glRotated(-30*.5*time_pos, 0, 0, 1);;
    glRotated(60+30*time_pos, 0, 1, 0);
    glRotated(60+30*time_pos, 1, 0, 0);
    glTranslated(
     -.3+.1*sin(SDL_GetTicks()*.0017)*(1-time_pos)-.7*time_pos,
     1-.8*time_pos,
     -5+1*oscill_force*(1-time_pos)+2*time_pos
     );
    glScaled(1,1,1+.2*time_pos);
    draw_arrow_high_quality();
    if(mode){
     glPushMatrix();
      glTranslated(-1.7,0,1.5);
      glRotated(10,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
     glPushMatrix();
      glTranslated(1.7,0,0.75);
      glRotated(-10,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
    }if(mode==2){
     glPushMatrix();
      glTranslated(-3.2,0,3);
      glRotated(20,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
     glPushMatrix();
      glTranslated(3.2,0,1.5);
      glRotated(-20,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
    }
    glClear(0x00000100);
   glPopMatrix();
   glTranslated(0, 1.5*time_pos, 2*time_pos); glRotated(-130*.5*time_pos, 0, 1, 0); glRotated(-30*.5*time_pos, 0, 0, 1);;
   if(time_pos){
    draw_hand(.3*time_pos,2*time_pos,1);
    if(mode==2){
     draw_bow_v3(.2,.2+.6*time_pos);
    }else if(mode==1){
     draw_bow_v2(.2,.2+.6*time_pos);
    }else{
     draw_bow(.2,.2+.6*time_pos);
    }
   }else{
    draw_hand( .3+.1*oscill_force,0,0);
    if(mode==2){
     draw_bow_v3(.2,.2+.1*oscill_force);
    }else if(mode==1){
     draw_bow_v2(.2,.2+.1*oscill_force);
    }else{
     draw_bow(.2,.2+.1*oscill_force);
    }
   }
 glPopMatrix();
}

canonical_original_code:
void weapon_HUD_ARM(struct Game *game, int mode, double time_offset){
 double time_pos = game->trigger_value+time_offset;
 double oscill_force = .5*sin(SDL_GetTicks()*.001)+.5*sin(SDL_GetTicks()*.00085);
 glPushMatrix();
 double real_rho = game->player->rho +fake_rho; double real_theta = game->player->theta+fake_theta; glRotated(real_rho*(-4),1,0,0); glRotated(real_theta*.5, 0.0, 1.0, 0.0); double real_HUD_drho_compensation = HUD_drho_compensation+fake_HUD_drho_compensation; glTranslated(0,0,-real_HUD_drho_compensation*real_HUD_drho_compensation*0.0007); glTranslated(5,0,-3); glTranslated(real_theta*(.05),0,0); glRotated(80, 0, 1, 0); glRotated(70, 1, 0, 0); glRotated(real_theta*(1),0,0,1); glRotated(real_HUD_drho_compensation,0,1,0); glTranslated(0,0,-1); glLineWidth(3.0);
   glPushMatrix();
    glTranslated(0, 1.5*time_pos, 2*time_pos); glRotated(-130*.5*time_pos, 0, 1, 0); glRotated(-30*.5*time_pos, 0, 0, 1);;
    glRotated(60+30*time_pos, 0, 1, 0);
    glRotated(60+30*time_pos, 1, 0, 0);
    glTranslated(
     -.3+.1*sin(SDL_GetTicks()*.0017)*(1-time_pos)-.7*time_pos,
     1-.8*time_pos,
     -5+1*oscill_force*(1-time_pos)+2*time_pos
     );
    glScaled(1,1,1+.2*time_pos);
    draw_arrow_high_quality();
    if(mode){
     glPushMatrix();
      glTranslated(-1.7,0,1.5);
      glRotated(10,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
     glPushMatrix();
      glTranslated(1.7,0,0.75);
      glRotated(-10,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
    }if(mode==2){
     glPushMatrix();
      glTranslated(-3.2,0,3);
      glRotated(20,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
     glPushMatrix();
      glTranslated(3.2,0,1.5);
      glRotated(-20,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
    }
    glClear(0x00000100);
   glPopMatrix();
   glTranslated(0, 1.5*time_pos, 2*time_pos); glRotated(-130*.5*time_pos, 0, 1, 0); glRotated(-30*.5*time_pos, 0, 0, 1);;
   if(time_pos){
    draw_hand(.3*time_pos,2*time_pos,1);
    if(mode==2){
     draw_bow_v3(.2,.2+.6*time_pos);
    }else if(mode==1){
     draw_bow_v2(.2,.2+.6*time_pos);
    }else{
     draw_bow(.2,.2+.6*time_pos);
    }
   }else{
    draw_hand( .3+.1*oscill_force,0,0);
    if(mode==2){
     draw_bow_v3(.2,.2+.1*oscill_force);
    }else if(mode==1){
     draw_bow_v2(.2,.2+.1*oscill_force);
    }else{
     draw_bow(.2,.2+.1*oscill_force);
    }
   }
 glPopMatrix();
}

variable_types: mode int

user_defined_types: struct AudioPlayer { struct SoundSample *s1; char *next_file_path; char *now_playing; double time_buffer_offset; unsigned int source_id; unsigned int buffer_id[2]; unsigned int sound_buffer; }

user_defined_types: struct vorbis_block { float **pcm; struct oggpack_buffer opb; long lW; long W; long nW; int pcmend; int mode; int eofflag; long granulepos; long sequence; struct vorbis_dsp_state *vd; void *localstore; long localtop; long localalloc; long totaluse; struct alloc_chain *reap; long glue_bits; long time_bits; long floor_bits; long res_bits; void *internal; }


decompiled_code:
__int64 __fastcall weapon_HUD_FIRE(double *a1, int a2, double a3)
{
double v3; // xmm1_8
__int64 v4; // xmm4_8
double v5; // xmm1_8
double v6; // xmm0_8
double v8; // xmm2_8
double v9; // xmm1_8
int v10; // eax
double v11; // r12
int v12; // eax
int v13; // eax
double v14; // xmm0_8
double v15; // xmm4_8
double v16; // xmm2_8
double v17; // [rsp+8h] [rbp-28h]
double v18; // [rsp+10h] [rbp-20h]
double v19; // [rsp+18h] [rbp-18h]
double v20; // [rsp+18h] [rbp-18h]
double v21; // [rsp+18h] [rbp-18h]
double v22; // [rsp+18h] [rbp-18h]
double v23; // [rsp+18h] [rbp-18h]
double v24; // [rsp+18h] [rbp-18h]
double v25; // [rsp+18h] [rbp-18h]

((void (*)(void))glPushMatrix)();
v19 = *(double *)&fake_theta + *(double *)(*(_QWORD *)a1 + 8LL);
glRotated((*(double *)(*(_QWORD *)a1 + 24LL) + *(double *)&fake_rho) * -4.0, 1.0, 0.0);
glRotated(0.5 * v19, 0.0, 1.0);
v17 = *(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation;
glTranslated(
0.0,
0.0,
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation) ^ LC22)
* (*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation)
* 0.0007);
glTranslated(5.0, 0.0, -3.0);
glTranslated(v19 * 0.05, 0.0, 0.0);
glRotated(80.0, 0.0, 1.0);
glRotated(70.0, 1.0, 0.0);
glRotated(v19, 0.0, 0.0);
glRotated(v17, 0.0, 1.0);
glTranslated(0.0, 0.0, -1.0);
glLineWidth(3.0);
v3 = 1.0 - a1[23] + a3;
if ( v3 < 0.1 )
{
v22 = (exp(1.0 - v3 / 0.1) - 1.0) / 1.718281828459045;
glTranslated(v22, v22 + 0.5, 2.5);
glRotated(-65.0, 0.0, 1.0);
glRotated(-15.0, 0.0, 0.0);
glRotated(10.0, 0.0, 1.0);
((void (*)(void))glPushMatrix)();
glRotated(90.0, 0.0, 1.0);
glRotated(90.0, 1.0, 0.0);
glRotated(3.0, 1.0, 0.0);
glTranslated(0.0, 0.3, 5.0 * v22 - 8.0);
*(_QWORD *)&v8 = COERCE_UNSIGNED_INT64(1.0 - v22) ^ LC22;
glTranslated(0.0, 0.0, v8);
draw_arrow_high_quality();
glPopMatrix();
v9 = 4.0 - (v22 + v22);
v23 = 0.5 * v22;
draw_hand(1LL, v23, v9, v8, 0.0);
v5 = v23;
v6 = *(double *)&LC7;
if ( a2 != 2 )
{
if ( a2 != 1 )
goto LABEL_6;
LABEL_13:
draw_bow_v2(v6, v5);
return glPopMatrix();
}
LABEL_10:
draw_bow_v3(v6, v5);
return glPopMatrix();
}
if ( v3 < 0.3 )
{
v21 = (v3 - 0.1) / 0.2;
glTranslated(0.0, 0.5, 2.5);
glRotated(-65.0, 0.0, 1.0);
glRotated(-15.0, 0.0, 0.0);
glRotated(10.0, 0.0, 1.0);
glRotated(v21 * -40.0, 1.0, 0.0);
glTranslated(0.0, 0.0, -3.0 * v21);
draw_hand(1LL, 0.0, 4.0, -3.0 * v21, 0.0);
v4 = LC7;
if ( a2 != 2 )
goto LABEL_5;
goto LABEL_9;
}
if ( v3 >= 0.6 )
{
v24 = 1.0 - a1[23] + a3;
v10 = SDL_GetTicks();
v11 = sin((double)v10 * 0.001);
v12 = SDL_GetTicks();
v25 = 1.0 - (v24 - 0.6) / 0.4;
v18 = v11 * 0.5 + sin((double)v12 * 0.00085) * 0.5;
glTranslated(v25 + v25, 0.0, 0.0);
glRotated(v25 * 30.0, 0.0, 1.0);
glRotated(0.0, 0.0, 0.0);
glPushMatrix(0.0, 0.0, 0.0, 1.0);
glRotated(60.0, 0.0, 1.0);
glRotated(60.0, 1.0, 0.0);
v13 = SDL_GetTicks();
v14 = sin((double)v13 * 0.0017);
glTranslated(v14 * 0.1 - 0.3, 1.0, v18 - 5.0);
glTranslated(5.0 * v25, 5.0 * v25, 0.0);
glTranslated(-10.0 * v25, 0.0, 0.0);
glRotated(v25 * -40.0, 1.0, 0.0);
glTranslated(10.0 * v25, 0.0, 0.0);
glTranslated(0.0, v25 + v25, v25 + v25);
glTranslated(-3.0 * v25, 0.0, 0.0);
draw_arrow_high_quality();
if ( a2 )
{
glPushMatrix(-3.0 * v25, 0.0, 0.0, 0.0);
glTranslated(-1.3, 0.0, 1.7);
glRotated(10.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glPushMatrix(10.0, 0.0, 1.0, 0.0);
glTranslated(1.3, 0.0, 1.0);
glRotated(-10.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glPopMatrix();
draw_hand(0LL, 0.1 * v18 + 0.3, 0.0, 0.1 * v18, 0.0);
v16 = 0.1 * v18;
if ( a2 == 2 )
{
draw_bow_v3(0.2, 0.1 * v18 + 0.2);
return glPopMatrix();
}
v15 = *(double *)&LC7;
v5 = v16 + 0.2;
if ( a2 == 1 )
{
v6 = *(double *)&LC7;
goto LABEL_13;
}
}
else
{
glPopMatrix();
draw_hand(0LL, 0.1 * v18 + 0.3, 0.0, 0.1 * v18, 0.0);
v15 = *(double *)&LC7;
v16 = 0.1 * v18;
}
v6 = v15;
v5 = v16 + v15;
goto LABEL_6;
}
v20 = (v3 - 0.3) / 0.3;
glTranslated(0.0, 0.5, 2.5);
glRotated(-65.0, 0.0, 1.0);
glRotated(-15.0, 0.0, 0.0);
glRotated(10.0, 0.0, 1.0);
glRotated(-40.0, 1.0, 0.0);
glTranslated(0.0, 0.0, -3.0 * v20);
glRotated(v20 * 20.0, 0.0, 1.0);
glRotated(v20 * 20.0, 1.0, 1.0);
glTranslated(0.0, 0.0, -3.0);
draw_hand(1LL, 0.0, 4.0 - (v20 + v20), -3.0, 0.0);
v4 = LC7;
if ( a2 == 2 )
{
LABEL_9:
v5 = 0.0;
v6 = *(double *)&v4;
goto LABEL_10;
}
LABEL_5:
v5 = 0.0;
v6 = *(double *)&v4;
if ( a2 == 1 )
goto LABEL_13;
LABEL_6:
draw_bow(v6, v5);
return glPopMatrix();
}

canonical_decompiled_code:
__int64 __fastcall func4(double *a1, int a2, double a3)
{
double v3; // xmm1_8
__int64 v4; // xmm4_8
double v5; // xmm1_8
double v6; // xmm0_8
double v8; // xmm2_8
double v9; // xmm1_8
int v10; // eax
double v11; // r12
int v12; // eax
int v13; // eax
double v14; // xmm0_8
double v15; // xmm4_8
double v16; // xmm2_8
double v17; // [rsp+8h] [rbp-28h]
double v18; // [rsp+10h] [rbp-20h]
double v19; // [rsp+18h] [rbp-18h]
double v20; // [rsp+18h] [rbp-18h]
double v21; // [rsp+18h] [rbp-18h]
double v22; // [rsp+18h] [rbp-18h]
double v23; // [rsp+18h] [rbp-18h]
double v24; // [rsp+18h] [rbp-18h]
double v25; // [rsp+18h] [rbp-18h]

((void (*)(void))glPushMatrix)();
v19 = *(double *)&fake_theta + *(double *)(*(_QWORD *)a1 + 8LL);
glRotated((*(double *)(*(_QWORD *)a1 + 24LL) + *(double *)&fake_rho) * -4.0, 1.0, 0.0);
glRotated(0.5 * v19, 0.0, 1.0);
v17 = *(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation;
glTranslated(
0.0,
0.0,
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation) ^ LC22)
* (*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation)
* 0.0007);
glTranslated(5.0, 0.0, -3.0);
glTranslated(v19 * 0.05, 0.0, 0.0);
glRotated(80.0, 0.0, 1.0);
glRotated(70.0, 1.0, 0.0);
glRotated(v19, 0.0, 0.0);
glRotated(v17, 0.0, 1.0);
glTranslated(0.0, 0.0, -1.0);
glLineWidth(3.0);
v3 = 1.0 - a1[23] + a3;
if ( v3 < 0.1 )
{
v22 = (exp(1.0 - v3 / 0.1) - 1.0) / 1.718281828459045;
glTranslated(v22, v22 + 0.5, 2.5);
glRotated(-65.0, 0.0, 1.0);
glRotated(-15.0, 0.0, 0.0);
glRotated(10.0, 0.0, 1.0);
((void (*)(void))glPushMatrix)();
glRotated(90.0, 0.0, 1.0);
glRotated(90.0, 1.0, 0.0);
glRotated(3.0, 1.0, 0.0);
glTranslated(0.0, 0.3, 5.0 * v22 - 8.0);
*(_QWORD *)&v8 = COERCE_UNSIGNED_INT64(1.0 - v22) ^ LC22;
glTranslated(0.0, 0.0, v8);
draw_arrow_high_quality();
glPopMatrix();
v9 = 4.0 - (v22 + v22);
v23 = 0.5 * v22;
draw_hand(1LL, v23, v9, v8, 0.0);
v5 = v23;
v6 = *(double *)&LC7;
if ( a2 != 2 )
{
if ( a2 != 1 )
goto LABEL_6;
LABEL_13:
draw_bow_v2(v6, v5);
return glPopMatrix();
}
LABEL_10:
draw_bow_v3(v6, v5);
return glPopMatrix();
}
if ( v3 < 0.3 )
{
v21 = (v3 - 0.1) / 0.2;
glTranslated(0.0, 0.5, 2.5);
glRotated(-65.0, 0.0, 1.0);
glRotated(-15.0, 0.0, 0.0);
glRotated(10.0, 0.0, 1.0);
glRotated(v21 * -40.0, 1.0, 0.0);
glTranslated(0.0, 0.0, -3.0 * v21);
draw_hand(1LL, 0.0, 4.0, -3.0 * v21, 0.0);
v4 = LC7;
if ( a2 != 2 )
goto LABEL_5;
goto LABEL_9;
}
if ( v3 >= 0.6 )
{
v24 = 1.0 - a1[23] + a3;
v10 = SDL_GetTicks();
v11 = sin((double)v10 * 0.001);
v12 = SDL_GetTicks();
v25 = 1.0 - (v24 - 0.6) / 0.4;
v18 = v11 * 0.5 + sin((double)v12 * 0.00085) * 0.5;
glTranslated(v25 + v25, 0.0, 0.0);
glRotated(v25 * 30.0, 0.0, 1.0);
glRotated(0.0, 0.0, 0.0);
glPushMatrix(0.0, 0.0, 0.0, 1.0);
glRotated(60.0, 0.0, 1.0);
glRotated(60.0, 1.0, 0.0);
v13 = SDL_GetTicks();
v14 = sin((double)v13 * 0.0017);
glTranslated(v14 * 0.1 - 0.3, 1.0, v18 - 5.0);
glTranslated(5.0 * v25, 5.0 * v25, 0.0);
glTranslated(-10.0 * v25, 0.0, 0.0);
glRotated(v25 * -40.0, 1.0, 0.0);
glTranslated(10.0 * v25, 0.0, 0.0);
glTranslated(0.0, v25 + v25, v25 + v25);
glTranslated(-3.0 * v25, 0.0, 0.0);
draw_arrow_high_quality();
if ( a2 )
{
glPushMatrix(-3.0 * v25, 0.0, 0.0, 0.0);
glTranslated(-1.3, 0.0, 1.7);
glRotated(10.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glPushMatrix(10.0, 0.0, 1.0, 0.0);
glTranslated(1.3, 0.0, 1.0);
glRotated(-10.0, 0.0, 1.0);
draw_arrow_high_quality();
glPopMatrix();
glPopMatrix();
draw_hand(0LL, 0.1 * v18 + 0.3, 0.0, 0.1 * v18, 0.0);
v16 = 0.1 * v18;
if ( a2 == 2 )
{
draw_bow_v3(0.2, 0.1 * v18 + 0.2);
return glPopMatrix();
}
v15 = *(double *)&LC7;
v5 = v16 + 0.2;
if ( a2 == 1 )
{
v6 = *(double *)&LC7;
goto LABEL_13;
}
}
else
{
glPopMatrix();
draw_hand(0LL, 0.1 * v18 + 0.3, 0.0, 0.1 * v18, 0.0);
v15 = *(double *)&LC7;
v16 = 0.1 * v18;
}
v6 = v15;
v5 = v16 + v15;
goto LABEL_6;
}
v20 = (v3 - 0.3) / 0.3;
glTranslated(0.0, 0.5, 2.5);
glRotated(-65.0, 0.0, 1.0);
glRotated(-15.0, 0.0, 0.0);
glRotated(10.0, 0.0, 1.0);
glRotated(-40.0, 1.0, 0.0);
glTranslated(0.0, 0.0, -3.0 * v20);
glRotated(v20 * 20.0, 0.0, 1.0);
glRotated(v20 * 20.0, 1.0, 1.0);
glTranslated(0.0, 0.0, -3.0);
draw_hand(1LL, 0.0, 4.0 - (v20 + v20), -3.0, 0.0);
v4 = LC7;
if ( a2 == 2 )
{
LABEL_9:
v5 = 0.0;
v6 = *(double *)&v4;
goto LABEL_10;
}
LABEL_5:
v5 = 0.0;
v6 = *(double *)&v4;
if ( a2 == 1 )
goto LABEL_13;
LABEL_6:
draw_bow(v6, v5);
return glPopMatrix();
}

original_code:
void weapon_HUD_FIRE(Game* game, int mode,double time_offset){
 glPushMatrix();
 double real_rho=game->player->rho +fake_rho; double real_theta=game->player->theta+fake_theta; glRotated(real_rho*(-4),1,0,0); glRotated(real_theta*.5, 0.0, 1.0, 0.0); double real_HUD_drho_compensation=HUD_drho_compensation+fake_HUD_drho_compensation; glTranslated(0,0,-real_HUD_drho_compensation*real_HUD_drho_compensation*0.0007); glTranslated(5,0,-3); glTranslated(real_theta*(.05),0,0); glRotated(80, 0, 1, 0); glRotated(70, 1, 0, 0); glRotated(real_theta*(1),0,0,1); glRotated(real_HUD_drho_compensation,0,1,0); glTranslated(0,0,-1); glLineWidth(3.0);
 double time_pos=game->fire_value;
 time_pos=1-time_pos + time_offset;
 if(time_pos<.1){
  time_pos=(time_pos)/.1;
  time_pos=(exp( 1-time_pos )-1)/(exp(1)-1);
  glTranslated(1*time_pos, 1.5-1+1*time_pos, 2.5);
  glRotated(-130*.5, 0, 1, 0);
  glRotated(-30*.5, 0, 0, 1);
  glRotated(10, 0, 1, 0);
  glPushMatrix();
   glRotated(90, 0, 1, 0);
   glRotated(90, 1, 0, 0);
   glRotated(3, 1, 0, 0);
   glTranslated(0,.3,-8+5*time_pos);
   glTranslated(0,0,-1*(1-time_pos));
   draw_arrow_high_quality();
  glPopMatrix();
  draw_hand(.5*time_pos,2.+2-2*time_pos,1);
  if(mode==2){
   draw_bow_v3(.2,.5*time_pos);
  }else if(mode==1){
   draw_bow_v2(.2,.5*time_pos);
  }else{
   draw_bow(.2,.5*time_pos);
  }
 }else if(time_pos<.3){
  time_pos=(time_pos-.1)/.2;
  glTranslated(0, 1.5-1, 2.5);
  glRotated(-130*.5, 0, 1, 0);
  glRotated(-30*.5, 0, 0, 1);
  glRotated(10, 0, 1, 0);
  glRotated(-40*time_pos, 1, 0, 0);
  glTranslated(0, 0, -3*time_pos);
  draw_hand(0,2.+2,1);
  if (mode==2){
   draw_bow_v3(.2,0);
  }else if(mode==1){
   draw_bow_v2(.2,0);
  }else{
   draw_bow(.2,0);
  }
 }else if(time_pos<.6){
  time_pos=(time_pos-.3)/.3;
  glTranslated(0, 1.5-1, 2.5);
  glRotated(-130*.5, 0, 1, 0);
  glRotated(-30*.5, 0, 0, 1);
  glRotated(10, 0, 1, 0);
  glRotated(-40, 1, 0, 0);
  glTranslated(0, 0, -3*time_pos);
  glRotated(20*time_pos, 0, 1, 0);
  glRotated(20*time_pos, 1, 1, 0);
  glTranslated(0, 0, -3);
  draw_hand(0,2.+2-2*time_pos,1);
  if (mode==2){
   draw_bow_v3(.2,0);
  }else if(mode==1){
   draw_bow_v2(.2,0);
  }else{
   draw_bow(.2,0);
  }
 }else{
  double oscill_force=.5*sin(SDL_GetTicks()*.001)+.5*sin(SDL_GetTicks()*.00085);
  time_pos=(time_pos-.6)/.4;
  time_pos=1-time_pos;
  glTranslated(2*time_pos, 0, 0);
  glRotated(30*(time_pos), 0, 1, 0);
  glRotated(-0, 0, 0, 1);
  glPushMatrix();
   glRotated(60, 0, 1, 0);
   glRotated(60, 1, 0, 0);
   glTranslated(
    -.3+.1*sin(SDL_GetTicks()*.0017),
    1,
    -5+1*oscill_force
    );
   glTranslated(5*time_pos,5*time_pos,0);
   glTranslated(-10*time_pos,0,0);
   glRotated(-40*time_pos, 1,0,0);
   glTranslated(10*time_pos,0,0);
   glTranslated(0,2*time_pos,2*time_pos);
   glTranslated(-3*time_pos,0,0);
   draw_arrow_high_quality();
    if(mode){
     glPushMatrix();
      glTranslated(-1.3,0,1.7);
      glRotated(10,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
     glPushMatrix();
      glTranslated(1.3,0,1);
      glRotated(-10,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
    }
  glPopMatrix();
  draw_hand( .3+.1*oscill_force,0,0);
  if(mode==2){
   draw_bow_v3(.2,.2+.1*oscill_force);
  }else if(mode==1){
   draw_bow_v2(.2,.2+.1*oscill_force);
  }else{
   draw_bow(.2,.2+.1*oscill_force);
  }
 }
 glPopMatrix();
}

canonical_original_code:
void weapon_HUD_FIRE(struct Game *game, int mode, double time_offset){
 glPushMatrix();
 double real_rho = game->player->rho +fake_rho; double real_theta = game->player->theta+fake_theta; glRotated(real_rho*(-4),1,0,0); glRotated(real_theta*.5, 0.0, 1.0, 0.0); double real_HUD_drho_compensation = HUD_drho_compensation+fake_HUD_drho_compensation; glTranslated(0,0,-real_HUD_drho_compensation*real_HUD_drho_compensation*0.0007); glTranslated(5,0,-3); glTranslated(real_theta*(.05),0,0); glRotated(80, 0, 1, 0); glRotated(70, 1, 0, 0); glRotated(real_theta*(1),0,0,1); glRotated(real_HUD_drho_compensation,0,1,0); glTranslated(0,0,-1); glLineWidth(3.0);
 double time_pos = game->fire_value;
 time_pos=1-time_pos + time_offset;
 if(time_pos<.1){
  time_pos=(time_pos)/.1;
  time_pos=(exp( 1-time_pos )-1)/(exp(1)-1);
  glTranslated(1*time_pos, 1.5-1+1*time_pos, 2.5);
  glRotated(-130*.5, 0, 1, 0);
  glRotated(-30*.5, 0, 0, 1);
  glRotated(10, 0, 1, 0);
  glPushMatrix();
   glRotated(90, 0, 1, 0);
   glRotated(90, 1, 0, 0);
   glRotated(3, 1, 0, 0);
   glTranslated(0,.3,-8+5*time_pos);
   glTranslated(0,0,-1*(1-time_pos));
   draw_arrow_high_quality();
  glPopMatrix();
  draw_hand(.5*time_pos,2.+2-2*time_pos,1);
  if(mode==2){
   draw_bow_v3(.2,.5*time_pos);
  }else if(mode==1){
   draw_bow_v2(.2,.5*time_pos);
  }else{
   draw_bow(.2,.5*time_pos);
  }
 }else if(time_pos<.3){
  time_pos=(time_pos-.1)/.2;
  glTranslated(0, 1.5-1, 2.5);
  glRotated(-130*.5, 0, 1, 0);
  glRotated(-30*.5, 0, 0, 1);
  glRotated(10, 0, 1, 0);
  glRotated(-40*time_pos, 1, 0, 0);
  glTranslated(0, 0, -3*time_pos);
  draw_hand(0,2.+2,1);
  if (mode==2){
   draw_bow_v3(.2,0);
  }else if(mode==1){
   draw_bow_v2(.2,0);
  }else{
   draw_bow(.2,0);
  }
 }else if(time_pos<.6){
  time_pos=(time_pos-.3)/.3;
  glTranslated(0, 1.5-1, 2.5);
  glRotated(-130*.5, 0, 1, 0);
  glRotated(-30*.5, 0, 0, 1);
  glRotated(10, 0, 1, 0);
  glRotated(-40, 1, 0, 0);
  glTranslated(0, 0, -3*time_pos);
  glRotated(20*time_pos, 0, 1, 0);
  glRotated(20*time_pos, 1, 1, 0);
  glTranslated(0, 0, -3);
  draw_hand(0,2.+2-2*time_pos,1);
  if (mode==2){
   draw_bow_v3(.2,0);
  }else if(mode==1){
   draw_bow_v2(.2,0);
  }else{
   draw_bow(.2,0);
  }
 }else{
  double oscill_force = .5*sin(SDL_GetTicks()*.001)+.5*sin(SDL_GetTicks()*.00085);
  time_pos=(time_pos-.6)/.4;
  time_pos=1-time_pos;
  glTranslated(2*time_pos, 0, 0);
  glRotated(30*(time_pos), 0, 1, 0);
  glRotated(-0, 0, 0, 1);
  glPushMatrix();
   glRotated(60, 0, 1, 0);
   glRotated(60, 1, 0, 0);
   glTranslated(
    -.3+.1*sin(SDL_GetTicks()*.0017),
    1,
    -5+1*oscill_force
    );
   glTranslated(5*time_pos,5*time_pos,0);
   glTranslated(-10*time_pos,0,0);
   glRotated(-40*time_pos, 1,0,0);
   glTranslated(10*time_pos,0,0);
   glTranslated(0,2*time_pos,2*time_pos);
   glTranslated(-3*time_pos,0,0);
   draw_arrow_high_quality();
    if(mode){
     glPushMatrix();
      glTranslated(-1.3,0,1.7);
      glRotated(10,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
     glPushMatrix();
      glTranslated(1.3,0,1);
      glRotated(-10,0,1,0);
      draw_arrow_high_quality();
     glPopMatrix();
    }
  glPopMatrix();
  draw_hand( .3+.1*oscill_force,0,0);
  if(mode==2){
   draw_bow_v3(.2,.2+.1*oscill_force);
  }else if(mode==1){
   draw_bow_v2(.2,.2+.1*oscill_force);
  }else{
   draw_bow(.2,.2+.1*oscill_force);
  }
 }
 glPopMatrix();
}

variable_types: struct Game { struct Camera { struct Game *game; double theta; double phi; double rho; double dtheta; double dphi; double drho; double ddtheta; double ddphi; double ddrho; double x; double y; double z; double fake_y; double fake_z; double dx; double dy; double dz; double ddx; double ddy; double ddz; double mConvergence; double mEyeSeparation; double mAspectRatio; double mFOV; double mNearClippingDistance; double mFarClippingDistance; int avance; double angle; double x_culling; double y_culling; } *player; struct Arrow { double x; double y; double z; double dx; double dy; double dz; struct Arrow *next; struct Arrow *prev; struct Arrow *next_update; double v; double dist; double alpha; double beta; } *arrows; struct Arrow *arrows_last; struct Arrow *arrows_to_update; struct Arrow *sorting_arrow; struct Arrow *sorting_next; int color_debug; int sorting; double world_x_size; double world_y_size; double speed_custom; struct Mechant { double x; double y; double z; double dx; double dy; double dz; double phi; double theta; double rho; double dphi; double dtheta; double drho; int type; struct Mechant *next; struct Mechant *prev; void (*update)(struct Mechant *mechant); double dist; } *mechants; struct Mechant *mechants_last; struct Particle { double x; double y; double z; double z_destination; double dx; double dy; double dz; int good; struct Particle *next; struct Particle *prev; struct Particle *next_update; struct Particle *prev_update; } *particles; struct Particle *particles_update; struct AudioPlayer { struct SoundSample { char *data; char *old_data; int size; int old_read_size; int read_size; int freq; int format; int bitStream; union soundFile { struct OggVorbis_File { void *datasource; int seekable; long offset; long end; struct ogg_sync_state { unsigned char *data; int storage; int fill; int returned; int unsynced; int headerbytes; int bodybytes; } oy; int links; long *offsets; long *dataoffsets; long *serialnos; long *pcmlengths; struct vorbis_info { int version; int channels; long rate; long bitrate_upper; long bitrate_nominal; long bitrate_lower; long bitrate_window; void *codec_setup; } *vi; struct vorbis_comment { char **user_comments; int *comment_lengths; int comments; char *vendor; } *vc; long pcm_offset; int ready_state; long current_serialno; int current_link; double bittrack; double samptrack; struct ogg_stream_state { unsigned char *body_data; long body_storage; long body_fill; long body_returned; int *lacing_vals; long *granule_vals; long lacing_storage; long lacing_fill; long lacing_packet; long lacing_returned; unsigned char header[282]; int header_fill; int e_o_s; int b_o_s; long serialno; long pageno; long packetno; long granulepos; } os; struct vorbis_dsp_state { int analysisp; struct vorbis_info *vi; float **pcm; float **pcmret; int pcm_storage; int pcm_current; int pcm_returned; int preextrapolate; int eofflag; long lW; long W; long nW; long centerW; long granulepos; long sequence; long glue_bits; long time_bits; long floor_bits; long res_bits; void *backend_state; } vd; struct vorbis_block { float **pcm; struct oggpack_buffer { long endbyte; int endbit; unsigned char *buffer; unsigned char *ptr; long storage; } opb; long lW; long W; long nW; int pcmend; int mode; int eofflag; long granulepos; long sequence; struct vorbis_dsp_state *vd; void *localstore; long localtop; long localalloc; long totaluse; struct alloc_chain { void *ptr; struct alloc_chain *next; } *reap; long glue_bits; long time_bits; long floor_bits; long res_bits; void *internal; } vb; struct ov_callbacks { unsigned long (*read_func)(void *ptr, unsigned long size, unsigned long nmemb, void *datasource); int (*seek_func)(void *datasource, long offset, int whence); int (*close_func)(void *datasource); long (*tell_func)(void *datasource); } callbacks; } oggFile; } s_file; } *s1; char *next_file_path; char *now_playing; double time_buffer_offset; unsigned int source_id; unsigned int buffer_id[2]; unsigned int sound_buffer; } *audio; double audio_amplitude; double heart_beat; double heart_beat_time; double heart_beat_time_normalized; void (*update)(struct Game *game, int dt); void (*render)(struct Game *game); void (*HUD_render)(struct Game *game); int (*mechant_regeneration_type)(); double fire_value; int fire_state; double trigger_value; int trigger_state; int FIRST_SHOT; int weapon; int stereo; void (*trigger)(struct Game *game, int state); void (*fire)(struct Game *game, int state); } *

return_type: void

user_defined_types: struct Game { struct Camera *player; struct Arrow *arrows; struct Arrow *arrows_last; struct Arrow *arrows_to_update; struct Arrow *sorting_arrow; struct Arrow *sorting_next; int color_debug; int sorting; double world_x_size; double world_y_size; double speed_custom; struct Mechant *mechants; struct Mechant *mechants_last; struct Particle *particles; struct Particle *particles_update; struct AudioPlayer *audio; double audio_amplitude; double heart_beat; double heart_beat_time; double heart_beat_time_normalized; void (*update)(struct Game *game, int dt); void (*render)(struct Game *game); void (*HUD_render)(struct Game *game); int (*mechant_regeneration_type)(); double fire_value; int fire_state; double trigger_value; int trigger_state; int FIRST_SHOT; int weapon; int stereo; void (*trigger)(struct Game *game, int state); void (*fire)(struct Game *game, int state); }

user_defined_types: struct SoundSample { char *data; char *old_data; int size; int old_read_size; int read_size; int freq; int format; int bitStream; union soundFile s_file; }

user_defined_types: union soundFile { struct OggVorbis_File oggFile; }

user_defined_types: struct OggVorbis_File { void *datasource; int seekable; long offset; long end; struct ogg_sync_state oy; int links; long *offsets; long *dataoffsets; long *serialnos; long *pcmlengths; struct vorbis_info *vi; struct vorbis_comment *vc; long pcm_offset; int ready_state; long current_serialno; int current_link; double bittrack; double samptrack; struct ogg_stream_state os; struct vorbis_dsp_state vd; struct vorbis_block vb; struct ov_callbacks callbacks; }


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

if ( a1[23] <= 0.0 )
result = weapon_HUD_ARM(a1, a2, a3);
else
result = weapon_HUD_FIRE(a1, a2, a3);
return result;
}

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

if ( a1[23] <= 0.0 )
result = func3(a1, a2, a3);
else
result = func4(a1, a2, a3);
return result;
}

original_code:
void bow_HUD(Game* game, int mode,double time_offset){
 if(game->fire_value<=0){
  weapon_HUD_ARM(game,mode,time_offset);
 }else{
  weapon_HUD_FIRE(game,mode,time_offset);
 }
}

canonical_original_code:
void bow_HUD(struct Game *game, int mode, double time_offset){
 if(game->fire_value<=0){
  weapon_HUD_ARM(game,mode,time_offset);
 }else{
  weapon_HUD_FIRE(game,mode,time_offset);
 }
}

user_defined_types: struct Camera { struct Game *game; double theta; double phi; double rho; double dtheta; double dphi; double drho; double ddtheta; double ddphi; double ddrho; double x; double y; double z; double fake_y; double fake_z; double dx; double dy; double dz; double ddx; double ddy; double ddz; double mConvergence; double mEyeSeparation; double mAspectRatio; double mFOV; double mNearClippingDistance; double mFarClippingDistance; int avance; double angle; double x_culling; double y_culling; }

user_defined_types: struct Arrow { double x; double y; double z; double dx; double dy; double dz; struct Arrow *next; struct Arrow *prev; struct Arrow *next_update; double v; double dist; double alpha; double beta; }

user_defined_types: struct Mechant { double x; double y; double z; double dx; double dy; double dz; double phi; double theta; double rho; double dphi; double dtheta; double drho; int type; struct Mechant *next; struct Mechant *prev; void (*update)(struct Mechant *mechant); double dist; }

user_defined_types: struct Particle { double x; double y; double z; double z_destination; double dx; double dy; double dz; int good; struct Particle *next; struct Particle *prev; struct Particle *next_update; struct Particle *prev_update; }

user_defined_types: struct ogg_sync_state { unsigned char *data; int storage; int fill; int returned; int unsynced; int headerbytes; int bodybytes; }

user_defined_types: struct ogg_stream_state { unsigned char *body_data; long body_storage; long body_fill; long body_returned; int *lacing_vals; long *granule_vals; long lacing_storage; long lacing_fill; long lacing_packet; long lacing_returned; unsigned char header[282]; int header_fill; int e_o_s; int b_o_s; long serialno; long pageno; long packetno; long granulepos; }

user_defined_types: struct vorbis_dsp_state { int analysisp; struct vorbis_info *vi; float **pcm; float **pcmret; int pcm_storage; int pcm_current; int pcm_returned; int preextrapolate; int eofflag; long lW; long W; long nW; long centerW; long granulepos; long sequence; long glue_bits; long time_bits; long floor_bits; long res_bits; void *backend_state; }

user_defined_types: struct ov_callbacks { unsigned long (*read_func)(void *ptr, unsigned long size, unsigned long nmemb, void *datasource); int (*seek_func)(void *datasource, long offset, int whence); int (*close_func)(void *datasource); long (*tell_func)(void *datasource); }

user_defined_types: struct vorbis_info { int version; int channels; long rate; long bitrate_upper; long bitrate_nominal; long bitrate_lower; long bitrate_window; void *codec_setup; }

user_defined_types: struct vorbis_comment { char **user_comments; int *comment_lengths; int comments; char *vendor; }

user_defined_types: struct oggpack_buffer { long endbyte; int endbit; unsigned char *buffer; unsigned char *ptr; long storage; }

user_defined_types: struct alloc_chain { void *ptr; struct alloc_chain *next; }


decompiled_code:
__int64 __fastcall sulfateuse_HUD(double *a1, unsigned int a2, double a3, double a4, double a5, double a6)
{
int v6; // eax
double v7; // rbx
int v8; // eax
double v9; // xmm0_8
int v10; // eax
int v11; // ebx
double v12; // xmm0_8
float v13; // xmm0_4
__int64 result; // rax
double v15; // [rsp+0h] [rbp-40h]
double v16; // [rsp+8h] [rbp-38h]
double v17; // [rsp+10h] [rbp-30h]
double v18; // [rsp+18h] [rbp-28h]

v6 = SDL_GetTicks();
v7 = sin((double)v6 * 0.001);
v8 = SDL_GetTicks();
v15 = v7 * 0.5 + sin((double)v8 * 0.00085) * 0.5;
if ( n == 1 )
v9 = 16.0 * a1[25] + *(double *)∠
else
v9 = 10.0 * a1[25] + *(double *)∠
angle = *(_QWORD *)&v9;
glGetError();
v10 = n;
if ( n > 0 )
{
v11 = 0;
do
{
while ( 1 )
{
v12 = (double)v11 / (double)v10;
v16 = 1.0 - v12;
glPushMatrix(v12, (double)v10, a5, a6);
v18 = *(double *)(*(_QWORD *)a1 + 8LL) + *(double *)&fake_theta;
glRotated((*(double *)(*(_QWORD *)a1 + 24LL) + *(double *)&fake_rho) * -4.0, 1.0, 0.0);
glRotated(0.5 * v18, 0.0, 1.0);
v17 = *(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation;
glTranslated(
0.05 * v18 + 5.0,
0.0,
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation) ^ LC22)
* (*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation)
* 0.0007
- 3.0);
glRotated(80.0, 0.0, 1.0);
glRotated(70.0, 1.0, 0.0);
glRotated(v18, 0.0, 0.0);
a6 = 0.0;
glRotated(v17, 0.0, 1.0);
a5 = *(double *)&LC28;
glTranslated(0.0, 0.0, -1.0);
if ( a1[25] * (1.0 - v12) != 0.0 )
{
glTranslated(0.0, COERCE_DOUBLE(*(_QWORD *)&v16 ^ LC22) * a1[23], 0.0);
a5 = 0.0;
a6 = *(double *)&LC12;
glRotated(v16 * -2.0 * a1[23], 0.0, 0.0);
}
glLineWidth(3.0);
draw_hand(0LL, 0.1 * v15 + 0.3, 0.0, a5, a6);
draw_sulfateuse(a2, 0.0, *(double *)&angle - (double)(4 * v11) * a1[25]);
glPopMatrix();
v13 = 1.0 / (double)n;
if ( v11 )
break;
v11 = 1;
glAccum(257LL, v13);
v10 = n;
if ( n <= 1 )
goto LABEL_10;
}
++v11;
glAccum(256LL, v13);
v10 = n;
}
while ( n > v11 );
}
LABEL_10:
glAccum(258LL, 1.0);
result = glGetError();
if ( (result & 0x502) != 0 )
n = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(double *a1, unsigned int a2, double a3, double a4, double a5, double a6)
{
int v6; // eax
double v7; // rbx
int v8; // eax
double v9; // xmm0_8
int v10; // eax
int v11; // ebx
double v12; // xmm0_8
float v13; // xmm0_4
__int64 result; // rax
double v15; // [rsp+0h] [rbp-40h]
double v16; // [rsp+8h] [rbp-38h]
double v17; // [rsp+10h] [rbp-30h]
double v18; // [rsp+18h] [rbp-28h]

v6 = SDL_GetTicks();
v7 = sin((double)v6 * 0.001);
v8 = SDL_GetTicks();
v15 = v7 * 0.5 + sin((double)v8 * 0.00085) * 0.5;
if ( n == 1 )
v9 = 16.0 * a1[25] + *(double *)∠
else
v9 = 10.0 * a1[25] + *(double *)∠
angle = *(_QWORD *)&v9;
glGetError();
v10 = n;
if ( n > 0 )
{
v11 = 0;
do
{
while ( 1 )
{
v12 = (double)v11 / (double)v10;
v16 = 1.0 - v12;
glPushMatrix(v12, (double)v10, a5, a6);
v18 = *(double *)(*(_QWORD *)a1 + 8LL) + *(double *)&fake_theta;
glRotated((*(double *)(*(_QWORD *)a1 + 24LL) + *(double *)&fake_rho) * -4.0, 1.0, 0.0);
glRotated(0.5 * v18, 0.0, 1.0);
v17 = *(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation;
glTranslated(
0.05 * v18 + 5.0,
0.0,
COERCE_DOUBLE(COERCE_UNSIGNED_INT64(*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation) ^ LC22)
* (*(double *)&HUD_drho_compensation + *(double *)&fake_HUD_drho_compensation)
* 0.0007
- 3.0);
glRotated(80.0, 0.0, 1.0);
glRotated(70.0, 1.0, 0.0);
glRotated(v18, 0.0, 0.0);
a6 = 0.0;
glRotated(v17, 0.0, 1.0);
a5 = *(double *)&LC28;
glTranslated(0.0, 0.0, -1.0);
if ( a1[25] * (1.0 - v12) != 0.0 )
{
glTranslated(0.0, COERCE_DOUBLE(*(_QWORD *)&v16 ^ LC22) * a1[23], 0.0);
a5 = 0.0;
a6 = *(double *)&LC12;
glRotated(v16 * -2.0 * a1[23], 0.0, 0.0);
}
glLineWidth(3.0);
draw_hand(0LL, 0.1 * v15 + 0.3, 0.0, a5, a6);
draw_sulfateuse(a2, 0.0, *(double *)&angle - (double)(4 * v11) * a1[25]);
glPopMatrix();
v13 = 1.0 / (double)n;
if ( v11 )
break;
v11 = 1;
glAccum(257LL, v13);
v10 = n;
if ( n <= 1 )
goto LABEL_10;
}
++v11;
glAccum(256LL, v13);
v10 = n;
}
while ( n > v11 );
}
LABEL_10:
glAccum(258LL, 1.0);
result = glGetError();
if ( (result & 0x502) != 0 )
n = 1;
return result;
}

original_code:
void sulfateuse_HUD(Game* game, int color,double time_offset){
 double oscill_force=.5*sin(SDL_GetTicks()*.001)+.5*sin(SDL_GetTicks()*.00085);
 if(n==1){
  angle+=game->trigger_value*16.;
 }else{
  angle+=game->trigger_value*10.;
 }
 glGetError();
 for(int i=0;i<n;i++){
  double x=1-i*1./n;
  glPushMatrix();
    double real_rho=game->player->rho +fake_rho;
    double real_theta=game->player->theta+fake_theta;
    glRotated(real_rho*(-4),1,0,0);
    glRotated(real_theta*.5, 0, 1, 0);
    double real_HUD_drho_compensation=HUD_drho_compensation+fake_HUD_drho_compensation;
    glTranslated(real_theta*(.05)+5,0,-real_HUD_drho_compensation*real_HUD_drho_compensation*0.0007-3);
    glRotated(80, 0, 1, 0);
    glRotated(70, 1, 0, 0);
    glRotated(real_theta*(1),0,0,1);
    glRotated(real_HUD_drho_compensation,0,1,0);
     glTranslated(0,0,-1);
    if(x*game->trigger_value){
     glTranslated(0,-x*game->fire_value,0);
     glRotated(-2*x*game->fire_value,0,0,1);
    }
    glLineWidth(3.0);
    draw_hand( .3+.1*oscill_force,0,0);
    draw_sulfateuse(0,angle-4*i*game->trigger_value,color);
  glPopMatrix();
  if(i == 0)
   glAccum(0x0101, 1.0 / n);
  else
   glAccum(0x0100, 1.0 / n);
 }
 glAccum(0x0102, 1.0);
 if(glGetError()&0x0502) {
  n=1;
 }
}

canonical_original_code:
void sulfateuse_HUD(struct Game *game, int color, double time_offset){
 double oscill_force = .5*sin(SDL_GetTicks()*.001)+.5*sin(SDL_GetTicks()*.00085);
 if(n==1){
  angle+=game->trigger_value*16.;
 }else{
  angle+=game->trigger_value*10.;
 }
 glGetError();
 for(int i = 0;i<n;i++){
  double x = 1-i*1./n;
  glPushMatrix();
    double real_rho = game->player->rho +fake_rho;
    double real_theta = game->player->theta+fake_theta;
    glRotated(real_rho*(-4),1,0,0);
    glRotated(real_theta*.5, 0, 1, 0);
    double real_HUD_drho_compensation = HUD_drho_compensation+fake_HUD_drho_compensation;
    glTranslated(real_theta*(.05)+5,0,-real_HUD_drho_compensation*real_HUD_drho_compensation*0.0007-3);
    glRotated(80, 0, 1, 0);
    glRotated(70, 1, 0, 0);
    glRotated(real_theta*(1),0,0,1);
    glRotated(real_HUD_drho_compensation,0,1,0);
     glTranslated(0,0,-1);
    if(x*game->trigger_value){
     glTranslated(0,-x*game->fire_value,0);
     glRotated(-2*x*game->fire_value,0,0,1);
    }
    glLineWidth(3.0);
    draw_hand( .3+.1*oscill_force,0,0);
    draw_sulfateuse(0,angle-4*i*game->trigger_value,color);
  glPopMatrix();
  if(i == 0)
   glAccum(0x0101, 1.0 / n);
  else
   glAccum(0x0100, 1.0 / n);
 }
 glAccum(0x0102, 1.0);
 if(glGetError()&0x0502) {
  n=1;
 }
}

variable_types: color int

variable_types: i int

variable_types: x double

user_defined_types: struct AudioPlayer { struct SoundSample *s1; char *next_file_path; char *now_playing; double time_buffer_offset; unsigned int source_id; unsigned int buffer_id[2]; unsigned int sound_buffer; }

user_defined_types: struct vorbis_block { float **pcm; struct oggpack_buffer opb; long lW; long W; long nW; int pcmend; int mode; int eofflag; long granulepos; long sequence; struct vorbis_dsp_state *vd; void *localstore; long localtop; long localalloc; long totaluse; struct alloc_chain *reap; long glue_bits; long time_bits; long floor_bits; long res_bits; void *internal; }


HUD

decompiled_code:
__int64 __fastcall HUD(__int64 a1, double a2, double a3, double a4, double a5)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 216);
if ( (_DWORD)result )
{
switch ( (_DWORD)result )
{
case 1:
result = bow_HUD((double *)a1, 0, 0.0);
break;
case 2:
result = sulfateuse_HUD((double *)a1, 0, 0.0, a3, a4, a5);
break;
case 3:
result = sulfateuse_HUD((double *)a1, 1u, 0.0, a3, a4, a5);
break;
case 4:
result = bow_HUD((double *)a1, 1, 0.0);
break;
case 5:
result = bow_HUD((double *)a1, 2, 0.0);
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, double a2, double a3, double a4, double a5)
{
__int64 result; // rax

result = *(unsigned int *)(a1 + 216);
if ( (_DWORD)result )
{
switch ( (_DWORD)result )
{
case 1:
result = func5((double *)a1, 0, 0.0);
break;
case 2:
result = func6((double *)a1, 0, 0.0, a3, a4, a5);
break;
case 3:
result = func6((double *)a1, 1u, 0.0, a3, a4, a5);
break;
case 4:
result = func5((double *)a1, 1, 0.0);
break;
case 5:
result = func5((double *)a1, 2, 0.0);
break;
}
}
return result;
}

original_code:
void HUD(Game* game){
  double time_offset=0;
    if(game->weapon==0){
    }
    else if(game->weapon==1){
     bow_HUD(game,0,time_offset);
    }
    else if(game->weapon==2){
     sulfateuse_HUD(game,0,time_offset);
    }else if(game->weapon==3){
     sulfateuse_HUD(game,1,time_offset);
    }else if(game->weapon==4){
     bow_HUD(game,1,time_offset);
    }else if(game->weapon==5){
     bow_HUD(game,2,time_offset);
    }
}

canonical_original_code:
void HUD(struct Game *game){
  double time_offset = 0;
    if(game->weapon==0){
    }
    else if(game->weapon==1){
     bow_HUD(game,0,time_offset);
    }
    else if(game->weapon==2){
     sulfateuse_HUD(game,0,time_offset);
    }else if(game->weapon==3){
     sulfateuse_HUD(game,1,time_offset);
    }else if(game->weapon==4){
     bow_HUD(game,1,time_offset);
    }else if(game->weapon==5){
     bow_HUD(game,2,time_offset);
    }
}

user_defined_types: struct Game { struct Camera *player; struct Arrow *arrows; struct Arrow *arrows_last; struct Arrow *arrows_to_update; struct Arrow *sorting_arrow; struct Arrow *sorting_next; int color_debug; int sorting; double world_x_size; double world_y_size; double speed_custom; struct Mechant *mechants; struct Mechant *mechants_last; struct Particle *particles; struct Particle *particles_update; struct AudioPlayer *audio; double audio_amplitude; double heart_beat; double heart_beat_time; double heart_beat_time_normalized; void (*update)(struct Game *game, int dt); void (*render)(struct Game *game); void (*HUD_render)(struct Game *game); int (*mechant_regeneration_type)(); double fire_value; int fire_state; double trigger_value; int trigger_state; int FIRST_SHOT; int weapon; int stereo; void (*trigger)(struct Game *game, int state); void (*fire)(struct Game *game, int state); }

user_defined_types: struct SoundSample { char *data; char *old_data; int size; int old_read_size; int read_size; int freq; int format; int bitStream; union soundFile s_file; }


decompiled_code:
void __fastcall ingame_level4_update(__int64 a1)
{
__int64 v1; // r8
const char *v2; // rsi
int v3; // er12
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm3_8
double v7; // xmm5_8
double v8; // xmm4_8
char v9; // al
double v10; // xmm2_8
double v11; // [rsp+10h] [rbp-20h]
double v12; // [rsp+10h] [rbp-20h]
double v13; // [rsp+10h] [rbp-20h]
double v14; // [rsp+18h] [rbp-18h]
double v15; // [rsp+18h] [rbp-18h]
double v16; // [rsp+18h] [rbp-18h]

v1 = *(_QWORD *)(a1 + 112);
v2 = *(const char **)(v1 + 16);
*(_QWORD *)(a1 + 176) = mechant_regeneration_type_level4_0;
if ( !strcmp(v2, "music/Goto80_gopho_level4.ogg") )
{
audioplayer_set_next(v1, "music/silence.ogg");
v14 = audioplayer_getTime(*(_QWORD *)(a1 + 112));
v3 = SDL_GetTicks();
v4 = (double)v3 * 0.001 - level3_get_time_offset();
v5 = fmod(v4, 0.96);
v6 = v14;
v7 = *(double *)&LC5;
t = *(_QWORD *)&v5;
if ( v14 <= 69.0 || v14 >= 76.0 )
{
if ( v14 > 76.0 && v14 < 83.0 )
{
if ( !ending_cleared )
{
clear_arrow(a1);
clear_particles(a1);
clear_mechant(a1);
v7 = *(double *)&LC5;
v6 = v14;
ending_cleared = 1;
}
v16 = v7;
change_bg_color(1.0 - (v6 - v7) / 7.0, 0.0);
v7 = v16;
}
}
else
{
change_bg_color((v14 - 69.0) / 7.0, 0.0);
v7 = *(double *)&LC5;
}
v8 = *(double *)&LC10;
if ( v6 < 14.85 )
{
v13 = v7;
change_bg_color(1.0, 1.0);
v7 = v13;
v8 = *(double *)&LC10;
}
if ( v6 > v8 && v6 < 15.3 )
{
v9 = mega_sulfateuse_transition;
if ( v6 > v8 + (double)mega_sulfateuse_transition * 0.4500000000000011 / 7.0 )
{
++mega_sulfateuse_transition;
v11 = v7;
if ( ((v9 + 1) & 1) != 0 )
{
change_bg_color(1.0, 0.0);
v7 = v11;
*(_DWORD *)(a1 + 216) = 3;
}
else
{
change_bg_color(0.5, 0.0);
v7 = v11;
*(_DWORD *)(a1 + 216) = 2;
}
}
}
if ( v6 > 15.3 && v7 > v6 )
{
if ( mega_sulfateuse_transition )
{
change_bg_color(0.0, 0.0);
*(_DWORD *)(a1 + 216) = 3;
mega_sulfateuse_transition = 0;
}
v10 = *(double *)&t;
v12 = *(double *)&t;
*(double *)(a1 + 144) = *(double *)&t / 0.96;
*(double *)(a1 + 136) = v10;
v15 = exp(v10 * -4.0);
*(double *)(a1 + 128) = (v15 + v15) * sin(v12 * 24.0);
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
__int64 v1; // r8
const char *v2; // rsi
int v3; // er12
double v4; // xmm0_8
double v5; // xmm0_8
double v6; // xmm3_8
double v7; // xmm5_8
double v8; // xmm4_8
char v9; // al
double v10; // xmm2_8
double v11; // [rsp+10h] [rbp-20h]
double v12; // [rsp+10h] [rbp-20h]
double v13; // [rsp+10h] [rbp-20h]
double v14; // [rsp+18h] [rbp-18h]
double v15; // [rsp+18h] [rbp-18h]
double v16; // [rsp+18h] [rbp-18h]

v1 = *(_QWORD *)(a1 + 112);
v2 = *(const char **)(v1 + 16);
*(_QWORD *)(a1 + 176) = mechant_regeneration_type_level4_0;
if ( !strcmp(v2, "music/Goto80_gopho_level4.ogg") )
{
audioplayer_set_next(v1, "music/silence.ogg");
v14 = audioplayer_getTime(*(_QWORD *)(a1 + 112));
v3 = SDL_GetTicks();
v4 = (double)v3 * 0.001 - level3_get_time_offset();
v5 = fmod(v4, 0.96);
v6 = v14;
v7 = *(double *)&LC5;
t = *(_QWORD *)&v5;
if ( v14 <= 69.0 || v14 >= 76.0 )
{
if ( v14 > 76.0 && v14 < 83.0 )
{
if ( !ending_cleared )
{
clear_arrow(a1);
clear_particles(a1);
clear_mechant(a1);
v7 = *(double *)&LC5;
v6 = v14;
ending_cleared = 1;
}
v16 = v7;
change_bg_color(1.0 - (v6 - v7) / 7.0, 0.0);
v7 = v16;
}
}
else
{
change_bg_color((v14 - 69.0) / 7.0, 0.0);
v7 = *(double *)&LC5;
}
v8 = *(double *)&LC10;
if ( v6 < 14.85 )
{
v13 = v7;
change_bg_color(1.0, 1.0);
v7 = v13;
v8 = *(double *)&LC10;
}
if ( v6 > v8 && v6 < 15.3 )
{
v9 = mega_sulfateuse_transition;
if ( v6 > v8 + (double)mega_sulfateuse_transition * 0.4500000000000011 / 7.0 )
{
++mega_sulfateuse_transition;
v11 = v7;
if ( ((v9 + 1) & 1) != 0 )
{
change_bg_color(1.0, 0.0);
v7 = v11;
*(_DWORD *)(a1 + 216) = 3;
}
else
{
change_bg_color(0.5, 0.0);
v7 = v11;
*(_DWORD *)(a1 + 216) = 2;
}
}
}
if ( v6 > 15.3 && v7 > v6 )
{
if ( mega_sulfateuse_transition )
{
change_bg_color(0.0, 0.0);
*(_DWORD *)(a1 + 216) = 3;
mega_sulfateuse_transition = 0;
}
v10 = *(double *)&t;
v12 = *(double *)&t;
*(double *)(a1 + 144) = *(double *)&t / 0.96;
*(double *)(a1 + 136) = v10;
v15 = exp(v10 * -4.0);
*(double *)(a1 + 128) = (v15 + v15) * sin(v12 * 24.0);
}
}
}

original_code:
void ingame_level4_update(Game* game,int dt){
 int mechant_regeneration_type_level4(){
  return rand()%3;
 }
 game->mechant_regeneration_type=mechant_regeneration_type_level4;
 if(!strcmp(game->audio->now_playing,"music/Goto80_gopho_level4.ogg")){
  audioplayer_set_next(game->audio,"music/silence.ogg");
  double music_time=audioplayer_getTime(game->audio);
  double time_=SDL_GetTicks()*0.001-level3_get_time_offset();
  t=fmod(time_,deltat);
  if(music_time>69 && music_time<69+7){
   double xxx =(music_time-69.)/7.;
   change_bg_color(xxx,0.,0.);
  }else if(music_time>76 && music_time<83){
   if(!ending_cleared){
    clear_arrow(game);
    clear_particles(game);
    clear_mechant(game);
    ending_cleared=1;
   }
   double xxx=(music_time-76)/(83.-76.);
   change_bg_color(1.-xxx,0.,0.);
  }
  if(music_time<14.85){
   change_bg_color(1,1,1);
  }
  if(music_time>14.85 && music_time<15.30 ){
   if(music_time>14.85+mega_sulfateuse_transition*(15.30-14.85)/7.){
    mega_sulfateuse_transition++;
    if(mega_sulfateuse_transition%2==0){
     change_bg_color(.5,0,0);
     game->weapon=2;
    }else{
     change_bg_color(1,0,0);
     game->weapon=3;
    }
   }
  }
  if(music_time>15.30 && music_time<69+7 ){
   if(mega_sulfateuse_transition){
    change_bg_color(0,0,0);
    game->weapon=3;
    mega_sulfateuse_transition=0;
   }
   game->heart_beat_time=t;
   game->heart_beat_time_normalized=t/deltat;
   game->heart_beat=2*exp(-4*t)*sin(24*t);
  }
 }
}

canonical_original_code:
void ingame_level4_update(struct Game *game, int dt){
 int mechant_regeneration_type_level4(){
  return rand()%3;
 }
 game->mechant_regeneration_type=mechant_regeneration_type_level4;
 if(!strcmp(game->audio->now_playing,"music/Goto80_gopho_level4.ogg")){
  audioplayer_set_next(game->audio,"music/silence.ogg");
  double music_time = audioplayer_getTime(game->audio);
  double time_ = SDL_GetTicks()*0.001-level3_get_time_offset();
  t=fmod(time_,deltat);
  if(music_time>69 && music_time<69+7){
   double xxx = (music_time-69.)/7.;
   change_bg_color(xxx,0.,0.);
  }else if(music_time>76 && music_time<83){
   if(!ending_cleared){
    clear_arrow(game);
    clear_particles(game);
    clear_mechant(game);
    ending_cleared=1;
   }
   double xxx = (music_time-76)/(83.-76.);
   change_bg_color(1.-xxx,0.,0.);
  }
  if(music_time<14.85){
   change_bg_color(1,1,1);
  }
  if(music_time>14.85 && music_time<15.30 ){
   if(music_time>14.85+mega_sulfateuse_transition*(15.30-14.85)/7.){
    mega_sulfateuse_transition++;
    if(mega_sulfateuse_transition%2==0){
     change_bg_color(.5,0,0);
     game->weapon=2;
    }else{
     change_bg_color(1,0,0);
     game->weapon=3;
    }
   }
  }
  if(music_time>15.30 && music_time<69+7 ){
   if(mega_sulfateuse_transition){
    change_bg_color(0,0,0);
    game->weapon=3;
    mega_sulfateuse_transition=0;
   }
   game->heart_beat_time=t;
   game->heart_beat_time_normalized=t/deltat;
   game->heart_beat=2*exp(-4*t)*sin(24*t);
  }
 }
}

variable_types: dt int

variable_types: xxx double

user_defined_types: union soundFile { struct OggVorbis_File oggFile; }

user_defined_types: struct OggVorbis_File { void *datasource; int seekable; long offset; long end; struct ogg_sync_state oy; int links; long *offsets; long *dataoffsets; long *serialnos; long *pcmlengths; struct vorbis_info *vi; struct vorbis_comment *vc; long pcm_offset; int ready_state; long current_serialno; int current_link; double bittrack; double samptrack; struct ogg_stream_state os; struct vorbis_dsp_state vd; struct vorbis_block vb; struct ov_callbacks callbacks; }


decompiled_code:
char __fastcall ingame_level4_render(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm1_8
bool v3; // zf
char result; // al
double v5; // xmm2_8

v1 = audioplayer_getTime(*(_QWORD *)(a1 + 112));
v2 = v1;
v3 = strcmp(*(const char **)(*(_QWORD *)(a1 + 112) + 16LL), "music/Goto80_gopho_level4.ogg") == 0;
result = !v3;
if ( v3 )
{
v5 = *(double *)&LC4;
if ( v1 > 15.3 && v1 < 69.0 )
{
result = draw_sky_random_cubes((double *)a1, 1.0);
v5 = *(double *)&LC4;
v2 = v1;
}
if ( v2 > v5 && v2 < 76.0 )
result = draw_sky_random_cubes((double *)a1, 1.0 - (v2 - v5) / 7.0);
}
return result;
}

canonical_decompiled_code:
char __fastcall func3(__int64 a1)
{
double v1; // xmm0_8
double v2; // xmm1_8
bool v3; // zf
char result; // al
double v5; // xmm2_8

v1 = audioplayer_getTime(*(_QWORD *)(a1 + 112));
v2 = v1;
v3 = strcmp(*(const char **)(*(_QWORD *)(a1 + 112) + 16LL), "music/Goto80_gopho_level4.ogg") == 0;
result = !v3;
if ( v3 )
{
v5 = *(double *)&LC4;
if ( v1 > 15.3 && v1 < 69.0 )
{
result = func2((double *)a1, 1.0);
v5 = *(double *)&LC4;
v2 = v1;
}
if ( v2 > v5 && v2 < 76.0 )
result = func2((double *)a1, 1.0 - (v2 - v5) / 7.0);
}
return result;
}

original_code:
void ingame_level4_render(Game* game){
 double music_time=audioplayer_getTime(game->audio);
 if(!strcmp(game->audio->now_playing,"music/Goto80_gopho_level4.ogg")){
  if(music_time>15.30 && music_time<69 ){
   draw_sky_random_cubes(game,1);
  }if(music_time>69 && music_time<69+7){
   double k=(music_time-69)/7.;
   draw_sky_random_cubes(game,1-k);
  }
 }
}

canonical_original_code:
void ingame_level4_render(struct Game *game){
 double music_time = audioplayer_getTime(game->audio);
 if(!strcmp(game->audio->now_playing,"music/Goto80_gopho_level4.ogg")){
  if(music_time>15.30 && music_time<69 ){
   draw_sky_random_cubes(game,1);
  }if(music_time>69 && music_time<69+7){
   double k = (music_time-69)/7.;
   draw_sky_random_cubes(game,1-k);
  }
 }
}

variable_types: k double

user_defined_types: struct Camera { struct Game *game; double theta; double phi; double rho; double dtheta; double dphi; double drho; double ddtheta; double ddphi; double ddrho; double x; double y; double z; double fake_y; double fake_z; double dx; double dy; double dz; double ddx; double ddy; double ddz; double mConvergence; double mEyeSeparation; double mAspectRatio; double mFOV; double mNearClippingDistance; double mFarClippingDistance; int avance; double angle; double x_culling; double y_culling; }

user_defined_types: struct Arrow { double x; double y; double z; double dx; double dy; double dz; struct Arrow *next; struct Arrow *prev; struct Arrow *next_update; double v; double dist; double alpha; double beta; }


decompiled_code:
__int64 __fastcall ingame_level4_setup(_QWORD *a1)
{
audioplayer_set_next(a1[14], "music/Goto80_gopho_level4.ogg");
a1[19] = ingame_level4_update;
a1[20] = ingame_level4_render;
set_time_(0.0);
level3_get_time_offset();
glEnable(2912LL);
glFogi(2917LL, 9729LL);
glFogf(2915LL, 20.0);
glFogf(2916LL, 250.0);
glFogf(2914LL, 0.34999999);
return change_bg_color(1.0, 1.0);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
audioplayer_set_next(a1[14], "music/Goto80_gopho_level4.ogg");
a1[19] = ingame_level4_update;
a1[20] = ingame_level4_render;
set_time_(0.0);
level3_get_time_offset();
glEnable(2912LL);
glFogi(2917LL, 9729LL);
glFogf(2915LL, 20.0);
glFogf(2916LL, 250.0);
glFogf(2914LL, 0.34999999);
return change_bg_color(1.0, 1.0);
}

original_code:
void ingame_level4_setup(Game* game){
 audioplayer_set_next(game->audio,"music/Goto80_gopho_level4.ogg");
 game->update=ingame_level4_update;
 game->render=ingame_level4_render;
 set_time_(0);
 time_offset=level3_get_time_offset();
 glEnable(0x0B60);
 glFogi(0x0B65, 0x2601);
 glFogf(0x0B63, 20);
 glFogf(0x0B64, 250);
 glFogf(0x0B62, 0.35f);
 change_bg_color(1,1,1);
}

canonical_original_code:
void ingame_level4_setup(struct Game *game){
 audioplayer_set_next(game->audio,"music/Goto80_gopho_level4.ogg");
 game->update=ingame_level4_update;
 game->render=ingame_level4_render;
 set_time_(0);
 time_offset=level3_get_time_offset();
 glEnable(0x0B60);
 glFogi(0x0B65, 0x2601);
 glFogf(0x0B63, 20);
 glFogf(0x0B64, 250);
 glFogf(0x0B62, 0.35f);
 change_bg_color(1,1,1);
}

user_defined_types: struct Mechant { double x; double y; double z; double dx; double dy; double dz; double phi; double theta; double rho; double dphi; double dtheta; double drho; int type; struct Mechant *next; struct Mechant *prev; void (*update)(struct Mechant *mechant); double dist; }

user_defined_types: struct Particle { double x; double y; double z; double z_destination; double dx; double dy; double dz; int good; struct Particle *next; struct Particle *prev; struct Particle *next_update; struct Particle *prev_update; }


original_code:
static void draw_sky_random_cubes(Game* game,double dissipation){
 if(!skycubeinit){
  for(int i=0;i<30;i++){
   for(int j=0;j<30;j++){
    skycubes[i][j][0]=(i-30/2.)*600./30;
    skycubes[i][j][1]=(j-30/2.)*600./30;
    skycubes[i][j][2]=130;
   }
  }
  skycubeinit=1;
 }
 for(int i=0;i<30;i++){
  for(int j=0;j<30;j++){
   skycubes[i][j][2]=130;
  }
 }
 double music_time=audioplayer_getTime(game->audio);
 double ttt=SDL_GetTicks()*0.001;
 for (int j=0;j<30;j++){
  for (int i=0;i<30;i++){
   game_loop_coord(game,&skycubes[i][j][0], &skycubes[i][j][1]);
   double x=i*1./30;
   double y=j*1./30;
   double front_x=game->player->x_culling - game->player->x;
   double front_y=game->player->y_culling - game->player->y;
   front_x*=30;
   front_y*=30;
   front_x=front_x + game->player->x;
   front_y=front_y + game->player->y;
   double alpha = atan2((skycubes[i][j][1]+front_y),(skycubes[i][j][0]+front_x))*180./3.14159265359;
   alpha = alpha+game->player->phi;
   while(alpha<=0) alpha+=360;
   while(alpha>360) alpha-=360;
   if(alpha <90||alpha>360-90){
    double xx=skycubes[i][j][0]+game->player->x;
    double yy=skycubes[i][j][1]+game->player->y;
    xx*=xx;
    yy*=yy;
    double dist= sqrt (xx+yy) / 600.;
    double z_size=80.;
    skycubes[i][j][2]+=
     -20*cos(i*6*3.14159265359/30 +SDL_GetTicks()*0.001)
     -10*cos(i*12*3.14159265359/30 -SDL_GetTicks()*0.002)
     -20*cos(j*8*3.14159265359/30 +SDL_GetTicks()*0.001);
     -10*cos(j*10*3.14159265359/30 -SDL_GetTicks()*0.003);
    glPushMatrix();
     glTranslated(
      skycubes[i][j][0],
      skycubes[i][j][1],
      ( skycubes[i][j][2] - dist*200 + 20*cos(dist*2*3.14159265359 +.001*game->heart_beat)*game->heart_beat)
      +z_size/2.);
     glScaled(500./30,500./30,-z_size);
     simple_cube_color(
      (.5-dist*.5)*dissipation + 1-dissipation +(.3+.3*cos(3*2*3.14159265359*x+3*2*3.14159265359*y+ttt*10-1.2*t))*dissipation,
      0,
      0,
      0+1-dissipation,
      0,
      0);
    glPopMatrix();
    glPushMatrix();
     glTranslated(
      skycubes[i][j][0],
      skycubes[i][j][1],
      -skycubes[i][j][2] + dist*200 - 20*cos(dist*2*3.14159265359)*game->heart_beat
      -z_size/2.);
     glScaled(500./30,500./30,z_size);
     simple_cube_color(
      (.2-dist*.2)*dissipation + 1 - dissipation +(.2+.2*cos(-3*2*3.14159265359*x-3*2*3.14159265359*y+ttt*10-1.2*t))*dissipation,
      0,
      0,
      1-dissipation,0,0);
    glPopMatrix();
   }
  }
 }
}

canonical_original_code:
static void draw_sky_random_cubes(struct Game *game, double dissipation){
 if(!skycubeinit){
  for(int i = 0;i<30;i++){
   for(int j = 0;j<30;j++){
    skycubes[i][j][0]=(i-30/2.)*600./30;
    skycubes[i][j][1]=(j-30/2.)*600./30;
    skycubes[i][j][2]=130;
   }
  }
  skycubeinit=1;
 }
 for(int i = 0;i<30;i++){
  for(int j = 0;j<30;j++){
   skycubes[i][j][2]=130;
  }
 }
 double music_time = audioplayer_getTime(game->audio);
 double ttt = SDL_GetTicks()*0.001;
 for (int j = 0;j<30;j++){
  for (int i = 0;i<30;i++){
   game_loop_coord(game,&skycubes[i][j][0], &skycubes[i][j][1]);
   double x = i*1./30;
   double y = j*1./30;
   double front_x = game->player->x_culling - game->player->x;
   double front_y = game->player->y_culling - game->player->y;
   front_x*=30;
   front_y*=30;
   front_x=front_x + game->player->x;
   front_y=front_y + game->player->y;
   double alpha = atan2((skycubes[i][j][1]+front_y),(skycubes[i][j][0]+front_x))*180./3.14159265359;
   alpha = alpha+game->player->phi;
   while(alpha<=0) alpha+=360;
   while(alpha>360) alpha-=360;
   if(alpha <90||alpha>360-90){
    double xx = skycubes[i][j][0]+game->player->x;
    double yy = skycubes[i][j][1]+game->player->y;
    xx*=xx;
    yy*=yy;
    double dist = sqrt (xx+yy) / 600.;
    double z_size = 80.;
    skycubes[i][j][2]+=
     -20*cos(i*6*3.14159265359/30 +SDL_GetTicks()*0.001)
     -10*cos(i*12*3.14159265359/30 -SDL_GetTicks()*0.002)
     -20*cos(j*8*3.14159265359/30 +SDL_GetTicks()*0.001);
     -10*cos(j*10*3.14159265359/30 -SDL_GetTicks()*0.003);
    glPushMatrix();
     glTranslated(
      skycubes[i][j][0],
      skycubes[i][j][1],
      ( skycubes[i][j][2] - dist*200 + 20*cos(dist*2*3.14159265359 +.001*game->heart_beat)*game->heart_beat)
      +z_size/2.);
     glScaled(500./30,500./30,-z_size);
     simple_cube_color(
      (.5-dist*.5)*dissipation + 1-dissipation +(.3+.3*cos(3*2*3.14159265359*x+3*2*3.14159265359*y+ttt*10-1.2*t))*dissipation,
      0,
      0,
      0+1-dissipation,
      0,
      0);
    glPopMatrix();
    glPushMatrix();
     glTranslated(
      skycubes[i][j][0],
      skycubes[i][j][1],
      -skycubes[i][j][2] + dist*200 - 20*cos(dist*2*3.14159265359)*game->heart_beat
      -z_size/2.);
     glScaled(500./30,500./30,z_size);
     simple_cube_color(
      (.2-dist*.2)*dissipation + 1 - dissipation +(.2+.2*cos(-3*2*3.14159265359*x-3*2*3.14159265359*y+ttt*10-1.2*t))*dissipation,
      0,
      0,
      1-dissipation,0,0);
    glPopMatrix();
   }
  }
 }
}

variable_types: dissipation double

variable_types: j int

variable_types: ttt double

variable_types: y double

variable_types: alpha double

variable_types: xx double

variable_types: yy double

variable_types: dist double

user_defined_types: struct ogg_sync_state { unsigned char *data; int storage; int fill; int returned; int unsynced; int headerbytes; int bodybytes; }

user_defined_types: struct ogg_stream_state { unsigned char *body_data; long body_storage; long body_fill; long body_returned; int *lacing_vals; long *granule_vals; long lacing_storage; long lacing_fill; long lacing_packet; long lacing_returned; unsigned char header[282]; int header_fill; int e_o_s; int b_o_s; long serialno; long pageno; long packetno; long granulepos; }


repo: pousa/fake-affinity

decompiled_code:
const char *__fastcall get_logical_allowed_CPUs(__int64 a1)
{
const char *result; // rax
const char *v3; // r12
void *v4; // rsp
const char *i; // rdi
__int64 v6; // r15
char v7[8]; // [rsp+0h] [rbp-50h] BYREF
char *v8; // [rsp+8h] [rbp-48h]
char delim[2]; // [rsp+1Eh] [rbp-32h] BYREF

result = getenv("LSB_BIND_CPU_LIST");
if ( result )
{
v3 = result;
result = (const char *)strlen(result);
if ( result )
{
v8 = v7;
v4 = alloca((signed __int64)result);
strcpy(delim, ",");
strncpy(v7, v3, (size_t)result);
result = strtok(v7, delim);
for ( i = result; result; i = result )
{
a1 += 4LL;
v6 = (unsigned int)atoi(i);
fprintf(stderr, "cpu #%d\n", v6);
*(_DWORD *)(a1 - 4) = v6;
result = strtok(0LL, delim);
}
}
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func6(__int64 a1)
{
const char *result; // rax
const char *v3; // r12
void *v4; // rsp
const char *i; // rdi
__int64 v6; // r15
char v7[8]; // [rsp+0h] [rbp-50h] BYREF
char *v8; // [rsp+8h] [rbp-48h]
char delim[2]; // [rsp+1Eh] [rbp-32h] BYREF

result = getenv("LSB_BIND_CPU_LIST");
if ( result )
{
v3 = result;
result = (const char *)strlen(result);
if ( result )
{
v8 = v7;
v4 = alloca((signed __int64)result);
strcpy(delim, ",");
strncpy(v7, v3, (size_t)result);
result = strtok(v7, delim);
for ( i = result; result; i = result )
{
a1 += 4LL;
v6 = (unsigned int)atoi(i);
fprintf(stderr, "cpu #%d\n", v6);
*(_DWORD *)(a1 - 4) = v6;
result = strtok(0LL, delim);
}
}
}
return result;
}

original_code:
void get_logical_allowed_CPUs(int *logical_allowed)
{
        char *env_cpu_list;
        int ncpus = 0;
        if ((env_cpu_list = getenv("LSB_BIND_CPU_LIST")) != ((void *)0)) {
                size_t len;
                len = strlen(env_cpu_list);
                if(len) {
                        char buffer[len];
                        char *token;
                        int cpu;
                        const char delim[2] = ",\0";
                        if (strncpy(buffer, env_cpu_list, len) == ((void *)0))
                                return 0;
                        token = buffer;
                        for (token = strtok(buffer, delim);
                                token != ((void *)0);
                                token = strtok(((void *)0), delim)) {
                                        cpu = atoi(token);
                                        fprintf(stderr, "cpu #%d\n",cpu);
                                        logical_allowed[ncpus] = cpu;
                                        ncpus++;
                        }
                        return ncpus;
                }
        }
        return 0;
}

canonical_original_code:
void get_logical_allowed_CPUs(int *logical_allowed)
{
        char *env_cpu_list;
        int ncpus = 0;
        if ((env_cpu_list = getenv("LSB_BIND_CPU_LIST")) != ((void *)0)) {
                unsigned long len;
                len = strlen(env_cpu_list);
                if(len) {
                        char buffer[-1];
                        char *token;
                        int cpu;
                        char delim[2] = ",\0";
                        if (strncpy(buffer, env_cpu_list, len) == ((void *)0))
                                return 0;
                        token = buffer;
                        for (token = strtok(buffer, delim);
                                token != ((void *)0);
                                token = strtok(((void *)0), delim)) {
                                        cpu = atoi(token);
                                        fprintf(stderr, "cpu #%d\n",cpu);
                                        logical_allowed[ncpus] = cpu;
                                        ncpus++;
                        }
                        return ncpus;
                }
        }
        return 0;
}

variable_types: ncpus int

variable_types:
len
unsigned long

variable_types:
buffer
char [-1]

variable_types:
token
char *

variable_types: cpu int

variable_types:
delim
char [2]


decompiled_code:
__int64 __fastcall get_allowed_CPUs(_QWORD *a1)
{
unsigned int v1; // er12
char *v3; // rax
const char *v4; // r13
size_t v5; // rax
void *v7; // rsp
char *i; // rdi
int v9; // eax
char v10[14]; // [rsp+0h] [rbp-40h] BYREF
char delim[2]; // [rsp+Eh] [rbp-32h] BYREF

v1 = 0;
v3 = getenv("LSB_BIND_CPU_LIST");
if ( v3 )
{
v4 = v3;
v5 = strlen(v3);
if ( v5 )
{
v7 = alloca(v5);
strcpy(delim, ",");
strncpy(v10, v4, v5);
*a1 = 0LL;
a1[15] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 128) >> 3));
for ( i = strtok(v10, delim); i; i = strtok(0LL, delim) )
{
v9 = atoi(i);
if ( (unsigned __int64)v9 <= 0x3FF )
a1[(unsigned __int64)v9 >> 6] |= 1LL << v9;
++v1;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
unsigned int v1; // er12
char *v3; // rax
const char *v4; // r13
size_t v5; // rax
void *v7; // rsp
char *i; // rdi
int v9; // eax
char v10[14]; // [rsp+0h] [rbp-40h] BYREF
char delim[2]; // [rsp+Eh] [rbp-32h] BYREF

v1 = 0;
v3 = getenv("LSB_BIND_CPU_LIST");
if ( v3 )
{
v4 = v3;
v5 = strlen(v3);
if ( v5 )
{
v7 = alloca(v5);
strcpy(delim, ",");
strncpy(v10, v4, v5);
*a1 = 0LL;
a1[15] = 0LL;
memset(
(void *)((unsigned __int64)(a1 + 1) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a1 - (((_DWORD)a1 + 8) & 0xFFFFFFF8) + 128) >> 3));
for ( i = strtok(v10, delim); i; i = strtok(0LL, delim) )
{
v9 = atoi(i);
if ( (unsigned __int64)v9 <= 0x3FF )
a1[(unsigned __int64)v9 >> 6] |= 1LL << v9;
++v1;
}
}
}
return v1;
}

original_code:
int get_allowed_CPUs(cpu_set_t *allowed) {
 char *env_cpu_list;
        int ncpus = 0;
 if ((env_cpu_list = getenv("LSB_BIND_CPU_LIST")) != ((void *)0)) {
  size_t len;
  len = strlen(env_cpu_list);
  if(len) {
   char buffer[len];
   char *token;
   int cpu;
   const char delim[2] = ",\0";
   if (strncpy(buffer, env_cpu_list, len) == ((void *)0))
    return 0;
   do __builtin_memset (allowed, '\0', sizeof (cpu_set_t)); while (0);
   token = buffer;
   for (token = strtok(buffer, delim);
    token != ((void *)0);
    token = strtok(((void *)0), delim)) {
     cpu = atoi(token);
     (__extension__ ({ size_t __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((allowed)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
     ncpus++;
   }
   return ncpus;
  }
 }
 return 0;
}

canonical_original_code:
int get_allowed_CPUs(struct cpu_set_t *allowed) {
 char *env_cpu_list;
        int ncpus = 0;
 if ((env_cpu_list = getenv("LSB_BIND_CPU_LIST")) != ((void *)0)) {
  unsigned long len;
  len = strlen(env_cpu_list);
  if(len) {
   char buffer[-1];
   char *token;
   int cpu;
   char delim[2] = ",\0";
   if (strncpy(buffer, env_cpu_list, len) == ((void *)0))
    return 0;
   do __builtin_memset (allowed, '\0', sizeof (cpu_set_t)); while (0);
   token = buffer;
   for (token = strtok(buffer, delim);
    token != ((void *)0);
    token = strtok(((void *)0), delim)) {
     cpu = atoi(token);
     (__extension__ ({ unsigned long __cpu = (cpu); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((allowed)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
     ncpus++;
   }
   return ncpus;
  }
 }
 return 0;
}

variable_types: struct cpu_set_t { unsigned long __bits[-1]; } *

return_type: int


decompiled_code:
_BOOL8 __fastcall have_full_node(int a1)
{
char *v1; // rax
const char *v2; // r12
char *v3; // rsi
char *v4; // rax
const char *v5; // r12
size_t v6; // rdx
void *v7; // rsp
char *v8; // rax
__int64 v9; // r12
char v11[32]; // [rsp+0h] [rbp-20h] BYREF

v1 = getenv("LSB_MCPU_HOSTS");
if ( !v1 )
return 0LL;
v2 = v1;
v3 = getenv("HOSTNAME");
if ( !v3 )
return 0LL;
v4 = strstr(v2, v3);
v5 = v4;
if ( !v4 )
return 0LL;
v6 = (int)strlen(v4);
v7 = alloca(v6);
strncpy(v11, v5, v6);
strtok(v11, " ");
v8 = strtok(0LL, " ");
v9 = (unsigned int)atoi(v8);
fprintf(stderr, "Allocation of %d CPUs.\n", v9);
return (_DWORD)v9 == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1)
{
char *v1; // rax
const char *v2; // r12
char *v3; // rsi
char *v4; // rax
const char *v5; // r12
size_t v6; // rdx
void *v7; // rsp
char *v8; // rax
__int64 v9; // r12
char v11[32]; // [rsp+0h] [rbp-20h] BYREF

v1 = getenv("LSB_MCPU_HOSTS");
if ( !v1 )
return 0LL;
v2 = v1;
v3 = getenv("HOSTNAME");
if ( !v3 )
return 0LL;
v4 = strstr(v2, v3);
v5 = v4;
if ( !v4 )
return 0LL;
v6 = (int)strlen(v4);
v7 = alloca(v6);
strncpy(v11, v5, v6);
strtok(v11, " ");
v8 = strtok(0LL, " ");
v9 = (unsigned int)atoi(v8);
fprintf(stderr, "Allocation of %d CPUs.\n", v9);
return (_DWORD)v9 == a1;
}

original_code:
int have_full_node(int n_cpus) {
 char *alloc_str;
 char *my_host_name;
 char *loc;
 int len, a_cpus;
 if ((alloc_str = getenv("LSB_MCPU_HOSTS")) == ((void *)0))
  return 0;
 if ((my_host_name = getenv("HOSTNAME")) == ((void *)0))
  return 0;
 if ((loc = strstr(alloc_str, my_host_name)) == ((void *)0))
  return 0;
 len = (int) strlen(loc);
 {
  char buffer[len];
  char *token;
  if (strncpy (buffer, loc, len) == ((void *)0))
   return 0;
  token = strtok(buffer, " \0");
  token = strtok(((void *)0), " \0");
  a_cpus = atoi(token);
  fprintf(stderr, "Allocation of %d CPUs.\n", a_cpus);
  return (a_cpus == n_cpus);
 }
 return 0;
}

canonical_original_code:
int have_full_node(int n_cpus) {
 char *alloc_str;
 char *my_host_name;
 char *loc;
 int len; int a_cpus;
 if ((alloc_str = getenv("LSB_MCPU_HOSTS")) == ((void *)0))
  return 0;
 if ((my_host_name = getenv("HOSTNAME")) == ((void *)0))
  return 0;
 if ((loc = strstr(alloc_str, my_host_name)) == ((void *)0))
  return 0;
 len = (int) strlen(loc);
 {
  char buffer[-1];
  char *token;
  if (strncpy (buffer, loc, len) == ((void *)0))
   return 0;
  token = strtok(buffer, " \0");
  token = strtok(((void *)0), " \0");
  a_cpus = atoi(token);
  fprintf(stderr, "Allocation of %d CPUs.\n", a_cpus);
  return (a_cpus == n_cpus);
 }
 return 0;
}

variable_types:
loc
char *

variable_types: len int


decompiled_code:
__int64 __fastcall numa_sched_setaffinity(unsigned int a1, __int64 a2)
{
int v2; // er14
unsigned __int64 v3; // rax
_QWORD *v4; // r9
__int64 v5; // rdx
__int64 i; // rax
char *v7; // r8
__int64 result; // rax
__int64 (__fastcall *v9)(_QWORD, __int64, __int64 *); // rax
void *v10; // rax
_QWORD v11[16384]; // [rsp+0h] [rbp-60038h] BYREF
_QWORD s2[16384]; // [rsp+20000h] [rbp-40038h] BYREF
__int64 v13[16391]; // [rsp+40000h] [rbp-20038h] BYREF

v2 = sysconf(83);
fprintf(stderr, "There are %d CPUs.\n", (unsigned int)v2);
if ( (int)get_allowed_CPUs(s2) > 0 )
{
v3 = 0LL;
memset(v13, 0, 0x80uLL);
if ( v2 <= 0 )
{
v5 = 0LL;
}
else
{
v4 = *(_QWORD **)(a2 + 8);
while ( 1 )
{
if ( (*v4 & (1LL << v3)) != 0 && v3 <= 0x3FF )
v13[v3 >> 6] |= 1LL << v3;
if ( v3 == v2 - 1 )
break;
++v3;
}
v5 = v13[0];
}
for ( i = 0LL; ; v5 = v13[i] )
{
v11[i] = s2[i] | v5;
if ( ++i == 16 )
break;
}
if ( memcmp(v11, s2, 0x80uLL) )
goto LABEL_14;
LABEL_17:
v9 = (__int64 (__fastcall *)(_QWORD, __int64, __int64 *))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
return v9(a1, 0x20000LL, v13);
}
if ( (unsigned int)have_full_node((unsigned int)v2) )
goto LABEL_17;
LABEL_14:
v7 = getenv("AFFINITY_NO_COMPLAIN");
result = 0LL;
if ( !v7 )
{
fwrite("Using cores from cpuset.\n", 1uLL, 0x19uLL, stderr);
v10 = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
result = ((__int64 (__fastcall *)(_QWORD, __int64, _QWORD *))v10)(a1, 0x20000LL, s2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, __int64 a2)
{
int v2; // er14
unsigned __int64 v3; // rax
_QWORD *v4; // r9
__int64 v5; // rdx
__int64 i; // rax
char *v7; // r8
__int64 result; // rax
__int64 (__fastcall *v9)(_QWORD, __int64, __int64 *); // rax
void *v10; // rax
_QWORD v11[16384]; // [rsp+0h] [rbp-60038h] BYREF
_QWORD s2[16384]; // [rsp+20000h] [rbp-40038h] BYREF
__int64 v13[16391]; // [rsp+40000h] [rbp-20038h] BYREF

v2 = sysconf(83);
fprintf(stderr, "There are %d CPUs.\n", (unsigned int)v2);
if ( (int)func7(s2) > 0 )
{
v3 = 0LL;
memset(v13, 0, 0x80uLL);
if ( v2 <= 0 )
{
v5 = 0LL;
}
else
{
v4 = *(_QWORD **)(a2 + 8);
while ( 1 )
{
if ( (*v4 & (1LL << v3)) != 0 && v3 <= 0x3FF )
v13[v3 >> 6] |= 1LL << v3;
if ( v3 == v2 - 1 )
break;
++v3;
}
v5 = v13[0];
}
for ( i = 0LL; ; v5 = v13[i] )
{
v11[i] = s2[i] | v5;
if ( ++i == 16 )
break;
}
if ( memcmp(v11, s2, 0x80uLL) )
goto LABEL_14;
LABEL_17:
v9 = (__int64 (__fastcall *)(_QWORD, __int64, __int64 *))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
return v9(a1, 0x20000LL, v13);
}
if ( (unsigned int)func8((unsigned int)v2) )
goto LABEL_17;
LABEL_14:
v7 = getenv("AFFINITY_NO_COMPLAIN");
result = 0LL;
if ( !v7 )
{
fwrite("Using cores from cpuset.\n", 1uLL, 0x19uLL, stderr);
v10 = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
result = ((__int64 (__fastcall *)(_QWORD, __int64, _QWORD *))v10)(a1, 0x20000LL, s2);
}
return result;
}

original_code:
int numa_sched_setaffinity(pid_t pid, struct bitmask *mask) {
 cpu_set_t requested_mask[1024], allowed_mask[1024], lnuma_mask[1024];
        static void * (*real_function)();
        int n_cpus;
        int allow_change;
        n_cpus = (int) sysconf(_SC_NPROCESSORS_CONF);
        fprintf(stderr, "There are %d CPUs.\n", n_cpus);
        allow_change = 0;
        if (get_allowed_CPUs(allowed_mask)>0) {
                int bit;
                do __builtin_memset (lnuma_mask, '\0', sizeof (cpu_set_t)); while (0);
                for (bit = 0; bit < n_cpus; bit++)
                 if(((1L << bit) & *(mask->maskp)) != 0 )
                     (__extension__ ({ size_t __cpu = (bit); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((lnuma_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
                (__extension__ ({ cpu_set_t *__dest = (requested_mask); const __cpu_mask *__arr1 = (lnuma_mask)->__bits; const __cpu_mask *__arr2 = (allowed_mask)->__bits; size_t __imax = (sizeof (cpu_set_t)) / sizeof (__cpu_mask); size_t __i; for (__i = 0; __i < __imax; ++__i) ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] | __arr2[__i]; __dest; }));
  allow_change = (__builtin_memcmp (requested_mask, allowed_mask, sizeof (cpu_set_t)) == 0);
        } else {
                allow_change = have_full_node(n_cpus);
        }
        if (allow_change) {
                real_function = (void *(*) ()) dlsym(((void *) -1l), "sched_setaffinity");
                return (int) real_function(pid, sizeof(lnuma_mask),lnuma_mask);
        } else {
                char *env_var;
                if ((env_var = getenv("AFFINITY_NO_COMPLAIN")))
                        return 0;
  else{
   fprintf(stderr, "Using cores from cpuset.\n");
   real_function = (void *(*) ()) dlsym(((void *) -1l), "sched_setaffinity");
                 return (int) real_function(pid, sizeof(allowed_mask),allowed_mask);
  }
        }
}

canonical_original_code:
int numa_sched_setaffinity(int pid, struct bitmask *mask) {
 struct cpu_set_t requested_mask[1024]; struct cpu_set_t allowed_mask[1024]; struct cpu_set_t lnuma_mask[1024];
        static void *(*real_function)();
        int n_cpus;
        int allow_change;
        n_cpus = (int) sysconf(_SC_NPROCESSORS_CONF);
        fprintf(stderr, "There are %d CPUs.\n", n_cpus);
        allow_change = 0;
        if (get_allowed_CPUs(allowed_mask)>0) {
                int bit;
                do __builtin_memset (lnuma_mask, '\0', sizeof (cpu_set_t)); while (0);
                for (bit = 0; bit < n_cpus; bit++)
                 if(((1L << bit) & *(mask->maskp)) != 0 )
                     (__extension__ ({ unsigned long __cpu = (bit); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((lnuma_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
                (__extension__ ({ struct cpu_set_t *__dest = (requested_mask); unsigned long *__arr1 = (lnuma_mask)->__bits; unsigned long *__arr2 = (allowed_mask)->__bits; unsigned long __imax = (sizeof (cpu_set_t)) / sizeof (__cpu_mask); unsigned long __i; for (__i = 0; __i < __imax; ++__i) ((unsigned long *) __dest->__bits)[__i] = __arr1[__i] | __arr2[__i]; __dest; }));
  allow_change = (__builtin_memcmp (requested_mask, allowed_mask, sizeof (cpu_set_t)) == 0);
        } else {
                allow_change = have_full_node(n_cpus);
        }
        if (allow_change) {
                real_function = (void *(*)()) dlsym(((void *) -1l), "sched_setaffinity");
                return (int) real_function(pid, sizeof(lnuma_mask),lnuma_mask);
        } else {
                char *env_var;
                if ((env_var = getenv("AFFINITY_NO_COMPLAIN")))
                        return 0;
  else{
   fprintf(stderr, "Using cores from cpuset.\n");
   real_function = (void *(*)()) dlsym(((void *) -1l), "sched_setaffinity");
                 return (int) real_function(pid, sizeof(allowed_mask),allowed_mask);
  }
        }
}

variable_types: pid int

variable_types: struct bitmask { unsigned long size; unsigned long *maskp; } *

variable_types: struct cpu_set_t { unsigned long __bits[-1]; } [1024]

variable_types: bit int


decompiled_code:
__int64 __fastcall sched_setaffinity(unsigned int a1, __int64 a2, __int64 a3)
{
int v5; // ebp
int v6; // ebx
__int64 v7; // rax
char *v8; // r8
__int64 result; // rax
__int64 (__fastcall *v10)(_QWORD, __int64, __int64); // rax
char *v11; // r13
int *v12; // r14
int v13; // edx
__int64 i; // rcx
__int64 v15; // rsi
__int64 v16; // rsi
char *v17; // rcx
unsigned __int64 v18; // rax
__int64 v19; // rcx
unsigned __int64 v20; // rdi
void *v21; // rax
_QWORD s1[16384]; // [rsp+10h] [rbp-60038h] BYREF
_QWORD s2[16384]; // [rsp+20010h] [rbp-40038h] BYREF
_QWORD v24[16391]; // [rsp+40010h] [rbp-20038h] BYREF

v5 = sysconf(83);
fprintf(stderr, "There are %d CPUs.\n", (unsigned int)v5);
v6 = get_allowed_CPUs(s2);
v7 = 0LL;
memset(s1, 0, 0x80uLL);
if ( v6 <= 0 )
{
if ( !(unsigned int)have_full_node((unsigned int)v5) )
goto LABEL_4;
LABEL_7:
fwrite("Change allowed.\n", 1uLL, 0x10uLL, stderr);
v10 = (__int64 (__fastcall *)(_QWORD, __int64, __int64))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
return v10(a1, a2, a3);
}
do
{
s1[v7] = s2[v7] | *(_QWORD *)(a3 + 8 * v7);
++v7;
}
while ( v7 != 16 );
if ( !memcmp(s1, s2, 0x80uLL) )
goto LABEL_7;
LABEL_4:
v8 = getenv("AFFINITY_NO_COMPLAIN");
result = 0LL;
if ( !v8 )
{
fwrite("Shuffling.\n", 1uLL, 0xBuLL, stderr);
v11 = (char *)malloc(4LL * v5);
memset(v11, -1, 4LL * v5);
v12 = (int *)calloc(v6, 4uLL);
get_logical_allowed_CPUs(v12);
v13 = v6;
if ( v6 > 0 )
{
for ( i = 0LL; i != v6; ++i )
{
v15 = v12[i];
*(_DWORD *)&v11[4 * v15] = v15;
if ( (int)v15 > v13 )
v13 = i;
}
}
if ( v5 <= 0 )
{
memset(v24, 0, 0x80uLL);
}
else
{
v16 = (unsigned int)(v5 - 1);
v17 = v11;
do
{
if ( *(_DWORD *)v17 == -1 )
{
*(_DWORD *)v17 = v12[v13];
v13 = (v13 + 1) % v6;
}
v17 += 4;
}
while ( &v11[4 * v16 + 4] != v17 );
v18 = 0LL;
memset(v24, 0, 0x80uLL);
while ( 1 )
{
if ( v18 <= 0x3FF )
{
v19 = *(_QWORD *)(a3 + 8 * (v18 >> 6));
if ( _bittest64(&v19, v18) )
{
v20 = *(int *)&v11[4 * v18];
if ( v20 <= 0x3FF )
v24[v20 >> 6] |= 1LL << *(_DWORD *)&v11[4 * v18];
}
}
if ( v16 == v18 )
break;
++v18;
}
}
free(v11);
free(v12);
v21 = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
result = ((__int64 (__fastcall *)(_QWORD, __int64, _QWORD *))v21)(a1, 0x20000LL, v24);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, __int64 a2, __int64 a3)
{
int v5; // ebp
int v6; // ebx
__int64 v7; // rax
char *v8; // r8
__int64 result; // rax
__int64 (__fastcall *v10)(_QWORD, __int64, __int64); // rax
char *v11; // r13
int *v12; // r14
int v13; // edx
__int64 i; // rcx
__int64 v15; // rsi
__int64 v16; // rsi
char *v17; // rcx
unsigned __int64 v18; // rax
__int64 v19; // rcx
unsigned __int64 v20; // rdi
void *v21; // rax
_QWORD s1[16384]; // [rsp+10h] [rbp-60038h] BYREF
_QWORD s2[16384]; // [rsp+20010h] [rbp-40038h] BYREF
_QWORD v24[16391]; // [rsp+40010h] [rbp-20038h] BYREF

v5 = sysconf(83);
fprintf(stderr, "There are %d CPUs.\n", (unsigned int)v5);
v6 = func7(s2);
v7 = 0LL;
memset(s1, 0, 0x80uLL);
if ( v6 <= 0 )
{
if ( !(unsigned int)func8((unsigned int)v5) )
goto LABEL_4;
LABEL_7:
fwrite("Change allowed.\n", 1uLL, 0x10uLL, stderr);
v10 = (__int64 (__fastcall *)(_QWORD, __int64, __int64))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
return v10(a1, a2, a3);
}
do
{
s1[v7] = s2[v7] | *(_QWORD *)(a3 + 8 * v7);
++v7;
}
while ( v7 != 16 );
if ( !memcmp(s1, s2, 0x80uLL) )
goto LABEL_7;
LABEL_4:
v8 = getenv("AFFINITY_NO_COMPLAIN");
result = 0LL;
if ( !v8 )
{
fwrite("Shuffling.\n", 1uLL, 0xBuLL, stderr);
v11 = (char *)malloc(4LL * v5);
memset(v11, -1, 4LL * v5);
v12 = (int *)calloc(v6, 4uLL);
func6(v12);
v13 = v6;
if ( v6 > 0 )
{
for ( i = 0LL; i != v6; ++i )
{
v15 = v12[i];
*(_DWORD *)&v11[4 * v15] = v15;
if ( (int)v15 > v13 )
v13 = i;
}
}
if ( v5 <= 0 )
{
memset(v24, 0, 0x80uLL);
}
else
{
v16 = (unsigned int)(v5 - 1);
v17 = v11;
do
{
if ( *(_DWORD *)v17 == -1 )
{
*(_DWORD *)v17 = v12[v13];
v13 = (v13 + 1) % v6;
}
v17 += 4;
}
while ( &v11[4 * v16 + 4] != v17 );
v18 = 0LL;
memset(v24, 0, 0x80uLL);
while ( 1 )
{
if ( v18 <= 0x3FF )
{
v19 = *(_QWORD *)(a3 + 8 * (v18 >> 6));
if ( _bittest64(&v19, v18) )
{
v20 = *(int *)&v11[4 * v18];
if ( v20 <= 0x3FF )
v24[v20 >> 6] |= 1LL << *(_DWORD *)&v11[4 * v18];
}
}
if ( v16 == v18 )
break;
++v18;
}
}
free(v11);
free(v12);
v21 = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
result = ((__int64 (__fastcall *)(_QWORD, __int64, _QWORD *))v21)(a1, 0x20000LL, v24);
}
return result;
}

original_code:
int sched_setaffinity(pid_t pid, size_t cpusetsize, const cpu_set_t *mask) {
 cpu_set_t requested_mask[1024], allowed_mask[1024], used_mask[1024];
 static void * (*real_function)();
 int n_cpus,c_cpus;
 int allow_change;
 int *mapp_allowed_cpus,*l_allowed_mask;
 n_cpus = (int) sysconf(_SC_NPROCESSORS_CONF);
 fprintf(stderr, "There are %d CPUs.\n", n_cpus);
 allow_change = 0;
        c_cpus = get_allowed_CPUs(allowed_mask);
 do __builtin_memset (requested_mask, '\0', sizeof (cpu_set_t)); while (0);
 if (c_cpus > 0) {
  (__extension__ ({ cpu_set_t *__dest = (requested_mask); const __cpu_mask *__arr1 = (mask)->__bits; const __cpu_mask *__arr2 = (allowed_mask)->__bits; size_t __imax = (sizeof (cpu_set_t)) / sizeof (__cpu_mask); size_t __i; for (__i = 0; __i < __imax; ++__i) ((__cpu_mask *) __dest->__bits)[__i] = __arr1[__i] | __arr2[__i]; __dest; }));
  allow_change = (__builtin_memcmp (requested_mask, allowed_mask, sizeof (cpu_set_t)) == 0);
 } else {
  allow_change = have_full_node(n_cpus);
 }
 if (allow_change) {
  fprintf(stderr, "Change allowed.\n");
  real_function = (void *(*) ()) dlsym(((void *) -1l), "sched_setaffinity");
  return (int) real_function(pid, cpusetsize, mask);
 } else {
  char *env_var;
  if ((env_var = getenv("AFFINITY_NO_COMPLAIN")))
   return 0;
                else{
   int p,greater,bit;
   fprintf(stderr, "Shuffling.\n");
   mapp_allowed_cpus = malloc(n_cpus*sizeof(int));
   memset (mapp_allowed_cpus, -1, n_cpus*sizeof (int) );
   l_allowed_mask = calloc(c_cpus,sizeof(int));
   get_logical_allowed_CPUs(l_allowed_mask);
   greater = c_cpus;
   for(p=0; p < c_cpus; p++)
   {
    mapp_allowed_cpus[l_allowed_mask[p]] = l_allowed_mask[p];
    if(l_allowed_mask[p] > greater)
     greater = p;
   }
   int index = greater;
   for(p=0; p < n_cpus; p++)
    if(mapp_allowed_cpus[p] == -1)
    {
     mapp_allowed_cpus[p] = l_allowed_mask[index];
     index = (index+1) % c_cpus;
    }
   do __builtin_memset (used_mask, '\0', sizeof (cpu_set_t)); while (0);
   for (bit=0;bit<n_cpus;bit++)
    if((__extension__ ({ size_t __cpu = (bit); __cpu / 8 < (sizeof (cpu_set_t)) ? ((((const __cpu_mask *) ((mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] & ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask)))))) != 0 : 0; }))){
     (__extension__ ({ size_t __cpu = (mapp_allowed_cpus[bit]); __cpu / 8 < (sizeof (cpu_set_t)) ? (((__cpu_mask *) ((used_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((__cpu_mask) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
   }
   free(mapp_allowed_cpus);
   free(l_allowed_mask);
                        real_function = (void *(*) ()) dlsym(((void *) -1l), "sched_setaffinity");
                        return (int) real_function(pid, sizeof(used_mask), used_mask);
                }
 }
}

canonical_original_code:
int sched_setaffinity(int pid, unsigned long cpusetsize, struct cpu_set_t *mask) {
 struct cpu_set_t requested_mask[1024]; struct cpu_set_t allowed_mask[1024]; struct cpu_set_t used_mask[1024];
 static void *(*real_function)();
 int n_cpus; int c_cpus;
 int allow_change;
 int *mapp_allowed_cpus; int *l_allowed_mask;
 n_cpus = (int) sysconf(_SC_NPROCESSORS_CONF);
 fprintf(stderr, "There are %d CPUs.\n", n_cpus);
 allow_change = 0;
        c_cpus = get_allowed_CPUs(allowed_mask);
 do __builtin_memset (requested_mask, '\0', sizeof (cpu_set_t)); while (0);
 if (c_cpus > 0) {
  (__extension__ ({ struct cpu_set_t *__dest = (requested_mask); unsigned long *__arr1 = (mask)->__bits; unsigned long *__arr2 = (allowed_mask)->__bits; unsigned long __imax = (sizeof (cpu_set_t)) / sizeof (__cpu_mask); unsigned long __i; for (__i = 0; __i < __imax; ++__i) ((unsigned long *) __dest->__bits)[__i] = __arr1[__i] | __arr2[__i]; __dest; }));
  allow_change = (__builtin_memcmp (requested_mask, allowed_mask, sizeof (cpu_set_t)) == 0);
 } else {
  allow_change = have_full_node(n_cpus);
 }
 if (allow_change) {
  fprintf(stderr, "Change allowed.\n");
  real_function = (void *(*)()) dlsym(((void *) -1l), "sched_setaffinity");
  return (int) real_function(pid, cpusetsize, mask);
 } else {
  char *env_var;
  if ((env_var = getenv("AFFINITY_NO_COMPLAIN")))
   return 0;
                else{
   int p; int greater; int bit;
   fprintf(stderr, "Shuffling.\n");
   mapp_allowed_cpus = malloc(n_cpus*sizeof(int));
   memset (mapp_allowed_cpus, -1, n_cpus*sizeof (int) );
   l_allowed_mask = calloc(c_cpus,sizeof(int));
   get_logical_allowed_CPUs(l_allowed_mask);
   greater = c_cpus;
   for(p=0; p < c_cpus; p++)
   {
    mapp_allowed_cpus[l_allowed_mask[p]] = l_allowed_mask[p];
    if(l_allowed_mask[p] > greater)
     greater = p;
   }
   int index = greater;
   for(p=0; p < n_cpus; p++)
    if(mapp_allowed_cpus[p] == -1)
    {
     mapp_allowed_cpus[p] = l_allowed_mask[index];
     index = (index+1) % c_cpus;
    }
   do __builtin_memset (used_mask, '\0', sizeof (cpu_set_t)); while (0);
   for (bit=0;bit<n_cpus;bit++)
    if((__extension__ ({ unsigned long __cpu = (bit); __cpu / 8 < (sizeof (cpu_set_t)) ? ((((unsigned long *) ((mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] & ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask)))))) != 0 : 0; }))){
     (__extension__ ({ unsigned long __cpu = (mapp_allowed_cpus[bit]); __cpu / 8 < (sizeof (cpu_set_t)) ? (((unsigned long *) ((used_mask)->__bits))[((__cpu) / (8 * sizeof (__cpu_mask)))] |= ((unsigned long) 1 << ((__cpu) % (8 * sizeof (__cpu_mask))))) : 0; }));
   }
   free(mapp_allowed_cpus);
   free(l_allowed_mask);
                        real_function = (void *(*)()) dlsym(((void *) -1l), "sched_setaffinity");
                        return (int) real_function(pid, sizeof(used_mask), used_mask);
                }
 }
}

variable_types:
cpusetsize
unsigned long

variable_types: p int

variable_types: greater int

variable_types: index int

user_defined_types: struct cpu_set_t { unsigned long __bits[-1]; }


repo: poyannabati/charlando

decompiled_code:
int sigchld_handler()
{
int *v0; // rax

do
{
LODWORD(v0) = waitpid(-1, 0LL, 1);
if ( !(_DWORD)v0 )
break;
v0 = __errno_location();
}
while ( *v0 != 10 );
return (int)v0;
}

canonical_decompiled_code:
int func7()
{
int *v0; // rax

do
{
LODWORD(v0) = waitpid(-1, 0LL, 1);
if ( !(_DWORD)v0 )
break;
v0 = __errno_location();
}
while ( *v0 != 10 );
return (int)v0;
}

original_code:
void sigchld_handler(int status) {
 while (waitpid(-1, ((void *)0), 1) != 0) {
  if ((*__errno_location ()) == 10) {
   break;
  }
 }
}

variable_types: status int


decompiled_code:
__int64 process_mq_child()
{
const char *v0; // rbx
__int64 result; // rax

mq_notify();
v0 = (const char *)calloc(0x2000uLL, 1uLL);
while ( 1 )
{
result = mq_receive();
if ( result < 0 )
break;
fprintf(stderr, "R:%s\n", v0);
if ( write(accepted_socket, v0, 0x2000uLL) == -1 )
fprintf(stderr, "No write%s\n", v0);
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
const char *v0; // rbx
__int64 result; // rax

mq_notify();
v0 = (const char *)calloc(0x2000uLL, 1uLL);
while ( 1 )
{
result = mq_receive();
if ( result < 0 )
break;
fprintf(stderr, "R:%s\n", v0);
if ( write(accepted_socket, v0, 0x2000uLL) == -1 )
fprintf(stderr, "No write%s\n", v0);
}
return result;
}

original_code:
void process_mq_child() {
 struct sigevent sev;
 sev.sigev_notify = SIGEV_SIGNAL;
 sev.sigev_signo = 10;
 mq_notify(incoming, &sev);
 char *msg = malloc(8192);
 memset(msg, 0, 8192);
 while (mq_receive(incoming, msg, 8192, 0) >= 0) {
  fprintf(stderr, "R:%s\n", msg);
  if (write(accepted_socket, msg, 8192) == -1) {
   fprintf(stderr, "No write%s\n", msg);
  }
 }
}

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

variable_types:
msg
char *

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }


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

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

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

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

original_code:
LinkedList *ll_init() {
 LinkedList *ll = malloc(sizeof(LinkedList));
 ll->head = ((void *)0);
 ll->tail = ((void *)0);
 ll->cur = ((void *)0);
 return ll;
}

canonical_original_code:
struct LinkedList *ll_init() {
 struct LinkedList *ll = malloc(sizeof(LinkedList));
 ll->head = ((void *)0);
 ll->tail = ((void *)0);
 ll->cur = ((void *)0);
 return ll;
}

variable_types: struct LinkedList { struct Node { struct Node *next; void *data; unsigned long length; } *head; struct Node *tail; struct Node *cur; } *

user_defined_types: struct LinkedList { struct Node *head; struct Node *tail; struct Node *cur; }


decompiled_code:
__int64 __fastcall ll_next(__int64 *a1)
{
__int64 *v1; // rax
__int64 result; // rax

v1 = (__int64 *)a1[2];
if ( !v1 )
v1 = a1;
result = *v1;
a1[2] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 *a1)
{
__int64 *v1; // rax
__int64 result; // rax

v1 = (__int64 *)a1[2];
if ( !v1 )
v1 = a1;
result = *v1;
a1[2] = result;
return result;
}

original_code:
Node *ll_next(LinkedList *ll) {
 if (ll->cur == ((void *)0)) {
  ll->cur = ll->head;
 } else {
  ll->cur = ll->cur->next;
 }
 return ll->cur;
}

canonical_original_code:
struct Node *ll_next(struct LinkedList *ll) {
 if (ll->cur == ((void *)0)) {
  ll->cur = ll->head;
 } else {
  ll->cur = ll->cur->next;
 }
 return ll->cur;
}

variable_types: struct LinkedList { struct Node *head; struct Node *tail; struct Node *cur; } *

return_type: struct Node { struct Node *next; void *data; unsigned long length; } *