display

decompiled_code:
__int64 display()
{
float v0; // xmm1_4
char v2[12]; // [rsp+Ch] [rbp-8Ch] BYREF
char v3[12]; // [rsp+18h] [rbp-80h] BYREF
int v4[3]; // [rsp+24h] [rbp-74h] BYREF
char v5[64]; // [rsp+30h] [rbp-68h] BYREF
int v6[4]; // [rsp+70h] [rbp-28h] BYREF
int v7[6]; // [rsp+80h] [rbp-18h] BYREF

glClear(16640LL);
glMatrixMode(5889LL);
v0 = (double)width / (double)height;
mat_persp(v5, 60.0, v0, 0.1, 1000.0);
glLoadMatrixf(v5);
glMatrixMode(5888LL);
get_camera((float *)v4, (__int64)v3, (__int64)v2);
mat_lookat(v5, v4, v3, v2);
glLoadMatrixf(v5);
glEnable(2896LL);
v6[0] = LC3;
v6[1] = LC3;
v6[2] = LC3;
v6[3] = LC3;
glLightfv(0x4000LL, 4609LL, v6);
v7[0] = v4[0];
v7[1] = v4[1];
v7[2] = v4[2];
v7[3] = LC3;
glLightfv(0x4000LL, 4611LL, v7);
glEnable(0x4000LL);
ed_render(ed);
gl_draw_xyz();
gl_begin_2d();
gl_draw_fps(0.92500001, 0.97500002);
ed_render_overlay(ed);
gl_end_2d();
glutSwapBuffers();
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func11()
{
float v0; // xmm1_4
char v2[12]; // [rsp+Ch] [rbp-8Ch] BYREF
char v3[12]; // [rsp+18h] [rbp-80h] BYREF
int v4[3]; // [rsp+24h] [rbp-74h] BYREF
char v5[64]; // [rsp+30h] [rbp-68h] BYREF
int v6[4]; // [rsp+70h] [rbp-28h] BYREF
int v7[6]; // [rsp+80h] [rbp-18h] BYREF

glClear(16640LL);
glMatrixMode(5889LL);
v0 = (double)width / (double)height;
mat_persp(v5, 60.0, v0, 0.1, 1000.0);
glLoadMatrixf(v5);
glMatrixMode(5888LL);
func10((float *)v4, (__int64)v3, (__int64)v2);
mat_lookat(v5, v4, v3, v2);
glLoadMatrixf(v5);
glEnable(2896LL);
v6[0] = LC3;
v6[1] = LC3;
v6[2] = LC3;
v6[3] = LC3;
glLightfv(0x4000LL, 4609LL, v6);
v7[0] = v4[0];
v7[1] = v4[1];
v7[2] = v4[2];
v7[3] = LC3;
glLightfv(0x4000LL, 4611LL, v7);
glEnable(0x4000LL);
ed_render(ed);
gl_draw_xyz();
gl_begin_2d();
gl_draw_fps(0.92500001, 0.97500002);
ed_render_overlay(ed);
gl_end_2d();
glutSwapBuffers();
return glutPostRedisplay();
}

original_code:
static void display(void)
{
 matrix m;
 vector eye, at, up;
 glClear(0x00004000 | 0x00000100);
 glMatrixMode(0x1701);
 mat_persp(m, fovy, (double) width / height, znear, zfar);
 glLoadMatrixf(m);
 glMatrixMode(0x1700);
 get_camera(eye, at, up);
 mat_lookat(m, eye, at, up);
 glLoadMatrixf(m);
 glEnable(0x0B50);
 glLightfv(0x4000, 0x1201,
    (GLfloat[4]) { 1.0f, 1.0f, 1.0f, 1.0f });
 glLightfv(0x4000, 0x1203,
    (GLfloat[4]) { eye[0], eye[1], eye[2], 1.0f });
 glEnable(0x4000);
 ed_render(ed);
 gl_draw_xyz();
 gl_begin_2d();
 gl_draw_fps(0.925f, 0.975f);
 ed_render_overlay(ed);
 gl_end_2d();
 glutSwapBuffers();
 glutPostRedisplay();
}

canonical_original_code:
static void display()
{
 float m[16];
 float eye[3]; float at[3]; float up[3];
 glClear(0x00004000 | 0x00000100);
 glMatrixMode(0x1701);
 mat_persp(m, fovy, (double) width / height, znear, zfar);
 glLoadMatrixf(m);
 glMatrixMode(0x1700);
 get_camera(eye, at, up);
 mat_lookat(m, eye, at, up);
 glLoadMatrixf(m);
 glEnable(0x0B50);
 glLightfv(0x4000, 0x1201,
    (float [4]) { 1.0f, 1.0f, 1.0f, 1.0f });
 glLightfv(0x4000, 0x1203,
    (float [4]) { eye[0], eye[1], eye[2], 1.0f });
 glEnable(0x4000);
 ed_render(ed);
 gl_draw_xyz();
 gl_begin_2d();
 gl_draw_fps(0.925f, 0.975f);
 ed_render_overlay(ed);
 gl_end_2d();
 glutSwapBuffers();
 glutPostRedisplay();
}


reshape

repo: skaslev/catmull-clark

decompiled_code:
__int64 __fastcall reshape(int a1, int a2)
{
int v2; // ecx
int v3; // edx

v2 = 1;
v3 = a1;
if ( a1 <= 0 )
v3 = 1;
width = v3;
if ( a2 > 0 )
v2 = a2;
height = v2;
glViewport(0LL, 0LL);
glClearDepth(1.0);
glClearColor(0.0, 0.0, 0.0);
return glEnable(2929LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, int a2)
{
int v2; // ecx
int v3; // edx

v2 = 1;
v3 = a1;
if ( a1 <= 0 )
v3 = 1;
width = v3;
if ( a2 > 0 )
v2 = a2;
height = v2;
glViewport(0LL, 0LL);
glClearDepth(1.0);
glClearColor(0.0, 0.0, 0.0);
return glEnable(2929LL);
}

original_code:
static void reshape(int w, int h)
{
 width = w > 1 ? w : 1;
 height = h > 1 ? h : 1;
 glViewport(0, 0, width, height);
 glClearDepth(1.0);
 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
 glEnable(0x0B71);
}

variable_types: w int

variable_types: h int

return_type: void


special

decompiled_code:
void __fastcall special(int a1)
{
__int64 v1; // rax
__int64 v2; // rax

if ( !(unsigned int)ed_is_editing(ed) )
{
if ( a1 == 102 )
{
ed_next_obj(ed);
v1 = ed_cur_obj(ed);
focus_camera(v1);
}
else if ( a1 > 102 )
{
if ( a1 == 103 )
ed_prev_level(ed);
}
else if ( a1 == 100 )
{
ed_prev_obj(ed);
v2 = ed_cur_obj(ed);
focus_camera(v2);
}
else if ( a1 == 101 )
{
ed_next_level(ed);
}
}
}

canonical_decompiled_code:
void __fastcall func14(int a1)
{
__int64 v1; // rax
__int64 v2; // rax

if ( !(unsigned int)ed_is_editing(ed) )
{
if ( a1 == 102 )
{
ed_next_obj(ed);
v1 = ed_cur_obj(ed);
func13(v1);
}
else if ( a1 > 102 )
{
if ( a1 == 103 )
ed_prev_level(ed);
}
else if ( a1 == 100 )
{
ed_prev_obj(ed);
v2 = ed_cur_obj(ed);
func13(v2);
}
else if ( a1 == 101 )
{
ed_next_level(ed);
}
}
}

original_code:
static void special(int key, int x, int y)
{
 if (ed_is_editing(ed))
  return;
 switch (key) {
 case 0x0066:
  ed_next_obj(ed);
  focus_camera(ed_cur_obj(ed));
  break;
 case 0x0064:
  ed_prev_obj(ed);
  focus_camera(ed_cur_obj(ed));
  break;
 case 0x0065:
  ed_next_level(ed);
  break;
 case 0x0067:
  ed_prev_level(ed);
  break;
 }
}

variable_types: key int

variable_types: x int

variable_types: y int


keyboard

decompiled_code:
void __fastcall keyboard(unsigned __int8 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

if ( a1 == 70 )
goto LABEL_16;
if ( a1 <= 0x46u )
{
if ( a1 == 27 )
goto LABEL_17;
if ( a1 != 69 )
{
if ( a1 != 17 )
goto LABEL_6;
LABEL_17:
exit(0);
}
goto LABEL_18;
}
if ( a1 == 101 )
{
LABEL_18:
ed_toggle_editing(ed);
LABEL_6:
if ( (unsigned int)ed_is_editing(ed) )
return;
if ( a1 == 61 )
{
LABEL_26:
ed_next_level(ed);
return;
}
if ( a1 <= 0x3Du )
{
if ( a1 == 32 )
{
ed_next_obj(ed);
v3 = ed_cur_obj(ed);
focus_camera(v3);
return;
}
if ( a1 > 0x20u )
{
if ( a1 != 43 )
{
if ( a1 != 45 )
return;
goto LABEL_13;
}
goto LABEL_26;
}
if ( a1 != 8 )
return;
LABEL_20:
ed_prev_obj(ed);
v2 = ed_cur_obj(ed);
focus_camera(v2);
return;
}
goto LABEL_28;
}
if ( a1 == 102 )
{
LABEL_16:
v1 = ed_cur_obj(ed);
focus_camera(v1);
goto LABEL_6;
}
if ( (unsigned int)ed_is_editing(ed) )
return;
LABEL_28:
if ( a1 == 119 )
goto LABEL_25;
if ( a1 <= 0x77u )
{
if ( a1 != 87 )
{
if ( a1 == 95 )
{
LABEL_13:
ed_prev_level(ed);
return;
}
return;
}
LABEL_25:
ed_toggle_wireframe(ed);
return;
}
if ( a1 == 127 )
goto LABEL_20;
}

canonical_decompiled_code:
void __fastcall func15(unsigned __int8 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax

if ( a1 == 70 )
goto LABEL_16;
if ( a1 <= 0x46u )
{
if ( a1 == 27 )
goto LABEL_17;
if ( a1 != 69 )
{
if ( a1 != 17 )
goto LABEL_6;
LABEL_17:
exit(0);
}
goto LABEL_18;
}
if ( a1 == 101 )
{
LABEL_18:
ed_toggle_editing(ed);
LABEL_6:
if ( (unsigned int)ed_is_editing(ed) )
return;
if ( a1 == 61 )
{
LABEL_26:
ed_next_level(ed);
return;
}
if ( a1 <= 0x3Du )
{
if ( a1 == 32 )
{
ed_next_obj(ed);
v3 = ed_cur_obj(ed);
func13(v3);
return;
}
if ( a1 > 0x20u )
{
if ( a1 != 43 )
{
if ( a1 != 45 )
return;
goto LABEL_13;
}
goto LABEL_26;
}
if ( a1 != 8 )
return;
LABEL_20:
ed_prev_obj(ed);
v2 = ed_cur_obj(ed);
func13(v2);
return;
}
goto LABEL_28;
}
if ( a1 == 102 )
{
LABEL_16:
v1 = ed_cur_obj(ed);
func13(v1);
goto LABEL_6;
}
if ( (unsigned int)ed_is_editing(ed) )
return;
LABEL_28:
if ( a1 == 119 )
goto LABEL_25;
if ( a1 <= 0x77u )
{
if ( a1 != 87 )
{
if ( a1 == 95 )
{
LABEL_13:
ed_prev_level(ed);
return;
}
return;
}
LABEL_25:
ed_toggle_wireframe(ed);
return;
}
if ( a1 == 127 )
goto LABEL_20;
}

original_code:
static void keyboard(unsigned char key, int x, int y)
{
 switch (key) {
 case 27: case 17:
  exit(0);
  break;
 case 'f': case 'F':
  focus_camera(ed_cur_obj(ed));
  break;
 case 'e': case 'E':
  ed_toggle_editing(ed);
  break;
 }
 if (!ed_is_editing(ed)) {
  switch (key) {
  case ' ':
   ed_next_obj(ed);
   focus_camera(ed_cur_obj(ed));
   break;
  case 8: case 127:
   ed_prev_obj(ed);
   focus_camera(ed_cur_obj(ed));
   break;
  case 'w': case 'W':
   ed_toggle_wireframe(ed);
   break;
  case '=': case '+':
   ed_next_level(ed);
   break;
  case '-': case '_':
   ed_prev_level(ed);
   break;
  }
 }
}

variable_types:
key
unsigned char


main

canonical_name: main

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

v5[0] = argc;
glutInit(v5, argv, envp);
glutInitDisplayMode(18LL);
glutInitWindowSize((unsigned int)width, (unsigned int)height);
glutCreateWindow("catmull-clark");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIdleFunc(idle);
printf("Loading... ");
fflush(stdout);
ed = ed_create();
ed_add_obj(ed, "objs/cube.obj", 5LL);
ed_add_obj(ed, "objs/tetra.obj", 5LL);
ed_add_obj(ed, "objs/bigguy.obj", 3LL);
ed_add_obj(ed, "objs/monsterfrog.obj", 3LL);
puts("done.");
v3 = ed_cur_obj(ed);
focus_camera(v3);
glutMainLoop();
return 0;
}

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

v5[0] = argc;
glutInit(v5, argv, envp);
glutInitDisplayMode(18LL);
glutInitWindowSize((unsigned int)width, (unsigned int)height);
glutCreateWindow("catmull-clark");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIdleFunc(idle);
printf("Loading... ");
fflush(stdout);
ed = ed_create();
ed_add_obj(ed, "objs/cube.obj", 5LL);
ed_add_obj(ed, "objs/tetra.obj", 5LL);
ed_add_obj(ed, "objs/bigguy.obj", 3LL);
ed_add_obj(ed, "objs/monsterfrog.obj", 3LL);
puts("done.");
v3 = ed_cur_obj(ed);
func13(v3);
glutMainLoop();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 glutInit(&argc, argv);
 glutInitDisplayMode(0x0000 | 0x0010 | 0x0002);
 glutInitWindowSize(width, height);
 glutCreateWindow("catmull-clark");
 glutReshapeFunc(reshape);
 glutDisplayFunc(display);
 glutKeyboardFunc(keyboard);
 glutSpecialFunc(special);
 glutMouseFunc(mouse);
 glutMotionFunc(motion);
 glutIdleFunc(idle);
 printf("Loading... "); fflush(stdout);
 ed = ed_create();
 ed_add_obj(ed, "objs/cube.obj", 5);
 ed_add_obj(ed, "objs/tetra.obj", 5);
 ed_add_obj(ed, "objs/bigguy.obj", 3);
 ed_add_obj(ed, "objs/monsterfrog.obj", 3);
 printf("done.\n");
 focus_camera(ed_cur_obj(ed));
 glutMainLoop();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
__int64 gl_begin_2d()
{
glPushAttrib(0xFFFFFFFFLL);
glDepthMask(0LL);
glDisable(2929LL);
glDisable(2896LL);
glColor3f(1.0, 1.0);
glMatrixMode(5889LL);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
glMatrixMode(5888LL);
glPushMatrix();
return glLoadIdentity();
}

canonical_decompiled_code:
__int64 func0()
{
glPushAttrib(0xFFFFFFFFLL);
glDepthMask(0LL);
glDisable(2929LL);
glDisable(2896LL);
glColor3f(1.0, 1.0);
glMatrixMode(5889LL);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, 0.0, 1.0);
glMatrixMode(5888LL);
glPushMatrix();
return glLoadIdentity();
}

