glInit

decompiled_code:
__int64 glInit()
{
unsigned int v0; // eax
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
__int64 result; // rax
const char *v7; // rax
int v8[8]; // [rsp+0h] [rbp-98h] BYREF
unsigned int v9; // [rsp+20h] [rbp-78h]
int v10[8]; // [rsp+30h] [rbp-68h] BYREF
int v11[8]; // [rsp+50h] [rbp-48h] BYREF
int v12[10]; // [rsp+70h] [rbp-28h] BYREF

v0 = glewInit();
if ( v0 )
{
v7 = (const char *)glewGetErrorString(v0);
printf("ERROR with the glew: %s\n", v7);
result = 0LL;
}
else
{
initShaderSystem();
initFrameBufferSystem();
v1 = createAndLoadShader("flagvel");
returnShader(v10, v1);
velShader = v10[0];
v2 = createAndLoadShader("flag");
returnShader(v11, v2);
starShader = v11[0];
v3 = createAndLoadShader("pos");
returnShader(v12, v3);
posShader = v12[0];
createFrameBuffersAndTextures(256LL, 256LL);
v4 = findFrameBufferByName("pos");
returnFrameBuffer(v8, v4);
posTexid = v9;
posFBid = v8[0];
v5 = findFrameBufferByName("vel");
returnFrameBuffer(v8, v5);
velTexid = v9;
velFBid = v8[0];
printf(
"velTexid: %d velFBid: %d velShader: %d posTexid: %d posFBid: %d posShader: %d \n",
v9,
(unsigned int)v8[0],
(unsigned int)velShader,
(unsigned int)posTexid,
(unsigned int)posFBid,
(unsigned int)posShader);
printf("star: %d\n", (unsigned int)starShader);
glVBO();
glDisable(2929LL);
glEnable(3042LL);
glEnable(32925LL);
glEnable(2832LL);
glEnable(34370LL);
glEnable(3553LL);
glBlendFunc(1LL, 1LL);
glColor3f(1.0, 1.0);
fillRandom();
initUniforms();
updateCameraProjMatrix();
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // eax
unsigned int v1; // eax
unsigned int v2; // eax
unsigned int v3; // eax
unsigned int v4; // eax
unsigned int v5; // eax
__int64 result; // rax
const char *v7; // rax
int v8[8]; // [rsp+0h] [rbp-98h] BYREF
unsigned int v9; // [rsp+20h] [rbp-78h]
int v10[8]; // [rsp+30h] [rbp-68h] BYREF
int v11[8]; // [rsp+50h] [rbp-48h] BYREF
int v12[10]; // [rsp+70h] [rbp-28h] BYREF

v0 = glewInit();
if ( v0 )
{
v7 = (const char *)glewGetErrorString(v0);
printf("ERROR with the glew: %s\n", v7);
result = 0LL;
}
else
{
initShaderSystem();
initFrameBufferSystem();
v1 = createAndLoadShader("flagvel");
returnShader(v10, v1);
velShader = v10[0];
v2 = createAndLoadShader("flag");
returnShader(v11, v2);
starShader = v11[0];
v3 = createAndLoadShader("pos");
returnShader(v12, v3);
posShader = v12[0];
createFrameBuffersAndTextures(256LL, 256LL);
v4 = findFrameBufferByName("pos");
returnFrameBuffer(v8, v4);
posTexid = v9;
posFBid = v8[0];
v5 = findFrameBufferByName("vel");
returnFrameBuffer(v8, v5);
velTexid = v9;
velFBid = v8[0];
printf(
"velTexid: %d velFBid: %d velShader: %d posTexid: %d posFBid: %d posShader: %d \n",
v9,
(unsigned int)v8[0],
(unsigned int)velShader,
(unsigned int)posTexid,
(unsigned int)posFBid,
(unsigned int)posShader);
printf("star: %d\n", (unsigned int)starShader);
func0();
glDisable(2929LL);
glEnable(3042LL);
glEnable(32925LL);
glEnable(2832LL);
glEnable(34370LL);
glEnable(3553LL);
glBlendFunc(1LL, 1LL);
glColor3f(1.0, 1.0);
func1();
func7();
func5();
result = 1LL;
}
return result;
}

original_code:
int glInit(void){
 GLenum glewError = glewInit();
 if(glewError != 0){
  printf("ERROR with the glew: %s\n", glewGetErrorString(glewError));
  return 0;
 }
 initShaderSystem();
 initFrameBufferSystem();
  velShader = returnShader(createAndLoadShader("flagvel")).id;
  starShader = returnShader(createAndLoadShader("flag")).id;
 posShader = returnShader(createAndLoadShader("pos")).id;
 createFrameBuffersAndTextures(256, 256);
 framebuffer_t tf;
 tf = returnFrameBuffer(findFrameBufferByName("pos"));
 posTexid = tf.texid;
 posFBid = tf.id;
 tf = returnFrameBuffer(findFrameBufferByName("vel"));
 velTexid = tf.texid;
 velFBid = tf.id;
 printf("velTexid: %d velFBid: %d velShader: %d  posTexid: %d posFBid: %d posShader: %d \n", velTexid, velFBid, velShader, posTexid, posFBid, posShader);
 printf("star: %d\n", starShader);
 glVBO();
 glDisable(0x0B71);
 glEnable(0x0BE2);
 glEnable(0x809D);
 glEnable(0x0B10);
 glEnable(0x8642);
 glEnable(0x0DE1);
 glBlendFunc(1, 1);
 glColor3f(1.0f, 1.0f, 1.0f);
 fillRandom();
 initUniforms();
 updateCameraProjMatrix();
 return 1;
}

canonical_original_code:
int glInit(){
 unsigned int glewError = glewInit();
 if(glewError != 0){
  printf("ERROR with the glew: %s\n", glewGetErrorString(glewError));
  return 0;
 }
 initShaderSystem();
 initFrameBufferSystem();
  velShader = returnShader(createAndLoadShader("flagvel")).id;
  starShader = returnShader(createAndLoadShader("flag")).id;
 posShader = returnShader(createAndLoadShader("pos")).id;
 createFrameBuffersAndTextures(256, 256);
 struct framebuffer_s tf;
 tf = returnFrameBuffer(findFrameBufferByName("pos"));
 posTexid = tf.texid;
 posFBid = tf.id;
 tf = returnFrameBuffer(findFrameBufferByName("vel"));
 velTexid = tf.texid;
 velFBid = tf.id;
 printf("velTexid: %d velFBid: %d velShader: %d  posTexid: %d posFBid: %d posShader: %d \n", velTexid, velFBid, velShader, posTexid, posFBid, posShader);
 printf("star: %d\n", starShader);
 glVBO();
 glDisable(0x0B71);
 glEnable(0x0BE2);
 glEnable(0x809D);
 glEnable(0x0B10);
 glEnable(0x8642);
 glEnable(0x0DE1);
 glBlendFunc(1, 1);
 glColor3f(1.0f, 1.0f, 1.0f);
 fillRandom();
 initUniforms();
 updateCameraProjMatrix();
 return 1;
}

variable_types:
glewError
unsigned int

variable_types: struct framebuffer_s { unsigned int id; char *name; unsigned int width; unsigned int height; float aspect; unsigned int fov; unsigned int texid; char type; }


glRender

decompiled_code:
__int64 glRender()
{
int v0; // eax
double v1; // xmm2_8

_glewBindVertexArray((unsigned int)vaoID);
glViewport(0LL, 0LL, 256LL, 256LL);
_glewUseProgram((unsigned int)velShader);
v0 = clock();
v1 = sin((float)((float)v0 / 1000000.0)) * 0.01;
*(float *)&v1 = v1;
_glewUniform3f((unsigned int)forceunipos, v1, -0.02);
_glewBindFramebuffer(36160LL, (unsigned int)velFBid);
glBindTexture(3553LL, (unsigned int)posTexid);
glDrawElements(4LL, 6LL, 5125LL, 0LL);
glBlendFunc(774LL, 0LL);
glColor3f(0.40000001, 0.40000001);
_glewUseProgram(0LL);
glBindTexture(3553LL, 0LL);
glDrawElements(4LL, 6LL, 5125LL, 0LL);
glBlendFunc(1LL, 1LL);
glColor3f(1.0, 1.0);
_glewUseProgram((unsigned int)posShader);
_glewBindFramebuffer(36160LL, (unsigned int)posFBid);
glBindTexture(3553LL, (unsigned int)velTexid);
glDrawElements(4LL, 6LL, 5125LL, 0LL);
_glewBindVertexArray((unsigned int)vaostarID);
glViewport(0LL, 0LL, (unsigned int)screenx, (unsigned int)screeny);
_glewUseProgram((unsigned int)starShader);
_glewBindFramebuffer(36160LL, 0LL);
glBindTexture(3553LL, (unsigned int)posTexid);
glClear(16640LL);
glDrawArrays(0LL, 0LL, 0x10000LL);
swapBuffers();
return 1LL;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax
double v1; // xmm2_8

_glewBindVertexArray((unsigned int)vaoID);
glViewport(0LL, 0LL, 256LL, 256LL);
_glewUseProgram((unsigned int)velShader);
v0 = clock();
v1 = sin((float)((float)v0 / 1000000.0)) * 0.01;
*(float *)&v1 = v1;
_glewUniform3f((unsigned int)forceunipos, v1, -0.02);
_glewBindFramebuffer(36160LL, (unsigned int)velFBid);
glBindTexture(3553LL, (unsigned int)posTexid);
glDrawElements(4LL, 6LL, 5125LL, 0LL);
glBlendFunc(774LL, 0LL);
glColor3f(0.40000001, 0.40000001);
_glewUseProgram(0LL);
glBindTexture(3553LL, 0LL);
glDrawElements(4LL, 6LL, 5125LL, 0LL);
glBlendFunc(1LL, 1LL);
glColor3f(1.0, 1.0);
_glewUseProgram((unsigned int)posShader);
_glewBindFramebuffer(36160LL, (unsigned int)posFBid);
glBindTexture(3553LL, (unsigned int)velTexid);
glDrawElements(4LL, 6LL, 5125LL, 0LL);
_glewBindVertexArray((unsigned int)vaostarID);
glViewport(0LL, 0LL, (unsigned int)screenx, (unsigned int)screeny);
_glewUseProgram((unsigned int)starShader);
_glewBindFramebuffer(36160LL, 0LL);
glBindTexture(3553LL, (unsigned int)posTexid);
glClear(16640LL);
glDrawArrays(0LL, 0LL, 0x10000LL);
swapBuffers();
return 1LL;
}

original_code:
int glRender(void){
 __glewBindVertexArray(vaoID);
 glViewport(0,0, 256, 256);
 __glewUseProgram(velShader);
 float time = (float)clock() / ((__clock_t) 1000000);
 float dirz = sin(time) * 0.01;
 float dirx = sin(time) * 0.01;
 __glewUniform3f(forceunipos, dirx, -0.02, dirz);
 __glewBindFramebuffer(0x8D40, velFBid);
 glBindTexture(0x0DE1, posTexid);
 glDrawElements(0x0004, 6, 0x1405, 0);
 glBlendFunc(0x0306, 0);
 glColor3f(0.4, 0.4, 0.4);
 __glewUseProgram(0);
 glBindTexture(0x0DE1, 0);
 glDrawElements(0x0004, 6, 0x1405, 0);
 glBlendFunc(1, 1);
 glColor3f(1.0, 1.0, 1.0);
 __glewUseProgram(posShader);
 __glewBindFramebuffer(0x8D40, posFBid);
 glBindTexture(0x0DE1, velTexid);
 glDrawElements(0x0004, 6, 0x1405, 0);
 __glewBindVertexArray(vaostarID);
 glViewport(0,0,screenx,screeny);
 __glewUseProgram(starShader);
 __glewBindFramebuffer(0x8D40, 0);
 glBindTexture(0x0DE1, posTexid);
 glClear(0x00004000| 0x00000100);
 glDrawArrays(0x0000, 0, 256*256);
 swapBuffers();
 return 1;
}

canonical_original_code:
int glRender(){
 __glewBindVertexArray(vaoID);
 glViewport(0,0, 256, 256);
 __glewUseProgram(velShader);
 float time = (float)clock() / ((__clock_t) 1000000);
 float dirz = sin(time) * 0.01;
 float dirx = sin(time) * 0.01;
 __glewUniform3f(forceunipos, dirx, -0.02, dirz);
 __glewBindFramebuffer(0x8D40, velFBid);
 glBindTexture(0x0DE1, posTexid);
 glDrawElements(0x0004, 6, 0x1405, 0);
 glBlendFunc(0x0306, 0);
 glColor3f(0.4, 0.4, 0.4);
 __glewUseProgram(0);
 glBindTexture(0x0DE1, 0);
 glDrawElements(0x0004, 6, 0x1405, 0);
 glBlendFunc(1, 1);
 glColor3f(1.0, 1.0, 1.0);
 __glewUseProgram(posShader);
 __glewBindFramebuffer(0x8D40, posFBid);
 glBindTexture(0x0DE1, velTexid);
 glDrawElements(0x0004, 6, 0x1405, 0);
 __glewBindVertexArray(vaostarID);
 glViewport(0,0,screenx,screeny);
 __glewUseProgram(starShader);
 __glewBindFramebuffer(0x8D40, 0);
 glBindTexture(0x0DE1, posTexid);
 glClear(0x00004000| 0x00000100);
 glDrawArrays(0x0000, 0, 256*256);
 swapBuffers();
 return 1;
}

variable_types: time float

variable_types: dirz float

variable_types: dirx float

return_type: int


addProgramToList

decompiled_code:
__int64 __fastcall addProgramToList(__int64 a1, int a2, int a3, int a4)
{
unsigned int v6; // er14
size_t v7; // rbx
char *v8; // rax
char *v9; // rbx

v6 = programnumber++;
v7 = 24LL * programnumber;
programlist = realloc(programlist, v7);
v7 -= 24LL;
v8 = (char *)programlist + v7;
*((_QWORD *)v8 + 1) = a1;
*(_DWORD *)v8 = a2;
v9 = (char *)programlist + v7;
*((_DWORD *)v9 + 4) = a3;
*((_DWORD *)v9 + 5) = a4;
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, int a3, int a4)
{
unsigned int v6; // er14
size_t v7; // rbx
char *v8; // rax
char *v9; // rbx

v6 = programnumber++;
v7 = 24LL * programnumber;
programlist = realloc(programlist, v7);
v7 -= 24LL;
v8 = (char *)programlist + v7;
*((_QWORD *)v8 + 1) = a1;
*(_DWORD *)v8 = a2;
v9 = (char *)programlist + v7;
*((_DWORD *)v9 + 4) = a3;
*((_DWORD *)v9 + 5) = a4;
return v6;
}

original_code:
int addProgramToList(char *name, GLuint id, GLuint vertexid, GLuint fragmentid){
 int current = programnumber;
 programnumber++;
 programlist = realloc(programlist, (programnumber)*sizeof(shaderprogram_t));
 programlist[current].name = name;
 programlist[current].id = id;
 programlist[current].vertexid = vertexid;
 programlist[current].fragmentid = fragmentid;
 return current;
}

canonical_original_code:
int addProgramToList(char *name, unsigned int id, unsigned int vertexid, unsigned int fragmentid){
 int current = programnumber;
 programnumber++;
 programlist = realloc(programlist, (programnumber)*sizeof(shaderprogram_t));
 programlist[current].name = name;
 programlist[current].id = id;
 programlist[current].vertexid = vertexid;
 programlist[current].fragmentid = fragmentid;
 return current;
}

variable_types:
name
char *

variable_types:
id
unsigned int

variable_types:
vertexid
unsigned int

variable_types:
fragmentid
unsigned int

variable_types: current int


initShaderSystem

decompiled_code:
__int64 initShaderSystem()
{
size_t v0; // rbx

if ( programlist )
free(programlist);
v0 = 24LL * programnumber;
programlist = malloc(v0);
if ( !programlist )
memset(0LL, 0, v0);
addProgramToList((__int64)"default", 0, 0, 0);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
size_t v0; // rbx

if ( programlist )
free(programlist);
v0 = 24LL * programnumber;
programlist = malloc(v0);
if ( !programlist )
memset(0LL, 0, v0);
func0((__int64)"default", 0, 0, 0);
return 1LL;
}

original_code:
int initShaderSystem(void){
 if(programlist) free(programlist);
 programlist = malloc(programnumber * sizeof(shaderprogram_t));
 if(!programlist) memset(programlist, 0 , programnumber * sizeof(shaderprogram_t));
 addProgramToList("default", 0, 0, 0);
 return 1;
}

canonical_original_code:
int initShaderSystem(){
 if(programlist) free(programlist);
 programlist = malloc(programnumber * sizeof(shaderprogram_t));
 if(!programlist) memset(programlist, 0 , programnumber * sizeof(shaderprogram_t));
 addProgramToList("default", 0, 0, 0);
 return 1;
}


findProgramByName

decompiled_code:
__int64 __fastcall findProgramByName(char *s1)
{
int v1; // er13
const char **v2; // rbx
unsigned int v3; // ebp

v1 = programnumber;
if ( programnumber <= 0 )
return 0;
v2 = (const char **)((char *)programlist + 8);
v3 = 0;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 3;
if ( v3 == v1 )
return 0;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
int v1; // er13
const char **v2; // rbx
unsigned int v3; // ebp

v1 = programnumber;
if ( programnumber <= 0 )
return 0;
v2 = (const char **)((char *)programlist + 8);
v3 = 0;
while ( strcmp(s1, *v2) )
{
++v3;
v2 += 3;
if ( v3 == v1 )
return 0;
}
return v3;
}

original_code:
int findProgramByName(char * name){
 int i;
 for(i = 0; i<programnumber; i++){
  if(!strcmp(name, programlist[i].name)) return i;
 }
 return 0;
}

canonical_original_code:
int findProgramByName(char *name){
 int i;
 for(i = 0; i<programnumber; i++){
  if(!strcmp(name, programlist[i].name)) return i;
 }
 return 0;
}

variable_types: i int


printProgramLogStatus

decompiled_code:
__int64 __fastcall printProgramLogStatus(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax
char *v3; // r12
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
_glewGetProgramiv(a1, 35716LL, v4);
v1 = v4[0];
result = 1LL;
if ( v4[0] > 1 )
{
v3 = (char *)malloc(v4[0]);
_glewGetProgramInfoLog((unsigned int)a1, v1, 0LL, v3);
printf("program log: %s \n", v3);
free(v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax
char *v3; // r12
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
_glewGetProgramiv(a1, 35716LL, v4);
v1 = v4[0];
result = 1LL;
if ( v4[0] > 1 )
{
v3 = (char *)malloc(v4[0]);
_glewGetProgramInfoLog((unsigned int)a1, v1, 0LL, v3);
printf("program log: %s \n", v3);
free(v3);
result = 0LL;
}
return result;
}

original_code:
int printProgramLogStatus(int id){
 GLint blen = 0;
 __glewGetProgramiv(id, 0x8B84, &blen);
 if(blen > 1){
  GLchar *log = (GLchar *) malloc(blen);
  __glewGetProgramInfoLog(id, blen, 0, log);
  printf("program log: %s \n", log);
  free(log);
  return 0;
 }
 return 1;
}

canonical_original_code:
int printProgramLogStatus(int id){
 int blen = 0;
 __glewGetProgramiv(id, 0x8B84, &blen);
 if(blen > 1){
  char *log = (GLchar *) malloc(blen);
  __glewGetProgramInfoLog(id, blen, 0, log);
  printf("program log: %s \n", log);
  free(log);
  return 0;
 }
 return 1;
}

variable_types: id int

variable_types: blen int

variable_types:
log
char *


createAndLoadShader

decompiled_code:
__int64 __fastcall createAndLoadShader(char *src)
{
size_t v1; // rax
char *v2; // rbx
unsigned int v3; // ebx
size_t v4; // rax
char *v5; // rbx
unsigned int v6; // er12
unsigned int v7; // er13
__int64 v8; // rbx
unsigned int v10; // [rsp+4h] [rbp-44h] BYREF
void *v11; // [rsp+8h] [rbp-40h] BYREF
unsigned int v12; // [rsp+14h] [rbp-34h] BYREF
void *ptr[6]; // [rsp+18h] [rbp-30h] BYREF

v1 = strlen(src);
v2 = (char *)malloc(v1 + 5);
strcpy(v2, src);
strcat(v2, ".vert");
loadFileString(v2, ptr, &v12, 2LL);
free(v2);
v3 = v12;
if ( v12 )
{
v4 = strlen(src);
v5 = (char *)malloc(v4 + 5);
strcpy(v5, src);
strcat(v5, ".frag");
loadFileString(v5, &v11, &v10, 2LL);
free(v5);
v3 = v10;
if ( v10 )
{
v6 = _glewCreateShader(35633LL);
v7 = _glewCreateShader(35632LL);
_glewShaderSource(v6, 1LL, ptr, &v12);
_glewShaderSource(v7, 1LL, &v11, &v10);
free(ptr[0]);
free(v11);
_glewCompileShader(v6);
_glewCompileShader(v7);
v8 = (unsigned int)_glewCreateProgram();
_glewAttachShader(v8, v6);
_glewAttachShader((unsigned int)v8, v7);
_glewLinkProgram((unsigned int)v8);
printProgramLogStatus((unsigned int)v8);
v3 = addProgramToList((__int64)src, v8, v6, v7);
}
else
{
free(v11);
}
}
else
{
free(ptr[0]);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src)
{
size_t v1; // rax
char *v2; // rbx
unsigned int v3; // ebx
size_t v4; // rax
char *v5; // rbx
unsigned int v6; // er12
unsigned int v7; // er13
__int64 v8; // rbx
unsigned int v10; // [rsp+4h] [rbp-44h] BYREF
void *v11; // [rsp+8h] [rbp-40h] BYREF
unsigned int v12; // [rsp+14h] [rbp-34h] BYREF
void *ptr[6]; // [rsp+18h] [rbp-30h] BYREF

v1 = strlen(src);
v2 = (char *)malloc(v1 + 5);
strcpy(v2, src);
strcat(v2, ".vert");
loadFileString(v2, ptr, &v12, 2LL);
free(v2);
v3 = v12;
if ( v12 )
{
v4 = strlen(src);
v5 = (char *)malloc(v4 + 5);
strcpy(v5, src);
strcat(v5, ".frag");
loadFileString(v5, &v11, &v10, 2LL);
free(v5);
v3 = v10;
if ( v10 )
{
v6 = _glewCreateShader(35633LL);
v7 = _glewCreateShader(35632LL);
_glewShaderSource(v6, 1LL, ptr, &v12);
_glewShaderSource(v7, 1LL, &v11, &v10);
free(ptr[0]);
free(v11);
_glewCompileShader(v6);
_glewCompileShader(v7);
v8 = (unsigned int)_glewCreateProgram();
_glewAttachShader(v8, v6);
_glewAttachShader((unsigned int)v8, v7);
_glewLinkProgram((unsigned int)v8);
func3((unsigned int)v8);
v3 = func0((__int64)src, v8, v6, v7);
}
else
{
free(v11);
}
}
else
{
free(ptr[0]);
}
return v3;
}

original_code:
int createAndLoadShader(char * name){
 char * vertname = malloc(strlen(name) + 5);
 strcpy(vertname, name);strcat(vertname, ".vert");
 char * vertstring;
 int vertlength;
 loadFileString(vertname, &vertstring, &vertlength, 2);
 free(vertname);
 if(vertlength == 0){
  free(vertstring);
  return 0;
 }
 char * fragname = malloc(strlen(name) + 5);
 strcpy(fragname,name); strcat(fragname, ".frag");
 char * fragstring;
 int fraglength;
 loadFileString(fragname, &fragstring, &fraglength, 2);
 free(fragname);
 if(fraglength == 0){
  free(fragstring);
  return 0;
 }
 GLuint vertid = __glewCreateShader(0x8B31);
 GLuint fragid = __glewCreateShader(0x8B30);
 __glewShaderSource(vertid, 1, (const GLchar**) &vertstring, &vertlength);
 __glewShaderSource(fragid, 1, (const GLchar**) &fragstring, &fraglength);
 free(vertstring); free(fragstring);
 __glewCompileShader(vertid);
 __glewCompileShader(fragid);
 GLuint programid = __glewCreateProgram();
 __glewAttachShader(programid, vertid);
 __glewAttachShader(programid, fragid);
 __glewLinkProgram(programid);
 printProgramLogStatus(programid);
 int id = addProgramToList(name, programid, vertid, fragid);
 return id;
}

canonical_original_code:
int createAndLoadShader(char *name){
 char *vertname = malloc(strlen(name) + 5);
 strcpy(vertname, name);strcat(vertname, ".vert");
 char *vertstring;
 int vertlength;
 loadFileString(vertname, &vertstring, &vertlength, 2);
 free(vertname);
 if(vertlength == 0){
  free(vertstring);
  return 0;
 }
 char *fragname = malloc(strlen(name) + 5);
 strcpy(fragname,name); strcat(fragname, ".frag");
 char *fragstring;
 int fraglength;
 loadFileString(fragname, &fragstring, &fraglength, 2);
 free(fragname);
 if(fraglength == 0){
  free(fragstring);
  return 0;
 }
 unsigned int vertid = __glewCreateShader(0x8B31);
 unsigned int fragid = __glewCreateShader(0x8B30);
 __glewShaderSource(vertid, 1, (char **) &vertstring, &vertlength);
 __glewShaderSource(fragid, 1, (char **) &fragstring, &fraglength);
 free(vertstring); free(fragstring);
 __glewCompileShader(vertid);
 __glewCompileShader(fragid);
 unsigned int programid = __glewCreateProgram();
 __glewAttachShader(programid, vertid);
 __glewAttachShader(programid, fragid);
 __glewLinkProgram(programid);
 printProgramLogStatus(programid);
 int id = addProgramToList(name, programid, vertid, fragid);
 return id;
}

variable_types:
vertname
char *

variable_types:
vertstring
char *

variable_types: vertlength int

variable_types:
fragname
char *

variable_types:
fragstring
char *

variable_types: fraglength int

variable_types:
vertid
unsigned int

variable_types:
fragid
unsigned int

variable_types:
programid
unsigned int


getProgramLogStatus

decompiled_code:
__int64 __fastcall getProgramLogStatus(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er12
void *v4; // rax
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
_glewGetProgramiv(a1, 35716LL, v5);
v2 = v5[0];
if ( (int)v5[0] > 1 )
{
v4 = malloc((int)v5[0]);
*a2 = v4;
_glewGetProgramInfoLog((unsigned int)a1, v2, 0LL, v4);
}
return v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _QWORD *a2)
{
unsigned int v2; // er12
void *v4; // rax
unsigned int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v5[0] = 0;
_glewGetProgramiv(a1, 35716LL, v5);
v2 = v5[0];
if ( (int)v5[0] > 1 )
{
v4 = malloc((int)v5[0]);
*a2 = v4;
_glewGetProgramInfoLog((unsigned int)a1, v2, 0LL, v4);
}
return v5[0];
}

original_code:
int getProgramLogStatus(int id, char ** output){
 GLint length = 0;
 __glewGetProgramiv(id, 0x8B84, &length);
 if(length > 1){
  *output = malloc(length);
  __glewGetProgramInfoLog(id, length, 0, *output);
 }
 return length;
}

canonical_original_code:
int getProgramLogStatus(int id, char **output){
 int length = 0;
 __glewGetProgramiv(id, 0x8B84, &length);
 if(length > 1){
  *output = malloc(length);
  __glewGetProgramInfoLog(id, length, 0, *output);
 }
 return length;
}

variable_types:
output
char **

variable_types: length int


setupUniforms

decompiled_code:
__int64 setupUniforms()
{
void (__fastcall *v0)(_QWORD, float, float); // rbx
unsigned int v1; // eax
float v3; // [rsp+8h] [rbp-10h]
float v4; // [rsp+Ch] [rbp-Ch]

_glewUseProgram((unsigned int)programobject);
v0 = (void (__fastcall *)(_QWORD, float, float))_glewUniform2f;
v3 = 1.0 / (float)playheight;
v4 = 1.0 / (float)playwidth;
v1 = _glewGetUniformLocation((unsigned int)programobject, "offsetVec");
v0(v1, v4, v3);
_glewUseProgram(0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
void (__fastcall *v0)(_QWORD, float, float); // rbx
unsigned int v1; // eax
float v3; // [rsp+8h] [rbp-10h]
float v4; // [rsp+Ch] [rbp-Ch]

_glewUseProgram((unsigned int)programobject);
v0 = (void (__fastcall *)(_QWORD, float, float))_glewUniform2f;
v3 = 1.0 / (float)playheight;
v4 = 1.0 / (float)playwidth;
v1 = _glewGetUniformLocation((unsigned int)programobject, "offsetVec");
v0(v1, v4, v3);
_glewUseProgram(0LL);
return 1LL;
}

original_code:
int setupUniforms(void){
 __glewUseProgram(programobject);
 __glewUniform2f(__glewGetUniformLocation(programobject, "offsetVec"), 1.0/(float)playwidth, 1.0/(float)playheight);
 __glewUseProgram(0);
 return 1;
}

canonical_original_code:
int setupUniforms(){
 __glewUseProgram(programobject);
 __glewUniform2f(__glewGetUniformLocation(programobject, "offsetVec"), 1.0/(float)playwidth, 1.0/(float)playheight);
 __glewUseProgram(0);
 return 1;
}


printShaderLogStatus

decompiled_code:
__int64 __fastcall printShaderLogStatus(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax
char *v3; // r12
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
_glewGetShaderiv(a1, 35716LL, v4);
v1 = v4[0];
result = 1LL;
if ( v4[0] > 1 )
{
v3 = (char *)malloc(v4[0]);
_glewGetShaderInfoLog((unsigned int)a1, v1, 0LL, v3);
fprintf(stderr, "shader_log: %s \n", v3);
free(v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax
char *v3; // r12
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
_glewGetShaderiv(a1, 35716LL, v4);
v1 = v4[0];
result = 1LL;
if ( v4[0] > 1 )
{
v3 = (char *)malloc(v4[0]);
_glewGetShaderInfoLog((unsigned int)a1, v1, 0LL, v3);
fprintf(stderr, "shader_log: %s \n", v3);
free(v3);
result = 0LL;
}
return result;
}

original_code:
int printShaderLogStatus(int shader){
 GLint blen = 0;
 __glewGetShaderiv(shader, 0x8B84 , &blen);
 if (blen > 1){
  GLchar *log = (GLchar*)malloc(blen);
  __glewGetShaderInfoLog(shader, blen, 0, log);
  fprintf(stderr, "shader_log: %s \n", log);
  free(log);
  return 0;
 }
 return 1;
}

canonical_original_code:
int printShaderLogStatus(int shader){
 int blen = 0;
 __glewGetShaderiv(shader, 0x8B84 , &blen);
 if (blen > 1){
  char *log = (GLchar*)malloc(blen);
  __glewGetShaderInfoLog(shader, blen, 0, log);
  fprintf(stderr, "shader_log: %s \n", log);
  free(log);
  return 0;
 }
 return 1;
}

variable_types: shader int


printProgramLogStatus

decompiled_code:
__int64 __fastcall printProgramLogStatus(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax
char *v3; // r12
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
_glewGetProgramiv(a1, 35716LL, v4);
v1 = v4[0];
result = 1LL;
if ( v4[0] > 1 )
{
v3 = (char *)malloc(v4[0]);
_glewGetProgramInfoLog((unsigned int)a1, v1, 0LL, v3);
fprintf(stderr, "program_log: %s \n", v3);
free(v3);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
unsigned int v1; // ebp
__int64 result; // rax
char *v3; // r12
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v4[0] = 0;
_glewGetProgramiv(a1, 35716LL, v4);
v1 = v4[0];
result = 1LL;
if ( v4[0] > 1 )
{
v3 = (char *)malloc(v4[0]);
_glewGetProgramInfoLog((unsigned int)a1, v1, 0LL, v3);
fprintf(stderr, "program_log: %s \n", v3);
free(v3);
result = 0LL;
}
return result;
}

original_code:
int printProgramLogStatus(int program){
 GLint blen = 0;
 __glewGetProgramiv(program, 0x8B84 , &blen);
 if (blen > 1){
  GLchar *log = (GLchar*)malloc(blen);
  __glewGetProgramInfoLog(program, blen, 0, log);
  fprintf(stderr, "program_log: %s \n", log);
  free(log);
  return 0;
 }
 return 1;
}

canonical_original_code:
int printProgramLogStatus(int program){
 int blen = 0;
 __glewGetProgramiv(program, 0x8B84 , &blen);
 if (blen > 1){
  char *log = (GLchar*)malloc(blen);
  __glewGetProgramInfoLog(program, blen, 0, log);
  fprintf(stderr, "program_log: %s \n", log);
  free(log);
  return 0;
 }
 return 1;
}

variable_types: program int


initShader

decompiled_code:
__int64 initShader()
{
unsigned int v0; // ebp
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 result; // rax
int v4; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+4h] [rbp-34h] BYREF
unsigned int v6; // [rsp+8h] [rbp-30h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-2Ch] BYREF
void *v8; // [rsp+10h] [rbp-28h] BYREF
void *ptr[4]; // [rsp+18h] [rbp-20h] BYREF

if ( debugmode )
puts("DEBUG -- Initializing Shaders");
if ( shadervertname )
{
loadfilestring(shadervertname, ptr, &v7);
if ( debugmode )
printf("DEBUG -- Vert shader loaded with size %i and contents: \n %s \n", v7, (const char *)ptr[0]);
if ( shaderfragname )
{
loadfilestring(shaderfragname, &v8, &v6);
if ( debugmode )
printf("DEBUG -- Frag shader loaded with size %i and contents: \n %s \n", v6, (const char *)v8);
v0 = _glewCreateShader(35633LL);
v1 = _glewCreateShader(35632LL);
v2 = v1;
if ( debugmode )
printf("DEBUG -- Shaders created at %i and %i\n", v0, v1);
_glewShaderSource(v0, 1LL, ptr, &v7);
_glewShaderSource(v2, 1LL, &v8, &v6);
free(ptr[0]);
free(v8);
_glewCompileShader(v0);
_glewCompileShader(v2);
_glewGetShaderiv(v0, 35713LL, &v4);
_glewGetShaderiv(v2, 35713LL, &v5);
if ( !v4 )
printShaderLogStatus(v0);
if ( !v5 )
printShaderLogStatus(v2);
programobject = _glewCreateProgram();
_glewAttachShader((unsigned int)programobject, v0);
_glewAttachShader((unsigned int)programobject, v2);
_glewLinkProgram((unsigned int)programobject);
printProgramLogStatus((unsigned int)programobject);
if ( debugmode )
puts("DEBUG -- Shader compiled and linked ");
setupUniforms();
result = 1LL;
}
else
{
fwrite("ERROR -- No fragment shader! \n", 1uLL, 0x1EuLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR -- No vertex shader! \n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebp
unsigned int v1; // eax
unsigned int v2; // ebx
__int64 result; // rax
int v4; // [rsp+0h] [rbp-38h] BYREF
int v5; // [rsp+4h] [rbp-34h] BYREF
unsigned int v6; // [rsp+8h] [rbp-30h] BYREF
unsigned int v7; // [rsp+Ch] [rbp-2Ch] BYREF
void *v8; // [rsp+10h] [rbp-28h] BYREF
void *ptr[4]; // [rsp+18h] [rbp-20h] BYREF

if ( debugmode )
puts("DEBUG -- Initializing Shaders");
if ( shadervertname )
{
loadfilestring(shadervertname, ptr, &v7);
if ( debugmode )
printf("DEBUG -- Vert shader loaded with size %i and contents: \n %s \n", v7, (const char *)ptr[0]);
if ( shaderfragname )
{
loadfilestring(shaderfragname, &v8, &v6);
if ( debugmode )
printf("DEBUG -- Frag shader loaded with size %i and contents: \n %s \n", v6, (const char *)v8);
v0 = _glewCreateShader(35633LL);
v1 = _glewCreateShader(35632LL);
v2 = v1;
if ( debugmode )
printf("DEBUG -- Shaders created at %i and %i\n", v0, v1);
_glewShaderSource(v0, 1LL, ptr, &v7);
_glewShaderSource(v2, 1LL, &v8, &v6);
free(ptr[0]);
free(v8);
_glewCompileShader(v0);
_glewCompileShader(v2);
_glewGetShaderiv(v0, 35713LL, &v4);
_glewGetShaderiv(v2, 35713LL, &v5);
if ( !v4 )
func1(v0);
if ( !v5 )
func1(v2);
programobject = _glewCreateProgram();
_glewAttachShader((unsigned int)programobject, v0);
_glewAttachShader((unsigned int)programobject, v2);
_glewLinkProgram((unsigned int)programobject);
func2((unsigned int)programobject);
if ( debugmode )
puts("DEBUG -- Shader compiled and linked ");
func0();
result = 1LL;
}
else
{
fwrite("ERROR -- No fragment shader! \n", 1uLL, 0x1EuLL, stderr);
result = 0LL;
}
}
else
{
fwrite("ERROR -- No vertex shader! \n", 1uLL, 0x1CuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int initShader(void){
 if(debugmode) printf("DEBUG -- Initializing Shaders\n");
 char * shadervertstring;
 char * shaderfragstring;
 const int shadervertlength, shaderfraglength;
 if(shadervertname){
  loadfilestring(shadervertname, &shadervertstring, &shadervertlength);
  if(debugmode)printf("DEBUG -- Vert shader loaded with size %i and contents: \n %s \n", shadervertlength, shadervertstring);
 } else {
  fprintf(stderr, "ERROR -- No vertex shader! \n");
  return 0;
 }
 if(shaderfragname){
  loadfilestring(shaderfragname, &shaderfragstring, &shaderfraglength);
  if(debugmode)printf("DEBUG -- Frag shader loaded with size %i and contents: \n %s \n", shaderfraglength, shaderfragstring);
 } else {
  fprintf(stderr, "ERROR -- No fragment shader! \n");
  return 0;
 }
 GLuint vertshader = __glewCreateShader(0x8B31);
 GLuint fragshader = __glewCreateShader(0x8B30);
 if(debugmode) printf("DEBUG -- Shaders created at %i and %i\n", vertshader, fragshader);
 __glewShaderSource(vertshader, 1, (const GLchar **)&shadervertstring, &shadervertlength);
 __glewShaderSource(fragshader, 1, (const GLchar **)&shaderfragstring, &shaderfraglength);
 free(shadervertstring);
 free(shaderfragstring);
 __glewCompileShader(vertshader);
 __glewCompileShader(fragshader);
 GLint fragcompiled, vertcompiled ;
 __glewGetShaderiv(vertshader, 0x8B81, &vertcompiled);
 __glewGetShaderiv(fragshader, 0x8B81, &fragcompiled);
 if (!vertcompiled)printShaderLogStatus(vertshader);
 if (!fragcompiled)printShaderLogStatus(fragshader);
 programobject = __glewCreateProgram();
 __glewAttachShader(programobject, vertshader);
 __glewAttachShader(programobject, fragshader);
 __glewLinkProgram(programobject);
  printProgramLogStatus(programobject);
 if(debugmode) printf("DEBUG -- Shader compiled and linked \n");
 setupUniforms();
 return 1;
}

canonical_original_code:
int initShader(){
 if(debugmode) printf("DEBUG -- Initializing Shaders\n");
 char *shadervertstring;
 char *shaderfragstring;
 int shadervertlength; int shaderfraglength;
 if(shadervertname){
  loadfilestring(shadervertname, &shadervertstring, &shadervertlength);
  if(debugmode)printf("DEBUG -- Vert shader loaded with size %i and contents: \n %s \n", shadervertlength, shadervertstring);
 } else {
  fprintf(stderr, "ERROR -- No vertex shader! \n");
  return 0;
 }
 if(shaderfragname){
  loadfilestring(shaderfragname, &shaderfragstring, &shaderfraglength);
  if(debugmode)printf("DEBUG -- Frag shader loaded with size %i and contents: \n %s \n", shaderfraglength, shaderfragstring);
 } else {
  fprintf(stderr, "ERROR -- No fragment shader! \n");
  return 0;
 }
 unsigned int vertshader = __glewCreateShader(0x8B31);
 unsigned int fragshader = __glewCreateShader(0x8B30);
 if(debugmode) printf("DEBUG -- Shaders created at %i and %i\n", vertshader, fragshader);
 __glewShaderSource(vertshader, 1, (char **)&shadervertstring, &shadervertlength);
 __glewShaderSource(fragshader, 1, (char **)&shaderfragstring, &shaderfraglength);
 free(shadervertstring);
 free(shaderfragstring);
 __glewCompileShader(vertshader);
 __glewCompileShader(fragshader);
 int fragcompiled; int vertcompiled;
 __glewGetShaderiv(vertshader, 0x8B81, &vertcompiled);
 __glewGetShaderiv(fragshader, 0x8B81, &fragcompiled);
 if (!vertcompiled)printShaderLogStatus(vertshader);
 if (!fragcompiled)printShaderLogStatus(fragshader);
 programobject = __glewCreateProgram();
 __glewAttachShader(programobject, vertshader);
 __glewAttachShader(programobject, fragshader);
 __glewLinkProgram(programobject);
  printProgramLogStatus(programobject);
 if(debugmode) printf("DEBUG -- Shader compiled and linked \n");
 setupUniforms();
 return 1;
}

variable_types:
shadervertstring
char *

variable_types:
shaderfragstring
char *

variable_types: shadervertlength int

variable_types: shaderfraglength int

variable_types:
vertshader
unsigned int

variable_types:
fragshader
unsigned int

variable_types: fragcompiled int

variable_types: vertcompiled int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
int v5; // ebp
int v6; // ebx

debugmode = 1;
active = 0;
slowness = 1;
skip = 0;
zoom = 1065353216;
shadervertname = (__int64)"./life.vert";
shaderfragname = (__int64)"./life.frag";
playwidth = 800;
playheight = 600;
if ( (unsigned int)sdlInit(1366LL, 768LL, 24LL) && (unsigned int)glInit() )
{
if ( argc <= 1 )
startsmall();
else
loadTexture(argv[1]);
v5 = SDL_GetTicks();
while ( 1 )
{
sdlCheckEvent();
if ( active )
{
glRender();
if ( ++v3 > 999 )
{
v6 = SDL_GetTicks();
printf("%f fps\n", (float)(1000000.0 / (float)(v6 - v5)));
v5 = v6;
v3 = 0;
}
}
else
{
glDrawScreen(1LL);
}
if ( slowness > 1 )
SDL_Delay();
}
}
return 0;
}

original_code:
int main(int argc, char *argv[]){
 debugmode = 1;
 active = 0;
 slowness = 1;
 skip = 0;
 zoom = 1.0f;
 int framecount, to, t;
 shadervertname = "./life.vert";
 shaderfragname = "./life.frag";
 playwidth = 800;
 playheight = 600;
 if(!sdlInit(1366, 768, 24) || !glInit()) return 0;
 if(argc >1)
  loadTexture(argv[1]);
 else startsmall();
 to = SDL_GetTicks();
 while(1){
  sdlCheckEvent();
  if(active){
   glRender();
   framecount++;
   if(framecount>999){
    t = SDL_GetTicks();
    printf("%f fps\n", 1000000.0f/(t-to));
    to = t;
    framecount = 0;
   }
  } else {
   glDrawScreen(1);
  }
 if(slowness > 1)
  SDL_Delay(slowness);
 }
 return 1;
}

canonical_original_code:
int main(int argc, char *argv[]){
 debugmode = 1;
 active = 0;
 slowness = 1;
 skip = 0;
 zoom = 1.0f;
 int framecount; int to; int t;
 shadervertname = "./life.vert";
 shaderfragname = "./life.frag";
 playwidth = 800;
 playheight = 600;
 if(!sdlInit(1366, 768, 24) || !glInit()) return 0;
 if(argc >1)
  loadTexture(argv[1]);
 else startsmall();
 to = SDL_GetTicks();
 while(1){
  sdlCheckEvent();
  if(active){
   glRender();
   framecount++;
   if(framecount>999){
    t = SDL_GetTicks();
    printf("%f fps\n", 1000000.0f/(t-to));
    to = t;
    framecount = 0;
   }
  } else {
   glDrawScreen(1);
  }
 if(slowness > 1)
  SDL_Delay(slowness);
 }
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: framecount int

variable_types: to int

variable_types: t int


initFB

decompiled_code:
__int64 initFB()
{
if ( !playwidth )
playwidth = 1;
if ( !playheight )
playheight = 1;
*(float *)&aspect = (float)screenWidth / (float)screenHeight;
glGenTextures(1LL, &texid1);
glBindTexture(3553LL, (unsigned int)texid1);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9728LL);
glTexImage2D(3553LL, 0LL, 6403LL, (unsigned int)playwidth, (unsigned int)playheight, 0LL, 6403LL, 5121LL, 0LL);
glBindTexture(3553LL, 0LL);
_glewGenFramebuffers(1LL, &fbid1);
_glewBindFramebuffer(36160LL, (unsigned int)fbid1);
_glewFramebufferTexture2D(36160LL, 36064LL, 3553LL, (unsigned int)texid1, 0LL);
glClear(16640LL);
_glewBindFramebuffer(36160LL, 0LL);
if ( debugmode )
printf("DEBUG -- Bound framebuffer1 to: %i and texture to : %i \n", (unsigned int)fbid1, (unsigned int)texid1);
glGenTextures(1LL, &texid2);
glBindTexture(3553LL, (unsigned int)texid2);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9728LL);
glTexImage2D(3553LL, 0LL, 6403LL, (unsigned int)playwidth, (unsigned int)playheight, 0LL, 6403LL, 5121LL, 0LL);
glBindTexture(3553LL, 0LL);
_glewGenFramebuffers(1LL, &fbid2);
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
_glewFramebufferTexture2D(36160LL, 36064LL, 3553LL, (unsigned int)texid2, 0LL);
glClear(16640LL);
_glewBindFramebuffer(36160LL, 0LL);
if ( debugmode )
printf("DEBUG -- Bound framebuffer2 to: %i and texture to : %i \n", (unsigned int)fbid2, (unsigned int)texid2);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
if ( !playwidth )
playwidth = 1;
if ( !playheight )
playheight = 1;
*(float *)&aspect = (float)screenWidth / (float)screenHeight;
glGenTextures(1LL, &texid1);
glBindTexture(3553LL, (unsigned int)texid1);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9728LL);
glTexImage2D(3553LL, 0LL, 6403LL, (unsigned int)playwidth, (unsigned int)playheight, 0LL, 6403LL, 5121LL, 0LL);
glBindTexture(3553LL, 0LL);
_glewGenFramebuffers(1LL, &fbid1);
_glewBindFramebuffer(36160LL, (unsigned int)fbid1);
_glewFramebufferTexture2D(36160LL, 36064LL, 3553LL, (unsigned int)texid1, 0LL);
glClear(16640LL);
_glewBindFramebuffer(36160LL, 0LL);
if ( debugmode )
printf("DEBUG -- Bound framebuffer1 to: %i and texture to : %i \n", (unsigned int)fbid1, (unsigned int)texid1);
glGenTextures(1LL, &texid2);
glBindTexture(3553LL, (unsigned int)texid2);
glTexParameteri(3553LL, 10241LL, 9729LL);
glTexParameteri(3553LL, 10240LL, 9728LL);
glTexImage2D(3553LL, 0LL, 6403LL, (unsigned int)playwidth, (unsigned int)playheight, 0LL, 6403LL, 5121LL, 0LL);
glBindTexture(3553LL, 0LL);
_glewGenFramebuffers(1LL, &fbid2);
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
_glewFramebufferTexture2D(36160LL, 36064LL, 3553LL, (unsigned int)texid2, 0LL);
glClear(16640LL);
_glewBindFramebuffer(36160LL, 0LL);
if ( debugmode )
printf("DEBUG -- Bound framebuffer2 to: %i and texture to : %i \n", (unsigned int)fbid2, (unsigned int)texid2);
return 1LL;
}

original_code:
int initFB(void){
 if(playwidth ==0) playwidth = 1;
 if(playheight ==0) playheight = 1;
 aspect = (float)screenWidth/(float)screenHeight;
 glGenTextures(1, &texid1);
 glBindTexture(0x0DE1, texid1);
  glTexParameteri(0x0DE1, 0x2801, 0x2601);
  glTexParameteri(0x0DE1, 0x2800, 0x2600);
  glTexImage2D(0x0DE1, 0, 0x1903, playwidth, playheight, 0, 0x1903, 0x1401, ((void *)0));
 glBindTexture(0x0DE1, 0);
 __glewGenFramebuffers(1, &fbid1);
 __glewBindFramebuffer(0x8D40, fbid1);
  __glewFramebufferTexture2D(0x8D40,0x8CE0,0x0DE1, texid1, 0);
  glClear(0x00004000 | 0x00000100);
 __glewBindFramebuffer(0x8D40, 0);
 if(debugmode) printf("DEBUG -- Bound framebuffer1 to: %i and texture to : %i \n", fbid1, texid1);
 glGenTextures(1, &texid2);
 glBindTexture(0x0DE1, texid2);
  glTexParameteri(0x0DE1, 0x2801, 0x2601);
  glTexParameteri(0x0DE1, 0x2800, 0x2600);
  glTexImage2D(0x0DE1, 0, 0x1903, playwidth, playheight, 0, 0x1903, 0x1401, ((void *)0));
 glBindTexture(0x0DE1, 0);
 __glewGenFramebuffers(1, &fbid2);
 __glewBindFramebuffer(0x8D40, fbid2);
  __glewFramebufferTexture2D(0x8D40,0x8CE0,0x0DE1, texid2, 0);
  glClear(0x00004000 | 0x00000100);
 __glewBindFramebuffer(0x8D40, 0);
 if(debugmode) printf("DEBUG -- Bound framebuffer2 to: %i and texture to : %i \n", fbid2, texid2);
 return 1;
}

canonical_original_code:
int initFB(){
 if(playwidth ==0) playwidth = 1;
 if(playheight ==0) playheight = 1;
 aspect = (float)screenWidth/(float)screenHeight;
 glGenTextures(1, &texid1);
 glBindTexture(0x0DE1, texid1);
  glTexParameteri(0x0DE1, 0x2801, 0x2601);
  glTexParameteri(0x0DE1, 0x2800, 0x2600);
  glTexImage2D(0x0DE1, 0, 0x1903, playwidth, playheight, 0, 0x1903, 0x1401, ((void *)0));
 glBindTexture(0x0DE1, 0);
 __glewGenFramebuffers(1, &fbid1);
 __glewBindFramebuffer(0x8D40, fbid1);
  __glewFramebufferTexture2D(0x8D40,0x8CE0,0x0DE1, texid1, 0);
  glClear(0x00004000 | 0x00000100);
 __glewBindFramebuffer(0x8D40, 0);
 if(debugmode) printf("DEBUG -- Bound framebuffer1 to: %i and texture to : %i \n", fbid1, texid1);
 glGenTextures(1, &texid2);
 glBindTexture(0x0DE1, texid2);
  glTexParameteri(0x0DE1, 0x2801, 0x2601);
  glTexParameteri(0x0DE1, 0x2800, 0x2600);
  glTexImage2D(0x0DE1, 0, 0x1903, playwidth, playheight, 0, 0x1903, 0x1401, ((void *)0));
 glBindTexture(0x0DE1, 0);
 __glewGenFramebuffers(1, &fbid2);
 __glewBindFramebuffer(0x8D40, fbid2);
  __glewFramebufferTexture2D(0x8D40,0x8CE0,0x0DE1, texid2, 0);
  glClear(0x00004000 | 0x00000100);
 __glewBindFramebuffer(0x8D40, 0);
 if(debugmode) printf("DEBUG -- Bound framebuffer2 to: %i and texture to : %i \n", fbid2, texid2);
 return 1;
}


initVBO

decompiled_code:
__int64 initVBO()
{
_glewGenVertexArrays(1LL, &fsvao);
_glewGenBuffers(1LL, &fsvbo);
_glewGenBuffers(1LL, &fsivbo);
_glewBindVertexArray((unsigned int)fsvao);
_glewBindBuffer(34962LL, (unsigned int)fsvbo);
_glewBufferData(34962LL, 64LL, &fsverts, 35044LL);
glEnableClientState(32884LL);
glVertexPointer(2LL, 5126LL, 16LL, 0LL);
glEnableClientState(32888LL);
glTexCoordPointer(2LL, 5126LL, 16LL, 8LL);
_glewBindBuffer(34963LL, (unsigned int)fsivbo);
_glewBufferData(34963LL, 24LL, &fsindices, 35044LL);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
_glewGenVertexArrays(1LL, &fsvao);
_glewGenBuffers(1LL, &fsvbo);
_glewGenBuffers(1LL, &fsivbo);
_glewBindVertexArray((unsigned int)fsvao);
_glewBindBuffer(34962LL, (unsigned int)fsvbo);
_glewBufferData(34962LL, 64LL, &fsverts, 35044LL);
glEnableClientState(32884LL);
glVertexPointer(2LL, 5126LL, 16LL, 0LL);
glEnableClientState(32888LL);
glTexCoordPointer(2LL, 5126LL, 16LL, 8LL);
_glewBindBuffer(34963LL, (unsigned int)fsivbo);
_glewBufferData(34963LL, 24LL, &fsindices, 35044LL);
return 1LL;
}

original_code:
int initVBO(void){
 __glewGenVertexArrays(1, &fsvao);
 __glewGenBuffers(1, &fsvbo);
 __glewGenBuffers(1, &fsivbo);
 __glewBindVertexArray(fsvao);
 __glewBindBuffer(0x8892, fsvbo);
 __glewBufferData(0x8892, sizeof(fsverts),fsverts, 0x88E4);
 glEnableClientState(0x8074);
 glVertexPointer(2, 0x1406, 4*sizeof(GLfloat), ((void *)0));
 glEnableClientState(0x8078);
 glTexCoordPointer(2, 0x1406, 4*sizeof(GLfloat), ((char*)((void *)0))+2*sizeof(GLfloat) );
 __glewBindBuffer(0x8893, fsivbo);
 __glewBufferData(0x8893, sizeof(fsindices),fsindices, 0x88E4);
 return 1;
}

canonical_original_code:
int initVBO(){
 __glewGenVertexArrays(1, &fsvao);
 __glewGenBuffers(1, &fsvbo);
 __glewGenBuffers(1, &fsivbo);
 __glewBindVertexArray(fsvao);
 __glewBindBuffer(0x8892, fsvbo);
 __glewBufferData(0x8892, sizeof(fsverts),fsverts, 0x88E4);
 glEnableClientState(0x8074);
 glVertexPointer(2, 0x1406, 4*sizeof(GLfloat), ((void *)0));
 glEnableClientState(0x8078);
 glTexCoordPointer(2, 0x1406, 4*sizeof(GLfloat), ((char *)((void *)0))+2*sizeof(GLfloat) );
 __glewBindBuffer(0x8893, fsivbo);
 __glewBufferData(0x8893, sizeof(fsindices),fsindices, 0x88E4);
 return 1;
}


glInit

decompiled_code:
__int64 __fastcall glInit(__int64 a1, const char *a2)
{
unsigned int v2; // eax
__int64 result; // rax
const char *v4; // rax

if ( debugmode )
puts("DEBUG -- Initialising OpenGL ");
v2 = glewInit();
if ( v2 )
{
v4 = (const char *)glewGetErrorString(v2);
printf("Error initializing GLEW! %s\n", v4);
result = 0LL;
}
else
{
glDisable("ializing GLEW! %s\n", a2);
glClearColor(0.0, 0.0, 0.0, 0.5);
glEnable(3553LL);
glViewport(0LL, 0LL, (unsigned int)playwidth, (unsigned int)playheight);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, 0.1000000014901161, 100.0);
glMatrixMode(5888LL);
glLoadIdentity();
glColor3f(1.0, 1.0);
result = initShader();
if ( (_DWORD)result )
{
result = initFB();
if ( (_DWORD)result )
{
initVBO();
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
unsigned int v2; // eax
__int64 result; // rax
const char *v4; // rax

if ( debugmode )
puts("DEBUG -- Initialising OpenGL ");
v2 = glewInit();
if ( v2 )
{
v4 = (const char *)glewGetErrorString(v2);
printf("Error initializing GLEW! %s\n", v4);
result = 0LL;
}
else
{
glDisable("ializing GLEW! %s\n", a2);
glClearColor(0.0, 0.0, 0.0, 0.5);
glEnable(3553LL);
glViewport(0LL, 0LL, (unsigned int)playwidth, (unsigned int)playheight);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, 0.1000000014901161, 100.0);
glMatrixMode(5888LL);
glLoadIdentity();
glColor3f(1.0, 1.0);
result = initShader();
if ( (_DWORD)result )
{
result = func0();
if ( (_DWORD)result )
{
func1();
result = 1LL;
}
}
}
return result;
}

original_code:
int glInit(void){
 if(debugmode) printf("DEBUG -- Initialising OpenGL \n");
 GLenum glewError = glewInit();
 if( glewError != 0 ){
  printf( "Error initializing GLEW! %s\n", glewGetErrorString( glewError ) );
  return 0;
 }
 glDisable(0x0B71);
 glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
 glEnable(0x0DE1);
 glViewport(0, 0, playwidth, playheight);
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, 0.1f, 100.0f);
 glMatrixMode(0x1700);
 glLoadIdentity();
 glColor3f(1.0f, 1.0f, 1.0f);
 if(!initShader()) return 0;
 if(!initFB()) return 0;
 initVBO();
 return 1;
}

canonical_original_code:
int glInit(){
 if(debugmode) printf("DEBUG -- Initialising OpenGL \n");
 unsigned int glewError = glewInit();
 if( glewError != 0 ){
  printf( "Error initializing GLEW! %s\n", glewGetErrorString( glewError ) );
  return 0;
 }
 glDisable(0x0B71);
 glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
 glEnable(0x0DE1);
 glViewport(0, 0, playwidth, playheight);
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, 0.1f, 100.0f);
 glMatrixMode(0x1700);
 glLoadIdentity();
 glColor3f(1.0f, 1.0f, 1.0f);
 if(!initShader()) return 0;
 if(!initFB()) return 0;
 initVBO();
 return 1;
}

variable_types:
glewError
unsigned int


drawfsquad

decompiled_code:
__int64 drawfsquad()
{
return glDrawElements(4LL, 6LL, 5125LL, 0LL);
}

canonical_decompiled_code:
__int64 func3()
{
return glDrawElements(4LL, 6LL, 5125LL, 0LL);
}

original_code:
void drawfsquad(void){
 glDrawElements(0x0004, 6, 0x1405, 0);
}

canonical_original_code:
void drawfsquad(){
 glDrawElements(0x0004, 6, 0x1405, 0);
}

return_type: void


drawsmallquad

decompiled_code:
__int64 __fastcall drawsmallquad(float a1, float a2)
{
__m128i v2; // xmm1
__m128i v3; // xmm3

glBegin(7LL);
glTexCoord2f(0.0);
v2 = (__m128i)_mm_xor_ps((__m128)LODWORD(a2), (__m128)(unsigned int)LC11);
v3 = (__m128i)_mm_xor_ps((__m128)(unsigned int)LC11, (__m128)LODWORD(a1));
glVertex3f(*(double *)v3.m128i_i64, *(double *)v2.m128i_i64, -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
glVertex3f(
COERCE_DOUBLE((unsigned __int64)LODWORD(a1)),
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v2)).m128i_i64,
-0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
glVertex3f(COERCE_DOUBLE((unsigned __int64)LODWORD(a1)), COERCE_DOUBLE((unsigned __int64)LODWORD(a2)), -0.5);
glTexCoord2f(0.0);
glVertex3f(
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v3)).m128i_i64,
COERCE_DOUBLE((unsigned __int64)LODWORD(a2)),
-0.5);
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func4(float a1, float a2)
{
__m128i v2; // xmm1
__m128i v3; // xmm3

glBegin(7LL);
glTexCoord2f(0.0);
v2 = (__m128i)_mm_xor_ps((__m128)LODWORD(a2), (__m128)(unsigned int)LC11);
v3 = (__m128i)_mm_xor_ps((__m128)(unsigned int)LC11, (__m128)LODWORD(a1));
glVertex3f(*(double *)v3.m128i_i64, *(double *)v2.m128i_i64, -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
glVertex3f(
COERCE_DOUBLE((unsigned __int64)LODWORD(a1)),
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v2)).m128i_i64,
-0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
glVertex3f(COERCE_DOUBLE((unsigned __int64)LODWORD(a1)), COERCE_DOUBLE((unsigned __int64)LODWORD(a2)), -0.5);
glTexCoord2f(0.0);
glVertex3f(
*(double *)_mm_cvtsi32_si128(_mm_cvtsi128_si32(v3)).m128i_i64,
COERCE_DOUBLE((unsigned __int64)LODWORD(a2)),
-0.5);
return glEnd();
}

original_code:
void drawsmallquad(const float sizex, const float sizey){
 glBegin(0x0007);
  glTexCoord2f(0.0f, 0.0f);glVertex3f(-sizex,-sizey, -0.5f);
  glTexCoord2f(1.0f, 0.0f);glVertex3f( sizex,-sizey, -0.5f);
  glTexCoord2f(1.0f, 1.0f);glVertex3f( sizex, sizey, -0.5f);
  glTexCoord2f(0.0f, 1.0f);glVertex3f(-sizex, sizey, -0.5f);
 glEnd();
}

canonical_original_code:
void drawsmallquad(float sizex, float sizey){
 glBegin(0x0007);
  glTexCoord2f(0.0f, 0.0f);glVertex3f(-sizex,-sizey, -0.5f);
  glTexCoord2f(1.0f, 0.0f);glVertex3f( sizex,-sizey, -0.5f);
  glTexCoord2f(1.0f, 1.0f);glVertex3f( sizex, sizey, -0.5f);
  glTexCoord2f(0.0f, 1.0f);glVertex3f(-sizex, sizey, -0.5f);
 glEnd();
}

variable_types: sizex float

variable_types: sizey float


drawposquad

decompiled_code:
__int64 __fastcall drawposquad(float a1, float a2, float a3, float a4)
{
__m128i v4; // xmm4
unsigned int v5; // ebx
__m128i v6; // xmm5
unsigned int v7; // er14
__m128i v8; // xmm5
unsigned int v9; // er15
__m128i v10; // xmm4
unsigned int v11; // ebx

glBegin(7LL);
glTexCoord2f(0.0);
v4 = (__m128i)LODWORD(a4);
*(float *)v4.m128i_i32 = a4 - a2;
v5 = _mm_cvtsi128_si32(v4);
v6 = (__m128i)LODWORD(a3);
*(float *)v6.m128i_i32 = a3 - a1;
v7 = _mm_cvtsi128_si32(v6);
glVertex3f(*(double *)v6.m128i_i64, *(double *)v4.m128i_i64, -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
v8 = (__m128i)LODWORD(a3);
*(float *)v8.m128i_i32 = a3 + a1;
v9 = _mm_cvtsi128_si32(v8);
glVertex3f(*(double *)v8.m128i_i64, *(double *)_mm_cvtsi32_si128(v5).m128i_i64, -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
v10 = (__m128i)LODWORD(a4);
*(float *)v10.m128i_i32 = a4 + a2;
v11 = _mm_cvtsi128_si32(v10);
glVertex3f(*(double *)_mm_cvtsi32_si128(v9).m128i_i64, *(double *)v10.m128i_i64, -0.5);
glTexCoord2f(0.0);
glVertex3f(*(double *)_mm_cvtsi32_si128(v7).m128i_i64, *(double *)_mm_cvtsi32_si128(v11).m128i_i64, -0.5);
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func5(float a1, float a2, float a3, float a4)
{
__m128i v4; // xmm4
unsigned int v5; // ebx
__m128i v6; // xmm5
unsigned int v7; // er14
__m128i v8; // xmm5
unsigned int v9; // er15
__m128i v10; // xmm4
unsigned int v11; // ebx

glBegin(7LL);
glTexCoord2f(0.0);
v4 = (__m128i)LODWORD(a4);
*(float *)v4.m128i_i32 = a4 - a2;
v5 = _mm_cvtsi128_si32(v4);
v6 = (__m128i)LODWORD(a3);
*(float *)v6.m128i_i32 = a3 - a1;
v7 = _mm_cvtsi128_si32(v6);
glVertex3f(*(double *)v6.m128i_i64, *(double *)v4.m128i_i64, -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
v8 = (__m128i)LODWORD(a3);
*(float *)v8.m128i_i32 = a3 + a1;
v9 = _mm_cvtsi128_si32(v8);
glVertex3f(*(double *)v8.m128i_i64, *(double *)_mm_cvtsi32_si128(v5).m128i_i64, -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
v10 = (__m128i)LODWORD(a4);
*(float *)v10.m128i_i32 = a4 + a2;
v11 = _mm_cvtsi128_si32(v10);
glVertex3f(*(double *)_mm_cvtsi32_si128(v9).m128i_i64, *(double *)v10.m128i_i64, -0.5);
glTexCoord2f(0.0);
glVertex3f(*(double *)_mm_cvtsi32_si128(v7).m128i_i64, *(double *)_mm_cvtsi32_si128(v11).m128i_i64, -0.5);
return glEnd();
}

original_code:
void drawposquad(const float sizex, const float sizey, const float xpos, const float ypos){
 glBegin(0x0007);
  glTexCoord2f(0.0f, 0.0f);glVertex3f(xpos-sizex,ypos-sizey, -0.5f);
  glTexCoord2f(1.0f, 0.0f);glVertex3f(xpos+sizex,ypos-sizey, -0.5f);
  glTexCoord2f(1.0f, 1.0f);glVertex3f(xpos+sizex,ypos+sizey, -0.5f);
  glTexCoord2f(0.0f, 1.0f);glVertex3f(xpos-sizex,ypos+sizey, -0.5f);
 glEnd();
}

canonical_original_code:
void drawposquad(float sizex, float sizey, float xpos, float ypos){
 glBegin(0x0007);
  glTexCoord2f(0.0f, 0.0f);glVertex3f(xpos-sizex,ypos-sizey, -0.5f);
  glTexCoord2f(1.0f, 0.0f);glVertex3f(xpos+sizex,ypos-sizey, -0.5f);
  glTexCoord2f(1.0f, 1.0f);glVertex3f(xpos+sizex,ypos+sizey, -0.5f);
  glTexCoord2f(0.0f, 1.0f);glVertex3f(xpos-sizex,ypos+sizey, -0.5f);
 glEnd();
}

variable_types: xpos float

variable_types: ypos float


startsmall

decompiled_code:
__int64 startsmall()
{
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
glClear(16640LL);
glColor3f(1.0, 1.0);
return drawsmallquad(0.5, 0.5);
}

canonical_decompiled_code:
__int64 func6()
{
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
glClear(16640LL);
glColor3f(1.0, 1.0);
return func4(0.5, 0.5);
}

original_code:
void startsmall(void){
 __glewBindFramebuffer(0x8D40, fbid2);
 glClear(0x00004000 | 0x00000100);
 glColor3f(1.0f, 1.0f, 1.0f);
 drawsmallquad(0.5f, 0.5f);
}

canonical_original_code:
void startsmall(){
 __glewBindFramebuffer(0x8D40, fbid2);
 glClear(0x00004000 | 0x00000100);
 glColor3f(1.0f, 1.0f, 1.0f);
 drawsmallquad(0.5f, 0.5f);
}


glDrawScreen

decompiled_code:
__int64 __fastcall glDrawScreen(int a1)
{
glViewport(0LL, 0LL, (unsigned int)screenWidth, (unsigned int)screenHeight);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(COERCE_FLOAT(aspect ^ LC11), *(float *)&aspect, -1.0, 1.0, 0.1000000014901161, 100.0);
if ( which )
glBindTexture(3553LL, (unsigned int)texid1);
else
glBindTexture(3553LL, (unsigned int)texid2);
_glewBindFramebuffer(36160LL, 0LL);
_glewUseProgram(0LL);
if ( a1 )
glClear(16640LL);
drawposquad(*(float *)&zoom, *(float *)&zoom, *(float *)&viewposx, *(float *)&viewposy);
SDL_GL_SwapBuffers();
glViewport(0LL, 0LL, (unsigned int)playwidth, (unsigned int)playheight);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, 0.1000000014901161, 100.0);
return _glewUseProgram((unsigned int)programobject);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
glViewport(0LL, 0LL, (unsigned int)screenWidth, (unsigned int)screenHeight);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(COERCE_FLOAT(aspect ^ LC11), *(float *)&aspect, -1.0, 1.0, 0.1000000014901161, 100.0);
if ( which )
glBindTexture(3553LL, (unsigned int)texid1);
else
glBindTexture(3553LL, (unsigned int)texid2);
_glewBindFramebuffer(36160LL, 0LL);
_glewUseProgram(0LL);
if ( a1 )
glClear(16640LL);
func5(*(float *)&zoom, *(float *)&zoom, *(float *)&viewposx, *(float *)&viewposy);
SDL_GL_SwapBuffers();
glViewport(0LL, 0LL, (unsigned int)playwidth, (unsigned int)playheight);
glMatrixMode(5889LL);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, 0.1000000014901161, 100.0);
return _glewUseProgram((unsigned int)programobject);
}

original_code:
void glDrawScreen(int redraw){
 glViewport(0, 0, screenWidth, screenHeight);
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(-aspect, aspect, -1.0f, 1.0f, 0.1f, 100.0f);
 if(which)glBindTexture(0x0DE1, texid1);
 else glBindTexture(0x0DE1, texid2);
 __glewBindFramebuffer(0x8D40, 0);
 __glewUseProgram(0);
 if(redraw) glClear(0x00004000 | 0x00000100);
 drawposquad(zoom, zoom, viewposx, viewposy);
 SDL_GL_SwapBuffers();
 glViewport(0, 0, playwidth, playheight);
 glMatrixMode(0x1701);
 glLoadIdentity();
 glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, 0.1f, 100.0f);
 __glewUseProgram(programobject);
}

variable_types: redraw int


loadTexture

decompiled_code:
__int64 __fastcall loadTexture(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v3; // [rsp+10h] [rbp-18h] BYREF
unsigned int v4; // [rsp+14h] [rbp-14h] BYREF
__int64 v5; // [rsp+18h] [rbp-10h] BYREF

sdlImportImage(a1, &v3, &v4, &v5);
glGenTextures(1LL, &v2);
glBindTexture(3553LL, v2);
glTexImage2D(3553LL, 0LL, 6407LL, v4, v3, 0LL, 32992LL, 5121LL, v5);
glTexParameteri(3553LL, 10241LL, 9728LL);
glTexParameteri(3553LL, 10240LL, 9728LL);
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
glBindTexture(3553LL, v2);
_glewUseProgram(0LL);
drawsmallquad((float)(int)v4 / (float)playwidth, (float)(int)v3 / (float)playheight);
glDeleteTextures(1LL, &v2);
glDrawScreen(0);
_glewUseProgram((unsigned int)programobject);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
unsigned int v2; // [rsp+Ch] [rbp-1Ch] BYREF
unsigned int v3; // [rsp+10h] [rbp-18h] BYREF
unsigned int v4; // [rsp+14h] [rbp-14h] BYREF
__int64 v5; // [rsp+18h] [rbp-10h] BYREF

sdlImportImage(a1, &v3, &v4, &v5);
glGenTextures(1LL, &v2);
glBindTexture(3553LL, v2);
glTexImage2D(3553LL, 0LL, 6407LL, v4, v3, 0LL, 32992LL, 5121LL, v5);
glTexParameteri(3553LL, 10241LL, 9728LL);
glTexParameteri(3553LL, 10240LL, 9728LL);
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
glBindTexture(3553LL, v2);
_glewUseProgram(0LL);
func4((float)(int)v4 / (float)playwidth, (float)(int)v3 / (float)playheight);
glDeleteTextures(1LL, &v2);
func7(0);
_glewUseProgram((unsigned int)programobject);
return 1LL;
}

original_code:
int loadTexture(const char * filename){
 void * data;
 int width, height;
 GLuint texture;
 sdlImportImage(filename, &height, &width, &data);
 glGenTextures(1, &texture);
 glBindTexture(0x0DE1, texture);
 glTexImage2D(0x0DE1, 0, 0x1907, width, height, 0, 0x80E0, 0x1401, data);
 glTexParameteri(0x0DE1, 0x2801, 0x2600);
 glTexParameteri(0x0DE1, 0x2800, 0x2600);
 __glewBindFramebuffer(0x8D40,fbid2);
 glBindTexture(0x0DE1, texture);
 __glewUseProgram(0);
 drawsmallquad((float)width/(float)playwidth, (float)height/(float)playheight);
 glDeleteTextures( 1, &texture);
 glDrawScreen(0);
 __glewUseProgram(programobject);
 return 1;
}

canonical_original_code:
int loadTexture(char *filename){
 void *data;
 int width; int height;
 unsigned int texture;
 sdlImportImage(filename, &height, &width, &data);
 glGenTextures(1, &texture);
 glBindTexture(0x0DE1, texture);
 glTexImage2D(0x0DE1, 0, 0x1907, width, height, 0, 0x80E0, 0x1401, data);
 glTexParameteri(0x0DE1, 0x2801, 0x2600);
 glTexParameteri(0x0DE1, 0x2800, 0x2600);
 __glewBindFramebuffer(0x8D40,fbid2);
 glBindTexture(0x0DE1, texture);
 __glewUseProgram(0);
 drawsmallquad((float)width/(float)playwidth, (float)height/(float)playheight);
 glDeleteTextures( 1, &texture);
 glDrawScreen(0);
 __glewUseProgram(programobject);
 return 1;
}

variable_types:
filename
char *

variable_types:
data
void *

variable_types: width int

variable_types: height int

variable_types:
texture
unsigned int


glRender

decompiled_code:
__int64 glRender()
{
if ( which )
{
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
glBindTexture(3553LL, (unsigned int)texid1);
}
else
{
_glewBindFramebuffer(36160LL, (unsigned int)fbid1);
glBindTexture(3553LL, (unsigned int)texid2);
}
drawfsquad();
if ( count > skip )
{
glDrawScreen(0);
count = 0;
}
which = which == 0;
++count;
return 1LL;
}

canonical_decompiled_code:
__int64 func9()
{
if ( which )
{
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
glBindTexture(3553LL, (unsigned int)texid1);
}
else
{
_glewBindFramebuffer(36160LL, (unsigned int)fbid1);
glBindTexture(3553LL, (unsigned int)texid2);
}
func3();
if ( count > skip )
{
func7(0);
count = 0;
}
which = which == 0;
++count;
return 1LL;
}

original_code:
int glRender(void){
 if(which){
  __glewBindFramebuffer(0x8D40,fbid2);
  glBindTexture(0x0DE1, texid1);
 } else {
  __glewBindFramebuffer(0x8D40,fbid1);
  glBindTexture(0x0DE1, texid2);
 }
 drawfsquad();
 if(count > skip){
  glDrawScreen(0);
  count = 0;
 }
 which = !which;
 count++;
 return 1;
}

canonical_original_code:
int glRender(){
 if(which){
  __glewBindFramebuffer(0x8D40,fbid2);
  glBindTexture(0x0DE1, texid1);
 } else {
  __glewBindFramebuffer(0x8D40,fbid1);
  glBindTexture(0x0DE1, texid2);
 }
 drawfsquad();
 if(count > skip){
  glDrawScreen(0);
  count = 0;
 }
 which = !which;
 count++;
 return 1;
}


resizeWindow

decompiled_code:
__int64 __fastcall resizeWindow(int a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rdi
unsigned int v5; // edx
const char *v7; // rax

if ( debugmode )
printf("DEBUG -- SDL video resize to: %ix%i with %i bits per pixel \n", (unsigned int)a1, (unsigned int)a2, a3);
v4 = 1LL;
a2 = (unsigned int)a2;
if ( (int)a2 <= 0 )
a2 = 1LL;
if ( a1 > 0 )
v4 = (unsigned int)a1;
screenWidth = v4;
screenHeight = a2;
surface = SDL_SetVideoMode(v4, a2, (unsigned int)screenBPP, (unsigned int)videoFlags);
v5 = 1;
if ( !surface )
{
v7 = (const char *)SDL_GetError(v4, a2, 1LL);
fprintf(stderr, "ERROR -- SDL video resize failed: %s \n", v7);
v5 = 0;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rdi
unsigned int v5; // edx
const char *v7; // rax

if ( debugmode )
printf("DEBUG -- SDL video resize to: %ix%i with %i bits per pixel \n", (unsigned int)a1, (unsigned int)a2, a3);
v4 = 1LL;
a2 = (unsigned int)a2;
if ( (int)a2 <= 0 )
a2 = 1LL;
if ( a1 > 0 )
v4 = (unsigned int)a1;
screenWidth = v4;
screenHeight = a2;
surface = SDL_SetVideoMode(v4, a2, (unsigned int)screenBPP, (unsigned int)videoFlags);
v5 = 1;
if ( !surface )
{
v7 = (const char *)SDL_GetError(v4, a2, 1LL);
fprintf(stderr, "ERROR -- SDL video resize failed: %s \n", v7);
v5 = 0;
}
return v5;
}

original_code:
int resizeWindow(int width, int height, int bpp){
 if(debugmode) printf("DEBUG -- SDL video resize to: %ix%i with %i bits per pixel \n", width, height, bpp);
 if(height<1) height = 1;
 if(width<1) width = 1;
 screenWidth = width;
 screenHeight = height;
 surface = SDL_SetVideoMode(screenWidth, screenHeight, screenBPP, videoFlags);
 if(!surface){
  fprintf(stderr, "ERROR -- SDL video resize failed: %s \n", SDL_GetError());
  return 0;
 }
 return 1;
}

variable_types: bpp int


sdlInit

decompiled_code:
__int64 __fastcall sdlInit(int a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rdx
int v5; // eax
__int64 result; // rax
const char *v7; // rax

if ( debugmode )
puts("DEBUG -- SDL window initializing ");
if ( (int)SDL_Init(32LL) < 0 )
{
v7 = (const char *)SDL_GetError(32LL, a2, v4);
fprintf(stderr, "ERROR -- SDL video init failed: %s \n", v7);
result = 0LL;
}
else
{
videoInfo = SDL_GetVideoInfo();
videoFlags = 536870935;
v5 = -((*(_BYTE *)(videoInfo + 1) & 2) == 0);
LOBYTE(v5) = 0;
videoFlags = v5 + 536871191;
SDL_GL_SetAttribute(5LL, 1LL);
result = resizeWindow(a1, (unsigned int)a2, a3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rdx
int v5; // eax
__int64 result; // rax
const char *v7; // rax

if ( debugmode )
puts("DEBUG -- SDL window initializing ");
if ( (int)SDL_Init(32LL) < 0 )
{
v7 = (const char *)SDL_GetError(32LL, a2, v4);
fprintf(stderr, "ERROR -- SDL video init failed: %s \n", v7);
result = 0LL;
}
else
{
videoInfo = SDL_GetVideoInfo();
videoFlags = 536870935;
v5 = -((*(_BYTE *)(videoInfo + 1) & 2) == 0);
LOBYTE(v5) = 0;
videoFlags = v5 + 536871191;
SDL_GL_SetAttribute(5LL, 1LL);
result = func0(a1, (unsigned int)a2, a3);
}
return result;
}

original_code:
int sdlInit(int width, int height, int bpp){
 if(debugmode) printf("DEBUG -- SDL window initializing \n");
 if(SDL_Init(0x00000020)<0){
  fprintf(stderr, "ERROR -- SDL video init failed: %s \n", SDL_GetError());
  return 0;
 }
 videoInfo = SDL_GetVideoInfo();
 videoFlags = 0x00000002;
 videoFlags |= SDL_GL_DOUBLEBUFFER;
 videoFlags |= 0x20000000;
 videoFlags |= 0x00000010;
 if(videoInfo->hw_available) videoFlags |= 0x00000001;
 else videoFlags |= 0x00000000;
 if(videoInfo->blit_hw) videoFlags |= 0x00000100;
 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 return resizeWindow(width, height, bpp);
}


sdlHandleKeyPress

decompiled_code:
unsigned int __fastcall sdlHandleKeyPress(__int64 a1)
{
unsigned int result; // eax
__int64 v2; // rsi
__int64 v3; // rsi
double v4; // xmm1_8
int v5; // xmm0_4
double v6; // xmm1_8
int v7; // xmm0_4
double v8; // xmm1_8
int v9; // xmm0_4
double v10; // xmm1_8
int v11; // xmm0_4

result = *(_DWORD *)(a1 + 4);
if ( result > 0x77 )
{
if ( result == 275 )
{
skip = (int)((double)(skip + 1) * 10.0 - 1.0);
result = printf("frameskip: %i\n", (unsigned int)skip);
}
else if ( result <= 0x113 )
{
if ( result == 273 )
{
*(float *)&zoom = *(float *)&zoom + *(float *)&zoom;
printf("zoom: %f\n", *(float *)&zoom);
glDrawScreen(1LL);
result = glDrawScreen(1LL);
}
else if ( result == 274 )
{
*(float *)&zoom = 0.5 * *(float *)&zoom;
printf("zoom: %f\n", *(float *)&zoom);
glDrawScreen(1LL);
result = glDrawScreen(1LL);
}
}
else if ( result == 276 )
{
v2 = (unsigned int)(int)((double)(skip + 1) / 10.0 - 1.0);
if ( (int)v2 < 0 )
v2 = 0LL;
skip = v2;
result = printf("frameskip: %i\n", v2);
}
}
else if ( result <= 0x5A )
{
if ( result == 27 )
{
SDL_Quit();
exit(1);
}
if ( result == 32 )
{
result = active == 0;
active = result;
}
}
else
{
result -= 91;
switch ( result )
{
case 0u:
v3 = (unsigned int)(int)((double)slowness * 0.5);
if ( (int)v3 <= 0 )
v3 = 1LL;
slowness = v3;
result = printf("slowness: %i\n", v3);
break;
case 2u:
slowness = (int)((double)slowness + (double)slowness);
result = printf("slowness: %i\n", (unsigned int)slowness);
break;
case 6u:
v8 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v8);
else
v8 = sqrt(v8);
*(float *)&v9 = *(float *)&viewposx + 0.5 / v8;
viewposx = v9;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
case 9u:
v10 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v10);
else
v10 = sqrt(v10);
*(float *)&v11 = *(float *)&viewposx + -0.5 / v10;
viewposx = v11;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
case 0x17u:
zoom = 1065353216;
printf("zoom: %f\n", *(double *)&LC5);
viewposx = 0;
viewposy = 0;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
case 0x18u:
v6 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v6);
else
v6 = sqrt(v6);
*(float *)&v7 = *(float *)&viewposy + 0.5 / v6;
viewposy = v7;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
case 0x1Cu:
v4 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v4);
else
v4 = sqrt(v4);
*(float *)&v5 = *(float *)&viewposy + -0.5 / v4;
viewposy = v5;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
default:
return result;
}
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func2(__int64 a1)
{
unsigned int result; // eax
__int64 v2; // rsi
__int64 v3; // rsi
double v4; // xmm1_8
int v5; // xmm0_4
double v6; // xmm1_8
int v7; // xmm0_4
double v8; // xmm1_8
int v9; // xmm0_4
double v10; // xmm1_8
int v11; // xmm0_4

result = *(_DWORD *)(a1 + 4);
if ( result > 0x77 )
{
if ( result == 275 )
{
skip = (int)((double)(skip + 1) * 10.0 - 1.0);
result = printf("frameskip: %i\n", (unsigned int)skip);
}
else if ( result <= 0x113 )
{
if ( result == 273 )
{
*(float *)&zoom = *(float *)&zoom + *(float *)&zoom;
printf("zoom: %f\n", *(float *)&zoom);
glDrawScreen(1LL);
result = glDrawScreen(1LL);
}
else if ( result == 274 )
{
*(float *)&zoom = 0.5 * *(float *)&zoom;
printf("zoom: %f\n", *(float *)&zoom);
glDrawScreen(1LL);
result = glDrawScreen(1LL);
}
}
else if ( result == 276 )
{
v2 = (unsigned int)(int)((double)(skip + 1) / 10.0 - 1.0);
if ( (int)v2 < 0 )
v2 = 0LL;
skip = v2;
result = printf("frameskip: %i\n", v2);
}
}
else if ( result <= 0x5A )
{
if ( result == 27 )
{
SDL_Quit();
exit(1);
}
if ( result == 32 )
{
result = active == 0;
active = result;
}
}
else
{
result -= 91;
switch ( result )
{
case 0u:
v3 = (unsigned int)(int)((double)slowness * 0.5);
if ( (int)v3 <= 0 )
v3 = 1LL;
slowness = v3;
result = printf("slowness: %i\n", v3);
break;
case 2u:
slowness = (int)((double)slowness + (double)slowness);
result = printf("slowness: %i\n", (unsigned int)slowness);
break;
case 6u:
v8 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v8);
else
v8 = sqrt(v8);
*(float *)&v9 = *(float *)&viewposx + 0.5 / v8;
viewposx = v9;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
case 9u:
v10 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v10);
else
v10 = sqrt(v10);
*(float *)&v11 = *(float *)&viewposx + -0.5 / v10;
viewposx = v11;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
case 0x17u:
zoom = 1065353216;
printf("zoom: %f\n", *(double *)&LC5);
viewposx = 0;
viewposy = 0;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
case 0x18u:
v6 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v6);
else
v6 = sqrt(v6);
*(float *)&v7 = *(float *)&viewposy + 0.5 / v6;
viewposy = v7;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
case 0x1Cu:
v4 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v4);
else
v4 = sqrt(v4);
*(float *)&v5 = *(float *)&viewposy + -0.5 / v4;
viewposy = v5;
glDrawScreen(1LL);
result = glDrawScreen(1LL);
break;
default:
return result;
}
}
return result;
}

original_code:
void sdlHandleKeyPress(SDL_keysym *keysym){
        switch (keysym->sym){
                case SDLK_ESCAPE:
                        SDL_Quit();
   exit(1);
                break;
                case SDLK_SPACE:
                        active =!active;
                break;
                case SDLK_RIGHT:
                        skip = ((skip+1)*10.0)-1;
   printf("frameskip: %i\n", skip);
                break;
                case SDLK_LEFT:
                        skip = ((skip+1)/10.0)-1;
   if(skip <0) skip = 0;
   printf("frameskip: %i\n", skip);
                break;
                case SDLK_RIGHTBRACKET:
                        slowness = ((slowness)*2.0);
   printf("slowness: %i\n", slowness);
                break;
                case SDLK_LEFTBRACKET:
                        slowness = ((slowness)/2.0);
   if(slowness <1) slowness = 1;
   printf("slowness: %i\n", slowness);
                break;
                case SDLK_UP:
                        zoom*=2;
   printf("zoom: %f\n", zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_DOWN:
                        zoom/=2;
   printf("zoom: %f\n", zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_r:
                        zoom= 1;
   printf("zoom: %f\n", zoom);
   viewposx = 0;
   viewposy = 0;
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_w:
   viewposy += -0.5/sqrt(zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_s:
   viewposy += 0.5/sqrt(zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_a:
   viewposx += 0.5/sqrt(zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_d:
   viewposx += -0.5/sqrt(zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
  default:
  break;
        }
        return;
}

canonical_original_code:
void sdlHandleKeyPress(struct SDL_keysym *keysym){
        switch (keysym->sym){
                case SDLK_ESCAPE:
                        SDL_Quit();
   exit(1);
                break;
                case SDLK_SPACE:
                        active =!active;
                break;
                case SDLK_RIGHT:
                        skip = ((skip+1)*10.0)-1;
   printf("frameskip: %i\n", skip);
                break;
                case SDLK_LEFT:
                        skip = ((skip+1)/10.0)-1;
   if(skip <0) skip = 0;
   printf("frameskip: %i\n", skip);
                break;
                case SDLK_RIGHTBRACKET:
                        slowness = ((slowness)*2.0);
   printf("slowness: %i\n", slowness);
                break;
                case SDLK_LEFTBRACKET:
                        slowness = ((slowness)/2.0);
   if(slowness <1) slowness = 1;
   printf("slowness: %i\n", slowness);
                break;
                case SDLK_UP:
                        zoom*=2;
   printf("zoom: %f\n", zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_DOWN:
                        zoom/=2;
   printf("zoom: %f\n", zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_r:
                        zoom= 1;
   printf("zoom: %f\n", zoom);
   viewposx = 0;
   viewposy = 0;
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_w:
   viewposy += -0.5/sqrt(zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_s:
   viewposy += 0.5/sqrt(zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_a:
   viewposx += 0.5/sqrt(zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
                case SDLK_d:
   viewposx += -0.5/sqrt(zoom);
   glDrawScreen(1);
   glDrawScreen(1);
                break;
  default:
  break;
        }
        return;
}

variable_types: struct SDL_keysym { unsigned char scancode; enum SDLKey { SDLK_UNKNOWN=0, SDLK_FIRST=0, SDLK_BACKSPACE=8, SDLK_TAB=9, SDLK_CLEAR=12, SDLK_RETURN=13, SDLK_PAUSE=19, SDLK_ESCAPE=27, SDLK_SPACE=32, SDLK_EXCLAIM=33, SDLK_QUOTEDBL=34, SDLK_HASH=35, SDLK_DOLLAR=36, SDLK_AMPERSAND=38, SDLK_QUOTE=39, SDLK_LEFTPAREN=40, SDLK_RIGHTPAREN=41, SDLK_ASTERISK=42, SDLK_PLUS=43, SDLK_COMMA=44, SDLK_MINUS=45, SDLK_PERIOD=46, SDLK_SLASH=47, SDLK_0=48, SDLK_1=49, SDLK_2=50, SDLK_3=51, SDLK_4=52, SDLK_5=53, SDLK_6=54, SDLK_7=55, SDLK_8=56, SDLK_9=57, SDLK_COLON=58, SDLK_SEMICOLON=59, SDLK_LESS=60, SDLK_EQUALS=61, SDLK_GREATER=62, SDLK_QUESTION=63, SDLK_AT=64, SDLK_LEFTBRACKET=91, SDLK_BACKSLASH=92, SDLK_RIGHTBRACKET=93, SDLK_CARET=94, SDLK_UNDERSCORE=95, SDLK_BACKQUOTE=96, SDLK_a=97, SDLK_b=98, SDLK_c=99, SDLK_d=100, SDLK_e=101, SDLK_f=102, SDLK_g=103, SDLK_h=104, SDLK_i=105, SDLK_j=106, SDLK_k=107, SDLK_l=108, SDLK_m=109, SDLK_n=110, SDLK_o=111, SDLK_p=112, SDLK_q=113, SDLK_r=114, SDLK_s=115, SDLK_t=116, SDLK_u=117, SDLK_v=118, SDLK_w=119, SDLK_x=120, SDLK_y=121, SDLK_z=122, SDLK_DELETE=127, SDLK_WORLD_0=160, SDLK_WORLD_1=161, SDLK_WORLD_2=162, SDLK_WORLD_3=163, SDLK_WORLD_4=164, SDLK_WORLD_5=165, SDLK_WORLD_6=166, SDLK_WORLD_7=167, SDLK_WORLD_8=168, SDLK_WORLD_9=169, SDLK_WORLD_10=170, SDLK_WORLD_11=171, SDLK_WORLD_12=172, SDLK_WORLD_13=173, SDLK_WORLD_14=174, SDLK_WORLD_15=175, SDLK_WORLD_16=176, SDLK_WORLD_17=177, SDLK_WORLD_18=178, SDLK_WORLD_19=179, SDLK_WORLD_20=180, SDLK_WORLD_21=181, SDLK_WORLD_22=182, SDLK_WORLD_23=183, SDLK_WORLD_24=184, SDLK_WORLD_25=185, SDLK_WORLD_26=186, SDLK_WORLD_27=187, SDLK_WORLD_28=188, SDLK_WORLD_29=189, SDLK_WORLD_30=190, SDLK_WORLD_31=191, SDLK_WORLD_32=192, SDLK_WORLD_33=193, SDLK_WORLD_34=194, SDLK_WORLD_35=195, SDLK_WORLD_36=196, SDLK_WORLD_37=197, SDLK_WORLD_38=198, SDLK_WORLD_39=199, SDLK_WORLD_40=200, SDLK_WORLD_41=201, SDLK_WORLD_42=202, SDLK_WORLD_43=203, SDLK_WORLD_44=204, SDLK_WORLD_45=205, SDLK_WORLD_46=206, SDLK_WORLD_47=207, SDLK_WORLD_48=208, SDLK_WORLD_49=209, SDLK_WORLD_50=210, SDLK_WORLD_51=211, SDLK_WORLD_52=212, SDLK_WORLD_53=213, SDLK_WORLD_54=214, SDLK_WORLD_55=215, SDLK_WORLD_56=216, SDLK_WORLD_57=217, SDLK_WORLD_58=218, SDLK_WORLD_59=219, SDLK_WORLD_60=220, SDLK_WORLD_61=221, SDLK_WORLD_62=222, SDLK_WORLD_63=223, SDLK_WORLD_64=224, SDLK_WORLD_65=225, SDLK_WORLD_66=226, SDLK_WORLD_67=227, SDLK_WORLD_68=228, SDLK_WORLD_69=229, SDLK_WORLD_70=230, SDLK_WORLD_71=231, SDLK_WORLD_72=232, SDLK_WORLD_73=233, SDLK_WORLD_74=234, SDLK_WORLD_75=235, SDLK_WORLD_76=236, SDLK_WORLD_77=237, SDLK_WORLD_78=238, SDLK_WORLD_79=239, SDLK_WORLD_80=240, SDLK_WORLD_81=241, SDLK_WORLD_82=242, SDLK_WORLD_83=243, SDLK_WORLD_84=244, SDLK_WORLD_85=245, SDLK_WORLD_86=246, SDLK_WORLD_87=247, SDLK_WORLD_88=248, SDLK_WORLD_89=249, SDLK_WORLD_90=250, SDLK_WORLD_91=251, SDLK_WORLD_92=252, SDLK_WORLD_93=253, SDLK_WORLD_94=254, SDLK_WORLD_95=255, SDLK_KP0=256, SDLK_KP1=257, SDLK_KP2=258, SDLK_KP3=259, SDLK_KP4=260, SDLK_KP5=261, SDLK_KP6=262, SDLK_KP7=263, SDLK_KP8=264, SDLK_KP9=265, SDLK_KP_PERIOD=266, SDLK_KP_DIVIDE=267, SDLK_KP_MULTIPLY=268, SDLK_KP_MINUS=269, SDLK_KP_PLUS=270, SDLK_KP_ENTER=271, SDLK_KP_EQUALS=272, SDLK_UP=273, SDLK_DOWN=274, SDLK_RIGHT=275, SDLK_LEFT=276, SDLK_INSERT=277, SDLK_HOME=278, SDLK_END=279, SDLK_PAGEUP=280, SDLK_PAGEDOWN=281, SDLK_F1=282, SDLK_F2=283, SDLK_F3=284, SDLK_F4=285, SDLK_F5=286, SDLK_F6=287, SDLK_F7=288, SDLK_F8=289, SDLK_F9=290, SDLK_F10=291, SDLK_F11=292, SDLK_F12=293, SDLK_F13=294, SDLK_F14=295, SDLK_F15=296, SDLK_NUMLOCK=300, SDLK_CAPSLOCK=301, SDLK_SCROLLOCK=302, SDLK_RSHIFT=303, SDLK_LSHIFT=304, SDLK_RCTRL=305, SDLK_LCTRL=306, SDLK_RALT=307, SDLK_LALT=308, SDLK_RMETA=309, SDLK_LMETA=310, SDLK_LSUPER=311, SDLK_RSUPER=312, SDLK_MODE=313, SDLK_COMPOSE=314, SDLK_HELP=315, SDLK_PRINT=316, SDLK_SYSREQ=317, SDLK_BREAK=318, SDLK_MENU=319, SDLK_POWER=320, SDLK_EURO=321, SDLK_UNDO=322, SDLK_LAST=323 } sym; enum SDLMod { KMOD_NONE=0, KMOD_LSHIFT=1, KMOD_RSHIFT=2, KMOD_LCTRL=64, KMOD_RCTRL=128, KMOD_LALT=256, KMOD_RALT=512, KMOD_LMETA=1024, KMOD_RMETA=2048, KMOD_NUM=4096, KMOD_CAPS=8192, KMOD_MODE=16384, KMOD_RESERVED=32768 } mod; unsigned short unicode; } *

user_defined_types: struct SDL_keysym { unsigned char scancode; enum SDLKey sym; enum SDLMod mod; unsigned short unicode; }


startup

repo: robotastic/LED-Print

decompiled_code:
int __fastcall startup(int argc, char **argv)
{
int i; // eax
size_t v3; // rax
int v4; // edx
int result; // eax
size_t v6; // rax
unsigned int v7; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
verbosity = 0;
displaylen = 16;
dev = "/dev/ttyUSB0";
for ( i = getopt_long(argc, argv, "dl:v::", &longOpts, longind);
i != -1;
i = getopt_long(argc, argv, "dl:v::", &longOpts, longind) )
{
if ( i == 108 )
{
displaylen = *optarg;
}
else if ( i > 108 )
{
if ( i == 118 )
++verbosity;
}
else if ( i == 63 )
{
display_usage();
}
else if ( i == 100 )
{
dev = optarg;
}
}
if ( optind >= argc )
{
printf("Enter text to display: ");
fgets(&text, 100, stdin);
}
else
{
strcpy(&text, argv[optind]);
}
v3 = strlen(&text);
v4 = displaylen;
if ( v3 < displaylen )
{
if ( displaylen > (int)v3 )
{
v3 = (int)v3;
do
*(&text + v3++) = 32;
while ( v4 > (int)v3 );
}
*(&text + v4 + 1) = 0;
}
if ( verbosity )
{
v6 = strlen(&text);
printf("The text is: %s Length: %lu\n", &text, v6);
}
fd = setupport(dev);
result = initport(fd);
if ( verbosity )
{
v7 = getbaud(fd);
result = printf("baud=%d\n", v7);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int argc, char **argv)
{
int i; // eax
size_t v3; // rax
int v4; // edx
int result; // eax
size_t v6; // rax
unsigned int v7; // eax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

longind[0] = 0;
verbosity = 0;
displaylen = 16;
dev = "/dev/ttyUSB0";
for ( i = getopt_long(argc, argv, "dl:v::", &longOpts, longind);
i != -1;
i = getopt_long(argc, argv, "dl:v::", &longOpts, longind) )
{
if ( i == 108 )
{
displaylen = *optarg;
}
else if ( i > 108 )
{
if ( i == 118 )
++verbosity;
}
else if ( i == 63 )
{
display_usage();
}
else if ( i == 100 )
{
dev = optarg;
}
}
if ( optind >= argc )
{
printf("Enter text to display: ");
fgets(&text, 100, stdin);
}
else
{
strcpy(&text, argv[optind]);
}
v3 = strlen(&text);
v4 = displaylen;
if ( v3 < displaylen )
{
if ( displaylen > (int)v3 )
{
v3 = (int)v3;
do
*(&text + v3++) = 32;
while ( v4 > (int)v3 );
}
*(&text + v4 + 1) = 0;
}
if ( verbosity )
{
v6 = strlen(&text);
printf("The text is: %s Length: %lu\n", &text, v6);
}
fd = setupport(dev);
result = initport(fd);
if ( verbosity )
{
v7 = getbaud(fd);
result = printf("baud=%d\n", v7);
}
return result;
}

original_code:
void startup(int argc, char **argv) {
int opt=0;
int longIndex=0;
 int i;
verbosity=0;
displaylen=16;
dev="/dev/ttyUSB0";
  opt = getopt_long( argc, argv, optString, longOpts, &longIndex);
  while (opt != -1) {
    switch ( opt ) {
    case 'd':
      dev = optarg;
      break;
    case 'l':
      displaylen = *optarg;
      break;
    case 'v':
      verbosity++;
      break;
    case '?':
      display_usage();
      break;
    };
    opt = getopt_long( argc, argv, optString, longOpts, &longIndex);
  }
  if (optind < argc) {
    strcpy(text, argv[optind]);
  } else {
    printf("Enter text to display: ");
    fgets(text, sizeof(text), stdin);
  }
  if (strlen(text) < displaylen) {
    for (i = strlen(text); i < displaylen; i++) {
      text[i] = ' ';
    }
    text[displaylen + 1] = '\0';
  }
  if (verbosity) {
    printf("The text is: %s Length: %lu\n",text,strlen(text));
  }
  fd = setupport(dev);
  initport(fd);
  if (verbosity) {
    printf("baud=%d\n", getbaud(fd));
  }
}

canonical_original_code:
void startup(int argc, char **argv) {
int opt = 0;
int longIndex = 0;
 int i;
verbosity=0;
displaylen=16;
dev="/dev/ttyUSB0";
  opt = getopt_long( argc, argv, optString, longOpts, &longIndex);
  while (opt != -1) {
    switch ( opt ) {
    case 'd':
      dev = optarg;
      break;
    case 'l':
      displaylen = *optarg;
      break;
    case 'v':
      verbosity++;
      break;
    case '?':
      display_usage();
      break;
    };
    opt = getopt_long( argc, argv, optString, longOpts, &longIndex);
  }
  if (optind < argc) {
    strcpy(text, argv[optind]);
  } else {
    printf("Enter text to display: ");
    fgets(text, sizeof(text), stdin);
  }
  if (strlen(text) < displaylen) {
    for (i = strlen(text); i < displaylen; i++) {
      text[i] = ' ';
    }
    text[displaylen + 1] = '\0';
  }
  if (verbosity) {
    printf("The text is: %s Length: %lu\n",text,strlen(text));
  }
  fd = setupport(dev);
  initport(fd);
  if (verbosity) {
    printf("baud=%d\n", getbaud(fd));
  }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: opt int

variable_types: longIndex int

variable_types: i int


msleep

decompiled_code:
__int64 __fastcall msleep(unsigned __int64 a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec v3; // [rsp+10h] [rbp-18h] BYREF

v2.tv_sec = 0LL;
v2.tv_nsec = 0LL;
v3.tv_sec = (int)(a1 / 0x3E8);
v3.tv_nsec = 1000000 * (a1 - 1000 * v3.tv_sec);
_nsleep(&v3, &v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int64 a1)
{
struct timespec v2; // [rsp+0h] [rbp-28h] BYREF
struct timespec v3; // [rsp+10h] [rbp-18h] BYREF

v2.tv_sec = 0LL;
v2.tv_nsec = 0LL;
v3.tv_sec = (int)(a1 / 0x3E8);
v3.tv_nsec = 1000000 * (a1 - 1000 * v3.tv_sec);
func1(&v3, &v2);
return 1LL;
}

original_code:
int msleep(unsigned long milisec)
{
  struct timespec req={0},rem={0};
  time_t sec=(int)(milisec/1000);
  milisec=milisec-(sec*1000);
  req.tv_sec=sec;
  req.tv_nsec=milisec*1000000L;
  __nsleep(&req,&rem);
  return 1;
}

canonical_original_code:
int msleep(unsigned long milisec)
{
  struct timespec req = {0}; struct timespec rem = {0};
  long sec = (int)(milisec/1000);
  milisec=milisec-(sec*1000);
  req.tv_sec=sec;
  req.tv_nsec=milisec*1000000L;
  __nsleep(&req,&rem);
  return 1;
}

variable_types:
milisec
unsigned long

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

variable_types: sec long


getbaud

decompiled_code:
__int64 __fastcall getbaud(int a1)
{
speed_t v1; // eax
char v2; // cf
bool v3; // zf
__int64 result; // rax
struct termios v5; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(a1, &v5);
v1 = cfgetispeed(&v5);
if ( !(v2 | v3) )
return 0xFFFFFFFFLL;
switch ( v1 )
{
case 0u:
result = 0LL;
break;
case 1u:
result = 50LL;
break;
case 2u:
return 0xFFFFFFFFLL;
case 3u:
result = 110LL;
break;
case 4u:
result = 134LL;
break;
case 5u:
result = 150LL;
break;
case 6u:
result = 200LL;
break;
case 7u:
result = 300LL;
break;
case 8u:
result = 600LL;
break;
case 9u:
result = 1200LL;
break;
case 0xAu:
result = 1800LL;
break;
case 0xBu:
result = 2400LL;
break;
case 0xCu:
result = 4800LL;
break;
case 0xDu:
result = 9600LL;
break;
case 0xEu:
result = 19200LL;
break;
case 0xFu:
result = 38400LL;
break;
default:
v3 = v1 == 4098;
result = 0xFFFFFFFFLL;
if ( v3 )
result = 115200LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
speed_t v1; // eax
char v2; // cf
bool v3; // zf
__int64 result; // rax
struct termios v5; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(a1, &v5);
v1 = cfgetispeed(&v5);
if ( !(v2 | v3) )
return 0xFFFFFFFFLL;
switch ( v1 )
{
case 0u:
result = 0LL;
break;
case 1u:
result = 50LL;
break;
case 2u:
return 0xFFFFFFFFLL;
case 3u:
result = 110LL;
break;
case 4u:
result = 134LL;
break;
case 5u:
result = 150LL;
break;
case 6u:
result = 200LL;
break;
case 7u:
result = 300LL;
break;
case 8u:
result = 600LL;
break;
case 9u:
result = 1200LL;
break;
case 0xAu:
result = 1800LL;
break;
case 0xBu:
result = 2400LL;
break;
case 0xCu:
result = 4800LL;
break;
case 0xDu:
result = 9600LL;
break;
case 0xEu:
result = 19200LL;
break;
case 0xFu:
result = 38400LL;
break;
default:
v3 = v1 == 4098;
result = 0xFFFFFFFFLL;
if ( v3 )
result = 115200LL;
break;
}
return result;
}

original_code:
int getbaud(int fd) {
  struct termios termAttr;
  int inputSpeed = -1;
  speed_t baudRate;
  tcgetattr(fd, &termAttr);
  baudRate = cfgetispeed(&termAttr);
  switch (baudRate) {
  case 0000000: inputSpeed = 0; break;
  case 0000001: inputSpeed = 50; break;
  case 0000003: inputSpeed = 110; break;
  case 0000004: inputSpeed = 134; break;
  case 0000005: inputSpeed = 150; break;
  case 0000006: inputSpeed = 200; break;
  case 0000007: inputSpeed = 300; break;
  case 0000010: inputSpeed = 600; break;
  case 0000011: inputSpeed = 1200; break;
  case 0000012: inputSpeed = 1800; break;
  case 0000013: inputSpeed = 2400; break;
  case 0000014: inputSpeed = 4800; break;
  case 0000015: inputSpeed = 9600; break;
  case 0000016: inputSpeed = 19200; break;
  case 0000017: inputSpeed = 38400; break;
  case 0010002: inputSpeed = 115200; break;
  }
  return inputSpeed;
}

canonical_original_code:
int getbaud(int fd) {
  struct termios termAttr;
  int inputSpeed = -1;
  unsigned int baudRate;
  tcgetattr(fd, &termAttr);
  baudRate = cfgetispeed(&termAttr);
  switch (baudRate) {
  case 0000000: inputSpeed = 0; break;
  case 0000001: inputSpeed = 50; break;
  case 0000003: inputSpeed = 110; break;
  case 0000004: inputSpeed = 134; break;
  case 0000005: inputSpeed = 150; break;
  case 0000006: inputSpeed = 200; break;
  case 0000007: inputSpeed = 300; break;
  case 0000010: inputSpeed = 600; break;
  case 0000011: inputSpeed = 1200; break;
  case 0000012: inputSpeed = 1800; break;
  case 0000013: inputSpeed = 2400; break;
  case 0000014: inputSpeed = 4800; break;
  case 0000015: inputSpeed = 9600; break;
  case 0000016: inputSpeed = 19200; break;
  case 0000017: inputSpeed = 38400; break;
  case 0010002: inputSpeed = 115200; break;
  }
  return inputSpeed;
}

variable_types: fd int

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

variable_types: inputSpeed int

variable_types:
baudRate
unsigned int


readport

decompiled_code:
__int64 __fastcall readport(int a1, char *a2)
{
int v2; // ebp
__int64 result; // rax
unsigned __int8 *v4; // rbx
int *v5; // rbx
char *v6; // rax

v2 = read(a1, a2, 0xFEuLL);
if ( verbosity )
{
printf("result[] = ");
if ( v2 > 0 )
{
v4 = (unsigned __int8 *)a2;
do
printf("%d,", *v4++);
while ( v4 != (unsigned __int8 *)&a2[v2 - 1 + 1] );
}
putchar(10);
}
result = 1LL;
if ( v2 < 0 )
{
v5 = _errno_location();
if ( *v5 == 11 )
{
puts("SERIAL EAGAIN ERROR");
}
else
{
v6 = strerror(*v5);
printf("SERIAL read error %d %s\n", (unsigned int)*v5, v6);
}
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, char *a2)
{
int v2; // ebp
__int64 result; // rax
unsigned __int8 *v4; // rbx
int *v5; // rbx
char *v6; // rax

v2 = read(a1, a2, 0xFEuLL);
if ( verbosity )
{
printf("result[] = ");
if ( v2 > 0 )
{
v4 = (unsigned __int8 *)a2;
do
printf("%d,", *v4++);
while ( v4 != (unsigned __int8 *)&a2[v2 - 1 + 1] );
}
putchar(10);
}
result = 1LL;
if ( v2 < 0 )
{
v5 = _errno_location();
if ( *v5 == 11 )
{
puts("SERIAL EAGAIN ERROR");
}
else
{
v6 = strerror(*v5);
printf("SERIAL read error %d %s\n", (unsigned int)*v5, v6);
}
result = 0LL;
}
return result;
}

original_code:
int readport(int fd, unsigned char *result) {
  int iIn = read(fd, result, 254);
  int counter = 0;
  if (verbosity) {
  printf("result[] = ");
  while(counter < iIn) {
    printf("%d,",result[counter]);
    counter++;
  }
  printf("\n");
  }
  if (iIn < 0) {
    if ((*__errno_location ()) == 11) {
      printf("SERIAL EAGAIN ERROR\n");
      return 0;
    } else {
      printf("SERIAL read error %d %s\n", (*__errno_location ()), strerror((*__errno_location ())));
      return 0;
    }
  }
  return 1;
}

variable_types:
result
unsigned char *

variable_types: iIn int

variable_types: counter int


writeport

decompiled_code:
__int64 __fastcall writeport(int fd, void *buf, int a3)
{
int v4; // edx
__int64 result; // rax
unsigned __int8 *v6; // rbx

if ( verbosity > 1 )
{
printf("write array = ");
if ( a3 > 0 )
{
v6 = (unsigned __int8 *)buf;
do
printf("%d,", *v6++);
while ( v6 != (unsigned __int8 *)((char *)buf + (unsigned int)(a3 - 1) + 1) );
}
putchar(10);
}
v4 = write(fd, buf, a3);
result = 1LL;
if ( v4 < 0 )
{
fwrite("write failed!\n", 1uLL, 0xEuLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, int a3)
{
int v4; // edx
__int64 result; // rax
unsigned __int8 *v6; // rbx

if ( verbosity > 1 )
{
printf("write array = ");
if ( a3 > 0 )
{
v6 = (unsigned __int8 *)buf;
do
printf("%d,", *v6++);
while ( v6 != (unsigned __int8 *)((char *)buf + (unsigned int)(a3 - 1) + 1) );
}
putchar(10);
}
v4 = write(fd, buf, a3);
result = 1LL;
if ( v4 < 0 )
{
fwrite("write failed!\n", 1uLL, 0xEuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int writeport(int fd, unsigned char *chars, int numBytes) {
  int counter = 0;
  if (verbosity>1) {
 printf("write array = ");
  while(counter < numBytes) {
    printf("%d,", chars[counter]);
    counter++;
  }
  printf("\n");
  }
  int n = write(fd, chars, numBytes);
  if (n < 0) {
    fputs("write failed!\n", stderr);
    return 0;
  }
  return 1;
}

variable_types:
chars
unsigned char *

variable_types: numBytes int

variable_types: n int


initport

decompiled_code:
__int64 __fastcall initport(int fd)
{
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(fd, &v2);
cfsetispeed(&v2, 0xDu);
cfsetospeed(&v2, 0xDu);
v2.c_cflag = v2.c_cflag & 0xFFFFFE8F | 0x8B0;
tcsetattr(fd, 0, &v2);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd)
{
struct termios v2; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(fd, &v2);
cfsetispeed(&v2, 0xDu);
cfsetospeed(&v2, 0xDu);
v2.c_cflag = v2.c_cflag & 0xFFFFFE8F | 0x8B0;
tcsetattr(fd, 0, &v2);
return 1LL;
}

original_code:
int initport(int fd) {
  struct termios options;
  tcgetattr(fd, &options);
  cfsetispeed(&options, 0000015);
  cfsetospeed(&options, 0000015);
  options.c_cflag |= (0004000 | 0000200);
  options.c_cflag &= ~0000400;
  options.c_cflag &= ~0000100;
  options.c_cflag &= ~0000060;
  options.c_cflag |= 0000060;
  tcsetattr(fd, 0, &options);
  return 1;
}

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


setupport

decompiled_code:
__int64 __fastcall setupport(const char *a1)
{
int v1; // eax
unsigned int v2; // ebx
unsigned int v4; // eax

v1 = open(a1, 2306);
if ( v1 == -1 )
{
perror("open_port: Unable to open dev - ");
v2 = 1;
}
else
{
v2 = v1;
fcntl(v1, 4, 0LL);
if ( verbosity )
{
v4 = getbaud(v2);
printf("baud=%d\n", v4);
}
}
return v2;
}

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

v1 = open(a1, 2306);
if ( v1 == -1 )
{
perror("open_port: Unable to open dev - ");
v2 = 1;
}
else
{
v2 = v1;
fcntl(v1, 4, 0LL);
if ( verbosity )
{
v4 = func0(v2);
printf("baud=%d\n", v4);
}
}
return v2;
}

original_code:
int setupport(char *fdpath){
  int fd = open(fdpath, 02 | 0400 | 04000);
  if (fd == -1) {
    perror("open_port: Unable to open dev - ");
    return 1;
  } else {
    fcntl(fd, 4, 0);
  }
  if (verbosity) {
  printf("baud=%d\n", getbaud(fd));
  }
  return fd;
}

variable_types:
fdpath
char *


decompiled_code:
int display_usage()
{
puts("LED Scroll - Scrolls a message a sinlge time across a message board");
puts("Options:");
puts(" -d, --dev Path to the USB dev for the board, default: /dev/ttyUSB0");
puts(" -l, --displaylen The number of charecters in the display, default: 16");
puts(" -v, --verbose Will print out lots of info, default: off");
return puts(" -vv Extra bonus info");
}

canonical_decompiled_code:
int func0()
{
puts("LED Scroll - Scrolls a message a sinlge time across a message board");
puts("Options:");
puts(" -d, --dev Path to the USB dev for the board, default: /dev/ttyUSB0");
puts(" -l, --displaylen The number of charecters in the display, default: 16");
puts(" -v, --verbose Will print out lots of info, default: off");
return puts(" -vv Extra bonus info");
}

original_code:
void display_usage( void ) {
  puts( "LED Scroll - Scrolls a message a sinlge time across a message board");
  puts( "Options:" );
  puts( " -d, --dev         Path to the USB dev for the board, default: /dev/ttyUSB0" );
  puts( " -l, --displaylen  The number of charecters in the display, default: 16");
  puts( " -v, --verbose     Will print out lots of info, default: off");
  puts( " -vv               Extra bonus info");
}

canonical_original_code:
void display_usage() {
  puts( "LED Scroll - Scrolls a message a sinlge time across a message board");
  puts( "Options:" );
  puts( " -d, --dev         Path to the USB dev for the board, default: /dev/ttyUSB0" );
  puts( " -l, --displaylen  The number of charecters in the display, default: 16");
  puts( " -v, --verbose     Will print out lots of info, default: off");
  puts( " -vv               Extra bonus info");
}


repo: robryk/curtain

decompiled_code:
unsigned int __fastcall lock_input(Window a1)
{
unsigned int v1; // eax
unsigned int result; // eax

v1 = XGrabKeyboard(display, a1, 1, 1, 1, 0LL);
if ( v1 )
{
fprintf(stderr, "XGrabKeyboard failed: %d\n", v1);
exit(1);
}
result = XGrabPointer(display, a1, 1, 0, 1, 1, a1, 0LL, 0LL);
if ( result )
{
fprintf(stderr, "XGrabPointer failed: %d\n", result);
exit(1);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func1(Window a1)
{
unsigned int v1; // eax
unsigned int result; // eax

v1 = XGrabKeyboard(display, a1, 1, 1, 1, 0LL);
if ( v1 )
{
fprintf(stderr, "XGrabKeyboard failed: %d\n", v1);
exit(1);
}
result = XGrabPointer(display, a1, 1, 0, 1, 1, a1, 0LL, 0LL);
if ( result )
{
fprintf(stderr, "XGrabPointer failed: %d\n", result);
exit(1);
}
return result;
}

original_code:
void lock_input(Window lock_to) {
 int err = XGrabKeyboard(
  display,
  lock_to,
  1,
  1,
  1,
  0L);
 if (err != 0) {
  fprintf(stderr, "XGrabKeyboard failed: %d\n", err);
  exit(1);
 }
 err = XGrabPointer(
  display,
  lock_to,
  1,
  0,
  1,
  1,
  lock_to,
  0L,
  0L);
 if (err != 0) {
  fprintf(stderr, "XGrabPointer failed: %d\n", err);
  exit(1);
 }
}

canonical_original_code:
void lock_input(unsigned long lock_to) {
 int err = XGrabKeyboard(
  display,
  lock_to,
  1,
  1,
  1,
  0L);
 if (err != 0) {
  fprintf(stderr, "XGrabKeyboard failed: %d\n", err);
  exit(1);
 }
 err = XGrabPointer(
  display,
  lock_to,
  1,
  0,
  1,
  1,
  lock_to,
  0L,
  0L);
 if (err != 0) {
  fprintf(stderr, "XGrabPointer failed: %d\n", err);
  exit(1);
 }
}

variable_types: err int


repo: rochus/floerr

decompiled_code:
void __fastcall free_flow(void *ptr)
{
if ( ptr )
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
if ( ptr )
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
void
free_flow(FLOfile *f)
{
 if (f) free(f->data);
 free(f);
}

canonical_original_code:
void free_flow(struct FLOfile *f)
{
 if (f) free(f->data);
 free(f);
}

variable_types: struct FLOfile { int w; enum FLOformat { FF_FLO=0, FF_FLOW=1, FF_LAST=2 } fmt; int nmemb; float *data; } *

user_defined_types: struct FLOfile { int w; enum FLOformat fmt; int nmemb; float *data; }


strdup

decompiled_code:
char *__fastcall strdup(char *src)
{
int v1; // eax
char *v2; // rax
char *v3; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

canonical_decompiled_code:
char *__fastcall func11(char *src)
{
int v1; // eax
char *v2; // rax
char *v3; // rbx

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
strcpy(v2, src);
return v3;
}

original_code:
char*
strdup(const char *str)
{
 int n = strlen(str) + 1;
 char *dup = malloc(n);
 if (dup) strcpy(dup, str);
 return dup;
}

canonical_original_code:
char *strdup(char *str)
{
 int n = strlen(str) + 1;
 char *dup = malloc(n);
 if (dup) strcpy(dup, str);
 return dup;
}

variable_types:
str
char *

variable_types:
dup
char *

return_type: char *


decompiled_code:
__int64 __fastcall test_file(char *a1)
{
int v1; // edx
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3);
result = 1LL;
if ( v1 )
{
fprintf(stderr, "Error: File '%s' does not exist.\n", a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1)
{
int v1; // edx
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = func17(a1, &v3);
result = 1LL;
if ( v1 )
{
fprintf(stderr, "Error: File '%s' does not exist.\n", a1);
result = 0LL;
}
return result;
}

original_code:
_Bool
test_file(char *f)
{
 struct stat sb;
 if (stat(f, &sb)) {
  fprintf(stderr, "Error: File '%s' does not exist.\n", f);
  return 0;
 }
 return 1;
}

variable_types:
f
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rax
char v5; // dl
int result; // eax
char v7; // dl

v3 = strdup((char *)*argv);
v4 = __xpg_basename(v3);
if ( argc <= 3 )
{
usage(stderr, v4);
result = 1;
}
else
{
v5 = test_file((char *)argv[1]);
result = 1;
if ( v5 )
{
v7 = test_file((char *)argv[2]);
result = 1;
if ( v7 )
{
cmp(argv[1], argv[2], argv[3]);
result = 0;
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rax
char v5; // dl
int result; // eax
char v7; // dl

v3 = func11((char *)*argv);
v4 = __xpg_basename(v3);
if ( argc <= 3 )
{
func12(stderr, v4);
result = 1;
}
else
{
v5 = func13((char *)argv[1]);
result = 1;
if ( v5 )
{
v7 = func13((char *)argv[2]);
result = 1;
if ( v7 )
{
func14(argv[1], argv[2], argv[3]);
result = 0;
}
}
}
return result;
}

original_code:
int
main(int argc, char *argv[])
{
 char *pname = strdup(argv[0]);
 pname = __xpg_basename(pname);
 if (argc < 4) {
  usage(stderr, pname);
  return 1;
 }
 if (!test_file(argv[1]) || !test_file(argv[2]))
  return 1;
 cmp(argv[1], argv[2], argv[3]);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
pname
char *