drawposquad

decompiled_code:
__int64 __fastcall drawposquad(float a1, float a2, float a3, double a4)
{
double v4; // xmm5_8
double v5; // xmm4_8
double v6; // xmm3_8
float v8; // [rsp+14h] [rbp-14h]

v8 = *(float *)&a4;
glBegin(7LL);
glTexCoord2f(0.0);
*(_QWORD *)&a4 = LODWORD(a4);
*(_QWORD *)&v4 = LODWORD(a3);
*(float *)&a4 = *(float *)&a4 - a2;
*(float *)&v4 = a3 - a1;
glVertex3f(v4, a4, -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
*(_QWORD *)&v5 = LODWORD(a3);
*(float *)&v5 = a3 + a1;
glVertex3f(v5, COERCE_DOUBLE((unsigned __int64)LODWORD(a4)), -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
*(_QWORD *)&v6 = LODWORD(v8);
*(float *)&v6 = v8 + a2;
glVertex3f(COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT(a3 + a1)), v6, -0.5);
glTexCoord2f(0.0);
glVertex3f(
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT(a3 - a1)),
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT(v8 + a2)),
-0.5);
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func5(float a1, float a2, float a3, double a4)
{
double v4; // xmm5_8
double v5; // xmm4_8
double v6; // xmm3_8
float v8; // [rsp+14h] [rbp-14h]

v8 = *(float *)&a4;
glBegin(7LL);
glTexCoord2f(0.0);
*(_QWORD *)&a4 = LODWORD(a4);
*(_QWORD *)&v4 = LODWORD(a3);
*(float *)&a4 = *(float *)&a4 - a2;
*(float *)&v4 = a3 - a1;
glVertex3f(v4, a4, -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
*(_QWORD *)&v5 = LODWORD(a3);
*(float *)&v5 = a3 + a1;
glVertex3f(v5, COERCE_DOUBLE((unsigned __int64)LODWORD(a4)), -0.5);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC10));
*(_QWORD *)&v6 = LODWORD(v8);
*(float *)&v6 = v8 + a2;
glVertex3f(COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT(a3 + a1)), v6, -0.5);
glTexCoord2f(0.0);
glVertex3f(
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT(a3 - a1)),
COERCE_DOUBLE((unsigned __int64)COERCE_UNSIGNED_INT(v8 + a2)),
-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);
}

return_type: void


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, COERCE_DOUBLE((unsigned __int64)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, COERCE_DOUBLE((unsigned __int64)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, &v2, &v5);
glGenTextures(1LL, &v4);
glBindTexture(3553LL, v4);
glTexImage2D(3553LL, 0LL, 6407LL, v2, v3, 0LL, 32992LL, 5121LL, v5);
glTexParameteri(3553LL, 10241LL, 9728LL);
glTexParameteri(3553LL, 10240LL, 9728LL);
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
glBindTexture(3553LL, v4);
_glewUseProgram(0LL);
drawsmallquad((float)(int)v2 / (float)playwidth, (float)(int)v3 / (float)playheight);
glDeleteTextures(1LL, &v4);
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, &v2, &v5);
glGenTextures(1LL, &v4);
glBindTexture(3553LL, v4);
glTexImage2D(3553LL, 0LL, 6407LL, v2, v3, 0LL, 32992LL, 5121LL, v5);
glTexParameteri(3553LL, 10241LL, 9728LL);
glTexParameteri(3553LL, 10240LL, 9728LL);
_glewBindFramebuffer(36160LL, (unsigned int)fbid2);
glBindTexture(3553LL, v4);
_glewUseProgram(0LL);
func4((float)(int)v2 / (float)playwidth, (float)(int)v3 / (float)playheight);
glDeleteTextures(1LL, &v4);
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

return_type: int


glRender

decompiled_code:
__int64 glRender()
{
int v0; // eax
__int64 result; // rax

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);
v0 = 1;
}
else
{
v0 = count + 1;
}
count = v0;
result = 1LL;
which = which == 0;
return result;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // eax
__int64 result; // rax

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);
v0 = 1;
}
else
{
v0 = count + 1;
}
count = v0;
result = 1LL;
which = which == 0;
return result;
}

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
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
unsigned int v8; // er8
const char *v10; // 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;
screenHeight = a2;
screenWidth = v4;
v5 = SDL_SetVideoMode(v4, a2, (unsigned int)screenBPP, (unsigned int)videoFlags);
v8 = 1;
surface = v5;
if ( !v5 )
{
v10 = (const char *)SDL_GetError(v4, a2, v6, v7, 1LL);
fprintf(stderr, "ERROR -- SDL video resize failed: %s \n", v10);
v8 = 0;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, __int64 a2, unsigned int a3)
{
__int64 v4; // rdi
__int64 v5; // rax
__int64 v6; // rdx
__int64 v7; // rcx
unsigned int v8; // er8
const char *v10; // 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;
screenHeight = a2;
screenWidth = v4;
v5 = SDL_SetVideoMode(v4, a2, (unsigned int)screenBPP, (unsigned int)videoFlags);
v8 = 1;
surface = v5;
if ( !v5 )
{
v10 = (const char *)SDL_GetError(v4, a2, v6, v7, 1LL);
fprintf(stderr, "ERROR -- SDL video resize failed: %s \n", v10);
v8 = 0;
}
return v8;
}

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
__int64 v5; // rcx
__int64 v6; // r8
int v7; // eax
const char *v9; // rax

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

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

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

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
float v3; // xmm0_4
double v4; // xmm1_8
int v5; // xmm0_4
double v6; // xmm1_8
int v7; // xmm0_4
__int64 v8; // rsi
double v9; // xmm1_8
__int64 v10; // xmm2_8
double v11; // xmm0_8
int v12; // xmm0_4

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

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

