idle

decompiled_code:
__int64 idle()
{
animateGPU();
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 func2()
{
animateGPU();
return glutPostRedisplay();
}

original_code:
void idle(void)
{
 animateGPU();
 glutPostRedisplay();
}

canonical_original_code:
void idle()
{
 animateGPU();
 glutPostRedisplay();
}


appMotion

repo: uOptim/pmg-enseirb

decompiled_code:
__int64 __fastcall appMotion(int a1, int a2)
{
float v2; // xmm0_4
int v3; // xmm1_4
int v4; // xmm0_4
int v6; // xmm0_4

v2 = (float)(a2 - mouse_old_y);
if ( (mouse_buttons & 1) != 0 )
{
*(float *)&v3 = v2 * 0.2 + *(float *)&rotate_x;
rotate_x = v3;
*(float *)&v4 = (float)(a1 - mouse_old_x) * 0.2 + *(float *)&rotate_y;
rotate_y = v4;
}
else if ( (mouse_buttons & 4) != 0 )
{
*(float *)&v6 = v2 * 0.1 + *(float *)&translate_z;
translate_z = v6;
}
mouse_old_x = a1;
mouse_old_y = a2;
true_redisplay = 1;
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
float v2; // xmm0_4
int v3; // xmm1_4
int v4; // xmm0_4
int v6; // xmm0_4

v2 = (float)(a2 - mouse_old_y);
if ( (mouse_buttons & 1) != 0 )
{
*(float *)&v3 = v2 * 0.2 + *(float *)&rotate_x;
rotate_x = v3;
*(float *)&v4 = (float)(a1 - mouse_old_x) * 0.2 + *(float *)&rotate_y;
rotate_y = v4;
}
else if ( (mouse_buttons & 4) != 0 )
{
*(float *)&v6 = v2 * 0.1 + *(float *)&translate_z;
translate_z = v6;
}
mouse_old_x = a1;
mouse_old_y = a2;
true_redisplay = 1;
return glutPostRedisplay();
}

original_code:
void appMotion(int x, int y)
{
 float dx, dy;
 dx = x - mouse_old_x;
 dy = y - mouse_old_y;
 if (mouse_buttons & 1) {
  rotate_x += dy * 0.2;
  rotate_y += dx * 0.2;
 } else if (mouse_buttons & 4) {
  translate_z += dy * 0.1;
 }
 mouse_old_x = x;
 mouse_old_y = y;
 true_redisplay = 1;
 glutPostRedisplay();
}

canonical_original_code:
void appMotion(int x, int y)
{
 float dx; float dy;
 dx = x - mouse_old_x;
 dy = y - mouse_old_y;
 if (mouse_buttons & 1) {
  rotate_x += dy * 0.2;
  rotate_y += dx * 0.2;
 } else if (mouse_buttons & 4) {
  translate_z += dy * 0.1;
 }
 mouse_old_x = x;
 mouse_old_y = y;
 true_redisplay = 1;
 glutPostRedisplay();
}

variable_types: x int

variable_types: y int

variable_types: dx float

variable_types: dy float

return_type: void


timer

decompiled_code:
__int64 __fastcall timer(unsigned int a1)
{
animateGPU();
glutPostRedisplay();
return glutTimerFunc(TIMER_VAL, timer, a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
animateGPU();
glutPostRedisplay();
return glutTimerFunc(TIMER_VAL, timer, a1);
}

original_code:
void timer(int arg)
{
 animateGPU();
 glutPostRedisplay();
 glutTimerFunc(TIMER_VAL, timer, arg) ;
}

variable_types: arg int


drawScene

decompiled_code:
__int64 __fastcall drawScene(__int64 a1)
{
if ( true_redisplay )
{
glLoadIdentity();
gluLookAt(eye[0], eye[1], eye[2], center[0], center[1], center[2], up[0], up[1], a1);
glTranslatef(0.0, 0.0, *(float *)&translate_z);
glTranslatef(
COERCE_DOUBLE((unsigned __int64)LODWORD(center[0])),
COERCE_DOUBLE((unsigned __int64)LODWORD(center[1])),
center[2]);
glRotatef(*(float *)&rotate_x, 1.0, 0.0);
glRotatef(*(float *)&rotate_y, 0.0, COERCE_DOUBLE((unsigned __int64)LC3));
glTranslatef(
COERCE_DOUBLE(LODWORD(center[0]) ^ (unsigned __int64)(unsigned int)LC4),
COERCE_DOUBLE(LODWORD(center[1]) ^ (unsigned __int64)(unsigned int)LC4),
COERCE_FLOAT(LODWORD(center[2]) ^ LC4));
true_redisplay = 0;
}
renderAtoms();
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glBegin(6LL);
glColor4f(0.60000002, 0.60000002, 1.0, 0.40000001);
glVertex3f(center[0], min_ext[1], center[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], max_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(max_ext[0], min_ext[1], max_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(max_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
return glEnd();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( true_redisplay )
{
glLoadIdentity();
gluLookAt(eye[0], eye[1], eye[2], center[0], center[1], center[2], up[0], up[1], a1);
glTranslatef(0.0, 0.0, *(float *)&translate_z);
glTranslatef(
COERCE_DOUBLE((unsigned __int64)LODWORD(center[0])),
COERCE_DOUBLE((unsigned __int64)LODWORD(center[1])),
center[2]);
glRotatef(*(float *)&rotate_x, 1.0, 0.0);
glRotatef(*(float *)&rotate_y, 0.0, COERCE_DOUBLE((unsigned __int64)LC3));
glTranslatef(
COERCE_DOUBLE(LODWORD(center[0]) ^ (unsigned __int64)(unsigned int)LC4),
COERCE_DOUBLE(LODWORD(center[1]) ^ (unsigned __int64)(unsigned int)LC4),
COERCE_FLOAT(LODWORD(center[2]) ^ LC4));
true_redisplay = 0;
}
renderAtoms();
glEnable(3042LL);
glBlendFunc(770LL, 771LL);
glBegin(6LL);
glColor4f(0.60000002, 0.60000002, 1.0, 0.40000001);
glVertex3f(center[0], min_ext[1], center[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], max_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(max_ext[0], min_ext[1], max_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(max_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
glVertex3f(min_ext[0], min_ext[1], min_ext[2]);
glNormal3f(0.0, 1.0);
return glEnd();
}

original_code:
void drawScene() {
 if(true_redisplay) {
  glLoadIdentity();
  gluLookAt(
    (GLdouble)eye[0],(GLdouble)eye[1],(GLdouble)eye[2],
    (GLdouble)center[0],(GLdouble)center[1],(GLdouble)center[2],
    (GLdouble)up[0],(GLdouble)up[1],(GLdouble)up[2]);
  glTranslatef(0.0, 0.0, translate_z);
  glTranslatef(center[0], center[1], center[2]);
  glRotatef(rotate_x, 1.0, 0.0, 0.0);
  glRotatef(rotate_y, 0.0, 1.0, 0.0);
  glTranslatef(-center[0], -center[1], -center[2]);
  true_redisplay = 0;
 }
 renderAtoms();
 glEnable (0x0BE2);
 glBlendFunc (0x0302, 0x0303);
 glBegin(0x0006);
 glColor4f(.6f, 0.6f, 1.0f, 0.4f);
 glVertex3f(center[0], min_ext[1], center[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], max_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(max_ext[0], min_ext[1], max_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(max_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glEnd();
}

canonical_original_code:
void drawScene() {
 if(true_redisplay) {
  glLoadIdentity();
  gluLookAt(
    (double)eye[0],(double)eye[1],(double)eye[2],
    (double)center[0],(double)center[1],(double)center[2],
    (double)up[0],(double)up[1],(double)up[2]);
  glTranslatef(0.0, 0.0, translate_z);
  glTranslatef(center[0], center[1], center[2]);
  glRotatef(rotate_x, 1.0, 0.0, 0.0);
  glRotatef(rotate_y, 0.0, 1.0, 0.0);
  glTranslatef(-center[0], -center[1], -center[2]);
  true_redisplay = 0;
 }
 renderAtoms();
 glEnable (0x0BE2);
 glBlendFunc (0x0302, 0x0303);
 glBegin(0x0006);
 glColor4f(.6f, 0.6f, 1.0f, 0.4f);
 glVertex3f(center[0], min_ext[1], center[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], max_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(max_ext[0], min_ext[1], max_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(max_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glVertex3f(min_ext[0], min_ext[1], min_ext[2]); glNormal3f(0.0, 1.0, 0.0);
 glEnd();
}


display

decompiled_code:
__int64 display()
{
glClear(16640LL);
drawScene(16640LL);
return glutSwapBuffers();
}

canonical_decompiled_code:
__int64 func6()
{
glClear(16640LL);
func5(16640LL);
return glutSwapBuffers();
}

original_code:
void display()
{
 glClear(0x00004000|0x00000100);
 drawScene();
 glutSwapBuffers();
}


initView

original_code:
void initView (float *min_ext, float *max_ext)
{
 GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
 GLfloat light_position1[] = {0.5, 0.5, 1.0, 0.0};
 float dif_ext[3];
 int i;
 glLightfv(0x4000, 0x1201, light_diffuse);
 glLightfv(0x4000, 0x1203, light_position1);
 glEnable(0x0B50);
 glEnable(0x4000);
 glEnable(0x0B71);
 for (i=0; i<3; i++)
  dif_ext[i] = max_ext[i] - min_ext[i];
 dis = 0.0;
 for (i=0; i<3; i++)
  dis += dif_ext[i]*dif_ext[i];
 dis = (float)sqrt((double)dis);
 for (i=0; i<3; i++)
  center[i] = min_ext[i] + dif_ext[i]/2.0;
 eye[0] = center[0];
 eye[1] = center[1];
 eye[2] = center[2] + dis;
 up[0] = 0.0;
 up[1] = 1.0;
 up[2] = 0.0;
 near_clip = (GLdouble)( 0.5*(dis-0.5*dif_ext[2]) );
 far_clip = (GLdouble)( 2.0*(dis+0.5*dif_ext[2]) );
 fovy = (GLdouble)( 0.5*dif_ext[1]/(dis-0.5*dif_ext[2]) );
 fovy = (GLdouble)( 2*atan((double)fovy)/3.14159265358979323846*180.0 );
 fovy = (GLdouble)(1.2*fovy);
 glEnable(0x0B57);
}

canonical_original_code:
void initView(float *min_ext, float *max_ext)
{
 float light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
 float light_position1[] = {0.5, 0.5, 1.0, 0.0};
 float dif_ext[3];
 int i;
 glLightfv(0x4000, 0x1201, light_diffuse);
 glLightfv(0x4000, 0x1203, light_position1);
 glEnable(0x0B50);
 glEnable(0x4000);
 glEnable(0x0B71);
 for (i=0; i<3; i++)
  dif_ext[i] = max_ext[i] - min_ext[i];
 dis = 0.0;
 for (i=0; i<3; i++)
  dis += dif_ext[i]*dif_ext[i];
 dis = (float)sqrt((double)dis);
 for (i=0; i<3; i++)
  center[i] = min_ext[i] + dif_ext[i]/2.0;
 eye[0] = center[0];
 eye[1] = center[1];
 eye[2] = center[2] + dis;
 up[0] = 0.0;
 up[1] = 1.0;
 up[2] = 0.0;
 near_clip = (GLdouble)( 0.5*(dis-0.5*dif_ext[2]) );
 far_clip = (GLdouble)( 2.0*(dis+0.5*dif_ext[2]) );
 fovy = (GLdouble)( 0.5*dif_ext[1]/(dis-0.5*dif_ext[2]) );
 fovy = (GLdouble)( 2*atan((double)fovy)/3.14159265358979323846*180.0 );
 fovy = (GLdouble)(1.2*fovy);
 glEnable(0x0B57);
}

variable_types: i int


appDestroy

decompiled_code:
void __noreturn appDestroy()
{
atomFinalize();
ocl_finalize();
vboFinalize();
if ( glutWindowHandle )
glutDestroyWindow();
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
atomFinalize();
ocl_finalize();
vboFinalize();
if ( glutWindowHandle )
glutDestroyWindow();
exit(0);
}

original_code:
void appDestroy()
{
 atomFinalize();
 ocl_finalize();
 vboFinalize();
 if(glutWindowHandle)
  glutDestroyWindow(glutWindowHandle);
 exit(0);
}


decompiled_code:
__int64 __fastcall change_skin(unsigned int a1)
{
ocl_readAtomCoordinatesFromAccel();
clearVBO();
setAtomsSkin(a1);
buildAtoms();
updateAtomCoordinatesToAccel();
resetAnimation();
return glutPostRedisplay();
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1)
{
ocl_readAtomCoordinatesFromAccel();
clearVBO();
setAtomsSkin(a1);
buildAtoms();
updateAtomCoordinatesToAccel();
resetAnimation();
return glutPostRedisplay();
}

original_code:
void change_skin(atom_skin_t skin)
{
 ocl_readAtomCoordinatesFromAccel();
 clearVBO();
 setAtomsSkin(skin);
 buildAtoms();
 updateAtomCoordinatesToAccel();
 resetAnimation();
 glutPostRedisplay();
}

canonical_original_code:
void change_skin(enum atom_skin_t skin)
{
 ocl_readAtomCoordinatesFromAccel();
 clearVBO();
 setAtomsSkin(skin);
 buildAtoms();
 updateAtomCoordinatesToAccel();
 resetAnimation();
 glutPostRedisplay();
}

variable_types: enum atom_skin_t { SPHERE_SKIN=0, PACMAN_SKIN=1 }


appKeyboard

decompiled_code:
int __fastcall appKeyboard(char a1)
{
__int64 v1; // rdi
int v2; // xmm0_4
int result; // eax
int v4; // xmm0_4
unsigned __int64 v5; // rdx

v1 = (unsigned __int8)(a1 - 13);
switch ( (char)v1 )
{
case 0:
case 14:
case 68:
case 100:
appDestroy(v1);
return result;
case 30:
result = -858993459 * TIMER_VAL;
TIMER_VAL -= TIMER_VAL / 0xAuLL;
break;
case 32:
v5 = 1LL;
if ( TIMER_VAL > 9uLL )
{
result = -858993459 * TIMER_VAL;
v5 = TIMER_VAL / 0xAuLL;
}
TIMER_VAL += v5;
break;
case 47:
*(float *)&v2 = *(float *)&translate_z - 0.1;
translate_z = v2;
true_redisplay = 1;
result = glutPostRedisplay();
break;
case 49:
*(float *)&v4 = *(float *)&translate_z + 0.1;
translate_z = v4;
true_redisplay = 1;
result = glutPostRedisplay();
break;
case 54:
case 86:
detect_collision = 1 - detect_collision;
result = printf("collision detect: %d\n", detect_collision);
break;
case 56:
case 88:
eating_enabled = 1 - eating_enabled;
result = printf("eating mode: %d\n", eating_enabled);
break;
case 57:
case 89:
force_enabled = 1 - force_enabled;
result = printf("force: %d\n", force_enabled);
break;
case 58:
case 90:
gravity_enabled = 1 - gravity_enabled;
result = printf("gravity: %d\n", gravity_enabled);
break;
case 64:
case 96:
move_enabled = 1 - move_enabled;
result = printf("move: %d\n", move_enabled);
break;
case 65:
case 97:
result = change_skin(0);
break;
case 67:
case 99:
result = change_skin(1u);
break;
case 77:
case 109:
result = zeroSpeeds();
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(char a1)
{
__int64 v1; // rdi
int v2; // xmm0_4
int result; // eax
int v4; // xmm0_4
unsigned __int64 v5; // rdx

v1 = (unsigned __int8)(a1 - 13);
switch ( (char)v1 )
{
case 0:
case 14:
case 68:
case 100:
func8(v1);
return result;
case 30:
result = -858993459 * TIMER_VAL;
TIMER_VAL -= TIMER_VAL / 0xAuLL;
break;
case 32:
v5 = 1LL;
if ( TIMER_VAL > 9uLL )
{
result = -858993459 * TIMER_VAL;
v5 = TIMER_VAL / 0xAuLL;
}
TIMER_VAL += v5;
break;
case 47:
*(float *)&v2 = *(float *)&translate_z - 0.1;
translate_z = v2;
true_redisplay = 1;
result = glutPostRedisplay();
break;
case 49:
*(float *)&v4 = *(float *)&translate_z + 0.1;
translate_z = v4;
true_redisplay = 1;
result = glutPostRedisplay();
break;
case 54:
case 86:
detect_collision = 1 - detect_collision;
result = printf("collision detect: %d\n", detect_collision);
break;
case 56:
case 88:
eating_enabled = 1 - eating_enabled;
result = printf("eating mode: %d\n", eating_enabled);
break;
case 57:
case 89:
force_enabled = 1 - force_enabled;
result = printf("force: %d\n", force_enabled);
break;
case 58:
case 90:
gravity_enabled = 1 - gravity_enabled;
result = printf("gravity: %d\n", gravity_enabled);
break;
case 64:
case 96:
move_enabled = 1 - move_enabled;
result = printf("move: %d\n", move_enabled);
break;
case 65:
case 97:
result = func9(0);
break;
case 67:
case 99:
result = func9(1u);
break;
case 77:
case 109:
result = zeroSpeeds();
break;
default:
return result;
}
return result;
}

original_code:
void appKeyboard(unsigned char key, int x, int y)
{
 switch(key)
 {
  case '<' : translate_z -= 0.1; true_redisplay = 1; glutPostRedisplay(); break;
  case '>' : translate_z += 0.1; true_redisplay = 1; glutPostRedisplay(); break;
  case '+' : TIMER_VAL = TIMER_VAL - TIMER_VAL/10; break;
  case '-' : TIMER_VAL = TIMER_VAL + (TIMER_VAL/10 ? : 1); break;
  case 'e' :
  case 'E' : eating_enabled = 1 - eating_enabled;
       printf("eating mode: %d\n", eating_enabled); break;
  case 'n' :
  case 'N' : change_skin(SPHERE_SKIN); break;
  case 'p' :
  case 'P' : change_skin(PACMAN_SKIN); break;
  case 'z' :
  case 'Z' : zeroSpeeds(); break;
  case 'm' :
  case 'M' : move_enabled = 1 - move_enabled;
       printf("move: %d\n", move_enabled); break;
  case 'f' :
  case 'F' : force_enabled = 1 - force_enabled;
       printf("force: %d\n", force_enabled); break;
  case 'g' :
  case 'G' : gravity_enabled = 1 - gravity_enabled;
       printf("gravity: %d\n", gravity_enabled); break;
  case 'c' :
  case 'C' : detect_collision = 1 - detect_collision;
       printf("collision detect: %d\n", detect_collision); break;
  case '\033':
  case '\015':
  case 'Q':
  case 'q':
       appDestroy();
       break;
 }
}

variable_types:
key
unsigned char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int v4; // ebx
const char *v5; // r12
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v7[0] = argc;
glutInit(v7, argv, envp);
v3 = argv + 1;
v4 = v7[0];
if ( v7[0] <= 1 )
goto LABEL_21;
while ( 1 )
{
v5 = *v3;
if ( strcmp(*v3, "--full-speed") )
{
if ( strcmp(*v3, "-fs") )
break;
}
full_speed = 1;
LABEL_4:
v7[0] = --v4;
++v3;
if ( v4 == 1 )
goto LABEL_21;
}
if ( !strcmp(*v3, "--move") || !strcmp(*v3, "-m") )
{
move_enabled = 1;
goto LABEL_4;
}
if ( !strcmp(*v3, "--collision") || !strcmp(*v3, "-c") )
{
detect_collision = 1;
move_enabled = 1;
goto LABEL_4;
}
if ( !strcmp(v5, "--gravity") || !strcmp(v5, "-g") )
{
gravity_enabled = 1;
move_enabled = 1;
goto LABEL_4;
}
if ( !strcmp(v5, "--leonnard-force") || !strcmp(v5, "-lf") )
{
force_enabled = 1;
move_enabled = 1;
goto LABEL_4;
}
if ( v4 > 1 )
MD_FILE = *v3;
LABEL_21:
initializeAtoms();
glutInitDisplayMode(18LL);
glutInitWindowSize((unsigned int)winx, (unsigned int)winy);
glutWindowHandle = glutCreateWindow("Lennard-Jones Atoms");
initView((__int64)min_ext, (__int64)max_ext);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
if ( full_speed )
glutIdleFunc(idle);
else
glutTimerFunc(TIMER_VAL, timer, 0LL);
glutKeyboardFunc(appKeyboard);
glutMouseFunc(appMouse);
glutMotionFunc(appMotion);
buildAtoms();
buildVBO();
printf(
"#atoms = %d, #vertices = %d, #triangles = %d, #vertices per atom = %d\n",
natoms,
nb_vertices,
nb_indexes / 3uLL,
vertices_per_atom);
initializeComputeDevices();
glutMainLoop();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int v4; // ebx
const char *v5; // r12
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v7[0] = argc;
glutInit(v7, argv, envp);
v3 = argv + 1;
v4 = v7[0];
if ( v7[0] <= 1 )
goto LABEL_21;
while ( 1 )
{
v5 = *v3;
if ( strcmp(*v3, "--full-speed") )
{
if ( strcmp(*v3, "-fs") )
break;
}
full_speed = 1;
LABEL_4:
v7[0] = --v4;
++v3;
if ( v4 == 1 )
goto LABEL_21;
}
if ( !strcmp(*v3, "--move") || !strcmp(*v3, "-m") )
{
move_enabled = 1;
goto LABEL_4;
}
if ( !strcmp(*v3, "--collision") || !strcmp(*v3, "-c") )
{
detect_collision = 1;
move_enabled = 1;
goto LABEL_4;
}
if ( !strcmp(v5, "--gravity") || !strcmp(v5, "-g") )
{
gravity_enabled = 1;
move_enabled = 1;
goto LABEL_4;
}
if ( !strcmp(v5, "--leonnard-force") || !strcmp(v5, "-lf") )
{
force_enabled = 1;
move_enabled = 1;
goto LABEL_4;
}
if ( v4 > 1 )
MD_FILE = *v3;
LABEL_21:
initializeAtoms();
glutInitDisplayMode(18LL);
glutInitWindowSize((unsigned int)winx, (unsigned int)winy);
glutWindowHandle = glutCreateWindow("Lennard-Jones Atoms");
func7((__int64)min_ext, (__int64)max_ext);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
if ( full_speed )
glutIdleFunc(idle);
else
glutTimerFunc(TIMER_VAL, timer, 0LL);
glutKeyboardFunc(appKeyboard);
glutMouseFunc(appMouse);
glutMotionFunc(appMotion);
buildAtoms();
buildVBO();
printf(
"#atoms = %d, #vertices = %d, #triangles = %d, #vertices per atom = %d\n",
natoms,
nb_vertices,
nb_indexes / 3uLL,
vertices_per_atom);
initializeComputeDevices();
glutMainLoop();
return 0;
}

original_code:
int main(int argc, char **argv)
{
 glutInit(&argc, argv);
 argv++;
 while (argc > 1) {
  if(!strcmp(*argv, "--full-speed") || !strcmp(*argv, "-fs")) {
   full_speed = 1;
  }
  else if(!strcmp(*argv, "--move") || !strcmp(*argv, "-m")) {
   move_enabled = 1;
  }
  else if(!strcmp(*argv, "--collision") || !strcmp(*argv, "-c")) {
   detect_collision = 1;
   move_enabled = 1;
  }
  else if(!strcmp(*argv, "--gravity") || !strcmp(*argv, "-g")) {
   gravity_enabled = 1;
   move_enabled = 1;
  }
  else if(!strcmp(*argv, "--leonnard-force") || !strcmp(*argv, "-lf")) {
   force_enabled = 1;
   move_enabled = 1;
  }
  else
   break;
  argc--; argv++;
 }
 if(argc > 1)
  MD_FILE = *argv;
 initializeAtoms();
 unsigned int display_mode = 0x0000|0x0010|0x0002;
 glutInitDisplayMode(display_mode);
 glutInitWindowSize(winx, winy);
 glutWindowHandle = glutCreateWindow("Lennard-Jones Atoms");
 initView(min_ext, max_ext);
 glutDisplayFunc(display);
 glutReshapeFunc(reshape);
 if(full_speed)
  glutIdleFunc(idle);
 else
  glutTimerFunc(TIMER_VAL, timer, 0);
 glutKeyboardFunc(appKeyboard);
 glutMouseFunc(appMouse);
 glutMotionFunc(appMotion);
 buildAtoms();
 buildVBO();
 printf("#atoms = %d, #vertices = %d, #triangles = %d, #vertices per atom = %d\n",
   natoms, nb_vertices, nb_indexes/3, vertices_per_atom);
 initializeComputeDevices();
 glutMainLoop();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
__off_t __fastcall file_size(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) < 0 )
{
perror("stat");
abort();
}
return v2.st_size;
}

canonical_decompiled_code:
__off_t __fastcall func0(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

if ( stat(a1, &v2) < 0 )
{
perror("stat");
abort();
}
return v2.st_size;
}

original_code:
static size_t file_size(const char *filename) {
 struct stat sb;
 if (stat(filename, &sb) < 0) {
  perror ("stat");
  abort ();
 }
 return sb.st_size;
}

canonical_original_code:
static unsigned long file_size(char *filename) {
 struct stat sb;
 if (stat(filename, &sb) < 0) {
  perror ("stat");
  abort ();
 }
 return sb.st_size;
}

variable_types:
filename
char *

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

return_type: unsigned long


decompiled_code:
__int64 ocl_readAtomCoordinatesFromAccel()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned int v2; // eax

v0 = atomPosAddr();
v1 = atomPosSize();
v2 = clEnqueueReadBuffer(queue, pos_buffer, 1LL, 0LL, v1, v0, 0LL, 0LL, 0LL);
if ( v2 )
{
fprintf(stderr, "(%d) Error: Failed to read from atom positions array!\n", v2);
exit(1);
}
return clFinish(queue);
}

canonical_decompiled_code:
__int64 func4()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned int v2; // eax

v0 = atomPosAddr();
v1 = atomPosSize();
v2 = clEnqueueReadBuffer(queue, pos_buffer, 1LL, 0LL, v1, v0, 0LL, 0LL, 0LL);
if ( v2 )
{
fprintf(stderr, "(%d) Error: Failed to read from atom positions array!\n", v2);
exit(1);
}
return clFinish(queue);
}

original_code:
void ocl_readAtomCoordinatesFromAccel(void)
{
 cl_int err;
 err = clEnqueueReadBuffer(queue, pos_buffer, 1, 0,
   atomPosSize(), atomPosAddr(), 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to read from atom positions array!\n", err); exit(1); } } while(0);
 clFinish(queue);
}

canonical_original_code:
void ocl_readAtomCoordinatesFromAccel()
{
 int err;
 err = clEnqueueReadBuffer(queue, pos_buffer, 1, 0,
   atomPosSize(), atomPosAddr(), 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to read from atom positions array!\n", err); exit(1); } } while(0);
 clFinish(queue);
}

variable_types: err int


decompiled_code:
__int64 ocl_readAtomSpeedFromAccel()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned int v2; // eax

v0 = atomSpeedAddr();
v1 = atomSpeedSize();
v2 = clEnqueueReadBuffer(queue, speed_buffer, 1LL, 0LL, v1, v0, 0LL, 0LL, 0LL);
if ( v2 )
{
fprintf(stderr, "(%d) Error: Failed to read from atom speeds array!\n", v2);
exit(1);
}
return clFinish(queue);
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbx
__int64 v1; // rax
unsigned int v2; // eax

v0 = atomSpeedAddr();
v1 = atomSpeedSize();
v2 = clEnqueueReadBuffer(queue, speed_buffer, 1LL, 0LL, v1, v0, 0LL, 0LL, 0LL);
if ( v2 )
{
fprintf(stderr, "(%d) Error: Failed to read from atom speeds array!\n", v2);
exit(1);
}
return clFinish(queue);
}

original_code:
void ocl_readAtomSpeedFromAccel(void)
{
 cl_int err;
 err = clEnqueueReadBuffer(queue, speed_buffer, 1, 0,
   atomSpeedSize(), atomSpeedAddr(), 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to read from atom speeds array!\n", err); exit(1); } } while(0);
 clFinish(queue);
}

canonical_original_code:
void ocl_readAtomSpeedFromAccel()
{
 int err;
 err = clEnqueueReadBuffer(queue, speed_buffer, 1, 0,
   atomSpeedSize(), atomSpeedAddr(), 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to read from atom speeds array!\n", err); exit(1); } } while(0);
 clFinish(queue);
}


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

glFinish();
v0 = clEnqueueAcquireGLObjects(queue, 1LL, &vbo_buffer, 0LL, 0LL, 0LL);
if ( v0 )
{
fprintf(stderr, "(%d) Error: Failed to acquire lock!\n", v0);
exit(1);
}
v1 = clEnqueueWriteBuffer(queue, vbo_buffer, 1LL, 0LL, 12LL * nb_vertices, &vbo_vertex, 0LL, 0LL, 0LL);
if ( v1 )
{
fprintf(stderr, "(%d) Error: Failed to write to vbo_buffer array!\n", v1);
exit(1);
}
clFinish(queue);
result = clEnqueueReleaseGLObjects(queue, 1LL, &vbo_buffer, 0LL, 0LL, 0LL);
if ( (_DWORD)result )
{
fprintf(stderr, "(%d) Error: Failed to release lock!\n", (unsigned int)result);
exit(1);
}
return result;
}

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

glFinish();
v0 = clEnqueueAcquireGLObjects(queue, 1LL, &vbo_buffer, 0LL, 0LL, 0LL);
if ( v0 )
{
fprintf(stderr, "(%d) Error: Failed to acquire lock!\n", v0);
exit(1);
}
v1 = clEnqueueWriteBuffer(queue, vbo_buffer, 1LL, 0LL, 12LL * nb_vertices, &vbo_vertex, 0LL, 0LL, 0LL);
if ( v1 )
{
fprintf(stderr, "(%d) Error: Failed to write to vbo_buffer array!\n", v1);
exit(1);
}
clFinish(queue);
result = clEnqueueReleaseGLObjects(queue, 1LL, &vbo_buffer, 0LL, 0LL, 0LL);
if ( (_DWORD)result )
{
fprintf(stderr, "(%d) Error: Failed to release lock!\n", (unsigned int)result);
exit(1);
}
return result;
}

original_code:
void ocl_updateVBOFromHost(void)
{
 cl_int err;
 glFinish();
 err = clEnqueueAcquireGLObjects(queue, 1, &vbo_buffer, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to acquire lock!\n", err); exit(1); } } while(0);
 err = clEnqueueWriteBuffer(queue, vbo_buffer, 1, 0,
   sizeof(float) * 3 * nb_vertices, vbo_vertex, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to write to vbo_buffer array!\n", err); exit(1); } } while(0);
 clFinish(queue);
 err = clEnqueueReleaseGLObjects(queue, 1, &vbo_buffer, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to release lock!\n", err); exit(1); } } while(0);
}

canonical_original_code:
void ocl_updateVBOFromHost()
{
 int err;
 glFinish();
 err = clEnqueueAcquireGLObjects(queue, 1, &vbo_buffer, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to acquire lock!\n", err); exit(1); } } while(0);
 err = clEnqueueWriteBuffer(queue, vbo_buffer, 1, 0,
   sizeof(float) * 3 * nb_vertices, vbo_vertex, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to write to vbo_buffer array!\n", err); exit(1); } } while(0);
 clFinish(queue);
 err = clEnqueueReleaseGLObjects(queue, 1, &vbo_buffer, 0, ((void *)0), ((void *)0));
 do { if(err != 0) { fprintf(stderr, "(%d) Error: " "Failed to release lock!\n", err); exit(1); } } while(0);
}


decompiled_code:
__int64 ocl_finalize()
{
clReleaseMemObject(vbo_buffer);
clReleaseMemObject(min_buffer);
clReleaseMemObject(max_buffer);
clReleaseMemObject(pos_buffer);
clReleaseMemObject(speed_buffer);
clReleaseCommandQueue(queue);
clReleaseProgram(program);
return clReleaseContext(context);
}

canonical_decompiled_code:
__int64 func7()
{
clReleaseMemObject(vbo_buffer);
clReleaseMemObject(min_buffer);
clReleaseMemObject(max_buffer);
clReleaseMemObject(pos_buffer);
clReleaseMemObject(speed_buffer);
clReleaseCommandQueue(queue);
clReleaseProgram(program);
return clReleaseContext(context);
}

original_code:
void ocl_finalize(void)
{
 clReleaseMemObject(vbo_buffer);
 clReleaseMemObject(min_buffer);
 clReleaseMemObject(max_buffer);
 clReleaseMemObject(pos_buffer);
 clReleaseMemObject(speed_buffer);
 clReleaseCommandQueue(queue);
 clReleaseProgram(program);
 clReleaseContext(context);
}

canonical_original_code:
void ocl_finalize()
{
 clReleaseMemObject(vbo_buffer);
 clReleaseMemObject(min_buffer);
 clReleaseMemObject(max_buffer);
 clReleaseMemObject(pos_buffer);
 clReleaseMemObject(speed_buffer);
 clReleaseCommandQueue(queue);
 clReleaseProgram(program);
 clReleaseContext(context);
}


putsI

repo: uOptim/rubic-enseirb

decompiled_code:
int __fastcall putsI(unsigned int a1)
{
return printf("%d\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(unsigned int a1)
{
return printf("%d\n", a1);
}

original_code:
int32_t putsI(int32_t i) {
 return printf("%d\n", i);
}

canonical_original_code:
int putsI(int i) {
 return printf("%d\n", i);
}


putsF

decompiled_code:
int __fastcall putsF(double a1)
{
return printf("%lf\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(double a1)
{
return printf("%lf\n", a1);
}

original_code:
int32_t putsF(double f) {
 return printf("%lf\n", f);
}

canonical_original_code:
int putsF(double f) {
 return printf("%lf\n", f);
}

variable_types: f double


putsB

decompiled_code:
int __fastcall putsB(char a1)
{
int result; // eax

if ( a1 )
result = printf("true\n");
else
result = printf("false\n");
return result;
}

canonical_decompiled_code:
int __fastcall func2(char a1)
{
int result; // eax

if ( a1 )
result = printf("true\n");
else
result = printf("false\n");
return result;
}

original_code:
int32_t putsB(int8_t b) {
 if (b == 0) {
  return printf("false\n");
 }
 else {
  return printf("true\n");
 }
}

canonical_original_code:
int putsB(char b) {
 if (b == 0) {
  return printf("false\n");
 }
 else {
  return printf("true\n");
 }
}

variable_types: b char


putsS

decompiled_code:
int __fastcall putsS(const char *a1)
{
return printf("%s\n", a1);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1)
{
return printf("%s\n", a1);
}

original_code:
int32_t putsS(char * s) {
 return printf("%s\n", s);
}

canonical_original_code:
int putsS(char *s) {
 return printf("%s\n", s);
}

variable_types:
s
char *


hash

original_code:
static size_t hash(const char *key)
{
 size_t n = 0;
 const char *p = key;
 for (; *p != '\0'; p++) {
  n += *p;
 }
 return n % 512;
}

canonical_original_code:
static unsigned long hash(char *key)
{
 unsigned long n = 0;
 char *p = key;
 for (; *p != '\0'; p++) {
  n += *p;
 }
 return n % 512;
}

variable_types:
key
char *

variable_types:
n
unsigned long

variable_types:
p
char *


original_code:
void hashmap_free(struct hashmap **h, void (*free_data)(void *))
{
 unsigned int idx;
 struct cell *cur, *tmp;
 for (idx = 0; idx < 512; idx++) {
  cur = (*h)->array[idx];
  while (cur != ((void *)0)) {
   tmp = cur->next;
   free(cur->key);
   if (free_data != ((void *)0)) free_data(cur->data);
   free(cur);
   cur = tmp;
  }
 }
 free((*h)->array);
 free(*h);
 *h = ((void *)0);
}

canonical_original_code:
void hashmap_free(struct hashmap **h, void (*free_data)(void *))
{
 unsigned int idx;
 struct cell *cur; struct cell *tmp;
 for (idx = 0; idx < 512; idx++) {
  cur = (*h)->array[idx];
  while (cur != ((void *)0)) {
   tmp = cur->next;
   free(cur->key);
   if (free_data != ((void *)0)) free_data(cur->data);
   free(cur);
   cur = tmp;
  }
 }
 free((*h)->array);
 free(*h);
 *h = ((void *)0);
}

variable_types: struct hashmap { struct cell { void *data; char *key; struct cell *next; } **array; } **

variable_types:
idx
unsigned int


decompiled_code:
_QWORD *hashmap_new()
{
_QWORD *v0; // rbx
void *v1; // rbp

v0 = malloc(8uLL);
if ( v0 )
{
v1 = calloc(0x200uLL, 8uLL);
*v0 = v1;
if ( !v1 )
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // rbx
void *v1; // rbp

v0 = malloc(8uLL);
if ( v0 )
{
v1 = calloc(0x200uLL, 8uLL);
*v0 = v1;
if ( !v1 )
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

original_code:
struct hashmap * hashmap_new()
{
 struct hashmap *h = malloc(sizeof *h);
 if (h == ((void *)0))
  return ((void *)0);
 h->array = calloc(512, sizeof *h->array);
 if (h->array == ((void *)0)) {
  free(h);
  return ((void *)0);
 }
 return h;
}

canonical_original_code:
struct hashmap *hashmap_new()
{
 struct hashmap *h = malloc(sizeof *h);
 if (h == ((void *)0))
  return ((void *)0);
 h->array = calloc(512, sizeof *h->array);
 if (h->array == ((void *)0)) {
  free(h);
  return ((void *)0);
 }
 return h;
}

variable_types: struct hashmap { struct cell { void *data; char *key; struct cell *next; } **array; } *


decompiled_code:
__int64 __fastcall hashmap_set(_QWORD *a1, char *a2, __int64 a3)
{
__int64 v4; // rbp
_QWORD *v5; // rax
__int64 v6; // rdx

v4 = hash(a2);
v5 = cell_new(a2, a3);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = *(_QWORD *)(*a1 + 8 * v4);
if ( v6 )
v5[2] = v6;
*(_QWORD *)(*a1 + 8 * v4) = v5;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, char *a2, __int64 a3)
{
__int64 v4; // rbp
_QWORD *v5; // rax
__int64 v6; // rdx

v4 = func0(a2);
v5 = cell_new(a2, a3);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = *(_QWORD *)(*a1 + 8 * v4);
if ( v6 )
v5[2] = v6;
*(_QWORD *)(*a1 + 8 * v4) = v5;
return 0LL;
}

original_code:
int hashmap_set(struct hashmap *h, const char *k, void *v)
{
 size_t idx = hash(k);
 struct cell *c = cell_new(k, v);
 if (c == ((void *)0)) return -1;
 if (h->array[idx] != ((void *)0)) {
  c->next = h->array[idx];
 }
 h->array[idx] = c;
 return 0;
}

canonical_original_code:
int hashmap_set(struct hashmap *h, char *k, void *v)
{
 unsigned long idx = hash(k);
 struct cell *c = cell_new(k, v);
 if (c == ((void *)0)) return -1;
 if (h->array[idx] != ((void *)0)) {
  c->next = h->array[idx];
 }
 h->array[idx] = c;
 return 0;
}

variable_types:
k
char *

variable_types:
v
void *

variable_types:
idx
unsigned long

variable_types: struct cell { void *data; char *key; struct cell *next; } *


decompiled_code:
__int64 __fastcall hashmap_dump(__int64 *a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 i; // r12
__int64 result; // rax
__int64 j; // rbx

for ( i = 0LL; i != 4096; i += 8LL )
{
result = *a1;
for ( j = *(_QWORD *)(*a1 + i); j; j = *(_QWORD *)(j + 16) )
{
printf("Key: %s\n", *(const char **)(j + 8));
result = a2(*(_QWORD *)j);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 i; // r12
__int64 result; // rax
__int64 j; // rbx

for ( i = 0LL; i != 4096; i += 8LL )
{
result = *a1;
for ( j = *(_QWORD *)(*a1 + i); j; j = *(_QWORD *)(j + 16) )
{
printf("Key: %s\n", *(const char **)(j + 8));
result = a2(*(_QWORD *)j);
}
}
return result;
}

original_code:
void hashmap_dump(struct hashmap *h, void (*dump_data)(void *))
{
 unsigned int idx;
 struct cell *cur;
 for (idx = 0; idx < 512; idx++) {
  cur = h->array[idx];
  while (cur != ((void *)0)) {
   printf("Key: %s\n", cur->key);
   dump_data(cur->data);
   cur = cur->next;
  }
 }
}

user_defined_types: struct cell { void *data; char *key; struct cell *next; }


decompiled_code:
void __fastcall cst_free(void *ptr)
{
if ( *(_DWORD *)ptr == 3 )
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func10(void *ptr)
{
if ( *(_DWORD *)ptr == 3 )
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void cst_free(void *cst)
{
 struct cst *c = (struct cst *) cst;
 if (c->type == 3) {
  free(c->s);
  c->s = ((void *)0);
 }
 free(cst);
}

variable_types:
cst
void *

variable_types: struct cst { unsigned int type; union { int i; char c; double f; char *s; unsigned int o; }; } *


decompiled_code:
int __fastcall cst_dump(double *a1)
{
int v1; // eax

puts("Constant:");
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 1 )
return printf("* type: float, value: %g\n", a1[1]);
if ( v1 == 2 )
return printf("* type: bool, value: %i\n", (unsigned int)*((char *)a1 + 8));
if ( v1 )
return puts("Type Unknown");
return printf("* type: int, value: %d\n", *((unsigned int *)a1 + 2));
}

canonical_decompiled_code:
int __fastcall func13(double *a1)
{
int v1; // eax

puts("Constant:");
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 1 )
return printf("* type: float, value: %g\n", a1[1]);
if ( v1 == 2 )
return printf("* type: bool, value: %i\n", (unsigned int)*((char *)a1 + 8));
if ( v1 )
return puts("Type Unknown");
return printf("* type: int, value: %d\n", *((unsigned int *)a1 + 2));
}

original_code:
void cst_dump(const struct cst *c)
{
 puts("Constant:");
 switch (c->type) {
  case 0:
   printf("* type: int, value: %d\n", c->i);
   break;
  case 1:
   printf("* type: float, value: %g\n", c->f);
   break;
  case 2:
   printf("* type: bool, value: %i\n", c->c);
   break;
  default:
   printf("Type Unknown\n");
 }
}

canonical_original_code:
void cst_dump(struct cst *c)
{
 puts("Constant:");
 switch (c->type) {
  case 0:
   printf("* type: int, value: %d\n", c->i);
   break;
  case 1:
   printf("* type: float, value: %g\n", c->f);
   break;
  case 2:
   printf("* type: bool, value: %i\n", c->c);
   break;
  default:
   printf("Type Unknown\n");
 }
}

user_defined_types: struct cst { unsigned int type; union { int i; char c; double f; char *s; unsigned int o; }; }


decompiled_code:
__int64 __fastcall type_copy(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1;
}

original_code:
void * type_copy(void *type) {
 return type;
}

canonical_original_code:
void *type_copy(void *type) {
 return type;
}

variable_types:
type
void *

return_type: void *


decompiled_code:
__int64 type_new()
{
return (unsigned int)id_0++;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)id_0++;
}

original_code:
type_t type_new(void) {
 static type_t id = 4;
 return id++;
}

canonical_original_code:
unsigned int type_new() {
 static unsigned int id = 4;
 return id++;
}

variable_types:
id
unsigned int

return_type: unsigned int


decompiled_code:
_QWORD *stack_new()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
*(_DWORD *)v0 = 0;
v0[1] = 0LL;
v0[2] = 0LL;
}
else
{
perror("malloc");
}
return v1;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
*(_DWORD *)v0 = 0;
v0[1] = 0LL;
v0[2] = 0LL;
}
else
{
perror("malloc");
}
return v1;
}

original_code:
struct stack * stack_new()
{
 struct stack *s = malloc(sizeof *s);
 if (s == ((void *)0)) {
  perror("malloc");
 } else {
  s->size = 0;
  s->head = ((void *)0);
  s->cursor = ((void *)0);
 }
 return s;
}

canonical_original_code:
struct stack *stack_new()
{
 struct stack *s = malloc(sizeof *s);
 if (s == ((void *)0)) {
  perror("malloc");
 } else {
  s->size = 0;
  s->head = ((void *)0);
  s->cursor = ((void *)0);
 }
 return s;
}

variable_types: struct stack { int size; struct elt { void *data; struct elt *next; } *head; struct elt *cursor; } *

user_defined_types: struct stack { int size; struct elt *head; struct elt *cursor; }


decompiled_code:
void __fastcall stack_free(__int64 *a1, void (__fastcall *a2)(_QWORD *))
{
stack_clear(*a1, a2);
free((void *)*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(__int64 *a1, void (__fastcall *a2)(_QWORD *))
{
stack_clear(*a1, a2);
free((void *)*a1);
*a1 = 0LL;
}

original_code:
void stack_free(struct stack **s, void (*free_data)(void *))
{
 stack_clear(*s, free_data);
 free(*s);
 *s = ((void *)0);
}

variable_types: struct stack { int size; struct elt { void *data; struct elt *next; } *head; struct elt *cursor; } **


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

v2 = malloc(0x10uLL);
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 8);
if ( !v3 )
*(_QWORD *)(a1 + 16) = v2;
*v2 = a2;
v2[1] = v3;
*(_QWORD *)(a1 + 8) = v2;
++*(_DWORD *)a1;
result = 0LL;
}
else
{
perror("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

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

v2 = malloc(0x10uLL);
if ( v2 )
{
v3 = *(_QWORD *)(a1 + 8);
if ( !v3 )
*(_QWORD *)(a1 + 16) = v2;
*v2 = a2;
v2[1] = v3;
*(_QWORD *)(a1 + 8) = v2;
++*(_DWORD *)a1;
result = 0LL;
}
else
{
perror("malloc");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int stack_push(struct stack *s, void *d)
{
 struct elt *e = malloc(sizeof *e);
 if (e == ((void *)0)) {
  perror("malloc");
  return -1;
 }
 if (s->head == ((void *)0)) {
  s->cursor = e;
 }
 e->data = d;
 e->next = s->head;
 s->head = e;
 s->size++;
 return 0;
}

variable_types:
d
void *

variable_types: struct elt { void *data; struct elt *next; } *


decompiled_code:
__int64 __fastcall stack_size(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int *a1)
{
return *a1;
}

original_code:
int stack_size(struct stack *s) {
 return s->size;
}

user_defined_types: struct elt { void *data; struct elt *next; }


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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void stack_rewind(struct stack *s)
{
 s->cursor = s->head;
}


decompiled_code:
__int64 __fastcall stack_next(__int64 a1)
{
__int64 *v1; // rbx
__int64 result; // rax

v1 = *(__int64 **)(a1 + 16);
if ( v1 )
{
result = *v1;
*(_QWORD *)(a1 + 16) = v1[1];
}
else
{
stack_rewind(a1);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 *v1; // rbx
__int64 result; // rax

v1 = *(__int64 **)(a1 + 16);
if ( v1 )
{
result = *v1;
*(_QWORD *)(a1 + 16) = v1[1];
}
else
{
func5(a1);
result = 0LL;
}
return result;
}

original_code:
void * stack_next(struct stack *s)
{
 void *d = ((void *)0);
 if (s->cursor != ((void *)0)) {
  d = s->cursor->data;
  s->cursor = s->cursor->next;
 } else {
  stack_rewind(s);
 }
 return d;
}

canonical_original_code:
void *stack_next(struct stack *s)
{
 void *d = ((void *)0);
 if (s->cursor != ((void *)0)) {
  d = s->cursor->data;
  s->cursor = s->cursor->next;
 } else {
  stack_rewind(s);
 }
 return d;
}


restoreTerm

repo: uaarg/telemetry-over-wifi

decompiled_code:
int __fastcall restoreTerm(struct termios *termios_p)
{
int v2; // edi
int result; // eax

printf("\x1B[32mRestoring terminal settings\x1B[00m\n %p", termios_p);
if ( termios_p )
{
v2 = termios_p[2].c_cflag;
if ( v2 == -1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "restoreTerm", 25LL);
result = fwrite("File fd wasn't opened well", 1uLL, 0x1AuLL, stderr);
}
else
{
tcsetattr(v2, 0, termios_p);
result = tcflush(termios_p[2].c_cflag, 1);
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "restoreTerm", 31LL);
result = fwrite("termStorage is NULL", 1uLL, 0x13uLL, stderr);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(struct termios *termios_p)
{
int v2; // edi
int result; // eax

printf("\x1B[32mRestoring terminal settings\x1B[00m\n %p", termios_p);
if ( termios_p )
{
v2 = termios_p[2].c_cflag;
if ( v2 == -1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "restoreTerm", 25LL);
result = fwrite("File fd wasn't opened well", 1uLL, 0x1AuLL, stderr);
}
else
{
tcsetattr(v2, 0, termios_p);
result = tcflush(termios_p[2].c_cflag, 1);
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "restoreTerm", 31LL);
result = fwrite("termStorage is NULL", 1uLL, 0x13uLL, stderr);
}
return result;
}

original_code:
void restoreTerm(void *termStorage) {
  printf("\033[32mRestoring terminal settings\033[00m\n %p", termStorage);
  if (termStorage != ((void *)0)) {
    TermPair *tp = (TermPair *)termStorage;
    if (tp->fd == -1) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 25); fprintf(stderr, "File fd wasn't opened well"); };
    } else {
      tcsetattr(tp->fd, 0, &(tp->origTerm));
      tcflush(tp->fd, 1);
    }
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 31); fprintf(stderr, "termStorage is NULL"); };
  }
}

canonical_original_code:
void restoreTerm(void *termStorage) {
  printf("\033[32mRestoring terminal settings\033[00m\n %p", termStorage);
  if (termStorage != ((void *)0)) {
    struct TermPair *tp = (TermPair *)termStorage;
    if (tp->fd == -1) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 25); fprintf(stderr, "File fd wasn't opened well"); };
    } else {
      tcsetattr(tp->fd, 0, &(tp->origTerm));
      tcflush(tp->fd, 1);
    }
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 31); fprintf(stderr, "termStorage is NULL"); };
  }
}

variable_types:
termStorage
void *

variable_types: struct TermPair { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } origTerm; struct termios newTerm; struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; } baudRatePair; int fd; } *

user_defined_types: struct TermPair { struct termios origTerm; struct termios newTerm; struct BaudRatePair baudRatePair; int fd; }


closeAndFreeFP

decompiled_code:
void __fastcall closeAndFreeFP(void *ptr)
{
if ( ptr )
{
close(*(_DWORD *)ptr);
free(ptr);
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "closeAndFreeFP", 40LL);
fwrite("File descriptor to be closed cannot be NULL", 1uLL, 0x2BuLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
close(*(_DWORD *)ptr);
free(ptr);
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/sigHandling.c", "closeAndFreeFP", 40LL);
fwrite("File descriptor to be closed cannot be NULL", 1uLL, 0x2BuLL, stderr);
}
}

original_code:
void closeAndFreeFP(void *fd) {
  if (fd != ((void *)0)) {
    close(*((int *)fd));
    free(fd);
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/sigHandling.c", __func__, 40); fprintf(stderr, "File descriptor to be closed cannot be NULL"); };
  }
}

variable_types:
fd
void *


terminate

decompiled_code:
void __noreturn terminate()
{
freeSList(resourcesList);
fwrite("Exiting...\n", 1uLL, 0xBuLL, stderr);
exit(-1);
}

canonical_decompiled_code:
void __noreturn func2()
{
freeSList(resourcesList);
fwrite("Exiting...\n", 1uLL, 0xBuLL, stderr);
exit(-1);
}

original_code:
void terminate() {
  freeSList(resourcesList);
  fprintf(stderr, "Exiting...\n");
  exit(-1);
}


shutDown

decompiled_code:
void __noreturn shutDown()
{
fwrite("Shutting down...\n", 1uLL, 0x11uLL, stderr);
freeSList(resourcesList);
exit(0);
}

canonical_decompiled_code:
void __noreturn func3()
{
fwrite("Shutting down...\n", 1uLL, 0x11uLL, stderr);
freeSList(resourcesList);
exit(0);
}

original_code:
void shutDown() {
  fprintf(stderr, "Shutting down...\n");
  freeSList(resourcesList);
  exit(0);
}


sigHandler

decompiled_code:
int __fastcall sigHandler(__int64 a1, __int64 a2)
{
if ( (_DWORD)a1 == 2 )
terminate();
if ( (_DWORD)a1 == 15 )
shutDown(a1, a2, (unsigned int)a1);
return fprintf(stderr, "\x1B[31mUnhandled signal %d\n\x1B[00m", (unsigned int)a1);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2)
{
if ( (_DWORD)a1 == 2 )
func2();
if ( (_DWORD)a1 == 15 )
func3(a1, a2, (unsigned int)a1);
return fprintf(stderr, "\x1B[31mUnhandled signal %d\n\x1B[00m", (unsigned int)a1);
}

original_code:
void sigHandler(const int signalNum) {
  switch(signalNum) {
    case 2: {
        terminate();
        break;
    }
    case 15: {
        shutDown();
        break;
    }
    default: {
        fprintf(stderr, "\033[31mUnhandled signal %d\n\033[00m", signalNum);
        break;
    }
  }
}

canonical_original_code:
void sigHandler(int signalNum) {
  switch(signalNum) {
    case 2: {
        terminate();
        break;
    }
    case 15: {
        shutDown();
        break;
    }
    default: {
        fprintf(stderr, "\033[31mUnhandled signal %d\n\033[00m", signalNum);
        break;
    }
  }
}

variable_types: signalNum int


setSigHandler

decompiled_code:
__int64 setSigHandler()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sigHandler;
sigaction(2, &v1, 0LL);
resourcesList = createSList();
return initSList(resourcesList, &pseudoArgPass, restoreTerm, &freeNode);
}

canonical_decompiled_code:
__int64 func5()
{
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)sigHandler;
sigaction(2, &v1, 0LL);
resourcesList = createSList();
return initSList(resourcesList, &pseudoArgPass, restoreTerm, &freeNode);
}

original_code:
void setSigHandler() {
  struct sigaction theAction;
  theAction.__sigaction_handler.sa_handler = sigHandler;
  sigaction(2, &theAction, ((void *)0));
  resourcesList = createSList();
  initSList(resourcesList, pseudoArgPass, restoreTerm, freeNode);
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


addToTrackedResources

decompiled_code:
__int64 __fastcall addToTrackedResources(__int64 a1)
{
__int64 v1; // rbx

v1 = (unsigned int)addToList(resourcesList, a1);
printf("Add Status :%d\n", v1);
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rbx

v1 = (unsigned int)addToList(resourcesList, a1);
printf("Add Status :%d\n", v1);
return (unsigned int)v1;
}

original_code:
int addToTrackedResources(void *termToTrack) {
  int addStatus = addToList(resourcesList, termToTrack);
  printf("Add Status :%d\n", addStatus);
  return addStatus;
}

variable_types:
termToTrack
void *

variable_types: addStatus int


decompiled_code:
__pid_t sigchld_handler()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
__pid_t func7()
{
__pid_t result; // eax

do
result = waitpid(-1, 0LL, 1);
while ( result > 0 );
return result;
}

original_code:
void sigchld_handler(const int s) {
  while(waitpid(-1, ((void *)0), 1) > 0);
}

canonical_original_code:
void sigchld_handler(int s) {
  while(waitpid(-1, ((void *)0), 1) > 0);
}

variable_types: s int


createSList

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

result = malloc(0x30uLL);
if ( !result )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "createSList", 20LL);
fwrite("Run-out of memory, please release or debug memory allocations", 1uLL, 0x3DuLL, stderr);
exit(-2);
}
*(_DWORD *)result = 0;
result[2] = 0LL;
result[1] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

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

result = malloc(0x30uLL);
if ( !result )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "createSList", 20LL);
fwrite("Run-out of memory, please release or debug memory allocations", 1uLL, 0x3DuLL, stderr);
exit(-2);
}
*(_DWORD *)result = 0;
result[2] = 0LL;
result[1] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
return result;
}

original_code:
SList *createSList(void) {
  SList *newSL = ((void *)0);
  if ((newSL = (SList *)malloc(sizeof(SList))) == ((void *)0)) {
    { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 20); fprintf(stderr, "Run-out of memory, please release or debug memory allocations"); }; exit(-2); };
  }
  newSL->size = 0;
  newSL->head = newSL->tail = ((void *)0);
  newSL->copyData = ((void *)0);
  newSL->freeData = ((void *)0);
  newSL->freeNode = ((void *)0);
  return newSL;
}

canonical_original_code:
struct SList *createSList() {
  struct SList *newSL = ((void *)0);
  if ((newSL = (struct SList *)malloc(sizeof(SList))) == ((void *)0)) {
    { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 20); fprintf(stderr, "Run-out of memory, please release or debug memory allocations"); }; exit(-2); };
  }
  newSL->size = 0;
  newSL->head = newSL->tail = ((void *)0);
  newSL->copyData = ((void *)0);
  newSL->freeData = ((void *)0);
  newSL->freeNode = ((void *)0);
  return newSL;
}

variable_types: struct SList { int size; struct Node_ { void *data; int visits; void (*freeFunc)(void *); void *(*dataCopier)(void *); struct Node_ *next; } *head; void *(*copyData)(void *); void (*freeData)(void *); int (*freeNode)(struct Node_ *, void (*)(void *)); } *

user_defined_types: struct SList { int size; struct Node_ *head; void *(*copyData)(void *); void (*freeData)(void *); int (*freeNode)(struct Node_ *, void (*)(void *)); }


freeNode

decompiled_code:
__int64 __fastcall freeNode(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx
void (__fastcall *v3)(_QWORD); // r13
unsigned int v4; // er12
_QWORD *v5; // rbp

if ( !ptr )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeNode", 63LL);
fwrite("NULL node cannot be freed", 1uLL, 0x19uLL, stderr);
return 0;
}
v2 = ptr;
v3 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 2);
if ( !v3 )
{
if ( !a2 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeNode", 48LL);
fwrite("DataFree function cannot be NULL", 1uLL, 0x20uLL, stderr);
return 0;
}
v3 = a2;
}
v4 = 0;
do
{
v5 = v2;
v2 = (_QWORD *)v2[4];
v3(*v5);
free(v5);
++v4;
}
while ( v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr, void (__fastcall *a2)(_QWORD))
{
_QWORD *v2; // rbx
void (__fastcall *v3)(_QWORD); // r13
unsigned int v4; // er12
_QWORD *v5; // rbp

if ( !ptr )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeNode", 63LL);
fwrite("NULL node cannot be freed", 1uLL, 0x19uLL, stderr);
return 0;
}
v2 = ptr;
v3 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 2);
if ( !v3 )
{
if ( !a2 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeNode", 48LL);
fwrite("DataFree function cannot be NULL", 1uLL, 0x20uLL, stderr);
return 0;
}
v3 = a2;
}
v4 = 0;
do
{
v5 = v2;
v2 = (_QWORD *)v2[4];
v3(*v5);
free(v5);
++v4;
}
while ( v2 );
return v4;
}

original_code:
int freeNode(Node *n, void (*freeData)(void *)) {
  int freeCount = 0;
  if (n != ((void *)0)) {
    void (*dataFreer)(void *) = freeData;
    if (n->freeFunc != ((void *)0))
      dataFreer = n->freeFunc;
    if (dataFreer == ((void *)0)) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 48); fprintf(stderr, "DataFree function cannot be NULL"); };
    } else {
      while (n != ((void *)0)) {
 Node *tmp = n->next;
 dataFreer(n->data);
 free(n);
 n = tmp;
 ++freeCount;
      }
    }
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 63); fprintf(stderr, "NULL node cannot be freed"); };
  }
  return freeCount;
}

