decompiled_code:
__int64 __fastcall odm_metrics_add(__int64 *a1, const char *a2, __int64 a3)
{
const char *v3; // r15
__int64 v5; // r12
size_t v6; // rax
size_t v7; // rbp
unsigned __int8 *v8; // rdi
unsigned int v9; // er8
unsigned int v10; // esi
int v11; // er9
int v12; // er10
unsigned int v13; // edx
unsigned int v14; // eax
int v15; // ecx
unsigned int v16; // edx
unsigned int v17; // eax
int v18; // ecx
unsigned int v19; // edx
unsigned int v20; // eax
unsigned int v21; // eax
int v22; // ecx
unsigned int v23; // edx
unsigned int v24; // eax
int v25; // ecx
unsigned int v26; // edx
unsigned int v27; // eax
int v28; // ecx
__int64 v29; // rsi
__int64 v30; // rbx
__int64 v31; // r13
__int64 j; // rbx
__int64 v33; // rbx
unsigned int v34; // edx
unsigned __int8 *v36; // rbx
unsigned int v37; // er12
int v38; // ebp
unsigned int v39; // eax
int v40; // ebp
unsigned int v41; // er12
unsigned int v42; // eax
int v43; // ebp
unsigned int v44; // er12
unsigned int v45; // eax
int v46; // ebp
unsigned int v47; // eax
__int64 v48; // rcx
__int64 v49; // rax
__int64 v50; // rdx
__int64 v51; // rdx
__int64 v52; // rax
_DWORD *v53; // rbp
size_t v54; // r12
char *v55; // rax
char *v56; // rbx
__int64 v57; // rdx
unsigned int v58; // er8
__int64 v59; // rax
__int64 v60; // rsi
__int64 i; // rdi
_DWORD *v62; // rdx
char *v63; // rcx
unsigned int v64; // eax
_DWORD *v65; // rax
int v66; // ecx
__int64 v67; // rax
_QWORD *v68; // rax
_QWORD *v69; // r13
_QWORD *v70; // rax
_QWORD *v71; // rbx
void *v72; // rdx
_QWORD *v73; // rax
__int64 v74; // rdx
unsigned int v75; // er14
int v76; // eax
unsigned int v77; // er12
unsigned int v78; // eax
int v79; // ebp
unsigned int v80; // er12
unsigned int v81; // eax
int v82; // ebp
unsigned int v83; // er12
unsigned int v84; // eax
int v85; // eax
__int64 v87; // [rsp+8h] [rbp-40h]

v3 = a2;
v5 = *a1;
if ( !*a1 )
{
v68 = malloc(0x48uLL);
v69 = v68;
v34 = -1;
if ( !v68 )
return v34;
*v68 = a2;
v68[1] = a3;
v68[4] = 0LL;
v68[7] = a2;
*((_DWORD *)v68 + 16) = strlen(a2);
*a1 = (__int64)v69;
v69[3] = 0LL;
v70 = malloc(0x40uLL);
v71 = v70;
v69[2] = v70;
if ( !v70 )
exit(-1);
v70[2] = 0LL;
v70[5] = 0LL;
v70[6] = 0LL;
v70[7] = 0LL;
v70[3] = v69 + 2;
*((_DWORD *)v70 + 2) = 32;
*((_DWORD *)v70 + 3) = 5;
v70[4] = 16LL;
v72 = malloc(0x200uLL);
*v71 = v72;
if ( !v72 )
exit(-1);
memset(v72, 0, 0x200uLL);
*((_DWORD *)v71 + 14) = -1609490463;
LABEL_68:
++*(_DWORD *)(*(_QWORD *)(*a1 + 16) + 16LL);
v87 = *a1;
v69[2] = *(_QWORD *)(*a1 + 16);
*((_DWORD *)v69 + 17) = -17973521;
v75 = strlen(v3);
if ( v75 <= 0xB )
{
v36 = (unsigned __int8 *)v3;
v37 = -1640531527;
v38 = -1640531527;
}
else
{
v36 = (unsigned __int8 *)v3;
v76 = -17973521;
v37 = -1640531527;
v38 = -1640531527;
do
{
v77 = (v36[5] << 8) + (v36[6] << 16) + v36[4] + (v36[7] << 24) + v37;
v78 = (v36[9] << 8) + (v36[10] << 16) + v36[8] + (v36[11] << 24) + v76;
v79 = (v78 >> 13) ^ ((v36[1] << 8) + (v36[2] << 16) + *v36 + (v36[3] << 24) - v78 - v77 + v38);
v80 = (v79 << 8) ^ (v77 - v78 - v79);
v81 = (v80 >> 13) ^ (v78 - v79 - v80);
v82 = (v81 >> 12) ^ (v79 - v80 - v81);
v83 = (v82 << 16) ^ (v80 - v81 - v82);
v84 = (v83 >> 5) ^ (v81 - v82 - v83);
v38 = (v84 >> 3) ^ (v82 - v83 - v84);
v37 = (v38 << 10) ^ (v83 - v84 - v38);
v76 = (v37 >> 15) ^ (v84 - v38 - v37);
v36 += 12;
v75 -= 12;
}
while ( v75 > 0xB );
*((_DWORD *)v69 + 17) = v76;
}
v85 = *((_DWORD *)v69 + 17) + strlen(v3);
*((_DWORD *)v69 + 17) = v85;
switch ( v75 )
{
case 1u:
goto LABEL_39;
case 2u:
goto LABEL_38;
case 3u:
goto LABEL_37;
case 4u:
goto LABEL_36;
case 5u:
goto LABEL_35;
case 6u:
goto LABEL_34;
case 7u:
goto LABEL_33;
case 8u:
goto LABEL_32;
case 9u:
goto LABEL_31;
case 0xAu:
goto LABEL_30;
case 0xBu:
*((_DWORD *)v69 + 17) = (v36[10] << 24) + v85;
LABEL_30:
*((_DWORD *)v69 + 17) += v36[9] << 16;
LABEL_31:
*((_DWORD *)v69 + 17) += v36[8] << 8;
LABEL_32:
v37 += v36[7] << 24;
LABEL_33:
v37 += v36[6] << 16;
LABEL_34:
v37 += v36[5] << 8;
LABEL_35:
v37 += v36[4];
LABEL_36:
v38 += v36[3] << 24;
LABEL_37:
v38 += v36[2] << 16;
LABEL_38:
v38 += v36[1] << 8;
LABEL_39:
v38 += *v36;
break;
default:
break;
}
v39 = *((_DWORD *)v69 + 17);
v40 = (v39 >> 13) ^ (v38 - v39 - v37);
v41 = (v40 << 8) ^ (v37 - v39 - v40);
v42 = (v41 >> 13) ^ (v39 - v40 - v41);
v43 = (v40 - v41 - v42) ^ (v42 >> 12);
v44 = (v41 - v42 - v43) ^ (v43 << 16);
v45 = (v44 >> 5) ^ (v42 - v43 - v44);
v46 = (v45 >> 3) ^ (v43 - v44 - v45);
v47 = (((v46 << 10) ^ (v44 - v45 - v46)) >> 15) ^ (v45 - v46 - ((v46 << 10) ^ (v44 - v45 - v46)));
*((_DWORD *)v69 + 17) = v47;
v48 = *(_QWORD *)(v87 + 16);
v49 = 16LL * ((*(_DWORD *)(v48 + 8) - 1) & v47);
++*(_DWORD *)(*(_QWORD *)v48 + v49 + 8);
v50 = *a1;
v69[6] = *(_QWORD *)(**(_QWORD **)(*a1 + 16) + v49);
v69[5] = 0LL;
v51 = *(_QWORD *)(**(_QWORD **)(v50 + 16) + v49);
if ( v51 )
*(_QWORD *)(v51 + 24) = v69 + 2;
*(_QWORD *)(**(_QWORD **)(*a1 + 16) + v49) = v69 + 2;
v52 = **(_QWORD **)(*a1 + 16) + v49;
if ( *(_DWORD *)(v52 + 8) < (unsigned int)(2 * (5 * *(_DWORD *)(v52 + 12) + 5)) )
return 0;
v53 = (_DWORD *)v69[2];
v34 = 0;
if ( v53[13] != 1 )
{
v54 = 16LL * (unsigned int)(2 * v53[2]);
v55 = (char *)malloc(v54);
v56 = v55;
if ( !v55 )
exit(-1);
memset(v55, 0, v54);
v53[10] = ((v53[4] & (2 * v53[2] - 1)) != 0) + (v53[4] >> (v53[3] + 1));
*(_DWORD *)(v69[2] + 44LL) = 0;
v57 = v69[2];
if ( *(_DWORD *)(v57 + 8) )
{
v58 = 0;
do
{
for ( i = *(_QWORD *)(*(_QWORD *)v57 + 16LL * v58); i; *(_QWORD *)v63 = v60 )
{
v60 = i;
i = *(_QWORD *)(i + 32);
v62 = (_DWORD *)v69[2];
v63 = &v56[16 * (*(_DWORD *)(v60 + 52) & (2 * v62[2] - 1))];
v64 = *((_DWORD *)v63 + 2) + 1;
*((_DWORD *)v63 + 2) = v64;
if ( v64 > v62[10] )
{
++v62[11];
*((_DWORD *)v63 + 3) = *((_DWORD *)v63 + 2) / *(_DWORD *)(v69[2] + 40LL);
}
*(_QWORD *)(v60 + 24) = 0LL;
v59 = *(_QWORD *)v63;
*(_QWORD *)(v60 + 32) = *(_QWORD *)v63;
if ( v59 )
*(_QWORD *)(v59 + 24) = v60;
}
++v58;
v57 = v69[2];
}
while ( *(_DWORD *)(v57 + 8) > v58 );
}
free(*(void **)v57);
*(_DWORD *)(v69[2] + 8LL) *= 2;
++*(_DWORD *)(v69[2] + 12LL);
*(_QWORD *)v69[2] = v56;
v65 = (_DWORD *)v69[2];
v66 = 0;
if ( v65[11] > v65[4] >> 1 )
v66 = v65[12] + 1;
v65[12] = v66;
v67 = v69[2];
v34 = 0;
if ( *(_DWORD *)(v67 + 48) > 1u )
*(_DWORD *)(v67 + 52) = 1;
}
return v34;
}
v6 = strlen(a2);
v7 = v6;
if ( (unsigned int)v6 <= 0xB )
{
v8 = (unsigned __int8 *)a2;
v9 = v6;
v10 = -1640531527;
v11 = -1640531527;
v12 = -17973521;
}
else
{
v8 = (unsigned __int8 *)a2;
v9 = v6;
v10 = -1640531527;
v11 = -1640531527;
v12 = -17973521;
do
{
v13 = v10 + (v8[5] << 8) + (v8[6] << 16) + v8[4] + (v8[7] << 24);
v14 = v12 + (v8[9] << 8) + (v8[10] << 16) + v8[8] + (v8[11] << 24);
v15 = (v14 >> 13) ^ (v11 + (v8[1] << 8) + (v8[2] << 16) + *v8 + (v8[3] << 24) - v13 - v14);
v16 = (v15 << 8) ^ (v13 - v14 - v15);
v17 = (v16 >> 13) ^ (v14 - v15 - v16);
v18 = (v17 >> 12) ^ (v15 - v16 - v17);
v19 = (v18 << 16) ^ (v16 - v17 - v18);
v20 = (v19 >> 5) ^ (v17 - v18 - v19);
v11 = (v18 - v19 - v20) ^ (v20 >> 3);
v10 = (v19 - v20 - v11) ^ (v11 << 10);
v12 = (v20 - v11 - v10) ^ (v10 >> 15);
v8 += 12;
v9 -= 12;
}
while ( v9 > 0xB );
}
v21 = v12 + v7;
switch ( v9 )
{
case 1u:
goto LABEL_17;
case 2u:
goto LABEL_16;
case 3u:
goto LABEL_15;
case 4u:
goto LABEL_14;
case 5u:
goto LABEL_13;
case 6u:
goto LABEL_12;
case 7u:
goto LABEL_11;
case 8u:
goto LABEL_10;
case 9u:
goto LABEL_9;
case 0xAu:
goto LABEL_8;
case 0xBu:
v21 += v8[10] << 24;
LABEL_8:
v21 += v8[9] << 16;
LABEL_9:
v21 += v8[8] << 8;
LABEL_10:
v10 += v8[7] << 24;
LABEL_11:
v10 += v8[6] << 16;
LABEL_12:
v10 += v8[5] << 8;
LABEL_13:
v10 += v8[4];
LABEL_14:
v11 += v8[3] << 24;
LABEL_15:
v11 += v8[2] << 16;
LABEL_16:
v11 += v8[1] << 8;
LABEL_17:
v11 += *v8;
break;
default:
break;
}
v22 = (v21 >> 13) ^ (v11 - (v21 + v10));
v23 = (v22 << 8) ^ (v10 - v21 - v22);
v24 = (v23 >> 13) ^ (v21 - v22 - v23);
v25 = (v24 >> 12) ^ (v22 - v23 - v24);
v26 = (v25 << 16) ^ (v23 - v24 - v25);
v27 = (v26 >> 5) ^ (v24 - v25 - v26);
v28 = (v27 >> 3) ^ (v25 - v26 - v27);
v29 = *(_QWORD *)(v5 + 16);
v30 = *(_QWORD *)(*(_QWORD *)v29
+ 16LL
* (((v27 - v28 - ((v26 - v27 - v28) ^ (v28 << 10))) ^ (((v26 - v27 - v28) ^ (v28 << 10)) >> 15)) & (*(_DWORD *)(v29 + 8) - 1)));
if ( !v30 )
{
LABEL_66:
v73 = malloc(0x48uLL);
v69 = v73;
if ( !v73 )
return (unsigned int)-1;
*v73 = v3;
v73[1] = a3;
v73[4] = 0LL;
v73[7] = v3;
*((_DWORD *)v73 + 16) = strlen(v3);
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v5 + 16) + 24LL) + 16LL) = v69;
v74 = *a1;
v69[3] = *(_QWORD *)(*(_QWORD *)(*a1 + 16) + 24LL) - *(_QWORD *)(*(_QWORD *)(*a1 + 16) + 32LL);
*(_QWORD *)(*(_QWORD *)(v74 + 16) + 24LL) = v69 + 2;
goto LABEL_68;
}
v31 = -*(_QWORD *)(v29 + 32);
for ( j = v30 - *(_QWORD *)(v29 + 32); ; j = v31 + v33 )
{
if ( v7 == *(_DWORD *)(j + 64) )
{
v34 = memcmp(*(const void **)(j + 56), v3, v7);
if ( !v34 )
break;
}
v33 = *(_QWORD *)(j + 48);
if ( !v33 )
goto LABEL_66;
}
*(_QWORD *)(j + 8) = a3;
return v34;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, const char *a2, __int64 a3)
{
const char *v3; // r15
__int64 v5; // r12
size_t v6; // rax
size_t v7; // rbp
unsigned __int8 *v8; // rdi
unsigned int v9; // er8
unsigned int v10; // esi
int v11; // er9
int v12; // er10
unsigned int v13; // edx
unsigned int v14; // eax
int v15; // ecx
unsigned int v16; // edx
unsigned int v17; // eax
int v18; // ecx
unsigned int v19; // edx
unsigned int v20; // eax
unsigned int v21; // eax
int v22; // ecx
unsigned int v23; // edx
unsigned int v24; // eax
int v25; // ecx
unsigned int v26; // edx
unsigned int v27; // eax
int v28; // ecx
__int64 v29; // rsi
__int64 v30; // rbx
__int64 v31; // r13
__int64 j; // rbx
__int64 v33; // rbx
unsigned int v34; // edx
unsigned __int8 *v36; // rbx
unsigned int v37; // er12
int v38; // ebp
unsigned int v39; // eax
int v40; // ebp
unsigned int v41; // er12
unsigned int v42; // eax
int v43; // ebp
unsigned int v44; // er12
unsigned int v45; // eax
int v46; // ebp
unsigned int v47; // eax
__int64 v48; // rcx
__int64 v49; // rax
__int64 v50; // rdx
__int64 v51; // rdx
__int64 v52; // rax
_DWORD *v53; // rbp
size_t v54; // r12
char *v55; // rax
char *v56; // rbx
__int64 v57; // rdx
unsigned int v58; // er8
__int64 v59; // rax
__int64 v60; // rsi
__int64 i; // rdi
_DWORD *v62; // rdx
char *v63; // rcx
unsigned int v64; // eax
_DWORD *v65; // rax
int v66; // ecx
__int64 v67; // rax
_QWORD *v68; // rax
_QWORD *v69; // r13
_QWORD *v70; // rax
_QWORD *v71; // rbx
void *v72; // rdx
_QWORD *v73; // rax
__int64 v74; // rdx
unsigned int v75; // er14
int v76; // eax
unsigned int v77; // er12
unsigned int v78; // eax
int v79; // ebp
unsigned int v80; // er12
unsigned int v81; // eax
int v82; // ebp
unsigned int v83; // er12
unsigned int v84; // eax
int v85; // eax
__int64 v87; // [rsp+8h] [rbp-40h]

v3 = a2;
v5 = *a1;
if ( !*a1 )
{
v68 = malloc(0x48uLL);
v69 = v68;
v34 = -1;
if ( !v68 )
return v34;
*v68 = a2;
v68[1] = a3;
v68[4] = 0LL;
v68[7] = a2;
*((_DWORD *)v68 + 16) = strlen(a2);
*a1 = (__int64)v69;
v69[3] = 0LL;
v70 = malloc(0x40uLL);
v71 = v70;
v69[2] = v70;
if ( !v70 )
exit(-1);
v70[2] = 0LL;
v70[5] = 0LL;
v70[6] = 0LL;
v70[7] = 0LL;
v70[3] = v69 + 2;
*((_DWORD *)v70 + 2) = 32;
*((_DWORD *)v70 + 3) = 5;
v70[4] = 16LL;
v72 = malloc(0x200uLL);
*v71 = v72;
if ( !v72 )
exit(-1);
memset(v72, 0, 0x200uLL);
*((_DWORD *)v71 + 14) = -1609490463;
LABEL_68:
++*(_DWORD *)(*(_QWORD *)(*a1 + 16) + 16LL);
v87 = *a1;
v69[2] = *(_QWORD *)(*a1 + 16);
*((_DWORD *)v69 + 17) = -17973521;
v75 = strlen(v3);
if ( v75 <= 0xB )
{
v36 = (unsigned __int8 *)v3;
v37 = -1640531527;
v38 = -1640531527;
}
else
{
v36 = (unsigned __int8 *)v3;
v76 = -17973521;
v37 = -1640531527;
v38 = -1640531527;
do
{
v77 = (v36[5] << 8) + (v36[6] << 16) + v36[4] + (v36[7] << 24) + v37;
v78 = (v36[9] << 8) + (v36[10] << 16) + v36[8] + (v36[11] << 24) + v76;
v79 = (v78 >> 13) ^ ((v36[1] << 8) + (v36[2] << 16) + *v36 + (v36[3] << 24) - v78 - v77 + v38);
v80 = (v79 << 8) ^ (v77 - v78 - v79);
v81 = (v80 >> 13) ^ (v78 - v79 - v80);
v82 = (v81 >> 12) ^ (v79 - v80 - v81);
v83 = (v82 << 16) ^ (v80 - v81 - v82);
v84 = (v83 >> 5) ^ (v81 - v82 - v83);
v38 = (v84 >> 3) ^ (v82 - v83 - v84);
v37 = (v38 << 10) ^ (v83 - v84 - v38);
v76 = (v37 >> 15) ^ (v84 - v38 - v37);
v36 += 12;
v75 -= 12;
}
while ( v75 > 0xB );
*((_DWORD *)v69 + 17) = v76;
}
v85 = *((_DWORD *)v69 + 17) + strlen(v3);
*((_DWORD *)v69 + 17) = v85;
switch ( v75 )
{
case 1u:
goto LABEL_39;
case 2u:
goto LABEL_38;
case 3u:
goto LABEL_37;
case 4u:
goto LABEL_36;
case 5u:
goto LABEL_35;
case 6u:
goto LABEL_34;
case 7u:
goto LABEL_33;
case 8u:
goto LABEL_32;
case 9u:
goto LABEL_31;
case 0xAu:
goto LABEL_30;
case 0xBu:
*((_DWORD *)v69 + 17) = (v36[10] << 24) + v85;
LABEL_30:
*((_DWORD *)v69 + 17) += v36[9] << 16;
LABEL_31:
*((_DWORD *)v69 + 17) += v36[8] << 8;
LABEL_32:
v37 += v36[7] << 24;
LABEL_33:
v37 += v36[6] << 16;
LABEL_34:
v37 += v36[5] << 8;
LABEL_35:
v37 += v36[4];
LABEL_36:
v38 += v36[3] << 24;
LABEL_37:
v38 += v36[2] << 16;
LABEL_38:
v38 += v36[1] << 8;
LABEL_39:
v38 += *v36;
break;
default:
break;
}
v39 = *((_DWORD *)v69 + 17);
v40 = (v39 >> 13) ^ (v38 - v39 - v37);
v41 = (v40 << 8) ^ (v37 - v39 - v40);
v42 = (v41 >> 13) ^ (v39 - v40 - v41);
v43 = (v40 - v41 - v42) ^ (v42 >> 12);
v44 = (v41 - v42 - v43) ^ (v43 << 16);
v45 = (v44 >> 5) ^ (v42 - v43 - v44);
v46 = (v45 >> 3) ^ (v43 - v44 - v45);
v47 = (((v46 << 10) ^ (v44 - v45 - v46)) >> 15) ^ (v45 - v46 - ((v46 << 10) ^ (v44 - v45 - v46)));
*((_DWORD *)v69 + 17) = v47;
v48 = *(_QWORD *)(v87 + 16);
v49 = 16LL * ((*(_DWORD *)(v48 + 8) - 1) & v47);
++*(_DWORD *)(*(_QWORD *)v48 + v49 + 8);
v50 = *a1;
v69[6] = *(_QWORD *)(**(_QWORD **)(*a1 + 16) + v49);
v69[5] = 0LL;
v51 = *(_QWORD *)(**(_QWORD **)(v50 + 16) + v49);
if ( v51 )
*(_QWORD *)(v51 + 24) = v69 + 2;
*(_QWORD *)(**(_QWORD **)(*a1 + 16) + v49) = v69 + 2;
v52 = **(_QWORD **)(*a1 + 16) + v49;
if ( *(_DWORD *)(v52 + 8) < (unsigned int)(2 * (5 * *(_DWORD *)(v52 + 12) + 5)) )
return 0;
v53 = (_DWORD *)v69[2];
v34 = 0;
if ( v53[13] != 1 )
{
v54 = 16LL * (unsigned int)(2 * v53[2]);
v55 = (char *)malloc(v54);
v56 = v55;
if ( !v55 )
exit(-1);
memset(v55, 0, v54);
v53[10] = ((v53[4] & (2 * v53[2] - 1)) != 0) + (v53[4] >> (v53[3] + 1));
*(_DWORD *)(v69[2] + 44LL) = 0;
v57 = v69[2];
if ( *(_DWORD *)(v57 + 8) )
{
v58 = 0;
do
{
for ( i = *(_QWORD *)(*(_QWORD *)v57 + 16LL * v58); i; *(_QWORD *)v63 = v60 )
{
v60 = i;
i = *(_QWORD *)(i + 32);
v62 = (_DWORD *)v69[2];
v63 = &v56[16 * (*(_DWORD *)(v60 + 52) & (2 * v62[2] - 1))];
v64 = *((_DWORD *)v63 + 2) + 1;
*((_DWORD *)v63 + 2) = v64;
if ( v64 > v62[10] )
{
++v62[11];
*((_DWORD *)v63 + 3) = *((_DWORD *)v63 + 2) / *(_DWORD *)(v69[2] + 40LL);
}
*(_QWORD *)(v60 + 24) = 0LL;
v59 = *(_QWORD *)v63;
*(_QWORD *)(v60 + 32) = *(_QWORD *)v63;
if ( v59 )
*(_QWORD *)(v59 + 24) = v60;
}
++v58;
v57 = v69[2];
}
while ( *(_DWORD *)(v57 + 8) > v58 );
}
free(*(void **)v57);
*(_DWORD *)(v69[2] + 8LL) *= 2;
++*(_DWORD *)(v69[2] + 12LL);
*(_QWORD *)v69[2] = v56;
v65 = (_DWORD *)v69[2];
v66 = 0;
if ( v65[11] > v65[4] >> 1 )
v66 = v65[12] + 1;
v65[12] = v66;
v67 = v69[2];
v34 = 0;
if ( *(_DWORD *)(v67 + 48) > 1u )
*(_DWORD *)(v67 + 52) = 1;
}
return v34;
}
v6 = strlen(a2);
v7 = v6;
if ( (unsigned int)v6 <= 0xB )
{
v8 = (unsigned __int8 *)a2;
v9 = v6;
v10 = -1640531527;
v11 = -1640531527;
v12 = -17973521;
}
else
{
v8 = (unsigned __int8 *)a2;
v9 = v6;
v10 = -1640531527;
v11 = -1640531527;
v12 = -17973521;
do
{
v13 = v10 + (v8[5] << 8) + (v8[6] << 16) + v8[4] + (v8[7] << 24);
v14 = v12 + (v8[9] << 8) + (v8[10] << 16) + v8[8] + (v8[11] << 24);
v15 = (v14 >> 13) ^ (v11 + (v8[1] << 8) + (v8[2] << 16) + *v8 + (v8[3] << 24) - v13 - v14);
v16 = (v15 << 8) ^ (v13 - v14 - v15);
v17 = (v16 >> 13) ^ (v14 - v15 - v16);
v18 = (v17 >> 12) ^ (v15 - v16 - v17);
v19 = (v18 << 16) ^ (v16 - v17 - v18);
v20 = (v19 >> 5) ^ (v17 - v18 - v19);
v11 = (v18 - v19 - v20) ^ (v20 >> 3);
v10 = (v19 - v20 - v11) ^ (v11 << 10);
v12 = (v20 - v11 - v10) ^ (v10 >> 15);
v8 += 12;
v9 -= 12;
}
while ( v9 > 0xB );
}
v21 = v12 + v7;
switch ( v9 )
{
case 1u:
goto LABEL_17;
case 2u:
goto LABEL_16;
case 3u:
goto LABEL_15;
case 4u:
goto LABEL_14;
case 5u:
goto LABEL_13;
case 6u:
goto LABEL_12;
case 7u:
goto LABEL_11;
case 8u:
goto LABEL_10;
case 9u:
goto LABEL_9;
case 0xAu:
goto LABEL_8;
case 0xBu:
v21 += v8[10] << 24;
LABEL_8:
v21 += v8[9] << 16;
LABEL_9:
v21 += v8[8] << 8;
LABEL_10:
v10 += v8[7] << 24;
LABEL_11:
v10 += v8[6] << 16;
LABEL_12:
v10 += v8[5] << 8;
LABEL_13:
v10 += v8[4];
LABEL_14:
v11 += v8[3] << 24;
LABEL_15:
v11 += v8[2] << 16;
LABEL_16:
v11 += v8[1] << 8;
LABEL_17:
v11 += *v8;
break;
default:
break;
}
v22 = (v21 >> 13) ^ (v11 - (v21 + v10));
v23 = (v22 << 8) ^ (v10 - v21 - v22);
v24 = (v23 >> 13) ^ (v21 - v22 - v23);
v25 = (v24 >> 12) ^ (v22 - v23 - v24);
v26 = (v25 << 16) ^ (v23 - v24 - v25);
v27 = (v26 >> 5) ^ (v24 - v25 - v26);
v28 = (v27 >> 3) ^ (v25 - v26 - v27);
v29 = *(_QWORD *)(v5 + 16);
v30 = *(_QWORD *)(*(_QWORD *)v29
+ 16LL
* (((v27 - v28 - ((v26 - v27 - v28) ^ (v28 << 10))) ^ (((v26 - v27 - v28) ^ (v28 << 10)) >> 15)) & (*(_DWORD *)(v29 + 8) - 1)));
if ( !v30 )
{
LABEL_66:
v73 = malloc(0x48uLL);
v69 = v73;
if ( !v73 )
return (unsigned int)-1;
*v73 = v3;
v73[1] = a3;
v73[4] = 0LL;
v73[7] = v3;
*((_DWORD *)v73 + 16) = strlen(v3);
*(_QWORD *)(*(_QWORD *)(*(_QWORD *)(v5 + 16) + 24LL) + 16LL) = v69;
v74 = *a1;
v69[3] = *(_QWORD *)(*(_QWORD *)(*a1 + 16) + 24LL) - *(_QWORD *)(*(_QWORD *)(*a1 + 16) + 32LL);
*(_QWORD *)(*(_QWORD *)(v74 + 16) + 24LL) = v69 + 2;
goto LABEL_68;
}
v31 = -*(_QWORD *)(v29 + 32);
for ( j = v30 - *(_QWORD *)(v29 + 32); ; j = v31 + v33 )
{
if ( v7 == *(_DWORD *)(j + 64) )
{
v34 = memcmp(*(const void **)(j + 56), v3, v7);
if ( !v34 )
break;
}
v33 = *(_QWORD *)(j + 48);
if ( !v33 )
goto LABEL_66;
}
*(_QWORD *)(j + 8) = a3;
return v34;
}

