cylinderInterseption

repo: josemoO/RayTracing

decompiled_code:
void __fastcall cylinderInterseption(long double *a1, long double *a2, long double *a3, __int64 a4)
{
long double v4; // fst7
long double v5; // fst5
long double v6; // fst6
long double v7; // fst4
long double v8; // fst2
long double v9; // fst3
long double v10; // fst3
long double v11; // fst2
long double v12; // fst7
double v13; // xmm2_8
double v14; // xmm13_8
double v15; // xmm6_8
long double v16; // rt0
long double v17; // fst1
double v18; // xmm5_8
double v19; // xmm1_8
long double v20; // rt1
long double v21; // fst1
long double v22; // fst3
long double v23; // fst2
long double v24; // fst5
double v25; // xmm12_8
long double v26; // rt1
double v27; // xmm0_8
double v28; // xmm10_8
double v29; // xmm4_8
double v30; // xmm9_8
long double v31; // fst2
double v32; // xmm2_8
double v33; // xmm6_8
double v34; // xmm2_8
long double v35; // fst6
double v36; // xmm1_8
double v37; // xmm1_8
double v38; // xmm6_8
double v39; // xmm0_8
double v40; // xmm4_8
double v41; // xmm0_8
double v42; // xmm4_8
double v43; // xmm3_8
double v44; // xmm0_8
double v45; // xmm5_8
double v47; // xmm3_8
double v48; // xmm2_8
double v49; // xmm6_8
double v50; // xmm1_8
long double v51; // fst7
long double v52; // fst6
long double v53; // fst5
long double v54; // fst4
long double v55; // fst3
long double v56; // fst2
long double v57; // fst1
long double v58; // fst6
long double v59; // fst5
long double v60; // fst4
long double v61; // fst7
long double v62; // fst4
long double v63; // fst3
long double v64; // rtt
long double v65; // fst1
long double v66; // fst7
long double v67; // fst6
long double v68; // fst5
long double v69; // fst4
long double v70; // fst3
long double v71; // fst2
long double v72; // fst1
long double v73; // fst6
long double v74; // fst5
long double v75; // fst7
long double v76; // fst4
long double v77; // fst3
long double v78; // rt2
long double v79; // fst1
_BYTE v80[1280]; // [rsp-500h] [rbp-1018h] BYREF
long double v81; // [rsp+0h] [rbp-B18h]
long double v82; // [rsp+10h] [rbp-B08h]
long double v83; // [rsp+20h] [rbp-AF8h]
long double v84; // [rsp+30h] [rbp-AE8h]
long double v85; // [rsp+40h] [rbp-AD8h]
long double v86; // [rsp+50h] [rbp-AC8h]
long double v87; // [rsp+60h] [rbp-AB8h]
long double v88; // [rsp+70h] [rbp-AA8h]
long double v89; // [rsp+80h] [rbp-A98h]
long double v90; // [rsp+90h] [rbp-A88h]
long double v91; // [rsp+A0h] [rbp-A78h]
long double v92; // [rsp+B0h] [rbp-A68h]
long double v93; // [rsp+C0h] [rbp-A58h]
double v94; // [rsp+D8h] [rbp-A40h]
long double v95; // [rsp+E0h] [rbp-A38h]
long double v96; // [rsp+F0h] [rbp-A28h]
_BYTE v97[1280]; // [rsp+100h] [rbp-A18h] BYREF
_BYTE v98[1280]; // [rsp+600h] [rbp-518h] BYREF

v4 = *a2;
v81 = a3[44];
v5 = a3[45];
v6 = a3[46];
*(double *)&v82 = v81 * v4 + a2[1] * v5 + a2[2] * v6;
v7 = *(double *)&v82;
v94 = *(double *)&v82;
v8 = (*a1 - a3[32]) * v81 + (a1[1] - a3[33]) * v5;
v9 = a1[2];
v82 = a3[34];
v10 = (double)(v8 + (v9 - v82) * v6);
v95 = v7;
v11 = v4;
v12 = v81 * v7;
v13 = (double)v11 * (double)v11;
*(double *)&v83 = v5 * v7;
v14 = *(double *)&v83 * *(double *)&v83;
v15 = (double)a2[1] * (double)a2[1];
v16 = v5 * v7;
v17 = v7 * v6;
*(double *)&v83 = v17;
v18 = (double)v17 * (double)v17;
*(double *)&v83 = a2[2];
v84 = v11;
v19 = *(double *)&v83 * *(double *)&v83;
v20 = v17;
v86 = v11 + v11;
v96 = v10;
v21 = v10;
v22 = v81;
*(double *)&v81 = v21;
v85 = v12;
v88 = a2[1] + a2[1];
v23 = v5;
v24 = v20;
v83 = v23 * (double)v21;
v89 = a2[2] + a2[2];
v90 = v20 + v20;
*(double *)&v87 = *a1;
v25 = *(double *)&v87 * *(double *)&v87;
v26 = v6 * (double)v21;
v27 = a3[32];
v87 = v22 * v21;
*(double *)&v91 = v87;
v91 = *a1 + *a1;
*(double *)&v92 = a1[1];
v28 = *(double *)&v92 * *(double *)&v92;
v29 = (double)a3[33] * (double)a3[33];
*(double *)&v92 = v83;
v30 = (double)v83 * (double)v83;
v92 = a1[1] + a1[1];
v31 = a1[2];
v93 = v31 + v31;
*(double *)&v84 = v84 * -2.0 * v12 + (double)v12 * (double)v12 + v13;
v32 = *(double *)&v84;
*(double *)&v84 = v16 * (a2[1] * -2.0) + v14 + v15;
v33 = *(double *)&v84;
*(double *)&v84 = v24 * (-2.0 * a2[2]) + v18 + v19;
v34 = v32 + v33 + *(double *)&v84;
*(double *)&v84 = *a1 * v86 - a3[32] * v86 - v86 * v87 - *a1 * (v12 + v12) + a3[32] * (v12 + v12) + (v12 + v12) * v87;
v35 = v83;
*(double *)&v83 = a1[1] * v88
- a3[33] * v88
- v88 * v83
- a1[1] * (v16 + v16)
+ a3[33] * (v16 + v16)
+ (v16 + v16) * v83;
v36 = *(double *)&v84 + *(double *)&v83;
*(double *)&v83 = v82 * v90 + a1[2] * v89 - v89 * v82 - v89 * v26 - a1[2] * v90 + v90 * v26;
v37 = v36 + *(double *)&v83;
*(double *)&v83 = a3[31];
v38 = *(double *)&v83;
*(double *)&v83 = v87 * (a3[32] + a3[32]) + v27 * v27 + v25 + (double)v87 * (double)v87 - a3[32] * v91 - v91 * v87;
v39 = *(double *)&v83;
v40 = v35 * (a3[33] + a3[33]) + v29 + v28 + v30 - a3[33] * v92 - v92 * v35;
*(double *)&v83 = (double)v82 * (double)v82 + (double)v31 * (double)v31 + (double)v26 * (double)v26;
v41 = v39 + v40;
v42 = *(double *)&LC2;
*(double *)&v82 = v26 * (v82 + v82) + *(double *)&v83 - v93 * v82 - v93 * v26;
if ( v37 * v37 - (v41 + *(double *)&v82 - v38 * v38) * (4.0 * v34) > 0.0005 )
{
v43 = v37 * v37 - (v41 + *(double *)&v82 - v38 * v38) * (4.0 * v34);
v44 = 0.0;
*(_QWORD *)&v45 = *(_QWORD *)&v37 ^ LC3;
if ( v43 < 0.0 )
{
*(_QWORD *)&v86 = a3;
*(_QWORD *)&v85 = *(_QWORD *)&v37 ^ LC3;
*(double *)&v84 = v43;
*(double *)&v83 = v34 + v34;
*(double *)&v82 = (sqrt(v43) - v37) / (v34 + v34);
v44 = sqrt(v43);
a3 = *(long double **)&v86;
*(_QWORD *)&v45 = *(_QWORD *)&v37 ^ LC3;
v48 = v34 + v34;
v47 = v44;
v49 = *(double *)&v82;
v42 = *(double *)&LC2;
}
else
{
v47 = sqrt(v43);
v48 = v34 + v34;
v49 = (v47 - v37) / v48;
}
v50 = (v45 - v47) / v48;
if ( v49 > v42 )
{
v51 = *a1;
qmemcpy(v97, a3, 0x4C0uLL);
v52 = *a2;
v53 = a1[1];
v54 = a2[1];
v83 = a1[2];
v55 = a2[2];
v56 = a3[48];
v57 = a3[49];
if ( 0.0 == v56 && 0.0 == v57 )
goto LABEL_10;
v44 = v94 * v49 + *(double *)&v81;
*(double *)&v82 = v44;
if ( v57 >= v44 && *(double *)&v82 >= v56 )
{
LABEL_10:
*(double *)&v82 = v49;
*(double *)&v84 = (v45 - v47) / v48;
v58 = v52 * v49 + v51;
v59 = v53 + v54 * v49;
v60 = v83;
*(_QWORD *)&v83 = a3;
v61 = v49 * v55 + v60;
v62 = v95 * v49 + v96;
v63 = a3[31];
v64 = (v59 - (a3[45] * v62 + a3[33])) / v63;
v65 = v62 * a3[46] + a3[34];
*(long double *)&v97[1168] = (v58 - (a3[44] * v62 + a3[32])) / v63;
*(long double *)&v97[1184] = v64;
*(long double *)&v97[1200] = (v61 - v65) / v63;
*(long double *)&v97[1120] = *(long double *)&v97[1168];
*(long double *)&v97[1136] = v64;
*(long double *)&v97[1152] = *(long double *)&v97[1200];
*(long double *)&v97[1216] = v49;
*(long double *)&v97[1232] = v58;
*(long double *)&v97[1248] = v59;
*(long double *)&v97[1264] = v61;
qmemcpy(v80, v97, sizeof(v80));
insertInOrder(a4, v44, v50);
v50 = *(double *)&v84;
a3 = *(long double **)&v83;
v42 = *(double *)&LC2;
}
}
if ( v50 > v42 )
{
v66 = *a1;
qmemcpy(v98, a3, 0x4C0uLL);
v67 = *a2;
v68 = a1[1];
v69 = a2[1];
v82 = a1[2];
v70 = a2[2];
v71 = a3[48];
v72 = a3[49];
if ( 0.0 == v71 && 0.0 == v72 )
goto LABEL_14;
v44 = v94 * v50 + *(double *)&v81;
*(double *)&v81 = v44;
if ( v72 >= v44 && *(double *)&v81 >= v71 )
{
LABEL_14:
*(double *)&v81 = v50;
v73 = v67 * v50 + v66;
v74 = v68 + v69 * v50;
v75 = v50 * v70 + v82;
v76 = v95 * v50 + v96;
v77 = a3[31];
v78 = (v74 - (a3[45] * v76 + a3[33])) / v77;
v79 = v76 * a3[46] + a3[34];
*(long double *)&v98[1168] = (v73 - (a3[44] * v76 + a3[32])) / v77;
*(long double *)&v98[1184] = v78;
*(long double *)&v98[1200] = (v75 - v79) / v77;
*(long double *)&v98[1120] = *(long double *)&v98[1168];
*(long double *)&v98[1136] = v78;
*(long double *)&v98[1152] = *(long double *)&v98[1200];
*(long double *)&v98[1216] = v50;
*(long double *)&v98[1232] = v73;
*(long double *)&v98[1248] = v74;
*(long double *)&v98[1264] = v75;
qmemcpy(v80, v98, sizeof(v80));
insertInOrder(a4, v44, v50);
}
}
}
}