canonical_original_code:
int freeNode(struct Node_ *n, void (*freeData)(void *)) {
  int freeCount = 0;
  if (n != ((void *)0)) {
    void (*dataFreer)(void *) = freeData;
    if (n->freeFunc != ((void *)0))
      dataFreer = n->freeFunc;
    if (dataFreer == ((void *)0)) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 48); fprintf(stderr, "DataFree function cannot be NULL"); };
    } else {
      while (n != ((void *)0)) {
 struct Node_ *tmp = n->next;
 dataFreer(n->data);
 free(n);
 n = tmp;
 ++freeCount;
      }
    }
  } else {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 63); fprintf(stderr, "NULL node cannot be freed"); };
  }
  return freeCount;
}

variable_types: struct Node_ { void *data; int visits; void (*freeFunc)(void *); void *(*dataCopier)(void *); struct Node_ *next; } *

variable_types:
freeData
void (*)(void *)

variable_types: freeCount int

variable_types:
dataFreer
void (*)(void *)


freeSList

decompiled_code:
__int64 __fastcall freeSList(void *ptr)
{
__int64 v1; // rbp

if ( !ptr )
return 0LL;
v1 = (*((unsigned int (__fastcall **)(_QWORD, _QWORD))ptr + 5))(*((_QWORD *)ptr + 1), *((_QWORD *)ptr + 4));
printf("nFrees: %d\n", v1);
if ( *(_DWORD *)ptr != (_DWORD)v1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeSList", 78LL);
fwrite("Number of freed nodes is not equal to the SL size", 1uLL, 0x31uLL, stderr);
}
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
__int64 v1; // rbp

if ( !ptr )
return 0LL;
v1 = (*((unsigned int (__fastcall **)(_QWORD, _QWORD))ptr + 5))(*((_QWORD *)ptr + 1), *((_QWORD *)ptr + 4));
printf("nFrees: %d\n", v1);
if ( *(_DWORD *)ptr != (_DWORD)v1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "freeSList", 78LL);
fwrite("Number of freed nodes is not equal to the SL size", 1uLL, 0x31uLL, stderr);
}
free(ptr);
return 0LL;
}