original_code:
int odm_metrics_add(odm_t *odm, const char *key, int *value)
{
    struct metric *metric;
    do { unsigned _hf_bkt,_hf_hashv; metric=((void *)0); if (odm->metrics) { do { unsigned _hj_i,_hj_j,_hj_k; unsigned char *_hj_key=(unsigned char*)(key); _hf_hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned)(strlen(key)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) + ( (unsigned)_hj_key[2] << 16 ) + ( (unsigned)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) + ( (unsigned)_hj_key[6] << 16 ) + ( (unsigned)_hj_key[7] << 24 ) ); _hf_hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) + ( (unsigned)_hj_key[10] << 16 ) + ( (unsigned)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } _hf_hashv += strlen(key); switch ( _hj_k ) { case 11: _hf_hashv += ( (unsigned)_hj_key[10] << 24 ); case 10: _hf_hashv += ( (unsigned)_hj_key[9] << 16 ); case 9: _hf_hashv += ( (unsigned)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hf_bkt = _hf_hashv & ((odm->metrics)->hh.tbl->num_buckets-1); } while(0); if ((1)) { do { if ((odm->metrics)->hh.tbl->buckets[ _hf_bkt ].hh_head) do { (metric) = (__typeof(metric))(((void*)(((char*)((odm->metrics)->hh.tbl->buckets[ _hf_bkt ].hh_head)) - (((odm->metrics)->hh.tbl)->hho)))); } while(0); else metric=((void *)0); while (metric) { if ((metric)->hh.keylen == strlen(key)) { if ((memcmp((metric)->hh.key,key,strlen(key))) == 0) break; } if ((metric)->hh.hh_next) do { (metric) = (__typeof(metric))(((void*)(((char*)((metric)->hh.hh_next)) - (((odm->metrics)->hh.tbl)->hho)))); } while(0); else metric = ((void *)0); } } while(0); } } } while (0);
    if (!metric)
    {
        metric = malloc(sizeof *metric);
        if (!metric)
            return -1;
        metric->key = key;
        metric->value = value;
        do { unsigned _ha_bkt; (metric)->hh.next = ((void *)0); (metric)->hh.key = (char*)(key); (metric)->hh.keylen = (unsigned)(strlen(key)); if (!(odm->metrics)) { odm->metrics = (metric); (odm->metrics)->hh.prev = ((void *)0); do { (odm->metrics)->hh.tbl = (UT_hash_table*)malloc(sizeof(UT_hash_table)); if (!((odm->metrics)->hh.tbl)) { exit(-1); } memset((odm->metrics)->hh.tbl, 0, sizeof(UT_hash_table)); (odm->metrics)->hh.tbl->tail = &((odm->metrics)->hh); (odm->metrics)->hh.tbl->num_buckets = 32; (odm->metrics)->hh.tbl->log2_num_buckets = 5; (odm->metrics)->hh.tbl->hho = (char*)(&(odm->metrics)->hh) - (char*)(odm->metrics); (odm->metrics)->hh.tbl->buckets = (UT_hash_bucket*)malloc(32*sizeof(struct UT_hash_bucket)); if (! (odm->metrics)->hh.tbl->buckets) { exit(-1); } memset((odm->metrics)->hh.tbl->buckets, 0, 32*sizeof(struct UT_hash_bucket)); ; (odm->metrics)->hh.tbl->signature = 0xa0111fe1; } while(0); } else { (odm->metrics)->hh.tbl->tail->next = (metric); (metric)->hh.prev = ((void*)(((char*)((odm->metrics)->hh.tbl->tail)) - (((odm->metrics)->hh.tbl)->hho))); (odm->metrics)->hh.tbl->tail = &((metric)->hh); } (odm->metrics)->hh.tbl->num_items++; (metric)->hh.tbl = (odm->metrics)->hh.tbl; do { unsigned _hj_i,_hj_j,_hj_k; unsigned char *_hj_key=(unsigned char*)(key); (metric)->hh.hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned)(strlen(key)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) + ( (unsigned)_hj_key[2] << 16 ) + ( (unsigned)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) + ( (unsigned)_hj_key[6] << 16 ) + ( (unsigned)_hj_key[7] << 24 ) ); (metric)->hh.hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) + ( (unsigned)_hj_key[10] << 16 ) + ( (unsigned)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 13 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 12 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 3 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } (metric)->hh.hashv += strlen(key); switch ( _hj_k ) { case 11: (metric)->hh.hashv += ( (unsigned)_hj_key[10] << 24 ); case 10: (metric)->hh.hashv += ( (unsigned)_hj_key[9] << 16 ); case 9: (metric)->hh.hashv += ( (unsigned)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 13 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 12 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 3 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 15 ); } while (0); _ha_bkt = (metric)->hh.hashv & ((odm->metrics)->hh.tbl->num_buckets-1); } while(0); do { (odm->metrics)->hh.tbl->buckets[_ha_bkt].count++; (&(metric)->hh)->hh_next = (odm->metrics)->hh.tbl->buckets[_ha_bkt].hh_head; (&(metric)->hh)->hh_prev = ((void *)0); if ((odm->metrics)->hh.tbl->buckets[_ha_bkt].hh_head) { ((odm->metrics)->hh.tbl->buckets[_ha_bkt]).hh_head->hh_prev = (&(metric)->hh); } ((odm->metrics)->hh.tbl->buckets[_ha_bkt]).hh_head=&(metric)->hh; if ((odm->metrics)->hh.tbl->buckets[_ha_bkt].count >= (((odm->metrics)->hh.tbl->buckets[_ha_bkt].expand_mult+1) * 10) && (&(metric)->hh)->tbl->noexpand != 1) { do { unsigned _he_bkt; unsigned _he_bkt_i; struct UT_hash_handle *_he_thh, *_he_hh_nxt; UT_hash_bucket *_he_new_buckets, *_he_newbkt; _he_new_buckets = (UT_hash_bucket*)malloc(2 * (&(metric)->hh)->tbl->num_buckets * sizeof(struct UT_hash_bucket)); if (!_he_new_buckets) { exit(-1); } memset(_he_new_buckets, 0, 2 * (&(metric)->hh)->tbl->num_buckets * sizeof(struct UT_hash_bucket)); (&(metric)->hh)->tbl->ideal_chain_maxlen = ((&(metric)->hh)->tbl->num_items >> ((&(metric)->hh)->tbl->log2_num_buckets+1)) + (((&(metric)->hh)->tbl->num_items & (((&(metric)->hh)->tbl->num_buckets*2)-1)) ? 1 : 0); (&(metric)->hh)->tbl->nonideal_items = 0; for(_he_bkt_i = 0; _he_bkt_i < (&(metric)->hh)->tbl->num_buckets; _he_bkt_i++) { _he_thh = (&(metric)->hh)->tbl->buckets[ _he_bkt_i ].hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; do { _he_bkt = ((_he_thh->hashv) & (((&(metric)->hh)->tbl->num_buckets*2) - 1)); } while(0); _he_newbkt = &(_he_new_buckets[ _he_bkt ]); if (++(_he_newbkt->count) > (&(metric)->hh)->tbl->ideal_chain_maxlen) { (&(metric)->hh)->tbl->nonideal_items++; _he_newbkt->expand_mult = _he_newbkt->count / (&(metric)->hh)->tbl->ideal_chain_maxlen; } _he_thh->hh_prev = ((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = _he_thh; _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } } free((&(metric)->hh)->tbl->buckets); (&(metric)->hh)->tbl->num_buckets *= 2; (&(metric)->hh)->tbl->log2_num_buckets++; (&(metric)->hh)->tbl->buckets = _he_new_buckets; (&(metric)->hh)->tbl->ineff_expands = ((&(metric)->hh)->tbl->nonideal_items > ((&(metric)->hh)->tbl->num_items >> 1)) ? ((&(metric)->hh)->tbl->ineff_expands+1) : 0; if ((&(metric)->hh)->tbl->ineff_expands > 1) { (&(metric)->hh)->tbl->noexpand=1; ; } ; } while(0); } } while(0); ; ; ; } while(0);
    }
    else
    {
        metric->value = value;
    }
    return 0;
}

