decompiled_code:
__int64 __fastcall clear_img(int a1)
{
__int64 result; // rax
_DWORD *v2; // rdx
__int64 v3; // rcx
__int64 v4; // rcx

result = (unsigned int)(HEIGHT * WIDTH);
if ( (int)result > 0 )
{
v2 = (_DWORD *)img;
v3 = (unsigned int)(result - 1);
result = img + 4LL;
v4 = img + 4LL + 4 * v3;
while ( 1 )
{
*v2 = a1;
v2 = (_DWORD *)result;
if ( result == v4 )
break;
result += 4LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax
_DWORD *v2; // rdx
__int64 v3; // rcx
__int64 v4; // rcx

result = (unsigned int)(HEIGHT * WIDTH);
if ( (int)result > 0 )
{
v2 = (_DWORD *)img;
v3 = (unsigned int)(result - 1);
result = img + 4LL;
v4 = img + 4LL + 4 * v3;
while ( 1 )
{
*v2 = a1;
v2 = (_DWORD *)result;
if ( result == v4 )
break;
result += 4LL;
}
}
return result;
}

original_code:
void clear_img(const Uint32 color)
{
 int x, len = WIDTH*HEIGHT;
 for (x=0;x<len;x++) {
  img[x] = color;
 }
}

canonical_original_code:
void clear_img(unsigned int color)
{
 int x; int len = WIDTH*HEIGHT;
 for (x=0;x<len;x++) {
  img[x] = color;
 }
}


repo: jabberx/snaps

decompiled_code:
void compute_yp()
{
float v0; // xmm0_4
float v1; // xmm0_4
float v2; // xmm0_4
float v3; // xmm1_4
double v4; // [rsp+8h] [rbp-20h]
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

sincos(yaw * DTR, sinx, &cosx);
v0 = cosx;
cosyaw = LODWORD(v0);
v4 = sinx[0];
sincos(pitch * DTR, sinx, &cosx);
v1 = cosx;
cospitch = LODWORD(v1);
v2 = sinx[0];
v3 = v4;
sinpitch = LODWORD(v2);
sinyaw = LODWORD(v3);
}

canonical_decompiled_code:
void func2()
{
float v0; // xmm0_4
float v1; // xmm0_4
float v2; // xmm0_4
float v3; // xmm1_4
double v4; // [rsp+8h] [rbp-20h]
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

sincos(yaw * DTR, sinx, &cosx);
v0 = cosx;
cosyaw = LODWORD(v0);
v4 = sinx[0];
sincos(pitch * DTR, sinx, &cosx);
v1 = cosx;
cospitch = LODWORD(v1);
v2 = sinx[0];
v3 = v4;
sinpitch = LODWORD(v2);
sinyaw = LODWORD(v3);
}

original_code:
void compute_yp()
{
 cosyaw = cos(yaw*DTR);
 cospitch = cos(pitch*DTR);
 sinyaw = sin(yaw*DTR);
 sinpitch = sin(pitch*DTR);
}

return_type: void


decompiled_code:
void compute_viewdir()
{
float v0; // xmm1_4
float v1; // xmm1_4
float v2; // xmm0_4
double v3; // [rsp+0h] [rbp-28h]
double v4; // [rsp+8h] [rbp-20h]
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

sincos((float)(yaw + 90.0) * DTR, sinx, &cosx);
v4 = cosx;
v3 = sinx[0];
sincos(pitch * DTR, sinx, &cosx);
v0 = v4 * cosx;
viewx = LODWORD(v0);
v1 = sinx[0];
v2 = cosx * v3;
viewy = LODWORD(v1);
viewz = LODWORD(v2);
}

canonical_decompiled_code:
void func3()
{
float v0; // xmm1_4
float v1; // xmm1_4
float v2; // xmm0_4
double v3; // [rsp+0h] [rbp-28h]
double v4; // [rsp+8h] [rbp-20h]
double cosx; // [rsp+10h] [rbp-18h] BYREF
double sinx[2]; // [rsp+18h] [rbp-10h] BYREF

sincos((float)(yaw + 90.0) * DTR, sinx, &cosx);
v4 = cosx;
v3 = sinx[0];
sincos(pitch * DTR, sinx, &cosx);
v0 = v4 * cosx;
viewx = LODWORD(v0);
v1 = sinx[0];
v2 = cosx * v3;
viewy = LODWORD(v1);
viewz = LODWORD(v2);
}

original_code:
void compute_viewdir()
{
 viewx = cos((yaw+90)*DTR) * cos(pitch*DTR);
 viewy = sin(pitch*DTR);
 viewz = sin((yaw+90)*DTR) * cos(pitch*DTR);
}


project

decompiled_code:
char __fastcall project(int a1, int a2, int a3, unsigned int a4, char a5, char a6, char a7, char a8)
{
float v11; // xmm2_4
float v12; // xmm1_4
float v13; // xmm0_4
float *v14; // rax
float v15; // xmm5_4
float v16; // xmm1_4
float v17; // xmm0_4
float v18; // xmm3_4
double v19; // xmm6_8
double v20; // xmm2_8
double v21; // xmm0_8
__int64 v22; // rdi
__int64 v23; // rsi
__int64 v24; // rdx

v11 = (double)a7 * 0.007874015748031496;
v12 = (double)a6 * 0.007874015748031496;
v13 = (double)a5 * 0.007874015748031496;
LOBYTE(v14) = is_back_culled(v13, v12, v11);
if ( (_BYTE)v14 )
{
LODWORD(v14) = (int)(float)((float)a1 - camx);
v15 = (float)(int)(float)((float)a3 - camz);
v16 = (float)((float)-(int)v14 * sinyaw) + (float)(cosyaw * v15);
v17 = (float)(int)(float)((float)a2 - camy);
v18 = (float)(v17 * sinpitch) + (float)(cospitch * v16);
if ( v18 <= 100000.0 && v18 >= 0.050000001 )
{
v19 = (float)(fov / v18);
v20 = (float)((float)((float)(int)v14 * cosyaw) + (float)(v15 * sinyaw)) * v19 + (double)(WIDTH / 2);
v21 = (float)((float)(v17 * cospitch) - (float)(v16 * sinpitch)) * v19 + (double)(HEIGHT / 2);
v22 = (unsigned int)(int)v20;
v23 = (unsigned int)(int)v21;
LOBYTE(v14) = (int)v21 < 0 || (int)v20 < 0 || WIDTH <= (int)v22;
if ( !(_BYTE)v14 && HEIGHT > (int)v23 )
{
v24 = (int)v22 + (int)v23 * WIDTH;
v14 = (float *)(zbuffer + 4 * v24);
if ( v18 < *v14 )
{
*v14 = v18;
*(_BYTE *)(NXbuf + v24) = a5;
*(_BYTE *)(NYbuf + v24) = a6;
*(_BYTE *)(NZbuf + v24) = a7;
*(_BYTE *)(SHbuf + v24) = a8;
LOBYTE(v14) = SDL_DrawPixel(v22, v23, a4);
}
}
}
}
return (char)v14;
}

canonical_decompiled_code:
char __fastcall func4(int a1, int a2, int a3, unsigned int a4, char a5, char a6, char a7, char a8)
{
float v11; // xmm2_4
float v12; // xmm1_4
float v13; // xmm0_4
float *v14; // rax
float v15; // xmm5_4
float v16; // xmm1_4
float v17; // xmm0_4
float v18; // xmm3_4
double v19; // xmm6_8
double v20; // xmm2_8
double v21; // xmm0_8
__int64 v22; // rdi
__int64 v23; // rsi
__int64 v24; // rdx

v11 = (double)a7 * 0.007874015748031496;
v12 = (double)a6 * 0.007874015748031496;
v13 = (double)a5 * 0.007874015748031496;
LOBYTE(v14) = is_back_culled(v13, v12, v11);
if ( (_BYTE)v14 )
{
LODWORD(v14) = (int)(float)((float)a1 - camx);
v15 = (float)(int)(float)((float)a3 - camz);
v16 = (float)((float)-(int)v14 * sinyaw) + (float)(cosyaw * v15);
v17 = (float)(int)(float)((float)a2 - camy);
v18 = (float)(v17 * sinpitch) + (float)(cospitch * v16);
if ( v18 <= 100000.0 && v18 >= 0.050000001 )
{
v19 = (float)(fov / v18);
v20 = (float)((float)((float)(int)v14 * cosyaw) + (float)(v15 * sinyaw)) * v19 + (double)(WIDTH / 2);
v21 = (float)((float)(v17 * cospitch) - (float)(v16 * sinpitch)) * v19 + (double)(HEIGHT / 2);
v22 = (unsigned int)(int)v20;
v23 = (unsigned int)(int)v21;
LOBYTE(v14) = (int)v21 < 0 || (int)v20 < 0 || WIDTH <= (int)v22;
if ( !(_BYTE)v14 && HEIGHT > (int)v23 )
{
v24 = (int)v22 + (int)v23 * WIDTH;
v14 = (float *)(zbuffer + 4 * v24);
if ( v18 < *v14 )
{
*v14 = v18;
*(_BYTE *)(NXbuf + v24) = a5;
*(_BYTE *)(NYbuf + v24) = a6;
*(_BYTE *)(NZbuf + v24) = a7;
*(_BYTE *)(SHbuf + v24) = a8;
LOBYTE(v14) = SDL_DrawPixel(v22, v23, a4);
}
}
}
}
return (char)v14;
}

original_code:
void project(int32_t x, int32_t y, int32_t z, uint32_t col,
    int8_t nx, int8_t ny, int8_t nz, uint8_t sh)
{
  float newx,newz0,newy,newz; int sx,sy;
  static const int marg=0; double nfov;
  const int32_t tx=x-camx, ty=y-camy, tz=z-camz;
  if (!is_back_culled(x,y,z,nx/127.0,ny/127.0,nz/127.0)) return;
  newx = tx * cosyaw + tz * sinyaw;
  newz0=-tx * sinyaw + tz * cosyaw;
  newy = ty * cospitch - newz0 * sinpitch;
  newz = ty * sinpitch + newz0 * cospitch;
  if (newz<0.05f || newz>100000) return;
  if (newz<0.05f) return; nfov = fov/newz;
  sx = WIDTH/2 + newx * nfov;
  sy = HEIGHT/2 + newy * nfov;
  if(sx<marg ||
      sx>WIDTH-marg-1 ||
      sy<marg ||
      sy>HEIGHT-marg-1) return;
  if(newz<zbuffer[sx+sy*WIDTH]) {
    zbuffer[sx+sy*WIDTH] = newz;
    NXbuf[sx+sy*WIDTH] = nx;
    NYbuf[sx+sy*WIDTH] = ny;
    NZbuf[sx+sy*WIDTH] = nz;
    SHbuf[sx+sy*WIDTH] = sh;
    SDL_DrawPixel(sx,sy,col); }
}

canonical_original_code:
void project(int x, int y, int z, unsigned int col, char nx, char ny, char nz, unsigned char sh)
{
  float newx; float newz0; float newy; float newz; int sx; int sy;
  static int marg = 0; double nfov;
  int tx = x-camx; int ty = y-camy; int tz = z-camz;
  if (!is_back_culled(x,y,z,nx/127.0,ny/127.0,nz/127.0)) return;
  newx = tx * cosyaw + tz * sinyaw;
  newz0=-tx * sinyaw + tz * cosyaw;
  newy = ty * cospitch - newz0 * sinpitch;
  newz = ty * sinpitch + newz0 * cospitch;
  if (newz<0.05f || newz>100000) return;
  if (newz<0.05f) return; nfov = fov/newz;
  sx = WIDTH/2 + newx * nfov;
  sy = HEIGHT/2 + newy * nfov;
  if(sx<marg ||
      sx>WIDTH-marg-1 ||
      sy<marg ||
      sy>HEIGHT-marg-1) return;
  if(newz<zbuffer[sx+sy*WIDTH]) {
    zbuffer[sx+sy*WIDTH] = newz;
    NXbuf[sx+sy*WIDTH] = nx;
    NYbuf[sx+sy*WIDTH] = ny;
    NZbuf[sx+sy*WIDTH] = nz;
    SHbuf[sx+sy*WIDTH] = sh;
    SDL_DrawPixel(sx,sy,col); }
}

variable_types: x int

variable_types: y int

variable_types: z int

variable_types:
col
unsigned int

variable_types: nx char

variable_types: ny char

variable_types: nz char

variable_types:
sh
unsigned char

variable_types: newx float

variable_types: newy float

variable_types: newz float

variable_types: sx int

variable_types: sy int

variable_types: marg int

variable_types: nfov double

variable_types: tx int

variable_types: ty int

variable_types: tz int


decompiled_code:
__int64 __fastcall project_render(int a1, int a2, int a3, int a4, char a5, char a6, char a7, char a8)
{
float v11; // xmm2_4
float v12; // xmm1_4
float v13; // xmm0_4
__int64 result; // rax
int v15; // edx
int v16; // ecx
float v17; // xmm1_4
float v18; // xmm3_4
int v19; // er10
int v20; // er9
__int64 v21; // rsi
float *v22; // rdi

v11 = (double)a7 * 0.007874015748031496;
v12 = (double)a6 * 0.007874015748031496;
v13 = (double)a5 * 0.007874015748031496;
result = is_back_culled(v13, v12, v11);
if ( (_BYTE)result )
{
result = (unsigned int)(int)(float)((float)a1 - camx);
v15 = (int)(float)((float)a2 - camy);
v16 = (int)(float)((float)a3 - camz);
v17 = (float)((float)-(int)(float)((float)a1 - camx) * sinyaw) + (float)(cosyaw * (float)v16);
v18 = (float)((float)v15 * sinpitch) + (float)(cospitch * v17);
if ( v18 <= 100000.0 && v18 >= 0.050000001 )
{
v19 = (int)(float)((float)((float)((float)((float)((float)v15 * cospitch) - (float)(v17 * sinpitch)) * fov) / v18)
+ (float)(HEIGHT / 2));
v20 = (int)(float)((float)((float)((float)((float)((float)(int)result * cosyaw) + (float)((float)v16 * sinyaw))
* fov)
/ v18)
+ (float)(WIDTH / 2));
if ( v19 >= 0 && v20 >= 0 && WIDTH > v20 && HEIGHT > v19 )
{
v21 = v20 + v19 * WIDTH;
v22 = (float *)(zbuffer + 4 * v21);
if ( v18 < *v22 )
{
*v22 = v18;
*(_DWORD *)(Xbuf + 4 * v21) = result;
*(_DWORD *)(Ybuf + 4 * v21) = v15;
*(_DWORD *)(Zbuf + 4 * v21) = v16;
*(_BYTE *)(NXbuf + v21) = a5;
*(_BYTE *)(NYbuf + v21) = a6;
*(_BYTE *)(NZbuf + v21) = a7;
*(_BYTE *)(SHbuf + v21) = a8;
result = img;
*(_DWORD *)(img + 4 * v21) = a4;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, int a2, int a3, int a4, char a5, char a6, char a7, char a8)
{
float v11; // xmm2_4
float v12; // xmm1_4
float v13; // xmm0_4
__int64 result; // rax
int v15; // edx
int v16; // ecx
float v17; // xmm1_4
float v18; // xmm3_4
int v19; // er10
int v20; // er9
__int64 v21; // rsi
float *v22; // rdi

v11 = (double)a7 * 0.007874015748031496;
v12 = (double)a6 * 0.007874015748031496;
v13 = (double)a5 * 0.007874015748031496;
result = is_back_culled(v13, v12, v11);
if ( (_BYTE)result )
{
result = (unsigned int)(int)(float)((float)a1 - camx);
v15 = (int)(float)((float)a2 - camy);
v16 = (int)(float)((float)a3 - camz);
v17 = (float)((float)-(int)(float)((float)a1 - camx) * sinyaw) + (float)(cosyaw * (float)v16);
v18 = (float)((float)v15 * sinpitch) + (float)(cospitch * v17);
if ( v18 <= 100000.0 && v18 >= 0.050000001 )
{
v19 = (int)(float)((float)((float)((float)((float)((float)v15 * cospitch) - (float)(v17 * sinpitch)) * fov) / v18)
+ (float)(HEIGHT / 2));
v20 = (int)(float)((float)((float)((float)((float)((float)(int)result * cosyaw) + (float)((float)v16 * sinyaw))
* fov)
/ v18)
+ (float)(WIDTH / 2));
if ( v19 >= 0 && v20 >= 0 && WIDTH > v20 && HEIGHT > v19 )
{
v21 = v20 + v19 * WIDTH;
v22 = (float *)(zbuffer + 4 * v21);
if ( v18 < *v22 )
{
*v22 = v18;
*(_DWORD *)(Xbuf + 4 * v21) = result;
*(_DWORD *)(Ybuf + 4 * v21) = v15;
*(_DWORD *)(Zbuf + 4 * v21) = v16;
*(_BYTE *)(NXbuf + v21) = a5;
*(_BYTE *)(NYbuf + v21) = a6;
*(_BYTE *)(NZbuf + v21) = a7;
*(_BYTE *)(SHbuf + v21) = a8;
result = img;
*(_DWORD *)(img + 4 * v21) = a4;
}
}
}
}
return result;
}

original_code:
void project_render
 (const int32_t x, const int32_t y, const int32_t z, uint32_t col,
  int8_t nx, int8_t ny, int8_t nz, uint8_t sh)
{
  float newx,newz0,newy,newz; int sx,sy;
  static const int marg=0;
  const int32_t tx=x-camx, ty=y-camy, tz=z-camz;
  if (!is_back_culled(x,y,z,nx/127.0,ny/127.0,nz/127.0)) return;
  newx = tx * cosyaw + tz * sinyaw;
  newz0=-tx * sinyaw + tz * cosyaw;
  newy = ty * cospitch - newz0 * sinpitch;
  newz = ty * sinpitch + newz0 * cospitch;
  if (newz<0.05f || newz>100000) return;
  if (newz<0.05f) return;
  sx = WIDTH/2 + newx * fov/newz;
  sy = HEIGHT/2 + newy * fov/newz;
  if(sx<marg ||
      sx>WIDTH-marg-1 ||
      sy<marg ||
      sy>HEIGHT-marg-1) return;
  if(newz<zbuffer[sx+sy*WIDTH]) {
    zbuffer[sx+sy*WIDTH] = newz;
    Xbuf[sx+sy*WIDTH] = tx;
    Ybuf[sx+sy*WIDTH] = ty;
    Zbuf[sx+sy*WIDTH] = tz;
    NXbuf[sx+sy*WIDTH] = nx;
    NYbuf[sx+sy*WIDTH] = ny;
    NZbuf[sx+sy*WIDTH] = nz;
    SHbuf[sx+sy*WIDTH] = sh;
    img[sx+sy*WIDTH] = col;
 }
}

canonical_original_code:
void project_render(int x, int y, int z, unsigned int col, char nx, char ny, char nz, unsigned char sh)
{
  float newx; float newz0; float newy; float newz; int sx; int sy;
  static int marg = 0;
  int tx = x-camx; int ty = y-camy; int tz = z-camz;
  if (!is_back_culled(x,y,z,nx/127.0,ny/127.0,nz/127.0)) return;
  newx = tx * cosyaw + tz * sinyaw;
  newz0=-tx * sinyaw + tz * cosyaw;
  newy = ty * cospitch - newz0 * sinpitch;
  newz = ty * sinpitch + newz0 * cospitch;
  if (newz<0.05f || newz>100000) return;
  if (newz<0.05f) return;
  sx = WIDTH/2 + newx * fov/newz;
  sy = HEIGHT/2 + newy * fov/newz;
  if(sx<marg ||
      sx>WIDTH-marg-1 ||
      sy<marg ||
      sy>HEIGHT-marg-1) return;
  if(newz<zbuffer[sx+sy*WIDTH]) {
    zbuffer[sx+sy*WIDTH] = newz;
    Xbuf[sx+sy*WIDTH] = tx;
    Ybuf[sx+sy*WIDTH] = ty;
    Zbuf[sx+sy*WIDTH] = tz;
    NXbuf[sx+sy*WIDTH] = nx;
    NYbuf[sx+sy*WIDTH] = ny;
    NZbuf[sx+sy*WIDTH] = nz;
    SHbuf[sx+sy*WIDTH] = sh;
    img[sx+sy*WIDTH] = col;
 }
}

variable_types: x int

variable_types: y int


decompiled_code:
void add_spec_to_img()
{
__int64 v0; // rbp
__int64 v1; // rdx
double v2; // xmm6_8
__int64 i; // rbx
float v4; // xmm2_4
float v5; // xmm1_4
float v6; // xmm0_4
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = (unsigned int)(HEIGHT * WIDTH);
if ( (_DWORD)v0 )
{
v1 = img;
v2 = *(double *)&LC2;
for ( i = 0LL; i != v0; ++i )
{
if ( *(_DWORD *)(v1 + 4 * i) != -828333920 )
{
v7[0] = *(_DWORD *)(v1 + 4 * i);
v4 = (double)*(char *)(NZbuf + i) * v2;
v5 = (double)*(char *)(NYbuf + i) * v2;
v6 = (double)*(char *)(NXbuf + i) * v2;
shade_spec(v7, *(unsigned __int8 *)(SHbuf + i), v6, v5, v4, lightx, lighty, lightz);
v1 = img;
*(_DWORD *)(img + 4 * i) = v7[0];
v2 = *(double *)&LC2;
}
}
}
}

canonical_decompiled_code:
void func6()
{
__int64 v0; // rbp
__int64 v1; // rdx
double v2; // xmm6_8
__int64 i; // rbx
float v4; // xmm2_4
float v5; // xmm1_4
float v6; // xmm0_4
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v0 = (unsigned int)(HEIGHT * WIDTH);
if ( (_DWORD)v0 )
{
v1 = img;
v2 = *(double *)&LC2;
for ( i = 0LL; i != v0; ++i )
{
if ( *(_DWORD *)(v1 + 4 * i) != -828333920 )
{
v7[0] = *(_DWORD *)(v1 + 4 * i);
v4 = (double)*(char *)(NZbuf + i) * v2;
v5 = (double)*(char *)(NYbuf + i) * v2;
v6 = (double)*(char *)(NXbuf + i) * v2;
shade_spec(v7, *(unsigned __int8 *)(SHbuf + i), v6, v5, v4, lightx, lighty, lightz);
v1 = img;
*(_DWORD *)(img + 4 * i) = v7[0];
v2 = *(double *)&LC2;
}
}
}
}

original_code:
void add_spec_to_img()
{
 uint32_t i, len = WIDTH*HEIGHT;
 Color32 c32;
 for (i=0;i<len;i++) {
  if (img[i]!=0xCEA0A0A0) {
   c32.col = img[i];
   shade_spec(&c32, NXbuf[i]/127.0, NYbuf[i]/127.0, NZbuf[i]/127.0,
        lightx, lighty, lightz, SHbuf[i]);
   img[i] = c32.col;
  }
 }
}

canonical_original_code:
void add_spec_to_img()
{
 unsigned int i; unsigned int len = WIDTH*HEIGHT;
 union Color32 c32;
 for (i=0;i<len;i++) {
  if (img[i]!=0xCEA0A0A0) {
   c32.col = img[i];
   shade_spec(&c32, NXbuf[i]/127.0, NYbuf[i]/127.0, NZbuf[i]/127.0,
        lightx, lighty, lightz, SHbuf[i]);
   img[i] = c32.col;
  }
 }
}

variable_types:
i
unsigned int

variable_types:
len
unsigned int

variable_types: union Color32 { unsigned int col; unsigned char rgba[4]; }


canonical_original_code:
void add_fog_to_img()
{
 unsigned int i; unsigned int len = WIDTH*HEIGHT;
 union Color32 c32; float z;
 for (i=0;i<len;i++) {
  if (img[i]!=0xCEA0A0A0) {
   z = zbuffer[i];
   if (z>0.02f) continue;
   z *= z * 100000 * 4;
   z > 1 ? z=1:0;
   z < 0.25f ? z=0.25f:0;
   c32.col = img[i];
   c32.rgba[0] *= z;
   c32.rgba[1] *= z;
   c32.rgba[2] *= z;
   c32.rgba[0] += 0x88 * (1-z);
   c32.rgba[1] += 0xDD * (1-z);
   c32.rgba[2] += 0xEE * (1-z);
   img[i] = c32.col;
  }
 }
}

variable_types: z float

user_defined_types: union Color32 { unsigned int col; unsigned char rgba[4]; }


decompiled_code:
__int64 __fastcall draw_cloud(_QWORD *a1, int a2, int a3, int a4, int a5)
{
__int64 result; // rax
unsigned int v6; // ebp
__int64 v7; // r14
__int64 v8; // r13
unsigned int v9; // er12
unsigned int v10; // er15
unsigned int v11; // eax
__int64 v12; // [rsp-10h] [rbp-68h]
unsigned int v13; // [rsp+Ch] [rbp-4Ch]

result = *(unsigned int *)a1;
v13 = result;
if ( (_DWORD)result )
{
v6 = 0;
do
{
v7 = *(unsigned __int8 *)(a1[8] + v6);
v8 = (unsigned int)*(char *)(a1[7] + v6);
v9 = *(char *)(a1[6] + v6);
v10 = *(char *)(a1[5] + v6);
v11 = high2true(*(unsigned __int16 *)(a1[4] + 2LL * v6));
project(
(unsigned int)(*(_DWORD *)(a1[1] + 4LL * v6) + a2),
(unsigned int)(*(_DWORD *)(a1[2] + 4LL * v6) + a3),
(unsigned int)(*(_DWORD *)(a1[3] + 4LL * v6) + a4),
v11,
v10,
v9,
v8,
v7);
v6 += a5;
result = v12;
}
while ( v13 > v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, int a2, int a3, int a4, int a5)
{
__int64 result; // rax
unsigned int v6; // ebp
__int64 v7; // r14
__int64 v8; // r13
unsigned int v9; // er12
unsigned int v10; // er15
unsigned int v11; // eax
__int64 v12; // [rsp-10h] [rbp-68h]
unsigned int v13; // [rsp+Ch] [rbp-4Ch]

result = *(unsigned int *)a1;
v13 = result;
if ( (_DWORD)result )
{
v6 = 0;
do
{
v7 = *(unsigned __int8 *)(a1[8] + v6);
v8 = (unsigned int)*(char *)(a1[7] + v6);
v9 = *(char *)(a1[6] + v6);
v10 = *(char *)(a1[5] + v6);
v11 = high2true(*(unsigned __int16 *)(a1[4] + 2LL * v6));
project(
(unsigned int)(*(_DWORD *)(a1[1] + 4LL * v6) + a2),
(unsigned int)(*(_DWORD *)(a1[2] + 4LL * v6) + a3),
(unsigned int)(*(_DWORD *)(a1[3] + 4LL * v6) + a4),
v11,
v10,
v9,
v8,
v7);
v6 += a5;
result = v12;
}
while ( v13 > v6 );
}
return result;
}

original_code:
void draw_cloud
 (Cloud *cloud,
 const int32_t xo, const int32_t yo, const int32_t zo, const uint32_t skip)
{
 uint32_t i, len = cloud->s;
 for (i=0; i<len; i+=skip) {
  project(
   cloud->x[i]+xo, cloud->y[i]+yo, cloud->z[i]+zo,
   high2true(cloud->c[i]),
   cloud->nx[i], cloud->ny[i], cloud->nz[i], cloud->sh[i]
  );
 }
}

canonical_original_code:
void draw_cloud(struct Cloud *cloud, int xo, int yo, int zo, unsigned int skip)
{
 unsigned int i; unsigned int len = cloud->s;
 for (i=0; i<len; i+=skip) {
  project(
   cloud->x[i]+xo, cloud->y[i]+yo, cloud->z[i]+zo,
   high2true(cloud->c[i]),
   cloud->nx[i], cloud->ny[i], cloud->nz[i], cloud->sh[i]
  );
 }
}

variable_types: struct Cloud { unsigned int s; int *x; unsigned short *c; char *nx; unsigned char *sh; } *

variable_types: xo int

variable_types: yo int

variable_types: zo int

variable_types:
skip
unsigned int


decompiled_code:
__int64 __fastcall render_cloud(_QWORD *a1, int a2, int a3, int a4, int a5)
{
__int64 result; // rax
unsigned int v6; // ebp
__int64 v7; // r14
__int64 v8; // r13
unsigned int v9; // er12
unsigned int v10; // er15
unsigned int v11; // eax
__int64 v12; // [rsp-10h] [rbp-68h]
unsigned int v13; // [rsp+Ch] [rbp-4Ch]

result = *(unsigned int *)a1;
v13 = result;
if ( (_DWORD)result )
{
v6 = 0;
do
{
v7 = *(unsigned __int8 *)(a1[8] + v6);
v8 = (unsigned int)*(char *)(a1[7] + v6);
v9 = *(char *)(a1[6] + v6);
v10 = *(char *)(a1[5] + v6);
v11 = high2true(*(unsigned __int16 *)(a1[4] + 2LL * v6));
project_render(
(unsigned int)(*(_DWORD *)(a1[1] + 4LL * v6) + a2),
(unsigned int)(*(_DWORD *)(a1[2] + 4LL * v6) + a3),
(unsigned int)(*(_DWORD *)(a1[3] + 4LL * v6) + a4),
v11,
v10,
v9,
v8,
v7);
v6 += a5;
result = v12;
}
while ( v13 > v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2, int a3, int a4, int a5)
{
__int64 result; // rax
unsigned int v6; // ebp
__int64 v7; // r14
__int64 v8; // r13
unsigned int v9; // er12
unsigned int v10; // er15
unsigned int v11; // eax
__int64 v12; // [rsp-10h] [rbp-68h]
unsigned int v13; // [rsp+Ch] [rbp-4Ch]

result = *(unsigned int *)a1;
v13 = result;
if ( (_DWORD)result )
{
v6 = 0;
do
{
v7 = *(unsigned __int8 *)(a1[8] + v6);
v8 = (unsigned int)*(char *)(a1[7] + v6);
v9 = *(char *)(a1[6] + v6);
v10 = *(char *)(a1[5] + v6);
v11 = high2true(*(unsigned __int16 *)(a1[4] + 2LL * v6));
project_render(
(unsigned int)(*(_DWORD *)(a1[1] + 4LL * v6) + a2),
(unsigned int)(*(_DWORD *)(a1[2] + 4LL * v6) + a3),
(unsigned int)(*(_DWORD *)(a1[3] + 4LL * v6) + a4),
v11,
v10,
v9,
v8,
v7);
v6 += a5;
result = v12;
}
while ( v13 > v6 );
}
return result;
}

original_code:
void render_cloud
 (Cloud *cloud,
 const int32_t xo, const int32_t yo, const int32_t zo, const uint32_t skip)
{
 uint32_t i, len = cloud->s;
 for (i=0; i<len; i+=skip) {
  project_render(
   cloud->x[i]+xo, cloud->y[i]+yo, cloud->z[i]+zo,
   high2true(cloud->c[i]),
   cloud->nx[i], cloud->ny[i], cloud->nz[i], cloud->sh[i]
  );
 }
}

canonical_original_code:
void render_cloud(struct Cloud *cloud, int xo, int yo, int zo, unsigned int skip)
{
 unsigned int i; unsigned int len = cloud->s;
 for (i=0; i<len; i+=skip) {
  project_render(
   cloud->x[i]+xo, cloud->y[i]+yo, cloud->z[i]+zo,
   high2true(cloud->c[i]),
   cloud->nx[i], cloud->ny[i], cloud->nz[i], cloud->sh[i]
  );
 }
}

user_defined_types: struct Cloud { unsigned int s; int *x; unsigned short *c; char *nx; unsigned char *sh; }


decompiled_code:
void *SDL_Initialize()
{
int v0; // ebx
void *result; // rax

v0 = WIDTH * HEIGHT;
screen = SDL_SetVideoMode(WIDTH, HEIGHT, 32LL, 1LL);
result = malloc(4LL * v0);
img = result;
return result;
}

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

v0 = WIDTH * HEIGHT;
screen = SDL_SetVideoMode(WIDTH, HEIGHT, 32LL, 1LL);
result = malloc(4LL * v0);
img = result;
return result;
}

original_code:
void SDL_Initialize()
{
 screen = SDL_SetVideoMode(WIDTH, HEIGHT, 32, 0x00000001);
 img = (Uint32*)malloc(WIDTH*HEIGHT*sizeof(Uint32));
}

canonical_original_code:
void SDL_Initialize()
{
 screen = SDL_SetVideoMode(WIDTH, HEIGHT, 32, 0x00000001);
 img = (unsigned int *)malloc(WIDTH*HEIGHT*sizeof(Uint32));
}


decompiled_code:
__int64 SDL_FlipScreen()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = screen;
if ( *(_DWORD *)(screen + 40LL) || (*screen & 0x4005) != 0 )
{
result = SDL_LockSurface();
if ( (int)result < 0 )
return result;
v0 = screen;
}
memcpy(*(void **)(v0 + 32), img, 4LL * HEIGHT * WIDTH);
if ( *(_DWORD *)(screen + 40LL) || (*screen & 0x4005) != 0 )
SDL_UnlockSurface();
return SDL_Flip();
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rdi
__int64 result; // rax

v0 = screen;
if ( *(_DWORD *)(screen + 40LL) || (*screen & 0x4005) != 0 )
{
result = SDL_LockSurface();
if ( (int)result < 0 )
return result;
v0 = screen;
}
memcpy(*(void **)(v0 + 32), img, 4LL * HEIGHT * WIDTH);
if ( *(_DWORD *)(screen + 40LL) || (*screen & 0x4005) != 0 )
SDL_UnlockSurface();
return SDL_Flip();
}

original_code:
void SDL_FlipScreen()
{
 if((screen->offset || ((screen->flags & (0x00000001|0x00000004|0x00004000)) != 0))) if(SDL_LockSurface(screen)<0) return;
 memcpy(screen->pixels, img, WIDTH*HEIGHT*sizeof(int));
 if((screen->offset || ((screen->flags & (0x00000001|0x00000004|0x00004000)) != 0))) SDL_UnlockSurface(screen);
 SDL_Flip(screen);
}


decompiled_code:
__int64 SDL_HandleEvents()
{
__int64 result; // rax
char v1; // al
char v2; // al
int v3; // eax
int v4; // eax

LABEL_1:
while ( 1 )
{
result = SDL_PollEvent(&event);
if ( !(_DWORD)result )
return result;
while ( 1 )
{
if ( event == 4 )
{
MOUSEX = *((unsigned __int16 *)&event + 2);
MOUSEY = *((unsigned __int16 *)&event + 3);
goto LABEL_1;
}
if ( event == 12 )
{
exit_flag = 1;
SDL_Quit();
exit(1);
}
if ( event != 5 )
break;
MOUSEX = *((unsigned __int16 *)&event + 2);
MOUSEY = *((unsigned __int16 *)&event + 3);
v1 = *((_BYTE *)&event + 2);
if ( v1 == 1 )
{
BUTTON[0] = 1;
goto LABEL_1;
}
if ( v1 == 2 )
{
BUTTON[1] = 1;
goto LABEL_1;
}
if ( v1 != 3 )
{
if ( v1 == 4 )
{
BUTTON[3] = 1;
}
else if ( v1 == 5 )
{
BUTTON[4] = 1;
}
goto LABEL_1;
}
BUTTON[2] = 1;
result = SDL_PollEvent(&event);
if ( !(_DWORD)result )
return result;
}
switch ( event )
{
case 6:
MOUSEX = *((unsigned __int16 *)&event + 2);
MOUSEY = *((unsigned __int16 *)&event + 3);
v2 = *((_BYTE *)&event + 2);
switch ( v2 )
{
case 1:
BUTTON[0] = 0;
break;
case 2:
BUTTON[1] = 0;
break;
case 3:
BUTTON[2] = 0;
break;
case 4:
BUTTON[3] = 0;
break;
case 5:
BUTTON[4] = 0;
break;
}
break;
case 2:
v3 = *((_DWORD *)&event + 2);
switch ( v3 )
{
case 8:
KEY[0] = 1;
break;
case 9:
KEY[1] = 1;
break;
case 12:
KEY[2] = 1;
break;
case 13:
KEY[3] = 1;
break;
case 19:
KEY[4] = 1;
break;
case 27:
KEY[5] = 1;
break;
case 32:
KEY[6] = 1;
break;
case 33:
KEY[7] = 1;
break;
case 34:
KEY[8] = 1;
break;
case 35:
KEY[9] = 1;
break;
case 36:
KEY[10] = 1;
break;
case 38:
KEY[11] = 1;
break;
case 39:
KEY[12] = 1;
break;
case 40:
KEY[13] = 1;
break;
case 41:
KEY[14] = 1;
break;
case 42:
KEY[15] = 1;
break;
case 43:
KEY[16] = 1;
break;
case 44:
KEY[17] = 1;
break;
case 45:
KEY[18] = 1;
break;
case 46:
KEY[19] = 1;
break;
case 47:
KEY[20] = 1;
break;
case 48:
KEY[21] = 1;
break;
case 49:
KEY[22] = 1;
break;
case 50:
KEY[23] = 1;
break;
case 51:
KEY[24] = 1;
break;
case 52:
KEY[25] = 1;
break;
case 53:
KEY[26] = 1;
break;
case 54:
KEY[27] = 1;
break;
case 55:
KEY[28] = 1;
break;
case 56:
KEY[29] = 1;
break;
case 57:
KEY[30] = 1;
break;
case 58:
KEY[31] = 1;
break;
case 59:
KEY[32] = 1;
break;
case 60:
KEY[33] = 1;
break;
case 61:
KEY[34] = 1;
break;
case 62:
KEY[35] = 1;
break;
case 63:
KEY[36] = 1;
break;
case 64:
KEY[37] = 1;
break;
case 91:
KEY[38] = 1;
break;
case 92:
KEY[39] = 1;
break;
case 93:
KEY[40] = 1;
break;
case 94:
KEY[41] = 1;
break;
case 95:
KEY[42] = 1;
break;
case 96:
KEY[43] = 1;
break;
case 97:
KEY[44] = 1;
break;
case 98:
KEY[45] = 1;
break;
case 99:
KEY[46] = 1;
break;
case 100:
KEY[47] = 1;
break;
case 101:
KEY[48] = 1;
break;
case 102:
KEY[49] = 1;
break;
case 103:
KEY[50] = 1;
break;
case 104:
KEY[51] = 1;
break;
case 105:
KEY[52] = 1;
break;
case 106:
KEY[53] = 1;
break;
case 107:
KEY[54] = 1;
break;
case 108:
KEY[55] = 1;
break;
case 109:
KEY[56] = 1;
break;
case 110:
KEY[57] = 1;
break;
case 111:
KEY[58] = 1;
break;
case 112:
KEY[59] = 1;
break;
case 113:
KEY[60] = 1;
break;
case 114:
KEY[61] = 1;
break;
case 115:
KEY[62] = 1;
break;
case 116:
KEY[63] = 1;
break;
case 117:
KEY[64] = 1;
break;
case 118:
KEY[65] = 1;
break;
case 119:
KEY[66] = 1;
break;
case 120:
KEY[67] = 1;
break;
case 121:
KEY[68] = 1;
break;
case 122:
KEY[69] = 1;
break;
case 127:
KEY[70] = 1;
break;
case 256:
KEY[71] = 1;
break;
case 257:
KEY[72] = 1;
break;
case 258:
KEY[73] = 1;
break;
case 259:
KEY[74] = 1;
break;
case 260:
KEY[75] = 1;
break;
case 261:
KEY[76] = 1;
break;
case 262:
KEY[77] = 1;
break;
case 263:
KEY[78] = 1;
break;
case 264:
KEY[79] = 1;
break;
case 265:
KEY[80] = 1;
break;
case 266:
KEY[81] = 1;
break;
case 267:
KEY[82] = 1;
break;
case 268:
KEY[83] = 1;
break;
case 269:
KEY[84] = 1;
break;
case 270:
KEY[85] = 1;
break;
case 271:
KEY[86] = 1;
break;
case 272:
KEY[87] = 1;
break;
case 273:
KEY[88] = 1;
break;
case 274:
KEY[89] = 1;
break;
case 275:
KEY[90] = 1;
break;
case 276:
KEY[91] = 1;
break;
case 277:
KEY[92] = 1;
break;
case 278:
KEY[93] = 1;
break;
case 279:
KEY[94] = 1;
break;
case 280:
KEY[95] = 1;
break;
case 281:
KEY[96] = 1;
break;
case 282:
KEY[97] = 1;
break;
case 283:
KEY[98] = 1;
break;
case 284:
KEY[99] = 1;
break;
case 285:
KEY[100] = 1;
break;
case 286:
KEY[101] = 1;
break;
case 287:
KEY[102] = 1;
break;
case 288:
KEY[103] = 1;
break;
case 289:
KEY[104] = 1;
break;
case 290:
KEY[105] = 1;
break;
case 291:
KEY[106] = 1;
break;
case 292:
KEY[107] = 1;
break;
case 293:
KEY[108] = 1;
break;
case 294:
KEY[109] = 1;
break;
case 295:
KEY[110] = 1;
break;
case 296:
KEY[111] = 1;
break;
case 300:
KEY[112] = 1;
break;
case 301:
KEY[113] = 1;
break;
case 302:
KEY[114] = 1;
break;
case 303:
KEY[115] = 1;
break;
case 304:
KEY[116] = 1;
break;
case 305:
KEY[117] = 1;
break;
case 306:
KEY[118] = 1;
break;
case 307:
KEY[119] = 1;
break;
case 308:
KEY[120] = 1;
break;
}
break;
case 3:
v4 = *((_DWORD *)&event + 2);
switch ( v4 )
{
case 8:
KEY[0] = 0;
break;
case 9:
KEY[1] = 0;
break;
case 12:
KEY[2] = 0;
break;
case 13:
KEY[3] = 0;
break;
case 19:
KEY[4] = 0;
break;
case 27:
KEY[5] = 0;
break;
case 32:
KEY[6] = 0;
break;
case 33:
KEY[7] = 0;
break;
case 34:
KEY[8] = 0;
break;
case 35:
KEY[9] = 0;
break;
case 36:
KEY[10] = 0;
break;
case 38:
KEY[11] = 0;
break;
case 39:
KEY[12] = 0;
break;
case 40:
KEY[13] = 0;
break;
case 41:
KEY[14] = 0;
break;
case 42:
KEY[15] = 0;
break;
case 43:
KEY[16] = 0;
break;
case 44:
KEY[17] = 0;
break;
case 45:
KEY[18] = 0;
break;
case 46:
KEY[19] = 0;
break;
case 47:
KEY[20] = 0;
break;
case 48:
KEY[21] = 0;
break;
case 49:
KEY[22] = 0;
break;
case 50:
KEY[23] = 0;
break;
case 51:
KEY[24] = 0;
break;
case 52:
KEY[25] = 0;
break;
case 53:
KEY[26] = 0;
break;
case 54:
KEY[27] = 0;
break;
case 55:
KEY[28] = 0;
break;
case 56:
KEY[29] = 0;
break;
case 57:
KEY[30] = 0;
break;
case 58:
KEY[31] = 0;
break;
case 59:
KEY[32] = 0;
break;
case 60:
KEY[33] = 0;
break;
case 61:
KEY[34] = 0;
break;
case 62:
KEY[35] = 0;
break;
case 63:
KEY[36] = 0;
break;
case 64:
KEY[37] = 0;
break;
case 91:
KEY[38] = 0;
break;
case 92:
KEY[39] = 0;
break;
case 93:
KEY[40] = 0;
break;
case 94:
KEY[41] = 0;
break;
case 95:
KEY[42] = 0;
break;
case 96:
KEY[43] = 0;
break;
case 97:
KEY[44] = 0;
break;
case 98:
KEY[45] = 0;
break;
case 99:
KEY[46] = 0;
break;
case 100:
KEY[47] = 0;
break;
case 101:
KEY[48] = 0;
break;
case 102:
KEY[49] = 0;
break;
case 103:
KEY[50] = 0;
break;
case 104:
KEY[51] = 0;
break;
case 105:
KEY[52] = 0;
break;
case 106:
KEY[53] = 0;
break;
case 107:
KEY[54] = 0;
break;
case 108:
KEY[55] = 0;
break;
case 109:
KEY[56] = 0;
break;
case 110:
KEY[57] = 0;
break;
case 111:
KEY[58] = 0;
break;
case 112:
KEY[59] = 0;
break;
case 113:
KEY[60] = 0;
break;
case 114:
KEY[61] = 0;
break;
case 115:
KEY[62] = 0;
break;
case 116:
KEY[63] = 0;
break;
case 117:
KEY[64] = 0;
break;
case 118:
KEY[65] = 0;
break;
case 119:
KEY[66] = 0;
break;
case 120:
KEY[67] = 0;
break;
case 121:
KEY[68] = 0;
break;
case 122:
KEY[69] = 0;
break;
case 127:
KEY[70] = 0;
break;
case 256:
KEY[71] = 0;
break;
case 257:
KEY[72] = 0;
break;
case 258:
KEY[73] = 0;
break;
case 259:
KEY[74] = 0;
break;
case 260:
KEY[75] = 0;
break;
case 261:
KEY[76] = 0;
break;
case 262:
KEY[77] = 0;
break;
case 263:
KEY[78] = 0;
break;
case 264:
KEY[79] = 0;
break;
case 265:
KEY[80] = 0;
break;
case 266:
KEY[81] = 0;
break;
case 267:
KEY[82] = 0;
break;
case 268:
KEY[83] = 0;
break;
case 269:
KEY[84] = 0;
break;
case 270:
KEY[85] = 0;
break;
case 271:
KEY[86] = 0;
break;
case 272:
KEY[87] = 0;
break;
case 273:
KEY[88] = 0;
break;
case 274:
KEY[89] = 0;
break;
case 275:
KEY[90] = 0;
break;
case 276:
KEY[91] = 0;
break;
case 277:
KEY[92] = 0;
break;
case 278:
KEY[93] = 0;
break;
case 279:
KEY[94] = 0;
break;
case 280:
KEY[95] = 0;
break;
case 281:
KEY[96] = 0;
break;
case 282:
KEY[97] = 0;
break;
case 283:
KEY[98] = 0;
break;
case 284:
KEY[99] = 0;
break;
case 285:
KEY[100] = 0;
break;
case 286:
KEY[101] = 0;
break;
case 287:
KEY[102] = 0;
break;
case 288:
KEY[103] = 0;
break;
case 289:
KEY[104] = 0;
break;
case 290:
KEY[105] = 0;
break;
case 291:
KEY[106] = 0;
break;
case 292:
KEY[107] = 0;
break;
case 293:
KEY[108] = 0;
break;
case 294:
KEY[109] = 0;
break;
case 295:
KEY[110] = 0;
break;
case 296:
KEY[111] = 0;
break;
case 300:
KEY[112] = 0;
break;
case 301:
KEY[113] = 0;
break;
case 302:
KEY[114] = 0;
break;
case 303:
KEY[115] = 0;
break;
case 304:
KEY[116] = 0;
break;
case 305:
KEY[117] = 0;
break;
case 306:
KEY[118] = 0;
break;
case 307:
KEY[119] = 0;
break;
case 308:
KEY[120] = 0;
break;
}
break;
}
}
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char v1; // al
char v2; // al
int v3; // eax
int v4; // eax

LABEL_1:
while ( 1 )
{
result = SDL_PollEvent(&event);
if ( !(_DWORD)result )
return result;
while ( 1 )
{
if ( event == 4 )
{
MOUSEX = *((unsigned __int16 *)&event + 2);
MOUSEY = *((unsigned __int16 *)&event + 3);
goto LABEL_1;
}
if ( event == 12 )
{
exit_flag = 1;
SDL_Quit();
exit(1);
}
if ( event != 5 )
break;
MOUSEX = *((unsigned __int16 *)&event + 2);
MOUSEY = *((unsigned __int16 *)&event + 3);
v1 = *((_BYTE *)&event + 2);
if ( v1 == 1 )
{
BUTTON[0] = 1;
goto LABEL_1;
}
if ( v1 == 2 )
{
BUTTON[1] = 1;
goto LABEL_1;
}
if ( v1 != 3 )
{
if ( v1 == 4 )
{
BUTTON[3] = 1;
}
else if ( v1 == 5 )
{
BUTTON[4] = 1;
}
goto LABEL_1;
}
BUTTON[2] = 1;
result = SDL_PollEvent(&event);
if ( !(_DWORD)result )
return result;
}
switch ( event )
{
case 6:
MOUSEX = *((unsigned __int16 *)&event + 2);
MOUSEY = *((unsigned __int16 *)&event + 3);
v2 = *((_BYTE *)&event + 2);
switch ( v2 )
{
case 1:
BUTTON[0] = 0;
break;
case 2:
BUTTON[1] = 0;
break;
case 3:
BUTTON[2] = 0;
break;
case 4:
BUTTON[3] = 0;
break;
case 5:
BUTTON[4] = 0;
break;
}
break;
case 2:
v3 = *((_DWORD *)&event + 2);
switch ( v3 )
{
case 8:
KEY[0] = 1;
break;
case 9:
KEY[1] = 1;
break;
case 12:
KEY[2] = 1;
break;
case 13:
KEY[3] = 1;
break;
case 19:
KEY[4] = 1;
break;
case 27:
KEY[5] = 1;
break;
case 32:
KEY[6] = 1;
break;
case 33:
KEY[7] = 1;
break;
case 34:
KEY[8] = 1;
break;
case 35:
KEY[9] = 1;
break;
case 36:
KEY[10] = 1;
break;
case 38:
KEY[11] = 1;
break;
case 39:
KEY[12] = 1;
break;
case 40:
KEY[13] = 1;
break;
case 41:
KEY[14] = 1;
break;
case 42:
KEY[15] = 1;
break;
case 43:
KEY[16] = 1;
break;
case 44:
KEY[17] = 1;
break;
case 45:
KEY[18] = 1;
break;
case 46:
KEY[19] = 1;
break;
case 47:
KEY[20] = 1;
break;
case 48:
KEY[21] = 1;
break;
case 49:
KEY[22] = 1;
break;
case 50:
KEY[23] = 1;
break;
case 51:
KEY[24] = 1;
break;
case 52:
KEY[25] = 1;
break;
case 53:
KEY[26] = 1;
break;
case 54:
KEY[27] = 1;
break;
case 55:
KEY[28] = 1;
break;
case 56:
KEY[29] = 1;
break;
case 57:
KEY[30] = 1;
break;
case 58:
KEY[31] = 1;
break;
case 59:
KEY[32] = 1;
break;
case 60:
KEY[33] = 1;
break;
case 61:
KEY[34] = 1;
break;
case 62:
KEY[35] = 1;
break;
case 63:
KEY[36] = 1;
break;
case 64:
KEY[37] = 1;
break;
case 91:
KEY[38] = 1;
break;
case 92:
KEY[39] = 1;
break;
case 93:
KEY[40] = 1;
break;
case 94:
KEY[41] = 1;
break;
case 95:
KEY[42] = 1;
break;
case 96:
KEY[43] = 1;
break;
case 97:
KEY[44] = 1;
break;
case 98:
KEY[45] = 1;
break;
case 99:
KEY[46] = 1;
break;
case 100:
KEY[47] = 1;
break;
case 101:
KEY[48] = 1;
break;
case 102:
KEY[49] = 1;
break;
case 103:
KEY[50] = 1;
break;
case 104:
KEY[51] = 1;
break;
case 105:
KEY[52] = 1;
break;
case 106:
KEY[53] = 1;
break;
case 107:
KEY[54] = 1;
break;
case 108:
KEY[55] = 1;
break;
case 109:
KEY[56] = 1;
break;
case 110:
KEY[57] = 1;
break;
case 111:
KEY[58] = 1;
break;
case 112:
KEY[59] = 1;
break;
case 113:
KEY[60] = 1;
break;
case 114:
KEY[61] = 1;
break;
case 115:
KEY[62] = 1;
break;
case 116:
KEY[63] = 1;
break;
case 117:
KEY[64] = 1;
break;
case 118:
KEY[65] = 1;
break;
case 119:
KEY[66] = 1;
break;
case 120:
KEY[67] = 1;
break;
case 121:
KEY[68] = 1;
break;
case 122:
KEY[69] = 1;
break;
case 127:
KEY[70] = 1;
break;
case 256:
KEY[71] = 1;
break;
case 257:
KEY[72] = 1;
break;
case 258:
KEY[73] = 1;
break;
case 259:
KEY[74] = 1;
break;
case 260:
KEY[75] = 1;
break;
case 261:
KEY[76] = 1;
break;
case 262:
KEY[77] = 1;
break;
case 263:
KEY[78] = 1;
break;
case 264:
KEY[79] = 1;
break;
case 265:
KEY[80] = 1;
break;
case 266:
KEY[81] = 1;
break;
case 267:
KEY[82] = 1;
break;
case 268:
KEY[83] = 1;
break;
case 269:
KEY[84] = 1;
break;
case 270:
KEY[85] = 1;
break;
case 271:
KEY[86] = 1;
break;
case 272:
KEY[87] = 1;
break;
case 273:
KEY[88] = 1;
break;
case 274:
KEY[89] = 1;
break;
case 275:
KEY[90] = 1;
break;
case 276:
KEY[91] = 1;
break;
case 277:
KEY[92] = 1;
break;
case 278:
KEY[93] = 1;
break;
case 279:
KEY[94] = 1;
break;
case 280:
KEY[95] = 1;
break;
case 281:
KEY[96] = 1;
break;
case 282:
KEY[97] = 1;
break;
case 283:
KEY[98] = 1;
break;
case 284:
KEY[99] = 1;
break;
case 285:
KEY[100] = 1;
break;
case 286:
KEY[101] = 1;
break;
case 287:
KEY[102] = 1;
break;
case 288:
KEY[103] = 1;
break;
case 289:
KEY[104] = 1;
break;
case 290:
KEY[105] = 1;
break;
case 291:
KEY[106] = 1;
break;
case 292:
KEY[107] = 1;
break;
case 293:
KEY[108] = 1;
break;
case 294:
KEY[109] = 1;
break;
case 295:
KEY[110] = 1;
break;
case 296:
KEY[111] = 1;
break;
case 300:
KEY[112] = 1;
break;
case 301:
KEY[113] = 1;
break;
case 302:
KEY[114] = 1;
break;
case 303:
KEY[115] = 1;
break;
case 304:
KEY[116] = 1;
break;
case 305:
KEY[117] = 1;
break;
case 306:
KEY[118] = 1;
break;
case 307:
KEY[119] = 1;
break;
case 308:
KEY[120] = 1;
break;
}
break;
case 3:
v4 = *((_DWORD *)&event + 2);
switch ( v4 )
{
case 8:
KEY[0] = 0;
break;
case 9:
KEY[1] = 0;
break;
case 12:
KEY[2] = 0;
break;
case 13:
KEY[3] = 0;
break;
case 19:
KEY[4] = 0;
break;
case 27:
KEY[5] = 0;
break;
case 32:
KEY[6] = 0;
break;
case 33:
KEY[7] = 0;
break;
case 34:
KEY[8] = 0;
break;
case 35:
KEY[9] = 0;
break;
case 36:
KEY[10] = 0;
break;
case 38:
KEY[11] = 0;
break;
case 39:
KEY[12] = 0;
break;
case 40:
KEY[13] = 0;
break;
case 41:
KEY[14] = 0;
break;
case 42:
KEY[15] = 0;
break;
case 43:
KEY[16] = 0;
break;
case 44:
KEY[17] = 0;
break;
case 45:
KEY[18] = 0;
break;
case 46:
KEY[19] = 0;
break;
case 47:
KEY[20] = 0;
break;
case 48:
KEY[21] = 0;
break;
case 49:
KEY[22] = 0;
break;
case 50:
KEY[23] = 0;
break;
case 51:
KEY[24] = 0;
break;
case 52:
KEY[25] = 0;
break;
case 53:
KEY[26] = 0;
break;
case 54:
KEY[27] = 0;
break;
case 55:
KEY[28] = 0;
break;
case 56:
KEY[29] = 0;
break;
case 57:
KEY[30] = 0;
break;
case 58:
KEY[31] = 0;
break;
case 59:
KEY[32] = 0;
break;
case 60:
KEY[33] = 0;
break;
case 61:
KEY[34] = 0;
break;
case 62:
KEY[35] = 0;
break;
case 63:
KEY[36] = 0;
break;
case 64:
KEY[37] = 0;
break;
case 91:
KEY[38] = 0;
break;
case 92:
KEY[39] = 0;
break;
case 93:
KEY[40] = 0;
break;
case 94:
KEY[41] = 0;
break;
case 95:
KEY[42] = 0;
break;
case 96:
KEY[43] = 0;
break;
case 97:
KEY[44] = 0;
break;
case 98:
KEY[45] = 0;
break;
case 99:
KEY[46] = 0;
break;
case 100:
KEY[47] = 0;
break;
case 101:
KEY[48] = 0;
break;
case 102:
KEY[49] = 0;
break;
case 103:
KEY[50] = 0;
break;
case 104:
KEY[51] = 0;
break;
case 105:
KEY[52] = 0;
break;
case 106:
KEY[53] = 0;
break;
case 107:
KEY[54] = 0;
break;
case 108:
KEY[55] = 0;
break;
case 109:
KEY[56] = 0;
break;
case 110:
KEY[57] = 0;
break;
case 111:
KEY[58] = 0;
break;
case 112:
KEY[59] = 0;
break;
case 113:
KEY[60] = 0;
break;
case 114:
KEY[61] = 0;
break;
case 115:
KEY[62] = 0;
break;
case 116:
KEY[63] = 0;
break;
case 117:
KEY[64] = 0;
break;
case 118:
KEY[65] = 0;
break;
case 119:
KEY[66] = 0;
break;
case 120:
KEY[67] = 0;
break;
case 121:
KEY[68] = 0;
break;
case 122:
KEY[69] = 0;
break;
case 127:
KEY[70] = 0;
break;
case 256:
KEY[71] = 0;
break;
case 257:
KEY[72] = 0;
break;
case 258:
KEY[73] = 0;
break;
case 259:
KEY[74] = 0;
break;
case 260:
KEY[75] = 0;
break;
case 261:
KEY[76] = 0;
break;
case 262:
KEY[77] = 0;
break;
case 263:
KEY[78] = 0;
break;
case 264:
KEY[79] = 0;
break;
case 265:
KEY[80] = 0;
break;
case 266:
KEY[81] = 0;
break;
case 267:
KEY[82] = 0;
break;
case 268:
KEY[83] = 0;
break;
case 269:
KEY[84] = 0;
break;
case 270:
KEY[85] = 0;
break;
case 271:
KEY[86] = 0;
break;
case 272:
KEY[87] = 0;
break;
case 273:
KEY[88] = 0;
break;
case 274:
KEY[89] = 0;
break;
case 275:
KEY[90] = 0;
break;
case 276:
KEY[91] = 0;
break;
case 277:
KEY[92] = 0;
break;
case 278:
KEY[93] = 0;
break;
case 279:
KEY[94] = 0;
break;
case 280:
KEY[95] = 0;
break;
case 281:
KEY[96] = 0;
break;
case 282:
KEY[97] = 0;
break;
case 283:
KEY[98] = 0;
break;
case 284:
KEY[99] = 0;
break;
case 285:
KEY[100] = 0;
break;
case 286:
KEY[101] = 0;
break;
case 287:
KEY[102] = 0;
break;
case 288:
KEY[103] = 0;
break;
case 289:
KEY[104] = 0;
break;
case 290:
KEY[105] = 0;
break;
case 291:
KEY[106] = 0;
break;
case 292:
KEY[107] = 0;
break;
case 293:
KEY[108] = 0;
break;
case 294:
KEY[109] = 0;
break;
case 295:
KEY[110] = 0;
break;
case 296:
KEY[111] = 0;
break;
case 300:
KEY[112] = 0;
break;
case 301:
KEY[113] = 0;
break;
case 302:
KEY[114] = 0;
break;
case 303:
KEY[115] = 0;
break;
case 304:
KEY[116] = 0;
break;
case 305:
KEY[117] = 0;
break;
case 306:
KEY[118] = 0;
break;
case 307:
KEY[119] = 0;
break;
case 308:
KEY[120] = 0;
break;
}
break;
}
}
}

original_code:
void SDL_HandleEvents()
{
  while(SDL_PollEvent(&event)) {
    if(event.type==SDL_MOUSEMOTION) {
      MOUSEX=event.motion.x; MOUSEY=event.motion.y; }
    if(event.type==SDL_QUIT) {
      exit_flag=1;
      SDL_Quit();
      exit(1); }
    if(event.type==SDL_MOUSEBUTTONDOWN) {
      MOUSEX=event.motion.x; MOUSEY=event.motion.y;
      if(event.button.button==1)BUTTON[LB]=1;
      if(event.button.button==2)BUTTON[MB]=1;
      if(event.button.button==3)BUTTON[RB]=1;
      if(event.button.button==4)BUTTON[WUP]=1;
      if(event.button.button==5)BUTTON[WDOWN]=1; }
    if(event.type==SDL_MOUSEBUTTONUP) {
      MOUSEX=event.motion.x; MOUSEY=event.motion.y;
      if(event.button.button==1)BUTTON[LB]=0;
      if(event.button.button==2)BUTTON[MB]=0;
      if(event.button.button==3)BUTTON[RB]=0;
      if(event.button.button==4)BUTTON[WUP]=0;
      if(event.button.button==5)BUTTON[WDOWN]=0; }
    if(event.type==SDL_KEYDOWN) {
      int bset=1;
      if(event.key.keysym.sym==SDLK_BACKSPACE)KEY[BACKSPACE]=bset;
      if(event.key.keysym.sym==SDLK_TAB)KEY[TAB]=bset;
      if(event.key.keysym.sym==SDLK_CLEAR)KEY[CLEAR]=bset;
      if(event.key.keysym.sym==SDLK_RETURN)KEY[ENTER]=bset;
      if(event.key.keysym.sym==SDLK_PAUSE)KEY[PAUSE]=bset;
      if(event.key.keysym.sym==SDLK_ESCAPE)KEY[ESCAPE]=bset;
      if(event.key.keysym.sym==SDLK_SPACE)KEY[SPACE]=bset;
      if(event.key.keysym.sym==SDLK_EXCLAIM)KEY[EXCLAIM]=bset;
      if(event.key.keysym.sym==SDLK_QUOTEDBL)KEY[QUOTEDBL]=bset;
      if(event.key.keysym.sym==SDLK_HASH)KEY[HASH]=bset;
      if(event.key.keysym.sym==SDLK_DOLLAR)KEY[DOLLAR]=bset;
      if(event.key.keysym.sym==SDLK_AMPERSAND)KEY[AMPERSAND]=bset;
      if(event.key.keysym.sym==SDLK_QUOTE)KEY[QUOTE]=bset;
      if(event.key.keysym.sym==SDLK_LEFTPAREN)KEY[LEFTPAREN]=bset;
      if(event.key.keysym.sym==SDLK_RIGHTPAREN)KEY[RIGHTPAREN]=bset;
      if(event.key.keysym.sym==SDLK_ASTERISK)KEY[ASTERISK]=bset;
      if(event.key.keysym.sym==SDLK_PLUS)KEY[PLUS]=bset;
      if(event.key.keysym.sym==SDLK_COMMA)KEY[COMMA]=bset;
      if(event.key.keysym.sym==SDLK_MINUS)KEY[MINUS]=bset;
      if(event.key.keysym.sym==SDLK_PERIOD)KEY[PERIOD]=bset;
      if(event.key.keysym.sym==SDLK_SLASH)KEY[SLASH]=bset;
      if(event.key.keysym.sym==SDLK_0)KEY[key_0]=bset;
      if(event.key.keysym.sym==SDLK_1)KEY[key_1]=bset;
      if(event.key.keysym.sym==SDLK_2)KEY[key_2]=bset;
      if(event.key.keysym.sym==SDLK_3)KEY[key_3]=bset;
      if(event.key.keysym.sym==SDLK_4)KEY[key_4]=bset;
      if(event.key.keysym.sym==SDLK_5)KEY[key_5]=bset;
      if(event.key.keysym.sym==SDLK_6)KEY[key_6]=bset;
      if(event.key.keysym.sym==SDLK_7)KEY[key_7]=bset;
      if(event.key.keysym.sym==SDLK_8)KEY[key_8]=bset;
      if(event.key.keysym.sym==SDLK_9)KEY[key_9]=bset;
      if(event.key.keysym.sym==SDLK_COLON)KEY[COLON]=bset;
      if(event.key.keysym.sym==SDLK_SEMICOLON)KEY[SEMICOLON]=bset;
      if(event.key.keysym.sym==SDLK_LESS)KEY[LESS]=bset;
      if(event.key.keysym.sym==SDLK_EQUALS)KEY[EQUALS]=bset;
      if(event.key.keysym.sym==SDLK_GREATER)KEY[GREATER]=bset;
      if(event.key.keysym.sym==SDLK_QUESTION)KEY[QUESTION]=bset;
      if(event.key.keysym.sym==SDLK_AT)KEY[AT]=bset;
      if(event.key.keysym.sym==SDLK_LEFTBRACKET)KEY[LEFTBRACKET]=bset;
      if(event.key.keysym.sym==SDLK_BACKSLASH)KEY[BACKSLASH]=bset;
      if(event.key.keysym.sym==SDLK_RIGHTBRACKET)KEY[RIGHTBRACKET]=bset;
      if(event.key.keysym.sym==SDLK_CARET)KEY[CARET]=bset;
      if(event.key.keysym.sym==SDLK_UNDERSCORE)KEY[UNDERSCORE]=bset;
      if(event.key.keysym.sym==SDLK_BACKQUOTE)KEY[BACKQUOTE]=bset;
      if(event.key.keysym.sym==SDLK_a)KEY[key_a]=bset;
      if(event.key.keysym.sym==SDLK_b)KEY[key_b]=bset;
      if(event.key.keysym.sym==SDLK_c)KEY[key_c]=bset;
      if(event.key.keysym.sym==SDLK_d)KEY[key_d]=bset;
      if(event.key.keysym.sym==SDLK_e)KEY[key_e]=bset;
      if(event.key.keysym.sym==SDLK_f)KEY[key_f]=bset;
      if(event.key.keysym.sym==SDLK_g)KEY[key_g]=bset;
      if(event.key.keysym.sym==SDLK_h)KEY[key_h]=bset;
      if(event.key.keysym.sym==SDLK_i)KEY[key_i]=bset;
      if(event.key.keysym.sym==SDLK_j)KEY[key_j]=bset;
      if(event.key.keysym.sym==SDLK_k)KEY[key_k]=bset;
      if(event.key.keysym.sym==SDLK_l)KEY[key_l]=bset;
      if(event.key.keysym.sym==SDLK_m)KEY[key_m]=bset;
      if(event.key.keysym.sym==SDLK_n)KEY[key_n]=bset;
      if(event.key.keysym.sym==SDLK_o)KEY[key_o]=bset;
      if(event.key.keysym.sym==SDLK_p)KEY[key_p]=bset;
      if(event.key.keysym.sym==SDLK_q)KEY[key_q]=bset;
      if(event.key.keysym.sym==SDLK_r)KEY[key_r]=bset;
      if(event.key.keysym.sym==SDLK_s)KEY[key_s]=bset;
      if(event.key.keysym.sym==SDLK_t)KEY[key_t_]=bset;
      if(event.key.keysym.sym==SDLK_u)KEY[key_u]=bset;
      if(event.key.keysym.sym==SDLK_v)KEY[key_v]=bset;
      if(event.key.keysym.sym==SDLK_w)KEY[key_w]=bset;
      if(event.key.keysym.sym==SDLK_x)KEY[key_x]=bset;
      if(event.key.keysym.sym==SDLK_y)KEY[key_y]=bset;
      if(event.key.keysym.sym==SDLK_z)KEY[key_z]=bset;
      if(event.key.keysym.sym==SDLK_DELETE)KEY[DEL]=bset;
      if(event.key.keysym.sym==SDLK_KP0)KEY[KP0]=bset;
      if(event.key.keysym.sym==SDLK_KP1)KEY[KP1]=bset;
      if(event.key.keysym.sym==SDLK_KP2)KEY[KP2]=bset;
      if(event.key.keysym.sym==SDLK_KP3)KEY[KP3]=bset;
      if(event.key.keysym.sym==SDLK_KP4)KEY[KP4]=bset;
      if(event.key.keysym.sym==SDLK_KP5)KEY[KP5]=bset;
      if(event.key.keysym.sym==SDLK_KP6)KEY[KP6]=bset;
      if(event.key.keysym.sym==SDLK_KP7)KEY[KP7]=bset;
      if(event.key.keysym.sym==SDLK_KP8)KEY[KP8]=bset;
      if(event.key.keysym.sym==SDLK_KP9)KEY[KP9]=bset;
      if(event.key.keysym.sym==SDLK_KP_PERIOD)KEY[KP_PERIOD]=bset;
      if(event.key.keysym.sym==SDLK_KP_DIVIDE)KEY[KP_DIVIDE]=bset;
      if(event.key.keysym.sym==SDLK_KP_MULTIPLY)KEY[KP_MULTIPLY]=bset;
      if(event.key.keysym.sym==SDLK_KP_MINUS)KEY[KP_MINUS]=bset;
      if(event.key.keysym.sym==SDLK_KP_PLUS)KEY[KP_PLUS]=bset;
      if(event.key.keysym.sym==SDLK_KP_ENTER)KEY[KP_ENTER]=bset;
      if(event.key.keysym.sym==SDLK_KP_EQUALS)KEY[KP_EQUALS]=bset;
      if(event.key.keysym.sym==SDLK_UP)KEY[UP]=bset;
      if(event.key.keysym.sym==SDLK_DOWN)KEY[DOWN]=bset;
      if(event.key.keysym.sym==SDLK_RIGHT)KEY[RIGHT]=bset;
      if(event.key.keysym.sym==SDLK_LEFT)KEY[LEFT]=bset;
      if(event.key.keysym.sym==SDLK_INSERT)KEY[INSERT]=bset;
      if(event.key.keysym.sym==SDLK_HOME)KEY[HOME]=bset;
      if(event.key.keysym.sym==SDLK_END)KEY[END]=bset;
      if(event.key.keysym.sym==SDLK_PAGEUP)KEY[PAGEUP]=bset;
      if(event.key.keysym.sym==SDLK_PAGEDOWN)KEY[PAGEDOWN]=bset;
      if(event.key.keysym.sym==SDLK_F1)KEY[F1]=bset;
      if(event.key.keysym.sym==SDLK_F2)KEY[F2]=bset;
      if(event.key.keysym.sym==SDLK_F3)KEY[F3]=bset;
      if(event.key.keysym.sym==SDLK_F4)KEY[F4]=bset;
      if(event.key.keysym.sym==SDLK_F5)KEY[F5]=bset;
      if(event.key.keysym.sym==SDLK_F6)KEY[F6]=bset;
      if(event.key.keysym.sym==SDLK_F7)KEY[F7]=bset;
      if(event.key.keysym.sym==SDLK_F8)KEY[F8]=bset;
      if(event.key.keysym.sym==SDLK_F9)KEY[F9]=bset;
      if(event.key.keysym.sym==SDLK_F10)KEY[F10]=bset;
      if(event.key.keysym.sym==SDLK_F11)KEY[F11]=bset;
      if(event.key.keysym.sym==SDLK_F12)KEY[F12]=bset;
      if(event.key.keysym.sym==SDLK_F13)KEY[F13]=bset;
      if(event.key.keysym.sym==SDLK_F14)KEY[F14]=bset;
      if(event.key.keysym.sym==SDLK_F15)KEY[F15]=bset;
      if(event.key.keysym.sym==SDLK_NUMLOCK)KEY[NUMLOCK]=bset;
      if(event.key.keysym.sym==SDLK_CAPSLOCK)KEY[CAPSLOCK]=bset;
      if(event.key.keysym.sym==SDLK_SCROLLOCK)KEY[SCROLLOCK]=bset;
      if(event.key.keysym.sym==SDLK_RSHIFT)KEY[RSHIFT]=bset;
      if(event.key.keysym.sym==SDLK_LSHIFT)KEY[LSHIFT]=bset;
      if(event.key.keysym.sym==SDLK_RCTRL)KEY[RCTRL]=bset;
      if(event.key.keysym.sym==SDLK_LCTRL)KEY[LCTRL]=bset;
      if(event.key.keysym.sym==SDLK_RALT)KEY[RALT]=bset;
      if(event.key.keysym.sym==SDLK_LALT)KEY[LALT]=bset; }
    if(event.type==SDL_KEYUP) {
      int bset=0;
      if(event.key.keysym.sym==SDLK_BACKSPACE)KEY[BACKSPACE]=bset;
      if(event.key.keysym.sym==SDLK_TAB)KEY[TAB]=bset;
      if(event.key.keysym.sym==SDLK_CLEAR)KEY[CLEAR]=bset;
      if(event.key.keysym.sym==SDLK_RETURN)KEY[ENTER]=bset;
      if(event.key.keysym.sym==SDLK_PAUSE)KEY[PAUSE]=bset;
      if(event.key.keysym.sym==SDLK_ESCAPE)KEY[ESCAPE]=bset;
      if(event.key.keysym.sym==SDLK_SPACE)KEY[SPACE]=bset;
      if(event.key.keysym.sym==SDLK_EXCLAIM)KEY[EXCLAIM]=bset;
      if(event.key.keysym.sym==SDLK_QUOTEDBL)KEY[QUOTEDBL]=bset;
      if(event.key.keysym.sym==SDLK_HASH)KEY[HASH]=bset;
      if(event.key.keysym.sym==SDLK_DOLLAR)KEY[DOLLAR]=bset;
      if(event.key.keysym.sym==SDLK_AMPERSAND)KEY[AMPERSAND]=bset;
      if(event.key.keysym.sym==SDLK_QUOTE)KEY[QUOTE]=bset;
      if(event.key.keysym.sym==SDLK_LEFTPAREN)KEY[LEFTPAREN]=bset;
      if(event.key.keysym.sym==SDLK_RIGHTPAREN)KEY[RIGHTPAREN]=bset;
      if(event.key.keysym.sym==SDLK_ASTERISK)KEY[ASTERISK]=bset;
      if(event.key.keysym.sym==SDLK_PLUS)KEY[PLUS]=bset;
      if(event.key.keysym.sym==SDLK_COMMA)KEY[COMMA]=bset;
      if(event.key.keysym.sym==SDLK_MINUS)KEY[MINUS]=bset;
      if(event.key.keysym.sym==SDLK_PERIOD)KEY[PERIOD]=bset;
      if(event.key.keysym.sym==SDLK_SLASH)KEY[SLASH]=bset;
      if(event.key.keysym.sym==SDLK_0)KEY[key_0]=bset;
      if(event.key.keysym.sym==SDLK_1)KEY[key_1]=bset;
      if(event.key.keysym.sym==SDLK_2)KEY[key_2]=bset;
      if(event.key.keysym.sym==SDLK_3)KEY[key_3]=bset;
      if(event.key.keysym.sym==SDLK_4)KEY[key_4]=bset;
      if(event.key.keysym.sym==SDLK_5)KEY[key_5]=bset;
      if(event.key.keysym.sym==SDLK_6)KEY[key_6]=bset;
      if(event.key.keysym.sym==SDLK_7)KEY[key_7]=bset;
      if(event.key.keysym.sym==SDLK_8)KEY[key_8]=bset;
      if(event.key.keysym.sym==SDLK_9)KEY[key_9]=bset;
      if(event.key.keysym.sym==SDLK_COLON)KEY[COLON]=bset;
      if(event.key.keysym.sym==SDLK_SEMICOLON)KEY[SEMICOLON]=bset;
      if(event.key.keysym.sym==SDLK_LESS)KEY[LESS]=bset;
      if(event.key.keysym.sym==SDLK_EQUALS)KEY[EQUALS]=bset;
      if(event.key.keysym.sym==SDLK_GREATER)KEY[GREATER]=bset;
      if(event.key.keysym.sym==SDLK_QUESTION)KEY[QUESTION]=bset;
      if(event.key.keysym.sym==SDLK_AT)KEY[AT]=bset;
      if(event.key.keysym.sym==SDLK_LEFTBRACKET)KEY[LEFTBRACKET]=bset;
      if(event.key.keysym.sym==SDLK_BACKSLASH)KEY[BACKSLASH]=bset;
      if(event.key.keysym.sym==SDLK_RIGHTBRACKET)KEY[RIGHTBRACKET]=bset;
      if(event.key.keysym.sym==SDLK_CARET)KEY[CARET]=bset;
      if(event.key.keysym.sym==SDLK_UNDERSCORE)KEY[UNDERSCORE]=bset;
      if(event.key.keysym.sym==SDLK_BACKQUOTE)KEY[BACKQUOTE]=bset;
      if(event.key.keysym.sym==SDLK_a)KEY[key_a]=bset;
      if(event.key.keysym.sym==SDLK_b)KEY[key_b]=bset;
      if(event.key.keysym.sym==SDLK_c)KEY[key_c]=bset;
      if(event.key.keysym.sym==SDLK_d)KEY[key_d]=bset;
      if(event.key.keysym.sym==SDLK_e)KEY[key_e]=bset;
      if(event.key.keysym.sym==SDLK_f)KEY[key_f]=bset;
      if(event.key.keysym.sym==SDLK_g)KEY[key_g]=bset;
      if(event.key.keysym.sym==SDLK_h)KEY[key_h]=bset;
      if(event.key.keysym.sym==SDLK_i)KEY[key_i]=bset;
      if(event.key.keysym.sym==SDLK_j)KEY[key_j]=bset;
      if(event.key.keysym.sym==SDLK_k)KEY[key_k]=bset;
      if(event.key.keysym.sym==SDLK_l)KEY[key_l]=bset;
      if(event.key.keysym.sym==SDLK_m)KEY[key_m]=bset;
      if(event.key.keysym.sym==SDLK_n)KEY[key_n]=bset;
      if(event.key.keysym.sym==SDLK_o)KEY[key_o]=bset;
      if(event.key.keysym.sym==SDLK_p)KEY[key_p]=bset;
      if(event.key.keysym.sym==SDLK_q)KEY[key_q]=bset;
      if(event.key.keysym.sym==SDLK_r)KEY[key_r]=bset;
      if(event.key.keysym.sym==SDLK_s)KEY[key_s]=bset;
      if(event.key.keysym.sym==SDLK_t)KEY[key_t_]=bset;
      if(event.key.keysym.sym==SDLK_u)KEY[key_u]=bset;
      if(event.key.keysym.sym==SDLK_v)KEY[key_v]=bset;
      if(event.key.keysym.sym==SDLK_w)KEY[key_w]=bset;
      if(event.key.keysym.sym==SDLK_x)KEY[key_x]=bset;
      if(event.key.keysym.sym==SDLK_y)KEY[key_y]=bset;
      if(event.key.keysym.sym==SDLK_z)KEY[key_z]=bset;
      if(event.key.keysym.sym==SDLK_DELETE)KEY[DEL]=bset;
      if(event.key.keysym.sym==SDLK_KP0)KEY[KP0]=bset;
      if(event.key.keysym.sym==SDLK_KP1)KEY[KP1]=bset;
      if(event.key.keysym.sym==SDLK_KP2)KEY[KP2]=bset;
      if(event.key.keysym.sym==SDLK_KP3)KEY[KP3]=bset;
      if(event.key.keysym.sym==SDLK_KP4)KEY[KP4]=bset;
      if(event.key.keysym.sym==SDLK_KP5)KEY[KP5]=bset;
      if(event.key.keysym.sym==SDLK_KP6)KEY[KP6]=bset;
      if(event.key.keysym.sym==SDLK_KP7)KEY[KP7]=bset;
      if(event.key.keysym.sym==SDLK_KP8)KEY[KP8]=bset;
      if(event.key.keysym.sym==SDLK_KP9)KEY[KP9]=bset;
      if(event.key.keysym.sym==SDLK_KP_PERIOD)KEY[KP_PERIOD]=bset;
      if(event.key.keysym.sym==SDLK_KP_DIVIDE)KEY[KP_DIVIDE]=bset;
      if(event.key.keysym.sym==SDLK_KP_MULTIPLY)KEY[KP_MULTIPLY]=bset;
      if(event.key.keysym.sym==SDLK_KP_MINUS)KEY[KP_MINUS]=bset;
      if(event.key.keysym.sym==SDLK_KP_PLUS)KEY[KP_PLUS]=bset;
      if(event.key.keysym.sym==SDLK_KP_ENTER)KEY[KP_ENTER]=bset;
      if(event.key.keysym.sym==SDLK_KP_EQUALS)KEY[KP_EQUALS]=bset;
      if(event.key.keysym.sym==SDLK_UP)KEY[UP]=bset;
      if(event.key.keysym.sym==SDLK_DOWN)KEY[DOWN]=bset;
      if(event.key.keysym.sym==SDLK_RIGHT)KEY[RIGHT]=bset;
      if(event.key.keysym.sym==SDLK_LEFT)KEY[LEFT]=bset;
      if(event.key.keysym.sym==SDLK_INSERT)KEY[INSERT]=bset;
      if(event.key.keysym.sym==SDLK_HOME)KEY[HOME]=bset;
      if(event.key.keysym.sym==SDLK_END)KEY[END]=bset;
      if(event.key.keysym.sym==SDLK_PAGEUP)KEY[PAGEUP]=bset;
      if(event.key.keysym.sym==SDLK_PAGEDOWN)KEY[PAGEDOWN]=bset;
      if(event.key.keysym.sym==SDLK_F1)KEY[F1]=bset;
      if(event.key.keysym.sym==SDLK_F2)KEY[F2]=bset;
      if(event.key.keysym.sym==SDLK_F3)KEY[F3]=bset;
      if(event.key.keysym.sym==SDLK_F4)KEY[F4]=bset;
      if(event.key.keysym.sym==SDLK_F5)KEY[F5]=bset;
      if(event.key.keysym.sym==SDLK_F6)KEY[F6]=bset;
      if(event.key.keysym.sym==SDLK_F7)KEY[F7]=bset;
      if(event.key.keysym.sym==SDLK_F8)KEY[F8]=bset;
      if(event.key.keysym.sym==SDLK_F9)KEY[F9]=bset;
      if(event.key.keysym.sym==SDLK_F10)KEY[F10]=bset;
      if(event.key.keysym.sym==SDLK_F11)KEY[F11]=bset;
      if(event.key.keysym.sym==SDLK_F12)KEY[F12]=bset;
      if(event.key.keysym.sym==SDLK_F13)KEY[F13]=bset;
      if(event.key.keysym.sym==SDLK_F14)KEY[F14]=bset;
      if(event.key.keysym.sym==SDLK_F15)KEY[F15]=bset;
      if(event.key.keysym.sym==SDLK_NUMLOCK)KEY[NUMLOCK]=bset;
      if(event.key.keysym.sym==SDLK_CAPSLOCK)KEY[CAPSLOCK]=bset;
      if(event.key.keysym.sym==SDLK_SCROLLOCK)KEY[SCROLLOCK]=bset;
      if(event.key.keysym.sym==SDLK_RSHIFT)KEY[RSHIFT]=bset;
      if(event.key.keysym.sym==SDLK_LSHIFT)KEY[LSHIFT]=bset;
      if(event.key.keysym.sym==SDLK_RCTRL)KEY[RCTRL]=bset;
      if(event.key.keysym.sym==SDLK_LCTRL)KEY[LCTRL]=bset;
      if(event.key.keysym.sym==SDLK_RALT)KEY[RALT]=bset;
      if(event.key.keysym.sym==SDLK_LALT)KEY[LALT]=bset; } } }

canonical_original_code:
void SDL_HandleEvents()
{
  while(SDL_PollEvent(&event)) {
    if(event.type==SDL_MOUSEMOTION) {
      MOUSEX=event.motion.x; MOUSEY=event.motion.y; }
    if(event.type==SDL_QUIT) {
      exit_flag=1;
      SDL_Quit();
      exit(1); }
    if(event.type==SDL_MOUSEBUTTONDOWN) {
      MOUSEX=event.motion.x; MOUSEY=event.motion.y;
      if(event.button.button==1)BUTTON[LB]=1;
      if(event.button.button==2)BUTTON[MB]=1;
      if(event.button.button==3)BUTTON[RB]=1;
      if(event.button.button==4)BUTTON[WUP]=1;
      if(event.button.button==5)BUTTON[WDOWN]=1; }
    if(event.type==SDL_MOUSEBUTTONUP) {
      MOUSEX=event.motion.x; MOUSEY=event.motion.y;
      if(event.button.button==1)BUTTON[LB]=0;
      if(event.button.button==2)BUTTON[MB]=0;
      if(event.button.button==3)BUTTON[RB]=0;
      if(event.button.button==4)BUTTON[WUP]=0;
      if(event.button.button==5)BUTTON[WDOWN]=0; }
    if(event.type==SDL_KEYDOWN) {
      int bset = 1;
      if(event.key.keysym.sym==SDLK_BACKSPACE)KEY[BACKSPACE]=bset;
      if(event.key.keysym.sym==SDLK_TAB)KEY[TAB]=bset;
      if(event.key.keysym.sym==SDLK_CLEAR)KEY[CLEAR]=bset;
      if(event.key.keysym.sym==SDLK_RETURN)KEY[ENTER]=bset;
      if(event.key.keysym.sym==SDLK_PAUSE)KEY[PAUSE]=bset;
      if(event.key.keysym.sym==SDLK_ESCAPE)KEY[ESCAPE]=bset;
      if(event.key.keysym.sym==SDLK_SPACE)KEY[SPACE]=bset;
      if(event.key.keysym.sym==SDLK_EXCLAIM)KEY[EXCLAIM]=bset;
      if(event.key.keysym.sym==SDLK_QUOTEDBL)KEY[QUOTEDBL]=bset;
      if(event.key.keysym.sym==SDLK_HASH)KEY[HASH]=bset;
      if(event.key.keysym.sym==SDLK_DOLLAR)KEY[DOLLAR]=bset;
      if(event.key.keysym.sym==SDLK_AMPERSAND)KEY[AMPERSAND]=bset;
      if(event.key.keysym.sym==SDLK_QUOTE)KEY[QUOTE]=bset;
      if(event.key.keysym.sym==SDLK_LEFTPAREN)KEY[LEFTPAREN]=bset;
      if(event.key.keysym.sym==SDLK_RIGHTPAREN)KEY[RIGHTPAREN]=bset;
      if(event.key.keysym.sym==SDLK_ASTERISK)KEY[ASTERISK]=bset;
      if(event.key.keysym.sym==SDLK_PLUS)KEY[PLUS]=bset;
      if(event.key.keysym.sym==SDLK_COMMA)KEY[COMMA]=bset;
      if(event.key.keysym.sym==SDLK_MINUS)KEY[MINUS]=bset;
      if(event.key.keysym.sym==SDLK_PERIOD)KEY[PERIOD]=bset;
      if(event.key.keysym.sym==SDLK_SLASH)KEY[SLASH]=bset;
      if(event.key.keysym.sym==SDLK_0)KEY[key_0]=bset;
      if(event.key.keysym.sym==SDLK_1)KEY[key_1]=bset;
      if(event.key.keysym.sym==SDLK_2)KEY[key_2]=bset;
      if(event.key.keysym.sym==SDLK_3)KEY[key_3]=bset;
      if(event.key.keysym.sym==SDLK_4)KEY[key_4]=bset;
      if(event.key.keysym.sym==SDLK_5)KEY[key_5]=bset;
      if(event.key.keysym.sym==SDLK_6)KEY[key_6]=bset;
      if(event.key.keysym.sym==SDLK_7)KEY[key_7]=bset;
      if(event.key.keysym.sym==SDLK_8)KEY[key_8]=bset;
      if(event.key.keysym.sym==SDLK_9)KEY[key_9]=bset;
      if(event.key.keysym.sym==SDLK_COLON)KEY[COLON]=bset;
      if(event.key.keysym.sym==SDLK_SEMICOLON)KEY[SEMICOLON]=bset;
      if(event.key.keysym.sym==SDLK_LESS)KEY[LESS]=bset;
      if(event.key.keysym.sym==SDLK_EQUALS)KEY[EQUALS]=bset;
      if(event.key.keysym.sym==SDLK_GREATER)KEY[GREATER]=bset;
      if(event.key.keysym.sym==SDLK_QUESTION)KEY[QUESTION]=bset;
      if(event.key.keysym.sym==SDLK_AT)KEY[AT]=bset;
      if(event.key.keysym.sym==SDLK_LEFTBRACKET)KEY[LEFTBRACKET]=bset;
      if(event.key.keysym.sym==SDLK_BACKSLASH)KEY[BACKSLASH]=bset;
      if(event.key.keysym.sym==SDLK_RIGHTBRACKET)KEY[RIGHTBRACKET]=bset;
      if(event.key.keysym.sym==SDLK_CARET)KEY[CARET]=bset;
      if(event.key.keysym.sym==SDLK_UNDERSCORE)KEY[UNDERSCORE]=bset;
      if(event.key.keysym.sym==SDLK_BACKQUOTE)KEY[BACKQUOTE]=bset;
      if(event.key.keysym.sym==SDLK_a)KEY[key_a]=bset;
      if(event.key.keysym.sym==SDLK_b)KEY[key_b]=bset;
      if(event.key.keysym.sym==SDLK_c)KEY[key_c]=bset;
      if(event.key.keysym.sym==SDLK_d)KEY[key_d]=bset;
      if(event.key.keysym.sym==SDLK_e)KEY[key_e]=bset;
      if(event.key.keysym.sym==SDLK_f)KEY[key_f]=bset;
      if(event.key.keysym.sym==SDLK_g)KEY[key_g]=bset;
      if(event.key.keysym.sym==SDLK_h)KEY[key_h]=bset;
      if(event.key.keysym.sym==SDLK_i)KEY[key_i]=bset;
      if(event.key.keysym.sym==SDLK_j)KEY[key_j]=bset;
      if(event.key.keysym.sym==SDLK_k)KEY[key_k]=bset;
      if(event.key.keysym.sym==SDLK_l)KEY[key_l]=bset;
      if(event.key.keysym.sym==SDLK_m)KEY[key_m]=bset;
      if(event.key.keysym.sym==SDLK_n)KEY[key_n]=bset;
      if(event.key.keysym.sym==SDLK_o)KEY[key_o]=bset;
      if(event.key.keysym.sym==SDLK_p)KEY[key_p]=bset;
      if(event.key.keysym.sym==SDLK_q)KEY[key_q]=bset;
      if(event.key.keysym.sym==SDLK_r)KEY[key_r]=bset;
      if(event.key.keysym.sym==SDLK_s)KEY[key_s]=bset;
      if(event.key.keysym.sym==SDLK_t)KEY[key_t_]=bset;
      if(event.key.keysym.sym==SDLK_u)KEY[key_u]=bset;
      if(event.key.keysym.sym==SDLK_v)KEY[key_v]=bset;
      if(event.key.keysym.sym==SDLK_w)KEY[key_w]=bset;
      if(event.key.keysym.sym==SDLK_x)KEY[key_x]=bset;
      if(event.key.keysym.sym==SDLK_y)KEY[key_y]=bset;
      if(event.key.keysym.sym==SDLK_z)KEY[key_z]=bset;
      if(event.key.keysym.sym==SDLK_DELETE)KEY[DEL]=bset;
      if(event.key.keysym.sym==SDLK_KP0)KEY[KP0]=bset;
      if(event.key.keysym.sym==SDLK_KP1)KEY[KP1]=bset;
      if(event.key.keysym.sym==SDLK_KP2)KEY[KP2]=bset;
      if(event.key.keysym.sym==SDLK_KP3)KEY[KP3]=bset;
      if(event.key.keysym.sym==SDLK_KP4)KEY[KP4]=bset;
      if(event.key.keysym.sym==SDLK_KP5)KEY[KP5]=bset;
      if(event.key.keysym.sym==SDLK_KP6)KEY[KP6]=bset;
      if(event.key.keysym.sym==SDLK_KP7)KEY[KP7]=bset;
      if(event.key.keysym.sym==SDLK_KP8)KEY[KP8]=bset;
      if(event.key.keysym.sym==SDLK_KP9)KEY[KP9]=bset;
      if(event.key.keysym.sym==SDLK_KP_PERIOD)KEY[KP_PERIOD]=bset;
      if(event.key.keysym.sym==SDLK_KP_DIVIDE)KEY[KP_DIVIDE]=bset;
      if(event.key.keysym.sym==SDLK_KP_MULTIPLY)KEY[KP_MULTIPLY]=bset;
      if(event.key.keysym.sym==SDLK_KP_MINUS)KEY[KP_MINUS]=bset;
      if(event.key.keysym.sym==SDLK_KP_PLUS)KEY[KP_PLUS]=bset;
      if(event.key.keysym.sym==SDLK_KP_ENTER)KEY[KP_ENTER]=bset;
      if(event.key.keysym.sym==SDLK_KP_EQUALS)KEY[KP_EQUALS]=bset;
      if(event.key.keysym.sym==SDLK_UP)KEY[UP]=bset;
      if(event.key.keysym.sym==SDLK_DOWN)KEY[DOWN]=bset;
      if(event.key.keysym.sym==SDLK_RIGHT)KEY[RIGHT]=bset;
      if(event.key.keysym.sym==SDLK_LEFT)KEY[LEFT]=bset;
      if(event.key.keysym.sym==SDLK_INSERT)KEY[INSERT]=bset;
      if(event.key.keysym.sym==SDLK_HOME)KEY[HOME]=bset;
      if(event.key.keysym.sym==SDLK_END)KEY[END]=bset;
      if(event.key.keysym.sym==SDLK_PAGEUP)KEY[PAGEUP]=bset;
      if(event.key.keysym.sym==SDLK_PAGEDOWN)KEY[PAGEDOWN]=bset;
      if(event.key.keysym.sym==SDLK_F1)KEY[F1]=bset;
      if(event.key.keysym.sym==SDLK_F2)KEY[F2]=bset;
      if(event.key.keysym.sym==SDLK_F3)KEY[F3]=bset;
      if(event.key.keysym.sym==SDLK_F4)KEY[F4]=bset;
      if(event.key.keysym.sym==SDLK_F5)KEY[F5]=bset;
      if(event.key.keysym.sym==SDLK_F6)KEY[F6]=bset;
      if(event.key.keysym.sym==SDLK_F7)KEY[F7]=bset;
      if(event.key.keysym.sym==SDLK_F8)KEY[F8]=bset;
      if(event.key.keysym.sym==SDLK_F9)KEY[F9]=bset;
      if(event.key.keysym.sym==SDLK_F10)KEY[F10]=bset;
      if(event.key.keysym.sym==SDLK_F11)KEY[F11]=bset;
      if(event.key.keysym.sym==SDLK_F12)KEY[F12]=bset;
      if(event.key.keysym.sym==SDLK_F13)KEY[F13]=bset;
      if(event.key.keysym.sym==SDLK_F14)KEY[F14]=bset;
      if(event.key.keysym.sym==SDLK_F15)KEY[F15]=bset;
      if(event.key.keysym.sym==SDLK_NUMLOCK)KEY[NUMLOCK]=bset;
      if(event.key.keysym.sym==SDLK_CAPSLOCK)KEY[CAPSLOCK]=bset;
      if(event.key.keysym.sym==SDLK_SCROLLOCK)KEY[SCROLLOCK]=bset;
      if(event.key.keysym.sym==SDLK_RSHIFT)KEY[RSHIFT]=bset;
      if(event.key.keysym.sym==SDLK_LSHIFT)KEY[LSHIFT]=bset;
      if(event.key.keysym.sym==SDLK_RCTRL)KEY[RCTRL]=bset;
      if(event.key.keysym.sym==SDLK_LCTRL)KEY[LCTRL]=bset;
      if(event.key.keysym.sym==SDLK_RALT)KEY[RALT]=bset;
      if(event.key.keysym.sym==SDLK_LALT)KEY[LALT]=bset; }
    if(event.type==SDL_KEYUP) {
      int bset = 0;
      if(event.key.keysym.sym==SDLK_BACKSPACE)KEY[BACKSPACE]=bset;
      if(event.key.keysym.sym==SDLK_TAB)KEY[TAB]=bset;
      if(event.key.keysym.sym==SDLK_CLEAR)KEY[CLEAR]=bset;
      if(event.key.keysym.sym==SDLK_RETURN)KEY[ENTER]=bset;
      if(event.key.keysym.sym==SDLK_PAUSE)KEY[PAUSE]=bset;
      if(event.key.keysym.sym==SDLK_ESCAPE)KEY[ESCAPE]=bset;
      if(event.key.keysym.sym==SDLK_SPACE)KEY[SPACE]=bset;
      if(event.key.keysym.sym==SDLK_EXCLAIM)KEY[EXCLAIM]=bset;
      if(event.key.keysym.sym==SDLK_QUOTEDBL)KEY[QUOTEDBL]=bset;
      if(event.key.keysym.sym==SDLK_HASH)KEY[HASH]=bset;
      if(event.key.keysym.sym==SDLK_DOLLAR)KEY[DOLLAR]=bset;
      if(event.key.keysym.sym==SDLK_AMPERSAND)KEY[AMPERSAND]=bset;
      if(event.key.keysym.sym==SDLK_QUOTE)KEY[QUOTE]=bset;
      if(event.key.keysym.sym==SDLK_LEFTPAREN)KEY[LEFTPAREN]=bset;
      if(event.key.keysym.sym==SDLK_RIGHTPAREN)KEY[RIGHTPAREN]=bset;
      if(event.key.keysym.sym==SDLK_ASTERISK)KEY[ASTERISK]=bset;
      if(event.key.keysym.sym==SDLK_PLUS)KEY[PLUS]=bset;
      if(event.key.keysym.sym==SDLK_COMMA)KEY[COMMA]=bset;
      if(event.key.keysym.sym==SDLK_MINUS)KEY[MINUS]=bset;
      if(event.key.keysym.sym==SDLK_PERIOD)KEY[PERIOD]=bset;
      if(event.key.keysym.sym==SDLK_SLASH)KEY[SLASH]=bset;
      if(event.key.keysym.sym==SDLK_0)KEY[key_0]=bset;
      if(event.key.keysym.sym==SDLK_1)KEY[key_1]=bset;
      if(event.key.keysym.sym==SDLK_2)KEY[key_2]=bset;
      if(event.key.keysym.sym==SDLK_3)KEY[key_3]=bset;
      if(event.key.keysym.sym==SDLK_4)KEY[key_4]=bset;
      if(event.key.keysym.sym==SDLK_5)KEY[key_5]=bset;
      if(event.key.keysym.sym==SDLK_6)KEY[key_6]=bset;
      if(event.key.keysym.sym==SDLK_7)KEY[key_7]=bset;
      if(event.key.keysym.sym==SDLK_8)KEY[key_8]=bset;
      if(event.key.keysym.sym==SDLK_9)KEY[key_9]=bset;
      if(event.key.keysym.sym==SDLK_COLON)KEY[COLON]=bset;
      if(event.key.keysym.sym==SDLK_SEMICOLON)KEY[SEMICOLON]=bset;
      if(event.key.keysym.sym==SDLK_LESS)KEY[LESS]=bset;
      if(event.key.keysym.sym==SDLK_EQUALS)KEY[EQUALS]=bset;
      if(event.key.keysym.sym==SDLK_GREATER)KEY[GREATER]=bset;
      if(event.key.keysym.sym==SDLK_QUESTION)KEY[QUESTION]=bset;
      if(event.key.keysym.sym==SDLK_AT)KEY[AT]=bset;
      if(event.key.keysym.sym==SDLK_LEFTBRACKET)KEY[LEFTBRACKET]=bset;
      if(event.key.keysym.sym==SDLK_BACKSLASH)KEY[BACKSLASH]=bset;
      if(event.key.keysym.sym==SDLK_RIGHTBRACKET)KEY[RIGHTBRACKET]=bset;
      if(event.key.keysym.sym==SDLK_CARET)KEY[CARET]=bset;
      if(event.key.keysym.sym==SDLK_UNDERSCORE)KEY[UNDERSCORE]=bset;
      if(event.key.keysym.sym==SDLK_BACKQUOTE)KEY[BACKQUOTE]=bset;
      if(event.key.keysym.sym==SDLK_a)KEY[key_a]=bset;
      if(event.key.keysym.sym==SDLK_b)KEY[key_b]=bset;
      if(event.key.keysym.sym==SDLK_c)KEY[key_c]=bset;
      if(event.key.keysym.sym==SDLK_d)KEY[key_d]=bset;
      if(event.key.keysym.sym==SDLK_e)KEY[key_e]=bset;
      if(event.key.keysym.sym==SDLK_f)KEY[key_f]=bset;
      if(event.key.keysym.sym==SDLK_g)KEY[key_g]=bset;
      if(event.key.keysym.sym==SDLK_h)KEY[key_h]=bset;
      if(event.key.keysym.sym==SDLK_i)KEY[key_i]=bset;
      if(event.key.keysym.sym==SDLK_j)KEY[key_j]=bset;
      if(event.key.keysym.sym==SDLK_k)KEY[key_k]=bset;
      if(event.key.keysym.sym==SDLK_l)KEY[key_l]=bset;
      if(event.key.keysym.sym==SDLK_m)KEY[key_m]=bset;
      if(event.key.keysym.sym==SDLK_n)KEY[key_n]=bset;
      if(event.key.keysym.sym==SDLK_o)KEY[key_o]=bset;
      if(event.key.keysym.sym==SDLK_p)KEY[key_p]=bset;
      if(event.key.keysym.sym==SDLK_q)KEY[key_q]=bset;
      if(event.key.keysym.sym==SDLK_r)KEY[key_r]=bset;
      if(event.key.keysym.sym==SDLK_s)KEY[key_s]=bset;
      if(event.key.keysym.sym==SDLK_t)KEY[key_t_]=bset;
      if(event.key.keysym.sym==SDLK_u)KEY[key_u]=bset;
      if(event.key.keysym.sym==SDLK_v)KEY[key_v]=bset;
      if(event.key.keysym.sym==SDLK_w)KEY[key_w]=bset;
      if(event.key.keysym.sym==SDLK_x)KEY[key_x]=bset;
      if(event.key.keysym.sym==SDLK_y)KEY[key_y]=bset;
      if(event.key.keysym.sym==SDLK_z)KEY[key_z]=bset;
      if(event.key.keysym.sym==SDLK_DELETE)KEY[DEL]=bset;
      if(event.key.keysym.sym==SDLK_KP0)KEY[KP0]=bset;
      if(event.key.keysym.sym==SDLK_KP1)KEY[KP1]=bset;
      if(event.key.keysym.sym==SDLK_KP2)KEY[KP2]=bset;
      if(event.key.keysym.sym==SDLK_KP3)KEY[KP3]=bset;
      if(event.key.keysym.sym==SDLK_KP4)KEY[KP4]=bset;
      if(event.key.keysym.sym==SDLK_KP5)KEY[KP5]=bset;
      if(event.key.keysym.sym==SDLK_KP6)KEY[KP6]=bset;
      if(event.key.keysym.sym==SDLK_KP7)KEY[KP7]=bset;
      if(event.key.keysym.sym==SDLK_KP8)KEY[KP8]=bset;
      if(event.key.keysym.sym==SDLK_KP9)KEY[KP9]=bset;
      if(event.key.keysym.sym==SDLK_KP_PERIOD)KEY[KP_PERIOD]=bset;
      if(event.key.keysym.sym==SDLK_KP_DIVIDE)KEY[KP_DIVIDE]=bset;
      if(event.key.keysym.sym==SDLK_KP_MULTIPLY)KEY[KP_MULTIPLY]=bset;
      if(event.key.keysym.sym==SDLK_KP_MINUS)KEY[KP_MINUS]=bset;
      if(event.key.keysym.sym==SDLK_KP_PLUS)KEY[KP_PLUS]=bset;
      if(event.key.keysym.sym==SDLK_KP_ENTER)KEY[KP_ENTER]=bset;
      if(event.key.keysym.sym==SDLK_KP_EQUALS)KEY[KP_EQUALS]=bset;
      if(event.key.keysym.sym==SDLK_UP)KEY[UP]=bset;
      if(event.key.keysym.sym==SDLK_DOWN)KEY[DOWN]=bset;
      if(event.key.keysym.sym==SDLK_RIGHT)KEY[RIGHT]=bset;
      if(event.key.keysym.sym==SDLK_LEFT)KEY[LEFT]=bset;
      if(event.key.keysym.sym==SDLK_INSERT)KEY[INSERT]=bset;
      if(event.key.keysym.sym==SDLK_HOME)KEY[HOME]=bset;
      if(event.key.keysym.sym==SDLK_END)KEY[END]=bset;
      if(event.key.keysym.sym==SDLK_PAGEUP)KEY[PAGEUP]=bset;
      if(event.key.keysym.sym==SDLK_PAGEDOWN)KEY[PAGEDOWN]=bset;
      if(event.key.keysym.sym==SDLK_F1)KEY[F1]=bset;
      if(event.key.keysym.sym==SDLK_F2)KEY[F2]=bset;
      if(event.key.keysym.sym==SDLK_F3)KEY[F3]=bset;
      if(event.key.keysym.sym==SDLK_F4)KEY[F4]=bset;
      if(event.key.keysym.sym==SDLK_F5)KEY[F5]=bset;
      if(event.key.keysym.sym==SDLK_F6)KEY[F6]=bset;
      if(event.key.keysym.sym==SDLK_F7)KEY[F7]=bset;
      if(event.key.keysym.sym==SDLK_F8)KEY[F8]=bset;
      if(event.key.keysym.sym==SDLK_F9)KEY[F9]=bset;
      if(event.key.keysym.sym==SDLK_F10)KEY[F10]=bset;
      if(event.key.keysym.sym==SDLK_F11)KEY[F11]=bset;
      if(event.key.keysym.sym==SDLK_F12)KEY[F12]=bset;
      if(event.key.keysym.sym==SDLK_F13)KEY[F13]=bset;
      if(event.key.keysym.sym==SDLK_F14)KEY[F14]=bset;
      if(event.key.keysym.sym==SDLK_F15)KEY[F15]=bset;
      if(event.key.keysym.sym==SDLK_NUMLOCK)KEY[NUMLOCK]=bset;
      if(event.key.keysym.sym==SDLK_CAPSLOCK)KEY[CAPSLOCK]=bset;
      if(event.key.keysym.sym==SDLK_SCROLLOCK)KEY[SCROLLOCK]=bset;
      if(event.key.keysym.sym==SDLK_RSHIFT)KEY[RSHIFT]=bset;
      if(event.key.keysym.sym==SDLK_LSHIFT)KEY[LSHIFT]=bset;
      if(event.key.keysym.sym==SDLK_RCTRL)KEY[RCTRL]=bset;
      if(event.key.keysym.sym==SDLK_LCTRL)KEY[LCTRL]=bset;
      if(event.key.keysym.sym==SDLK_RALT)KEY[RALT]=bset;
      if(event.key.keysym.sym==SDLK_LALT)KEY[LALT]=bset; } } }

variable_types: bset int


decompiled_code:
__int64 mouse_look()
{
int v0; // ebp
int v1; // ebx
float v2; // xmm4_4
double v3; // xmm0_8
bool v4; // cc
double v5; // xmm2_8
float v6; // xmm0_4
float v7; // xmm0_4
float v8; // xmm1_4
float v9; // xmm0_4
__int64 v11; // [rsp+0h] [rbp-38h]
double v12; // [rsp+8h] [rbp-30h]
double cosx; // [rsp+10h] [rbp-28h] BYREF
double sinx[4]; // [rsp+18h] [rbp-20h] BYREF

v0 = HEIGHT;
v1 = WIDTH;
v2 = pitch - (float)(MOUSEY - HEIGHT / 2) * 0.15;
pitch = LODWORD(v2);
v3 = yaw - (float)(MOUSEX - WIDTH / 2) * 0.15;
*(float *)&v3 = v3;
yaw = LODWORD(v3);
if ( *(float *)&v3 > 360.0 )
{
do
{
v4 = *(float *)&v3 <= 720.0;
*(float *)&v3 = *(float *)&v3 - 360.0;
}
while ( !v4 );
yaw = LODWORD(v3);
}
v5 = 0.0;
if ( *(float *)&v3 < 0.0 )
{
do
{
v5 = v3;
*(float *)&v3 = *(float *)&v3 + 360.0;
}
while ( *(float *)&v5 < -360.0 );
yaw = LODWORD(v3);
}
if ( v2 <= 90.0 )
{
if ( v2 >= -90.0 )
{
*(double *)&v11 = v2;
}
else
{
pitch = -1028521984;
v11 = LC1;
}
}
else
{
pitch = 1118961664;
v11 = LC0;
}
sincos(*(float *)&v3 * DTR, sinx, &cosx);
v6 = cosx;
cosyaw = LODWORD(v6);
v12 = sinx[0];
sincos(*(double *)&v11 * DTR, sinx, &cosx);
v7 = cosx;
v8 = v12;
cospitch = LODWORD(v7);
v9 = sinx[0];
sinyaw = LODWORD(v8);
sinpitch = LODWORD(v9);
return SDL_WarpMouse(
(unsigned __int16)(v1 / 2),
(unsigned __int16)(v0 / 2),
v9,
v8,
v5,
COERCE_DOUBLE((unsigned __int64)LC6));
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // ebp
int v1; // ebx
float v2; // xmm4_4
double v3; // xmm0_8
bool v4; // cc
double v5; // xmm2_8
float v6; // xmm0_4
float v7; // xmm0_4
float v8; // xmm1_4
float v9; // xmm0_4
__int64 v11; // [rsp+0h] [rbp-38h]
double v12; // [rsp+8h] [rbp-30h]
double cosx; // [rsp+10h] [rbp-28h] BYREF
double sinx[4]; // [rsp+18h] [rbp-20h] BYREF

v0 = HEIGHT;
v1 = WIDTH;
v2 = pitch - (float)(MOUSEY - HEIGHT / 2) * 0.15;
pitch = LODWORD(v2);
v3 = yaw - (float)(MOUSEX - WIDTH / 2) * 0.15;
*(float *)&v3 = v3;
yaw = LODWORD(v3);
if ( *(float *)&v3 > 360.0 )
{
do
{
v4 = *(float *)&v3 <= 720.0;
*(float *)&v3 = *(float *)&v3 - 360.0;
}
while ( !v4 );
yaw = LODWORD(v3);
}
v5 = 0.0;
if ( *(float *)&v3 < 0.0 )
{
do
{
v5 = v3;
*(float *)&v3 = *(float *)&v3 + 360.0;
}
while ( *(float *)&v5 < -360.0 );
yaw = LODWORD(v3);
}
if ( v2 <= 90.0 )
{
if ( v2 >= -90.0 )
{
*(double *)&v11 = v2;
}
else
{
pitch = -1028521984;
v11 = LC1;
}
}
else
{
pitch = 1118961664;
v11 = LC0;
}
sincos(*(float *)&v3 * DTR, sinx, &cosx);
v6 = cosx;
cosyaw = LODWORD(v6);
v12 = sinx[0];
sincos(*(double *)&v11 * DTR, sinx, &cosx);
v7 = cosx;
v8 = v12;
cospitch = LODWORD(v7);
v9 = sinx[0];
sinyaw = LODWORD(v8);
sinpitch = LODWORD(v9);
return SDL_WarpMouse(
(unsigned __int16)(v1 / 2),
(unsigned __int16)(v0 / 2),
v9,
v8,
v5,
COERCE_DOUBLE((unsigned __int64)LC6));
}

original_code:
void mouse_look()
{
 float dx = MOUSEX-WIDTH/2, dy = MOUSEY-HEIGHT/2;
 yaw -= dx*0.15;
 pitch -= dy*0.15;
 while (yaw>360) yaw-=360;
 while (yaw<0) yaw+=360;
 if (pitch>90) pitch=89;
 if (pitch<-90) pitch=-89;
 cosyaw = cos(yaw*DTR);
 cospitch = cos(pitch*DTR);
 sinyaw = sin(yaw*DTR);
 sinpitch = sin(pitch*DTR);
 SDL_WarpMouse(WIDTH/2, HEIGHT/2);
}

canonical_original_code:
void mouse_look()
{
 float dx = MOUSEX-WIDTH/2; float dy = MOUSEY-HEIGHT/2;
 yaw -= dx*0.15;
 pitch -= dy*0.15;
 while (yaw>360) yaw-=360;
 while (yaw<0) yaw+=360;
 if (pitch>90) pitch=89;
 if (pitch<-90) pitch=-89;
 cosyaw = cos(yaw*DTR);
 cospitch = cos(pitch*DTR);
 sinyaw = sin(yaw*DTR);
 sinpitch = sin(pitch*DTR);
 SDL_WarpMouse(WIDTH/2, HEIGHT/2);
}

variable_types: dx float

variable_types: dy float


decompiled_code:
void __fastcall fly_forward(float a1)
{
float v1; // xmm1_4
float v2; // xmm1_4
float v3; // xmm0_4
double v4; // [rsp+8h] [rbp-30h]
double v5; // [rsp+10h] [rbp-28h]
double v6; // [rsp+18h] [rbp-20h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

v6 = (float)(a1 * 35.0);
sincos((float)(yaw + 90.0) * DTR, sinx, &cosx);
v5 = cosx;
v4 = sinx[0];
sincos(pitch * DTR, sinx, &cosx);
v1 = v5 * cosx * v6 + camx;
camx = LODWORD(v1);
v2 = camy + sinx[0] * v6;
camy = LODWORD(v2);
v3 = cosx * v4 * v6 + camz;
camz = LODWORD(v3);
}

canonical_decompiled_code:
void __fastcall func1(float a1)
{
float v1; // xmm1_4
float v2; // xmm1_4
float v3; // xmm0_4
double v4; // [rsp+8h] [rbp-30h]
double v5; // [rsp+10h] [rbp-28h]
double v6; // [rsp+18h] [rbp-20h]
double cosx; // [rsp+20h] [rbp-18h] BYREF
double sinx[2]; // [rsp+28h] [rbp-10h] BYREF

v6 = (float)(a1 * 35.0);
sincos((float)(yaw + 90.0) * DTR, sinx, &cosx);
v5 = cosx;
v4 = sinx[0];
sincos(pitch * DTR, sinx, &cosx);
v1 = v5 * cosx * v6 + camx;
camx = LODWORD(v1);
v2 = camy + sinx[0] * v6;
camy = LODWORD(v2);
v3 = cosx * v4 * v6 + camz;
camz = LODWORD(v3);
}

original_code:
void fly_forward(float speed)
{
 speed *= 35;
 camx += speed*cos((yaw+90)*DTR) * cos(pitch*DTR);
 camy += speed*sin(pitch*DTR);
 camz += speed*sin((yaw+90)*DTR) * cos(pitch*DTR);
}

variable_types: speed float


original_code:
void fill_holes()
{
 uint32_t x, y;
 static uint32_t *img2 = ((void *)0);
 if (img2 == ((void *)0)) {
  img2 = (uint32_t*) malloc (WIDTH*HEIGHT*sizeof(uint32_t));
 }
 memcpy(img2, img, WIDTH*HEIGHT*sizeof(Uint32));
 for (x=0;x<WIDTH-1;x++) {
  for (y=0;y<HEIGHT;y++) {
   const uint32_t addr = x + y*WIDTH;
   if (img2[addr] == 0xCEA0A0A0) {
    img2[addr] = img[addr+1];
   }
  }
 }
 for (x=1;x<WIDTH;x++) {
  for (y=0;y<HEIGHT;y++) {
   const uint32_t addr = x + y*WIDTH;
   if (img2[addr] == 0xCEA0A0A0) {
    img2[addr] = img[addr-1];
   }
  }
 }
 memcpy(img, img2, WIDTH*HEIGHT*sizeof(uint32_t));
 for (x=0;x<WIDTH;x++) {
  for (y=0;y<HEIGHT-1;y++) {
   const uint32_t addr = x + y*WIDTH;
   if (img2[addr] == 0xCEA0A0A0) {
    img2[addr] = img[addr+WIDTH];
   }
  }
 }
 for (x=0;x<WIDTH;x++) {
  for (y=1;y<HEIGHT;y++) {
   const uint32_t addr = x + y*WIDTH;
   if (img2[addr] == 0xCEA0A0A0) {
    img2[addr] = img[addr-WIDTH];
   }
  }
 }
 memcpy(img, img2, WIDTH*HEIGHT*sizeof(uint32_t));
}

canonical_original_code:
void fill_holes()
{
 unsigned int x; unsigned int y;
 static unsigned int *img2 = ((void *)0);
 if (img2 == ((void *)0)) {
  img2 = (unsigned int *) malloc (WIDTH*HEIGHT*sizeof(unsigned int));
 }
 memcpy(img2, img, WIDTH*HEIGHT*sizeof(Uint32));
 for (x=0;x<WIDTH-1;x++) {
  for (y=0;y<HEIGHT;y++) {
   unsigned int addr = x + y*WIDTH;
   if (img2[addr] == 0xCEA0A0A0) {
    img2[addr] = img[addr+1];
   }
  }
 }
 for (x=1;x<WIDTH;x++) {
  for (y=0;y<HEIGHT;y++) {
   unsigned int addr = x + y*WIDTH;
   if (img2[addr] == 0xCEA0A0A0) {
    img2[addr] = img[addr-1];
   }
  }
 }
 memcpy(img, img2, WIDTH*HEIGHT*sizeof(unsigned int));
 for (x=0;x<WIDTH;x++) {
  for (y=0;y<HEIGHT-1;y++) {
   unsigned int addr = x + y*WIDTH;
   if (img2[addr] == 0xCEA0A0A0) {
    img2[addr] = img[addr+WIDTH];
   }
  }
 }
 for (x=0;x<WIDTH;x++) {
  for (y=1;y<HEIGHT;y++) {
   unsigned int addr = x + y*WIDTH;
   if (img2[addr] == 0xCEA0A0A0) {
    img2[addr] = img[addr-WIDTH];
   }
  }
 }
 memcpy(img, img2, WIDTH*HEIGHT*sizeof(unsigned int));
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types:
addr
unsigned int


repo: jaccovanschaik/libjvs

decompiled_code:
void __fastcall v3Set(double *a1, double a2, double a3, double a4)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
}

canonical_decompiled_code:
void __fastcall func2(double *a1, double a2, double a3, double a4)
{
*a1 = a2;
a1[1] = a3;
a1[2] = a4;
}

original_code:
void v3Set(Vector3 *v, double x, double y, double z)
{
    v->r[0] = x;
    v->r[1] = y;
    v->r[2] = z;
}

canonical_original_code:
void v3Set(struct Vector3 *v, double x, double y, double z)
{
    v->r[0] = x;
    v->r[1] = y;
    v->r[2] = z;
}

variable_types:
v
struct Vector3 { double r[3]; } *

variable_types: x double

variable_types: y double

variable_types: z double


decompiled_code:
void __fastcall v3Add(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
*a1 = *a1 + a10;
a1[1] = a1[1] + a11;
a1[2] = a1[2] + a12;
}

canonical_decompiled_code:
void __fastcall func4(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
*a1 = *a1 + a10;
a1[1] = a1[1] + a11;
a1[2] = a1[2] + a12;
}

canonical_original_code:
void v3Add(struct Vector3 *v, struct Vector3 d)
{
    v->r[0] += d.r[0];
    v->r[1] += d.r[1];
    v->r[2] += d.r[2];
}

variable_types:
d
struct Vector3


decompiled_code:
void __fastcall v3Sub(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
*a1 = *a1 - a10;
a1[1] = a1[1] - a11;
a1[2] = a1[2] - a12;
}

canonical_decompiled_code:
void __fastcall func6(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12)
{
*a1 = *a1 - a10;
a1[1] = a1[1] - a11;
a1[2] = a1[2] - a12;
}

canonical_original_code:
void v3Sub(struct Vector3 *v, struct Vector3 d)
{
    v->r[0] -= d.r[0];
    v->r[1] -= d.r[1];
    v->r[2] -= d.r[2];
}


decompiled_code:
double __fastcall v3LenSquared(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
return a9 * a9 + a10 * a10 + a11 * a11;
}

canonical_decompiled_code:
double __fastcall func7(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
return a9 * a9 + a10 * a10 + a11 * a11;
}

original_code:
double v3LenSquared(Vector3 v)
{
    return v.r[0] * v.r[0] + v.r[1] * v.r[1] + v.r[2] * v.r[2];
}

canonical_original_code:
double v3LenSquared(struct Vector3 v)
{
    return v.r[0] * v.r[0] + v.r[1] * v.r[1] + v.r[2] * v.r[2];
}

variable_types:
v
struct Vector3 { double r[3]; }

return_type: double


decompiled_code:
void __fastcall v3Len(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v17; // xmm0_8

v17 = v3LenSquared(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
if ( v17 < 0.0 )
sqrt(v17);
}

canonical_decompiled_code:
void __fastcall func8(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11)
{
double v17; // xmm0_8

v17 = func7(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
if ( v17 < 0.0 )
sqrt(v17);
}

original_code:
double v3Len(Vector3 v)
{
    return sqrt(v3LenSquared(v));
}

canonical_original_code:
double v3Len(struct Vector3 v)
{
    return sqrt(v3LenSquared(v));
}


decompiled_code:
void __fastcall v3Scale(double *a1, double a2)
{
double v2; // xmm1_8
double v3; // xmm0_8

*a1 = *a1 * a2;
v2 = a1[1] * a2;
v3 = a2 * a1[2];
a1[1] = v2;
a1[2] = v3;
}

original_code:
void v3Scale(Vector3 *v, double scale)
{
    v->r[0] *= scale;
    v->r[1] *= scale;
    v->r[2] *= scale;
}

canonical_original_code:
void v3Scale(struct Vector3 *v, double scale)
{
    v->r[0] *= scale;
    v->r[1] *= scale;
    v->r[2] *= scale;
}

variable_types: scale double


decompiled_code:
void __fastcall v3Normalize(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
v3Len(a2, a3, a4, a5, a6, a7, a8, a9, *a1, a1[1], a1[2]);
*a1 = *a1 / a2;
a1[1] = a1[1] / a2;
a1[2] = a1[2] / a2;
}

canonical_decompiled_code:
void __fastcall func11(double *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
func8(a2, a3, a4, a5, a6, a7, a8, a9, *a1, a1[1], a1[2]);
*a1 = *a1 / a2;
a1[1] = a1[1] / a2;
a1[2] = a1[2] / a2;
}

original_code:
void v3Normalize(Vector3 *v)
{
    double len = v3Len(*v);
    v->r[0] /= len;
    v->r[1] /= len;
    v->r[2] /= len;
}

canonical_original_code:
void v3Normalize(struct Vector3 *v)
{
    double len = v3Len(*v);
    v->r[0] /= len;
    v->r[1] /= len;
    v->r[2] /= len;
}

variable_types: len double


decompiled_code:
double __fastcall v3Dot(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

canonical_decompiled_code:
double __fastcall func13(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
return a9 * a12 + a10 * a13 + a11 * a14;
}

canonical_original_code:
double v3Dot(struct Vector3 v1, struct Vector3 v2)
{
    return v1.r[0] * v2.r[0] + v1.r[1] * v2.r[1] + v1.r[2] * v2.r[2];
}


decompiled_code:
void __fastcall v3Angle(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
double v20; // xmm0_8

*(_QWORD *)&v20 = v3Cos(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
acos(v20);
}

canonical_decompiled_code:
void __fastcall func14(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14)
{
double v20; // xmm0_8

*(_QWORD *)&v20 = v3Cos(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
acos(v20);
}

original_code:
double v3Angle(Vector3 v1, Vector3 v2)
{
    return acos(v3Cos(v1, v2));
}

canonical_original_code:
double v3Angle(struct Vector3 v1, struct Vector3 v2)
{
    return acos(v3Cos(v1, v2));
}


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

v2 = calloc(1uLL, 0x18uLL);
paSet(a1 + 56, a2, v2);
return disOnData(a1, a2, &ns_handle_data, 0LL);
}

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

v2 = calloc(1uLL, 0x18uLL);
paSet(a1 + 56, a2, v2);
return disOnData(a1, a2, &ns_handle_data, 0LL);
}

original_code:
static void ns_add_connection(NS *ns, int fd)
{
    NS_Connection *conn = calloc(1, sizeof(NS_Connection));
    paSet(&ns->connections, fd, conn);
    if (0) _dbgPrint(stderr, "ns.c", 90, __func__, "New connection on fd %d\n", fd);
    disOnData(&ns->dis, fd, ns_handle_data, ((void *)0));
}

canonical_original_code:
static void ns_add_connection(struct NS *ns, int fd)
{
    struct NS_Connection *conn = calloc(1, sizeof(NS_Connection));
    paSet(&ns->connections, fd, conn);
    if (0) _dbgPrint(stderr, "ns.c", 90, __func__, "New connection on fd %d\n", fd);
    disOnData(&ns->dis, fd, ns_handle_data, ((void *)0));
}

variable_types: struct NS { struct Dispatcher { struct PointerArray { int num_ptrs; void **ptr; } files; struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } timers; struct timeval { long tv_sec; long tv_usec; } tv; } dis; struct PointerArray connections; void (*on_connect_cb)(struct NS *ns, int fd, void *udata); void *on_connect_udata; void (*on_disconnect_cb)(struct NS *ns, int fd, void *udata); void *on_disconnect_udata; void (*on_error_cb)(struct NS *ns, int fd, int error, void *udata); void *on_error_udata; void (*on_socket_cb)(struct NS *ns, int fd, char *buffer, int size, void *udata); void *on_socket_udata; } *

variable_types: fd int

variable_types: struct NS_Connection { struct Buffer { char *data; unsigned long used; unsigned long size; } incoming; } *

user_defined_types: struct NS { struct Dispatcher dis; struct PointerArray connections; void (*on_connect_cb)(struct NS *ns, int fd, void *udata); void *on_connect_udata; void (*on_disconnect_cb)(struct NS *ns, int fd, void *udata); void *on_disconnect_udata; void (*on_error_cb)(struct NS *ns, int fd, int error, void *udata); void *on_error_udata; void (*on_socket_cb)(struct NS *ns, int fd, char *buffer, int size, void *udata); void *on_socket_udata; }

user_defined_types: struct NS_Connection { struct Buffer incoming; }

user_defined_types: struct Dispatcher { struct PointerArray files; struct List timers; struct timeval tv; }

user_defined_types: struct List { struct ListNode *head; struct ListNode *tail; int length; }


nsInit

decompiled_code:
__int64 __fastcall nsInit(_QWORD *a1)
{
int v1; // ecx
unsigned __int64 v2; // rdi
__int64 result; // rax

*a1 = 0LL;
v1 = (int)a1;
v2 = (unsigned __int64)(a1 + 1);
result = 0LL;
*(_QWORD *)(v2 + 120) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * ((v1 - (v2 & 0xFFFFFFF8) + 136) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
int v1; // ecx
unsigned __int64 v2; // rdi
__int64 result; // rax

*a1 = 0LL;
v1 = (int)a1;
v2 = (unsigned __int64)(a1 + 1);
result = 0LL;
*(_QWORD *)(v2 + 120) = 0LL;
memset((void *)(v2 & 0xFFFFFFFFFFFFFFF8LL), 0, 8 * ((v1 - (v2 & 0xFFFFFFF8) + 136) >> 3));
return result;
}

original_code:
void nsInit(NS *ns)
{
    memset(ns, 0, sizeof(NS));
}

canonical_original_code:
void nsInit(struct NS *ns)
{
    memset(ns, 0, sizeof(NS));
}

user_defined_types: struct PointerArray { int num_ptrs; void **ptr; }

user_defined_types: struct timeval { long tv_sec; long tv_usec; }

user_defined_types: struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; }


nsCreate

decompiled_code:
void *nsCreate()
{
void *v0; // r12

v0 = calloc(1uLL, 0x88uLL);
disInit(v0);
return v0;
}

canonical_decompiled_code:
void *func2()
{
void *v0; // r12

v0 = calloc(1uLL, 0x88uLL);
disInit(v0);
return v0;
}

original_code:
NS *nsCreate(void)
{
    NS *ns = calloc(1, sizeof(NS));
    disInit(&ns->dis);
    return ns;
}

canonical_original_code:
struct NS *nsCreate()
{
    struct NS *ns = calloc(1, sizeof(NS));
    disInit(&ns->dis);
    return ns;
}

return_type: struct NS { struct Dispatcher { struct PointerArray { int num_ptrs; void **ptr; } files; struct List { struct ListNode { struct ListNode *next; struct ListNode *prev; struct List *list; } *head; struct ListNode *tail; int length; } timers; struct timeval { long tv_sec; long tv_usec; } tv; } dis; struct PointerArray connections; void (*on_connect_cb)(struct NS *ns, int fd, void *udata); void *on_connect_udata; void (*on_disconnect_cb)(struct NS *ns, int fd, void *udata); void *on_disconnect_udata; void (*on_error_cb)(struct NS *ns, int fd, int error, void *udata); void *on_error_udata; void (*on_socket_cb)(struct NS *ns, int fd, char *buffer, int size, void *udata); void *on_socket_udata; } *


nsListen

decompiled_code:
__int64 __fastcall nsListen(__int64 a1, __int64 a2, unsigned __int16 a3)
{
int v3; // eax
unsigned int v4; // er12

v3 = tcpListen(a2, a3);
if ( v3 < 0 )
return (unsigned int)-1;
v4 = v3;
disOnData(a1, (unsigned int)v3, ns_accept_connection, 0LL);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned __int16 a3)
{
int v3; // eax
unsigned int v4; // er12

v3 = tcpListen(a2, a3);
if ( v3 < 0 )
return (unsigned int)-1;
v4 = v3;
disOnData(a1, (unsigned int)v3, ns_accept_connection, 0LL);
return v4;
}

original_code:
int nsListen(NS *ns, const char *host, uint16_t port)
{
    int listen_fd;
    if ((listen_fd = tcpListen(host, port)) < 0) {
        return -1;
    }
    disOnData(&ns->dis, listen_fd, ns_accept_connection, ((void *)0));
    return listen_fd;
}

canonical_original_code:
int nsListen(struct NS *ns, char *host, unsigned short port)
{
    int listen_fd;
    if ((listen_fd = tcpListen(host, port)) < 0) {
        return -1;
    }
    disOnData(&ns->dis, listen_fd, ns_accept_connection, ((void *)0));
    return listen_fd;
}

variable_types:
host
char *

variable_types:
port
unsigned short

return_type: int


nsOnConnect

original_code:
void nsOnConnect(NS *ns, void (*cb)(NS *ns, int fd, void *udata), void *udata)
{
    ns->on_connect_cb = cb;
    ns->on_connect_udata = udata;
}

canonical_original_code:
void nsOnConnect(struct NS *ns, void (*cb)(struct NS *ns, int fd, void *udata), void *udata)
{
    ns->on_connect_cb = cb;
    ns->on_connect_udata = udata;
}

variable_types: void (*)(struct NS *ns, int fd, void *udata)

variable_types:
udata
void *


nsOnDisconnect

decompiled_code:
void __fastcall nsOnDisconnect(__int64 a1, __int64 a2, __int64 a3)
{
*(_QWORD *)(a1 + 88) = a2;
*(_QWORD *)(a1 + 96) = a3;
}

original_code:
void nsOnDisconnect(NS *ns, void (*cb)(NS *ns, int fd, void *udata), void *udata)
{
    ns->on_disconnect_cb = cb;
    ns->on_disconnect_udata = udata;
}

canonical_original_code:
void nsOnDisconnect(struct NS *ns, void (*cb)(struct NS *ns, int fd, void *udata), void *udata)
{
    ns->on_disconnect_cb = cb;
    ns->on_disconnect_udata = udata;
}


nsOnSocket

original_code:
void nsOnSocket(NS *ns, void (*cb)(NS *ns, int fd, const char *buffer, int size, void *udata),
        void *udata)
{
    ns->on_socket_cb = cb;
    ns->on_socket_udata = udata;
}

canonical_original_code:
void nsOnSocket(struct NS *ns, void (*cb)(struct NS *ns, int fd, char *buffer, int size, void *udata), void *udata)
{
    ns->on_socket_cb = cb;
    ns->on_socket_udata = udata;
}

variable_types: void (*)(struct NS *ns, int fd, char *buffer, int size, void *udata)


nsOnError

original_code:
void nsOnError(NS *ns, void (*cb)(NS *ns, int fd, int error, void *udata), void *udata)
{
    ns->on_error_cb = cb;
    ns->on_error_udata = udata;
}

canonical_original_code:
void nsOnError(struct NS *ns, void (*cb)(struct NS *ns, int fd, int error, void *udata), void *udata)
{
    ns->on_error_cb = cb;
    ns->on_error_udata = udata;
}

variable_types: void (*)(struct NS *ns, int fd, int error, void *udata)


nsConnect

decompiled_code:
__int64 __fastcall nsConnect(__int64 a1, __int64 a2, unsigned __int16 a3)
{
__int64 result; // rax
unsigned int v4; // [rsp+Ch] [rbp-Ch]

result = tcpConnect(a2, a3);
if ( (int)result >= 0 )
{
v4 = result;
ns_add_connection(a1, result);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, unsigned __int16 a3)
{
__int64 result; // rax
unsigned int v4; // [rsp+Ch] [rbp-Ch]

result = tcpConnect(a2, a3);
if ( (int)result >= 0 )
{
v4 = result;
func0(a1, result);
result = v4;
}
return result;
}

original_code:
int nsConnect(NS *ns, const char *host, uint16_t port)
{
    int fd = tcpConnect(host, port);
    if (fd >= 0) {
        ns_add_connection(ns, fd);
    }
    return fd;
}

canonical_original_code:
int nsConnect(struct NS *ns, char *host, unsigned short port)
{
    int fd = tcpConnect(host, port);
    if (fd >= 0) {
        ns_add_connection(ns, fd);
    }
    return fd;
}


nsDisconnect

decompiled_code:
void __fastcall nsDisconnect(__int64 a1, unsigned int a2)
{
void *v2; // r12

v2 = (void *)paGet(a1 + 56);
close(a2);
disDropData(a1, a2);
paDrop(a1 + 56, a2);
bufRewind(v2);
free(v2);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, unsigned int a2)
{
void *v2; // r12

v2 = (void *)paGet(a1 + 56);
close(a2);
disDropData(a1, a2);
paDrop(a1 + 56, a2);
bufRewind(v2);
free(v2);
}

original_code:
void nsDisconnect(NS *ns, int fd)
{
    NS_Connection *conn = paGet(&ns->connections, fd);
    if (0) _dbgPrint(stderr, "ns.c", 215, __func__, "Closing fd %d\n", fd);
    close(fd);
    disDropData(&ns->dis, fd);
    paDrop(&ns->connections, fd);
    bufRewind(&conn->incoming);
    free(conn);
}

canonical_original_code:
void nsDisconnect(struct NS *ns, int fd)
{
    struct NS_Connection *conn = paGet(&ns->connections, fd);
    if (0) _dbgPrint(stderr, "ns.c", 215, __func__, "Closing fd %d\n", fd);
    close(fd);
    disDropData(&ns->dis, fd);
    paDrop(&ns->connections, fd);
    bufRewind(&conn->incoming);
    free(conn);
}

user_defined_types: struct Buffer { char *data; unsigned long used; unsigned long size; }