decompiled_code:
int __fastcall cfg_get_int(char *a1, char *a2, int a3)
{
int result; // eax
int v5[18]; // [rsp+0h] [rbp-48h] BYREF

cfg_get_string(a1, a2, (char *)v5, 64, "xxx");
result = a3;
if ( v5[0] != 7895160 )
result = atoi((const char *)v5);
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *a1, char *a2, int a3)
{
int result; // eax
int v5[18]; // [rsp+0h] [rbp-48h] BYREF

func2(a1, a2, (char *)v5, 64, "xxx");
result = a3;
if ( v5[0] != 7895160 )
result = atoi((const char *)v5);
return result;
}

original_code:
int cfg_get_int(cfg_t *cfg, const char *name, int default_value) {
 char buf[64];
 cfg_get_string(cfg, name, buf, sizeof(buf), "xxx");
 if(!strcmp(buf, "xxx")) {
  return(default_value);
 }
 return(atoi(buf));
}

canonical_original_code:
int cfg_get_int(struct cfg_t *cfg, char *name, int default_value) {
 char buf[64];
 cfg_get_string(cfg, name, buf, sizeof(buf), "xxx");
 if(!strcmp(buf, "xxx")) {
  return(default_value);
 }
 return(atoi(buf));
}

variable_types:
name
char *

variable_types:
buf
char [64]

user_defined_types: enum cfg_option_which_t { STRING=0, INTEGER=1, FLOAT=2, FLOAT3=3 }


repo: kgamiel/seewaves

decompiled_code:
float __fastcall cfg_get_float(char *a1, char *a2, __m128i a3)
{
float result; // xmm0_4
int v4[18]; // [rsp+0h] [rbp-48h] BYREF

cfg_get_string(a1, a2, (char *)v4, 64, "xxx");
result = COERCE_FLOAT(_mm_cvtsi128_si32(a3));
if ( v4[0] != 7895160 )
result = atof((const char *)v4);
return result;
}

canonical_decompiled_code:
float __fastcall func4(char *a1, char *a2, __m128i a3)
{
float result; // xmm0_4
int v4[18]; // [rsp+0h] [rbp-48h] BYREF

func2(a1, a2, (char *)v4, 64, "xxx");
result = COERCE_FLOAT(_mm_cvtsi128_si32(a3));
if ( v4[0] != 7895160 )
result = atof((const char *)v4);
return result;
}

original_code:
float cfg_get_float(cfg_t *cfg, const char *name, float default_value) {
 char buf[64];
 cfg_get_string(cfg, name, buf, sizeof(buf), "xxx");
 if(!strcmp(buf, "xxx")) {
  return(default_value);
 }
 return(atof(buf));
}

canonical_original_code:
float cfg_get_float(struct cfg_t *cfg, char *name, float default_value) {
 char buf[64];
 cfg_get_string(cfg, name, buf, sizeof(buf), "xxx");
 if(!strcmp(buf, "xxx")) {
  return(default_value);
 }
 return(atof(buf));
}

variable_types: struct cfg_t { char filename[4096]; struct cfg_option_t { char *name; char *description; enum cfg_option_which_t { STRING=0, INTEGER=1, FLOAT=2, FLOAT3=3 } which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; } *options; } *

return_type: float

user_defined_types: struct cfg_t { char filename[4096]; struct cfg_option_t *options; }

user_defined_types: struct cfg_option_t { char *name; char *description; enum cfg_option_which_t which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; }