canonical_original_code:
int odm_metrics_add(struct odm *odm, char *key, int *value)
{
    struct metric *metric;
    do { unsigned int _hf_bkt; unsigned int _hf_hashv; metric=((void *)0); if (odm->metrics) { do { unsigned int _hj_i; unsigned int _hj_j; unsigned int _hj_k; unsigned char *_hj_key = (unsigned char*)(key); _hf_hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned int)(strlen(key)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned int)_hj_key[1] << 8 ) + ( (unsigned int)_hj_key[2] << 16 ) + ( (unsigned int)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned int)_hj_key[5] << 8 ) + ( (unsigned int)_hj_key[6] << 16 ) + ( (unsigned int)_hj_key[7] << 24 ) ); _hf_hashv += (_hj_key[8] + ( (unsigned int)_hj_key[9] << 8 ) + ( (unsigned int)_hj_key[10] << 16 ) + ( (unsigned int)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } _hf_hashv += strlen(key); switch ( _hj_k ) { case 11: _hf_hashv += ( (unsigned int)_hj_key[10] << 24 ); case 10: _hf_hashv += ( (unsigned int)_hj_key[9] << 16 ); case 9: _hf_hashv += ( (unsigned int)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned int)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned int)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned int)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned int)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned int)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned int)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hf_bkt = _hf_hashv & ((odm->metrics)->hh.tbl->num_buckets-1); } while(0); if ((1)) { do { if ((odm->metrics)->hh.tbl->buckets[ _hf_bkt ].hh_head) do { (metric) = (__typeof(metric))(((void *)(((char *)((odm->metrics)->hh.tbl->buckets[ _hf_bkt ].hh_head)) - (((odm->metrics)->hh.tbl)->hho)))); } while(0); else metric=((void *)0); while (metric) { if ((metric)->hh.keylen == strlen(key)) { if ((memcmp((metric)->hh.key,key,strlen(key))) == 0) break; } if ((metric)->hh.hh_next) do { (metric) = (__typeof(metric))(((void *)(((char *)((metric)->hh.hh_next)) - (((odm->metrics)->hh.tbl)->hho)))); } while(0); else metric = ((void *)0); } } while(0); } } } while (0);
    if (!metric)
    {
        metric = malloc(sizeof *metric);
        if (!metric)
            return -1;
        metric->key = key;
        metric->value = value;
        do { unsigned int _ha_bkt; (metric)->hh.next = ((void *)0); (metric)->hh.key = (char *)(key); (metric)->hh.keylen = (unsigned int)(strlen(key)); if (!(odm->metrics)) { odm->metrics = (metric); (odm->metrics)->hh.prev = ((void *)0); do { (odm->metrics)->hh.tbl = (struct UT_hash_table *)malloc(sizeof(UT_hash_table)); if (!((odm->metrics)->hh.tbl)) { exit(-1); } memset((odm->metrics)->hh.tbl, 0, sizeof(UT_hash_table)); (odm->metrics)->hh.tbl->tail = &((odm->metrics)->hh); (odm->metrics)->hh.tbl->num_buckets = 32; (odm->metrics)->hh.tbl->log2_num_buckets = 5; (odm->metrics)->hh.tbl->hho = (char *)(&(odm->metrics)->hh) - (char *)(odm->metrics); (odm->metrics)->hh.tbl->buckets = (struct UT_hash_bucket *)malloc(32*sizeof(struct UT_hash_bucket)); if (! (odm->metrics)->hh.tbl->buckets) { exit(-1); } memset((odm->metrics)->hh.tbl->buckets, 0, 32*sizeof(struct UT_hash_bucket)); ; (odm->metrics)->hh.tbl->signature = 0xa0111fe1; } while(0); } else { (odm->metrics)->hh.tbl->tail->next = (metric); (metric)->hh.prev = ((void *)(((char *)((odm->metrics)->hh.tbl->tail)) - (((odm->metrics)->hh.tbl)->hho))); (odm->metrics)->hh.tbl->tail = &((metric)->hh); } (odm->metrics)->hh.tbl->num_items++; (metric)->hh.tbl = (odm->metrics)->hh.tbl; do { unsigned int _hj_i; unsigned int _hj_j; unsigned int _hj_k; unsigned char *_hj_key = (unsigned char*)(key); (metric)->hh.hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned int)(strlen(key)); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned int)_hj_key[1] << 8 ) + ( (unsigned int)_hj_key[2] << 16 ) + ( (unsigned int)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned int)_hj_key[5] << 8 ) + ( (unsigned int)_hj_key[6] << 16 ) + ( (unsigned int)_hj_key[7] << 24 ) ); (metric)->hh.hashv += (_hj_key[8] + ( (unsigned int)_hj_key[9] << 8 ) + ( (unsigned int)_hj_key[10] << 16 ) + ( (unsigned int)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 13 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 12 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 3 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } (metric)->hh.hashv += strlen(key); switch ( _hj_k ) { case 11: (metric)->hh.hashv += ( (unsigned int)_hj_key[10] << 24 ); case 10: (metric)->hh.hashv += ( (unsigned int)_hj_key[9] << 16 ); case 9: (metric)->hh.hashv += ( (unsigned int)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned int)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned int)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned int)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned int)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned int)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned int)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 13 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 12 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= (metric)->hh.hashv; _hj_i ^= ( (metric)->hh.hashv >> 3 ); _hj_j -= (metric)->hh.hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); (metric)->hh.hashv -= _hj_i; (metric)->hh.hashv -= _hj_j; (metric)->hh.hashv ^= ( _hj_j >> 15 ); } while (0); _ha_bkt = (metric)->hh.hashv & ((odm->metrics)->hh.tbl->num_buckets-1); } while(0); do { (odm->metrics)->hh.tbl->buckets[_ha_bkt].count++; (&(metric)->hh)->hh_next = (odm->metrics)->hh.tbl->buckets[_ha_bkt].hh_head; (&(metric)->hh)->hh_prev = ((void *)0); if ((odm->metrics)->hh.tbl->buckets[_ha_bkt].hh_head) { ((odm->metrics)->hh.tbl->buckets[_ha_bkt]).hh_head->hh_prev = (&(metric)->hh); } ((odm->metrics)->hh.tbl->buckets[_ha_bkt]).hh_head=&(metric)->hh; if ((odm->metrics)->hh.tbl->buckets[_ha_bkt].count >= (((odm->metrics)->hh.tbl->buckets[_ha_bkt].expand_mult+1) * 10) && (&(metric)->hh)->tbl->noexpand != 1) { do { unsigned int _he_bkt; unsigned int _he_bkt_i; struct UT_hash_handle *_he_thh; struct UT_hash_handle *_he_hh_nxt; struct UT_hash_bucket *_he_new_buckets; struct UT_hash_bucket *_he_newbkt; _he_new_buckets = (struct UT_hash_bucket *)malloc(2 * (&(metric)->hh)->tbl->num_buckets * sizeof(struct UT_hash_bucket)); if (!_he_new_buckets) { exit(-1); } memset(_he_new_buckets, 0, 2 * (&(metric)->hh)->tbl->num_buckets * sizeof(struct UT_hash_bucket)); (&(metric)->hh)->tbl->ideal_chain_maxlen = ((&(metric)->hh)->tbl->num_items >> ((&(metric)->hh)->tbl->log2_num_buckets+1)) + (((&(metric)->hh)->tbl->num_items & (((&(metric)->hh)->tbl->num_buckets*2)-1)) ? 1 : 0); (&(metric)->hh)->tbl->nonideal_items = 0; for(_he_bkt_i = 0; _he_bkt_i < (&(metric)->hh)->tbl->num_buckets; _he_bkt_i++) { _he_thh = (&(metric)->hh)->tbl->buckets[ _he_bkt_i ].hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; do { _he_bkt = ((_he_thh->hashv) & (((&(metric)->hh)->tbl->num_buckets*2) - 1)); } while(0); _he_newbkt = &(_he_new_buckets[ _he_bkt ]); if (++(_he_newbkt->count) > (&(metric)->hh)->tbl->ideal_chain_maxlen) { (&(metric)->hh)->tbl->nonideal_items++; _he_newbkt->expand_mult = _he_newbkt->count / (&(metric)->hh)->tbl->ideal_chain_maxlen; } _he_thh->hh_prev = ((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = _he_thh; _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } } free((&(metric)->hh)->tbl->buckets); (&(metric)->hh)->tbl->num_buckets *= 2; (&(metric)->hh)->tbl->log2_num_buckets++; (&(metric)->hh)->tbl->buckets = _he_new_buckets; (&(metric)->hh)->tbl->ineff_expands = ((&(metric)->hh)->tbl->nonideal_items > ((&(metric)->hh)->tbl->num_items >> 1)) ? ((&(metric)->hh)->tbl->ineff_expands+1) : 0; if ((&(metric)->hh)->tbl->ineff_expands > 1) { (&(metric)->hh)->tbl->noexpand=1; ; } ; } while(0); } } while(0); ; ; ; } while(0);
    }
    else
    {
        metric->value = value;
    }
    return 0;
}