result = *(_DWORD *)(a1 + 4);
if ( result > 0x77 )
{
if ( result == 275 )
{
skip = (int)((double)(skip + 1) * 10.0 - 1.0);
return printf("frameskip: %i\n", (unsigned int)skip);
}
if ( result <= 0x113 )
{
if ( result == 273 )
{
v3 = *(float *)&zoom + *(float *)&zoom;
}
else
{
if ( result != 274 )
return result;
v3 = 0.5 * *(float *)&zoom;
}
zoom = LODWORD(v3);
printf("zoom: %f\n", v3);
LABEL_18:
glDrawScreen(1LL);
result = glDrawScreen(1LL);
}
else if ( result == 276 )
{
v2 = (unsigned int)(int)((double)(skip + 1) / 10.0 - 1.0);
if ( (int)v2 < 0 )
{
skip = 0;
v2 = 0LL;
}
else
{
skip = (int)((double)(skip + 1) / 10.0 - 1.0);
}
result = printf("frameskip: %i\n", v2);
}
}
else
{
if ( result > 0x5A )
{
result -= 91;
switch ( result )
{
case 0u:
v8 = (unsigned int)(int)((double)slowness * 0.5);
if ( (int)v8 <= 0 )
{
slowness = 1;
v8 = 1LL;
}
else
{
slowness = (int)((double)slowness * 0.5);
}
return printf("slowness: %i\n", v8);
case 2u:
slowness = (int)((double)slowness + (double)slowness);
return printf("slowness: %i\n", (unsigned int)slowness);
case 6u:
v9 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v9);
else
v9 = sqrt(v9);
v10 = LC8;
v11 = *(float *)&viewposx;
goto LABEL_32;
case 9u:
v9 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v9);
else
v9 = sqrt(v9);
v10 = LC14;
v11 = *(float *)&viewposx;
LABEL_32:
*(float *)&v12 = v11 + *(double *)&v10 / v9;
viewposx = v12;
goto LABEL_18;
case 0x17u:
zoom = 1065353216;
printf("zoom: %f\n", *(double *)&LC5);
viewposx = 0;
viewposy = 0;
goto LABEL_18;
case 0x18u:
v4 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v4);
else
v4 = sqrt(v4);
*(float *)&v5 = *(float *)&viewposy + 0.5 / v4;
viewposy = v5;
goto LABEL_18;
case 0x1Cu:
v6 = *(float *)&zoom;
if ( *(float *)&zoom < 0.0 )
sqrt(v6);
else
v6 = sqrt(v6);
*(float *)&v7 = *(float *)&viewposy + -0.5 / v6;
viewposy = v7;
goto LABEL_18;
default:
return result;
}
}
if ( result == 27 )
{
SDL_Quit();
exit(1);
}
if ( result == 32 )
{
result = active == 0;
active = 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; // ebx
int result; // eax
unsigned int v6; // eax
size_t v7; // rax
int longind[7]; // [rsp+Ch] [rbp-1Ch] BYREF

verbosity = 0;
longind[0] = 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 )
memset(&text + (int)v3, 32, (unsigned int)(displaylen - 1 - v3) + 1LL);
*(&text + v4 + 1) = 0;
}
if ( verbosity )
{
v7 = strlen(&text);
printf("The text is: %s Length: %lu\n", &text, v7);
}
fd = setupport(dev);
initport(fd);
result = verbosity;
if ( verbosity )
{
v6 = getbaud(fd);
result = printf("baud=%d\n", v6);
}
return result;
}

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

verbosity = 0;
longind[0] = 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 )
memset(&text + (int)v3, 32, (unsigned int)(displaylen - 1 - v3) + 1LL);
*(&text + v4 + 1) = 0;
}
if ( verbosity )
{
v7 = strlen(&text);
printf("The text is: %s Length: %lu\n", &text, v7);
}
fd = setupport(dev);
initport(fd);
result = verbosity;
if ( verbosity )
{
v6 = getbaud(fd);
result = printf("baud=%d\n", v6);
}
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

v3 = 0LL;
v2.tv_sec = (int)(a1 / 0x3E8);
v2.tv_nsec = 1000000 * (a1 - 1000 * v2.tv_sec);
_nsleep(&v2, &v3);
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

v3 = 0LL;
v2.tv_sec = (int)(a1 / 0x3E8);
v2.tv_nsec = 1000000 * (a1 - 1000 * v2.tv_sec);
func1(&v2, &v3);
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
bool v2; // zf
__int64 result; // rax
struct termios v4; // [rsp+0h] [rbp-48h] BYREF

tcgetattr(a1, &v4);
v1 = cfgetispeed(&v4);
switch ( v1 )
{
case 0u:
result = 0LL;
break;
case 1u:
result = 50LL;
break;
case 2u:
result = 0xFFFFFFFFLL;
break;
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:
v2 = v1 == 4098;
result = 0xFFFFFFFFLL;
if ( v2 )
result = 115200LL;
break;
}
return result;
}

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

