decompiled_code:
_BOOL8 __fastcall opt_kcmp(const void *a1, const void *a2, int a3)
{
__int64 v4; // rax

if ( a3 != 16 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "klen == sizeof(fh_opra_opt_key_t)", "fh_opra_option.c", 310LL);
fh_log("fh_opra_option.c", 310LL, 0LL, "ERR", v4);
exit(1);
}
return memcmp(a1, a2, 0x10uLL) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const void *a1, const void *a2, int a3)
{
__int64 v4; // rax

if ( a3 != 16 )
{
v4 = fh_log_fmt("assertion '%s' failed at %s:%d", "klen == sizeof(fh_opra_opt_key_t)", "fh_opra_option.c", 310LL);
fh_log("fh_opra_option.c", 310LL, 0LL, "ERR", v4);
exit(1);
}
return memcmp(a1, a2, 0x10uLL) == 0;
}

original_code:
static int opt_kcmp(fh_opra_opt_key_t *key1, fh_opra_opt_key_t *key2, 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", 310); fh_log("fh_opra_option.c", 310, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return(memcmp(key1, key2, sizeof(fh_opra_opt_key_t)) == 0);
}

canonical_original_code:
static int opt_kcmp(struct fh_opra_opt_key_t *key1, struct fh_opra_opt_key_t *key2, 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", 310); fh_log("fh_opra_option.c", 310, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    return(memcmp(key1, key2, sizeof(fh_opra_opt_key_t)) == 0);
}

user_defined_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; }


repo: csinitiative/fhce

decompiled_code:
char *__fastcall opt_kdump(__int64 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", 294LL);
fh_log("fh_opra_option.c", 294LL, 0LL, "ERR", v3);
exit(1);
}
sprintf(
keystr_0,
"Option symbol: %s year: %.2u month: %.2u day: %.2u put/call: %c strike: %u.%u exch: %c",
(const char *)a1,
*(unsigned __int8 *)(a1 + 5),
*(unsigned __int8 *)(a1 + 6),
*(unsigned __int8 *)(a1 + 7),
(unsigned int)*(char *)(a1 + 8),
*(unsigned int *)(a1 + 12),
*(unsigned __int16 *)(a1 + 10),
(unsigned int)*(char *)(a1 + 9));
return keystr_0;
}

canonical_decompiled_code:
char *__fastcall func3(__int64 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", 294LL);
fh_log("fh_opra_option.c", 294LL, 0LL, "ERR", v3);
exit(1);
}
sprintf(
keystr_0,
"Option symbol: %s year: %.2u month: %.2u day: %.2u put/call: %c strike: %u.%u exch: %c",
(const char *)a1,
*(unsigned __int8 *)(a1 + 5),
*(unsigned __int8 *)(a1 + 6),
*(unsigned __int8 *)(a1 + 7),
(unsigned int)*(char *)(a1 + 8),
*(unsigned int *)(a1 + 12),
*(unsigned __int16 *)(a1 + 10),
(unsigned int)*(char *)(a1 + 9));
return keystr_0;
}

original_code:
static char *opt_kdump(fh_opra_opt_key_t *k, int klen)
{
    static char keystr[256];
    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", 294); fh_log("fh_opra_option.c", 294, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    sprintf(keystr, "Option symbol: %s year: %.2u month: %.2u day: %.2u put/call: %c "
            "strike: %u.%u exch: %c", k->k_symbol, k->k_year, k->k_month, k->k_day,
            k->k_putcall, k->k_decimal, k->k_fraction, k->k_exchid);
    return(keystr);
}

canonical_original_code:
static char *opt_kdump(struct fh_opra_opt_key_t *k, int klen)
{
    static char keystr[256];
    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", 294); fh_log("fh_opra_option.c", 294, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    sprintf(keystr, "Option symbol: %s year: %.2u month: %.2u day: %.2u put/call: %c "
            "strike: %u.%u exch: %c", k->k_symbol, k->k_year, k->k_month, k->k_day,
            k->k_putcall, k->k_decimal, k->k_fraction, k->k_exchid);
    return(keystr);
}

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:
keystr
char [256]

variable_types: nok int

return_type: char *


decompiled_code:
__int64 fh_opra_opt_init()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

if ( dword_E58 )
{
v1 = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init == 0", "fh_opra_option.c", 78LL);
fh_log("fh_opra_option.c", 78LL, 0LL, "ERR", v1);
exit(1);
}
opt_db = fh_mpool_new("OptionTable", 184LL, opra_cfg[3895], 0LL);
if ( opt_db )
{
qword_E48 = fh_ht_new(opra_cfg[3895], 0LL, odb_kops);
if ( qword_E48 )
{
if ( (fh_log_lvl[8] & 4) != 0 )
{
v4 = fh_log_fmt("Option DB initialized: size:%d key size:%d", opra_cfg[3895], 16LL);
fh_log("fh_opra_option.c", 105LL, "LH", "STATE", v4);
}
dword_E54 = opra_cfg[3895];
dword_E50 = 0;
dword_E58 = 1;
result = 0LL;
}
else
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v3 = fh_log_fmt("Failed to initialize the options H-table");
fh_log("fh_opra_option.c", 100LL, "LH", "ERR", v3);
}
fh_mpool_free(opt_db);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v2 = fh_log_fmt("Failed to initialize the options mem pool");
fh_log("fh_opra_option.c", 91LL, "LH", "ERR", v2);
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

if ( dword_E58 )
{
v1 = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init == 0", "fh_opra_option.c", 78LL);
fh_log("fh_opra_option.c", 78LL, 0LL, "ERR", v1);
exit(1);
}
opt_db = fh_mpool_new("OptionTable", 184LL, opra_cfg[3895], 0LL);
if ( opt_db )
{
qword_E48 = fh_ht_new(opra_cfg[3895], 0LL, odb_kops);
if ( qword_E48 )
{
if ( (fh_log_lvl[8] & 4) != 0 )
{
v4 = fh_log_fmt("Option DB initialized: size:%d key size:%d", opra_cfg[3895], 16LL);
fh_log("fh_opra_option.c", 105LL, "LH", "STATE", v4);
}
dword_E54 = opra_cfg[3895];
dword_E50 = 0;
dword_E58 = 1;
result = 0LL;
}
else
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v3 = fh_log_fmt("Failed to initialize the options H-table");
fh_log("fh_opra_option.c", 100LL, "LH", "ERR", v3);
}
fh_mpool_free(opt_db);
result = 0xFFFFFFFFLL;
}
}
else
{
result = 0xFFFFFFFFLL;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v2 = fh_log_fmt("Failed to initialize the options mem pool");
fh_log("fh_opra_option.c", 91LL, "LH", "ERR", v2);
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
FH_STATUS fh_opra_opt_init()
{
    do { int nok = !(odb->odb_init == 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init == 0", "fh_opra_option.c", 78); fh_log("fh_opra_option.c", 78, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    odb->odb_mpool = fh_mpool_new("OptionTable", sizeof(fh_opra_opt_t),
                                  opra_cfg.ocfg_table_size, 0);
    if (!odb->odb_mpool) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to initialize the options mem pool"); fh_log("fh_opra_option.c", 91, "LH", "ERR", _msg); } } while (0);
        return (-1);
    }
    odb->odb_htable = fh_ht_new(opra_cfg.ocfg_table_size, 0, &odb_kops);
    if (!odb->odb_htable) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to initialize the options H-table"); fh_log("fh_opra_option.c", 100, "LH", "ERR", _msg); } } while (0);
        fh_mpool_free(odb->odb_mpool);
        return (-1);
    }
    do { if ((fh_log_lvl[(2)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Option DB initialized: size:%d key size:%d", opra_cfg.ocfg_table_size, sizeof(fh_opra_opt_key_t)); fh_log("fh_opra_option.c", 105, "LH", "STATE", _msg); } } while (0);
    odb->odb_size = opra_cfg.ocfg_table_size;
    odb->odb_count = 0;
    odb->odb_init = 1;
    return (0);
}

canonical_original_code:
int fh_opra_opt_init()
{
    do { int nok = !(odb->odb_init == 0); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init == 0", "fh_opra_option.c", 78); fh_log("fh_opra_option.c", 78, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    odb->odb_mpool = fh_mpool_new("OptionTable", sizeof(fh_opra_opt_t),
                                  opra_cfg.ocfg_table_size, 0);
    if (!odb->odb_mpool) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to initialize the options mem pool"); fh_log("fh_opra_option.c", 91, "LH", "ERR", _msg); } } while (0);
        return (-1);
    }
    odb->odb_htable = fh_ht_new(opra_cfg.ocfg_table_size, 0, &odb_kops);
    if (!odb->odb_htable) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to initialize the options H-table"); fh_log("fh_opra_option.c", 100, "LH", "ERR", _msg); } } while (0);
        fh_mpool_free(odb->odb_mpool);
        return (-1);
    }
    do { if ((fh_log_lvl[(2)] & ((0x00000004)))) { char *_msg = fh_log_fmt ("Option DB initialized: size:%d key size:%d", opra_cfg.ocfg_table_size, sizeof(fh_opra_opt_key_t)); fh_log("fh_opra_option.c", 105, "LH", "STATE", _msg); } } while (0);
    odb->odb_size = opra_cfg.ocfg_table_size;
    odb->odb_count = 0;
    odb->odb_init = 1;
    return (0);
}

return_type: int


decompiled_code:
__int64 fh_opra_opt_memdump()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
int v5; // eax
__int64 v6; // rax
int v7; // eax
__int64 v8; // rax
__int64 v9; // rax
__int64 v11; // rax

if ( !dword_E58 )
{
v11 = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 122LL);
fh_log("fh_opra_option.c", 122LL, 0LL, "ERR", v11);
exit(1);
}
v0 = fh_log_fmt("--------------------------------------------------------");
fh_log("fh_opra_option.c", 124LL, 0LL, "DIAG", v0);
v1 = fh_log_fmt("> Options Database Memory footprint:");
fh_log("fh_opra_option.c", 125LL, 0LL, "DIAG", v1);
v2 = fh_log_fmt("--------------------------------------------------------");
fh_log("fh_opra_option.c", 126LL, 0LL, "DIAG", v2);
v3 = fh_log_fmt("OPTION DB number of options : %d", (unsigned int)dword_E50);
fh_log("fh_opra_option.c", 127LL, 0LL, "DIAG", v3);
v4 = fh_log_fmt(
"OPTION DB H-table usage ratio : %d / %d",
*(unsigned int *)(qword_E48 + 20),
*(unsigned int *)(qword_E48 + 16));
fh_log("fh_opra_option.c", 128LL, 0LL, "DIAG", v4);
v5 = fh_ht_memuse(qword_E48);
v6 = fh_log_fmt("OPTION DB H-table memory : %.2fK bytes", (float)((float)v5 / 1000.0));
fh_log("fh_opra_option.c", 130LL, 0LL, "DIAG", v6);
v7 = fh_mpool_memuse(opt_db);
v8 = fh_log_fmt("OPTION DB Mem pool memory : %.2fK bytes", (float)((float)v7 / 1000.0));
fh_log("fh_opra_option.c", 132LL, 0LL, "DIAG", v8);
v9 = fh_log_fmt("--------------------------------------------------------");
return fh_log("fh_opra_option.c", 134LL, 0LL, "DIAG", v9);
}

canonical_decompiled_code:
__int64 func5()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
int v5; // eax
__int64 v6; // rax
int v7; // eax
__int64 v8; // rax
__int64 v9; // rax
__int64 v11; // rax