variable_types:
key
char *

variable_types:
value
int *

variable_types: struct metric { char *key; int *value; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *

variable_types: struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } *

variable_types: struct UT_hash_bucket { struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } *hh_head; unsigned int count; unsigned int expand_mult; } *


repo: kanemathers/odmetrics

decompiled_code:
int __fastcall odm_metrics_print(__int64 *a1)
{
__int64 i; // rbx

for ( i = *a1; i; i = *(_QWORD *)(i + 32) )
printf("%s: %d\n", *(const char **)i, **(unsigned int **)(i + 8));
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(__int64 *a1)
{
__int64 i; // rbx

for ( i = *a1; i; i = *(_QWORD *)(i + 32) )
printf("%s: %d\n", *(const char **)i, **(unsigned int **)(i + 8));
return putchar(10);
}

original_code:
void odm_metrics_print(odm_t *odm)
{
    struct metric *metric;
    for (metric = odm->metrics; metric != ((void *)0); metric = metric->hh.next)
        printf("%s: %d\n", metric->key, *metric->value);
    printf("\n");
}

canonical_original_code:
void odm_metrics_print(struct odm *odm)
{
    struct metric *metric;
    for (metric = odm->metrics; metric != ((void *)0); metric = metric->hh.next)
        printf("%s: %d\n", metric->key, *metric->value);
    printf("\n");
}

variable_types: struct odm { struct metric { char *key; int *value; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *metrics; unsigned long server; } *

return_type: void

user_defined_types: struct odm { struct metric *metrics; unsigned long server; }

user_defined_types: struct metric { char *key; int *value; struct UT_hash_handle hh; }

user_defined_types: struct UT_hash_handle { struct UT_hash_table *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; }

user_defined_types: struct UT_hash_table { struct UT_hash_bucket *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; }


decompiled_code:
char *__fastcall odm_metrics_serialize(__int64 *a1)
{
__int64 v1; // rbx
int v2; // ebp
char *v3; // rax
char *v4; // r13
__int64 v5; // rbx
char *v6; // rbp

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
v2 += snprintf(0LL, 0LL, "%s\t%d\n", *(const char **)v1, **(unsigned int **)(v1 + 8));
v1 = *(_QWORD *)(v1 + 32);
}
while ( v1 );
}
else
{
v2 = 0;
}
v3 = (char *)malloc(v2 + 1);
v4 = v3;
if ( v3 )
{
v5 = *a1;
if ( *a1 )
{
v6 = v3;
do
{
v6 += sprintf(v6, "%s\t%d\n", *(const char **)v5, **(unsigned int **)(v5 + 8));
v5 = *(_QWORD *)(v5 + 32);
}
while ( v5 );
}
}
return v4;
}

original_code:
char *odm_metrics_serialize(odm_t *odm)
{
    int len = 0;
    char *p;
    struct metric *metric;
    char *output;
    for (metric = odm->metrics; metric != ((void *)0); metric = metric->hh.next)
        len += snprintf(((void *)0), 0, "%s\t%d\n", metric->key, *metric->value);
    output = malloc(len + 1);
    if (!output)
        return ((void *)0);
    p = output;
    for (metric = odm->metrics; metric != ((void *)0); metric = metric->hh.next)
        p += sprintf(p, "%s\t%d\n", metric->key, *metric->value);
    return output;
}

canonical_original_code:
char *odm_metrics_serialize(struct odm *odm)
{
    int len = 0;
    char *p;
    struct metric *metric;
    char *output;
    for (metric = odm->metrics; metric != ((void *)0); metric = metric->hh.next)
        len += snprintf(((void *)0), 0, "%s\t%d\n", metric->key, *metric->value);
    output = malloc(len + 1);
    if (!output)
        return ((void *)0);
    p = output;
    for (metric = odm->metrics; metric != ((void *)0); metric = metric->hh.next)
        p += sprintf(p, "%s\t%d\n", metric->key, *metric->value);
    return output;
}

variable_types: len int

variable_types:
p
char *

variable_types:
output
char *

return_type: char *

user_defined_types: struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; }


repo: kaneplusplus/flexmem

decompiled_code:
__int64 __fastcall xmem_set_threshold(__int64 a1)
{
if ( a1 )
{
omp_set_nest_lock(&lock);
xmem_threshold = a1;
omp_unset_nest_lock(&lock);
}
return xmem_threshold;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
if ( a1 )
{
omp_set_nest_lock(&lock);
xmem_threshold = a1;
omp_unset_nest_lock(&lock);
}
return xmem_threshold;
}

original_code:
size_t
xmem_set_threshold (size_t j)
{
  if (j > 0)
  {
    omp_set_nest_lock (&lock);
    xmem_threshold = j;
    omp_unset_nest_lock (&lock);
  }
  return xmem_threshold;
}

canonical_original_code:
unsigned long xmem_set_threshold(unsigned long j)
{
  if (j > 0)
  {
    omp_set_nest_lock (&lock);
    xmem_threshold = j;
    omp_unset_nest_lock (&lock);
  }
  return xmem_threshold;
}

variable_types:
j
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall xmem_madvise(int a1)
{
if ( a1 >= 0 )
{
omp_set_nest_lock(&lock);
xmem_advise = a1;
omp_unset_nest_lock(&lock);
}
return xmem_advise;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
if ( a1 >= 0 )
{
omp_set_nest_lock(&lock);
xmem_advise = a1;
omp_unset_nest_lock(&lock);
}
return xmem_advise;
}

original_code:
int
xmem_madvise (int j)
{
  if(j> -1)
  {
    omp_set_nest_lock (&lock);
    xmem_advise = j;
    omp_unset_nest_lock (&lock);
  }
  return xmem_advise;
}

canonical_original_code:
int xmem_madvise(int j)
{
  if(j> -1)
  {
    omp_set_nest_lock (&lock);
    xmem_advise = j;
    omp_unset_nest_lock (&lock);
  }
  return xmem_advise;
}

variable_types: j int

return_type: int


decompiled_code:
__int64 __fastcall xmem_memcpy_offset(int a1)
{
if ( a1 >= 0 )
{
omp_set_nest_lock(&lock);
xmem_offset[0] = a1;
omp_unset_nest_lock(&lock);
}
return xmem_offset[0];
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
if ( a1 >= 0 )
{
omp_set_nest_lock(&lock);
xmem_offset[0] = a1;
omp_unset_nest_lock(&lock);
}
return xmem_offset[0];
}

original_code:
int
xmem_memcpy_offset (int j)
{
  if(j> -1)
  {
    omp_set_nest_lock (&lock);
    xmem_offset = j;
    omp_unset_nest_lock (&lock);
  }
  return xmem_offset;
}

canonical_original_code:
int xmem_memcpy_offset(int j)
{
  if(j> -1)
  {
    omp_set_nest_lock (&lock);
    xmem_offset = j;
    omp_unset_nest_lock (&lock);
  }
  return xmem_offset;
}


decompiled_code:
__int64 __fastcall xmem_set_template(char *src)
{
int v2; // eax
bool v3; // zf
unsigned int v4; // ebx

v2 = strlen(src);
if ( v2 <= 5 )
return (unsigned int)-1;
v3 = memcmp(&src[v2 - 6], "XXXXXX", 6uLL) == 0;
v4 = !v3;
if ( !v3 )
return (unsigned int)-2;
omp_set_nest_lock(&lock);
memset(xmem_fname_template, 0, 0x1000uLL);
strncpy(xmem_fname_template, src, 0x1000uLL);
omp_unset_nest_lock(&lock);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src)
{
int v2; // eax
bool v3; // zf
unsigned int v4; // ebx

v2 = strlen(src);
if ( v2 <= 5 )
return (unsigned int)-1;
v3 = memcmp(&src[v2 - 6], "XXXXXX", 6uLL) == 0;
v4 = !v3;
if ( !v3 )
return (unsigned int)-2;
omp_set_nest_lock(&lock);
memset(xmem_fname_template, 0, 0x1000uLL);
strncpy(xmem_fname_template, src, 0x1000uLL);
omp_unset_nest_lock(&lock);
return v4;
}

original_code:
int
xmem_set_template (char *name)
{
  char *s;
  int n = strlen(name);
  if(n<6) return -1;
  s = name + (n-6);
  if(strncmp(s, "XXXXXX", 6)!=0) return -2;
  omp_set_nest_lock (&lock);
  memset(xmem_fname_template, 0, 4096);
  strncpy(xmem_fname_template, name, 4096);
  omp_unset_nest_lock (&lock);
  return 0;
}

canonical_original_code:
int xmem_set_template(char *name)
{
  char *s;
  int n = strlen(name);
  if(n<6) return -1;
  s = name + (n-6);
  if(strncmp(s, "XXXXXX", 6)!=0) return -2;
  omp_set_nest_lock (&lock);
  memset(xmem_fname_template, 0, 4096);
  strncpy(xmem_fname_template, name, 4096);
  omp_unset_nest_lock (&lock);
  return 0;
}

variable_types:
name
char *

variable_types:
s
char *

variable_types: n int


