decompiled_code:
int de_plugin_init()
{
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_CFG_LOAD", 74LL, "de_cfg_load");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_CFG_LOAD", 74LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_LH_INIT", 75LL, "de_lh_init");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_LH_INIT", 75LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_ALERT", 77LL, "de_alert");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_ALERT", 77LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_MSG_SEND", 1LL, "de_msg_send");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_MSG_SEND", 1LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_MSG_FLUSH", 2LL, "de_msg_flush");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_MSG_FLUSH", 2LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_SYSTEM_EVENT",
83LL,
"de_system_event_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_SYSTEM_EVENT",
83LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_ADD_ORDER", 84LL, "de_add_order_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_ADD_ORDER", 84LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_ORDER_EXECUTED",
85LL,
"de_order_exe_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_ORDER_EXECUTED",
85LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_ORDER_CANCELED",
86LL,
"de_order_cancel_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_ORDER_CANCELED",
86LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_TRADE", 87LL, "de_trade_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_TRADE", 87LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_BROKEN_TRADE",
88LL,
"de_broken_trade_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_BROKEN_TRADE",
88LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_SECURITY_STATUS",
89LL,
"de_security_status_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_SECURITY_STATUS",
89LL);
exit(1);
}
return puts("done");
}

canonical_decompiled_code:
int func22()
{
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_CFG_LOAD", 74LL, "de_cfg_load");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_CFG_LOAD", 74LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_LH_INIT", 75LL, "de_lh_init");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_LH_INIT", 75LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_ALERT", 77LL, "de_alert");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_ALERT", 77LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_MSG_SEND", 1LL, "de_msg_send");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_MSG_SEND", 1LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_MSG_FLUSH", 2LL, "de_msg_flush");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_MSG_FLUSH", 2LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_SYSTEM_EVENT",
83LL,
"de_system_event_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_SYSTEM_EVENT",
83LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_ADD_ORDER", 84LL, "de_add_order_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_ADD_ORDER", 84LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_ORDER_EXECUTED",
85LL,
"de_order_exe_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_ORDER_EXECUTED",
85LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_ORDER_CANCELED",
86LL,
"de_order_cancel_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_ORDER_CANCELED",
86LL);
exit(1);
}
puts("done");
printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_TRADE", 87LL, "de_trade_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_TRADE", 87LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_BROKEN_TRADE",
88LL,
"de_broken_trade_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_BROKEN_TRADE",
88LL);
exit(1);
}
puts("done");
printf(
"Loading DirectEdge hook: %s (%d) hook=%s...",
"FH_PLUGIN_DIR_EDGE_MSG_SECURITY_STATUS",
89LL,
"de_security_status_msg");
if ( (unsigned int)fh_plugin_register() )
{
fprintf(
stderr,
"DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n",
"FH_PLUGIN_DIR_EDGE_MSG_SECURITY_STATUS",
89LL);
exit(1);
}
return puts("done");
}

original_code:
void __attribute__ ((constructor)) de_plugin_init(void)
{
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_CFG_LOAD", (74), "de_cfg_load"); if (fh_plugin_register(((74)), (fh_plugin_hook_t)(de_cfg_load)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_CFG_LOAD", (74)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_LH_INIT", (75), "de_lh_init"); if (fh_plugin_register(((75)), (fh_plugin_hook_t)(de_lh_init)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_LH_INIT", (75)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_ALERT", (77), "de_alert"); if (fh_plugin_register(((77)), (fh_plugin_hook_t)(de_alert)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_ALERT", (77)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_MSG_SEND", (1), "de_msg_send"); if (fh_plugin_register(((1)), (fh_plugin_hook_t)(de_msg_send)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_MSG_SEND", (1)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_MSG_FLUSH", (2), "de_msg_flush"); if (fh_plugin_register(((2)), (fh_plugin_hook_t)(de_msg_flush)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_MSG_FLUSH", (2)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_SYSTEM_EVENT", (83), "de_system_event_msg"); if (fh_plugin_register(((83)), (fh_plugin_hook_t)(de_system_event_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_SYSTEM_EVENT", (83)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_ADD_ORDER", (84), "de_add_order_msg"); if (fh_plugin_register(((84)), (fh_plugin_hook_t)(de_add_order_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_ADD_ORDER", (84)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_ORDER_EXECUTED", (85), "de_order_exe_msg"); if (fh_plugin_register(((85)), (fh_plugin_hook_t)(de_order_exe_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_ORDER_EXECUTED", (85)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_ORDER_CANCELED", (86), "de_order_cancel_msg"); if (fh_plugin_register(((86)), (fh_plugin_hook_t)(de_order_cancel_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_ORDER_CANCELED", (86)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_TRADE", (87), "de_trade_msg"); if (fh_plugin_register(((87)), (fh_plugin_hook_t)(de_trade_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_TRADE", (87)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_BROKEN_TRADE", (88), "de_broken_trade_msg"); if (fh_plugin_register(((88)), (fh_plugin_hook_t)(de_broken_trade_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_BROKEN_TRADE", (88)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_SECURITY_STATUS", (89), "de_security_status_msg"); if (fh_plugin_register(((89)), (fh_plugin_hook_t)(de_security_status_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_SECURITY_STATUS", (89)); exit(1); } printf("done\n"); } while (0);
}

canonical_original_code:
void de_plugin_init()
{
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_CFG_LOAD", (74), "de_cfg_load"); if (fh_plugin_register(((74)), (fh_plugin_hook_t)(de_cfg_load)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_CFG_LOAD", (74)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_LH_INIT", (75), "de_lh_init"); if (fh_plugin_register(((75)), (fh_plugin_hook_t)(de_lh_init)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_LH_INIT", (75)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_ALERT", (77), "de_alert"); if (fh_plugin_register(((77)), (fh_plugin_hook_t)(de_alert)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_ALERT", (77)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_MSG_SEND", (1), "de_msg_send"); if (fh_plugin_register(((1)), (fh_plugin_hook_t)(de_msg_send)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_MSG_SEND", (1)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_MSG_FLUSH", (2), "de_msg_flush"); if (fh_plugin_register(((2)), (fh_plugin_hook_t)(de_msg_flush)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_MSG_FLUSH", (2)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_SYSTEM_EVENT", (83), "de_system_event_msg"); if (fh_plugin_register(((83)), (fh_plugin_hook_t)(de_system_event_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_SYSTEM_EVENT", (83)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_ADD_ORDER", (84), "de_add_order_msg"); if (fh_plugin_register(((84)), (fh_plugin_hook_t)(de_add_order_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_ADD_ORDER", (84)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_ORDER_EXECUTED", (85), "de_order_exe_msg"); if (fh_plugin_register(((85)), (fh_plugin_hook_t)(de_order_exe_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_ORDER_EXECUTED", (85)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_ORDER_CANCELED", (86), "de_order_cancel_msg"); if (fh_plugin_register(((86)), (fh_plugin_hook_t)(de_order_cancel_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_ORDER_CANCELED", (86)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_TRADE", (87), "de_trade_msg"); if (fh_plugin_register(((87)), (fh_plugin_hook_t)(de_trade_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_TRADE", (87)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_BROKEN_TRADE", (88), "de_broken_trade_msg"); if (fh_plugin_register(((88)), (fh_plugin_hook_t)(de_broken_trade_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_BROKEN_TRADE", (88)); exit(1); } printf("done\n"); } while (0);
    do { printf("Loading DirectEdge hook: %s (%d) hook=%s...", "FH_PLUGIN_DIR_EDGE_MSG_SECURITY_STATUS", (89), "de_security_status_msg"); if (fh_plugin_register(((89)), (fh_plugin_hook_t)(de_security_status_msg)) != (0)) { fprintf(stderr, "DIRECT_EDGE_PLUGIN: Unable to register %s (%d) hook\n", "FH_PLUGIN_DIR_EDGE_MSG_SECURITY_STATUS", (89)); exit(1); } printf("done\n"); } while (0);
}


repo: csinitiative/fhce

decompiled_code:
__int64 __fastcall fh_shr_lkp_sym_init(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 255) )
{
v3 = fh_mpool_new("SymbolTable", 48LL, *(unsigned int *)(a1 + 256), 0LL);
*(_QWORD *)a2 = v3;
if ( v3 )
{
v4 = fh_ht_new(*(unsigned int *)(a1 + 256), 0LL, key_operations_1);
*(_QWORD *)(a2 + 8) = v4;
if ( v4 )
{
if ( (fh_log_lvl[8] & 4) != 0 )
{
v7 = fh_log_fmt("Symbol table initialized: size:%d key size:%d", *(unsigned int *)(a1 + 256), 20LL);
fh_log("fh_shr_lkp_symbol.c", 78LL, "LH", "STATE", v7);
}
*(_DWORD *)(a2 + 16) = *(_DWORD *)(a1 + 256);
*(_DWORD *)(a2 + 20) = 0;
result = 0LL;
}
else
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v6 = fh_log_fmt("Failed to initialize the symbol hash table");
fh_log("fh_shr_lkp_symbol.c", 73LL, "LH", "ERR", v6);
}
fh_mpool_free(*(_QWORD *)a2);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v5 = fh_log_fmt("failed to initialize the symbol table memory pool");
fh_log("fh_shr_lkp_symbol.c", 66LL, "LH", "ERR", v5);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
result = 0LL;
if ( *(_BYTE *)(a1 + 255) )
{
v3 = fh_mpool_new("SymbolTable", 48LL, *(unsigned int *)(a1 + 256), 0LL);
*(_QWORD *)a2 = v3;
if ( v3 )
{
v4 = fh_ht_new(*(unsigned int *)(a1 + 256), 0LL, key_operations_1);
*(_QWORD *)(a2 + 8) = v4;
if ( v4 )
{
if ( (fh_log_lvl[8] & 4) != 0 )
{
v7 = fh_log_fmt("Symbol table initialized: size:%d key size:%d", *(unsigned int *)(a1 + 256), 20LL);
fh_log("fh_shr_lkp_symbol.c", 78LL, "LH", "STATE", v7);
}
*(_DWORD *)(a2 + 16) = *(_DWORD *)(a1 + 256);
*(_DWORD *)(a2 + 20) = 0;
result = 0LL;
}
else
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v6 = fh_log_fmt("Failed to initialize the symbol hash table");
fh_log("fh_shr_lkp_symbol.c", 73LL, "LH", "ERR", v6);
}
fh_mpool_free(*(_QWORD *)a2);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v5 = fh_log_fmt("failed to initialize the symbol table memory pool");
fh_log("fh_shr_lkp_symbol.c", 66LL, "LH", "ERR", v5);
result = 0xFFFFFFFFLL;
}
}
}
return result;
}