if ( !dword_E58 )
{
v11 = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 122LL);
fh_log("fh_opra_option.c", 122LL, 0LL, "ERR", v11);
exit(1);
}
v0 = fh_log_fmt("--------------------------------------------------------");
fh_log("fh_opra_option.c", 124LL, 0LL, "DIAG", v0);
v1 = fh_log_fmt("> Options Database Memory footprint:");
fh_log("fh_opra_option.c", 125LL, 0LL, "DIAG", v1);
v2 = fh_log_fmt("--------------------------------------------------------");
fh_log("fh_opra_option.c", 126LL, 0LL, "DIAG", v2);
v3 = fh_log_fmt("OPTION DB number of options : %d", (unsigned int)dword_E50);
fh_log("fh_opra_option.c", 127LL, 0LL, "DIAG", v3);
v4 = fh_log_fmt(
"OPTION DB H-table usage ratio : %d / %d",
*(unsigned int *)(qword_E48 + 20),
*(unsigned int *)(qword_E48 + 16));
fh_log("fh_opra_option.c", 128LL, 0LL, "DIAG", v4);
v5 = fh_ht_memuse(qword_E48);
v6 = fh_log_fmt("OPTION DB H-table memory : %.2fK bytes", (float)((float)v5 / 1000.0));
fh_log("fh_opra_option.c", 130LL, 0LL, "DIAG", v6);
v7 = fh_mpool_memuse(opt_db);
v8 = fh_log_fmt("OPTION DB Mem pool memory : %.2fK bytes", (float)((float)v7 / 1000.0));
fh_log("fh_opra_option.c", 132LL, 0LL, "DIAG", v8);
v9 = fh_log_fmt("--------------------------------------------------------");
return fh_log("fh_opra_option.c", 134LL, 0LL, "DIAG", v9);
}

original_code:
void fh_opra_opt_memdump()
{
    do { int nok = !(odb->odb_init); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 122); fh_log("fh_opra_option.c", 122, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_option.c", 124, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("> Options Database Memory footprint:"); fh_log("fh_opra_option.c", 125, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_option.c", 126, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("OPTION DB number of options   : %d", odb->odb_count); fh_log("fh_opra_option.c", 127, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("OPTION DB H-table usage ratio : %d / %d", odb->odb_htable->ht_count, odb->odb_htable->ht_size); fh_log("fh_opra_option.c", 128, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("OPTION DB H-table memory      : %.2fK bytes", (float) fh_ht_memuse(odb->odb_htable)/1000); fh_log("fh_opra_option.c", 130, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("OPTION DB Mem pool memory     : %.2fK bytes", (float) fh_mpool_memuse(odb->odb_mpool)/1000); fh_log("fh_opra_option.c", 132, ((void *)0), "DIAG", _msg); } while (0);
    do { char *_msg = fh_log_fmt ("--------------------------------------------------------"); fh_log("fh_opra_option.c", 134, ((void *)0), "DIAG", _msg); } while (0);
}

return_type: void


decompiled_code:
__int64 __fastcall fh_opra_opt_add(const __m128i *a1, __m128i **a2)
{
__m128i *v2; // rax
__m128i *v3; // rbp
const char *v4; // r14
unsigned int v5; // er12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
char *v17; // rax
__int64 v18; // rax
unsigned int v19; // eax
char *v20; // rax
__int64 v21; // rax
char *v22; // rax
__int64 v23; // rax
__int64 v24; // rsi
__int64 v25; // rax
__int64 v26; // rax
__int64 v27[6]; // [rsp+8h] [rbp-30h] BYREF

v27[0] = 0LL;
if ( !dword_E58 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 148LL);
fh_log("fh_opra_option.c", 148LL, 0LL, "ERR", v7);
exit(1);
}
if ( (fh_log_lvl[8] & 0x20) != 0 )
{
v8 = fh_log_fmt(" > Option Symbol : %s", a1->m128i_i8);
fh_log("fh_opra_option.c", 151LL, 0LL, "INFO", v8);
v9 = fh_log_fmt(" > Expiration Year : %.2u", a1->m128i_u8[5]);
fh_log("fh_opra_option.c", 152LL, 0LL, "INFO", v9);
v10 = fh_log_fmt(" > Expiration Month : %.2u", a1->m128i_u8[6]);
fh_log("fh_opra_option.c", 153LL, 0LL, "INFO", v10);
v11 = fh_log_fmt(" > Expiration Day : %.2u", a1->m128i_u8[7]);
fh_log("fh_opra_option.c", 154LL, 0LL, "INFO", v11);
v12 = fh_log_fmt(" > Put/Call : %c", (unsigned int)a1->m128i_i8[8]);
fh_log("fh_opra_option.c", 155LL, 0LL, "INFO", v12);
v13 = fh_log_fmt(" > Strike Price : %u.%u", a1->m128i_u32[3], a1->m128i_u16[5]);
fh_log("fh_opra_option.c", 156LL, 0LL, "INFO", v13);
v14 = fh_log_fmt(" > Exchange Code : %c", (unsigned int)a1->m128i_i8[9]);
fh_log("fh_opra_option.c", 157LL, 0LL, "INFO", v14);
}
if ( (unsigned int)fh_opra_lo_lookup(a1, v27) )
{
v5 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v15 = fh_log_fmt("Failed to get a new options entry");
fh_log("fh_opra_option.c", 165LL, "LH", "ERR", v15);
}
}
else
{
v2 = (__m128i *)fh_mpool_get(opt_db);
v3 = v2;
if ( v2 )
{
v2[3] = _mm_loadu_si128(a1);
v4 = v2[1].m128i_i8;
v5 = fh_opra_topic_fmt(&opra_cfg[740], a1, &v2[1], 32LL);
if ( v5 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v17 = opt_kdump((__int64)a1, 16);
v18 = fh_log_fmt("Failed to format the topic for sec:%s k:%s", (const char *)(v27[0] + 7), v17);
fh_log("fh_opra_option.c", 188LL, "LH", "ERR", v18);
}
LABEL_9:
fh_mpool_put(opt_db, v3);
return v5;
}
v3[4].m128i_i64[0] = v27[0];
v19 = fh_ht_put(qword_E48, &v3[3], 16LL, v3);
v5 = v19;
if ( v19 == 2 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v20 = opt_kdump((__int64)a1, 16);
v21 = fh_log_fmt("Duplicate option in DB: '%s'", v20);
fh_log("fh_opra_option.c", 204LL, "LH", "ERR", v21);
}
goto LABEL_9;
}
if ( v19 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v22 = opt_kdump((__int64)a1, 16);
v23 = fh_log_fmt("Failed to add option to DB (size:%d)", v22);
fh_log("fh_opra_option.c", 211LL, "LH", "ERR", v23);
}
goto LABEL_9;
}
fh_opra_lh_add_opt(fh_opra_lh_line_num, v3);
if ( (unsigned int)fh_opra_ml_opt_add(v3) && (fh_log_lvl[8] & 1) != 0 )
{
v26 = fh_log_fmt("Failed to add option to message layer: %s", v4);
fh_log("fh_opra_option.c", 228LL, "LH", "ERR", v26);
}
*a2 = v3;
v24 = (unsigned int)(dword_E50 + 1);
dword_E50 = v24;
if ( 10 * (int)v24 > (unsigned int)(9 * dword_E54) && (_DWORD)v24 == 10000 * ((unsigned int)v24 / 0x2710) )
{
v25 = fh_log_fmt(
"Option Table size over %.2f %% utilization (count: %d)",
(float)((float)((float)(int)v24 * 100.0) / (float)dword_E54),
v24);
fh_log("fh_opra_option.c", 240LL, 0LL, "WARN", v25);
}
}
else
{
v5 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v16 = fh_log_fmt("Failed to get a new options entry");
fh_log("fh_opra_option.c", 174LL, "LH", "ERR", v16);
}
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(const __m128i *a1, __m128i **a2)
{
__m128i *v2; // rax
__m128i *v3; // rbp
const char *v4; // r14
unsigned int v5; // er12
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rax
__int64 v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
char *v17; // rax
__int64 v18; // rax
unsigned int v19; // eax
char *v20; // rax
__int64 v21; // rax
char *v22; // rax
__int64 v23; // rax
__int64 v24; // rsi
__int64 v25; // rax
__int64 v26; // rax
__int64 v27[6]; // [rsp+8h] [rbp-30h] BYREF

v27[0] = 0LL;
if ( !dword_E58 )
{
v7 = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 148LL);
fh_log("fh_opra_option.c", 148LL, 0LL, "ERR", v7);
exit(1);
}
if ( (fh_log_lvl[8] & 0x20) != 0 )
{
v8 = fh_log_fmt(" > Option Symbol : %s", a1->m128i_i8);
fh_log("fh_opra_option.c", 151LL, 0LL, "INFO", v8);
v9 = fh_log_fmt(" > Expiration Year : %.2u", a1->m128i_u8[5]);
fh_log("fh_opra_option.c", 152LL, 0LL, "INFO", v9);
v10 = fh_log_fmt(" > Expiration Month : %.2u", a1->m128i_u8[6]);
fh_log("fh_opra_option.c", 153LL, 0LL, "INFO", v10);
v11 = fh_log_fmt(" > Expiration Day : %.2u", a1->m128i_u8[7]);
fh_log("fh_opra_option.c", 154LL, 0LL, "INFO", v11);
v12 = fh_log_fmt(" > Put/Call : %c", (unsigned int)a1->m128i_i8[8]);
fh_log("fh_opra_option.c", 155LL, 0LL, "INFO", v12);
v13 = fh_log_fmt(" > Strike Price : %u.%u", a1->m128i_u32[3], a1->m128i_u16[5]);
fh_log("fh_opra_option.c", 156LL, 0LL, "INFO", v13);
v14 = fh_log_fmt(" > Exchange Code : %c", (unsigned int)a1->m128i_i8[9]);
fh_log("fh_opra_option.c", 157LL, 0LL, "INFO", v14);
}
if ( (unsigned int)fh_opra_lo_lookup(a1, v27) )
{
v5 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v15 = fh_log_fmt("Failed to get a new options entry");
fh_log("fh_opra_option.c", 165LL, "LH", "ERR", v15);
}
}
else
{
v2 = (__m128i *)fh_mpool_get(opt_db);
v3 = v2;
if ( v2 )
{
v2[3] = _mm_loadu_si128(a1);
v4 = v2[1].m128i_i8;
v5 = fh_opra_topic_fmt(&opra_cfg[740], a1, &v2[1], 32LL);
if ( v5 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v17 = func3((__int64)a1, 16);
v18 = fh_log_fmt("Failed to format the topic for sec:%s k:%s", (const char *)(v27[0] + 7), v17);
fh_log("fh_opra_option.c", 188LL, "LH", "ERR", v18);
}
LABEL_9:
fh_mpool_put(opt_db, v3);
return v5;
}
v3[4].m128i_i64[0] = v27[0];
v19 = fh_ht_put(qword_E48, &v3[3], 16LL, v3);
v5 = v19;
if ( v19 == 2 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v20 = func3((__int64)a1, 16);
v21 = fh_log_fmt("Duplicate option in DB: '%s'", v20);
fh_log("fh_opra_option.c", 204LL, "LH", "ERR", v21);
}
goto LABEL_9;
}
if ( v19 )
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v22 = func3((__int64)a1, 16);
v23 = fh_log_fmt("Failed to add option to DB (size:%d)", v22);
fh_log("fh_opra_option.c", 211LL, "LH", "ERR", v23);
}
goto LABEL_9;
}
fh_opra_lh_add_opt(fh_opra_lh_line_num, v3);
if ( (unsigned int)fh_opra_ml_opt_add(v3) && (fh_log_lvl[8] & 1) != 0 )
{
v26 = fh_log_fmt("Failed to add option to message layer: %s", v4);
fh_log("fh_opra_option.c", 228LL, "LH", "ERR", v26);
}
*a2 = v3;
v24 = (unsigned int)(dword_E50 + 1);
dword_E50 = v24;
if ( 10 * (int)v24 > (unsigned int)(9 * dword_E54) && (_DWORD)v24 == 10000 * ((unsigned int)v24 / 0x2710) )
{
v25 = fh_log_fmt(
"Option Table size over %.2f %% utilization (count: %d)",
(float)((float)((float)(int)v24 * 100.0) / (float)dword_E54),
v24);
fh_log("fh_opra_option.c", 240LL, 0LL, "WARN", v25);
}
}
else
{
v5 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v16 = fh_log_fmt("Failed to get a new options entry");
fh_log("fh_opra_option.c", 174LL, "LH", "ERR", v16);
}
}
}
return v5;
}