decompiled_code:
__int64 __fastcall xmem_set_pattern(char *src)
{
int v2; // eax
bool v3; // zf
unsigned int v4; // ebx

v2 = strlen(src);
if ( v2 <= 5 )
return (unsigned int)-1;
v3 = memcmp(&src[v2 - 6], "XXXXXX", 6uLL) == 0;
v4 = !v3;
if ( !v3 )
return (unsigned int)-2;
omp_set_nest_lock(&lock);
memset(xmem_fname_template, 0, 0x1000uLL);
memset(xmem_fname_pattern, 0, 0x1000uLL);
strncpy(xmem_fname_pattern, src, 0x1000uLL);
snprintf(xmem_fname_template, 0x1000uLL, "%s/%s", xmem_fname_path, xmem_fname_pattern);
omp_unset_nest_lock(&lock);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src)
{
int v2; // eax
bool v3; // zf
unsigned int v4; // ebx

v2 = strlen(src);
if ( v2 <= 5 )
return (unsigned int)-1;
v3 = memcmp(&src[v2 - 6], "XXXXXX", 6uLL) == 0;
v4 = !v3;
if ( !v3 )
return (unsigned int)-2;
omp_set_nest_lock(&lock);
memset(xmem_fname_template, 0, 0x1000uLL);
memset(xmem_fname_pattern, 0, 0x1000uLL);
strncpy(xmem_fname_pattern, src, 0x1000uLL);
snprintf(xmem_fname_template, 0x1000uLL, "%s/%s", xmem_fname_path, xmem_fname_pattern);
omp_unset_nest_lock(&lock);
return v4;
}

original_code:
int
xmem_set_pattern (char *name)
{
  char *s;
  int n = strlen(name);
  if(n<6) return -1;
  s = name + (n-6);
  if(strncmp(s, "XXXXXX", 6)!=0) return -2;
  omp_set_nest_lock (&lock);
  memset(xmem_fname_template, 0, 4096);
  memset(xmem_fname_pattern, 0, 4096);
  strncpy (xmem_fname_pattern, name, 4096);
  snprintf(xmem_fname_template, 4096, "%s/%s",
           xmem_fname_path, xmem_fname_pattern);
  omp_unset_nest_lock (&lock);
  return 0;
}

canonical_original_code:
int xmem_set_pattern(char *name)
{
  char *s;
  int n = strlen(name);
  if(n<6) return -1;
  s = name + (n-6);
  if(strncmp(s, "XXXXXX", 6)!=0) return -2;
  omp_set_nest_lock (&lock);
  memset(xmem_fname_template, 0, 4096);
  memset(xmem_fname_pattern, 0, 4096);
  strncpy (xmem_fname_pattern, name, 4096);
  snprintf(xmem_fname_template, 4096, "%s/%s",
           xmem_fname_path, xmem_fname_pattern);
  omp_unset_nest_lock (&lock);
  return 0;
}


decompiled_code:
__int64 __fastcall xmem_set_path(char *src)
{
if ( (int)strlen(src) <= 5 )
return 0xFFFFFFFFLL;
omp_set_nest_lock(&lock);
memset(xmem_fname_template, 0, 0x1000uLL);
memset(xmem_fname_path, 0, 0x1000uLL);
strncpy(xmem_fname_path, src, 0x1000uLL);
snprintf(xmem_fname_template, 0x1000uLL, "%s/%s", xmem_fname_path, xmem_fname_pattern);
omp_unset_nest_lock(&lock);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src)
{
if ( (int)strlen(src) <= 5 )
return 0xFFFFFFFFLL;
omp_set_nest_lock(&lock);
memset(xmem_fname_template, 0, 0x1000uLL);
memset(xmem_fname_path, 0, 0x1000uLL);
strncpy(xmem_fname_path, src, 0x1000uLL);
snprintf(xmem_fname_template, 0x1000uLL, "%s/%s", xmem_fname_path, xmem_fname_pattern);
omp_unset_nest_lock(&lock);
return 0LL;
}

original_code:
int
xmem_set_path (char *p)
{
  int n = strlen(p);
  if(n<6) return -1;
  omp_set_nest_lock (&lock);
  memset(xmem_fname_template, 0, 4096);
  memset(xmem_fname_path, 0, 4096);
  strncpy (xmem_fname_path, p, 4096);
  snprintf(xmem_fname_template, 4096, "%s/%s",
           xmem_fname_path, xmem_fname_pattern);
  omp_unset_nest_lock (&lock);
  return 0;
}

canonical_original_code:
int xmem_set_path(char *p)
{
  int n = strlen(p);
  if(n<6) return -1;
  omp_set_nest_lock (&lock);
  memset(xmem_fname_template, 0, 4096);
  memset(xmem_fname_path, 0, 4096);
  strncpy (xmem_fname_path, p, 4096);
  snprintf(xmem_fname_template, 4096, "%s/%s",
           xmem_fname_path, xmem_fname_pattern);
  omp_unset_nest_lock (&lock);
  return 0;
}


decompiled_code:
char *xmem_get_template()
{
char *v0; // rbx

omp_set_nest_lock(&lock);
v0 = strndup(xmem_fname_template, 0x1000uLL);
omp_unset_nest_lock(&lock);
return v0;
}

canonical_decompiled_code:
char *func6()
{
char *v0; // rbx

omp_set_nest_lock(&lock);
v0 = strndup(xmem_fname_template, 0x1000uLL);
omp_unset_nest_lock(&lock);
return v0;
}

original_code:
char *
xmem_get_template()
{
  char *s;
  omp_set_nest_lock (&lock);
  s = strndup(xmem_fname_template,4096);
  omp_unset_nest_lock (&lock);
  return s;
}

canonical_original_code:
char *xmem_get_template()
{
  char *s;
  omp_set_nest_lock (&lock);
  s = strndup(xmem_fname_template,4096);
  omp_unset_nest_lock (&lock);
  return s;
}


original_code:
char *
xmem_lookup(void *addr)
{
  char *f = ((void *)0);
  struct map *x;
  omp_set_nest_lock (&lock);
  do { unsigned _hf_bkt,_hf_hashv; x=((void *)0); if (flexmap) { do { unsigned _hj_i,_hj_j,_hj_k; char *_hj_key=(char*)(&addr); _hf_hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned)sizeof(void *); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) + ( (unsigned)_hj_key[2] << 16 ) + ( (unsigned)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) + ( (unsigned)_hj_key[6] << 16 ) + ( (unsigned)_hj_key[7] << 24 ) ); _hf_hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) + ( (unsigned)_hj_key[10] << 16 ) + ( (unsigned)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } _hf_hashv += sizeof(void *); switch ( _hj_k ) { case 11: _hf_hashv += ( (unsigned)_hj_key[10] << 24 ); case 10: _hf_hashv += ( (unsigned)_hj_key[9] << 16 ); case 9: _hf_hashv += ( (unsigned)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hf_bkt = _hf_hashv & ((flexmap)->hh.tbl->num_buckets-1); } while(0); if ((1)) { do { if ((flexmap)->hh.tbl->buckets[ _hf_bkt ].hh_head) do { (x) = (__typeof(x))(((void*)(((char*)((flexmap)->hh.tbl->buckets[ _hf_bkt ].hh_head)) - (((flexmap)->hh.tbl)->hho)))); } while(0); else x=((void *)0); while (x) { if ((x)->hh.keylen == sizeof(void *)) { if ((memcmp((x)->hh.key,&addr,sizeof(void *))) == 0) break; } if ((x)->hh.hh_next) do { (x) = (__typeof(x))(((void*)(((char*)((x)->hh.hh_next)) - (((flexmap)->hh.tbl)->hho)))); } while(0); else x = ((void *)0); } } while(0); } } } while (0);
  if(x) f = strndup(x->path,4096);
  omp_unset_nest_lock (&lock);
  return f;
}

canonical_original_code:
char *xmem_lookup(void *addr)
{
  char *f = ((void *)0);
  struct map *x;
  omp_set_nest_lock (&lock);
  do { unsigned int _hf_bkt; unsigned int _hf_hashv; x=((void *)0); if (flexmap) { do { unsigned int _hj_i; unsigned int _hj_j; unsigned int _hj_k; char *_hj_key = (char*)(&addr); _hf_hashv = 0xfeedbeef; _hj_i = _hj_j = 0x9e3779b9; _hj_k = (unsigned int)sizeof(void *); while (_hj_k >= 12) { _hj_i += (_hj_key[0] + ( (unsigned int)_hj_key[1] << 8 ) + ( (unsigned int)_hj_key[2] << 16 ) + ( (unsigned int)_hj_key[3] << 24 ) ); _hj_j += (_hj_key[4] + ( (unsigned int)_hj_key[5] << 8 ) + ( (unsigned int)_hj_key[6] << 16 ) + ( (unsigned int)_hj_key[7] << 24 ) ); _hf_hashv += (_hj_key[8] + ( (unsigned int)_hj_key[9] << 8 ) + ( (unsigned int)_hj_key[10] << 16 ) + ( (unsigned int)_hj_key[11] << 24 ) ); do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hj_key += 12; _hj_k -= 12; } _hf_hashv += sizeof(void *); switch ( _hj_k ) { case 11: _hf_hashv += ( (unsigned int)_hj_key[10] << 24 ); case 10: _hf_hashv += ( (unsigned int)_hj_key[9] << 16 ); case 9: _hf_hashv += ( (unsigned int)_hj_key[8] << 8 ); case 8: _hj_j += ( (unsigned int)_hj_key[7] << 24 ); case 7: _hj_j += ( (unsigned int)_hj_key[6] << 16 ); case 6: _hj_j += ( (unsigned int)_hj_key[5] << 8 ); case 5: _hj_j += _hj_key[4]; case 4: _hj_i += ( (unsigned int)_hj_key[3] << 24 ); case 3: _hj_i += ( (unsigned int)_hj_key[2] << 16 ); case 2: _hj_i += ( (unsigned int)_hj_key[1] << 8 ); case 1: _hj_i += _hj_key[0]; } do { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 13 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 8 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 13 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 12 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 16 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 5 ); _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= ( _hf_hashv >> 3 ); _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= ( _hj_i << 10 ); _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= ( _hj_j >> 15 ); } while (0); _hf_bkt = _hf_hashv & ((flexmap)->hh.tbl->num_buckets-1); } while(0); if ((1)) { do { if ((flexmap)->hh.tbl->buckets[ _hf_bkt ].hh_head) do { (x) = (__typeof(x))(((void *)(((char *)((flexmap)->hh.tbl->buckets[ _hf_bkt ].hh_head)) - (((flexmap)->hh.tbl)->hho)))); } while(0); else x=((void *)0); while (x) { if ((x)->hh.keylen == sizeof(void *)) { if ((memcmp((x)->hh.key,&addr,sizeof(void *))) == 0) break; } if ((x)->hh.hh_next) do { (x) = (__typeof(x))(((void *)(((char *)((x)->hh.hh_next)) - (((flexmap)->hh.tbl)->hho)))); } while(0); else x = ((void *)0); } } while(0); } } } while (0);
  if(x) f = strndup(x->path,4096);
  omp_unset_nest_lock (&lock);
  return f;
}

variable_types:
addr
void *

variable_types:
f
char *

variable_types: struct map { void *addr; char *path; unsigned long length; int pid; struct UT_hash_handle { struct UT_hash_table { struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned int count; unsigned int expand_mult; } *buckets; unsigned int num_buckets; unsigned int num_items; struct UT_hash_handle *tail; long hho; unsigned int ideal_chain_maxlen; unsigned int nonideal_items; unsigned int ineff_expands; unsigned int signature; } *tbl; void *prev; void *next; struct UT_hash_handle *hh_prev; struct UT_hash_handle *hh_next; void *key; unsigned int keylen; unsigned int hashv; } hh; } *

user_defined_types: struct map { void *addr; char *path; unsigned long length; int pid; struct UT_hash_handle hh; }


strnicmp

decompiled_code:
__int64 __fastcall strnicmp(unsigned __int8 *a1, _BYTE *a2, __int64 a3)
{
_BYTE *v4; // r12
_BYTE *v5; // r14
unsigned __int8 v6; // bl
__int32_t v7; // ebp
const __int32_t **v8; // rax

if ( a3 )
{
v4 = a2;
v5 = &a2[a3];
while ( 1 )
{
v6 = *a1;
LOBYTE(v7) = *v4;
++a1;
++v4;
if ( !(_BYTE)v7 )
break;
if ( !v6 )
break;
if ( v6 != (_BYTE)v7 )
{
v8 = _ctype_tolower_loc();
v6 = (*v8)[v6];
v7 = (*v8)[(unsigned __int8)v7];
if ( v6 != (_BYTE)v7 )
break;
}
if ( v4 == v5 )
{
v6 = v7;
return v6 - (unsigned int)(unsigned __int8)v7;
}
}
}
else
{
LOBYTE(v7) = 0;
v6 = 0;
}
return v6 - (unsigned int)(unsigned __int8)v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, _BYTE *a2, __int64 a3)
{
_BYTE *v4; // r12
_BYTE *v5; // r14
unsigned __int8 v6; // bl
__int32_t v7; // ebp
const __int32_t **v8; // rax

if ( a3 )
{
v4 = a2;
v5 = &a2[a3];
while ( 1 )
{
v6 = *a1;
LOBYTE(v7) = *v4;
++a1;
++v4;
if ( !(_BYTE)v7 )
break;
if ( !v6 )
break;
if ( v6 != (_BYTE)v7 )
{
v8 = _ctype_tolower_loc();
v6 = (*v8)[v6];
v7 = (*v8)[(unsigned __int8)v7];
if ( v6 != (_BYTE)v7 )
break;
}
if ( v4 == v5 )
{
v6 = v7;
return v6 - (unsigned int)(unsigned __int8)v7;
}
}
}
else
{
LOBYTE(v7) = 0;
v6 = 0;
}
return v6 - (unsigned int)(unsigned __int8)v7;
}

original_code:
int strnicmp(const char *s1, const char *s2, size_t len)
{
 unsigned char c1, c2;
 c1 = 0; c2 = 0;
 if (len) {
  do {
   c1 = *s1; c2 = *s2;
   s1++; s2++;
   if (!c1)
    break;
   if (!c2)
    break;
   if (c1 == c2)
    continue;
   c1 = tolower(c1);
   c2 = tolower(c2);
   if (c1 != c2)
    break;
  } while (--len);
 }
 return (int)c1 - (int)c2;
}