canonical_decompiled_code:
void __fastcall func0(long double *a1, long double *a2, long double *a3, __int64 a4)
{
long double v4; // fst7
long double v5; // fst5
long double v6; // fst6
long double v7; // fst4
long double v8; // fst2
long double v9; // fst3
long double v10; // fst3
long double v11; // fst2
long double v12; // fst7
double v13; // xmm2_8
double v14; // xmm13_8
double v15; // xmm6_8
long double v16; // rt0
long double v17; // fst1
double v18; // xmm5_8
double v19; // xmm1_8
long double v20; // rt1
long double v21; // fst1
long double v22; // fst3
long double v23; // fst2
long double v24; // fst5
double v25; // xmm12_8
long double v26; // rt1
double v27; // xmm0_8
double v28; // xmm10_8
double v29; // xmm4_8
double v30; // xmm9_8
long double v31; // fst2
double v32; // xmm2_8
double v33; // xmm6_8
double v34; // xmm2_8
long double v35; // fst6
double v36; // xmm1_8
double v37; // xmm1_8
double v38; // xmm6_8
double v39; // xmm0_8
double v40; // xmm4_8
double v41; // xmm0_8
double v42; // xmm4_8
double v43; // xmm3_8
double v44; // xmm0_8
double v45; // xmm5_8
double v47; // xmm3_8
double v48; // xmm2_8
double v49; // xmm6_8
double v50; // xmm1_8
long double v51; // fst7
long double v52; // fst6
long double v53; // fst5
long double v54; // fst4
long double v55; // fst3
long double v56; // fst2
long double v57; // fst1
long double v58; // fst6
long double v59; // fst5
long double v60; // fst4
long double v61; // fst7
long double v62; // fst4
long double v63; // fst3
long double v64; // rtt
long double v65; // fst1
long double v66; // fst7
long double v67; // fst6
long double v68; // fst5
long double v69; // fst4
long double v70; // fst3
long double v71; // fst2
long double v72; // fst1
long double v73; // fst6
long double v74; // fst5
long double v75; // fst7
long double v76; // fst4
long double v77; // fst3
long double v78; // rt2
long double v79; // fst1
_BYTE v80[1280]; // [rsp-500h] [rbp-1018h] BYREF
long double v81; // [rsp+0h] [rbp-B18h]
long double v82; // [rsp+10h] [rbp-B08h]
long double v83; // [rsp+20h] [rbp-AF8h]
long double v84; // [rsp+30h] [rbp-AE8h]
long double v85; // [rsp+40h] [rbp-AD8h]
long double v86; // [rsp+50h] [rbp-AC8h]
long double v87; // [rsp+60h] [rbp-AB8h]
long double v88; // [rsp+70h] [rbp-AA8h]
long double v89; // [rsp+80h] [rbp-A98h]
long double v90; // [rsp+90h] [rbp-A88h]
long double v91; // [rsp+A0h] [rbp-A78h]
long double v92; // [rsp+B0h] [rbp-A68h]
long double v93; // [rsp+C0h] [rbp-A58h]
double v94; // [rsp+D8h] [rbp-A40h]
long double v95; // [rsp+E0h] [rbp-A38h]
long double v96; // [rsp+F0h] [rbp-A28h]
_BYTE v97[1280]; // [rsp+100h] [rbp-A18h] BYREF
_BYTE v98[1280]; // [rsp+600h] [rbp-518h] BYREF

v4 = *a2;
v81 = a3[44];
v5 = a3[45];
v6 = a3[46];
*(double *)&v82 = v81 * v4 + a2[1] * v5 + a2[2] * v6;
v7 = *(double *)&v82;
v94 = *(double *)&v82;
v8 = (*a1 - a3[32]) * v81 + (a1[1] - a3[33]) * v5;
v9 = a1[2];
v82 = a3[34];
v10 = (double)(v8 + (v9 - v82) * v6);
v95 = v7;
v11 = v4;
v12 = v81 * v7;
v13 = (double)v11 * (double)v11;
*(double *)&v83 = v5 * v7;
v14 = *(double *)&v83 * *(double *)&v83;
v15 = (double)a2[1] * (double)a2[1];
v16 = v5 * v7;
v17 = v7 * v6;
*(double *)&v83 = v17;
v18 = (double)v17 * (double)v17;
*(double *)&v83 = a2[2];
v84 = v11;
v19 = *(double *)&v83 * *(double *)&v83;
v20 = v17;
v86 = v11 + v11;
v96 = v10;
v21 = v10;
v22 = v81;
*(double *)&v81 = v21;
v85 = v12;
v88 = a2[1] + a2[1];
v23 = v5;
v24 = v20;
v83 = v23 * (double)v21;
v89 = a2[2] + a2[2];
v90 = v20 + v20;
*(double *)&v87 = *a1;
v25 = *(double *)&v87 * *(double *)&v87;
v26 = v6 * (double)v21;
v27 = a3[32];
v87 = v22 * v21;
*(double *)&v91 = v87;
v91 = *a1 + *a1;
*(double *)&v92 = a1[1];
v28 = *(double *)&v92 * *(double *)&v92;
v29 = (double)a3[33] * (double)a3[33];
*(double *)&v92 = v83;
v30 = (double)v83 * (double)v83;
v92 = a1[1] + a1[1];
v31 = a1[2];
v93 = v31 + v31;
*(double *)&v84 = v84 * -2.0 * v12 + (double)v12 * (double)v12 + v13;
v32 = *(double *)&v84;
*(double *)&v84 = v16 * (a2[1] * -2.0) + v14 + v15;
v33 = *(double *)&v84;
*(double *)&v84 = v24 * (-2.0 * a2[2]) + v18 + v19;
v34 = v32 + v33 + *(double *)&v84;
*(double *)&v84 = *a1 * v86 - a3[32] * v86 - v86 * v87 - *a1 * (v12 + v12) + a3[32] * (v12 + v12) + (v12 + v12) * v87;
v35 = v83;
*(double *)&v83 = a1[1] * v88
- a3[33] * v88
- v88 * v83
- a1[1] * (v16 + v16)
+ a3[33] * (v16 + v16)
+ (v16 + v16) * v83;
v36 = *(double *)&v84 + *(double *)&v83;
*(double *)&v83 = v82 * v90 + a1[2] * v89 - v89 * v82 - v89 * v26 - a1[2] * v90 + v90 * v26;
v37 = v36 + *(double *)&v83;
*(double *)&v83 = a3[31];
v38 = *(double *)&v83;
*(double *)&v83 = v87 * (a3[32] + a3[32]) + v27 * v27 + v25 + (double)v87 * (double)v87 - a3[32] * v91 - v91 * v87;
v39 = *(double *)&v83;
v40 = v35 * (a3[33] + a3[33]) + v29 + v28 + v30 - a3[33] * v92 - v92 * v35;
*(double *)&v83 = (double)v82 * (double)v82 + (double)v31 * (double)v31 + (double)v26 * (double)v26;
v41 = v39 + v40;
v42 = *(double *)&LC2;
*(double *)&v82 = v26 * (v82 + v82) + *(double *)&v83 - v93 * v82 - v93 * v26;
if ( v37 * v37 - (v41 + *(double *)&v82 - v38 * v38) * (4.0 * v34) > 0.0005 )
{
v43 = v37 * v37 - (v41 + *(double *)&v82 - v38 * v38) * (4.0 * v34);
v44 = 0.0;
*(_QWORD *)&v45 = *(_QWORD *)&v37 ^ LC3;
if ( v43 < 0.0 )
{
*(_QWORD *)&v86 = a3;
*(_QWORD *)&v85 = *(_QWORD *)&v37 ^ LC3;
*(double *)&v84 = v43;
*(double *)&v83 = v34 + v34;
*(double *)&v82 = (sqrt(v43) - v37) / (v34 + v34);
v44 = sqrt(v43);
a3 = *(long double **)&v86;
*(_QWORD *)&v45 = *(_QWORD *)&v37 ^ LC3;
v48 = v34 + v34;
v47 = v44;
v49 = *(double *)&v82;
v42 = *(double *)&LC2;
}
else
{
v47 = sqrt(v43);
v48 = v34 + v34;
v49 = (v47 - v37) / v48;
}
v50 = (v45 - v47) / v48;
if ( v49 > v42 )
{
v51 = *a1;
qmemcpy(v97, a3, 0x4C0uLL);
v52 = *a2;
v53 = a1[1];
v54 = a2[1];
v83 = a1[2];
v55 = a2[2];
v56 = a3[48];
v57 = a3[49];
if ( 0.0 == v56 && 0.0 == v57 )
goto LABEL_10;
v44 = v94 * v49 + *(double *)&v81;
*(double *)&v82 = v44;
if ( v57 >= v44 && *(double *)&v82 >= v56 )
{
LABEL_10:
*(double *)&v82 = v49;
*(double *)&v84 = (v45 - v47) / v48;
v58 = v52 * v49 + v51;
v59 = v53 + v54 * v49;
v60 = v83;
*(_QWORD *)&v83 = a3;
v61 = v49 * v55 + v60;
v62 = v95 * v49 + v96;
v63 = a3[31];
v64 = (v59 - (a3[45] * v62 + a3[33])) / v63;
v65 = v62 * a3[46] + a3[34];
*(long double *)&v97[1168] = (v58 - (a3[44] * v62 + a3[32])) / v63;
*(long double *)&v97[1184] = v64;
*(long double *)&v97[1200] = (v61 - v65) / v63;
*(long double *)&v97[1120] = *(long double *)&v97[1168];
*(long double *)&v97[1136] = v64;
*(long double *)&v97[1152] = *(long double *)&v97[1200];
*(long double *)&v97[1216] = v49;
*(long double *)&v97[1232] = v58;
*(long double *)&v97[1248] = v59;
*(long double *)&v97[1264] = v61;
qmemcpy(v80, v97, sizeof(v80));
insertInOrder(a4, v44, v50);
v50 = *(double *)&v84;
a3 = *(long double **)&v83;
v42 = *(double *)&LC2;
}
}
if ( v50 > v42 )
{
v66 = *a1;
qmemcpy(v98, a3, 0x4C0uLL);
v67 = *a2;
v68 = a1[1];
v69 = a2[1];
v82 = a1[2];
v70 = a2[2];
v71 = a3[48];
v72 = a3[49];
if ( 0.0 == v71 && 0.0 == v72 )
goto LABEL_14;
v44 = v94 * v50 + *(double *)&v81;
*(double *)&v81 = v44;
if ( v72 >= v44 && *(double *)&v81 >= v71 )
{
LABEL_14:
*(double *)&v81 = v50;
v73 = v67 * v50 + v66;
v74 = v68 + v69 * v50;
v75 = v50 * v70 + v82;
v76 = v95 * v50 + v96;
v77 = a3[31];
v78 = (v74 - (a3[45] * v76 + a3[33])) / v77;
v79 = v76 * a3[46] + a3[34];
*(long double *)&v98[1168] = (v73 - (a3[44] * v76 + a3[32])) / v77;
*(long double *)&v98[1184] = v78;
*(long double *)&v98[1200] = (v75 - v79) / v77;
*(long double *)&v98[1120] = *(long double *)&v98[1168];
*(long double *)&v98[1136] = v78;
*(long double *)&v98[1152] = *(long double *)&v98[1200];
*(long double *)&v98[1216] = v50;
*(long double *)&v98[1232] = v73;
*(long double *)&v98[1248] = v74;
*(long double *)&v98[1264] = v75;
qmemcpy(v80, v98, sizeof(v80));
insertInOrder(a4, v44, v50);
}
}
}
}