tcgetattr(a1, &v4);
v1 = cfgetispeed(&v4);
switch ( v1 )
{
case 0u:
result = 0LL;
break;
case 1u:
result = 50LL;
break;
case 2u:
result = 0xFFFFFFFFLL;
break;
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:
v2 = v1 == 4098;
result = 0xFFFFFFFFLL;
if ( v2 )
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, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbx
int v3; // ebp
__int64 result; // rax
int *v5; // rax
unsigned int *v6; // rbx
char *v7; // rax
__int64 v8; // r12
__int64 v9; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func1(int a1, unsigned __int8 *a2)
{
unsigned __int8 *v2; // rbx
int v3; // ebp
__int64 result; // rax
int *v5; // rax
unsigned int *v6; // rbx
char *v7; // rax
__int64 v8; // r12
__int64 v9; // rsi

v2 = a2;
v3 = read(a1, a2, 0xFEuLL);
if ( verbosity )
{
printf("result[] = ");
if ( v3 > 0 )
{
v8 = (__int64)&a2[v3 - 1 + 1];
do
{
v9 = *v2++;
printf("%d,", v9);
}
while ( v2 != (unsigned __int8 *)v8 );
}
putchar(10);
}
result = 1LL;
if ( v3 < 0 )
{
v5 = _errno_location();
v6 = (unsigned int *)v5;
if ( *v5 == 11 )
{
puts("SERIAL EAGAIN ERROR");
}
else
{
v7 = strerror(*v5);
printf("SERIAL read error %d %s\n", *v6, v7);
}
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)
{
void *v3; // r12
int v5; // er8
__int64 result; // rax
char *v7; // rbx
char *v8; // r14
__int64 v9; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf, int a3)
{
void *v3; // r12
int v5; // er8
__int64 result; // rax
char *v7; // rbx
char *v8; // r14
__int64 v9; // rsi

v3 = buf;
if ( verbosity > 1 )
{
printf("write array = ");
if ( a3 > 0 )
{
v7 = (char *)buf;
v8 = (char *)buf + (unsigned int)(a3 - 1) + 1;
do
{
v9 = (unsigned __int8)*v7++;
printf("%d,", v9);
}
while ( v7 != v8 );
}
putchar(10);
}
v5 = write(fd, v3, a3);
result = 1LL;
if ( v5 < 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; // er12
__int64 result; // rax
unsigned int v4; // eax

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

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

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

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);
goto LABEL_5;
}
result = XGrabPointer(display, a1, 1, 0, 1, 1, a1, 0LL, 0LL);
if ( result )
{
fprintf(stderr, "XGrabPointer failed: %d\n", result);
LABEL_5:
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);
goto LABEL_5;
}
result = XGrabPointer(display, a1, 1, 0, 1, 1, a1, 0LL, 0LL);
if ( result )
{
fprintf(stderr, "XGrabPointer failed: %d\n", result);
LABEL_5:
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


main

canonical_name: main

repo: rochus/floerr

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

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

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

v3 = (char *)func10((void *)*argv);
v4 = __xpg_basename(v3);
if ( argc <= 3 )
{
func11(stderr, v4);
result = 1;
}
else if ( (unsigned __int8)func12(argv[1]) && (unsigned __int8)func12(argv[2]) )
{
func13(argv[1], argv[2], argv[3]);
result = 0;
}
else
{
result = 1;
}
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 *


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

canonical_decompiled_code:
void __fastcall func9(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:
void *__fastcall strdup(void *src)
{
size_t v1; // rbx
void *v2; // rax
void *v3; // r8

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

canonical_decompiled_code:
void *__fastcall func10(void *src)
{
size_t v1; // rbx
void *v2; // rax
void *v3; // r8

v1 = strlen((const char *)src);
v2 = malloc((int)v1 + 1);
v3 = v2;
if ( v2 )
v3 = memcpy(v2, src, v1 + 1);
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; // er8
__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 func12(char *a1)
{
int v1; // er8
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = func16(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]; }


center

decompiled_code:
int __fastcall center(const char *a1, const char *a2, int a3, char a4, const char *a5)
{
int v5; // er15
int v8; // er12
int v9; // er12
int v12; // [rsp+8h] [rbp-40h]

v5 = 0;
v12 = strlen(a2);
v8 = (int)((double)(a3 - v12 - 2) * 0.5);
printf("%s", a1);
if ( v8 > 0 )
{
do
{
++v5;
putchar(a4);
}
while ( v8 != v5 );
}
if ( *a2 )
printf(" %s ", a2);
else
printf("%c%c", (unsigned int)a4, (unsigned int)a4);
v9 = v8 + v12 + 2;
if ( a3 > v9 )
{
do
{
++v9;
putchar(a4);
}
while ( a3 != v9 );
}
return printf("%s", a5);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1, const char *a2, int a3, char a4, const char *a5)
{
int v5; // er15
int v8; // er12
int v9; // er12
int v12; // [rsp+8h] [rbp-40h]

v5 = 0;
v12 = strlen(a2);
v8 = (int)((double)(a3 - v12 - 2) * 0.5);
printf("%s", a1);
if ( v8 > 0 )
{
do
{
++v5;
putchar(a4);
}
while ( v8 != v5 );
}
if ( *a2 )
printf(" %s ", a2);
else
printf("%c%c", (unsigned int)a4, (unsigned int)a4);
v9 = v8 + v12 + 2;
if ( a3 > v9 )
{
do
{
++v9;
putchar(a4);
}
while ( a3 != v9 );
}
return printf("%s", a5);
}

original_code:
void center( char* begin, char* text, int col, char pad, char* end )
{
 int length = strlen(text);
 int i, j = 0.5 * ( col - length - 2 );
 printf("%s", begin);
 for ( i = 0; i < j; i++ ) printf("%c",pad);
 if ( *text != '\0' ) printf(" %s ", text);
 else printf("%c%c", pad, pad);
 j += 2 + length;
 for ( i = j; i < col; i++ ) printf("%c",pad);
 printf("%s", end);
}

canonical_original_code:
void center(char *begin, char *text, int col, char pad, char *end)
{
 int length = strlen(text);
 int i; int j = 0.5 * ( col - length - 2 );
 printf("%s", begin);
 for ( i = 0; i < j; i++ ) printf("%c",pad);
 if ( *text != '\0' ) printf(" %s ", text);
 else printf("%c%c", pad, pad);
 j += 2 + length;
 for ( i = j; i < col; i++ ) printf("%c",pad);
 printf("%s", end);
}

variable_types:
begin
char *

variable_types:
text
char *

variable_types: col int

variable_types: pad char

variable_types:
end
char *

variable_types: length int

variable_types: i int

variable_types: j int


eqcap

decompiled_code:
float __fastcall eqcap(int a1, int a2)
{
return (float)((float)a2 * *(float *)&MCC) / (float)a1;
}

canonical_decompiled_code:
float __fastcall func10(int a1, int a2)
{
return (float)((float)a2 * *(float *)&MCC) / (float)a1;
}

original_code:
float eqcap( int ser, int par )
{
 return par*MCC/ser;
}

canonical_original_code:
float eqcap(int ser, int par)
{
 return par*MCC/ser;
}

variable_types: ser int

variable_types: par int

return_type: float


timeNowUsec

repo: roevhat/matriC

decompiled_code:
__int64 timeNowUsec()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (unsigned int)(LODWORD(v1.tv_usec) + 1000000 * LODWORD(v1.tv_sec));
}

canonical_decompiled_code:
__int64 func0()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return (unsigned int)(LODWORD(v1.tv_usec) + 1000000 * LODWORD(v1.tv_sec));
}

original_code:
int timeNowUsec(){
    struct timeval now;
    gettimeofday(&now, ((void *)0));
    return (now.tv_sec) * 1000000 + (now.tv_usec);
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


timestampNow

decompiled_code:
unsigned __int64 timestampNow()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
sprintf(
s,
"%02i%02i%i%02i%02i%02i",
(unsigned int)v0->tm_mday,
(unsigned int)(v0->tm_mon + 1),
(unsigned int)(v0->tm_year + 1900),
(unsigned int)v0->tm_hour,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec);
return strtoul(s, 0LL, 10);
}

canonical_decompiled_code:
unsigned __int64 func1()
{
struct tm *v0; // rax
time_t timer; // [rsp+8h] [rbp-30h] BYREF
char s[40]; // [rsp+10h] [rbp-28h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
sprintf(
s,
"%02i%02i%i%02i%02i%02i",
(unsigned int)v0->tm_mday,
(unsigned int)(v0->tm_mon + 1),
(unsigned int)(v0->tm_year + 1900),
(unsigned int)v0->tm_hour,
(unsigned int)v0->tm_min,
(unsigned int)v0->tm_sec);
return strtoul(s, 0LL, 10);
}

original_code:
unsigned long timestampNow(){
    char timestamp[32];
    time_t currentTime;
    struct tm * ts;
    currentTime = time(((void *)0));
    ts = localtime(&currentTime);
    sprintf(timestamp,"%02i%02i%i%02i%02i%02i", ts->tm_mday, ts->tm_mon+1, ts->tm_year+1900, ts->tm_hour, ts->tm_min, ts->tm_sec);
    return strtoul(timestamp, ((void *)0), 10);
}

canonical_original_code:
unsigned long timestampNow(){
    char timestamp[32];
    long currentTime;
    struct tm *ts;
    currentTime = time(((void *)0));
    ts = localtime(&currentTime);
    sprintf(timestamp,"%02i%02i%i%02i%02i%02i", ts->tm_mday, ts->tm_mon+1, ts->tm_year+1900, ts->tm_hour, ts->tm_min, ts->tm_sec);
    return strtoul(timestamp, ((void *)0), 10);
}

variable_types:
timestamp
char [32]

variable_types: currentTime long

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

return_type: unsigned long


outputDet

decompiled_code:
__int64 __fastcall outputDet(unsigned int *a1, int a2, int a3)
{
int v4; // er12
float v5; // xmm0_4
unsigned int v6; // ebp
int v8; // er12
float v9; // [rsp+Ch] [rbp-1Ch]

if ( a2 )
{
printf("{INPUT(%ix%i)}\n", *a1, a1[1]);
putchar(10);
printMatrix(a1);
putchar(10);
v8 = timeNowUsec();
v9 = cofactorExpansion(a1, 1LL);
v6 = timeNowUsec() - v8;
puts("{DETERMINANT OF MATRIX}");
putchar(10);
v5 = v9;
}
else
{
v4 = timeNowUsec();
v5 = cofactorExpansion(a1, 1LL);
v6 = timeNowUsec() - v4;
}
printf("det(INPUT) = %f\n", v5);
if ( a3 )
{
putchar(10);
puts("{TIMER}");
printf("It took %i microseconds!\n", v6);
putchar(10);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1, int a2, int a3)
{
int v4; // er12
float v5; // xmm0_4
unsigned int v6; // ebp
int v8; // er12
float v9; // [rsp+Ch] [rbp-1Ch]

if ( a2 )
{
printf("{INPUT(%ix%i)}\n", *a1, a1[1]);
putchar(10);
printMatrix(a1);
putchar(10);
v8 = func0();
v9 = cofactorExpansion(a1, 1LL);
v6 = func0() - v8;
puts("{DETERMINANT OF MATRIX}");
putchar(10);
v5 = v9;
}
else
{
v4 = func0();
v5 = cofactorExpansion(a1, 1LL);
v6 = func0() - v4;
}
printf("det(INPUT) = %f\n", v5);
if ( a3 )
{
putchar(10);
puts("{TIMER}");
printf("It took %i microseconds!\n", v6);
putchar(10);
}
return 1LL;
}

original_code:
int outputDet(matrix * entity, int all, int timer){
    if (all){
        printf("{INPUT(%ix%i)}\n", entity->m, entity->n);
        printf("\n");
        printMatrix(entity);
        printf("\n");
    }
    int t1 = timeNowUsec();
    float det = cofactorExpansion(entity, 1);
    int t2 = timeNowUsec();
    int tDiff = t2-t1;
    if (all){
        printf("%s\n", "{DETERMINANT OF MATRIX}");
        printf("\n");
    }
    printf("det(INPUT) = %f\n", det);
    if (timer){
        printf("\n");
        printf("%s\n", "{TIMER}");
        printf("It took %i microseconds!\n", tDiff);
        printf("\n");
    }
    return 1;
}

canonical_original_code:
int outputDet(struct matrix *entity, int all, int timer){
    if (all){
        printf("{INPUT(%ix%i)}\n", entity->m, entity->n);
        printf("\n");
        printMatrix(entity);
        printf("\n");
    }
    int t1 = timeNowUsec();
    float det = cofactorExpansion(entity, 1);
    int t2 = timeNowUsec();
    int tDiff = t2-t1;
    if (all){
        printf("%s\n", "{DETERMINANT OF MATRIX}");
        printf("\n");
    }
    printf("det(INPUT) = %f\n", det);
    if (timer){
        printf("\n");
        printf("%s\n", "{TIMER}");
        printf("It took %i microseconds!\n", tDiff);
        printf("\n");
    }
    return 1;
}

variable_types: struct matrix { int m; int n; float matrix[100][100]; } *

variable_types: all int

variable_types: timer int

variable_types: det float

variable_types: tDiff int


outputRref

decompiled_code:
__int64 __fastcall outputRref(unsigned int *a1, int a2, int a3)
{
int v4; // er14
unsigned int v5; // er13
int v7; // er14
unsigned int v8; // er14
unsigned int v9; // eax
_BYTE v10[40016]; // [rsp+0h] [rbp-138C8h] BYREF
int v11[10014]; // [rsp+9C50h] [rbp-9C78h] BYREF

if ( a2 )
{
printf("{INPUT(%ix%i)}\n", *a1, a1[1]);
putchar(10);
printMatrix(a1);
putchar(10);
v7 = timeNowUsec();
if ( (unsigned int)toRowEchelonForm(v10, a1, 1LL) )
{
puts("{ROW ECHELON FORM}");
putchar(10);
printMatrix(v10);
putchar(10);
if ( (unsigned int)toReducedRowEchelonForm(v11, v10, 1LL) )
{
v5 = timeNowUsec() - v7;
puts("{REDUCED ROW ECHELON FORM}");
putchar(10);
printMatrix(v11);
putchar(10);
puts("{RANK AND NULLITY}");
v8 = matrixNullity(v11);
v9 = matrixRank(v11);
printf("Rank is %i and nullity is %i\n", v9, v8);
if ( !a3 )
goto LABEL_5;
goto LABEL_10;
}
}
}
else
{
v4 = timeNowUsec();
if ( (unsigned int)toRowEchelonForm(v10, a1, 0LL) && (unsigned int)toReducedRowEchelonForm(v11, v10, 0LL) )
{
v5 = timeNowUsec() - v4;
printMatrix(v11);
if ( !a3 )
{
LABEL_5:
logToJSON((int *)a1, v11, v5, "rref");
return 1LL;
}
LABEL_10:
putchar(10);
puts("{TIMER}");
printf("It took %i microseconds!\n", v5);
putchar(10);
goto LABEL_5;
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, int a2, int a3)
{
int v4; // er14
unsigned int v5; // er13
int v7; // er14
unsigned int v8; // er14
unsigned int v9; // eax
_BYTE v10[40016]; // [rsp+0h] [rbp-138C8h] BYREF
int v11[10014]; // [rsp+9C50h] [rbp-9C78h] BYREF

if ( a2 )
{
printf("{INPUT(%ix%i)}\n", *a1, a1[1]);
putchar(10);
printMatrix(a1);
putchar(10);
v7 = func0();
if ( (unsigned int)toRowEchelonForm(v10, a1, 1LL) )
{
puts("{ROW ECHELON FORM}");
putchar(10);
printMatrix(v10);
putchar(10);
if ( (unsigned int)toReducedRowEchelonForm(v11, v10, 1LL) )
{
v5 = func0() - v7;
puts("{REDUCED ROW ECHELON FORM}");
putchar(10);
printMatrix(v11);
putchar(10);
puts("{RANK AND NULLITY}");
v8 = matrixNullity(v11);
v9 = matrixRank(v11);
printf("Rank is %i and nullity is %i\n", v9, v8);
if ( !a3 )
goto LABEL_5;
goto LABEL_10;
}
}
}
else
{
v4 = func0();
if ( (unsigned int)toRowEchelonForm(v10, a1, 0LL) && (unsigned int)toReducedRowEchelonForm(v11, v10, 0LL) )
{
v5 = func0() - v4;
printMatrix(v11);
if ( !a3 )
{
LABEL_5:
func3((int *)a1, v11, v5, "rref");
return 1LL;
}
LABEL_10:
putchar(10);
puts("{TIMER}");
printf("It took %i microseconds!\n", v5);
putchar(10);
goto LABEL_5;
}
}
return 0LL;
}

original_code:
int outputRref(matrix * entity, int all, int timer){
    if (all){
        printf("{INPUT(%ix%i)}\n", entity->m, entity->n);
        printf("\n");
        printMatrix(entity);
        printf("\n");
    }
    int t1 = timeNowUsec();
    matrix rowEchelonForm;
    if (all){
        if(!toRowEchelonForm(&rowEchelonForm, entity, 1)){
            return 0;
        }
    } else {
        if(!toRowEchelonForm(&rowEchelonForm, entity, 0)){
            return 0;
        }
    }
    if (all){
        printf("%s\n", "{ROW ECHELON FORM}");
        printf("\n");
        printMatrix(&rowEchelonForm);
        printf("\n");
    }
    matrix reducedRowEchelonForm;
    if (all){
        if(!toReducedRowEchelonForm(&reducedRowEchelonForm, &rowEchelonForm, 1)){
            return 0;
        }
    } else {
        if(!toReducedRowEchelonForm(&reducedRowEchelonForm, &rowEchelonForm, 0)){
            return 0;
        }
    }
    int t2 = timeNowUsec();
    int tDiff = t2-t1;
    if (all){
        printf("%s\n", "{REDUCED ROW ECHELON FORM}");
        printf("\n");
    }
    printMatrix(&reducedRowEchelonForm);
    if (all){
        printf("\n");
        printf("%s\n", "{RANK AND NULLITY}");
        printf("Rank is %i and nullity is %i\n", matrixRank(&reducedRowEchelonForm), matrixNullity(&reducedRowEchelonForm));
    }
    if (timer){
        printf("\n");
        printf("%s\n", "{TIMER}");
        printf("It took %i microseconds!\n", tDiff);
        printf("\n");
    }
    logToJSON(entity, &reducedRowEchelonForm, tDiff, "rref");
    return 1;
}

canonical_original_code:
int outputRref(struct matrix *entity, int all, int timer){
    if (all){
        printf("{INPUT(%ix%i)}\n", entity->m, entity->n);
        printf("\n");
        printMatrix(entity);
        printf("\n");
    }
    int t1 = timeNowUsec();
    struct matrix rowEchelonForm;
    if (all){
        if(!toRowEchelonForm(&rowEchelonForm, entity, 1)){
            return 0;
        }
    } else {
        if(!toRowEchelonForm(&rowEchelonForm, entity, 0)){
            return 0;
        }
    }
    if (all){
        printf("%s\n", "{ROW ECHELON FORM}");
        printf("\n");
        printMatrix(&rowEchelonForm);
        printf("\n");
    }
    struct matrix reducedRowEchelonForm;
    if (all){
        if(!toReducedRowEchelonForm(&reducedRowEchelonForm, &rowEchelonForm, 1)){
            return 0;
        }
    } else {
        if(!toReducedRowEchelonForm(&reducedRowEchelonForm, &rowEchelonForm, 0)){
            return 0;
        }
    }
    int t2 = timeNowUsec();
    int tDiff = t2-t1;
    if (all){
        printf("%s\n", "{REDUCED ROW ECHELON FORM}");
        printf("\n");
    }
    printMatrix(&reducedRowEchelonForm);
    if (all){
        printf("\n");
        printf("%s\n", "{RANK AND NULLITY}");
        printf("Rank is %i and nullity is %i\n", matrixRank(&reducedRowEchelonForm), matrixNullity(&reducedRowEchelonForm));
    }
    if (timer){
        printf("\n");
        printf("%s\n", "{TIMER}");
        printf("It took %i microseconds!\n", tDiff);
        printf("\n");
    }
    logToJSON(entity, &reducedRowEchelonForm, tDiff, "rref");
    return 1;
}

variable_types: struct matrix { int m; int n; float matrix[100][100]; }


outputInverse

decompiled_code:
__int64 __fastcall outputInverse(unsigned int *a1, int a2, int a3)
{
int v4; // er13
unsigned int v6; // er14
int v7; // er13
int v8[10014]; // [rsp+0h] [rbp-9C78h] BYREF

if ( a2 )
{
printf("{INPUT(%ix%i)}\n", *a1, a1[1]);
putchar(10);
printMatrix(a1);
putchar(10);
v7 = timeNowUsec();
if ( !(unsigned int)inverseOfMatrix(v8, a1) )
return 0LL;
v6 = timeNowUsec() - v7;
puts("{INVERSE OF MATRIX}");
putchar(10);
printMatrix(v8);
if ( !a3 )
goto LABEL_5;
LABEL_8:
putchar(10);
puts("{TIMER}");
printf("It took %i microseconds!\n", v6);
putchar(10);
goto LABEL_5;
}
v4 = timeNowUsec();
if ( !(unsigned int)inverseOfMatrix(v8, a1) )
return 0LL;
v6 = timeNowUsec() - v4;
printMatrix(v8);
if ( a3 )
goto LABEL_8;
LABEL_5:
logToJSON((int *)a1, v8, v6, "inverse");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int *a1, int a2, int a3)
{
int v4; // er13
unsigned int v6; // er14
int v7; // er13
int v8[10014]; // [rsp+0h] [rbp-9C78h] BYREF

if ( a2 )
{
printf("{INPUT(%ix%i)}\n", *a1, a1[1]);
putchar(10);
printMatrix(a1);
putchar(10);
v7 = func0();
if ( !(unsigned int)inverseOfMatrix(v8, a1) )
return 0LL;
v6 = func0() - v7;
puts("{INVERSE OF MATRIX}");
putchar(10);
printMatrix(v8);
if ( !a3 )
goto LABEL_5;
LABEL_8:
putchar(10);
puts("{TIMER}");
printf("It took %i microseconds!\n", v6);
putchar(10);
goto LABEL_5;
}
v4 = func0();
if ( !(unsigned int)inverseOfMatrix(v8, a1) )
return 0LL;
v6 = func0() - v4;
printMatrix(v8);
if ( a3 )
goto LABEL_8;
LABEL_5:
func3((int *)a1, v8, v6, "inverse");
return 1LL;
}

original_code:
int outputInverse(matrix * entity, int all, int timer){
    if (all){
        printf("{INPUT(%ix%i)}\n", entity->m, entity->n);
        printf("\n");
        printMatrix(entity);
        printf("\n");
    }
    int t1 = timeNowUsec();
    matrix inverse;
    if(!inverseOfMatrix(&inverse, entity)){
        return 0;
    }
    int t2 = timeNowUsec();
    int tDiff = t2-t1;
    if (all){
        printf("%s\n", "{INVERSE OF MATRIX}");
        printf("\n");
    }
    printMatrix(&inverse);
    if (timer){
        printf("\n");
        printf("%s\n", "{TIMER}");
        printf("It took %i microseconds!\n", tDiff);
        printf("\n");
    }
    logToJSON(entity, &inverse, tDiff, "inverse");
    return 1;
}

canonical_original_code:
int outputInverse(struct matrix *entity, int all, int timer){
    if (all){
        printf("{INPUT(%ix%i)}\n", entity->m, entity->n);
        printf("\n");
        printMatrix(entity);
        printf("\n");
    }
    int t1 = timeNowUsec();
    struct matrix inverse;
    if(!inverseOfMatrix(&inverse, entity)){
        return 0;
    }
    int t2 = timeNowUsec();
    int tDiff = t2-t1;
    if (all){
        printf("%s\n", "{INVERSE OF MATRIX}");
        printf("\n");
    }
    printMatrix(&inverse);
    if (timer){
        printf("\n");
        printf("%s\n", "{TIMER}");
        printf("It took %i microseconds!\n", tDiff);
        printf("\n");
    }
    logToJSON(entity, &inverse, tDiff, "inverse");
    return 1;
}

user_defined_types: struct matrix { int m; int n; float matrix[100][100]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
_BOOL8 v4; // r12
_BOOL8 v5; // r13
char *v6; // r14
char *v7; // rax
unsigned int v9[10014]; // [rsp+0h] [rbp-9C78h] BYREF

if ( argc <= 2 )
{
puts("matriC needs additional arguments!");
puts("Specify a primary function as an argument:");
puts(" -> R (reduced row echelon form)");
puts(" -> I (inverse)");
puts(" -> D (determinant)");
puts("Additional arguments:");
puts(" -> t (add timer)");
puts(" -> all (verbose output)");
puts(" -> f (specify a file instead of inline matrix)");
return 0;
}
v3 = argv[1];
if ( *v3 != 45 )
{
puts("With no options specified, you have to many arguments.");
puts("Remember the syntax for options: ma3c -(R/I/D) input_here.");
return 0;
}
v4 = strchr(v3, 116) != 0LL;
v5 = strstr(v3, "all") != 0LL;
v6 = strchr(v3, 102);
v7 = strchr(v3, 82);
if ( !v6 )
{
if ( v7 )
return 0;
if ( !strchr(v3, 73) )
{
if ( !strchr(v3, 68) )
goto LABEL_7;
if ( !(unsigned int)parseInput(v9, argv[2], 0LL) )
return 0;
goto LABEL_18;
}
if ( !(unsigned int)parseInput(v9, argv[2], 0LL) )
return 0;
LABEL_20:
outputInverse(v9, v5, v4);
return 0;
}
if ( !v7 )
{
if ( !strchr(v3, 73) )
{
if ( !strchr(v3, 68) )
{
LABEL_7:
puts("matriC needs a primary function specified as an argument:");
puts(" -> R (reduced row echelon form)");
puts(" -> I (inverse)");
puts(" -> D (determinant)");
return 0;
}
if ( !(unsigned int)parseInput(v9, argv[2], 1LL) )
return 0;
LABEL_18:
outputDet(v9, v5, v4);
return 0;
}
if ( !(unsigned int)parseInput(v9, argv[2], 1LL) )
return 0;
goto LABEL_20;
}
if ( (unsigned int)parseInput(v9, argv[2], 1LL) )
outputRref(v9, v5, v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
_BOOL8 v4; // r12
_BOOL8 v5; // r13
char *v6; // r14
char *v7; // rax
unsigned int v9[10014]; // [rsp+0h] [rbp-9C78h] BYREF

if ( argc <= 2 )
{
puts("matriC needs additional arguments!");
puts("Specify a primary function as an argument:");
puts(" -> R (reduced row echelon form)");
puts(" -> I (inverse)");
puts(" -> D (determinant)");
puts("Additional arguments:");
puts(" -> t (add timer)");
puts(" -> all (verbose output)");
puts(" -> f (specify a file instead of inline matrix)");
return 0;
}
v3 = argv[1];
if ( *v3 != 45 )
{
puts("With no options specified, you have to many arguments.");
puts("Remember the syntax for options: ma3c -(R/I/D) input_here.");
return 0;
}
v4 = strchr(v3, 116) != 0LL;
v5 = strstr(v3, "all") != 0LL;
v6 = strchr(v3, 102);
v7 = strchr(v3, 82);
if ( !v6 )
{
if ( v7 )
return 0;
if ( !strchr(v3, 73) )
{
if ( !strchr(v3, 68) )
goto LABEL_7;
if ( !(unsigned int)parseInput(v9, argv[2], 0LL) )
return 0;
goto LABEL_18;
}
if ( !(unsigned int)parseInput(v9, argv[2], 0LL) )
return 0;
LABEL_20:
func5(v9, v5, v4);
return 0;
}
if ( !v7 )
{
if ( !strchr(v3, 73) )
{
if ( !strchr(v3, 68) )
{
LABEL_7:
puts("matriC needs a primary function specified as an argument:");
puts(" -> R (reduced row echelon form)");
puts(" -> I (inverse)");
puts(" -> D (determinant)");
return 0;
}
if ( !(unsigned int)parseInput(v9, argv[2], 1LL) )
return 0;
LABEL_18:
func2(v9, v5, v4);
return 0;
}
if ( !(unsigned int)parseInput(v9, argv[2], 1LL) )
return 0;
goto LABEL_20;
}
if ( (unsigned int)parseInput(v9, argv[2], 1LL) )
func4(v9, v5, v4);
return 0;
}

original_code:
int main(int argc, char *argv[]){
    int options = 0;
    int timer = 0;
    int all = 0;
    int file = 0;
    matrix input;
    if (argc <= 2){
        printf("%s\n", "matriC needs additional arguments!");
        printf("%s\n", "Specify a primary function as an argument:");
        printf("%s\n", "    -> R (reduced row echelon form)");
        printf("%s\n", "    -> I (inverse)");
        printf("%s\n", "    -> D (determinant)");
        printf("%s\n", "Additional arguments:");
        printf("%s\n", "    -> t (add timer)");
        printf("%s\n", "    -> all (verbose output)");
        printf("%s\n", "    -> f (specify a file instead of inline matrix)");
    } else {
        if (argv[1][0] == '-'){
            options = 1;
        } else {
            if (argc > 2){
                printf("%s\n", "With no options specified, you have to many arguments.");
                printf("%s\n", "Remember the syntax for options: ma3c -(R/I/D) input_here.");
                return 0;
            }
        }
        if (strstr(argv[1], "t") && options == 1){
            timer = 1;
        }
        if (strstr(argv[1], "all") && options == 1){
            all = 1;
        }
        if (strstr(argv[1], "f") && options == 1){
            file = 1;
        }
        if ((strstr(argv[1], "R") && options == 1) || options == 0){
            if (file){
                if (parseInput(&input, argv[2], 1)){
                    outputRref(&input, all, timer);
                } else {
                    return 0;
                }
            } else {
                if (options == 0 && parseInput(&input, argv[1], 0)){
                    outputRref(&input, all, timer);
                } else {
                    return 0;
                }
                if (options == 1 && parseInput(&input, argv[2], 0)){
                    outputRref(&input, all, timer);
                } else {
                    return 0;
                }
            }
        } else if (strstr(argv[1], "I")){
            if (file){
                if (parseInput(&input, argv[2], 1)){
                    outputInverse(&input, all, timer);
                } else {
                    return 0;
                }
            } else {
                if (parseInput(&input, argv[2], 0)){
                    outputInverse(&input, all, timer);
                } else {
                    return 0;
                }
            }
        } else if (strstr(argv[1], "D")){
            if (file){
                if (parseInput(&input, argv[2], 1)){
                    outputDet(&input, all, timer);
                } else {
                    return 0;
                }
            } else {
                if (parseInput(&input, argv[2], 0)){
                    outputDet(&input, all, timer);
                } else {
                    return 0;
                }
            }
        } else {
            printf("%s\n", "matriC needs a primary function specified as an argument:");
            printf("%s\n", "    -> R (reduced row echelon form)");
            printf("%s\n", "    -> I (inverse)");
            printf("%s\n", "    -> D (determinant)");
        }
    }
}

canonical_original_code:
int main(int argc, char *argv[]){
    int options = 0;
    int timer = 0;
    int all = 0;
    int file = 0;
    struct matrix input;
    if (argc <= 2){
        printf("%s\n", "matriC needs additional arguments!");
        printf("%s\n", "Specify a primary function as an argument:");
        printf("%s\n", "    -> R (reduced row echelon form)");
        printf("%s\n", "    -> I (inverse)");
        printf("%s\n", "    -> D (determinant)");
        printf("%s\n", "Additional arguments:");
        printf("%s\n", "    -> t (add timer)");
        printf("%s\n", "    -> all (verbose output)");
        printf("%s\n", "    -> f (specify a file instead of inline matrix)");
    } else {
        if (argv[1][0] == '-'){
            options = 1;
        } else {
            if (argc > 2){
                printf("%s\n", "With no options specified, you have to many arguments.");
                printf("%s\n", "Remember the syntax for options: ma3c -(R/I/D) input_here.");
                return 0;
            }
        }
        if (strstr(argv[1], "t") && options == 1){
            timer = 1;
        }
        if (strstr(argv[1], "all") && options == 1){
            all = 1;
        }
        if (strstr(argv[1], "f") && options == 1){
            file = 1;
        }
        if ((strstr(argv[1], "R") && options == 1) || options == 0){
            if (file){
                if (parseInput(&input, argv[2], 1)){
                    outputRref(&input, all, timer);
                } else {
                    return 0;
                }
            } else {
                if (options == 0 && parseInput(&input, argv[1], 0)){
                    outputRref(&input, all, timer);
                } else {
                    return 0;
                }
                if (options == 1 && parseInput(&input, argv[2], 0)){
                    outputRref(&input, all, timer);
                } else {
                    return 0;
                }
            }
        } else if (strstr(argv[1], "I")){
            if (file){
                if (parseInput(&input, argv[2], 1)){
                    outputInverse(&input, all, timer);
                } else {
                    return 0;
                }
            } else {
                if (parseInput(&input, argv[2], 0)){
                    outputInverse(&input, all, timer);
                } else {
                    return 0;
                }
            }
        } else if (strstr(argv[1], "D")){
            if (file){
                if (parseInput(&input, argv[2], 1)){
                    outputDet(&input, all, timer);
                } else {
                    return 0;
                }
            } else {
                if (parseInput(&input, argv[2], 0)){
                    outputDet(&input, all, timer);
                } else {
                    return 0;
                }
            }
        } else {
            printf("%s\n", "matriC needs a primary function specified as an argument:");
            printf("%s\n", "    -> R (reduced row echelon form)");
            printf("%s\n", "    -> I (inverse)");
            printf("%s\n", "    -> D (determinant)");
        }
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: options int

variable_types: file int


usage

repo: roganartu/autodjtg

decompiled_code:
void __noreturn usage()
{
puts(
"Usage:\n"
" autodjtg [-h]\n"
" \n"
" This tool automates the usage of djtgcfg from Digilent.\n"
" Currently does not support file paths as arguments.\n"
" In the meantime just run the tool from the directory\n"
" containing the .bit file you wish to program.");
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts(
"Usage:\n"
" autodjtg [-h]\n"
" \n"
" This tool automates the usage of djtgcfg from Digilent.\n"
" Currently does not support file paths as arguments.\n"
" In the meantime just run the tool from the directory\n"
" containing the .bit file you wish to program.");
exit(1);
}

original_code:
void usage() {
    char* usage = "Usage:\n       autodjtg [-h]\n   \n   This tool automates the usage of djtgcfg from Digilent.\n   Currently does not support file paths as arguments.\n   In the meantime just run the tool from the directory\n   containing the .bit file you wish to program.";
    printf("%s\n", usage);
    exit(1);
}

canonical_original_code:
void usage() {
    char *usage = "Usage:\n       autodjtg [-h]\n   \n   This tool automates the usage of djtgcfg from Digilent.\n   Currently does not support file paths as arguments.\n   In the meantime just run the tool from the directory\n   containing the .bit file you wish to program.";
    printf("%s\n", usage);
    exit(1);
}

variable_types:
usage
char *


decompiled_code:
void __fastcall get_options(int a1, __int64 a2)
{
const char **v2; // rax
const char *v3; // r8

if ( a1 > 1 )
{
v2 = (const char **)(a2 + 8);
do
{
v3 = *v2;
if ( !strcmp(*v2, "--help") || *v3 == 45 && v3[1] == 104 && !v3[2] )
cmd_args = 1;
++v2;
}
while ( v2 != (const char **)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) );
if ( a1 > 2 )
goto LABEL_10;
}
if ( a1 == 2 && !cmd_args )
LABEL_10:
cmd_args = 1;
}

canonical_decompiled_code:
void __fastcall func1(int a1, __int64 a2)
{
const char **v2; // rax
const char *v3; // r8

if ( a1 > 1 )
{
v2 = (const char **)(a2 + 8);
do
{
v3 = *v2;
if ( !strcmp(*v2, "--help") || *v3 == 45 && v3[1] == 104 && !v3[2] )
cmd_args = 1;
++v2;
}
while ( v2 != (const char **)(a2 + 8LL * (unsigned int)(a1 - 2) + 16) );
if ( a1 > 2 )
goto LABEL_10;
}
if ( a1 == 2 && !cmd_args )
LABEL_10:
cmd_args = 1;
}

original_code:
void get_options(int argc, char** argv) {
    int i;
    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "--help") == 0 ||
                strcmp(argv[i], "-h") == 0)
            cmd_args.help = 1;
    }
    if (argc > 2 || (argc == 2 && !cmd_args.help))
        cmd_args.help = 1;
}

canonical_original_code:
void get_options(int argc, char **argv) {
    int i;
    for (i = 1; i < argc; i++) {
        if (strcmp(argv[i], "--help") == 0 ||
                strcmp(argv[i], "-h") == 0)
            cmd_args.help = 1;
    }
    if (argc > 2 || (argc == 2 && !cmd_args.help))
        cmd_args.help = 1;
}

variable_types:
argv
char **

variable_types: i int


decompiled_code:
void __fastcall __noreturn program_device(char **a1)
{
char *v1; // rax
__int64 *v2; // rbx
char *v3; // rax
char *v4; // rax
const char *v5; // rsi
char *v6[8]; // [rsp+0h] [rbp-68h] BYREF
__int64 v7; // [rsp+40h] [rbp-28h] BYREF

v1 = *a1;
v2 = (__int64 *)v6;
v6[0] = "djtgcfg";
v6[3] = v1;
v3 = a1[2];
v6[1] = "prog";
v6[5] = v3;
v4 = a1[1];
v6[2] = "-d";
v6[4] = "-i";
v6[6] = "-f";
v6[7] = v4;
v7 = 0LL;
execvp("djtgcfg", v6);
printf("There was an error executing: ");
do
{
v5 = (const char *)*v2++;
printf("%s ", v5);
}
while ( v2 != &v7 );
putchar(10);
exit(999);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(char **a1)
{
char *v1; // rax
__int64 *v2; // rbx
char *v3; // rax
char *v4; // rax
const char *v5; // rsi
char *v6[8]; // [rsp+0h] [rbp-68h] BYREF
__int64 v7; // [rsp+40h] [rbp-28h] BYREF

v1 = *a1;
v2 = (__int64 *)v6;
v6[0] = "djtgcfg";
v6[3] = v1;
v3 = a1[2];
v6[1] = "prog";
v6[5] = v3;
v4 = a1[1];
v6[2] = "-d";
v6[4] = "-i";
v6[6] = "-f";
v6[7] = v4;
v7 = 0LL;
execvp("djtgcfg", v6);
printf("There was an error executing: ");
do
{
v5 = (const char *)*v2++;
printf("%s ", v5);
}
while ( v2 != &v7 );
putchar(10);
exit(999);
}

original_code:
void program_device(Device *device) {
    char* args[9];
    args[0] = "djtgcfg";
    args[1] = "prog";
    args[2] = "-d";
    args[3] = device->id;
    args[4] = "-i";
    args[5] = device->index;
    args[6] = "-f";
    args[7] = device->file;
    args[8] = (char*) 0;
    execvp("djtgcfg", args);
    printf("There was an error executing: ");
    for (int i = 0; i < 8; i++)
        printf("%s ", args[i]);
    printf("\n");
    exit(999);
}

canonical_original_code:
void program_device(struct Device *device) {
    char *args[9];
    args[0] = "djtgcfg";
    args[1] = "prog";
    args[2] = "-d";
    args[3] = device->id;
    args[4] = "-i";
    args[5] = device->index;
    args[6] = "-f";
    args[7] = device->file;
    args[8] = (char *) 0;
    execvp("djtgcfg", args);
    printf("There was an error executing: ");
    for (int i = 0; i < 8; i++)
        printf("%s ", args[i]);
    printf("\n");
    exit(999);
}

variable_types: struct Device { char *id; char *file; char *index; } *

variable_types:
args
char *[9]


decompiled_code:
__int64 pipe_and_fork()
{
__int64 result; // rax
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

pipe(pipedes);
childPid = fork();
if ( childPid )
{
close(pipedes[1]);
result = (unsigned int)pipedes[0];
}
else
{
close(pipedes[0]);
dup2(pipedes[1], 1);
result = (unsigned int)pipedes[1];
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
int pipedes[2]; // [rsp+8h] [rbp-10h] BYREF

pipe(pipedes);
childPid = fork();
if ( childPid )
{
close(pipedes[1]);
result = (unsigned int)pipedes[0];
}
else
{
close(pipedes[0]);
dup2(pipedes[1], 1);
result = (unsigned int)pipedes[1];
}
return result;
}

original_code:
int pipe_and_fork() {
    int pipes[2];
    int output;
    pid_t pid;
    if (pipe(pipes) != 0) {
    }
    if ((pid = fork()) == -1) {
    }
    childPid = pid;
    if (pid == 0) {
        close(pipes[0]);
        output = 1;
        if (dup2(pipes[1], output) == -1) {
        }
        return pipes[1];
    } else {
        close(pipes[1]);
        return pipes[0];
    }
}

canonical_original_code:
int pipe_and_fork() {
    int pipes[2];
    int output;
    int pid;
    if (pipe(pipes) != 0) {
    }
    if ((pid = fork()) == -1) {
    }
    childPid = pid;
    if (pid == 0) {
        close(pipes[0]);
        output = 1;
        if (dup2(pipes[1], output) == -1) {
        }
        return pipes[1];
    } else {
        close(pipes[1]);
        return pipes[0];
    }
}

variable_types:
pipes
int [2]

variable_types: output int

variable_types: pid int


main

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

retcode = 0;
get_options(argc, (__int64)argv);
if ( cmd_args )
usage();
v3 = (const char **)malloc(0x18uLL);
get_device_id((char **)v3);
if ( *v3 )
{
printf("Found USB Device: %s\n", *v3);
get_device_index((char **)v3);
get_file_path((__int64)v3);
program_device((char **)v3);
}
retcode = 2;
free((void *)v3[1]);
free(v3);
return retcode;
}

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

retcode = 0;
func1(argc, (__int64)argv);
if ( cmd_args )
func0();
v3 = (const char **)malloc(0x18uLL);
func5((char **)v3);
if ( *v3 )
{
printf("Found USB Device: %s\n", *v3);
func6((char **)v3);
func2((__int64)v3);
func3((char **)v3);
}
retcode = 2;
free((void *)v3[1]);
free(v3);
return retcode;
}

original_code:
int main(int argc, char** argv) {
    Device* device;
    retcode = 0;
    get_options(argc, argv);
    if (cmd_args.help)
        usage();
    device = (Device*) malloc(sizeof(Device));
    get_device_id(device);
    if (device->id == ((void *)0)) {
        retcode = 2;
        goto cleanup;
    }
    printf("Found USB Device: %s\n", device->id);
    get_device_index(device);
    if (device->index < 0) {
        retcode = 3;
        goto cleanup;
    }
    get_file_path(device);
    program_device(device);
cleanup:
    free(device->id);
    free(device->file);
    free(device);
    return retcode;
}

canonical_original_code:
int main(int argc, char **argv) {
    struct Device *device;
    retcode = 0;
    get_options(argc, argv);
    if (cmd_args.help)
        usage();
    device = (struct Device *) malloc(sizeof(Device));
    get_device_id(device);
    if (device->id == ((void *)0)) {
        retcode = 2;
        goto cleanup;
    }
    printf("Found USB Device: %s\n", device->id);
    get_device_index(device);
    if (device->index < 0) {
        retcode = 3;
        goto cleanup;
    }
    get_file_path(device);
    program_device(device);
cleanup:
    free(device->id);
    free(device->file);
    free(device);
    return retcode;
}

user_defined_types: struct Device { char *id; char *file; char *index; }