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

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

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

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

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

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

variable_types:
argv
char **

variable_types: argc int

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

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


repo: csinitiative/fhce

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

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

original_code:
int fh_cli_alias_size()
{
    return alias_cnt;
}

return_type: int


variable_types: i int

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

return_type: void

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

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


decompiled_code:
__int64 __fastcall fh_cli_alias_add(char *src, char *a2)
{
char *v2; // rbx
char *v3; // rax
__int64 v4; // rax
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func5(char *src, char *a2)
{
char *v2; // rbx
char *v3; // rax
__int64 v4; // rax
__int64 result; // rax

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

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

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

variable_types:
name
char *

variable_types:
cmd
char *

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


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

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

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

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

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

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


decompiled_code:
_BOOL8 __fastcall opt_kcmp(_OWORD *a1, _OWORD *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 *a2 == *a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(_OWORD *a1, _OWORD *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 *a2 == *a1;
}

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

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

variable_types: klen int

variable_types: nok int


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

return_type: char *

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


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

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

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

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

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

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

return_type: unsigned int


decompiled_code:
__int64 fh_opra_opt_init()
{
int v0; // eax
unsigned int v1; // er12
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

if ( dword_D38 )
{
v6 = 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", v6);
exit(1);
}
opt_db = fh_mpool_new("OptionTable", 184LL, opra_cfg[3895], 0LL);
if ( opt_db )
{
qword_D28 = fh_ht_new(opra_cfg[3895], 0LL, odb_kops);
if ( qword_D28 )
{
if ( (fh_log_lvl[8] & 4) != 0 )
{
v3 = fh_log_fmt("Option DB initialized: size:%d key size:%d", opra_cfg[3895], 16LL);
fh_log("fh_opra_option.c", 105LL, "LH", "STATE", v3);
}
v0 = opra_cfg[3895];
v1 = 0;
dword_D30 = 0;
dword_D38 = 1;
dword_D34 = v0;
}
else
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v5 = fh_log_fmt("Failed to initialize the options H-table");
fh_log("fh_opra_option.c", 100LL, "LH", "ERR", v5);
}
v1 = -1;
fh_mpool_free(opt_db);
}
}
else
{
v1 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v4 = fh_log_fmt("Failed to initialize the options mem pool");
fh_log("fh_opra_option.c", 91LL, "LH", "ERR", v4);
}
}
return v1;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
unsigned int v1; // er12
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

if ( dword_D38 )
{
v6 = 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", v6);
exit(1);
}
opt_db = fh_mpool_new("OptionTable", 184LL, opra_cfg[3895], 0LL);
if ( opt_db )
{
qword_D28 = fh_ht_new(opra_cfg[3895], 0LL, odb_kops);
if ( qword_D28 )
{
if ( (fh_log_lvl[8] & 4) != 0 )
{
v3 = fh_log_fmt("Option DB initialized: size:%d key size:%d", opra_cfg[3895], 16LL);
fh_log("fh_opra_option.c", 105LL, "LH", "STATE", v3);
}
v0 = opra_cfg[3895];
v1 = 0;
dword_D30 = 0;
dword_D38 = 1;
dword_D34 = v0;
}
else
{
if ( (fh_log_lvl[8] & 1) != 0 )
{
v5 = fh_log_fmt("Failed to initialize the options H-table");
fh_log("fh_opra_option.c", 100LL, "LH", "ERR", v5);
}
v1 = -1;
fh_mpool_free(opt_db);
}
}
else
{
v1 = -1;
if ( (fh_log_lvl[8] & 1) != 0 )
{
v4 = fh_log_fmt("Failed to initialize the options mem pool");
fh_log("fh_opra_option.c", 91LL, "LH", "ERR", v4);
}
}
return v1;
}

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


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_D38 )
{
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_D30);
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_D28 + 20),
*(unsigned int *)(qword_D28 + 16));
fh_log("fh_opra_option.c", 128LL, 0LL, "DIAG", v4);
v5 = fh_ht_memuse(qword_D28);
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_D38 )
{
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_D30);
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_D28 + 20),
*(unsigned int *)(qword_D28 + 16));
fh_log("fh_opra_option.c", 128LL, 0LL, "DIAG", v4);
v5 = fh_ht_memuse(qword_D28);
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);
}