original_code:
FH_STATUS fh_shr_lkp_sym_init(fh_shr_cfg_tbl_t *config, fh_shr_lkp_tbl_t *table)
{
    memset(table, 0, sizeof(fh_shr_lkp_tbl_t));
    if (config->enabled) {
        static fh_ht_kops_t key_operations = {
            .kops_khash = (fh_ht_khash_t *)key_hash,
            .kops_kcmp = (fh_ht_kcmp_t *)key_compare,
            .kops_kdump = (fh_ht_kdump_t *)key_dump,
        };
        table->mempool = fh_mpool_new("SymbolTable", sizeof(fh_shr_lkp_sym_t), config->size, 0);
        if (!table->mempool) {
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to initialize the symbol table memory pool"); fh_log("fh_shr_lkp_symbol.c", 66, "LH", "ERR", _msg); } } while (0);
            return (-1);
        }
        table->hash = fh_ht_new(config->size, 0, &key_operations);
        if (!table->hash) {
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to initialize the symbol hash table"); fh_log("fh_shr_lkp_symbol.c", 73, "LH", "ERR", _msg); } } while (0);
            fh_mpool_free(table->mempool);
            return (-1);
        }
        do { if ((fh_log_lvl[(2)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Symbol table initialized: size:%d key size:%d", config->size, sizeof(fh_shr_lkp_sym_key_t)); fh_log("fh_shr_lkp_symbol.c", 78, "LH", "STATE", _msg); } } while (0);
        table->size = config->size;
        table->count = 0;
    }
    return (0);
}

canonical_original_code:
int fh_shr_lkp_sym_init(struct fh_shr_cfg_tbl *config, struct fh_shr_lkp_tbl *table)
{
    memset(table, 0, sizeof(fh_shr_lkp_tbl_t));
    if (config->enabled) {
        static struct fh_ht_kops_t key_operations = {
            .kops_khash = (fh_ht_khash_t *)key_hash,
            .kops_kcmp = (fh_ht_kcmp_t *)key_compare,
            .kops_kdump = (fh_ht_kdump_t *)key_dump,
        };
        table->mempool = fh_mpool_new("SymbolTable", sizeof(fh_shr_lkp_sym_t), config->size, 0);
        if (!table->mempool) {
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to initialize the symbol table memory pool"); fh_log("fh_shr_lkp_symbol.c", 66, "LH", "ERR", _msg); } } while (0);
            return (-1);
        }
        table->hash = fh_ht_new(config->size, 0, &key_operations);
        if (!table->hash) {
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to initialize the symbol hash table"); fh_log("fh_shr_lkp_symbol.c", 73, "LH", "ERR", _msg); } } while (0);
            fh_mpool_free(table->mempool);
            return (-1);
        }
        do { if ((fh_log_lvl[(2)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Symbol table initialized: size:%d key size:%d", config->size, sizeof(fh_shr_lkp_sym_key_t)); fh_log("fh_shr_lkp_symbol.c", 78, "LH", "STATE", _msg); } } while (0);
        table->size = config->size;
        table->count = 0;
    }
    return (0);
}

variable_types: struct fh_shr_cfg_tbl { char name[255]; unsigned char enabled; unsigned int size; } *

variable_types: struct fh_shr_lkp_tbl { struct fh_mpool_t { char *mp_name; struct _mp_mblock { struct _mp_mblock *mb_next; } *mp_mblocks; struct _mp_mchunk { struct _mp_mchunk *mc_next; } *mp_mchunks; unsigned int mp_chunksize; unsigned int mp_nchunks; unsigned int mp_nblocks; unsigned int mp_flags; unsigned int mp_free; unsigned int mp_inuse; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mp_lock; } *mempool; struct fh_ht_t { struct fh_mpool_t *ht_mpool; struct he_head_t { struct _fh_ht_elt { struct he_entry_t { struct _fh_ht_elt *tqe_next; struct _fh_ht_elt **tqe_prev; } he_next; struct he_head_t *he_chead; void *he_value; void *he_key; int he_klen; unsigned int he_hashval; } *tqh_first; struct _fh_ht_elt **tqh_last; } *ht_table; unsigned int ht_size; unsigned int ht_count; unsigned int ht_mask; unsigned int ht_flags; struct fh_ht_kops_t { unsigned int (*kops_khash)(void *key, int klen); char *(*kops_kdump)(void *key, int klen); int (*kops_kcmp)(void *key_a, void *key_b, int klen); } ht_kops; } *hash; unsigned int size; unsigned int count; } *

return_type: int

user_defined_types: struct fh_shr_lkp_tbl { struct fh_mpool_t *mempool; struct fh_ht_t *hash; unsigned int size; unsigned int count; }

user_defined_types: struct fh_mpool_t { char *mp_name; struct _mp_mblock *mp_mblocks; struct _mp_mchunk *mp_mchunks; unsigned int mp_chunksize; unsigned int mp_nchunks; unsigned int mp_nblocks; unsigned int mp_flags; unsigned int mp_free; unsigned int mp_inuse; union pthread_mutex_t mp_lock; }

user_defined_types: struct fh_ht_t { struct fh_mpool_t *ht_mpool; struct he_head_t *ht_table; unsigned int ht_size; unsigned int ht_count; unsigned int ht_mask; unsigned int ht_flags; struct fh_ht_kops_t ht_kops; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }

user_defined_types: struct he_head_t { struct _fh_ht_elt *tqh_first; struct _fh_ht_elt **tqh_last; }

user_defined_types: struct _fh_ht_elt { struct he_entry_t he_next; struct he_head_t *he_chead; void *he_value; void *he_key; int he_klen; unsigned int he_hashval; }


decompiled_code:
__int64 __fastcall fh_shr_lkp_sym_get(_QWORD *a1, const __m128i *a2, __int64 *a3)
{
unsigned int v4; // eax
unsigned int v5; // ebx
__int64 v7; // rax
__m128i *v8; // rax
const char *v9; // r13
__int64 v10; // rsi
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax

v4 = fh_ht_get(a1[1], a2, 20LL, a3);
if ( v4 == 1 )
{
v7 = fh_mpool_get(*a1);
*a3 = v7;
if ( v7 )
{
strcpy((char *)(v7 + 20), a2->m128i_i8);
v8 = (__m128i *)*a3;
*v8 = _mm_loadu_si128(a2);
v8[1].m128i_i32[0] = a2[1].m128i_i32[0];
v9 = (const char *)*a3;
v5 = fh_ht_put(a1[1], *a3, 20LL, *a3);
if ( v5 == 2 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v13 = fh_log_fmt("duplicate symbol in symbol table: %s", v9);
fh_log("fh_shr_lkp_symbol.c", 116LL, "LH", "ERR", v13);
}
fh_mpool_put(*a1, *a3);
}
else
{
v10 = (unsigned int)(*((_DWORD *)a1 + 5) + 1);
*((_DWORD *)a1 + 5) = v10;
v5 = 0;
if ( 10 * (int)v10 > (unsigned int)(9 * *((_DWORD *)a1 + 4))
&& (_DWORD)v10 == 100 * ((unsigned int)v10 / 0x64)
&& (fh_log_lvl[8] & 2) != 0 )
{
v11 = fh_log_fmt("symbol table over 90%% full (count: %d)", v10);
fh_log("fh_shr_lkp_symbol.c", 126LL, "LH", "WARN", v11);
}
}
}
else
{
v5 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v12 = fh_log_fmt("failed to get a new symbol table entry");
fh_log("fh_shr_lkp_symbol.c", 103LL, "LH", "ERR", v12);
}
}
}
else
{
v5 = v4;
if ( v4 && (fh_log_lvl[8] & 1) != 0 )
{
v14 = fh_log_fmt("Unknown error fetching entry from symbol table (%d)", v4);
fh_log("fh_shr_lkp_symbol.c", 131LL, "LH", "ERR", v14);
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, const __m128i *a2, __int64 *a3)
{
unsigned int v4; // eax
unsigned int v5; // ebx
__int64 v7; // rax
__m128i *v8; // rax
const char *v9; // r13
__int64 v10; // rsi
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax

v4 = fh_ht_get(a1[1], a2, 20LL, a3);
if ( v4 == 1 )
{
v7 = fh_mpool_get(*a1);
*a3 = v7;
if ( v7 )
{
strcpy((char *)(v7 + 20), a2->m128i_i8);
v8 = (__m128i *)*a3;
*v8 = _mm_loadu_si128(a2);
v8[1].m128i_i32[0] = a2[1].m128i_i32[0];
v9 = (const char *)*a3;
v5 = fh_ht_put(a1[1], *a3, 20LL, *a3);
if ( v5 == 2 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v13 = fh_log_fmt("duplicate symbol in symbol table: %s", v9);
fh_log("fh_shr_lkp_symbol.c", 116LL, "LH", "ERR", v13);
}
fh_mpool_put(*a1, *a3);
}
else
{
v10 = (unsigned int)(*((_DWORD *)a1 + 5) + 1);
*((_DWORD *)a1 + 5) = v10;
v5 = 0;
if ( 10 * (int)v10 > (unsigned int)(9 * *((_DWORD *)a1 + 4))
&& (_DWORD)v10 == 100 * ((unsigned int)v10 / 0x64)
&& (fh_log_lvl[8] & 2) != 0 )
{
v11 = fh_log_fmt("symbol table over 90%% full (count: %d)", v10);
fh_log("fh_shr_lkp_symbol.c", 126LL, "LH", "WARN", v11);
}
}
}
else
{
v5 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v12 = fh_log_fmt("failed to get a new symbol table entry");
fh_log("fh_shr_lkp_symbol.c", 103LL, "LH", "ERR", v12);
}
}
}
else
{
v5 = v4;
if ( v4 && (fh_log_lvl[8] & 1) != 0 )
{
v14 = fh_log_fmt("Unknown error fetching entry from symbol table (%d)", v4);
fh_log("fh_shr_lkp_symbol.c", 131LL, "LH", "ERR", v14);
}
}
return v5;
}

original_code:
FH_STATUS fh_shr_lkp_sym_get(fh_shr_lkp_tbl_t *table, fh_shr_lkp_sym_key_t *key,
                             fh_shr_lkp_sym_t **entry)
{
    FH_STATUS rc;
    rc = fh_ht_get(table->hash, key, sizeof(fh_shr_lkp_sym_key_t), (void **)entry);
    if (rc == (1)) {
        *entry = (fh_shr_lkp_sym_t *)fh_mpool_get(table->mempool);
        if (*entry == ((void *)0)) {
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to get a new symbol table entry"); fh_log("fh_shr_lkp_symbol.c", 103, "LH", "ERR", _msg); } } while (0);
            return (-1);
        }
        strcpy((*entry)->symbol, key->symbol);
        memcpy(&(*entry)->key, key, sizeof(fh_shr_lkp_sym_key_t));
        key = &(*entry)->key;
        if (fh_ht_put(table->hash, key, sizeof(fh_shr_lkp_sym_key_t), *entry) == (2)) {
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("duplicate symbol in symbol table: %s", key); fh_log("fh_shr_lkp_symbol.c", 116, "LH", "ERR", _msg); } } while (0);
            fh_mpool_put(table->mempool, *entry);
            return (2);
        }
        table->count++;
        if ((10 * table->count) > (9 * table->size) && (table->count % 100) == 0) {
            do { if ((fh_log_lvl[(2)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("symbol table over 90%% full (count: %d)", table->count); fh_log("fh_shr_lkp_symbol.c", 126, "LH", "WARN", _msg); } } while (0);
        }
    }
    else if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Unknown error fetching entry from symbol table (%d)", rc); fh_log("fh_shr_lkp_symbol.c", 131, "LH", "ERR", _msg); } } while (0);
        return rc;
    }
    return (0);
}

canonical_original_code:
int fh_shr_lkp_sym_get(struct fh_shr_lkp_tbl *table, struct fh_shr_lkp_sym_key *key, struct fh_shr_lkp_sym **entry)
{
    int rc;
    rc = fh_ht_get(table->hash, key, sizeof(fh_shr_lkp_sym_key_t), (void **)entry);
    if (rc == (1)) {
        *entry = (struct fh_shr_lkp_sym *)fh_mpool_get(table->mempool);
        if (*entry == ((void *)0)) {
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("failed to get a new symbol table entry"); fh_log("fh_shr_lkp_symbol.c", 103, "LH", "ERR", _msg); } } while (0);
            return (-1);
        }
        strcpy((*entry)->symbol, key->symbol);
        memcpy(&(*entry)->key, key, sizeof(fh_shr_lkp_sym_key_t));
        key = &(*entry)->key;
        if (fh_ht_put(table->hash, key, sizeof(fh_shr_lkp_sym_key_t), *entry) == (2)) {
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("duplicate symbol in symbol table: %s", key); fh_log("fh_shr_lkp_symbol.c", 116, "LH", "ERR", _msg); } } while (0);
            fh_mpool_put(table->mempool, *entry);
            return (2);
        }
        table->count++;
        if ((10 * table->count) > (9 * table->size) && (table->count % 100) == 0) {
            do { if ((fh_log_lvl[(2)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("symbol table over 90%% full (count: %d)", table->count); fh_log("fh_shr_lkp_symbol.c", 126, "LH", "WARN", _msg); } } while (0);
        }
    }
    else if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Unknown error fetching entry from symbol table (%d)", rc); fh_log("fh_shr_lkp_symbol.c", 131, "LH", "ERR", _msg); } } while (0);
        return rc;
    }
    return (0);
}

variable_types: struct fh_shr_lkp_sym_key { char symbol[20]; } *

variable_types: struct fh_shr_lkp_sym { struct fh_shr_lkp_sym_key key; char symbol[20]; void *context; } **

variable_types: rc int

user_defined_types: struct fh_ht_kops_t { unsigned int (*kops_khash)(void *key, int klen); char *(*kops_kdump)(void *key, int klen); int (*kops_kcmp)(void *key_a, void *key_b, int klen); }

user_defined_types: struct _mp_mblock { struct _mp_mblock *mb_next; }

user_defined_types: struct _mp_mchunk { struct _mp_mchunk *mc_next; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct he_entry_t { struct _fh_ht_elt *tqe_next; struct _fh_ht_elt **tqe_prev; }


decompiled_code:
__int64 __fastcall fh_opra_pkt_process(__int64 a1, __int64 a2, _BYTE *a3, unsigned int a4)
{
unsigned __int8 *v6; // rax
unsigned int v7; // ebx
unsigned int v8; // er15
unsigned int v9; // ebx
unsigned int v10; // ebp
int v12; // edx
__int64 v13; // rax
__int64 v14; // rax
unsigned __int8 v15; // [rsp+Ah] [rbp-3Eh] BYREF
unsigned __int8 v16; // [rsp+Bh] [rbp-3Dh] BYREF
unsigned int v17[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v17[0] = 0;
if ( a3[1] == 2 )
{
v6 = a3 + 2;
v7 = 0;
do
v7 = *v6++ + 10 * v7 - 48;
while ( v6 != a3 + 12 );
v8 = (unsigned __int8)a3[14] + 10 * ((unsigned __int8)a3[13] + 2 * (5 * (unsigned __int8)a3[12] - 240) - 48) - 48;
if ( (int)fast_opra_hdr_info(a1, a3, a4, &v16, &v15, 0LL, v17) < 0 )
{
++*(_QWORD *)(*(_QWORD *)(a2 + 24) + 8LL);
v9 = -1;
}
else if ( *(_DWORD *)(a2 + 64) )
{
*(_QWORD *)(*(_QWORD *)(a2 + 24) + 64LL) += v8;
fh_opra_lh_tap(a2, v16, v15, v7, v8, fh_opra_lh_recv_time);
v9 = 0;
}
else
{
v9 = fh_opra_lh_is_dup(a2, (unsigned int)(char)v16, (unsigned int)(char)v15, v7, v8, v17[0]);
if ( v9 )
{
v9 = -1;
}
else
{
v10 = fast_opra_decode(a1, a3, a4);
if ( v10 != v8 && (fh_log_lvl[8] & 1) != 0 )
{
v14 = fh_log_fmt("Line %s parsed messages %d packet header %d", (const char *)a2, v10, v8);
fh_log("fh_opra_lh_v2.c", 132LL, "LH", "ERR", v14);
}
*(_QWORD *)(*(_QWORD *)(a2 + 24) + 64LL) += v10;
}
}
}
else
{
v12 = pkt_count_0;
if ( pkt_count_0 == 100000 * (pkt_count_0 / 100000) )
{
++pkt_count_0;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v13 = fh_log_fmt("FastOpraV2: Invalid OPRA Fast version: %d pkts", (unsigned int)(v12 + 1));
fh_log("fh_opra_lh_v2.c", 75LL, "LH", "ERR", v13);
}
}
++*(_QWORD *)(*(_QWORD *)(a2 + 24) + 8LL);
v9 = -1;
}
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, _BYTE *a3, unsigned int a4)
{
unsigned __int8 *v6; // rax
unsigned int v7; // ebx
unsigned int v8; // er15
unsigned int v9; // ebx
unsigned int v10; // ebp
int v12; // edx
__int64 v13; // rax
__int64 v14; // rax
unsigned __int8 v15; // [rsp+Ah] [rbp-3Eh] BYREF
unsigned __int8 v16; // [rsp+Bh] [rbp-3Dh] BYREF
unsigned int v17[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v17[0] = 0;
if ( a3[1] == 2 )
{
v6 = a3 + 2;
v7 = 0;
do
v7 = *v6++ + 10 * v7 - 48;
while ( v6 != a3 + 12 );
v8 = (unsigned __int8)a3[14] + 10 * ((unsigned __int8)a3[13] + 2 * (5 * (unsigned __int8)a3[12] - 240) - 48) - 48;
if ( (int)fast_opra_hdr_info(a1, a3, a4, &v16, &v15, 0LL, v17) < 0 )
{
++*(_QWORD *)(*(_QWORD *)(a2 + 24) + 8LL);
v9 = -1;
}
else if ( *(_DWORD *)(a2 + 64) )
{
*(_QWORD *)(*(_QWORD *)(a2 + 24) + 64LL) += v8;
fh_opra_lh_tap(a2, v16, v15, v7, v8, fh_opra_lh_recv_time);
v9 = 0;
}
else
{
v9 = fh_opra_lh_is_dup(a2, (unsigned int)(char)v16, (unsigned int)(char)v15, v7, v8, v17[0]);
if ( v9 )
{
v9 = -1;
}
else
{
v10 = fast_opra_decode(a1, a3, a4);
if ( v10 != v8 && (fh_log_lvl[8] & 1) != 0 )
{
v14 = fh_log_fmt("Line %s parsed messages %d packet header %d", (const char *)a2, v10, v8);
fh_log("fh_opra_lh_v2.c", 132LL, "LH", "ERR", v14);
}
*(_QWORD *)(*(_QWORD *)(a2 + 24) + 64LL) += v10;
}
}
}
else
{
v12 = pkt_count_0;
if ( pkt_count_0 == 100000 * (pkt_count_0 / 100000) )
{
++pkt_count_0;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v13 = fh_log_fmt("FastOpraV2: Invalid OPRA Fast version: %d pkts", (unsigned int)(v12 + 1));
fh_log("fh_opra_lh_v2.c", 75LL, "LH", "ERR", v13);
}
}
++*(_QWORD *)(*(_QWORD *)(a2 + 24) + 8LL);
v9 = -1;
}
return v9;
}

original_code:
FH_STATUS fh_opra_pkt_process(Fast *fast, lh_line_t *l, uint8_t *buffer, uint32_t len)
{
    uint32_t num_msgs = 0;
    uint32_t parsed_num_msgs = 1;
    uint32_t msg_sn = 0;
    uint32_t msg_time = 0;
    char msg_cat;
    char msg_type;
    uint8_t *seq_num_ptr = buffer + 2;
    uint8_t *num_msgs_ptr = buffer + 12;
    int i;
    if (buffer[1] != 2) {
        static int pkt_count = 0;
        if ((pkt_count % 100000) == 0) {
            pkt_count++;
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("FastOpraV2: Invalid OPRA Fast version: %d pkts", pkt_count); fh_log("fh_opra_lh_v2.c", 75, "LH", "ERR", _msg); } } while (0);
        }
        l->l_stats->lst_pkt_errs++;
        return (-1);
    }
    for (i=0; i<10; i++) {
        msg_sn *= 10;
        msg_sn += (seq_num_ptr[i] - '0');
    }
    for (i=0; i<3; i++) {
        num_msgs *= 10;
        num_msgs += (num_msgs_ptr[i] - '0');
    }
    if (fast_opra_hdr_info(fast, buffer, len, &msg_cat, &msg_type, ((void *)0), &msg_time) < 0) {
        l->l_stats->lst_pkt_errs++;
        return (-1);
    }
    if (l->l_tap) {
        l->l_stats->lst_msg_rx += num_msgs;
        fh_opra_lh_tap(l, msg_cat, msg_type, msg_sn, num_msgs, fh_opra_lh_recv_time);
        return (0);
    }
    if (fh_opra_lh_is_dup(l, msg_cat, msg_type, msg_sn, num_msgs, msg_time)) {
        return (-1);
    }
    parsed_num_msgs = fast_opra_decode(fast, buffer, len);
    if (parsed_num_msgs != num_msgs) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Line %s parsed messages %d packet header %d", l->l_name, parsed_num_msgs, num_msgs); fh_log("fh_opra_lh_v2.c", 132, "LH", "ERR", _msg); } } while (0);
    }
    l->l_stats->lst_msg_rx += parsed_num_msgs;
    return (0);
}