original_code:
int freeSList(SList *sl) {
  int freeCount = 0;
  if (sl != ((void *)0)) {
    int nFrees = sl->freeNode(sl->head, sl->freeData);
    printf("nFrees: %d\n", nFrees);
    if (nFrees != sl->size) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 78); fprintf(stderr, "Number of freed nodes is not equal to the SL size"); };
    }
    sl->size = 0;
    free(sl);
    sl = ((void *)0);
  }
  return freeCount;
}

canonical_original_code:
int freeSList(struct SList *sl) {
  int freeCount = 0;
  if (sl != ((void *)0)) {
    int nFrees = sl->freeNode(sl->head, sl->freeData);
    printf("nFrees: %d\n", nFrees);
    if (nFrees != sl->size) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 78); fprintf(stderr, "Number of freed nodes is not equal to the SL size"); };
    }
    sl->size = 0;
    free(sl);
    sl = ((void *)0);
  }
  return freeCount;
}

variable_types: nFrees int

user_defined_types: struct Node_ { void *data; int visits; void (*freeFunc)(void *); void *(*dataCopier)(void *); struct Node_ *next; }


pseudoArgPass

decompiled_code:
__int64 __fastcall pseudoArgPass(__int64 a1)
{
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return a1;
}

original_code:
void *pseudoArgPass(void *arg) {
  return arg;
}

