intersect

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

*(float *)v9 = *a2 - *a1;
*(float *)&v9[1] = a2[1] - a1[1];
*(float *)&v9[2] = a2[2] - a1[2];
v7[1] = DotProduct(a3, v9);
v4 = DotProduct(v9, v9) - (float)(a4 * a4);
*(float *)v7 = v4;
solveQuadric((float *)v7, 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[2]; // [rsp+14h] [rbp-1Ch] BYREF
float v8[2]; // [rsp+1Ch] [rbp-14h] BYREF
int v9[3]; // [rsp+24h] [rbp-Ch] BYREF

*(float *)v9 = *a2 - *a1;
*(float *)&v9[1] = a2[1] - a1[1];
*(float *)&v9[2] = a2[2] - a1[2];
v7[1] = DotProduct(a3, v9);
v4 = DotProduct(v9, v9) - (float)(a4 * a4);
*(float *)v7 = v4;
func2((float *)v7, 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; }


repo: ForsakenX/forsaken

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: struct VECTOR { float x; float y; float z; } *

variable_types: radius float

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


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: Radius float

variable_types:
RayStart
struct VECTOR *

variable_types:
RayEnd
struct VECTOR *

variable_types:
IntPoint
struct VECTOR *

variable_types: RayLength float

return_type: short

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


RaytoSphereShort

decompiled_code:
bool __fastcall RaytoSphereShort(float *a1, float *a2, float *a3, float a4, float a5)
{
bool result; // al
float v6; // xmm2_4
float v7; // xmm5_4
float v9; // xmm0_4
float v10; // xmm3_4
float v11; // xmm4_4
float v12; // xmm2_4
float v13; // xmm3_4
float v14; // xmm3_4
float v15; // xmm0_4

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

canonical_decompiled_code:
bool __fastcall func7(float *a1, float *a2, float *a3, float a4, float a5)
{
bool result; // al
float v6; // xmm2_4
float v7; // xmm5_4
float v9; // xmm0_4
float v10; // xmm3_4
float v11; // xmm4_4
float v12; // xmm2_4
float v13; // xmm3_4
float v14; // xmm3_4
float v15; // xmm0_4

result = 1;
v6 = a2[1] - a1[1];
v7 = a2[2] - a1[2];
v9 = *a2 - *a1;
v10 = a4 * a4;
v11 = (float)((float)(v9 * v9) + (float)(v6 * v6)) + (float)(v7 * v7);
if ( v10 < v11 )
{
v12 = (float)((float)(v6 * a3[1]) + (float)(v9 * *a3)) + (float)(v7 * a3[2]);
v13 = v10 - (float)(v11 - (float)(v12 * v12));
if ( v13 < 0.0 || (v14 = fsqrt(v13), v15 = fminf(v14 - v12, COERCE_FLOAT(LODWORD(v14) ^ LC5) - v12), v15 < 0.0) )
result = 0;
else
result = v15 <= 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: 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

return_type: 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; // r12
__int64 result; // rax

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

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

v0 = (const char *)convert_path();
if ( stat(v0, &s_2) || (result = 1LL, (byte_879 & 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; // r13
unsigned int v2; // er12
gcc_va_list arg; // [rsp+8h] [rbp-D8h] BYREF

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

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

va_start(arg, format);
vsnprintf(pathname_1, 0xFFuLL, format, arg);
byte_85F = 0;
v1 = (const char *)convert_path(pathname_1);
v2 = stat(v1, &s_0);
if ( v2 )
return mkdir(v1, 0x1FFu) == 0;
if ( (byte_6D9 & 0x40) != 0 )
return 1LL;
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; // er13
const char *v2; // r12
int v3; // eax
const char *v4; // rdx

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

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

v2 = (const char *)convert_path(a1);
v3 = access(v2, 0);
v4 = "missing";
if ( !v3 )
v4 = "exits";
LOBYTE(v1) = v3 == 0;
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; // r12
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; // r12
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; // r12
int v2; // eax
__int64 v4; // rax

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");
return 0LL;
}
if ( v2 > 2 )
{
if ( v2 == 3 )
{
DebugPrintf("file: find_file: no match\n");
return 0LL;
}
goto LABEL_11;
}
if ( v2 )
{
if ( v2 == 1 )
{
DebugPrintf("file: find_file: ran out of memory!\n");
return 0LL;
}
LABEL_11:
DebugPrintf("file: find_file: unknown return value from glob()\n");
return 0LL;
}
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]);
}

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

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");
return 0LL;
}
if ( v2 > 2 )
{
if ( v2 == 3 )
{
DebugPrintf("file: find_file: no match\n");
return 0LL;
}
goto LABEL_11;
}
if ( v2 )
{
if ( v2 == 1 )
{
DebugPrintf("file: find_file: ran out of memory!\n");
return 0LL;
}
LABEL_11:
DebugPrintf("file: find_file: unknown return value from glob()\n");
return 0LL;
}
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]);
}

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()
{
__int64 v0; // rax

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

canonical_decompiled_code:
const char *func12()
{
__int64 v0; // rax

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

return_type: void


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

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

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

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

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_AF2, 0LL);
return result;
}

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