canonical_original_code:
int fh_opra_pkt_process(struct Fast *fast, struct lh_line *l, unsigned char *buffer, unsigned int len)
{
    unsigned int num_msgs = 0;
    unsigned int parsed_num_msgs = 1;
    unsigned int msg_sn = 0;
    unsigned int msg_time = 0;
    char msg_cat;
    char msg_type;
    unsigned char *seq_num_ptr = buffer + 2;
    unsigned char *num_msgs_ptr = buffer + 12;
    int i;
    if (buffer[1] != 2) {
        static int pkt_count = 0;
        if ((pkt_count % 100000) == 0) {
            pkt_count++;
            do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("FastOpraV2: Invalid OPRA Fast version: %d pkts", pkt_count); fh_log("fh_opra_lh_v2.c", 75, "LH", "ERR", _msg); } } while (0);
        }
        l->l_stats->lst_pkt_errs++;
        return (-1);
    }
    for (i=0; i<10; i++) {
        msg_sn *= 10;
        msg_sn += (seq_num_ptr[i] - '0');
    }
    for (i=0; i<3; i++) {
        num_msgs *= 10;
        num_msgs += (num_msgs_ptr[i] - '0');
    }
    if (fast_opra_hdr_info(fast, buffer, len, &msg_cat, &msg_type, ((void *)0), &msg_time) < 0) {
        l->l_stats->lst_pkt_errs++;
        return (-1);
    }
    if (l->l_tap) {
        l->l_stats->lst_msg_rx += num_msgs;
        fh_opra_lh_tap(l, msg_cat, msg_type, msg_sn, num_msgs, fh_opra_lh_recv_time);
        return (0);
    }
    if (fh_opra_lh_is_dup(l, msg_cat, msg_type, msg_sn, num_msgs, msg_time)) {
        return (-1);
    }
    parsed_num_msgs = fast_opra_decode(fast, buffer, len);
    if (parsed_num_msgs != num_msgs) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Line %s parsed messages %d packet header %d", l->l_name, parsed_num_msgs, num_msgs); fh_log("fh_opra_lh_v2.c", 132, "LH", "ERR", _msg); } } while (0);
    }
    l->l_stats->lst_msg_rx += parsed_num_msgs;
    return (0);
}

variable_types: struct Fast { unsigned char (*getCategory)(struct Fast *fast, unsigned int tag); void (*setBuffer)(struct Fast *fast, unsigned char *buf, int size); int (*decode_new_msg)(struct Fast *fast, unsigned int tag); int (*decode_end_msg)(struct Fast *fast, unsigned int tag); unsigned char (*decode_ch)(struct Fast *fast, unsigned int tag); unsigned int (*decode_u32)(struct Fast *fast, unsigned int tag); int (*decode_str)(struct Fast *fast, unsigned int tag, unsigned char *data, int size); void (*verbose)(struct Fast *fast); struct fast_codec_t { unsigned int magic; char *name; struct fast_pmap_t { unsigned char bits[-1]; unsigned int size; unsigned int max_pos; } pmap[1]; struct fast_buffer_t { int fd; unsigned char *head; unsigned char *tail; unsigned char *end; unsigned char *data; } input[1]; struct fast_cv_t { int i32_values[64]; unsigned int u32_values[64]; unsigned char *str_values[64]; unsigned int valid[64]; } cv[15]; int count; int skip_io; int verbose; int curr_tag; int in_message; struct fast_codec_error_t { char *fn; char *text; unsigned int tag; enum fast_error_t { FAST_ERR_NONE=0, FAST_ERR_CODEC=-1, FAST_ERR_SIZE=-2, FAST_ERR_VALUE=-3, FAST_ERR_TAG_OP=-4, FAST_ERR_TAG_TYPE=-5, FAST_ERR_CALL_SEQ=-6, FAST_ERR_IO=-7 } code; } error[1]; } *codec; } *