original_code:
FH_STATUS fh_opra_opt_add(fh_opra_opt_key_t *k, fh_opra_opt_t **optp)
{
    fh_opra_opt_t *opt = ((void *)0);
    FH_STATUS rc;
    fh_opra_lo_t *lo = ((void *)0);
    do { int nok = !(odb->odb_init); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 148); fh_log("fh_opra_option.c", 148, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if ((fh_log_lvl[(2)] & ((0x00000020)))) {
        do { char *_msg = fh_log_fmt (" > Option Symbol     : %s", k->k_symbol); fh_log("fh_opra_option.c", 151, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Expiration Year   : %.2u", k->k_year); fh_log("fh_opra_option.c", 152, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Expiration Month  : %.2u", k->k_month); fh_log("fh_opra_option.c", 153, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Expiration Day    : %.2u", k->k_day); fh_log("fh_opra_option.c", 154, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Put/Call          : %c", k->k_putcall); fh_log("fh_opra_option.c", 155, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Strike Price      : %u.%u", k->k_decimal, k->k_fraction); fh_log("fh_opra_option.c", 156, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Exchange Code     : %c", k->k_exchid); fh_log("fh_opra_option.c", 157, ((void *)0), "INFO", _msg); } while (0);
    }
    rc = fh_opra_lo_lookup(k->k_symbol, &lo);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to get a new options entry"); fh_log("fh_opra_option.c", 165, "LH", "ERR", _msg); } } while (0);
        return (-1);
    }
    opt = (fh_opra_opt_t *) fh_mpool_get(odb->odb_mpool);
    if (!opt) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to get a new options entry"); fh_log("fh_opra_option.c", 174, "LH", "ERR", _msg); } } while (0);
        return (-1);
    }
    memcpy(&opt->opt_key, k, sizeof(fh_opra_opt_key_t));
    rc = fh_opra_topic_fmt(&opra_cfg.ocfg_topic_fmt, k, opt->opt_topic, sizeof(opt->opt_topic));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to format the topic for sec:%s k:%s", lo->lo_sec, opt_kdump(k, sizeof(fh_opra_opt_key_t))); fh_log("fh_opra_option.c", 188, "LH", "ERR", _msg); } } while (0);
        fh_mpool_put(odb->odb_mpool, opt);
        return rc;
    }
    opt->opt_lo = lo;
    rc = fh_ht_put(odb->odb_htable, &opt->opt_key, sizeof(fh_opra_opt_key_t), opt);
    if (rc == (2)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Duplicate option in DB: '%s'", opt_kdump(k, sizeof(fh_opra_opt_key_t))); fh_log("fh_opra_option.c", 204, "LH", "ERR", _msg); } } while (0);
        fh_mpool_put(odb->odb_mpool, opt);
        return rc;
    }
    if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to add option to DB (size:%d)", opt_kdump(k, sizeof(fh_opra_opt_key_t)), odb->odb_count); fh_log("fh_opra_option.c", 211, "LH", "ERR", _msg); } } while (0);
        fh_mpool_put(odb->odb_mpool, opt);
        return rc;
    }
    fh_opra_lh_add_opt(fh_opra_lh_line_num, opt);
    rc = fh_opra_ml_opt_add(opt);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to add option to message layer: %s", opt->opt_topic); fh_log("fh_opra_option.c", 228, "LH", "ERR", _msg); } } while (0);
    }
    *optp = opt;
    odb->odb_count++;
    if ((10 * odb->odb_count > 9 * odb->odb_size) && (odb->odb_count % 10000) == 0) {
        do { char *_msg = fh_log_fmt ("Option Table size over %.2f %% utilization (count: %d)", (float) odb->odb_count * 100 / odb->odb_size, odb->odb_count); fh_log("fh_opra_option.c", 240, ((void *)0), "WARN", _msg); } while (0);
    }
    return (0);
}

canonical_original_code:
int fh_opra_opt_add(struct fh_opra_opt_key_t *k, struct fh_opra_opt **optp)
{
    struct fh_opra_opt *opt = ((void *)0);
    int rc;
    struct fh_opra_lo_t *lo = ((void *)0);
    do { int nok = !(odb->odb_init); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 148); fh_log("fh_opra_option.c", 148, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    if ((fh_log_lvl[(2)] & ((0x00000020)))) {
        do { char *_msg = fh_log_fmt (" > Option Symbol     : %s", k->k_symbol); fh_log("fh_opra_option.c", 151, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Expiration Year   : %.2u", k->k_year); fh_log("fh_opra_option.c", 152, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Expiration Month  : %.2u", k->k_month); fh_log("fh_opra_option.c", 153, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Expiration Day    : %.2u", k->k_day); fh_log("fh_opra_option.c", 154, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Put/Call          : %c", k->k_putcall); fh_log("fh_opra_option.c", 155, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Strike Price      : %u.%u", k->k_decimal, k->k_fraction); fh_log("fh_opra_option.c", 156, ((void *)0), "INFO", _msg); } while (0);
        do { char *_msg = fh_log_fmt (" > Exchange Code     : %c", k->k_exchid); fh_log("fh_opra_option.c", 157, ((void *)0), "INFO", _msg); } while (0);
    }
    rc = fh_opra_lo_lookup(k->k_symbol, &lo);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to get a new options entry"); fh_log("fh_opra_option.c", 165, "LH", "ERR", _msg); } } while (0);
        return (-1);
    }
    opt = (struct fh_opra_opt *) fh_mpool_get(odb->odb_mpool);
    if (!opt) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to get a new options entry"); fh_log("fh_opra_option.c", 174, "LH", "ERR", _msg); } } while (0);
        return (-1);
    }
    memcpy(&opt->opt_key, k, sizeof(fh_opra_opt_key_t));
    rc = fh_opra_topic_fmt(&opra_cfg.ocfg_topic_fmt, k, opt->opt_topic, sizeof(opt->opt_topic));
    if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to format the topic for sec:%s k:%s", lo->lo_sec, opt_kdump(k, sizeof(fh_opra_opt_key_t))); fh_log("fh_opra_option.c", 188, "LH", "ERR", _msg); } } while (0);
        fh_mpool_put(odb->odb_mpool, opt);
        return rc;
    }
    opt->opt_lo = lo;
    rc = fh_ht_put(odb->odb_htable, &opt->opt_key, sizeof(fh_opra_opt_key_t), opt);
    if (rc == (2)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Duplicate option in DB: '%s'", opt_kdump(k, sizeof(fh_opra_opt_key_t))); fh_log("fh_opra_option.c", 204, "LH", "ERR", _msg); } } while (0);
        fh_mpool_put(odb->odb_mpool, opt);
        return rc;
    }
    if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to add option to DB (size:%d)", opt_kdump(k, sizeof(fh_opra_opt_key_t)), odb->odb_count); fh_log("fh_opra_option.c", 211, "LH", "ERR", _msg); } } while (0);
        fh_mpool_put(odb->odb_mpool, opt);
        return rc;
    }
    fh_opra_lh_add_opt(fh_opra_lh_line_num, opt);
    rc = fh_opra_ml_opt_add(opt);
    if (rc != (0)) {
        do { if ((fh_log_lvl[(2)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Failed to add option to message layer: %s", opt->opt_topic); fh_log("fh_opra_option.c", 228, "LH", "ERR", _msg); } } while (0);
    }
    *optp = opt;
    odb->odb_count++;
    if ((10 * odb->odb_count > 9 * odb->odb_size) && (odb->odb_count % 10000) == 0) {
        do { char *_msg = fh_log_fmt ("Option Table size over %.2f %% utilization (count: %d)", (float) odb->odb_count * 100 / odb->odb_size, odb->odb_count); fh_log("fh_opra_option.c", 240, ((void *)0), "WARN", _msg); } while (0);
    }
    return (0);
}

variable_types: 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 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; } **

variable_types: 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; } *

variable_types: rc int

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_opra_opt_lookup(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = 0LL;
if ( !dword_E58 )
{
v3 = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 258LL);
fh_log("fh_opra_option.c", 258LL, 0LL, "ERR", v3);
exit(1);
}
result = fh_ht_get(qword_E48, a1, 16LL, &v4);
if ( !(_DWORD)result )
*a2 = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = 0LL;
if ( !dword_E58 )
{
v3 = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 258LL);
fh_log("fh_opra_option.c", 258LL, 0LL, "ERR", v3);
exit(1);
}
result = fh_ht_get(qword_E48, a1, 16LL, &v4);
if ( !(_DWORD)result )
*a2 = v4;
return result;
}

