decompiled_code:
__int64 __fastcall parse_command_line(int a1, _QWORD *a2)
{
const char *v3; // rdi
int v4; // eax
const char *v5; // rdi
int v6; // eax

if ( a1 <= 1 )
return usage("You must supply at least a <player-name>.");
my_player_name = a2[1];
v3 = (const char *)a2[2];
v4 = 0;
if ( v3 )
v4 = atoi(v3);
my_connect_port = v4;
hosting = a1 <= 3;
if ( a1 > 3 )
{
host_ip = a2[3];
v5 = (const char *)a2[4];
v6 = 0;
if ( v5 )
v6 = atoi(v5);
host_port = v6;
}
_printf_chk(1LL, "-- command line arguments: ");
_printf_chk(
1LL,
"name=%s, connect_to=%d, hosting=%d host_ip=%s, host_port=%d\n",
(const char *)my_player_name,
(unsigned int)my_connect_port,
(unsigned int)hosting,
(const char *)host_ip,
(unsigned int)host_port);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, _QWORD *a2)
{
const char *v3; // rdi
int v4; // eax
const char *v5; // rdi
int v6; // eax

if ( a1 <= 1 )
return func8("You must supply at least a <player-name>.");
my_player_name = a2[1];
v3 = (const char *)a2[2];
v4 = 0;
if ( v3 )
v4 = atoi(v3);
my_connect_port = v4;
hosting = a1 <= 3;
if ( a1 > 3 )
{
host_ip = a2[3];
v5 = (const char *)a2[4];
v6 = 0;
if ( v5 )
v6 = atoi(v5);
host_port = v6;
}
_printf_chk(1LL, "-- command line arguments: ");
_printf_chk(
1LL,
"name=%s, connect_to=%d, hosting=%d host_ip=%s, host_port=%d\n",
(const char *)my_player_name,
(unsigned int)my_connect_port,
(unsigned int)hosting,
(const char *)host_ip,
(unsigned int)host_port);
return 0LL;
}

original_code:
int parse_command_line( int argc, char ** argv )
{
 if ( argc < 2 )
  return usage("You must supply at least a <player-name>.");
 my_player_name = (char*) argv[1];
 my_connect_port = argv[2] ? atoi(argv[2]) : 0 ;
 hosting = (argc < 4) ? 1 : 0 ;
 if(!hosting)
 {
  host_ip = (char*) argv[3];
  host_port = argv[4] ? atoi(argv[4]) : 0 ;
 }
 printf("-- command line arguments: ");
 printf("name=%s, connect_to=%d, hosting=%d host_ip=%s, host_port=%d\n",
  my_player_name, my_connect_port, hosting, host_ip, host_port);
 return 0;
}