variable_types: struct lh_line { char l_name[4]; int l_index; int l_sock; struct fh_opra_line_t { unsigned short ol_init; unsigned short ol_enable; unsigned short ol_side; unsigned short ol_port; unsigned int ol_mcaddr; char ol_ifname[16]; } *l_config; struct fh_opra_line_stats_t { unsigned long lst_pkt_rx; unsigned long lst_pkt_errs; unsigned long lst_pkt_dups; unsigned long lst_pkt_late; unsigned long lst_pkt_until_reset; unsigned long lst_pkt_bad_times; unsigned long lst_pkt_seq_jump; unsigned long lst_pkt_wrap_noreset; unsigned long lst_msg_rx; unsigned long lst_msg_loss; unsigned long lst_msg_recovered; unsigned long lst_msg_late; unsigned long lst_bytes; } *l_stats; struct lh_ftline { struct fh_opra_opt_lh_t { struct fh_opra_opt { struct fh_opra_opt_le_t { struct fh_opra_opt *tqe_next; struct fh_opra_opt **tqe_prev; } opt_line_le; char opt_topic[32]; struct fh_opra_opt_key_t { char k_symbol[5]; unsigned char k_year; unsigned char k_month; unsigned char k_day; char k_putcall; char k_exchid; unsigned short k_fraction; unsigned int k_decimal; } opt_key; struct fh_opra_lo_t { char lo_root[-1]; char lo_sec[-1]; } *opt_lo; void *opt_priv; unsigned short opt_ftline_idx; unsigned short opt_init; unsigned int opt_uflags; union opra_exp_date_t { char exp_year_v1; struct { char exp_year[2]; char exp_date[2]; } exp_date_v2; } opt_exp_date; char opt_session; char opt_bo_partid; char opt_bb_partid; unsigned int opt_seq_num; unsigned int opt_time; unsigned int opt_open_bid; unsigned int opt_open_offer; unsigned int opt_open_price; unsigned int opt_close_price; unsigned int opt_last_price; unsigned int opt_high_price; unsigned int opt_low_price; unsigned int opt_daily_high; unsigned int opt_daily_low; unsigned int opt_bid_price; unsigned int opt_offer_price; unsigned long opt_cum_volume; unsigned long opt_cum_value; unsigned long opt_halttime; unsigned long opt_unhalttime; } *tqh_first; struct fh_opra_opt **tqh_last; } ftl_options; struct fh_opra_ftline_t { unsigned int oftl_index; struct fh_opra_line_t oftl_line_a; struct fh_opra_line_t oftl_line_b; } *ftl_config; unsigned int ftl_reset_sn; unsigned int ftl_seq_num; unsigned int ftl_missing; unsigned int ftl_window[-1]; unsigned int ftl_state; void *ftl_priv; unsigned int ftl_time; } *l_ftline; unsigned int l_reset; struct lh_line *l_peer; struct fh_hist_t { char *hg_key; unsigned long hg_start; unsigned long hg_stop; int hg_bincnt; int hg_binsize; unsigned long *hg_bins; unsigned long hg_total; long hg_min; long hg_max; long hg_sum; float hg_avg; } *l_jitter_hist; unsigned int l_tap; unsigned int l_seq_num; } *

variable_types:
buffer
unsigned char *

variable_types:
len
unsigned int

variable_types: i int

user_defined_types: struct Fast { unsigned char (*getCategory)(struct Fast *fast, unsigned int tag); void (*setBuffer)(struct Fast *fast, unsigned char *buf, int size); int (*decode_new_msg)(struct Fast *fast, unsigned int tag); int (*decode_end_msg)(struct Fast *fast, unsigned int tag); unsigned char (*decode_ch)(struct Fast *fast, unsigned int tag); unsigned int (*decode_u32)(struct Fast *fast, unsigned int tag); int (*decode_str)(struct Fast *fast, unsigned int tag, unsigned char *data, int size); void (*verbose)(struct Fast *fast); struct fast_codec_t *codec; }

user_defined_types: struct lh_line { char l_name[4]; int l_index; int l_sock; struct fh_opra_line_t *l_config; struct fh_opra_line_stats_t *l_stats; struct lh_ftline *l_ftline; unsigned int l_reset; struct lh_line *l_peer; struct fh_hist_t *l_jitter_hist; unsigned int l_tap; unsigned int l_seq_num; }

user_defined_types: struct fast_codec_t { unsigned int magic; char *name; struct fast_pmap_t pmap[1]; struct fast_buffer_t input[1]; struct fast_cv_t cv[15]; int count; int skip_io; int verbose; int curr_tag; int in_message; struct fast_codec_error_t error[1]; }

user_defined_types: struct lh_ftline { struct fh_opra_opt_lh_t ftl_options; struct fh_opra_ftline_t *ftl_config; unsigned int ftl_reset_sn; unsigned int ftl_seq_num; unsigned int ftl_missing; unsigned int ftl_window[-1]; unsigned int ftl_state; void *ftl_priv; unsigned int ftl_time; }

user_defined_types: struct fh_opra_opt_lh_t { struct fh_opra_opt *tqh_first; struct fh_opra_opt **tqh_last; }

user_defined_types: struct fast_codec_error_t { char *fn; char *text; unsigned int tag; enum fast_error_t code; }

user_defined_types: struct fh_opra_opt { struct fh_opra_opt_le_t opt_line_le; char opt_topic[32]; struct fh_opra_opt_key_t opt_key; struct fh_opra_lo_t *opt_lo; void *opt_priv; unsigned short opt_ftline_idx; unsigned short opt_init; unsigned int opt_uflags; union opra_exp_date_t opt_exp_date; char opt_session; char opt_bo_partid; char opt_bb_partid; unsigned int opt_seq_num; unsigned int opt_time; unsigned int opt_open_bid; unsigned int opt_open_offer; unsigned int opt_open_price; unsigned int opt_close_price; unsigned int opt_last_price; unsigned int opt_high_price; unsigned int opt_low_price; unsigned int opt_daily_high; unsigned int opt_daily_low; unsigned int opt_bid_price; unsigned int opt_offer_price; unsigned long opt_cum_volume; unsigned long opt_cum_value; unsigned long opt_halttime; unsigned long opt_unhalttime; }


decompiled_code:
__int64 __fastcall fh_mpool_memuse(_DWORD *a1)
{
__int64 v2; // rax

if ( !a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 34LL);
fh_log("fh_mpool.c", 34LL, 0LL, "ERR", v2);
exit(1);
}
return (unsigned int)(a1[8] * (a1[7] * (a1[6] + 8) + 8));
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1)
{
__int64 v2; // rax

if ( !a1 )
{
v2 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 34LL);
fh_log("fh_mpool.c", 34LL, 0LL, "ERR", v2);
exit(1);
}
return (unsigned int)(a1[8] * (a1[7] * (a1[6] + 8) + 8));
}

original_code:
uint32_t fh_mpool_memuse(fh_mpool_t *mp)
{
    int chunk_size, block_size;
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 34); fh_log("fh_mpool.c", 34, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    chunk_size = sizeof(fh_mchunk_t) + mp->mp_chunksize;
    block_size = sizeof(fh_mblock_t) + mp->mp_nchunks * chunk_size;
    return mp->mp_nblocks * block_size;
}

canonical_original_code:
unsigned int fh_mpool_memuse(struct fh_mpool_t *mp)
{
    int chunk_size; int block_size;
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 34); fh_log("fh_mpool.c", 34, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    chunk_size = sizeof(fh_mchunk_t) + mp->mp_chunksize;
    block_size = sizeof(fh_mblock_t) + mp->mp_nchunks * chunk_size;
    return mp->mp_nblocks * block_size;
}

variable_types: struct fh_mpool_t { char *mp_name; struct _mp_mblock { struct _mp_mblock *mb_next; } *mp_mblocks; struct _mp_mchunk { struct _mp_mchunk *mc_next; } *mp_mchunks; unsigned int mp_chunksize; unsigned int mp_nchunks; unsigned int mp_nblocks; unsigned int mp_flags; unsigned int mp_free; unsigned int mp_inuse; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mp_lock; } *

variable_types: nok int

return_type: unsigned int

user_defined_types: struct fh_mpool_t { char *mp_name; struct _mp_mblock *mp_mblocks; struct _mp_mchunk *mp_mchunks; unsigned int mp_chunksize; unsigned int mp_nchunks; unsigned int mp_nblocks; unsigned int mp_flags; unsigned int mp_free; unsigned int mp_inuse; union pthread_mutex_t mp_lock; }


decompiled_code:
__int64 __fastcall fh_mpool_stats(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v12; // rax

if ( !a1 )
{
v12 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 49LL);
fh_log("fh_mpool.c", 49LL, 0LL, "ERR", v12);
exit(1);
}
v1 = fh_log_fmt("---------------------------------------------");
fh_log("fh_mpool.c", 51LL, 0LL, "DIAG", v1);
v2 = fh_log_fmt("------------ Memory Pool Stats --------------");
fh_log("fh_mpool.c", 52LL, 0LL, "DIAG", v2);
v3 = fh_log_fmt("---------------------------------------------");
fh_log("fh_mpool.c", 53LL, 0LL, "DIAG", v3);
v4 = fh_log_fmt(" > Memory pool name : %s", *(const char **)a1);
fh_log("fh_mpool.c", 54LL, 0LL, "DIAG", v4);
v5 = fh_log_fmt(" > Configuration flags : 0x%08X", *(unsigned int *)(a1 + 36));
fh_log("fh_mpool.c", 55LL, 0LL, "DIAG", v5);
v6 = fh_log_fmt(" > Chunk size : %10d", *(unsigned int *)(a1 + 24));
fh_log("fh_mpool.c", 56LL, 0LL, "DIAG", v6);
v7 = fh_log_fmt(" > Cum chunks per block : %10d", *(unsigned int *)(a1 + 28));
fh_log("fh_mpool.c", 57LL, 0LL, "DIAG", v7);
v8 = fh_log_fmt(" > Cum blocks : %10d", *(unsigned int *)(a1 + 32));
fh_log("fh_mpool.c", 58LL, 0LL, "DIAG", v8);
v9 = fh_log_fmt(" > Cum free chunks : %10d", *(unsigned int *)(a1 + 40));
fh_log("fh_mpool.c", 59LL, 0LL, "DIAG", v9);
v10 = fh_log_fmt(" > Cum inuse chunks : %10d", *(unsigned int *)(a1 + 44));
return fh_log("fh_mpool.c", 60LL, 0LL, "DIAG", v10);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v12; // rax

if ( !a1 )
{
v12 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 49LL);
fh_log("fh_mpool.c", 49LL, 0LL, "ERR", v12);
exit(1);
}
v1 = fh_log_fmt("---------------------------------------------");
fh_log("fh_mpool.c", 51LL, 0LL, "DIAG", v1);
v2 = fh_log_fmt("------------ Memory Pool Stats --------------");
fh_log("fh_mpool.c", 52LL, 0LL, "DIAG", v2);
v3 = fh_log_fmt("---------------------------------------------");
fh_log("fh_mpool.c", 53LL, 0LL, "DIAG", v3);
v4 = fh_log_fmt(" > Memory pool name : %s", *(const char **)a1);
fh_log("fh_mpool.c", 54LL, 0LL, "DIAG", v4);
v5 = fh_log_fmt(" > Configuration flags : 0x%08X", *(unsigned int *)(a1 + 36));
fh_log("fh_mpool.c", 55LL, 0LL, "DIAG", v5);
v6 = fh_log_fmt(" > Chunk size : %10d", *(unsigned int *)(a1 + 24));
fh_log("fh_mpool.c", 56LL, 0LL, "DIAG", v6);
v7 = fh_log_fmt(" > Cum chunks per block : %10d", *(unsigned int *)(a1 + 28));
fh_log("fh_mpool.c", 57LL, 0LL, "DIAG", v7);
v8 = fh_log_fmt(" > Cum blocks : %10d", *(unsigned int *)(a1 + 32));
fh_log("fh_mpool.c", 58LL, 0LL, "DIAG", v8);
v9 = fh_log_fmt(" > Cum free chunks : %10d", *(unsigned int *)(a1 + 40));
fh_log("fh_mpool.c", 59LL, 0LL, "DIAG", v9);
v10 = fh_log_fmt(" > Cum inuse chunks : %10d", *(unsigned int *)(a1 + 44));
return fh_log("fh_mpool.c", 60LL, 0LL, "DIAG", v10);
}