result = func4(a1);
if ( !(_BYTE)result )
result = func5(a1, &unk_AF2, 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; // r13
ssize_t v6; // r14
int v7; // eax
int v8; // er13

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

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

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

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) )
{
LABEL_4:
if ( !fetestexcept(1) )
goto LABEL_5;
goto LABEL_10;
}
}
else if ( !fetestexcept(32) )
{
goto LABEL_4;
}
DebugPrintf("FE_INEXACT\n");
if ( !fetestexcept(1) )
{
LABEL_5:
if ( !fetestexcept(8) )
goto LABEL_6;
goto LABEL_11;
}
LABEL_10:
DebugPrintf("FE_INVALID\n");
if ( !fetestexcept(8) )
{
LABEL_6:
if ( !fetestexcept(16) )
{
LABEL_7:
DebugPrintf("======================\n");
feclearexcept(61);
return 1;
}
LABEL_12:
DebugPrintf("FE_UNDERFLOW\n");
goto LABEL_7;
}
LABEL_11:
DebugPrintf("FE_OVERFLOW\n");
if ( !fetestexcept(16) )
goto LABEL_7;
goto LABEL_12;
}
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) )
{
LABEL_4:
if ( !fetestexcept(1) )
goto LABEL_5;
goto LABEL_10;
}
}
else if ( !fetestexcept(32) )
{
goto LABEL_4;
}
DebugPrintf("FE_INEXACT\n");
if ( !fetestexcept(1) )
{
LABEL_5:
if ( !fetestexcept(8) )
goto LABEL_6;
goto LABEL_11;
}
LABEL_10:
DebugPrintf("FE_INVALID\n");
if ( !fetestexcept(8) )
{
LABEL_6:
if ( !fetestexcept(16) )
{
LABEL_7:
DebugPrintf("======================\n");
feclearexcept(61);
return 1;
}
LABEL_12:
DebugPrintf("FE_UNDERFLOW\n");
goto LABEL_7;
}
LABEL_11:
DebugPrintf("FE_OVERFLOW\n");
if ( !fetestexcept(16) )
goto LABEL_7;
goto LABEL_12;
}
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)
{
__int64 v1; // rbx
char *v2; // rbp
const __int32_t **v3; // rdx

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

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

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

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
const char *v2; // 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 && SDL_GetVideoInfo() )
return 1LL;
v2 = (const char *)SDL_GetError();
p("Failed to initialize sdl: %s\n", v2);
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned __int8 *v0; // rax
const char *v2; // 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 && SDL_GetVideoInfo() )
return 1LL;
v2 = (const char *)SDL_GetError();
func2("Failed to initialize sdl: %s\n", v2);
return 0LL;
}

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, __int64 a2)
{
__int64 *v2; // rax
__int64 v3; // rax
int v4; // edx
__int64 result; // rax

v2 = (__int64 *)SDL_ListModes(0LL, a1);
if ( v2 )
{
if ( v2 == (__int64 *)-1LL )
{
*(_QWORD *)a2 = 0x1E000000280LL;
}
else
{
v3 = *v2;
v4 = *(unsigned __int16 *)(v3 + 4);
LODWORD(v3) = *(unsigned __int16 *)(v3 + 6);
*(_DWORD *)a2 = v4;
*(_DWORD *)(a2 + 4) = v3;
}
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, __int64 a2)
{
__int64 *v2; // rax
__int64 v3; // rax
int v4; // edx
__int64 result; // rax

v2 = (__int64 *)SDL_ListModes(0LL, a1);
if ( v2 )
{
if ( v2 == (__int64 *)-1LL )
{
*(_QWORD *)a2 = 0x1E000000280LL;
}
else
{
v3 = *v2;
v4 = *(unsigned __int16 *)(v3 + 4);
LODWORD(v3) = *(unsigned __int16 *)(v3 + 6);
*(_DWORD *)a2 = v4;
*(_DWORD *)(a2 + 4) = v3;
}
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; } *


decompiled_code:
__int64 __fastcall timer_run(__int64 a1)
{
__int64 result; // rax
float v2; // xmm2_4
int v3; // edx
float v4; // xmm0_4
float v5; // xmm2_4
bool v6; // zf

if ( *(_DWORD *)a1 )
{
result = SDL_GetTicks();
v2 = *(float *)(a1 + 4);
v3 = result - *(_DWORD *)a1;
*(_DWORD *)a1 = result;
v4 = (float)v3 / 1000.0;
*(float *)(a1 + 12) = v4;
if ( v2 == 0.0 || v2 > v4 )
{
v5 = *(float *)(a1 + 8);
*(float *)(a1 + 4) = v4;
v6 = v5 == 0.0;
}
else
{
v5 = *(float *)(a1 + 8);
v6 = v5 == 0.0;
}
if ( v6 || v4 > v5 )
*(float *)(a1 + 8) = v4;
}
else
{
result = SDL_GetTicks();
*(_DWORD *)a1 = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
float v2; // xmm2_4
int v3; // edx
float v4; // xmm0_4
float v5; // xmm2_4
bool v6; // zf

if ( *(_DWORD *)a1 )
{
result = SDL_GetTicks();
v2 = *(float *)(a1 + 4);
v3 = result - *(_DWORD *)a1;
*(_DWORD *)a1 = result;
v4 = (float)v3 / 1000.0;
*(float *)(a1 + 12) = v4;
if ( v2 == 0.0 || v2 > v4 )
{
v5 = *(float *)(a1 + 8);
*(float *)(a1 + 4) = v4;
v6 = v5 == 0.0;
}
else
{
v5 = *(float *)(a1 + 8);
v6 = v5 == 0.0;
}
if ( v6 || v4 > v5 )
*(float *)(a1 + 8) = v4;
}
else
{
result = SDL_GetTicks();
*(_DWORD *)a1 = result;
}
return result;
}

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

return_type: float

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


decompiled_code:
__int64 __fastcall timer_peek(__int64 *a1)
{
__int64 v1; // r12
__int64 v2; // rbp
__int64 result; // rax

v1 = *a1;
v2 = a1[1];
result = timer_run((__int64)a1);
*a1 = v1;
a1[1] = v2;
return result;
}

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_401610(argc, argv, envp) )
{
while ( (unsigned int)sub_401280() )
;
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; // rax
bool v3; // cc
__int64 result; // rax

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

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

v2 = *((_QWORD *)a2 + 2);
v3 = *((_QWORD *)a1 + 2) <= v2;
result = *((_QWORD *)a1 + 2) < v2;
if ( !v3 )
result = 0xFFFFFFFFLL;
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
bool v5; // zf
void *v6; // r8
__int64 v7; // rdx
__int64 v8; // rax
__int64 v9; // rdx
__int64 v10; // rbx
__int64 v11; // rbx
__int64 v13; // rbx
__int64 v14; // rcx
__int64 v15; // rbp
unsigned int v16; // [rsp+Ch] [rbp-401Ch] BYREF
char s[8192]; // [rsp+10h] [rbp-4018h] BYREF
char v18[8216]; // [rsp+2010h] [rbp-2018h] BYREF

v16 = 4;
if ( argc > 1 && (unsigned int)_isoc99_sscanf(argv[1], &unk_3E, &v16) == 1 && (v16 & 0x80000000) != 0 )
{
fprintf(stderr, "invalid parameter for seconds: %d\n", v16);
exit(1);
}
v3 = 0LL;
for ( i = 0LL; i != 6; ++i )
{
while ( 1 )
{
snprintf(s, 0x2000uLL, "input/%zu/A", i);
snprintf(v18, 0x2000uLL, "input/%zu/c", i);
v8 = off_28(s, v18, 0LL);
v9 = (unsigned int)correct[i];
if ( v9 != v8 )
break;
++i;
++v3;
if ( i == 6 )
goto LABEL_10;
}
v5 = (_DWORD)v9 == 0;
v6 = &unk_3B;
v7 = i;
if ( !v5 )
v6 = &unk_39;
printf("\"%s\" failed test %zu: return value %llu but the system has %s solution.\n", fm, v7, v8, v6);
}
LABEL_10:
if ( v3 > 5 )
{
v13 = 0LL;
printf("\"%s\" PASSED ALL %zu TESTS.\n", fm, 6uLL);
do
{
printf("Counting test %zu: ", v13);
fflush(stdout);
snprintf(s, 0x2000uLL, "input/%zu/A", v13);
v14 = v13++;
snprintf(v18, 0x2000uLL, "input/%zu/c", v14);
v15 = off_28(s, v18, v16);
printf("%*llu\n", 20, v15);
qword_30 += v15;
}
while ( v13 != 6 );
}
else
{
printf("\"%s\" FAILED %zu/%zu TESTS.\n", fm, i - v3, 6uLL);
}
qsort(&fm, 1uLL, 0x18uLL, (__compar_fn_t)compare_count);
v10 = 44LL;
do
{
putchar(61);
--v10;
}
while ( v10 );
v11 = 44LL;
putchar(10);
printf("%2zu %-*s %*llu\n", 1uLL, 20, fm, 20, qword_30);
do
{
putchar(61);
--v11;
}
while ( v11 );
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
void **v5; // rbp
void *v6; // rdi

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

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

if ( a1 )
{
v4 = a2;
v5 = &a2[a1];
do
{
v6 = *v4++;
free(v6);
}
while ( v4 != v5 );
}
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 v8; // r12
__int64 v9; // r14
__int64 v10; // rbx
__int64 v11; // rsi
__int64 v12; // rsi

result = printf("Rows: %zu, Cols: %zu\n", a3, a4);
if ( a3 )
{
v8 = 0LL;
do
{
v9 = *(_QWORD *)(a1 + 8 * v8);
if ( a4 )
{
v10 = 0LL;
do
{
v11 = *(unsigned int *)(v9 + 8 * v10++);
printf("%d ", v11);
}
while ( a4 != v10 );
}
v12 = *(unsigned int *)(a2 + 8 * v8++);
result = printf(" = %d\n", v12);
}
while ( a3 != v8 );
}
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; // r12
__int64 v9; // rbx
__int64 v10; // r15
__int64 v11; // rdi
__int64 v12; // rdi

result = printf("Rows: %zu, Cols: %zu\n", a3, a4);
if ( a3 )
{
v8 = 0LL;
do
{
v9 = *(_QWORD *)(a1 + 8 * v8);
if ( a4 )
{
v10 = 0LL;
do
{
v11 = v9;
++v10;
v9 += 8LL;
rat_print(v11);
putchar(32);
}
while ( a4 != v10 );
}
++v8;
printf(" = ");
v12 = a2;
a2 += 8LL;
rat_print(v12);
result = putchar(10);
}
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(int *a1, int *a2)
{
__int64 result; // rax
int v3; // er8
int v4; // edx
int v5; // ecx
int v6; // edx
int v7; // ecx

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

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, int *a2)
{
__int64 result; // rax
int v3; // er8
int v4; // edx
int v5; // ecx
int v6; // edx
int v7; // ecx

result = (unsigned int)a1[1];
v3 = a2[1];
v4 = *a1;
v5 = *a2;
if ( (_DWORD)result == v3 )
{
*a1 = v4 - v5;
}
else
{
v6 = v3 * v4;
v7 = result * v5;
result = (unsigned int)(v3 * result);
*a1 = v6 - v7;
a1[1] = result;
if ( v6 - v7 < 0 && (int)result < 0 )
{
result = (unsigned int)-(int)result;
a1[1] = result;
*a1 = v7 - v6;
}
}
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(int *a1, int *a2)
{
__int64 v2; // rdx
int v3; // er8
int v4; // eax
int v5; // ecx
int v6; // eax
int v7; // ecx
__int64 v8; // rdx
unsigned __int64 result; // rax

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

canonical_decompiled_code:
unsigned __int64 __fastcall func2(int *a1, int *a2)
{
__int64 v2; // rdx
int v3; // er8
int v4; // eax
int v5; // ecx
int v6; // eax
int v7; // ecx
__int64 v8; // rdx
unsigned __int64 result; // rax

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

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
__int64 result; // rax
unsigned int v4; // ecx
int v5; // edx

v2 = *a1;
result = a2[1];
if ( *a1 == *a2 )
{
*a1 = result;
}
else
{
v4 = a1[1];
if ( v4 == (_DWORD)result )
{
a1[1] = *a2;
result = v2;
}
else
{
result = v2 * (unsigned int)result;
*a1 = result;
a1[1] = *a2 * v4;
}
}
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
__int64 result; // rax
unsigned int v4; // ecx
int v5; // edx

v2 = *a1;
result = a2[1];
if ( *a1 == *a2 )
{
*a1 = result;
}
else
{
v4 = a1[1];
if ( v4 == (_DWORD)result )
{
a1[1] = *a2;
result = v2;
}
else
{
result = v2 * (unsigned int)result;
*a1 = result;
a1[1] = *a2 * v4;
}
}
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(int *a1, int *a2)
{
int v2; // eax
int v3; // edx
int v4; // edi
int v5; // ecx
bool result; // al

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

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

v2 = a1[1];
v3 = a2[1];
v4 = *a1;
v5 = *a2;
if ( v2 == v3 )
result = v5 == v4;
else
result = v4 * v3 == v5 * 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(int *a1, int *a2)
{
int v2; // eax
int v3; // edx
int v4; // edi
int v5; // ecx
int v6; // edx
__int64 result; // rax

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

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

v2 = a1[1];
v3 = a2[1];
v4 = *a1;
v5 = *a2;
if ( v2 == v3 )
v6 = v4 - v5;
else
v6 = v4 * v3 - v5 * v2;
result = (unsigned int)-(v6 != 0);
if ( v6 > 0 )
result = 1LL;
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)
{
unsigned int v2; // ebp
int v3; // ebx
__int64 v4; // rax
__int64 result; // rax

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

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

if ( a2 )
{
v2 = 0;
v3 = a1 + 1;
do
{
printf("%04x: %04x ", (unsigned int)(v3 - 1), (unsigned __int16)ram[v3 - 1]);
printf("%04x ", (unsigned __int16)ram[v3]);
printf("%04x ", (unsigned __int16)ram[v3 + 1]);
v4 = (unsigned int)(v3 + 2);
v3 += 4;
printf("%04x ", (unsigned __int16)ram[v4]);
putchar(10);
result = v2++;
}
while ( (unsigned int)(a2 - 1) >> 2 != (_DWORD)result );
}
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()
{
intQueing = 0;
*((_QWORD *)&regs + 2) = 0LL;
regs = 0LL;
}

canonical_decompiled_code:
void func0()
{
intQueing = 0;
*((_QWORD *)&regs + 2) = 0LL;
regs = 0LL;
}

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", (unsigned __int16)regs, WORD1(regs), WORD2(regs), WORD3(regs));
printf("Y :%04x Z :%04x I :%04x J :%04x\n", WORD4(regs), WORD5(regs), WORD6(regs), HIWORD(regs));
return printf(
"PC:%04x SP:%04x EX:%04x IA:%04x\n",
*((unsigned __int16 *)&regs + 8),
*((unsigned __int16 *)&regs + 9),
*((unsigned __int16 *)&regs + 10),
*((unsigned __int16 *)&regs + 11));
}

canonical_decompiled_code:
int func2()
{
printf("A :%04x B :%04x C :%04x X :%04x\n", (unsigned __int16)regs, WORD1(regs), WORD2(regs), WORD3(regs));
printf("Y :%04x Z :%04x I :%04x J :%04x\n", WORD4(regs), WORD5(regs), WORD6(regs), HIWORD(regs));
return printf(
"PC:%04x SP:%04x EX:%04x IA:%04x\n",
*((unsigned __int16 *)&regs + 8),
*((unsigned __int16 *)&regs + 9),
*((unsigned __int16 *)&regs + 10),
*((unsigned __int16 *)&regs + 11));
}

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


run

decompiled_code:
void run()
{
unsigned __int16 i; // ax
unsigned int v1; // er12

for ( i = *((_WORD *)&regs + 8); ; *((_WORD *)&regs + 8) = i )
{
v1 = *((unsigned __int16 *)&ram + i);
puts("----- NEW INSTRUCTION -----");
printf("%04x -- o: %x, b: %x, a: %x\n", v1, v1 & 0xF, ((int)v1 >> 4) & 0x3F, ((unsigned __int16)v1 >> 10) & 0x3F);
printRam(0LL, 4LL);
printRegisters();
switch ( v1 & 0xF )
{
case 0u:
specialInstruction(v1);
break;
case 1u:
setInst(v1);
break;
case 2u:
addInst(v1);
break;
case 3u:
subInst(v1);
break;
case 4u:
mulInst(v1);
break;
case 5u:
mliInst(v1);
break;
case 6u:
divInst(v1);
break;
case 7u:
dviInst(v1);
break;
case 8u:
modInst(v1);
break;
case 9u:
mdiInst(v1);
break;
case 0xAu:
andInst(v1);
break;
case 0xBu:
borInst(v1);
break;
case 0xCu:
xorInst(v1);
break;
case 0xDu:
shrInst(v1);
break;
case 0xEu:
asrInst(v1);
break;
case 0xFu:
shlInst(v1);
break;
}
i = *((_WORD *)&regs + 8) + 1;
}
}

canonical_decompiled_code:
void func3()
{
unsigned __int16 i; // ax
unsigned int v1; // er12

for ( i = *((_WORD *)&regs + 8); ; *((_WORD *)&regs + 8) = i )
{
v1 = *((unsigned __int16 *)&ram + i);
puts("----- NEW INSTRUCTION -----");
printf("%04x -- o: %x, b: %x, a: %x\n", v1, v1 & 0xF, ((int)v1 >> 4) & 0x3F, ((unsigned __int16)v1 >> 10) & 0x3F);
printRam(0LL, 4LL);
func2();
switch ( v1 & 0xF )
{
case 0u:
func1(v1);
break;
case 1u:
setInst(v1);
break;
case 2u:
addInst(v1);
break;
case 3u:
subInst(v1);
break;
case 4u:
mulInst(v1);
break;
case 5u:
mliInst(v1);
break;
case 6u:
divInst(v1);
break;
case 7u:
dviInst(v1);
break;
case 8u:
modInst(v1);
break;
case 9u:
mdiInst(v1);
break;
case 0xAu:
andInst(v1);
break;
case 0xBu:
borInst(v1);
break;
case 0xCu:
xorInst(v1);
break;
case 0xDu:
shrInst(v1);
break;
case 0xEu:
asrInst(v1);
break;
case 0xFu:
shlInst(v1);
break;
}
i = *((_WORD *)&regs + 8) + 1;
}
}

original_code:
void run() {
  uint16_t instruction = 0x0;
  uint8_t opCode = 0x0;
  while (1) {
    instruction = ram[regs.PC];
    opCode = ((instruction & 0b0000000000001111) >> 0);
    printf("----- NEW INSTRUCTION -----\n");
    printf("%04x -- o: %x, b: %x, a: %x\n", instruction, ((instruction & 0b0000000000001111) >> 0), ((instruction & 0b0000001111110000) >> 4) , ((instruction & 0b1111110000000000) >> 10));
    printRam(0,4);
    printRegisters();
    switch (opCode) {
      case 0x00 :
        specialInstruction(instruction);
        break;
      case 0x01 :
        setInst(instruction);
        break;
      case 0x02 :
        addInst(instruction);
        break;
      case 0x03 :
        subInst(instruction);
        break;
      case 0x04 :
        mulInst(instruction);
        break;
      case 0x05 :
        mliInst(instruction);
        break;
      case 0x06 :
        divInst(instruction);
        break;
      case 0x07 :
        dviInst(instruction);
        break;
      case 0x08 :
        modInst(instruction);
        break;
      case 0x09 :
        mdiInst(instruction);
        break;
      case 0x0a :
        andInst(instruction);
        break;
      case 0x0b :
        borInst(instruction);
        break;
      case 0x0c :
        xorInst(instruction);
        break;
      case 0x0d :
        shrInst(instruction);
        break;
      case 0x0e :
        asrInst(instruction);
        break;
      case 0x0f :
        shlInst(instruction);
        break;
      case 0x10 :
        ifbInst(instruction);
        break;
      case 0x11 :
        ifcInst(instruction);
        break;
      case 0x12 :
        ifeInst(instruction);
        break;
      case 0x13 :
        ifnInst(instruction);
        break;
      case 0x14 :
        ifgInst(instruction);
        break;
      case 0x15 :
        ifaInst(instruction);
        break;
      case 0x16 :
        iflInst(instruction);
        break;
      case 0x17 :
        ifuInst(instruction);
        break;
      case 0x18 :
        break;
      case 0x19 :
        break;
      case 0x1a :
        adxInst(instruction);
        break;
      case 0x1b :
        sbxInst(instruction);
        break;
      case 0x1c :
        break;
      case 0x1d :
        break;
      case 0x1e :
        sdiInst(instruction);
        break;
      case 0x1f :
        stdInst(instruction);
        break;
      default :
        printf("Unknown opCode : %x\nExiting\n", opCode);
        exit(1);
        break;
    }
    regs.PC++;
  }
}

canonical_original_code:
void run() {
  unsigned short instruction = 0x0;
  unsigned char opCode = 0x0;
  while (1) {
    instruction = ram[regs.PC];
    opCode = ((instruction & 0b0000000000001111) >> 0);
    printf("----- NEW INSTRUCTION -----\n");
    printf("%04x -- o: %x, b: %x, a: %x\n", instruction, ((instruction & 0b0000000000001111) >> 0), ((instruction & 0b0000001111110000) >> 4) , ((instruction & 0b1111110000000000) >> 10));
    printRam(0,4);
    printRegisters();
    switch (opCode) {
      case 0x00 :
        specialInstruction(instruction);
        break;
      case 0x01 :
        setInst(instruction);
        break;
      case 0x02 :
        addInst(instruction);
        break;
      case 0x03 :
        subInst(instruction);
        break;
      case 0x04 :
        mulInst(instruction);
        break;
      case 0x05 :
        mliInst(instruction);
        break;
      case 0x06 :
        divInst(instruction);
        break;
      case 0x07 :
        dviInst(instruction);
        break;
      case 0x08 :
        modInst(instruction);
        break;
      case 0x09 :
        mdiInst(instruction);
        break;
      case 0x0a :
        andInst(instruction);
        break;
      case 0x0b :
        borInst(instruction);
        break;
      case 0x0c :
        xorInst(instruction);
        break;
      case 0x0d :
        shrInst(instruction);
        break;
      case 0x0e :
        asrInst(instruction);
        break;
      case 0x0f :
        shlInst(instruction);
        break;
      case 0x10 :
        ifbInst(instruction);
        break;
      case 0x11 :
        ifcInst(instruction);
        break;
      case 0x12 :
        ifeInst(instruction);
        break;
      case 0x13 :
        ifnInst(instruction);
        break;
      case 0x14 :
        ifgInst(instruction);
        break;
      case 0x15 :
        ifaInst(instruction);
        break;
      case 0x16 :
        iflInst(instruction);
        break;
      case 0x17 :
        ifuInst(instruction);
        break;
      case 0x18 :
        break;
      case 0x19 :
        break;
      case 0x1a :
        adxInst(instruction);
        break;
      case 0x1b :
        sbxInst(instruction);
        break;
      case 0x1c :
        break;
      case 0x1d :
        break;
      case 0x1e :
        sdiInst(instruction);
        break;
      case 0x1f :
        stdInst(instruction);
        break;
      default :
        printf("Unknown opCode : %x\nExiting\n", opCode);
        exit(1);
        break;
    }
    regs.PC++;
  }
}


decompiled_code:
__int64 __fastcall assstack_find(__int64 a1, __int64 a2)
{
size_t v2; // rbx
__int64 v3; // r12

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a2 + 8);
v3 = a1;
do
{
if ( *(_QWORD *)(v3 + 8) == v2 && !memcmp(*(const void **)v3, *(const void **)a2, v2) )
break;
v3 = *(_QWORD *)(v3 + 32);
}
while ( v3 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
size_t v2; // rbx
__int64 v3; // r12

if ( !a1 )
return 0LL;
v2 = *(_QWORD *)(a2 + 8);
v3 = a1;
do
{
if ( *(_QWORD *)(v3 + 8) == v2 && !memcmp(*(const void **)v3, *(const void **)a2, v2) )
break;
v3 = *(_QWORD *)(v3 + 32);
}
while ( v3 );
return v3;
}

original_code:
struct assstack_entry *assstack_find(struct assstack_entry *stack, struct string *key) {
    for (; stack; stack = stack->next)
 if (stack->key.len == key->len && !memcmp(stack->key.data, key->data, key->len))
     return stack;
    return ((void *)0);
}

variable_types:
stack
struct assstack_entry *

variable_types:
key
struct string *

return_type: struct assstack_entry { struct string { void *data; unsigned long len; } key; struct string val; struct assstack_entry *next; } *

user_defined_types: struct assstack_entry { struct string key; struct string val; struct assstack_entry *next; }


printsoa

original_code:
void printsoa(struct string *soa) {
    char *s;
    size_t i;
    s = (char *)soa->data;
    i = 0;
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    printf("(\n\t\t\t\t");
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    printf("; Serialnumber\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Refresh\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Retry\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Expire\n\t\t\t\t");
    while (i < soa->len) {
 putchar(s[i++]);
    }
    printf(" )\t; Minimum TTL\n");
}

canonical_original_code:
void printsoa(struct string *soa) {
    char *s;
    unsigned long i;
    s = (char *)soa->data;
    i = 0;
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    printf("(\n\t\t\t\t");
    while (i < soa->len) {
 putchar(s[i]);
 if (s[i++] == ' ')
     break;
    }
    printf("; Serialnumber\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Refresh\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Retry\n\t\t\t\t");
    while (i < soa->len) {
 if (s[i] == ' ')
     break;
 putchar(s[i++]);
    }
    i++;
    printf("\t; Expire\n\t\t\t\t");
    while (i < soa->len) {
 putchar(s[i++]);
    }
    printf(" )\t; Minimum TTL\n");
}

variable_types: struct string { void *data; unsigned long len; } *

variable_types:
s
char *

variable_types:
i
unsigned long


printrrs

decompiled_code:
int __fastcall printrrs(char *s1, __int64 a2)
{
__int64 v3; // rax
_BYTE *v4; // r12
int v5; // edi
__int64 i; // rbx
unsigned __int64 v7; // rax
int v8; // ebx
int result; // eax
__int64 v10; // rbp
const char *v11; // r14
char *v12; // rax
const char *v13; // r12
unsigned __int64 v14; // rbx
__int64 v15; // r12
int v16; // edi
char *v17; // rax

v3 = *(_QWORD *)(a2 + 8);
v4 = *(_BYTE **)a2;
if ( v3 != 1 )
{
if ( !v3 )
{
LABEL_23:
putchar(9);
LABEL_8:
v8 = 0;
result = putchar(9);
goto LABEL_9;
}
v5 = (char)*v4;
LABEL_4:
for ( i = 0LL; ; v5 = (char)v4[i] )
{
putchar(v5);
v7 = *(_QWORD *)(a2 + 8);
if ( v7 <= ++i )
break;
}
if ( v7 > 7 )
goto LABEL_8;
goto LABEL_23;
}
v5 = (char)*v4;
if ( *v4 != 64 )
goto LABEL_4;
v8 = 1;
result = printf("@\t");
LABEL_9:
v10 = *(_QWORD *)(a2 + 16);
if ( v10 )
{
v11 = *(const char **)v10;
v12 = strchr(*(const char **)v10, 32);
*v12 = 0;
v13 = v12 + 1;
if ( strcmp(s1, v11) )
goto LABEL_17;
while ( 1 )
{
putchar(9);
if ( v8 )
{
printf("IN\t%s\t", v13);
if ( !strcmp(v13, "SOA") )
{
result = printsoa((__int64 *)(v10 + 16));
v10 = *(_QWORD *)(v10 + 32);
if ( !v10 )
return result;
goto LABEL_16;
}
}
else
{
printf("%s\t", v13);
}
v14 = 0LL;
v15 = *(_QWORD *)(v10 + 16);
while ( *(_QWORD *)(v10 + 24) > v14 )
{
v16 = *(char *)(v15 + v14++);
putchar(v16);
}
result = putchar(10);
v10 = *(_QWORD *)(v10 + 32);
if ( !v10 )
return result;
LABEL_16:
v11 = *(const char **)v10;
v8 = 0;
v17 = strchr(*(const char **)v10, 32);
*v17 = 0;
v13 = v17 + 1;
printf("\t\t");
if ( strcmp(s1, v11) )
LABEL_17:
printf("%s", v11);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(char *s1, __int64 a2)
{
__int64 v3; // rax
_BYTE *v4; // r12
int v5; // edi
__int64 i; // rbx
unsigned __int64 v7; // rax
int v8; // ebx
int result; // eax
__int64 v10; // rbp
const char *v11; // r14
char *v12; // rax
const char *v13; // r12
unsigned __int64 v14; // rbx
__int64 v15; // r12
int v16; // edi
char *v17; // rax

v3 = *(_QWORD *)(a2 + 8);
v4 = *(_BYTE **)a2;
if ( v3 != 1 )
{
if ( !v3 )
{
LABEL_23:
putchar(9);
LABEL_8:
v8 = 0;
result = putchar(9);
goto LABEL_9;
}
v5 = (char)*v4;
LABEL_4:
for ( i = 0LL; ; v5 = (char)v4[i] )
{
putchar(v5);
v7 = *(_QWORD *)(a2 + 8);
if ( v7 <= ++i )
break;
}
if ( v7 > 7 )
goto LABEL_8;
goto LABEL_23;
}
v5 = (char)*v4;
if ( *v4 != 64 )
goto LABEL_4;
v8 = 1;
result = printf("@\t");
LABEL_9:
v10 = *(_QWORD *)(a2 + 16);
if ( v10 )
{
v11 = *(const char **)v10;
v12 = strchr(*(const char **)v10, 32);
*v12 = 0;
v13 = v12 + 1;
if ( strcmp(s1, v11) )
goto LABEL_17;
while ( 1 )
{
putchar(9);
if ( v8 )
{
printf("IN\t%s\t", v13);
if ( !strcmp(v13, "SOA") )
{
result = func3((__int64 *)(v10 + 16));
v10 = *(_QWORD *)(v10 + 32);
if ( !v10 )
return result;
goto LABEL_16;
}
}
else
{
printf("%s\t", v13);
}
v14 = 0LL;
v15 = *(_QWORD *)(v10 + 16);
while ( *(_QWORD *)(v10 + 24) > v14 )
{
v16 = *(char *)(v15 + v14++);
putchar(v16);
}
result = putchar(10);
v10 = *(_QWORD *)(v10 + 32);
if ( !v10 )
return result;
LABEL_16:
v11 = *(const char **)v10;
v8 = 0;
v17 = strchr(*(const char **)v10, 32);
*v17 = 0;
v13 = v17 + 1;
printf("\t\t");
if ( strcmp(s1, v11) )
LABEL_17:
printf("%s", v11);
}
}
return result;
}

original_code:
void printrrs(char *defaultttl, struct assstack_entry *item) {
    struct assstack_entry *stack;
    char *s;
    int first;
    size_t i;
    char *ttl, *type;
    int top;
    s = (char *)item->key.data;
    if (item->key.len == 1 && *s == '@') {
 top = 1;
 printf("@\t");
    } else {
 top = 0;
 for (i = 0; i < item->key.len; i++)
     putchar(s[i]);
 if (item->key.len < 8)
     putchar('\t');
 putchar('\t');
    }
    first = 1;
    for (stack = (struct assstack_entry *) item->val.data; stack; stack = stack->next) {
 ttl = (char *)stack->key.data;
 s = strchr(ttl, ' ');
 *s++ = '\0';
 type = s;
 if (first)
     first = 0;
        else
     printf("\t\t");
 if (strcmp(defaultttl, ttl))
     printf("%s", ttl);
 putchar('\t');
 if (top) {
     top = 0;
     printf("IN\t%s\t", type);
     if (!strcmp(type, "SOA")) {
  printsoa(&stack->val);
  continue;
     }
 } else
     printf("%s\t", type);
 s = (char *)stack->val.data;
 for (i = 0; i < stack->val.len; i++)
     putchar(s[i]);
 putchar('\n');
    }
}

canonical_original_code:
void printrrs(char *defaultttl, struct assstack_entry *item) {
    struct assstack_entry *stack;
    char *s;
    int first;
    unsigned long i;
    char *ttl; char *type;
    int top;
    s = (char *)item->key.data;
    if (item->key.len == 1 && *s == '@') {
 top = 1;
 printf("@\t");
    } else {
 top = 0;
 for (i = 0; i < item->key.len; i++)
     putchar(s[i]);
 if (item->key.len < 8)
     putchar('\t');
 putchar('\t');
    }
    first = 1;
    for (stack = (struct assstack_entry *) item->val.data; stack; stack = stack->next) {
 ttl = (char *)stack->key.data;
 s = strchr(ttl, ' ');
 *s++ = '\0';
 type = s;
 if (first)
     first = 0;
        else
     printf("\t\t");
 if (strcmp(defaultttl, ttl))
     printf("%s", ttl);
 putchar('\t');
 if (top) {
     top = 0;
     printf("IN\t%s\t", type);
     if (!strcmp(type, "SOA")) {
  printsoa(&stack->val);
  continue;
     }
 } else
     printf("%s\t", type);
 s = (char *)stack->val.data;
 for (i = 0; i < stack->val.len; i++)
     putchar(s[i]);
 putchar('\n');
    }
}

variable_types:
defaultttl
char *

variable_types: struct assstack_entry { struct string { void *data; unsigned long len; } key; struct string val; struct assstack_entry *next; } *

variable_types: first int

variable_types:
ttl
char *

variable_types:
type
char *

variable_types: top int


decompiled_code:
int __fastcall print_zone(char *s1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax

v2 = a2;
for ( result = printf("$TTL %s\n", s1); v2; v2 = *(_QWORD *)(v2 + 32) )
result = printrrs(s1, v2);
return result;
}

canonical_decompiled_code:
int __fastcall func5(char *s1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax

v2 = a2;
for ( result = printf("$TTL %s\n", s1); v2; v2 = *(_QWORD *)(v2 + 32) )
result = func4(s1, v2);
return result;
}

original_code:
void print_zone(char *defaultttl, struct assstack_entry *stack) {
    printf("$TTL %s\n", defaultttl);
    for (; stack; stack = stack->next)
 printrrs(defaultttl, stack);
}

user_defined_types: struct string { void *data; unsigned long len; }


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(
stderr,
"Usage: %s [-D BIND DN] [-w BIND PASSWORD] \n <ZONE NAME> <LDAP-URL> <DEFAULT TTL> [SERIAL]\n",
a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func6(const char *a1)
{
fprintf(
stderr,
"Usage: %s [-D BIND DN] [-w BIND PASSWORD] \n <ZONE NAME> <LDAP-URL> <DEFAULT TTL> [SERIAL]\n",
a1);
exit(1);
}

original_code:
void usage(char *name) {
    fprintf(stderr, "Usage: %s "
     "[-D BIND DN] [-w BIND PASSWORD] "
     "\n"
     "       <ZONE NAME> <LDAP-URL> <DEFAULT TTL> [SERIAL]\n", name);
    exit(1);
}

variable_types:
name
char *


err

decompiled_code:
void __fastcall __noreturn err(const char *a1, const char *a2)
{
fprintf(stderr, "%s: %s\n", a1, a2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1, const char *a2)
{
fprintf(stderr, "%s: %s\n", a1, a2);
exit(1);
}

original_code:
void err(char *name, const char *msg) {
    fprintf(stderr, "%s: %s\n", name, msg);
    exit(1);
}

canonical_original_code:
void err(char *name, char *msg) {
    fprintf(stderr, "%s: %s\n", name, msg);
    exit(1);
}

variable_types:
msg
char *