variable_types:
arg
void *


addToListWithFuncs

decompiled_code:
__int64 __fastcall addToListWithFuncs(__int64 a1, const void *a2, __int64 (__fastcall *a3)(const void *), __int64 a4)
{
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax
_QWORD *v7; // rax

if ( a1 )
{
if ( a3 || (a3 = *(__int64 (__fastcall **)(const void *))(a1 + 24)) != 0LL )
{
if ( *(_QWORD *)(a1 + 8) )
{
*(_QWORD *)(a1 + 16) = addNodeAndFunc(*(_QWORD *)(a1 + 16), a2, a3, a4);
}
else
{
v7 = addNodeAndFunc(0LL, a2, a3, a4);
*(_QWORD *)(a1 + 8) = v7;
*(_QWORD *)(a1 + 16) = v7[4];
}
v4 = *(_QWORD *)(a1 + 8);
v5 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)(v4 + 32) != v5 )
*(_QWORD *)(v4 + 32) = v5;
++*(_DWORD *)a1;
result = 1LL;
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "addToListWithFuncs", 194LL);
fwrite("copyData function of SL is NULL. Please initialize it first", 1uLL, 0x3BuLL, stderr);
result = 0LL;
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "addToListWithFuncs", 183LL);
fwrite("NULL SL passed in. First create SL", 1uLL, 0x22uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const void *a2, __int64 (__fastcall *a3)(const void *), __int64 a4)
{
__int64 v4; // rax
__int64 v5; // rdx
__int64 result; // rax
_QWORD *v7; // rax

if ( a1 )
{
if ( a3 || (a3 = *(__int64 (__fastcall **)(const void *))(a1 + 24)) != 0LL )
{
if ( *(_QWORD *)(a1 + 8) )
{
*(_QWORD *)(a1 + 16) = addNodeAndFunc(*(_QWORD *)(a1 + 16), a2, a3, a4);
}
else
{
v7 = addNodeAndFunc(0LL, a2, a3, a4);
*(_QWORD *)(a1 + 8) = v7;
*(_QWORD *)(a1 + 16) = v7[4];
}
v4 = *(_QWORD *)(a1 + 8);
v5 = *(_QWORD *)(a1 + 16);
if ( *(_QWORD *)(v4 + 32) != v5 )
*(_QWORD *)(v4 + 32) = v5;
++*(_DWORD *)a1;
result = 1LL;
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "addToListWithFuncs", 194LL);
fwrite("copyData function of SL is NULL. Please initialize it first", 1uLL, 0x3BuLL, stderr);
result = 0LL;
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "addToListWithFuncs", 183LL);
fwrite("NULL SL passed in. First create SL", 1uLL, 0x22uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int addToListWithFuncs(
  SList *sl, void *data, void *(*copier)(void *), void (*dataFreer)(void *)
) {
  if (sl == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 183); fprintf(stderr, "NULL SL passed in. First create SL"); };
    return 0;
  } else {
    void * (*copyingFunc)(void *) = sl->copyData;
    if (copier != ((void *)0))
      copyingFunc = copier;
    if (copyingFunc == ((void *)0)) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 194); fprintf(stderr, "copyData function of SL is NULL. Please initialize it first"); };
      return 0;
    }
    if (sl->head == ((void *)0)) {
      sl->head = addNodeAndFunc(sl->head, data, copyingFunc, dataFreer);
      sl->tail = sl->head->next;
    } else {
      sl->tail = addNodeAndFunc(sl->tail, data, copyingFunc, dataFreer);
    }
    if (sl->head->next != sl->tail)
      sl->head->next = sl->tail;
    ++(sl->size);
    return 1;
  }
}