original_code:
void fh_mpool_stats(fh_mpool_t *mp)
{
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 49); fh_log("fh_mpool.c", 49, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { char *_msg = fh_log_fmt ("---------------------------------------------"); fh_log("fh_mpool.c", 51, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("------------ Memory Pool Stats --------------"); fh_log("fh_mpool.c", 52, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("---------------------------------------------"); fh_log("fh_mpool.c", 53, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Memory pool name     : %s", mp->mp_name); fh_log("fh_mpool.c", 54, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Configuration flags  : 0x%08X", mp->mp_flags); fh_log("fh_mpool.c", 55, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Chunk size           : %10d", mp->mp_chunksize); fh_log("fh_mpool.c", 56, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Cum chunks per block : %10d", mp->mp_nchunks); fh_log("fh_mpool.c", 57, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Cum blocks           : %10d", mp->mp_nblocks); fh_log("fh_mpool.c", 58, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Cum free chunks      : %10d", mp->mp_free); fh_log("fh_mpool.c", 59, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Cum inuse chunks     : %10d", mp->mp_inuse); fh_log("fh_mpool.c", 60, ((void *)0), "DIAG", _msg); } while (0);
}

canonical_original_code:
void fh_mpool_stats(struct fh_mpool_t *mp)
{
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 49); fh_log("fh_mpool.c", 49, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { char *_msg = fh_log_fmt ("---------------------------------------------"); fh_log("fh_mpool.c", 51, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("------------ Memory Pool Stats --------------"); fh_log("fh_mpool.c", 52, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("---------------------------------------------"); fh_log("fh_mpool.c", 53, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Memory pool name     : %s", mp->mp_name); fh_log("fh_mpool.c", 54, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Configuration flags  : 0x%08X", mp->mp_flags); fh_log("fh_mpool.c", 55, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Chunk size           : %10d", mp->mp_chunksize); fh_log("fh_mpool.c", 56, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Cum chunks per block : %10d", mp->mp_nchunks); fh_log("fh_mpool.c", 57, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Cum blocks           : %10d", mp->mp_nblocks); fh_log("fh_mpool.c", 58, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Cum free chunks      : %10d", mp->mp_free); fh_log("fh_mpool.c", 59, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt (" > Cum inuse chunks     : %10d", mp->mp_inuse); fh_log("fh_mpool.c", 60, ((void *)0), "DIAG", _msg); } while (0);
}

return_type: void

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }


decompiled_code:
__int64 __fastcall mpool_grow(_QWORD *a1)
{
int v2; // er12
unsigned int v3; // er13
int v4; // er14
_QWORD *v5; // rax
_QWORD *v6; // rbx
unsigned int v7; // er10
_QWORD *v8; // rax
int v9; // edi
int v10; // ecx
int v11; // edi
unsigned int v12; // edx
_QWORD *v13; // rsi
int v14; // esi
__int64 result; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax

if ( !a1 )
{
v16 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 76LL);
fh_log("fh_mpool.c", 76LL, 0LL, "ERR", v16);
exit(1);
}
v2 = *((_DWORD *)a1 + 6) + 8;
v3 = *((_DWORD *)a1 + 7);
v4 = v3 * v2 + 8;
v5 = malloc(v4);
v6 = v5;
if ( v5 )
{
memset(v5, 0, v4);
*v6 = a1[1];
a1[1] = v6;
v7 = *((_DWORD *)a1 + 8) + 1;
*((_DWORD *)a1 + 8) = v7;
if ( v3 )
{
v8 = (_QWORD *)a1[2];
v9 = *((_DWORD *)a1 + 10);
v10 = v9 + 1;
v11 = v3 + v9;
v12 = 0;
do
{
v13 = v8;
v8 = (_QWORD *)((char *)v6 + v12 + 8);
*v8 = v13;
v14 = v10++;
v12 += v2;
}
while ( v14 != v11 );
a1[2] = v8;
*((_DWORD *)a1 + 10) = v14;
}
result = 0LL;
if ( (fh_log_lvl & 0x20) != 0 )
{
v18 = fh_log_fmt(
"MPOOL_GROW: pool '%s' nblocks %d nchunks %d free %d inuse %d",
(const char *)*a1,
v7,
v3,
*((unsigned int *)a1 + 10),
*((unsigned int *)a1 + 11));
fh_log("fh_mpool.c", 108LL, "CSI", "INFO", v18);
result = 0LL;
}
}
else
{
if ( (fh_log_lvl & 1) != 0 )
{
v17 = fh_log_fmt("Failed to allocate new block: %d bytes", *a1);
fh_log("fh_mpool.c", 83LL, "CSI", "ERR", v17);
}
fh_mpool_stats((__int64)a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
int v2; // er12
unsigned int v3; // er13
int v4; // er14
_QWORD *v5; // rax
_QWORD *v6; // rbx
unsigned int v7; // er10
_QWORD *v8; // rax
int v9; // edi
int v10; // ecx
int v11; // edi
unsigned int v12; // edx
_QWORD *v13; // rsi
int v14; // esi
__int64 result; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax

if ( !a1 )
{
v16 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 76LL);
fh_log("fh_mpool.c", 76LL, 0LL, "ERR", v16);
exit(1);
}
v2 = *((_DWORD *)a1 + 6) + 8;
v3 = *((_DWORD *)a1 + 7);
v4 = v3 * v2 + 8;
v5 = malloc(v4);
v6 = v5;
if ( v5 )
{
memset(v5, 0, v4);
*v6 = a1[1];
a1[1] = v6;
v7 = *((_DWORD *)a1 + 8) + 1;
*((_DWORD *)a1 + 8) = v7;
if ( v3 )
{
v8 = (_QWORD *)a1[2];
v9 = *((_DWORD *)a1 + 10);
v10 = v9 + 1;
v11 = v3 + v9;
v12 = 0;
do
{
v13 = v8;
v8 = (_QWORD *)((char *)v6 + v12 + 8);
*v8 = v13;
v14 = v10++;
v12 += v2;
}
while ( v14 != v11 );
a1[2] = v8;
*((_DWORD *)a1 + 10) = v14;
}
result = 0LL;
if ( (fh_log_lvl & 0x20) != 0 )
{
v18 = fh_log_fmt(
"MPOOL_GROW: pool '%s' nblocks %d nchunks %d free %d inuse %d",
(const char *)*a1,
v7,
v3,
*((unsigned int *)a1 + 10),
*((unsigned int *)a1 + 11));
fh_log("fh_mpool.c", 108LL, "CSI", "INFO", v18);
result = 0LL;
}
}
else
{
if ( (fh_log_lvl & 1) != 0 )
{
v17 = fh_log_fmt("Failed to allocate new block: %d bytes", *a1);
fh_log("fh_mpool.c", 83LL, "CSI", "ERR", v17);
}
func1((__int64)a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static FH_STATUS mpool_grow(fh_mpool_t *mp)
{
    int chunk_size, block_size;
    uint32_t i;
    char *arena = ((void *)0);
    fh_mblock_t *mb = ((void *)0);
    fh_mchunk_t *mc = ((void *)0);
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 76); fh_log("fh_mpool.c", 76, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    chunk_size = sizeof(fh_mchunk_t) + mp->mp_chunksize;
    block_size = sizeof(fh_mblock_t) + mp->mp_nchunks * chunk_size;
    arena = (char *) malloc(block_size);
    if (!arena) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to allocate new block: %d bytes", mp->mp_name, block_size); fh_log("fh_mpool.c", 83, "CSI", "ERR", _msg); } } while (0);
        fh_mpool_stats(mp);
        return (-1);
    }
    memset(arena, 0, block_size);
    mb = (fh_mblock_t *) arena;
    mb->mb_next = mp->mp_mblocks;
    mp->mp_mblocks = mb;
    mp->mp_nblocks++;
    arena = (char *)(mb+1);
    for (i=0; i<mp->mp_nchunks; i++) {
        mc = (fh_mchunk_t *) (arena + i * chunk_size);
        mc->mc_next = mp->mp_mchunks;
        mp->mp_mchunks = mc;
        mp->mp_free++;
    }
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("MPOOL_GROW: pool '%s' nblocks %d nchunks %d free %d inuse %d", mp->mp_name, mp->mp_nblocks, mp->mp_nchunks, mp->mp_free, mp->mp_inuse); fh_log("fh_mpool.c", 108, "CSI", "INFO", _msg); } } while (0);
    return (0);
}

canonical_original_code:
static int mpool_grow(struct fh_mpool_t *mp)
{
    int chunk_size; int block_size;
    unsigned int i;
    char *arena = ((void *)0);
    struct _mp_mblock *mb = ((void *)0);
    struct _mp_mchunk *mc = ((void *)0);
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 76); fh_log("fh_mpool.c", 76, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    chunk_size = sizeof(fh_mchunk_t) + mp->mp_chunksize;
    block_size = sizeof(fh_mblock_t) + mp->mp_nchunks * chunk_size;
    arena = (char *) malloc(block_size);
    if (!arena) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to allocate new block: %d bytes", mp->mp_name, block_size); fh_log("fh_mpool.c", 83, "CSI", "ERR", _msg); } } while (0);
        fh_mpool_stats(mp);
        return (-1);
    }
    memset(arena, 0, block_size);
    mb = (struct _mp_mblock *) arena;
    mb->mb_next = mp->mp_mblocks;
    mp->mp_mblocks = mb;
    mp->mp_nblocks++;
    arena = (char *)(mb+1);
    for (i=0; i<mp->mp_nchunks; i++) {
        mc = (struct _mp_mchunk *) (arena + i * chunk_size);
        mc->mc_next = mp->mp_mchunks;
        mp->mp_mchunks = mc;
        mp->mp_free++;
    }
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("MPOOL_GROW: pool '%s' nblocks %d nchunks %d free %d inuse %d", mp->mp_name, mp->mp_nblocks, mp->mp_nchunks, mp->mp_free, mp->mp_inuse); fh_log("fh_mpool.c", 108, "CSI", "INFO", _msg); } } while (0);
    return (0);
}

variable_types:
i
unsigned int

variable_types:
arena
char *

variable_types: struct _mp_mblock { struct _mp_mblock *mb_next; } *

variable_types: struct _mp_mchunk { struct _mp_mchunk *mc_next; } *

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
void __fastcall fh_mpool_free(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi
__int64 v4; // rax
__int64 v5; // rax

if ( !ptr )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 169LL);
fh_log("fh_mpool.c", 169LL, 0LL, "ERR", v4);
exit(1);
}
if ( (*((_BYTE *)ptr + 36) & 2) != 0 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 48));
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( !v2 )
goto LABEL_5;
}
else
{
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( !v2 )
goto LABEL_7;
}
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
LABEL_5:
if ( (*((_BYTE *)ptr + 36) & 2) != 0 )
{
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 48));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
}
LABEL_7:
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
if ( (fh_log_lvl & 0x20) != 0 )
{
v5 = fh_log_fmt(
"MPOOL_FREE: pool='%s': free pool: free %d, inuse %d",
*(const char **)ptr,
*((unsigned int *)ptr + 10),
*((unsigned int *)ptr + 11));
fh_log("fh_mpool.c", 192LL, "CSI", "INFO", v5);
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi
__int64 v4; // rax
__int64 v5; // rax

if ( !ptr )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 169LL);
fh_log("fh_mpool.c", 169LL, 0LL, "ERR", v4);
exit(1);
}
if ( (*((_BYTE *)ptr + 36) & 2) != 0 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)ptr + 48));
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( !v2 )
goto LABEL_5;
}
else
{
v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( !v2 )
goto LABEL_7;
}
do
{
v3 = v2;
v2 = (_QWORD *)*v2;
free(v3);
}
while ( v2 );
LABEL_5:
if ( (*((_BYTE *)ptr + 36) & 2) != 0 )
{
pthread_mutex_unlock((pthread_mutex_t *)((char *)ptr + 48));
pthread_mutex_destroy((pthread_mutex_t *)((char *)ptr + 48));
}
LABEL_7:
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
if ( (fh_log_lvl & 0x20) != 0 )
{
v5 = fh_log_fmt(
"MPOOL_FREE: pool='%s': free pool: free %d, inuse %d",
*(const char **)ptr,
*((unsigned int *)ptr + 10),
*((unsigned int *)ptr + 11));
fh_log("fh_mpool.c", 192LL, "CSI", "INFO", v5);
}
free(ptr);
}

original_code:
void fh_mpool_free(fh_mpool_t *mp)
{
    fh_mblock_t *mb = ((void *)0);
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 169); fh_log("fh_mpool.c", 169, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_lock(&mp->mp_lock);
    }
    mb = mp->mp_mblocks;
    while (mb != ((void *)0)) {
        fh_mblock_t *nextmb = mb->mb_next;
        free(mb);
        mb = nextmb;
    }
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_unlock(&mp->mp_lock);
        pthread_mutex_destroy(&mp->mp_lock);
    }
    if (mp->mp_name) {
        free(mp->mp_name);
    }
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("MPOOL_FREE: pool='%s': free pool: free %d, inuse %d", mp->mp_name, mp->mp_free, mp->mp_inuse); fh_log("fh_mpool.c", 192, "CSI", "INFO", _msg); } } while (0);
    free(mp);
}

canonical_original_code:
void fh_mpool_free(struct fh_mpool_t *mp)
{
    struct _mp_mblock *mb = ((void *)0);
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 169); fh_log("fh_mpool.c", 169, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_lock(&mp->mp_lock);
    }
    mb = mp->mp_mblocks;
    while (mb != ((void *)0)) {
        struct _mp_mblock *nextmb = mb->mb_next;
        free(mb);
        mb = nextmb;
    }
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_unlock(&mp->mp_lock);
        pthread_mutex_destroy(&mp->mp_lock);
    }
    if (mp->mp_name) {
        free(mp->mp_name);
    }
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("MPOOL_FREE: pool='%s': free pool: free %d, inuse %d", mp->mp_name, mp->mp_free, mp->mp_inuse); fh_log("fh_mpool.c", 192, "CSI", "INFO", _msg); } } while (0);
    free(mp);
}