decompiled_code:
__int64 __fastcall fh_opra_opt_add(const __m128i *a1, __m128i **a2)
{
__m128i *v3; // rax
__m128i *v4; // r12
const char *v5; // r15
unsigned int v6; // er13
__int64 v8; // rdi
unsigned int v9; // eax
char *v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
int v19; // eax
int v20; // edx
__int64 v21; // rsi
__int64 v22; // rax
char *v23; // rax
__int64 v24; // rax
char *v25; // rax
__int64 v26; // rax
__int64 v27; // rax
__int64 v28; // rax
__int64 v29; // rax
__int64 v30; // rax
__int64 v31[8]; // [rsp+8h] [rbp-40h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func6(const __m128i *a1, __m128i **a2)
{
__m128i *v3; // rax
__m128i *v4; // r12
const char *v5; // r15
unsigned int v6; // er13
__int64 v8; // rdi
unsigned int v9; // eax
char *v10; // rax
__int64 v11; // rax
__int64 v12; // rax
__int64 v13; // rax
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax
int v19; // eax
int v20; // edx
__int64 v21; // rsi
__int64 v22; // rax
char *v23; // rax
__int64 v24; // rax
char *v25; // rax
__int64 v26; // rax
__int64 v27; // rax
__int64 v28; // rax
__int64 v29; // rax
__int64 v30; // rax
__int64 v31[8]; // [rsp+8h] [rbp-40h] BYREF

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

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_D38 )
{
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_D28, 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_D38 )
{
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_D28, 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:
__int128 *getstatus()
{
if ( !DWORD2(proc_info) )
DWORD2(proc_info) = fh_shr_tcp_lh_get_tid();
return &proc_info;
}

canonical_decompiled_code:
__int128 *func0()
{
if ( !DWORD2(proc_info) )
DWORD2(proc_info) = 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)
{
int v1; // eax
__int64 v2; // rax
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
__int64 v6; // rax

v1 = fh_log_lvl[3] & 2;
if ( a1 == 13 )
{
if ( v1 )
{
v5 = fh_log_fmt("SIGPIPE caught - exiting -");
fh_log("fh_shr_tcp.c", 94LL, "MGMT", "WARN", v5);
}
}
else if ( a1 > 13 )
{
if ( a1 != 15 )
{
LABEL_11:
if ( v1 )
{
v3 = fh_log_fmt("Unhandled Signal received: %d", (unsigned int)a1);
fh_log("fh_shr_tcp.c", 98LL, "MGMT", "WARN", v3);
}
goto LABEL_7;
}
if ( v1 )
{
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 ( v1 )
{
v6 = fh_log_fmt("SIGINT caught - exiting - ");
fh_log("fh_shr_tcp.c", 90LL, "MGMT", "WARN", v6);
}
goto LABEL_7;
}
goto LABEL_11;
}
if ( v1 )
{
v4 = fh_log_fmt("SIGHUP caught - exiting - ");
fh_log("fh_shr_tcp.c", 86LL, "MGMT", "WARN", v4);
}
}
LABEL_7:
fh_shr_tcp_exit();
}

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

v1 = fh_log_lvl[3] & 2;
if ( a1 == 13 )
{
if ( v1 )
{
v5 = fh_log_fmt("SIGPIPE caught - exiting -");
fh_log("fh_shr_tcp.c", 94LL, "MGMT", "WARN", v5);
}
}
else if ( a1 > 13 )
{
if ( a1 != 15 )
{
LABEL_11:
if ( v1 )
{
v3 = fh_log_fmt("Unhandled Signal received: %d", (unsigned int)a1);
fh_log("fh_shr_tcp.c", 98LL, "MGMT", "WARN", v3);
}
goto LABEL_7;
}
if ( v1 )
{
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 ( v1 )
{
v6 = fh_log_fmt("SIGINT caught - exiting - ");
fh_log("fh_shr_tcp.c", 90LL, "MGMT", "WARN", v6);
}
goto LABEL_7;
}
goto LABEL_11;
}
if ( v1 )
{
v4 = fh_log_fmt("SIGHUP caught - exiting - ");
fh_log("fh_shr_tcp.c", 86LL, "MGMT", "WARN", v4);
}
}
LABEL_7:
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[3] & 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[3] & 1) != 0 )
{
v4 = fh_log_fmt("Init for SIGHUP failed");
fh_log("fh_shr_tcp.c", 118LL, "MGMT", "ERR", v4);
}
if ( signal(15, fh_tcp_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[3] & 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[3] & 1) != 0 )
{
v2 = fh_log_fmt("Init for SIGPIPE failed");
result = (__sighandler_t)fh_log("fh_shr_tcp.c", 126LL, "MGMT", "ERR", v2);
}
}
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[3] & 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[3] & 1) != 0 )
{
v4 = fh_log_fmt("Init for SIGHUP failed");
fh_log("fh_shr_tcp.c", 118LL, "MGMT", "ERR", v4);
}
if ( signal(15, fh_tcp_sig_handle) == (__sighandler_t)-1LL && (fh_log_lvl[3] & 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[3] & 1) != 0 )
{
v2 = fh_log_fmt("Init for SIGPIPE failed");
result = (__sighandler_t)fh_log("fh_shr_tcp.c", 126LL, "MGMT", "ERR", v2);
}
}
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

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

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