original_code:
void cylinderInterseption(VECTOR *eyePosition, VECTOR *rayFromEyeDirection, OBJECT *cylinder, LIST_NODE_PTR *intersections) {
    INTERSECTION intersectionOne, intersectionTwo;
    double a_partCommon, b_partCommon;
    double ax, bx, cx, ay, by, cy, az, bz, cz;
    int insertIntersectionOne = 0, insertIntersectionTwo = 0;
    a_partCommon = rayFromEyeDirection->x * cylinder->cylinder.vectorQ.x + rayFromEyeDirection->y * cylinder->cylinder.vectorQ.y + rayFromEyeDirection->z * cylinder->cylinder.vectorQ.z;
    b_partCommon = cylinder->cylinder.vectorQ.x * (eyePosition->x - cylinder->cylinder.position.x) +
            cylinder->cylinder.vectorQ.y * (eyePosition->y - cylinder->cylinder.position.y) +
            cylinder->cylinder.vectorQ.z * (eyePosition->z - cylinder->cylinder.position.z);
    ax = -2 * rayFromEyeDirection->x * (a_partCommon * cylinder->cylinder.vectorQ.x) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.x, 2) + pow(rayFromEyeDirection->x, 2);
    ay = -2 * rayFromEyeDirection->y * (a_partCommon * cylinder->cylinder.vectorQ.y) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.y, 2) + pow(rayFromEyeDirection->y, 2);
    az = -2 * rayFromEyeDirection->z * (a_partCommon * cylinder->cylinder.vectorQ.z) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.z, 2) + pow(rayFromEyeDirection->z, 2);
    bx = 2 * rayFromEyeDirection->x * eyePosition->x - 2 * rayFromEyeDirection->x * cylinder->cylinder.position.x - 2 * rayFromEyeDirection->x * (b_partCommon * cylinder->cylinder.vectorQ.x)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * eyePosition->x + 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * cylinder->cylinder.position.x + 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * (b_partCommon * cylinder->cylinder.vectorQ.x);
    by = 2 * rayFromEyeDirection->y * eyePosition->y - 2 * rayFromEyeDirection->y * cylinder->cylinder.position.y - 2 * rayFromEyeDirection->y * (b_partCommon * cylinder->cylinder.vectorQ.y)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * eyePosition->y + 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * cylinder->cylinder.position.y + 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * (b_partCommon * cylinder->cylinder.vectorQ.y);
    bz = 2 * rayFromEyeDirection->z * eyePosition->z - 2 * rayFromEyeDirection->z * cylinder->cylinder.position.z - 2 * rayFromEyeDirection->z * (b_partCommon * cylinder->cylinder.vectorQ.z)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * eyePosition->z + 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * cylinder->cylinder.position.z + 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * (b_partCommon * cylinder->cylinder.vectorQ.z);
    cx = pow(eyePosition->x, 2) + pow(cylinder->cylinder.position.x, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.x, 2)
            - 2 * eyePosition->x * cylinder->cylinder.position.x - 2 * eyePosition->x * (b_partCommon * cylinder->cylinder.vectorQ.x) + 2 * cylinder->cylinder.position.x * (b_partCommon * cylinder->cylinder.vectorQ.x);
    cy = pow(eyePosition->y, 2) + pow(cylinder->cylinder.position.y, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.y, 2)
            - 2 * eyePosition->y * cylinder->cylinder.position.y - 2 * eyePosition->y * (b_partCommon * cylinder->cylinder.vectorQ.y) + 2 * cylinder->cylinder.position.y * (b_partCommon * cylinder->cylinder.vectorQ.y);
    cz = pow(eyePosition->z, 2) + pow(cylinder->cylinder.position.z, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.z, 2)
            - 2 * eyePosition->z * cylinder->cylinder.position.z - 2 * eyePosition->z * (b_partCommon * cylinder->cylinder.vectorQ.z) + 2 * cylinder->cylinder.position.z * (b_partCommon * cylinder->cylinder.vectorQ.z);
    double a_final, b_final, c_final, discriminating, t1, t2;
    a_final = ax + ay + az;
    b_final = bx + by + bz;
    c_final = (cx + cy + cz) - pow(cylinder->cylinder.radius, 2);
    discriminating = pow(b_final, 2) - 4 * a_final * c_final;
    if (discriminating > 0.0005) {
        t1 = (-1 * b_final + sqrt(discriminating)) / (2 * a_final);
        t2 = (-1 * b_final - sqrt(discriminating)) / (2 * a_final);
        if (t1 > 0.0005) {
            intersectionOne.intersection.x = eyePosition->x + t1 * rayFromEyeDirection->x;
            intersectionOne.intersection.y = eyePosition->y + t1 * rayFromEyeDirection->y;
            intersectionOne.intersection.z = eyePosition->z + t1 * rayFromEyeDirection->z;
            intersectionOne.t = t1;
            intersectionOne.object = *cylinder;
            if (cylinder->cylinder.distance1 != 0 || cylinder->cylinder.distance2 != 0) {
                double distanceOriginTo_XM_YM_ZM;
                distanceOriginTo_XM_YM_ZM = t1 * a_partCommon + b_partCommon;
                if (distanceOriginTo_XM_YM_ZM <= cylinder->cylinder.distance2 && distanceOriginTo_XM_YM_ZM >= cylinder->cylinder.distance1) {
                    insertIntersectionOne = 1;
                }
            } else {
                insertIntersectionOne = 1;
            }
            if (insertIntersectionOne == 1) {
                intersectionOne.object.normal.x = (intersectionOne.intersection.x -
                        (cylinder->cylinder.position.x + cylinder->cylinder.vectorQ.x * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.normal.y = (intersectionOne.intersection.y -
                        (cylinder->cylinder.position.y + cylinder->cylinder.vectorQ.y * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.normal.z = (intersectionOne.intersection.z -
                        (cylinder->cylinder.position.z + cylinder->cylinder.vectorQ.z * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.dependedNormal = intersectionOne.object.normal;
                insertInOrder(intersections, intersectionOne);
            }
        }
        if (t2 > 0.0005) {
            intersectionTwo.intersection.x = eyePosition->x + t2 * rayFromEyeDirection->x;
            intersectionTwo.intersection.y = eyePosition->y + t2 * rayFromEyeDirection->y;
            intersectionTwo.intersection.z = eyePosition->z + t2 * rayFromEyeDirection->z;
            intersectionTwo.t = t2;
            intersectionTwo.object = *cylinder;
            if (cylinder->cylinder.distance1 != 0 || cylinder->cylinder.distance2 != 0) {
                double distanceOriginTo_XM_YM_ZM;
                distanceOriginTo_XM_YM_ZM = t2 * a_partCommon + b_partCommon;
                if (distanceOriginTo_XM_YM_ZM <= cylinder->cylinder.distance2 && distanceOriginTo_XM_YM_ZM >= cylinder->cylinder.distance1) {
                    insertIntersectionTwo = 1;
                }
            } else {
                insertIntersectionTwo = 1;
            }
            if (insertIntersectionTwo == 1) {
                intersectionTwo.object.normal.x = (intersectionTwo.intersection.x -
                        (cylinder->cylinder.position.x + cylinder->cylinder.vectorQ.x * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.normal.y = (intersectionTwo.intersection.y -
                        (cylinder->cylinder.position.y + cylinder->cylinder.vectorQ.y * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.normal.z = (intersectionTwo.intersection.z -
                        (cylinder->cylinder.position.z + cylinder->cylinder.vectorQ.z * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.dependedNormal = intersectionTwo.object.normal;
                insertInOrder(intersections, intersectionTwo);
            }
        }
    }
}

canonical_original_code:
void cylinderInterseption(struct VECTOR *eyePosition, struct VECTOR *rayFromEyeDirection, struct OBJECT *cylinder, struct listNode **intersections) {
    struct INTERSECTION intersectionOne; struct INTERSECTION intersectionTwo;
    double a_partCommon; double b_partCommon;
    double ax; double bx; double cx; double ay; double by; double cy; double az; double bz; double cz;
    int insertIntersectionOne = 0; int insertIntersectionTwo = 0;
    a_partCommon = rayFromEyeDirection->x * cylinder->cylinder.vectorQ.x + rayFromEyeDirection->y * cylinder->cylinder.vectorQ.y + rayFromEyeDirection->z * cylinder->cylinder.vectorQ.z;
    b_partCommon = cylinder->cylinder.vectorQ.x * (eyePosition->x - cylinder->cylinder.position.x) +
            cylinder->cylinder.vectorQ.y * (eyePosition->y - cylinder->cylinder.position.y) +
            cylinder->cylinder.vectorQ.z * (eyePosition->z - cylinder->cylinder.position.z);
    ax = -2 * rayFromEyeDirection->x * (a_partCommon * cylinder->cylinder.vectorQ.x) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.x, 2) + pow(rayFromEyeDirection->x, 2);
    ay = -2 * rayFromEyeDirection->y * (a_partCommon * cylinder->cylinder.vectorQ.y) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.y, 2) + pow(rayFromEyeDirection->y, 2);
    az = -2 * rayFromEyeDirection->z * (a_partCommon * cylinder->cylinder.vectorQ.z) +
            pow(a_partCommon * cylinder->cylinder.vectorQ.z, 2) + pow(rayFromEyeDirection->z, 2);
    bx = 2 * rayFromEyeDirection->x * eyePosition->x - 2 * rayFromEyeDirection->x * cylinder->cylinder.position.x - 2 * rayFromEyeDirection->x * (b_partCommon * cylinder->cylinder.vectorQ.x)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * eyePosition->x + 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * cylinder->cylinder.position.x + 2 * (a_partCommon * cylinder->cylinder.vectorQ.x) * (b_partCommon * cylinder->cylinder.vectorQ.x);
    by = 2 * rayFromEyeDirection->y * eyePosition->y - 2 * rayFromEyeDirection->y * cylinder->cylinder.position.y - 2 * rayFromEyeDirection->y * (b_partCommon * cylinder->cylinder.vectorQ.y)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * eyePosition->y + 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * cylinder->cylinder.position.y + 2 * (a_partCommon * cylinder->cylinder.vectorQ.y) * (b_partCommon * cylinder->cylinder.vectorQ.y);
    bz = 2 * rayFromEyeDirection->z * eyePosition->z - 2 * rayFromEyeDirection->z * cylinder->cylinder.position.z - 2 * rayFromEyeDirection->z * (b_partCommon * cylinder->cylinder.vectorQ.z)
            - 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * eyePosition->z + 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * cylinder->cylinder.position.z + 2 * (a_partCommon * cylinder->cylinder.vectorQ.z) * (b_partCommon * cylinder->cylinder.vectorQ.z);
    cx = pow(eyePosition->x, 2) + pow(cylinder->cylinder.position.x, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.x, 2)
            - 2 * eyePosition->x * cylinder->cylinder.position.x - 2 * eyePosition->x * (b_partCommon * cylinder->cylinder.vectorQ.x) + 2 * cylinder->cylinder.position.x * (b_partCommon * cylinder->cylinder.vectorQ.x);
    cy = pow(eyePosition->y, 2) + pow(cylinder->cylinder.position.y, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.y, 2)
            - 2 * eyePosition->y * cylinder->cylinder.position.y - 2 * eyePosition->y * (b_partCommon * cylinder->cylinder.vectorQ.y) + 2 * cylinder->cylinder.position.y * (b_partCommon * cylinder->cylinder.vectorQ.y);
    cz = pow(eyePosition->z, 2) + pow(cylinder->cylinder.position.z, 2) + pow(b_partCommon * cylinder->cylinder.vectorQ.z, 2)
            - 2 * eyePosition->z * cylinder->cylinder.position.z - 2 * eyePosition->z * (b_partCommon * cylinder->cylinder.vectorQ.z) + 2 * cylinder->cylinder.position.z * (b_partCommon * cylinder->cylinder.vectorQ.z);
    double a_final; double b_final; double c_final; double discriminating; double t1; double t2;
    a_final = ax + ay + az;
    b_final = bx + by + bz;
    c_final = (cx + cy + cz) - pow(cylinder->cylinder.radius, 2);
    discriminating = pow(b_final, 2) - 4 * a_final * c_final;
    if (discriminating > 0.0005) {
        t1 = (-1 * b_final + sqrt(discriminating)) / (2 * a_final);
        t2 = (-1 * b_final - sqrt(discriminating)) / (2 * a_final);
        if (t1 > 0.0005) {
            intersectionOne.intersection.x = eyePosition->x + t1 * rayFromEyeDirection->x;
            intersectionOne.intersection.y = eyePosition->y + t1 * rayFromEyeDirection->y;
            intersectionOne.intersection.z = eyePosition->z + t1 * rayFromEyeDirection->z;
            intersectionOne.t = t1;
            intersectionOne.object = *cylinder;
            if (cylinder->cylinder.distance1 != 0 || cylinder->cylinder.distance2 != 0) {
                double distanceOriginTo_XM_YM_ZM;
                distanceOriginTo_XM_YM_ZM = t1 * a_partCommon + b_partCommon;
                if (distanceOriginTo_XM_YM_ZM <= cylinder->cylinder.distance2 && distanceOriginTo_XM_YM_ZM >= cylinder->cylinder.distance1) {
                    insertIntersectionOne = 1;
                }
            } else {
                insertIntersectionOne = 1;
            }
            if (insertIntersectionOne == 1) {
                intersectionOne.object.normal.x = (intersectionOne.intersection.x -
                        (cylinder->cylinder.position.x + cylinder->cylinder.vectorQ.x * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.normal.y = (intersectionOne.intersection.y -
                        (cylinder->cylinder.position.y + cylinder->cylinder.vectorQ.y * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.normal.z = (intersectionOne.intersection.z -
                        (cylinder->cylinder.position.z + cylinder->cylinder.vectorQ.z * (intersectionOne.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionOne.object.dependedNormal = intersectionOne.object.normal;
                insertInOrder(intersections, intersectionOne);
            }
        }
        if (t2 > 0.0005) {
            intersectionTwo.intersection.x = eyePosition->x + t2 * rayFromEyeDirection->x;
            intersectionTwo.intersection.y = eyePosition->y + t2 * rayFromEyeDirection->y;
            intersectionTwo.intersection.z = eyePosition->z + t2 * rayFromEyeDirection->z;
            intersectionTwo.t = t2;
            intersectionTwo.object = *cylinder;
            if (cylinder->cylinder.distance1 != 0 || cylinder->cylinder.distance2 != 0) {
                double distanceOriginTo_XM_YM_ZM;
                distanceOriginTo_XM_YM_ZM = t2 * a_partCommon + b_partCommon;
                if (distanceOriginTo_XM_YM_ZM <= cylinder->cylinder.distance2 && distanceOriginTo_XM_YM_ZM >= cylinder->cylinder.distance1) {
                    insertIntersectionTwo = 1;
                }
            } else {
                insertIntersectionTwo = 1;
            }
            if (insertIntersectionTwo == 1) {
                intersectionTwo.object.normal.x = (intersectionTwo.intersection.x -
                        (cylinder->cylinder.position.x + cylinder->cylinder.vectorQ.x * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.normal.y = (intersectionTwo.intersection.y -
                        (cylinder->cylinder.position.y + cylinder->cylinder.vectorQ.y * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.normal.z = (intersectionTwo.intersection.z -
                        (cylinder->cylinder.position.z + cylinder->cylinder.vectorQ.z * (intersectionTwo.t * a_partCommon + b_partCommon))) / cylinder->cylinder.radius;
                intersectionTwo.object.dependedNormal = intersectionTwo.object.normal;
                insertInOrder(intersections, intersectionTwo);
            }
        }
    }
}

variable_types: struct VECTOR { long double x; long double y; long double z; } *

variable_types:
rayFromEyeDirection
struct VECTOR *

variable_types: struct OBJECT { struct RGB { float r; float g; float b; } color; long double diffusionCoefficient_Kd; long double ambientLightingCoefficient_Ka; long double specularReflexionCoeffient_Ks; long double specularReflexionRefinement_Kn; long double O1; long double O2; long double O3; long double translucencyCoefficient_kt; long double componentD; long double dependedComponentD; enum OBJECT_TYPE { LIGHT=0, SPHERE=1, POLYGON=2, DISK=3, CYLINDER=4, CONE=5, PLANE=6 } type; struct OBJECT_SPHERE { long double radius; struct VECTOR position; } sphere; struct OBJECT_POLYGON { void *listOfPointsPtr; void *listOfPointsSplashPtr; } polygon; struct OBJECT_DISK { long double radiusOne; long double radiusTwo; struct VECTOR position; struct POINT { long double x; long double y; long double z; } point1; struct POINT point2; struct POINT point3; } disk; struct OBJECT_CYLINDER { long double radius; struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; struct VECTOR vectorQ; long double componentD; long double distance1; long double distance2; } cylinder; struct OBJECT_CONE { struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; struct VECTOR vectorQ; long double componentD; long double distance1; long double distance2; long double uRatio; long double vRatio; } cone; struct VECTOR normal; struct VECTOR dependedNormal; } *

variable_types: struct listNode { struct NODE_DATA { struct OBJECT object; struct LIGHT_POINT { struct VECTOR position; long double intensity_Ip; long double c1; long double c2; long double c3; } light; struct POINT point; struct INTERSECTION { struct OBJECT object; long double t; struct VECTOR intersection; } intersection; } data; struct listNode *nextPtr; } **

variable_types: struct INTERSECTION { struct OBJECT { struct RGB { float r; float g; float b; } color; long double diffusionCoefficient_Kd; long double ambientLightingCoefficient_Ka; long double specularReflexionCoeffient_Ks; long double specularReflexionRefinement_Kn; long double O1; long double O2; long double O3; long double translucencyCoefficient_kt; long double componentD; long double dependedComponentD; enum OBJECT_TYPE { LIGHT=0, SPHERE=1, POLYGON=2, DISK=3, CYLINDER=4, CONE=5, PLANE=6 } type; struct OBJECT_SPHERE { long double radius; struct VECTOR { long double x; long double y; long double z; } position; } sphere; struct OBJECT_POLYGON { void *listOfPointsPtr; void *listOfPointsSplashPtr; } polygon; struct OBJECT_DISK { long double radiusOne; long double radiusTwo; struct VECTOR position; struct POINT { long double x; long double y; long double z; } point1; struct POINT point2; struct POINT point3; } disk; struct OBJECT_CYLINDER { long double radius; struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; struct VECTOR vectorQ; long double componentD; long double distance1; long double distance2; } cylinder; struct OBJECT_CONE { struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; struct VECTOR vectorQ; long double componentD; long double distance1; long double distance2; long double uRatio; long double vRatio; } cone; struct VECTOR normal; struct VECTOR dependedNormal; } object; long double t; struct VECTOR intersection; }

variable_types: ax double

variable_types: bx double

variable_types: cx double

variable_types: ay double

variable_types: by double

variable_types: cy double

variable_types: az double

variable_types: bz double

variable_types: cz double

variable_types: insertIntersectionOne int

variable_types: insertIntersectionTwo int

variable_types: discriminating double

user_defined_types: struct OBJECT { struct RGB color; long double diffusionCoefficient_Kd; long double ambientLightingCoefficient_Ka; long double specularReflexionCoeffient_Ks; long double specularReflexionRefinement_Kn; long double O1; long double O2; long double O3; long double translucencyCoefficient_kt; long double componentD; long double dependedComponentD; enum OBJECT_TYPE type; struct OBJECT_SPHERE sphere; struct OBJECT_POLYGON polygon; struct OBJECT_DISK disk; struct OBJECT_CYLINDER cylinder; struct OBJECT_CONE cone; struct VECTOR normal; struct VECTOR dependedNormal; }

user_defined_types: struct OBJECT_DISK { long double radiusOne; long double radiusTwo; struct VECTOR position; struct POINT point1; struct POINT point2; struct POINT point3; }

user_defined_types: struct listNode { struct NODE_DATA data; struct listNode *nextPtr; }

user_defined_types: struct NODE_DATA { struct OBJECT object; struct LIGHT_POINT light; struct POINT point; struct INTERSECTION intersection; }


testsimple

repo: josephburns/map

decompiled_code:
__int64 testsimple()
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
void *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
ptr[0] = 0LL;
puts("\n\nTesting map_init, kv_put, kv_get, kv_remove...\n");
map_init(&v1, 0LL);
kv_put(&v1, "fred", "flinstone");
kv_get(v1, "fred", ptr);
if ( ptr[0] )
{
printf("get fred = %s\n", (const char *)ptr[0]);
free(ptr[0]);
}
ptr[0] = 0LL;
kv_put(&v1, "fred", "flanders");
kv_get(v1, "fred", ptr);
if ( ptr[0] )
{
printf("get fred = %s\n", (const char *)ptr[0]);
free(ptr[0]);
}
ptr[0] = 0LL;
kv_remove(v1, "fred");
kv_get(v1, "fred", ptr);
if ( ptr[0] )
free(ptr[0]);
else
printf("after remove: get fred = %s\n", "(null)");
ptr[0] = 0LL;
return map_destroy(v1);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v1; // [rsp+0h] [rbp-18h] BYREF
void *ptr[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = 0LL;
ptr[0] = 0LL;
puts("\n\nTesting map_init, kv_put, kv_get, kv_remove...\n");
map_init(&v1, 0LL);
kv_put(&v1, "fred", "flinstone");
kv_get(v1, "fred", ptr);
if ( ptr[0] )
{
printf("get fred = %s\n", (const char *)ptr[0]);
free(ptr[0]);
}
ptr[0] = 0LL;
kv_put(&v1, "fred", "flanders");
kv_get(v1, "fred", ptr);
if ( ptr[0] )
{
printf("get fred = %s\n", (const char *)ptr[0]);
free(ptr[0]);
}
ptr[0] = 0LL;
kv_remove(v1, "fred");
kv_get(v1, "fred", ptr);
if ( ptr[0] )
free(ptr[0]);
else
printf("after remove: get fred = %s\n", "(null)");
ptr[0] = 0LL;
return map_destroy(v1);
}

original_code:
void testsimple(void) {
 map *testmap = ((void *)0);
 char *getresult = ((void *)0);
 status code1, code2, code3, code4;
 printf("\n\nTesting map_init, kv_put, kv_get, kv_remove...\n\n");
 code1 = map_init(&testmap, CHPTR_CHPTR);
   code2 = kv_put(&testmap,"fred","flinstone");
   code3 = kv_get(testmap,"fred", (void**)&getresult);
   if(getresult != ((void *)0)) {
      printf("get fred = %s\n", getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   code2 = kv_put(&testmap,"fred","flanders");
   code3 = kv_get(testmap,"fred", (void**)&getresult);
   if(getresult != ((void *)0)) {
    printf("get fred = %s\n", getresult);
      free(getresult);
   }
   getresult = ((void *)0);
 kv_remove(testmap,"fred");
   code3= kv_get(testmap,"fred", (void**)&getresult);
   if(getresult == ((void *)0)) {
      printf("after remove: get fred = %s\n", ((getresult!=((void *)0))?getresult:"(null)"));
   }
   else free(getresult);
   getresult = ((void *)0);
 code4 = map_destroy(testmap);
}

canonical_original_code:
void testsimple() {
 struct map *testmap = ((void *)0);
 char *getresult = ((void *)0);
 enum status code1; enum status code2; enum status code3; enum status code4;
 printf("\n\nTesting map_init, kv_put, kv_get, kv_remove...\n\n");
 code1 = map_init(&testmap, CHPTR_CHPTR);
   code2 = kv_put(&testmap,"fred","flinstone");
   code3 = kv_get(testmap,"fred", (void **)&getresult);
   if(getresult != ((void *)0)) {
      printf("get fred = %s\n", getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   code2 = kv_put(&testmap,"fred","flanders");
   code3 = kv_get(testmap,"fred", (void **)&getresult);
   if(getresult != ((void *)0)) {
    printf("get fred = %s\n", getresult);
      free(getresult);
   }
   getresult = ((void *)0);
 kv_remove(testmap,"fred");
   code3= kv_get(testmap,"fred", (void **)&getresult);
   if(getresult == ((void *)0)) {
      printf("after remove: get fred = %s\n", ((getresult!=((void *)0))?getresult:"(null)"));
   }
   else free(getresult);
   getresult = ((void *)0);
 code4 = map_destroy(testmap);
}

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } *

variable_types:
getresult
char *

return_type: void

user_defined_types: struct map { struct bucket *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status type; }

user_defined_types: struct bucket { struct kvpair *start; unsigned long index; long count; }


testsimplelong

decompiled_code:
__int64 testsimplelong()
{
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
void *ptr; // [rsp+10h] [rbp-18h] BYREF
__int64 v3[2]; // [rsp+18h] [rbp-10h] BYREF

v1 = 0LL;
v3[0] = 35LL;
puts("\n\nTesting chptr-long map simple map functions...\n");
map_init(&v1, 1LL);
kv_put(&v1, "fred", v3);
kv_get(v1, "fred", &ptr);
if ( ptr )
{
printf("get fred = %ld\n", *(_QWORD *)ptr);
free(ptr);
}
ptr = 0LL;
v3[0] = 53LL;
kv_put(&v1, "fred", v3);
kv_get(v1, "fred", &ptr);
if ( ptr )
{
printf("get fred = %ld\n", *(_QWORD *)ptr);
free(ptr);
}
ptr = 0LL;
kv_remove(v1, "fred");
kv_get(v1, "fred", &ptr);
if ( ptr )
{
puts("remove failed!");
free(ptr);
}
else
{
puts("get fred after remove = (null)");
}
ptr = 0LL;
return map_destroy(v1);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v1; // [rsp+8h] [rbp-20h] BYREF
void *ptr; // [rsp+10h] [rbp-18h] BYREF
__int64 v3[2]; // [rsp+18h] [rbp-10h] BYREF

v1 = 0LL;
v3[0] = 35LL;
puts("\n\nTesting chptr-long map simple map functions...\n");
map_init(&v1, 1LL);
kv_put(&v1, "fred", v3);
kv_get(v1, "fred", &ptr);
if ( ptr )
{
printf("get fred = %ld\n", *(_QWORD *)ptr);
free(ptr);
}
ptr = 0LL;
v3[0] = 53LL;
kv_put(&v1, "fred", v3);
kv_get(v1, "fred", &ptr);
if ( ptr )
{
printf("get fred = %ld\n", *(_QWORD *)ptr);
free(ptr);
}
ptr = 0LL;
kv_remove(v1, "fred");
kv_get(v1, "fred", &ptr);
if ( ptr )
{
puts("remove failed!");
free(ptr);
}
else
{
puts("get fred after remove = (null)");
}
ptr = 0LL;
return map_destroy(v1);
}

original_code:
void testsimplelong(void) {
   map *testmap = ((void *)0);
   long *getresult, putarg = 35;
   status code1,code2,code3,code4;
   printf("\n\nTesting chptr-long map simple map functions...\n\n");
   code1 = map_init(&testmap, CHPTR_LONG);
   code2 = kv_put(&testmap, "fred", &putarg);
   code3 = kv_get(testmap, "fred", (void**)&getresult);
   if(getresult!=((void *)0)) {
      printf("get fred = %ld\n",*getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   putarg = 53;
   code2 = kv_put(&testmap, "fred", &putarg);
   code3 = kv_get(testmap, "fred", (void**)&getresult);
   if(getresult!=((void *)0)) {
      printf("get fred = %ld\n",*getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   kv_remove(testmap,"fred");
   code3 = kv_get(testmap, "fred", (void**)&getresult);
   if(getresult==((void *)0)) {
      printf("get fred after remove = (null)\n");
   }
   else {
      printf("remove failed!\n");
      free(getresult);
   }
   getresult = ((void *)0);
   code4 = map_destroy(testmap);
}

canonical_original_code:
void testsimplelong() {
   struct map *testmap = ((void *)0);
   long *getresult; long putarg = 35;
   enum status code1; enum status code2; enum status code3; enum status code4;
   printf("\n\nTesting chptr-long map simple map functions...\n\n");
   code1 = map_init(&testmap, CHPTR_LONG);
   code2 = kv_put(&testmap, "fred", &putarg);
   code3 = kv_get(testmap, "fred", (void **)&getresult);
   if(getresult!=((void *)0)) {
      printf("get fred = %ld\n",*getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   putarg = 53;
   code2 = kv_put(&testmap, "fred", &putarg);
   code3 = kv_get(testmap, "fred", (void **)&getresult);
   if(getresult!=((void *)0)) {
      printf("get fred = %ld\n",*getresult);
      free(getresult);
   }
   getresult = ((void *)0);
   kv_remove(testmap,"fred");
   code3 = kv_get(testmap, "fred", (void **)&getresult);
   if(getresult==((void *)0)) {
      printf("get fred after remove = (null)\n");
   }
   else {
      printf("remove failed!\n");
      free(getresult);
   }
   getresult = ((void *)0);
   code4 = map_destroy(testmap);
}

variable_types:
getresult
long *

variable_types: putarg long

variable_types: enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 }

user_defined_types: struct kvpair { void *key; void *value; struct kvpair *next; }


testnotsosimple

original_code:
void testnotsosimple(void) {
 map *testmap;
 int i,j,k,t;
   int code1,code2,code3;
 char *key=((void *)0),*value=((void *)0),**thekeys=((void *)0);
   printf("\n\ntesting keys...\n\n");
 code1 = map_init(&testmap, CHPTR_CHPTR);
   for(i=0;i<25;i++) {
    t = (random() % 25) + 1;
  key = (char*)malloc(sizeof(char) * t + 1);
  value = (char*)malloc(sizeof(char) * t + 1);
      for(k=0;k<t;k++) {
       j = random() % 26;
         *(key+k) = *(value+k) = 97 + j;
      }
  *(key+t) = *(value+t) = 0x00;
      printf("%d - inserting key: %s, value: %s\n",i,key,value);
  code2 = kv_put(&testmap,key,value);
      if(key!=((void *)0))
         free((void*)key);
      if(value!=((void *)0))
         free((void*)value);
      key = value = ((void *)0);
 }
 map_keys(testmap,(void***)&thekeys);
 for(i=0;i<testmap->size;i++) {
  printf("key %d: %s\n",i,*(thekeys+i));
 }
 if(thekeys!=((void *)0))
  free(thekeys);
 code3 = map_destroy(testmap);
}

canonical_original_code:
void testnotsosimple() {
 struct map *testmap;
 int i; int j; int k; int t;
   int code1; int code2; int code3;
 char *key = ((void *)0); char *value = ((void *)0); char **thekeys = ((void *)0);
   printf("\n\ntesting keys...\n\n");
 code1 = map_init(&testmap, CHPTR_CHPTR);
   for(i=0;i<25;i++) {
    t = (random() % 25) + 1;
  key = (char *)malloc(sizeof(char) * t + 1);
  value = (char *)malloc(sizeof(char) * t + 1);
      for(k=0;k<t;k++) {
       j = random() % 26;
         *(key+k) = *(value+k) = 97 + j;
      }
  *(key+t) = *(value+t) = 0x00;
      printf("%d - inserting key: %s, value: %s\n",i,key,value);
  code2 = kv_put(&testmap,key,value);
      if(key!=((void *)0))
         free((void *)key);
      if(value!=((void *)0))
         free((void *)value);
      key = value = ((void *)0);
 }
 map_keys(testmap,(void ***)&thekeys);
 for(i=0;i<testmap->size;i++) {
  printf("key %d: %s\n",i,*(thekeys+i));
 }
 if(thekeys!=((void *)0))
  free(thekeys);
 code3 = map_destroy(testmap);
}

variable_types: i int

variable_types: j int

variable_types: k int

variable_types: t int

variable_types:
key
char *

variable_types:
value
char *

variable_types:
thekeys
char **

user_defined_types: enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 }


testnotsosimplelong

original_code:
void testnotsosimplelong(void) {
 map *testmap;
 int i,j,k,t;
   int code1,code2,code3;
 char *key=((void *)0),**thekeys=((void *)0);
   long value;
   printf("\n\ntesting keys...\n\n");
 code1 = map_init(&testmap, CHPTR_LONG);
   for(i=0;i<25;i++) {
    t = (random() % 25) + 1;
  key = (char*)malloc(sizeof(char) * t + 1);
      for(k=0;k<t;k++) {
       j = random() % 26;
         *(key+k) = 97 + j;
      }
      value = (long)j;
  *(key+t) = 0x00;
      printf("%d - inserting key: %s, value: %ld\n",i,key,value);
  code2 = kv_put(&testmap,key,&value);
      if(key!=((void *)0))
         free((void*)key);
      key = ((void *)0);
 }
 map_keys(testmap,(void***)&thekeys);
 for(i=0;i<testmap->size;i++) {
  printf("key %d: %s\n",i,*(thekeys+i));
 }
 if(thekeys!=((void *)0))
  free(thekeys);
 code3 = map_destroy(testmap);
}

canonical_original_code:
void testnotsosimplelong() {
 struct map *testmap;
 int i; int j; int k; int t;
   int code1; int code2; int code3;
 char *key = ((void *)0); char **thekeys = ((void *)0);
   long value;
   printf("\n\ntesting keys...\n\n");
 code1 = map_init(&testmap, CHPTR_LONG);
   for(i=0;i<25;i++) {
    t = (random() % 25) + 1;
  key = (char *)malloc(sizeof(char) * t + 1);
      for(k=0;k<t;k++) {
       j = random() % 26;
         *(key+k) = 97 + j;
      }
      value = (long)j;
  *(key+t) = 0x00;
      printf("%d - inserting key: %s, value: %ld\n",i,key,value);
  code2 = kv_put(&testmap,key,&value);
      if(key!=((void *)0))
         free((void *)key);
      key = ((void *)0);
 }
 map_keys(testmap,(void ***)&thekeys);
 for(i=0;i<testmap->size;i++) {
  printf("key %d: %s\n",i,*(thekeys+i));
 }
 if(thekeys!=((void *)0))
  free(thekeys);
 code3 = map_destroy(testmap);
}

variable_types: value long


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
testsimple(argc, argv, envp);
testnotsosimple();
testsimplelong();
testnotsosimplelong();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func0(argc, argv, envp);
func2();
func1();
func3();
return 0;
}

original_code:
int main(void) {
   testsimple();
   testnotsosimple();
   testsimplelong();
   testnotsosimplelong();
   return 0;
}

canonical_original_code:
int main() {
   testsimple();
   testnotsosimple();
   testsimplelong();
   testnotsosimplelong();
   return 0;
}

return_type: int


original_code:
int create_map(map **inhashmap, int thetype, long start_size, int rsize_factor, double ld_factor) {
   bucket *curr = ((void *)0);
   map *hashmap = ((void *)0);
   int i;
   hashmap = (map*)malloc(sizeof(map));
   hashmap->size = 0;
   hashmap->bucketsize = start_size;
   hashmap->resize_factor = rsize_factor;
   hashmap->load_factor = ld_factor;
   hashmap->currentload = 0.0;
   hashmap->bucketsused = 0;
   hashmap->scale = rand()% 4 + 1;
   hashmap->offset = rand() % hashmap->bucketsize;
   hashmap->type = thetype;
   hashmap->start = (bucket*)malloc((sizeof(bucket) * hashmap->bucketsize));
   if( hashmap->start == ((void *)0)) {
      perror("malloc of buckets failed");
      return FAILURE;
   }
   else {
      curr = hashmap->start;
      for(i=0; i < hashmap->bucketsize; i++) {
         curr->start = ((void *)0);
         curr->index = i;
         curr->count = 0;
         curr++;
      }
   }
   *inhashmap = hashmap;
   return SUCCESS;
}

canonical_original_code:
int create_map(struct map **inhashmap, int thetype, long start_size, int rsize_factor, double ld_factor) {
   struct bucket *curr = ((void *)0);
   struct map *hashmap = ((void *)0);
   int i;
   hashmap = (struct map *)malloc(sizeof(map));
   hashmap->size = 0;
   hashmap->bucketsize = start_size;
   hashmap->resize_factor = rsize_factor;
   hashmap->load_factor = ld_factor;
   hashmap->currentload = 0.0;
   hashmap->bucketsused = 0;
   hashmap->scale = rand()% 4 + 1;
   hashmap->offset = rand() % hashmap->bucketsize;
   hashmap->type = thetype;
   hashmap->start = (struct bucket *)malloc((sizeof(bucket) * hashmap->bucketsize));
   if( hashmap->start == ((void *)0)) {
      perror("malloc of buckets failed");
      return FAILURE;
   }
   else {
      curr = hashmap->start;
      for(i=0; i < hashmap->bucketsize; i++) {
         curr->start = ((void *)0);
         curr->index = i;
         curr->count = 0;
         curr++;
      }
   }
   *inhashmap = hashmap;
   return SUCCESS;
}

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } **

variable_types: thetype int


decompiled_code:
__int64 __fastcall map_init(_QWORD *a1, int a2)
{
return create_map(a1, a2, 5LL, 2, 0.5);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2)
{
return func0(a1, a2, 5LL, 2, 0.5);
}

original_code:
int map_init(map **themap,int type) {
   return create_map(themap, type, (long)5, (long)2, (double)0.5);
}

canonical_original_code:
int map_init(struct map **themap, int type) {
   return create_map(themap, type, (long)5, (long)2, (double)0.5);
}

variable_types: type int


isempty

decompiled_code:
_BOOL8 __fastcall isempty(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

original_code:
int isempty(map *themap) {
   return ((themap->size) > 0 ? FALSE : TRUE);
}

canonical_original_code:
int isempty(struct map *themap) {
   return ((themap->size) > 0 ? FALSE : TRUE);
}


decompiled_code:
__int64 __fastcall map_size(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(_QWORD *)(a1 + 16);
}

original_code:
unsigned long map_size(map *themap) {
   return themap->size;
}

canonical_original_code:
unsigned long map_size(struct map *themap) {
   return themap->size;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall k_hash(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 1]();
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 1]();
}

original_code:
unsigned long k_hash(map *themap,void *key) {
   return mapfntab[themap->type].fn_hash(themap,key);
}

canonical_original_code:
unsigned long k_hash(struct map *themap, void *key) {
   return mapfntab[themap->type].fn_hash(themap,key);
}

variable_types:
key
void *


decompiled_code:
__int64 __fastcall kv_put(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(*(_QWORD *)a1 + 64LL) + 2]();
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(*(_QWORD *)a1 + 64LL) + 2]();
}

original_code:
int kv_put(map **ppthemap, void *key, void *value) {
   int code;
   code = mapfntab[(*ppthemap)->type].fn_put(ppthemap, key, value);
   return code;
}

canonical_original_code:
int kv_put(struct map **ppthemap, void *key, void *value) {
   int code;
   code = mapfntab[(*ppthemap)->type].fn_put(ppthemap, key, value);
   return code;
}

variable_types:
value
void *

variable_types: code int


decompiled_code:
__int64 __fastcall kv_get(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 3]();
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 3]();
}

original_code:
int kv_get(map *themap, void *key, void **newvalue) {
   return mapfntab[themap->type].fn_get(themap, key, newvalue);
}

canonical_original_code:
int kv_get(struct map *themap, void *key, void **newvalue) {
   return mapfntab[themap->type].fn_get(themap, key, newvalue);
}

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } *

variable_types:
newvalue
void **


decompiled_code:
__int64 __fastcall kv_remove(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 4]();
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 4]();
}

original_code:
int kv_remove(map *themap, void *key) {
   return mapfntab[themap->type].fn_remove(themap, key);
}

canonical_original_code:
int kv_remove(struct map *themap, void *key) {
   return mapfntab[themap->type].fn_remove(themap, key);
}


decompiled_code:
__int64 __fastcall map_destroy(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 5]();
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 5]();
}

original_code:
int map_destroy(map *themap) {
   return mapfntab[themap->type].fn_destroy(themap);
}

canonical_original_code:
int map_destroy(struct map *themap) {
   return mapfntab[themap->type].fn_destroy(themap);
}


decompiled_code:
__int64 __fastcall map_rehash(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(*(_QWORD *)a1 + 64LL) + 6]();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(*(_QWORD *)a1 + 64LL) + 6]();
}

original_code:
int map_rehash(map **themap) {
   return mapfntab[(*themap)->type].fn_rehash(themap);
}

canonical_original_code:
int map_rehash(struct map **themap) {
   return mapfntab[(*themap)->type].fn_rehash(themap);
}


decompiled_code:
__int64 __fastcall map_keys(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 7]();
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return mapfntab[8 * (unsigned __int64)*(unsigned int *)(a1 + 64) + 7]();
}

original_code:
int map_keys(map *themap, void ***keyptr) {
   return mapfntab[themap->type].fn_keys(themap,keyptr);
}

canonical_original_code:
int map_keys(struct map *themap, void ***keyptr) {
   return mapfntab[themap->type].fn_keys(themap,keyptr);
}

variable_types:
keyptr
void ***


decompiled_code:
__int64 __fastcall chptr_hash(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
_BYTE *v2; // rcx
__int64 i; // r8

v1 = *a1;
v2 = a1 + 1;
for ( i = 5381LL; v1; v1 = *(v2 - 1) )
{
++v2;
i += 32 * i + v1;
}
return i;
}

original_code:
unsigned long chptr_hash(unsigned char *str) {
   unsigned long hashvalue = 5381;
   int c;
   while ((c = *str++))
      hashvalue = ((hashvalue << 5) + hashvalue) + c;
   return hashvalue;
}

variable_types:
str
unsigned char *

variable_types:
hashvalue
unsigned long

variable_types: c int


decompiled_code:
unsigned __int64 __fastcall sp_k_hash(__int64 a1, unsigned __int8 *a2)
{
__int64 v2; // rax
__int64 v3; // r9

v2 = chptr_hash(a2);
return (*(unsigned int *)(v3 + 60) + v2 * (unsigned __int64)*(unsigned int *)(v3 + 56)) % *(_QWORD *)(v3 + 8);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func1(__int64 a1, unsigned __int8 *a2)
{
__int64 v2; // rax
__int64 v3; // r9

v2 = func0(a2);
return (*(unsigned int *)(v3 + 60) + v2 * (unsigned __int64)*(unsigned int *)(v3 + 56)) % *(_QWORD *)(v3 + 8);
}

original_code:
unsigned long sp_k_hash(map* themap, void* string) {
   return ((themap->scale) * chptr_hash((char*)string) + themap->offset) % themap->bucketsize;
}

canonical_original_code:
unsigned long sp_k_hash(struct map *themap, void *string) {
   return ((themap->scale) * chptr_hash((char *)string) + themap->offset) % themap->bucketsize;
}

variable_types:
string
void *


decompiled_code:
__int64 __fastcall sp_kv_get(__int64 a1, unsigned __int8 *a2, char **a3)
{
unsigned __int64 v4; // rax
_QWORD *v5; // r10
__int64 v6; // rbx
size_t v7; // rax
char *v8; // rax
__int64 result; // rax

v4 = sp_k_hash(a1, a2);
v6 = *(_QWORD *)(*v5 + 24 * v4);
if ( v6 )
{
while ( strcmp(*(const char **)v6, (const char *)a2) )
{
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
goto LABEL_6;
}
v7 = strlen(*(const char **)(v6 + 8));
v8 = (char *)malloc(v7 + 1);
*a3 = v8;
strcpy(v8, *(const char **)(v6 + 8));
result = 1LL;
}
else
{
LABEL_6:
result = 2LL;
*a3 = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int8 *a2, char **a3)
{
unsigned __int64 v4; // rax
_QWORD *v5; // r10
__int64 v6; // rbx
size_t v7; // rax
char *v8; // rax
__int64 result; // rax

v4 = func1(a1, a2);
v6 = *(_QWORD *)(*v5 + 24 * v4);
if ( v6 )
{
while ( strcmp(*(const char **)v6, (const char *)a2) )
{
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
goto LABEL_6;
}
v7 = strlen(*(const char **)(v6 + 8));
v8 = (char *)malloc(v7 + 1);
*a3 = v8;
strcpy(v8, *(const char **)(v6 + 8));
result = 1LL;
}
else
{
LABEL_6:
result = 2LL;
*a3 = 0LL;
}
return result;
}

original_code:
int sp_kv_get(map *themap, void *key, void **value) {
 unsigned long code = 0;
 bucket* buck = ((void *)0);
 kvpair *kvcurr = ((void *)0);
 code = sp_k_hash(themap, key);
   buck = themap->start + code;
 kvcurr = buck->start;
 while(kvcurr != ((void *)0)) {
      if(strcmp(((char*)kvcurr->key),(char*)key) == 0) {
     (*value) = malloc(sizeof(char) * strlen(kvcurr->value) + 1);
         strcpy((*value),kvcurr->value);
         return SUCCESS;
  }
  kvcurr = kvcurr->next;
 }
   *value = ((void *)0);
 return NOTFOUND;
}

canonical_original_code:
int sp_kv_get(struct map *themap, void *key, void **value) {
 unsigned long code = 0;
 struct bucket *buck = ((void *)0);
 struct kvpair *kvcurr = ((void *)0);
 code = sp_k_hash(themap, key);
   buck = themap->start + code;
 kvcurr = buck->start;
 while(kvcurr != ((void *)0)) {
      if(strcmp(((char *)kvcurr->key),(char *)key) == 0) {
     (*value) = malloc(sizeof(char) * strlen(kvcurr->value) + 1);
         strcpy((*value),kvcurr->value);
         return SUCCESS;
  }
  kvcurr = kvcurr->next;
 }
   *value = ((void *)0);
 return NOTFOUND;
}

variable_types:
value
void **

variable_types:
code
unsigned long

variable_types: struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *


decompiled_code:
__int64 __fastcall sp_kv_remove(__int64 a1, unsigned __int8 *a2)
{
int v2; // eax
_QWORD *v3; // r10
_QWORD *v4; // rax
__int64 v5; // rbx
_QWORD *v6; // r14
int i; // er12
char *v8; // r15
_QWORD *v9; // rbp
int v10; // eax
void *v11; // rdi
_QWORD *v13; // [rsp+8h] [rbp-40h]

v2 = sp_k_hash(a1, a2);
v4 = (_QWORD *)(*v3 + 24LL * v2);
v13 = v4;
if ( !v4 )
return 0LL;
v5 = *v4;
if ( !*v4 )
return 2LL;
v6 = (_QWORD *)*v4;
for ( i = 0; ; ++i )
{
v8 = *(char **)v5;
v9 = (_QWORD *)v5;
v10 = strcmp(*(const char **)v5, (const char *)a2);
v5 = *(_QWORD *)(v5 + 16);
if ( !v10 )
break;
v6 = v9;
if ( !v5 )
return 2LL;
}
if ( i )
v6[2] = v5;
else
*v13 = v5;
free(v8);
v11 = (void *)v9[1];
if ( v11 )
free(v11);
free(v9);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned __int8 *a2)
{
int v2; // eax
_QWORD *v3; // r10
_QWORD *v4; // rax
__int64 v5; // rbx
_QWORD *v6; // r14
int i; // er12
char *v8; // r15
_QWORD *v9; // rbp
int v10; // eax
void *v11; // rdi
_QWORD *v13; // [rsp+8h] [rbp-40h]

v2 = func1(a1, a2);
v4 = (_QWORD *)(*v3 + 24LL * v2);
v13 = v4;
if ( !v4 )
return 0LL;
v5 = *v4;
if ( !*v4 )
return 2LL;
v6 = (_QWORD *)*v4;
for ( i = 0; ; ++i )
{
v8 = *(char **)v5;
v9 = (_QWORD *)v5;
v10 = strcmp(*(const char **)v5, (const char *)a2);
v5 = *(_QWORD *)(v5 + 16);
if ( !v10 )
break;
v6 = v9;
if ( !v5 )
return 2LL;
}
if ( i )
v6[2] = v5;
else
*v13 = v5;
free(v8);
v11 = (void *)v9[1];
if ( v11 )
free(v11);
free(v9);
return 1LL;
}

original_code:
int sp_kv_remove(map *themap, void *searchstring) {
 bucket *bucketptr=((void *)0);
 kvpair *prev=((void *)0),*curr=((void *)0);
 int i=0,code;
 code = sp_k_hash(themap, (char*)searchstring);
 bucketptr = themap->start + code;
 if(bucketptr == ((void *)0))
  return FALSE;
 else {
  prev = curr = bucketptr->start;
  while(curr != ((void *)0)) {
    if(strcmp(curr->key, (char*)searchstring)==0) {
    if(i==0)
     bucketptr->start = curr->next;
    else
     prev->next = curr->next;
    if(curr->key != ((void *)0))
     free((void*)curr->key);
            curr->key = ((void *)0);
    if(curr->value != ((void *)0))
     free((void*)curr->value);
            curr->value = ((void *)0);
            if(curr != ((void *)0))
               free((void*)curr);
            curr = prev = ((void *)0);
    return TRUE;
   }
   prev = curr;
   curr = curr->next;
   i++;
  }
  return NOTFOUND;
 }
}

canonical_original_code:
int sp_kv_remove(struct map *themap, void *searchstring) {
 struct bucket *bucketptr = ((void *)0);
 struct kvpair *prev = ((void *)0); struct kvpair *curr = ((void *)0);
 int i = 0; int code;
 code = sp_k_hash(themap, (char *)searchstring);
 bucketptr = themap->start + code;
 if(bucketptr == ((void *)0))
  return FALSE;
 else {
  prev = curr = bucketptr->start;
  while(curr != ((void *)0)) {
    if(strcmp(curr->key, (char *)searchstring)==0) {
    if(i==0)
     bucketptr->start = curr->next;
    else
     prev->next = curr->next;
    if(curr->key != ((void *)0))
     free((void *)curr->key);
            curr->key = ((void *)0);
    if(curr->value != ((void *)0))
     free((void *)curr->value);
            curr->value = ((void *)0);
            if(curr != ((void *)0))
               free((void *)curr);
            curr = prev = ((void *)0);
    return TRUE;
   }
   prev = curr;
   curr = curr->next;
   i++;
  }
  return NOTFOUND;
 }
}

variable_types:
searchstring
void *

variable_types: struct kvpair { void *key; void *value; struct kvpair *next; } *

variable_types: i int


original_code:
int sp_map_destroy(map *themap) {
 bucket *bucketptr = ((void *)0);
 kvpair *kvcurr = ((void *)0), *kvprev = ((void *)0);
 int i=0;
 bucketptr = themap->start;
 for(i=0; i < themap->bucketsize; i++) {
  if(bucketptr->start != ((void *)0)) {
   kvcurr = bucketptr->start;
   while(kvcurr != ((void *)0)) {
    if(kvcurr->key != ((void *)0))
     free(kvcurr->key);
    kvcurr->key = ((void *)0);
    if(kvcurr->value != ((void *)0))
     free(kvcurr->value);
    kvcurr->value = ((void *)0);
    kvprev = kvcurr;
    kvcurr = kvcurr->next;
    kvprev->next = ((void *)0);
    if(kvprev != ((void *)0))
     free((void*)kvprev);
    kvprev = ((void *)0);
   }
  }
  bucketptr++;
 }
 if(themap->start != ((void *)0))
  free((void*)themap->start);
   themap->start = ((void *)0);
 themap = ((void *)0);
   return SUCCESS;
}

canonical_original_code:
int sp_map_destroy(struct map *themap) {
 struct bucket *bucketptr = ((void *)0);
 struct kvpair *kvcurr = ((void *)0); struct kvpair *kvprev = ((void *)0);
 int i = 0;
 bucketptr = themap->start;
 for(i=0; i < themap->bucketsize; i++) {
  if(bucketptr->start != ((void *)0)) {
   kvcurr = bucketptr->start;
   while(kvcurr != ((void *)0)) {
    if(kvcurr->key != ((void *)0))
     free(kvcurr->key);
    kvcurr->key = ((void *)0);
    if(kvcurr->value != ((void *)0))
     free(kvcurr->value);
    kvcurr->value = ((void *)0);
    kvprev = kvcurr;
    kvcurr = kvcurr->next;
    kvprev->next = ((void *)0);
    if(kvprev != ((void *)0))
     free((void *)kvprev);
    kvprev = ((void *)0);
   }
  }
  bucketptr++;
 }
 if(themap->start != ((void *)0))
  free((void *)themap->start);
   themap->start = ((void *)0);
 themap = ((void *)0);
   return SUCCESS;
}


original_code:
int sp_map_keys(map *themap, void ***inkeys) {
 bucket *bucketptr=((void *)0);
   kvpair *curr=((void *)0);
   void **pkeys = ((void *)0);
   int i=0;
 pkeys = (void**)malloc(sizeof(char*) * ((themap->size)+1));
   if(pkeys == ((void *)0)) {
    perror("key list malloc failed\n");
      return FAILURE;
   }
   bucketptr = themap->start;
 for(i=0;i<themap->bucketsize;i++) {
  if((bucketptr->start) == ((void *)0)) {
   bucketptr++;
   continue;
  }
  else {
   curr = bucketptr->start;
   while(curr!=((void *)0)) {
    *pkeys = (char*)malloc(sizeof(char) * (strlen(curr->key)+1));
    if((*pkeys)!=((void *)0)) {
     strcpy((*pkeys),curr->key);
     pkeys++;
    }
    curr = curr->next;
   }
  }
  bucketptr++;
 }
 *pkeys = ((void *)0);
   *inkeys = pkeys -= themap->size;
   return SUCCESS;
}

canonical_original_code:
int sp_map_keys(struct map *themap, void ***inkeys) {
 struct bucket *bucketptr = ((void *)0);
   struct kvpair *curr = ((void *)0);
   void **pkeys = ((void *)0);
   int i = 0;
 pkeys = (void **)malloc(sizeof(char *) * ((themap->size)+1));
   if(pkeys == ((void *)0)) {
    perror("key list malloc failed\n");
      return FAILURE;
   }
   bucketptr = themap->start;
 for(i=0;i<themap->bucketsize;i++) {
  if((bucketptr->start) == ((void *)0)) {
   bucketptr++;
   continue;
  }
  else {
   curr = bucketptr->start;
   while(curr!=((void *)0)) {
    *pkeys = (char *)malloc(sizeof(char) * (strlen(curr->key)+1));
    if((*pkeys)!=((void *)0)) {
     strcpy((*pkeys),curr->key);
     pkeys++;
    }
    curr = curr->next;
   }
  }
  bucketptr++;
 }
 *pkeys = ((void *)0);
   *inkeys = pkeys -= themap->size;
   return SUCCESS;
}

variable_types:
inkeys
void ***

variable_types:
pkeys
void **


nextprobableprime

decompiled_code:
__int64 __fastcall nextprobableprime(__int64 a1)
{
return a1 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return a1 + 1;
}

original_code:
unsigned long nextprobableprime(unsigned long num) {
 return num + 1;
}

variable_types:
num
unsigned long


original_code:
int sp_map_rehash(map **incmap) {
   map *themap = *incmap;
 map *pnewmap = ((void *)0);
 kvpair *curr=((void *)0),*prev=((void *)0);
 bucket *bucketptr=((void *)0);
   status code;
 long i=0;
   pnewmap = (map*)malloc(sizeof(map));
   code = create_map(&pnewmap, themap->type, nextprobableprime((themap->bucketsize) * (themap->resize_factor)), themap->resize_factor, themap->load_factor);
 bucketptr = themap->start;
 for(i=0;i<themap->bucketsize;i++) {
  if((bucketptr->start) == ((void *)0)) {
   bucketptr++;
   continue;
  }
  else {
   curr = bucketptr->start;
   while(curr!=((void *)0)) {
    kv_put(&pnewmap, (void*)curr->key, (void*)curr->value);
    prev = curr;
    curr = curr->next;
    if((prev->key)!=((void *)0))
       free((void*)prev->key);
    prev->key = ((void *)0);
    if((prev->value)!=((void *)0))
     free((void*)prev->value);
    prev->value = ((void *)0);
            if(prev!=((void *)0))
               free((void*)prev);
            prev = ((void *)0);
   }
  }
  bucketptr++;
 }
 if(themap->start!=((void *)0))
  free((void*)themap->start);
 themap->start = ((void *)0);
   if(themap!=((void *)0))
      free((void*)themap);
   themap = ((void *)0);
   *incmap = pnewmap;
   return SUCCESS;
}

canonical_original_code:
int sp_map_rehash(struct map **incmap) {
   struct map *themap = *incmap;
 struct map *pnewmap = ((void *)0);
 struct kvpair *curr = ((void *)0); struct kvpair *prev = ((void *)0);
 struct bucket *bucketptr = ((void *)0);
   enum status code;
 long i = 0;
   pnewmap = (struct map *)malloc(sizeof(map));
   code = create_map(&pnewmap, themap->type, nextprobableprime((themap->bucketsize) * (themap->resize_factor)), themap->resize_factor, themap->load_factor);
 bucketptr = themap->start;
 for(i=0;i<themap->bucketsize;i++) {
  if((bucketptr->start) == ((void *)0)) {
   bucketptr++;
   continue;
  }
  else {
   curr = bucketptr->start;
   while(curr!=((void *)0)) {
    kv_put(&pnewmap, (void *)curr->key, (void *)curr->value);
    prev = curr;
    curr = curr->next;
    if((prev->key)!=((void *)0))
       free((void *)prev->key);
    prev->key = ((void *)0);
    if((prev->value)!=((void *)0))
     free((void *)prev->value);
    prev->value = ((void *)0);
            if(prev!=((void *)0))
               free((void *)prev);
            prev = ((void *)0);
   }
  }
  bucketptr++;
 }
 if(themap->start!=((void *)0))
  free((void *)themap->start);
 themap->start = ((void *)0);
   if(themap!=((void *)0))
      free((void *)themap);
   themap = ((void *)0);
   *incmap = pnewmap;
   return SUCCESS;
}

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } **

variable_types: i long


decompiled_code:
__int64 __fastcall sp_kv_put(__int64 *a1, unsigned __int8 *a2, void *a3)
{
__int64 v4; // r12
unsigned __int64 v5; // rax
__int64 v6; // r10
__int64 *v7; // r15
__int64 v8; // rbx
_QWORD *v9; // rax
__int64 result; // rax
void *v11; // rdi
char *v12; // rax
_QWORD *v13; // rax
__int64 v14; // rax
bool v15; // sf
unsigned __int64 v16; // rax
double v17; // xmm0_8
__int64 v18; // rax
double v19; // xmm1_8
double v20; // xmm0_8
bool v21; // cc
__int64 v22; // rdx

v4 = *a1;
v5 = sp_k_hash(*a1, a2);
v7 = (__int64 *)(v6 + 24 * v5);
v8 = *v7;
if ( *v7 )
{
while ( strcmp(*(const char **)v8, (const char *)a2) )
{
if ( !*(_QWORD *)(v8 + 16) )
{
v9 = sp_createkvpair(a2, a3);
if ( v9 )
{
++*(_QWORD *)(v4 + 16);
*(_QWORD *)(v8 + 16) = v9;
result = 1LL;
}
else
{
perror("allocate of kvpair at end of list failed");
result = 0LL;
}
return result;
}
v8 = *(_QWORD *)(v8 + 16);
}
v11 = *(void **)(v8 + 8);
if ( v11 )
free(v11);
v12 = (char *)malloc(9uLL);
*(_QWORD *)(v8 + 8) = v12;
strcpy(v12, (const char *)a3);
result = 1LL;
}
else
{
v13 = sp_createkvpair(a2, a3);
*v7 = (__int64)v13;
if ( v13 )
{
v14 = *(_QWORD *)(v4 + 24);
++*(_QWORD *)(v4 + 16);
v15 = v14 + 1 < 0;
v16 = v14 + 1;
*(_QWORD *)(v4 + 24) = v16;
if ( v15 )
v17 = (double)(int)(v16 & 1 | (v16 >> 1)) + (double)(int)(v16 & 1 | (v16 >> 1));
else
v17 = (double)(int)v16;
v18 = *(_QWORD *)(v4 + 8);
if ( v18 < 0 )
{
v22 = *(_QWORD *)(v4 + 8) & 1LL | (*(_QWORD *)(v4 + 8) >> 1);
v19 = (double)(int)v22 + (double)(int)v22;
}
else
{
v19 = (double)(int)v18;
}
v20 = v17 / v19;
result = 1LL;
v21 = v20 <= *(double *)(v4 + 48);
*(double *)(v4 + 40) = v20;
if ( !v21 )
{
sp_map_rehash((void **)a1);
result = 1LL;
}
}
else
{
perror("new kvpair allocation failed");
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1, unsigned __int8 *a2, void *a3)
{
__int64 v4; // r12
unsigned __int64 v5; // rax
__int64 v6; // r10
__int64 *v7; // r15
__int64 v8; // rbx
_QWORD *v9; // rax
__int64 result; // rax
void *v11; // rdi
char *v12; // rax
_QWORD *v13; // rax
__int64 v14; // rax
bool v15; // sf
unsigned __int64 v16; // rax
double v17; // xmm0_8
__int64 v18; // rax
double v19; // xmm1_8
double v20; // xmm0_8
bool v21; // cc
__int64 v22; // rdx

v4 = *a1;
v5 = func1(*a1, a2);
v7 = (__int64 *)(v6 + 24 * v5);
v8 = *v7;
if ( *v7 )
{
while ( strcmp(*(const char **)v8, (const char *)a2) )
{
if ( !*(_QWORD *)(v8 + 16) )
{
v9 = sp_createkvpair(a2, a3);
if ( v9 )
{
++*(_QWORD *)(v4 + 16);
*(_QWORD *)(v8 + 16) = v9;
result = 1LL;
}
else
{
perror("allocate of kvpair at end of list failed");
result = 0LL;
}
return result;
}
v8 = *(_QWORD *)(v8 + 16);
}
v11 = *(void **)(v8 + 8);
if ( v11 )
free(v11);
v12 = (char *)malloc(9uLL);
*(_QWORD *)(v8 + 8) = v12;
strcpy(v12, (const char *)a3);
result = 1LL;
}
else
{
v13 = sp_createkvpair(a2, a3);
*v7 = (__int64)v13;
if ( v13 )
{
v14 = *(_QWORD *)(v4 + 24);
++*(_QWORD *)(v4 + 16);
v15 = v14 + 1 < 0;
v16 = v14 + 1;
*(_QWORD *)(v4 + 24) = v16;
if ( v15 )
v17 = (double)(int)(v16 & 1 | (v16 >> 1)) + (double)(int)(v16 & 1 | (v16 >> 1));
else
v17 = (double)(int)v16;
v18 = *(_QWORD *)(v4 + 8);
if ( v18 < 0 )
{
v22 = *(_QWORD *)(v4 + 8) & 1LL | (*(_QWORD *)(v4 + 8) >> 1);
v19 = (double)(int)v22 + (double)(int)v22;
}
else
{
v19 = (double)(int)v18;
}
v20 = v17 / v19;
result = 1LL;
v21 = v20 <= *(double *)(v4 + 48);
*(double *)(v4 + 40) = v20;
if ( !v21 )
{
func7((void **)a1);
result = 1LL;
}
}
else
{
perror("new kvpair allocation failed");
result = 0LL;
}
}
return result;
}

original_code:
int sp_kv_put(map **inmap, void *inkey, void *invalue) {
   unsigned long code;
 bucket *bucketptr;
 char *prev = ((void *)0);
   map *themap = *inmap;
   char* key = (char*)inkey;
   char* value = (char*)invalue;
 bucketptr = themap->start;
 code = sp_k_hash(themap, key);
 bucketptr += code;
 if(bucketptr->start == ((void *)0)) {
  bucketptr->start = sp_createkvpair(key,value);
  if(bucketptr->start == ((void *)0)) {
   perror("new kvpair allocation failed");
   return FAILURE;
  }
  else {
   themap->size++;
   themap->bucketsused++;
   themap->currentload = (double)(themap->bucketsused) / (double)(themap->bucketsize);
   if(themap->currentload > themap->load_factor) {
    sp_map_rehash(inmap);
   }
  }
 }
 else {
  kvpair *entry,*preventry;
  entry = bucketptr->start;
  while(entry != ((void *)0)) {
   if(strcmp(entry->key, key) == 0) {
    prev = entry->value;
    if(prev != ((void *)0))
     free((void*)prev);
    prev = ((void *)0);
    entry->value = (char*)malloc(sizeof(value) + 1);
    strcpy(entry->value,value);
    return SUCCESS;
   }
   preventry = entry;
   entry = entry->next;
  }
  entry = sp_createkvpair(key,value);
  if(entry == ((void *)0)) {
   perror("allocate of kvpair at end of list failed");
   return FAILURE;
  }
  else {
   themap->size++;
   preventry->next = entry;
  }
 }
 return SUCCESS;
}

canonical_original_code:
int sp_kv_put(struct map **inmap, void *inkey, void *invalue) {
   unsigned long code;
 struct bucket *bucketptr;
 char *prev = ((void *)0);
   struct map *themap = *inmap;
   char *key = (char*)inkey;
   char *value = (char*)invalue;
 bucketptr = themap->start;
 code = sp_k_hash(themap, key);
 bucketptr += code;
 if(bucketptr->start == ((void *)0)) {
  bucketptr->start = sp_createkvpair(key,value);
  if(bucketptr->start == ((void *)0)) {
   perror("new kvpair allocation failed");
   return FAILURE;
  }
  else {
   themap->size++;
   themap->bucketsused++;
   themap->currentload = (double)(themap->bucketsused) / (double)(themap->bucketsize);
   if(themap->currentload > themap->load_factor) {
    sp_map_rehash(inmap);
   }
  }
 }
 else {
  struct kvpair *entry; struct kvpair *preventry;
  entry = bucketptr->start;
  while(entry != ((void *)0)) {
   if(strcmp(entry->key, key) == 0) {
    prev = entry->value;
    if(prev != ((void *)0))
     free((void *)prev);
    prev = ((void *)0);
    entry->value = (char *)malloc(sizeof(value) + 1);
    strcpy(entry->value,value);
    return SUCCESS;
   }
   preventry = entry;
   entry = entry->next;
  }
  entry = sp_createkvpair(key,value);
  if(entry == ((void *)0)) {
   perror("allocate of kvpair at end of list failed");
   return FAILURE;
  }
  else {
   themap->size++;
   preventry->next = entry;
  }
 }
 return SUCCESS;
}

variable_types:
inkey
void *

variable_types:
invalue
void *

variable_types:
prev
char *

variable_types: struct map { struct bucket { struct kvpair { void *key; void *value; struct kvpair *next; } *start; unsigned long index; long count; } *start; unsigned long bucketsize; unsigned long size; unsigned long bucketsused; unsigned int resize_factor; double currentload; double load_factor; unsigned int scale; unsigned int offset; enum status { FAILURE=0, SUCCESS=1, NOTFOUND=2 } type; } *

variable_types:
key
char *

variable_types:
value
char *


original_code:
int si_kv_put(map **inmap, void *inkey, void *invalue) {
   unsigned long code;
 bucket *bucketptr;
   map *themap = *inmap;
   char* key = (char*)inkey;
   long value = *((long*)invalue);
 bucketptr = themap->start;
 code = sp_k_hash(themap, key);
 bucketptr += code;
 if(bucketptr->start == ((void *)0)) {
  bucketptr->start = si_createkvpair(key,value);
  if(bucketptr->start == ((void *)0)) {
   perror("new kvpair allocation failed");
   return FAILURE;
  }
  else {
   themap->size++;
   themap->bucketsused++;
   themap->currentload = (double)(themap->bucketsused) / (double)(themap->bucketsize);
   if(themap->currentload > themap->load_factor) {
    map_rehash(inmap);
   }
  }
 }
 else {
  kvpair *entry,*preventry;
  entry = bucketptr->start;
  while(entry != ((void *)0)) {
   if(strcmp(entry->key, key) == 0) {
            (*((long*)entry->value)) = value;
    return SUCCESS;
   }
   preventry = entry;
   entry = entry->next;
  }
  entry = si_createkvpair(key,value);
  if(entry == ((void *)0)) {
   perror("allocate of kvpair at end of list failed");
   return FAILURE;
  }
  else {
   themap->size++;
   preventry->next = entry;
  }
 }
 return SUCCESS;
}

canonical_original_code:
int si_kv_put(struct map **inmap, void *inkey, void *invalue) {
   unsigned long code;
 struct bucket *bucketptr;
   struct map *themap = *inmap;
   char *key = (char*)inkey;
   long value = *((long*)invalue);
 bucketptr = themap->start;
 code = sp_k_hash(themap, key);
 bucketptr += code;
 if(bucketptr->start == ((void *)0)) {
  bucketptr->start = si_createkvpair(key,value);
  if(bucketptr->start == ((void *)0)) {
   perror("new kvpair allocation failed");
   return FAILURE;
  }
  else {
   themap->size++;
   themap->bucketsused++;
   themap->currentload = (double)(themap->bucketsused) / (double)(themap->bucketsize);
   if(themap->currentload > themap->load_factor) {
    map_rehash(inmap);
   }
  }
 }
 else {
  struct kvpair *entry; struct kvpair *preventry;
  entry = bucketptr->start;
  while(entry != ((void *)0)) {
   if(strcmp(entry->key, key) == 0) {
            (*((long *)entry->value)) = value;
    return SUCCESS;
   }
   preventry = entry;
   entry = entry->next;
  }
  entry = si_createkvpair(key,value);
  if(entry == ((void *)0)) {
   perror("allocate of kvpair at end of list failed");
   return FAILURE;
  }
  else {
   themap->size++;
   preventry->next = entry;
  }
 }
 return SUCCESS;
}

variable_types: value long


decompiled_code:
__int64 __fastcall si_kv_get(__int64 a1, unsigned __int8 *a2, _QWORD *a3)
{
unsigned __int64 v4; // rax
_QWORD *v5; // r10
__int64 v6; // rbx
_QWORD *v7; // rax
__int64 v8; // rdx
__int64 result; // rax

v4 = sp_k_hash(a1, a2);
v6 = *(_QWORD *)(*v5 + 24 * v4);
if ( v6 )
{
while ( strcmp(*(const char **)v6, (const char *)a2) )
{
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
goto LABEL_8;
}
v7 = malloc(8uLL);
if ( v7 )
{
v8 = **(_QWORD **)(v6 + 8);
*a3 = v7;
*v7 = v8;
}
result = 1LL;
}
else
{
LABEL_8:
*a3 = 0LL;
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned __int8 *a2, _QWORD *a3)
{
unsigned __int64 v4; // rax
_QWORD *v5; // r10
__int64 v6; // rbx
_QWORD *v7; // rax
__int64 v8; // rdx
__int64 result; // rax

v4 = func1(a1, a2);
v6 = *(_QWORD *)(*v5 + 24 * v4);
if ( v6 )
{
while ( strcmp(*(const char **)v6, (const char *)a2) )
{
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
goto LABEL_8;
}
v7 = malloc(8uLL);
if ( v7 )
{
v8 = **(_QWORD **)(v6 + 8);
*a3 = v7;
*v7 = v8;
}
result = 1LL;
}
else
{
LABEL_8:
*a3 = 0LL;
result = 2LL;
}
return result;
}

original_code:
int si_kv_get(map *themap,void *key,void **value) {
 unsigned long code = 0;
 bucket* buck = ((void *)0);
 kvpair *kvcurr = ((void *)0);
   long *plong = ((void *)0);
 code = sp_k_hash(themap, key);
   buck = themap->start + code;
 kvcurr = buck->start;
 while(kvcurr != ((void *)0)) {
      if(strcmp(((char*)kvcurr->key),(char*)key) == 0) {
     plong = (void*)malloc(sizeof(long));
         if(plong != ((void *)0)) {
            *plong = *((long*)kvcurr->value);
            *value = (void*)plong;
         }
         return SUCCESS;
  }
  kvcurr = kvcurr->next;
 }
   *value = ((void *)0);
 return NOTFOUND;
}

canonical_original_code:
int si_kv_get(struct map *themap, void *key, void **value) {
 unsigned long code = 0;
 struct bucket *buck = ((void *)0);
 struct kvpair *kvcurr = ((void *)0);
   long *plong = ((void *)0);
 code = sp_k_hash(themap, key);
   buck = themap->start + code;
 kvcurr = buck->start;
 while(kvcurr != ((void *)0)) {
      if(strcmp(((char *)kvcurr->key),(char *)key) == 0) {
     plong = (void *)malloc(sizeof(long));
         if(plong != ((void *)0)) {
            *plong = *((long *)kvcurr->value);
            *value = (void *)plong;
         }
         return SUCCESS;
  }
  kvcurr = kvcurr->next;
 }
   *value = ((void *)0);
 return NOTFOUND;
}

variable_types:
key
void *

variable_types:
value
void **

variable_types:
code
unsigned long

variable_types:
plong
long *


FichaEnTurno

repo: joseprous/damas-chinas

decompiled_code:
__int64 __fastcall FichaEnTurno(int a1)
{
int v1; // ecx
__int64 v2; // rax

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0LL;
v2 = 0LL;
while ( turnos[7 * modo + turno + v2] != a1 )
{
if ( v1 <= (int)++v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
int v1; // ecx
__int64 v2; // rax

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0LL;
v2 = 0LL;
while ( turnos[7 * modo + turno + v2] != a1 )
{
if ( v1 <= (int)++v2 )
return 0LL;
}
return 1LL;
}

original_code:
int FichaEnTurno(int ficha)
{
 int i;
 for (i=0;i<fichasxturno[modo];i++)
 {
  if (ficha == turnos[modo][turno+i]) return 1;
 }
 return 0;
}

variable_types: ficha int

variable_types: i int


DameContrario

decompiled_code:
__int64 __fastcall DameContrario(int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = (unsigned int)(a1 - 2);
if ( (unsigned int)v1 <= 5 )
result = (unsigned int)CSWTCH_36[v1];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 v1; // rdi
__int64 result; // rax

v1 = (unsigned int)(a1 - 2);
if ( (unsigned int)v1 <= 5 )
result = (unsigned int)CSWTCH_36[v1];
return result;
}

original_code:
int DameContrario(int ficha)
{
 switch (ficha)
 {
  case 2: return 3;
  case 3: return 2;
  case 4: return 5;
  case 5: return 4;
  case 7: return 6;
  case 6: return 7;
 }
}


ComerFicha

decompiled_code:
__int64 __fastcall ComerFicha(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rsi
int v4; // edi

result = (unsigned int)comer;
if ( comer )
{
v3 = 13LL * a1 + a2;
v4 = tablero[v3];
result = FichaEnTurno(v4);
if ( !(_DWORD)result )
{
result = turno;
tablero[v3] = 1;
++fichas_comidas[v4 - 2];
++puntajes[result];
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rsi
int v4; // edi

result = (unsigned int)comer;
if ( comer )
{
v3 = 13LL * a1 + a2;
v4 = tablero[v3];
result = func0(v4);
if ( !(_DWORD)result )
{
result = turno;
tablero[v3] = 1;
++fichas_comidas[v4 - 2];
++puntajes[result];
}
}
return result;
}

original_code:
void ComerFicha(int m,int n)
{
 if (!comer){return;}
 if (FichaEnTurno(tablero[m][n])){return;}
 fichas_comidas[(tablero[m][n]-2)]++;
 tablero[m][n] = 1;
 puntajes[turno]++;
}

canonical_original_code:
void ComerFicha(int m, int n)
{
 if (!comer){return;}
 if (FichaEnTurno(tablero[m][n])){return;}
 fichas_comidas[(tablero[m][n]-2)]++;
 tablero[m][n] = 1;
 puntajes[turno]++;
}

variable_types: m int

variable_types: n int


MovidaValida

original_code:
int MovidaValida(int m0, int n0, int m1, int n1,int mirar)
{
 if ( (m1 < 0 || m1 > 16) || (n1 < 0 || n1 > 12)) {return 0;}
 if (tablero[m1][n1]!=1) {return 0;}
 int rest_m = (m1-m0);
 int rest_n = (n1-n0);
 int dist_m = abs(rest_m);
 int dist_n = abs(rest_n);
 int sent_m = (rest_m) ? (rest_m)/dist_m : 0 ;
 int sent_n = (rest_n) ? (rest_n)/dist_n : 0;
 int paridad = (m0%2==0) ? 1 : -1;
 if( (m0+(2*sent_m)==m1 && sent_m!=0 ) && (n0+(sent_n)==n1 && sent_n!=0))
 {
  if (tablero[m0+(sent_m)][n0-1+((paridad+1)/2)+((sent_n+1)/2)]>1)
  {
   if (!mirar){ComerFicha(m0+(sent_m),n0-1+((paridad+1)/2)+((sent_n+1)/2));}
   return 2;
  }
 }
 if( m0==m1 && (n0+(2*sent_n)==n1 && tablero[m0][n0+(sent_n)]>1) )
 {
  if(!mirar){ComerFicha(m0,n0+(sent_n));}
  return 2;
 }
 if( m0+(sent_m)==m1 && n0==n1 ) {return 1;}
 if( m0==m1 && n0+(sent_n)==n1 ) {return 1;}
 if( m0+(sent_m) == m1 && n0+paridad == n1 ) {return 1;}
 return 0;
}

canonical_original_code:
int MovidaValida(int m0, int n0, int m1, int n1, int mirar)
{
 if ( (m1 < 0 || m1 > 16) || (n1 < 0 || n1 > 12)) {return 0;}
 if (tablero[m1][n1]!=1) {return 0;}
 int rest_m = (m1-m0);
 int rest_n = (n1-n0);
 int dist_m = abs(rest_m);
 int dist_n = abs(rest_n);
 int sent_m = (rest_m) ? (rest_m)/dist_m : 0;
 int sent_n = (rest_n) ? (rest_n)/dist_n : 0;
 int paridad = (m0%2==0) ? 1 : -1;
 if( (m0+(2*sent_m)==m1 && sent_m!=0 ) && (n0+(sent_n)==n1 && sent_n!=0))
 {
  if (tablero[m0+(sent_m)][n0-1+((paridad+1)/2)+((sent_n+1)/2)]>1)
  {
   if (!mirar){ComerFicha(m0+(sent_m),n0-1+((paridad+1)/2)+((sent_n+1)/2));}
   return 2;
  }
 }
 if( m0==m1 && (n0+(2*sent_n)==n1 && tablero[m0][n0+(sent_n)]>1) )
 {
  if(!mirar){ComerFicha(m0,n0+(sent_n));}
  return 2;
 }
 if( m0+(sent_m)==m1 && n0==n1 ) {return 1;}
 if( m0==m1 && n0+(sent_n)==n1 ) {return 1;}
 if( m0+(sent_m) == m1 && n0+paridad == n1 ) {return 1;}
 return 0;
}

variable_types: mirar int

variable_types: paridad int


TotalFichasTurno

decompiled_code:
__int64 __fastcall TotalFichasTurno(int a1)
{
int v1; // esi
__int64 v2; // rdx
unsigned int v3; // er8
int v4; // eax

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0LL;
v2 = 0LL;
v3 = 0;
do
{
v4 = turnos[7 * modo + a1 + v2++];
v3 += 10 - fichas_comidas[v4 - 2];
}
while ( v1 > (int)v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1)
{
int v1; // esi
__int64 v2; // rdx
unsigned int v3; // er8
int v4; // eax

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0LL;
v2 = 0LL;
v3 = 0;
do
{
v4 = turnos[7 * modo + a1 + v2++];
v3 += 10 - fichas_comidas[v4 - 2];
}
while ( v1 > (int)v2 );
return v3;
}

original_code:
int TotalFichasTurno(int algunturno)
{
 int i,total;
 total = 0;
 for(i=0;i<fichasxturno[modo];i++)
 {
  total+= (10 -fichas_comidas[(turnos[modo][algunturno+i]-2)]);
 }
 return total;
}

canonical_original_code:
int TotalFichasTurno(int algunturno)
{
 int i; int total;
 total = 0;
 for(i=0;i<fichasxturno[modo];i++)
 {
  total+= (10 -fichas_comidas[(turnos[modo][algunturno+i]-2)]);
 }
 return total;
}

variable_types: algunturno int

variable_types: total int


TurnoSobreviviente

decompiled_code:
__int64 TurnoSobreviviente()
{
__int64 v0; // rbx
__int64 v1; // r11
int v2; // ebp
int v3; // er10

v0 = modo;
v1 = 7LL * modo;
if ( !turnos[7 * modo] )
return 1LL;
v2 = turno;
v3 = 0;
while ( v2 == v3 || !(unsigned int)TotalFichasTurno(v3) )
{
v3 += fichasxturno[v0];
if ( !turnos[v1 + v3] )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rbx
__int64 v1; // r11
int v2; // ebp
int v3; // er10

v0 = modo;
v1 = 7LL * modo;
if ( !turnos[7 * modo] )
return 1LL;
v2 = turno;
v3 = 0;
while ( v2 == v3 || !(unsigned int)func4(v3) )
{
v3 += fichasxturno[v0];
if ( !turnos[v1 + v3] )
return 1LL;
}
return 0LL;
}

original_code:
int TurnoSobreviviente()
{
 int i;
 for(i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
   if(i!=turno && TotalFichasTurno(i)){return 0;}
 }
 return 1;
}


FichasEnBase

decompiled_code:
__int64 __fastcall FichasEnBase(int a1)
{
__int64 v1; // rdi
int v2; // er8
unsigned int v3; // er9
char *v4; // rax
char *v5; // rdi

v1 = 80LL * (int)(DameContrario(a1) - 2);
v4 = (char *)&iniciales + v1;
v5 = (char *)&iniciales + v1 + 80;
do
{
if ( tablero[13 * *(int *)v4 + *((int *)v4 + 1)] == v2 )
++v3;
v4 += 8;
}
while ( v4 != v5 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 v1; // rdi
int v2; // er8
unsigned int v3; // er9
char *v4; // rax
char *v5; // rdi

v1 = 80LL * (int)(func1(a1) - 2);
v4 = (char *)&iniciales + v1;
v5 = (char *)&iniciales + v1 + 80;
do
{
if ( tablero[13 * *(int *)v4 + *((int *)v4 + 1)] == v2 )
++v3;
v4 += 8;
}
while ( v4 != v5 );
return v3;
}

original_code:
int FichasEnBase(int ficha)
{
 int i,j,cont;
 cont = 0;
 i = (DameContrario(ficha)-2);
 for (j=0;j<20;j+=2)
 {
  if (tablero[iniciales[i][j]][iniciales[i][j+1]] == ficha){cont++;}
 }
 return cont;
}

canonical_original_code:
int FichasEnBase(int ficha)
{
 int i; int j; int cont;
 cont = 0;
 i = (DameContrario(ficha)-2);
 for (j=0;j<20;j+=2)
 {
  if (tablero[iniciales[i][j]][iniciales[i][j+1]] == ficha){cont++;}
 }
 return cont;
}

variable_types: j int

variable_types: cont int


PuntajeTurno

decompiled_code:
__int64 __fastcall PuntajeTurno(int a1)
{
int v1; // ecx
__int64 v2; // rax
int *v3; // r10
int *v4; // rbx
int v5; // eax
int v6; // er11
int v7; // er11

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return (unsigned int)puntajes[a1];
v2 = a1 + 7LL * modo;
v3 = &turnos[v2];
v4 = &turnos[(unsigned int)(v1 - 1) + 1 + v2];
do
{
v5 = FichasEnBase(*v3);
v7 = v5 + v6;
}
while ( v3 != v4 );
return (unsigned int)(v7 + puntajes[a1]);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v1; // ecx
__int64 v2; // rax
int *v3; // r10
int *v4; // rbx
int v5; // eax
int v6; // er11
int v7; // er11

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return (unsigned int)puntajes[a1];
v2 = a1 + 7LL * modo;
v3 = &turnos[v2];
v4 = &turnos[(unsigned int)(v1 - 1) + 1 + v2];
do
{
v5 = func6(*v3);
v7 = v5 + v6;
}
while ( v3 != v4 );
return (unsigned int)(v7 + puntajes[a1]);
}

original_code:
int PuntajeTurno(int algunturno)
{
 int i,acumulado;
 acumulado = 0;
 for (i=0;i<fichasxturno[modo];i++)
 {
  acumulado+=FichasEnBase(turnos[modo][algunturno+i]);
 }
 return (puntajes[algunturno]+acumulado);
}

canonical_original_code:
int PuntajeTurno(int algunturno)
{
 int i; int acumulado;
 acumulado = 0;
 for (i=0;i<fichasxturno[modo];i++)
 {
  acumulado+=FichasEnBase(turnos[modo][algunturno+i]);
 }
 return (puntajes[algunturno]+acumulado);
}

variable_types: acumulado int


TotalFichasEnBase

decompiled_code:
__int64 __fastcall TotalFichasEnBase(int a1)
{
int v1; // ecx
__int64 v2; // rax
int *v3; // r10
int *v4; // rbx
int v5; // eax
int v6; // er11
unsigned int v7; // er11

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0LL;
v2 = a1 + 7LL * modo;
v3 = &turnos[v2];
v4 = &turnos[(unsigned int)(v1 - 1) + 1 + v2];
do
{
v5 = FichasEnBase(*v3);
v7 = v5 + v6;
}
while ( v3 != v4 );
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
int v1; // ecx
__int64 v2; // rax
int *v3; // r10
int *v4; // rbx
int v5; // eax
int v6; // er11
unsigned int v7; // er11

v1 = fichasxturno[modo];
if ( v1 <= 0 )
return 0LL;
v2 = a1 + 7LL * modo;
v3 = &turnos[v2];
v4 = &turnos[(unsigned int)(v1 - 1) + 1 + v2];
do
{
v5 = func6(*v3);
v7 = v5 + v6;
}
while ( v3 != v4 );
return v7;
}

original_code:
int TotalFichasEnBase(int algunturno)
{
 int i,fichasenbase = 0;
 for (i=0;i<fichasxturno[modo];i++)
 {
  fichasenbase+=FichasEnBase(turnos[modo][algunturno+i]);
 }
 return fichasenbase;
}

canonical_original_code:
int TotalFichasEnBase(int algunturno)
{
 int i; int fichasenbase = 0;
 for (i=0;i<fichasxturno[modo];i++)
 {
  fichasenbase+=FichasEnBase(turnos[modo][algunturno+i]);
 }
 return fichasenbase;
}

variable_types: fichasenbase int


FinJuego

decompiled_code:
__int64 FinJuego()
{
int v0; // er14
__int64 v1; // r13
__int64 v2; // r12
int v3; // ebx
int v4; // ebp
int v5; // eax

v0 = comer;
v1 = modo;
v2 = 7LL * modo;
if ( !turnos[7 * modo] )
return v0 != 0;
v3 = 0;
while ( 1 )
{
v4 = TotalFichasTurno(v3);
v5 = TotalFichasEnBase(v3);
if ( v0 )
break;
if ( v4 == v5 )
return 1LL;
LABEL_4:
v3 += fichasxturno[v1];
if ( !turnos[v2 + v3] )
return v0 != 0;
}
if ( v4 == v5 )
goto LABEL_4;
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
int v0; // er14
__int64 v1; // r13
__int64 v2; // r12
int v3; // ebx
int v4; // ebp
int v5; // eax

v0 = comer;
v1 = modo;
v2 = 7LL * modo;
if ( !turnos[7 * modo] )
return v0 != 0;
v3 = 0;
while ( 1 )
{
v4 = func4(v3);
v5 = func8(v3);
if ( v0 )
break;
if ( v4 == v5 )
return 1LL;
LABEL_4:
v3 += fichasxturno[v1];
if ( !turnos[v2 + v3] )
return v0 != 0;
}
if ( v4 == v5 )
goto LABEL_4;
return 0LL;
}

original_code:
int FinJuego()
{
 int i,fichasenbase,fichastotal;
 fichasenbase = fichastotal = 0;
 for (i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
  fichastotal = TotalFichasTurno(i);
  fichasenbase = TotalFichasEnBase(i);
  if (comer)
  {
   if (fichasenbase!=fichastotal){return 0;}
  }
  else
  {
   if (fichasenbase==fichastotal)
   {
    return 1;
   }
  }
 }
 if (!comer){return 0;}
 return 1;
}

canonical_original_code:
int FinJuego()
{
 int i; int fichasenbase; int fichastotal;
 fichasenbase = fichastotal = 0;
 for (i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
  fichastotal = TotalFichasTurno(i);
  fichasenbase = TotalFichasEnBase(i);
  if (comer)
  {
   if (fichasenbase!=fichastotal){return 0;}
  }
  else
  {
   if (fichasenbase==fichastotal)
   {
    return 1;
   }
  }
 }
 if (!comer){return 0;}
 return 1;
}

variable_types: fichastotal int


TurnoGanador

decompiled_code:
__int64 TurnoGanador()
{
__int64 v0; // rbp
int v1; // er12
int v2; // er15
int v3; // er13
__int64 v4; // r14
int *v5; // rbx
__int64 v6; // rbp
int v7; // er10
bool v8; // zf
int v9; // eax
int v11; // [rsp+0h] [rbp-38h]
_BOOL4 v13; // [rsp+4h] [rbp-34h]

if ( !turnos[7 * modo] )
return 0;
v0 = fichasxturno[modo];
v11 = 0;
v1 = 0;
v2 = 0;
v13 = 0;
v3 = fichasxturno[modo];
v4 = 4 * v0;
v5 = &turnos[7 * modo + v0];
v6 = -1 * v0;
do
{
if ( (int)PuntajeTurno(v2) >= v1 && (unsigned int)TotalFichasTurno(v2) )
{
v8 = v7 == v1;
v11 = v2;
v1 = v7;
v13 = v8;
}
v5 = (int *)((char *)v5 + v4);
v2 += v3;
}
while ( v5[v6] );
v9 = -1;
if ( !v13 )
v9 = v11;
return (unsigned int)v9;
}

original_code:
int TurnoGanador()
{
 int i,mayorpuntaje,mayorturno,empate,puntaje;
 empate = 0;
 mayorpuntaje = 0;
 for (i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
  puntaje = PuntajeTurno(i);
  if (puntaje>=mayorpuntaje && TotalFichasTurno(i)!=0)
  {
   if (puntaje==mayorpuntaje){empate = 1;}else{empate=0;}
   mayorturno = i;
   mayorpuntaje = puntaje;
  }
 }
 if(empate) {return -1;}
 return mayorturno;
}

canonical_original_code:
int TurnoGanador()
{
 int i; int mayorpuntaje; int mayorturno; int empate; int puntaje;
 empate = 0;
 mayorpuntaje = 0;
 for (i=0;turnos[modo][i]!=0;i+=fichasxturno[modo])
 {
  puntaje = PuntajeTurno(i);
  if (puntaje>=mayorpuntaje && TotalFichasTurno(i)!=0)
  {
   if (puntaje==mayorpuntaje){empate = 1;}else{empate=0;}
   mayorturno = i;
   mayorpuntaje = puntaje;
  }
 }
 if(empate) {return -1;}
 return mayorturno;
}

variable_types: mayorpuntaje int

variable_types: mayorturno int

variable_types: empate int

variable_types: puntaje int


SigueJugando

decompiled_code:
_BOOL8 __fastcall SigueJugando(unsigned int a1, int a2)
{
_BOOL8 result; // rax
int v3; // er8
int v4; // er8
int v5; // er8
int v6; // er8

if ( (unsigned int)MovidaValida(a1, a2, a1 - 2, a2 + 1, 1)
|| (unsigned int)MovidaValida(a1, a2, a1 - 2, a2 - 1, 1)
|| (unsigned int)MovidaValida(a1, a2, a1, a2 - 2, v3)
|| (unsigned int)MovidaValida(a1, a2, a1, a2 + 2, v4)
|| (unsigned int)MovidaValida(a1, a2, a1 + 2, a2 - 1, v5) )
{
result = 1LL;
}
else
{
result = (unsigned int)MovidaValida(a1, a2, a1 + 2, a2 + 1, v6) != 0;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(unsigned int a1, int a2)
{
_BOOL8 result; // rax
int v3; // er8
int v4; // er8
int v5; // er8
int v6; // er8

if ( (unsigned int)func3(a1, a2, a1 - 2, a2 + 1, 1)
|| (unsigned int)func3(a1, a2, a1 - 2, a2 - 1, 1)
|| (unsigned int)func3(a1, a2, a1, a2 - 2, v3)
|| (unsigned int)func3(a1, a2, a1, a2 + 2, v4)
|| (unsigned int)func3(a1, a2, a1 + 2, a2 - 1, v5) )
{
result = 1LL;
}
else
{
result = (unsigned int)func3(a1, a2, a1 + 2, a2 + 1, v6) != 0;
}
return result;
}

original_code:
int SigueJugando(int m,int n)
{
 if (MovidaValida(m,n,m-2,n+1,1)) return 1;
 if (MovidaValida(m,n,m-2,n-1,1)) return 1;
 if (MovidaValida(m,n,m,n-2,1)) return 1;
 if (MovidaValida(m,n,m,n+2,1)) return 1;
 if (MovidaValida(m,n,m+2,n-1,1)) return 1;
 if (MovidaValida(m,n,m+2,n+1,1)) return 1;
 return 0;
}

canonical_original_code:
int SigueJugando(int m, int n)
{
 if (MovidaValida(m,n,m-2,n+1,1)) return 1;
 if (MovidaValida(m,n,m-2,n-1,1)) return 1;
 if (MovidaValida(m,n,m,n-2,1)) return 1;
 if (MovidaValida(m,n,m,n+2,1)) return 1;
 if (MovidaValida(m,n,m+2,n-1,1)) return 1;
 if (MovidaValida(m,n,m+2,n+1,1)) return 1;
 return 0;
}