original_code:
void gl_begin_2d(void)
{
 glPushAttrib(0xFFFFFFFF);
 glDepthMask(0);
 glDisable(0x0B71);
 glDisable(0x0B50);
 glColor3f(1.0f, 1.0f, 1.0f);
 glMatrixMode(0x1701);
 glPushMatrix();
 glLoadIdentity();
 glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
 glMatrixMode(0x1700);
 glPushMatrix();
 glLoadIdentity();
}

canonical_original_code:
void gl_begin_2d()
{
 glPushAttrib(0xFFFFFFFF);
 glDepthMask(0);
 glDisable(0x0B71);
 glDisable(0x0B50);
 glColor3f(1.0f, 1.0f, 1.0f);
 glMatrixMode(0x1701);
 glPushMatrix();
 glLoadIdentity();
 glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
 glMatrixMode(0x1700);
 glPushMatrix();
 glLoadIdentity();
}


decompiled_code:
__int64 gl_end_2d()
{
glMatrixMode(5889LL);
glPopMatrix();
glMatrixMode(5888LL);
glPopMatrix();
return glPopAttrib();
}

canonical_decompiled_code:
__int64 func1()
{
glMatrixMode(5889LL);
glPopMatrix();
glMatrixMode(5888LL);
glPopMatrix();
return glPopAttrib();
}

original_code:
void gl_end_2d(void)
{
 glMatrixMode(0x1701);
 glPopMatrix();
 glMatrixMode(0x1700);
 glPopMatrix();
 glPopAttrib();
}

canonical_original_code:
void gl_end_2d()
{
 glMatrixMode(0x1701);
 glPopMatrix();
 glMatrixMode(0x1700);
 glPopMatrix();
 glPopAttrib();
}


decompiled_code:
__int64 gl_draw_xyz()
{
glPushAttrib(0x2000LL);
glDisable(2896LL);
glBegin(1LL);
glColor3f(1.0, 0.0);
glVertex3f(0.0, 0.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC0), 0.0);
glColor3f(0.0, 1.0);
glVertex3f(0.0, 0.0);
glVertex3f(0.0, COERCE_DOUBLE((unsigned __int64)LC0));
glColor3f(0.0, 0.0);
glVertex3f(0.0, 0.0);
glVertex3f(0.0, 0.0);
glEnd(0.0, 0.0, 1.0);
return glPopAttrib();
}

canonical_decompiled_code:
__int64 func2()
{
glPushAttrib(0x2000LL);
glDisable(2896LL);
glBegin(1LL);
glColor3f(1.0, 0.0);
glVertex3f(0.0, 0.0);
glVertex3f(COERCE_DOUBLE((unsigned __int64)LC0), 0.0);
glColor3f(0.0, 1.0);
glVertex3f(0.0, 0.0);
glVertex3f(0.0, COERCE_DOUBLE((unsigned __int64)LC0));
glColor3f(0.0, 0.0);
glVertex3f(0.0, 0.0);
glVertex3f(0.0, 0.0);
glEnd(0.0, 0.0, 1.0);
return glPopAttrib();
}


decompiled_code:
__int64 __fastcall gl_draw_quad(int a1, double a2, double a3, float a4)
{
int v4; // ebx
double v5; // xmm0_8

glBegin(7LL);
if ( a1 )
{
glTexCoord2f(0.0, 1.0);
glVertex2f(0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), 1.0);
glVertex2f(COERCE_DOUBLE((unsigned __int64)LC0));
v4 = LC3;
}
else
{
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), 0.0);
glVertex2f(COERCE_DOUBLE((unsigned __int64)LC0));
v4 = LC0;
}
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), *(float *)&v4);
glVertex2f(COERCE_DOUBLE((unsigned __int64)LC0));
glTexCoord2f(0.0, *(float *)&v4);
v5 = glVertex2f(0.0);
return glEnd(v5, COERCE_DOUBLE((unsigned __int64)LC0), a4);
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, double a2, double a3, float a4)
{
int v4; // ebx
double v5; // xmm0_8

glBegin(7LL);
if ( a1 )
{
glTexCoord2f(0.0, 1.0);
glVertex2f(0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), 1.0);
glVertex2f(COERCE_DOUBLE((unsigned __int64)LC0));
v4 = LC3;
}
else
{
glTexCoord2f(0.0, 0.0);
glVertex2f(0.0);
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), 0.0);
glVertex2f(COERCE_DOUBLE((unsigned __int64)LC0));
v4 = LC0;
}
glTexCoord2f(COERCE_DOUBLE((unsigned __int64)LC0), *(float *)&v4);
glVertex2f(COERCE_DOUBLE((unsigned __int64)LC0));
glTexCoord2f(0.0, *(float *)&v4);
v5 = glVertex2f(0.0);
return glEnd(v5, COERCE_DOUBLE((unsigned __int64)LC0), a4);
}

original_code:
void gl_draw_quad(int flipy)
{
 glBegin(0x0007);
 glTexCoord2f(0.0f, flipy ? 1.0f : 0.0f);
 glVertex2f(0.0f, 0.0f);
 glTexCoord2f(1.0f, flipy ? 1.0f : 0.0f);
 glVertex2f(1.0f, 0.0f);
 glTexCoord2f(1.0f, flipy ? 0.0f : 1.0f);
 glVertex2f(1.0f, 1.0f);
 glTexCoord2f(0.0f, flipy ? 0.0f : 1.0f);
 glVertex2f(0.0f, 1.0f);
 glEnd();
}

variable_types: flipy int


decompiled_code:
int gl_printf(__int64 a1, const char *a2, ...)
{
int result; // eax
char v3; // si
char *v4; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-2E0h] BYREF
char s[512]; // [rsp+20h] [rbp-2C8h] BYREF

va_start(arg, a2);
result = vsprintf(s, a2, arg);
v3 = s[0];
if ( s[0] )
{
v4 = s;
do
{
result = glutBitmapCharacter(a1, (unsigned int)v3);
v3 = *++v4;
}
while ( *v4 );
}
return result;
}

canonical_decompiled_code:
int func4(__int64 a1, const char *a2, ...)
{
int result; // eax
char v3; // si
char *v4; // rbx
gcc_va_list arg; // [rsp+8h] [rbp-2E0h] BYREF
char s[512]; // [rsp+20h] [rbp-2C8h] BYREF

va_start(arg, a2);
result = vsprintf(s, a2, arg);
v3 = s[0];
if ( s[0] )
{
v4 = s;
do
{
result = glutBitmapCharacter(a1, (unsigned int)v3);
v3 = *++v4;
}
while ( *v4 );
}
return result;
}

original_code:
void gl_printf(void *font, const char *format, ...)
{
 char str[512], *p;
 va_list args;
 __builtin_va_start(args,format);
 vsprintf(str, format, args);
 __builtin_va_end(args);
 for (p = str; *p; p++)
  glutBitmapCharacter(font, *p);
}

canonical_original_code:
void gl_printf(void *font, char *format, ...)
{
 char str[512]; char *p;
 __builtin_va_list args;
 __builtin_va_start(args,format);
 vsprintf(str, format, args);
 __builtin_va_end(args);
 for (p = str; *p; p++)
  glutBitmapCharacter(font, *p);
}

variable_types:
font
void *

variable_types:
format
char *

variable_types:
str
char [512]

variable_types:
p
char *


decompiled_code:
int __fastcall gl_draw_fps(float a1, float a2)
{
int v2; // ebx
clock_t v3; // rax

v2 = ++nr_frames_2;
v3 = clock();
if ( v3 - ticks_1 > 999999 )
{
fps_0 = v2;
ticks_1 = v3;
nr_frames_2 = 0;
}
glRasterPos2f(a1, a2);
return gl_printf((__int64)&glutBitmapHelvetica18, "%d fps", (unsigned int)fps_0);
}

canonical_decompiled_code:
int __fastcall func5(float a1, float a2)
{
int v2; // ebx
clock_t v3; // rax

v2 = ++nr_frames_2;
v3 = clock();
if ( v3 - ticks_1 > 999999 )
{
fps_0 = v2;
ticks_1 = v3;
nr_frames_2 = 0;
}
glRasterPos2f(a1, a2);
return func4((__int64)&glutBitmapHelvetica18, "%d fps", (unsigned int)fps_0);
}

original_code:
void gl_draw_fps(float x, float y)
{
 static clock_t ticks;
 static int nr_frames, fps;
 clock_t now;
 nr_frames++;
 now = clock();
 if (now - ticks >= ((__clock_t) 1000000)) {
  fps = nr_frames;
  ticks = now;
  nr_frames = 0;
 }
 glRasterPos2f(x, y);
 gl_printf(((void *) &glutBitmapHelvetica18), "%d fps", fps);
}

canonical_original_code:
void gl_draw_fps(float x, float y)
{
 static long ticks;
 static int nr_frames; static int fps;
 long now;
 nr_frames++;
 now = clock();
 if (now - ticks >= ((long) 1000000)) {
  fps = nr_frames;
  ticks = now;
  nr_frames = 0;
 }
 glRasterPos2f(x, y);
 gl_printf(((void *) &glutBitmapHelvetica18), "%d fps", fps);
}

variable_types: x float

variable_types: y float

variable_types: ticks long

variable_types: fps int

variable_types: now long


original_code:
static inline void vec_add(vector r, const vector a, const vector b)
{
 r[0] = a[0] + b[0];
 r[1] = a[1] + b[1];
 r[2] = a[2] + b[2];
}

variable_types:
r
float [3]

variable_types:
a
float [3]

variable_types:
b
float [3]


original_code:
static inline void vec_sub(vector r, const vector a, const vector b)
{
 r[0] = a[0] - b[0];
 r[1] = a[1] - b[1];
 r[2] = a[2] - b[2];
}


original_code:
static inline void vec_mul(vector r, float f, const vector a)
{
 r[0] = f * a[0];
 r[1] = f * a[1];
 r[2] = f * a[2];
}

canonical_original_code:
static inline void vec_mul(float r[3], float f, float a[3])
{
 r[0] = f * a[0];
 r[1] = f * a[1];
 r[2] = f * a[2];
}

variable_types: f float


decompiled_code:
float __fastcall vec_dot(float *a1, float *a2)
{
return (float)((float)(*a1 * *a2) + (float)(a1[1] * a2[1])) + (float)(a1[2] * a2[2]);
}

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

original_code:
static inline float vec_dot(const vector a, const vector b)
{
 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}

canonical_original_code:
static inline float vec_dot(float a[3], float b[3])
{
 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}

return_type: float


original_code:
static inline void vec_cross(vector r, const vector a, const vector b)
{
 r[0] = a[1] * b[2] - a[2] * b[1];
 r[1] = a[2] * b[0] - a[0] * b[2];
 r[2] = a[0] * b[1] - a[1] * b[0];
}


decompiled_code:
float __fastcall vec_len(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = vec_dot(a1, a1);
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

canonical_decompiled_code:
float __fastcall func5(float *a1)
{
float v1; // xmm0_4
float result; // xmm0_4

v1 = func3(a1, a1);
if ( v1 < 0.0 )
result = sqrtf(v1);
else
result = fsqrt(v1);
return result;
}

original_code:
static inline float vec_len(const vector a)
{
 return sqrtf(vec_dot(a, a));
}

canonical_original_code:
static inline float vec_len(float a[3])
{
 return sqrtf(vec_dot(a, a));
}


decompiled_code:
void __fastcall vec_normalize(float *a1, float *a2)
{
float v2; // xmm1_4

v2 = vec_len(a2);
vec_mul(a1, a2, 1.0 / v2);
}

canonical_decompiled_code:
void __fastcall func6(float *a1, float *a2)
{
float v2; // xmm1_4

v2 = func5(a2);
func2(a1, a2, 1.0 / v2);
}

original_code:
static inline void vec_normalize(vector r, const vector a)
{
 vec_mul(r, 1.0f / vec_len(a), a);
}

canonical_original_code:
static inline void vec_normalize(float r[3], float a[3])
{
 vec_mul(r, 1.0f / vec_len(a), a);
}


decompiled_code:
_QWORD *mesh_create()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func7()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
return result;
}

original_code:
struct mesh *mesh_create(void)
{
 struct mesh *mesh = malloc(sizeof(*mesh));
 mesh->vbuf = ((void *)0);
 mesh->nbuf = ((void *)0);
 mesh->ibuf = ((void *)0);
 mesh->faces = ((void *)0);
 return mesh;
}

canonical_original_code:
struct mesh *mesh_create()
{
 struct mesh *mesh = malloc(sizeof(*mesh));
 mesh->vbuf = ((void *)0);
 mesh->nbuf = ((void *)0);
 mesh->ibuf = ((void *)0);
 mesh->faces = ((void *)0);
 return mesh;
}

variable_types: struct mesh { float *vbuf; float *nbuf; struct idx { int vi; } *ibuf; int *faces; } *

user_defined_types: struct mesh { float *vbuf; float *nbuf; struct idx *ibuf; int *faces; }


decompiled_code:
void __fastcall mesh_free(void *ptr)
{
__int64 v2; // rdi
__int64 v3; // rdi
__int64 v4; // rdi
__int64 v5; // rdi

if ( ptr )
{
v2 = *(_QWORD *)ptr;
if ( v2 )
free((void *)(v2 - 16));
v3 = *((_QWORD *)ptr + 1);
if ( v3 )
free((void *)(v3 - 16));
v4 = *((_QWORD *)ptr + 2);
if ( v4 )
free((void *)(v4 - 16));
v5 = *((_QWORD *)ptr + 3);
if ( v5 )
free((void *)(v5 - 16));
free(ptr);
}
}

original_code:
void mesh_free(struct mesh *mesh)
{
 if (!mesh)
  return;
 ((mesh->vbuf) ? free(((size_t *) (mesh->vbuf) - 2)) : (void) 0);
 ((mesh->nbuf) ? free(((size_t *) (mesh->nbuf) - 2)) : (void) 0);
 ((mesh->ibuf) ? free(((size_t *) (mesh->ibuf) - 2)) : (void) 0);
 ((mesh->faces) ? free(((size_t *) (mesh->faces) - 2)) : (void) 0);
 free(mesh);
}

