decompiled_code:
__int64 init_resources()
{
unsigned int v0; // ebx
__int64 result; // rax
unsigned int v2; // ebp
int v3[14]; // [rsp+0h] [rbp-98h] BYREF
__int16 v4[4]; // [rsp+38h] [rbp-60h] BYREF
int v5[8]; // [rsp+40h] [rbp-58h] BYREF
int v6[7]; // [rsp+60h] [rbp-38h] BYREF
int v7[7]; // [rsp+7Ch] [rbp-1Ch] BYREF

v7[0] = 0;
fps_start = glutGet(700LL);
program_start = fps_start;
v0 = create_shader("triangle.v.glsl", 35633LL);
result = 0LL;
if ( v0 )
{
v2 = create_shader("triangle.f.glsl", 35632LL);
result = 0LL;
if ( v2 )
{
program = _glewCreateProgram();
_glewAttachShader((unsigned int)program, v0);
_glewAttachShader((unsigned int)program, v2);
_glewLinkProgram((unsigned int)program);
_glewGetProgramiv((unsigned int)program, 35714LL, v7);
if ( !v7[0] )
{
fwrite("glLinkProgram:", 1uLL, 0xEuLL, stderr);
print_log((unsigned int)program);
}
texture_id = make_texture("glass.gif");
texture_id2 = make_texture("nehe.gif");
texture_id3 = make_texture("star.gif");
v6[0] = 0;
v6[1] = LC13;
v6[2] = LC14;
v6[3] = LC14;
v6[4] = LC13;
v6[5] = LC14;
vbo_triangle = make_buffer(34962LL, v6, 24LL);
v5[0] = LC15;
v5[1] = LC15;
v5[2] = LC16;
v5[3] = LC15;
v5[4] = LC15;
v5[5] = LC16;
v5[6] = LC16;
v5[7] = LC16;
vbo_quad = make_buffer(34962LL, v5, 32LL);
v4[0] = 0;
v4[1] = 1;
v4[2] = 2;
v4[3] = 3;
vbo_quad_elements = make_buffer(34962LL, v4, 8LL);
v3[0] = 0;
v3[1] = 0;
v3[2] = LC17;
v3[3] = 0;
v3[4] = LC17;
v3[5] = LC17;
v3[6] = LC17;
v3[7] = LC17;
v3[8] = LC17;
v3[9] = 0;
v3[10] = 0;
v3[11] = 0;
vbo_cube_texcoords = make_buffer(34962LL, v3, 48LL);
attribute_coord2d = _glewGetAttribLocation((unsigned int)program, "coord2d");
if ( attribute_coord2d == -1 )
{
fwrite("Could not bind attribute coord2d\n", 1uLL, 0x21uLL, stderr);
result = 0LL;
}
else
{
uniform_mytexture = _glewGetUniformLocation((unsigned int)program, "mytexture");
if ( uniform_mytexture == -1 )
{
fwrite("Could not bind uniform mytexture\n", 1uLL, 0x21uLL, stderr);
result = 0LL;
}
else
{
uniform_location = _glewGetUniformLocation((unsigned int)program, "location");
if ( uniform_location == -1 )
{
fwrite("Could not bind uniform location\n", 1uLL, 0x20uLL, stderr);
result = 0LL;
}
else
{
uniform_size = _glewGetUniformLocation((unsigned int)program, "size");
if ( uniform_location == -1 )
{
fwrite("Could not bind uniform size\n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
else
{
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glClearColor(0.0, 0.0, 0.0, 1.0);
result = 1LL;
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx
__int64 result; // rax
unsigned int v2; // ebp
int v3[14]; // [rsp+0h] [rbp-98h] BYREF
__int16 v4[4]; // [rsp+38h] [rbp-60h] BYREF
int v5[8]; // [rsp+40h] [rbp-58h] BYREF
int v6[7]; // [rsp+60h] [rbp-38h] BYREF
int v7[7]; // [rsp+7Ch] [rbp-1Ch] BYREF

v7[0] = 0;
fps_start = glutGet(700LL);
program_start = fps_start;
v0 = create_shader("triangle.v.glsl", 35633LL);
result = 0LL;
if ( v0 )
{
v2 = create_shader("triangle.f.glsl", 35632LL);
result = 0LL;
if ( v2 )
{
program = _glewCreateProgram();
_glewAttachShader((unsigned int)program, v0);
_glewAttachShader((unsigned int)program, v2);
_glewLinkProgram((unsigned int)program);
_glewGetProgramiv((unsigned int)program, 35714LL, v7);
if ( !v7[0] )
{
fwrite("glLinkProgram:", 1uLL, 0xEuLL, stderr);
print_log((unsigned int)program);
}
texture_id = make_texture("glass.gif");
texture_id2 = make_texture("nehe.gif");
texture_id3 = make_texture("star.gif");
v6[0] = 0;
v6[1] = LC13;
v6[2] = LC14;
v6[3] = LC14;
v6[4] = LC13;
v6[5] = LC14;
vbo_triangle = make_buffer(34962LL, v6, 24LL);
v5[0] = LC15;
v5[1] = LC15;
v5[2] = LC16;
v5[3] = LC15;
v5[4] = LC15;
v5[5] = LC16;
v5[6] = LC16;
v5[7] = LC16;
vbo_quad = make_buffer(34962LL, v5, 32LL);
v4[0] = 0;
v4[1] = 1;
v4[2] = 2;
v4[3] = 3;
vbo_quad_elements = make_buffer(34962LL, v4, 8LL);
v3[0] = 0;
v3[1] = 0;
v3[2] = LC17;
v3[3] = 0;
v3[4] = LC17;
v3[5] = LC17;
v3[6] = LC17;
v3[7] = LC17;
v3[8] = LC17;
v3[9] = 0;
v3[10] = 0;
v3[11] = 0;
vbo_cube_texcoords = make_buffer(34962LL, v3, 48LL);
attribute_coord2d = _glewGetAttribLocation((unsigned int)program, "coord2d");
if ( attribute_coord2d == -1 )
{
fwrite("Could not bind attribute coord2d\n", 1uLL, 0x21uLL, stderr);
result = 0LL;
}
else
{
uniform_mytexture = _glewGetUniformLocation((unsigned int)program, "mytexture");
if ( uniform_mytexture == -1 )
{
fwrite("Could not bind uniform mytexture\n", 1uLL, 0x21uLL, stderr);
result = 0LL;
}
else
{
uniform_location = _glewGetUniformLocation((unsigned int)program, "location");
if ( uniform_location == -1 )
{
fwrite("Could not bind uniform location\n", 1uLL, 0x20uLL, stderr);
result = 0LL;
}
else
{
uniform_size = _glewGetUniformLocation((unsigned int)program, "size");
if ( uniform_location == -1 )
{
fwrite("Could not bind uniform size\n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
else
{
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glClearColor(0.0, 0.0, 0.0, 1.0);
result = 1LL;
}
}
}
}
}
}
return result;
}

original_code:
int init_resources() {
    GLint compile_ok = 0, link_ok = 0;
    program_start = fps_start = glutGet(0x02BC);
    GLuint vs, fs;
    if ((vs = create_shader("triangle.v.glsl", 0x8B31)) == 0) return 0;
    if ((fs = create_shader("triangle.f.glsl", 0x8B30)) == 0) return 0;
    program = __glewCreateProgram();
    __glewAttachShader(program, vs);
    __glewAttachShader(program, fs);
    __glewLinkProgram(program);
    __glewGetProgramiv(program, 0x8B82, &link_ok);
    if (!link_ok) {
        fprintf(stderr, "glLinkProgram:");
        print_log(program);
    }
    texture_id = make_texture("glass.gif");
    texture_id2 = make_texture("nehe.gif");
    texture_id3 = make_texture("star.gif");
    GLfloat triangle_vertices[] = {
        0.0, 0.8,
        -0.8, -0.8,
        0.8, -0.8,
    };
    vbo_triangle = make_buffer(0x8892, triangle_vertices, sizeof (triangle_vertices));
    GLfloat quad_vertices[] = {
        -0.2, -0.2,
         0.2, -0.2,
        -0.2, 0.2,
         0.2, 0.2,
    };
    vbo_quad = make_buffer(0x8892, quad_vertices, sizeof (quad_vertices));
    GLushort quad_elements[] = {
        0, 1, 2, 3,
    };
    vbo_quad_elements = make_buffer(0x8892, quad_elements, sizeof (quad_elements));
    GLfloat cube_texcoords[] = {
        0.0, 0.0,
        1.0, 0.0,
        1.0, 1.0,
        1.0, 1.0,
        1.0, 0.0,
        0.0, 0.0,
    };
    vbo_cube_texcoords = make_buffer(0x8892, cube_texcoords, sizeof (cube_texcoords));
    attribute_coord2d = __glewGetAttribLocation(program, "coord2d");
    if (attribute_coord2d == -1) {
        fprintf(stderr, "Could not bind attribute coord2d\n");
        return 0;
    }
    uniform_mytexture = __glewGetUniformLocation(program, "mytexture");
    if (uniform_mytexture == -1) {
        fprintf(stderr, "Could not bind uniform mytexture\n");
        return 0;
    }
    uniform_location = __glewGetUniformLocation(program, "location");
    if (uniform_location == -1) {
        fprintf(stderr, "Could not bind uniform location\n");
        return 0;
    }
    uniform_size = __glewGetUniformLocation(program, "size");
    if (uniform_location == -1) {
        fprintf(stderr, "Could not bind uniform size\n");
        return 0;
    }
    glEnable(0x0BE2);
    glBlendFunc(0x0302, 0x0303);
    glClearColor(0.0, 0.0, 0.0, 1.0);
    return 1;
}

canonical_original_code:
int init_resources() {
    int compile_ok = 0; int link_ok = 0;
    program_start = fps_start = glutGet(0x02BC);
    unsigned int vs; unsigned int fs;
    if ((vs = create_shader("triangle.v.glsl", 0x8B31)) == 0) return 0;
    if ((fs = create_shader("triangle.f.glsl", 0x8B30)) == 0) return 0;
    program = __glewCreateProgram();
    __glewAttachShader(program, vs);
    __glewAttachShader(program, fs);
    __glewLinkProgram(program);
    __glewGetProgramiv(program, 0x8B82, &link_ok);
    if (!link_ok) {
        fprintf(stderr, "glLinkProgram:");
        print_log(program);
    }
    texture_id = make_texture("glass.gif");
    texture_id2 = make_texture("nehe.gif");
    texture_id3 = make_texture("star.gif");
    float triangle_vertices[] = {
        0.0, 0.8,
        -0.8, -0.8,
        0.8, -0.8,
    };
    vbo_triangle = make_buffer(0x8892, triangle_vertices, sizeof (triangle_vertices));
    float quad_vertices[] = {
        -0.2, -0.2,
         0.2, -0.2,
        -0.2, 0.2,
         0.2, 0.2,
    };
    vbo_quad = make_buffer(0x8892, quad_vertices, sizeof (quad_vertices));
    unsigned short quad_elements[] = {
        0, 1, 2, 3,
    };
    vbo_quad_elements = make_buffer(0x8892, quad_elements, sizeof (quad_elements));
    float cube_texcoords[] = {
        0.0, 0.0,
        1.0, 0.0,
        1.0, 1.0,
        1.0, 1.0,
        1.0, 0.0,
        0.0, 0.0,
    };
    vbo_cube_texcoords = make_buffer(0x8892, cube_texcoords, sizeof (cube_texcoords));
    attribute_coord2d = __glewGetAttribLocation(program, "coord2d");
    if (attribute_coord2d == -1) {
        fprintf(stderr, "Could not bind attribute coord2d\n");
        return 0;
    }
    uniform_mytexture = __glewGetUniformLocation(program, "mytexture");
    if (uniform_mytexture == -1) {
        fprintf(stderr, "Could not bind uniform mytexture\n");
        return 0;
    }
    uniform_location = __glewGetUniformLocation(program, "location");
    if (uniform_location == -1) {
        fprintf(stderr, "Could not bind uniform location\n");
        return 0;
    }
    uniform_size = __glewGetUniformLocation(program, "size");
    if (uniform_location == -1) {
        fprintf(stderr, "Could not bind uniform size\n");
        return 0;
    }
    glEnable(0x0BE2);
    glBlendFunc(0x0302, 0x0303);
    glClearColor(0.0, 0.0, 0.0, 1.0);
    return 1;
}

variable_types:
vs
unsigned int

variable_types:
fs
unsigned int


repo: rnentjes/OpenGL

decompiled_code:
__int64 free_resources()
{
_glewDeleteProgram((unsigned int)program);
_glewDeleteBuffers(1LL, &vbo_triangle);
_glewDeleteBuffers(1LL, &vbo_quad);
return glDeleteTextures(1LL, &texture_id);
}

canonical_decompiled_code:
__int64 func3()
{
_glewDeleteProgram((unsigned int)program);
_glewDeleteBuffers(1LL, &vbo_triangle);
_glewDeleteBuffers(1LL, &vbo_quad);
return glDeleteTextures(1LL, &texture_id);
}

original_code:
void free_resources() {
    __glewDeleteProgram(program);
    __glewDeleteBuffers(1, &vbo_triangle);
    __glewDeleteBuffers(1, &vbo_quad);
    glDeleteTextures(1, &texture_id);
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int result; // eax
const char *v5; // rax
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = argc;
glutInit(v6, argv, envp);
glutInitDisplayMode(26LL);
glutInitWindowSize(1000LL, 800LL);
glutCreateWindow("My First Triangle");
v3 = glewInit();
if ( v3 )
{
v5 = (const char *)glewGetErrorString(v3);
fprintf(stderr, "Error: %s\n", v5);
result = 1;
}
else
{
if ( (unsigned int)init_resources() )
{
glutDisplayFunc(onDisplay);
glutIdleFunc(idle);
glutMainLoop();
}
free_resources();
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
int result; // eax
const char *v5; // rax
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = argc;
glutInit(v6, argv, envp);
glutInitDisplayMode(26LL);
glutInitWindowSize(1000LL, 800LL);
glutCreateWindow("My First Triangle");
v3 = glewInit();
if ( v3 )
{
v5 = (const char *)glewGetErrorString(v3);
fprintf(stderr, "Error: %s\n", v5);
result = 1;
}
else
{
if ( (unsigned int)func2() )
{
glutDisplayFunc(onDisplay);
glutIdleFunc(idle);
glutMainLoop();
}
func3();
result = 0;
}
return result;
}

original_code:
int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(0x0000 | 0x0008 | 0x0002 | 0x0010);
    glutInitWindowSize(1000, 800);
    glutCreateWindow("My First Triangle");
    GLenum glew_status = glewInit();
    if (glew_status != 0) {
        fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
        return 1;
    }
    if (init_resources()) {
        glutDisplayFunc(onDisplay);
        glutIdleFunc(idle);
        glutMainLoop();
    }
    free_resources();
    return (0);
}

canonical_original_code:
int main(int argc, char **argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(0x0000 | 0x0008 | 0x0002 | 0x0010);
    glutInitWindowSize(1000, 800);
    glutCreateWindow("My First Triangle");
    unsigned int glew_status = glewInit();
    if (glew_status != 0) {
        fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
        return 1;
    }
    if (init_resources()) {
        glutDisplayFunc(onDisplay);
        glutIdleFunc(idle);
        glutMainLoop();
    }
    free_resources();
    return (0);
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
__int64 __fastcall le_short(unsigned __int8 *a1)
{
return ((char)a1[1] << 8) | (unsigned int)*a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
return ((char)a1[1] << 8) | (unsigned int)*a1;
}

original_code:
static short le_short(unsigned char *bytes) {
    return bytes[0] | ((char) bytes[1] << 8);
}

variable_types:
bytes
unsigned char *

return_type: short


decompiled_code:
void __fastcall print_log(unsigned int a1)
{
char *v1; // rbp
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2[0] = 0;
if ( (unsigned __int8)((__int64 (*)(void))_glewIsShader)() )
{
_glewGetShaderiv(a1, 35716LL, v2);
}
else
{
if ( !(unsigned __int8)_glewIsProgram(a1) )
{
fwrite("printlog: Not a shader or a program\n", 1uLL, 0x24uLL, stderr);
return;
}
_glewGetProgramiv(a1, 35716LL, v2);
}
v1 = (char *)malloc(v2[0]);
if ( (unsigned __int8)_glewIsShader(a1) )
{
_glewGetShaderInfoLog(a1, (unsigned int)v2[0], 0LL, v1);
}
else if ( (unsigned __int8)_glewIsProgram(a1) )
{
_glewGetProgramInfoLog(a1, (unsigned int)v2[0], 0LL, v1);
}
fputs(v1, stderr);
free(v1);
}

canonical_decompiled_code:
void __fastcall func1(unsigned int a1)
{
char *v1; // rbp
int v2[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2[0] = 0;
if ( (unsigned __int8)((__int64 (*)(void))_glewIsShader)() )
{
_glewGetShaderiv(a1, 35716LL, v2);
}
else
{
if ( !(unsigned __int8)_glewIsProgram(a1) )
{
fwrite("printlog: Not a shader or a program\n", 1uLL, 0x24uLL, stderr);
return;
}
_glewGetProgramiv(a1, 35716LL, v2);
}
v1 = (char *)malloc(v2[0]);
if ( (unsigned __int8)_glewIsShader(a1) )
{
_glewGetShaderInfoLog(a1, (unsigned int)v2[0], 0LL, v1);
}
else if ( (unsigned __int8)_glewIsProgram(a1) )
{
_glewGetProgramInfoLog(a1, (unsigned int)v2[0], 0LL, v1);
}
fputs(v1, stderr);
free(v1);
}

original_code:
void print_log(GLuint object) {
    GLint log_length = 0;
    if (__glewIsShader(object))
        __glewGetShaderiv(object, 0x8B84, &log_length);
    else if (__glewIsProgram(object))
        __glewGetProgramiv(object, 0x8B84, &log_length);
    else {
        fprintf(stderr, "printlog: Not a shader or a program\n");
        return;
    }
    char* log = (char*) malloc(log_length);
    if (__glewIsShader(object))
        __glewGetShaderInfoLog(object, log_length, ((void *)0), log);
    else if (__glewIsProgram(object))
        __glewGetProgramInfoLog(object, log_length, ((void *)0), log);
    fprintf(stderr, "%s", log);
    free(log);
}

canonical_original_code:
void print_log(unsigned int object) {
    int log_length = 0;
    if (__glewIsShader(object))
        __glewGetShaderiv(object, 0x8B84, &log_length);
    else if (__glewIsProgram(object))
        __glewGetProgramiv(object, 0x8B84, &log_length);
    else {
        fprintf(stderr, "printlog: Not a shader or a program\n");
        return;
    }
    char *log = (char*) malloc(log_length);
    if (__glewIsShader(object))
        __glewGetShaderInfoLog(object, log_length, ((void *)0), log);
    else if (__glewIsProgram(object))
        __glewGetProgramInfoLog(object, log_length, ((void *)0), log);
    fprintf(stderr, "%s", log);
    free(log);
}

variable_types:
object
unsigned int

variable_types:
log
char *


decompiled_code:
__int64 __fastcall create_shader(const char *a1, unsigned int a2)
{
__int64 v2; // rbx
int v4; // [rsp+4h] [rbp-24h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = file_read(a1);
if ( ptr )
{
v2 = (unsigned int)_glewCreateShader(a2);
_glewShaderSource(v2, 1LL, &ptr, 0LL);
free(ptr);
_glewCompileShader((unsigned int)v2);
v4 = 0;
_glewGetShaderiv((unsigned int)v2, 35713LL, &v4);
if ( !v4 )
{
fprintf(stderr, "%s:", a1);
print_log(v2);
_glewDeleteShader((unsigned int)v2);
LODWORD(v2) = 0;
}
}
else
{
fprintf(stderr, "Error opening %s: ", a1);
perror(&s);
LODWORD(v2) = 0;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, unsigned int a2)
{
__int64 v2; // rbx
int v4; // [rsp+4h] [rbp-24h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

ptr = file_read(a1);
if ( ptr )
{
v2 = (unsigned int)_glewCreateShader(a2);
_glewShaderSource(v2, 1LL, &ptr, 0LL);
free(ptr);
_glewCompileShader((unsigned int)v2);
v4 = 0;
_glewGetShaderiv((unsigned int)v2, 35713LL, &v4);
if ( !v4 )
{
fprintf(stderr, "%s:", a1);
func1(v2);
_glewDeleteShader((unsigned int)v2);
LODWORD(v2) = 0;
}
}
else
{
fprintf(stderr, "Error opening %s: ", a1);
perror(&s);
LODWORD(v2) = 0;
}
return (unsigned int)v2;
}

original_code:
GLuint create_shader(const char* filename, GLenum type) {
    const GLchar* source = file_read(filename);
    if (source == ((void *)0)) {
        fprintf(stderr, "Error opening %s: ", filename);
        perror("");
        return 0;
    }
    GLuint res = __glewCreateShader(type);
    __glewShaderSource(res, 1, &source, ((void *)0));
    free((void*) source);
    __glewCompileShader(res);
    GLint compile_ok = 0;
    __glewGetShaderiv(res, 0x8B81, &compile_ok);
    if (compile_ok == 0) {
        fprintf(stderr, "%s:", filename);
        print_log(res);
        __glewDeleteShader(res);
        return 0;
    }
    return res;
}

canonical_original_code:
unsigned int create_shader(char *filename, unsigned int type) {
    char *source = file_read(filename);
    if (source == ((void *)0)) {
        fprintf(stderr, "Error opening %s: ", filename);
        perror("");
        return 0;
    }
    unsigned int res = __glewCreateShader(type);
    __glewShaderSource(res, 1, &source, ((void *)0));
    free((void *) source);
    __glewCompileShader(res);
    int compile_ok = 0;
    __glewGetShaderiv(res, 0x8B81, &compile_ok);
    if (compile_ok == 0) {
        fprintf(stderr, "%s:", filename);
        print_log(res);
        __glewDeleteShader(res);
        return 0;
    }
    return res;
}

variable_types:
filename
char *

variable_types:
type
unsigned int

variable_types:
source
char *

variable_types:
res
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall make_buffer(unsigned int a1, __int64 a2, int a3)
{
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_glewGenBuffers(1LL, v5);
_glewBindBuffer(a1, v5[0]);
_glewBufferData(a1, a3, a2, 35044LL);
return v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2, int a3)
{
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_glewGenBuffers(1LL, v5);
_glewBindBuffer(a1, v5[0]);
_glewBufferData(a1, a3, a2, 35044LL);
return v5[0];
}

original_code:
GLuint make_buffer(
        GLenum target,
        const void *buffer_data,
        GLsizei buffer_size
        ) {
    GLuint buffer;
    __glewGenBuffers(1, &buffer);
    __glewBindBuffer(target, buffer);
    __glewBufferData(target, buffer_size, buffer_data, 0x88E4);
    return buffer;
}

canonical_original_code:
unsigned int make_buffer(unsigned int target, void *buffer_data, int buffer_size) {
    unsigned int buffer;
    __glewGenBuffers(1, &buffer);
    __glewBindBuffer(target, buffer);
    __glewBufferData(target, buffer_size, buffer_data, 0x88E4);
    return buffer;
}

variable_types:
target
unsigned int

variable_types:
buffer
unsigned int


decompiled_code:
__int64 __fastcall make_texture_old(const char *a1)
{
void *v1; // rbx
__int64 result; // rax
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = read_tga(a1, v5, &v4);
result = 0LL;
if ( v1 )
{
glGenTextures(1LL, &v3);
glBindTexture(3553LL, v3);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
glTexParameteri(3553LL, 10242LL, 33071LL);
glTexParameteri(3553LL, 10243LL, 33071LL);
glTexImage2D(3553LL, 0LL, 32849LL, v5[0], v4, 0LL, 32992LL, 5121LL, v1);
free(v1);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1)
{
void *v1; // rbx
__int64 result; // rax
unsigned int v3; // [rsp+4h] [rbp-14h] BYREF
unsigned int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = func5(a1, v5, &v4);
result = 0LL;
if ( v1 )
{
glGenTextures(1LL, &v3);
glBindTexture(3553LL, v3);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
glTexParameteri(3553LL, 10242LL, 33071LL);
glTexParameteri(3553LL, 10243LL, 33071LL);
glTexImage2D(3553LL, 0LL, 32849LL, v5[0], v4, 0LL, 32992LL, 5121LL, v1);
free(v1);
result = v3;
}
return result;
}

original_code:
GLuint make_texture_old(const char *filename) {
    int width, height;
    void *pixels = read_tga(filename, &width, &height);
    GLuint texture;
    if (!pixels)
        return 0;
    glGenTextures(1, &texture);
    glBindTexture(0x0DE1, texture);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2802, 0x812F);
    glTexParameteri(0x0DE1, 0x2803, 0x812F);
    glTexImage2D(
            0x0DE1, 0,
            0x8051,
            width, height, 0,
            0x80E0, 0x1401,
            pixels
            );
    free(pixels);
    return texture;
}

canonical_original_code:
unsigned int make_texture_old(char *filename) {
    int width; int height;
    void *pixels = read_tga(filename, &width, &height);
    unsigned int texture;
    if (!pixels)
        return 0;
    glGenTextures(1, &texture);
    glBindTexture(0x0DE1, texture);
    glTexParameteri(0x0DE1, 0x2801, 0x2601);
    glTexParameteri(0x0DE1, 0x2800, 0x2601);
    glTexParameteri(0x0DE1, 0x2802, 0x812F);
    glTexParameteri(0x0DE1, 0x2803, 0x812F);
    glTexImage2D(
            0x0DE1, 0,
            0x8051,
            width, height, 0,
            0x80E0, 0x1401,
            pixels
            );
    free(pixels);
    return texture;
}

variable_types: width int

variable_types: height int

variable_types:
pixels
void *

variable_types:
texture
unsigned int


decompiled_code:
__int64 __fastcall make_texture(const char *a1)
{
unsigned int v1; // eax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
unsigned int v6; // ebp
unsigned int v7; // eax
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = FreeImage_GetFileType(a1, 0LL);
v2 = FreeImage_Load(v1, a1, 0LL);
v3 = FreeImage_ConvertTo32Bits(v2);
if ( v3 )
{
v4 = v3;
glGenTextures(1LL, v9);
glBindTexture(3553LL, v9[0]);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
v5 = FreeImage_GetBits(v4);
v6 = FreeImage_GetHeight(v4);
v7 = FreeImage_GetWidth(v4);
glTexImage2D(3553LL, 0LL, 4LL, v7, v6, 0LL, 32993LL, 5121LL, v5);
FreeImage_Unload(v4);
}
else
{
fprintf(stderr, "Can't load texture: %s\n", a1);
}
return v9[0];
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
unsigned int v1; // eax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rbx
__int64 v5; // r12
unsigned int v6; // ebp
unsigned int v7; // eax
unsigned int v9[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = FreeImage_GetFileType(a1, 0LL);
v2 = FreeImage_Load(v1, a1, 0LL);
v3 = FreeImage_ConvertTo32Bits(v2);
if ( v3 )
{
v4 = v3;
glGenTextures(1LL, v9);
glBindTexture(3553LL, v9[0]);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9729LL);
v5 = FreeImage_GetBits(v4);
v6 = FreeImage_GetHeight(v4);
v7 = FreeImage_GetWidth(v4);
glTexImage2D(3553LL, 0LL, 4LL, v7, v6, 0LL, 32993LL, 5121LL, v5);
FreeImage_Unload(v4);
}
else
{
fprintf(stderr, "Can't load texture: %s\n", a1);
}
return v9[0];
}

original_code:
GLuint make_texture(const char *filename) {
    GLuint texture;
    FREE_IMAGE_FORMAT fifmt = FreeImage_GetFileType(filename, 0);
    FIBITMAP *dib = FreeImage_Load(fifmt, filename, 0);
    dib = FreeImage_ConvertTo32Bits(dib);
    if (dib != ((void *)0)) {
        glGenTextures(1, &texture);
        glBindTexture(0x0DE1, texture);
        glTexParameteri(0x0DE1, 0x2801, 0x2601);
        glTexParameteri(0x0DE1, 0x2800, 0x2601);
        BYTE *pixels = (BYTE*) FreeImage_GetBits(dib);
        glTexImage2D(0x0DE1, 0, 4, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0,
                0x80E1, 0x1401, pixels);
        FreeImage_Unload(dib);
    } else {
        fprintf(stderr, "Can't load texture: %s\n", filename);
    }
    return texture;
}

canonical_original_code:
unsigned int make_texture(char *filename) {
    unsigned int texture;
    int fifmt = FreeImage_GetFileType(filename, 0);
    struct FIBITMAP *dib = FreeImage_Load(fifmt, filename, 0);
    dib = FreeImage_ConvertTo32Bits(dib);
    if (dib != ((void *)0)) {
        glGenTextures(1, &texture);
        glBindTexture(0x0DE1, texture);
        glTexParameteri(0x0DE1, 0x2801, 0x2601);
        glTexParameteri(0x0DE1, 0x2800, 0x2601);
        unsigned char *pixels = (BYTE*) FreeImage_GetBits(dib);
        glTexImage2D(0x0DE1, 0, 4, FreeImage_GetWidth(dib), FreeImage_GetHeight(dib), 0,
                0x80E1, 0x1401, pixels);
        FreeImage_Unload(dib);
    } else {
        fprintf(stderr, "Can't load texture: %s\n", filename);
    }
    return texture;
}

variable_types: fifmt int

variable_types:
dib
struct FIBITMAP { void *data; } *

variable_types:
pixels
unsigned char *


hardwareInit

repo: rnestler/heligame

decompiled_code:
__int64 hardwareInit()
{
__int64 v0; // rdi
unsigned int v1; // eax
__int64 result; // rax

if ( (int)SDL_Init(32LL) < 0 )
exit(1);
atexit((void (*)(void))&SDL_Quit);
if ( (int)TTF_Init() < 0 )
exit(2);
atexit((void (*)(void))&TTF_Quit);
v0 = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSansMono.ttf", 16LL);
font = v0;
if ( !v0 )
exit(3);
v1 = TTF_FontLineSkip(v0);
printf("The font line skip is: %d\n", v1);
result = SDL_SetVideoMode(320LL, 160LL, 16LL, 0LL);
screen = result;
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rdi
unsigned int v1; // eax
__int64 result; // rax

if ( (int)SDL_Init(32LL) < 0 )
exit(1);
atexit((void (*)(void))&SDL_Quit);
if ( (int)TTF_Init() < 0 )
exit(2);
atexit((void (*)(void))&TTF_Quit);
v0 = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSansMono.ttf", 16LL);
font = v0;
if ( !v0 )
exit(3);
v1 = TTF_FontLineSkip(v0);
printf("The font line skip is: %d\n", v1);
result = SDL_SetVideoMode(320LL, 160LL, 16LL, 0LL);
screen = result;
return result;
}

original_code:
void hardwareInit()
{
 if(SDL_Init(0x00000020)<0) {
  exit(1);
 }
 atexit(SDL_Quit);
 if(TTF_Init() < 0) {
  exit(2);
 }
 atexit(TTF_Quit);
 font = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSansMono.ttf", 8*2);
 if(!font) {
  exit(3);
 }
 printf("The font line skip is: %d\n", TTF_FontLineSkip(font));
 Uint32 flags = 0x00000000;
 screen = SDL_SetVideoMode(160*2, 80*2, 16, flags);
}

canonical_original_code:
void hardwareInit()
{
 if(SDL_Init(0x00000020)<0) {
  exit(1);
 }
 atexit(SDL_Quit);
 if(TTF_Init() < 0) {
  exit(2);
 }
 atexit(TTF_Quit);
 font = TTF_OpenFont("/usr/share/fonts/TTF/DejaVuSansMono.ttf", 8*2);
 if(!font) {
  exit(3);
 }
 printf("The font line skip is: %d\n", TTF_FontLineSkip(font));
 unsigned int flags = 0x00000000;
 screen = SDL_SetVideoMode(160*2, 80*2, 16, flags);
}

variable_types:
flags
unsigned int


DelayMs

decompiled_code:
__int64 DelayMs()
{
return SDL_Delay();
}

canonical_decompiled_code:
__int64 func3()
{
return SDL_Delay();
}

original_code:
void DelayMs (int ms)
{
 SDL_Delay(ms);
}

canonical_original_code:
void DelayMs(int ms)
{
 SDL_Delay(ms);
}

variable_types: ms int


DisplayClrArea

decompiled_code:
__int64 __fastcall DisplayClrArea(__int16 a1, __int16 a2, __int16 a3, __int16 a4)
{
__int16 v5[8]; // [rsp+8h] [rbp-10h] BYREF

v5[0] = a1;
v5[1] = a2;
v5[2] = 2 * a3;
v5[3] = 2 * a4;
SDL_FillRect(screen, v5, 0LL);
return SDL_UpdateRect(screen, 0LL, 0LL, 320LL, 160LL);
}

original_code:
void DisplayClrArea (int x_start, int y_start, int x_end, int y_end)
{
 SDL_Rect rect;
 rect.x = x_start;
 rect.y = y_start;
 rect.w = x_end*2;
 rect.h = y_end*2;
 SDL_FillRect(screen, &rect, 0x000000);
 SDL_UpdateRect(screen, 0, 0, 160*2, 80*2);
}

canonical_original_code:
void DisplayClrArea(int x_start, int y_start, int x_end, int y_end)
{
 struct SDL_Rect rect;
 rect.x = x_start;
 rect.y = y_start;
 rect.w = x_end*2;
 rect.h = y_end*2;
 SDL_FillRect(screen, &rect, 0x000000);
 SDL_UpdateRect(screen, 0, 0, 160*2, 80*2);
}

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


DisplaySetPoint

decompiled_code:
__int64 __fastcall DisplaySetPoint(__int16 a1, __int16 a2)
{
__int16 v3[8]; // [rsp+8h] [rbp-10h] BYREF

v3[0] = 2 * a1;
v3[1] = 2 * (80 - a2);
v3[2] = 2;
v3[3] = 2;
return SDL_FillRect(screen, v3, 0xFFFFFFLL);
}

original_code:
int DisplaySetPoint (int x, int y)
{
 SDL_Rect rect;
 rect.x = 2*x;
 rect.y = 2*(80-y);
 rect.w = 2;
 rect.h = 2;
 return SDL_FillRect(screen,
               &rect,
      0xFFFFFF);
}

canonical_original_code:
int DisplaySetPoint(int x, int y)
{
 struct SDL_Rect rect;
 rect.x = 2*x;
 rect.y = 2*(80-y);
 rect.w = 2;
 rect.h = 2;
 return SDL_FillRect(screen,
               &rect,
      0xFFFFFF);
}

variable_types: x int

variable_types: y int

user_defined_types: struct SDL_Rect { short x; unsigned short w; }


DisplayClrPoint

original_code:
int DisplayClrPoint (int x, int y)
{
 SDL_Rect rect;
 rect.x = 2*x;
 rect.y = 2*(80-y);
 rect.w = 2;
 rect.h = 2;
 return SDL_FillRect(screen,
               &rect,
      0x000000);
}

canonical_original_code:
int DisplayClrPoint(int x, int y)
{
 struct SDL_Rect rect;
 rect.x = 2*x;
 rect.y = 2*(80-y);
 rect.w = 2;
 rect.h = 2;
 return SDL_FillRect(screen,
               &rect,
      0x000000);
}


DisplayDrawCircle

decompiled_code:
__int64 __fastcall DisplayDrawCircle(__int16 a1, __int16 a2, int a3)
{
int v3; // ebp
int v4; // er14
int i; // ebx
int v7; // [rsp+Ch] [rbp-3Ch]

v3 = a3;
v4 = 1 - a3;
v7 = -2 * a3;
DisplaySetPoint(a1, a3 + a2);
DisplaySetPoint(a1, a2 - v3);
DisplaySetPoint(v3 + a1, a2);
DisplaySetPoint(a1 - v3, a2);
if ( v3 > 0 )
{
for ( i = 0; i < v3; DisplaySetPoint(a1 - v3, a2 - i) )
{
if ( v4 >= 0 )
{
--v3;
v7 += 2;
v4 += v7;
}
++i;
v4 += 2 * i + 1;
DisplaySetPoint(a1 + i, v3 + a2);
DisplaySetPoint(a1 - i, v3 + a2);
DisplaySetPoint(a1 + i, a2 - v3);
DisplaySetPoint(a1 - i, a2 - v3);
DisplaySetPoint(v3 + a1, i + a2);
DisplaySetPoint(a1 - v3, i + a2);
DisplaySetPoint(v3 + a1, a2 - i);
}
}
return SDL_UpdateRect(screen, 0LL, 0LL, 320LL, 160LL);
}

original_code:
void DisplayDrawCircle(int x0, int y0, int radius)
{
    int f = 1 - radius;
    int ddF_x = 0;
    int ddF_y = -2 * radius;
    int x = 0;
    int y = radius;
    DisplaySetPoint(x0, y0 + radius);
    DisplaySetPoint(x0, y0 - radius);
    DisplaySetPoint(x0 + radius, y0);
    DisplaySetPoint(x0 - radius, y0);
    while(x < y)
    {
       if(f >= 0)
       {
          y--;
          ddF_y += 2;
          f += ddF_y;
       }
       x++;
       ddF_x += 2;
       f += ddF_x + 1;
       DisplaySetPoint(x0 + x, y0 + y);
       DisplaySetPoint(x0 - x, y0 + y);
       DisplaySetPoint(x0 + x, y0 - y);
       DisplaySetPoint(x0 - x, y0 - y);
       DisplaySetPoint(x0 + y, y0 + x);
       DisplaySetPoint(x0 - y, y0 + x);
       DisplaySetPoint(x0 + y, y0 - x);
       DisplaySetPoint(x0 - y, y0 - x);
    }
 SDL_UpdateRect(screen, 0, 0, 160*2, 80*2);
}

variable_types: radius int

variable_types: f int


DisplayClearCircle

decompiled_code:
__int64 __fastcall DisplayClearCircle(__int16 a1, __int16 a2, int a3)
{
int v3; // ebp
int v4; // er14
__int64 result; // rax
int i; // ebx
int v7; // [rsp+Ch] [rbp-3Ch]

v3 = a3;
v4 = 1 - a3;
v7 = -2 * a3;
DisplayClrPoint(a1, a3 + a2);
DisplayClrPoint(a1, a2 - v3);
DisplayClrPoint(v3 + a1, a2);
result = DisplayClrPoint(a1 - (unsigned __int16)v3, a2);
if ( v3 > 0 )
{
for ( i = 0; i < v3; result = DisplayClrPoint(a1 - (unsigned __int16)v3, a2 - (unsigned __int16)i) )
{
if ( v4 >= 0 )
{
--v3;
v7 += 2;
v4 += v7;
}
++i;
v4 += 2 * i + 1;
DisplayClrPoint(a1 + i, v3 + a2);
DisplayClrPoint(a1 - i, v3 + a2);
DisplayClrPoint(a1 + i, a2 - v3);
DisplayClrPoint(a1 - i, a2 - v3);
DisplayClrPoint(v3 + a1, i + a2);
DisplayClrPoint(a1 - v3, i + a2);
DisplayClrPoint(v3 + a1, a2 - i);
}
}
return result;
}

original_code:
void DisplayClearCircle(int x0, int y0, int radius)
{
    int f = 1 - radius;
    int ddF_x = 0;
    int ddF_y = -2 * radius;
    int x = 0;
    int y = radius;
    DisplayClrPoint(x0, y0 + radius);
    DisplayClrPoint(x0, y0 - radius);
    DisplayClrPoint(x0 + radius, y0);
    DisplayClrPoint(x0 - radius, y0);
    while(x < y)
    {
       if(f >= 0)
       {
          y--;
          ddF_y += 2;
          f += ddF_y;
       }
       x++;
       ddF_x += 2;
       f += ddF_x + 1;
       DisplayClrPoint(x0 + x, y0 + y);
       DisplayClrPoint(x0 - x, y0 + y);
       DisplayClrPoint(x0 + x, y0 - y);
       DisplayClrPoint(x0 - x, y0 - y);
       DisplayClrPoint(x0 + y, y0 + x);
       DisplayClrPoint(x0 - y, y0 + x);
       DisplayClrPoint(x0 + y, y0 - x);
       DisplayClrPoint(x0 - y, y0 - x);
    }
}


DisplayDrawLine

decompiled_code:
__int64 __fastcall DisplayDrawLine(int a1, int a2, int a3, int a4)
{
int v4; // ebp
int v5; // ebx
int v6; // er12
int v7; // esi
signed int v8; // er13
signed int v9; // er12
int v10; // er14
int v11; // er15
signed int v12; // er14
__int64 result; // rax
int i; // er13
signed int v15; // er12
int v16; // eax
int v17; // er12
int v18; // er15

v4 = a1;
v5 = a2;
v6 = a4 - a2;
if ( a3 == a1 )
{
if ( v6 >= 0 )
{
for ( i = 0; i <= v6; ++i )
result = DisplaySetPoint(a1, (unsigned __int16)a2 + (unsigned __int16)i);
}
}
else
{
v7 = a3;
v8 = abs32(a3 - a1);
if ( a4 == v5 )
{
v15 = 0;
do
result = DisplaySetPoint((unsigned __int16)v15++ + (unsigned __int16)a1, v5);
while ( v8 >= v15 );
}
else
{
v9 = abs32(v6);
v10 = v9 / v8;
if ( v9 / v8 )
{
if ( a4 < v5 )
{
LOWORD(v5) = a4;
v4 = a3;
v7 = a1;
}
v11 = 0;
v12 = 0;
do
{
result = DisplaySetPoint(
(unsigned __int16)(v11 / v9) + (unsigned __int16)v4,
(unsigned __int16)v12++ + (unsigned __int16)v5);
v11 += v7 - v4;
}
while ( v9 >= v12 );
}
else
{
if ( a3 < a1 )
{
v16 = v5;
v5 = a4;
a4 = v16;
LOWORD(v4) = a3;
}
v17 = a4 - v5;
v18 = 0;
do
{
result = DisplaySetPoint(
(unsigned __int16)v4 + (unsigned __int16)v10++,
(unsigned __int16)(v18 / v8) + (unsigned __int16)v5);
v18 += v17;
}
while ( v8 >= v10 );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2, int a3, int a4)
{
int v4; // ebp
int v5; // ebx
int v6; // er12
int v7; // esi
signed int v8; // er13
signed int v9; // er12
int v10; // er14
int v11; // er15
signed int v12; // er14
__int64 result; // rax
int i; // er13
signed int v15; // er12
int v16; // eax
int v17; // er12
int v18; // er15

v4 = a1;
v5 = a2;
v6 = a4 - a2;
if ( a3 == a1 )
{
if ( v6 >= 0 )
{
for ( i = 0; i <= v6; ++i )
result = func5(a1, (unsigned __int16)a2 + (unsigned __int16)i);
}
}
else
{
v7 = a3;
v8 = abs32(a3 - a1);
if ( a4 == v5 )
{
v15 = 0;
do
result = func5((unsigned __int16)v15++ + (unsigned __int16)a1, v5);
while ( v8 >= v15 );
}
else
{
v9 = abs32(v6);
v10 = v9 / v8;
if ( v9 / v8 )
{
if ( a4 < v5 )
{
LOWORD(v5) = a4;
v4 = a3;
v7 = a1;
}
v11 = 0;
v12 = 0;
do
{
result = func5(
(unsigned __int16)(v11 / v9) + (unsigned __int16)v4,
(unsigned __int16)v12++ + (unsigned __int16)v5);
v11 += v7 - v4;
}
while ( v9 >= v12 );
}
else
{
if ( a3 < a1 )
{
v16 = v5;
v5 = a4;
a4 = v16;
LOWORD(v4) = a3;
}
v17 = a4 - v5;
v18 = 0;
do
{
result = func5(
(unsigned __int16)v4 + (unsigned __int16)v10++,
(unsigned __int16)(v18 / v8) + (unsigned __int16)v5);
v18 += v17;
}
while ( v8 >= v10 );
}
}
}
return result;
}

original_code:
void DisplayDrawLine (int x_start, int y_start, int x_end, int y_end)
{
 int x, y, temp, delta_x, delta_y;
 delta_x = abs(x_end - x_start);
 delta_y = abs(y_end - y_start);
 if (delta_x == 0)
  for (y = 0; y <= (y_end-y_start); y++)
   DisplaySetPoint(x_start, y+y_start);
 else if (delta_y == 0)
  for(x = 0; x <= (delta_x); x++)
   DisplaySetPoint(x+x_start, y_start);
 else if (delta_y / delta_x)
 {
  if (y_end < y_start)
  {
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   temp = x_end;
   x_end = x_start;
   x_start = temp;
  }
  for(y = 0; y <= (delta_y); y++)
  {
   x = x_start + y * (x_end - x_start) / (delta_y);
   DisplaySetPoint(x, y_start + y);
  }
 }
 else
  {
  if (x_end < x_start)
  {
   temp = x_end;
   x_end = x_start;
   x_start = temp;
   temp = y_end;
   y_end = y_start;
   y_start = temp;
  }
  for (x = 0; x <= (delta_x); x++)
  {
   y = y_start + x * (y_end - y_start) / (delta_x);
   DisplaySetPoint(x_start + x, y);
  }
 }
}

canonical_original_code:
void DisplayDrawLine(int x_start, int y_start, int x_end, int y_end)
{
 int x; int y; int temp; int delta_x; int delta_y;
 delta_x = abs(x_end - x_start);
 delta_y = abs(y_end - y_start);
 if (delta_x == 0)
  for (y = 0; y <= (y_end-y_start); y++)
   DisplaySetPoint(x_start, y+y_start);
 else if (delta_y == 0)
  for(x = 0; x <= (delta_x); x++)
   DisplaySetPoint(x+x_start, y_start);
 else if (delta_y / delta_x)
 {
  if (y_end < y_start)
  {
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   temp = x_end;
   x_end = x_start;
   x_start = temp;
  }
  for(y = 0; y <= (delta_y); y++)
  {
   x = x_start + y * (x_end - x_start) / (delta_y);
   DisplaySetPoint(x, y_start + y);
  }
 }
 else
  {
  if (x_end < x_start)
  {
   temp = x_end;
   x_end = x_start;
   x_start = temp;
   temp = y_end;
   y_end = y_start;
   y_start = temp;
  }
  for (x = 0; x <= (delta_x); x++)
  {
   y = y_start + x * (y_end - y_start) / (delta_x);
   DisplaySetPoint(x_start + x, y);
  }
 }
}

variable_types: temp int


DisplayClrLine

decompiled_code:
__int64 __fastcall DisplayClrLine(int a1, int a2, int a3, int a4)
{
int v4; // ebp
int v5; // ebx
int v6; // er12
int v7; // esi
signed int v8; // er13
signed int v9; // er12
int v10; // er14
int v11; // er15
signed int v12; // er14
__int64 result; // rax
int i; // er13
signed int v15; // er12
int v16; // eax
int v17; // er12
int v18; // er15

v4 = a1;
v5 = a2;
v6 = a4 - a2;
if ( a3 == a1 )
{
if ( v6 >= 0 )
{
for ( i = 0; i <= v6; ++i )
result = DisplayClrPoint(a1, (unsigned __int16)a2 + (unsigned __int16)i);
}
}
else
{
v7 = a3;
v8 = abs32(a3 - a1);
if ( a4 == v5 )
{
v15 = 0;
do
result = DisplayClrPoint((unsigned __int16)v15++ + (unsigned __int16)a1, v5);
while ( v8 >= v15 );
}
else
{
v9 = abs32(v6);
v10 = v9 / v8;
if ( v9 / v8 )
{
if ( a4 < v5 )
{
LOWORD(v5) = a4;
v4 = a3;
v7 = a1;
}
v11 = 0;
v12 = 0;
do
{
result = DisplayClrPoint(
(unsigned __int16)(v11 / v9) + (unsigned __int16)v4,
(unsigned __int16)v12++ + (unsigned __int16)v5);
v11 += v7 - v4;
}
while ( v9 >= v12 );
}
else
{
if ( a3 < a1 )
{
v16 = v5;
v5 = a4;
a4 = v16;
LOWORD(v4) = a3;
}
v17 = a4 - v5;
v18 = 0;
do
{
result = DisplayClrPoint(
(unsigned __int16)v4 + (unsigned __int16)v10++,
(unsigned __int16)(v18 / v8) + (unsigned __int16)v5);
v18 += v17;
}
while ( v8 >= v10 );
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, int a2, int a3, int a4)
{
int v4; // ebp
int v5; // ebx
int v6; // er12
int v7; // esi
signed int v8; // er13
signed int v9; // er12
int v10; // er14
int v11; // er15
signed int v12; // er14
__int64 result; // rax
int i; // er13
signed int v15; // er12
int v16; // eax
int v17; // er12
int v18; // er15

v4 = a1;
v5 = a2;
v6 = a4 - a2;
if ( a3 == a1 )
{
if ( v6 >= 0 )
{
for ( i = 0; i <= v6; ++i )
result = func6(a1, (unsigned __int16)a2 + (unsigned __int16)i);
}
}
else
{
v7 = a3;
v8 = abs32(a3 - a1);
if ( a4 == v5 )
{
v15 = 0;
do
result = func6((unsigned __int16)v15++ + (unsigned __int16)a1, v5);
while ( v8 >= v15 );
}
else
{
v9 = abs32(v6);
v10 = v9 / v8;
if ( v9 / v8 )
{
if ( a4 < v5 )
{
LOWORD(v5) = a4;
v4 = a3;
v7 = a1;
}
v11 = 0;
v12 = 0;
do
{
result = func6(
(unsigned __int16)(v11 / v9) + (unsigned __int16)v4,
(unsigned __int16)v12++ + (unsigned __int16)v5);
v11 += v7 - v4;
}
while ( v9 >= v12 );
}
else
{
if ( a3 < a1 )
{
v16 = v5;
v5 = a4;
a4 = v16;
LOWORD(v4) = a3;
}
v17 = a4 - v5;
v18 = 0;
do
{
result = func6(
(unsigned __int16)v4 + (unsigned __int16)v10++,
(unsigned __int16)(v18 / v8) + (unsigned __int16)v5);
v18 += v17;
}
while ( v8 >= v10 );
}
}
}
return result;
}

original_code:
void DisplayClrLine (int x_start, int y_start, int x_end, int y_end)
{
 int x, y, temp, delta_x, delta_y;
 delta_x = abs(x_end - x_start);
 delta_y = abs(y_end - y_start);
 if (delta_x == 0)
  for (y = 0; y <= (y_end-y_start); y++)
   DisplayClrPoint(x_start, y+y_start);
 else if (delta_y == 0)
  for(x = 0; x <= (delta_x); x++)
   DisplayClrPoint(x + x_start, y_start);
 else if (delta_y / delta_x)
 {
  if (y_end < y_start)
  {
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   temp = x_end;
   x_end = x_start;
   x_start = temp;
  }
  for (y = 0; y <= (delta_y); y++)
  {
   x = x_start + y * (x_end - x_start) / (delta_y);
   DisplayClrPoint(x, y_start + y);
  }
 }
 else
 {
  if (x_end < x_start)
  {
   temp = x_end;
   x_end = x_start;
   x_start = temp;
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   }
  for (x = 0; x <= (delta_x); x++)
  {
   y = y_start + x * (y_end - y_start) / (delta_x);
   DisplayClrPoint(x_start + x, y);
  }
 }
}

canonical_original_code:
void DisplayClrLine(int x_start, int y_start, int x_end, int y_end)
{
 int x; int y; int temp; int delta_x; int delta_y;
 delta_x = abs(x_end - x_start);
 delta_y = abs(y_end - y_start);
 if (delta_x == 0)
  for (y = 0; y <= (y_end-y_start); y++)
   DisplayClrPoint(x_start, y+y_start);
 else if (delta_y == 0)
  for(x = 0; x <= (delta_x); x++)
   DisplayClrPoint(x + x_start, y_start);
 else if (delta_y / delta_x)
 {
  if (y_end < y_start)
  {
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   temp = x_end;
   x_end = x_start;
   x_start = temp;
  }
  for (y = 0; y <= (delta_y); y++)
  {
   x = x_start + y * (x_end - x_start) / (delta_y);
   DisplayClrPoint(x, y_start + y);
  }
 }
 else
 {
  if (x_end < x_start)
  {
   temp = x_end;
   x_end = x_start;
   x_start = temp;
   temp = y_end;
   y_end = y_start;
   y_start = temp;
   }
  for (x = 0; x <= (delta_x); x++)
  {
   y = y_start + x * (y_end - y_start) / (delta_x);
   DisplayClrPoint(x_start + x, y);
  }
 }
}


decompiled_code:
__int64 __fastcall change_state(int *a1, int a2)
{
int v2; // eax

v2 = *a1;
if ( *a1 == 1 )
{
game_state_game(a1, 1LL);
}
else if ( v2 == 2 )
{
game_state_highscore(a1, 1LL);
}
else
{
if ( v2 )
exit(-1);
game_state_menu(a1, 1LL);
}
*a1 = a2;
if ( a2 == 1 )
return game_state_game(a1, 0LL);
if ( a2 == 2 )
return game_state_highscore(a1, 0LL);
if ( a2 )
exit(-1);
return game_state_menu(a1, 0LL);
}

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

v2 = *a1;
if ( *a1 == 1 )
{
func2(a1, 1LL);
}
else if ( v2 == 2 )
{
func3(a1, 1LL);
}
else
{
if ( v2 )
exit(-1);
func1(a1, 1LL);
}
*a1 = a2;
if ( a2 == 1 )
return func2(a1, 0LL);
if ( a2 == 2 )
return func3(a1, 0LL);
if ( a2 )
exit(-1);
return func1(a1, 0LL);
}

original_code:
void change_state(Game *game, GameState new)
{
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, EEventExit);
   break;
  case EStateGame:
   game_state_game(game, EEventExit);
   break;
  case EStateHighScore:
   game_state_highscore(game, EEventExit);
   break;
  default:
   exit(-1);
 }
 game->state = new;
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, EEventEntry);
   break;
  case EStateGame:
   game_state_game(game, EEventEntry);
   break;
  case EStateHighScore:
   game_state_highscore(game, EEventEntry);
   break;
  default:
   exit(-1);
 }
}

canonical_original_code:
void change_state(struct Game *game, enum GameState new)
{
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, EEventExit);
   break;
  case EStateGame:
   game_state_game(game, EEventExit);
   break;
  case EStateHighScore:
   game_state_highscore(game, EEventExit);
   break;
  default:
   exit(-1);
 }
 game->state = new;
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, EEventEntry);
   break;
  case EStateGame:
   game_state_game(game, EEventEntry);
   break;
  case EStateHighScore:
   game_state_highscore(game, EEventEntry);
   break;
  default:
   exit(-1);
 }
}

variable_types: struct Game { enum GameState { EStateMenu=0, EStateGame=1, EStateHighScore=2 } state; struct Wall { float x; int y1; } wall; struct Heli { float x; float speed; } heli; struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; } landscape; unsigned int menuitem; int scapeSize; unsigned int startTicks; unsigned int oldTime; unsigned int difficultyTimer; int keyState[4]; int keys[4]; int currentKey; unsigned int highscore[10]; } *

user_defined_types: struct Game { enum GameState state; struct Wall wall; struct Heli heli; struct Landscape landscape; unsigned int menuitem; int scapeSize; unsigned int startTicks; unsigned int oldTime; unsigned int difficultyTimer; int keyState[4]; int keys[4]; int currentKey; unsigned int highscore[10]; }


decompiled_code:
void __fastcall game_state_menu(int *a1, __int64 a2)
{
int v2; // eax
int v3; // eax
__int64 v4; // rsi

if ( (_DWORD)a2 )
{
if ( (_DWORD)a2 == 3 )
{
v2 = a1[115];
if ( v2 == 97 )
{
MIODispWriteText(" ", (unsigned int)a1[102], 1LL);
v4 = (a1[102] & 1u) + 1;
a1[102] = v4;
MIODispWriteText(">", v4, 1LL);
}
else if ( v2 == 119 )
{
v3 = a1[102];
if ( v3 == 1 )
{
change_state(a1, 1);
}
else if ( v3 == 2 )
{
change_state(a1, 2);
}
}
}
}
else
{
DisplayClrArea(0LL, a2, 160LL, 80LL);
MIODispWriteText("> Start", 1LL, 1LL);
MIODispWriteText(" Highscore", 2LL, 1LL);
a1[102] = 1;
}
}

canonical_decompiled_code:
void __fastcall func1(int *a1, __int64 a2)
{
int v2; // eax
int v3; // eax
__int64 v4; // rsi

if ( (_DWORD)a2 )
{
if ( (_DWORD)a2 == 3 )
{
v2 = a1[115];
if ( v2 == 97 )
{
MIODispWriteText(" ", (unsigned int)a1[102], 1LL);
v4 = (a1[102] & 1u) + 1;
a1[102] = v4;
MIODispWriteText(">", v4, 1LL);
}
else if ( v2 == 119 )
{
v3 = a1[102];
if ( v3 == 1 )
{
func0(a1, 1);
}
else if ( v3 == 2 )
{
func0(a1, 2);
}
}
}
}
else
{
DisplayClrArea(0LL, a2, 160LL, 80LL);
MIODispWriteText("> Start", 1LL, 1LL);
MIODispWriteText(" Highscore", 2LL, 1LL);
a1[102] = 1;
}
}

original_code:
void game_state_menu(Game *game, GameEvent event)
{
 static const unsigned nitem=2;
 if(event == EEventEntry) {
  DisplayClrArea (0, 0, 160, 80);
  MIODispWriteText("> Start",1,1);
  MIODispWriteText("  Highscore",2,1);
  game->menuitem=1;
  return;
 } else if(event == EEventExit) {
  return;
 } else if(event == EEventKeyDown) {
  switch(game->currentKey) {
   case SDLK_w:
    switch(game->menuitem) {
     case 1:
      change_state(game, EStateGame);
      break;
     case 2:
      change_state(game, EStateHighScore);
      break;
    }
    break;
   case SDLK_a:
    MIODispWriteText(" ",game->menuitem,1);
    game->menuitem = (game->menuitem%nitem)+1;
    MIODispWriteText(">",game->menuitem,1);
    break;
  }
 }
 else if(event == EEventRun) {
 }
}

canonical_original_code:
void game_state_menu(struct Game *game, enum GameEvent event)
{
 static unsigned int nitem = 2;
 if(event == EEventEntry) {
  DisplayClrArea (0, 0, 160, 80);
  MIODispWriteText("> Start",1,1);
  MIODispWriteText("  Highscore",2,1);
  game->menuitem=1;
  return;
 } else if(event == EEventExit) {
  return;
 } else if(event == EEventKeyDown) {
  switch(game->currentKey) {
   case SDLK_w:
    switch(game->menuitem) {
     case 1:
      change_state(game, EStateGame);
      break;
     case 2:
      change_state(game, EStateHighScore);
      break;
    }
    break;
   case SDLK_a:
    MIODispWriteText(" ",game->menuitem,1);
    game->menuitem = (game->menuitem%nitem)+1;
    MIODispWriteText(">",game->menuitem,1);
    break;
  }
 }
 else if(event == EEventRun) {
 }
}

variable_types: enum GameEvent { EEventEntry=0, EEventExit=1, EEventRun=2, EEventKeyDown=3, EEventKeyUp=4 }

variable_types:
nitem
unsigned int

user_defined_types: enum GameState { EStateMenu=0, EStateGame=1, EStateHighScore=2 }

user_defined_types: struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; }


decompiled_code:
void __fastcall game_state_game(__int64 a1, int a2)
{
unsigned int v2; // ebp
unsigned int v3; // eax
int v4; // eax
unsigned int v5; // ebp
__int64 v6; // rax
unsigned int v7; // edx
_DWORD *v8; // rax
int v9; // ebp
unsigned int v10; // er12
int v11; // eax
unsigned int v12; // er12
unsigned int v13; // eax
__int64 v14; // rdx
__int64 v15; // rsi
unsigned int v16; // eax
char s[50]; // [rsp+6h] [rbp-32h] BYREF

if ( a2 )
{
if ( a2 == 1 )
{
v5 = ((unsigned int)SDL_GetTicks() - *(_DWORD *)(a1 + 416)) / 0x64;
printf("Score: %i\n", v5);
v6 = 0LL;
while ( 1 )
{
v7 = v6;
if ( *(_DWORD *)(a1 + 4 * v6 + 464) < v5 )
break;
if ( ++v6 == 10 )
return;
}
if ( (unsigned int)v6 <= 8 )
{
v8 = (_DWORD *)(a1 + 496);
do
{
v8[1] = *v8;
--v8;
}
while ( v8 != (_DWORD *)(a1 + 492 - 4LL * (8 - v7)) );
}
*(_DWORD *)(a1 + 4LL * v7 + 464) = v5;
}
else if ( a2 == 2 )
{
v9 = SDL_GetTicks();
v10 = v9 - *(_DWORD *)(a1 + 420);
*(_DWORD *)(a1 + 420) = v9;
sprintf(s, "%i", (unsigned int)(v9 - *(_DWORD *)(a1 + 416)) / 0x64uLL);
MIODispWriteText(s, 9LL, 0LL);
if ( (unsigned int)(v9 - *(_DWORD *)(a1 + 424)) > 0x3E8 )
{
*(_DWORD *)(a1 + 424) = v9;
++rangeYHight;
if ( rangeYHight <= 40 )
{
v11 = *(_DWORD *)(a1 + 412) - 1;
if ( v11 > 9 )
*(_DWORD *)(a1 + 412) = v11;
else
*(_DWORD *)(a1 + 412) = 10;
}
else
{
*(_DWORD *)(a1 + 412) = 39;
}
}
heli_clear(a1 + 16);
if ( (unsigned int)DIORead(119LL) )
heli_update(a1 + 16, v10, 0.001);
else
heli_update(a1 + 16, v10, -0.001);
heli_draw(a1 + 16);
landscapeFlow(a1 + 28, *(unsigned int *)(a1 + 412));
wall_clear(a1 + 4);
wall_update(a1 + 4, v10);
if ( *(float *)(a1 + 4) <= 0.0 )
{
v12 = getYBottom(a1 + 28, 160LL);
v13 = getYRoof(a1 + 28, 160LL);
v14 = v13;
v15 = (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8) + 1);
v16 = v13 - v12;
if ( (int)(v16 - 19) <= (int)v15 )
{
v15 = v16 - 20;
if ( (int)(v16 - 20) <= 0 )
v15 = 1LL;
}
wall_init(a1 + 4, v15, v14, v12);
}
wall_draw(a1 + 4);
if ( (unsigned int)heli_check_collision(
a1 + 16,
*(float *)(a1 + 4),
(float)*(int *)(a1 + 8),
*(float *)(a1 + 4),
(float)*(int *)(a1 + 12)) )
change_state((int *)a1, 2);
if ( (unsigned int)touch(
a1 + 28,
(unsigned int)(int)*(float *)(a1 + 16),
(unsigned int)(int)(float)(*(float *)(a1 + 20) + 5.0)) )
change_state((int *)a1, 2);
if ( (unsigned int)touch(
a1 + 28,
(unsigned int)(int)*(float *)(a1 + 16),
(unsigned int)(int)(float)(*(float *)(a1 + 20) - 5.0)) )
change_state((int *)a1, 2);
}
}
else
{
puts("game entry");
rangeYHight = 1;
DisplayClrArea(0LL, 0LL, 160LL, 80LL);
initLandscape(a1 + 28, 70LL);
heli_init(a1 + 16);
v2 = getYBottom(a1 + 28, 159LL);
v3 = getYRoof(a1 + 28, 159LL);
wall_init(a1 + 4, 10LL, v3, v2);
*(_DWORD *)(a1 + 412) = 70;
v4 = SDL_GetTicks();
*(_DWORD *)(a1 + 416) = v4;
*(_DWORD *)(a1 + 420) = v4;
*(_DWORD *)(a1 + 424) = v4;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
unsigned int v2; // ebp
unsigned int v3; // eax
int v4; // eax
unsigned int v5; // ebp
__int64 v6; // rax
unsigned int v7; // edx
_DWORD *v8; // rax
int v9; // ebp
unsigned int v10; // er12
int v11; // eax
unsigned int v12; // er12
unsigned int v13; // eax
__int64 v14; // rdx
__int64 v15; // rsi
unsigned int v16; // eax
char s[50]; // [rsp+6h] [rbp-32h] BYREF

if ( a2 )
{
if ( a2 == 1 )
{
v5 = ((unsigned int)SDL_GetTicks() - *(_DWORD *)(a1 + 416)) / 0x64;
printf("Score: %i\n", v5);
v6 = 0LL;
while ( 1 )
{
v7 = v6;
if ( *(_DWORD *)(a1 + 4 * v6 + 464) < v5 )
break;
if ( ++v6 == 10 )
return;
}
if ( (unsigned int)v6 <= 8 )
{
v8 = (_DWORD *)(a1 + 496);
do
{
v8[1] = *v8;
--v8;
}
while ( v8 != (_DWORD *)(a1 + 492 - 4LL * (8 - v7)) );
}
*(_DWORD *)(a1 + 4LL * v7 + 464) = v5;
}
else if ( a2 == 2 )
{
v9 = SDL_GetTicks();
v10 = v9 - *(_DWORD *)(a1 + 420);
*(_DWORD *)(a1 + 420) = v9;
sprintf(s, "%i", (unsigned int)(v9 - *(_DWORD *)(a1 + 416)) / 0x64uLL);
MIODispWriteText(s, 9LL, 0LL);
if ( (unsigned int)(v9 - *(_DWORD *)(a1 + 424)) > 0x3E8 )
{
*(_DWORD *)(a1 + 424) = v9;
++rangeYHight;
if ( rangeYHight <= 40 )
{
v11 = *(_DWORD *)(a1 + 412) - 1;
if ( v11 > 9 )
*(_DWORD *)(a1 + 412) = v11;
else
*(_DWORD *)(a1 + 412) = 10;
}
else
{
*(_DWORD *)(a1 + 412) = 39;
}
}
heli_clear(a1 + 16);
if ( (unsigned int)DIORead(119LL) )
heli_update(a1 + 16, v10, 0.001);
else
heli_update(a1 + 16, v10, -0.001);
heli_draw(a1 + 16);
landscapeFlow(a1 + 28, *(unsigned int *)(a1 + 412));
wall_clear(a1 + 4);
wall_update(a1 + 4, v10);
if ( *(float *)(a1 + 4) <= 0.0 )
{
v12 = getYBottom(a1 + 28, 160LL);
v13 = getYRoof(a1 + 28, 160LL);
v14 = v13;
v15 = (unsigned int)(*(_DWORD *)(a1 + 12) - *(_DWORD *)(a1 + 8) + 1);
v16 = v13 - v12;
if ( (int)(v16 - 19) <= (int)v15 )
{
v15 = v16 - 20;
if ( (int)(v16 - 20) <= 0 )
v15 = 1LL;
}
wall_init(a1 + 4, v15, v14, v12);
}
wall_draw(a1 + 4);
if ( (unsigned int)heli_check_collision(
a1 + 16,
*(float *)(a1 + 4),
(float)*(int *)(a1 + 8),
*(float *)(a1 + 4),
(float)*(int *)(a1 + 12)) )
func0((int *)a1, 2);
if ( (unsigned int)touch(
a1 + 28,
(unsigned int)(int)*(float *)(a1 + 16),
(unsigned int)(int)(float)(*(float *)(a1 + 20) + 5.0)) )
func0((int *)a1, 2);
if ( (unsigned int)touch(
a1 + 28,
(unsigned int)(int)*(float *)(a1 + 16),
(unsigned int)(int)(float)(*(float *)(a1 + 20) - 5.0)) )
func0((int *)a1, 2);
}
}
else
{
puts("game entry");
rangeYHight = 1;
DisplayClrArea(0LL, 0LL, 160LL, 80LL);
initLandscape(a1 + 28, 70LL);
heli_init(a1 + 16);
v2 = getYBottom(a1 + 28, 159LL);
v3 = getYRoof(a1 + 28, 159LL);
wall_init(a1 + 4, 10LL, v3, v2);
*(_DWORD *)(a1 + 412) = 70;
v4 = SDL_GetTicks();
*(_DWORD *)(a1 + 416) = v4;
*(_DWORD *)(a1 + 420) = v4;
*(_DWORD *)(a1 + 424) = v4;
}
}

original_code:
void game_state_game(Game *game, GameEvent event)
{
 if(event == EEventEntry) {
  printf("game entry\n");
  rangeYHight = 1;
  DisplayClrArea (0, 0, 160, 80);
  initLandscape(&game->landscape, 70);
  heli_init(&game->heli);
  wall_init(&game->wall, 10, getYRoof(&game->landscape, 159), getYBottom(&game->landscape, 159) );
  game->scapeSize=70;
  game->startTicks = SDL_GetTicks();
  game->oldTime = game->startTicks;
  game->difficultyTimer = game->startTicks;
 } else if(event == EEventExit) {
  Uint32 time = SDL_GetTicks();
  Uint32 score = (time-game->startTicks)/100;
  printf("Score: %i\n", score);
  for(unsigned i=0; i<10; ++i) {
   if(score > game->highscore[i]) {
    for(unsigned j=10 -1; j>i; --j) {
     game->highscore[j] = game->highscore[j-1];
    }
    game->highscore[i] = score;
    break;
   }
  }
 } else if(event == EEventRun) {
  Uint32 time = SDL_GetTicks();
  Uint32 diffTime = time-game->oldTime;
  game->oldTime=time;
  char buf[10];
  sprintf(buf, "%i", (time-game->startTicks)/100);
  MIODispWriteText(buf, 9, 0);
  if((time - game->difficultyTimer) >1000) {
   game->difficultyTimer = time;
   rangeYHight++;
   if(rangeYHight > 40 ) game->scapeSize = 40;
   game->scapeSize--;
   if(game->scapeSize < 10 ) game->scapeSize = 10;
  }
  heli_clear(&game->heli);
  if(DIORead(SDLK_w)) {
   heli_update(&game->heli, 0.001, diffTime);
  }
  else {
   heli_update(&game->heli, -0.001, diffTime);
  }
  heli_draw(&game->heli);
  landscapeFlow(&game->landscape, game->scapeSize);
  wall_clear(&game->wall);
  wall_update(&game->wall, diffTime);
  if(game->wall.x <=0 ) {
   int length;
   int ymin, ymax;
   ymin = getYBottom(&game->landscape, 160);
   ymax = getYRoof(&game->landscape, 160);
   length = game->wall.y2-game->wall.y1+1;
   if(length>(ymax-ymin-20) ) {
    length = ymax-ymin-20;
    if(length<1) length = 1;
   }
   wall_init(&game->wall, length, ymax, ymin );
  }
  wall_draw(&game->wall);
  if(heli_check_collision(&game->heli, game->wall.x, game->wall.y1, game->wall.x, game->wall.y2)) {
   change_state(game, EStateHighScore);
  }
  if(touch(&game->landscape, game->heli.x, game->heli.y+heliRadius)) {
   change_state(game, EStateHighScore);
  }
  if(touch(&game->landscape, game->heli.x, game->heli.y-heliRadius)) {
   change_state(game, EStateHighScore);
  }
 }
}

canonical_original_code:
void game_state_game(struct Game *game, enum GameEvent event)
{
 if(event == EEventEntry) {
  printf("game entry\n");
  rangeYHight = 1;
  DisplayClrArea (0, 0, 160, 80);
  initLandscape(&game->landscape, 70);
  heli_init(&game->heli);
  wall_init(&game->wall, 10, getYRoof(&game->landscape, 159), getYBottom(&game->landscape, 159) );
  game->scapeSize=70;
  game->startTicks = SDL_GetTicks();
  game->oldTime = game->startTicks;
  game->difficultyTimer = game->startTicks;
 } else if(event == EEventExit) {
  unsigned int time = SDL_GetTicks();
  unsigned int score = (time-game->startTicks)/100;
  printf("Score: %i\n", score);
  for(unsigned int i = 0; i<10; ++i) {
   if(score > game->highscore[i]) {
    for(unsigned int j = 10 -1; j>i; --j) {
     game->highscore[j] = game->highscore[j-1];
    }
    game->highscore[i] = score;
    break;
   }
  }
 } else if(event == EEventRun) {
  unsigned int time = SDL_GetTicks();
  unsigned int diffTime = time-game->oldTime;
  game->oldTime=time;
  char buf[10];
  sprintf(buf, "%i", (time-game->startTicks)/100);
  MIODispWriteText(buf, 9, 0);
  if((time - game->difficultyTimer) >1000) {
   game->difficultyTimer = time;
   rangeYHight++;
   if(rangeYHight > 40 ) game->scapeSize = 40;
   game->scapeSize--;
   if(game->scapeSize < 10 ) game->scapeSize = 10;
  }
  heli_clear(&game->heli);
  if(DIORead(SDLK_w)) {
   heli_update(&game->heli, 0.001, diffTime);
  }
  else {
   heli_update(&game->heli, -0.001, diffTime);
  }
  heli_draw(&game->heli);
  landscapeFlow(&game->landscape, game->scapeSize);
  wall_clear(&game->wall);
  wall_update(&game->wall, diffTime);
  if(game->wall.x <=0 ) {
   int length;
   int ymin; int ymax;
   ymin = getYBottom(&game->landscape, 160);
   ymax = getYRoof(&game->landscape, 160);
   length = game->wall.y2-game->wall.y1+1;
   if(length>(ymax-ymin-20) ) {
    length = ymax-ymin-20;
    if(length<1) length = 1;
   }
   wall_init(&game->wall, length, ymax, ymin );
  }
  wall_draw(&game->wall);
  if(heli_check_collision(&game->heli, game->wall.x, game->wall.y1, game->wall.x, game->wall.y2)) {
   change_state(game, EStateHighScore);
  }
  if(touch(&game->landscape, game->heli.x, game->heli.y+heliRadius)) {
   change_state(game, EStateHighScore);
  }
  if(touch(&game->landscape, game->heli.x, game->heli.y-heliRadius)) {
   change_state(game, EStateHighScore);
  }
 }
}

variable_types:
time
unsigned int

variable_types:
score
unsigned int

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
diffTime
unsigned int

variable_types:
buf
char [10]

variable_types: length int

variable_types: ymin int

variable_types: ymax int

user_defined_types: enum GameEvent { EEventEntry=0, EEventExit=1, EEventRun=2, EEventKeyDown=3, EEventKeyUp=4 }


decompiled_code:
__int64 __fastcall game_state_highscore(int *a1, int a2)
{
__int64 i; // rbx
__int64 result; // rax
char s[34]; // [rsp+6h] [rbp-22h] BYREF

if ( a2 )
{
if ( a2 == 3 && a1[115] == 119 )
result = change_state(a1, 0);
}
else
{
for ( i = 0LL; i != 10; ++i )
{
sprintf(s, "%2u. %4i", (unsigned int)(i + 1), (unsigned int)a1[i + 116]);
result = MIODispWriteText(s, (unsigned int)i, 0LL);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, int a2)
{
__int64 i; // rbx
__int64 result; // rax
char s[34]; // [rsp+6h] [rbp-22h] BYREF

if ( a2 )
{
if ( a2 == 3 && a1[115] == 119 )
result = func0(a1, 0);
}
else
{
for ( i = 0LL; i != 10; ++i )
{
sprintf(s, "%2u. %4i", (unsigned int)(i + 1), (unsigned int)a1[i + 116]);
result = MIODispWriteText(s, (unsigned int)i, 0LL);
}
}
return result;
}

original_code:
void game_state_highscore(Game *game, GameEvent event)
{
 if(event == EEventEntry) {
  char buf[10];
  for(unsigned i=0; i<10; ++i) {
   sprintf(buf, "%2u. %4i", i+1, game->highscore[i]);
   MIODispWriteText(buf, i, 0);
  }
 } else if(event == EEventExit) {
 } else if(event == EEventKeyDown) {
  if(game->currentKey == SDLK_w) {
   change_state(game, EStateMenu);
  }
 }
 else if(event == EEventRun) {
 }
}

canonical_original_code:
void game_state_highscore(struct Game *game, enum GameEvent event)
{
 if(event == EEventEntry) {
  char buf[10];
  for(unsigned int i = 0; i<10; ++i) {
   sprintf(buf, "%2u. %4i", i+1, game->highscore[i]);
   MIODispWriteText(buf, i, 0);
  }
 } else if(event == EEventExit) {
 } else if(event == EEventKeyDown) {
  if(game->currentKey == SDLK_w) {
   change_state(game, EStateMenu);
  }
 }
 else if(event == EEventRun) {
 }
}


original_code:
Game* game_init()
{
 Game* game = malloc(sizeof(Game));
 for(unsigned i=0; i< 10; ++i) {
  game->highscore[i] = 0;
 }
 for(unsigned i=0; i<4; ++i) {
  game->keyState[i] = 0;
 }
 game->keys[0] = SDLK_w;
 game->keys[1] = SDLK_a;
 game->keys[2] = SDLK_d;
 game->keys[3] = SDLK_s;
 game->menuitem = 0;
 game->scapeSize = 0;
 game->startTicks = 0;
 game->oldTime = 0;
 game->difficultyTimer = 0;
 game->state = EStateMenu;
 game_state_menu(game, EEventEntry);
 return game;
}

canonical_original_code:
struct Game *game_init()
{
 struct Game *game = malloc(sizeof(Game));
 for(unsigned int i = 0; i< 10; ++i) {
  game->highscore[i] = 0;
 }
 for(unsigned int i = 0; i<4; ++i) {
  game->keyState[i] = 0;
 }
 game->keys[0] = SDLK_w;
 game->keys[1] = SDLK_a;
 game->keys[2] = SDLK_d;
 game->keys[3] = SDLK_s;
 game->menuitem = 0;
 game->scapeSize = 0;
 game->startTicks = 0;
 game->oldTime = 0;
 game->difficultyTimer = 0;
 game->state = EStateMenu;
 game_state_menu(game, EEventEntry);
 return game;
}

return_type: struct Game { enum GameState { EStateMenu=0, EStateGame=1, EStateHighScore=2 } state; struct Wall { float x; int y1; } wall; struct Heli { float x; float speed; } heli; struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; } landscape; unsigned int menuitem; int scapeSize; unsigned int startTicks; unsigned int oldTime; unsigned int difficultyTimer; int keyState[4]; int keys[4]; int currentKey; unsigned int highscore[10]; } *


decompiled_code:
void __fastcall game_run(int *a1)
{
__int64 i; // rbx
int v2; // eax
__int64 v3; // rsi
int v4; // eax

DelayMs(10LL);
for ( i = 0LL; i != 4; ++i )
{
v2 = DIORead((unsigned int)a1[i + 111]);
if ( v2 )
{
if ( !a1[i + 107] )
{
a1[115] = a1[(unsigned int)i + 111];
a1[(unsigned int)i + 107] = v2;
v3 = 3LL;
goto LABEL_9;
}
}
else if ( a1[i + 107] )
{
a1[115] = a1[(unsigned int)i + 111];
a1[(unsigned int)i + 107] = 0;
v3 = 4LL;
goto LABEL_9;
}
}
v3 = 2LL;
LABEL_9:
v4 = *a1;
if ( *a1 == 1 )
{
game_state_game((__int64)a1, v3);
}
else if ( v4 == 2 )
{
game_state_highscore(a1, v3);
}
else
{
if ( v4 )
exit(-1);
game_state_menu(a1, v3);
}
}

canonical_decompiled_code:
void __fastcall func5(int *a1)
{
__int64 i; // rbx
int v2; // eax
__int64 v3; // rsi
int v4; // eax

DelayMs(10LL);
for ( i = 0LL; i != 4; ++i )
{
v2 = DIORead((unsigned int)a1[i + 111]);
if ( v2 )
{
if ( !a1[i + 107] )
{
a1[115] = a1[(unsigned int)i + 111];
a1[(unsigned int)i + 107] = v2;
v3 = 3LL;
goto LABEL_9;
}
}
else if ( a1[i + 107] )
{
a1[115] = a1[(unsigned int)i + 111];
a1[(unsigned int)i + 107] = 0;
v3 = 4LL;
goto LABEL_9;
}
}
v3 = 2LL;
LABEL_9:
v4 = *a1;
if ( *a1 == 1 )
{
func2((__int64)a1, v3);
}
else if ( v4 == 2 )
{
func3(a1, v3);
}
else
{
if ( v4 )
exit(-1);
func1(a1, v3);
}
}

original_code:
void game_run(Game *game)
{
 GameEvent event = EEventRun;
 DelayMs(10);
 for(unsigned i=0; i<4; ++i) {
  int state = DIORead(game->keys[i]);
  if(state && game->keyState[i]==0) {
   event = EEventKeyDown;
   game->currentKey = game->keys[i];
   game->keyState[i] = state;
   break;
  } else if(state == 0 && game->keyState[i]) {
   event = EEventKeyUp;
   game->currentKey = game->keys[i];
   game->keyState[i] = state;
   break;
  }
 }
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, event);
   break;
  case EStateGame:
   game_state_game(game, event);
   break;
  case EStateHighScore:
   game_state_highscore(game, event);
   break;
  default:
   exit(-1);
 }
}

canonical_original_code:
void game_run(struct Game *game)
{
 enum GameEvent event = EEventRun;
 DelayMs(10);
 for(unsigned int i = 0; i<4; ++i) {
  int state = DIORead(game->keys[i]);
  if(state && game->keyState[i]==0) {
   event = EEventKeyDown;
   game->currentKey = game->keys[i];
   game->keyState[i] = state;
   break;
  } else if(state == 0 && game->keyState[i]) {
   event = EEventKeyUp;
   game->currentKey = game->keys[i];
   game->keyState[i] = state;
   break;
  }
 }
 switch(game->state) {
  case EStateMenu:
   game_state_menu(game, event);
   break;
  case EStateGame:
   game_state_game(game, event);
   break;
  case EStateHighScore:
   game_state_highscore(game, event);
   break;
  default:
   exit(-1);
 }
}

variable_types: state int


original_code:
void wall_init(Wall *wall, int length, int ymax, int ymin)
{
 printf("%i, %i, %i ->", length, ymax, ymin);
 wall->x=160;
 wall->y1=ymin+(rand()%(ymax-ymin-length));
 wall->y2=wall->y1+length;
 printf("%i, %i\n", wall->y1, wall->y2);
}

canonical_original_code:
void wall_init(struct Wall *wall, int length, int ymax, int ymin)
{
 printf("%i, %i, %i ->", length, ymax, ymin);
 wall->x=160;
 wall->y1=ymin+(rand()%(ymax-ymin-length));
 wall->y2=wall->y1+length;
 printf("%i, %i\n", wall->y1, wall->y2);
}

variable_types:
wall
struct Wall { float x; int y1; } *


decompiled_code:
void __fastcall wall_update(float *a1)
{
*a1 = *a1 - 1.0;
}

canonical_decompiled_code:
void __fastcall func1(float *a1)
{
*a1 = *a1 - 1.0;
}

original_code:
void wall_update(Wall *wall, int dtime)
{
 wall->x-=1;
}

canonical_original_code:
void wall_update(struct Wall *wall, int dtime)
{
 wall->x-=1;
}

variable_types: dtime int


decompiled_code:
__int64 __fastcall wall_draw(__int64 a1)
{
return DisplayDrawLine(
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 4),
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return DisplayDrawLine(
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 4),
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 8));
}

original_code:
void wall_draw(Wall *wall)
{
 DisplayDrawLine(wall->x,wall->y1,wall->x,wall->y2);
}

canonical_original_code:
void wall_draw(struct Wall *wall)
{
 DisplayDrawLine(wall->x,wall->y1,wall->x,wall->y2);
}


decompiled_code:
__int64 __fastcall wall_clear(__int64 a1)
{
return DisplayClrLine(
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 4),
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return DisplayClrLine(
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 4),
(unsigned int)(int)*(float *)a1,
*(unsigned int *)(a1 + 8));
}

original_code:
void wall_clear(Wall *wall)
{
 DisplayClrLine(wall->x,wall->y1,wall->x,wall->y2);
}

canonical_original_code:
void wall_clear(struct Wall *wall)
{
 DisplayClrLine(wall->x,wall->y1,wall->x,wall->y2);
}


initLandscape

original_code:
void initLandscape(Landscape *lndscp, int deltaY)
{
  int j;
  lndscp->nrOfPnts = 0;
  lndscp->xPnts[0] = 0;
  lndscp->yBottom[0] = rand()%rangeYHight;
  lndscp->yRoof[0] = lndscp->yBottom[0] + deltaY + rand()%rangeAdditionalYDistance;
  lndscp->yBorderLeftBottom = lndscp->yBottom[0];
  lndscp->yBorderLeftRoof = lndscp->yRoof[0];
  do
  {
    lndscp->nrOfPnts++;
    lndscp->xPnts[lndscp->nrOfPnts] = lndscp->xPnts[lndscp->nrOfPnts - 1]
                                      + minXDistance + rand() % rangeAdditionalXDistance;
    lndscp->yBottom[lndscp->nrOfPnts] = rand() % rangeYHight;
    lndscp->yRoof[lndscp->nrOfPnts] = lndscp->yBottom[lndscp->nrOfPnts]
                                      + deltaY + rand() % rangeAdditionalYDistance;
  } while (lndscp->xPnts[lndscp->nrOfPnts] <= xMax);
  for (j = 1; j < lndscp->nrOfPnts; j++)
  {
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                    lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayDrawLine(lndscp->xPnts[j-1], lndscp->yRoof[j - 1],
                    lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  lndscp->yBorderRightBottom = lndscp->yBottom[lndscp->nrOfPnts - 1]
    + ((lndscp->yBottom[lndscp->nrOfPnts] - lndscp->yBottom[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  lndscp->yBorderRightRoof = lndscp->yRoof[lndscp->nrOfPnts - 1]
    + ((lndscp->yRoof[lndscp->nrOfPnts] - lndscp->yRoof[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightBottom);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightRoof);
}

canonical_original_code:
void initLandscape(struct Landscape *lndscp, int deltaY)
{
  int j;
  lndscp->nrOfPnts = 0;
  lndscp->xPnts[0] = 0;
  lndscp->yBottom[0] = rand()%rangeYHight;
  lndscp->yRoof[0] = lndscp->yBottom[0] + deltaY + rand()%rangeAdditionalYDistance;
  lndscp->yBorderLeftBottom = lndscp->yBottom[0];
  lndscp->yBorderLeftRoof = lndscp->yRoof[0];
  do
  {
    lndscp->nrOfPnts++;
    lndscp->xPnts[lndscp->nrOfPnts] = lndscp->xPnts[lndscp->nrOfPnts - 1]
                                      + minXDistance + rand() % rangeAdditionalXDistance;
    lndscp->yBottom[lndscp->nrOfPnts] = rand() % rangeYHight;
    lndscp->yRoof[lndscp->nrOfPnts] = lndscp->yBottom[lndscp->nrOfPnts]
                                      + deltaY + rand() % rangeAdditionalYDistance;
  } while (lndscp->xPnts[lndscp->nrOfPnts] <= xMax);
  for (j = 1; j < lndscp->nrOfPnts; j++)
  {
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                    lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayDrawLine(lndscp->xPnts[j-1], lndscp->yRoof[j - 1],
                    lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  lndscp->yBorderRightBottom = lndscp->yBottom[lndscp->nrOfPnts - 1]
    + ((lndscp->yBottom[lndscp->nrOfPnts] - lndscp->yBottom[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  lndscp->yBorderRightRoof = lndscp->yRoof[lndscp->nrOfPnts - 1]
    + ((lndscp->yRoof[lndscp->nrOfPnts] - lndscp->yRoof[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightBottom);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightRoof);
}

variable_types: struct Landscape { int xPnts[30]; int yBottom[30]; int yRoof[30]; int yBorderLeftBottom; int yBorderRightBottom; int yBorderLeftRoof; int yBorderRightRoof; int nrOfPnts; } *

variable_types: deltaY int

variable_types: j int


landscapeFlow

original_code:
void landscapeFlow(Landscape *lndscp, int deltaY)
{
  int j;
  DisplayClrLine(0, lndscp->yBorderLeftBottom,
                 lndscp->xPnts[1], lndscp->yBottom[1]);
  DisplayClrLine(0, lndscp->yBorderLeftRoof,
                 lndscp->xPnts[1], lndscp->yRoof[1]);
  for (j = 2; j < lndscp->nrOfPnts; j++)
  {
    DisplayClrLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                   lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayClrLine(lndscp->xPnts[j - 1], lndscp->yRoof[j - 1],
                   lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  DisplayClrLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                 xMax, lndscp->yBorderRightBottom);
  DisplayClrLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                 xMax, lndscp->yBorderRightRoof);
  for (j = 0; j <= lndscp->nrOfPnts; j++)
  {
    lndscp->xPnts[j]--;
  }
  if (lndscp->xPnts[lndscp->nrOfPnts] < 160)
  {
    lndscp->nrOfPnts++;
    lndscp->xPnts[lndscp->nrOfPnts] = lndscp->xPnts[lndscp->nrOfPnts - 1]
                                              + minXDistance + rand() % rangeAdditionalXDistance;
    lndscp->yBottom[lndscp->nrOfPnts] = rand() % rangeYHight;
    lndscp->yRoof[lndscp->nrOfPnts] = lndscp->yBottom[lndscp->nrOfPnts]
                                              + deltaY + rand() % rangeAdditionalYDistance;
  }
  if (lndscp->xPnts[1] < 0)
  {
    for(j = 0; j < lndscp->nrOfPnts ; j++)
    {
      lndscp->xPnts[j] = lndscp->xPnts[j + 1];
      lndscp->yBottom[j] = lndscp->yBottom[j + 1];
      lndscp->yRoof[j] = lndscp->yRoof[j + 1];
    }
    lndscp->nrOfPnts--;
  }
  lndscp->yBorderLeftBottom = lndscp->yBottom[0]
    + ((lndscp->yBottom[1] - lndscp->yBottom[0])
       * (0 - lndscp->xPnts[0]))
    / (lndscp->xPnts[1] - lndscp->xPnts[0]);
  lndscp->yBorderLeftRoof = lndscp->yRoof[0]
    + ((lndscp->yRoof[1]-lndscp->yRoof[0])
       * (0 - lndscp->xPnts[0]))
    / (lndscp->xPnts[1] - lndscp->xPnts[0]);
  DisplayDrawLine(0, lndscp->yBorderLeftBottom,
                  lndscp->xPnts[1], lndscp->yBottom[1]);
  DisplayDrawLine(0, lndscp->yBorderLeftRoof,
                  lndscp->xPnts[1], lndscp->yRoof[1]);
  for (j = 2; j < lndscp->nrOfPnts; j++)
  {
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                    lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yRoof[j - 1],
                    lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  lndscp->yBorderRightBottom = lndscp->yBottom[lndscp->nrOfPnts - 1]
    + ((lndscp->yBottom[lndscp->nrOfPnts] - lndscp->yBottom[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  lndscp->yBorderRightRoof = lndscp->yRoof[lndscp->nrOfPnts - 1]
    + ((lndscp->yRoof[lndscp->nrOfPnts] - lndscp->yRoof[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightBottom);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightRoof);
}

canonical_original_code:
void landscapeFlow(struct Landscape *lndscp, int deltaY)
{
  int j;
  DisplayClrLine(0, lndscp->yBorderLeftBottom,
                 lndscp->xPnts[1], lndscp->yBottom[1]);
  DisplayClrLine(0, lndscp->yBorderLeftRoof,
                 lndscp->xPnts[1], lndscp->yRoof[1]);
  for (j = 2; j < lndscp->nrOfPnts; j++)
  {
    DisplayClrLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                   lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayClrLine(lndscp->xPnts[j - 1], lndscp->yRoof[j - 1],
                   lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  DisplayClrLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                 xMax, lndscp->yBorderRightBottom);
  DisplayClrLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                 xMax, lndscp->yBorderRightRoof);
  for (j = 0; j <= lndscp->nrOfPnts; j++)
  {
    lndscp->xPnts[j]--;
  }
  if (lndscp->xPnts[lndscp->nrOfPnts] < 160)
  {
    lndscp->nrOfPnts++;
    lndscp->xPnts[lndscp->nrOfPnts] = lndscp->xPnts[lndscp->nrOfPnts - 1]
                                              + minXDistance + rand() % rangeAdditionalXDistance;
    lndscp->yBottom[lndscp->nrOfPnts] = rand() % rangeYHight;
    lndscp->yRoof[lndscp->nrOfPnts] = lndscp->yBottom[lndscp->nrOfPnts]
                                              + deltaY + rand() % rangeAdditionalYDistance;
  }
  if (lndscp->xPnts[1] < 0)
  {
    for(j = 0; j < lndscp->nrOfPnts ; j++)
    {
      lndscp->xPnts[j] = lndscp->xPnts[j + 1];
      lndscp->yBottom[j] = lndscp->yBottom[j + 1];
      lndscp->yRoof[j] = lndscp->yRoof[j + 1];
    }
    lndscp->nrOfPnts--;
  }
  lndscp->yBorderLeftBottom = lndscp->yBottom[0]
    + ((lndscp->yBottom[1] - lndscp->yBottom[0])
       * (0 - lndscp->xPnts[0]))
    / (lndscp->xPnts[1] - lndscp->xPnts[0]);
  lndscp->yBorderLeftRoof = lndscp->yRoof[0]
    + ((lndscp->yRoof[1]-lndscp->yRoof[0])
       * (0 - lndscp->xPnts[0]))
    / (lndscp->xPnts[1] - lndscp->xPnts[0]);
  DisplayDrawLine(0, lndscp->yBorderLeftBottom,
                  lndscp->xPnts[1], lndscp->yBottom[1]);
  DisplayDrawLine(0, lndscp->yBorderLeftRoof,
                  lndscp->xPnts[1], lndscp->yRoof[1]);
  for (j = 2; j < lndscp->nrOfPnts; j++)
  {
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yBottom[j - 1],
                    lndscp->xPnts[j], lndscp->yBottom[j]);
    DisplayDrawLine(lndscp->xPnts[j - 1], lndscp->yRoof[j - 1],
                    lndscp->xPnts[j], lndscp->yRoof[j]);
  }
  lndscp->yBorderRightBottom = lndscp->yBottom[lndscp->nrOfPnts - 1]
    + ((lndscp->yBottom[lndscp->nrOfPnts] - lndscp->yBottom[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  lndscp->yBorderRightRoof = lndscp->yRoof[lndscp->nrOfPnts - 1]
    + ((lndscp->yRoof[lndscp->nrOfPnts] - lndscp->yRoof[lndscp->nrOfPnts - 1])
       * (xMax - lndscp->xPnts[lndscp->nrOfPnts - 1]))
    / (lndscp->xPnts[lndscp->nrOfPnts] - lndscp->xPnts[lndscp->nrOfPnts - 1]);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yBottom[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightBottom);
  DisplayDrawLine(lndscp->xPnts[lndscp->nrOfPnts - 1], lndscp->yRoof[lndscp->nrOfPnts - 1],
                  xMax, lndscp->yBorderRightRoof);
}


touch

original_code:
int touch (Landscape *lndscp, int pointX, int pointY)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      if (
           ((pointX - lndscp->xPnts[j]) * (lndscp->yRoof[j - 1] - lndscp->yRoof[j])
             - (pointY - lndscp->yRoof[j]) * (lndscp->xPnts[j - 1] - lndscp->xPnts[j])
           < 0)
           &&
           ((pointX - lndscp->xPnts[j]) * (lndscp->yBottom[j - 1] - lndscp->yBottom[j])
             - (pointY - lndscp->yBottom[j]) * (lndscp->xPnts[j - 1] - lndscp->xPnts[j])
           > 0)
         )
        return 0;
      else
        return 1;
    }
  }
}

canonical_original_code:
int touch(struct Landscape *lndscp, int pointX, int pointY)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      if (
           ((pointX - lndscp->xPnts[j]) * (lndscp->yRoof[j - 1] - lndscp->yRoof[j])
             - (pointY - lndscp->yRoof[j]) * (lndscp->xPnts[j - 1] - lndscp->xPnts[j])
           < 0)
           &&
           ((pointX - lndscp->xPnts[j]) * (lndscp->yBottom[j - 1] - lndscp->yBottom[j])
             - (pointY - lndscp->yBottom[j]) * (lndscp->xPnts[j - 1] - lndscp->xPnts[j])
           > 0)
         )
        return 0;
      else
        return 1;
    }
  }
}

variable_types: pointX int

variable_types: pointY int


getYRoof

original_code:
int getYRoof(Landscape *lndscp, int pointX)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      return lndscp->yRoof[j-1]
          + ((lndscp->yRoof[j] - lndscp->yRoof[j-1])
       * (pointX - lndscp->xPnts[j-1]))
    / (lndscp->xPnts[j] - lndscp->xPnts[j-1]);
    }
  }
}

canonical_original_code:
int getYRoof(struct Landscape *lndscp, int pointX)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      return lndscp->yRoof[j-1]
          + ((lndscp->yRoof[j] - lndscp->yRoof[j-1])
       * (pointX - lndscp->xPnts[j-1]))
    / (lndscp->xPnts[j] - lndscp->xPnts[j-1]);
    }
  }
}


getYBottom

original_code:
int getYBottom(Landscape *lndscp, int pointX)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      return lndscp->yBottom[j-1]
          + ((lndscp->yBottom[j] - lndscp->yBottom[j-1])
       * (pointX - lndscp->xPnts[j-1]))
    / (lndscp->xPnts[j] - lndscp->xPnts[j-1]);
    }
  }
}

canonical_original_code:
int getYBottom(struct Landscape *lndscp, int pointX)
{
  int j = 0;
  while (1)
  {
  j++;
    if (pointX <= lndscp->xPnts[j])
    {
      return lndscp->yBottom[j-1]
          + ((lndscp->yBottom[j] - lndscp->yBottom[j-1])
       * (pointX - lndscp->xPnts[j-1]))
    / (lndscp->xPnts[j] - lndscp->xPnts[j-1]);
    }
  }
}


decompiled_code:
__int64 __fastcall heli_update(float *a1, int a2, float a3)
{
float v3; // xmm0_4
__int64 result; // rax
float v5; // xmm0_4

v3 = (float)((float)a2 * a3) + a1[2];
a1[2] = v3;
a1[1] = v3 + a1[1];
result = DIORead(97LL);
if ( (_DWORD)result )
{
*a1 = *a1 - 1.0;
}
else
{
result = DIORead(100LL);
if ( (_DWORD)result )
*a1 = *a1 + 1.0;
}
v5 = a1[1];
if ( v5 <= 80.0 )
{
if ( v5 < 0.0 )
a1[1] = 0.0;
}
else
{
a1[1] = 80.0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(float *a1, int a2, float a3)
{
float v3; // xmm0_4
__int64 result; // rax
float v5; // xmm0_4

v3 = (float)((float)a2 * a3) + a1[2];
a1[2] = v3;
a1[1] = v3 + a1[1];
result = DIORead(97LL);
if ( (_DWORD)result )
{
*a1 = *a1 - 1.0;
}
else
{
result = DIORead(100LL);
if ( (_DWORD)result )
*a1 = *a1 + 1.0;
}
v5 = a1[1];
if ( v5 <= 80.0 )
{
if ( v5 < 0.0 )
a1[1] = 0.0;
}
else
{
a1[1] = 80.0;
}
return result;
}

original_code:
void heli_update(Heli* heli, float acc, int dtime)
{
 heli->speed += acc*dtime;
 heli->y += heli->speed;
 if(DIORead(SDLK_a)) {
  heli->x -= 1;
 }
 else if(DIORead(SDLK_d)) {
  heli->x += 1;
 }
 if(heli->y > 80) heli->y = 80;
 if(heli->y < 0) heli->y = 0;
}

canonical_original_code:
void heli_update(struct Heli *heli, float acc, int dtime)
{
 heli->speed += acc*dtime;
 heli->y += heli->speed;
 if(DIORead(SDLK_a)) {
  heli->x -= 1;
 }
 else if(DIORead(SDLK_d)) {
  heli->x += 1;
 }
 if(heli->y > 80) heli->y = 80;
 if(heli->y < 0) heli->y = 0;
}

variable_types:
heli
struct Heli { float x; float speed; } *

variable_types: acc float


decompiled_code:
__int64 __fastcall heli_draw(float *a1)
{
return DisplayDrawCircle((unsigned int)(int)(*a1 + 0.5), (unsigned int)(int)(a1[1] + 0.5), 5LL);
}

canonical_decompiled_code:
__int64 __fastcall func2(float *a1)
{
return DisplayDrawCircle((unsigned int)(int)(*a1 + 0.5), (unsigned int)(int)(a1[1] + 0.5), 5LL);
}

original_code:
void heli_draw(Heli* heli)
{
 DisplayDrawCircle(heli->x+0.5, heli->y+0.5, heliRadius);
}

canonical_original_code:
void heli_draw(struct Heli *heli)
{
 DisplayDrawCircle(heli->x+0.5, heli->y+0.5, heliRadius);
}


decompiled_code:
__int64 __fastcall heli_clear(float *a1)
{
return DisplayClearCircle((unsigned int)(int)(*a1 + 0.5), (unsigned int)(int)(a1[1] + 0.5), 5LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(float *a1)
{
return DisplayClearCircle((unsigned int)(int)(*a1 + 0.5), (unsigned int)(int)(a1[1] + 0.5), 5LL);
}

original_code:
void heli_clear(Heli* heli)
{
 DisplayClearCircle(heli->x+0.5, heli->y+0.5, heliRadius);
}

canonical_original_code:
void heli_clear(struct Heli *heli)
{
 DisplayClearCircle(heli->x+0.5, heli->y+0.5, heliRadius);
}


decompiled_code:
float __fastcall heli_get_y(__int64 a1)
{
return *(float *)(a1 + 4);
}

canonical_decompiled_code:
float __fastcall func4(__int64 a1)
{
return *(float *)(a1 + 4);
}

original_code:
float heli_get_y(Heli* heli)
{
 return heli->y;
}

canonical_original_code:
float heli_get_y(struct Heli *heli)
{
 return heli->y;
}

return_type: float


decompiled_code:
__int64 __fastcall heli_check_collision(float *a1, float a2, float a3, float a4, float a5)
{
__int64 result; // rax
float v6; // [rsp+Ch] [rbp-1Ch]

v6 = (float)((float)((float)((float)(a1[1] - a3) * (float)(a4 - a2)) - (float)((float)(*a1 - a2) * (float)(a5 - a3)))
* (float)((float)((float)(a1[1] - a3) * (float)(a4 - a2)) - (float)((float)(*a1 - a2) * (float)(a5 - a3))))
/ (float)((float)((float)(a4 - a2) * (float)(a4 - a2)) + (float)((float)(a5 - a3) * (float)(a5 - a3)));
printf("%f\n", (float)(v6 - 5.0));
result = 0LL;
if ( v6 <= 25.0 )
{
if ( (float)(*a1 - 5.0) > fmaxf(a2, a4) )
{
puts("xbig");
result = 0LL;
}
else if ( (float)(a1[1] - 5.0) > fmaxf(a3, a5) )
{
puts("xsmall");
result = 0LL;
}
else if ( fminf(a2, a4) > (float)(*a1 + 5.0) )
{
puts("ybig");
result = 0LL;
}
else
{
result = 1LL;
if ( fminf(a3, a5) > (float)(a1[1] + 5.0) )
{
puts("ysmall");
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(float *a1, float a2, float a3, float a4, float a5)
{
__int64 result; // rax
float v6; // [rsp+Ch] [rbp-1Ch]

v6 = (float)((float)((float)((float)(a1[1] - a3) * (float)(a4 - a2)) - (float)((float)(*a1 - a2) * (float)(a5 - a3)))
* (float)((float)((float)(a1[1] - a3) * (float)(a4 - a2)) - (float)((float)(*a1 - a2) * (float)(a5 - a3))))
/ (float)((float)((float)(a4 - a2) * (float)(a4 - a2)) + (float)((float)(a5 - a3) * (float)(a5 - a3)));
printf("%f\n", (float)(v6 - 5.0));
result = 0LL;
if ( v6 <= 25.0 )
{
if ( (float)(*a1 - 5.0) > fmaxf(a2, a4) )
{
puts("xbig");
result = 0LL;
}
else if ( (float)(a1[1] - 5.0) > fmaxf(a3, a5) )
{
puts("xsmall");
result = 0LL;
}
else if ( fminf(a2, a4) > (float)(*a1 + 5.0) )
{
puts("ybig");
result = 0LL;
}
else
{
result = 1LL;
if ( fminf(a3, a5) > (float)(a1[1] + 5.0) )
{
puts("ysmall");
result = 0LL;
}
}
}
return result;
}

original_code:
int heli_check_collision(Heli *heli, float x1, float y1, float x2, float y2)
{
 float dirx = x2-x1;
 float diry = y2-y1;
 float diffx = heli->x - x1;
 float diffy = heli->y - y1;
 float a = dirx*diffy - diry*diffx;
 float r = dirx*dirx + diry*diry;
 a = a*a;
 printf("%f\n", a/r-heliRadius);
 if(a/r<=heliRadius*heliRadius) {
  if(heli->x-heliRadius > (x1>x2? x1 : x2)){ printf("xbig\n"); return 0;}
  if(heli->y-heliRadius > (y1>y2? y1 : y2)){ printf("xsmall\n"); return 0;}
  if(heli->x+heliRadius < (x1<x2? x1 : x2)){ printf("ybig\n"); return 0;}
  if(heli->y+heliRadius < (y1<y2? y1 : y2)){ printf("ysmall\n"); return 0;}
  return 1;
 }
 return 0;
}

canonical_original_code:
int heli_check_collision(struct Heli *heli, float x1, float y1, float x2, float y2)
{
 float dirx = x2-x1;
 float diry = y2-y1;
 float diffx = heli->x - x1;
 float diffy = heli->y - y1;
 float a = dirx*diffy - diry*diffx;
 float r = dirx*dirx + diry*diry;
 a = a*a;
 printf("%f\n", a/r-heliRadius);
 if(a/r<=heliRadius*heliRadius) {
  if(heli->x-heliRadius > (x1>x2? x1 : x2)){ printf("xbig\n"); return 0;}
  if(heli->y-heliRadius > (y1>y2? y1 : y2)){ printf("xsmall\n"); return 0;}
  if(heli->x+heliRadius < (x1<x2? x1 : x2)){ printf("ybig\n"); return 0;}
  if(heli->y+heliRadius < (y1<y2? y1 : y2)){ printf("ysmall\n"); return 0;}
  return 1;
 }
 return 0;
}

variable_types: dirx float

variable_types: diry float

variable_types: diffx float

variable_types: diffy float

variable_types: a float

variable_types: r float


original_code:
int v_semi(float *V, float lamda)
{
 float get_f_variable(char *);
 float k,accum,to_kcal;
 int i,numatm, a_number(void);
 ATOM *ap, *a_next(int);
 k = get_f_variable("ksemi");
 if( k < 0.) k = 0.;
 numatm = a_number();
 if(numatm < 1) return 0;
 to_kcal = 0.5/(4.184*1000.*1000.);
 accum = 0.;
 for( i=0; i< numatm; i++)
 {
  ap = a_next(i);
  accum -= to_kcal*k*ap->mass*(ap->vx*ap->vx);
  accum -= to_kcal*k*ap->mass*(ap->vy*ap->vy);
  accum -= to_kcal*k*ap->mass*(ap->vz*ap->vz);
 }
 *V += accum;
 return 0;
}

canonical_original_code:
int v_semi(float *V, float lamda)
{
 float get_f_variable(char *);
 float k; float accum; float to_kcal;
 int i; int numatm; int a_number();
 struct ATOM *ap; struct ATOM *a_next(int);
 k = get_f_variable("ksemi");
 if( k < 0.) k = 0.;
 numatm = a_number();
 if(numatm < 1) return 0;
 to_kcal = 0.5/(4.184*1000.*1000.);
 accum = 0.;
 for( i=0; i< numatm; i++)
 {
  ap = a_next(i);
  accum -= to_kcal*k*ap->mass*(ap->vx*ap->vx);
  accum -= to_kcal*k*ap->mass*(ap->vy*ap->vy);
  accum -= to_kcal*k*ap->mass*(ap->vz*ap->vz);
 }
 *V += accum;
 return 0;
}

variable_types:
V
float *

variable_types: lamda float

variable_types: k float

variable_types: accum float

variable_types: i int

variable_types: numatm int

variable_types: struct ATOM { float x; double fx; int serial; float q; float na; float rdebye; void *next; char active; char name[9]; float chi; float vx; float gx; float VP; float qxx; float qxw; void *close[400]; void *excluded[64]; char exkind[64]; int dontuse; } *(int)


original_code:
int f_semi( float lambda)
{
 float get_f_variable(char *);
 float k,to_kcal;
 int i,numatm, a_number(void);
 ATOM *ap, *a_next(int);
 k = get_f_variable("ksemi");
 if( k < 0.) k = 0.;
 numatm = a_number();
 if(numatm < 1) return 0;
 to_kcal = 0.5/(4.184*1000.*1000.);
 to_kcal += to_kcal;
 for( i=0; i< numatm; i++)
 {
  ap = a_next(i);
  ap->fx += to_kcal*k*ap->fx;
  ap->fy += to_kcal*k*ap->fy;
  ap->fz += to_kcal*k*ap->fz;
 }
 return 0;
}

canonical_original_code:
int f_semi(float lambda)
{
 float get_f_variable(char *);
 float k; float to_kcal;
 int i; int numatm; int a_number();
 struct ATOM *ap; struct ATOM *a_next(int);
 k = get_f_variable("ksemi");
 if( k < 0.) k = 0.;
 numatm = a_number();
 if(numatm < 1) return 0;
 to_kcal = 0.5/(4.184*1000.*1000.);
 to_kcal += to_kcal;
 for( i=0; i< numatm; i++)
 {
  ap = a_next(i);
  ap->fx += to_kcal*k*ap->fx;
  ap->fy += to_kcal*k*ap->fy;
  ap->fz += to_kcal*k*ap->fz;
 }
 return 0;
}

variable_types: lambda float

variable_types: struct ATOM { float x; double fx; int serial; float q; float na; float rdebye; void *next; char active; char name[9]; float chi; float vx; float gx; float VP; float qxx; float qxw; void *close[400]; void *excluded[64]; char exkind[64]; int dontuse; } *


main

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

set_f_variable("mxdq", argv, envp, 0.05);
set_f_variable("mxcut", argv, v3, 6.0);
set_i_variable("nostep", 1LL);
read_eval_do(stdin, stdout);
return 0;
}

original_code:
int main()
{
    void read_eval_do();
    set_f_variable( "mxdq", .05);
    set_f_variable( "mxcut", 6.);
    set_i_variable( "nostep", 1);
    read_eval_do( stdin,stdout);
}


randf

original_code:
float randf()
{
    static float buff[55];
    static int ip = 0,jp = 0,kp;
    int i,seed,get_i_variable();
    static double xva;
    if( ip == 0 && jp == 0)
    {
        seed = get_i_variable("seed");
        for( ip=0; ip < 55; ip++)
        { seed = (seed*2349+14867)%32767;
            buff[ip] = (float)seed/32767.;
            if( buff[ip] > 1.) buff[ip] = buff[ip]-1.;
            if( buff[ip] < 0.) buff[ip] = buff[ip]+1.;
        }
        ip = 23; jp=54; kp = 0;
    }
    i = kp;
    xva = buff[jp]+buff[ip];
    if( xva > 1.) xva = xva -1.;
    buff[kp] = xva;
    kp = (kp+1)%55;
    ip = (ip+1)%55;
    jp = (jp+1)%55;
    return buff[i];
}

canonical_original_code:
float randf()
{
    static float buff[55];
    static int ip = 0; static int jp = 0; static int kp;
    int i; int seed; int get_i_variable();
    static double xva;
    if( ip == 0 && jp == 0)
    {
        seed = get_i_variable("seed");
        for( ip=0; ip < 55; ip++)
        { seed = (seed*2349+14867)%32767;
            buff[ip] = (float)seed/32767.;
            if( buff[ip] > 1.) buff[ip] = buff[ip]-1.;
            if( buff[ip] < 0.) buff[ip] = buff[ip]+1.;
        }
        ip = 23; jp=54; kp = 0;
    }
    i = kp;
    xva = buff[jp]+buff[ip];
    if( xva > 1.) xva = xva -1.;
    buff[kp] = xva;
    kp = (kp+1)%55;
    ip = (ip+1)%55;
    jp = (jp+1)%55;
    return buff[i];
}

variable_types:
buff
float [55]

variable_types: ip int

variable_types: jp int

variable_types: kp int

variable_types: seed int

variable_types: xva double


randg

original_code:
float randg()
{
    float randf();
    float x1,x2,norm;
    norm = 2.;
    while( norm > 1.)
    {
        x1 = 2.*randf()-1; x2 = 2.*randf()-1;
        norm = x1*x1 + x2*x2;
    }
    if( norm < 1.e-9) norm = 1.e-9;
    return x1*sqrt( -2.*log(norm)/norm );
}

canonical_original_code:
float randg()
{
    float randf();
    float x1; float x2; float norm;
    norm = 2.;
    while( norm > 1.)
    {
        x1 = 2.*randf()-1; x2 = 2.*randf()-1;
        norm = x1*x1 + x2*x2;
    }
    if( norm < 1.e-9) norm = 1.e-9;
    return x1*sqrt( -2.*log(norm)/norm );
}

variable_types:
randf
float ()

variable_types: norm float


decompiled_code:
__int64 grasp_valid_coordinate()
{
__int64 result; // rax
int v1; // er13
__int64 v2; // rbp
int v3; // er12
unsigned int v4; // ebx
float *v5; // rax

result = a_number();
if ( (int)result > 0 )
{
v1 = result;
v2 = *(_QWORD *)(a_next(0xFFFFFFFFLL) + 80);
v3 = 1;
result = 1LL;
if ( v1 > 1 )
{
while ( 1 )
{
v4 = 0;
if ( v3 > 0 )
break;
LABEL_10:
v2 = *(_QWORD *)(v2 + 80);
if ( v1 == ++v3 )
return 1LL;
}
while ( 1 )
{
v5 = (float *)a_next(v4);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)v2 - *v5) & LC0) < 0.1
&& COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 4) - v5[1]) & LC0) < 0.1
&& COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 8) - v5[2]) & LC0) < 0.1 )
{
break;
}
if ( ++v4 == v3 )
goto LABEL_10;
}
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
int v1; // er13
__int64 v2; // rbp
int v3; // er12
unsigned int v4; // ebx
float *v5; // rax

result = a_number();
if ( (int)result > 0 )
{
v1 = result;
v2 = *(_QWORD *)(a_next(0xFFFFFFFFLL) + 80);
v3 = 1;
result = 1LL;
if ( v1 > 1 )
{
while ( 1 )
{
v4 = 0;
if ( v3 > 0 )
break;
LABEL_10:
v2 = *(_QWORD *)(v2 + 80);
if ( v1 == ++v3 )
return 1LL;
}
while ( 1 )
{
v5 = (float *)a_next(v4);
if ( COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)v2 - *v5) & LC0) < 0.1
&& COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 4) - v5[1]) & LC0) < 0.1
&& COERCE_FLOAT(COERCE_UNSIGNED_INT(*(float *)(v2 + 8) - v5[2]) & LC0) < 0.1 )
{
break;
}
if ( ++v4 == v3 )
goto LABEL_10;
}
result = 0LL;
}
}
return result;
}

original_code:
int grasp_valid_coordinate()
{
    int na,a_number();
    ATOM *ap1,*ap2,*a_next();
    int i,j;
    float x,y,z;
    na = a_number();
    if( na < 1) return ;
    ap1 = a_next(-1);
    ap1 = ap1->next;
    for( i=1; i< na; i++)
    {
        for( j=0; j< i; j++)
        {
            ap2 = a_next(j);
            x = fabs(ap1->x -ap2->x);
            if( x < 1.e-1)
            {
                y = fabs(ap1->y -ap2->y);
                if( y < 1.e-1)
                {
                    z = fabs(ap1->z -ap2->z);
                    if( z< 1.e-1)
                    {
                        return 1==0;
                    }}}
        }
        ap1 = ap1->next;
    }
    return 1==1;
}

canonical_original_code:
int grasp_valid_coordinate()
{
    int na; int a_number();
    struct ATOM *ap1; struct ATOM *ap2; struct ATOM *a_next();
    int i; int j;
    float x; float y; float z;
    na = a_number();
    if( na < 1) return ;
    ap1 = a_next(-1);
    ap1 = ap1->next;
    for( i=1; i< na; i++)
    {
        for( j=0; j< i; j++)
        {
            ap2 = a_next(j);
            x = fabs(ap1->x -ap2->x);
            if( x < 1.e-1)
            {
                y = fabs(ap1->y -ap2->y);
                if( y < 1.e-1)
                {
                    z = fabs(ap1->z -ap2->z);
                    if( z< 1.e-1)
                    {
                        return 1==0;
                    }}}
        }
        ap1 = ap1->next;
    }
    return 1==1;
}

variable_types: struct ATOM { float x; double fx; int serial; float q; float na; float rdebye; void *next; char active; char name[9]; float chi; float vx; float gx; float VP; float qxx; float qxw; void *close[400]; void *excluded[64]; char exkind[64]; int dontuse; } *()

variable_types: j int

variable_types: x float

variable_types: y float

variable_types: z float


ghost

decompiled_code:
__int64 __fastcall ghost(int a1, int a2, int a3)
{
int v3; // er14
_QWORD *v5; // rax
__int64 v6; // r12
unsigned int v8; // ebp
unsigned int i; // ebx

v3 = a2;
v5 = malloc(0x18uLL);
if ( !v5 )
{
aaerror("memory allocation error in ghost\n");
exit(0);
}
v6 = firstGHOST;
v5[2] = firstGHOST;
firstGHOST = (__int64)v5;
if ( a2 > a3 )
{
v3 = a3;
a3 = a2;
}
*(_DWORD *)v5 = v3;
*((_DWORD *)v5 + 1) = a3;
for ( *((_DWORD *)v5 + 2) = a1; v6; v6 = *(_QWORD *)(v6 + 16) )
{
if ( *(_DWORD *)(v6 + 8) != a1 && v3 <= a3 )
{
v8 = v3;
do
{
for ( i = *(_DWORD *)v6; *(_DWORD *)(v6 + 4) >= (signed int)i; ++i )
tailor_exclude(v8, i);
++v8;
}
while ( a3 >= (int)v8 );
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3)
{
int v3; // er14
_QWORD *v5; // rax
__int64 v6; // r12
unsigned int v8; // ebp
unsigned int i; // ebx

v3 = a2;
v5 = malloc(0x18uLL);
if ( !v5 )
{
aaerror("memory allocation error in ghost\n");
exit(0);
}
v6 = firstGHOST;
v5[2] = firstGHOST;
firstGHOST = (__int64)v5;
if ( a2 > a3 )
{
v3 = a3;
a3 = a2;
}
*(_DWORD *)v5 = v3;
*((_DWORD *)v5 + 1) = a3;
for ( *((_DWORD *)v5 + 2) = a1; v6; v6 = *(_QWORD *)(v6 + 16) )
{
if ( *(_DWORD *)(v6 + 8) != a1 && v3 <= a3 )
{
v8 = v3;
do
{
for ( i = *(_DWORD *)v6; *(_DWORD *)(v6 + 4) >= (signed int)i; ++i )
tailor_exclude(v8, i);
++v8;
}
while ( a3 >= (int)v8 );
}
}
return 0LL;
}

original_code:
int ghost( int serial, int low, int high)
{
 int tailor_exclude(int,int);
 GHOST *gp;
 gp = (GHOST *)malloc( sizeof(GHOST));
 if( gp == ((void *)0)) {aaerror("memory allocation error in ghost\n"); exit(0);}
 gp->next_ghost = firstGHOST;
 firstGHOST = gp;
 if( low > high) { int i = low; low = high; high = i;}
 gp->low = low;
 gp->high = high;
 gp->serial = serial;
 while( gp->next_ghost != ((void *)0))
 {
  int i,j;
  gp = gp->next_ghost;
  if( gp->serial == serial) continue;
  for( i= low; i<= high; i++)
   for( j= gp->low; j <= gp->high; j++)
    tailor_exclude(i,j);
 }
 return 0;
}

canonical_original_code:
int ghost(int serial, int low, int high)
{
 int tailor_exclude(int, int);
 struct GHOST *gp;
 gp = (struct GHOST *)malloc( sizeof(GHOST));
 if( gp == ((void *)0)) {aaerror("memory allocation error in ghost\n"); exit(0);}
 gp->next_ghost = firstGHOST;
 firstGHOST = gp;
 if( low > high) { int i = low; low = high; high = i;}
 gp->low = low;
 gp->high = high;
 gp->serial = serial;
 while( gp->next_ghost != ((void *)0))
 {
  int i; int j;
  gp = gp->next_ghost;
  if( gp->serial == serial) continue;
  for( i= low; i<= high; i++)
   for( j= gp->low; j <= gp->high; j++)
    tailor_exclude(i,j);
 }
 return 0;
}

variable_types: serial int

variable_types: low int

variable_types: high int

variable_types: struct GHOST { int low; int serial; void *next_ghost; } *

variable_types: i int