canonical_original_code:
int strnicmp(char *s1, char *s2, unsigned long len)
{
 unsigned char c1; unsigned char c2;
 c1 = 0; c2 = 0;
 if (len) {
  do {
   c1 = *s1; c2 = *s2;
   s1++; s2++;
   if (!c1)
    break;
   if (!c2)
    break;
   if (c1 == c2)
    continue;
   c1 = tolower(c1);
   c2 = tolower(c2);
   if (c1 != c2)
    break;
  } while (--len);
 }
 return (int)c1 - (int)c2;
}

variable_types:
len
unsigned long


strcmp

decompiled_code:
__int64 __fastcall strcmp(__int64 a1, __int64 a2)
{
__int64 i; // rax
char v3; // dl
char v4; // cl

for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(a1 + i);
v4 = v3 - *(_BYTE *)(a2 + i);
if ( v4 )
break;
if ( !v3 )
return 0;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 i; // rax
char v3; // dl
char v4; // cl

for ( i = 0LL; ; ++i )
{
v3 = *(_BYTE *)(a1 + i);
v4 = v3 - *(_BYTE *)(a2 + i);
if ( v4 )
break;
if ( !v3 )
return 0;
}
return (unsigned int)v4;
}

original_code:
int strcmp(const char * cs,const char * ct)
{
 register signed char __res;
 while (1) {
  if ((__res = *cs - *ct++) != 0 || !*cs++)
   break;
 }
 return __res;
}

canonical_original_code:
int strcmp(char *cs, char *ct)
{
 register char __res;
 while (1) {
  if ((__res = *cs - *ct++) != 0 || !*cs++)
   break;
 }
 return __res;
}

variable_types:
cs
char *

variable_types:
ct
char *


strncmp

decompiled_code:
__int64 __fastcall strncmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
char v4; // cl

if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
v4 = *(_BYTE *)(a1 + i) - *(_BYTE *)(a2 + i);
if ( v4 )
break;
if ( !*(_BYTE *)(a1 + i) )
return 0;
}
}
else
{
v4 = 0;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
char v4; // cl

if ( a3 )
{
for ( i = 0LL; i != a3; ++i )
{
v4 = *(_BYTE *)(a1 + i) - *(_BYTE *)(a2 + i);
if ( v4 )
break;
if ( !*(_BYTE *)(a1 + i) )
return 0;
}
}
else
{
v4 = 0;
}
return (unsigned int)v4;
}

original_code:
int strncmp(const char * cs,const char * ct,size_t count)
{
 register signed char __res = 0;
 while (count) {
  if ((__res = *cs - *ct++) != 0 || !*cs++)
   break;
  count--;
 }
 return __res;
}

canonical_original_code:
int strncmp(char *cs, char *ct, unsigned long count)
{
 register char __res = 0;
 while (count) {
  if ((__res = *cs - *ct++) != 0 || !*cs++)
   break;
  count--;
 }
 return __res;
}

variable_types:
count
unsigned long


strspn