canonical_original_code:
int addToListWithFuncs(struct SList *sl, void *data, void *(*copier)(void *), void (*dataFreer)(void *)) {
  if (sl == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 183); fprintf(stderr, "NULL SL passed in. First create SL"); };
    return 0;
  } else {
    void *(*copyingFunc)(void *) = sl->copyData;
    if (copier != ((void *)0))
      copyingFunc = copier;
    if (copyingFunc == ((void *)0)) {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 194); fprintf(stderr, "copyData function of SL is NULL. Please initialize it first"); };
      return 0;
    }
    if (sl->head == ((void *)0)) {
      sl->head = addNodeAndFunc(sl->head, data, copyingFunc, dataFreer);
      sl->tail = sl->head->next;
    } else {
      sl->tail = addNodeAndFunc(sl->tail, data, copyingFunc, dataFreer);
    }
    if (sl->head->next != sl->tail)
      sl->head->next = sl->tail;
    ++(sl->size);
    return 1;
  }
}

variable_types:
data
void *

variable_types:
copier
void *(*)(void *)

variable_types:
copyingFunc
void *(*)(void *)


addToList

decompiled_code:
__int64 __fastcall addToList(__int64 a1, const void *a2)
{
return addToListWithFuncs(a1, a2, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const void *a2)
{
return func5(a1, a2, 0LL, 0LL);
}

original_code:
int addToList(SList *sl, void *data) {
  return addToListWithFuncs(sl, data, ((void *)0), ((void *)0));
}

canonical_original_code:
int addToList(struct SList *sl, void *data) {
  return addToListWithFuncs(sl, data, ((void *)0), ((void *)0));
}


strCopier

decompiled_code:
char *__fastcall strCopier(const char *a1)
{
char *result; // rax

result = (char *)a1;
if ( a1 )
result = strdup(a1);
return result;
}

canonical_decompiled_code:
char *__fastcall func7(const char *a1)
{
char *result; // rax

result = (char *)a1;
if ( a1 )
result = strdup(a1);
return result;
}

original_code:
void *strCopier(void *data) {
  return data == ((void *)0) ? ((void *)0) : (void *)strdup((char *)data);
}


peek

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

if ( a1 )
result = getData(*(_QWORD *)(a1 + 8));
else
result = 0LL;
return result;
}

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