fh_info_version_msg();
result = *(unsigned int *)(a2 + 8);
if ( (_DWORD)result )
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, __int64 a4, __int64 *a5)
{
__int64 v8; // rdx
__int64 v9; // rsi
__int64 v10; // rax
__int64 v11; // r12
__int64 v12; // r12
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18[4]; // [rsp+0h] [rbp-25C8h] BYREF
__int64 v19[6]; // [rsp+20h] [rbp-25A8h] BYREF
char v20[256]; // [rsp+50h] [rbp-2578h] BYREF
int v21; // [rsp+150h] [rbp-2478h]
int v22[4]; // [rsp+380h] [rbp-2248h] BYREF
char v23[510]; // [rsp+390h] [rbp-2238h] BYREF
char v24[4097]; // [rsp+58Eh] [rbp-203Ah] BYREF
char v25[4153]; // [rsp+158Fh] [rbp-1039h] BYREF

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

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

v8 = *(unsigned int *)(a4 + 8);
v9 = *(_QWORD *)a4;
v19[0] = (__int64)fh_shr_tcp_exit;
v19[1] = (__int64)&fh_shr_tcp_lh_get_stats;
v19[2] = (__int64)&fh_shr_tcp_lh_clear_stats;
v19[3] = (__int64)&fh_shr_tcp_lh_snap_stats;
v19[4] = (__int64)&fh_shr_tcp_lh_latency;
v19[5] = (__int64)getstatus;
v18[0] = *a5;
v18[1] = a5[1];
v18[2] = a5[2];
v18[3] = a5[3];
fh_shr_cfg_set_defaults(v22, v9, v8);
fh_shr_cfg_cmd_parse(a1, a2, *(_QWORD *)a4, v22);
if ( !v22[1] )
fh_daemonize();
v10 = fh_cfg_load(v24);
v11 = v10;
if ( !v10 )
{
fprintf(stderr, "ERROR: loading confguration file: %s\n", v24);
exit(1);
}
if ( (unsigned int)fh_shr_cfg_log_init(v22, v10) )
{
fwrite("ERROR: initializing logging configuration\n", 1uLL, 0x2AuLL, stderr);
exit(1);
}
fh_plugin_load(v25);
if ( (unsigned int)fh_shr_cfg_lh_get_proc(v23, a3, v11) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v16 = fh_log_fmt("invalid process specified or no default process available");
fh_log("fh_shr_tcp.c", 212LL, "CSI", "ERR", v16);
}
LABEL_12:
exit(1);
}
if ( (unsigned int)fh_shr_cfg_tcp_lh_load(v23, v11, v20) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v15 = fh_log_fmt("unable to parse configuration into line handler process configuration");
fh_log("fh_shr_tcp.c", 221LL, "CSI", "ERR", v15);
}
goto LABEL_12;
}
fh_cfg_free(v11);
func4(a4, (__int64)v22);
func3();
v12 = fh_util_thread_name("Main", v23);
fh_log_thread_start(v12);
if ( (unsigned int)fh_shr_mgmt_start((unsigned int)v22[0], a4, v23, v19) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v14 = fh_log_fmt("error starting management thread for '%s'", v23);
fh_log("fh_shr_tcp.c", 248LL, "CSI", "ERR", v14);
}
goto LABEL_12;
}
proc_info = 0LL;
LODWORD(proc_info) = getpid();
DWORD2(proc_info) = fh_shr_tcp_lh_get_tid();
DWORD1(proc_info) = v21;
HIDWORD(proc_info) = time(0LL);
if ( (unsigned int)fh_shr_tcp_lh_start(a4, v20, v18) )
{
if ( (fh_log_lvl[0] & 1) != 0 )
{
v17 = fh_log_fmt("error starting line handler thread for '%s'", v23);
fh_log("fh_shr_tcp.c", 262LL, "CSI", "ERR", v17);
}
goto LABEL_12;
}
fh_shr_mgmt_wait();
fh_shr_tcp_lh_wait();
fh_log_thread_stop(v12);
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(const char *a1, const char *a2)
{
const char *v2; // r14
char *v4; // rax
char *v5; // rbx
char v7[296]; // [rsp+0h] [rbp-128h] BYREF

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

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

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

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(const char *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(const char *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(const char *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(const char *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 **


decompiled_code:
__int64 __fastcall fh_cfg_set_yesno(const char *a1, const char *a2, _BYTE *a3)
{
const char *v4; // rax
unsigned int v5; // er8

v4 = fh_cfg_get_string(a1, a2);
if ( !v4 )
return 1LL;
if ( (*v4 & 0xDF) != 89 )
{
if ( (*v4 & 0xDF) != 78 )
return (unsigned int)-1;
v5 = -1;
if ( (v4[1] & 0xDF) == 79 )
{
*a3 = 0;
v5 = 0;
}
return v5;
}
v5 = -1;
if ( (v4[1] & 0xDF) != 69 || (v4[2] & 0xDF) != 83 )
return v5;
*a3 = 1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2, _BYTE *a3)
{
const char *v4; // rax
unsigned int v5; // er8

v4 = func4(a1, a2);
if ( !v4 )
return 1LL;
if ( (*v4 & 0xDF) != 89 )
{
if ( (*v4 & 0xDF) != 78 )
return (unsigned int)-1;
v5 = -1;
if ( (v4[1] & 0xDF) == 79 )
{
*a3 = 0;
v5 = 0;
}
return v5;
}
v5 = -1;
if ( (v4[1] & 0xDF) != 69 || (v4[2] & 0xDF) != 83 )
return v5;
*a3 = 1;
return 0LL;
}

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(const char *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(const char *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(const char *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(const char *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(const char *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(const char *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)
{
unsigned int v2; // er12
int *v4; // rax
__int64 v5; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, int a2)
{
unsigned int v2; // er12
int *v4; // rax
__int64 v5; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

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)
{
unsigned int v2; // er12
int *v4; // rax
__int64 v5; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, int a2)
{
unsigned int v2; // er12
int *v4; // rax
__int64 v5; // rax
int optval[7]; // [rsp+Ch] [rbp-1Ch] BYREF

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

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; // er12
int v9; // edi
int *v10; // rax
__int64 v11; // rax

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

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

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