original_code:
FH_STATUS fh_opra_opt_lookup(fh_opra_opt_key_t *k, fh_opra_opt_t **optp)
{
    FH_STATUS rc;
    void *val = ((void *)0);
    do { int nok = !(odb->odb_init); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 258); fh_log("fh_opra_option.c", 258, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_ht_get(odb->odb_htable, k, sizeof(fh_opra_opt_key_t), &val);
    if (rc != (0)) {
        return rc;
    }
    *optp = (fh_opra_opt_t *) val;
    return (0);
}

canonical_original_code:
int fh_opra_opt_lookup(struct fh_opra_opt_key_t *k, struct fh_opra_opt **optp)
{
    int rc;
    void *val = ((void *)0);
    do { int nok = !(odb->odb_init); if (nok) { char *_msg = fh_log_fmt("assertion '%s' failed at %s:%d", "odb->odb_init", "fh_opra_option.c", 258); fh_log("fh_opra_option.c", 258, ((void *)0), "ERR", _msg); exit(1); } } while (0);
    rc = fh_ht_get(odb->odb_htable, k, sizeof(fh_opra_opt_key_t), &val);
    if (rc != (0)) {
        return rc;
    }
    *optp = (struct fh_opra_opt *) val;
    return (0);
}

variable_types:
val
void *

user_defined_types: struct fh_opra_opt_le_t { struct fh_opra_opt *tqe_next; struct fh_opra_opt **tqe_prev; }

user_defined_types: union opra_exp_date_t { char exp_year_v1; struct { char exp_year[2]; char exp_date[2]; } exp_date_v2; }

user_defined_types: struct fh_opra_lo_t { char lo_root[-1]; char lo_sec[-1]; }


getstatus

decompiled_code:
__int64 *getstatus()
{
if ( !(_DWORD)qword_778 )
LODWORD(qword_778) = fh_shr_tcp_lh_get_tid();
return &proc_info;
}

canonical_decompiled_code:
__int64 *func0()
{
if ( !(_DWORD)qword_778 )
LODWORD(qword_778) = fh_shr_tcp_lh_get_tid();
return &proc_info;
}

original_code:
fh_info_proc_t *getstatus()
{
    if (proc_info.tid <= 0) {
        proc_info.tid = fh_shr_tcp_lh_get_tid();
    }
    return &proc_info;
}

canonical_original_code:
struct fh_info_proc *getstatus()
{
    if (proc_info.tid <= 0) {
        proc_info.tid = fh_shr_tcp_lh_get_tid();
    }
    return &proc_info;
}

return_type: struct fh_info_proc { unsigned int pid; unsigned int cpu; unsigned int tid; unsigned int start_time; } *


decompiled_code:
__int64 fh_shr_tcp_exit()
{
fh_shr_mgmt_exit();
return fh_shr_tcp_lh_exit();
}

canonical_decompiled_code:
__int64 func1()
{
fh_shr_mgmt_exit();
return fh_shr_tcp_lh_exit();
}

original_code:
void fh_shr_tcp_exit()
{
    fh_shr_mgmt_exit();
    fh_shr_tcp_lh_exit();
}


decompiled_code:
void __fastcall fh_tcp_sig_handle(int a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax

if ( a1 == 13 )
{
if ( (fh_log_lvl[12] & 2) != 0 )
{
v4 = fh_log_fmt("SIGPIPE caught - exiting -");
fh_log("fh_shr_tcp.c", 94LL, "MGMT", "WARN", v4);
}
}
else if ( a1 > 13 )
{
if ( a1 != 15 )
{
LABEL_15:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v5 = fh_log_fmt("Unhandled Signal received: %d", (unsigned int)a1);
fh_log("fh_shr_tcp.c", 98LL, "MGMT", "WARN", v5);
}
goto LABEL_10;
}
if ( (fh_log_lvl[12] & 2) != 0 )
{
v2 = fh_log_fmt("SIGTERM caught - exiting - ");
fh_log("fh_shr_tcp.c", 82LL, "MGMT", "WARN", v2);
}
}
else
{
if ( a1 != 1 )
{
if ( a1 == 2 )
{
if ( (fh_log_lvl[12] & 2) != 0 )
{
v1 = fh_log_fmt("SIGINT caught - exiting - ");
fh_log("fh_shr_tcp.c", 90LL, "MGMT", "WARN", v1);
}
goto LABEL_10;
}
goto LABEL_15;
}
if ( (fh_log_lvl[12] & 2) != 0 )
{
v3 = fh_log_fmt("SIGHUP caught - exiting - ");
fh_log("fh_shr_tcp.c", 86LL, "MGMT", "WARN", v3);
}
}
LABEL_10:
fh_shr_tcp_exit();
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax

if ( a1 == 13 )
{
if ( (fh_log_lvl[12] & 2) != 0 )
{
v4 = fh_log_fmt("SIGPIPE caught - exiting -");
fh_log("fh_shr_tcp.c", 94LL, "MGMT", "WARN", v4);
}
}
else if ( a1 > 13 )
{
if ( a1 != 15 )
{
LABEL_15:
if ( (fh_log_lvl[12] & 2) != 0 )
{
v5 = fh_log_fmt("Unhandled Signal received: %d", (unsigned int)a1);
fh_log("fh_shr_tcp.c", 98LL, "MGMT", "WARN", v5);
}
goto LABEL_10;
}
if ( (fh_log_lvl[12] & 2) != 0 )
{
v2 = fh_log_fmt("SIGTERM caught - exiting - ");
fh_log("fh_shr_tcp.c", 82LL, "MGMT", "WARN", v2);
}
}
else
{
if ( a1 != 1 )
{
if ( a1 == 2 )
{
if ( (fh_log_lvl[12] & 2) != 0 )
{
v1 = fh_log_fmt("SIGINT caught - exiting - ");
fh_log("fh_shr_tcp.c", 90LL, "MGMT", "WARN", v1);
}
goto LABEL_10;
}
goto LABEL_15;
}
if ( (fh_log_lvl[12] & 2) != 0 )
{
v3 = fh_log_fmt("SIGHUP caught - exiting - ");
fh_log("fh_shr_tcp.c", 86LL, "MGMT", "WARN", v3);
}
}
LABEL_10:
func1();
}

original_code:
static void fh_tcp_sig_handle(int32_t signo)
{
    switch (signo) {
    case 15:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGTERM caught - exiting - "); fh_log("fh_shr_tcp.c", 82, "MGMT", "WARN", _msg); } } while (0);
        break;
    case 1:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGHUP caught - exiting - "); fh_log("fh_shr_tcp.c", 86, "MGMT", "WARN", _msg); } } while (0);
        break;
    case 2:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGINT caught - exiting - "); fh_log("fh_shr_tcp.c", 90, "MGMT", "WARN", _msg); } } while (0);
        break;
    case 13:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGPIPE caught - exiting -"); fh_log("fh_shr_tcp.c", 94, "MGMT", "WARN", _msg); } } while (0);
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Unhandled Signal received: %d", signo); fh_log("fh_shr_tcp.c", 98, "MGMT", "WARN", _msg); } } while (0);
    }
    fh_shr_tcp_exit();
}

canonical_original_code:
static void fh_tcp_sig_handle(int signo)
{
    switch (signo) {
    case 15:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGTERM caught - exiting - "); fh_log("fh_shr_tcp.c", 82, "MGMT", "WARN", _msg); } } while (0);
        break;
    case 1:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGHUP caught - exiting - "); fh_log("fh_shr_tcp.c", 86, "MGMT", "WARN", _msg); } } while (0);
        break;
    case 2:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGINT caught - exiting - "); fh_log("fh_shr_tcp.c", 90, "MGMT", "WARN", _msg); } } while (0);
        break;
    case 13:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("SIGPIPE caught - exiting -"); fh_log("fh_shr_tcp.c", 94, "MGMT", "WARN", _msg); } } while (0);
        break;
    default:
        do { if ((fh_log_lvl[(3)] & ((0x00000002)))) { char *_msg = fh_log_fmt ("Unhandled Signal received: %d", signo); fh_log("fh_shr_tcp.c", 98, "MGMT", "WARN", _msg); } } while (0);
    }
    fh_shr_tcp_exit();
}

variable_types: signo int