if ( a1 )
result = getData(*(_QWORD *)(a1 + 8));
else
result = 0LL;
return result;
}

original_code:
inline void *peek(SList *sl) {
  return sl == ((void *)0) ? ((void *)0) : getData(sl->head);
}

canonical_original_code:
inline void *peek(struct SList *sl) {
  return sl == ((void *)0) ? ((void *)0) : getData(sl->head);
}


pop

decompiled_code:
__int64 __fastcall pop(__int64 a1)
{
void *v1; // rbp
__int64 v2; // r12

if ( (unsigned int)getSize() )
{
v1 = *(void **)(a1 + 8);
if ( v1 )
{
v2 = getData(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = getNext(v1);
free(v1);
--*(_DWORD *)a1;
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "pop", 256LL);
fwrite("Trying to pop from an empty node", 1uLL, 0x20uLL, stderr);
v2 = 0LL;
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "pop", 240LL);
fwrite("Cannot pop from a NULL sl", 1uLL, 0x19uLL, stderr);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
void *v1; // rbp
__int64 v2; // r12

if ( (unsigned int)getSize() )
{
v1 = *(void **)(a1 + 8);
if ( v1 )
{
v2 = getData(*(_QWORD *)(a1 + 8));
*(_QWORD *)(a1 + 8) = getNext(v1);
free(v1);
--*(_DWORD *)a1;
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "pop", 256LL);
fwrite("Trying to pop from an empty node", 1uLL, 0x20uLL, stderr);
v2 = 0LL;
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/SList.c", "pop", 240LL);
fwrite("Cannot pop from a NULL sl", 1uLL, 0x19uLL, stderr);
v2 = 0LL;
}
return v2;
}

original_code:
void *pop(SList *sl) {
  if (! getSize(sl)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 240); fprintf(stderr, "Cannot pop from a NULL sl"); };
    return ((void *)0);
  } else {
    Node *prevHead = sl->head;
    if (sl->head != ((void *)0)) {
      void *copiedData = getData(sl->head);
      sl->head = getNext(sl->head);
      free(prevHead);
      prevHead = ((void *)0);
      --sl->size;
      return copiedData;
    } else {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 256); fprintf(stderr, "Trying to pop from an empty node"); };
      return ((void *)0);
    }
  }
}

canonical_original_code:
void *pop(struct SList *sl) {
  if (! getSize(sl)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 240); fprintf(stderr, "Cannot pop from a NULL sl"); };
    return ((void *)0);
  } else {
    struct Node_ *prevHead = sl->head;
    if (sl->head != ((void *)0)) {
      void *copiedData = getData(sl->head);
      sl->head = getNext(sl->head);
      free(prevHead);
      prevHead = ((void *)0);
      --sl->size;
      return copiedData;
    } else {
      { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/SList.c", __func__, 256); fprintf(stderr, "Trying to pop from an empty node"); };
      return ((void *)0);
    }
  }
}

variable_types:
copiedData
void *


matchBaudRate

decompiled_code:
__int64 __fastcall matchBaudRate(int a1)
{
__int64 result; // rax

if ( a1 == 1200 )
return 9LL;
if ( a1 > 1200 )
{
if ( a1 == 19200 )
{
result = 14LL;
}
else if ( a1 <= 19200 )
{
result = 12LL;
if ( a1 != 4800 )
{
if ( a1 <= 4800 )
{
result = 10LL;
if ( a1 != 1800 )
{
if ( a1 != 2400 )
goto LABEL_8;
result = 11LL;
}
}
else
{
result = 13LL;
if ( a1 != 9600 )
goto LABEL_8;
}
}
}
else
{
result = 4098LL;
if ( a1 != 115200 )
{
if ( a1 <= 115200 )
{
result = 15LL;
if ( a1 != 38400 )
{
if ( a1 != 57600 )
goto LABEL_8;
result = 4097LL;
}
}
else
{
result = 4099LL;
if ( a1 != 230400 )
goto LABEL_8;
}
}
}
}
else if ( a1 == 134 )
{
result = 4LL;
}
else if ( a1 <= 134 )
{
result = 2LL;
if ( a1 != 75 )
{
if ( a1 <= 75 )
{
result = 0LL;
if ( a1 )
{
if ( a1 != 50 )
goto LABEL_8;
result = 1LL;
}
}
else
{
result = 3LL;
if ( a1 != 110 )
goto LABEL_8;
}
}
}
else
{
result = 7LL;
if ( a1 != 300 )
{
if ( a1 <= 300 )
{
result = 5LL;
if ( a1 != 150 )
{
if ( a1 != 200 )
goto LABEL_8;
result = 6LL;
}
}
else
{
result = 8LL;
if ( a1 != 600 )
{
LABEL_8:
printf("bad baudrate %d\n", (unsigned int)a1);
return 0xFFFFFFFFLL;
}
}
}
}
return result;
}

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

if ( a1 == 1200 )
return 9LL;
if ( a1 > 1200 )
{
if ( a1 == 19200 )
{
result = 14LL;
}
else if ( a1 <= 19200 )
{
result = 12LL;
if ( a1 != 4800 )
{
if ( a1 <= 4800 )
{
result = 10LL;
if ( a1 != 1800 )
{
if ( a1 != 2400 )
goto LABEL_8;
result = 11LL;
}
}
else
{
result = 13LL;
if ( a1 != 9600 )
goto LABEL_8;
}
}
}
else
{
result = 4098LL;
if ( a1 != 115200 )
{
if ( a1 <= 115200 )
{
result = 15LL;
if ( a1 != 38400 )
{
if ( a1 != 57600 )
goto LABEL_8;
result = 4097LL;
}
}
else
{
result = 4099LL;
if ( a1 != 230400 )
goto LABEL_8;
}
}
}
}
else if ( a1 == 134 )
{
result = 4LL;
}
else if ( a1 <= 134 )
{
result = 2LL;
if ( a1 != 75 )
{
if ( a1 <= 75 )
{
result = 0LL;
if ( a1 )
{
if ( a1 != 50 )
goto LABEL_8;
result = 1LL;
}
}
else
{
result = 3LL;
if ( a1 != 110 )
goto LABEL_8;
}
}
}
else
{
result = 7LL;
if ( a1 != 300 )
{
if ( a1 <= 300 )
{
result = 5LL;
if ( a1 != 150 )
{
if ( a1 != 200 )
goto LABEL_8;
result = 6LL;
}
}
else
{
result = 8LL;
if ( a1 != 600 )
{
LABEL_8:
printf("bad baudrate %d\n", (unsigned int)a1);
return 0xFFFFFFFFLL;
}
}
}
}
return result;
}

original_code:
speed_t matchBaudRate(const int speed) {
  speed_t theBaudRate;
  switch (speed) {
    case 0:
      theBaudRate = 0000000;
      break;
    case 50:
      theBaudRate = 0000001;
      break;
    case 75:
      theBaudRate = 0000002;
      break;
    case 110:
      theBaudRate = 0000003;
      break;
    case 134:
      theBaudRate = 0000004;
      break;
    case 150:
      theBaudRate = 0000005;
      break;
    case 200:
      theBaudRate = 0000006;
      break;
    case 300:
      theBaudRate = 0000007;
      break;
    case 600:
      theBaudRate = 0000010;
      break;
    case 1200:
      theBaudRate = 0000011;
      break;
    case 1800:
      theBaudRate = 0000012;
      break;
    case 2400:
      theBaudRate = 0000013;
      break;
    case 4800:
      theBaudRate = 0000014;
      break;
    case 9600:
      theBaudRate = 0000015;
      break;
    case 19200:
      theBaudRate = 0000016;
      break;
    case 38400:
      theBaudRate = 0000017;
      break;
    case 57600:
      theBaudRate = 0010001;
      break;
    case 115200:
      theBaudRate = 0010002;
      break;
    case 230400:
      theBaudRate = 0010003;
      break;
    default:
      printf("bad baudrate %d\n", speed);
      theBaudRate = -1;
  }
  return theBaudRate;
}

canonical_original_code:
unsigned int matchBaudRate(int speed) {
  unsigned int theBaudRate;
  switch (speed) {
    case 0:
      theBaudRate = 0000000;
      break;
    case 50:
      theBaudRate = 0000001;
      break;
    case 75:
      theBaudRate = 0000002;
      break;
    case 110:
      theBaudRate = 0000003;
      break;
    case 134:
      theBaudRate = 0000004;
      break;
    case 150:
      theBaudRate = 0000005;
      break;
    case 200:
      theBaudRate = 0000006;
      break;
    case 300:
      theBaudRate = 0000007;
      break;
    case 600:
      theBaudRate = 0000010;
      break;
    case 1200:
      theBaudRate = 0000011;
      break;
    case 1800:
      theBaudRate = 0000012;
      break;
    case 2400:
      theBaudRate = 0000013;
      break;
    case 4800:
      theBaudRate = 0000014;
      break;
    case 9600:
      theBaudRate = 0000015;
      break;
    case 19200:
      theBaudRate = 0000016;
      break;
    case 38400:
      theBaudRate = 0000017;
      break;
    case 57600:
      theBaudRate = 0010001;
      break;
    case 115200:
      theBaudRate = 0010002;
      break;
    case 230400:
      theBaudRate = 0010003;
      break;
    default:
      printf("bad baudrate %d\n", speed);
      theBaudRate = -1;
  }
  return theBaudRate;
}

variable_types: speed int

variable_types:
theBaudRate
unsigned int


decompiled_code:
int __fastcall c_init_serialFD(struct termios *termios_p, int a2, int a3)
{
speed_t v4; // ebp
__int64 v5; // rcx
int v6; // eax
tcflag_t v7; // eax
tcflag_t v8; // eax

if ( !termios_p )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/cserial.c", "c_init_serialFD", 148LL);
fwrite("A non-NULL termios pair is needed to store the new term attributes", 1uLL, 0x42uLL, stderr);
exit(-2);
}
v4 = matchBaudRate(a2);
if ( termios_p[2].c_cflag == -1 )
perror("opening modem serial device : fd < 0");
tcgetattr(termios_p[2].c_cflag, termios_p);
v5 = *(_QWORD *)&termios_p->c_cflag;
v6 = *(_QWORD *)&termios_p->c_iflag;
*(_QWORD *)&termios_p[1].c_iflag = *(_QWORD *)&termios_p->c_iflag;
*(_QWORD *)&termios_p[1].c_cflag = v5;
*(__m128i *)&termios_p[1].c_line = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
*(__m128i *)&termios_p[1].c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
*(_QWORD *)&termios_p[1].c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
termios_p[1].c_ospeed = termios_p->c_ospeed;
termios_p[1].c_iflag = v6 & 0xFFFFC200 | 2;
termios_p[1].c_oflag &= 0xFFFFFFC2;
if ( a3 )
v7 = termios_p[1].c_cflag & 0xFFFFF00F | 0x800008B0;
else
v7 = termios_p[1].c_cflag & 0x7FFFF00F | 0x8B0;
termios_p[1].c_cflag = v7;
v8 = termios_p[1].c_lflag & 0xFFFF2FF4;
LOBYTE(v8) = termios_p[1].c_lflag & 0xF4 | 0x80;
termios_p[1].c_lflag = v8;
cfsetspeed(termios_p + 1, v4);
return tcsetattr(termios_p[2].c_cflag, 1, termios_p + 1);
}

