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 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 draw_sky_random_cubes(double *a1, double a2)
{
int v3; // esi
double *v4; // rdi
int v5; // ecx
double *v6; // rax
int v7; // edx
double (**v8)(double, double); // rdx
double (**v9)(double, double); // rax
double v10; // xmm0_8
double v11; // xmm1_8
double v12; // xmm0_8
double v13; // xmm0_8
int v14; // eax
double v15; // r15
int v16; // eax
double v17; // xmm0_8
int v18; // eax
double v19; // xmm0_8
double v20; // r15
double v21; // xmm0_8
double v22; // xmm1_8
double v23; // xmm0_8
double v24; // xmm1_8
int i; // er13
double *v26; // r12
double v27; // xmm0_8
__int64 v28; // rax
double j; // xmm0_8
__int64 result; // rax
__int64 v31; // [rsp+8h] [rbp-88h]
double v32; // [rsp+10h] [rbp-80h]
int v33; // [rsp+1Ch] [rbp-74h]
double v34; // [rsp+28h] [rbp-68h]
double x; // [rsp+30h] [rbp-60h]
double v36; // [rsp+38h] [rbp-58h]
double v38; // [rsp+58h] [rbp-38h]

v3 = skycubeinit;
if ( !skycubeinit )
{
v4 = (double *)&skycubes;
v5 = skycubeinit;
do
{
v6 = v4;
v7 = v3;
do
{
*v6 = ((double)v5 - 15.0) * 600.0 / 30.0;
v6[1] = ((double)v7 - 15.0) * 600.0 / 30.0;
*((_QWORD *)v6 + 2) = LC19;
++v7;
v6 += 3;
}
while ( v7 != 30 );
++v5;
v4 += 90;
}
while ( v5 != 30 );
skycubeinit = 1;
}
v8 = (double (**)(double, double))&unk_DE0;
do
{
v9 = v8 - 90;
do
{
*v9 = (double (*)(double, double))LC19;
v9 += 3;
}
while ( v9 != v8 );
v8 += 90;
}
while ( v8 != &atan2 );
v10 = audioplayer_getTime(*((_QWORD *)a1 + 14));
v32 = (double)(int)SDL_GetTicks(v10) * 0.001;
v31 = 0LL;
v33 = 0;
do
{
v26 = (double *)((char *)&skycubes + v31);
for ( i = 0; i != 30; ++i )
{
game_loop_coord(a1, v26, v26 + 1);
v27 = atan2(
*(double *)(*(_QWORD *)a1 + 88LL)
+ (*(double *)(*(_QWORD *)a1 + 240LL) - *(double *)(*(_QWORD *)a1 + 88LL)) * 30.0
+ v26[1],
(*(double *)(*(_QWORD *)a1 + 232LL) - *(double *)(*(_QWORD *)a1 + 80LL)) * 30.0
+ *(double *)(*(_QWORD *)a1 + 80LL)
+ *v26);
v28 = *(_QWORD *)a1;
for ( j = v27 * 180.0 / 3.14159265359 + *(double *)(*(_QWORD *)a1 + 16LL); j <= 0.0; j = j + 360.0 )
;
for ( ; j > 360.0; j = j - 360.0 )
;
if ( j < 90.0 || j > 270.0 )
{
v11 = v26[1] + *(double *)(v28 + 88);
v12 = (*v26 + *(double *)(v28 + 80)) * (*v26 + *(double *)(v28 + 80)) + v11 * v11;
if ( v12 < 0.0 )
v13 = sqrt(v12);
else
v13 = sqrt(v12);
v36 = (double)i / 30.0;
v38 = v13 / 600.0;
v14 = SDL_GetTicks(v13 / 600.0);
v15 = cos((double)(6 * i) * 3.14159265359 / 30.0 + (double)v14 * 0.001);
v16 = SDL_GetTicks(v15);
v17 = cos((double)(12 * i) * 3.14159265359 / 30.0 - (double)v16 * 0.002) * 10.0;
v18 = SDL_GetTicks(v17);
v19 = v15 * -20.0 - v17 - 20.0 * cos((double)(8 * v33) * 3.14159265359 / 30.0 + (double)v18 * 0.001) + v26[2];
v26[2] = v19;
SDL_GetTicks(v19);
glPushMatrix();
v20 = a1[16];
x = (v38 + v38) * 3.14159265359;
v21 = cos(v20 * 0.001 + x);
glTranslated(*v26, v26[1], v26[2] - v38 * 200.0 + v21 * 20.0 * v20 + 40.0);
glScaled(16.66666666666667, 16.66666666666667, -80.0);
v34 = (double)v33 / 30.0 * 18.84955592154;
v22 = cos(18.84955592154 * v36 + v34 + v32 * 10.0 - 1.2 * *(double *)&t);
simple_cube_color((0.5 - v38 * 0.5) * a2 + 1.0 - a2 + (v22 * 0.3 + 0.3) * a2, 0.0, 0.0, 1.0 - a2, 0.0);
glPopMatrix();
glPushMatrix();
v23 = cos(x);
glTranslated(*v26, v26[1], v38 * 200.0 - v26[2] - v23 * 20.0 * a1[16] - 40.0);
glScaled(16.66666666666667, 16.66666666666667, 80.0);
v24 = cos(v36 * -18.84955592154 - v34 + v32 * 10.0 - 1.2 * *(double *)&t);
simple_cube_color((0.2 - v38 * 0.2) * a2 + 1.0 - a2 + (v24 * 0.2 + 0.2) * a2, 0.0, 0.0, 1.0 - a2, 0.0);
glPopMatrix();
}
v26 += 90;
}
result = (unsigned int)++v33;
v31 += 24LL;
}
while ( v33 != 30 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(double *a1, double a2)
{
int v3; // esi
double *v4; // rdi
int v5; // ecx
double *v6; // rax
int v7; // edx
double (**v8)(double, double); // rdx
double (**v9)(double, double); // rax
double v10; // xmm0_8
double v11; // xmm1_8
double v12; // xmm0_8
double v13; // xmm0_8
int v14; // eax
double v15; // r15
int v16; // eax
double v17; // xmm0_8
int v18; // eax
double v19; // xmm0_8
double v20; // r15
double v21; // xmm0_8
double v22; // xmm1_8
double v23; // xmm0_8
double v24; // xmm1_8
int i; // er13
double *v26; // r12
double v27; // xmm0_8
__int64 v28; // rax
double j; // xmm0_8
__int64 result; // rax
__int64 v31; // [rsp+8h] [rbp-88h]
double v32; // [rsp+10h] [rbp-80h]
int v33; // [rsp+1Ch] [rbp-74h]
double v34; // [rsp+28h] [rbp-68h]
double x; // [rsp+30h] [rbp-60h]
double v36; // [rsp+38h] [rbp-58h]
double v38; // [rsp+58h] [rbp-38h]

v3 = skycubeinit;
if ( !skycubeinit )
{
v4 = (double *)&skycubes;
v5 = skycubeinit;
do
{
v6 = v4;
v7 = v3;
do
{
*v6 = ((double)v5 - 15.0) * 600.0 / 30.0;
v6[1] = ((double)v7 - 15.0) * 600.0 / 30.0;
*((_QWORD *)v6 + 2) = LC19;
++v7;
v6 += 3;
}
while ( v7 != 30 );
++v5;
v4 += 90;
}
while ( v5 != 30 );
skycubeinit = 1;
}
v8 = (double (**)(double, double))&unk_DE0;
do
{
v9 = v8 - 90;
do
{
*v9 = (double (*)(double, double))LC19;
v9 += 3;
}
while ( v9 != v8 );
v8 += 90;
}
while ( v8 != &atan2 );
v10 = audioplayer_getTime(*((_QWORD *)a1 + 14));
v32 = (double)(int)SDL_GetTicks(v10) * 0.001;
v31 = 0LL;
v33 = 0;
do
{
v26 = (double *)((char *)&skycubes + v31);
for ( i = 0; i != 30; ++i )
{
game_loop_coord(a1, v26, v26 + 1);
v27 = atan2(
*(double *)(*(_QWORD *)a1 + 88LL)
+ (*(double *)(*(_QWORD *)a1 + 240LL) - *(double *)(*(_QWORD *)a1 + 88LL)) * 30.0
+ v26[1],
(*(double *)(*(_QWORD *)a1 + 232LL) - *(double *)(*(_QWORD *)a1 + 80LL)) * 30.0
+ *(double *)(*(_QWORD *)a1 + 80LL)
+ *v26);
v28 = *(_QWORD *)a1;
for ( j = v27 * 180.0 / 3.14159265359 + *(double *)(*(_QWORD *)a1 + 16LL); j <= 0.0; j = j + 360.0 )
;
for ( ; j > 360.0; j = j - 360.0 )
;
if ( j < 90.0 || j > 270.0 )
{
v11 = v26[1] + *(double *)(v28 + 88);
v12 = (*v26 + *(double *)(v28 + 80)) * (*v26 + *(double *)(v28 + 80)) + v11 * v11;
if ( v12 < 0.0 )
v13 = sqrt(v12);
else
v13 = sqrt(v12);
v36 = (double)i / 30.0;
v38 = v13 / 600.0;
v14 = SDL_GetTicks(v13 / 600.0);
v15 = cos((double)(6 * i) * 3.14159265359 / 30.0 + (double)v14 * 0.001);
v16 = SDL_GetTicks(v15);
v17 = cos((double)(12 * i) * 3.14159265359 / 30.0 - (double)v16 * 0.002) * 10.0;
v18 = SDL_GetTicks(v17);
v19 = v15 * -20.0 - v17 - 20.0 * cos((double)(8 * v33) * 3.14159265359 / 30.0 + (double)v18 * 0.001) + v26[2];
v26[2] = v19;
SDL_GetTicks(v19);
glPushMatrix();
v20 = a1[16];
x = (v38 + v38) * 3.14159265359;
v21 = cos(v20 * 0.001 + x);
glTranslated(*v26, v26[1], v26[2] - v38 * 200.0 + v21 * 20.0 * v20 + 40.0);
glScaled(16.66666666666667, 16.66666666666667, -80.0);
v34 = (double)v33 / 30.0 * 18.84955592154;
v22 = cos(18.84955592154 * v36 + v34 + v32 * 10.0 - 1.2 * *(double *)&t);
simple_cube_color((0.5 - v38 * 0.5) * a2 + 1.0 - a2 + (v22 * 0.3 + 0.3) * a2, 0.0, 0.0, 1.0 - a2, 0.0);
glPopMatrix();
glPushMatrix();
v23 = cos(x);
glTranslated(*v26, v26[1], v38 * 200.0 - v26[2] - v23 * 20.0 * a1[16] - 40.0);
glScaled(16.66666666666667, 16.66666666666667, 80.0);
v24 = cos(v36 * -18.84955592154 - v34 + v32 * 10.0 - 1.2 * *(double *)&t);
simple_cube_color((0.2 - v38 * 0.2) * a2 + 1.0 - a2 + (v24 * 0.2 + 0.2) * a2, 0.0, 0.0, 1.0 - a2, 0.0);
glPopMatrix();
}
v26 += 90;
}
result = (unsigned int)++v33;
v31 += 24LL;
}
while ( v33 != 30 );
return result;
}

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

variable_types: dissipation double

variable_types: i int

variable_types: j int

variable_types: ttt double

variable_types: x double

variable_types: y double

variable_types: alpha double

variable_types: xx double

variable_types: yy double

variable_types: dist double

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

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


repo: pousa/fake-affinity

decompiled_code:
const char *__fastcall get_logical_allowed_CPUs(_DWORD *a1)
{
const char *result; // rax
const char *v3; // r13
void *v4; // rsp
const char *i; // rdi
__int64 v6; // r14
char v7[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

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

canonical_decompiled_code:
const char *__fastcall func6(_DWORD *a1)
{
const char *result; // rax
const char *v3; // r13
void *v4; // rsp
const char *i; // rdi
__int64 v6; // r14
char v7[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

result = getenv("LSB_BIND_CPU_LIST");
if ( result )
{
v3 = result;
result = (const char *)strlen(result);
if ( result )
{
v4 = alloca((signed __int64)result);
strcpy(delim, ",");
strncpy(v7, v3, (size_t)result);
result = strtok(v7, delim);
for ( i = result; result; ++a1 )
{
v6 = (unsigned int)atoi(i);
fprintf(stderr, "cpu #%d\n", v6);
*a1 = v6;
result = strtok(0LL, delim);
i = result;
}
}
}
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)
{
char *v2; // rax
unsigned int v3; // ebx
const char *v4; // r13
size_t v5; // rax
void *v7; // rsp
char *v8; // rdi
int v9; // eax
char v10[14]; // [rsp+0h] [rbp-30h] BYREF
char delim[2]; // [rsp+Eh] [rbp-22h] BYREF

v2 = getenv("LSB_BIND_CPU_LIST");
v3 = 0;
if ( v2 )
{
v4 = v2;
v5 = strlen(v2);
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));
v8 = strtok(v10, delim);
if ( v8 )
{
do
{
v9 = atoi(v8);
if ( (unsigned __int64)v9 <= 0x3FF )
a1[(unsigned __int64)v9 >> 6] |= 1LL << v9;
++v3;
v8 = strtok(0LL, delim);
}
while ( v8 );
}
else
{
v3 = 0;
}
}
}
return v3;
}

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

v2 = getenv("LSB_BIND_CPU_LIST");
v3 = 0;
if ( v2 )
{
v4 = v2;
v5 = strlen(v2);
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));
v8 = strtok(v10, delim);
if ( v8 )
{
do
{
v9 = atoi(v8);
if ( (unsigned __int64)v9 <= 0x3FF )
a1[(unsigned __int64)v9 >> 6] |= 1LL << v9;
++v3;
v8 = strtok(0LL, delim);
}
while ( v8 );
}
else
{
v3 = 0;
}
}
}
return v3;
}

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; // rbx
_BOOL8 result; // rax
char *v3; // rsi
char *v4; // rbx
size_t v5; // rdx
void *v6; // rsp
char *v7; // rax
__int64 v8; // rbx
char v9[32]; // [rsp+0h] [rbp-20h] BYREF

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

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

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

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; // ebp
unsigned __int64 v3; // rax
_QWORD *v4; // r9
__int64 i; // rax
char *v6; // rdx
__int64 result; // rax
__int64 (__fastcall *v8)(_QWORD, __int64, __int64 *); // rax
void *v9; // rax
__int64 v10[16384]; // [rsp+0h] [rbp-60018h] BYREF
_QWORD s2[16384]; // [rsp+20000h] [rbp-40018h] BYREF
__int64 s1[16387]; // [rsp+40000h] [rbp-20018h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, __int64 a2)
{
int v2; // ebp
unsigned __int64 v3; // rax
_QWORD *v4; // r9
__int64 i; // rax
char *v6; // rdx
__int64 result; // rax
__int64 (__fastcall *v8)(_QWORD, __int64, __int64 *); // rax
void *v9; // rax
__int64 v10[16384]; // [rsp+0h] [rbp-60018h] BYREF
_QWORD s2[16384]; // [rsp+20000h] [rbp-40018h] BYREF
__int64 s1[16387]; // [rsp+40000h] [rbp-20018h] BYREF

v2 = sysconf(83);
fprintf(stderr, "There are %d CPUs.\n", (unsigned int)v2);
if ( (int)func7(s2) > 0 )
{
v3 = 0LL;
memset(v10, 0, 0x80uLL);
if ( v2 > 0 )
{
v4 = *(_QWORD **)(a2 + 8);
while ( 1 )
{
if ( (*v4 & (1LL << v3)) != 0 && v3 <= 0x3FF )
v10[v3 >> 6] |= 1LL << v3;
if ( v2 - 1 == v3 )
break;
++v3;
}
}
for ( i = 0LL; i != 16; ++i )
s1[i] = s2[i] | v10[i];
if ( memcmp(s1, s2, 0x80uLL) )
goto LABEL_12;
LABEL_15:
v8 = (__int64 (__fastcall *)(_QWORD, __int64, __int64 *))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
return v8(a1, 0x20000LL, v10);
}
if ( (unsigned int)func8((unsigned int)v2) )
goto LABEL_15;
LABEL_12:
v6 = getenv("AFFINITY_NO_COMPLAIN");
result = 0LL;
if ( !v6 )
{
fwrite("Using cores from cpuset.\n", 1uLL, 0x19uLL, stderr);
v9 = dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sched_setaffinity");
result = ((__int64 (__fastcall *)(_QWORD, __int64, _QWORD *))v9)(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 v4; // er12
int v5; // ebp
__int64 v6; // rax
char *v7; // rdx
__int64 result; // rax
__int64 (__fastcall *v9)(_QWORD, __int64, __int64); // rax
char *v10; // r14
_DWORD *v11; // r15
int v12; // edx
__int64 i; // rcx
int v14; // eax
char *v15; // rcx
__int64 v16; // rsi
unsigned __int64 v17; // rax
__int64 v18; // rdx
int v19; // ecx
void *v20; // rax
_QWORD v21[16384]; // [rsp+0h] [rbp-60038h] BYREF
_QWORD s2[16384]; // [rsp+20000h] [rbp-40038h] BYREF
__int64 s1[16391]; // [rsp+40000h] [rbp-20038h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, __int64 a2, __int64 a3)
{
int v4; // er12
int v5; // ebp
__int64 v6; // rax
char *v7; // rdx
__int64 result; // rax
__int64 (__fastcall *v9)(_QWORD, __int64, __int64); // rax
char *v10; // r14
_DWORD *v11; // r15
int v12; // edx
__int64 i; // rcx
int v14; // eax
char *v15; // rcx
__int64 v16; // rsi
unsigned __int64 v17; // rax
__int64 v18; // rdx
int v19; // ecx
void *v20; // rax
_QWORD v21[16384]; // [rsp+0h] [rbp-60038h] BYREF
_QWORD s2[16384]; // [rsp+20000h] [rbp-40038h] BYREF
__int64 s1[16391]; // [rsp+40000h] [rbp-20038h] BYREF

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

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

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

mq_notify();
v0 = malloc(0x2000uLL);
memset(v0, 0, 0x2000uLL);
while ( 1 )
{
result = mq_receive();
if ( result < 0 )
break;
fprintf(stderr, "R:%s\n", (const char *)v0);
if ( write(accepted_socket, v0, 0x2000uLL) == -1 )
fprintf(stderr, "No write%s\n", (const char *)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; } *


decompiled_code:
__int64 process_mq_parent()
{
void *v0; // rbx
__int64 result; // rax

mq_notify();
v0 = malloc(0x2000uLL);
memset(v0, 0, 0x2000uLL);
while ( 1 )
{
result = mq_receive();
if ( result < 0 )
break;
fprintf(stderr, "%s\n", (const char *)v0);
while ( ll_next((__int64 *)mq_ll) )
mq_send();
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
void *v0; // rbx
__int64 result; // rax

mq_notify();
v0 = malloc(0x2000uLL);
memset(v0, 0, 0x2000uLL);
while ( 1 )
{
result = mq_receive();
if ( result < 0 )
break;
fprintf(stderr, "%s\n", (const char *)v0);
while ( func11((__int64 *)mq_ll) )
mq_send();
}
return result;
}

original_code:
void process_mq_parent() {
 struct sigevent sev;
 sev.sigev_notify = SIGEV_SIGNAL;
 sev.sigev_signo = 10;
 mq_notify(mqd_parent_incoming, &sev);
 mqd_t *mqd_child;
 Node *node = ((void *)0);
 char *msg = malloc(8192);
 memset(msg, 0, 8192);
 while (mq_receive(mqd_parent_incoming, msg, 8192, 0) >= 0) {
  fprintf(stderr, "%s\n", msg);
  while ((node = ll_next(mq_ll))) {
   mqd_child = node->data;
   mq_send(*mqd_child, msg, 8192, 0);
  }
 }
}

canonical_original_code:
void process_mq_parent() {
 struct sigevent sev;
 sev.sigev_notify = SIGEV_SIGNAL;
 sev.sigev_signo = 10;
 mq_notify(mqd_parent_incoming, &sev);
 int *mqd_child;
 struct Node *node = ((void *)0);
 char *msg = malloc(8192);
 memset(msg, 0, 8192);
 while (mq_receive(mqd_parent_incoming, msg, 8192, 0) >= 0) {
  fprintf(stderr, "%s\n", msg);
  while ((node = ll_next(mq_ll))) {
   mqd_child = node->data;
   mq_send(*mqd_child, msg, 8192, 0);
  }
 }
}

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

user_defined_types: union sigval { int sival_int; void *sival_ptr; }

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }


decompiled_code:
void __fastcall ll_reset(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void ll_reset(LinkedList *ll) {
 ll->cur = ((void *)0);
}

canonical_original_code:
void ll_reset(struct LinkedList *ll) {
 ll->cur = ((void *)0);
}

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


decompiled_code:
size_t sigpipe_handler()
{
return fwrite("Sigpipe.\n", 1uLL, 9uLL, stderr);
}

canonical_decompiled_code:
size_t func14()
{
return fwrite("Sigpipe.\n", 1uLL, 9uLL, stderr);
}

original_code:
void sigpipe_handler(int status) {
 fprintf(stderr, "Sigpipe.\n");
}


strrev

decompiled_code:
void *__fastcall strrev(void *dest, __int64 a2)
{
size_t v3; // rbp
_BYTE *v4; // rsi
_BYTE *v5; // rax
_BYTE *v6; // rdx
_BYTE *v7; // rcx

if ( *((char *)dest + a2 - 1) )
__assert_fail("*(string + length - 1) == '\\0'", "../server.c", 0x3Cu, "strrev");
v3 = a2 - 1;
v4 = malloc(a2 - 1);
if ( v3 )
{
v5 = (char *)dest + a2 - 2;
v6 = v4;
do
{
*v6 = *v5;
v7 = v5--;
++v6;
}
while ( v7 != dest );
}
return memcpy(dest, v4, v3);
}

canonical_decompiled_code:
void *__fastcall func15(void *dest, __int64 a2)
{
size_t v3; // rbp
_BYTE *v4; // rsi
_BYTE *v5; // rax
_BYTE *v6; // rdx
_BYTE *v7; // rcx

if ( *((char *)dest + a2 - 1) )
__assert_fail("*(string + length - 1) == '\\0'", "../server.c", 0x3Cu, "strrev");
v3 = a2 - 1;
v4 = malloc(a2 - 1);
if ( v3 )
{
v5 = (char *)dest + a2 - 2;
v6 = v4;
do
{
*v6 = *v5;
v7 = v5--;
++v6;
}
while ( v7 != dest );
}
return memcpy(dest, v4, v3);
}

original_code:
void strrev(char *string, size_t length) {
 ((void) sizeof ((*(string + length - 1) == '\0') ? 1 : 0), __extension__ ({ if (*(string + length - 1) == '\0') ; else __assert_fail ("*(string + length - 1) == '\\0'", "../server.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 size_t content = length - 1;
 char *reversed = malloc(content);
 int i;
 for (i = 0; i < content; i++) {
  *(reversed + i) = *(string + content - i - 1);
 }
 memcpy(string, reversed, content);
}

canonical_original_code:
void strrev(char *string, unsigned long length) {
 ((void) sizeof ((*(string + length - 1) == '\0') ? 1 : 0), __extension__ ({ if (*(string + length - 1) == '\0') ; else __assert_fail ("*(string + length - 1) == '\\0'", "../server.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 unsigned long content = length - 1;
 char *reversed = malloc(content);
 int i;
 for (i = 0; i < content; i++) {
  *(reversed + i) = *(string + content - i - 1);
 }
 memcpy(string, reversed, content);
}

variable_types:
string
char *

variable_types:
length
unsigned long

variable_types:
content
unsigned long

variable_types:
reversed
char *

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int *v4; // rbx
_BYTE *v5; // r13
unsigned int v6; // er12
_DWORD *v7; // rbx
_QWORD *v8; // rsi
unsigned int v9; // er14
char *v10; // rbx
__int64 v11; // rcx
__sigset_t *v12; // rdi
void *v14; // rbx
_BYTE *v15; // rbx
int v16; // ebp
char v17; // al
int buf; // [rsp+Ch] [rbp-FCh] BYREF
struct sigaction v19; // [rsp+10h] [rbp-F8h] BYREF
struct sockaddr addr; // [rsp+B0h] [rbp-58h] BYREF
int optval[15]; // [rsp+CCh] [rbp-3Ch] BYREF

mq_ll = (__int64)ll_init();
mqd_parent_incoming = mq_open();
fwrite("Server starting. \n", 1uLL, 0x12uLL, stderr);
v3 = socket(2, 1, 0);
optval[0] = 1;
setsockopt(v3, 1, 2, optval, 4u);
signal(13, (__sighandler_t)1);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v4 = (unsigned int *)malloc(0x20uLL);
inet_pton(2, "127.0.0.1", v4);
*(_QWORD *)&addr.sa_data[2] = *v4;
*(_WORD *)addr.sa_data = _bswap_16(16999);
if ( bind(v3, &addr, 0x10u) )
{
fwrite("Couldn't bind address. \n", 1uLL, 0x18uLL, stderr);
}
else
{
fwrite("Main>Successfully bound address. \n", 1uLL, 0x22uLL, stderr);
if ( !listen(v3, 10) )
{
fwrite("Main>Listening for connections.\n", 1uLL, 0x20uLL, stderr);
fwrite("Main>Accepting connections! Will block. \n", 1uLL, 0x29uLL, stderr);
while ( 1 )
{
v5 = malloc(0x2001uLL);
accepted_socket = accept(v3, 0LL, 0LL);
fwrite("Main>Accepted socket, forking \n", 1uLL, 0x1FuLL, stderr);
v6 = fork();
if ( !v6 )
break;
memset(&v19.sa_mask, 0, 0x90uLL);
v19.sa_handler = (__sighandler_t)sigchld_handler;
v19.sa_flags = 0x10000000;
sigaction(17, &v19, 0LL);
memset(&v19.sa_mask, 0, 0x90uLL);
v19.sa_handler = (__sighandler_t)process_mq_parent;
v19.sa_flags = 0x10000000;
sigaction(10, &v19, 0LL);
v7 = malloc(0x64uLL);
memset(v7, 0, 0x60uLL);
v7[24] = 0;
sprintf((char *)v7, "/charlando_server_child_%d", v6);
fprintf(stderr, "%s\n", (const char *)v7);
buf = mq_open();
v8 = node_init(&buf, 4uLL);
ll_add((_QWORD *)mq_ll, (__int64)v8);
free(v7);
process_mq_parent();
fprintf(stderr, "Main>Child created Server[%d]\n", v6);
}
v9 = getpid();
mq_open();
v10 = (char *)malloc(0x64uLL);
sprintf(v10, "/charlando_server_child_%d", v9);
incoming = mq_open();
free(v10);
v11 = 36LL;
v12 = &v19.sa_mask;
while ( v11 )
{
LODWORD(v12->__val[0]) = 0;
v12 = (__sigset_t *)((char *)v12 + 4);
--v11;
}
v19.sa_handler = (__sighandler_t)process_mq_child;
v19.sa_flags = 0x10000000;
sigaction(10, &v19, 0LL);
process_mq_child();
while ( 1 )
{
v15 = v5;
v16 = v6;
do
{
v16 += recv(accepted_socket, &buf, 1uLL, 0);
if ( v16 <= 0 )
{
free(v5);
fprintf(stderr, "Server[%d]>Client disconnected, exiting.\n", v9);
exit(0);
}
v17 = buf;
*v15++ = buf;
}
while ( v17 );
v14 = malloc(0x2000uLL);
memset(v14, 0, 0x2000uLL);
sprintf((char *)v14, "Client[%d]>%s\n", v9, v5);
strlen((const char *)v14);
mq_send();
free(v14);
}
}
fwrite("Couldn't listen. \n", 1uLL, 0x12uLL, stderr);
}
close(v3);
fwrite("Server shutting down. \n", 1uLL, 0x17uLL, stderr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int *v4; // rbx
_BYTE *v5; // r13
unsigned int v6; // er12
_DWORD *v7; // rbx
_QWORD *v8; // rsi
unsigned int v9; // er14
char *v10; // rbx
__int64 v11; // rcx
__sigset_t *v12; // rdi
void *v14; // rbx
_BYTE *v15; // rbx
int v16; // ebp
char v17; // al
int buf; // [rsp+Ch] [rbp-FCh] BYREF
struct sigaction v19; // [rsp+10h] [rbp-F8h] BYREF
struct sockaddr addr; // [rsp+B0h] [rbp-58h] BYREF
int optval[15]; // [rsp+CCh] [rbp-3Ch] BYREF

mq_ll = (__int64)func10();
mqd_parent_incoming = mq_open();
fwrite("Server starting. \n", 1uLL, 0x12uLL, stderr);
v3 = socket(2, 1, 0);
optval[0] = 1;
setsockopt(v3, 1, 2, optval, 4u);
signal(13, (__sighandler_t)1);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v4 = (unsigned int *)malloc(0x20uLL);
inet_pton(2, "127.0.0.1", v4);
*(_QWORD *)&addr.sa_data[2] = *v4;
*(_WORD *)addr.sa_data = func9(16999);
if ( bind(v3, &addr, 0x10u) )
{
fwrite("Couldn't bind address. \n", 1uLL, 0x18uLL, stderr);
}
else
{
fwrite("Main>Successfully bound address. \n", 1uLL, 0x22uLL, stderr);
if ( !listen(v3, 10) )
{
fwrite("Main>Listening for connections.\n", 1uLL, 0x20uLL, stderr);
fwrite("Main>Accepting connections! Will block. \n", 1uLL, 0x29uLL, stderr);
while ( 1 )
{
v5 = malloc(0x2001uLL);
accepted_socket = accept(v3, 0LL, 0LL);
fwrite("Main>Accepted socket, forking \n", 1uLL, 0x1FuLL, stderr);
v6 = fork();
if ( !v6 )
break;
memset(&v19.sa_mask, 0, 0x90uLL);
v19.sa_handler = (__sighandler_t)sigchld_handler;
v19.sa_flags = 0x10000000;
sigaction(17, &v19, 0LL);
memset(&v19.sa_mask, 0, 0x90uLL);
v19.sa_handler = (__sighandler_t)process_mq_parent;
v19.sa_flags = 0x10000000;
sigaction(10, &v19, 0LL);
v7 = malloc(0x64uLL);
memset(v7, 0, 0x60uLL);
v7[24] = 0;
sprintf((char *)v7, "/charlando_server_child_%d", v6);
fprintf(stderr, "%s\n", (const char *)v7);
buf = mq_open();
v8 = node_init(&buf, 4uLL);
ll_add((_QWORD *)mq_ll, (__int64)v8);
free(v7);
func12();
fprintf(stderr, "Main>Child created Server[%d]\n", v6);
}
v9 = getpid();
mq_open();
v10 = (char *)malloc(0x64uLL);
sprintf(v10, "/charlando_server_child_%d", v9);
incoming = mq_open();
free(v10);
v11 = 36LL;
v12 = &v19.sa_mask;
while ( v11 )
{
LODWORD(v12->__val[0]) = 0;
v12 = (__sigset_t *)((char *)v12 + 4);
--v11;
}
v19.sa_handler = (__sighandler_t)process_mq_child;
v19.sa_flags = 0x10000000;
sigaction(10, &v19, 0LL);
func8();
while ( 1 )
{
v15 = v5;
v16 = v6;
do
{
v16 += recv(accepted_socket, &buf, 1uLL, 0);
if ( v16 <= 0 )
{
free(v5);
fprintf(stderr, "Server[%d]>Client disconnected, exiting.\n", v9);
exit(0);
}
v17 = buf;
*v15++ = buf;
}
while ( v17 );
v14 = malloc(0x2000uLL);
memset(v14, 0, 0x2000uLL);
sprintf((char *)v14, "Client[%d]>%s\n", v9, v5);
strlen((const char *)v14);
mq_send();
free(v14);
}
}
fwrite("Couldn't listen. \n", 1uLL, 0x12uLL, stderr);
}
close(v3);
fwrite("Server shutting down. \n", 1uLL, 0x17uLL, stderr);
return 0;
}

original_code:
int main(int argc, char **argv) {
 mq_ll = ll_init();
 mqd_parent_incoming = mq_open("/charlando_server_parent",
 0100 | 00 | 04000,
 ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
 fprintf(stderr, "Server starting. \n");
 int sockfd = socket(2, SOCK_STREAM, 0);
 int optval = 1;
 setsockopt(sockfd, 1, 2, &optval, sizeof optval);
 signal(13, ((__sighandler_t) 1));
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 void *binaryLocalhost = malloc(32);
 inet_pton(2, "127.0.0.1", binaryLocalhost);
 addr.sin_family = 2;
 addr.sin_addr.s_addr = *(in_addr_t *) binaryLocalhost;
 addr.sin_port = htons(16999);
 if (bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))
   == 0) {
  fprintf(stderr, "Main>Successfully bound address. \n");
  if (listen(sockfd, 10) == 0) {
   fprintf(stderr, "Main>Listening for connections.\n");
   fprintf(stderr, "Main>Accepting connections! Will block. \n");
   while (1) {
    int bufsize = 8192;
    char *buf = malloc(bufsize + 1);
    char chr;
    accepted_socket = accept(sockfd, ((void *)0), 0);
    fprintf(stderr, "Main>Accepted socket, forking \n");
    pid_t child_pid = fork();
    switch (child_pid) {
    case 0: {
     pid_t process_pid = getpid();
     mqd_t outgoing = mq_open("/charlando_server_parent",
     0100 | 01, ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     char *queue_name = malloc(100);
     sprintf(queue_name, "/charlando_server_child_%d",
       process_pid);
     incoming = mq_open(queue_name,
     0100 | 00 | 04000,
     ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     free(queue_name);
     struct sigaction sa;
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &process_mq_child;
     sa.sa_flags = 0x10000000;
     sigaction(10, &sa, ((void *)0));
     process_mq_child();
     while (1) {
      int i;
      int bytes = 0;
      for (i = 0;
        (bytes += recv(accepted_socket, &chr, 1, 0)) > 0;
        i++) {
       buf[i] = chr;
       if (chr == '\0')
        break;
      }
      if (bytes > 0) {
       char *msg = malloc(8192);
       memset(msg, 0, 8192);
       sprintf(msg, "Client[%d]>%s\n", process_pid, buf);
       mq_send(outgoing, msg, strlen(msg), 0);
       free(msg);
      } else {
       break;
      }
     }
     free(buf);
     fprintf(stderr,
       "Server[%d]>Client disconnected, exiting.\n",
       process_pid);
     exit(0);
     break;
    }
    default: {
     struct sigaction sa;
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &sigchld_handler;
     sa.sa_flags = 0x10000000;
     sigaction(17, &sa, ((void *)0));
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &process_mq_parent;
     sa.sa_flags = 0x10000000;
     sigaction(10, &sa, ((void *)0));
     char *queue_name = malloc(100);
     memset(queue_name, 0, 100);
     sprintf(queue_name, "/charlando_server_child_%d",
       child_pid);
     fprintf(stderr, "%s\n", queue_name);
     mqd_t child_mqd = mq_open(queue_name, 0100 | 01,
     ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     ll_add(mq_ll, node_init(&child_mqd, sizeof(child_mqd)));
     free(queue_name);
     process_mq_parent();
     fprintf(stderr, "Main>Child created Server[%d]\n",
       child_pid);
     break;
    }
    }
   }
  } else {
   fprintf(stderr, "Couldn't listen. \n");
  }
 } else {
  fprintf(stderr, "Couldn't bind address. \n");
 }
 close(sockfd);
 fprintf(stderr, "Server shutting down. \n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 mq_ll = ll_init();
 mqd_parent_incoming = mq_open("/charlando_server_parent",
 0100 | 00 | 04000,
 ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
 fprintf(stderr, "Server starting. \n");
 int sockfd = socket(2, SOCK_STREAM, 0);
 int optval = 1;
 setsockopt(sockfd, 1, 2, &optval, sizeof optval);
 signal(13, ((void (*)(int)) 1));
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 void *binaryLocalhost = malloc(32);
 inet_pton(2, "127.0.0.1", binaryLocalhost);
 addr.sin_family = 2;
 addr.sin_addr.s_addr = *(unsigned int *) binaryLocalhost;
 addr.sin_port = htons(16999);
 if (bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))
   == 0) {
  fprintf(stderr, "Main>Successfully bound address. \n");
  if (listen(sockfd, 10) == 0) {
   fprintf(stderr, "Main>Listening for connections.\n");
   fprintf(stderr, "Main>Accepting connections! Will block. \n");
   while (1) {
    int bufsize = 8192;
    char *buf = malloc(bufsize + 1);
    char chr;
    accepted_socket = accept(sockfd, ((void *)0), 0);
    fprintf(stderr, "Main>Accepted socket, forking \n");
    int child_pid = fork();
    switch (child_pid) {
    case 0: {
     int process_pid = getpid();
     int outgoing = mq_open("/charlando_server_parent",
     0100 | 01, ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     char *queue_name = malloc(100);
     sprintf(queue_name, "/charlando_server_child_%d",
       process_pid);
     incoming = mq_open(queue_name,
     0100 | 00 | 04000,
     ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     free(queue_name);
     struct sigaction sa;
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &process_mq_child;
     sa.sa_flags = 0x10000000;
     sigaction(10, &sa, ((void *)0));
     process_mq_child();
     while (1) {
      int i;
      int bytes = 0;
      for (i = 0;
        (bytes += recv(accepted_socket, &chr, 1, 0)) > 0;
        i++) {
       buf[i] = chr;
       if (chr == '\0')
        break;
      }
      if (bytes > 0) {
       char *msg = malloc(8192);
       memset(msg, 0, 8192);
       sprintf(msg, "Client[%d]>%s\n", process_pid, buf);
       mq_send(outgoing, msg, strlen(msg), 0);
       free(msg);
      } else {
       break;
      }
     }
     free(buf);
     fprintf(stderr,
       "Server[%d]>Client disconnected, exiting.\n",
       process_pid);
     exit(0);
     break;
    }
    default: {
     struct sigaction sa;
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &sigchld_handler;
     sa.sa_flags = 0x10000000;
     sigaction(17, &sa, ((void *)0));
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &process_mq_parent;
     sa.sa_flags = 0x10000000;
     sigaction(10, &sa, ((void *)0));
     char *queue_name = malloc(100);
     memset(queue_name, 0, 100);
     sprintf(queue_name, "/charlando_server_child_%d",
       child_pid);
     fprintf(stderr, "%s\n", queue_name);
     int child_mqd = mq_open(queue_name, 0100 | 01,
     ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     ll_add(mq_ll, node_init(&child_mqd, sizeof(child_mqd)));
     free(queue_name);
     process_mq_parent();
     fprintf(stderr, "Main>Child created Server[%d]\n",
       child_pid);
     break;
    }
    }
   }
  } else {
   fprintf(stderr, "Couldn't listen. \n");
  }
 } else {
  fprintf(stderr, "Couldn't bind address. \n");
 }
 close(sockfd);
 fprintf(stderr, "Server shutting down. \n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: sockfd int

variable_types: optval int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types:
binaryLocalhost
void *

variable_types: bufsize int

variable_types:
buf
char *

variable_types: chr char

variable_types: outgoing int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: bytes int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


original_code:
void trim_newlines(char *string, size_t length) {
 int i;
 for (i = 0; i < length; i++) {
  if (string[i] == '\n')
   string[i] = ' ';
 }
}

canonical_original_code:
void trim_newlines(char *string, unsigned long length) {
 int i;
 for (i = 0; i < length; i++) {
  if (string[i] == '\n')
   string[i] = ' ';
 }
}

variable_types:
string
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int *v4; // rbx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rbx
__int64 v7; // rbx
char v8; // al
char v10; // [rsp+Fh] [rbp-39h] BYREF
size_t n; // [rsp+10h] [rbp-38h] BYREF
void *buf; // [rsp+18h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

puts("Client starting. ");
v3 = socket(2, 1, 0);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v4 = (unsigned int *)malloc(0x20uLL);
inet_pton(2, "127.0.0.1", v4);
*(_QWORD *)&addr.sa_data[2] = *v4;
*(_WORD *)addr.sa_data = _bswap_16(16999);
puts("Attempting to connect. ");
if ( !connect(v3, &addr, 0x10u) )
{
puts("Connected! ");
v10 = 0;
n = 0x2000LL;
buf = malloc(0x2000uLL);
memset(buf, 0, 0x2000uLL);
while ( 1 )
{
do
{
while ( 1 )
{
printf("Client>");
v5 = getline((char **)&buf, &n, _bss_start);
v6 = v5;
if ( v5 <= 1 )
break;
trim_newlines(buf, v5);
write(v3, buf, v6 + 1);
}
}
while ( v5 != 1 );
memset(buf, 0, n);
v7 = 0LL;
do
{
if ( !(unsigned int)recv(v3, &v10, 1uLL, 0) )
break;
v8 = v10;
*((_BYTE *)buf + v7++) = v10;
}
while ( v8 );
printf("Server>%s\n", (const char *)buf);
}
}
printf("Failed");
close(v3);
puts("Client shutting down. ");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned int *v4; // rbx
unsigned __int64 v5; // rax
unsigned __int64 v6; // rbx
__int64 v7; // rbx
char v8; // al
char v10; // [rsp+Fh] [rbp-39h] BYREF
size_t n; // [rsp+10h] [rbp-38h] BYREF
void *buf; // [rsp+18h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

puts("Client starting. ");
v3 = socket(2, 1, 0);
*(_QWORD *)&addr.sa_family = 2LL;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v4 = (unsigned int *)malloc(0x20uLL);
inet_pton(2, "127.0.0.1", v4);
*(_QWORD *)&addr.sa_data[2] = *v4;
*(_WORD *)addr.sa_data = func7(16999);
puts("Attempting to connect. ");
if ( !connect(v3, &addr, 0x10u) )
{
puts("Connected! ");
v10 = 0;
n = 0x2000LL;
buf = malloc(0x2000uLL);
memset(buf, 0, 0x2000uLL);
while ( 1 )
{
do
{
while ( 1 )
{
printf("Client>");
v5 = getline((char **)&buf, &n, _bss_start);
v6 = v5;
if ( v5 <= 1 )
break;
func8(buf, v5);
write(v3, buf, v6 + 1);
}
}
while ( v5 != 1 );
memset(buf, 0, n);
v7 = 0LL;
do
{
if ( !(unsigned int)recv(v3, &v10, 1uLL, 0) )
break;
v8 = v10;
*((_BYTE *)buf + v7++) = v10;
}
while ( v8 );
printf("Server>%s\n", (const char *)buf);
}
}
printf("Failed");
close(v3);
puts("Client shutting down. ");
return 0;
}

original_code:
int main(int argc, char **argv) {
 printf("Client starting. \n");
 int sockfd = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 void *binaryLocalhost = malloc(32);
 inet_pton(2, "127.0.0.1", binaryLocalhost);
 addr.sin_family = 2;
 addr.sin_addr.s_addr = *(in_addr_t *) binaryLocalhost;
 addr.sin_port = htons(16999);
 printf("Attempting to connect. \n");
 if (connect(sockfd, &addr, sizeof(addr)) == 0) {
  printf("Connected! \n");
  char chr = ((void *)0);
  size_t msg_size = 8192;
  char *msg = malloc(msg_size);
  memset(msg, 0, msg_size);
  size_t input_size = 0;
  while (1) {
   printf("Client>");
   input_size = getline(&msg, &msg_size, stdin);
   if (input_size > 1) {
    trim_newlines(msg, input_size);
    write(sockfd, msg, (input_size + 1));
   } else if (input_size == 1) {
    memset(msg, 0, msg_size);
    int i;
    int result;
    for (i = 0; (result = recv(sockfd, &chr, 1, 0)); i++) {
     msg[i]=chr;
     if (chr == '\0')
      break;
    }
    printf("Server>%s\n", msg);
   }
  }
 } else {
  printf("Failed");
 }
 close(sockfd);
 printf("Client shutting down. \n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 printf("Client starting. \n");
 int sockfd = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 void *binaryLocalhost = malloc(32);
 inet_pton(2, "127.0.0.1", binaryLocalhost);
 addr.sin_family = 2;
 addr.sin_addr.s_addr = *(unsigned int *) binaryLocalhost;
 addr.sin_port = htons(16999);
 printf("Attempting to connect. \n");
 if (connect(sockfd, &addr, sizeof(addr)) == 0) {
  printf("Connected! \n");
  char chr = ((void *)0);
  unsigned long msg_size = 8192;
  char *msg = malloc(msg_size);
  memset(msg, 0, msg_size);
  unsigned long input_size = 0;
  while (1) {
   printf("Client>");
   input_size = getline(&msg, &msg_size, stdin);
   if (input_size > 1) {
    trim_newlines(msg, input_size);
    write(sockfd, msg, (input_size + 1));
   } else if (input_size == 1) {
    memset(msg, 0, msg_size);
    int i;
    int result;
    for (i = 0; (result = recv(sockfd, &chr, 1, 0)); i++) {
     msg[i]=chr;
     if (chr == '\0')
      break;
    }
    printf("Server>%s\n", msg);
   }
  }
 } else {
  printf("Failed");
 }
 close(sockfd);
 printf("Client shutting down. \n");
 return 0;
}

variable_types:
msg
char *

variable_types: result int


decompiled_code:
void __fastcall __noreturn sig_handler(int a1)
{
__sysv_signal(a1, (__sighandler_t)1);
puts("\nGoodbye");
close(a);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int a1)
{
__sysv_signal(a1, (__sighandler_t)1);
puts("\nGoodbye");
close(a);
exit(1);
}

original_code:
void sig_handler(int signum) {
 signal(signum, ((__sighandler_t) 1));
 printf("\nGoodbye\n");
 close(a);
 exit(1);
}

canonical_original_code:
void sig_handler(int signum) {
 signal(signum, ((void (*)(int)) 1));
 printf("\nGoodbye\n");
 close(a);
 exit(1);
}

variable_types: signum int


decompiled_code:
int __fastcall extract_file(unsigned int a1, const char *a2)
{
void *v3; // rax
void *v4; // rbx
int v5; // edi
int v6; // er14
int i; // er12
size_t v8; // rbp
void *v9; // rax
void *v10; // rbx
size_t v11; // rax
int result; // eax
int buf[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = malloc(0x20uLL);
if ( !v3 )
exit(1);
v4 = v3;
v5 = open(a2, 0);
a = v5;
if ( v5 == -1 )
{
perror("open archive");
exit(1);
}
if ( read(v5, v4, 0x20uLL) == -1 )
perror("read name");
puts((const char *)v4);
v6 = open((const char *)v4, 1217, 384LL);
if ( v6 == -1 )
{
perror("create temporary file");
exit(1);
}
if ( flock(a, 2) == -1 )
{
perror("flock - LOCK_EX");
exit(1);
}
for ( i = 0; ; ++i )
{
if ( (int)read(a, buf, 4uLL) <= 0 )
{
printf("File with indice %d doesn't exist in archive\n", a1);
unlink("README1");
if ( flock(a, 8) != -1 )
{
if ( close(a) != -1 )
exit(1);
perror("close archive");
exit(1);
}
perror("flock - LOCK_UN");
exit(1);
}
v8 = buf[0] - 1LL;
v9 = malloc(v8);
v10 = v9;
if ( !v9 )
exit(1);
if ( read(a, v9, v8) == -1 )
{
perror("read content");
exit(1);
}
if ( i == a1 )
break;
free(v10);
}
puts("EXTRACT");
v11 = strlen((const char *)v10);
if ( write(v6, v10, v11) == -1 )
{
perror("write content");
exit(1);
}
free(v10);
if ( flock(a, 8) == -1 )
{
perror("flock - LOCK_UN");
exit(1);
}
if ( close(a) == -1 )
{
perror("close archive");
exit(1);
}
result = close(v6);
if ( result == -1 )
{
perror("close temporary");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, const char *a2)
{
void *v3; // rax
void *v4; // rbx
int v5; // edi
int v6; // er14
int i; // er12
size_t v8; // rbp
void *v9; // rax
void *v10; // rbx
size_t v11; // rax
int result; // eax
int buf[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v3 = malloc(0x20uLL);
if ( !v3 )
exit(1);
v4 = v3;
v5 = open(a2, 0);
a = v5;
if ( v5 == -1 )
{
perror("open archive");
exit(1);
}
if ( read(v5, v4, 0x20uLL) == -1 )
perror("read name");
puts((const char *)v4);
v6 = open((const char *)v4, 1217, 384LL);
if ( v6 == -1 )
{
perror("create temporary file");
exit(1);
}
if ( flock(a, 2) == -1 )
{
perror("flock - LOCK_EX");
exit(1);
}
for ( i = 0; ; ++i )
{
if ( (int)read(a, buf, 4uLL) <= 0 )
{
printf("File with indice %d doesn't exist in archive\n", a1);
unlink("README1");
if ( flock(a, 8) != -1 )
{
if ( close(a) != -1 )
exit(1);
perror("close archive");
exit(1);
}
perror("flock - LOCK_UN");
exit(1);
}
v8 = buf[0] - 1LL;
v9 = malloc(v8);
v10 = v9;
if ( !v9 )
exit(1);
if ( read(a, v9, v8) == -1 )
{
perror("read content");
exit(1);
}
if ( i == a1 )
break;
free(v10);
}
puts("EXTRACT");
v11 = strlen((const char *)v10);
if ( write(v6, v10, v11) == -1 )
{
perror("write content");
exit(1);
}
free(v10);
if ( flock(a, 8) == -1 )
{
perror("flock - LOCK_UN");
exit(1);
}
if ( close(a) == -1 )
{
perror("close archive");
exit(1);
}
result = close(v6);
if ( result == -1 )
{
perror("close temporary");
exit(1);
}
return result;
}

original_code:
void extract_file(int indice, char *archivename) {
 int temporary;
 char *name;
 name=(char*)malloc(sizeof(char)*32);
 if(name==((void *)0)){
  free(name);
  exit(1);
 }
 a=open(archivename, 00);
 if(a==-1) {
  perror("open archive");
  exit(1);
 }
 if(read(a,(void*)name,(size_t)32)==-1){
  perror("read name");
 }
 printf("%s\n",name);
 temporary=open(name, 01|0100|0200|02000, 0400|0200);
 if(temporary==-1) {
  perror("create temporary file");
  exit(1);
 }
 if(flock(a,2)==-1) {
  perror("flock - LOCK_EX");
  exit(1);
 }
 int x,err;
 int flag = 0;
 int i = 0;
 while((err=read(a, (void *)&x, sizeof(int)))>0) {
  if(err==-1) {
   perror("read int");
   exit(1);
  }
  char *buffer;
  buffer=(char *)malloc((sizeof(char)*x)-1);
  if(buffer==((void *)0)) {
   free(buffer);
   exit(1);
  }
  if(read(a, (void *)buffer, (size_t)x-1)==-1) {
   perror("read content");
   exit(1);
  }
  if(i==indice) {
   flag=1;
   printf("EXTRACT\n");
   if(write(temporary, (void *)buffer, strlen(buffer))==-1) {
    perror("write content");
    exit(1);
   }
   free(buffer);
   break;
  }
  free(buffer);
  i++;
 }
 if(flag==0) {
  printf("File with indice %d doesn't exist in archive\n", indice);
  unlink("README1");
  if (flock(a,8)==-1) {
   perror("flock - LOCK_UN");
   exit(1);
  }
  if(close(a)==-1) {
   perror("close archive");
   exit(1);
  }
  exit(1);
 }
 if (flock(a,8)==-1) {
  perror("flock - LOCK_UN");
  exit(1);
 }
 if(close(a)==-1) {
  perror("close archive");
  exit(1);
 }
 if(close(temporary)==-1) {
  perror("close temporary");
  exit(1);
 }
}

canonical_original_code:
void extract_file(int indice, char *archivename) {
 int temporary;
 char *name;
 name=(char *)malloc(sizeof(char)*32);
 if(name==((void *)0)){
  free(name);
  exit(1);
 }
 a=open(archivename, 00);
 if(a==-1) {
  perror("open archive");
  exit(1);
 }
 if(read(a,(void *)name,(unsigned long)32)==-1){
  perror("read name");
 }
 printf("%s\n",name);
 temporary=open(name, 01|0100|0200|02000, 0400|0200);
 if(temporary==-1) {
  perror("create temporary file");
  exit(1);
 }
 if(flock(a,2)==-1) {
  perror("flock - LOCK_EX");
  exit(1);
 }
 int x; int err;
 int flag = 0;
 int i = 0;
 while((err=read(a, (void *)&x, sizeof(int)))>0) {
  if(err==-1) {
   perror("read int");
   exit(1);
  }
  char *buffer;
  buffer=(char *)malloc((sizeof(char)*x)-1);
  if(buffer==((void *)0)) {
   free(buffer);
   exit(1);
  }
  if(read(a, (void *)buffer, (unsigned long)x-1)==-1) {
   perror("read content");
   exit(1);
  }
  if(i==indice) {
   flag=1;
   printf("EXTRACT\n");
   if(write(temporary, (void *)buffer, strlen(buffer))==-1) {
    perror("write content");
    exit(1);
   }
   free(buffer);
   break;
  }
  free(buffer);
  i++;
 }
 if(flag==0) {
  printf("File with indice %d doesn't exist in archive\n", indice);
  unlink("README1");
  if (flock(a,8)==-1) {
   perror("flock - LOCK_UN");
   exit(1);
  }
  if(close(a)==-1) {
   perror("close archive");
   exit(1);
  }
  exit(1);
 }
 if (flock(a,8)==-1) {
  perror("flock - LOCK_UN");
  exit(1);
 }
 if(close(a)==-1) {
  perror("close archive");
  exit(1);
 }
 if(close(temporary)==-1) {
  perror("close temporary");
  exit(1);
 }
}

variable_types: indice int

variable_types:
archivename
char *

variable_types: temporary int

variable_types:
name
char *

variable_types: x int

variable_types: err int

variable_types: flag int

variable_types: i int

variable_types:
buffer
char *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char *v4; // r12
int v5; // eax
unsigned int v6; // ebx
int result; // eax
__int64 i; // rax

if ( argc == 4 )
{
while ( 1 )
{
v5 = getopt(4, (char *const *)argv, "n:");
if ( v5 == -1 )
{
for ( i = _bss_start; (int)i <= 3; ++i )
v4 = argv[i];
__sysv_signal(2, (__sighandler_t)sig_handler);
__sysv_signal(1, (__sighandler_t)sig_handler);
__sysv_signal(3, (__sighandler_t)sig_handler);
__sysv_signal(15, (__sighandler_t)sig_handler);
__sysv_signal(20, (__sighandler_t)sig_handler);
extract_file(v3, v4);
return 0;
}
if ( v5 == 63 )
break;
if ( v5 != 110 )
return 1;
v3 = atoi(optarg);
}
v6 = optopt;
if ( optopt == 110 )
{
printf("Option -%c requires an argument.\n", 110LL);
result = 1;
}
else
{
if ( ((*__ctype_b_loc())[v6] & 0x4000) != 0 )
printf("Unknown option '-%c'.\n", v6);
else
printf("Unknown option character '\\x%x'.\n", v6);
result = 1;
}
}
else
{
puts("Wrong number of arguments");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
const char *v4; // r12
int v5; // eax
unsigned int v6; // ebx
int result; // eax
__int64 i; // rax

if ( argc == 4 )
{
while ( 1 )
{
v5 = getopt(4, (char *const *)argv, "n:");
if ( v5 == -1 )
{
for ( i = _bss_start; (int)i <= 3; ++i )
v4 = argv[i];
__sysv_signal(2, (__sighandler_t)sig_handler);
__sysv_signal(1, (__sighandler_t)sig_handler);
__sysv_signal(3, (__sighandler_t)sig_handler);
__sysv_signal(15, (__sighandler_t)sig_handler);
__sysv_signal(20, (__sighandler_t)sig_handler);
func8(v3, v4);
return 0;
}
if ( v5 == 63 )
break;
if ( v5 != 110 )
return 1;
v3 = atoi(optarg);
}
v6 = optopt;
if ( optopt == 110 )
{
printf("Option -%c requires an argument.\n", 110LL);
result = 1;
}
else
{
if ( ((*__ctype_b_loc())[v6] & 0x4000) != 0 )
printf("Unknown option '-%c'.\n", v6);
else
printf("Unknown option character '\\x%x'.\n", v6);
result = 1;
}
}
else
{
puts("Wrong number of arguments");
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 if(argc==4) {
  char *archivename;
  int opt, index, indice;
  while((opt=getopt(argc,argv,"n:"))!=-1) {
   switch(opt) {
    case 'n':
     indice=atoi(optarg);
     break;
    case '?':
     if(optopt=='n')
      printf("Option -%c requires an argument.\n", optopt);
     else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short int) _ISprint))
      printf("Unknown option '-%c'.\n", optopt);
     else
      printf("Unknown option character '\\x%x'.\n", optopt);
     return 1;
    default:
     return 1;
   }
  }
  for(index=optind; index<argc; index++)
   archivename=argv[index];
  signal(2, sig_handler);
  signal(1, sig_handler);
  signal(3, sig_handler);
  signal(15, sig_handler);
  signal(20, sig_handler);
  extract_file(indice, archivename);
  return 0;
 }
 else {
  printf("Wrong number of arguments\n");
  return 1;
 }
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if(argc==4) {
  char *archivename;
  int opt; int index; int indice;
  while((opt=getopt(argc,argv,"n:"))!=-1) {
   switch(opt) {
    case 'n':
     indice=atoi(optarg);
     break;
    case '?':
     if(optopt=='n')
      printf("Option -%c requires an argument.\n", optopt);
     else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short) _ISprint))
      printf("Unknown option '-%c'.\n", optopt);
     else
      printf("Unknown option character '\\x%x'.\n", optopt);
     return 1;
    default:
     return 1;
   }
  }
  for(index=optind; index<argc; index++)
   archivename=argv[index];
  signal(2, sig_handler);
  signal(1, sig_handler);
  signal(3, sig_handler);
  signal(15, sig_handler);
  signal(20, sig_handler);
  extract_file(indice, archivename);
  return 0;
 }
 else {
  printf("Wrong number of arguments\n");
  return 1;
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: opt int

variable_types: index int


decompiled_code:
__int64 __fastcall send_dns_reply(const char *a1, __int64 a2, __int64 a3, int a4, __int64 a5, signed int a6)
{
unsigned __int16 v9; // [rsp+8h] [rbp-20h]

if ( (int)(strlen(a1) + 16) >= a6 )
{
puts("Failed to send DNS reply; DNS request packet appears to have an invalid length.");
return 0LL;
}
inet_addr("212.58.251.195");
inet_addr("74.125.226.212");
_bswap_16(49164);
v9 = _bswap_16(1);
_bswap_16(5);
if ( v9 == a4 )
{
_bswap_16(4);
if ( !malloc(a6 + 32) )
{
LABEL_6:
perror("Malloc Failure");
return 0LL;
}
}
else if ( (unsigned __int16)_bswap_16(2) == a4 )
{
_bswap_16(6);
if ( !malloc(a6 + 36) )
goto LABEL_6;
}
puts("\x1B[1;32mFINAL STEP : Ready to send ...\x1B[0m");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2, __int64 a3, int a4, __int64 a5, signed int a6)
{
unsigned __int16 v9; // [rsp+8h] [rbp-20h]

if ( (int)(strlen(a1) + 16) >= a6 )
{
puts("Failed to send DNS reply; DNS request packet appears to have an invalid length.");
return 0LL;
}
inet_addr("212.58.251.195");
inet_addr("74.125.226.212");
func0(49164);
v9 = func0(1);
func0(5);
if ( v9 == a4 )
{
func0(4);
if ( !malloc(a6 + 32) )
{
LABEL_6:
perror("Malloc Failure");
return 0LL;
}
}
else if ( (unsigned __int16)func0(2) == a4 )
{
func0(6);
if ( !malloc(a6 + 36) )
goto LABEL_6;
}
puts("\x1B[1;32mFINAL STEP : Ready to send ...\x1B[0m");
return 0LL;
}

original_code:
int send_dns_reply(char *question_domain, int sock, struct sockaddr_in *clientaddr, int dns_type, char *request_packet, int request_packet_size)
{
 char *reply_packet = ((void *)0), *fqdn = ((void *)0);
 struct dns_header *header = ((void *)0);
 struct dns_answer_section answer;
 int reply_packet_size = 0;
 int answer_size = sizeof(struct dns_answer_section);
 int bytes_sent = 0;
 int memcpy_offset = 0;
 in_addr_t ip_address1 = {0};
 in_addr_t ip_address2 = {0};
 memset(&answer,0,sizeof(struct dns_answer_section));
 fqdn = "www.facebook.com";
 if(request_packet_size > ((int) (sizeof(struct dns_header) + sizeof(struct dns_question_section)) + (int) strlen(question_domain))){
   ip_address2 = inet_addr("212.58.251.195");
   ip_address1 = inet_addr("74.125.226.212");
  answer.name = htons(0xC00C);
  answer.type = dns_type;
  answer.class = htons(0x0001);
  answer.ttl = htons(0x0005);
  if(dns_type == htons(0x0001)){
   answer.data_len = htons(0x0004);
   reply_packet_size = request_packet_size + ((answer_size + 0x0004) * 0x0002);
   if((reply_packet = malloc(reply_packet_size)) != ((void *)0)){
    memcpy(reply_packet,request_packet,request_packet_size);
    memcpy_offset += request_packet_size;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,(void *) &ip_address1,0x0004);
    memcpy_offset += 0x0004;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,(void *) &ip_address2,0x0004);
   } else {
    perror("Malloc Failure");
    return 0;
   }
  } else if(dns_type == htons(0x0002)){
   answer.data_len = htons(0x0006);
   reply_packet_size = request_packet_size + ((answer_size + 0x0006) * 0x0002);
   if((reply_packet = malloc(reply_packet_size)) != ((void *)0)){
    memcpy(reply_packet,request_packet,request_packet_size);
    memcpy_offset += request_packet_size;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,"\x03ns1\xC0\x0C",0x0006);
    memcpy_offset += 0x0006;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,"\x03ns2\xC0\x0C",0x0006);
   } else {
    perror("Malloc Failure");
    return 0;
   }
  }
        header = (struct dns_header *) reply_packet;
        header->num_answers = htons(0x0002);
        header->flags = htons(0x8180);
  printf("\x1b[1;32m""FINAL STEP : Ready to send ...""\x1b[0m""\n");
 } else {
  printf("Failed to send DNS reply; DNS request packet appears to have an invalid length.\n");
 }
 return 0;
}

canonical_original_code:
int send_dns_reply(char *question_domain, int sock, struct sockaddr_in *clientaddr, int dns_type, char *request_packet, int request_packet_size)
{
 char *reply_packet = ((void *)0); char *fqdn = ((void *)0);
 struct dns_header *header = ((void *)0);
 struct dns_answer_section answer;
 int reply_packet_size = 0;
 int answer_size = sizeof(struct dns_answer_section);
 int bytes_sent = 0;
 int memcpy_offset = 0;
 unsigned int ip_address1 = {0};
 unsigned int ip_address2 = {0};
 memset(&answer,0,sizeof(struct dns_answer_section));
 fqdn = "www.facebook.com";
 if(request_packet_size > ((int) (sizeof(struct dns_header) + sizeof(struct dns_question_section)) + (int) strlen(question_domain))){
   ip_address2 = inet_addr("212.58.251.195");
   ip_address1 = inet_addr("74.125.226.212");
  answer.name = htons(0xC00C);
  answer.type = dns_type;
  answer.class = htons(0x0001);
  answer.ttl = htons(0x0005);
  if(dns_type == htons(0x0001)){
   answer.data_len = htons(0x0004);
   reply_packet_size = request_packet_size + ((answer_size + 0x0004) * 0x0002);
   if((reply_packet = malloc(reply_packet_size)) != ((void *)0)){
    memcpy(reply_packet,request_packet,request_packet_size);
    memcpy_offset += request_packet_size;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,(void *) &ip_address1,0x0004);
    memcpy_offset += 0x0004;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,(void *) &ip_address2,0x0004);
   } else {
    perror("Malloc Failure");
    return 0;
   }
  } else if(dns_type == htons(0x0002)){
   answer.data_len = htons(0x0006);
   reply_packet_size = request_packet_size + ((answer_size + 0x0006) * 0x0002);
   if((reply_packet = malloc(reply_packet_size)) != ((void *)0)){
    memcpy(reply_packet,request_packet,request_packet_size);
    memcpy_offset += request_packet_size;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,"\x03ns1\xC0\x0C",0x0006);
    memcpy_offset += 0x0006;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,"\x03ns2\xC0\x0C",0x0006);
   } else {
    perror("Malloc Failure");
    return 0;
   }
  }
        header = (struct dns_header *) reply_packet;
        header->num_answers = htons(0x0002);
        header->flags = htons(0x8180);
  printf("\x1b[1;32m""FINAL STEP : Ready to send ...""\x1b[0m""\n");
 } else {
  printf("Failed to send DNS reply; DNS request packet appears to have an invalid length.\n");
 }
 return 0;
}

variable_types: sock int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types:
fqdn
char *

variable_types: struct dns_header { unsigned short xid; unsigned short flags; unsigned short num_questions; unsigned short num_answers; unsigned short num_authority; unsigned short num_additional; } *

variable_types: struct dns_answer_section { unsigned short name; unsigned short type; unsigned short class; unsigned short ttl_top; unsigned short ttl; unsigned short data_len; }

user_defined_types: struct dns_question_section { unsigned short type; unsigned short class; }