canonical_original_code:
void mesh_free(struct mesh *mesh)
{
 if (!mesh)
  return;
 ((mesh->vbuf) ? free(((unsigned long *) (mesh->vbuf) - 2)) : (void) 0);
 ((mesh->nbuf) ? free(((unsigned long *) (mesh->nbuf) - 2)) : (void) 0);
 ((mesh->ibuf) ? free(((unsigned long *) (mesh->ibuf) - 2)) : (void) 0);
 ((mesh->faces) ? free(((unsigned long *) (mesh->faces) - 2)) : (void) 0);
 free(mesh);
}


decompiled_code:
void mesh_end_face()
{
;
}

canonical_decompiled_code:
void func12()
{
;
}

original_code:
void mesh_end_face(struct mesh *mesh)
{
}


decompiled_code:
unsigned __int64 __fastcall mesh_vertex_buffer(_QWORD *a1, _QWORD *a2)
{
unsigned __int64 result; // rax

if ( a2 )
*a2 = *a1;
result = 0LL;
if ( *a1 )
result = *(_QWORD *)(*a1 - 8LL) / 3uLL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func13(_QWORD *a1, _QWORD *a2)
{
unsigned __int64 result; // rax

if ( a2 )
*a2 = *a1;
result = 0LL;
if ( *a1 )
result = *(_QWORD *)(*a1 - 8LL) / 3uLL;
return result;
}

original_code:
int mesh_vertex_buffer(const struct mesh *mesh, const float **buf)
{
 if (buf)
  *buf = mesh->vbuf;
 return ((mesh->vbuf) ? (((size_t *) (mesh->vbuf) - 2)[1]) : 0) / 3;
}

canonical_original_code:
int mesh_vertex_buffer(struct mesh *mesh, float **buf)
{
 if (buf)
  *buf = mesh->vbuf;
 return ((mesh->vbuf) ? (((unsigned long *) (mesh->vbuf) - 2)[1]) : 0) / 3;
}

variable_types:
buf
float **


decompiled_code:
unsigned __int64 __fastcall mesh_normal_buffer(__int64 a1, _QWORD *a2)
{
__int64 v2; // rdx
unsigned __int64 result; // rax

if ( a2 )
*a2 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 8);
result = 0LL;
if ( v2 )
result = *(_QWORD *)(v2 - 8) / 3uLL;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func14(__int64 a1, _QWORD *a2)
{
__int64 v2; // rdx
unsigned __int64 result; // rax

if ( a2 )
*a2 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 8);
result = 0LL;
if ( v2 )
result = *(_QWORD *)(v2 - 8) / 3uLL;
return result;
}

original_code:
int mesh_normal_buffer(const struct mesh *mesh, const float **buf)
{
 if (buf)
  *buf = mesh->nbuf;
 return ((mesh->nbuf) ? (((size_t *) (mesh->nbuf) - 2)[1]) : 0) / 3;
}

canonical_original_code:
int mesh_normal_buffer(struct mesh *mesh, float **buf)
{
 if (buf)
  *buf = mesh->nbuf;
 return ((mesh->nbuf) ? (((unsigned long *) (mesh->nbuf) - 2)[1]) : 0) / 3;
}


decompiled_code:
__int64 __fastcall mesh_face_count(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 24);
result = 0LL;
if ( v1 )
result = *(unsigned int *)(v1 - 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 v1; // rdx
__int64 result; // rax

v1 = *(_QWORD *)(a1 + 24);
result = 0LL;
if ( v1 )
result = *(unsigned int *)(v1 - 8);
return result;
}

original_code:
int mesh_face_count(const struct mesh *mesh)
{
 return ((mesh->faces) ? (((size_t *) (mesh->faces) - 2)[1]) : 0);
}

canonical_original_code:
int mesh_face_count(struct mesh *mesh)
{
 return ((mesh->faces) ? (((unsigned long *) (mesh->faces) - 2)[1]) : 0);
}


original_code:
int mesh_face_vertex_count(const struct mesh *mesh, int face)
{
 int beg, end;
 beg = mesh->faces[face];
 end = face != ((mesh->faces) ? (((size_t *) (mesh->faces) - 2)[1]) : 0) - 1 ?
  mesh->faces[face + 1] : ((mesh->ibuf) ? (((size_t *) (mesh->ibuf) - 2)[1]) : 0);
 return end - beg;
}

canonical_original_code:
int mesh_face_vertex_count(struct mesh *mesh, int face)
{
 int beg; int end;
 beg = mesh->faces[face];
 end = face != ((mesh->faces) ? (((unsigned long *) (mesh->faces) - 2)[1]) : 0) - 1 ?
  mesh->faces[face + 1] : ((mesh->ibuf) ? (((unsigned long *) (mesh->ibuf) - 2)[1]) : 0);
 return end - beg;
}

variable_types: face int

variable_types: beg int

variable_types: end int


decompiled_code:
__int64 __fastcall mesh_get_vertex(_QWORD *a1, int a2, int a3)
{
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

mesh_face_vertex_index((__int64)a1, a2, a3, v5, &v4);
return *a1 + 12LL * v5[0];
}

canonical_decompiled_code:
__int64 __fastcall func18(_QWORD *a1, int a2, int a3)
{
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

func17((__int64)a1, a2, a3, v5, &v4);
return *a1 + 12LL * v5[0];
}

original_code:
float *mesh_get_vertex(const struct mesh *mesh, int face, int vert)
{
 int vi, ni;
 mesh_face_vertex_index(mesh, face, vert, &vi, &ni);
 return &mesh->vbuf[vi * 3];
}

canonical_original_code:
float *mesh_get_vertex(struct mesh *mesh, int face, int vert)
{
 int vi; int ni;
 mesh_face_vertex_index(mesh, face, vert, &vi, &ni);
 return &mesh->vbuf[vi * 3];
}

variable_types: vert int

variable_types: vi int

variable_types: ni int

return_type: float *


decompiled_code:
__int64 __fastcall mesh_get_normal(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

mesh_face_vertex_index(a1, a2, a3, v5, &v4);
if ( v4 == -1 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 8) + 12LL * v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // [rsp+8h] [rbp-10h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

func17(a1, a2, a3, v5, &v4);
if ( v4 == -1 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 8) + 12LL * v4;
return result;
}

original_code:
float *mesh_get_normal(const struct mesh *mesh, int face, int vert)
{
 int vi, ni;
 mesh_face_vertex_index(mesh, face, vert, &vi, &ni);
 return ni != -1 ? &mesh->nbuf[ni * 3] : ((void *)0);
}

canonical_original_code:
float *mesh_get_normal(struct mesh *mesh, int face, int vert)
{
 int vi; int ni;
 mesh_face_vertex_index(mesh, face, vert, &vi, &ni);
 return ni != -1 ? &mesh->nbuf[ni * 3] : ((void *)0);
}


decompiled_code:
char *__fastcall skip_space(char *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
return a1;
}

canonical_decompiled_code:
char *__fastcall func0(char *a1)
{
const unsigned __int16 *v2; // rdx

v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
return a1;
}

original_code:
static const char *skip_space(const char *str)
{
 while (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace))
  str++;
 return str;
}