canonical_decompiled_code:
int __fastcall func1(struct termios *termios_p, int a2, int a3)
{
speed_t v4; // ebp
__int64 v5; // rcx
int v6; // eax
tcflag_t v7; // eax
tcflag_t v8; // eax

if ( !termios_p )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/cserial.c", "c_init_serialFD", 148LL);
fwrite("A non-NULL termios pair is needed to store the new term attributes", 1uLL, 0x42uLL, stderr);
exit(-2);
}
v4 = func0(a2);
if ( termios_p[2].c_cflag == -1 )
perror("opening modem serial device : fd < 0");
tcgetattr(termios_p[2].c_cflag, termios_p);
v5 = *(_QWORD *)&termios_p->c_cflag;
v6 = *(_QWORD *)&termios_p->c_iflag;
*(_QWORD *)&termios_p[1].c_iflag = *(_QWORD *)&termios_p->c_iflag;
*(_QWORD *)&termios_p[1].c_cflag = v5;
*(__m128i *)&termios_p[1].c_line = _mm_loadu_si128((const __m128i *)&termios_p->c_line);
*(__m128i *)&termios_p[1].c_cc[15] = _mm_loadu_si128((const __m128i *)&termios_p->c_cc[15]);
*(_QWORD *)&termios_p[1].c_cc[31] = *(_QWORD *)&termios_p->c_cc[31];
termios_p[1].c_ospeed = termios_p->c_ospeed;
termios_p[1].c_iflag = v6 & 0xFFFFC200 | 2;
termios_p[1].c_oflag &= 0xFFFFFFC2;
if ( a3 )
v7 = termios_p[1].c_cflag & 0xFFFFF00F | 0x800008B0;
else
v7 = termios_p[1].c_cflag & 0x7FFFF00F | 0x8B0;
termios_p[1].c_cflag = v7;
v8 = termios_p[1].c_lflag & 0xFFFF2FF4;
LOBYTE(v8) = termios_p[1].c_lflag & 0xF4 | 0x80;
termios_p[1].c_lflag = v8;
cfsetspeed(termios_p + 1, v4);
return tcsetattr(termios_p[2].c_cflag, 1, termios_p + 1);
}

variable_types: struct TermPair { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } origTerm; struct termios newTerm; struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; } baudRatePair; int fd; } *

variable_types:
selectedBaudRate
unsigned int


decompiled_code:
int __fastcall c_init_serial(struct termios *termios_p, char *file, int a3, int a4)
{
if ( !termios_p )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/cserial.c", "c_init_serial", 136LL);
fwrite("The storage for the file descriptor must not be NULL", 1uLL, 0x34uLL, stderr);
exit(-2);
}
termios_p[2].c_cflag = open(file, 2050);
return c_init_serialFD(termios_p, a3, a4);
}

canonical_decompiled_code:
int __fastcall func2(struct termios *termios_p, char *file, int a3, int a4)
{
if ( !termios_p )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/cserial.c", "c_init_serial", 136LL);
fwrite("The storage for the file descriptor must not be NULL", 1uLL, 0x34uLL, stderr);
exit(-2);
}
termios_p[2].c_cflag = open(file, 2050);
return func1(termios_p, a3, a4);
}