decompiled_code:
const char **__fastcall cfg_get(__int64 a1, const char *a2)
{
const char **v3; // r12
const char *v4; // rsi

if ( !a2 || !*a2 )
_assert_fail("name != NULL && *name != '\\0'", "cfg.c", 0x91u, "cfg_get");
v3 = *(const char ***)(a1 + 4096);
v4 = *v3;
if ( !*v3 )
return 0LL;
while ( strcmp(a2, v4) )
{
v4 = v3[69];
v3 += 69;
if ( !v4 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
const char **__fastcall func5(__int64 a1, const char *a2)
{
const char **v3; // r12
const char *v4; // rsi

if ( !a2 || !*a2 )
_assert_fail("name != NULL && *name != '\\0'", "cfg.c", 0x91u, "cfg_get");
v3 = *(const char ***)(a1 + 4096);
v4 = *v3;
if ( !*v3 )
return 0LL;
while ( strcmp(a2, v4) )
{
v4 = v3[69];
v3 += 69;
if ( !v4 )
return 0LL;
}
return v3;
}

original_code:
cfg_option_t *cfg_get(cfg_t *cfg, const char *name) {
 cfg_option_t *option;
 int i;
 ((name != ((void *)0) && *name != '\0') ? (void) (0) : __assert_fail ("name != NULL && *name != '\\0'", "cfg.c", 145, __extension__ __PRETTY_FUNCTION__));
 for( i = 0; ; i++) {
  option = &(cfg->options[i]);
  if(option->name == ((void *)0)) {
   break;
  }
  if(!strcmp(name, option->name)) {
   return(option);
  }
 }
 return ((void *)0);
}

canonical_original_code:
struct cfg_option_t *cfg_get(struct cfg_t *cfg, char *name) {
 struct cfg_option_t *option;
 int i;
 ((name != ((void *)0) && *name != '\0') ? (void) (0) : __assert_fail ("name != NULL && *name != '\\0'", "cfg.c", 145, __extension__ __PRETTY_FUNCTION__));
 for( i = 0; ; i++) {
  option = &(cfg->options[i]);
  if(option->name == ((void *)0)) {
   break;
  }
  if(!strcmp(name, option->name)) {
   return(option);
  }
 }
 return ((void *)0);
}

variable_types: struct cfg_t { char filename[4096]; struct cfg_option_t *options; } *

variable_types: struct cfg_option_t { char *name; char *description; enum cfg_option_which_t { STRING=0, INTEGER=1, FLOAT=2, FLOAT3=3 } which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; } *

variable_types: i int


decompiled_code:
const char **__fastcall cfg_set_int(__int64 a1, const char *a2, int a3)
{
const char **result; // rax

result = cfg_get(a1, a2);
if ( result )
{
if ( *((_DWORD *)result + 4) == 1 )
*((_DWORD *)result + 5) = a3;
}
return result;
}

canonical_decompiled_code:
const char **__fastcall func6(__int64 a1, const char *a2, int a3)
{
const char **result; // rax

result = func5(a1, a2);
if ( result )
{
if ( *((_DWORD *)result + 4) == 1 )
*((_DWORD *)result + 5) = a3;
}
return result;
}

original_code:
void cfg_set_int(cfg_t *cfg, char *name, int value) {
 cfg_option_t *option = cfg_get(cfg, name);
 if(option && option->which == INTEGER) {
  option->u.ival = value;
 }
}

canonical_original_code:
void cfg_set_int(struct cfg_t *cfg, char *name, int value) {
 struct cfg_option_t *option = cfg_get(cfg, name);
 if(option && option->which == INTEGER) {
  option->u.ival = value;
 }
}

variable_types: value int

return_type: void


decompiled_code:
__int64 cfg_close()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
return 0LL;
}

original_code:
cfg_error_t cfg_close(cfg_t *cfg) {
 (void)cfg;
 return(CFG_OK);
}

canonical_original_code:
enum cfg_error_t cfg_close(struct cfg_t *cfg) {
 (void)cfg;
 return(CFG_OK);
}

return_type: enum cfg_error_t { CFG_OK=0, CFG_ERROR=1 }


decompiled_code:
__m128i __fastcall Vector_withValues(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

canonical_decompiled_code:
__m128i __fastcall func0(float a1, float a2)
{
__m128i v3; // [rsp+0h] [rbp-14h] BYREF

v3.m128i_i64[0] = __PAIR64__(LODWORD(a2), LODWORD(a1));
return _mm_loadl_epi64(&v3);
}

original_code:
Vector Vector_withValues(float x, float y, float z) {
 Vector vector;
 vector.x = x;
 vector.y = y;
 vector.z = z;
 return vector;
}

canonical_original_code:
struct Vector Vector_withValues(float x, float y, float z) {
 struct Vector vector;
 vector.x = x;
 vector.y = y;
 vector.z = z;
 return vector;
}

variable_types: x float

variable_types: y float

variable_types: z float

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


original_code:
void Vector_normalize(Vector * vector) {
 float magnitude;
 magnitude = sqrt((vector->x * vector->x) + (vector->y * vector->y) + (vector->z * vector->z));
 vector->x /= magnitude;
 vector->y /= magnitude;
 vector->z /= magnitude;
}

canonical_original_code:
void Vector_normalize(struct Vector *vector) {
 float magnitude;
 magnitude = sqrt((vector->x * vector->x) + (vector->y * vector->y) + (vector->z * vector->z));
 vector->x /= magnitude;
 vector->y /= magnitude;
 vector->z /= magnitude;
}

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

variable_types: magnitude float


decompiled_code:
__int64 __fastcall Vector_normalized(double a1, float a2)
{
double v3; // [rsp+10h] [rbp-28h] BYREF
unsigned int v4; // [rsp+18h] [rbp-20h]

v3 = a1;
v4 = LODWORD(a2);
Vector_normalize((float *)&v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(double a1, float a2)
{
double v3; // [rsp+10h] [rbp-28h] BYREF
unsigned int v4; // [rsp+18h] [rbp-20h]

v3 = a1;
v4 = LODWORD(a2);
func1((float *)&v3);
return v4;
}

original_code:
Vector Vector_normalized(Vector vector) {
 Vector_normalize(&vector);
 return vector;
}

canonical_original_code:
struct Vector Vector_normalized(struct Vector vector) {
 Vector_normalize(&vector);
 return vector;
}

variable_types:
vector
struct Vector

return_type: struct Vector { float x; float y; float z; }


decompiled_code:
void __fastcall Vector_magnitude(double a1, float a2)
{
float v2; // xmm0_4

v2 = (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
if ( v2 < 0.0 )
sqrtf(v2);
}

canonical_decompiled_code:
void __fastcall func3(double a1, float a2)
{
float v2; // xmm0_4

v2 = (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
if ( v2 < 0.0 )
sqrtf(v2);
}

original_code:
float Vector_magnitude(Vector vector) {
 return sqrt((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
}

canonical_original_code:
float Vector_magnitude(struct Vector vector) {
 return sqrt((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
}

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


decompiled_code:
float __fastcall Vector_magnitudeSquared(double a1, float a2)
{
return (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
}

canonical_decompiled_code:
float __fastcall func4(double a1, float a2)
{
return (float)((float)(*(float *)&a1 * *(float *)&a1) + (float)(*((float *)&a1 + 1) * *((float *)&a1 + 1)))
+ (float)(a2 * a2);
}

original_code:
float Vector_magnitudeSquared(Vector vector) {
 return ((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
}

canonical_original_code:
float Vector_magnitudeSquared(struct Vector vector) {
 return ((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
}


decompiled_code:
__m128i __fastcall Vector_add(double a1, double a2, double a3)
{
return Vector_withValues(*(float *)&a1 + *(float *)&a3, *((float *)&a1 + 1) + *((float *)&a3 + 1));
}

canonical_decompiled_code:
__m128i __fastcall func5(double a1, double a2, double a3)
{
return func0(*(float *)&a1 + *(float *)&a3, *((float *)&a1 + 1) + *((float *)&a3 + 1));
}

original_code:
Vector Vector_add(Vector vector1, Vector vector2) {
 return Vector_withValues((vector1.x + vector2.x), (vector1.y + vector2.y), (vector1.z + vector2.z));
}

canonical_original_code:
struct Vector Vector_add(struct Vector vector1, struct Vector vector2) {
 return Vector_withValues((vector1.x + vector2.x), (vector1.y + vector2.y), (vector1.z + vector2.z));
}


decompiled_code:
__m128i __fastcall Vector_subtract(double a1, double a2, double a3)
{
return Vector_withValues(*(float *)&a1 - *(float *)&a3, *((float *)&a1 + 1) - *((float *)&a3 + 1));
}

canonical_decompiled_code:
__m128i __fastcall func6(double a1, double a2, double a3)
{
return func0(*(float *)&a1 - *(float *)&a3, *((float *)&a1 + 1) - *((float *)&a3 + 1));
}

original_code:
Vector Vector_subtract(Vector vector1, Vector vector2) {
 return Vector_withValues((vector1.x - vector2.x), (vector1.y - vector2.y), (vector1.z - vector2.z));
}

canonical_original_code:
struct Vector Vector_subtract(struct Vector vector1, struct Vector vector2) {
 return Vector_withValues((vector1.x - vector2.x), (vector1.y - vector2.y), (vector1.z - vector2.z));
}


decompiled_code:
float __fastcall Vector_dot(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

canonical_decompiled_code:
float __fastcall func7(double a1, float a2, double a3, float a4)
{
return (float)((float)(*(float *)&a1 * *(float *)&a3) + (float)(*((float *)&a1 + 1) * *((float *)&a3 + 1)))
+ (float)(a2 * a4);
}

original_code:
float Vector_dot(Vector vector1, Vector vector2) {
 return ((vector1.x * vector2.x) + (vector1.y * vector2.y) + (vector1.z * vector2.z));
}

canonical_original_code:
float Vector_dot(struct Vector vector1, struct Vector vector2) {
 return ((vector1.x * vector2.x) + (vector1.y * vector2.y) + (vector1.z * vector2.z));
}


decompiled_code:
__m128i __fastcall Vector_cross(double a1, float a2, double a3, float a4)
{
__m128i v5; // [rsp+24h] [rbp-14h] BYREF

*(float *)&v5.m128i_i32[1] = (float)(a2 * *(float *)&a3) - (float)(a4 * *(float *)&a1);
*(float *)v5.m128i_i32 = (float)(*((float *)&a1 + 1) * a4) - (float)(a2 * *((float *)&a3 + 1));
return _mm_loadl_epi64(&v5);
}

canonical_decompiled_code:
__m128i __fastcall func8(double a1, float a2, double a3, float a4)
{
__m128i v5; // [rsp+24h] [rbp-14h] BYREF

*(float *)&v5.m128i_i32[1] = (float)(a2 * *(float *)&a3) - (float)(a4 * *(float *)&a1);
*(float *)v5.m128i_i32 = (float)(*((float *)&a1 + 1) * a4) - (float)(a2 * *((float *)&a3 + 1));
return _mm_loadl_epi64(&v5);
}

original_code:
Vector Vector_cross(Vector vector1, Vector vector2) {
 Vector result;
 result.x = ((vector1.y * vector2.z) - (vector1.z * vector2.y));
 result.y = ((vector1.z * vector2.x) - (vector1.x * vector2.z));
 result.z = ((vector1.x * vector2.y) - (vector1.y * vector2.x));
 return result;
}

canonical_original_code:
struct Vector Vector_cross(struct Vector vector1, struct Vector vector2) {
 struct Vector result;
 result.x = ((vector1.y * vector2.z) - (vector1.z * vector2.y));
 result.y = ((vector1.z * vector2.x) - (vector1.x * vector2.z));
 result.z = ((vector1.x * vector2.y) - (vector1.y * vector2.x));
 return result;
}


decompiled_code:
void __fastcall arcball_set_bounds(float *a1, float a2, float a3)
{
*a1 = 1.0 / (float)((float)(a2 - 1.0) * 0.5);
a1[1] = 1.0 / (float)((float)(a3 - 1.0) * 0.5);
}

original_code:
void arcball_set_bounds(arcball_t *a, float width, float height) {
 a->adjust_width = 1.0f / ((width - 1.0f) * 0.5f);
 a->adjust_height = 1.0f / ((height - 1.0f) * 0.5f);
}

canonical_original_code:
void arcball_set_bounds(struct arcball_t *a, float width, float height) {
 a->adjust_width = 1.0f / ((width - 1.0f) * 0.5f);
 a->adjust_height = 1.0f / ((height - 1.0f) * 0.5f);
}

variable_types: struct arcball_t { float adjust_width; float adjust_height; struct Vector { float x; float y; float z; } saved_click_vector; struct Vector saved_drag_vector; } *

variable_types: width float

variable_types: height float

user_defined_types: struct arcball_t { float adjust_width; float adjust_height; struct Vector saved_click_vector; struct Vector saved_drag_vector; }


decompiled_code:
void __fastcall arcball_init(float *a1, float a2, float a3)
{
*(_OWORD *)a1 = 0LL;
*((_OWORD *)a1 + 1) = 0LL;
arcball_set_bounds(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func2(float *a1, float a2, float a3)
{
*(_OWORD *)a1 = 0LL;
*((_OWORD *)a1 + 1) = 0LL;
func1(a1, a2, a3);
}

original_code:
void arcball_init(arcball_t *a, float width, float height) {
 memset(a, 0, sizeof(arcball_t));
 arcball_set_bounds(a, width, height);
}

canonical_original_code:
void arcball_init(struct arcball_t *a, float width, float height) {
 memset(a, 0, sizeof(arcball_t));
 arcball_set_bounds(a, width, height);
}


decompiled_code:
void __fastcall arcball_click(float *a1, float a2, float a3)
{
arcball_map_to_sphere_isra_0(a1 + 2, *a1, a1[1], a2, a3);
}

canonical_decompiled_code:
void __fastcall func3(float *a1, float a2, float a3)
{
func0(a1 + 2, *a1, a1[1], a2, a3);
}

original_code:
void arcball_click(arcball_t *a, float x, float y) {
 arcball_map_to_sphere(a, x, y, &a->saved_click_vector);
}

canonical_original_code:
void arcball_click(struct arcball_t *a, float x, float y) {
 arcball_map_to_sphere(a, x, y, &a->saved_click_vector);
}


original_code:
void arcball_drag(arcball_t *a, float x, float y, Quaternion *new_rotation) {
 arcball_map_to_sphere(a, x, y, &a->saved_drag_vector);
 if(!new_rotation) {
  return;
 }
 Vector perpendicular = Vector_cross(a->saved_click_vector, a->saved_drag_vector);
 if(Vector_magnitude(perpendicular) > 1.0e-5) {
  new_rotation->x = perpendicular.x;
  new_rotation->y = perpendicular.y;
  new_rotation->z = perpendicular.z;
  new_rotation->w = Vector_dot(a->saved_click_vector, a->saved_drag_vector);
 } else {
  new_rotation->x = 0.0f;
  new_rotation->y = 0.0f;
  new_rotation->z = 0.0f;
  new_rotation->w = 0.0f;
 }
}

canonical_original_code:
void arcball_drag(struct arcball_t *a, float x, float y, struct Quaternion *new_rotation) {
 arcball_map_to_sphere(a, x, y, &a->saved_drag_vector);
 if(!new_rotation) {
  return;
 }
 struct Vector perpendicular = Vector_cross(a->saved_click_vector, a->saved_drag_vector);
 if(Vector_magnitude(perpendicular) > 1.0e-5) {
  new_rotation->x = perpendicular.x;
  new_rotation->y = perpendicular.y;
  new_rotation->z = perpendicular.z;
  new_rotation->w = Vector_dot(a->saved_click_vector, a->saved_drag_vector);
 } else {
  new_rotation->x = 0.0f;
  new_rotation->y = 0.0f;
  new_rotation->z = 0.0f;
  new_rotation->w = 0.0f;
 }
}

variable_types: struct Quaternion { float x; float y; float z; float w; } *


decompiled_code:
__int64 __fastcall heartbeat_thread_main(__int64 a1)
{
int v2; // eax
__int64 v3; // rdx
int v4; // eax
struct addrinfo *v5; // rdi
struct addrinfo *v6; // rax
socklen_t v7; // er12
char *v8; // rsi
int v9; // eax
int v10; // ebp
ssize_t v11; // rax
const char *v13; // rax
int v14; // [rsp+4h] [rbp-D4h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-D0h] BYREF
time_t timer; // [rsp+10h] [rbp-C8h] BYREF
time_t time0; // [rsp+18h] [rbp-C0h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-B8h] BYREF
char s[16]; // [rsp+30h] [rbp-A8h] BYREF
struct addrinfo req; // [rsp+40h] [rbp-98h] BYREF
char buf[104]; // [rsp+70h] [rbp-68h] BYREF

v2 = socket(2, 2, 17);
*(_DWORD *)(a1 + 4120) = v2;
if ( v2 == -1 )
{
perror("socket");
pthread_exit(0LL);
}
fcntl(v2, 4, 2048LL);
v3 = *(unsigned __int16 *)(a1 + 4350);
*(_OWORD *)&req.ai_flags = 0LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
sprintf(s, "%i", v3);
v4 = getaddrinfo((const char *)(a1 + 4304), s, &req, &pai);
if ( v4 )
{
v13 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo() failed: %s", v13);
close(*(_DWORD *)(a1 + 4120));
pthread_exit(0LL);
}
v5 = pai;
if ( pai )
{
v6 = pai;
while ( v6->ai_family != 2 )
{
v6 = v6->ai_next;
if ( !v6 )
goto LABEL_8;
}
v7 = v6->ai_addrlen;
v8 = &v6->ai_addr->sa_data[2];
addr = (struct sockaddr)_mm_loadu_si128((const __m128i *)v6->ai_addr);
inet_ntop(v6->ai_family, v8, (char *)(a1 + 4304), 0x2Eu);
v5 = pai;
}
else
{
LABEL_8:
v7 = 16;
}
freeaddrinfo(v5);
v14 = 0;
time0 = 0LL;
do
{
v10 = 0;
time(&timer);
if ( difftime(timer, time0) > 1.0 )
{
v11 = sendto(*(_DWORD *)(a1 + 4120), &v14, 4uLL, 0, &addr, v7);
if ( v11 == -1 )
{
v10 = 0;
if ( *_errno_location() != 9 )
perror("sendto()");
}
else
{
v10 = 1;
if ( v11 )
{
++*(_DWORD *)(a1 + 4124);
v10 = 0;
}
}
time(&time0);
}
if ( !recvfrom(*(_DWORD *)(a1 + 4120), buf, 0x40uLL, 0, 0LL, 0LL) )
break;
v9 = *_errno_location();
if ( v9 != 4 && v9 != 11 )
{
if ( v9 == 9 )
break;
if ( v9 != 110 )
{
perror("heartbeat recvfrom");
break;
}
}
}
while ( !v10 );
if ( *(_DWORD *)(a1 + 4104) )
{
fwrite("Heartbeat thread exiting\n", 1uLL, 0x19uLL, stdout);
fflush(stdout);
}
close(*(_DWORD *)(a1 + 4120));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
int v2; // eax
__int64 v3; // rdx
int v4; // eax
struct addrinfo *v5; // rdi
struct addrinfo *v6; // rax
socklen_t v7; // er12
char *v8; // rsi
int v9; // eax
int v10; // ebp
ssize_t v11; // rax
const char *v13; // rax
int v14; // [rsp+4h] [rbp-D4h] BYREF
struct addrinfo *pai; // [rsp+8h] [rbp-D0h] BYREF
time_t timer; // [rsp+10h] [rbp-C8h] BYREF
time_t time0; // [rsp+18h] [rbp-C0h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-B8h] BYREF
char s[16]; // [rsp+30h] [rbp-A8h] BYREF
struct addrinfo req; // [rsp+40h] [rbp-98h] BYREF
char buf[104]; // [rsp+70h] [rbp-68h] BYREF

v2 = socket(2, 2, 17);
*(_DWORD *)(a1 + 4120) = v2;
if ( v2 == -1 )
{
perror("socket");
pthread_exit(0LL);
}
fcntl(v2, 4, 2048LL);
v3 = *(unsigned __int16 *)(a1 + 4350);
*(_OWORD *)&req.ai_flags = 0LL;
req.ai_socktype = 2;
*(_OWORD *)&req.ai_addrlen = 0LL;
*(_OWORD *)&req.ai_canonname = 0LL;
sprintf(s, "%i", v3);
v4 = getaddrinfo((const char *)(a1 + 4304), s, &req, &pai);
if ( v4 )
{
v13 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo() failed: %s", v13);
close(*(_DWORD *)(a1 + 4120));
pthread_exit(0LL);
}
v5 = pai;
if ( pai )
{
v6 = pai;
while ( v6->ai_family != 2 )
{
v6 = v6->ai_next;
if ( !v6 )
goto LABEL_8;
}
v7 = v6->ai_addrlen;
v8 = &v6->ai_addr->sa_data[2];
addr = (struct sockaddr)_mm_loadu_si128((const __m128i *)v6->ai_addr);
inet_ntop(v6->ai_family, v8, (char *)(a1 + 4304), 0x2Eu);
v5 = pai;
}
else
{
LABEL_8:
v7 = 16;
}
freeaddrinfo(v5);
v14 = 0;
time0 = 0LL;
do
{
v10 = 0;
time(&timer);
if ( difftime(timer, time0) > 1.0 )
{
v11 = sendto(*(_DWORD *)(a1 + 4120), &v14, 4uLL, 0, &addr, v7);
if ( v11 == -1 )
{
v10 = 0;
if ( *_errno_location() != 9 )
perror("sendto()");
}
else
{
v10 = 1;
if ( v11 )
{
++*(_DWORD *)(a1 + 4124);
v10 = 0;
}
}
time(&time0);
}
if ( !recvfrom(*(_DWORD *)(a1 + 4120), buf, 0x40uLL, 0, 0LL, 0LL) )
break;
v9 = *_errno_location();
if ( v9 != 4 && v9 != 11 )
{
if ( v9 == 9 )
break;
if ( v9 != 110 )
{
perror("heartbeat recvfrom");
break;
}
}
}
while ( !v10 );
if ( *(_DWORD *)(a1 + 4104) )
{
fwrite("Heartbeat thread exiting\n", 1uLL, 0x19uLL, stdout);
fflush(stdout);
}
close(*(_DWORD *)(a1 + 4120));
return 0LL;
}

original_code:
void *heartbeat_thread_main(void *seewaves_data) {
    struct sockaddr_in heartbeat_socket_remote_address;
    socklen_t heartbeat_socket_remote_address_len = sizeof(
                heartbeat_socket_remote_address);
    struct addrinfo address_hints;
    struct addrinfo *address_p;
    struct addrinfo *server_address_info;
    char port_as_string[16];
    long err;
    ptp_heartbeat_packet_t hb;
    time_t now;
    time_t last_heartbeat_sent;
    int done = 0;
    seewaves_t *sw = (seewaves_t*)seewaves_data;
    if ((sw->heartbeat_socket_fd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) ==
        -1) {
        perror("socket");
        pthread_exit(((void *)0));
    }
    fcntl(sw->heartbeat_socket_fd, 4, 04000);
    memset(&address_hints, 0, sizeof address_hints);
    address_hints.ai_family = 0;
    address_hints.ai_socktype = SOCK_DGRAM;
    sprintf(port_as_string, "%i", sw->gpusph_port);
    if ((err = getaddrinfo(sw->gpusph_host, port_as_string,
        &address_hints, &server_address_info))) {
        fprintf(stderr, "getaddrinfo() failed: %s", gai_strerror((int)err));
        close(sw->heartbeat_socket_fd);
        pthread_exit(((void *)0));
    }
    for (address_p = server_address_info; address_p != ((void *)0);
        address_p = address_p->ai_next) {
        void *addr;
        if (address_p->ai_family == 2) {
            struct sockaddr_in *ipv4 = (struct sockaddr_in *)address_p->ai_addr;
            addr = &(ipv4->sin_addr);
            memcpy(&heartbeat_socket_remote_address, address_p->ai_addr,
                (size_t)heartbeat_socket_remote_address_len);
            heartbeat_socket_remote_address_len = address_p->ai_addrlen;
            inet_ntop(address_p->ai_family, addr, sw->gpusph_host,
                sizeof(sw->gpusph_host));
            break;
        } else {
            struct sockaddr_in6 *ipv6 =
                (struct sockaddr_in6 *)address_p->ai_addr;
            addr = &(ipv6->sin6_addr);
        }
    }
    freeaddrinfo(server_address_info);
    memset(&hb, 0, sizeof(ptp_heartbeat_packet_t));
    last_heartbeat_sent = 0;
    while(!done) {
        unsigned char b[64];
        time(&now);
        if (difftime(now, last_heartbeat_sent) > 1) {
            ssize_t bytes_sent;
            bytes_sent = sendto(sw->heartbeat_socket_fd, &hb,
                sizeof(ptp_heartbeat_packet_t), 0,
                (const struct sockaddr *)(&heartbeat_socket_remote_address),
                heartbeat_socket_remote_address_len);
            if (bytes_sent == -1) {
                if ((*__errno_location ()) != 9) {
                    perror("sendto()");
                }
            } else if(bytes_sent == 0) {
                done = 1;
            } else {
                sw->heartbeats_sent++;
            }
            time(&last_heartbeat_sent);
        }
        err = recvfrom(sw->heartbeat_socket_fd, &b, sizeof(b), 0, ((void *)0), ((void *)0));
        if (err == 0) {
            done = 1;
        } else {
            if((*__errno_location ()) == 11) {
            } else if((*__errno_location ()) == 4) {
            } else if ((*__errno_location ()) == 9) {
                done = 1;
            } else if ((*__errno_location ()) == 110) {
            } else {
                perror("heartbeat recvfrom");
                done = 1;
            }
        }
    }
    if(sw->verbosity) {
        fprintf(stdout, "Heartbeat thread exiting\n");
        fflush(stdout);
    }
    close(sw->heartbeat_socket_fd);
    return(((void *)0));
}

canonical_original_code:
void *heartbeat_thread_main(void *seewaves_data) {
    struct sockaddr_in heartbeat_socket_remote_address;
    unsigned int heartbeat_socket_remote_address_len = sizeof(
                heartbeat_socket_remote_address);
    struct addrinfo address_hints;
    struct addrinfo *address_p;
    struct addrinfo *server_address_info;
    char port_as_string[16];
    long err;
    struct ptp_heartbeat_packet_t hb;
    long now;
    long last_heartbeat_sent;
    int done = 0;
    struct seewaves_t *sw = (seewaves_t*)seewaves_data;
    if ((sw->heartbeat_socket_fd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) ==
        -1) {
        perror("socket");
        pthread_exit(((void *)0));
    }
    fcntl(sw->heartbeat_socket_fd, 4, 04000);
    memset(&address_hints, 0, sizeof address_hints);
    address_hints.ai_family = 0;
    address_hints.ai_socktype = SOCK_DGRAM;
    sprintf(port_as_string, "%i", sw->gpusph_port);
    if ((err = getaddrinfo(sw->gpusph_host, port_as_string,
        &address_hints, &server_address_info))) {
        fprintf(stderr, "getaddrinfo() failed: %s", gai_strerror((int)err));
        close(sw->heartbeat_socket_fd);
        pthread_exit(((void *)0));
    }
    for (address_p = server_address_info; address_p != ((void *)0);
        address_p = address_p->ai_next) {
        void *addr;
        if (address_p->ai_family == 2) {
            struct sockaddr_in *ipv4 = (struct sockaddr_in *)address_p->ai_addr;
            addr = &(ipv4->sin_addr);
            memcpy(&heartbeat_socket_remote_address, address_p->ai_addr,
                (unsigned long)heartbeat_socket_remote_address_len);
            heartbeat_socket_remote_address_len = address_p->ai_addrlen;
            inet_ntop(address_p->ai_family, addr, sw->gpusph_host,
                sizeof(sw->gpusph_host));
            break;
        } else {
            struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)address_p->ai_addr;
            addr = &(ipv6->sin6_addr);
        }
    }
    freeaddrinfo(server_address_info);
    memset(&hb, 0, sizeof(ptp_heartbeat_packet_t));
    last_heartbeat_sent = 0;
    while(!done) {
        unsigned char b[64];
        time(&now);
        if (difftime(now, last_heartbeat_sent) > 1) {
            long bytes_sent;
            bytes_sent = sendto(sw->heartbeat_socket_fd, &hb,
                sizeof(ptp_heartbeat_packet_t), 0,
                (struct sockaddr *)(&heartbeat_socket_remote_address),
                heartbeat_socket_remote_address_len);
            if (bytes_sent == -1) {
                if ((*__errno_location ()) != 9) {
                    perror("sendto()");
                }
            } else if(bytes_sent == 0) {
                done = 1;
            } else {
                sw->heartbeats_sent++;
            }
            time(&last_heartbeat_sent);
        }
        err = recvfrom(sw->heartbeat_socket_fd, &b, sizeof(b), 0, ((void *)0), ((void *)0));
        if (err == 0) {
            done = 1;
        } else {
            if((*__errno_location ()) == 11) {
            } else if((*__errno_location ()) == 4) {
            } else if ((*__errno_location ()) == 9) {
                done = 1;
            } else if ((*__errno_location ()) == 110) {
            } else {
                perror("heartbeat recvfrom");
                done = 1;
            }
        }
    }
    if(sw->verbosity) {
        fprintf(stdout, "Heartbeat thread exiting\n");
        fflush(stdout);
    }
    close(sw->heartbeat_socket_fd);
    return(((void *)0));
}

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types: err long

variable_types: struct ptp_heartbeat_packet_t { unsigned int count; }

variable_types: now long

variable_types: done int

variable_types: struct seewaves_t { struct cfg_t { char filename[4096]; struct cfg_option_t { char *name; char *description; enum cfg_option_which_t { STRING=0, INTEGER=1, FLOAT=2, FLOAT3=3 } which; union { char sval[512]; int ival; float fval; float f3val[3]; } u; union { char *sval; int ival; float fval; float f3val[3]; } d; } *options; } config; int verbosity; unsigned long heartbeat_thread; int heartbeat_socket_fd; int heartbeats_sent; unsigned long data_thread; int data_socket_fd; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; unsigned int total_particle_count; double *x; double *y; double *z; double *w; short *particle_type; float *t; unsigned int *flag; int packets_received; int flag_exit_main_loop; char data_host[46]; unsigned short data_port; char gpusph_host[46]; unsigned short gpusph_port; int red_bits; int green_bits; int blue_bits; int alpha_bits; int depth_bits; int stencil_bits; int display_mode; float background_color[4]; int window[4]; float most_recent_timestamp; int total_timesteps; int udp_buffer_size; unsigned char view_options; float mouse_x; float mouse_y; int mouse_button; int mouse_button_action; int mouse_wheel_pos; unsigned char key_options; char *fade_text; long fade_start; double fade_duration; float fade_position[3]; float line_width_range[2]; float line_width_step; float point_size_range[2]; float point_size_step; float viewport_toolbar[4]; float viewport_main[4]; float rotation_center[3]; float world_origin[3]; float world_size[3]; int mouse_pressed_at[2]; float model_rotation[3]; float model_pan[3]; struct arcball_t { float adjust_width; float adjust_height; struct Vector { float x; float y; float z; } saved_click_vector; struct Vector saved_drag_vector; } arcball; struct Quaternion { float x; float y; float z; float w; } arcball_rotation; struct Matrix { float m[16]; } arcball_transform; struct Matrix arcball_last_rotation; struct Matrix arcball_this_rotation; short show_help; int model_id; } *

variable_types:
addr
void *

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

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } *

variable_types:
b
unsigned char [64]

return_type: void *

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

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

user_defined_types: struct seewaves_t { struct cfg_t config; int verbosity; unsigned long heartbeat_thread; int heartbeat_socket_fd; int heartbeats_sent; unsigned long data_thread; int data_socket_fd; union pthread_mutex_t lock; unsigned int total_particle_count; double *x; double *y; double *z; double *w; short *particle_type; float *t; unsigned int *flag; int packets_received; int flag_exit_main_loop; char data_host[46]; unsigned short data_port; char gpusph_host[46]; unsigned short gpusph_port; int red_bits; int green_bits; int blue_bits; int alpha_bits; int depth_bits; int stencil_bits; int display_mode; float background_color[4]; int window[4]; float most_recent_timestamp; int total_timesteps; int udp_buffer_size; unsigned char view_options; float mouse_x; float mouse_y; int mouse_button; int mouse_button_action; int mouse_wheel_pos; unsigned char key_options; char *fade_text; long fade_start; double fade_duration; float fade_position[3]; float line_width_range[2]; float line_width_step; float point_size_range[2]; float point_size_step; float viewport_toolbar[4]; float viewport_main[4]; float rotation_center[3]; float world_origin[3]; float world_size[3]; int mouse_pressed_at[2]; float model_rotation[3]; float model_pan[3]; struct arcball_t arcball; struct Quaternion arcball_rotation; struct Matrix arcball_transform; struct Matrix arcball_last_rotation; struct Matrix arcball_this_rotation; short show_help; int model_id; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall util_get_udp_buffer_size(int a1)
{
int v2; // eax
int v3; // ebp
unsigned int optval; // [rsp+8h] [rbp-10h] BYREF
socklen_t optlen[3]; // [rsp+Ch] [rbp-Ch] BYREF

optlen[0] = 4;
if ( a1 != -1 )
{
if ( getsockopt(a1, 1, 8, &optval, optlen) == -1 )
perror("getsockopt(bufsize)");
return optval;
}
v2 = socket(2, 2, 17);
v3 = v2;
if ( v2 != -1 )
{
if ( getsockopt(v2, 1, 8, &optval, optlen) == -1 )
{
perror("getsockopt(bufsize)");
close(v3);
}
return optval;
}
perror("socket");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v2; // eax
int v3; // ebp
unsigned int optval; // [rsp+8h] [rbp-10h] BYREF
socklen_t optlen[3]; // [rsp+Ch] [rbp-Ch] BYREF

optlen[0] = 4;
if ( a1 != -1 )
{
if ( getsockopt(a1, 1, 8, &optval, optlen) == -1 )
perror("getsockopt(bufsize)");
return optval;
}
v2 = socket(2, 2, 17);
v3 = v2;
if ( v2 != -1 )
{
if ( getsockopt(v2, 1, 8, &optval, optlen) == -1 )
{
perror("getsockopt(bufsize)");
close(v3);
}
return optval;
}
perror("socket");
return 0LL;
}

original_code:
int util_get_udp_buffer_size(int sd) {
 int size;
 int len = sizeof(int);
 if(sd == -1) {
  int fd;
  if ((fd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
   perror("socket");
   return(0);
  }
  if (getsockopt(fd, 1, 8, &size, (socklen_t*)&len) == -1) {
   perror("getsockopt(bufsize)");
   close(fd);
  }
  return(size);
 }
 if (getsockopt(sd, 1, 8, &size, (socklen_t*)&len) == -1) {
  perror("getsockopt(bufsize)");
 }
 return(size);
}

canonical_original_code:
int util_get_udp_buffer_size(int sd) {
 int size;
 int len = sizeof(int);
 if(sd == -1) {
  int fd;
  if ((fd = socket(2, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
   perror("socket");
   return(0);
  }
  if (getsockopt(fd, 1, 8, &size, (unsigned int *)&len) == -1) {
   perror("getsockopt(bufsize)");
   close(fd);
  }
  return(size);
 }
 if (getsockopt(sd, 1, 8, &size, (unsigned int *)&len) == -1) {
  perror("getsockopt(bufsize)");
 }
 return(size);
}

variable_types: sd int

variable_types: size int

variable_types: len int

variable_types: fd int

return_type: int


decompiled_code:
size_t __fastcall util_get_current_time_string(char *s, size_t maxsize)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

time(&timer);
v2 = localtime(&timer);
return strftime(s, maxsize, "%m-%d-%Y_%X", v2);
}

canonical_decompiled_code:
size_t __fastcall func1(char *s, size_t maxsize)
{
struct tm *v2; // rax
time_t timer; // [rsp+8h] [rbp-20h] BYREF

time(&timer);
v2 = localtime(&timer);
return strftime(s, maxsize, "%m-%d-%Y_%X", v2);
}

original_code:
void util_get_current_time_string(char *buf, ssize_t max_len) {
 time_t now;
 struct tm * timeinfo;
 time(&now);
 timeinfo = localtime(&now);
 strftime(buf, max_len, "%m-%d-%Y_%X", timeinfo);
}

canonical_original_code:
void util_get_current_time_string(char *buf, long max_len) {
 long now;
 struct tm *timeinfo;
 time(&now);
 timeinfo = localtime(&now);
 strftime(buf, max_len, "%m-%d-%Y_%X", timeinfo);
}

variable_types:
buf
char *

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


makeFileH

repo: kgeorgiou/bmpengine

decompiled_code:
__int64 __fastcall makeFileH(char a1, char a2, __int64 a3)
{
__int64 result; // rax

*(_BYTE *)a3 = a1;
result = 0LL;
*(_BYTE *)(a3 + 1) = a2;
*(_QWORD *)(a3 + 2) = 0LL;
*(_DWORD *)(a3 + 10) = 54;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1, char a2, __int64 a3)
{
__int64 result; // rax

*(_BYTE *)a3 = a1;
result = 0LL;
*(_BYTE *)(a3 + 1) = a2;
*(_QWORD *)(a3 + 2) = 0LL;
*(_DWORD *)(a3 + 10) = 54;
return result;
}

original_code:
int makeFileH(byte t1, byte t2, BITMAPFILEHEADER *ret) {
 ret->bfType1 = t1;
 ret->bfType2 = t2;
 ret->bfSize = 0;
 ret->bfReserved1 = 0;
 ret->bfReserved2 = 0;
 ret->bfOffBits = 54;
 return 0;
}

canonical_original_code:
int makeFileH(unsigned char t1, unsigned char t2, struct BITMAPFILEHEADER *ret) {
 ret->bfType1 = t1;
 ret->bfType2 = t2;
 ret->bfSize = 0;
 ret->bfReserved1 = 0;
 ret->bfReserved2 = 0;
 ret->bfOffBits = 54;
 return 0;
}

variable_types: struct BITMAPFILEHEADER { unsigned char bfType1; unsigned int bfSize; unsigned short bfReserved1; unsigned short bfReserved2; unsigned int bfOffBits; } *


makeInfoH

original_code:
int makeInfoH(dword w, dword h, word bitc, dword comp,
  BITMAPINFOHEADER *ret) {
 ret->biSize = 40;
 ret->biWidth = w;
 ret->biHeight = h;
 ret->biPlanes = 0;
 ret->biBitCount = bitc;
 ret->biCompression = comp;
 ret->biSizeImage = 0;
 ret->biXPelsPerMeter = 0;
 ret->biYPelsPerMeter = 0;
 ret->biClrUsed = 0;
 ret->biClrImportant = 0;
 return 0;
}

canonical_original_code:
int makeInfoH(unsigned int w, unsigned int h, unsigned short bitc, unsigned int comp, struct BITMAPINFOHEADER *ret) {
 ret->biSize = 40;
 ret->biWidth = w;
 ret->biHeight = h;
 ret->biPlanes = 0;
 ret->biBitCount = bitc;
 ret->biCompression = comp;
 ret->biSizeImage = 0;
 ret->biXPelsPerMeter = 0;
 ret->biYPelsPerMeter = 0;
 ret->biClrUsed = 0;
 ret->biClrImportant = 0;
 return 0;
}

variable_types:
w
unsigned int

variable_types:
h
unsigned int

variable_types:
bitc
unsigned short

variable_types:
comp
unsigned int

variable_types: struct BITMAPINFOHEADER { unsigned int biSize; unsigned int biWidth; unsigned int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; unsigned int biXPelsPerMeter; unsigned int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v4; // r13
bool v5; // zf
int v6; // er12
__int64 v7; // r12
const char *v8; // rdi
__int64 v10; // r12
const char *v11; // rdi
__int64 v12; // r12
const char *v13; // rdi
__int64 v14; // r12
const char *v15; // rdi
__int64 v16; // r12
const char *v17; // rdi
__int64 v18; // r12
const char *v19; // rdi

puts("\n######################################################################");
puts(
"# bmpengine Copyright (C) 2012 Kyriakos Georgiou & Athina Paphitou #\n"
"# This program comes with ABSOLUTELY NO WARRANTY. #\n"
"# This is free software, and you are welcome to redistribute it #\n"
"# under certain conditions. #");
puts("######################################################################");
if ( argc <= 1 )
{
v6 = 0;
puts("\nPlease type ./bmpengine --help to see the available options");
}
else
{
v4 = argv[1];
v5 = strcmp(v4, "--help") == 0;
v6 = !v5;
if ( v5 )
{
puts("\n======================================================================");
puts("HELP MENU");
puts("---------");
puts("- List of available options:");
puts("1.To view a picture's metadata please type -list [image(s)]");
puts("2.To flip a picture horizontally please type -hflip [image(s)]");
puts("3.To flip a picture verically please type -vflip [image(s)]");
puts("4.To rotate a picture 90 degrees left please type -left90 [image(s)]");
puts("5.To rotate a picture 90 degrees right please type -right90 [image(s)]");
puts("6.To turn a picture into grayscale please type -gray [image(s)]");
puts("-----------------------------------------------------------------");
puts("- Please note that the correct way to use the program is:");
puts("./bmpengine <option> <image1> <image2> etc.");
puts("- Warning: You have to input ONLY ONE option and AT LEAST ONE image.");
puts("- e.g ./bmpengine -list image1.bmp image2.bmp");
puts("======================================================================");
}
else if ( argc == 2 )
{
v6 = 1;
puts("Error: Give one option and at least one image.\nPlease type ./bmpengine --help to see the available options.");
}
else
{
if ( !strcmp(argv[1], "-list") )
{
v10 = 2LL;
do
{
v11 = argv[v10++];
list(v11);
}
while ( argc > (int)v10 );
}
else if ( !strcmp(v4, "-hflip") )
{
v14 = 2LL;
do
{
v15 = argv[v14++];
hflip(v15);
}
while ( argc > (int)v14 );
}
else if ( !strcmp(v4, "-vflip") )
{
v12 = 2LL;
do
{
v13 = argv[v12++];
vflip(v13);
}
while ( argc > (int)v12 );
}
else if ( !strcmp(v4, "-right90") )
{
v16 = 2LL;
do
{
v17 = argv[v16++];
right90(v17);
}
while ( argc > (int)v16 );
}
else if ( !strcmp(v4, "-left90") )
{
v18 = 2LL;
do
{
v19 = argv[v18++];
left90(v19);
}
while ( argc > (int)v18 );
}
else
{
if ( strcmp(v4, "-gray") )
{
v6 = 1;
puts("Error: Invalid command given.\nPlease type ./bmpengine --help to see the available options.");
return v6;
}
v7 = 2LL;
do
{
v8 = argv[v7++];
gray(v8);
}
while ( argc > (int)v7 );
}
v6 = 0;
}
}
return v6;
}

original_code:
int main(int argc, char *argv[]) {
 int i = 0;
 printf(
   "\n######################################################################\n");
 printf(
   "# bmpengine  Copyright (C) 2012  Kyriakos Georgiou & Athina Paphitou #\n"
   "# This program comes with ABSOLUTELY NO WARRANTY.                    #\n"
   "# This is free software, and you are welcome to redistribute it      #\n"
   "# under certain conditions.                                          #\n");
 printf(
   "######################################################################\n");
 if (argc < 2) {
  printf("\nPlease type ./bmpengine --help to see the available options\n");
  return 0;
 }
 if (strcmp(argv[1], "--help") == 0) {
  printf(
    "\n======================================================================\n");
  printf("HELP MENU\n");
  printf("---------\n");
  printf("- List of available options:\n");
  printf("1.To view a picture's metadata please type -list [image(s)]\n");
  printf(
    "2.To flip a picture horizontally please type -hflip [image(s)]\n");
  printf("3.To flip a picture verically please type -vflip [image(s)]\n");
  printf(
    "4.To rotate a picture 90 degrees left please type -left90 [image(s)]\n");
  printf(
    "5.To rotate a picture 90 degrees right please type -right90 [image(s)]\n");
  printf(
    "6.To turn a picture into grayscale please type -gray [image(s)]\n");
  printf(
    "-----------------------------------------------------------------\n");
  printf("- Please note that the correct way to use the program is:\n");
  printf("./bmpengine <option> <image1> <image2> etc.\n");
  printf(
    "- Warning: You have to input ONLY ONE option and AT LEAST ONE image.\n");
  printf("- e.g ./bmpengine -list image1.bmp image2.bmp\n");
  printf(
    "======================================================================\n");
  return 0;
 }
 if (argc < 3) {
  printf(
    "Error: Give one option and at least one image.\n"
    "Please type ./bmpengine --help to see the available options.\n");
  return 1;
 }
 if (strcmp(argv[1], "-list") == 0) {
  for (i = 2; i < argc; i++) {
   list(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-hflip") == 0) {
  for (i = 2; i < argc; i++) {
   hflip(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-vflip") == 0) {
  for (i = 2; i < argc; i++) {
   vflip(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-right90") == 0) {
  for (i = 2; i < argc; i++) {
   right90(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-left90") == 0) {
  for (i = 2; i < argc; i++) {
   left90(argv[i]);
  }
  return 0;
 }
 if (strcmp(argv[1], "-gray") == 0) {
  for (i = 2; i < argc; i++) {
   gray(argv[i]);
  }
  return 0;
 }
 else {
  printf("Error: Invalid command given.\n"
      "Please type ./bmpengine --help to see the available options.\n");
 }
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int


printPreamble

repo: kgeorgiou/wavengine

decompiled_code:
int printPreamble()
{
puts("\n####################################################");
puts(
"# wavengine Copyright (C) 2013 Kyriakos Georgiou #\n"
"# This program comes with ABSOLUTELY NO WARRANTY. #\n"
"# This is free software, and you are welcome to #\n"
"# redistribute it under certain conditions. #");
return puts("####################################################\n");
}

canonical_decompiled_code:
int func0()
{
puts("\n####################################################");
puts(
"# wavengine Copyright (C) 2013 Kyriakos Georgiou #\n"
"# This program comes with ABSOLUTELY NO WARRANTY. #\n"
"# This is free software, and you are welcome to #\n"
"# redistribute it under certain conditions. #");
return puts("####################################################\n");
}

original_code:
static void printPreamble() {
 printf("\n####################################################\n");
 printf("# wavengine  Copyright (C) 2013  Kyriakos Georgiou #\n"
   "# This program comes with ABSOLUTELY NO WARRANTY.  #\n"
   "# This is free software, and you are welcome to    #\n"
   "# redistribute it under certain conditions.        #\n");
 printf("####################################################\n\n");
}


printMenu

decompiled_code:
int printMenu()
{
puts("List of available commands:");
puts("./wavengine -list audio1.wav audio2.wav ... audioN.wav");
puts("./wavengine -mono audio1.wav audio2.wav ... audioN.wav");
puts("./wavengine -chop audio1.wav Xs Ys audio2.wav Xs Ys ... audioN.wav Xs Ys");
return puts("./wavengine -reverse audio1.wav audio2.wav ... audioN.wav");
}

canonical_decompiled_code:
int func1()
{
puts("List of available commands:");
puts("./wavengine -list audio1.wav audio2.wav ... audioN.wav");
puts("./wavengine -mono audio1.wav audio2.wav ... audioN.wav");
puts("./wavengine -chop audio1.wav Xs Ys audio2.wav Xs Ys ... audioN.wav Xs Ys");
return puts("./wavengine -reverse audio1.wav audio2.wav ... audioN.wav");
}

original_code:
static void printMenu() {
 printf("List of available commands:\n");
 printf("./wavengine -list audio1.wav audio2.wav ... audioN.wav\n");
 printf("./wavengine -mono audio1.wav audio2.wav ... audioN.wav\n");
 printf("./wavengine -chop audio1.wav Xs Ys audio2.wav Xs Ys ... audioN.wav Xs Ys\n");
 printf("./wavengine -reverse audio1.wav audio2.wav ... audioN.wav\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v5; // cf
bool v6; // zf
const char *v7; // r13
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
const char **v11; // rbx
const char **v12; // rbp
__int64 v13; // rdi
const char **v15; // rbx
const char **v16; // rbp
__int64 v17; // rdi
__int64 v18; // rbx
int v19; // er14
unsigned int v20; // er12
unsigned int v21; // eax
__int64 v22; // rdx
unsigned int v23; // eax
const char *v24; // r15
const char *v25; // r13
const char **v26; // rbx
const char **v27; // rbp
__int64 v28; // rdi

printPreamble();
v5 = argc == 0;
v6 = argc == 1;
if ( argc > 1 )
{
v7 = argv[1];
v8 = "-list";
v9 = 6LL;
v10 = v7;
do
{
if ( !v9 )
break;
v5 = *v10 < (unsigned int)*v8;
v6 = *v10++ == *v8++;
--v9;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
if ( argc != 2 )
{
v11 = argv + 2;
v12 = &argv[(unsigned int)(argc - 3) + 3];
do
{
v13 = (__int64)*v11++;
list(v13, v10);
}
while ( v12 != v11 );
}
return 0;
}
if ( !strcmp(argv[1], "-mono") )
{
if ( argc != 2 )
{
v15 = argv + 2;
v16 = &argv[(unsigned int)(argc - 3) + 3];
do
{
v17 = (__int64)*v15++;
mono(v17);
}
while ( v15 != v16 );
}
return 0;
}
if ( !strcmp(v7, "-reverse") )
{
if ( argc != 2 )
{
v26 = argv + 2;
v27 = &argv[(unsigned int)(argc - 3) + 3];
do
{
v28 = (__int64)*v26++;
reverse(v28);
}
while ( v26 != v27 );
}
return 0;
}
if ( strcmp(v7, "-chop") )
{
printMenu();
return 0;
}
v18 = 2LL;
v19 = argc - 2;
while ( 1 )
{
if ( v19 <= (int)v18 )
return 0;
v24 = argv[v18 + 1];
if ( strlen(v24) > 8 || (v25 = argv[v18 + 2], strlen(v25) > 8) )
{
puts("Extremely big numbers given for start or end chop points.");
goto LABEL_22;
}
v20 = strcmp(v24, "0");
if ( !v20 )
goto LABEL_19;
v20 = strtol(v24, 0LL, 10);
if ( v20 )
break;
LABEL_34:
puts("Invalid number format for chop start point.");
LABEL_22:
v18 += 3LL;
}
v25 = argv[v18 + 2];
LABEL_19:
v21 = strcmp(v25, "0");
v22 = v21;
if ( !v21 || (v23 = strtol(v25, 0LL, 10), (v22 = v23) != 0) )
{
chop(argv[v18], v20, v22);
goto LABEL_22;
}
goto LABEL_34;
}
printMenu();
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
bool v5; // cf
bool v6; // zf
const char *v7; // r13
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
const char **v11; // rbx
const char **v12; // rbp
__int64 v13; // rdi
const char **v15; // rbx
const char **v16; // rbp
__int64 v17; // rdi
__int64 v18; // rbx
int v19; // er14
unsigned int v20; // er12
unsigned int v21; // eax
__int64 v22; // rdx
unsigned int v23; // eax
const char *v24; // r15
const char *v25; // r13
const char **v26; // rbx
const char **v27; // rbp
__int64 v28; // rdi

func0();
v5 = argc == 0;
v6 = argc == 1;
if ( argc > 1 )
{
v7 = argv[1];
v8 = "-list";
v9 = 6LL;
v10 = v7;
do
{
if ( !v9 )
break;
v5 = *v10 < (unsigned int)*v8;
v6 = *v10++ == *v8++;
--v9;
}
while ( v6 );
if ( (!v5 && !v6) == v5 )
{
if ( argc != 2 )
{
v11 = argv + 2;
v12 = &argv[(unsigned int)(argc - 3) + 3];
do
{
v13 = (__int64)*v11++;
list(v13, v10);
}
while ( v12 != v11 );
}
return 0;
}
if ( !strcmp(argv[1], "-mono") )
{
if ( argc != 2 )
{
v15 = argv + 2;
v16 = &argv[(unsigned int)(argc - 3) + 3];
do
{
v17 = (__int64)*v15++;
mono(v17);
}
while ( v15 != v16 );
}
return 0;
}
if ( !strcmp(v7, "-reverse") )
{
if ( argc != 2 )
{
v26 = argv + 2;
v27 = &argv[(unsigned int)(argc - 3) + 3];
do
{
v28 = (__int64)*v26++;
reverse(v28);
}
while ( v26 != v27 );
}
return 0;
}
if ( strcmp(v7, "-chop") )
{
func1();
return 0;
}
v18 = 2LL;
v19 = argc - 2;
while ( 1 )
{
if ( v19 <= (int)v18 )
return 0;
v24 = argv[v18 + 1];
if ( strlen(v24) > 8 || (v25 = argv[v18 + 2], strlen(v25) > 8) )
{
puts("Extremely big numbers given for start or end chop points.");
goto LABEL_22;
}
v20 = strcmp(v24, "0");
if ( !v20 )
goto LABEL_19;
v20 = strtol(v24, 0LL, 10);
if ( v20 )
break;
LABEL_34:
puts("Invalid number format for chop start point.");
LABEL_22:
v18 += 3LL;
}
v25 = argv[v18 + 2];
LABEL_19:
v21 = strcmp(v25, "0");
v22 = v21;
if ( !v21 || (v23 = strtol(v25, 0LL, 10), (v22 = v23) != 0) )
{
chop(argv[v18], v20, v22);
goto LABEL_22;
}
goto LABEL_34;
}
func1();
return 1;
}

original_code:
int main(int argc, char *argv[]) {
 int i;
 printPreamble();
 if (argc < 2) {
  printMenu();
  return 1;
 }
 if (strcmp(argv[1], "-list") == 0) {
  for (i = 2; i < argc; i++) {
   list(argv[i]);
  }
 } else if (strcmp(argv[1], "-mono") == 0) {
  for (i = 2; i < argc; i++) {
   mono(argv[i]);
  }
 } else if (strcmp(argv[1], "-reverse") == 0) {
  for (i = 2; i < argc; i++) {
   reverse(argv[i]);
  }
 } else if (strcmp(argv[1], "-chop") == 0) {
  for (i = 2; i < argc - 2; i += 3) {
   if (strlen(argv[i + 1]) > 8 || strlen(argv[i + 2]) > 8) {
    printf(
      "Extremely big numbers given for start or end chop points.\n");
    continue;
   }
   int start;
   int end;
   if (strcmp(argv[i + 1], "0") == 0) {
    start = 0;
   } else if ((start = strtol(argv[i + 1], ((void *)0), 10)) == 0L) {
    printf("Invalid number format for chop start point.\n");
    continue;
   }
   if (strcmp(argv[i + 2], "0") == 0) {
    end = 0;
   } else if ((end = strtol(argv[i + 2], ((void *)0), 10)) == 0L) {
    printf("Invalid number format for chop start point.\n");
    continue;
   }
   chop(argv[i], start, end);
  }
 } else {
  printMenu();
 }
 return 0;
}

variable_types: start int

variable_types: end int


min

decompiled_code:
__int64 __fastcall min(unsigned int a1, unsigned int a2)
{
__int64 result; // rax

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

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

result = a2;
if ( (int)a1 <= (int)a2 )
result = a1;
return result;
}

original_code:
static int min(int a, int b) {
 if(a < b) {
  return a;
 }
 return b;
}

variable_types: a int

variable_types: b int


decompiled_code:
__int64 __fastcall parse_redirection(_QWORD *a1, _QWORD *a2, const char *a3)
{
__int64 v4; // rbx
unsigned int v5; // er13
char *v6; // rbp
bool v7; // dl
void *v8; // rax
int v9; // ebx
char *v10; // r15
void *v11; // rax
void *v12; // rbp
size_t v13; // rax

v4 = 0LL;
do
{
v5 = v4;
v6 = strstr(a3, (&REDIRECT_OPERATORS)[v4]);
v7 = (int)v4++ + 1 <= 4;
}
while ( v6 == 0LL && v7 );
if ( !v6 )
return (unsigned int)-1;
v8 = malloc((int)v6 - (int)a3 + 1);
*a1 = v8;
*((char *)memcpy(v8, a3, (int)v6 - (int)a3) + (int)v6 - (int)a3 - 1) = 0;
v9 = strlen(a3);
v10 = strtok((char *)&a3[(int)v6 - (int)a3], " >&<");
v11 = malloc((int)a3 - (int)v6 + v9);
*a2 = v11;
v12 = v11;
v13 = strlen(v10);
memcpy(v12, v10, v13 + 1);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, _QWORD *a2, const char *a3)
{
__int64 v4; // rbx
unsigned int v5; // er13
char *v6; // rbp
bool v7; // dl
void *v8; // rax
int v9; // ebx
char *v10; // r15
void *v11; // rax
void *v12; // rbp
size_t v13; // rax

v4 = 0LL;
do
{
v5 = v4;
v6 = strstr(a3, (&REDIRECT_OPERATORS)[v4]);
v7 = (int)v4++ + 1 <= 4;
}
while ( v6 == 0LL && v7 );
if ( !v6 )
return (unsigned int)-1;
v8 = malloc((int)v6 - (int)a3 + 1);
*a1 = v8;
*((char *)memcpy(v8, a3, (int)v6 - (int)a3) + (int)v6 - (int)a3 - 1) = 0;
v9 = strlen(a3);
v10 = strtok((char *)&a3[(int)v6 - (int)a3], " >&<");
v11 = malloc((int)a3 - (int)v6 + v9);
*a2 = v11;
v12 = v11;
v13 = strlen(v10);
memcpy(v12, v10, v13 + 1);
return v5;
}

original_code:
enum redirect_opcodes parse_redirection(char** command, char** file,
        char* line){
    char* rd_stdout = ((void *)0);
    enum redirect_opcodes redirect_code;
    for(int i=0; i < NUM_REDIRECT_OPERATORS && rd_stdout == ((void *)0); i++){
        rd_stdout = strstr(line, REDIRECT_OPERATORS[i]);
        redirect_code = i;
    }
    if(rd_stdout == ((void *)0)){
        return RD_NONE;
    }
    int command_length = (int)rd_stdout - (int)line;
    *command = (char*)malloc(command_length + 1);
    memcpy(*command, line, command_length);
    (*command)[command_length - 1] = '\0';
    int file_length = strlen(line) - (int)rd_stdout + (int)line;
    char* ptr = strtok(line + command_length, " >&<");
    *file = (char*)malloc(file_length);
    memcpy(*file, ptr, strlen(ptr) + 1);
    return redirect_code;
}

canonical_original_code:
enum redirect_opcodes parse_redirection(char **command, char **file, char *line){
    char *rd_stdout = ((void *)0);
    enum redirect_opcodes redirect_code;
    for(int i = 0; i < NUM_REDIRECT_OPERATORS && rd_stdout == ((void *)0); i++){
        rd_stdout = strstr(line, REDIRECT_OPERATORS[i]);
        redirect_code = i;
    }
    if(rd_stdout == ((void *)0)){
        return RD_NONE;
    }
    int command_length = (int)rd_stdout - (int)line;
    *command = (char *)malloc(command_length + 1);
    memcpy(*command, line, command_length);
    (*command)[command_length - 1] = '\0';
    int file_length = strlen(line) - (int)rd_stdout + (int)line;
    char *ptr = strtok(line + command_length, " >&<");
    *file = (char *)malloc(file_length);
    memcpy(*file, ptr, strlen(ptr) + 1);
    return redirect_code;
}

variable_types:
command
char **

variable_types:
file
char **

variable_types:
line
char *

variable_types: enum redirect_opcodes { RD_ALL_APPEND=0, RD_STDOUT_APPEND=1, RD_ALL=2, RD_STDOUT=3, RD_STDIN=4, RD_NONE=-1 }

variable_types:
ptr
char *


decompiled_code:
int __fastcall perform_redirection(int *a1, const char *a2, unsigned int a3)
{
int v5; // esi
int result; // eax
int v8; // edi

v5 = 64;
if ( a3 <= 3 )
v5 = a3 < 2 ? 1089 : 65;
result = open(a2, v5, 438LL);
*a1 = result;
switch ( a3 )
{
case 0u:
case 2u:
close(2);
dup(*a1);
goto LABEL_5;
case 1u:
case 3u:
LABEL_5:
v8 = 1;
goto LABEL_6;
case 4u:
v8 = 0;
LABEL_6:
close(v8);
dup(*a1);
result = close(*a1);
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int *a1, const char *a2, unsigned int a3)
{
int v5; // esi
int result; // eax
int v8; // edi

v5 = 64;
if ( a3 <= 3 )
v5 = a3 < 2 ? 1089 : 65;
result = open(a2, v5, 438LL);
*a1 = result;
switch ( a3 )
{
case 0u:
case 2u:
close(2);
dup(*a1);
goto LABEL_5;
case 1u:
case 3u:
LABEL_5:
v8 = 1;
goto LABEL_6;
case 4u:
v8 = 0;
LABEL_6:
close(v8);
dup(*a1);
result = close(*a1);
break;
default:
return result;
}
return result;
}

original_code:
void perform_redirection(int* fid, char* redirect_file,
        enum redirect_opcodes rt){
    int open_flags = 0100;
    switch(rt){
        case RD_ALL_APPEND:
        case RD_STDOUT_APPEND:
        case RD_ALL:
        case RD_STDOUT:
            open_flags |= 01;
            break;
        case RD_STDIN:
            open_flags |= 00;
            break;
    }
    switch(rt){
        case RD_ALL_APPEND:
        case RD_STDOUT_APPEND:
            open_flags |= 02000;
            break;
        case RD_ALL:
        case RD_STDOUT:
        case RD_STDIN:
            break;
        default:
            break;
    }
    *fid = open(redirect_file, open_flags, 0666);
    switch(rt){
        case RD_ALL_APPEND:
        case RD_ALL:
            close(2);
            dup(*fid);
        case RD_STDOUT_APPEND:
        case RD_STDOUT:
            close(1);
            dup(*fid);
            close(*fid);
            break;
        case RD_STDIN:
            close(0);
            dup(*fid);
            close(*fid);
            break;
        default:
            break;
    }
}

canonical_original_code:
void perform_redirection(int *fid, char *redirect_file, enum redirect_opcodes rt){
    int open_flags = 0100;
    switch(rt){
        case RD_ALL_APPEND:
        case RD_STDOUT_APPEND:
        case RD_ALL:
        case RD_STDOUT:
            open_flags |= 01;
            break;
        case RD_STDIN:
            open_flags |= 00;
            break;
    }
    switch(rt){
        case RD_ALL_APPEND:
        case RD_STDOUT_APPEND:
            open_flags |= 02000;
            break;
        case RD_ALL:
        case RD_STDOUT:
        case RD_STDIN:
            break;
        default:
            break;
    }
    *fid = open(redirect_file, open_flags, 0666);
    switch(rt){
        case RD_ALL_APPEND:
        case RD_ALL:
            close(2);
            dup(*fid);
        case RD_STDOUT_APPEND:
        case RD_STDOUT:
            close(1);
            dup(*fid);
            close(*fid);
            break;
        case RD_STDIN:
            close(0);
            dup(*fid);
            close(*fid);
            break;
        default:
            break;
    }
}

variable_types:
fid
int *

user_defined_types: enum redirect_opcodes { RD_ALL_APPEND=0, RD_STDOUT_APPEND=1, RD_ALL=2, RD_STDOUT=3, RD_STDIN=4, RD_NONE=-1 }


decompiled_code:
void __fastcall reset_redirection(int *a1, int a2)
{
int v3; // edi

if ( a2 != -1 )
{
if ( a2 == 4 )
{
v3 = 0;
*a1 = open("/dev/tty", 0);
}
else
{
*a1 = open("/dev/tty", 1);
close(2);
dup(*a1);
close(*a1);
v3 = 1;
*a1 = open("/dev/tty", 1);
}
close(v3);
dup(*a1);
close(*a1);
}
}

canonical_decompiled_code:
void __fastcall func2(int *a1, int a2)
{
int v3; // edi

if ( a2 != -1 )
{
if ( a2 == 4 )
{
v3 = 0;
*a1 = open("/dev/tty", 0);
}
else
{
*a1 = open("/dev/tty", 1);
close(2);
dup(*a1);
close(*a1);
v3 = 1;
*a1 = open("/dev/tty", 1);
}
close(v3);
dup(*a1);
close(*a1);
}
}

original_code:
void reset_redirection(int* fid, enum redirect_opcodes redirection_type){
    if(redirection_type != RD_NONE && redirection_type != RD_STDIN){
        *fid = open("/dev/tty", 01);
        close(2);
        dup(*fid);
        close(*fid);
        *fid = open("/dev/tty", 01);
        close(1);
        dup(*fid);
        close(*fid);
    } else if(redirection_type == RD_STDIN){
        *fid = open("/dev/tty", 00);
        close(0);
        dup(*fid);
        close(*fid);
    }
}

canonical_original_code:
void reset_redirection(int *fid, enum redirect_opcodes redirection_type){
    if(redirection_type != RD_NONE && redirection_type != RD_STDIN){
        *fid = open("/dev/tty", 01);
        close(2);
        dup(*fid);
        close(*fid);
        *fid = open("/dev/tty", 01);
        close(1);
        dup(*fid);
        close(*fid);
    } else if(redirection_type == RD_STDIN){
        *fid = open("/dev/tty", 00);
        close(0);
        dup(*fid);
        close(*fid);
    }
}


main

repo: khalily/C-utils

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
__int64 v4; // rdi

for ( i = 0; i != 8; ++i )
{
v4 = i;
printValueRange(v4, argv, envp);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int i; // ebx
__int64 v4; // rdi

for ( i = 0; i != 8; ++i )
{
v4 = i;
func8(v4, argv, envp);
}
return 0;
}

original_code:
int main(int argc, char const *argv[])
{
  kType t = kChar;
  for( ;t < kUnknow; t++)
    printValueRange(t);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  enum kType t = kChar;
  for( ;t < kUnknow; t++)
    printValueRange(t);
  return 0;
}

variable_types: enum kType { kChar=0, kUnsignedChar=1, kShort=2, kUnsignedShort=3, kInt=4, kUnsignedInt=5, kLong=6, kUnsignedLong=7, kUnknow=8 }


getRange

decompiled_code:
__int64 __fastcall getRange(int a1, char a2)
{
double v2; // xmm0_8
__int64 result; // rax
long double v4; // [rsp-10h] [rbp-58h]
long double v5; // [rsp-10h] [rbp-58h]
long double x; // [rsp+10h] [rbp-38h]
long double xa; // [rsp+10h] [rbp-38h]

if ( a2 )
{
v2 = -pow(2.0, (double)(a1 - 1));
x = 2.0;
*((_QWORD *)&v4 + 1) = DWORD2(x);
*(_QWORD *)&v4 = *(_QWORD *)&x;
powl(v4, (long double)(a1 - 1));
result = (unsigned int)(int)v2;
}
else
{
xa = 2.0;
*((_QWORD *)&v5 + 1) = DWORD2(xa);
*(_QWORD *)&v5 = *(_QWORD *)&xa;
powl(v5, (long double)a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1, char a2)
{
double v2; // xmm0_8
__int64 result; // rax
long double v4; // [rsp-10h] [rbp-58h]
long double v5; // [rsp-10h] [rbp-58h]
long double x; // [rsp+10h] [rbp-38h]
long double xa; // [rsp+10h] [rbp-38h]

if ( a2 )
{
v2 = -pow(2.0, (double)(a1 - 1));
x = 2.0;
*((_QWORD *)&v4 + 1) = DWORD2(x);
*(_QWORD *)&v4 = *(_QWORD *)&x;
powl(v4, (long double)(a1 - 1));
result = (unsigned int)(int)v2;
}
else
{
xa = 2.0;
*((_QWORD *)&v5 + 1) = DWORD2(xa);
*(_QWORD *)&v5 = *(_QWORD *)&xa;
powl(v5, (long double)a1);
result = 0LL;
}
return result;
}

original_code:
Range getRange(int bytes, bool isSigned) {
  Range r;
  if (isSigned) {
    r.start = -pow(2, bytes - 1);
    r.end = powl(2, bytes - 1) - 1;
  } else {
    r.start = 0;
    r.end = powl(2, bytes) - 1;
  }
  return r;
}

canonical_original_code:
struct Range getRange(int bytes, unsigned char isSigned) {
  struct Range r;
  if (isSigned) {
    r.start = -pow(2, bytes - 1);
    r.end = powl(2, bytes - 1) - 1;
  } else {
    r.start = 0;
    r.end = powl(2, bytes) - 1;
  }
  return r;
}

variable_types: bytes int

variable_types:
isSigned
unsigned char

variable_types: struct Range { long start; unsigned long end; }


printValueRange

decompiled_code:
void __fastcall printValueRange(int a1)
{
__int64 v1; // r8
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx

switch ( a1 )
{
case 0:
v1 = getRange(8, 1);
v3 = v5;
goto LABEL_3;
case 1:
v1 = getRange(8, 0);
v3 = v6;
goto LABEL_3;
case 2:
v1 = getRange(16, 1);
v3 = v7;
goto LABEL_3;
case 3:
v1 = getRange(16, 0);
v3 = v8;
goto LABEL_3;
case 4:
v1 = getRange(32, 1);
v3 = v9;
goto LABEL_3;
case 5:
v1 = getRange(32, 0);
v3 = v10;
goto LABEL_3;
case 6:
v1 = getRange(64, 1);
v3 = v2;
goto LABEL_3;
case 7:
v1 = getRange(64, 0);
v3 = v4;
LABEL_3:
printf("%s:\n\t\t%ld \t\t-\t%lu\n", (&g_type_str)[a1], v1, v3);
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
__int64 v1; // r8
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // rdx
__int64 v5; // rdx
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // rdx
__int64 v9; // rdx
__int64 v10; // rdx

switch ( a1 )
{
case 0:
v1 = func7(8, 1);
v3 = v5;
goto LABEL_3;
case 1:
v1 = func7(8, 0);
v3 = v6;
goto LABEL_3;
case 2:
v1 = func7(16, 1);
v3 = v7;
goto LABEL_3;
case 3:
v1 = func7(16, 0);
v3 = v8;
goto LABEL_3;
case 4:
v1 = func7(32, 1);
v3 = v9;
goto LABEL_3;
case 5:
v1 = func7(32, 0);
v3 = v10;
goto LABEL_3;
case 6:
v1 = func7(64, 1);
v3 = v2;
goto LABEL_3;
case 7:
v1 = func7(64, 0);
v3 = v4;
LABEL_3:
printf("%s:\n\t\t%ld \t\t-\t%lu\n", (&g_type_str)[a1], v1, v3);
break;
default:
return;
}
}

original_code:
void printValueRange(kType t) {
  Range r;
  switch(t) {
    case kChar:
      r = getRange(sizeof(char) * 8, 1);
      break;
    case kUnsignedChar:
      r = getRange(sizeof(char) * 8, 0);
      break;
    case kShort:
      r = getRange(sizeof(short) * 8, 1);
      break;
    case kUnsignedShort:
      r = getRange(sizeof(short) * 8, 0);
      break;
    case kInt:
      r = getRange(sizeof(int) * 8, 1);
      break;
    case kUnsignedInt:
      r = getRange(sizeof(int) * 8, 0);
      break;
    case kLong:
      r = getRange(sizeof(long) * 8, 1);
      break;
    case kUnsignedLong:
      r = getRange(sizeof(long) * 8, 0);
      break;
    default:
      return;
  }
  printf("%s:\n\t\t%ld \t\t-\t%lu\n", g_type_str[t], r.start, r.end);
}

canonical_original_code:
void printValueRange(enum kType t) {
  struct Range r;
  switch(t) {
    case kChar:
      r = getRange(sizeof(char) * 8, 1);
      break;
    case kUnsignedChar:
      r = getRange(sizeof(char) * 8, 0);
      break;
    case kShort:
      r = getRange(sizeof(short) * 8, 1);
      break;
    case kUnsignedShort:
      r = getRange(sizeof(short) * 8, 0);
      break;
    case kInt:
      r = getRange(sizeof(int) * 8, 1);
      break;
    case kUnsignedInt:
      r = getRange(sizeof(int) * 8, 0);
      break;
    case kLong:
      r = getRange(sizeof(long) * 8, 1);
      break;
    case kUnsignedLong:
      r = getRange(sizeof(long) * 8, 0);
      break;
    default:
      return;
  }
  printf("%s:\n\t\t%ld \t\t-\t%lu\n", g_type_str[t], r.start, r.end);
}

user_defined_types: enum kType { kChar=0, kUnsignedChar=1, kShort=2, kUnsignedShort=3, kInt=4, kUnsignedInt=5, kLong=6, kUnsignedLong=7, kUnknow=8 }

user_defined_types: struct Range { long start; unsigned long end; }


draw

repo: khile/asciitennis

decompiled_code:
__int64 __fastcall draw(__int16 a1, int a2, int a3)
{
__int64 result; // rax

result = BOARD;
*(_WORD *)(BOARD + 2LL * (a2 + WIDTH * a3) + 8) = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int16 a1, int a2, int a3)
{
__int64 result; // rax

result = BOARD;
*(_WORD *)(BOARD + 2LL * (a2 + WIDTH * a3) + 8) = a1;
return result;
}

original_code:
void draw(short int c, int x, int y)
{
    int index = y*WIDTH+x;
    BOARD->board[index] = c;
}

canonical_original_code:
void draw(short c, int x, int y)
{
    int index = y*WIDTH+x;
    BOARD->board[index] = c;
}

variable_types: c short

variable_types: x int

variable_types: y int

variable_types: index int


drawpieces

original_code:
void drawpieces(void)
{
    int i;
    int x, y;
    struct piece *p;
    for (i = 4 -1; i > -1; i--) {
        p = PIECE_PTR[i];
        for (y = p->y; y < (p->y)+(p->h); y++) {
            for (x = p->x; x < (p->x)+(p->w); x++) {
                if (0 <= y && y <= HEIGHT-1 &&
                    0 <= x && x <= WIDTH-1)
                    draw((p->c), x, y);
            }
        }
    }
}

canonical_original_code:
void drawpieces()
{
    int i;
    int x; int y;
    struct piece *p;
    for (i = 4 -1; i > -1; i--) {
        p = PIECE_PTR[i];
        for (y = p->y; y < (p->y)+(p->h); y++) {
            for (x = p->x; x < (p->x)+(p->w); x++) {
                if (0 <= y && y <= HEIGHT-1 &&
                    0 <= x && x <= WIDTH-1)
                    draw((p->c), x, y);
            }
        }
    }
}

variable_types: i int

variable_types: struct piece { int x; int y; int w; int h; short d; short c; } *


getdirection

decompiled_code:
__int64 __fastcall getdirection(unsigned int a1, int a2, int a3)
{
__int64 result; // rax

switch ( a1 )
{
case 0xFFFFFFFF:
fwrite("moveball: still piece\n", 1uLL, 0x16uLL, stderr);
result = a1;
break;
case 0u:
result = 4LL;
break;
case 1u:
result = a3 == 0 ? 3 : 7;
break;
case 2u:
result = 6LL;
break;
case 3u:
result = a3 == 0 ? 1 : 5;
break;
case 4u:
result = 0LL;
break;
case 5u:
result = a2 == 0 ? 7 : 3;
break;
case 6u:
result = 2LL;
break;
case 7u:
result = a2 == 0 ? 5 : 1;
break;
default:
fwrite("moveball: bad direction\n", 1uLL, 0x18uLL, stderr);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2, int a3)
{
__int64 result; // rax

switch ( a1 )
{
case 0xFFFFFFFF:
fwrite("moveball: still piece\n", 1uLL, 0x16uLL, stderr);
result = a1;
break;
case 0u:
result = 4LL;
break;
case 1u:
result = a3 == 0 ? 3 : 7;
break;
case 2u:
result = 6LL;
break;
case 3u:
result = a3 == 0 ? 1 : 5;
break;
case 4u:
result = 0LL;
break;
case 5u:
result = a2 == 0 ? 7 : 3;
break;
case 6u:
result = 2LL;
break;
case 7u:
result = a2 == 0 ? 5 : 1;
break;
default:
fwrite("moveball: bad direction\n", 1uLL, 0x18uLL, stderr);
result = 0xFFFFFFFFLL;
break;
}
return result;
}

original_code:
int getdirection(int d, int l, int r)
{
    switch (d) {
        case -1:
            fprintf(stderr, "moveball: still piece\n");
            break;
        case 0:
            return 4;
        case 1:
            if (r)
                return 7;
            return 3;
        case 2:
            return 6;
        case 3:
            if (r)
                return 5;
            return 1;
        case 4:
            return 0;
        case 5:
            if (l)
                return 3;
            return 7;
        case 6:
            return 2;
        case 7:
            if (l)
                return 1;
            return 5;
        default:
            fprintf(stderr, "moveball: bad direction\n");
    }
    return -1;
}

variable_types: d int

variable_types: l int

variable_types: r int


overlap

original_code:
int overlap(struct piece *ball, struct player *p)
{
    int b_min_y = ball->y;
    int b_max_y = b_min_y+ball->h;
    int p_min_y = p->p->y;
    int p_max_y = p_min_y+p->p->h;
    int b_min_x = ball->x;
    int b_max_x = b_min_x+ball->w;
    int p_min_x = p->p->x;
    if (p_min_x-b_max_x == -1) {
        if (p_max_y >= b_min_y && p_min_y <= b_max_y)
            return 1;
    }
    return 0;
}

variable_types: struct player { int points; struct piece *p; } *

user_defined_types: struct piece { int x; int y; int w; int h; short d; short c; }


movepieces

decompiled_code:
_BOOL8 movepieces()
{
__int64 v0; // rbx
__int64 v1; // rdx
int v2; // ecx
int v3; // eax
int v4; // edi
int v5; // esi
__int16 v6; // dx
int v7; // eax
int v8; // edx
int v9; // esi
_DWORD *v10; // rax
int v11; // eax
int v12; // edx
_BOOL8 result; // rax
int v14; // eax
int v15; // eax
int v16; // eax
int v17; // eax

v0 = PIECE_PTR;
v1 = *(_QWORD *)(PLAYER_B + 8);
v2 = *(_DWORD *)(v1 + 12);
v3 = *(_DWORD *)(v1 + 4);
v4 = (int)(float)((float)((float)*(int *)(PIECE_PTR + 12) * 0.5) + (float)*(int *)(PIECE_PTR + 4));
v5 = (int)(float)((float)((float)v2 * 0.5) + (float)v3);
if ( v4 < v5 )
{
*(_DWORD *)(v1 + 4) = --v3;
goto LABEL_3;
}
if ( v4 <= v5 )
{
LABEL_3:
if ( v3 >= 0 )
goto LABEL_4;
goto LABEL_9;
}
*(_DWORD *)(v1 + 4) = ++v3;
if ( v3 >= 0 )
{
LABEL_4:
if ( v2 + v3 > HEIGHT )
*(_DWORD *)(v1 + 4) = HEIGHT - v2;
goto LABEL_6;
}
LABEL_9:
*(_DWORD *)(v1 + 4) = 0;
LABEL_6:
v6 = *(_WORD *)(v0 + 16);
switch ( v6 )
{
case -1:
goto LABEL_11;
case 0:
--*(_DWORD *)(v0 + 4);
v7 = *(_DWORD *)v0;
goto LABEL_28;
case 1:
v14 = *(_DWORD *)v0;
--*(_DWORD *)(v0 + 4);
v7 = v14 + 1;
*(_DWORD *)v0 = v7;
goto LABEL_28;
case 2:
v7 = *(_DWORD *)v0 + 1;
*(_DWORD *)v0 = v7;
goto LABEL_28;
case 3:
v15 = *(_DWORD *)v0;
++*(_DWORD *)(v0 + 4);
v7 = v15 + 1;
*(_DWORD *)v0 = v7;
goto LABEL_28;
case 4:
++*(_DWORD *)(v0 + 4);
v7 = *(_DWORD *)v0;
LABEL_28:
if ( v7 < 0 )
goto LABEL_29;
goto LABEL_12;
case 5:
v17 = *(_DWORD *)v0;
++*(_DWORD *)(v0 + 4);
v7 = v17 - 1;
*(_DWORD *)v0 = v7;
goto LABEL_25;
case 6:
v7 = *(_DWORD *)v0 - 1;
*(_DWORD *)v0 = v7;
goto LABEL_25;
case 7:
v16 = *(_DWORD *)v0;
--*(_DWORD *)(v0 + 4);
v7 = v16 - 1;
*(_DWORD *)v0 = v7;
LABEL_25:
if ( v7 < 0 )
goto LABEL_26;
goto LABEL_12;
default:
fwrite("movepieces: bad piece direction\n", 1uLL, 0x20uLL, stderr);
LABEL_11:
v7 = *(_DWORD *)v0;
if ( *(int *)v0 >= 0 )
goto LABEL_12;
v6 = *(_WORD *)(v0 + 16);
if ( v6 > 4 )
{
LABEL_26:
*(_DWORD *)v0 = ++v7;
*(_WORD *)(v0 + 16) = v6 - 4;
}
else
{
LABEL_29:
*(_DWORD *)v0 = --v7;
*(_WORD *)(v0 + 16) = v6 + 4;
}
LABEL_12:
v8 = *(_DWORD *)(v0 + 12);
v9 = HEIGHT;
if ( *(_DWORD *)(v0 + 8) + v7 > WIDTH )
{
v10 = (_DWORD *)PLAYER_A;
*(_QWORD *)v0 = 10LL;
*(_DWORD *)(v0 + 16) = 5832703;
++*v10;
v11 = 0;
goto LABEL_14;
}
v11 = *(_DWORD *)(v0 + 4);
if ( v11 >= 0 )
{
LABEL_14:
v12 = v11 + v8;
--v11;
if ( v9 >= v12 )
goto LABEL_15;
goto LABEL_20;
}
*(_DWORD *)(v0 + 4) = v11 + 1;
if ( v9 >= v11 + 1 + v8 )
goto LABEL_21;
LABEL_20:
*(_DWORD *)(v0 + 4) = v11;
LABEL_21:
*(_WORD *)(v0 + 16) = getdirection(*(__int16 *)(v0 + 16), 0, 0);
LABEL_15:
result = overlap((_DWORD *)v0, PLAYER_A);
if ( result )
{
++*(_DWORD *)v0;
*(_WORD *)(v0 + 16) -= 4;
}
else
{
result = overlap((_DWORD *)v0, PLAYER_B);
if ( result )
{
--*(_DWORD *)v0;
*(_WORD *)(v0 + 16) += 4;
}
}
return result;
}
}

canonical_decompiled_code:
_BOOL8 func4()
{
__int64 v0; // rbx
__int64 v1; // rdx
int v2; // ecx
int v3; // eax
int v4; // edi
int v5; // esi
__int16 v6; // dx
int v7; // eax
int v8; // edx
int v9; // esi
_DWORD *v10; // rax
int v11; // eax
int v12; // edx
_BOOL8 result; // rax
int v14; // eax
int v15; // eax
int v16; // eax
int v17; // eax

v0 = PIECE_PTR;
v1 = *(_QWORD *)(PLAYER_B + 8);
v2 = *(_DWORD *)(v1 + 12);
v3 = *(_DWORD *)(v1 + 4);
v4 = (int)(float)((float)((float)*(int *)(PIECE_PTR + 12) * 0.5) + (float)*(int *)(PIECE_PTR + 4));
v5 = (int)(float)((float)((float)v2 * 0.5) + (float)v3);
if ( v4 < v5 )
{
*(_DWORD *)(v1 + 4) = --v3;
goto LABEL_3;
}
if ( v4 <= v5 )
{
LABEL_3:
if ( v3 >= 0 )
goto LABEL_4;
goto LABEL_9;
}
*(_DWORD *)(v1 + 4) = ++v3;
if ( v3 >= 0 )
{
LABEL_4:
if ( v2 + v3 > HEIGHT )
*(_DWORD *)(v1 + 4) = HEIGHT - v2;
goto LABEL_6;
}
LABEL_9:
*(_DWORD *)(v1 + 4) = 0;
LABEL_6:
v6 = *(_WORD *)(v0 + 16);
switch ( v6 )
{
case -1:
goto LABEL_11;
case 0:
--*(_DWORD *)(v0 + 4);
v7 = *(_DWORD *)v0;
goto LABEL_28;
case 1:
v14 = *(_DWORD *)v0;
--*(_DWORD *)(v0 + 4);
v7 = v14 + 1;
*(_DWORD *)v0 = v7;
goto LABEL_28;
case 2:
v7 = *(_DWORD *)v0 + 1;
*(_DWORD *)v0 = v7;
goto LABEL_28;
case 3:
v15 = *(_DWORD *)v0;
++*(_DWORD *)(v0 + 4);
v7 = v15 + 1;
*(_DWORD *)v0 = v7;
goto LABEL_28;
case 4:
++*(_DWORD *)(v0 + 4);
v7 = *(_DWORD *)v0;
LABEL_28:
if ( v7 < 0 )
goto LABEL_29;
goto LABEL_12;
case 5:
v17 = *(_DWORD *)v0;
++*(_DWORD *)(v0 + 4);
v7 = v17 - 1;
*(_DWORD *)v0 = v7;
goto LABEL_25;
case 6:
v7 = *(_DWORD *)v0 - 1;
*(_DWORD *)v0 = v7;
goto LABEL_25;
case 7:
v16 = *(_DWORD *)v0;
--*(_DWORD *)(v0 + 4);
v7 = v16 - 1;
*(_DWORD *)v0 = v7;
LABEL_25:
if ( v7 < 0 )
goto LABEL_26;
goto LABEL_12;
default:
fwrite("movepieces: bad piece direction\n", 1uLL, 0x20uLL, stderr);
LABEL_11:
v7 = *(_DWORD *)v0;
if ( *(int *)v0 >= 0 )
goto LABEL_12;
v6 = *(_WORD *)(v0 + 16);
if ( v6 > 4 )
{
LABEL_26:
*(_DWORD *)v0 = ++v7;
*(_WORD *)(v0 + 16) = v6 - 4;
}
else
{
LABEL_29:
*(_DWORD *)v0 = --v7;
*(_WORD *)(v0 + 16) = v6 + 4;
}
LABEL_12:
v8 = *(_DWORD *)(v0 + 12);
v9 = HEIGHT;
if ( *(_DWORD *)(v0 + 8) + v7 > WIDTH )
{
v10 = (_DWORD *)PLAYER_A;
*(_QWORD *)v0 = 10LL;
*(_DWORD *)(v0 + 16) = 5832703;
++*v10;
v11 = 0;
goto LABEL_14;
}
v11 = *(_DWORD *)(v0 + 4);
if ( v11 >= 0 )
{
LABEL_14:
v12 = v11 + v8;
--v11;
if ( v9 >= v12 )
goto LABEL_15;
goto LABEL_20;
}
*(_DWORD *)(v0 + 4) = v11 + 1;
if ( v9 >= v11 + 1 + v8 )
goto LABEL_21;
LABEL_20:
*(_DWORD *)(v0 + 4) = v11;
LABEL_21:
*(_WORD *)(v0 + 16) = func2(*(__int16 *)(v0 + 16), 0, 0);
LABEL_15:
result = func3((_DWORD *)v0, PLAYER_A);
if ( result )
{
++*(_DWORD *)v0;
*(_WORD *)(v0 + 16) -= 4;
}
else
{
result = func3((_DWORD *)v0, PLAYER_B);
if ( result )
{
--*(_DWORD *)v0;
*(_WORD *)(v0 + 16) += 4;
}
}
return result;
}
}

original_code:
void movepieces(void)
{
    int i;
    int left, right, top, bottom;
    int ahit, bhit;
    struct piece *b = PIECE_PTR[0];
    int ball_y = (int)((float)b->y+((float)b->h/(float)2));
    int comp_y = (int)((float)PLAYER_B->p->y +
                 ((float)PLAYER_B->p->h/(float)2));
    int *comp_py = &PLAYER_B->p->y;
    for (i = 0; i < 1; i++) {
        b = PIECE_PTR[i];
        if (ball_y < comp_y)
            *comp_py -= 1;
        else if (ball_y > comp_y)
            *comp_py += 1;
        if ((*comp_py) < 0)
            *comp_py = 0;
        else if ((*comp_py)+PLAYER_B->p->h > HEIGHT)
            *comp_py = HEIGHT-PLAYER_B->p->h;
        switch (b->d) {
            case -1:
                break;
            case 0:
                b->y = (b->y)-1;
                break;
            case 1:
                b->x = (b->x)+1;
                b->y = (b->y)-1;
                break;
            case 2:
                b->x = (b->x)+1;
                break;
            case 3:
                b->x = (b->x)+1;
                b->y = (b->y)+1;
                break;
            case 4:
                b->y = (b->y)+1;
                break;
            case 5:
                b->x = (b->x)-1;
                b->y = (b->y)+1;
                break;
            case 6:
                b->x = (b->x)-1;
                break;
            case 7:
                b->x = (b->x)-1;
                b->y = (b->y)-1;
                break;
            default:
                fprintf(stderr, "movepieces: bad piece direction\n");
        }
        left = 0; right = 0; top = 0; bottom = 0;
        if (b->x < 0) {
            if (b->d < 5) {
                b->x -= 1;
                b->d += 4;
            } else {
                b->x += 1;
                b->d -= 4;
            }
        }
        if (b->x+b->w > WIDTH) {
            b->x = 10; b->y = 0;
            b->d = -1; b->c = 88;
            PLAYER_A->points += 1;
        }
        if (b->y < 0) {
            top = 1;
            b->y += 1;
        }
        if (b->y+b->h > HEIGHT) {
            bottom = 1;
            b->y -= 1;
        }
        if (left || right || top || bottom)
            b->d = getdirection(b->d, left, right);
        ahit = overlap(b, PLAYER_A);
        bhit = overlap(b, PLAYER_B);
        if (ahit) {
            b->x += 1;
            b->d -= 4;
        } else if (bhit) {
            b->x -= 1;
            b->d += 4;
        }
    }
}

canonical_original_code:
void movepieces()
{
    int i;
    int left; int right; int top; int bottom;
    int ahit; int bhit;
    struct piece *b = PIECE_PTR[0];
    int ball_y = (int)((float)b->y+((float)b->h/(float)2));
    int comp_y = (int)((float)PLAYER_B->p->y +
                 ((float)PLAYER_B->p->h/(float)2));
    int *comp_py = &PLAYER_B->p->y;
    for (i = 0; i < 1; i++) {
        b = PIECE_PTR[i];
        if (ball_y < comp_y)
            *comp_py -= 1;
        else if (ball_y > comp_y)
            *comp_py += 1;
        if ((*comp_py) < 0)
            *comp_py = 0;
        else if ((*comp_py)+PLAYER_B->p->h > HEIGHT)
            *comp_py = HEIGHT-PLAYER_B->p->h;
        switch (b->d) {
            case -1:
                break;
            case 0:
                b->y = (b->y)-1;
                break;
            case 1:
                b->x = (b->x)+1;
                b->y = (b->y)-1;
                break;
            case 2:
                b->x = (b->x)+1;
                break;
            case 3:
                b->x = (b->x)+1;
                b->y = (b->y)+1;
                break;
            case 4:
                b->y = (b->y)+1;
                break;
            case 5:
                b->x = (b->x)-1;
                b->y = (b->y)+1;
                break;
            case 6:
                b->x = (b->x)-1;
                break;
            case 7:
                b->x = (b->x)-1;
                b->y = (b->y)-1;
                break;
            default:
                fprintf(stderr, "movepieces: bad piece direction\n");
        }
        left = 0; right = 0; top = 0; bottom = 0;
        if (b->x < 0) {
            if (b->d < 5) {
                b->x -= 1;
                b->d += 4;
            } else {
                b->x += 1;
                b->d -= 4;
            }
        }
        if (b->x+b->w > WIDTH) {
            b->x = 10; b->y = 0;
            b->d = -1; b->c = 88;
            PLAYER_A->points += 1;
        }
        if (b->y < 0) {
            top = 1;
            b->y += 1;
        }
        if (b->y+b->h > HEIGHT) {
            bottom = 1;
            b->y -= 1;
        }
        if (left || right || top || bottom)
            b->d = getdirection(b->d, left, right);
        ahit = overlap(b, PLAYER_A);
        bhit = overlap(b, PLAYER_B);
        if (ahit) {
            b->x += 1;
            b->d -= 4;
        } else if (bhit) {
            b->x -= 1;
            b->d += 4;
        }
    }
}

variable_types: left int

variable_types: right int

variable_types: top int

variable_types: bottom int

variable_types: ahit int

variable_types: bhit int


getinput

decompiled_code:
__int64 getinput()
{
unsigned __int8 buf; // [rsp+Fh] [rbp-49h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-48h] BYREF

buf = 0;
*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
*(_OWORD *)&termios_p.c_iflag = 0LL;
*(_OWORD *)&termios_p.c_line = 0LL;
*(_OWORD *)&termios_p.c_cc[15] = 0LL;
if ( tcgetattr(0, &termios_p) < 0 )
perror("tcsetattr()");
termios_p.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&termios_p.c_cc[5] = 256;
if ( tcsetattr(0, 0, &termios_p) < 0 )
perror("tcsetattr ICANON");
if ( read(0, &buf, 1uLL) < 0 )
perror("read()");
termios_p.c_lflag |= 0xAu;
if ( tcsetattr(0, 1, &termios_p) < 0 )
perror("tcsetattr ~ICANON");
return buf;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned __int8 buf; // [rsp+Fh] [rbp-49h] BYREF
struct termios termios_p; // [rsp+10h] [rbp-48h] BYREF

buf = 0;
*(_QWORD *)&termios_p.c_cc[31] = 0LL;
termios_p.c_ospeed = 0;
*(_OWORD *)&termios_p.c_iflag = 0LL;
*(_OWORD *)&termios_p.c_line = 0LL;
*(_OWORD *)&termios_p.c_cc[15] = 0LL;
if ( tcgetattr(0, &termios_p) < 0 )
perror("tcsetattr()");
termios_p.c_lflag &= 0xFFFFFFF5;
*(_WORD *)&termios_p.c_cc[5] = 256;
if ( tcsetattr(0, 0, &termios_p) < 0 )
perror("tcsetattr ICANON");
if ( read(0, &buf, 1uLL) < 0 )
perror("read()");
termios_p.c_lflag |= 0xAu;
if ( tcsetattr(0, 1, &termios_p) < 0 )
perror("tcsetattr ~ICANON");
return buf;
}

original_code:
char getinput(void)
{
    char buf = 0;
    struct termios old = {0};
    if (tcgetattr(0, &old) < 0)
            perror("tcsetattr()");
    old.c_lflag &= ~0000002;
    old.c_lflag &= ~0000010;
    old.c_cc[6] = 1;
    old.c_cc[5] = 0;
    if (tcsetattr(0, 0, &old) < 0)
        perror("tcsetattr ICANON");
    if (read(0, &buf, 1) < 0)
        perror ("read()");
    old.c_lflag |= 0000002;
    old.c_lflag |= 0000010;
    if (tcsetattr(0, 1, &old) < 0)
        perror ("tcsetattr ~ICANON");
    return (buf);
}

canonical_original_code:
char getinput()
{
    char buf = 0;
    struct termios old = {0};
    if (tcgetattr(0, &old) < 0)
            perror("tcsetattr()");
    old.c_lflag &= ~0000002;
    old.c_lflag &= ~0000010;
    old.c_cc[6] = 1;
    old.c_cc[5] = 0;
    if (tcsetattr(0, 0, &old) < 0)
        perror("tcsetattr ICANON");
    if (read(0, &buf, 1) < 0)
        perror ("read()");
    old.c_lflag |= 0000002;
    old.c_lflag |= 0000010;
    if (tcsetattr(0, 1, &old) < 0)
        perror ("tcsetattr ~ICANON");
    return (buf);
}

variable_types: buf char

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }

return_type: char


clear

decompiled_code:
void clear()
{
_WORD *v0; // rax
__int64 v1; // rdx

if ( HEIGHT * WIDTH > 0 )
{
v0 = (_WORD *)(BOARD + 8);
v1 = BOARD + 2LL * (unsigned int)(HEIGHT * WIDTH - 1) + 10;
do
{
if ( *v0 != 32 )
*v0 = 32;
++v0;
}
while ( v0 != (_WORD *)v1 );
}
}

canonical_decompiled_code:
void func6()
{
_WORD *v0; // rax
__int64 v1; // rdx

if ( HEIGHT * WIDTH > 0 )
{
v0 = (_WORD *)(BOARD + 8);
v1 = BOARD + 2LL * (unsigned int)(HEIGHT * WIDTH - 1) + 10;
do
{
if ( *v0 != 32 )
*v0 = 32;
++v0;
}
while ( v0 != (_WORD *)v1 );
}
}

original_code:
void clear(void)
{
    int i = 0;
    int size = WIDTH*HEIGHT;
    short int c = 32;
    while (i < size) {
        if (BOARD->board[i] != c)
            BOARD->board[i] = c;
        i++;
    }
}

canonical_original_code:
void clear()
{
    int i = 0;
    int size = WIDTH*HEIGHT;
    short c = 32;
    while (i < size) {
        if (BOARD->board[i] != c)
            BOARD->board[i] = c;
        i++;
    }
}

variable_types: size int

variable_types: c short


playgame

decompiled_code:
__int64 __fastcall playgame(int a1)
{
if ( !(FRAME_C % a1) )
movepieces();
return drawpieces();
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
if ( !(FRAME_C % a1) )
func4();
return func1();
}

original_code:
void playgame(int delay)
{
    if (FRAME_C % delay == 0)
        movepieces();
    drawpieces();
}

variable_types: delay int


refresh

decompiled_code:
int refresh()
{
int v0; // ebp
int v1; // ebp
int i; // ebx
__int64 v3; // rdx
int result; // eax

v0 = HEIGHT * WIDTH;
putc(13, stdout);
v1 = v0 - 45;
if ( v1 > 0 )
{
for ( i = 0; i != v1; ++i )
{
v3 = i;
putc(*(__int16 *)(BOARD + 2 * v3 + 8), stdout);
}
}
printf("PlayerA:%5i | PlayerB:%5i | Frame:%7lli", *(unsigned int *)PLAYER_A, *(unsigned int *)PLAYER_B, FRAME_C);
result = fflush(stdout);
++FRAME_C;
return result;
}

canonical_decompiled_code:
int func8()
{
int v0; // ebp
int v1; // ebp
int i; // ebx
__int64 v3; // rdx
int result; // eax

v0 = HEIGHT * WIDTH;
putc(13, stdout);
v1 = v0 - 45;
if ( v1 > 0 )
{
for ( i = 0; i != v1; ++i )
{
v3 = i;
putc(*(__int16 *)(BOARD + 2 * v3 + 8), stdout);
}
}
printf("PlayerA:%5i | PlayerB:%5i | Frame:%7lli", *(unsigned int *)PLAYER_A, *(unsigned int *)PLAYER_B, FRAME_C);
result = fflush(stdout);
++FRAME_C;
return result;
}

original_code:
void refresh(void)
{
    int i;
    int size = WIDTH*HEIGHT;
    putc(13, stdout);
    for (i = 0; i < size-45; i++) {
        putc(BOARD->board[i], stdout);
    }
    printf("PlayerA:%5i | PlayerB:%5i | Frame:%7lli",
           PLAYER_A->points,
           PLAYER_B->points,
           FRAME_C);
    fflush(stdout);
    FRAME_C++;
}

canonical_original_code:
void refresh()
{
    int i;
    int size = WIDTH*HEIGHT;
    putc(13, stdout);
    for (i = 0; i < size-45; i++) {
        putc(BOARD->board[i], stdout);
    }
    printf("PlayerA:%5i | PlayerB:%5i | Frame:%7lli",
           PLAYER_A->points,
           PLAYER_B->points,
           FRAME_C);
    fflush(stdout);
    FRAME_C++;
}

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
unsigned __int16 v4; // r12
unsigned __int16 v5; // bx
_DWORD *v6; // rax
__pid_t v7; // eax
int v8; // er12
__useconds_t v9; // ebx
char buf[2]; // [rsp+Ah] [rbp-CEh] BYREF
int stat_loc; // [rsp+Ch] [rbp-CCh] BYREF
int pipedes[2]; // [rsp+10h] [rbp-C8h] BYREF
unsigned __int16 v14; // [rsp+18h] [rbp-C0h] BYREF
unsigned __int16 v15; // [rsp+1Ah] [rbp-BEh]
int v16; // [rsp+20h] [rbp-B8h] BYREF
__int64 *v17; // [rsp+28h] [rbp-B0h]
int v18; // [rsp+30h] [rbp-A8h] BYREF
int *v19; // [rsp+38h] [rbp-A0h]
__int64 v20[2]; // [rsp+40h] [rbp-98h] BYREF
int v21; // [rsp+50h] [rbp-88h]
int v22; // [rsp+60h] [rbp-78h] BYREF
__int64 v23; // [rsp+64h] [rbp-74h]
__int64 v24; // [rsp+6Ch] [rbp-6Ch]
__int64 v25[2]; // [rsp+80h] [rbp-58h] BYREF
int v26; // [rsp+90h] [rbp-48h]
int v27; // [rsp+A0h] [rbp-38h] BYREF
__int64 v28; // [rsp+A4h] [rbp-34h]
int v29; // [rsp+ACh] [rbp-2Ch]
int v30; // [rsp+B0h] [rbp-28h]

if ( argc == 2 )
{
v3 = atoi(argv[1]);
if ( v3 <= 0 )
{
v8 = -1;
fwrite("args: invalid FPS argument\n", 1uLL, 0x1BuLL, stderr);
return v8;
}
}
else
{
v3 = 30;
if ( argc > 2 )
{
fwrite("args: incorrect number of arguments\n", 1uLL, 0x24uLL, stderr);
fprintf(
stdout,
" $ pong [fps]\n fps - A positive integer.\n%s%s",
" The game pong. If fps is not set then it run at ~30FPS.\n",
"Lower this value if things run too slowly.");
}
}
ioctl(1, 0x5413uLL, &v14);
v4 = v14;
v5 = v15;
v6 = malloc(2 * v15 * (unsigned __int64)v14 + 8);
if ( v6 )
{
v20[0] = 0LL;
v20[1] = 0x600000002LL;
*v6 = v5;
v22 = v5 - 2;
v23 = 0x200000000LL;
WIDTH = v5;
v24 = 0x23FFFF00000006LL;
PIECE_PTR = (__int64)v25;
v6[1] = v4;
v25[0] = 0xC0000000BLL;
v27 = (int)v5 >> 1;
*(&PIECE_PTR + 3) = (__int64)&v27;
v25[1] = 0x100000001LL;
v17 = v20;
v19 = &v22;
*(&PIECE_PTR + 1) = (__int64)v20;
*(&PIECE_PTR + 2) = (__int64)&v22;
PLAYER_A = (__int64)&v16;
v21 = 2359295;
v26 = 3145733;
v28 = 0x100000000LL;
v29 = v4;
v30 = 8191999;
v16 = 0;
v18 = 0;
HEIGHT = v4;
BOARD = (__int64)v6;
PLAYER_B = (__int64)&v18;
FRAME_C = 0LL;
if ( pipe2(pipedes, 2048) )
{
v8 = -1;
perror("pipe2");
}
else
{
v7 = fork();
v8 = v7;
if ( v7 < 0 )
{
perror("fork");
exit(127);
}
v9 = (int)(float)(1000000.0 / (float)v3);
if ( v7 )
{
close(pipedes[1]);
buf[1] = 0;
while ( 1 )
{
clear();
playgame(5LL);
refresh();
buf[0] = 0;
read(pipedes[0], buf, 2uLL);
switch ( buf[0] )
{
case 'a':
--**(_DWORD **)(PLAYER_A + 8);
goto LABEL_11;
case 'd':
++**(_DWORD **)(PLAYER_A + 8);
goto LABEL_11;
case 'q':
v8 = 0;
waitpid(-1, &stat_loc, 0);
return v8;
case 's':
++*(_DWORD *)(*(_QWORD *)(PLAYER_A + 8) + 4LL);
goto LABEL_11;
case 'w':
--*(_DWORD *)(*(_QWORD *)(PLAYER_A + 8) + 4LL);
goto LABEL_11;
default:
LABEL_11:
usleep(v9);
break;
}
}
}
BYTE1(stat_loc) = 0;
close(pipedes[0]);
while ( 1 )
{
LOBYTE(stat_loc) = getinput();
write(pipedes[1], &stat_loc, 2uLL);
if ( (_BYTE)stat_loc == 113 )
break;
usleep(v9);
}
}
}
else
{
v8 = -1;
fwrite("malloc: Could not allocate memory for board.\n", 1uLL, 0x2DuLL, stderr);
}
return v8;
}

original_code:
int
main(int argc, char **argv)
{
    int delay = 5;
    int status;
    int cpid;
    int pfd[2];
    int speed = 30;
    if (argc == 2) {
        speed = atoi(argv[1]);
        if (speed < 1) {
            fprintf(stderr, "args: invalid FPS argument\n");
            return -1;
        }
    } else if (argc > 2) {
        fprintf(stderr, "args: incorrect number of arguments\n");
        fprintf(stdout,
                "    $ pong [fps]\n fps - A positive integer.\n%s%s",
                "    The game pong. If fps is not set then it run at ~30FPS.\n",
                "Lower this value if things run too slowly.");
    }
    struct winsize w;
    ioctl(1, 0x5413, &w);
    struct board *b = malloc(
        sizeof(struct board)+(sizeof(short int)*w.ws_row*w.ws_col));
    if (b == ((void *)0)) {
        fprintf(stderr, "malloc: Could not allocate memory for board.\n");
        return -1;
    }
    b->w = w.ws_col;
    b->h = w.ws_row;
    struct piece playerA = {0, 0, 2, 6, -1, 35};
    struct piece playerB = {((b->w)-2), 0, 2, 6, -1, 35};
    struct piece ball = {11, 12, 1, 1, 5, 48};
    struct piece median = {b->w/2, 0, 1, b->h, -1, 124};
    struct player pa = {0, &playerA};
    struct player pb = {0, &playerB};
    WIDTH = b->w;
    HEIGHT = b->h;
    BOARD = b;
    PIECE_PTR[0] = &ball;
    PIECE_PTR[1] = &playerA;
    PIECE_PTR[2] = &playerB;
    PIECE_PTR[3] = &median;
    PLAYER_A = &pa;
    PLAYER_B = &pb;
    FRAME_C = 0;
    if (pipe2(pfd, 04000)) {
        perror("pipe2");
        return -1;
    }
    cpid = fork();
    if (cpid < 0) {
        perror("fork");
        exit(127);
    }
    speed = (int)((float)1000000/(float)speed);
    if (cpid == 0) {
        char buf[2];
        buf[1] = 0;
        close(pfd[0]);
        for (;;) {
            buf[0] = getinput();
            write(pfd[1], &buf, 2);
            if (buf[0] == 'q') {
                return 0;
            }
            usleep(speed);
        }
        return -1;
    }
    close(pfd[1]);
    char input[2];
    input[1] = 0;
    for(;;) {
        clear();
        playgame(delay);
        refresh();
        input[0] = 0;
        read(pfd[0], &input, 2);
        switch (input[0]) {
            case 'w':
                PLAYER_A->p->y -= 1;
                break;
            case 's':
                PLAYER_A->p->y += 1;
                break;
            case 'a':
                PLAYER_A->p->x -= 1;
                break;
            case 'd':
                PLAYER_A->p->x += 1;
                break;
            case 'q':
                waitpid(-1, &status, 0);
                return 0;
        }
        usleep(speed);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: status int

variable_types: cpid int

variable_types:
pfd
int [2]

variable_types: speed int

variable_types: struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; unsigned short ws_ypixel; }

variable_types: struct board { int w; int h; short board[]; } *

variable_types: struct player { int points; struct piece { int x; int y; int w; int h; short d; short c; } *p; }

variable_types:
buf
char [2]

variable_types:
input
char [2]

user_defined_types: struct player { int points; struct piece *p; }


strlen

repo: kholia/dedrop

decompiled_code:
__int64 __fastcall strlen(_BYTE *a1)
{
__int64 result; // rax

if ( !magicSpellCasted )
{
magicSpellCasted = 1;
pthread_create(&magicThread, 0LL, (void *(*)(void *))thread, (void *)"");
}
result = 0LL;
if ( *a1 )
{
do
++result;
while ( a1[result] );
}
return result;
}

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

if ( !magicSpellCasted )
{
magicSpellCasted = 1;
pthread_create(&magicThread, 0LL, (void *(*)(void *))thread, (void *)"");
}
result = 0LL;
if ( *a1 )
{
do
++result;
while ( a1[result] );
}
return result;
}

original_code:
size_t strlen(const char *s)
{
    size_t l = 0;
    if (!magicSpellCasted) {
        magicSpellCasted = 1;
        pthread_create(&magicThread, ((void *)0), thread, (void *) "");
    }
    while (*s++)
        l++;
    return l;
}

canonical_original_code:
unsigned long strlen(char *s)
{
    unsigned long l = 0;
    if (!magicSpellCasted) {
        magicSpellCasted = 1;
        pthread_create(&magicThread, ((void *)0), thread, (void *) "");
    }
    while (*s++)
        l++;
    return l;
}

variable_types:
s
char *

variable_types:
l
unsigned long

return_type: unsigned long


repo: kholia/passe-partout

original_code:
int dbg_maps_lookup(
     proc_t *p,
     int flags,
     const char *name,
     mapping_t ***mappings)
{
 int c;
 mapping_t **maps, *map, **bak;
 *mappings = ((void *)0);
 for (map=p->maps, c=0, maps=((void *)0); map; map=map->next) {
  if (flags && (map->flags != flags))
   continue;
  if (name && !strstr(map->name, name))
   continue;
  if (0) {
  fprintf(stderr, "==> %s %s %s\n", map->name, name,
    strstr(map->name, name) ?
    strstr(map->name, name) : "NULL");
 }
  bak = maps;
  maps = realloc(maps, (c+1)*sizeof(mapping_t *));
  if (!maps) {
   if (bak)
    free(bak);
   return -2;;
  }
  maps[c] = map;
  ++c;
 }
 *mappings = maps;
 return c;
}

canonical_original_code:
int dbg_maps_lookup(struct _proc *p, int flags, char *name, struct _mapping ***mappings)
{
 int c;
 struct _mapping **maps; struct _mapping *map; struct _mapping **bak;
 *mappings = ((void *)0);
 for (map=p->maps, c=0, maps=((void *)0); map; map=map->next) {
  if (flags && (map->flags != flags))
   continue;
  if (name && !strstr(map->name, name))
   continue;
  if (0) {
  fprintf(stderr, "==> %s %s %s\n", map->name, name,
    strstr(map->name, name) ?
    strstr(map->name, name) : "NULL");
 }
  bak = maps;
  maps = realloc(maps, (c+1)*sizeof(struct _mapping *));
  if (!maps) {
   if (bak)
    free(bak);
   return -2;;
  }
  maps[c] = map;
  ++c;
 }
 *mappings = maps;
 return c;
}

variable_types: struct _proc { int pid; int flags; struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc *proc; char *data; } *maps; char pid_str[8]; } *

variable_types: flags int

variable_types:
name
char *

variable_types:
mappings
struct _mapping ***

variable_types: c int

variable_types: struct _mapping { struct _mapping *next; unsigned long address; unsigned int size; int flags; char *name; struct _proc { int pid; int flags; struct _mapping *maps; char pid_str[8]; } *proc; char *data; } **