decompiled_code:
__sighandler_t fh_shr_tcp_sig_init()
{
__sighandler_t result; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

if ( signal(2, fh_tcp_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v1 = fh_log_fmt("Init for SIGINT failed");
fh_log("fh_shr_tcp.c", 114LL, "MGMT", "ERR", v1);
}
if ( signal(1, fh_tcp_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v2 = fh_log_fmt("Init for SIGHUP failed");
fh_log("fh_shr_tcp.c", 118LL, "MGMT", "ERR", v2);
}
if ( signal(15, fh_tcp_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v3 = fh_log_fmt("Init for SIGTERM failed");
fh_log("fh_shr_tcp.c", 122LL, "MGMT", "ERR", v3);
}
result = signal(13, fh_tcp_sig_handle);
if ( result == (__sighandler_t)-1LL )
{
result = (__sighandler_t)fh_log_lvl;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = fh_log_fmt("Init for SIGPIPE failed");
result = (__sighandler_t)fh_log("fh_shr_tcp.c", 126LL, "MGMT", "ERR", v4);
}
}
return result;
}

canonical_decompiled_code:
__sighandler_t func3()
{
__sighandler_t result; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax

if ( signal(2, fh_tcp_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v1 = fh_log_fmt("Init for SIGINT failed");
fh_log("fh_shr_tcp.c", 114LL, "MGMT", "ERR", v1);
}
if ( signal(1, fh_tcp_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v2 = fh_log_fmt("Init for SIGHUP failed");
fh_log("fh_shr_tcp.c", 118LL, "MGMT", "ERR", v2);
}
if ( signal(15, fh_tcp_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[12] & 1) != 0 )
{
v3 = fh_log_fmt("Init for SIGTERM failed");
fh_log("fh_shr_tcp.c", 122LL, "MGMT", "ERR", v3);
}
result = signal(13, fh_tcp_sig_handle);
if ( result == (__sighandler_t)-1LL )
{
result = (__sighandler_t)fh_log_lvl;
if ( (fh_log_lvl[12] & 1) != 0 )
{
v4 = fh_log_fmt("Init for SIGPIPE failed");
result = (__sighandler_t)fh_log("fh_shr_tcp.c", 126LL, "MGMT", "ERR", v4);
}
}
return result;
}

original_code:
static void fh_shr_tcp_sig_init()
{
    if (signal(2, fh_tcp_sig_handle) == ((__sighandler_t) -1)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Init for SIGINT failed"); fh_log("fh_shr_tcp.c", 114, "MGMT", "ERR", _msg); } } while (0);
    }
    if (signal(1, fh_tcp_sig_handle) == ((__sighandler_t) -1)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Init for SIGHUP failed"); fh_log("fh_shr_tcp.c", 118, "MGMT", "ERR", _msg); } } while (0);
    }
    if (signal(15, fh_tcp_sig_handle) == ((__sighandler_t) -1)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Init for SIGTERM failed"); fh_log("fh_shr_tcp.c", 122, "MGMT", "ERR", _msg); } } while (0);
    }
    if (signal(13, fh_tcp_sig_handle) == ((__sighandler_t) -1)) {
        do { if ((fh_log_lvl[(3)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("Init for SIGPIPE failed"); fh_log("fh_shr_tcp.c", 126, "MGMT", "ERR", _msg); } } while (0);
    }
}


decompiled_code:
__int64 __fastcall fh_shr_tcp_version(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = fh_info_version_msg();
if ( *(_DWORD *)(a2 + 8) )
exit(0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax

result = fh_info_version_msg();
if ( *(_DWORD *)(a2 + 8) )
exit(0);
return result;
}

original_code:
void fh_shr_tcp_version(const fh_info_build_t *info, fh_shr_cfg_options_t *options)
{
    fh_info_version_msg(info);
    if (options->display_version) {
        exit(0);
    }
}

canonical_original_code:
void fh_shr_tcp_version(struct fh_info_build *info, struct fh_shr_cfg_options_t *options)
{
    fh_info_version_msg(info);
    if (options->display_version) {
        exit(0);
    }
}

variable_types: struct fh_info_build { char *name; int version; char *build_user; char *build_host; char *build_arch; char *build_kernel; char *build_date; char *build_svn_url; char *build_svn_rev; } *

variable_types: struct fh_shr_cfg_options_t { int standalone; int debug_level; int display_version; int version; char process[255]; char logging_tag[255]; char config_file[-1]; char plugin_path[-1]; char *program_name; } *


decompiled_code:
__int64 __fastcall fh_shr_tcp_main(unsigned int a1, __int64 a2, __int64 a3, _QWORD *a4, __int64 *a5)
{
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rbp
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15[4]; // [rsp+0h] [rbp-25C8h] BYREF
__int64 v16[6]; // [rsp+20h] [rbp-25A8h] BYREF
char v17[256]; // [rsp+50h] [rbp-2578h] BYREF
int v18; // [rsp+150h] [rbp-2478h]
int v19[4]; // [rsp+380h] [rbp-2248h] BYREF
char v20[510]; // [rsp+390h] [rbp-2238h] BYREF
char v21[4097]; // [rsp+58Eh] [rbp-203Ah] BYREF
char v22[4153]; // [rsp+158Fh] [rbp-1039h] BYREF

v16[0] = (__int64)fh_shr_tcp_exit;
v16[1] = (__int64)&fh_shr_tcp_lh_get_stats;
v16[2] = (__int64)&fh_shr_tcp_lh_clear_stats;
v16[3] = (__int64)&fh_shr_tcp_lh_snap_stats;
v16[4] = (__int64)&fh_shr_tcp_lh_latency;
v16[5] = (__int64)getstatus;
v15[0] = *a5;
v15[1] = a5[1];
v15[2] = a5[2];
v15[3] = a5[3];
fh_shr_cfg_set_defaults(v19, *a4, *((unsigned int *)a4 + 2));
fh_shr_cfg_cmd_parse(a1, a2, *a4, v19);
if ( !v19[1] )
fh_daemonize();
v7 = fh_cfg_load(v21);
v8 = v7;
if ( !v7 )
{
fprintf(stderr, "ERROR: loading confguration file: %s\n", v21);
exit(1);
}
if ( (unsigned int)fh_shr_cfg_log_init(v19, v7) )
{
fwrite("ERROR: initializing logging configuration\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
fh_plugin_load(v22);
if ( (unsigned int)fh_shr_cfg_lh_get_proc(v20, a3, v8) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v11 = fh_log_fmt("invalid process specified or no default process available");
fh_log("fh_shr_tcp.c", 212LL, "CSI", "ERR", v11);
}
exit(1);
}
if ( (unsigned int)fh_shr_cfg_tcp_lh_load(v20, v8, v17) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v12 = fh_log_fmt("unable to parse configuration into line handler process configuration");
fh_log("fh_shr_tcp.c", 221LL, "CSI", "ERR", v12);
}
exit(1);
}
fh_cfg_free(v8);
fh_shr_tcp_version((__int64)a4, (__int64)v19);
fh_shr_tcp_sig_init();
v9 = fh_util_thread_name("Main", v20);
fh_log_thread_start(v9);
if ( (unsigned int)fh_shr_mgmt_start((unsigned int)v19[0], a4, v20, v16) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v13 = fh_log_fmt("error starting management thread for '%s'", v20);
fh_log("fh_shr_tcp.c", 248LL, "CSI", "ERR", v13);
}
exit(1);
}
proc_info = 0LL;
qword_778 = 0LL;
LODWORD(proc_info) = getpid();
LODWORD(qword_778) = fh_shr_tcp_lh_get_tid();
HIDWORD(proc_info) = v18;
HIDWORD(qword_778) = time(0LL);
if ( (unsigned int)fh_shr_tcp_lh_start(a4, v17, v15) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v14 = fh_log_fmt("error starting line handler thread for '%s'", v20);
fh_log("fh_shr_tcp.c", 262LL, "CSI", "ERR", v14);
}
exit(1);
}
fh_shr_mgmt_wait();
fh_shr_tcp_lh_wait();
fh_log_thread_stop(v9);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2, __int64 a3, _QWORD *a4, __int64 *a5)
{
__int64 v7; // rax
__int64 v8; // rbp
__int64 v9; // rbp
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15[4]; // [rsp+0h] [rbp-25C8h] BYREF
__int64 v16[6]; // [rsp+20h] [rbp-25A8h] BYREF
char v17[256]; // [rsp+50h] [rbp-2578h] BYREF
int v18; // [rsp+150h] [rbp-2478h]
int v19[4]; // [rsp+380h] [rbp-2248h] BYREF
char v20[510]; // [rsp+390h] [rbp-2238h] BYREF
char v21[4097]; // [rsp+58Eh] [rbp-203Ah] BYREF
char v22[4153]; // [rsp+158Fh] [rbp-1039h] BYREF

v16[0] = (__int64)fh_shr_tcp_exit;
v16[1] = (__int64)&fh_shr_tcp_lh_get_stats;
v16[2] = (__int64)&fh_shr_tcp_lh_clear_stats;
v16[3] = (__int64)&fh_shr_tcp_lh_snap_stats;
v16[4] = (__int64)&fh_shr_tcp_lh_latency;
v16[5] = (__int64)getstatus;
v15[0] = *a5;
v15[1] = a5[1];
v15[2] = a5[2];
v15[3] = a5[3];
fh_shr_cfg_set_defaults(v19, *a4, *((unsigned int *)a4 + 2));
fh_shr_cfg_cmd_parse(a1, a2, *a4, v19);
if ( !v19[1] )
fh_daemonize();
v7 = fh_cfg_load(v21);
v8 = v7;
if ( !v7 )
{
fprintf(stderr, "ERROR: loading confguration file: %s\n", v21);
exit(1);
}
if ( (unsigned int)fh_shr_cfg_log_init(v19, v7) )
{
fwrite("ERROR: initializing logging configuration\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
fh_plugin_load(v22);
if ( (unsigned int)fh_shr_cfg_lh_get_proc(v20, a3, v8) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v11 = fh_log_fmt("invalid process specified or no default process available");
fh_log("fh_shr_tcp.c", 212LL, "CSI", "ERR", v11);
}
exit(1);
}
if ( (unsigned int)fh_shr_cfg_tcp_lh_load(v20, v8, v17) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v12 = fh_log_fmt("unable to parse configuration into line handler process configuration");
fh_log("fh_shr_tcp.c", 221LL, "CSI", "ERR", v12);
}
exit(1);
}
fh_cfg_free(v8);
func4((__int64)a4, (__int64)v19);
func3();
v9 = fh_util_thread_name("Main", v20);
fh_log_thread_start(v9);
if ( (unsigned int)fh_shr_mgmt_start((unsigned int)v19[0], a4, v20, v16) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v13 = fh_log_fmt("error starting management thread for '%s'", v20);
fh_log("fh_shr_tcp.c", 248LL, "CSI", "ERR", v13);
}
exit(1);
}
proc_info = 0LL;
qword_778 = 0LL;
LODWORD(proc_info) = getpid();
LODWORD(qword_778) = fh_shr_tcp_lh_get_tid();
HIDWORD(proc_info) = v18;
HIDWORD(qword_778) = time(0LL);
if ( (unsigned int)fh_shr_tcp_lh_start(a4, v17, v15) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v14 = fh_log_fmt("error starting line handler thread for '%s'", v20);
fh_log("fh_shr_tcp.c", 262LL, "CSI", "ERR", v14);
}
exit(1);
}
fh_shr_mgmt_wait();
fh_shr_tcp_lh_wait();
fh_log_thread_stop(v9);
return 0LL;
}

original_code:
int fh_shr_tcp_main(int argc, char **argv, const char *cfg_tag,
                    const fh_info_build_t *info, fh_shr_tcp_cb_t *cb)
{
    fh_shr_cfg_options_t options;
    fh_shr_cfg_lh_proc_t process_config;
    fh_cfg_node_t *config = ((void *)0);
    char *thread_name = ((void *)0);
    fh_shr_mgmt_cb_t mgmt_callbacks = {
        fh_shr_tcp_exit,
        fh_shr_tcp_lh_get_stats,
        fh_shr_tcp_lh_clear_stats,
        fh_shr_tcp_lh_snap_stats,
        fh_shr_tcp_lh_latency,
        getstatus
    };
    fh_shr_tcp_cb_t lh_callbacks = {
        cb->init,
        cb->parse,
        cb->connect,
        cb->alarm,
    };
    fh_shr_cfg_set_defaults(&options, info->name, info->version);
    fh_shr_cfg_cmd_parse(argc, argv, info->name, &options);
    if (!options.debug_level) {
        fh_daemonize();
    }
    config = fh_cfg_load(options.config_file);
    if (config == ((void *)0)) {
        fprintf(stderr, "ERROR: loading confguration file: %s\n",
                options.config_file);
        exit(1);
    }
    if (fh_shr_cfg_log_init(&options, config) != (0)) {
        fprintf(stderr, "ERROR: initializing logging configuration\n");
        exit(1);
    }
    fh_plugin_load(options.plugin_path);
    if (fh_shr_cfg_lh_get_proc(options.process, cfg_tag, config) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("invalid process specified or no default process available"); fh_log("fh_shr_tcp.c", 212, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    if (fh_shr_cfg_tcp_lh_load(options.process, config, &process_config) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("unable to parse configuration into line handler process configuration"); fh_log("fh_shr_tcp.c", 221, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    fh_cfg_free(config);
    fh_shr_tcp_version(info, &options);
    fh_shr_tcp_sig_init();
    thread_name = fh_util_thread_name("Main", options.process);
    fh_log_thread_start(thread_name);
    if (fh_shr_mgmt_start(options.standalone, info, options.process,
                          &mgmt_callbacks) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("error starting management thread for '%s'", options.process); fh_log("fh_shr_tcp.c", 248, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    memset(&proc_info, 0, sizeof(fh_info_proc_t));
    proc_info.pid = getpid();
    proc_info.tid = fh_shr_tcp_lh_get_tid();
    proc_info.cpu = process_config.cpu;
    proc_info.start_time = time(((void *)0));
    if (fh_shr_tcp_lh_start(info, &process_config, &lh_callbacks) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("error starting line handler thread for '%s'", options.process); fh_log("fh_shr_tcp.c", 262, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    fh_shr_mgmt_wait();
    fh_shr_tcp_lh_wait();
    fh_log_thread_stop(thread_name);
    return 0;
}

canonical_original_code:
int fh_shr_tcp_main(int argc, char **argv, char *cfg_tag, struct fh_info_build *info, struct fh_shr_tcp_cb_t *cb)
{
    struct fh_shr_cfg_options_t options;
    struct fh_shr_cfg_lh_proc process_config;
    struct fh_cfg_node *config = ((void *)0);
    char *thread_name = ((void *)0);
    struct fh_shr_mgmt_cb_t mgmt_callbacks = {
        fh_shr_tcp_exit,
        fh_shr_tcp_lh_get_stats,
        fh_shr_tcp_lh_clear_stats,
        fh_shr_tcp_lh_snap_stats,
        fh_shr_tcp_lh_latency,
        getstatus
    };
    struct fh_shr_tcp_cb_t lh_callbacks = {
        cb->init,
        cb->parse,
        cb->connect,
        cb->alarm,
    };
    fh_shr_cfg_set_defaults(&options, info->name, info->version);
    fh_shr_cfg_cmd_parse(argc, argv, info->name, &options);
    if (!options.debug_level) {
        fh_daemonize();
    }
    config = fh_cfg_load(options.config_file);
    if (config == ((void *)0)) {
        fprintf(stderr, "ERROR: loading confguration file: %s\n",
                options.config_file);
        exit(1);
    }
    if (fh_shr_cfg_log_init(&options, config) != (0)) {
        fprintf(stderr, "ERROR: initializing logging configuration\n");
        exit(1);
    }
    fh_plugin_load(options.plugin_path);
    if (fh_shr_cfg_lh_get_proc(options.process, cfg_tag, config) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("invalid process specified or no default process available"); fh_log("fh_shr_tcp.c", 212, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    if (fh_shr_cfg_tcp_lh_load(options.process, config, &process_config) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("unable to parse configuration into line handler process configuration"); fh_log("fh_shr_tcp.c", 221, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    fh_cfg_free(config);
    fh_shr_tcp_version(info, &options);
    fh_shr_tcp_sig_init();
    thread_name = fh_util_thread_name("Main", options.process);
    fh_log_thread_start(thread_name);
    if (fh_shr_mgmt_start(options.standalone, info, options.process,
                          &mgmt_callbacks) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("error starting management thread for '%s'", options.process); fh_log("fh_shr_tcp.c", 248, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    memset(&proc_info, 0, sizeof(fh_info_proc_t));
    proc_info.pid = getpid();
    proc_info.tid = fh_shr_tcp_lh_get_tid();
    proc_info.cpu = process_config.cpu;
    proc_info.start_time = time(((void *)0));
    if (fh_shr_tcp_lh_start(info, &process_config, &lh_callbacks) != (0)) {
        do { if ((fh_log_lvl[(0)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("error starting line handler thread for '%s'", options.process); fh_log("fh_shr_tcp.c", 262, "CSI", "ERR", _msg); } } while (0);
        exit(1);
    }
    fh_shr_mgmt_wait();
    fh_shr_tcp_lh_wait();
    fh_log_thread_stop(thread_name);
    return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: struct fh_shr_tcp_cb_t { int (*init)(struct fh_shr_lh_proc { struct fh_shr_lh_line { struct fh_shr_lh_proc *process; struct fh_shr_lh_conn { struct fh_shr_lh_line *line; int socket; struct fh_shr_cfg_lh_conn { struct fh_shr_cfg_lh_line { struct fh_shr_cfg_lh_proc { char name[255]; int cpu; struct fh_shr_cfg_lh_line *lines; int num_lines; int gap_list_max; int gap_timeout; struct fh_shr_cfg_tbl { char name[255]; unsigned char enabled; unsigned int size; } symbol_table; struct fh_shr_cfg_tbl order_table; void *context; } *process; char name[255]; struct fh_shr_cfg_lh_conn primary; struct fh_shr_cfg_lh_conn secondary; void *context; } *line; unsigned char enabled; unsigned short port; unsigned int address; char login_name[6]; char login_passwd[10]; char interface[255]; void *context; } *config; char tag[10]; unsigned long timestamp; struct fh_info_stats { unsigned long packets; unsigned long messages; unsigned long bytes; unsigned long packet_errors; unsigned long message_errors; unsigned long duplicate_packets; unsigned long gaps; unsigned long lost_messages; unsigned long recovered_messages; } stats; void *context; } primary; struct fh_shr_cfg_lh_line *config; unsigned long next_seq_no; unsigned long timestamp; struct fh_info_stats stats; void *context; } *lines; int num_lines; struct fh_shr_cfg_lh_proc *config; struct fh_info_stats stats; 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; } symbol_table; struct fh_shr_lkp_tbl order_table; void *context; } *); int (*parse)(char *, unsigned int, char, struct fh_shr_lh_conn *, struct fh_shr_cfg_lh_line *, unsigned long *); int (*connect)(struct fh_shr_lh_proc *, struct fh_shr_cfg_lh_line *, unsigned long *); int (*alarm)(char *, int, int); } *

variable_types: struct fh_shr_cfg_options_t { int standalone; int debug_level; int display_version; int version; char process[255]; char logging_tag[255]; char config_file[-1]; char plugin_path[-1]; char *program_name; }

variable_types: struct fh_shr_cfg_lh_proc { char name[255]; int cpu; struct fh_shr_cfg_lh_line { struct fh_shr_cfg_lh_proc *process; char name[255]; struct fh_shr_cfg_lh_conn { struct fh_shr_cfg_lh_line *line; unsigned char enabled; unsigned short port; unsigned int address; char login_name[6]; char login_passwd[10]; char interface[255]; void *context; } primary; struct fh_shr_cfg_lh_conn secondary; void *context; } *lines; int num_lines; int gap_list_max; int gap_timeout; struct fh_shr_cfg_tbl { char name[255]; unsigned char enabled; unsigned int size; } symbol_table; struct fh_shr_cfg_tbl order_table; void *context; }

variable_types: struct fh_cfg_node { char name[255]; struct fh_cfg_node **children; struct fh_cfg_node *parent; char **values; int num_children; int num_values; } *

variable_types: struct fh_shr_mgmt_cb_t { void (*exit)(); void (*getstats)(struct fh_adm_stats_resp_t { char stats_service[16]; unsigned int stats_state; unsigned int stats_line_cnt; struct fh_adm_line_stats_t { char line_name[32]; unsigned long line_pkt_rx; unsigned long line_pkt_dups; unsigned long line_pkt_errs; unsigned long line_pkt_late; unsigned long line_pkt_until_reset; unsigned long line_pkt_bad_times; unsigned long line_pkt_seq_jump; unsigned long line_pkt_wrap_noreset; unsigned long line_msg_rx; unsigned long line_msg_loss; unsigned long line_msg_recovered; unsigned long line_msg_late; unsigned long line_bytes; } stats_lines[-1]; } *); void (*clrstats)(); void (*snapstats)(); void (*snaplatency)(); struct fh_info_proc { unsigned int pid; unsigned int cpu; unsigned int tid; unsigned int start_time; } *(*getstatus)(); }

user_defined_types: struct fh_shr_cfg_lh_proc { char name[255]; int cpu; struct fh_shr_cfg_lh_line *lines; int num_lines; int gap_list_max; int gap_timeout; struct fh_shr_cfg_tbl symbol_table; struct fh_shr_cfg_tbl order_table; void *context; }

user_defined_types: struct fh_shr_mgmt_cb_t { void (*exit)(); void (*getstats)(struct fh_adm_stats_resp_t *); void (*clrstats)(); void (*snapstats)(); void (*snaplatency)(); struct fh_info_proc *(*getstatus)(); }

user_defined_types: struct fh_shr_tcp_cb_t { int (*init)(struct fh_shr_lh_proc *); int (*parse)(char *, unsigned int, char, struct fh_shr_lh_conn *, struct fh_shr_cfg_lh_line *, unsigned long *); int (*connect)(struct fh_shr_lh_proc *, struct fh_shr_cfg_lh_line *, unsigned long *); int (*alarm)(char *, int, int); }

user_defined_types: struct fh_info_build { char *name; int version; char *build_user; char *build_host; char *build_arch; char *build_kernel; char *build_date; char *build_svn_url; char *build_svn_rev; }

user_defined_types: struct fh_shr_cfg_lh_line { struct fh_shr_cfg_lh_proc *process; char name[255]; struct fh_shr_cfg_lh_conn primary; struct fh_shr_cfg_lh_conn secondary; void *context; }

user_defined_types: struct fh_adm_stats_resp_t { char stats_service[16]; unsigned int stats_state; unsigned int stats_line_cnt; struct fh_adm_line_stats_t stats_lines[-1]; }

user_defined_types: struct fh_shr_lh_proc { struct fh_shr_lh_line *lines; int num_lines; struct fh_shr_cfg_lh_proc *config; struct fh_info_stats stats; struct fh_shr_lkp_tbl symbol_table; struct fh_shr_lkp_tbl order_table; void *context; }

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_shr_lh_line { struct fh_shr_lh_proc *process; struct fh_shr_lh_conn primary; struct fh_shr_cfg_lh_line *config; unsigned long next_seq_no; unsigned long timestamp; struct fh_info_stats stats; void *context; }

user_defined_types: struct fh_shr_lh_conn { struct fh_shr_lh_line *line; int socket; struct fh_shr_cfg_lh_conn *config; char tag[10]; unsigned long timestamp; struct fh_info_stats stats; void *context; }

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:
int __fastcall fh_cfg_dump(__int64 a1)
{
return fh_cfg_dump_localalias(a1, 0);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
return func0(a1, 0);
}

original_code:
void fh_cfg_dump(fh_cfg_node_t *config)
{
    _fh_cfg_dump(config, 0);
}

canonical_original_code:
void fh_cfg_dump(struct fh_cfg_node *config)
{
    _fh_cfg_dump(config, 0);
}

user_defined_types: struct fh_cfg_node { char name[255]; struct fh_cfg_node **children; struct fh_cfg_node *parent; char **values; int num_children; int num_values; }


decompiled_code:
const char *__fastcall fh_cfg_get_node(__int64 a1, const char *a2)
{
const char *v3; // r14
char *v4; // rax
char *v5; // rbx
const char *result; // rax
char v7[296]; // [rsp+0h] [rbp-128h] BYREF

v3 = a2;
v4 = strchr(a2, 46);
if ( !v4 )
return fh_cfg_find_child(a1, v3);
v5 = v4;
while ( 1 )
{
strncpy(v7, v3, (int)v5 - (int)v3);
v7[(int)v5 - (int)v3] = 0;
result = fh_cfg_find_child(a1, v7);
a1 = (__int64)result;
if ( !result )
break;
v3 = v5 + 1;
v5 = strchr(v5 + 1, 46);
if ( !v5 )
return fh_cfg_find_child(a1, v3);
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(__int64 a1, const char *a2)
{
const char *v3; // r14
char *v4; // rax
char *v5; // rbx
const char *result; // rax
char v7[296]; // [rsp+0h] [rbp-128h] BYREF

v3 = a2;
v4 = strchr(a2, 46);
if ( !v4 )
return func2(a1, v3);
v5 = v4;
while ( 1 )
{
strncpy(v7, v3, (int)v5 - (int)v3);
v7[(int)v5 - (int)v3] = 0;
result = func2(a1, v7);
a1 = (__int64)result;
if ( !result )
break;
v3 = v5 + 1;
v5 = strchr(v5 + 1, 46);
if ( !v5 )
return func2(a1, v3);
}
return result;
}

original_code:
const fh_cfg_node_t *fh_cfg_get_node(const fh_cfg_node_t *config, const char *path)
{
    int num_chars;
    char segment[255];
    char *marker;
    const char *remains = path;
    const fh_cfg_node_t *curr = config;
    marker = strchr(remains, '.');
    while (marker != ((void *)0)) {
        num_chars = (marker - remains) / sizeof(char);
        strncpy(segment, remains, num_chars);
        segment[num_chars] = '\0';
        curr = _fh_cfg_find_child(curr, segment);
        if (curr == ((void *)0)) {
            return ((void *)0);
        }
        remains = marker + sizeof(char);
        marker = strchr(remains, '.');
    }
    curr = _fh_cfg_find_child(curr, remains);
    if (curr == ((void *)0)) {
        return ((void *)0);
    }
    return curr;
}

canonical_original_code:
struct fh_cfg_node *fh_cfg_get_node(struct fh_cfg_node *config, char *path)
{
    int num_chars;
    char segment[255];
    char *marker;
    char *remains = path;
    struct fh_cfg_node *curr = config;
    marker = strchr(remains, '.');
    while (marker != ((void *)0)) {
        num_chars = (marker - remains) / sizeof(char);
        strncpy(segment, remains, num_chars);
        segment[num_chars] = '\0';
        curr = _fh_cfg_find_child(curr, segment);
        if (curr == ((void *)0)) {
            return ((void *)0);
        }
        remains = marker + sizeof(char);
        marker = strchr(remains, '.');
    }
    curr = _fh_cfg_find_child(curr, remains);
    if (curr == ((void *)0)) {
        return ((void *)0);
    }
    return curr;
}

variable_types:
config
struct fh_cfg_node *

variable_types:
path
char *

variable_types:
segment
char [255]

variable_types:
marker
char *

variable_types:
remains
char *

return_type: struct fh_cfg_node { char name[255]; struct fh_cfg_node **children; struct fh_cfg_node *parent; char **values; int num_children; int num_values; } *


decompiled_code:
const char *__fastcall fh_cfg_get_string(__int64 a1, const char *a2)
{
const char *result; // rax

result = fh_cfg_get_node(a1, a2);
if ( result )
{
if ( *((int *)result + 71) <= 0 )
result = 0LL;
else
result = (const char *)**((_QWORD **)result + 34);
}
return result;
}

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

result = func3(a1, a2);
if ( result )
{
if ( *((int *)result + 71) <= 0 )
result = 0LL;
else
result = (const char *)**((_QWORD **)result + 34);
}
return result;
}

original_code:
const char *fh_cfg_get_string(const fh_cfg_node_t *config, const char *path)
{
    const fh_cfg_node_t *node;
    node = fh_cfg_get_node(config, path);
    if(node == ((void *)0) || node->num_values < 1) {
        return ((void *)0);
    }
    return node->values[0];
}

canonical_original_code:
char *fh_cfg_get_string(struct fh_cfg_node *config, char *path)
{
    struct fh_cfg_node *node;
    node = fh_cfg_get_node(config, path);
    if(node == ((void *)0) || node->num_values < 1) {
        return ((void *)0);
    }
    return node->values[0];
}


decompiled_code:
const char *__fastcall fh_cfg_get_array(__int64 a1, const char *a2)
{
const char *result; // rax

result = fh_cfg_get_node(a1, a2);
if ( result )
result = (const char *)*((_QWORD *)result + 34);
return result;
}

canonical_decompiled_code:
const char *__fastcall func5(__int64 a1, const char *a2)
{
const char *result; // rax

result = func3(a1, a2);
if ( result )
result = (const char *)*((_QWORD *)result + 34);
return result;
}

original_code:
const char **fh_cfg_get_array(const fh_cfg_node_t *config, const char *path)
{
    const fh_cfg_node_t *node;
    node = fh_cfg_get_node(config, path);
    if(node == ((void *)0)) return ((void *)0);
    return (const char **)node->values;
}

canonical_original_code:
char **fh_cfg_get_array(struct fh_cfg_node *config, char *path)
{
    struct fh_cfg_node *node;
    node = fh_cfg_get_node(config, path);
    if(node == ((void *)0)) return ((void *)0);
    return (char **)node->values;
}

return_type: char **


original_code:
FH_STATUS fh_cfg_set_yesno(const fh_cfg_node_t *config, const char *property, uint8_t *value)
{
    const char *str;
    str = fh_cfg_get_string(config, property);
    if (str == ((void *)0)) {
        return (1);
    }
    if ((str[0] == 'y' || str[0] == 'Y') && (str[1] == 'e' || str[1] == 'E') &&
        (str[2] == 's' || str[2] == 'S')) {
        *value = 1;
    }
    else if ((str[0] == 'n' || str[0] == 'N') && (str[1] == 'o' || str[1] == 'O')) {
        *value = 0;
    }
    else {
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_cfg_set_yesno(struct fh_cfg_node *config, char *property, unsigned char *value)
{
    char *str;
    str = fh_cfg_get_string(config, property);
    if (str == ((void *)0)) {
        return (1);
    }
    if ((str[0] == 'y' || str[0] == 'Y') && (str[1] == 'e' || str[1] == 'E') &&
        (str[2] == 's' || str[2] == 'S')) {
        *value = 1;
    }
    else if ((str[0] == 'n' || str[0] == 'N') && (str[1] == 'o' || str[1] == 'O')) {
        *value = 0;
    }
    else {
        return (-1);
    }
    return (0);
}

variable_types:
property
char *

variable_types:
value
unsigned char *

variable_types:
str
char *


decompiled_code:
__int64 __fastcall fh_cfg_set_uint32(__int64 a1, const char *a2, _DWORD *a3)
{
const char *v4; // rbx
__int64 result; // rax
int v6; // edx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v4 = fh_cfg_get_string(a1, a2);
result = 1LL;
if ( v4 )
{
v6 = strtoul(v4, &endptr, 0);
result = 0xFFFFFFFFLL;
if ( *v4 )
{
if ( !*endptr )
{
*a3 = v6;
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, _DWORD *a3)
{
const char *v4; // rbx
__int64 result; // rax
int v6; // edx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v4 = func4(a1, a2);
result = 1LL;
if ( v4 )
{
v6 = strtoul(v4, &endptr, 0);
result = 0xFFFFFFFFLL;
if ( *v4 )
{
if ( !*endptr )
{
*a3 = v6;
result = 0LL;
}
}
}
return result;
}

original_code:
FH_STATUS fh_cfg_set_uint32(const fh_cfg_node_t *config, const char *property, uint32_t *value)
{
    const char *str;
    char *last;
    uint32_t val;
    str = fh_cfg_get_string(config, property);
    if (str == ((void *)0)) {
        return (1);
    }
    val = (uint32_t)strtoul(str, &last, 0);
    if (str[0] == '\0' || last[0] != '\0') {
        return (-1);
    }
    *value = val;
    return (0);
}

canonical_original_code:
int fh_cfg_set_uint32(struct fh_cfg_node *config, char *property, unsigned int *value)
{
    char *str;
    char *last;
    unsigned int val;
    str = fh_cfg_get_string(config, property);
    if (str == ((void *)0)) {
        return (1);
    }
    val = (unsigned int)strtoul(str, &last, 0);
    if (str[0] == '\0' || last[0] != '\0') {
        return (-1);
    }
    *value = val;
    return (0);
}

variable_types:
value
unsigned int *

variable_types:
last
char *

variable_types:
val
unsigned int


decompiled_code:
__int64 __fastcall fh_cfg_set_uint16(__int64 a1, const char *a2, _WORD *a3)
{
const char *v4; // rbx
__int64 result; // rax
__int16 v6; // dx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v4 = fh_cfg_get_string(a1, a2);
result = 1LL;
if ( v4 )
{
v6 = strtoul(v4, &endptr, 0);
result = 0xFFFFFFFFLL;
if ( *v4 )
{
if ( !*endptr )
{
*a3 = v6;
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, const char *a2, _WORD *a3)
{
const char *v4; // rbx
__int64 result; // rax
__int16 v6; // dx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v4 = func4(a1, a2);
result = 1LL;
if ( v4 )
{
v6 = strtoul(v4, &endptr, 0);
result = 0xFFFFFFFFLL;
if ( *v4 )
{
if ( !*endptr )
{
*a3 = v6;
result = 0LL;
}
}
}
return result;
}

original_code:
FH_STATUS fh_cfg_set_uint16(const fh_cfg_node_t *config, const char *property, uint16_t *value)
{
    const char *str;
    char *last;
    uint16_t val;
    str = fh_cfg_get_string(config, property);
    if (str == ((void *)0)) {
        return (1);
    }
    val = (uint16_t)strtoul(str, &last, 0);
    if (str[0] == '\0' || last[0] != '\0') {
        return (-1);
    }
    *value = val;
    return (0);
}

canonical_original_code:
int fh_cfg_set_uint16(struct fh_cfg_node *config, char *property, unsigned short *value)
{
    char *str;
    char *last;
    unsigned short val;
    str = fh_cfg_get_string(config, property);
    if (str == ((void *)0)) {
        return (1);
    }
    val = (unsigned short)strtoul(str, &last, 0);
    if (str[0] == '\0' || last[0] != '\0') {
        return (-1);
    }
    *value = val;
    return (0);
}

variable_types:
value
unsigned short *

variable_types:
val
unsigned short


decompiled_code:
__int64 __fastcall fh_cfg_set_int(__int64 a1, const char *a2, _DWORD *a3)
{
const char *v4; // rbx
__int64 result; // rax
int v6; // edx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v4 = fh_cfg_get_string(a1, a2);
result = 1LL;
if ( v4 )
{
v6 = strtoul(v4, &endptr, 0);
result = 0xFFFFFFFFLL;
if ( *v4 )
{
if ( !*endptr )
{
*a3 = v6;
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2, _DWORD *a3)
{
const char *v4; // rbx
__int64 result; // rax
int v6; // edx
char *endptr; // [rsp+8h] [rbp-20h] BYREF

v4 = func4(a1, a2);
result = 1LL;
if ( v4 )
{
v6 = strtoul(v4, &endptr, 0);
result = 0xFFFFFFFFLL;
if ( *v4 )
{
if ( !*endptr )
{
*a3 = v6;
result = 0LL;
}
}
}
return result;
}

original_code:
FH_STATUS fh_cfg_set_int(const fh_cfg_node_t *config, const char *property, int *value)
{
    const char *str;
    char *last;
    int val;
    str = fh_cfg_get_string(config, property);
    if (str == ((void *)0)) {
        return (1);
    }
    val = (int)strtoul(str, &last, 0);
    if (str[0] == '\0' || last[0] != '\0') {
        return (-1);
    }
    *value = val;
    return (0);
}

canonical_original_code:
int fh_cfg_set_int(struct fh_cfg_node *config, char *property, int *value)
{
    char *str;
    char *last;
    int val;
    str = fh_cfg_get_string(config, property);
    if (str == ((void *)0)) {
        return (1);
    }
    val = (int)strtoul(str, &last, 0);
    if (str[0] == '\0' || last[0] != '\0') {
        return (-1);
    }
    *value = val;
    return (0);
}

variable_types:
value
int *

variable_types: val int


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

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

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

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

original_code:
FH_STATUS fh_udp_tstamp(int s, int on)
{
    if (setsockopt(s, 1, 29, &on, sizeof(on)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt SO_TIMESTAMP failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_udp.c", 49, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_udp_tstamp(int s, int on)
{
    if (setsockopt(s, 1, 29, &on, sizeof(on)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt SO_TIMESTAMP failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_udp.c", 49, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

variable_types: s int

variable_types: on int


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

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

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

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

original_code:
FH_STATUS fh_udp_pktinfo(int s, int on)
{
    if (setsockopt(s, IPPROTO_IP, 8, (char*)&on, sizeof(on)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_PKTINFO failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_udp.c", 66, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}

canonical_original_code:
int fh_udp_pktinfo(int s, int on)
{
    if (setsockopt(s, IPPROTO_IP, 8, (char *)&on, sizeof(on)) < 0) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> setsockopt IP_PKTINFO failed on socket #%d: %d", s, (*__errno_location ())); fh_log("fh_udp.c", 66, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    return (0);
}


decompiled_code:
__int64 __fastcall fh_udp_open(unsigned int a1, unsigned __int16 a2, char a3, unsigned int *a4)
{
unsigned int v6; // eax
unsigned int v7; // ebx
int *v9; // rax
__int64 v10; // rax

v6 = socket(2, 2, 0);
v7 = v6;
if ( v6 == -1 )
{
if ( (fh_log_lvl[4] & 1) != 0 )
{
v9 = _errno_location();
v10 = fh_log_fmt("NET> Failed to open UDP socket: %d", (unsigned int)*v9);
fh_log("fh_udp.c", 126LL, "NET", "ERR", v10);
}
}
else if ( (a3 & 1) != 0 && (int)fh_sock_reuse(v6, 1LL) < 0
|| (int)fh_sock_bind(v7, a1, a2) < 0
|| (int)fh_udp_pktinfo(v7, 1) < 0
|| (int)fh_udp_tstamp(v7, 1) < 0 )
{
close(v7);
v7 = -1;
}
else
{
if ( (a3 & 2) != 0 )
fh_udp_set_maxbufsz(v7);
*a4 = v7;
v7 = 0;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned __int16 a2, char a3, unsigned int *a4)
{
unsigned int v6; // eax
unsigned int v7; // ebx
int *v9; // rax
__int64 v10; // rax

v6 = socket(2, 2, 0);
v7 = v6;
if ( v6 == -1 )
{
if ( (fh_log_lvl[4] & 1) != 0 )
{
v9 = _errno_location();
v10 = fh_log_fmt("NET> Failed to open UDP socket: %d", (unsigned int)*v9);
fh_log("fh_udp.c", 126LL, "NET", "ERR", v10);
}
}
else if ( (a3 & 1) != 0 && (int)fh_sock_reuse(v6, 1LL) < 0
|| (int)fh_sock_bind(v7, a1, a2) < 0
|| (int)func1(v7, 1) < 0
|| (int)func0(v7, 1) < 0 )
{
close(v7);
v7 = -1;
}
else
{
if ( (a3 & 2) != 0 )
fh_udp_set_maxbufsz(v7);
*a4 = v7;
v7 = 0;
}
return v7;
}

original_code:
FH_STATUS fh_udp_open(uint32_t addr, uint16_t port, int flags, int *s)
{
    int sock;
    sock = socket(2, SOCK_DGRAM, 0);
    if (sock == -1) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> Failed to open UDP socket: %d", (*__errno_location ())); fh_log("fh_udp.c", 126, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    if (flags & (0x00000001)) {
        if (fh_sock_reuse(sock, 1) < 0) {
            goto error;
        }
    }
    if (fh_sock_bind(sock, addr, port) < 0) {
        goto error;
    }
    if (fh_udp_pktinfo(sock, 1) < 0) {
        goto error;
    }
    if (fh_udp_tstamp(sock, 1) < 0) {
        goto error;
    }
    if (flags & (0x00000002)) {
        fh_udp_set_maxbufsz(sock);
    }
    *s = sock;
    return (0);
error:
    close(sock);
    return (-1);
}

canonical_original_code:
int fh_udp_open(unsigned int addr, unsigned short port, int flags, int *s)
{
    int sock;
    sock = socket(2, SOCK_DGRAM, 0);
    if (sock == -1) {
        do { if ((fh_log_lvl[(1)] & ((0x00000001)))) { char *_msg = fh_log_fmt ("NET> Failed to open UDP socket: %d", (*__errno_location ())); fh_log("fh_udp.c", 126, "NET", "ERR", _msg); } } while (0);
        return (-1);
    }
    if (flags & (0x00000001)) {
        if (fh_sock_reuse(sock, 1) < 0) {
            goto error;
        }
    }
    if (fh_sock_bind(sock, addr, port) < 0) {
        goto error;
    }
    if (fh_udp_pktinfo(sock, 1) < 0) {
        goto error;
    }
    if (fh_udp_tstamp(sock, 1) < 0) {
        goto error;
    }
    if (flags & (0x00000002)) {
        fh_udp_set_maxbufsz(sock);
    }
    *s = sock;
    return (0);
error:
    close(sock);
    return (-1);
}

variable_types:
addr
unsigned int

variable_types:
port
unsigned short

variable_types: flags int

variable_types:
s
int *

variable_types: sock int


decompiled_code:
ssize_t __fastcall fh_udp_send(int a1, const void *a2, int a3, const struct sockaddr *a4)
{
return sendto(a1, a2, a3, 0, a4, 0x10u);
}

canonical_decompiled_code:
ssize_t __fastcall func3(int a1, const void *a2, int a3, const struct sockaddr *a4)
{
return sendto(a1, a2, a3, 0, a4, 0x10u);
}

original_code:
int fh_udp_send(int s, void *buf, int nbytes, struct sockaddr_in *to)
{
    return sendto(s, (char*)buf, nbytes, 0,
                  (struct sockaddr *)to, sizeof(struct sockaddr_in));
}

canonical_original_code:
int fh_udp_send(int s, void *buf, int nbytes, struct sockaddr_in *to)
{
    return sendto(s, (char *)buf, nbytes, 0,
                  (struct sockaddr *)to, sizeof(struct sockaddr_in));
}

variable_types:
buf
void *

variable_types: nbytes int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall fast_opra_init(__int64 a1)
{
memset(FastOpra_msg_ops, 0, 0x158uLL);
qword_4D0 = (__int64)&decode_OpraFastQuoteSizeMsg_v2;
qword_498 = (__int64)&decode_OpraFastOpenIntMsg_v2;
qword_480 = (__int64)&decode_OpraFastLastSaleMsg_v2;
qword_4A8 = (__int64)&decode_OpraFastEodMsg_v2;
qword_3F0 = (__int64)&decode_OpraFastFcoLastSaleMsg_v2;
qword_420 = (__int64)&decode_OpraFastFcoQuoteMsg_v2;
qword_3A8 = (__int64)&decode_OpraFastFcoEodMsg_v2;
qword_440 = (__int64)&decode_OpraFastUlValueMsg_v2;
qword_390 = (__int64)&decode_OpraFastAdminMsg_v2;
qword_3B8 = (__int64)&decode_OpraFastControlMsg_v2;
return init_fast(a1, FastOpra_msg_ops);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
memset(FastOpra_msg_ops, 0, 0x158uLL);
qword_4D0 = (__int64)&decode_OpraFastQuoteSizeMsg_v2;
qword_498 = (__int64)&decode_OpraFastOpenIntMsg_v2;
qword_480 = (__int64)&decode_OpraFastLastSaleMsg_v2;
qword_4A8 = (__int64)&decode_OpraFastEodMsg_v2;
qword_3F0 = (__int64)&decode_OpraFastFcoLastSaleMsg_v2;
qword_420 = (__int64)&decode_OpraFastFcoQuoteMsg_v2;
qword_3A8 = (__int64)&decode_OpraFastFcoEodMsg_v2;
qword_440 = (__int64)&decode_OpraFastUlValueMsg_v2;
qword_390 = (__int64)&decode_OpraFastAdminMsg_v2;
qword_3B8 = (__int64)&decode_OpraFastControlMsg_v2;
return init_fast(a1, FastOpra_msg_ops);
}

original_code:
void fast_opra_init(Fast *fast)
{
    memset(FastOpra_msg_ops, 0 , sizeof(FastOpra_msg_ops));
    FastOpra_msg_ops['k' - 'A'] = decode_OpraFastQuoteSizeMsg_v2;
    FastOpra_msg_ops['d' - 'A'] = decode_OpraFastOpenIntMsg_v2;
    FastOpra_msg_ops['a' - 'A'] = decode_OpraFastLastSaleMsg_v2;
    FastOpra_msg_ops['f' - 'A'] = decode_OpraFastEodMsg_v2;
    FastOpra_msg_ops['O' - 'A'] = decode_OpraFastFcoLastSaleMsg_v2;
    FastOpra_msg_ops['U' - 'A'] = decode_OpraFastFcoQuoteMsg_v2;
    FastOpra_msg_ops['F' - 'A'] = decode_OpraFastFcoEodMsg_v2;
    FastOpra_msg_ops['Y' - 'A'] = decode_OpraFastUlValueMsg_v2;
    FastOpra_msg_ops['C' - 'A'] = decode_OpraFastAdminMsg_v2;
    FastOpra_msg_ops['H' - 'A'] = decode_OpraFastControlMsg_v2;
    init_fast(fast);
}

canonical_original_code:
void fast_opra_init(struct Fast *fast)
{
    memset(FastOpra_msg_ops, 0 , sizeof(FastOpra_msg_ops));
    FastOpra_msg_ops['k' - 'A'] = decode_OpraFastQuoteSizeMsg_v2;
    FastOpra_msg_ops['d' - 'A'] = decode_OpraFastOpenIntMsg_v2;
    FastOpra_msg_ops['a' - 'A'] = decode_OpraFastLastSaleMsg_v2;
    FastOpra_msg_ops['f' - 'A'] = decode_OpraFastEodMsg_v2;
    FastOpra_msg_ops['O' - 'A'] = decode_OpraFastFcoLastSaleMsg_v2;
    FastOpra_msg_ops['U' - 'A'] = decode_OpraFastFcoQuoteMsg_v2;
    FastOpra_msg_ops['F' - 'A'] = decode_OpraFastFcoEodMsg_v2;
    FastOpra_msg_ops['Y' - 'A'] = decode_OpraFastUlValueMsg_v2;
    FastOpra_msg_ops['C' - 'A'] = decode_OpraFastAdminMsg_v2;
    FastOpra_msg_ops['H' - 'A'] = decode_OpraFastControlMsg_v2;
    init_fast(fast);
}

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; } *

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 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 fast_codec_error_t { char *fn; char *text; unsigned int tag; enum fast_error_t code; }


original_code:
int fast_opra_hdr_info(Fast *fast, uint8_t *buffer, uint32_t len, char *msg_cat, char *msg_type, uint32_t *msg_sn, uint32_t *time)
{
    int acq_size;
    acq_size = buffer[15];
    if (acq_size == 0xff) {
        fast->setBuffer(fast, (uint8_t *) (buffer+16), len);
    }
    else if ((acq_size > 0) && (acq_size < 0xff)) {
        fast->setBuffer(fast, (uint8_t *) (buffer+16), acq_size);
    }
    else {
        return -1;
    }
    if (fast->decode_new_msg(fast, OPRA_BASE_TID) < 0) {
        return -1;
    }
    *msg_cat = (char) fast->decode_u32(fast, MESSAGE_CATEGORY_V2);
    *msg_type = (char) fast->decode_u32(fast, MESSAGE_TYPE_V2);
    if (msg_sn) {
        (void) fast->decode_u32(fast, PARTICIPANT_ID_V2);
        (void) fast->decode_u32(fast, RETRANSMISSION_REQUESTER_V2);
        *msg_sn = (uint32_t) fast->decode_u32(fast, MESSAGE_SEQUENCE_NUMBER_V2);
    }
    if (time) {
        (void) fast->decode_u32(fast, PARTICIPANT_ID_V2);
        (void) fast->decode_u32(fast, RETRANSMISSION_REQUESTER_V2);
        (void) fast->decode_u32(fast, MESSAGE_SEQUENCE_NUMBER_V2);
        *time = (uint32_t) fast->decode_u32(fast, TIME_V2);
    }
    return 0;
}

canonical_original_code:
int fast_opra_hdr_info(struct Fast *fast, unsigned char *buffer, unsigned int len, char *msg_cat, char *msg_type, unsigned int *msg_sn, unsigned int *time)
{
    int acq_size;
    acq_size = buffer[15];
    if (acq_size == 0xff) {
        fast->setBuffer(fast, (unsigned char *) (buffer+16), len);
    }
    else if ((acq_size > 0) && (acq_size < 0xff)) {
        fast->setBuffer(fast, (unsigned char *) (buffer+16), acq_size);
    }
    else {
        return -1;
    }
    if (fast->decode_new_msg(fast, OPRA_BASE_TID) < 0) {
        return -1;
    }
    *msg_cat = (char) fast->decode_u32(fast, MESSAGE_CATEGORY_V2);
    *msg_type = (char) fast->decode_u32(fast, MESSAGE_TYPE_V2);
    if (msg_sn) {
        (void) fast->decode_u32(fast, PARTICIPANT_ID_V2);
        (void) fast->decode_u32(fast, RETRANSMISSION_REQUESTER_V2);
        *msg_sn = (unsigned int) fast->decode_u32(fast, MESSAGE_SEQUENCE_NUMBER_V2);
    }
    if (time) {
        (void) fast->decode_u32(fast, PARTICIPANT_ID_V2);
        (void) fast->decode_u32(fast, RETRANSMISSION_REQUESTER_V2);
        (void) fast->decode_u32(fast, MESSAGE_SEQUENCE_NUMBER_V2);
        *time = (unsigned int) fast->decode_u32(fast, TIME_V2);
    }
    return 0;
}

variable_types:
buffer
unsigned char *

variable_types:
len
unsigned int

variable_types:
time
unsigned int *

user_defined_types: struct fast_pmap_t { unsigned char bits[-1]; unsigned int size; unsigned int max_pos; }

user_defined_types: struct fast_buffer_t { int fd; unsigned char *head; unsigned char *tail; unsigned char *end; unsigned char *data; }

user_defined_types: struct fast_cv_t { int i32_values[64]; unsigned int u32_values[64]; unsigned char *str_values[64]; unsigned int valid[64]; }

user_defined_types: 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 }