original_code:
void c_init_serial(
  TermPair *termStorage, const char *devicePath,
  const int speed, const Bool hw_flow_control
) {
  if (termStorage == ((void *)0)) {
    { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/cserial.c", __func__, 136); fprintf(stderr, "The storage for the file descriptor must not be NULL"); }; exit(-2); };
  }
  termStorage->fd = open(devicePath, 02|04000);
  c_init_serialFD(termStorage, speed, hw_flow_control);
}

canonical_original_code:
void c_init_serial(struct TermPair *termStorage, char *devicePath, int speed, enum Bool hw_flow_control) {
  if (termStorage == ((void *)0)) {
    { { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/cserial.c", __func__, 136); fprintf(stderr, "The storage for the file descriptor must not be NULL"); }; exit(-2); };
  }
  termStorage->fd = open(devicePath, 02|04000);
  c_init_serialFD(termStorage, speed, hw_flow_control);
}

variable_types:
devicePath
char *

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

user_defined_types: struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; }


decompiled_code:
__int64 __fastcall c_set_dtr(int fd, int a2)
{
int v2; // eax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

ioctl(fd, 0x5415uLL, v4);
if ( a2 )
v2 = v4[0] | 2;
else
v2 = v4[0] & 0xFFFFFFFD;
v4[0] = v2;
ioctl(fd, 0x5418uLL, v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int a2)
{
int v2; // eax
int v4[7]; // [rsp+Ch] [rbp-1Ch] BYREF

ioctl(fd, 0x5415uLL, v4);
if ( a2 )
v2 = v4[0] | 2;
else
v2 = v4[0] & 0xFFFFFFFD;
v4[0] = v2;
ioctl(fd, 0x5418uLL, v4);
return 0LL;
}

original_code:
int c_set_dtr(int fd, Bool val_bit) {
  int status;
  ioctl(fd, 0x5415, &status);
  if (val_bit)
    status |= 0x002;
  else
    status &= ~0x002;
  ioctl(fd, 0x5418, &status);
  return 0;
}

canonical_original_code:
int c_set_dtr(int fd, enum Bool val_bit) {
  int status;
  ioctl(fd, 0x5415, &status);
  if (val_bit)
    status |= 0x002;
  else
    status &= ~0x002;
  ioctl(fd, 0x5418, &status);
  return 0;
}

variable_types: fd int

variable_types: status int


decompiled_code:
__int64 __fastcall c_serial_set_baudrate(int fd, int a2)
{
speed_t v2; // ebp
struct termios v4; // [rsp+0h] [rbp-58h] BYREF

v2 = matchBaudRate(a2);
if ( tcgetattr(fd, &v4) < 0 )
puts("tcgetattr");
v4.c_iflag = 0;
v4.c_oflag = 0;
v4.c_cflag = 2224;
v4.c_cc[6] = 1;
v4.c_cc[5] = 5;
v4.c_lflag &= 0xFFFFFF84;
cfsetispeed(&v4, v2);
cfsetospeed(&v4, v2);
if ( tcsetattr(fd, 2, &v4) < 0 )
puts("tcsetattr");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, int a2)
{
speed_t v2; // ebp
struct termios v4; // [rsp+0h] [rbp-58h] BYREF

v2 = func0(a2);
if ( tcgetattr(fd, &v4) < 0 )
puts("tcgetattr");
v4.c_iflag = 0;
v4.c_oflag = 0;
v4.c_cflag = 2224;
v4.c_cc[6] = 1;
v4.c_cc[5] = 5;
v4.c_lflag &= 0xFFFFFF84;
cfsetispeed(&v4, v2);
cfsetospeed(&v4, v2);
if ( tcsetattr(fd, 2, &v4) < 0 )
puts("tcsetattr");
return 0LL;
}

original_code:
int c_serial_set_baudrate(int fd, const int speed) {
  struct termios tio;
  speed_t br = matchBaudRate(speed);
  if (tcgetattr(fd, &tio) < 0) {
    printf("tcgetattr\n");
  }
  tio.c_iflag = 0;
  tio.c_oflag = 0;
  tio.c_cflag = 0000060 | 0000200 | 0004000;
  tio.c_cc[6] = 1;
  tio.c_cc[5] = 5;
  tio.c_lflag &= ~(0000002 | 0000001 | 0000010 | 0000100 | 0000020 | 0000040);
  cfsetispeed(&tio, br);
  cfsetospeed(&tio, br);
  if (tcsetattr(fd, 0 | 2, &tio) < 0) {
    printf("tcsetattr\n");
  }
  return 0;
}

canonical_original_code:
int c_serial_set_baudrate(int fd, int speed) {
  struct termios tio;
  unsigned int br = matchBaudRate(speed);
  if (tcgetattr(fd, &tio) < 0) {
    printf("tcgetattr\n");
  }
  tio.c_iflag = 0;
  tio.c_oflag = 0;
  tio.c_cflag = 0000060 | 0000200 | 0004000;
  tio.c_cc[6] = 1;
  tio.c_cc[5] = 5;
  tio.c_lflag &= ~(0000002 | 0000001 | 0000010 | 0000100 | 0000020 | 0000040);
  cfsetispeed(&tio, br);
  cfsetospeed(&tio, br);
  if (tcsetattr(fd, 0 | 2, &tio) < 0) {
    printf("tcsetattr\n");
  }
  return 0;
}

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

variable_types:
br
unsigned int


dTest

decompiled_code:
int *__fastcall dTest(int *a1)
{
int *result; // rax

result = a1;
if ( *a1 > 0 )
{
--*a1;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
int *__fastcall func0(int *a1)
{
int *result; // rax

result = a1;
if ( *a1 > 0 )
{
--*a1;
result = 0LL;
}
return result;
}

original_code:
void *dTest(void *data) {
  int *tP = (int *)data;
  if (*tP > 0) {
    --(*tP);
    return ((void *)0);
  }
  return tP;
}

variable_types:
tP
int *


initPollThStruct

original_code:
void initPollThStruct(
  pollThStruct *pTSt, double timeOut,
  void *errorValue, Comparison comp(void *, void *)
) {
  if (pTSt != ((void *)0)) {
    pTSt->tryCount = INIT_TRY_COUNT;
    pTSt->timeOut = timeOut;
    pTSt->errorValue = errorValue;
    pTSt->valComp = comp;
  }
}

canonical_original_code:
void initPollThStruct(struct pollThStruct *pTSt, double timeOut, void *errorValue, enum Comparison comp(void *, void *)) {
  if (pTSt != ((void *)0)) {
    pTSt->tryCount = INIT_TRY_COUNT;
    pTSt->timeOut = timeOut;
    pTSt->errorValue = errorValue;
    pTSt->valComp = comp;
  }
}

variable_types: struct pollThStruct { void *arg; void *errorValue; void *savSuccess; double timeOut; unsigned int tryCount; void *(*funcToRun)(void *data); enum Comparison { LT=-1, EQ=0, GT=1 } (*valComp)(void *, void *); } *

variable_types: timeOut double

variable_types:
errorValue
void *

variable_types: enum Comparison { LT=-1, EQ=0, GT=1 } (void *, void *)

user_defined_types: struct pollThStruct { void *arg; void *errorValue; void *savSuccess; double timeOut; unsigned int tryCount; void *(*funcToRun)(void *data); enum Comparison (*valComp)(void *, void *); }


pollTill

decompiled_code:
size_t __fastcall pollTill(__int64 a1)
{
size_t result; // rax
__int64 v2; // rdx
__int64 v3; // rax
double i; // [rsp+8h] [rbp-10h]

if ( a1 )
{
for ( i = *(double *)(a1 + 24); ; sleep((int)i) )
{
v3 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 40))(*(_QWORD *)a1);
*(_QWORD *)(a1 + 16) = v3;
if ( (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 48))(v3, *(_QWORD *)(a1 + 8)) )
break;
clearCursorLine(stderr);
v2 = (unsigned int)(*(_DWORD *)(a1 + 32) + 1);
*(_DWORD *)(a1 + 32) = v2;
fprintf(stderr, "Try Count: %d Sleeping for %1.2f seconds\r", v2, i);
}
result = fwrite("\x1B[33mDone Polling as condition met\n\x1B[00m", 1uLL, 0x28uLL, stderr);
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/polling.c", "pollTill", 35LL);
result = fwrite("NULL pollThStruct passed in", 1uLL, 0x1BuLL, stderr);
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func2(__int64 a1)
{
size_t result; // rax
__int64 v2; // rdx
__int64 v3; // rax
double i; // [rsp+8h] [rbp-10h]

if ( a1 )
{
for ( i = *(double *)(a1 + 24); ; sleep((int)i) )
{
v3 = (*(__int64 (__fastcall **)(_QWORD))(a1 + 40))(*(_QWORD *)a1);
*(_QWORD *)(a1 + 16) = v3;
if ( (*(unsigned int (__fastcall **)(__int64, _QWORD))(a1 + 48))(v3, *(_QWORD *)(a1 + 8)) )
break;
clearCursorLine(stderr);
v2 = (unsigned int)(*(_DWORD *)(a1 + 32) + 1);
*(_DWORD *)(a1 + 32) = v2;
fprintf(stderr, "Try Count: %d Sleeping for %1.2f seconds\r", v2, i);
}
result = fwrite("\x1B[33mDone Polling as condition met\n\x1B[00m", 1uLL, 0x28uLL, stderr);
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/polling.c", "pollTill", 35LL);
result = fwrite("NULL pollThStruct passed in", 1uLL, 0x1BuLL, stderr);
}
return result;
}

original_code:
void pollTill(pollThStruct *pollTST) {
  if (pollTST == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/polling.c", __func__, 35); fprintf(stderr, "NULL pollThStruct passed in"); };
    return;
  }
  const double timeOutSecs = pollTST->timeOut;
  while (1) {
    pollTST->savSuccess = pollTST->funcToRun(pollTST->arg);
    Comparison vComparison = pollTST->valComp(
      pollTST->savSuccess, pollTST->errorValue
    );
    if (vComparison != EQ) {
      fprintf(stderr, "\033[33mDone Polling as condition met\n\033[00m");
      break;
    } else {
      clearCursorLine(stderr);
      fprintf(stderr, "Try Count: %d Sleeping for %1.2f seconds\r",
        ++(pollTST->tryCount), timeOutSecs);
    }
    sleep(timeOutSecs);
  }
}

canonical_original_code:
void pollTill(struct pollThStruct *pollTST) {
  if (pollTST == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/polling.c", __func__, 35); fprintf(stderr, "NULL pollThStruct passed in"); };
    return;
  }
  double timeOutSecs = pollTST->timeOut;
  while (1) {
    pollTST->savSuccess = pollTST->funcToRun(pollTST->arg);
    enum Comparison vComparison = pollTST->valComp(
      pollTST->savSuccess, pollTST->errorValue
    );
    if (vComparison != EQ) {
      fprintf(stderr, "\033[33mDone Polling as condition met\n\033[00m");
      break;
    } else {
      clearCursorLine(stderr);
      fprintf(stderr, "Try Count: %d Sleeping for %1.2f seconds\r",
        ++(pollTST->tryCount), timeOutSecs);
    }
    sleep(timeOutSecs);
  }
}

variable_types: timeOutSecs double

variable_types:
vComparison
enum Comparison { LT=-1, EQ=0, GT=1 }


intPtrComp

decompiled_code:
__int64 __fastcall intPtrComp(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 0LL;
if ( *a1 != *a2 )
result = 2 * (unsigned int)(*a1 >= *a2) - 1;
return result;
}

canonical_original_code:
enum Comparison intPtrComp(void *a, void *b) {
  int *aInt = (int *)a;
  int *bInt = (int *)b;
  if (*aInt != *bInt) {
    return *aInt < *bInt ? LT : GT;
  }
  return EQ;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
aInt
int *

variable_types:
bInt
int *

return_type: enum Comparison { LT=-1, EQ=0, GT=1 }


getChars

decompiled_code:
__int64 __fastcall getChars(int fd, _BYTE *a2, int a3, _DWORD *a4)
{
_BYTE *v6; // rbp
unsigned int v7; // ebx
int v8; // eax
char buf[57]; // [rsp+Fh] [rbp-39h] BYREF

if ( a2 )
{
if ( fd == -1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/ioLib.c", "getChars", 29LL);
fwrite("NULL file descriptor cannot be read from.", 1uLL, 0x29uLL, stderr);
v7 = -1;
}
else
{
v6 = a2;
v7 = 0;
if ( a3 > 0 )
{
while ( 1 )
{
v8 = read(fd, buf, 1uLL);
if ( !v8 )
break;
if ( v8 == -1 )
goto LABEL_12;
*v6 = buf[0];
++v7;
++v6;
if ( a3 == v7 )
goto LABEL_7;
}
*a4 = 1;
LABEL_12:
if ( v7 )
{
LABEL_7:
a2[v7] = 0;
return v7;
}
}
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/ioLib.c", "getChars", 23LL);
fwrite("NULL string storage passed in.", 1uLL, 0x1EuLL, stderr);
v7 = -1;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, _BYTE *a2, int a3, _DWORD *a4)
{
_BYTE *v6; // rbp
unsigned int v7; // ebx
int v8; // eax
char buf[57]; // [rsp+Fh] [rbp-39h] BYREF

if ( a2 )
{
if ( fd == -1 )
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/ioLib.c", "getChars", 29LL);
fwrite("NULL file descriptor cannot be read from.", 1uLL, 0x29uLL, stderr);
v7 = -1;
}
else
{
v6 = a2;
v7 = 0;
if ( a3 > 0 )
{
while ( 1 )
{
v8 = read(fd, buf, 1uLL);
if ( !v8 )
break;
if ( v8 == -1 )
goto LABEL_12;
*v6 = buf[0];
++v7;
++v6;
if ( a3 == v7 )
goto LABEL_7;
}
*a4 = 1;
LABEL_12:
if ( v7 )
{
LABEL_7:
a2[v7] = 0;
return v7;
}
}
}
}
else
{
fprintf(stderr, "\x1B[31m[%s: %s]\x1B[00m Traceback to line: %d:: ", "src/ioLib.c", "getChars", 23LL);
fwrite("NULL string storage passed in.", 1uLL, 0x1EuLL, stderr);
v7 = -1;
}
return v7;
}

original_code:
int getChars(int fd, char *destStr, const int len, int *eofState) {
  if (destStr == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/ioLib.c", __func__, 23); fprintf(stderr, "NULL string storage passed in."); };
    return -1;
  }
  if (fd == ERROR_SOCKFD_VALUE) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/ioLib.c", __func__, 29); fprintf(stderr, "NULL file descriptor cannot be read from."); };
    return -1;
  }
  char c;
  int nAdded = 0;
  for (; nAdded < len; ++nAdded) {
    int readResult = read(fd, &c, 1);
    if (readResult == 0) {
      *eofState = True;
      break;
    } else if (readResult == -1)
        break;
    destStr[nAdded] = c;
  }
  if (nAdded)
    destStr[nAdded] = '\0';
  return nAdded;
}

canonical_original_code:
int getChars(int fd, char *destStr, int len, int *eofState) {
  if (destStr == ((void *)0)) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/ioLib.c", __func__, 23); fprintf(stderr, "NULL string storage passed in."); };
    return -1;
  }
  if (fd == ERROR_SOCKFD_VALUE) {
    { fprintf(stderr, "\033[31m[%s: %s]\033[00m Traceback to line: %d:: ", "src/ioLib.c", __func__, 29); fprintf(stderr, "NULL file descriptor cannot be read from."); };
    return -1;
  }
  char c;
  int nAdded = 0;
  for (; nAdded < len; ++nAdded) {
    int readResult = read(fd, &c, 1);
    if (readResult == 0) {
      *eofState = True;
      break;
    } else if (readResult == -1)
        break;
    destStr[nAdded] = c;
  }
  if (nAdded)
    destStr[nAdded] = '\0';
  return nAdded;
}

variable_types:
destStr
char *

variable_types: len int

variable_types:
eofState
int *

variable_types: c char

variable_types: nAdded int

variable_types: readResult int


freeWord

decompiled_code:
__int64 __fastcall freeWord(void *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
{
free(a1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
{
free(a1);
result = 1LL;
}
return result;
}

canonical_original_code:
enum Bool freeWord(char *w) {
  if (w == ((void *)0)) return False;
  free(w);
  w = ((void *)0);
  return True;
}

variable_types:
w
char *

return_type: enum Bool { False=0, True=1 }


flushTermSettings

decompiled_code:
__int64 __fastcall flushTermSettings(const struct termios *a1)
{
int v1; // ecx
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = a1[2].c_cflag;
result = 0LL;
if ( v1 != -1 )
{
tcsetattr(v1, 0, a1 + 1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const struct termios *a1)
{
int v1; // ecx
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = a1[2].c_cflag;
result = 0LL;
if ( v1 != -1 )
{
tcsetattr(v1, 0, a1 + 1);
result = 1LL;
}
return result;
}

original_code:
Bool flushTermSettings(TermPair *tP) {
  if (tP == ((void *)0)) return False;
  if (tP->fd == ERROR_SOCKFD_VALUE) return False;
  tcsetattr(tP->fd, 0, &(tP->newTerm));
  return True;
}

canonical_original_code:
enum Bool flushTermSettings(struct TermPair *tP) {
  if (tP == ((void *)0)) return False;
  if (tP->fd == ERROR_SOCKFD_VALUE) return False;
  tcsetattr(tP->fd, 0, &(tP->newTerm));
  return True;
}

variable_types: struct TermPair { struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; } origTerm; struct termios newTerm; struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; } baudRatePair; int fd; } *


setBaudRate

decompiled_code:
__int64 __fastcall setBaudRate(const struct termios *a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = 0LL;
if ( a1[2].c_cflag != -1 )
{
if ( (_DWORD)a2 != -1 )
cfsetispeed((struct termios *)&a1[1], a2);
if ( HIDWORD(a2) != -1 )
cfsetospeed((struct termios *)&a1[1], HIDWORD(a2));
tcsetattr(a1[2].c_cflag, 0, a1 + 1);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const struct termios *a1, __int64 a2)
{
__int64 result; // rax

if ( !a1 )
return 0LL;
result = 0LL;
if ( a1[2].c_cflag != -1 )
{
if ( (_DWORD)a2 != -1 )
cfsetispeed((struct termios *)&a1[1], a2);
if ( HIDWORD(a2) != -1 )
cfsetospeed((struct termios *)&a1[1], HIDWORD(a2));
tcsetattr(a1[2].c_cflag, 0, a1 + 1);
result = 1LL;
}
return result;
}

original_code:
Bool setBaudRate(TermPair *tP, const BaudRatePair newBP) {
  if (tP == ((void *)0) || tP->fd == ERROR_SOCKFD_VALUE) return False;
  if (newBP.inBaudRate != ERROR_BAUD_RATE)
    cfsetispeed(&(tP->newTerm), newBP.inBaudRate);
  if (newBP.outBaudRate != ERROR_BAUD_RATE)
    cfsetospeed(&(tP->newTerm), newBP.outBaudRate);
  tcsetattr(tP->fd, 0, &(tP->newTerm));
  return True;
}

canonical_original_code:
enum Bool setBaudRate(struct TermPair *tP, struct BaudRatePair newBP) {
  if (tP == ((void *)0) || tP->fd == ERROR_SOCKFD_VALUE) return False;
  if (newBP.inBaudRate != ERROR_BAUD_RATE)
    cfsetispeed(&(tP->newTerm), newBP.inBaudRate);
  if (newBP.outBaudRate != ERROR_BAUD_RATE)
    cfsetospeed(&(tP->newTerm), newBP.outBaudRate);
  tcsetattr(tP->fd, 0, &(tP->newTerm));
  return True;
}

variable_types:
newBP
struct BaudRatePair


revertTermSettings

decompiled_code:
_BOOL8 __fastcall revertTermSettings(struct termios *termios_p)
{
int v2; // edi
_BOOL8 result; // rax

if ( !termios_p )
return 0LL;
v2 = termios_p[2].c_cflag;
result = 0LL;
if ( v2 != -1 )
result = tcsetattr(v2, 0, termios_p) != -1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(struct termios *termios_p)
{
int v2; // edi
_BOOL8 result; // rax

if ( !termios_p )
return 0LL;
v2 = termios_p[2].c_cflag;
result = 0LL;
if ( v2 != -1 )
result = tcsetattr(v2, 0, termios_p) != -1;
return result;
}

original_code:
Bool revertTermSettings(TermPair *tP) {
  if (tP == ((void *)0) || tP->fd == ERROR_SOCKFD_VALUE) return False;
  return tcsetattr(tP->fd, 0, &(tP->origTerm)) != ERROR_SETATTR_RESULT;
}

canonical_original_code:
enum Bool revertTermSettings(struct TermPair *tP) {
  if (tP == ((void *)0) || tP->fd == ERROR_SOCKFD_VALUE) return False;
  return tcsetattr(tP->fd, 0, &(tP->origTerm)) != ERROR_SETATTR_RESULT;
}


initTermPair

decompiled_code:
int __fastcall initTermPair(int fd, struct termios *a2)
{
int result; // eax

if ( fd != -1 )
{
if ( a2 )
{
tcgetattr(fd, a2);
result = tcsetattr(fd, 0, a2 + 1);
a2[2].c_cflag = fd;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int fd, struct termios *a2)
{
int result; // eax

if ( fd != -1 )
{
if ( a2 )
{
tcgetattr(fd, a2);
result = tcsetattr(fd, 0, a2 + 1);
a2[2].c_cflag = fd;
}
}
return result;
}

original_code:
void initTermPair(const int fd, TermPair *tP) {
  if (fd != ERROR_SOCKFD_VALUE && tP != ((void *)0)) {
    tcgetattr(fd, &(tP->origTerm));
    tcsetattr(fd, 0, &(tP->newTerm));
    tP->fd = fd;
  }
}

canonical_original_code:
void initTermPair(int fd, struct TermPair *tP) {
  if (fd != ERROR_SOCKFD_VALUE && tP != ((void *)0)) {
    tcgetattr(fd, &(tP->origTerm));
    tcsetattr(fd, 0, &(tP->newTerm));
    tP->fd = fd;
  }
}

variable_types: fd int


initBaudRatePair

decompiled_code:
__int64 __fastcall initBaudRatePair(_DWORD *a1, int a2, int a3)
{
if ( !a1 )
return 0LL;
*a1 = a2;
a1[1] = a3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_DWORD *a1, int a2, int a3)
{
if ( !a1 )
return 0LL;
*a1 = a2;
a1[1] = a3;
return 1LL;
}

original_code:
Bool initBaudRatePair(
  BaudRatePair *bP, const speed_t inSpeed, const speed_t outSpeed
) {
  if (bP == ((void *)0)) return False;
  bP->inBaudRate = inSpeed;
  bP->outBaudRate = outSpeed;
  return True;
}

canonical_original_code:
enum Bool initBaudRatePair(struct BaudRatePair *bP, unsigned int inSpeed, unsigned int outSpeed) {
  if (bP == ((void *)0)) return False;
  bP->inBaudRate = inSpeed;
  bP->outBaudRate = outSpeed;
  return True;
}

variable_types: struct BaudRatePair { unsigned int inBaudRate; unsigned int outBaudRate; } *

variable_types:
inSpeed
unsigned int

variable_types:
outSpeed
unsigned int


initTBaudRatePair

decompiled_code:
__int64 __fastcall initTBaudRatePair(__int64 a1, int a2, int a3)
{
return initBaudRatePair((_DWORD *)(a1 + 120), a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2, int a3)
{
return func7((_DWORD *)(a1 + 120), a2, a3);
}

original_code:
Bool initTBaudRatePair(
  TermPair *tP, const speed_t inBaudRate, const speed_t outBaudRate
) {
  return initBaudRatePair(&(tP->baudRatePair), inBaudRate, outBaudRate);
}

canonical_original_code:
enum Bool initTBaudRatePair(struct TermPair *tP, unsigned int inBaudRate, unsigned int outBaudRate) {
  return initBaudRatePair(&(tP->baudRatePair), inBaudRate, outBaudRate);
}

variable_types:
inBaudRate
unsigned int

variable_types:
outBaudRate
unsigned int