decompiled_code:
__int64 __fastcall strspn(char *a1, _BYTE *a2)
{
char v3; // cl
char v4; // r9
__int64 v5; // rsi
char v6; // dl
_BYTE *v7; // rax

v3 = *a1;
if ( !*a1 )
return 0LL;
v4 = *a2;
v5 = 0LL;
do
{
if ( v4 == v3 || !v4 )
{
v6 = v4;
}
else
{
v7 = a2;
do
v6 = *++v7;
while ( *v7 != v3 && v6 );
}
if ( !v6 )
break;
v3 = a1[++v5];
}
while ( v3 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, _BYTE *a2)
{
char v3; // cl
char v4; // r9
__int64 v5; // rsi
char v6; // dl
_BYTE *v7; // rax

v3 = *a1;
if ( !*a1 )
return 0LL;
v4 = *a2;
v5 = 0LL;
do
{
if ( v4 == v3 || !v4 )
{
v6 = v4;
}
else
{
v7 = a2;
do
v6 = *++v7;
while ( *v7 != v3 && v6 );
}
if ( !v6 )
break;
v3 = a1[++v5];
}
while ( v3 );
return v5;
}

original_code:
size_t strspn(const char *s, const char *accept)
{
 const char *p;
 const char *a;
 size_t count = 0;
 for (p = s; *p != '\0'; ++p) {
  for (a = accept; *a != '\0'; ++a) {
   if (*p == *a)
    break;
  }
  if (*a == '\0')
   return count;
  ++count;
 }
 return count;
}

canonical_original_code:
unsigned long strspn(char *s, char *accept)
{
 char *p;
 char *a;
 unsigned long count = 0;
 for (p = s; *p != '\0'; ++p) {
  for (a = accept; *a != '\0'; ++a) {
   if (*p == *a)
    break;
  }
  if (*a == '\0')
   return count;
  ++count;
 }
 return count;
}

variable_types:
accept
char *

variable_types:
a
char *


bcopy

original_code:
void bcopy(const void *src, void *dest, size_t count)
{
 char *destTmp = (char *)dest;
 char *srcTmp = (char *)src;
 while (count--)
  *destTmp++ = *srcTmp++;
}

canonical_original_code:
void bcopy(void *src, void *dest, unsigned long count)
{
 char *destTmp = (char *)dest;
 char *srcTmp = (char *)src;
 while (count--)
  *destTmp++ = *srcTmp++;
}

variable_types:
src
void *

variable_types:
dest
void *

variable_types:
destTmp
char *

variable_types:
srcTmp
char *


memcmp

decompiled_code:
__int64 __fastcall memcmp(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
unsigned int v6; // edx

if ( !a3 )
return 0;
for ( i = 0LL; i != a3; ++i )
{
v6 = *(unsigned __int8 *)(a1 + i) - *(unsigned __int8 *)(a2 + i);
if ( v6 )
break;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, __int64 a2, __int64 a3)
{
__int64 i; // rax
unsigned int v6; // edx

if ( !a3 )
return 0;
for ( i = 0LL; i != a3; ++i )
{
v6 = *(unsigned __int8 *)(a1 + i) - *(unsigned __int8 *)(a2 + i);
if ( v6 )
break;
}
return v6;
}

original_code:
int memcmp(const void * cs,const void * ct,size_t count)
{
 const unsigned char *su1, *su2;
 int res = 0;
 for( su1 = (const unsigned char *)cs, su2 = (const unsigned char *)ct; 0 < count; ++su1, ++su2, count--)
  if ((res = *su1 - *su2) != 0)
   break;
 return res;
}

canonical_original_code:
int memcmp(void *cs, void *ct, unsigned long count)
{
 unsigned char *su1; unsigned char *su2;
 int res = 0;
 for( su1 = (unsigned char *)cs, su2 = (unsigned char *)ct; 0 < count; ++su1, ++su2, count--)
  if ((res = *su1 - *su2) != 0)
   break;
 return res;
}

variable_types:
cs
void *

variable_types:
ct
void *

variable_types: res int


memscan

decompiled_code:
unsigned __int8 *__fastcall memscan(unsigned __int8 *a1, int a2, __int64 a3)
{
unsigned __int8 *result; // rax

result = a1;
if ( a3 )
{
while ( *result != a2 )
{
if ( ++result == &a1[a3] )
return &a1[a3];
}
}
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func16(unsigned __int8 *a1, int a2, __int64 a3)
{
unsigned __int8 *result; // rax

result = a1;
if ( a3 )
{
while ( *result != a2 )
{
if ( ++result == &a1[a3] )
return &a1[a3];
}
}
return result;
}

original_code:
void * memscan(void * addr, int c, size_t size)
{
 unsigned char * p = (unsigned char *) addr;
 while (size) {
  if (*p == c)
   return (void *) p;
  p++;
  size--;
 }
   return (void *) p;
}

canonical_original_code:
void *memscan(void *addr, int c, unsigned long size)
{
 unsigned char *p = (unsigned char *) addr;
 while (size) {
  if (*p == c)
   return (void *) p;
  p++;
  size--;
 }
   return (void *) p;
}

variable_types: c int

variable_types:
size
unsigned long

variable_types:
p
unsigned char *

return_type: void *


strstr

decompiled_code:
__int64 __fastcall strstr(_BYTE *a1, _BYTE *a2)
{
int v2; // eax
__int64 v3; // rbx
int v4; // er14
int v5; // er13
int v6; // eax
int v7; // er15

v2 = strlen(a2);
v3 = (__int64)a1;
if ( v2 )
{
v4 = v2;
v5 = v2;
v6 = strlen(a1);
if ( v4 > v6 )
{
v3 = 0LL;
}
else
{
v7 = v6 + (_DWORD)a1;
while ( (unsigned int)memcmp(v3, (__int64)a2, v4) )
{
if ( v7 - (int)++v3 < v5 )
return 0LL;
}
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func17(_BYTE *a1, _BYTE *a2)
{
int v2; // eax
__int64 v3; // rbx
int v4; // er14
int v5; // er13
int v6; // eax
int v7; // er15

v2 = func7(a2);
v3 = (__int64)a1;
if ( v2 )
{
v4 = v2;
v5 = v2;
v6 = func7(a1);
if ( v4 > v6 )
{
v3 = 0LL;
}
else
{
v7 = v6 + (_DWORD)a1;
while ( (unsigned int)func15(v3, (__int64)a2, v4) )
{
if ( v7 - (int)++v3 < v5 )
return 0LL;
}
}
}
return v3;
}

original_code:
char * strstr(const char * s1,const char * s2)
{
 int l1, l2;
 l2 = strlen(s2);
 if (!l2)
  return (char *) s1;
 l1 = strlen(s1);
 while (l1 >= l2) {
  l1--;
  if (!memcmp(s1,s2,l2))
   return (char *) s1;
  s1++;
 }
 return ((void *)0);
}

canonical_original_code:
char *strstr(char *s1, char *s2)
{
 int l1; int l2;
 l2 = strlen(s2);
 if (!l2)
  return (char *) s1;
 l1 = strlen(s1);
 while (l1 >= l2) {
  l1--;
  if (!memcmp(s1,s2,l2))
   return (char *) s1;
  s1++;
 }
 return ((void *)0);
}


repo: kaniini/slabbed-or-not

decompiled_code:
char vmware_hypervisor_port_check()
{
unsigned __int32 v0; // eax

v0 = __indword(0x5658u);
return 0;
}

canonical_decompiled_code:
char func8()
{
unsigned __int32 v0; // eax

v0 = __indword(0x5658u);
return 0;
}

original_code:
static _Bool vmware_hypervisor_port_check(void)
{
 uint32_t eax, ebx, ecx, edx;
 ebx = (0x7fffffff * 2U + 1U);
 __asm__("inl %%dx, %%eax" : "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : "0"(0x564D5868), "1"(10), "2"(0x5658), "3"(ebx) : "memory");;
 if (ebx == 0x564D5868)
  return 1;
 return 0;
}

canonical_original_code:
static _Bool vmware_hypervisor_port_check()
{
 unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx;
 ebx = (0x7fffffff * 2U + 1U);
 __asm__("inl %%dx, %%eax" : "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : "0"(0x564D5868), "1"(10), "2"(0x5658), "3"(ebx) : "memory");;
 if (ebx == 0x564D5868)
  return 1;
 return 0;
}

variable_types:
eax
unsigned int

variable_types:
ebx
unsigned int

variable_types:
ecx
unsigned int

variable_types:
edx
unsigned int


decompiled_code:
__int64 __fastcall vmware_read_device_chunk(int a1, unsigned __int16 a2, int *a3)
{
unsigned __int32 v4; // eax
unsigned int v5; // edx

v4 = __indword(0x5658u);
v5 = 0;
if ( v4 )
{
*a3 = a2 | (a1 << 16);
v5 = 1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, unsigned __int16 a2, int *a3)
{
unsigned __int32 v4; // eax
unsigned int v5; // edx

v4 = __indword(0x5658u);
v5 = 0;
if ( v4 )
{
*a3 = a2 | (a1 << 16);
v5 = 1;
}
return v5;
}

original_code:
static _Bool vmware_read_device_chunk(uint16_t id, uint16_t offset, uint32_t *data)
{
 uint32_t eax, ebx, ecx, edx;
 ebx = (id << 16) | offset;
 __asm__("inl %%dx, %%eax" : "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : "0"(0x564D5868), "1"(11), "2"(0x5658), "3"(ebx) : "memory");;
 if (eax == 0)
  return 0;
 *data = ebx;
 return 1;
}

canonical_original_code:
static _Bool vmware_read_device_chunk(unsigned short id, unsigned short offset, unsigned int *data)
{
 unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx;
 ebx = (id << 16) | offset;
 __asm__("inl %%dx, %%eax" : "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : "0"(0x564D5868), "1"(11), "2"(0x5658), "3"(ebx) : "memory");;
 if (eax == 0)
  return 0;
 *data = ebx;
 return 1;
}

variable_types:
id
unsigned short

variable_types:
offset
unsigned short

variable_types:
data
unsigned int *


decompiled_code:
__int64 __fastcall vmware_read_device(unsigned __int16 a1, __int64 a2)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 0LL; i != 40; i += 4LL )
{
result = vmware_read_device_chunk(a1, i, (int *)(a2 + i));
if ( !(_BYTE)result )
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned __int16 a1, __int64 a2)
{
__int64 i; // rbx
__int64 result; // rax

for ( i = 0LL; i != 40; i += 4LL )
{
result = func9(a1, i, (int *)(a2 + i));
if ( !(_BYTE)result )
break;
}
return result;
}

original_code:
static _Bool vmware_read_device(uint16_t id, struct vmware_device *dev)
{
 uint16_t step;
 uint32_t *p;
 for (step = 0, p = (uint32_t *) dev; step < sizeof(struct vmware_device); step += sizeof(uint32_t), p++)
  if (!vmware_read_device_chunk(id, step, p))
   return 0;
 return 1;
}

canonical_original_code:
static _Bool vmware_read_device(unsigned short id, struct vmware_device *dev)
{
 unsigned short step;
 unsigned int *p;
 for (step = 0, p = (unsigned int *) dev; step < sizeof(struct vmware_device); step += sizeof(unsigned int), p++)
  if (!vmware_read_device_chunk(id, step, p))
   return 0;
 return 1;
}

variable_types: struct vmware_device { char devname[32]; unsigned int devid; _Bool enabled; char pad[3]; } *

variable_types:
step
unsigned short

variable_types:
p
unsigned int *


decompiled_code:
__int64 __fastcall do_tests(__int64 a1, __int64 a2)
{
__int64 v3; // rbp

if ( !a2 )
return 0LL;
v3 = 0LL;
while ( !(*(unsigned __int8 (**)(void))(*(_QWORD *)a1 + 8LL))() )
{
++v3;
a1 += 8LL;
if ( a2 == v3 )
return 0LL;
}
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v3; // rbp

if ( !a2 )
return 0LL;
v3 = 0LL;
while ( !(*(unsigned __int8 (**)(void))(*(_QWORD *)a1 + 8LL))() )
{
++v3;
a1 += 8LL;
if ( a2 == v3 )
return 0LL;
}
return *(_QWORD *)a1;
}

original_code:
static struct test_impl *do_tests(struct test_impl **impls, size_t impl_count)
{
 size_t i;
 for (i = 0; i < impl_count; i++)
 {
  if (impls[i]->check())
   return impls[i];
 }
 return ((void *)0);
}

canonical_original_code:
static struct test_impl *do_tests(struct test_impl **impls, unsigned long impl_count)
{
 unsigned long i;
 for (i = 0; i < impl_count; i++)
 {
  if (impls[i]->check())
   return impls[i];
 }
 return ((void *)0);
}

variable_types:
impls
struct test_impl **

variable_types:
i
unsigned long

return_type: struct test_impl { char *hv_name; _Bool (*check)(); void (*explain)(); } *


decompiled_code:
__int64 __fastcall cpuid_scan(char *s1)
{
unsigned int v1; // ebx
char s2[4]; // [rsp+3h] [rbp-35h] BYREF
int v4; // [rsp+7h] [rbp-31h]
int v5; // [rsp+Bh] [rbp-2Dh]
char v6; // [rsp+Fh] [rbp-29h]
int v7; // [rsp+10h] [rbp-28h] BYREF
int v8; // [rsp+14h] [rbp-24h] BYREF
int v9; // [rsp+18h] [rbp-20h] BYREF
int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

cpuid_base = 0x40000000;
v1 = 0x40000000;
while ( 1 )
{
xen_cpuid(v1, v10, &v9, &v8, &v7);
*(_DWORD *)s2 = v9;
v4 = v8;
v5 = v7;
v6 = 0;
if ( !strcmp(s1, s2) )
break;
v1 += 256;
cpuid_base = v1;
if ( v1 == 1073807360 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *s1)
{
unsigned int v1; // ebx
char s2[4]; // [rsp+3h] [rbp-35h] BYREF
int v4; // [rsp+7h] [rbp-31h]
int v5; // [rsp+Bh] [rbp-2Dh]
char v6; // [rsp+Fh] [rbp-29h]
int v7; // [rsp+10h] [rbp-28h] BYREF
int v8; // [rsp+14h] [rbp-24h] BYREF
int v9; // [rsp+18h] [rbp-20h] BYREF
int v10[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

cpuid_base = 0x40000000;
v1 = 0x40000000;
while ( 1 )
{
func7(v1, v10, &v9, &v8, &v7);
*(_DWORD *)s2 = v9;
v4 = v8;
v5 = v7;
v6 = 0;
if ( !strcmp(s1, s2) )
break;
v1 += 256;
cpuid_base = v1;
if ( v1 == 1073807360 )
return 0LL;
}
return 1LL;
}

original_code:
static _Bool cpuid_scan(char *sigbase)
{
 uint32_t eax, ebx, ecx, edx;
 char signature[13];
 for (cpuid_base = 0x40000000; cpuid_base < 0x40010000; cpuid_base += 0x100)
 {
  xen_cpuid(cpuid_base, &eax, &ebx, &ecx, &edx);
  *(uint32_t *)(signature + 0) = ebx;
  *(uint32_t *)(signature + 4) = ecx;
  *(uint32_t *)(signature + 8) = edx;
  signature[12] = '\0';
  if (!strcmp(sigbase, signature))
   return 1;
 }
 return 0;
}

canonical_original_code:
static _Bool cpuid_scan(char *sigbase)
{
 unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx;
 char signature[13];
 for (cpuid_base = 0x40000000; cpuid_base < 0x40010000; cpuid_base += 0x100)
 {
  xen_cpuid(cpuid_base, &eax, &ebx, &ecx, &edx);
  *(unsigned int *)(signature + 0) = ebx;
  *(unsigned int *)(signature + 4) = ecx;
  *(unsigned int *)(signature + 8) = edx;
  signature[12] = '\0';
  if (!strcmp(sigbase, signature))
   return 1;
 }
 return 0;
}

variable_types:
sigbase
char *

variable_types:
signature
char [13]


decompiled_code:
__int64 bhyve_check()
{
return cpuid_scan("bhyve bhyve ");
}

canonical_decompiled_code:
__int64 func13()
{
return func12("bhyve bhyve ");
}

original_code:
static _Bool bhyve_check(void)
{
 return cpuid_scan("bhyve bhyve ");
}

canonical_original_code:
static _Bool bhyve_check()
{
 return cpuid_scan("bhyve bhyve ");
}


decompiled_code:
__int64 kvm_check()
{
return cpuid_scan("KVMKVMKVM");
}

canonical_decompiled_code:
__int64 func14()
{
return func12("KVMKVMKVM");
}

original_code:
static _Bool kvm_check(void)
{
 return cpuid_scan("KVMKVMKVM");
}

canonical_original_code:
static _Bool kvm_check()
{
 return cpuid_scan("KVMKVMKVM");
}


decompiled_code:
__int64 hyperv_check()
{
return cpuid_scan("Microsoft Hv");
}

canonical_decompiled_code:
__int64 func15()
{
return func12("Microsoft Hv");
}

original_code:
static _Bool hyperv_check(void)
{
 return cpuid_scan("Microsoft Hv");
}

canonical_original_code:
static _Bool hyperv_check()
{
 return cpuid_scan("Microsoft Hv");
}


decompiled_code:
char vmware_check()
{
char result; // al

result = cpuid_scan("VMwareVMware");
if ( result )
result = vmware_hypervisor_port_check();
return result;
}

canonical_decompiled_code:
char func16()
{
char result; // al

result = func12("VMwareVMware");
if ( result )
result = func8();
return result;
}

original_code:
static _Bool vmware_check(void)
{
 if (!cpuid_scan("VMwareVMware"))
  return 0;
 return vmware_hypervisor_port_check();
}

canonical_original_code:
static _Bool vmware_check()
{
 if (!cpuid_scan("VMwareVMware"))
  return 0;
 return vmware_hypervisor_port_check();
}


decompiled_code:
__int64 xen_check_inner()
{
unsigned int i; // ebx
int v2[3]; // [rsp+3h] [rbp-25h] BYREF
char v3; // [rsp+Fh] [rbp-19h]
int v4; // [rsp+10h] [rbp-18h] BYREF
int v5; // [rsp+14h] [rbp-14h] BYREF
int v6; // [rsp+18h] [rbp-10h] BYREF
unsigned int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

xen_base = 0x40000000;
for ( i = 0x40000000; i != 1073807360; xen_base = i )
{
xen_cpuid(i, v7, &v6, &v5, &v4);
v2[0] = v6;
v2[1] = v5;
v2[2] = v4;
v3 = 0;
if ( !strcmp("XenVMMXenVMM", (const char *)v2) && v7[0] >= i + 2 )
return 1LL;
i += 256;
}
return 0LL;
}

canonical_decompiled_code:
__int64 func17()
{
unsigned int i; // ebx
int v2[3]; // [rsp+3h] [rbp-25h] BYREF
char v3; // [rsp+Fh] [rbp-19h]
int v4; // [rsp+10h] [rbp-18h] BYREF
int v5; // [rsp+14h] [rbp-14h] BYREF
int v6; // [rsp+18h] [rbp-10h] BYREF
unsigned int v7[3]; // [rsp+1Ch] [rbp-Ch] BYREF

xen_base = 0x40000000;
for ( i = 0x40000000; i != 1073807360; xen_base = i )
{
func7(i, v7, &v6, &v5, &v4);
v2[0] = v6;
v2[1] = v5;
v2[2] = v4;
v3 = 0;
if ( !strcmp("XenVMMXenVMM", (const char *)v2) && v7[0] >= i + 2 )
return 1LL;
i += 256;
}
return 0LL;
}

original_code:
static _Bool xen_check_inner(void)
{
 uint32_t eax, ebx, ecx, edx;
 char signature[13];
 for (xen_base = 0x40000000; xen_base < 0x40010000; xen_base += 0x100)
 {
  xen_cpuid(xen_base, &eax, &ebx, &ecx, &edx);
  *(uint32_t *)(signature + 0) = ebx;
  *(uint32_t *)(signature + 4) = ecx;
  *(uint32_t *)(signature + 8) = edx;
  signature[12] = '\0';
  if (!strcmp("XenVMMXenVMM", signature) && eax >= (xen_base + 2))
   return 1;
 }
 return 0;
}

canonical_original_code:
static _Bool xen_check_inner()
{
 unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx;
 char signature[13];
 for (xen_base = 0x40000000; xen_base < 0x40010000; xen_base += 0x100)
 {
  xen_cpuid(xen_base, &eax, &ebx, &ecx, &edx);
  *(unsigned int *)(signature + 0) = ebx;
  *(unsigned int *)(signature + 4) = ecx;
  *(unsigned int *)(signature + 8) = edx;
  signature[12] = '\0';
  if (!strcmp("XenVMMXenVMM", signature) && eax >= (xen_base + 2))
   return 1;
 }
 return 0;
}


decompiled_code:
int vmware_enum_devices()
{
unsigned int i; // ebx
int result; // eax
const char *v2; // rcx
__int64 v3[4]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+20h] [rbp-28h]

for ( i = 0; i != 50; ++i )
{
v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
v4 = 0LL;
result = vmware_read_device(i, (__int64)v3);
if ( (_BYTE)result && LOBYTE(v3[0]) )
{
v2 = "enabled";
if ( !BYTE4(v4) )
v2 = "disabled";
result = printf("Device %d: %s (%s)\n", i, (const char *)v3, v2);
}
}
return result;
}

canonical_decompiled_code:
int func18()
{
unsigned int i; // ebx
int result; // eax
const char *v2; // rcx
__int64 v3[4]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+20h] [rbp-28h]

for ( i = 0; i != 50; ++i )
{
v3[0] = 0LL;
v3[1] = 0LL;
v3[2] = 0LL;
v3[3] = 0LL;
v4 = 0LL;
result = func10(i, (__int64)v3);
if ( (_BYTE)result && LOBYTE(v3[0]) )
{
v2 = "enabled";
if ( !BYTE4(v4) )
v2 = "disabled";
result = printf("Device %d: %s (%s)\n", i, (const char *)v3, v2);
}
}
return result;
}

original_code:
static void vmware_enum_devices(void)
{
 uint16_t i;
 for (i = 0; i < 50; i++)
 {
  struct vmware_device dev = { };
  if (!vmware_read_device(i, &dev))
   continue;
  if (*dev.devname == '\0')
   continue;
  printf("Device %d: %s (%s)\n", i, dev.devname, dev.enabled ? "enabled" : "disabled");
 }
}

canonical_original_code:
static void vmware_enum_devices()
{
 unsigned short i;
 for (i = 0; i < 50; i++)
 {
  struct vmware_device dev = { };
  if (!vmware_read_device(i, &dev))
   continue;
  if (*dev.devname == '\0')
   continue;
  printf("Device %d: %s (%s)\n", i, dev.devname, dev.enabled ? "enabled" : "disabled");
 }
}

variable_types:
i
unsigned short

variable_types: struct vmware_device { char devname[32]; unsigned int devid; _Bool enabled; char pad[3]; }


decompiled_code:
void vmware_explain()
{
unsigned __int32 v0; // eax

v0 = __indword(0x5658u);
abort();
}

canonical_decompiled_code:
void func19()
{
unsigned __int32 v0; // eax

v0 = __indword(0x5658u);
abort();
}

original_code:
static void vmware_explain(void)
{
 uint32_t eax, ebx, ecx, edx;
 __asm__("inl %%dx, %%eax" : "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : "0"(0x564D5868), "1"(10), "2"(0x5658), "3"(ebx) : "memory");;
 if (ebx != 0x564D5868)
  abort();
 printf("Hypervisor: VMware (protocol %d)\n", eax);
 if (ecx != 0)
  printf("Product: %s\n", vmware_types[ecx]);
 vmware_enum_devices();
 __asm__("inl %%dx, %%eax" : "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : "0"(0x564D5868), "1"(17), "2"(0x5658), "3"(ebx) : "memory");;
 if (ebx != 0x564D5868)
  return;
 if (eax != -1)
  printf("Hardware Model: %d\n", eax);
}

canonical_original_code:
static void vmware_explain()
{
 unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx;
 __asm__("inl %%dx, %%eax" : "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : "0"(0x564D5868), "1"(10), "2"(0x5658), "3"(ebx) : "memory");;
 if (ebx != 0x564D5868)
  abort();
 printf("Hypervisor: VMware (protocol %d)\n", eax);
 if (ecx != 0)
  printf("Product: %s\n", vmware_types[ecx]);
 vmware_enum_devices();
 __asm__("inl %%dx, %%eax" : "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : "0"(0x564D5868), "1"(17), "2"(0x5658), "3"(ebx) : "memory");;
 if (ebx != 0x564D5868)
  return;
 if (eax != -1)
  printf("Hardware Model: %d\n", eax);
}


decompiled_code:
int xen_explain()
{
const char *v0; // rsi
int v2; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

xen_cpuid(xen_base + 1, v5, &v4, &v3, &v2);
v0 = "PV";
if ( !xen_pv_context )
v0 = "HVM";
printf("Hypervisor: Xen %s\n", v0);
return printf("Version: %d.%d\n", HIWORD(v5[0]), LOWORD(v5[0]));
}

canonical_decompiled_code:
int func20()
{
const char *v0; // rsi
int v2; // [rsp+0h] [rbp-18h] BYREF
int v3; // [rsp+4h] [rbp-14h] BYREF
int v4; // [rsp+8h] [rbp-10h] BYREF
unsigned int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

func7(xen_base + 1, v5, &v4, &v3, &v2);
v0 = "PV";
if ( !xen_pv_context )
v0 = "HVM";
printf("Hypervisor: Xen %s\n", v0);
return printf("Version: %d.%d\n", HIWORD(v5[0]), LOWORD(v5[0]));
}

original_code:
static void xen_explain(void)
{
 uint32_t eax, ebx, ecx, edx;
 xen_cpuid(xen_base + 1, &eax, &ebx, &ecx, &edx);
 printf("Hypervisor: Xen %s\n", xen_pv_context ? "PV" : "HVM");
 printf("Version: %d.%d\n", (uint16_t)(eax >> 16), (uint16_t)eax);
}

canonical_original_code:
static void xen_explain()
{
 unsigned int eax; unsigned int ebx; unsigned int ecx; unsigned int edx;
 xen_cpuid(xen_base + 1, &eax, &ebx, &ecx, &edx);
 printf("Hypervisor: Xen %s\n", xen_pv_context ? "PV" : "HVM");
 printf("Version: %d.%d\n", (unsigned short)(eax >> 16), (unsigned short)eax);
}


decompiled_code:
__int64 xen_check_outer()
{
unsigned int v0; // ebx
struct sigaction v2; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v3; // [rsp+A0h] [rbp-A8h] BYREF

xen_pv_context = 0;
v0 = xen_check_inner();
if ( !(_BYTE)v0 )
{
if ( _setjmp(xen_sigill_jmp) )
{
xen_pv_context = 0;
}
else
{
memset(&v3.sa_mask, 0, 0x90uLL);
v3.sa_handler = (__sighandler_t)xen_sigill_handler;
sigemptyset(&v3.sa_mask);
v0 = 0;
if ( !sigaction(4, &v3, &v2) )
{
xen_pv_context = 1;
v0 = xen_check_inner();
sigaction(4, &v2, 0LL);
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func21()
{
unsigned int v0; // ebx
struct sigaction v2; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v3; // [rsp+A0h] [rbp-A8h] BYREF

xen_pv_context = 0;
v0 = func17();
if ( !(_BYTE)v0 )
{
if ( _setjmp(xen_sigill_jmp) )
{
xen_pv_context = 0;
}
else
{
memset(&v3.sa_mask, 0, 0x90uLL);
v3.sa_handler = (__sighandler_t)xen_sigill_handler;
sigemptyset(&v3.sa_mask);
v0 = 0;
if ( !sigaction(4, &v3, &v2) )
{
xen_pv_context = 1;
v0 = func17();
sigaction(4, &v2, 0LL);
}
}
}
return v0;
}

original_code:
static _Bool xen_check_outer(void)
{
 struct sigaction act, oldact;
 _Bool ret;
 xen_pv_context = 0;
 if (xen_check_inner())
  return 1;
 if (_setjmp (xen_sigill_jmp))
 {
  xen_pv_context = 0;
  return 0;
 }
 memset(&act, 0, sizeof act);
 act.__sigaction_handler.sa_handler = xen_sigill_handler;
 sigemptyset(&act.sa_mask);
 if (sigaction(4, &act, &oldact))
  return 0;
 xen_pv_context = 1;
 ret = xen_check_inner();
 sigaction(4, &oldact, ((void *)0));
 return ret;
}

canonical_original_code:
static _Bool xen_check_outer()
{
 struct sigaction act; struct sigaction oldact;
 _Bool ret;
 xen_pv_context = 0;
 if (xen_check_inner())
  return 1;
 if (_setjmp (xen_sigill_jmp))
 {
  xen_pv_context = 0;
  return 0;
 }
 memset(&act, 0, sizeof act);
 act.__sigaction_handler.sa_handler = xen_sigill_handler;
 sigemptyset(&act.sa_mask);
 if (sigaction(4, &act, &oldact))
  return 0;
 xen_pv_context = 1;
 ret = xen_check_inner();
 sigaction(4, &oldact, ((void *)0));
 return ret;
}

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

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

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


decompiled_code:
void __noreturn xen_sigill_handler()
{
longjmp(xen_sigill_jmp, 1);
}

canonical_decompiled_code:
void __noreturn func22()
{
longjmp(xen_sigill_jmp, 1);
}

original_code:
static void xen_sigill_handler(int sig)
{
        longjmp(xen_sigill_jmp, 1);
}

variable_types: sig int


decompiled_code:
bool openvz_check()
{
int v0; // edx
bool result; // al

v0 = access("/proc/vz/vzaquota", 4);
result = 1;
if ( v0 )
result = access("/proc/user_beancounters", 4) == 0;
return result;
}

canonical_decompiled_code:
bool func23()
{
int v0; // edx
bool result; // al

v0 = access("/proc/vz/vzaquota", 4);
result = 1;
if ( v0 )
result = access("/proc/user_beancounters", 4) == 0;
return result;
}

original_code:
static _Bool openvz_check(void)
{
 if (!access("/proc/vz/vzaquota", 4))
  return 1;
 if (!access("/proc/user_beancounters", 4))
  return 1;
 return 0;
}

canonical_original_code:
static _Bool openvz_check()
{
 if (!access("/proc/vz/vzaquota", 4))
  return 1;
 if (!access("/proc/user_beancounters", 4))
  return 1;
 return 0;
}


main

canonical_name: main

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

v3 = do_tests((__int64)&ctr_test_impls, 1LL);
if ( v3 )
{
v4 = *(void (**)(void))(v3 + 16);
if ( v4 )
v4();
else
printf("Container: %s\n", *(const char **)v3);
}
else
{
puts("Not running under any known container type");
}
v5 = do_tests((__int64)hv_test_impls, 5LL);
if ( v5 )
{
v6 = *(void (**)(void))(v5 + 16);
if ( v6 )
v6();
else
printf("Hypervisor: %s\n", *(const char **)v5);
result = 1;
}
else
{
puts("Not running under any known hypervisor type");
result = 0;
}
return result;
}

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

v3 = func11((__int64)&ctr_test_impls, 1LL);
if ( v3 )
{
v4 = *(void (**)(void))(v3 + 16);
if ( v4 )
v4();
else
printf("Container: %s\n", *(const char **)v3);
}
else
{
puts("Not running under any known container type");
}
v5 = func11((__int64)hv_test_impls, 5LL);
if ( v5 )
{
v6 = *(void (**)(void))(v5 + 16);
if ( v6 )
v6();
else
printf("Hypervisor: %s\n", *(const char **)v5);
result = 1;
}
else
{
puts("Not running under any known hypervisor type");
result = 0;
}
return result;
}

original_code:
int main(int argc, const char *argv[])
{
 struct test_impl *hv, *ctr;
 ctr = do_tests(ctr_test_impls, (sizeof(ctr_test_impls) / sizeof((ctr_test_impls)[0])));
 if (ctr != ((void *)0))
 {
  if (ctr->explain != ((void *)0))
   ctr->explain();
  else
   printf("Container: %s\n", ctr->hv_name);
 }
 else
  printf("Not running under any known container type\n");
 hv = do_tests(hv_test_impls, (sizeof(hv_test_impls) / sizeof((hv_test_impls)[0])));
 if (hv == ((void *)0))
 {
  printf("Not running under any known hypervisor type\n");
  return 0;
 }
 if (hv->explain != ((void *)0))
  hv->explain();
 else
  printf("Hypervisor: %s\n", hv->hv_name);
 return 1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct test_impl *hv; struct test_impl *ctr;
 ctr = do_tests(ctr_test_impls, (sizeof(ctr_test_impls) / sizeof((ctr_test_impls)[0])));
 if (ctr != ((void *)0))
 {
  if (ctr->explain != ((void *)0))
   ctr->explain();
  else
   printf("Container: %s\n", ctr->hv_name);
 }
 else
  printf("Not running under any known container type\n");
 hv = do_tests(hv_test_impls, (sizeof(hv_test_impls) / sizeof((hv_test_impls)[0])));
 if (hv == ((void *)0))
 {
  printf("Not running under any known hypervisor type\n");
  return 0;
 }
 if (hv->explain != ((void *)0))
  hv->explain();
 else
  printf("Hypervisor: %s\n", hv->hv_name);
 return 1;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct test_impl { char *hv_name; _Bool (*check)(); void (*explain)(); } *


ding

repo: kaoya/CodeNotes

decompiled_code:
int ding()
{
return puts("Ding!");
}

canonical_decompiled_code:
int func7()
{
return puts("Ding!");
}

original_code:
void ding(int sig)
{
    printf("Ding!\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // ebx
__int64 v6; // [rsp+0h] [rbp-B8h] BYREF
struct sigaction v7; // [rsp+10h] [rbp-A8h] BYREF

v7.sa_handler = (__sighandler_t)ding;
sigemptyset(&v7.sa_mask);
v7.sa_flags = 0x10000000;
sigaction(14, &v7, 0LL);
alarm(3u);
puts("waiting for alarm to go off");
v3 = msgget(0, 950);
if ( v3 >= 0 )
{
v4 = v3;
puts("msgget success.");
if ( msgrcv(v4, &v6, 1uLL, 0LL, 0) == -1 )
perror("msgrcv fail");
puts("done");
exit(0);
}
perror("msgget fail");
return 0;
}

original_code:
int main()
{
    int nMsgID = -1;
    struct sigaction action;
    action.__sigaction_handler.sa_handler = ding;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
    action.sa_flags |= 0x10000000;
    sigaction(14, &action, ((void *)0));
    alarm(3);
    printf("waiting for alarm to go off\n");
    nMsgID = msgget(((__key_t) 0), 0666 | 01000);
    if( nMsgID < 0 )
    {
        perror("msgget fail" );
        return;
    }
    printf("msgget success.\n");
    struct msgst msg_st;
    if( -1 == msgrcv( nMsgID, (void*)&msg_st, 1, 0, 0 ) )
    {
        perror("msgrcv fail");
    }
    printf("done\n");
    exit(0);
}

canonical_original_code:
int main()
{
    int nMsgID = -1;
    struct sigaction action;
    action.__sigaction_handler.sa_handler = ding;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
    action.sa_flags |= 0x10000000;
    sigaction(14, &action, ((void *)0));
    alarm(3);
    printf("waiting for alarm to go off\n");
    nMsgID = msgget(((int) 0), 0666 | 01000);
    if( nMsgID < 0 )
    {
        perror("msgget fail" );
        return;
    }
    printf("msgget success.\n");
    struct msgst msg_st;
    if( -1 == msgrcv( nMsgID, (void *)&msg_st, 1, 0, 0 ) )
    {
        perror("msgrcv fail");
    }
    printf("done\n");
    exit(0);
}

variable_types: nMsgID int

variable_types: struct msgst { long msg_type; char buf[1]; }

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }

user_defined_types: union sigval { int sival_int; void *sival_ptr; }


decompiled_code:
int sig_handler()
{
puts("in handler");
sleep(1u);
return puts("handler return");
}

canonical_decompiled_code:
int func7()
{
puts("in handler");
sleep(1u);
return puts("handler return");
}

original_code:
void sig_handler(int signum)
{
    printf("in handler\n");
    sleep(1);
    printf("handler return\n");
}

variable_types: signum int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
struct sigaction v5; // [rsp+0h] [rbp-1B8h] BYREF
struct sigaction v6; // [rsp+A0h] [rbp-118h] BYREF
char buf[96]; // [rsp+140h] [rbp-78h] BYREF
int v8; // [rsp+1A0h] [rbp-18h]

v6.sa_handler = (__sighandler_t)sig_handler;
sigemptyset(&v6.sa_mask);
v6.sa_flags = 0;
sigaction(14, 0LL, &v5);
if ( v5.sa_handler != (__sighandler_t)1 )
sigaction(14, &v6, 0LL);
alarm(3u);
memset(buf, 0, sizeof(buf));
v8 = 0;
v3 = read(0, buf, 0x64uLL);
if ( v3 == -1 )
perror("read");
printf("read %d bytes:\n", v3);
puts(buf);
return 0;
}

original_code:
int main(int argc, char **argv)
{
    char buf[100];
    int ret;
    struct sigaction action, old_action;
    action.__sigaction_handler.sa_handler = sig_handler;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
 sigaction(14, ((void *)0), &old_action);
    if (old_action.__sigaction_handler.sa_handler != ((__sighandler_t) 1)) {
        sigaction(14, &action, ((void *)0));
    }
    alarm(3);
    bzero(buf, 100);
    ret = read(0, buf, 100);
    if (ret == -1) {
        perror("read");
    }
    printf("read %d bytes:\n", ret);
    printf("%s\n", buf);
    return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
    char buf[100];
    int ret;
    struct sigaction action; struct sigaction old_action;
    action.__sigaction_handler.sa_handler = sig_handler;
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;
 sigaction(14, ((void *)0), &old_action);
    if (old_action.__sigaction_handler.sa_handler != ((void (*)(int)) 1)) {
        sigaction(14, &action, ((void *)0));
    }
    alarm(3);
    bzero(buf, 100);
    ret = read(0, buf, 100);
    if (ret == -1) {
        perror("read");
    }
    printf("read %d bytes:\n", ret);
    printf("%s\n", buf);
    return 0;
}

variable_types:
argv
char **

variable_types:
buf
char [100]

variable_types: ret int


decompiled_code:
int __fastcall timer_thread(__int64 a1)
{
return printf("timer_thread function! %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
return printf("timer_thread function! %d\n", a1);
}

original_code:
void timer_thread(union sigval v)
{
    printf("timer_thread function! %d\n", v.sival_int);
}

variable_types: union sigval { int sival_int; void *sival_ptr; }