canonical_original_code:
int parse_command_line(int argc, char **argv)
{
 if ( argc < 2 )
  return usage("You must supply at least a <player-name>.");
 my_player_name = (char *) argv[1];
 my_connect_port = argv[2] ? atoi(argv[2]) : 0 ;
 hosting = (argc < 4) ? 1 : 0 ;
 if(!hosting)
 {
  host_ip = (char *) argv[3];
  host_port = argv[4] ? atoi(argv[4]) : 0 ;
 }
 printf("-- command line arguments: ");
 printf("name=%s, connect_to=%d, hosting=%d host_ip=%s, host_port=%d\n",
  my_player_name, my_connect_port, hosting, host_ip, host_port);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


repo: ForsakenX/forsaken

decompiled_code:
__int64 bind_port()
{
int v0; // eax
unsigned int v1; // edx

v0 = network_setup(my_player_name, (unsigned int)my_connect_port);
v1 = 0;
if ( v0 )
{
if ( v0 == 1 )
{
puts("-- enet failed to initialize.");
v1 = 1;
}
else
{
v1 = 1;
if ( v0 == 2 )
{
puts("-- either your local port is already in use or your arguments were invalid.");
v1 = 1;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // eax
unsigned int v1; // edx

v0 = network_setup(my_player_name, (unsigned int)my_connect_port);
v1 = 0;
if ( v0 )
{
if ( v0 == 1 )
{
puts("-- enet failed to initialize.");
v1 = 1;
}
else
{
v1 = 1;
if ( v0 == 2 )
{
puts("-- either your local port is already in use or your arguments were invalid.");
v1 = 1;
}
}
}
return v1;
}

original_code:
int bind_port( void )
{
 int rv = network_setup( my_player_name, my_connect_port );
 if( rv != NETWORK_OK )
 {
  switch( rv )
  {
  case NETWORK_ERROR_BIND:
   puts("-- either your local port is already in use or your arguments were invalid.");
   break;
  case NETWORK_ERROR_INIT:
   puts("-- enet failed to initialize.");
   break;
  }
  return 1;
 }
 return 0;
}

canonical_original_code:
int bind_port()
{
 int rv = network_setup( my_player_name, my_connect_port );
 if( rv != NETWORK_OK )
 {
  switch( rv )
  {
  case NETWORK_ERROR_BIND:
   puts("-- either your local port is already in use or your arguments were invalid.");
   break;
  case NETWORK_ERROR_INIT:
   puts("-- enet failed to initialize.");
   break;
  }
  return 1;
 }
 return 0;
}

variable_types: rv int

return_type: int


decompiled_code:
unsigned __int64 __fastcall describe_player(__int64 a1)
{
unsigned __int64 v2; // [rsp+10h] [rbp-10h]

v2 = __readfsqword(0x28u);
_printf_chk(
1LL,
"{ name: %s, source: %s:%d, ping: %ld/ms, bw{ in: %ld, out: %ld }, loss: %ld }\n",
(const char *)a1,
(const char *)(a1 + 15),
*(unsigned int *)(a1 + 32),
*(_QWORD *)(a1 + 40),
*(_QWORD *)(a1 + 64),
*(_QWORD *)(a1 + 72),
*(_QWORD *)(a1 + 48));
return v2 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func11(__int64 a1)
{
unsigned __int64 v2; // [rsp+10h] [rbp-10h]

v2 = __readfsqword(0x28u);
_printf_chk(
1LL,
"{ name: %s, source: %s:%d, ping: %ld/ms, bw{ in: %ld, out: %ld }, loss: %ld }\n",
(const char *)a1,
(const char *)(a1 + 15),
*(unsigned int *)(a1 + 32),
*(_QWORD *)(a1 + 40),
*(_QWORD *)(a1 + 64),
*(_QWORD *)(a1 + 72),
*(_QWORD *)(a1 + 48));
return v2 - __readfsqword(0x28u);
}

original_code:
void describe_player( network_player_t * player )
{
 printf( "{ name: %s, source: %s:%d, ping: %ld/ms, bw{ in: %ld, out: %ld }, loss: %ld }\n",
  player->name, player->ip, player->port, player->ping,
  player->bw_in, player->bw_out, player->packet_loss );
}

canonical_original_code:
void describe_player(struct _network_player_t *player)
{
 printf( "{ name: %s, source: %s:%d, ping: %ld/ms, bw{ in: %ld, out: %ld }, loss: %ld }\n",
  player->name, player->ip, player->port, player->ping,
  player->bw_in, player->bw_out, player->packet_loss );
}

variable_types: struct _network_player_t { char name[15]; char ip[16]; int port; unsigned long ping; unsigned long packet_loss; unsigned long packets_lost; unsigned long bw_in; unsigned long bw_out; struct _network_player_t *prev; struct _network_player_t *next; void *data; } *

return_type: void


decompiled_code:
unsigned __int64 debug_network_state()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
switch ( network_state )
{
case 0:
puts("-- network state NETWORK_CONNECTED");
break;
case 1:
puts("-- network state NETWORK_CONNECTING");
break;
case 2:
puts("-- network state NETWORK_DISCONNECTED");
break;
case 3:
puts("-- network state NETWORK_SYNCHING");
break;
case 4:
puts("-- network state NETWORK_SYNCH_FAILED");
break;
default:
return v1 - __readfsqword(0x28u);
}
return v1 - __readfsqword(0x28u);
}

canonical_decompiled_code:
unsigned __int64 func12()
{
unsigned __int64 v1; // [rsp+8h] [rbp-10h]

v1 = __readfsqword(0x28u);
switch ( network_state )
{
case 0:
puts("-- network state NETWORK_CONNECTED");
break;
case 1:
puts("-- network state NETWORK_CONNECTING");
break;
case 2:
puts("-- network state NETWORK_DISCONNECTED");
break;
case 3:
puts("-- network state NETWORK_SYNCHING");
break;
case 4:
puts("-- network state NETWORK_SYNCH_FAILED");
break;
default:
return v1 - __readfsqword(0x28u);
}
return v1 - __readfsqword(0x28u);
}

original_code:
void debug_network_state( void )
{
 switch( network_state )
 {
 case NETWORK_CONNECTED: puts("-- network state " "NETWORK_CONNECTED"); break;;
 case NETWORK_CONNECTING: puts("-- network state " "NETWORK_CONNECTING"); break;;
 case NETWORK_DISCONNECTED: puts("-- network state " "NETWORK_DISCONNECTED"); break;;
 case NETWORK_SYNCHING: puts("-- network state " "NETWORK_SYNCHING"); break;;
 case NETWORK_SYNCH_FAILED: puts("-- network state " "NETWORK_SYNCH_FAILED"); break;;
 }
}

canonical_original_code:
void debug_network_state()
{
 switch( network_state )
 {
 case NETWORK_CONNECTED: puts("-- network state " "NETWORK_CONNECTED"); break;;
 case NETWORK_CONNECTING: puts("-- network state " "NETWORK_CONNECTING"); break;;
 case NETWORK_DISCONNECTED: puts("-- network state " "NETWORK_DISCONNECTED"); break;;
 case NETWORK_SYNCHING: puts("-- network state " "NETWORK_SYNCHING"); break;;
 case NETWORK_SYNCH_FAILED: puts("-- network state " "NETWORK_SYNCH_FAILED"); break;;
 }
}


decompiled_code:
__int64 connect_to_host()
{
__int64 result; // rax
int i; // eax
int j; // eax

if ( (unsigned int)network_join(host_ip, (unsigned int)host_port) == 1 )
{
puts("-- waiting to connect to host.");
for ( i = network_state; network_state == 1; i = network_state )
network_pump();
if ( i == 2 )
{
puts("-- failed to connect to host to host.");
exit(1);
}
puts("-- synching with other players.");
for ( j = network_state; network_state == 3; j = network_state )
network_pump();
if ( j == 4 )
{
puts("-- synching failed");
exit(1);
}
if ( j )
{
debug_network_state();
puts("-- disconnect during synch");
exit(1);
}
puts("-- successfully synched with all players");
result = 0LL;
}
else
{
puts("-- failed to join game");
puts("-- most likely your arguments were invalid");
result = usage(0LL);
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
int i; // eax
int j; // eax

if ( (unsigned int)network_join(host_ip, (unsigned int)host_port) == 1 )
{
puts("-- waiting to connect to host.");
for ( i = network_state; network_state == 1; i = network_state )
network_pump();
if ( i == 2 )
{
puts("-- failed to connect to host to host.");
exit(1);
}
puts("-- synching with other players.");
for ( j = network_state; network_state == 3; j = network_state )
network_pump();
if ( j == 4 )
{
puts("-- synching failed");
exit(1);
}
if ( j )
{
func12();
puts("-- disconnect during synch");
exit(1);
}
puts("-- successfully synched with all players");
result = 0LL;
}
else
{
puts("-- failed to join game");
puts("-- most likely your arguments were invalid");
result = func8(0LL);
}
return result;
}

original_code:
int connect_to_host( void )
{
 int rv = network_join( host_ip, host_port );
 if( rv != 1 )
 {
  puts("-- failed to join game");
  puts("-- most likely your arguments were invalid");
  return usage(((void *)0));
 }
 printf("-- waiting to connect to host.\n");
 while( network_state == NETWORK_CONNECTING )
  network_pump();
 if( network_state == NETWORK_DISCONNECTED )
 {
  puts("-- failed to connect to host to host.");
  exit(1);
 }
 printf("-- synching with other players.\n");
 while( network_state == NETWORK_SYNCHING )
  network_pump();
 if( network_state == NETWORK_SYNCH_FAILED )
 {
  puts("-- synching failed");
  exit(1);
 }
 if( network_state != NETWORK_CONNECTED )
 {
  debug_network_state();
  puts("-- disconnect during synch");
  exit(1);
 }
 puts("-- successfully synched with all players");
 return 0;
}

canonical_original_code:
int connect_to_host()
{
 int rv = network_join( host_ip, host_port );
 if( rv != 1 )
 {
  puts("-- failed to join game");
  puts("-- most likely your arguments were invalid");
  return usage(((void *)0));
 }
 printf("-- waiting to connect to host.\n");
 while( network_state == NETWORK_CONNECTING )
  network_pump();
 if( network_state == NETWORK_DISCONNECTED )
 {
  puts("-- failed to connect to host to host.");
  exit(1);
 }
 printf("-- synching with other players.\n");
 while( network_state == NETWORK_SYNCHING )
  network_pump();
 if( network_state == NETWORK_SYNCH_FAILED )
 {
  puts("-- synching failed");
  exit(1);
 }
 if( network_state != NETWORK_CONNECTED )
 {
  debug_network_state();
  puts("-- disconnect during synch");
  exit(1);
 }
 puts("-- successfully synched with all players");
 return 0;
}


decompiled_code:
__int64 setup_network()
{
unsigned int v0; // ebx
int v1; // ebp

atexit((void (*)(void))&network_cleanup);
v0 = 1;
if ( !(unsigned int)bind_port() )
{
v0 = 0;
v1 = hosting;
if ( hosting )
{
network_host();
puts("-- waiting for connections.");
}
else
{
connect_to_host();
v0 = v1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func14()
{
unsigned int v0; // ebx
int v1; // ebp

atexit((void (*)(void))&network_cleanup);
v0 = 1;
if ( !(unsigned int)func10() )
{
v0 = 0;
v1 = hosting;
if ( hosting )
{
network_host();
puts("-- waiting for connections.");
}
else
{
func13();
v0 = v1;
}
}
return v0;
}

original_code:
int setup_network()
{
 atexit(network_cleanup);
 if(bind_port())
  return 1;
 if(hosting)
 {
  network_host();
  printf("-- waiting for connections.\n");
 }
 else
 {
  connect_to_host();
 }
 return 0;
}


decompiled_code:
__int64 __fastcall destroy_image(_QWORD *a1)
{
__int64 result; // rax

result = X_free(a1[35], "texture_png.c", 13LL);
*a1 = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1)
{
__int64 result; // rax

result = X_free(a1[35], "texture_png.c", 13LL);
*a1 = 0LL;
return result;
}

original_code:
void destroy_image( texture_image_t * image )
{
 X_free( (image->data), "texture_png.c", 13 );
 memset(image,0,sizeof(image));
}

canonical_original_code:
void destroy_image(struct texture_image_t *image)
{
 X_free( (image->data), "texture_png.c", 13 );
 memset(image,0,sizeof(image));
}

variable_types: struct texture_image_t { int id; int w; int h; int size; int colorkey; char path[256]; char *data; } *


SphereNormal

decompiled_code:
void __fastcall SphereNormal(float *a1, float *a2, float *a3, float a4)
{
*a3 = (float)(*a2 - *a1) / a4;
a3[1] = (float)(a2[1] - a1[1]) / a4;
a3[2] = (float)(a2[2] - a1[2]) / a4;
}

original_code:
void SphereNormal( VECTOR * Pos , VECTOR * Point , float radius , NORMAL * Normal )
{
 Normal->nx = ( Point->x - Pos->x ) / radius;
 Normal->ny = ( Point->y - Pos->y ) / radius;
 Normal->nz = ( Point->z - Pos->z ) / radius;
}

canonical_original_code:
void SphereNormal(struct VECTOR *Pos, struct VECTOR *Point, float radius, struct NORMAL *Normal)
{
 Normal->nx = ( Point->x - Pos->x ) / radius;
 Normal->ny = ( Point->y - Pos->y ) / radius;
 Normal->nz = ( Point->z - Pos->z ) / radius;
}

variable_types: struct VECTOR { float x; float y; float z; } *

variable_types:
Point
struct VECTOR *

variable_types: radius float

variable_types: struct NORMAL { union { float nx; float x; }; union { float ny; float y; }; union { float nz; float z; }; } *


isNotZero

decompiled_code:
double __fastcall isNotZero(double result)
{
if ( *(float *)&result > -0.0000001 && *(float *)&result < 0.0000001 )
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func1(double result)
{
if ( *(float *)&result > -0.0000001 && *(float *)&result < 0.0000001 )
result = 0.0;
return result;
}

original_code:
float isNotZero(float x)
{
 if( ( x > -1e-7 ) && ( x < 1e-7 ) )
  return 0.0F;
 return x;
}

variable_types: x float

return_type: float


solveQuadric

decompiled_code:
float __fastcall solveQuadric(float *a1, float *a2)
{
float v2; // ebx
double v3; // xmm0_8
double v4; // xmm0_8
float result; // xmm0_4
float v6; // xmm0_4
float x; // [rsp+Ch] [rbp-14h]

v2 = a1[1];
*(_QWORD *)&v3 = _mm_cvtsi32_si128(LODWORD(v2)).m128i_u64[0];
*(float *)&v3 = (float)(*(float *)&v3 * *(float *)&v3) - *a1;
x = *(float *)&v3;
v4 = isNotZero(v3);
if ( *(float *)&v4 == 0.0 )
{
*((_DWORD *)a2 + 1) = LODWORD(v2) ^ LC5;
*(_DWORD *)a2 = LODWORD(v2) ^ LC5;
result = *(float *)&LC3;
}
else
{
result = 0.0;
if ( x >= 0.0 )
{
v6 = fsqrt(x);
*a2 = v6 - v2;
a2[1] = COERCE_FLOAT(LODWORD(v6) ^ LC5) - v2;
result = *(float *)&LC4;
}
}
return result;
}

canonical_decompiled_code:
float __fastcall func2(float *a1, float *a2)
{
float v2; // ebx
double v3; // xmm0_8
double v4; // xmm0_8
float result; // xmm0_4
float v6; // xmm0_4
float x; // [rsp+Ch] [rbp-14h]

v2 = a1[1];
*(_QWORD *)&v3 = _mm_cvtsi32_si128(LODWORD(v2)).m128i_u64[0];
*(float *)&v3 = (float)(*(float *)&v3 * *(float *)&v3) - *a1;
x = *(float *)&v3;
v4 = func1(v3);
if ( *(float *)&v4 == 0.0 )
{
*((_DWORD *)a2 + 1) = LODWORD(v2) ^ LC5;
*(_DWORD *)a2 = LODWORD(v2) ^ LC5;
result = *(float *)&LC3;
}
else
{
result = 0.0;
if ( x >= 0.0 )
{
v6 = fsqrt(x);
*a2 = v6 - v2;
a2[1] = COERCE_FLOAT(LODWORD(v6) ^ LC5) - v2;
result = *(float *)&LC4;
}
}
return result;
}

original_code:
float solveQuadric(float * c, float * s)
{
float p, q, D;
float sqrt_D;
 p = c[1];
 q = c[0];
 D = p * p - q;
 if (!isNotZero(D))
     {
     s[0] = s[1] = -p;
     return 1.0F;
     }
 if (D < 0.0F)
     return 0.0F;
    sqrt_D = (float) sqrt(D);
    s[0] = sqrt_D - p;
    s[1] = -sqrt_D - p;
    return 2.0F;
}

canonical_original_code:
float solveQuadric(float *c, float *s)
{
float p; float q; float D;
float sqrt_D;
 p = c[1];
 q = c[0];
 D = p * p - q;
 if (!isNotZero(D))
     {
     s[0] = s[1] = -p;
     return 1.0F;
     }
 if (D < 0.0F)
     return 0.0F;
    sqrt_D = (float) sqrt(D);
    s[0] = sqrt_D - p;
    s[1] = -sqrt_D - p;
    return 2.0F;
}

variable_types:
c
float *

variable_types:
s
float *

variable_types: p float

variable_types: q float

variable_types: D float


decompiled_code:
__int64 __fastcall closest_intersection(float *a1, float a2)
{
float v3; // xmm0_4
__int64 result; // rax
float v5; // xmm1_4

v3 = 0.0;
if ( a2 != 0.0 )
v3 = *a1;
result = 2LL;
if ( a2 > 1.0 )
{
do
{
v3 = fminf(a1[result - 1], v3);
v5 = (float)(int)result++;
}
while ( a2 > v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(float *a1, float a2)
{
float v3; // xmm0_4
__int64 result; // rax
float v5; // xmm1_4

v3 = 0.0;
if ( a2 != 0.0 )
v3 = *a1;
result = 2LL;
if ( a2 > 1.0 )
{
do
{
v3 = fminf(a1[result - 1], v3);
v5 = (float)(int)result++;
}
while ( a2 > v5 );
}
return result;
}

original_code:
float closest_intersection(float * x, float x_num)
{
int i;
float x_min;
 x_min = (x_num) ? x[0] : 0.0F;
 for ( i = 1 ; i < x_num ; i++ )
 {
     if (x[i] < x_min)
  x_min = x[i];
 }
 return x_min;
}

canonical_original_code:
float closest_intersection(float *x, float x_num)
{
int i;
float x_min;
 x_min = (x_num) ? x[0] : 0.0F;
 for ( i = 1 ; i < x_num ; i++ )
 {
     if (x[i] < x_min)
  x_min = x[i];
 }
 return x_min;
}

variable_types:
x
float *

variable_types: i int


intersect

decompiled_code:
__int64 __fastcall intersect(float *a1, float *a2, __int64 a3, float a4)
{
float v4; // xmm0_4
int v7[3]; // [rsp+14h] [rbp-1Ch] BYREF
float v8; // [rsp+20h] [rbp-10h] BYREF
int v9[2]; // [rsp+28h] [rbp-8h] BYREF

*(float *)v7 = *a2 - *a1;
*(float *)&v7[1] = a2[1] - a1[1];
*(float *)&v7[2] = a2[2] - a1[2];
v9[1] = DotProduct(a3, v7);
*(float *)v9 = DotProduct(v7, v7) - (float)(a4 * a4);
v4 = solveQuadric((float *)v9, &v8);
return closest_intersection(&v8, v4);
}

canonical_decompiled_code:
__int64 __fastcall func4(float *a1, float *a2, __int64 a3, float a4)
{
float v4; // xmm0_4
int v7[3]; // [rsp+14h] [rbp-1Ch] BYREF
float v8; // [rsp+20h] [rbp-10h] BYREF
int v9[2]; // [rsp+28h] [rbp-8h] BYREF

*(float *)v7 = *a2 - *a1;
*(float *)&v7[1] = a2[1] - a1[1];
*(float *)&v7[2] = a2[2] - a1[2];
v9[1] = DotProduct(a3, v7);
*(float *)v9 = DotProduct(v7, v7) - (float)(a4 * a4);
v4 = func2((float *)v9, &v8);
return func3(&v8, v4);
}

original_code:
float intersect(VECTOR * sphere_pos, float radius , VECTOR * ray_org, VECTOR * ray_dir)
{
 float c[2];
 float s[2];
 float num;
 VECTOR d;
 d.x = ray_org->x - sphere_pos->x;
 d.y = ray_org->y - sphere_pos->y;
 d.z = ray_org->z - sphere_pos->z;
 c[1] = DotProduct( ray_dir , &d);
 c[0] = DotProduct(&d , &d) - radius * radius;
 num = solveQuadric( (float*) &c, (float*) &s);
 return closest_intersection( (float*) &s , num );
}

canonical_original_code:
float intersect(struct VECTOR *sphere_pos, float radius, struct VECTOR *ray_org, struct VECTOR *ray_dir)
{
 float c[2];
 float s[2];
 float num;
 struct VECTOR d;
 d.x = ray_org->x - sphere_pos->x;
 d.y = ray_org->y - sphere_pos->y;
 d.z = ray_org->z - sphere_pos->z;
 c[1] = DotProduct( ray_dir , &d);
 c[0] = DotProduct(&d , &d) - radius * radius;
 num = solveQuadric( (float *) &c, (float *) &s);
 return closest_intersection( (float *) &s , num );
}

variable_types:
c
float [2]

variable_types:
s
float [2]

variable_types: num float

variable_types: struct VECTOR { float x; float y; float z; }


original_code:
_Bool RaytoSphere2( VECTOR * sorigin, float radius, VECTOR * rorigin, VECTOR * rdir, VECTOR * inter, VECTOR * inter2 )
{
 float v;
 float disc;
 float d, d2;
 float d0;
 float d1;
 VECTOR EO;
 EO.x = (rorigin->x - sorigin->x);
 EO.y = (rorigin->y - sorigin->y);
 EO.z = (rorigin->z - sorigin->z);
 if( VectorLength( &EO ) <= radius ) return 0;
 v = ( ( EO.x * rdir->x ) + ( EO.y * rdir->y ) + ( EO.z * rdir->z ) );
 disc = ( ( radius * radius ) - ( ( ( EO.x * EO.x ) + ( EO.y * EO.y ) + ( EO.z * EO.z ) ) - ( v * v ) ) );
 if ( disc < 0.0F ) return 0;
 d = (float) sqrt( disc );
 d0 = d - v;
 d1 = ( -d ) - v;
 d = (d0 < d1) ? d0 : d1;
 d2 = (d0 > d1) ? d0 : d1;
 if ( d < 0.0F ) return 0;
 inter->x = rorigin->x + (rdir->x * d);
 inter->y = rorigin->y + (rdir->y * d);
 inter->z = rorigin->z + (rdir->z * d);
 inter2->x = rorigin->x + (rdir->x * d2);
 inter2->y = rorigin->y + (rdir->y * d2);
 inter2->z = rorigin->z + (rdir->z * d2);
 return 1;
}

canonical_original_code:
_Bool RaytoSphere2(struct VECTOR *sorigin, float radius, struct VECTOR *rorigin, struct VECTOR *rdir, struct VECTOR *inter, struct VECTOR *inter2)
{
 float v;
 float disc;
 float d; float d2;
 float d0;
 float d1;
 struct VECTOR EO;
 EO.x = (rorigin->x - sorigin->x);
 EO.y = (rorigin->y - sorigin->y);
 EO.z = (rorigin->z - sorigin->z);
 if( VectorLength( &EO ) <= radius ) return 0;
 v = ( ( EO.x * rdir->x ) + ( EO.y * rdir->y ) + ( EO.z * rdir->z ) );
 disc = ( ( radius * radius ) - ( ( ( EO.x * EO.x ) + ( EO.y * EO.y ) + ( EO.z * EO.z ) ) - ( v * v ) ) );
 if ( disc < 0.0F ) return 0;
 d = (float) sqrt( disc );
 d0 = d - v;
 d1 = ( -d ) - v;
 d = (d0 < d1) ? d0 : d1;
 d2 = (d0 > d1) ? d0 : d1;
 if ( d < 0.0F ) return 0;
 inter->x = rorigin->x + (rdir->x * d);
 inter->y = rorigin->y + (rdir->y * d);
 inter->z = rorigin->z + (rdir->z * d);
 inter2->x = rorigin->x + (rdir->x * d2);
 inter2->y = rorigin->y + (rdir->y * d2);
 inter2->z = rorigin->z + (rdir->z * d2);
 return 1;
}

variable_types:
rorigin
struct VECTOR *

variable_types:
rdir
struct VECTOR *

variable_types:
inter
struct VECTOR *

variable_types: v float

variable_types: disc float

variable_types: d float

user_defined_types: struct VECTOR { float x; float y; float z; }


decompiled_code:
__int64 __fastcall RaytoSphere3(float *a1, float *a2, float *a3, float *a4, float a5)
{
float v7; // xmm0_4
__int64 result; // rax
float v9; // xmm0_4
float v10; // xmm0_4
float v11; // xmm1_4
float v12; // [rsp+4h] [rbp-4Ch]
float v13; // [rsp+8h] [rbp-48h]
float v15; // [rsp+18h] [rbp-38h] BYREF
float v16; // [rsp+1Ch] [rbp-34h]
float v17; // [rsp+20h] [rbp-30h]
int v18[11]; // [rsp+24h] [rbp-2Ch] BYREF

*(float *)v18 = *a2 - *a1;
*(float *)&v18[1] = a2[1] - a1[1];
*(float *)&v18[2] = a2[2] - a1[2];
v7 = VectorLength(v18);
result = 1LL;
if ( a5 <= v7 )
{
v15 = *a3 - *a2;
v16 = a3[1] - a2[1];
v17 = a3[2] - a2[2];
v12 = VectorLength(&v15);
NormaliseVector(&v15);
v13 = DotProduct(v18, &v15);
v9 = (float)((float)(a5 * a5) - DotProduct(v18, v18)) - (float)(v13 * v13);
result = 0LL;
if ( v9 >= 0.0 )
{
v10 = fsqrt(v9);
v11 = fminf(v10 - v13, COERCE_FLOAT(LODWORD(v10) ^ LC5) - v13);
if ( v11 < 0.0 )
{
result = 2LL;
}
else
{
result = 3LL;
if ( v11 <= v12 )
{
*a4 = (float)(v11 * v15) + *a2;
a4[1] = (float)(v11 * v16) + a2[1];
a4[2] = (float)(v11 * v17) + a2[2];
result = 4LL;
}
}
}
}
return result;
}

original_code:
int16_t RaytoSphere3( VECTOR * SphereCenter, float Radius, VECTOR * RayStart,
        VECTOR * RayEnd, VECTOR * IntPoint )
{
 VECTOR EO;
 float v, disc, d, d0, d1;
 VECTOR RayDir;
 float RayLength;
 EO.x = ( RayStart->x - SphereCenter->x );
 EO.y = ( RayStart->y - SphereCenter->y );
 EO.z = ( RayStart->z - SphereCenter->z );
 if( VectorLength( &EO ) < Radius ) return( 1 );
 RayDir.x = ( RayEnd->x - RayStart->x );
 RayDir.y = ( RayEnd->y - RayStart->y );
 RayDir.z = ( RayEnd->z - RayStart->z );
 RayLength = VectorLength( &RayDir );
 NormaliseVector( &RayDir );
 v = DotProduct( &EO, &RayDir );
 disc = ( ( Radius * Radius ) - DotProduct( &EO, &EO ) - ( v * v ) );
 if ( disc < 0.0F ) return( 0 );
 d = (float) sqrt( disc );
 d0 = d - v;
 d1 = ( -d ) - v;
 d = (d0 < d1) ? d0 : d1;
 if( d < 0.0F ) return( 2 );
 if( d > RayLength ) return( 3 );
 IntPoint->x = RayStart->x + ( RayDir.x * d );
 IntPoint->y = RayStart->y + ( RayDir.y * d );
 IntPoint->z = RayStart->z + ( RayDir.z * d );
 return( 4 );
}

canonical_original_code:
short RaytoSphere3(struct VECTOR *SphereCenter, float Radius, struct VECTOR *RayStart, struct VECTOR *RayEnd, struct VECTOR *IntPoint)
{
 struct VECTOR EO;
 float v; float disc; float d; float d0; float d1;
 struct VECTOR RayDir;
 float RayLength;
 EO.x = ( RayStart->x - SphereCenter->x );
 EO.y = ( RayStart->y - SphereCenter->y );
 EO.z = ( RayStart->z - SphereCenter->z );
 if( VectorLength( &EO ) < Radius ) return( 1 );
 RayDir.x = ( RayEnd->x - RayStart->x );
 RayDir.y = ( RayEnd->y - RayStart->y );
 RayDir.z = ( RayEnd->z - RayStart->z );
 RayLength = VectorLength( &RayDir );
 NormaliseVector( &RayDir );
 v = DotProduct( &EO, &RayDir );
 disc = ( ( Radius * Radius ) - DotProduct( &EO, &EO ) - ( v * v ) );
 if ( disc < 0.0F ) return( 0 );
 d = (float) sqrt( disc );
 d0 = d - v;
 d1 = ( -d ) - v;
 d = (d0 < d1) ? d0 : d1;
 if( d < 0.0F ) return( 2 );
 if( d > RayLength ) return( 3 );
 IntPoint->x = RayStart->x + ( RayDir.x * d );
 IntPoint->y = RayStart->y + ( RayDir.y * d );
 IntPoint->z = RayStart->z + ( RayDir.z * d );
 return( 4 );
}

variable_types: struct VECTOR { float x; float y; float z; } *

variable_types: Radius float

variable_types:
RayStart
struct VECTOR *

variable_types:
RayEnd
struct VECTOR *

variable_types:
IntPoint
struct VECTOR *

variable_types: RayLength float

return_type: short


RaytoSphereShort

decompiled_code:
bool __fastcall RaytoSphereShort(float *a1, float *a2, float *a3, float a4, float a5)
{
float v5; // xmm1_4
float v6; // xmm4_4
float v7; // xmm3_4
float v8; // xmm2_4
float v9; // xmm0_4
bool result; // al
float v11; // xmm0_4
float v12; // xmm0_4
float v13; // xmm1_4
float v14; // [rsp+8h] [rbp-8h]

v5 = *a2 - *a1;
v6 = a2[1] - a1[1];
v7 = a2[2] - a1[2];
v8 = (float)((float)(v5 * v5) + (float)(v6 * v6)) + (float)(v7 * v7);
v9 = a4 * a4;
result = 1;
if ( v9 < v8 )
{
v14 = (float)((float)(v5 * *a3) + (float)(v6 * a3[1])) + (float)(v7 * a3[2]);
v11 = v9 - (float)(v8 - (float)(v14 * v14));
result = 0;
if ( v11 >= 0.0 )
{
v12 = fsqrt(v11);
v13 = fminf(v12 - v14, COERCE_FLOAT(LODWORD(v12) ^ LC5) - v14);
result = 0;
if ( v13 >= 0.0 )
result = v13 <= a5;
}
}
return result;
}

canonical_decompiled_code:
bool __fastcall func8(float *a1, float *a2, float *a3, float a4, float a5)
{
float v5; // xmm1_4
float v6; // xmm4_4
float v7; // xmm3_4
float v8; // xmm2_4
float v9; // xmm0_4
bool result; // al
float v11; // xmm0_4
float v12; // xmm0_4
float v13; // xmm1_4
float v14; // [rsp+8h] [rbp-8h]

v5 = *a2 - *a1;
v6 = a2[1] - a1[1];
v7 = a2[2] - a1[2];
v8 = (float)((float)(v5 * v5) + (float)(v6 * v6)) + (float)(v7 * v7);
v9 = a4 * a4;
result = 1;
if ( v9 < v8 )
{
v14 = (float)((float)(v5 * *a3) + (float)(v6 * a3[1])) + (float)(v7 * a3[2]);
v11 = v9 - (float)(v8 - (float)(v14 * v14));
result = 0;
if ( v11 >= 0.0 )
{
v12 = fsqrt(v11);
v13 = fminf(v12 - v14, COERCE_FLOAT(LODWORD(v12) ^ LC5) - v14);
result = 0;
if ( v13 >= 0.0 )
result = v13 <= a5;
}
}
return result;
}

original_code:
_Bool RaytoSphereShort( VECTOR * sorigin, float radius, VECTOR * rorigin, VECTOR * rdir, float rlength )
{
 float v;
 float disc;
 float d, d0, d1;
 float EO_LS;
 VECTOR EO;
 EO.x = ( rorigin->x - sorigin->x );
 EO.y = ( rorigin->y - sorigin->y );
 EO.z = ( rorigin->z - sorigin->z );
 EO_LS = ( EO.x * EO.x ) + ( EO.y * EO.y ) + ( EO.z * EO.z );
 if( EO_LS <= ( radius * radius ) ) return( 1 );
 v = ( ( EO.x * rdir->x ) + ( EO.y * rdir->y ) + ( EO.z * rdir->z ) );
 disc = ( ( radius * radius ) - ( EO_LS - ( v * v ) ) );
 if( disc < 0.0F ) return( 0 );
 d = (float) sqrt( disc );
 d0 = d - v;
 d1 = ( -d ) - v;
 d = (d0 < d1) ? d0 : d1;
 if ( d < 0.0F ) return( 0 );
 if( d > rlength ) return( 0 );
 return 1;
}

canonical_original_code:
_Bool RaytoSphereShort(struct VECTOR *sorigin, float radius, struct VECTOR *rorigin, struct VECTOR *rdir, float rlength)
{
 float v;
 float disc;
 float d; float d0; float d1;
 float EO_LS;
 struct VECTOR EO;
 EO.x = ( rorigin->x - sorigin->x );
 EO.y = ( rorigin->y - sorigin->y );
 EO.z = ( rorigin->z - sorigin->z );
 EO_LS = ( EO.x * EO.x ) + ( EO.y * EO.y ) + ( EO.z * EO.z );
 if( EO_LS <= ( radius * radius ) ) return( 1 );
 v = ( ( EO.x * rdir->x ) + ( EO.y * rdir->y ) + ( EO.z * rdir->z ) );
 disc = ( ( radius * radius ) - ( EO_LS - ( v * v ) ) );
 if( disc < 0.0F ) return( 0 );
 d = (float) sqrt( disc );
 d0 = d - v;
 d1 = ( -d ) - v;
 d = (d0 < d1) ? d0 : d1;
 if ( d < 0.0F ) return( 0 );
 if( d > rlength ) return( 0 );
 return 1;
}

variable_types: radius float

variable_types: rlength float


decompiled_code:
__int64 __fastcall find_globerr(const char *a1, int a2)
{
char *v2; // rax

v2 = strerror(a2);
DebugPrintf("file: glob error while searching for \"%s\": %s\n", a1, v2);
DebugPrintf("Trying to continue anyway...\n");
return 0LL;
}

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

v2 = strerror(a2);
DebugPrintf("file: glob error while searching for \"%s\": %s\n", a1, v2);
DebugPrintf("Trying to continue anyway...\n");
return 0LL;
}

original_code:
static int find_globerr( const char *epath, int eerrno )
{
 DebugPrintf("file: glob error while searching for \"%s\": %s\n", epath, strerror(eerrno));
 DebugPrintf("Trying to continue anyway...\n");
 return 0;
}

canonical_original_code:
static int find_globerr(char *epath, int eerrno)
{
 DebugPrintf("file: glob error while searching for \"%s\": %s\n", epath, strerror(eerrno));
 DebugPrintf("Trying to continue anyway...\n");
 return 0;
}

variable_types:
epath
char *

variable_types: eerrno int


decompiled_code:
const char *__fastcall find_strip_path(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

original_code:
static char *find_strip_path( char *path )
{
 char *c = strrchr(path, '/');
 if( c )
  return &c[1];
 else
  return path;
}

canonical_original_code:
static char *find_strip_path(char *path)
{
 char *c = strrchr(path, '/');
 if( c )
  return &c[1];
 else
  return path;
}

variable_types:
path
char *

variable_types:
c
char *

return_type: char *


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

v0 = (const char *)convert_path();
if ( stat(v0, &s_2) || (result = 1LL, (byte_819 & 0x40) == 0) )
{
DebugPrintf("folder '%s' is not a directory\n", v0);
result = 0LL;
}
return result;
}

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

v0 = (const char *)convert_path();
if ( stat(v0, &s_2) || (result = 1LL, (byte_819 & 0x40) == 0) )
{
DebugPrintf("folder '%s' is not a directory\n", v0);
result = 0LL;
}
return result;
}

original_code:
_Bool is_folder( char* str )
{
 static struct stat s;
 char * path = convert_path(str);
 if ( stat( path, &s ) == 0 && s.st_mode & 0040000 )
  return 1;
 DebugPrintf("folder '%s' is not a directory\n",path);
 return 0;
}

canonical_original_code:
_Bool is_folder(char *str)
{
 static struct stat s;
 char *path = convert_path(str);
 if ( stat( path, &s ) == 0 && s.st_mode & 0040000 )
  return 1;
 DebugPrintf("folder '%s' is not a directory\n",path);
 return 0;
}

variable_types:
str
char *

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

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


decompiled_code:
__int64 folder_exists(char *format, ...)
{
const char *v1; // r12
unsigned int v2; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-D8h] BYREF

va_start(arg, format);
vsnprintf(pathname_1, 0xFFuLL, format, arg);
byte_7FF = 0;
v1 = (const char *)convert_path(pathname_1);
v2 = stat(v1, &s_0);
if ( v2 )
return mkdir(v1, 0x1FFu) == 0;
if ( (byte_679 & 0x40) != 0 )
return 1;
DebugPrintf("'%s' is not a folder\n", v1);
return v2;
}

canonical_decompiled_code:
__int64 func3(char *format, ...)
{
const char *v1; // r12
unsigned int v2; // ebx
gcc_va_list arg; // [rsp+8h] [rbp-D8h] BYREF

va_start(arg, format);
vsnprintf(pathname_1, 0xFFuLL, format, arg);
byte_7FF = 0;
v1 = (const char *)convert_path(pathname_1);
v2 = stat(v1, &s_0);
if ( v2 )
return mkdir(v1, 0x1FFu) == 0;
if ( (byte_679 & 0x40) != 0 )
return 1;
DebugPrintf("'%s' is not a folder\n", v1);
return v2;
}

original_code:
int folder_exists( char *pathspec, ... )
{
 char * path;
 static char pathname[ 256 ];
 static struct stat s;
 va_list args;
 __builtin_va_start(args,pathspec);
 vsnprintf( pathname, sizeof(pathname)-1, pathspec, args );
 __builtin_va_end(args);
 pathname[sizeof(pathname)-1] = 0;
 path = convert_path(pathname);
 if ( stat( path, &s ) )
 {
  return mkdir( path, 0777 ) == 0;
 }
 else if ( s.st_mode & 0040000 )
 {
  return 1;
 }
 else
 {
  DebugPrintf("'%s' is not a folder\n",path);
  return 0;
 }
 DebugPrintf("folder '%s' does not exist\n",path);
 return 0;
}

canonical_original_code:
int folder_exists(char *pathspec, ...)
{
 char *path;
 static char pathname[256];
 static struct stat s;
 __builtin_va_list args;
 __builtin_va_start(args,pathspec);
 vsnprintf( pathname, sizeof(pathname)-1, pathspec, args );
 __builtin_va_end(args);
 pathname[sizeof(pathname)-1] = 0;
 path = convert_path(pathname);
 if ( stat( path, &s ) )
 {
  return mkdir( path, 0777 ) == 0;
 }
 else if ( s.st_mode & 0040000 )
 {
  return 1;
 }
 else
 {
  DebugPrintf("'%s' is not a folder\n",path);
  return 0;
 }
 DebugPrintf("folder '%s' does not exist\n",path);
 return 0;
}

variable_types:
pathspec
char *

variable_types:
pathname
char [256]

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


decompiled_code:
__int64 __fastcall File_Exists(__int64 a1)
{
unsigned int v1; // er12
const char *v2; // rbx
int v3; // eax
const char *v4; // rdx

v2 = (const char *)convert_path(a1);
v3 = access(v2, 0);
LOBYTE(v1) = v3 == 0;
v4 = "exits";
if ( v3 )
v4 = "missing";
DebugPrintf("file: check exists '%s' = %s\n", v2, v4);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
unsigned int v1; // er12
const char *v2; // rbx
int v3; // eax
const char *v4; // rdx

v2 = (const char *)convert_path(a1);
v3 = access(v2, 0);
LOBYTE(v1) = v3 == 0;
v4 = "exits";
if ( v3 )
v4 = "missing";
DebugPrintf("file: check exists '%s' = %s\n", v2, v4);
return v1;
}

original_code:
_Bool File_Exists( char * str )
{
 char * path = convert_path(str);
 int rval = (access( path, 0 ) == 0);
 DebugPrintf("file: check exists '%s' = %s\n",
  path, (rval)?"exits":"missing");
 return rval;
}

canonical_original_code:
_Bool File_Exists(char *str)
{
 char *path = convert_path(str);
 int rval = (access( path, 0 ) == 0);
 DebugPrintf("file: check exists '%s' = %s\n",
  path, (rval)?"exits":"missing");
 return rval;
}

variable_types: rval int


decompiled_code:
__off_t __fastcall Get_File_Size(__int64 a1)
{
const char *v1; // rbx
struct stat v3; // [rsp+0h] [rbp-A0h] BYREF

v1 = (const char *)convert_path(a1);
if ( !stat(v1, &v3) )
return v3.st_size;
DebugPrintf("file '%s' does not exist\n", v1);
perror("stat");
return 0LL;
}

canonical_decompiled_code:
__off_t __fastcall func7(__int64 a1)
{
const char *v1; // rbx
struct stat v3; // [rsp+0h] [rbp-A0h] BYREF

v1 = (const char *)convert_path(a1);
if ( !stat(v1, &v3) )
return v3.st_size;
DebugPrintf("file '%s' does not exist\n", v1);
perror("stat");
return 0LL;
}

original_code:
long Get_File_Size( char * Filename )
{
 struct stat st;
 char * path = convert_path(Filename);
  if ( !stat( path, &st ) )
 {
  return (long) st.st_size;
  }
  else
 {
  DebugPrintf("file '%s' does not exist\n",path);
  perror("stat");
  return 0;
 }
}

canonical_original_code:
long Get_File_Size(char *Filename)
{
 struct stat st;
 char *path = convert_path(Filename);
  if ( !stat( path, &st ) )
 {
  return (long) st.st_size;
  }
  else
 {
  DebugPrintf("file '%s' does not exist\n",path);
  perror("stat");
  return 0;
 }
}

variable_types:
Filename
char *

return_type: long


decompiled_code:
__int64 __fastcall file_time(const char *a1, _DWORD *a2)
{
const char *v2; // rax
__int64 result; // rax
struct tm tp; // [rsp+0h] [rbp-E0h] BYREF
struct stat v5; // [rsp+40h] [rbp-A0h] BYREF

v2 = (const char *)convert_path(a1);
if ( stat(v2, &v5) )
{
DebugPrintf("failed to retrieve file '%s' modification time\n", a1);
perror("stat");
result = 0LL;
}
else
{
gmtime_r(&v5.st_mtim.tv_sec, &tp);
*a2 = tp.tm_year + 1900;
a2[1] = tp.tm_mon + 1;
a2[2] = tp.tm_mday;
a2[3] = tp.tm_hour;
a2[4] = tp.tm_min;
a2[5] = tp.tm_sec;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1, _DWORD *a2)
{
const char *v2; // rax
__int64 result; // rax
struct tm tp; // [rsp+0h] [rbp-E0h] BYREF
struct stat v5; // [rsp+40h] [rbp-A0h] BYREF

v2 = (const char *)convert_path(a1);
if ( stat(v2, &v5) )
{
DebugPrintf("failed to retrieve file '%s' modification time\n", a1);
perror("stat");
result = 0LL;
}
else
{
gmtime_r(&v5.st_mtim.tv_sec, &tp);
*a2 = tp.tm_year + 1900;
a2[1] = tp.tm_mon + 1;
a2[2] = tp.tm_mday;
a2[3] = tp.tm_hour;
a2[4] = tp.tm_min;
a2[5] = tp.tm_sec;
result = 1LL;
}
return result;
}

original_code:
_Bool file_time( const char * path, struct filetime *t )
{
 struct stat st;
 struct tm lt;
 if ( stat( convert_path(path), &st ) != 0 )
 {
  DebugPrintf("failed to retrieve file '%s' modification time\n", path);
  perror("stat");
  return 0;
 }
 gmtime_r( &st.st_mtim.tv_sec, &lt );
 t->year = lt.tm_year + 1900;
 t->month = lt.tm_mon + 1;
 t->day = lt.tm_mday;
 t->hour = lt.tm_hour;
 t->minute = lt.tm_min;
 t->second = lt.tm_sec;
 return 1;
}

canonical_original_code:
_Bool file_time(char *path, struct filetime *t)
{
 struct stat st;
 struct tm lt;
 if ( stat( convert_path(path), &st ) != 0 )
 {
  DebugPrintf("failed to retrieve file '%s' modification time\n", path);
  perror("stat");
  return 0;
 }
 gmtime_r( &st.st_mtim.tv_sec, &lt );
 t->year = lt.tm_year + 1900;
 t->month = lt.tm_mon + 1;
 t->day = lt.tm_mday;
 t->hour = lt.tm_hour;
 t->minute = lt.tm_min;
 t->second = lt.tm_sec;
 return 1;
}

variable_types: struct filetime { int year; int month; int day; int hour; int minute; int second; } *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; }


decompiled_code:
bool __fastcall delete_file(__int64 a1)
{
const char *v1; // rax

v1 = (const char *)convert_path(a1);
return unlink(v1) == 0;
}

canonical_decompiled_code:
bool __fastcall func10(__int64 a1)
{
const char *v1; // rax

v1 = (const char *)convert_path(a1);
return unlink(v1) == 0;
}

original_code:
_Bool delete_file( char * str )
{
 char * path = convert_path(str);
 return (unlink( path )==0);
}

canonical_original_code:
_Bool delete_file(char *str)
{
 char *path = convert_path(str);
 return (unlink( path )==0);
}


decompiled_code:
const char *__fastcall find_file(__int64 a1)
{
const char *v1; // rbx
int v2; // eax
const char *result; // rax
int v4; // eax

v1 = (const char *)convert_path(a1);
DebugPrintf("file: find_file called with %s\n", v1);
if ( glob_pos >= 0 )
globfree(&glob_handle);
v2 = glob(v1, 0, (int (*)(const char *, int))find_globerr, &glob_handle);
if ( v2 == 2 )
{
DebugPrintf("file: find_file: read error!\n");
result = 0LL;
}
else
{
if ( v2 > 2 )
{
if ( v2 == 3 )
{
DebugPrintf("file: find_file: no match\n");
return 0LL;
}
}
else
{
if ( !v2 )
{
glob_pos = 0;
DebugPrintf("file: found file \"%s\" (1 of %d)\n", *(const char **)glob_handle.gl_pathv, glob_handle.gl_pathc);
v4 = glob_pos++;
return find_strip_path(glob_handle.gl_pathv[v4]);
}
if ( v2 == 1 )
{
DebugPrintf("file: find_file: ran out of memory!\n");
return 0LL;
}
}
DebugPrintf("file: find_file: unknown return value from glob()\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func11(__int64 a1)
{
const char *v1; // rbx
int v2; // eax
const char *result; // rax
int v4; // eax

v1 = (const char *)convert_path(a1);
DebugPrintf("file: find_file called with %s\n", v1);
if ( glob_pos >= 0 )
globfree(&glob_handle);
v2 = glob(v1, 0, (int (*)(const char *, int))find_globerr, &glob_handle);
if ( v2 == 2 )
{
DebugPrintf("file: find_file: read error!\n");
result = 0LL;
}
else
{
if ( v2 > 2 )
{
if ( v2 == 3 )
{
DebugPrintf("file: find_file: no match\n");
return 0LL;
}
}
else
{
if ( !v2 )
{
glob_pos = 0;
DebugPrintf("file: found file \"%s\" (1 of %d)\n", *(const char **)glob_handle.gl_pathv, glob_handle.gl_pathc);
v4 = glob_pos++;
return func1(glob_handle.gl_pathv[v4]);
}
if ( v2 == 1 )
{
DebugPrintf("file: find_file: ran out of memory!\n");
return 0LL;
}
}
DebugPrintf("file: find_file: unknown return value from glob()\n");
result = 0LL;
}
return result;
}

original_code:
char* find_file( char * str )
{
 char * path = convert_path(str);
 DebugPrintf("file: find_file called with %s\n",path);
 if (glob_pos >= 0)
  globfree(&glob_handle);
 switch( glob(path, 0, find_globerr, &glob_handle) )
 {
  case 0:
   glob_pos = 0;
   DebugPrintf("file: found file \"%s\" (1 of %d)\n", glob_handle.gl_pathv[0], glob_handle.gl_pathc);
   return find_strip_path(glob_handle.gl_pathv[glob_pos++]);
   break;
  case 1:
   DebugPrintf("file: find_file: ran out of memory!\n");
   break;
  case 2:
   DebugPrintf("file: find_file: read error!\n");
   break;
  case 3:
   DebugPrintf("file: find_file: no match\n");
   break;
  default:
   DebugPrintf("file: find_file: unknown return value from glob()\n");
   break;
 }
 return ((void *)0);
}

canonical_original_code:
char *find_file(char *str)
{
 char *path = convert_path(str);
 DebugPrintf("file: find_file called with %s\n",path);
 if (glob_pos >= 0)
  globfree(&glob_handle);
 switch( glob(path, 0, find_globerr, &glob_handle) )
 {
  case 0:
   glob_pos = 0;
   DebugPrintf("file: found file \"%s\" (1 of %d)\n", glob_handle.gl_pathv[0], glob_handle.gl_pathc);
   return find_strip_path(glob_handle.gl_pathv[glob_pos++]);
   break;
  case 1:
   DebugPrintf("file: find_file: ran out of memory!\n");
   break;
  case 2:
   DebugPrintf("file: find_file: read error!\n");
   break;
  case 3:
   DebugPrintf("file: find_file: no match\n");
   break;
  default:
   DebugPrintf("file: find_file: unknown return value from glob()\n");
   break;
 }
 return ((void *)0);
}


decompiled_code:
const char *find_next_file()
{
const char *v0; // rdx
int v1; // eax

if ( glob_pos < 0 )
return 0LL;
v0 = 0LL;
if ( glob_pos < SLODWORD(glob_handle.gl_pathc) )
{
DebugPrintf(
"file: found file \"%s\" (%d of %d)\n",
glob_handle.gl_pathv[glob_pos],
(unsigned int)(glob_pos + 1),
glob_handle.gl_pathc);
v1 = glob_pos++;
v0 = find_strip_path(glob_handle.gl_pathv[v1]);
}
return v0;
}

canonical_decompiled_code:
const char *func12()
{
const char *v0; // rdx
int v1; // eax

if ( glob_pos < 0 )
return 0LL;
v0 = 0LL;
if ( glob_pos < SLODWORD(glob_handle.gl_pathc) )
{
DebugPrintf(
"file: found file \"%s\" (%d of %d)\n",
glob_handle.gl_pathv[glob_pos],
(unsigned int)(glob_pos + 1),
glob_handle.gl_pathc);
v1 = glob_pos++;
v0 = func1(glob_handle.gl_pathv[v1]);
}
return v0;
}

original_code:
char* find_next_file( void )
{
 if (glob_pos < 0 || glob_pos >= (int)glob_handle.gl_pathc)
  return ((void *)0);
 DebugPrintf("file: found file \"%s\" (%d of %d)\n", glob_handle.gl_pathv[glob_pos], glob_pos+1, glob_handle.gl_pathc);
 return find_strip_path(glob_handle.gl_pathv[glob_pos++]);
}

canonical_original_code:
char *find_next_file()
{
 if (glob_pos < 0 || glob_pos >= (int)glob_handle.gl_pathc)
  return ((void *)0);
 DebugPrintf("file: found file \"%s\" (%d of %d)\n", glob_handle.gl_pathv[glob_pos], glob_pos+1, glob_handle.gl_pathc);
 return find_strip_path(glob_handle.gl_pathv[glob_pos++]);
}


decompiled_code:
void find_close()
{
globfree(&glob_handle);
glob_pos = -1;
}

canonical_decompiled_code:
void func13()
{
globfree(&glob_handle);
glob_pos = -1;
}

original_code:
void find_close( void )
{
 globfree(&glob_handle);
 glob_pos = -1;
}


decompiled_code:
ssize_t __fastcall Write_File(__int64 a1, const void *a2, size_t a3)
{
const char *v4; // rax
int v5; // eax
int v6; // ebx
ssize_t v7; // r14

v4 = (const char *)convert_path(a1);
v5 = open(v4, 578, 384LL);
v6 = v5;
v7 = 0LL;
if ( v5 != -1 )
{
v7 = write(v5, a2, a3);
close(v6);
}
return v7;
}

canonical_decompiled_code:
ssize_t __fastcall func5(__int64 a1, const void *a2, size_t a3)
{
const char *v4; // rax
int v5; // eax
int v6; // ebx
ssize_t v7; // r14

v4 = (const char *)convert_path(a1);
v5 = open(v4, 578, 384LL);
v6 = v5;
v7 = 0LL;
if ( v5 != -1 )
{
v7 = write(v5, a2, a3);
close(v6);
}
return v7;
}

original_code:
long Write_File( char * str, char * File_Buffer, long Write_Size )
{
 int Handle = -1;
 long Bytes_Written = 0;
 char * path = convert_path(str);
 Handle = open( path, 0100 | 01000 | 0 | 02 ,
         0400 | 0200 );
 if( Handle != -1 ) {
  Bytes_Written = write( Handle, File_Buffer, Write_Size );
  close( Handle );
 }
 return ( Bytes_Written );
}

canonical_original_code:
long Write_File(char *str, char *File_Buffer, long Write_Size)
{
 int Handle = -1;
 long Bytes_Written = 0;
 char *path = convert_path(str);
 Handle = open( path, 0100 | 01000 | 0 | 02 ,
         0400 | 0200 );
 if( Handle != -1 ) {
  Bytes_Written = write( Handle, File_Buffer, Write_Size );
  close( Handle );
 }
 return ( Bytes_Written );
}

variable_types: Handle int


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

result = File_Exists(a1);
if ( !(_BYTE)result )
result = Write_File(a1, &unk_A92, 0LL);
return result;
}

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

result = func4(a1);
if ( !(_BYTE)result )
result = func5(a1, &unk_A92, 0LL);
return result;
}

original_code:
void touch_file( char* path )
{
 if(!File_Exists(path))
  Write_File(path, "", 0);
}

canonical_original_code:
void touch_file(char *path)
{
 if(!File_Exists(path))
  Write_File(path, "", 0);
}


decompiled_code:
ssize_t __fastcall Read_File(__int64 a1, void *a2, __off_t a3)
{
__int64 v4; // rax
const char *v5; // r12
int v6; // eax
int v7; // er12
ssize_t v8; // r13

v4 = convert_path(a1);
v5 = (const char *)v4;
if ( !a3 )
a3 = Get_File_Size(v4);
v6 = open(v5, 0);
v7 = v6;
v8 = 0LL;
if ( v6 != -1 )
{
v8 = read(v6, a2, a3);
if ( v8 == -1 )
v8 = 0LL;
close(v7);
}
return v8;
}

canonical_decompiled_code:
ssize_t __fastcall func9(__int64 a1, void *a2, __off_t a3)
{
__int64 v4; // rax
const char *v5; // r12
int v6; // eax
int v7; // er12
ssize_t v8; // r13

v4 = convert_path(a1);
v5 = (const char *)v4;
if ( !a3 )
a3 = func7(v4);
v6 = open(v5, 0);
v7 = v6;
v8 = 0LL;
if ( v6 != -1 )
{
v8 = read(v6, a2, a3);
if ( v8 == -1 )
v8 = 0LL;
close(v7);
}
return v8;
}

original_code:
long Read_File( char * Filename, char * File_Buffer, long Read_Size )
{
 int Handle = -1;
 long Bytes_Read = 0;
 char * path = convert_path(Filename);
 if( Read_Size == 0 )
  Read_Size = Get_File_Size( path );
 Handle = open( path, 00 | 0 );
 if( Handle != -1 )
 {
  Bytes_Read = read( Handle, File_Buffer, Read_Size );
  if( Bytes_Read == -1 ) Bytes_Read = 0;
  close( Handle );
 }
 return ( Bytes_Read );
}

canonical_original_code:
long Read_File(char *Filename, char *File_Buffer, long Read_Size)
{
 int Handle = -1;
 long Bytes_Read = 0;
 char *path = convert_path(Filename);
 if( Read_Size == 0 )
  Read_Size = Get_File_Size( path );
 Handle = open( path, 00 | 0 );
 if( Handle != -1 )
 {
  Bytes_Read = read( Handle, File_Buffer, Read_Size );
  if( Bytes_Read == -1 ) Bytes_Read = 0;
  close( Handle );
 }
 return ( Bytes_Read );
}


InitMathErrors

decompiled_code:
void InitMathErrors()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void InitMathErrors(void)
{
}

canonical_original_code:
void InitMathErrors()
{
}


DebugMathErrors

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

result = fetestexcept(61);
if ( result )
{
DebugPrintf("======================\n");
DebugPrintf("Math Exception Summary\n");
DebugPrintf("======================\n");
if ( fetestexcept(4) )
DebugPrintf("FE_DIVBYZERO\n");
if ( fetestexcept(32) )
DebugPrintf("FE_INEXACT\n");
if ( fetestexcept(1) )
DebugPrintf("FE_INVALID\n");
if ( fetestexcept(8) )
DebugPrintf("FE_OVERFLOW\n");
if ( fetestexcept(16) )
DebugPrintf("FE_UNDERFLOW\n");
DebugPrintf("======================\n");
feclearexcept(61);
result = 1;
}
return result;
}

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

result = fetestexcept(61);
if ( result )
{
DebugPrintf("======================\n");
DebugPrintf("Math Exception Summary\n");
DebugPrintf("======================\n");
if ( fetestexcept(4) )
DebugPrintf("FE_DIVBYZERO\n");
if ( fetestexcept(32) )
DebugPrintf("FE_INEXACT\n");
if ( fetestexcept(1) )
DebugPrintf("FE_INVALID\n");
if ( fetestexcept(8) )
DebugPrintf("FE_OVERFLOW\n");
if ( fetestexcept(16) )
DebugPrintf("FE_UNDERFLOW\n");
DebugPrintf("======================\n");
feclearexcept(61);
result = 1;
}
return result;
}

original_code:
int DebugMathErrors( void )
{
 if(!fetestexcept((0x20 | 0x04 | 0x10 | 0x08 | 0x01)))
  return 0;
 DebugPrintf( "======================\n" );
 DebugPrintf( "Math Exception Summary\n" );
 DebugPrintf( "======================\n" );
 if(fetestexcept(0x04))
  DebugPrintf("FE_DIVBYZERO\n");
 if(fetestexcept(0x20))
  DebugPrintf("FE_INEXACT\n");
 if(fetestexcept(0x01))
  DebugPrintf("FE_INVALID\n");
 if(fetestexcept(0x08))
  DebugPrintf("FE_OVERFLOW\n");
 if(fetestexcept(0x10))
  DebugPrintf("FE_UNDERFLOW\n");
 DebugPrintf( "======================\n" );
 feclearexcept((0x20 | 0x04 | 0x10 | 0x08 | 0x01));
 return 1;
}

canonical_original_code:
int DebugMathErrors()
{
 if(!fetestexcept((0x20 | 0x04 | 0x10 | 0x08 | 0x01)))
  return 0;
 DebugPrintf( "======================\n" );
 DebugPrintf( "Math Exception Summary\n" );
 DebugPrintf( "======================\n" );
 if(fetestexcept(0x04))
  DebugPrintf("FE_DIVBYZERO\n");
 if(fetestexcept(0x20))
  DebugPrintf("FE_INEXACT\n");
 if(fetestexcept(0x01))
  DebugPrintf("FE_INVALID\n");
 if(fetestexcept(0x08))
  DebugPrintf("FE_OVERFLOW\n");
 if(fetestexcept(0x10))
  DebugPrintf("FE_UNDERFLOW\n");
 DebugPrintf( "======================\n" );
 feclearexcept((0x20 | 0x04 | 0x10 | 0x08 | 0x01));
 return 1;
}


repo: ForsakenX/mouse-dx-sdl-compare

decompiled_code:
__int64 __fastcall grab_mouse(int a1)
{
const char *v1; // rsi

SDL_WM_GrabInput(a1 == 1);
v1 = "grabbed";
if ( a1 != 1 )
v1 = "free";
return p("input state: %s\n", v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
const char *v1; // rsi

SDL_WM_GrabInput(a1 == 1);
v1 = "grabbed";
if ( a1 != 1 )
v1 = "free";
return p("input state: %s\n", v1);
}

original_code:
void grab_mouse( BOOL grab )
{
 SDL_WM_GrabInput( grab==1 ? SDL_GRAB_ON : SDL_GRAB_OFF );
 p("input state: %s\n",(grab==1?"grabbed":"free"));
}

canonical_original_code:
void grab_mouse(int grab)
{
 SDL_WM_GrabInput( grab==1 ? SDL_GRAB_ON : SDL_GRAB_OFF );
 p("input state: %s\n",(grab==1?"grabbed":"free"));
}

variable_types: grab int


decompiled_code:
__int64 sdl_timer_init()
{
return timer_clear(&sdl_mouse_timer);
}

canonical_decompiled_code:
__int64 func1()
{
return timer_clear(&sdl_mouse_timer);
}

original_code:
void sdl_timer_init( void )
{
 timer_clear( &sdl_mouse_timer );
}

canonical_original_code:
void sdl_timer_init()
{
 timer_clear( &sdl_mouse_timer );
}


strtoupper

decompiled_code:
void __fastcall strtoupper(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

canonical_decompiled_code:
void __fastcall func0(char *a1)
{
char v1; // bl
char *v2; // rbp
const __int32_t **v3; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1;
v3 = _ctype_toupper_loc();
do
{
*v2++ = (*v3)[v1];
v1 = *v2;
}
while ( *v2 );
}
}

original_code:
void strtoupper(char *str)
{
 while (*str)
 {
  *str = (char) toupper(*str);
  str++;
 }
}


p

decompiled_code:
int p(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-40D0h] BYREF
char s[16384]; // [rsp+20h] [rbp-40B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x4000uLL, format, arg);
fputs(s, stderr);
return l(s);
}

canonical_decompiled_code:
int func2(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-40D0h] BYREF
char s[16384]; // [rsp+20h] [rbp-40B8h] BYREF

va_start(arg, format);
vsnprintf(s, 0x4000uLL, format, arg);
fputs(s, stderr);
return func1(s);
}

original_code:
void p( const char * format, ... )
{
 char buf[0x4000];
 va_list args;
 __builtin_va_start(args,format);
 vsnprintf( buf, 0x4000, format, args );
 __builtin_va_end(args);
 fputs( buf, stderr );
 l( buf );
}

canonical_original_code:
void p(char *format, ...)
{
 char buf[16384];
 __builtin_va_list args;
 __builtin_va_start(args,format);
 vsnprintf( buf, 0x4000, format, args );
 __builtin_va_end(args);
 fputs( buf, stderr );
 l( buf );
}

variable_types:
format
char *

variable_types:
buf
char [16384]


decompiled_code:
__int64 sdl_print_info()
{
unsigned __int8 *v0; // rax
__int64 v1; // rdx
__int64 result; // rax
const char *v3; // rax

p("SDL compile-time version: %u.%u.%u\n", 1LL, 2LL, 15LL);
v0 = (unsigned __int8 *)SDL_Linked_Version();
p("SDL runtime version: %u.%u.%u\n", *v0, v0[1], v0[2]);
if ( (int)SDL_Init(32LL) < 0 || (v1 = SDL_GetVideoInfo(), result = 1LL, !v1) )
{
v3 = (const char *)SDL_GetError();
p("Failed to initialize sdl: %s\n", v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned __int8 *v0; // rax
__int64 v1; // rdx
__int64 result; // rax
const char *v3; // rax

func2("SDL compile-time version: %u.%u.%u\n", 1LL, 2LL, 15LL);
v0 = (unsigned __int8 *)SDL_Linked_Version();
func2("SDL runtime version: %u.%u.%u\n", *v0, v0[1], v0[2]);
if ( (int)SDL_Init(32LL) < 0 || (v1 = SDL_GetVideoInfo(), result = 1LL, !v1) )
{
v3 = (const char *)SDL_GetError();
func2("Failed to initialize sdl: %s\n", v3);
result = 0LL;
}
return result;
}

original_code:
BOOL sdl_print_info( void )
{
 SDL_version ver;
 { (&ver)->major = 1; (&ver)->minor = 2; (&ver)->patch = 15; };
 p("SDL compile-time version: %u.%u.%u\n", ver.major, ver.minor, ver.patch);
 ver = *SDL_Linked_Version();
 p("SDL runtime version: %u.%u.%u\n", ver.major, ver.minor, ver.patch);
 if( SDL_Init( 0x00000020 ) < 0 || !SDL_GetVideoInfo() )
 {
  p("Failed to initialize sdl: %s\n",SDL_GetError());
  return (!(1==1));
 }
 return (1==1);
}

canonical_original_code:
int sdl_print_info()
{
 struct SDL_version ver;
 { (&ver)->major = 1; (&ver)->minor = 2; (&ver)->patch = 15; };
 p("SDL compile-time version: %u.%u.%u\n", ver.major, ver.minor, ver.patch);
 ver = *SDL_Linked_Version();
 p("SDL runtime version: %u.%u.%u\n", ver.major, ver.minor, ver.patch);
 if( SDL_Init( 0x00000020 ) < 0 || !SDL_GetVideoInfo() )
 {
  p("Failed to initialize sdl: %s\n",SDL_GetError());
  return (!(1==1));
 }
 return (1==1);
}

variable_types: struct SDL_version { unsigned char major; unsigned char minor; unsigned char patch; }


decompiled_code:
__int64 __fastcall enumerate_video_mode(unsigned int a1, _DWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = SDL_ListModes(0LL, a1);
if ( v2 )
{
if ( v2 == -1 )
{
*a2 = 640;
a2[1] = 480;
}
else
{
*a2 = *(unsigned __int16 *)(*(_QWORD *)v2 + 4LL);
a2[1] = *(unsigned __int16 *)(*(_QWORD *)v2 + 6LL);
}
result = 1LL;
}
else
{
p("No video modes available for given format!\n");
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, _DWORD *a2)
{
__int64 v2; // rax
__int64 result; // rax

v2 = SDL_ListModes(0LL, a1);
if ( v2 )
{
if ( v2 == -1 )
{
*a2 = 640;
a2[1] = 480;
}
else
{
*a2 = *(unsigned __int16 *)(*(_QWORD *)v2 + 4LL);
a2[1] = *(unsigned __int16 *)(*(_QWORD *)v2 + 6LL);
}
result = 1LL;
}
else
{
func2("No video modes available for given format!\n");
result = 0LL;
}
return result;
}

original_code:
BOOL enumerate_video_mode( Uint32 flags, video_mode_t * mode )
{
 SDL_Rect** modes = SDL_ListModes(((void *)0), flags);
 if (modes == (SDL_Rect**)0)
 {
  p("No video modes available for given format!\n");
  return (!(1==1));
 }
 if (modes != (SDL_Rect**)-1)
 {
  mode->w = modes[0]->w;
  mode->h = modes[0]->h;
 }
 else
 {
  mode->w = 640;
  mode->h = 480;
 }
 return (1==1);
}

canonical_original_code:
int enumerate_video_mode(unsigned int flags, struct video_mode_t *mode)
{
 struct SDL_Rect **modes = SDL_ListModes(((void *)0), flags);
 if (modes == (struct SDL_Rect **)0)
 {
  p("No video modes available for given format!\n");
  return (!(1==1));
 }
 if (modes != (struct SDL_Rect **)-1)
 {
  mode->w = modes[0]->w;
  mode->h = modes[0]->h;
 }
 else
 {
  mode->w = 640;
  mode->h = 480;
 }
 return (1==1);
}

variable_types:
flags
unsigned int

variable_types:
mode
struct video_mode_t { int w; int h; } *

variable_types: struct SDL_Rect { short x; unsigned short w; } **


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)sdl_init(argc, argv, envp) )
{
while ( (unsigned int)sdl_handle_events() )
;
SDL_Quit();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func5(argc, argv, envp) )
{
while ( (unsigned int)sdl_handle_events() )
;
SDL_Quit();
}
return 0;
}

original_code:
int main( int argc, char* argv[] )
{
 if(!sdl_init())
  return (!(1==1));
 while(1)
 {
  if(!sdl_handle_events())
   break;
 }
 SDL_Quit();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if(!sdl_init())
  return (!(1==1));
 while(1)
 {
  if(!sdl_handle_events())
   break;
 }
 SDL_Quit();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall timer_debug(const char *a1, float *a2)
{
return p("%s: seconds = %5f, best = %5f, worst = %5f\n", a1, a2[3], a2[1], a2[2]);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, float *a2)
{
return p("%s: seconds = %5f, best = %5f, worst = %5f\n", a1, a2[3], a2[1], a2[2]);
}

original_code:
void timer_debug( char* name, px_timer_t* stats )
{
  p("%s: seconds = %5f, best = %5f, worst = %5f\n",name,stats->seconds,stats->best,stats->worst);
}

canonical_original_code:
void timer_debug(char *name, struct timer *stats)
{
  p("%s: seconds = %5f, best = %5f, worst = %5f\n",name,stats->seconds,stats->best,stats->worst);
}

variable_types:
name
char *

variable_types: struct timer { unsigned int last; float best; float worst; float seconds; } *


original_code:
float timer_run( px_timer_t* stats )
{
  Uint32 time_now;
  Uint32 time_diff;
  if(!stats->last)
  {
    stats->last = SDL_GetTicks();
    return 0.0F;
  }
  time_now = SDL_GetTicks();
  time_diff = time_now - stats->last;
  stats->seconds = ((float)time_diff) / 1000.0F;
  stats->last = time_now;
  if (stats->best == 0.0F || stats->seconds < stats->best)
    stats->best = stats->seconds;
  if (stats->worst == 0.0F || stats->seconds > stats->worst)
    stats->worst = stats->seconds;
  return stats->seconds;
}

canonical_original_code:
float timer_run(struct timer *stats)
{
  unsigned int time_now;
  unsigned int time_diff;
  if(!stats->last)
  {
    stats->last = SDL_GetTicks();
    return 0.0F;
  }
  time_now = SDL_GetTicks();
  time_diff = time_now - stats->last;
  stats->seconds = ((float)time_diff) / 1000.0F;
  stats->last = time_now;
  if (stats->best == 0.0F || stats->seconds < stats->best)
    stats->best = stats->seconds;
  if (stats->worst == 0.0F || stats->seconds > stats->worst)
    stats->worst = stats->seconds;
  return stats->seconds;
}

user_defined_types: struct timer { unsigned int last; float best; float worst; float seconds; }


original_code:
float timer_peek( px_timer_t* stats )
{
 float seconds;
 px_timer_t old = *stats;
 seconds = timer_run( stats );
 *stats = old;
 return seconds;
}

canonical_original_code:
float timer_peek(struct timer *stats)
{
 float seconds;
 struct timer old = *stats;
 seconds = timer_run( stats );
 *stats = old;
 return seconds;
}

variable_types: seconds float

variable_types: struct timer { unsigned int last; float best; float worst; float seconds; }


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)sub_401575(argc, argv, envp) )
{
while ( (unsigned int)sub_40124A() )
;
SDL_Quit();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func14(argc, argv, envp) )
{
while ( (unsigned int)func8() )
;
SDL_Quit();
}
return 0;
}


decompiled_code:
__int64 __fastcall compare_count(const void *a1, const void *a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rdx
__int64 result; // rax

v2 = *((_QWORD *)a1 + 2);
v3 = *((_QWORD *)a2 + 2);
result = 0xFFFFFFFFLL;
if ( v2 <= v3 )
result = v2 < v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const void *a1, const void *a2)
{
unsigned __int64 v2; // rcx
unsigned __int64 v3; // rdx
__int64 result; // rax

v2 = *((_QWORD *)a1 + 2);
v3 = *((_QWORD *)a2 + 2);
result = 0xFFFFFFFFLL;
if ( v2 <= v3 )
result = v2 < v3;
return result;
}

original_code:
static int compare_count(const void* ap, const void* bp)
{
 const struct fm* a = ap;
 const struct fm* b = bp;
 if (a->count > b->count)
  return -1;
 else if (a->count < b->count)
  return +1;
 else
  return 0;
}

canonical_original_code:
static int compare_count(void *ap, void *bp)
{
 struct fm *a = ap;
 struct fm *b = bp;
 if (a->count > b->count)
  return -1;
 else if (a->count < b->count)
  return +1;
 else
  return 0;
}

variable_types:
ap
void *

variable_types:
bp
void *

variable_types: struct fm { char *name; unsigned long long (*func)(char *, char *, int); unsigned long long count; } *


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned __int64 v3; // rbp
__int64 i; // rbx
__int64 v5; // rcx
const char *v6; // r8
__int64 v7; // rbx
__int64 v8; // rbx
__int64 j; // rbx
__int64 v11; // rbp
unsigned int v12; // [rsp+Ch] [rbp-401Ch] BYREF
char v13[8192]; // [rsp+10h] [rbp-4018h] BYREF
char s[8216]; // [rsp+2010h] [rbp-2018h] BYREF

v12 = 4;
if ( argc > 1 && (unsigned int)_isoc99_sscanf(argv[1], &unk_2CE, &v12) == 1 && (v12 & 0x80000000) != 0 )
{
fprintf(stderr, "invalid parameter for seconds: %d\n", v12);
exit(1);
}
v3 = 0LL;
for ( i = 0LL; i != 6; ++i )
{
snprintf(s, 0x2000uLL, "input/%zu/A", i);
snprintf(v13, 0x2000uLL, "input/%zu/c", i);
v5 = off_2B8(s, v13, 0LL);
if ( correct[i] == v5 )
{
++v3;
}
else
{
v6 = (const char *)&unk_2C9;
if ( !correct[i] )
v6 = (const char *)&unk_2CB;
printf("\"%s\" failed test %zu: return value %llu but the system has %s solution.\n", fm, i, v5, v6);
}
}
if ( v3 > 5 )
{
printf("\"%s\" PASSED ALL %zu TESTS.\n", fm, 6uLL);
for ( j = 0LL; j != 6; ++j )
{
printf("Counting test %zu: ", j);
fflush(stdout);
snprintf(s, 0x2000uLL, "input/%zu/A", j);
snprintf(v13, 0x2000uLL, "input/%zu/c", j);
v11 = off_2B8(s, v13, v12);
printf("%*llu\n", 20, v11);
qword_2C0 += v11;
}
}
else
{
printf("\"%s\" FAILED %zu/%zu TESTS.\n", fm, 6 - v3, 6uLL);
}
qsort(&fm, 1uLL, 0x18uLL, (__compar_fn_t)compare_count);
v7 = 44LL;
do
{
putchar(61);
--v7;
}
while ( v7 );
putchar(10);
printf("%2zu %-*s %*llu\n", 1uLL, 20, fm, 20, qword_2C0);
v8 = 44LL;
do
{
putchar(61);
--v8;
}
while ( v8 );
putchar(10);
return 0;
}

original_code:
int main(int argc, char** argv)
{
 size_t nfunc;
 size_t i;
 size_t j;
 unsigned long long result;
 char a[8192];
 char c[8192];
 size_t pass;
 size_t ntest;
 int seconds = 4;
 if (argc > 1
  && sscanf(argv[1], "%d", &seconds) == 1
  && seconds < 0) {
  fprintf(stderr, "invalid parameter for seconds: %d\n", seconds);
  exit(1);
 }
 ntest = sizeof correct/sizeof correct[0];
 nfunc = sizeof fm/sizeof fm[0];
 for (i = 0; i < nfunc; ++i) {
  pass = 0;
  for (j = 0; j < ntest; ++j) {
   snprintf(a, sizeof a, "input/%zu/A", j);
   snprintf(c, sizeof c, "input/%zu/c", j);
   result = (*fm[i].func)(a, c, 0);
   if (result == correct[j])
    pass += 1;
   else {
    printf("\"%s\" failed test %zu: "
     "return value %llu but "
     "the system has %s solution.\n",
     fm[i].name, j, result,
     correct[j] ? "a" : "no");
   }
  }
  if (pass < ntest)
   printf("\"%s\" FAILED %zu/%zu TESTS.\n", fm[i].name,
    ntest - pass, ntest);
  else {
   printf("\"%s\" PASSED ALL %zu TESTS.\n",
    fm[i].name, ntest);
   for (j = 0; j < ntest; ++j) {
    printf("Counting test %zu: ", j);
    fflush(stdout);
    snprintf(a, sizeof a, "input/%zu/A", j);
    snprintf(c, sizeof c, "input/%zu/c", j);
    result = (*fm[i].func)(a, c, seconds);
    printf("%*llu\n", (20), result);
    fm[i].count += result;
   }
  }
 }
 qsort(fm, nfunc, sizeof fm[0], compare_count);
 for (j = 0; j < ((4) + (20) + (20)); ++j)
  putchar('=');
 putchar('\n');
 for (j = 0; j < nfunc; ++j)
  printf("%2zu %-*s %*llu\n", j+1,
   (20) ,fm[j].name,
   (20) ,fm[j].count);
 for (j = 0; j < ((4) + (20) + (20)); ++j)
  putchar('=');
 putchar('\n');
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned long nfunc;
 unsigned long i;
 unsigned long j;
 unsigned long long result;
 char a[8192];
 char c[8192];
 unsigned long pass;
 unsigned long ntest;
 int seconds = 4;
 if (argc > 1
  && sscanf(argv[1], "%d", &seconds) == 1
  && seconds < 0) {
  fprintf(stderr, "invalid parameter for seconds: %d\n", seconds);
  exit(1);
 }
 ntest = sizeof correct/sizeof correct[0];
 nfunc = sizeof fm/sizeof fm[0];
 for (i = 0; i < nfunc; ++i) {
  pass = 0;
  for (j = 0; j < ntest; ++j) {
   snprintf(a, sizeof a, "input/%zu/A", j);
   snprintf(c, sizeof c, "input/%zu/c", j);
   result = (*fm[i].func)(a, c, 0);
   if (result == correct[j])
    pass += 1;
   else {
    printf("\"%s\" failed test %zu: "
     "return value %llu but "
     "the system has %s solution.\n",
     fm[i].name, j, result,
     correct[j] ? "a" : "no");
   }
  }
  if (pass < ntest)
   printf("\"%s\" FAILED %zu/%zu TESTS.\n", fm[i].name,
    ntest - pass, ntest);
  else {
   printf("\"%s\" PASSED ALL %zu TESTS.\n",
    fm[i].name, ntest);
   for (j = 0; j < ntest; ++j) {
    printf("Counting test %zu: ", j);
    fflush(stdout);
    snprintf(a, sizeof a, "input/%zu/A", j);
    snprintf(c, sizeof c, "input/%zu/c", j);
    result = (*fm[i].func)(a, c, seconds);
    printf("%*llu\n", (20), result);
    fm[i].count += result;
   }
  }
 }
 qsort(fm, nfunc, sizeof fm[0], compare_count);
 for (j = 0; j < ((4) + (20) + (20)); ++j)
  putchar('=');
 putchar('\n');
 for (j = 0; j < nfunc; ++j)
  printf("%2zu %-*s %*llu\n", j+1,
   (20) ,fm[j].name,
   (20) ,fm[j].count);
 for (j = 0; j < ((4) + (20) + (20)); ++j)
  putchar('=');
 putchar('\n');
 return 0;
}

variable_types:
argv
char **

variable_types:
nfunc
unsigned long

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
result
unsigned long long

variable_types:
pass
unsigned long

variable_types:
ntest
unsigned long

variable_types: seconds int


done

decompiled_code:
void done()
{
proceed = 0;
}

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

original_code:
static void done(int unused)
{
 proceed = 0;
 unused = unused;
}

variable_types: unused int


decompiled_code:
void __fastcall free_all(__int64 a1, void **a2, void *a3)
{
void **v4; // rbx

if ( a1 )
{
v4 = a2;
do
free(*v4++);
while ( v4 != &a2[a1] );
}
free(a2);
free(a3);
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, void **a2, void *a3)
{
void **v4; // rbx

if ( a1 )
{
v4 = a2;
do
free(*v4++);
while ( v4 != &a2[a1] );
}
free(a2);
free(a3);
}

original_code:
static void free_all(size_t rows, rational_t** a, rational_t* c) {
 size_t i;
 for(i = 0; i < rows ; i++)
  free(a[i]);
 free(a);
 free(c);
}

canonical_original_code:
static void free_all(unsigned long rows, struct rational_t **a, struct rational_t *c) {
 unsigned long i;
 for(i = 0; i < rows ; i++)
  free(a[i]);
 free(a);
 free(c);
}

variable_types:
rows
unsigned long

variable_types: struct rational_t { int num; int den; } **

variable_types:
c
struct rational_t *


original_code:
static int fm_elim(size_t rows, size_t cols, rational_t** a, rational_t* c)
{
 size_t i, j;
 rational_t **t = malloc(rows*sizeof(rational_t*));
 rational_t *q = malloc(rows*sizeof(rational_t));
 for (i = 0; i < rows; i += 1){
  t[i] = malloc(cols*sizeof(rational_t));
  q[i] = c[i];
  for(j = 0; j < cols; j += 1)
     t[i][j] = a[i][j];
 }
 rational_t ZERO;
 ZERO.num = 0;
 ZERO.den = 1;
 size_t n1 = 0;
 size_t n2 = 0;
 while(1){
  n1 = 0;
  n2 = 0;
  for(i = 0; i < rows; i += 1){
   int cmp = rat_cmp(&t[i][cols-1], &ZERO);
   if(cmp > 0)
    n1 += 1;
   else if(cmp < 0)
    n2 += 1;
  }
  n2 += n1;
  rational_t **t_sort = malloc(rows*sizeof(rational_t*));
  rational_t *q_sort = malloc(rows*sizeof(rational_t));
  size_t n1_i = 0, n2_i = n1, n3_i = n2;
  size_t cur = 0;
  while(cur != rows){
   int cmp = rat_cmp(&t[cur][cols-1], &ZERO);
   if(cmp > 0){
    q_sort[n1_i] = q[cur];
    t_sort[n1_i++] = t[cur];
   }else if(cmp < 0){
    q_sort[n2_i] = q[cur];
    t_sort[n2_i++] = t[cur];
   }else{
    q_sort[n3_i] = q[cur];
    t_sort[n3_i++] = t[cur];
   }
   cur++;
  }
  free(t);
  free(q);
  q = q_sort;
  t = t_sort;
  for(i = 0; i < n2; i += 1) {
   rational_t* div = &t[i][cols-1];
   rat_div(&q[i], div);
   for(j = 0; j < cols; j += 1) {
    rat_div(&t[i][j], div);
   }
  }
  if(cols == 1){
   rational_t tmp;
   tmp.num = 100000000;
   tmp.den = 1;
   int min = 0;
   int max = 0;
    for(i = 0; i < n1; i +=1)
     if(rat_cmp(&q[i], &tmp) < 0){
      tmp.num = q[i].num;
      tmp.den = q[i].den;
      min = i;
     }
   tmp.num = 0;
   tmp.den = 1;
   for(i = n1; i < n2; i +=1)
    if(rat_cmp(&q[i], &tmp) > 0 ){
     tmp.num = q[i].num;
     tmp.den = q[i].den;
     max = i;
    }
   if (rat_cmp(&q[max], &q[min]) > 0) {
    free_all(rows, t, q);
    return 0;
   }
   for(; n2 < rows; n2 += 1)
    if(rat_cmp(&q[n2], &ZERO) < 0) {
     free_all(rows, t, q);
     return 0;
    }
   free_all(rows, t, q);
   return 1;
  }
  size_t rows_pr = rows - n2 + n1 * (n2 - n1);
  if (rows_pr == 0) {
   free_all(rows, t, q);
   return 1;
  }
  rational_t **t2 = malloc(rows_pr*sizeof(rational_t*));
  rational_t *q2 = malloc(rows_pr*sizeof(rational_t));
  for (i = 0; i < rows_pr; i += 1)
    t2[i] = malloc((cols-1)*sizeof(rational_t));
  size_t k;
  size_t q_index = 0;
  for(i = 0; i < n1; i += 1)
    for(j = n1; j < n2; j += 1){
    q2[q_index] = q[i];
    rat_sub(&q2[q_index],&q[j]);
    for(k = 0; k < cols-1; k += 1) {
     t2[q_index][k] = t[i][k];
     rat_sub(&t2[q_index][k],&t[j][k]);
    }
    q_index++;
   }
  for(i = n2; i < rows; i += 1){
    q2[q_index] = q[i];
   for(k = 0; k < cols-1; k += 1)
    t2[q_index][k] = t[i][k];
   q_index++;
  }
  free_all(rows, t, q);
  q = q2;
  t = t2;
  cols--;
  rows = rows_pr;
 }
}

canonical_original_code:
static int fm_elim(unsigned long rows, unsigned long cols, struct rational_t **a, struct rational_t *c)
{
 unsigned long i; unsigned long j;
 struct rational_t **t = malloc(rows*sizeof(rational_t*));
 struct rational_t *q = malloc(rows*sizeof(rational_t));
 for (i = 0; i < rows; i += 1){
  t[i] = malloc(cols*sizeof(rational_t));
  q[i] = c[i];
  for(j = 0; j < cols; j += 1)
     t[i][j] = a[i][j];
 }
 struct rational_t ZERO;
 ZERO.num = 0;
 ZERO.den = 1;
 unsigned long n1 = 0;
 unsigned long n2 = 0;
 while(1){
  n1 = 0;
  n2 = 0;
  for(i = 0; i < rows; i += 1){
   int cmp = rat_cmp(&t[i][cols-1], &ZERO);
   if(cmp > 0)
    n1 += 1;
   else if(cmp < 0)
    n2 += 1;
  }
  n2 += n1;
  struct rational_t **t_sort = malloc(rows*sizeof(rational_t*));
  struct rational_t *q_sort = malloc(rows*sizeof(rational_t));
  unsigned long n1_i = 0; unsigned long n2_i = n1; unsigned long n3_i = n2;
  unsigned long cur = 0;
  while(cur != rows){
   int cmp = rat_cmp(&t[cur][cols-1], &ZERO);
   if(cmp > 0){
    q_sort[n1_i] = q[cur];
    t_sort[n1_i++] = t[cur];
   }else if(cmp < 0){
    q_sort[n2_i] = q[cur];
    t_sort[n2_i++] = t[cur];
   }else{
    q_sort[n3_i] = q[cur];
    t_sort[n3_i++] = t[cur];
   }
   cur++;
  }
  free(t);
  free(q);
  q = q_sort;
  t = t_sort;
  for(i = 0; i < n2; i += 1) {
   struct rational_t *div = &t[i][cols-1];
   rat_div(&q[i], div);
   for(j = 0; j < cols; j += 1) {
    rat_div(&t[i][j], div);
   }
  }
  if(cols == 1){
   struct rational_t tmp;
   tmp.num = 100000000;
   tmp.den = 1;
   int min = 0;
   int max = 0;
    for(i = 0; i < n1; i +=1)
     if(rat_cmp(&q[i], &tmp) < 0){
      tmp.num = q[i].num;
      tmp.den = q[i].den;
      min = i;
     }
   tmp.num = 0;
   tmp.den = 1;
   for(i = n1; i < n2; i +=1)
    if(rat_cmp(&q[i], &tmp) > 0 ){
     tmp.num = q[i].num;
     tmp.den = q[i].den;
     max = i;
    }
   if (rat_cmp(&q[max], &q[min]) > 0) {
    free_all(rows, t, q);
    return 0;
   }
   for(; n2 < rows; n2 += 1)
    if(rat_cmp(&q[n2], &ZERO) < 0) {
     free_all(rows, t, q);
     return 0;
    }
   free_all(rows, t, q);
   return 1;
  }
  unsigned long rows_pr = rows - n2 + n1 * (n2 - n1);
  if (rows_pr == 0) {
   free_all(rows, t, q);
   return 1;
  }
  struct rational_t **t2 = malloc(rows_pr*sizeof(rational_t*));
  struct rational_t *q2 = malloc(rows_pr*sizeof(rational_t));
  for (i = 0; i < rows_pr; i += 1)
    t2[i] = malloc((cols-1)*sizeof(rational_t));
  unsigned long k;
  unsigned long q_index = 0;
  for(i = 0; i < n1; i += 1)
    for(j = n1; j < n2; j += 1){
    q2[q_index] = q[i];
    rat_sub(&q2[q_index],&q[j]);
    for(k = 0; k < cols-1; k += 1) {
     t2[q_index][k] = t[i][k];
     rat_sub(&t2[q_index][k],&t[j][k]);
    }
    q_index++;
   }
  for(i = n2; i < rows; i += 1){
    q2[q_index] = q[i];
   for(k = 0; k < cols-1; k += 1)
    t2[q_index][k] = t[i][k];
   q_index++;
  }
  free_all(rows, t, q);
  q = q2;
  t = t2;
  cols--;
  rows = rows_pr;
 }
}

variable_types:
cols
unsigned long

variable_types: struct rational_t { int num; int den; } *

variable_types:
ZERO
struct rational_t { int num; int den; }

variable_types: cmp int

variable_types:
cur
unsigned long

variable_types:
tmp
struct rational_t { int num; int den; }

variable_types: min int

variable_types: max int

variable_types:
k
unsigned long


decompiled_code:
int __fastcall print_all(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int result; // eax
__int64 v7; // r13
__int64 v8; // r12
__int64 v9; // rbx

result = printf("Rows: %zu, Cols: %zu\n", a3, a4);
if ( a3 )
{
v7 = 0LL;
do
{
v8 = *(_QWORD *)(a1 + 8 * v7);
if ( a4 )
{
v9 = 0LL;
do
printf("%d ", *(unsigned int *)(v8 + 8 * v9++));
while ( a4 != v9 );
}
result = printf(" = %d\n", *(unsigned int *)(a2 + 8 * v7++));
}
while ( a3 != v7 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int result; // eax
__int64 v7; // r13
__int64 v8; // r12
__int64 v9; // rbx

result = printf("Rows: %zu, Cols: %zu\n", a3, a4);
if ( a3 )
{
v7 = 0LL;
do
{
v8 = *(_QWORD *)(a1 + 8 * v7);
if ( a4 )
{
v9 = 0LL;
do
printf("%d ", *(unsigned int *)(v8 + 8 * v9++));
while ( a4 != v9 );
}
result = printf(" = %d\n", *(unsigned int *)(a2 + 8 * v7++));
}
while ( a3 != v7 );
}
return result;
}

original_code:
void print_all(rational_t** A, rational_t* cc, size_t r, size_t c) {
 size_t i;
 size_t j;
 printf("Rows: %zu, Cols: %zu\n", r, c);
 for (i = 0; i < r; i++) {
  rational_t* row = A[i];
  for (j = 0; j < c; j++) {
   printf("%d ", row[j].num);
  }
  printf(" = %d\n", cc[i].num);
 }
}

canonical_original_code:
void print_all(struct rational_t **A, struct rational_t *cc, unsigned long r, unsigned long c) {
 unsigned long i;
 unsigned long j;
 printf("Rows: %zu, Cols: %zu\n", r, c);
 for (i = 0; i < r; i++) {
  struct rational_t *row = A[i];
  for (j = 0; j < c; j++) {
   printf("%d ", row[j].num);
  }
  printf(" = %d\n", cc[i].num);
 }
}

variable_types:
cc
struct rational_t *

variable_types:
r
unsigned long

variable_types:
c
unsigned long

variable_types:
i
unsigned long

variable_types:
j
unsigned long


decompiled_code:
int __fastcall print_all_rat(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int result; // eax
__int64 v8; // r13
__int64 v9; // rbx
__int64 v10; // rbp

result = printf("Rows: %zu, Cols: %zu\n", a3, a4);
if ( a3 )
{
v8 = 0LL;
do
{
v9 = *(_QWORD *)(a1 + 8 * v8);
if ( a4 )
{
v10 = 0LL;
do
{
rat_print(v9);
putchar(32);
++v10;
v9 += 8LL;
}
while ( a4 != v10 );
}
printf(" = ");
rat_print(a2);
result = putchar(10);
++v8;
a2 += 8LL;
}
while ( a3 != v8 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
int result; // eax
__int64 v8; // r13
__int64 v9; // rbx
__int64 v10; // rbp

result = printf("Rows: %zu, Cols: %zu\n", a3, a4);
if ( a3 )
{
v8 = 0LL;
do
{
v9 = *(_QWORD *)(a1 + 8 * v8);
if ( a4 )
{
v10 = 0LL;
do
{
rat_print(v9);
putchar(32);
++v10;
v9 += 8LL;
}
while ( a4 != v10 );
}
printf(" = ");
rat_print(a2);
result = putchar(10);
++v8;
a2 += 8LL;
}
while ( a3 != v8 );
}
return result;
}

original_code:
void print_all_rat(rational_t** A, rational_t* cc, size_t r, size_t c) {
 size_t i;
 size_t j;
 printf("Rows: %zu, Cols: %zu\n", r, c);
 for (i = 0; i < r; i++) {
  rational_t* row = A[i];
  for (j = 0; j < c; j++) {
   rat_print(&row[j]);
   printf(" ");
  }
  printf(" = ");
  rat_print(&cc[i]);
  printf("\n");
 }
}

canonical_original_code:
void print_all_rat(struct rational_t **A, struct rational_t *cc, unsigned long r, unsigned long c) {
 unsigned long i;
 unsigned long j;
 printf("Rows: %zu, Cols: %zu\n", r, c);
 for (i = 0; i < r; i++) {
  struct rational_t *row = A[i];
  for (j = 0; j < c; j++) {
   rat_print(&row[j]);
   printf(" ");
  }
  printf(" = ");
  rat_print(&cc[i]);
  printf("\n");
 }
}


decompiled_code:
__int64 __fastcall rat_sub(_DWORD *a1, unsigned int *a2)
{
int v2; // eax
unsigned int v3; // edx
int v4; // edx
int v5; // er8
__int64 result; // rax

v2 = a1[1];
v3 = a2[1];
if ( v2 == v3 )
{
result = *a2;
*a1 -= result;
}
else
{
v4 = *a1 * v3;
v5 = *a2 * v2;
*a1 = v4 - v5;
result = a2[1] * v2;
a1[1] = result;
if ( v4 - v5 < 0 && (int)result < 0 )
{
result = (unsigned int)-(int)result;
a1[1] = result;
*a1 = v5 - v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, unsigned int *a2)
{
int v2; // eax
unsigned int v3; // edx
int v4; // edx
int v5; // er8
__int64 result; // rax

v2 = a1[1];
v3 = a2[1];
if ( v2 == v3 )
{
result = *a2;
*a1 -= result;
}
else
{
v4 = *a1 * v3;
v5 = *a2 * v2;
*a1 = v4 - v5;
result = a2[1] * v2;
a1[1] = result;
if ( v4 - v5 < 0 && (int)result < 0 )
{
result = (unsigned int)-(int)result;
a1[1] = result;
*a1 = v5 - v4;
}
}
return result;
}

original_code:
void rat_sub(rational_t* a, rational_t* b)
{
        if (a->den == b->den) {
                a->num -= b->num;
                return;
        }
        a->num = a->num * b->den - b->num * a->den;
        a->den *= b->den;
        if (a->den < 0 && a->num < 0) {
                a->den *= -1;
                a->num *= -1;
        }
}

canonical_original_code:
void rat_sub(struct rational_t *a, struct rational_t *b)
{
        if (a->den == b->den) {
                a->num -= b->num;
                return;
        }
        a->num = a->num * b->den - b->num * a->den;
        a->den *= b->den;
        if (a->den < 0 && a->num < 0) {
                a->den *= -1;
                a->num *= -1;
        }
}

variable_types:
b
struct rational_t *


decompiled_code:
unsigned __int64 __fastcall rat_sub_cpy(_DWORD *a1, _DWORD *a2)
{
__int64 v2; // rax
int v3; // edx
int v4; // ecx
int v5; // esi
__int64 v6; // rax
unsigned int v7; // edx

v2 = (unsigned int)a1[1];
v3 = a2[1];
if ( (_DWORD)v2 == v3 )
return (unsigned int)(*a1 - *a2) | (unsigned __int64)(v2 << 32);
v4 = *a1 * v3;
v5 = *a2 * v2;
v6 = (unsigned int)(v3 * v2);
v7 = v4 - v5;
if ( v4 - v5 < 0 && (int)v6 < 0 )
{
v6 = (unsigned int)-(int)v6;
v7 = v5 - v4;
}
return v7 | (unsigned __int64)(v6 << 32);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(_DWORD *a1, _DWORD *a2)
{
__int64 v2; // rax
int v3; // edx
int v4; // ecx
int v5; // esi
__int64 v6; // rax
unsigned int v7; // edx

v2 = (unsigned int)a1[1];
v3 = a2[1];
if ( (_DWORD)v2 == v3 )
return (unsigned int)(*a1 - *a2) | (unsigned __int64)(v2 << 32);
v4 = *a1 * v3;
v5 = *a2 * v2;
v6 = (unsigned int)(v3 * v2);
v7 = v4 - v5;
if ( v4 - v5 < 0 && (int)v6 < 0 )
{
v6 = (unsigned int)-(int)v6;
v7 = v5 - v4;
}
return v7 | (unsigned __int64)(v6 << 32);
}

original_code:
rational_t rat_sub_cpy(rational_t* a, rational_t* b)
{
        rational_t c;
        if (a->den == b->den) {
                c.num = a->num - b->num;
                c.den = a->den;
                return c;
        }
        c.num = a->num * b->den - b->num * a->den;
        c.den = a->den * b->den;
        if (c.den < 0 && c.num < 0) {
                c.den *= -1;
                c.num *= -1;
        }
        return c;
}

canonical_original_code:
struct rational_t rat_sub_cpy(struct rational_t *a, struct rational_t *b)
{
        struct rational_t c;
        if (a->den == b->den) {
                c.num = a->num - b->num;
                c.den = a->den;
                return c;
        }
        c.num = a->num * b->den - b->num * a->den;
        c.den = a->den * b->den;
        if (c.den < 0 && c.num < 0) {
                c.den *= -1;
                c.num *= -1;
        }
        return c;
}

variable_types:
a
struct rational_t *

variable_types:
c
struct rational_t { int num; int den; }

return_type: struct rational_t { int num; int den; }


decompiled_code:
__int64 __fastcall rat_div(unsigned int *a1, unsigned int *a2)
{
unsigned int v2; // edx
unsigned int v3; // er8
__int64 result; // rax
int v5; // edx

if ( *a1 == *a2 )
{
*a1 = a2[1];
}
else
{
v2 = a1[1];
v3 = a2[1];
if ( v2 == v3 )
{
a1[1] = *a2;
}
else
{
*a1 *= v3;
a1[1] = *a2 * v2;
}
}
result = *a1;
if ( (_DWORD)result )
{
v5 = a1[1];
if ( v5 < 0 )
{
result = (unsigned int)-(int)result;
*a1 = result;
a1[1] = -v5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1, unsigned int *a2)
{
unsigned int v2; // edx
unsigned int v3; // er8
__int64 result; // rax
int v5; // edx

if ( *a1 == *a2 )
{
*a1 = a2[1];
}
else
{
v2 = a1[1];
v3 = a2[1];
if ( v2 == v3 )
{
a1[1] = *a2;
}
else
{
*a1 *= v3;
a1[1] = *a2 * v2;
}
}
result = *a1;
if ( (_DWORD)result )
{
v5 = a1[1];
if ( v5 < 0 )
{
result = (unsigned int)-(int)result;
*a1 = result;
a1[1] = -v5;
}
}
return result;
}

original_code:
void rat_div(rational_t* a, rational_t* b)
{
        if (a->num == b->num) {
                a->num = b->den;
        } else if(a->den == b->den) {
                a->den = b->num;
        } else {
                a->num *= b->den;
                a->den *= b->num;
        }
        if ((a->num > 0 && a->den < 0) || (a->num < 0 && a->den < 0)) {
                a->num *= -1;
                a->den *= -1;
        }
}

canonical_original_code:
void rat_div(struct rational_t *a, struct rational_t *b)
{
        if (a->num == b->num) {
                a->num = b->den;
        } else if(a->den == b->den) {
                a->den = b->num;
        } else {
                a->num *= b->den;
                a->den *= b->num;
        }
        if ((a->num > 0 && a->den < 0) || (a->num < 0 && a->den < 0)) {
                a->num *= -1;
                a->den *= -1;
        }
}


decompiled_code:
bool __fastcall rat_equals(_DWORD *a1, _DWORD *a2)
{
int v2; // eax
int v3; // edx
bool result; // al

v2 = a1[1];
v3 = a2[1];
if ( v2 == v3 )
result = *a1 == *a2;
else
result = *a1 * v3 == *a2 * v2;
return result;
}

canonical_decompiled_code:
bool __fastcall func5(_DWORD *a1, _DWORD *a2)
{
int v2; // eax
int v3; // edx
bool result; // al

v2 = a1[1];
v3 = a2[1];
if ( v2 == v3 )
result = *a1 == *a2;
else
result = *a1 * v3 == *a2 * v2;
return result;
}

original_code:
_Bool rat_equals(rational_t* a, rational_t* b)
{
        int diff;
        if (a->den == b->den) {
                diff = a->num - b->num;
                return (diff == 0);
        }
        diff = a->num * b->den - b->num * a->den;
        return (diff == 0);
}

canonical_original_code:
_Bool rat_equals(struct rational_t *a, struct rational_t *b)
{
        int diff;
        if (a->den == b->den) {
                diff = a->num - b->num;
                return (diff == 0);
        }
        diff = a->num * b->den - b->num * a->den;
        return (diff == 0);
}

variable_types: diff int


decompiled_code:
__int64 __fastcall rat_neg(_DWORD *a1)
{
return (unsigned int)(*a1 * a1[1]) >> 31;
}

canonical_decompiled_code:
__int64 __fastcall func6(_DWORD *a1)
{
return (unsigned int)(*a1 * a1[1]) >> 31;
}

original_code:
_Bool rat_neg(rational_t* a)
{
        return (a->den * a->num) < 0;
}

canonical_original_code:
_Bool rat_neg(struct rational_t *a)
{
        return (a->den * a->num) < 0;
}

variable_types: struct rational_t { int num; int den; } *


decompiled_code:
bool __fastcall rat_pos(_DWORD *a1)
{
return *a1 * a1[1] > 0;
}

canonical_decompiled_code:
bool __fastcall func7(_DWORD *a1)
{
return *a1 * a1[1] > 0;
}

original_code:
_Bool rat_pos(rational_t* a)
{
        return (a->den * a->num) > 0;
}

canonical_original_code:
_Bool rat_pos(struct rational_t *a)
{
        return (a->den * a->num) > 0;
}


decompiled_code:
__int64 __fastcall rat_cmp(_DWORD *a1, _DWORD *a2)
{
int v2; // edx
int v3; // eax
int v4; // eax
unsigned int v5; // edx
bool v6; // cc
__int64 result; // rax

v2 = a1[1];
v3 = a2[1];
if ( v2 == v3 )
v4 = *a1 - *a2;
else
v4 = *a1 * v3 - *a2 * v2;
v5 = v4 >> 31;
v6 = v4 <= 0;
result = 1LL;
if ( v6 )
result = v5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1, _DWORD *a2)
{
int v2; // edx
int v3; // eax
int v4; // eax
unsigned int v5; // edx
bool v6; // cc
__int64 result; // rax

v2 = a1[1];
v3 = a2[1];
if ( v2 == v3 )
v4 = *a1 - *a2;
else
v4 = *a1 * v3 - *a2 * v2;
v5 = v4 >> 31;
v6 = v4 <= 0;
result = 1LL;
if ( v6 )
result = v5;
return result;
}

original_code:
int rat_cmp(rational_t* a, rational_t* b)
{
        int diff;
        if (a->den == b->den)
                diff = a->num - b->num;
        else
                diff = a->num * b->den - b->num * a->den;
        if (diff > 0)
                return 1;
        else if (diff < 0)
                return -1;
        else
                return 0;
}

canonical_original_code:
int rat_cmp(struct rational_t *a, struct rational_t *b)
{
        int diff;
        if (a->den == b->den)
                diff = a->num - b->num;
        else
                diff = a->num * b->den - b->num * a->den;
        if (diff > 0)
                return 1;
        else if (diff < 0)
                return -1;
        else
                return 0;
}


decompiled_code:
bool __fastcall rat_set(_DWORD *a1)
{
return *a1 != 0;
}

canonical_decompiled_code:
bool __fastcall func9(_DWORD *a1)
{
return *a1 != 0;
}

original_code:
_Bool rat_set(rational_t *a)
{
        return a->num != 0;
}

canonical_original_code:
_Bool rat_set(struct rational_t *a)
{
        return a->num != 0;
}


decompiled_code:
int __fastcall rat_print(unsigned int *a1)
{
return printf("%d/%d", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int *a1)
{
return printf("%d/%d", *a1, a1[1]);
}

original_code:
void rat_print(rational_t *a)
{
        printf("%d/%d", a->num, a->den);
}

canonical_original_code:
void rat_print(struct rational_t *a)
{
        printf("%d/%d", a->num, a->den);
}


init

repo: Founky/tagada

decompiled_code:
__int64 init()
{
initRam();
return initCore();
}

canonical_decompiled_code:
__int64 func0()
{
initRam();
return initCore();
}

original_code:
void init(char * filePath) {
  initRam(filePath);
  initCore();
}

canonical_original_code:
void init(char *filePath) {
  initRam(filePath);
  initCore();
}

variable_types:
filePath
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi

if ( argc == 2 )
{
v3 = argv[1];
init(v3);
}
else
{
v3 = 0LL;
init(0LL);
}
run(v3, argv);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdi

if ( argc == 2 )
{
v3 = argv[1];
func0(v3);
}
else
{
v3 = 0LL;
func0(0LL);
}
run(v3, argv);
return 0;
}

original_code:
int main(int argc, char * argv[]) {
  if (argc == 2) {
    init(argv[1]);
  } else {
    init(((void *)0));
  }
  run();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  if (argc == 2) {
    init(argv[1]);
  } else {
    init(((void *)0));
  }
  run();
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


printRam

decompiled_code:
__int64 __fastcall printRam(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // er12
__int64 result; // rax

if ( a2 )
{
v2 = a1 + 1;
v3 = 0;
do
{
printf("%04x: %04x ", (unsigned int)(v2 - 1), (unsigned __int16)ram[v2 - 1]);
printf("%04x ", (unsigned __int16)ram[v2]);
printf("%04x ", (unsigned __int16)ram[v2 + 1]);
printf("%04x ", (unsigned __int16)ram[v2 + 2]);
putchar(10);
result = v3++;
v2 += 4;
}
while ( (_DWORD)result != (unsigned int)(a2 - 1) >> 2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // ebx
unsigned int v3; // er12
__int64 result; // rax

if ( a2 )
{
v2 = a1 + 1;
v3 = 0;
do
{
printf("%04x: %04x ", (unsigned int)(v2 - 1), (unsigned __int16)ram[v2 - 1]);
printf("%04x ", (unsigned __int16)ram[v2]);
printf("%04x ", (unsigned __int16)ram[v2 + 1]);
printf("%04x ", (unsigned __int16)ram[v2 + 2]);
putchar(10);
result = v3++;
v2 += 4;
}
while ( (_DWORD)result != (unsigned int)(a2 - 1) >> 2 );
}
return result;
}

original_code:
void printRam(uint32_t start, uint32_t end) {
  int i = 0;
  for (i = 0; i < end; i+=4) {
    printf("%04x: %04x ",i + start + 0, ram[i + start + 0]);
    printf("%04x ", ram[i + start + 1]);
    printf("%04x ", ram[i + start + 2]);
    printf("%04x ", ram[i + start + 3]);
    printf("\n");
  }
}

canonical_original_code:
void printRam(unsigned int start, unsigned int end) {
  int i = 0;
  for (i = 0; i < end; i+=4) {
    printf("%04x: %04x ",i + start + 0, ram[i + start + 0]);
    printf("%04x ", ram[i + start + 1]);
    printf("%04x ", ram[i + start + 2]);
    printf("%04x ", ram[i + start + 3]);
    printf("\n");
  }
}

variable_types:
start
unsigned int

variable_types:
end
unsigned int

variable_types: i int


initRam

decompiled_code:
void __fastcall initRam(const char *a1)
{
memset(ram, 0, (size_t)&unk_10000);
if ( a1 )
loadProgram(a1);
}

canonical_decompiled_code:
void __fastcall func2(const char *a1)
{
memset(ram, 0, (size_t)&unk_10000);
if ( a1 )
func0(a1);
}

original_code:
void initRam(char * filePath) {
  memset(ram, 0, 0x10000);
  if (filePath != ((void *)0)) {
    loadProgram(filePath);
  }
}

canonical_original_code:
void initRam(char *filePath) {
  memset(ram, 0, 0x10000);
  if (filePath != ((void *)0)) {
    loadProgram(filePath);
  }
}


initCore

decompiled_code:
void initCore()
{
regs[0] = 0LL;
regs[1] = 0LL;
regs[2] = 0LL;
intQueing = 0;
}

canonical_decompiled_code:
void func0()
{
regs[0] = 0LL;
regs[1] = 0LL;
regs[2] = 0LL;
intQueing = 0;
}

original_code:
void initCore() {
  memset(&regs, 0, 12 * sizeof(uint16_t));
  intQueing = 0;
}

canonical_original_code:
void initCore() {
  memset(&regs, 0, 12 * sizeof(unsigned short));
  intQueing = 0;
}


specialInstruction

decompiled_code:
__int64 __fastcall specialInstruction(unsigned __int16 a1)
{
__int64 result; // rax

switch ( ((int)a1 >> 4) & 0x3F )
{
case 1:
result = jsrInst();
break;
case 8:
result = intInst();
break;
case 9:
result = iagInst();
break;
case 0xA:
result = iasInst();
break;
case 0xB:
result = rfiInst();
break;
case 0xC:
result = iaqInst();
break;
case 0x10:
result = hwnInst();
break;
case 0x11:
result = hwqInst();
break;
case 0x12:
result = hwiInst();
break;
default:
printf("Unknown opCode : %x\nExiting\n", ((int)a1 >> 4) & 0x3F);
exit(1);
}
return result;
}

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

switch ( ((int)a1 >> 4) & 0x3F )
{
case 1:
result = jsrInst();
break;
case 8:
result = intInst();
break;
case 9:
result = iagInst();
break;
case 0xA:
result = iasInst();
break;
case 0xB:
result = rfiInst();
break;
case 0xC:
result = iaqInst();
break;
case 0x10:
result = hwnInst();
break;
case 0x11:
result = hwqInst();
break;
case 0x12:
result = hwiInst();
break;
default:
printf("Unknown opCode : %x\nExiting\n", ((int)a1 >> 4) & 0x3F);
exit(1);
}
return result;
}

original_code:
void specialInstruction(uint16_t instruction) {
  uint8_t opCode = ((instruction & 0b0000001111110000) >> 4);
  switch (opCode) {
    case 0x01 :
      jsrInst(instruction);
      break;
    case 0x08 :
      intInst(instruction);
      break;
    case 0x09 :
      iagInst(instruction);
      break;
    case 0x0a :
      iasInst(instruction);
      break;
    case 0x0b :
      rfiInst(instruction);
      break;
    case 0x0c :
      iaqInst(instruction);
      break;
    case 0x10 :
      hwnInst(instruction);
      break;
    case 0x11 :
      hwqInst(instruction);
      break;
    case 0x12 :
      hwiInst(instruction);
      break;
    default :
      printf("Unknown opCode : %x\nExiting\n", opCode);
      exit(1);
      break;
  }
}

canonical_original_code:
void specialInstruction(unsigned short instruction) {
  unsigned char opCode = ((instruction & 0b0000001111110000) >> 4);
  switch (opCode) {
    case 0x01 :
      jsrInst(instruction);
      break;
    case 0x08 :
      intInst(instruction);
      break;
    case 0x09 :
      iagInst(instruction);
      break;
    case 0x0a :
      iasInst(instruction);
      break;
    case 0x0b :
      rfiInst(instruction);
      break;
    case 0x0c :
      iaqInst(instruction);
      break;
    case 0x10 :
      hwnInst(instruction);
      break;
    case 0x11 :
      hwqInst(instruction);
      break;
    case 0x12 :
      hwiInst(instruction);
      break;
    default :
      printf("Unknown opCode : %x\nExiting\n", opCode);
      exit(1);
      break;
  }
}

variable_types:
instruction
unsigned short

variable_types:
opCode
unsigned char


printRegisters

decompiled_code:
int printRegisters()
{
printf("A :%04x B :%04x C :%04x X :%04x\n", LOWORD(regs[0]), WORD1(regs[0]), WORD2(regs[0]), HIWORD(regs[0]));
printf("Y :%04x Z :%04x I :%04x J :%04x\n", LOWORD(regs[1]), WORD1(regs[1]), WORD2(regs[1]), HIWORD(regs[1]));
return printf("PC:%04x SP:%04x EX:%04x IA:%04x\n", LOWORD(regs[2]), WORD1(regs[2]), WORD2(regs[2]), HIWORD(regs[2]));
}

canonical_decompiled_code:
int func2()
{
printf("A :%04x B :%04x C :%04x X :%04x\n", LOWORD(regs[0]), WORD1(regs[0]), WORD2(regs[0]), HIWORD(regs[0]));
printf("Y :%04x Z :%04x I :%04x J :%04x\n", LOWORD(regs[1]), WORD1(regs[1]), WORD2(regs[1]), HIWORD(regs[1]));
return printf("PC:%04x SP:%04x EX:%04x IA:%04x\n", LOWORD(regs[2]), WORD1(regs[2]), WORD2(regs[2]), HIWORD(regs[2]));
}

original_code:
void printRegisters() {
  printf("A :%04x B :%04x C :%04x X :%04x\n", regs.A, regs.B, regs.C, regs.X);
  printf("Y :%04x Z :%04x I :%04x J :%04x\n", regs.Y, regs.Z, regs.I, regs.J);
  printf("PC:%04x SP:%04x EX:%04x IA:%04x\n", regs.PC, regs.SP, regs.EX, regs.IA);
}