decompiled_code:
const void *__fastcall fh_mpool_get(const char **a1)
{
const char **v1; // rbp
const void *v2; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax

if ( !a1 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 208LL);
fh_log("fh_mpool.c", 208LL, 0LL, "ERR", v4);
exit(1);
}
if ( (*((_BYTE *)a1 + 36) & 2) != 0 )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 6));
if ( !*((_DWORD *)a1 + 10) )
{
if ( (*((_BYTE *)a1 + 36) & 1) == 0 )
{
fh_mpool_stats((__int64)a1);
v2 = 0LL;
if ( (fh_log_lvl & 1) != 0 )
{
v5 = fh_log_fmt("pool '%s' is not growable: %d free elments", *a1, *((unsigned int *)a1 + 10));
fh_log("fh_mpool.c", 218LL, "CSI", "ERR", v5);
}
goto LABEL_20;
}
if ( (unsigned int)mpool_grow(a1) )
{
v2 = 0LL;
if ( (fh_log_lvl & 1) != 0 )
{
v6 = fh_log_fmt("ran out of chunks and couldn't grow the memory pool");
fh_log("fh_mpool.c", 225LL, "CSI", "ERR", v6);
}
goto LABEL_20;
}
}
if ( !a1[2] && (fh_log_lvl & 1) != 0 )
{
v7 = fh_log_fmt(
"MPOOL_GET: pool='%s': ran out of chunks: inuse %d free %d",
*a1,
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 10));
fh_log("fh_mpool.c", 231LL, "CSI", "ERR", v7);
}
v1 = (const char **)a1[2];
a1[2] = *v1;
++*((_DWORD *)a1 + 11);
--*((_DWORD *)a1 + 10);
if ( (*((_BYTE *)a1 + 36) & 2) != 0 )
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 6));
v2 = v1 + 1;
if ( (fh_log_lvl & 0x20) == 0 )
goto LABEL_20;
}
else
{
v2 = v1 + 1;
if ( (fh_log_lvl & 0x20) == 0 )
return v2;
}
v8 = fh_log_fmt(
"MPOOL_GET: pool='%s': chunk=%p inuse %d free %d",
*a1,
v2,
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 10));
fh_log("fh_mpool.c", 248LL, "CSI", "INFO", v8);
LABEL_20:
if ( (*((_BYTE *)a1 + 36) & 2) != 0 )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 6));
return v2;
}

canonical_decompiled_code:
const void *__fastcall func4(const char **a1)
{
const char **v1; // rbp
const void *v2; // rbp
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax
__int64 v7; // rax
__int64 v8; // rax

if ( !a1 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 208LL);
fh_log("fh_mpool.c", 208LL, 0LL, "ERR", v4);
exit(1);
}
if ( (*((_BYTE *)a1 + 36) & 2) != 0 )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 6));
if ( !*((_DWORD *)a1 + 10) )
{
if ( (*((_BYTE *)a1 + 36) & 1) == 0 )
{
func1((__int64)a1);
v2 = 0LL;
if ( (fh_log_lvl & 1) != 0 )
{
v5 = fh_log_fmt("pool '%s' is not growable: %d free elments", *a1, *((unsigned int *)a1 + 10));
fh_log("fh_mpool.c", 218LL, "CSI", "ERR", v5);
}
goto LABEL_20;
}
if ( (unsigned int)func2(a1) )
{
v2 = 0LL;
if ( (fh_log_lvl & 1) != 0 )
{
v6 = fh_log_fmt("ran out of chunks and couldn't grow the memory pool");
fh_log("fh_mpool.c", 225LL, "CSI", "ERR", v6);
}
goto LABEL_20;
}
}
if ( !a1[2] && (fh_log_lvl & 1) != 0 )
{
v7 = fh_log_fmt(
"MPOOL_GET: pool='%s': ran out of chunks: inuse %d free %d",
*a1,
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 10));
fh_log("fh_mpool.c", 231LL, "CSI", "ERR", v7);
}
v1 = (const char **)a1[2];
a1[2] = *v1;
++*((_DWORD *)a1 + 11);
--*((_DWORD *)a1 + 10);
if ( (*((_BYTE *)a1 + 36) & 2) != 0 )
{
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 6));
v2 = v1 + 1;
if ( (fh_log_lvl & 0x20) == 0 )
goto LABEL_20;
}
else
{
v2 = v1 + 1;
if ( (fh_log_lvl & 0x20) == 0 )
return v2;
}
v8 = fh_log_fmt(
"MPOOL_GET: pool='%s': chunk=%p inuse %d free %d",
*a1,
v2,
*((unsigned int *)a1 + 11),
*((unsigned int *)a1 + 10));
fh_log("fh_mpool.c", 248LL, "CSI", "INFO", v8);
LABEL_20:
if ( (*((_BYTE *)a1 + 36) & 2) != 0 )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 6));
return v2;
}

original_code:
void *fh_mpool_get(fh_mpool_t *mp)
{
    fh_mchunk_t *mc;
    void *e = ((void *)0);
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 208); fh_log("fh_mpool.c", 208, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_lock(&mp->mp_lock);
    }
    if (mp->mp_free == 0) {
        if (!(mp->mp_flags & (0x0000001))) {
            fh_mpool_stats(mp);
            do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("pool '%s' is not growable: %d free elments", mp->mp_name, mp->mp_free); fh_log("fh_mpool.c", 218, "CSI", "ERR", _msg); } } while (0);
            goto end;
        }
        if (mpool_grow(mp) != (0)) {
            do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("ran out of chunks and couldn't grow the memory pool"); fh_log("fh_mpool.c", 225, "CSI", "ERR", _msg); } } while (0);
            goto end;
        }
    }
    if (mp->mp_mchunks == ((void *)0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("MPOOL_GET: pool='%s': ran out of chunks: inuse %d free %d", mp->mp_name, mp->mp_inuse, mp->mp_free); fh_log("fh_mpool.c", 231, "CSI", "ERR", _msg); } } while (0);
        do { int nok = !(1); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "1", "fh_mpool.c", 233); fh_log("fh_mpool.c", 233, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    }
    mc = mp->mp_mchunks;
    mp->mp_mchunks = mc->mc_next;
    mp->mp_inuse++;
    mp->mp_free--;
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_unlock(&mp->mp_lock);
    }
    e = (char *)mc + sizeof(fh_mchunk_t);
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("MPOOL_GET: pool='%s': chunk=%p inuse %d free %d", mp->mp_name, e, mp->mp_inuse, mp->mp_free); fh_log("fh_mpool.c", 248, "CSI", "INFO", _msg); } } while (0);
end:
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_unlock(&mp->mp_lock);
    }
    return e;
}

canonical_original_code:
void *fh_mpool_get(struct fh_mpool_t *mp)
{
    struct _mp_mchunk *mc;
    void *e = ((void *)0);
    do { int nok = !(mp); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp", "fh_mpool.c", 208); fh_log("fh_mpool.c", 208, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_lock(&mp->mp_lock);
    }
    if (mp->mp_free == 0) {
        if (!(mp->mp_flags & (0x0000001))) {
            fh_mpool_stats(mp);
            do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("pool '%s' is not growable: %d free elments", mp->mp_name, mp->mp_free); fh_log("fh_mpool.c", 218, "CSI", "ERR", _msg); } } while (0);
            goto end;
        }
        if (mpool_grow(mp) != (0)) {
            do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("ran out of chunks and couldn't grow the memory pool"); fh_log("fh_mpool.c", 225, "CSI", "ERR", _msg); } } while (0);
            goto end;
        }
    }
    if (mp->mp_mchunks == ((void *)0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("MPOOL_GET: pool='%s': ran out of chunks: inuse %d free %d", mp->mp_name, mp->mp_inuse, mp->mp_free); fh_log("fh_mpool.c", 231, "CSI", "ERR", _msg); } } while (0);
        do { int nok = !(1); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "1", "fh_mpool.c", 233); fh_log("fh_mpool.c", 233, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    }
    mc = mp->mp_mchunks;
    mp->mp_mchunks = mc->mc_next;
    mp->mp_inuse++;
    mp->mp_free--;
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_unlock(&mp->mp_lock);
    }
    e = (char *)mc + sizeof(fh_mchunk_t);
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("MPOOL_GET: pool='%s': chunk=%p inuse %d free %d", mp->mp_name, e, mp->mp_inuse, mp->mp_free); fh_log("fh_mpool.c", 248, "CSI", "INFO", _msg); } } while (0);
end:
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_unlock(&mp->mp_lock);
    }
    return e;
}

variable_types:
e
void *

return_type: void *


decompiled_code:
__int64 __fastcall fh_mpool_put(__int64 a1, char *a2)
{
__int64 v3; // rax
__int64 v4; // rax

if ( !a1 || !a2 )
{
v3 = fh_log_fmt("assertion '%s' failed at %s:%d", "mp && e", "fh_mpool.c", 267LL);
fh_log("fh_mpool.c", 267LL, 0LL, "ERR", v3);
exit(1);
}
if ( (*(_BYTE *)(a1 + 36) & 2) != 0 )
pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
if ( (*(_BYTE *)(a1 + 36) & 4) != 0 )
memset(a2, 0, *(unsigned int *)(a1 + 24));
*((_QWORD *)a2 - 1) = *(_QWORD *)(a1 + 16);
*(_QWORD *)(a1 + 16) = a2 - 8;
--*(_DWORD *)(a1 + 44);
++*(_DWORD *)(a1 + 40);
if ( (*(_BYTE *)(a1 + 36) & 2) != 0 )
pthread_mutex_unlock((pthread_mutex_t *)(a1 + 48));
if ( (fh_log_lvl & 0x20) != 0 )
{
v4 = fh_log_fmt(
"MPOOL_PUT: pool='%s': chunk=%p inuse %d free %d",
*(const char **)a1,
a2,
*(unsigned int *)(a1 + 44),
*(unsigned int *)(a1 + 40));
fh_log("fh_mpool.c", 289LL, "CSI", "INFO", v4);
}
return 0LL;
}

original_code:
FH_STATUS fh_mpool_put(fh_mpool_t *mp, void *e)
{
    fh_mchunk_t *mc = ((void *)0);
    do { int nok = !(mp && e); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp && e", "fh_mpool.c", 267); fh_log("fh_mpool.c", 267, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    mc = (fh_mchunk_t *) ((char *)e - sizeof(fh_mchunk_t));
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_lock(&mp->mp_lock);
    }
    if (mp->mp_flags & (0x0000004)) {
        memset(e, 0, mp->mp_chunksize);
    }
    mc->mc_next = mp->mp_mchunks;
    mp->mp_mchunks = mc;
    mp->mp_inuse--;
    mp->mp_free++;
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_unlock(&mp->mp_lock);
    }
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("MPOOL_PUT: pool='%s': chunk=%p inuse %d free %d", mp->mp_name, e, mp->mp_inuse, mp->mp_free); fh_log("fh_mpool.c", 289, "CSI", "INFO", _msg); } } while (0);
    return (0);
}

canonical_original_code:
int fh_mpool_put(struct fh_mpool_t *mp, void *e)
{
    struct _mp_mchunk *mc = ((void *)0);
    do { int nok = !(mp && e); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "mp && e", "fh_mpool.c", 267); fh_log("fh_mpool.c", 267, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    mc = (struct _mp_mchunk *) ((char *)e - sizeof(fh_mchunk_t));
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_lock(&mp->mp_lock);
    }
    if (mp->mp_flags & (0x0000004)) {
        memset(e, 0, mp->mp_chunksize);
    }
    mc->mc_next = mp->mp_mchunks;
    mp->mp_mchunks = mc;
    mp->mp_inuse--;
    mp->mp_free++;
    if (mp->mp_flags & (0x0000002)) {
        pthread_mutex_unlock(&mp->mp_lock);
    }
    do { if ((fh_log_lvl[(0)] & ((0x00000020)))) { char *_msg = fh_log_fmt ("MPOOL_PUT: pool='%s': chunk=%p inuse %d free %d", mp->mp_name, e, mp->mp_inuse, mp->mp_free); fh_log("fh_mpool.c", 289, "CSI", "INFO", _msg); } } while (0);
    return (0);
}