canonical_original_code:
static char *skip_space(char *str)
{
 while (((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace))
  str++;
 return str;
}

variable_types:
str
char *

return_type: char *


minf

decompiled_code:
float __fastcall minf(float a1, float a2)
{
return fminf(a1, a2);
}

canonical_decompiled_code:
float __fastcall func0(float a1, float a2)
{
return fminf(a1, a2);
}

original_code:
static inline float minf(float a, float b)
{
 return a < b ? a : b;
}

variable_types: a float

variable_types: b float


maxf

original_code:
static inline float maxf(float a, float b)
{
 return a < b ? b : a;
}


original_code:
static inline void vec_neg(vector r, const vector a)
{
 r[0] = -a[0];
 r[1] = -a[1];
 r[2] = -a[2];
}

canonical_original_code:
static inline void vec_neg(float r[3], float a[3])
{
 r[0] = -a[0];
 r[1] = -a[1];
 r[2] = -a[2];
}


original_code:
static inline void vec_min(vector r, const vector a, const vector b)
{
 r[0] = minf(a[0], b[0]);
 r[1] = minf(a[1], b[1]);
 r[2] = minf(a[2], b[2]);
}

canonical_original_code:
static inline void vec_min(float r[3], float a[3], float b[3])
{
 r[0] = minf(a[0], b[0]);
 r[1] = minf(a[1], b[1]);
 r[2] = minf(a[2], b[2]);
}


original_code:
static inline void vec_max(vector r, const vector a, const vector b)
{
 r[0] = maxf(a[0], b[0]);
 r[1] = maxf(a[1], b[1]);
 r[2] = maxf(a[2], b[2]);
}

canonical_original_code:
static inline void vec_max(float r[3], float a[3], float b[3])
{
 r[0] = maxf(a[0], b[0]);
 r[1] = maxf(a[1], b[1]);
 r[2] = maxf(a[2], b[2]);
}


repo: skeezix/libpnd-clone

decompiled_code:
__int64 __fastcall pnd_notify_callback(const char *filename, const struct stat *status, int flag, struct FTW *info)
{
if ( (flag & 1) == 0 )
return 0LL;
inotify_add_watch(notify_handle, filename, 0x2FC8u);
if ( (unsigned __int8)pnd_log_do_buried_logging() )
pnd_log(0LL, "notify callback: added watch on %s\n", filename);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *filename, const struct stat *status, int flag, struct FTW *info)
{
if ( (flag & 1) == 0 )
return 0LL;
inotify_add_watch(notify_handle, filename, 0x2FC8u);
if ( (unsigned __int8)pnd_log_do_buried_logging() )
pnd_log(0LL, "notify callback: added watch on %s\n", filename);
return 0LL;
}

original_code:
static int pnd_notify_callback ( const char *fpath, const struct stat *sb,
     int typeflag, struct FTW *ftwbuf )
{
  if ( ! ( typeflag & FTW_D ) ) {
    return ( 0 );
  }
  inotify_add_watch ( notify_handle, fpath, 0x00000100 | 0x00000200 | 0x00002000 | 0x00000400 | 0x00000800 | 0x00000040 | 0x00000080 | 0x00000008 );
  if ( pnd_log_do_buried_logging() ) {
    pnd_log ( 0, "notify callback: added watch on %s\n", fpath );
  }
  return ( 0 );
}

canonical_original_code:
static int pnd_notify_callback(char *fpath, struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
  if ( ! ( typeflag & FTW_D ) ) {
    return ( 0 );
  }
  inotify_add_watch ( notify_handle, fpath, 0x00000100 | 0x00000200 | 0x00002000 | 0x00000400 | 0x00000800 | 0x00000040 | 0x00000080 | 0x00000008 );
  if ( pnd_log_do_buried_logging() ) {
    pnd_log ( 0, "notify callback: added watch on %s\n", fpath );
  }
  return ( 0 );
}

variable_types:
fpath
char *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *

variable_types: typeflag int

variable_types:
ftwbuf
struct FTW { int base; int level; } *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
_DWORD *pnd_notify_init()
{
int v0; // eax
_DWORD *v1; // rbx
int v2; // ebp
_DWORD *v3; // rax

v0 = inotify_init();
v1 = 0LL;
if ( v0 >= 0 )
{
v2 = v0;
v3 = malloc(4uLL);
v1 = v3;
if ( v3 )
*v3 = v2;
else
close(v2);
}
return v1;
}

canonical_decompiled_code:
_DWORD *func1()
{
int v0; // eax
_DWORD *v1; // rbx
int v2; // ebp
_DWORD *v3; // rax

v0 = inotify_init();
v1 = 0LL;
if ( v0 >= 0 )
{
v2 = v0;
v3 = malloc(4uLL);
v1 = v3;
if ( v3 )
*v3 = v2;
else
close(v2);
}
return v1;
}

original_code:
pnd_notify_handle pnd_notify_init ( void ) {
  int fd;
  pnd_notify_t *p;
  fd = inotify_init();
  if ( fd < 0 ) {
    return ( ((void *)0) );
  }
  p = malloc ( sizeof(pnd_notify_t) );
  if ( ! p ) {
    close ( fd );
    return ( ((void *)0) );
  }
  p -> fd = fd;
  return ( p );
}

canonical_original_code:
void *pnd_notify_init() {
  int fd;
  struct pnd_notify_t *p;
  fd = inotify_init();
  if ( fd < 0 ) {
    return ( ((void *)0) );
  }
  p = malloc ( sizeof(pnd_notify_t) );
  if ( ! p ) {
    close ( fd );
    return ( ((void *)0) );
  }
  p -> fd = fd;
  return ( p );
}

variable_types: fd int

variable_types:
p
struct pnd_notify_t { int fd; } *

return_type: void *


decompiled_code:
void __fastcall pnd_notify_shutdown(void *ptr)
{
close(*(_DWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
close(*(_DWORD *)ptr);
free(ptr);
}

original_code:
void pnd_notify_shutdown ( pnd_notify_handle h ) {
  pnd_notify_t *p = (pnd_notify_t*) h;
  close ( p -> fd );
  free ( p );
  return;
}

canonical_original_code:
void pnd_notify_shutdown(void *h) {
  struct pnd_notify_t *p = (pnd_notify_t*) h;
  close ( p -> fd );
  free ( p );
  return;
}

variable_types:
h
void *


decompiled_code:
int __fastcall pnd_notify_watch_path(int *a1, const char *a2, char a3)
{
int result; // eax

result = inotify_add_watch(*a1, a2, 0x2FC8u);
if ( (a3 & 1) != 0 )
{
notify_handle = *a1;
result = nftw(a2, (__nftw_func_t)pnd_notify_callback, 10, 1);
notify_handle = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(int *a1, const char *a2, char a3)
{
int result; // eax

result = inotify_add_watch(*a1, a2, 0x2FC8u);
if ( (a3 & 1) != 0 )
{
notify_handle = *a1;
result = nftw(a2, (__nftw_func_t)pnd_notify_callback, 10, 1);
notify_handle = -1;
}
return result;
}

original_code:
void pnd_notify_watch_path ( pnd_notify_handle h, char *fullpath, unsigned int flags ) {
  pnd_notify_t *p = (pnd_notify_t*) h;
  inotify_add_watch ( p -> fd, fullpath, 0x00000100 | 0x00000200 | 0x00002000 | 0x00000400 | 0x00000800 | 0x00000040 | 0x00000080 | 0x00000008 );
  if ( flags & 1 ) {
    notify_handle = p -> fd;
    nftw ( fullpath,
    pnd_notify_callback,
    10,
    FTW_PHYS );
    notify_handle = -1;
  }
  return;
}

canonical_original_code:
void pnd_notify_watch_path(void *h, char *fullpath, unsigned int flags) {
  struct pnd_notify_t *p = (pnd_notify_t*) h;
  inotify_add_watch ( p -> fd, fullpath, 0x00000100 | 0x00000200 | 0x00002000 | 0x00000400 | 0x00000800 | 0x00000040 | 0x00000080 | 0x00000008 );
  if ( flags & 1 ) {
    notify_handle = p -> fd;
    nftw ( fullpath,
    pnd_notify_callback,
    10,
    FTW_PHYS );
    notify_handle = -1;
  }
  return;
}

variable_types:
fullpath
char *

variable_types:
flags
unsigned int


decompiled_code:
__int64 __fastcall pnd_notify_rediscover_p(int *a1)
{
int v2; // edi
int v3; // edx
__int64 result; // rax
int v5; // edi
int v6; // edx
unsigned int v7; // er12
unsigned int i; // ebp
_BYTE *v9; // rbx
_BYTE v10[4608]; // [rsp+0h] [rbp-12B8h] BYREF
fd_set readfds; // [rsp+1200h] [rbp-B8h] BYREF
struct timeval timeout; // [rsp+1280h] [rbp-38h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 5000LL;
memset(&readfds, 0, sizeof(readfds));
v2 = *a1;
readfds.fds_bits[v2 / 64] |= 1LL << (v2 % 64);
v3 = select(v2 + 1, &readfds, 0LL, 0LL, &timeout);
result = 0LL;
if ( v3 > 0 )
{
v5 = *a1;
result = 0LL;
if ( (readfds.fds_bits[v5 / 64] & (1LL << (v5 % 64))) != 0 )
{
v6 = read(v5, v10, 0x11F8uLL);
result = 0LL;
if ( v6 > 0 )
{
v7 = v6;
for ( i = 0; i < v7; i += *((_DWORD *)v9 + 3) + 16 )
{
v9 = &v10[i];
if ( (unsigned __int8)pnd_log_do_buried_logging() )
pnd_log(
0LL,
"notify: Got event against '%s' [%u %x]\n",
v9 + 16,
*((unsigned int *)v9 + 1),
*((unsigned int *)v9 + 1));
}
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int *a1)
{
int v2; // edi
int v3; // edx
__int64 result; // rax
int v5; // edi
int v6; // edx
unsigned int v7; // er12
unsigned int i; // ebp
_BYTE *v9; // rbx
_BYTE v10[4608]; // [rsp+0h] [rbp-12B8h] BYREF
fd_set readfds; // [rsp+1200h] [rbp-B8h] BYREF
struct timeval timeout; // [rsp+1280h] [rbp-38h] BYREF

timeout.tv_sec = 0LL;
timeout.tv_usec = 5000LL;
memset(&readfds, 0, sizeof(readfds));
v2 = *a1;
readfds.fds_bits[v2 / 64] |= 1LL << (v2 % 64);
v3 = select(v2 + 1, &readfds, 0LL, 0LL, &timeout);
result = 0LL;
if ( v3 > 0 )
{
v5 = *a1;
result = 0LL;
if ( (readfds.fds_bits[v5 / 64] & (1LL << (v5 % 64))) != 0 )
{
v6 = read(v5, v10, 0x11F8uLL);
result = 0LL;
if ( v6 > 0 )
{
v7 = v6;
for ( i = 0; i < v7; i += *((_DWORD *)v9 + 3) + 16 )
{
v9 = &v10[i];
if ( (unsigned __int8)pnd_log_do_buried_logging() )
pnd_log(
0LL,
"notify: Got event against '%s' [%u %x]\n",
v9 + 16,
*((unsigned int *)v9 + 1),
*((unsigned int *)v9 + 1));
}
result = 1LL;
}
}
}
return result;
}

original_code:
unsigned char pnd_notify_rediscover_p ( pnd_notify_handle h ) {
  pnd_notify_t *p = (pnd_notify_t*) h;
  struct timeval t;
  fd_set rfds;
  int retcode;
  t.tv_sec = 0;
  t.tv_usec = 5000;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfds)->__fds_bits)[(((p->fd)) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << (((p->fd)) % (8 * (int) sizeof (__fd_mask)))))));
  retcode = select ( (p->fd) + 1, &rfds, ((void *)0), ((void *)0), &t );
  if ( retcode < 0 ) {
    return ( 0 );
  } else if ( retcode == 0 ) {
    return ( 0 );
  }
  if ( ! ((((&rfds)->__fds_bits)[(((p->fd)) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << (((p->fd)) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
    return ( 0 );
  }
  unsigned char binbuf [ ( 100 * ( sizeof(struct inotify_event) + 30 ) ) ];
  int actuallen;
  actuallen = read ( (p->fd), binbuf, ( 100 * ( sizeof(struct inotify_event) + 30 ) ) );
  if ( actuallen < 0 ) {
    return ( 0 );
  } else if ( actuallen == 0 ) {
    return ( 0 );
  }
  unsigned int i = 0;
  struct inotify_event *e;
  while ( i < actuallen ) {
    e = (struct inotify_event *) &binbuf [ i ];
    if ( pnd_log_do_buried_logging() ) {
      pnd_log ( 0, "notify: Got event against '%s' [%u %x]\n", e -> name, e -> mask, e -> mask );
    }
    i += ( sizeof(struct inotify_event) + e -> len );
  }
  return ( 1 );
}

canonical_original_code:
unsigned char pnd_notify_rediscover_p(void *h) {
  struct pnd_notify_t *p = (pnd_notify_t*) h;
  struct timeval t;
  struct fd_set rfds;
  int retcode;
  t.tv_sec = 0;
  t.tv_usec = 5000;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&rfds)->__fds_bits)[(((p->fd)) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << (((p->fd)) % (8 * (int) sizeof (__fd_mask)))))));
  retcode = select ( (p->fd) + 1, &rfds, ((void *)0), ((void *)0), &t );
  if ( retcode < 0 ) {
    return ( 0 );
  } else if ( retcode == 0 ) {
    return ( 0 );
  }
  if ( ! ((((&rfds)->__fds_bits)[(((p->fd)) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << (((p->fd)) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
    return ( 0 );
  }
  unsigned char binbuf[-1];
  int actuallen;
  actuallen = read ( (p->fd), binbuf, ( 100 * ( sizeof(struct inotify_event) + 30 ) ) );
  if ( actuallen < 0 ) {
    return ( 0 );
  } else if ( actuallen == 0 ) {
    return ( 0 );
  }
  unsigned int i = 0;
  struct inotify_event *e;
  while ( i < actuallen ) {
    e = (struct inotify_event *) &binbuf [ i ];
    if ( pnd_log_do_buried_logging() ) {
      pnd_log ( 0, "notify: Got event against '%s' [%u %x]\n", e -> name, e -> mask, e -> mask );
    }
    i += ( sizeof(struct inotify_event) + e -> len );
  }
  return ( 1 );
}

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

variable_types:
rfds
struct fd_set { long __fds_bits[-1]; }

variable_types: retcode int

variable_types:
binbuf
unsigned char [-1]

variable_types: actuallen int

variable_types:
i
unsigned int

variable_types: struct inotify_event { int wd; unsigned int mask; unsigned int cookie; unsigned int len; char name[]; } *

return_type: unsigned char


decompiled_code:
__int64 __fastcall pnd_notify_wait_until_ready(unsigned int a1)
{
time_t v1; // rbp

v1 = time(0LL);
while ( 1 )
{
if ( a1 && time(0LL) - v1 >= a1 )
return 0LL;
if ( (unsigned __int8)inotify_test_run() )
break;
usleep(0x7A120u);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
time_t v1; // rbp

v1 = time(0LL);
while ( 1 )
{
if ( a1 && time(0LL) - v1 >= a1 )
return 0LL;
if ( (unsigned __int8)func5() )
break;
usleep(0x7A120u);
}
return 1LL;
}

original_code:
unsigned char pnd_notify_wait_until_ready ( unsigned int secs_timeout ) {
  time_t start = time ( ((void *)0) );
  while ( ( secs_timeout == 0 ) ||
   ( time ( ((void *)0) ) - start < secs_timeout ) )
  {
    if ( _inotify_test_run() ) {
      return ( 1 );
    }
    usleep ( 1000000 / 2 );
  }
  return ( 0 );
}

canonical_original_code:
unsigned char pnd_notify_wait_until_ready(unsigned int secs_timeout) {
  long start = time ( ((void *)0) );
  while ( ( secs_timeout == 0 ) ||
   ( time ( ((void *)0) ) - start < secs_timeout ) )
  {
    if ( _inotify_test_run() ) {
      return ( 1 );
    }
    usleep ( 1000000 / 2 );
  }
  return ( 0 );
}

variable_types: start long


decompiled_code:
char *mmcustom_determine_path()
{
char *v0; // rdx

v0 = getenv("HOME");
memset(path_0, 0, sizeof(path_0));
if ( !v0 )
v0 = (char *)&LC0;
snprintf(path_0, 0xFFFuLL, "%s/%s", v0, ".mmcats.conf");
return path_0;
}

canonical_decompiled_code:
char *func0()
{
char *v0; // rdx

v0 = getenv("HOME");
memset(path_0, 0, sizeof(path_0));
if ( !v0 )
v0 = (char *)&LC0;
snprintf(path_0, 0xFFFuLL, "%s/%s", v0, ".mmcats.conf");
return path_0;
}

original_code:
char *mmcustom_determine_path ( void ) {
  char *home = getenv ( "HOME" );
  static char path [ 4096 ];
  bzero ( path, 4096 );
  snprintf ( path, 4096 - 1, "%s/%s", home ? home : ".", ".mmcats.conf" );
  return ( path );
}

canonical_original_code:
char *mmcustom_determine_path() {
  char *home = getenv ( "HOME" );
  static char path[4096];
  bzero ( path, 4096 );
  snprintf ( path, 4096 - 1, "%s/%s", home ? home : ".", ".mmcats.conf" );
  return ( path );
}

variable_types:
home
char *

variable_types:
path
char [4096]


decompiled_code:
__int64 mmcustom_setup()
{
char *v1; // r13
const char *v2; // rbx
const char *v3; // rax
unsigned int v4; // er13

if ( loaded )
return 1LL;
loaded = 1;
v1 = mmcustom_determine_path();
g_custom_h = pnd_conf_fetch_by_path(v1);
if ( g_custom_h )
{
v2 = (const char *)pnd_box_get_head();
if ( v2 )
{
do
{
v3 = (const char *)pnd_box_get_key(v2);
if ( !memcmp(v3, "custom_categories", 0x11uLL) )
{
v4 = mmcustom_count;
mmcustom_complete[2 * v4] = strdup(v3 + 18);
if ( !strcmp(v2, "*parent*") )
mmcustom_complete[2 * v4 + 1] = 0LL;
else
mmcustom_complete[2 * v4 + 1] = strdup(v2);
mmcustom_count = v4 + 1;
}
v2 = (const char *)pnd_box_get_next(v2);
}
while ( v2 );
}
else
{
pnd_log(1LL, "Custom category conf file %s is empty. Fine.\n", v1);
}
}
else
{
pnd_log(1LL, "Custom category conf file %s not found; is okay.\n", v1);
}
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
char *v1; // r13
const char *v2; // rbx
const char *v3; // rax
unsigned int v4; // er13

if ( loaded )
return 1LL;
loaded = 1;
v1 = func0();
g_custom_h = pnd_conf_fetch_by_path(v1);
if ( g_custom_h )
{
v2 = (const char *)pnd_box_get_head();
if ( v2 )
{
do
{
v3 = (const char *)pnd_box_get_key(v2);
if ( !memcmp(v3, "custom_categories", 0x11uLL) )
{
v4 = mmcustom_count;
mmcustom_complete[2 * v4] = strdup(v3 + 18);
if ( !strcmp(v2, "*parent*") )
mmcustom_complete[2 * v4 + 1] = 0LL;
else
mmcustom_complete[2 * v4 + 1] = strdup(v2);
mmcustom_count = v4 + 1;
}
v2 = (const char *)pnd_box_get_next(v2);
}
while ( v2 );
}
else
{
pnd_log(1LL, "Custom category conf file %s is empty. Fine.\n", v1);
}
}
else
{
pnd_log(1LL, "Custom category conf file %s not found; is okay.\n", v1);
}
return 1LL;
}

original_code:
unsigned char mmcustom_setup ( void ) {
  if ( ! loaded ) {
    loaded = 1;
    char *path = mmcustom_determine_path();
    g_custom_h = pnd_conf_fetch_by_path ( path );
    if ( ! g_custom_h ) {
      pnd_log ( pndn_rem, "Custom category conf file %s not found; is okay.\n", path );
      return ( 1 );
    }
    char *iter = pnd_box_get_head ( g_custom_h );
    if ( ! iter ) {
      pnd_log ( pndn_rem, "Custom category conf file %s is empty. Fine.\n", path );
      return ( 1 );
    }
    while ( iter ) {
      char *k = pnd_box_get_key ( iter );
      if ( strncmp ( k, "custom_categories", strlen ( "custom_categories" ) ) == 0 ) {
 k += ( strlen ( "custom_categories" ) + 1 );
 mmcustom_complete [ mmcustom_count ].cat = strdup ( k );
 if ( iter && strcmp ( iter, "*parent*" ) != 0 ) {
   mmcustom_complete [ mmcustom_count ].parent_cat = strdup ( iter );
 } else {
   mmcustom_complete [ mmcustom_count ].parent_cat = ((void *)0);
 }
 mmcustom_count += 1;
      }
      iter = pnd_box_get_next ( iter );
    }
  }
  return ( 1 );
}

canonical_original_code:
unsigned char mmcustom_setup() {
  if ( ! loaded ) {
    loaded = 1;
    char *path = mmcustom_determine_path();
    g_custom_h = pnd_conf_fetch_by_path ( path );
    if ( ! g_custom_h ) {
      pnd_log ( pndn_rem, "Custom category conf file %s not found; is okay.\n", path );
      return ( 1 );
    }
    char *iter = pnd_box_get_head ( g_custom_h );
    if ( ! iter ) {
      pnd_log ( pndn_rem, "Custom category conf file %s is empty. Fine.\n", path );
      return ( 1 );
    }
    while ( iter ) {
      char *k = pnd_box_get_key ( iter );
      if ( strncmp ( k, "custom_categories", strlen ( "custom_categories" ) ) == 0 ) {
 k += ( strlen ( "custom_categories" ) + 1 );
 mmcustom_complete [ mmcustom_count ].cat = strdup ( k );
 if ( iter && strcmp ( iter, "*parent*" ) != 0 ) {
   mmcustom_complete [ mmcustom_count ].parent_cat = strdup ( iter );
 } else {
   mmcustom_complete [ mmcustom_count ].parent_cat = ((void *)0);
 }
 mmcustom_count += 1;
      }
      iter = pnd_box_get_next ( iter );
    }
  }
  return ( 1 );
}

variable_types:
path
char *

variable_types:
iter
char *

variable_types:
k
char *


decompiled_code:
_DWORD *mmcustom_shutdown()
{
_DWORD *result; // rax

memset(mmcustom_complete, 0, 0xFF0uLL);
result = mmcustom_count;
mmcustom_count[0] = 0;
loaded = 0;
return result;
}

canonical_decompiled_code:
_DWORD *func2()
{
_DWORD *result; // rax

memset(mmcustom_complete, 0, 0xFF0uLL);
result = mmcustom_count;
mmcustom_count[0] = 0;
loaded = 0;
return result;
}

original_code:
void mmcustom_shutdown ( void ) {
  bzero ( mmcustom_complete, sizeof(mmcustom_cat_t) * 255 );
  mmcustom_count = 0;
  loaded = 0;
  return;
}

canonical_original_code:
void mmcustom_shutdown() {
  bzero ( mmcustom_complete, sizeof(mmcustom_cat_t) * 255 );
  mmcustom_count = 0;
  loaded = 0;
  return;
}


decompiled_code:
__int64 mmcustom_is_ready()
{
return (unsigned __int8)loaded;
}

canonical_decompiled_code:
__int64 func3()
{
return (unsigned __int8)loaded;
}

original_code:
unsigned char mmcustom_is_ready ( void ) {
  return ( loaded );
}

canonical_original_code:
unsigned char mmcustom_is_ready() {
  return ( loaded );
}


decompiled_code:
__int64 __fastcall mmcustom_subcount(char *s2)
{
unsigned int v1; // ebp
const char **v2; // rbx
const char **v3; // r12

v1 = mmcustom_count[0];
if ( mmcustom_count[0] )
{
v2 = (const char **)&mmcustom_complete[1];
v3 = (const char **)&mmcustom_complete[2 * (unsigned int)(mmcustom_count[0] - 1) + 3];
v1 = 0;
do
{
if ( *v2 )
v1 += strcmp(*v2, s2) == 0;
v2 += 2;
}
while ( v2 != v3 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *s2)
{
unsigned int v1; // ebp
const char **v2; // rbx
const char **v3; // r12

v1 = mmcustom_count[0];
if ( mmcustom_count[0] )
{
v2 = (const char **)&mmcustom_complete[1];
v3 = (const char **)&mmcustom_complete[2 * (unsigned int)(mmcustom_count[0] - 1) + 3];
v1 = 0;
do
{
if ( *v2 )
v1 += strcmp(*v2, s2) == 0;
v2 += 2;
}
while ( v2 != v3 );
}
return v1;
}

original_code:
unsigned int mmcustom_subcount ( char *parentcatname ) {
  unsigned int counter = 0;
  int i;
  for ( i = 0; i < mmcustom_count; i++ ) {
    if ( mmcustom_complete [ i ].parent_cat &&
  strcmp ( mmcustom_complete [ i ].parent_cat, parentcatname ) == 0 )
    {
      counter++;
    }
  }
  return ( counter );
}

canonical_original_code:
unsigned int mmcustom_subcount(char *parentcatname) {
  unsigned int counter = 0;
  int i;
  for ( i = 0; i < mmcustom_count; i++ ) {
    if ( mmcustom_complete [ i ].parent_cat &&
  strcmp ( mmcustom_complete [ i ].parent_cat, parentcatname ) == 0 )
    {
      counter++;
    }
  }
  return ( counter );
}

variable_types:
parentcatname
char *

variable_types:
counter
unsigned int

variable_types: i int

return_type: unsigned int


decompiled_code:
__int64 __fastcall mmcustom_count_subcats(char *s2)
{
unsigned int v1; // ebp
const char **v2; // rbx
const char **v3; // r12

v1 = mmcustom_count[0];
if ( mmcustom_count[0] )
{
v2 = (const char **)&mmcustom_complete[1];
v3 = (const char **)&mmcustom_complete[2 * (unsigned int)(mmcustom_count[0] - 1) + 3];
v1 = 0;
do
{
if ( *v2 )
v1 += strcasecmp(*v2, s2) == 0;
v2 += 2;
}
while ( v2 != v3 );
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *s2)
{
unsigned int v1; // ebp
const char **v2; // rbx
const char **v3; // r12

v1 = mmcustom_count[0];
if ( mmcustom_count[0] )
{
v2 = (const char **)&mmcustom_complete[1];
v3 = (const char **)&mmcustom_complete[2 * (unsigned int)(mmcustom_count[0] - 1) + 3];
v1 = 0;
do
{
if ( *v2 )
v1 += strcasecmp(*v2, s2) == 0;
v2 += 2;
}
while ( v2 != v3 );
}
return v1;
}

original_code:
unsigned int mmcustom_count_subcats ( char *catname ) {
  int i;
  unsigned int counter = 0;
  for ( i = 0; i < mmcustom_count; i++ ) {
    if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, catname ) == 0 ) {
      counter++;
    }
  }
  return ( counter );
}

canonical_original_code:
unsigned int mmcustom_count_subcats(char *catname) {
  int i;
  unsigned int counter = 0;
  for ( i = 0; i < mmcustom_count; i++ ) {
    if ( mmcustom_complete [ i ].parent_cat && strcasecmp ( mmcustom_complete [ i ].parent_cat, catname ) == 0 ) {
      counter++;
    }
  }
  return ( counter );
}

variable_types:
catname
char *


decompiled_code:
__int64 pnd_log_empty_slot()
{
__int64 *v0; // rdx
unsigned int v1; // eax
unsigned int v2; // ecx

v0 = &log_targets;
v1 = 0;
while ( 1 )
{
v2 = v1;
if ( !*(_DWORD *)v0 )
break;
++v1;
v0 += 2;
if ( v1 == 5 )
return (unsigned int)-1;
}
return v2;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 *v0; // rdx
unsigned int v1; // eax
unsigned int v2; // ecx

v0 = &log_targets;
v1 = 0;
while ( 1 )
{
v2 = v1;
if ( !*(_DWORD *)v0 )
break;
++v1;
v0 += 2;
if ( v1 == 5 )
return (unsigned int)-1;
}
return v2;
}

original_code:
static int pnd_log_empty_slot ( void ) {
  unsigned char i;
  for ( i = 0; i < 5; i++ ) {
    if ( log_targets [ i ].type == pndl_nil ) {
      return ( i );
    }
  }
  return ( -1 );
}

canonical_original_code:
static int pnd_log_empty_slot() {
  unsigned char i;
  for ( i = 0; i < 5; i++ ) {
    if ( log_targets [ i ].type == pndl_nil ) {
      return ( i );
    }
  }
  return ( -1 );
}

variable_types:
i
unsigned char


decompiled_code:
void __fastcall pnd_log_emit(unsigned __int8 a1, const char *a2)
{
__int64 *v2; // rbx
int v3; // eax

v2 = &log_targets;
do
{
if ( *(_DWORD *)v2 == 1 )
{
if ( log_pretext )
fprintf((FILE *)v2[1], "%s ", (const char *)log_pretext);
v3 = time(0LL);
fprintf((FILE *)v2[1], "%u %u\t", a1, (unsigned int)(v3 - log_first));
if ( a2 )
{
fputs(a2, (FILE *)v2[1]);
if ( !strchr(a2, 10) )
fputc(10, (FILE *)v2[1]);
if ( log_flushafter )
fflush((FILE *)v2[1]);
}
}
v2 += 2;
}
while ( v2 != &log_targets + 10 );
}

canonical_decompiled_code:
void __fastcall func8(unsigned __int8 a1, const char *a2)
{
__int64 *v2; // rbx
int v3; // eax

v2 = &log_targets;
do
{
if ( *(_DWORD *)v2 == 1 )
{
if ( log_pretext )
fprintf((FILE *)v2[1], "%s ", (const char *)log_pretext);
v3 = time(0LL);
fprintf((FILE *)v2[1], "%u %u\t", a1, (unsigned int)(v3 - log_first));
if ( a2 )
{
fputs(a2, (FILE *)v2[1]);
if ( !strchr(a2, 10) )
fputc(10, (FILE *)v2[1]);
if ( log_flushafter )
fflush((FILE *)v2[1]);
}
}
v2 += 2;
}
while ( v2 != &log_targets + 10 );
}

original_code:
static void pnd_log_emit ( unsigned char level, char *message ) {
  unsigned char i;
  for ( i = 0; i < 5; i++ ) {
    switch ( log_targets [ i ].type ) {
    case pndl_nil:
      break;
    case pndl_stream:
      if ( log_pretext ) {
 fprintf ( log_targets [ i ].stream, "%s ", log_pretext );
      }
      fprintf ( log_targets [ i ].stream, "%u %u\t", level, (unsigned int) (time ( ((void *)0) ) - log_first) );
      if ( message ) {
 fprintf ( log_targets [ i ].stream, "%s", message );
 if ( strchr ( message, '\n' ) == ((void *)0) ) {
   fprintf ( log_targets [ i ].stream, "\n" );
 }
 if ( log_flushafter ) {
   fflush ( log_targets [ i ].stream );
 }
      }
      break;
    case pndl_syslog:
      break;
    case pndl_callback:
      break;
    }
  }
  return;
}

canonical_original_code:
static void pnd_log_emit(unsigned char level, char *message) {
  unsigned char i;
  for ( i = 0; i < 5; i++ ) {
    switch ( log_targets [ i ].type ) {
    case pndl_nil:
      break;
    case pndl_stream:
      if ( log_pretext ) {
 fprintf ( log_targets [ i ].stream, "%s ", log_pretext );
      }
      fprintf ( log_targets [ i ].stream, "%u %u\t", level, (unsigned int) (time ( ((void *)0) ) - log_first) );
      if ( message ) {
 fprintf ( log_targets [ i ].stream, "%s", message );
 if ( strchr ( message, '\n' ) == ((void *)0) ) {
   fprintf ( log_targets [ i ].stream, "\n" );
 }
 if ( log_flushafter ) {
   fflush ( log_targets [ i ].stream );
 }
      }
      break;
    case pndl_syslog:
      break;
    case pndl_callback:
      break;
    }
  }
  return;
}

variable_types:
level
unsigned char

variable_types:
message
char *


decompiled_code:
__int64 __fastcall pnd_log_set_filter(char a1)
{
__int64 result; // rax

result = (unsigned __int8)log_filterlevel;
log_filterlevel = a1;
return result;
}

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

result = (unsigned __int8)log_filterlevel;
log_filterlevel = a1;
return result;
}

original_code:
unsigned char pnd_log_set_filter ( unsigned char newlevel ) {
  unsigned char foo = log_filterlevel;
  log_filterlevel = newlevel;
  return ( foo );
}

canonical_original_code:
unsigned char pnd_log_set_filter(unsigned char newlevel) {
  unsigned char foo = log_filterlevel;
  log_filterlevel = newlevel;
  return ( foo );
}

variable_types:
newlevel
unsigned char

variable_types:
foo
unsigned char


decompiled_code:
__int64 pnd_log_get_filter()
{
return (unsigned __int8)log_filterlevel;
}

canonical_decompiled_code:
__int64 func10()
{
return (unsigned __int8)log_filterlevel;
}

original_code:
unsigned char pnd_log_get_filter ( void ) {
  return ( log_filterlevel );
}

canonical_original_code:
unsigned char pnd_log_get_filter() {
  return ( log_filterlevel );
}


decompiled_code:
void __fastcall pnd_log_set_flush(char a1)
{
log_flushafter = a1;
}

canonical_decompiled_code:
void __fastcall func11(char a1)
{
log_flushafter = a1;
}

original_code:
void pnd_log_set_flush ( unsigned char x ) {
  log_flushafter = x;
  return;
}

canonical_original_code:
void pnd_log_set_flush(unsigned char x) {
  log_flushafter = x;
  return;
}

variable_types:
x
unsigned char


decompiled_code:
void __fastcall pnd_log_set_pretext(char *s)
{
if ( log_pretext )
{
free(log_pretext);
log_pretext = 0LL;
}
if ( s )
log_pretext = strdup(s);
}

canonical_decompiled_code:
void __fastcall func12(char *s)
{
if ( log_pretext )
{
free(log_pretext);
log_pretext = 0LL;
}
if ( s )
log_pretext = strdup(s);
}

original_code:
void pnd_log_set_pretext ( char *pre ) {
  if ( log_pretext ) {
    free ( log_pretext );
    log_pretext = ((void *)0);
  }
  if ( pre ) {
    log_pretext = strdup ( pre );
  }
  return;
}

canonical_original_code:
void pnd_log_set_pretext(char *pre) {
  if ( log_pretext ) {
    free ( log_pretext );
    log_pretext = ((void *)0);
  }
  if ( pre ) {
    log_pretext = strdup ( pre );
  }
  return;
}

variable_types:
pre
char *


decompiled_code:
void pnd_log_to_nil()
{
log_targets = 0LL;
qword_4040C8 = 0LL;
qword_4040D0 = 0LL;
qword_4040D8 = 0LL;
qword_4040E0 = 0LL;
qword_4040E8 = 0LL;
qword_4040F0 = 0LL;
qword_4040F8 = 0LL;
qword_404100 = 0LL;
qword_404108 = 0LL;
}

original_code:
void pnd_log_to_nil ( void ) {
  memset ( log_targets, '\0', sizeof(pnd_log_target_t) * 5 );
  return;
}

canonical_original_code:
void pnd_log_to_nil() {
  memset ( log_targets, '\0', sizeof(pnd_log_target_t) * 5 );
  return;
}


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

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

original_code:
unsigned char pnd_log_to_syslog ( char *facility ) {
  return ( 0 );
}

canonical_original_code:
unsigned char pnd_log_to_syslog(char *facility) {
  return ( 0 );
}

variable_types:
facility
char *


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

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

original_code:
unsigned char pnd_log_to_callback ( pnd_log_callback_f f, void *userdata ) {
  return ( 0 );
}

canonical_original_code:
unsigned char pnd_log_to_callback(void (*f)(char *text, void *userdata), void *userdata) {
  return ( 0 );
}

variable_types:
f
void (*)(char *text, void *userdata)

variable_types:
userdata
void *


decompiled_code:
__int64 pnd_log_to_stdout()
{
return pnd_log_to_stream((__int64)stdout);
}

canonical_decompiled_code:
__int64 func17()
{
return func14((__int64)stdout);
}

original_code:
unsigned char pnd_log_to_stdout ( void ) {
  return ( pnd_log_to_stream ( stdout ) );
}

canonical_original_code:
unsigned char pnd_log_to_stdout() {
  return ( pnd_log_to_stream ( stdout ) );
}


decompiled_code:
__int64 pnd_log_to_stderr()
{
return pnd_log_to_stream((__int64)stderr);
}

canonical_decompiled_code:
__int64 func18()
{
return func14((__int64)stderr);
}

original_code:
unsigned char pnd_log_to_stderr ( void ) {
  return ( pnd_log_to_stream ( stderr ) );
}

canonical_original_code:
unsigned char pnd_log_to_stderr() {
  return ( pnd_log_to_stream ( stderr ) );
}


decompiled_code:
__int64 pnd_log_max_targets()
{
return 5LL;
}

canonical_decompiled_code:
__int64 func19()
{
return 5LL;
}

original_code:
unsigned char pnd_log_max_targets ( void ) {
  return ( 5 );
}

canonical_original_code:
unsigned char pnd_log_max_targets() {
  return ( 5 );
}


decompiled_code:
__int64 pnd_log(unsigned __int8 a1, const char *a2, ...)
{
__int64 result; // rax
char *v3; // rbp
int v4; // ebx
char *v5; // rax
int v6; // eax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

if ( !log_first )
log_first = time(0LL);
if ( a1 == 0xFF || (result = 0LL, (unsigned __int8)log_filterlevel <= a1) )
{
v3 = (char *)malloc(0x64uLL);
if ( v3 )
{
v4 = 100;
while ( 1 )
{
va_start(arg, a2);
v6 = vsnprintf(v3, v4, a2, arg);
if ( v6 >= 0 && v4 > v6 )
{
pnd_log_emit(a1, v3);
free(v3);
return 1LL;
}
v4 *= 2;
if ( v6 >= 0 )
v4 = v6 + 1;
v5 = (char *)realloc(v3, v4);
if ( !v5 )
break;
v3 = v5;
}
free(v3);
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func20(unsigned __int8 a1, const char *a2, ...)
{
__int64 result; // rax
char *v3; // rbp
int v4; // ebx
char *v5; // rax
int v6; // eax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

if ( !log_first )
log_first = time(0LL);
if ( a1 == 0xFF || (result = 0LL, (unsigned __int8)log_filterlevel <= a1) )
{
v3 = (char *)malloc(0x64uLL);
if ( v3 )
{
v4 = 100;
while ( 1 )
{
va_start(arg, a2);
v6 = vsnprintf(v3, v4, a2, arg);
if ( v6 >= 0 && v4 > v6 )
{
func8(a1, v3);
free(v3);
return 1LL;
}
v4 *= 2;
if ( v6 >= 0 )
v4 = v6 + 1;
v5 = (char *)realloc(v3, v4);
if ( !v5 )
break;
v3 = v5;
}
free(v3);
result = 0LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
unsigned char pnd_log ( unsigned char level, char *fmt, ... ) {
  if ( log_first == 0 ) {
    log_first = time ( ((void *)0) );
  }
  if ( level == (0xFF) ) {
  } else if ( level < log_filterlevel ) {
    return ( 0 );
  }
  int n, size = 100;
  char *p, *np;
  va_list ap;
  if ( ( p = malloc ( size ) ) == ((void *)0) ) {
    return ( 0 );
  }
  while ( 1 ) {
    __builtin_va_start(ap,fmt);
    n = vsnprintf ( p, size, fmt, ap );
    __builtin_va_end(ap);
    if ( n > -1 && n < size ) {
      pnd_log_emit ( level, p );
      break;
    }
    if ( n > -1 )
      size = n + 1;
    else
      size *= 2;
    if ( ( np = realloc ( p, size ) ) == ((void *)0) ) {
      free(p);
      return ( 0 );
    } else {
      p = np;
    }
  }
  if ( p ) {
    free ( p );
  }
  return ( 1 );
}

canonical_original_code:
unsigned char pnd_log(unsigned char level, char *fmt, ...) {
  if ( log_first == 0 ) {
    log_first = time ( ((void *)0) );
  }
  if ( level == (0xFF) ) {
  } else if ( level < log_filterlevel ) {
    return ( 0 );
  }
  int n; int size = 100;
  char *p; char *np;
  __builtin_va_list ap;
  if ( ( p = malloc ( size ) ) == ((void *)0) ) {
    return ( 0 );
  }
  while ( 1 ) {
    __builtin_va_start(ap,fmt);
    n = vsnprintf ( p, size, fmt, ap );
    __builtin_va_end(ap);
    if ( n > -1 && n < size ) {
      pnd_log_emit ( level, p );
      break;
    }
    if ( n > -1 )
      size = n + 1;
    else
      size *= 2;
    if ( ( np = realloc ( p, size ) ) == ((void *)0) ) {
      free(p);
      return ( 0 );
    } else {
      p = np;
    }
  }
  if ( p ) {
    free ( p );
  }
  return ( 1 );
}

variable_types:
fmt
char *

variable_types: n int

variable_types: size int

variable_types:
p
char *

variable_types:
np
char *


decompiled_code:
void __fastcall pnd_log_set_buried_logging(char a1)
{
do_buried_logging = a1;
}

canonical_decompiled_code:
void __fastcall func21(char a1)
{
do_buried_logging = a1;
}

original_code:
void pnd_log_set_buried_logging ( unsigned char yesno ) {
  _do_buried_logging = yesno;
  return;
}

canonical_original_code:
void pnd_log_set_buried_logging(unsigned char yesno) {
  _do_buried_logging = yesno;
  return;
}

variable_types:
yesno
unsigned char


decompiled_code:
bool pnd_log_do_buried_logging()
{
return do_buried_logging == 1;
}

canonical_decompiled_code:
bool func22()
{
return do_buried_logging == 1;
}

original_code:
unsigned char pnd_log_do_buried_logging ( void ) {
  if ( _do_buried_logging == 1 ) {
    return ( 1 );
  }
  return ( 0 );
}

canonical_original_code:
unsigned char pnd_log_do_buried_logging() {
  if ( _do_buried_logging == 1 ) {
    return ( 1 );
  }
  return ( 0 );
}


decompiled_code:
char *pnd_apps_exec_runline()
{
return apps_exec_runline;
}

canonical_decompiled_code:
char *func0()
{
return apps_exec_runline;
}

original_code:
char *pnd_apps_exec_runline ( void ) {
  return ( apps_exec_runline );
}

canonical_original_code:
char *pnd_apps_exec_runline() {
  return ( apps_exec_runline );
}


original_code:
unsigned char pnd_apps_exec_disco ( char *pndrun, pnd_disco_t *app,
        unsigned int options, void *reserved )
{
  char *argv [ 60 ];
  char fullpath [ 4096 ] = "";
  int f;
  if ( ! pndrun ) {
    return ( 0 );
  }
  if ( ! app -> unique_id ) {
    return ( 0 );
  }
  if ( ! app -> exec ) {
    return ( 0 );
  }
  if ( options & 16 && ! reserved ) {
    return ( 0 );
  }
  sprintf ( fullpath, "%s/%s", app -> object_path, app -> object_filename );
  memset ( argv, '\0', sizeof(char*) * 20 );
  f = 0;
  argv [ f++ ] = pndrun;
  argv [ f++ ] = "-p";
  argv [ f++ ] = fullpath;
  argv [ f++ ] = "-e";
  if ( options & 16 ) {
    argv [ f++ ] = ((pnd_apps_exec_info_t*)reserved) -> viewer;
  } else {
    argv [ f++ ] = app -> exec;
  }
  if ( app -> startdir ) {
    argv [ f++ ] = "-s";
    argv [ f++ ] = app -> startdir;
  }
  if ( options & 16 ) {
    if ( ((pnd_apps_exec_info_t*)reserved) -> args ) {
      argv [ f++ ] = "-a";
      argv [ f++ ] = ((pnd_apps_exec_info_t*)reserved) -> args;
    }
  } else {
    if ( app -> execargs ) {
      argv [ f++ ] = "-a";
      argv [ f++ ] = app -> execargs;
    }
  }
  if ( app -> appdata_dirname ) {
    argv [ f++ ] = "-b";
    argv [ f++ ] = app -> appdata_dirname;
  } else {
    argv [ f++ ] = "-b";
    argv [ f++ ] = app -> unique_id;
  }
  if ( options & 16 ) {
  } else {
    if ( app -> clockspeed ) {
      argv [ f++ ] = "-c";
      argv [ f++ ] = app -> clockspeed;
    }
  }
  if ( options & 2 ) {
    argv [ f++ ] = "-n";
  }
  if ( options & 4 ) {
    argv [ f++ ] = "-x";
  }
  argv [ f++ ] = ((void *)0);
  if ( options & 8 ) {
    unsigned char i;
    bzero ( apps_exec_runline, 1024 );
    unsigned char quotenext = 0;
    for ( i = 0; i < ( f - 1 ); i++ ) {
      if ( i > 0 ) {
 strncat ( apps_exec_runline, " ", 1000 );
      }
      if ( quotenext ) {
 strncat ( apps_exec_runline, "\"", 1000 );
      }
      strncat ( apps_exec_runline, argv [ i ], 1000 );
      if ( quotenext ) {
 strncat ( apps_exec_runline, "\"", 1000 );
      }
      if ( quotenext ) {
 quotenext = 0;
      } else {
 if ( ( strcmp ( argv [ i ], "-a" ) == 0 ) ||
      ( strcmp ( argv [ i ], "-p" ) == 0 ) ||
      ( strcmp ( argv [ i ], "-e" ) == 0 ) ||
      ( strcmp ( argv [ i ], "-s" ) == 0 ) ||
      ( strcmp ( argv [ i ], "-b" ) == 0 ) )
 {
   quotenext = 1;
 }
      }
    }
    return ( 1 );
  }
  if ( ( f = fork() ) < 0 ) {
  } else if ( f > 0 ) {
  } else {
    execv ( pndrun, argv );
  }
  if ( options & 1 ) {
    int status = 0;
    waitpid ( f, &status, 0 );
  }
  return ( 1 );
}

canonical_original_code:
unsigned char pnd_apps_exec_disco(char *pndrun, struct pnd_disco_t *app, unsigned int options, void *reserved)
{
  char *argv[60];
  char fullpath[4096] = "";
  int f;
  if ( ! pndrun ) {
    return ( 0 );
  }
  if ( ! app -> unique_id ) {
    return ( 0 );
  }
  if ( ! app -> exec ) {
    return ( 0 );
  }
  if ( options & 16 && ! reserved ) {
    return ( 0 );
  }
  sprintf ( fullpath, "%s/%s", app -> object_path, app -> object_filename );
  memset ( argv, '\0', sizeof(char *) * 20 );
  f = 0;
  argv [ f++ ] = pndrun;
  argv [ f++ ] = "-p";
  argv [ f++ ] = fullpath;
  argv [ f++ ] = "-e";
  if ( options & 16 ) {
    argv [ f++ ] = ((struct pnd_apps_exec_info_t *)reserved) -> viewer;
  } else {
    argv [ f++ ] = app -> exec;
  }
  if ( app -> startdir ) {
    argv [ f++ ] = "-s";
    argv [ f++ ] = app -> startdir;
  }
  if ( options & 16 ) {
    if ( ((struct pnd_apps_exec_info_t *)reserved) -> args ) {
      argv [ f++ ] = "-a";
      argv [ f++ ] = ((struct pnd_apps_exec_info_t *)reserved) -> args;
    }
  } else {
    if ( app -> execargs ) {
      argv [ f++ ] = "-a";
      argv [ f++ ] = app -> execargs;
    }
  }
  if ( app -> appdata_dirname ) {
    argv [ f++ ] = "-b";
    argv [ f++ ] = app -> appdata_dirname;
  } else {
    argv [ f++ ] = "-b";
    argv [ f++ ] = app -> unique_id;
  }
  if ( options & 16 ) {
  } else {
    if ( app -> clockspeed ) {
      argv [ f++ ] = "-c";
      argv [ f++ ] = app -> clockspeed;
    }
  }
  if ( options & 2 ) {
    argv [ f++ ] = "-n";
  }
  if ( options & 4 ) {
    argv [ f++ ] = "-x";
  }
  argv [ f++ ] = ((void *)0);
  if ( options & 8 ) {
    unsigned char i;
    bzero ( apps_exec_runline, 1024 );
    unsigned char quotenext = 0;
    for ( i = 0; i < ( f - 1 ); i++ ) {
      if ( i > 0 ) {
 strncat ( apps_exec_runline, " ", 1000 );
      }
      if ( quotenext ) {
 strncat ( apps_exec_runline, "\"", 1000 );
      }
      strncat ( apps_exec_runline, argv [ i ], 1000 );
      if ( quotenext ) {
 strncat ( apps_exec_runline, "\"", 1000 );
      }
      if ( quotenext ) {
 quotenext = 0;
      } else {
 if ( ( strcmp ( argv [ i ], "-a" ) == 0 ) ||
      ( strcmp ( argv [ i ], "-p" ) == 0 ) ||
      ( strcmp ( argv [ i ], "-e" ) == 0 ) ||
      ( strcmp ( argv [ i ], "-s" ) == 0 ) ||
      ( strcmp ( argv [ i ], "-b" ) == 0 ) )
 {
   quotenext = 1;
 }
      }
    }
    return ( 1 );
  }
  if ( ( f = fork() ) < 0 ) {
  } else if ( f > 0 ) {
  } else {
    execv ( pndrun, argv );
  }
  if ( options & 1 ) {
    int status = 0;
    waitpid ( f, &status, 0 );
  }
  return ( 1 );
}

variable_types:
pndrun
char *

variable_types: struct pnd_disco_t { unsigned char object_type; char *object_path; char *object_filename; unsigned int pnd_icon_pos; unsigned char subapp_number; unsigned int object_flags; char *package_id; char *title_en; char *desc_en; char *unique_id; char *appdata_dirname; char *icon; char *exec; char *execargs; char *clockspeed; char *startdir; char *option_no_x11; char *main_category; char *main_category1; char *main_category2; char *alt_category; char *alt_category1; char *alt_category2; char *preview_pic1; char *preview_pic2; char *mkdir_sp; char *info_name; char *info_filename; char *info_type; char *version_major; char *version_minor; char *version_release; char *version_build; char *package_version_major; char *package_version_minor; char *package_version_release; char *package_version_build; char *associationitem1_name; char *associationitem1_filetype; char *exec_dashdash_args; } *

variable_types:
options
unsigned int

variable_types:
reserved
void *

variable_types:
argv
char *[60]

variable_types:
fullpath
char [4096]

variable_types: f int

variable_types:
quotenext
unsigned char

variable_types: status int

user_defined_types: struct pnd_apps_exec_info_t { char *viewer; char *args; }


original_code:
unsigned char pnd_apps_exec ( char *pndrun, char *fullpath, char *unique_id,
         char *rel_exec, char *rel_startdir,
         char *args,
         unsigned int clockspeed, unsigned int options )
{
  pnd_disco_t d;
  bzero ( &d, sizeof(pnd_disco_t) );
  char cpuspeed [ 10 ];
  sprintf ( cpuspeed, "%u", clockspeed );
  char hackpath [ 4096 ];
  strncpy ( hackpath, fullpath, 4096 );
  char *c = strrchr ( hackpath, '/' );
  if ( c ) {
    *c = '\0';
    d.object_path = hackpath;
    d.object_filename = c + 1;
  } else {
    d.object_path = fullpath;
  }
  d.unique_id = unique_id;
  d.exec = rel_exec;
  d.startdir = rel_startdir;
  d.execargs = args;
  if ( clockspeed ) {
    d.clockspeed = cpuspeed;
  } else {
    d.clockspeed = ((void *)0);
  }
  return ( pnd_apps_exec_disco ( pndrun, &d, options, ((void *)0) ) );
}

canonical_original_code:
unsigned char pnd_apps_exec(char *pndrun, char *fullpath, char *unique_id, char *rel_exec, char *rel_startdir, char *args, unsigned int clockspeed, unsigned int options)
{
  struct pnd_disco_t d;
  bzero ( &d, sizeof(pnd_disco_t) );
  char cpuspeed[10];
  sprintf ( cpuspeed, "%u", clockspeed );
  char hackpath[4096];
  strncpy ( hackpath, fullpath, 4096 );
  char *c = strrchr ( hackpath, '/' );
  if ( c ) {
    *c = '\0';
    d.object_path = hackpath;
    d.object_filename = c + 1;
  } else {
    d.object_path = fullpath;
  }
  d.unique_id = unique_id;
  d.exec = rel_exec;
  d.startdir = rel_startdir;
  d.execargs = args;
  if ( clockspeed ) {
    d.clockspeed = cpuspeed;
  } else {
    d.clockspeed = ((void *)0);
  }
  return ( pnd_apps_exec_disco ( pndrun, &d, options, ((void *)0) ) );
}

variable_types:
fullpath
char *

variable_types:
args
char *

variable_types:
clockspeed
unsigned int

variable_types: struct pnd_disco_t { unsigned char object_type; char *object_path; char *object_filename; unsigned int pnd_icon_pos; unsigned char subapp_number; unsigned int object_flags; char *package_id; char *title_en; char *desc_en; char *unique_id; char *appdata_dirname; char *icon; char *exec; char *execargs; char *clockspeed; char *startdir; char *option_no_x11; char *main_category; char *main_category1; char *main_category2; char *alt_category; char *alt_category1; char *alt_category2; char *preview_pic1; char *preview_pic2; char *mkdir_sp; char *info_name; char *info_filename; char *info_type; char *version_major; char *version_minor; char *version_release; char *version_build; char *package_version_major; char *package_version_minor; char *package_version_release; char *package_version_build; char *associationitem1_name; char *associationitem1_filetype; char *exec_dashdash_args; }

variable_types:
cpuspeed
char [10]

variable_types:
hackpath
char [4096]

variable_types:
c
char *


decompiled_code:
int __fastcall pnd_get_ro_mountpoint(__int64 a1, const char *a2, char *a3, unsigned int a4)
{
int result; // eax

if ( a3 )
result = snprintf(a3, a4, "%s/%s/", "/mnt/pnd/", a2);
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2, char *a3, unsigned int a4)
{
int result; // eax

if ( a3 )
result = snprintf(a3, a4, "%s/%s/", "/mnt/pnd/", a2);
return result;
}

original_code:
void pnd_get_ro_mountpoint ( char *fullpath, char *unique_id, char *r_mountpoint, unsigned int mountpoint_len ) {
  if ( ! r_mountpoint ) {
    return;
  }
  snprintf ( r_mountpoint, mountpoint_len, "%s/%s/", "/mnt/pnd/", unique_id );
  return;
}

canonical_original_code:
void pnd_get_ro_mountpoint(char *fullpath, char *unique_id, char *r_mountpoint, unsigned int mountpoint_len) {
  if ( ! r_mountpoint ) {
    return;
  }
  snprintf ( r_mountpoint, mountpoint_len, "%s/%s/", "/mnt/pnd/", unique_id );
  return;
}


decompiled_code:
__int64 __fastcall pnd_device_open_write_close(const char *a1, const char *a2)
{
int v2; // ebx
__int64 result; // rax
size_t v4; // rax
size_t v5; // r12

v2 = open(a1, 1);
result = 0LL;
if ( v2 >= 0 )
{
v4 = strlen(a2);
v5 = write(v2, a2, v4);
if ( v5 < strlen(a2) )
{
close(v2);
result = 0LL;
}
else
{
close(v2);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, const char *a2)
{
int v2; // ebx
__int64 result; // rax
size_t v4; // rax
size_t v5; // r12

v2 = open(a1, 1);
result = 0LL;
if ( v2 >= 0 )
{
v4 = strlen(a2);
v5 = write(v2, a2, v4);
if ( v5 < strlen(a2) )
{
close(v2);
result = 0LL;
}
else
{
close(v2);
result = 1LL;
}
}
return result;
}

original_code:
unsigned char pnd_device_open_write_close ( char *name, char *v ) {
  int f;
  if ( ( f = open ( name, 01 ) ) < 0 ) {
    return ( 0 );
  }
  if ( write ( f, v, strlen ( v ) ) < strlen ( v ) ) {
    close ( f );
    return ( 0 );
  }
  close ( f );
  return ( 1 );
}

canonical_original_code:
unsigned char pnd_device_open_write_close(char *name, char *v) {
  int f;
  if ( ( f = open ( name, 01 ) ) < 0 ) {
    return ( 0 );
  }
  if ( write ( f, v, strlen ( v ) ) < strlen ( v ) ) {
    close ( f );
    return ( 0 );
  }
  close ( f );
  return ( 1 );
}

variable_types:
name
char *

variable_types:
v
char *


decompiled_code:
__int64 __fastcall pnd_device_set_clock(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v2, "%u", a1);
return pnd_device_open_write_close("/proc/pandora/cpu_mhz_max", v2);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v2, "%u", a1);
return func0("/proc/pandora/cpu_mhz_max", v2);
}

original_code:
unsigned char pnd_device_set_clock ( unsigned int c ) {
  char buffer [ 100 ];
  sprintf ( buffer, "%u", c );
  return ( pnd_device_open_write_close ( "/proc/pandora/cpu_mhz_max", buffer ) );
}

canonical_original_code:
unsigned char pnd_device_set_clock(unsigned int c) {
  char buffer[100];
  sprintf ( buffer, "%u", c );
  return ( pnd_device_open_write_close ( "/proc/pandora/cpu_mhz_max", buffer ) );
}

variable_types:
c
unsigned int

variable_types:
buffer
char [100]


decompiled_code:
int pnd_device_get_clock()
{
char v0; // dl
int result; // eax
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

v0 = pnd_device_open_read_close("/proc/pandora/cpu_mhz_max", v2, 100);
result = 0;
if ( v0 )
result = atoi(v2);
return result;
}

canonical_decompiled_code:
int func3()
{
char v0; // dl
int result; // eax
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

v0 = func1("/proc/pandora/cpu_mhz_max", v2, 100);
result = 0;
if ( v0 )
result = atoi(v2);
return result;
}

original_code:
unsigned int pnd_device_get_clock ( void ) {
  char buffer [ 100 ];
  if ( pnd_device_open_read_close ( "/proc/pandora/cpu_mhz_max", buffer, 100 ) ) {
    return ( atoi ( buffer ) );
  }
  return ( 0 );
}

canonical_original_code:
unsigned int pnd_device_get_clock() {
  char buffer[100];
  if ( pnd_device_open_read_close ( "/proc/pandora/cpu_mhz_max", buffer, 100 ) ) {
    return ( atoi ( buffer ) );
  }
  return ( 0 );
}


decompiled_code:
__int64 __fastcall pnd_device_set_backlight(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v2, "%u", a1);
return pnd_device_open_write_close("/sys/class/backlight/gpio-backlight/brightness", v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v2, "%u", a1);
return func0("/sys/class/backlight/gpio-backlight/brightness", v2);
}

original_code:
unsigned char pnd_device_set_backlight ( unsigned int c ) {
  char buffer [ 100 ];
  sprintf ( buffer, "%u", c );
  return ( pnd_device_open_write_close ( "/sys/class/backlight/gpio-backlight/brightness", buffer ) );
}

canonical_original_code:
unsigned char pnd_device_set_backlight(unsigned int c) {
  char buffer[100];
  sprintf ( buffer, "%u", c );
  return ( pnd_device_open_write_close ( "/sys/class/backlight/gpio-backlight/brightness", buffer ) );
}


decompiled_code:
int pnd_device_get_backlight()
{
char v0; // dl
int result; // eax
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

v0 = pnd_device_open_read_close("/sys/class/backlight/gpio-backlight/brightness", v2, 100);
result = 0;
if ( v0 )
result = atoi(v2);
return result;
}

canonical_decompiled_code:
int func5()
{
char v0; // dl
int result; // eax
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

v0 = func1("/sys/class/backlight/gpio-backlight/brightness", v2, 100);
result = 0;
if ( v0 )
result = atoi(v2);
return result;
}

original_code:
unsigned int pnd_device_get_backlight ( void ) {
  char buffer [ 100 ];
  if ( pnd_device_open_read_close ( "/sys/class/backlight/gpio-backlight/brightness", buffer, 100 ) ) {
    return ( atoi ( buffer ) );
  }
  return ( 0 );
}

canonical_original_code:
unsigned int pnd_device_get_backlight() {
  char buffer[100];
  if ( pnd_device_open_read_close ( "/sys/class/backlight/gpio-backlight/brightness", buffer, 100 ) ) {
    return ( atoi ( buffer ) );
  }
  return ( 0 );
}


decompiled_code:
int pnd_device_get_battery_gauge_perc()
{
int result; // eax
char v1[120]; // [rsp+0h] [rbp-78h] BYREF

if ( (unsigned __int8)pnd_device_open_read_close("/sys/class/power_supply/bq27500-0/capacity", v1, 100) )
result = atoi(v1);
else
result = -1;
return result;
}

canonical_decompiled_code:
int func6()
{
int result; // eax
char v1[120]; // [rsp+0h] [rbp-78h] BYREF

if ( (unsigned __int8)func1("/sys/class/power_supply/bq27500-0/capacity", v1, 100) )
result = atoi(v1);
else
result = -1;
return result;
}

original_code:
int pnd_device_get_battery_gauge_perc ( void ) {
  char buffer [ 100 ];
  if ( pnd_device_open_read_close ( "/sys/class/power_supply/bq27500-0/capacity", buffer, 100 ) ) {
    return ( atoi ( buffer ) );
  }
  return ( -1 );
}

canonical_original_code:
int pnd_device_get_battery_gauge_perc() {
  char buffer[100];
  if ( pnd_device_open_read_close ( "/sys/class/power_supply/bq27500-0/capacity", buffer, 100 ) ) {
    return ( atoi ( buffer ) );
  }
  return ( -1 );
}


decompiled_code:
__int64 __fastcall pnd_device_get_charge_current(int *a1)
{
__int64 result; // rax
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

result = pnd_device_open_read_close("/sys/class/power_supply/bq27500-0/current_now", v2, 100);
if ( (_BYTE)result )
{
*a1 = atoi(v2);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int *a1)
{
__int64 result; // rax
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

result = func1("/sys/class/power_supply/bq27500-0/current_now", v2, 100);
if ( (_BYTE)result )
{
*a1 = atoi(v2);
result = 1LL;
}
return result;
}

original_code:
unsigned char pnd_device_get_charge_current ( int *result ) {
  char buffer [ 100 ];
  if ( pnd_device_open_read_close ( "/sys/class/power_supply/bq27500-0/current_now", buffer, 100 ) ) {
    *result = atoi ( buffer );
    return ( 1 );
  }
  return ( 0 );
}

canonical_original_code:
unsigned char pnd_device_get_charge_current(int *result) {
  char buffer[100];
  if ( pnd_device_open_read_close ( "/sys/class/power_supply/bq27500-0/current_now", buffer, 100 ) ) {
    *result = atoi ( buffer );
    return ( 1 );
  }
  return ( 0 );
}

variable_types:
result
int *


decompiled_code:
int __fastcall pnd_device_get_charger_enable(char *a1)
{
const unsigned __int16 *v2; // rdx
char _0[112]; // [rsp+0h] [rbp+0h] BYREF
char s[136]; // [rsp+70h] [rbp+70h] BYREF

while ( (unsigned int)_isoc99_sscanf(a1, "%99s", _0) == 1 )
{
v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
a1 += strlen(_0);
snprintf(s, 0x64uLL, "/sys/class/power_supply/%s/enable", _0);
if ( (unsigned __int8)pnd_device_open_read_close(s, _0, 100) )
return atoi(_0);
}
return -1;
}

canonical_decompiled_code:
int __fastcall func8(char *a1)
{
const unsigned __int16 *v2; // rdx
char _0[112]; // [rsp+0h] [rbp+0h] BYREF
char s[136]; // [rsp+70h] [rbp+70h] BYREF

while ( (unsigned int)_isoc99_sscanf(a1, "%99s", _0) == 1 )
{
v2 = *_ctype_b_loc();
while ( (v2[*a1] & 0x2000) != 0 )
++a1;
a1 += strlen(_0);
snprintf(s, 0x64uLL, "/sys/class/power_supply/%s/enable", _0);
if ( (unsigned __int8)func1(s, _0, 100) )
return atoi(_0);
}
return -1;
}

original_code:
int pnd_device_get_charger_enable ( const char *devices ) {
  char fullname [ 100 ];
  char buffer [ 100 ];
  while ( 1 ) {
    if ( sscanf ( devices, "%99s", buffer ) != 1 ) {
      break;
    }
    while ( ((*__ctype_b_loc ())[(int) ((*devices))] & (unsigned short int) _ISspace) )
      devices++;
    devices += strlen ( buffer );
    snprintf ( fullname, sizeof ( fullname ), "/sys/class/power_supply" "/%s/enable", buffer );
    if ( pnd_device_open_read_close ( fullname, buffer, 100 ) ) {
      return ( atoi ( buffer ) );
    }
  }
  return ( -1 );
}

canonical_original_code:
int pnd_device_get_charger_enable(char *devices) {
  char fullname[100];
  char buffer[100];
  while ( 1 ) {
    if ( sscanf ( devices, "%99s", buffer ) != 1 ) {
      break;
    }
    while ( ((*__ctype_b_loc ())[(int) ((*devices))] & (unsigned short) _ISspace) )
      devices++;
    devices += strlen ( buffer );
    snprintf ( fullname, sizeof ( fullname ), "/sys/class/power_supply" "/%s/enable", buffer );
    if ( pnd_device_open_read_close ( fullname, buffer, 100 ) ) {
      return ( atoi ( buffer ) );
    }
  }
  return ( -1 );
}

variable_types:
devices
char *

variable_types:
fullname
char [100]


decompiled_code:
__int64 __fastcall pnd_device_set_charger_enable(char *a1, unsigned __int8 a2)
{
unsigned int v3; // er12
const unsigned __int16 *v4; // rdx
char _0[112]; // [rsp+0h] [rbp+0h] BYREF
char s[152]; // [rsp+70h] [rbp+70h] BYREF

v3 = 0;
while ( (unsigned int)_isoc99_sscanf(a1, "%99s", _0) == 1 )
{
v4 = *_ctype_b_loc();
while ( (v4[*a1] & 0x2000) != 0 )
++a1;
a1 += strlen(_0);
snprintf(s, 0x64uLL, "/sys/class/power_supply/%s/enable", _0);
sprintf(_0, "%u", a2);
v3 |= (unsigned __int8)pnd_device_open_write_close(s, _0);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, unsigned __int8 a2)
{
unsigned int v3; // er12
const unsigned __int16 *v4; // rdx
char _0[112]; // [rsp+0h] [rbp+0h] BYREF
char s[152]; // [rsp+70h] [rbp+70h] BYREF

v3 = 0;
while ( (unsigned int)_isoc99_sscanf(a1, "%99s", _0) == 1 )
{
v4 = *_ctype_b_loc();
while ( (v4[*a1] & 0x2000) != 0 )
++a1;
a1 += strlen(_0);
snprintf(s, 0x64uLL, "/sys/class/power_supply/%s/enable", _0);
sprintf(_0, "%u", a2);
v3 |= (unsigned __int8)func0(s, _0);
}
return v3;
}

original_code:
unsigned char pnd_device_set_charger_enable ( const char *devices, unsigned char v ) {
  char fullname [ 100 ];
  char buffer [ 100 ];
  int ret = 0;
  while ( 1 ) {
    if ( sscanf ( devices, "%99s", buffer ) != 1 ) {
      break;
    }
    while ( ((*__ctype_b_loc ())[(int) ((*devices))] & (unsigned short int) _ISspace) )
      devices++;
    devices += strlen ( buffer );
    snprintf ( fullname, sizeof ( fullname ), "/sys/class/power_supply" "/%s/enable", buffer );
    sprintf ( buffer, "%u", v );
    ret |= pnd_device_open_write_close ( fullname, buffer );
  }
  return ( ret );
}

canonical_original_code:
unsigned char pnd_device_set_charger_enable(char *devices, unsigned char v) {
  char fullname[100];
  char buffer[100];
  int ret = 0;
  while ( 1 ) {
    if ( sscanf ( devices, "%99s", buffer ) != 1 ) {
      break;
    }
    while ( ((*__ctype_b_loc ())[(int) ((*devices))] & (unsigned short) _ISspace) )
      devices++;
    devices += strlen ( buffer );
    snprintf ( fullname, sizeof ( fullname ), "/sys/class/power_supply" "/%s/enable", buffer );
    sprintf ( buffer, "%u", v );
    ret |= pnd_device_open_write_close ( fullname, buffer );
  }
  return ( ret );
}

variable_types:
v
unsigned char

variable_types: ret int


decompiled_code:
__int64 __fastcall pnd_device_set_led_power_brightness(unsigned __int8 a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v2, "%u", a1);
return pnd_device_open_write_close("/sys/class/leds/pandora::power/brightness", v2);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int8 a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v2, "%u", a1);
return func0("/sys/class/leds/pandora::power/brightness", v2);
}

original_code:
unsigned char pnd_device_set_led_power_brightness ( unsigned char v ) {
  char buffer [ 100 ];
  sprintf ( buffer, "%u", v );
  return ( pnd_device_open_write_close ( "/sys/class/leds/pandora::power" "/brightness", buffer ) );
}

canonical_original_code:
unsigned char pnd_device_set_led_power_brightness(unsigned char v) {
  char buffer[100];
  sprintf ( buffer, "%u", v );
  return ( pnd_device_open_write_close ( "/sys/class/leds/pandora::power" "/brightness", buffer ) );
}


decompiled_code:
__int64 __fastcall pnd_device_set_led_charger_brightness(unsigned __int8 a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v2, "%u", a1);
return pnd_device_open_write_close("/sys/class/leds/pandora::charger/brightness", v2);
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int8 a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

sprintf(v2, "%u", a1);
return func0("/sys/class/leds/pandora::charger/brightness", v2);
}

original_code:
unsigned char pnd_device_set_led_charger_brightness ( unsigned char v ) {
  char buffer [ 100 ];
  sprintf ( buffer, "%u", v );
  return ( pnd_device_open_write_close ( "/sys/class/leds/pandora::charger" "/brightness", buffer ) );
}

canonical_original_code:
unsigned char pnd_device_set_led_charger_brightness(unsigned char v) {
  char buffer[100];
  sprintf ( buffer, "%u", v );
  return ( pnd_device_open_write_close ( "/sys/class/leds/pandora::charger" "/brightness", buffer ) );
}


decompiled_code:
char *__fastcall cache_query(char *s2, char *s1)
{
char *i; // rbx

if ( !s2 )
return 0LL;
for ( i = s1; i; i = (char *)*((_QWORD *)i + 130) )
{
if ( i && !strcasecmp(i, s2) )
break;
}
return i;
}

canonical_decompiled_code:
char *__fastcall func0(char *s2, char *s1)
{
char *i; // rbx

if ( !s2 )
return 0LL;
for ( i = s1; i; i = (char *)*((_QWORD *)i + 130) )
{
if ( i && !strcasecmp(i, s2) )
break;
}
return i;
}

original_code:
mm_cache_t *cache_query ( char *id, mm_cache_t *head ) {
  mm_cache_t *iter = head;
  if ( ! id ) {
    return ( ((void *)0) );
  }
  while ( iter ) {
    if ( iter -> uniqueid &&
  strcasecmp ( iter -> uniqueid, id ) == 0 )
    {
      return ( iter );
    }
    iter = iter -> next;
  }
  return ( ((void *)0) );
}

canonical_original_code:
struct _mm_cache_t *cache_query(char *id, struct _mm_cache_t *head) {
  struct _mm_cache_t *iter = head;
  if ( ! id ) {
    return ( ((void *)0) );
  }
  while ( iter ) {
    if ( iter -> uniqueid &&
  strcasecmp ( iter -> uniqueid, id ) == 0 )
    {
      return ( iter );
    }
    iter = iter -> next;
  }
  return ( ((void *)0) );
}

variable_types:
id
char *

variable_types:
head
struct _mm_cache_t *

variable_types: struct _mm_cache_t { char uniqueid[1024]; void *i; void *itiny; struct _mm_cache_t *next; } *


decompiled_code:
char *__fastcall cache_query_icon(char *a1)
{
return cache_query(a1, g_icon_cache);
}

canonical_decompiled_code:
char *__fastcall func1(char *a1)
{
return func0(a1, g_icon_cache);
}

original_code:
mm_cache_t *cache_query_icon ( char *id ) {
  return ( cache_query ( id, g_icon_cache ) );
}

canonical_original_code:
struct _mm_cache_t *cache_query_icon(char *id) {
  return ( cache_query ( id, g_icon_cache ) );
}

return_type: struct _mm_cache_t { char uniqueid[1024]; void *i; void *itiny; struct _mm_cache_t *next; } *


decompiled_code:
char *__fastcall cache_query_preview(char *a1)
{
return cache_query(a1, g_preview_cache);
}

canonical_decompiled_code:
char *__fastcall func3(char *a1)
{
return func0(a1, g_preview_cache);
}

original_code:
mm_cache_t *cache_query_preview ( char *id ) {
  return ( cache_query ( id, g_preview_cache ) );
}

canonical_original_code:
struct _mm_cache_t *cache_query_preview(char *id) {
  return ( cache_query ( id, g_preview_cache ) );
}

user_defined_types: struct _mm_cache_t { char uniqueid[1024]; void *i; void *itiny; struct _mm_cache_t *next; }


decompiled_code:
int PND_Close_Controls()
{
int *v0; // rax

if ( fd_pndk > 0 )
close(fd_pndk);
if ( fd_gpio > 0 )
close(fd_gpio);
if ( fd_nub1 > 0 )
close(fd_nub1);
v0 = &fd_nub2;
if ( fd_nub2 > 0 )
LODWORD(v0) = close(fd_nub2);
return (int)v0;
}

canonical_decompiled_code:
int func0()
{
int *v0; // rax

if ( fd_pndk > 0 )
close(fd_pndk);
if ( fd_gpio > 0 )
close(fd_gpio);
if ( fd_nub1 > 0 )
close(fd_nub1);
v0 = &fd_nub2;
if ( fd_nub2 > 0 )
LODWORD(v0) = close(fd_nub2);
return (int)v0;
}

original_code:
void PND_Close_Controls ( void ) {
  if( fd_pndk > 0 )
    close(fd_pndk );
  if( fd_gpio > 0 )
    close(fd_gpio );
  if( fd_nub1 > 0 )
    close(fd_nub1 );
  if( fd_nub2 > 0 )
    close(fd_nub2 );
}

canonical_original_code:
void PND_Close_Controls() {
  if( fd_pndk > 0 )
    close(fd_pndk );
  if( fd_gpio > 0 )
    close(fd_gpio );
  if( fd_nub1 > 0 )
    close(fd_nub1 );
  if( fd_nub2 > 0 )
    close(fd_nub2 );
}


decompiled_code:
void PND_SendKeyEvents()
{
PND_ReadEvents(fd_pndk);
PND_ReadEvents(fd_gpio);
PND_ReadEvents(fd_nub1);
PND_ReadEvents(fd_nub2);
}

canonical_decompiled_code:
void func3()
{
func2(fd_pndk);
func2(fd_gpio);
func2(fd_nub1);
func2(fd_nub2);
}

original_code:
void PND_SendKeyEvents ( void ) {
  PND_ReadEvents( fd_pndk, 2 );
  PND_ReadEvents( fd_gpio, 3 );
  PND_ReadEvents( fd_nub1, 0 );
  PND_ReadEvents( fd_nub2, 1 );
}

canonical_original_code:
void PND_SendKeyEvents() {
  PND_ReadEvents( fd_pndk, 2 );
  PND_ReadEvents( fd_gpio, 3 );
  PND_ReadEvents( fd_nub1, 0 );
  PND_ReadEvents( fd_nub2, 1 );
}


decompiled_code:
__int64 __fastcall PND_OpenEventDeviceByID(unsigned int a1)
{
int v1; // eax
unsigned int v2; // ebx

snprintf(event_name, 0x1EuLL, "/dev/input/event%d", a1);
printf("Device: %s\n", event_name);
v1 = open(event_name, 2048);
if ( v1 < 0 )
{
perror("ERROR: Could not open device");
v2 = 0;
}
else
{
v2 = v1;
if ( ioctl(v1, 0x80044501uLL, version) )
{
perror("evtest: can't get version");
v2 = 0;
}
else
{
printf("Input driver version is %d.%d.%d\n", (unsigned int)(*(int *)version >> 16), version[1], version[0]);
ioctl(v2, 0x80084502uLL, id);
printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n", id[0], id[1], id[2], id[3]);
ioctl(v2, 0x81004506uLL, dev_name);
printf("Input device name: \"%s\"\n", dev_name);
}
}
return v2;
}

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

snprintf(event_name, 0x1EuLL, "/dev/input/event%d", a1);
printf("Device: %s\n", event_name);
v1 = open(event_name, 2048);
if ( v1 < 0 )
{
perror("ERROR: Could not open device");
v2 = 0;
}
else
{
v2 = v1;
if ( ioctl(v1, 0x80044501uLL, version) )
{
perror("evtest: can't get version");
v2 = 0;
}
else
{
printf("Input driver version is %d.%d.%d\n", (unsigned int)(*(int *)version >> 16), version[1], version[0]);
ioctl(v2, 0x80084502uLL, id);
printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n", id[0], id[1], id[2], id[3]);
ioctl(v2, 0x81004506uLL, dev_name);
printf("Input device name: \"%s\"\n", dev_name);
}
}
return v2;
}

original_code:
int PND_OpenEventDeviceByID ( int event_id ) {
  int fd;
  snprintf( event_name, sizeof(event_name), "/dev/input/event%d", event_id );
  printf( "Device: %s\n", event_name );
  if ((fd = open(event_name, 00 | 04000)) < 0) {
    perror("ERROR: Could not open device");
    return 0;
  }
  if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x01)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &version)) {
    perror("evtest: can't get version");
    return 0;
  }
  printf("Input driver version is %d.%d.%d\n",
  version >> 16, (version >> 8) & 0xff, version & 0xff);
  ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x02)) << 0) | ((((sizeof(struct input_id)))) << ((0 +8)+8))), id);
  printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
  id[0], id[1], id[2], id[3]);
  ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(dev_name)) << ((0 +8)+8))), dev_name);
  printf("Input device name: \"%s\"\n", dev_name);
  return fd;
}

canonical_original_code:
int PND_OpenEventDeviceByID(int event_id) {
  int fd;
  snprintf( event_name, sizeof(event_name), "/dev/input/event%d", event_id );
  printf( "Device: %s\n", event_name );
  if ((fd = open(event_name, 00 | 04000)) < 0) {
    perror("ERROR: Could not open device");
    return 0;
  }
  if (ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x01)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &version)) {
    perror("evtest: can't get version");
    return 0;
  }
  printf("Input driver version is %d.%d.%d\n",
  version >> 16, (version >> 8) & 0xff, version & 0xff);
  ioctl(fd, (((2U) << (((0 +8)+8)+14)) | ((('E')) << (0 +8)) | (((0x02)) << 0) | ((((sizeof(struct input_id)))) << ((0 +8)+8))), id);
  printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version 0x%x\n",
  id[0], id[1], id[2], id[3]);
  ioctl(fd, (((2U) << (((0 +8)+8)+14)) | (('E') << (0 +8)) | ((0x06) << 0) | ((sizeof(dev_name)) << ((0 +8)+8))), dev_name);
  printf("Input device name: \"%s\"\n", dev_name);
  return fd;
}

variable_types: fd int

user_defined_types: struct input_id { unsigned short bustype; unsigned short vendor; unsigned short product; unsigned short version; }