decompiled_code:
__int64 __fastcall fh_mcast_ttl(unsigned int a1, unsigned __int8 a2)
{
__int64 result; // rax
int *v3; // rax
__int64 v4; // rax
char optval[12]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = a2;
if ( setsockopt(a1, 0, 33, optval, 1u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = _errno_location();
v4 = fh_log_fmt(
"NET> setsockopt IP_MULTICAST_TTL(%d) failed on socket #%d: %d",
(unsigned __int8)optval[0],
a1,
(unsigned int)*v3);
fh_log("fh_mcast.c", 32LL, "NET", "ERR", v4);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned __int8 a2)
{
__int64 result; // rax
int *v3; // rax
__int64 v4; // rax
char optval[12]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = a2;
if ( setsockopt(a1, 0, 33, optval, 1u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = _errno_location();
v4 = fh_log_fmt(
"NET> setsockopt IP_MULTICAST_TTL(%d) failed on socket #%d: %d",
(unsigned __int8)optval[0],
a1,
(unsigned int)*v3);
fh_log("fh_mcast.c", 32LL, "NET", "ERR", v4);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
FH_STATUS fh_mcast_ttl(int s, uint8_t ttl)
{
    if (setsockopt(s, IPPROTO_IP, 33, (char*)&ttl, sizeof(ttl)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_MULTICAST_TTL(%d) failed on socket #%d: %d", ttl, s, (*__errno_location ())); fh_log("fh_mcast.c", 32, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_mcast_ttl(int s, unsigned char ttl)
{
    if (setsockopt(s, IPPROTO_IP, 33, (char *)&ttl, sizeof(ttl)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_MULTICAST_TTL(%d) failed on socket #%d: %d", ttl, s, (*__errno_location ())); fh_log("fh_mcast.c", 32, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: s int

variable_types:
ttl
unsigned char


decompiled_code:
__int64 __fastcall fh_mcast_if(int fd, const char *a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // er12
const char *v5; // rax
__int64 v6; // rax
unsigned int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = fh_net_ifaddr();
if ( optval[0] )
{
if ( setsockopt(fd, 0, 32, optval, 4u) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v4 = *_errno_location();
v5 = (const char *)fh_net_ntoa(optval[0]);
v6 = fh_log_fmt("NET> setsockopt IP_MULTICAST_IF(%s/%s) failed on socket #%d: %d", v5, a2, (unsigned int)fd, v4);
fh_log("fh_mcast.c", 56LL, "NET", "ERR", v6);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = fh_log_fmt("NET> Failed to get interface address (%s)", a2);
fh_log("fh_mcast.c", 51LL, "NET", "ERR", v3);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, const char *a2)
{
__int64 result; // rax
__int64 v3; // rax
unsigned int v4; // er12
const char *v5; // rax
__int64 v6; // rax
unsigned int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

optval[0] = fh_net_ifaddr();
if ( optval[0] )
{
if ( setsockopt(fd, 0, 32, optval, 4u) < 0 )
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v4 = *_errno_location();
v5 = (const char *)fh_net_ntoa(optval[0]);
v6 = fh_log_fmt("NET> setsockopt IP_MULTICAST_IF(%s/%s) failed on socket #%d: %d", v5, a2, (unsigned int)fd, v4);
fh_log("fh_mcast.c", 56LL, "NET", "ERR", v6);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0LL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = fh_log_fmt("NET> Failed to get interface address (%s)", a2);
fh_log("fh_mcast.c", 51LL, "NET", "ERR", v3);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
FH_STATUS fh_mcast_if(int s, char *ifname)
{
    uint32_t ifaddr;
    ifaddr = fh_net_ifaddr(s, ifname);
    if (ifaddr == 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> Failed to get interface address (%s)", ifname); fh_log("fh_mcast.c", 51, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    if (setsockopt(s, IPPROTO_IP, 32, (char*)&ifaddr, sizeof(ifaddr)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_MULTICAST_IF(%s/%s) failed on socket #%d: %d", fh_net_ntoa(ifaddr), ifname, s, (*__errno_location ())); fh_log("fh_mcast.c", 56, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_mcast_if(int s, char *ifname)
{
    unsigned int ifaddr;
    ifaddr = fh_net_ifaddr(s, ifname);
    if (ifaddr == 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> Failed to get interface address (%s)", ifname); fh_log("fh_mcast.c", 51, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    if (setsockopt(s, IPPROTO_IP, 32, (char *)&ifaddr, sizeof(ifaddr)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_MULTICAST_IF(%s/%s) failed on socket #%d: %d", fh_net_ntoa(ifaddr), ifname, s, (*__errno_location ())); fh_log("fh_mcast.c", 56, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types:
ifname
char *

variable_types:
ifaddr
unsigned int


decompiled_code:
__int64 __fastcall fh_mcast_loop(unsigned int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rcx
const char *v4; // rsi
__int64 v5; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = a2;
if ( setsockopt(a1, 0, 34, optval, 4u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = (unsigned int)*_errno_location();
v4 = "on";
if ( !optval[0] )
v4 = "off";
v5 = fh_log_fmt("NET> setsockopt IP_MULTICAST_LOOP(%s) failed on socket #%d: %d", v4, a1, v3);
fh_log("fh_mcast.c", 73LL, "NET", "ERR", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2)
{
__int64 result; // rax
__int64 v3; // rcx
const char *v4; // rsi
__int64 v5; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

optval[0] = a2;
if ( setsockopt(a1, 0, 34, optval, 4u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v3 = (unsigned int)*_errno_location();
v4 = "on";
if ( !optval[0] )
v4 = "off";
v5 = fh_log_fmt("NET> setsockopt IP_MULTICAST_LOOP(%s) failed on socket #%d: %d", v4, a1, v3);
fh_log("fh_mcast.c", 73LL, "NET", "ERR", v5);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
FH_STATUS fh_mcast_loop(int s, int on)
{
    if (setsockopt(s, IPPROTO_IP, 34, (char*)&on, sizeof(on)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_MULTICAST_LOOP(%s) failed on socket #%d: %d", on ? "on" : "off", s, (*__errno_location ())); fh_log("fh_mcast.c", 73, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_mcast_loop(int s, int on)
{
    if (setsockopt(s, IPPROTO_IP, 34, (char *)&on, sizeof(on)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_MULTICAST_LOOP(%s) failed on socket #%d: %d", on ? "on" : "off", s, (*__errno_location ())); fh_log("fh_mcast.c", 73, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: on int


decompiled_code:
__int64 __fastcall fh_mcast_join(unsigned int a1, int a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v5; // er12
const char *v6; // rax
__int64 v7; // rax
int optval[8]; // [rsp+8h] [rbp-20h] BYREF

optval[0] = a3;
optval[1] = a2;
if ( setsockopt(a1, 0, 35, optval, 8u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = *_errno_location();
v6 = (const char *)fh_net_ntoa(a3);
v7 = fh_log_fmt("NET> setsockopt IP_ADD_MEMBERSHIP(%s) failed on socket #%d: %d", v6, a1, v5);
fh_log("fh_mcast.c", 94LL, "NET", "ERR", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, int a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v5; // er12
const char *v6; // rax
__int64 v7; // rax
int optval[8]; // [rsp+8h] [rbp-20h] BYREF

optval[0] = a3;
optval[1] = a2;
if ( setsockopt(a1, 0, 35, optval, 8u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = *_errno_location();
v6 = (const char *)fh_net_ntoa(a3);
v7 = fh_log_fmt("NET> setsockopt IP_ADD_MEMBERSHIP(%s) failed on socket #%d: %d", v6, a1, v5);
fh_log("fh_mcast.c", 94LL, "NET", "ERR", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
FH_STATUS fh_mcast_join(int s, uint32_t ifaddr, uint32_t mcaddr)
{
    struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = mcaddr;
    mreq.imr_interface.s_addr = ifaddr;
    if (setsockopt(s, IPPROTO_IP, 35, (char *)&mreq, sizeof(mreq)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_ADD_MEMBERSHIP(%s) failed on socket #%d: %d", fh_net_ntoa(mcaddr), s, (*__errno_location ())); fh_log("fh_mcast.c", 94, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_mcast_join(int s, unsigned int ifaddr, unsigned int mcaddr)
{
    struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = mcaddr;
    mreq.imr_interface.s_addr = ifaddr;
    if (setsockopt(s, IPPROTO_IP, 35, (char *)&mreq, sizeof(mreq)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_ADD_MEMBERSHIP(%s) failed on socket #%d: %d", fh_net_ntoa(mcaddr), s, (*__errno_location ())); fh_log("fh_mcast.c", 94, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types:
mcaddr
unsigned int

variable_types: struct ip_mreq { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; }

user_defined_types: struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; }


decompiled_code:
__int64 __fastcall fh_mcast_leave(unsigned int a1, int a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v5; // er12
const char *v6; // rax
__int64 v7; // rax
int optval[8]; // [rsp+8h] [rbp-20h] BYREF

optval[0] = a3;
optval[1] = a2;
if ( setsockopt(a1, 0, 36, optval, 8u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = *_errno_location();
v6 = (const char *)fh_net_ntoa(a3);
v7 = fh_log_fmt("NET> setsockopt IP_DROP_MEMBERSHIP(%s) failed on socket #%d: %d", v6, a1, v5);
fh_log("fh_mcast.c", 115LL, "NET", "ERR", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, int a2, unsigned int a3)
{
__int64 result; // rax
unsigned int v5; // er12
const char *v6; // rax
__int64 v7; // rax
int optval[8]; // [rsp+8h] [rbp-20h] BYREF

optval[0] = a3;
optval[1] = a2;
if ( setsockopt(a1, 0, 36, optval, 8u) >= 0 )
return 0LL;
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[4] & 1) != 0 )
{
v5 = *_errno_location();
v6 = (const char *)fh_net_ntoa(a3);
v7 = fh_log_fmt("NET> setsockopt IP_DROP_MEMBERSHIP(%s) failed on socket #%d: %d", v6, a1, v5);
fh_log("fh_mcast.c", 115LL, "NET", "ERR", v7);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
FH_STATUS fh_mcast_leave(int s, uint32_t ifaddr, uint32_t mcaddr)
{
    struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = mcaddr;
    mreq.imr_interface.s_addr = ifaddr;
    if (setsockopt(s, IPPROTO_IP, 36, (char *)&mreq, sizeof(mreq)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_DROP_MEMBERSHIP(%s) failed on socket #%d: %d", fh_net_ntoa(mcaddr), s, (*__errno_location ())); fh_log("fh_mcast.c", 115, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_mcast_leave(int s, unsigned int ifaddr, unsigned int mcaddr)
{
    struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = mcaddr;
    mreq.imr_interface.s_addr = ifaddr;
    if (setsockopt(s, IPPROTO_IP, 36, (char *)&mreq, sizeof(mreq)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_DROP_MEMBERSHIP(%s) failed on socket #%d: %d", fh_net_ntoa(mcaddr), s, (*__errno_location ())); fh_log("fh_mcast.c", 115, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}


decompiled_code:
const char *__fastcall alias_find(char *s1)
{
const char *v1; // rbx
char *v2; // rbp
const char *v3; // r13

if ( alias_cnt <= 0 )
return 0LL;
v1 = alias;
v2 = &alias[144 * (alias_cnt - 1) + 144];
while ( 1 )
{
v3 = v1;
if ( !strcmp(s1, v1) )
break;
v1 += 144;
if ( v1 == v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
const char *__fastcall func0(char *s1)
{
const char *v1; // rbx
char *v2; // rbp
const char *v3; // r13

if ( alias_cnt <= 0 )
return 0LL;
v1 = alias;
v2 = &alias[144 * (alias_cnt - 1) + 144];
while ( 1 )
{
v3 = v1;
if ( !strcmp(s1, v1) )
break;
v1 += 144;
if ( v1 == v2 )
return 0LL;
}
return v3;
}

original_code:
static alias_t *alias_find(char *name)
{
    int i;
    for (i=0; i<alias_cnt; i++) {
        alias_t *a = &alias[i];
        if (strcmp(name, a->a_name) == 0) {
            return a;
        }
    }
    return ((void *)0);
}

canonical_original_code:
static struct alias_t *alias_find(char *name)
{
    int i;
    for (i=0; i<alias_cnt; i++) {
        struct alias_t *a = &alias[i];
        if (strcmp(name, a->a_name) == 0) {
            return a;
        }
    }
    return ((void *)0);
}

variable_types:
name
char *

variable_types: struct alias_t { char a_name[64]; char a_cmd[64]; int a_index; struct fh_cli_cmd { struct fh_cli_cmd_lh_t { struct fh_cli_cmd *tqh_first; struct fh_cli_cmd **tqh_last; } c_children; struct fh_cli_cmd_le_t { struct fh_cli_cmd *tqe_next; struct fh_cli_cmd **tqe_prev; } c_next; struct fh_cli_cmd *c_parent; char *c_name; unsigned short c_uniq_len; unsigned short c_len; int c_mode; char *c_help; int (*c_callback)(char *full_cmd, char **argv, int argc); struct fh_cli_cmd *c_childs; } *a_cmd_ref; } *

user_defined_types: struct alias_t { char a_name[64]; char a_cmd[64]; int a_index; struct fh_cli_cmd *a_cmd_ref; }

user_defined_types: struct fh_cli_cmd { struct fh_cli_cmd_lh_t c_children; struct fh_cli_cmd_le_t c_next; struct fh_cli_cmd *c_parent; char *c_name; unsigned short c_uniq_len; unsigned short c_len; int c_mode; char *c_help; int (*c_callback)(char *full_cmd, char **argv, int argc); struct fh_cli_cmd *c_childs; }


decompiled_code:
__int64 __fastcall alias_exec(char *a1)
{
const char *v1; // rax

v1 = alias_find(a1);
if ( !v1 )
_assert_fail("a", "fh_cli_alias.c", 0x4Du, "alias_exec");
return fh_cli_cmd_process(v1 + 64);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
const char *v1; // rax

v1 = func0(a1);
if ( !v1 )
_assert_fail("a", "fh_cli_alias.c", 0x4Du, "alias_exec");
return fh_cli_cmd_process(v1 + 64);
}

original_code:
static int alias_exec(char *full_cmd, char **argv, int argc)
{
    alias_t *a = alias_find(full_cmd);
    argv = ((void *)0);
    argc = 0;
    ((void) sizeof ((a) ? 1 : 0), __extension__ ({ if (a) ; else __assert_fail ("a", "fh_cli_alias.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    return fh_cli_cmd_process(a->a_cmd);
}

canonical_original_code:
static int alias_exec(char *full_cmd, char **argv, int argc)
{
    struct alias_t *a = alias_find(full_cmd);
    argv = ((void *)0);
    argc = 0;
    ((void) sizeof ((a) ? 1 : 0), __extension__ ({ if (a) ; else __assert_fail ("a", "fh_cli_alias.c", 77, __extension__ __PRETTY_FUNCTION__); }));
    return fh_cli_cmd_process(a->a_cmd);
}

variable_types:
argv
char **

variable_types: argc int

user_defined_types: struct fh_cli_cmd_lh_t { struct fh_cli_cmd *tqh_first; struct fh_cli_cmd **tqh_last; }

user_defined_types: struct fh_cli_cmd_le_t { struct fh_cli_cmd *tqe_next; struct fh_cli_cmd **tqe_prev; }


decompiled_code:
__int64 fh_cli_alias_size()
{
return (unsigned int)alias_cnt;
}

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

original_code:
int fh_cli_alias_size()
{
    return alias_cnt;
}


variable_types: i int


decompiled_code:
__int64 __fastcall fh_cli_alias_add(char *src, const char *a2)
{
int v2; // esi
__int64 v3; // rax
__int64 v4; // r14
char *v5; // r15
__int64 result; // rax

if ( alias_find(src) )
{
fh_cli_write("Alias already exist: %s\n", src);
result = 0xFFFFFFFFLL;
}
else
{
v2 = alias_cnt;
if ( alias_cnt > 99 )
{
fh_cli_write("Reached maximum number of aliases: %d\n", (unsigned int)alias_cnt);
result = 0xFFFFFFFFLL;
}
else
{
v3 = 144LL * alias_cnt;
*(_DWORD *)&alias[v3 + 128] = alias_cnt;
v4 = 144LL * v2;
v5 = &alias[v3];
strcpy(&alias[v3], src);
strcat(&alias[v4 + 64], a2);
*(_QWORD *)&alias[v4 + 136] = fh_cli_cmd_register(0LL, v5, 1LL, alias_exec, &alias[v4 + 64]);
++alias_cnt;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src, const char *a2)
{
int v2; // esi
__int64 v3; // rax
__int64 v4; // r14
char *v5; // r15
__int64 result; // rax

if ( func0(src) )
{
fh_cli_write("Alias already exist: %s\n", src);
result = 0xFFFFFFFFLL;
}
else
{
v2 = alias_cnt;
if ( alias_cnt > 99 )
{
fh_cli_write("Reached maximum number of aliases: %d\n", (unsigned int)alias_cnt);
result = 0xFFFFFFFFLL;
}
else
{
v3 = 144LL * alias_cnt;
*(_DWORD *)&alias[v3 + 128] = alias_cnt;
v4 = 144LL * v2;
v5 = &alias[v3];
strcpy(&alias[v3], src);
strcat(&alias[v4 + 64], a2);
*(_QWORD *)&alias[v4 + 136] = fh_cli_cmd_register(0LL, v5, 1LL, alias_exec, &alias[v4 + 64]);
++alias_cnt;
result = 0LL;
}
}
return result;
}

original_code:
int fh_cli_alias_add(char *name, char *cmd)
{
    alias_t *a = alias_find(name);
    if (a) {
        fh_cli_write("Alias already exist: %s\n", name);
        return -1;
    }
    if (alias_cnt < (100)) {
        fh_cli_cmd_t *c;
        a = &alias[alias_cnt];
        a->a_index = alias_cnt;
        strcpy(a->a_name, name);
        strcat(a->a_cmd, cmd);
        c = fh_cli_cmd_register(((void *)0), a->a_name, (1),
                                alias_exec, a->a_cmd);
        a->a_cmd_ref = c;
        alias_cnt++;
    }
    else {
        fh_cli_write("Reached maximum number of aliases: %d\n", alias_cnt);
        return -1;
    }
    return 0;
}

canonical_original_code:
int fh_cli_alias_add(char *name, char *cmd)
{
    struct alias_t *a = alias_find(name);
    if (a) {
        fh_cli_write("Alias already exist: %s\n", name);
        return -1;
    }
    if (alias_cnt < (100)) {
        struct fh_cli_cmd *c;
        a = &alias[alias_cnt];
        a->a_index = alias_cnt;
        strcpy(a->a_name, name);
        strcat(a->a_cmd, cmd);
        c = fh_cli_cmd_register(((void *)0), a->a_name, (1),
                                alias_exec, a->a_cmd);
        a->a_cmd_ref = c;
        alias_cnt++;
    }
    else {
        fh_cli_write("Reached maximum number of aliases: %d\n", alias_cnt);
        return -1;
    }
    return 0;
}

variable_types:
cmd
char *

variable_types: struct fh_cli_cmd { struct fh_cli_cmd_lh_t { struct fh_cli_cmd *tqh_first; struct fh_cli_cmd **tqh_last; } c_children; struct fh_cli_cmd_le_t { struct fh_cli_cmd *tqe_next; struct fh_cli_cmd **tqe_prev; } c_next; struct fh_cli_cmd *c_parent; char *c_name; unsigned short c_uniq_len; unsigned short c_len; int c_mode; char *c_help; int (*c_callback)(char *full_cmd, char **argv, int argc); struct fh_cli_cmd *c_childs; } *


decompiled_code:
__int64 __fastcall fh_cli_alias_del(char *a1)
{
const char *v1; // rax
__m128i *v2; // rbx
int v3; // edx
int v4; // ecx
__int64 result; // rax

v1 = alias_find(a1);
if ( v1 )
{
v2 = (__m128i *)v1;
fh_cli_cmd_unregister(*((_QWORD *)v1 + 17));
v3 = v2[8].m128i_i32[0];
v4 = alias_cnt;
if ( v3 < alias_cnt )
{
do
{
*v2 = _mm_loadu_si128(v2 + 9);
v2[1] = _mm_loadu_si128(v2 + 10);
v2[2] = _mm_loadu_si128(v2 + 11);
v2[3] = _mm_loadu_si128(v2 + 12);
v2[4] = _mm_loadu_si128(v2 + 13);
v2[5] = _mm_loadu_si128(v2 + 14);
v2[6] = _mm_loadu_si128(v2 + 15);
v2[7] = _mm_loadu_si128(v2 + 16);
v2[8] = _mm_loadu_si128(v2 + 17);
++v3;
}
while ( v3 != v4 );
}
alias_cnt = v4 - 1;
result = 0LL;
}
else
{
fh_cli_write("Alias not found: %s\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
const char *v1; // rax
__m128i *v2; // rbx
int v3; // edx
int v4; // ecx
__int64 result; // rax

v1 = func0(a1);
if ( v1 )
{
v2 = (__m128i *)v1;
fh_cli_cmd_unregister(*((_QWORD *)v1 + 17));
v3 = v2[8].m128i_i32[0];
v4 = alias_cnt;
if ( v3 < alias_cnt )
{
do
{
*v2 = _mm_loadu_si128(v2 + 9);
v2[1] = _mm_loadu_si128(v2 + 10);
v2[2] = _mm_loadu_si128(v2 + 11);
v2[3] = _mm_loadu_si128(v2 + 12);
v2[4] = _mm_loadu_si128(v2 + 13);
v2[5] = _mm_loadu_si128(v2 + 14);
v2[6] = _mm_loadu_si128(v2 + 15);
v2[7] = _mm_loadu_si128(v2 + 16);
v2[8] = _mm_loadu_si128(v2 + 17);
++v3;
}
while ( v3 != v4 );
}
alias_cnt = v4 - 1;
result = 0LL;
}
else
{
fh_cli_write("Alias not found: %s\n", a1);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int fh_cli_alias_del(char *name)
{
    alias_t *a;
    int i;
    a = alias_find(name);
    if (!a) {
        fh_cli_write("Alias not found: %s\n", name);
        return -1;
    }
    fh_cli_cmd_unregister(a->a_cmd_ref);
    for (i=a->a_index; i<alias_cnt; i++) {
        memcpy(a, a+1, sizeof(alias_t));
    }
    alias_cnt--;
    return 0;
}

canonical_original_code:
int fh_cli_alias_del(char *name)
{
    struct alias_t *a;
    int i;
    a = alias_find(name);
    if (!a) {
        fh_cli_write("Alias not found: %s\n", name);
        return -1;
    }
    fh_cli_cmd_unregister(a->a_cmd_ref);
    for (i=a->a_index; i<alias_cnt; i++) {
        memcpy(a, a+1, sizeof(alias_t));
    }
    alias_cnt--;
    return 0;
}


decompiled_code:
__int64 __fastcall opt_khash(_DWORD *a1, int a2)
{
__int64 v3; // rax

if ( a2 != 16 )
{
v3 = fh_log_fmt("assertion '%s' failed at %s:%d", "klen == sizeof(fh_opra_opt_key_t)", "fh_opra_option.c", 280LL);
fh_log("fh_opra_option.c", 280LL, 0LL, "ERR", v3);
exit(1);
}
return jhash2(a1, 4u, 0);
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, int a2)
{
__int64 v3; // rax

if ( a2 != 16 )
{
v3 = fh_log_fmt("assertion '%s' failed at %s:%d", "klen == sizeof(fh_opra_opt_key_t)", "fh_opra_option.c", 280LL);
fh_log("fh_opra_option.c", 280LL, 0LL, "ERR", v3);
exit(1);
}
return func0(a1, 4u, 0);
}

original_code:
static uint32_t opt_khash(fh_opra_opt_key_t *k, int klen)
{
    do { int nok = !(klen == sizeof(fh_opra_opt_key_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "klen == sizeof(fh_opra_opt_key_t)", "fh_opra_option.c", 280); fh_log("fh_opra_option.c", 280, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return jhash2((uint32_t*)k, (sizeof(fh_opra_opt_key_t)/sizeof(uint32_t)), 0);
}

canonical_original_code:
static unsigned int opt_khash(struct fh_opra_opt_key_t *k, int klen)
{
    do { int nok = !(klen == sizeof(fh_opra_opt_key_t)); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "klen == sizeof(fh_opra_opt_key_t)", "fh_opra_option.c", 280); fh_log("fh_opra_option.c", 280, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return jhash2((unsigned int *)k, (sizeof(fh_opra_opt_key_t)/sizeof(unsigned int)), 0);
}

variable_types: struct fh_opra_opt_key_t { char k_symbol[5]; unsigned char k_year; unsigned char k_month; unsigned char k_day; char k_putcall; char k_exchid; unsigned short k_fraction; unsigned int k_decimal; } *

variable_types: klen int

variable_types: nok int